Commit 5d286f5d 5d286f5d98dc932fff3754e3c992c40a765a3167 by Sergey Poznyakoff

* NEWS: Update.

* mailbox/Makefile.am: Replace tcpsrv.c with ipsrv.c.
* mailbox/tcpsrv.c: Replace with ...
* mailbox/ipsrv.c: ... this file, which supports both TCP and UDP.

* mailbox/msrv.c: Use mu_ip_server_t.
* mailbox/server.c (mu_server_destroy): Bugfix.
* comsat/comsat.c, comsat/comsat.h: Use m-server.

* maidag/lmtp.c, maidag/maidag.h, pop3d/pop3d.c: Update to match
changed m-server types.

* include/mailutils/server.h (mu_tcp_*): Replace with mu_ip_*.
Add new prototypes.
* include/mailutils/types.hin: Likewise.

* lib/tcpwrap.c, lib/tcpwrap.h (mu_tcp_wrapper_prefork): Update
signature to match mu_m_server_prefork_fp.

* examples/echosrv.c: Use mu_ip_server_t
* imap4d/idle.c, imap4d/imap4d.c, imap4d/imap4d.h,
imap4d/preauth.c, imap4d/util.c: Remove mu_gocs_daemon.
* include/mailutils/gocs.h, include/mailutils/libargp.h,
include/mailutils/libargp.h, libargp/cmdline.c,
libargp/common.c, libcfg/common.c, libcfg/init.c,
mailbox/daemon.c, mailbox/gocs.c: Remove mu_gocs_daemon.

* mailbox/amd.c (amd_open): Provide a null-locker.
* include/mailutils/locker.h, mailbox/locker.c
(mu_locker_mod_flags): New function.

* examples/config/mailutils.schema: LDAP schema for Mailutils.
* examples/config/Makefile.am: Add mailutils.schema

* dotlock/dotlock.c (main): Remove superfluous invocation of
mu_locker_set_flags.

* libproto/mbox/mbox.c (mbox_quick_get_message): Return
MU_ERR_NOENT if mailbox is empty.

