ReactOS  0.4.14-dev-98-gb0d4763
getnetconfig.c File Reference
#include <wintirpc.h>
#include <reentrant.h>
#include <stdio.h>
#include <errno.h>
#include <netconfig.h>
#include <stddef.h>
#include <stdlib.h>
#include <string.h>
#include <rpc/rpc.h>
#include "rpc_com.h"
Include dependency graph for getnetconfig.c:

Go to the source code of this file.

Classes

struct  netconfig_info
 
struct  netconfig_list
 
struct  netconfig_vars
 

Macros

#define NC_NONETCONFIG   ENOENT
 
#define NC_NOMEM   ENOMEM
 
#define NC_NOTINIT   EINVAL /* setnetconfig was not called first */
 
#define NC_BADFILE   EBADF /* format for netconfig file is bad */
 
#define NC_NOTFOUND   WSAENOPROTOOPT /* specified netid was not found */
 
#define NC_TPI_CLTS_S   "tpi_clts"
 
#define NC_TPI_COTS_S   "tpi_cots"
 
#define NC_TPI_COTS_ORD_S   "tpi_cots_ord"
 
#define NC_TPI_RAW_S   "tpi_raw"
 
#define NC_NOFLAG_C   '-'
 
#define NC_VISIBLE_C   'v'
 
#define NC_BROADCAST_C   'b'
 
#define NC_NOLOOKUP   "-"
 
#define NC_VALID   0xfeed
 
#define NC_STORAGE   0xf00d
 
#define NC_INVALID   0
 
#define MAXNETCONFIGLINE   1000
 
#define nc_error   (*(__nc_error()))
 

Functions

static void wintirpc_debug (char *fmt,...)
 
static int__nc_error (void)
 
static int parse_ncp (char *, struct netconfig *)
 
static struct netconfigdup_ncp (struct netconfig *)
 
voidsetnetconfig ()
 
struct netconfiggetnetconfig (void *handlep)
 
int endnetconfig (void *handlep)
 
struct netconfiggetnetconfigent (char *netid) const
 
void freenetconfigent (struct netconfig *netconfigp)
 
charnc_sperror ()
 
void nc_perror (char *s) const
 

Variables

static const char *const _nc_errors []
 
static FILEnc_file
 
static struct netconfig_info ni = { 0, 0, NULL, NULL}
 

Macro Definition Documentation

◆ MAXNETCONFIGLINE

#define MAXNETCONFIGLINE   1000

Definition at line 160 of file getnetconfig.c.

◆ NC_BADFILE

#define NC_BADFILE   EBADF /* format for netconfig file is bad */

Definition at line 97 of file getnetconfig.c.

◆ NC_BROADCAST_C

#define NC_BROADCAST_C   'b'

Definition at line 113 of file getnetconfig.c.

◆ nc_error

#define nc_error   (*(__nc_error()))

Definition at line 196 of file getnetconfig.c.

◆ NC_INVALID

#define NC_INVALID   0

Definition at line 149 of file getnetconfig.c.

◆ NC_NOFLAG_C

#define NC_NOFLAG_C   '-'

Definition at line 111 of file getnetconfig.c.

◆ NC_NOLOOKUP

#define NC_NOLOOKUP   "-"

Definition at line 118 of file getnetconfig.c.

◆ NC_NOMEM

#define NC_NOMEM   ENOMEM

Definition at line 95 of file getnetconfig.c.

◆ NC_NONETCONFIG

#define NC_NONETCONFIG   ENOENT

Definition at line 94 of file getnetconfig.c.

◆ NC_NOTFOUND

#define NC_NOTFOUND   WSAENOPROTOOPT /* specified netid was not found */

Definition at line 98 of file getnetconfig.c.

◆ NC_NOTINIT

#define NC_NOTINIT   EINVAL /* setnetconfig was not called first */

Definition at line 96 of file getnetconfig.c.

◆ NC_STORAGE

#define NC_STORAGE   0xf00d

Definition at line 148 of file getnetconfig.c.

◆ NC_TPI_CLTS_S

#define NC_TPI_CLTS_S   "tpi_clts"

Definition at line 103 of file getnetconfig.c.

◆ NC_TPI_COTS_ORD_S

#define NC_TPI_COTS_ORD_S   "tpi_cots_ord"

Definition at line 105 of file getnetconfig.c.

◆ NC_TPI_COTS_S

