--- rz.c.orig	Tue Mar 30 12:16:48 1999
+++ rz.c	Thu May 20 19:50:26 1999
@@ -1,5 +1,5 @@
-#define VERSION "3.50 03-30-99"
-#define PUBDIR "/usr/spool/uucppublic"
+#define VERSION "3.50/ache 03-30-99"
+#define PUBDIR "/var/spool/uucppublic"
 
 /*
  *
@@ -174,6 +174,8 @@
 int Zctlesc;		/* Encode control characters */
 int Zrwindow = 1400;	/* RX window size (controls garbage count) */
 
+int log_to_screen = 0;  /* Don't make log file */
+
 /*
  * Log an error
  */
@@ -205,9 +207,9 @@
 {
 	if (Verbose <= 0)
 		return;
-	fprintf(stderr, "Retry %d: ", errors);
-	fprintf(stderr, s, p, u);
-	fprintf(stderr, "\n");
+	fprintf(Logstream, "Retry %d: ", errors);
+	fprintf(Logstream, s, p, u);
+	fprintf(Logstream, "\n");
 }
 
 #include "zm.c"
@@ -222,7 +224,7 @@
 	if (Zmodem)
 		zmputs(Attn);
 	canit(); mode(0);
-	fprintf(stderr, "rz: caught signal %d; exiting", n);
+	fprintf(Logstream, "rz: caught signal %d; exiting\n", n);
 	exit(3);
 }
 
@@ -285,6 +287,9 @@
 						Zrwindow = atoi(*++argv);
 					}
 					break;
+				case 'V':
+					log_to_screen = 1;
+					/* fall */
 				case 'v':
 					++Verbose; break;
 				case 'y':
@@ -306,15 +311,15 @@
 		usage();
 	if (Batch && npats)
 		usage();
-	if (Verbose) {
-		if (freopen(LOGFILE, "a", stderr)==NULL)
-			if (freopen(LOGFILE2, "a", stderr)==NULL) {
+	if (Verbose && !log_to_screen) {
+		if ((Logstream = fopen(LOGFILE, "a"))==NULL)
+			if ((Logstream = fopen(LOGFILE2, "a"))==NULL) {
 				fprintf(stderr, "Can't open log file!\n");
-				exit(2);
-			}
-		setbuf(stderr, NULL);
-		fprintf(stderr, "argv[0]=%s Progname=%s\n", virgin, Progname);
-	}
+  				exit(2);
+  			}
+		setbuf(Logstream, NULL);
+		fprintf(Logstream, "argv[0]=%s Progname=%s\n", virgin, Progname);
+  	}
 	vfile("%s %s for %s tty=%s\n", Progname, VERSION, OS, Nametty);
 	mode(1);
 	if (signal(SIGINT, bibi) == SIG_IGN) {
@@ -330,8 +335,11 @@
 	}
 	if (exitcode && !Zmodem)	/* bellow again with all thy might. */
 		canit();
-	if (endmsg[0])
+	if (endmsg[0]) {
 		fprintf(stderr, "  %s: %s\r\n", Progname, endmsg);
+		if (Verbose)
+			fprintf(Logstream, "%s\r\n", endmsg);
+	}
 	fprintf(stderr, "%s %s finished.\r\n", Progname, VERSION);
 	fflush(stderr);
 #ifndef REGISTERED