* mailbox/tcpsrv.c (family_to_proto): Rename to
mu_address_family_to_domain.
* po/POTFILES.in: Update.
* pop3d/lock.c (pop3d_lock): use mu_locker_mod_flags, instead of
mu_locker_set_flags.
1 parent 6d0cedd1
1 2008-01-05 Sergey Poznyakoff <gray@gnu.org.ua> 1 2008-01-05 Sergey Poznyakoff <gray@gnu.org.ua>
2 2
3 * NEWS: Update.
4
5 * mailbox/Makefile.am: Replace tcpsrv.c with ipsrv.c.
6 * mailbox/tcpsrv.c: Replace with ...
7 * mailbox/ipsrv.c: ... this file, which supports both TCP and UDP.
8
9 * mailbox/msrv.c: Use mu_ip_server_t.
10 * mailbox/server.c (mu_server_destroy): Bugfix.
11 * comsat/comsat.c, comsat/comsat.h: Use m-server.
12
13 * maidag/lmtp.c, maidag/maidag.h, pop3d/pop3d.c: Update to match
14 changed m-server types.
15
16 * include/mailutils/server.h (mu_tcp_*): Replace with mu_ip_*.
17 Add new prototypes.
18 * include/mailutils/types.hin: Likewise.
19
20 * lib/tcpwrap.c, lib/tcpwrap.h (mu_tcp_wrapper_prefork): Update
21 signature to match mu_m_server_prefork_fp.
22
23 * examples/echosrv.c: Use mu_ip_server_t
24 * imap4d/idle.c, imap4d/imap4d.c, imap4d/imap4d.h,
25 imap4d/preauth.c, imap4d/util.c: Remove mu_gocs_daemon.
26 * include/mailutils/gocs.h, include/mailutils/libargp.h,
27 include/mailutils/libargp.h, libargp/cmdline.c,
28 libargp/common.c, libcfg/common.c, libcfg/init.c,
29 mailbox/daemon.c, mailbox/gocs.c: Remove mu_gocs_daemon.
30
31 * mailbox/amd.c (amd_open): Provide a null-locker.
32 * include/mailutils/locker.h, mailbox/locker.c
33 (mu_locker_mod_flags): New function.
34
35 * examples/config/mailutils.schema: LDAP schema for Mailutils.
36 * examples/config/Makefile.am: Add mailutils.schema
37
38 * dotlock/dotlock.c (main): Remove superfluous invocation of
39 mu_locker_set_flags.
40
41 * libproto/mbox/mbox.c (mbox_quick_get_message): Return
42 MU_ERR_NOENT if mailbox is empty.
43
44 * mailbox/tcpsrv.c (family_to_proto): Rename to
45 mu_address_family_to_domain.
46 * po/POTFILES.in: Update.
47 * pop3d/lock.c (pop3d_lock): use mu_locker_mod_flags, instead of
48 mu_locker_set_flags.
49
3 * include/mailutils/server.h (mu_m_server_prefork_fp): New 50 * include/mailutils/server.h (mu_m_server_prefork_fp): New
4 function type. 51 function type.
5 (mu_m_server_destroy, mu_m_server_set_prefork) 52 (mu_m_server_destroy, mu_m_server_set_prefork)
......
1 GNU mailutils NEWS -- history of user-visible changes. 2008-01-04 1 GNU mailutils NEWS -- history of user-visible changes. 2008-01-05
2 Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007 Free Software Foundation, Inc. 2 Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007 Free Software Foundation, Inc.
3 See the end of file for copying conditions. 3 See the end of file for copying conditions.
4 4
...@@ -93,12 +93,13 @@ PREAUTH mode: ...@@ -93,12 +93,13 @@ PREAUTH mode:
93 DES encrypted replies are understood. 93 DES encrypted replies are understood.
94 94
95 3. prog - Imap4d invokes an external program to authenticate the 95 3. prog - Imap4d invokes an external program to authenticate the
96 connection. Four arguments are supplied to the program: 96 connection. The command line is obtained from the supplied string,
97 by expandind the following variables:
97 98
98 1) Remote IP address in dotted-quad notation; 99 1) ${client_address} - Remote IP address in dotted-quad notation;
99 2) Remote port number; 100 2) ${client_port} - Remote port number;
100 3) Local IP address (currently "0.0.0.0"); 101 3) ${server_address} - Local IP address;
101 4) Local port number. 102 4) ${server_port} - Local port number.
102 103
103 If the connection is authenticated, the program should print the 104 If the connection is authenticated, the program should print the
104 user name, followed by a newline character, on its standard 105 user name, followed by a newline character, on its standard
......
1 /* GNU Mailutils -- a suite of utilities for electronic mail 1 /* GNU Mailutils -- a suite of utilities for electronic mail
2 Copyright (C) 1999, 2000, 2001, 2002, 2005, 2 Copyright (C) 1999, 2000, 2001, 2002, 2005,
3 2007 Free Software Foundation, Inc. 3 2007, 2008 Free Software Foundation, Inc.
4 4
5 GNU Mailutils is free software; you can redistribute it and/or modify 5 GNU Mailutils is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by 6 it under the terms of the GNU General Public License as published by
...@@ -56,12 +56,18 @@ typedef struct utmp UTMP; ...@@ -56,12 +56,18 @@ typedef struct utmp UTMP;
56 const char *program_version = "comsatd (" PACKAGE_STRING ")"; 56 const char *program_version = "comsatd (" PACKAGE_STRING ")";
57 static char doc[] = "GNU comsatd"; 57 static char doc[] = "GNU comsatd";
58 58
59 #define OPT_FOREGROUND 256
60
59 static struct argp_option options[] = 61 static struct argp_option options[] =
60 { 62 {
61 { "config", 'c', N_("FILE"), OPTION_HIDDEN, "", 0 }, 63 { "config", 'c', N_("FILE"), OPTION_HIDDEN, "", 0 },
62 { "convert-config", 'C', N_("FILE"), 0, 64 { "convert-config", 'C', N_("FILE"), 0,
63 N_("Convert the configuration FILE to new format."), 0 }, 65 N_("Convert the configuration FILE to new format."), 0 },
64 { "test", 't', NULL, 0, N_("Run in test mode"), 0 }, 66 { "test", 't', NULL, 0, N_("Run in test mode"), 0 },
67 { "foreground", OPT_FOREGROUND, 0, 0, N_("Remain in foreground."), 0},
68 { "inetd", 'i', 0, 0, N_("Run in inetd mode"), 0 },
69 { "daemon", 'd', N_("NUMBER"), OPTION_ARG_OPTIONAL,
70 N_("Runs in daemon mode with a maximum of NUMBER children"), 0 },
65 { NULL, 0, NULL, 0, NULL, 0 } 71 { NULL, 0, NULL, 0, NULL, 0 }
66 }; 72 };
67 73
...@@ -78,7 +84,6 @@ static struct argp argp = { ...@@ -78,7 +84,6 @@ static struct argp argp = {
78 }; 84 };
79 85
80 static const char *comsat_argp_capa[] = { 86 static const char *comsat_argp_capa[] = {
81 "daemon",
82 "common", 87 "common",
83 "debug", 88 "debug",
84 "logging", 89 "logging",
...@@ -96,31 +101,21 @@ static const char *comsat_argp_capa[] = { ...@@ -96,31 +101,21 @@ static const char *comsat_argp_capa[] = {
96 # define MAXHOSTNAMELEN 64 101 # define MAXHOSTNAMELEN 64
97 #endif 102 #endif
98 103
99 struct mu_gocs_daemon default_gocs_daemon = {
100 MODE_INTERACTIVE, /* Start in interactive (inetd) mode */
101 20, /* Default maximum number of children.
102 Currently unused */
103 512, /* Default biff port */
104 0, /* Default timeout */
105 };
106 int maxlines = 5; 104 int maxlines = 5;
107 char hostname[MAXHOSTNAMELEN]; 105 char hostname[MAXHOSTNAMELEN];
108 const char *username; 106 const char *username;
109 int require_tty; 107 int require_tty;
110 mu_acl_t comsat_acl; 108 mu_m_server_t server;
111 109
112 static void comsat_init (void); 110 static void comsat_init (void);
113 static void comsat_daemon_init (void);
114 static void comsat_daemon (int _port);
115 static int comsat_main (int fd); 111 static int comsat_main (int fd);
116 static void notify_user (const char *user, const char *device, 112 static void notify_user (const char *user, const char *device,
117 const char *path, mu_message_qid_t qid); 113 const char *path, mu_message_qid_t qid);
118 static int find_user (const char *name, char *tty); 114 static int find_user (const char *name, char *tty);
119 static char *mailbox_path (const char *user); 115 static char *mailbox_path (const char *user);
120 static void change_user (const char *user); 116 static int change_user (const char *user);
121 117
122 static int xargc; 118 static int reload = 0;
123 static char **xargv;
124 int test_mode; 119 int test_mode;
125 120
126 struct mu_cfg_param comsat_cfg_param[] = { 121 struct mu_cfg_param comsat_cfg_param[] = {
...@@ -142,13 +137,16 @@ struct mu_cfg_param comsat_cfg_param[] = { ...@@ -142,13 +137,16 @@ struct mu_cfg_param comsat_cfg_param[] = {
142 { "overflow-delay-time", mu_cfg_time, &overflow_delay_time, 137 { "overflow-delay-time", mu_cfg_time, &overflow_delay_time,
143 0, NULL, 138 0, NULL,
144 N_("Time to sleep after the first overflow occurs.") }, 139 N_("Time to sleep after the first overflow occurs.") },
145 { "acl", mu_cfg_section, }, 140 { ".server", mu_cfg_section, NULL, 0, NULL,
141 N_("Server configuration.") },
146 { NULL } 142 { NULL }
147 }; 143 };
148 144
149 static error_t 145 static error_t
150 comsatd_parse_opt (int key, char *arg, struct argp_state *state) 146 comsatd_parse_opt (int key, char *arg, struct argp_state *state)
151 { 147 {
148 static struct mu_argp_node_list lst;
149
152 switch (key) 150 switch (key)
153 { 151 {
154 case 'c': 152 case 'c':
...@@ -178,112 +176,43 @@ _("The old configuration file format and the --config command\n" ...@@ -178,112 +176,43 @@ _("The old configuration file format and the --config command\n"
178 convert_config (arg, stdout); 176 convert_config (arg, stdout);
179 exit (0); 177 exit (0);
180 178
179 case 'd':
180 mu_argp_node_list_new (&lst, "mode", "daemon");
181 if (arg)
182 mu_argp_node_list_new (&lst, "max-children", arg);
183 break;
184
185 case 'i':
186 mu_argp_node_list_new (&lst, "mode", "inetd");
187 break;
188
189 case OPT_FOREGROUND:
190 mu_argp_node_list_new (&lst, "foreground", "yes");
191 break;
192
181 case 't': 193 case 't':
182 test_mode = 1; 194 test_mode = 1;
183 break; 195 break;
184 196
197 case ARGP_KEY_INIT:
198 mu_argp_node_list_init (&lst);
199 break;
200
201 case ARGP_KEY_FINI:
202 mu_argp_node_list_finish (&lst, NULL, NULL);
203 break;
204
185 default: 205 default:
186 return ARGP_ERR_UNKNOWN; 206 return ARGP_ERR_UNKNOWN;
187 } 207 }
188 return 0; 208 return 0;
189 } 209 }
190 210
191 int
192 main (int argc, char **argv)
193 {
194 int c;
195 int ind;
196
197 /* Native Language Support */
198 mu_init_nls ();
199
200 mu_argp_init (program_version, NULL);
201 mu_gocs_daemon = default_gocs_daemon;
202 comsat_init ();
203 mu_acl_cfg_init ();
204
205 if (mu_app_init (&argp, comsat_argp_capa, comsat_cfg_param, argc, argv, 0,
206 &ind, &comsat_acl))
207 exit (1);
208
209 argc -= ind;
210 argv += ind;
211
212 if (test_mode)
213 {
214 char *user;
215
216 if (argc < 2 || argc > 2)
217 {
218 mu_error (_("Mailbox URL and message QID are required in test mode"));
219 exit (EXIT_FAILURE);
220 }
221
222 user = getenv ("LOGNAME");
223 if (!user)
224 {
225 user = getenv ("USER");
226 if (!user)
227 {
228 struct passwd *pw = getpwuid (getuid ());
229 if (!pw)
230 {
231 mu_error (_("Cannot determine user name"));
232 exit (EXIT_FAILURE);
233 }
234 user = pw->pw_name;
235 }
236 }
237
238 notify_user (user, "/dev/tty", argv[0], argv[1]);
239 exit (0);
240 }
241
242 if (mu_gocs_daemon.timeout > 0 && mu_gocs_daemon.mode == MODE_DAEMON)
243 {
244 mu_error (_("--timeout and --daemon are incompatible"));
245 exit (EXIT_FAILURE);
246 }
247
248 if (mu_gocs_daemon.mode == MODE_DAEMON)
249 {
250 /* Preserve invocation arguments */
251 xargc = argc;
252 xargv = argv;
253 comsat_daemon_init ();
254 }
255
256 /* Set up error messaging */
257 openlog ("gnu-comsat", LOG_PID, log_facility);
258
259 {
260 mu_debug_t debug;
261
262 mu_diag_get_debug (&debug);
263 mu_debug_set_print (debug, mu_diag_syslog_printer, NULL);
264 }
265
266 chdir ("/");
267
268 if (mu_gocs_daemon.mode == MODE_DAEMON)
269 comsat_daemon (mu_gocs_daemon.port);
270 else
271 c = comsat_main (0);
272
273 return c != 0;
274 }
275
276 static RETSIGTYPE 211 static RETSIGTYPE
277 sig_hup (int sig) 212 sig_hup (int sig)
278 { 213 {
279 mu_diag_output (MU_DIAG_NOTICE, _("Restarting")); 214 mu_m_server_stop (1);
280 215 reload = 1;
281 if (xargv[0][0] != '/')
282 mu_diag_output (MU_DIAG_ERROR, _("Cannot restart: program must be invoked using absolute pathname"));
283 else
284 execvp (xargv[0], xargv);
285
286 signal (sig, sig_hup);
287 } 216 }
288 217
289 void 218 void
...@@ -300,21 +229,6 @@ comsat_init () ...@@ -300,21 +229,6 @@ comsat_init ()
300 signal (SIGHUP, SIG_IGN); /* Ignore SIGHUP. */ 229 signal (SIGHUP, SIG_IGN); /* Ignore SIGHUP. */
301 } 230 }
302 231
303 /* Set up for daemon mode. */
304 static void
305 comsat_daemon_init (void)
306 {
307 extern int daemon (int, int);
308
309 /* Become a daemon. Take care to close inherited fds and to hold
310 first three ones, in, out, err. Do not do the chdir("/"). */
311 if (daemon (1, 0) < 0)
312 {
313 perror (_("Failed to become a daemon"));
314 exit (EXIT_FAILURE);
315 }
316 }
317
318 int allow_biffrc = 1; /* Allow per-user biffrc files */ 232 int allow_biffrc = 1; /* Allow per-user biffrc files */
319 unsigned maxrequests = 16; /* Maximum number of request allowed per 233 unsigned maxrequests = 16; /* Maximum number of request allowed per
320 control interval */ 234 control interval */
...@@ -322,140 +236,40 @@ time_t request_control_interval = 10; /* Request control interval */ ...@@ -322,140 +236,40 @@ time_t request_control_interval = 10; /* Request control interval */
322 time_t overflow_control_interval = 10; /* Overflow control interval */ 236 time_t overflow_control_interval = 10; /* Overflow control interval */
323 time_t overflow_delay_time = 5; 237 time_t overflow_delay_time = 5;
324 238
325
326 void 239 void
327 comsat_daemon (int port) 240 comsat_process (char *buffer, size_t rdlen)
328 { 241 {
329 int fd; 242 char tty[MAX_TTY_SIZE];
330 struct sockaddr_in local_sin; 243 char *p;
331 time_t last_request_time; /* Timestamp of the last received request */ 244 char *path = NULL;
332 unsigned reqcount = 0; /* Number of request received in the 245 mu_message_qid_t qid;
333 current control interval */
334 time_t last_overflow_time; /* Timestamp of last overflow */
335 unsigned overflow_count = 0; /* Number of overflows achieved during
336 the current interval */
337 time_t now;
338 246
339 fd = socket (PF_INET, SOCK_DGRAM, 0); 247 /* Parse the buffer */
340 if (fd == -1) 248 p = strchr (buffer, '@');
249 if (!p)
341 { 250 {
342 mu_diag_output (MU_DIAG_CRIT, "socket: %m"); 251 mu_diag_output (MU_DIAG_ERROR, _("Malformed input: %s"), buffer);
343 exit (1); 252 return;
344 } 253 }
254 *p++ = 0;
345 255
346 memset (&local_sin, 0, sizeof local_sin); 256 qid = p;
347 local_sin.sin_family = AF_INET; 257 p = strchr (qid, ':');
348 local_sin.sin_addr.s_addr = INADDR_ANY; /*FIXME*/ 258 if (p)
349 local_sin.sin_port = htons (port);
350
351 if (bind (fd, (struct sockaddr *) &local_sin, sizeof local_sin) < 0)
352 { 259 {
353 mu_diag_output (MU_DIAG_CRIT, "bind: %m"); 260 *p++ = 0;
354 exit (1); 261 path = p;
355 } 262 }
356 263
357 mu_diag_output (MU_DIAG_NOTICE, _("GNU comsat started")); 264 if (find_user (buffer, tty) != SUCCESS)
358
359 last_request_time = last_overflow_time = time (NULL);
360 while (1)
361 { 265 {
362 fd_set fdset; 266 if (require_tty)
363 int rc; 267 return;
364 268 strcpy (tty, "/dev/null");
365 FD_ZERO (&fdset);
366 FD_SET (fd, &fdset);
367 rc = select (fd+1, &fdset, NULL, NULL, NULL);
368 if (rc == -1)
369 {
370 if (errno != EINTR)
371 mu_diag_output (MU_DIAG_ERROR, "select: %m");
372 continue;
373 }
374
375 /* Control the request flow */
376 if (maxrequests != 0)
377 {
378 now = time (NULL);
379 if (reqcount > maxrequests)
380 {
381 unsigned delay;
382
383 delay = overflow_delay_time << (overflow_count + 1);
384 mu_diag_output (MU_DIAG_NOTICE,
385 ngettext ("Too many requests: pausing for %u second",
386 "Too many requests: pausing for %u seconds",
387 delay),
388 delay);
389 sleep (delay);
390 reqcount = 0;
391 if (now - last_overflow_time <= overflow_control_interval)
392 {
393 if ((overflow_delay_time << (overflow_count + 2)) >
394 overflow_delay_time)
395 ++overflow_count;
396 }
397 else
398 overflow_count = 0;
399 last_overflow_time = time (NULL);
400 }
401
402 if (now - last_request_time <= request_control_interval)
403 reqcount++;
404 else
405 {
406 last_request_time = now;
407 reqcount = 1;
408 }
409 }
410 comsat_main (fd);
411 } 269 }
412 }
413 270
414 int 271 /* Child: do actual I/O */
415 check_connection (int fd, struct sockaddr *addr, socklen_t addrlen) 272 notify_user (buffer, tty, path, qid);
416 {
417 switch (addr->sa_family)
418 {
419 case PF_UNIX:
420 mu_diag_output (MU_DIAG_INFO, _("connect from socket"));
421 break;
422
423 case PF_INET:
424 {
425 struct sockaddr_in *s_in = (struct sockaddr_in *)addr;
426
427 if (comsat_acl)
428 {
429 mu_acl_result_t res;
430
431 int rc = mu_acl_check_sockaddr (comsat_acl, addr, addrlen,
432 &res);
433 if (rc)
434 {
435 mu_error (_("Access from %s blocked: cannot check ACLs: %s"),
436 inet_ntoa (s_in->sin_addr), mu_strerror (rc));
437 return 1;
438 }
439 switch (res)
440 {
441 case mu_acl_result_undefined:
442 mu_diag_output (MU_DIAG_INFO,
443 _("%s: undefined ACL result; access allowed"),
444 inet_ntoa (s_in->sin_addr));
445 break;
446
447 case mu_acl_result_accept:
448 break;
449
450 case mu_acl_result_deny:
451 mu_error (_("Access from %s blocked."),
452 inet_ntoa (s_in->sin_addr));
453 return 1;
454 }
455 }
456 }
457 }
458 return 0;
459 } 273 }
460 274
461 int 275 int
...@@ -465,12 +279,7 @@ comsat_main (int fd) ...@@ -465,12 +279,7 @@ comsat_main (int fd)
465 int len; 279 int len;
466 struct sockaddr fromaddr; 280 struct sockaddr fromaddr;
467 char buffer[216]; /*FIXME: Arbitrary size */ 281 char buffer[216]; /*FIXME: Arbitrary size */
468 pid_t pid; 282
469 char tty[MAX_TTY_SIZE];
470 char *p;
471 char *path = NULL;
472 mu_message_qid_t qid;
473
474 len = sizeof fromaddr; 283 len = sizeof fromaddr;
475 rdlen = recvfrom (fd, buffer, sizeof buffer, 0, &fromaddr, &len); 284 rdlen = recvfrom (fd, buffer, sizeof buffer, 0, &fromaddr, &len);
476 if (rdlen <= 0) 285 if (rdlen <= 0)
...@@ -480,66 +289,102 @@ comsat_main (int fd) ...@@ -480,66 +289,102 @@ comsat_main (int fd)
480 mu_diag_output (MU_DIAG_ERROR, "recvfrom: %m"); 289 mu_diag_output (MU_DIAG_ERROR, "recvfrom: %m");
481 return 1; 290 return 1;
482 } 291 }
292 buffer[rdlen] = 0;
293
294 if (mu_m_server_check_acl (server, &fromaddr, len))
295 return 0;
483 296
484 if (check_connection (fd, &fromaddr, len)) 297 comsat_process (buffer, rdlen);
485 return 1; 298 return 0;
299 }
486 300
487 mu_diag_output (MU_DIAG_INFO, 301 static time_t last_request_time; /* Timestamp of the last received
488 ngettext ("Received %d byte from %s", 302 request */
489 "Received %d bytes from %s", rdlen), 303 static unsigned reqcount = 0; /* Number of request received in the
490 rdlen, inet_ntoa (((struct sockaddr_in*)&fromaddr)->sin_addr)); 304 current control interval */
491 305 static time_t last_overflow_time; /* Timestamp of last overflow */
492 buffer[rdlen] = 0; 306 static unsigned overflow_count = 0; /* Number of overflows detected during
493 mu_diag_output (MU_DIAG_INFO, "string: %s", buffer); 307 the current interval */
494 308
495 /* Parse the buffer */ 309 int
496 p = strchr (buffer, '@'); 310 comsat_prefork (int fd, void *data, struct sockaddr *s, int size)
497 if (!p) 311 {
312 int retval = 0;
313 time_t now;
314
315 /* Control the request flow */
316 if (maxrequests != 0)
498 { 317 {
499 mu_diag_output (MU_DIAG_ERROR, _("Malformed input: %s"), buffer); 318 now = time (NULL);
500 return 1; 319 if (reqcount > maxrequests)
501 } 320 {
502 *p++ = 0; 321 unsigned delay;
322
323 delay = overflow_delay_time << (overflow_count + 1);
324 mu_diag_output (MU_DIAG_NOTICE,
325 ngettext ("Too many requests: pausing for %u second",
326 "Too many requests: pausing for %u seconds",
327 delay),
328 delay);
329 /* FIXME: drain the socket? */
330 sleep (delay);
331 reqcount = 0;
332 if (now - last_overflow_time <= overflow_control_interval)
333 {
334 if ((overflow_delay_time << (overflow_count + 2)) >
335 overflow_delay_time)
336 ++overflow_count;
337 }
338 else
339 overflow_count = 0;
340 last_overflow_time = time (NULL);
341 retval = 1;
342 }
503 343
504 qid = p; 344 if (now - last_request_time <= request_control_interval)
505 p = strchr (qid, ':'); 345 reqcount++;
506 if (p) 346 else
507 { 347 {
508 *p++ = 0; 348 last_request_time = now;
509 path = p; 349 reqcount = 1;
510 } 350 }
511
512 if (find_user (buffer, tty) != SUCCESS)
513 {
514 if (require_tty)
515 return 0;
516 strcpy (tty, "/dev/null");
517 } 351 }
352 return retval;
353 }
518 354
519 /* All I/O is done by child process. This is to avoid various blocking 355 int
520 problems. */ 356 comsat_connection (int fd, struct sockaddr *sa, int salen,
521 357 void *data, mu_ip_server_t srv,
522 pid = fork (); 358 time_t to, int transcript)
359 {
360 char *buffer;
361 size_t rdlen, size;
523 362
524 if (pid == -1) 363 if (mu_udp_server_get_rdata (srv, &buffer, &rdlen))
364 return 0;
365 if (transcript)
525 { 366 {
526 mu_diag_output (MU_DIAG_ERROR, "fork: %m"); 367 char *p = mu_sockaddr_to_astr (sa, salen);
527 return 1; 368 mu_diag_output (MU_DIAG_INFO,
369 ngettext ("Received %d byte from %s",
370 "Received %d bytes from %s", rdlen),
371 rdlen, p);
372 mu_diag_output (MU_DIAG_INFO, "string: %s", buffer);
373 free (p);
528 } 374 }
529 375 mu_udp_server_get_bufsize (srv, &size);
530 if (pid > 0) 376 if (size < rdlen + 1)
531 { 377 {
532 struct timeval tv; 378 int rc = mu_udp_server_set_bufsize (srv, rdlen + 1);
533 tv.tv_sec = 0; 379 if (rc)
534 tv.tv_usec = 100000; 380 {
535 select (0, NULL, NULL, NULL, &tv); 381 mu_error (_("Cannot resize buffer: %s"), mu_strerror (rc));
536 kill (pid, SIGKILL); /* Just in case the child is hung */ 382 return 0;
537 return 0; 383 }
538 } 384 }
539 385 buffer[rdlen] = 0;
540 /* Child: do actual I/O */ 386 comsat_process (buffer, rdlen);
541 notify_user (buffer, tty, path, qid); 387 return 0;
542 exit (0);
543 } 388 }
544 389
545 static const char * 390 static const char *
...@@ -570,11 +415,12 @@ notify_user (const char *user, const char *device, const char *path, ...@@ -570,11 +415,12 @@ notify_user (const char *user, const char *device, const char *path,
570 mu_message_t msg; 415 mu_message_t msg;
571 int status; 416 int status;
572 417
573 change_user (user); 418 if (change_user (user))
419 return;
574 if ((fp = fopen (device, "w")) == NULL) 420 if ((fp = fopen (device, "w")) == NULL)
575 { 421 {
576 mu_error (_("Cannot open device %s: %m"), device); 422 mu_error (_("Cannot open device %s: %m"), device);
577 exit (0); 423 return;
578 } 424 }
579 425
580 cr = get_newline_str (fp); 426 cr = get_newline_str (fp);
...@@ -672,7 +518,7 @@ find_user (const char *name, char *tty) ...@@ -672,7 +518,7 @@ find_user (const char *name, char *tty)
672 return status; 518 return status;
673 } 519 }
674 520
675 void 521 int
676 change_user (const char *user) 522 change_user (const char *user)
677 { 523 {
678 struct passwd *pw; 524 struct passwd *pw;
...@@ -681,13 +527,14 @@ change_user (const char *user) ...@@ -681,13 +527,14 @@ change_user (const char *user)
681 if (!pw) 527 if (!pw)
682 { 528 {
683 mu_diag_output (MU_DIAG_CRIT, _("No such user: %s"), user); 529 mu_diag_output (MU_DIAG_CRIT, _("No such user: %s"), user);
684 exit (1); 530 return 1;
685 } 531 }
686 532
687 setgid (pw->pw_gid); 533 setgid (pw->pw_gid);
688 setuid (pw->pw_uid); 534 setuid (pw->pw_uid);
689 chdir (pw->pw_dir); 535 chdir (pw->pw_dir);
690 username = user; 536 username = user;
537 return 0;
691 } 538 }
692 539
693 char * 540 char *
...@@ -709,3 +556,111 @@ mailbox_path (const char *user) ...@@ -709,3 +556,111 @@ mailbox_path (const char *user)
709 return mailbox_name; 556 return mailbox_name;
710 } 557 }
711 558
559
560 int
561 main (int argc, char **argv)
562 {
563 int c;
564 int ind;
565
566 /* Native Language Support */
567 mu_init_nls ();
568
569 mu_argp_init (program_version, NULL);
570 comsat_init ();
571 mu_acl_cfg_init ();
572 mu_m_server_cfg_init ();
573 mu_m_server_create (&server, "GNU comsat");
574 mu_m_server_set_type (server, MU_IP_UDP);
575 mu_m_server_set_conn (server, comsat_connection);
576 mu_m_server_set_prefork (server, comsat_prefork);
577 mu_m_server_set_mode (server, MODE_INTERACTIVE);
578 mu_m_server_set_max_children (server, 20);
579 /* FIXME mu_m_server_set_pidfile (); */
580 mu_m_server_set_default_port (server, 512);
581 /* FIXME: timeout is not needed. How to disable it? */
582
583 if (mu_app_init (&argp, comsat_argp_capa, comsat_cfg_param, argc, argv, 0,
584 &ind, server))
585 exit (1);
586
587 if (test_mode)
588 {
589 char *user;
590
591 argc -= ind;
592 argv += ind;
593
594 if (argc < 2 || argc > 2)
595 {
596 mu_error (_("Mailbox URL and message QID are required in test mode"));
597 exit (EXIT_FAILURE);
598 }
599
600 user = getenv ("LOGNAME");
601 if (!user)
602 {
603 user = getenv ("USER");
604 if (!user)
605 {
606 struct passwd *pw = getpwuid (getuid ());
607 if (!pw)
608 {
609 mu_error (_("Cannot determine user name"));
610 exit (EXIT_FAILURE);
611 }
612 user = pw->pw_name;
613 }
614 }
615
616 notify_user (user, "/dev/tty", argv[0], argv[1]);
617 exit (0);
618 }
619
620 /* Set up error messaging */
621 openlog ("gnu-comsat", LOG_PID, log_facility);
622
623 {
624 mu_debug_t debug;
625
626 mu_diag_get_debug (&debug);
627 mu_debug_set_print (debug, mu_diag_syslog_printer, NULL);
628
629 mu_debug_default_printer = mu_debug_syslog_printer;
630 }
631
632 if (mu_m_server_mode (server) == MODE_DAEMON)
633 {
634 if (argv[0][0] != '/')
635 mu_diag_output (MU_DIAG_NOTICE,
636 _("Program name is not absolute; reloading will not "
637 "be possible"));
638 else
639 {
640 sigset_t set;
641
642 mu_m_server_get_sigset (server, &set);
643 sigdelset (&set, SIGHUP);
644 mu_m_server_set_sigset (server, &set);
645 signal (SIGHUP, sig_hup);
646 }
647
648 mu_m_server_begin (server);
649 c = mu_m_server_run (server);
650 mu_m_server_end (server);
651 mu_m_server_destroy (&server);
652 if (reload)
653 {
654 mu_diag_output (MU_DIAG_NOTICE, _("Restarting"));
655 execvp (argv[0], argv);
656 }
657 }
658 else
659 {
660 chdir ("/");
661 c = comsat_main (0);
662 }
663
664 return c != 0;
665 }
666
......
1 /* GNU Mailutils -- a suite of utilities for electronic mail 1 /* GNU Mailutils -- a suite of utilities for electronic mail
2 Copyright (C) 1999, 2000, 2001, 2002, 2007 Free Software Foundation, Inc. 2 Copyright (C) 1999, 2000, 2001, 2002, 2007,
3 2008 Free Software Foundation, Inc.
3 4
4 GNU Mailutils is free software; you can redistribute it and/or modify 5 GNU Mailutils 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 it under the terms of the GNU General Public License as published by
...@@ -61,6 +62,7 @@ ...@@ -61,6 +62,7 @@
61 #include <mailutils/nls.h> 62 #include <mailutils/nls.h>
62 #include <mailutils/daemon.h> 63 #include <mailutils/daemon.h>
63 #include <mailutils/acl.h> 64 #include <mailutils/acl.h>
65 #include <mailutils/server.h>
64 66
65 #ifndef INADDR_NONE 67 #ifndef INADDR_NONE
66 # define INADDR_NONE -1 68 # define INADDR_NONE -1
......
1 /* GNU Mailutils -- a suite of utilities for electronic mail 1 /* GNU Mailutils -- a suite of utilities for electronic mail
2 Copyright (C) 1999, 2000, 2001, 2002, 2005, 2 Copyright (C) 1999, 2000, 2001, 2002, 2005,
3 2007 Free Software Foundation, Inc. 3 2007, 2008 Free Software Foundation, Inc.
4 4
5 GNU Mailutils is free software; you can redistribute it and/or modify 5 GNU Mailutils is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by 6 it under the terms of the GNU General Public License as published by
...@@ -182,8 +182,6 @@ main (int argc, char *argv[]) ...@@ -182,8 +182,6 @@ main (int argc, char *argv[])
182 return MU_DL_EX_ERROR; 182 return MU_DL_EX_ERROR;
183 } 183 }
184 184
185 mu_locker_set_flags (locker, flags);
186
187 if (force != 0) 185 if (force != 0)
188 mu_locker_set_expire_time (locker, force); 186 mu_locker_set_expire_time (locker, force);
189 187
......
1 ## Process this file with GNU Automake to create Makefile.in 1 ## Process this file with GNU Automake to create Makefile.in
2 2
3 ## Copyright (C) 2004, 2005, 2007 Free Software Foundation, Inc. 3 ## Copyright (C) 2004, 2005, 2007, 2008 Free Software Foundation, Inc.
4 ## 4 ##
5 ## GNU Mailutils is free software; you can redistribute it and/or 5 ## GNU Mailutils is free software; you can redistribute it and/or
6 ## modify it under the terms of the GNU General Public License as 6 ## modify it under the terms of the GNU General Public License as
...@@ -21,5 +21,6 @@ EXTRA_DIST = \ ...@@ -21,5 +21,6 @@ EXTRA_DIST = \
21 dot.biffrc\ 21 dot.biffrc\
22 gnu-imap4d.pam\ 22 gnu-imap4d.pam\
23 gnu-pop3d.pam\ 23 gnu-pop3d.pam\
24 mailutils.dict 24 mailutils.dict\
25 mailutils.schema
25 26
......
1 # This file is part of GNU Mailutils -- a suite of utilities for electronic
2 # mail
3 # Copyright (C) 2007, 2008 Free Software Foundation, Inc.
4 #
5 # GNU Mailutils is free software; you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 3, or (at your option)
8 # any later version.
9 #
10 # GNU Mailutils is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
14 #
15 # You should have received a copy of the GNU General Public License
16 # along with this program. If not, see <http://www.gnu.org/licenses/>.
17
18 attributetype ( 1.3.6.1.4.1.11591.4.1.0 NAME 'mu-mailBox'
19 DESC 'The URL of the user mail box'
20 EQUALITY caseExactIA5Match
21 SYNTAX 1.3.6.1.4.1.1466.115.121.1.26 SINGLE-VALUE )
22
23 attributetype ( 1.3.6.1.4.1.11591.4.1.1 NAME 'mu-mailQuota'
24 DESC 'Maximum allowed size of the user mailbox'
25 EQUALITY integerMatch
26 SYNTAX 1.3.6.1.4.1.1466.115.121.1.27 SINGLE-VALUE )
27
28 # Object Class Definitions
29
30 objectclass ( 1.3.6.1.4.1.11591.4.2.0 NAME 'mailutilsAccount'
31 DESC 'Abstraction of an account with Mailutils attributes'
32 SUP posixAccount AUXILIARY
33 MUST ( cn $ uid $ uidNumber $ gidNumber $ homeDirectory )
34 MAY ( userPassword $ loginShell $ gecos $ mu-mailBox $ mu-mailQuota ) )
1 /* GNU Mailutils -- a suite of utilities for electronic mail 1 /* GNU Mailutils -- a suite of utilities for electronic mail
2 Copyright (C) 2007 Free Software Foundation, Inc. 2 Copyright (C) 2007, 2008 Free Software Foundation, Inc.
3 3
4 This library is free software; you can redistribute it and/or 4 This library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Lesser General Public 5 modify it under the terms of the GNU Lesser General Public
...@@ -37,7 +37,7 @@ mu_server_t server; ...@@ -37,7 +37,7 @@ mu_server_t server;
37 int 37 int
38 echo_conn (int fd, struct sockaddr *s, int len, 38 echo_conn (int fd, struct sockaddr *s, int len,
39 void *server_data, void *call_data, 39 void *server_data, void *call_data,
40 mu_tcp_server_t srv) 40 mu_ip_server_t srv)
41 { 41 {
42 struct sockaddr_in srv_addr, *s_in = (struct sockaddr_in *)s; 42 struct sockaddr_in srv_addr, *s_in = (struct sockaddr_in *)s;
43 int addrlen = sizeof srv_addr; 43 int addrlen = sizeof srv_addr;
...@@ -45,7 +45,7 @@ echo_conn (int fd, struct sockaddr *s, int len, ...@@ -45,7 +45,7 @@ echo_conn (int fd, struct sockaddr *s, int len,
45 char buf[512]; 45 char buf[512];
46 FILE *in, *out; 46 FILE *in, *out;
47 47
48 mu_tcp_server_get_sockaddr (srv, (struct sockaddr *)&srv_addr, &addrlen); 48 mu_ip_server_get_sockaddr (srv, (struct sockaddr *)&srv_addr, &addrlen);
49 49
50 pid = fork (); 50 pid = fork ();
51 if (pid == -1) 51 if (pid == -1)
...@@ -63,7 +63,7 @@ echo_conn (int fd, struct sockaddr *s, int len, ...@@ -63,7 +63,7 @@ echo_conn (int fd, struct sockaddr *s, int len,
63 return 0; 63 return 0;
64 } 64 }
65 65
66 mu_tcp_server_shutdown (srv); 66 mu_ip_server_shutdown (srv);
67 67
68 in = fdopen (fd, "r"); 68 in = fdopen (fd, "r");
69 out = fdopen (fd, "w"); 69 out = fdopen (fd, "w");
...@@ -88,11 +88,11 @@ echo_conn (int fd, struct sockaddr *s, int len, ...@@ -88,11 +88,11 @@ echo_conn (int fd, struct sockaddr *s, int len,
88 int 88 int
89 tcp_conn_handler (int fd, void *conn_data, void *server_data) 89 tcp_conn_handler (int fd, void *conn_data, void *server_data)
90 { 90 {
91 mu_tcp_server_t tcpsrv = (mu_tcp_server_t) conn_data; 91 mu_ip_server_t tcpsrv = (mu_ip_server_t) conn_data;
92 int rc = mu_tcp_server_accept (tcpsrv, server_data); 92 int rc = mu_ip_server_accept (tcpsrv, server_data);
93 if (rc && rc != EINTR) 93 if (rc && rc != EINTR)
94 { 94 {
95 mu_tcp_server_shutdown (tcpsrv); 95 mu_ip_server_shutdown (tcpsrv);
96 return MU_SERVER_CLOSE_CONN; 96 return MU_SERVER_CLOSE_CONN;
97 } 97 }
98 return MU_SERVER_SUCCESS; 98 return MU_SERVER_SUCCESS;
...@@ -101,8 +101,8 @@ tcp_conn_handler (int fd, void *conn_data, void *server_data) ...@@ -101,8 +101,8 @@ tcp_conn_handler (int fd, void *conn_data, void *server_data)
101 void 101 void
102 tcp_conn_free (void *conn_data, void *server_data) 102 tcp_conn_free (void *conn_data, void *server_data)
103 { 103 {
104 mu_tcp_server_t tcpsrv = (mu_tcp_server_t) conn_data; 104 mu_ip_server_t tcpsrv = (mu_ip_server_t) conn_data;
105 mu_tcp_server_destroy (&tcpsrv); 105 mu_ip_server_destroy (&tcpsrv);
106 } 106 }
107 107
108 void 108 void
...@@ -110,7 +110,7 @@ create_server (char *arg) ...@@ -110,7 +110,7 @@ create_server (char *arg)
110 { 110 {
111 char *p, *q; 111 char *p, *q;
112 struct sockaddr_in s; 112 struct sockaddr_in s;
113 mu_tcp_server_t tcpsrv; 113 mu_ip_server_t tcpsrv;
114 unsigned n; 114 unsigned n;
115 115
116 p = strchr (arg, ':'); 116 p = strchr (arg, ':');
...@@ -134,11 +134,12 @@ create_server (char *arg) ...@@ -134,11 +134,12 @@ create_server (char *arg)
134 } 134 }
135 s.sin_port = htons (n); 135 s.sin_port = htons (n);
136 136
137 MU_ASSERT (mu_tcp_server_create (&tcpsrv, (struct sockaddr*) &s, sizeof s)); 137 MU_ASSERT (mu_ip_server_create (&tcpsrv, (struct sockaddr*) &s, sizeof s,
138 MU_ASSERT (mu_tcp_server_open (tcpsrv)); 138 MU_IP_TCP));
139 MU_ASSERT (mu_tcp_server_set_conn (tcpsrv, echo_conn)); 139 MU_ASSERT (mu_ip_server_open (tcpsrv));
140 MU_ASSERT (mu_ip_server_set_conn (tcpsrv, echo_conn));
140 MU_ASSERT (mu_server_add_connection (server, 141 MU_ASSERT (mu_server_add_connection (server,
141 mu_tcp_server_get_fd (tcpsrv), 142 mu_ip_server_get_fd (tcpsrv),
142 tcpsrv, 143 tcpsrv,
143 tcp_conn_handler, tcp_conn_free)); 144 tcp_conn_handler, tcp_conn_free));
144 } 145 }
......
1 /* GNU Mailutils -- a suite of utilities for electronic mail 1 /* GNU Mailutils -- a suite of utilities for electronic mail
2 Copyright (C) 2003, 2007 Free Software Foundation, Inc. 2 Copyright (C) 2003, 2007, 2008 Free Software Foundation, Inc.
3 3
4 GNU Mailutils is free software; you can redistribute it and/or modify 4 GNU Mailutils is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by 5 it under the terms of the GNU General Public License as published by
...@@ -49,7 +49,7 @@ imap4d_idle (struct imap4d_command *command, char *arg) ...@@ -49,7 +49,7 @@ imap4d_idle (struct imap4d_command *command, char *arg)
49 if (rc) 49 if (rc)
50 break; 50 break;
51 } 51 }
52 else if (time (NULL) - start > mu_gocs_daemon.timeout) 52 else if (time (NULL) - start > idle_timeout)
53 imap4d_bye (ERR_TIMEOUT); 53 imap4d_bye (ERR_TIMEOUT);
54 54
55 imap4d_sync (); 55 imap4d_sync ();
......
...@@ -371,7 +371,6 @@ static int ...@@ -371,7 +371,6 @@ static int
371 imap4d_mainloop (int fd, FILE *infile, FILE *outfile) 371 imap4d_mainloop (int fd, FILE *infile, FILE *outfile)
372 { 372 {
373 char *text; 373 char *text;
374 struct sockaddr_in cs;
375 int debug_mode = isatty (fd); 374 int debug_mode = isatty (fd);
376 375
377 /* Reset hup to exit. */ 376 /* Reset hup to exit. */
...@@ -416,7 +415,8 @@ imap4d_mainloop (int fd, FILE *infile, FILE *outfile) ...@@ -416,7 +415,8 @@ imap4d_mainloop (int fd, FILE *infile, FILE *outfile)
416 } 415 }
417 416
418 int 417 int
419 imap4d_connection (int fd, void *data, time_t timeout, int transcript) 418 imap4d_connection (int fd, struct sockaddr *sa, int salen, void *data,
419 mu_ip_server_t srv, time_t timeout, int transcript)
420 { 420 {
421 idle_timeout = timeout; 421 idle_timeout = timeout;
422 imap4d_transcript = transcript; 422 imap4d_transcript = transcript;
......
...@@ -182,7 +182,9 @@ extern int preauth_only; ...@@ -182,7 +182,9 @@ extern int preauth_only;
182 extern int ident_port; 182 extern int ident_port;
183 extern char *ident_keyfile; 183 extern char *ident_keyfile;
184 extern int ident_encrypt_only; 184 extern int ident_encrypt_only;
185 185 extern unsigned int idle_timeout;
186 extern int imap4d_transcript;
187
186 #ifndef HAVE_STRTOK_R 188 #ifndef HAVE_STRTOK_R
187 extern char *strtok_r (char *s, const char *delim, char **save_ptr); 189 extern char *strtok_r (char *s, const char *delim, char **save_ptr);
188 #endif 190 #endif
......
1 /* GNU Mailutils -- a suite of utilities for electronic mail 1 /* GNU Mailutils -- a suite of utilities for electronic mail
2 Copyright (C) 1999, 2001, 2002, 2003, 2004, 2 Copyright (C) 1999, 2001, 2002, 2003, 2004,
3 2005, 2006, 2007 Free Software Foundation, Inc. 3 2005, 2006, 2007, 2008 Free Software Foundation, Inc.
4 4
5 GNU Mailutils is free software; you can redistribute it and/or modify 5 GNU Mailutils is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by 6 it under the terms of the GNU General Public License as published by
...@@ -20,13 +20,14 @@ ...@@ -20,13 +20,14 @@
20 /* Preauth support for imap4d */ 20 /* Preauth support for imap4d */
21 21
22 #include "imap4d.h" 22 #include "imap4d.h"
23 #include <mailutils/vartab.h>
23 #include "des.h" 24 #include "des.h"
24 25
25 26
26 /* Stdio preauth */ 27 /* Stdio preauth */
27 28
28 static char * 29 static char *
29 do_preauth_stdio (struct sockaddr_in *pcs) 30 do_preauth_stdio ()
30 { 31 {
31 struct passwd *pw = getpwuid (getuid ()); 32 struct passwd *pw = getpwuid (getuid ());
32 return pw ? strdup (pw->pw_name) : NULL; 33 return pw ? strdup (pw->pw_name) : NULL;
...@@ -321,15 +322,32 @@ ident_decrypt (const char *file, const char *name) ...@@ -321,15 +322,32 @@ ident_decrypt (const char *file, const char *name)
321 } 322 }
322 323
323 static char * 324 static char *
324 do_preauth_ident (struct sockaddr_in *pcs) 325 do_preauth_ident (struct sockaddr *clt_sa, struct sockaddr *srv_sa)
325 { 326 {
326 mu_stream_t stream; 327 mu_stream_t stream;
327 char hostaddr[16]; 328 char hostaddr[16];
328 char *p = inet_ntoa (pcs->sin_addr);
329 int rc; 329 int rc;
330 char *buf = NULL; 330 char *buf = NULL;
331 size_t size = 0; 331 size_t size = 0;
332 char *name = NULL; 332 char *name = NULL;
333 struct sockaddr_in *srv_addr, *clt_addr;
334 char *p;
335
336 if (!srv_sa || !clt_sa)
337 {
338 mu_diag_output (MU_DIAG_ERROR, _("Not enough data for IDENT preauth"));
339 return NULL;
340 }
341 if (srv_sa->sa_family != AF_INET)
342 {
343 mu_diag_output (MU_DIAG_ERROR,
344 _("Invalid socket family (%d) IDENT preauth"),
345 srv_sa->sa_family);
346 return NULL;
347 }
348 srv_addr = (struct sockaddr_in *) srv_sa;
349 clt_addr = (struct sockaddr_in *) clt_sa;
350 p = inet_ntoa (clt_addr->sin_addr);
333 351
334 memcpy (hostaddr, p, 15); 352 memcpy (hostaddr, p, 15);
335 hostaddr[15] = 0; 353 hostaddr[15] = 0;
...@@ -350,8 +368,9 @@ do_preauth_ident (struct sockaddr_in *pcs) ...@@ -350,8 +368,9 @@ do_preauth_ident (struct sockaddr_in *pcs)
350 return NULL; 368 return NULL;
351 } 369 }
352 370
353 mu_stream_sequential_printf (stream, "%u , %u\r\n", ntohs (pcs->sin_port), 371 mu_stream_sequential_printf (stream, "%u , %u\r\n",
354 mu_gocs_daemon.port); 372 ntohs (clt_addr->sin_port),
373 ntohs (srv_addr->sin_port));
355 mu_stream_shutdown (stream, MU_STREAM_WRITE); 374 mu_stream_shutdown (stream, MU_STREAM_WRITE);
356 375
357 rc = mu_stream_sequential_getline (stream, &buf, &size, NULL); 376 rc = mu_stream_sequential_getline (stream, &buf, &size, NULL);
...@@ -402,21 +421,35 @@ do_preauth_ident (struct sockaddr_in *pcs) ...@@ -402,21 +421,35 @@ do_preauth_ident (struct sockaddr_in *pcs)
402 421
403 /* External (program) preauth */ 422 /* External (program) preauth */
404 static char * 423 static char *
405 do_preauth_program (struct sockaddr_in *pcs) 424 do_preauth_program (struct sockaddr *pcs, struct sockaddr *sa)
406 { 425 {
426 int rc;
427 mu_vartab_t vtab;
428 char *cmd;
407 FILE *fp; 429 FILE *fp;
408 char *p = inet_ntoa (pcs->sin_addr);
409 char *cmd = 0;
410 char *buf = NULL; 430 char *buf = NULL;
411 size_t size; 431 size_t size = 0;
412 ssize_t rc; 432
413 433 mu_vartab_create (&vtab);
414 asprintf (&cmd, "%s %s %u %s %u", 434 if (pcs && pcs->sa_family == AF_INET)
415 preauth_program, 435 {
416 p, 436 struct sockaddr_in *s_in = (struct sockaddr_in *)pcs;
417 ntohs (pcs->sin_port), 437 mu_vartab_define (vtab, "client_address", inet_ntoa (s_in->sin_addr), 0);
418 "0.0.0.0", /* FIXME */ 438 mu_vartab_define (vtab, "client_port",
419 mu_gocs_daemon.port); 439 mu_umaxtostr (0, ntohs (s_in->sin_port)), 0);
440 }
441 if (sa && sa->sa_family == AF_INET)
442 {
443 struct sockaddr_in *s_in = (struct sockaddr_in *) sa;
444 mu_vartab_define (vtab, "server_address", inet_ntoa (s_in->sin_addr), 0);
445 mu_vartab_define (vtab, "server_port",
446 mu_umaxtostr (0, ntohs (s_in->sin_port)), 0);
447 }
448 rc = mu_vartab_expand (vtab, preauth_program, &cmd);
449 mu_vartab_destroy (&vtab);
450 if (rc)
451 return NULL;
452
420 fp = popen (cmd, "r"); 453 fp = popen (cmd, "r");
421 free (cmd); 454 free (cmd);
422 rc = getline (&buf, &size, fp); 455 rc = getline (&buf, &size, fp);
...@@ -436,14 +469,30 @@ do_preauth_program (struct sockaddr_in *pcs) ...@@ -436,14 +469,30 @@ do_preauth_program (struct sockaddr_in *pcs)
436 int 469 int
437 imap4d_preauth_setup (int fd) 470 imap4d_preauth_setup (int fd)
438 { 471 {
439 struct sockaddr_in cs; 472 struct sockaddr clt_sa, *pclt_sa;
440 int len = sizeof cs; 473 int clt_len = sizeof clt_sa;
474 struct sockaddr srv_sa, *psrv_sa;
475 int srv_len = sizeof srv_sa;
441 char *username = NULL; 476 char *username = NULL;
442 477
443 if (getpeername (fd, (struct sockaddr *) &cs, &len) < 0) 478 if (getsockname (fd, &srv_sa, &srv_len) == -1)
444 mu_diag_output (MU_DIAG_ERROR, 479 {
445 _("Cannot obtain IP address of client: %s"), 480 psrv_sa = NULL;
446 strerror (errno)); 481 srv_len = 0;
482 }
483 else
484 psrv_sa = &srv_sa;
485
486 if (getpeername (fd, (struct sockaddr *) &clt_sa, &clt_len) == -1)
487 {
488 mu_diag_output (MU_DIAG_ERROR,
489 _("Cannot obtain IP address of client: %s"),
490 strerror (errno));
491 pclt_sa = NULL;
492 clt_len = 0;
493 }
494 else
495 pclt_sa = &clt_sa;
447 496
448 auth_data = NULL; 497 auth_data = NULL;
449 switch (preauth_mode) 498 switch (preauth_mode)
...@@ -452,15 +501,15 @@ imap4d_preauth_setup (int fd) ...@@ -452,15 +501,15 @@ imap4d_preauth_setup (int fd)
452 return 0; 501 return 0;
453 502
454 case preauth_stdio: 503 case preauth_stdio:
455 username = do_preauth_stdio (&cs); 504 username = do_preauth_stdio ();
456 break; 505 break;
457 506
458 case preauth_ident: 507 case preauth_ident:
459 username = do_preauth_ident (&cs); 508 username = do_preauth_ident (pclt_sa, psrv_sa);
460 break; 509 break;
461 510
462 case preauth_prog: 511 case preauth_prog:
463 username = do_preauth_program (&cs); 512 username = do_preauth_program (pclt_sa, psrv_sa);
464 break; 513 break;
465 } 514 }
466 515
......
1 /* GNU Mailutils -- a suite of utilities for electronic mail 1 /* GNU Mailutils -- a suite of utilities for electronic mail
2 Copyright (C) 1999, 2001, 2002, 2003, 2004, 2 Copyright (C) 1999, 2001, 2002, 2003, 2004,
3 2005, 2006, 2007 Free Software Foundation, Inc. 3 2005, 2006, 2007, 2008 Free Software Foundation, Inc.
4 4
5 GNU Mailutils is free software; you can redistribute it and/or modify 5 GNU Mailutils is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by 6 it under the terms of the GNU General Public License as published by
...@@ -360,7 +360,7 @@ util_send (const char *format, ...) ...@@ -360,7 +360,7 @@ util_send (const char *format, ...)
360 if (!buf) 360 if (!buf)
361 imap4d_bye (ERR_NO_MEM); 361 imap4d_bye (ERR_NO_MEM);
362 362
363 if (mu_gocs_daemon.transcript) 363 if (imap4d_transcript)
364 mu_diag_output (MU_DIAG_DEBUG, "sent: %s", buf); 364 mu_diag_output (MU_DIAG_DEBUG, "sent: %s", buf);
365 365
366 status = mu_stream_sequential_write (ostream, buf, strlen (buf)); 366 status = mu_stream_sequential_write (ostream, buf, strlen (buf));
...@@ -414,7 +414,7 @@ util_out (int rc, const char *format, ...) ...@@ -414,7 +414,7 @@ util_out (int rc, const char *format, ...)
414 if (!buf) 414 if (!buf)
415 imap4d_bye (ERR_NO_MEM); 415 imap4d_bye (ERR_NO_MEM);
416 416
417 if (mu_gocs_daemon.transcript) 417 if (imap4d_transcript)
418 mu_diag_output (MU_DIAG_DEBUG, "sent: %s", buf); 418 mu_diag_output (MU_DIAG_DEBUG, "sent: %s", buf);
419 419
420 status = mu_stream_sequential_write (ostream, buf, strlen (buf)); 420 status = mu_stream_sequential_write (ostream, buf, strlen (buf));
...@@ -455,7 +455,7 @@ util_finish (struct imap4d_command *command, int rc, const char *format, ...) ...@@ -455,7 +455,7 @@ util_finish (struct imap4d_command *command, int rc, const char *format, ...)
455 strcat (buf, tempbuf); 455 strcat (buf, tempbuf);
456 free (tempbuf); 456 free (tempbuf);
457 457
458 if (mu_gocs_daemon.transcript) 458 if (imap4d_transcript)
459 mu_diag_output (MU_DIAG_DEBUG, "sent: %s\r\n", buf); 459 mu_diag_output (MU_DIAG_DEBUG, "sent: %s\r\n", buf);
460 460
461 mu_stream_sequential_write (ostream, buf, strlen (buf)); 461 mu_stream_sequential_write (ostream, buf, strlen (buf));
...@@ -503,7 +503,7 @@ imap4d_readline (void) ...@@ -503,7 +503,7 @@ imap4d_readline (void)
503 size_t sz; 503 size_t sz;
504 int rc; 504 int rc;
505 505
506 alarm (mu_gocs_daemon.timeout); 506 alarm (idle_timeout);
507 rc = mu_stream_sequential_readline (istream, buffer, sizeof (buffer), &sz); 507 rc = mu_stream_sequential_readline (istream, buffer, sizeof (buffer), &sz);
508 if (sz == 0) 508 if (sz == 0)
509 { 509 {
...@@ -577,7 +577,7 @@ imap4d_readline (void) ...@@ -577,7 +577,7 @@ imap4d_readline (void)
577 } 577 }
578 } 578 }
579 while (number > 0 || (total && line[total - 1] != '\n')); 579 while (number > 0 || (total && line[total - 1] != '\n'));
580 if (mu_gocs_daemon.transcript) 580 if (imap4d_transcript)
581 mu_diag_output (MU_DIAG_DEBUG, "recv: %s", line); 581 mu_diag_output (MU_DIAG_DEBUG, "recv: %s", line);
582 return line; 582 return line;
583 } 583 }
...@@ -1035,7 +1035,7 @@ util_localname () ...@@ -1035,7 +1035,7 @@ util_localname ()
1035 #define WILD_ABORT 2 1035 #define WILD_ABORT 2
1036 1036
1037 int 1037 int
1038 _wild_match (const char *expr, const char *name, const char *delim) 1038 _wild_match (const char *expr, const char *name, char delim)
1039 { 1039 {
1040 while (expr && *expr) 1040 while (expr && *expr)
1041 { 1041 {
......
1 /* GNU Mailutils -- a suite of utilities for electronic mail 1 /* GNU Mailutils -- a suite of utilities for electronic mail
2 Copyright (C) 2007 Free Software Foundation, Inc. 2 Copyright (C) 2007, 2008 Free Software Foundation, Inc.
3 3
4 This library is free software; you can redistribute it and/or 4 This library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Lesser General Public 5 modify it under the terms of the GNU Lesser General Public
...@@ -26,16 +26,6 @@ ...@@ -26,16 +26,6 @@
26 extern "C" { 26 extern "C" {
27 #endif 27 #endif
28 28
29 struct mu_gocs_daemon
30 {
31 int mode;
32 size_t maxchildren;
33 unsigned int port;
34 unsigned int timeout;
35 int transcript;
36 char *pidfile;
37 };
38
39 struct mu_gocs_logging 29 struct mu_gocs_logging
40 { 30 {
41 int facility; 31 int facility;
...@@ -104,7 +94,6 @@ int mu_gocs_enumerate (mu_list_action_t action, void *data); ...@@ -104,7 +94,6 @@ int mu_gocs_enumerate (mu_list_action_t action, void *data);
104 94
105 int mu_gocs_mailbox_init (void *data); 95 int mu_gocs_mailbox_init (void *data);
106 int mu_gocs_locking_init (void *data); 96 int mu_gocs_locking_init (void *data);
107 int mu_gocs_daemon_init (void *data);
108 int mu_gocs_source_email_init (void *data); 97 int mu_gocs_source_email_init (void *data);
109 int mu_gocs_mailer_init (void *data); 98 int mu_gocs_mailer_init (void *data);
110 int mu_gocs_logging_init (void *data); 99 int mu_gocs_logging_init (void *data);
......
1 /* GNU Mailutils -- a suite of utilities for electronic mail 1 /* GNU Mailutils -- a suite of utilities for electronic mail
2 Copyright (C) 1999, 2000, 2001, 2004, 2005, 2 Copyright (C) 1999, 2000, 2001, 2004, 2005,
3 2007 Free Software Foundation, Inc. 3 2007, 2008 Free Software Foundation, Inc.
4 4
5 This library is free software; you can redistribute it and/or 5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public 6 modify it under the terms of the GNU Lesser General Public
...@@ -52,7 +52,6 @@ extern struct mu_cmdline_capa mu_mailbox_cmdline; ...@@ -52,7 +52,6 @@ extern struct mu_cmdline_capa mu_mailbox_cmdline;
52 extern struct mu_cmdline_capa mu_locking_cmdline; 52 extern struct mu_cmdline_capa mu_locking_cmdline;
53 extern struct mu_cmdline_capa mu_address_cmdline; 53 extern struct mu_cmdline_capa mu_address_cmdline;
54 extern struct mu_cmdline_capa mu_mailer_cmdline; 54 extern struct mu_cmdline_capa mu_mailer_cmdline;
55 extern struct mu_cmdline_capa mu_daemon_cmdline;
56 extern struct mu_cmdline_capa mu_sieve_cmdline; 55 extern struct mu_cmdline_capa mu_sieve_cmdline;
57 extern struct mu_cmdline_capa mu_debug_cmdline; 56 extern struct mu_cmdline_capa mu_debug_cmdline;
58 57
......
1 /* GNU Mailutils -- a suite of utilities for electronic mail 1 /* GNU Mailutils -- a suite of utilities for electronic mail
2 Copyright (C) 2007 Free Software Foundation, Inc. 2 Copyright (C) 2007, 2008 Free Software Foundation, Inc.
3 3
4 This library is free software; you can redistribute it and/or 4 This library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Lesser General Public 5 modify it under the terms of the GNU Lesser General Public
...@@ -96,7 +96,6 @@ extern struct mu_cfg_capa mu_sql_cfg_capa; ...@@ -96,7 +96,6 @@ extern struct mu_cfg_capa mu_sql_cfg_capa;
96 extern struct mu_cfg_capa mu_tls_cfg_capa; 96 extern struct mu_cfg_capa mu_tls_cfg_capa;
97 extern struct mu_cfg_capa mu_virtdomain_cfg_capa; 97 extern struct mu_cfg_capa mu_virtdomain_cfg_capa;
98 extern struct mu_cfg_capa mu_sieve_cfg_capa; 98 extern struct mu_cfg_capa mu_sieve_cfg_capa;
99 extern struct mu_cfg_capa mu_daemon_cfg_capa;
100 extern struct mu_cfg_capa mu_auth_cfg_capa; 99 extern struct mu_cfg_capa mu_auth_cfg_capa;
101 extern struct mu_cfg_capa mu_ldap_cfg_capa; 100 extern struct mu_cfg_capa mu_ldap_cfg_capa;
102 101
......
1 /* GNU Mailutils -- a suite of utilities for electronic mail 1 /* GNU Mailutils -- a suite of utilities for electronic mail
2 Copyright (C) 1999, 2000, 2001, 2005, 2007 Free Software Foundation, Inc. 2 Copyright (C) 1999, 2000, 2001, 2005, 2007,
3 2008 Free Software Foundation, Inc.
3 4
4 This library is free software; you can redistribute it and/or 5 This library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Lesser General Public 6 modify it under the terms of the GNU Lesser General Public
...@@ -112,6 +113,8 @@ extern void mu_locker_destroy (mu_locker_t *); ...@@ -112,6 +113,8 @@ extern void mu_locker_destroy (mu_locker_t *);
112 /* Time is measured in seconds. */ 113 /* Time is measured in seconds. */
113 114
114 extern int mu_locker_set_flags (mu_locker_t, int); 115 extern int mu_locker_set_flags (mu_locker_t, int);
116 extern int mu_locker_mod_flags (mu_locker_t locker, int flags,
117 enum mu_locker_set_mode mode);
115 extern int mu_locker_set_expire_time (mu_locker_t, int); 118 extern int mu_locker_set_expire_time (mu_locker_t, int);
116 extern int mu_locker_set_retries (mu_locker_t, int); 119 extern int mu_locker_set_retries (mu_locker_t, int);
117 extern int mu_locker_set_retry_sleep (mu_locker_t, int); 120 extern int mu_locker_set_retry_sleep (mu_locker_t, int);
......
1 /* GNU Mailutils -- a suite of utilities for electronic mail 1 /* GNU Mailutils -- a suite of utilities for electronic mail
2 Copyright (C) 2007 Free Software Foundation, Inc. 2 Copyright (C) 2007, 2008 Free Software Foundation, Inc.
3 3
4 This library is free software; you can redistribute it and/or 4 This library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Lesser General Public 5 modify it under the terms of the GNU Lesser General Public
...@@ -43,42 +43,57 @@ int mu_server_set_timeout (mu_server_t srv, struct timeval *to); ...@@ -43,42 +43,57 @@ int mu_server_set_timeout (mu_server_t srv, struct timeval *to);
43 int mu_server_count (mu_server_t srv, size_t *pcount); 43 int mu_server_count (mu_server_t srv, size_t *pcount);
44 44
45 45
46 /* TCP server */ 46 /* IP (TCP and UDP) server */
47 struct sockaddr; 47 struct sockaddr;
48 typedef int (*mu_tcp_server_conn_fp) (int fd, struct sockaddr *s, int len, 48 typedef int (*mu_ip_server_conn_fp) (int fd, struct sockaddr *s, int len,
49 void *server_data, void *call_data, 49 void *server_data, void *call_data,
50 mu_tcp_server_t srv); 50 mu_ip_server_t srv);
51 typedef int (*mu_tcp_server_intr_fp) (void *data, void *call_data); 51 typedef int (*mu_ip_server_intr_fp) (void *data, void *call_data);
52 typedef void (*mu_tcp_server_free_fp) (void *data); 52 typedef void (*mu_ip_server_free_fp) (void *data);
53 53
54 54 #define MU_IP_TCP 0
55 int mu_tcp_server_create (mu_tcp_server_t *psrv, struct sockaddr *addr, 55 #define MU_IP_UDP 1
56 int len); 56
57 int mu_tcp_server_destroy (mu_tcp_server_t *psrv); 57 int mu_ip_server_create (mu_ip_server_t *psrv, struct sockaddr *addr,
58 int mu_tcp_server_set_debug (mu_tcp_server_t srv, mu_debug_t debug); 58 int len, int type);
59 int mu_tcp_server_get_debug (mu_tcp_server_t srv, mu_debug_t *pdebug); 59 int mu_ip_server_destroy (mu_ip_server_t *psrv);
60 int mu_tcp_server_set_backlog (mu_tcp_server_t srv, int backlog); 60 int mu_ip_server_get_type (mu_ip_server_t srv, int *ptype);
61 int mu_tcp_server_set_ident (mu_tcp_server_t srv, const char *ident); 61 int mu_ip_server_set_debug (mu_ip_server_t srv, mu_debug_t debug);
62 int mu_tcp_server_set_acl (mu_tcp_server_t srv, mu_acl_t acl); 62 int mu_ip_server_get_debug (mu_ip_server_t srv, mu_debug_t *pdebug);
63 int mu_tcp_server_set_conn (mu_tcp_server_t srv, mu_tcp_server_conn_fp conn); 63 int mu_ip_server_set_ident (mu_ip_server_t srv, const char *ident);
64 int mu_tcp_server_set_intr (mu_tcp_server_t srv, mu_tcp_server_intr_fp intr); 64 int mu_ip_server_set_acl (mu_ip_server_t srv, mu_acl_t acl);
65 int mu_tcp_server_set_data (mu_tcp_server_t srv, 65 int mu_ip_server_set_conn (mu_ip_server_t srv, mu_ip_server_conn_fp conn);
66 void *data, mu_tcp_server_free_fp free); 66 int mu_ip_server_set_intr (mu_ip_server_t srv, mu_ip_server_intr_fp intr);
67 int mu_tcp_server_open (mu_tcp_server_t srv); 67 int mu_ip_server_set_data (mu_ip_server_t srv,
68 int mu_tcp_server_shutdown (mu_tcp_server_t srv); 68 void *data, mu_ip_server_free_fp free);
69 int mu_tcp_server_accept (mu_tcp_server_t srv, void *call_data); 69 int mu_ip_server_open (mu_ip_server_t srv);
70 int mu_tcp_server_loop (mu_tcp_server_t srv, void *call_data); 70 int mu_ip_server_shutdown (mu_ip_server_t srv);
71 int mu_tcp_server_get_fd (mu_tcp_server_t srv); 71 int mu_ip_server_accept (mu_ip_server_t srv, void *call_data);
72 int mu_tcp_server_get_sockaddr (mu_tcp_server_t srv, struct sockaddr *s, 72 int mu_ip_server_loop (mu_ip_server_t srv, void *call_data);
73 int *size); 73 int mu_ip_server_get_fd (mu_ip_server_t srv);
74 int mu_ip_server_get_sockaddr (mu_ip_server_t srv, struct sockaddr *s,
75 int *size);
76
77 int mu_tcp_server_set_backlog (mu_ip_server_t srv, int backlog);
78 int mu_udp_server_set_bufsize (mu_ip_server_t srv, size_t size);
79 int mu_udp_server_get_bufsize (mu_ip_server_t srv, size_t *psize);
80 int mu_udp_server_get_rdata (mu_ip_server_t srv, char **pbuf,
81 size_t *pbufsize);
74 82
75 83
76 /* m-server */ 84 /* m-server */
77 typedef int (*mu_m_server_conn_fp) (int, void *, time_t, int); 85 typedef struct mu_m_server_connect_data mu_m_server_connect_data_t;
78 typedef int (*mu_m_server_prefork_fp) (int, struct sockaddr *s, int size); 86 typedef int (*mu_m_server_conn_fp) (int fd, struct sockaddr *sa, int salen,
87 void *data, mu_ip_server_t srv,
88 time_t timeout, int transcript);
89 typedef int (*mu_m_server_prefork_fp) (int, void *,
90 struct sockaddr *s, int size);
91
79 void mu_m_server_create (mu_m_server_t *psrv, const char *ident); 92 void mu_m_server_create (mu_m_server_t *psrv, const char *ident);
80 void mu_m_server_destroy (mu_m_server_t *pmsrv); 93 void mu_m_server_destroy (mu_m_server_t *pmsrv);
81 void mu_m_server_set_mode (mu_m_server_t srv, int mode); 94 void mu_m_server_set_mode (mu_m_server_t srv, int mode);
95 void mu_m_server_set_type (mu_m_server_t srv, int type);
96 void mu_m_server_get_type (mu_m_server_t srv, int *ptype);
82 void mu_m_server_set_conn (mu_m_server_t srv, mu_m_server_conn_fp f); 97 void mu_m_server_set_conn (mu_m_server_t srv, mu_m_server_conn_fp f);
83 void mu_m_server_set_prefork (mu_m_server_t srv, mu_m_server_prefork_fp fun); 98 void mu_m_server_set_prefork (mu_m_server_t srv, mu_m_server_prefork_fp fun);
84 void mu_m_server_set_data (mu_m_server_t srv, void *data); 99 void mu_m_server_set_data (mu_m_server_t srv, void *data);
...@@ -99,6 +114,9 @@ void mu_m_server_begin (mu_m_server_t msrv); ...@@ -99,6 +114,9 @@ void mu_m_server_begin (mu_m_server_t msrv);
99 int mu_m_server_run (mu_m_server_t msrv); 114 int mu_m_server_run (mu_m_server_t msrv);
100 void mu_m_server_end (mu_m_server_t msrv); 115 void mu_m_server_end (mu_m_server_t msrv);
101 116
117 void mu_m_server_stop (int code);
118 int mu_m_server_check_acl (mu_m_server_t msrv, struct sockaddr *s, int salen);
119
102 void mu_m_server_cfg_init (void); 120 void mu_m_server_cfg_init (void);
103 121
104 122
......
1 /* GNU Mailutils -- a suite of utilities for electronic mail -*- c -*- 1 /* GNU Mailutils -- a suite of utilities for electronic mail -*- c -*-
2 Copyright (C) 1999, 2000, 2001, 2005, 2007 Free Software Foundation, Inc. 2 Copyright (C) 1999, 2000, 2001, 2005, 2007,
3 2008 Free Software Foundation, Inc.
3 4
4 This library is free software; you can redistribute it and/or 5 This library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Lesser General Public 6 modify it under the terms of the GNU Lesser General Public
...@@ -107,7 +108,7 @@ typedef char *mu_message_qid_t; ...@@ -107,7 +108,7 @@ typedef char *mu_message_qid_t;
107 typedef int mu_log_level_t; 108 typedef int mu_log_level_t;
108 typedef struct _mu_acl *mu_acl_t; 109 typedef struct _mu_acl *mu_acl_t;
109 typedef struct _mu_server *mu_server_t; 110 typedef struct _mu_server *mu_server_t;
110 typedef struct _mu_tcp_server *mu_tcp_server_t; 111 typedef struct _mu_ip_server *mu_ip_server_t;
111 typedef struct _mu_m_server *mu_m_server_t; 112 typedef struct _mu_m_server *mu_m_server_t;
112 113
113 #define MU_FOLDER_ATTRIBUTE_DIRECTORY 0x001 114 #define MU_FOLDER_ATTRIBUTE_DIRECTORY 0x001
......
...@@ -142,7 +142,7 @@ mu_tcpwrapper_access (int fd) ...@@ -142,7 +142,7 @@ mu_tcpwrapper_access (int fd)
142 #endif 142 #endif
143 143
144 int 144 int
145 mu_tcp_wrapper_prefork (int fd, struct sockaddr *sa, int salen) 145 mu_tcp_wrapper_prefork (int fd, void *data, struct sockaddr *sa, int salen)
146 { 146 {
147 if (mu_tcp_wrapper_enable && !mu_tcpwrapper_access (fd)) 147 if (mu_tcp_wrapper_enable && !mu_tcpwrapper_access (fd))
148 { 148 {
......
...@@ -31,7 +31,8 @@ extern int mu_tcp_wrapper_cb_hosts_deny_syslog (mu_debug_t debug, void *data, ...@@ -31,7 +31,8 @@ extern int mu_tcp_wrapper_cb_hosts_deny_syslog (mu_debug_t debug, void *data,
31 char *arg); 31 char *arg);
32 extern int mu_tcpwrapper_access (int fd); 32 extern int mu_tcpwrapper_access (int fd);
33 extern void mu_tcpwrapper_cfg_init (void); 33 extern void mu_tcpwrapper_cfg_init (void);
34 extern int mu_tcp_wrapper_prefork (int fd, struct sockaddr *sa, int salen); 34 extern int mu_tcp_wrapper_prefork (int fd, void *data,
35 struct sockaddr *sa, int salen);
35 36
36 #ifdef WITH_LIBWRAP 37 #ifdef WITH_LIBWRAP
37 # define TCP_WRAPPERS_CONFIG { "tcp-wrappers", mu_cfg_section }, 38 # define TCP_WRAPPERS_CONFIG { "tcp-wrappers", mu_cfg_section },
......
1 /* GNU Mailutils -- a suite of utilities for electronic mail 1 /* GNU Mailutils -- a suite of utilities for electronic mail
2 Copyright (C) 2007 Free Software Foundation, Inc. 2 Copyright (C) 2007, 2008 Free Software Foundation, Inc.
3 3
4 This library is free software; you can redistribute it and/or 4 This library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Lesser General Public 5 modify it under the terms of the GNU Lesser General Public
...@@ -29,7 +29,6 @@ static struct mu_cmdline_capa *all_cmdline_capa[] = { ...@@ -29,7 +29,6 @@ static struct mu_cmdline_capa *all_cmdline_capa[] = {
29 &mu_locking_cmdline, 29 &mu_locking_cmdline,
30 &mu_address_cmdline, 30 &mu_address_cmdline,
31 &mu_mailer_cmdline, 31 &mu_mailer_cmdline,
32 &mu_daemon_cmdline,
33 &mu_debug_cmdline, 32 &mu_debug_cmdline,
34 &mu_pam_cmdline, 33 &mu_pam_cmdline,
35 &mu_gsasl_cmdline, 34 &mu_gsasl_cmdline,
......
1 /* GNU Mailutils -- a suite of utilities for electronic mail 1 /* GNU Mailutils -- a suite of utilities for electronic mail
2 Copyright (C) 2007 Free Software Foundation, Inc. 2 Copyright (C) 2007, 2008 Free Software Foundation, Inc.
3 3
4 This library is free software; you can redistribute it and/or 4 This library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Lesser General Public 5 modify it under the terms of the GNU Lesser General Public
...@@ -22,7 +22,6 @@ ...@@ -22,7 +22,6 @@
22 #include "cmdline.h" 22 #include "cmdline.h"
23 #include <string.h> 23 #include <string.h>
24 #include <mailutils/syslog.h> 24 #include <mailutils/syslog.h>
25 #include <mailutils/daemon.h>
26 #include <mailutils/mailbox.h> 25 #include <mailutils/mailbox.h>
27 26
28 27
...@@ -488,91 +487,6 @@ struct mu_cmdline_capa mu_mailer_cmdline = { ...@@ -488,91 +487,6 @@ struct mu_cmdline_capa mu_mailer_cmdline = {
488 }; 487 };
489 488
490 489
491 /* ************************************************************************* */
492 /* Daemon */
493 /* ************************************************************************* */
494
495 /* Options used by programs that become daemons. */
496 static struct argp_option mu_daemon_argp_option[] = {
497 {"daemon", 'd', N_("NUMBER"), OPTION_ARG_OPTIONAL,
498 N_("Runs in daemon mode with a maximum of NUMBER children")},
499 {"inetd", 'i', 0, 0,
500 N_("Run in inetd mode"), 0},
501 {"port", 'p', N_("PORT"), 0,
502 N_("Listen on specified port number"), 0},
503 {"timeout", 't', N_("NUMBER"), OPTION_HIDDEN,
504 N_("Set idle timeout value to NUMBER seconds"), 0},
505 {"transcript", 'x', NULL, 0,
506 N_("Output session transcript via syslog"), 0},
507 {"pidfile", 'P', N_("FILE"), OPTION_HIDDEN,
508 N_("Set PID file"), 0},
509 { NULL, 0, NULL, 0, NULL, 0 }
510 };
511
512 static error_t
513 mu_daemon_argp_parser (int key, char *arg, struct argp_state *state)
514 {
515 static struct mu_argp_node_list lst;
516
517 switch (key)
518 {
519 case 'd':
520 mu_argp_node_list_new (&lst, "mode", "daemon");
521 if (arg)
522 mu_argp_node_list_new (&lst, "max-children", arg);
523 break;
524
525 case 'i':
526 mu_argp_node_list_new (&lst, "mode", "inetd");
527 break;
528
529 case 'p':
530 mu_argp_node_list_new (&lst, "port", arg);
531 break;
532
533 case 'P':
534 mu_argp_node_list_new (&lst, "pidfile", arg);
535 break;
536
537 case 't':
538 mu_argp_node_list_new (&lst, "timeout", arg);
539 break;
540
541 case 'x':
542 mu_argp_node_list_new (&lst, "transcript", "yes");
543 break;
544
545 case ARGP_KEY_INIT:
546 mu_argp_node_list_init (&lst);
547 break;
548
549 case ARGP_KEY_FINI:
550 mu_argp_node_list_finish (&lst, "daemon", NULL);
551 break;
552
553 default:
554 return ARGP_ERR_UNKNOWN;
555 }
556 return 0;
557 }
558
559 struct argp mu_daemon_argp = {
560 mu_daemon_argp_option,
561 mu_daemon_argp_parser,
562 };
563
564 struct argp_child mu_daemon_argp_child = {
565 &mu_daemon_argp,
566 0,
567 N_("Daemon configuration options"),
568 0
569 };
570
571 struct mu_cmdline_capa mu_daemon_cmdline = {
572 "daemon", &mu_daemon_argp_child
573 };
574
575
576 static struct argp_option mu_debug_argp_options[] = 490 static struct argp_option mu_debug_argp_options[] =
577 { 491 {
578 { "debug-level", OPT_DEBUG_LEVEL, N_("LEVEL"), 0, 492 { "debug-level", OPT_DEBUG_LEVEL, N_("LEVEL"), 0,
...@@ -590,7 +504,8 @@ mu_debug_argp_parser (int key, char *arg, struct argp_state *state) ...@@ -590,7 +504,8 @@ mu_debug_argp_parser (int key, char *arg, struct argp_state *state)
590 switch (key) 504 switch (key)
591 { 505 {
592 case OPT_DEBUG_LEVEL: 506 case OPT_DEBUG_LEVEL:
593 mu_argp_node_list_new (&lst, "level", arg); 507 mu_global_debug_from_string (arg, "command line");
508 //mu_argp_node_list_new (&lst, "level", arg);
594 break; 509 break;
595 510
596 case OPT_LINE_INFO: 511 case OPT_LINE_INFO:
......
1 /* This file is part of GNU Mailutils 1 /* This file is part of GNU Mailutils
2 Copyright (C) 2007 Free Software Foundation, Inc. 2 Copyright (C) 2007, 2008 Free Software Foundation, Inc.
3 3
4 GNU Mailutils is free software; you can redistribute it and/or 4 GNU Mailutils is free software; you can redistribute it and/or
5 modify it under the terms of the GNU General Public License as 5 modify it under the terms of the GNU General Public License as
...@@ -21,13 +21,11 @@ ...@@ -21,13 +21,11 @@
21 #include <stdlib.h> 21 #include <stdlib.h>
22 #include <string.h> 22 #include <string.h>
23 #include "mailutils/libcfg.h" 23 #include "mailutils/libcfg.h"
24 #include <mailutils/daemon.h>
25 #include <mailutils/debug.h> 24 #include <mailutils/debug.h>
26 #include <mailutils/syslog.h> 25 #include <mailutils/syslog.h>
27 #include <mailutils/mailbox.h> 26 #include <mailutils/mailbox.h>
28 #include <mu_umaxtostr.h> 27 #include <mu_umaxtostr.h>
29 28
30 static struct mu_gocs_daemon daemon_settings;
31 static struct mu_gocs_locking locking_settings; 29 static struct mu_gocs_locking locking_settings;
32 static struct mu_gocs_logging logging_settings; 30 static struct mu_gocs_logging logging_settings;
33 static struct mu_gocs_mailbox mailbox_settings; 31 static struct mu_gocs_mailbox mailbox_settings;
...@@ -153,68 +151,6 @@ DCL_CFG_CAPA (logging); ...@@ -153,68 +151,6 @@ DCL_CFG_CAPA (logging);
153 151
154 152
155 /* ************************************************************************* */ 153 /* ************************************************************************* */
156 /* Daemon */
157 /* ************************************************************************* */
158
159 static int
160 _cb_daemon_mode (mu_debug_t debug, void *data, char *arg)
161 {
162 if (strcmp (arg, "inetd") == 0
163 || strcmp (arg, "interactive") == 0)
164 daemon_settings.mode = MODE_INTERACTIVE;
165 else if (strcmp (arg, "daemon") == 0)
166 daemon_settings.mode = MODE_DAEMON;
167 else
168 {
169 mu_cfg_format_error (debug, MU_DEBUG_ERROR, _("unknown daemon mode"));
170 return 1;
171 }
172 return 0;
173 }
174
175 static struct mu_cfg_param mu_daemon_param[] = {
176 { "max-children", mu_cfg_ulong, &daemon_settings.maxchildren, 0, NULL,
177 N_("Maximum number of children processes to run simultaneously.") },
178 { "mode", mu_cfg_callback, NULL, 0, _cb_daemon_mode,
179 N_("Set daemon mode (either inetd (or interactive) or daemon)."),
180 N_("mode") },
181 { "transcript", mu_cfg_bool, &daemon_settings.transcript, 0, NULL,
182 N_("Log the session transcript.") },
183 { "pidfile", mu_cfg_string, &daemon_settings.pidfile, 0, NULL,
184 N_("Store PID of the master process in this file."),
185 N_("file") },
186 { "port", mu_cfg_ushort, &daemon_settings.port, 0, NULL,
187 N_("Listen on the specified port number.") },
188 { "timeout", mu_cfg_ulong, &daemon_settings.timeout, 0, NULL,
189 N_("Set idle timeout.") },
190 { NULL }
191 };
192
193 int
194 mu_daemon_section_parser
195 (enum mu_cfg_section_stage stage, const mu_cfg_node_t *node,
196 const char *section_label, void **section_data,
197 void *call_data, mu_cfg_tree_t *tree)
198 {
199 switch (stage)
200 {
201 case mu_cfg_section_start:
202 daemon_settings = mu_gocs_daemon;
203 break;
204
205 case mu_cfg_section_end:
206 mu_gocs_daemon = daemon_settings;
207 mu_gocs_store ("daemon", &daemon_settings);
208 }
209 return 0;
210 }
211
212 struct mu_cfg_capa mu_daemon_cfg_capa = {
213 "daemon", mu_daemon_param, mu_daemon_section_parser
214 };
215
216
217 /* ************************************************************************* */
218 /* Debug */ 154 /* Debug */
219 /* ************************************************************************* */ 155 /* ************************************************************************* */
220 156
......
1 /* This file is part of GNU Mailutils 1 /* This file is part of GNU Mailutils
2 Copyright (C) 2007 Free Software Foundation, Inc. 2 Copyright (C) 2007, 2008 Free Software Foundation, Inc.
3 3
4 GNU Mailutils is free software; you can redistribute it and/or 4 GNU Mailutils is free software; you can redistribute it and/or
5 modify it under the terms of the GNU General Public License as 5 modify it under the terms of the GNU General Public License as
...@@ -37,7 +37,6 @@ struct mu_cfg_capa *cfg_capa_table[] = { ...@@ -37,7 +37,6 @@ struct mu_cfg_capa *cfg_capa_table[] = {
37 S (tls), 37 S (tls),
38 S (virtdomain), 38 S (virtdomain),
39 S (sieve), 39 S (sieve),
40 S (daemon),
41 S (ldap), 40 S (ldap),
42 S (debug), 41 S (debug),
43 NULL 42 NULL
......
1 /* GNU Mailutils -- a suite of utilities for electronic mail 1 /* GNU Mailutils -- a suite of utilities for electronic mail
2 Copyright (C) 1999, 2000, 2001, 2003, 2 Copyright (C) 1999, 2000, 2001, 2003,
3 2004, 2005, 2006, 2007 Free Software Foundation, Inc. 3 2004, 2005, 2006, 2007, 2008 Free Software Foundation, Inc.
4 4
5 This library is free software; you can redistribute it and/or 5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public 6 modify it under the terms of the GNU Lesser General Public
...@@ -1236,6 +1236,8 @@ mbox_quick_get_message (mu_mailbox_t mailbox, mu_message_qid_t qid, ...@@ -1236,6 +1236,8 @@ mbox_quick_get_message (mu_mailbox_t mailbox, mu_message_qid_t qid,
1236 status = mbox_scan1 (mailbox, offset, 0); 1236 status = mbox_scan1 (mailbox, offset, 0);
1237 if (status != 0) 1237 if (status != 0)
1238 return status; 1238 return status;
1239 if (mud->messages_count == 0)
1240 return MU_ERR_NOENT;
1239 } 1241 }
1240 1242
1241 /* Quick access mode retrieves only one message */ 1243 /* Quick access mode retrieves only one message */
......
1 /* GNU Mailutils -- a suite of utilities for electronic mail 1 /* GNU Mailutils -- a suite of utilities for electronic mail
2 Copyright (C) 2007 Free Software Foundation, Inc. 2 Copyright (C) 2007, 2008 Free Software Foundation, Inc.
3 3
4 GNU Mailutils is free software; you can redistribute it and/or modify 4 GNU Mailutils is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by 5 it under the terms of the GNU General Public License as published by
...@@ -564,7 +564,8 @@ typedef union ...@@ -564,7 +564,8 @@ typedef union
564 } all_addr_t; 564 } all_addr_t;
565 565
566 int 566 int
567 lmtp_connection (int fd, void *data, time_t timeout, int transcript) 567 lmtp_connection (int fd, struct sockaddr *sa, int salen, void *data,
568 mu_ip_server_t srv, time_t timeout, int transcript)
568 { 569 {
569 lmtp_transcript = transcript; 570 lmtp_transcript = transcript;
570 lmtp_loop (fdopen (fd, "r"), fdopen (fd, "w"), timeout); 571 lmtp_loop (fdopen (fd, "r"), fdopen (fd, "w"), timeout);
......
...@@ -133,7 +133,8 @@ int switch_user_id (struct mu_auth_data *auth, int user); ...@@ -133,7 +133,8 @@ int switch_user_id (struct mu_auth_data *auth, int user);
133 133
134 int maidag_stdio_delivery (int argc, char **argv); 134 int maidag_stdio_delivery (int argc, char **argv);
135 int maidag_lmtp_server (void); 135 int maidag_lmtp_server (void);
136 int lmtp_connection (int fd, void *data, time_t timeout, int transcript); 136 int lmtp_connection (int fd, struct sockaddr *sa, int salen, void *data,
137 mu_ip_server_t srv, time_t timeout, int transcript);
137 138
138 void mailer_err (char *fmt, ...); 139 void mailer_err (char *fmt, ...);
139 void notify_biff (mu_mailbox_t mbox, char *name, size_t size); 140 void notify_biff (mu_mailbox_t mbox, char *name, size_t size);
......
1 ## Process this file with GNU Automake to create Makefile.in 1 ## Process this file with GNU Automake to create Makefile.in
2 2
3 ## Copyright (C) 2000, 2001, 2002, 2004, 2005, 2006, 2007 3 ## Copyright (C) 2000, 2001, 2002, 2004, 2005, 2006, 2007, 2008
4 ## Free Software Foundation, Inc. 4 ## Free Software Foundation, Inc.
5 ## 5 ##
6 ## GNU Mailutils is free software; you can redistribute it and/or 6 ## GNU Mailutils is free software; you can redistribute it and/or
...@@ -67,6 +67,7 @@ libmailutils_la_SOURCES = \ ...@@ -67,6 +67,7 @@ libmailutils_la_SOURCES = \
67 gocs.c\ 67 gocs.c\
68 header.c\ 68 header.c\
69 iterator.c\ 69 iterator.c\
70 ipsrv.c\
70 kwd.c\ 71 kwd.c\
71 list.c\ 72 list.c\
72 locale.c\ 73 locale.c\
...@@ -106,7 +107,6 @@ libmailutils_la_SOURCES = \ ...@@ -106,7 +107,6 @@ libmailutils_la_SOURCES = \
106 system.c\ 107 system.c\
107 ticket.c\ 108 ticket.c\
108 tcp.c\ 109 tcp.c\
109 tcpsrv.c\
110 url.c\ 110 url.c\
111 vartab.c\ 111 vartab.c\
112 version.c\ 112 version.c\
......
1 /* GNU Mailutils -- a suite of utilities for electronic mail 1 /* GNU Mailutils -- a suite of utilities for electronic mail
2 Copyright (C) 1999, 2000, 2001, 2002, 2003, 2 Copyright (C) 1999, 2000, 2001, 2002, 2003,
3 2004, 2005, 2006, 2007 Free Software Foundation, Inc. 3 2004, 2005, 2006, 2007, 2008 Free Software Foundation, Inc.
4 4
5 This library is free software; you can redistribute it and/or 5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public 6 modify it under the terms of the GNU Lesser General Public
...@@ -347,6 +347,9 @@ amd_open (mu_mailbox_t mailbox, int flags) ...@@ -347,6 +347,9 @@ amd_open (mu_mailbox_t mailbox, int flags)
347 if (!S_ISDIR (st.st_mode)) 347 if (!S_ISDIR (st.st_mode))
348 return EINVAL; 348 return EINVAL;
349 349
350 if (mailbox->locker == NULL)
351 mu_locker_create (&mailbox->locker, "/dev/null", 0);
352
350 return 0; 353 return 0;
351 } 354 }
352 355
...@@ -582,7 +585,8 @@ _amd_delim (char *str) ...@@ -582,7 +585,8 @@ _amd_delim (char *str)
582 } 585 }
583 586
584 static int 587 static int
585 _amd_message_save (struct _amd_data *amd, struct _amd_message *mhm, int expunge) 588 _amd_message_save (struct _amd_data *amd, struct _amd_message *mhm,
589 int expunge)
586 { 590 {
587 mu_stream_t stream = NULL; 591 mu_stream_t stream = NULL;
588 char *name = NULL, *buf = NULL, *msg_name; 592 char *name = NULL, *buf = NULL, *msg_name;
...@@ -708,6 +712,7 @@ _amd_message_save (struct _amd_data *amd, struct _amd_message *mhm, int expunge) ...@@ -708,6 +712,7 @@ _amd_message_save (struct _amd_data *amd, struct _amd_message *mhm, int expunge)
708 free (buf); 712 free (buf);
709 fclose (fp); 713 fclose (fp);
710 714
715 /* FIXME: This does not work for maildir. */
711 msg_name = amd->msg_file_name (mhm, mhm->deleted); 716 msg_name = amd->msg_file_name (mhm, mhm->deleted);
712 if (rename (name, msg_name)) 717 if (rename (name, msg_name))
713 status = errno; 718 status = errno;
......
...@@ -78,18 +78,5 @@ mu_daemon_remove_pidfile (void) ...@@ -78,18 +78,5 @@ mu_daemon_remove_pidfile (void)
78 } 78 }
79 } 79 }
80 80
81
82 struct mu_gocs_daemon mu_gocs_daemon;
83
84 int
85 mu_gocs_daemon_init (void *data)
86 {
87 if (data)
88 {
89 struct mu_gocs_daemon *cfg = data;
90 mu_gocs_daemon = *cfg;
91 }
92 return 0;
93 }
94 81
95 82
......
1 /* GNU Mailutils -- a suite of utilities for electronic mail 1 /* GNU Mailutils -- a suite of utilities for electronic mail
2 Copyright (C) 2007 Free Software Foundation, Inc. 2 Copyright (C) 2007, 2008 Free Software Foundation, Inc.
3 3
4 This library is free software; you can redistribute it and/or 4 This library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Lesser General Public 5 modify it under the terms of the GNU Lesser General Public
...@@ -297,7 +297,6 @@ static struct mu_gocs_entry std_gocs_table[] = { ...@@ -297,7 +297,6 @@ static struct mu_gocs_entry std_gocs_table[] = {
297 { "license", mu_gocs_dummy }, 297 { "license", mu_gocs_dummy },
298 { "mailbox", mu_gocs_mailbox_init }, 298 { "mailbox", mu_gocs_mailbox_init },
299 { "locking", mu_gocs_locking_init }, 299 { "locking", mu_gocs_locking_init },
300 { "daemon", mu_gocs_daemon_init },
301 { "address", mu_gocs_source_email_init }, 300 { "address", mu_gocs_source_email_init },
302 { "mailer", mu_gocs_mailer_init }, 301 { "mailer", mu_gocs_mailer_init },
303 { "logging", mu_gocs_logging_init }, 302 { "logging", mu_gocs_logging_init },
......
1 /* GNU Mailutils -- a suite of utilities for electronic mail 1 /* GNU Mailutils -- a suite of utilities for electronic mail
2 Copyright (C) 2007 Free Software Foundation, Inc. 2 Copyright (C) 2007, 2008 Free Software Foundation, Inc.
3 3
4 This library is free software; you can redistribute it and/or 4 This library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Lesser General Public 5 modify it under the terms of the GNU Lesser General Public
...@@ -36,29 +36,52 @@ ...@@ -36,29 +36,52 @@
36 #include <mailutils/nls.h> 36 #include <mailutils/nls.h>
37 37
38 38
39 struct _mu_tcp_server 39 struct _mu_ip_server
40 { 40 {
41 char *ident; 41 char *ident;
42 struct sockaddr *addr; 42 struct sockaddr *addr;
43 int addrlen; 43 int addrlen;
44 int backlog; 44 int fd;
45 int fd; 45 int type;
46 mu_debug_t debug; 46 mu_debug_t debug;
47 mu_acl_t acl; 47 mu_acl_t acl;
48 mu_tcp_server_conn_fp f_conn; 48 mu_ip_server_conn_fp f_conn;
49 mu_tcp_server_intr_fp f_intr; 49 mu_ip_server_intr_fp f_intr;
50 mu_tcp_server_free_fp f_free; 50 mu_ip_server_free_fp f_free;
51 void *data; 51 void *data;
52 union
53 {
54 struct
55 {
56 int backlog;
57 } tcp_data;
58 struct
59 {
60 char *buf;
61 size_t bufsize;
62 ssize_t rdsize;
63 } udp_data;
64 } v;
52 }; 65 };
53 66
54 #define IDENTSTR(s) ((s)->ident ? (s)->ident : "default") 67 #define IDENTSTR(s) ((s)->ident ? (s)->ident : "default")
55 68
56 int 69 int
57 mu_tcp_server_create (mu_tcp_server_t *psrv, struct sockaddr *addr, 70 mu_ip_server_create (mu_ip_server_t *psrv, struct sockaddr *addr,
58 int addrlen) 71 int addrlen, int type)
59 { 72 {
60 struct _mu_tcp_server *srv; 73 struct _mu_ip_server *srv;
61 mu_log_level_t level; 74 mu_log_level_t level;
75
76 switch (type)
77 {
78 case MU_IP_UDP:
79 case MU_IP_TCP:
80 break;
81
82 default:
83 return EINVAL;
84 }
62 85
63 srv = calloc (1, sizeof *srv); 86 srv = calloc (1, sizeof *srv);
64 if (!srv) 87 if (!srv)
...@@ -71,22 +94,32 @@ mu_tcp_server_create (mu_tcp_server_t *psrv, struct sockaddr *addr, ...@@ -71,22 +94,32 @@ mu_tcp_server_create (mu_tcp_server_t *psrv, struct sockaddr *addr,
71 } 94 }
72 memcpy (srv->addr, addr, addrlen); 95 memcpy (srv->addr, addr, addrlen);
73 srv->addrlen = addrlen; 96 srv->addrlen = addrlen;
74 level = mu_global_debug_level ("tcp_server"); 97 srv->type = type;
98 level = mu_global_debug_level ("ip_server");
75 if (level) 99 if (level)
76 { 100 {
77 mu_debug_create (&srv->debug, NULL); 101 mu_debug_create (&srv->debug, NULL);
78 mu_debug_set_level (srv->debug, level); 102 mu_debug_set_level (srv->debug, level);
79 } 103 }
80 srv->fd = -1; 104 srv->fd = -1;
81 srv->backlog = 4; 105 switch (type)
106 {
107 case MU_IP_UDP:
108 srv->v.udp_data.bufsize = 4096;
109 break;
110
111 case MU_IP_TCP:
112 srv->v.tcp_data.backlog = 4;
113 }
114
82 *psrv = srv; 115 *psrv = srv;
83 return 0; 116 return 0;
84 } 117 }
85 118
86 int 119 int
87 mu_tcp_server_destroy (mu_tcp_server_t *psrv) 120 mu_ip_server_destroy (mu_ip_server_t *psrv)
88 { 121 {
89 mu_tcp_server_t srv; 122 mu_ip_server_t srv;
90 if (!psrv) 123 if (!psrv)
91 return EINVAL; 124 return EINVAL;
92 srv = *psrv; 125 srv = *psrv;
...@@ -97,13 +130,15 @@ mu_tcp_server_destroy (mu_tcp_server_t *psrv) ...@@ -97,13 +130,15 @@ mu_tcp_server_destroy (mu_tcp_server_t *psrv)
97 close (srv->fd); 130 close (srv->fd);
98 free (srv->addr); 131 free (srv->addr);
99 free (srv->ident); 132 free (srv->ident);
133 if (srv->type == MU_IP_UDP && srv->v.udp_data.buf)
134 free (srv->v.udp_data.buf);
100 free (srv); 135 free (srv);
101 *psrv = NULL; 136 *psrv = NULL;
102 return 0; 137 return 0;
103 } 138 }
104 139
105 int 140 int
106 mu_tcp_server_set_debug (mu_tcp_server_t srv, mu_debug_t debug) 141 mu_ip_server_set_debug (mu_ip_server_t srv, mu_debug_t debug)
107 { 142 {
108 if (!srv) 143 if (!srv)
109 return EINVAL; 144 return EINVAL;
...@@ -113,7 +148,7 @@ mu_tcp_server_set_debug (mu_tcp_server_t srv, mu_debug_t debug) ...@@ -113,7 +148,7 @@ mu_tcp_server_set_debug (mu_tcp_server_t srv, mu_debug_t debug)
113 } 148 }
114 149
115 int 150 int
116 mu_tcp_server_get_debug (mu_tcp_server_t srv, mu_debug_t *pdebug) 151 mu_ip_server_get_debug (mu_ip_server_t srv, mu_debug_t *pdebug)
117 { 152 {
118 if (!srv) 153 if (!srv)
119 return EINVAL; 154 return EINVAL;
...@@ -122,16 +157,50 @@ mu_tcp_server_get_debug (mu_tcp_server_t srv, mu_debug_t *pdebug) ...@@ -122,16 +157,50 @@ mu_tcp_server_get_debug (mu_tcp_server_t srv, mu_debug_t *pdebug)
122 } 157 }
123 158
124 int 159 int
125 mu_tcp_server_set_backlog (mu_tcp_server_t srv, int backlog) 160 mu_ip_server_get_type (mu_ip_server_t srv, int *ptype)
126 { 161 {
127 if (!srv) 162 if (!srv)
128 return EINVAL; 163 return EINVAL;
129 srv->backlog = backlog; 164 *ptype = srv->type;
130 return 0; 165 return 0;
131 } 166 }
132 167
133 int 168 int
134 mu_tcp_server_set_ident (mu_tcp_server_t srv, const char *ident) 169 mu_tcp_server_set_backlog (mu_ip_server_t srv, int backlog)
170 {
171 if (!srv || srv->type != MU_IP_TCP)
172 return EINVAL;
173 srv->v.tcp_data.backlog = backlog;
174 return 0;
175 }
176
177 int
178 mu_udp_server_get_bufsize (mu_ip_server_t srv, size_t *psize)
179 {
180 if (!srv || srv->type != MU_IP_UDP)
181 return EINVAL;
182 *psize = srv->v.udp_data.bufsize;
183 return 0;
184 }
185
186 int
187 mu_udp_server_set_bufsize (mu_ip_server_t srv, size_t size)
188 {
189 if (!srv || srv->type != MU_IP_UDP)
190 return EINVAL;
191 srv->v.udp_data.bufsize = size;
192 if (srv->v.udp_data.buf)
193 {
194 char *p = realloc (srv->v.udp_data.buf, size);
195 if (!p)
196 return ENOMEM;
197 srv->v.udp_data.buf = p;
198 }
199 return 0;
200 }
201
202 int
203 mu_ip_server_set_ident (mu_ip_server_t srv, const char *ident)
135 { 204 {
136 if (!srv) 205 if (!srv)
137 return EINVAL; 206 return EINVAL;
...@@ -144,7 +213,7 @@ mu_tcp_server_set_ident (mu_tcp_server_t srv, const char *ident) ...@@ -144,7 +213,7 @@ mu_tcp_server_set_ident (mu_tcp_server_t srv, const char *ident)
144 } 213 }
145 214
146 int 215 int
147 mu_tcp_server_set_acl (mu_tcp_server_t srv, mu_acl_t acl) 216 mu_ip_server_set_acl (mu_ip_server_t srv, mu_acl_t acl)
148 { 217 {
149 if (!srv) 218 if (!srv)
150 return EINVAL; 219 return EINVAL;
...@@ -153,7 +222,7 @@ mu_tcp_server_set_acl (mu_tcp_server_t srv, mu_acl_t acl) ...@@ -153,7 +222,7 @@ mu_tcp_server_set_acl (mu_tcp_server_t srv, mu_acl_t acl)
153 } 222 }
154 223
155 int 224 int
156 mu_tcp_server_set_conn (mu_tcp_server_t srv, mu_tcp_server_conn_fp conn) 225 mu_ip_server_set_conn (mu_ip_server_t srv, mu_ip_server_conn_fp conn)
157 { 226 {
158 if (!srv) 227 if (!srv)
159 return EINVAL; 228 return EINVAL;
...@@ -162,7 +231,7 @@ mu_tcp_server_set_conn (mu_tcp_server_t srv, mu_tcp_server_conn_fp conn) ...@@ -162,7 +231,7 @@ mu_tcp_server_set_conn (mu_tcp_server_t srv, mu_tcp_server_conn_fp conn)
162 } 231 }
163 232
164 int 233 int
165 mu_tcp_server_set_intr (mu_tcp_server_t srv, mu_tcp_server_intr_fp intr) 234 mu_ip_server_set_intr (mu_ip_server_t srv, mu_ip_server_intr_fp intr)
166 { 235 {
167 if (!srv) 236 if (!srv)
168 return EINVAL; 237 return EINVAL;
...@@ -171,8 +240,8 @@ mu_tcp_server_set_intr (mu_tcp_server_t srv, mu_tcp_server_intr_fp intr) ...@@ -171,8 +240,8 @@ mu_tcp_server_set_intr (mu_tcp_server_t srv, mu_tcp_server_intr_fp intr)
171 } 240 }
172 241
173 int 242 int
174 mu_tcp_server_set_data (mu_tcp_server_t srv, 243 mu_ip_server_set_data (mu_ip_server_t srv,
175 void *data, mu_tcp_server_free_fp free) 244 void *data, mu_ip_server_free_fp free)
176 { 245 {
177 if (!srv) 246 if (!srv)
178 return EINVAL; 247 return EINVAL;
...@@ -181,8 +250,8 @@ mu_tcp_server_set_data (mu_tcp_server_t srv, ...@@ -181,8 +250,8 @@ mu_tcp_server_set_data (mu_tcp_server_t srv,
181 return 0; 250 return 0;
182 } 251 }
183 252
184 static int 253 int
185 family_to_proto (int family) 254 mu_address_family_to_domain (int family)
186 { 255 {
187 switch (family) 256 switch (family)
188 { 257 {
...@@ -198,7 +267,7 @@ family_to_proto (int family) ...@@ -198,7 +267,7 @@ family_to_proto (int family)
198 } 267 }
199 268
200 int 269 int
201 mu_tcp_server_open (mu_tcp_server_t srv) 270 mu_ip_server_open (mu_ip_server_t srv)
202 { 271 {
203 int fd; 272 int fd;
204 273
...@@ -214,7 +283,8 @@ mu_tcp_server_open (mu_tcp_server_t srv) ...@@ -214,7 +283,8 @@ mu_tcp_server_open (mu_tcp_server_t srv)
214 free (p); 283 free (p);
215 } 284 }
216 285
217 fd = socket (family_to_proto (srv->addr->sa_family), SOCK_STREAM, 0); 286 fd = socket (mu_address_family_to_domain (srv->addr->sa_family),
287 ((srv->type == MU_IP_UDP) ? SOCK_DGRAM : SOCK_STREAM), 0);
218 if (fd == -1) 288 if (fd == -1)
219 { 289 {
220 MU_DEBUG2 (srv->debug, MU_DEBUG_ERROR, 290 MU_DEBUG2 (srv->debug, MU_DEBUG_ERROR,
...@@ -275,12 +345,15 @@ mu_tcp_server_open (mu_tcp_server_t srv) ...@@ -275,12 +345,15 @@ mu_tcp_server_open (mu_tcp_server_t srv)
275 return errno; 345 return errno;
276 } 346 }
277 347
278 if (listen (fd, srv->backlog) == -1) 348 if (srv->type == MU_IP_TCP)
279 { 349 {
280 MU_DEBUG2 (srv->debug, MU_DEBUG_ERROR, 350 if (listen (fd, srv->v.tcp_data.backlog) == -1)
281 "%s: listen: %s\n", IDENTSTR (srv), mu_strerror (errno)); 351 {
282 close (fd); 352 MU_DEBUG2 (srv->debug, MU_DEBUG_ERROR,
283 return errno; 353 "%s: listen: %s\n", IDENTSTR (srv), mu_strerror (errno));
354 close (fd);
355 return errno;
356 }
284 } 357 }
285 358
286 srv->fd = fd; 359 srv->fd = fd;
...@@ -288,7 +361,7 @@ mu_tcp_server_open (mu_tcp_server_t srv) ...@@ -288,7 +361,7 @@ mu_tcp_server_open (mu_tcp_server_t srv)
288 } 361 }
289 362
290 int 363 int
291 mu_tcp_server_shutdown (mu_tcp_server_t srv) 364 mu_ip_server_shutdown (mu_ip_server_t srv)
292 { 365 {
293 if (!srv || srv->fd != -1) 366 if (!srv || srv->fd != -1)
294 return EINVAL; 367 return EINVAL;
...@@ -305,19 +378,20 @@ mu_tcp_server_shutdown (mu_tcp_server_t srv) ...@@ -305,19 +378,20 @@ mu_tcp_server_shutdown (mu_tcp_server_t srv)
305 } 378 }
306 379
307 int 380 int
308 mu_tcp_server_accept (mu_tcp_server_t srv, void *call_data) 381 mu_ip_tcp_accept (mu_ip_server_t srv, void *call_data)
309 { 382 {
310 int rc; 383 int rc;
311 int connfd; 384 int connfd;
312 union 385 union
313 { 386 {
314 struct sockaddr sa; 387 struct sockaddr sa;
315 char buffer[512]; 388 struct sockaddr_in s_in;
389 struct sockaddr_un s_un;
316 } client; 390 } client;
317 391
318 socklen_t size = sizeof (client); 392 socklen_t size = sizeof (client);
319 393
320 if (!srv || srv->fd == -1) 394 if (!srv || srv->fd == -1 || srv->type == MU_IP_UDP)
321 return EINVAL; 395 return EINVAL;
322 396
323 connfd = accept (srv->fd, &client.sa, &size); 397 connfd = accept (srv->fd, &client.sa, &size);
...@@ -327,7 +401,7 @@ mu_tcp_server_accept (mu_tcp_server_t srv, void *call_data) ...@@ -327,7 +401,7 @@ mu_tcp_server_accept (mu_tcp_server_t srv, void *call_data)
327 if (ec == EINTR) 401 if (ec == EINTR)
328 { 402 {
329 if (srv->f_intr && srv->f_intr (srv->data, call_data)) 403 if (srv->f_intr && srv->f_intr (srv->data, call_data))
330 mu_tcp_server_shutdown (srv); 404 mu_ip_server_shutdown (srv);
331 } 405 }
332 return ec; 406 return ec;
333 } 407 }
...@@ -351,23 +425,117 @@ mu_tcp_server_accept (mu_tcp_server_t srv, void *call_data) ...@@ -351,23 +425,117 @@ mu_tcp_server_accept (mu_tcp_server_t srv, void *call_data)
351 } 425 }
352 } 426 }
353 rc = srv->f_conn (connfd, &client.sa, size, srv->data, call_data, srv); 427 rc = srv->f_conn (connfd, &client.sa, size, srv->data, call_data, srv);
354 if (rc)
355 mu_tcp_server_shutdown (srv);
356 close (connfd); 428 close (connfd);
357 return rc; 429 return rc;
358 } 430 }
359 431
360 int 432 int
361 mu_tcp_server_loop (mu_tcp_server_t srv, void *call_data) 433 mu_ip_udp_accept (mu_ip_server_t srv, void *call_data)
434 {
435 int rc;
436 union
437 {
438 struct sockaddr sa;
439 struct sockaddr_in s_in;
440 struct sockaddr_un s_un;
441 } client;
442 fd_set rdset;
443
444 socklen_t salen = sizeof (client);
445 ssize_t size;
446
447 if (!srv->v.udp_data.buf)
448 {
449 srv->v.udp_data.buf = malloc (srv->v.udp_data.bufsize);
450 if (!srv->v.udp_data.buf)
451 return ENOMEM;
452 }
453
454 FD_ZERO (&rdset);
455 FD_SET (srv->fd, &rdset);
456 for (;;)
457 {
458 rc = select (srv->fd + 1, &rdset, NULL, NULL, NULL);
459 if (rc == -1)
460 {
461 if (errno == EINTR)
462 {
463 if (srv->f_intr && srv->f_intr (srv->data, call_data))
464 break;
465 else
466 continue;
467 }
468 }
469 else
470 break;
471 }
472
473 if (rc == -1)
474 return errno;
475
476 size = recvfrom (srv->fd, srv->v.udp_data.buf, srv->v.udp_data.bufsize,
477 0, &client.sa, &salen);
478 if (size < 0)
479 {
480 MU_DEBUG2 (srv->debug, MU_DEBUG_ERROR,
481 "%s: recvfrom: %s",
482 IDENTSTR (srv), strerror (errno));
483 return MU_ERR_FAILURE;
484 }
485 srv->v.udp_data.rdsize = size;
486
487 if (srv->acl)
488 {
489 mu_acl_result_t res;
490 int rc = mu_acl_check_sockaddr (srv->acl, &client.sa, size, &res);
491 if (rc)
492 MU_DEBUG2 (srv->debug, MU_DEBUG_ERROR,
493 "%s: mu_acl_check_sockaddr: %s\n",
494 IDENTSTR (srv), strerror (rc));
495 if (res == mu_acl_result_deny)
496 {
497 char *p = mu_sockaddr_to_astr (srv->addr, srv->addrlen);
498 mu_diag_output (MU_DIAG_INFO, "Denying connection from %s", p);
499 free (p);
500 return 0;
501 }
502 }
503 rc = srv->f_conn (-1, &client.sa, size, srv->data, call_data, srv);
504 return rc;
505 }
506
507 int
508 mu_ip_server_accept (mu_ip_server_t srv, void *call_data)
509 {
510 int rc;
511 if (!srv || srv->fd == -1)
512 return EINVAL;
513 switch (srv->type)
514 {
515 case MU_IP_UDP:
516 rc = mu_ip_udp_accept (srv, call_data);
517 break;
518
519 case MU_IP_TCP:
520 rc = mu_ip_tcp_accept (srv, call_data);
521 }
522
523 if (rc)
524 mu_ip_server_shutdown (srv);
525 return rc;
526 }
527
528 int
529 mu_ip_server_loop (mu_ip_server_t srv, void *call_data)
362 { 530 {
363 if (!srv) 531 if (!srv)
364 return EINVAL; 532 return EINVAL;
365 while (srv->fd != -1) 533 while (srv->fd != -1)
366 { 534 {
367 int rc = mu_tcp_server_accept (srv, call_data); 535 int rc = mu_ip_server_accept (srv, call_data);
368 if (rc && rc != EINTR) 536 if (rc && rc != EINTR)
369 { 537 {
370 mu_tcp_server_shutdown (srv); 538 mu_ip_server_shutdown (srv);
371 return rc; 539 return rc;
372 } 540 }
373 } 541 }
...@@ -375,13 +543,23 @@ mu_tcp_server_loop (mu_tcp_server_t srv, void *call_data) ...@@ -375,13 +543,23 @@ mu_tcp_server_loop (mu_tcp_server_t srv, void *call_data)
375 } 543 }
376 544
377 int 545 int
378 mu_tcp_server_get_fd (mu_tcp_server_t srv) 546 mu_ip_server_get_fd (mu_ip_server_t srv)
379 { 547 {
380 return srv->fd; 548 return srv->fd;
381 } 549 }
382 550
383 int 551 int
384 mu_tcp_server_get_sockaddr (mu_tcp_server_t srv, struct sockaddr *s, int *size) 552 mu_udp_server_get_rdata (mu_ip_server_t srv, char **pbuf, size_t *pbufsize)
553 {
554 if (!srv || srv->type != MU_IP_UDP)
555 return EINVAL;
556 *pbuf = srv->v.udp_data.buf;
557 *pbufsize = srv->v.udp_data.rdsize;
558 return 0;
559 }
560
561 int
562 mu_ip_server_get_sockaddr (mu_ip_server_t srv, struct sockaddr *s, int *size)
385 { 563 {
386 int len; 564 int len;
387 565
......
1 /* GNU Mailutils -- a suite of utilities for electronic mail 1 /* GNU Mailutils -- a suite of utilities for electronic mail
2 Copyright (C) 1999, 2000, 2001, 2005, 2006, 2 Copyright (C) 1999, 2000, 2001, 2005, 2006,
3 2007 Free Software Foundation, Inc. 3 2007, 2008 Free Software Foundation, Inc.
4 4
5 This library is free software; you can redistribute it and/or 5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public 6 modify it under the terms of the GNU Lesser General Public
...@@ -103,11 +103,15 @@ static int unlock_kernel (mu_locker_t); ...@@ -103,11 +103,15 @@ static int unlock_kernel (mu_locker_t);
103 static int prelock_common (mu_locker_t); 103 static int prelock_common (mu_locker_t);
104 104
105 static struct locker_tab locker_tab[] = { 105 static struct locker_tab locker_tab[] = {
106 /* MU_LOCKER_TYPE_DOTLOCK */
106 { init_dotlock, destroy_dotlock, prelock_common, 107 { init_dotlock, destroy_dotlock, prelock_common,
107 lock_dotlock, unlock_dotlock }, 108 lock_dotlock, unlock_dotlock },
109 /* MU_LOCKER_TYPE_EXTERNAL */
108 { init_external, destroy_external, prelock_common, 110 { init_external, destroy_external, prelock_common,
109 lock_external, unlock_external }, 111 lock_external, unlock_external },
112 /* MU_LOCKER_TYPE_KERNEL */
110 { init_kernel, NULL, NULL, lock_kernel, unlock_kernel }, 113 { init_kernel, NULL, NULL, lock_kernel, unlock_kernel },
114 /* MU_LOCKER_TYPE_NULL */
111 { NULL, NULL, NULL, NULL, NULL } 115 { NULL, NULL, NULL, NULL, NULL }
112 }; 116 };
113 117
...@@ -246,17 +250,37 @@ mu_locker_set_default_external_program (char *path) ...@@ -246,17 +250,37 @@ mu_locker_set_default_external_program (char *path)
246 } 250 }
247 251
248 int 252 int
249 mu_locker_set_flags (mu_locker_t locker, int flags) 253 mu_locker_mod_flags (mu_locker_t locker, int flags,
254 enum mu_locker_set_mode mode)
250 { 255 {
251 unsigned otype, ntype; 256 unsigned otype, ntype;
257 int new_flags;
252 258
253 if (!locker) 259 if (!locker)
254 return MU_ERR_LOCKER_NULL; 260 return MU_ERR_LOCKER_NULL;
255 261
262 switch (mode)
263 {
264 case mu_locker_assign:
265 new_flags = flags;
266 break;
267
268 case mu_locker_set_bit:
269 new_flags = locker->flags | flags;
270 break;
271
272 case mu_locker_clear_bit:
273 new_flags = locker->flags & ~flags;
274 break;
275
276 default:
277 return EINVAL;
278 }
279
256 otype = MU_LOCKER_TYPE (locker); 280 otype = MU_LOCKER_TYPE (locker);
257 if (otype >= MU_LOCKER_NTYPES) 281 if (otype >= MU_LOCKER_NTYPES)
258 return EINVAL; 282 return EINVAL;
259 ntype = MU_LOCKER_FLAG_TO_TYPE (flags); 283 ntype = MU_LOCKER_FLAG_TO_TYPE (new_flags);
260 if (ntype >= MU_LOCKER_NTYPES) 284 if (ntype >= MU_LOCKER_NTYPES)
261 return EINVAL; 285 return EINVAL;
262 286
...@@ -266,22 +290,28 @@ mu_locker_set_flags (mu_locker_t locker, int flags) ...@@ -266,22 +290,28 @@ mu_locker_set_flags (mu_locker_t locker, int flags)
266 290
267 if (locker_tab[otype].destroy) 291 if (locker_tab[otype].destroy)
268 locker_tab[otype].destroy (locker); 292 locker_tab[otype].destroy (locker);
269 locker->flags = flags; 293 locker->flags = new_flags;
270 if (locker_tab[otype].init) 294 if (locker_tab[ntype].init)
271 { 295 {
272 rc = locker_tab[otype].init (locker); 296 rc = locker_tab[ntype].init (locker);
273 if (rc) 297 if (rc)
274 locker->flags = MU_LOCKER_NULL; 298 locker->flags = MU_LOCKER_NULL;
275 return rc; 299 return rc;
276 } 300 }
277 } 301 }
278 else 302 else
279 locker->flags = flags; 303 locker->flags = new_flags;
280 304
281 return 0; 305 return 0;
282 } 306 }
283 307
284 int 308 int
309 mu_locker_set_flags (mu_locker_t locker, int flags)
310 {
311 return mu_locker_mod_flags (locker, flags, mu_locker_assign);
312 }
313
314 int
285 mu_locker_set_expire_time (mu_locker_t locker, int etime) 315 mu_locker_set_expire_time (mu_locker_t locker, int etime)
286 { 316 {
287 if (!locker) 317 if (!locker)
......
...@@ -15,6 +15,10 @@ ...@@ -15,6 +15,10 @@
15 Public License along with this library; If not, see 15 Public License along with this library; If not, see
16 <http://www.gnu.org/licenses/>. */ 16 <http://www.gnu.org/licenses/>. */
17 17
18 /* This is an `m-server' - a universal framework for multi-process TCP
19 servers. An `m-' stands for `mail-', or `multi-' or maybe `meta-',
20 I don't remember what. */
21
18 #ifdef HAVE_CONFIG_H 22 #ifdef HAVE_CONFIG_H
19 # include <config.h> 23 # include <config.h>
20 #endif 24 #endif
...@@ -62,28 +66,52 @@ set_signal (int sig, mu_sig_handler_t handler) ...@@ -62,28 +66,52 @@ set_signal (int sig, mu_sig_handler_t handler)
62 66
63 struct _mu_m_server 67 struct _mu_m_server
64 { 68 {
65 char *ident; 69 char *ident; /* Server identifier, for logging purposes.*/
66 mu_server_t server; 70 int deftype; /* Default server type: MU_IP_TCP/MU_IP_UDP */
67 mu_list_t srvlist; 71 mu_server_t server; /* The server object. */
68 mu_m_server_conn_fp conn; 72 mu_list_t srvlist; /* A list of configured mu_ip_server_t
69 mu_m_server_prefork_fp prefork; 73 objects. It is cleared after the objects
70 void *data; 74 are opened and attached to the server. */
71 int mode; 75
72 int foreground; 76 mu_m_server_conn_fp conn; /* Connection handler function. */
73 size_t max_children; 77 mu_m_server_prefork_fp prefork;/* Pre-fork function. */
74 char *pidfile; 78 void *data; /* User-supplied data for conn and prefork. */
75 unsigned short defport; 79
76 time_t timeout; 80 int mode; /* Server mode: should be removed. */
77 mu_acl_t acl; 81
78 82 int foreground; /* Should the server remain in foregorund? */
79 sigset_t sigmask; 83 size_t max_children; /* Maximum number of sub-processes to run. */
80 mu_sig_handler_t sigtab[NSIG]; 84 char *pidfile; /* Name of a PID-file. */
85 unsigned short defport; /* Default port number. */
86 time_t timeout; /* Default idle timeout. */
87 mu_acl_t acl; /* Global access control list. */
88
89 sigset_t sigmask; /* A set of signals to handle by the
90 m-server. */
91 mu_sig_handler_t sigtab[NSIG]; /* Keeps old signal handlers. */
92 };
93
94 struct m_srv_config /* Configuration data for a single TCP server. */
95 {
96 mu_m_server_t msrv; /* Parent m-server. */
97 mu_ip_server_t tcpsrv; /* TCP server these data are for. */
98 mu_acl_t acl; /* Access control list for this server. */
99 int single_process; /* Should it run as a single process? */
100 int transcript; /* Enable session transcript. */
101 time_t timeout; /* Idle timeout for this server. */
81 }; 102 };
82 103
104
83 static int need_cleanup = 0; 105 static int need_cleanup = 0;
84 static int stop = 0; 106 static int stop = 0;
85 static size_t children; 107 static size_t children;
86 108
109 void
110 mu_m_server_stop (int code)
111 {
112 stop = code;
113 }
114
87 static int 115 static int
88 mu_m_server_idle (void *server_data MU_ARG_UNUSED) 116 mu_m_server_idle (void *server_data MU_ARG_UNUSED)
89 { 117 {
...@@ -156,6 +184,7 @@ mu_m_server_create (mu_m_server_t *psrv, const char *ident) ...@@ -156,6 +184,7 @@ mu_m_server_create (mu_m_server_t *psrv, const char *ident)
156 exit (1); 184 exit (1);
157 } 185 }
158 } 186 }
187 srv->deftype = MU_IP_TCP;
159 MU_ASSERT (mu_server_create (&srv->server)); 188 MU_ASSERT (mu_server_create (&srv->server));
160 mu_server_set_idle (srv->server, mu_m_server_idle); 189 mu_server_set_idle (srv->server, mu_m_server_idle);
161 sigemptyset (&srv->sigmask); 190 sigemptyset (&srv->sigmask);
...@@ -168,6 +197,18 @@ mu_m_server_create (mu_m_server_t *psrv, const char *ident) ...@@ -168,6 +197,18 @@ mu_m_server_create (mu_m_server_t *psrv, const char *ident)
168 } 197 }
169 198
170 void 199 void
200 mu_m_server_set_type (mu_m_server_t srv, int type)
201 {
202 srv->deftype = type;
203 }
204
205 void
206 mu_m_server_get_type (mu_m_server_t srv, int *type)
207 {
208 *type = srv->deftype;
209 }
210
211 void
171 mu_m_server_set_sigset (mu_m_server_t srv, sigset_t *sigset) 212 mu_m_server_set_sigset (mu_m_server_t srv, sigset_t *sigset)
172 { 213 {
173 srv->sigmask = *sigset; 214 srv->sigmask = *sigset;
...@@ -242,16 +283,6 @@ mu_m_server_timeout (mu_m_server_t srv) ...@@ -242,16 +283,6 @@ mu_m_server_timeout (mu_m_server_t srv)
242 return srv->timeout; 283 return srv->timeout;
243 } 284 }
244 285
245 struct m_srv_config
246 {
247 mu_m_server_t msrv;
248 mu_tcp_server_t tcpsrv;
249 mu_acl_t acl;
250 int single_process;
251 int transcript;
252 time_t timeout;
253 };
254
255 void 286 void
256 m_srv_config_free (void *data) 287 m_srv_config_free (void *data)
257 { 288 {
...@@ -262,16 +293,16 @@ m_srv_config_free (void *data) ...@@ -262,16 +293,16 @@ m_srv_config_free (void *data)
262 293
263 static int m_srv_conn (int fd, struct sockaddr *sa, int salen, 294 static int m_srv_conn (int fd, struct sockaddr *sa, int salen,
264 void *server_data, void *call_data, 295 void *server_data, void *call_data,
265 mu_tcp_server_t srv); 296 mu_ip_server_t srv);
266 297
267 static struct m_srv_config * 298 static struct m_srv_config *
268 add_server (mu_m_server_t msrv, struct sockaddr *s, int slen) 299 add_server (mu_m_server_t msrv, struct sockaddr *s, int slen, int type)
269 { 300 {
270 mu_tcp_server_t tcpsrv; 301 mu_ip_server_t tcpsrv;
271 struct m_srv_config *pconf; 302 struct m_srv_config *pconf;
272 303
273 MU_ASSERT (mu_tcp_server_create (&tcpsrv, s, slen)); 304 MU_ASSERT (mu_ip_server_create (&tcpsrv, s, slen, type)); /* FIXME: type */
274 MU_ASSERT (mu_tcp_server_set_conn (tcpsrv, m_srv_conn)); 305 MU_ASSERT (mu_ip_server_set_conn (tcpsrv, m_srv_conn));
275 pconf = calloc (1, sizeof (*pconf)); 306 pconf = calloc (1, sizeof (*pconf));
276 if (!pconf) 307 if (!pconf)
277 { 308 {
...@@ -282,7 +313,7 @@ add_server (mu_m_server_t msrv, struct sockaddr *s, int slen) ...@@ -282,7 +313,7 @@ add_server (mu_m_server_t msrv, struct sockaddr *s, int slen)
282 pconf->tcpsrv = tcpsrv; 313 pconf->tcpsrv = tcpsrv;
283 pconf->single_process = 0; 314 pconf->single_process = 0;
284 pconf->timeout = msrv->timeout; 315 pconf->timeout = msrv->timeout;
285 MU_ASSERT (mu_tcp_server_set_data (tcpsrv, pconf, m_srv_config_free)); 316 MU_ASSERT (mu_ip_server_set_data (tcpsrv, pconf, m_srv_config_free));
286 if (!msrv->srvlist) 317 if (!msrv->srvlist)
287 MU_ASSERT (mu_list_create (&msrv->srvlist)); 318 MU_ASSERT (mu_list_create (&msrv->srvlist));
288 MU_ASSERT (mu_list_append (msrv->srvlist, tcpsrv)); 319 MU_ASSERT (mu_list_append (msrv->srvlist, tcpsrv));
...@@ -306,9 +337,10 @@ mu_m_server_begin (mu_m_server_t msrv) ...@@ -306,9 +337,10 @@ mu_m_server_begin (mu_m_server_t msrv)
306 { 337 {
307 /* Add default server */ 338 /* Add default server */
308 struct sockaddr_in s; 339 struct sockaddr_in s;
340 s.sin_family = AF_INET;
309 s.sin_addr.s_addr = htonl (INADDR_ANY); 341 s.sin_addr.s_addr = htonl (INADDR_ANY);
310 s.sin_port = htons (msrv->defport); 342 s.sin_port = htons (msrv->defport);
311 add_server (msrv, (struct sockaddr *)&s, sizeof s); 343 add_server (msrv, (struct sockaddr *)&s, sizeof s, msrv->deftype);
312 } 344 }
313 345
314 if (!msrv->foreground) 346 if (!msrv->foreground)
...@@ -363,11 +395,11 @@ mu_m_server_destroy (mu_m_server_t *pmsrv) ...@@ -363,11 +395,11 @@ mu_m_server_destroy (mu_m_server_t *pmsrv)
363 static int 395 static int
364 tcp_conn_handler (int fd, void *conn_data, void *server_data) 396 tcp_conn_handler (int fd, void *conn_data, void *server_data)
365 { 397 {
366 mu_tcp_server_t tcpsrv = (mu_tcp_server_t) conn_data; 398 mu_ip_server_t tcpsrv = (mu_ip_server_t) conn_data;
367 int rc = mu_tcp_server_accept (tcpsrv, server_data); 399 int rc = mu_ip_server_accept (tcpsrv, server_data);
368 if (rc && rc != EINTR) 400 if (rc && rc != EINTR)
369 { 401 {
370 mu_tcp_server_shutdown (tcpsrv); 402 mu_ip_server_shutdown (tcpsrv);
371 return MU_SERVER_CLOSE_CONN; 403 return MU_SERVER_CLOSE_CONN;
372 } 404 }
373 return stop ? MU_SERVER_SHUTDOWN : MU_SERVER_SUCCESS; 405 return stop ? MU_SERVER_SHUTDOWN : MU_SERVER_SUCCESS;
...@@ -376,8 +408,8 @@ tcp_conn_handler (int fd, void *conn_data, void *server_data) ...@@ -376,8 +408,8 @@ tcp_conn_handler (int fd, void *conn_data, void *server_data)
376 static void 408 static void
377 tcp_conn_free (void *conn_data, void *server_data) 409 tcp_conn_free (void *conn_data, void *server_data)
378 { 410 {
379 mu_tcp_server_t tcpsrv = (mu_tcp_server_t) conn_data; 411 mu_ip_server_t tcpsrv = (mu_ip_server_t) conn_data;
380 mu_tcp_server_destroy (&tcpsrv); 412 mu_ip_server_destroy (&tcpsrv);
381 } 413 }
382 414
383 static int 415 static int
...@@ -391,29 +423,29 @@ _open_conn (void *item, void *data) ...@@ -391,29 +423,29 @@ _open_conn (void *item, void *data)
391 addr; 423 addr;
392 int addrlen = sizeof addr; 424 int addrlen = sizeof addr;
393 char *p; 425 char *p;
394 mu_tcp_server_t tcpsrv = item; 426 mu_ip_server_t tcpsrv = item;
395 mu_m_server_t msrv = data; 427 mu_m_server_t msrv = data;
396 int rc = mu_tcp_server_open (tcpsrv); 428 int rc = mu_ip_server_open (tcpsrv);
397 if (rc) 429 if (rc)
398 { 430 {
399 mu_tcp_server_get_sockaddr (tcpsrv, &addr.sa, &addrlen); 431 mu_ip_server_get_sockaddr (tcpsrv, &addr.sa, &addrlen);
400 p = mu_sockaddr_to_astr (&addr.sa, addrlen); 432 p = mu_sockaddr_to_astr (&addr.sa, addrlen);
401 mu_error (_("Cannot open connection on %s: %s"), p, mu_strerror (rc)); 433 mu_error (_("Cannot open connection on %s: %s"), p, mu_strerror (rc));
402 free (p); 434 free (p);
403 return 0; 435 return 0;
404 } 436 }
405 rc = mu_server_add_connection (msrv->server, 437 rc = mu_server_add_connection (msrv->server,
406 mu_tcp_server_get_fd (tcpsrv), 438 mu_ip_server_get_fd (tcpsrv),
407 tcpsrv, 439 tcpsrv,
408 tcp_conn_handler, tcp_conn_free); 440 tcp_conn_handler, tcp_conn_free);
409 if (rc) 441 if (rc)
410 { 442 {
411 mu_tcp_server_get_sockaddr (tcpsrv, &addr.sa, &addrlen); 443 mu_ip_server_get_sockaddr (tcpsrv, &addr.sa, &addrlen);
412 p = mu_sockaddr_to_astr (&addr.sa, addrlen); 444 p = mu_sockaddr_to_astr (&addr.sa, addrlen);
413 mu_error (_("Cannot add connection %s: %s"), p, mu_strerror (rc)); 445 mu_error (_("Cannot add connection %s: %s"), p, mu_strerror (rc));
414 free (p); 446 free (p);
415 mu_tcp_server_shutdown (tcpsrv); 447 mu_ip_server_shutdown (tcpsrv);
416 mu_tcp_server_destroy (&tcpsrv); 448 mu_ip_server_destroy (&tcpsrv);
417 } 449 }
418 return 0; 450 return 0;
419 } 451 }
...@@ -443,8 +475,8 @@ mu_m_server_run (mu_m_server_t msrv) ...@@ -443,8 +475,8 @@ mu_m_server_run (mu_m_server_t msrv)
443 475
444 476
445 477
446 static int 478 int
447 check_global_acl (mu_m_server_t msrv, struct sockaddr *s, int salen) 479 mu_m_server_check_acl (mu_m_server_t msrv, struct sockaddr *s, int salen)
448 { 480 {
449 if (msrv->acl) 481 if (msrv->acl)
450 { 482 {
...@@ -488,14 +520,14 @@ check_global_acl (mu_m_server_t msrv, struct sockaddr *s, int salen) ...@@ -488,14 +520,14 @@ check_global_acl (mu_m_server_t msrv, struct sockaddr *s, int salen)
488 int 520 int
489 m_srv_conn (int fd, struct sockaddr *sa, int salen, 521 m_srv_conn (int fd, struct sockaddr *sa, int salen,
490 void *server_data, void *call_data, 522 void *server_data, void *call_data,
491 mu_tcp_server_t srv) 523 mu_ip_server_t srv)
492 { 524 {
493 int status; 525 int status;
494 struct m_srv_config *pconf = server_data; 526 struct m_srv_config *pconf = server_data;
495
496 if (check_global_acl (pconf->msrv, sa, salen))
497 return 0;
498 527
528 if (mu_m_server_check_acl (pconf->msrv, sa, salen))
529 return 0;
530
499 if (!pconf->single_process) 531 if (!pconf->single_process)
500 { 532 {
501 pid_t pid; 533 pid_t pid;
...@@ -509,7 +541,8 @@ m_srv_conn (int fd, struct sockaddr *sa, int salen, ...@@ -509,7 +541,8 @@ m_srv_conn (int fd, struct sockaddr *sa, int salen,
509 pause (); 541 pause ();
510 return 0; 542 return 0;
511 } 543 }
512 if (pconf->msrv->prefork && pconf->msrv->prefork (fd, sa, salen)) 544 if (pconf->msrv->prefork
545 && pconf->msrv->prefork (fd, pconf->msrv->data, sa, salen))
513 return 0; 546 return 0;
514 547
515 pid = fork (); 548 pid = fork ();
...@@ -517,8 +550,8 @@ m_srv_conn (int fd, struct sockaddr *sa, int salen, ...@@ -517,8 +550,8 @@ m_srv_conn (int fd, struct sockaddr *sa, int salen,
517 mu_diag_output (MU_DIAG_ERROR, "fork: %s", strerror (errno)); 550 mu_diag_output (MU_DIAG_ERROR, "fork: %s", strerror (errno));
518 else if (pid == 0) /* Child. */ 551 else if (pid == 0) /* Child. */
519 { 552 {
520 mu_tcp_server_shutdown (srv); 553 mu_ip_server_shutdown (srv); /* FIXME: does it harm for MU_IP_UDP? */
521 status = pconf->msrv->conn (fd, pconf->msrv->data, 554 status = pconf->msrv->conn (fd, sa, salen, pconf->msrv->data, srv,
522 pconf->timeout, pconf->transcript); 555 pconf->timeout, pconf->transcript);
523 closelog (); 556 closelog ();
524 exit (status); 557 exit (status);
...@@ -528,10 +561,10 @@ m_srv_conn (int fd, struct sockaddr *sa, int salen, ...@@ -528,10 +561,10 @@ m_srv_conn (int fd, struct sockaddr *sa, int salen,
528 children++; 561 children++;
529 } 562 }
530 } 563 }
531 else 564 else if (pconf->msrv->prefork
532 pconf->msrv->conn (fd, pconf->msrv->data, 565 && pconf->msrv->prefork (fd, pconf->msrv->data, sa, salen) == 0)
566 pconf->msrv->conn (fd, sa, salen, pconf->msrv->data, srv,
533 pconf->timeout, pconf->transcript); 567 pconf->timeout, pconf->transcript);
534
535 return 0; 568 return 0;
536 } 569 }
537 570
...@@ -718,7 +751,7 @@ server_block_begin (mu_debug_t debug, char *arg, mu_m_server_t msrv, ...@@ -718,7 +751,7 @@ server_block_begin (mu_debug_t debug, char *arg, mu_m_server_t msrv,
718 } 751 }
719 } 752 }
720 753
721 *pdata = add_server (msrv, &s.s_sa, salen); 754 *pdata = add_server (msrv, &s.s_sa, salen, msrv->deftype);
722 return 0; 755 return 0;
723 } 756 }
724 757
...@@ -743,7 +776,7 @@ server_section_parser (enum mu_cfg_section_stage stage, ...@@ -743,7 +776,7 @@ server_section_parser (enum mu_cfg_section_stage stage,
743 { 776 {
744 struct m_srv_config *pconf = *section_data; 777 struct m_srv_config *pconf = *section_data;
745 if (pconf->acl) 778 if (pconf->acl)
746 mu_tcp_server_set_acl (pconf->tcpsrv, pconf->acl); 779 mu_ip_server_set_acl (pconf->tcpsrv, pconf->acl);
747 } 780 }
748 break; 781 break;
749 } 782 }
......
1 /* GNU Mailutils -- a suite of utilities for electronic mail 1 /* GNU Mailutils -- a suite of utilities for electronic mail
2 Copyright (C) 2007 Free Software Foundation, Inc. 2 Copyright (C) 2007, 2008 Free Software Foundation, Inc.
3 3
4 This library is free software; you can redistribute it and/or 4 This library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Lesser General Public 5 modify it under the terms of the GNU Lesser General Public
...@@ -201,8 +201,12 @@ mu_server_destroy (mu_server_t *psrv) ...@@ -201,8 +201,12 @@ mu_server_destroy (mu_server_t *psrv)
201 if (!srv) 201 if (!srv)
202 return 0; 202 return 0;
203 203
204 for (p = srv->head; p; p = p->next) 204 for (p = srv->head; p; )
205 destroy_connection (srv, p); 205 {
206 struct _mu_connection *next = p->next;
207 destroy_connection (srv, p);
208 p = next;
209 }
206 210
207 if (srv->f_free) 211 if (srv->f_free)
208 srv->f_free (srv->server_data); 212 srv->f_free (srv->server_data);
......
1 # 1 #
2 # List of source files containing translatable strings. 2 # List of source files containing translatable strings.
3 # Copyright (C) 2002, 2003, 2004, 2005 Free Software Foundation, Inc. 3 # Copyright (C) 2002, 2003, 2004, 2005, 2008 Free Software Foundation, Inc.
4 # 4 #
5 5
6 auth/pam.c 6 auth/pam.c
...@@ -8,7 +8,7 @@ auth/sql.c ...@@ -8,7 +8,7 @@ auth/sql.c
8 auth/tls.c 8 auth/tls.c
9 auth/virtual.c 9 auth/virtual.c
10 comsat/action.c 10 comsat/action.c
11 comsat/cfg.c 11 comsat/oldcfg.c
12 comsat/comsat.c 12 comsat/comsat.c
13 config/mailutils-config.c 13 config/mailutils-config.c
14 dotlock/dotlock.c 14 dotlock/dotlock.c
...@@ -107,6 +107,7 @@ mailbox/cfg_lexer.c ...@@ -107,6 +107,7 @@ mailbox/cfg_lexer.c
107 mailbox/errors 107 mailbox/errors
108 mailbox/file_stream.c 108 mailbox/file_stream.c
109 mailbox/filter_iconv.c 109 mailbox/filter_iconv.c
110 mailbox/ipsrv.c
110 mailbox/message.c 111 mailbox/message.c
111 mailbox/mu_auth.c 112 mailbox/mu_auth.c
112 mailbox/mutil.c 113 mailbox/mutil.c
......
1 /* GNU Mailutils -- a suite of utilities for electronic mail 1 /* GNU Mailutils -- a suite of utilities for electronic mail
2 Copyright (C) 1999, 2000, 2001, 2002, 2005, 2 Copyright (C) 1999, 2000, 2001, 2002, 2005,
3 2007 Free Software Foundation, Inc. 3 2007, 2008 Free Software Foundation, Inc.
4 4
5 GNU Mailutils is free software; you can redistribute it and/or modify 5 GNU Mailutils is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by 6 it under the terms of the GNU General Public License as published by
...@@ -30,7 +30,7 @@ pop3d_lock () ...@@ -30,7 +30,7 @@ pop3d_lock ()
30 mu_mailbox_get_url (mbox, &url); 30 mu_mailbox_get_url (mbox, &url);
31 name = mu_url_to_string (url); 31 name = mu_url_to_string (url);
32 mu_mailbox_get_locker (mbox, &lock); 32 mu_mailbox_get_locker (mbox, &lock);
33 mu_locker_set_flags (lock, MU_LOCKER_PID); 33 mu_locker_mod_flags (lock, MU_LOCKER_PID, mu_locker_set_bit);
34 if ((status = mu_locker_lock (lock))) 34 if ((status = mu_locker_lock (lock)))
35 { 35 {
36 mu_diag_output (MU_DIAG_NOTICE, _("Locking mailbox `%s' failed: %s"), 36 mu_diag_output (MU_DIAG_NOTICE, _("Locking mailbox `%s' failed: %s"),
......
...@@ -447,7 +447,8 @@ pop3d_mainloop (int fd, FILE *infile, FILE *outfile) ...@@ -447,7 +447,8 @@ pop3d_mainloop (int fd, FILE *infile, FILE *outfile)
447 } 447 }
448 448
449 int 449 int
450 pop3d_connection (int fd, void *data, time_t timeout, int transcript) 450 pop3d_connection (int fd, struct sockaddr *sa, int salen, void *data,
451 mu_ip_server_t srv, time_t timeout, int transcript)
451 { 452 {
452 idle_timeout = timeout; 453 idle_timeout = timeout;
453 pop3d_transcript = transcript; 454 pop3d_transcript = transcript;
......