annotate src/alias.c @ 355:ddb7b3fd3d08

found further appearences of ``localnet'' in the code
author markus schnalke <meillo@marmaro.de>
date Sun, 04 Sep 2011 11:33:31 +0200
parents 273f6c9eb6a2
children 41958685480d
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
1 /* MasqMail
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
2 Copyright (C) 2000-2001 Oliver Kurth
239
31ee44f45787 refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents: 233
diff changeset
3 Copyright (C) 2010 markus schnalke <meillo@marmaro.de>
0
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
4
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
5 This program is free software; you can redistribute it and/or modify
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
6 it under the terms of the GNU General Public License as published by
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
7 the Free Software Foundation; either version 2 of the License, or
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
8 (at your option) any later version.
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
9
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
10 This program is distributed in the hope that it will be useful,
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
13 GNU General Public License for more details.
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
14
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
15 You should have received a copy of the GNU General Public License
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
16 along with this program; if not, write to the Free Software
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
18 */
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
19
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
20 #include "masqmail.h"
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
21 #include <fnmatch.h>
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
22
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
23 gboolean
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
24 addr_is_local(address * addr)
0
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
25 {
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
26 GList *dom_node;
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
27 GList *addr_node;
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
28 address *a;
0
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
29
239
31ee44f45787 refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents: 233
diff changeset
30 if (addr->domain == NULL) {
31ee44f45787 refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents: 233
diff changeset
31 return TRUE;
31ee44f45787 refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents: 233
diff changeset
32 }
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
33 foreach(conf.local_hosts, dom_node) {
239
31ee44f45787 refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents: 233
diff changeset
34 /* Note: FNM_CASEFOLD is a GNU extension */
31ee44f45787 refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents: 233
diff changeset
35 if (fnmatch(dom_node->data, addr->domain, FNM_CASEFOLD) != 0) {
31ee44f45787 refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents: 233
diff changeset
36 /* no match, try next */
31ee44f45787 refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents: 233
diff changeset
37 continue;
31ee44f45787 refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents: 233
diff changeset
38 }
31ee44f45787 refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents: 233
diff changeset
39 foreach(conf.not_local_addresses, addr_node) {
31ee44f45787 refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents: 233
diff changeset
40 a = create_address_qualified(addr_node->data, TRUE, conf.host_name);
31ee44f45787 refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents: 233
diff changeset
41 DEBUG(6) debugf("not_local_addresses: addr_node->data=%s a->address=%s\n",
31ee44f45787 refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents: 233
diff changeset
42 addr_node->data, a->address);
244
7082044c05c6 renamed `alias_local_cmp' to `localpartcmp'
markus schnalke <meillo@marmaro.de>
parents: 242
diff changeset
43 if (addr_isequal(a, addr, conf.localpartcmp)) {
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
44 destroy_address(a);
239
31ee44f45787 refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents: 233
diff changeset
45 /* in local_hosts but also in not_local_addresses */
31ee44f45787 refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents: 233
diff changeset
46 return FALSE;
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
47 }
239
31ee44f45787 refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents: 233
diff changeset
48 destroy_address(a);
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
49 }
239
31ee44f45787 refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents: 233
diff changeset
50 /* in local_hosts */
31ee44f45787 refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents: 233
diff changeset
51 return TRUE;
0
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
52 }
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
53 foreach(conf.local_addresses, addr_node) {
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
54 a = create_address_qualified(addr_node->data, TRUE, conf.host_name);
114
a80ebfa16cd5 better debugging output (thanks to Paolo)
meillo@marmaro.de
parents: 14
diff changeset
55 DEBUG(6) debugf("local_addresses: addr_node->data=%s a->address=%s\n",
a80ebfa16cd5 better debugging output (thanks to Paolo)
meillo@marmaro.de
parents: 14
diff changeset
56 addr_node->data, a->address);
244
7082044c05c6 renamed `alias_local_cmp' to `localpartcmp'
markus schnalke <meillo@marmaro.de>
parents: 242
diff changeset
57 if (addr_isequal(a, addr, conf.localpartcmp)) {
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
58 destroy_address(a);
239
31ee44f45787 refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents: 233
diff changeset
59 /* in local_addresses */
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
60 return TRUE;
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
61 }
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
62 destroy_address(a);
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
63 }
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
64 return FALSE;
0
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
65 }
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
66
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
67 static GList*
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
68 parse_list(gchar * line)
0
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
69 {
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
70 GList *list = NULL;
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
71 gchar buf[256];
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
72 gchar *p, *q;
0
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
73
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
74 p = line;
14
a8f3424347dc replaced number 0 with character \0 where appropriate
meillo@marmaro.de
parents: 10
diff changeset
75 while (*p != '\0') {
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
76 q = buf;
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
77 while (isspace(*p))
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
78 p++;
239
31ee44f45787 refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents: 233
diff changeset
79 if (*p != '"') {
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
80 while (*p && (*p != ',') && (q < buf + 255))
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
81 *(q++) = *(p++);
14
a8f3424347dc replaced number 0 with character \0 where appropriate
meillo@marmaro.de
parents: 10
diff changeset
82 *q = '\0';
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
83 } else {
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
84 gboolean escape = FALSE;
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
85 p++;
239
31ee44f45787 refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents: 233
diff changeset
86 while (*p && (*p != '"' || escape) && (q < buf + 255)) {
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
87 if ((*p == '\\') && !escape)
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
88 escape = TRUE;
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
89 else {
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
90 escape = FALSE;
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
91 *(q++) = *p;
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
92 }
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
93 p++;
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
94 }
14
a8f3424347dc replaced number 0 with character \0 where appropriate
meillo@marmaro.de
parents: 10
diff changeset
95 *q = '\0';
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
96 while (*p && (*p != ','))
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
97 p++;
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
98 }
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
99 list = g_list_append(list, g_strdup(g_strchomp(buf)));
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
100 if (*p)
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
101 p++;
0
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
102 }
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
103 return list;
0
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
104 }
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
105
239
31ee44f45787 refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents: 233
diff changeset
106 /*
31ee44f45787 refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents: 233
diff changeset
107 addr is assumed to be local and no pipe address nor not-to-expand
31ee44f45787 refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents: 233
diff changeset
108 */
31ee44f45787 refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents: 233
diff changeset
109 static GList*
31ee44f45787 refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents: 233
diff changeset
110 expand_one(GList* alias_table, address* addr)
0
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
111 {
239
31ee44f45787 refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents: 233
diff changeset
112 GList *val_list;
31ee44f45787 refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents: 233
diff changeset
113 GList *val_node;
31ee44f45787 refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents: 233
diff changeset
114 GList *alias_list = NULL;
31ee44f45787 refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents: 233
diff changeset
115 GList *alias_node;
31ee44f45787 refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents: 233
diff changeset
116 gchar *val;
31ee44f45787 refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents: 233
diff changeset
117 address* alias_addr;
0
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
118
239
31ee44f45787 refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents: 233
diff changeset
119 /* expand the local alias */
31ee44f45787 refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents: 233
diff changeset
120 DEBUG(6) debugf("alias: '%s' is local and will get expanded\n", addr->local_part);
31ee44f45787 refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents: 233
diff changeset
121
31ee44f45787 refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents: 233
diff changeset
122 if (strcasecmp(addr->local_part, "postmaster") == 0) {
31ee44f45787 refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents: 233
diff changeset
123 /* postmaster must always be matched caseless
31ee44f45787 refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents: 233
diff changeset
124 see RFC 822 and RFC 5321 */
31ee44f45787 refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents: 233
diff changeset
125 val = (gchar *) table_find_func(alias_table, addr->local_part, strcasecmp);
31ee44f45787 refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents: 233
diff changeset
126 } else {
244
7082044c05c6 renamed `alias_local_cmp' to `localpartcmp'
markus schnalke <meillo@marmaro.de>
parents: 242
diff changeset
127 val = (gchar *) table_find_func(alias_table, addr->local_part, conf.localpartcmp);
239
31ee44f45787 refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents: 233
diff changeset
128 }
31ee44f45787 refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents: 233
diff changeset
129 if (!val) {
31ee44f45787 refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents: 233
diff changeset
130 DEBUG(5) debugf("alias: '%s' is fully expanded, hence completed\n",
31ee44f45787 refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents: 233
diff changeset
131 addr->local_part);
31ee44f45787 refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents: 233
diff changeset
132 return g_list_append(NULL, addr);
31ee44f45787 refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents: 233
diff changeset
133 }
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
134
239
31ee44f45787 refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents: 233
diff changeset
135 DEBUG(5) debugf("alias: '%s' -> '%s'\n", addr->local_part, val);
31ee44f45787 refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents: 233
diff changeset
136 val_list = parse_list(val);
31ee44f45787 refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents: 233
diff changeset
137 alias_list = NULL;
31ee44f45787 refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents: 233
diff changeset
138
31ee44f45787 refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents: 233
diff changeset
139 foreach(val_list, val_node) {
31ee44f45787 refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents: 233
diff changeset
140 gchar *val = (gchar *) (val_node->data);
31ee44f45787 refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents: 233
diff changeset
141 address *alias_addr;
31ee44f45787 refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents: 233
diff changeset
142 address *addr_parent = NULL;
31ee44f45787 refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents: 233
diff changeset
143
31ee44f45787 refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents: 233
diff changeset
144 DEBUG(6) debugf("alias: processing '%s'\n", val);
0
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
145
239
31ee44f45787 refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents: 233
diff changeset
146 if (val[0] == '\\') {
31ee44f45787 refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents: 233
diff changeset
147 DEBUG(5) debugf("alias: '%s' is marked as final, hence completed\n", val);
31ee44f45787 refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents: 233
diff changeset
148 alias_addr = create_address_qualified(val+1, TRUE, conf.host_name);
31ee44f45787 refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents: 233
diff changeset
149 g_free(val);
31ee44f45787 refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents: 233
diff changeset
150 DEBUG(6) debugf("alias: address generated: '%s'\n",
31ee44f45787 refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents: 233
diff changeset
151 alias_addr->local_part);
31ee44f45787 refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents: 233
diff changeset
152 alias_list = g_list_append(alias_list, alias_addr);
31ee44f45787 refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents: 233
diff changeset
153 continue;
31ee44f45787 refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents: 233
diff changeset
154 }
31ee44f45787 refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents: 233
diff changeset
155
31ee44f45787 refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents: 233
diff changeset
156 if (val[0] == '|') {
31ee44f45787 refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents: 233
diff changeset
157 DEBUG(5) debugf("alias: '%s' is a pipe address\n", val);
309
273f6c9eb6a2 bug fix: off-by-one in pipe aliases
meillo@marmaro.de
parents: 244
diff changeset
158 alias_addr = create_address_pipe(val);
239
31ee44f45787 refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents: 233
diff changeset
159 g_free(val);
31ee44f45787 refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents: 233
diff changeset
160 DEBUG(6) debugf("alias: pipe generated: %s\n",
31ee44f45787 refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents: 233
diff changeset
161 alias_addr->local_part);
31ee44f45787 refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents: 233
diff changeset
162 alias_list = g_list_append(alias_list, alias_addr);
31ee44f45787 refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents: 233
diff changeset
163 continue;
31ee44f45787 refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents: 233
diff changeset
164 }
0
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
165
239
31ee44f45787 refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents: 233
diff changeset
166 alias_addr = create_address_qualified(val, TRUE, conf.host_name);
31ee44f45787 refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents: 233
diff changeset
167 g_free(val);
31ee44f45787 refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents: 233
diff changeset
168
31ee44f45787 refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents: 233
diff changeset
169 if (!addr_is_local(alias_addr)) {
31ee44f45787 refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents: 233
diff changeset
170 DEBUG(5) debugf("alias: '%s@%s' is non-local, hence completed\n",
31ee44f45787 refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents: 233
diff changeset
171 alias_addr->local_part, alias_addr->domain);
31ee44f45787 refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents: 233
diff changeset
172 alias_list = g_list_append(alias_list, alias_addr);
31ee44f45787 refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents: 233
diff changeset
173 continue;
31ee44f45787 refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents: 233
diff changeset
174 }
31ee44f45787 refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents: 233
diff changeset
175
242
bc9d9cd9ee8e made addr_isequal() and addr_isequal_parent() more flexible
markus schnalke <meillo@marmaro.de>
parents: 239
diff changeset
176 /* addr is local and to expand at this point */
bc9d9cd9ee8e made addr_isequal() and addr_isequal_parent() more flexible
markus schnalke <meillo@marmaro.de>
parents: 239
diff changeset
177 /* but first ... search in parents for loops: */
244
7082044c05c6 renamed `alias_local_cmp' to `localpartcmp'
markus schnalke <meillo@marmaro.de>
parents: 242
diff changeset
178 if (addr_isequal_parent(addr, alias_addr, conf.localpartcmp)) {
239
31ee44f45787 refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents: 233
diff changeset
179 /* loop detected, ignore this path */
242
bc9d9cd9ee8e made addr_isequal() and addr_isequal_parent() more flexible
markus schnalke <meillo@marmaro.de>
parents: 239
diff changeset
180 logwrite(LOG_ALERT, "alias: detected loop, hence ignoring '%s'\n",
bc9d9cd9ee8e made addr_isequal() and addr_isequal_parent() more flexible
markus schnalke <meillo@marmaro.de>
parents: 239
diff changeset
181 alias_addr->local_part);
239
31ee44f45787 refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents: 233
diff changeset
182 continue;
31ee44f45787 refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents: 233
diff changeset
183 }
31ee44f45787 refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents: 233
diff changeset
184 alias_addr->parent = addr;
0
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
185
239
31ee44f45787 refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents: 233
diff changeset
186 /* recurse */
31ee44f45787 refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents: 233
diff changeset
187 DEBUG(6) debugf("alias: >>\n");
31ee44f45787 refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents: 233
diff changeset
188 alias_node = expand_one(alias_table, alias_addr);
31ee44f45787 refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents: 233
diff changeset
189 DEBUG(6) debugf("alias: <<\n");
31ee44f45787 refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents: 233
diff changeset
190 if (alias_node) {
31ee44f45787 refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents: 233
diff changeset
191 alias_list = g_list_concat(alias_list, alias_node);
31ee44f45787 refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents: 233
diff changeset
192 }
31ee44f45787 refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents: 233
diff changeset
193 }
31ee44f45787 refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents: 233
diff changeset
194 g_list_free(val_list);
31ee44f45787 refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents: 233
diff changeset
195 addr->children = g_list_copy(alias_list);
31ee44f45787 refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents: 233
diff changeset
196
31ee44f45787 refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents: 233
diff changeset
197 return alias_list;
31ee44f45787 refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents: 233
diff changeset
198 }
31ee44f45787 refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents: 233
diff changeset
199
31ee44f45787 refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents: 233
diff changeset
200 GList*
31ee44f45787 refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents: 233
diff changeset
201 alias_expand(GList* alias_table, GList* rcpt_list, GList* non_rcpt_list)
31ee44f45787 refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents: 233
diff changeset
202 {
31ee44f45787 refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents: 233
diff changeset
203 GList *rcpt_node = NULL;
31ee44f45787 refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents: 233
diff changeset
204 GList *alias_list = NULL;
31ee44f45787 refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents: 233
diff changeset
205 GList *done_list = NULL;
31ee44f45787 refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents: 233
diff changeset
206 GList *rcpt_node_next = NULL;
31ee44f45787 refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents: 233
diff changeset
207 address *addr = NULL;
31ee44f45787 refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents: 233
diff changeset
208
31ee44f45787 refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents: 233
diff changeset
209 for (rcpt_node=g_list_copy(rcpt_list);
31ee44f45787 refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents: 233
diff changeset
210 rcpt_node;
31ee44f45787 refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents: 233
diff changeset
211 rcpt_node=g_list_next(rcpt_node)) {
31ee44f45787 refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents: 233
diff changeset
212
31ee44f45787 refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents: 233
diff changeset
213 addr = (address *) (rcpt_node->data);
31ee44f45787 refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents: 233
diff changeset
214 if (addr_is_local(addr)) {
31ee44f45787 refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents: 233
diff changeset
215 DEBUG(5) debugf("alias: (orig rcpt addr) expand local '%s'\n",
31ee44f45787 refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents: 233
diff changeset
216 addr->local_part);
31ee44f45787 refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents: 233
diff changeset
217 alias_list = expand_one(alias_table, addr);
31ee44f45787 refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents: 233
diff changeset
218 if (alias_list) {
31ee44f45787 refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents: 233
diff changeset
219 done_list = g_list_concat(done_list, alias_list);
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
220 }
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
221 } else {
239
31ee44f45787 refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents: 233
diff changeset
222 DEBUG(5) debugf("alias: (orig rcpt addr) don't expand non-local '%s@%s'\n",
31ee44f45787 refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents: 233
diff changeset
223 addr->local_part, addr->domain);
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
224 done_list = g_list_append(done_list, addr);
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
225 }
239
31ee44f45787 refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents: 233
diff changeset
226 }
31ee44f45787 refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents: 233
diff changeset
227
31ee44f45787 refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents: 233
diff changeset
228 /* we're done if we don't have to remove rcpts */
31ee44f45787 refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents: 233
diff changeset
229 if (!non_rcpt_list) {
31ee44f45787 refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents: 233
diff changeset
230 return done_list;
0
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
231 }
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
232
239
31ee44f45787 refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents: 233
diff changeset
233 /* delete addresses of non_rcpt_list from done_list */
31ee44f45787 refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents: 233
diff changeset
234 for (rcpt_node = g_list_first(done_list); rcpt_node; rcpt_node = rcpt_node_next) {
31ee44f45787 refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents: 233
diff changeset
235 address *addr = (address *) (rcpt_node->data);
31ee44f45787 refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents: 233
diff changeset
236 GList *non_node;
0
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
237
239
31ee44f45787 refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents: 233
diff changeset
238 rcpt_node_next = g_list_next(rcpt_node);
31ee44f45787 refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents: 233
diff changeset
239 foreach(non_rcpt_list, non_node) {
31ee44f45787 refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents: 233
diff changeset
240 address *non_addr = (address *) (non_node->data);
244
7082044c05c6 renamed `alias_local_cmp' to `localpartcmp'
markus schnalke <meillo@marmaro.de>
parents: 242
diff changeset
241 if (addr_isequal(addr, non_addr, conf.localpartcmp)) {
239
31ee44f45787 refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents: 233
diff changeset
242 done_list = g_list_remove_link(done_list, rcpt_node);
31ee44f45787 refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents: 233
diff changeset
243 g_list_free_1(rcpt_node);
31ee44f45787 refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents: 233
diff changeset
244 /* this address is still in the children lists
31ee44f45787 refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents: 233
diff changeset
245 of the original address, simply mark them delivered */
31ee44f45787 refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents: 233
diff changeset
246 addr_mark_delivered(addr);
31ee44f45787 refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents: 233
diff changeset
247 break;
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
248 }
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
249 }
0
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
250 }
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
251 return done_list;
0
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
252 }