annotate src/masqmail.c @ 249:f9da5a7caeda

refactored the cmdline argument processing I replaced the nested switch statements with one single large else-if construct. Instead of char comparision now str(n)cmp(3) is used. Although this is slower it is much more readable and covers corner-cases which were uncovered before (e.g. -bdxxx). As always: Readability and simplicity matter, not performance.
author markus schnalke <meillo@marmaro.de>
date Thu, 04 Nov 2010 11:02:42 -0300
parents 018cfd163f5c
children a41c013c8458
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 {
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
41 MODE_ACCEPT = 0, /* accept message on stdin */
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
42 MODE_DAEMON, /* run as daemon */
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
43 MODE_RUNQUEUE, /* single queue run, online or offline */
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
44 MODE_SMTP, /* accept SMTP on stdin */
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
45 MODE_LIST, /* list queue */
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
46 MODE_MCMD, /* do queue manipulation */
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
47 MODE_VERSION, /* show version */
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
48 MODE_BI, /* fake ;-) */
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
49 MODE_NONE /* to prevent default MODE_ACCEPT */
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
50 } mta_mode;
0
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 gchar*
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
118 get_progname(gchar * arg0)
0
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 gchar *p = arg0 + strlen(arg0) - 1;
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
121 while (p > arg0) {
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
122 if (*p == '/')
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
123 return p + 1;
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
124 p--;
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
125 }
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
126 return p;
0
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
127 }
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
128
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
129 gboolean
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
130 write_pidfile(gchar * name)
0
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
131 {
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
132 FILE *fptr;
0
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
133
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
134 if ((fptr = fopen(name, "wt"))) {
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
135 fprintf(fptr, "%d\n", getpid());
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
136 fclose(fptr);
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
137 pidfile = strdup(name);
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
138 return TRUE;
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
139 }
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
140 logwrite(LOG_WARNING, "could not write pid file: %s\n", strerror(errno));
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
141 return FALSE;
0
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
142 }
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
143
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
144 static void
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
145 mode_daemon(gboolean do_listen, gint queue_interval, char *argv[])
0
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
146 {
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
147 guint pid;
0
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
148
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
149 /* daemon */
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
150 if (!conf.run_as_user) {
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
151 if ((conf.orig_uid != 0) && (conf.orig_uid != conf.mail_uid)) {
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
152 fprintf(stderr, "must be root or %s for daemon.\n", DEF_MAIL_USER);
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
153 exit(EXIT_FAILURE);
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
154 }
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
155 }
0
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
156
74
0a5b2e96ade3 do not reparent the daemon to init if init is already the parent
meillo@marmaro.de
parents: 73
diff changeset
157 /* reparent to init only if init is not already the parent */
0a5b2e96ade3 do not reparent the daemon to init if init is already the parent
meillo@marmaro.de
parents: 73
diff changeset
158 if (getppid() != 1) {
0a5b2e96ade3 do not reparent the daemon to init if init is already the parent
meillo@marmaro.de
parents: 73
diff changeset
159 if ((pid = fork()) > 0) {
0a5b2e96ade3 do not reparent the daemon to init if init is already the parent
meillo@marmaro.de
parents: 73
diff changeset
160 exit(EXIT_SUCCESS);
0a5b2e96ade3 do not reparent the daemon to init if init is already the parent
meillo@marmaro.de
parents: 73
diff changeset
161 } else if (pid < 0) {
208
3708b655a371 added newlines to the end of log and debug messages where missing
meillo@marmaro.de
parents: 205
diff changeset
162 logwrite(LOG_ALERT, "could not fork!\n");
74
0a5b2e96ade3 do not reparent the daemon to init if init is already the parent
meillo@marmaro.de
parents: 73
diff changeset
163 exit(EXIT_FAILURE);
0a5b2e96ade3 do not reparent the daemon to init if init is already the parent
meillo@marmaro.de
parents: 73
diff changeset
164 }
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
165 }
0
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
166
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
167 signal(SIGTERM, sigterm_handler);
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
168 write_pidfile(PIDFILEDIR "/masqmail.pid");
0
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
169
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
170 conf.do_verbose = FALSE;
0
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
171
72
ad034b57f3b2 fixed Debian bug 536060 (log files are closed after SIGHUP receival)
meillo@marmaro.de
parents: 46
diff changeset
172 /* closing and reopening the log ensures that it is open afterwards
ad034b57f3b2 fixed Debian bug 536060 (log files are closed after SIGHUP receival)
meillo@marmaro.de
parents: 46
diff changeset
173 because it is possible that the log is assigned to fd 1 and gets
ad034b57f3b2 fixed Debian bug 536060 (log files are closed after SIGHUP receival)
meillo@marmaro.de
parents: 46
diff changeset
174 thus closes by fclose(stdout). Similar for the debugfile.
ad034b57f3b2 fixed Debian bug 536060 (log files are closed after SIGHUP receival)
meillo@marmaro.de
parents: 46
diff changeset
175 */
ad034b57f3b2 fixed Debian bug 536060 (log files are closed after SIGHUP receival)
meillo@marmaro.de
parents: 46
diff changeset
176 logclose();
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
177 fclose(stdin);
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
178 fclose(stdout);
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
179 fclose(stderr);
72
ad034b57f3b2 fixed Debian bug 536060 (log files are closed after SIGHUP receival)
meillo@marmaro.de
parents: 46
diff changeset
180 logopen();
0
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
181
208
3708b655a371 added newlines to the end of log and debug messages where missing
meillo@marmaro.de
parents: 205
diff changeset
182 logwrite(LOG_NOTICE, "%s %s daemon starting\n", PACKAGE, VERSION);
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
183 listen_port(do_listen ? conf.listen_addresses : NULL, queue_interval, argv);
0
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
184 }
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 static void
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
187 mode_smtp()
0
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
188 {
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
189 /* accept smtp message on stdin */
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
190 /* write responses to stderr. */
0
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
191
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
192 struct sockaddr_in saddr;
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
193 gchar *peername = NULL;
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
194 int dummy = sizeof(saddr);
0
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
195
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
196 conf.do_verbose = FALSE;
0
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
197
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
198 if (!conf.run_as_user) {
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
199 seteuid(conf.orig_uid);
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
200 setegid(conf.orig_gid);
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
201 }
0
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
202
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
203 DEBUG(5) debugf("accepting smtp message on stdin\n");
0
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
204
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
205 if (getpeername(0, (struct sockaddr *) (&saddr), &dummy) == 0) {
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
206 peername = g_strdup(inet_ntoa(saddr.sin_addr));
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
207 } else if (errno != ENOTSOCK)
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
208 exit(EXIT_FAILURE);
0
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
209
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
210 smtp_in(stdin, stderr, peername, NULL);
0
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
211 }
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
212
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
213 static void
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
214 mode_accept(address * return_path, gchar * full_sender_name, guint accept_flags, char **addresses, int addr_cnt)
0
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
215 {
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
216 /* accept message on stdin */
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
217 accept_error err;
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
218 message *msg = create_message();
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
219 gint i;
0
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
220
83
085d6cd44462 using is_privileged_user() to check here too
meillo@marmaro.de
parents: 76
diff changeset
221 if (return_path && !is_privileged_user(conf.orig_uid)) {
96
b76080154aec small typo fix
meillo@marmaro.de
parents: 89
diff changeset
222 fprintf(stderr, "must be root, %s or in group %s for setting return path.\n", DEF_MAIL_USER, DEF_MAIL_GROUP);
83
085d6cd44462 using is_privileged_user() to check here too
meillo@marmaro.de
parents: 76
diff changeset
223 exit(EXIT_FAILURE);
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
224 }
0
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
225
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
226 if (!conf.run_as_user) {
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
227 seteuid(conf.orig_uid);
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
228 setegid(conf.orig_gid);
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
229 }
0
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
230
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
231 DEBUG(5) debugf("accepting message on stdin\n");
0
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 msg->received_prot = PROT_LOCAL;
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
234 for (i = 0; i < addr_cnt; i++) {
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
235 if (addresses[i][0] != '|')
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
236 msg->rcpt_list = g_list_append(msg->rcpt_list, create_address_qualified(addresses[i], TRUE, conf.host_name));
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
237 else {
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
238 logwrite(LOG_ALERT, "no pipe allowed as recipient address: %s\n", addresses[i]);
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
239 exit(EXIT_FAILURE);
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
240 }
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
241 }
0
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
242
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
243 /* -f option */
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
244 msg->return_path = return_path;
0
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
245
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
246 /* -F option */
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
247 msg->full_sender_name = full_sender_name;
0
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
248
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
249 if ((err = accept_message(stdin, msg, accept_flags)) == AERR_OK) {
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
250 if (spool_write(msg, TRUE)) {
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
251 pid_t pid;
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
252 logwrite(LOG_NOTICE, "%s <= %s with %s\n", msg->uid, addr_string(msg->return_path), prot_names[PROT_LOCAL]);
0
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
253
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
254 if (!conf.do_queue) {
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
255 if ((pid = fork()) == 0) {
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
256 conf.do_verbose = FALSE;
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
257 fclose(stdin);
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
258 fclose(stdout);
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
259 fclose(stderr);
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
260 if (deliver(msg)) {
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
261 exit(EXIT_SUCCESS);
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
262 } else
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
263 exit(EXIT_FAILURE);
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
264 } else if (pid < 0) {
208
3708b655a371 added newlines to the end of log and debug messages where missing
meillo@marmaro.de
parents: 205
diff changeset
265 logwrite(LOG_ALERT, "could not fork for delivery, id = %s\n", msg->uid);
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
266 }
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
267 }
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
268 } else {
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
269 fprintf(stderr, "Could not write spool file\n");
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
270 exit(EXIT_FAILURE);
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
271 }
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
272 } else {
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
273 switch (err) {
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
274 case AERR_EOF:
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
275 fprintf(stderr, "unexpected EOF.\n");
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
276 exit(EXIT_FAILURE);
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
277 case AERR_NORCPT:
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
278 fprintf(stderr, "no recipients.\n");
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
279 exit(EXIT_FAILURE);
117
5ec5e6637049 added server-side SMTP SIZE support (patch by Paolo)
meillo@marmaro.de
parents: 110
diff changeset
280 case AERR_SIZE:
5ec5e6637049 added server-side SMTP SIZE support (patch by Paolo)
meillo@marmaro.de
parents: 110
diff changeset
281 fprintf(stderr, "max message size exceeded.\n");
5ec5e6637049 added server-side SMTP SIZE support (patch by Paolo)
meillo@marmaro.de
parents: 110
diff changeset
282 exit(EXIT_FAILURE);
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
283 default:
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
284 /* should never happen: */
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
285 fprintf(stderr, "Unknown error (%d)\r\n", err);
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
286 exit(EXIT_FAILURE);
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
287 }
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
288 exit(EXIT_FAILURE);
0
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
289 }
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
290 }
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
291
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
292 int
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
293 main(int argc, char *argv[])
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
294 {
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
295 /* cmd line flags */
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
296 gchar *conf_file = CONF_FILE;
249
f9da5a7caeda refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents: 248
diff changeset
297 char* opt;
f9da5a7caeda refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents: 248
diff changeset
298 gint arg;
0
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
299
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
300 gboolean do_listen = FALSE;
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
301 gboolean do_runq = FALSE;
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
302 gboolean do_runq_online = FALSE;
0
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
303
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
304 gboolean do_queue = FALSE;
0
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
305
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
306 gboolean do_verbose = FALSE;
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
307 gint debug_level = -1;
0
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
308
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
309 mta_mode mta_mode = MODE_ACCEPT;
0
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
310
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
311 gint queue_interval = 0;
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
312 gboolean opt_t = FALSE;
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
313 gboolean opt_i = FALSE;
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
314 gboolean exit_failure = FALSE;
0
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
315
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
316 gchar *M_cmd = NULL;
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
317
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
318 gint exit_code = EXIT_SUCCESS;
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
319 gchar *route_name = NULL;
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
320 gchar *progname;
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
321 gchar *f_address = NULL;
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
322 gchar *full_sender_name = NULL;
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
323 address *return_path = NULL; /* may be changed by -f option */
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
324
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
325 progname = get_progname(argv[0]);
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
326
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
327 if (strcmp(progname, "mailq") == 0) {
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
328 mta_mode = MODE_LIST;
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
329 } else if (strcmp(progname, "mailrm") == 0) {
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
330 mta_mode = MODE_MCMD;
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
331 M_cmd = "rm";
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
332 } else if (strcmp(progname, "runq") == 0) {
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
333 mta_mode = MODE_RUNQUEUE;
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
334 do_runq = TRUE;
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
335 } else if (strcmp(progname, "rmail") == 0) {
89
a917cb178ca7 what about the `rmail' alias?
meillo@marmaro.de
parents: 83
diff changeset
336 /* the `rmail' alias should probably be removed now
a917cb178ca7 what about the `rmail' alias?
meillo@marmaro.de
parents: 83
diff changeset
337 that we have the rmail script. But let's keep it
a917cb178ca7 what about the `rmail' alias?
meillo@marmaro.de
parents: 83
diff changeset
338 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
339 mta_mode = MODE_ACCEPT;
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
340 opt_i = TRUE;
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
341 } 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
342 mta_mode = MODE_SMTP;
0
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
343 }
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
344
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
345 /* parse cmd line */
249
f9da5a7caeda refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents: 248
diff changeset
346 for (arg=1; arg<argc && argv[arg][0]=='-'; arg++) {
f9da5a7caeda refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents: 248
diff changeset
347 opt = argv[arg] + 1;
f9da5a7caeda refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents: 248
diff changeset
348
f9da5a7caeda refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents: 248
diff changeset
349 if (strcmp(opt, "-") == 0) {
f9da5a7caeda refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents: 248
diff changeset
350 /* everything after `--' are address arguments */
f9da5a7caeda refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents: 248
diff changeset
351 arg++;
f9da5a7caeda refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents: 248
diff changeset
352 break;
f9da5a7caeda refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents: 248
diff changeset
353
f9da5a7caeda refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents: 248
diff changeset
354 } else if (strcmp(opt, "bd") == 0) {
f9da5a7caeda refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents: 248
diff changeset
355 do_listen = TRUE;
f9da5a7caeda refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents: 248
diff changeset
356 mta_mode = MODE_DAEMON;
f9da5a7caeda refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents: 248
diff changeset
357
f9da5a7caeda refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents: 248
diff changeset
358 } else if (strcmp(opt, "bi") == 0) {
f9da5a7caeda refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents: 248
diff changeset
359 /* ignored */
f9da5a7caeda refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents: 248
diff changeset
360 mta_mode = MODE_BI;
f9da5a7caeda refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents: 248
diff changeset
361
f9da5a7caeda refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents: 248
diff changeset
362 } else if (strcmp(opt, "bs") == 0) {
f9da5a7caeda refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents: 248
diff changeset
363 mta_mode = MODE_SMTP;
f9da5a7caeda refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents: 248
diff changeset
364
f9da5a7caeda refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents: 248
diff changeset
365 } else if (strcmp(opt, "bp") == 0) {
f9da5a7caeda refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents: 248
diff changeset
366 mta_mode = MODE_LIST;
f9da5a7caeda refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents: 248
diff changeset
367
f9da5a7caeda refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents: 248
diff changeset
368 } else if (strcmp(opt, "bV") == 0) {
f9da5a7caeda refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents: 248
diff changeset
369 mta_mode = MODE_VERSION;
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
370
249
f9da5a7caeda refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents: 248
diff changeset
371 } else if (strncmp(opt, "B", 1) == 0) {
f9da5a7caeda refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents: 248
diff changeset
372 /* we ignore this and throw the argument away */
f9da5a7caeda refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents: 248
diff changeset
373 get_optarg(argv, &arg, opt+1);
f9da5a7caeda refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents: 248
diff changeset
374
f9da5a7caeda refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents: 248
diff changeset
375 } else if (strncmp(opt, "C", 1) == 0) {
f9da5a7caeda refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents: 248
diff changeset
376 if (!(conf_file = get_optarg(argv, &arg, opt+1))) {
f9da5a7caeda refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents: 248
diff changeset
377 fprintf(stderr, "-C requires a filename as argument.\n");
f9da5a7caeda refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents: 248
diff changeset
378 exit(EXIT_FAILURE);
f9da5a7caeda refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents: 248
diff changeset
379 }
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
380
249
f9da5a7caeda refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents: 248
diff changeset
381 } else if (strncmp(opt, "d", 1) == 0) {
f9da5a7caeda refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents: 248
diff changeset
382 if (getuid() != 0) {
f9da5a7caeda refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents: 248
diff changeset
383 fprintf(stderr, "only root may set the debug level.\n");
f9da5a7caeda refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents: 248
diff changeset
384 exit(EXIT_FAILURE);
f9da5a7caeda refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents: 248
diff changeset
385 }
f9da5a7caeda refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents: 248
diff changeset
386 char *lvl = get_optarg(argv, &arg, opt+1);
f9da5a7caeda refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents: 248
diff changeset
387 if (!lvl) {
f9da5a7caeda refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents: 248
diff changeset
388 fprintf(stderr, "-d requires a number argument.\n");
f9da5a7caeda refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents: 248
diff changeset
389 exit(EXIT_FAILURE);
f9da5a7caeda refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents: 248
diff changeset
390 }
f9da5a7caeda refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents: 248
diff changeset
391 debug_level = atoi(lvl);
f9da5a7caeda refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents: 248
diff changeset
392
f9da5a7caeda refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents: 248
diff changeset
393 } else if (strncmp(opt, "f", 1) == 0) {
f9da5a7caeda refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents: 248
diff changeset
394 /* set return path */
f9da5a7caeda refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents: 248
diff changeset
395 gchar *address = get_optarg(argv, &arg, opt+1);
f9da5a7caeda refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents: 248
diff changeset
396 if (!address) {
f9da5a7caeda refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents: 248
diff changeset
397 fprintf(stderr, "-f requires an address argument\n");
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
398 exit(EXIT_FAILURE);
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
399 }
249
f9da5a7caeda refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents: 248
diff changeset
400 f_address = g_strdup(address);
f9da5a7caeda refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents: 248
diff changeset
401
f9da5a7caeda refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents: 248
diff changeset
402 } else if (strncmp(opt, "F", 1) == 0) {
f9da5a7caeda refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents: 248
diff changeset
403 full_sender_name = get_optarg(argv, &arg, opt+1);
f9da5a7caeda refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents: 248
diff changeset
404 if (!full_sender_name) {
f9da5a7caeda refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents: 248
diff changeset
405 fprintf(stderr, "-F requires a name argument\n");
f9da5a7caeda refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents: 248
diff changeset
406 exit(EXIT_FAILURE);
f9da5a7caeda refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents: 248
diff changeset
407 }
f9da5a7caeda refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents: 248
diff changeset
408
f9da5a7caeda refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents: 248
diff changeset
409 } else if (strcmp(opt, "i") == 0) {
f9da5a7caeda refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents: 248
diff changeset
410 opt_i = TRUE;
f9da5a7caeda refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents: 248
diff changeset
411 exit_failure = FALSE; /* may override -oem */
f9da5a7caeda refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents: 248
diff changeset
412
f9da5a7caeda refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents: 248
diff changeset
413 } else if (strcmp(opt, "m") == 0) {
f9da5a7caeda refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents: 248
diff changeset
414 /* ignore -m (me too) switch (see man page) */
f9da5a7caeda refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents: 248
diff changeset
415
f9da5a7caeda refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents: 248
diff changeset
416 } else if (strcmp(opt, "Mrm") == 0) {
f9da5a7caeda refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents: 248
diff changeset
417 mta_mode = MODE_MCMD;
f9da5a7caeda refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents: 248
diff changeset
418 M_cmd = "rm";
f9da5a7caeda refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents: 248
diff changeset
419
f9da5a7caeda refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents: 248
diff changeset
420 } else if (strcmp(opt, "odq") == 0) {
f9da5a7caeda refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents: 248
diff changeset
421 do_queue = TRUE;
f9da5a7caeda refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents: 248
diff changeset
422
f9da5a7caeda refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents: 248
diff changeset
423 } else if (strcmp(opt, "oem") == 0) {
f9da5a7caeda refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents: 248
diff changeset
424 if (!opt_i) {
f9da5a7caeda refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents: 248
diff changeset
425 /* TODO: Why is this related to -i in any way? */
f9da5a7caeda refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents: 248
diff changeset
426 exit_failure = TRUE;
f9da5a7caeda refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents: 248
diff changeset
427 }
f9da5a7caeda refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents: 248
diff changeset
428
f9da5a7caeda refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents: 248
diff changeset
429 } else if (strcmp(opt, "oi") == 0) {
f9da5a7caeda refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents: 248
diff changeset
430 exit_failure = FALSE; /* may override -oem */
f9da5a7caeda refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents: 248
diff changeset
431
f9da5a7caeda refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents: 248
diff changeset
432 } else if (strncmp(opt, "o", 1) == 0) {
f9da5a7caeda refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents: 248
diff changeset
433 /* ignore all other -oXXX options */
f9da5a7caeda refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents: 248
diff changeset
434
f9da5a7caeda refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents: 248
diff changeset
435 } else if (strncmp(opt, "qo", 2) == 0) {
f9da5a7caeda refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents: 248
diff changeset
436 mta_mode = MODE_RUNQUEUE;
f9da5a7caeda refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents: 248
diff changeset
437 do_runq = FALSE;
f9da5a7caeda refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents: 248
diff changeset
438 do_runq_online = TRUE;
f9da5a7caeda refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents: 248
diff changeset
439 /* can be NULL, then we use online detection method */
f9da5a7caeda refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents: 248
diff changeset
440 route_name = get_optarg(argv, &arg, opt+2);
f9da5a7caeda refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents: 248
diff changeset
441
f9da5a7caeda refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents: 248
diff changeset
442 } else if (strncmp(opt, "q", 1) == 0) {
f9da5a7caeda refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents: 248
diff changeset
443 /* must be after the `qo' check */
f9da5a7caeda refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents: 248
diff changeset
444 gchar *optarg;
f9da5a7caeda refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents: 248
diff changeset
445 int dummy;
f9da5a7caeda refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents: 248
diff changeset
446
f9da5a7caeda refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents: 248
diff changeset
447 do_runq = TRUE;
f9da5a7caeda refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents: 248
diff changeset
448 mta_mode = MODE_RUNQUEUE;
f9da5a7caeda refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents: 248
diff changeset
449 if ((optarg = get_optarg(argv, &arg, opt+1))) {
f9da5a7caeda refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents: 248
diff changeset
450 mta_mode = MODE_DAEMON;
f9da5a7caeda refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents: 248
diff changeset
451 queue_interval = time_interval(optarg, &dummy);
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
f9da5a7caeda refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents: 248
diff changeset
454 } else if (strcmp(opt, "t") == 0) {
f9da5a7caeda refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents: 248
diff changeset
455 opt_t = TRUE;
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, "v") == 0) {
f9da5a7caeda refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents: 248
diff changeset
458 do_verbose = TRUE;
f9da5a7caeda refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents: 248
diff changeset
459
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
460 } else {
249
f9da5a7caeda refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents: 248
diff changeset
461 fprintf(stderr, "unrecognized option `-%s'\n", opt);
f9da5a7caeda refactored the cmdline argument processing
markus schnalke <meillo@marmaro.de>
parents: 248
diff changeset
462 exit(EXIT_FAILURE);
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
463 }
0
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
464 }
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
465
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
466 if (mta_mode == MODE_VERSION) {
12
9fb7ddbaf129 removed noop-code; some beautifying
meillo@marmaro.de
parents: 10
diff changeset
467 gchar *with_resolver = "";
9fb7ddbaf129 removed noop-code; some beautifying
meillo@marmaro.de
parents: 10
diff changeset
468 gchar *with_auth = "";
9fb7ddbaf129 removed noop-code; some beautifying
meillo@marmaro.de
parents: 10
diff changeset
469 gchar *with_ident = "";
0
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
470
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
471 #ifdef ENABLE_RESOLVER
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
472 with_resolver = " +resolver";
0
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
473 #endif
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
474 #ifdef ENABLE_AUTH
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
475 with_auth = " +auth";
0
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
476 #endif
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
477 #ifdef ENABLE_IDENT
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
478 with_ident = " +ident";
0
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
479 #endif
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
480
205
4fd237550525 REMOVED MAILDIR SUPPORT
meillo@marmaro.de
parents: 204
diff changeset
481 printf("%s %s%s%s%s\n", PACKAGE, VERSION, with_resolver, with_auth, with_ident);
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
482
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
483 exit(EXIT_SUCCESS);
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
484 }
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
485
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
486 /* initialize random generator */
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
487 srand(time(NULL));
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
488 /* ignore SIGPIPE signal */
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
489 signal(SIGPIPE, SIG_IGN);
0
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
490
73
9db75b801dc4 made a comment more exact
meillo@marmaro.de
parents: 72
diff changeset
491 /* 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
492 {
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
493 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
494
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
495 if (max_fd <= 0)
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
496 max_fd = 64;
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
497 for (i = 3; i < max_fd; i++)
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
498 close(i);
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
499 }
0
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
500
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
501 init_conf();
0
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
502
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
503 /* 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
504 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
505 privileges.
0
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
506
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
507 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
508 breaking security.
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
509 */
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
510 if (strcmp(conf_file, CONF_FILE) != 0) {
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
511 if (conf.orig_uid != 0) {
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
512 conf.run_as_user = TRUE;
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
513 seteuid(conf.orig_uid);
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
514 setegid(conf.orig_gid);
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
515 setuid(conf.orig_uid);
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
516 setgid(conf.orig_gid);
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
517 }
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
518 }
0
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
519
155
b5ab9cb2f18a shut down on errors reading config file
meillo@marmaro.de
parents: 117
diff changeset
520 conf.log_dir = LOG_DIR;
b5ab9cb2f18a shut down on errors reading config file
meillo@marmaro.de
parents: 117
diff changeset
521 logopen();
b5ab9cb2f18a shut down on errors reading config file
meillo@marmaro.de
parents: 117
diff changeset
522 if (!read_conf(conf_file)) {
b5ab9cb2f18a shut down on errors reading config file
meillo@marmaro.de
parents: 117
diff changeset
523 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
524 exit(5);
b5ab9cb2f18a shut down on errors reading config file
meillo@marmaro.de
parents: 117
diff changeset
525 }
b5ab9cb2f18a shut down on errors reading config file
meillo@marmaro.de
parents: 117
diff changeset
526 logclose();
0
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
527
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
528 if (do_queue)
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
529 conf.do_queue = TRUE;
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
530 if (do_verbose)
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
531 conf.do_verbose = TRUE;
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
532 if (debug_level >= 0) /* if >= 0, it was given by argument */
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
533 conf.debug_level = debug_level;
0
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
534
46
3cb6f383f07e fixed tests/local.sh
meillo@marmaro.de
parents: 12
diff changeset
535 /* It appears that changing to / ensures that we are never in
3cb6f383f07e fixed tests/local.sh
meillo@marmaro.de
parents: 12
diff changeset
536 a directory which we cannot access. This situation could be
3cb6f383f07e fixed tests/local.sh
meillo@marmaro.de
parents: 12
diff changeset
537 possible after changing identity.
3cb6f383f07e fixed tests/local.sh
meillo@marmaro.de
parents: 12
diff changeset
538 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
539 allow relative paths for log files in test setups for
3cb6f383f07e fixed tests/local.sh
meillo@marmaro.de
parents: 12
diff changeset
540 instance.
3cb6f383f07e fixed tests/local.sh
meillo@marmaro.de
parents: 12
diff changeset
541 */
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
542 chdir("/");
0
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
543
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
544 if (!conf.run_as_user) {
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
545 if (setgid(0) != 0) {
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
546 fprintf(stderr, "could not set gid to 0. Is the setuid bit set? : %s\n", strerror(errno));
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
547 exit(EXIT_FAILURE);
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
548 }
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
549 if (setuid(0) != 0) {
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
550 fprintf(stderr, "could not gain root privileges. Is the setuid bit set? : %s\n", strerror(errno));
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
551 exit(EXIT_FAILURE);
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
552 }
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
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
555 if (!logopen()) {
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
556 fprintf(stderr, "could not open log file\n");
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
557 exit(EXIT_FAILURE);
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
558 }
0
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
559
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
560 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
561
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
562 DEBUG(5) {
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
563 gchar **str = argv;
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
564 debugf("args: \n");
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
565 while (*str) {
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
566 debugf("%s \n", *str);
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
567 str++;
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
568 }
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
569 }
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
570 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
571
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
572 if (f_address) {
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
573 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
574 g_free(f_address);
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
575 if (!return_path) {
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
576 fprintf(stderr, "invalid RFC821 address: %s\n", f_address);
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
577 exit(EXIT_FAILURE);
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
578 }
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
579 }
0
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
580
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
581 switch (mta_mode) {
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
582 case MODE_DAEMON:
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
583 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
584 break;
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
585 case MODE_RUNQUEUE:
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
586 {
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
587 /* queue runs */
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
588 set_identity(conf.orig_uid, "queue run");
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
589
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
590 if (do_runq)
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
591 exit_code = queue_run() ? EXIT_SUCCESS : EXIT_FAILURE;
0
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
592
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
593 if (do_runq_online) {
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
594 if (route_name != NULL) {
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
595 conf.online_detect = g_strdup("argument");
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
596 set_online_name(route_name);
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
597 }
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
598 exit_code =
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
599 queue_run_online() ? EXIT_SUCCESS : EXIT_FAILURE;
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
600 }
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
601 }
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
602 break;
0
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
603
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
604 case MODE_SMTP:
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
605 mode_smtp();
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
606 break;
0
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
607
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
608 case MODE_LIST:
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
609 queue_list();
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
610 break;
0
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
611
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
612 case MODE_BI:
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
613 exit(EXIT_SUCCESS);
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
614 break; /* well... */
0
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
615
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
616 case MODE_MCMD:
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
617 if (strcmp(M_cmd, "rm") == 0) {
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
618 gboolean ok = FALSE;
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
619
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
620 set_euidgid(conf.mail_uid, conf.mail_gid, NULL, NULL);
0
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
621
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
622 if (is_privileged_user(conf.orig_uid)) {
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
623 for (; arg < argc; arg++) {
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
624 if (queue_delete(argv[arg]))
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
625 ok = TRUE;
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
626 }
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
627 } else {
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
628 struct passwd *pw = getpwuid(conf.orig_uid);
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
629 if (pw) {
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
630 for (; arg < argc; arg++) {
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
631 message *msg = msg_spool_read(argv[arg], FALSE);
0
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
632 #ifdef ENABLE_IDENT
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
633 if (((msg->received_host == NULL) && (msg->received_prot == PROT_LOCAL))
248
018cfd163f5c refactored processing of -oXXX options
markus schnalke <meillo@marmaro.de>
parents: 247
diff changeset
634 || is_in_netlist(msg->received_host, conf.ident_trusted_nets))
0
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
635 #else
248
018cfd163f5c refactored processing of -oXXX options
markus schnalke <meillo@marmaro.de>
parents: 247
diff changeset
636 if ((msg->received_host == NULL) && (msg->received_prot == PROT_LOCAL))
0
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
637 #endif
248
018cfd163f5c refactored processing of -oXXX options
markus schnalke <meillo@marmaro.de>
parents: 247
diff changeset
638 {
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
639 if (msg->ident) {
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
640 if (strcmp(pw->pw_name, msg->ident) == 0) {
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
641 if (queue_delete(argv[arg]))
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
642 ok = TRUE;
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
643 } else {
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
644 fprintf(stderr, "you do not own message id %s\n", argv[arg]);
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
645 }
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
646 } else
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
647 fprintf(stderr, "message %s does not have an ident.\n", argv[arg]);
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
648 } else {
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
649 fprintf(stderr, "message %s was not received locally or from a trusted network.\n", argv[arg]);
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 } else {
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
653 fprintf(stderr, "could not find a passwd entry for uid %d: %s\n", conf.orig_uid, strerror(errno));
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
654 }
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
655 }
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
656 exit(ok ? EXIT_SUCCESS : EXIT_FAILURE);
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
657 } else {
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
658 fprintf(stderr, "unknown command %s\n", M_cmd);
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
659 exit(EXIT_FAILURE);
0
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
660 }
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
661 break;
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 case MODE_ACCEPT:
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
664 {
107
9104234a56a5 never create headers from recipients
meillo@marmaro.de
parents: 106
diff changeset
665 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
666 | (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
667 mode_accept(return_path, full_sender_name, accept_flags, &(argv[arg]), argc - arg);
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
668 exit(exit_failure ? EXIT_FAILURE : EXIT_SUCCESS);
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
669 }
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
670 break;
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
671 case MODE_NONE:
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
672 break;
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
673 default:
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
674 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
675 break;
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
676 }
0
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
677
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
678 logclose();
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 exit(exit_code);
0
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
681 }