#define NC_TPI_COTS_S   "tpi_cots"

Definition at line 104 of file getnetconfig.c.

◆ NC_TPI_RAW_S

#define NC_TPI_RAW_S   "tpi_raw"

Definition at line 106 of file getnetconfig.c.

◆ NC_VALID

#define NC_VALID   0xfeed

Definition at line 147 of file getnetconfig.c.

◆ NC_VISIBLE_C

#define NC_VISIBLE_C   'v'

Definition at line 112 of file getnetconfig.c.

Function Documentation

◆ __nc_error()

static int * __nc_error ( void  )
static

Definition at line 163 of file getnetconfig.c.

164 {
165  extern mutex_t nc_lock;
166  extern thread_key_t nc_key;
167  static int nc_error = 0;
168  int error, *nc_addr;
169 
170  /*
171  * Use the static `nc_error' if we are the main thread
172  * (including non-threaded programs), or if an allocation
173  * fails.
174  */
175  if (nc_key == -1) {
176  error = 0;
178  if (nc_key == -1)
179  error = nc_key = TlsAlloc(); //thr_keycreate(&nc_key, free);
181  if (error == TLS_OUT_OF_INDEXES)
182  return (&nc_error);
183  }
184  if ((nc_addr = (int *)thr_getspecific(nc_key)) == NULL) {
185  nc_addr = (int *)malloc(sizeof (int *));
186  if (thr_setspecific(nc_key, (void *) nc_addr) == 0) {
187  if (nc_addr)
188  free(nc_addr);
189  return (&nc_error);
190  }
191  *nc_addr = 0;
192  }
193  return (nc_addr);
194 }
#define error(str)
Definition: mkdosfs.c:1605
#define thr_setspecific(k, p)
Definition: reentrant.h:146
#define free
Definition: debug_ros.c:5
#define mutex_lock(m)
Definition: reentrant.h:128
#define nc_error
Definition: getnetconfig.c:196
#define mutex_unlock(m)
Definition: reentrant.h:129
#define thread_key_t
Definition: reentrant.h:124
smooth NULL
Definition: ftsmooth.c:416
#define thr_getspecific(k)
Definition: reentrant.h:147
DWORD WINAPI TlsAlloc(VOID)
Definition: thread.c:1088
#define TLS_OUT_OF_INDEXES
Definition: winbase.h:530
mutex_t nc_lock
Definition: mt_misc.c:103
thread_key_t nc_key
Definition: mt_misc.c:93
#define malloc
Definition: debug_ros.c:4
Definition: module.h:446

◆ dup_ncp()

static struct netconfig * dup_ncp ( struct netconfig ncp)
static

Definition at line 689 of file getnetconfig.c.

691 {
692  struct netconfig *p;
693  char *tmp;
694  u_int i;
695 
696  if ((tmp=malloc(MAXNETCONFIGLINE)) == NULL)
697  return(NULL);
698  if ((p=(struct netconfig *)malloc(sizeof(struct netconfig))) == NULL) {
699  free(tmp);
700  return(NULL);
701  }
702  /*
703  * First we dup all the data from matched netconfig buffer. Then we
704  * adjust some of the member pointer to a pre-allocated buffer where
705  * contains part of the data.
706  * To follow the convention used in parse_ncp(), we store all the
707  * necessary information in the pre-allocated buffer and let each
708  * of the netconfig char pointer member point to the right address
709  * in the buffer.
710  */
711  *p = *ncp;
712  p->nc_netid = (char *)strcpy(tmp,ncp->nc_netid);
713  tmp = strchr(tmp, 0) + 1;
714  p->nc_protofmly = (char *)strcpy(tmp,ncp->nc_protofmly);
715  tmp = strchr(tmp, 0) + 1;
716  p->nc_proto = (char *)strcpy(tmp,ncp->nc_proto);
717  tmp = strchr(tmp, 0) + 1;
718  p->nc_device = (char *)strcpy(tmp,ncp->nc_device);
719  p->nc_lookups = (char **)malloc((size_t)(p->nc_nlookups+1) * sizeof(char *));
720  if (p->nc_lookups == NULL) {
721  free(p->nc_netid);
722  return(NULL);
723  }
724  for (i=0; i < p->nc_nlookups; i++) {
725  tmp = strchr(tmp, 0) + 1;
726  p->nc_lookups[i] = (char *)strcpy(tmp,ncp->nc_lookups[i]);
727  }
728  return(p);
729 }
#define MAXNETCONFIGLINE
Definition: getnetconfig.c:160
#define free
Definition: debug_ros.c:5
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
char * nc_protofmly
Definition: netconfig.h:14
smooth NULL
Definition: ftsmooth.c:416
char * nc_proto
Definition: netconfig.h:15
char * nc_netid
Definition: netconfig.h:11
char * nc_device
Definition: netconfig.h:16
UINT32 u_int
Definition: types.h:82
char ** nc_lookups
Definition: netconfig.h:18
char * strchr(const char *String, int ch)
Definition: utclib.c:501
char * strcpy(char *DstString, const char *SrcString)
Definition: utclib.c:388
#define malloc
Definition: debug_ros.c:4
GLfloat GLfloat p
Definition: glext.h:8902

