/*
* The author of this software is Eric Grosse. Copyright (c) 1994 by AT&T.
* Permission to use, copy, modify, and distribute this software for any
* purpose without fee is hereby granted, provided that this entire notice
* is included in all copies of any software which is or includes a copy
* or modification of this software and in all copies of the supporting
* documentation for such software.
* THIS SOFTWARE IS BEING PROVIDED "AS IS", WITHOUT ANY EXPRESS OR IMPLIED
* WARRANTY. IN PARTICULAR, NEITHER THE AUTHORS NOR AT&T MAKE ANY
* REPRESENTATION OR WARRANTY OF ANY KIND CONCERNING THE MERCHANTABILITY
* OF THIS SOFTWARE OR ITS FITNESS FOR ANY PARTICULAR PURPOSE.
*/
#define _POSIX_SOURCE
#include <stdlib.h>
#include <unistd.h>
#include <stdio.h>
#include <string.h>
#include <ctype.h>
#include <errno.h>
#include <limits.h>
extern int Error(char*,...);
char *progname;
void
filechk(char *f)
{
char *p;
unsigned char c;
if(!f || !*f) Error("null filename");
if(*f=='/') Error("leading slash");
if(strncmp(f,"../",3)==0) Error("leading ..");
for(p = strchr(f,'/'); p; p = strchr(p+1,'/'))
if(p[1]=='.' && p[2]=='.' && (p[3]==0 || p[3]=='/') )
Error("embedded ..");
for(p = f; *p; p++){
c = *p;
if( !isascii(c) || isspace(c) || !isprint(c) )
Error("bad char");
/* check for characters interpreted by the shell (by which
nefarious users might otherwise break into the system) */
if ( strchr("\"'`$\n;&|^<>()\\", c) || (c & 0200) )
Error("unsafe character");
}
}
nt
main(int argc, char **argv)
{
int rc, removes = 0;
unsigned long tim, len, sum;
char cmd[21], name[2001];
double space = 0.;
progname = argv[0];
while((rc=fscanf(stdin,"%20s %2000s %lu %lu %lx",
cmd,name,&tim,&len,&sum))!=EOF){
if(rc!=5) Error("saw %d fields, expected 5",rc);
filechk(name);
switch(*cmd){
case 'g': /* get */
space += len;
break;
case 'r': /* rm */
space -= len;
removes++;
break;
case 't': /* time */
break;
default:
Error("? %s %s",cmd,name);
}
}
space /= 1.e6;
if(space>50.)
Error("will need %gMB additional disk\n",space);
if(removes>30)
Error("%d files to be removed\n",removes);
exit(0);
}
.