ReactOS 0.4.15-dev-7924-g5949c20
svc_simple.c File Reference
#include <wintirpc.h>
#include <reentrant.h>
#include <sys/types.h>
#include <rpc/rpc.h>
#include <rpc/nettype.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "rpc_com.h"
Include dependency graph for svc_simple.c:

Go to the source code of this file.

Classes

struct  proglst
 

Functions

static void universal (struct svc_req *, SVCXPRT *)
 
int rpc_reg (rpcprog_t prognum, rpcvers_t versnum, rpcproc_t procnum, char **progname, xdrproc_t inproc, xdrproc_t outproc, char *nettype)
 

Variables

static struct proglstproglst
 
static const char rpc_reg_err [] = "%s: %s"
 
static const char rpc_reg_msg [] = "rpc_reg: "
 
static const char __reg_err1 [] = "can't find appropriate transport"
 
static const char __reg_err2 [] = "can't get protocol info"
 
static const char __reg_err3 [] = "unsupported transport size"
 
static const char __no_mem_str [] = "out of memory"
 

Function Documentation

◆ rpc_reg()

int rpc_reg ( rpcprog_t  prognum,
rpcvers_t  versnum,
rpcproc_t  procnum,
char **  progname,
xdrproc_t  inproc,
xdrproc_t  outproc,
char nettype 
)

Definition at line 92 of file svc_simple.c.

