1: #ifndef lint
   2: static char sccsid[] = "@(#)uuclean.c	5.6 (Berkeley) 10/9/85";
   3: #endif
   4: 
   5: #include <signal.h>
   6: #include "uucp.h"
   7: #include <pwd.h>
   8: #include <sys/stat.h>
   9: #ifdef  NDIR
  10: #include "ndir.h"
  11: #else
  12: #include <sys/dir.h>
  13: #endif
  14: 
  15: /*
  16:  *
  17:  *	this program will search through the spool
  18:  *	directory (Spool) and delete all files with a requested
  19:  *	prefix which are older than (nomtime) seconds.
  20:  *	If the -m option is set, the program will try to
  21:  *	send mail to the usid of the file.
  22:  *
  23:  *	options:
  24:  *		-m  -  send mail for deleted file
  25:  *		-d  -  directory to clean
  26:  *		-n  -  time to age files before delete (in hours)
  27:  *		-p  -  prefix for search
  28:  *		-x  -  turn on debug outputs
  29:  *	exit status:
  30:  *		0  -  normal return
  31:  *		1  -  can not read directory
  32:  */
  33: 
  34: #define NOMTIME 72  /* hours to age files before deletion */
  35: 
  36: int checkprefix = 0;
  37: struct timeb Now;
  38: 
  39: main(argc, argv)
  40: char *argv[];
  41: {
  42:     DIR *dirp;
  43:     char file[NAMESIZE];
  44:     time_t nomtime, ptime;
  45:     struct stat stbuf;
  46:     int mflg=0;
  47: 
  48:     strcpy(Progname, "uuclean");
  49:     uucpname(Myname);
  50:     nomtime = NOMTIME * (time_t)3600;
  51: 
  52:     while (argc>1 && argv[1][0] == '-') {
  53:         switch (argv[1][1]) {
  54:         case 'd':
  55:             Spool = &argv[1][2];
  56:             break;
  57:         case 'm':
  58:             mflg = 1;
  59:             break;
  60:         case 'n':
  61:             nomtime = atoi(&argv[1][2]) * (time_t)3600;
  62:             break;
  63:         case 'p':
  64:             checkprefix = 1;
  65:             if (&argv[1][2] != '\0')
  66:                 stpre(&argv[1][2]);
  67:             break;
  68:         case 'x':
  69:             chkdebug();
  70:             Debug = atoi(&argv[1][2]);
  71:             if (Debug <= 0)
  72:                 Debug = 1;
  73:             break;
  74:         default:
  75:             printf("unknown flag %s\n", argv[1]); break;
  76:         }
  77:         --argc;  argv++;
  78:     }
  79: 
  80:     DEBUG(4, "DEBUG# %s\n", "START");
  81:     if (chdir(Spool) < 0) { /* NO subdirs in uuclean!  rti!trt */
  82:         printf("%s directory inaccessible\n", Spool);
  83:         exit(1);
  84:     }
  85: 
  86:     if ((dirp = opendir(Spool)) == NULL) {
  87:         printf("%s directory unreadable\n", Spool);
  88:         exit(1);
  89:     }
  90: 
  91:     time(&ptime);
  92:     while (gnamef(dirp, file)) {
  93:         if (checkprefix && !chkpre(file))
  94:             continue;
  95: 
  96:         if (stat(file, &stbuf) == -1) {
  97:             DEBUG(4, "stat on %s failed\n", file);
  98:             continue;
  99:         }
 100: 
 101: 
 102:         if ((stbuf.st_mode & S_IFMT) == S_IFDIR)
 103:             continue;
 104:         if ((ptime - stbuf.st_mtime) < nomtime)
 105:             continue;
 106:         if (file[0] == CMDPRE)
 107:             notfyuser(file);
 108:         DEBUG(4, "unlink file %s\n", file);
 109:         unlink(file);
 110:         if (mflg)
 111:             sdmail(file, stbuf.st_uid);
 112:     }
 113: 
 114:     closedir(dirp);
 115:     exit(0);
 116: }
 117: 
 118: 
 119: #define MAXPRE 10
 120: char Pre[MAXPRE][NAMESIZE];
 121: int Npre = 0;
 122: /***
 123:  *	chkpre(file)	check for prefix
 124:  *	char *file;
 125:  *
 126:  *	return codes:
 127:  *		0  -  not prefix
 128:  *		1  -  is prefix
 129:  */
 130: 
 131: chkpre(file)
 132: char *file;
 133: {
 134:     int i;
 135: 
 136:     for (i = 0; i < Npre; i++) {
 137:         if (prefix(Pre[i], file))
 138:             return(1);
 139:         }
 140:     return(0);
 141: }
 142: 
 143: /***
 144:  *	stpre(p)	store prefix
 145:  *	char *p;
 146:  *
 147:  *	return codes:  none
 148:  */
 149: 
 150: stpre(p)
 151: char *p;
 152: {
 153:     if (Npre < MAXPRE - 2)
 154:         strcpy(Pre[Npre++], p);
 155:     return;
 156: }
 157: 
 158: /***
 159:  *	notfyuser(file)	- notfiy requestor of deleted requres
 160:  *
 161:  *	return code - none
 162:  */
 163: 
 164: notfyuser(file)
 165: char *file;
 166: {
 167:     FILE *fp;
 168:     int numrq;
 169:     char frqst[100], lrqst[100];
 170:     char msg[BUFSIZ];
 171:     char *args[10];
 172: 
 173:     if ((fp = fopen(file, "r")) == NULL)
 174:         return;
 175:     if (fgets(frqst, 100, fp) == NULL) {
 176:         fclose(fp);
 177:         return;
 178:     }
 179:     numrq = 1;
 180:     while (fgets(lrqst, 100, fp))
 181:         numrq++;
 182:     fclose(fp);
 183:     sprintf(msg,
 184:       "File %s delete. \nCould not contact remote. \n%d requests deleted.\n", file, numrq);
 185:     if (numrq == 1) {
 186:         strcat(msg, "REQUEST: ");
 187:         strcat(msg, frqst);
 188:     } else {
 189:         strcat(msg, "FIRST REQUEST: ");
 190:         strcat(msg, frqst);
 191:         strcat(msg, "\nLAST REQUEST: ");
 192:         strcat(msg, lrqst);
 193:     }
 194:     getargs(frqst, args, 10);
 195:     mailst(args[3], msg, CNULL);
 196: }
 197: 
 198: 
 199: /***
 200:  *	sdmail(file, uid)
 201:  *
 202:  *	sdmail  -  this routine will determine the owner
 203:  *	of the file (file), create a message string and
 204:  *	call "mailst" to send the cleanup message.
 205:  *	This is only implemented for local system
 206:  *	mail at this time.
 207:  */
 208: 
 209: sdmail(file, uid)
 210: char *file;
 211: {
 212:     static struct passwd *pwd;
 213:     struct passwd *getpwuid();
 214:     char mstr[40];
 215: 
 216:     sprintf(mstr, "uuclean deleted file %s\n", file);
 217:     if (pwd != NULL && pwd->pw_uid == uid) {
 218:         mailst(pwd->pw_name, mstr, CNULL);
 219:         return;
 220:     }
 221: 
 222:     setpwent();
 223:     if ((pwd = getpwuid(uid)) != NULL)
 224:         mailst(pwd->pw_name, mstr, CNULL);
 225: }
 226: 
 227: cleanup(code)
 228: int code;
 229: {
 230:     exit(code);
 231: }

Defined functions

chkpre defined in line 131; used 1 times
  • in line 93
cleanup defined in line 227; never used
main defined in line 39; never used
notfyuser defined in line 164; used 1 times
sdmail defined in line 209; used 1 times
stpre defined in line 150; used 1 times
  • in line 66

Defined variables

Now defined in line 37; never used
Npre defined in line 121; used 3 times
Pre defined in line 120; used 2 times
checkprefix defined in line 36; used 2 times
sccsid defined in line 2; never used

Defined macros

MAXPRE defined in line 119; used 2 times
NOMTIME defined in line 34; used 1 times
  • in line 50
Last modified: 1987-02-17
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 2909
Valid CSS Valid XHTML 1.0 Strict