diff -c -P --recursive --exclude=COPYRIGHT --exclude=COPYING netstd.orig/pop3d.orig/Makefile netstd/pop3d/Makefile
*** netstd.orig/pop3d.orig/Makefile	Sat Oct  9 20:10:30 1993
--- netstd/pop3d/Makefile	Sat Oct 21 00:20:23 1995
***************
*** 1,20 ****
  # make file for the IP/TCP/POP3 server for VAX/UNIX 4.3BSD
  
! CFLAGS=-O6 -s -DLINUX -DSHADOWPWD
  
! OBJS	= main.o folder.o util.o
! LIBS	= -lshadow
  
  all: pop3d
  
  install: all
! 	install -c -m 711 pop3d $(DESTDIR)/etc/pop3d
  
! clean: all
  	rm -f *.o core pop3d
  
  pop3d: $(OBJS)
! 	cc -o pop3d $(OBJS) $(LIBS)
  
  main.o:	main.c pop3.h
  folder.o: folder.c pop3.h
--- 1,22 ----
  # make file for the IP/TCP/POP3 server for VAX/UNIX 4.3BSD
  
! CFLAGS=-O2 -fno-strength-reduce -DLINUX # -DSHADOWPWD
  
! OBJS	= main.o folder.o util.o xcreat.o lock.o
! LIBS	= # -lshadow
  
  all: pop3d
  
  install: all
! 	install -o root -g mail -m 2755 pop3d ${DEBDIR}/usr/sbin/in.pop3d
! 	install -o root -g root -m 0644 pop3d.8 ${DEBDIR}/usr/man/man8 
! 	install -o root -g root -m 0644 in.pop3d.8 ${DEBDIR}/usr/man/man8 
  
! clean:
  	rm -f *.o core pop3d
  
  pop3d: $(OBJS)
! 	cc -s -o pop3d $(OBJS) $(LIBS)
  
  main.o:	main.c pop3.h
  folder.o: folder.c pop3.h
diff -c -P --recursive --exclude=COPYRIGHT --exclude=COPYING netstd.orig/pop3d.orig/README.Debian netstd/pop3d/README.Debian
*** netstd.orig/pop3d.orig/README.Debian	Thu Jan  1 01:00:00 1970
--- netstd/pop3d/README.Debian	Wed Nov 15 11:29:33 1995
***************
*** 0 ****
--- 1,21 ----
+ Last update: 05/03/94
+ 
+ The following things have been changed for the Debian distribution:
+ 
+ - changed the makefile (install target)
+ - changed the definitions for the mail and pop directories in pop3.h
+ - wrote a manpage for pop3d (from the catpage)
+ 
+ Peter Tobias <tobias@et-inf.fho-emden.de>
+ 
+ Additional changes:
+ 
+ - SIGPIPE caught
+ - reliable dotlocking
+ - sgid mail (for dotlocking, needed on most systems)
+ - syslog support
+ - disable MBOX command, fix security problem
+ - restrict HOST command, fix security problem
+ 
+ Stephen R. van den Berg <srb@cuci.nl>
+ - 
diff -c -P --recursive --exclude=COPYRIGHT --exclude=COPYING netstd.orig/pop3d.orig/folder.c netstd/pop3d/folder.c
*** netstd.orig/pop3d.orig/folder.c	Tue Jun  8 15:28:13 1993
--- netstd/pop3d/folder.c	Wed Nov 15 11:29:33 1995
***************
*** 110,116 ****
  	strcpy(cli_mbox,DEF_POP3_DIR);
  	strcat(cli_mbox,hostname);
  	/* Open mailbox */
