ReactOS  0.4.14-dev-41-g31d7680
auth_unix.c File Reference
#include <wintirpc.h>
#include <reentrant.h>
#include <assert.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <rpc/types.h>
#include <rpc/xdr.h>
#include <rpc/auth.h>
#include <rpc/auth_unix.h>
Include dependency graph for auth_unix.c:

Go to the source code of this file.

Classes

struct  audata
 

Macros

#define AUTH_PRIVATE(auth)   ((struct audata *)auth->ah_private)
 

Functions

static void authunix_nextverf (AUTH *)
 
static bool_t authunix_marshal (AUTH *, XDR *, u_int *seq)
 
static bool_t authunix_validate (AUTH *, struct opaque_auth *, u_int)
 
static bool_t authunix_refresh (AUTH *, void *)
 
static void authunix_destroy (AUTH *)
 
static void marshal_new_auth (AUTH *)
 
static struct auth_ops * authunix_ops (void)
 
AUTHauthunix_create (char *machname, uid_t uid, gid_t gid, int len, gid_t *aup_gids)
 
AUTHauthunix_create_default ()
 
static bool_t authunix_wrap (AUTH *auth, XDR *xdrs, xdrproc_t func, caddr_t args, u_int seq)
 

Macro Definition Documentation

◆ AUTH_PRIVATE

#define AUTH_PRIVATE (   auth)    ((struct audata *)auth->ah_private)

Definition at line 100 of file auth_unix.c.

Function Documentation

◆ authunix_create()

AUTH* authunix_create ( char machname,
uid_t  uid,
gid_t  gid,
int  len,
gid_t aup_gids 
)

Definition at line 107 of file auth_unix.c.

