Commit dc78d43f dc78d43ff77a65e3400af0401142aca2ebb6cd1e by Sergey Poznyakoff

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.
1 parent d1339b3f
Showing 99 changed files with 573 additions and 3479 deletions
......@@ -97,8 +97,6 @@ SUBDIRS = . \
libmu_compat\
testsuite\
lib\
libmu_argp\
libmu_cfg\
$(LIBMU_CPP_DIR)\
$(GINT_DIR)\
$(LIBMU_SCM_DIR)\
......
......@@ -1480,9 +1480,7 @@ AC_CONFIG_FILES([
include/mailutils/cpp/Makefile
lib/Makefile
lib/gnu/Makefile
libmu_argp/Makefile
libmu_auth/Makefile
libmu_cfg/Makefile
libmu_cpp/Makefile
libmu_scm/Makefile
libmu_scm/mailutils/Makefile
......
......@@ -181,7 +181,6 @@ static char *frm_argp_capa[] = {
"debug",
"mailbox",
"locking",
"tls",
NULL
};
......@@ -328,7 +327,7 @@ main (int argc, char **argv)
/* register the formats. */
mu_register_all_mbox_formats ();
mu_cli_capa_register (&mu_cli_capa_tls);
mu_auth_register_module (&mu_auth_tls_module);
mu_cli (argc, argv, &cli, frm_argp_capa, NULL, &argc, &argv);
if (align && (s = util_getcols ()))
......
......@@ -63,6 +63,7 @@
#include <mailutils/error.h>
#include <mailutils/util.h>
#include <mailutils/mime.h>
#include <mailutils/mu_auth.h>
#include "mailutils/cli.h"
......
......@@ -48,7 +48,6 @@ static char *capa[] = {
"debug",
"mailbox",
"locking",
"tls",
NULL
};
......@@ -89,7 +88,7 @@ main (int argc, char **argv)
/* register the formats. */
mu_register_all_mbox_formats ();
mu_cli_capa_register (&mu_cli_capa_tls);
mu_auth_register_module (&mu_auth_tls_module);
mu_cli (argc, argv, &cli, capa, NULL, &argc, &argv);
if (argc > 1)
......
......@@ -72,7 +72,7 @@ imap4d_SOURCES = \
util.c
imap4d_LDADD = \
${MU_APP_LIBRARIES}\
${MU_APP_NEW_LIBRARIES}\
${MU_LIB_MBOX}\
${MU_LIB_MH}\
${MU_LIB_MAILDIR}\
......
......@@ -17,7 +17,7 @@
#include "imap4d.h"
#include <mailutils/gsasl.h>
#include "mailutils/libargp.h"
#include "mailutils/cli.h"
#include "mailutils/kwd.h"
#include "tcpwrap.h"
......@@ -56,92 +56,78 @@ int ident_encrypt_only;
int test_mode;
const char *program_version = "imap4d (" PACKAGE_STRING ")";
static char doc[] = N_("GNU imap4d -- the IMAP4D daemon.");
#define OPT_PREAUTH 259
#define OPT_FOREGROUND 260
#define OPT_TEST_MODE 261
static struct argp_option options[] = {
{ "foreground", OPT_FOREGROUND, 0, 0, N_("remain in foreground"), 0},
{ "inetd", 'i', 0, 0, N_("run in inetd mode"), 0},
{ "daemon", 'd', N_("NUMBER"), OPTION_ARG_OPTIONAL,
N_("runs in daemon mode with a maximum of NUMBER children"), 0 },
{ "test", OPT_TEST_MODE, 0, 0,
N_("run in test mode"), 0 },
{ "preauth", OPT_PREAUTH, NULL, 0,
N_("start in preauth mode") },
{NULL, 0, NULL, 0, NULL, 0}
};
static error_t imap4d_parse_opt (int key, char *arg,
struct argp_state *state);
static struct argp argp = {
options,
imap4d_parse_opt,
NULL,
doc,
NULL,
NULL, NULL
};
static const char *imap4d_capa[] = {
"mailutils",
"auth",
"common",
"debug",
"mailbox",
"locking",
"logging",
NULL
};
static void
set_foreground (struct mu_parseopt *po, struct mu_option *opt,
char const *arg)
{
mu_m_server_set_foreground (server, 1);
}
static error_t
imap4d_parse_opt (int key, char *arg, struct argp_state *state)
static void
set_inetd_mode (struct mu_parseopt *po, struct mu_option *opt,
char const *arg)
{
static mu_list_t lst;
mu_m_server_set_mode (server, MODE_INTERACTIVE);
}
switch (key)
{
case 'd':
mu_argp_node_list_new (lst, "mode", "daemon");
static void
set_daemon_mode (struct mu_parseopt *po, struct mu_option *opt,
char const *arg)
{
mu_m_server_set_mode (server, MODE_DAEMON);
if (arg)
mu_argp_node_list_new (lst, "max-children", arg);
break;
{
size_t max_children;
char *errmsg;
int rc = mu_str_to_c (arg, mu_c_size, &max_children, &errmsg);
if (rc)
{
mu_parseopt_error (po, _("%s: bad argument"), arg);
exit (po->po_exit_error);
}
mu_m_server_set_max_children (server, max_children);
}
}
case 'i':
mu_argp_node_list_new (lst, "mode", "inetd");
break;
static void
set_preauth (struct mu_parseopt *po, struct mu_option *opt, char const *arg)
{
preauth_mode = preauth_stdio;
}
case OPT_FOREGROUND:
mu_argp_node_list_new (lst, "foreground", "yes");
break;
static struct mu_option imap4d_options[] = {
{ "foreground", 0, NULL, MU_OPTION_DEFAULT,
N_("remain in foreground"),
mu_c_bool, NULL, set_foreground },
{ "inetd", 'i', NULL, MU_OPTION_DEFAULT,
N_("run in inetd mode"),
mu_c_bool, NULL, set_inetd_mode },
{ "daemon", 'd', N_("NUMBER"), MU_OPTION_ARG_OPTIONAL,
N_("runs in daemon mode with a maximum of NUMBER children"),
mu_c_string, NULL, set_daemon_mode },
case OPT_PREAUTH:
preauth_mode = preauth_stdio;
break;
{ "test", 0, NULL, MU_OPTION_DEFAULT,
N_("run in test mode"),
mu_c_bool, &test_mode },
case OPT_TEST_MODE:
mu_argp_node_list_new (lst, "mode", "inetd");
test_mode = 1;
break;
{ "preauth", 0, NULL, MU_OPTION_DEFAULT,
N_("start in preauth mode"),
mu_c_string, NULL, set_preauth },
case ARGP_KEY_INIT:
mu_argp_node_list_init (&lst);
break;
MU_OPTION_END
}, *options[] = { imap4d_options, NULL };
case ARGP_KEY_FINI:
mu_argp_node_list_finish (lst, NULL, NULL);
break;
default:
return ARGP_ERR_UNKNOWN;
}
return 0;
}
static char *capa[] = {
"auth",
"debug",
"mailbox",
"locking",
"logging",
NULL
};
static int
cb_mode (void *data, mu_config_value_t *val)
......@@ -455,6 +441,12 @@ static struct mu_cfg_param imap4d_cfg_param[] = {
{ NULL }
};
struct mu_cli_setup cli = {
options,
imap4d_cfg_param,
N_("GNU imap4d -- the IMAP4D daemon.")
};
int
mu_get_user_groups (const char *user, mu_list_t retain, mu_list_t *pgrouplist)
{
......@@ -933,18 +925,10 @@ main (int argc, char **argv)
mu_register_local_mbox_formats ();
imap4d_capability_init ();
#ifdef WITH_TLS
mu_gocs_register ("tls", mu_tls_module_init);
#endif /* WITH_TLS */
#ifdef WITH_GSASL
mu_gocs_register ("gsasl", mu_gsasl_module_init);
#endif
mu_tcpwrapper_cfg_init ();
manlock_cfg_init ();
mu_acl_cfg_init ();
mu_argp_init (NULL, NULL);
mu_m_server_create (&server, program_version);
mu_m_server_set_config_size (server, sizeof (struct imap4d_srv_config));
mu_m_server_set_conn (server, imap4d_connection);
......@@ -961,9 +945,15 @@ main (int argc, char **argv)
mu_log_syslog = 1;
if (mu_app_init (&argp, imap4d_capa, imap4d_cfg_param,
argc, argv, 0, NULL, server))
exit (EX_CONFIG); /* FIXME: No way to discern from EX_USAGE? */
mu_cli (argc, argv, &cli, capa, server, &argc, &argv);
if (argc)
{
mu_error (_("too many arguments"));
exit (EX_USAGE);
}
if (test_mode)
mu_m_server_set_mode (server, MODE_INTERACTIVE);
if (login_disabled)
imap4d_capability_add (IMAP_CAPA_LOGINDISABLED);
......
......@@ -106,6 +106,7 @@
#include <mailutils/imapio.h>
#include <mailutils/imaputil.h>
#include <mailutils/msgset.h>
#include <mailutils/syslog.h>
#include <mu_umaxtostr.h>
#include <muaux.h>
......
......@@ -48,7 +48,6 @@ pkginclude_HEADERS = \
error.h\
filter.h\
folder.h\
gocs.h\
gsasl.h\
guile.h\
header.h\
......@@ -59,8 +58,6 @@ pkginclude_HEADERS = \
iterator.h\
kwd.h\
ldap.h\
libargp.h\
libcfg.h\
list.h\
locker.h\
log.h\
......
......@@ -35,7 +35,8 @@ struct mu_cli_capa
void mu_cli_capa_init (void);
void mu_cli_capa_register (struct mu_cli_capa *capa);
void mu_cli_capa_apply (char const *name, mu_list_t opts, mu_list_t commits);
void mu_cli_capa_extend_settings (char const *name, mu_list_t opts,
mu_list_t commits);
struct mu_cli_setup
{
......@@ -49,6 +50,8 @@ struct mu_cli_setup
int ex_usage; /* If not 0, exit code on usage errors */
int ex_config; /* If not 0, exit code on configuration
errors */
int inorder;
void (*prog_doc_hook) (mu_stream_t);
};
void mu_version_func (struct mu_parseopt *po, mu_stream_t stream);
......
......@@ -20,7 +20,6 @@
#define _MAILUTILS_DAEMON_H
#include <mailutils/types.h>
#include <mailutils/gocs.h>
#ifdef __cplusplus
extern "C" {
......@@ -33,8 +32,6 @@ extern "C" {
extern int mu_daemon_create_pidfile (const char *);
extern void mu_daemon_remove_pidfile (void);
extern struct mu_gocs_daemon mu_gocs_daemon;
#ifdef __cplusplus
}
#endif
......
/* GNU Mailutils -- a suite of utilities for electronic mail
Copyright (C) 2007-2008, 2010-2012, 2014-2016 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
License as published by the Free Software Foundation; either
version 3 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General
Public License along with this library. If not, see
<http://www.gnu.org/licenses/>. */
#ifndef _MAILUTILS_GOCS_H
#define _MAILUTILS_GOCS_H
#include <mailutils/types.h>
#include <mailutils/list.h>
#include <mailutils/syslog.h>
#ifdef __cplusplus
extern "C" {
#endif
struct mu_gocs_debug
{
char *string;
int line_info;
};
struct mu_gocs_mailbox
{
char *mail_spool;
char *mailbox_pattern;
char *mailbox_type;
};
struct mu_gocs_locking
{
char *lock_flags;
unsigned long lock_retry_timeout;
unsigned long lock_retry_count;
unsigned long lock_expire_timeout;
char *external_locker;
};
struct mu_gocs_source_email
{
char *address;
char *domain;
};
struct mu_gocs_mailer
{
char *mailer;
};
struct mu_gocs_pam
{
char *service;
};
struct mu_gocs_virtual
{
char *pwddir;
};
/* Auxiliary variables for use by libargp/libcfg */
extern char *mu_site_rcfile;
extern int mu_load_user_rcfile;
extern int mu_load_site_rcfile;
extern char *mu_load_rcfile;
typedef int (*mu_gocs_init_fp) (enum mu_gocs_op op, void *data);
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 (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
}
#endif
#endif
......@@ -18,6 +18,7 @@
#ifndef _MAILUTILS_GSASL_H
#define _MAILUTILS_GSASL_H
#include <mailutils/cli.h>
struct mu_gsasl_module_data
{
......@@ -28,16 +29,13 @@ struct mu_gsasl_module_data
char *anon_user;
char *cram_md5_pwd;
};
extern struct mu_gsasl_module_data mu_gsasl_module_data;
int mu_gsasl_enabled (void);
#ifdef WITH_GSASL
#include <gsasl.h>
int mu_gsasl_module_init (enum mu_gocs_op, void *);
extern struct mu_gsasl_module_data mu_gsasl_module_data;
int gsasl_encoder_stream (mu_stream_t *pstr, mu_stream_t transport,
Gsasl_session *ctx, int flags);
int gsasl_decoder_stream (mu_stream_t *pstr, mu_stream_t transport,
......
/* GNU Mailutils -- a suite of utilities for electronic mail
Copyright (C) 1999-2001, 2004-2005, 2007-2008, 2010-2012, 2014-2016
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
License as published by the Free Software Foundation; either
version 3 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General
Public License along with this library. If not, see
<http://www.gnu.org/licenses/>. */
#ifndef _MAILUTILS_LIBARGP_H
#define _MAILUTILS_LIBARGP_H
#include "mailutils/types.h"
#include "mailutils/gocs.h"
#include "mailutils/nls.h"
#include "mailutils/error.h"
#include "mailutils/errno.h"
#include "mailutils/version.h"
#include "argp.h"
#include "errno.h"
#include "strings.h"
#include "mailutils/libcfg.h"
#ifdef __cplusplus
extern "C" {
#endif
struct mu_cmdline_capa
{
char *name;
struct argp_child *child;
void (*modflags) (int *);
};
extern int mu_help_config_mode;
extern int mu_rcfile_lint;
extern int (*mu_app_cfg_verifier) (void);
extern struct mu_cmdline_capa mu_mailutils_cmdline;
extern struct mu_cmdline_capa mu_common_cmdline;
extern struct mu_cmdline_capa mu_logging_cmdline;
extern struct mu_cmdline_capa mu_mailbox_cmdline;
extern struct mu_cmdline_capa mu_locking_cmdline;
extern struct mu_cmdline_capa mu_address_cmdline;
extern struct mu_cmdline_capa mu_mailer_cmdline;
extern struct mu_cmdline_capa mu_sieve_cmdline;
extern struct mu_cmdline_capa mu_debug_cmdline;
extern struct mu_cmdline_capa mu_pam_cmdline;
extern struct mu_cmdline_capa mu_gsasl_cmdline;
extern struct mu_cmdline_capa mu_radius_cmdline;
extern struct mu_cmdline_capa mu_sql_cmdline;
extern struct mu_cmdline_capa mu_virtdomain_cmdline;
extern void mu_libargp_init (void);
extern struct argp *mu_argp_build (const struct argp *argp, char ***pcapa,
int *flags);
extern void mu_argp_done (struct argp *argp);
extern int mu_register_argp_capa (const char *name, struct argp_child *child,
void (*modflags) (int*));
void mu_argp_init (const char *vers, const char *bugaddr);
int mu_app_init (struct argp *myargp, const char **capa,
struct mu_cfg_param *cfg_param,
int argc, char **argv, int flags, int *pindex, void *data);
extern void mu_program_version_hook (FILE *stream, struct argp_state *state);
error_t mu_argp_parse (const struct argp *myargp,
int *pargc, char **pargv[],
unsigned flags,
const char *capa[],
int *arg_index,
void *input) MU_DEPRECATED;
void mu_argp_node_list_init (mu_list_t *);
void mu_argp_node_list_add (mu_list_t, mu_cfg_node_t *);
void mu_argp_node_list_new (mu_list_t, const char *, const char *);
void mu_argp_node_list_finish (mu_list_t, char *, char *);
#ifdef __cplusplus
}
#endif
#endif
/* GNU Mailutils -- a suite of utilities for electronic mail
Copyright (C) 2007-2012, 2014-2016 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
License as published by the Free Software Foundation; either
version 3 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General
Public License along with this library. If not, see
<http://www.gnu.org/licenses/>. */
#ifndef _MAILUTILS_LIBCFG_H
#define _MAILUTILS_LIBCFG_H
#include <mailutils/cfg.h>
#include <mailutils/gocs.h>
#include <mailutils/nls.h>
#include <mailutils/error.h>
#include <mailutils/errno.h>
#ifndef MU_USER_CONFIG_FILE
# define MU_USER_CONFIG_FILE "~/.mailutils"
#endif
#ifdef __cplusplus
extern "C" {
#endif
struct mu_cfg_capa
{
char *name;
struct mu_cfg_param *cfgparam;
mu_cfg_section_fp parser;
};
extern int mu_libcfg_register_capa (struct mu_cfg_capa *capa);
extern void mu_libcfg_init (char **cnames);
extern int mu_parse_config_files (struct mu_cfg_param *param,
void *target_ptr) MU_CFG_DEPRECATED;
int mu_libcfg_parse_config (mu_cfg_tree_t **ptree);
extern void mu_acl_cfg_init (void);
#define __mu_common_cat2__(a,b) a ## b
#define __mu_common_cat3__(a,b,c) a ## b ## c
#define DCL_PARSER(capa) \
int \
__mu_common_cat3__(mu_,capa,_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: \
break; \
\
case mu_cfg_section_end: \
mu_gocs_store (#capa, &__mu_common_cat2__(capa, _settings)); \
} \
return 0; \
}
#define DCL_DEFAULT_CFG_CAPA(capa) \
struct mu_cfg_capa __mu_common_cat3__(mu_,capa,_cfg_capa) = { \
#capa, \
__mu_common_cat3__(mu_,capa,_param), \
__mu_common_cat3__(mu_,capa,_section_parser) \
}
#define DCL_CFG_CAPA(capa) \
DCL_PARSER (capa) \
DCL_DEFAULT_CFG_CAPA (capa)
extern struct mu_cfg_capa mu_mailbox_cfg_capa;
extern struct mu_cfg_capa mu_locking_cfg_capa;
extern struct mu_cfg_capa mu_address_cfg_capa;
extern struct mu_cfg_capa mu_mailer_cfg_capa;
extern struct mu_cfg_capa mu_logging_cfg_capa;
extern struct mu_cfg_capa mu_debug_cfg_capa;
extern struct mu_cfg_capa mu_gsasl_cfg_capa;
extern struct mu_cfg_capa mu_pam_cfg_capa;
extern struct mu_cfg_capa mu_radius_cfg_capa;
extern struct mu_cfg_capa mu_sql_cfg_capa;
extern struct mu_cfg_capa mu_tls_cfg_capa;
extern struct mu_cfg_capa mu_virtdomain_cfg_capa;
extern struct mu_cfg_capa mu_sieve_cfg_capa;
extern struct mu_cfg_capa mu_auth_cfg_capa;
extern struct mu_cfg_capa mu_ldap_cfg_capa;
#ifdef __cplusplus
}
#endif
#endif
......@@ -58,7 +58,6 @@
#include <mailutils/stream.h>
#include <mailutils/tls.h>
#include <mailutils/url.h>
#include <mailutils/gocs.h>
#include <mailutils/version.h>
#include <mailutils/io.h>
#include <mailutils/secret.h>
......@@ -66,6 +65,7 @@
#include <mailutils/cstr.h>
#include <mailutils/wordsplit.h>
#include <mailutils/log.h>
#include <mailutils/syslog.h>
#include <mailutils/stdstream.h>
#include <mailutils/prog.h>
#include <mailutils/sockaddr.h>
......
......@@ -20,8 +20,8 @@
#define _MAILUTILS_MU_AUTH_H
#include <mailutils/types.h>
#include <mailutils/gocs.h>
#include <mailutils/debug.h>
#include <mailutils/cli.h>
#define MU_AUTH_NAME "name"
#define MU_AUTH_PASSWD "passwd"
......@@ -64,30 +64,41 @@ typedef int (*mu_auth_fp) (struct mu_auth_data **data,
void *func_data,
void *call_data);
enum mu_auth_mode
{
mu_auth_authenticate,
mu_auth_getpwnam,
mu_auth_getpwuid
};
#define MU_AUTH_MODE_COUNT 3
struct mu_auth_module
{
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;
mu_auth_fp handler[MU_AUTH_MODE_COUNT];
void *data[MU_AUTH_MODE_COUNT];
struct mu_option *opt;
struct mu_cfg_param *cfg;
mu_cfg_section_fp parser;
mu_cli_capa_commit_fp commit;
};
enum mu_auth_key_type
{
mu_auth_key_name,
mu_auth_key_uid
mu_auth_key_name = mu_auth_getpwnam,
mu_auth_key_uid = mu_auth_getpwuid
};
void mu_auth_begin_setup (void);
void mu_auth_finish_setup (void);
void mu_auth_extend_settings (mu_list_t opts, mu_list_t commits);
extern int mu_auth_runlist (mu_list_t flist,
struct mu_auth_data **return_data,
const void *key, void *data);
int mu_auth_runlist (mu_list_t flist,
enum mu_auth_mode mode,
const void *key, void *data,
struct mu_auth_data **return_data);
extern int mu_get_auth (struct mu_auth_data **auth, enum mu_auth_key_type type,
const void *key);
......@@ -116,7 +127,6 @@ extern void mu_authentication_add_module_list (const char *modlist);
extern void mu_authentication_clear_list (void);
extern void mu_authorization_clear_list (void);
extern void mu_auth_init (void);
extern int mu_auth_data_alloc (struct mu_auth_data **ptr,
const char *name,
const char *passwd,
......@@ -138,6 +148,8 @@ extern struct mu_auth_module mu_auth_sql_module;
extern struct mu_auth_module mu_auth_virtual_module;
extern struct mu_auth_module mu_auth_radius_module;
extern struct mu_auth_module mu_auth_ldap_module;
extern struct mu_auth_module mu_auth_gsasl_module;
extern struct mu_auth_module mu_auth_tls_module;
#define MU_AUTH_REGISTER_ALL_MODULES() do {\
mu_auth_register_module (&mu_auth_generic_module); \
......@@ -147,6 +159,8 @@ extern struct mu_auth_module mu_auth_ldap_module;
mu_auth_register_module (&mu_auth_virtual_module);\
mu_auth_register_module (&mu_auth_radius_module);\
mu_auth_register_module (&mu_auth_ldap_module);\
mu_auth_register_module (&mu_auth_gsasl_module);\
mu_auth_register_module (&mu_auth_tls_module);\
} while (0)
#endif
......
......@@ -102,6 +102,7 @@ struct mu_option_cache
#define MU_PARSEOPT_HELP_HOOK 0x00200000
#define MU_PARSEOPT_DATA 0x00400000
#define MU_PARSEOPT_VERSION_HOOK 0x00800000
#define MU_PARSEOPT_PROG_DOC_HOOK 0x01000000
/* Reuse mu_parseopt struct initialized previously */
#define MU_PARSEOPT_REUSE 0x80000000
......@@ -131,6 +132,7 @@ struct mu_parseopt
char const *po_package_url;
char const *po_extra_info;
void (*po_prog_doc_hook) (struct mu_parseopt *po, mu_stream_t stream);
void (*po_help_hook) (struct mu_parseopt *po, mu_stream_t stream);
void (*po_version_hook) (struct mu_parseopt *po, mu_stream_t stream);
......
......@@ -28,6 +28,4 @@ struct mu_radius_module_data
char *getpwuid_request;
};
extern int mu_radius_module_init (enum mu_gocs_op, void *data);
#endif
......
......@@ -272,17 +272,6 @@ int mu_sieve_disass (mu_sieve_machine_t mach);
#define MU_SIEVE_CLEAR_INCLUDE_PATH 0x1
#define MU_SIEVE_CLEAR_LIBRARY_PATH 0x2
struct mu_gocs_sieve
{
int clearflags;
/* mu_list_t include_path_prefix;*/
mu_list_t include_path;
mu_list_t library_path_prefix;
mu_list_t library_path;
};
int mu_sieve_module_init (enum mu_gocs_op, void *);
extern struct mu_cli_capa mu_cli_capa_sieve;
#ifdef __cplusplus
......
......@@ -29,24 +29,6 @@ enum mu_password_type
struct mu_sql_module_config
{
char *interface;
char *getpwnam_query;
char *getpass_query;
char *getpwuid_query;
char *host;
char *user;
char *passwd;
char *db;
int port;
enum mu_password_type password_type;
int positional;
mu_assoc_t field_map;
};
/* FIXME: Should not be here, but needed for several other sources
(imap4d/auth_gsasl.c, for instance) */
struct mu_internal_sql_config
{
int interface;
char *getpwnam_query;
char *getpass_query;
......@@ -61,7 +43,7 @@ struct mu_internal_sql_config
mu_assoc_t field_map;
};
extern struct mu_internal_sql_config mu_sql_module_config;
extern struct mu_sql_module_config mu_sql_module_config;
/* Loadable Modules Support */
#define __s_cat2__(a,b) a ## b
......@@ -131,7 +113,7 @@ struct mu_sql_dispatch
};
/* Public interfaces */
int mu_sql_interface_index (char *name);
int mu_sql_interface_index (char const *name);
int mu_sql_connection_init (mu_sql_connection_t *conn, int interface,
char *server, int port, char *login,
......
......@@ -42,8 +42,6 @@ struct mu_tls_module_config
char *priorities;
};
extern int mu_tls_module_init (enum mu_gocs_op, void *);
extern int mu_tls_server_stream_create (mu_stream_t *stream,
mu_stream_t strin, mu_stream_t strout,
int flags);
......
......@@ -151,12 +151,6 @@ struct mu_locus
unsigned mu_col;
};
enum mu_gocs_op
{
mu_gocs_op_set,
mu_gocs_op_flush
};
#ifdef __cplusplus
}
#endif
......
/* GNU Mailutils -- a suite of utilities for electronic mail
Copyright (C) 2007, 2009-2012, 2014-2016 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
License as published by the Free Software Foundation; either
version 3 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General
Public License along with this library. If not, see
<http://www.gnu.org/licenses/>. */
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
#include <unistd.h>
#include <string.h>
char *
__argp_base_name (const char *arg)
{
char *p = strrchr (arg, '/');
return (char *)(p ? p + 1 : arg);
}
......@@ -161,23 +161,19 @@ mu_auth_data_destroy (struct mu_auth_data **pptr)
/* Generic functions */
struct auth_stack_entry {
char *name; /* for diagnostics purposes */
mu_auth_fp fun;
void *func_data;
};
void
mu_insert_stack_entry (mu_list_t *pflist, struct auth_stack_entry *entry)
static void
append_auth_module (mu_list_t *pflist, struct mu_auth_module *mod)
{
if (!*pflist && mu_list_create (pflist))
return;
mu_list_append (*pflist, entry);
mu_list_append (*pflist, mod);
}
int
mu_auth_runlist (mu_list_t flist, struct mu_auth_data **return_data,
const void *key, void *data)
mu_auth_runlist (mu_list_t flist,
enum mu_auth_mode mode,
const void *key, void *data,
struct mu_auth_data **return_data)
{
int status = MU_ERR_AUTH_FAILURE;
int rc;
......@@ -185,15 +181,17 @@ mu_auth_runlist (mu_list_t flist, struct mu_auth_data **return_data,
if (mu_list_get_iterator (flist, &itr) == 0)
{
struct auth_stack_entry *ep;
struct mu_auth_module *ep;
for (mu_iterator_first (itr); !mu_iterator_is_done (itr);
mu_iterator_next (itr))
{
mu_iterator_current (itr, (void **)&ep);
if (!ep->handler[mode])
continue;
mu_debug (MU_DEBCAT_AUTH, MU_DEBUG_TRACE2,
("Trying %s...", ep->name));
rc = ep->fun (return_data, key, ep->func_data, data);
rc = ep->handler[mode] (return_data, key, ep->data[mode], data);
mu_debug (MU_DEBCAT_AUTH, MU_DEBUG_TRACE2,
("%s yields %d=%s", ep->name, rc, mu_strerror (rc)));
if (rc == 0)
......@@ -230,30 +228,25 @@ mu_auth_nosupport (struct mu_auth_data **return_data MU_ARG_UNUSED,
/* II. Authorization: retrieving information about user */
static mu_list_t mu_auth_by_name_list, _tmp_auth_by_name_list;
static mu_list_t mu_auth_by_uid_list, _tmp_auth_by_uid_list;
static mu_list_t mu_getpw_modules, selected_getpw_modules;
int
mu_get_auth (struct mu_auth_data **auth, enum mu_auth_key_type type,
const void *key)
{
mu_list_t list;
if (!mu_auth_by_name_list)
if (!mu_getpw_modules)
mu_auth_begin_setup ();
switch (type)
{
case mu_auth_key_name:
mu_debug (MU_DEBCAT_AUTH, MU_DEBUG_TRACE1,
("Getting auth info for user %s", (char*) key));
list = mu_auth_by_name_list;
break;
case mu_auth_key_uid:
mu_debug (MU_DEBCAT_AUTH, MU_DEBUG_TRACE1,
("Getting auth info for UID %lu",
(unsigned long) *(uid_t*) key));
list = mu_auth_by_uid_list;
break;
default:
......@@ -261,7 +254,7 @@ mu_get_auth (struct mu_auth_data **auth, enum mu_auth_key_type type,
("Unknown mu_auth_key_type: %d", type));
return EINVAL;
}
return mu_auth_runlist (list, auth, key, NULL);
return mu_auth_runlist (mu_getpw_modules, type, key, NULL, auth);
}
struct mu_auth_data *
......@@ -282,7 +275,7 @@ mu_get_auth_by_uid (uid_t uid)
/* III. Authentication: determining the authenticity of a user */
static mu_list_t mu_authenticate_list, _tmp_authenticate_list;
static mu_list_t mu_auth_modules, selected_auth_modules;
int
mu_authenticate (struct mu_auth_data *auth_data, const char *pass)
......@@ -292,68 +285,52 @@ mu_authenticate (struct mu_auth_data *auth_data, const char *pass)
mu_debug (MU_DEBCAT_AUTH, MU_DEBUG_TRACE1,
("mu_authenticate, user %s, source %s",
auth_data->name, auth_data->source));
if (!mu_authenticate_list)
if (!mu_auth_modules)
mu_auth_begin_setup ();
return mu_auth_runlist (mu_authenticate_list, NULL, auth_data, (void*) pass);
return mu_auth_runlist (mu_auth_modules,
mu_auth_authenticate,
auth_data, pass, NULL);
}
/* ************************************************************************* */
struct _module_handler {
struct auth_stack_entry authenticate;
struct auth_stack_entry auth_by_name;
struct auth_stack_entry auth_by_uid;
};
static mu_list_t module_handler_list;
static mu_list_t module_list;
void
mu_auth_register_module (struct mu_auth_module *mod)
static void
module_list_init (void)
{
struct _module_handler *entry;
if (mod->init)
mu_gocs_register (mod->name, mod->init);
if (!module_handler_list && mu_list_create (&module_handler_list))
abort ();
entry = malloc (sizeof (*entry));
if (!entry)
if (!module_list)
{
mu_error ("not enough memory");
exit (1);
if (mu_list_create (&module_list))
abort ();
mu_list_append (module_list, &mu_auth_generic_module);
mu_list_append (module_list, &mu_auth_system_module);
}
entry->authenticate.name = mod->name;
entry->authenticate.fun = mod->authenticate;
entry->authenticate.func_data = mod->authenticate_data;
entry->auth_by_name.name = mod->name;
entry->auth_by_name.fun = mod->auth_by_name;
entry->auth_by_name.func_data = mod->auth_by_name_data;
entry->auth_by_uid.name = mod->name;
entry->auth_by_uid.fun = mod->auth_by_uid;
entry->auth_by_uid.func_data = mod->auth_by_uid_data;
mu_list_append (module_handler_list, entry);
}
void
mu_auth_register_module (struct mu_auth_module *mod)
{
module_list_init ();
mu_list_append (module_list, mod);
}
static struct _module_handler *
static struct mu_auth_module *
_locate (const char *name)
{
struct _module_handler *rp = NULL;
struct mu_auth_module *rp = NULL;
mu_iterator_t itr;
if (mu_list_get_iterator (module_handler_list, &itr) == 0)
if (mu_list_get_iterator (module_list, &itr) == 0)
{
struct _module_handler *p;
struct mu_auth_module *p;
for (mu_iterator_first (itr); !rp && !mu_iterator_is_done (itr);
mu_iterator_next (itr))
{
mu_iterator_current (itr, (void **)&p);
if (strcmp (p->authenticate.name, name) == 0)
if (strcmp (p->name, name) == 0)
rp = p;
}
......@@ -397,15 +374,14 @@ _add_module_list (const char *modlist, int (*fun)(const char *name))
int
mu_authorization_add_module (const char *name)
{
struct _module_handler *mod = _locate (name);
struct mu_auth_module *mod = _locate (name);
if (!mod)
{
errno = MU_ERR_NOENT;
return 1;
}
mu_insert_stack_entry (&_tmp_auth_by_name_list, &mod->auth_by_name);
mu_insert_stack_entry (&_tmp_auth_by_uid_list, &mod->auth_by_uid);
append_auth_module (&selected_getpw_modules, mod);
return 0;
}
......@@ -418,22 +394,21 @@ mu_authorization_add_module_list (const char *modlist)
void
mu_authorization_clear_list ()
{
mu_list_destroy (&_tmp_auth_by_name_list);
mu_list_destroy (&_tmp_auth_by_uid_list);
mu_list_destroy (&selected_getpw_modules);
}
int
mu_authentication_add_module (const char *name)
{
struct _module_handler *mod = _locate (name);
struct mu_auth_module *mod = _locate (name);
if (!mod)
{
errno = MU_ERR_NOENT;
return 1;
}
mu_insert_stack_entry (&_tmp_authenticate_list, &mod->authenticate);
append_auth_module (&selected_auth_modules, mod);
return 0;
}
......@@ -446,7 +421,7 @@ mu_authentication_add_module_list (const char *modlist)
void
mu_authentication_clear_list ()
{
mu_list_destroy (&_tmp_authenticate_list);
mu_list_destroy (&selected_auth_modules);
}
......@@ -462,45 +437,39 @@ mu_authentication_clear_list ()
argp_parse() exits. */
void
mu_auth_begin_setup ()
mu_auth_begin_setup (void)
{
mu_iterator_t itr;
if (!module_handler_list)
{
mu_auth_register_module (&mu_auth_generic_module);
mu_auth_register_module (&mu_auth_system_module);
}
module_list_init ();
if (!mu_authenticate_list)
if (!mu_auth_modules)
{
if (mu_list_get_iterator (module_handler_list, &itr) == 0)
if (mu_list_get_iterator (module_list, &itr) == 0)
{
struct _module_handler *mod;
struct mu_auth_module *mod;
for (mu_iterator_first (itr); !mu_iterator_is_done (itr);
mu_iterator_next (itr))
{
mu_iterator_current (itr, (void **)&mod);
mu_insert_stack_entry (&mu_authenticate_list,
&mod->authenticate);
append_auth_module (&mu_auth_modules, mod);
}
mu_iterator_destroy (&itr);
}
}
if (!mu_auth_by_name_list)
if (!mu_getpw_modules)
{
if (mu_list_get_iterator (module_handler_list, &itr) == 0)
if (mu_list_get_iterator (module_list, &itr) == 0)
{
struct _module_handler *mod;
struct mu_auth_module *mod;
for (mu_iterator_first (itr); !mu_iterator_is_done (itr);
mu_iterator_next (itr))
{
mu_iterator_current (itr, (void **)&mod);
mu_insert_stack_entry (&mu_auth_by_name_list, &mod->auth_by_name);
mu_insert_stack_entry (&mu_auth_by_uid_list, &mod->auth_by_uid);
append_auth_module (&mu_getpw_modules, mod);
}
mu_iterator_destroy (&itr);
}
......@@ -508,20 +477,48 @@ mu_auth_begin_setup ()
}
void
mu_auth_finish_setup ()
mu_auth_finish_setup (void)
{
mu_list_destroy (&mu_authenticate_list);
mu_list_destroy (&mu_auth_by_name_list);
mu_list_destroy (&mu_auth_by_uid_list);
mu_list_destroy (&mu_auth_modules);
mu_auth_modules = selected_auth_modules;
selected_auth_modules = NULL;
mu_authenticate_list = _tmp_authenticate_list;
_tmp_authenticate_list = NULL;
mu_auth_by_name_list = _tmp_auth_by_name_list;
_tmp_auth_by_name_list = NULL;
mu_auth_by_uid_list = _tmp_auth_by_uid_list;
_tmp_auth_by_uid_list = NULL;
mu_list_destroy (&mu_getpw_modules);
mu_getpw_modules = selected_getpw_modules;
selected_getpw_modules = NULL;
mu_auth_begin_setup ();
}
struct settings
{
mu_list_t opts;
mu_list_t commits;
};
static int
do_extend (void *item, void *data)
{
struct mu_auth_module *mod = item;
struct settings *set = data;
if (mod->opt)
mu_list_append (set->opts, mod->opt);
if (mod->commit)
mu_list_append (set->commits, mod->commit);
if (mod->parser || mod->cfg)
mu_config_root_register_section (NULL, mod->name, NULL,
mod->parser, mod->cfg);
return 0;
}
void
mu_auth_extend_settings (mu_list_t opts, mu_list_t commits)
{
struct settings s;
s.opts = opts;
s.commits = commits;
mu_list_foreach (module_list, do_extend, &s);
}
......
......@@ -141,25 +141,19 @@ mu_authenticate_system (struct mu_auth_data **return_data MU_ARG_UNUSED,
struct mu_auth_module mu_auth_system_module = {
"system",
NULL,
mu_authenticate_system,
NULL,
mu_auth_system_by_name,
NULL,
mu_auth_system_by_uid,
NULL
.name = "system",
.handler = {
[mu_auth_authenticate] = mu_authenticate_system,
[mu_auth_getpwnam] = mu_auth_system_by_name,
[mu_auth_getpwuid] = mu_auth_system_by_uid
}
};
struct mu_auth_module mu_auth_generic_module = {
"generic",
NULL,
mu_authenticate_generic,
NULL,
mu_auth_nosupport,
NULL,
mu_auth_nosupport,
NULL
.name = "generic",
.handler = {
[mu_auth_authenticate] = mu_authenticate_generic
}
};
......
......@@ -21,8 +21,7 @@ libcfg_la_SOURCES = \
driver.c\
format.c\
lexer.c\
parser.c\
gocs.c
parser.c
localedir = $(datadir)/locale
AM_CPPFLAGS = \
......
/* GNU Mailutils -- a suite of utilities for electronic mail
Copyright (C) 2007-2012, 2014-2016 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
License as published by the Free Software Foundation; either
version 3 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General
Public License along with this library. If not, see
<http://www.gnu.org/licenses/>. */
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
#include <stdlib.h>
#include <string.h>
#include <mailutils/types.h>
#include <mailutils/gocs.h>
#include <mailutils/mailbox.h>
#include <mailutils/locker.h>
#include <mailutils/util.h>
#include <mailutils/mailer.h>
#include <mailutils/error.h>
#include <mailutils/errno.h>
#include <mailutils/nls.h>
#include <mailutils/debug.h>
#include <mailutils/syslog.h>
#include <mailutils/registrar.h>
#include <mailutils/stdstream.h>
#include <mailutils/stream.h>
#include <mailutils/log.h>
#include <syslog.h>
#ifndef MU_CONFIG_FILE
# define MU_CONFIG_FILE SYSCONFDIR "/mailutils.rc"
#endif
char *mu_site_rcfile = MU_CONFIG_FILE;
int mu_load_user_rcfile = 1;
int mu_load_site_rcfile = 1;
char *mu_load_rcfile = NULL;
int
mu_gocs_dummy (enum mu_gocs_op op, void *data)
{
return 0;
}
int
mu_gocs_mailbox_init (enum mu_gocs_op op, void *data)
{
int rc;
struct mu_gocs_mailbox *p = data;
if (op == mu_gocs_op_set && p)
{
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 (enum mu_gocs_op op, void *data)
{
struct mu_gocs_locking *p = data;
if (!(op == mu_gocs_op_set && p))
return 0;
if (p->lock_flags)
{
int flags = 0;
char *s;
for (s = p->lock_flags; *s; s++)
{
switch (*s)
{
case 'E':
flags |= MU_LOCKER_EXTERNAL;
break;
case 'R':
flags |= MU_LOCKER_RETRY;
break;
case 'T':
flags |= MU_LOCKER_TIME;
break;
case 'P':
flags |= MU_LOCKER_PID;
break;
default:
mu_error (_("invalid lock flag `%c'"), *s);
}
}
mu_locker_set_default_flags (flags, mu_locker_assign);
free (p->lock_flags);
p->lock_flags = NULL;
}
if (p->lock_retry_count)
{
mu_locker_set_default_retry_count (p->lock_retry_count);
mu_locker_set_default_flags (MU_LOCKER_RETRY, mu_locker_set_bit);
p->lock_retry_count = 0;
}
if (p->lock_retry_timeout)
{
mu_locker_set_default_retry_timeout (p->lock_retry_timeout);
mu_locker_set_default_flags (MU_LOCKER_RETRY, mu_locker_set_bit);
p->lock_retry_timeout = 0;
}
if (p->lock_expire_timeout)
{
mu_locker_set_default_expire_timeout (p->lock_expire_timeout);
mu_locker_set_default_flags (MU_LOCKER_EXTERNAL, mu_locker_set_bit);
p->lock_expire_timeout = 0;
}
if (p->external_locker)
{
mu_locker_set_default_external_program (p->external_locker);
mu_locker_set_default_flags (MU_LOCKER_TIME, mu_locker_set_bit);
free (p->external_locker);
p->external_locker = NULL;
}
return 0;
}
int
mu_gocs_source_email_init (enum mu_gocs_op op, void *data)
{
struct mu_gocs_source_email *p = data;
int rc;
if (!(op == mu_gocs_op_set && p))
return 0;
if (p->address)
{
if ((rc = mu_set_user_email (p->address)) != 0)
mu_error (_("invalid email address `%s': %s"),
p->address, mu_strerror (rc));
free (p->address);
p->address = NULL;
}
if (p->domain)
{
if ((rc = mu_set_user_email_domain (p->domain)) != 0)
mu_error (_("invalid email domain `%s': %s"),
p->domain, mu_strerror (rc));
free (p->domain);
p->domain = NULL;
}
return 0;
}
int
mu_gocs_mailer_init (enum mu_gocs_op op, void *data)
{
struct mu_gocs_mailer *p = data;
int rc;
if (!(op == mu_gocs_op_set && p))
return 0;
if (p->mailer)
{
if ((rc = mu_mailer_set_url_default (p->mailer)) != 0)
mu_error (_("invalid mailer URL `%s': %s"),
p->mailer, mu_strerror (rc));
free (p->mailer);
p->mailer = NULL;
}
return 0;
}
int
mu_gocs_logging_init (enum mu_gocs_op op, void *data)
{
if (mu_log_syslog >= 0)
mu_stdstream_strerr_setup (mu_log_syslog ?
MU_STRERR_SYSLOG : MU_STRERR_STDERR);
return 0;
}
int
mu_gocs_debug_init (enum mu_gocs_op op, void *data)
{
if (op == mu_gocs_op_set && data)
{
struct mu_gocs_debug *p = data;
if (p->string)
mu_debug_parse_spec (p->string);
if (p->line_info >= 0)
mu_debug_line_info = p->line_info;
}
return 0;
}
struct mu_gocs_entry
{
const char *name;
mu_gocs_init_fp init;
};
#define MAX_GOCS 512
static struct mu_gocs_entry _gocs_table[MAX_GOCS];
void
mu_gocs_register (const char *capa, mu_gocs_init_fp init)
{
int i;
for (i = 0; _gocs_table[i].name; i++)
{
if (i == MAX_GOCS-1)
{
mu_error (_("gocs table overflow"));
abort ();
}
else if (strcmp (_gocs_table[i].name, capa) == 0)
return;
}
_gocs_table[i].name = capa;
_gocs_table[i].init = init;
}
int
mu_gocs_enumerate (mu_list_action_t action, void *data)
{
int i;
for (i = 0; _gocs_table[i].name; i++)
{
int rc = action ((void*) _gocs_table[i].name, data);
if (rc)
return rc;
}
return 0;
}
static mu_gocs_init_fp
find_init_function (struct mu_gocs_entry *tab, const char *capa)
{
for (; tab->name; tab++)
if (strcmp (tab->name, capa) == 0)
return tab->init;
return NULL;
}
static struct mu_gocs_entry std_gocs_table[] = {
{ "mailutils", mu_gocs_dummy },
{ "common", mu_gocs_dummy },
{ "mailbox", mu_gocs_mailbox_init },
{ "locking", mu_gocs_locking_init },
{ "address", mu_gocs_source_email_init },
{ "mailer", mu_gocs_mailer_init },
{ "logging", mu_gocs_logging_init },
{ "debug", mu_gocs_debug_init },
{ "auth", mu_gocs_dummy },
{ NULL }
};
void
mu_gocs_register_std (const char *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'"),
__FILE__, __LINE__, name);
abort ();
}
mu_gocs_register (name, init);
}
struct mu_gocs_data
{
char *capa;
void *data;
};
static mu_list_t /* of struct mu_gocs_data */ data_list;
static int
_gocs_comp (const void *a, const void *b)
{
const struct mu_gocs_data *da = a, *db = b;
return !(strcmp (da->capa, db->capa) == 0 && da->data == db->data);
}
void
mu_gocs_store (char *capa, void *data)
{
struct mu_gocs_data *s;
if (!data_list)
{
mu_list_create (&data_list);
mu_list_set_destroy_item (data_list, mu_list_free_item);
mu_list_set_comparator (data_list, _gocs_comp);
}
s = malloc (sizeof *s);
if (!s)
{
mu_error ("%s", mu_strerror (ENOMEM));
exit (1);
}
s->capa = capa;
s->data = data;
if (mu_list_locate (data_list, s, NULL) == 0)
free (s);
else
mu_list_prepend (data_list, s);
}
int
_gocs_flush (void *item, void *data)
{
struct mu_gocs_data *s = item;
mu_gocs_init_fp initfun = find_init_function (_gocs_table, s->capa);
if (!initfun)
{
mu_error (_("INTERNAL ERROR at %s:%d: unknown capability `%s'"),
__FILE__, __LINE__, s->capa);
abort ();
}
if (initfun (mu_gocs_op_set, s->data))
{
mu_error (_("initialization of GOCS `%s' failed"), s->capa);
return 1;
}
return 0;
}
void
mu_gocs_flush ()
{
int i;
mu_list_foreach (data_list, _gocs_flush, NULL);
for (i = 0; _gocs_table[i].name; i++)
_gocs_table[i].init (mu_gocs_op_flush, NULL);
}
......@@ -60,7 +60,7 @@ struct capa_apply
};
static int
capa_apply (void *item, void *data)
capa_extend (void *item, void *data)
{
struct mu_cli_capa *cp = item;
struct capa_apply *ap = data;
......@@ -80,14 +80,15 @@ capa_apply (void *item, void *data)
}
void
mu_cli_capa_apply (char const *name, mu_list_t opts, mu_list_t commits)
mu_cli_capa_extend_settings (char const *name, mu_list_t opts,
mu_list_t commits)
{
struct capa_apply app;
app.name = name;
app.opts = opts;
app.commits = commits;
app.found = 0;
mu_list_foreach (capa_list, capa_apply, &app);
mu_list_foreach (capa_list, capa_extend, &app);
if (!app.found)
mu_error (_("INTERNAL ERROR at %s:%d: unknown standard capability `%s'"),
__FILE__, __LINE__, name);
......
......@@ -31,6 +31,7 @@
#include <mailutils/stdstream.h>
#include <mailutils/io.h>
#include <mailutils/syslog.h>
#include <mailutils/mu_auth.h>
#ifndef MU_SITE_CONFIG_FILE
# define MU_SITE_CONFIG_FILE SYSCONFDIR "/mailutils.rc"
......@@ -87,6 +88,14 @@ extra_help_hook (struct mu_parseopt *po, mu_stream_t stream)
}
static void
prog_doc_hook (struct mu_parseopt *po, mu_stream_t stream)
{
struct mu_cfg_parse_hints *hints = po->po_data;
struct mu_cli_setup *setup = hints->data;
setup->prog_doc_hook (stream);
}
static void
change_progname (struct mu_parseopt *po, struct mu_option *opt,
char const *arg)
{
......@@ -283,6 +292,7 @@ init_options (char **capa, struct mu_cli_setup *setup,
{
size_t i, s;
mu_list_t oplist;
mu_list_t comlist;
struct mu_parseopt po;
mu_list_create (&oplist);
......@@ -291,16 +301,16 @@ init_options (char **capa, struct mu_cli_setup *setup,
for (i = 0; setup->optv[i]; i++)
mu_list_append (oplist, setup->optv[i]);
}
mu_list_create (&comlist);
mu_auth_extend_settings (oplist, comlist);
if (capa)
{
mu_list_t comlist;
mu_list_create (&comlist);
for (i = 0; capa[i]; i++)
mu_cli_capa_apply (capa[i], oplist, comlist);
*ret_comlist = comlist;
mu_cli_capa_extend_settings (capa[i], oplist, comlist);
}
else
*ret_comlist = NULL;
*ret_comlist = comlist;
mu_list_append (oplist, mu_common_options);
mu_list_append (oplist, mu_extra_help_options);
......@@ -346,6 +356,8 @@ mu_cli (int argc, char **argv, struct mu_cli_setup *setup, char **capa,
setup->ex_usage = EX_USAGE;
if (setup->ex_config == 0)
setup->ex_config = EX_CONFIG;
if (setup->inorder)
flags |= MU_PARSEOPT_IN_ORDER;
/* Set program name */
mu_set_program_name (argv[0]);
......@@ -370,6 +382,7 @@ mu_cli (int argc, char **argv, struct mu_cli_setup *setup, char **capa,
hints.data = setup;
/* Initialize po */
if (setup->prog_doc)
{
po.po_prog_doc = setup->prog_doc;
......@@ -424,6 +437,12 @@ mu_cli (int argc, char **argv, struct mu_cli_setup *setup, char **capa,
flags |= MU_PARSEOPT_HELP_HOOK;
}
if (setup->prog_doc_hook)
{
po.po_prog_doc_hook = prog_doc_hook;
flags |= MU_PARSEOPT_PROG_DOC_HOOK;
}
po.po_data = &hints;
flags |= MU_PARSEOPT_DATA;
......
......@@ -352,6 +352,12 @@ mu_program_help (struct mu_parseopt *po, mu_stream_t outstr)
}
mu_stream_printf (str, "\n");
if (po->po_prog_doc_hook)
{
po->po_prog_doc_hook (po, str);
mu_stream_printf (str, "\n");
}
mu_option_describe_options (str, po->po_optv, po->po_optc);
if (po->po_help_hook)
......
......@@ -213,6 +213,8 @@ find_long_option (struct mu_parseopt *po, char const *optstr,
case 0:
ind = i;
found++;
if (optlen == strlen (po->po_optv[i]->opt_long))
i = po->po_optc - 1; /* exact match: break the loop */
break;
case 1:
......@@ -511,6 +513,8 @@ parseopt_init (struct mu_parseopt *po, struct mu_option **options,
po->po_exit_error = EXIT_ERROR;
if (!(flags & MU_PARSEOPT_VERSION_HOOK))
po->po_version_hook = NULL;
if (!(flags & MU_PARSEOPT_PROG_DOC_HOOK))
po->po_prog_doc_hook = NULL;
/* Count the options */
po->po_optc = 0;
......
*.la
*.lo
.deps
.libs
Makefile
Makefile.in
.gdbinit
# This file is part of GNU Mailutils
# Copyright (C) 2007, 2009-2012, 2014-2016 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 the Free Software Foundation; either version 3, or (at
# your option) any later version.
#
# GNU Mailutils is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with GNU Mailutils. If not, see <http://www.gnu.org/licenses/>.
# This library uses gnulib calls and is always linked with gnulib, therefore
# we use application includes here.
AM_CPPFLAGS = \
@MU_APP_COMMON_INCLUDES@\
-DSYSCONFDIR=\"$(sysconfdir)\"\
-DSITE_VIRTUAL_PWDDIR=\"@SITE_VIRTUAL_PWDDIR@\"\
-DSITE_CRAM_MD5_PWD=\"@SITE_CRAM_MD5_PWD@\"
lib_LTLIBRARIES = libmu_argp.la
libmu_argp_la_SOURCES =\
cmdline.c\
cmdline.h\
common.c\
mailutils.c\
mu_argp.c\
muinit.c\
sieve.c
libmu_argp_la_LIBADD=../lib/libmuaux.la
libmu_argp_la_LDFLAGS=-version-info @VI_CURRENT@:@VI_REVISION@:@VI_AGE@
/* GNU Mailutils -- a suite of utilities for electronic mail
Copyright (C) 2007-2012, 2014-2016 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
License as published by the Free Software Foundation; either
version 3 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General
Public License along with this library. If not, see
<http://www.gnu.org/licenses/>. */
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
#include <stdlib.h>
#include "cmdline.h"
static struct mu_cmdline_capa *all_cmdline_capa[] = {
&mu_mailutils_cmdline,
&mu_common_cmdline,
&mu_logging_cmdline,
&mu_mailer_cmdline,
&mu_debug_cmdline,
&mu_sieve_cmdline,
NULL
};
static int libargp_init_passed = 0;
void
mu_libargp_init ()
{
struct mu_cmdline_capa **cpp;
if (libargp_init_passed)
return;
libargp_init_passed = 1;
for (cpp = all_cmdline_capa; *cpp; cpp++)
{
struct mu_cmdline_capa *cp = *cpp;
if (mu_register_argp_capa (cp->name, cp->child, cp->modflags))
{
mu_error (_("INTERNAL ERROR: cannot register argp capability `%s'"),
cp->name);
abort ();
}
}
}
void
mu_argp_node_list_init (mu_list_t *plist)
{
int rc = mu_cfg_create_node_list (plist);
if (rc)
{
mu_diag_funcall (MU_DIAG_ERROR, "mu_cfg_create_node_list", NULL, rc);
abort ();
}
}
void
mu_argp_node_list_add (mu_list_t lst, mu_cfg_node_t *node)
{
int rc = mu_list_append (lst, node);
if (rc)
{
mu_diag_funcall (MU_DIAG_ERROR, "mu_list_append", NULL, rc);
abort ();
}
}
void
mu_argp_node_list_new (mu_list_t lst, const char *tag, const char *label)
{
mu_cfg_node_t *node;
size_t n;
struct mu_locus loc = { "command line", 0 };
mu_list_count (lst, &n);
loc.mu_line = n;
node = mu_cfg_tree_create_node (mu_argp_tree, mu_cfg_node_param,
&loc, tag, label, NULL);
mu_argp_node_list_add (lst, node);
}
void
mu_argp_node_list_finish (mu_list_t lst, char *tag, char *label)
{
if (mu_list_is_empty (lst))
return;
if (tag)
{
mu_cfg_node_t *node = mu_cfg_tree_create_node (mu_argp_tree,
mu_cfg_node_statement,
NULL,
tag, label,
lst);
mu_cfg_tree_add_node (mu_argp_tree, node);
}
else
{
mu_cfg_tree_add_nodelist (mu_argp_tree, lst);
mu_list_destroy (&lst);
}
}
/* GNU Mailutils -- a suite of utilities for electronic mail
Copyright (C) 2007, 2010-2012, 2014-2016 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
License as published by the Free Software Foundation; either
version 3 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General
Public License along with this library. If not, see
<http://www.gnu.org/licenses/>. */
#include "mailutils/libcfg.h"
#include "mailutils/libargp.h"
extern struct mu_cfg_tree *mu_argp_tree;
/* GNU Mailutils -- a suite of utilities for electronic mail
Copyright (C) 2007-2012, 2014-2016 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
License as published by the Free Software Foundation; either
version 3 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General
Public License along with this library. If not, see
<http://www.gnu.org/licenses/>. */
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
#include "cmdline.h"
#include <unistd.h>
#include <stdlib.h>
#include <string.h>
#include <mailutils/syslog.h>
#include <mailutils/mailbox.h>
/* ************************************************************************* */
/* Common */
/* ************************************************************************* */
enum {
OPT_SHOW_OPTIONS=256,
OPT_NO_USER_RCFILE,
OPT_NO_SITE_RCFILE,
OPT_RCFILE,
OPT_RCFILE_LINT,
OPT_RCFILE_VERBOSE,
OPT_LOG_FACILITY,
OPT_LICENSE,
OPT_DEBUG_LEVEL,
OPT_LINE_INFO,
OPT_HELP_CONFIG,
OPT_SET
};
static struct argp_option mu_common_argp_options[] =
{
{ NULL, 0, NULL, 0, N_("Common options"), 0},
{ "show-config-options", OPT_SHOW_OPTIONS, NULL, 0,
N_("show compilation options"), 0 },
{ "config-help", OPT_HELP_CONFIG, NULL, 0,
N_("show configuration file summary"), 0 },
{ "no-user-config", OPT_NO_USER_RCFILE, NULL, 0,
N_("do not load user configuration file"), 0 },
{ "no-user-rcfile", 0, NULL, OPTION_ALIAS, NULL },
{ "no-site-config", OPT_NO_SITE_RCFILE, NULL, 0,
N_("do not load site configuration file"), 0 },
{ "no-site-rcfile", 0, NULL, OPTION_ALIAS, NULL },
{ "config-file", OPT_RCFILE, N_("FILE"), 0,
N_("load this configuration file"), 0, },
{ "rcfile", 0, NULL, OPTION_ALIAS, NULL },
{ "config-verbose", OPT_RCFILE_VERBOSE, NULL, 0,
N_("verbosely log parsing of the configuration files"), 0 },
{ "rcfile-verbose", 0, NULL, OPTION_ALIAS, NULL },
{ "config-lint", OPT_RCFILE_LINT, NULL, 0,
N_("check configuration file syntax and exit"), 0 },
{ "rcfile-lint", 0, NULL, OPTION_ALIAS, NULL },
{ "set", OPT_SET, N_("PARAM=VALUE"), 0,
N_("set configuration parameter"), 0 },
{ NULL, 0, NULL, 0, NULL, 0 }
};
static void
set_config_param (const char *path, struct argp_state *state)
{
mu_cfg_node_t *node;
int rc = mu_cfg_create_subtree (path, &node);
if (rc)
argp_error (state, "cannot create node: %s", mu_strerror (rc));
mu_cfg_tree_add_node (mu_argp_tree, node);
}
static error_t
mu_common_argp_parser (int key, char *arg, struct argp_state *state)
{
switch (key)
{
case OPT_SHOW_OPTIONS:
mu_print_options ();
exit (0);
case OPT_NO_USER_RCFILE:
mu_load_user_rcfile = 0;
break;
case OPT_NO_SITE_RCFILE:
mu_load_site_rcfile = 0;
break;
case OPT_RCFILE:
mu_load_rcfile = arg;
break;
case OPT_RCFILE_LINT:
mu_cfg_parser_verbose++;
mu_rcfile_lint = 1;
break;
case OPT_RCFILE_VERBOSE:
mu_cfg_parser_verbose++;
break;
case OPT_HELP_CONFIG:
mu_help_config_mode = 1;
break;
case OPT_SET:
set_config_param (arg, state);
break;
default:
return ARGP_ERR_UNKNOWN;
}
return 0;
}
struct argp mu_common_argp = {
mu_common_argp_options,
mu_common_argp_parser,
};
struct argp_child mu_common_argp_child = {
&mu_common_argp,
0,
NULL,
0,
};
struct mu_cmdline_capa mu_common_cmdline = {
"common", &mu_common_argp_child
};
/* ************************************************************************* */
/* Logging */
/* ************************************************************************* */
static struct argp_option mu_logging_argp_option[] = {
{"log-facility", OPT_LOG_FACILITY, N_("FACILITY"), 0,
N_("output logs to syslog FACILITY"), 0},
{ NULL, 0, NULL, 0, NULL, 0 }
};
static error_t
mu_logging_argp_parser (int key, char *arg, struct argp_state *state)
{
static mu_list_t lst;
switch (key)
{
/* log */
case OPT_LOG_FACILITY:
mu_argp_node_list_new (lst, "facility", arg);
break;
case ARGP_KEY_INIT:
mu_argp_node_list_init (&lst);
break;
case ARGP_KEY_FINI:
mu_argp_node_list_finish (lst, "logging", NULL);
break;
default:
return ARGP_ERR_UNKNOWN;
}
return 0;
}
struct argp mu_logging_argp = {
mu_logging_argp_option,
mu_logging_argp_parser,
};
struct argp_child mu_logging_argp_child = {
&mu_logging_argp,
0,
NULL,
0
};
struct mu_cmdline_capa mu_logging_cmdline = {
"logging", &mu_logging_argp_child
};
/* ************************************************************************* */
/* Mailer */
/* ************************************************************************* */
/* Options used by programs that send mail. */
static struct argp_option mu_mailer_argp_option[] = {
{"mailer", 'M', N_("MAILER"), 0,
N_("use specified URL as the default mailer"), 0},
{ NULL, 0, NULL, 0, NULL, 0 }
};
static error_t
mu_mailer_argp_parser (int key, char *arg, struct argp_state *state)
{
static mu_list_t lst;
switch (key)
{
/* mailer */
case 'M':
mu_argp_node_list_new (lst, "url", arg);
break;
case ARGP_KEY_INIT:
mu_argp_node_list_init (&lst);
break;
case ARGP_KEY_FINI:
mu_argp_node_list_finish (lst, "mailer", NULL);
break;
default:
return ARGP_ERR_UNKNOWN;
}
return 0;
}
struct argp mu_mailer_argp = {
mu_mailer_argp_option,
mu_mailer_argp_parser,
};
struct argp_child mu_mailer_argp_child = {
&mu_mailer_argp,
0,
NULL,
0
};
struct mu_cmdline_capa mu_mailer_cmdline = {
"mailer", &mu_mailer_argp_child
};
static struct argp_option mu_debug_argp_options[] =
{
{ "debug-level", OPT_DEBUG_LEVEL, N_("LEVEL"), 0,
N_("set Mailutils debugging level"), 0 },
{ "debug-line-info", OPT_LINE_INFO, NULL, 0,
N_("show source info with debugging messages"), 0 },
{ NULL }
};
static error_t
mu_debug_argp_parser (int key, char *arg, struct argp_state *state)
{
static mu_list_t lst;
switch (key)
{
case OPT_DEBUG_LEVEL:
mu_debug_parse_spec (arg);
/*mu_argp_node_list_new (lst, "level", arg);*/
break;
case OPT_LINE_INFO:
mu_argp_node_list_new (lst, "line-info", "yes");
break;
case ARGP_KEY_INIT:
mu_argp_node_list_init (&lst);
break;
case ARGP_KEY_FINI:
mu_argp_node_list_finish (lst, "debug", NULL);
break;
default:
return ARGP_ERR_UNKNOWN;
}
return 0;
}
struct argp mu_debug_argp = {
mu_debug_argp_options,
mu_debug_argp_parser,
};
struct argp_child mu_debug_argp_child = {
&mu_debug_argp,
0,
N_("Global debugging settings"),
0
};
struct mu_cmdline_capa mu_debug_cmdline = {
"debug", &mu_debug_argp_child
};
/* GNU Mailutils -- a suite of utilities for electronic mail
Copyright (C) 2007-2012, 2014-2016 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
License as published by the Free Software Foundation; either
version 3 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General
Public License along with this library. If not, see
<http://www.gnu.org/licenses/>. */
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
#include "cmdline.h"
#include <unistd.h>
#include <stdlib.h>
/* Provide declaration of __argp_base_name: */
#include <argp-namefrob.h>
/* ************************************************************************* */
/* GNU Mailutils help and version output */
/* ************************************************************************* */
#define OPT_PROGNAME -2
#define OPT_USAGE -3
#define OPT_HANG -4
static struct argp_option mu_mailutils_argp_options[] =
{
{"help", '?', 0, 0, N_("give this help list"), -1},
{"usage", OPT_USAGE, 0, 0, N_("give a short usage message"), 0},
{"version", 'V', 0, 0, N_("print program version"), -1},
{"program-name",OPT_PROGNAME,N_("NAME"), OPTION_HIDDEN, N_("set the program name"), 0},
{"HANG", OPT_HANG, N_("SECS"), OPTION_ARG_OPTIONAL | OPTION_HIDDEN,
N_("hang for SECS seconds (default 3600)"), 0},
{ NULL }
};
static error_t
mu_mailutils_argp_parser (int key, char *arg, struct argp_state *state)
{
switch (key)
{
case '?':
argp_state_help (state, state->out_stream,
ARGP_HELP_SHORT_USAGE | ARGP_HELP_LONG | ARGP_HELP_DOC);
/* TRANSLATORS: The placeholder indicates the bug-reporting address
for this package. Please add _another line_ saying
"Report translation bugs to <...>\n" with the address for translation
bugs (typically your translation team's web or email address). */
printf (_("\nReport bugs to: %s\n"), "<" PACKAGE_BUGREPORT ">");
#ifdef PACKAGE_PACKAGER_BUG_REPORTS
printf (_("Report %s bugs to: %s\n"), PACKAGE_PACKAGER,
PACKAGE_PACKAGER_BUG_REPORTS);
#endif
#ifdef PACKAGE_URL
printf (_("%s home page: <%s>\n"), PACKAGE_NAME, PACKAGE_URL);
#endif
fputs (_("General help using GNU software: <http://www.gnu.org/gethelp/>\n"),
stdout);
exit (0);
case OPT_USAGE:
argp_state_help (state, state->out_stream,
ARGP_HELP_USAGE | ARGP_HELP_EXIT_OK);
break;
case 'V':
if (argp_program_version_hook)
(*argp_program_version_hook) (state->out_stream, state);
else if (argp_program_version)
fprintf (state->out_stream, "%s\n", argp_program_version);
else
argp_error (state, "%s",
dgettext (state->root_argp->argp_domain,
"(PROGRAM ERROR) No version known!?"));
exit(0);
case OPT_PROGNAME: /* Set the program name. */
#if HAVE_DECL_PROGRAM_INVOCATION_NAME
program_invocation_name = arg;
#endif
/* Update what we use for messages. */
state->name = __argp_base_name (arg);
#if HAVE_DECL_PROGRAM_INVOCATION_SHORT_NAME
program_invocation_short_name = state->name;
#endif
if ((state->flags & (ARGP_PARSE_ARGV0 | ARGP_NO_ERRS))
== ARGP_PARSE_ARGV0)
/* Update what getopt uses too. */
state->argv[0] = arg;
break;
case OPT_HANG:
{
int hang = atoi (arg ? arg : "3600");
while (hang-- > 0)
sleep (1);
break;
}
default:
return ARGP_ERR_UNKNOWN;
}
return 0;
}
struct argp mu_mailutils_argp = {
mu_mailutils_argp_options,
mu_mailutils_argp_parser,
};
struct argp_child mu_mailutils_argp_child = {
&mu_mailutils_argp,
0,
NULL,
-1,
};
static void
mu_mailutils_modflags(int *flags)
{
*flags |= ARGP_NO_HELP;
}
struct mu_cmdline_capa mu_mailutils_cmdline = {
"mailutils", &mu_mailutils_argp_child, mu_mailutils_modflags
};
/* GNU Mailutils -- a suite of utilities for electronic mail
Copyright (C) 1999, 2001-2007, 2009-2012, 2014-2016 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
License as published by the Free Software Foundation; either
version 3 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General
Public License along with this library. If not, see
<http://www.gnu.org/licenses/>. */
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
#include <pwd.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <syslog.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include "mailutils/libargp.h"
/* ************************************************************************* */
/* Capability array and auxiliary functions. */
/* ************************************************************************* */
#define MU_MAX_CAPA 24
struct argp_capa {
char *capability;
struct argp_child *child;
void (*modflags)(int*);
} mu_argp_capa[MU_MAX_CAPA] = {
{NULL,}
};
int
mu_register_argp_capa (const char *name, struct argp_child *child,
void (*modflags)(int*))
{
int i;
for (i = 0; i < MU_MAX_CAPA; i++)
if (mu_argp_capa[i].capability == NULL)
{
if ((mu_argp_capa[i].capability = strdup (name)) == NULL)
return ENOMEM;
mu_argp_capa[i].child = child;
mu_argp_capa[i].modflags = modflags;
return 0;
}
return 1;
}
static struct argp_capa *
find_capa (const char *name)
{
int i;
for (i = 0; mu_argp_capa[i].capability; i++)
if (strcmp (mu_argp_capa[i].capability, name) == 0)
return &mu_argp_capa[i];
return NULL;
}
static struct argp *
mu_build_argp (const struct argp *template, char **capa, int *flags)
{
int n;
int nchild;
struct argp_child *ap;
const struct argp_option *opt;
struct argp *argp;
int group = 0;
/* Count the capabilities. */
for (n = 0; capa && capa[n]; n++)
;
if (template->children)
for (; template->children[n].argp; n++)
;
ap = calloc (n + 1, sizeof (*ap));
if (!ap)
{
mu_error (_("not enough memory"));
abort ();
}
/* Copy the template's children. */
nchild = 0;
if (template->children)
for (n = 0; template->children[n].argp; n++, nchild++)
ap[nchild] = template->children[n];
/* Find next group number */
for (opt = template->options;
opt && ((opt->name && opt->key) || opt->doc); opt++)
if (opt->group > group)
group = opt->group;
group++;
/* Append any capabilities to the children or options, as appropriate. */
for (n = 0; capa && capa[n]; n++)
{
struct argp_capa *cp = find_capa (capa[n]);
if (cp)
{
if (cp->modflags)
cp->modflags (flags);
if (cp->child)
{
ap[nchild] = *cp->child;
if (ap[nchild].group < 0)
ap[nchild].group = 0;
else
ap[nchild].group = group++;
nchild++;
}
}
}
ap[nchild].argp = NULL;
/* Copy the template, and give it the expanded children. */
argp = malloc (sizeof (*argp));
if (!argp)
{
mu_error (_("not enough memory"));
abort ();
}
memcpy (argp, template, sizeof (*argp));
argp->children = ap;
return argp;
}
struct cap_buf
{
char **capa;
size_t numcapa;
size_t maxcapa;
};
static void
cap_buf_init (struct cap_buf *bp)
{
bp->numcapa = 0;
bp->maxcapa = 2;
bp->capa = calloc (bp->maxcapa, sizeof bp->capa[0]);
if (!bp->capa)
{
mu_error ("%s", mu_strerror (errno));
abort ();
}
bp->capa[0] = NULL;
}
static void
cap_buf_add (struct cap_buf *bp, char *str)
{
if (bp->numcapa == bp->maxcapa)
{
bp->maxcapa *= 2;
bp->capa = realloc (bp->capa, bp->maxcapa * sizeof bp->capa[0]);
if (!bp->capa)
{
mu_error ("%s", mu_strerror (errno));
abort ();
}
}
bp->capa[bp->numcapa] = str;
if (str)
bp->numcapa++;
}
static void
cap_buf_free (struct cap_buf *bp)
{
free (bp->capa);
}
static int
argp_reg_action (void *item, void *data)
{
struct cap_buf *bp = data;
cap_buf_add (bp, item);
return 0;
}
struct argp *
mu_argp_build (const struct argp *init_argp, char ***pcapa, int *flags)
{
struct cap_buf cb;
struct argp *argp;
cap_buf_init (&cb);
mu_gocs_enumerate (argp_reg_action, &cb);
cap_buf_add (&cb, NULL);
mu_libargp_init ();
argp = mu_build_argp (init_argp, cb.capa, flags);
if (pcapa)
*pcapa = cb.capa;
else
cap_buf_free (&cb);
return argp;
}
void
mu_argp_done (struct argp *argp)
{
free ((void*) argp->children);
free ((void*) argp);
}
/* GNU Mailutils -- a suite of utilities for electronic mail
Copyright (C) 2007-2012, 2014-2016 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
License as published by the Free Software Foundation; either
version 3 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General
Public License along with this library. If not, see
<http://www.gnu.org/licenses/>. */
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
#include "cmdline.h"
#include <unistd.h>
#include <stdlib.h>
#include <mailutils/alloc.h>
#include <mailutils/stream.h>
#include <mailutils/io.h>
#include <mailutils/stdstream.h>
#include <string.h>
#ifdef MU_ALPHA_RELEASE
# include <git-describe.h>
#endif
struct mu_cfg_tree *mu_argp_tree;
const char version_etc_copyright[] =
/* Do *not* mark this string for translation. %s is a copyright
symbol suitable for this locale, and %d is the copyright
year. */
"Copyright %s 2007-2015 Free Software Foundation, inc.";
void
mu_program_version_hook (FILE *stream, struct argp_state *state)
{
#ifdef GIT_DESCRIBE
fprintf (stream, "%s (%s) %s [%s]\n",
mu_program_name, PACKAGE_NAME, PACKAGE_VERSION, GIT_DESCRIBE);
#else
fprintf (stream, "%s (%s) %s\n", mu_program_name,
PACKAGE_NAME, PACKAGE_VERSION);
#endif
/* TRANSLATORS: Translate "(C)" to the copyright symbol
(C-in-a-circle), if this symbol is available in the user's
locale. Otherwise, do not translate "(C)"; leave it as-is. */
fprintf (stream, version_etc_copyright, _("(C)"));
fputs (_("\
\n\
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>\nThis is free software: you are free to change and redistribute it.\n\
There is NO WARRANTY, to the extent permitted by law.\n\
\n\
"),
stream);
}
void
mu_argp_init (const char *vers, const char *bugaddr)
{
if (vers)
argp_program_version = vers;
else
argp_program_version_hook = mu_program_version_hook;
argp_program_bug_address = bugaddr ? bugaddr : "<" PACKAGE_BUGREPORT ">";
}
static char *
get_canonical_name ()
{
char *name;
size_t len;
char *p;
if (!argp_program_version ||
!(p = strchr (argp_program_version, ' ')))
return strdup (mu_program_name);
len = p - argp_program_version;
name = mu_alloc (len + 1);
memcpy (name, argp_program_version, len);
name[len] = 0;
return name;
}
int mu_help_config_mode;
int mu_rcfile_lint;
int (*mu_app_cfg_verifier) (void) = NULL;
int
mu_app_init (struct argp *myargp, const char **capa,
struct mu_cfg_param *cfg_param,
int argc, char **argv, int flags, int *pindex, void *data)
{
int rc, i;
struct argp *argp;
struct argp argpnull = { 0 };
char **excapa;
struct mu_cfg_tree *parse_tree = NULL;
if (!mu_program_name)
mu_set_program_name (argv[0]);
if (!mu_log_tag)
mu_log_tag = (char*)mu_program_name;
mu_stdstream_setup (MU_STDSTREAM_RESET_NONE);
mu_libargp_init ();
if (capa)
for (i = 0; capa[i]; i++)
mu_gocs_register_std (capa[i]); /*FIXME*/
if (!myargp)
myargp = &argpnull;
argp = mu_argp_build (myargp, &excapa, &flags);
mu_cfg_tree_create (&mu_argp_tree);
rc = argp_parse (argp, argc, argv, flags, pindex, data);
mu_argp_done (argp);
if (rc)
return rc;
/* Reset program name, it may have been changed using the `--program-name'
option. */
mu_set_program_name (program_invocation_name);
mu_libcfg_init (excapa);
free (excapa);
if (mu_help_config_mode)
{
char *comment;
char *canonical_name = get_canonical_name ();
mu_stream_t stream;
struct mu_cfg_cont *cont;
static struct mu_cfg_param dummy_include_param[] = {
{ "include", mu_c_string, NULL, 0, NULL,
N_("Include contents of the given file. If a directory is given, "
"include contents of the file <file>/<program>, where "
"<program> is the name of the program. This latter form is "
"allowed only in the site-wide configuration file."),
N_("file-or-directory") },
{ NULL }
};
mu_stdio_stream_create (&stream, MU_STDOUT_FD, 0);
mu_asprintf (&comment,
"Configuration file structure for %s utility.",
mu_program_name);
mu_cfg_format_docstring (stream, comment, 0);
free (comment);
mu_asprintf (&comment,
"For use in global configuration file (%s), enclose it "
"in `program %s { ... };",
mu_site_rcfile,
mu_program_name);
mu_cfg_format_docstring (stream, comment, 0);
free (comment);
mu_asprintf (&comment, "For more information, use `info %s'.",
canonical_name);
mu_cfg_format_docstring (stream, comment, 0);
free (comment);
cont = mu_config_clone_root_container ();
mu_config_container_register_section (&cont, NULL, NULL, NULL, NULL,
dummy_include_param, NULL);
mu_config_container_register_section (&cont, NULL, NULL, NULL, NULL,
cfg_param, NULL);
mu_cfg_format_container (stream, cont);
mu_config_destroy_container (&cont);
mu_stream_destroy (&stream);
exit (0);
}
rc = mu_libcfg_parse_config (&parse_tree);
if (rc == 0)
{
struct mu_cfg_parse_hints hints = { MU_PARSE_CONFIG_PLAIN };
hints.flags |= MU_CFG_PARSE_PROGRAM;
hints.program = (char*)mu_program_name;
if (mu_cfg_parser_verbose)
hints.flags |= MU_PARSE_CONFIG_VERBOSE;
if (mu_cfg_parser_verbose > 1)
hints.flags |= MU_PARSE_CONFIG_DUMP;
mu_cfg_tree_postprocess (mu_argp_tree, &hints);
mu_cfg_tree_union (&parse_tree, &mu_argp_tree);
rc = mu_cfg_tree_reduce (parse_tree, &hints, cfg_param, data);
}
if (mu_rcfile_lint)
{
if (rc || mu_cfg_error_count)
exit (1);
if (mu_app_cfg_verifier)
rc = mu_app_cfg_verifier ();
exit (rc ? 1 : 0);
}
mu_gocs_flush ();
mu_cfg_destroy_tree (&mu_argp_tree);
mu_cfg_destroy_tree (&parse_tree);
return !!(rc || mu_cfg_error_count);
}
/* GNU Mailutils -- a suite of utilities for electronic mail
Copyright (C) 1999-2002, 2005, 2007, 2009-2012, 2014-2016 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
License as published by the Free Software Foundation; either
version 3 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General
Public License along with this library. If not, see
<http://www.gnu.org/licenses/>. */
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
#include "cmdline.h"
#include "mailutils/sieve.h"
enum {
OPT_CLEAR_INCLUDE_PATH = 256,
OPT_CLEAR_LIBRARY_PATH,
OPT_PREFIX_LIBRARY_PATH
};
static struct argp_option sieve_argp_option[] = {
{ "includedir", 'I', N_("DIR"), 0,
N_("append DIR to the list of directories searched for include files"), 0 },
{ "libdir", 'L', N_("DIR"), 0,
N_("append DIR to the list of directories searched for library files"), 0 },
{ "libdir-prefix", OPT_PREFIX_LIBRARY_PATH, N_("DIR"), 0,
N_("add DIR to the beginning of the list of directories searched for "
"library files"), 0 },
{ "clear-include-path", OPT_CLEAR_INCLUDE_PATH, NULL, 0,
N_("clear Sieve include path"), 0 },
{ "clear-library-path", OPT_CLEAR_LIBRARY_PATH, NULL, 0,
N_("clear Sieve library path"), 0 },
{ "clearpath", 0, NULL, OPTION_ALIAS, NULL },
{ NULL, 0, NULL, 0, NULL, 0 }
};
static error_t
sieve_argp_parser (int key, char *arg, struct argp_state *state)
{
static mu_list_t lst;
switch (key)
{
case 'I':
mu_argp_node_list_new (lst, "include-path", arg);
break;
case 'L':
mu_argp_node_list_new (lst, "library-path", arg);
break;
case OPT_PREFIX_LIBRARY_PATH:
mu_argp_node_list_new (lst, "library-path-prefix", arg);
break;
case OPT_CLEAR_INCLUDE_PATH:
mu_argp_node_list_new (lst, "clear-include-path", "yes");
break;
case OPT_CLEAR_LIBRARY_PATH:
mu_argp_node_list_new (lst, "clear-library-path", "yes");
break;
case ARGP_KEY_INIT:
mu_argp_node_list_init (&lst);
break;
case ARGP_KEY_FINI:
mu_argp_node_list_finish (lst, "sieve", NULL);
break;
default:
return ARGP_ERR_UNKNOWN;
}
return 0;
}
static struct argp sieve_argp = {
sieve_argp_option,
sieve_argp_parser,
};
static struct argp_child sieve_argp_child = {
&sieve_argp,
0,
N_("Sieve options"),
0
};
struct mu_cmdline_capa mu_sieve_cmdline = {
"sieve", &sieve_argp_child
};
......@@ -19,6 +19,7 @@
#if HAVE_CONFIG_H
# include <config.h>
#endif
#include <mailutils/cli.h>
#ifdef WITH_GSASL
......@@ -46,13 +47,27 @@ struct mu_gsasl_module_data mu_gsasl_module_data = {
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
};
......
......@@ -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);
}
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 }
};
if (op != mu_gocs_op_set)
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;
}
if (cfg)
ldap_param = *cfg;
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
......@@ -272,8 +336,6 @@ _mu_conn_setup (LDAP **pld)
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
};
......
......@@ -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
};
......
......@@ -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? */
struct mu_locus locus;
if (!input)
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*/
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;
......@@ -158,13 +171,42 @@ parse_pairlist (grad_avp_t **plist, char *input)
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
......
......@@ -50,11 +50,96 @@
#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
}
};
......
......@@ -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 */
......
......@@ -53,21 +53,19 @@
#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 };
static char *pwddir = { 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 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 */
......@@ -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,
}
};
......
*.la
*.lo
.deps
.libs
Makefile
Makefile.in
.gdbinit
# This file is part of GNU Mailutils
# Copyright (C) 2007, 2009-2012, 2014-2016 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 the Free Software Foundation; either version 3, or (at
# your option) any later version.
#
# GNU Mailutils is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with GNU Mailutils. If not, see <http://www.gnu.org/licenses/>.
AM_CPPFLAGS = \
@MU_LIB_COMMON_INCLUDES@\
-DSITE_VIRTUAL_PWDDIR=\"@SITE_VIRTUAL_PWDDIR@\" \
-DSITE_CRAM_MD5_PWD=\"@SITE_CRAM_MD5_PWD@\"
lib_LTLIBRARIES = libmu_cfg.la
libmu_cfg_la_SOURCES=\
acl.c\
auth.c\
common.c\
init.c\
gsasl.c\
ldap.c\
pam.c\
radius.c\
sieve.c\
sql.c\
tls.c\
virtdomain.c
libmu_cfg_la_LDFLAGS=-version-info @VI_CURRENT@:@VI_REVISION@:@VI_AGE@
/* This file is part of GNU Mailutils
Copyright (C) 2007-2012, 2014-2016 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 the Free Software Foundation; either version 3, or (at
your option) any later version.
GNU Mailutils is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with GNU Mailutils. If not, see <http://www.gnu.org/licenses/>.
*/
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
#include "mailutils/libcfg.h"
#include "mailutils/acl.h"
#include "mailutils/argcv.h"
#include "mailutils/cidr.h"
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <sys/time.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#define ISSPACE(c) ((c)==' '||(c)=='\t')
#define SKIPWS(p) while (*(p) && ISSPACE (*(p))) (p)++;
static const char *
getword (mu_config_value_t *val, int *pn)
{
int n = (*pn)++;
mu_config_value_t *v;
if (n >= val->v.arg.c)
{
mu_error (_("not enough arguments"));
return NULL;
}
v = &val->v.arg.v[n];
if (mu_cfg_assert_value_type (v, MU_CFG_STRING))
return NULL;
return v->v.string;
}
static int
parsearg (mu_config_value_t *val, struct mu_cidr *cidr, char **prest)
{
const char *w;
int n = 0;
int rc;
if (mu_cfg_assert_value_type (val, MU_CFG_ARRAY))
return 1;
w = getword (val, &n);
if (!w)
return 1;
if (strcmp (w, "from") == 0) {
w = getword (val, &n);
if (!w)
return 1;
}
if (strcmp (w, "any") == 0)
cidr->len = 0;
else
{
rc = mu_cidr_from_string (cidr, w);
if (rc)
{
mu_error (_("invalid source CIDR: %s"), mu_strerror (rc));
return 1;
}
}
if (prest)
{
if (n == val->v.arg.c)
*prest = NULL;
else
{
size_t size = 0;
int i;
char *buf;
for (i = n; i < val->v.arg.c; i++)
{
if (mu_cfg_assert_value_type (&val->v.arg.v[i], MU_CFG_STRING))
return 1;
size += strlen (val->v.arg.v[i].v.string) + 1;
}
buf = malloc (size);
if (!buf)
{
mu_error ("%s", mu_strerror (errno));
return 1;
}
*prest = buf;
for (i = n; i < val->v.arg.c; i++)
{
if (i > n)
*buf++ = ' ';
strcpy (buf, val->v.arg.v[i].v.string);
buf += strlen (buf);
}
*buf = 0;
}
}
else if (n != val->v.arg.c)
{
mu_error (_("junk after IP address"));
return 1;
}
return 0;
}
static int
cb_allow (void *data, mu_config_value_t *val)
{
int rc;
mu_acl_t acl = *(mu_acl_t*)data;
struct mu_cidr cidr;
if (parsearg (val, &cidr, NULL))
return 1;
rc = mu_acl_append (acl, mu_acl_accept, NULL, &cidr);
if (rc)
mu_error (_("cannot append acl entry: %s"), mu_strerror (rc));
return rc;
}
static int
cb_deny (void *data, mu_config_value_t *val)
{
int rc;
mu_acl_t acl = *(mu_acl_t*)data;
struct mu_cidr cidr;
if (parsearg (val, &cidr, NULL))
return 1;
rc = mu_acl_append (acl, mu_acl_deny, NULL, &cidr);
if (rc)
mu_error (_("cannot append acl entry: %s"), mu_strerror (rc));
return rc;
}
static int
cb_log (void *data, mu_config_value_t *val)
{
int rc;
mu_acl_t acl = *(mu_acl_t*)data;
struct mu_cidr cidr;
char *rest;
if (parsearg (val, &cidr, &rest))
return 1;
rc = mu_acl_append (acl, mu_acl_log, rest, &cidr);
if (rc)
mu_error (_("cannot append acl entry: %s"), mu_strerror (rc));
return rc;
}
static int
cb_exec (void *data, mu_config_value_t *val)
{
int rc;
mu_acl_t acl = *(mu_acl_t*)data;
struct mu_cidr cidr;
char *rest;
if (parsearg (val, &cidr, &rest))
return 1;
rc = mu_acl_append (acl, mu_acl_exec, rest, &cidr);
if (rc)
mu_error (_("cannot append acl entry: %s"), mu_strerror (rc));
return rc;
}
static int
cb_ifexec (void *data, mu_config_value_t *val)
{
int rc;
mu_acl_t acl = *(mu_acl_t*)data;
struct mu_cidr cidr;
char *rest;
if (parsearg (val, &cidr, &rest))
return 1;
rc = mu_acl_append (acl, mu_acl_ifexec, rest, &cidr);
if (rc)
mu_error (_("cannot append acl entry: %s"), mu_strerror (rc));
return rc;
}
static struct mu_cfg_param acl_param[] = {
{ "allow", mu_cfg_callback, NULL, 0, cb_allow,
N_("Allow connections from this IP address. Optional word `from' is "
"allowed between it and its argument. The same holds true for other "
"actions below."),
N_("addr: IP") },
{ "deny", mu_cfg_callback, NULL, 0, cb_deny,
N_("Deny connections from this IP address."),
N_("addr: IP") },
{ "log", mu_cfg_callback, NULL, 0, cb_log,
N_("Log connections from this IP address."),
N_("addr: IP") },
{ "exec", mu_cfg_callback, NULL, 0, cb_exec,
N_("Execute supplied program if a connection from this IP address is "
"requested. Arguments are:\n"
" <addr: IP> <program: string>\n"
"Following macros are expanded in <program> before executing:\n"
" address - Source IP address\n"
" port - Source port number\n") },
{ "ifexec", mu_cfg_callback, NULL, 0, cb_ifexec,
N_("If a connection from this IP address is requested, execute supplied "
"program and allow or deny the connection depending on its exit code. "
"See `exec' for a description of its arguments.") },
{ NULL }
};
static int
acl_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:
{
void *data = *section_data;
mu_acl_create ((mu_acl_t*)data);
}
break;
case mu_cfg_section_end:
break;
}
return 0;
}
void
mu_acl_cfg_init ()
{
struct mu_cfg_section *section;
if (mu_create_canned_section ("acl", &section) == 0)
{
section->parser = acl_section_parser;
mu_cfg_section_add_params (section, acl_param);
}
}
/* This file is part of GNU Mailutils
Copyright (C) 2007-2008, 2010-2012, 2014-2016 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 the Free Software Foundation; either version 3, or (at
your option) any later version.
GNU Mailutils is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with GNU Mailutils. If not, see <http://www.gnu.org/licenses/>.
*/
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
#include "mailutils/libcfg.h"
#include <mailutils/mu_auth.h>
#include <string.h>
/* FIXME: mu_auth.c should be reviewed */
/* ************************************************************************* */
/* Resource-style configuration */
/* ************************************************************************* */
static int
cb_authentication (void *data, mu_config_value_t *val)
{
if (val->type == MU_CFG_STRING)
{
if (strcmp (val->v.string, "clear") == 0)
mu_authentication_clear_list ();
else
/*FIXME: use err for error reporting*/
mu_authentication_add_module_list (val->v.string);
}
else if (val->type == MU_CFG_LIST)
{
int i;
for (i = 0; i < val->v.arg.c; i++)
{
if (mu_cfg_assert_value_type (&val->v.arg.v[i], MU_CFG_STRING))
return 1;
if (strcmp (val->v.arg.v[i].v.string, "clear") == 0)
mu_authentication_clear_list ();
else
mu_authentication_add_module (val->v.arg.v[i].v.string);
}
}
else
{
mu_error (_("expected string value"));
return 1;
}
return 0;
}
static int
cb_authorization (void *data, mu_config_value_t *val)
{
if (val->type == MU_CFG_STRING)
{
if (strcmp (val->v.string, "clear") == 0)
mu_authorization_clear_list ();
else
/*FIXME: use err for error reporting*/
mu_authorization_add_module_list (val->v.string);
}
else if (val->type == MU_CFG_LIST)
{
int i;
for (i = 0; i < val->v.arg.c; i++)
{
if (mu_cfg_assert_value_type (&val->v.arg.v[i], MU_CFG_STRING))
return 1;
if (strcmp (val->v.arg.v[i].v.string, "clear") == 0)
mu_authorization_clear_list ();
else
mu_authorization_add_module (val->v.arg.v[i].v.string);
}
}
else
{
mu_error (_("expected string value"));
return 1;
}
return 0;
}
static struct mu_cfg_param mu_auth_param[] = {
{ "authentication", mu_cfg_callback, NULL, 0, cb_authentication,
/* FIXME: The description is incomplete. MU-list is also allowed as
argument */
N_("Set a list of modules for authentication. Modlist is a "
"colon-separated list of module names or a word `clear' to "
"clear the previously set up values."),
N_("modlist") },
{ "authorization", mu_cfg_callback, NULL, 0, cb_authorization,
N_("Set a list of modules for authorization. Modlist is a "
"colon-separated list of module names or a word `clear' to "
"clear the previously set up values."),
N_("modlist") },
{ NULL }
};
int
mu_auth_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:
break;
case mu_cfg_section_end:
mu_auth_finish_setup ();
}
return 0;
}
struct mu_cfg_capa mu_auth_cfg_capa = {
"auth", mu_auth_param, mu_auth_section_parser
};
/* This file is part of GNU Mailutils
Copyright (C) 2007-2012, 2014-2016 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 the Free Software Foundation; either version 3, or (at
your option) any later version.
GNU Mailutils is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with GNU Mailutils. If not, see <http://www.gnu.org/licenses/>.
*/
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
#include <stdlib.h>
#include <string.h>
#include "mailutils/libcfg.h"
#include <mailutils/debug.h>
#include <mailutils/syslog.h>
#include <mailutils/mailbox.h>
#include <mailutils/io.h>
#include <mailutils/stream.h>
#include <mailutils/stdstream.h>
static struct mu_gocs_locking locking_settings;
static struct mu_gocs_mailbox mailbox_settings;
static struct mu_gocs_source_email address_settings;
static struct mu_gocs_mailer mailer_settings;
static struct mu_gocs_debug debug_settings;
/* ************************************************************************* */
/* Mailbox */
/* ************************************************************************* */
static int
_cb_folder (void *data, mu_config_value_t *val)
{
if (mu_cfg_assert_value_type (val, MU_CFG_STRING))
return 1;
mu_set_folder_directory (val->v.string);
return 0;
}
static struct mu_cfg_param mu_mailbox_param[] = {
{ "mail-spool", mu_c_string, &mailbox_settings.mail_spool, 0, NULL,
N_("Use specified URL as a mailspool directory."),
N_("url") },
{ "mailbox-pattern", mu_c_string, &mailbox_settings.mailbox_pattern,
0, NULL,
N_("Create mailbox URL using <pattern>."),
N_("pattern") },
{ "mailbox-type", mu_c_string, &mailbox_settings.mailbox_type, 0, NULL,
N_("Default mailbox type."), N_("protocol") },
{ "folder", mu_cfg_callback, NULL, 0, _cb_folder,
N_("Default user mail folder"),
N_("dir") },
{ NULL }
};
DCL_CFG_CAPA (mailbox);
/* ************************************************************************* */
/* Locking */
/* ************************************************************************* */
static struct mu_cfg_param mu_locking_param[] = {
/* FIXME: Flags are superfluous. */
{ "flags", mu_c_string, &locking_settings.lock_flags, 0, NULL,
N_("Default locker flags (E=external, R=retry, T=time, P=pid).") },
{ "retry-timeout", mu_c_ulong, &locking_settings.lock_retry_timeout,
0, NULL,
N_("Set timeout for acquiring the lock.") },
{ "retry-count", mu_c_ulong, &locking_settings.lock_retry_count, 0, NULL,
N_("Set the maximum number of times to retry acquiring the lock.") },
{ "expire-timeout", mu_c_ulong, &locking_settings.lock_expire_timeout,
0, NULL,
N_("Expire locks older than this amount of time.") },
{ "external-locker", mu_c_string, &locking_settings.external_locker,
0, NULL,
N_("Use external locker program."),
N_("prog") },
{ NULL, }
};
DCL_CFG_CAPA (locking);
/* ************************************************************************* */
/* Address */
/* ************************************************************************* */
static struct mu_cfg_param mu_address_param[] = {
{ "email-addr", mu_c_string, &address_settings.address, 0, NULL,
N_("Set the current user email address (default is "
"loginname@defaultdomain)."),
N_("email") },
{ "email-domain", mu_c_string, &address_settings.domain, 0, NULL,
N_("Set e-mail domain for unqualified user names (default is this host)"),
N_("domain") },
{ NULL }
};
DCL_CFG_CAPA (address);
/* ************************************************************************* */
/* Mailer */
/* ************************************************************************* */
static struct mu_cfg_param mu_mailer_param[] = {
{ "url", mu_c_string, &mailer_settings.mailer, 0, NULL,
N_("Use this URL as the default mailer"),
N_("url") },
{ NULL }
};
DCL_CFG_CAPA (mailer);
/* ************************************************************************* */
/* Logging */
/* ************************************************************************* */
static int
cb_facility (void *data, mu_config_value_t *val)
{
if (mu_cfg_assert_value_type (val, MU_CFG_STRING))
return 1;
if (mu_string_to_syslog_facility (val->v.string, &mu_log_facility))
{
mu_error (_("unknown syslog facility `%s'"), val->v.string);
return 1;
}
return 0;
}
static int
cb_severity (void *data, mu_config_value_t *val)
{
unsigned n;
if (mu_cfg_assert_value_type (val, MU_CFG_STRING))
return 1;
if (mu_severity_from_string (val->v.string, &n))
{
mu_error (_("unknown severity `%s'"), val->v.string);
return 1;
}
mu_log_severity_threshold = n;
return 0;
}
static struct mu_cfg_param mu_logging_param[] = {
{ "syslog", mu_c_bool, &mu_log_syslog, 0, NULL,
N_("Send diagnostics to syslog.") },
{ "print-severity", mu_c_bool, &mu_log_print_severity, 0, NULL,
N_("Print message severity levels.") },
{ "severity", mu_cfg_callback, NULL, 0, cb_severity,
N_("Output only messages with a severity equal to or greater than "
"this one.") },
{ "facility", mu_cfg_callback, NULL, 0, cb_facility,
N_("Set syslog facility. Arg is one of the following: user, daemon, "
"auth, authpriv, mail, cron, local0 through local7 (case-insensitive), "
"or a facility number.") },
{ "session-id", mu_c_bool, &mu_log_session_id, 0, NULL,
N_("Log session ID") },
{ "tag", mu_c_string, &mu_log_tag, 0, NULL,
N_("Tag syslog messages with this string.") },
{ NULL }
};
static int logging_settings; /* Dummy variable */
DCL_CFG_CAPA (logging);
/* ************************************************************************* */
/* Debug */
/* ************************************************************************* */
static int
_cb2_debug_level (const char *arg, void *data MU_ARG_UNUSED)
{
mu_debug_parse_spec (arg);
return 0;
}
static int
cb_debug_level (void *data, mu_config_value_t *val)
{
return mu_cfg_string_value_cb (val, _cb2_debug_level, NULL);
}
static struct mu_cfg_param mu_debug_param[] = {
{ "level", mu_cfg_callback, NULL, 0, &cb_debug_level,
N_("Set Mailutils debugging level. Argument is a colon-separated list "
"of debugging specifications in the form:\n"
" <object: string>[[:]=<level: number>].") },
{ "line-info", mu_c_bool, &debug_settings.line_info, 0, NULL,
N_("Prefix debug messages with Mailutils source locations.") },
{ NULL }
};
DCL_CFG_CAPA (debug);
/* This file is part of GNU Mailutils
Copyright (C) 2007, 2010-2012, 2014-2016 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 the Free Software Foundation; either version 3, or (at
your option) any later version.
GNU Mailutils is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with GNU Mailutils. If not, see <http://www.gnu.org/licenses/>.
*/
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
#include <stdlib.h>
#include "mailutils/libcfg.h"
#include <mailutils/gsasl.h>
static struct mu_gsasl_module_data gsasl_settings;
static struct mu_cfg_param mu_gsasl_param[] = {
{ "enable", mu_c_bool, &gsasl_settings.enable, 0, NULL,
N_("Enable GSASL (default)") },
{ "cram-passwd", mu_c_string, &gsasl_settings.cram_md5_pwd, 0, NULL,
N_("Name of GSASL password file."),
N_("file") },
{ "service", mu_c_string, &gsasl_settings.service, 0, NULL,
N_("SASL service name."),
N_("name") },
{ "realm", mu_c_string, &gsasl_settings.realm, 0, NULL,
N_("SASL realm name."),
N_("name") },
{ "hostname", mu_c_string, &gsasl_settings.hostname, 0, NULL,
N_("SASL host name."),
N_("name") },
{ "anonymous-user", mu_c_string, &gsasl_settings.anon_user, 0, NULL,
N_("Anonymous user name."),
N_("name") },
{ NULL }
};
DCL_CFG_CAPA (gsasl);
/* This file is part of GNU Mailutils
Copyright (C) 2007-2012, 2014-2016 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 the Free Software Foundation; either version 3, or (at
your option) any later version.
GNU Mailutils is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with GNU Mailutils. If not, see <http://www.gnu.org/licenses/>.
*/
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
#define MU_CFG_COMPATIBILITY /* This source uses deprecated cfg interfaces */
#include "mailutils/libcfg.h"
#include <string.h>
#include <stdlib.h>
#define CFG_CAPA_MAX 512
static struct mu_cfg_capa *cfg_capa_table[CFG_CAPA_MAX] = {
#define S(c) &__mu_common_cat3__(mu_,c,_cfg_capa)
S (auth),
S (mailbox),
S (locking),
S (address),
S (mailer),
S (logging),
S (gsasl),
S (pam),
S (radius),
S (sql),
S (tls),
S (virtdomain),
S (sieve),
S (ldap),
S (debug),
NULL
};
static int cfg_capa_index = MU_ARRAY_SIZE(cfg_capa_table) - 1;
static struct mu_cfg_capa *
find_cfg_capa (const char *name)
{
int i;
for (i = 0; cfg_capa_table[i]; i++)
if (strcmp (cfg_capa_table[i]->name, name) == 0)
return cfg_capa_table[i];
return NULL;
}
static int
reserved_name (const char *name)
{
static char *reserved[] = { "common", NULL };
char **p;
if (name[0] == '.')
return 1;
for (p = reserved; *p; p++)
if (strcmp (name, *p) == 0)
return 1;
return 0;
}
int
mu_libcfg_register_capa (struct mu_cfg_capa *capa)
{
if (cfg_capa_index == CFG_CAPA_MAX)
return MU_ERR_NOENT;
cfg_capa_table[cfg_capa_index++] = capa;
return 0;
}
void
mu_libcfg_init (char **cnames)
{
int i;
for (i = 0; cnames[i]; i++)
{
if (!reserved_name (cnames[i]))
{
struct mu_cfg_capa *cp = find_cfg_capa (cnames[i]);
if (cp)
mu_config_root_register_section (NULL, cp->name, NULL,
cp->parser, cp->cfgparam);
#if 0
else
mu_error (_("unknown configuration group requested `%s'"),
cnames[i]);
#endif
}
}
}
int
mu_libcfg_parse_config (mu_cfg_tree_t **ptree)
{
struct mu_cfg_parse_hints hints;
memset (&hints, 0, sizeof (hints));
if (mu_cfg_parser_verbose)
hints.flags |= MU_PARSE_CONFIG_VERBOSE;
if (mu_cfg_parser_verbose > 1)
hints.flags |= MU_PARSE_CONFIG_DUMP;
if (mu_load_site_rcfile)
{
hints.flags |= MU_CFG_PARSE_SITE_RCFILE;
hints.site_rcfile = mu_site_rcfile;
}
if (mu_load_user_rcfile && mu_program_name)
{
hints.flags |= MU_CFG_PARSE_PROGRAM;
hints.program = (char*) mu_program_name;
}
if (mu_load_rcfile)
{
hints.flags |= MU_CFG_PARSE_CUSTOM_RCFILE;
hints.custom_rcfile = mu_load_rcfile;
}
return mu_cfg_parse_config (ptree, &hints);
}
/* FIXME: Deprecated */
int
mu_parse_config_files (struct mu_cfg_param *param, void *target)
{
int flags = 0;
int rc;
if (mu_cfg_parser_verbose)
flags |= MU_PARSE_CONFIG_VERBOSE;
if (mu_cfg_parser_verbose > 1)
flags |= MU_PARSE_CONFIG_DUMP;
if (mu_load_site_rcfile)
{
rc = mu_parse_config (mu_site_rcfile, mu_program_name, param,
flags | MU_PARSE_CONFIG_GLOBAL, target);
if (rc == ENOMEM)
{
mu_error ("%s", mu_strerror (rc));
return rc;
}
}
if (mu_load_user_rcfile && mu_program_name)
{
size_t size = 3 + strlen (mu_program_name) + 1;
char *file_name = malloc (size);
if (file_name)
{
strcpy (file_name, "~/.");
strcat (file_name, mu_program_name);
rc = mu_parse_config (file_name, mu_program_name, param, flags,
target);
if (rc == ENOMEM)
{
mu_error ("%s", mu_strerror (rc));
return rc;
}
free (file_name);
}
}
if (mu_load_rcfile)
{
rc = mu_parse_config (mu_load_rcfile, mu_program_name, param,
flags, target);
if (rc)
{
mu_error (_("errors parsing file %s: %s"), mu_load_rcfile,
mu_strerror (rc));
return rc;
}
}
return 0;
}
/* This file is part of GNU Mailutils
Copyright (C) 2007-2012, 2014-2016 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 the Free Software Foundation; either version 3, or (at
your option) any later version.
GNU Mailutils is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with GNU Mailutils. If not, see <http://www.gnu.org/licenses/>.
*/
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
#include <stdlib.h>
#include "mailutils/libcfg.h"
#include "mailutils/util.h"
#include "mailutils/ldap.h"
static struct mu_ldap_module_config ldap_settings;
static int
_cb2_field_map (const char *arg, void *data)
{
int err;
int rc = mutil_parse_field_map (arg, &ldap_settings.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)
{
return mu_cfg_string_value_cb (val, _cb2_field_map, NULL);
}
static struct mu_cfg_param mu_ldap_param[] = {
{ "enable", mu_c_bool, &ldap_settings.enable, 0, NULL,
N_("Enable LDAP lookups.") },
{ "url", mu_c_string, &ldap_settings.url, 0, NULL,
N_("Set URL of the LDAP server."),
N_("url") },
{ "base", mu_c_string, &ldap_settings.base, 0, NULL,
N_("Base DN for LDAP lookups."),
N_("dn") },
{ "binddn", mu_c_string, &ldap_settings.binddn, 0, NULL,
N_("DN for accessing LDAP database."),
N_("dn") },
{ "passwd", mu_c_string, &ldap_settings.passwd, 0, NULL,
N_("Password for use with binddn.") },
{ "tls", mu_c_bool, &ldap_settings.tls, 0, NULL,
N_("Use TLS encryption.") },
{ "debug", mu_c_int, &ldap_settings.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_settings.getpwnam_filter, 0, NULL,
N_("LDAP filter to use for getpwnam requests."),
N_("filter") },
{ "getpwuid", mu_c_string, &ldap_settings.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_settings.enable = 1;
break;
case mu_cfg_section_end:
mu_gocs_store ("ldap", &ldap_settings);
}
return 0;
}
struct mu_cfg_capa mu_ldap_cfg_capa = {
"ldap", mu_ldap_param, mu_ldap_section_parser
};
/* This file is part of GNU Mailutils
Copyright (C) 2007, 2010-2012, 2014-2016 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 the Free Software Foundation; either version 3, or (at
your option) any later version.
GNU Mailutils is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with GNU Mailutils. If not, see <http://www.gnu.org/licenses/>.
*/
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
#include <stdlib.h>
#include "mailutils/libcfg.h"
static char *pam_settings;
static struct mu_cfg_param mu_pam_param[] = {
{ "service", mu_c_string, &pam_settings, 0, NULL,
N_("Set PAM service name."),
N_("name") },
{ NULL }
};
DCL_CFG_CAPA (pam);
/* This file is part of GNU Mailutils
Copyright (C) 2007, 2010-2012, 2014-2016 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 the Free Software Foundation; either version 3, or (at
your option) any later version.
GNU Mailutils is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with GNU Mailutils. If not, see <http://www.gnu.org/licenses/>.
*/
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
#include <stdlib.h>
#include "mailutils/libcfg.h"
#include <mailutils/radius.h>
static struct mu_radius_module_data radius_settings;
static struct mu_cfg_param mu_radius_param[] = {
{ "auth", mu_c_string, &radius_settings.auth_request, 0, NULL,
N_("Radius request for authorization."),
N_("request") },
{ "getpwnam", mu_c_string, &radius_settings.getpwnam_request, 0, NULL,
N_("Radius request for getpwnam."),
N_("request") },
{ "getpwuid", mu_c_string, &radius_settings.getpwuid_request, 0, NULL,
N_("Radius request for getpwuid."),
N_("request") },
{ "directory", mu_c_string, &radius_settings.config_dir, 0, NULL,
N_("Set radius configuration directory.") },
{ NULL }
};
DCL_CFG_CAPA (radius);