Browse Source

Plan 9 from Bell Labs 2007-05-30

David du Colombier 14 years ago
parent
commit
919ac81287
4 changed files with 43 additions and 37 deletions
  1. 4 4
      dist/replica/_plan9.db
  2. 4 4
      dist/replica/plan9.db
  3. 4 0
      dist/replica/plan9.log
  4. 31 29
      sys/src/cmd/auth/secstore/password.c

+ 4 - 4
dist/replica/_plan9.db

@@ -71,9 +71,9 @@
 386/bin/auth/rsafill - 775 sys sys 1168402273 143968
 386/bin/auth/rsagen - 775 sys sys 1178568249 151953
 386/bin/auth/secretpem - 775 sys sys 1045537944 118526
-386/bin/auth/secstore - 775 sys sys 1178568249 194983
-386/bin/auth/secstored - 775 sys sys 1178568250 196571
-386/bin/auth/secuser - 775 sys sys 1178568250 151765
+386/bin/auth/secstore - 775 sys sys 1180468712 195983
+386/bin/auth/secstored - 775 sys sys 1180468713 197571
+386/bin/auth/secuser - 775 sys sys 1180468714 152765
 386/bin/auth/status - 775 sys sys 1020319060 738
 386/bin/auth/uniq - 775 sys sys 1168402275 63314
 386/bin/auth/warning - 775 sys sys 1179372071 99970
@@ -9618,7 +9618,7 @@ sys/src/cmd/auth/secstore/aescbc.c - 664 sys sys 1143465912 4063
 sys/src/cmd/auth/secstore/dirls.c - 664 sys sys 1062277640 1842
 sys/src/cmd/auth/secstore/mkfile - 664 sys sys 1106577499 836
 sys/src/cmd/auth/secstore/pak.c - 664 sys sys 1140272943 9314
-sys/src/cmd/auth/secstore/password.c - 664 sys sys 1106577427 2929
+sys/src/cmd/auth/secstore/password.c - 664 sys sys 1180417351 3038
 sys/src/cmd/auth/secstore/secchk.c - 664 sys sys 1172776633 565
 sys/src/cmd/auth/secstore/secstore.c - 664 sys sys 1143465894 12678
 sys/src/cmd/auth/secstore/secstore.h - 664 sys sys 1106575526 859

+ 4 - 4
dist/replica/plan9.db

@@ -71,9 +71,9 @@
 386/bin/auth/rsafill - 775 sys sys 1168402273 143968
 386/bin/auth/rsagen - 775 sys sys 1178568249 151953
 386/bin/auth/secretpem - 775 sys sys 1045537944 118526
-386/bin/auth/secstore - 775 sys sys 1178568249 194983
-386/bin/auth/secstored - 775 sys sys 1178568250 196571
-386/bin/auth/secuser - 775 sys sys 1178568250 151765
+386/bin/auth/secstore - 775 sys sys 1180468712 195983
+386/bin/auth/secstored - 775 sys sys 1180468713 197571
+386/bin/auth/secuser - 775 sys sys 1180468714 152765
 386/bin/auth/status - 775 sys sys 1020319060 738
 386/bin/auth/uniq - 775 sys sys 1168402275 63314
 386/bin/auth/warning - 775 sys sys 1179372071 99970
@@ -9618,7 +9618,7 @@ sys/src/cmd/auth/secstore/aescbc.c - 664 sys sys 1143465912 4063
 sys/src/cmd/auth/secstore/dirls.c - 664 sys sys 1062277640 1842
 sys/src/cmd/auth/secstore/mkfile - 664 sys sys 1106577499 836
 sys/src/cmd/auth/secstore/pak.c - 664 sys sys 1140272943 9314
-sys/src/cmd/auth/secstore/password.c - 664 sys sys 1106577427 2929
+sys/src/cmd/auth/secstore/password.c - 664 sys sys 1180417351 3038
 sys/src/cmd/auth/secstore/secchk.c - 664 sys sys 1172776633 565
 sys/src/cmd/auth/secstore/secstore.c - 664 sys sys 1143465894 12678
 sys/src/cmd/auth/secstore/secstore.h - 664 sys sys 1106575526 859

+ 4 - 0
dist/replica/plan9.log

@@ -49110,3 +49110,7 @@
 1180209622 1 c 386/bin/fossil/flfmt - 775 sys sys 1180209226 245137
 1180209622 2 c 386/bin/fossil/fossil - 775 sys sys 1180209226 363773
 1180251038 0 c sys/src/9/port/devfs.c - 664 sys sys 1180249924 13409
+1180418423 0 c sys/src/cmd/auth/secstore/password.c - 664 sys sys 1180417351 3038
+1180468823 0 c 386/bin/auth/secstore - 775 sys sys 1180468712 195983
+1180468823 1 c 386/bin/auth/secstored - 775 sys sys 1180468713 197571
+1180468823 2 c 386/bin/auth/secuser - 775 sys sys 1180468714 152765

+ 31 - 29
sys/src/cmd/auth/secstore/password.c

