Subject: misc/3639: Cleanup of ftpd code
To: None <gnats-bugs@gnats.netbsd.org>
From: None <darcy@druid.net>
List: netbsd-bugs
Date: 05/17/1997 16:14:05
>Number:         3639
>Category:       misc
>Synopsis:       Cleanup of ftpd code
>Confidential:   no
>Severity:       non-critical
>Priority:       high
>Responsible:    misc-bug-people (Misc Bug People)
>State:          open
>Class:          change-request
>Submitter-Id:   net
>Arrival-Date:   Sat May 17 13:20:02 1997
>Last-Modified:
>Originator:     D'Arcy J.M. Cain
>Organization:
D'Arcy J.M. Cain                           |  Democracy is three wolves
darcy@{druid.net|vex.net}                  |  and a sheep voting on         
+1 416 424 2871     (DoD#0082)    (eNTP)   |  what's for dinner.
                --  http://www.druid.net/darcy  --                       
>Release:        NetBSD-current
>Environment:
	
System: NetBSD druid.net 1.2E NetBSD 1.2E (DRUID) #1: Fri May 16 08:20:31 EDT 1997 darcy@druid.net:/usr/src/sys/arch/i386/compile/DRUID i386


>Description:
	I have made some changes to the code to clean it up.  In fact I
	want to add a new option but I thought I would send in the cleanup
	first then work on an official version with the enhancement.
	FYI, the enhancement will allow the chrooted directory for anon
	logins to be defined on the command line.  Given the way NetBSD's
	inetd works, this should be the only change necessary to make
	virtual ftp domains work.
>How-To-Repeat:
	N/A
>Fix:
	Here are the diffs.  Included in these changes are;

		- Make the function calls ANSI style
		- Add many const keywords
		- Remove "(void)" from function calls
		- Minor code cleanups and comments
		- Document the 'u' option in the man page

I realize that removing "(void)" from in front of function calls is
a somewhat religious call.  That's why I point it out here so that
you can decide for yourself whether to make this change.


*** ../src.original/./libexec/ftpd/extern.h	Sat May 17 09:31:35 1997
--- ./libexec/ftpd/extern.h	Sat May 17 15:42:57 1997
***************
*** 37,67 ****
  
  void	blkfree __P((char **));
  char  **copyblk __P((char **));
! void	cwd __P((char *));
! void	delete __P((char *));
  void	dologout __P((int));
  void	fatal __P((char *));
  int	ftpd_pclose __P((FILE *));
! FILE   *ftpd_popen __P((char *, char *));
  char   *getline __P((char *, int, FILE *));
! void	logwtmp __P((char *, char *, char *));
  void	lreply __P((int, const char *, ...));
! void	makedir __P((char *));
! void	nack __P((char *));
! void	pass __P((char *));
  void	passive __P((void));
! void	perror_reply __P((int, char *));
! void	pwd __P((void));
! void	removedir __P((char *));
! void	renamecmd __P((char *, char *));
  char   *renamefrom __P((char *));
  void	reply __P((int, const char *, ...));
! void	retrieve __P((char *, char *));
! void	send_file_list __P((char *));
  void	setproctitle __P((const char *, ...));
  void	statcmd __P((void));
! void	statfilecmd __P((char *));
! void	store __P((char *, char *, int));
  void	upper __P((char *));
! void	user __P((char *));
! void	yyerror __P((char *));
--- 37,67 ----
  
  void	blkfree __P((char **));
  char  **copyblk __P((char **));
! void	cwd __P((const char *));
! void	delete __P((const char *));
  void	dologout __P((int));
  void	fatal __P((char *));
  int	ftpd_pclose __P((FILE *));
! FILE   *ftpd_popen __P((char *, const char *));
  char   *getline __P((char *, int, FILE *));
! void	logwtmp __P((const char *, const char *, const char *));
  void	lreply __P((int, const char *, ...));
! void	makedir __P((const char *));
! void	nack __P((const char *));
! void	pass __P((const char *));
  void	passive __P((void));
! void	perror_reply __P((int, const char *));
! void	pwd __P((const void));
! void	removedir __P((const char *));
! void	renamecmd __P((const char *, const char *));
  char   *renamefrom __P((char *));
  void	reply __P((int, const char *, ...));
! void	retrieve __P((const char *, const char *));
! void	send_file_list __P((const char *));
  void	setproctitle __P((const char *, ...));
  void	statcmd __P((void));
! void	statfilecmd __P((const char *));
! void	store __P((const char *, const char *, int));
  void	upper __P((char *));
! void	user __P((const char *));
! void	yyerror __P((const char *));
*** ../src.original/./libexec/ftpd/ftpcmd.y	Sat May 17 12:06:37 1997
--- ./libexec/ftpd/ftpcmd.y	Sat May 17 15:54:17 1997
***************
*** 158,164 ****
  		{
  			usedefault = 0;
  			if (pdata >= 0) {
! 				(void) close(pdata);
  				pdata = -1;
  			}
  			reply(200, "PORT command successful.");
--- 158,164 ----
  		{
  			usedefault = 0;
  			if (pdata >= 0) {
! 				close(pdata);
  				pdata = -1;
  			}
  			reply(200, "PORT command successful.");
***************
*** 237,243 ****
  	| RETR check_login SP pathname CRLF
  		{
  			if ($2 && $4 != NULL)
! 				retrieve((char *) 0, $4);
  			if ($4 != NULL)
  				free($4);
  		}
--- 237,243 ----
  	| RETR check_login SP pathname CRLF
  		{
  			if ($2 && $4 != NULL)
! 				retrieve(NULL, $4);
  			if ($4 != NULL)
  				free($4);
  		}
***************
*** 385,391 ****
  
  			if ($4) {
  				oldmask = umask(0);
! 				(void) umask(oldmask);
  				reply(200, "Current UMASK is %03o", oldmask);
  			}
  		}
--- 385,391 ----
  
  			if ($4) {
  				oldmask = umask(0);
! 				umask(oldmask);
  				reply(200, "Current UMASK is %03o", oldmask);
  			}
  		}
***************
*** 432,438 ****
  				    maxtimeout);
  			} else {
  				timeout = $5;
! 				(void) alarm((unsigned) timeout);
  				reply(200,
  				    "Maximum IDLE time set to %d seconds",
  				    timeout);
--- 432,438 ----
  				    maxtimeout);
  			} else {
  				timeout = $5;
! 				alarm((unsigned) timeout);
  				reply(200,
  				    "Maximum IDLE time set to %d seconds",
  				    timeout);
***************
*** 518,525 ****
  rcmd
  	: RNFR check_login SP pathname CRLF
  		{
- 			char *renamefrom();
- 
  			restart_point = (off_t) 0;
  			if ($2 && $4) {
  				fromname = renamefrom($4);
--- 518,523 ----
***************
*** 767,773 ****
  	short	token;
  	short	state;
  	short	implemented;	/* 1 if command is implemented */
! 	char	*help;
  };
  
  struct tab cmdtab[] = {		/* In order defined in RFC 765 */
--- 765,771 ----
  	short		token;
  	short		state;
  	short		implemented;	/* 1 if command is implemented */
! 	const char	*help;
  };
  
  struct tab cmdtab[] = {		/* In order defined in RFC 765 */
***************
*** 829,848 ****
  	{ NULL,   0,    0,    0,	0 }
  };
  
! static char	*copy __P((char *));
  static void	 help __P((struct tab *, char *));
  static struct tab *
! 		 lookup __P((struct tab *, char *));
! static void	 sizecmd __P((char *));
  static void	 toolong __P((int));
  static int	 yylex __P((void));
  
  static struct tab *
! lookup(p, cmd)
! 	struct tab *p;
! 	char *cmd;
  {
- 
  	for (; p->name != NULL; p++)
  		if (strcmp(cmd, p->name) == 0)
  			return (p);
--- 827,843 ----
  	{ NULL,   0,    0,    0,	0 }
  };
  
! static char	*copy __P((const char *));
  static void	 help __P((struct tab *, char *));
  static struct tab *
! 		 lookup __P((struct tab *, const char *));
! static void	 sizecmd __P((const char *));
  static void	 toolong __P((int));
  static int	 yylex __P((void));
  
  static struct tab *
! lookup(struct tab *p, const char *cmd)
  {
  	for (; p->name != NULL; p++)
  		if (strcmp(cmd, p->name) == 0)
  			return (p);
***************
*** 855,869 ****
   * getline - a hacked up version of fgets to ignore TELNET escape codes.
   */
  char *
! getline(s, n, iop)
! 	char *s;
! 	int n;
! 	FILE *iop;
  {
  	int c;
! 	register char *cs;
  
- 	cs = s;
  /* tmpline may contain saved command from urgent mode interruption */
  	for (c = 0; tmpline[c] != '\0' && --n > 0; ++c) {
  		*cs++ = tmpline[c];
--- 850,860 ----
   * getline - a hacked up version of fgets to ignore TELNET escape codes.
   */
  char *
! getline(char *s, int n, FILE *iop)
  {
  	int c;
! 	register char *cs = s;
  
  /* tmpline may contain saved command from urgent mode interruption */
  	for (c = 0; tmpline[c] != '\0' && --n > 0; ++c) {
  		*cs++ = tmpline[c];
***************
*** 887,899 ****
  			case WONT:
  				c = getc(iop);
  				printf("%c%c%c", IAC, DONT, 0377&c);
! 				(void) fflush(stdout);
  				continue;
  			case DO:
  			case DONT:
  				c = getc(iop);
  				printf("%c%c%c", IAC, WONT, 0377&c);
! 				(void) fflush(stdout);
  				continue;
  			case IAC:
  				break;
--- 878,890 ----
  			case WONT:
  				c = getc(iop);
  				printf("%c%c%c", IAC, DONT, 0377&c);
! 				fflush(stdout);
  				continue;
  			case DO:
  			case DONT:
  				c = getc(iop);
  				printf("%c%c%c", IAC, WONT, 0377&c);
! 				fflush(stdout);
  				continue;
  			case IAC:
  				break;
***************
*** 931,940 ****
  }
  
  static void
! toolong(signo)
! 	int signo;
  {
- 
  	reply(421,
  	    "Timeout (%d seconds): closing control connection.", timeout);
  	if (logging)
--- 922,929 ----
  }
  
  static void
! toolong(int signo)
  {
  	reply(421,
  	    "Timeout (%d seconds): closing control connection.", timeout);
  	if (logging)
***************
*** 944,950 ****
  }
  
  static int
! yylex()
  {
  	static int cpos, state;
  	char *cp, *cp2;
--- 933,939 ----
  }
  
  static int
! yylex(void)
  {
  	static int cpos, state;
  	char *cp, *cp2;
***************
*** 956,968 ****
  		switch (state) {
  
  		case CMD:
! 			(void) signal(SIGALRM, toolong);
! 			(void) alarm((unsigned) timeout);
  			if (getline(cbuf, sizeof(cbuf)-1, stdin) == NULL) {
  				reply(221, "You could at least say goodbye.");
  				dologout(0);
  			}
! 			(void) alarm(0);
  #ifdef HASSETPROCTITLE
  			if (strncasecmp(cbuf, "PASS", 4) != NULL)
  				setproctitle("%s: %s", proctitle, cbuf);
--- 945,957 ----
  		switch (state) {
  
  		case CMD:
! 			signal(SIGALRM, toolong);
! 			alarm((unsigned) timeout);
  			if (getline(cbuf, sizeof(cbuf)-1, stdin) == NULL) {
  				reply(221, "You could at least say goodbye.");
  				dologout(0);
  			}
! 			alarm(0);
  #ifdef HASSETPROCTITLE
  			if (strncasecmp(cbuf, "PASS", 4) != NULL)
  				setproctitle("%s: %s", proctitle, cbuf);
***************
*** 1162,1198 ****
  }
  
  void
! upper(s)
! 	char *s;
  {
! 	while (*s != '\0') {
! 		if (islower(*s))
  			*s = toupper(*s);
- 		s++;
- 	}
  }
  
  static char *
! copy(s)
! 	char *s;
  {
  	char *p;
  
! 	p = malloc((unsigned) strlen(s) + 1);
! 	if (p == NULL)
  		fatal("Ran out of memory.");
! 	(void) strcpy(p, s);
! 	return (p);
  }
  
  static void
! help(ctab, s)
! 	struct tab *ctab;
! 	char *s;
  {
  	struct tab *c;
  	int width, NCMDS;
! 	char *type;
  
  	if (ctab == sitetab)
  		type = "SITE ";
--- 1151,1180 ----
  }
  
  void
! upper(char *s)
  {
! 	/* no need to test character - toupper is safe according to Posix */
! 	for (; *s; s++)
  		*s = toupper(*s);
  }
  
  static char *
! copy(const char *s)
  {
  	char *p;
  
! 	if ((p = malloc((unsigned) strlen(s) + 1)) == NULL)
  		fatal("Ran out of memory.");
! 
! 	return strcpy(p, s);
  }
  
  static void
! help(struct tab *ctab, char *s)
  {
  	struct tab *c;
  	int width, NCMDS;
! 	const char *type;
  
  	if (ctab == sitetab)
  		type = "SITE ";
***************
*** 1233,1239 ****
  			}
  			printf("\r\n");
  		}
! 		(void) fflush(stdout);
  		reply(214, "Direct comments to ftp-bugs@%s.", hostname);
  		return;
  	}
--- 1215,1221 ----
  			}
  			printf("\r\n");
  		}
! 		fflush(stdout);
  		reply(214, "Direct comments to ftp-bugs@%s.", hostname);
  		return;
  	}
***************
*** 1251,1258 ****
  }
  
  static void
! sizecmd(filename)
! 	char *filename;
  {
  	switch (type) {
  	case TYPE_L:
--- 1233,1239 ----
  }
  
  static void
! sizecmd(const char *filename)
  {
  	switch (type) {
  	case TYPE_L:
***************
*** 1275,1281 ****
  		}
  		if (fstat(fileno(fin), &stbuf) < 0 || !S_ISREG(stbuf.st_mode)) {
  			reply(550, "%s: not a plain file.", filename);
! 			(void) fclose(fin);
  			return;
  		}
  
--- 1256,1262 ----
  		}
  		if (fstat(fileno(fin), &stbuf) < 0 || !S_ISREG(stbuf.st_mode)) {
  			reply(550, "%s: not a plain file.", filename);
! 			fclose(fin);
  			return;
  		}
  
***************
*** 1285,1291 ****
  				count++;
  			count++;
  		}
! 		(void) fclose(fin);
  
  		reply(213, "%qd", count);
  		break; }
--- 1266,1272 ----
  				count++;
  			count++;
  		}
