22 |
#endif |
#endif |
23 |
|
|
24 |
mailbox_t mbox; |
mailbox_t mbox; |
|
unsigned int timeout; |
|
25 |
int state; |
int state; |
26 |
char *username; |
char *username; |
|
char *maildir = MU_PATH_MAILDIR; |
|
27 |
FILE *ifile; |
FILE *ifile; |
28 |
FILE *ofile; |
FILE *ofile; |
29 |
char *md5shared; |
char *md5shared; |
|
/* Number of child processes. */ |
|
|
volatile size_t children; |
|
30 |
|
|
31 |
static struct option long_options[] = |
struct daemon_param daemon_param = { |
32 |
{ |
MODE_INTERACTIVE, /* Start in interactive (inetd) mode */ |
33 |
{"daemon", optional_argument, 0, 'd'}, |
20, /* Default maximum number of children */ |
34 |
{"help", no_argument, 0, 'h'}, |
110, /* Standard POP3 port */ |
35 |
{"inetd", no_argument, 0, 'i'}, |
600 /* Idle timeout */ |
|
{"maildir", required_argument, 0, 'm'}, |
|
|
{"port", required_argument, 0, 'p'}, |
|
|
{"timeout", required_argument, 0, 't'}, |
|
|
{"version", no_argument, 0, 'v'}, |
|
|
{0, 0, 0, 0} |
|
36 |
}; |
}; |
37 |
|
|
38 |
const char *short_options = "d::him:p:t:v"; |
/* Number of child processes. */ |
39 |
|
volatile size_t children; |
40 |
|
|
41 |
static int pop3d_mainloop __P ((int, int)); |
static int pop3d_mainloop __P ((int, int)); |
42 |
static void pop3d_daemon_init __P ((void)); |
static void pop3d_daemon_init __P ((void)); |
43 |
static void pop3d_daemon __P ((unsigned int, unsigned int)); |
static void pop3d_daemon __P ((unsigned int, unsigned int)); |
44 |
static void pop3d_usage __P ((char *)); |
static void pop3d_usage __P ((char *)); |
45 |
|
|
46 |
#ifndef DEFMAXCHILDREN |
const char *argp_program_version = "pop3d (" PACKAGE ") " VERSION; |
47 |
# define DEFMAXCHILDREN 10 /* Default maximum number of children */ |
const char *argp_program_bug_address = "<bug-mailutils@gnu.org>"; |
48 |
#endif |
static char doc[] = "GNU pop3d -- the POP3 daemon"; |
49 |
|
|
50 |
|
static struct argp argp = { |
51 |
|
NULL, |
52 |
|
NULL, |
53 |
|
NULL, |
54 |
|
doc, |
55 |
|
mu_daemon_argp_child, |
56 |
|
NULL, NULL |
57 |
|
}; |
58 |
|
|
59 |
|
|
60 |
int |
int |
61 |
main (int argc, char **argv) |
main (int argc, char **argv) |
62 |
{ |
{ |
63 |
struct group *gr; |
struct group *gr; |
|
static int mode = INTERACTIVE; |
|
|
size_t maxchildren = DEFMAXCHILDREN; |
|
|
int c = 0; |
|
64 |
int status = OK; |
int status = OK; |
|
unsigned int port; |
|
65 |
|
|
66 |
port = 110; /* Default POP3 port. */ |
mu_create_argcv (argc, argv, &argc, &argv); |
67 |
timeout = 600; /* Default timeout of 600. */ |
argp_parse (&argp, argc, argv, 0, 0, &daemon_param); |
|
|
|
|
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; |
|
|
} |
|
|
} |
|
68 |
|
|
69 |
maildir = mu_normalize_maildir (maildir); |
maildir = mu_normalize_maildir (maildir); |
70 |
if (!maildir) |
if (!maildir) |
116 |
signal (SIGPIPE, pop3d_signal); |
signal (SIGPIPE, pop3d_signal); |
117 |
signal (SIGABRT, pop3d_signal); |
signal (SIGABRT, pop3d_signal); |
118 |
|
|
119 |
if (mode == DAEMON) |
if (daemon_param.mode == MODE_DAEMON) |
120 |
pop3d_daemon_init (); |
pop3d_daemon_init (); |
121 |
else |
else |
122 |
{ |
{ |
125 |
} |
} |
126 |
|
|
127 |
/* Set up for syslog. */ |
/* Set up for syslog. */ |
128 |
openlog ("gnu-pop3d", LOG_PID, LOG_FACILITY); |
openlog ("gnu-pop3d", LOG_PID, log_facility); |
129 |
/* Redirect any stdout error from the library to syslog, they |
/* Redirect any stdout error from the library to syslog, they |
130 |
should not go to the client. */ |
should not go to the client. */ |
131 |
mu_error_set_print (mu_syslog_error_printer); |
mu_error_set_print (mu_syslog_error_printer); |
133 |
umask (S_IROTH | S_IWOTH | S_IXOTH); /* 007 */ |
umask (S_IROTH | S_IWOTH | S_IXOTH); /* 007 */ |
134 |
|
|
135 |
/* Actually run the daemon. */ |
/* Actually run the daemon. */ |
136 |
if (mode == DAEMON) |
if (daemon_param.mode == MODE_DAEMON) |
137 |
pop3d_daemon (maxchildren, port); |
pop3d_daemon (daemon_param.maxchildren, daemon_param.port); |
138 |
/* exit (EXIT_SUCCESS) -- no way out of daemon except a signal. */ |
/* exit (EXIT_SUCCESS) -- no way out of daemon except a signal. */ |
139 |
else |
else |
140 |
status = pop3d_mainloop (fileno (stdin), fileno (stdout)); |
status = pop3d_mainloop (fileno (stdin), fileno (stdout)); |
405 |
} |
} |
406 |
} |
} |
407 |
|
|
|
/* Prints out usage information and exits the program */ |
|
408 |
|
|
|
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); |
|
|
} |
|
409 |
|
|
410 |
|
|