Subject: misc/1040: Feature addition to ftpd
To: None <gnats-admin@sun-lamp.cs.berkeley.edu>
From: Leslie Todd Masco <cactus@hks.net>
List: netbsd-bugs
Date: 05/11/1995 02:35:05
>Number:         1040
>Category:       misc
>Synopsis:       Feature addition to ftpd
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    misc-bug-people (Misc Bug People)
>State:          open
>Class:          change-request
>Submitter-Id:   net
>Arrival-Date:   Thu May 11 02:35:03 1995
>Originator:     Leslie Todd Masco
>Organization:
	HKS, Inc.
>Release:        May 12, 1995
>Environment:
	All
System: NetBSD zyro.herd.hks.net 1.0A NetBSD 1.0A (HERD) #1: Mon May 1 19:19:44 EDT 1995 root@zyro.herd.hks.net:/export/netbsd/sup/allsrc/src/sys/arch/pmax/compile/HERD pmax


>Description:
	Feature to mimck wu-ftpd's printing of .message files and notification
	of README* files and the interval since modification of same.
>How-To-Repeat:
	n/a
>Fix:
	
*** ftpd.c.orig	Thu May 11 01:03:22 1995
--- ftpd.c	Thu May 11 02:08:49 1995
***************
*** 82,87 ****
--- 82,88 ----
  #include <syslog.h>
  #include <time.h>
  #include <unistd.h>
+ #include <tzfile.h>
  
  #include "pathnames.h"
  #include "extern.h"
***************
*** 92,98 ****
  #include <varargs.h>
  #endif
  
! static char version[] = "Version 6.00";
  
  extern	off_t restart_point;
  extern	char cbuf[];
--- 93,99 ----
  #include <varargs.h>
  #endif
  
! static char version[] = "Version 6.01";
  
  extern	off_t restart_point;
  extern	char cbuf[];
***************
*** 187,192 ****
--- 188,194 ----
  static struct passwd *
  		 sgetpwnam __P((char *));
  static char	*sgetsave __P((char *));
+ static void    checkftpdir __P((int));
  
  static char *
  curdir()
***************
*** 643,648 ****
--- 645,651 ----
  		(void) fclose(fd);
  	}
  	if (guest) {
+ 	        checkftpdir(230);
  		reply(230, "Guest login ok, access restrictions apply.");
  #ifdef HASSETPROCTITLE
  		snprintf(proctitle, sizeof(proctitle),
***************
*** 655,660 ****
--- 658,664 ----
  			syslog(LOG_INFO, "ANONYMOUS FTP LOGIN FROM %s, %s",
  			    remotehost, passwd);
  	} else {
+                 checkftpdir(230);
  		reply(230, "User %s logged in.", pw->pw_name);
  #ifdef HASSETPROCTITLE
  		snprintf(proctitle, sizeof(proctitle),
***************
*** 1292,1302 ****
  cwd(path)
  	char *path;
  {
! 
! 	if (chdir(path) < 0)
! 		perror_reply(550, path);
! 	else
! 		ack("CWD");
  }
  
  void
--- 1296,1361 ----
  cwd(path)
  	char *path;
  {
!   if (chdir(path) < 0)
!     perror_reply(550, path);
!   else {
!     checkftpdir(250);
!     ack("CWD");
!   }
! }
! 
! void checkftpdir(protocol_code)
! int protocol_code;
! {
!   FILE *fd;
!   DIR *dd;
!   char line[LINE_MAX], date[LINE_MAX], *cp;
!   struct dirent *de;
!   struct stat sb;
!   time_t now, interval;
! 
!   if ((fd = fopen(".message", "r")) != NULL) {
!     while (fgets(line, sizeof(line), fd) != NULL) {
!       if ((cp = strchr(line, '\n')) != NULL)
! 	*cp = '\0';
!       lreply(protocol_code, "%s", line);
!     }
!     lreply(protocol_code, "%s", "");
!     (void) fflush(stdout);
!     (void) fclose(fd);
!     /* reply(protocol_code,) is done in ack("CWD") */
!   }
!   
!   /* Find each file beginning with "README" and notify the user of its
!      existence and mtime. */
!   
!   if ((dd = opendir(".")) != NULL) {
!     while ((de = readdir(dd)) != NULL) {
!       if ((de->d_namlen > 4) && (strncmp(de->d_name, "README",6) == NULL)) {
! 	sprintf(line,"Please read the file %s",de->d_name);
! 	lreply(protocol_code, "%s", line);
! 
! 	if (stat(de->d_name,&sb) == 0) {
! 	  sprintf(date,"%s", ctime((time_t *)&(sb.st_mtimespec.ts_sec)));
! 
! 	  /* Cut off final \n from ctime() */
! 
! 	  date[strlen(date)-1] = '\0';
! 	  sprintf(line,"  it was last modified on %s ",date);
! 	  if (time(&now) != ((time_t) -1)) {
! 	    interval = now - sb.st_mtimespec.ts_sec;
! 	    if (interval > SECSPERDAY)
! 	      sprintf(date,"- %d days ago", interval / SECSPERDAY);
! 	    else
! 	      sprintf(date,"- within the last day.");
! 	    strcat(line, date);
! 	  }
! 	  lreply(protocol_code, "%s", line);
! 	}
!       }
!     }
!     (void)closedir(dd);
!   }
  }
  
  void

>Audit-Trail:
>Unformatted: