Browse Source

Plan 9 from Bell Labs 2006-05-13

David du Colombier 18 years ago
parent
commit
5172abebc6

+ 6 - 6
dist/replica/_plan9.db

@@ -49,7 +49,7 @@
 386/bin/auth/changeuser - 775 sys sys 1144688911 97391
 386/bin/auth/convkeys - 775 sys sys 1143777742 87820
 386/bin/auth/convkeys2 - 775 sys sys 1143777742 87879
-386/bin/auth/cron - 775 sys sys 1144688911 144283
+386/bin/auth/cron - 775 sys sys 1147453006 144614
 386/bin/auth/debug - 775 sys sys 1144256027 101661
 386/bin/auth/disable - 775 sys sys 1020319057 146
 386/bin/auth/enable - 775 sys sys 1020319057 134
@@ -225,7 +225,7 @@
 386/bin/execnet - 775 sys sys 1143777788 178363
 386/bin/exportfs - 775 sys sys 1145992764 162645
 386/bin/ext2srv - 775 sys sys 1143777788 180053
-386/bin/faces - 775 sys sys 1144688927 194536
+386/bin/faces - 775 sys sys 1147453006 194589
 386/bin/factor - 775 sys sys 1143777789 61794
 386/bin/fcp - 775 sys sys 1143777789 82528
 386/bin/file - 775 sys sys 1144264733 121024
@@ -7745,7 +7745,7 @@ sys/man/8/scuzz - 664 sys sys 984709640 7916
 sys/man/8/secstore - 664 sys sys 1105016705 1954
 sys/man/8/securenet - 664 sys sys 954305552 3160
 sys/man/8/send - 664 sys sys 1045501634 2168
-sys/man/8/smtp - 664 sys sys 1133631990 4507
+sys/man/8/smtp - 664 sys sys 1147439305 4499
 sys/man/8/snoopy - 664 sys sys 1146318297 4288
 sys/man/8/stats - 664 sys sys 1067722908 4291
 sys/man/8/statusbar - 664 sys sys 1141313214 1253
@@ -9459,7 +9459,7 @@ sys/src/cmd/auth/changeuser.c - 664 sys sys 1118884775 2932
 sys/src/cmd/auth/convbio.c - 664 sys sys 1015008432 2212
 sys/src/cmd/auth/convkeys.c - 664 sys sys 1140272940 2370
 sys/src/cmd/auth/convkeys2.c - 664 sys sys 1140272940 2427
-sys/src/cmd/auth/cron.c - 664 sys sys 1143694942 11443
+sys/src/cmd/auth/cron.c - 664 sys sys 1147439284 11681
 sys/src/cmd/auth/debug.c - 664 sys sys 1143694911 7325
 sys/src/cmd/auth/disable - 775 sys sys 1015008431 146
 sys/src/cmd/auth/enable - 775 sys sys 1015008430 134
@@ -10123,7 +10123,7 @@ sys/src/cmd/faces - 20000000775 sys sys 952888246 0
 sys/src/cmd/faces/dblook.c - 664 sys sys 944961084 359
 sys/src/cmd/faces/facedb.c - 664 sys sys 1142086801 10551
 sys/src/cmd/faces/faces.h - 664 sys sys 1072972232 1115
-sys/src/cmd/faces/main.c - 664 sys sys 1106409986 13643
+sys/src/cmd/faces/main.c - 664 sys sys 1147439217 13713
 sys/src/cmd/faces/mkfile - 664 sys sys 1062460262 355
 sys/src/cmd/faces/plumb.c - 664 sys sys 1143759346 7029
 sys/src/cmd/faces/util.c - 664 sys sys 1035698250 569
@@ -14047,7 +14047,7 @@ sys/src/cmd/upas/smtp/rfc822.y - 664 sys sys 1064589606 13417
 sys/src/cmd/upas/smtp/rmtdns.c - 664 sys sys 1015013150 1069
 sys/src/cmd/upas/smtp/smtp.c - 664 sys sys 1143759341 20123
 sys/src/cmd/upas/smtp/smtp.h - 664 sys sys 1108827986 1270