Referenced by getnetconfigent().

◆ endnetconfig()

int endnetconfig ( void handlep)

Definition at line 373 of file getnetconfig.c.

375 {
376  struct netconfig_vars *nc_handlep = (struct netconfig_vars *)handlep;
377 
378  struct netconfig_list *q, *p;
379 
380  /*
381  * Verify that handle is valid
382  */
383  if (nc_handlep == NULL || (nc_handlep->valid != NC_VALID &&
384  nc_handlep->valid != NC_STORAGE)) {
386  return (-1);
387  }
388 
389  /*
390  * Return 0 if anyone still needs it.
391  */
392  nc_handlep->valid = NC_INVALID;
393  nc_handlep->flag = 0;
394  nc_handlep->nc_configs = NULL;
395  if (--ni.ref > 0) {
396  free(nc_handlep);
397  return(0);
398  }
399 
400  /*
401  * Noone needs these entries anymore, then frees them.
402  * Make sure all info in netconfig_info structure has been reinitialized.
403  */
404  q = p = ni.head;
405  ni.eof = ni.ref = 0;
406  ni.head = NULL;
407  ni.tail = NULL;
408  while (q) {
409  p = q->next;
410  if (q->ncp->nc_lookups != NULL) free(q->ncp->nc_lookups);
411  free(q->ncp);
412  free(q->linep);
413  free(q);
414  q = p;
415  }
416  free(nc_handlep);
417 
418  fclose(nc_file);
419  nc_file = NULL;
420  return (0);
421 }
#define NC_INVALID
Definition: getnetconfig.c:149
static struct netconfig_info ni
Definition: getnetconfig.c:158
#define free
Definition: debug_ros.c:5
#define NC_VALID
Definition: getnetconfig.c:147
#define nc_error
Definition: getnetconfig.c:196
#define NC_STORAGE
Definition: getnetconfig.c:148
smooth NULL
Definition: ftsmooth.c:416
GLdouble GLdouble GLdouble GLdouble q
Definition: gl.h:2063
_Check_return_opt_ _CRTIMP int __cdecl fclose(_Inout_ FILE *_File)
#define NC_NOTINIT
Definition: getnetconfig.c:96
struct netconfig_list * nc_configs
Definition: getnetconfig.c:144
static FILE * nc_file
Definition: getnetconfig.c:157
GLfloat GLfloat p
Definition: glext.h:8902

Referenced by __rpc_endconf(), __rpc_getconfip(), __rpcbind_is_up(), _des_crypt_call(), endnetpath(), getkeyserv_handle(), local_rpcb(), and setnetpath().

◆ freenetconfigent()

void freenetconfigent ( struct netconfig netconfigp)

Definition at line 530 of file getnetconfig.c.

532 {
533  if (netconfigp != NULL) {
534  free(netconfigp->nc_netid); /* holds all netconfigp's strings */
535  if (netconfigp->nc_lookups != NULL)
536  free(netconfigp->nc_lookups);
537  free(netconfigp);
538  }
539  return;
540 }
#define free
Definition: debug_ros.c:5
smooth NULL
Definition: ftsmooth.c:416
char * nc_netid
Definition: netconfig.h:11
char ** nc_lookups
Definition: netconfig.h:18

Referenced by __rpc_sockinfo2netid(), __rpcb_findaddr_timed(), cache_get(), cache_set(), endnetpath(), get_client_for_netaddr(), nfs41_server_resolve(), pmap_set(), pmap_unset(), and svc_reg().

