1*8221Smckusick static char sccsid[] = "@(#)netrm.c 4.2 (Berkeley) 09/12/82";
28199Smckusick
38199Smckusick # include "defs.h"
48199Smckusick /* sccs id variable */
58199Smckusick static char *netrm_sid = "@(#)netrm.c 1.2";
68199Smckusick
78199Smckusick
88199Smckusick /*
98199Smckusick * netrm - remove an entry from the network queue.
108199Smckusick *
118199Smckusick * first does a creat to truncate the file to zero length in
128199Smckusick * case it is being sent. (this stops the daemon!) Next the
138199Smckusick * file is removed.
148199Smckusick * must be setuid root
158199Smckusick */
168199Smckusick
178199Smckusick char path[] = NETRMPATH;
188199Smckusick char pathname[]= NETRMNAME;
198199Smckusick
208199Smckusick int hisuid, hisgid;
218199Smckusick static char visit[26];
228199Smckusick static struct stat statbuf;
238199Smckusick
main(argc,argv)248199Smckusick main(argc,argv)
258199Smckusick char *argv[];
268199Smckusick {
278199Smckusick int cnt, mach, i, all = 0;
288199Smckusick
298199Smckusick if (argc < 2)
308199Smckusick {
318199Smckusick printf("usage: netrm [-] file1 file2 ... filen\n");
328199Smckusick exit(EX_USAGE);
338199Smckusick }
348199Smckusick
358199Smckusick hisuid = getuid();
368199Smckusick hisuid = uidmask(hisuid);
378199Smckusick hisgid = getgid();
388199Smckusick
398199Smckusick if(argv[1][0] == '-'){
408199Smckusick all++;
418199Smckusick argv++;
428199Smckusick argc--;
438199Smckusick }
448199Smckusick cnt = 0;
458199Smckusick
468199Smckusick while (++cnt < argc)rmfile(argv[cnt]);
478199Smckusick if(all){
488199Smckusick visit[chtoinx(local)] = 1; /* skip this machine */
498199Smckusick for(i = 0; i < MAXINX; i++)
508199Smckusick if((mach = gothru(local,inxtoch(i)))
518199Smckusick && !visit[chtoinx(mach)]){
528199Smckusick visit[chtoinx(mach)] = 1;
538199Smckusick senddir[strlen(senddir)-1] = mach;
548199Smckusick if(chdir(senddir) < 0)
558199Smckusick continue;
568199Smckusick pdir(senddir);
578199Smckusick }
588199Smckusick }
598199Smckusick }
pdir(str)608199Smckusick static pdir(str)
618199Smckusick char *str; {
62*8221Smckusick DIR *df;
63*8221Smckusick register struct direct *dp;
64*8221Smckusick df = opendir(str);
658199Smckusick if(df == NULL){
668199Smckusick perror(str);
678199Smckusick exit(EX_OSFILE);
688199Smckusick }
69*8221Smckusick while((dp = readdir(df)) != NULL){
70*8221Smckusick if(dp->d_name[0] != 'd'
71*8221Smckusick || dp->d_name[1] != 'f'
72*8221Smckusick || stat(dp->d_name,&statbuf) < 0)
738199Smckusick continue;
748199Smckusick if(guid(statbuf.st_uid,statbuf.st_gid) != hisuid)
758199Smckusick continue;
768199Smckusick /* kludge in file name */
77*8221Smckusick dp->d_name[3] = dp->d_name[2];
78*8221Smckusick rmfile(dp->d_name+3);
798199Smckusick }
80*8221Smckusick closedir(df);
818199Smckusick }
rmfile(str)828199Smckusick rmfile(str)
838199Smckusick char *str;
848199Smckusick {
858199Smckusick register char *ap, *cp;
868199Smckusick int tt;
878199Smckusick char *ostr,*rem,buf[20];
888199Smckusick ostr = str;
898199Smckusick if(str[0] != 'd' || str[1] != 'f' || str[3] != 'a'){
908199Smckusick strcpy(buf+3,str);
918199Smckusick buf[0] = 'd';
928199Smckusick buf[1] = 'f';
938199Smckusick buf[2] = str[0];
948199Smckusick buf[3] = 'a';
958199Smckusick str = buf;
968199Smckusick }
978199Smckusick cp = path;
988199Smckusick ap = pathname;
998199Smckusick while (*ap++ = *cp++);
1008199Smckusick cp = pathname + strlen(pathname) - 10;
1018199Smckusick while(*cp++ != 'f');
1028199Smckusick cp--;
1038199Smckusick cp--;
1048199Smckusick rem = cp;
1058199Smckusick ap = str;
1068199Smckusick while(*cp != '\0' && (*cp++ = *ap++));
1078199Smckusick pathname[strlen(pathname) - 11] = str[2]; /* set dir for mach */
1088199Smckusick
1098199Smckusick if (stat(pathname,&statbuf) < 0) {
1108199Smckusick perror(ostr);
1118199Smckusick return;
1128199Smckusick }
1138199Smckusick
1148199Smckusick tt = guid(statbuf.st_uid,statbuf.st_gid);
1158199Smckusick if(tt != hisuid && hisuid != 0) {
1168199Smckusick printf("%s: Permission Denied\n",ostr);
1178199Smckusick return;
1188199Smckusick }
1198199Smckusick
1208199Smckusick printf("removing file %s\n",ostr);
1218199Smckusick creat(pathname,0600);
1228199Smckusick unlink(pathname);
1238199Smckusick *rem = 'c';
1248199Smckusick unlink(pathname);
1258199Smckusick }
126