Commit 3532efec 3532efec550eb2192ebecc64493d2ab6b5d2129a by Sergey Poznyakoff

Fix TLS support, improve GOCS subsystem.

* include/mailutils/gocs.h (gocs_init_fp): Rename to mu_gocs_init_fp. Change
signature.
(mu_gocs_mailbox_init, mu_gocs_locking_init, mu_gocs_source_email_init)
(mu_gocs_mailer_init, mu_gocs_logging_init)
(mu_gocs_debug_init): Fix prototypes.
* include/mailutils/gsasl.h (mu_gsasl_module_init): Update prototype.
* include/mailutils/libsieve.h (mu_sieve_module_init): Update prototype.
* include/mailutils/mu_auth.h (struct mu_auth_module.init): Update type
to mu_gocs_init_fp.
* include/mailutils/radius.h (mu_radius_module_init): Update prototype.

* include/mailutils/tls.h (struct mu_tls_module_config.client_enable):
Replace with .enable. It affects entire TLS subsystem, not only client
part.
(mu_tls_module_init): Update prototype.
* include/mailutils/types.hin (mu_gocs_op): New enum.

* mailbox/gocs.c (mu_gocs_dummy, mu_gocs_mailbox_init)
(mu_gocs_locking_init, mu_gocs_source_email_init)
(mu_gocs_mailer_init, mu_gocs_logging_init)
(mu_gocs_debug_init): Take two arguments.
(mu_gocs_flush): After running set stage, call all init callbacks with
mu_gocs_op_flush.