99{
100 struct netconfig *nconf;
101 int done = FALSE;
102 void *handle;
103 extern mutex_t proglst_lock;
104
105 if (procnum == NULLPROC) {
106 // XXXwarnx("%s can't reassign procedure number %u", rpc_reg_msg,
107// NULLPROC);
108 return (-1);
109 }
110
111 if (nettype == NULL)
112 nettype = "netpath"; /* The default behavior */
113 if ((handle = __rpc_setconf(nettype)) == NULL) {
114 // XXX warnx(rpc_reg_err, rpc_reg_msg, __reg_err1);
115 return (-1);
116 }
117/* VARIABLES PROTECTED BY proglst_lock: proglst */
119 while ((nconf = __rpc_getconf(handle)) != NULL) {
120 struct proglst *pl;
121 SVCXPRT *svcxprt;
122 int madenow;
123 u_int recvsz;
124 char *xdrbuf;
125 char *netid;
126
127 madenow = FALSE;
128 svcxprt = NULL;
129 recvsz = 0;
130 xdrbuf = netid = NULL;
131 for (pl = proglst; pl; pl = pl->p_nxt) {
132 if (strcmp(pl->p_netid, nconf->nc_netid) == 0) {
133 svcxprt = pl->p_transp;
134 xdrbuf = pl->p_xdrbuf;
135 recvsz = pl->p_recvsz;
136 netid = pl->p_netid;
137 break;
138 }
139 }
140
141 if (svcxprt == NULL) {
142 struct __rpc_sockinfo si;
143
144 svcxprt = svc_tli_create(RPC_ANYFD, nconf, NULL, 0, 0);
145 if (svcxprt == NULL)
146 continue;
147 if (!__rpc_fd2sockinfo(svcxprt->xp_fd, &si)) {
148 // XXX warnx(rpc_reg_err, rpc_reg_msg, __reg_err2);
149 SVC_DESTROY(svcxprt);
150 continue;
151 }
152 recvsz = __rpc_get_t_size(si.si_af, si.si_proto, 0);
153 if (recvsz == 0) {
154 // XXX warnx(rpc_reg_err, rpc_reg_msg, __reg_err3);
155 SVC_DESTROY(svcxprt);
156 continue;
157 }
158 if (((xdrbuf = malloc((unsigned)recvsz)) == NULL) ||
159 ((netid = strdup(nconf->nc_netid)) == NULL)) {
160 // XXX warnx(rpc_reg_err, rpc_reg_msg, __no_mem_str);
161 SVC_DESTROY(svcxprt);
162 break;
163 }
164 madenow = TRUE;
165 }
166 /*
167 * Check if this (program, version, netid) had already been
168 * registered. The check may save a few RPC calls to rpcbind
169 */
170 for (pl = proglst; pl; pl = pl->p_nxt)
171 if ((pl->p_prognum == prognum) &&
172 (pl->p_versnum == versnum) &&
173 (strcmp(pl->p_netid, netid) == 0))
174 break;
175 if (pl == NULL) { /* Not yet */
176 (void) rpcb_unset(prognum, versnum, nconf);
177 } else {
178 /* so that svc_reg does not call rpcb_set() */
179 nconf = NULL;
180 }
181
182 if (!svc_reg(svcxprt, prognum, versnum, universal, nconf)) {
183 // XXX warnx("%s couldn't register prog %u vers %u for %s",
184// rpc_reg_msg, (unsigned)prognum,
185// (unsigned)versnum, netid);
186 if (madenow) {
187 SVC_DESTROY(svcxprt);
188 free(xdrbuf);
189 free(netid);
190 }
191 continue;
192 }
193
194 pl = malloc(sizeof (struct proglst));
195 if (pl == NULL) {
196 // XXX warnx(rpc_reg_err, rpc_reg_msg, __no_mem_str);
197 if (madenow) {
198 SVC_DESTROY(svcxprt);
199 free(xdrbuf);
200 free(netid);
201 }
202 break;
203 }
204 pl->p_progname = progname;
205 pl->p_prognum = prognum;
206 pl->p_versnum = versnum;
207 pl->p_procnum = procnum;
208 pl->p_inproc = inproc;
209 pl->p_outproc = outproc;
210 pl->p_transp = svcxprt;
211 pl->p_xdrbuf = xdrbuf;
212 pl->p_recvsz = recvsz;
213 pl->p_netid = netid;
214 pl->p_nxt = proglst;
215 proglst = pl;
216 done = TRUE;
217 }
220
221 if (done == FALSE) {
222 // XXX warnx("%s cant find suitable transport for %s",
223// rpc_reg_msg, nettype);
224 return (-1);
225 }
226 return (0);
227}
int strcmp(const char *String1, const char *String2)
Definition: utclib.c:469
static const char * progname
Definition: cjpeg.c:137
#define NULLPROC
Definition: clnt.h:294
#define free
Definition: debug_ros.c:5
#define malloc
Definition: debug_ros.c:4
#define RPC_ANYFD
Definition: svc.h:328
#define SVC_DESTROY(xprt)
Definition: svc.h:184
UINT32 u_int
Definition: types.h:82
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
mutex_t proglst_lock
Definition: mt_misc.c:77
#define mutex_lock(m)
Definition: reentrant.h:128
#define mutex_unlock(m)
Definition: reentrant.h:129
void * __rpc_setconf(char *nettype) const
Definition: rpc_generic.c:305
u_int __rpc_get_t_size(int af, int proto, int size)
Definition: rpc_generic.c:139
struct netconfig * __rpc_getconf(void *vhandle)
Definition: rpc_generic.c:348
int __rpc_fd2sockinfo(SOCKET fd, struct __rpc_sockinfo *sip)
Definition: rpc_generic.c:481
void __rpc_endconf(void *vhandle)
Definition: rpc_generic.c:425
bool_t rpcb_unset(rpcprog_t program, rpcvers_t version, const struct netconfig *nconf)
Definition: rpcb_clnt.c:581
_Check_return_ _CRTIMP char *__cdecl strdup(_In_opt_z_ const char *_Src)
Definition: module.h:456
char * nc_netid
Definition: netconfig.h:16
xdrproc_t p_outproc
Definition: svc_simple.c:69
rpcprog_t p_prognum
Definition: svc_simple.c:62
rpcvers_t p_versnum
Definition: svc_simple.c:63
char * p_xdrbuf
Definition: svc_simple.c:67
int p_recvsz
Definition: svc_simple.c:68
SVCXPRT * p_transp
Definition: svc_simple.c:65
rpcproc_t p_procnum
Definition: svc_simple.c:64
struct proglst * p_nxt
Definition: svc_simple.c:70
char * p_netid
Definition: svc_simple.c:66
char *(* p_progname)(char *)
Definition: svc_simple.c:61
xdrproc_t p_inproc
Definition: svc_simple.c:69
bool_t svc_reg(SVCXPRT *xprt, const rpcprog_t prog, const rpcvers_t vers, void *dispatch, const struct netconfig *nconf)
Definition: svc.c:178
SVCXPRT * svc_tli_create(SOCKET fd, const struct netconfig *nconf, const struct t_bind *bindaddr, u_int sendsz, u_int recvsz)
Definition: svc_generic.c:182
static void universal(struct svc_req *, SVCXPRT *)
Definition: svc_simple.c:235