! 		fclose(fin);
  
  		reply(213, "%qd", count);
  		break; }
*** ../src.original/./libexec/ftpd/ftpd.8	Sat May 17 13:25:16 1997
--- ./libexec/ftpd/ftpd.8	Sat May 17 13:28:24 1997
***************
*** 80,85 ****
--- 80,87 ----
  The inactivity timeout period is set to
  .Ar timeout
  seconds (the default is 15 minutes).
+ .It Fl u
+ Sets the default umask.  Must be in octal form, e.g. "002"
  .El
  .Pp
  The file
*** ../src.original/./libexec/ftpd/ftpd.c	Sat May 17 09:15:45 1997
--- ./libexec/ftpd/ftpd.c	Sat May 17 15:57:50 1997
***************
*** 176,200 ****
  			cmd, (*(file) == '/') ? "" : curdir(), file, cnt); \
  	}
  
! static void	 ack __P((char *));
  static void	 myoob __P((int));
! static int	 checkuser __P((char *, char *));
! static int	 checkaccess __P((char *));
! static FILE	*dataconn __P((char *, off_t, char *));
  static void	 dolog __P((struct sockaddr_in *));
  static char	*curdir __P((void));
  static void	 end_login __P((void));
! static FILE	*getdatasock __P((char *));
! static char	*gunique __P((char *));
  static void	 lostconn __P((int));
  static int	 receive_data __P((FILE *, FILE *));
  static void	 send_data __P((FILE *, FILE *, off_t));
  static struct passwd *