@@ -10,9 +10,9 @@
 static Biobuf*
 openPW(char *id, int mode)
 {
-	Biobuf *b;
 	int nfn = strlen(SECSTORE_DIR)+strlen(id)+20;
 	char *fn;
+	Biobuf *b;
 
 	if(validatefile(id) == nil || strcmp(id,".") == 0)
 		return nil;
@@ -26,83 +26,86 @@ openPW(char *id, int mode)
 static ulong
 mtimePW(char *id)
 {
-	Dir *d;
-	int nfn = strlen(SECSTORE_DIR)+strlen(id)+20;
-	char *fn = emalloc(nfn);
 	ulong mt;
+	char *fn;
+	Dir *d;
 
-	snprint(fn, nfn, "%s/who/%s", SECSTORE_DIR, id);
+	fn = smprint("%s/who/%s", SECSTORE_DIR, id);
 	d = dirstat(fn);
-	free(fn);
-	mt = d->mtime;
+	mt = (d? d->mtime: 0);
 	free(d);
+	free(fn);
 	return mt;
 }
 
 PW *
 getPW(char *id, int dead_or_alive)
 {
-	uint now = time(0);
+	ulong now = time(0);
+	char *f1, *f2, *oid;		/* fields 1, 2 = attribute, value */
 	Biobuf *bin;
 	PW *pw;
-	char *f1, *f2; // fields 1, 2 = attribute, value
 
+	oid = id;
 	if((bin = openPW(id, OREAD)) == 0){
 		id = "FICTITIOUS";
 		if((bin = openPW(id, OREAD)) == 0){
-			werrstr("account does not exist");
+			werrstr("accounts %s and FICTITIOUS do not exist", oid);
 			return nil;
 		}
 	}
-	pw = emalloc(sizeof(*pw));
+	pw = emalloc(sizeof *pw);
 	pw->id = estrdup(id);
 	pw->status |= Enabled;
 	while( (f1 = Brdline(bin, '\n')) != 0){
 		f1[Blinelen(bin)-1] = 0;
-		for(f2 = f1; *f2 && (*f2!=' ') && (*f2!='\t'); f2++){}
+		for(f2 = f1; *f2 && *f2 != ' ' && *f2 != '\t'; f2++)
+			;
 		if(*f2)
-			for(*f2++ = 0; *f2 && (*f2==' ' || *f2=='\t'); f2++){}
-		if(strcmp(f1, "exp") == 0){
+			for(*f2++ = 0; *f2 && (*f2==' ' || *f2=='\t'); f2++)
+				;
+		if(strcmp(f1, "exp") == 0)
 			pw->expire = strtoul(f2, 0, 10);
-		}else if(strcmp(f1, "DISABLED") == 0){
+		else if(strcmp(f1, "DISABLED") == 0)
 			pw->status &= ~Enabled;
-		}else if(strcmp(f1, "STA") == 0){
+		else if(strcmp(f1, "STA") == 0)
 			pw->status |= STA;
-		}else if(strcmp(f1, "failed") == 0){
+		else if(strcmp(f1, "failed") == 0)
 			pw->failed = strtoul(f2, 0, 10);
-		}else if(strcmp(f1, "other") == 0){
+		else if(strcmp(f1, "other") == 0)
 			pw->other = estrdup(f2);
-		}else if(strcmp(f1, "PAK-Hi") == 0){
+		else if(strcmp(f1, "PAK-Hi") == 0)
 			pw->Hi = strtomp(f2, nil, 64, nil);
-		}
 	}
 	Bterm(bin);
 	if(pw->Hi == nil){
-		werrstr("corrupted account file");
+		werrstr("corrupted account file for %s", pw->id);
 		freePW(pw);
 		return nil;
 	}
 	if(dead_or_alive)
-		return pw;  // return PW entry for editing, whether currently valid or not
-	if(pw->expire <= now){
-		werrstr("account expired");
+		return pw;  /* return for editing, whether valid now or not */
+	if(pw->expire != 0 && pw->expire <= now){
+		/* %.28s excludes ctime's newline */
+		werrstr("account %s expired at %.28s", pw->id,
+			ctime(pw->expire));
 		freePW(pw);
 		return nil;
 	}
 	if((pw->status & Enabled) == 0){
-		werrstr("account disabled");
+		werrstr("account %s disabled", pw->id);
 		freePW(pw);
 		return nil;
 	}
 	if(pw->failed < 10)
-		return pw;  // success
+		return pw;	/* success */
 	if(now < mtimePW(id)+300){
 		werrstr("too many failures; try again in five minutes");
 		freePW(pw);
 		return nil;
 	}
 	pw->failed = 0;
-	putPW(pw);  // reset failed-login-counter after five minutes
+	putPW(pw);	/* reset failed-login-counter after five minutes */
 	return pw;
 }
 
@@ -113,7 +116,7 @@ putPW(PW *pw)
 	char *hexHi;
 
 	if((bout = openPW(pw->id, OWRITE|OTRUNC)) ==0){
-		werrstr("can't open PW file");
+		werrstr("can't open PW file for %s", pw->id);
 		return -1;
 	}
 	Bprint(bout, "exp	%lud\n", pw->expire);
@@ -141,4 +144,3 @@ freePW(PW *pw)
 	mpfree(pw->Hi);
 	free(pw);
 }
-