ReactOS 0.4.15-dev-7711-g5627da4
getnetpath.c File Reference
#include <wintirpc.h>
#include <stdio.h>
#include <errno.h>
#include <netconfig.h>
#include <stdlib.h>
#include <string.h>
Include dependency graph for getnetpath.c:

Go to the source code of this file.

Classes

struct  netpath_chain
 
struct  netpath_vars
 

Macros

#define NP_VALID   0xf00d
 
#define NP_INVALID   0
 

Functions

char_get_next_token (char *, int)
 
voidsetnetpath ()
 
struct netconfiggetnetpath (void *handlep)
 
int endnetpath (void *handlep)
 

Macro Definition Documentation

◆ NP_INVALID

#define NP_INVALID   0

Definition at line 61 of file getnetpath.c.

◆ NP_VALID

#define NP_VALID   0xf00d

Definition at line 60 of file getnetpath.c.

Function Documentation

◆ _get_next_token()

char * _get_next_token ( char npp,
int  token 
)

Definition at line 228 of file getnetpath.c.

231{
232 char *cp; /* char pointer */
233 char *np; /* netpath pointer */
234 char *ep; /* escape pointer */
235
236 if ((cp = strchr(npp, token)) == NULL) {
237 return (NULL);
238 }
239 /*
240 * did find a token, but it might be escaped.
241 */
242 if ((cp > npp) && (cp[-1] == '\\')) {
243 /* if slash was also escaped, carry on, otherwise find next token */
244 if ((cp > npp + 1) && (cp[-2] != '\\')) {
245 /* shift r-o-s onto the escaped token */
246 strcpy(&cp[-1], cp); /* XXX: overlapping string copy */
247 /*
248 * Do a recursive call.
249 * We don't know how many escaped tokens there might be.
250 */
251 return (_get_next_token(cp, token));
252 }
253 }
254
255 *cp++ = '\0'; /* null-terminate token */
256 /* get rid of any backslash escapes */
257 ep = npp;
258 while ((np = strchr(ep, '\\')) != 0) {
259 if (np[1] == '\\')
260 np++;
261 strcpy(np, (ep = &np[1])); /* XXX: overlapping string copy */
262 }
263 return (cp); /* return ptr to r-o-s */
264}
char * strcpy(char *DstString, const char *SrcString)
Definition: utclib.c:388
char * strchr(const char *String, int ch)
Definition: utclib.c:501
#define NULL
Definition: types.h:112
char * _get_next_token(char *, int)
Definition: getnetpath.c:228
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 token
Definition: glfuncs.h:210
POINT cp
Definition: magnifier.c:59

Referenced by _get_next_token(), getnetpath(), and parse_ncp().

◆ endnetpath()

int endnetpath ( void handlep)

Definition at line 191 of file getnetpath.c.

193{
194 struct netpath_vars *np_sessionp = (struct netpath_vars *)handlep;
195 struct netpath_chain *chainp, *lastp;
196
197 if (np_sessionp == NULL || np_sessionp->valid != NP_VALID) {
198 errno = EINVAL;
199 return (-1);
200 }
201 if (np_sessionp->nc_handlep != NULL)
202 endnetconfig(np_sessionp->nc_handlep);
203 if (np_sessionp->netpath_start != NULL)
204 free(np_sessionp->netpath_start);
205 for (chainp = np_sessionp->ncp_list; chainp != NULL;
206 lastp=chainp, chainp=chainp->nchain_next, free(lastp)) {
207 freenetconfigent(chainp->ncp);
208 }
209 free(np_sessionp);
210#ifdef MEM_CHK
211 if (malloc_verify() == 0) {
212 fprintf(stderr, "memory heap corrupted in endnetpath\n");
213 exit(1);
214 }
215#endif
216 return (0);
217}
#define EINVAL
Definition: acclib.h:90
#define free
Definition: debug_ros.c:5
void freenetconfigent(struct netconfig *netconfigp)
Definition: getnetconfig.c:530
int endnetconfig(void *handlep)
Definition: getnetconfig.c:373
#define NP_VALID
Definition: getnetpath.c:60
#define stderr
Definition: stdio.h:100
_Check_return_opt_ _CRTIMP int __cdecl fprintf(_Inout_ FILE *_File, _In_z_ _Printf_format_string_ const char *_Format,...)
#define errno
Definition: errno.h:18
#define exit(n)
Definition: config.h:202
struct netconfig * ncp
Definition: getnetpath.c:47
struct netpath_chain * nchain_next
Definition: getnetpath.c:48
char * netpath_start
Definition: getnetpath.c:56
struct netpath_chain * ncp_list
Definition: getnetpath.c:57
void * nc_handlep
Definition: getnetpath.c:54