! 		 sgetpwnam __P((char *));
! static char	*sgetsave __P((char *));
  
  static char *
! curdir()
  {
  	static char path[MAXPATHLEN+1+1];	/* path + '/' + '\0' */
  
--- 176,200 ----
  			cmd, (*(file) == '/') ? "" : curdir(), file, cnt); \
  	}
  
! static void	 ack __P((const char *));
  static void	 myoob __P((int));
! static int	 checkuser __P((const char *, const char *));
! static int	 checkaccess __P((const char *));
! static FILE	*dataconn __P((const char *, off_t, const char *));
  static void	 dolog __P((struct sockaddr_in *));
  static char	*curdir __P((void));
  static void	 end_login __P((void));
! static FILE	*getdatasock __P((const char *));
! static char	*gunique __P((const char *));
  static void	 lostconn __P((int));
  static int	 receive_data __P((FILE *, FILE *));
  static void	 send_data __P((FILE *, FILE *, off_t));
  static struct passwd *
! 		 sgetpwnam __P((const char *));
! static char	*sgetsave __P((const char *));
  
  static char *
! curdir(void)
  {
  	static char path[MAXPATHLEN+1+1];	/* path + '/' + '\0' */
  
***************
*** 207,216 ****
  }
  
  int
! main(argc, argv, envp)
! 	int argc;
! 	char *argv[];
! 	char **envp;
  {
  	int addrlen, ch, on = 1, tos;
  	char *cp, line[LINE_MAX];
--- 207,213 ----
  }
  
  int
! main(int argc, char **argv)
  {
  	int addrlen, ch, on = 1, tos;
  	char *cp, line[LINE_MAX];
***************
*** 240,250 ****
  	debug = 0;
  
  	/* set this here so klogin can use it... */
! 	(void)sprintf(ttyline, "ftp%d", getpid());
  
  	while ((ch = getopt(argc, argv, "dlt:T:u:v")) != EOF) {
  		switch (ch) {
  		case 'd':
  			debug = 1;
  			break;
  
--- 237,248 ----
  	debug = 0;
  
  	/* set this here so klogin can use it... */
! 	sprintf(ttyline, "ftp%d", getpid());
  
  	while ((ch = getopt(argc, argv, "dlt:T:u:v")) != EOF) {
  		switch (ch) {
  		case 'd':
+ 		case 'v':		/* deprecated - here for backwards compatibility */
  			debug = 1;
  			break;
  
***************
*** 276,293 ****
  			break;
  		    }
  
- 		case 'v':
- 			debug = 1;
- 			break;
- 
  		default:
  			warnx("unknown flag -%c ignored", optopt);
  			break;
  		}
  	}
! 	(void) freopen(_PATH_DEVNULL, "w", stderr);
! 	(void) signal(SIGPIPE, lostconn);
! 	(void) signal(SIGCHLD, SIG_IGN);
  	if ((long)signal(SIGURG, myoob) < 0)
  		syslog(LOG_ERR, "signal: %m");
  
--- 274,287 ----
  			break;
  		    }
  
  		default:
  			warnx("unknown flag -%c ignored", optopt);
  			break;
  		}
  	}
! 	freopen(_PATH_DEVNULL, "w", stderr);
! 	signal(SIGPIPE, lostconn);
! 	signal(SIGCHLD, SIG_IGN);
  	if ((long)signal(SIGURG, myoob) < 0)
  		syslog(LOG_ERR, "signal: %m");
  
***************
*** 319,326 ****
  				*cp = '\0';
  			lreply(530, "%s", line);
  		}
! 		(void) fflush(stdout);
! 		(void) fclose(fd);
  		reply(530, "System not available.");
  		exit(0);
  	}
--- 313,320 ----
  				*cp = '\0';
  			lreply(530, "%s", line);
  		}
! 		fflush(stdout);
! 		fclose(fd);
  		reply(530, "System not available.");
  		exit(0);
  	}
***************
*** 330,350 ****
  				*cp = '\0';
  			lreply(220, "%s", line);
  		}
! 		(void) fflush(stdout);
! 		(void) fclose(fd);
  		/* reply(220,) must follow */
  	}
! 	(void) gethostname(hostname, sizeof(hostname));
  	reply(220, "%s FTP server (%s) ready.", hostname, version);
! 	(void) setjmp(errcatch);
  	for (;;)
! 		(void) yyparse();
  	/* NOTREACHED */
  }
  
  static void
! lostconn(signo)
! 	int signo;
  {
  
  	if (debug)
--- 324,343 ----
  				*cp = '\0';
  			lreply(220, "%s", line);
  		}
! 		fflush(stdout);
! 		fclose(fd);
  		/* reply(220,) must follow */
  	}
! 	gethostname(hostname, sizeof(hostname));
  	reply(220, "%s FTP server (%s) ready.", hostname, version);
! 	setjmp(errcatch);
  	for (;;)
! 		yyparse();
  	/* NOTREACHED */
  }
  
  static void
! lostconn(int signo)
  {
  
  	if (debug)
***************
*** 356,363 ****
   * Helper function for sgetpwnam().
   */
  static char *
! sgetsave(s)
! 	char *s;
  {
  	char *new = malloc((unsigned) strlen(s) + 1);
  
--- 349,355 ----
   * Helper function for sgetpwnam().
   */
  static char *
! sgetsave(const char *s)
  {
  	char *new = malloc((unsigned) strlen(s) + 1);
  
***************
*** 366,372 ****
  		dologout(1);
  		/* NOTREACHED */
  	}
! 	(void) strcpy(new, s);
  	return (new);
  }
  
--- 358,364 ----
  		dologout(1);
  		/* NOTREACHED */
  	}
! 	strcpy(new, s);
  	return (new);
  }
  
***************
*** 376,383 ****
   * (e.g., globbing).
   */
  static struct passwd *