◆ getnetconfig()

struct netconfig* getnetconfig ( void handlep)

Definition at line 253 of file getnetconfig.c.

255 {
256  struct netconfig_vars *ncp = (struct netconfig_vars *)handlep;
257  char *stringp; /* tmp string pointer */
258  struct netconfig_list *list;
259  struct netconfig *np;
260 
261  /*
262  * Verify that handle is valid
263  */
264  if (ncp == NULL || nc_file == NULL) {
266  return (NULL);
267  }
268 
269  switch (ncp->valid) {
270  case NC_VALID:
271  /*
272  * If entry has already been read into the list,
273  * we return the entry in the linked list.
274  * If this is the first time call, check if there are any entries in
275  * linked list. If no entries, we need to read the netconfig db.
276  * If we have been here and the next entry is there, we just return
277  * it.
278  */
279  if (ncp->flag == 0) { /* first time */
280  ncp->flag = 1;
281  ncp->nc_configs = ni.head;
282  if (ncp->nc_configs != NULL) /* entry already exist */
283  return(ncp->nc_configs->ncp);
284  }
285  else if (ncp->nc_configs != NULL && ncp->nc_configs->next != NULL) {
286  ncp->nc_configs = ncp->nc_configs->next;
287  return(ncp->nc_configs->ncp);
288  }
289 
290  /*
291  * If we cannot find the entry in the list and is end of file,
292  * we give up.
293  */
294  if (ni.eof == 1)
295  return(NULL);
296  break;
297  default:
299  return (NULL);
300  }
301 
302  stringp = (char *) malloc(MAXNETCONFIGLINE);
303  if (stringp == NULL)
304  return (NULL);
305 
306 #ifdef MEM_CHK
307  if (malloc_verify() == 0) {
308  fprintf(stderr, "memory heap corrupted in getnetconfig\n");
309  exit(1);
310  }
311 #endif
312 
313  /*
314  * Read a line from netconfig file.
315  */
316  do {
317  if (fgets(stringp, MAXNETCONFIGLINE, nc_file) == NULL) {
318  free(stringp);
319  ni.eof = 1;
320  return (NULL);
321  }
322  } while (*stringp == '#');
323 
324  list = (struct netconfig_list *) malloc(sizeof (struct netconfig_list));
325  if (list == NULL) {
326  free(stringp);
327  return(NULL);
328  }
329  np = (struct netconfig *) malloc(sizeof (struct netconfig));
330  if (np == NULL) {
331  free(stringp);
332  free(list);
333  return(NULL);
334  }
335  list->ncp = np;
336  list->next = NULL;
337  list->ncp->nc_lookups = NULL;
338  list->linep = stringp;
339  wintirpc_debug("%s: before parse: &list->linep %p, list->linep %p, stringp %p\n", __FUNCTION__, &list->linep, list->linep, stringp);
340  if (parse_ncp(stringp, list->ncp) == -1) {
341  free(stringp);
342  free(np);
343  free(list);
344  return (NULL);
345  } else {
346  wintirpc_debug("%s: after parse: list->linep %p, stringp %p\n", __FUNCTION__, list->linep, stringp);
347  /*
348  * If this is the first entry that's been read, it is the head of
349  * the list. If not, put the entry at the end of the list.
350  * Reposition the current pointer of the handle to the last entry
351  * in the list.
352  */
353  if (ni.head == NULL) { /* first entry */
354  ni.head = ni.tail = list;
355  }
356  else {
357  ni.tail->next = list;
358  ni.tail = ni.tail->next;
359  }
360  ncp->nc_configs = ni.tail;
361  return(ni.tail->ncp);
362  }
363 }
#define MAXNETCONFIGLINE
Definition: getnetconfig.c:160
static struct netconfig_info ni
Definition: getnetconfig.c:158
#define free
Definition: debug_ros.c:5
#define NC_VALID
Definition: getnetconfig.c:147
#define nc_error
Definition: getnetconfig.c:196
_Check_return_opt_ _CRTIMP int __cdecl fprintf(_Inout_ FILE *_File, _In_z_ _Printf_format_string_ const char *_Format,...)
smooth NULL
Definition: ftsmooth.c:416
struct list * next
Definition: list.h:38
static int parse_ncp(char *, struct netconfig *)
Definition: getnetconfig.c:555
Definition: _list.h:228
#define NC_NOTINIT
Definition: getnetconfig.c:96
_Check_return_opt_ _CRTIMP char *__cdecl fgets(_Out_writes_z_(_MaxCount) char *_Buf, _In_ int _MaxCount, _Inout_ FILE *_File)
struct netconfig_list * nc_configs
Definition: getnetconfig.c:144
static FILE * nc_file
Definition: getnetconfig.c:157
#define list
Definition: rosglue.h:35
FILE * stderr
#define malloc
Definition: debug_ros.c:4
void exit(int exitcode)
Definition: _exit.c:33
#define __FUNCTION__
Definition: types.h:112
static void wintirpc_debug(char *fmt,...)
Definition: getnetconfig.c:49