113 {
114  struct authunix_parms aup;
115  char mymem[MAX_AUTH_BYTES];
116  struct timeval now;
117  XDR xdrs;
118  AUTH *auth;
119  struct audata *au;
120 
121  /*
122  * Allocate and set up auth handle
123  */
124  au = NULL;
125  auth = mem_alloc(sizeof(*auth));
126 #ifndef _KERNEL
127  if (auth == NULL) {
128  // XXX warnx("authunix_create: out of memory");
129  goto cleanup_authunix_create;
130  }
131 #endif
132  au = mem_alloc(sizeof(*au));
133 #ifndef _KERNEL
134  if (au == NULL) {
135  // XXX warnx("authunix_create: out of memory");
136  goto cleanup_authunix_create;
137  }
138 #endif
139  auth->ah_ops = authunix_ops();
140  auth->ah_private = (caddr_t)au;
141  auth->ah_verf = au->au_shcred = _null_auth;
142  au->au_shfaults = 0;
143  au->au_origcred.oa_base = NULL;
144 
145  /*
146  * fill in param struct from the given params
147  */
149  aup.aup_time = now.tv_sec;
150  aup.aup_machname = machname;
151  aup.aup_uid = uid;
152  aup.aup_gid = gid;
153  aup.aup_len = (u_int)len;
154  aup.aup_gids = aup_gids;
155 
156  /*
157  * Serialize the parameters into origcred
158  */
159  xdrmem_create(&xdrs, mymem, MAX_AUTH_BYTES, XDR_ENCODE);
160  if (! xdr_authunix_parms(&xdrs, &aup))
161  abort();
162  au->au_origcred.oa_length = len = XDR_GETPOS(&xdrs);
163  au->au_origcred.oa_flavor = AUTH_UNIX;
164 #ifdef _KERNEL
165  au->au_origcred.oa_base = mem_alloc((u_int) len);
166 #else
167  if ((au->au_origcred.oa_base = mem_alloc((u_int) len)) == NULL) {
168  // XXX warnx("authunix_create: out of memory");
169  goto cleanup_authunix_create;
170  }
171 #endif
172  memmove(au->au_origcred.oa_base, mymem, (size_t)len);
173 
174  /*
175  * set auth handle to reflect new cred.
176  */
177  auth->ah_cred = au->au_origcred;
178  marshal_new_auth(auth);
179  return (auth);
180 #ifndef _KERNEL
181  cleanup_authunix_create:
182  if (auth)
183  mem_free(auth, sizeof(*auth));
184  if (au) {
185  if (au->au_origcred.oa_base)
186  mem_free(au->au_origcred.oa_base, (u_int)len);
187  mem_free(au, sizeof(*au));
188  }
189  return (NULL);
190 #endif
191 }
#define memmove(s1, s2, n)
Definition: mkisofs.h:881
bool_t xdr_authunix_parms(XDR *xdrs, struct authunix_parms *p)
Definition: authunix_prot.c:50
#define MAX_AUTH_BYTES
Definition: auth.h:77
#define XDR_GETPOS(xdrs)
Definition: xdr.h:199
struct png_info_def **typedef void(__cdecl typeof(png_destroy_read_struct))(struct png_struct_def **
Definition: typeof.h:49
struct opaque_auth au_origcred
Definition: auth_unix.c:94
Definition: auth.h:205
static void marshal_new_auth(AUTH *)
Definition: auth_unix.c:358
Definition: xdr.h:103
#define gettimeofday(tv, tz)
Definition: adns_win32.h:159
#define mem_alloc(bsize)
Definition: types.h:123
struct opaque_auth _null_auth
time_t now
Definition: finger.c:65
static struct auth_ops * authunix_ops(void)
Definition: auth_unix.c:396
smooth NULL
Definition: ftsmooth.c:416
void * ah_private
Definition: auth.h:225
struct opaque_auth ah_verf
Definition: auth.h:207
#define AUTH_UNIX
Definition: auth.h:404
Definition: xdr.h:85
GLenum GLsizei len
Definition: glext.h:6722
#define caddr_t
Definition: ftp.c:24
UINT32 u_int
Definition: types.h:82
u_long au_shfaults
Definition: auth_unix.c:96
#define abort()
Definition: i386-dis.c:35
struct __auth::auth_ops * ah_ops
void xdrmem_create(XDR *xdrs, char *addr, u_int size, enum xdr_op op)
Definition: xdr_mem.c:94
struct opaque_auth ah_cred
Definition: auth.h:206
#define mem_free(ptr, bsize)
Definition: types.h:124
struct opaque_auth au_shcred
Definition: auth_unix.c:95

Referenced by authunix_create_default().

◆ authunix_create_default()

AUTH* authunix_create_default ( void  )

Definition at line 198 of file auth_unix.c.

199 {
200  int len;
201  char machname[MAXHOSTNAMELEN + 1];
202  uid_t uid;
203  gid_t gid;
204  gid_t gids[NGRPS];
205 
206  if (gethostname(machname, sizeof machname) == -1)
207  abort();
208  machname[sizeof(machname) - 1] = 0;
209 #if 0
210  uid = geteuid();
211  gid = getegid();
212  if ((len = getgroups(NGRPS, gids)) < 0)
213  abort();
214 #else
215  // XXX Need to figure out what to do here!
216  uid = 666;
217  gid = 777;
218  gids[0] = 0;
219  len = 0;
220 #endif
221  /* XXX: interface problem; those should all have been unsigned */
222  return (authunix_create(machname, uid, gid, len, gids));
223 }
AUTH * authunix_create(char *machname, uid_t uid, gid_t gid, int len, gid_t *aup_gids)
Definition: auth_unix.c:107
long uid_t
Definition: various.h:8
UINT gid_t
Definition: types.h:89
INT WSAAPI gethostname(OUT char FAR *name, IN INT namelen)
Definition: getxbyxx.c:397
EXPORT gid_t getegid()
Definition: gid.c:37
GLenum GLsizei len
Definition: glext.h:6722
EXPORT uid_t geteuid()
Definition: uid.c:37
#define MAXHOSTNAMELEN
Definition: ftp.c:31
#define abort()
Definition: i386-dis.c:35
#define NGRPS
Definition: auth_unix.h:54

Referenced by rpc_broadcast_exp().

◆ authunix_destroy()

static void authunix_destroy ( AUTH auth)
static

Definition at line 332 of file auth_unix.c.

334 {
335  struct audata *au;
336 
337  assert(auth != NULL);
338 
339  au = AUTH_PRIVATE(auth);
340  mem_free(au->au_origcred.oa_base, au->au_origcred.oa_length);
341 
342  if (au->au_shcred.oa_base != NULL)
343  mem_free(au->au_shcred.oa_base, au->au_shcred.oa_length);
344 
345  mem_free(auth->ah_private, sizeof(struct audata));
346 
347  if (auth->ah_verf.oa_base != NULL)
348  mem_free(auth->ah_verf.oa_base, auth->ah_verf.oa_length);
349 
350  mem_free(auth, sizeof(*auth));
351 }
struct opaque_auth au_origcred
Definition: auth_unix.c:94
#define assert(x)
Definition: debug.h:53
smooth NULL
Definition: ftsmooth.c:416
void * ah_private
Definition: auth.h:225
struct opaque_auth ah_verf
Definition: auth.h:207
#define mem_free(ptr, bsize)
Definition: types.h:124
struct opaque_auth au_shcred
Definition: auth_unix.c:95
#define AUTH_PRIVATE(auth)
Definition: auth_unix.c:100

Referenced by authunix_ops().

◆ authunix_marshal()

static bool_t authunix_marshal ( AUTH auth,
XDR xdrs,
u_int seq 
)
static

Definition at line 238 of file auth_unix.c.

242 {
243  struct audata *au;
244 
245  assert(auth != NULL);
246  assert(xdrs != NULL);
247 
248  au = AUTH_PRIVATE(auth);
249  return (XDR_PUTBYTES(xdrs, au->au_marshed, au->au_mpos));
250 }
#define assert(x)
Definition: debug.h:53
smooth NULL
Definition: ftsmooth.c:416
#define XDR_PUTBYTES(xdrs, addr, len)
Definition: xdr.h:194
char au_marshed[MAX_AUTH_BYTES]
Definition: auth_unix.c:97
u_int au_mpos
Definition: auth_unix.c:98
#define AUTH_PRIVATE(auth)
Definition: auth_unix.c:100

Referenced by authunix_ops().

◆ authunix_nextverf()

static void authunix_nextverf ( AUTH auth)
static

Definition at line 231 of file auth_unix.c.

233 {
234  /* no action necessary */
235 }

Referenced by authunix_ops().

◆ authunix_ops()

static struct auth_ops * authunix_ops ( void  )
static

Definition at line 396 of file auth_unix.c.

397 {
398  static struct auth_ops ops;
399  extern mutex_t ops_lock;
400 
401  /* VARIABLES PROTECTED BY ops_lock: ops */
402 
404  if (ops.ah_nextverf == NULL) {
405  ops.ah_nextverf = authunix_nextverf;
406  ops.ah_marshal = authunix_marshal;
407  ops.ah_validate = authunix_validate;
408  ops.ah_refresh = authunix_refresh;
409  ops.ah_destroy = authunix_destroy;
410  ops.ah_wrap = authunix_wrap;
411 #ifndef __REACTOS__
412  ops.ah_unwrap = authunix_wrap;
413 #else
414  ops.ah_unwrap = authunix_unwrap;
415 #endif
416  }
418  return (&ops);
419 }
mutex_t ops_lock
Definition: mt_misc.c:71
static void authunix_nextverf(AUTH *)
Definition: auth_unix.c:231
static bool_t authunix_validate(AUTH *, struct opaque_auth *, u_int)
Definition: auth_unix.c:253
static bool_t authunix_marshal(AUTH *, XDR *, u_int *seq)
Definition: auth_unix.c:238
#define mutex_lock(m)
Definition: reentrant.h:128
#define mutex_unlock(m)
Definition: reentrant.h:129
static bool_t authunix_wrap(AUTH *auth, XDR *xdrs, xdrproc_t func, caddr_t args, u_int seq)
Definition: auth_unix.c:380
smooth NULL
Definition: ftsmooth.c:416
static bool_t authunix_refresh(AUTH *, void *)
Definition: auth_unix.c:288
static void authunix_destroy(AUTH *)
Definition: auth_unix.c:332
Definition: module.h:446

Referenced by authunix_create().

◆ authunix_refresh()

static bool_t authunix_refresh ( AUTH auth,
void dummy 
)
static

Definition at line 288 of file auth_unix.c.

289 {
290  struct audata *au = AUTH_PRIVATE(auth);
291  struct authunix_parms aup;
292  struct timeval now;
293  XDR xdrs;
294  int stat;
295 
296  assert(auth != NULL);
297 
298  if (auth->ah_cred.oa_base == au->au_origcred.oa_base) {
299  /* there is no hope. Punt */
300  return (FALSE);
301  }
302  au->au_shfaults ++;
303 
304  /* first deserialize the creds back into a struct authunix_parms */
305  aup.aup_machname = NULL;
306  aup.aup_gids = NULL;
307  xdrmem_create(&xdrs, au->au_origcred.oa_base,
308  au->au_origcred.oa_length, XDR_DECODE);
309  stat = xdr_authunix_parms(&xdrs, &aup);
310  if (! stat)
311  goto done;
312 
313  /* update the time and serialize in place */
315  aup.aup_time = now.tv_sec;
316  xdrs.x_op = XDR_ENCODE;
317  XDR_SETPOS(&xdrs, 0);
318  stat = xdr_authunix_parms(&xdrs, &aup);
319  if (! stat)
320  goto done;
321  auth->ah_cred = au->au_origcred;
322  marshal_new_auth(auth);
323 done:
324  /* free the struct authunix_parms created by deserializing */
325  xdrs.x_op = XDR_FREE;
326  (void)xdr_authunix_parms(&xdrs, &aup);
327  XDR_DESTROY(&xdrs);
328  return (stat);
329 }
bool_t xdr_authunix_parms(XDR *xdrs, struct authunix_parms *p)
Definition: authunix_prot.c:50
struct png_info_def **typedef void(__cdecl typeof(png_destroy_read_struct))(struct png_struct_def **
Definition: typeof.h:49
struct opaque_auth au_origcred
Definition: auth_unix.c:94
static void marshal_new_auth(AUTH *)
Definition: auth_unix.c:358
#define assert(x)
Definition: debug.h:53
Definition: xdr.h:103
#define gettimeofday(tv, tz)
Definition: adns_win32.h:159
time_t now
Definition: finger.c:65
smooth NULL
Definition: ftsmooth.c:416
Definition: xdr.h:85
Definition: stat.h:55
#define XDR_SETPOS(xdrs, pos)
Definition: xdr.h:204
_CRTIMP int __cdecl stat(const char *_Filename, struct stat *_Stat)
Definition: stat.h:345
u_long au_shfaults
Definition: auth_unix.c:96
void xdrmem_create(XDR *xdrs, char *addr, u_int size, enum xdr_op op)
Definition: xdr_mem.c:94
Definition: xdr.h:87
struct opaque_auth ah_cred
Definition: auth.h:206
Definition: xdr.h:86
#define XDR_DESTROY(xdrs)
Definition: xdr.h:214
#define AUTH_PRIVATE(auth)
Definition: auth_unix.c:100

Referenced by authunix_ops().

◆ authunix_validate()

static bool_t authunix_validate ( AUTH auth,
struct opaque_auth verf,
u_int  seq 
)
static

Definition at line 253 of file auth_unix.c.

257 {
258  struct audata *au;
259  XDR xdrs;
260 
261  assert(auth != NULL);
262  assert(verf != NULL);
263 
264  if (verf->oa_flavor == AUTH_SHORT) {
265  au = AUTH_PRIVATE(auth);
266  xdrmem_create(&xdrs, verf->oa_base, verf->oa_length,
267  XDR_DECODE);
268 
269  if (au->au_shcred.oa_base != NULL) {
270  mem_free(au->au_shcred.oa_base,
271  au->au_shcred.oa_length);
272  au->au_shcred.oa_base = NULL;
273  }
274  if (xdr_opaque_auth(&xdrs, &au->au_shcred)) {
275  auth->ah_cred = au->au_shcred;
276  } else {
277  xdrs.x_op = XDR_FREE;
278  (void)xdr_opaque_auth(&xdrs, &au->au_shcred);
279  au->au_shcred.oa_base = NULL;
280  auth->ah_cred = au->au_origcred;
281  }
282  marshal_new_auth(auth);
283  }
284  return (TRUE);
285 }
#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
u_int oa_length
Definition: auth.h:198
caddr_t oa_base
Definition: auth.h:197
struct opaque_auth au_origcred
Definition: auth_unix.c:94
static void marshal_new_auth(AUTH *)
Definition: auth_unix.c:358
#define assert(x)
Definition: debug.h:53
Definition: xdr.h:103
smooth NULL
Definition: ftsmooth.c:416
enum xdr_op x_op
Definition: xdr.h:104
enum_t oa_flavor
Definition: auth.h:196
void xdrmem_create(XDR *xdrs, char *addr, u_int size, enum xdr_op op)
Definition: xdr_mem.c:94
bool_t xdr_opaque_auth()
Definition: xdr.h:87
struct opaque_auth ah_cred
Definition: auth.h:206
Definition: xdr.h:86
#define mem_free(ptr, bsize)
Definition: types.h:124
#define AUTH_SHORT
Definition: auth.h:405
struct opaque_auth au_shcred
Definition: auth_unix.c:95
#define AUTH_PRIVATE(auth)
Definition: auth_unix.c:100

Referenced by authunix_ops().

◆ authunix_wrap()

static bool_t authunix_wrap ( AUTH auth,
XDR xdrs,
xdrproc_t  func,
caddr_t  args,
u_int  seq 
)
static

Definition at line 380 of file auth_unix.c.

384 {
385  return ((*func)(xdrs, args));
386 }
GLenum func
Definition: glext.h:6028
Definition: match.c:390

Referenced by authunix_ops().

◆ marshal_new_auth()

static void marshal_new_auth ( AUTH auth)
static

Definition at line 358 of file auth_unix.c.

360 {
361  XDR xdr_stream;
362  XDR *xdrs = &xdr_stream;
363  struct audata *au;
364 
365  assert(auth != NULL);
366 
367  au = AUTH_PRIVATE(auth);
369  if ((! xdr_opaque_auth(xdrs, &(auth->ah_cred))) ||
370  (! xdr_opaque_auth(xdrs, &(auth->ah_verf))))
371  assert(0); // XXX
372  // XXX warnx("auth_none.c - Fatal marshalling problem");
373  else
374  au->au_mpos = XDR_GETPOS(xdrs);
375  XDR_DESTROY(xdrs);
376 }
#define MAX_AUTH_BYTES
Definition: auth.h:77
#define XDR_GETPOS(xdrs)
Definition: xdr.h:199
#define assert(x)
Definition: debug.h:53
Definition: xdr.h:103
smooth NULL
Definition: ftsmooth.c:416
struct opaque_auth ah_verf
Definition: auth.h:207
Definition: xdr.h:85
void xdrmem_create(XDR *xdrs, char *addr, u_int size, enum xdr_op op)
Definition: xdr_mem.c:94
bool_t xdr_opaque_auth()
struct opaque_auth ah_cred
Definition: auth.h:206
char au_marshed[MAX_AUTH_BYTES]
Definition: auth_unix.c:97
u_int au_mpos
Definition: auth_unix.c:98
#define XDR_DESTROY(xdrs)
Definition: xdr.h:214
#define AUTH_PRIVATE(auth)
Definition: auth_unix.c:100

Referenced by authunix_create(), authunix_refresh(), and authunix_validate().