|
|
1.1 root 1: #include <stdio.h>
2: #include <pwd.h>
3: #include "mail.h"
4: #include "string.h"
5: #include "dest.h"
6: #include "aux.h"
7: #include "process.h"
8: #include "ugid.h"
9: #include <sys/stat.h>
10:
11: /* cheap foriegn import */
12: extern struct passwd * getpwnam();
13: extern FILE *lockopen();
14:
15: /* expand a local destination into a list of destinations */
16: extern dest *
17: expand_local(dp)
18: dest *dp;
19: {
20: FILE *fp;
21: string *file = s_new();
22: string *line = s_new();
23: dest *rv;
24: int status;
25: struct passwd *pw;
26: struct stat sbuf;
27: struct ugid ubuf;
28:
29: /* security - can't have a / in the original address */
30: if (strchr(s_to_c(dp->addr), '/')!=NULL) {
31: dp->status = d_syntax;
32: return NULL;
33: }
34:
35: /* make the mail file name */
36: if (dp->repl1 == NULL)
37: abspath(s_to_c(dp->addr), MAILROOT, file);
38: else
39: abspath(s_to_c(dp->repl1), MAILROOT, file);
40: fp = lockopen(s_to_c(file), "r", 0, 0, 0);
41:
42: /* check for forwarding or piping */
43: if (fp != NULL) {
44: fstat(fileno(fp), &sbuf);
45: (void)s_getline(fp, line);
46: lockclose(fp);
47: status = delivery_status(line);
48: } else
49: status = MF_NOMBOX;
50:
51: switch(status) {
52: case MF_PIPE:
53: dp->repl1 = s_clone(line);
54: dp->status = d_pipeto;
55: if (mboxowner(s_to_c(file),&ubuf) < 0)
56: dp->status = d_unknown;
57: else {
58: dp->uid = ubuf.uid;
59: dp->gid = ubuf.gid;
60: }
61: break;
62: case MF_FORWARD:
63: rv = s_to_dest(line, dp);
64: if(rv==NULL)
65: dp->status = d_badmbox;
66: s_free(line);
67: s_free(file);
68: return rv;
69: case MF_NORMAL:
70: dp->status = d_cat;
71: break;
72: case MF_NOMBOX:
73: /* no mailbox. deliver only if in /etc/passwd. */
74: pw = getpwnam(basename(s_to_c(file)));
75: if (pw != NULL) {
76: dp->uid = pw->pw_uid;
77: dp->gid = pw->pw_gid;
78: dp->status = d_cat;
79: } else
80: dp->status = d_unknown;
81: break;
82: case MF_NOTMBOX:
83: /* security - don't cat onto non-mailboxes */
84: dp->status = d_badmbox;
85: break;
86: }
87: s_free(line);
88: s_free(file);
89: return NULL;
90: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.