◆ universal()

static void universal ( struct svc_req rqstp,
SVCXPRT transp 
)
static

Definition at line 235 of file svc_simple.c.

238{
240 rpcvers_t vers;
242 char *outdata;
243 char *xdrbuf;
244 struct proglst *pl;
245 extern mutex_t proglst_lock;
246
247 /*
248 * enforce "procnum 0 is echo" convention
249 */
250 if (rqstp->rq_proc == NULLPROC) {
251 if (svc_sendreply(transp, (xdrproc_t) xdr_void, NULL) ==
252 FALSE) {
253 // XXX warnx("svc_sendreply failed");
254 }
255 return;
256 }
257 prog = rqstp->rq_prog;
258 vers = rqstp->rq_vers;
259 proc = rqstp->rq_proc;
261 for (pl = proglst; pl; pl = pl->p_nxt)
262 if (pl->p_prognum == prog && pl->p_procnum == proc &&
263 pl->p_versnum == vers &&
264 (strcmp(pl->p_netid, transp->xp_netid) == 0)) {
265 /* decode arguments into a CLEAN buffer */
266 xdrbuf = pl->p_xdrbuf;
267 /* Zero the arguments: reqd ! */
268 (void) memset(xdrbuf, 0, sizeof (pl->p_recvsz));
269 /*
270 * Assuming that sizeof (xdrbuf) would be enough
271 * for the arguments; if not then the program
272 * may bomb. BEWARE!
273 */
274 if (!svc_getargs(transp, pl->p_inproc, xdrbuf)) {
275 svcerr_decode(transp);
277 return;
278 }
279 outdata = (*(pl->p_progname))(xdrbuf);
280 if (outdata == NULL &&
281 pl->p_outproc != (xdrproc_t) xdr_void){
282 /* there was an error */
284 return;
285 }
286 if (!svc_sendreply(transp, pl->p_outproc, outdata)) {
287 // XXX warnx(
288// "rpc: rpc_reg trouble replying to prog %u vers %u",
289// (unsigned)prog, (unsigned)vers);
291 return;
292 }
293 /* free the decoded arguments */
294 (void)svc_freeargs(transp, pl->p_inproc, xdrbuf);
296 return;
297 }
299 /* This should never happen */
300 // XXX warnx("rpc: rpc_reg: never registered prog %u vers %u",
301// (unsigned)prog, (unsigned)vers);
302 return;
303}
bool_t xdr_void(void)
Definition: xdr.c:92
#define svc_getargs(xprt, xargs, argsp)
Definition: svc.h:171
#define svc_freeargs(xprt, xargs, argsp)
Definition: svc.h:181
u_int32_t rpcprog_t
Definition: types.h:104
u_int32_t rpcvers_t
Definition: types.h:105
u_int32_t rpcproc_t
Definition: types.h:106
char * prog
Definition: isohybrid.c:47
static HANDLE proc()
Definition: pdb.c:34
#define memset(x, y, z)
Definition: compat.h:39
char * xp_netid
Definition: svc.h:118
u_int32_t rq_prog
Definition: svc.h:134
u_int32_t rq_proc
Definition: svc.h:136
u_int32_t rq_vers
Definition: svc.h:135
bool_t svc_sendreply(SVCXPRT *xprt, xdrproc_t xdr_results, void *xdr_location)
Definition: svc.c:399
void svcerr_decode(SVCXPRT *xprt)
Definition: svc.c:439
bool_t(* xdrproc_t)(XDR *,...)
Definition: xdr.h:144

Referenced by rpc_reg().

Variable Documentation

◆ __no_mem_str

const char __no_mem_str[] = "out of memory"
static

Definition at line 78 of file svc_simple.c.

◆ __reg_err1

const char __reg_err1[] = "can't find appropriate transport"
static

Definition at line 75 of file svc_simple.c.

◆ __reg_err2

const char __reg_err2[] = "can't get protocol info"
static

Definition at line 76 of file svc_simple.c.

◆ __reg_err3

const char __reg_err3[] = "unsupported transport size"
static

Definition at line 77 of file svc_simple.c.

◆ proglst

◆ rpc_reg_err

const char rpc_reg_err[] = "%s: %s"
static

Definition at line 73 of file svc_simple.c.

◆ rpc_reg_msg

const char rpc_reg_msg[] = "rpc_reg: "
static

Definition at line 74 of file svc_simple.c.