! sgetpwnam(name)
! 	char *name;
  {
  	static struct passwd save;
  	struct passwd *p;
--- 368,374 ----
   * (e.g., globbing).
   */
  static struct passwd *
! sgetpwnam(const char *name)
  {
  	static struct passwd save;
  	struct passwd *p;
***************
*** 416,423 ****
   * _PATH_FTPUSERS to allow people such as root and uucp to be avoided.
   */
  void
! user(name)
! 	char *name;
  {
  	if (logged_in) {
  		if (guest) {
--- 407,413 ----
   * _PATH_FTPUSERS to allow people such as root and uucp to be avoided.
   */
  void
! user(const char *name)
  {
  	if (logged_in) {
  		if (guest) {
***************
*** 451,457 ****
  		strncpy(curname, name, sizeof(curname)-1);
  #ifdef SKEY
  	if (!skey_haskey(name)) {
! 		char *myskey, *skey_keyinfo __P((char *name));
  
  		myskey = skey_keyinfo(name);
  		reply(331, "Password [%s] for %s required.",
--- 441,447 ----
  		strncpy(curname, name, sizeof(curname)-1);
  #ifdef SKEY
  	if (!skey_haskey(name)) {
! 		const char *myskey, *skey_keyinfo __P((const char *name));
  
  		myskey = skey_keyinfo(name);
  		reply(331, "Password [%s] for %s required.",
***************
*** 473,481 ****
   * Check if a user is in the file "fname"
   */
  static int
! checkuser(fname, name)
! 	char *fname;
! 	char *name;
  {
  	FILE *fd;
  	int found = 0;
--- 463,469 ----
   * Check if a user is in the file "fname"
   */
  static int
! checkuser(const char *fname, const char *name)
  {
  	FILE *fd;
  	int found = 0;
***************
*** 492,498 ****
  					break;
  				}
  			}
! 		(void) fclose(fd);
  	}
  	return (found);
  }
--- 480,486 ----
  					break;
  				}
  			}
! 		fclose(fd);
  	}
  	return (found);
  }
***************
*** 518,525 ****
   * Return 1 if the user is denied, or 0 if he is allowed.
   */
  static int
! checkaccess(name)
! 	char *name;
  {
  #define ALLOWED		0
  #define	NOT_ALLOWED	1
--- 506,512 ----
   * Return 1 if the user is denied, or 0 if he is allowed.
   */
  static int
! checkaccess(const char *name)
  {
  #define ALLOWED		0
  #define	NOT_ALLOWED	1
***************
*** 543,549 ****
  			break;
  		}
  	}
! 	(void) fclose(fd);
  	return (retval);
  
  }
--- 530,536 ----
  			break;
  		}
  	}
! 	fclose(fd);
  	return (retval);
  
  }
***************
*** 555,564 ****
   * used when USER command is given or login fails.
   */
  static void
! end_login()
  {
  
! 	(void) seteuid((uid_t)0);
  	if (logged_in)
  		logwtmp(ttyline, "", "");
  	pw = NULL;
--- 542,551 ----
   * used when USER command is given or login fails.
   */
  static void
! end_login(void)
  {
  
! 	seteuid((uid_t)0);
  	if (logged_in)
  		logwtmp(ttyline, "", "");
  	pw = NULL;
***************
*** 568,575 ****
  }
  
  void
! pass(passwd)
! 	char *passwd;
  {
  	int rval;
  	FILE *fd;
--- 555,561 ----
  }
  
  void
! pass(const char *passwd)
  {
  	int rval;
  	FILE *fd;
***************
*** 659,665 ****
  		reply(550, "Can't set gid.");
  		return;
  	}
! 	(void) initgroups(pw->pw_name, pw->pw_gid);
  
  	/* open wtmp before chroot */
  	logwtmp(ttyline, pw->pw_name, remotehost);
--- 645,651 ----
  		reply(550, "Can't set gid.");
  		return;
  	}
! 	initgroups(pw->pw_name, pw->pw_gid);
  
  	/* open wtmp before chroot */
  	logwtmp(ttyline, pw->pw_name, remotehost);
***************
*** 705,712 ****
  				*cp = '\0';
  			lreply(230, "%s", line);
  		}
! 		(void) fflush(stdout);
! 		(void) fclose(fd);
  	}
  	if (guest) {
  		reply(230, "Guest login ok, access restrictions apply.");
--- 691,698 ----
  				*cp = '\0';
  			lreply(230, "%s", line);
  		}
! 		fflush(stdout);
! 		fclose(fd);
  	}
  	if (guest) {
  		reply(230, "Guest login ok, access restrictions apply.");
***************
*** 733,742 ****
  	}
  #ifndef INSECURE_GUEST
  	if (guest) 
! 	    (void) umask(GUEST_CMASK);
  	else
  #endif
! 	    (void) umask(defumask);
  	return;
  bad:
  	/* Forget all about it... */
--- 719,728 ----
  	}
  #ifndef INSECURE_GUEST
  	if (guest) 
! 	    umask(GUEST_CMASK);
  	else
  #endif
! 	    umask(defumask);
  	return;
  bad:
  	/* Forget all about it... */
***************
*** 744,751 ****
  }
  
  void
! retrieve(cmd, name)
! 	char *cmd, *name;
  {
  	FILE *fin, *dout;
  	struct stat st;
--- 730,736 ----
  }
  
  void
! retrieve(const char *cmd, const char *name)
  {
  	FILE *fin, *dout;
  	struct stat st;
***************
*** 757,763 ****
  	} else {
  		char line[BUFSIZ];
  
! 		(void) sprintf(line, cmd, name), name = line;
  		fin = ftpd_popen(line, "r"), closefunc = ftpd_pclose;
  		st.st_size = -1;
  		st.st_blksize = BUFSIZ;
--- 742,748 ----
  	} else {
  		char line[BUFSIZ];
  
! 		sprintf(line, cmd, name), name = line;
  		fin = ftpd_popen(line, "r"), closefunc = ftpd_pclose;
  		st.st_size = -1;
  		st.st_blksize = BUFSIZ;
***************
*** 800,806 ****
  	if (dout == NULL)
  		goto done;
  	send_data(fin, dout, st.st_blksize);
! 	(void) fclose(dout);
  	data = -1;
  	pdata = -1;
  done:
--- 785,791 ----
  	if (dout == NULL)
  		goto done;
  	send_data(fin, dout, st.st_blksize);
! 	fclose(dout);
  	data = -1;
  	pdata = -1;
  done:
***************
*** 810,818 ****
  }
  
  void
! store(name, mode, unique)
! 	char *name, *mode;
! 	int unique;
  {
  	FILE *fout, *din;
  	struct stat st;
--- 795,801 ----
  }
  
  void
! store(const char *name, const char *mode, int unique)
  {
  	FILE *fout, *din;
  	struct stat st;
***************
*** 873,879 ****
  		else
  			reply(226, "Transfer complete.");
  	}
! 	(void) fclose(din);
  	data = -1;
  	pdata = -1;
  done:
--- 856,862 ----
  		else
  			reply(226, "Transfer complete.");
  	}
! 	fclose(din);
  	data = -1;
  	pdata = -1;
  done:
***************
*** 882,895 ****
  }
  
  static FILE *
! getdatasock(mode)
! 	char *mode;
  {
  	int on = 1, s, t, tries;
  
  	if (data >= 0)
  		return (fdopen(data, mode));
! 	(void) seteuid((uid_t)0);
  	s = socket(AF_INET, SOCK_STREAM, 0);
  	if (s < 0)
  		goto bad;
--- 865,877 ----
  }
  
  static FILE *
