ReactOS  0.4.14-dev-98-gb0d4763
clnt_generic.c File Reference
#include <wintirpc.h>
#include <reentrant.h>
#include <sys/types.h>
#include <fcntl.h>
#include <stdio.h>
#include <errno.h>
#include <string.h>
#include <stdlib.h>
#include <rpc/rpc.h>
#include <rpc/nettype.h>
#include "rpc_com.h"
Include dependency graph for clnt_generic.c:

Go to the source code of this file.

Macros

#define NETIDLEN   32
 

Functions

bool_t __rpc_is_local_host (const char *)
 
CLIENTclnt_create_vers (const char *hostname, const rpcprog_t prog, rpcvers_t *vers_out, const rpcvers_t vers_low, const rpcvers_t vers_high, const char *nettype)
 
CLIENTclnt_create_vers_timed (const char *hostname, const rpcprog_t prog, rpcvers_t *vers_out, const rpcvers_t vers_low_in, const rpcvers_t vers_high_in, const char *nettype, const struct timeval *tp)
 
CLIENTclnt_create (const char *hostname, const rpcprog_t prog, const rpcvers_t vers, const char *nettype)
 
CLIENTclnt_create_timed (const char *hostname, const rpcprog_t prog, const rpcvers_t vers, const char *netclass, const struct timeval *tp)
 
CLIENTclnt_tp_create (const char *hostname, const rpcprog_t prog, const rpcvers_t vers, const struct netconfig *nconf)
 
CLIENTclnt_tp_create_timed (const char *hostname, const rpcprog_t prog, const rpcvers_t vers, const struct netconfig *nconf, const struct timeval *tp)
 
CLIENTclnt_tli_create (const SOCKET fd_in, const struct netconfig *nconf, struct netbuf *svcaddr, const rpcprog_t prog, const rpcvers_t vers, const uint sendsz, const uint recvsz, int(*callback_xdr)(void *, void *), int(*callback_function)(void *, void *, void **), void *callback_args)
 

Macro Definition Documentation

◆ NETIDLEN

#define NETIDLEN   32

Definition at line 81 of file clnt_generic.c.

Function Documentation

◆ __rpc_is_local_host()

bool_t __rpc_is_local_host ( const char )

◆ clnt_create()

CLIENT* clnt_create ( const char hostname,
const rpcprog_t  prog,
const rpcvers_t  vers,
const char nettype 
)

Definition at line 179 of file clnt_generic.c.

181 {
182 
183  return (clnt_create_timed(hostname, prog, vers, nettype, NULL));
184 }
CLIENT * clnt_create_timed(const char *hostname, const rpcprog_t prog, const rpcvers_t vers, const char *netclass, const struct timeval *tp)
Definition: clnt_generic.c:195
char * prog
Definition: isohybrid.c:47
char * hostname
Definition: ftp.c:88
smooth NULL
Definition: ftsmooth.c:416

Referenced by rpc_call().

◆ clnt_create_timed()

CLIENT* clnt_create_timed ( const char hostname,
const rpcprog_t  prog,
const rpcvers_t  vers,
const char netclass,
const struct timeval tp 
)

Definition at line 195 of file clnt_generic.c.