Referenced by __rpc_endconf().

◆ getnetpath()

struct netconfig * getnetpath ( void handlep)

Definition at line 134 of file getnetpath.c.

136{
137 struct netpath_vars *np_sessionp = (struct netpath_vars *)handlep;
138 struct netconfig *ncp = NULL; /* temp. holds a netconfig session */
139 struct netpath_chain *chainp; /* holds chain of ncp's we alloc */
140 char *npp; /* holds current NETPATH */
141
142 if (np_sessionp == NULL || np_sessionp->valid != NP_VALID) {
143 errno = EINVAL;
144 return (NULL);
145 }
146 if (np_sessionp->netpath_start == NULL) { /* NETPATH was not set */
147 do { /* select next visible network */
148 if (np_sessionp->nc_handlep == NULL) {
149 np_sessionp->nc_handlep = setnetconfig();
150 if (np_sessionp->nc_handlep == NULL) {
151 //syslog (LOG_ERR, "rpc: failed to open " NETCONFIG);
152 }
153 }
154 if ((ncp = getnetconfig(np_sessionp->nc_handlep)) == NULL) {
155 return(NULL);
156 }
157 } while ((ncp->nc_flag & NC_VISIBLE) == 0);
158 return (ncp);
159 }
160 /*
161 * Find first valid network ID in netpath.
162 */
163 while ((npp = np_sessionp->netpath) != NULL && strlen(npp) != 0) {
164 np_sessionp->netpath = _get_next_token(npp, ':');
165 /*
166 * npp is a network identifier.
167 */
168 if ((ncp = getnetconfigent(npp)) != NULL) {
169 chainp = (struct netpath_chain *) /* cobble alloc chain entry */
170 malloc(sizeof (struct netpath_chain));
171 chainp->ncp = ncp;
172 chainp->nchain_next = NULL;
173 if (np_sessionp->ncp_list == NULL) {
174 np_sessionp->ncp_list = chainp;
175 } else {
176 np_sessionp->ncp_list->nchain_next = chainp;
177 }
178 return (ncp);
179 }
180 /* couldn't find this token in the database; go to next one. */
181 }
182 return (NULL);
183}
ACPI_SIZE strlen(const char *String)
Definition: utclib.c:269
#define malloc
Definition: debug_ros.c:4
struct netconfig * getnetconfigent(char *netid) const
Definition: getnetconfig.c:432
struct netconfig * getnetconfig(void *handlep)
Definition: getnetconfig.c:253
void * setnetconfig()
Definition: getnetconfig.c:217
#define NC_VISIBLE
Definition: netconfig.h:44
char * netpath
Definition: getnetpath.c:55

Referenced by __rpc_getconf().

◆ setnetpath()

void * setnetpath ( void  )

Definition at line 78 of file getnetpath.c.

79{
80
81 struct netpath_vars *np_sessionp; /* this session's variables */
82 char *npp; /* NETPATH env variable */
83
84#ifdef MEM_CHK
85 malloc_debug(1);
86#endif
87
88 if ((np_sessionp =
89 (struct netpath_vars *)malloc(sizeof (struct netpath_vars))) == NULL) {
90 return (NULL);
91 }
92 if ((np_sessionp->nc_handlep = setnetconfig()) == NULL) {
93 //syslog (LOG_ERR, "rpc: failed to open " NETCONFIG);
94 return (NULL);
95 }
96 np_sessionp->valid = NP_VALID;
97 np_sessionp->ncp_list = NULL;
98 if ((npp = getenv(NETPATH)) == NULL) {
99 np_sessionp->netpath = NULL;
100 } else {
101 (void) endnetconfig(np_sessionp->nc_handlep);/* won't need nc session*/
102 np_sessionp->nc_handlep = NULL;
103 if ((np_sessionp->netpath = malloc(strlen(npp)+1)) == NULL) {
104 free(np_sessionp);
105 return (NULL);
106 } else {
107 (void) strcpy(np_sessionp->netpath, npp);
108 }
109 }
110 np_sessionp->netpath_start = np_sessionp->netpath;
111 return ((void *)np_sessionp);
112}
_Check_return_ char *__cdecl getenv(_In_z_ const char *_VarName)
#define NETPATH
Definition: netconfig.h:13

Referenced by __rpc_setconf().