* auth/tls.c (mu_tls_module_config): Initialize .enable to 1.
(mu_tls_module_init): Rewrite using new prototype.
Use mu_gocs_op_flush to initialize the library.
(mu_init_tls_libs): Initialize the library only if mu_tls_module_config.enable
is set.
* auth/gsasl.c (mu_gsasl_module_init): Update.
* auth/ldap.c (mu_ldap_module_init): Update.
* auth/pam.c (mu_pam_module_init): Update.
* auth/radius.c (mu_radius_module_init): Update.
* auth/sql.c (mu_sql_module_init): Update.
* auth/virtual.c (mu_virtual_module_init): Update.
* libcfg/tls.c (mu_tls_param): Update.
* libsieve/conf.c (mu_sieve_module_init): Update.
* doc/texinfo/programs.texi: Update.
1 parent 7b333284
......@@ -36,18 +36,15 @@
#include <gsasl.h>
#include <lbuf.h>
struct mu_gsasl_module_data mu_gsasl_module_data;
struct mu_gsasl_module_data mu_gsasl_module_data = {
SITE_CRAM_MD5_PWD
};
int
mu_gsasl_module_init (void *data)
mu_gsasl_module_init (enum mu_gocs_op op, void *data)
{
static struct mu_gsasl_module_data _default_module_data = {
SITE_CRAM_MD5_PWD
};
if (!data)
mu_gsasl_module_data = _default_module_data;
memcpy (&mu_gsasl_module_data, data, sizeof (mu_gsasl_module_data));
if (op == mu_gocs_op_set && data)
memcpy (&mu_gsasl_module_data, data, sizeof (mu_gsasl_module_data));
return 0;
}
......
......@@ -59,9 +59,13 @@ const char *default_field_map =
static struct mu_ldap_module_config ldap_param;
int
mu_ldap_module_init (void *data)
mu_ldap_module_init (enum mu_gocs_op op, void *data)
{
struct mu_ldap_module_config *cfg = data;
if (op != mu_gocs_op_set)
return 0;
if (cfg)
ldap_param = *cfg;
......
/* GNU Mailutils -- a suite of utilities for electronic mail
Copyright (C) 2002, 2007 Free Software Foundation, Inc.
Copyright (C) 2002, 2007, 2008 Free Software Foundation, Inc.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
......@@ -146,9 +146,9 @@ mu_authenticate_pam (struct mu_auth_data **return_data MU_ARG_UNUSED,
#endif
int
mu_pam_module_init (void *data)
mu_pam_module_init (enum mu_gocs_op op, void *data)
{
if (data)
if (op == mu_gocs_op_set && data)
{
struct mu_gocs_pam *p = data;
mu_pam_service = p->service ? strdup (p->service) : p->service;
......
......@@ -210,10 +210,12 @@ mu_grad_logger(int level,
}
int
mu_radius_module_init (void *data)
mu_radius_module_init (enum mu_gocs_op op, void *data)
{
struct mu_radius_module_data *cfg = data;
if (op != mu_gocs_op_set)
return 0;
if (!NEED_RADIUS_P (cfg))
return 0;
......
......@@ -607,10 +607,12 @@ mu_sql_authenticate (struct mu_auth_data **return_data MU_ARG_UNUSED,
}
int
mu_sql_module_init (void *data)
mu_sql_module_init (enum mu_gocs_op op, void *data)
{
struct mu_sql_module_config *cfg = data;
if (op != mu_gocs_op_set)
return 0;
mu_sql_module_config.interface = mu_sql_interface_index (cfg->interface);
if (mu_sql_module_config.interface == 0)
{
......
/* GNU Mailutils -- a suite of utilities for electronic mail
Copyright (C) 2003, 2004, 2007 Free Software Foundation, Inc.
Copyright (C) 2003, 2004, 2007, 2008 Free Software Foundation, Inc.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
......@@ -36,18 +36,22 @@
#include <lbuf.h>
struct mu_tls_module_config mu_tls_module_config;
struct mu_tls_module_config mu_tls_module_config = { 1, NULL, NULL, NULL };
int
mu_tls_module_init (void *data)
mu_tls_module_init (enum mu_gocs_op op, void *data)
{
if (data)
switch (op)
{
memcpy (&mu_tls_module_config, data, sizeof mu_tls_module_config);
case mu_gocs_op_set:
if (data)
memcpy (&mu_tls_module_config, data, sizeof mu_tls_module_config);
break;
case mu_gocs_op_flush:
#ifdef WITH_TLS
if (mu_tls_module_config.client_enable)
mu_init_tls_libs ();
#endif
mu_init_tls_libs ();
#endif
}
return 0;
}
......@@ -113,7 +117,7 @@ int mu_tls_enable = 0;
int
mu_init_tls_libs (void)
{
if (!mu_tls_enable)
if (mu_tls_module_config.enable && !mu_tls_enable)
mu_tls_enable = !gnutls_global_init (); /* Returns 1 on success */
return mu_tls_enable;
}
......
/* GNU Mailutils -- a suite of utilities for electronic mail
Copyright (C) 2002, 2006, 2007 Free Software Foundation, Inc.
Copyright (C) 2002, 2006, 2007, 2008 Free Software Foundation, Inc.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
......@@ -58,9 +58,9 @@
struct mu_gocs_virtual mu_virtual_module_config = { SITE_VIRTUAL_PWDDIR };
int
mu_virtual_module_init (void *data)
mu_virtual_module_init (enum mu_gocs_op op, void *data)
{
if (data)
if (op == mu_gocs_op_set && data)
{
struct mu_gocs_virtual *p = data;
mu_virtual_module_config = *p;
......
......@@ -2042,8 +2042,8 @@ ldap @{
@subheading Syntax
@smallexample
tls @{
# @r{Enable client TLS encryption.}
tls @var{bool};
# @r{Enable TLS support.}
enable @var{bool};
# @r{Specify SSL certificate file.}
ssl-cert @var{bool};
# @r{Specify SSL certificate key file.}
......
......@@ -82,20 +82,20 @@ extern int mu_load_user_rcfile;
extern int mu_load_site_rcfile;
extern char *mu_load_rcfile;
typedef int (*gocs_init_fp) (void *data);
typedef int (*mu_gocs_init_fp) (enum mu_gocs_op op, void *data);
void mu_gocs_register (const char *capa, gocs_init_fp init);
void mu_gocs_register (const char *capa, mu_gocs_init_fp init);
void mu_gocs_register_std (const char *name);
void mu_gocs_store (char *capa, void *data);
void mu_gocs_flush (void);
int mu_gocs_enumerate (mu_list_action_t action, void *data);
int mu_gocs_mailbox_init (void *data);
int mu_gocs_locking_init (void *data);
int mu_gocs_source_email_init (void *data);
int mu_gocs_mailer_init (void *data);
int mu_gocs_logging_init (void *data);
int mu_gocs_debug_init (void *data);
int mu_gocs_mailbox_init (enum mu_gocs_op, void *data);
int mu_gocs_locking_init (enum mu_gocs_op, void *data);
int mu_gocs_source_email_init (enum mu_gocs_op, void *data);
int mu_gocs_mailer_init (enum mu_gocs_op, void *data);
int mu_gocs_logging_init (enum mu_gocs_op, void *data);
int mu_gocs_debug_init (enum mu_gocs_op, void *data);
#ifdef __cplusplus
}
......
......@@ -28,7 +28,7 @@ struct mu_gsasl_module_data
char *cram_md5_pwd;
};
int mu_gsasl_module_init (void *data);
int mu_gsasl_module_init (enum mu_gocs_op, void *);
struct mu_gsasl_module_data mu_gsasl_module_data;
......
......@@ -275,7 +275,7 @@ struct mu_gocs_sieve
mu_list_t library_path;
};
int mu_sieve_module_init (void *);
int mu_sieve_module_init (enum mu_gocs_op, void *);
#ifdef __cplusplus
}
......
......@@ -66,14 +66,14 @@ typedef int (*mu_auth_fp) (struct mu_auth_data **data,
struct mu_auth_module
{
char *name;
gocs_init_fp init;
mu_auth_fp authenticate;
void *authenticate_data;
mu_auth_fp auth_by_name;
void *auth_by_name_data;
mu_auth_fp auth_by_uid;
void *auth_by_uid_data;
char *name;
mu_gocs_init_fp init;
mu_auth_fp authenticate;
void *authenticate_data;
mu_auth_fp auth_by_name;
void *auth_by_name_data;
mu_auth_fp auth_by_uid;
void *auth_by_uid_data;
};
enum mu_auth_key_type
......
/* GNU Mailutils -- a suite of utilities for electronic mail
Copyright (C) 1999, 2000, 2001, 2004, 2005,
2007 Free Software Foundation, Inc.
2007, 2008 Free Software Foundation, Inc.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
......@@ -29,6 +29,6 @@ struct mu_radius_module_data
char *getpwuid_request;
};
extern int mu_radius_module_init (void *data);
extern int mu_radius_module_init (enum mu_gocs_op, void *data);
#endif
......
/* GNU Mailutils -- a suite of utilities for electronic mail
Copyright (C) 2003, 2005, 2007 Free Software Foundation, Inc.
Copyright (C) 2003, 2005, 2007, 2008 Free Software Foundation, Inc.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
......@@ -27,13 +27,13 @@ extern "C" {
struct mu_tls_module_config
{
int client_enable;
int enable;
char *ssl_cert;
char *ssl_key;
char *ssl_cafile;
};
extern int mu_tls_module_init (void *data);
extern int mu_tls_module_init (enum mu_gocs_op, void *);
extern int mu_tls_stream_create (mu_stream_t *stream,
mu_stream_t strin, mu_stream_t strout,
......
......@@ -123,7 +123,13 @@ typedef struct _mu_progmailer *mu_progmailer_t;
#define MU_ARRAY_SIZE(a) (sizeof(a)/sizeof((a)[0]))
#define MU_DEFAULT_RECORD _MU_DEFAULT_RECORD_
enum mu_gocs_op
{
mu_gocs_op_set,
mu_gocs_op_flush
};
#ifdef __cplusplus
}
#endif
......
/* This file is part of GNU Mailutils
Copyright (C) 2007 Free Software Foundation, Inc.
Copyright (C) 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
......@@ -25,7 +25,7 @@
static struct mu_tls_module_config tls_settings;
static struct mu_cfg_param mu_tls_param[] = {
{ "tls", mu_cfg_bool, &tls_settings.client_enable, 0, NULL,
{ "enable", mu_cfg_bool, &tls_settings.enable, 0, NULL,
N_("Enable client TLS encryption.") },
{ "ssl-cert", mu_cfg_string, &tls_settings.ssl_cert, 0, NULL,
N_("Specify SSL certificate file."),
......
......@@ -50,10 +50,10 @@ _path_append (void *item, void *data)
}
int
mu_sieve_module_init (void *data)
mu_sieve_module_init (enum mu_gocs_op op, void *data)
{
struct mu_gocs_sieve *p;
if (!data)
if (!(op == mu_gocs_op_set && data))
return 0;
p = data;
......
......@@ -41,53 +41,54 @@ char *mu_load_rcfile = NULL;
int
mu_gocs_dummy (void *data)
mu_gocs_dummy (enum mu_gocs_op op, void *data)
{
return 0;
}
int
mu_gocs_mailbox_init (void *data)
mu_gocs_mailbox_init (enum mu_gocs_op op, void *data)
{
int rc;
struct mu_gocs_mailbox *p = data;
if (!p)
return 0;
if (p->mail_spool)
{
rc = mu_set_mail_directory (p->mail_spool);
if (rc)
mu_error (_("Cannot set mail directory name to `%s': %s"),
p->mail_spool, mu_strerror (rc));
free (p->mail_spool);
p->mail_spool = NULL;
}
if (p->mailbox_pattern)
{
rc = mu_set_mailbox_pattern (p->mailbox_pattern);
if (rc)
mu_error (_("Cannot set mailbox pattern to `%s': %s"),
p->mailbox_pattern, mu_strerror (rc));
free (p->mailbox_pattern);
p->mailbox_pattern = NULL;
}
if (p->mailbox_type)
if (op == mu_gocs_op_set && p)
{
if (mu_registrar_set_default_scheme (p->mailbox_type))
mu_error (_("Invalid mailbox type: %s"), p->mailbox_type);
free (p->mailbox_type);
p->mailbox_type = NULL;
if (p->mail_spool)
{
rc = mu_set_mail_directory (p->mail_spool);
if (rc)
mu_error (_("Cannot set mail directory name to `%s': %s"),
p->mail_spool, mu_strerror (rc));
free (p->mail_spool);
p->mail_spool = NULL;
}
if (p->mailbox_pattern)
{
rc = mu_set_mailbox_pattern (p->mailbox_pattern);
if (rc)
mu_error (_("Cannot set mailbox pattern to `%s': %s"),
p->mailbox_pattern, mu_strerror (rc));
free (p->mailbox_pattern);
p->mailbox_pattern = NULL;
}
if (p->mailbox_type)
{
if (mu_registrar_set_default_scheme (p->mailbox_type))
mu_error (_("Invalid mailbox type: %s"), p->mailbox_type);
free (p->mailbox_type);
p->mailbox_type = NULL;
}
}
return 0;
}
int
mu_gocs_locking_init (void *data)
mu_gocs_locking_init (enum mu_gocs_op op, void *data)
{
struct mu_gocs_locking *p = data;
if (!p)
if (!(op == mu_gocs_op_set && p))
return 0;
if (p->lock_flags)
......@@ -156,12 +157,12 @@ mu_gocs_locking_init (void *data)
}
int
mu_gocs_source_email_init (void *data)
mu_gocs_source_email_init (enum mu_gocs_op op, void *data)
{
struct mu_gocs_source_email *p = data;
int rc;
if (!p)
if (!(op == mu_gocs_op_set && p))
return 0;
if (p->address)
......@@ -186,12 +187,12 @@ mu_gocs_source_email_init (void *data)
}
int
mu_gocs_mailer_init (void *data)
mu_gocs_mailer_init (enum mu_gocs_op op, void *data)
{
struct mu_gocs_mailer *p = data;
int rc;
if (!p)
if (!(op == mu_gocs_op_set && p))
return 0;
if (p->mailer)
......@@ -206,37 +207,38 @@ mu_gocs_mailer_init (void *data)
}
int
mu_gocs_logging_init (void *data)
mu_gocs_logging_init (enum mu_gocs_op op, void *data)
{
struct mu_gocs_logging *p = data;
if (!p)
if (op == mu_gocs_op_set)
{
static struct mu_gocs_logging default_gocs_logging = { LOG_FACILITY };
p = &default_gocs_logging;
}
if (!p)
{
static struct mu_gocs_logging default_gocs_logging = { LOG_FACILITY };
p = &default_gocs_logging;
}
if (p->facility)
{
mu_log_facility = p->facility;
mu_debug_default_printer = mu_debug_syslog_printer;
}
else
mu_debug_default_printer = mu_debug_stderr_printer;
if (p->facility)
{
mu_log_facility = p->facility;
mu_debug_default_printer = mu_debug_syslog_printer;
}
else
mu_debug_default_printer = mu_debug_stderr_printer;
if (p->tag)
mu_log_tag = strdup (p->tag);
/* FIXME: Tag */
if (p->tag)
mu_log_tag = strdup (p->tag);
}
return 0;
}
int
mu_gocs_debug_init (void *data)
mu_gocs_debug_init (enum mu_gocs_op op, void *data)
{
struct mu_gocs_debug *p;
if (data)
if (op == mu_gocs_op_set && data)
{
p = data;
struct mu_gocs_debug *p = data;
if (p->string && p->errpfx)
{
mu_global_debug_from_string (p->string, p->errpfx);
......@@ -252,7 +254,7 @@ mu_gocs_debug_init (void *data)
struct mu_gocs_entry
{
const char *name;
gocs_init_fp init;
mu_gocs_init_fp init;
};
#define MAX_GOCS 512
......@@ -260,7 +262,7 @@ struct mu_gocs_entry
static struct mu_gocs_entry _gocs_table[MAX_GOCS];
void
mu_gocs_register (const char *capa, gocs_init_fp init)
mu_gocs_register (const char *capa, mu_gocs_init_fp init)
{
int i;
for (i = 0; _gocs_table[i].name; i++)
......@@ -287,7 +289,7 @@ mu_gocs_enumerate (mu_list_action_t action, void *data)
return 0;
}
static gocs_init_fp
static mu_gocs_init_fp
find_init_function (struct mu_gocs_entry *tab, const char *capa)
{
for (; tab->name; tab++)
......@@ -312,7 +314,7 @@ static struct mu_gocs_entry std_gocs_table[] = {
void
mu_gocs_register_std (const char *name)
{
gocs_init_fp init = find_init_function (std_gocs_table, name);
mu_gocs_init_fp init = find_init_function (std_gocs_table, name);
if (!init)
{
mu_error (_("INTERNAL ERROR at %s:%d: unknown standard capability `%s'"),
......@@ -372,7 +374,7 @@ int
_gocs_flush (void *item, void *data)
{
struct mu_gocs_data *s = item;
gocs_init_fp initfun = find_init_function (_gocs_table, s->capa);
mu_gocs_init_fp initfun = find_init_function (_gocs_table, s->capa);
if (!initfun)
{
......@@ -381,7 +383,7 @@ _gocs_flush (void *item, void *data)
abort ();
}
if (initfun (s->data))
if (initfun (mu_gocs_op_set, s->data))
{
mu_error (_("Initialization of GOCS `%s' failed"), s->capa);
return 1;
......@@ -393,5 +395,9 @@ _gocs_flush (void *item, void *data)
void
mu_gocs_flush ()
{
int i;
mu_list_do (data_list, _gocs_flush, NULL);
for (i = 0; _gocs_table[i].name; i++)
_gocs_table[i].init (mu_gocs_op_flush, NULL);
}
......