! 	if ((cnt = fld_select(cli_mbox,1)) == -1) {
  		sprintf(svr_buf,"-ERR cannot open mailbox %s\r\n",
  			cli_mbox);
  		free(cli_mbox);
--- 110,116 ----
  	strcpy(cli_mbox,DEF_POP3_DIR);
  	strcat(cli_mbox,hostname);
  	/* Open mailbox */
! 	if (strchr(hostname,'/') || (cnt = fld_select(cli_mbox,1)) == -1) {
  		sprintf(svr_buf,"-ERR cannot open mailbox %s\r\n",
  			cli_mbox);
  		free(cli_mbox);
***************
*** 318,323 ****
--- 318,325 ----
  		return -1;
  	
  	/* Secure mailbox for POP3 session; copy to temporary file */
+ 	if (lockmbox(mbox))
+ 		return -1;
  	if ((mboxfp = fopen(mbox, "r")) == NULL)
  		return -1;
  	if ((lock = dup(fileno(mboxfp))) == -1) {
***************
*** 362,367 ****
--- 364,370 ----
  	/* Unlock mailbox */
  	flock(lock, LOCK_UN);
  	close(lock);
+ 	unlockmbox();
  
  	/* Prepare to use temporary file for POP3 session */
  	if (fld_max > 0) {
***************
*** 439,444 ****
--- 442,449 ----
  	/* Save changes made to original mailbox folder during
  	 * this POP3 session
  	 */
+ 	if (lockmbox(cli_mbox))
+ 		fail(FAIL_FILE_ERROR);
  	if (zap_orig_mbox == REMOVE_MBOX) {
  		/* No changes to save */
  		if ((mboxfp = fopen(cli_mbox, "w")) == NULL)
***************
*** 600,606 ****
  	/* Unlock original mailbox folder */
  	flock(lock, LOCK_UN);
  	close(lock);
! 
  
  cleanup:
  	/* Close and remove working copy of mailbox folder */
--- 605,611 ----
  	/* Unlock original mailbox folder */
  	flock(lock, LOCK_UN);
  	close(lock);
! 	unlockmbox();
  
  cleanup:
  	/* Close and remove working copy of mailbox folder */
diff -c -P --recursive --exclude=COPYRIGHT --exclude=COPYING netstd.orig/pop3d.orig/in.pop3d.8 netstd/pop3d/in.pop3d.8
*** netstd.orig/pop3d.orig/in.pop3d.8	Thu Jan  1 01:00:00 1970
--- netstd/pop3d/in.pop3d.8	Tue May 10 23:35:03 1994
***************
*** 0 ****
--- 1 ----
+ .so man8/pop3d.8
diff -c -P --recursive --exclude=COPYRIGHT --exclude=COPYING netstd.orig/pop3d.orig/lock.c netstd/pop3d/lock.c
*** netstd.orig/pop3d.orig/lock.c	Thu Jan  1 01:00:00 1970
--- netstd/pop3d/lock.c	Tue Oct 10 00:46:34 1995
***************
*** 0 ****
--- 1,36 ----
+ /************************************************************************
+  *	Created 1995, S.R. van den Berg, The Netherlands		*
+  *			<srb@cuci.nl>					*
+  ************************************************************************/
+ 
+ #include <string.h>
+ #include <stdlib.h>
+ 
+ #define LOCKSLEEP	8
+ 
+ static char*lastlocked;
+ static const char lockext[]=".lock";
+ 
+ #define STRLEN(x)	(sizeof(x)-1)
+ 
+ void unlockmbox()
+ { unlink(lastlocked);free(lastlocked);lastlocked=0;
+ }
+ 
+ int lockmbox(mbox)char*mbox;
+ { if(lastlocked)
+      unlockmbox();
+   if(lastlocked=malloc(strlen(mbox)+STRLEN(lockext)+1))
+    { strcpy(lastlocked,mbox);strcat(lastlocked,lockext);
+      for(;;)
+       { switch(xcreat(lastlocked))
+          { case 0:
+ 	      return 0;
+ 	   default:free(lastlocked);lastlocked=0;
+ 	      return -1;
+            case -1:sleep(LOCKSLEEP);
+          }
+       }
+    }
+   return -1;
+ }
diff -c -P --recursive --exclude=COPYRIGHT --exclude=COPYING netstd.orig/pop3d.orig/main.c netstd/pop3d/main.c
*** netstd.orig/pop3d.orig/main.c	Tue Jun  8 15:26:39 1993
--- netstd/pop3d/main.c	Wed Nov 15 11:29:33 1995
***************
*** 101,106 ****
--- 101,107 ----
  	signal(SIGALRM, svr_timeout);		/* timer expiration */
  
  	signal(SIGHUP, int_hangup);		/* socket signals */
+ 	signal(SIGPIPE, int_hangup);
  	signal(SIGURG, int_hangup);
  	signal(SIGTERM, int_hangup);
  
***************
*** 220,225 ****
--- 221,227 ----
  			fld_list(-1);
  		else
  			fld_list(atoi(inbuf));
+ #ifdef MBOX_CMD
  	} else if (strncmp(inbuf,"mbox",4) == 0) {
  		inbuf += 4;
  		EATSPACE(inbuf);
***************
*** 227,232 ****
--- 229,235 ----
  			sprintf(svr_buf,"-ERR must specify mailbox filename\r\n");
  		else
  			state = fld_fromsp(inbuf);
+ #endif
  	} else if (strncmp(inbuf,"noop",4) == 0) {
  		strcpy(svr_buf,"+OK\r\n");
  	} else if (strncmp(inbuf,"retr",4) == 0) {
***************
*** 256,262 ****
  		}
  	} else {
  		sprintf(svr_buf,
! 			"%s  DELE, HOST, LAST, LIST, MBOX, NOOP, RETR, RSET, STAT, TOP  or  QUIT\r\n",
  			svr_invalid);
  	}
  	return(state);
--- 259,269 ----
  		}
  	} else {
  		sprintf(svr_buf,
! 			"%s  DELE, HOST, LAST, LIST,"
! #ifdef MBOX_CMD
! 			" MBOX,"
! #endif
! 			" NOOP, RETR, RSET, STAT, TOP  or  QUIT\r\n",
  			svr_invalid);
  	}
  	return(state);
***************
*** 274,283 ****
--- 281,292 ----
  		inbuf += 4;
  		EATSPACE(inbuf);
  		state = fld_bsmtp(inbuf);
+ #ifdef MBOX_CMD
  	} else if (strncmp(inbuf,"mbox",4) == 0) {
  		inbuf += 4;
  		EATSPACE(inbuf);
  		state = fld_fromsp(inbuf);
+ #endif
  	} else if (strncmp(inbuf,"noop",4) == 0) {
  		strcpy(svr_buf,"+OK\r\n");
  	} else {
diff -c -P --recursive --exclude=COPYRIGHT --exclude=COPYING netstd.orig/pop3d.orig/pop3.h netstd/pop3d/pop3.h
*** netstd.orig/pop3d.orig/pop3.h	Tue Mar 16 23:30:28 1993
--- netstd/pop3d/pop3.h	Mon Mar 13 15:49:18 1995
***************
*** 80,87 ****
  #define SVR_BUFSIZ		1024
  #define CLI_BUFSIZ		128
  
! #define DEF_MAIL_DIR		"/usr/spool/mail/"
! #define DEF_POP3_DIR		"/usr/spool/pop/"
  #define POP3_TMPFILE		"/tmp/pop3XXXXXX"
  #define POP3_RCPT_HDR		"X-POP3-Rcpt:"
  
--- 80,87 ----
  #define SVR_BUFSIZ		1024
  #define CLI_BUFSIZ		128
  
! #define DEF_MAIL_DIR		"/var/spool/mail/"
! #define DEF_POP3_DIR		"/var/spool/pop/"
  #define POP3_TMPFILE		"/tmp/pop3XXXXXX"
  #define POP3_RCPT_HDR		"X-POP3-Rcpt:"
  
***************
*** 108,114 ****
  }
  
  /* #define DEBUG			1	Comment out for no debug file */
