masqmail

view src/masqmail.c @ 79:d2bee9f4625c

man/Makefile.in was not up to date
author meillo@marmaro.de
date Sat, 19 Jun 2010 10:52:24 +0200
parents 0a5b2e96ade3
children 085d6cd44462
line source
1 /* MasqMail
2 Copyright (C) 1999-2001 Oliver Kurth
3 Copyright (C) 2010 markus schnalke <meillo@marmaro.de>
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18 */
20 #include <stdio.h>
21 #include <errno.h>
22 #include <stdlib.h>
23 #include <string.h>
24 #include <unistd.h>
25 #include <sys/types.h>
26 #include <sys/socket.h>
27 #include <sys/time.h>
28 #include <netinet/in.h>
29 #include <netdb.h>
30 #include <syslog.h>
31 #include <signal.h>
33 #include <glib.h>
35 #include "masqmail.h"
37 /* mutually exclusive modes. Note that there is neither a 'get' mode
38 nor a 'queue daemon' mode. These, as well as the distinction beween
39 the two (non exclusive) daemon (queue and listen) modes are handled
40 by flags.*/
41 typedef enum _mta_mode {
42 MODE_ACCEPT = 0, /* accept message on stdin */
43 MODE_DAEMON, /* run as daemon */
44 MODE_RUNQUEUE, /* single queue run, online or offline */
45 MODE_GET_DAEMON, /* run as get (retrieve) daemon */
46 MODE_SMTP, /* accept SMTP on stdin */
47 MODE_LIST, /* list queue */
48 MODE_MCMD, /* do queue manipulation */
49 MODE_VERSION, /* show version */
50 MODE_BI, /* fake ;-) */
51 MODE_NONE /* to prevent default MODE_ACCEPT */
52 } mta_mode;
54 char *pidfile = NULL;
55 volatile int sigterm_in_progress = 0;
57 static void
58 sigterm_handler(int sig)
59 {
60 if (sigterm_in_progress)
61 raise(sig);
62 sigterm_in_progress = 1;
64 if (pidfile) {
65 uid_t uid;
66 uid = seteuid(0);
67 if (unlink(pidfile) != 0)
68 logwrite(LOG_WARNING, "could not delete pid file %s: %s\n", pidfile, strerror(errno));
69 seteuid(uid); /* we exit anyway after this, just to be sure */
70 }
72 signal(sig, SIG_DFL);
73 raise(sig);
74 }
76 #ifdef ENABLE_IDENT /* so far used for that only */
77 static gboolean
78 is_in_netlist(gchar * host, GList * netlist)
79 {
80 guint hostip = inet_addr(host);
81 struct in_addr addr;
83 addr.s_addr = hostip;
84 if (addr.s_addr != INADDR_NONE) {
85 GList *node;
86 foreach(netlist, node) {
87 struct in_addr *net = (struct in_addr *) (node->data);
88 if ((addr.s_addr & net->s_addr) == net->s_addr)
89 return TRUE;
90 }
91 }
92 return FALSE;
93 }
94 #endif
96 gchar*
97 get_optarg(char *argv[], gint argc, gint * argp, gint * pos)
98 {
99 if (argv[*argp][*pos])
100 return &(argv[*argp][*pos]);
101 else {
102 if (*argp + 1 < argc) {
103 if (argv[(*argp) + 1][0] != '-') {
104 (*argp)++;
105 *pos = 0;
106 return &(argv[*argp][*pos]);
107 }
108 }
109 }
110 return NULL;
111 }
113 gchar*
114 get_progname(gchar * arg0)
115 {
116 gchar *p = arg0 + strlen(arg0) - 1;
117 while (p > arg0) {
118 if (*p == '/')
119 return p + 1;
120 p--;
121 }
122 return p;
123 }
125 gboolean
126 write_pidfile(gchar * name)
127 {
128 FILE *fptr;
130 if ((fptr = fopen(name, "wt"))) {
131 fprintf(fptr, "%d\n", getpid());
132 fclose(fptr);
133 pidfile = strdup(name);
134 return TRUE;
135 }
136 logwrite(LOG_WARNING, "could not write pid file: %s\n", strerror(errno));
137 return FALSE;
138 }
140 static void
141 mode_daemon(gboolean do_listen, gint queue_interval, char *argv[])
142 {
143 guint pid;
145 /* daemon */
146 if (!conf.run_as_user) {
147 if ((conf.orig_uid != 0) && (conf.orig_uid != conf.mail_uid)) {
148 fprintf(stderr, "must be root or %s for daemon.\n", DEF_MAIL_USER);
149 exit(EXIT_FAILURE);
150 }
151 }
153 /* reparent to init only if init is not already the parent */
154 if (getppid() != 1) {
155 if ((pid = fork()) > 0) {
156 exit(EXIT_SUCCESS);
157 } else if (pid < 0) {
158 logwrite(LOG_ALERT, "could not fork!");
159 exit(EXIT_FAILURE);
160 }
161 }
163 signal(SIGTERM, sigterm_handler);
164 write_pidfile(PIDFILEDIR "/masqmail.pid");
166 conf.do_verbose = FALSE;
168 /* closing and reopening the log ensures that it is open afterwards
169 because it is possible that the log is assigned to fd 1 and gets
170 thus closes by fclose(stdout). Similar for the debugfile.
171 */
172 logclose();
173 fclose(stdin);
174 fclose(stdout);
175 fclose(stderr);
176 logopen();
178 listen_port(do_listen ? conf.listen_addresses : NULL, queue_interval, argv);
179 }
181 #ifdef ENABLE_POP3
182 static void
183 mode_get_daemon(gint get_interval, char *argv[])
184 {
185 guint pid;
187 /* daemon */
188 if (!conf.run_as_user) {
189 if ((conf.orig_uid != 0) && (conf.orig_uid != conf.mail_uid)) {
190 fprintf(stderr, "must be root or %s for daemon.\n", DEF_MAIL_USER);
191 exit(EXIT_FAILURE);
192 }
193 }
195 /* reparent to init only if init is not already the parent */
196 if (getppid() != 1) {
197 if ((pid = fork()) > 0) {
198 exit(EXIT_SUCCESS);
199 } else if (pid < 0) {
200 logwrite(LOG_ALERT, "could not fork!");
201 exit(EXIT_FAILURE);
202 }
203 }
205 signal(SIGTERM, sigterm_handler);
206 write_pidfile(PIDFILEDIR "/masqmail-get.pid");
208 conf.do_verbose = FALSE;
210 /* closing and reopening the log ensures that it is open afterwards
211 because it is possible that the log is assigned to fd 1 and gets
212 thus closes by fclose(stdout). Similar for the debugfile.
213 */
214 logclose();
215 fclose(stdin);
216 fclose(stdout);
217 fclose(stderr);
218 logopen();
220 get_daemon(get_interval, argv);
221 }
222 #endif
224 #ifdef ENABLE_SMTP_SERVER
225 static void
226 mode_smtp()
227 {
228 /* accept smtp message on stdin */
229 /* write responses to stderr. */
231 struct sockaddr_in saddr;
232 gchar *peername = NULL;
233 int dummy = sizeof(saddr);
235 conf.do_verbose = FALSE;
237 if (!conf.run_as_user) {
238 seteuid(conf.orig_uid);
239 setegid(conf.orig_gid);
240 }
242 DEBUG(5) debugf("accepting smtp message on stdin\n");
244 if (getpeername(0, (struct sockaddr *) (&saddr), &dummy) == 0) {
245 peername = g_strdup(inet_ntoa(saddr.sin_addr));
246 } else if (errno != ENOTSOCK)
247 exit(EXIT_FAILURE);
249 smtp_in(stdin, stderr, peername, NULL);
250 }
251 #endif
253 static void
254 mode_accept(address * return_path, gchar * full_sender_name, guint accept_flags, char **addresses, int addr_cnt)
255 {
256 /* accept message on stdin */
257 accept_error err;
258 message *msg = create_message();
259 gint i;
261 if (return_path != NULL) {
262 if ((conf.orig_uid != 0)
263 && (conf.orig_uid != conf.mail_uid)
264 && (!is_ingroup(conf.orig_uid, conf.mail_gid))) {
265 fprintf(stderr, "must be in root, %s or in group %s for setting return path.\n", DEF_MAIL_USER, DEF_MAIL_GROUP);
266 exit(EXIT_FAILURE);
267 }
268 }
270 if (!conf.run_as_user) {
271 seteuid(conf.orig_uid);
272 setegid(conf.orig_gid);
273 }
275 DEBUG(5) debugf("accepting message on stdin\n");
277 msg->received_prot = PROT_LOCAL;
278 for (i = 0; i < addr_cnt; i++) {
279 if (addresses[i][0] != '|')
280 msg->rcpt_list = g_list_append(msg->rcpt_list, create_address_qualified(addresses[i], TRUE, conf.host_name));
281 else {
282 logwrite(LOG_ALERT, "no pipe allowed as recipient address: %s\n", addresses[i]);
283 exit(EXIT_FAILURE);
284 }
285 }
287 /* -f option */
288 msg->return_path = return_path;
290 /* -F option */
291 msg->full_sender_name = full_sender_name;
293 if ((err = accept_message(stdin, msg, accept_flags)) == AERR_OK) {
294 if (spool_write(msg, TRUE)) {
295 pid_t pid;
296 logwrite(LOG_NOTICE, "%s <= %s with %s\n", msg->uid, addr_string(msg->return_path), prot_names[PROT_LOCAL]);
298 if (!conf.do_queue) {
299 if ((pid = fork()) == 0) {
300 conf.do_verbose = FALSE;
301 fclose(stdin);
302 fclose(stdout);
303 fclose(stderr);
304 if (deliver(msg)) {
305 exit(EXIT_SUCCESS);
306 } else
307 exit(EXIT_FAILURE);
308 } else if (pid < 0) {
309 logwrite(LOG_ALERT, "could not fork for delivery, id = %s", msg->uid);
310 }
311 }
312 } else {
313 fprintf(stderr, "Could not write spool file\n");
314 exit(EXIT_FAILURE);
315 }
316 } else {
317 switch (err) {
318 case AERR_EOF:
319 fprintf(stderr, "unexpected EOF.\n");
320 exit(EXIT_FAILURE);
321 case AERR_NORCPT:
322 fprintf(stderr, "no recipients.\n");
323 exit(EXIT_FAILURE);
324 default:
325 /* should never happen: */
326 fprintf(stderr, "Unknown error (%d)\r\n", err);
327 exit(EXIT_FAILURE);
328 }
329 exit(EXIT_FAILURE);
330 }
331 }
333 int
334 main(int argc, char *argv[])
335 {
336 /* cmd line flags */
337 gchar *conf_file = CONF_FILE;
338 gint arg = 1;
339 gboolean do_get = FALSE;
340 gboolean do_get_online = FALSE;
342 gboolean do_listen = FALSE;
343 gboolean do_runq = FALSE;
344 gboolean do_runq_online = FALSE;
346 gboolean do_queue = FALSE;
348 gboolean do_verbose = FALSE;
349 gint debug_level = -1;
351 mta_mode mta_mode = MODE_ACCEPT;
353 gint queue_interval = 0;
354 gint get_interval = 0;
355 gboolean opt_t = FALSE;
356 gboolean opt_i = FALSE;
357 gboolean opt_odb = FALSE;
358 gboolean opt_oem = FALSE;
359 gboolean exit_failure = FALSE;
361 gchar *M_cmd = NULL;
363 gint exit_code = EXIT_SUCCESS;
364 gchar *route_name = NULL;
365 gchar *get_name = NULL;
366 gchar *progname;
367 gchar *f_address = NULL;
368 gchar *full_sender_name = NULL;
369 address *return_path = NULL; /* may be changed by -f option */
371 progname = get_progname(argv[0]);
373 if (strcmp(progname, "mailq") == 0) {
374 mta_mode = MODE_LIST;
375 } else if (strcmp(progname, "mailrm") == 0) {
376 mta_mode = MODE_MCMD;
377 M_cmd = "rm";
378 } else if (strcmp(progname, "runq") == 0) {
379 mta_mode = MODE_RUNQUEUE;
380 do_runq = TRUE;
381 } else if (strcmp(progname, "rmail") == 0) {
382 mta_mode = MODE_ACCEPT;
383 opt_i = TRUE;
384 } else if (strcmp(progname, "smtpd") == 0 || strcmp(progname, "in.smtpd") == 0) {
385 mta_mode = MODE_SMTP;
386 }
388 /* parse cmd line */
389 while (arg < argc) {
390 gint pos = 0;
391 if ((argv[arg][pos] == '-') && (argv[arg][pos + 1] != '-')) {
392 pos++;
393 switch (argv[arg][pos++]) {
394 case 'b':
395 switch (argv[arg][pos++]) {
396 case 'd':
397 do_listen = TRUE;
398 mta_mode = MODE_DAEMON;
399 break;
400 case 'i':
401 /* ignored */
402 mta_mode = MODE_BI;
403 break;
404 case 's':
405 mta_mode = MODE_SMTP;
406 break;
407 case 'p':
408 mta_mode = MODE_LIST;
409 break;
410 case 'V':
411 mta_mode = MODE_VERSION;
412 break;
413 default:
414 fprintf(stderr, "unrecognized option '%s'\n", argv[arg]);
415 exit(EXIT_FAILURE);
416 }
417 break;
418 case 'B':
419 /* we ignore this and throw the argument away */
420 get_optarg(argv, argc, &arg, &pos);
421 break;
422 case 'C':
423 if (!(conf_file = get_optarg(argv, argc, &arg, &pos))) {
424 fprintf(stderr, "-C requires a filename as argument.\n");
425 exit(EXIT_FAILURE);
426 }
427 break;
428 case 'F':
429 {
430 full_sender_name = get_optarg(argv, argc, &arg, &pos);
431 if (!full_sender_name) {
432 fprintf(stderr, "-F requires a name as an argument\n");
433 exit(EXIT_FAILURE);
434 }
435 }
436 break;
437 case 'd':
438 if (getuid() == 0) {
439 char *lvl = get_optarg(argv, argc, &arg, &pos);
440 if (lvl)
441 debug_level = atoi(lvl);
442 else {
443 fprintf(stderr, "-d requires a number as an argument.\n");
444 exit(EXIT_FAILURE);
445 }
446 } else {
447 fprintf(stderr, "only root may set the debug level.\n");
448 exit(EXIT_FAILURE);
449 }
450 break;
451 case 'f':
452 /* set return path */
453 {
454 gchar *address;
455 address = get_optarg(argv, argc, &arg, &pos);
456 if (address) {
457 f_address = g_strdup(address);
458 } else {
459 fprintf(stderr, "-f requires an address as an argument\n");
460 exit(EXIT_FAILURE);
461 }
462 }
463 break;
464 case 'g':
465 do_get = TRUE;
466 if (!mta_mode)
467 mta_mode = MODE_NONE; /* to prevent default MODE_ACCEPT */
468 if (argv[arg][pos] == 'o') {
469 pos++;
470 do_get_online = TRUE;
471 /* can be NULL, then we use online detection method */
472 route_name = get_optarg(argv, argc, &arg, &pos);
474 if (route_name != NULL) {
475 if (isdigit(route_name[0])) {
476 get_interval = time_interval(route_name, &pos);
477 route_name = get_optarg(argv, argc, &arg, &pos);
478 mta_mode = MODE_GET_DAEMON;
479 do_get = FALSE;
480 }
481 }
482 } else {
483 if ((optarg = get_optarg(argv, argc, &arg, &pos))) {
484 get_name = get_optarg(argv, argc, &arg, &pos);
485 }
486 }
487 break;
488 case 'i':
489 if (argv[arg][pos] == 0) {
490 opt_i = TRUE;
491 exit_failure = FALSE; /* may override -oem */
492 } else {
493 fprintf(stderr, "unrecognized option '%s'\n", argv[arg]);
494 exit(EXIT_FAILURE);
495 }
496 break;
497 case 'M':
498 {
499 mta_mode = MODE_MCMD;
500 M_cmd = g_strdup(&(argv[arg][pos]));
501 }
502 break;
503 case 'o':
504 switch (argv[arg][pos++]) {
505 case 'e':
506 if (argv[arg][pos++] == 'm') /* -oem */
507 if (!opt_i)
508 exit_failure = TRUE;
509 opt_oem = TRUE;
510 break;
511 case 'd':
512 if (argv[arg][pos] == 'b') /* -odb */
513 opt_odb = TRUE;
514 else if (argv[arg][pos] == 'q') /* -odq */
515 do_queue = TRUE;
516 break;
517 case 'i':
518 opt_i = TRUE;
519 exit_failure = FALSE; /* may override -oem */
520 break;
521 }
522 break;
524 case 'q':
525 {
526 gchar *optarg;
528 do_runq = TRUE;
529 mta_mode = MODE_RUNQUEUE;
530 if (argv[arg][pos] == 'o') {
531 pos++;
532 do_runq = FALSE;
533 do_runq_online = TRUE;
534 /* can be NULL, then we use online detection method */
535 route_name = get_optarg(argv, argc, &arg, &pos);
536 } else
537 if ((optarg = get_optarg(argv, argc, &arg, &pos))) {
538 mta_mode = MODE_DAEMON;
539 queue_interval = time_interval(optarg, &pos);
540 }
541 }
542 break;
543 case 't':
544 if (argv[arg][pos] == 0) {
545 opt_t = TRUE;
546 } else {
547 fprintf(stderr, "unrecognized option '%s'\n", argv[arg]);
548 exit(EXIT_FAILURE);
549 }
550 break;
551 case 'v':
552 do_verbose = TRUE;
553 break;
554 default:
555 fprintf(stderr, "unrecognized option '%s'\n", argv[arg]);
556 exit(EXIT_FAILURE);
557 }
558 } else {
559 if (argv[arg][pos + 1] == '-') {
560 if (argv[arg][pos + 2] != '\0') {
561 fprintf(stderr, "unrecognized option '%s'\n", argv[arg]);
562 exit(EXIT_FAILURE);
563 }
564 arg++;
565 }
566 break;
567 }
568 arg++;
569 }
571 if (mta_mode == MODE_VERSION) {
572 gchar *with_resolver = "";
573 gchar *with_smtp_server = "";
574 gchar *with_pop3 = "";
575 gchar *with_auth = "";
576 gchar *with_maildir = "";
577 gchar *with_ident = "";
578 gchar *with_mserver = "";
580 #ifdef ENABLE_RESOLVER
581 with_resolver = " +resolver";
582 #endif
583 #ifdef ENABLE_SMTP_SERVER
584 with_smtp_server = " +smtp-server";
585 #endif
586 #ifdef ENABLE_POP3
587 with_pop3 = " +pop3";
588 #endif
589 #ifdef ENABLE_AUTH
590 with_auth = " +auth";
591 #endif
592 #ifdef ENABLE_MAILDIR
593 with_maildir = " +maildir";
594 #endif
595 #ifdef ENABLE_IDENT
596 with_ident = " +ident";
597 #endif
598 #ifdef ENABLE_MSERVER
599 with_mserver = " +mserver";
600 #endif
602 printf("%s %s%s%s%s%s%s%s%s\n", PACKAGE, VERSION, with_resolver, with_smtp_server,
603 with_pop3, with_auth, with_maildir, with_ident, with_mserver);
605 exit(EXIT_SUCCESS);
606 }
608 /* initialize random generator */
609 srand(time(NULL));
610 /* ignore SIGPIPE signal */
611 signal(SIGPIPE, SIG_IGN);
613 /* close all possibly open file descriptors, except std{in,out,err} */
614 {
615 int i, max_fd = sysconf(_SC_OPEN_MAX);
617 if (max_fd <= 0)
618 max_fd = 64;
619 for (i = 3; i < max_fd; i++)
620 close(i);
621 }
623 init_conf();
625 /* if we are not privileged, and the config file was changed we
626 implicetely set the the run_as_user flag and give up all
627 privileges.
629 So it is possible for a user to run his own daemon without
630 breaking security.
631 */
632 if (strcmp(conf_file, CONF_FILE) != 0) {
633 if (conf.orig_uid != 0) {
634 conf.run_as_user = TRUE;
635 seteuid(conf.orig_uid);
636 setegid(conf.orig_gid);
637 setuid(conf.orig_uid);
638 setgid(conf.orig_gid);
639 }
640 }
642 read_conf(conf_file);
644 if (do_queue)
645 conf.do_queue = TRUE;
646 if (do_verbose)
647 conf.do_verbose = TRUE;
648 if (debug_level >= 0) /* if >= 0, it was given by argument */
649 conf.debug_level = debug_level;
651 /* It appears that changing to / ensures that we are never in
652 a directory which we cannot access. This situation could be
653 possible after changing identity.
654 Maybe we should only change to / if we not run as user, to
655 allow relative paths for log files in test setups for
656 instance.
657 */
658 chdir("/");
660 if (!conf.run_as_user) {
661 if (setgid(0) != 0) {
662 fprintf(stderr, "could not set gid to 0. Is the setuid bit set? : %s\n", strerror(errno));
663 exit(EXIT_FAILURE);
664 }
665 if (setuid(0) != 0) {
666 fprintf(stderr, "could not gain root privileges. Is the setuid bit set? : %s\n", strerror(errno));
667 exit(EXIT_FAILURE);
668 }
669 }
671 if (!logopen()) {
672 fprintf(stderr, "could not open log file\n");
673 exit(EXIT_FAILURE);
674 }
676 DEBUG(1) debugf("masqmail %s starting\n", VERSION);
678 DEBUG(5) {
679 gchar **str = argv;
680 debugf("args: \n");
681 while (*str) {
682 debugf("%s \n", *str);
683 str++;
684 }
685 }
686 DEBUG(5) debugf("queue_interval = %d\n", queue_interval);
688 if (f_address) {
689 return_path = create_address_qualified(f_address, TRUE, conf.host_name);
690 g_free(f_address);
691 if (!return_path) {
692 fprintf(stderr, "invalid RFC821 address: %s\n", f_address);
693 exit(EXIT_FAILURE);
694 }
695 }
697 if (do_get) {
698 #ifdef ENABLE_POP3
699 if ((mta_mode == MODE_NONE) || (mta_mode == MODE_RUNQUEUE)) {
700 set_identity(conf.orig_uid, "getting mail");
701 if (do_get_online) {
702 if (route_name != NULL) {
703 conf.online_detect = g_strdup("argument");
704 set_online_name(route_name);
705 }
706 get_online();
707 } else {
708 if (get_name)
709 get_from_name(get_name);
710 else
711 get_all();
712 }
713 } else {
714 logwrite(LOG_ALERT, "get (-g) only allowed alone or together with queue run (-q)\n");
715 }
716 #else
717 fprintf(stderr, "get (pop) support not compiled in\n");
718 #endif
719 }
721 switch (mta_mode) {
722 case MODE_DAEMON:
723 mode_daemon(do_listen, queue_interval, argv);
724 break;
725 case MODE_RUNQUEUE:
726 {
727 /* queue runs */
728 set_identity(conf.orig_uid, "queue run");
730 if (do_runq)
731 exit_code = queue_run() ? EXIT_SUCCESS : EXIT_FAILURE;
733 if (do_runq_online) {
734 if (route_name != NULL) {
735 conf.online_detect = g_strdup("argument");
736 set_online_name(route_name);
737 }
738 exit_code =
739 queue_run_online() ? EXIT_SUCCESS : EXIT_FAILURE;
740 }
741 }
742 break;
743 case MODE_GET_DAEMON:
744 #ifdef ENABLE_POP3
745 if (route_name != NULL) {
746 conf.online_detect = g_strdup("argument");
747 set_online_name(route_name);
748 }
749 mode_get_daemon(get_interval, argv);
750 #endif
751 break;
753 case MODE_SMTP:
754 #ifdef ENABLE_SMTP_SERVER
755 mode_smtp();
756 #else
757 fprintf(stderr, "smtp server support not compiled in\n");
758 #endif
759 break;
761 case MODE_LIST:
762 queue_list();
763 break;
765 case MODE_BI:
766 exit(EXIT_SUCCESS);
767 break; /* well... */
769 case MODE_MCMD:
770 if (strcmp(M_cmd, "rm") == 0) {
771 gboolean ok = FALSE;
773 set_euidgid(conf.mail_uid, conf.mail_gid, NULL, NULL);
775 if (is_privileged_user(conf.orig_uid)) {
776 for (; arg < argc; arg++) {
777 if (queue_delete(argv[arg]))
778 ok = TRUE;
779 }
780 } else {
781 struct passwd *pw = getpwuid(conf.orig_uid);
782 if (pw) {
783 for (; arg < argc; arg++) {
784 message *msg = msg_spool_read(argv[arg], FALSE);
785 #ifdef ENABLE_IDENT
786 if (((msg->received_host == NULL) && (msg->received_prot == PROT_LOCAL))
787 || is_in_netlist(msg->received_host, conf.ident_trusted_nets)) {
788 #else
789 if ((msg->received_host == NULL) && (msg->received_prot == PROT_LOCAL)) {
790 #endif
791 if (msg->ident) {
792 if (strcmp(pw->pw_name, msg->ident) == 0) {
793 if (queue_delete(argv[arg]))
794 ok = TRUE;
795 } else {
796 fprintf(stderr, "you do not own message id %s\n", argv[arg]);
797 }
798 } else
799 fprintf(stderr, "message %s does not have an ident.\n", argv[arg]);
800 } else {
801 fprintf(stderr, "message %s was not received locally or from a trusted network.\n", argv[arg]);
802 }
803 }
804 } else {
805 fprintf(stderr, "could not find a passwd entry for uid %d: %s\n", conf.orig_uid, strerror(errno));
806 }
807 }
808 exit(ok ? EXIT_SUCCESS : EXIT_FAILURE);
809 } else {
810 fprintf(stderr, "unknown command %s\n", M_cmd);
811 exit(EXIT_FAILURE);
812 }
813 break;
815 case MODE_ACCEPT:
816 {
817 guint accept_flags = (opt_t ? ACC_DEL_RCPTS | ACC_DEL_BCC | ACC_RCPT_FROM_HEAD : ACC_HEAD_FROM_RCPT)
818 | (opt_i ? ACC_NODOT_TERM : ACC_NODOT_RELAX);
819 mode_accept(return_path, full_sender_name, accept_flags, &(argv[arg]), argc - arg);
820 exit(exit_failure ? EXIT_FAILURE : EXIT_SUCCESS);
821 }
822 break;
823 case MODE_NONE:
824 break;
825 default:
826 fprintf(stderr, "unknown mode: %d\n", mta_mode);
827 break;
828 }
830 logclose();
832 exit(exit_code);
833 }