11 openPW(char *id, int mode)
14 int nfn = strlen(SECSTORE_DIR)+strlen(id)+20;
15 char *fn = emalloc(nfn);
17 snprint(fn, nfn, "%s/who/%s", SECSTORE_DIR, id);
27 int nfn = strlen(SECSTORE_DIR)+strlen(id)+20;
28 char *fn = emalloc(nfn);
31 snprint(fn, nfn, "%s/who/%s", SECSTORE_DIR, id);
40 getPW(char *id, int dead_or_alive)
45 char *f1, *f2; // fields 1, 2 = attribute, value
47 if((bin = openPW(id, OREAD)) == 0){
49 if((bin = openPW(id, OREAD)) == 0){
50 werrstr("account does not exist");
54 pw = emalloc(sizeof(*pw));
56 pw->status |= Enabled;
57 while( (f1 = Brdline(bin, '\n')) != 0){
58 f1[Blinelen(bin)-1] = 0;
59 for(f2 = f1; *f2 && (*f2!=' ') && (*f2!='\t'); f2++){}
61 for(*f2++ = 0; *f2 && (*f2==' ' || *f2=='\t'); f2++){}
62 if(strcmp(f1, "exp") == 0){
63 pw->expire = strtoul(f2, 0, 10);
64 }else if(strcmp(f1, "DISABLED") == 0){
65 pw->status &= ~Enabled;
66 }else if(strcmp(f1, "STA") == 0){
68 }else if(strcmp(f1, "failed") == 0){
69 pw->failed = strtoul(f2, 0, 10);
70 }else if(strcmp(f1, "other") == 0){
71 pw->other = estrdup(f2);
72 }else if(strcmp(f1, "PAK-Hi") == 0){
73 pw->Hi = strtomp(f2, nil, 64, nil);
78 return pw; // return PW entry for editing, whether currently valid or not
79 if(pw->expire <= now){
80 werrstr("account expired");
84 if((pw->status & Enabled) == 0){
85 werrstr("account disabled");
91 if(now < mtimePW(id)+300){
92 werrstr("too many failures; try again in five minutes");
97 putPW(pw); // reset failed-login-counter after five minutes
107 if((bout = openPW(pw->id, OWRITE|OTRUNC)) ==0){
108 werrstr("can't open PW file");
111 Bprint(bout, "exp %lud\n", pw->expire);
112 if(!(pw->status & Enabled))
113 Bprint(bout, "DISABLED\n");
115 Bprint(bout, "STA\n");
117 Bprint(bout, "failed\t%d\n", pw->failed);
119 Bprint(bout,"other\t%s\n", pw->other);
120 hexHi = mptoa(pw->Hi, 64, nil, 0);
121 Bprint(bout, "PAK-Hi\t%s\n", hexHi);