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