! getdatasock(const char *mode)
  {
  	int on = 1, s, t, tries;
  
  	if (data >= 0)
  		return (fdopen(data, mode));
! 	seteuid((uid_t)0);
  	s = socket(AF_INET, SOCK_STREAM, 0);
  	if (s < 0)
  		goto bad;
***************
*** 908,914 ****
  			goto bad;
  		sleep(tries);
  	}
! 	(void) seteuid((uid_t)pw->pw_uid);
  #ifdef IP_TOS
  	on = IPTOS_THROUGHPUT;
  	if (setsockopt(s, IPPROTO_IP, IP_TOS, (char *)&on, sizeof(int)) < 0)
--- 890,896 ----
  			goto bad;
  		sleep(tries);
  	}
! 	seteuid((uid_t)pw->pw_uid);
  #ifdef IP_TOS
  	on = IPTOS_THROUGHPUT;
  	if (setsockopt(s, IPPROTO_IP, IP_TOS, (char *)&on, sizeof(int)) < 0)
***************
*** 918,934 ****
  bad:
  	/* Return the real value of errno (close may change it) */
  	t = errno;
! 	(void) seteuid((uid_t)pw->pw_uid);
! 	(void) close(s);
  	errno = t;
  	return (NULL);
  }
  
  static FILE *
! dataconn(name, size, mode)
! 	char *name;
! 	off_t size;
! 	char *mode;
  {
  	char sizebuf[32];
  	FILE *file;
--- 900,913 ----
  bad:
  	/* Return the real value of errno (close may change it) */
  	t = errno;
! 	seteuid((uid_t)pw->pw_uid);
! 	close(s);
  	errno = t;
  	return (NULL);
  }
  
  static FILE *
! dataconn(const char *name, off_t size, const char *mode)
  {
  	char sizebuf[32];
  	FILE *file;
***************
*** 937,945 ****
  	file_size = size;
  	byte_count = 0;
  	if (size != (off_t) -1)
! 		(void) sprintf(sizebuf, " (%qd bytes)", size);
  	else
! 		(void) strcpy(sizebuf, "");
  	if (pdata >= 0) {
  		struct sockaddr_in from;
  		int s, fromlen = sizeof(from);
--- 916,924 ----
  	file_size = size;
  	byte_count = 0;
  	if (size != (off_t) -1)
! 		sprintf(sizebuf, " (%qd bytes)", size);
  	else
! 		strcpy(sizebuf, "");
  	if (pdata >= 0) {
  		struct sockaddr_in from;
  		int s, fromlen = sizeof(from);
***************
*** 947,961 ****
  		s = accept(pdata, (struct sockaddr *)&from, &fromlen);
  		if (s < 0) {
  			reply(425, "Can't open data connection.");
! 			(void) close(pdata);
  			pdata = -1;
  			return (NULL);
  		}
! 		(void) close(pdata);
  		pdata = s;
  #ifdef IP_TOS
  		tos = IPTOS_THROUGHPUT;
! 		(void) setsockopt(s, IPPROTO_IP, IP_TOS, (char *)&tos,
  		    sizeof(int));
  #endif
  		reply(150, "Opening %s mode data connection for '%s'%s.",
--- 926,940 ----
  		s = accept(pdata, (struct sockaddr *)&from, &fromlen);
  		if (s < 0) {
  			reply(425, "Can't open data connection.");
! 			close(pdata);
  			pdata = -1;
  			return (NULL);
  		}
! 		close(pdata);
  		pdata = s;
  #ifdef IP_TOS
  		tos = IPTOS_THROUGHPUT;
! 		setsockopt(s, IPPROTO_IP, IP_TOS, (char *)&tos,
  		    sizeof(int));
  #endif
  		reply(150, "Opening %s mode data connection for '%s'%s.",
***************
*** 987,993 ****
  			continue;
  		}
  		perror_reply(425, "Can't build data connection");
! 		(void) fclose(file);
  		data = -1;
  		return (NULL);
  	}
--- 966,972 ----
  			continue;
  		}
  		perror_reply(425, "Can't build data connection");
! 		fclose(file);
  		data = -1;
  		return (NULL);
  	}
***************
*** 1003,1011 ****
   * NB: Form isn't handled.
   */
  static void
! send_data(instr, outstr, blksize)
! 	FILE *instr, *outstr;
! 	off_t blksize;
  {
  	int c, cnt, filefd, netfd;
  	char *buf;
--- 982,988 ----
   * NB: Form isn't handled.
   */
  static void
! send_data(FILE *instr, FILE *outstr, off_t blksize)
  {
  	int c, cnt, filefd, netfd;
  	char *buf;
***************
*** 1023,1031 ****
  			if (c == '\n') {
  				if (ferror(outstr))
  					goto data_err;
! 				(void) putc('\r', outstr);
  			}
! 			(void) putc(c, outstr);
  		}
  		fflush(outstr);
  		transflag = 0;
--- 1000,1008 ----
  			if (c == '\n') {
  				if (ferror(outstr))
  					goto data_err;
! 				putc('\r', outstr);
  			}
! 			putc(c, outstr);
  		}
  		fflush(outstr);
  		transflag = 0;
***************
*** 1049,1055 ****
  		    write(netfd, buf, cnt) == cnt)
  			byte_count += cnt;
  		transflag = 0;
! 		(void)free(buf);
  		if (cnt != 0) {
  			if (cnt < 0)
  				goto file_err;
--- 1026,1032 ----
  		    write(netfd, buf, cnt) == cnt)
  			byte_count += cnt;
  		transflag = 0;
! 		free(buf);
  		if (cnt != 0) {
  			if (cnt < 0)
  				goto file_err;
***************
*** 1080,1087 ****
   * N.B.: Form isn't handled.
   */
  static int
! receive_data(instr, outstr)
! 	FILE *instr, *outstr;
  {
  	int c;
  	int cnt, bare_lfs = 0;
--- 1057,1063 ----
   * N.B.: Form isn't handled.
   */
  static int
! receive_data(FILE *instr, FILE *outstr)
  {
  	int c;
  	int cnt, bare_lfs = 0;
***************
*** 1120,1131 ****
  				if (ferror(outstr))
  					goto data_err;
  				if ((c = getc(instr)) != '\n') {
! 					(void) putc ('\r', outstr);
  					if (c == '\0' || c == EOF)
  						goto contin2;
  				}
  			}
! 			(void) putc(c, outstr);
  	contin2:	;
  		}
  		fflush(outstr);
--- 1096,1107 ----
  				if (ferror(outstr))
  					goto data_err;
  				if ((c = getc(instr)) != '\n') {
! 					putc ('\r', outstr);
  					if (c == '\0' || c == EOF)
  						goto contin2;
  				}
  			}
! 			putc(c, outstr);
  	contin2:	;
  		}
  		fflush(outstr);
***************
*** 1138,1144 ****
  			lreply(226,
  		"WARNING! %d bare linefeeds received in ASCII mode",
  			    bare_lfs);
! 		(void)printf("   File may not have transferred correctly.\r\n");
  		}
  		return (0);
  	default:
--- 1114,1120 ----
  			lreply(226,
  		"WARNING! %d bare linefeeds received in ASCII mode",
  			    bare_lfs);
! 		printf("   File may not have transferred correctly.\r\n");
  		}
  		return (0);
  	default:
***************
*** 1159,1197 ****
  }
  
  void
