ReactOS  0.4.14-dev-854-gb9426a3
svc_generic.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 <errno.h>
#include <stdlib.h>
#include <string.h>
#include "rpc_com.h"
#include <rpc/svc.h>
Include dependency graph for svc_generic.c:

Go to the source code of this file.

Functions

int __svc_vc_setflag (SVCXPRT *, int)
 
int svc_create (void *dispatch, rpcprog_t prognum, rpcvers_t versnum, const char *nettype)
 
SVCXPRTsvc_tp_create (void *dispatch, rpcprog_t prognum, rpcvers_t versnum, const struct netconfig *nconf)
 
SVCXPRTsvc_tli_create (SOCKET fd, const struct netconfig *nconf, const struct t_bind *bindaddr, u_int sendsz, u_int recvsz)
 

Function Documentation

◆ __svc_vc_setflag()

int __svc_vc_setflag ( SVCXPRT ,
int   
)

Referenced by svc_tli_create().

◆ svc_create()

int svc_create ( void dispatch,
rpcprog_t  prognum,
rpcvers_t  versnum,
const char nettype 
)

Definition at line 68 of file svc_generic.c.

73 {
74  struct xlist {
75  SVCXPRT *xprt; /* Server handle */
76  struct xlist *next; /* Next item */
77  } *l;
78  static struct xlist *xprtlist; /* A link list of all the handles */
79  int num = 0;
80  SVCXPRT *xprt;
81  struct netconfig *nconf;
82  void *handle;
83  extern mutex_t xprtlist_lock;
84 
85 /* VARIABLES PROTECTED BY xprtlist_lock: xprtlist */
86 
87  if ((handle = __rpc_setconf(nettype)) == NULL) {
88  // XXX warnx("svc_create: unknown protocol");
89  return (0);
90  }
91  while ((nconf = __rpc_getconf(handle)) != NULL) {
93  for (l = xprtlist; l; l = l->next) {
94  if (strcmp(l->xprt->xp_netid, nconf->nc_netid) == 0) {
95  /* Found an old one, use it */
96  (void) rpcb_unset(prognum, versnum, nconf);
97  if (svc_reg(l->xprt, prognum, versnum,
98  dispatch, nconf) == FALSE) {
99  // XXX warnx(
100 // "svc_create: could not register prog %u vers %u on %s",
101 // (unsigned)prognum, (unsigned)versnum,
102 // nconf->nc_netid);
103  } else {
104  num++;
105  }
106  break;
107  }
108  }
109  if (l == NULL) {
110  /* It was not found. Now create a new one */
111  xprt = svc_tp_create(dispatch, prognum, versnum, nconf);
112  if (xprt) {
113  l = (struct xlist *)malloc(sizeof (*l));
114  if (l == NULL) {
115  // XXX warnx("svc_create: no memory");
117  return (0);
118  }
119  l->xprt = xprt;
120  l->next = xprtlist;
121  xprtlist = l;
122  num++;
123  }
124  }
126  }
128  /*
129  * In case of num == 0; the error messages are generated by the
130  * underlying layers; and hence not needed here.
131  */
132  return (num);
133 }
namespace GUID const ADDRINFOEXW ADDRINFOEXW struct timeval OVERLAPPED LPLOOKUPSERVICE_COMPLETION_ROUTINE HANDLE * handle
Definition: sock.c:82
struct png_info_def **typedef void(__cdecl typeof(png_destroy_read_struct))(struct png_struct_def **
Definition: typeof.h:49
SVCXPRT * svc_tp_create(void *dispatch, rpcprog_t prognum, rpcvers_t versnum, const struct netconfig *nconf)
Definition: svc_generic.c:141
struct netconfig * __rpc_getconf(void *vhandle)
Definition: rpc_generic.c:348
#define mutex_lock(m)
Definition: reentrant.h:128
#define mutex_unlock(m)
Definition: reentrant.h:129
mutex_t xprtlist_lock
Definition: mt_misc.c:97
smooth NULL
Definition: ftsmooth.c:416
r l[0]
Definition: byte_order.h:167
bool_t rpcb_unset(rpcprog_t program, rpcvers_t version, const struct netconfig *nconf)
Definition: rpcb_clnt.c:581
GLuint GLuint num
Definition: glext.h:9618
char * nc_netid
Definition: netconfig.h:11
void dispatch(HANDLE hStopEvent)
Definition: dispatch.c:66
static unsigned __int64 next
Definition: rand_nt.c:6
void * __rpc_setconf(char *nettype) const
Definition: rpc_generic.c:305
bool_t svc_reg(SVCXPRT *xprt, const rpcprog_t prog, const rpcvers_t vers, void *dispatch, const struct netconfig *nconf)
Definition: svc.c:178
int strcmp(const char *String1, const char *String2)
Definition: utclib.c:469
#define malloc
Definition: debug_ros.c:4
void __rpc_endconf(void *vhandle)
Definition: rpc_generic.c:425
Definition: module.h:446

◆ svc_tli_create()

SVCXPRT* svc_tli_create ( SOCKET  fd,
const struct netconfig nconf,
const struct t_bind bindaddr,
u_int  sendsz,
u_int  recvsz 
)

Definition at line 182 of file svc_generic.c.

188 {
189  SVCXPRT *xprt = NULL; /* service handle */
190  bool_t madefd = FALSE; /* whether fd opened here */
191  struct __rpc_sockinfo si;
192  struct sockaddr_storage ss;
193  socklen_t slen;
194 
195  if (fd == RPC_ANYFD) {
196  if (nconf == NULL) {
197  // XXX warnx("svc_tli_create: invalid netconfig");
198  return (NULL);
199  }
200  fd = __rpc_nconf2fd(nconf);
201  if (fd == -1) {
202  // XXX warnx(
203 // "svc_tli_create: could not open connection for %s",
204 // nconf->nc_netid);
205  return (NULL);
206  }
207  __rpc_nconf2sockinfo(nconf, &si);
208  madefd = TRUE;
209  } else {
210  /*
211  * It is an open descriptor. Get the transport info.
212  */
213  if (!__rpc_fd2sockinfo(fd, &si)) {
214  // XXX warnx(
215 // "svc_tli_create: could not get transport information");
216  return (NULL);
217  }
218  }
219 
220  /*
221  * If the fd is unbound, try to bind it.
222  */
223  if (madefd || !__rpc_sockisbound(fd)) {
224  if (bindaddr == NULL) {
225  if (bindresvport(fd, NULL) < 0) {
226  memset(&ss, 0, sizeof ss);
227  ss.ss_family = si.si_af;
228  if (bind(fd, (struct sockaddr *)(void *)&ss,
229  (socklen_t)si.si_alen) == SOCKET_ERROR) {
230  // XXX warnx(
231 // "svc_tli_create: could not bind to anonymous port");
232  goto freedata;
233  }
234  }
235  listen(fd, SOMAXCONN);
236  } else {
237  if (bind(fd,
238  (struct sockaddr *)bindaddr->addr.buf,
239  (socklen_t)si.si_alen) == SOCKET_ERROR) {
240  // XXX warnx(
241 // "svc_tli_create: could not bind to requested address");
242  goto freedata;
243  }
244  listen(fd, (int)bindaddr->qlen);
245  }
246 
247  }
248  /*
249  * call transport specific function.
250  */
251  switch (si.si_socktype) {
252  case SOCK_STREAM:
253  slen = sizeof ss;
254  if (getpeername(fd, (struct sockaddr *)(void *)&ss, &slen)
255  == 0) {
256  /* accepted socket */
257  xprt = svc_fd_create(fd, sendsz, recvsz);
258  } else
259  xprt = svc_vc_create(fd, sendsz, recvsz);
260  if (!nconf || !xprt)
261  break;
262 #if 0
263  /* XXX fvdl */
264  if (strcmp(nconf->nc_protofmly, "inet") == 0 ||
265  strcmp(nconf->nc_protofmly, "inet6") == 0)
266  (void) __svc_vc_setflag(xprt, TRUE);
267 #endif
268  break;
269  case SOCK_DGRAM:
270  xprt = svc_dg_create(fd, sendsz, recvsz);
271  break;
272  default:
273  // XXX warnx("svc_tli_create: bad service type");
274  goto freedata;
275  }
276 
277  if (xprt == NULL)
278  /*
279  * The error messages here are spitted out by the lower layers:
280  * svc_vc_create(), svc_fd_create() and svc_dg_create().
281  */
282  goto freedata;
283 
284  /* Fill in type of service */
285  xprt->xp_type = __rpc_socktype2seman(si.si_socktype);
286 
287  if (nconf) {
288  xprt->xp_netid = strdup(nconf->nc_netid);
289  xprt->xp_tp = strdup(nconf->nc_device);
290  }
291  return (xprt);
292 
293 freedata:
294  if (madefd)
295  (void)closesocket(fd);
296  if (xprt) {
297  if (!madefd) /* so that svc_destroy doesnt close fd */
298  xprt->xp_fd = RPC_ANYFD;
299  SVC_DESTROY(xprt);
300  }
301  return (NULL);
302 }
#define SOCKET_ERROR
Definition: winsock.h:333
struct netbuf addr
Definition: types.h:156
#define TRUE
Definition: types.h:120
struct png_info_def **typedef void(__cdecl typeof(png_destroy_read_struct))(struct png_struct_def **
Definition: typeof.h:49
int32_t bool_t
Definition: types.h:101
INT WSAAPI bind(IN SOCKET s, IN CONST struct sockaddr *name, IN INT namelen)
Definition: socklife.c:36
#define RPC_ANYFD
Definition: svc.h:328
SVCXPRT * svc_dg_create(int fd, u_int sendsize, u_int recvsize)
Definition: svc_dg.c:95
#define closesocket
Definition: precomp.h:57
int __rpc_sockisbound(SOCKET)
Definition: rpc_generic.c:909
int __rpc_socktype2seman(int)
Definition: rpc_generic.c:859
static int fd
Definition: io.c:51
int __svc_vc_setflag(SVCXPRT *, int)
#define SOMAXCONN
Definition: winsock.h:399
int __rpc_fd2sockinfo(SOCKET fd, struct __rpc_sockinfo *sip)
Definition: rpc_generic.c:481
_Check_return_ _CRTIMP char *__cdecl strdup(_In_opt_z_ const char *_Src)
char * nc_protofmly
Definition: netconfig.h:14
int bindresvport(SOCKET sd, struct sockaddr_in *sin)
Definition: bindresvport.c:53
char * xp_tp
Definition: svc.h:117
smooth NULL
Definition: ftsmooth.c:416
INT WSAAPI getpeername(IN SOCKET s, OUT LPSOCKADDR name, IN OUT INT FAR *namelen)
Definition: sockctrl.c:167
SOCKET xp_fd
Definition: svc.h:91
#define SVC_DESTROY(xprt)
Definition: svc.h:184
int socklen_t
Definition: tcp.c:35
char * nc_netid
Definition: netconfig.h:11
int xp_type
Definition: svc.h:126
char * nc_device
Definition: netconfig.h:16
SOCKET __rpc_nconf2fd(const struct netconfig *nconf)
Definition: rpc_generic.c:562
INT WSAAPI listen(IN SOCKET s, IN INT backlog)
Definition: sockctrl.c:123
int strcmp(const char *String1, const char *String2)
Definition: utclib.c:469
int __rpc_nconf2sockinfo(const struct netconfig *nconf, struct __rpc_sockinfo *sip)
Definition: rpc_generic.c:540
#define SOCK_STREAM
Definition: tcpip.h:118
#define ss
Definition: i386-dis.c:432
#define SOCK_DGRAM
Definition: winsock.h:336
SVCXPRT * svc_fd_create(SOCKET fd, u_int sendsize, u_int recvsize)
Definition: svc_vc.c:204
#define memset(x, y, z)
Definition: compat.h:39
char * xp_netid
Definition: svc.h:118
SVCXPRT * svc_vc_create(int fd, u_int sendsize, u_int recvsize)
Definition: svc_vc.c:146
unsigned int qlen
Definition: types.h:157

Referenced by rpc_reg(), and svc_tp_create().

◆ svc_tp_create()

SVCXPRT* svc_tp_create ( void dispatch,
rpcprog_t  prognum,
rpcvers_t  versnum,
const struct netconfig nconf 
)

Definition at line 141 of file svc_generic.c.

146 {
147  SVCXPRT *xprt;
148 
149  if (nconf == NULL) {
150  // XXX warnx(
151 // "svc_tp_create: invalid netconfig structure for prog %u vers %u",
152 // (unsigned)prognum, (unsigned)versnum);
153  return (NULL);
154  }
155  xprt = svc_tli_create(RPC_ANYFD, nconf, NULL, 0, 0);
156  if (xprt == NULL) {
157  return (NULL);
158  }
159  /*LINTED const castaway*/
160  (void) rpcb_unset(prognum, versnum, (struct netconfig *) nconf);
161  if (svc_reg(xprt, prognum, versnum, dispatch, nconf) == FALSE) {
162  // XXX warnx(
163 // "svc_tp_create: Could not register prog %u vers %u on %s",
164 // (unsigned)prognum, (unsigned)versnum,
165 // nconf->nc_netid);
166  SVC_DESTROY(xprt);
167  return (NULL);
168  }
169  return (xprt);
170 }
struct png_info_def **typedef void(__cdecl typeof(png_destroy_read_struct))(struct png_struct_def **
Definition: typeof.h:49
#define RPC_ANYFD
Definition: svc.h:328
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
smooth NULL
Definition: ftsmooth.c:416
#define SVC_DESTROY(xprt)
Definition: svc.h:184
bool_t rpcb_unset(rpcprog_t program, rpcvers_t version, const struct netconfig *nconf)
Definition: rpcb_clnt.c:581
void dispatch(HANDLE hStopEvent)
Definition: dispatch.c:66
bool_t svc_reg(SVCXPRT *xprt, const rpcprog_t prog, const rpcvers_t vers, void *dispatch, const struct netconfig *nconf)
Definition: svc.c:178

Referenced by svc_create().