-sys/src/cmd/upas/smtp/smtpd.c - 664 sys sys 1132331205 31097
+sys/src/cmd/upas/smtp/smtpd.c - 664 sys sys 1147439361 31157
 sys/src/cmd/upas/smtp/smtpd.h - 664 sys sys 1067722781 1111
 sys/src/cmd/upas/smtp/smtpd.y - 664 sys sys 1143670612 6961
 sys/src/cmd/upas/smtp/spam.c - 664 sys sys 1139699502 10238

+ 6 - 6
dist/replica/plan9.db

@@ -49,7 +49,7 @@
 386/bin/auth/changeuser - 775 sys sys 1144688911 97391
 386/bin/auth/convkeys - 775 sys sys 1143777742 87820
 386/bin/auth/convkeys2 - 775 sys sys 1143777742 87879
-386/bin/auth/cron - 775 sys sys 1144688911 144283
+386/bin/auth/cron - 775 sys sys 1147453006 144614
 386/bin/auth/debug - 775 sys sys 1144256027 101661
 386/bin/auth/disable - 775 sys sys 1020319057 146
 386/bin/auth/enable - 775 sys sys 1020319057 134
@@ -225,7 +225,7 @@
 386/bin/execnet - 775 sys sys 1143777788 178363
 386/bin/exportfs - 775 sys sys 1145992764 162645
 386/bin/ext2srv - 775 sys sys 1143777788 180053
-386/bin/faces - 775 sys sys 1144688927 194536
+386/bin/faces - 775 sys sys 1147453006 194589
 386/bin/factor - 775 sys sys 1143777789 61794
 386/bin/fcp - 775 sys sys 1143777789 82528
 386/bin/file - 775 sys sys 1144264733 121024
@@ -7745,7 +7745,7 @@ sys/man/8/scuzz - 664 sys sys 984709640 7916
 sys/man/8/secstore - 664 sys sys 1105016705 1954
 sys/man/8/securenet - 664 sys sys 954305552 3160
 sys/man/8/send - 664 sys sys 1045501634 2168
-sys/man/8/smtp - 664 sys sys 1133631990 4507
+sys/man/8/smtp - 664 sys sys 1147439305 4499
 sys/man/8/snoopy - 664 sys sys 1146318297 4288
 sys/man/8/stats - 664 sys sys 1067722908 4291
 sys/man/8/statusbar - 664 sys sys 1141313214 1253
@@ -9459,7 +9459,7 @@ sys/src/cmd/auth/changeuser.c - 664 sys sys 1118884775 2932
 sys/src/cmd/auth/convbio.c - 664 sys sys 1015008432 2212
 sys/src/cmd/auth/convkeys.c - 664 sys sys 1140272940 2370
 sys/src/cmd/auth/convkeys2.c - 664 sys sys 1140272940 2427
-sys/src/cmd/auth/cron.c - 664 sys sys 1143694942 11443
+sys/src/cmd/auth/cron.c - 664 sys sys 1147439284 11681
 sys/src/cmd/auth/debug.c - 664 sys sys 1143694911 7325
 sys/src/cmd/auth/disable - 775 sys sys 1015008431 146
 sys/src/cmd/auth/enable - 775 sys sys 1015008430 134
@@ -10123,7 +10123,7 @@ sys/src/cmd/faces - 20000000775 sys sys 952888246 0
 sys/src/cmd/faces/dblook.c - 664 sys sys 944961084 359
 sys/src/cmd/faces/facedb.c - 664 sys sys 1142086801 10551
 sys/src/cmd/faces/faces.h - 664 sys sys 1072972232 1115
-sys/src/cmd/faces/main.c - 664 sys sys 1106409986 13643
+sys/src/cmd/faces/main.c - 664 sys sys 1147439217 13713
 sys/src/cmd/faces/mkfile - 664 sys sys 1062460262 355
 sys/src/cmd/faces/plumb.c - 664 sys sys 1143759346 7029
 sys/src/cmd/faces/util.c - 664 sys sys 1035698250 569
@@ -14047,7 +14047,7 @@ sys/src/cmd/upas/smtp/rfc822.y - 664 sys sys 1064589606 13417
 sys/src/cmd/upas/smtp/rmtdns.c - 664 sys sys 1015013150 1069
 sys/src/cmd/upas/smtp/smtp.c - 664 sys sys 1143759341 20123
 sys/src/cmd/upas/smtp/smtp.h - 664 sys sys 1108827986 1270
