Browse Source

Plan 9 from Bell Labs 2007-06-04

David du Colombier 17 years ago
parent
commit
afc8dfb435

+ 4 - 4
dist/replica/_plan9.db

@@ -480,7 +480,7 @@
 386/bin/upas/token - 775 sys sys 1178568317 76393
 386/bin/upas/unesc - 775 sys sys 1176520512 60137
 386/bin/upas/unspam - 775 sys sys 1064598367 38
-386/bin/upas/vf - 775 sys sys 1178568317 95923
+386/bin/upas/vf - 775 sys sys 1180900507 97407
 386/bin/usb - 20000000775 sys sys 1019538890 0
 386/bin/usb/usbaudio - 775 sys sys 1179548037 188012
 386/bin/usb/usbd - 775 sys sys 1179548037 130769
@@ -5314,7 +5314,7 @@ mail/lib/smtpd.conf - 664 upas upas 961114164 536
 mail/lib/spam.rc - 775 upas upas 1063950954 400
 mail/lib/unspam.rc - 775 upas upas 1063950954 400
 mail/lib/validateaddress - 775 upas upas 1098803974 48
-mail/lib/validateattachment - 775 upas upas 1128571809 1144
+mail/lib/validateattachment - 775 upas upas 1180857656 1209
 mail/lib/validatesender - 775 upas upas 1106233741 1128
 mail/lib/white.starter - 664 upas upas 1067739606 326
 mail/queue - 20000000777 upas upas 953302652 0
@@ -14192,7 +14192,7 @@ sys/src/cmd/upas/misc/omail.rc - 775 sys sys 944961318 197
 sys/src/cmd/upas/misc/qmail - 775 sys sys 944961318 119
 sys/src/cmd/upas/misc/remotemail - 775 sys sys 954266541 113
 sys/src/cmd/upas/misc/rewrite - 664 sys sys 954264578 661
-sys/src/cmd/upas/mkfile - 664 sys sys 1130423810 1916
+sys/src/cmd/upas/mkfile - 664 sys sys 1180844442 1937
 sys/src/cmd/upas/ml - 20000000775 sys sys 1064589605 0
 sys/src/cmd/upas/ml/common.c - 664 sys sys 1177589087 3379
 sys/src/cmd/upas/ml/dat.h - 664 sys sys 1015096762 517
@@ -14252,7 +14252,7 @@ sys/src/cmd/upas/unesc/mkfile - 664 sys sys 1173383407 142
 sys/src/cmd/upas/unesc/unesc.c - 664 sys sys 1173383408 969
 sys/src/cmd/upas/vf - 20000000775 sys sys 1064589607 0
 sys/src/cmd/upas/vf/mkfile - 664 sys sys 1064393881 241
-sys/src/cmd/upas/vf/vf.c - 664 sys sys 1143759341 20030
+sys/src/cmd/upas/vf/vf.c - 664 sys sys 1180857236 20273
 sys/src/cmd/usb - 20000000775 sys sys 1091205029 0
 sys/src/cmd/usb/audio - 20000000775 sys sys 1091204980 0
 sys/src/cmd/usb/audio/audiofs.c - 664 sys sys 1172903208 18518

+ 4 - 4
dist/replica/plan9.db

@@ -480,7 +480,7 @@
 386/bin/upas/token - 775 sys sys 1178568317 76393
 386/bin/upas/unesc - 775 sys sys 1176520512 60137
 386/bin/upas/unspam - 775 sys sys 1064598367 38
-386/bin/upas/vf - 775 sys sys 1178568317 95923
+386/bin/upas/vf - 775 sys sys 1180900507 97407
 386/bin/usb - 20000000775 sys sys 1019538890 0
 386/bin/usb/usbaudio - 775 sys sys 1179548037 188012
 386/bin/usb/usbd - 775 sys sys 1179548037 130769
@@ -5314,7 +5314,7 @@ mail/lib/smtpd.conf - 664 upas upas 961114164 536
 mail/lib/spam.rc - 775 upas upas 1063950954 400
 mail/lib/unspam.rc - 775 upas upas 1063950954 400
 mail/lib/validateaddress - 775 upas upas 1098803974 48
