2 * Copyright (c) 1988-1999 by Sun Microsystems, Inc.
6 #pragma ident "%Z%%M% %I% %E% SMI"
13 #include <rpc/nettype.h>
14 #include <netconfig.h>
22 extern int __rpc_negotiate_uid(int);
25 * The highest level interface for server creation.
26 * Copied from svc_generic.c and cmd/keyserv/key_generic.c, but adapted
27 * to work only for TPI_CLTS semantics, and to be called only once
28 * from kwarnd.c. Returns 1 (interface created) on success and 0
29 * (no interfaces created) on failure.
32 svc_create_local_service(void (*dispatch
) (), /* Dispatch function */
33 u_long prognum
, /* Program number */
34 u_long versnum
, /* Version number */
35 char *nettype
, /* Networktype token */
36 char *servname
) /* name of the srvc */
40 struct netconfig
*nconf
;
41 struct t_bind
*bind_addr
;
44 struct nd_hostserv ns
;
45 struct nd_addrlist
*nas
;
47 if ((net
= __rpc_setconf(nettype
)) == 0) {
48 (void) syslog(LOG_ERR
,
49 gettext("svc_create: could not read netconfig database"));
52 while (nconf
= __rpc_getconf(net
)) {
53 if ((strcmp(nconf
->nc_protofmly
, NC_LOOPBACK
)) ||
54 (nconf
->nc_semantics
!= NC_TPI_COTS_ORD
))
57 if ((fd
= t_open(nconf
->nc_device
, O_RDWR
, NULL
)) < 0) {
58 (void) syslog(LOG_ERR
,
59 gettext("svc_create: %s: cannot open connection: %s"),
60 nconf
->nc_netid
, t_errlist
[t_errno
]);
65 * Negotiate for returning the uid of the caller.
66 * This should be done before enabling the endpoint for
67 * service via t_bind() (called in svc_tli_create())
68 * so that requests to kwarnd contain the uid.
70 if (__rpc_negotiate_uid(fd
) != 0) {
72 gettext("Could not negotiate for"
73 " uid with loopback transport %s"),
79 /* LINTED pointer alignment */
80 bind_addr
= (struct t_bind
*) t_alloc(fd
, T_BIND
, T_ADDR
);
81 if ((bind_addr
== NULL
)) {
83 (void) syslog(LOG_ERR
,
84 gettext("svc_create: t_alloc failed\n"));
87 ns
.h_host
= HOST_SELF
;
89 if (!netdir_getbyname(nconf
, &ns
, &nas
)) {
90 /* Copy the address */
91 bind_addr
->addr
.len
= nas
->n_addrs
->len
;
92 (void) memcpy(bind_addr
->addr
.buf
, nas
->n_addrs
->buf
,
93 (int) nas
->n_addrs
->len
);
95 netdir_free((char *) nas
, ND_ADDRLIST
);
97 (void) syslog(LOG_ERR
,
98 gettext("svc_create: no well known "
99 "address for %s on %s\n"),
100 servname
, nconf
->nc_netid
);
101 (void) t_free((char *) bind_addr
, T_BIND
);
105 xprt
= svc_tli_create(fd
, nconf
, bind_addr
, 0, 0);
107 (void) t_free((char *) bind_addr
, T_BIND
);
110 (void) syslog(LOG_ERR
,
111 gettext("svc_create: svc_tli_create failed\n"));
114 (void) rpcb_unset(prognum
, versnum
, nconf
);
115 if (svc_reg(xprt
, prognum
, versnum
, dispatch
, nconf
)
117 (void) syslog(LOG_ERR
,
118 gettext("svc_create: cannot"
119 " register %d vers %d on %s"),
120 prognum
, versnum
, nconf
->nc_netid
);
121 SVC_DESTROY(xprt
); /* also t_closes fd */