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 1997 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
27 /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
28 /* All Rights Reserved */
31 * University Copyright- Copyright (c) 1982, 1986, 1988
32 * The Regents of the University of California
35 * University Acknowledgment- Portions of this document are derived from
36 * software developed by the University of California, Berkeley, and its
40 #pragma ident "%Z%%M% %I% %E% SMI"
46 #include <sys/syslog.h>
50 #include <rpc/nettype.h>
51 #include <netconfig.h>
54 extern char *strdup();
57 * The highest level interface for server creation.
58 * It tries for all the nettokens in that particular class of token
59 * and returns the number of handles it can create and/or find.
61 * It creates a link list of all the handles it could create.
62 * If svc_create() is called multiple times, it uses the handle
63 * created earlier instead of creating a new handle every time.
65 * Copied from svc_generic.c
68 svc_create_local_service(dispatch
, prognum
, versnum
, nettype
, servname
)
69 void (*dispatch
) (); /* Dispatch function */
70 ulong_t prognum
; /* Program number */
71 ulong_t versnum
; /* Version number */
72 char *nettype
; /* Networktype token */
73 char *servname
; /* name of the service */
76 SVCXPRT
*xprt
; /* Server handle */
77 struct xlist
*next
; /* Next item */
79 static struct xlist
*xprtlist
;
82 struct netconfig
*nconf
;
83 struct t_bind
*bind_addr
;
86 struct nd_hostserv ns
;
87 struct nd_addrlist
*nas
;
89 if ((handle
= __rpc_setconf(nettype
)) == NULL
) {
90 (void) syslog(LOG_ERR
,
91 "svc_create: could not read netconfig database");
94 while (nconf
= __rpc_getconf(handle
)) {
95 if (strcmp(nconf
->nc_protofmly
, NC_LOOPBACK
))
97 for (l
= xprtlist
; l
; l
= l
->next
) {
98 if (strcmp(l
->xprt
->xp_netid
, nconf
->nc_netid
) == 0) {
99 /* Found an old one, use it */
100 (void) rpcb_unset(prognum
, versnum
, nconf
);
101 if (svc_reg(l
->xprt
, prognum
, versnum
,
102 dispatch
, nconf
) == FALSE
)
103 (void) syslog(LOG_ERR
,
104 "svc_create: could not register prog %d vers %d on %s",
105 prognum
, versnum
, nconf
->nc_netid
);
113 /* It was not found. Now create a new one */
114 if ((fd
= t_open(nconf
->nc_device
, O_RDWR
, NULL
)) < 0) {
116 "svc_create: %s: cannot open connection: %s",
117 nconf
->nc_netid
, t_errlist
[t_errno
]);
122 * Negotiate for returning the uid of the caller.
123 * This should be done before enabling the endpoint for
124 * service via t_bind() (called in svc_tli_create())
125 * so that requests to keyserv contain the uid.
127 if (__rpc_negotiate_uid(fd
) != 0) {
129 "Couldn't negotiate for uid with loopback transport %s",
135 bind_addr
= (struct t_bind
*)t_alloc(fd
, T_BIND
, T_ADDR
);
136 if ((bind_addr
== NULL
)) {
138 (void) syslog(LOG_ERR
, "svc_create: t_alloc failed\n");
141 ns
.h_host
= HOST_SELF
;
142 ns
.h_serv
= servname
;
143 if (!netdir_getbyname(nconf
, &ns
, &nas
)) {
144 /* Copy the address */
145 bind_addr
->addr
.len
= nas
->n_addrs
->len
;
146 memcpy(bind_addr
->addr
.buf
, nas
->n_addrs
->buf
,
147 (int)nas
->n_addrs
->len
);
149 netdir_free((char *)nas
, ND_ADDRLIST
);
152 "svc_create: no well known address for %s on transport %s",
153 servname
, nconf
->nc_netid
);
154 (void) t_free((char *)bind_addr
, T_BIND
);
158 xprt
= svc_tli_create(fd
, nconf
, bind_addr
, 0, 0);
160 (void) t_free((char *)bind_addr
, T_BIND
);
162 (void) rpcb_unset(prognum
, versnum
, nconf
);
163 if (svc_reg(xprt
, prognum
, versnum
,
164 dispatch
, nconf
) == FALSE
) {
165 (void) syslog(LOG_ERR
,
166 "svc_create: could not register prog %d vers %d on %s",
167 prognum
, versnum
, nconf
->nc_netid
);
171 l
= (struct xlist
*)malloc(sizeof (struct xlist
));
173 (void) syslog(LOG_ERR
,
174 "svc_create: no memory");
184 __rpc_endconf(handle
);