-mail/lib/validateattachment - 775 upas upas 1128571809 1144
+mail/lib/validateattachment - 775 upas upas 1180857656 1209
 mail/lib/validatesender - 775 upas upas 1106233741 1128
 mail/lib/white.starter - 664 upas upas 1067739606 326
 mail/queue - 20000000777 upas upas 953302652 0
@@ -14192,7 +14192,7 @@ sys/src/cmd/upas/misc/omail.rc - 775 sys sys 944961318 197
 sys/src/cmd/upas/misc/qmail - 775 sys sys 944961318 119
 sys/src/cmd/upas/misc/remotemail - 775 sys sys 954266541 113
 sys/src/cmd/upas/misc/rewrite - 664 sys sys 954264578 661
-sys/src/cmd/upas/mkfile - 664 sys sys 1130423810 1916
+sys/src/cmd/upas/mkfile - 664 sys sys 1180844442 1937
 sys/src/cmd/upas/ml - 20000000775 sys sys 1064589605 0
 sys/src/cmd/upas/ml/common.c - 664 sys sys 1177589087 3379
 sys/src/cmd/upas/ml/dat.h - 664 sys sys 1015096762 517
@@ -14252,7 +14252,7 @@ sys/src/cmd/upas/unesc/mkfile - 664 sys sys 1173383407 142
 sys/src/cmd/upas/unesc/unesc.c - 664 sys sys 1173383408 969
 sys/src/cmd/upas/vf - 20000000775 sys sys 1064589607 0
 sys/src/cmd/upas/vf/mkfile - 664 sys sys 1064393881 241
-sys/src/cmd/upas/vf/vf.c - 664 sys sys 1143759341 20030
+sys/src/cmd/upas/vf/vf.c - 664 sys sys 1180857236 20273
 sys/src/cmd/usb - 20000000775 sys sys 1091205029 0
 sys/src/cmd/usb/audio - 20000000775 sys sys 1091204980 0
 sys/src/cmd/usb/audio/audiofs.c - 664 sys sys 1172903208 18518

+ 6 - 0
dist/replica/plan9.log

@@ -49124,3 +49124,9 @@
 1180720823 0 c sys/man/8/6in4 - 664 sys sys 1180719862 1850
 1180724424 0 a lib/rfc - 20000000775 sys sys 1180723363 0
 1180726223 0 a lib/rfc/grabrfc - 775 sys sys 1180724499 804
+1180845022 0 c mail/lib/validateattachment - 775 upas upas 1180844764 1216
+1180845022 1 c sys/src/cmd/upas/mkfile - 664 sys sys 1180844442 1937
+1180845022 2 c sys/src/cmd/upas/vf/vf.c - 664 sys sys 1180844407 20273
+1180857641 0 c sys/src/cmd/upas/vf/vf.c - 664 sys sys 1180857236 20273
+1180859423 0 c mail/lib/validateattachment - 775 upas upas 1180857656 1209
+1180900822 0 c 386/bin/upas/vf - 775 sys sys 1180900507 97407

+ 10 - 8
mail/lib/validateattachment

@@ -1,6 +1,8 @@
 #!/bin/rc
-rfork n
-
+# validateattachment mboxfile
+rfork en
+upastmp=/mail/tmp
+#
 # exit status matching:
 #
 #	*discard* - is really bad, refuse the message 
@@ -14,12 +16,14 @@ if(! ~ $#* 1){
 }
 
 echo validating >[1=2]