! statfilecmd(filename)
! 	char *filename;
  {
  	FILE *fin;
  	int c;
  	char line[LINE_MAX];
  
! 	(void)snprintf(line, sizeof(line), "/bin/ls -lgA %s", filename);
  	fin = ftpd_popen(line, "r");
  	lreply(211, "status of %s:", filename);
  	while ((c = getc(fin)) != EOF) {
  		if (c == '\n') {
  			if (ferror(stdout)){
  				perror_reply(421, "control connection");
! 				(void) ftpd_pclose(fin);
  				dologout(1);
  				/* NOTREACHED */
  			}
  			if (ferror(fin)) {
  				perror_reply(551, filename);
! 				(void) ftpd_pclose(fin);
  				return;
  			}
! 			(void) putc('\r', stdout);
  		}
! 		(void) putc(c, stdout);
  	}
! 	(void) ftpd_pclose(fin);
  	reply(211, "End of Status");
  }
  
  void
! statcmd()
  {
  	struct sockaddr_in *sin;
  	u_char *a, *p;
--- 1135,1172 ----
  }
  
  void
! statfilecmd(const char *filename)
  {
  	FILE *fin;
  	int c;
  	char line[LINE_MAX];
  
! 	snprintf(line, sizeof(line), "/bin/ls -lgA %s", filename);
  	fin = ftpd_popen(line, "r");
  	lreply(211, "status of %s:", filename);
  	while ((c = getc(fin)) != EOF) {
  		if (c == '\n') {
  			if (ferror(stdout)){
  				perror_reply(421, "control connection");
! 				ftpd_pclose(fin);
  				dologout(1);
  				/* NOTREACHED */
  			}
  			if (ferror(fin)) {
  				perror_reply(551, filename);
! 				ftpd_pclose(fin);
  				return;
  			}
! 			putc('\r', stdout);
  		}
! 		putc(c, stdout);
  	}
! 	ftpd_pclose(fin);
  	reply(211, "End of Status");
  }
  
  void
! statcmd(void)
  {
  	struct sockaddr_in *sin;
  	u_char *a, *p;
***************
*** 1255,1279 ****
  }
  
  void
- #if __STDC__
  reply(int n, const char *fmt, ...)
