From lmjm@icparc.ic.ac.uk Fri Feb 19 20:21:24 1999 Date: Tue, 16 Feb 1999 22:12:07 +0000 From: Lee McLoughlin To: lundberg+wuftpd@vr.net Subject: patch?? I've a couple of patches to wu-ftpd that you might find interesting. diff -cbrw orig/wu-ftpd-2.4.2-beta-18-vr14/config.h wu-ftpd-2.4.2-beta-18-vr14/config.h *** orig/wu-ftpd-2.4.2-beta-18-vr14/config.h Sat Feb 13 22:41:57 1999 --- wu-ftpd-2.4.2-beta-18-vr14/config.h Tue Feb 16 21:09:10 1999 *************** *** 262,264 **** --- 262,287 ---- * compliant, so it may cause problems for some client sites. */ #define FIGHT_PASV_PORT_RACE + + + /* + * PLUS_PW + * Some ftptool type packages are all graphical and don't allow you + * to type commands so you cannot type 'get file' where file + * is really a .Z/.z/.gz file to auto-uncompress. + * A leading + in the passwd causes ls output to have + * any trailing .Z/.z/.gz's stripped to allow these tools to work. + * (All that happens is that the environment variable NODOTZ is set + * and an ls shell script runs the real ls output thru sed.) + */ + + #define PLUS_PW + + /* + * FILEWHAT + * If SETPROCTITLE doesn't work or if you have so many users that ps + * takes a long time then FILEWHAT keeps the info in a file so that + * ftpcount can just print it. + */ + + #define FILEWHAT diff -cbrw orig/wu-ftpd-2.4.2-beta-18-vr14/src/access.c wu-ftpd-2.4.2-beta-18-vr14/src/access.c *** orig/wu-ftpd-2.4.2-beta-18-vr14/src/access.c Thu Jan 28 17:04:59 1999 --- wu-ftpd-2.4.2-beta-18-vr14/src/access.c Tue Feb 16 21:12:34 1999 *************** *** 76,81 **** --- 76,85 ---- static char incline[MAXLINE]; int pidfd = -1; extern int Bypass_PID_Files; + #ifdef FILEWHAT + int whatindex = -1; + extern void whatopen(); + #endif #ifndef HELP_CRACKERS extern char DelayedMessageFile []; *************** *** 1132,1137 **** --- 1136,1145 ---- struct flock arg; #endif + #ifdef FILEWHAT + whatopen( class ); + #endif + if (Bypass_PID_Files) return (0); /* *************** *** 1281,1286 **** --- 1289,1297 ---- } buf[avail] = procid; + #ifdef FILEWHAT + whatindex = avail; + #endif lseek(pidfd, (off_t)0, L_SET); write(pidfd, (void *)buf, sizeof(buf)); diff -cbrw orig/wu-ftpd-2.4.2-beta-18-vr14/src/extensions.h wu-ftpd-2.4.2-beta-18-vr14/src/extensions.h *** orig/wu-ftpd-2.4.2-beta-18-vr14/src/extensions.h Sat Feb 13 22:41:57 1999 --- wu-ftpd-2.4.2-beta-18-vr14/src/extensions.h Tue Feb 16 21:14:33 1999 *************** *** 80,82 **** --- 80,88 ---- #endif #endif /* QUOTA */ + + #ifdef FILEWHAT + #define WHATLEN 80 /* How much of the string to record. + * Need (MAXUSERS * WHATLEN) for the file for each class + */ + #endif diff -cbrw orig/wu-ftpd-2.4.2-beta-18-vr14/src/ftpcount.c wu-ftpd-2.4.2-beta-18-vr14/src/ftpcount.c *** orig/wu-ftpd-2.4.2-beta-18-vr14/src/ftpcount.c Mon Dec 28 17:42:02 1998 --- wu-ftpd-2.4.2-beta-18-vr14/src/ftpcount.c Tue Feb 16 21:17:26 1999 *************** *** 216,221 **** --- 216,227 ---- #ifndef HAVE_FLOCK struct flock arg; #endif + #ifdef FILEWHAT + FILE *what = NULL; + char whatfile[MAXPATHLEN+1]; + char whatstr[WHATLEN+1]; + int dowhat = 1; + #endif sprintf(pidfile, _PATH_PIDNAMES, class); pidfd = open(pidfile, O_RDONLY, 0644); *************** *** 223,228 **** --- 229,242 ---- return (0); } lseek(pidfd, 0, L_SET); + #ifdef FILEWHAT + sprintf(whatfile, _PATH_WHATNAMES, class); + if (!(what = fopen(whatfile, "r"))) { + /* Cannot open whatfile */ + fprintf(stderr, "Cannot open whatfile %s\n", whatfile); + dowhat = 0; + } + #endif count = 0; *************** *** 232,237 **** --- 246,259 ---- stat = kill(buf[which], SIGCONT); if (((stat == -1) && (errno == EPERM)) || !stat) { if (strcmp(progname,"ftpcount")) { + #ifdef FILEWHAT + if (dowhat) { + fseek(what, WHATLEN * which, SEEK_SET); + memset(whatstr, '\0', sizeof(whatstr)); + fread(whatstr, sizeof(char), WHATLEN, what); + printf(" %s\n", whatstr ); + } + #else /* ! FILEWHAT */ #if defined(SVR4) #ifdef AIX sprintf(line,"/bin/ps %d",buf[which]); *************** *** 254,259 **** --- 276,282 ---- fgets(line, 1024, ZeFile); printf("%s",line); pclose(ZeFile); + #endif /* FILEWHAT */ } count++; } *************** *** 266,271 **** --- 289,299 ---- fcntl(pidfd, F_SETLK, &arg); #endif close(pidfd); + + #ifdef FILEWHAT + if( what ) + fclose(what); + #endif return (count); } diff -cbrw orig/wu-ftpd-2.4.2-beta-18-vr14/src/ftpd.c wu-ftpd-2.4.2-beta-18-vr14/src/ftpd.c *** orig/wu-ftpd-2.4.2-beta-18-vr14/src/ftpd.c Sat Feb 13 22:41:58 1999 --- wu-ftpd-2.4.2-beta-18-vr14/src/ftpd.c Tue Feb 16 21:30:00 1999 *************** *** 67,72 **** --- 67,83 ---- #include #endif + #ifdef FILEWHAT + #ifdef HAVE_GETRLIMIT + #include + #include + #endif + #ifdef SVR4 + #include + #include + #endif /* SVR4 */ + #endif /* FILEWHAT */ + #include #include #include *************** *** 2272,2277 **** --- 2283,2295 ---- if (*passwd == '-') dolreplies = 0; + #ifdef PLUS_PW + else if (*passwd == '+') { + dolreplies = 0; + passwd++; + putenv( "NODOTZ=1" ); + } + #endif /* PLUS_PW */ else dolreplies = 1; /* ******** REGULAR/GUEST USER PASSWORD PROCESSING ********** */ *************** *** 5726,5731 **** --- 5744,5766 ---- Argv[1] = 0; # endif # endif /* SPT_TYPE != SPT_NONE */ + #ifdef FILEWHAT + { + register char *p; + register int i; + char buf[WHATLEN]; + VA_LOCAL_DECL + + p = buf; + + /* print the argument string */ + VA_START(fmt); + (void) vsnprintf(buf, sizeof buf, fmt, ap); + VA_END; + + filewhat(buf); + } + #endif /* FILEWHAT */ } #endif /* SPT_TYPE != SPT_BUILTIN */ *************** *** 6021,6023 **** --- 6056,6124 ---- } } #endif /* DAEMON */ + + #ifdef FILEWHAT + extern int whatindex; + int what; + int dontwhat = 0; + + void + whatopen( class ) + char *class; + { + char whatfile[MAXPATHLEN]; + + if (!what) { + sprintf(whatfile, _PATH_WHATNAMES, class); + if (!(what = open(whatfile, O_RDWR|O_CREAT, 0644))) { + /* Cannot open whatfile */ + syslog(LOG_ERR, "Cannot open whatfile %s", whatfile); + dontwhat = 1; + } + } + } + + /* write to the what file */ + filewhat( str ) + char *str; + { + char out[ WHATLEN + 100 ]; /* Add some space for overflows */ + char *cr; + static int pid = -1; + #ifdef SVR4 + static int tps = -1; + struct tms tms; + #else + struct rusage ru; + #endif + unsigned long int usecs = 0, secs = 0; + + if (dontwhat || !what || whatindex < 0) + return; + + if( pid < 0 ) + pid = getpid(); + + #ifdef SVR4 + if( tps < 0 ) + tps = CLK_TCK; + + if( times( &tms ) > 0 ) + secs = (tms.tms_utime + tms.tms_stime + tps/2) / tps; /* Round up */ + #else + if( getrusage( RUSAGE_SELF, &ru ) > 0 ){ + usecs = (ru.ru_utime.tv_usec + ru.ru_stime.tv_usec) + + (ru.ru_utime.tv_sec + ru.ru_stime.tv_sec) * 1000; + secs = (usecs + 500)/1000; /* Round up */ + } + #endif + + sprintf( out, "%d %d:%02d %s", pid, secs / 60, secs % 60, str ); + if (cr = strchr(out, '\n')) + *cr = '\0'; + out[ WHATLEN - 1 ] = '\0'; + lseek(what, WHATLEN * whatindex, SEEK_SET); + write(what, out, WHATLEN); + } + + #endif /* FILEWHAT */ diff -cbrw orig/wu-ftpd-2.4.2-beta-18-vr14/src/pathnames.h wu-ftpd-2.4.2-beta-18-vr14/src/pathnames.h *** orig/wu-ftpd-2.4.2-beta-18-vr14/src/pathnames.h Sat Oct 31 15:58:16 1998 --- wu-ftpd-2.4.2-beta-18-vr14/src/pathnames.h Tue Feb 16 21:27:44 1999 *************** *** 78,95 **** --- 78,99 ---- #endif /* _PATH_FTPD_PIDFILE is only used if DAEMON is defined */ + /* _PATH_WHATNAMES is only used if FILEWHAT is defined */ #ifdef USE_VAR #ifdef USE_PID #define _PATH_PIDNAMES "/var/pid/ftp.pids-%s" #define _PATH_FTPD_PID "/var/pid/ftpd.pid" + #define _PATH_WHATNAMES "/var/pid/ftp.whats-%s" #else #ifdef VAR_RUN #define _PATH_PIDNAMES "/var/run/ftp.pids-%s" #define _PATH_FTPD_PID "/var/run/ftpd.pid" + #define _PATH_WHATNAMES "/var/run/ftp.whats-%s" #else #define _PATH_PIDNAMES "/var/adm/ftp.pids-%s" #define _PATH_FTPD_PID "/var/adm/ftpd.pid" + #define _PATH_WHATNAMES "/var/adm/ftp.whats-%s" #endif #ifdef USE_LOG #define _PATH_XFERLOG "/var/log/xferlog" *************** *** 101,110 **** --- 105,116 ---- #ifdef USE_USR #define _PATH_PIDNAMES "/usr/adm/ftp.pids-%s" #define _PATH_FTPD_PID "/usr/adm/ftpd.pid" + #define _PATH_WHATNAMES "/usr/adm/ftp.whats-%s" #define _PATH_XFERLOG "/usr/adm/xferlog" #else #define _PATH_PIDNAMES "/usr/local/lib/ftpd/pids/%s" #define _PATH_FTPD_PID "/usr/local/lib/ftpd/pids/ftpd.pid" + #define _PATH_WHATNAMES "/usr/local/lib/ftpd/pics/ftp.whats-%s" #define _PATH_XFERLOG "/usr/local/logs/xferlog" #endif #endif -- -- Lee McLoughlin. Phone: +44 171 594 8388 IC-Parc, Imperial College, Fax: +44 171 594 8432 South Kensington, London. SW7 2AZ. UK. Email: lmjm@icparc.ic.ac.uk