Mercurial > masqmail
annotate src/masqmail.c @ 323:29de6a1c4538
Fixed an important bug with folded headers!
g_strconcat() returns a *copy* of the string, but hdr->value still
pointed to the old header (which probably was a memory leak, too).
If the folded part had been quite small it was likely that the new
string was at the same position as the old one, thus making everything
go well. But if pretty long headers were folded several times it was
likely that the new string was allocated somewhere else in memory,
thus breaking things. In result mails to lots of recipients (folded
header) were frequently only sent to the ones in the first line. Sorry
for the inconvenience.
author | meillo@marmaro.de |
---|---|
date | Fri, 03 Jun 2011 09:47:27 +0200 |
parents | f10a56dc7481 |
children | e507c854a63e |
rev | line source |
---|---|
0 | 1 /* MasqMail |
2 Copyright (C) 1999-2001 Oliver Kurth | |
76
3b344bf57162
added copyright notices to files I improved
meillo@marmaro.de
parents:
74
diff
changeset
|
3 Copyright (C) 2010 markus schnalke <meillo@marmaro.de> |
0 | 4 |
5 This program is free software; you can redistribute it and/or modify | |
6 it under the terms of the GNU General Public License as published by | |
7 the Free Software Foundation; either version 2 of the License, or | |
8 (at your option) any later version. | |
9 | |
10 This program is distributed in the hope that it will be useful, | |
11 but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
13 GNU General Public License for more details. | |
14 | |
15 You should have received a copy of the GNU General Public License | |
16 along with this program; if not, write to the Free Software | |
17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. | |
18 */ | |
19 | |
20 #include <stdio.h> | |
21 #include <errno.h> | |
22 #include <stdlib.h> | |
23 #include <string.h> | |
24 #include <unistd.h> | |
25 #include <sys/types.h> | |
26 #include <sys/socket.h> | |
27 #include <sys/time.h> | |
28 #include <netinet/in.h> | |
29 #include <netdb.h> | |
30 #include <syslog.h> | |
31 #include <signal.h> | |
32 | |
33 #include <glib.h> | |
34 | |
35 #include "masqmail.h" | |
36 | |
192 | 37 /* mutually exclusive modes. Note that there is no 'queue daemon' mode. |
38 It, as well as the distinction beween the two (non exclusive) daemon | |
39 (queue and listen) modes, is handled by flags.*/ | |
281
ea5f86e0a81c
modes are now enforced exclusive
markus schnalke <meillo@marmaro.de>
parents:
278
diff
changeset
|
40 enum mta_mode { |
ea5f86e0a81c
modes are now enforced exclusive
markus schnalke <meillo@marmaro.de>
parents:
278
diff
changeset
|
41 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
|
42 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
|
43 MODE_DAEMON, /* run as daemon */ |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
44 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
|
45 MODE_SMTP, /* accept SMTP on stdin */ |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
46 MODE_LIST, /* list queue */ |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
47 MODE_MCMD, /* do queue manipulation */ |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
48 MODE_VERSION, /* show version */ |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
49 MODE_BI, /* fake ;-) */ |
281
ea5f86e0a81c
modes are now enforced exclusive
markus schnalke <meillo@marmaro.de>
parents:
278
diff
changeset
|
50 }; |
ea5f86e0a81c
modes are now enforced exclusive
markus schnalke <meillo@marmaro.de>
parents:
278
diff
changeset
|
51 enum mta_mode mta_mode = MODE_NONE; |
0 | 52 |
53 char *pidfile = NULL; | |
54 volatile int sigterm_in_progress = 0; | |
55 | |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
56 static void |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
57 sigterm_handler(int sig) |
0 | 58 { |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
59 if (sigterm_in_progress) |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
60 raise(sig); |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
61 sigterm_in_progress = 1; |
0 | 62 |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
63 if (pidfile) { |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
64 uid_t uid; |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
65 uid = seteuid(0); |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
66 if (unlink(pidfile) != 0) |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
67 logwrite(LOG_WARNING, "could not delete pid file %s: %s\n", pidfile, strerror(errno)); |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
68 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
|
69 } |
0 | 70 |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
71 signal(sig, SIG_DFL); |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
72 raise(sig); |
0 | 73 } |
74 | |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
75 #ifdef ENABLE_IDENT /* so far used for that only */ |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
76 static gboolean |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
77 is_in_netlist(gchar * host, GList * netlist) |
0 | 78 { |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
79 guint hostip = inet_addr(host); |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
80 struct in_addr addr; |
0 | 81 |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
82 addr.s_addr = hostip; |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
83 if (addr.s_addr != INADDR_NONE) { |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
84 GList *node; |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
85 foreach(netlist, node) { |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
86 struct in_addr *net = (struct in_addr *) (node->data); |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
87 if ((addr.s_addr & net->s_addr) == net->s_addr) |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
88 return TRUE; |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
89 } |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
90 } |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
91 return FALSE; |
0 | 92 } |
93 #endif | |
94 | |
249
f9da5a7caeda
refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents:
248
diff
changeset
|
95 /* |
f9da5a7caeda
refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents:
248
diff
changeset
|
96 argv: the original argv |
f9da5a7caeda
refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents:
248
diff
changeset
|
97 argp: number of arg (may get modified!) |
f9da5a7caeda
refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents:
248
diff
changeset
|
98 cp: pointing to the char after the option |
f9da5a7caeda
refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents:
248
diff
changeset
|
99 e.g. `-d 6' `-d6' |
f9da5a7caeda
refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents:
248
diff
changeset
|
100 ^ ^ |
f9da5a7caeda
refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents:
248
diff
changeset
|
101 */ |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
102 gchar* |
249
f9da5a7caeda
refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents:
248
diff
changeset
|
103 get_optarg(char* argv[], gint* argp, char* cp) |
0 | 104 { |
249
f9da5a7caeda
refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents:
248
diff
changeset
|
105 if (*cp) { |
f9da5a7caeda
refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents:
248
diff
changeset
|
106 /* this kind: -xval */ |
f9da5a7caeda
refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents:
248
diff
changeset
|
107 return cp; |
f9da5a7caeda
refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents:
248
diff
changeset
|
108 } |
f9da5a7caeda
refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents:
248
diff
changeset
|
109 cp = argv[*argp+1]; |
f9da5a7caeda
refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents:
248
diff
changeset
|
110 if (cp && (*cp != '-')) { |
f9da5a7caeda
refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents:
248
diff
changeset
|
111 /* this kind: -x val */ |
f9da5a7caeda
refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents:
248
diff
changeset
|
112 (*argp)++; |
f9da5a7caeda
refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents:
248
diff
changeset
|
113 return cp; |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
114 } |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
115 return NULL; |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
116 } |
0 | 117 |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
118 gboolean |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
119 write_pidfile(gchar * name) |
0 | 120 { |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
121 FILE *fptr; |
0 | 122 |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
123 if ((fptr = fopen(name, "wt"))) { |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
124 fprintf(fptr, "%d\n", getpid()); |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
125 fclose(fptr); |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
126 pidfile = strdup(name); |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
127 return TRUE; |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
128 } |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
129 logwrite(LOG_WARNING, "could not write pid file: %s\n", strerror(errno)); |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
130 return FALSE; |
0 | 131 } |
132 | |
264
1e5e457dea18
comments and a small refactoring
markus schnalke <meillo@marmaro.de>
parents:
263
diff
changeset
|
133 /* 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
|
134 static void |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
135 mode_daemon(gboolean do_listen, gint queue_interval, char *argv[]) |
0 | 136 { |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
137 guint pid; |
0 | 138 |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
139 /* daemon */ |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
140 if (!conf.run_as_user) { |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
141 if ((conf.orig_uid != 0) && (conf.orig_uid != conf.mail_uid)) { |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
142 fprintf(stderr, "must be root or %s for daemon.\n", DEF_MAIL_USER); |
262
fc1c6425c024
s/EXIT_SUCCESS/0/ && s/EXIT_FAILURE/1/
markus schnalke <meillo@marmaro.de>
parents:
261
diff
changeset
|
143 exit(1); |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
144 } |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
145 } |
0 | 146 |
74
0a5b2e96ade3
do not reparent the daemon to init if init is already the parent
meillo@marmaro.de
parents:
73
diff
changeset
|
147 /* 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
|
148 if (getppid() != 1) { |
0a5b2e96ade3
do not reparent the daemon to init if init is already the parent
meillo@marmaro.de
parents:
73
diff
changeset
|
149 if ((pid = fork()) > 0) { |
262
fc1c6425c024
s/EXIT_SUCCESS/0/ && s/EXIT_FAILURE/1/
markus schnalke <meillo@marmaro.de>
parents:
261
diff
changeset
|
150 exit(0); |
74
0a5b2e96ade3
do not reparent the daemon to init if init is already the parent
meillo@marmaro.de
parents:
73
diff
changeset
|
151 } 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
|
152 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
|
153 exit(1); |
74
0a5b2e96ade3
do not reparent the daemon to init if init is already the parent
meillo@marmaro.de
parents:
73
diff
changeset
|
154 } |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
155 } |
0 | 156 |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
157 signal(SIGTERM, sigterm_handler); |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
158 write_pidfile(PIDFILEDIR "/masqmail.pid"); |
0 | 159 |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
160 conf.do_verbose = FALSE; |
0 | 161 |
72
ad034b57f3b2
fixed Debian bug 536060 (log files are closed after SIGHUP receival)
meillo@marmaro.de
parents:
46
diff
changeset
|
162 /* closing and reopening the log ensures that it is open afterwards |
ad034b57f3b2
fixed Debian bug 536060 (log files are closed after SIGHUP receival)
meillo@marmaro.de
parents:
46
diff
changeset
|
163 because it is possible that the log is assigned to fd 1 and gets |
ad034b57f3b2
fixed Debian bug 536060 (log files are closed after SIGHUP receival)
meillo@marmaro.de
parents:
46
diff
changeset
|
164 thus closes by fclose(stdout). Similar for the debugfile. |
ad034b57f3b2
fixed Debian bug 536060 (log files are closed after SIGHUP receival)
meillo@marmaro.de
parents:
46
diff
changeset
|
165 */ |
ad034b57f3b2
fixed Debian bug 536060 (log files are closed after SIGHUP receival)
meillo@marmaro.de
parents:
46
diff
changeset
|
166 logclose(); |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
167 fclose(stdin); |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
168 fclose(stdout); |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
169 fclose(stderr); |
72
ad034b57f3b2
fixed Debian bug 536060 (log files are closed after SIGHUP receival)
meillo@marmaro.de
parents:
46
diff
changeset
|
170 logopen(); |
0 | 171 |
208
3708b655a371
added newlines to the end of log and debug messages where missing
meillo@marmaro.de
parents:
205
diff
changeset
|
172 logwrite(LOG_NOTICE, "%s %s daemon starting\n", PACKAGE, VERSION); |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
173 listen_port(do_listen ? conf.listen_addresses : NULL, queue_interval, argv); |
0 | 174 } |
175 | |
264
1e5e457dea18
comments and a small refactoring
markus schnalke <meillo@marmaro.de>
parents:
263
diff
changeset
|
176 /* -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
|
177 static void |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
178 mode_smtp() |
0 | 179 { |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
180 /* accept smtp message on stdin */ |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
181 /* write responses to stderr. */ |
0 | 182 |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
183 struct sockaddr_in saddr; |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
184 gchar *peername = NULL; |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
185 int dummy = sizeof(saddr); |
0 | 186 |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
187 conf.do_verbose = FALSE; |
0 | 188 |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
189 if (!conf.run_as_user) { |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
190 seteuid(conf.orig_uid); |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
191 setegid(conf.orig_gid); |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
192 } |
0 | 193 |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
194 DEBUG(5) debugf("accepting smtp message on stdin\n"); |
0 | 195 |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
196 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
|
197 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
|
198 } else if (errno != ENOTSOCK) |
262
fc1c6425c024
s/EXIT_SUCCESS/0/ && s/EXIT_FAILURE/1/
markus schnalke <meillo@marmaro.de>
parents:
261
diff
changeset
|
199 exit(1); |
0 | 200 |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
201 smtp_in(stdin, stderr, peername, NULL); |
0 | 202 } |
203 | |
264
1e5e457dea18
comments and a small refactoring
markus schnalke <meillo@marmaro.de>
parents:
263
diff
changeset
|
204 /* 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
|
205 static void |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
206 mode_accept(address * return_path, gchar * full_sender_name, guint accept_flags, char **addresses, int addr_cnt) |
0 | 207 { |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
208 /* accept message on stdin */ |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
209 accept_error err; |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
210 message *msg = create_message(); |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
211 gint i; |
266
ab39047ffe44
refactored mode_accept()
markus schnalke <meillo@marmaro.de>
parents:
264
diff
changeset
|
212 pid_t pid; |
0 | 213 |
83
085d6cd44462
using is_privileged_user() to check here too
meillo@marmaro.de
parents:
76
diff
changeset
|
214 if (return_path && !is_privileged_user(conf.orig_uid)) { |
96 | 215 fprintf(stderr, "must be root, %s or in group %s for setting return path.\n", 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
|
216 exit(1); |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
217 } |
0 | 218 |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
219 if (!conf.run_as_user) { |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
220 seteuid(conf.orig_uid); |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
221 setegid(conf.orig_gid); |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
222 } |
0 | 223 |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
224 DEBUG(5) debugf("accepting message on stdin\n"); |
0 | 225 |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
226 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
|
227 |
1abc1faeb45d
for -t cmdline args are now added to the rcpt list instead of substracted
markus schnalke <meillo@marmaro.de>
parents:
268
diff
changeset
|
228 /* 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
|
229 if (addr_cnt && (accept_flags & ACC_RCPT_FROM_HEAD)) { |
1abc1faeb45d
for -t cmdline args are now added to the rcpt list instead of substracted
markus schnalke <meillo@marmaro.de>
parents:
268
diff
changeset
|
230 logwrite(LOG_ALERT, "command line address arguments are now *added* to the mail header\\\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
|
231 logwrite(LOG_ALERT, " recipient addresses (instead of substracted) when -t is given.\\\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
|
232 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
|
233 } |
1abc1faeb45d
for -t cmdline args are now added to the rcpt list instead of substracted
markus schnalke <meillo@marmaro.de>
parents:
268
diff
changeset
|
234 |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
235 for (i = 0; i < addr_cnt; i++) { |
266
ab39047ffe44
refactored mode_accept()
markus schnalke <meillo@marmaro.de>
parents:
264
diff
changeset
|
236 if (addresses[i][0] == '|') { |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
237 logwrite(LOG_ALERT, "no pipe allowed as recipient 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
|
238 /* 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
|
239 exit(1); |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
240 } |
264
1e5e457dea18
comments and a small refactoring
markus schnalke <meillo@marmaro.de>
parents:
263
diff
changeset
|
241 msg->rcpt_list = g_list_append(msg->rcpt_list, create_address_qualified(addresses[i], TRUE, conf.host_name)); |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
242 } |
0 | 243 |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
244 /* -f option */ |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
245 msg->return_path = return_path; |
0 | 246 |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
247 /* -F option */ |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
248 msg->full_sender_name = full_sender_name; |
0 | 249 |
266
ab39047ffe44
refactored mode_accept()
markus schnalke <meillo@marmaro.de>
parents:
264
diff
changeset
|
250 err = accept_message(stdin, msg, accept_flags); |
ab39047ffe44
refactored mode_accept()
markus schnalke <meillo@marmaro.de>
parents:
264
diff
changeset
|
251 |
ab39047ffe44
refactored mode_accept()
markus schnalke <meillo@marmaro.de>
parents:
264
diff
changeset
|
252 switch (err) { |
ab39047ffe44
refactored mode_accept()
markus schnalke <meillo@marmaro.de>
parents:
264
diff
changeset
|
253 case AERR_OK: |
ab39047ffe44
refactored mode_accept()
markus schnalke <meillo@marmaro.de>
parents:
264
diff
changeset
|
254 /* to continue; all other cases exit */ |
ab39047ffe44
refactored mode_accept()
markus schnalke <meillo@marmaro.de>
parents:
264
diff
changeset
|
255 break; |
ab39047ffe44
refactored mode_accept()
markus schnalke <meillo@marmaro.de>
parents:
264
diff
changeset
|
256 case AERR_EOF: |
ab39047ffe44
refactored mode_accept()
markus schnalke <meillo@marmaro.de>
parents:
264
diff
changeset
|
257 fprintf(stderr, "unexpected EOF.\n"); |
ab39047ffe44
refactored mode_accept()
markus schnalke <meillo@marmaro.de>
parents:
264
diff
changeset
|
258 exit(1); |
ab39047ffe44
refactored mode_accept()
markus schnalke <meillo@marmaro.de>
parents:
264
diff
changeset
|
259 case AERR_NORCPT: |
ab39047ffe44
refactored mode_accept()
markus schnalke <meillo@marmaro.de>
parents:
264
diff
changeset
|
260 fprintf(stderr, "no recipients.\n"); |
ab39047ffe44
refactored mode_accept()
markus schnalke <meillo@marmaro.de>
parents:
264
diff
changeset
|
261 exit(1); |
ab39047ffe44
refactored mode_accept()
markus schnalke <meillo@marmaro.de>
parents:
264
diff
changeset
|
262 case AERR_SIZE: |
ab39047ffe44
refactored mode_accept()
markus schnalke <meillo@marmaro.de>
parents:
264
diff
changeset
|
263 fprintf(stderr, "max message size exceeded.\n"); |
ab39047ffe44
refactored mode_accept()
markus schnalke <meillo@marmaro.de>
parents:
264
diff
changeset
|
264 exit(1); |
ab39047ffe44
refactored mode_accept()
markus schnalke <meillo@marmaro.de>
parents:
264
diff
changeset
|
265 default: |
ab39047ffe44
refactored mode_accept()
markus schnalke <meillo@marmaro.de>
parents:
264
diff
changeset
|
266 /* should never happen: */ |
ab39047ffe44
refactored mode_accept()
markus schnalke <meillo@marmaro.de>
parents:
264
diff
changeset
|
267 fprintf(stderr, "Unknown error (%d)\r\n", err); |
ab39047ffe44
refactored mode_accept()
markus schnalke <meillo@marmaro.de>
parents:
264
diff
changeset
|
268 exit(1); |
ab39047ffe44
refactored mode_accept()
markus schnalke <meillo@marmaro.de>
parents:
264
diff
changeset
|
269 } |
0 | 270 |
266
ab39047ffe44
refactored mode_accept()
markus schnalke <meillo@marmaro.de>
parents:
264
diff
changeset
|
271 if (!spool_write(msg, TRUE)) { |
ab39047ffe44
refactored mode_accept()
markus schnalke <meillo@marmaro.de>
parents:
264
diff
changeset
|
272 fprintf(stderr, "Could not write spool file\n"); |
ab39047ffe44
refactored mode_accept()
markus schnalke <meillo@marmaro.de>
parents:
264
diff
changeset
|
273 exit(1); |
ab39047ffe44
refactored mode_accept()
markus schnalke <meillo@marmaro.de>
parents:
264
diff
changeset
|
274 } |
ab39047ffe44
refactored mode_accept()
markus schnalke <meillo@marmaro.de>
parents:
264
diff
changeset
|
275 |
267
8be687c06c20
comments (should we really exit failure in this case?)
markus schnalke <meillo@marmaro.de>
parents:
266
diff
changeset
|
276 /* here the mail is queued and thus in our responsibility */ |
266
ab39047ffe44
refactored mode_accept()
markus schnalke <meillo@marmaro.de>
parents:
264
diff
changeset
|
277 logwrite(LOG_NOTICE, "%s <= %s with %s\n", msg->uid, addr_string(msg->return_path), prot_names[PROT_LOCAL]); |
ab39047ffe44
refactored mode_accept()
markus schnalke <meillo@marmaro.de>
parents:
264
diff
changeset
|
278 |
ab39047ffe44
refactored mode_accept()
markus schnalke <meillo@marmaro.de>
parents:
264
diff
changeset
|
279 if (conf.do_queue) { |
ab39047ffe44
refactored mode_accept()
markus schnalke <meillo@marmaro.de>
parents:
264
diff
changeset
|
280 /* we're finished as we only need to queue it */ |
ab39047ffe44
refactored mode_accept()
markus schnalke <meillo@marmaro.de>
parents:
264
diff
changeset
|
281 return; |
ab39047ffe44
refactored mode_accept()
markus schnalke <meillo@marmaro.de>
parents:
264
diff
changeset
|
282 } |
ab39047ffe44
refactored mode_accept()
markus schnalke <meillo@marmaro.de>
parents:
264
diff
changeset
|
283 |
ab39047ffe44
refactored mode_accept()
markus schnalke <meillo@marmaro.de>
parents:
264
diff
changeset
|
284 /* deliver at once */ |
ab39047ffe44
refactored mode_accept()
markus schnalke <meillo@marmaro.de>
parents:
264
diff
changeset
|
285 if ((pid = fork()) < 0) { |
ab39047ffe44
refactored mode_accept()
markus schnalke <meillo@marmaro.de>
parents:
264
diff
changeset
|
286 logwrite(LOG_ALERT, "could not fork for delivery, id = %s\n", msg->uid); |
ab39047ffe44
refactored mode_accept()
markus schnalke <meillo@marmaro.de>
parents:
264
diff
changeset
|
287 } else if (pid == 0) { |
ab39047ffe44
refactored mode_accept()
markus schnalke <meillo@marmaro.de>
parents:
264
diff
changeset
|
288 conf.do_verbose = FALSE; |
ab39047ffe44
refactored mode_accept()
markus schnalke <meillo@marmaro.de>
parents:
264
diff
changeset
|
289 fclose(stdin); |
ab39047ffe44
refactored mode_accept()
markus schnalke <meillo@marmaro.de>
parents:
264
diff
changeset
|
290 fclose(stdout); |
ab39047ffe44
refactored mode_accept()
markus schnalke <meillo@marmaro.de>
parents:
264
diff
changeset
|
291 fclose(stderr); |
ab39047ffe44
refactored mode_accept()
markus schnalke <meillo@marmaro.de>
parents:
264
diff
changeset
|
292 if (deliver(msg)) { |
ab39047ffe44
refactored mode_accept()
markus schnalke <meillo@marmaro.de>
parents:
264
diff
changeset
|
293 exit(0); |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
294 } else { |
267
8be687c06c20
comments (should we really exit failure in this case?)
markus schnalke <meillo@marmaro.de>
parents:
266
diff
changeset
|
295 /* |
8be687c06c20
comments (should we really exit failure in this case?)
markus schnalke <meillo@marmaro.de>
parents:
266
diff
changeset
|
296 TODO: |
8be687c06c20
comments (should we really exit failure in this case?)
markus schnalke <meillo@marmaro.de>
parents:
266
diff
changeset
|
297 Should we really fail here? Because the mail is queued |
8be687c06c20
comments (should we really exit failure in this case?)
markus schnalke <meillo@marmaro.de>
parents:
266
diff
changeset
|
298 already. If we fail the client might submit it again. |
8be687c06c20
comments (should we really exit failure in this case?)
markus schnalke <meillo@marmaro.de>
parents:
266
diff
changeset
|
299 If at-once-delivery is seen as an additional best-effort |
8be687c06c20
comments (should we really exit failure in this case?)
markus schnalke <meillo@marmaro.de>
parents:
266
diff
changeset
|
300 service, then we should still exit successful here. |
8be687c06c20
comments (should we really exit failure in this case?)
markus schnalke <meillo@marmaro.de>
parents:
266
diff
changeset
|
301 */ |
262
fc1c6425c024
s/EXIT_SUCCESS/0/ && s/EXIT_FAILURE/1/
markus schnalke <meillo@marmaro.de>
parents:
261
diff
changeset
|
302 exit(1); |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
303 } |
0 | 304 } |
305 } | |
306 | |
250
a41c013c8458
moved the queue manipulation code to an new function
markus schnalke <meillo@marmaro.de>
parents:
249
diff
changeset
|
307 /* |
264
1e5e457dea18
comments and a small refactoring
markus schnalke <meillo@marmaro.de>
parents:
263
diff
changeset
|
308 if -Mrm is given |
1e5e457dea18
comments and a small refactoring
markus schnalke <meillo@marmaro.de>
parents:
263
diff
changeset
|
309 |
250
a41c013c8458
moved the queue manipulation code to an new function
markus schnalke <meillo@marmaro.de>
parents:
249
diff
changeset
|
310 currently only the `rm' command is supported |
a41c013c8458
moved the queue manipulation code to an new function
markus schnalke <meillo@marmaro.de>
parents:
249
diff
changeset
|
311 until this changes, we don't need any facility for further commands |
a41c013c8458
moved the queue manipulation code to an new function
markus schnalke <meillo@marmaro.de>
parents:
249
diff
changeset
|
312 return success if at least one message had been deleted |
a41c013c8458
moved the queue manipulation code to an new function
markus schnalke <meillo@marmaro.de>
parents:
249
diff
changeset
|
313 */ |
a41c013c8458
moved the queue manipulation code to an new function
markus schnalke <meillo@marmaro.de>
parents:
249
diff
changeset
|
314 static int |
a41c013c8458
moved the queue manipulation code to an new function
markus schnalke <meillo@marmaro.de>
parents:
249
diff
changeset
|
315 manipulate_queue(char* cmd, char* id[]) |
a41c013c8458
moved the queue manipulation code to an new function
markus schnalke <meillo@marmaro.de>
parents:
249
diff
changeset
|
316 { |
a41c013c8458
moved the queue manipulation code to an new function
markus schnalke <meillo@marmaro.de>
parents:
249
diff
changeset
|
317 gboolean ok = FALSE; |
a41c013c8458
moved the queue manipulation code to an new function
markus schnalke <meillo@marmaro.de>
parents:
249
diff
changeset
|
318 |
a41c013c8458
moved the queue manipulation code to an new function
markus schnalke <meillo@marmaro.de>
parents:
249
diff
changeset
|
319 if (strcmp(cmd, "rm") != 0) { |
a41c013c8458
moved the queue manipulation code to an new function
markus schnalke <meillo@marmaro.de>
parents:
249
diff
changeset
|
320 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
|
321 return FALSE; |
a41c013c8458
moved the queue manipulation code to an new function
markus schnalke <meillo@marmaro.de>
parents:
249
diff
changeset
|
322 } |
a41c013c8458
moved the queue manipulation code to an new function
markus schnalke <meillo@marmaro.de>
parents:
249
diff
changeset
|
323 |
a41c013c8458
moved the queue manipulation code to an new function
markus schnalke <meillo@marmaro.de>
parents:
249
diff
changeset
|
324 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
|
325 |
a41c013c8458
moved the queue manipulation code to an new function
markus schnalke <meillo@marmaro.de>
parents:
249
diff
changeset
|
326 /* 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
|
327 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
|
328 for (; *id; id++) { |
a41c013c8458
moved the queue manipulation code to an new function
markus schnalke <meillo@marmaro.de>
parents:
249
diff
changeset
|
329 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
|
330 if (queue_delete(*id)) { |
a41c013c8458
moved the queue manipulation code to an new function
markus schnalke <meillo@marmaro.de>
parents:
249
diff
changeset
|
331 ok = TRUE; |
a41c013c8458
moved the queue manipulation code to an new function
markus schnalke <meillo@marmaro.de>
parents:
249
diff
changeset
|
332 } |
a41c013c8458
moved the queue manipulation code to an new function
markus schnalke <meillo@marmaro.de>
parents:
249
diff
changeset
|
333 } |
a41c013c8458
moved the queue manipulation code to an new function
markus schnalke <meillo@marmaro.de>
parents:
249
diff
changeset
|
334 return ok; |
a41c013c8458
moved the queue manipulation code to an new function
markus schnalke <meillo@marmaro.de>
parents:
249
diff
changeset
|
335 } |
a41c013c8458
moved the queue manipulation code to an new function
markus schnalke <meillo@marmaro.de>
parents:
249
diff
changeset
|
336 |
a41c013c8458
moved the queue manipulation code to an new function
markus schnalke <meillo@marmaro.de>
parents:
249
diff
changeset
|
337 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
|
338 if (!pw) { |
a41c013c8458
moved the queue manipulation code to an new function
markus schnalke <meillo@marmaro.de>
parents:
249
diff
changeset
|
339 fprintf(stderr, "could not find a passwd entry for uid %d: %s\n", |
a41c013c8458
moved the queue manipulation code to an new function
markus schnalke <meillo@marmaro.de>
parents:
249
diff
changeset
|
340 conf.orig_uid, strerror(errno)); |
a41c013c8458
moved the queue manipulation code to an new function
markus schnalke <meillo@marmaro.de>
parents:
249
diff
changeset
|
341 return FALSE; |
a41c013c8458
moved the queue manipulation code to an new function
markus schnalke <meillo@marmaro.de>
parents:
249
diff
changeset
|
342 } |
a41c013c8458
moved the queue manipulation code to an new function
markus schnalke <meillo@marmaro.de>
parents:
249
diff
changeset
|
343 |
a41c013c8458
moved the queue manipulation code to an new function
markus schnalke <meillo@marmaro.de>
parents:
249
diff
changeset
|
344 /* 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
|
345 for (; *id; id++) { |
a41c013c8458
moved the queue manipulation code to an new function
markus schnalke <meillo@marmaro.de>
parents:
249
diff
changeset
|
346 message *msg = msg_spool_read(*id, FALSE); |
a41c013c8458
moved the queue manipulation code to an new function
markus schnalke <meillo@marmaro.de>
parents:
249
diff
changeset
|
347 |
a41c013c8458
moved the queue manipulation code to an new function
markus schnalke <meillo@marmaro.de>
parents:
249
diff
changeset
|
348 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
|
349 |
a41c013c8458
moved the queue manipulation code to an new function
markus schnalke <meillo@marmaro.de>
parents:
249
diff
changeset
|
350 if (!msg->ident) { |
a41c013c8458
moved the queue manipulation code to an new function
markus schnalke <meillo@marmaro.de>
parents:
249
diff
changeset
|
351 fprintf(stderr, "message %s does not have an ident\n", *id); |
a41c013c8458
moved the queue manipulation code to an new function
markus schnalke <meillo@marmaro.de>
parents:
249
diff
changeset
|
352 continue; |
a41c013c8458
moved the queue manipulation code to an new function
markus schnalke <meillo@marmaro.de>
parents:
249
diff
changeset
|
353 } |
a41c013c8458
moved the queue manipulation code to an new function
markus schnalke <meillo@marmaro.de>
parents:
249
diff
changeset
|
354 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
|
355 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
|
356 continue; |
a41c013c8458
moved the queue manipulation code to an new function
markus schnalke <meillo@marmaro.de>
parents:
249
diff
changeset
|
357 } |
a41c013c8458
moved the queue manipulation code to an new function
markus schnalke <meillo@marmaro.de>
parents:
249
diff
changeset
|
358 |
a41c013c8458
moved the queue manipulation code to an new function
markus schnalke <meillo@marmaro.de>
parents:
249
diff
changeset
|
359 if ( (msg->received_host || (msg->received_prot != PROT_LOCAL)) |
a41c013c8458
moved the queue manipulation code to an new function
markus schnalke <meillo@marmaro.de>
parents:
249
diff
changeset
|
360 #ifdef ENABLE_IDENT |
a41c013c8458
moved the queue manipulation code to an new function
markus schnalke <meillo@marmaro.de>
parents:
249
diff
changeset
|
361 && !is_in_netlist(msg->received_host, conf.ident_trusted_nets) |
a41c013c8458
moved the queue manipulation code to an new function
markus schnalke <meillo@marmaro.de>
parents:
249
diff
changeset
|
362 #endif |
a41c013c8458
moved the queue manipulation code to an new function
markus schnalke <meillo@marmaro.de>
parents:
249
diff
changeset
|
363 ) { |
a41c013c8458
moved the queue manipulation code to an new function
markus schnalke <meillo@marmaro.de>
parents:
249
diff
changeset
|
364 fprintf(stderr, "message %s was not received locally or from a trusted network\n", *id); |
a41c013c8458
moved the queue manipulation code to an new function
markus schnalke <meillo@marmaro.de>
parents:
249
diff
changeset
|
365 continue; |
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 |
a41c013c8458
moved the queue manipulation code to an new function
markus schnalke <meillo@marmaro.de>
parents:
249
diff
changeset
|
368 ok = queue_delete(*id); |
a41c013c8458
moved the queue manipulation code to an new function
markus schnalke <meillo@marmaro.de>
parents:
249
diff
changeset
|
369 } |
a41c013c8458
moved the queue manipulation code to an new function
markus schnalke <meillo@marmaro.de>
parents:
249
diff
changeset
|
370 return ok; |
a41c013c8458
moved the queue manipulation code to an new function
markus schnalke <meillo@marmaro.de>
parents:
249
diff
changeset
|
371 } |
a41c013c8458
moved the queue manipulation code to an new function
markus schnalke <meillo@marmaro.de>
parents:
249
diff
changeset
|
372 |
264
1e5e457dea18
comments and a small refactoring
markus schnalke <meillo@marmaro.de>
parents:
263
diff
changeset
|
373 /* -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
|
374 static int |
2babd21e7c75
moved run_queue to a new function
markus schnalke <meillo@marmaro.de>
parents:
250
diff
changeset
|
375 run_queue(gboolean do_runq, gboolean do_runq_online, char* route_name) |
2babd21e7c75
moved run_queue to a new function
markus schnalke <meillo@marmaro.de>
parents:
250
diff
changeset
|
376 { |
2babd21e7c75
moved run_queue to a new function
markus schnalke <meillo@marmaro.de>
parents:
250
diff
changeset
|
377 int ret; |
2babd21e7c75
moved run_queue to a new function
markus schnalke <meillo@marmaro.de>
parents:
250
diff
changeset
|
378 |
2babd21e7c75
moved run_queue to a new function
markus schnalke <meillo@marmaro.de>
parents:
250
diff
changeset
|
379 /* queue runs */ |
2babd21e7c75
moved run_queue to a new function
markus schnalke <meillo@marmaro.de>
parents:
250
diff
changeset
|
380 set_identity(conf.orig_uid, "queue run"); |
2babd21e7c75
moved run_queue to a new function
markus schnalke <meillo@marmaro.de>
parents:
250
diff
changeset
|
381 |
2babd21e7c75
moved run_queue to a new function
markus schnalke <meillo@marmaro.de>
parents:
250
diff
changeset
|
382 if (do_runq) { |
2babd21e7c75
moved run_queue to a new function
markus schnalke <meillo@marmaro.de>
parents:
250
diff
changeset
|
383 ret = queue_run(); |
2babd21e7c75
moved run_queue to a new function
markus schnalke <meillo@marmaro.de>
parents:
250
diff
changeset
|
384 } |
2babd21e7c75
moved run_queue to a new function
markus schnalke <meillo@marmaro.de>
parents:
250
diff
changeset
|
385 |
2babd21e7c75
moved run_queue to a new function
markus schnalke <meillo@marmaro.de>
parents:
250
diff
changeset
|
386 if (do_runq_online) { |
2babd21e7c75
moved run_queue to a new function
markus schnalke <meillo@marmaro.de>
parents:
250
diff
changeset
|
387 if (route_name) { |
310
f10a56dc7481
reworked online_detect to the simpler online_query
meillo@marmaro.de
parents:
290
diff
changeset
|
388 conf.online_query = g_strdup_printf("/bin/echo %s", route_name); |
251
2babd21e7c75
moved run_queue to a new function
markus schnalke <meillo@marmaro.de>
parents:
250
diff
changeset
|
389 } |
290
792e0201c1b3
mark -qo (without argument) obsolete
markus schnalke <meillo@marmaro.de>
parents:
288
diff
changeset
|
390 /* TODO: change behavior of `-qo without argument'? |
792e0201c1b3
mark -qo (without argument) obsolete
markus schnalke <meillo@marmaro.de>
parents:
288
diff
changeset
|
391 Because that behavior is included in -q. */ |
251
2babd21e7c75
moved run_queue to a new function
markus schnalke <meillo@marmaro.de>
parents:
250
diff
changeset
|
392 ret = queue_run_online(); |
2babd21e7c75
moved run_queue to a new function
markus schnalke <meillo@marmaro.de>
parents:
250
diff
changeset
|
393 } |
2babd21e7c75
moved run_queue to a new function
markus schnalke <meillo@marmaro.de>
parents:
250
diff
changeset
|
394 return ret; |
2babd21e7c75
moved run_queue to a new function
markus schnalke <meillo@marmaro.de>
parents:
250
diff
changeset
|
395 } |
2babd21e7c75
moved run_queue to a new function
markus schnalke <meillo@marmaro.de>
parents:
250
diff
changeset
|
396 |
264
1e5e457dea18
comments and a small refactoring
markus schnalke <meillo@marmaro.de>
parents:
263
diff
changeset
|
397 /* -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
|
398 static void |
0afe18a9ee03
fixed previous commit and excluded mode_version() from main()
markus schnalke <meillo@marmaro.de>
parents:
260
diff
changeset
|
399 mode_version(void) |
0afe18a9ee03
fixed previous commit and excluded mode_version() from main()
markus schnalke <meillo@marmaro.de>
parents:
260
diff
changeset
|
400 { |
0afe18a9ee03
fixed previous commit and excluded mode_version() from main()
markus schnalke <meillo@marmaro.de>
parents:
260
diff
changeset
|
401 gchar *with_resolver = ""; |
0afe18a9ee03
fixed previous commit and excluded mode_version() from main()
markus schnalke <meillo@marmaro.de>
parents:
260
diff
changeset
|
402 gchar *with_auth = ""; |
0afe18a9ee03
fixed previous commit and excluded mode_version() from main()
markus schnalke <meillo@marmaro.de>
parents:
260
diff
changeset
|
403 gchar *with_ident = ""; |
0afe18a9ee03
fixed previous commit and excluded mode_version() from main()
markus schnalke <meillo@marmaro.de>
parents:
260
diff
changeset
|
404 |
0afe18a9ee03
fixed previous commit and excluded mode_version() from main()
markus schnalke <meillo@marmaro.de>
parents:
260
diff
changeset
|
405 #ifdef ENABLE_RESOLVER |
0afe18a9ee03
fixed previous commit and excluded mode_version() from main()
markus schnalke <meillo@marmaro.de>
parents:
260
diff
changeset
|
406 with_resolver = " +resolver"; |
0afe18a9ee03
fixed previous commit and excluded mode_version() from main()
markus schnalke <meillo@marmaro.de>
parents:
260
diff
changeset
|
407 #endif |
0afe18a9ee03
fixed previous commit and excluded mode_version() from main()
markus schnalke <meillo@marmaro.de>
parents:
260
diff
changeset
|
408 #ifdef ENABLE_AUTH |
0afe18a9ee03
fixed previous commit and excluded mode_version() from main()
markus schnalke <meillo@marmaro.de>
parents:
260
diff
changeset
|
409 with_auth = " +auth"; |
0afe18a9ee03
fixed previous commit and excluded mode_version() from main()
markus schnalke <meillo@marmaro.de>
parents:
260
diff
changeset
|
410 #endif |
0afe18a9ee03
fixed previous commit and excluded mode_version() from main()
markus schnalke <meillo@marmaro.de>
parents:
260
diff
changeset
|
411 #ifdef ENABLE_IDENT |
0afe18a9ee03
fixed previous commit and excluded mode_version() from main()
markus schnalke <meillo@marmaro.de>
parents:
260
diff
changeset
|
412 with_ident = " +ident"; |
0afe18a9ee03
fixed previous commit and excluded mode_version() from main()
markus schnalke <meillo@marmaro.de>
parents:
260
diff
changeset
|
413 #endif |
0afe18a9ee03
fixed previous commit and excluded mode_version() from main()
markus schnalke <meillo@marmaro.de>
parents:
260
diff
changeset
|
414 |
0afe18a9ee03
fixed previous commit and excluded mode_version() from main()
markus schnalke <meillo@marmaro.de>
parents:
260
diff
changeset
|
415 printf("%s %s%s%s%s\n", PACKAGE, VERSION, with_resolver, with_auth, with_ident); |
0afe18a9ee03
fixed previous commit and excluded mode_version() from main()
markus schnalke <meillo@marmaro.de>
parents:
260
diff
changeset
|
416 } |
0afe18a9ee03
fixed previous commit and excluded mode_version() from main()
markus schnalke <meillo@marmaro.de>
parents:
260
diff
changeset
|
417 |
281
ea5f86e0a81c
modes are now enforced exclusive
markus schnalke <meillo@marmaro.de>
parents:
278
diff
changeset
|
418 void |
ea5f86e0a81c
modes are now enforced exclusive
markus schnalke <meillo@marmaro.de>
parents:
278
diff
changeset
|
419 set_mode(enum mta_mode mode) |
ea5f86e0a81c
modes are now enforced exclusive
markus schnalke <meillo@marmaro.de>
parents:
278
diff
changeset
|
420 { |
ea5f86e0a81c
modes are now enforced exclusive
markus schnalke <meillo@marmaro.de>
parents:
278
diff
changeset
|
421 if (mta_mode && mta_mode!=mode) { |
ea5f86e0a81c
modes are now enforced exclusive
markus schnalke <meillo@marmaro.de>
parents:
278
diff
changeset
|
422 fprintf(stderr, "operation mode was already specified (%d vs. %d)\n", mta_mode, mode); |
ea5f86e0a81c
modes are now enforced exclusive
markus schnalke <meillo@marmaro.de>
parents:
278
diff
changeset
|
423 exit(1); |
ea5f86e0a81c
modes are now enforced exclusive
markus schnalke <meillo@marmaro.de>
parents:
278
diff
changeset
|
424 } |
ea5f86e0a81c
modes are now enforced exclusive
markus schnalke <meillo@marmaro.de>
parents:
278
diff
changeset
|
425 |
ea5f86e0a81c
modes are now enforced exclusive
markus schnalke <meillo@marmaro.de>
parents:
278
diff
changeset
|
426 mta_mode = mode; |
ea5f86e0a81c
modes are now enforced exclusive
markus schnalke <meillo@marmaro.de>
parents:
278
diff
changeset
|
427 return; |
ea5f86e0a81c
modes are now enforced exclusive
markus schnalke <meillo@marmaro.de>
parents:
278
diff
changeset
|
428 } |
ea5f86e0a81c
modes are now enforced exclusive
markus schnalke <meillo@marmaro.de>
parents:
278
diff
changeset
|
429 |
0 | 430 int |
431 main(int argc, char *argv[]) | |
432 { | |
251
2babd21e7c75
moved run_queue to a new function
markus schnalke <meillo@marmaro.de>
parents:
250
diff
changeset
|
433 gchar *progname; |
249
f9da5a7caeda
refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents:
248
diff
changeset
|
434 char* opt; |
f9da5a7caeda
refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents:
248
diff
changeset
|
435 gint arg; |
0 | 436 |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
437 gboolean do_listen = FALSE; |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
438 gboolean do_runq = FALSE; |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
439 gboolean do_runq_online = FALSE; |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
440 gboolean do_queue = FALSE; |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
441 gint queue_interval = 0; |
251
2babd21e7c75
moved run_queue to a new function
markus schnalke <meillo@marmaro.de>
parents:
250
diff
changeset
|
442 gchar *M_cmd = NULL; |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
443 gboolean opt_t = FALSE; |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
444 gboolean opt_i = FALSE; |
251
2babd21e7c75
moved run_queue to a new function
markus schnalke <meillo@marmaro.de>
parents:
250
diff
changeset
|
445 gchar *conf_file = CONF_FILE; |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
446 gchar *route_name = NULL; |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
447 gchar *f_address = NULL; |
251
2babd21e7c75
moved run_queue to a new function
markus schnalke <meillo@marmaro.de>
parents:
250
diff
changeset
|
448 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
|
449 gchar *full_sender_name = NULL; |
251
2babd21e7c75
moved run_queue to a new function
markus schnalke <meillo@marmaro.de>
parents:
250
diff
changeset
|
450 gboolean do_verbose = FALSE; |
2babd21e7c75
moved run_queue to a new function
markus schnalke <meillo@marmaro.de>
parents:
250
diff
changeset
|
451 gint debug_level = -1; |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
452 |
260
bd3109ec0f0a
substituted get_progname() with a call to strrchr()
markus schnalke <meillo@marmaro.de>
parents:
259
diff
changeset
|
453 /* strip the path part */ |
261
0afe18a9ee03
fixed previous commit and excluded mode_version() from main()
markus schnalke <meillo@marmaro.de>
parents:
260
diff
changeset
|
454 progname = strrchr(argv[0], '/'); |
0afe18a9ee03
fixed previous commit and excluded mode_version() from main()
markus schnalke <meillo@marmaro.de>
parents:
260
diff
changeset
|
455 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
|
456 |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
457 if (strcmp(progname, "mailq") == 0) { |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
458 mta_mode = MODE_LIST; |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
459 } else if (strcmp(progname, "mailrm") == 0) { |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
460 mta_mode = MODE_MCMD; |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
461 M_cmd = "rm"; |
284
4869321aa7bf
recognize the program name `newaliases' too
markus schnalke <meillo@marmaro.de>
parents:
282
diff
changeset
|
462 } else if (strcmp(progname, "newaliases") == 0) { |
4869321aa7bf
recognize the program name `newaliases' too
markus schnalke <meillo@marmaro.de>
parents:
282
diff
changeset
|
463 mta_mode = MODE_BI; |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
464 } else if (strcmp(progname, "rmail") == 0) { |
89 | 465 /* the `rmail' alias should probably be removed now |
466 that we have the rmail script. But let's keep it | |
467 for some while for compatibility. 2010-06-19 */ | |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
468 mta_mode = MODE_ACCEPT; |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
469 opt_i = TRUE; |
284
4869321aa7bf
recognize the program name `newaliases' too
markus schnalke <meillo@marmaro.de>
parents:
282
diff
changeset
|
470 } else if (strcmp(progname, "runq") == 0) { |
4869321aa7bf
recognize the program name `newaliases' too
markus schnalke <meillo@marmaro.de>
parents:
282
diff
changeset
|
471 mta_mode = MODE_RUNQUEUE; |
4869321aa7bf
recognize the program name `newaliases' too
markus schnalke <meillo@marmaro.de>
parents:
282
diff
changeset
|
472 do_runq = TRUE; |
4869321aa7bf
recognize the program name `newaliases' too
markus schnalke <meillo@marmaro.de>
parents:
282
diff
changeset
|
473 } else if (strcmp(progname, "smtpd") == 0 |
4869321aa7bf
recognize the program name `newaliases' too
markus schnalke <meillo@marmaro.de>
parents:
282
diff
changeset
|
474 || strcmp(progname, "in.smtpd") == 0) { |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
475 mta_mode = MODE_SMTP; |
0 | 476 } |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
477 |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
478 /* parse cmd line */ |
249
f9da5a7caeda
refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents:
248
diff
changeset
|
479 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
|
480 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
|
481 |
f9da5a7caeda
refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents:
248
diff
changeset
|
482 if (strcmp(opt, "-") == 0) { |
f9da5a7caeda
refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents:
248
diff
changeset
|
483 /* everything after `--' are address arguments */ |
f9da5a7caeda
refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents:
248
diff
changeset
|
484 arg++; |
f9da5a7caeda
refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents:
248
diff
changeset
|
485 break; |
f9da5a7caeda
refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents:
248
diff
changeset
|
486 |
278
c35c59a36a2a
added -bm for mode accept (the other MTAs have it too)
markus schnalke <meillo@marmaro.de>
parents:
276
diff
changeset
|
487 } else if (strcmp(opt, "bm") == 0) { |
281
ea5f86e0a81c
modes are now enforced exclusive
markus schnalke <meillo@marmaro.de>
parents:
278
diff
changeset
|
488 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
|
489 |
249
f9da5a7caeda
refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents:
248
diff
changeset
|
490 } else if (strcmp(opt, "bd") == 0) { |
281
ea5f86e0a81c
modes are now enforced exclusive
markus schnalke <meillo@marmaro.de>
parents:
278
diff
changeset
|
491 set_mode(MODE_DAEMON); |
249
f9da5a7caeda
refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents:
248
diff
changeset
|
492 do_listen = TRUE; |
f9da5a7caeda
refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents:
248
diff
changeset
|
493 |
f9da5a7caeda
refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents:
248
diff
changeset
|
494 } else if (strcmp(opt, "bi") == 0) { |
281
ea5f86e0a81c
modes are now enforced exclusive
markus schnalke <meillo@marmaro.de>
parents:
278
diff
changeset
|
495 set_mode(MODE_BI); |
249
f9da5a7caeda
refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents:
248
diff
changeset
|
496 |
f9da5a7caeda
refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents:
248
diff
changeset
|
497 } else if (strcmp(opt, "bs") == 0) { |
281
ea5f86e0a81c
modes are now enforced exclusive
markus schnalke <meillo@marmaro.de>
parents:
278
diff
changeset
|
498 set_mode(MODE_SMTP); |
249
f9da5a7caeda
refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents:
248
diff
changeset
|
499 |
f9da5a7caeda
refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents:
248
diff
changeset
|
500 } else if (strcmp(opt, "bp") == 0) { |
281
ea5f86e0a81c
modes are now enforced exclusive
markus schnalke <meillo@marmaro.de>
parents:
278
diff
changeset
|
501 set_mode(MODE_LIST); |
249
f9da5a7caeda
refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents:
248
diff
changeset
|
502 |
f9da5a7caeda
refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents:
248
diff
changeset
|
503 } else if (strcmp(opt, "bV") == 0) { |
281
ea5f86e0a81c
modes are now enforced exclusive
markus schnalke <meillo@marmaro.de>
parents:
278
diff
changeset
|
504 set_mode(MODE_VERSION); |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
505 |
249
f9da5a7caeda
refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents:
248
diff
changeset
|
506 } else if (strncmp(opt, "B", 1) == 0) { |
f9da5a7caeda
refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents:
248
diff
changeset
|
507 /* we ignore this and throw the argument away */ |
f9da5a7caeda
refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents:
248
diff
changeset
|
508 get_optarg(argv, &arg, opt+1); |
f9da5a7caeda
refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents:
248
diff
changeset
|
509 |
f9da5a7caeda
refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents:
248
diff
changeset
|
510 } 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
|
511 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
|
512 if (!conf_file) { |
249
f9da5a7caeda
refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents:
248
diff
changeset
|
513 fprintf(stderr, "-C requires a filename as argument.\n"); |
262
fc1c6425c024
s/EXIT_SUCCESS/0/ && s/EXIT_FAILURE/1/
markus schnalke <meillo@marmaro.de>
parents:
261
diff
changeset
|
514 exit(1); |
249
f9da5a7caeda
refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents:
248
diff
changeset
|
515 } |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
516 |
249
f9da5a7caeda
refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents:
248
diff
changeset
|
517 } else if (strncmp(opt, "d", 1) == 0) { |
f9da5a7caeda
refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents:
248
diff
changeset
|
518 if (getuid() != 0) { |
f9da5a7caeda
refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents:
248
diff
changeset
|
519 fprintf(stderr, "only root may set the debug level.\n"); |
262
fc1c6425c024
s/EXIT_SUCCESS/0/ && s/EXIT_FAILURE/1/
markus schnalke <meillo@marmaro.de>
parents:
261
diff
changeset
|
520 exit(1); |
249
f9da5a7caeda
refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents:
248
diff
changeset
|
521 } |
f9da5a7caeda
refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents:
248
diff
changeset
|
522 char *lvl = get_optarg(argv, &arg, opt+1); |
f9da5a7caeda
refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents:
248
diff
changeset
|
523 if (!lvl) { |
f9da5a7caeda
refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents:
248
diff
changeset
|
524 fprintf(stderr, "-d requires a number argument.\n"); |
262
fc1c6425c024
s/EXIT_SUCCESS/0/ && s/EXIT_FAILURE/1/
markus schnalke <meillo@marmaro.de>
parents:
261
diff
changeset
|
525 exit(1); |
249
f9da5a7caeda
refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents:
248
diff
changeset
|
526 } |
f9da5a7caeda
refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents:
248
diff
changeset
|
527 debug_level = atoi(lvl); |
f9da5a7caeda
refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents:
248
diff
changeset
|
528 |
f9da5a7caeda
refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents:
248
diff
changeset
|
529 } else if (strncmp(opt, "f", 1) == 0) { |
f9da5a7caeda
refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents:
248
diff
changeset
|
530 /* set return path */ |
f9da5a7caeda
refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents:
248
diff
changeset
|
531 gchar *address = get_optarg(argv, &arg, opt+1); |
f9da5a7caeda
refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents:
248
diff
changeset
|
532 if (!address) { |
f9da5a7caeda
refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents:
248
diff
changeset
|
533 fprintf(stderr, "-f requires an address argument\n"); |
262
fc1c6425c024
s/EXIT_SUCCESS/0/ && s/EXIT_FAILURE/1/
markus schnalke <meillo@marmaro.de>
parents:
261
diff
changeset
|
534 exit(1); |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
535 } |
249
f9da5a7caeda
refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents:
248
diff
changeset
|
536 f_address = g_strdup(address); |
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 (strncmp(opt, "F", 1) == 0) { |
f9da5a7caeda
refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents:
248
diff
changeset
|
539 full_sender_name = get_optarg(argv, &arg, opt+1); |
f9da5a7caeda
refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents:
248
diff
changeset
|
540 if (!full_sender_name) { |
f9da5a7caeda
refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents:
248
diff
changeset
|
541 fprintf(stderr, "-F requires a name argument\n"); |
262
fc1c6425c024
s/EXIT_SUCCESS/0/ && s/EXIT_FAILURE/1/
markus schnalke <meillo@marmaro.de>
parents:
261
diff
changeset
|
542 exit(1); |
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 |
f9da5a7caeda
refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents:
248
diff
changeset
|
545 } else if (strcmp(opt, "i") == 0) { |
f9da5a7caeda
refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents:
248
diff
changeset
|
546 opt_i = TRUE; |
f9da5a7caeda
refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents:
248
diff
changeset
|
547 |
f9da5a7caeda
refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents:
248
diff
changeset
|
548 } else if (strcmp(opt, "m") == 0) { |
f9da5a7caeda
refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents:
248
diff
changeset
|
549 /* ignore -m (me too) switch (see man page) */ |
f9da5a7caeda
refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents:
248
diff
changeset
|
550 |
f9da5a7caeda
refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents:
248
diff
changeset
|
551 } else if (strcmp(opt, "Mrm") == 0) { |
281
ea5f86e0a81c
modes are now enforced exclusive
markus schnalke <meillo@marmaro.de>
parents:
278
diff
changeset
|
552 set_mode(MODE_MCMD); |
249
f9da5a7caeda
refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents:
248
diff
changeset
|
553 M_cmd = "rm"; |
f9da5a7caeda
refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents:
248
diff
changeset
|
554 |
f9da5a7caeda
refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents:
248
diff
changeset
|
555 } else if (strcmp(opt, "odq") == 0) { |
f9da5a7caeda
refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents:
248
diff
changeset
|
556 do_queue = TRUE; |
f9da5a7caeda
refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents:
248
diff
changeset
|
557 |
f9da5a7caeda
refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents:
248
diff
changeset
|
558 } 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
|
559 opt_i = TRUE; |
249
f9da5a7caeda
refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents:
248
diff
changeset
|
560 |
f9da5a7caeda
refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents:
248
diff
changeset
|
561 } else if (strncmp(opt, "o", 1) == 0) { |
f9da5a7caeda
refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents:
248
diff
changeset
|
562 /* ignore all other -oXXX options */ |
f9da5a7caeda
refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents:
248
diff
changeset
|
563 |
f9da5a7caeda
refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents:
248
diff
changeset
|
564 } 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
|
565 /* must be before the `q' check */ |
281
ea5f86e0a81c
modes are now enforced exclusive
markus schnalke <meillo@marmaro.de>
parents:
278
diff
changeset
|
566 set_mode(MODE_RUNQUEUE); |
249
f9da5a7caeda
refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents:
248
diff
changeset
|
567 do_runq_online = TRUE; |
f9da5a7caeda
refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents:
248
diff
changeset
|
568 /* 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
|
569 /* TODO: behavior might change if it is NULL */ |
249
f9da5a7caeda
refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents:
248
diff
changeset
|
570 route_name = get_optarg(argv, &arg, opt+2); |
290
792e0201c1b3
mark -qo (without argument) obsolete
markus schnalke <meillo@marmaro.de>
parents:
288
diff
changeset
|
571 if (!route_name) { |
792e0201c1b3
mark -qo (without argument) obsolete
markus schnalke <meillo@marmaro.de>
parents:
288
diff
changeset
|
572 fprintf(stderr, "Please do not use -qo without argument anymore; use -q instead.\n"); |
792e0201c1b3
mark -qo (without argument) obsolete
markus schnalke <meillo@marmaro.de>
parents:
288
diff
changeset
|
573 fprintf(stderr, "The behavior for -qo without argument is likely to change.\n"); |
792e0201c1b3
mark -qo (without argument) obsolete
markus schnalke <meillo@marmaro.de>
parents:
288
diff
changeset
|
574 } |
249
f9da5a7caeda
refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents:
248
diff
changeset
|
575 |
f9da5a7caeda
refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents:
248
diff
changeset
|
576 } else if (strncmp(opt, "q", 1) == 0) { |
f9da5a7caeda
refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents:
248
diff
changeset
|
577 /* must be after the `qo' check */ |
f9da5a7caeda
refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents:
248
diff
changeset
|
578 gchar *optarg; |
f9da5a7caeda
refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents:
248
diff
changeset
|
579 |
251
2babd21e7c75
moved run_queue to a new function
markus schnalke <meillo@marmaro.de>
parents:
250
diff
changeset
|
580 optarg = get_optarg(argv, &arg, opt+1); |
2babd21e7c75
moved run_queue to a new function
markus schnalke <meillo@marmaro.de>
parents:
250
diff
changeset
|
581 if (optarg) { |
2babd21e7c75
moved run_queue to a new function
markus schnalke <meillo@marmaro.de>
parents:
250
diff
changeset
|
582 /* not just one single queue run but regular runs */ |
281
ea5f86e0a81c
modes are now enforced exclusive
markus schnalke <meillo@marmaro.de>
parents:
278
diff
changeset
|
583 set_mode(MODE_DAEMON); |
254
82d168dd52fd
removed the obsolete pos argument from time_interval()
markus schnalke <meillo@marmaro.de>
parents:
251
diff
changeset
|
584 queue_interval = time_interval(optarg); |
281
ea5f86e0a81c
modes are now enforced exclusive
markus schnalke <meillo@marmaro.de>
parents:
278
diff
changeset
|
585 } else { |
ea5f86e0a81c
modes are now enforced exclusive
markus schnalke <meillo@marmaro.de>
parents:
278
diff
changeset
|
586 set_mode(MODE_RUNQUEUE); |
ea5f86e0a81c
modes are now enforced exclusive
markus schnalke <meillo@marmaro.de>
parents:
278
diff
changeset
|
587 do_runq = TRUE; |
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, "t") == 0) { |
f9da5a7caeda
refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents:
248
diff
changeset
|
591 opt_t = 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, "v") == 0) { |
f9da5a7caeda
refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents:
248
diff
changeset
|
594 do_verbose = TRUE; |
f9da5a7caeda
refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents:
248
diff
changeset
|
595 |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
596 } else { |
249
f9da5a7caeda
refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents:
248
diff
changeset
|
597 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
|
598 exit(1); |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
599 } |
0 | 600 } |
601 | |
281
ea5f86e0a81c
modes are now enforced exclusive
markus schnalke <meillo@marmaro.de>
parents:
278
diff
changeset
|
602 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
|
603 /* |
c35c59a36a2a
added -bm for mode accept (the other MTAs have it too)
markus schnalke <meillo@marmaro.de>
parents:
276
diff
changeset
|
604 In this case no rcpts can be found, thus no mail |
c35c59a36a2a
added -bm for mode accept (the other MTAs have it too)
markus schnalke <meillo@marmaro.de>
parents:
276
diff
changeset
|
605 can be sent, thus masqmail will always fail. We |
c35c59a36a2a
added -bm for mode accept (the other MTAs have it too)
markus schnalke <meillo@marmaro.de>
parents:
276
diff
changeset
|
606 rather do something better instead. This covers |
c35c59a36a2a
added -bm for mode accept (the other MTAs have it too)
markus schnalke <meillo@marmaro.de>
parents:
276
diff
changeset
|
607 also the case of calling masqmail without args. |
c35c59a36a2a
added -bm for mode accept (the other MTAs have it too)
markus schnalke <meillo@marmaro.de>
parents:
276
diff
changeset
|
608 */ |
281
ea5f86e0a81c
modes are now enforced exclusive
markus schnalke <meillo@marmaro.de>
parents:
278
diff
changeset
|
609 mode_version(); |
ea5f86e0a81c
modes are now enforced exclusive
markus schnalke <meillo@marmaro.de>
parents:
278
diff
changeset
|
610 exit(0); |
259
f4117fd5a163
made default mode sensible
markus schnalke <meillo@marmaro.de>
parents:
258
diff
changeset
|
611 } |
f4117fd5a163
made default mode sensible
markus schnalke <meillo@marmaro.de>
parents:
258
diff
changeset
|
612 |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
613 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
|
614 mode_version(); |
262
fc1c6425c024
s/EXIT_SUCCESS/0/ && s/EXIT_FAILURE/1/
markus schnalke <meillo@marmaro.de>
parents:
261
diff
changeset
|
615 exit(0); |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
616 } |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
617 |
281
ea5f86e0a81c
modes are now enforced exclusive
markus schnalke <meillo@marmaro.de>
parents:
278
diff
changeset
|
618 if (!mta_mode) { |
ea5f86e0a81c
modes are now enforced exclusive
markus schnalke <meillo@marmaro.de>
parents:
278
diff
changeset
|
619 mta_mode = MODE_ACCEPT; |
ea5f86e0a81c
modes are now enforced exclusive
markus schnalke <meillo@marmaro.de>
parents:
278
diff
changeset
|
620 } |
ea5f86e0a81c
modes are now enforced exclusive
markus schnalke <meillo@marmaro.de>
parents:
278
diff
changeset
|
621 |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
622 /* initialize random generator */ |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
623 srand(time(NULL)); |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
624 /* ignore SIGPIPE signal */ |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
625 signal(SIGPIPE, SIG_IGN); |
0 | 626 |
73 | 627 /* 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
|
628 { |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
629 int i, max_fd = sysconf(_SC_OPEN_MAX); |
0 | 630 |
251
2babd21e7c75
moved run_queue to a new function
markus schnalke <meillo@marmaro.de>
parents:
250
diff
changeset
|
631 if (max_fd <= 0) { |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
632 max_fd = 64; |
251
2babd21e7c75
moved run_queue to a new function
markus schnalke <meillo@marmaro.de>
parents:
250
diff
changeset
|
633 } |
2babd21e7c75
moved run_queue to a new function
markus schnalke <meillo@marmaro.de>
parents:
250
diff
changeset
|
634 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
|
635 close(i); |
251
2babd21e7c75
moved run_queue to a new function
markus schnalke <meillo@marmaro.de>
parents:
250
diff
changeset
|
636 } |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
637 } |
0 | 638 |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
639 init_conf(); |
0 | 640 |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
641 /* if we are not privileged, and the config file was changed we |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
642 implicetely set the the run_as_user flag and give up all |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
643 privileges. |
0 | 644 |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
645 So it is possible for a user to run his own daemon without |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
646 breaking security. |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
647 */ |
251
2babd21e7c75
moved run_queue to a new function
markus schnalke <meillo@marmaro.de>
parents:
250
diff
changeset
|
648 if ((strcmp(conf_file, CONF_FILE) != 0) && (conf.orig_uid != 0)) { |
2babd21e7c75
moved run_queue to a new function
markus schnalke <meillo@marmaro.de>
parents:
250
diff
changeset
|
649 conf.run_as_user = TRUE; |
2babd21e7c75
moved run_queue to a new function
markus schnalke <meillo@marmaro.de>
parents:
250
diff
changeset
|
650 seteuid(conf.orig_uid); |
2babd21e7c75
moved run_queue to a new function
markus schnalke <meillo@marmaro.de>
parents:
250
diff
changeset
|
651 setegid(conf.orig_gid); |
2babd21e7c75
moved run_queue to a new function
markus schnalke <meillo@marmaro.de>
parents:
250
diff
changeset
|
652 setuid(conf.orig_uid); |
2babd21e7c75
moved run_queue to a new function
markus schnalke <meillo@marmaro.de>
parents:
250
diff
changeset
|
653 setgid(conf.orig_gid); |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
654 } |
0 | 655 |
155 | 656 conf.log_dir = LOG_DIR; |
288
84ea0b1fc8f8
FIXME comment: where to log while reading the config file?
markus schnalke <meillo@marmaro.de>
parents:
284
diff
changeset
|
657 /* FIXME: fails if we run as user */ |
155 | 658 logopen(); |
659 if (!read_conf(conf_file)) { | |
660 logwrite(LOG_ALERT, "SHUTTING DOWN due to problems reading config\n"); | |
661 exit(5); | |
662 } | |
663 logclose(); | |
0 | 664 |
251
2babd21e7c75
moved run_queue to a new function
markus schnalke <meillo@marmaro.de>
parents:
250
diff
changeset
|
665 if (do_queue) { |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
666 conf.do_queue = TRUE; |
251
2babd21e7c75
moved run_queue to a new function
markus schnalke <meillo@marmaro.de>
parents:
250
diff
changeset
|
667 } |
2babd21e7c75
moved run_queue to a new function
markus schnalke <meillo@marmaro.de>
parents:
250
diff
changeset
|
668 if (do_verbose) { |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
669 conf.do_verbose = TRUE; |
251
2babd21e7c75
moved run_queue to a new function
markus schnalke <meillo@marmaro.de>
parents:
250
diff
changeset
|
670 } |
2babd21e7c75
moved run_queue to a new function
markus schnalke <meillo@marmaro.de>
parents:
250
diff
changeset
|
671 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
|
672 conf.debug_level = debug_level; |
251
2babd21e7c75
moved run_queue to a new function
markus schnalke <meillo@marmaro.de>
parents:
250
diff
changeset
|
673 } |
0 | 674 |
46 | 675 /* It appears that changing to / ensures that we are never in |
676 a directory which we cannot access. This situation could be | |
677 possible after changing identity. | |
678 Maybe we should only change to / if we not run as user, to | |
679 allow relative paths for log files in test setups for | |
680 instance. | |
681 */ | |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
682 chdir("/"); |
0 | 683 |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
684 if (!conf.run_as_user) { |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
685 if (setgid(0) != 0) { |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
686 fprintf(stderr, "could not set gid to 0. Is the setuid bit set? : %s\n", strerror(errno)); |
262
fc1c6425c024
s/EXIT_SUCCESS/0/ && s/EXIT_FAILURE/1/
markus schnalke <meillo@marmaro.de>
parents:
261
diff
changeset
|
687 exit(1); |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
688 } |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
689 if (setuid(0) != 0) { |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
690 fprintf(stderr, "could not gain root privileges. Is the setuid bit set? : %s\n", strerror(errno)); |
262
fc1c6425c024
s/EXIT_SUCCESS/0/ && s/EXIT_FAILURE/1/
markus schnalke <meillo@marmaro.de>
parents:
261
diff
changeset
|
691 exit(1); |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
692 } |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
693 } |
0 | 694 |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
695 if (!logopen()) { |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
696 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
|
697 exit(1); |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
698 } |
0 | 699 |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
700 DEBUG(1) debugf("masqmail %s starting\n", VERSION); |
0 | 701 |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
702 DEBUG(5) { |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
703 gchar **str = argv; |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
704 debugf("args: \n"); |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
705 while (*str) { |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
706 debugf("%s \n", *str); |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
707 str++; |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
708 } |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
709 } |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
710 DEBUG(5) debugf("queue_interval = %d\n", queue_interval); |
0 | 711 |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
712 if (f_address) { |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
713 return_path = create_address_qualified(f_address, TRUE, conf.host_name); |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
714 g_free(f_address); |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
715 if (!return_path) { |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
716 fprintf(stderr, "invalid RFC821 address: %s\n", f_address); |
262
fc1c6425c024
s/EXIT_SUCCESS/0/ && s/EXIT_FAILURE/1/
markus schnalke <meillo@marmaro.de>
parents:
261
diff
changeset
|
717 exit(1); |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
718 } |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
719 } |
0 | 720 |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
721 switch (mta_mode) { |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
722 case MODE_DAEMON: |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
723 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
|
724 break; |
251
2babd21e7c75
moved run_queue to a new function
markus schnalke <meillo@marmaro.de>
parents:
250
diff
changeset
|
725 |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
726 case MODE_RUNQUEUE: |
251
2babd21e7c75
moved run_queue to a new function
markus schnalke <meillo@marmaro.de>
parents:
250
diff
changeset
|
727 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
|
728 break; |
0 | 729 |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
730 case MODE_SMTP: |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
731 mode_smtp(); |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
732 break; |
0 | 733 |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
734 case MODE_LIST: |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
735 queue_list(); |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
736 break; |
0 | 737 |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
738 case MODE_BI: |
262
fc1c6425c024
s/EXIT_SUCCESS/0/ && s/EXIT_FAILURE/1/
markus schnalke <meillo@marmaro.de>
parents:
261
diff
changeset
|
739 exit(0); |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
740 break; /* well... */ |
0 | 741 |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
742 case MODE_MCMD: |
250
a41c013c8458
moved the queue manipulation code to an new function
markus schnalke <meillo@marmaro.de>
parents:
249
diff
changeset
|
743 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
|
744 break; |
0 | 745 |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
746 case MODE_ACCEPT: |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
747 { |
268
7b12d081b939
removed ACC_DEL_RCPTS because it's always used with ACC_RCPT_FROM_HEAD
markus schnalke <meillo@marmaro.de>
parents:
267
diff
changeset
|
748 guint accept_flags = (opt_t ? ACC_RCPT_FROM_HEAD : 0) |
110
c678d0342451
changed name ACC_NODOT_TERM to ACC_DOT_IGNORE for better understanding
meillo@marmaro.de
parents:
107
diff
changeset
|
749 | (opt_i ? ACC_DOT_IGNORE : ACC_NODOT_RELAX); |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
750 mode_accept(return_path, full_sender_name, accept_flags, &(argv[arg]), argc - arg); |
258
05fa719b7002
fixed -oem by removing it ;-)
markus schnalke <meillo@marmaro.de>
parents:
257
diff
changeset
|
751 exit(0); |
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 break; |
251
2babd21e7c75
moved run_queue to a new function
markus schnalke <meillo@marmaro.de>
parents:
250
diff
changeset
|
754 |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
755 default: |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
756 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
|
757 break; |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
758 } |
0 | 759 |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
760 logclose(); |
0 | 761 |
263
e9e73505ab2c
removed now obsolete exit_code
markus schnalke <meillo@marmaro.de>
parents:
262
diff
changeset
|
762 exit(0); |
0 | 763 } |