- #else
- reply(n, fmt, va_alist)
- 	int n;
- 	char *fmt;
-         va_dcl
- #endif
  {
  	va_list ap;
- #if __STDC__
  	va_start(ap, fmt);
! #else
! 	va_start(ap);
! #endif
! 	(void)printf("%d ", n);
! 	(void)vprintf(fmt, ap);
! 	(void)printf("\r\n");
! 	(void)fflush(stdout);
  	if (debug) {
  		syslog(LOG_DEBUG, "<--- %d ", n);
  		vsyslog(LOG_DEBUG, fmt, ap);
--- 1230,1243 ----
  }
  
  void
  reply(int n, const char *fmt, ...)
  {
  	va_list ap;
  	va_start(ap, fmt);
! 	printf("%d ", n);
! 	vprintf(fmt, ap);
! 	printf("\r\n");
! 	fflush(stdout);
  	if (debug) {
  		syslog(LOG_DEBUG, "<--- %d ", n);
  		vsyslog(LOG_DEBUG, fmt, ap);
***************
*** 1281,1305 ****
  }
  
  void
- #if __STDC__
  lreply(int n, const char *fmt, ...)
- #else
- lreply(n, fmt, va_alist)
- 	int n;
- 	char *fmt;
-         va_dcl
- #endif
  {
  	va_list ap;
- #if __STDC__
  	va_start(ap, fmt);
! #else
! 	va_start(ap);
! #endif
! 	(void)printf("%d- ", n);
! 	(void)vprintf(fmt, ap);
! 	(void)printf("\r\n");
! 	(void)fflush(stdout);
  	if (debug) {
  		syslog(LOG_DEBUG, "<--- %d- ", n);
  		vsyslog(LOG_DEBUG, fmt, ap);
--- 1245,1258 ----
  }
  
  void
  lreply(int n, const char *fmt, ...)
  {
  	va_list ap;
  	va_start(ap, fmt);
! 	printf("%d- ", n);
! 	vprintf(fmt, ap);
! 	printf("\r\n");
! 	fflush(stdout);
  	if (debug) {
  		syslog(LOG_DEBUG, "<--- %d- ", n);
  		vsyslog(LOG_DEBUG, fmt, ap);
***************
*** 1307,1331 ****
  }
  
  static void
! ack(s)
! 	char *s;
  {
- 
  	reply(250, "%s command successful.", s);
  }
  
  void
! nack(s)
! 	char *s;
  {
- 
  	reply(502, "%s command not implemented.", s);
  }
  
  /* ARGSUSED */
  void
! yyerror(s)
! 	char *s;
  {
  	char *cp;
  
--- 1260,1279 ----
  }
  
  static void
! ack(const char *s)
  {
  	reply(250, "%s command successful.", s);
  }
  
  void
! nack(const char *s)
  {
  	reply(502, "%s command not implemented.", s);
  }
  
  /* ARGSUSED */
  void
! yyerror(const char *s)
  {
  	char *cp;
  
***************
*** 1335,1342 ****
  }
  
  void
! delete(name)
! 	char *name;
  {
  	struct stat st;
  
--- 1283,1289 ----
  }
  
  void
! delete(const char *name)
  {
  	struct stat st;
  
***************
*** 1361,1370 ****
  }
  
  void
! cwd(path)
! 	char *path;
  {
- 
  	if (chdir(path) < 0)
  		perror_reply(550, path);
  	else
--- 1308,1315 ----
  }
  
  void
! cwd(const char *path)
  {
  	if (chdir(path) < 0)
  		perror_reply(550, path);
  	else
***************
*** 1372,1381 ****
  }
  
  void
! makedir(name)
! 	char *name;
  {
- 
  	LOGCMD("mkdir", name);
  	if (mkdir(name, 0777) < 0)
  		perror_reply(550, name);
--- 1317,1324 ----
  }
  
  void
! makedir(const char *name)
  {
  	LOGCMD("mkdir", name);
  	if (mkdir(name, 0777) < 0)
  		perror_reply(550, name);
***************
*** 1384,1393 ****
  }
  
  void
! removedir(name)
! 	char *name;
  {
- 
  	LOGCMD("rmdir", name);
  	if (rmdir(name) < 0)
  		perror_reply(550, name);
--- 1327,1334 ----
  }
  
  void
! removedir(const char *name)
  {
  	LOGCMD("rmdir", name);
  	if (rmdir(name) < 0)
  		perror_reply(550, name);
***************
*** 1396,1430 ****
  }
  
  void
! pwd()
  {
  	char path[MAXPATHLEN + 1];
  
! 	if (getwd(path) == (char *)NULL)
  		reply(550, "%s.", path);
  	else
  		reply(257, "\"%s\" is current directory.", path);
  }
  
  char *
! renamefrom(name)
! 	char *name;
  {
  	struct stat st;
  
  	if (stat(name, &st) < 0) {
  		perror_reply(550, name);
! 		return ((char *)0);
  	}
  	reply(350, "File exists, ready for destination name");
  	return (name);
  }
  
  void
! renamecmd(from, to)
! 	char *from, *to;
  {
- 
  	LOGCMD2("rename", from, to);
  	if (rename(from, to) < 0)
  		perror_reply(550, "rename");
--- 1337,1368 ----
  }
  
  void
! pwd(void)
  {
  	char path[MAXPATHLEN + 1];
  
! 	if (getwd(path) == NULL)
  		reply(550, "%s.", path);
  	else
  		reply(257, "\"%s\" is current directory.", path);
  }
  
  char *
! renamefrom(char *name)
  {
  	struct stat st;
  
  	if (stat(name, &st) < 0) {
  		perror_reply(550, name);
! 		return NULL;
  	}
  	reply(350, "File exists, ready for destination name");
  	return (name);
  }
  
  void
! renamecmd(const char *from, const char *to)
  {
  	LOGCMD2("rename", from, to);
  	if (rename(from, to) < 0)
  		perror_reply(550, "rename");
***************
*** 1433,1448 ****
  }
  
  static void
! dolog(sin)
! 	struct sockaddr_in *sin;
  {
  	struct hostent *hp = gethostbyaddr((char *)&sin->sin_addr,
  		sizeof(struct in_addr), AF_INET);
  
  	if (hp)
! 		(void) strncpy(remotehost, hp->h_name, sizeof(remotehost));
  	else
! 		(void) strncpy(remotehost, inet_ntoa(sin->sin_addr),
  		    sizeof(remotehost));
  #ifdef HASSETPROCTITLE
  	snprintf(proctitle, sizeof(proctitle), "%s: connected", remotehost);
--- 1371,1385 ----
  }
  
  static void
! dolog(struct sockaddr_in *sin)
  {
  	struct hostent *hp = gethostbyaddr((char *)&sin->sin_addr,
  		sizeof(struct in_addr), AF_INET);
  
  	if (hp)
! 		strncpy(remotehost, hp->h_name, sizeof(remotehost));
  	else
! 		strncpy(remotehost, inet_ntoa(sin->sin_addr),
  		    sizeof(remotehost));
  #ifdef HASSETPROCTITLE
  	snprintf(proctitle, sizeof(proctitle), "%s: connected", remotehost);
***************
*** 1458,1465 ****
   * and exit with supplied status.
   */
  void
! dologout(status)
! 	int status;
  {
  	/*
  	* Prevent reception of SIGURG from resulting in a resumption
--- 1395,1401 ----
   * and exit with supplied status.
   */
  void
! dologout(int status)
  {
  	/*
  	* Prevent reception of SIGURG from resulting in a resumption
***************
*** 1468,1474 ****
  	transflag = 0;
  
  	if (logged_in) {
! 		(void) seteuid((uid_t)0);
  		logwtmp(ttyline, "", "");
  #if defined(KERBEROS)
  		if (!notickets && krbtkfile_env)
--- 1404,1410 ----
  	transflag = 0;
  
  	if (logged_in) {
! 		seteuid((uid_t)0);
  		logwtmp(ttyline, "", "");
  #if defined(KERBEROS)
  		if (!notickets && krbtkfile_env)
***************
*** 1480,1487 ****
  }
  
  static void
! myoob(signo)
! 	int signo;
  {
  	char *cp;
  
--- 1416,1422 ----
  }
  
  static void
! myoob(int signo)
  {
  	char *cp;
  
***************
*** 1516,1522 ****
   *	with Rick Adams on 25 Jan 89.
   */
  void
! passive()
  {
  	int len;
  	char *p, *a;
--- 1451,1457 ----
   *	with Rick Adams on 25 Jan 89.
   */
  void
! passive(void)
  {
  	int len;
  	char *p, *a;
***************
*** 1528,1539 ****
  	}
  	pasv_addr = ctrl_addr;
  	pasv_addr.sin_port = 0;
! 	(void) seteuid((uid_t)0);
  	if (bind(pdata, (struct sockaddr *)&pasv_addr, sizeof(pasv_addr)) < 0) {
! 		(void) seteuid((uid_t)pw->pw_uid);
  		goto pasv_error;
  	}
! 	(void) seteuid((uid_t)pw->pw_uid);
  	len = sizeof(pasv_addr);
  	if (getsockname(pdata, (struct sockaddr *) &pasv_addr, &len) < 0)
  		goto pasv_error;
--- 1463,1474 ----
  	}
  	pasv_addr = ctrl_addr;
  	pasv_addr.sin_port = 0;
! 	seteuid((uid_t)0);
  	if (bind(pdata, (struct sockaddr *)&pasv_addr, sizeof(pasv_addr)) < 0) {
! 		seteuid((uid_t)pw->pw_uid);
  		goto pasv_error;
  	}
! 	seteuid((uid_t)pw->pw_uid);
  	len = sizeof(pasv_addr);
  	if (getsockname(pdata, (struct sockaddr *) &pasv_addr, &len) < 0)
  		goto pasv_error;
***************
*** 1549,1555 ****
  	return;
  
  pasv_error:
! 	(void) close(pdata);
  	pdata = -1;
  	perror_reply(425, "Can't open passive connection");
  	return;
--- 1484,1490 ----
  	return;
  
  pasv_error:
! 	close(pdata);
  	pdata = -1;
  	perror_reply(425, "Can't open passive connection");
  	return;
***************
*** 1561,1568 ****
   * Generates failure reply on error.
   */
  static char *
! gunique(local)
! 	char *local;
  {
  	static char new[MAXPATHLEN];
  	struct stat st;
--- 1496,1502 ----
   * Generates failure reply on error.
   */
  static char *
! gunique(const char *local)
  {
  	static char new[MAXPATHLEN];
  	struct stat st;
***************
*** 1578,1588 ****
  	}
  	if (cp)
  		*cp = '/';
! 	(void) strcpy(new, local);
  	cp = new + strlen(new);
  	*cp++ = '.';
  	for (count = 1; count < 100; count++) {
! 		(void)sprintf(cp, "%d", count);
  		if (stat(new, &st) < 0)
  			return (new);
  	}
--- 1512,1522 ----
  	}
  	if (cp)
  		*cp = '/';
! 	strcpy(new, local);
  	cp = new + strlen(new);
  	*cp++ = '.';
  	for (count = 1; count < 100; count++) {
! 		sprintf(cp, "%d", count);
  		if (stat(new, &st) < 0)
  			return (new);
  	}
***************
*** 1594,1621 ****
   * Format and send reply containing system error number.
   */
  void
! perror_reply(code, string)
! 	int code;
! 	char *string;
  {
- 
  	reply(code, "%s: %s.", string, strerror(errno));
  }
  
! static char *onefile[] = {
  	"",
  	0
  };
  
  void
! send_file_list(whichf)
! 	char *whichf;
  {
  	struct stat st;
  	DIR *dirp = NULL;
  	struct dirent *dir;
  	FILE *dout = NULL;
! 	char **dirlist, *dirname;
  	int simple = 0;
  	int freeglob = 0;
  	glob_t gl;
--- 1528,1552 ----
   * Format and send reply containing system error number.
   */
  void
! perror_reply(int code, const char *string)
  {
  	reply(code, "%s: %s.", string, strerror(errno));
  }
  
! static const char *onefile[] = {
  	"",
  	0
  };
  
  void
! send_file_list(const char *whichf)
  {
  	struct stat st;
  	DIR *dirp = NULL;
  	struct dirent *dir;
  	FILE *dout = NULL;
! 	const char * const *dirlist;
! 	const char *dirname;
  	int simple = 0;
  	int freeglob = 0;
  	glob_t gl;
***************
*** 1633,1639 ****
  			perror_reply(550, whichf);
  			goto out;
  		}
! 		dirlist = gl.gl_pathv;
  	} else {
  		onefile[0] = whichf;
  		dirlist = onefile;
--- 1564,1570 ----
  			perror_reply(550, whichf);
  			goto out;
  		}
! 		dirlist = (const char * const * )gl.gl_pathv;
  	} else {
  		onefile[0] = whichf;
  		dirlist = onefile;
***************
*** 1657,1663 ****
  			}
  			perror_reply(550, whichf);
  			if (dout != NULL) {
! 				(void) fclose(dout);
  				transflag = 0;
  				data = -1;
  				pdata = -1;
--- 1588,1594 ----
  			}
  			perror_reply(550, whichf);
  			if (dout != NULL) {
! 				fclose(dout);
  				transflag = 0;
  				data = -1;
  				pdata = -1;
***************
*** 1715,1721 ****
  				byte_count += strlen(nbuf) + 1;
  			}
  		}
! 		(void) closedir(dirp);
  	}
  
  	if (dout == NULL)
--- 1646,1652 ----
  				byte_count += strlen(nbuf) + 1;
  			}
  		}
! 		closedir(dirp);
  	}
  
  	if (dout == NULL)
***************
*** 1727,1733 ****
  
  	transflag = 0;
  	if (dout != NULL)
! 		(void) fclose(dout);
  	data = -1;
  	pdata = -1;
  out:
--- 1658,1664 ----
  
  	transflag = 0;
  	if (dout != NULL)
! 		fclose(dout);
  	data = -1;
  	pdata = -1;
  out:
*** ../src.original/./libexec/ftpd/logwtmp.c	Sat May 17 15:35:43 1997
--- ./libexec/ftpd/logwtmp.c	Sat May 17 15:55:54 1997
***************
*** 61,68 ****
   * after login, but before logout).
   */
  void
