summaryrefslogtreecommitdiff
path: root/libmu_auth
diff options
context:
space:
mode:
authorSergey Poznyakoff <gray@gnu.org.ua>2016-10-19 17:20:42 +0300
committerSergey Poznyakoff <gray@gnu.org.ua>2016-10-19 19:20:31 +0300
commitdc78d43ff77a65e3400af0401142aca2ebb6cd1e (patch)
tree61b7442d72109e743527a19e5e4ae575a749ed2d /libmu_auth
parentd1339b3ffaa3d82e21c3a36e5bdfccee3246904d (diff)
downloadmailutils-dc78d43ff77a65e3400af0401142aca2ebb6cd1e.tar.gz
mailutils-dc78d43ff77a65e3400af0401142aca2ebb6cd1e.tar.bz2
Convert remaining utilities (except mh) to mu_cli.
* Makefile.am: Remove libmu_argp and libmu_cfg * configure.ac: Likewise. * libmu_argp/: Remove. * libmu_cfg/: Remove. * include/mailutils/Makefile.am (pkginclude_HEADERS): Remove gocs.h, libargp.h, libcfg.h * frm/frm.c: Register tls auth module * frm/from.c: Likewise. * maidag/maidag.c: Likewise. * mail/mail.c: Likewise. * messages/messages.c: Likewise. * movemail/movemail.c: Likewise. * readmsg/readmsg.c: Likewise. * sieve/sieve.c: Likewise. * frm/frm.h: Remove obsolete includes * imap4d/Makefile.am: Update. * imap4d/imap4d.c: Use mu_cli for command line and configuration parsing. * imap4d/imap4d.h: Update. * include/mailutils/gocs.h: Remove. * libmailutils/cfg/gocs.c: Remove. * libmailutils/cfg/Makefile.am: Remove gocs.c * include/mailutils/cli.h (mu_cli_capa_apply): Rename to mu_cli_capa_extend_settings (mu_cli_setup) <inorder, prog_doc_hook>: New fields. * include/mailutils/daemon.h: Remove obsolete includes. * include/mailutils/gsasl.h: Likewise. * include/mailutils/mailutils.h: Update. * include/mailutils/mu_auth.h (mu_auth_mode): New enum (mu_auth_module): Redo structure. * include/mailutils/opt.h (mu_parseopt) <po_prog_doc_hook>: New field. * include/mailutils/sql.h (mu_sql_module_config): New extern. (mu_sql_interface_index): Change proto. * libmailutils/auth/mu_auth.c: Rewrite. * libmailutils/auth/system.c (mu_auth_system_module): Update structure * libmailutils/cli/capa.c (mu_cli_capa_apply): Rename to mu_cli_capa_extend_settings * libmailutils/cli/cli.c: Extend settings from auth modules as well. * libmailutils/opt/help.c (mu_program_help): Invoke po_prog_doc_hook if defined. * libmailutils/opt/opt.c (parseopt_init): Check the MU_PARSEOPT_PROG_DOC_HOOK flag. (find_long_option): Fix recognition of ambiguous options in case of exact match. * libmu_auth/gsasl.c: Add configuration. * libmu_auth/ldap.c: Likewise. * libmu_auth/pam.c: Likewise. * libmu_auth/radius.c: Likewise. * libmu_auth/sql.c: Likewise. * libmu_auth/tls.c: Likewise. * libmu_auth/virtual.c: Likewise. * mu/Makefile.am: Update. * mu/mu.c: Rewrite using mu_cli * mu/mu.h: Likewise. * mu/acl.c: Likewise. * mu/cflags.c: Likewise. * mu/dbm.c: Likewise. * mu/dispatch.c: Likewise. * mu/filter.c: Likewise. * mu/flt2047.c: Likewise. * mu/getans.c: Likewise. * mu/getarg.c: Likewise. * mu/getyn.c: Likewise. * mu/help.c: Likewise. * mu/imap.c: Likewise. * mu/info.c: Likewise. * mu/ldflags.c: Likewise. * mu/logger.c: Likewise. * mu/pop.c: Likewise. * mu/query.c: Likewise. * mu/send.c: Likewise. * mu/shell.c: Likewise. * mu/smtp.c: Likewise. * mu/util.c: Likewise. * mu/verbose.c: Likewise. * mu/wicket.c: Likewise. * pop3d/Makefile.am: Update. * pop3d/pop3d.c: Convert to mu_cli interface. * pop3d/pop3d.h: Likewise. * sql/sql.c (mu_sql_interface_index): Change argument qualifiers.
Diffstat (limited to 'libmu_auth')
-rw-r--r--libmu_auth/gsasl.c37
-rw-r--r--libmu_auth/ldap.c101
-rw-r--r--libmu_auth/pam.c48
-rw-r--r--libmu_auth/radius.c147
-rw-r--r--libmu_auth/sql.c136
-rw-r--r--libmu_auth/tls.c30
-rw-r--r--libmu_auth/virtual.c51
7 files changed, 318 insertions, 232 deletions
diff --git a/libmu_auth/gsasl.c b/libmu_auth/gsasl.c
index 5ffd0fe01..e8c50dc6e 100644
--- a/libmu_auth/gsasl.c
+++ b/libmu_auth/gsasl.c
@@ -19,6 +19,7 @@
#if HAVE_CONFIG_H
# include <config.h>
#endif
+#include <mailutils/cli.h>
#ifdef WITH_GSASL
@@ -45,14 +46,28 @@ struct mu_gsasl_module_data mu_gsasl_module_data = {
NULL,
SITE_CRAM_MD5_PWD
};
-
-int
-mu_gsasl_module_init (enum mu_gocs_op op, void *data)
-{
- if (op == mu_gocs_op_set && data)
- memcpy (&mu_gsasl_module_data, data, sizeof (mu_gsasl_module_data));
- return 0;
-}
+
+static struct mu_cfg_param mu_gsasl_param[] = {
+ { "enable", mu_c_bool, &mu_gsasl_module_data.enable, 0, NULL,
+ N_("Enable GSASL (default)") },
+ { "cram-passwd", mu_c_string, &mu_gsasl_module_data.cram_md5_pwd, 0, NULL,
+ N_("Name of GSASL password file."),
+ N_("file") },
+ { "service", mu_c_string, &mu_gsasl_module_data.service, 0, NULL,
+ N_("SASL service name."),
+ N_("name") },
+ { "realm", mu_c_string, &mu_gsasl_module_data.realm, 0, NULL,
+ N_("SASL realm name."),
+ N_("name") },
+ { "hostname", mu_c_string, &mu_gsasl_module_data.hostname, 0, NULL,
+ N_("SASL host name."),
+ N_("name") },
+ { "anonymous-user", mu_c_string, &mu_gsasl_module_data.anon_user, 0, NULL,
+ N_("Anonymous user name."),
+ N_("name") },
+
+ { NULL }
+};
int
mu_gsasl_enabled (void)
@@ -231,4 +246,10 @@ mu_gsasl_enabled (void)
{
return 0;
}
+#define mu_gsasl_param NULL
#endif
+
+struct mu_auth_module mu_auth_gsasl_module = {
+ .name = "gsasl",
+ .cfg = mu_gsasl_param
+};
diff --git a/libmu_auth/ldap.c b/libmu_auth/ldap.c
index 7c321f29b..246f80278 100644
--- a/libmu_auth/ldap.c
+++ b/libmu_auth/ldap.c
@@ -61,17 +61,82 @@ const char *default_field_map =
static struct mu_ldap_module_config ldap_param;
-int
-mu_ldap_module_init (enum mu_gocs_op op, void *data)
+
+
+static int
+_cb2_field_map (const char *arg, void *data)
+{
+ int err;
+ int rc = mutil_parse_field_map (arg, &ldap_param.field_map, &err);
+ if (rc)
+ /* FIXME: this message can be misleading */
+ mu_error (_("error near element %d: %s"), err, mu_strerror (rc));
+ return 0;
+}
+
+static int
+cb_field_map (void *data, mu_config_value_t *val)
{
- struct mu_ldap_module_config *cfg = data;
+ return mu_cfg_string_value_cb (val, _cb2_field_map, NULL);
+}
- if (op != mu_gocs_op_set)
- return 0;
-
- if (cfg)
- ldap_param = *cfg;
+static struct mu_cfg_param mu_ldap_param[] = {
+ { "enable", mu_c_bool, &ldap_param.enable, 0, NULL,
+ N_("Enable LDAP lookups.") },
+ { "url", mu_c_string, &ldap_param.url, 0, NULL,
+ N_("Set URL of the LDAP server."),
+ N_("url") },
+ { "base", mu_c_string, &ldap_param.base, 0, NULL,
+ N_("Base DN for LDAP lookups."),
+ N_("dn") },
+ { "binddn", mu_c_string, &ldap_param.binddn, 0, NULL,
+ N_("DN for accessing LDAP database."),
+ N_("dn") },
+ { "passwd", mu_c_string, &ldap_param.passwd, 0, NULL,
+ N_("Password for use with binddn.") },
+ { "tls", mu_c_bool, &ldap_param.tls, 0, NULL,
+ N_("Use TLS encryption.") },
+ { "debug", mu_c_int, &ldap_param.debug, 0, NULL,
+ N_("Set LDAP debugging level.") },
+ { "field-map", mu_cfg_callback, NULL, 0, cb_field_map,
+ N_("Set a field-map for parsing LDAP replies. The map is a "
+ "column-separated list of definitions. Each definition has the "
+ "following form:\n"
+ " <name: string>=<attr: string>\n"
+ "where <name> is one of the following: name, passwd, uid, gid, "
+ "gecos, dir, shell, mailbox, quota, and <attr> is the name of "
+ "the corresponding LDAP attribute."),
+ N_("map") },
+ { "getpwnam", mu_c_string, &ldap_param.getpwnam_filter, 0, NULL,
+ N_("LDAP filter to use for getpwnam requests."),
+ N_("filter") },
+ { "getpwuid", mu_c_string, &ldap_param.getpwuid_filter, 0, NULL,
+ N_("LDAP filter to use for getpwuid requests."),
+ N_("filter") },
+ { NULL }
+};
+
+int
+mu_ldap_section_parser
+ (enum mu_cfg_section_stage stage, const mu_cfg_node_t *node,
+ const char *section_label, void **section_data,
+ void *call_data, mu_cfg_tree_t *tree)
+{
+ switch (stage)
+ {
+ case mu_cfg_section_start:
+ ldap_param.enable = 1;
+ break;
+ default:
+ break;
+ }
+ return 0;
+}
+
+static void
+module_init (void *ptr)
+{
if (ldap_param.enable)
{
if (!ldap_param.getpwnam_filter)
@@ -85,7 +150,6 @@ mu_ldap_module_init (enum mu_gocs_op op, void *data)
mutil_parse_field_map (default_field_map, &ldap_param.field_map, &d);
}
}
- return 0;
}
static int
@@ -271,8 +335,6 @@ _mu_conn_setup (LDAP **pld)
*pld = ld;
return 0;
}
-
-
static int
_mu_ldap_bind (LDAP *ld)
@@ -862,15 +924,16 @@ mu_auth_ldap_user_by_uid (struct mu_auth_data **return_data,
# define mu_ldap_authenticate mu_auth_nosupport
# define mu_auth_ldap_user_by_name mu_auth_nosupport
# define mu_auth_ldap_user_by_uid mu_auth_nosupport
+
#endif
struct mu_auth_module mu_auth_ldap_module = {
- "ldap",
- mu_ldap_module_init,
- mu_ldap_authenticate,
- NULL,
- mu_auth_ldap_user_by_name,
- NULL,
- mu_auth_ldap_user_by_uid,
- NULL
+ .name = "ldap",
+ .commit = module_init,
+ .handler = {
+ [mu_auth_authenticate] = mu_ldap_authenticate,
+ [mu_auth_getpwnam] = mu_auth_ldap_user_by_name,
+ [mu_auth_getpwuid] = mu_auth_ldap_user_by_uid
+ },
+ .cfg = mu_ldap_param
};
diff --git a/libmu_auth/pam.c b/libmu_auth/pam.c
index 2bf36833e..fbc3e3e39 100644
--- a/libmu_auth/pam.c
+++ b/libmu_auth/pam.c
@@ -49,6 +49,14 @@
char *mu_pam_service = PACKAGE;
#ifdef USE_LIBPAM
+static struct mu_cfg_param mu_pam_param[] = {
+ { "service", mu_c_string, &mu_pam_service, 0, NULL,
+ N_("Set PAM service name."),
+ N_("name") },
+ { NULL }
+};
+
+
#define COPY_STRING(s) (s) ? strdup(s) : NULL
static char *_pwd;
@@ -175,43 +183,13 @@ mu_authenticate_pam (struct mu_auth_data **return_data MU_ARG_UNUSED,
}
#else
-
-int
-mu_authenticate_pam (struct mu_auth_data **return_data MU_ARG_UNUSED,
- const void *key MU_ARG_UNUSED,
- void *func_data MU_ARG_UNUSED,
- void *call_data MU_ARG_UNUSED)
-{
- return ENOSYS;
-}
-
+# define mu_pam_param NULL
+# define mu_authenticate_pam NULL
#endif
-int
-mu_pam_module_init (enum mu_gocs_op op, void *data)
-{
- if (op == mu_gocs_op_set && data)
- {
- struct mu_gocs_pam *p = data;
- if (p->service)
- {
- if ((mu_pam_service = strdup (p->service)) == NULL)
- return ENOMEM;
- }
- else
- mu_pam_service = NULL;
- }
- return 0;
-}
-
struct mu_auth_module mu_auth_pam_module = {
- "pam",
- mu_pam_module_init,
- mu_authenticate_pam,
- NULL,
- mu_auth_nosupport,
- NULL,
- mu_auth_nosupport,
- NULL
+ .name = "pam",
+ .handler = { [mu_auth_authenticate] = mu_authenticate_pam },
+ .cfg = mu_pam_param
};
diff --git a/libmu_auth/radius.c b/libmu_auth/radius.c
index f6e7e28d8..4d6c380a0 100644
--- a/libmu_auth/radius.c
+++ b/libmu_auth/radius.c
@@ -42,6 +42,9 @@
#include <mailutils/nls.h>
#include <mailutils/io.h>
#include <mailutils/cctype.h>
+#include <mailutils/cli.h>
+#include <mailutils/stream.h>
+#include <mailutils/stdstream.h>
#ifdef ENABLE_RADIUS
@@ -62,7 +65,6 @@ static grad_avp_t *auth_request;
static grad_avp_t *getpwnam_request;
static grad_avp_t *getpwuid_request;
-
int
get_attribute (int *pattr, char *name)
{
@@ -84,30 +86,41 @@ enum parse_state
state_delim
};
-int
-parse_pairlist (grad_avp_t **plist, char *input)
+static int
+cb_request (void *data, mu_config_value_t *val)
{
+ grad_avp_t **plist = data;
size_t i;
struct mu_wordsplit ws;
enum parse_state state;
grad_locus_t loc;
char *name;
- char *op; /* FIXME: It is actually ignored. Should it be? */
-
- if (!input)
+ struct mu_locus locus;
+
+ if (mu_cfg_assert_value_type (val, MU_CFG_STRING))
return 1;
ws.ws_delim = ",";
- if (mu_wordsplit (input, &ws,
+ if (mu_wordsplit (val->v.string, &ws,
MU_WRDSF_DEFFLAGS|MU_WRDSF_DELIM|MU_WRDSF_RETURN_DELIMS))
{
- mu_error (_("cannot parse input `%s': %s"), input,
+ mu_error (_("cannot parse input `%s': %s"), val->v.string,
mu_wordsplit_strerror (&ws));
return 1;
}
- loc.file = "<configuration>"; /*FIXME*/
- loc.line = 0;
+ if (mu_stream_ioctl (mu_strerr, MU_IOCTL_LOGSTREAM,
+ MU_IOCTL_LOGSTREAM_GET_LOCUS,
+ &locus) == 0)
+ {
+ loc.file = locus.mu_file;
+ loc.line = locus.mu_line;
+ }
+ else
+ {
+ loc.file = "<unknown>";
+ loc.line = 0;
+ }
for (i = 0, state = state_lhs; i < ws.ws_wordc; i++)
{
@@ -121,7 +134,7 @@ parse_pairlist (grad_avp_t **plist, char *input)
break;
case state_op:
- op = ws.ws_wordv[i];
+ //op = ws.ws_wordv[i];
state = state_rhs;
break;
@@ -155,16 +168,45 @@ parse_pairlist (grad_avp_t **plist, char *input)
return 1;
}
+ return 0;
+}
+
+static int
+cb_config_dir (void *data, mu_config_value_t *val)
+{
+ if (mu_cfg_assert_value_type (val, MU_CFG_STRING))
+ return 1;
+ grad_config_dir = grad_estrdup (val->v.string);
return 0;
}
+static struct mu_cfg_param mu_radius_param[] = {
+ { "auth", mu_cfg_callback, &auth_request, 0, cb_request,
+ N_("Radius request for authorization."),
+ N_("request: string") },
+ { "getpwnam", mu_cfg_callback, &getpwnam_request, 0, cb_request,
+ N_("Radius request for getpwnam."),
+ N_("request: string") },
+ { "getpwuid", mu_cfg_callback, &getpwuid_request, 0, cb_request,
+ N_("Radius request for getpwuid."),
+ N_("request: string") },
+ { "directory", mu_cfg_callback, NULL, 0, cb_config_dir,
+ N_("Set radius configuration directory.") },
+ { NULL }
+};
+
+struct mu_cli_capa mu_cli_capa_radius = {
+ "radius",
+ NULL,
+ mu_radius_param
+};
+
/* Assume radius support is needed if any of the above requests is
defined. Actually, all of them should be, but it is the responsibility
of init to check for consistency of the configuration */
-#define NEED_RADIUS_P(cfg) \
- ((cfg) && \
- ((cfg)->auth_request || (cfg)->getpwnam_request || (cfg)->getpwuid_request))
+#define NEED_RADIUS_P() \
+ (auth_request || getpwnam_request || getpwuid_request)
static void
mu_grad_logger(int level,
@@ -196,21 +238,16 @@ mu_grad_logger(int level,
}
mu_diag_voutput (mlevel[level & GRAD_LOG_PRIMASK], pfx ? pfx : fmt, ap);
if (pfx)
- free(pfx);
+ free (pfx);
}
-int
-mu_radius_module_init (enum mu_gocs_op op, void *data)
+static void
+module_init (void *ptr)
{
- struct mu_radius_module_data *cfg = data;
-
- if (op != mu_gocs_op_set)
- return 0;
- if (!NEED_RADIUS_P (cfg))
- return 0;
+ if (!NEED_RADIUS_P ())
+ return;
grad_set_logger (mu_grad_logger);
- grad_config_dir = grad_estrdup (cfg->config_dir);
grad_path_init ();
srand (time (NULL) + getpid ());
@@ -218,7 +255,7 @@ mu_radius_module_init (enum mu_gocs_op op, void *data)
if (grad_dict_init ())
{
mu_error (_("cannot read radius dictionaries"));
- return 1;
+ return;
}
/* Check whether mailutils attributes are defined */
@@ -229,16 +266,9 @@ mu_radius_module_init (enum mu_gocs_op op, void *data)
|| get_attribute (&MU_Dir, "MU-Dir")
|| get_attribute (&MU_Shell, "MU-Shell")
|| get_attribute (&MU_Mailbox, "MU-Mailbox"))
- return 1;
-
- /* Parse saved requests */
- if (parse_pairlist (&auth_request, cfg->auth_request)
- || parse_pairlist (&getpwnam_request, cfg->getpwnam_request)
- || parse_pairlist (&getpwuid_request, cfg->getpwuid_request))
- return 1;
+ return;
radius_auth_enabled = 1;
- return 0;
}
static char *
@@ -518,44 +548,19 @@ mu_auth_radius_user_by_uid (struct mu_auth_data **return_data,
return rc;
}
-#else
-static int
-mu_radius_authenticate (struct mu_auth_data **return_data MU_ARG_UNUSED,
- const void *key,
- void *func_data MU_ARG_UNUSED, void *call_data)
-{
- return ENOSYS;
-}
-
-static int
-mu_auth_radius_user_by_name (struct mu_auth_data **return_data MU_ARG_UNUSED,
- const void *key MU_ARG_UNUSED,
- void *func_data MU_ARG_UNUSED,
- void *call_data MU_ARG_UNUSED)
-{
- return ENOSYS;
-}
-
-static int
-mu_auth_radius_user_by_uid (struct mu_auth_data **return_data,
- const void *key,
- void *func_data, void *call_data)
-{
- return ENOSYS;
-}
-#endif
-
struct mu_auth_module mu_auth_radius_module = {
- "radius",
-#ifdef ENABLE_RADIUS
- mu_radius_module_init,
+ .name = "radius",
+ .cfg = mu_radius_param,
+ .commit = module_init,
+ .handler = {
+ [mu_auth_authenticate] = mu_radius_authenticate,
+ [mu_auth_getpwnam] = mu_auth_radius_user_by_name,
+ [mu_auth_getpwuid] = mu_auth_radius_user_by_uid
+ }
+};
#else
- NULL,
-#endif
- mu_radius_authenticate,
- NULL,
- mu_auth_radius_user_by_name,
- NULL,
- mu_auth_radius_user_by_uid,
- NULL
+struct mu_auth_module mu_auth_radius_module = {
+ .name = "radius"
};
+#endif
+
diff --git a/libmu_auth/sql.c b/libmu_auth/sql.c
index f84d9b03a..eeb3e3fdf 100644
--- a/libmu_auth/sql.c
+++ b/libmu_auth/sql.c
@@ -50,12 +50,97 @@
#include <mailutils/sql.h>
#include <mailutils/cstr.h>
#include <mailutils/wordsplit.h>
+#include <mailutils/cli.h>
#include "sql.h"
#ifdef USE_SQL
-struct mu_internal_sql_config mu_sql_module_config;
+struct mu_sql_module_config mu_sql_module_config;
+/* Resource file configuration */
+static int
+cb_password_type (void *data, mu_config_value_t *val)
+{
+ if (mu_cfg_assert_value_type (val, MU_CFG_STRING))
+ return 1;
+
+ if (mu_sql_decode_password_type (val->v.string, &mu_sql_module_config.password_type))
+ mu_error (_("unknown password type `%s'"), val->v.string);
+ return 0;
+}
+
+static int
+_cb2_field_map (const char *arg, void *data)
+{
+ int err;
+ int rc = mutil_parse_field_map (arg, &mu_sql_module_config.field_map, &err);
+ if (rc)
+ /* FIXME: this message may be misleading */
+ mu_error (_("error near element %d: %s"), err, mu_strerror (rc));
+ return 0;
+}
+static int
+cb_field_map (void *data, mu_config_value_t *val)
+{
+ return mu_cfg_string_value_cb (val, _cb2_field_map, NULL);
+}
+
+static int
+cb_interface (void *data, mu_config_value_t *val)
+{
+ if (mu_cfg_assert_value_type (val, MU_CFG_STRING))
+ return 1;
+ mu_sql_module_config.interface = mu_sql_interface_index (val->v.string);
+ if (mu_sql_module_config.interface == 0)
+ {
+ mu_error (_("unknown SQL interface `%s'"), val->v.string);
+ return 1;
+ }
+ return 0;
+}
+
+static struct mu_cfg_param mu_sql_param[] = {
+ { "interface", mu_cfg_callback, &mu_sql_module_config.interface, 0,
+ cb_interface,
+ N_("Set SQL interface to use."),
+ N_("iface: mysql|odbc|postgres") },
+ { "getpwnam", mu_c_string, &mu_sql_module_config.getpwnam_query, 0, NULL,
+ N_("SQL query to use for getpwnam requests."),
+ N_("query") },
+ { "getpwuid", mu_c_string, &mu_sql_module_config.getpwuid_query, 0, NULL,
+ N_("SQL query to use for getpwuid requests."),
+ N_("query") },
+ { "getpass", mu_c_string, &mu_sql_module_config.getpass_query, 0, NULL,
+ N_("SQL query returning the user's password."),
+ N_("query") },
+ { "host", mu_c_string, &mu_sql_module_config.host, 0, NULL,
+ N_("SQL server host name.") },
+ { "user", mu_c_string, &mu_sql_module_config.user, 0, NULL,
+ N_("SQL user name.") },
+ { "passwd", mu_c_string, &mu_sql_module_config.passwd, 0, NULL,
+ N_("Password for the SQL user.") },
+ { "port", mu_c_int, &mu_sql_module_config.port, 0, NULL,
+ N_("SQL server port.") },
+ { "db", mu_c_string, &mu_sql_module_config.db, 0, NULL,
+ N_("Database name.") },
+ { "password-type", mu_cfg_callback, NULL, 0, cb_password_type,
+ N_("Type of password returned by getpass query (one of: plain, hash, "
+ "scrambled).") },
+ { "positional", mu_c_bool, &mu_sql_module_config.positional, 0, NULL,
+ N_("Use positional (v1.0 compatible) field interface.") },
+ { "field-map", mu_cfg_callback, NULL, 0, cb_field_map,
+ N_("Set a field-map for parsing SQL replies. The map is a "
+ "column-separated list of definitions. Each definition has the "
+ "following form:\n"
+ " <name: string>=<column: string>\n"
+ "where <name> is one of the following: name, passwd, uid, gid, "
+ "gecos, dir, shell, mailbox, quota, and <column> is the name of "
+ "the corresponding SQL column."),
+ N_("map") },
+ { NULL }
+};
+
+
static char *
sql_escape_string (const char *ustr)
{
@@ -668,55 +753,22 @@ mu_sql_authenticate (struct mu_auth_data **return_data MU_ARG_UNUSED,
return rc == 0 ? 0 : MU_ERR_AUTH_FAILURE;
}
-int
-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)
- {
- mu_error (_("unknown SQL interface `%s'"), cfg->interface);
- return 1;
- }
-
- mu_sql_module_config.getpwnam_query = cfg->getpwnam_query;
- mu_sql_module_config.getpass_query = cfg->getpass_query;
- mu_sql_module_config.getpwuid_query = cfg->getpwuid_query;
- mu_sql_module_config.host = cfg->host;
- mu_sql_module_config.user = cfg->user;
- mu_sql_module_config.passwd = cfg->passwd;
- mu_sql_module_config.db = cfg->db;
- mu_sql_module_config.port = cfg->port;
- mu_sql_module_config.password_type = cfg->password_type;
- mu_sql_module_config.field_map = cfg->field_map;
-
- return 0;
-}
-
#else
# define mu_sql_authenticate mu_auth_nosupport
# define mu_auth_sql_by_name mu_auth_nosupport
# define mu_auth_sql_by_uid mu_auth_nosupport
-
+# define mu_sql_param NULL
#endif
struct mu_auth_module mu_auth_sql_module = {
- "sql",
-#ifdef USE_SQL
- mu_sql_module_init,
-#else
- NULL,
-#endif
- mu_sql_authenticate,
- NULL,
- mu_auth_sql_by_name,
- NULL,
- mu_auth_sql_by_uid,
- NULL
+ .name = "sql",
+ .cfg = mu_sql_param,
+ .handler = {
+ [mu_auth_authenticate] = mu_sql_authenticate,
+ [mu_auth_getpwnam] = mu_auth_sql_by_name,
+ [mu_auth_getpwuid] = mu_auth_sql_by_uid
+ }
};
diff --git a/libmu_auth/tls.c b/libmu_auth/tls.c
index 89e3b528b..656ff2c2d 100644
--- a/libmu_auth/tls.c
+++ b/libmu_auth/tls.c
@@ -64,22 +64,6 @@ struct mu_tls_module_config mu_tls_module_config = {
0
#endif
};
-//FIXME: REMOVE
-int
-mu_tls_module_init (enum mu_gocs_op op, void *data)
-{
- switch (op)
- {
- case mu_gocs_op_set:
- if (data)
- memcpy (&mu_tls_module_config, data, sizeof mu_tls_module_config);
- break;
-
- case mu_gocs_op_flush:
- break;
- }
- return 0;
-}
#ifdef WITH_TLS
@@ -870,16 +854,14 @@ static struct mu_cfg_param mu_tls_param[] = {
{ NULL }
};
-struct mu_cli_capa mu_cli_capa_tls = {
- "tls",
- NULL,
- mu_tls_param,
- NULL, NULL
+struct mu_auth_module mu_auth_tls_module = {
+ .name = "tls",
+ .cfg = mu_tls_param
};
+
#else
-struct mu_cli_capa mu_cli_capa_tls = {
- "tls",
- NULL
+struct mu_auth_module mu_auth_tls_module = {
+ .name = "tls"
};
#endif /* WITH_TLS */
diff --git a/libmu_auth/virtual.c b/libmu_auth/virtual.c
index b97a96bf5..171b893c8 100644
--- a/libmu_auth/virtual.c
+++ b/libmu_auth/virtual.c
@@ -53,22 +53,20 @@
#include <mailutils/nls.h>
#include <mailutils/errno.h>
#include <mailutils/util.h>
+#include <mailutils/cli.h>
#ifdef ENABLE_VIRTUAL_DOMAINS
-struct mu_gocs_virtual mu_virtual_module_config = { SITE_VIRTUAL_PWDDIR };
-
-int
-mu_virtual_module_init (enum mu_gocs_op op, void *data)
-{
- if (op == mu_gocs_op_set && data)
- {
- struct mu_gocs_virtual *p = data;
- mu_virtual_module_config = *p;
- }
- return 0;
-}
+static char *pwddir = { SITE_VIRTUAL_PWDDIR };
+static struct mu_cfg_param mu_virtdomain_param[] = {
+ { "passwd-dir", mu_c_string, &pwddir, 0, NULL,
+ N_("Name of the directory where virtual domain password files are "
+ "located."),
+ N_("dir") },
+ { NULL }
+};
+
#if !HAVE_FGETPWENT
/* FIXME: A temporary solution. Need proper declaration in .h */
extern struct passwd *mu_fgetpwent (FILE *fp);
@@ -90,7 +88,7 @@ getpwnam_virtual (const char *u)
if (delim == 0)
return NULL;
- filename = mu_make_file_name (mu_virtual_module_config.pwddir, &u[delim + 1]);
+ filename = mu_make_file_name (pwddir, &u[delim + 1]);
if (filename == NULL)
return NULL;
@@ -191,28 +189,15 @@ mu_auth_virt_domain_by_name (struct mu_auth_data **return_data,
}
#else
-static int
-mu_auth_virt_domain_by_name (struct mu_auth_data **return_data MU_ARG_UNUSED,
- const void *key MU_ARG_UNUSED,
- void *func_data MU_ARG_UNUSED,
- void *call_data MU_ARG_UNUSED)
-{
- return ENOSYS;
-}
+# define mu_virtdomain_param NULL
+# define mu_auth_virt_domain_by_name NULL
#endif
struct mu_auth_module mu_auth_virtual_module = {
- "virtdomain",
-#ifdef ENABLE_VIRTUAL_DOMAINS
- mu_virtual_module_init,
-#else
- NULL,
-#endif
- mu_auth_nosupport,
- NULL,
- mu_auth_virt_domain_by_name,
- NULL,
- mu_auth_nosupport,
- NULL
+ .name = "virtdomain",
+ .cfg = mu_virtdomain_param,
+ .handler = {
+ [mu_auth_getpwnam] = mu_auth_virt_domain_by_name,
+ }
};

Return to:

Send suggestions and report system problems to the System administrator.