197 {
198  struct netconfig *nconf;
199  CLIENT *clnt = NULL;
200  void *handle;
201  enum clnt_stat save_cf_stat = RPC_SUCCESS;
202  struct rpc_err save_cf_error;
203  char nettype_array[NETIDLEN];
204  char *nettype = &nettype_array[0];
205 
206  if (netclass == NULL)
207  nettype = NULL;
208  else {
209  size_t len = strlen(netclass);
210  if (len >= sizeof (nettype_array)) {
212  return (NULL);
213  }
214  strcpy(nettype, netclass);
215  }
216 
217  if ((handle = __rpc_setconf((char *)nettype)) == NULL) {
219  return (NULL);
220  }
222  while (clnt == NULL) {
223  if ((nconf = __rpc_getconf(handle)) == NULL) {
226  break;
227  }
228 #ifdef CLNT_DEBUG
229  printf("trying netid %s\n", nconf->nc_netid);
230 #endif
231  clnt = clnt_tp_create_timed(hostname, prog, vers, nconf, tp);
232  if (clnt)
233  break;
234  else {
235  /*
236  * Since we didn't get a name-to-address
237  * translation failure here, we remember
238  * this particular error. The object of
239  * this is to enable us to return to the
240  * caller a more-specific error than the
241  * unhelpful ``Name to address translation
242  * failed'' which might well occur if we
243  * merely returned the last error (because
244  * the local loopbacks are typically the
245  * last ones in /etc/netconfig and the most
246  * likely to be unable to translate a host
247  * name). We also check for a more
248  * meaningful error than ``unknown host
249  * name'' for the same reasons.
250  */
253  save_cf_stat = rpc_createerr.cf_stat;
254  save_cf_error = rpc_createerr.cf_error;
255  }
256  }
257  }
258 
259  /*
260  * Attempt to return an error more specific than ``Name to address
261  * translation failed'' or ``unknown host name''
262  */
265  (save_cf_stat != RPC_SUCCESS)) {
266  rpc_createerr.cf_stat = save_cf_stat;
267  rpc_createerr.cf_error = save_cf_error;
268  }
270  return (clnt);
271 }
namespace GUID const ADDRINFOEXW ADDRINFOEXW struct timeval OVERLAPPED LPLOOKUPSERVICE_COMPLETION_ROUTINE HANDLE * handle
Definition: sock.c:82
ACPI_SIZE strlen(const char *String)
Definition: utclib.c:269
char * prog
Definition: isohybrid.c:47
CLIENT * clnt_tp_create_timed(const char *hostname, const rpcprog_t prog, const rpcvers_t vers, const struct netconfig *nconf, const struct timeval *tp)
Definition: clnt_generic.c:295
struct netconfig * __rpc_getconf(void *vhandle)
Definition: rpc_generic.c:348
char * hostname
Definition: ftp.c:88
smooth NULL
Definition: ftsmooth.c:416
#define NETIDLEN
Definition: clnt_generic.c:81
_In_ uint64_t _In_ uint64_t _In_ uint64_t _In_opt_ traverse_ptr * tp
Definition: btrfs.c:2883
enum clnt_stat cf_stat
Definition: clnt.h:496
char * nc_netid
Definition: netconfig.h:11
GLenum GLsizei len
Definition: glext.h:6722
Definition: clnt.h:95
void * __rpc_setconf(char *nettype) const
Definition: rpc_generic.c:305
struct rpc_err cf_error
Definition: clnt.h:497
char * strcpy(char *DstString, const char *SrcString)
Definition: utclib.c:388
void __rpc_endconf(void *vhandle)
Definition: rpc_generic.c:425
clnt_stat
Definition: clnt_stat.h:21
#define printf
Definition: config.h:203

Referenced by clnt_create(), and clnt_create_vers_timed().

◆ clnt_create_vers()

CLIENT* clnt_create_vers ( const char hostname,
const rpcprog_t  prog,
rpcvers_t vers_out,
const rpcvers_t  vers_low,
const rpcvers_t  vers_high,
const char nettype 
)

Definition at line 94 of file clnt_generic.c.

96 {
97 
98  return (clnt_create_vers_timed(hostname, prog, vers_out, vers_low,
99  vers_high, nettype, NULL));
100 }
char * prog
Definition: isohybrid.c:47
char * hostname
Definition: ftp.c:88
smooth NULL
Definition: ftsmooth.c:416
CLIENT * clnt_create_vers_timed(const char *hostname, const rpcprog_t prog, rpcvers_t *vers_out, const rpcvers_t vers_low_in, const rpcvers_t vers_high_in, const char *nettype, const struct timeval *tp)
Definition: clnt_generic.c:109

◆ clnt_create_vers_timed()

CLIENT* clnt_create_vers_timed ( const char hostname,
const rpcprog_t  prog,
rpcvers_t vers_out,
const rpcvers_t  vers_low_in,
const rpcvers_t  vers_high_in,
const char nettype,
const struct timeval tp 
)

Definition at line 109 of file clnt_generic.c.

