10 static void userinput(char *, int);
14 ensure_exists(char *f, ulong perm)
18 if(access(f, AEXIST) >= 0)
21 fprint(2,"first time setup for secstore: create %s %lo\n", f, perm);
22 fd = create(f, OREAD, perm);
24 fprint(2, "unable to create %s\n", f);
25 exits("secstored directories");
32 main(int argc, char **argv)
35 char *id, buf[Maxmsg], home[Maxmsg], prompt[100], *hexHi;
38 mpint *H = mpnew(0), *Hi = mpnew(0);
42 SECSTORE_DIR = unsharp("#9/secstore");
50 print("usage: secuser [-v] <user>\n");
54 ensure_exists(SECSTORE_DIR, DMDIR|0755L);
55 snprint(home, sizeof(home), "%s/who", SECSTORE_DIR);
56 ensure_exists(home, DMDIR|0755L);
57 snprint(home, sizeof(home), "%s/store", SECSTORE_DIR);
58 ensure_exists(home, DMDIR|0700L);
62 fprint(2,"secuser %s\n", id);
63 if((pw = getPW(id,1)) == nil){
65 print("new account (because %s/%s %r)\n", SECSTORE_DIR, id);
66 pw = emalloc(sizeof(*pw));
68 snprint(home, sizeof(home), "%s/store/%s", SECSTORE_DIR, id);
69 if(access(home, AEXIST) == 0){
70 print("new user, but directory %s already exists\n", home);
77 /* get main password for id */
80 snprint(prompt, sizeof(prompt), "%s password", id);
82 snprint(prompt, sizeof(prompt), "%s password [default = don't change]", id);
83 pass = readcons(prompt, nil, 1);
85 print("getpass failed\n");
86 exits("getpass failed");
89 print("%ld characters\n", strlen(pass));
90 if(pass[0] == '\0' && isnew == 0)
94 print("password must be at least 7 characters\n");
98 snprint(prompt, sizeof(prompt), "retype password");
100 print("confirming...\n");
101 passck = readcons(prompt, nil, 1);
103 print("getpass failed\n");
104 exits("getpass failed");
106 if(strcmp(pass, passck) != 0){
107 print("passwords didn't match\n");
110 memset(passck, 0, strlen(passck));
112 hexHi = PAK_Hi(id, pass, H, Hi);
113 memset(pass, 0, strlen(pass));
120 /* get expiration time (midnight of date specified) */
122 expsecs = time(0) + 365*24*60*60;
124 expsecs = pw->expire;
127 tm = localtime(expsecs);
128 print("expires [DDMMYYYY, default = %2.2d%2.2d%4.4d]: ",
129 tm->mday, tm->mon, tm->year+1900);
130 userinput(buf, sizeof(buf));
133 if(strlen(buf) != 8){
134 print("!bad date format: %s\n", buf);
137 tm->mday = (buf[0]-'0')*10 + (buf[1]-'0');
138 if(tm->mday > 31 || tm->mday < 1){
139 print("!bad day of month: %d\n", tm->mday);
142 tm->mon = (buf[2]-'0')*10 + (buf[3]-'0') - 1;
143 if(tm->mon > 11 || tm->mday < 0){
144 print("!bad month: %d\n", tm->mon + 1);
147 tm->year = atoi(buf+4) - 1900;
149 print("!bad year: %d\n", tm->year + 1900);
156 expsecs = tm2sec(tm);
159 pw->expire = expsecs;
163 print("clearing %d failed login attempts\n", pw->failed);
168 pw->status = Enabled;
170 print("Enabled or Disabled [default %s]: ",
171 (pw->status & Enabled) ? "Enabled" : "Disabled" );
172 userinput(buf, sizeof(buf));
175 if(buf[0]=='E' || buf[0]=='e'){
176 pw->status |= Enabled;
179 if(buf[0]=='D' || buf[0]=='d'){
180 pw->status = pw->status & ~Enabled;
185 print("require STA? [default %s]: ",
186 (pw->status & STA) ? "yes" : "no" );
187 userinput(buf, sizeof(buf));
190 if(buf[0]=='Y' || buf[0]=='y'){
194 if(buf[0]=='N' || buf[0]=='n'){
195 pw->status = pw->status & ~STA;
200 /* free form field */
203 print("comments [default = %s]: ", (pw->other == nil) ? "" : pw->other);
204 userinput(buf, 72); /* 72 comes from password.h */
206 if((pw->other = strdup(buf)) == nil)
209 syslog(0, LOG, "CHANGELOGIN for '%s'", pw->id);
211 print("error writing entry: %r\n");
212 exits("can't write password file");
214 print("change written\n");
215 if(isnew && create(home, OREAD, DMDIR | 0775L) < 0){
216 print("unable to create %s: %r\n", home);
222 return 1; /* keep other compilers happy */
227 userinput(char *buf, int blen)
232 n = read(0, buf, blen);
241 exits("input too large");