Referenced by __rpc_getconf(), __rpc_getconfip(), __rpcbind_is_up(), _des_crypt_call(), getkeyserv_handle(), getnetpath(), and local_rpcb().

◆ getnetconfigent()

struct netconfig* getnetconfigent ( char netid) const

Definition at line 432 of file getnetconfig.c.

434 {
435  FILE *file; /* NETCONFIG db's file pointer */
436  char *linep; /* holds current netconfig line */
437  char *stringp; /* temporary string pointer */
438  struct netconfig *ncp = NULL; /* returned value */
439  struct netconfig_list *list; /* pointer to cache list */
440 
441  nc_error = NC_NOTFOUND; /* default error. */
442  if (netid == NULL || strlen(netid) == 0) {
443  return (NULL);
444  }
445 
446  if (strcmp(netid, "unix") == 0) {
447  fprintf(stderr, "The local transport is called \"unix\" ");
448  fprintf(stderr, "in /etc/netconfig.\n");
449  fprintf(stderr, "Please change this to \"local\" manually ");
450  fprintf(stderr, "or run mergemaster(8).\n");
451  fprintf(stderr, "See UPDATING entry 20021216 for details.\n");
452  fprintf(stderr, "Continuing in 10 seconds\n\n");
453  fprintf(stderr, "This warning will be removed 20030301\n");
454  Sleep(10000); // sleep(10);
455  }
456 
457  /*
458  * Look up table if the entries have already been read and parsed in
459  * getnetconfig(), then copy this entry into a buffer and return it.
460  * If we cannot find the entry in the current list and there are more
461  * entries in the netconfig db that has not been read, we then read the
462  * db and try find the match netid.
463  * If all the netconfig db has been read and placed into the list and
464  * there is no match for the netid, return NULL.
465  */
466  if (ni.head != NULL) {
467  for (list = ni.head; list; list = list->next) {
468  if (strcmp(list->ncp->nc_netid, netid) == 0) {
469  return(dup_ncp(list->ncp));
470  }
471  }
472  if (ni.eof == 1) /* that's all the entries */
473  return(NULL);
474  }
475 
476 
477  if ((file = fopen(NETCONFIG, "r")) == NULL) {
479  return (NULL);
480  }
481 
482  if ((linep = malloc(MAXNETCONFIGLINE)) == NULL) {
483  fclose(file);
484  nc_error = NC_NOMEM;
485  return (NULL);
486  }
487  do {
488  ptrdiff_t len;
489  char *tmpp; /* tmp string pointer */
490 
491  do {
492  if ((stringp = fgets(linep, MAXNETCONFIGLINE, file)) == NULL) {
493  break;
494  }
495  } while (*stringp == '#');
496  if (stringp == NULL) { /* eof */
497  break;
498  }
499  if ((tmpp = strpbrk(stringp, "\t ")) == NULL) { /* can't parse file */
501  break;
502  }
503  if (strlen(netid) == (size_t) (len = tmpp - stringp) && /* a match */
504  strncmp(stringp, netid, (size_t)len) == 0) {
505  if ((ncp = (struct netconfig *)
506  malloc(sizeof (struct netconfig))) == NULL) {
507  break;
508  }
509  ncp->nc_lookups = NULL;
510  if (parse_ncp(linep, ncp) == -1) {
511  free(ncp);
512  ncp = NULL;
513  }
514  break;
515  }
516  } while (stringp != NULL);
517  if (ncp == NULL) {
518  free(linep);
519  }
520  fclose(file);
521  return(ncp);
522 }
#define MAXNETCONFIGLINE
Definition: getnetconfig.c:160
static struct netconfig * dup_ncp(struct netconfig *)
Definition: getnetconfig.c:689
VOID WINAPI DECLSPEC_HOTPATCH Sleep(IN DWORD dwMilliseconds)
Definition: synch.c:790
ACPI_SIZE strlen(const char *String)
Definition: utclib.c:269
char * strpbrk(const char *String, const char *Delimiters)
Definition: utclib.c:302
static struct netconfig_info ni
Definition: getnetconfig.c:158
#define free
Definition: debug_ros.c:5
struct netconfig * ncp
Definition: getnetconfig.c:137
#define nc_error
Definition: getnetconfig.c:196
_Check_return_opt_ _CRTIMP int __cdecl fprintf(_Inout_ FILE *_File, _In_z_ _Printf_format_string_ const char *_Format,...)
smooth NULL
Definition: ftsmooth.c:416
const char file[]
Definition: icontest.c:11
int strncmp(const char *String1, const char *String2, ACPI_SIZE Count)
Definition: utclib.c:534
struct list * next
Definition: list.h:38
static int parse_ncp(char *, struct netconfig *)
Definition: getnetconfig.c:555
#define NC_NONETCONFIG
Definition: getnetconfig.c:94
GLenum GLsizei len
Definition: glext.h:6722
Definition: _list.h:228
_Check_return_opt_ _CRTIMP int __cdecl fclose(_Inout_ FILE *_File)
_Check_return_ _CRTIMP FILE *__cdecl fopen(_In_z_ const char *_Filename, _In_z_ const char *_Mode)
_Check_return_opt_ _CRTIMP char *__cdecl fgets(_Out_writes_z_(_MaxCount) char *_Buf, _In_ int _MaxCount, _Inout_ FILE *_File)
#define NC_NOTFOUND
Definition: getnetconfig.c:98
#define list
Definition: rosglue.h:35
__kernel_ptrdiff_t ptrdiff_t
Definition: linux.h:247
#define NETCONFIG
Definition: netconfig.h:7
#define NC_NOMEM
Definition: getnetconfig.c:95
FILE * stderr
int strcmp(const char *String1, const char *String2)
Definition: utclib.c:469
#define malloc
Definition: debug_ros.c:4
#define NC_BADFILE
Definition: getnetconfig.c:97
Definition: fci.c:126

