masqmail-0.2

view src/masqmail.c @ 10:26e34ae9a3e3

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