Mercurial > masqmail
annotate src/masqmail.c @ 434:f2a7271746d1 default tip
Removes Freshmeat.net from the docs
The site, which was later renamed to freecode.com, is no longer
maintained (contains only a static copy).
author | markus schnalke <meillo@marmaro.de> |
---|---|
date | Sat, 07 Feb 2015 11:45:07 +0100 |
parents | a19e47ebbb33 |
children |
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) 1999-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 | 19 */ |
20 | |
21 #include <stdio.h> | |
22 #include <errno.h> | |
23 #include <stdlib.h> | |
24 #include <string.h> | |
25 #include <unistd.h> | |
26 #include <sys/types.h> | |
27 #include <sys/socket.h> | |
28 #include <sys/time.h> | |
29 #include <netinet/in.h> | |
30 #include <netdb.h> | |
31 #include <syslog.h> | |
32 #include <signal.h> | |
33 | |
34 #include <glib.h> | |
35 | |
36 #include "masqmail.h" | |
37 | |
367
b27f66555ba8
Reformated multiline comments to have leading asterisks on each line
markus schnalke <meillo@marmaro.de>
parents:
366
diff
changeset
|
38 /* |
b27f66555ba8
Reformated multiline comments to have leading asterisks on each line
markus schnalke <meillo@marmaro.de>
parents:
366
diff
changeset
|
39 ** mutually exclusive modes. Note that there is no 'queue daemon' mode. |
b27f66555ba8
Reformated multiline comments to have leading asterisks on each line
markus schnalke <meillo@marmaro.de>
parents:
366
diff
changeset
|
40 ** It, as well as the distinction beween the two (non exclusive) daemon |
b27f66555ba8
Reformated multiline comments to have leading asterisks on each line
markus schnalke <meillo@marmaro.de>
parents:
366
diff
changeset
|
41 ** (queue and listen) modes, is handled by flags. |
b27f66555ba8
Reformated multiline comments to have leading asterisks on each line
markus schnalke <meillo@marmaro.de>
parents:
366
diff
changeset
|
42 */ |
281
ea5f86e0a81c
modes are now enforced exclusive
markus schnalke <meillo@marmaro.de>
parents:
278
diff
changeset
|
43 enum mta_mode { |
ea5f86e0a81c
modes are now enforced exclusive
markus schnalke <meillo@marmaro.de>
parents:
278
diff
changeset
|
44 MODE_NONE = 0, /* to check if a mode was set */ |
ea5f86e0a81c
modes are now enforced exclusive
markus schnalke <meillo@marmaro.de>
parents:
278
diff
changeset
|
45 MODE_ACCEPT, /* accept message on stdin (fallback mode) */ |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
46 MODE_DAEMON, /* run as daemon */ |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
47 MODE_RUNQUEUE, /* single queue run, online or offline */ |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
48 MODE_SMTP, /* accept SMTP on stdin */ |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
49 MODE_LIST, /* list queue */ |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
50 MODE_MCMD, /* do queue manipulation */ |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
51 MODE_VERSION, /* show version */ |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
52 MODE_BI, /* fake ;-) */ |
281
ea5f86e0a81c
modes are now enforced exclusive
markus schnalke <meillo@marmaro.de>
parents:
278
diff
changeset
|
53 }; |
ea5f86e0a81c
modes are now enforced exclusive
markus schnalke <meillo@marmaro.de>
parents:
278
diff
changeset
|
54 enum mta_mode mta_mode = MODE_NONE; |
0 | 55 |
56 char *pidfile = NULL; | |
57 volatile int sigterm_in_progress = 0; | |
58 | |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
59 static void |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
60 sigterm_handler(int sig) |
0 | 61 { |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
62 if (sigterm_in_progress) |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
63 raise(sig); |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
64 sigterm_in_progress = 1; |
0 | 65 |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
66 if (pidfile) { |
331
e507c854a63e
Security fix! Correct handling of seteuid() return value
markus schnalke <meillo@marmaro.de>
parents:
310
diff
changeset
|
67 uid_t uid = geteuid(); |
e507c854a63e
Security fix! Correct handling of seteuid() return value
markus schnalke <meillo@marmaro.de>
parents:
310
diff
changeset
|
68 if (seteuid(0) != 0) { |
409 | 69 logwrite(LOG_ALERT, "sigterm_handler: could not set " |
70 "euid to %d: %s\n", | |
71 0, strerror(errno)); | |
331
e507c854a63e
Security fix! Correct handling of seteuid() return value
markus schnalke <meillo@marmaro.de>
parents:
310
diff
changeset
|
72 } |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
73 if (unlink(pidfile) != 0) |
409 | 74 logwrite(LOG_WARNING, |
75 "could not delete pid file %s: %s\n", | |
76 pidfile, strerror(errno)); | |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
77 seteuid(uid); /* we exit anyway after this, just to be sure */ |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
78 } |
0 | 79 |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
80 signal(sig, SIG_DFL); |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
81 raise(sig); |
0 | 82 } |
83 | |
249
f9da5a7caeda
refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents:
248
diff
changeset
|
84 /* |
367
b27f66555ba8
Reformated multiline comments to have leading asterisks on each line
markus schnalke <meillo@marmaro.de>
parents:
366
diff
changeset
|
85 ** argv: the original argv |
b27f66555ba8
Reformated multiline comments to have leading asterisks on each line
markus schnalke <meillo@marmaro.de>
parents:
366
diff
changeset
|
86 ** argp: number of arg (may get modified!) |
b27f66555ba8
Reformated multiline comments to have leading asterisks on each line
markus schnalke <meillo@marmaro.de>
parents:
366
diff
changeset
|
87 ** cp: pointing to the char after the option |
b27f66555ba8
Reformated multiline comments to have leading asterisks on each line
markus schnalke <meillo@marmaro.de>
parents:
366
diff
changeset
|
88 ** e.g. `-d 6' `-d6' |
b27f66555ba8
Reformated multiline comments to have leading asterisks on each line
markus schnalke <meillo@marmaro.de>
parents:
366
diff
changeset
|
89 ** ^ ^ |
249
f9da5a7caeda
refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents:
248
diff
changeset
|
90 */ |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
91 gchar* |
366
41958685480d
Switched to `type *name' style
markus schnalke <meillo@marmaro.de>
parents:
349
diff
changeset
|
92 get_optarg(char *argv[], gint *argp, char *cp) |
0 | 93 { |
249
f9da5a7caeda
refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents:
248
diff
changeset
|
94 if (*cp) { |
f9da5a7caeda
refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents:
248
diff
changeset
|
95 /* this kind: -xval */ |
f9da5a7caeda
refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents:
248
diff
changeset
|
96 return cp; |
f9da5a7caeda
refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents:
248
diff
changeset
|
97 } |
f9da5a7caeda
refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents:
248
diff
changeset
|
98 cp = argv[*argp+1]; |
f9da5a7caeda
refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents:
248
diff
changeset
|
99 if (cp && (*cp != '-')) { |
f9da5a7caeda
refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents:
248
diff
changeset
|
100 /* this kind: -x val */ |
f9da5a7caeda
refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents:
248
diff
changeset
|
101 (*argp)++; |
f9da5a7caeda
refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents:
248
diff
changeset
|
102 return cp; |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
103 } |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
104 return NULL; |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
105 } |
0 | 106 |
421
f37384470855
Changed lockdir to /var/lock/masqmail; Create lockdir and piddir on startup.
markus schnalke <meillo@marmaro.de>
parents:
419
diff
changeset
|
107 /* |
f37384470855
Changed lockdir to /var/lock/masqmail; Create lockdir and piddir on startup.
markus schnalke <meillo@marmaro.de>
parents:
419
diff
changeset
|
108 ** Create any missing directory in pathname `dir'. (Like `mkdir -p'.) |
f37384470855
Changed lockdir to /var/lock/masqmail; Create lockdir and piddir on startup.
markus schnalke <meillo@marmaro.de>
parents:
419
diff
changeset
|
109 ** The code is taken from nmh. |
f37384470855
Changed lockdir to /var/lock/masqmail; Create lockdir and piddir on startup.
markus schnalke <meillo@marmaro.de>
parents:
419
diff
changeset
|
110 */ |
f37384470855
Changed lockdir to /var/lock/masqmail; Create lockdir and piddir on startup.
markus schnalke <meillo@marmaro.de>
parents:
419
diff
changeset
|
111 gboolean |
f37384470855
Changed lockdir to /var/lock/masqmail; Create lockdir and piddir on startup.
markus schnalke <meillo@marmaro.de>
parents:
419
diff
changeset
|
112 makedir_rec(char *dir, int perms) |
f37384470855
Changed lockdir to /var/lock/masqmail; Create lockdir and piddir on startup.
markus schnalke <meillo@marmaro.de>
parents:
419
diff
changeset
|
113 { |
f37384470855
Changed lockdir to /var/lock/masqmail; Create lockdir and piddir on startup.
markus schnalke <meillo@marmaro.de>
parents:
419
diff
changeset
|
114 char path[PATH_MAX]; |
f37384470855
Changed lockdir to /var/lock/masqmail; Create lockdir and piddir on startup.
markus schnalke <meillo@marmaro.de>
parents:
419
diff
changeset
|
115 char *cp, *c; |
f37384470855
Changed lockdir to /var/lock/masqmail; Create lockdir and piddir on startup.
markus schnalke <meillo@marmaro.de>
parents:
419
diff
changeset
|
116 int had_an_error = 0; |
425
a19e47ebbb33
Create the spool and log dirs on program startup if missing.
markus schnalke <meillo@marmaro.de>
parents:
421
diff
changeset
|
117 mode_t savedmask; |
421
f37384470855
Changed lockdir to /var/lock/masqmail; Create lockdir and piddir on startup.
markus schnalke <meillo@marmaro.de>
parents:
419
diff
changeset
|
118 |
f37384470855
Changed lockdir to /var/lock/masqmail; Create lockdir and piddir on startup.
markus schnalke <meillo@marmaro.de>
parents:
419
diff
changeset
|
119 c = strncpy(path, dir, sizeof(path)); |
f37384470855
Changed lockdir to /var/lock/masqmail; Create lockdir and piddir on startup.
markus schnalke <meillo@marmaro.de>
parents:
419
diff
changeset
|
120 |
425
a19e47ebbb33
Create the spool and log dirs on program startup if missing.
markus schnalke <meillo@marmaro.de>
parents:
421
diff
changeset
|
121 savedmask = umask(0); |
a19e47ebbb33
Create the spool and log dirs on program startup if missing.
markus schnalke <meillo@marmaro.de>
parents:
421
diff
changeset
|
122 |
421
f37384470855
Changed lockdir to /var/lock/masqmail; Create lockdir and piddir on startup.
markus schnalke <meillo@marmaro.de>
parents:
419
diff
changeset
|
123 while (!had_an_error && (c = strchr(c+1, '/'))) { |
f37384470855
Changed lockdir to /var/lock/masqmail; Create lockdir and piddir on startup.
markus schnalke <meillo@marmaro.de>
parents:
419
diff
changeset
|
124 *c = '\0'; |
f37384470855
Changed lockdir to /var/lock/masqmail; Create lockdir and piddir on startup.
markus schnalke <meillo@marmaro.de>
parents:
419
diff
changeset
|
125 /* Create an outer directory. */ |
f37384470855
Changed lockdir to /var/lock/masqmail; Create lockdir and piddir on startup.
markus schnalke <meillo@marmaro.de>
parents:
419
diff
changeset
|
126 if (mkdir(path, perms) == -1 && errno != EEXIST) { |
f37384470855
Changed lockdir to /var/lock/masqmail; Create lockdir and piddir on startup.
markus schnalke <meillo@marmaro.de>
parents:
419
diff
changeset
|
127 fprintf(stderr, "unable to create `%s': %s\n", |
f37384470855
Changed lockdir to /var/lock/masqmail; Create lockdir and piddir on startup.
markus schnalke <meillo@marmaro.de>
parents:
419
diff
changeset
|
128 path, strerror(errno)); |
f37384470855
Changed lockdir to /var/lock/masqmail; Create lockdir and piddir on startup.
markus schnalke <meillo@marmaro.de>
parents:
419
diff
changeset
|
129 had_an_error = 1; |
f37384470855
Changed lockdir to /var/lock/masqmail; Create lockdir and piddir on startup.
markus schnalke <meillo@marmaro.de>
parents:
419
diff
changeset
|
130 } |
f37384470855
Changed lockdir to /var/lock/masqmail; Create lockdir and piddir on startup.
markus schnalke <meillo@marmaro.de>
parents:
419
diff
changeset
|
131 *c = '/'; |
425
a19e47ebbb33
Create the spool and log dirs on program startup if missing.
markus schnalke <meillo@marmaro.de>
parents:
421
diff
changeset
|
132 } |
421
f37384470855
Changed lockdir to /var/lock/masqmail; Create lockdir and piddir on startup.
markus schnalke <meillo@marmaro.de>
parents:
419
diff
changeset
|
133 |
f37384470855
Changed lockdir to /var/lock/masqmail; Create lockdir and piddir on startup.
markus schnalke <meillo@marmaro.de>
parents:
419
diff
changeset
|
134 /* |
f37384470855
Changed lockdir to /var/lock/masqmail; Create lockdir and piddir on startup.
markus schnalke <meillo@marmaro.de>
parents:
419
diff
changeset
|
135 ** Create the innermost nested subdirectory of the |
f37384470855
Changed lockdir to /var/lock/masqmail; Create lockdir and piddir on startup.
markus schnalke <meillo@marmaro.de>
parents:
419
diff
changeset
|
136 ** path we're being asked to create. |
f37384470855
Changed lockdir to /var/lock/masqmail; Create lockdir and piddir on startup.
markus schnalke <meillo@marmaro.de>
parents:
419
diff
changeset
|
137 */ |
f37384470855
Changed lockdir to /var/lock/masqmail; Create lockdir and piddir on startup.
markus schnalke <meillo@marmaro.de>
parents:
419
diff
changeset
|
138 if (!had_an_error && mkdir(dir, perms)==-1 && errno != EEXIST) { |
f37384470855
Changed lockdir to /var/lock/masqmail; Create lockdir and piddir on startup.
markus schnalke <meillo@marmaro.de>
parents:
419
diff
changeset
|
139 fprintf(stderr, "unable to create `%s': %s\n", |
f37384470855
Changed lockdir to /var/lock/masqmail; Create lockdir and piddir on startup.
markus schnalke <meillo@marmaro.de>
parents:
419
diff
changeset
|
140 dir, strerror(errno)); |
f37384470855
Changed lockdir to /var/lock/masqmail; Create lockdir and piddir on startup.
markus schnalke <meillo@marmaro.de>
parents:
419
diff
changeset
|
141 had_an_error = 1; |
425
a19e47ebbb33
Create the spool and log dirs on program startup if missing.
markus schnalke <meillo@marmaro.de>
parents:
421
diff
changeset
|
142 } |
a19e47ebbb33
Create the spool and log dirs on program startup if missing.
markus schnalke <meillo@marmaro.de>
parents:
421
diff
changeset
|
143 umask(savedmask); |
421
f37384470855
Changed lockdir to /var/lock/masqmail; Create lockdir and piddir on startup.
markus schnalke <meillo@marmaro.de>
parents:
419
diff
changeset
|
144 |
f37384470855
Changed lockdir to /var/lock/masqmail; Create lockdir and piddir on startup.
markus schnalke <meillo@marmaro.de>
parents:
419
diff
changeset
|
145 return (had_an_error) ? 0 : 1; |
f37384470855
Changed lockdir to /var/lock/masqmail; Create lockdir and piddir on startup.
markus schnalke <meillo@marmaro.de>
parents:
419
diff
changeset
|
146 } |
f37384470855
Changed lockdir to /var/lock/masqmail; Create lockdir and piddir on startup.
markus schnalke <meillo@marmaro.de>
parents:
419
diff
changeset
|
147 |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
148 gboolean |
366
41958685480d
Switched to `type *name' style
markus schnalke <meillo@marmaro.de>
parents:
349
diff
changeset
|
149 write_pidfile(gchar *name) |
0 | 150 { |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
151 FILE *fptr; |
0 | 152 |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
153 if ((fptr = fopen(name, "wt"))) { |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
154 fprintf(fptr, "%d\n", getpid()); |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
155 fclose(fptr); |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
156 pidfile = strdup(name); |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
157 return TRUE; |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
158 } |
409 | 159 logwrite(LOG_WARNING, "could not write pid file: %s\n", |
160 strerror(errno)); | |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
161 return FALSE; |
0 | 162 } |
163 | |
264
1e5e457dea18
comments and a small refactoring
markus schnalke <meillo@marmaro.de>
parents:
263
diff
changeset
|
164 /* on -bd or if -q has an argument */ |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
165 static void |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
166 mode_daemon(gboolean do_listen, gint queue_interval, char *argv[]) |
0 | 167 { |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
168 guint pid; |
0 | 169 |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
170 /* daemon */ |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
171 if (!conf.run_as_user) { |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
172 if ((conf.orig_uid != 0) && (conf.orig_uid != conf.mail_uid)) { |
409 | 173 fprintf(stderr, "must be root or %s for daemon.\n", |
174 DEF_MAIL_USER); | |
262
fc1c6425c024
s/EXIT_SUCCESS/0/ && s/EXIT_FAILURE/1/
markus schnalke <meillo@marmaro.de>
parents:
261
diff
changeset
|
175 exit(1); |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
176 } |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
177 } |
0 | 178 |
74
0a5b2e96ade3
do not reparent the daemon to init if init is already the parent
meillo@marmaro.de
parents:
73
diff
changeset
|
179 /* reparent to init only if init is not already the parent */ |
0a5b2e96ade3
do not reparent the daemon to init if init is already the parent
meillo@marmaro.de
parents:
73
diff
changeset
|
180 if (getppid() != 1) { |
0a5b2e96ade3
do not reparent the daemon to init if init is already the parent
meillo@marmaro.de
parents:
73
diff
changeset
|
181 if ((pid = fork()) > 0) { |
262
fc1c6425c024
s/EXIT_SUCCESS/0/ && s/EXIT_FAILURE/1/
markus schnalke <meillo@marmaro.de>
parents:
261
diff
changeset
|
182 exit(0); |
74
0a5b2e96ade3
do not reparent the daemon to init if init is already the parent
meillo@marmaro.de
parents:
73
diff
changeset
|
183 } else if (pid < 0) { |
208
3708b655a371
added newlines to the end of log and debug messages where missing
meillo@marmaro.de
parents:
205
diff
changeset
|
184 logwrite(LOG_ALERT, "could not fork!\n"); |
262
fc1c6425c024
s/EXIT_SUCCESS/0/ && s/EXIT_FAILURE/1/
markus schnalke <meillo@marmaro.de>
parents:
261
diff
changeset
|
185 exit(1); |
74
0a5b2e96ade3
do not reparent the daemon to init if init is already the parent
meillo@marmaro.de
parents:
73
diff
changeset
|
186 } |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
187 } |
0 | 188 |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
189 signal(SIGTERM, sigterm_handler); |
421
f37384470855
Changed lockdir to /var/lock/masqmail; Create lockdir and piddir on startup.
markus schnalke <meillo@marmaro.de>
parents:
419
diff
changeset
|
190 makedir_rec(PID_DIR, 0755); |
419
d209b4846f2b
The pid files goes to /var/run/masqmail.pid now. Added --with-piddir.
markus schnalke <meillo@marmaro.de>
parents:
415
diff
changeset
|
191 write_pidfile(PID_DIR "/masqmail.pid"); |
0 | 192 |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
193 conf.do_verbose = FALSE; |
0 | 194 |
367
b27f66555ba8
Reformated multiline comments to have leading asterisks on each line
markus schnalke <meillo@marmaro.de>
parents:
366
diff
changeset
|
195 /* |
b27f66555ba8
Reformated multiline comments to have leading asterisks on each line
markus schnalke <meillo@marmaro.de>
parents:
366
diff
changeset
|
196 ** closing and reopening the log ensures that it is open afterwards |
b27f66555ba8
Reformated multiline comments to have leading asterisks on each line
markus schnalke <meillo@marmaro.de>
parents:
366
diff
changeset
|
197 ** because it is possible that the log is assigned to fd 1 and gets |
b27f66555ba8
Reformated multiline comments to have leading asterisks on each line
markus schnalke <meillo@marmaro.de>
parents:
366
diff
changeset
|
198 ** thus closes by fclose(stdout). Similar for the debugfile. |
72
ad034b57f3b2
fixed Debian bug 536060 (log files are closed after SIGHUP receival)
meillo@marmaro.de
parents:
46
diff
changeset
|
199 */ |
ad034b57f3b2
fixed Debian bug 536060 (log files are closed after SIGHUP receival)
meillo@marmaro.de
parents:
46
diff
changeset
|
200 logclose(); |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
201 fclose(stdin); |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
202 fclose(stdout); |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
203 fclose(stderr); |
72
ad034b57f3b2
fixed Debian bug 536060 (log files are closed after SIGHUP receival)
meillo@marmaro.de
parents:
46
diff
changeset
|
204 logopen(); |
0 | 205 |
208
3708b655a371
added newlines to the end of log and debug messages where missing
meillo@marmaro.de
parents:
205
diff
changeset
|
206 logwrite(LOG_NOTICE, "%s %s daemon starting\n", PACKAGE, VERSION); |
409 | 207 listen_port(do_listen ? conf.listen_addresses : NULL, |
208 queue_interval, argv); | |
0 | 209 } |
210 | |
264
1e5e457dea18
comments and a small refactoring
markus schnalke <meillo@marmaro.de>
parents:
263
diff
changeset
|
211 /* -bs or called as smtpd or in.smtpd */ |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
212 static void |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
213 mode_smtp() |
0 | 214 { |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
215 /* accept smtp message on stdin */ |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
216 /* write responses to stderr. */ |
0 | 217 |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
218 struct sockaddr_in saddr; |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
219 gchar *peername = NULL; |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
220 int dummy = sizeof(saddr); |
0 | 221 |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
222 conf.do_verbose = FALSE; |
0 | 223 |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
224 if (!conf.run_as_user) { |
331
e507c854a63e
Security fix! Correct handling of seteuid() return value
markus schnalke <meillo@marmaro.de>
parents:
310
diff
changeset
|
225 set_euidgid(conf.orig_uid, conf.orig_gid, NULL, NULL); |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
226 } |
0 | 227 |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
228 DEBUG(5) debugf("accepting smtp message on stdin\n"); |
0 | 229 |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
230 if (getpeername(0, (struct sockaddr *) (&saddr), &dummy) == 0) { |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
231 peername = g_strdup(inet_ntoa(saddr.sin_addr)); |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
232 } else if (errno != ENOTSOCK) |
262
fc1c6425c024
s/EXIT_SUCCESS/0/ && s/EXIT_FAILURE/1/
markus schnalke <meillo@marmaro.de>
parents:
261
diff
changeset
|
233 exit(1); |
0 | 234 |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
235 smtp_in(stdin, stderr, peername, NULL); |
0 | 236 } |
237 | |
264
1e5e457dea18
comments and a small refactoring
markus schnalke <meillo@marmaro.de>
parents:
263
diff
changeset
|
238 /* default mode if address args or -t is specified, or called as rmail */ |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
239 static void |
367
b27f66555ba8
Reformated multiline comments to have leading asterisks on each line
markus schnalke <meillo@marmaro.de>
parents:
366
diff
changeset
|
240 mode_accept(address *return_path, gchar *full_sender_name, guint accept_flags, |
b27f66555ba8
Reformated multiline comments to have leading asterisks on each line
markus schnalke <meillo@marmaro.de>
parents:
366
diff
changeset
|
241 char **addresses, int addr_cnt) |
0 | 242 { |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
243 /* accept message on stdin */ |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
244 accept_error err; |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
245 message *msg = create_message(); |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
246 gint i; |
266
ab39047ffe44
refactored mode_accept()
markus schnalke <meillo@marmaro.de>
parents:
264
diff
changeset
|
247 pid_t pid; |
0 | 248 |
83
085d6cd44462
using is_privileged_user() to check here too
meillo@marmaro.de
parents:
76
diff
changeset
|
249 if (return_path && !is_privileged_user(conf.orig_uid)) { |
409 | 250 fprintf(stderr, "must be root, %s or in group %s for " |
251 "setting return path.\n", | |
252 DEF_MAIL_USER, DEF_MAIL_GROUP); | |
262
fc1c6425c024
s/EXIT_SUCCESS/0/ && s/EXIT_FAILURE/1/
markus schnalke <meillo@marmaro.de>
parents:
261
diff
changeset
|
253 exit(1); |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
254 } |
0 | 255 |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
256 if (!conf.run_as_user) { |
331
e507c854a63e
Security fix! Correct handling of seteuid() return value
markus schnalke <meillo@marmaro.de>
parents:
310
diff
changeset
|
257 set_euidgid(conf.orig_uid, conf.orig_gid, NULL, NULL); |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
258 } |
0 | 259 |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
260 DEBUG(5) debugf("accepting message on stdin\n"); |
0 | 261 |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
262 msg->received_prot = PROT_LOCAL; |
276
1abc1faeb45d
for -t cmdline args are now added to the rcpt list instead of substracted
markus schnalke <meillo@marmaro.de>
parents:
268
diff
changeset
|
263 |
1abc1faeb45d
for -t cmdline args are now added to the rcpt list instead of substracted
markus schnalke <meillo@marmaro.de>
parents:
268
diff
changeset
|
264 /* warn if -t option and cmdline addr args */ |
1abc1faeb45d
for -t cmdline args are now added to the rcpt list instead of substracted
markus schnalke <meillo@marmaro.de>
parents:
268
diff
changeset
|
265 if (addr_cnt && (accept_flags & ACC_RCPT_FROM_HEAD)) { |
409 | 266 logwrite(LOG_ALERT, "command line address arguments are " |
267 "now *added* to the mail header\\\n"); | |
268 logwrite(LOG_ALERT, " recipient addresses (instead of " | |
269 "substracted) when -t is given.\\\n"); | |
276
1abc1faeb45d
for -t cmdline args are now added to the rcpt list instead of substracted
markus schnalke <meillo@marmaro.de>
parents:
268
diff
changeset
|
270 logwrite(LOG_ALERT, " this changed with version 0.3.1\n"); |
1abc1faeb45d
for -t cmdline args are now added to the rcpt list instead of substracted
markus schnalke <meillo@marmaro.de>
parents:
268
diff
changeset
|
271 } |
1abc1faeb45d
for -t cmdline args are now added to the rcpt list instead of substracted
markus schnalke <meillo@marmaro.de>
parents:
268
diff
changeset
|
272 |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
273 for (i = 0; i < addr_cnt; i++) { |
266
ab39047ffe44
refactored mode_accept()
markus schnalke <meillo@marmaro.de>
parents:
264
diff
changeset
|
274 if (addresses[i][0] == '|') { |
409 | 275 logwrite(LOG_ALERT, "no pipe allowed as recipient " |
276 "address: %s\n", addresses[i]); | |
276
1abc1faeb45d
for -t cmdline args are now added to the rcpt list instead of substracted
markus schnalke <meillo@marmaro.de>
parents:
268
diff
changeset
|
277 /* should we better ignore this one addr? */ |
262
fc1c6425c024
s/EXIT_SUCCESS/0/ && s/EXIT_FAILURE/1/
markus schnalke <meillo@marmaro.de>
parents:
261
diff
changeset
|
278 exit(1); |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
279 } |
409 | 280 msg->rcpt_list = g_list_append(msg->rcpt_list, |
281 create_address_qualified(addresses[i], | |
282 TRUE, conf.host_name)); | |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
283 } |
0 | 284 |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
285 /* -f option */ |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
286 msg->return_path = return_path; |
0 | 287 |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
288 /* -F option */ |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
289 msg->full_sender_name = full_sender_name; |
0 | 290 |
266
ab39047ffe44
refactored mode_accept()
markus schnalke <meillo@marmaro.de>
parents:
264
diff
changeset
|
291 err = accept_message(stdin, msg, accept_flags); |
ab39047ffe44
refactored mode_accept()
markus schnalke <meillo@marmaro.de>
parents:
264
diff
changeset
|
292 |
ab39047ffe44
refactored mode_accept()
markus schnalke <meillo@marmaro.de>
parents:
264
diff
changeset
|
293 switch (err) { |
ab39047ffe44
refactored mode_accept()
markus schnalke <meillo@marmaro.de>
parents:
264
diff
changeset
|
294 case AERR_OK: |
ab39047ffe44
refactored mode_accept()
markus schnalke <meillo@marmaro.de>
parents:
264
diff
changeset
|
295 /* to continue; all other cases exit */ |
ab39047ffe44
refactored mode_accept()
markus schnalke <meillo@marmaro.de>
parents:
264
diff
changeset
|
296 break; |
ab39047ffe44
refactored mode_accept()
markus schnalke <meillo@marmaro.de>
parents:
264
diff
changeset
|
297 case AERR_EOF: |
ab39047ffe44
refactored mode_accept()
markus schnalke <meillo@marmaro.de>
parents:
264
diff
changeset
|
298 fprintf(stderr, "unexpected EOF.\n"); |
ab39047ffe44
refactored mode_accept()
markus schnalke <meillo@marmaro.de>
parents:
264
diff
changeset
|
299 exit(1); |
ab39047ffe44
refactored mode_accept()
markus schnalke <meillo@marmaro.de>
parents:
264
diff
changeset
|
300 case AERR_NORCPT: |
ab39047ffe44
refactored mode_accept()
markus schnalke <meillo@marmaro.de>
parents:
264
diff
changeset
|
301 fprintf(stderr, "no recipients.\n"); |
ab39047ffe44
refactored mode_accept()
markus schnalke <meillo@marmaro.de>
parents:
264
diff
changeset
|
302 exit(1); |
ab39047ffe44
refactored mode_accept()
markus schnalke <meillo@marmaro.de>
parents:
264
diff
changeset
|
303 case AERR_SIZE: |
ab39047ffe44
refactored mode_accept()
markus schnalke <meillo@marmaro.de>
parents:
264
diff
changeset
|
304 fprintf(stderr, "max message size exceeded.\n"); |
ab39047ffe44
refactored mode_accept()
markus schnalke <meillo@marmaro.de>
parents:
264
diff
changeset
|
305 exit(1); |
ab39047ffe44
refactored mode_accept()
markus schnalke <meillo@marmaro.de>
parents:
264
diff
changeset
|
306 default: |
ab39047ffe44
refactored mode_accept()
markus schnalke <meillo@marmaro.de>
parents:
264
diff
changeset
|
307 /* should never happen: */ |
ab39047ffe44
refactored mode_accept()
markus schnalke <meillo@marmaro.de>
parents:
264
diff
changeset
|
308 fprintf(stderr, "Unknown error (%d)\r\n", err); |
ab39047ffe44
refactored mode_accept()
markus schnalke <meillo@marmaro.de>
parents:
264
diff
changeset
|
309 exit(1); |
ab39047ffe44
refactored mode_accept()
markus schnalke <meillo@marmaro.de>
parents:
264
diff
changeset
|
310 } |
0 | 311 |
266
ab39047ffe44
refactored mode_accept()
markus schnalke <meillo@marmaro.de>
parents:
264
diff
changeset
|
312 if (!spool_write(msg, TRUE)) { |
ab39047ffe44
refactored mode_accept()
markus schnalke <meillo@marmaro.de>
parents:
264
diff
changeset
|
313 fprintf(stderr, "Could not write spool file\n"); |
ab39047ffe44
refactored mode_accept()
markus schnalke <meillo@marmaro.de>
parents:
264
diff
changeset
|
314 exit(1); |
ab39047ffe44
refactored mode_accept()
markus schnalke <meillo@marmaro.de>
parents:
264
diff
changeset
|
315 } |
ab39047ffe44
refactored mode_accept()
markus schnalke <meillo@marmaro.de>
parents:
264
diff
changeset
|
316 |
267
8be687c06c20
comments (should we really exit failure in this case?)
markus schnalke <meillo@marmaro.de>
parents:
266
diff
changeset
|
317 /* here the mail is queued and thus in our responsibility */ |
409 | 318 logwrite(LOG_NOTICE, "%s <= %s with %s\n", msg->uid, |
319 addr_string(msg->return_path), prot_names[PROT_LOCAL]); | |
266
ab39047ffe44
refactored mode_accept()
markus schnalke <meillo@marmaro.de>
parents:
264
diff
changeset
|
320 |
ab39047ffe44
refactored mode_accept()
markus schnalke <meillo@marmaro.de>
parents:
264
diff
changeset
|
321 if (conf.do_queue) { |
ab39047ffe44
refactored mode_accept()
markus schnalke <meillo@marmaro.de>
parents:
264
diff
changeset
|
322 /* we're finished as we only need to queue it */ |
ab39047ffe44
refactored mode_accept()
markus schnalke <meillo@marmaro.de>
parents:
264
diff
changeset
|
323 return; |
ab39047ffe44
refactored mode_accept()
markus schnalke <meillo@marmaro.de>
parents:
264
diff
changeset
|
324 } |
ab39047ffe44
refactored mode_accept()
markus schnalke <meillo@marmaro.de>
parents:
264
diff
changeset
|
325 |
ab39047ffe44
refactored mode_accept()
markus schnalke <meillo@marmaro.de>
parents:
264
diff
changeset
|
326 /* deliver at once */ |
ab39047ffe44
refactored mode_accept()
markus schnalke <meillo@marmaro.de>
parents:
264
diff
changeset
|
327 if ((pid = fork()) < 0) { |
409 | 328 logwrite(LOG_ALERT, "could not fork for delivery, id = %s\n", |
329 msg->uid); | |
266
ab39047ffe44
refactored mode_accept()
markus schnalke <meillo@marmaro.de>
parents:
264
diff
changeset
|
330 } else if (pid == 0) { |
ab39047ffe44
refactored mode_accept()
markus schnalke <meillo@marmaro.de>
parents:
264
diff
changeset
|
331 conf.do_verbose = FALSE; |
ab39047ffe44
refactored mode_accept()
markus schnalke <meillo@marmaro.de>
parents:
264
diff
changeset
|
332 fclose(stdin); |
ab39047ffe44
refactored mode_accept()
markus schnalke <meillo@marmaro.de>
parents:
264
diff
changeset
|
333 fclose(stdout); |
ab39047ffe44
refactored mode_accept()
markus schnalke <meillo@marmaro.de>
parents:
264
diff
changeset
|
334 fclose(stderr); |
ab39047ffe44
refactored mode_accept()
markus schnalke <meillo@marmaro.de>
parents:
264
diff
changeset
|
335 if (deliver(msg)) { |
ab39047ffe44
refactored mode_accept()
markus schnalke <meillo@marmaro.de>
parents:
264
diff
changeset
|
336 exit(0); |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
337 } else { |
267
8be687c06c20
comments (should we really exit failure in this case?)
markus schnalke <meillo@marmaro.de>
parents:
266
diff
changeset
|
338 /* |
367
b27f66555ba8
Reformated multiline comments to have leading asterisks on each line
markus schnalke <meillo@marmaro.de>
parents:
366
diff
changeset
|
339 ** TODO: Should we really fail here? Because the |
b27f66555ba8
Reformated multiline comments to have leading asterisks on each line
markus schnalke <meillo@marmaro.de>
parents:
366
diff
changeset
|
340 ** mail is queued already. If we fail the client |
b27f66555ba8
Reformated multiline comments to have leading asterisks on each line
markus schnalke <meillo@marmaro.de>
parents:
366
diff
changeset
|
341 ** might submit it again. If at-once-delivery |
b27f66555ba8
Reformated multiline comments to have leading asterisks on each line
markus schnalke <meillo@marmaro.de>
parents:
366
diff
changeset
|
342 ** is seen as an additional best-effort service, |
b27f66555ba8
Reformated multiline comments to have leading asterisks on each line
markus schnalke <meillo@marmaro.de>
parents:
366
diff
changeset
|
343 ** then we should still exit successful here. |
267
8be687c06c20
comments (should we really exit failure in this case?)
markus schnalke <meillo@marmaro.de>
parents:
266
diff
changeset
|
344 */ |
262
fc1c6425c024
s/EXIT_SUCCESS/0/ && s/EXIT_FAILURE/1/
markus schnalke <meillo@marmaro.de>
parents:
261
diff
changeset
|
345 exit(1); |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
346 } |
0 | 347 } |
348 } | |
349 | |
250
a41c013c8458
moved the queue manipulation code to an new function
markus schnalke <meillo@marmaro.de>
parents:
249
diff
changeset
|
350 /* |
367
b27f66555ba8
Reformated multiline comments to have leading asterisks on each line
markus schnalke <meillo@marmaro.de>
parents:
366
diff
changeset
|
351 ** if -Mrm is given |
b27f66555ba8
Reformated multiline comments to have leading asterisks on each line
markus schnalke <meillo@marmaro.de>
parents:
366
diff
changeset
|
352 ** |
b27f66555ba8
Reformated multiline comments to have leading asterisks on each line
markus schnalke <meillo@marmaro.de>
parents:
366
diff
changeset
|
353 ** currently only the `rm' command is supported |
b27f66555ba8
Reformated multiline comments to have leading asterisks on each line
markus schnalke <meillo@marmaro.de>
parents:
366
diff
changeset
|
354 ** until this changes, we don't need any facility for further commands |
b27f66555ba8
Reformated multiline comments to have leading asterisks on each line
markus schnalke <meillo@marmaro.de>
parents:
366
diff
changeset
|
355 ** return success if at least one message had been deleted |
250
a41c013c8458
moved the queue manipulation code to an new function
markus schnalke <meillo@marmaro.de>
parents:
249
diff
changeset
|
356 */ |
a41c013c8458
moved the queue manipulation code to an new function
markus schnalke <meillo@marmaro.de>
parents:
249
diff
changeset
|
357 static int |
366
41958685480d
Switched to `type *name' style
markus schnalke <meillo@marmaro.de>
parents:
349
diff
changeset
|
358 manipulate_queue(char *cmd, char *id[]) |
250
a41c013c8458
moved the queue manipulation code to an new function
markus schnalke <meillo@marmaro.de>
parents:
249
diff
changeset
|
359 { |
a41c013c8458
moved the queue manipulation code to an new function
markus schnalke <meillo@marmaro.de>
parents:
249
diff
changeset
|
360 gboolean ok = FALSE; |
a41c013c8458
moved the queue manipulation code to an new function
markus schnalke <meillo@marmaro.de>
parents:
249
diff
changeset
|
361 |
a41c013c8458
moved the queue manipulation code to an new function
markus schnalke <meillo@marmaro.de>
parents:
249
diff
changeset
|
362 if (strcmp(cmd, "rm") != 0) { |
a41c013c8458
moved the queue manipulation code to an new function
markus schnalke <meillo@marmaro.de>
parents:
249
diff
changeset
|
363 fprintf(stderr, "unknown command %s\n", cmd); |
a41c013c8458
moved the queue manipulation code to an new function
markus schnalke <meillo@marmaro.de>
parents:
249
diff
changeset
|
364 return FALSE; |
a41c013c8458
moved the queue manipulation code to an new function
markus schnalke <meillo@marmaro.de>
parents:
249
diff
changeset
|
365 } |
a41c013c8458
moved the queue manipulation code to an new function
markus schnalke <meillo@marmaro.de>
parents:
249
diff
changeset
|
366 |
a41c013c8458
moved the queue manipulation code to an new function
markus schnalke <meillo@marmaro.de>
parents:
249
diff
changeset
|
367 set_euidgid(conf.mail_uid, conf.mail_gid, NULL, NULL); |
a41c013c8458
moved the queue manipulation code to an new function
markus schnalke <meillo@marmaro.de>
parents:
249
diff
changeset
|
368 |
a41c013c8458
moved the queue manipulation code to an new function
markus schnalke <meillo@marmaro.de>
parents:
249
diff
changeset
|
369 /* privileged users may delete any mail */ |
a41c013c8458
moved the queue manipulation code to an new function
markus schnalke <meillo@marmaro.de>
parents:
249
diff
changeset
|
370 if (is_privileged_user(conf.orig_uid)) { |
a41c013c8458
moved the queue manipulation code to an new function
markus schnalke <meillo@marmaro.de>
parents:
249
diff
changeset
|
371 for (; *id; id++) { |
a41c013c8458
moved the queue manipulation code to an new function
markus schnalke <meillo@marmaro.de>
parents:
249
diff
changeset
|
372 fprintf(stderr, "id: %s\n", *id); |
a41c013c8458
moved the queue manipulation code to an new function
markus schnalke <meillo@marmaro.de>
parents:
249
diff
changeset
|
373 if (queue_delete(*id)) { |
a41c013c8458
moved the queue manipulation code to an new function
markus schnalke <meillo@marmaro.de>
parents:
249
diff
changeset
|
374 ok = TRUE; |
a41c013c8458
moved the queue manipulation code to an new function
markus schnalke <meillo@marmaro.de>
parents:
249
diff
changeset
|
375 } |
a41c013c8458
moved the queue manipulation code to an new function
markus schnalke <meillo@marmaro.de>
parents:
249
diff
changeset
|
376 } |
a41c013c8458
moved the queue manipulation code to an new function
markus schnalke <meillo@marmaro.de>
parents:
249
diff
changeset
|
377 return ok; |
a41c013c8458
moved the queue manipulation code to an new function
markus schnalke <meillo@marmaro.de>
parents:
249
diff
changeset
|
378 } |
a41c013c8458
moved the queue manipulation code to an new function
markus schnalke <meillo@marmaro.de>
parents:
249
diff
changeset
|
379 |
a41c013c8458
moved the queue manipulation code to an new function
markus schnalke <meillo@marmaro.de>
parents:
249
diff
changeset
|
380 struct passwd *pw = getpwuid(conf.orig_uid); |
a41c013c8458
moved the queue manipulation code to an new function
markus schnalke <meillo@marmaro.de>
parents:
249
diff
changeset
|
381 if (!pw) { |
409 | 382 fprintf(stderr, "could not find a passwd entry for " |
383 "uid %d: %s\n", | |
384 conf.orig_uid, strerror(errno)); | |
250
a41c013c8458
moved the queue manipulation code to an new function
markus schnalke <meillo@marmaro.de>
parents:
249
diff
changeset
|
385 return FALSE; |
a41c013c8458
moved the queue manipulation code to an new function
markus schnalke <meillo@marmaro.de>
parents:
249
diff
changeset
|
386 } |
a41c013c8458
moved the queue manipulation code to an new function
markus schnalke <meillo@marmaro.de>
parents:
249
diff
changeset
|
387 |
a41c013c8458
moved the queue manipulation code to an new function
markus schnalke <meillo@marmaro.de>
parents:
249
diff
changeset
|
388 /* non-privileged users may only delete their own messages */ |
a41c013c8458
moved the queue manipulation code to an new function
markus schnalke <meillo@marmaro.de>
parents:
249
diff
changeset
|
389 for (; *id; id++) { |
349
b45dc53f2829
Removed unused second arg of msg_spool_read()
markus schnalke <meillo@marmaro.de>
parents:
331
diff
changeset
|
390 message *msg = msg_spool_read(*id); |
250
a41c013c8458
moved the queue manipulation code to an new function
markus schnalke <meillo@marmaro.de>
parents:
249
diff
changeset
|
391 |
a41c013c8458
moved the queue manipulation code to an new function
markus schnalke <meillo@marmaro.de>
parents:
249
diff
changeset
|
392 fprintf(stderr, "id: %s\n", *id); |
a41c013c8458
moved the queue manipulation code to an new function
markus schnalke <meillo@marmaro.de>
parents:
249
diff
changeset
|
393 |
a41c013c8458
moved the queue manipulation code to an new function
markus schnalke <meillo@marmaro.de>
parents:
249
diff
changeset
|
394 if (!msg->ident) { |
409 | 395 fprintf(stderr, "message %s does not have an ident\n", |
396 *id); | |
250
a41c013c8458
moved the queue manipulation code to an new function
markus schnalke <meillo@marmaro.de>
parents:
249
diff
changeset
|
397 continue; |
a41c013c8458
moved the queue manipulation code to an new function
markus schnalke <meillo@marmaro.de>
parents:
249
diff
changeset
|
398 } |
a41c013c8458
moved the queue manipulation code to an new function
markus schnalke <meillo@marmaro.de>
parents:
249
diff
changeset
|
399 if (strcmp(pw->pw_name, msg->ident) != 0) { |
a41c013c8458
moved the queue manipulation code to an new function
markus schnalke <meillo@marmaro.de>
parents:
249
diff
changeset
|
400 fprintf(stderr, "you do not own message id %s\n", *id); |
a41c013c8458
moved the queue manipulation code to an new function
markus schnalke <meillo@marmaro.de>
parents:
249
diff
changeset
|
401 continue; |
a41c013c8458
moved the queue manipulation code to an new function
markus schnalke <meillo@marmaro.de>
parents:
249
diff
changeset
|
402 } |
a41c013c8458
moved the queue manipulation code to an new function
markus schnalke <meillo@marmaro.de>
parents:
249
diff
changeset
|
403 |
378
5781ba87df95
Removed ident. This had been discussed on the mailing list in Oct 2011.
markus schnalke <meillo@marmaro.de>
parents:
367
diff
changeset
|
404 if (msg->received_host || (msg->received_prot != PROT_LOCAL)) { |
409 | 405 fprintf(stderr, "message %s was not received " |
406 "locally\n", *id); | |
250
a41c013c8458
moved the queue manipulation code to an new function
markus schnalke <meillo@marmaro.de>
parents:
249
diff
changeset
|
407 continue; |
a41c013c8458
moved the queue manipulation code to an new function
markus schnalke <meillo@marmaro.de>
parents:
249
diff
changeset
|
408 } |
a41c013c8458
moved the queue manipulation code to an new function
markus schnalke <meillo@marmaro.de>
parents:
249
diff
changeset
|
409 |
a41c013c8458
moved the queue manipulation code to an new function
markus schnalke <meillo@marmaro.de>
parents:
249
diff
changeset
|
410 ok = queue_delete(*id); |
a41c013c8458
moved the queue manipulation code to an new function
markus schnalke <meillo@marmaro.de>
parents:
249
diff
changeset
|
411 } |
a41c013c8458
moved the queue manipulation code to an new function
markus schnalke <meillo@marmaro.de>
parents:
249
diff
changeset
|
412 return ok; |
a41c013c8458
moved the queue manipulation code to an new function
markus schnalke <meillo@marmaro.de>
parents:
249
diff
changeset
|
413 } |
a41c013c8458
moved the queue manipulation code to an new function
markus schnalke <meillo@marmaro.de>
parents:
249
diff
changeset
|
414 |
264
1e5e457dea18
comments and a small refactoring
markus schnalke <meillo@marmaro.de>
parents:
263
diff
changeset
|
415 /* -qo, -q (without argument), or called as runq */ |
251
2babd21e7c75
moved run_queue to a new function
markus schnalke <meillo@marmaro.de>
parents:
250
diff
changeset
|
416 static int |
366
41958685480d
Switched to `type *name' style
markus schnalke <meillo@marmaro.de>
parents:
349
diff
changeset
|
417 run_queue(gboolean do_runq, gboolean do_runq_online, char *route_name) |
251
2babd21e7c75
moved run_queue to a new function
markus schnalke <meillo@marmaro.de>
parents:
250
diff
changeset
|
418 { |
2babd21e7c75
moved run_queue to a new function
markus schnalke <meillo@marmaro.de>
parents:
250
diff
changeset
|
419 int ret; |
2babd21e7c75
moved run_queue to a new function
markus schnalke <meillo@marmaro.de>
parents:
250
diff
changeset
|
420 |
2babd21e7c75
moved run_queue to a new function
markus schnalke <meillo@marmaro.de>
parents:
250
diff
changeset
|
421 /* queue runs */ |
2babd21e7c75
moved run_queue to a new function
markus schnalke <meillo@marmaro.de>
parents:
250
diff
changeset
|
422 set_identity(conf.orig_uid, "queue run"); |
2babd21e7c75
moved run_queue to a new function
markus schnalke <meillo@marmaro.de>
parents:
250
diff
changeset
|
423 |
2babd21e7c75
moved run_queue to a new function
markus schnalke <meillo@marmaro.de>
parents:
250
diff
changeset
|
424 if (do_runq) { |
2babd21e7c75
moved run_queue to a new function
markus schnalke <meillo@marmaro.de>
parents:
250
diff
changeset
|
425 ret = queue_run(); |
2babd21e7c75
moved run_queue to a new function
markus schnalke <meillo@marmaro.de>
parents:
250
diff
changeset
|
426 } |
2babd21e7c75
moved run_queue to a new function
markus schnalke <meillo@marmaro.de>
parents:
250
diff
changeset
|
427 |
2babd21e7c75
moved run_queue to a new function
markus schnalke <meillo@marmaro.de>
parents:
250
diff
changeset
|
428 if (do_runq_online) { |
2babd21e7c75
moved run_queue to a new function
markus schnalke <meillo@marmaro.de>
parents:
250
diff
changeset
|
429 if (route_name) { |
409 | 430 conf.online_query = g_strdup_printf("/bin/echo %s", |
431 route_name); | |
251
2babd21e7c75
moved run_queue to a new function
markus schnalke <meillo@marmaro.de>
parents:
250
diff
changeset
|
432 } |
367
b27f66555ba8
Reformated multiline comments to have leading asterisks on each line
markus schnalke <meillo@marmaro.de>
parents:
366
diff
changeset
|
433 /* |
b27f66555ba8
Reformated multiline comments to have leading asterisks on each line
markus schnalke <meillo@marmaro.de>
parents:
366
diff
changeset
|
434 ** TODO: change behavior of `-qo without argument'? |
b27f66555ba8
Reformated multiline comments to have leading asterisks on each line
markus schnalke <meillo@marmaro.de>
parents:
366
diff
changeset
|
435 ** Because that behavior is included in -q. |
b27f66555ba8
Reformated multiline comments to have leading asterisks on each line
markus schnalke <meillo@marmaro.de>
parents:
366
diff
changeset
|
436 */ |
251
2babd21e7c75
moved run_queue to a new function
markus schnalke <meillo@marmaro.de>
parents:
250
diff
changeset
|
437 ret = queue_run_online(); |
2babd21e7c75
moved run_queue to a new function
markus schnalke <meillo@marmaro.de>
parents:
250
diff
changeset
|
438 } |
2babd21e7c75
moved run_queue to a new function
markus schnalke <meillo@marmaro.de>
parents:
250
diff
changeset
|
439 return ret; |
2babd21e7c75
moved run_queue to a new function
markus schnalke <meillo@marmaro.de>
parents:
250
diff
changeset
|
440 } |
2babd21e7c75
moved run_queue to a new function
markus schnalke <meillo@marmaro.de>
parents:
250
diff
changeset
|
441 |
264
1e5e457dea18
comments and a small refactoring
markus schnalke <meillo@marmaro.de>
parents:
263
diff
changeset
|
442 /* -bV or default mode if neither addr arg nor -t */ |
261
0afe18a9ee03
fixed previous commit and excluded mode_version() from main()
markus schnalke <meillo@marmaro.de>
parents:
260
diff
changeset
|
443 static void |
0afe18a9ee03
fixed previous commit and excluded mode_version() from main()
markus schnalke <meillo@marmaro.de>
parents:
260
diff
changeset
|
444 mode_version(void) |
0afe18a9ee03
fixed previous commit and excluded mode_version() from main()
markus schnalke <meillo@marmaro.de>
parents:
260
diff
changeset
|
445 { |
0afe18a9ee03
fixed previous commit and excluded mode_version() from main()
markus schnalke <meillo@marmaro.de>
parents:
260
diff
changeset
|
446 gchar *with_resolver = ""; |
0afe18a9ee03
fixed previous commit and excluded mode_version() from main()
markus schnalke <meillo@marmaro.de>
parents:
260
diff
changeset
|
447 gchar *with_auth = ""; |
0afe18a9ee03
fixed previous commit and excluded mode_version() from main()
markus schnalke <meillo@marmaro.de>
parents:
260
diff
changeset
|
448 |
0afe18a9ee03
fixed previous commit and excluded mode_version() from main()
markus schnalke <meillo@marmaro.de>
parents:
260
diff
changeset
|
449 #ifdef ENABLE_RESOLVER |
0afe18a9ee03
fixed previous commit and excluded mode_version() from main()
markus schnalke <meillo@marmaro.de>
parents:
260
diff
changeset
|
450 with_resolver = " +resolver"; |
0afe18a9ee03
fixed previous commit and excluded mode_version() from main()
markus schnalke <meillo@marmaro.de>
parents:
260
diff
changeset
|
451 #endif |
0afe18a9ee03
fixed previous commit and excluded mode_version() from main()
markus schnalke <meillo@marmaro.de>
parents:
260
diff
changeset
|
452 #ifdef ENABLE_AUTH |
0afe18a9ee03
fixed previous commit and excluded mode_version() from main()
markus schnalke <meillo@marmaro.de>
parents:
260
diff
changeset
|
453 with_auth = " +auth"; |
0afe18a9ee03
fixed previous commit and excluded mode_version() from main()
markus schnalke <meillo@marmaro.de>
parents:
260
diff
changeset
|
454 #endif |
0afe18a9ee03
fixed previous commit and excluded mode_version() from main()
markus schnalke <meillo@marmaro.de>
parents:
260
diff
changeset
|
455 |
378
5781ba87df95
Removed ident. This had been discussed on the mailing list in Oct 2011.
markus schnalke <meillo@marmaro.de>
parents:
367
diff
changeset
|
456 printf("%s %s%s%s\n", PACKAGE, VERSION, with_resolver, with_auth); |
261
0afe18a9ee03
fixed previous commit and excluded mode_version() from main()
markus schnalke <meillo@marmaro.de>
parents:
260
diff
changeset
|
457 } |
0afe18a9ee03
fixed previous commit and excluded mode_version() from main()
markus schnalke <meillo@marmaro.de>
parents:
260
diff
changeset
|
458 |
281
ea5f86e0a81c
modes are now enforced exclusive
markus schnalke <meillo@marmaro.de>
parents:
278
diff
changeset
|
459 void |
ea5f86e0a81c
modes are now enforced exclusive
markus schnalke <meillo@marmaro.de>
parents:
278
diff
changeset
|
460 set_mode(enum mta_mode mode) |
ea5f86e0a81c
modes are now enforced exclusive
markus schnalke <meillo@marmaro.de>
parents:
278
diff
changeset
|
461 { |
ea5f86e0a81c
modes are now enforced exclusive
markus schnalke <meillo@marmaro.de>
parents:
278
diff
changeset
|
462 if (mta_mode && mta_mode!=mode) { |
409 | 463 fprintf(stderr, "operation mode was already specified " |
464 "(%d vs. %d)\n", mta_mode, mode); | |
281
ea5f86e0a81c
modes are now enforced exclusive
markus schnalke <meillo@marmaro.de>
parents:
278
diff
changeset
|
465 exit(1); |
ea5f86e0a81c
modes are now enforced exclusive
markus schnalke <meillo@marmaro.de>
parents:
278
diff
changeset
|
466 } |
ea5f86e0a81c
modes are now enforced exclusive
markus schnalke <meillo@marmaro.de>
parents:
278
diff
changeset
|
467 |
ea5f86e0a81c
modes are now enforced exclusive
markus schnalke <meillo@marmaro.de>
parents:
278
diff
changeset
|
468 mta_mode = mode; |
ea5f86e0a81c
modes are now enforced exclusive
markus schnalke <meillo@marmaro.de>
parents:
278
diff
changeset
|
469 return; |
ea5f86e0a81c
modes are now enforced exclusive
markus schnalke <meillo@marmaro.de>
parents:
278
diff
changeset
|
470 } |
ea5f86e0a81c
modes are now enforced exclusive
markus schnalke <meillo@marmaro.de>
parents:
278
diff
changeset
|
471 |
0 | 472 int |
473 main(int argc, char *argv[]) | |
474 { | |
251
2babd21e7c75
moved run_queue to a new function
markus schnalke <meillo@marmaro.de>
parents:
250
diff
changeset
|
475 gchar *progname; |
366
41958685480d
Switched to `type *name' style
markus schnalke <meillo@marmaro.de>
parents:
349
diff
changeset
|
476 char *opt; |
249
f9da5a7caeda
refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents:
248
diff
changeset
|
477 gint arg; |
0 | 478 |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
479 gboolean do_listen = FALSE; |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
480 gboolean do_runq = FALSE; |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
481 gboolean do_runq_online = FALSE; |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
482 gboolean do_queue = FALSE; |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
483 gint queue_interval = 0; |
251
2babd21e7c75
moved run_queue to a new function
markus schnalke <meillo@marmaro.de>
parents:
250
diff
changeset
|
484 gchar *M_cmd = NULL; |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
485 gboolean opt_t = FALSE; |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
486 gboolean opt_i = FALSE; |
251
2babd21e7c75
moved run_queue to a new function
markus schnalke <meillo@marmaro.de>
parents:
250
diff
changeset
|
487 gchar *conf_file = CONF_FILE; |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
488 gchar *route_name = NULL; |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
489 gchar *f_address = NULL; |
251
2babd21e7c75
moved run_queue to a new function
markus schnalke <meillo@marmaro.de>
parents:
250
diff
changeset
|
490 address *return_path = NULL; /* may be changed by -f option */ |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
491 gchar *full_sender_name = NULL; |
251
2babd21e7c75
moved run_queue to a new function
markus schnalke <meillo@marmaro.de>
parents:
250
diff
changeset
|
492 gboolean do_verbose = FALSE; |
2babd21e7c75
moved run_queue to a new function
markus schnalke <meillo@marmaro.de>
parents:
250
diff
changeset
|
493 gint debug_level = -1; |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
494 |
260
bd3109ec0f0a
substituted get_progname() with a call to strrchr()
markus schnalke <meillo@marmaro.de>
parents:
259
diff
changeset
|
495 /* strip the path part */ |
261
0afe18a9ee03
fixed previous commit and excluded mode_version() from main()
markus schnalke <meillo@marmaro.de>
parents:
260
diff
changeset
|
496 progname = strrchr(argv[0], '/'); |
0afe18a9ee03
fixed previous commit and excluded mode_version() from main()
markus schnalke <meillo@marmaro.de>
parents:
260
diff
changeset
|
497 progname = (progname) ? progname+1 : argv[0]; |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
498 |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
499 if (strcmp(progname, "mailq") == 0) { |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
500 mta_mode = MODE_LIST; |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
501 } else if (strcmp(progname, "mailrm") == 0) { |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
502 mta_mode = MODE_MCMD; |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
503 M_cmd = "rm"; |
284
4869321aa7bf
recognize the program name `newaliases' too
markus schnalke <meillo@marmaro.de>
parents:
282
diff
changeset
|
504 } else if (strcmp(progname, "newaliases") == 0) { |
4869321aa7bf
recognize the program name `newaliases' too
markus schnalke <meillo@marmaro.de>
parents:
282
diff
changeset
|
505 mta_mode = MODE_BI; |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
506 } else if (strcmp(progname, "rmail") == 0) { |
367
b27f66555ba8
Reformated multiline comments to have leading asterisks on each line
markus schnalke <meillo@marmaro.de>
parents:
366
diff
changeset
|
507 /* |
b27f66555ba8
Reformated multiline comments to have leading asterisks on each line
markus schnalke <meillo@marmaro.de>
parents:
366
diff
changeset
|
508 ** the `rmail' alias should probably be removed now |
b27f66555ba8
Reformated multiline comments to have leading asterisks on each line
markus schnalke <meillo@marmaro.de>
parents:
366
diff
changeset
|
509 ** that we have the rmail script. But let's keep it |
b27f66555ba8
Reformated multiline comments to have leading asterisks on each line
markus schnalke <meillo@marmaro.de>
parents:
366
diff
changeset
|
510 ** for some while for compatibility. 2010-06-19 |
b27f66555ba8
Reformated multiline comments to have leading asterisks on each line
markus schnalke <meillo@marmaro.de>
parents:
366
diff
changeset
|
511 */ |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
512 mta_mode = MODE_ACCEPT; |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
513 opt_i = TRUE; |
284
4869321aa7bf
recognize the program name `newaliases' too
markus schnalke <meillo@marmaro.de>
parents:
282
diff
changeset
|
514 } else if (strcmp(progname, "runq") == 0) { |
4869321aa7bf
recognize the program name `newaliases' too
markus schnalke <meillo@marmaro.de>
parents:
282
diff
changeset
|
515 mta_mode = MODE_RUNQUEUE; |
4869321aa7bf
recognize the program name `newaliases' too
markus schnalke <meillo@marmaro.de>
parents:
282
diff
changeset
|
516 do_runq = TRUE; |
4869321aa7bf
recognize the program name `newaliases' too
markus schnalke <meillo@marmaro.de>
parents:
282
diff
changeset
|
517 } else if (strcmp(progname, "smtpd") == 0 |
4869321aa7bf
recognize the program name `newaliases' too
markus schnalke <meillo@marmaro.de>
parents:
282
diff
changeset
|
518 || strcmp(progname, "in.smtpd") == 0) { |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
519 mta_mode = MODE_SMTP; |
0 | 520 } |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
521 |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
522 /* parse cmd line */ |
249
f9da5a7caeda
refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents:
248
diff
changeset
|
523 for (arg=1; arg<argc && argv[arg][0]=='-'; arg++) { |
251
2babd21e7c75
moved run_queue to a new function
markus schnalke <meillo@marmaro.de>
parents:
250
diff
changeset
|
524 opt = argv[arg] + 1; /* points to the char after the dash */ |
249
f9da5a7caeda
refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents:
248
diff
changeset
|
525 |
f9da5a7caeda
refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents:
248
diff
changeset
|
526 if (strcmp(opt, "-") == 0) { |
f9da5a7caeda
refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents:
248
diff
changeset
|
527 /* everything after `--' are address arguments */ |
f9da5a7caeda
refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents:
248
diff
changeset
|
528 arg++; |
f9da5a7caeda
refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents:
248
diff
changeset
|
529 break; |
f9da5a7caeda
refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents:
248
diff
changeset
|
530 |
278
c35c59a36a2a
added -bm for mode accept (the other MTAs have it too)
markus schnalke <meillo@marmaro.de>
parents:
276
diff
changeset
|
531 } else if (strcmp(opt, "bm") == 0) { |
281
ea5f86e0a81c
modes are now enforced exclusive
markus schnalke <meillo@marmaro.de>
parents:
278
diff
changeset
|
532 set_mode(MODE_ACCEPT); |
278
c35c59a36a2a
added -bm for mode accept (the other MTAs have it too)
markus schnalke <meillo@marmaro.de>
parents:
276
diff
changeset
|
533 |
249
f9da5a7caeda
refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents:
248
diff
changeset
|
534 } else if (strcmp(opt, "bd") == 0) { |
281
ea5f86e0a81c
modes are now enforced exclusive
markus schnalke <meillo@marmaro.de>
parents:
278
diff
changeset
|
535 set_mode(MODE_DAEMON); |
249
f9da5a7caeda
refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents:
248
diff
changeset
|
536 do_listen = TRUE; |
f9da5a7caeda
refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents:
248
diff
changeset
|
537 |
f9da5a7caeda
refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents:
248
diff
changeset
|
538 } else if (strcmp(opt, "bi") == 0) { |
281
ea5f86e0a81c
modes are now enforced exclusive
markus schnalke <meillo@marmaro.de>
parents:
278
diff
changeset
|
539 set_mode(MODE_BI); |
249
f9da5a7caeda
refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents:
248
diff
changeset
|
540 |
f9da5a7caeda
refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents:
248
diff
changeset
|
541 } else if (strcmp(opt, "bs") == 0) { |
281
ea5f86e0a81c
modes are now enforced exclusive
markus schnalke <meillo@marmaro.de>
parents:
278
diff
changeset
|
542 set_mode(MODE_SMTP); |
249
f9da5a7caeda
refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents:
248
diff
changeset
|
543 |
f9da5a7caeda
refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents:
248
diff
changeset
|
544 } else if (strcmp(opt, "bp") == 0) { |
281
ea5f86e0a81c
modes are now enforced exclusive
markus schnalke <meillo@marmaro.de>
parents:
278
diff
changeset
|
545 set_mode(MODE_LIST); |
249
f9da5a7caeda
refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents:
248
diff
changeset
|
546 |
f9da5a7caeda
refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents:
248
diff
changeset
|
547 } else if (strcmp(opt, "bV") == 0) { |
281
ea5f86e0a81c
modes are now enforced exclusive
markus schnalke <meillo@marmaro.de>
parents:
278
diff
changeset
|
548 set_mode(MODE_VERSION); |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
549 |
249
f9da5a7caeda
refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents:
248
diff
changeset
|
550 } else if (strncmp(opt, "B", 1) == 0) { |
f9da5a7caeda
refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents:
248
diff
changeset
|
551 /* we ignore this and throw the argument away */ |
f9da5a7caeda
refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents:
248
diff
changeset
|
552 get_optarg(argv, &arg, opt+1); |
f9da5a7caeda
refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents:
248
diff
changeset
|
553 |
f9da5a7caeda
refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents:
248
diff
changeset
|
554 } else if (strncmp(opt, "C", 1) == 0) { |
251
2babd21e7c75
moved run_queue to a new function
markus schnalke <meillo@marmaro.de>
parents:
250
diff
changeset
|
555 conf_file = get_optarg(argv, &arg, opt+1); |
2babd21e7c75
moved run_queue to a new function
markus schnalke <meillo@marmaro.de>
parents:
250
diff
changeset
|
556 if (!conf_file) { |
409 | 557 fprintf(stderr, "-C requires filename arg.\n"); |
262
fc1c6425c024
s/EXIT_SUCCESS/0/ && s/EXIT_FAILURE/1/
markus schnalke <meillo@marmaro.de>
parents:
261
diff
changeset
|
558 exit(1); |
249
f9da5a7caeda
refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents:
248
diff
changeset
|
559 } |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
560 |
249
f9da5a7caeda
refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents:
248
diff
changeset
|
561 } else if (strncmp(opt, "d", 1) == 0) { |
f9da5a7caeda
refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents:
248
diff
changeset
|
562 if (getuid() != 0) { |
409 | 563 fprintf(stderr, "only root may set the " |
564 "debug level.\n"); | |
262
fc1c6425c024
s/EXIT_SUCCESS/0/ && s/EXIT_FAILURE/1/
markus schnalke <meillo@marmaro.de>
parents:
261
diff
changeset
|
565 exit(1); |
249
f9da5a7caeda
refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents:
248
diff
changeset
|
566 } |
f9da5a7caeda
refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents:
248
diff
changeset
|
567 char *lvl = get_optarg(argv, &arg, opt+1); |
f9da5a7caeda
refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents:
248
diff
changeset
|
568 if (!lvl) { |
409 | 569 fprintf(stderr, "-d requires number arg.\n"); |
262
fc1c6425c024
s/EXIT_SUCCESS/0/ && s/EXIT_FAILURE/1/
markus schnalke <meillo@marmaro.de>
parents:
261
diff
changeset
|
570 exit(1); |
249
f9da5a7caeda
refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents:
248
diff
changeset
|
571 } |
f9da5a7caeda
refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents:
248
diff
changeset
|
572 debug_level = atoi(lvl); |
f9da5a7caeda
refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents:
248
diff
changeset
|
573 |
f9da5a7caeda
refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents:
248
diff
changeset
|
574 } else if (strncmp(opt, "f", 1) == 0) { |
f9da5a7caeda
refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents:
248
diff
changeset
|
575 /* set return path */ |
f9da5a7caeda
refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents:
248
diff
changeset
|
576 gchar *address = get_optarg(argv, &arg, opt+1); |
f9da5a7caeda
refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents:
248
diff
changeset
|
577 if (!address) { |
409 | 578 fprintf(stderr, "-f requires address arg.\n"); |
262
fc1c6425c024
s/EXIT_SUCCESS/0/ && s/EXIT_FAILURE/1/
markus schnalke <meillo@marmaro.de>
parents:
261
diff
changeset
|
579 exit(1); |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
580 } |
249
f9da5a7caeda
refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents:
248
diff
changeset
|
581 f_address = g_strdup(address); |
f9da5a7caeda
refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents:
248
diff
changeset
|
582 |
f9da5a7caeda
refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents:
248
diff
changeset
|
583 } else if (strncmp(opt, "F", 1) == 0) { |
f9da5a7caeda
refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents:
248
diff
changeset
|
584 full_sender_name = get_optarg(argv, &arg, opt+1); |
f9da5a7caeda
refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents:
248
diff
changeset
|
585 if (!full_sender_name) { |
409 | 586 fprintf(stderr, "-F requires name arg.\n"); |
262
fc1c6425c024
s/EXIT_SUCCESS/0/ && s/EXIT_FAILURE/1/
markus schnalke <meillo@marmaro.de>
parents:
261
diff
changeset
|
587 exit(1); |
249
f9da5a7caeda
refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents:
248
diff
changeset
|
588 } |
f9da5a7caeda
refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents:
248
diff
changeset
|
589 |
f9da5a7caeda
refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents:
248
diff
changeset
|
590 } else if (strcmp(opt, "i") == 0) { |
f9da5a7caeda
refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents:
248
diff
changeset
|
591 opt_i = TRUE; |
f9da5a7caeda
refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents:
248
diff
changeset
|
592 |
f9da5a7caeda
refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents:
248
diff
changeset
|
593 } else if (strcmp(opt, "m") == 0) { |
f9da5a7caeda
refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents:
248
diff
changeset
|
594 /* ignore -m (me too) switch (see man page) */ |
f9da5a7caeda
refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents:
248
diff
changeset
|
595 |
f9da5a7caeda
refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents:
248
diff
changeset
|
596 } else if (strcmp(opt, "Mrm") == 0) { |
281
ea5f86e0a81c
modes are now enforced exclusive
markus schnalke <meillo@marmaro.de>
parents:
278
diff
changeset
|
597 set_mode(MODE_MCMD); |
249
f9da5a7caeda
refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents:
248
diff
changeset
|
598 M_cmd = "rm"; |
f9da5a7caeda
refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents:
248
diff
changeset
|
599 |
f9da5a7caeda
refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents:
248
diff
changeset
|
600 } else if (strcmp(opt, "odq") == 0) { |
f9da5a7caeda
refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents:
248
diff
changeset
|
601 do_queue = TRUE; |
f9da5a7caeda
refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents:
248
diff
changeset
|
602 |
f9da5a7caeda
refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents:
248
diff
changeset
|
603 } else if (strcmp(opt, "oi") == 0) { |
257
8cca5305e4f0
fixed -oi to really be the same as -i
markus schnalke <meillo@marmaro.de>
parents:
254
diff
changeset
|
604 opt_i = TRUE; |
249
f9da5a7caeda
refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents:
248
diff
changeset
|
605 |
f9da5a7caeda
refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents:
248
diff
changeset
|
606 } else if (strncmp(opt, "o", 1) == 0) { |
f9da5a7caeda
refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents:
248
diff
changeset
|
607 /* ignore all other -oXXX options */ |
f9da5a7caeda
refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents:
248
diff
changeset
|
608 |
f9da5a7caeda
refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents:
248
diff
changeset
|
609 } else if (strncmp(opt, "qo", 2) == 0) { |
278
c35c59a36a2a
added -bm for mode accept (the other MTAs have it too)
markus schnalke <meillo@marmaro.de>
parents:
276
diff
changeset
|
610 /* must be before the `q' check */ |
281
ea5f86e0a81c
modes are now enforced exclusive
markus schnalke <meillo@marmaro.de>
parents:
278
diff
changeset
|
611 set_mode(MODE_RUNQUEUE); |
249
f9da5a7caeda
refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents:
248
diff
changeset
|
612 do_runq_online = TRUE; |
f9da5a7caeda
refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents:
248
diff
changeset
|
613 /* can be NULL, then we use online detection method */ |
290
792e0201c1b3
mark -qo (without argument) obsolete
markus schnalke <meillo@marmaro.de>
parents:
288
diff
changeset
|
614 /* TODO: behavior might change if it is NULL */ |
249
f9da5a7caeda
refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents:
248
diff
changeset
|
615 route_name = get_optarg(argv, &arg, opt+2); |
290
792e0201c1b3
mark -qo (without argument) obsolete
markus schnalke <meillo@marmaro.de>
parents:
288
diff
changeset
|
616 if (!route_name) { |
409 | 617 fprintf(stderr, "Please do not use -qo " |
618 "without argument anymore; " | |
619 "use -q instead.\n"); | |
620 fprintf(stderr, "The behavior for -qo without " | |
621 "argument is likely to " | |
622 "change.\n"); | |
290
792e0201c1b3
mark -qo (without argument) obsolete
markus schnalke <meillo@marmaro.de>
parents:
288
diff
changeset
|
623 } |
249
f9da5a7caeda
refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents:
248
diff
changeset
|
624 |
f9da5a7caeda
refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents:
248
diff
changeset
|
625 } else if (strncmp(opt, "q", 1) == 0) { |
f9da5a7caeda
refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents:
248
diff
changeset
|
626 /* must be after the `qo' check */ |
f9da5a7caeda
refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents:
248
diff
changeset
|
627 gchar *optarg; |
f9da5a7caeda
refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents:
248
diff
changeset
|
628 |
251
2babd21e7c75
moved run_queue to a new function
markus schnalke <meillo@marmaro.de>
parents:
250
diff
changeset
|
629 optarg = get_optarg(argv, &arg, opt+1); |
2babd21e7c75
moved run_queue to a new function
markus schnalke <meillo@marmaro.de>
parents:
250
diff
changeset
|
630 if (optarg) { |
409 | 631 /* do regular queue runs */ |
281
ea5f86e0a81c
modes are now enforced exclusive
markus schnalke <meillo@marmaro.de>
parents:
278
diff
changeset
|
632 set_mode(MODE_DAEMON); |
254
82d168dd52fd
removed the obsolete pos argument from time_interval()
markus schnalke <meillo@marmaro.de>
parents:
251
diff
changeset
|
633 queue_interval = time_interval(optarg); |
281
ea5f86e0a81c
modes are now enforced exclusive
markus schnalke <meillo@marmaro.de>
parents:
278
diff
changeset
|
634 } else { |
409 | 635 /* do a single queue run */ |
281
ea5f86e0a81c
modes are now enforced exclusive
markus schnalke <meillo@marmaro.de>
parents:
278
diff
changeset
|
636 set_mode(MODE_RUNQUEUE); |
ea5f86e0a81c
modes are now enforced exclusive
markus schnalke <meillo@marmaro.de>
parents:
278
diff
changeset
|
637 do_runq = TRUE; |
249
f9da5a7caeda
refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents:
248
diff
changeset
|
638 } |
f9da5a7caeda
refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents:
248
diff
changeset
|
639 |
f9da5a7caeda
refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents:
248
diff
changeset
|
640 } else if (strcmp(opt, "t") == 0) { |
f9da5a7caeda
refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents:
248
diff
changeset
|
641 opt_t = TRUE; |
f9da5a7caeda
refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents:
248
diff
changeset
|
642 |
f9da5a7caeda
refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents:
248
diff
changeset
|
643 } else if (strcmp(opt, "v") == 0) { |
f9da5a7caeda
refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents:
248
diff
changeset
|
644 do_verbose = TRUE; |
f9da5a7caeda
refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents:
248
diff
changeset
|
645 |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
646 } else { |
249
f9da5a7caeda
refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents:
248
diff
changeset
|
647 fprintf(stderr, "unrecognized option `-%s'\n", opt); |
262
fc1c6425c024
s/EXIT_SUCCESS/0/ && s/EXIT_FAILURE/1/
markus schnalke <meillo@marmaro.de>
parents:
261
diff
changeset
|
648 exit(1); |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
649 } |
0 | 650 } |
651 | |
281
ea5f86e0a81c
modes are now enforced exclusive
markus schnalke <meillo@marmaro.de>
parents:
278
diff
changeset
|
652 if (!mta_mode && arg==argc && !opt_t) { |
278
c35c59a36a2a
added -bm for mode accept (the other MTAs have it too)
markus schnalke <meillo@marmaro.de>
parents:
276
diff
changeset
|
653 /* |
367
b27f66555ba8
Reformated multiline comments to have leading asterisks on each line
markus schnalke <meillo@marmaro.de>
parents:
366
diff
changeset
|
654 ** In this case no rcpts can be found, thus no mail |
b27f66555ba8
Reformated multiline comments to have leading asterisks on each line
markus schnalke <meillo@marmaro.de>
parents:
366
diff
changeset
|
655 ** can be sent, thus masqmail will always fail. We |
b27f66555ba8
Reformated multiline comments to have leading asterisks on each line
markus schnalke <meillo@marmaro.de>
parents:
366
diff
changeset
|
656 ** rather do something better instead. This covers |
b27f66555ba8
Reformated multiline comments to have leading asterisks on each line
markus schnalke <meillo@marmaro.de>
parents:
366
diff
changeset
|
657 ** also the case of calling masqmail without args. |
278
c35c59a36a2a
added -bm for mode accept (the other MTAs have it too)
markus schnalke <meillo@marmaro.de>
parents:
276
diff
changeset
|
658 */ |
281
ea5f86e0a81c
modes are now enforced exclusive
markus schnalke <meillo@marmaro.de>
parents:
278
diff
changeset
|
659 mode_version(); |
ea5f86e0a81c
modes are now enforced exclusive
markus schnalke <meillo@marmaro.de>
parents:
278
diff
changeset
|
660 exit(0); |
259
f4117fd5a163
made default mode sensible
markus schnalke <meillo@marmaro.de>
parents:
258
diff
changeset
|
661 } |
f4117fd5a163
made default mode sensible
markus schnalke <meillo@marmaro.de>
parents:
258
diff
changeset
|
662 |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
663 if (mta_mode == MODE_VERSION) { |
261
0afe18a9ee03
fixed previous commit and excluded mode_version() from main()
markus schnalke <meillo@marmaro.de>
parents:
260
diff
changeset
|
664 mode_version(); |
262
fc1c6425c024
s/EXIT_SUCCESS/0/ && s/EXIT_FAILURE/1/
markus schnalke <meillo@marmaro.de>
parents:
261
diff
changeset
|
665 exit(0); |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
666 } |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
667 |
281
ea5f86e0a81c
modes are now enforced exclusive
markus schnalke <meillo@marmaro.de>
parents:
278
diff
changeset
|
668 if (!mta_mode) { |
ea5f86e0a81c
modes are now enforced exclusive
markus schnalke <meillo@marmaro.de>
parents:
278
diff
changeset
|
669 mta_mode = MODE_ACCEPT; |
ea5f86e0a81c
modes are now enforced exclusive
markus schnalke <meillo@marmaro.de>
parents:
278
diff
changeset
|
670 } |
ea5f86e0a81c
modes are now enforced exclusive
markus schnalke <meillo@marmaro.de>
parents:
278
diff
changeset
|
671 |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
672 /* initialize random generator */ |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
673 srand(time(NULL)); |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
674 /* ignore SIGPIPE signal */ |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
675 signal(SIGPIPE, SIG_IGN); |
0 | 676 |
73 | 677 /* close all possibly open file descriptors, except std{in,out,err} */ |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
678 { |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
679 int i, max_fd = sysconf(_SC_OPEN_MAX); |
0 | 680 |
251
2babd21e7c75
moved run_queue to a new function
markus schnalke <meillo@marmaro.de>
parents:
250
diff
changeset
|
681 if (max_fd <= 0) { |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
682 max_fd = 64; |
251
2babd21e7c75
moved run_queue to a new function
markus schnalke <meillo@marmaro.de>
parents:
250
diff
changeset
|
683 } |
2babd21e7c75
moved run_queue to a new function
markus schnalke <meillo@marmaro.de>
parents:
250
diff
changeset
|
684 for (i=3; i<max_fd; i++) { |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
685 close(i); |
251
2babd21e7c75
moved run_queue to a new function
markus schnalke <meillo@marmaro.de>
parents:
250
diff
changeset
|
686 } |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
687 } |
0 | 688 |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
689 init_conf(); |
0 | 690 |
367
b27f66555ba8
Reformated multiline comments to have leading asterisks on each line
markus schnalke <meillo@marmaro.de>
parents:
366
diff
changeset
|
691 /* |
b27f66555ba8
Reformated multiline comments to have leading asterisks on each line
markus schnalke <meillo@marmaro.de>
parents:
366
diff
changeset
|
692 ** if we are not privileged, and the config file was changed we |
b27f66555ba8
Reformated multiline comments to have leading asterisks on each line
markus schnalke <meillo@marmaro.de>
parents:
366
diff
changeset
|
693 ** implicetely set the the run_as_user flag and give up all |
b27f66555ba8
Reformated multiline comments to have leading asterisks on each line
markus schnalke <meillo@marmaro.de>
parents:
366
diff
changeset
|
694 ** privileges. |
b27f66555ba8
Reformated multiline comments to have leading asterisks on each line
markus schnalke <meillo@marmaro.de>
parents:
366
diff
changeset
|
695 ** |
b27f66555ba8
Reformated multiline comments to have leading asterisks on each line
markus schnalke <meillo@marmaro.de>
parents:
366
diff
changeset
|
696 ** So it is possible for a user to run his own daemon without |
b27f66555ba8
Reformated multiline comments to have leading asterisks on each line
markus schnalke <meillo@marmaro.de>
parents:
366
diff
changeset
|
697 ** breaking security. |
b27f66555ba8
Reformated multiline comments to have leading asterisks on each line
markus schnalke <meillo@marmaro.de>
parents:
366
diff
changeset
|
698 */ |
251
2babd21e7c75
moved run_queue to a new function
markus schnalke <meillo@marmaro.de>
parents:
250
diff
changeset
|
699 if ((strcmp(conf_file, CONF_FILE) != 0) && (conf.orig_uid != 0)) { |
421
f37384470855
Changed lockdir to /var/lock/masqmail; Create lockdir and piddir on startup.
markus schnalke <meillo@marmaro.de>
parents:
419
diff
changeset
|
700 logwrite(LOG_NOTICE, "Changing to run_as_user.\n"); |
251
2babd21e7c75
moved run_queue to a new function
markus schnalke <meillo@marmaro.de>
parents:
250
diff
changeset
|
701 conf.run_as_user = TRUE; |
331
e507c854a63e
Security fix! Correct handling of seteuid() return value
markus schnalke <meillo@marmaro.de>
parents:
310
diff
changeset
|
702 set_euidgid(conf.orig_uid, conf.orig_gid, NULL, NULL); |
e507c854a63e
Security fix! Correct handling of seteuid() return value
markus schnalke <meillo@marmaro.de>
parents:
310
diff
changeset
|
703 if (setgid(conf.orig_gid)) { |
409 | 704 logwrite(LOG_ALERT, "could not set gid to %d: %s\n", |
705 conf.orig_gid, strerror(errno)); | |
331
e507c854a63e
Security fix! Correct handling of seteuid() return value
markus schnalke <meillo@marmaro.de>
parents:
310
diff
changeset
|
706 exit(1); |
e507c854a63e
Security fix! Correct handling of seteuid() return value
markus schnalke <meillo@marmaro.de>
parents:
310
diff
changeset
|
707 } |
e507c854a63e
Security fix! Correct handling of seteuid() return value
markus schnalke <meillo@marmaro.de>
parents:
310
diff
changeset
|
708 if (setuid(conf.orig_uid)) { |
409 | 709 logwrite(LOG_ALERT, "could not set uid to %d: %s\n", |
710 conf.orig_uid, strerror(errno)); | |
331
e507c854a63e
Security fix! Correct handling of seteuid() return value
markus schnalke <meillo@marmaro.de>
parents:
310
diff
changeset
|
711 exit(1); |
e507c854a63e
Security fix! Correct handling of seteuid() return value
markus schnalke <meillo@marmaro.de>
parents:
310
diff
changeset
|
712 } |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
713 } |
0 | 714 |
155 | 715 conf.log_dir = LOG_DIR; |
397
cdd16614c1f5
Fixed debugging output during read_conf().
markus schnalke <meillo@marmaro.de>
parents:
378
diff
changeset
|
716 conf.debug_level = debug_level; /* for debuggin during read_conf() */ |
288
84ea0b1fc8f8
FIXME comment: where to log while reading the config file?
markus schnalke <meillo@marmaro.de>
parents:
284
diff
changeset
|
717 /* FIXME: fails if we run as user */ |
155 | 718 logopen(); |
719 if (!read_conf(conf_file)) { | |
409 | 720 logwrite(LOG_ALERT, "SHUTTING DOWN due to problems reading " |
721 "config\n"); | |
155 | 722 exit(5); |
723 } | |
724 logclose(); | |
0 | 725 |
251
2babd21e7c75
moved run_queue to a new function
markus schnalke <meillo@marmaro.de>
parents:
250
diff
changeset
|
726 if (do_queue) { |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
727 conf.do_queue = TRUE; |
251
2babd21e7c75
moved run_queue to a new function
markus schnalke <meillo@marmaro.de>
parents:
250
diff
changeset
|
728 } |
2babd21e7c75
moved run_queue to a new function
markus schnalke <meillo@marmaro.de>
parents:
250
diff
changeset
|
729 if (do_verbose) { |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
730 conf.do_verbose = TRUE; |
251
2babd21e7c75
moved run_queue to a new function
markus schnalke <meillo@marmaro.de>
parents:
250
diff
changeset
|
731 } |
2babd21e7c75
moved run_queue to a new function
markus schnalke <meillo@marmaro.de>
parents:
250
diff
changeset
|
732 if (debug_level >= 0) { /* if >= 0, it was given by argument */ |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
733 conf.debug_level = debug_level; |
251
2babd21e7c75
moved run_queue to a new function
markus schnalke <meillo@marmaro.de>
parents:
250
diff
changeset
|
734 } |
0 | 735 |
367
b27f66555ba8
Reformated multiline comments to have leading asterisks on each line
markus schnalke <meillo@marmaro.de>
parents:
366
diff
changeset
|
736 /* |
b27f66555ba8
Reformated multiline comments to have leading asterisks on each line
markus schnalke <meillo@marmaro.de>
parents:
366
diff
changeset
|
737 ** It appears that changing to / ensures that we are never in |
b27f66555ba8
Reformated multiline comments to have leading asterisks on each line
markus schnalke <meillo@marmaro.de>
parents:
366
diff
changeset
|
738 ** a directory which we cannot access. This situation could be |
b27f66555ba8
Reformated multiline comments to have leading asterisks on each line
markus schnalke <meillo@marmaro.de>
parents:
366
diff
changeset
|
739 ** possible after changing identity. |
b27f66555ba8
Reformated multiline comments to have leading asterisks on each line
markus schnalke <meillo@marmaro.de>
parents:
366
diff
changeset
|
740 ** Maybe we should only change to / if we not run as user, to |
b27f66555ba8
Reformated multiline comments to have leading asterisks on each line
markus schnalke <meillo@marmaro.de>
parents:
366
diff
changeset
|
741 ** allow relative paths for log files in test setups for |
b27f66555ba8
Reformated multiline comments to have leading asterisks on each line
markus schnalke <meillo@marmaro.de>
parents:
366
diff
changeset
|
742 ** instance. |
46 | 743 */ |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
744 chdir("/"); |
0 | 745 |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
746 if (!conf.run_as_user) { |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
747 if (setgid(0) != 0) { |
409 | 748 fprintf(stderr, "could not set gid to 0. " |
749 "Is the setuid bit set? : %s\n", | |
750 strerror(errno)); | |
262
fc1c6425c024
s/EXIT_SUCCESS/0/ && s/EXIT_FAILURE/1/
markus schnalke <meillo@marmaro.de>
parents:
261
diff
changeset
|
751 exit(1); |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
752 } |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
753 if (setuid(0) != 0) { |
409 | 754 fprintf(stderr, "could not gain root privileges. " |
755 "Is the setuid bit set? : %s\n", | |
756 strerror(errno)); | |
262
fc1c6425c024
s/EXIT_SUCCESS/0/ && s/EXIT_FAILURE/1/
markus schnalke <meillo@marmaro.de>
parents:
261
diff
changeset
|
757 exit(1); |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
758 } |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
759 } |
0 | 760 |
421
f37384470855
Changed lockdir to /var/lock/masqmail; Create lockdir and piddir on startup.
markus schnalke <meillo@marmaro.de>
parents:
419
diff
changeset
|
761 if (conf.run_as_user) { |
f37384470855
Changed lockdir to /var/lock/masqmail; Create lockdir and piddir on startup.
markus schnalke <meillo@marmaro.de>
parents:
419
diff
changeset
|
762 logwrite(LOG_NOTICE, "Using spool directory `%s' for " |
f37384470855
Changed lockdir to /var/lock/masqmail; Create lockdir and piddir on startup.
markus schnalke <meillo@marmaro.de>
parents:
419
diff
changeset
|
763 "lock files.\n", conf.spool_dir); |
f37384470855
Changed lockdir to /var/lock/masqmail; Create lockdir and piddir on startup.
markus schnalke <meillo@marmaro.de>
parents:
419
diff
changeset
|
764 conf.lock_dir = conf.spool_dir; |
425
a19e47ebbb33
Create the spool and log dirs on program startup if missing.
markus schnalke <meillo@marmaro.de>
parents:
421
diff
changeset
|
765 makedir_rec(conf.spool_dir, 0755); |
a19e47ebbb33
Create the spool and log dirs on program startup if missing.
markus schnalke <meillo@marmaro.de>
parents:
421
diff
changeset
|
766 makedir_rec(conf.log_dir, 0755); |
421
f37384470855
Changed lockdir to /var/lock/masqmail; Create lockdir and piddir on startup.
markus schnalke <meillo@marmaro.de>
parents:
419
diff
changeset
|
767 } else { |
f37384470855
Changed lockdir to /var/lock/masqmail; Create lockdir and piddir on startup.
markus schnalke <meillo@marmaro.de>
parents:
419
diff
changeset
|
768 makedir_rec(conf.lock_dir, 0775); |
425
a19e47ebbb33
Create the spool and log dirs on program startup if missing.
markus schnalke <meillo@marmaro.de>
parents:
421
diff
changeset
|
769 chown(conf.lock_dir, conf.mail_uid, conf.mail_gid); |
a19e47ebbb33
Create the spool and log dirs on program startup if missing.
markus schnalke <meillo@marmaro.de>
parents:
421
diff
changeset
|
770 makedir_rec(conf.spool_dir, 0755); |
a19e47ebbb33
Create the spool and log dirs on program startup if missing.
markus schnalke <meillo@marmaro.de>
parents:
421
diff
changeset
|
771 chown(conf.spool_dir, conf.mail_uid, conf.mail_gid); |
a19e47ebbb33
Create the spool and log dirs on program startup if missing.
markus schnalke <meillo@marmaro.de>
parents:
421
diff
changeset
|
772 makedir_rec(conf.log_dir, 0755); |
a19e47ebbb33
Create the spool and log dirs on program startup if missing.
markus schnalke <meillo@marmaro.de>
parents:
421
diff
changeset
|
773 chown(conf.log_dir, conf.mail_uid, conf.mail_gid); |
421
f37384470855
Changed lockdir to /var/lock/masqmail; Create lockdir and piddir on startup.
markus schnalke <meillo@marmaro.de>
parents:
419
diff
changeset
|
774 } |
f37384470855
Changed lockdir to /var/lock/masqmail; Create lockdir and piddir on startup.
markus schnalke <meillo@marmaro.de>
parents:
419
diff
changeset
|
775 |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
776 if (!logopen()) { |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
777 fprintf(stderr, "could not open log file\n"); |
262
fc1c6425c024
s/EXIT_SUCCESS/0/ && s/EXIT_FAILURE/1/
markus schnalke <meillo@marmaro.de>
parents:
261
diff
changeset
|
778 exit(1); |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
779 } |
0 | 780 |
415
0430194f7ef8
Debug message cosmetic.
markus schnalke <meillo@marmaro.de>
parents:
409
diff
changeset
|
781 DEBUG(1) debugf("----STARTING---- masqmail %s\n", VERSION); |
0 | 782 |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
783 DEBUG(5) { |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
784 gchar **str = argv; |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
785 debugf("args: \n"); |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
786 while (*str) { |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
787 debugf("%s \n", *str); |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
788 str++; |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
789 } |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
790 } |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
791 DEBUG(5) debugf("queue_interval = %d\n", queue_interval); |
0 | 792 |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
793 if (f_address) { |
409 | 794 return_path = create_address_qualified(f_address, TRUE, |
795 conf.host_name); | |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
796 g_free(f_address); |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
797 if (!return_path) { |
409 | 798 fprintf(stderr, "invalid RFC821 address: %s\n", |
799 f_address); | |
262
fc1c6425c024
s/EXIT_SUCCESS/0/ && s/EXIT_FAILURE/1/
markus schnalke <meillo@marmaro.de>
parents:
261
diff
changeset
|
800 exit(1); |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
801 } |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
802 } |
0 | 803 |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
804 switch (mta_mode) { |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
805 case MODE_DAEMON: |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
806 mode_daemon(do_listen, queue_interval, argv); |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
807 break; |
251
2babd21e7c75
moved run_queue to a new function
markus schnalke <meillo@marmaro.de>
parents:
250
diff
changeset
|
808 |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
809 case MODE_RUNQUEUE: |
251
2babd21e7c75
moved run_queue to a new function
markus schnalke <meillo@marmaro.de>
parents:
250
diff
changeset
|
810 exit(run_queue(do_runq, do_runq_online, route_name) ? 0 : 1); |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
811 break; |
0 | 812 |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
813 case MODE_SMTP: |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
814 mode_smtp(); |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
815 break; |
0 | 816 |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
817 case MODE_LIST: |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
818 queue_list(); |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
819 break; |
0 | 820 |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
821 case MODE_BI: |
262
fc1c6425c024
s/EXIT_SUCCESS/0/ && s/EXIT_FAILURE/1/
markus schnalke <meillo@marmaro.de>
parents:
261
diff
changeset
|
822 exit(0); |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
823 break; /* well... */ |
0 | 824 |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
825 case MODE_MCMD: |
250
a41c013c8458
moved the queue manipulation code to an new function
markus schnalke <meillo@marmaro.de>
parents:
249
diff
changeset
|
826 exit(manipulate_queue(M_cmd, &argv[arg]) ? 0 : 1); |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
827 break; |
0 | 828 |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
829 case MODE_ACCEPT: |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
830 { |
409 | 831 guint accept_flags = 0; |
832 accept_flags |= (opt_t ? ACC_RCPT_FROM_HEAD : 0); | |
833 accept_flags |= (opt_i ? | |
834 ACC_DOT_IGNORE : ACC_NODOT_RELAX); | |
835 mode_accept(return_path, full_sender_name, | |
836 accept_flags, argv + arg, argc - arg); | |
258
05fa719b7002
fixed -oem by removing it ;-)
markus schnalke <meillo@marmaro.de>
parents:
257
diff
changeset
|
837 exit(0); |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
838 } |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
839 break; |
251
2babd21e7c75
moved run_queue to a new function
markus schnalke <meillo@marmaro.de>
parents:
250
diff
changeset
|
840 |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
841 default: |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
842 fprintf(stderr, "unknown mode: %d\n", mta_mode); |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
843 break; |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
844 } |
0 | 845 |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
846 logclose(); |
0 | 847 |
263
e9e73505ab2c
removed now obsolete exit_code
markus schnalke <meillo@marmaro.de>
parents:
262
diff
changeset
|
848 exit(0); |
0 | 849 } |