16 |
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ |
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ |
17 |
|
|
18 |
#include "imap4d.h" |
#include "imap4d.h" |
|
|
|
19 |
#ifdef HAVE_MYSQL |
#ifdef HAVE_MYSQL |
20 |
# include "../MySql/MySql.h" |
# include "../MySql/MySql.h" |
21 |
#endif |
#endif |
22 |
|
|
23 |
FILE *ofile; |
FILE *ofile; |
|
unsigned int timeout = 1800; /* RFC2060: 30 minutes, if enable. */ |
|
24 |
mailbox_t mbox; |
mailbox_t mbox; |
25 |
char *homedir; |
char *homedir; |
|
char *maildir = MU_PATH_MAILDIR; |
|
26 |
int state = STATE_NONAUTH; |
int state = STATE_NONAUTH; |
27 |
|
|
28 |
|
struct daemon_param daemon_param = { |
29 |
|
MODE_INTERACTIVE, /* Start in interactive (inetd) mode */ |
30 |
|
20, /* Default maximum number of children */ |
31 |
|
143, /* Standard IMAP4 port */ |
32 |
|
1800 /* RFC2060: 30 minutes. */ |
33 |
|
}; |
34 |
|
|
35 |
/* Number of child processes. */ |
/* Number of child processes. */ |
36 |
volatile size_t children; |
volatile size_t children; |
37 |
|
|
38 |
static struct option long_options[] = |
const char *argp_program_version = "imap4d (" PACKAGE ") " VERSION; |
39 |
|
const char *argp_program_bug_address = "<bug-mailutils@gnu.org>"; |
40 |
|
static char doc[] = "GNU imap4d -- the IMAP4D daemon"; |
41 |
|
|
42 |
|
static struct argp_option options[] = |
43 |
{ |
{ |
44 |
{"daemon", optional_argument, 0, 'd'}, |
{"other-namespace", 'O', "PATHLIST", 0, |
45 |
{"help", no_argument, 0, 'h'}, |
"set the `other' namespace", 0}, |
46 |
{"inetd", no_argument, 0, 'i'}, |
{"shared-namespace", 'S', "PATHLIST", 0, |
47 |
{"maildir", required_argument, 0, 'm'}, |
"set the `shared' namespace", 0}, |
48 |
{"port", required_argument, 0, 'p'}, |
{ NULL, 0, NULL, 0, NULL, 0 } |
|
{"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} |
|
49 |
}; |
}; |
50 |
|
|
51 |
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); |
52 |
|
|
53 |
|
static struct argp argp = { |
54 |
|
options, |
55 |
|
imap4d_parse_opt, |
56 |
|
NULL, |
57 |
|
doc, |
58 |
|
mu_daemon_argp_child, |
59 |
|
NULL, NULL |
60 |
|
}; |
61 |
|
|
62 |
static int imap4d_mainloop __P ((int, int)); |
static int imap4d_mainloop __P ((int, int)); |
63 |
static void imap4d_daemon_init __P ((void)); |
static void imap4d_daemon_init __P ((void)); |
64 |
static void imap4d_daemon __P ((unsigned int, unsigned int)); |
static void imap4d_daemon __P ((unsigned int, unsigned int)); |
65 |
static int imap4d_mainloop __P ((int, int)); |
static int imap4d_mainloop __P ((int, int)); |
|
static void imap4d_usage __P ((char *)); |
|
66 |
|
|
67 |
#ifndef DEFMAXCHILDREN |
static error_t |
68 |
# define DEFMAXCHILDREN 20 /* Default maximum number of children */ |
imap4d_parse_opt (int key, char *arg, struct argp_state *state) |
69 |
#endif |
{ |
70 |
|
switch (key) |
71 |
|
{ |
72 |
|
case ARGP_KEY_INIT: |
73 |
|
state->child_inputs[0] = state->input; |
74 |
|
break; |
75 |
|
|
76 |
|
case 'O': |
77 |
|
set_namespace (NS_OTHER, arg); |
78 |
|
break; |
79 |
|
|
80 |
|
case 'S': |
81 |
|
set_namespace (NS_SHARED, arg); |
82 |
|
break; |
83 |
|
|
84 |
|
default: |
85 |
|
return ARGP_ERR_UNKNOWN; |
86 |
|
} |
87 |
|
return 0; |
88 |
|
} |
89 |
|
|
90 |
int |
int |
91 |
main (int argc, char **argv) |
main (int argc, char **argv) |
92 |
{ |
{ |
93 |
struct group *gr; |
struct group *gr; |
|
static int mode = INTERACTIVE; |
|
|
size_t maxchildren = DEFMAXCHILDREN; |
|
|
int c = 0; |
|
94 |
int status = EXIT_SUCCESS; |
int status = EXIT_SUCCESS; |
|
unsigned int port; |
|
95 |
|
|
|
port = 143; /* Default IMAP4 port. */ |
|
|
timeout = 1800; /* RFC2060: 30 minutes, if enable. */ |
|
96 |
state = STATE_NONAUTH; /* Starting state in non-auth. */ |
state = STATE_NONAUTH; /* Starting state in non-auth. */ |
97 |
|
|
98 |
while ((c = getopt_long (argc, argv, short_options, long_options, NULL)) |
mu_create_argcv (argc, argv, &argc, &argv); |
99 |
!= -1) |
argp_parse (&argp, argc, argv, 0, 0, &daemon_param); |
|
{ |
|
|
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; |
|
|
} |
|
|
} |
|
100 |
|
|
101 |
maildir = mu_normalize_maildir (maildir); |
maildir = mu_normalize_maildir (maildir); |
102 |
if (!maildir) |
if (!maildir) |
147 |
/*signal (SIGPIPE, SIG_IGN); */ |
/*signal (SIGPIPE, SIG_IGN); */ |
148 |
signal (SIGABRT, imap4d_signal); |
signal (SIGABRT, imap4d_signal); |
149 |
|
|
150 |
if (mode == DAEMON) |
if (daemon_param.mode == MODE_DAEMON) |
151 |
imap4d_daemon_init (); |
imap4d_daemon_init (); |
152 |
else |
else |
153 |
{ |
{ |
156 |
} |
} |
157 |
|
|
158 |
/* Set up for syslog. */ |
/* Set up for syslog. */ |
159 |
openlog ("gnu-imap4d", LOG_PID, LOG_FACILITY); |
openlog ("gnu-imap4d", LOG_PID, log_facility); |
160 |
|
|
161 |
/* Redirect any stdout error from the library to syslog, they |
/* Redirect any stdout error from the library to syslog, they |
162 |
should not go to the client. */ |
should not go to the client. */ |
165 |
umask (S_IROTH | S_IWOTH | S_IXOTH); /* 007 */ |
umask (S_IROTH | S_IWOTH | S_IXOTH); /* 007 */ |
166 |
|
|
167 |
/* Actually run the daemon. */ |
/* Actually run the daemon. */ |
168 |
if (mode == DAEMON) |
if (daemon_param.mode == MODE_DAEMON) |
169 |
imap4d_daemon (maxchildren, port); |
imap4d_daemon (daemon_param.maxchildren, daemon_param.port); |
170 |
/* exit (0) -- no way out of daemon except a signal. */ |
/* exit (0) -- no way out of daemon except a signal. */ |
171 |
else |
else |
172 |
status = imap4d_mainloop (fileno (stdin), fileno (stdout)); |
status = imap4d_mainloop (fileno (stdin), fileno (stdout)); |
328 |
} |
} |
329 |
} |
} |
330 |
|
|
|
/* 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); |
|
|
} |
|
331 |
|
|
332 |
|
|