@@ -355,10 +363,10 @@
 {
 	fprintf(stderr,
 	"Receive Files and Commands with ZMODEM/YMODEM/XMODEM Protocol\n\n");
-	fprintf(stderr,"Usage:	rz [-v]   [-wN] [-tT]	(ZMODEM)\n");
-	fprintf(stderr,"or	rb [-avy] [-tT]		(YMODEM)\n");
-	fprintf(stderr,"or	rc [-avy] [-tT] file	(XMODEM-CRC)\n");
-	fprintf(stderr,"or	rx [-avy] [-tT] file	(XMODEM)\n\n");
+	fprintf(stderr,"Usage:  rz [-vV]   [-wN] [-tT]   (ZMODEM)\n");
+	fprintf(stderr,"or      rb [-avVy] [-tT]         (YMODEM)\n");
+	fprintf(stderr,"or      rc [-avVy] [-tT] file    (XMODEM-CRC)\n");
+	fprintf(stderr,"or      rx [-avVy] [-tT] file    (XMODEM)\n\n");
 	fprintf(stderr,
 "Supports the following incoming ZMODEM options given to the sending program:\n\
 	compression (-Z), binary (-b), ASCII CR/LF>NL (-a), newer(-n),\n\
@@ -451,13 +459,13 @@
 
 et_tu:
 	Firstsec=TRUE;  Eofseen=FALSE;
+	purgeline();    /* Do read next time ... */
 	sendline(Crcflg?WANTCRC:NAK);  flushmo();
-	Lleft=0;	/* Do read next time ... */
 	switch (c = wcgetsec(rpn, 100)) {
 	case WCEOT:
 		zperr2( "Pathname fetch returned %d", c);
+		purgeline();    /* Do read next time ... */
 		sendline(ACK);  flushmo();
-		Lleft=0;	/* Do read next time ... */
 		readline(1);
 		goto et_tu;
 	case 0:
@@ -482,9 +490,9 @@
 	sendchar=Crcflg?WANTCRC:NAK;
 
 	for (;;) {
+		purgeline();    /* Do read next time ... */
 		sendline(sendchar);	/* send it now, we're ready! */
 		flushmo();
-		Lleft=0;	/* Do read next time ... */
 		sectcurr=wcgetsec(secbuf, (sectnum&0177)?50:130);
 		if (sectcurr==(sectnum+1 &0377)) {
 			sectnum++;
@@ -502,8 +510,8 @@
 		else if (sectcurr==WCEOT) {
 			if (closeit())
 				return ERROR;
+			purgeline();    /* Do read next time ... */
 			sendline(ACK); flushmo();
-			Lleft=0;	/* Do read next time ... */
 			return OK;
 		}
 		else if (sectcurr==ERROR)
@@ -602,11 +610,11 @@
 		while(readline(1)!=TIMEOUT)
 			;
 		if (Firstsec) {
+			purgeline();    /* Do read next time ... */
 			sendline(Crcflg?WANTCRC:NAK);  flushmo();
-			Lleft=0;	/* Do read next time ... */
 		} else {
+			purgeline();    /* Do read next time ... */
 			maxtime=40; sendline(NAK);  flushmo();
-			Lleft=0;	/* Do read next time ... */
 		}
 	}
 	/* try to stop the bubble machine. */
@@ -660,9 +668,9 @@
 		if (Filemode & UNIXFILE)
 			++Thisbinary;
 		if (Verbose) {
-			fprintf(stderr,  "Incoming: %s %ld %lo %o\n",
+			fprintf(Logstream,  "Incoming: %s %ld %lo %o\n",
 			  name, Bytesleft, Modtime, Filemode);
-			fprintf(stderr,  "YMODEM header: %s\n", p);
+			fprintf(Logstream,  "YMODEM header: %s\n", p);
 		}
 	}
 
@@ -683,7 +691,7 @@
 		zmanag &= ZMMASK;
 		if (zmanag==ZMPROT)
 			goto skipfile;
-		vfile("Current %s is %ld %lo", name, f.st_size, f.st_mtime);
+		vfile("Current %s is %ld %lo", name, (long)f.st_size, f.st_mtime);
 		if (Thisbinary && zconv==ZCRESUM) {
 			rxbytes = f.st_size & ~511;
 			if (Bytesleft < rxbytes) {
@@ -930,7 +938,7 @@
 	if (Restricted) {
 		if (fopen(name, "r") != NULL) {
 			canit();
-			fprintf(stderr, "\r\nrz: %s exists\n", name);
+			fprintf(stderr, "\r\nrz: %s exists\r\n", name);
 			bibi(-1);
 		}
 		/* restrict pathnames to current tree or uucppublic */
@@ -1049,6 +1057,10 @@
 				return ERROR;
 			}
 #endif
+#ifndef BIG_SECURITY_HOLE
+			sprintf(endmsg, "ZCOMMAND Denied.");
+			return ERROR;
+#else
 			cmdzack1flg = Rxhdr[ZF0];
 			if (zrdata(secbuf, 1024) == GOTCRCW) {
 				void exec2();
@@ -1068,6 +1080,7 @@
 				return ZCOMPL;
 			}
 			zshhdr(4,ZNAK, Txhdr); goto again;
+#endif
 		case ZCOMPL:
 			goto again;
 		default:
@@ -1222,7 +1235,7 @@
 			}
 moredata:
 			if (Verbose>1)
-				fprintf(stderr, "%7ld ZMODEM%s\n",
+				fprintf(Logstream, "%7ld ZMODEM%s\n",
 				  rxbytes, Crc32r?" CRC-32":"");
 #ifdef SEGMENTS
 			if (chinseg >= (1024 * SEGMENTS)) {
