annotate src/alias.c @ 371:f122535c589e

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