Mercurial > masqmail
annotate src/masqmail.c @ 256:d4d0defaf769
updated ChangeLog
author | markus schnalke <meillo@marmaro.de> |
---|---|
date | Thu, 04 Nov 2010 14:57:53 -0300 |
parents | 82d168dd52fd |
children | 8cca5305e4f0 |
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.*/ | |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
40 typedef enum _mta_mode { |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
41 MODE_ACCEPT = 0, /* accept message on stdin */ |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
42 MODE_DAEMON, /* run as daemon */ |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
43 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
|
44 MODE_SMTP, /* accept SMTP on stdin */ |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
45 MODE_LIST, /* list queue */ |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
46 MODE_MCMD, /* do queue manipulation */ |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
47 MODE_VERSION, /* show version */ |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
48 MODE_BI, /* fake ;-) */ |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
49 MODE_NONE /* to prevent default MODE_ACCEPT */ |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
50 } mta_mode; |
0 | 51 |
52 char *pidfile = NULL; | |
53 volatile int sigterm_in_progress = 0; | |
54 | |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
55 static void |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
56 sigterm_handler(int sig) |
0 | 57 { |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
58 if (sigterm_in_progress) |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
59 raise(sig); |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
60 sigterm_in_progress = 1; |
0 | 61 |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
62 if (pidfile) { |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
63 uid_t uid; |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
64 uid = seteuid(0); |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
65 if (unlink(pidfile) != 0) |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
66 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
|
67 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
|
68 } |
0 | 69 |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
70 signal(sig, SIG_DFL); |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
71 raise(sig); |
0 | 72 } |
73 | |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
74 #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
|
75 static gboolean |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
76 is_in_netlist(gchar * host, GList * netlist) |
0 | 77 { |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
78 guint hostip = inet_addr(host); |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
79 struct in_addr addr; |
0 | 80 |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
81 addr.s_addr = hostip; |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
82 if (addr.s_addr != INADDR_NONE) { |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
83 GList *node; |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
84 foreach(netlist, node) { |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
85 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
|
86 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
|
87 return TRUE; |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
88 } |
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 return FALSE; |
0 | 91 } |
92 #endif | |
93 | |
249
f9da5a7caeda
refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents:
248
diff
changeset
|
94 /* |
f9da5a7caeda
refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents:
248
diff
changeset
|
95 argv: the original argv |
f9da5a7caeda
refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents:
248
diff
changeset
|
96 argp: number of arg (may get modified!) |
f9da5a7caeda
refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents:
248
diff
changeset
|
97 cp: pointing to the char after the option |
f9da5a7caeda
refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents:
248
diff
changeset
|
98 e.g. `-d 6' `-d6' |
f9da5a7caeda
refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents:
248
diff
changeset
|
99 ^ ^ |
f9da5a7caeda
refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents:
248
diff
changeset
|
100 */ |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
101 gchar* |
249
f9da5a7caeda
refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents:
248
diff
changeset
|
102 get_optarg(char* argv[], gint* argp, char* cp) |
0 | 103 { |
249
f9da5a7caeda
refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents:
248
diff
changeset
|
104 if (*cp) { |
f9da5a7caeda
refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents:
248
diff
changeset
|
105 /* this kind: -xval */ |
f9da5a7caeda
refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents:
248
diff
changeset
|
106 return cp; |
f9da5a7caeda
refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents:
248
diff
changeset
|
107 } |
f9da5a7caeda
refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents:
248
diff
changeset
|
108 cp = argv[*argp+1]; |
f9da5a7caeda
refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents:
248
diff
changeset
|
109 if (cp && (*cp != '-')) { |
f9da5a7caeda
refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents:
248
diff
changeset
|
110 /* this kind: -x val */ |
f9da5a7caeda
refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents:
248
diff
changeset
|
111 (*argp)++; |
f9da5a7caeda
refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents:
248
diff
changeset
|
112 return cp; |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
113 } |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
114 return NULL; |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
115 } |
0 | 116 |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
117 gchar* |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
118 get_progname(gchar * arg0) |
0 | 119 { |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
120 gchar *p = arg0 + strlen(arg0) - 1; |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
121 while (p > arg0) { |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
122 if (*p == '/') |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
123 return p + 1; |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
124 p--; |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
125 } |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
126 return p; |
0 | 127 } |
128 | |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
129 gboolean |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
130 write_pidfile(gchar * name) |
0 | 131 { |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
132 FILE *fptr; |
0 | 133 |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
134 if ((fptr = fopen(name, "wt"))) { |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
135 fprintf(fptr, "%d\n", getpid()); |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
136 fclose(fptr); |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
137 pidfile = strdup(name); |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
138 return TRUE; |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
139 } |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
140 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
|
141 return FALSE; |
0 | 142 } |
143 | |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
144 static void |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
145 mode_daemon(gboolean do_listen, gint queue_interval, char *argv[]) |
0 | 146 { |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
147 guint pid; |
0 | 148 |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
149 /* daemon */ |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
150 if (!conf.run_as_user) { |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
151 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
|
152 fprintf(stderr, "must be root or %s for daemon.\n", DEF_MAIL_USER); |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
153 exit(EXIT_FAILURE); |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
154 } |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
155 } |
0 | 156 |
74
0a5b2e96ade3
do not reparent the daemon to init if init is already the parent
meillo@marmaro.de
parents:
73
diff
changeset
|
157 /* 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
|
158 if (getppid() != 1) { |
0a5b2e96ade3
do not reparent the daemon to init if init is already the parent
meillo@marmaro.de
parents:
73
diff
changeset
|
159 if ((pid = fork()) > 0) { |
0a5b2e96ade3
do not reparent the daemon to init if init is already the parent
meillo@marmaro.de
parents:
73
diff
changeset
|
160 exit(EXIT_SUCCESS); |
0a5b2e96ade3
do not reparent the daemon to init if init is already the parent
meillo@marmaro.de
parents:
73
diff
changeset
|
161 } 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
|
162 logwrite(LOG_ALERT, "could not fork!\n"); |
74
0a5b2e96ade3
do not reparent the daemon to init if init is already the parent
meillo@marmaro.de
parents:
73
diff
changeset
|
163 exit(EXIT_FAILURE); |
0a5b2e96ade3
do not reparent the daemon to init if init is already the parent
meillo@marmaro.de
parents:
73
diff
changeset
|
164 } |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
165 } |
0 | 166 |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
167 signal(SIGTERM, sigterm_handler); |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
168 write_pidfile(PIDFILEDIR "/masqmail.pid"); |
0 | 169 |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
170 conf.do_verbose = FALSE; |
0 | 171 |
72
ad034b57f3b2
fixed Debian bug 536060 (log files are closed after SIGHUP receival)
meillo@marmaro.de
parents:
46
diff
changeset
|
172 /* 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
|
173 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
|
174 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
|
175 */ |
ad034b57f3b2
fixed Debian bug 536060 (log files are closed after SIGHUP receival)
meillo@marmaro.de
parents:
46
diff
changeset
|
176 logclose(); |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
177 fclose(stdin); |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
178 fclose(stdout); |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
179 fclose(stderr); |
72
ad034b57f3b2
fixed Debian bug 536060 (log files are closed after SIGHUP receival)
meillo@marmaro.de
parents:
46
diff
changeset
|
180 logopen(); |
0 | 181 |
208
3708b655a371
added newlines to the end of log and debug messages where missing
meillo@marmaro.de
parents:
205
diff
changeset
|
182 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
|
183 listen_port(do_listen ? conf.listen_addresses : NULL, queue_interval, argv); |
0 | 184 } |
185 | |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
186 static void |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
187 mode_smtp() |
0 | 188 { |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
189 /* accept smtp message on stdin */ |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
190 /* write responses to stderr. */ |
0 | 191 |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
192 struct sockaddr_in saddr; |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
193 gchar *peername = NULL; |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
194 int dummy = sizeof(saddr); |
0 | 195 |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
196 conf.do_verbose = FALSE; |
0 | 197 |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
198 if (!conf.run_as_user) { |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
199 seteuid(conf.orig_uid); |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
200 setegid(conf.orig_gid); |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
201 } |
0 | 202 |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
203 DEBUG(5) debugf("accepting smtp message on stdin\n"); |
0 | 204 |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
205 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
|
206 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
|
207 } else if (errno != ENOTSOCK) |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
208 exit(EXIT_FAILURE); |
0 | 209 |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
210 smtp_in(stdin, stderr, peername, NULL); |
0 | 211 } |
212 | |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
213 static void |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
214 mode_accept(address * return_path, gchar * full_sender_name, guint accept_flags, char **addresses, int addr_cnt) |
0 | 215 { |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
216 /* accept message on stdin */ |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
217 accept_error err; |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
218 message *msg = create_message(); |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
219 gint i; |
0 | 220 |
83
085d6cd44462
using is_privileged_user() to check here too
meillo@marmaro.de
parents:
76
diff
changeset
|
221 if (return_path && !is_privileged_user(conf.orig_uid)) { |
96 | 222 fprintf(stderr, "must be root, %s or in group %s for setting return path.\n", DEF_MAIL_USER, DEF_MAIL_GROUP); |
83
085d6cd44462
using is_privileged_user() to check here too
meillo@marmaro.de
parents:
76
diff
changeset
|
223 exit(EXIT_FAILURE); |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
224 } |
0 | 225 |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
226 if (!conf.run_as_user) { |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
227 seteuid(conf.orig_uid); |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
228 setegid(conf.orig_gid); |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
229 } |
0 | 230 |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
231 DEBUG(5) debugf("accepting message on stdin\n"); |
0 | 232 |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
233 msg->received_prot = PROT_LOCAL; |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
234 for (i = 0; i < addr_cnt; i++) { |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
235 if (addresses[i][0] != '|') |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
236 msg->rcpt_list = g_list_append(msg->rcpt_list, create_address_qualified(addresses[i], TRUE, conf.host_name)); |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
237 else { |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
238 logwrite(LOG_ALERT, "no pipe allowed as recipient address: %s\n", addresses[i]); |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
239 exit(EXIT_FAILURE); |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
240 } |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
241 } |
0 | 242 |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
243 /* -f option */ |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
244 msg->return_path = return_path; |
0 | 245 |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
246 /* -F option */ |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
247 msg->full_sender_name = full_sender_name; |
0 | 248 |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
249 if ((err = accept_message(stdin, msg, accept_flags)) == AERR_OK) { |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
250 if (spool_write(msg, TRUE)) { |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
251 pid_t pid; |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
252 logwrite(LOG_NOTICE, "%s <= %s with %s\n", msg->uid, addr_string(msg->return_path), prot_names[PROT_LOCAL]); |
0 | 253 |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
254 if (!conf.do_queue) { |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
255 if ((pid = fork()) == 0) { |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
256 conf.do_verbose = FALSE; |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
257 fclose(stdin); |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
258 fclose(stdout); |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
259 fclose(stderr); |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
260 if (deliver(msg)) { |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
261 exit(EXIT_SUCCESS); |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
262 } else |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
263 exit(EXIT_FAILURE); |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
264 } 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
|
265 logwrite(LOG_ALERT, "could not fork for delivery, id = %s\n", msg->uid); |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
266 } |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
267 } |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
268 } else { |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
269 fprintf(stderr, "Could not write spool file\n"); |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
270 exit(EXIT_FAILURE); |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
271 } |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
272 } else { |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
273 switch (err) { |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
274 case AERR_EOF: |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
275 fprintf(stderr, "unexpected EOF.\n"); |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
276 exit(EXIT_FAILURE); |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
277 case AERR_NORCPT: |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
278 fprintf(stderr, "no recipients.\n"); |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
279 exit(EXIT_FAILURE); |
117
5ec5e6637049
added server-side SMTP SIZE support (patch by Paolo)
meillo@marmaro.de
parents:
110
diff
changeset
|
280 case AERR_SIZE: |
5ec5e6637049
added server-side SMTP SIZE support (patch by Paolo)
meillo@marmaro.de
parents:
110
diff
changeset
|
281 fprintf(stderr, "max message size exceeded.\n"); |
5ec5e6637049
added server-side SMTP SIZE support (patch by Paolo)
meillo@marmaro.de
parents:
110
diff
changeset
|
282 exit(EXIT_FAILURE); |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
283 default: |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
284 /* should never happen: */ |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
285 fprintf(stderr, "Unknown error (%d)\r\n", err); |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
286 exit(EXIT_FAILURE); |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
287 } |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
288 exit(EXIT_FAILURE); |
0 | 289 } |
290 } | |
291 | |
250
a41c013c8458
moved the queue manipulation code to an new function
markus schnalke <meillo@marmaro.de>
parents:
249
diff
changeset
|
292 /* |
a41c013c8458
moved the queue manipulation code to an new function
markus schnalke <meillo@marmaro.de>
parents:
249
diff
changeset
|
293 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
|
294 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
|
295 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
|
296 */ |
a41c013c8458
moved the queue manipulation code to an new function
markus schnalke <meillo@marmaro.de>
parents:
249
diff
changeset
|
297 static int |
a41c013c8458
moved the queue manipulation code to an new function
markus schnalke <meillo@marmaro.de>
parents:
249
diff
changeset
|
298 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
|
299 { |
a41c013c8458
moved the queue manipulation code to an new function
markus schnalke <meillo@marmaro.de>
parents:
249
diff
changeset
|
300 gboolean ok = FALSE; |
a41c013c8458
moved the queue manipulation code to an new function
markus schnalke <meillo@marmaro.de>
parents:
249
diff
changeset
|
301 |
a41c013c8458
moved the queue manipulation code to an new function
markus schnalke <meillo@marmaro.de>
parents:
249
diff
changeset
|
302 if (strcmp(cmd, "rm") != 0) { |
a41c013c8458
moved the queue manipulation code to an new function
markus schnalke <meillo@marmaro.de>
parents:
249
diff
changeset
|
303 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
|
304 return FALSE; |
a41c013c8458
moved the queue manipulation code to an new function
markus schnalke <meillo@marmaro.de>
parents:
249
diff
changeset
|
305 } |
a41c013c8458
moved the queue manipulation code to an new function
markus schnalke <meillo@marmaro.de>
parents:
249
diff
changeset
|
306 |
a41c013c8458
moved the queue manipulation code to an new function
markus schnalke <meillo@marmaro.de>
parents:
249
diff
changeset
|
307 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
|
308 |
a41c013c8458
moved the queue manipulation code to an new function
markus schnalke <meillo@marmaro.de>
parents:
249
diff
changeset
|
309 /* 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
|
310 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
|
311 for (; *id; id++) { |
a41c013c8458
moved the queue manipulation code to an new function
markus schnalke <meillo@marmaro.de>
parents:
249
diff
changeset
|
312 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
|
313 if (queue_delete(*id)) { |
a41c013c8458
moved the queue manipulation code to an new function
markus schnalke <meillo@marmaro.de>
parents:
249
diff
changeset
|
314 ok = TRUE; |
a41c013c8458
moved the queue manipulation code to an new function
markus schnalke <meillo@marmaro.de>
parents:
249
diff
changeset
|
315 } |
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 return ok; |
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 |
a41c013c8458
moved the queue manipulation code to an new function
markus schnalke <meillo@marmaro.de>
parents:
249
diff
changeset
|
320 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
|
321 if (!pw) { |
a41c013c8458
moved the queue manipulation code to an new function
markus schnalke <meillo@marmaro.de>
parents:
249
diff
changeset
|
322 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
|
323 conf.orig_uid, strerror(errno)); |
a41c013c8458
moved the queue manipulation code to an new function
markus schnalke <meillo@marmaro.de>
parents:
249
diff
changeset
|
324 return FALSE; |
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 |
a41c013c8458
moved the queue manipulation code to an new function
markus schnalke <meillo@marmaro.de>
parents:
249
diff
changeset
|
327 /* 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
|
328 for (; *id; id++) { |
a41c013c8458
moved the queue manipulation code to an new function
markus schnalke <meillo@marmaro.de>
parents:
249
diff
changeset
|
329 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
|
330 |
a41c013c8458
moved the queue manipulation code to an new function
markus schnalke <meillo@marmaro.de>
parents:
249
diff
changeset
|
331 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
|
332 |
a41c013c8458
moved the queue manipulation code to an new function
markus schnalke <meillo@marmaro.de>
parents:
249
diff
changeset
|
333 if (!msg->ident) { |
a41c013c8458
moved the queue manipulation code to an new function
markus schnalke <meillo@marmaro.de>
parents:
249
diff
changeset
|
334 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
|
335 continue; |
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 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
|
338 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
|
339 continue; |
a41c013c8458
moved the queue manipulation code to an new function
markus schnalke <meillo@marmaro.de>
parents:
249
diff
changeset
|
340 } |
a41c013c8458
moved the queue manipulation code to an new function
markus schnalke <meillo@marmaro.de>
parents:
249
diff
changeset
|
341 |
a41c013c8458
moved the queue manipulation code to an new function
markus schnalke <meillo@marmaro.de>
parents:
249
diff
changeset
|
342 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
|
343 #ifdef ENABLE_IDENT |
a41c013c8458
moved the queue manipulation code to an new function
markus schnalke <meillo@marmaro.de>
parents:
249
diff
changeset
|
344 && !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
|
345 #endif |
a41c013c8458
moved the queue manipulation code to an new function
markus schnalke <meillo@marmaro.de>
parents:
249
diff
changeset
|
346 ) { |
a41c013c8458
moved the queue manipulation code to an new function
markus schnalke <meillo@marmaro.de>
parents:
249
diff
changeset
|
347 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
|
348 continue; |
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 |
a41c013c8458
moved the queue manipulation code to an new function
markus schnalke <meillo@marmaro.de>
parents:
249
diff
changeset
|
351 ok = queue_delete(*id); |
a41c013c8458
moved the queue manipulation code to an new function
markus schnalke <meillo@marmaro.de>
parents:
249
diff
changeset
|
352 } |
a41c013c8458
moved the queue manipulation code to an new function
markus schnalke <meillo@marmaro.de>
parents:
249
diff
changeset
|
353 return ok; |
a41c013c8458
moved the queue manipulation code to an new function
markus schnalke <meillo@marmaro.de>
parents:
249
diff
changeset
|
354 } |
a41c013c8458
moved the queue manipulation code to an new function
markus schnalke <meillo@marmaro.de>
parents:
249
diff
changeset
|
355 |
251
2babd21e7c75
moved run_queue to a new function
markus schnalke <meillo@marmaro.de>
parents:
250
diff
changeset
|
356 static int |
2babd21e7c75
moved run_queue to a new function
markus schnalke <meillo@marmaro.de>
parents:
250
diff
changeset
|
357 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
|
358 { |
2babd21e7c75
moved run_queue to a new function
markus schnalke <meillo@marmaro.de>
parents:
250
diff
changeset
|
359 int ret; |
2babd21e7c75
moved run_queue to a new function
markus schnalke <meillo@marmaro.de>
parents:
250
diff
changeset
|
360 |
2babd21e7c75
moved run_queue to a new function
markus schnalke <meillo@marmaro.de>
parents:
250
diff
changeset
|
361 /* queue runs */ |
2babd21e7c75
moved run_queue to a new function
markus schnalke <meillo@marmaro.de>
parents:
250
diff
changeset
|
362 set_identity(conf.orig_uid, "queue run"); |
2babd21e7c75
moved run_queue to a new function
markus schnalke <meillo@marmaro.de>
parents:
250
diff
changeset
|
363 |
2babd21e7c75
moved run_queue to a new function
markus schnalke <meillo@marmaro.de>
parents:
250
diff
changeset
|
364 if (do_runq) { |
2babd21e7c75
moved run_queue to a new function
markus schnalke <meillo@marmaro.de>
parents:
250
diff
changeset
|
365 ret = queue_run(); |
2babd21e7c75
moved run_queue to a new function
markus schnalke <meillo@marmaro.de>
parents:
250
diff
changeset
|
366 } |
2babd21e7c75
moved run_queue to a new function
markus schnalke <meillo@marmaro.de>
parents:
250
diff
changeset
|
367 |
2babd21e7c75
moved run_queue to a new function
markus schnalke <meillo@marmaro.de>
parents:
250
diff
changeset
|
368 if (do_runq_online) { |
2babd21e7c75
moved run_queue to a new function
markus schnalke <meillo@marmaro.de>
parents:
250
diff
changeset
|
369 if (route_name) { |
2babd21e7c75
moved run_queue to a new function
markus schnalke <meillo@marmaro.de>
parents:
250
diff
changeset
|
370 conf.online_detect = g_strdup("argument"); |
2babd21e7c75
moved run_queue to a new function
markus schnalke <meillo@marmaro.de>
parents:
250
diff
changeset
|
371 set_online_name(route_name); |
2babd21e7c75
moved run_queue to a new function
markus schnalke <meillo@marmaro.de>
parents:
250
diff
changeset
|
372 } |
2babd21e7c75
moved run_queue to a new function
markus schnalke <meillo@marmaro.de>
parents:
250
diff
changeset
|
373 ret = queue_run_online(); |
2babd21e7c75
moved run_queue to a new function
markus schnalke <meillo@marmaro.de>
parents:
250
diff
changeset
|
374 } |
2babd21e7c75
moved run_queue to a new function
markus schnalke <meillo@marmaro.de>
parents:
250
diff
changeset
|
375 return ret; |
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 |
0 | 378 int |
379 main(int argc, char *argv[]) | |
380 { | |
251
2babd21e7c75
moved run_queue to a new function
markus schnalke <meillo@marmaro.de>
parents:
250
diff
changeset
|
381 gchar *progname; |
249
f9da5a7caeda
refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents:
248
diff
changeset
|
382 char* opt; |
f9da5a7caeda
refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents:
248
diff
changeset
|
383 gint arg; |
0 | 384 |
251
2babd21e7c75
moved run_queue to a new function
markus schnalke <meillo@marmaro.de>
parents:
250
diff
changeset
|
385 mta_mode mta_mode = MODE_ACCEPT; |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
386 gboolean do_listen = FALSE; |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
387 gboolean do_runq = FALSE; |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
388 gboolean do_runq_online = FALSE; |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
389 gboolean do_queue = FALSE; |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
390 gint queue_interval = 0; |
251
2babd21e7c75
moved run_queue to a new function
markus schnalke <meillo@marmaro.de>
parents:
250
diff
changeset
|
391 gchar *M_cmd = NULL; |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
392 gboolean opt_t = FALSE; |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
393 gboolean opt_i = FALSE; |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
394 gboolean exit_failure = FALSE; |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
395 gint exit_code = EXIT_SUCCESS; |
251
2babd21e7c75
moved run_queue to a new function
markus schnalke <meillo@marmaro.de>
parents:
250
diff
changeset
|
396 gchar *conf_file = CONF_FILE; |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
397 gchar *route_name = NULL; |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
398 gchar *f_address = NULL; |
251
2babd21e7c75
moved run_queue to a new function
markus schnalke <meillo@marmaro.de>
parents:
250
diff
changeset
|
399 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
|
400 gchar *full_sender_name = NULL; |
251
2babd21e7c75
moved run_queue to a new function
markus schnalke <meillo@marmaro.de>
parents:
250
diff
changeset
|
401 gboolean do_verbose = FALSE; |
2babd21e7c75
moved run_queue to a new function
markus schnalke <meillo@marmaro.de>
parents:
250
diff
changeset
|
402 gint debug_level = -1; |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
403 |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
404 progname = get_progname(argv[0]); |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
405 |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
406 if (strcmp(progname, "mailq") == 0) { |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
407 mta_mode = MODE_LIST; |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
408 } else if (strcmp(progname, "mailrm") == 0) { |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
409 mta_mode = MODE_MCMD; |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
410 M_cmd = "rm"; |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
411 } else if (strcmp(progname, "runq") == 0) { |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
412 mta_mode = MODE_RUNQUEUE; |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
413 do_runq = TRUE; |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
414 } else if (strcmp(progname, "rmail") == 0) { |
89 | 415 /* the `rmail' alias should probably be removed now |
416 that we have the rmail script. But let's keep it | |
417 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
|
418 mta_mode = MODE_ACCEPT; |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
419 opt_i = TRUE; |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
420 } else if (strcmp(progname, "smtpd") == 0 || strcmp(progname, "in.smtpd") == 0) { |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
421 mta_mode = MODE_SMTP; |
0 | 422 } |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
423 |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
424 /* parse cmd line */ |
249
f9da5a7caeda
refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents:
248
diff
changeset
|
425 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
|
426 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
|
427 |
f9da5a7caeda
refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents:
248
diff
changeset
|
428 if (strcmp(opt, "-") == 0) { |
f9da5a7caeda
refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents:
248
diff
changeset
|
429 /* everything after `--' are address arguments */ |
f9da5a7caeda
refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents:
248
diff
changeset
|
430 arg++; |
f9da5a7caeda
refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents:
248
diff
changeset
|
431 break; |
f9da5a7caeda
refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents:
248
diff
changeset
|
432 |
f9da5a7caeda
refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents:
248
diff
changeset
|
433 } else if (strcmp(opt, "bd") == 0) { |
f9da5a7caeda
refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents:
248
diff
changeset
|
434 do_listen = TRUE; |
f9da5a7caeda
refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents:
248
diff
changeset
|
435 mta_mode = MODE_DAEMON; |
f9da5a7caeda
refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents:
248
diff
changeset
|
436 |
f9da5a7caeda
refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents:
248
diff
changeset
|
437 } else if (strcmp(opt, "bi") == 0) { |
f9da5a7caeda
refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents:
248
diff
changeset
|
438 /* ignored */ |
f9da5a7caeda
refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents:
248
diff
changeset
|
439 mta_mode = MODE_BI; |
f9da5a7caeda
refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents:
248
diff
changeset
|
440 |
f9da5a7caeda
refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents:
248
diff
changeset
|
441 } else if (strcmp(opt, "bs") == 0) { |
f9da5a7caeda
refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents:
248
diff
changeset
|
442 mta_mode = MODE_SMTP; |
f9da5a7caeda
refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents:
248
diff
changeset
|
443 |
f9da5a7caeda
refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents:
248
diff
changeset
|
444 } else if (strcmp(opt, "bp") == 0) { |
f9da5a7caeda
refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents:
248
diff
changeset
|
445 mta_mode = MODE_LIST; |
f9da5a7caeda
refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents:
248
diff
changeset
|
446 |
f9da5a7caeda
refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents:
248
diff
changeset
|
447 } else if (strcmp(opt, "bV") == 0) { |
f9da5a7caeda
refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents:
248
diff
changeset
|
448 mta_mode = MODE_VERSION; |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
449 |
249
f9da5a7caeda
refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents:
248
diff
changeset
|
450 } else if (strncmp(opt, "B", 1) == 0) { |
f9da5a7caeda
refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents:
248
diff
changeset
|
451 /* we ignore this and throw the argument away */ |
f9da5a7caeda
refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents:
248
diff
changeset
|
452 get_optarg(argv, &arg, opt+1); |
f9da5a7caeda
refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents:
248
diff
changeset
|
453 |
f9da5a7caeda
refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents:
248
diff
changeset
|
454 } 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
|
455 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
|
456 if (!conf_file) { |
249
f9da5a7caeda
refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents:
248
diff
changeset
|
457 fprintf(stderr, "-C requires a filename as argument.\n"); |
f9da5a7caeda
refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents:
248
diff
changeset
|
458 exit(EXIT_FAILURE); |
f9da5a7caeda
refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents:
248
diff
changeset
|
459 } |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
460 |
249
f9da5a7caeda
refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents:
248
diff
changeset
|
461 } else if (strncmp(opt, "d", 1) == 0) { |
f9da5a7caeda
refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents:
248
diff
changeset
|
462 if (getuid() != 0) { |
f9da5a7caeda
refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents:
248
diff
changeset
|
463 fprintf(stderr, "only root may set the debug level.\n"); |
f9da5a7caeda
refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents:
248
diff
changeset
|
464 exit(EXIT_FAILURE); |
f9da5a7caeda
refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents:
248
diff
changeset
|
465 } |
f9da5a7caeda
refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents:
248
diff
changeset
|
466 char *lvl = get_optarg(argv, &arg, opt+1); |
f9da5a7caeda
refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents:
248
diff
changeset
|
467 if (!lvl) { |
f9da5a7caeda
refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents:
248
diff
changeset
|
468 fprintf(stderr, "-d requires a number argument.\n"); |
f9da5a7caeda
refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents:
248
diff
changeset
|
469 exit(EXIT_FAILURE); |
f9da5a7caeda
refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents:
248
diff
changeset
|
470 } |
f9da5a7caeda
refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents:
248
diff
changeset
|
471 debug_level = atoi(lvl); |
f9da5a7caeda
refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents:
248
diff
changeset
|
472 |
f9da5a7caeda
refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents:
248
diff
changeset
|
473 } else if (strncmp(opt, "f", 1) == 0) { |
f9da5a7caeda
refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents:
248
diff
changeset
|
474 /* set return path */ |
f9da5a7caeda
refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents:
248
diff
changeset
|
475 gchar *address = get_optarg(argv, &arg, opt+1); |
f9da5a7caeda
refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents:
248
diff
changeset
|
476 if (!address) { |
f9da5a7caeda
refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents:
248
diff
changeset
|
477 fprintf(stderr, "-f requires an address argument\n"); |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
478 exit(EXIT_FAILURE); |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
479 } |
249
f9da5a7caeda
refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents:
248
diff
changeset
|
480 f_address = g_strdup(address); |
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 } else if (strncmp(opt, "F", 1) == 0) { |
f9da5a7caeda
refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents:
248
diff
changeset
|
483 full_sender_name = get_optarg(argv, &arg, opt+1); |
f9da5a7caeda
refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents:
248
diff
changeset
|
484 if (!full_sender_name) { |
f9da5a7caeda
refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents:
248
diff
changeset
|
485 fprintf(stderr, "-F requires a name argument\n"); |
f9da5a7caeda
refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents:
248
diff
changeset
|
486 exit(EXIT_FAILURE); |
f9da5a7caeda
refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents:
248
diff
changeset
|
487 } |
f9da5a7caeda
refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents:
248
diff
changeset
|
488 |
f9da5a7caeda
refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents:
248
diff
changeset
|
489 } else if (strcmp(opt, "i") == 0) { |
f9da5a7caeda
refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents:
248
diff
changeset
|
490 opt_i = TRUE; |
f9da5a7caeda
refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents:
248
diff
changeset
|
491 exit_failure = FALSE; /* may override -oem */ |
f9da5a7caeda
refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents:
248
diff
changeset
|
492 |
f9da5a7caeda
refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents:
248
diff
changeset
|
493 } else if (strcmp(opt, "m") == 0) { |
f9da5a7caeda
refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents:
248
diff
changeset
|
494 /* ignore -m (me too) switch (see man page) */ |
f9da5a7caeda
refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents:
248
diff
changeset
|
495 |
f9da5a7caeda
refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents:
248
diff
changeset
|
496 } else if (strcmp(opt, "Mrm") == 0) { |
f9da5a7caeda
refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents:
248
diff
changeset
|
497 mta_mode = MODE_MCMD; |
f9da5a7caeda
refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents:
248
diff
changeset
|
498 M_cmd = "rm"; |
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, "odq") == 0) { |
f9da5a7caeda
refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents:
248
diff
changeset
|
501 do_queue = TRUE; |
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, "oem") == 0) { |
f9da5a7caeda
refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents:
248
diff
changeset
|
504 if (!opt_i) { |
f9da5a7caeda
refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents:
248
diff
changeset
|
505 /* TODO: Why is this related to -i in any way? */ |
f9da5a7caeda
refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents:
248
diff
changeset
|
506 exit_failure = TRUE; |
f9da5a7caeda
refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents:
248
diff
changeset
|
507 } |
f9da5a7caeda
refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents:
248
diff
changeset
|
508 |
f9da5a7caeda
refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents:
248
diff
changeset
|
509 } else if (strcmp(opt, "oi") == 0) { |
f9da5a7caeda
refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents:
248
diff
changeset
|
510 exit_failure = FALSE; /* may override -oem */ |
f9da5a7caeda
refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents:
248
diff
changeset
|
511 |
f9da5a7caeda
refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents:
248
diff
changeset
|
512 } else if (strncmp(opt, "o", 1) == 0) { |
f9da5a7caeda
refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents:
248
diff
changeset
|
513 /* ignore all other -oXXX options */ |
f9da5a7caeda
refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents:
248
diff
changeset
|
514 |
f9da5a7caeda
refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents:
248
diff
changeset
|
515 } else if (strncmp(opt, "qo", 2) == 0) { |
f9da5a7caeda
refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents:
248
diff
changeset
|
516 mta_mode = MODE_RUNQUEUE; |
f9da5a7caeda
refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents:
248
diff
changeset
|
517 do_runq = FALSE; |
f9da5a7caeda
refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents:
248
diff
changeset
|
518 do_runq_online = TRUE; |
f9da5a7caeda
refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents:
248
diff
changeset
|
519 /* can be NULL, then we use online detection method */ |
f9da5a7caeda
refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents:
248
diff
changeset
|
520 route_name = get_optarg(argv, &arg, opt+2); |
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 } else if (strncmp(opt, "q", 1) == 0) { |
f9da5a7caeda
refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents:
248
diff
changeset
|
523 /* must be after the `qo' check */ |
f9da5a7caeda
refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents:
248
diff
changeset
|
524 gchar *optarg; |
f9da5a7caeda
refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents:
248
diff
changeset
|
525 |
f9da5a7caeda
refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents:
248
diff
changeset
|
526 do_runq = TRUE; |
f9da5a7caeda
refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents:
248
diff
changeset
|
527 mta_mode = MODE_RUNQUEUE; |
251
2babd21e7c75
moved run_queue to a new function
markus schnalke <meillo@marmaro.de>
parents:
250
diff
changeset
|
528 optarg = get_optarg(argv, &arg, opt+1); |
2babd21e7c75
moved run_queue to a new function
markus schnalke <meillo@marmaro.de>
parents:
250
diff
changeset
|
529 if (optarg) { |
2babd21e7c75
moved run_queue to a new function
markus schnalke <meillo@marmaro.de>
parents:
250
diff
changeset
|
530 /* not just one single queue run but regular runs */ |
249
f9da5a7caeda
refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents:
248
diff
changeset
|
531 mta_mode = MODE_DAEMON; |
254
82d168dd52fd
removed the obsolete pos argument from time_interval()
markus schnalke <meillo@marmaro.de>
parents:
251
diff
changeset
|
532 queue_interval = time_interval(optarg); |
249
f9da5a7caeda
refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents:
248
diff
changeset
|
533 } |
f9da5a7caeda
refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents:
248
diff
changeset
|
534 |
f9da5a7caeda
refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents:
248
diff
changeset
|
535 } else if (strcmp(opt, "t") == 0) { |
f9da5a7caeda
refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents:
248
diff
changeset
|
536 opt_t = TRUE; |
f9da5a7caeda
refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents:
248
diff
changeset
|
537 |
f9da5a7caeda
refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents:
248
diff
changeset
|
538 } else if (strcmp(opt, "v") == 0) { |
f9da5a7caeda
refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents:
248
diff
changeset
|
539 do_verbose = TRUE; |
f9da5a7caeda
refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents:
248
diff
changeset
|
540 |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
541 } else { |
249
f9da5a7caeda
refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents:
248
diff
changeset
|
542 fprintf(stderr, "unrecognized option `-%s'\n", opt); |
f9da5a7caeda
refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents:
248
diff
changeset
|
543 exit(EXIT_FAILURE); |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
544 } |
0 | 545 } |
546 | |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
547 if (mta_mode == MODE_VERSION) { |
12 | 548 gchar *with_resolver = ""; |
549 gchar *with_auth = ""; | |
550 gchar *with_ident = ""; | |
0 | 551 |
552 #ifdef ENABLE_RESOLVER | |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
553 with_resolver = " +resolver"; |
0 | 554 #endif |
555 #ifdef ENABLE_AUTH | |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
556 with_auth = " +auth"; |
0 | 557 #endif |
558 #ifdef ENABLE_IDENT | |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
559 with_ident = " +ident"; |
0 | 560 #endif |
561 | |
205 | 562 printf("%s %s%s%s%s\n", PACKAGE, VERSION, with_resolver, with_auth, with_ident); |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
563 |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
564 exit(EXIT_SUCCESS); |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
565 } |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
566 |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
567 /* initialize random generator */ |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
568 srand(time(NULL)); |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
569 /* ignore SIGPIPE signal */ |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
570 signal(SIGPIPE, SIG_IGN); |
0 | 571 |
73 | 572 /* 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
|
573 { |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
574 int i, max_fd = sysconf(_SC_OPEN_MAX); |
0 | 575 |
251
2babd21e7c75
moved run_queue to a new function
markus schnalke <meillo@marmaro.de>
parents:
250
diff
changeset
|
576 if (max_fd <= 0) { |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
577 max_fd = 64; |
251
2babd21e7c75
moved run_queue to a new function
markus schnalke <meillo@marmaro.de>
parents:
250
diff
changeset
|
578 } |
2babd21e7c75
moved run_queue to a new function
markus schnalke <meillo@marmaro.de>
parents:
250
diff
changeset
|
579 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
|
580 close(i); |
251
2babd21e7c75
moved run_queue to a new function
markus schnalke <meillo@marmaro.de>
parents:
250
diff
changeset
|
581 } |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
582 } |
0 | 583 |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
584 init_conf(); |
0 | 585 |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
586 /* 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
|
587 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
|
588 privileges. |
0 | 589 |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
590 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
|
591 breaking security. |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
592 */ |
251
2babd21e7c75
moved run_queue to a new function
markus schnalke <meillo@marmaro.de>
parents:
250
diff
changeset
|
593 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
|
594 conf.run_as_user = TRUE; |
2babd21e7c75
moved run_queue to a new function
markus schnalke <meillo@marmaro.de>
parents:
250
diff
changeset
|
595 seteuid(conf.orig_uid); |
2babd21e7c75
moved run_queue to a new function
markus schnalke <meillo@marmaro.de>
parents:
250
diff
changeset
|
596 setegid(conf.orig_gid); |
2babd21e7c75
moved run_queue to a new function
markus schnalke <meillo@marmaro.de>
parents:
250
diff
changeset
|
597 setuid(conf.orig_uid); |
2babd21e7c75
moved run_queue to a new function
markus schnalke <meillo@marmaro.de>
parents:
250
diff
changeset
|
598 setgid(conf.orig_gid); |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
599 } |
0 | 600 |
155 | 601 conf.log_dir = LOG_DIR; |
602 logopen(); | |
603 if (!read_conf(conf_file)) { | |
604 logwrite(LOG_ALERT, "SHUTTING DOWN due to problems reading config\n"); | |
605 exit(5); | |
606 } | |
607 logclose(); | |
0 | 608 |
251
2babd21e7c75
moved run_queue to a new function
markus schnalke <meillo@marmaro.de>
parents:
250
diff
changeset
|
609 if (do_queue) { |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
610 conf.do_queue = TRUE; |
251
2babd21e7c75
moved run_queue to a new function
markus schnalke <meillo@marmaro.de>
parents:
250
diff
changeset
|
611 } |
2babd21e7c75
moved run_queue to a new function
markus schnalke <meillo@marmaro.de>
parents:
250
diff
changeset
|
612 if (do_verbose) { |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
613 conf.do_verbose = TRUE; |
251
2babd21e7c75
moved run_queue to a new function
markus schnalke <meillo@marmaro.de>
parents:
250
diff
changeset
|
614 } |
2babd21e7c75
moved run_queue to a new function
markus schnalke <meillo@marmaro.de>
parents:
250
diff
changeset
|
615 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
|
616 conf.debug_level = debug_level; |
251
2babd21e7c75
moved run_queue to a new function
markus schnalke <meillo@marmaro.de>
parents:
250
diff
changeset
|
617 } |
0 | 618 |
46 | 619 /* It appears that changing to / ensures that we are never in |
620 a directory which we cannot access. This situation could be | |
621 possible after changing identity. | |
622 Maybe we should only change to / if we not run as user, to | |
623 allow relative paths for log files in test setups for | |
624 instance. | |
625 */ | |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
626 chdir("/"); |
0 | 627 |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
628 if (!conf.run_as_user) { |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
629 if (setgid(0) != 0) { |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
630 fprintf(stderr, "could not set gid to 0. Is the setuid bit set? : %s\n", strerror(errno)); |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
631 exit(EXIT_FAILURE); |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
632 } |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
633 if (setuid(0) != 0) { |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
634 fprintf(stderr, "could not gain root privileges. Is the setuid bit set? : %s\n", strerror(errno)); |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
635 exit(EXIT_FAILURE); |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
636 } |
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 if (!logopen()) { |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
640 fprintf(stderr, "could not open log file\n"); |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
641 exit(EXIT_FAILURE); |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
642 } |
0 | 643 |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
644 DEBUG(1) debugf("masqmail %s starting\n", VERSION); |
0 | 645 |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
646 DEBUG(5) { |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
647 gchar **str = argv; |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
648 debugf("args: \n"); |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
649 while (*str) { |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
650 debugf("%s \n", *str); |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
651 str++; |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
652 } |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
653 } |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
654 DEBUG(5) debugf("queue_interval = %d\n", queue_interval); |
0 | 655 |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
656 if (f_address) { |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
657 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
|
658 g_free(f_address); |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
659 if (!return_path) { |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
660 fprintf(stderr, "invalid RFC821 address: %s\n", f_address); |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
661 exit(EXIT_FAILURE); |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
662 } |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
663 } |
0 | 664 |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
665 switch (mta_mode) { |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
666 case MODE_DAEMON: |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
667 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
|
668 break; |
251
2babd21e7c75
moved run_queue to a new function
markus schnalke <meillo@marmaro.de>
parents:
250
diff
changeset
|
669 |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
670 case MODE_RUNQUEUE: |
251
2babd21e7c75
moved run_queue to a new function
markus schnalke <meillo@marmaro.de>
parents:
250
diff
changeset
|
671 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
|
672 break; |
0 | 673 |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
674 case MODE_SMTP: |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
675 mode_smtp(); |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
676 break; |
0 | 677 |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
678 case MODE_LIST: |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
679 queue_list(); |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
680 break; |
0 | 681 |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
682 case MODE_BI: |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
683 exit(EXIT_SUCCESS); |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
684 break; /* well... */ |
0 | 685 |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
686 case MODE_MCMD: |
250
a41c013c8458
moved the queue manipulation code to an new function
markus schnalke <meillo@marmaro.de>
parents:
249
diff
changeset
|
687 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
|
688 break; |
0 | 689 |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
690 case MODE_ACCEPT: |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
691 { |
107 | 692 guint accept_flags = (opt_t ? ACC_DEL_RCPTS | 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
|
693 | (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
|
694 mode_accept(return_path, full_sender_name, accept_flags, &(argv[arg]), argc - arg); |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
695 exit(exit_failure ? EXIT_FAILURE : EXIT_SUCCESS); |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
696 } |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
697 break; |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
698 case MODE_NONE: |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
699 break; |
251
2babd21e7c75
moved run_queue to a new function
markus schnalke <meillo@marmaro.de>
parents:
250
diff
changeset
|
700 |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
701 default: |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
702 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
|
703 break; |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
704 } |
0 | 705 |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
706 logclose(); |
0 | 707 |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
708 exit(exit_code); |
0 | 709 } |