! logwtmp(line, name, host)
! 	char *line, *name, *host;
  {
  	struct utmp ut;
  	struct stat buf;
--- 61,67 ----
   * after login, but before logout).
   */
  void
! logwtmp(const char *line, const char *name, const char *host)
  {
  	struct utmp ut;
  	struct stat buf;
***************
*** 70,81 ****
  	if (fd < 0 && (fd = open(_PATH_WTMP, O_WRONLY|O_APPEND, 0)) < 0)
  		return;
  	if (fstat(fd, &buf) == 0) {
! 		(void)strncpy(ut.ut_line, line, sizeof(ut.ut_line));
! 		(void)strncpy(ut.ut_name, name, sizeof(ut.ut_name));
! 		(void)strncpy(ut.ut_host, host, sizeof(ut.ut_host));
! 		(void)time(&ut.ut_time);
  		if (write(fd, (char *)&ut, sizeof(struct utmp)) !=
  		    sizeof(struct utmp))
! 			(void)ftruncate(fd, buf.st_size);
  	}
  }
--- 69,80 ----
  	if (fd < 0 && (fd = open(_PATH_WTMP, O_WRONLY|O_APPEND, 0)) < 0)
  		return;
  	if (fstat(fd, &buf) == 0) {
! 		strncpy(ut.ut_line, line, sizeof(ut.ut_line));
! 		strncpy(ut.ut_name, name, sizeof(ut.ut_name));
! 		strncpy(ut.ut_host, host, sizeof(ut.ut_host));
! 		time(&ut.ut_time);
  		if (write(fd, (char *)&ut, sizeof(struct utmp)) !=
  		    sizeof(struct utmp))
! 			ftruncate(fd, buf.st_size);
  	}
  }
*** ../src.original/./libexec/ftpd/popen.c	Sat May 17 15:40:26 1997
--- ./libexec/ftpd/popen.c	Sat May 17 15:46:13 1997
***************
*** 67,74 ****
  static int fds;
  
  FILE *
! ftpd_popen(program, type)
! 	char *program, *type;
  {
  	char *cp;
  	FILE *iop;
--- 67,73 ----
  static int fds;
  
  FILE *
! ftpd_popen(char *program, const char *type)
  {
  	char *cp;
  	FILE *iop;
***************
*** 112,135 ****
  	iop = NULL;
  	switch(pid = vfork()) {
  	case -1:			/* error */
! 		(void)close(pdes[0]);
! 		(void)close(pdes[1]);
  		goto pfree;
  		/* NOTREACHED */
  	case 0:				/* child */
  		if (*type == 'r') {
  			if (pdes[1] != STDOUT_FILENO) {
  				dup2(pdes[1], STDOUT_FILENO);
! 				(void)close(pdes[1]);
  			}
  			dup2(STDOUT_FILENO, STDERR_FILENO); /* stderr too! */
! 			(void)close(pdes[0]);
  		} else {
  			if (pdes[0] != STDIN_FILENO) {
  				dup2(pdes[0], STDIN_FILENO);
! 				(void)close(pdes[0]);
  			}
! 			(void)close(pdes[1]);
  		}
  		execv(gargv[0], gargv);
  		_exit(1);
--- 111,134 ----
  	iop = NULL;
  	switch(pid = vfork()) {
  	case -1:			/* error */
! 		close(pdes[0]);
! 		close(pdes[1]);
  		goto pfree;
  		/* NOTREACHED */
  	case 0:				/* child */
  		if (*type == 'r') {
  			if (pdes[1] != STDOUT_FILENO) {
  				dup2(pdes[1], STDOUT_FILENO);
! 				close(pdes[1]);
  			}
  			dup2(STDOUT_FILENO, STDERR_FILENO); /* stderr too! */
! 			close(pdes[0]);
  		} else {
  			if (pdes[0] != STDIN_FILENO) {
  				dup2(pdes[0], STDIN_FILENO);
! 				close(pdes[0]);
  			}
! 			close(pdes[1]);
  		}
  		execv(gargv[0], gargv);
  		_exit(1);
***************
*** 137,146 ****
  	/* parent; assume fdopen can't fail...  */
  	if (*type == 'r') {
  		iop = fdopen(pdes[0], type);
! 		(void)close(pdes[1]);
  	} else {
  		iop = fdopen(pdes[1], type);
! 		(void)close(pdes[0]);
  	}
  	pids[fileno(iop)] = pid;
  
--- 136,145 ----
  	/* parent; assume fdopen can't fail...  */
  	if (*type == 'r') {
  		iop = fdopen(pdes[0], type);
! 		close(pdes[1]);
  	} else {
  		iop = fdopen(pdes[1], type);
! 		close(pdes[0]);
  	}
  	pids[fileno(iop)] = pid;
  
***************
*** 151,158 ****
  }
  
  int
! ftpd_pclose(iop)
! 	FILE *iop;
  {
  	int fdes, status;
  	pid_t pid;
--- 150,156 ----
  }
  
  int
! ftpd_pclose(FILE *iop)
  {
  	int fdes, status;
  	pid_t pid;
***************
*** 164,170 ****
  	 */
  	if (pids == 0 || pids[fdes = fileno(iop)] == 0)
  		return (-1);
! 	(void)fclose(iop);
  	sigemptyset(&sigset);
  	sigaddset(&sigset, SIGINT);
  	sigaddset(&sigset, SIGQUIT);
--- 162,168 ----
  	 */
  	if (pids == 0 || pids[fdes = fileno(iop)] == 0)
  		return (-1);
! 	fclose(iop);
  	sigemptyset(&sigset);
  	sigaddset(&sigset, SIGINT);
  	sigaddset(&sigset, SIGQUIT);
>Audit-Trail:
>Unformatted: