aboutsummaryrefslogtreecommitdiff
path: root/riemann.fmi.uni-sofia.bg/programs/nlogin-0.3-pre/nv_getpwent.c
blob: 75ce6cbb664c37c77b093040608e0e5c7f759192 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#include <pwd.h> /*EXTRACT_UNMOD*/
#include "parselib.h"
#define NV_SETPWENT
#include "config.h"

static struct state S;

void nv_setpwent() /*EXTRACT_INCL*/ {__prepare_parse(__PASSWD_FILE,&S);}
void nv_endpwent() /*EXTRACT_INCL*/ {__end_parse(&S);}

struct passwd *nv_getpwent() /*EXTRACT_INCL*/ {
  static struct passwd pw;
  static char buf[__PASSWD_BUFFER];
  char *p,*arg[9];
  unsigned long u;

  if (!S.buffirst) nv_setpwent();
  if (!S.buffirst) return 0;

 again:
  if ((u = __parse_feed(&S, buf, sizeof(buf)))==0) return 0;
  if (7 != __parse_split(buf,u,':',7,arg)) goto again;

  pw.pw_name   = arg[0];
#ifndef DONT_NEED_PASSWD
  pw.pw_passwd = arg[1];
#endif
#ifndef DONT_NEED_UID
  p=arg[2];  if (!*p || p[scan_ulong(p,&u)]) goto again; pw.pw_uid =u;
#endif
#ifndef DONT_NEED_GID
  p=arg[3];  if (!*p || p[scan_ulong(p,&u)]) goto again; pw.pw_gid =u;
#endif
#ifndef DONT_NEED_GECOS
  pw.pw_gecos  = arg[4];
#endif
#ifndef DONT_NEED_DIR
  pw.pw_dir    = arg[5];
#endif
#ifndef DONT_NEED_SHELL
  pw.pw_shell  = arg[6];
#endif
  return(&pw);
}