4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License, Version 1.0 only
6 * (the "License"). You may not use this file except in compliance
9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 * or http://www.opensolaris.org/os/licensing.
11 * See the License for the specific language governing permissions
12 * and limitations under the License.
14 * When distributing Covered Code, include this CDDL HEADER in each
15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 * If applicable, add the following below this CDDL HEADER, with the
17 * fields enclosed by brackets "[]" replaced with your own identifying
18 * information: Portions Copyright [yyyy] [name of copyright owner]
23 * Copyright (c) 1988-1997, by Sun Microsystems, Inc.
24 * All rights reserved.
27 #pragma ident "%Z%%M% %I% %E% SMI"
34 #include <rpc/nettype.h>
35 #include <netconfig.h>
43 extern int __rpc_negotiate_uid(int);
46 * The highest level interface for server creation.
47 * Copied from svc_generic.c and cmd/keyserv/key_generic.c, but adapted
48 * to work only for TPI_CLTS semantics, and to be called only once
49 * from gssd.c. Returns 1 (interface created) on success and 0
50 * (no interfaces created) on failure.
53 svc_create_local_service(dispatch
, prognum
, versnum
, nettype
, servname
)
54 void (*dispatch
) (); /* Dispatch function */
55 u_long prognum
; /* Program number */
56 u_long versnum
; /* Version number */
57 char *nettype
; /* Networktype token */
58 char *servname
; /* name of the service */
62 struct netconfig
*nconf
;
63 struct t_bind
*bind_addr
;
66 struct nd_hostserv ns
;
67 struct nd_addrlist
*nas
;
69 if ((net
= __rpc_setconf(nettype
)) == 0) {
70 (void) syslog(LOG_ERR
,
71 gettext("svc_create: could not read netconfig database"));
74 while (nconf
= __rpc_getconf(net
)) {
75 if ((strcmp(nconf
->nc_protofmly
, NC_LOOPBACK
)) ||
76 (nconf
->nc_semantics
!= NC_TPI_COTS_ORD
))
79 if ((fd
= t_open(nconf
->nc_device
, O_RDWR
, NULL
)) < 0) {
80 (void) syslog(LOG_ERR
,
81 gettext("svc_create: %s: cannot open connection: %s"),
82 nconf
->nc_netid
, t_errlist
[t_errno
]);
87 * Negotiate for returning the uid of the caller.
88 * This should be done before enabling the endpoint for
89 * service via t_bind() (called in svc_tli_create())
90 * so that requests to gssd contain the uid.
92 if (__rpc_negotiate_uid(fd
) != 0) {
94 gettext("Could not negotiate for"
95 " uid with loopback transport %s"),
101 /* LINTED pointer alignment */
102 bind_addr
= (struct t_bind
*) t_alloc(fd
, T_BIND
, T_ADDR
);
103 if ((bind_addr
== NULL
)) {
105 (void) syslog(LOG_ERR
,
106 gettext("svc_create: t_alloc failed\n"));
109 ns
.h_host
= HOST_SELF
;
110 ns
.h_serv
= servname
;
111 if (!netdir_getbyname(nconf
, &ns
, &nas
)) {
112 /* Copy the address */
113 bind_addr
->addr
.len
= nas
->n_addrs
->len
;
114 (void) memcpy(bind_addr
->addr
.buf
, nas
->n_addrs
->buf
,
115 (int) nas
->n_addrs
->len
);
117 netdir_free((char *) nas
, ND_ADDRLIST
);
119 (void) syslog(LOG_ERR
,
120 gettext("svc_create: no well known "
121 "address for %s on %s\n"),
122 servname
, nconf
->nc_netid
);
123 (void) t_free((char *) bind_addr
, T_BIND
);
127 xprt
= svc_tli_create(fd
, nconf
, bind_addr
, 0, 0);
129 (void) t_free((char *) bind_addr
, T_BIND
);
132 (void) syslog(LOG_ERR
,
133 gettext("svc_create: svc_tli_create failed\n"));
136 (void) rpcb_unset(prognum
, versnum
, nconf
);
137 if (svc_reg(xprt
, prognum
, versnum
, dispatch
, nconf
)
139 (void) syslog(LOG_ERR
,
140 gettext("svc_create: cannot"
141 " register %d vers %d on %s"),
142 prognum
, versnum
, nconf
->nc_netid
);
143 SVC_DESTROY(xprt
); /* also t_closes fd */