-sys/src/cmd/upas/smtp/smtpd.c - 664 sys sys 1132331205 31097
+sys/src/cmd/upas/smtp/smtpd.c - 664 sys sys 1147439361 31157
 sys/src/cmd/upas/smtp/smtpd.h - 664 sys sys 1067722781 1111
 sys/src/cmd/upas/smtp/smtpd.y - 664 sys sys 1143670612 6961
 sys/src/cmd/upas/smtp/spam.c - 664 sys sys 1139699502 10238

+ 6 - 0
dist/replica/plan9.log

@@ -29657,3 +29657,9 @@
 1147181480 0 c sys/src/cmd/htmlroff/html.c - 664 sys sys 1147180952 3992
 1147356016 0 c sys/src/cmd/fossil/9lstn.c - 664 sys sys 1147355153 3038
 1147366819 0 c 386/bin/fossil/fossil - 775 sys sys 1147366528 363992
+1147440641 0 c sys/man/8/smtp - 664 sys sys 1147439305 4499
+1147440641 1 c sys/src/cmd/auth/cron.c - 664 sys sys 1147439284 11681
+1147440641 2 c sys/src/cmd/faces/main.c - 664 sys sys 1147439217 13713
+1147440641 3 c sys/src/cmd/upas/smtp/smtpd.c - 664 sys sys 1147439361 31157
+1147453245 0 c 386/bin/faces - 775 sys sys 1147453006 194589
+1147453245 1 c 386/bin/auth/cron - 775 sys sys 1147453006 144614

+ 5 - 6
sys/man/8/smtp

@@ -112,7 +112,7 @@ turns on forward DNS validation of non-trusted sender address.
 .B -g
 turns on grey/white list processing.  All mail is rejected (with a
 retry code) unless the sender's IP address is on the whitelist,
-.BR /mail/lib/whitelist ,
+.BR /mail/grey/whitelist ,
 an append only file.
 Addresses can be added to the whitelist by the administrator.  However,
 the usual way for addresses to be added is by
@@ -120,10 +120,10 @@ the usual way for addresses to be added is by
 itself.
 Whenever a message is received and the sender's address isn't on the whitelist,
 .I smtpd
