annotate src/alias.c @ 421:f37384470855

Changed lockdir to /var/lock/masqmail; Create lockdir and piddir on startup. Moved the lockdir out of the spool dir. (When /var/lock is a ramdisk we do well to have the lock files there.) Added the new configure option --with-lockdir to change that location. Nontheless, if we run_as_user, then lock files are always stored in the spool dir directly. Instead of installing the lockdir and piddir at installation time, we create them on startup time now if they are missing. This is necessary if lockdir or piddir are a tmpfs.
author markus schnalke <meillo@marmaro.de>
date Wed, 30 May 2012 09:38:38 +0200
parents ddac877ced95
children
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
390
68ae9182059c Refactoring and code layouting.
markus schnalke <meillo@marmaro.de>
parents: 387
diff changeset
31 if (!addr->domain) {
239
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 */
390
68ae9182059c Refactoring and code layouting.
markus schnalke <meillo@marmaro.de>
parents: 387
diff changeset
36 if (fnmatch(dom_node->data, addr->domain, FNM_CASEFOLD)!=0) {
239
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) {
390
68ae9182059c Refactoring and code layouting.
markus schnalke <meillo@marmaro.de>
parents: 387
diff changeset
41 a = create_address_qualified(addr_node->data, TRUE,
68ae9182059c Refactoring and code layouting.
markus schnalke <meillo@marmaro.de>
parents: 387
diff changeset
42 conf.host_name);
68ae9182059c Refactoring and code layouting.
markus schnalke <meillo@marmaro.de>
parents: 387
diff changeset
43 DEBUG(6) debugf("not_local_addresses: "
68ae9182059c Refactoring and code layouting.
markus schnalke <meillo@marmaro.de>
parents: 387
diff changeset
44 "addr_node->data=%s a->address=%s\n",
239
31ee44f45787 refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents: 233
diff changeset
45 addr_node->data, a->address);
244
7082044c05c6 renamed `alias_local_cmp' to `localpartcmp'
markus schnalke <meillo@marmaro.de>
parents: 242
diff changeset
46 if (addr_isequal(a, addr, conf.localpartcmp)) {
390
68ae9182059c Refactoring and code layouting.
markus schnalke <meillo@marmaro.de>
parents: 387
diff changeset
47 /* also in not_local_addresses */
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
48 destroy_address(a);
239
31ee44f45787 refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents: 233
diff changeset
49 return FALSE;
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 destroy_address(a);
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
52 }
239
31ee44f45787 refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents: 233
diff changeset
53 /* in local_hosts */
31ee44f45787 refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents: 233
diff changeset
54 return TRUE;
0
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
55 }
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
56 foreach(conf.local_addresses, addr_node) {
390
68ae9182059c Refactoring and code layouting.
markus schnalke <meillo@marmaro.de>
parents: 387
diff changeset
57 a = create_address_qualified(addr_node->data, TRUE,
68ae9182059c Refactoring and code layouting.
markus schnalke <meillo@marmaro.de>
parents: 387
diff changeset
58 conf.host_name);
68ae9182059c Refactoring and code layouting.
markus schnalke <meillo@marmaro.de>
parents: 387
diff changeset
59 DEBUG(6) debugf("local_addresses: addr_node->data=%s "
68ae9182059c Refactoring and code layouting.
markus schnalke <meillo@marmaro.de>
parents: 387
diff changeset
60 "a->address=%s\n",
114
a80ebfa16cd5 better debugging output (thanks to Paolo)
meillo@marmaro.de
parents: 14
diff changeset
61 addr_node->data, a->address);
244
7082044c05c6 renamed `alias_local_cmp' to `localpartcmp'
markus schnalke <meillo@marmaro.de>
parents: 242
diff changeset
62 if (addr_isequal(a, addr, conf.localpartcmp)) {
390
68ae9182059c Refactoring and code layouting.
markus schnalke <meillo@marmaro.de>
parents: 387
diff changeset
63 /* in local_addresses */
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
64 destroy_address(a);
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
65 return TRUE;
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
66 }
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
67 destroy_address(a);
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
68 }
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
69 return FALSE;
0
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
70 }
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
71
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
72 static GList*
366
41958685480d Switched to `type *name' style
markus schnalke <meillo@marmaro.de>
parents: 309
diff changeset
73 parse_list(gchar *line)
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 GList *list = NULL;
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
76 gchar buf[256];
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
77 gchar *p, *q;
0
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
78
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
79 p = line;
390
68ae9182059c Refactoring and code layouting.
markus schnalke <meillo@marmaro.de>
parents: 387
diff changeset
80 while (*p) {
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
81 q = buf;
390
68ae9182059c Refactoring and code layouting.
markus schnalke <meillo@marmaro.de>
parents: 387
diff changeset
82 while (isspace(*p)) {
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
83 p++;
390
68ae9182059c Refactoring and code layouting.
markus schnalke <meillo@marmaro.de>
parents: 387
diff changeset
84 }
239
31ee44f45787 refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents: 233
diff changeset
85 if (*p != '"') {
390
68ae9182059c Refactoring and code layouting.
markus schnalke <meillo@marmaro.de>
parents: 387
diff changeset
86 while (*p && (*p != ',') && (q < buf + 255)) {
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
87 *(q++) = *(p++);
390
68ae9182059c Refactoring and code layouting.
markus schnalke <meillo@marmaro.de>
parents: 387
diff changeset
88 }
14
a8f3424347dc replaced number 0 with character \0 where appropriate
meillo@marmaro.de
parents: 10
diff changeset
89 *q = '\0';
10
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 gboolean escape = FALSE;
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
92 p++;
390
68ae9182059c Refactoring and code layouting.
markus schnalke <meillo@marmaro.de>
parents: 387
diff changeset
93 while (*p && (*p != '"' || escape) && (q < buf+255)) {
68ae9182059c Refactoring and code layouting.
markus schnalke <meillo@marmaro.de>
parents: 387
diff changeset
94 if ((*p == '\\') && !escape) {
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
95 escape = TRUE;
390
68ae9182059c Refactoring and code layouting.
markus schnalke <meillo@marmaro.de>
parents: 387
diff changeset
96 } else {
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
97 escape = FALSE;
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
98 *(q++) = *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 p++;
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
101 }
14
a8f3424347dc replaced number 0 with character \0 where appropriate
meillo@marmaro.de
parents: 10
diff changeset
102 *q = '\0';
390
68ae9182059c Refactoring and code layouting.
markus schnalke <meillo@marmaro.de>
parents: 387
diff changeset
103 while (*p && (*p != ',')) {
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
104 p++;
390
68ae9182059c Refactoring and code layouting.
markus schnalke <meillo@marmaro.de>
parents: 387
diff changeset
105 }
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
106 }
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
107 list = g_list_append(list, g_strdup(g_strchomp(buf)));
390
68ae9182059c Refactoring and code layouting.
markus schnalke <meillo@marmaro.de>
parents: 387
diff changeset
108 if (*p) {
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
109 p++;
390
68ae9182059c Refactoring and code layouting.
markus schnalke <meillo@marmaro.de>
parents: 387
diff changeset
110 }
0
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
111 }
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
112 return list;
0
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
113 }
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
114
387
a408411ff8df Added a glob-pattern aliasing facility.
markus schnalke <meillo@marmaro.de>
parents: 376
diff changeset
115 static int
a408411ff8df Added a glob-pattern aliasing facility.
markus schnalke <meillo@marmaro.de>
parents: 376
diff changeset
116 globaliascmp(const char *pattern, const char *addr)
a408411ff8df Added a glob-pattern aliasing facility.
markus schnalke <meillo@marmaro.de>
parents: 376
diff changeset
117 {
390
68ae9182059c Refactoring and code layouting.
markus schnalke <meillo@marmaro.de>
parents: 387
diff changeset
118 if (conf.localpartcmp == strcasecmp) {
387
a408411ff8df Added a glob-pattern aliasing facility.
markus schnalke <meillo@marmaro.de>
parents: 376
diff changeset
119 return fnmatch(pattern, addr, FNM_CASEFOLD);
a408411ff8df Added a glob-pattern aliasing facility.
markus schnalke <meillo@marmaro.de>
parents: 376
diff changeset
120 } else if (strncasecmp(addr, "postmaster", 10)==0) {
390
68ae9182059c Refactoring and code layouting.
markus schnalke <meillo@marmaro.de>
parents: 387
diff changeset
121 /* postmaster must always be matched caseless
68ae9182059c Refactoring and code layouting.
markus schnalke <meillo@marmaro.de>
parents: 387
diff changeset
122 ** see RFC 822 and RFC 5321 */
387
a408411ff8df Added a glob-pattern aliasing facility.
markus schnalke <meillo@marmaro.de>
parents: 376
diff changeset
123 return fnmatch(pattern, addr, FNM_CASEFOLD);
a408411ff8df Added a glob-pattern aliasing facility.
markus schnalke <meillo@marmaro.de>
parents: 376
diff changeset
124 } else {
a408411ff8df Added a glob-pattern aliasing facility.
markus schnalke <meillo@marmaro.de>
parents: 376
diff changeset
125 /* case-sensitive */
a408411ff8df Added a glob-pattern aliasing facility.
markus schnalke <meillo@marmaro.de>
parents: 376
diff changeset
126 return fnmatch(pattern, addr, 0);
a408411ff8df Added a glob-pattern aliasing facility.
markus schnalke <meillo@marmaro.de>
parents: 376
diff changeset
127 }
a408411ff8df Added a glob-pattern aliasing facility.
markus schnalke <meillo@marmaro.de>
parents: 376
diff changeset
128 }
a408411ff8df Added a glob-pattern aliasing facility.
markus schnalke <meillo@marmaro.de>
parents: 376
diff changeset
129
239
31ee44f45787 refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents: 233
diff changeset
130 /*
367
b27f66555ba8 Reformated multiline comments to have leading asterisks on each line
markus schnalke <meillo@marmaro.de>
parents: 366
diff changeset
131 ** 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
132 */
31ee44f45787 refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents: 233
diff changeset
133 static GList*
387
a408411ff8df Added a glob-pattern aliasing facility.
markus schnalke <meillo@marmaro.de>
parents: 376
diff changeset
134 expand_one(GList *alias_table, address *addr, int doglob)
0
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
135 {
239
31ee44f45787 refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents: 233
diff changeset
136 GList *val_list;
31ee44f45787 refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents: 233
diff changeset
137 GList *val_node;
31ee44f45787 refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents: 233
diff changeset
138 GList *alias_list = NULL;
31ee44f45787 refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents: 233
diff changeset
139 GList *alias_node;
31ee44f45787 refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents: 233
diff changeset
140 gchar *val;
416
ddac877ced95 Fixed the globalias mechanism.
markus schnalke <meillo@marmaro.de>
parents: 399
diff changeset
141 char addrstr[BUFSIZ];
ddac877ced95 Fixed the globalias mechanism.
markus schnalke <meillo@marmaro.de>
parents: 399
diff changeset
142
ddac877ced95 Fixed the globalias mechanism.
markus schnalke <meillo@marmaro.de>
parents: 399
diff changeset
143 if (doglob) {
ddac877ced95 Fixed the globalias mechanism.
markus schnalke <meillo@marmaro.de>
parents: 399
diff changeset
144 snprintf(addrstr, sizeof addrstr, "%s@%s",
ddac877ced95 Fixed the globalias mechanism.
markus schnalke <meillo@marmaro.de>
parents: 399
diff changeset
145 addr->local_part, addr->domain);
ddac877ced95 Fixed the globalias mechanism.
markus schnalke <meillo@marmaro.de>
parents: 399
diff changeset
146 } else {
ddac877ced95 Fixed the globalias mechanism.
markus schnalke <meillo@marmaro.de>
parents: 399
diff changeset
147 snprintf(addrstr, sizeof addrstr, "%s", addr->local_part);
ddac877ced95 Fixed the globalias mechanism.
markus schnalke <meillo@marmaro.de>
parents: 399
diff changeset
148 }
0
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
149
239
31ee44f45787 refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents: 233
diff changeset
150 /* expand the local alias */
387
a408411ff8df Added a glob-pattern aliasing facility.
markus schnalke <meillo@marmaro.de>
parents: 376
diff changeset
151 DEBUG(6) debugf("alias: '%s' is local and will get expanded\n",
416
ddac877ced95 Fixed the globalias mechanism.
markus schnalke <meillo@marmaro.de>
parents: 399
diff changeset
152 addrstr);
239
31ee44f45787 refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents: 233
diff changeset
153
387
a408411ff8df Added a glob-pattern aliasing facility.
markus schnalke <meillo@marmaro.de>
parents: 376
diff changeset
154 if (doglob) {
416
ddac877ced95 Fixed the globalias mechanism.
markus schnalke <meillo@marmaro.de>
parents: 399
diff changeset
155 val = (gchar *) table_find_func(alias_table, addrstr,
387
a408411ff8df Added a glob-pattern aliasing facility.
markus schnalke <meillo@marmaro.de>
parents: 376
diff changeset
156 globaliascmp);
a408411ff8df Added a glob-pattern aliasing facility.
markus schnalke <meillo@marmaro.de>
parents: 376
diff changeset
157
a408411ff8df Added a glob-pattern aliasing facility.
markus schnalke <meillo@marmaro.de>
parents: 376
diff changeset
158 } else if (strcasecmp(addr->local_part, "postmaster") == 0) {
390
68ae9182059c Refactoring and code layouting.
markus schnalke <meillo@marmaro.de>
parents: 387
diff changeset
159 /* postmaster must always be matched caseless
68ae9182059c Refactoring and code layouting.
markus schnalke <meillo@marmaro.de>
parents: 387
diff changeset
160 ** see RFC 822 and RFC 5321 */
416
ddac877ced95 Fixed the globalias mechanism.
markus schnalke <meillo@marmaro.de>
parents: 399
diff changeset
161 val = (gchar *) table_find_func(alias_table, addrstr,
387
a408411ff8df Added a glob-pattern aliasing facility.
markus schnalke <meillo@marmaro.de>
parents: 376
diff changeset
162 strcasecmp);
239
31ee44f45787 refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents: 233
diff changeset
163 } else {
416
ddac877ced95 Fixed the globalias mechanism.
markus schnalke <meillo@marmaro.de>
parents: 399
diff changeset
164 val = (gchar *) table_find_func(alias_table, addrstr,
387
a408411ff8df Added a glob-pattern aliasing facility.
markus schnalke <meillo@marmaro.de>
parents: 376
diff changeset
165 conf.localpartcmp);
239
31ee44f45787 refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents: 233
diff changeset
166 }
31ee44f45787 refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents: 233
diff changeset
167 if (!val) {
387
a408411ff8df Added a glob-pattern aliasing facility.
markus schnalke <meillo@marmaro.de>
parents: 376
diff changeset
168 DEBUG(5) debugf("alias: '%s' is fully expanded, hence "
416
ddac877ced95 Fixed the globalias mechanism.
markus schnalke <meillo@marmaro.de>
parents: 399
diff changeset
169 "completed\n", addrstr);
239
31ee44f45787 refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents: 233
diff changeset
170 return g_list_append(NULL, addr);
31ee44f45787 refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents: 233
diff changeset
171 }
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
172
416
ddac877ced95 Fixed the globalias mechanism.
markus schnalke <meillo@marmaro.de>
parents: 399
diff changeset
173 DEBUG(5) debugf("alias: '%s' -> '%s'\n", addrstr, val);
239
31ee44f45787 refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents: 233
diff changeset
174 val_list = parse_list(val);
31ee44f45787 refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents: 233
diff changeset
175 alias_list = NULL;
31ee44f45787 refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents: 233
diff changeset
176
31ee44f45787 refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents: 233
diff changeset
177 foreach(val_list, val_node) {
31ee44f45787 refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents: 233
diff changeset
178 gchar *val = (gchar *) (val_node->data);
31ee44f45787 refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents: 233
diff changeset
179 address *alias_addr;
31ee44f45787 refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents: 233
diff changeset
180
31ee44f45787 refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents: 233
diff changeset
181 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
182
399
c7cc3c03193c Minor refactoring.
markus schnalke <meillo@marmaro.de>
parents: 390
diff changeset
183 if (*val == '\\') {
390
68ae9182059c Refactoring and code layouting.
markus schnalke <meillo@marmaro.de>
parents: 387
diff changeset
184 DEBUG(5) debugf("alias: '%s' is marked as final, "
68ae9182059c Refactoring and code layouting.
markus schnalke <meillo@marmaro.de>
parents: 387
diff changeset
185 "hence completed\n", val);
68ae9182059c Refactoring and code layouting.
markus schnalke <meillo@marmaro.de>
parents: 387
diff changeset
186 alias_addr = create_address_qualified(val+1, TRUE,
68ae9182059c Refactoring and code layouting.
markus schnalke <meillo@marmaro.de>
parents: 387
diff changeset
187 conf.host_name);
239
31ee44f45787 refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents: 233
diff changeset
188 g_free(val);
31ee44f45787 refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents: 233
diff changeset
189 DEBUG(6) debugf("alias: address generated: '%s'\n",
387
a408411ff8df Added a glob-pattern aliasing facility.
markus schnalke <meillo@marmaro.de>
parents: 376
diff changeset
190 alias_addr->address);
239
31ee44f45787 refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents: 233
diff changeset
191 alias_list = g_list_append(alias_list, alias_addr);
31ee44f45787 refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents: 233
diff changeset
192 continue;
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
399
c7cc3c03193c Minor refactoring.
markus schnalke <meillo@marmaro.de>
parents: 390
diff changeset
195 if (*val == '|') {
390
68ae9182059c Refactoring and code layouting.
markus schnalke <meillo@marmaro.de>
parents: 387
diff changeset
196 DEBUG(5) debugf("alias: '%s' is a pipe address\n",
68ae9182059c Refactoring and code layouting.
markus schnalke <meillo@marmaro.de>
parents: 387
diff changeset
197 val);
309
273f6c9eb6a2 bug fix: off-by-one in pipe aliases
meillo@marmaro.de
parents: 244
diff changeset
198 alias_addr = create_address_pipe(val);
239
31ee44f45787 refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents: 233
diff changeset
199 g_free(val);
31ee44f45787 refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents: 233
diff changeset
200 DEBUG(6) debugf("alias: pipe generated: %s\n",
31ee44f45787 refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents: 233
diff changeset
201 alias_addr->local_part);
31ee44f45787 refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents: 233
diff changeset
202 alias_list = g_list_append(alias_list, alias_addr);
31ee44f45787 refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents: 233
diff changeset
203 continue;
31ee44f45787 refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents: 233
diff changeset
204 }
0
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
205
390
68ae9182059c Refactoring and code layouting.
markus schnalke <meillo@marmaro.de>
parents: 387
diff changeset
206 alias_addr = create_address_qualified(val, TRUE,
68ae9182059c Refactoring and code layouting.
markus schnalke <meillo@marmaro.de>
parents: 387
diff changeset
207 conf.host_name);
239
31ee44f45787 refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents: 233
diff changeset
208 g_free(val);
31ee44f45787 refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents: 233
diff changeset
209
31ee44f45787 refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents: 233
diff changeset
210 if (!addr_is_local(alias_addr)) {
390
68ae9182059c Refactoring and code layouting.
markus schnalke <meillo@marmaro.de>
parents: 387
diff changeset
211 DEBUG(5) debugf("alias: '%s' is non-local, "
68ae9182059c Refactoring and code layouting.
markus schnalke <meillo@marmaro.de>
parents: 387
diff changeset
212 "hence completed\n",
387
a408411ff8df Added a glob-pattern aliasing facility.
markus schnalke <meillo@marmaro.de>
parents: 376
diff changeset
213 alias_addr->address);
239
31ee44f45787 refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents: 233
diff changeset
214 alias_list = g_list_append(alias_list, alias_addr);
31ee44f45787 refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents: 233
diff changeset
215 continue;
31ee44f45787 refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents: 233
diff changeset
216 }
31ee44f45787 refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents: 233
diff changeset
217
242
bc9d9cd9ee8e made addr_isequal() and addr_isequal_parent() more flexible
markus schnalke <meillo@marmaro.de>
parents: 239
diff changeset
218 /* 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
219 /* but first ... search in parents for loops: */
244
7082044c05c6 renamed `alias_local_cmp' to `localpartcmp'
markus schnalke <meillo@marmaro.de>
parents: 242
diff changeset
220 if (addr_isequal_parent(addr, alias_addr, conf.localpartcmp)) {
239
31ee44f45787 refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents: 233
diff changeset
221 /* loop detected, ignore this path */
390
68ae9182059c Refactoring and code layouting.
markus schnalke <meillo@marmaro.de>
parents: 387
diff changeset
222 logwrite(LOG_ALERT, "alias: detected loop, "
68ae9182059c Refactoring and code layouting.
markus schnalke <meillo@marmaro.de>
parents: 387
diff changeset
223 "hence ignoring '%s'\n",
416
ddac877ced95 Fixed the globalias mechanism.
markus schnalke <meillo@marmaro.de>
parents: 399
diff changeset
224 alias_addr->address);
239
31ee44f45787 refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents: 233
diff changeset
225 continue;
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 alias_addr->parent = addr;
0
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
228
239
31ee44f45787 refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents: 233
diff changeset
229 /* recurse */
31ee44f45787 refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents: 233
diff changeset
230 DEBUG(6) debugf("alias: >>\n");
387
a408411ff8df Added a glob-pattern aliasing facility.
markus schnalke <meillo@marmaro.de>
parents: 376
diff changeset
231 alias_node = expand_one(alias_table, alias_addr, doglob);
239
31ee44f45787 refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents: 233
diff changeset
232 DEBUG(6) debugf("alias: <<\n");
31ee44f45787 refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents: 233
diff changeset
233 if (alias_node) {
31ee44f45787 refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents: 233
diff changeset
234 alias_list = g_list_concat(alias_list, alias_node);
31ee44f45787 refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents: 233
diff changeset
235 }
31ee44f45787 refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents: 233
diff changeset
236 }
31ee44f45787 refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents: 233
diff changeset
237 g_list_free(val_list);
31ee44f45787 refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents: 233
diff changeset
238 addr->children = g_list_copy(alias_list);
31ee44f45787 refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents: 233
diff changeset
239
31ee44f45787 refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents: 233
diff changeset
240 return alias_list;
31ee44f45787 refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents: 233
diff changeset
241 }
31ee44f45787 refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents: 233
diff changeset
242
31ee44f45787 refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents: 233
diff changeset
243 GList*
387
a408411ff8df Added a glob-pattern aliasing facility.
markus schnalke <meillo@marmaro.de>
parents: 376
diff changeset
244 alias_expand(GList *alias_table, GList *rcpt_list, GList *non_rcpt_list,
a408411ff8df Added a glob-pattern aliasing facility.
markus schnalke <meillo@marmaro.de>
parents: 376
diff changeset
245 int doglob)
239
31ee44f45787 refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents: 233
diff changeset
246 {
31ee44f45787 refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents: 233
diff changeset
247 GList *rcpt_node = NULL;
31ee44f45787 refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents: 233
diff changeset
248 GList *alias_list = NULL;
31ee44f45787 refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents: 233
diff changeset
249 GList *done_list = NULL;
31ee44f45787 refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents: 233
diff changeset
250 GList *rcpt_node_next = NULL;
31ee44f45787 refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents: 233
diff changeset
251 address *addr = NULL;
31ee44f45787 refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents: 233
diff changeset
252
399
c7cc3c03193c Minor refactoring.
markus schnalke <meillo@marmaro.de>
parents: 390
diff changeset
253 for (rcpt_node=g_list_copy(rcpt_list); rcpt_node;
c7cc3c03193c Minor refactoring.
markus schnalke <meillo@marmaro.de>
parents: 390
diff changeset
254 rcpt_node=g_list_next(rcpt_node)) {
239
31ee44f45787 refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents: 233
diff changeset
255
31ee44f45787 refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents: 233
diff changeset
256 addr = (address *) (rcpt_node->data);
31ee44f45787 refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents: 233
diff changeset
257 if (addr_is_local(addr)) {
416
ddac877ced95 Fixed the globalias mechanism.
markus schnalke <meillo@marmaro.de>
parents: 399
diff changeset
258 DEBUG(5) debugf("alias: expand local '%s' "
ddac877ced95 Fixed the globalias mechanism.
markus schnalke <meillo@marmaro.de>
parents: 399
diff changeset
259 "(orig rcpt addr)\n", addr->address);
387
a408411ff8df Added a glob-pattern aliasing facility.
markus schnalke <meillo@marmaro.de>
parents: 376
diff changeset
260 alias_list = expand_one(alias_table, addr, doglob);
239
31ee44f45787 refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents: 233
diff changeset
261 if (alias_list) {
390
68ae9182059c Refactoring and code layouting.
markus schnalke <meillo@marmaro.de>
parents: 387
diff changeset
262 done_list = g_list_concat(done_list,
68ae9182059c Refactoring and code layouting.
markus schnalke <meillo@marmaro.de>
parents: 387
diff changeset
263 alias_list);
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
264 }
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
265 } else {
416
ddac877ced95 Fixed the globalias mechanism.
markus schnalke <meillo@marmaro.de>
parents: 399
diff changeset
266 DEBUG(5) debugf("alias: don't expand non-local '%s' "
ddac877ced95 Fixed the globalias mechanism.
markus schnalke <meillo@marmaro.de>
parents: 399
diff changeset
267 "(orig rcpt addr)\n", addr->address);
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
268 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
269 }
239
31ee44f45787 refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents: 233
diff changeset
270 }
31ee44f45787 refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents: 233
diff changeset
271
31ee44f45787 refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents: 233
diff changeset
272 /* 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
273 if (!non_rcpt_list) {
31ee44f45787 refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents: 233
diff changeset
274 return done_list;
0
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
275 }
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
276
239
31ee44f45787 refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents: 233
diff changeset
277 /* delete addresses of non_rcpt_list from done_list */
390
68ae9182059c Refactoring and code layouting.
markus schnalke <meillo@marmaro.de>
parents: 387
diff changeset
278 for (rcpt_node = g_list_first(done_list); rcpt_node;
68ae9182059c Refactoring and code layouting.
markus schnalke <meillo@marmaro.de>
parents: 387
diff changeset
279 rcpt_node = rcpt_node_next) {
239
31ee44f45787 refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents: 233
diff changeset
280 address *addr = (address *) (rcpt_node->data);
31ee44f45787 refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents: 233
diff changeset
281 GList *non_node;
0
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
282
239
31ee44f45787 refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents: 233
diff changeset
283 rcpt_node_next = g_list_next(rcpt_node);
31ee44f45787 refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents: 233
diff changeset
284 foreach(non_rcpt_list, non_node) {
31ee44f45787 refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents: 233
diff changeset
285 address *non_addr = (address *) (non_node->data);
244
7082044c05c6 renamed `alias_local_cmp' to `localpartcmp'
markus schnalke <meillo@marmaro.de>
parents: 242
diff changeset
286 if (addr_isequal(addr, non_addr, conf.localpartcmp)) {
390
68ae9182059c Refactoring and code layouting.
markus schnalke <meillo@marmaro.de>
parents: 387
diff changeset
287 done_list = g_list_remove_link(done_list,
68ae9182059c Refactoring and code layouting.
markus schnalke <meillo@marmaro.de>
parents: 387
diff changeset
288 rcpt_node);
239
31ee44f45787 refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents: 233
diff changeset
289 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
290 /*
b27f66555ba8 Reformated multiline comments to have leading asterisks on each line
markus schnalke <meillo@marmaro.de>
parents: 366
diff changeset
291 ** 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
292 ** 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
293 ** mark them delivered
b27f66555ba8 Reformated multiline comments to have leading asterisks on each line
markus schnalke <meillo@marmaro.de>
parents: 366
diff changeset
294 */
239
31ee44f45787 refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents: 233
diff changeset
295 addr_mark_delivered(addr);
31ee44f45787 refactored alias.c heavily
markus schnalke <meillo@marmaro.de>
parents: 233
diff changeset
296 break;
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
297 }
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
298 }
0
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
299 }
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
300 return done_list;
0
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
301 }