summaryrefslogtreecommitdiff
path: root/pop3d
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 /pop3d
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 'pop3d')
-rw-r--r--pop3d/extra.c23
-rw-r--r--pop3d/pop3d.c43
-rw-r--r--pop3d/pop3d.h2
3 files changed, 53 insertions, 15 deletions
diff --git a/pop3d/extra.c b/pop3d/extra.c
index c2d1c420f..83f468a45 100644
--- a/pop3d/extra.c
+++ b/pop3d/extra.c
@@ -93,6 +93,10 @@ pop3d_abquit (int reason)
mu_diag_output (MU_DIAG_INFO, _("no socket to send to"));
break;
+ case ERR_FILE:
+ code = EX_IOERR;
+ break;
+
case ERR_PROTO:
code = EX_PROTOCOL;
mu_diag_output (MU_DIAG_INFO, _("remote protocol error"));
@@ -125,7 +129,7 @@ pop3d_abquit (int reason)
}
void
-pop3d_setio (int ifd, int ofd)
+pop3d_setio (int ifd, int ofd, int tls)
{
mu_stream_t str, istream, ostream;
@@ -137,11 +141,26 @@ pop3d_setio (int ifd, int ofd)
if (mu_stdio_stream_create (&istream, ifd, MU_STREAM_READ))
pop3d_abquit (ERR_NO_IFILE);
mu_stream_set_buffer (istream, mu_buffer_line, 0);
-
+
if (mu_stdio_stream_create (&ostream, ofd, MU_STREAM_WRITE))
pop3d_abquit (ERR_NO_OFILE);
/* Combine the two streams into an I/O one. */
+#ifdef WITH_TLS
+ if (tls)
+ {
+ int rc = mu_tls_server_stream_create (&str, istream, ostream, 0);
+ if (rc)
+ {
+ mu_stream_unref (istream);
+ mu_stream_unref (ostream);
+ mu_error (_("failed to create TLS stream: %s"), mu_strerror (rc));
+ pop3d_abquit (ERR_FILE);
+ }
+ tls_done = 1;
+ }
+ else
+#endif
if (mu_iostream_create (&str, istream, ostream))
pop3d_abquit (ERR_FILE);
diff --git a/pop3d/pop3d.c b/pop3d/pop3d.c
index 4a15b3831..3df05514d 100644
--- a/pop3d/pop3d.c
+++ b/pop3d/pop3d.c
@@ -18,6 +18,7 @@
#include "pop3d.h"
#include "mailutils/pam.h"
#include "mailutils/libargp.h"
+#include "mailutils/pop3.h"
#include "tcpwrap.h"
mu_mailbox_t mbox;
@@ -107,6 +108,19 @@ cb_bulletin_db (void *data, mu_config_value_t *val)
}
#endif
+struct pop3d_srv_config
+{
+ struct mu_srv_config m_cfg;
+ int tls;
+};
+
+static struct mu_cfg_param pop3d_srv_param[] = {
+ { "tls", mu_cfg_bool, NULL, mu_offsetof (struct pop3d_srv_config, tls), NULL,
+ N_("Use TLS encryption for this server")
+ },
+ { NULL }
+};
+
static struct mu_cfg_param pop3d_cfg_param[] = {
{ "undelete", mu_cfg_bool, &undelete_on_startup, 0, NULL,
N_("On startup, clear deletion marks from all the messages.") },
@@ -247,9 +261,10 @@ pop3d_get_client_address (int fd, struct sockaddr_in *pcs)
executes the proper functions. Also handles the bulk of error reporting.
Arguments:
ifd -- input descriptor
- ofd -- output descriptor */
+ ofd -- output descriptor
+ tls -- initiate encrypted connection */
int
-pop3d_mainloop (int ifd, int ofd)
+pop3d_mainloop (int ifd, int ofd, int tls)
{
int status = OK;
char buffer[512];
@@ -258,7 +273,7 @@ pop3d_mainloop (int ifd, int ofd)
mu_set_signals (pop3d_child_signal, sigtab, MU_ARRAY_SIZE (sigtab));
- pop3d_setio (ifd, ofd);
+ pop3d_setio (ifd, ofd, tls);
state = initial_state;
@@ -324,13 +339,16 @@ pop3d_mainloop (int ifd, int ofd)
}
int
-pop3d_connection (int fd, struct sockaddr *sa, int salen, void *data,
- mu_ip_server_t srv, time_t timeout, int transcript)
+pop3d_connection (int fd, struct sockaddr *sa, int salen,
+ struct mu_srv_config *pconf,
+ void *data)
{
- idle_timeout = timeout;
- if (pop3d_transcript != transcript)
- pop3d_transcript = transcript;
- pop3d_mainloop (fd, fd);
+ struct pop3d_srv_config *cfg = (struct pop3d_srv_config *) pconf;
+
+ idle_timeout = pconf->timeout;
+ pop3d_transcript = pconf->transcript;
+
+ pop3d_mainloop (fd, fd, cfg->tls);
return 0;
}
@@ -370,11 +388,12 @@ main (int argc, char **argv)
mu_tcpwrapper_cfg_init ();
manlock_cfg_init ();
mu_acl_cfg_init ();
- mu_m_server_cfg_init ();
+ mu_m_server_cfg_init (pop3d_srv_param);
mu_argp_init (NULL, NULL);
mu_m_server_create (&server, program_version);
+ mu_m_server_set_config_size (server, sizeof (struct pop3d_srv_config));
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);
@@ -451,7 +470,7 @@ main (int argc, char **argv)
tls_available = mu_check_tls_environment ();
if (tls_available)
{
- tls_available = mu_init_tls_libs ();
+ tls_available = mu_init_tls_libs (1);
if (tls_available)
enable_stls ();
}
@@ -469,7 +488,7 @@ main (int argc, char **argv)
{
/* Make sure we are in the root directory. */
chdir ("/");
- status = pop3d_mainloop (MU_STDIN_FD, MU_STDOUT_FD);
+ status = pop3d_mainloop (MU_STDIN_FD, MU_STDOUT_FD, 0);
}
if (status)
diff --git a/pop3d/pop3d.h b/pop3d/pop3d.h
index 0696c51f3..2ae628654 100644
--- a/pop3d/pop3d.h
+++ b/pop3d/pop3d.h
@@ -236,7 +236,7 @@ extern void enable_stls (void);
#endif /* WITH_TLS */
extern void pop3d_outf (const char *fmt, ...) MU_PRINTFLIKE(1,2);
-extern void pop3d_setio (int, int);
+extern void pop3d_setio (int, int, int);
extern char *pop3d_readline (char *, size_t);
extern void pop3d_flush_output (void);

Return to:

Send suggestions and report system problems to the System administrator.