112 {
113  CLIENT *clnt;
114  struct timeval to;
115  enum clnt_stat rpc_stat;
116  struct rpc_err rpcerr;
117  rpcvers_t vers_high = vers_high_in;
118  rpcvers_t vers_low = vers_low_in;
119 
120  clnt = clnt_create_timed(hostname, prog, vers_high, nettype, tp);
121  if (clnt == NULL) {
122  return (NULL);
123  }
124  to.tv_sec = 10;
125  to.tv_usec = 0;
126  rpc_stat = clnt_call(clnt, NULLPROC, (xdrproc_t)xdr_void,
127  (char *)NULL, (xdrproc_t)xdr_void, (char *)NULL, to);
128  if (rpc_stat == RPC_SUCCESS) {
129  *vers_out = vers_high;
130  return (clnt);
131  }
132  while (rpc_stat == RPC_PROGVERSMISMATCH && vers_high > vers_low) {
133  unsigned int minvers, maxvers;
134 
135  clnt_geterr(clnt, &rpcerr);
136  minvers = rpcerr.re_vers.low;
137  maxvers = rpcerr.re_vers.high;
138  if (maxvers < vers_high)
139  vers_high = maxvers;
140  else
141  vers_high--;
142  if (minvers > vers_low)
143  vers_low = minvers;
144  if (vers_low > vers_high) {
145  goto error;
146  }
147  CLNT_CONTROL(clnt, CLSET_VERS, (char *)&vers_high);
148  rpc_stat = clnt_call(clnt, NULLPROC, (xdrproc_t)xdr_void,
149  (char *)NULL, (xdrproc_t)xdr_void,
150  (char *)NULL, to);
151  if (rpc_stat == RPC_SUCCESS) {
152  *vers_out = vers_high;
153  return (clnt);
154  }
155  }
156  clnt_geterr(clnt, &rpcerr);
157 
158 error:
159  rpc_createerr.cf_stat = rpc_stat;
160  rpc_createerr.cf_error = rpcerr;
161  clnt_destroy(clnt);
162  return (NULL);
163 }
#define clnt_geterr(rh, errp)
Definition: clnt.h:220
u_int32_t rpcvers_t
Definition: types.h:105
#define error(str)
Definition: mkdosfs.c:1605
CLIENT * clnt_create_timed(const char *hostname, const rpcprog_t prog, const rpcvers_t vers, const char *netclass, const struct timeval *tp)
Definition: clnt_generic.c:195
char * prog
Definition: isohybrid.c:47
char * hostname
Definition: ftp.c:88
bool_t(* xdrproc_t)(XDR *,...)
Definition: xdr.h:144
smooth NULL
Definition: ftsmooth.c:416
_In_ uint64_t _In_ uint64_t _In_ uint64_t _In_opt_ traverse_ptr * tp
Definition: btrfs.c:2883
#define NULLPROC
Definition: clnt.h:294
enum clnt_stat cf_stat
Definition: clnt.h:496
bool_t xdr_void(void)
Definition: xdr.c:92
Definition: clnt.h:95
#define clnt_call(rh, proc, xargs, argsp, xres, resp, secs)
Definition: clnt.h:202
#define CLSET_VERS
Definition: clnt.h:256
struct rpc_err cf_error
Definition: clnt.h:497
#define CLNT_CONTROL(cl, rq, in)
Definition: clnt.h:240
#define clnt_destroy(rh)
Definition: clnt.h:276
clnt_stat
Definition: clnt_stat.h:21

Referenced by clnt_create_vers().

◆ clnt_tli_create()

CLIENT* clnt_tli_create ( const SOCKET  fd_in,
const struct netconfig nconf,
struct netbuf svcaddr,
const rpcprog_t  prog,
const rpcvers_t  vers,
const uint  sendsz,
const uint  recvsz,
int(*)(void *, void *)  callback_xdr,
int(*)(void *, void *, void **)  callback_function,
void callback_args 
)

Definition at line 347 of file clnt_generic.c.

