comparison src/masqmail.c @ 367:b27f66555ba8

Reformated multiline comments to have leading asterisks on each line Now we use: /* ** comment */ This makes the indent style simpler, too.
author markus schnalke <meillo@marmaro.de>
date Thu, 20 Oct 2011 10:20:59 +0200
parents 41958685480d
children 5781ba87df95
comparison
equal deleted inserted replaced
366:41958685480d 367:b27f66555ba8
1 /* MasqMail 1 /*
2 Copyright (C) 1999-2001 Oliver Kurth 2 ** MasqMail
3 Copyright (C) 2010 markus schnalke <meillo@marmaro.de> 3 ** Copyright (C) 1999-2001 Oliver Kurth
4 4 ** Copyright (C) 2010 markus schnalke <meillo@marmaro.de>
5 This program is free software; you can redistribute it and/or modify 5 **
6 it under the terms of the GNU General Public License as published by 6 ** This program is free software; you can redistribute it and/or modify
7 the Free Software Foundation; either version 2 of the License, or 7 ** it under the terms of the GNU General Public License as published by
8 (at your option) any later version. 8 ** the Free Software Foundation; either version 2 of the License, or
9 9 ** (at your option) any later version.
10 This program is distributed in the hope that it will be useful, 10 **
11 but WITHOUT ANY WARRANTY; without even the implied warranty of 11 ** This program is distributed in the hope that it will be useful,
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
13 GNU General Public License for more details. 13 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 14 ** GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License 15 **
16 along with this program; if not, write to the Free Software 16 ** You should have received a copy of the GNU General Public License
17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 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.
18 */ 19 */
19 20
20 #include <stdio.h> 21 #include <stdio.h>
21 #include <errno.h> 22 #include <errno.h>
22 #include <stdlib.h> 23 #include <stdlib.h>
32 33
33 #include <glib.h> 34 #include <glib.h>
34 35
35 #include "masqmail.h" 36 #include "masqmail.h"
36 37
37 /* mutually exclusive modes. Note that there is no 'queue daemon' mode. 38 /*
38 It, as well as the distinction beween the two (non exclusive) daemon 39 ** mutually exclusive modes. Note that there is no 'queue daemon' mode.
39 (queue and listen) modes, is handled by flags.*/ 40 ** It, as well as the distinction beween the two (non exclusive) daemon
41 ** (queue and listen) modes, is handled by flags.
42 */
40 enum mta_mode { 43 enum mta_mode {
41 MODE_NONE = 0, /* to check if a mode was set */ 44 MODE_NONE = 0, /* to check if a mode was set */
42 MODE_ACCEPT, /* accept message on stdin (fallback mode) */ 45 MODE_ACCEPT, /* accept message on stdin (fallback mode) */
43 MODE_DAEMON, /* run as daemon */ 46 MODE_DAEMON, /* run as daemon */
44 MODE_RUNQUEUE, /* single queue run, online or offline */ 47 MODE_RUNQUEUE, /* single queue run, online or offline */
93 return FALSE; 96 return FALSE;
94 } 97 }
95 #endif 98 #endif
96 99
97 /* 100 /*
98 argv: the original argv 101 ** argv: the original argv
99 argp: number of arg (may get modified!) 102 ** argp: number of arg (may get modified!)
100 cp: pointing to the char after the option 103 ** cp: pointing to the char after the option
101 e.g. `-d 6' `-d6' 104 ** e.g. `-d 6' `-d6'
102 ^ ^ 105 ** ^ ^
103 */ 106 */
104 gchar* 107 gchar*
105 get_optarg(char *argv[], gint *argp, char *cp) 108 get_optarg(char *argv[], gint *argp, char *cp)
106 { 109 {
107 if (*cp) { 110 if (*cp) {
159 signal(SIGTERM, sigterm_handler); 162 signal(SIGTERM, sigterm_handler);
160 write_pidfile(PIDFILEDIR "/masqmail.pid"); 163 write_pidfile(PIDFILEDIR "/masqmail.pid");
161 164
162 conf.do_verbose = FALSE; 165 conf.do_verbose = FALSE;
163 166
164 /* closing and reopening the log ensures that it is open afterwards 167 /*
165 because it is possible that the log is assigned to fd 1 and gets 168 ** closing and reopening the log ensures that it is open afterwards
166 thus closes by fclose(stdout). Similar for the debugfile. 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.
167 */ 171 */
168 logclose(); 172 logclose();
169 fclose(stdin); 173 fclose(stdin);
170 fclose(stdout); 174 fclose(stdout);
171 fclose(stderr); 175 fclose(stderr);
202 smtp_in(stdin, stderr, peername, NULL); 206 smtp_in(stdin, stderr, peername, NULL);
203 } 207 }
204 208
205 /* default mode if address args or -t is specified, or called as rmail */ 209 /* default mode if address args or -t is specified, or called as rmail */
206 static void 210 static void
207 mode_accept(address *return_path, gchar *full_sender_name, guint accept_flags, char **addresses, int addr_cnt) 211 mode_accept(address *return_path, gchar *full_sender_name, guint accept_flags,
212 char **addresses, int addr_cnt)
208 { 213 {
209 /* accept message on stdin */ 214 /* accept message on stdin */
210 accept_error err; 215 accept_error err;
211 message *msg = create_message(); 216 message *msg = create_message();
212 gint i; 217 gint i;
291 fclose(stderr); 296 fclose(stderr);
292 if (deliver(msg)) { 297 if (deliver(msg)) {
293 exit(0); 298 exit(0);
294 } else { 299 } else {
295 /* 300 /*
296 TODO: 301 ** TODO: Should we really fail here? Because the
297 Should we really fail here? Because the mail is queued 302 ** mail is queued already. If we fail the client
298 already. If we fail the client might submit it again. 303 ** might submit it again. If at-once-delivery
299 If at-once-delivery is seen as an additional best-effort 304 ** is seen as an additional best-effort service,
300 service, then we should still exit successful here. 305 ** then we should still exit successful here.
301 */ 306 */
302 exit(1); 307 exit(1);
303 } 308 }
304 } 309 }
305 } 310 }
306 311
307 /* 312 /*
308 if -Mrm is given 313 ** if -Mrm is given
309 314 **
310 currently only the `rm' command is supported 315 ** currently only the `rm' command is supported
311 until this changes, we don't need any facility for further commands 316 ** until this changes, we don't need any facility for further commands
312 return success if at least one message had been deleted 317 ** return success if at least one message had been deleted
313 */ 318 */
314 static int 319 static int
315 manipulate_queue(char *cmd, char *id[]) 320 manipulate_queue(char *cmd, char *id[])
316 { 321 {
317 gboolean ok = FALSE; 322 gboolean ok = FALSE;
385 390
386 if (do_runq_online) { 391 if (do_runq_online) {
387 if (route_name) { 392 if (route_name) {
388 conf.online_query = g_strdup_printf("/bin/echo %s", route_name); 393 conf.online_query = g_strdup_printf("/bin/echo %s", route_name);
389 } 394 }
390 /* TODO: change behavior of `-qo without argument'? 395 /*
391 Because that behavior is included in -q. */ 396 ** TODO: change behavior of `-qo without argument'?
397 ** Because that behavior is included in -q.
398 */
392 ret = queue_run_online(); 399 ret = queue_run_online();
393 } 400 }
394 return ret; 401 return ret;
395 } 402 }
396 403
410 #endif 417 #endif
411 #ifdef ENABLE_IDENT 418 #ifdef ENABLE_IDENT
412 with_ident = " +ident"; 419 with_ident = " +ident";
413 #endif 420 #endif
414 421
415 printf("%s %s%s%s%s\n", PACKAGE, VERSION, with_resolver, with_auth, with_ident); 422 printf("%s %s%s%s%s\n", PACKAGE, VERSION, with_resolver, with_auth,
423 with_ident);
416 } 424 }
417 425
418 void 426 void
419 set_mode(enum mta_mode mode) 427 set_mode(enum mta_mode mode)
420 { 428 {
460 mta_mode = MODE_MCMD; 468 mta_mode = MODE_MCMD;
461 M_cmd = "rm"; 469 M_cmd = "rm";
462 } else if (strcmp(progname, "newaliases") == 0) { 470 } else if (strcmp(progname, "newaliases") == 0) {
463 mta_mode = MODE_BI; 471 mta_mode = MODE_BI;
464 } else if (strcmp(progname, "rmail") == 0) { 472 } else if (strcmp(progname, "rmail") == 0) {
465 /* the `rmail' alias should probably be removed now 473 /*
466 that we have the rmail script. But let's keep it 474 ** the `rmail' alias should probably be removed now
467 for some while for compatibility. 2010-06-19 */ 475 ** that we have the rmail script. But let's keep it
476 ** for some while for compatibility. 2010-06-19
477 */
468 mta_mode = MODE_ACCEPT; 478 mta_mode = MODE_ACCEPT;
469 opt_i = TRUE; 479 opt_i = TRUE;
470 } else if (strcmp(progname, "runq") == 0) { 480 } else if (strcmp(progname, "runq") == 0) {
471 mta_mode = MODE_RUNQUEUE; 481 mta_mode = MODE_RUNQUEUE;
472 do_runq = TRUE; 482 do_runq = TRUE;
599 } 609 }
600 } 610 }
601 611
602 if (!mta_mode && arg==argc && !opt_t) { 612 if (!mta_mode && arg==argc && !opt_t) {
603 /* 613 /*
604 In this case no rcpts can be found, thus no mail 614 ** In this case no rcpts can be found, thus no mail
605 can be sent, thus masqmail will always fail. We 615 ** can be sent, thus masqmail will always fail. We
606 rather do something better instead. This covers 616 ** rather do something better instead. This covers
607 also the case of calling masqmail without args. 617 ** also the case of calling masqmail without args.
608 */ 618 */
609 mode_version(); 619 mode_version();
610 exit(0); 620 exit(0);
611 } 621 }
612 622
636 } 646 }
637 } 647 }
638 648
639 init_conf(); 649 init_conf();
640 650
641 /* if we are not privileged, and the config file was changed we 651 /*
642 implicetely set the the run_as_user flag and give up all 652 ** if we are not privileged, and the config file was changed we
643 privileges. 653 ** implicetely set the the run_as_user flag and give up all
644 654 ** privileges.
645 So it is possible for a user to run his own daemon without 655 **
646 breaking security. 656 ** So it is possible for a user to run his own daemon without
647 */ 657 ** breaking security.
658 */
648 if ((strcmp(conf_file, CONF_FILE) != 0) && (conf.orig_uid != 0)) { 659 if ((strcmp(conf_file, CONF_FILE) != 0) && (conf.orig_uid != 0)) {
649 conf.run_as_user = TRUE; 660 conf.run_as_user = TRUE;
650 set_euidgid(conf.orig_uid, conf.orig_gid, NULL, NULL); 661 set_euidgid(conf.orig_uid, conf.orig_gid, NULL, NULL);
651 if (setgid(conf.orig_gid)) { 662 if (setgid(conf.orig_gid)) {
652 logwrite(LOG_ALERT, "could not set gid to %d: %s\n", conf.orig_gid, strerror(errno)); 663 logwrite(LOG_ALERT, "could not set gid to %d: %s\n", conf.orig_gid, strerror(errno));
675 } 686 }
676 if (debug_level >= 0) { /* if >= 0, it was given by argument */ 687 if (debug_level >= 0) { /* if >= 0, it was given by argument */
677 conf.debug_level = debug_level; 688 conf.debug_level = debug_level;
678 } 689 }
679 690
680 /* It appears that changing to / ensures that we are never in 691 /*
681 a directory which we cannot access. This situation could be 692 ** It appears that changing to / ensures that we are never in
682 possible after changing identity. 693 ** a directory which we cannot access. This situation could be
683 Maybe we should only change to / if we not run as user, to 694 ** possible after changing identity.
684 allow relative paths for log files in test setups for 695 ** Maybe we should only change to / if we not run as user, to
685 instance. 696 ** allow relative paths for log files in test setups for
697 ** instance.
686 */ 698 */
687 chdir("/"); 699 chdir("/");
688 700
689 if (!conf.run_as_user) { 701 if (!conf.run_as_user) {
690 if (setgid(0) != 0) { 702 if (setgid(0) != 0) {