4 static int forward_loop(char *, char *);
6 /* bind the destinations to the commands to be executed */
8 up_bind(dest *destp, message *mp, int checkforward)
10 dest *list[2]; /* lists of unbound destinations */
11 int li; /* index into list[2] */
12 dest *bound=0; /* bound destinations */
20 * loop once to check for:
23 * - illegal characters
24 * - characters that need escaping
26 for (dp = d_rm(&list[0]); dp != 0; dp = d_rm(&list[0])) {
29 dp->addr = escapespecial(dp->addr);
30 if (forward_loop(s_to_c(dp->addr), thissys)) {
32 d_same_insert(&bound, dp);
33 } else if(forward_loop(s_to_c(mp->sender), thissys)) {
35 d_same_insert(&bound, dp);
36 } else if(shellchars(s_to_c(dp->addr))) {
37 dp->status = d_syntax;
38 d_same_insert(&bound, dp);
40 d_insert(&list[1], dp);
44 /* Loop until all addresses are bound or address loop detected */
45 for (i=0; list[li]!=0 && i<32; ++i, li ^= 1) {
46 /* Traverse the current list. Bound items are put on the
47 * `bound' list. Unbound items are put on the next list to
48 * traverse, `list[li^1]'.
50 for (dp = d_rm(&list[li]); dp != 0; dp = d_rm(&list[li])){
55 fprint(2, "%s -> %s\n", s_to_c(dp->addr),
56 dp->repl1 ? s_to_c(dp->repl1):"");
59 /* authorize address if not already authorized */
62 if(dp->status==d_auth)
63 d_insert(&list[li^1], dp);
69 /* address -> local */
70 newlist = expand_local(dp);
72 /* append to mailbox (or error) */
73 d_same_insert(&bound, dp);
74 } else if (newlist->status == d_undefined) {
76 d_insert(&list[li^1], newlist);
79 d_same_insert(&bound, newlist);
83 /* address -> command */
84 d_same_insert(&bound, dp);
87 /* address -> rewritten address */
88 newlist = s_to_dest(dp->repl1, dp);
90 d_insert(&list[li^1], newlist);
92 d_same_insert(&bound, dp);
95 /* pipe to a translator */
96 newlist = translate(dp);
98 d_insert(&list[li^1], newlist);
100 d_same_insert(&bound, dp);
104 d_same_insert(&bound, dp);
110 /* mark remaining comands as "forwarding loops" */
111 for (dp = d_rm(&list[li]); dp != 0; dp = d_rm(&list[li])) {
113 d_same_insert(&bound, dp);
119 /* Return TRUE if a forwarding loop exists, i.e., the String `system'
120 * is found more than 4 times in the return address.
123 forward_loop(char *addr, char *system)
125 int len = strlen(system), found = 0;
127 while (addr = strchr(addr, '!'))
128 if (!strncmp(++addr, system, len)
129 && addr[len] == '!' && ++found == 4)