Referenced by __rpc_getconfip(), __rpc_sockinfo2netid(), __rpcb_findaddr_timed(), __rpcgettp(), cache_get(), cache_set(), get_client_for_netaddr(), getnetpath(), local_rpcb(), and nfs41_server_resolve().

◆ nc_perror()

void nc_perror ( char s) const

Definition at line 679 of file getnetconfig.c.

681 {
682  fprintf(stderr, "%s: %s\n", s, nc_sperror());
683 }
_Check_return_opt_ _CRTIMP int __cdecl fprintf(_Inout_ FILE *_File, _In_z_ _Printf_format_string_ const char *_Format,...)
GLdouble s
Definition: gl.h:2039
char * nc_sperror()
Definition: getnetconfig.c:648
FILE * stderr

◆ nc_sperror()

char* nc_sperror ( void  )

Definition at line 648 of file getnetconfig.c.

649 {
650  const char *message;
651 
652  switch(nc_error) {
653  case NC_NONETCONFIG:
654  message = _nc_errors[0];
655  break;
656  case NC_NOMEM:
657  message = _nc_errors[1];
658  break;
659  case NC_NOTINIT:
660  message = _nc_errors[2];
661  break;
662  case NC_BADFILE:
663  message = _nc_errors[3];
664  break;
665  case NC_NOTFOUND:
666  message = _nc_errors[4];
667  break;
668  default:
669  message = "Unknown network selection error";
670  }
671  /* LINTED const castaway */
672  return ((char *)message);
673 }
Definition: tftpd.h:59
GLenum GLuint GLenum GLsizei const GLchar * message
Definition: glext.h:5579
static const char *const _nc_errors[]
Definition: getnetconfig.c:120
#define nc_error
Definition: getnetconfig.c:196
#define NC_NONETCONFIG
Definition: getnetconfig.c:94
#define NC_NOTINIT
Definition: getnetconfig.c:96
#define NC_NOTFOUND
Definition: getnetconfig.c:98
#define NC_NOMEM
Definition: getnetconfig.c:95
#define NC_BADFILE
Definition: getnetconfig.c:97

