aboutsummaryrefslogtreecommitdiff
path: root/riemann.fmi.uni-sofia.bg/programs/nlogin-0.3-pre/nv_getspent.c
blob: 3d6a75c6e94661c0ca4f34536353a92133916826 (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
45
46
47
#include <shadow.h> /*EXTRACT_UNMOD*/
#include "parselib.h"
#define NV_SETSPENT
#include "config.h"

static struct state S;

void nv_setspent() /*EXTRACT_INCL*/{__prepare_parse(__SHADOW_FILE,&S);}
void nv_endspent() /*EXTRACT_INCL*/{__end_parse(&S);}

struct spwd *nv_getspent() /*EXTRACT_INCL*/ {
  static struct spwd sp;
  static char buf[__SHADOW_BUFFER];
  char *arg[12];
  unsigned int u;

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

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

  sp.sp_namp = arg[0];
  sp.sp_pwdp = arg[1];
#ifndef DONT_NEED_ALL_SHADOW
  { 
    unsigned long i,j,l;
    for (i=2; i<u; i++) {
      j=scan_ulong(arg[i],&l);
      if (arg[i][j]) goto again;
      if (j==0) l = (unsigned long)-1;
      
      switch (i) {
      case 2: sp.sp_lstchg=l; break;
      case 3: sp.sp_min=l; break;
      case 4: sp.sp_max=l; break;
      case 5: sp.sp_warn=l; break;
      case 6: sp.sp_inact=l; break;
      case 7: sp.sp_expire=l; break;
      case 8: sp.sp_flag=l; break;
      }
    }
  }
#endif
  return(&sp);
}