-first looks for the file,
-.B /mail/grey/<remote ipaddr>/<local ipaddr>/<recipient> .
-If that file exists, the remote address is added to the whitelist.  If
-not, the file is created and the mail is rejected with a 'try again'
+first looks for the file
+.BI /mail/grey/tmp/\| local-ipaddr /\| remote-ipaddr /\| recipient.
+If it exists, the remote address is added to the whitelist.  If
+not, the file is created and the mail is rejected with a `try again'
 code.  The expectation is that spammers will not retry and that others
 will.
 .TP
@@ -179,7 +179,6 @@ is normally run by a network listener such as
 Most of the command line options are more conveniently
 specified in the smtpd configuration file stored in
 .BR /mail/lib/smtpd.conf .
-.SH FILES
 .SH SOURCE
 .TP
 .B /sys/src/cmd/upas/smtp

+ 52 - 38
sys/src/cmd/auth/cron.c

@@ -7,12 +7,18 @@
 
 char CRONLOG[] = "cron";
 
+enum {
+	Minute = 60,
+	Hour = 60 * Minute,
+	Day = 24 * Hour,
+};
+
 typedef struct Job	Job;
 typedef struct Time	Time;
 typedef struct User	User;
 
 struct Time{			/* bit masks for each valid time */
-	ulong	min;			/* actually 1 bit for every 2 min */
+	uvlong	min;
 	ulong	hour;
 	ulong	mday;
 	ulong	wday;
@@ -45,7 +51,7 @@ void	rexec(User*, Job*);
 void	readalljobs(void);
 Job	*readjobs(char*, User*);
 int	getname(char**);
-ulong	gettime(int, int);
+uvlong	gettime(int, int);
 int	gettok(int, int);
 void	initcap(void);
 void	pushtok(void);
@@ -67,7 +73,7 @@ main(int argc, char *argv[])
 	Job *j;
 	Tm tm;
 	Time t;
-	ulong now, last, x;
+	ulong now, last, nowsecs, future;
 	int i;
 
 	debug = 0;
@@ -81,7 +87,6 @@ main(int argc, char *argv[])
 	default:
 		usage();
 	}ARGEND
-	USED(argc, argv);
 
 	if(debug){
 		readalljobs();
@@ -102,30 +107,36 @@ main(int argc, char *argv[])
 
 	argv0 = "cron";
 	srand(getpid()*time(0));
-	last = time(0) / 60;
+	last = time(0) / Minute;
 	for(;;){
 		readalljobs();
-		now = time(0) / 60;
-		if ((now-last) > (60*60*24))		/* don't go mad */
-			last = now-(60*60*24);
-		for(; last <= now; last += 2){
-			tm = *localtime(last*60);
-			t.min = 1 << tm.min/2;
+		now = time(0) / Minute;
+		if (now-last > Day/Minute)	/* don't go mad */
+			last = now - Day/Minute; /* just execute 1 day's jobs */
+		for(; last <= now; last++){
+			tm = *localtime(last*Minute);
+			t.min = 1ULL << tm.min;
 			t.hour = 1 << tm.hour;
 			t.wday = 1 << tm.wday;
 			t.mday = 1 << tm.mday;
-			t.mon = 1 << (tm.mon + 1);
+			t.mon =  1 << (tm.mon + 1);
 			for(i = 0; i < nuser; i++)
 				for(j = users[i].jobs; j; j = j->next)
-					if(j->time.min & t.min && j->time.hour & t.hour
+					if(j->time.min & t.min
+					&& j->time.hour & t.hour
 					&& j->time.wday & t.wday
 					&& j->time.mday & t.mday
 					&& j->time.mon & t.mon)
 						rexec(&users[i], j);
 		}
-		x = time(0) / 60;
-		if(x - now < 2)
-			sleep((2 - (x - now))*60*1000);
+		/*
+		 * if we're not there yet, sleep until (now+1)*Minute,
+		 * which synchronises with minute roll-over as a side-effect.
+		 */
+		future = (now + 1) * Minute;
+		nowsecs = time(0);
+		if (nowsecs < future)
+			sleep((future - nowsecs)*1000);
 	}
 	/* not reached */
 }
@@ -172,7 +183,8 @@ readalljobs(void)
 			if(strcmp(d[i].name, "log") == 0)
 				continue;
 			if(strcmp(d[i].name, d[i].uid) != 0){
-				syslog(1, CRONLOG, "cron for %s owned by %s\n", d[i].name, d[i].uid);
+				syslog(1, CRONLOG, "cron for %s owned by %s\n",
+					d[i].name, d[i].uid);
 				continue;
 			}
 			u = newuser(d[i].name);
@@ -219,12 +231,13 @@ readjobs(char *file, User *user)
 		if(*savec == '#' || *savec == '\0')
 			continue;
 		if(strlen(savec) > 1024){
-			syslog(0, CRONLOG, "%s: line %d: line too long", user->name, line);
+			syslog(0, CRONLOG, "%s: line %d: line too long",
+				user->name, line);
 			continue;
 		}
 		j = emalloc(sizeof *j);
-		if((j->time.min = gettime(0, 59))
-		&& (j->time.hour = gettime(0, 23))
+		j->time.min = gettime(0, 59);
+		if(j->time.min && (j->time.hour = gettime(0, 23))
 		&& (j->time.mday = gettime(1, 31))
 		&& (j->time.mon = gettime(1, 12))
 		&& (j->time.wday = gettime(0, 6))
@@ -234,7 +247,8 @@ readjobs(char *file, User *user)
 			j->next = jobs;
 			jobs = j;
 		}else{
-			syslog(0, CRONLOG, "%s: line %d: syntax error", user->name, line);
+			syslog(0, CRONLOG, "%s: line %d: syntax error",
+				user->name, line);
 			free(j);
 		}
 	}
@@ -251,12 +265,12 @@ printjobs(void)
 
 	for(i = 0; i < nuser; i++){
 		print("user %s\n", users[i].name);
-		for(j = users[i].jobs; j; j = j->next){
+		for(j = users[i].jobs; j; j = j->next)
 			if(!mkcmd(j->cmd, buf, sizeof buf))
-				print("\tbad job %s on host %s\n", j->cmd, j->host);
+				print("\tbad job %s on host %s\n",
+					j->cmd, j->host);
 			else
 				print("\tjob %s on host %s\n", buf, j->host);
-		}
 	}
 }
 
@@ -321,7 +335,7 @@ getname(char **namep)
 }
 
 /*
- * return the next time range in the file:
+ * return the next time range (as a bit vector) in the file:
  * times: '*'
  * 	| range
  * range: number
@@ -329,21 +343,21 @@ getname(char **namep)
  *	| range ',' range
  * a return of zero means a syntax error was discovered
  */
-ulong
+uvlong
 gettime(int min, int max)
 {
-	ulong n, m, e;
+	uvlong n, m, e;
 
 	if(gettok(min, max) == '*')
-		return ~0;
+		return ~0ULL;
 	n = 0;
 	while(tok == '1'){
-		m = 1 << lexval;
+		m = 1ULL << lexval;
 		n |= m;
 		if(gettok(0, 0) == '-'){
 			if(gettok(lexval, max) != '1')
 				return 0;
-			e = 1 << lexval;
+			e = 1ULL << lexval;
 			for( ; m <= e; m <<= 1)
 				n |= m;
 			gettok(min, max);
@@ -379,8 +393,6 @@ gettok(int min, int max)
 		lexval = strtoul(savec, &savec, 10);
 		if(lexval < min || lexval > max)
 			return tok = 0;
-		if(max > 32)
-			lexval /= 2;			/* yuk: correct min by / 2 */
 		return tok = '1';
 	case '*': case '-': case ',':
 		savec++;
@@ -476,23 +488,25 @@ syslog(0, CRONLOG, "%s: ran '%s' on %s", user->name, j->cmd, j->host);
 		_exits(0);
 	}
 
-	alarm(2*60*1000);
+	alarm(2*Minute*1000);
 	fd = call(j->host);
 	if(fd < 0){
-		if(fd == -2){
-			syslog(0, CRONLOG, "%s: dangerous host %s", user->name, j->host);
-		}
+		if(fd == -2)
+			syslog(0, CRONLOG, "%s: dangerous host %s",
+				user->name, j->host);
 		syslog(0, CRONLOG, "%s: can't call %s: %r", user->name, j->host);
 		_exits(0);
 	}
 syslog(0, CRONLOG, "%s: called %s on %s", user->name, j->cmd, j->host);
 	if(becomeuser(user->name) < 0){
-		syslog(0, CRONLOG, "%s: can't change uid for %s on %s: %r", user->name, j->cmd, j->host);
+		syslog(0, CRONLOG, "%s: can't change uid for %s on %s: %r",
+			user->name, j->cmd, j->host);
 		_exits(0);
 	}
 	ai = auth_proxy(fd, nil, "proto=p9any role=client");
 	if(ai == nil){
-		syslog(0, CRONLOG, "%s: can't authenticate for %s on %s: %r", user->name, j->cmd, j->host);
+		syslog(0, CRONLOG, "%s: can't authenticate for %s on %s: %r",
+			user->name, j->cmd, j->host);
 		_exits(0);
 	}
 syslog(0, CRONLOG, "%s: authenticated %s on %s", user->name, j->cmd, j->host);

+ 2 - 1
sys/src/cmd/faces/main.c

@@ -150,7 +150,8 @@ timeproc(void)
 		updatetimes();
 		flushimage(display, 1);
 		unlockdisplay(display);
-		sleep(60000);
+		now = time(nil);
+		sleep(((60 - now%60) + 1)*1000); /* wait for minute to change */
 		setdate();
 	}
 }

+ 4 - 3
sys/src/cmd/upas/smtp/smtpd.c

@@ -284,11 +284,12 @@ hello(String *himp, int extended)
 	/*
 	 * it is never acceptable to claim to be "localhost",
 	 * "localhost.localdomain" or "localhost.example.com"; only spammers
-	 * do this.  it should be unacceptable to claim any string that doesn't
+	 * do this.  it is also unacceptable to claim any string that doesn't
 	 * look like a domain name (e.g., has at least one dot in it), but
-	 * Microsoft mail software gets this wrong.
+	 * Microsoft mail client software gets this wrong, so let trusted
+	 * (local) clients get it wrong.
 	 */
-	if (strcmp(him, "localhost") == 0 ||
+	if (!trusted && strchr(him, '.') == nil ||
 	    strcmp(him, "localhost.localdomain") == 0 ||
 	    strcmp(him, "localhost.example.com") == 0)
 		goto Liarliar;