annotate src/masqmail.c @ 265:409552c5647f

removed obsolete commented code
author markus schnalke <meillo@marmaro.de>
date Fri, 03 Dec 2010 11:30:01 -0300
parents 1e5e457dea18
children ab39047ffe44
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
1 /* MasqMail
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
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
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
4
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
5 This program is free software; you can redistribute it and/or modify
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
6 it under the terms of the GNU General Public License as published by
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
7 the Free Software Foundation; either version 2 of the License, or
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
8 (at your option) any later version.
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
9
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
10 This program is distributed in the hope that it will be useful,
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
13 GNU General Public License for more details.
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
14
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
15 You should have received a copy of the GNU General Public License
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
16 along with this program; if not, write to the Free Software
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
18 */
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
19
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
20 #include <stdio.h>
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
21 #include <errno.h>
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
22 #include <stdlib.h>
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
23 #include <string.h>
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
24 #include <unistd.h>
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
25 #include <sys/types.h>
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
26 #include <sys/socket.h>
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
27 #include <sys/time.h>
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
28 #include <netinet/in.h>
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
29 #include <netdb.h>
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
30 #include <syslog.h>
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
31 #include <signal.h>
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
32
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
33 #include <glib.h>
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
34
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
35 #include "masqmail.h"
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
36
192
89f951be358f REMOVED POP3 SUPPORT
meillo@marmaro.de
parents: 168
diff changeset
37 /* mutually exclusive modes. Note that there is no 'queue daemon' mode.
89f951be358f REMOVED POP3 SUPPORT
meillo@marmaro.de
parents: 168
diff changeset
38 It, as well as the distinction beween the two (non exclusive) daemon
89f951be358f REMOVED POP3 SUPPORT
meillo@marmaro.de
parents: 168
diff changeset
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 {
259
f4117fd5a163 made default mode sensible
markus schnalke <meillo@marmaro.de>
parents: 258
diff changeset
41 MODE_NONE = 0, /* for being able to check if a mode was defined */
f4117fd5a163 made default mode sensible
markus schnalke <meillo@marmaro.de>
parents: 258
diff changeset
42 MODE_ACCEPT, /* accept message on stdin */
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 ;-) */
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
50 } mta_mode;
0
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
51
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
52 char *pidfile = NULL;
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
53 volatile int sigterm_in_progress = 0;
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
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
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
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
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
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
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
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
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
72 }
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
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
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
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
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
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
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
91 }
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
92 #endif
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
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
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
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
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
116
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
117 gboolean
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
118 write_pidfile(gchar * name)
0
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
119 {
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
120 FILE *fptr;
0
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
121
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
122 if ((fptr = fopen(name, "wt"))) {
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
123 fprintf(fptr, "%d\n", getpid());
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
124 fclose(fptr);
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
125 pidfile = strdup(name);
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
126 return TRUE;
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
127 }
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
128 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
129 return FALSE;
0
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
130 }
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
131
264
1e5e457dea18 comments and a small refactoring
markus schnalke <meillo@marmaro.de>
parents: 263
diff changeset
132 /* 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
133 static void
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
134 mode_daemon(gboolean do_listen, gint queue_interval, char *argv[])
0
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
135 {
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
136 guint pid;
0
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
137
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
138 /* daemon */
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
139 if (!conf.run_as_user) {
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
140 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
141 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
142 exit(1);
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
143 }
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
144 }
0
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
145
74
0a5b2e96ade3 do not reparent the daemon to init if init is already the parent
meillo@marmaro.de
parents: 73
diff changeset
146 /* 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
147 if (getppid() != 1) {
0a5b2e96ade3 do not reparent the daemon to init if init is already the parent
meillo@marmaro.de
parents: 73
diff changeset
148 if ((pid = fork()) > 0) {
262
fc1c6425c024 s/EXIT_SUCCESS/0/ && s/EXIT_FAILURE/1/
markus schnalke <meillo@marmaro.de>
parents: 261
diff changeset
149 exit(0);
74
0a5b2e96ade3 do not reparent the daemon to init if init is already the parent
meillo@marmaro.de
parents: 73
diff changeset
150 } 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
151 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
152 exit(1);
74
0a5b2e96ade3 do not reparent the daemon to init if init is already the parent
meillo@marmaro.de
parents: 73
diff changeset
153 }
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
154 }
0
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
155
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
156 signal(SIGTERM, sigterm_handler);
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
157 write_pidfile(PIDFILEDIR "/masqmail.pid");
0
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
158
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
159 conf.do_verbose = FALSE;
0
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
160
72
ad034b57f3b2 fixed Debian bug 536060 (log files are closed after SIGHUP receival)
meillo@marmaro.de
parents: 46
diff changeset
161 /* 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
162 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
163 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
164 */
ad034b57f3b2 fixed Debian bug 536060 (log files are closed after SIGHUP receival)
meillo@marmaro.de
parents: 46
diff changeset
165 logclose();
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
166 fclose(stdin);
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
167 fclose(stdout);
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
168 fclose(stderr);
72
ad034b57f3b2 fixed Debian bug 536060 (log files are closed after SIGHUP receival)
meillo@marmaro.de
parents: 46
diff changeset
169 logopen();
0
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
170
208
3708b655a371 added newlines to the end of log and debug messages where missing
meillo@marmaro.de
parents: 205
diff changeset
171 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
172 listen_port(do_listen ? conf.listen_addresses : NULL, queue_interval, argv);
0
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
173 }
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
174
264
1e5e457dea18 comments and a small refactoring
markus schnalke <meillo@marmaro.de>
parents: 263
diff changeset
175 /* -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
176 static void
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
177 mode_smtp()
0
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
178 {
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
179 /* accept smtp message on stdin */
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
180 /* write responses to stderr. */
0
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
181
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
182 struct sockaddr_in saddr;
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
183 gchar *peername = NULL;
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
184 int dummy = sizeof(saddr);
0
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
185
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
186 conf.do_verbose = FALSE;
0
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
187
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
188 if (!conf.run_as_user) {
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
189 seteuid(conf.orig_uid);
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
190 setegid(conf.orig_gid);
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
191 }
0
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
192
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
193 DEBUG(5) debugf("accepting smtp message on stdin\n");
0
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
194
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
195 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
196 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
197 } else if (errno != ENOTSOCK)
262
fc1c6425c024 s/EXIT_SUCCESS/0/ && s/EXIT_FAILURE/1/
markus schnalke <meillo@marmaro.de>
parents: 261
diff changeset
198 exit(1);
0
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
199
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
200 smtp_in(stdin, stderr, peername, NULL);
0
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
201 }
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
202
264
1e5e457dea18 comments and a small refactoring
markus schnalke <meillo@marmaro.de>
parents: 263
diff changeset
203 /* 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
204 static void
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
205 mode_accept(address * return_path, gchar * full_sender_name, guint accept_flags, char **addresses, int addr_cnt)
0
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
206 {
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
207 /* accept message on stdin */
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
208 accept_error err;
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
209 message *msg = create_message();
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
210 gint i;
0
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
211
83
085d6cd44462 using is_privileged_user() to check here too
meillo@marmaro.de
parents: 76
diff changeset
212 if (return_path && !is_privileged_user(conf.orig_uid)) {
96
b76080154aec small typo fix
meillo@marmaro.de
parents: 89
diff changeset
213 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
214 exit(1);
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
215 }
0
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
216
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
217 if (!conf.run_as_user) {
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
218 seteuid(conf.orig_uid);
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
219 setegid(conf.orig_gid);
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
220 }
0
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
221
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
222 DEBUG(5) debugf("accepting message on stdin\n");
0
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
223
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
224 msg->received_prot = PROT_LOCAL;
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
225 for (i = 0; i < addr_cnt; i++) {
264
1e5e457dea18 comments and a small refactoring
markus schnalke <meillo@marmaro.de>
parents: 263
diff changeset
226 if (addresses[i][0] == '|')
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
227 logwrite(LOG_ALERT, "no pipe allowed as recipient address: %s\n", addresses[i]);
262
fc1c6425c024 s/EXIT_SUCCESS/0/ && s/EXIT_FAILURE/1/
markus schnalke <meillo@marmaro.de>
parents: 261
diff changeset
228 exit(1);
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
229 }
264
1e5e457dea18 comments and a small refactoring
markus schnalke <meillo@marmaro.de>
parents: 263
diff changeset
230 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
231 }
0
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
232
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
233 /* -f option */
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
234 msg->return_path = return_path;
0
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
235
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
236 /* -F option */
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
237 msg->full_sender_name = full_sender_name;
0
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
238
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
239 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
240 if (spool_write(msg, TRUE)) {
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
241 pid_t pid;
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
242 logwrite(LOG_NOTICE, "%s <= %s with %s\n", msg->uid, addr_string(msg->return_path), prot_names[PROT_LOCAL]);
0
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
243
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
244 if (!conf.do_queue) {
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
245 if ((pid = fork()) == 0) {
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
246 conf.do_verbose = FALSE;
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
247 fclose(stdin);
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
248 fclose(stdout);
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
249 fclose(stderr);
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
250 if (deliver(msg)) {
262
fc1c6425c024 s/EXIT_SUCCESS/0/ && s/EXIT_FAILURE/1/
markus schnalke <meillo@marmaro.de>
parents: 261
diff changeset
251 exit(0);
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
252 } else
262
fc1c6425c024 s/EXIT_SUCCESS/0/ && s/EXIT_FAILURE/1/
markus schnalke <meillo@marmaro.de>
parents: 261
diff changeset
253 exit(1);
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
254 } 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
255 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
256 }
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
257 }
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
258 } else {
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
259 fprintf(stderr, "Could not write spool file\n");
262
fc1c6425c024 s/EXIT_SUCCESS/0/ && s/EXIT_FAILURE/1/
markus schnalke <meillo@marmaro.de>
parents: 261
diff changeset
260 exit(1);
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
261 }
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 switch (err) {
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
264 case AERR_EOF:
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
265 fprintf(stderr, "unexpected EOF.\n");
262
fc1c6425c024 s/EXIT_SUCCESS/0/ && s/EXIT_FAILURE/1/
markus schnalke <meillo@marmaro.de>
parents: 261
diff changeset
266 exit(1);
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
267 case AERR_NORCPT:
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
268 fprintf(stderr, "no recipients.\n");
262
fc1c6425c024 s/EXIT_SUCCESS/0/ && s/EXIT_FAILURE/1/
markus schnalke <meillo@marmaro.de>
parents: 261
diff changeset
269 exit(1);
117
5ec5e6637049 added server-side SMTP SIZE support (patch by Paolo)
meillo@marmaro.de
parents: 110
diff changeset
270 case AERR_SIZE:
5ec5e6637049 added server-side SMTP SIZE support (patch by Paolo)
meillo@marmaro.de
parents: 110
diff changeset
271 fprintf(stderr, "max message size exceeded.\n");
262
fc1c6425c024 s/EXIT_SUCCESS/0/ && s/EXIT_FAILURE/1/
markus schnalke <meillo@marmaro.de>
parents: 261
diff changeset
272 exit(1);
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
273 default:
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
274 /* should never happen: */
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
275 fprintf(stderr, "Unknown error (%d)\r\n", err);
262
fc1c6425c024 s/EXIT_SUCCESS/0/ && s/EXIT_FAILURE/1/
markus schnalke <meillo@marmaro.de>
parents: 261
diff changeset
276 exit(1);
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
277 }
262
fc1c6425c024 s/EXIT_SUCCESS/0/ && s/EXIT_FAILURE/1/
markus schnalke <meillo@marmaro.de>
parents: 261
diff changeset
278 exit(1);
0
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
279 }
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
280 }
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
281
250
a41c013c8458 moved the queue manipulation code to an new function
markus schnalke <meillo@marmaro.de>
parents: 249
diff changeset
282 /*
264
1e5e457dea18 comments and a small refactoring
markus schnalke <meillo@marmaro.de>
parents: 263
diff changeset
283 if -Mrm is given
1e5e457dea18 comments and a small refactoring
markus schnalke <meillo@marmaro.de>
parents: 263
diff changeset
284
250
a41c013c8458 moved the queue manipulation code to an new function
markus schnalke <meillo@marmaro.de>
parents: 249
diff changeset
285 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
286 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
287 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
288 */
a41c013c8458 moved the queue manipulation code to an new function
markus schnalke <meillo@marmaro.de>
parents: 249
diff changeset
289 static int
a41c013c8458 moved the queue manipulation code to an new function
markus schnalke <meillo@marmaro.de>
parents: 249
diff changeset
290 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
291 {
a41c013c8458 moved the queue manipulation code to an new function
markus schnalke <meillo@marmaro.de>
parents: 249
diff changeset
292 gboolean ok = FALSE;
a41c013c8458 moved the queue manipulation code to an new function
markus schnalke <meillo@marmaro.de>
parents: 249
diff changeset
293
a41c013c8458 moved the queue manipulation code to an new function
markus schnalke <meillo@marmaro.de>
parents: 249
diff changeset
294 if (strcmp(cmd, "rm") != 0) {
a41c013c8458 moved the queue manipulation code to an new function
markus schnalke <meillo@marmaro.de>
parents: 249
diff changeset
295 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
296 return FALSE;
a41c013c8458 moved the queue manipulation code to an new function
markus schnalke <meillo@marmaro.de>
parents: 249
diff changeset
297 }
a41c013c8458 moved the queue manipulation code to an new function
markus schnalke <meillo@marmaro.de>
parents: 249
diff changeset
298
a41c013c8458 moved the queue manipulation code to an new function
markus schnalke <meillo@marmaro.de>
parents: 249
diff changeset
299 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
300
a41c013c8458 moved the queue manipulation code to an new function
markus schnalke <meillo@marmaro.de>
parents: 249
diff changeset
301 /* 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
302 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
303 for (; *id; id++) {
a41c013c8458 moved the queue manipulation code to an new function
markus schnalke <meillo@marmaro.de>
parents: 249
diff changeset
304 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
305 if (queue_delete(*id)) {
a41c013c8458 moved the queue manipulation code to an new function
markus schnalke <meillo@marmaro.de>
parents: 249
diff changeset
306 ok = TRUE;
a41c013c8458 moved the queue manipulation code to an new function
markus schnalke <meillo@marmaro.de>
parents: 249
diff changeset
307 }
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 return ok;
a41c013c8458 moved the queue manipulation code to an new function
markus schnalke <meillo@marmaro.de>
parents: 249
diff changeset
310 }
a41c013c8458 moved the queue manipulation code to an new function
markus schnalke <meillo@marmaro.de>
parents: 249
diff changeset
311
a41c013c8458 moved the queue manipulation code to an new function
markus schnalke <meillo@marmaro.de>
parents: 249
diff changeset
312 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
313 if (!pw) {
a41c013c8458 moved the queue manipulation code to an new function
markus schnalke <meillo@marmaro.de>
parents: 249
diff changeset
314 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
315 conf.orig_uid, strerror(errno));
a41c013c8458 moved the queue manipulation code to an new function
markus schnalke <meillo@marmaro.de>
parents: 249
diff changeset
316 return FALSE;
a41c013c8458 moved the queue manipulation code to an new function
markus schnalke <meillo@marmaro.de>
parents: 249
diff changeset
317 }
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 /* 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
320 for (; *id; id++) {
a41c013c8458 moved the queue manipulation code to an new function
markus schnalke <meillo@marmaro.de>
parents: 249
diff changeset
321 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
322
a41c013c8458 moved the queue manipulation code to an new function
markus schnalke <meillo@marmaro.de>
parents: 249
diff changeset
323 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
324
a41c013c8458 moved the queue manipulation code to an new function
markus schnalke <meillo@marmaro.de>
parents: 249
diff changeset
325 if (!msg->ident) {
a41c013c8458 moved the queue manipulation code to an new function
markus schnalke <meillo@marmaro.de>
parents: 249
diff changeset
326 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
327 continue;
a41c013c8458 moved the queue manipulation code to an new function
markus schnalke <meillo@marmaro.de>
parents: 249
diff changeset
328 }
a41c013c8458 moved the queue manipulation code to an new function
markus schnalke <meillo@marmaro.de>
parents: 249
diff changeset
329 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
330 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
331 continue;
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 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
335 #ifdef ENABLE_IDENT
a41c013c8458 moved the queue manipulation code to an new function
markus schnalke <meillo@marmaro.de>
parents: 249
diff changeset
336 && !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
337 #endif
a41c013c8458 moved the queue manipulation code to an new function
markus schnalke <meillo@marmaro.de>
parents: 249
diff changeset
338 ) {
a41c013c8458 moved the queue manipulation code to an new function
markus schnalke <meillo@marmaro.de>
parents: 249
diff changeset
339 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
340 continue;
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
a41c013c8458 moved the queue manipulation code to an new function
markus schnalke <meillo@marmaro.de>
parents: 249
diff changeset
343 ok = queue_delete(*id);
a41c013c8458 moved the queue manipulation code to an new function
markus schnalke <meillo@marmaro.de>
parents: 249
diff changeset
344 }
a41c013c8458 moved the queue manipulation code to an new function
markus schnalke <meillo@marmaro.de>
parents: 249
diff changeset
345 return ok;
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
264
1e5e457dea18 comments and a small refactoring
markus schnalke <meillo@marmaro.de>
parents: 263
diff changeset
348 /* -qo, -q (without argument), or called as runq */
1e5e457dea18 comments and a small refactoring
markus schnalke <meillo@marmaro.de>
parents: 263
diff changeset
349 /* TODO: are -qo and -q exclusively or not?
1e5e457dea18 comments and a small refactoring
markus schnalke <meillo@marmaro.de>
parents: 263
diff changeset
350 And how is this related to being a daemon? */
251
2babd21e7c75 moved run_queue to a new function
markus schnalke <meillo@marmaro.de>
parents: 250
diff changeset
351 static int
2babd21e7c75 moved run_queue to a new function
markus schnalke <meillo@marmaro.de>
parents: 250
diff changeset
352 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
353 {
2babd21e7c75 moved run_queue to a new function
markus schnalke <meillo@marmaro.de>
parents: 250
diff changeset
354 int ret;
2babd21e7c75 moved run_queue to a new function
markus schnalke <meillo@marmaro.de>
parents: 250
diff changeset
355
2babd21e7c75 moved run_queue to a new function
markus schnalke <meillo@marmaro.de>
parents: 250
diff changeset
356 /* queue runs */
2babd21e7c75 moved run_queue to a new function
markus schnalke <meillo@marmaro.de>
parents: 250
diff changeset
357 set_identity(conf.orig_uid, "queue run");
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 if (do_runq) {
2babd21e7c75 moved run_queue to a new function
markus schnalke <meillo@marmaro.de>
parents: 250
diff changeset
360 ret = queue_run();
2babd21e7c75 moved run_queue to a new function
markus schnalke <meillo@marmaro.de>
parents: 250
diff changeset
361 }
2babd21e7c75 moved run_queue to a new function
markus schnalke <meillo@marmaro.de>
parents: 250
diff changeset
362
2babd21e7c75 moved run_queue to a new function
markus schnalke <meillo@marmaro.de>
parents: 250
diff changeset
363 if (do_runq_online) {
2babd21e7c75 moved run_queue to a new function
markus schnalke <meillo@marmaro.de>
parents: 250
diff changeset
364 if (route_name) {
2babd21e7c75 moved run_queue to a new function
markus schnalke <meillo@marmaro.de>
parents: 250
diff changeset
365 conf.online_detect = g_strdup("argument");
2babd21e7c75 moved run_queue to a new function
markus schnalke <meillo@marmaro.de>
parents: 250
diff changeset
366 set_online_name(route_name);
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 ret = queue_run_online();
2babd21e7c75 moved run_queue to a new function
markus schnalke <meillo@marmaro.de>
parents: 250
diff changeset
369 }
2babd21e7c75 moved run_queue to a new function
markus schnalke <meillo@marmaro.de>
parents: 250
diff changeset
370 return ret;
2babd21e7c75 moved run_queue to a new function
markus schnalke <meillo@marmaro.de>
parents: 250
diff changeset
371 }
2babd21e7c75 moved run_queue to a new function
markus schnalke <meillo@marmaro.de>
parents: 250
diff changeset
372
264
1e5e457dea18 comments and a small refactoring
markus schnalke <meillo@marmaro.de>
parents: 263
diff changeset
373 /* -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
374 static void
0afe18a9ee03 fixed previous commit and excluded mode_version() from main()
markus schnalke <meillo@marmaro.de>
parents: 260
diff changeset
375 mode_version(void)
0afe18a9ee03 fixed previous commit and excluded mode_version() from main()
markus schnalke <meillo@marmaro.de>
parents: 260
diff changeset
376 {
0afe18a9ee03 fixed previous commit and excluded mode_version() from main()
markus schnalke <meillo@marmaro.de>
parents: 260
diff changeset
377 gchar *with_resolver = "";
0afe18a9ee03 fixed previous commit and excluded mode_version() from main()
markus schnalke <meillo@marmaro.de>
parents: 260
diff changeset
378 gchar *with_auth = "";
0afe18a9ee03 fixed previous commit and excluded mode_version() from main()
markus schnalke <meillo@marmaro.de>
parents: 260
diff changeset
379 gchar *with_ident = "";
0afe18a9ee03 fixed previous commit and excluded mode_version() from main()
markus schnalke <meillo@marmaro.de>
parents: 260
diff changeset
380
0afe18a9ee03 fixed previous commit and excluded mode_version() from main()
markus schnalke <meillo@marmaro.de>
parents: 260
diff changeset
381 #ifdef ENABLE_RESOLVER
0afe18a9ee03 fixed previous commit and excluded mode_version() from main()
markus schnalke <meillo@marmaro.de>
parents: 260
diff changeset
382 with_resolver = " +resolver";
0afe18a9ee03 fixed previous commit and excluded mode_version() from main()
markus schnalke <meillo@marmaro.de>
parents: 260
diff changeset
383 #endif
0afe18a9ee03 fixed previous commit and excluded mode_version() from main()
markus schnalke <meillo@marmaro.de>
parents: 260
diff changeset
384 #ifdef ENABLE_AUTH
0afe18a9ee03 fixed previous commit and excluded mode_version() from main()
markus schnalke <meillo@marmaro.de>
parents: 260
diff changeset
385 with_auth = " +auth";
0afe18a9ee03 fixed previous commit and excluded mode_version() from main()
markus schnalke <meillo@marmaro.de>
parents: 260
diff changeset
386 #endif
0afe18a9ee03 fixed previous commit and excluded mode_version() from main()
markus schnalke <meillo@marmaro.de>
parents: 260
diff changeset
387 #ifdef ENABLE_IDENT
0afe18a9ee03 fixed previous commit and excluded mode_version() from main()
markus schnalke <meillo@marmaro.de>
parents: 260
diff changeset
388 with_ident = " +ident";
0afe18a9ee03 fixed previous commit and excluded mode_version() from main()
markus schnalke <meillo@marmaro.de>
parents: 260
diff changeset
389 #endif
0afe18a9ee03 fixed previous commit and excluded mode_version() from main()
markus schnalke <meillo@marmaro.de>
parents: 260
diff changeset
390
0afe18a9ee03 fixed previous commit and excluded mode_version() from main()
markus schnalke <meillo@marmaro.de>
parents: 260
diff changeset
391 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
392 }
0afe18a9ee03 fixed previous commit and excluded mode_version() from main()
markus schnalke <meillo@marmaro.de>
parents: 260
diff changeset
393
0
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
394 int
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
395 main(int argc, char *argv[])
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
396 {
251
2babd21e7c75 moved run_queue to a new function
markus schnalke <meillo@marmaro.de>
parents: 250
diff changeset
397 gchar *progname;
249
f9da5a7caeda refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents: 248
diff changeset
398 char* opt;
f9da5a7caeda refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents: 248
diff changeset
399 gint arg;
0
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
400
259
f4117fd5a163 made default mode sensible
markus schnalke <meillo@marmaro.de>
parents: 258
diff changeset
401 mta_mode mta_mode = MODE_NONE;
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
402 gboolean do_listen = FALSE;
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
403 gboolean do_runq = FALSE;
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
404 gboolean do_runq_online = FALSE;
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
405 gboolean do_queue = FALSE;
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
406 gint queue_interval = 0;
251
2babd21e7c75 moved run_queue to a new function
markus schnalke <meillo@marmaro.de>
parents: 250
diff changeset
407 gchar *M_cmd = NULL;
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
408 gboolean opt_t = FALSE;
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
409 gboolean opt_i = FALSE;
251
2babd21e7c75 moved run_queue to a new function
markus schnalke <meillo@marmaro.de>
parents: 250
diff changeset
410 gchar *conf_file = CONF_FILE;
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
411 gchar *route_name = NULL;
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
412 gchar *f_address = NULL;
251
2babd21e7c75 moved run_queue to a new function
markus schnalke <meillo@marmaro.de>
parents: 250
diff changeset
413 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
414 gchar *full_sender_name = NULL;
251
2babd21e7c75 moved run_queue to a new function
markus schnalke <meillo@marmaro.de>
parents: 250
diff changeset
415 gboolean do_verbose = FALSE;
2babd21e7c75 moved run_queue to a new function
markus schnalke <meillo@marmaro.de>
parents: 250
diff changeset
416 gint debug_level = -1;
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
417
260
bd3109ec0f0a substituted get_progname() with a call to strrchr()
markus schnalke <meillo@marmaro.de>
parents: 259
diff changeset
418 /* strip the path part */
261
0afe18a9ee03 fixed previous commit and excluded mode_version() from main()
markus schnalke <meillo@marmaro.de>
parents: 260
diff changeset
419 progname = strrchr(argv[0], '/');
0afe18a9ee03 fixed previous commit and excluded mode_version() from main()
markus schnalke <meillo@marmaro.de>
parents: 260
diff changeset
420 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
421
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
422 if (strcmp(progname, "mailq") == 0) {
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
423 mta_mode = MODE_LIST;
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
424 } else if (strcmp(progname, "mailrm") == 0) {
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
425 mta_mode = MODE_MCMD;
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
426 M_cmd = "rm";
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
427 } else if (strcmp(progname, "runq") == 0) {
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
428 mta_mode = MODE_RUNQUEUE;
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
429 do_runq = TRUE;
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
430 } else if (strcmp(progname, "rmail") == 0) {
89
a917cb178ca7 what about the `rmail' alias?
meillo@marmaro.de
parents: 83
diff changeset
431 /* the `rmail' alias should probably be removed now
a917cb178ca7 what about the `rmail' alias?
meillo@marmaro.de
parents: 83
diff changeset
432 that we have the rmail script. But let's keep it
a917cb178ca7 what about the `rmail' alias?
meillo@marmaro.de
parents: 83
diff changeset
433 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
434 mta_mode = MODE_ACCEPT;
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
435 opt_i = TRUE;
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
436 } 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
437 mta_mode = MODE_SMTP;
0
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
438 }
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
439
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
440 /* parse cmd line */
249
f9da5a7caeda refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents: 248
diff changeset
441 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
442 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
443
f9da5a7caeda refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents: 248
diff changeset
444 if (strcmp(opt, "-") == 0) {
f9da5a7caeda refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents: 248
diff changeset
445 /* everything after `--' are address arguments */
f9da5a7caeda refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents: 248
diff changeset
446 arg++;
f9da5a7caeda refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents: 248
diff changeset
447 break;
f9da5a7caeda refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents: 248
diff changeset
448
f9da5a7caeda refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents: 248
diff changeset
449 } else if (strcmp(opt, "bd") == 0) {
f9da5a7caeda refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents: 248
diff changeset
450 do_listen = TRUE;
f9da5a7caeda refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents: 248
diff changeset
451 mta_mode = MODE_DAEMON;
f9da5a7caeda refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents: 248
diff changeset
452
f9da5a7caeda refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents: 248
diff changeset
453 } else if (strcmp(opt, "bi") == 0) {
f9da5a7caeda refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents: 248
diff changeset
454 /* ignored */
f9da5a7caeda refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents: 248
diff changeset
455 mta_mode = MODE_BI;
f9da5a7caeda refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents: 248
diff changeset
456
f9da5a7caeda refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents: 248
diff changeset
457 } else if (strcmp(opt, "bs") == 0) {
f9da5a7caeda refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents: 248
diff changeset
458 mta_mode = MODE_SMTP;
f9da5a7caeda refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents: 248
diff changeset
459
f9da5a7caeda refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents: 248
diff changeset
460 } else if (strcmp(opt, "bp") == 0) {
f9da5a7caeda refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents: 248
diff changeset
461 mta_mode = MODE_LIST;
f9da5a7caeda refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents: 248
diff changeset
462
f9da5a7caeda refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents: 248
diff changeset
463 } else if (strcmp(opt, "bV") == 0) {
f9da5a7caeda refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents: 248
diff changeset
464 mta_mode = MODE_VERSION;
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
465
249
f9da5a7caeda refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents: 248
diff changeset
466 } else if (strncmp(opt, "B", 1) == 0) {
f9da5a7caeda refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents: 248
diff changeset
467 /* we ignore this and throw the argument away */
f9da5a7caeda refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents: 248
diff changeset
468 get_optarg(argv, &arg, opt+1);
f9da5a7caeda refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents: 248
diff changeset
469
f9da5a7caeda refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents: 248
diff changeset
470 } 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
471 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
472 if (!conf_file) {
249
f9da5a7caeda refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents: 248
diff changeset
473 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
474 exit(1);
249
f9da5a7caeda refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents: 248
diff changeset
475 }
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
476
249
f9da5a7caeda refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents: 248
diff changeset
477 } else if (strncmp(opt, "d", 1) == 0) {
f9da5a7caeda refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents: 248
diff changeset
478 if (getuid() != 0) {
f9da5a7caeda refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents: 248
diff changeset
479 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
480 exit(1);
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 char *lvl = get_optarg(argv, &arg, opt+1);
f9da5a7caeda refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents: 248
diff changeset
483 if (!lvl) {
f9da5a7caeda refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents: 248
diff changeset
484 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
485 exit(1);
249
f9da5a7caeda refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents: 248
diff changeset
486 }
f9da5a7caeda refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents: 248
diff changeset
487 debug_level = atoi(lvl);
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 (strncmp(opt, "f", 1) == 0) {
f9da5a7caeda refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents: 248
diff changeset
490 /* set return path */
f9da5a7caeda refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents: 248
diff changeset
491 gchar *address = get_optarg(argv, &arg, opt+1);
f9da5a7caeda refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents: 248
diff changeset
492 if (!address) {
f9da5a7caeda refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents: 248
diff changeset
493 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
494 exit(1);
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
495 }
249
f9da5a7caeda refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents: 248
diff changeset
496 f_address = g_strdup(address);
f9da5a7caeda refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents: 248
diff changeset
497
f9da5a7caeda refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents: 248
diff changeset
498 } else if (strncmp(opt, "F", 1) == 0) {
f9da5a7caeda refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents: 248
diff changeset
499 full_sender_name = get_optarg(argv, &arg, opt+1);
f9da5a7caeda refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents: 248
diff changeset
500 if (!full_sender_name) {
f9da5a7caeda refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents: 248
diff changeset
501 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
502 exit(1);
249
f9da5a7caeda refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents: 248
diff changeset
503 }
f9da5a7caeda refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents: 248
diff changeset
504
f9da5a7caeda refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents: 248
diff changeset
505 } else if (strcmp(opt, "i") == 0) {
f9da5a7caeda refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents: 248
diff changeset
506 opt_i = 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 } else if (strcmp(opt, "m") == 0) {
f9da5a7caeda refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents: 248
diff changeset
509 /* ignore -m (me too) switch (see man page) */
f9da5a7caeda refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents: 248
diff changeset
510
f9da5a7caeda refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents: 248
diff changeset
511 } else if (strcmp(opt, "Mrm") == 0) {
f9da5a7caeda refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents: 248
diff changeset
512 mta_mode = MODE_MCMD;
f9da5a7caeda refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents: 248
diff changeset
513 M_cmd = "rm";
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 (strcmp(opt, "odq") == 0) {
f9da5a7caeda refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents: 248
diff changeset
516 do_queue = TRUE;
f9da5a7caeda refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents: 248
diff changeset
517
f9da5a7caeda refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents: 248
diff changeset
518 } 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
519 opt_i = TRUE;
249
f9da5a7caeda refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents: 248
diff changeset
520
f9da5a7caeda refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents: 248
diff changeset
521 } else if (strncmp(opt, "o", 1) == 0) {
f9da5a7caeda refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents: 248
diff changeset
522 /* ignore all other -oXXX options */
f9da5a7caeda refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents: 248
diff changeset
523
f9da5a7caeda refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents: 248
diff changeset
524 } else if (strncmp(opt, "qo", 2) == 0) {
f9da5a7caeda refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents: 248
diff changeset
525 mta_mode = MODE_RUNQUEUE;
f9da5a7caeda refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents: 248
diff changeset
526 do_runq = FALSE;
f9da5a7caeda refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents: 248
diff changeset
527 do_runq_online = TRUE;
f9da5a7caeda refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents: 248
diff changeset
528 /* can be NULL, then we use online detection method */
f9da5a7caeda refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents: 248
diff changeset
529 route_name = get_optarg(argv, &arg, opt+2);
f9da5a7caeda refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents: 248
diff changeset
530
f9da5a7caeda refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents: 248
diff changeset
531 } else if (strncmp(opt, "q", 1) == 0) {
f9da5a7caeda refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents: 248
diff changeset
532 /* must be after the `qo' check */
f9da5a7caeda refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents: 248
diff changeset
533 gchar *optarg;
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 do_runq = TRUE;
f9da5a7caeda refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents: 248
diff changeset
536 mta_mode = MODE_RUNQUEUE;
251
2babd21e7c75 moved run_queue to a new function
markus schnalke <meillo@marmaro.de>
parents: 250
diff changeset
537 optarg = get_optarg(argv, &arg, opt+1);
2babd21e7c75 moved run_queue to a new function
markus schnalke <meillo@marmaro.de>
parents: 250
diff changeset
538 if (optarg) {
2babd21e7c75 moved run_queue to a new function
markus schnalke <meillo@marmaro.de>
parents: 250
diff changeset
539 /* 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
540 mta_mode = MODE_DAEMON;
254
82d168dd52fd removed the obsolete pos argument from time_interval()
markus schnalke <meillo@marmaro.de>
parents: 251
diff changeset
541 queue_interval = time_interval(optarg);
249
f9da5a7caeda refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents: 248
diff changeset
542 }
f9da5a7caeda refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents: 248
diff changeset
543
f9da5a7caeda refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents: 248
diff changeset
544 } else if (strcmp(opt, "t") == 0) {
f9da5a7caeda refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents: 248
diff changeset
545 opt_t = TRUE;
f9da5a7caeda refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents: 248
diff changeset
546
f9da5a7caeda refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents: 248
diff changeset
547 } else if (strcmp(opt, "v") == 0) {
f9da5a7caeda refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents: 248
diff changeset
548 do_verbose = TRUE;
f9da5a7caeda refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents: 248
diff changeset
549
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
550 } else {
249
f9da5a7caeda refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents: 248
diff changeset
551 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
552 exit(1);
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
553 }
0
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
554 }
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
555
259
f4117fd5a163 made default mode sensible
markus schnalke <meillo@marmaro.de>
parents: 258
diff changeset
556 if (!mta_mode) {
f4117fd5a163 made default mode sensible
markus schnalke <meillo@marmaro.de>
parents: 258
diff changeset
557 mta_mode = (arg<argc || opt_t) ? MODE_ACCEPT : MODE_VERSION;
f4117fd5a163 made default mode sensible
markus schnalke <meillo@marmaro.de>
parents: 258
diff changeset
558 }
f4117fd5a163 made default mode sensible
markus schnalke <meillo@marmaro.de>
parents: 258
diff changeset
559
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
560 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
561 mode_version();
262
fc1c6425c024 s/EXIT_SUCCESS/0/ && s/EXIT_FAILURE/1/
markus schnalke <meillo@marmaro.de>
parents: 261
diff changeset
562 exit(0);
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
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
565 /* initialize random generator */
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
566 srand(time(NULL));
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
567 /* ignore SIGPIPE signal */
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
568 signal(SIGPIPE, SIG_IGN);
0
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
569
73
9db75b801dc4 made a comment more exact
meillo@marmaro.de
parents: 72
diff changeset
570 /* 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
571 {
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
572 int i, max_fd = sysconf(_SC_OPEN_MAX);
0
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
573
251
2babd21e7c75 moved run_queue to a new function
markus schnalke <meillo@marmaro.de>
parents: 250
diff changeset
574 if (max_fd <= 0) {
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
575 max_fd = 64;
251
2babd21e7c75 moved run_queue to a new function
markus schnalke <meillo@marmaro.de>
parents: 250
diff changeset
576 }
2babd21e7c75 moved run_queue to a new function
markus schnalke <meillo@marmaro.de>
parents: 250
diff changeset
577 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
578 close(i);
251
2babd21e7c75 moved run_queue to a new function
markus schnalke <meillo@marmaro.de>
parents: 250
diff changeset
579 }
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
580 }
0
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
581
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
582 init_conf();
0
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
583
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
584 /* 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
585 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
586 privileges.
0
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
587
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
588 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
589 breaking security.
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
590 */
251
2babd21e7c75 moved run_queue to a new function
markus schnalke <meillo@marmaro.de>
parents: 250
diff changeset
591 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
592 conf.run_as_user = TRUE;
2babd21e7c75 moved run_queue to a new function
markus schnalke <meillo@marmaro.de>
parents: 250
diff changeset
593 seteuid(conf.orig_uid);
2babd21e7c75 moved run_queue to a new function
markus schnalke <meillo@marmaro.de>
parents: 250
diff changeset
594 setegid(conf.orig_gid);
2babd21e7c75 moved run_queue to a new function
markus schnalke <meillo@marmaro.de>
parents: 250
diff changeset
595 setuid(conf.orig_uid);
2babd21e7c75 moved run_queue to a new function
markus schnalke <meillo@marmaro.de>
parents: 250
diff changeset
596 setgid(conf.orig_gid);
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
597 }
0
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
598
155
b5ab9cb2f18a shut down on errors reading config file
meillo@marmaro.de
parents: 117
diff changeset
599 conf.log_dir = LOG_DIR;
b5ab9cb2f18a shut down on errors reading config file
meillo@marmaro.de
parents: 117
diff changeset
600 logopen();
b5ab9cb2f18a shut down on errors reading config file
meillo@marmaro.de
parents: 117
diff changeset
601 if (!read_conf(conf_file)) {
b5ab9cb2f18a shut down on errors reading config file
meillo@marmaro.de
parents: 117
diff changeset
602 logwrite(LOG_ALERT, "SHUTTING DOWN due to problems reading config\n");
b5ab9cb2f18a shut down on errors reading config file
meillo@marmaro.de
parents: 117
diff changeset
603 exit(5);
b5ab9cb2f18a shut down on errors reading config file
meillo@marmaro.de
parents: 117
diff changeset
604 }
b5ab9cb2f18a shut down on errors reading config file
meillo@marmaro.de
parents: 117
diff changeset
605 logclose();
0
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
606
251
2babd21e7c75 moved run_queue to a new function
markus schnalke <meillo@marmaro.de>
parents: 250
diff changeset
607 if (do_queue) {
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
608 conf.do_queue = TRUE;
251
2babd21e7c75 moved run_queue to a new function
markus schnalke <meillo@marmaro.de>
parents: 250
diff changeset
609 }
2babd21e7c75 moved run_queue to a new function
markus schnalke <meillo@marmaro.de>
parents: 250
diff changeset
610 if (do_verbose) {
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
611 conf.do_verbose = TRUE;
251
2babd21e7c75 moved run_queue to a new function
markus schnalke <meillo@marmaro.de>
parents: 250
diff changeset
612 }
2babd21e7c75 moved run_queue to a new function
markus schnalke <meillo@marmaro.de>
parents: 250
diff changeset
613 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
614 conf.debug_level = debug_level;
251
2babd21e7c75 moved run_queue to a new function
markus schnalke <meillo@marmaro.de>
parents: 250
diff changeset
615 }
0
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
616
46
3cb6f383f07e fixed tests/local.sh
meillo@marmaro.de
parents: 12
diff changeset
617 /* It appears that changing to / ensures that we are never in
3cb6f383f07e fixed tests/local.sh
meillo@marmaro.de
parents: 12
diff changeset
618 a directory which we cannot access. This situation could be
3cb6f383f07e fixed tests/local.sh
meillo@marmaro.de
parents: 12
diff changeset
619 possible after changing identity.
3cb6f383f07e fixed tests/local.sh
meillo@marmaro.de
parents: 12
diff changeset
620 Maybe we should only change to / if we not run as user, to
3cb6f383f07e fixed tests/local.sh
meillo@marmaro.de
parents: 12
diff changeset
621 allow relative paths for log files in test setups for
3cb6f383f07e fixed tests/local.sh
meillo@marmaro.de
parents: 12
diff changeset
622 instance.
3cb6f383f07e fixed tests/local.sh
meillo@marmaro.de
parents: 12
diff changeset
623 */
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
624 chdir("/");
0
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
625
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
626 if (!conf.run_as_user) {
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
627 if (setgid(0) != 0) {
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
628 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
629 exit(1);
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
630 }
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
631 if (setuid(0) != 0) {
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
632 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
633 exit(1);
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
634 }
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
635 }
0
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
636
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
637 if (!logopen()) {
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
638 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
639 exit(1);
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
640 }
0
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
641
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
642 DEBUG(1) debugf("masqmail %s starting\n", VERSION);
0
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
643
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
644 DEBUG(5) {
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
645 gchar **str = argv;
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
646 debugf("args: \n");
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
647 while (*str) {
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
648 debugf("%s \n", *str);
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
649 str++;
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
650 }
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
651 }
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
652 DEBUG(5) debugf("queue_interval = %d\n", queue_interval);
0
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
653
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
654 if (f_address) {
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
655 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
656 g_free(f_address);
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
657 if (!return_path) {
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
658 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
659 exit(1);
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
660 }
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
661 }
0
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
662
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
663 switch (mta_mode) {
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
664 case MODE_DAEMON:
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
665 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
666 break;
251
2babd21e7c75 moved run_queue to a new function
markus schnalke <meillo@marmaro.de>
parents: 250
diff changeset
667
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
668 case MODE_RUNQUEUE:
251
2babd21e7c75 moved run_queue to a new function
markus schnalke <meillo@marmaro.de>
parents: 250
diff changeset
669 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
670 break;
0
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
671
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
672 case MODE_SMTP:
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
673 mode_smtp();
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
674 break;
0
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
675
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
676 case MODE_LIST:
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
677 queue_list();
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
678 break;
0
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
679
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
680 case MODE_BI:
262
fc1c6425c024 s/EXIT_SUCCESS/0/ && s/EXIT_FAILURE/1/
markus schnalke <meillo@marmaro.de>
parents: 261
diff changeset
681 exit(0);
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
682 break; /* well... */
0
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
683
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
684 case MODE_MCMD:
250
a41c013c8458 moved the queue manipulation code to an new function
markus schnalke <meillo@marmaro.de>
parents: 249
diff changeset
685 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
686 break;
0
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
687
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
688 case MODE_ACCEPT:
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
689 {
107
9104234a56a5 never create headers from recipients
meillo@marmaro.de
parents: 106
diff changeset
690 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
691 | (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
692 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
693 exit(0);
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
694 }
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
695 break;
251
2babd21e7c75 moved run_queue to a new function
markus schnalke <meillo@marmaro.de>
parents: 250
diff changeset
696
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
697 default:
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
698 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
699 break;
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
700 }
0
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
701
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
702 logclose();
0
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
703
263
e9e73505ab2c removed now obsolete exit_code
markus schnalke <meillo@marmaro.de>
parents: 262
diff changeset
704 exit(0);
0
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
705 }