ReactOS 0.4.15-dev-7953-g1f49173
netnamer.c File Reference
#include <wintirpc.h>
#include <sys/param.h>
#include <rpc/rpc.h>
#include "rpc_com.h"
#include <ctype.h>
#include <stdio.h>
#include <grp.h>
#include <pwd.h>
#include <string.h>
#include <stdlib.h>
#include <unistd.h>
Include dependency graph for netnamer.c:

Go to the source code of this file.

Macros

#define NGROUPS   16
 

Functions

static int getnetid (char *, char *)
 
static int _getgroups (char *, gid_t *)
 
int netname2user (netname, uid_t *uidp, gid_t *gidp, int *gidlenp, gid_t *gidlist)
 
static int _getgroups (char *uname, groups)
 
int netname2host (netname, char *hostname, int hostlen)
 

Variables

static charOPSYS = "unix"
 
static charNETID = "netid.byname"
 
static charNETIDFILE = "/etc/netid"
 

Macro Definition Documentation

◆ NGROUPS

#define NGROUPS   16

Definition at line 60 of file netnamer.c.

Function Documentation

◆ _getgroups() [1/2]

static int _getgroups ( char ,
gid_t  
)
static

Referenced by netname2user().

◆ _getgroups() [2/2]

static int _getgroups ( char uname,
groups   
)
static

Definition at line 149 of file netnamer.c.

152{
153 gid_t ngroups = 0;
154 struct group *grp;
155 int i;
156 int j;
157 int filter;
158
159 setgrent();
160 while ((grp = getgrent())) {
161 for (i = 0; grp->gr_mem[i]; i++)
162 if (!strcmp(grp->gr_mem[i], uname)) {
163 if (ngroups == NGROUPS) {
164#ifdef DEBUG
166 "initgroups: %s is in too many groups\n", uname);
167#endif
168 goto toomany;
169 }
170 /* filter out duplicate group entries */
171 filter = 0;
172 for (j = 0; j < ngroups; j++)
173 if (groups[j] == grp->gr_gid) {
174 filter++;
175 break;
176 }
177 if (!filter)
178 groups[ngroups++] = grp->gr_gid;
179 }
180 }
181toomany:
182 endgrent();
183 return (ngroups);
184}
int strcmp(const char *String1, const char *String2)
Definition: utclib.c:469
UINT gid_t
Definition: types.h:89
GLsizei GLuint * groups
Definition: glext.h:11113
GLint GLint GLint GLint GLint GLint GLint GLbitfield GLenum filter
Definition: glext.h:7005
GLboolean GLuint group
Definition: glext.h:11120
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
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 GLint GLint j
Definition: glfuncs.h:250
#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 NGROUPS
Definition: netnamer.c:60

◆ getnetid()

int getnetid ( char key,
char ret 
)
static

Definition at line 239 of file netnamer.c.

241{
242 char buf[1024]; /* big enough */
243 char *res;
244 char *mkey;
245 char *mval;
246 FILE *fd;
247#ifdef YP
248 char *domain;
249 int err;
250 char *lookup;
251 int len;
252#endif
253
254 fd = fopen(NETIDFILE, "r");
255 if (fd == NULL) {
256#ifdef YP
257 res = "+";
258 goto getnetidyp;
259#else
260 return (0);
261#endif
262 }
263 for (;;) {
264 if (fd == NULL)
265 return (0); /* getnetidyp brings us here */
266 res = fgets(buf, sizeof(buf), fd);
267 if (res == NULL) {
268 fclose(fd);
269 return (0);
270 }
271 if (res[0] == '#')
272 continue;
273 else if (res[0] == '+') {
274#ifdef YP
275 getnetidyp:
276 err = yp_get_default_domain(&domain);
277 if (err) {
278 continue;
279 }
280 lookup = NULL;
281 err = yp_match(domain, NETID, key,
282 strlen(key), &lookup, &len);
283 if (err) {
284#ifdef DEBUG
285 fprintf(stderr, "match failed error %d\n", err);
286#endif
287 continue;
288 }
289 lookup[len] = 0;
290 strcpy(ret, lookup);
291 free(lookup);
292 if (fd != NULL)
293 fclose(fd);
294 return (2);
295#else /* YP */
296#ifdef DEBUG
298"Bad record in %s '+' -- NIS not supported in this library copy\n",
299 NETIDFILE);
300#endif
301 continue;
302#endif /* YP */
303 } else {
304 mkey = strsep(&res, "\t ");
305 if (mkey == NULL) {
307 "Bad record in %s -- %s", NETIDFILE, buf);
308 continue;
309 }
310 do {
311 mval = strsep(&res, " \t#\n");
312 } while (mval != NULL && !*mval);
313 if (mval == NULL) {
315 "Bad record in %s val problem - %s", NETIDFILE, buf);
316 continue;
317 }
318 if (strcmp(mkey, key) == 0) {
319 strcpy(ret, mval);
320 fclose(fd);
321 return (1);
322
323 }
324 }
325 }
326}
ACPI_SIZE strlen(const char *String)
Definition: utclib.c:269
char * strcpy(char *DstString, const char *SrcString)
Definition: utclib.c:388
#define free
Definition: debug_ros.c:5
#define NULL
Definition: types.h:112
static ULONG lookup[16]
Definition: vga.c:48
GLuint res
Definition: glext.h:9613
GLenum GLuint GLenum GLsizei const GLchar * buf
Definition: glext.h:7751
GLenum GLsizei len
Definition: glext.h:6722
_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)
_Check_return_opt_ _CRTIMP int __cdecl fclose(_Inout_ FILE *_File)
static char * NETIDFILE
Definition: netnamer.c:54
static char * NETID
Definition: netnamer.c:53
#define err(...)
static int fd
Definition: io.c:51
Definition: cookie.c:42
Definition: copy.c:22
int ret

