Commit fef074ea fef074ea553712804485bf71f9d65b33d37e00b5 by Sergey Poznyakoff

* include/mailutils/server.h (mu_m_server_prefork_fp): New

function type.
(mu_m_server_destroy, mu_m_server_set_prefork)
(mu_m_server_configured_count, mu_m_server_end): New functions.
* mailbox/msrv.c (struct _mu_m_server.prefork): New member.
(mu_m_server_set_prefork): New function.
(m_srv_conn): Use prefork to decide whether to proceed with a
connection.

* lib/tcpwrap.c, lib/tcpwrap.h (mu_tcp_wrapper_prefork): New
function.

* imap4d/imap4d.c, maidag/lmtp.c, maidag/maidag.c,
pop3d/pop3d.c: Use m-server prefork to handle TCP wrappers.

* po/POTFILES.in: Add more files.
1 parent 846221a1
......@@ -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 (); */
......
......@@ -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);
......
/* 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;
}
......
/* 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 },
......
......@@ -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;
......
......@@ -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);
......
......@@ -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));
......
......@@ -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
......
......@@ -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 (); */
......