masqmail

view src/masqmail.c @ 430:180a7f6a9383

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