Referenced by netname2host(), and netname2user().

◆ netname2host()

int netname2host ( netname  ,
char hostname,
int  hostlen 
)

Definition at line 190 of file netnamer.c.

194{
195 int err;
196 char valbuf[1024];
197 char *val;
198 char *val2;
199 int vallen;
200 char *domain;
201
202 if (getnetid(netname, valbuf)) {
203 val = valbuf;
204 if ((*val == '0') && (val[1] == ':')) {
205 (void) strncpy(hostname, val + 2, hostlen);
206 return (1);
207 }
208 }
209 val = strchr(netname, '.');
210 if (val == NULL)
211 return (0);
212 if (strncmp(netname, OPSYS, (val - netname)))
213 return (0);
214 val++;
215 val2 = strchr(val, '@');
216 if (val2 == NULL)
217 return (0);
218 vallen = val2 - val;
219 if (vallen > (hostlen - 1))
220 vallen = hostlen - 1;
221 (void) strncpy(hostname, val, vallen);
222 hostname[vallen] = 0;
223
224 err = __rpc_get_default_domain(&domain); /* change to rpc */
225 if (err)
226 return (0);
227
228 if (strcmp(val2 + 1, domain))
229 return (0); /* wrong domain */
230 else
231 return (1);
232}
int strncmp(const char *String1, const char *String2, ACPI_SIZE Count)
Definition: utclib.c:534
char * strncpy(char *DstString, const char *SrcString, ACPI_SIZE Count)
Definition: utclib.c:427
char * strchr(const char *String, int ch)
Definition: utclib.c:501
char * hostname
Definition: ftp.c:88
GLuint GLfloat * val
Definition: glext.h:7180
static char * OPSYS
Definition: netnamer.c:52
static int getnetid(char *, char *)
Definition: netnamer.c:239
int __rpc_get_default_domain(char **)
Definition: rpcdname.c:72

◆ netname2user()

int netname2user ( netname  ,
uid_t uidp,
gid_t gidp,
int gidlenp,
gid_t gidlist 
)

Definition at line 67 of file netnamer.c.

73{
74 char *p;
75 int gidlen;
76 uid_t uid;
77 long luid;
78 struct passwd *pwd;
79 char val[1024];
80 char *val1, *val2;
81 char *domain;
82 int vallen;
83 int err;
84
85 if (getnetid(netname, val)) {
86 char *res = val;
87
88 p = strsep(&res, ":");
89 if (p == NULL)
90 return (0);
91 *uidp = (uid_t) atol(p);
92 p = strsep(&res, "\n,");
93 if (p == NULL) {
94 return (0);
95 }
96 *gidp = (gid_t) atol(p);
97 gidlen = 0;
98 for (gidlen = 0; gidlen < NGROUPS; gidlen++) {
99 p = strsep(&res, "\n,");
100 if (p == NULL)
101 break;
102 gidlist[gidlen] = (gid_t) atol(p);
103 }
104 *gidlenp = gidlen;
105
106 return (1);
107 }
108 val1 = strchr(netname, '.');
109 if (val1 == NULL)
110 return (0);
111 if (strncmp(netname, OPSYS, (val1-netname)))
112 return (0);
113 val1++;
114 val2 = strchr(val1, '@');
115 if (val2 == NULL)
116 return (0);
117 vallen = val2 - val1;
118 if (vallen > (1024 - 1))
119 vallen = 1024 - 1;
120 (void) strncpy(val, val1, 1024);
121 val[vallen] = 0;
122
123 err = __rpc_get_default_domain(&domain); /* change to rpc */
124 if (err)
125 return (0);
126
127 if (strcmp(val2 + 1, domain))
128 return (0); /* wrong domain */
129
130 if (sscanf(val, "%ld", &luid) != 1)
131 return (0);
132 uid = luid;
133
134 /* use initgroups method */
135 pwd = getpwuid(uid);
136 if (pwd == NULL)
137 return (0);
138 *uidp = pwd->pw_uid;
139 *gidp = pwd->pw_gid;
140 *gidlenp = _getgroups(pwd->pw_name, gidlist);
141 return (1);
142}
long uid_t
Definition: various.h:8
void pwd(int argc, const char *argv[])
Definition: cmds.c:1401
#define gid_t
Definition: types.h:71
#define uid_t
Definition: types.h:70
GLfloat GLfloat p
Definition: glext.h:8902
_Check_return_ _CRTIMP int __cdecl sscanf(_In_z_ const char *_Src, _In_z_ _Scanf_format_string_ const char *_Format,...)
_Check_return_ long __cdecl atol(_In_z_ const char *_Str)
static int _getgroups(char *, gid_t *)

Variable Documentation

◆ NETID

char* NETID = "netid.byname"
static

Definition at line 53 of file netnamer.c.

Referenced by getnetid().

◆ NETIDFILE

char* NETIDFILE = "/etc/netid"
static

Definition at line 54 of file netnamer.c.

Referenced by getnetid().

◆ OPSYS

char* OPSYS = "unix"
static

Definition at line 52 of file netnamer.c.

Referenced by netname2host(), and netname2user().