Referenced by nc_perror().

◆ parse_ncp()

static int parse_ncp ( char stringp,
struct netconfig ncp 
)
static

Definition at line 555 of file getnetconfig.c.

558 {
559  char *tokenp; /* for processing tokens */
560  char *lasts;
561 
562  nc_error = NC_BADFILE; /* nearly anything that breaks is for this reason */
563  wintirpc_debug("%s: The last character being chopped is '%02x'\n", __FUNCTION__, stringp[strlen(stringp)-1]);
564  wintirpc_debug("%s: The string before chopping is '%s'\n", __FUNCTION__, stringp);
565  stringp[strlen(stringp)-1] = '\0'; /* get rid of newline */
566  wintirpc_debug("%s: The last character after chopping is '%02x'\n", __FUNCTION__, stringp[strlen(stringp)-1]);
567  wintirpc_debug("%s: The string after chopping is '%s'\n", __FUNCTION__, stringp);
568  /* netid */
569  if ((ncp->nc_netid = strtok_r(stringp, "\t ", &lasts)) == NULL) {
570  return (-1);
571  }
572 
573  /* semantics */
574  if ((tokenp = strtok_r(NULL, "\t ", &lasts)) == NULL) {
575  return (-1);
576  }
577  if (strcmp(tokenp, NC_TPI_COTS_ORD_S) == 0)
578  ncp->nc_semantics = NC_TPI_COTS_ORD;
579  else if (strcmp(tokenp, NC_TPI_COTS_S) == 0)
580  ncp->nc_semantics = NC_TPI_COTS;
581  else if (strcmp(tokenp, NC_TPI_CLTS_S) == 0)
582  ncp->nc_semantics = NC_TPI_CLTS;
583  else if (strcmp(tokenp, NC_TPI_RAW_S) == 0)
584  ncp->nc_semantics = NC_TPI_RAW;
585  else
586  return (-1);
587 
588  /* flags */
589  if ((tokenp = strtok_r(NULL, "\t ", &lasts)) == NULL) {
590  return (-1);
591  }
592  for (ncp->nc_flag = NC_NOFLAG; *tokenp != '\0';
593  tokenp++) {
594  switch (*tokenp) {
595  case NC_NOFLAG_C:
596  break;
597  case NC_VISIBLE_C:
598  ncp->nc_flag |= NC_VISIBLE;
599  break;
600  case NC_BROADCAST_C:
601  ncp->nc_flag |= NC_BROADCAST;
602  break;
603  default:
604  return (-1);
605  }
606  }
607  /* protocol family */
608  if ((ncp->nc_protofmly = strtok_r(NULL, "\t ", &lasts)) == NULL) {
609  return (-1);
610  }
611  /* protocol name */
612  if ((ncp->nc_proto = strtok_r(NULL, "\t ", &lasts)) == NULL) {
613  return (-1);
614  }
615  /* network device */
616  if ((ncp->nc_device = strtok_r(NULL, "\t ", &lasts)) == NULL) {
617  return (-1);
618  }
619  if ((tokenp = strtok_r(NULL, "\t ", &lasts)) == NULL) {
620  return (-1);
621  }
622  if (strcmp(tokenp, NC_NOLOOKUP) == 0) {
623  ncp->nc_nlookups = 0;
624  ncp->nc_lookups = NULL;
625  } else {
626  char *cp; /* tmp string */
627 
628  if (ncp->nc_lookups != NULL) /* from last visit */
629  free(ncp->nc_lookups);
630  /* preallocate one string pointer */
631  ncp->nc_lookups = (char **)malloc(sizeof (char *));
632  ncp->nc_nlookups = 0;
633  while ((cp = tokenp) != NULL) {
634  tokenp = _get_next_token(cp, ',');
635  ncp->nc_lookups[(size_t)ncp->nc_nlookups++] = cp;
636  ncp->nc_lookups = (char **)realloc(ncp->nc_lookups,
637  (size_t)(ncp->nc_nlookups+1) *sizeof(char *)); /* for next loop */
638  }
639  }
640  return (0);
641 }
#define realloc
Definition: debug_ros.c:6
ACPI_SIZE strlen(const char *String)
Definition: utclib.c:269
#define NC_TPI_CLTS
Definition: netconfig.h:30
#define free
Definition: debug_ros.c:5
#define NC_BROADCAST
Definition: netconfig.h:40
#define NC_TPI_COTS_ORD_S
Definition: getnetconfig.c:105
struct netconfig * ncp
Definition: getnetconfig.c:137
#define NC_NOFLAG
Definition: netconfig.h:38
char * _get_next_token(char *, int)
Definition: getnetpath.c:228
#define strtok_r
Definition: wintirpc.h:57
#define NC_VISIBLE_C
Definition: getnetconfig.c:112
#define nc_error
Definition: getnetconfig.c:196
#define NC_TPI_COTS_ORD
Definition: netconfig.h:32
#define NC_TPI_RAW
Definition: netconfig.h:33
#define NC_TPI_COTS_S
Definition: getnetconfig.c:104
smooth NULL
Definition: ftsmooth.c:416
#define NC_VISIBLE
Definition: netconfig.h:39
#define NC_NOFLAG_C
Definition: getnetconfig.c:111
__kernel_size_t size_t
Definition: linux.h:237
#define NC_BROADCAST_C
Definition: getnetconfig.c:113
#define NC_TPI_CLTS_S
Definition: getnetconfig.c:103
#define NC_TPI_COTS
Definition: netconfig.h:31
#define NC_NOLOOKUP
Definition: getnetconfig.c:118
#define NC_TPI_RAW_S
Definition: getnetconfig.c:106
POINT cp
Definition: magnifier.c:59
int strcmp(const char *String1, const char *String2)
Definition: utclib.c:469
#define malloc
Definition: debug_ros.c:4
#define __FUNCTION__
Definition: types.h:112
#define NC_BADFILE
Definition: getnetconfig.c:97
static void wintirpc_debug(char *fmt,...)
Definition: getnetconfig.c:49

