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
44 #include <sys/syslog.h>
48 #include <rpc/nettype.h>
49 #include <netconfig.h>
52 extern char *strdup();
55 * The highest level interface for server creation.
56 * It tries for all the nettokens in that particular class of token
57 * and returns the number of handles it can create and/or find.
59 * It creates a link list of all the handles it could create.
60 * If svc_create() is called multiple times, it uses the handle
61 * created earlier instead of creating a new handle every time.
63 * Copied from svc_generic.c
66 svc_create_local_service(dispatch
, prognum
, versnum
, nettype
, servname
)
67 void (*dispatch
) (); /* Dispatch function */
68 ulong_t prognum
; /* Program number */
69 ulong_t versnum
; /* Version number */
70 char *nettype
; /* Networktype token */
71 char *servname
; /* name of the service */
74 SVCXPRT
*xprt
; /* Server handle */
75 struct xlist
*next
; /* Next item */
77 static struct xlist
*xprtlist
;
80 struct netconfig
*nconf
;
81 struct t_bind
*bind_addr
;
84 struct nd_hostserv ns
;
85 struct nd_addrlist
*nas
;
87 if ((handle
= __rpc_setconf(nettype
)) == NULL
) {
88 (void) syslog(LOG_ERR
,
89 "svc_create: could not read netconfig database");
92 while (nconf
= __rpc_getconf(handle
)) {
93 if (strcmp(nconf
->nc_protofmly
, NC_LOOPBACK
))
95 for (l
= xprtlist
; l
; l
= l
->next
) {
96 if (strcmp(l
->xprt
->xp_netid
, nconf
->nc_netid
) == 0) {
97 /* Found an old one, use it */
98 (void) rpcb_unset(prognum
, versnum
, nconf
);
99 if (svc_reg(l
->xprt
, prognum
, versnum
,
100 dispatch
, nconf
) == FALSE
)
101 (void) syslog(LOG_ERR
,
102 "svc_create: could not register prog %d vers %d on %s",
103 prognum
, versnum
, nconf
->nc_netid
);
111 /* It was not found. Now create a new one */
112 if ((fd
= t_open(nconf
->nc_device
, O_RDWR
, NULL
)) < 0) {
114 "svc_create: %s: cannot open connection: %s",
115 nconf
->nc_netid
, t_errlist
[t_errno
]);
120 * Negotiate for returning the uid of the caller.
121 * This should be done before enabling the endpoint for
122 * service via t_bind() (called in svc_tli_create())
123 * so that requests to keyserv contain the uid.
125 if (__rpc_negotiate_uid(fd
) != 0) {
127 "Couldn't negotiate for uid with loopback transport %s",
133 bind_addr
= (struct t_bind
*)t_alloc(fd
, T_BIND
, T_ADDR
);
134 if ((bind_addr
== NULL
)) {
136 (void) syslog(LOG_ERR
, "svc_create: t_alloc failed\n");
139 ns
.h_host
= HOST_SELF
;
140 ns
.h_serv
= servname
;
141 if (!netdir_getbyname(nconf
, &ns
, &nas
)) {
142 /* Copy the address */
143 bind_addr
->addr
.len
= nas
->n_addrs
->len
;
144 memcpy(bind_addr
->addr
.buf
, nas
->n_addrs
->buf
,
145 (int)nas
->n_addrs
->len
);
147 netdir_free((char *)nas
, ND_ADDRLIST
);
150 "svc_create: no well known address for %s on transport %s",
151 servname
, nconf
->nc_netid
);
152 (void) t_free((char *)bind_addr
, T_BIND
);
156 xprt
= svc_tli_create(fd
, nconf
, bind_addr
, 0, 0);
158 (void) t_free((char *)bind_addr
, T_BIND
);
160 (void) rpcb_unset(prognum
, versnum
, nconf
);
161 if (svc_reg(xprt
, prognum
, versnum
,
162 dispatch
, nconf
) == FALSE
) {
163 (void) syslog(LOG_ERR
,
164 "svc_create: could not register prog %d vers %d on %s",
165 prognum
, versnum
, nconf
->nc_netid
);
169 l
= (struct xlist
*)malloc(sizeof (struct xlist
));
170 if (l
== (struct xlist
*)NULL
) {
171 (void) syslog(LOG_ERR
,
172 "svc_create: no memory");
182 __rpc_endconf(handle
);