353 {
354  CLIENT *cl; /* client handle */
355  bool_t madefd = FALSE; /* whether fd opened here */
356  long servtype;
357  BOOL one = TRUE;
358  struct __rpc_sockinfo si;
359  extern int __rpc_minfd;
360  SOCKET fd = fd_in;
361 
362  if (fd == RPC_ANYFD) {
363  if (nconf == NULL) {
365  return (NULL);
366  }
367 
368  fd = __rpc_nconf2fd(nconf);
369 
370  if (fd == INVALID_SOCKET)
371  goto err;
372 #if 0
373  if (fd < __rpc_minfd)
374  fd = __rpc_raise_fd(fd);
375 #endif
376  madefd = TRUE;
377  servtype = nconf->nc_semantics;
378  bindresvport(fd, NULL);
379  if (!__rpc_fd2sockinfo(fd, &si))
380  goto err;
381  } else {
382  if (!__rpc_fd2sockinfo(fd, &si))
383  goto err;
384  servtype = __rpc_socktype2seman(si.si_socktype);
385  if (servtype == -1) {
387  return (NULL);
388  }
389  }
390 
391  if (si.si_af != ((struct sockaddr *)svcaddr->buf)->sa_family) {
393  goto err1;
394  }
395 
396  switch (servtype) {
397  case NC_TPI_COTS:
398  cl = clnt_vc_create(fd, svcaddr, prog, vers, sendsz, recvsz,
399  callback_xdr, callback_function, callback_args);
400  break;
401  case NC_TPI_COTS_ORD:
402  if (nconf &&
403  ((strcmp(nconf->nc_protofmly, "inet") == 0) ||
404  (strcmp(nconf->nc_protofmly, "inet6") == 0))) {
405  setsockopt(fd, IPPROTO_TCP, TCP_NODELAY, (const char *)&one,
406  sizeof (one));
407  }
408  cl = clnt_vc_create(fd, svcaddr, prog, vers, sendsz, recvsz,
409  callback_xdr, callback_function, callback_args);
410  break;
411  case NC_TPI_CLTS:
412  cl = clnt_dg_create(fd, svcaddr, prog, vers, sendsz, recvsz);
413  break;
414  default:
415  goto err;
416  }
417 
418  if (cl == NULL)
419  goto err1; /* borrow errors from clnt_dg/vc creates */
420  if (nconf) {
421  cl->cl_netid = strdup(nconf->nc_netid);
422  cl->cl_tp = strdup(nconf->nc_device);
423  } else {
424  cl->cl_netid = "";
425  cl->cl_tp = "";
426  }
427  if (madefd) {
429 /* (void) CLNT_CONTROL(cl, CLSET_POP_TIMOD, NULL); */
430  };
431 
432  return (cl);
433 
434 err:
436  rpc_createerr.cf_error.re_errno = errno;
437 err1: if (madefd)
438  (void)closesocket(fd);
439  return (NULL);
440 }
#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
#define NC_TPI_CLTS
Definition: netconfig.h:30
char * prog
Definition: isohybrid.c:47
#define RPC_ANYFD
Definition: svc.h:328
int __rpc_socktype2seman(int)
Definition: rpc_generic.c:859
void * buf
Definition: types.h:147
static int fd
Definition: io.c:51
int errno
#define CLSET_FD_CLOSE
Definition: clnt.h:251
static double one
Definition: j0_y0.c:80
#define TCP_NODELAY
Definition: tcpdef.h:117
int __rpc_fd2sockinfo(SOCKET fd, struct __rpc_sockinfo *sip)
Definition: rpc_generic.c:481
#define closesocket
Definition: main.c:39
unsigned int BOOL
Definition: ntddk_ex.h:94
_Check_return_ _CRTIMP char *__cdecl strdup(_In_opt_z_ const char *_Src)
#define NC_TPI_COTS_ORD
Definition: netconfig.h:32
char * nc_protofmly
Definition: netconfig.h:14
INT WSAAPI setsockopt(IN SOCKET s, IN INT level, IN INT optname, IN CONST CHAR FAR *optval, IN INT optlen)
Definition: sockctrl.c:421
int bindresvport(SOCKET sd, struct sockaddr_in *sin)
Definition: bindresvport.c:53
smooth NULL
Definition: ftsmooth.c:416
char * cl_tp
Definition: clnt.h:144
#define INVALID_SOCKET
Definition: winsock.h:332
enum clnt_stat cf_stat
Definition: clnt.h:496
char * nc_netid
Definition: netconfig.h:11
#define NC_TPI_COTS
Definition: netconfig.h:31
CLIENT * clnt_vc_create(int fd, const struct netbuf *raddr, const rpcprog_t prog, const rpcvers_t vers, u_int sendsz, u_int recvsz, int *cb_xdr, int *cb_fn, void *cb_args)
Definition: clnt_vc.c:324
#define err(...)
char * nc_device
Definition: netconfig.h:16
SOCKET __rpc_nconf2fd(const struct netconfig *nconf)
Definition: rpc_generic.c:562
char * cl_netid
Definition: clnt.h:143
struct rpc_err cf_error
Definition: clnt.h:497
int strcmp(const char *String1, const char *String2)
Definition: utclib.c:469
CLIENT * clnt_dg_create(SOCKET fd, const struct netbuf *svcaddr, rpcprog_t program, rpcvers_t version, u_int sendsz, u_int recvsz)
Definition: clnt_dg.c:154
UINT_PTR SOCKET
Definition: winsock.h:47
unsigned long nc_semantics
Definition: netconfig.h:12
#define CLNT_CONTROL(cl, rq, in)
Definition: clnt.h:240

Referenced by clnt_tp_create_timed(), get_client_for_netaddr(), and getclnthandle().

◆ clnt_tp_create()