! #define LOGFILE			"/home/cc/cckatie/pop3d/pop3svr.log"
  
  #define FAIL_CONFUSION		51		/* unknown error */
  #define FAIL_FILE_ERROR		52		/* file read/write error */
--- 108,114 ----
  }
  
  /* #define DEBUG			1	Comment out for no debug file */
! #define LOGFILE			"/var/log/pop3svr.log"
  
  #define FAIL_CONFUSION		51		/* unknown error */
  #define FAIL_FILE_ERROR		52		/* file read/write error */
diff -c -P --recursive --exclude=COPYRIGHT --exclude=COPYING netstd.orig/pop3d.orig/pop3d.8 netstd/pop3d/pop3d.8
*** netstd.orig/pop3d.orig/pop3d.8	Thu Jan  1 01:00:00 1970
--- netstd/pop3d/pop3d.8	Tue May  3 13:53:47 1994
***************
*** 0 ****
--- 1,77 ----
+ .\" catpage converted back to manpage by <tobias@server.et-inf.fho-emden.de>
+ .TH POP3D 8 "May 2 1994" "Linux" "Linux Programmer's Manual"
+ .SH NAME
+ \fBpop3d\fP - remote maildrop access server
+ .SH SYNOPSIS
+ \fB/usr/sbin/in.pop3d\fP
+ .SH DESCRIPTION
+ \fBPop3d\fP
+ is a mailbox server based on the Internet RFC1225,
+ Post Office Protocol Version 3. The program allows remote
+ access to UNIX maildrops found in
+ \fB/var/spool/mail\fP.
+ The server requires user and password verification before a
+ maildrop can be opened. The server can retrieve and delete
+ messages from the maildrop on a per-message basis.
+ 
+ \fBPop3d\fP
+ listens for TCP requests on port 110. Once connected
+ it expects single line commands terminated by a <CR-LF>.
+ 
+ \fBPop3d\fP
+ currently supports the following POP3 commands; the
+ commands are case independent. In addition, the server
+ supports one extension command, HOST, which allows access
+ to BSMTP formatted maildrops in the directory
+ \fB/var/spool/pop\fP.
+ 
+ The syntax for the HOST command is:   HOST <hostname>
+ 
+ Example:	HOST fennario.ucdavis.edu
+ 
+ this will open the file at /var/spool/pop/fennario.ucdavis.edu
+ 
+ Command	Description
+ .br
+ USER		specify user for maildrop access
+ .br
+ PASS		specify password for maildrop access
+ .br
+ STAT		give message count and size of maildrop
+ .br
+ LIST		list size of individual messages
+ .br
+ RETR		retrieve a message
+ .br
+ DELE		delete a message
+ .br
+ NOOP		do nothing, return a positive response
+ .br
+ LAST		give highest message number accessed
+ .br
+ RSET		unmark messages marked for deletion
+ .br
+ TOP		retrieve part of a message
+ .br
+ QUIT		terminate session
+ 
+ The remaining optional command specified in RFC1225 (RPOP)
+ is not implemented.
+ 
+ .SH FILES
+ /var/spool/mail/*	UNIX FromSPACE delimited maildrops
+ /var/spool/pop/*	BSMTP formatted maildrops
+ 
+ .SH SEE ALSO
+ pop2d(8)
+ 
+ .SH AUTHOR
+ Katie Stevens, dkstevens@ucdavis.edu
+ .br
+ Information Technology -- Campus Access Point
+ .br
+ University of California, Davis
+ 
+ .SH NOTES
+ The POP3 standard supersedes Post Office Protocol Version 2
+ (POP2), described in RFC937.
diff -c -P --recursive --exclude=COPYRIGHT --exclude=COPYING netstd.orig/pop3d.orig/pop3d.man netstd/pop3d/pop3d.man
*** netstd.orig/pop3d.orig/pop3d.man	Tue Mar 16 23:31:09 1993
--- netstd/pop3d/pop3d.man	Tue May  3 12:46:52 1994
***************
*** 1,16 ****
! POP3D (8C)             UNIX Programmer's Manual            POP3D (8C)
  
  
  NAME
  	pop3d  --  remote maildrop access server
  
  SYNOPSIS
! 	/etc/pop3d
  
  DESCRIPTION
  	Pop3d is a mailbox server based on the Internet RFC1225,
  	Post Office Protocol Version 3. The program allows remote
! 	access to UNIX maildrops found in /usr/spool/mail. The
  	server requires user and password verification before a
  	maildrop can be opened. The server can retrieve and delete
  	messages from the maildrop on a per-message basis.
--- 1,16 ----
! POP3D (8)              UNIX Programmer's Manual             POP3D (8)
  
  
  NAME
  	pop3d  --  remote maildrop access server
  
  SYNOPSIS
! 	/usr/sbin/pop3d
  
  DESCRIPTION
  	Pop3d is a mailbox server based on the Internet RFC1225,
  	Post Office Protocol Version 3. The program allows remote
! 	access to UNIX maildrops found in /var/spool/mail. The
  	server requires user and password verification before a
  	maildrop can be opened. The server can retrieve and delete
  	messages from the maildrop on a per-message basis.
***************
*** 21,30 ****
  	Pop3d currently supports the following POP3 commands; the
  	commands are case independent. In addition, the server
  	supports one extension command, HOST, which allows access
! 	to BSMTP formatted maildrops in the directory /usr/spool/pop.
  	The syntax for the HOST command is:   HOST <hostname>
  	Example:	HOST fennario.ucdavis.edu
! 	this will open the file at /usr/spool/pop/fennario.ucdavis.edu
  
  	Command			Description
  	USER			specify user for maildrop access
--- 21,30 ----
  	Pop3d currently supports the following POP3 commands; the
  	commands are case independent. In addition, the server
  	supports one extension command, HOST, which allows access
! 	to BSMTP formatted maildrops in the directory /var/spool/pop.
  	The syntax for the HOST command is:   HOST <hostname>
  	Example:	HOST fennario.ucdavis.edu
! 	this will open the file at /var/spool/pop/fennario.ucdavis.edu
  
  	Command			Description
  	USER			specify user for maildrop access
***************
*** 43,53 ****
  	is not implemented.
  
  FILES
! 	/usr/spool/mail/*	UNIX FromSPACE delimited maildrops
! 	/usr/spool/pop/*	BSMTP formatted maildrops
  
  SEE ALSO
! 	pop2d(8C)
  
  AUTHOR
  	Katie Stevens, dkstevens@ucdavis.edu
--- 43,53 ----
  	is not implemented.
  
  FILES
! 	/var/spool/mail/*	UNIX FromSPACE delimited maildrops
! 	/var/spool/pop/*	BSMTP formatted maildrops
  
  SEE ALSO
! 	pop2d(8)
  
  AUTHOR
  	Katie Stevens, dkstevens@ucdavis.edu
diff -c -P --recursive --exclude=COPYRIGHT --exclude=COPYING netstd.orig/pop3d.orig/xcreat.c netstd/pop3d/xcreat.c
*** netstd.orig/pop3d.orig/xcreat.c	Thu Jan  1 01:00:00 1970
--- netstd/pop3d/xcreat.c	Tue Oct 10 00:46:34 1995
***************
*** 0 ****
--- 1,132 ----
+ /************************************************************************
+  *	secure exclusive creat/lock	v1.6 1995/05/05			*
+  *	(works even across NFS, which O_EXCL does *not*)		*
+  *									*
+  *	Created 1990-1995, S.R. van den Berg, The Netherlands		*
+  *			berg@pool.informatik.rwth-aachen.de		*
+  *			berg@physik.tu-muenchen.de			*
+  *									*
+  *	This file is donated to the public domain.			*
+  *									*
+  *	Usage: int xcreat(const char*filename,mode_t mode)		*
+  *									*
+  *	returns  0:success  -1:lock busy				*
+  *	 	-2:parameter error or out of memory			*
+  *									*
+  *		sets errno on failure					*
+  *									*
+  *	To remove a `lockfile', simply unlink it.			*
+  *									*
+  ************************************************************************/
+ #define HOSTNAMElen	9	      /* significant characters for hostname */
+ /*#define NOuname		      /* uncomment if uname is not available */
+ /*#define NOstrpbrk		    /* uncomment if strpbrk is not available */
+ /*#define strchr(s,c) index(s,c)     /* uncomment if strchr is not available */
+ #define const			      /* can be undefined for ANSI compilers */
+ static const char dirsep[]="/";			     /* directory separators */
+ 
+ #include <unistd.h>			/* open() close() link() unlink()
+ 					   getpid() */
+ #include <fcntl.h>			/* O_WRONLY O_CREAT O_EXCL */
+ #include <stdlib.h>			/* malloc() free() */
+ #include <string.h>			/* strncpy() strcat() strpbrk() */
+ #include <sys/stat.h>			/* stat() struct stat */
+ #ifndef NOuname
+ #include <sys/utsname.h>		/* uname() struct utsname */
+ #endif
+ #include <errno.h>
+ 
+ /************************************************************************
+  * Only edit below this line if you *think* you know what you are doing *
+  ************************************************************************/
+ 
+ #ifndef O_SYNC
+ #define O_SYNC		0
+ #endif
+ #ifndef	O_CREAT
+ #define	copen(path,type,mode)	creat(path,mode)
+ #else
+ #define copen(path,type,mode)	open(path,type,mode)
+ #endif
+ #define log(string)			      /* should log string to stderr */
+ #define UNIQ_PREFIX	'_'
+ #define charsSERIAL	4
+ #define UNIQnamelen	(1+charsSERIAL+HOSTNAMElen+1)
+ #define bitsSERIAL	(6*charsSERIAL)
+ #define maskSERIAL	((1L<<bitsSERIAL)-1)
+ #define rotbSERIAL	2
+ #define irotbSERIAL	(1L<<bitsSERIAL-rotbSERIAL)
+ #define mrotbSERIAL	((maskSERIAL&irotbSERIAL-1)+irotbSERIAL)
+ 
+ extern errno;
+ 
+ #ifdef NOstrpbrk
+ char*strpbrk(st,del)const char*const st,*del;
+ { const char*f=0,*t;
+   for(f=0;*del;)
+      if((t=strchr(st,*del++))&&(!f||t<f))
+         f=t;
+   return(char*)f;
+ }
+ #endif
+ 
+ static const char*hostname()
+ { static char name[HOSTNAMElen+1];
+ #ifdef	NOuname
+   gethostname(name,HOSTNAMElen+1);
+ #else
+   struct utsname names;
+   uname(&names);strncpy(name,names.nodename,HOSTNAMElen);
+ #endif
+   name[HOSTNAMElen]='\0';
+   return name;
+ }
+ 
+ static ultoan(val,dest)unsigned long val;char*dest;   /* convert to a number */
+ { register i;				     /* within the set [0-9A-Za-z-_] */
+   do
+    { i=val&0x3f;
+      *dest++=i+(i<10?'0':i<10+26?'A'-10:i<10+26+26?'a'-10-26:
+       i==10+26+26?'-'-10-26-26:'_'-10-26-27);
+    }
+   while(val>>=6);
+   *dest='\0';
+ }
+ 
+ static unique(full,p,mode)const char*const full;char*const p;const mode_t mode;
+ { unsigned long retry=mrotbSERIAL;int i;	  /* create unique file name */
+   do
+    { ultoan(maskSERIAL&(retry-=irotbSERIAL)+(long)getpid(),p+1);*p=UNIQ_PREFIX;
+      strcat(p,hostname());
+    }
+   while(0>(i=copen(full,O_WRONLY|O_CREAT|O_EXCL|O_SYNC,mode))&&errno==EEXIST&&
+    retry);	    /* casually check if it already exists (highly unlikely) */
+   if(i<0)
+    { log("Error while writing to \"");log(full);log("\"\n");
+      return 0;
+    }
+   close(i);
+   return 1;
+ }
+ 				     /* rename MUST fail if already existent */
+ static myrename(old,newn)const char*const old,*const newn;
+ { int i,serrno;struct stat stbuf;
+   if(!link(old,newn))
+    { unlink(old);
+      return 0;
+    }
+   serrno=errno;i=stat(old,&stbuf);unlink(old);errno=serrno;
+   return stbuf.st_nlink==2?i:-1;
+ }
+ 					/* an NFS secure exclusive file open */
+ xcreat(name,mode)char*name;const mode_t mode;
+ { char*p,*q;int j= -2,i;
+   for(q=name;p=strpbrk(q,dirsep);q=p+1);		 /* find last DIRSEP */
+   if(!(p=malloc((i=q-name)+UNIQnamelen)))		    /* out of memory */
+      return j;
+   strncpy(p,name,i);
+   if(unique(p,p+i,mode))
+      j=myrename(p,name);	 /* try and rename it, fails if nonexclusive */
+   free(p);
+   return j;
+ }
