summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--imap4d/imap4d.c19
-rw-r--r--include/mailutils/server.h7
-rw-r--r--lib/tcpwrap.c18
-rw-r--r--lib/tcpwrap.h4
-rw-r--r--maidag/lmtp.c8
-rw-r--r--maidag/maidag.c1
-rw-r--r--mailbox/msrv.c11
-rw-r--r--po/POTFILES.in1
-rw-r--r--pop3d/pop3d.c16
9 files changed, 46 insertions, 39 deletions
diff --git a/imap4d/imap4d.c b/imap4d/imap4d.c
index 83cc0deb9..c3866e80e 100644
--- a/imap4d/imap4d.c
+++ b/imap4d/imap4d.c
@@ -374,24 +374,6 @@ imap4d_mainloop (int fd, FILE *infile, FILE *outfile)
struct sockaddr_in cs;
int debug_mode = isatty (fd);
- mu_diag_output (MU_DIAG_INFO, _("Incoming connection opened"));
- if (!debug_mode)
- {
- if (get_client_address (fd, &cs) == 0)
- {
- if (!mu_tcpwrapper_access (fd))
- {
- mu_error (_("Access from %s blocked."), inet_ntoa (cs.sin_addr));
- return 1;
- }
- }
- else if (mu_tcp_wrapper_enable)
- {
- mu_error (_("Rejecting connection from unknown address"));
- return 1;
- }
- }
-
/* Reset hup to exit. */
signal (SIGHUP, imap4d_signal);
/* Timeout alarm. */
@@ -502,6 +484,7 @@ main (int argc, char **argv)
mu_m_server_create (&server, "GNU imap4d");
mu_m_server_set_conn (server, imap4d_connection);
+ mu_m_server_set_prefork (server, mu_tcp_wrapper_prefork);
mu_m_server_set_mode (server, MODE_INTERACTIVE);
mu_m_server_set_max_children (server, 20);
/* FIXME mu_m_server_set_pidfile (); */
diff --git a/include/mailutils/server.h b/include/mailutils/server.h
index df749e56a..d09215f44 100644
--- a/include/mailutils/server.h
+++ b/include/mailutils/server.h
@@ -75,10 +75,12 @@ int mu_tcp_server_get_sockaddr (mu_tcp_server_t srv, struct sockaddr *s,
/* m-server */
typedef int (*mu_m_server_conn_fp) (int, void *, time_t, int);
-
+typedef int (*mu_m_server_prefork_fp) (int, struct sockaddr *s, int size);
void mu_m_server_create (mu_m_server_t *psrv, const char *ident);
+void mu_m_server_destroy (mu_m_server_t *pmsrv);
void mu_m_server_set_mode (mu_m_server_t srv, int mode);
void mu_m_server_set_conn (mu_m_server_t srv, mu_m_server_conn_fp f);
+void mu_m_server_set_prefork (mu_m_server_t srv, mu_m_server_prefork_fp fun);
void mu_m_server_set_data (mu_m_server_t srv, void *data);
void mu_m_server_set_max_children (mu_m_server_t srv, size_t num);
int mu_m_server_set_pidfile (mu_m_server_t srv, const char *pidfile);
@@ -91,8 +93,11 @@ int mu_m_server_mode (mu_m_server_t srv);
time_t mu_m_server_timeout (mu_m_server_t srv);
void mu_m_server_get_sigset (mu_m_server_t srv, sigset_t *sigset);
+void mu_m_server_configured_count (mu_m_server_t msrv, size_t count);
+
void mu_m_server_begin (mu_m_server_t msrv);
int mu_m_server_run (mu_m_server_t msrv);
+void mu_m_server_end (mu_m_server_t msrv);
void mu_m_server_cfg_init (void);
diff --git a/lib/tcpwrap.c b/lib/tcpwrap.c
index 98ac22acf..8917389fa 100644
--- a/lib/tcpwrap.c
+++ b/lib/tcpwrap.c
@@ -1,6 +1,6 @@
/* GNU Mailutils -- a suite of utilities for electronic mail
Copyright (C) 1999, 2001, 2002, 2003, 2004,
- 2005, 2006, 2007 Free Software Foundation, Inc.
+ 2005, 2006, 2007, 2008 Free Software Foundation, Inc.
GNU Mailutils is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -20,6 +20,7 @@
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
+#include <stdlib.h>
#include <syslog.h>
#include <string.h>
#include <mailutils/debug.h>
@@ -27,6 +28,7 @@
#include <mailutils/syslog.h>
#include <mailutils/cfg.h>
#include <mailutils/diag.h>
+#include <mailutils/error.h>
int mu_tcp_wrapper_enable = 1;
char *mu_tcp_wrapper_daemon;
@@ -138,3 +140,17 @@ mu_tcpwrapper_access (int fd)
}
#endif
+
+int
+mu_tcp_wrapper_prefork (int fd, struct sockaddr *sa, int salen)
+{
+ if (mu_tcp_wrapper_enable && !mu_tcpwrapper_access (fd))
+ {
+ char *p = mu_sockaddr_to_astr (sa, salen);
+ mu_error (_("Access from %s blocked by TCP wrappers."), p);
+ free (p);
+ return 1;
+ }
+ return 0;
+}
+
diff --git a/lib/tcpwrap.h b/lib/tcpwrap.h
index 4d461c312..ad483f1c4 100644
--- a/lib/tcpwrap.h
+++ b/lib/tcpwrap.h
@@ -1,6 +1,6 @@
/* GNU Mailutils -- a suite of utilities for electronic mail
Copyright (C) 1999, 2001, 2002, 2003, 2004,
- 2005, 2006, 2007 Free Software Foundation, Inc.
+ 2005, 2006, 2007, 2008 Free Software Foundation, Inc.
GNU Mailutils is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -30,8 +30,8 @@ extern int mu_tcp_wrapper_cb_hosts_allow_syslog (mu_debug_t debug, void *data,
extern int mu_tcp_wrapper_cb_hosts_deny_syslog (mu_debug_t debug, void *data,
char *arg);
extern int mu_tcpwrapper_access (int fd);
-
extern void mu_tcpwrapper_cfg_init (void);
+extern int mu_tcp_wrapper_prefork (int fd, struct sockaddr *sa, int salen);
#ifdef WITH_LIBWRAP
# define TCP_WRAPPERS_CONFIG { "tcp-wrappers", mu_cfg_section },
diff --git a/maidag/lmtp.c b/maidag/lmtp.c
index 454a6a6a5..31f3d2afc 100644
--- a/maidag/lmtp.c
+++ b/maidag/lmtp.c
@@ -556,10 +556,16 @@ lmtp_loop (FILE *in, FILE *out, unsigned int timeout)
return 0;
}
+typedef union
+{
+ struct sockaddr sa;
+ struct sockaddr_in s_in;
+ struct sockaddr_un s_un;
+} all_addr_t;
+
int
lmtp_connection (int fd, void *data, time_t timeout, int transcript)
{
- /* FIXME: TCP wrappers */
lmtp_transcript = transcript;
lmtp_loop (fdopen (fd, "r"), fdopen (fd, "w"), timeout);
return 0;
diff --git a/maidag/maidag.c b/maidag/maidag.c
index 73eba58a2..2827e2efc 100644
--- a/maidag/maidag.c
+++ b/maidag/maidag.c
@@ -478,6 +478,7 @@ main (int argc, char *argv[])
mu_m_server_create (&server, "GNU maidag");
mu_m_server_set_conn (server, lmtp_connection);
+ mu_m_server_set_prefork (server, mu_tcp_wrapper_prefork);
mu_m_server_set_mode (server, MODE_INTERACTIVE);
mu_m_server_set_max_children (server, 20);
mu_m_server_set_timeout (server, 600);
diff --git a/mailbox/msrv.c b/mailbox/msrv.c
index e0bd9ba95..8952d34e4 100644
--- a/mailbox/msrv.c
+++ b/mailbox/msrv.c
@@ -66,6 +66,7 @@ struct _mu_m_server
mu_server_t server;
mu_list_t srvlist;
mu_m_server_conn_fp conn;
+ mu_m_server_prefork_fp prefork;
void *data;
int mode;
int foreground;
@@ -192,6 +193,12 @@ mu_m_server_set_conn (mu_m_server_t srv, mu_m_server_conn_fp conn)
}
void
+mu_m_server_set_prefork (mu_m_server_t srv, mu_m_server_prefork_fp fun)
+{
+ srv->prefork = fun;
+}
+
+void
mu_m_server_set_data (mu_m_server_t srv, void *data)
{
srv->data = data;
@@ -502,7 +509,9 @@ m_srv_conn (int fd, struct sockaddr *sa, int salen,
pause ();
return 0;
}
-
+ if (pconf->msrv->prefork && pconf->msrv->prefork (fd, sa, salen))
+ return 0;
+
pid = fork ();
if (pid == -1)
mu_diag_output (MU_DIAG_ERROR, "fork: %s", strerror (errno));
diff --git a/po/POTFILES.in b/po/POTFILES.in
index 6e63c6cca..b2aaa7686 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -31,6 +31,7 @@ lib/argp-help.c
lib/argp-parse.c
lib/getopt.c
lib/mailcap.c
+lib/tcpwrap.c
lib/xmalloc.c
libargp/auth.c
libargp/cmdline.c
diff --git a/pop3d/pop3d.c b/pop3d/pop3d.c
index 9ec6703cc..57e005e26 100644
--- a/pop3d/pop3d.c
+++ b/pop3d/pop3d.c
@@ -291,21 +291,6 @@ pop3d_mainloop (int fd, FILE *infile, FILE *outfile)
{
int status = OK;
char buffer[512];
- struct sockaddr_in cs;
-
- if (pop3d_get_client_address (fd, &cs) == 0)
- {
- if (!mu_tcpwrapper_access (fd))
- {
- mu_error (_("Access from %s blocked."), inet_ntoa (cs.sin_addr));
- return 1;
- }
- }
- else if (!debug_mode && mu_tcp_wrapper_enable)
- {
- mu_error (_("Rejecting connection from unknown address"));
- return 1;
- }
/* Reset hup to exit. */
signal (SIGHUP, pop3d_signal);
@@ -494,6 +479,7 @@ main (int argc, char **argv)
mu_m_server_create (&server, "GNU pop3d");
mu_m_server_set_conn (server, pop3d_connection);
+ mu_m_server_set_prefork (server, mu_tcp_wrapper_prefork);
mu_m_server_set_mode (server, MODE_INTERACTIVE);
mu_m_server_set_max_children (server, 20);
/* FIXME mu_m_server_set_pidfile (); */

Return to:

Send suggestions and report system problems to the System administrator.