svc_simple.c (7c478bd9) svc_simple.c (61961e0f)
1/*
2 * CDDL HEADER START
3 *
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
7 * with the License.
8 *

--- 5 unchanged lines hidden (view full) ---

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]
19 *
20 * CDDL HEADER END
21 */
1/*
2 * CDDL HEADER START
3 *
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
7 * with the License.
8 *

--- 5 unchanged lines hidden (view full) ---

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]
19 *
20 * CDDL HEADER END
21 */
22
22/*
23/*
23 * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
24 * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
25 */
26/* Copyright (c) 1983, 1984, 1985, 1986, 1987, 1988, 1989 AT&T */
27/* All Rights Reserved */
28/*
29 * Portions of this source code were derived from Berkeley
30 * 4.3 BSD under license from the Regents of the University of
31 * California.

--- 16 unchanged lines hidden (view full) ---

48#include "mt.h"
49#include "rpc_mt.h"
50#include <errno.h>
51#include <stdio.h>
52#include <stdlib.h>
53#include <string.h>
54#include <rpc/rpc.h>
55#include <sys/types.h>
25 * Use is subject to license terms.
26 */
27/* Copyright (c) 1983, 1984, 1985, 1986, 1987, 1988, 1989 AT&T */
28/* All Rights Reserved */
29/*
30 * Portions of this source code were derived from Berkeley
31 * 4.3 BSD under license from the Regents of the University of
32 * California.

--- 16 unchanged lines hidden (view full) ---

49#include "mt.h"
50#include "rpc_mt.h"
51#include <errno.h>
52#include <stdio.h>
53#include <stdlib.h>
54#include <string.h>
55#include <rpc/rpc.h>
56#include <sys/types.h>
56#include <rpc/trace.h>
57#include <syslog.h>
58#include <rpc/nettype.h>
59
60static struct proglst {
61 char *(*p_progname)();
62 rpcprog_t p_prognum;
63 rpcvers_t p_versnum;
64 rpcproc_t p_procnum;

--- 19 unchanged lines hidden (view full) ---

84 * handle is created for all the services (actually one of each netid)
85 * and same xdrbuf is used for same netid. The size of the arguments
86 * is also limited by the recvsize for that transport, even if it is
87 * a COTS transport. This may be wrong, but for cases like these, they
88 * should not use the simplified interfaces like this.
89 */
90
91int
57#include <syslog.h>
58#include <rpc/nettype.h>
59
60static struct proglst {
61 char *(*p_progname)();
62 rpcprog_t p_prognum;
63 rpcvers_t p_versnum;
64 rpcproc_t p_procnum;

--- 19 unchanged lines hidden (view full) ---

84 * handle is created for all the services (actually one of each netid)
85 * and same xdrbuf is used for same netid. The size of the arguments
86 * is also limited by the recvsize for that transport, even if it is
87 * a COTS transport. This may be wrong, but for cases like these, they
88 * should not use the simplified interfaces like this.
89 */
90
91int
92rpc_reg(prognum, versnum, procnum, progname, inproc, outproc, nettype)
93 rpcprog_t prognum; /* program number */
94 rpcvers_t versnum; /* version number */
95 rpcproc_t procnum; /* procedure number */
96 char *(*progname)(); /* Server routine */
97 xdrproc_t inproc, outproc; /* in/out XDR procedures */
98 const char *nettype; /* nettype */
92rpc_reg(const rpcprog_t prognum, const rpcvers_t versnum,
93 const rpcproc_t procnum, char *(*progname)(), const xdrproc_t inproc,
94 const xdrproc_t outproc, const char *nettype)
99{
100 struct netconfig *nconf;
101 int done = FALSE;
102 void *handle;
103 extern mutex_t proglst_lock;
104
95{
96 struct netconfig *nconf;
97 int done = FALSE;
98 void *handle;
99 extern mutex_t proglst_lock;
100
105
106
107 trace4(TR_rpc_reg, 0, prognum, versnum, procnum);
108 if (procnum == NULLPROC) {
109 (void) syslog(LOG_ERR, (const char *) "%s: %s %d",
110 rpc_reg_msg,
111 (const char *) "can't reassign procedure number %d",
112 NULLPROC);
101 if (procnum == NULLPROC) {
102 (void) syslog(LOG_ERR, (const char *) "%s: %s %d",
103 rpc_reg_msg,
104 (const char *) "can't reassign procedure number %d",
105 NULLPROC);
113 trace4(TR_rpc_reg, 1, prognum, versnum, procnum);
114 return (-1);
115 }
116
117 if (nettype == NULL)
118 nettype = "netpath"; /* The default behavior */
119 if ((handle = __rpc_setconf((char *)nettype)) == NULL) {
120 (void) syslog(LOG_ERR, rpc_reg_err, rpc_reg_msg, __reg_err1);
121 return (-1);
122 }
123/* VARIABLES PROTECTED BY proglst_lock: proglst */
106 return (-1);
107 }
108
109 if (nettype == NULL)
110 nettype = "netpath"; /* The default behavior */
111 if ((handle = __rpc_setconf((char *)nettype)) == NULL) {
112 (void) syslog(LOG_ERR, rpc_reg_err, rpc_reg_msg, __reg_err1);
113 return (-1);
114 }
115/* VARIABLES PROTECTED BY proglst_lock: proglst */
124 mutex_lock(&proglst_lock);
116 (void) mutex_lock(&proglst_lock);
125 while (nconf = __rpc_getconf(handle)) {
126 struct proglst *pl;
127 SVCXPRT *svcxprt;
128 int madenow;
129 uint_t recvsz;
130 char *xdrbuf;
131 char *netid;
132
133 madenow = FALSE;
117 while (nconf = __rpc_getconf(handle)) {
118 struct proglst *pl;
119 SVCXPRT *svcxprt;
120 int madenow;
121 uint_t recvsz;
122 char *xdrbuf;
123 char *netid;
124
125 madenow = FALSE;
134 svcxprt = (SVCXPRT *)NULL;
126 svcxprt = NULL;
135 for (pl = proglst; pl; pl = pl->p_nxt)
136 if (strcmp(pl->p_netid, nconf->nc_netid) == 0) {
137 svcxprt = pl->p_transp;
138 xdrbuf = pl->p_xdrbuf;
139 recvsz = pl->p_recvsz;
140 netid = pl->p_netid;
141 break;
142 }
143
127 for (pl = proglst; pl; pl = pl->p_nxt)
128 if (strcmp(pl->p_netid, nconf->nc_netid) == 0) {
129 svcxprt = pl->p_transp;
130 xdrbuf = pl->p_xdrbuf;
131 recvsz = pl->p_recvsz;
132 netid = pl->p_netid;
133 break;
134 }
135
144 if (svcxprt == (SVCXPRT *)NULL) {
136 if (svcxprt == NULL) {
145 struct t_info tinfo;
146
137 struct t_info tinfo;
138
147 svcxprt = svc_tli_create(RPC_ANYFD, nconf,
148 (struct t_bind *)NULL, 0, 0);
149 if (svcxprt == (SVCXPRT *)NULL)
139 svcxprt = svc_tli_create(RPC_ANYFD, nconf, NULL, 0, 0);
140 if (svcxprt == NULL)
150 continue;
151 if (t_getinfo(svcxprt->xp_fd, &tinfo) == -1) {
152 char errorstr[100];
153
154 __tli_sys_strerror(errorstr, sizeof (errorstr),
155 t_errno, errno);
156 (void) syslog(LOG_ERR, "%s : %s : %s",
157 rpc_reg_msg, "t_getinfo failed",

--- 39 unchanged lines hidden (view full) ---

197 if (madenow) {
198 SVC_DESTROY(svcxprt);
199 free(xdrbuf);
200 free(netid);
201 }
202 continue;
203 }
204
141 continue;
142 if (t_getinfo(svcxprt->xp_fd, &tinfo) == -1) {
143 char errorstr[100];
144
145 __tli_sys_strerror(errorstr, sizeof (errorstr),
146 t_errno, errno);
147 (void) syslog(LOG_ERR, "%s : %s : %s",
148 rpc_reg_msg, "t_getinfo failed",

--- 39 unchanged lines hidden (view full) ---

188 if (madenow) {
189 SVC_DESTROY(svcxprt);
190 free(xdrbuf);
191 free(netid);
192 }
193 continue;
194 }
195
205 pl = (struct proglst *)malloc(sizeof (struct proglst));
206 if (pl == (struct proglst *)NULL) {
196 pl = malloc(sizeof (struct proglst));
197 if (pl == NULL) {
207 (void) syslog(LOG_ERR, rpc_reg_err, rpc_reg_msg,
208 __no_mem_str);
209 if (madenow) {
210 SVC_DESTROY(svcxprt);
211 free(xdrbuf);
212 free(netid);
213 }
214 break;

--- 8 unchanged lines hidden (view full) ---

223 pl->p_xdrbuf = xdrbuf;
224 pl->p_recvsz = recvsz;
225 pl->p_netid = netid;
226 pl->p_nxt = proglst;
227 proglst = pl;
228 done = TRUE;
229 }
230 __rpc_endconf(handle);
198 (void) syslog(LOG_ERR, rpc_reg_err, rpc_reg_msg,
199 __no_mem_str);
200 if (madenow) {
201 SVC_DESTROY(svcxprt);
202 free(xdrbuf);
203 free(netid);
204 }
205 break;

--- 8 unchanged lines hidden (view full) ---

214 pl->p_xdrbuf = xdrbuf;
215 pl->p_recvsz = recvsz;
216 pl->p_netid = netid;
217 pl->p_nxt = proglst;
218 proglst = pl;
219 done = TRUE;
220 }
221 __rpc_endconf(handle);
231 mutex_unlock(&proglst_lock);
222 (void) mutex_unlock(&proglst_lock);
232
233 if (done == FALSE) {
234 (void) syslog(LOG_ERR,
235 (const char *) "%s cant find suitable transport for %s",
236 rpc_reg_msg, nettype);
223
224 if (done == FALSE) {
225 (void) syslog(LOG_ERR,
226 (const char *) "%s cant find suitable transport for %s",
227 rpc_reg_msg, nettype);
237 trace4(TR_rpc_reg, 1, prognum, versnum, procnum);
238 return (-1);
239 }
228 return (-1);
229 }
240 trace4(TR_rpc_reg, 1, prognum, versnum, procnum);
241 return (0);
242}
243
244/*
245 * The universal handler for the services registered using registerrpc.
246 * It handles both the connectionless and the connection oriented cases.
247 */
248
230 return (0);
231}
232
233/*
234 * The universal handler for the services registered using registerrpc.
235 * It handles both the connectionless and the connection oriented cases.
236 */
237
249static const char __univ_err[] = " prog %d vers %d";
250static void
238static void
251universal(rqstp, transp)
252 struct svc_req *rqstp;
253 SVCXPRT *transp;
239universal(struct svc_req *rqstp, SVCXPRT *transp)
254{
255 rpcprog_t prog;
256 rpcvers_t vers;
257 rpcproc_t proc;
258 char *outdata;
259 char *xdrbuf;
260 struct proglst *pl;
261 extern mutex_t proglst_lock;
262
263 /*
264 * enforce "procnum 0 is echo" convention
265 */
240{
241 rpcprog_t prog;
242 rpcvers_t vers;
243 rpcproc_t proc;
244 char *outdata;
245 char *xdrbuf;
246 struct proglst *pl;
247 extern mutex_t proglst_lock;
248
249 /*
250 * enforce "procnum 0 is echo" convention
251 */
266 trace1(TR_universal, 0);
267 if (rqstp->rq_proc == NULLPROC) {
252 if (rqstp->rq_proc == NULLPROC) {
268 if (svc_sendreply(transp, (xdrproc_t)xdr_void,
269 (char *)NULL) == FALSE) {
253 if (svc_sendreply(transp, (xdrproc_t)xdr_void, NULL) == FALSE) {
270 (void) syslog(LOG_ERR,
271 (const char *) "svc_sendreply failed");
272 }
254 (void) syslog(LOG_ERR,
255 (const char *) "svc_sendreply failed");
256 }
273 trace1(TR_universal, 1);
274 return;
275 }
276 prog = rqstp->rq_prog;
277 vers = rqstp->rq_vers;
278 proc = rqstp->rq_proc;
257 return;
258 }
259 prog = rqstp->rq_prog;
260 vers = rqstp->rq_vers;
261 proc = rqstp->rq_proc;
279 mutex_lock(&proglst_lock);
280 for (pl = proglst; pl; pl = pl->p_nxt)
262 (void) mutex_lock(&proglst_lock);
263 for (pl = proglst; pl; pl = pl->p_nxt) {
281 if (pl->p_prognum == prog && pl->p_procnum == proc &&
282 pl->p_versnum == vers &&
283 (strcmp(pl->p_netid, transp->xp_netid) == 0)) {
284 /* decode arguments into a CLEAN buffer */
285 xdrbuf = pl->p_xdrbuf;
286 /* Zero the arguments: reqd ! */
287 (void) memset(xdrbuf, 0, pl->p_recvsz);
288 /*
289 * Assuming that sizeof (xdrbuf) would be enough
290 * for the arguments; if not then the program
291 * may bomb. BEWARE!
292 */
293 if (!svc_getargs(transp, pl->p_inproc, xdrbuf)) {
294 svcerr_decode(transp);
264 if (pl->p_prognum == prog && pl->p_procnum == proc &&
265 pl->p_versnum == vers &&
266 (strcmp(pl->p_netid, transp->xp_netid) == 0)) {
267 /* decode arguments into a CLEAN buffer */
268 xdrbuf = pl->p_xdrbuf;
269 /* Zero the arguments: reqd ! */
270 (void) memset(xdrbuf, 0, pl->p_recvsz);
271 /*
272 * Assuming that sizeof (xdrbuf) would be enough
273 * for the arguments; if not then the program
274 * may bomb. BEWARE!
275 */
276 if (!svc_getargs(transp, pl->p_inproc, xdrbuf)) {
277 svcerr_decode(transp);
295 mutex_unlock(&proglst_lock);
296 trace1(TR_universal, 1);
278 (void) mutex_unlock(&proglst_lock);
297 return;
298 }
299 outdata = (*(pl->p_progname))(xdrbuf);
300 if (outdata == NULL &&
301 pl->p_outproc != (xdrproc_t)xdr_void) {
302 /* there was an error */
279 return;
280 }
281 outdata = (*(pl->p_progname))(xdrbuf);
282 if (outdata == NULL &&
283 pl->p_outproc != (xdrproc_t)xdr_void) {
284 /* there was an error */
303 mutex_unlock(&proglst_lock);
304 trace1(TR_universal, 1);
285 (void) mutex_unlock(&proglst_lock);
305 return;
306 }
307 if (!svc_sendreply(transp, pl->p_outproc, outdata)) {
308 (void) syslog(LOG_ERR, (const char *)
309 "rpc: rpc_reg trouble replying to prog %d vers %d",
310 prog, vers);
286 return;
287 }
288 if (!svc_sendreply(transp, pl->p_outproc, outdata)) {
289 (void) syslog(LOG_ERR, (const char *)
290 "rpc: rpc_reg trouble replying to prog %d vers %d",
291 prog, vers);
311 mutex_unlock(&proglst_lock);
312 trace1(TR_universal, 1);
292 (void) mutex_unlock(&proglst_lock);
313 return;
314 }
315 /* free the decoded arguments */
316 (void) svc_freeargs(transp, pl->p_inproc, xdrbuf);
293 return;
294 }
295 /* free the decoded arguments */
296 (void) svc_freeargs(transp, pl->p_inproc, xdrbuf);
317 mutex_unlock(&proglst_lock);
318 trace1(TR_universal, 1);
297 (void) mutex_unlock(&proglst_lock);
319 return;
320 }
298 return;
299 }
321 mutex_unlock(&proglst_lock);
300 }
301 (void) mutex_unlock(&proglst_lock);
322 /* This should never happen */
323 (void) syslog(LOG_ERR, (const char *)
324 "rpc: rpc_reg: never registered prog %d vers %d",
325 prog, vers);
302 /* This should never happen */
303 (void) syslog(LOG_ERR, (const char *)
304 "rpc: rpc_reg: never registered prog %d vers %d",
305 prog, vers);
326 trace1(TR_universal, 1);
327}
306}