1: static char sccsid[] = "@(#)netrm.c 4.2 (Berkeley) 9/12/82";
2:
3: # include "defs.h"
4: /* sccs id variable */
5: static char *netrm_sid = "@(#)netrm.c 1.2";
6:
7:
8: /*
9: * netrm - remove an entry from the network queue.
10: *
11: * first does a creat to truncate the file to zero length in
12: * case it is being sent. (this stops the daemon!) Next the
13: * file is removed.
14: * must be setuid root
15: */
16:
17: char path[] = NETRMPATH;
18: char pathname[]= NETRMNAME;
19:
20: int hisuid, hisgid;
21: static char visit[26];
22: static struct stat statbuf;
23:
24: main(argc,argv)
25: char *argv[];
26: {
27: int cnt, mach, i, all = 0;
28:
29: if (argc < 2)
30: {
31: printf("usage: netrm [-] file1 file2 ... filen\n");
32: exit(EX_USAGE);
33: }
34:
35: hisuid = getuid();
36: hisuid = uidmask(hisuid);
37: hisgid = getgid();
38:
39: if(argv[1][0] == '-'){
40: all++;
41: argv++;
42: argc--;
43: }
44: cnt = 0;
45:
46: while (++cnt < argc)rmfile(argv[cnt]);
47: if(all){
48: visit[chtoinx(local)] = 1; /* skip this machine */
49: for(i = 0; i < MAXINX; i++)
50: if((mach = gothru(local,inxtoch(i)))
51: && !visit[chtoinx(mach)]){
52: visit[chtoinx(mach)] = 1;
53: senddir[strlen(senddir)-1] = mach;
54: if(chdir(senddir) < 0)
55: continue;
56: pdir(senddir);
57: }
58: }
59: }
60: static pdir(str)
61: char *str; {
62: DIR *df;
63: register struct direct *dp;
64: df = opendir(str);
65: if(df == NULL){
66: perror(str);
67: exit(EX_OSFILE);
68: }
69: while((dp = readdir(df)) != NULL){
70: if(dp->d_name[0] != 'd'
71: || dp->d_name[1] != 'f'
72: || stat(dp->d_name,&statbuf) < 0)
73: continue;
74: if(guid(statbuf.st_uid,statbuf.st_gid) != hisuid)
75: continue;
76: /* kludge in file name */
77: dp->d_name[3] = dp->d_name[2];
78: rmfile(dp->d_name+3);
79: }
80: closedir(df);
81: }
82: rmfile(str)
83: char *str;
84: {
85: register char *ap, *cp;
86: int tt;
87: char *ostr,*rem,buf[20];
88: ostr = str;
89: if(str[0] != 'd' || str[1] != 'f' || str[3] != 'a'){
90: strcpy(buf+3,str);
91: buf[0] = 'd';
92: buf[1] = 'f';
93: buf[2] = str[0];
94: buf[3] = 'a';
95: str = buf;
96: }
97: cp = path;
98: ap = pathname;
99: while (*ap++ = *cp++);
100: cp = pathname + strlen(pathname) - 10;
101: while(*cp++ != 'f');
102: cp--;
103: cp--;
104: rem = cp;
105: ap = str;
106: while(*cp != '\0' && (*cp++ = *ap++));
107: pathname[strlen(pathname) - 11] = str[2]; /* set dir for mach */
108:
109: if (stat(pathname,&statbuf) < 0) {
110: perror(ostr);
111: return;
112: }
113:
114: tt = guid(statbuf.st_uid,statbuf.st_gid);
115: if(tt != hisuid && hisuid != 0) {
116: printf("%s: Permission Denied\n",ostr);
117: return;
118: }
119:
120: printf("removing file %s\n",ostr);
121: creat(pathname,0600);
122: unlink(pathname);
123: *rem = 'c';
124: unlink(pathname);
125: }
Defined functions
main
defined in line
24;
never used
pdir
defined in line
60; used 1 times
Defined variables
path
defined in line
17; used 1 times
sccsid
defined in line
1;
never used
visit
defined in line
21; used 3 times