CLIENT* clnt_tp_create ( const char hostname,
const rpcprog_t  prog,
const rpcvers_t  vers,
const struct netconfig nconf 
)

Definition at line 282 of file clnt_generic.c.

284 {
285  return (clnt_tp_create_timed(hostname, prog, vers, nconf, NULL));
286 }
char * prog
Definition: isohybrid.c:47
CLIENT * clnt_tp_create_timed(const char *hostname, const rpcprog_t prog, const rpcvers_t vers, const struct netconfig *nconf, const struct timeval *tp)
Definition: clnt_generic.c:295
char * hostname
Definition: ftp.c:88
smooth NULL
Definition: ftsmooth.c:416

Referenced by _des_crypt_call(), and getkeyserv_handle().

◆ clnt_tp_create_timed()

CLIENT* clnt_tp_create_timed ( const char hostname,
const rpcprog_t  prog,
const rpcvers_t  vers,
const struct netconfig nconf,
const struct timeval tp 
)

Definition at line 295 of file clnt_generic.c.

297 {
298  struct netbuf *svcaddr; /* servers address */
299  CLIENT *cl = NULL; /* client handle */
300 
301  if (nconf == NULL) {
303  return (NULL);
304  }
305 
306  /*
307  * Get the address of the server
308  */
309  if ((svcaddr = __rpcb_findaddr_timed(prog, vers,
310  (struct netconfig *)nconf, (char *)hostname,
311  &cl, (struct timeval *)tp)) == NULL) {
312  /* appropriate error number is set by rpcbind libraries */
313  return (NULL);
314  }
315  if (cl == NULL) {
316  cl = clnt_tli_create(RPC_ANYFD, nconf, svcaddr,
317  prog, vers, 0, 0, NULL, NULL, NULL);
318  } else {
319  /* Reuse the CLIENT handle and change the appropriate fields */
320  if (CLNT_CONTROL(cl, CLSET_SVC_ADDR, (void *)svcaddr) == TRUE) {
321  if (cl->cl_netid == NULL)
322  cl->cl_netid = strdup(nconf->nc_netid);
323  if (cl->cl_tp == NULL)
324  cl->cl_tp = strdup(nconf->nc_device);
325  (void) CLNT_CONTROL(cl, CLSET_PROG, (void *)&prog);
326  (void) CLNT_CONTROL(cl, CLSET_VERS, (void *)&vers);
327  } else {
328  CLNT_DESTROY(cl);
329  cl = clnt_tli_create(RPC_ANYFD, nconf, svcaddr,
330  prog, vers, 0, 0, NULL, NULL, NULL);
331  }
332  }
333  free(svcaddr->buf);
334  free(svcaddr);
335  return (cl);
336 }
#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
#define CLSET_SVC_ADDR
Definition: clnt.h:259
struct netbuf * __rpcb_findaddr_timed(rpcprog_t, rpcvers_t, const struct netconfig *, const char *host, CLIENT **clpp, struct timeval *tp)
Definition: rpcb_clnt.c:709
char * prog
Definition: isohybrid.c:47
#define RPC_ANYFD
Definition: svc.h:328
#define free
Definition: debug_ros.c:5
char * hostname
Definition: ftp.c:88
_Check_return_ _CRTIMP char *__cdecl strdup(_In_opt_z_ const char *_Src)
smooth NULL
Definition: ftsmooth.c:416
char * cl_tp
Definition: clnt.h:144
_In_ uint64_t _In_ uint64_t _In_ uint64_t _In_opt_ traverse_ptr * tp
Definition: btrfs.c:2883
#define CLSET_PROG
Definition: clnt.h:258
enum clnt_stat cf_stat
Definition: clnt.h:496
char * nc_netid
Definition: netconfig.h:11
CLIENT * clnt_tli_create(const SOCKET fd_in, const struct netconfig *nconf, struct netbuf *svcaddr, const rpcprog_t prog, const rpcvers_t vers, const uint sendsz, const uint recvsz, int(*callback_xdr)(void *, void *), int(*callback_function)(void *, void *, void **), void *callback_args)
Definition: clnt_generic.c:347
char * nc_device
Definition: netconfig.h:16
char * cl_netid
Definition: clnt.h:143
#define CLNT_DESTROY(rh)
Definition: clnt.h:275
#define CLSET_VERS
Definition: clnt.h:256
Definition: types.h:144
#define CLNT_CONTROL(cl, rq, in)
Definition: clnt.h:240

Referenced by clnt_create_timed(), and clnt_tp_create().