|
|
1.1 root 1: #include <regexp.h>
2: #include "mail.h"
3: #include "string.h"
4: #include <stdio.h>
5: #include "message.h"
6: #include "dest.h"
7:
8: /* imported */
9: extern char *thissys;
10: extern int debug;
11:
12: /* bind the destinations to the commands to be executed */
13: extern dest *
14: up_bind(destp, mp, checkforward)
15: dest *destp;
16: message *mp;
17: {
18: dest *list[2]; /* lists of unbound destinations */
19: int li; /* index into list[2] */
20: dest *bound=NULL; /* bound destinations */
21: dest *dp;
22: int i;
23:
24: list[0] = destp;
25: list[1] = NULL;
26:
27: /*
28: * loop once to check for:
29: * - forwarding rights
30: * - addressing loops
31: * - illegal characters
32: */
33: for (dp = d_rm(&list[0]); dp != NULL; dp = d_rm(&list[0])) {
34: if (!checkforward)
35: dp->authorized = 1;
36: if (forward_loop(s_to_c(dp->addr), thissys)) {
37: dp->status = d_eloop;
38: d_same_insert(&bound, dp);
39: } else if(forward_loop(s_to_c(mp->sender), thissys)) {
40: dp->status = d_eloop;
41: d_same_insert(&bound, dp);
42: } else if(shellchars(s_to_c(dp->addr))) {
43: dp->status = d_syntax;
44: d_same_insert(&bound, dp);
45: } else
46: d_insert(&list[1], dp);
47: }
48: li = 1;
49:
50: /* Loop until all addresses are bound or address loop detected */
51: for (i=0; list[li]!=NULL && i<32; ++i, li ^= 1) {
52: /* Traverse the current list. Bound items are put on the
53: * `bound' list. Unbound items are put on the next list to
54: * traverse, `list[li^1]'.
55: */
56: for (dp = d_rm(&list[li]); dp != NULL; dp = d_rm(&list[li])){
57: dest *newlist;
58: extern dest *expand_local();
59: extern dest *translate();
60:
61: rewrite(dp, s_to_c(mp->replyaddr));
62: if(debug) {
63: if (dp->status == d_undefined)
64: fprintf(stderr, "%s -> error\n",
65: s_to_c(dp->addr));
66: else
67: fprintf(stderr, "%s -> %s\n",
68: s_to_c(dp->addr),
69: s_to_c(dp->repl1));
70: }
71: switch (dp->status) {
72: case d_auth:
73: /* authorize address if not already authorized */
74: if(!dp->authorized){
75: authorize(dp);
76: if(dp->status==d_auth)
77: d_insert(&list[li^1], dp);
78: else
79: d_insert(&bound, dp);
80: }
81: break;
82: case d_cat:
83: /* address -> local */
84: newlist = expand_local(dp);
85: if (newlist == NULL) {
86: /* append to mailbox (or error) */
87: d_same_insert(&bound, dp);
88: } else if (newlist->status == d_undefined) {
89: /* Forward to ... */
90: d_insert(&list[li^1], newlist);
91: } else {
92: /* Pipe to ... */
93: d_same_insert(&bound, newlist);
94: }
95: break;
96: case d_pipe:
97: /* address -> command */
98: d_same_insert(&bound, dp);
99: break;
100: case d_alias:
101: /* address -> rewritten address */
102: newlist = s_to_dest(dp->repl1, dp);
103: if(newlist != NULL)
104: d_insert(&list[li^1], newlist);
105: else
106: d_same_insert(&bound, dp);
107: break;
108: case d_translate:
109: /* pipe to a translator */
110: newlist = translate(dp);
111: if (newlist != NULL)
112: d_insert(&list[li^1], newlist);
113: else
114: d_same_insert(&bound, dp);
115: break;
116: default:
117: /* error */
118: d_same_insert(&bound, dp);
119: break;
120: }
121: }
122: }
123:
124: /* mark remaining comands as "forwarding loops" */
125: for (dp = d_rm(&list[li]); dp != NULL; dp = d_rm(&list[li])) {
126: dp->status = d_loop;
127: d_same_insert(&bound, dp);
128: }
129:
130: return bound;
131: }
132:
133: /* Return TRUE if a forwarding loop exists, i.e., the string `system'
134: * is found more than 4 times in the return address.
135: */
136: static int
137: forward_loop(addr, system)
138: char *addr;
139: char *system;
140: {
141: int len = strlen(system), found = 0;
142:
143: while (addr = strchr(addr, '!'))
144: if (!strncmp(++addr, system, len)
145: && addr[len] == '!' && ++found == 4)
146: return 1;
147: return 0;
148: }
149:
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.