-9fs other
 fn save {
 	d=`{date -n}
-	cp body /n/other/upas/tmp/$d.$1
-	cp raw /n/other/upas/tmp/$d.$1.raw
-	whatis x >/n/other/upas/tmp/$d.$1.file
+	cp body $upastmp/$d.$1
+	cp raw  $upastmp/$d.$1.raw
+	whatis x >$upastmp/$d.$1.file
+}
+fn sigexit {
+	rm -f $upastmp/$d.$1^('' .raw .file)
 }
 
 upas/fs -f $1
@@ -58,5 +62,3 @@ case *MSDOS*
 
 save wrap
 exit wrap
-
-

+ 2 - 3
sys/src/cmd/upas/mkfile

@@ -89,10 +89,9 @@ setup:V:
 	chmod 775 /mail
 	mkdir /mail/lib
 	chmod 775 /mail/lib
-	mkdir /mail/queue
-	mkdir /mail/box
-	mkdir /mail/tmp
+	mkdir	  /mail/queue /mail/box /mail/tmp
 	chmod 777 /mail/queue /mail/box /mail/tmp
+	chmod +t  /mail/queue /mail/tmp
 	mkdir /mail/ml
 	chmod 775 /mail/ml
 	cp misc/rewrite misc/qmail misc/remotemail misc/namefiles /mail/lib

+ 39 - 33
sys/src/cmd/upas/vf/vf.c

@@ -41,12 +41,12 @@ static void	writeheader(Part *p, int);
 
 enum
 {
-	// encodings
+	/* encodings */
 	Enone=	0,
 	Ebase64,
 	Equoted,
 
-	// disposition possibilities
+	/* disposition possibilities */
 	Dnone=	0,
 	Dinline,
 	Dfile,
@@ -156,10 +156,13 @@ main(int argc, char **argv)
 }
 
 void
-refuse(void)
+refuse(char *reason)
 {
-	postnote(PNGROUP, getpid(), "mail refused: we don't accept executable attachments");
-	exits("mail refused: we don't accept executable attachments");
+	static char msg[] =
+		"mail refused: we don't accept executable attachments";
+
+	postnote(PNGROUP, getpid(), smprint("%s: %s", msg, reason));
+	exits(msg);
 }
 
 
@@ -208,7 +211,7 @@ part(Part *pp)
 			passnotheader();
 			return part(p);
 		} else {
-			/* 
+			/*
 			 * This is the meat.  This may be an executable.
 			 * if so, wrap it and change its type
 			 */
@@ -216,11 +219,12 @@ part(Part *pp)
 				if(p->badfile == 2){
 					if(savefile != nil)
 						save(p, savefile);
-					syslog(0, "vf", "vf rejected %s %s", p->type?s_to_c(p->type):"?",
+					syslog(0, "vf", "vf rejected %s %s",
+						p->type? s_to_c(p->type): "?",
 						p->filename?s_to_c(p->filename):"?");
 					fprint(2, "The mail contained an executable attachment.\n");
 					fprint(2, "We refuse all mail containing such.\n");
-					refuse();
+					refuse(nil);
 				}
 				np = problemchild(p);
 				if(np != p)
@@ -384,7 +388,7 @@ save(Part *p, char *file)
 	Bprint(&out, "\n");
 	Bterm(&out);
 	close(fd);
-	
+
 	memset(&out, 0, sizeof out);
 	Binit(&out, 1, OWRITE);
 	return 0;
@@ -396,28 +400,30 @@ save(Part *p, char *file)
 static char*
 savetmp(Part *p)
 {
-	char buf[40], *name;
+	char *buf, *name;
 	int fd;
-	
-	strcpy(buf, "/tmp/vf.XXXXXXXXXXX");
+
+	buf = smprint("%s/vf.XXXXXXXXXXX", UPASTMP);
 	name = mktemp(buf);
 	if((fd = create(name, OWRITE|OEXCL, 0666)) < 0){
-		fprint(2, "error creating temporary file: %r\n");
-		refuse();
+		fprint(2, "%s: error creating temporary file: %r\n", argv0);
+		refuse("can't create temporary file");
 	}
+	free(buf);
 	close(fd);
 	if(save(p, name) < 0){
-		fprint(2, "error saving temporary file: %r\n");
-		refuse();
+		fprint(2, "%s: error saving temporary file: %r\n", argv0);
+		refuse("can't write temporary file");
 	}
 	if(p->tmpbuf){
-		fprint(2, "error in savetmp: already have tmp file!\n");
-		refuse();
+		fprint(2, "%s: error in savetmp: already have tmp file!\n",
+			argv0);
+		refuse("already have temporary file");
 	}
 	p->tmpbuf = Bopen(name, OREAD|ORCLOSE);
 	if(p->tmpbuf == nil){
-		fprint(2, "error reading tempoary file: %r\n");
-		refuse();
+		fprint(2, "%s: error reading temporary file: %r\n", argv0);
+		refuse("error reading temporary file");
 	}
 	Bseek(p->tmpbuf, bodyoff, 0);
 	return strdup(name);
@@ -432,10 +438,10 @@ runchecker(Part *p)
 	int pid;
 	char *name;
 	Waitmsg *w;
-	
+
 	if(access("/mail/lib/validateattachment", AEXEC) < 0)
 		return 0;
-	
+
 	name = savetmp(p);
 	fprint(2, "run checker %s\n", name);
 	switch(pid = fork()){
@@ -463,7 +469,7 @@ runchecker(Part *p)
 		name = s_to_c(p->filename);
 	if(strstr(w->msg, "discard")){
 		syslog(0, "mail", "vf validateattachment rejected %s", name);
-		refuse();
+		refuse("rejected by validateattachment");
 	}
 	if(strstr(w->msg, "accept")){
 		syslog(0, "mail", "vf validateattachment accepted %s", name);
@@ -588,7 +594,7 @@ isattribute(char **pp, char *attr)
 }
 
 /*
- *  parse content type header 
+ *  parse content type header
  */
 static void
 ctype(Part *p, Hdef *h, char *cp)
@@ -602,7 +608,7 @@ ctype(Part *p, Hdef *h, char *cp)
 	cp = getstring(cp, p->type, 1);
 	if(badtype(s_to_c(p->type)))
 		p->badtype = 1;
-	
+
 	while(*cp){
 		if(isattribute(&cp, "boundary")){
 			s = s_new();
@@ -624,13 +630,13 @@ ctype(Part *p, Hdef *h, char *cp)
 				p->charset = s_new();
 			cp = getstring(cp, s_reset(p->charset), 0);
 		}
-		
+
 		cp = skiptosemi(cp);
 	}
 }
 
 /*
- *  parse content encoding header 
+ *  parse content encoding header
  */
 static void
 cencoding(Part *m, Hdef *h, char *p)
@@ -644,7 +650,7 @@ cencoding(Part *m, Hdef *h, char *p)
 }
 
 /*
- *  parse content disposition header 
+ *  parse content disposition header
  */
 static void
 cdisposition(Part *p, Hdef *h, char *cp)
@@ -957,7 +963,7 @@ tokenconvert(String *t)
 	e = token+len-2;
 	token += 2;
 
-	// bail if we don't understand the character set
+	/* bail if we don't understand the character set */
 	for(i = 0; i < nelem(charsets); i++)
 		if(cistrncmp(charsets[i].name, token, charsets[i].len) == 0)
 		if(token[charsets[i].len] == '?'){
@@ -967,11 +973,11 @@ tokenconvert(String *t)
 	if(i >= nelem(charsets))
 		goto err;
 
-	// bail if it doesn't fit 
+	/* bail if it doesn't fit */
 	if(strlen(token) > sizeof(decoded)-1)
 		goto err;
 
-	// bail if we don't understand the encoding
+	/* bail if we don't understand the encoding */
 	if(cistrncmp(token, "b?", 2) == 0){
 		token += 2;
 		len = dec64((uchar*)decoded, sizeof(decoded), token, e-token);
@@ -1003,7 +1009,7 @@ err:
 }
 
 /*
- *  decode quoted 
+ *  decode quoted
  */
 enum
 {
@@ -1090,7 +1096,7 @@ decquoted(char *out, char *in, char *e)
 	if(in < e)
 		p = decquotedline(p, in, e-1);
 
-	// make sure we end with a new line
+	/* make sure we end with a new line */
 	if(*(p-1) != '\n'){
 		*p++ = '\n';
 		*p = 0;