summaryrefslogtreecommitdiff
path: root/libmailutils/server/msrv.c
diff options
context:
space:
mode:
authorSergey Poznyakoff <gray@gnu.org.ua>2011-11-04 21:30:38 +0200
committerSergey Poznyakoff <gray@gnu.org.ua>2011-11-04 21:44:56 +0200
commite1233d5516f48cd7d786a69d4eebd40e73d95d45 (patch)
tree38692d813e645ac60bfababee4c5f7ec7f8cede9 /libmailutils/server/msrv.c
parentbad3c6c3a982f65af0fe137d1e5b7a98d13bb9d5 (diff)
downloadmailutils-e1233d5516f48cd7d786a69d4eebd40e73d95d45.tar.gz
mailutils-e1233d5516f48cd7d786a69d4eebd40e73d95d45.tar.bz2
Implement pop3s and imap4s in respective servers.
* comsat/comsat.c (comsat_prefork,comsat_connection): Change signatures. * imap4d/imap4d.c: Implement imaps. * imap4d/imap4d.h (io_setio): Change signature. (tls_encryption_on): New proto. * imap4d/io.c (io_setio): Change signature. Initialize TLS stream if requested. * imap4d/starttls.c (tls_encryption_on): New function. * include/mailutils/server.h (mu_srv_config): New struct. (mu_m_server_conn_fp, mu_m_server_prefork_fp): Remove typedefs. (mu_m_server_handler_fp): New typedef. (mu_m_server_set_conn): Change signature. (mu_m_server_set_prefork): Change signature. (mu_m_server_set_app_data_size) (mu_m_server_set_config_size): New prototype. (mu_m_server_cfg_init): Change signature. * include/mailutils/tls.h (mu_init_tls_libs): Change signature. * lib/tcpwrap.c: Include tcpwrap.h (mu_tcp_wrapper_daemon): Fix declaration. (mu_tcp_wrapper_prefork): Change signature. * lib/tcpwrap.h (mu_tcp_wrapper_prefork): Change signature * libmailutils/server/msrv.c (_mu_m_server) <conn,prefork>: Change data type. All uses updated. <app_data_size>: New member. (m_srv_config): Remove struct. Replaced with mu_srv_config from tls.h (mu_m_server_set_conn): Change signature. (mu_m_server_set_prefork): Change signature. (mu_m_server_set_app_data_size) (mu_m_server_set_config_size): New functions. (add_server): Allocate app_data_size additional bytes of data. (mu_m_server_cfg_init): Take one argument. * libmu_auth/tls.c (mu_tls_module_init): Update call to mu_init_tls_libs. Don't call mu_file_safety_check with NULL argument. (mu_init_tls_libs): Rewrite. Prepare x509 here, instead of doing it each time a TLS stream is created. (mu_deinit_tls_libs): Free x509, if exists. (_tls_server_open): Update call to mu_init_tls_libs. Remove x509 initialization. * libmu_cfg/tls.c (cb2_safety_checks): Fix typos. * maidag/lmtp.c (lmtp_connection): Change signature. * maidag/maidag.c (main): Update call to mu_m_server_cfg_init. * maidag/maidag.h (lmtp_connection): Change signature. * pop3d/extra.c (pop3d_setio): Initialize TLS stream, if requested. * pop3d/pop3d.c: Implement pops. * pop3d/pop3d.h (pop3d_setio): Change prototype.
Diffstat (limited to 'libmailutils/server/msrv.c')
-rw-r--r--libmailutils/server/msrv.c74
1 files changed, 41 insertions, 33 deletions
diff --git a/libmailutils/server/msrv.c b/libmailutils/server/msrv.c
index d5ceb8a39..fca9322c6 100644
--- a/libmailutils/server/msrv.c
+++ b/libmailutils/server/msrv.c
@@ -76,9 +76,10 @@ struct _mu_m_server
objects. It is cleared after the objects
are opened and attached to the server. */
- mu_m_server_conn_fp conn; /* Connection handler function. */
- mu_m_server_prefork_fp prefork;/* Pre-fork function. */
+ mu_m_server_handler_fp conn; /* Connection handler function. */
+ mu_m_server_handler_fp prefork;/* Pre-fork function. */
void *data; /* User-supplied data for conn and prefork. */
+ size_t app_data_size;
int mode; /* Server mode: should be removed. */
@@ -98,16 +99,6 @@ struct _mu_m_server
description. */
};
-struct m_srv_config /* Configuration data for a single TCP server. */
-{
- mu_m_server_t msrv; /* Parent m-server. */
- mu_ip_server_t tcpsrv; /* TCP server these data are for. */
- mu_acl_t acl; /* Access control list for this server. */
- int single_process; /* Should it run as a single process? */
- int transcript; /* Enable session transcript. */
- time_t timeout; /* Idle timeout for this server. */
-};
-
static int need_cleanup = 0;
static int stop = 0; /* FIXME: Must be per-m-server */
@@ -326,13 +317,13 @@ 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 conn)
+mu_m_server_set_conn (mu_m_server_t srv, mu_m_server_handler_fp conn)
{
srv->conn = conn;
}
void
-mu_m_server_set_prefork (mu_m_server_t srv, mu_m_server_prefork_fp fun)
+mu_m_server_set_prefork (mu_m_server_t srv, mu_m_server_handler_fp fun)
{
srv->prefork = fun;
}
@@ -433,9 +424,24 @@ mu_m_server_foreground (mu_m_server_t srv)
}
void
-m_srv_config_free (void *data)
+mu_m_server_set_app_data_size (mu_m_server_t srv, size_t size)
+{
+ srv->app_data_size = size;
+}
+
+int
+mu_m_server_set_config_size (mu_m_server_t srv, size_t size)
+{
+ if (size < sizeof (struct mu_srv_config))
+ return EINVAL;
+ srv->app_data_size = size - sizeof (struct mu_srv_config);
+ return 0;
+}
+
+void
+mu_srv_config_free (void *data)
{
- struct m_srv_config *pconf = data;
+ struct mu_srv_config *pconf = data;
/* FIXME */
free (pconf);
}
@@ -444,15 +450,15 @@ static int m_srv_conn (int fd, struct sockaddr *sa, int salen,
void *server_data, void *call_data,
mu_ip_server_t srv);
-static struct m_srv_config *
+static struct mu_srv_config *
add_server (mu_m_server_t msrv, struct mu_sockaddr *s, int type)
{
mu_ip_server_t tcpsrv;
- struct m_srv_config *pconf;
+ struct mu_srv_config *pconf;
MU_ASSERT (mu_ip_server_create (&tcpsrv, s, type)); /* FIXME: type */
MU_ASSERT (mu_ip_server_set_conn (tcpsrv, m_srv_conn));
- pconf = calloc (1, sizeof (*pconf));
+ pconf = calloc (1, sizeof (*pconf) + msrv->app_data_size);
if (!pconf)
{
mu_error ("%s", mu_strerror (ENOMEM));
@@ -462,7 +468,7 @@ add_server (mu_m_server_t msrv, struct mu_sockaddr *s, int type)
pconf->tcpsrv = tcpsrv;
pconf->single_process = 0;
pconf->timeout = msrv->timeout;
- MU_ASSERT (mu_ip_server_set_data (tcpsrv, pconf, m_srv_config_free));
+ MU_ASSERT (mu_ip_server_set_data (tcpsrv, pconf, mu_srv_config_free));
if (!msrv->srvlist)
MU_ASSERT (mu_list_create (&msrv->srvlist));
MU_ASSERT (mu_list_append (msrv->srvlist, tcpsrv));
@@ -681,7 +687,7 @@ m_srv_conn (int fd, struct sockaddr *sa, int salen,
mu_ip_server_t srv)
{
int status;
- struct m_srv_config *pconf = server_data;
+ struct mu_srv_config *pconf = server_data;
if (mu_m_server_check_acl (pconf->msrv, sa, salen))
return 0;
@@ -701,7 +707,7 @@ m_srv_conn (int fd, struct sockaddr *sa, int salen,
return 0;
}
if (pconf->msrv->prefork
- && pconf->msrv->prefork (fd, pconf->msrv->data, sa, salen))
+ && pconf->msrv->prefork (fd, sa, salen, pconf, pconf->msrv->data))
return 0;
pid = fork ();
@@ -711,8 +717,8 @@ m_srv_conn (int fd, struct sockaddr *sa, int salen,
{
mu_ip_server_shutdown (srv); /* FIXME: does it harm for MU_IP_UDP? */
mu_m_server_restore_signals (pconf->msrv);
- status = pconf->msrv->conn (fd, sa, salen, pconf->msrv->data, srv,
- pconf->timeout, pconf->transcript);
+ status = pconf->msrv->conn (fd, sa, salen, pconf,
+ pconf->msrv->data);
closelog ();
exit (status);
}
@@ -722,9 +728,9 @@ m_srv_conn (int fd, struct sockaddr *sa, int salen,
}
}
else if (!pconf->msrv->prefork
- || pconf->msrv->prefork (fd, pconf->msrv->data, sa, salen) == 0)
- pconf->msrv->conn (fd, sa, salen, pconf->msrv->data, srv,
- pconf->timeout, pconf->transcript);
+ || pconf->msrv->prefork (fd, sa, salen, pconf,
+ pconf->msrv->data) == 0)
+ pconf->msrv->conn (fd, sa, salen, pconf, pconf->msrv->data);
return 0;
}
@@ -802,7 +808,7 @@ server_section_parser (enum mu_cfg_section_stage stage,
case mu_cfg_section_end:
{
- struct m_srv_config *pconf = *section_data;
+ struct mu_srv_config *pconf = *section_data;
if (pconf->acl)
mu_ip_server_set_acl (pconf->tcpsrv, pconf->acl);
}
@@ -904,22 +910,22 @@ static struct mu_cfg_param dot_server_cfg_param[] = {
static struct mu_cfg_param server_cfg_param[] = {
{ "single-process", mu_cfg_bool,
- NULL, mu_offsetof (struct m_srv_config, single_process), NULL,
+ NULL, mu_offsetof (struct mu_srv_config, single_process), NULL,
N_("Run this server in foreground.") },
{ "transcript", mu_cfg_bool,
- NULL, mu_offsetof (struct m_srv_config, transcript), NULL,
+ NULL, mu_offsetof (struct mu_srv_config, transcript), NULL,
N_("Log the session transcript.") },
{ "timeout", mu_cfg_time,
- NULL, mu_offsetof (struct m_srv_config, timeout), NULL,
+ NULL, mu_offsetof (struct mu_srv_config, timeout), NULL,
N_("Set idle timeout.") },
{ "acl", mu_cfg_section,
- NULL, mu_offsetof (struct m_srv_config, acl), NULL,
+ NULL, mu_offsetof (struct mu_srv_config, acl), NULL,
N_("Global access control list.") },
{ NULL }
};
void
-mu_m_server_cfg_init ()
+mu_m_server_cfg_init (struct mu_cfg_param *app_param)
{
struct mu_cfg_section *section;
if (mu_create_canned_section ("server", &section) == 0)
@@ -927,6 +933,8 @@ mu_m_server_cfg_init ()
section->parser = server_section_parser;
section->label = N_("ipaddr[:port]");
mu_cfg_section_add_params (section, server_cfg_param);
+ if (app_param)
+ mu_cfg_section_add_params (section, app_param);
}
if (mu_create_canned_section (".server", &section) == 0)
{

Return to:

Send suggestions and report system problems to the System administrator.