Referenced by getnetconfig(), and getnetconfigent().

◆ setnetconfig()

void* setnetconfig ( void  )

Definition at line 217 of file getnetconfig.c.

218 {
219  struct netconfig_vars *nc_vars;
220 
221  if ((nc_vars = (struct netconfig_vars *)malloc(sizeof
222  (struct netconfig_vars))) == NULL) {
223  return(NULL);
224  }
225 
226  /*
227  * For multiple calls, i.e. nc_file is not NULL, we just return the
228  * handle without reopening the netconfig db.
229  */
230  ni.ref++;
231  if ((nc_file != NULL) || (nc_file = fopen(NETCONFIG, "r")) != NULL) {
232  nc_vars->valid = NC_VALID;
233  nc_vars->flag = 0;
234  nc_vars->nc_configs = ni.head;
235  return ((void *)nc_vars);
236  }
237  ni.ref--;
239  free(nc_vars);
240  return (NULL);
241 }
static struct netconfig_info ni
Definition: getnetconfig.c:158
#define free
Definition: debug_ros.c:5
#define NC_VALID
Definition: getnetconfig.c:147
#define nc_error
Definition: getnetconfig.c:196
smooth NULL
Definition: ftsmooth.c:416
#define NC_NONETCONFIG
Definition: getnetconfig.c:94
_Check_return_ _CRTIMP FILE *__cdecl fopen(_In_z_ const char *_Filename, _In_z_ const char *_Mode)
struct netconfig_list * nc_configs
Definition: getnetconfig.c:144
static FILE * nc_file
Definition: getnetconfig.c:157
#define NETCONFIG
Definition: netconfig.h:7
#define malloc
Definition: debug_ros.c:4

Referenced by __rpc_getconfip(), __rpc_setconf(), __rpcbind_is_up(), _des_crypt_call(), getkeyserv_handle(), getnetpath(), local_rpcb(), and setnetpath().

◆ wintirpc_debug()

static void wintirpc_debug ( char fmt,
  ... 
)
static

Definition at line 49 of file getnetconfig.c.

50 {
51  return;
52 }

Referenced by getnetconfig(), and parse_ncp().

Variable Documentation

◆ _nc_errors

const char* const _nc_errors[]
static
Initial value:
= {
"Netconfig database not found",
"Not enough memory",
"Not initialized",
"Netconfig database has invalid format",
"Netid not found in netconfig database"
}

Definition at line 120 of file getnetconfig.c.

Referenced by nc_sperror().

◆ nc_file

FILE* nc_file
static

Definition at line 157 of file getnetconfig.c.

Referenced by endnetconfig(), getnetconfig(), and setnetconfig().

◆ ni