diff options
-rw-r--r-- | comsat/comsat.c | 117 | ||||
-rw-r--r-- | imap4d/imap4d.c | 160 | ||||
-rw-r--r-- | mail.local/main.c | 203 | ||||
-rw-r--r-- | pop3d/pop3d.c | 118 |
4 files changed, 238 insertions, 360 deletions
diff --git a/comsat/comsat.c b/comsat/comsat.c index 540dab29e..2a00c3547 100644 --- a/comsat/comsat.c +++ b/comsat/comsat.c @@ -47,22 +47,26 @@ typedef struct utmp UTMP; #define MAX_TTY_SIZE (sizeof (PATH_TTY_PFX) + sizeof (((UTMP*)0)->ut_line)) -static char short_options[] = "c:dhim:p:t:v"; -static struct option long_options[] = +const char *argp_program_version = "comsatd (" PACKAGE ") " VERSION; +const char *argp_program_bug_address = "<bug-mailutils@gnu.org>"; +static char doc[] = "GNU comsatd"; + +static struct argp_option options[] = { - {"config", required_argument, 0, 'c'}, - {"daemon", no_argument, 0, 'd'}, - {"help", no_argument, 0, 'h'}, - {"inetd", no_argument, 0, 'i'}, - {"maildir", required_argument, 0, 'm'}, - {"port", required_argument, 0, 'p'}, - {"timeout", required_argument, 0, 't'}, - {"version", no_argument, 0, 'v'}, - {0, 0, 0, 0} + {"config", 'c', "FILE", 0, "Read configuration from FILE", 0}, + { NULL, 0, NULL, 0, NULL, 0 } }; -#define MODE_INETD 0 -#define MODE_DAEMON 1 +static error_t comsatd_parse_opt (int key, char *arg, struct argp_state *state); + +static struct argp argp = { + options, + comsatd_parse_opt, + NULL, + doc, + mu_daemon_argp_child, + NULL, NULL +}; #define SUCCESS 0 #define NOT_HERE 1 @@ -72,13 +76,16 @@ static struct option long_options[] = # define MAXHOSTNAMELEN 64 #endif -int mode = MODE_INETD; -int port = 512; /* Default biff port */ -int timeout = 0; +struct daemon_param daemon_param = { + MODE_INTERACTIVE, /* Start in interactive (inetd) mode */ + 20, /* Default maximum number of children. + Currently unused */ + 512, /* Default biff port */ + 0, /* Default timeout */ +}; int maxlines = 5; char hostname[MAXHOSTNAMELEN]; const char *username; -const char *maildir = MU_PATH_MAILDIR; static void comsat_init (void); static void comsat_daemon_init (void); @@ -92,55 +99,35 @@ static void change_user (const char *user); static int xargc; static char **xargv; +char *config_file = NULL; + +static error_t +comsatd_parse_opt (int key, char *arg, struct argp_state *state) +{ + switch (key) + { + case ARGP_KEY_INIT: + state->child_inputs[0] = state->input; + break; + + case 'c': + config_file = arg; + break; + + default: + return ARGP_ERR_UNKNOWN; + } + return 0; +} + int main(int argc, char **argv) { int c; - char *config_file = NULL; - - while ((c = getopt_long (argc, argv, short_options, long_options, NULL)) - != -1) - { - switch (c) - { - case 'c': - config_file = optarg; - break; - - case 'd': - mode = MODE_DAEMON; - break; - - case 'h': - help (); - /*NOTREACHED*/ - - case 'i': - mode = MODE_INETD; - break; - - case 'm': - maildir = optarg; - break; - - case 'p': - port = strtoul (optarg, NULL, 10); - break; - - case 't': - timeout = strtoul (optarg, NULL, 10); - break; - - case 'v': - printf (IMPL " ("PACKAGE " " VERSION ")\n"); - exit (EXIT_SUCCESS); - break; - - default: - exit (EXIT_FAILURE); - } - } + + mu_create_argcv (argc, argv, &argc, &argv); + argp_parse (&argp, argc, argv, 0, 0, &daemon_param); maildir = mu_normalize_maildir (maildir); if (!maildir) @@ -149,7 +136,7 @@ main(int argc, char **argv) exit (1); } - if (timeout > 0 && mode == MODE_DAEMON) + if (daemon_param.timeout > 0 && daemon_param.mode == MODE_DAEMON) { fprintf (stderr, "--timeout and --daemon are incompatible\n"); exit (EXIT_FAILURE); @@ -157,7 +144,7 @@ main(int argc, char **argv) comsat_init (); - if (mode == MODE_DAEMON) + if (daemon_param.mode == MODE_DAEMON) { /* Preserve invocation arguments */ xargc = argc; @@ -174,8 +161,8 @@ main(int argc, char **argv) chdir ("/"); - if (mode == MODE_DAEMON) - comsat_daemon (port); + if (daemon_param.mode == MODE_DAEMON) + comsat_daemon (daemon_param.port); else c = comsat_main (0); diff --git a/imap4d/imap4d.c b/imap4d/imap4d.c index a8527d0b8..96043f7ea 100644 --- a/imap4d/imap4d.c +++ b/imap4d/imap4d.c @@ -16,112 +16,87 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ #include "imap4d.h" - #ifdef HAVE_MYSQL # include "../MySql/MySql.h" #endif FILE *ofile; -unsigned int timeout = 1800; /* RFC2060: 30 minutes, if enable. */ mailbox_t mbox; char *homedir; -char *maildir = MU_PATH_MAILDIR; int state = STATE_NONAUTH; +struct daemon_param daemon_param = { + MODE_INTERACTIVE, /* Start in interactive (inetd) mode */ + 20, /* Default maximum number of children */ + 143, /* Standard IMAP4 port */ + 1800 /* RFC2060: 30 minutes. */ +}; + /* Number of child processes. */ volatile size_t children; -static struct option long_options[] = +const char *argp_program_version = "imap4d (" PACKAGE ") " VERSION; +const char *argp_program_bug_address = "<bug-mailutils@gnu.org>"; +static char doc[] = "GNU imap4d -- the IMAP4D daemon"; + +static struct argp_option options[] = { - {"daemon", optional_argument, 0, 'd'}, - {"help", no_argument, 0, 'h'}, - {"inetd", no_argument, 0, 'i'}, - {"maildir", required_argument, 0, 'm'}, - {"port", required_argument, 0, 'p'}, - {"other-namespace", required_argument, 0, 'O'}, - {"shared-namespace", required_argument, 0, 'S'}, - {"timeout", required_argument, 0, 't'}, - {"version", no_argument, 0, 'v'}, - {0, 0, 0, 0} + {"other-namespace", 'O', "PATHLIST", 0, + "set the `other' namespace", 0}, + {"shared-namespace", 'S', "PATHLIST", 0, + "set the `shared' namespace", 0}, + { NULL, 0, NULL, 0, NULL, 0 } }; -const char *short_options ="d::him:p:t:vO:P:S:"; +static error_t imap4d_parse_opt (int key, char *arg, struct argp_state *state); + +static struct argp argp = { + options, + imap4d_parse_opt, + NULL, + doc, + mu_daemon_argp_child, + NULL, NULL +}; static int imap4d_mainloop __P ((int, int)); static void imap4d_daemon_init __P ((void)); static void imap4d_daemon __P ((unsigned int, unsigned int)); static int imap4d_mainloop __P ((int, int)); -static void imap4d_usage __P ((char *)); -#ifndef DEFMAXCHILDREN -# define DEFMAXCHILDREN 20 /* Default maximum number of children */ -#endif +static error_t +imap4d_parse_opt (int key, char *arg, struct argp_state *state) +{ + switch (key) + { + case ARGP_KEY_INIT: + state->child_inputs[0] = state->input; + break; + + case 'O': + set_namespace (NS_OTHER, arg); + break; + + case 'S': + set_namespace (NS_SHARED, arg); + break; + + default: + return ARGP_ERR_UNKNOWN; + } + return 0; +} int main (int argc, char **argv) { struct group *gr; - static int mode = INTERACTIVE; - size_t maxchildren = DEFMAXCHILDREN; - int c = 0; int status = EXIT_SUCCESS; - unsigned int port; - port = 143; /* Default IMAP4 port. */ - timeout = 1800; /* RFC2060: 30 minutes, if enable. */ state = STATE_NONAUTH; /* Starting state in non-auth. */ - while ((c = getopt_long (argc, argv, short_options, long_options, NULL)) - != -1) - { - switch (c) - { - case 'd': - mode = DAEMON; - if (optarg) - maxchildren = strtoul (optarg, NULL, 10); - if (maxchildren == 0) - maxchildren = DEFMAXCHILDREN; - break; - - case 'h': - imap4d_usage (argv[0]); - break; - - case 'i': - mode = INTERACTIVE; - break; - - case 'm': - maildir = optarg; - break; - - case 'p': - mode = DAEMON; - port = strtoul (optarg, NULL, 10); - break; - - case 'O': - set_namespace (NS_OTHER, optarg); - break; - - case 'S': - set_namespace (NS_SHARED, optarg); - break; - - case 't': - timeout = strtoul (optarg, NULL, 10); - break; - - case 'v': - printf ("GNU imap4 daemon" "("PACKAGE " " VERSION ")\n"); - exit (0); - break; - - default: - break; - } - } + mu_create_argcv (argc, argv, &argc, &argv); + argp_parse (&argp, argc, argv, 0, 0, &daemon_param); maildir = mu_normalize_maildir (maildir); if (!maildir) @@ -172,7 +147,7 @@ main (int argc, char **argv) /*signal (SIGPIPE, SIG_IGN); */ signal (SIGABRT, imap4d_signal); - if (mode == DAEMON) + if (daemon_param.mode == MODE_DAEMON) imap4d_daemon_init (); else { @@ -181,7 +156,7 @@ main (int argc, char **argv) } /* Set up for syslog. */ - openlog ("gnu-imap4d", LOG_PID, LOG_FACILITY); + openlog ("gnu-imap4d", LOG_PID, log_facility); /* Redirect any stdout error from the library to syslog, they should not go to the client. */ @@ -190,8 +165,8 @@ main (int argc, char **argv) umask (S_IROTH | S_IWOTH | S_IXOTH); /* 007 */ /* Actually run the daemon. */ - if (mode == DAEMON) - imap4d_daemon (maxchildren, port); + if (daemon_param.mode == MODE_DAEMON) + imap4d_daemon (daemon_param.maxchildren, daemon_param.port); /* exit (0) -- no way out of daemon except a signal. */ else status = imap4d_mainloop (fileno (stdin), fileno (stdout)); @@ -353,30 +328,5 @@ imap4d_daemon (unsigned int maxchildren, unsigned int port) } } -/* Prints out usage information and exits the program */ - -static void -imap4d_usage (char *argv0) -{ - printf ("Usage: %s [OPTIONS]\n", argv0); - printf ("Runs the GNU IMAP4 daemon.\n\n"); - printf (" -d, --daemon[=MAXCHILDREN] runs in daemon mode with a maximum\n"); - printf (" of MAXCHILDREN child processes\n"); - printf (" MAXCHILDREN defaults to %d\n", - DEFMAXCHILDREN); - printf (" -h, --help display this help and exit\n"); - printf (" -i, --inetd runs in inetd mode (default)\n"); - printf (" -p, --port=PORT specifies port to listen on, implies -d\n" -); - printf (" defaults to 143, which need not be specified\n"); - printf (" -m, --maildir=PATH set path to the mailspool directory\n"); - printf (" -O, --other-namespace=PATHLIST sets the `other' namespace\n"); - printf (" -S, --shared-namespace=PATHLIST sets the `shared' namespace\n"); - printf (" -t, --timeout=TIMEOUT sets idle timeout to TIMEOUT seconds\n"); - printf (" TIMEOUT default is 1800 (30 minutes)\n"); - printf (" -v, --version display version information and exit\n"); - printf ("\nReport bugs to bug-mailutils@gnu.org\n"); - exit (0); -} diff --git a/mail.local/main.c b/mail.local/main.c index f8f3e6a1d..93bbeafa5 100644 --- a/mail.local/main.c +++ b/mail.local/main.c @@ -22,7 +22,6 @@ int multiple_delivery; int ex_quota_tempfail; int exit_code = EX_OK; uid_t uid; -char *maildir = MU_PATH_MAILDIR; char *quotadbname = NULL; int lock_timeout = 300; @@ -40,73 +39,86 @@ void guess_retval (int ec); void mailer_err (char *fmt, ...); void notify_biff (mailbox_t mbox, char *name, size_t size); -char short_opts[] = "hf:Llm:q:r:s:x::vW;"; - -static struct option long_opts[] = { - { "ex-multiple-delivery-success", no_argument, &multiple_delivery, 1 }, - { "ex-quota-tempfail", no_argument, &ex_quota_tempfail, 1 }, - { "from", required_argument, 0, 'f' }, - { "help", no_argument, 0, 'h' }, - { "license", no_argument, 0, 'L' }, - { "maildir", required_argument, 0, 'm' }, - { "quota-db", required_argument, 0, 'q' }, - { "source", required_argument, 0, 's' }, - { "timeout", required_argument, 0, 't' }, - { "debug", optional_argument, 0, 'x' }, - { "version", no_argument, 0, 'v' }, - { 0, 0, 0, 0 } +const char *argp_program_version = "mail.local (" PACKAGE ") " VERSION; +const char *argp_program_bug_address = "<bug-mailutils@gnu.org>"; +static char doc[] = "GNU mail.local -- the local MDA"; +static char args_doc[] = "recipient [recipient ...]"; + +#define ARG_MULTIPLE_DELIVERY 1 +#define ARG_QUOTA_TEMPFAIL 2 + +static struct argp_option options[] = +{ + { "ex-multiple-delivery-success", ARG_MULTIPLE_DELIVERY, NULL, 0, + "Don't return errors when delivering to multiple recipients", 0 }, + { "ex-quota-tempfail", ARG_QUOTA_TEMPFAIL, NULL, 0, + "Return temporary failure if disk or mailbox quota is exceeded", 0 }, + { "from", 'f', "EMAIL", 0, + "Specify the sender's name" }, + { NULL, 'r', NULL, OPTION_ALIAS, NULL }, +#ifdef USE_DBM + { "quota-db", 'q', "FILE", 0, + "Specify path to quota database", 0 }, +#endif +#ifdef WITH_GUILE + { "source", 's', "PATTERN", 0, + "Set name pattern for user-defined mail filters", 0 }, +#endif + { "debug", 'x', +#ifdef WITH_GUILE + "{NUMBER|guile}", +#else + "NUMBER", +#endif + 0, + "Enable debugging", 0 }, + { "timeout", 't', "NUMBER", 0, + "Set timeout for acquiring the lockfile" }, + + { NULL, 0, NULL, 0, NULL, 0 } }; - -int -main (int argc, char *argv[]) +static error_t parse_opt (int key, char *arg, struct argp_state *state); + +static struct argp argp = { + options, + parse_opt, + args_doc, + doc, + mu_common_argp_child, + NULL, NULL +}; + +char *from = NULL; +char *progfile_pattern = NULL; + +static error_t +parse_opt (int key, char *arg, struct argp_state *state) { - int c; - FILE *fp; - char *from = NULL; - char *progfile_pattern = NULL; - char *tempfile = NULL; - - /* Preparative work: close inherited fds, force a reasonable umask - and prepare a logging. */ - close_fds (); - umask (0077); + switch (key) + { + case ARG_MULTIPLE_DELIVERY: + multiple_delivery = 1; + break; - openlog ("mail.local", LOG_PID, LOG_FACILITY); - mu_error_set_print (mu_syslog_error_printer); - - uid = getuid (); - while ((c = getopt_long (argc, argv, short_opts, long_opts, NULL)) != EOF) - switch (c) - { - case 0: /* option already handled */ - break; - case 'r': - case 'f': - if (from != NULL) - { - mu_error ("multiple --from options"); - return EX_USAGE; - } - from = optarg; - break; + case ARG_QUOTA_TEMPFAIL: + ex_quota_tempfail = 1; + break; - case 'h': - print_help (); - break; - - case 'L': - print_license (); - break; + case 'r': + case 'f': + if (from != NULL) + { + mu_error ("multiple --from options"); + return EX_USAGE; + } + from = arg; + break; - case 'm': - maildir = optarg; - break; - #ifdef USE_DBM - case 'q': - quotadbname = optarg; - break; + case 'q': + quotadbname = arg; + break; #endif #ifdef WITH_GUILE @@ -127,7 +139,7 @@ main (int argc, char *argv[]) debug_guile = 1; else #endif - debug_level = strtoul (optarg, NULL, 0); + debug_level = strtoul (optarg, NULL, 0); } else { @@ -137,17 +149,38 @@ main (int argc, char *argv[]) #endif } break; - - case 'v': - print_version (); - break; - - default: - return EX_USAGE; - } - argc -= optind; - argv += optind; + default: + return ARGP_ERR_UNKNOWN; + + case ARGP_KEY_ERROR: + exit (EX_USAGE); + } + return 0; +} + +int +main (int argc, char *argv[]) +{ + FILE *fp; + char *tempfile = NULL; + int arg_index; + + /* Preparative work: close inherited fds, force a reasonable umask + and prepare a logging. */ + close_fds (); + umask (0077); + + mu_create_argcv (argc, argv, &argc, &argv); + argp_parse (&argp, argc, argv, 0, &arg_index, NULL); + + openlog ("mail.local", LOG_PID, log_facility); + mu_error_set_print (mu_syslog_error_printer); + + uid = getuid (); + + argc -= arg_index; + argv += arg_index; if (!argc) print_help (); @@ -729,31 +762,5 @@ static char help_message[] = exit (0); } -void -print_license () -{ - static char license_text[] = - " This program is free software; you can redistribute it and/or modify\n" - " it under the terms of the GNU General Public License as published by\n" - " the Free Software Foundation; either version 2, or (at your option)\n" - " any later version.\n" - "\n" - " This program is distributed in the hope that it will be useful,\n" - " but WITHOUT ANY WARRANTY; without even the implied warranty of\n" - " MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n" - " GNU General Public License for more details.\n" - "\n" - " You should have received a copy of the GNU General Public License\n" - " along with this program; if not, write to the Free Software\n" - " Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.\n"; - printf ("%s", license_text); - exit (0); -} -void -print_version () -{ - printf ("mail.local ("PACKAGE " " VERSION ")\n"); - exit (0); -} diff --git a/pop3d/pop3d.c b/pop3d/pop3d.c index 2b8e1c7ca..17e53bc24 100644 --- a/pop3d/pop3d.c +++ b/pop3d/pop3d.c @@ -22,95 +22,49 @@ #endif mailbox_t mbox; -unsigned int timeout; int state; char *username; -char *maildir = MU_PATH_MAILDIR; FILE *ifile; FILE *ofile; char *md5shared; -/* Number of child processes. */ -volatile size_t children; -static struct option long_options[] = -{ - {"daemon", optional_argument, 0, 'd'}, - {"help", no_argument, 0, 'h'}, - {"inetd", no_argument, 0, 'i'}, - {"maildir", required_argument, 0, 'm'}, - {"port", required_argument, 0, 'p'}, - {"timeout", required_argument, 0, 't'}, - {"version", no_argument, 0, 'v'}, - {0, 0, 0, 0} +struct daemon_param daemon_param = { + MODE_INTERACTIVE, /* Start in interactive (inetd) mode */ + 20, /* Default maximum number of children */ + 110, /* Standard POP3 port */ + 600 /* Idle timeout */ }; -const char *short_options = "d::him:p:t:v"; +/* Number of child processes. */ +volatile size_t children; static int pop3d_mainloop __P ((int, int)); static void pop3d_daemon_init __P ((void)); static void pop3d_daemon __P ((unsigned int, unsigned int)); static void pop3d_usage __P ((char *)); -#ifndef DEFMAXCHILDREN -# define DEFMAXCHILDREN 10 /* Default maximum number of children */ -#endif +const char *argp_program_version = "pop3d (" PACKAGE ") " VERSION; +const char *argp_program_bug_address = "<bug-mailutils@gnu.org>"; +static char doc[] = "GNU pop3d -- the POP3 daemon"; + +static struct argp argp = { + NULL, + NULL, + NULL, + doc, + mu_daemon_argp_child, + NULL, NULL +}; + int main (int argc, char **argv) { struct group *gr; - static int mode = INTERACTIVE; - size_t maxchildren = DEFMAXCHILDREN; - int c = 0; int status = OK; - unsigned int port; - port = 110; /* Default POP3 port. */ - timeout = 600; /* Default timeout of 600. */ - - while ((c = getopt_long (argc, argv, short_options, long_options, NULL)) - != -1) - { - switch (c) - { - case 'd': - mode = DAEMON; - if (optarg) - maxchildren = strtoul (optarg, NULL, 10); - if (maxchildren == 0) - maxchildren = DEFMAXCHILDREN; - break; - - case 'h': - pop3d_usage (argv[0]); - break; - - case 'i': - mode = INTERACTIVE; - break; - - case 'm': - maildir = optarg; - break; - - case 'p': - mode = DAEMON; - port = strtoul (optarg, NULL, 10); - break; - - case 't': - timeout = strtoul (optarg, NULL, 10); - break; - - case 'v': - printf (IMPL " ("PACKAGE " " VERSION ")\n"); - exit (EXIT_SUCCESS); - break; - - default: - break; - } - } + mu_create_argcv (argc, argv, &argc, &argv); + argp_parse (&argp, argc, argv, 0, 0, &daemon_param); maildir = mu_normalize_maildir (maildir); if (!maildir) @@ -162,7 +116,7 @@ main (int argc, char **argv) signal (SIGPIPE, pop3d_signal); signal (SIGABRT, pop3d_signal); - if (mode == DAEMON) + if (daemon_param.mode == MODE_DAEMON) pop3d_daemon_init (); else { @@ -171,7 +125,7 @@ main (int argc, char **argv) } /* Set up for syslog. */ - openlog ("gnu-pop3d", LOG_PID, LOG_FACILITY); + openlog ("gnu-pop3d", LOG_PID, log_facility); /* Redirect any stdout error from the library to syslog, they should not go to the client. */ mu_error_set_print (mu_syslog_error_printer); @@ -179,8 +133,8 @@ main (int argc, char **argv) umask (S_IROTH | S_IWOTH | S_IXOTH); /* 007 */ /* Actually run the daemon. */ - if (mode == DAEMON) - pop3d_daemon (maxchildren, port); + if (daemon_param.mode == MODE_DAEMON) + pop3d_daemon (daemon_param.maxchildren, daemon_param.port); /* exit (EXIT_SUCCESS) -- no way out of daemon except a signal. */ else status = pop3d_mainloop (fileno (stdin), fileno (stdout)); @@ -451,26 +405,6 @@ pop3d_daemon (unsigned int maxchildren, unsigned int port) } } -/* Prints out usage information and exits the program */ -static void -pop3d_usage (char *argv0) -{ - printf ("Usage: %s [OPTIONS]\n", argv0); - printf ("Runs the GNU POP3 daemon.\n\n"); - printf (" -d, --daemon=MAXCHILDREN runs in daemon mode with a maximum\n"); - printf (" of MAXCHILDREN child processes\n"); - printf (" -h, --help display this help and exit\n"); - printf (" -i, --inetd runs in inetd mode (default)\n"); - printf (" -m, --maildir=PATH sets path to the mailspool directory\n"); - printf (" -p, --port=PORT specifies port to listen on, implies -d\n" -); - printf (" defaults to 110, which need not be specified\n"); - printf (" -t, --timeout=TIMEOUT sets idle timeout to TIMEOUT seconds\n"); - printf (" TIMEOUT default is 600 (10 minutes)\n"); - printf (" -v, --version display version information and exit\n"); - printf ("\nReport bugs to bug-mailutils@gnu.org\n"); - exit (EXIT_SUCCESS); -} |