|
|
1.1 root 1: #include <dirent.h>
2: #include <limits.h>
3: #include <stdio.h>
4: #include <stdlib.h>
5: #include <string.h>
6: #include <unistd.h>
7: #include "dist.h"
8:
9: static char *
10: copy(char *s)
11: {
12: char *r;
13:
14: r = malloc(strlen(s) + 1);
15: if (r)
16: strcpy(r, s);
17: return r;
18: }
19:
20: static void
21: removeq(char *name)
22: {
23: DIR *dp;
24: struct dirent *d;
25: char file[2 * MAXNAME + 1];
26:
27: name = copy(name); /* readdir bug?!? */
28: if (fork() == 0) {
29: setuid(getuid());
30: execl(LDIR "/genmail", "genmail", "-f", name, (char *) 0);
31: exit(0);
32: } else
33: wait(0);
34: if (!(dp = opendir(name)))
35: return;
36: while (d = readdir(dp)) {
37: if (!strcmp(d->d_name, ".") || !strcmp(d->d_name, ".."))
38: continue;
39: sprintf(file, "%s/%.*s", name, MAXNAME, d->d_name);
40: remove(file);
41: }
42: closedir(dp);
43: rmdir(name);
44: free(name);
45: }
46:
47: void
48: scanq(char *remsys, void (*func)(char *, int, char *))
49: {
50: DIR *dp;
51: struct dirent *d;
52: FILE *fp;
53: char sys[MAXLINE], cansys[MAXLINE], file[MAXNAME];
54: int num, zapq;
55:
56: if (remsys)
57: canon(remsys, cansys);
58:
59: if (chdir(SDIR) < 0) {
60: eprintf("can't chdir %s", SDIR);
61: exit(1);
62: }
63:
64: if (!(dp = opendir("."))) {
65: eprintf("can't read spool directory!");
66: exit(1);
67: }
68:
69: while (d = readdir(dp))
70: if (strncmp(d->d_name, QPREFIX, strlen(QPREFIX)) == 0) {
71: zapq = 1;
72: if (chdir(d->d_name) < 0) {
73: eprintf("can't chdir %s/%s", SDIR, d->d_name);
74: continue;
75: }
76: if (fp = fopen(CTL, "r")) {
77: while (fscanf(fp, "%d%s", &num, sys) == 2) {
78: sprintf(file, "%d.%s", num, DONE);
79: if (access(file, F_OK) == 0)
80: continue;
81: if (remsys && strcmp(sys, cansys) != 0) {
82: zapq = 0;
83: continue;
84: }
85: if (func)
86: (*func)(d->d_name, num, sys);
87: if (access(file, F_OK) != 0)
88: zapq = 0;
89: }
90: fclose(fp);
91: } else
92: eprintf("can't read %s/%s", d->d_name, CTL);
93: chdir("..");
94: if (zapq)
95: removeq(d->d_name);
96: }
97:
98: closedir(dp);
99: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.