rev |
line source |
meillo@0
|
1 /* MasqMail
|
meillo@0
|
2 Copyright (C) 1999-2001 Oliver Kurth
|
meillo@0
|
3
|
meillo@0
|
4 This program is free software; you can redistribute it and/or modify
|
meillo@0
|
5 it under the terms of the GNU General Public License as published by
|
meillo@0
|
6 the Free Software Foundation; either version 2 of the License, or
|
meillo@0
|
7 (at your option) any later version.
|
meillo@0
|
8
|
meillo@0
|
9 This program is distributed in the hope that it will be useful,
|
meillo@0
|
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
|
meillo@0
|
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
meillo@0
|
12 GNU General Public License for more details.
|
meillo@0
|
13
|
meillo@0
|
14 You should have received a copy of the GNU General Public License
|
meillo@0
|
15 along with this program; if not, write to the Free Software
|
meillo@0
|
16 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
meillo@0
|
17 */
|
meillo@0
|
18
|
meillo@0
|
19 #include "masqmail.h"
|
meillo@0
|
20
|
meillo@0
|
21 #include "pwd.h"
|
meillo@0
|
22 #include "grp.h"
|
meillo@0
|
23
|
meillo@0
|
24 masqmail_conf conf;
|
meillo@0
|
25
|
meillo@0
|
26 void init_conf()
|
meillo@0
|
27 {
|
meillo@0
|
28 struct passwd *passwd;
|
meillo@0
|
29 struct group *group;
|
meillo@0
|
30
|
meillo@0
|
31 memset(&conf, 0, sizeof(masqmail_conf));
|
meillo@0
|
32
|
meillo@0
|
33 conf.orig_uid = getuid();
|
meillo@0
|
34 conf.orig_gid = getgid();
|
meillo@0
|
35
|
meillo@0
|
36 if((passwd = getpwnam(DEF_MAIL_USER)))
|
meillo@0
|
37 conf.mail_uid = passwd->pw_uid;
|
meillo@0
|
38 else{
|
meillo@0
|
39 fprintf(stderr, "user %s not found! (terminating)\n", DEF_MAIL_USER);
|
meillo@0
|
40 exit(EXIT_FAILURE);
|
meillo@0
|
41 }
|
meillo@0
|
42 if((group = getgrnam(DEF_MAIL_GROUP)))
|
meillo@0
|
43 conf.mail_gid = group->gr_gid;
|
meillo@0
|
44 else{
|
meillo@0
|
45 fprintf(stderr, "group %s not found! (terminating)\n", DEF_MAIL_GROUP);
|
meillo@0
|
46 exit(EXIT_FAILURE);
|
meillo@0
|
47 }
|
meillo@0
|
48 }
|
meillo@0
|
49
|
meillo@0
|
50 static gchar *true_strings[] =
|
meillo@0
|
51 {
|
meillo@0
|
52 "yes", "on", "true", NULL
|
meillo@0
|
53 };
|
meillo@0
|
54
|
meillo@0
|
55 static gchar *false_strings[] =
|
meillo@0
|
56 {
|
meillo@0
|
57 "no", "off", "false", NULL
|
meillo@0
|
58 };
|
meillo@0
|
59
|
meillo@0
|
60 static
|
meillo@0
|
61 gboolean parse_boolean(gchar *rval)
|
meillo@0
|
62 {
|
meillo@0
|
63 gchar **str;
|
meillo@0
|
64
|
meillo@0
|
65 DEBUG(6) fprintf(stderr, "parse_boolean: %s\n", rval);
|
meillo@0
|
66
|
meillo@0
|
67 str = true_strings;
|
meillo@0
|
68 while(*str){
|
meillo@0
|
69 if(strncasecmp(*str, rval, strlen(*str)) == 0)
|
meillo@0
|
70 return TRUE;
|
meillo@0
|
71 str++;
|
meillo@0
|
72 }
|
meillo@0
|
73
|
meillo@0
|
74 str = false_strings;
|
meillo@0
|
75 while(*str){
|
meillo@0
|
76 if(strncasecmp(*str, rval, strlen(*str)) == 0)
|
meillo@0
|
77 return FALSE;
|
meillo@0
|
78 str++;
|
meillo@0
|
79 }
|
meillo@0
|
80
|
meillo@0
|
81 fprintf(stderr, "cannot parse value '%s'\n", rval);
|
meillo@0
|
82 exit(EXIT_FAILURE);
|
meillo@0
|
83 }
|
meillo@0
|
84
|
meillo@0
|
85 /* make a list from each line in a file */
|
meillo@0
|
86 static
|
meillo@0
|
87 GList *parse_list_file(gchar *fname)
|
meillo@0
|
88 {
|
meillo@0
|
89 GList *list = NULL;
|
meillo@0
|
90 FILE *fptr;
|
meillo@0
|
91
|
meillo@0
|
92 if((fptr = fopen(fname, "rt"))){
|
meillo@0
|
93 gchar buf[256];
|
meillo@0
|
94
|
meillo@0
|
95 while(!feof(fptr)){
|
meillo@0
|
96 fgets(buf, 255, fptr);
|
meillo@0
|
97 if(buf[0] && (buf[0] != '#') && (buf[0] != '\n')){
|
meillo@0
|
98 g_strchomp(buf);
|
meillo@0
|
99 list = g_list_append(list, g_strdup(buf));
|
meillo@0
|
100 }
|
meillo@0
|
101 }
|
meillo@0
|
102 fclose(fptr);
|
meillo@0
|
103 }else{
|
meillo@0
|
104 logwrite(LOG_ALERT, "could not open %s for reading: %s\n", fname, strerror(errno));
|
meillo@0
|
105 exit(EXIT_FAILURE);
|
meillo@0
|
106 }
|
meillo@0
|
107
|
meillo@0
|
108 return list;
|
meillo@0
|
109 }
|
meillo@0
|
110
|
meillo@0
|
111 /* given a semicolon separated string, this function
|
meillo@0
|
112 makes a GList out of it.
|
meillo@0
|
113 */
|
meillo@0
|
114 GList *parse_list(gchar *line, gboolean read_file)
|
meillo@0
|
115 {
|
meillo@0
|
116 GList *list = NULL;
|
meillo@0
|
117 gchar buf[256];
|
meillo@0
|
118 gchar *p, *q;
|
meillo@0
|
119
|
meillo@0
|
120 DEBUG(6) fprintf(stderr, "parsing list %s\n", line);
|
meillo@0
|
121
|
meillo@0
|
122 p = line;
|
meillo@0
|
123 while(*p != 0){
|
meillo@0
|
124 q = buf;
|
meillo@0
|
125
|
meillo@0
|
126 while(*p && (*p != ';') && (q < buf+255))
|
meillo@0
|
127 *(q++) = *(p++);
|
meillo@0
|
128 *q = 0;
|
meillo@0
|
129
|
meillo@0
|
130 if((buf[0] == '/') && (read_file))
|
meillo@0
|
131 /* item is a filename, include its contents */
|
meillo@0
|
132 list = g_list_concat(list, parse_list_file(buf));
|
meillo@0
|
133 else
|
meillo@0
|
134 /* just a normal item */
|
meillo@0
|
135 list = g_list_append(list, g_strdup(buf));
|
meillo@0
|
136
|
meillo@0
|
137 DEBUG(6) printf("item = %s\n", buf);
|
meillo@0
|
138
|
meillo@0
|
139 if(*p) p++;
|
meillo@0
|
140 }
|
meillo@0
|
141 return list;
|
meillo@0
|
142 }
|
meillo@0
|
143
|
meillo@0
|
144 static
|
meillo@0
|
145 GList *parse_address_list(gchar *line, gboolean read_file)
|
meillo@0
|
146 {
|
meillo@0
|
147 GList *plain_list = parse_list(line, read_file);
|
meillo@0
|
148 GList *node;
|
meillo@0
|
149 GList *list = NULL;
|
meillo@0
|
150
|
meillo@0
|
151 foreach(plain_list, node){
|
meillo@0
|
152 gchar *item = (gchar *)(node->data);
|
meillo@0
|
153 address *addr = create_address(item, TRUE);
|
meillo@0
|
154 if(addr)
|
meillo@0
|
155 list = g_list_append(list, addr);
|
meillo@0
|
156 g_free(item);
|
meillo@0
|
157 }
|
meillo@0
|
158 g_list_free(plain_list);
|
meillo@0
|
159
|
meillo@0
|
160 return list;
|
meillo@0
|
161 }
|
meillo@0
|
162
|
meillo@0
|
163 static
|
meillo@0
|
164 GList *parse_resolve_list(gchar *line)
|
meillo@0
|
165 {
|
meillo@0
|
166 GList *list;
|
meillo@0
|
167 GList *list_node;
|
meillo@0
|
168 GList *res_list = NULL;
|
meillo@0
|
169
|
meillo@0
|
170 list = parse_list(line, FALSE);
|
meillo@0
|
171 if(list){
|
meillo@0
|
172 foreach(list, list_node){
|
meillo@0
|
173 gchar *item = (gchar *)(list_node->data);
|
meillo@0
|
174 if(strcmp(item, "byname") == 0){
|
meillo@0
|
175 res_list = g_list_append(res_list, resolve_byname);
|
meillo@0
|
176 #ifdef ENABLE_RESOLVER
|
meillo@0
|
177 }else if(strcmp(item, "dns_a") == 0){
|
meillo@0
|
178 res_list = g_list_append(res_list, resolve_dns_a);
|
meillo@0
|
179 }else if(strcmp(item, "dns_mx") == 0){
|
meillo@0
|
180 res_list = g_list_append(res_list, resolve_dns_mx);
|
meillo@0
|
181 #endif
|
meillo@0
|
182 }else{
|
meillo@0
|
183 logwrite(LOG_ALERT, "unknown resolver %s\n", item);
|
meillo@0
|
184 exit(EXIT_FAILURE);
|
meillo@0
|
185 }
|
meillo@0
|
186 g_free(item);
|
meillo@0
|
187 }
|
meillo@0
|
188 g_list_free(list);
|
meillo@0
|
189 }
|
meillo@0
|
190 return res_list;
|
meillo@0
|
191 }
|
meillo@0
|
192
|
meillo@0
|
193 static
|
meillo@0
|
194 interface *parse_interface(gchar *line, gint def_port)
|
meillo@0
|
195 {
|
meillo@0
|
196 gchar buf[256];
|
meillo@0
|
197 gchar *p, *q;
|
meillo@0
|
198 interface *iface;
|
meillo@0
|
199
|
meillo@0
|
200 DEBUG(6) fprintf(stderr, "parse_interface: %s\n", line);
|
meillo@0
|
201
|
meillo@0
|
202 p = line;
|
meillo@0
|
203 q = buf;
|
meillo@0
|
204 while((*p != 0) && (*p != ':') && (q < buf+255))
|
meillo@0
|
205 *(q++) = *(p++);
|
meillo@0
|
206 *q = 0;
|
meillo@0
|
207
|
meillo@0
|
208 iface = g_malloc(sizeof(interface));
|
meillo@0
|
209 iface->address = g_strdup(buf);
|
meillo@0
|
210
|
meillo@0
|
211 if(*p){
|
meillo@0
|
212 p++;
|
meillo@0
|
213 iface->port = atoi(p);
|
meillo@0
|
214 }else
|
meillo@0
|
215 iface->port = def_port;
|
meillo@0
|
216
|
meillo@0
|
217 return iface;
|
meillo@0
|
218 }
|
meillo@0
|
219
|
meillo@0
|
220 #ifdef ENABLE_IDENT /* so far used for that only */
|
meillo@0
|
221 static
|
meillo@0
|
222 struct in_addr *parse_network(gchar *line, gint def_port)
|
meillo@0
|
223 {
|
meillo@0
|
224 gchar buf[256];
|
meillo@0
|
225 gchar *p, *q;
|
meillo@0
|
226 struct in_addr addr, mask_addr, net_addr, *p_net_addr;
|
meillo@0
|
227 guint n;
|
meillo@0
|
228
|
meillo@0
|
229 DEBUG(6) fprintf(stderr, "parse_network: %s\n", line);
|
meillo@0
|
230
|
meillo@0
|
231 p = line;
|
meillo@0
|
232 q = buf;
|
meillo@0
|
233 while((*p != 0) && (*p != '/') && (q < buf+255))
|
meillo@0
|
234 *(q++) = *(p++);
|
meillo@0
|
235 *q = 0;
|
meillo@0
|
236
|
meillo@0
|
237 if((addr.s_addr = inet_addr(buf)) != INADDR_NONE){
|
meillo@0
|
238 if(*p){
|
meillo@0
|
239 guint i;
|
meillo@0
|
240 p++;
|
meillo@0
|
241 i = atoi(p);
|
meillo@0
|
242 if((i >= 0) && (i <= 32))
|
meillo@0
|
243 n = i ? ~((1 << (32 - i)) - 1) : 0;
|
meillo@0
|
244 else{
|
meillo@0
|
245 fprintf(stderr, "'%d' is not a valid net mask (must be >= 0 and <= 32)\n", i);
|
meillo@0
|
246 exit(EXIT_FAILURE);
|
meillo@0
|
247 }
|
meillo@0
|
248 }else
|
meillo@0
|
249 n = 0;
|
meillo@0
|
250
|
meillo@0
|
251 mask_addr.s_addr = htonl(n);
|
meillo@0
|
252 net_addr.s_addr = mask_addr.s_addr & addr.s_addr;
|
meillo@0
|
253 }else{
|
meillo@0
|
254 fprintf(stderr, "'%s' is not a valid address (must be ip)\n", buf);
|
meillo@0
|
255 exit(EXIT_FAILURE);
|
meillo@0
|
256 }
|
meillo@0
|
257
|
meillo@0
|
258 p_net_addr = g_malloc(sizeof(struct in_addr));
|
meillo@0
|
259 p_net_addr->s_addr = net_addr.s_addr;
|
meillo@0
|
260 return p_net_addr;
|
meillo@0
|
261 }
|
meillo@0
|
262 #endif
|
meillo@0
|
263
|
meillo@0
|
264 static
|
meillo@0
|
265 gboolean eat_comments(FILE *in)
|
meillo@0
|
266 {
|
meillo@0
|
267 gint c;
|
meillo@0
|
268
|
meillo@0
|
269 for(c = fgetc(in); (c == '#' || isspace(c)) && c != EOF; c = fgetc(in)){
|
meillo@0
|
270 if(c == '#'){
|
meillo@0
|
271 gint c;
|
meillo@0
|
272 for(c = fgetc(in); (c != '\n') && (c != EOF); c = fgetc(in));
|
meillo@0
|
273 }
|
meillo@0
|
274 }
|
meillo@0
|
275 if(c == EOF) return FALSE;
|
meillo@0
|
276 ungetc(c, in);
|
meillo@0
|
277 return TRUE;
|
meillo@0
|
278 }
|
meillo@0
|
279
|
meillo@0
|
280 /* after parsing, eat trailing character until LF */
|
meillo@0
|
281 static
|
meillo@0
|
282 gboolean eat_line_trailing(FILE *in)
|
meillo@0
|
283 {
|
meillo@0
|
284 gint c;
|
meillo@0
|
285
|
meillo@0
|
286 for(c = fgetc(in); c != EOF && c != '\n'; c = fgetc(in));
|
meillo@0
|
287 if(c == EOF) return FALSE;
|
meillo@0
|
288 return TRUE;
|
meillo@0
|
289 }
|
meillo@0
|
290
|
meillo@0
|
291 static
|
meillo@0
|
292 gboolean eat_spaces(FILE *in)
|
meillo@0
|
293 {
|
meillo@0
|
294 gint c;
|
meillo@0
|
295
|
meillo@0
|
296 for(c = fgetc(in); c != EOF && isspace(c); c = fgetc(in));
|
meillo@0
|
297 if(c == EOF) return FALSE;
|
meillo@0
|
298 ungetc(c, in);
|
meillo@0
|
299 return TRUE;
|
meillo@0
|
300 }
|
meillo@0
|
301
|
meillo@0
|
302 static
|
meillo@0
|
303 gboolean read_lval(FILE *in, gchar *buf, gint size)
|
meillo@0
|
304 {
|
meillo@0
|
305 gint c;
|
meillo@0
|
306 gchar *ptr = buf;
|
meillo@0
|
307
|
meillo@0
|
308 DEBUG(6) fprintf(stderr, "read_lval()\n");
|
meillo@0
|
309
|
meillo@0
|
310 if(!eat_spaces(in)) return FALSE;
|
meillo@0
|
311
|
meillo@0
|
312 c = fgetc(in);
|
meillo@0
|
313 DEBUG(6) fprintf(stderr, "read_lval() 2\n");
|
meillo@0
|
314 while((isalnum(c) || c == '_' || c == '-' || c == '.')
|
meillo@0
|
315 && (ptr < buf+size-1)
|
meillo@0
|
316 && (c != EOF)
|
meillo@0
|
317 ){
|
meillo@0
|
318 *ptr = c; ptr++;
|
meillo@0
|
319 c = fgetc(in);
|
meillo@0
|
320 }
|
meillo@0
|
321 *ptr = 0;
|
meillo@0
|
322 ungetc(c, in);
|
meillo@0
|
323
|
meillo@0
|
324 if(c == EOF){
|
meillo@0
|
325 fprintf(stderr, "unexpected EOF after %s\n", buf);
|
meillo@0
|
326 return FALSE;
|
meillo@0
|
327 }else if(ptr >= buf+size-1){
|
meillo@0
|
328 fprintf(stderr, "lval too long\n");
|
meillo@0
|
329 }
|
meillo@0
|
330
|
meillo@0
|
331 eat_spaces(in);
|
meillo@0
|
332
|
meillo@0
|
333 DEBUG(6) fprintf(stderr, "lval = %s\n", buf);
|
meillo@0
|
334
|
meillo@0
|
335 return buf[0] != 0;
|
meillo@0
|
336 }
|
meillo@0
|
337
|
meillo@0
|
338 static
|
meillo@0
|
339 gboolean read_rval(FILE *in, gchar *buf, gint size)
|
meillo@0
|
340 {
|
meillo@0
|
341 gint c;
|
meillo@0
|
342 gchar *ptr = buf;
|
meillo@0
|
343
|
meillo@0
|
344 DEBUG(6) fprintf(stderr, "read_rval()\n");
|
meillo@0
|
345
|
meillo@0
|
346 if(!eat_spaces(in)) return FALSE;
|
meillo@0
|
347
|
meillo@0
|
348 c = fgetc(in);
|
meillo@0
|
349 if(c != '\"'){
|
meillo@0
|
350 while((isalnum(c) || c == '_' || c == '-' || c == '.' || c == '/' || c == '@' || c == ';')
|
meillo@0
|
351 && (ptr < buf+size-1)
|
meillo@0
|
352 && (c != EOF)
|
meillo@0
|
353 ){
|
meillo@0
|
354 *ptr = c; ptr++;
|
meillo@0
|
355 c = fgetc(in);
|
meillo@0
|
356 }
|
meillo@0
|
357 *ptr = 0;
|
meillo@0
|
358 ungetc(c, in);
|
meillo@0
|
359 }else{
|
meillo@0
|
360 gboolean escape = FALSE;
|
meillo@0
|
361 c = fgetc(in);
|
meillo@0
|
362 while(((c != '\"') || escape) && (ptr < buf+size-1)){
|
meillo@0
|
363 if(c != '\n'){ /* ignore line breaks */
|
meillo@0
|
364 if((c == '\\') && (!escape)){
|
meillo@0
|
365 escape = TRUE;
|
meillo@0
|
366 }else{
|
meillo@0
|
367 *ptr = c; ptr++;
|
meillo@0
|
368 escape = FALSE;
|
meillo@0
|
369 }
|
meillo@0
|
370 }
|
meillo@0
|
371 c = fgetc(in);
|
meillo@0
|
372 }
|
meillo@0
|
373 *ptr = 0;
|
meillo@0
|
374 }
|
meillo@0
|
375
|
meillo@0
|
376 eat_line_trailing(in);
|
meillo@0
|
377
|
meillo@0
|
378 DEBUG(6) fprintf(stderr, "rval = %s\n", buf);
|
meillo@0
|
379
|
meillo@0
|
380 return TRUE;
|
meillo@0
|
381 }
|
meillo@0
|
382
|
meillo@0
|
383 static
|
meillo@0
|
384 gboolean read_statement(FILE *in,
|
meillo@0
|
385 gchar *lval, gint lsize,
|
meillo@0
|
386 gchar *rval, gint rsize)
|
meillo@0
|
387 {
|
meillo@0
|
388 gint c;
|
meillo@0
|
389
|
meillo@0
|
390 DEBUG(6) fprintf(stderr, "read_statement()\n");
|
meillo@0
|
391
|
meillo@0
|
392 /* eat comments and empty lines: */
|
meillo@0
|
393 if(!eat_comments(in)) return FALSE;
|
meillo@0
|
394
|
meillo@0
|
395 DEBUG(6) fprintf(stderr, "read_statement() 1\n");
|
meillo@0
|
396
|
meillo@0
|
397 if(read_lval(in, lval, lsize)){
|
meillo@0
|
398 DEBUG(6) fprintf(stderr, "lval = %s\n", lval);
|
meillo@0
|
399 if((c = fgetc(in) == '=')){
|
meillo@0
|
400 if(read_rval(in, rval, rsize)){
|
meillo@0
|
401 DEBUG(6) fprintf(stderr, "rval = %s\n", rval);
|
meillo@0
|
402 return TRUE;
|
meillo@0
|
403 }
|
meillo@0
|
404 }else{
|
meillo@0
|
405 fprintf(stderr, "'=' expected after %s, char was '%c'\n", lval, c);
|
meillo@0
|
406 }
|
meillo@0
|
407 }
|
meillo@0
|
408 return FALSE;
|
meillo@0
|
409 }
|
meillo@0
|
410
|
meillo@0
|
411 gboolean read_conf(gchar *filename)
|
meillo@0
|
412 {
|
meillo@0
|
413 FILE *in;
|
meillo@0
|
414
|
meillo@0
|
415 conf.log_max_pri = 7;
|
meillo@0
|
416
|
meillo@0
|
417 conf.remote_port = 25;
|
meillo@0
|
418
|
meillo@0
|
419 conf.do_relay = TRUE;
|
meillo@0
|
420
|
meillo@0
|
421 conf.alias_local_cmp = strcmp;
|
meillo@0
|
422
|
meillo@0
|
423 conf.max_defer_time = 86400*4; /* 4 days */
|
meillo@0
|
424
|
meillo@0
|
425 if((in = fopen(filename, "r"))){
|
meillo@0
|
426 gchar lval[256], rval[2048];
|
meillo@0
|
427 while(read_statement(in, lval, 256, rval, 2048)){
|
meillo@0
|
428 if(strcmp(lval, "debug_level") == 0)
|
meillo@0
|
429 conf.debug_level = atoi(rval);
|
meillo@0
|
430 else if(strcmp(lval, "run_as_user") == 0){
|
meillo@0
|
431 if(!conf.run_as_user) /* you should not be able
|
meillo@0
|
432 to reset that flag */
|
meillo@0
|
433 conf.run_as_user = parse_boolean(rval);
|
meillo@0
|
434 }else if(strcmp(lval, "use_syslog") == 0)
|
meillo@0
|
435 conf.use_syslog = parse_boolean(rval);
|
meillo@0
|
436 else if(strcmp(lval, "mail_dir") == 0)
|
meillo@0
|
437 conf.mail_dir = g_strdup(rval);
|
meillo@0
|
438 else if(strcmp(lval, "lock_dir") == 0)
|
meillo@0
|
439 conf.lock_dir = g_strdup(rval);
|
meillo@0
|
440 else if(strcmp(lval, "spool_dir") == 0)
|
meillo@0
|
441 conf.spool_dir = g_strdup(rval);
|
meillo@0
|
442 else if(strcmp(lval, "log_dir") == 0)
|
meillo@0
|
443 conf.log_dir = g_strdup(rval);
|
meillo@0
|
444 else if(strcmp(lval, "host_name") == 0){
|
meillo@0
|
445 if(rval[0] != '/')
|
meillo@0
|
446 conf.host_name = g_strdup(rval);
|
meillo@0
|
447 else{
|
meillo@0
|
448 char buf[256];
|
meillo@0
|
449 FILE *fptr = fopen(rval, "rt");
|
meillo@0
|
450 if(fptr){
|
meillo@0
|
451 fgets(buf, 255, fptr);
|
meillo@0
|
452 g_strchomp(buf);
|
meillo@0
|
453 conf.host_name = g_strdup(buf);
|
meillo@0
|
454 fclose(fptr);
|
meillo@0
|
455 }else{
|
meillo@0
|
456 fprintf(stderr, "could not open %s: %s\n", rval, strerror(errno));
|
meillo@0
|
457 return FALSE;
|
meillo@0
|
458 }
|
meillo@0
|
459 }
|
meillo@0
|
460 }
|
meillo@0
|
461 else if(strcmp(lval, "remote_port") == 0){
|
meillo@0
|
462 fprintf(stderr,
|
meillo@0
|
463 "the remote_port option is now deprecated. Use 'mail_host' in the\n"
|
meillo@0
|
464 "route configuration instead. See man masqmail.route\n");
|
meillo@0
|
465 conf.remote_port = atoi(rval);
|
meillo@0
|
466 }else if(strcmp(lval, "local_hosts") == 0)
|
meillo@0
|
467 conf.local_hosts = parse_list(rval, FALSE);
|
meillo@0
|
468 else if(strcmp(lval, "local_addresses") == 0)
|
meillo@0
|
469 conf.local_addresses = parse_list(rval, TRUE);
|
meillo@0
|
470 else if(strcmp(lval, "not_local_addresses") == 0)
|
meillo@0
|
471 conf.not_local_addresses = parse_list(rval, TRUE);
|
meillo@0
|
472 else if(strcmp(lval, "local_nets") == 0)
|
meillo@0
|
473 conf.local_nets = parse_list(rval, FALSE);
|
meillo@0
|
474 else if(strcmp(lval, "do_save_envelope_to") == 0)
|
meillo@0
|
475 conf.do_save_envelope_to = parse_boolean(rval);
|
meillo@0
|
476 else if(strcmp(lval, "defer_all") == 0)
|
meillo@0
|
477 conf.defer_all = parse_boolean(rval);
|
meillo@0
|
478 else if(strcmp(lval, "do_relay") == 0)
|
meillo@0
|
479 conf.do_relay = parse_boolean(rval);
|
meillo@0
|
480 else if(strcmp(lval, "alias_file") == 0){
|
meillo@0
|
481 conf.alias_file = g_strdup(rval);
|
meillo@0
|
482 }else if(strcmp(lval, "alias_local_caseless") == 0){
|
meillo@0
|
483 conf.alias_local_cmp = parse_boolean(rval) ? strcasecmp : strcmp;
|
meillo@0
|
484 }else if(strcmp(lval, "mbox_default") == 0){
|
meillo@0
|
485 conf.mbox_default = g_strdup(rval);
|
meillo@0
|
486 }else if(strcmp(lval, "mbox_users") == 0){
|
meillo@0
|
487 conf.mbox_users = parse_list(rval, TRUE);
|
meillo@0
|
488 }else if(strcmp(lval, "mda_users") == 0){
|
meillo@0
|
489 conf.mda_users = parse_list(rval, TRUE);
|
meillo@0
|
490 }else if(strcmp(lval, "maildir_users") == 0){
|
meillo@0
|
491 conf.maildir_users = parse_list(rval, TRUE);
|
meillo@0
|
492 }else if(strcmp(lval, "mda") == 0){
|
meillo@0
|
493 conf.mda = g_strdup(rval);
|
meillo@0
|
494 }else if(strcmp(lval, "mda_fromline") == 0){
|
meillo@0
|
495 conf.mda_fromline = parse_boolean(rval);
|
meillo@0
|
496 }else if(strcmp(lval, "mda_fromhack") == 0){
|
meillo@0
|
497 conf.mda_fromhack = parse_boolean(rval);
|
meillo@0
|
498 }else if(strcmp(lval, "pipe_fromline") == 0){
|
meillo@0
|
499 conf.pipe_fromline = parse_boolean(rval);
|
meillo@0
|
500 }else if(strcmp(lval, "pipe_fromhack") == 0){
|
meillo@0
|
501 conf.pipe_fromhack = parse_boolean(rval);
|
meillo@0
|
502 }else if(strcmp(lval, "listen_addresses") == 0){
|
meillo@0
|
503 GList *node;
|
meillo@0
|
504 GList *tmp_list = parse_list(rval, FALSE);
|
meillo@0
|
505
|
meillo@0
|
506 conf.listen_addresses = NULL;
|
meillo@0
|
507 foreach(tmp_list, node){
|
meillo@0
|
508 conf.listen_addresses =
|
meillo@0
|
509 g_list_append(conf.listen_addresses,
|
meillo@0
|
510 parse_interface((gchar *)(node->data), 25));
|
meillo@0
|
511 g_free(node->data);
|
meillo@0
|
512 }
|
meillo@0
|
513 g_list_free(tmp_list);
|
meillo@0
|
514 }
|
meillo@0
|
515 else if(strcmp(lval, "ident_trusted_nets") == 0){
|
meillo@0
|
516 #ifdef ENABLE_IDENT
|
meillo@0
|
517 GList *node;
|
meillo@0
|
518 GList *tmp_list = parse_list(rval, FALSE);
|
meillo@0
|
519
|
meillo@0
|
520 conf.ident_trusted_nets = NULL;
|
meillo@0
|
521 foreach(tmp_list, node){
|
meillo@0
|
522 conf.ident_trusted_nets =
|
meillo@0
|
523 g_list_append(conf.ident_trusted_nets,
|
meillo@0
|
524 parse_network((gchar *)(node->data), 25));
|
meillo@0
|
525 g_free(node->data);
|
meillo@0
|
526 }
|
meillo@0
|
527 g_list_free(tmp_list);
|
meillo@0
|
528 #else
|
meillo@0
|
529 fprintf(stderr, "%s ignored: not compiled with ident support\n", lval);
|
meillo@0
|
530 #endif
|
meillo@0
|
531 }
|
meillo@0
|
532 else if((strncmp(lval, "connect_route.", 14) == 0) ||
|
meillo@0
|
533 (strncmp(lval, "online_routes.", 14) == 0)){
|
meillo@0
|
534 GList *file_list = parse_list(rval, FALSE);
|
meillo@0
|
535 table_pair *pair = create_pair(&(lval[14]), file_list);
|
meillo@0
|
536 conf.connect_routes = g_list_append(conf.connect_routes, pair);
|
meillo@0
|
537 }
|
meillo@0
|
538 else if(strcmp(lval, "local_net_route") == 0){
|
meillo@0
|
539 conf.local_net_routes = parse_list(rval, FALSE);
|
meillo@0
|
540 }
|
meillo@0
|
541 else if(strcmp(lval, "online_detect") == 0)
|
meillo@0
|
542 conf.online_detect = g_strdup(rval);
|
meillo@0
|
543 else if(strcmp(lval, "online_file") == 0)
|
meillo@0
|
544 conf.online_file = g_strdup(rval);
|
meillo@0
|
545 else if(strcmp(lval, "online_pipe") == 0)
|
meillo@0
|
546 conf.online_pipe = g_strdup(rval);
|
meillo@0
|
547 else if(strcmp(lval, "mserver_iface") == 0)
|
meillo@0
|
548 conf.mserver_iface = parse_interface(rval, 224);
|
meillo@0
|
549 else if(strcmp(lval, "do_queue") == 0)
|
meillo@0
|
550 conf.do_queue = parse_boolean(rval);
|
meillo@0
|
551 else if(strncmp(lval, "get.", 4) == 0){
|
meillo@0
|
552 #ifdef ENABLE_POP3
|
meillo@0
|
553 table_pair *pair = create_pair_string(&(lval[4]), rval);
|
meillo@0
|
554 conf.get_names = g_list_append(conf.get_names, pair);
|
meillo@0
|
555 #else
|
meillo@0
|
556 fprintf(stderr, "get.<name> ignored: not compiled with pop support\n");
|
meillo@0
|
557 #endif
|
meillo@0
|
558 }
|
meillo@0
|
559 else if(strncmp(lval, "online_gets.", 12) == 0){
|
meillo@0
|
560 #ifdef ENABLE_POP3
|
meillo@0
|
561 GList *file_list = parse_list(rval, FALSE);
|
meillo@0
|
562 table_pair *pair = create_pair(&(lval[12]), file_list);
|
meillo@0
|
563 conf.online_gets = g_list_append(conf.online_gets, pair);
|
meillo@0
|
564 #else
|
meillo@0
|
565 fprintf(stderr, "online_gets.<name> ignored: not compiled with pop support\n");
|
meillo@0
|
566 #endif
|
meillo@0
|
567 }
|
meillo@0
|
568 else if(strcmp(lval, "errmsg_file") == 0)
|
meillo@0
|
569 conf.errmsg_file = g_strdup(rval);
|
meillo@0
|
570 else if(strcmp(lval, "warnmsg_file") == 0)
|
meillo@0
|
571 conf.warnmsg_file = g_strdup(rval);
|
meillo@0
|
572 else if(strcmp(lval, "warn_intervals") == 0)
|
meillo@0
|
573 conf.warn_intervals = parse_list(rval, FALSE);
|
meillo@0
|
574 else if(strcmp(lval, "max_defer_time") == 0){
|
meillo@0
|
575 gint dummy;
|
meillo@0
|
576 gint ival = time_interval(rval, &dummy);
|
meillo@0
|
577 if(ival < 0)
|
meillo@0
|
578 fprintf(stderr, "invalid time interval for 'max_defer_time': %s\n", rval);
|
meillo@0
|
579 else
|
meillo@0
|
580 conf.max_defer_time = ival;
|
meillo@0
|
581 }else if(strcmp(lval, "log_user") == 0)
|
meillo@0
|
582 conf.log_user = g_strdup(rval);
|
meillo@0
|
583
|
meillo@0
|
584 else
|
meillo@0
|
585 fprintf(stderr, "var '%s' not (yet) known, ignored\n", lval);
|
meillo@0
|
586 }
|
meillo@0
|
587 fclose(in);
|
meillo@0
|
588
|
meillo@0
|
589 if(conf.errmsg_file == NULL)
|
meillo@0
|
590 conf.errmsg_file = g_strdup(DATA_DIR"/tpl/failmsg.tpl");
|
meillo@0
|
591 if(conf.warnmsg_file == NULL)
|
meillo@0
|
592 conf.warnmsg_file = g_strdup(DATA_DIR"/tpl/warnmsg.tpl");
|
meillo@0
|
593
|
meillo@0
|
594 if(conf.lock_dir == NULL)
|
meillo@0
|
595 conf.lock_dir = g_strdup_printf("%s/lock/", conf.spool_dir);
|
meillo@0
|
596
|
meillo@0
|
597 if(conf.mbox_default == NULL)
|
meillo@0
|
598 conf.mbox_default = g_strdup("mbox");
|
meillo@0
|
599
|
meillo@0
|
600 if(conf.warn_intervals == NULL)
|
meillo@0
|
601 conf.warn_intervals = parse_list("1h;4h;8h;1d;2d;3d", FALSE);
|
meillo@0
|
602
|
meillo@0
|
603 return TRUE;
|
meillo@0
|
604 }else
|
meillo@0
|
605 fprintf(stderr, "could not open config file %s: %s\n", filename, strerror(errno));
|
meillo@0
|
606 return FALSE;
|
meillo@0
|
607 }
|
meillo@0
|
608
|
meillo@0
|
609 connect_route *read_route(gchar *filename, gboolean is_local_net)
|
meillo@0
|
610 {
|
meillo@0
|
611 gboolean ok = FALSE;
|
meillo@0
|
612 FILE *in;
|
meillo@0
|
613
|
meillo@0
|
614 connect_route *route = g_malloc(sizeof(connect_route));
|
meillo@0
|
615 memset(route, 0, sizeof(connect_route));
|
meillo@0
|
616
|
meillo@0
|
617 DEBUG(5) debugf("read_route, filename = %s\n", filename);
|
meillo@0
|
618
|
meillo@0
|
619 route->filename = g_strdup(filename);
|
meillo@0
|
620 route->name = g_strdup(filename); /* quick hack */
|
meillo@0
|
621
|
meillo@0
|
622 route->protocol = g_strdup("smtp");
|
meillo@0
|
623 route->expand_h_sender_address = TRUE;
|
meillo@0
|
624
|
meillo@0
|
625 route->is_local_net = is_local_net;
|
meillo@0
|
626
|
meillo@0
|
627 route->do_pipelining = TRUE;
|
meillo@0
|
628
|
meillo@0
|
629 if((in = fopen(route->filename, "r"))){
|
meillo@0
|
630 gchar lval[256], rval[2048];
|
meillo@0
|
631 while(read_statement(in, lval, 256, rval, 2048)){
|
meillo@0
|
632 if(strcmp(lval, "protocol") == 0)
|
meillo@0
|
633 route->protocol = g_strdup(rval);
|
meillo@0
|
634 else if(strcmp(lval, "mail_host") == 0)
|
meillo@0
|
635 route->mail_host = parse_interface(rval, conf.remote_port);
|
meillo@0
|
636 else if(strcmp(lval, "helo_name") == 0)
|
meillo@0
|
637 route->helo_name = g_strdup(rval);
|
meillo@0
|
638 else if(strcmp(lval, "wrapper") == 0)
|
meillo@0
|
639 route->wrapper = g_strdup(rval);
|
meillo@0
|
640 else if(strcmp(lval, "connect_error_fail") == 0)
|
meillo@0
|
641 route->connect_error_fail = parse_boolean(rval);
|
meillo@0
|
642 else if(strcmp(lval, "do_correct_helo") == 0)
|
meillo@0
|
643 route->do_correct_helo = parse_boolean(rval);
|
meillo@0
|
644 else if(strcmp(lval, "do_pipelining") == 0)
|
meillo@0
|
645 route->do_pipelining = parse_boolean(rval);
|
meillo@0
|
646 else if(strcmp(lval, "allowed_return_paths") == 0)
|
meillo@0
|
647 route->allowed_return_paths = parse_address_list(rval, TRUE);
|
meillo@0
|
648 else if(strcmp(lval, "allowed_mail_locals") == 0)
|
meillo@0
|
649 route->allowed_mail_locals = parse_list(rval, TRUE);
|
meillo@0
|
650 else if(strcmp(lval, "not_allowed_return_paths") == 0)
|
meillo@0
|
651 route->not_allowed_return_paths = parse_address_list(rval, TRUE);
|
meillo@0
|
652 else if(strcmp(lval, "not_allowed_mail_locals") == 0)
|
meillo@0
|
653 route->not_allowed_mail_locals = parse_list(rval, TRUE);
|
meillo@0
|
654 else if(strcmp(lval, "allowed_rcpt_domains") == 0)
|
meillo@0
|
655 route->allowed_rcpt_domains = parse_list(rval, TRUE);
|
meillo@0
|
656 else if(strcmp(lval, "not_allowed_rcpt_domains") == 0)
|
meillo@0
|
657 route->not_allowed_rcpt_domains = parse_list(rval, TRUE);
|
meillo@0
|
658 else if(strcmp(lval, "set_h_from_domain") == 0)
|
meillo@0
|
659 route->set_h_from_domain = g_strdup(rval);
|
meillo@0
|
660 else if(strcmp(lval, "set_h_reply_to_domain") == 0)
|
meillo@0
|
661 route->set_h_reply_to_domain = g_strdup(rval);
|
meillo@0
|
662 else if(strcmp(lval, "set_return_path_domain") == 0)
|
meillo@0
|
663 route->set_return_path_domain = g_strdup(rval);
|
meillo@0
|
664 else if(strcmp(lval, "map_return_path_addresses") == 0){
|
meillo@0
|
665 GList *node, *list;
|
meillo@0
|
666
|
meillo@0
|
667 list = parse_list(rval, TRUE);
|
meillo@0
|
668 foreach(list, node){
|
meillo@0
|
669 gchar *item = (gchar *)(node->data);
|
meillo@0
|
670 table_pair *pair = parse_table_pair(item, ':');
|
meillo@0
|
671 address *addr = create_address((gchar *)(pair->value), TRUE);
|
meillo@0
|
672 g_free(pair->value);
|
meillo@0
|
673 pair->value = (gpointer *)addr;
|
meillo@0
|
674 route->map_return_path_addresses =
|
meillo@0
|
675 g_list_append(route->map_return_path_addresses, pair);
|
meillo@0
|
676 g_free(item);
|
meillo@0
|
677 }
|
meillo@0
|
678 g_list_free(list);
|
meillo@0
|
679 }
|
meillo@0
|
680 else if(strcmp(lval, "map_h_from_addresses") == 0){
|
meillo@0
|
681 GList *list, *node;
|
meillo@0
|
682
|
meillo@0
|
683 list = parse_list(rval, TRUE);
|
meillo@0
|
684 foreach(list, node){
|
meillo@0
|
685 gchar *item = (gchar *)(node->data);
|
meillo@0
|
686 table_pair *pair = parse_table_pair(item, ':');
|
meillo@0
|
687 route->map_h_from_addresses =
|
meillo@0
|
688 g_list_append(route->map_h_from_addresses, pair);
|
meillo@0
|
689 g_free(item);
|
meillo@0
|
690 }
|
meillo@0
|
691 g_list_free(list);
|
meillo@0
|
692 }
|
meillo@0
|
693 else if(strcmp(lval, "map_h_reply_to_addresses") == 0){
|
meillo@0
|
694 GList *list, *node;
|
meillo@0
|
695
|
meillo@0
|
696 list = parse_list(rval, TRUE);
|
meillo@0
|
697 foreach(list, node){
|
meillo@0
|
698 gchar *item = (gchar *)(node->data);
|
meillo@0
|
699 table_pair *pair = parse_table_pair(item, ':');
|
meillo@0
|
700 route->map_h_reply_to_addresses =
|
meillo@0
|
701 g_list_append(route->map_h_reply_to_addresses, pair);
|
meillo@0
|
702 g_free(item);
|
meillo@0
|
703 }
|
meillo@0
|
704 g_list_free(list);
|
meillo@0
|
705 }
|
meillo@0
|
706 else if(strcmp(lval, "map_h_mail_followup_to_addresses") == 0){
|
meillo@0
|
707 GList *list, *node;
|
meillo@0
|
708
|
meillo@0
|
709 list = parse_list(rval, TRUE);
|
meillo@0
|
710 foreach(list, node){
|
meillo@0
|
711 gchar *item = (gchar *)(node->data);
|
meillo@0
|
712 table_pair *pair = parse_table_pair(item, ':');
|
meillo@0
|
713 route->map_h_mail_followup_to_addresses =
|
meillo@0
|
714 g_list_append(route->map_h_mail_followup_to_addresses, pair);
|
meillo@0
|
715 g_free(item);
|
meillo@0
|
716 }
|
meillo@0
|
717 g_list_free(list);
|
meillo@0
|
718 }
|
meillo@0
|
719 else if(strcmp(lval, "expand_h_sender_domain") == 0){
|
meillo@0
|
720 route->expand_h_sender_domain = parse_boolean(rval);
|
meillo@0
|
721 }
|
meillo@0
|
722 else if(strcmp(lval, "expand_h_sender_address") == 0){
|
meillo@0
|
723 route->expand_h_sender_address = parse_boolean(rval);
|
meillo@0
|
724 }
|
meillo@0
|
725 else if(strcmp(lval, "resolve_list") == 0)
|
meillo@0
|
726 route->resolve_list = parse_resolve_list(rval);
|
meillo@0
|
727 else if(strcmp(lval, "do_ssl") == 0){
|
meillo@0
|
728 /* we ignore this. This option is used by sqilconf */
|
meillo@0
|
729 ;
|
meillo@0
|
730 }
|
meillo@0
|
731 #ifdef ENABLE_AUTH
|
meillo@0
|
732 else if(strcmp(lval, "auth_name") == 0){
|
meillo@0
|
733 route->auth_name = g_strdup(rval);
|
meillo@0
|
734 }
|
meillo@0
|
735 else if(strcmp(lval, "auth_login") == 0){
|
meillo@0
|
736 route->auth_login = g_strdup(rval);
|
meillo@0
|
737 }
|
meillo@0
|
738 else if(strcmp(lval, "auth_secret") == 0){
|
meillo@0
|
739 route->auth_secret = g_strdup(rval);
|
meillo@0
|
740 }
|
meillo@0
|
741 #else
|
meillo@0
|
742 else if((strcmp(lval, "auth_name") == 0) ||
|
meillo@0
|
743 (strcmp(lval, "auth_login") == 0) ||
|
meillo@0
|
744 (strcmp(lval, "auth_secret") == 0)){
|
meillo@0
|
745 logwrite(LOG_WARNING, "%s ignored: not compiled with auth support.\n", lval);
|
meillo@0
|
746 }
|
meillo@0
|
747 #endif
|
meillo@0
|
748 else if(strcmp(lval, "pop3_login") == 0){
|
meillo@0
|
749 #ifdef ENABLE_POP3
|
meillo@0
|
750 route->pop3_login = g_strdup(rval);
|
meillo@0
|
751 #else
|
meillo@0
|
752 logwrite(LOG_WARNING, "pop3_login ignored: not compiled with pop support.\n");
|
meillo@0
|
753 #endif
|
meillo@0
|
754 }
|
meillo@0
|
755 else if(strcmp(lval, "pipe") == 0){
|
meillo@0
|
756 route->pipe = g_strdup(rval);
|
meillo@0
|
757 }
|
meillo@0
|
758 else if(strcmp(lval, "pipe_fromline") == 0){
|
meillo@0
|
759 route->pipe_fromline = parse_boolean(rval);
|
meillo@0
|
760 }
|
meillo@0
|
761 else if(strcmp(lval, "pipe_fromhack") == 0){
|
meillo@0
|
762 route->pipe_fromhack = parse_boolean(rval);
|
meillo@0
|
763 }
|
meillo@0
|
764 else if(strcmp(lval, "last_route") == 0){
|
meillo@0
|
765 route->last_route = parse_boolean(rval);
|
meillo@0
|
766 }
|
meillo@0
|
767 else
|
meillo@0
|
768 logwrite(LOG_WARNING, "var '%s' not (yet) known, ignored\n", lval);
|
meillo@0
|
769 }
|
meillo@0
|
770
|
meillo@0
|
771 if(route->resolve_list == NULL){
|
meillo@0
|
772 if(is_local_net){
|
meillo@0
|
773 route->resolve_list =
|
meillo@0
|
774 g_list_append(NULL, resolve_byname);
|
meillo@0
|
775 }else{
|
meillo@0
|
776 #ifdef ENABLE_RESOLVER
|
meillo@0
|
777 route->resolve_list =
|
meillo@0
|
778 g_list_append(route->resolve_list, resolve_dns_mx);
|
meillo@0
|
779 route->resolve_list =
|
meillo@0
|
780 g_list_append(route->resolve_list, resolve_dns_a);
|
meillo@0
|
781 #endif
|
meillo@0
|
782 route->resolve_list =
|
meillo@0
|
783 g_list_append(route->resolve_list, resolve_byname);
|
meillo@0
|
784 }
|
meillo@0
|
785 }
|
meillo@0
|
786 fclose(in);
|
meillo@0
|
787 ok = TRUE;
|
meillo@0
|
788
|
meillo@0
|
789 /* warn user about misconfigurations: */
|
meillo@0
|
790 if((route->map_h_from_addresses != NULL) && (route->set_h_from_domain != NULL)){
|
meillo@0
|
791 logwrite(LOG_WARNING, "'map_h_from_addresses' overrides 'set_h_from_domain'\n");
|
meillo@0
|
792 g_free(route->set_h_from_domain);
|
meillo@0
|
793 route->set_h_from_domain = NULL;
|
meillo@0
|
794 }
|
meillo@0
|
795 if((route->map_h_reply_to_addresses != NULL) && (route->set_h_reply_to_domain != NULL)){
|
meillo@0
|
796 logwrite(LOG_WARNING, "'map_h_reply_to_addresses' overrides 'set_h_reply_to_domain'\n");
|
meillo@0
|
797 g_free(route->set_h_reply_to_domain);
|
meillo@0
|
798 route->set_h_reply_to_domain = NULL;
|
meillo@0
|
799 }
|
meillo@0
|
800 }else{
|
meillo@0
|
801 logwrite(LOG_ALERT, "could not open route file %s: %s\n",
|
meillo@0
|
802 route->filename, strerror(errno));
|
meillo@0
|
803 }
|
meillo@0
|
804
|
meillo@0
|
805 if(!ok){
|
meillo@0
|
806 g_free(route);
|
meillo@0
|
807 route = NULL;
|
meillo@0
|
808 }
|
meillo@0
|
809
|
meillo@0
|
810 return route;
|
meillo@0
|
811 }
|
meillo@0
|
812
|
meillo@0
|
813 static
|
meillo@0
|
814 void _g_list_free_all(GList *list)
|
meillo@0
|
815 {
|
meillo@0
|
816 GList *node;
|
meillo@0
|
817 if(list){
|
meillo@0
|
818 foreach(list, node)
|
meillo@0
|
819 g_free(node->data);
|
meillo@0
|
820 g_list_free(list);
|
meillo@0
|
821 }
|
meillo@0
|
822 }
|
meillo@0
|
823
|
meillo@0
|
824 void destroy_route(connect_route *r)
|
meillo@0
|
825 {
|
meillo@0
|
826 if(r->filename) g_free(r->filename);
|
meillo@0
|
827 if(r->protocol) g_free(r->protocol);
|
meillo@0
|
828 if(r->mail_host){
|
meillo@0
|
829 g_free(r->mail_host->address);
|
meillo@0
|
830 g_free(r->mail_host);
|
meillo@0
|
831 }
|
meillo@0
|
832 if(r->wrapper) g_free(r->wrapper);
|
meillo@0
|
833 if(r->helo_name) g_free(r->helo_name);
|
meillo@0
|
834 _g_list_free_all(r->allowed_mail_locals);
|
meillo@0
|
835 _g_list_free_all(r->not_allowed_mail_locals);
|
meillo@0
|
836 _g_list_free_all(r->allowed_rcpt_domains);
|
meillo@0
|
837 _g_list_free_all(r->not_allowed_rcpt_domains);
|
meillo@0
|
838 if(r->set_h_from_domain) g_free(r->set_h_from_domain);
|
meillo@0
|
839 if(r->set_h_reply_to_domain) g_free(r->set_h_reply_to_domain);
|
meillo@0
|
840 if(r->set_return_path_domain) g_free(r->set_return_path_domain);
|
meillo@0
|
841 if(r->map_h_reply_to_addresses) destroy_table(r->map_h_reply_to_addresses);
|
meillo@0
|
842 if(r->resolve_list) g_list_free(r->resolve_list);
|
meillo@0
|
843 #ifdef ENABLE_AUTH
|
meillo@0
|
844 if(r->auth_name) g_free(r->auth_name);
|
meillo@0
|
845 if(r->auth_login) g_free(r->auth_login);
|
meillo@0
|
846 if(r->auth_secret) g_free(r->auth_secret);
|
meillo@0
|
847 #endif
|
meillo@0
|
848 #ifdef ENABLE_POP3
|
meillo@0
|
849 if(r->pop3_login) g_free(r->pop3_login);
|
meillo@0
|
850 #endif
|
meillo@0
|
851 if(r->pipe) g_free(r->pipe);
|
meillo@0
|
852 g_free(r);
|
meillo@0
|
853 }
|
meillo@0
|
854
|
meillo@0
|
855 GList *read_route_list(GList *rf_list, gboolean is_local_net)
|
meillo@0
|
856 {
|
meillo@0
|
857 GList *list = NULL;
|
meillo@0
|
858 GList *node;
|
meillo@0
|
859 uid_t saved_uid, saved_gid;
|
meillo@0
|
860
|
meillo@0
|
861 if(!conf.run_as_user){
|
meillo@0
|
862 set_euidgid(0, 0, &saved_uid, &saved_gid);
|
meillo@0
|
863 }
|
meillo@0
|
864
|
meillo@0
|
865 foreach(rf_list, node){
|
meillo@0
|
866 gchar *fname = (gchar *)(node->data);
|
meillo@0
|
867 connect_route *route = read_route(fname, is_local_net);
|
meillo@0
|
868 if(route)
|
meillo@0
|
869 list = g_list_append(list, route);
|
meillo@0
|
870 else
|
meillo@0
|
871 logwrite(LOG_ALERT, "could not read route configuration %s\n", fname);
|
meillo@0
|
872 }
|
meillo@0
|
873
|
meillo@0
|
874 /* set uid and gid back */
|
meillo@0
|
875 if(!conf.run_as_user){
|
meillo@0
|
876 set_euidgid(saved_uid, saved_gid, NULL, NULL);
|
meillo@0
|
877 }
|
meillo@0
|
878
|
meillo@0
|
879 return list;
|
meillo@0
|
880 }
|
meillo@0
|
881
|
meillo@0
|
882 void destroy_route_list(GList *list)
|
meillo@0
|
883 {
|
meillo@0
|
884 GList *node;
|
meillo@0
|
885
|
meillo@0
|
886 foreach(list, node){
|
meillo@0
|
887 connect_route *route = (connect_route *)(node->data);
|
meillo@0
|
888 destroy_route(route);
|
meillo@0
|
889 }
|
meillo@0
|
890 g_list_free(list);
|
meillo@0
|
891 }
|
meillo@0
|
892
|
meillo@0
|
893 #ifdef ENABLE_POP3
|
meillo@0
|
894
|
meillo@0
|
895 get_conf *read_get_conf(gchar *filename)
|
meillo@0
|
896 {
|
meillo@0
|
897 FILE *in;
|
meillo@0
|
898
|
meillo@0
|
899 get_conf *gc = g_malloc(sizeof(get_conf));
|
meillo@0
|
900 memset(gc, 0, sizeof(get_conf));
|
meillo@0
|
901
|
meillo@0
|
902 gc->server_port = 110;
|
meillo@0
|
903
|
meillo@0
|
904 if((in = fopen(filename, "r"))){
|
meillo@0
|
905 gchar lval[256], rval[2048];
|
meillo@0
|
906 while(read_statement(in, lval, 256, rval, 2048)){
|
meillo@0
|
907 if(strcmp(lval, "protocol") == 0)
|
meillo@0
|
908 gc->protocol = g_strdup(rval);
|
meillo@0
|
909 else if(strcmp(lval, "server") == 0)
|
meillo@0
|
910 gc->server_name = g_strdup(rval);
|
meillo@0
|
911 else if(strcmp(lval, "port") == 0)
|
meillo@0
|
912 gc->server_port = atoi(rval);
|
meillo@0
|
913 else if(strcmp(lval, "wrapper") == 0)
|
meillo@0
|
914 gc->wrapper = g_strdup(rval);
|
meillo@0
|
915 else if(strcmp(lval, "user") == 0)
|
meillo@0
|
916 gc->login_user = g_strdup(rval);
|
meillo@0
|
917 else if(strcmp(lval, "pass") == 0)
|
meillo@0
|
918 gc->login_pass = g_strdup(rval);
|
meillo@0
|
919 else if(strcmp(lval, "address") == 0)
|
meillo@0
|
920 gc->address = create_address_qualified(rval, TRUE, conf.host_name);
|
meillo@0
|
921 else if(strcmp(lval, "return_path") == 0)
|
meillo@0
|
922 gc->return_path = create_address_qualified(rval, TRUE, conf.host_name);
|
meillo@0
|
923 else if(strcmp(lval, "do_ssl") == 0)
|
meillo@0
|
924 /* we ignore this. This option is used by sqilconf */
|
meillo@0
|
925 ;
|
meillo@0
|
926 else if(strcmp(lval, "do_keep") == 0)
|
meillo@0
|
927 gc->do_keep = parse_boolean(rval);
|
meillo@0
|
928 else if(strcmp(lval, "do_uidl") == 0)
|
meillo@0
|
929 gc->do_uidl = parse_boolean(rval);
|
meillo@0
|
930 else if(strcmp(lval, "do_uidl_dele") == 0)
|
meillo@0
|
931 gc->do_uidl_dele = parse_boolean(rval);
|
meillo@0
|
932 else if(strcmp(lval, "max_size") == 0)
|
meillo@0
|
933 gc->max_size = atoi(rval);
|
meillo@0
|
934 else if(strcmp(lval, "max_size_delete") == 0)
|
meillo@0
|
935 gc->max_size = parse_boolean(rval);
|
meillo@0
|
936 else if(strcmp(lval, "max_count") == 0)
|
meillo@0
|
937 gc->max_count = atoi(rval);
|
meillo@0
|
938 else if(strcmp(lval, "resolve_list") == 0)
|
meillo@0
|
939 gc->resolve_list = parse_resolve_list(rval);
|
meillo@0
|
940 else
|
meillo@0
|
941 logwrite(LOG_WARNING, "var '%s' not (yet) known, ignored\n", lval);
|
meillo@0
|
942 }
|
meillo@0
|
943 fclose(in);
|
meillo@0
|
944
|
meillo@0
|
945 if(gc->resolve_list == NULL){
|
meillo@0
|
946 #ifdef ENABLE_RESOLVER
|
meillo@0
|
947 gc->resolve_list =
|
meillo@0
|
948 g_list_append(NULL, resolve_dns_a);
|
meillo@0
|
949 #endif
|
meillo@0
|
950 gc->resolve_list =
|
meillo@0
|
951 g_list_append(NULL, resolve_byname);
|
meillo@0
|
952 }
|
meillo@0
|
953
|
meillo@0
|
954 if(gc->protocol == NULL)
|
meillo@0
|
955 gc->protocol = g_strdup("pop3");
|
meillo@0
|
956 return gc;
|
meillo@0
|
957 }
|
meillo@0
|
958 logwrite(LOG_ALERT, "could not open get file %s: %s\n", filename, strerror(errno));
|
meillo@0
|
959
|
meillo@0
|
960 g_free(gc);
|
meillo@0
|
961 return NULL;
|
meillo@0
|
962 }
|
meillo@0
|
963
|
meillo@0
|
964 void destroy_get_conf(get_conf *gc)
|
meillo@0
|
965 {
|
meillo@0
|
966 if(gc->protocol) g_free(gc->protocol);
|
meillo@0
|
967 if(gc->server_name) g_free(gc->server_name);
|
meillo@0
|
968 if(gc->login_user) g_free(gc->login_user);
|
meillo@0
|
969 if(gc->login_pass) g_free(gc->login_pass);
|
meillo@0
|
970 if(gc->wrapper) g_free(gc->wrapper);
|
meillo@0
|
971 if(gc->address) destroy_address(gc->address);
|
meillo@0
|
972 if(gc->return_path) destroy_address(gc->return_path);
|
meillo@0
|
973 if(gc->resolve_list) g_list_free(gc->resolve_list);
|
meillo@0
|
974 g_free(gc);
|
meillo@0
|
975 }
|
meillo@0
|
976
|
meillo@0
|
977 #endif
|
meillo@0
|
978
|
meillo@0
|
979 connect_route *create_local_route()
|
meillo@0
|
980 {
|
meillo@0
|
981 connect_route *route;
|
meillo@0
|
982
|
meillo@0
|
983 route = g_malloc(sizeof(connect_route));
|
meillo@0
|
984 if(route){
|
meillo@0
|
985 memset(route, 0, sizeof(connect_route));
|
meillo@0
|
986 route->protocol = g_strdup("smtp");
|
meillo@0
|
987 route->is_local_net = TRUE;
|
meillo@0
|
988 route->name = g_strdup("local_net (default)");
|
meillo@0
|
989 route->expand_h_sender_address = TRUE;
|
meillo@0
|
990 route->resolve_list =
|
meillo@0
|
991 g_list_append(NULL, resolve_byname);
|
meillo@0
|
992 route->connect_error_fail = TRUE;
|
meillo@0
|
993 }
|
meillo@0
|
994 return route;
|
meillo@0
|
995 }
|