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 1147 additions and 4921 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,93 +56,79 @@ 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") },
static void
set_foreground (struct mu_parseopt *po, struct mu_option *opt,
char const *arg)
{
mu_m_server_set_foreground (server, 1);
}
static void
set_inetd_mode (struct mu_parseopt *po, struct mu_option *opt,
char const *arg)
{
mu_m_server_set_mode (server, MODE_INTERACTIVE);
}
{NULL, 0, NULL, 0, NULL, 0}
};
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)
{
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);
}
}
static void
set_preauth (struct mu_parseopt *po, struct mu_option *opt, char const *arg)
{
preauth_mode = preauth_stdio;
}
static error_t imap4d_parse_opt (int key, char *arg,
struct argp_state *state);
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 },
static struct argp argp = {
options,
imap4d_parse_opt,
NULL,
doc,
NULL,
NULL, NULL
};
{ "test", 0, NULL, MU_OPTION_DEFAULT,
N_("run in test mode"),
mu_c_bool, &test_mode },
static const char *imap4d_capa[] = {
"mailutils",
{ "preauth", 0, NULL, MU_OPTION_DEFAULT,
N_("start in preauth mode"),
mu_c_string, NULL, set_preauth },
MU_OPTION_END
}, *options[] = { imap4d_options, NULL };
static char *capa[] = {
"auth",
"common",
"debug",
"mailbox",
"locking",
"logging",
NULL
};
static error_t
imap4d_parse_opt (int key, char *arg, struct argp_state *state)
{
static mu_list_t lst;
switch (key)
{
case 'd':
mu_argp_node_list_new (lst, "mode", "daemon");
if (arg)
mu_argp_node_list_new (lst, "max-children", arg);
break;
case 'i':
mu_argp_node_list_new (lst, "mode", "inetd");
break;
case OPT_FOREGROUND:
mu_argp_node_list_new (lst, "foreground", "yes");
break;
case OPT_PREAUTH:
preauth_mode = preauth_stdio;
break;
case OPT_TEST_MODE:
mu_argp_node_list_new (lst, "mode", "inetd");
test_mode = 1;
break;
case ARGP_KEY_INIT:
mu_argp_node_list_init (&lst);
break;
case ARGP_KEY_FINI:
mu_argp_node_list_finish (lst, NULL, NULL);
break;
default:
return ARGP_ERR_UNKNOWN;
}
return 0;
}
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,10 +945,16 @@ 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_list;
static mu_list_t module_handler_list;
static void
module_list_init (void)
{
if (!module_list)
{
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);
}
}
void
mu_auth_register_module (struct mu_auth_module *mod)
{
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)
{
mu_error ("not enough memory");
exit (1);
}
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);
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);
}
if (!mu_authenticate_list)
module_list_init ();
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_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_auth_modules);
mu_auth_modules = selected_auth_modules;
selected_auth_modules = 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"
......@@ -85,6 +86,14 @@ extra_help_hook (struct mu_parseopt *po, mu_stream_t stream)
struct mu_cli_setup *setup = hints->data;
mu_stream_printf (stream, "%s\n", _(setup->prog_extra_doc));
}
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,
......@@ -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,7 +356,9 @@ 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]);
......@@ -358,7 +370,7 @@ mu_cli (int argc, char **argv, struct mu_cli_setup *setup, char **capa,
/* Initialize standard capabilities */
mu_cli_capa_init ();
/* Initialize hints */
memset (&hints, 0, sizeof (hints));
hints.flags |= MU_CFG_PARSE_SITE_RCFILE;
......@@ -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;
......@@ -423,6 +436,12 @@ mu_cli (int argc, char **argv, struct mu_cli_setup *setup, char **capa,
po.po_help_hook = extra_help_hook;
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;
......@@ -458,7 +477,7 @@ mu_cli (int argc, char **argv, struct mu_cli_setup *setup, char **capa,
mu_list_foreach (com_list, run_commit, NULL);
mu_list_destroy (&com_list);
if (hints.flags & MU_PARSE_CONFIG_LINT)
exit (0);
......
......@@ -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
......@@ -45,14 +46,28 @@ struct mu_gsasl_module_data mu_gsasl_module_data = {
NULL,
SITE_CRAM_MD5_PWD
};
int
mu_gsasl_module_init (enum mu_gocs_op op, void *data)
{
if (op == mu_gocs_op_set && data)
memcpy (&mu_gsasl_module_data, data, sizeof (mu_gsasl_module_data));
return 0;
}
static struct mu_cfg_param mu_gsasl_param[] = {
{ "enable", mu_c_bool, &mu_gsasl_module_data.enable, 0, NULL,
N_("Enable GSASL (default)") },
{ "cram-passwd", mu_c_string, &mu_gsasl_module_data.cram_md5_pwd, 0, NULL,
N_("Name of GSASL password file."),
N_("file") },
{ "service", mu_c_string, &mu_gsasl_module_data.service, 0, NULL,
N_("SASL service name."),
N_("name") },
{ "realm", mu_c_string, &mu_gsasl_module_data.realm, 0, NULL,
N_("SASL realm name."),
N_("name") },
{ "hostname", mu_c_string, &mu_gsasl_module_data.hostname, 0, NULL,
N_("SASL host name."),
N_("name") },
{ "anonymous-user", mu_c_string, &mu_gsasl_module_data.anon_user, 0, NULL,
N_("Anonymous user name."),
N_("name") },
{ NULL }
};
int
mu_gsasl_enabled (void)
......@@ -231,4 +246,10 @@ mu_gsasl_enabled (void)
{
return 0;
}
#define mu_gsasl_param NULL
#endif
struct mu_auth_module mu_auth_gsasl_module = {
.name = "gsasl",
.cfg = mu_gsasl_param
};
......
......@@ -61,17 +61,82 @@ const char *default_field_map =
static struct mu_ldap_module_config ldap_param;
int
mu_ldap_module_init (enum mu_gocs_op op, void *data)
static int
_cb2_field_map (const char *arg, void *data)
{
int err;
int rc = mutil_parse_field_map (arg, &ldap_param.field_map, &err);
if (rc)
/* FIXME: this message can be misleading */
mu_error (_("error near element %d: %s"), err, mu_strerror (rc));
return 0;
}
static int
cb_field_map (void *data, mu_config_value_t *val)
{
struct mu_ldap_module_config *cfg = data;
return mu_cfg_string_value_cb (val, _cb2_field_map, NULL);
}
if (op != mu_gocs_op_set)
return 0;
if (cfg)
ldap_param = *cfg;
static struct mu_cfg_param mu_ldap_param[] = {
{ "enable", mu_c_bool, &ldap_param.enable, 0, NULL,
N_("Enable LDAP lookups.") },
{ "url", mu_c_string, &ldap_param.url, 0, NULL,
N_("Set URL of the LDAP server."),
N_("url") },
{ "base", mu_c_string, &ldap_param.base, 0, NULL,
N_("Base DN for LDAP lookups."),
N_("dn") },
{ "binddn", mu_c_string, &ldap_param.binddn, 0, NULL,
N_("DN for accessing LDAP database."),
N_("dn") },
{ "passwd", mu_c_string, &ldap_param.passwd, 0, NULL,
N_("Password for use with binddn.") },
{ "tls", mu_c_bool, &ldap_param.tls, 0, NULL,
N_("Use TLS encryption.") },
{ "debug", mu_c_int, &ldap_param.debug, 0, NULL,
N_("Set LDAP debugging level.") },
{ "field-map", mu_cfg_callback, NULL, 0, cb_field_map,
N_("Set a field-map for parsing LDAP replies. The map is a "
"column-separated list of definitions. Each definition has the "
"following form:\n"
" <name: string>=<attr: string>\n"
"where <name> is one of the following: name, passwd, uid, gid, "
"gecos, dir, shell, mailbox, quota, and <attr> is the name of "
"the corresponding LDAP attribute."),
N_("map") },
{ "getpwnam", mu_c_string, &ldap_param.getpwnam_filter, 0, NULL,
N_("LDAP filter to use for getpwnam requests."),
N_("filter") },
{ "getpwuid", mu_c_string, &ldap_param.getpwuid_filter, 0, NULL,
N_("LDAP filter to use for getpwuid requests."),
N_("filter") },
{ NULL }
};
int
mu_ldap_section_parser
(enum mu_cfg_section_stage stage, const mu_cfg_node_t *node,
const char *section_label, void **section_data,
void *call_data, mu_cfg_tree_t *tree)
{
switch (stage)
{
case mu_cfg_section_start:
ldap_param.enable = 1;
break;
default:
break;
}
return 0;
}
static void
module_init (void *ptr)
{
if (ldap_param.enable)
{
if (!ldap_param.getpwnam_filter)
......@@ -85,7 +150,6 @@ mu_ldap_module_init (enum mu_gocs_op op, void *data)
mutil_parse_field_map (default_field_map, &ldap_param.field_map, &d);
}
}
return 0;
}
static int
......@@ -271,8 +335,6 @@ _mu_conn_setup (LDAP **pld)
*pld = ld;
return 0;
}
static int
_mu_ldap_bind (LDAP *ld)
......@@ -862,15 +924,16 @@ mu_auth_ldap_user_by_uid (struct mu_auth_data **return_data,
# define mu_ldap_authenticate mu_auth_nosupport
# define mu_auth_ldap_user_by_name mu_auth_nosupport
# define mu_auth_ldap_user_by_uid mu_auth_nosupport
#endif
struct mu_auth_module mu_auth_ldap_module = {
"ldap",
mu_ldap_module_init,
mu_ldap_authenticate,
NULL,
mu_auth_ldap_user_by_name,
NULL,
mu_auth_ldap_user_by_uid,
NULL
.name = "ldap",
.commit = module_init,
.handler = {
[mu_auth_authenticate] = mu_ldap_authenticate,
[mu_auth_getpwnam] = mu_auth_ldap_user_by_name,
[mu_auth_getpwuid] = mu_auth_ldap_user_by_uid
},
.cfg = mu_ldap_param
};
......
......@@ -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? */
if (!input)
struct mu_locus locus;
if (mu_cfg_assert_value_type (val, MU_CFG_STRING))
return 1;
ws.ws_delim = ",";
if (mu_wordsplit (input, &ws,
if (mu_wordsplit (val->v.string, &ws,
MU_WRDSF_DEFFLAGS|MU_WRDSF_DELIM|MU_WRDSF_RETURN_DELIMS))
{
mu_error (_("cannot parse input `%s': %s"), input,
mu_error (_("cannot parse input `%s': %s"), val->v.string,
mu_wordsplit_strerror (&ws));
return 1;
}
loc.file = "<configuration>"; /*FIXME*/
loc.line = 0;
if (mu_stream_ioctl (mu_strerr, MU_IOCTL_LOGSTREAM,
MU_IOCTL_LOGSTREAM_GET_LOCUS,
&locus) == 0)
{
loc.file = locus.mu_file;
loc.line = locus.mu_line;
}
else
{
loc.file = "<unknown>";
loc.line = 0;
}
for (i = 0, state = state_lhs; i < ws.ws_wordc; i++)
{
......@@ -121,7 +134,7 @@ parse_pairlist (grad_avp_t **plist, char *input)
break;
case state_op:
op = ws.ws_wordv[i];
//op = ws.ws_wordv[i];
state = state_rhs;
break;
......@@ -155,16 +168,45 @@ parse_pairlist (grad_avp_t **plist, char *input)
return 1;
}
return 0;
}
static int
cb_config_dir (void *data, mu_config_value_t *val)
{
if (mu_cfg_assert_value_type (val, MU_CFG_STRING))
return 1;
grad_config_dir = grad_estrdup (val->v.string);
return 0;
}
static struct mu_cfg_param mu_radius_param[] = {
{ "auth", mu_cfg_callback, &auth_request, 0, cb_request,
N_("Radius request for authorization."),
N_("request: string") },
{ "getpwnam", mu_cfg_callback, &getpwnam_request, 0, cb_request,
N_("Radius request for getpwnam."),
N_("request: string") },
{ "getpwuid", mu_cfg_callback, &getpwuid_request, 0, cb_request,
N_("Radius request for getpwuid."),
N_("request: string") },
{ "directory", mu_cfg_callback, NULL, 0, cb_config_dir,
N_("Set radius configuration directory.") },
{ NULL }
};
struct mu_cli_capa mu_cli_capa_radius = {
"radius",
NULL,
mu_radius_param
};
/* Assume radius support is needed if any of the above requests is
defined. Actually, all of them should be, but it is the responsibility
of init to check for consistency of the configuration */
#define NEED_RADIUS_P(cfg) \
((cfg) && \
((cfg)->auth_request || (cfg)->getpwnam_request || (cfg)->getpwuid_request))
#define NEED_RADIUS_P() \
(auth_request || getpwnam_request || getpwuid_request)
static void
mu_grad_logger(int level,
......@@ -196,21 +238,16 @@ mu_grad_logger(int level,
}
mu_diag_voutput (mlevel[level & GRAD_LOG_PRIMASK], pfx ? pfx : fmt, ap);
if (pfx)
free(pfx);
free (pfx);
}
int
mu_radius_module_init (enum mu_gocs_op op, void *data)
static void
module_init (void *ptr)
{
struct mu_radius_module_data *cfg = data;
if (op != mu_gocs_op_set)
return 0;
if (!NEED_RADIUS_P (cfg))
return 0;
if (!NEED_RADIUS_P ())
return;
grad_set_logger (mu_grad_logger);
grad_config_dir = grad_estrdup (cfg->config_dir);
grad_path_init ();
srand (time (NULL) + getpid ());
......@@ -218,7 +255,7 @@ mu_radius_module_init (enum mu_gocs_op op, void *data)
if (grad_dict_init ())
{
mu_error (_("cannot read radius dictionaries"));
return 1;
return;
}
/* Check whether mailutils attributes are defined */
......@@ -229,16 +266,9 @@ mu_radius_module_init (enum mu_gocs_op op, void *data)
|| get_attribute (&MU_Dir, "MU-Dir")
|| get_attribute (&MU_Shell, "MU-Shell")
|| get_attribute (&MU_Mailbox, "MU-Mailbox"))
return 1;
/* Parse saved requests */
if (parse_pairlist (&auth_request, cfg->auth_request)
|| parse_pairlist (&getpwnam_request, cfg->getpwnam_request)
|| parse_pairlist (&getpwuid_request, cfg->getpwuid_request))
return 1;
return;
radius_auth_enabled = 1;
return 0;
}
static char *
......@@ -518,44 +548,19 @@ mu_auth_radius_user_by_uid (struct mu_auth_data **return_data,
return rc;
}
#else
static int
mu_radius_authenticate (struct mu_auth_data **return_data MU_ARG_UNUSED,
const void *key,
void *func_data MU_ARG_UNUSED, void *call_data)
{
return ENOSYS;
}
static int
mu_auth_radius_user_by_name (struct mu_auth_data **return_data MU_ARG_UNUSED,
const void *key MU_ARG_UNUSED,
void *func_data MU_ARG_UNUSED,
void *call_data MU_ARG_UNUSED)
{
return ENOSYS;
}
static int
mu_auth_radius_user_by_uid (struct mu_auth_data **return_data,
const void *key,
void *func_data, void *call_data)
{
return ENOSYS;
}
#endif
struct mu_auth_module mu_auth_radius_module = {
"radius",
#ifdef ENABLE_RADIUS
mu_radius_module_init,
.name = "radius",
.cfg = mu_radius_param,
.commit = module_init,
.handler = {
[mu_auth_authenticate] = mu_radius_authenticate,
[mu_auth_getpwnam] = mu_auth_radius_user_by_name,
[mu_auth_getpwuid] = mu_auth_radius_user_by_uid
}
};
#else
NULL,
#endif
mu_radius_authenticate,
NULL,
mu_auth_radius_user_by_name,
NULL,
mu_auth_radius_user_by_uid,
NULL
struct mu_auth_module mu_auth_radius_module = {
.name = "radius"
};
#endif
......
......@@ -50,12 +50,97 @@
#include <mailutils/sql.h>
#include <mailutils/cstr.h>
#include <mailutils/wordsplit.h>
#include <mailutils/cli.h>
#include "sql.h"
#ifdef USE_SQL
struct mu_internal_sql_config mu_sql_module_config;
struct mu_sql_module_config mu_sql_module_config;
/* Resource file configuration */
static int
cb_password_type (void *data, mu_config_value_t *val)
{
if (mu_cfg_assert_value_type (val, MU_CFG_STRING))
return 1;
if (mu_sql_decode_password_type (val->v.string, &mu_sql_module_config.password_type))
mu_error (_("unknown password type `%s'"), val->v.string);
return 0;
}
static int
_cb2_field_map (const char *arg, void *data)
{
int err;
int rc = mutil_parse_field_map (arg, &mu_sql_module_config.field_map, &err);
if (rc)
/* FIXME: this message may be misleading */
mu_error (_("error near element %d: %s"), err, mu_strerror (rc));
return 0;
}
static int
cb_field_map (void *data, mu_config_value_t *val)
{
return mu_cfg_string_value_cb (val, _cb2_field_map, NULL);
}
static int
cb_interface (void *data, mu_config_value_t *val)
{
if (mu_cfg_assert_value_type (val, MU_CFG_STRING))
return 1;
mu_sql_module_config.interface = mu_sql_interface_index (val->v.string);
if (mu_sql_module_config.interface == 0)
{
mu_error (_("unknown SQL interface `%s'"), val->v.string);
return 1;
}
return 0;
}
static struct mu_cfg_param mu_sql_param[] = {
{ "interface", mu_cfg_callback, &mu_sql_module_config.interface, 0,
cb_interface,
N_("Set SQL interface to use."),
N_("iface: mysql|odbc|postgres") },
{ "getpwnam", mu_c_string, &mu_sql_module_config.getpwnam_query, 0, NULL,
N_("SQL query to use for getpwnam requests."),
N_("query") },
{ "getpwuid", mu_c_string, &mu_sql_module_config.getpwuid_query, 0, NULL,
N_("SQL query to use for getpwuid requests."),
N_("query") },
{ "getpass", mu_c_string, &mu_sql_module_config.getpass_query, 0, NULL,
N_("SQL query returning the user's password."),
N_("query") },
{ "host", mu_c_string, &mu_sql_module_config.host, 0, NULL,
N_("SQL server host name.") },
{ "user", mu_c_string, &mu_sql_module_config.user, 0, NULL,
N_("SQL user name.") },
{ "passwd", mu_c_string, &mu_sql_module_config.passwd, 0, NULL,
N_("Password for the SQL user.") },
{ "port", mu_c_int, &mu_sql_module_config.port, 0, NULL,
N_("SQL server port.") },
{ "db", mu_c_string, &mu_sql_module_config.db, 0, NULL,
N_("Database name.") },
{ "password-type", mu_cfg_callback, NULL, 0, cb_password_type,
N_("Type of password returned by getpass query (one of: plain, hash, "
"scrambled).") },
{ "positional", mu_c_bool, &mu_sql_module_config.positional, 0, NULL,
N_("Use positional (v1.0 compatible) field interface.") },
{ "field-map", mu_cfg_callback, NULL, 0, cb_field_map,
N_("Set a field-map for parsing SQL replies. The map is a "
"column-separated list of definitions. Each definition has the "
"following form:\n"
" <name: string>=<column: string>\n"
"where <name> is one of the following: name, passwd, uid, gid, "
"gecos, dir, shell, mailbox, quota, and <column> is the name of "
"the corresponding SQL column."),
N_("map") },
{ NULL }
};
static char *
sql_escape_string (const char *ustr)
{
......@@ -668,55 +753,22 @@ mu_sql_authenticate (struct mu_auth_data **return_data MU_ARG_UNUSED,
return rc == 0 ? 0 : MU_ERR_AUTH_FAILURE;
}
int
mu_sql_module_init (enum mu_gocs_op op, void *data)
{
struct mu_sql_module_config *cfg = data;
if (op != mu_gocs_op_set)
return 0;
mu_sql_module_config.interface = mu_sql_interface_index (cfg->interface);
if (mu_sql_module_config.interface == 0)
{
mu_error (_("unknown SQL interface `%s'"), cfg->interface);
return 1;
}
mu_sql_module_config.getpwnam_query = cfg->getpwnam_query;
mu_sql_module_config.getpass_query = cfg->getpass_query;
mu_sql_module_config.getpwuid_query = cfg->getpwuid_query;
mu_sql_module_config.host = cfg->host;
mu_sql_module_config.user = cfg->user;
mu_sql_module_config.passwd = cfg->passwd;
mu_sql_module_config.db = cfg->db;
mu_sql_module_config.port = cfg->port;
mu_sql_module_config.password_type = cfg->password_type;
mu_sql_module_config.field_map = cfg->field_map;
return 0;
}
#else
# define mu_sql_authenticate mu_auth_nosupport
# define mu_auth_sql_by_name mu_auth_nosupport
# define mu_auth_sql_by_uid mu_auth_nosupport
# define mu_sql_param NULL
#endif
struct mu_auth_module mu_auth_sql_module = {
"sql",
#ifdef USE_SQL
mu_sql_module_init,
#else
NULL,
#endif
mu_sql_authenticate,
NULL,
mu_auth_sql_by_name,
NULL,
mu_auth_sql_by_uid,
NULL
.name = "sql",
.cfg = mu_sql_param,
.handler = {
[mu_auth_authenticate] = mu_sql_authenticate,
[mu_auth_getpwnam] = mu_auth_sql_by_name,
[mu_auth_getpwuid] = mu_auth_sql_by_uid
}
};
......
......@@ -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,22 +53,20 @@
#include <mailutils/nls.h>
#include <mailutils/errno.h>
#include <mailutils/util.h>
#include <mailutils/cli.h>
#ifdef ENABLE_VIRTUAL_DOMAINS
struct mu_gocs_virtual mu_virtual_module_config = { SITE_VIRTUAL_PWDDIR };
int
mu_virtual_module_init (enum mu_gocs_op op, void *data)
{
if (op == mu_gocs_op_set && data)
{
struct mu_gocs_virtual *p = data;
mu_virtual_module_config = *p;
}
return 0;
}
static char *pwddir = { SITE_VIRTUAL_PWDDIR };
static struct mu_cfg_param mu_virtdomain_param[] = {
{ "passwd-dir", mu_c_string, &pwddir, 0, NULL,
N_("Name of the directory where virtual domain password files are "
"located."),
N_("dir") },
{ NULL }
};
#if !HAVE_FGETPWENT
/* FIXME: A temporary solution. Need proper declaration in .h */
extern struct passwd *mu_fgetpwent (FILE *fp);
......@@ -90,7 +88,7 @@ getpwnam_virtual (const char *u)
if (delim == 0)
return NULL;
filename = mu_make_file_name (mu_virtual_module_config.pwddir, &u[delim + 1]);
filename = mu_make_file_name (pwddir, &u[delim + 1]);
if (filename == NULL)
return NULL;
......@@ -191,28 +189,15 @@ mu_auth_virt_domain_by_name (struct mu_auth_data **return_data,
}
#else
static int
mu_auth_virt_domain_by_name (struct mu_auth_data **return_data MU_ARG_UNUSED,
const void *key MU_ARG_UNUSED,
void *func_data MU_ARG_UNUSED,
void *call_data MU_ARG_UNUSED)
{
return ENOSYS;
}
# define mu_virtdomain_param NULL
# define mu_auth_virt_domain_by_name NULL
#endif
struct mu_auth_module mu_auth_virtual_module = {
"virtdomain",
#ifdef ENABLE_VIRTUAL_DOMAINS
mu_virtual_module_init,
#else
NULL,
#endif
mu_auth_nosupport,
NULL,
mu_auth_virt_domain_by_name,
NULL,
mu_auth_nosupport,
NULL
.name = "virtdomain",
.cfg = mu_virtdomain_param,
.handler = {
[mu_auth_getpwnam] = mu_auth_virt_domain_by_name,
}
};
......
*.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);
/* 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 <stdlib.h>
#include "mailutils/libcfg.h"
#include <mailutils/sieve.h>
static struct mu_gocs_sieve sieve_settings;
static int
cb_clear_library_path (void *data, mu_config_value_t *val)
{
int flag;
if (mu_cfg_assert_value_type (val, MU_CFG_STRING))
return 1;
if (mu_str_to_c (val->v.string, mu_c_bool, &flag, NULL))
{
mu_error (_("not a boolean"));
return 1;
}
if (flag)
sieve_settings.clearflags |= MU_SIEVE_CLEAR_LIBRARY_PATH;
return 0;
}
static int
cb_clear_include_path (void *data, mu_config_value_t *val)
{
int flag;
if (mu_cfg_assert_value_type (val, MU_CFG_STRING))
return 1;
if (mu_str_to_c (val->v.string, mu_c_bool, &flag, NULL))
{
mu_error (_("not a boolean"));
return 1;
}
if (flag)
sieve_settings.clearflags |= MU_SIEVE_CLEAR_INCLUDE_PATH;
return 0;
}
static int
_add_path (const char *arg, void *data)
{
mu_list_t *plist = data;
if (!*plist)
{
int rc = mu_list_create (plist);
if (rc)
{
mu_error (_("cannot create list: %s"), mu_strerror (rc));
exit (1);
}
mu_list_set_destroy_item (*plist, mu_list_free_item);
}
return mu_string_split (arg, ":", *plist);
}
static int
cb_include_path (void *data, mu_config_value_t *val)
{
return mu_cfg_string_value_cb (val, _add_path,
&sieve_settings.include_path);
}
static int
cb_library_path (void *data, mu_config_value_t *val)
{
return mu_cfg_string_value_cb (val, _add_path,
&sieve_settings.library_path);
}
static int
cb_library_path_prefix (void *data, mu_config_value_t *val)
{
return mu_cfg_string_value_cb (val, _add_path,
&sieve_settings.library_path_prefix);
}
static struct mu_cfg_param mu_sieve_param[] = {
{ "clear-library-path", mu_cfg_callback, NULL, 0, cb_clear_library_path,
N_("Clear library search path.") },
{ "clear-include-path", mu_cfg_callback, NULL, 0, cb_clear_include_path,
N_("Clear include search path.") },
{ "library-path", mu_cfg_callback, NULL, 0, cb_library_path,
N_("Add directories to the library search path. Argument is a "
"colon-separated list of directories."),
N_("list") },
{ "library-path-prefix", mu_cfg_callback, NULL, 0, cb_library_path_prefix,
N_("Add directories to the beginning of the library search path. "
"Argument is a colon-separated list of directories."),
N_("list") },
{ "include-path", mu_cfg_callback, NULL, 0, cb_include_path,
N_("Add directories to the include search path. Argument is a "
"colon-separated list of directories."),
N_("list") },
{ NULL }
};
DCL_CFG_CAPA (sieve);
/* 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/sql.h>
#include <mailutils/util.h>
static struct mu_sql_module_config sql_settings;
/* 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, &sql_settings.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, &sql_settings.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 struct mu_cfg_param mu_sql_param[] = {
{ "interface", mu_c_string, &sql_settings.interface, 0, NULL,
N_("Set SQL interface to use (one of: mysql, odbc, or postgres).") },
{ "getpwnam", mu_c_string, &sql_settings.getpwnam_query, 0, NULL,
N_("SQL query to use for getpwnam requests."),
N_("query") },
{ "getpwuid", mu_c_string, &sql_settings.getpwuid_query, 0, NULL,
N_("SQL query to use for getpwuid requests."),
N_("query") },
{ "getpass", mu_c_string, &sql_settings.getpass_query, 0, NULL,
N_("SQL query returning the user's password."),
N_("query") },
{ "host", mu_c_string, &sql_settings.host, 0, NULL,
N_("SQL server host name.") },
{ "user", mu_c_string, &sql_settings.user, 0, NULL,
N_("SQL user name.") },
{ "passwd", mu_c_string, &sql_settings.passwd, 0, NULL,
N_("Password for the SQL user.") },
{ "port", mu_c_int, &sql_settings.port, 0, NULL,
N_("SQL server port.") },
{ "db", mu_c_string, &sql_settings.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, &sql_settings.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 }
};
DCL_CFG_CAPA (sql);
/* 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 <stdlib.h>
#include "mailutils/libcfg.h"
#include <mailutils/tls.h>
#include <mailutils/util.h>
#include <mailutils/kwd.h>
#define SSL_CERT_FILE_CHECKS (MU_FILE_SAFETY_GROUP_WRITABLE | \
MU_FILE_SAFETY_GROUP_WRITABLE | \
MU_FILE_SAFETY_LINKED_WRDIR)
#define SSL_KEY_FILE_CHECKS (MU_FILE_SAFETY_ALL & ~MU_FILE_SAFETY_OWNER_MISMATCH)
#define SSL_CA_FILE_CHECKS (MU_FILE_SAFETY_GROUP_WRITABLE | \
MU_FILE_SAFETY_GROUP_WRITABLE | \
MU_FILE_SAFETY_LINKED_WRDIR)
static struct mu_tls_module_config tls_settings = {
1, /* enabled by default */
NULL, /* Certificate file */
SSL_CERT_FILE_CHECKS,
NULL, /* Key file */
SSL_KEY_FILE_CHECKS, /* Stringent safety checks for keys */
NULL, /* CA file */
SSL_CA_FILE_CHECKS
};
static int
cb2_safety_checks (const char *name, void *data)
{
int defval;
if (data == &tls_settings.ssl_key_safety_checks)
defval = SSL_KEY_FILE_CHECKS;
else if (data == &tls_settings.ssl_cert_safety_checks)
defval = SSL_CERT_FILE_CHECKS;
else if (data == &tls_settings.ssl_cafile_safety_checks)
defval = SSL_CA_FILE_CHECKS;
else
{
mu_error (_("INTERNAL ERROR at %s:%d: unknown default value?"),
__FILE__, __LINE__);
defval = MU_FILE_SAFETY_ALL;
}
if (mu_file_safety_compose (data, name, defval))
mu_error (_("unknown keyword: %s"), name);
return 0;
}
static int
cb_safety_checks (void *data, mu_config_value_t *arg)
{
return mu_cfg_string_value_cb (arg, cb2_safety_checks, data);
}
static struct mu_cfg_param mu_tls_param[] = {
{ "enable", mu_c_bool, &tls_settings.enable, 0, NULL,
N_("Enable TLS encryption.") },
{ "ssl-cert", mu_c_string, &tls_settings.ssl_cert, 0, NULL,
N_("Specify SSL certificate file."),
N_("file") },
{ "ssl-key", mu_c_string, &tls_settings.ssl_key, 0, NULL,
N_("Specify SSL certificate key file."),
N_("file") },
{ "ssl-cafile", mu_c_string, &tls_settings.ssl_cafile, 0, NULL,
N_("Specify trusted CAs file."),
N_("file") },
{ "ssl-priorities", mu_c_string, &tls_settings.priorities, 0, NULL,
N_("Set the priorities to use on the ciphers, key exchange methods, "
"macs and compression methods."),
NULL },
{ "key-file-safety-checks", mu_cfg_callback,
&tls_settings.ssl_key_safety_checks, 0,
cb_safety_checks,
N_("Configure safety checks for SSL key file. Argument is a list or "
"sequence of check names optionally prefixed with '+' to enable or "
"'-' to disable the corresponding check. Valid check names are:\n"
"\n"
" none disable all checks\n"
" all enable all checks\n"
" gwrfil forbid group writable files\n"
" awrfil forbid world writable files\n"
" grdfil forbid group readable files\n"
" ardfil forbid world writable files\n"
" linkwrdir forbid symbolic links in group or world writable directories\n"
" gwrdir forbid files in group writable directories\n"
" awrdir forbid files in world writable directories\n"),
N_("arg: list") },
{ "cert-file-safety-checks", mu_cfg_callback,
&tls_settings.ssl_cert_safety_checks, 0,
cb_safety_checks,
N_("Configure safety checks for SSL certificate. See above for a description of <arg>."),
N_("arg: list") },
{ "ca-file-safety-checks", mu_cfg_callback,
&tls_settings.ssl_cafile_safety_checks, 0,
cb_safety_checks,
N_("Configure safety checks for SSL certificate authority file. See above for a description of <arg>."),
N_("arg: list") },
{ NULL }
};
DCL_CFG_CAPA (tls);
/* 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 struct mu_gocs_virtual virtdomain_settings;
static struct mu_cfg_param mu_virtdomain_param[] = {
{ "passwd-dir", mu_c_string, &virtdomain_settings, 0, NULL,
N_("Name of the directory where virtual domain password files are "
"located."),
N_("dir") },
{ NULL }
};
DCL_CFG_CAPA (virtdomain);
......@@ -29,9 +29,6 @@ mu_list_t mu_sieve_library_path = NULL;
mu_list_t mu_sieve_library_path_prefix = NULL;
mu_debug_handle_t mu_sieve_debug_handle;
//FIXME: provide definition (from gocs.h)
static struct mu_gocs_sieve sieve_settings;
void
mu_sieve_debug_init (void)
{
......@@ -39,6 +36,15 @@ mu_sieve_debug_init (void)
mu_sieve_debug_handle = mu_debug_register_category ("sieve");
}
struct sieve_settings
{
int clearflags;
mu_list_t include_path;
mu_list_t library_path_prefix;
mu_list_t library_path;
};
static struct sieve_settings sieve_settings;
/*FIXME: REMOVE BEGIN */
static int
_path_append (void *item, void *data)
......@@ -61,33 +67,6 @@ _path_append (void *item, void *data)
return mu_list_append (*plist, p);
}
int
mu_sieve_module_init (enum mu_gocs_op op, void *data)
{
struct mu_gocs_sieve *p;
if (!(op == mu_gocs_op_set && data))
return 0;
p = data;
if (p->clearflags & MU_SIEVE_CLEAR_INCLUDE_PATH)
mu_list_destroy (&mu_sieve_include_path);
mu_list_foreach (p->include_path, _path_append, &mu_sieve_include_path);
if (p->clearflags & MU_SIEVE_CLEAR_LIBRARY_PATH)
{
mu_list_destroy (&mu_sieve_library_path);
mu_list_destroy (&mu_sieve_library_path_prefix);
}
mu_list_foreach (p->library_path_prefix, _path_append,
&mu_sieve_library_path_prefix);
mu_list_foreach (p->library_path, _path_append, &mu_sieve_library_path);
mu_list_destroy (&p->library_path);
mu_list_destroy (&p->library_path_prefix);
mu_list_destroy (&p->include_path);
mu_sieve_debug_init ();
return 0;
}
/* FIXME: REMOVE END */
static int
cb_clear_library_path (void *data, mu_config_value_t *val)
{
......@@ -238,9 +217,30 @@ static struct mu_option sieve_option[] = {
MU_OPTION_END
};
static void
sieve_commit (void *ptr)
{
if (sieve_settings.clearflags & MU_SIEVE_CLEAR_INCLUDE_PATH)
mu_list_destroy (&mu_sieve_include_path);
mu_list_foreach (sieve_settings.include_path, _path_append, &mu_sieve_include_path);
if (sieve_settings.clearflags & MU_SIEVE_CLEAR_LIBRARY_PATH)
{
mu_list_destroy (&mu_sieve_library_path);
mu_list_destroy (&mu_sieve_library_path_prefix);
}
mu_list_foreach (sieve_settings.library_path_prefix, _path_append,
&mu_sieve_library_path_prefix);
mu_list_foreach (sieve_settings.library_path, _path_append, &mu_sieve_library_path);
mu_list_destroy (&sieve_settings.library_path);
mu_list_destroy (&sieve_settings.library_path_prefix);
mu_list_destroy (&sieve_settings.include_path);
mu_sieve_debug_init ();
}
struct mu_cli_capa mu_cli_capa_sieve = {
"sieve",
sieve_option,
mu_sieve_param,
NULL, NULL
NULL,
sieve_commit
};
......
......@@ -270,7 +270,6 @@ static char *capa[] = {
"locking",
"mailer",
"sieve",
"tls",
NULL
};
......@@ -553,7 +552,7 @@ main (int argc, char *argv[])
mu_log_print_severity = 1;
/* Parse command line */
mu_cli_capa_register (&mu_cli_capa_tls);
mu_cli_capa_register (&mu_cli_capa_sieve);
mu_cli (argc, argv, &cli, capa, NULL, &argc, &argv);
......
......@@ -17,6 +17,7 @@
#include "mail.h"
#include "mailutils/cli.h"
#include "mailutils/mu_auth.h"
/* Global variables and constants*/
mu_mailbox_t mbox; /* Mailbox being operated upon */
......@@ -240,7 +241,6 @@ static char *mail_capa[] = {
"debug",
"mailbox",
"locking",
"tls",
NULL
};
......@@ -368,6 +368,8 @@ main (int argc, char **argv)
/* Register the desired formats. */
mu_register_all_formats ();
mu_auth_register_module (&mu_auth_tls_module);
interactive = isatty (fileno (stdin));
#ifdef HAVE_SIGACTION
{
......@@ -417,7 +419,6 @@ main (int argc, char **argv)
MOPTF_OVERWRITE);
/* argument parsing */
mu_cli_capa_register (&mu_cli_capa_tls);
mu_cli (argc, argv, &cli, mail_capa, NULL, &argc, &argv);
if ((hint & (HINT_SEND_MODE|HINT_FILE_OPTION)) ==
......
......@@ -41,7 +41,6 @@ static char *capa[] = {
"debug",
"mailbox",
"locking",
"tls",
NULL
};
......@@ -65,7 +64,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 == 0 && messages_count (NULL) < 0)
......
......@@ -843,10 +843,10 @@ main (int argc, char **argv)
/* Register the desired "mailbox" formats. */
mu_register_all_formats ();
/* argument parsing */
/* Register authentication modules */
mu_auth_register_module (&mu_auth_tls_module);
mu_cli_capa_register (&mu_cli_capa_tls);
/* argument parsing */
mu_cli (argc, argv, &cli, movemail_capa, NULL, &argc, &argv);
if (argc < 2 || argc > 3)
......
......@@ -75,7 +75,7 @@ mailutils_SOURCES = \
$(MODULES)
mailutils_LDADD = \
${MU_APP_LIBRARIES}\
${MU_APP_NEW_LIBRARIES}\
${MU_LIB_MBOX}\
${MU_LIB_IMAP}\
${MU_LIB_POP}\
......
......@@ -14,63 +14,24 @@
You should have received a copy of the GNU General Public License
along with GNU Mailutils. If not, see <http://www.gnu.org/licenses/>. */
#if defined(HAVE_CONFIG_H)
# include <config.h>
#endif
#include <stdlib.h>
#include <string.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <sys/un.h>
#include <arpa/inet.h>
#include <mailutils/mailutils.h>
#include <mailutils/libcfg.h>
#include "argp.h"
#include "mu.h"
static char acl_doc[] = N_("mu acl - test access control lists.");
char acl_docstring[] = N_("test access control lists");
static char acl_args_doc[] = N_("ADDRESS [ADDRESS...]");
static struct argp_option acl_options[] = {
{ "file", 'f', N_("FILE"), 0, N_("read ACLs from FILE") },
{ "path", 'p', N_("PATH"), 0,
N_("path to the ACL in the configuration tree") },
{ NULL }
};
static char *input_file_name;
static struct mu_sockaddr *target_sa;
static mu_acl_t acl;
static const char *path = "acl";
static error_t
acl_parse_opt (int key, char *arg, struct argp_state *state)
{
switch (key)
{
case 'f':
input_file_name = arg;
break;
case 'p':
path = arg;
break;
default:
return ARGP_ERR_UNKNOWN;
}
return 0;
}
static struct argp acl_argp = {
acl_options,
acl_parse_opt,
acl_args_doc,
acl_doc,
NULL,
NULL,
NULL
static struct mu_option acl_options[] = {
{ "file", 'f', N_("FILE"), MU_OPTION_DEFAULT,
N_("read ACLs from FILE"),
mu_c_string, &input_file_name },
{ "path", 'p', N_("PATH"), MU_OPTION_DEFAULT,
N_("path to the ACL in the configuration tree"),
mu_c_string, &path },
{ NULL }
};
......@@ -82,16 +43,13 @@ static struct mu_cfg_param acl_cfg_param[] = {
int
mutool_acl (int argc, char **argv)
{
int rc, index;
int rc;
mu_acl_result_t result;
mu_cfg_tree_t *tree = NULL, *temp_tree = NULL;
mu_cfg_node_t *node;
if (argp_parse (&acl_argp, argc, argv, ARGP_IN_ORDER, &index, NULL))
return 1;
struct mu_cfg_parse_hints hints;
argc -= index;
argv += index;
mu_action_getopt (&argc, &argv, acl_options, acl_docstring, acl_args_doc);
if (argc == 0)
{
......@@ -99,16 +57,13 @@ mutool_acl (int argc, char **argv)
return 1;
}
if (input_file_name)
{
mu_load_site_rcfile = 0;
mu_load_user_rcfile = 0;
mu_load_rcfile = input_file_name;
}
memset (&hints, 0, sizeof (hints));
hints.flags = MU_CFG_PARSE_CUSTOM_RCFILE;
hints.custom_rcfile = input_file_name;
mu_acl_cfg_init ();
if (mu_libcfg_parse_config (&tree))
return 1;
if (mu_cfg_parse_config (&tree, &hints))
exit (EX_CONFIG);
if (!tree)
return 0;
......
......@@ -14,32 +14,19 @@
You should have received a copy of the GNU General Public License
along with GNU Mailutils. If not, see <http://www.gnu.org/licenses/>. */
#if defined(HAVE_CONFIG_H)
# include <config.h>
#endif
#include <stdlib.h>
#include <mailutils/mailutils.h>
#include <mailutils/libcfg.h>
#include <argp.h>
static char cflags_doc[] = N_("mu cflags - show compiler options");
char cflags_docstring[] = N_("show compiler options");
#include "mu.h"
static struct argp cflags_argp = {
NULL,
NULL,
NULL,
cflags_doc,
NULL,
NULL,
NULL
};
char cflags_docstring[] = N_("show compiler options");
int
mutool_cflags (int argc, char **argv)
{
if (argp_parse (&cflags_argp, argc, argv, ARGP_IN_ORDER, NULL, NULL))
return 1;
mu_action_getopt (&argc, &argv, NULL, cflags_docstring, NULL);
if (argc)
{
mu_error (_("too many arguments"));
return EX_USAGE;
}
mu_printf ("%s\n", COMPILE_FLAGS);
return 0;
}
......
......@@ -14,21 +14,12 @@
You should have received a copy of the GNU General Public License
along with GNU Mailutils. If not, see <http://www.gnu.org/licenses/>. */
#if defined(HAVE_CONFIG_H)
# include <config.h>
#endif
#include <sys/types.h>
#include <sys/stat.h>
#include <stdlib.h>
#include <string.h>
#include <grp.h>
#include <sysexits.h>
#include "mu.h"
#include <mailutils/dbm.h>
#include <fnmatch.h>
#include <regex.h>
#include <mailutils/mailutils.h>
#include <mailutils/dbm.h>
#include "argp.h"
#include "mu.h"
#include <sys/stat.h>
#include <grp.h>
static char dbm_doc[] = N_("mu dbm - DBM management tool\n"
"Valid COMMANDs are:\n"
......@@ -39,6 +30,7 @@ static char dbm_doc[] = N_("mu dbm - DBM management tool\n"
" delete - delete specified keys from the database\n"
" add - add records to the database\n"
" replace - add records replacing ones with matching keys\n");
char dbm_docstring[] = N_("DBM management tool");
static char dbm_args_doc[] = N_("COMMAND FILE [KEY...]");
......@@ -1603,154 +1595,161 @@ delete_database (int argc, char **argv)
mu dbm --replace a.db < input
*/
static struct argp_option dbm_options[] = {
{ NULL, 0, NULL, 0, N_("Create Options"), 0},
{ "file", 'f', N_("FILE"), 0,
N_("read input from FILE (with create, delete, add and replace)") },
{ "permissions", 'p', N_("NUM"), 0,
N_("set permissions on the created database") },
{ "user", 'u', N_("USER"), 0,
N_("set database owner name") },
{ "group", 'g', N_("GROUP"), 0,
N_("set database owner group") },
{ "copy-permissions", 'P', NULL, 0,
N_("copy database permissions and ownership from the input file") },
{ "ignore-meta", 'm', NULL, 0,
N_("ignore meta-information from input file headers") },
{ "ignore-directives", 'I', N_("NAMES"), 0,
N_("ignore the listed directives") },
{ NULL, 0, NULL, 0, N_("List and Dump Options"), 0},
{ "format", 'H', N_("TYPE"), 0,
N_("select output format") },
{ "no-header", 'q', NULL, 0,
N_("suppress format header") },
{ NULL, 0, NULL, 0, N_("List, Dump and Delete Options"), 0},
{ "glob", 'G', NULL, 0,
N_("treat keys as globbing patterns") },
{ "regex", 'R', NULL, 0,
N_("treat keys as regular expressions") },
{ "ignore-case", 'i', NULL, 0,
N_("case-insensitive matches") },
{ NULL, 0, NULL, 0, N_("Options for Use with Format 0.0"), 0 },
{ "count-null", 'N', NULL, 0,
N_("data length accounts for terminating zero") },
{ "no-count-null", 'n', NULL, 0,
N_("data length does not account for terminating zero") },
{ NULL }
};
static error_t
dbm_parse_opt (int key, char *arg, struct argp_state *state)
static void
set_permissions (struct mu_parseopt *po, struct mu_option *opt, char const *arg)
{
switch (key)
char *p;
unsigned long d = strtoul (arg, &p, 8);
if (*p || (d & ~0777))
{
case 'f':
input_file = arg;
break;
case 'H':
select_format (arg);
break;
case 'p':
{
char *p;
unsigned long d = strtoul (arg, &p, 8);
if (*p || (d & ~0777))
argp_error (state, _("invalid file mode: %s"), arg);
file_mode = d;
known_meta_data |= META_FILE_MODE;
}
break;
mu_parseopt_error (po, _("invalid file mode: %s"), arg);
exit (po->po_exit_error);
}
file_mode = d;
known_meta_data |= META_FILE_MODE;
}
case 'P':
copy_permissions = 1;
break;
static void
set_user (struct mu_parseopt *po, struct mu_option *opt, char const *arg)
{
auth = mu_get_auth_by_name (arg);
if (auth)
known_meta_data |= META_AUTH;
else
{
char *p;
unsigned long n = strtoul (arg, &p, 0);
if (*p == 0)
{
owner_uid = n;
known_meta_data |= META_UID;
}
else
{
mu_parseopt_error (po, _("no such user: %s"), arg);
exit (po->po_exit_error);
}
}
ignore_directives ("user,uid");
}
case 'q':
suppress_header = 1;
break;
case 'u':
auth = mu_get_auth_by_name (arg);
if (auth)
known_meta_data |= META_AUTH;
static void
set_group (struct mu_parseopt *po, struct mu_option *opt, char const *arg)
{
struct group *gr = getgrnam (arg);
if (!gr)
{
char *p;
unsigned long n = strtoul (arg, &p, 0);
if (*p == 0)
owner_gid = n;
else
{
char *p;
unsigned long n = strtoul (arg, &p, 0);
if (*p == 0)
{
owner_uid = n;
known_meta_data |= META_UID;
}
else
argp_error (state, _("no such user: %s"), arg);
mu_parseopt_error (po, _("no such group: %s"), arg);
exit (po->po_exit_error);
}
ignore_directives ("user,uid");
break;
}
else
owner_gid = gr->gr_gid;
known_meta_data |= META_GID;
ignore_directives ("group,gid");
}
case 'g':
{
struct group *gr = getgrnam (arg);
if (!gr)
{
char *p;
unsigned long n = strtoul (arg, &p, 0);
if (*p == 0)
owner_gid = n;
else
argp_error (state, _("no such group: %s"), arg);
}
else
owner_gid = gr->gr_gid;
known_meta_data |= META_GID;
ignore_directives ("group,gid");
}
break;
static void
set_ignore_meta (struct mu_parseopt *po, struct mu_option *opt, char const *arg)
{
ignore_flagged_directives (DF_META);
}
case 'G':
key_type = key_glob;
break;
static void
set_ignore_directives (struct mu_parseopt *po, struct mu_option *opt,
char const *arg)
{
ignore_directives (arg);
}
case 'R':
key_type = key_regex;
break;
static void
set_format (struct mu_parseopt *po, struct mu_option *opt, char const *arg)
{
select_format (arg);
}
case 'm':/* FIXME: Why m? */
ignore_flagged_directives (DF_META);
break;
static void
set_glob (struct mu_parseopt *po, struct mu_option *opt, char const *arg)
{
key_type = key_glob;
}
case 'I':
ignore_directives (arg);
break;
case 'i':
case_sensitive = 0;
break;
static void
set_regex (struct mu_parseopt *po, struct mu_option *opt, char const *arg)
{
key_type = key_regex;
}
case 'N':
include_zero = 1;
break;
static void
set_ignore_case (struct mu_parseopt *po, struct mu_option *opt, char const *arg)
{
case_sensitive = 0;
}
case 'n':
include_zero = 0;
break;
default:
return ARGP_ERR_UNKNOWN;
}
return 0;
static void
clear_include_zero (struct mu_parseopt *po, struct mu_option *opt,
char const *arg)
{
include_zero = 0;
}
static struct argp dbm_argp = {
dbm_options,
dbm_parse_opt,
dbm_args_doc,
dbm_doc,
NULL,
NULL,
NULL
static struct mu_option dbm_options[] = {
MU_OPTION_GROUP (N_("Create Options")),
{ "file", 'f', N_("FILE"), MU_OPTION_DEFAULT,
N_("read input from FILE (with create, delete, add and replace)"),
mu_c_string, &input_file },
{ "permissions", 'p', N_("NUM"), MU_OPTION_DEFAULT,
N_("set permissions on the created database"),
mu_c_string, NULL, set_permissions },
{ "user", 'u', N_("USER"), MU_OPTION_DEFAULT,
N_("set database owner name"),
mu_c_string, NULL, set_user },
{ "group", 'g', N_("GROUP"), MU_OPTION_DEFAULT,
N_("set database owner group"),
mu_c_string, NULL, set_group },
{ "copy-permissions", 'P', NULL, MU_OPTION_DEFAULT,
N_("copy database permissions and ownership from the input file"),
mu_c_bool, &copy_permissions },
{ "ignore-meta", 'm', NULL, MU_OPTION_DEFAULT,
N_("ignore meta-information from input file headers"),
mu_c_string, NULL, set_ignore_meta },
{ "ignore-directives", 'I', N_("NAMES"), MU_OPTION_DEFAULT,
N_("ignore the listed directives"),
mu_c_string, NULL, set_ignore_directives },
MU_OPTION_GROUP (N_("List and Dump Options")),
{ "format", 'H', N_("TYPE"), MU_OPTION_DEFAULT,
N_("select output format"),
mu_c_string, NULL, set_format },
{ "no-header", 'q', NULL, MU_OPTION_DEFAULT,
N_("suppress format header"),
mu_c_bool, &suppress_header },
MU_OPTION_GROUP (N_("List, Dump and Delete Options")),
{ "glob", 'G', NULL, MU_OPTION_DEFAULT,
N_("treat keys as globbing patterns"),
mu_c_string, NULL, set_glob },
{ "regex", 'R', NULL, MU_OPTION_DEFAULT,
N_("treat keys as regular expressions"),
mu_c_string, NULL, set_regex },
{ "ignore-case", 'i', NULL, MU_OPTION_DEFAULT,
N_("case-insensitive matches"),
mu_c_string, NULL, set_ignore_case },
MU_OPTION_GROUP (N_("Options for Use with Format 0.0")),
{ "count-null", 'N', NULL, MU_OPTION_DEFAULT,
N_("data length accounts for terminating zero"),
mu_c_bool, &include_zero },
{ "no-count-null", 'n', NULL, MU_OPTION_DEFAULT,
N_("data length does not account for terminating zero"),
mu_c_string, NULL, clear_include_zero },
MU_OPTION_END
};
struct mu_kwd mode_tab[] =
......@@ -1769,12 +1768,8 @@ int
mutool_dbm (int argc, char **argv)
{
int index;
if (argp_parse (&dbm_argp, argc, argv, 0, &index, NULL))
return 1;
argc -= index;
argv += index;
mu_action_getopt (&argc, &argv, dbm_options, dbm_doc, dbm_args_doc);
if (argc == 0)
{
......
......@@ -49,33 +49,34 @@ dispatch_find_action (const char *name)
return NULL;
}
char *
dispatch_docstring (const char *text)
void
subcommand_help (mu_stream_t str)
{
mu_stream_t str;
struct mutool_action_tab *p;
mu_off_t size;
size_t n;
char *ret;
unsigned margin;
mu_memory_stream_create (&str, MU_STREAM_RDWR);
mu_stream_printf (str, "%s\n%s\n\n", text, _("Commands are:"));
mu_stream_printf (str, "%s\n\n", _("Commands are:"));
for (p = mutool_action_tab; p->name; p++)
mu_stream_printf (str, " %s %-16s - %s\n",
mu_program_name,
p->name, gettext (p->docstring));
{
margin = 2;
mu_stream_ioctl (str, MU_IOCTL_WORDWRAPSTREAM,
MU_IOCTL_WORDWRAP_SET_MARGIN,
&margin);
mu_stream_printf (str, "%s %s", mu_program_name, p->name);
margin = 29;
mu_stream_ioctl (str, MU_IOCTL_WORDWRAPSTREAM,
MU_IOCTL_WORDWRAP_SET_MARGIN,
&margin);
mu_stream_printf (str, "%s", gettext (p->docstring));
}
margin = 0;
mu_stream_ioctl (str, MU_IOCTL_WORDWRAPSTREAM,
MU_IOCTL_WORDWRAP_SET_MARGIN,
&margin);
mu_stream_printf (str,
_("\nTry `%s COMMAND --help' to get help on a particular "
"COMMAND.\n\n"),
mu_program_name);
mu_stream_printf (str, "%s\n", _("Options are:"));
mu_stream_flush (str);
mu_stream_size (str, &size);
ret = mu_alloc (size + 1);
mu_stream_seek (str, 0, MU_SEEK_SET, NULL);
mu_stream_read (str, ret, size, &n);
ret[n] = 0;
mu_stream_destroy (&str);
return ret;
mu_stream_printf (str, "%s\n", _("OPTIONs are:"));
}
......
......@@ -23,57 +23,41 @@
#include "argp.h"
#include "mu.h"
static char filter_doc[] = N_("mu filter - apply a chain of filters to the input");
char filter_docstring[] = N_("apply a chain of filters to the input");
static char filter_args_doc[] = N_("[~]NAME [ARGS] [+ [~]NAME [ARGS]...]");
static struct argp_option filter_options[] = {
{ "encode", 'e', NULL, 0, N_("encode the input (default)") },
{ "decode", 'd', NULL, 0, N_("decode the input") },
{ "newline", 'n', NULL, 0, N_("print additional newline") },
{ "list", 'L', NULL, 0, N_("list supported filters") },
{ NULL }
};
static int filter_mode = MU_FILTER_ENCODE;
static int newline_option = 0;
static int list_option;
static error_t
filter_parse_opt (int key, char *arg, struct argp_state *state)
static void
set_encode_mode (struct mu_parseopt *po, struct mu_option *opt,
char const *arg)
{
switch (key)
{
case 'e':
filter_mode = MU_FILTER_ENCODE;
break;
case 'd':
filter_mode = MU_FILTER_DECODE;
break;
case 'n':
newline_option = 1;
break;
filter_mode = MU_FILTER_ENCODE;
}
case 'L':
list_option = 1;
break;
default:
return ARGP_ERR_UNKNOWN;
}
return 0;
static void
set_decode_mode (struct mu_parseopt *po, struct mu_option *opt,
char const *arg)
{
filter_mode = MU_FILTER_DECODE;
}
static struct argp filter_argp = {
filter_options,
filter_parse_opt,
filter_args_doc,
filter_doc,
NULL,
NULL,
NULL
static struct mu_option filter_options[] = {
{ "encode", 'e', NULL, MU_OPTION_DEFAULT,
N_("encode the input (default)"),
mu_c_string, NULL, set_encode_mode },
{ "decode", 'd', NULL, MU_OPTION_DEFAULT,
N_("decode the input"),
mu_c_string, NULL, set_decode_mode },
{ "newline", 'n', NULL, MU_OPTION_DEFAULT,
N_("print additional newline"),
mu_c_bool, &newline_option },
{ "list", 'L', NULL, MU_OPTION_DEFAULT,
N_("list supported filters"),
mu_c_bool, &list_option },
MU_OPTION_END
};
static int
......@@ -85,7 +69,7 @@ filter_printer (void *item, void *data)
}
static int
list_filters ()
list_filters (void)
{
mu_list_t list;
int rc = mu_filter_get_list (&list);
......@@ -111,17 +95,14 @@ negate_filter_mode (int mode)
int
mutool_filter (int argc, char **argv)
{
int rc, index;
int rc;
mu_stream_t flt, prev_stream;
const char *fltname;
int mode;
if (argp_parse (&filter_argp, argc, argv, ARGP_IN_ORDER, &index, NULL))
return 1;
argc -= index;
argv += index;
mu_action_getopt (&argc, &argv, filter_options, filter_docstring,
filter_args_doc);
if (list_option)
{
if (argc)
......
......@@ -14,87 +14,50 @@
You should have received a copy of the GNU General Public License
along with GNU Mailutils. If not, see <http://www.gnu.org/licenses/>. */
#if defined(HAVE_CONFIG_H)
# include <config.h>
#endif
#include <stdlib.h>
#include <string.h>
#include <mailutils/mailutils.h>
#include "argp.h"
#include "mu.h"
static char flt2047_doc[] = N_("mu 2047 - decode/encode message headers.");
char flt2047_docstring[] = N_("decode/encode email message headers");
static char flt2047_args_doc[] = N_("[text]");
static struct argp_option flt2047_options[] = {
{ "encode", 'e', NULL, 0, N_("encode the input (default)") },
{ "decode", 'd', NULL, 0, N_("decode the input") },
{ "newline", 'n', NULL, 0, N_("print additional newline") },
{ "charset", 'c', N_("NAME"), 0,
N_("set charset (default: iso-8859-1)") },
{ "encoding", 'E', N_("NAME"), 0,
N_("set encoding (default: quoted-printable)") },
{ NULL }
};
static int decode_mode = 0;
static int newline_option = 0;
static const char *charset = "iso-8859-1";
static const char *encoding = "quoted-printable";
static error_t
flt2047_parse_opt (int key, char *arg, struct argp_state *state)
static void
set_encode_mode (struct mu_parseopt *po, struct mu_option *opt,
char const *arg)
{
switch (key)
{
case 'c':
charset = arg;
break;
case 'e':
decode_mode = 0;
break;
case 'E':
encoding = arg;
break;
case 'd':
decode_mode = 1;
break;
case 'n':
newline_option = 0;
break;
default:
return ARGP_ERR_UNKNOWN;
}
return 0;
decode_mode = 0;
}
static struct argp flt2047_argp = {
flt2047_options,
flt2047_parse_opt,
flt2047_args_doc,
flt2047_doc,
NULL,
NULL,
NULL
static struct mu_option flt2047_options[] = {
{ "encode", 'e', NULL, MU_OPTION_DEFAULT,
N_("encode the input (default)"),
mu_c_string, NULL, set_encode_mode },
{ "decode", 'd', NULL, MU_OPTION_DEFAULT,
N_("decode the input"),
mu_c_bool, &decode_mode },
{ "newline", 'n', NULL, MU_OPTION_DEFAULT,
N_("print additional newline"),
mu_c_bool, &newline_option },
{ "charset", 'c', N_("NAME"), MU_OPTION_DEFAULT,
N_("set charset (default: iso-8859-1)"),
mu_c_string, &charset },
{ "encoding", 'E', N_("NAME"), MU_OPTION_DEFAULT,
N_("set encoding (default: quoted-printable)"),
mu_c_string, &encoding },
MU_OPTION_END
};
int
mutool_flt2047 (int argc, char **argv)
{
int rc, index;
int rc;
char *p;
if (argp_parse (&flt2047_argp, argc, argv, ARGP_IN_ORDER, &index, NULL))
return 1;
argc -= index;
argv += index;
mu_action_getopt (&argc, &argv, flt2047_options, flt2047_docstring,
flt2047_args_doc);
if (argc)
{
......
......@@ -14,10 +14,6 @@
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/mailutils.h>
#include "mu.h"
int
......
......@@ -14,16 +14,8 @@
You should have received a copy of the GNU General Public License
along with GNU Mailutils. If not, see <http://www.gnu.org/licenses/>. */
#if defined(HAVE_CONFIG_H)
# include <config.h>
#endif
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <netdb.h>
#include <netinet/in.h>
#include <mailutils/mailutils.h>
#include "mu.h"
#include <netdb.h>
int
get_bool (const char *str, int *pb)
......
......@@ -14,10 +14,6 @@
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/mailutils.h>
#include "mu.h"
int
......
......@@ -29,37 +29,24 @@ static char help_doc[] = N_("mu help - display a terse help summary");
char help_docstring[] = N_("display a terse help summary");
static char help_args_doc[] = N_("[COMMAND]");
static struct argp help_argp = {
NULL,
NULL,
help_args_doc,
help_doc,
NULL,
NULL,
NULL
};
int
mutool_help (int argc, char **argv)
{
int index;
if (argp_parse (&help_argp, argc, argv, ARGP_IN_ORDER, &index, NULL))
return 1;
mu_action_getopt (&argc, &argv, NULL, help_doc, help_args_doc);
if (index == argc - 1)
if (argc == 1)
{
mutool_action_t action = dispatch_find_action (argv[index]);
mutool_action_t action = dispatch_find_action (argv[0]);
if (!action)
{
mu_error (_("don't know what %s is"), argv[index]);
mu_error (_("don't know what %s is"), argv[0]);
exit (1);
}
mu_asprintf (&argv[0], "%s %s", mu_program_name, argv[index]);
mu_asprintf (&argv[0], "%s %s", mu_program_name, argv[0]);
argv[1] = "--help";
return action (2, argv);
}
else if (argc != index)
else if (argc > 1)
{
mu_error (_("too many arguments"));
exit (1);
......
......@@ -31,35 +31,7 @@
#include "mu.h"
#include "argp.h"
static char imap_doc[] = N_("mu imap - IMAP4 client shell.");
char imap_docstring[] = N_("IMAP4 client shell");
static char imap_args_doc[] = "";
static struct argp_option imap_options[] = {
{ NULL }
};
static error_t
imap_parse_opt (int key, char *arg, struct argp_state *state)
{
switch (key)
{
default:
return ARGP_ERR_UNKNOWN;
}
return 0;
}
static struct argp imap_argp = {
imap_options,
imap_parse_opt,
imap_args_doc,
imap_doc,
NULL,
NULL,
NULL
};
static mu_imap_t imap;
static int uid_mode;
......@@ -1336,13 +1308,7 @@ struct mutool_command imap_comtab[] = {
int
mutool_imap (int argc, char **argv)
{
int index;
if (argp_parse (&imap_argp, argc, argv, ARGP_IN_ORDER, &index, NULL))
return 1;
argc -= index;
argv += index;
mu_action_getopt (&argc, &argv, NULL, imap_docstring, NULL);
if (argc)
{
......
......@@ -14,13 +14,6 @@
You should have received a copy of the GNU General Public License
along with GNU Mailutils. If not, see <http://www.gnu.org/licenses/>. */
#if defined(HAVE_CONFIG_H)
# include <config.h>
#endif
#include <stdlib.h>
#include <string.h>
#include <mailutils/mailutils.h>
#include "argp.h"
#include "mu.h"
static char info_doc[] = N_("mu info - print a list of configuration\
......@@ -29,49 +22,19 @@ static char info_doc[] = N_("mu info - print a list of configuration\
char info_docstring[] = N_("show Mailutils configuration");
static char info_args_doc[] = N_("[capa...]");
static struct argp_option info_options[] = {
{ "verbose", 'v', NULL, 0,
N_("increase output verbosity"), 0},
{ NULL }
};
static int verbose;
static error_t
info_parse_opt (int key, char *arg, struct argp_state *state)
{
switch (key)
{
case 'v':
verbose++;
break;
default:
return ARGP_ERR_UNKNOWN;
}
return 0;
}
static struct argp info_argp = {
info_options,
info_parse_opt,
info_args_doc,
info_doc,
NULL,
NULL,
NULL
static struct mu_option info_options[] = {
{ "verbose", 'v', NULL, MU_OPTION_DEFAULT,
N_("increase output verbosity"),
mu_c_bool, &verbose },
MU_OPTION_END
};
int
mutool_info (int argc, char **argv)
{
int index;
if (argp_parse (&info_argp, argc, argv, ARGP_IN_ORDER, &index, NULL))
return 1;
argc -= index;
argv += index;
mu_action_getopt (&argc, &argv, info_options, info_doc, info_args_doc);
if (argc == 0)
mu_format_options (mu_strout, verbose);
......
......@@ -14,28 +14,11 @@
You should have received a copy of the GNU General Public License
along with GNU Mailutils. If not, see <http://www.gnu.org/licenses/>. */
#if defined(HAVE_CONFIG_H)
# include <config.h>
#endif
#include <stdlib.h>
#include <mailutils/mailutils.h>
#include <mailutils/libcfg.h>
#include <argp.h>
#include "mu.h"
static char ldflags_doc[] = N_("mu ldflags - list libraries required to link");
char ldflags_docstring[] = N_("list libraries required to link");
static char ldflags_args_doc[] = N_("KEYWORD [KEYWORD...]");
static struct argp ldflags_argp = {
NULL,
NULL,
ldflags_args_doc,
ldflags_doc,
NULL,
NULL,
NULL
};
#ifdef WITH_TLS
# define NEEDAUTH "-lmu_auth " AUTHLIBS
......@@ -140,13 +123,9 @@ sort_entries ()
int
mutool_ldflags (int argc, char **argv)
{
int i, j;
if (argp_parse (&ldflags_argp, argc, argv, ARGP_IN_ORDER, &i, NULL))
return 1;
int j;
argc -= i;
argv += i;
mu_action_getopt (&argc, &argv, NULL, ldflags_docstring, ldflags_args_doc);
add_entry (-100, LINK_FLAGS);
add_entry (100, LINK_POSTFLAGS);
......
......@@ -14,35 +14,11 @@
You should have received a copy of the GNU General Public License
along with GNU Mailutils. If not, see <http://www.gnu.org/licenses/>. */
#if defined(HAVE_CONFIG_H)
# include <config.h>
#endif
#include <mailutils/mailutils.h>
#include "argp.h"
#include "mu.h"
static char logger_doc[] = N_("mu logger - log data using Mailutils log facility");
char logger_docstring[] = N_("log data using Mailutils log facility");
static char logger_args_doc[] = N_("[TEXT]");
#define OPT_SYSLOG 256
#define OPT_STDERR 257
static struct argp_option logger_options[] = {
{ "file", 'f', N_("FILE"), 0, N_("read message from FILE") },
{ "priority", 'p', N_("FACILITY[.LEVEL]"), 0,
N_("log at the specified syslog priority (implies --syslog)") },
{ "syslog", OPT_SYSLOG, NULL, 0, N_("log via syslog") },
{ "stderr", OPT_STDERR, NULL, 0, N_("log to the standard error") },
{ "severity", 's', N_("SEV"), 0,
N_("log at Mailutils severity level SEV") },
{ "locus", 'l', N_("FILE:LINE[:COL]"), 0,
N_("set locus for logging") },
{ "tag", 't', N_("syslog tag"), 0,
N_("set syslog tag") },
{ NULL }
};
static char *input_file = NULL;
static int logger_type = MU_STRERR_STDERR;
static int log_severity = MU_LOG_ERROR;
......@@ -51,104 +27,119 @@ static int syslog_facility = LOG_USER;
static int syslog_priority = LOG_ERR;
static char *syslog_tag = NULL;
static error_t
logger_parse_opt (int key, char *arg, struct argp_state *state)
static void
set_priority (struct mu_parseopt *po, struct mu_option *opt,
char const *arg)
{
switch (key)
char *s = strchr (arg, '.');
if (s)
*s++ = 0;
if (mu_string_to_syslog_facility (arg, &syslog_facility))
{
case 'f':
input_file = arg;
break;
mu_parseopt_error (po, _("unknown facility: %s"), arg);
exit (po->po_exit_error);
}
if (s && mu_string_to_syslog_priority (s, &syslog_priority))
{
mu_parseopt_error (po, _("unknown priority: %s"), s);
exit (po->po_exit_error);
}
logger_type = MU_STRERR_SYSLOG;
}
case OPT_SYSLOG:
logger_type = MU_STRERR_SYSLOG;
break;
static void
set_syslog (struct mu_parseopt *po, struct mu_option *opt,
char const *arg)
{
logger_type = MU_STRERR_SYSLOG;
}
case OPT_STDERR:
logger_type = MU_STRERR_STDERR;
break;
static void
set_stderr (struct mu_parseopt *po, struct mu_option *opt,
char const *arg)
{
logger_type = MU_STRERR_STDERR;
}
case 's':
static void
set_severity (struct mu_parseopt *po, struct mu_option *opt,
char const *arg)
{
int i;
for (i = 0; i < _mu_severity_num; i++)
if (mu_c_strcasecmp (_mu_severity_str[i], arg) == 0)
{
int i;
log_severity = i;
return;
}
mu_parseopt_error (po, _("unknown severity: %s"), arg);
exit (po->po_exit_error);
}
for (i = 0; i < _mu_severity_num; i++)
if (mu_c_strcasecmp (_mu_severity_str[i], arg) == 0)
static void
set_locus (struct mu_parseopt *po, struct mu_option *opt,
char const *arg)
{
char *s;
locus.mu_file = mu_strdup (arg);
s = strchr (arg, ':');
if (s)
{
*s++ = 0;
locus.mu_line = strtoul (s, &s, 10);
if (*s == ':')
{
locus.mu_col = strtoul (s + 1, &s, 10);
if (*s)
{
log_severity = i;
return 0;
mu_parseopt_error (po, _("bad column number: %s"), arg);
exit (po->po_exit_error);
}
argp_error (state, _("unknown severity: %s"), arg);
break;
}
case 't':
syslog_tag = arg;
break;
case 'p':
{
char *s = strchr (arg, '.');
if (s)
*s++ = 0;
if (mu_string_to_syslog_facility (arg, &syslog_facility))
argp_error (state, _("unknown facility: %s"), arg);
if (s &&
mu_string_to_syslog_priority (s, &syslog_priority))
argp_error (state, _("unknown priority: %s"), s);
logger_type = MU_STRERR_SYSLOG;
break;
}
case 'l':
{
char *s;
locus.mu_file = arg;
s = strchr (arg, ':');
if (s)
{
*s++ = 0;
locus.mu_line = strtoul (s, &s, 10);
if (*s == ':')
{
locus.mu_col = strtoul (s + 1, &s, 10);
if (*s)
argp_error (state, _("bad column number: %s"), arg);
}
else if (*s)
argp_error (state, _("bad line number: %s"), arg);
}
break;
}
default:
return ARGP_ERR_UNKNOWN;
}
else if (*s)
{
mu_parseopt_error (po, _("bad line number: %s"), arg);
exit (po->po_exit_error);
}
}
return 0;
}
static struct argp logger_argp = {
logger_options,
logger_parse_opt,
logger_args_doc,
logger_doc,
NULL,
NULL,
NULL
static struct mu_option logger_options[] = {
{ "file", 'f', N_("FILE"), MU_OPTION_DEFAULT,
N_("read message from FILE"),
mu_c_string, &input_file },
{ "priority", 'p', N_("FACILITY[.LEVEL]"), MU_OPTION_DEFAULT,
N_("log at the specified syslog priority (implies --syslog)"),
mu_c_string, NULL, set_priority },
{ "syslog", 0, NULL, MU_OPTION_DEFAULT,
N_("log via syslog"),
mu_c_string, NULL, set_syslog },
{ "stderr", 0, NULL, MU_OPTION_DEFAULT,
N_("log to the standard error"),
mu_c_string, NULL, set_stderr },
{ "severity", 's', N_("SEV"), MU_OPTION_DEFAULT,
N_("log at Mailutils severity level SEV"),
mu_c_string, NULL, set_severity },
{ "locus", 'l', N_("FILE:LINE[:COL]"), MU_OPTION_DEFAULT,
N_("set locus for logging"),
mu_c_string, NULL, set_locus },
{ "tag", 't', N_("TAG"), MU_OPTION_DEFAULT,
N_("set syslog tag"),
mu_c_string, &syslog_tag },
MU_OPTION_END
};
int
mutool_logger (int argc, char **argv)
{
int index;
mu_stream_t logger, input;
int rc, mode;
if (argp_parse (&logger_argp, argc, argv, ARGP_IN_ORDER, &index, NULL))
return 1;
argc -= index;
argv += index;
mu_action_getopt (&argc, &argv, logger_options, logger_docstring,
logger_args_doc);
if (argc && input_file)
{
......
......@@ -21,58 +21,17 @@
#include <string.h>
#include <mailutils/mailutils.h>
#include <mailutils/tls.h>
#include "mailutils/libargp.h"
#include "mailutils/cli.h"
#include "mu.h"
static char args_doc[] = N_("COMMAND [CMDOPTS]");
static char doc[] = N_("GNU Mailutils multi-purpose tool.");
static struct argp_option options[] = {
{ NULL }
struct mu_cli_setup cli = {
.prog_doc = N_("GNU Mailutils multi-purpose tool."),
.prog_args = N_("COMMAND [CMDOPTS]"),
.inorder = 1,
.prog_doc_hook = subcommand_help
};
static error_t
parse_opt (int key, char *arg, struct argp_state *state)
{
switch (key)
{
default:
return ARGP_ERR_UNKNOWN;
}
return 0;
}
static char *
mu_help_filter (int key, const char *text, void *input)
{
char *s;
switch (key)
{
case ARGP_KEY_HELP_PRE_DOC:
s = dispatch_docstring (text);
break;
default:
s = (char*) text;
}
return s;
}
static struct argp argp = {
options,
parse_opt,
args_doc,
doc,
NULL,
mu_help_filter,
NULL
};
static const char *mu_tool_capa[] = {
"mailutils",
"common",
static char *capa[] = {
"debug",
"locking",
"mailbox",
......@@ -80,26 +39,9 @@ static const char *mu_tool_capa[] = {
NULL
};
struct mu_cfg_param mu_tool_param[] = {
{ NULL }
};
int
mu_help ()
{
char *x_argv[3];
x_argv[0] = (char*) mu_program_name;
x_argv[1] = "--help";
x_argv[2] = NULL;
return mu_app_init (&argp, mu_tool_capa, mu_tool_param,
2, x_argv, 0, NULL, NULL);
}
int
main (int argc, char **argv)
{
int index;
mutool_action_t action;
/* Native Language Support */
......@@ -109,16 +51,7 @@ main (int argc, char **argv)
/* Register the desired mailbox formats. */
mu_register_all_mbox_formats ();
#ifdef WITH_TLS
mu_gocs_register ("tls", mu_tls_module_init);
#endif
mu_argp_init (NULL, NULL);
if (mu_app_init (&argp, mu_tool_capa, mu_tool_param,
argc, argv, ARGP_IN_ORDER, &index, NULL))
exit (1);
argc -= index;
argv += index;
mu_cli (argc, argv, &cli, capa, NULL, &argc, &argv);
if (argc < 1)
{
......@@ -133,16 +66,60 @@ main (int argc, char **argv)
exit (1);
}
/* Disable --version option in action. */
argp_program_version = NULL;
argp_program_version_hook = NULL;
/* Reset argv[0] for diagnostic purposes */
mu_asprintf (&argv[0], "%s %s", mu_program_name, argv[0]);
/* Run the action. */
exit (action (argc, argv));
}
int
mu_help (void)
{
char *argv[3];
argv[0] = mu_full_program_name;
argv[1] = "--help";
argv[2] = NULL;
mu_cli (2, argv, &cli, capa, NULL, NULL, NULL);
return 0;
}
void
mu_action_getopt (int *pargc, char ***pargv, struct mu_option *opt,
char const *docstring, char const *argdoc)
{
struct mu_parseopt po;
int flags = MU_PARSEOPT_IMMEDIATE;
struct mu_option *options[2];
char const *prog_args[2];
char *progname;
options[0] = opt;
options[1] = NULL;
mu_asprintf (&progname, "%s %s", mu_program_name, (*pargv)[0]);
po.po_prog_name = progname;
flags |= MU_PARSEOPT_PROG_NAME;
po.po_prog_doc = docstring;
flags |= MU_PARSEOPT_PROG_DOC;
if (argdoc)
{
prog_args[0] = argdoc;
prog_args[1] = NULL;
po.po_prog_args = prog_args;
flags |= MU_PARSEOPT_PROG_ARGS;
}
po.po_bug_address = PACKAGE_BUGREPORT;
flags |= MU_PARSEOPT_BUG_ADDRESS;
if (mu_parseopt (&po, *pargc, *pargv, options, flags))
exit (po.po_exit_error);
*pargc -= po.po_arg_start;
*pargv += po.po_arg_start;
mu_parseopt_free (&po);
}
......
......@@ -14,7 +14,17 @@
You should have received a copy of the GNU General Public License
along with GNU Mailutils. If not, see <http://www.gnu.org/licenses/>. */
#include <mailutils/types.h>
#if defined(HAVE_CONFIG_H)
# include <config.h>
#endif
#include <stdlib.h>
#include <string.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <sys/un.h>
#include <arpa/inet.h>
#include <sysexits.h>
#include <mailutils/mailutils.h>
typedef int (*mutool_action_t) (int argc, char **argv);
......@@ -40,7 +50,7 @@ mu_stream_t mutool_open_pager (void);
int mu_help (void);
mutool_action_t dispatch_find_action (const char *name);
char *dispatch_docstring (const char *text);
void subcommand_help (mu_stream_t str);
int port_from_sa (struct mu_sockaddr *sa);
......@@ -64,3 +74,6 @@ int get_port (const char *port_str, int *pn);
int mu_getans (const char *variants, const char *fmt, ...);
void mu_action_getopt (int *pargc, char ***pargv, struct mu_option *opt,
char const *docstring, char const *argdoc);
......
......@@ -14,48 +14,9 @@
You should have received a copy of the GNU General Public License
along with GNU Mailutils. If not, see <http://www.gnu.org/licenses/>. */
#if defined(HAVE_CONFIG_H)
# include <config.h>
#endif
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/time.h>
#include <netinet/in.h>
#include <netdb.h>
#include <mailutils/mailutils.h>
#include "mu.h"
#include "argp.h"
static char pop_doc[] = N_("mu pop - POP3 client shell.");
char pop_docstring[] = N_("POP3 client shell");
static char pop_args_doc[] = "";
static struct argp_option pop_options[] = {
{ NULL }
};
static error_t
pop_parse_opt (int key, char *arg, struct argp_state *state)
{
switch (key)
{
default:
return ARGP_ERR_UNKNOWN;
}
return 0;
}
static struct argp pop_argp = {
pop_options,
pop_parse_opt,
pop_args_doc,
pop_doc,
NULL,
NULL,
NULL
};
/* Global handle for pop3. */
static mu_pop3_t pop3;
......@@ -656,13 +617,7 @@ struct mutool_command pop_comtab[] = {
int
mutool_pop (int argc, char **argv)
{
int index;
if (argp_parse (&pop_argp, argc, argv, ARGP_IN_ORDER, &index, NULL))
return 1;
argc -= index;
argv += index;
mu_action_getopt (&argc, &argv, NULL, pop_docstring, NULL);
if (argc)
{
......
......@@ -14,98 +14,44 @@
You should have received a copy of the GNU General Public License
along with GNU Mailutils. If not, see <http://www.gnu.org/licenses/>. */
#if defined(HAVE_CONFIG_H)
# include <config.h>
#endif
#include <stdlib.h>
#include <string.h>
#include <mailutils/mailutils.h>
#include <mailutils/libcfg.h>
#include "argp.h"
#include "mu.h"
static char query_doc[] = N_("mu query - query configuration values.");
char query_docstring[] = N_("query configuration values");
static char query_args_doc[] = N_("path [path...]");
static char *file_name;
static struct mu_cfg_parse_hints hints;
int value_option;
int path_option;
int verbose_option;
char *progname;
enum {
VALUE_OPTION = 256,
PATH_OPTION
};
static struct argp_option query_options[] = {
{ "file", 'f', N_("FILE"), 0,
static struct mu_option query_options[] = {
{ "file", 'f', N_("FILE"), MU_OPTION_DEFAULT,
N_("query configuration values from FILE (default mailutils.rc)"),
0 },
{ "value", VALUE_OPTION, NULL, 0,
mu_c_string, &file_name },
{ "value", 0, NULL, MU_OPTION_DEFAULT,
N_("display parameter values only"),
0 },
{ "program", 'p', N_("NAME"), 0,
mu_c_bool, &value_option },
{ "program", 'p', N_("NAME"), MU_OPTION_DEFAULT,
N_("set program name for configuration lookup"),
0 },
{ "path", PATH_OPTION, NULL, 0,
N_("display parameters as paths") },
{ "verbose", 'v', NULL, 0,
N_("increase output verbosity"), 0},
{ NULL }
};
static error_t
query_parse_opt (int key, char *arg, struct argp_state *state)
{
switch (key)
{
case 'f':
file_name = arg;
break;
case 'p':
hints.flags |= MU_CFG_PARSE_PROGRAM;
hints.program = arg;
break;
case 'v':
hints.flags |= MU_CFG_FMT_LOCUS;
break;
case VALUE_OPTION:
hints.flags |= MU_CFG_FMT_VALUE_ONLY;
break;
case PATH_OPTION:
hints.flags |= MU_CFG_FMT_PARAM_PATH;
break;
default:
return ARGP_ERR_UNKNOWN;
}
return 0;
}
static struct argp query_argp = {
query_options,
query_parse_opt,
query_args_doc,
query_doc,
NULL,
NULL,
NULL
mu_c_string, &progname },
{ "path", 0, NULL, MU_OPTION_DEFAULT,
N_("display parameters as paths"),
mu_c_bool, &path_option },
{ "verbose", 'v', NULL, MU_OPTION_DEFAULT,
N_("increase output verbosity"),
mu_c_bool, &verbose_option },
MU_OPTION_END
};
int
mutool_query (int argc, char **argv)
{
int index;
static struct mu_cfg_parse_hints hints;
mu_cfg_tree_t *tree = NULL;
if (argp_parse (&query_argp, argc, argv, ARGP_IN_ORDER, &index, NULL))
return 1;
argc -= index;
argv += index;
mu_action_getopt (&argc, &argv, query_options, query_docstring,
query_args_doc);
if (argc == 0)
{
......@@ -113,8 +59,21 @@ mutool_query (int argc, char **argv)
return 1;
}
hints.flags |= MU_CFG_PARSE_SITE_RCFILE | MU_PARSE_CONFIG_GLOBAL;
hints.site_rcfile = file_name ? file_name : mu_site_rcfile;
hints.flags = MU_CFG_PARSE_SITE_RCFILE | MU_PARSE_CONFIG_GLOBAL;
hints.site_rcfile = file_name ? file_name : mu_site_config_file ();
if (progname)
{
hints.flags |= MU_CFG_PARSE_PROGRAM;
hints.program = progname;
}
if (verbose_option)
hints.flags |= MU_CFG_FMT_LOCUS;
if (value_option)
hints.flags |= MU_CFG_FMT_VALUE_ONLY;
if (path_option)
hints.flags |= MU_CFG_FMT_PARAM_PATH;
if (mu_cfg_parse_config (&tree, &hints))
return 1;
......
......@@ -14,17 +14,6 @@
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 <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include <netdb.h>
#include <netinet/in.h>
#include <mailutils/cctype.h>
#include <mailutils/mailutils.h>
#include <argp.h>
#include "mu.h"
static int read_recipients;
......@@ -46,59 +35,41 @@ send_address_add (mu_address_t *paddr, const char *value)
MU_ASSERT (mu_address_union (paddr, addr));
mu_address_destroy (&addr);
}
static char send_doc[] = N_("mu send - send a message.");
char send_docstring[] = N_("send a message");
static char send_args_doc[] = "URL-or-HOST [FILE]";
static struct argp_option send_options[] = {
{ "from", 'F', N_("ADDRESS"), 0,
N_("send mail from this ADDRESS") },
{ "rcpt", 'T', N_("ADDRESS"), 0,
N_("send mail to this ADDRESS") },
{ "read-recipients", 't', NULL, 0,
N_("read recipients from the message") },
{ NULL }
};
static error_t
send_parse_opt (int key, char *arg, struct argp_state *state)
static void
set_from_address (struct mu_parseopt *po, struct mu_option *opt,
char const *arg)
{
switch (key)
{
case 'F':
MU_ASSERT (mu_address_create_null (&from_addr));
send_address_add (&from_addr, arg);
break;
case 'T':
send_address_add (&rcpt_addr, arg);
break;
case 't':
read_recipients = 1;
break;
MU_ASSERT (mu_address_create_null (&from_addr));
send_address_add (&from_addr, arg);
}
default:
return ARGP_ERR_UNKNOWN;
}
return 0;
static void
set_rcpt_address (struct mu_parseopt *po, struct mu_option *opt,
char const *arg)
{
send_address_add (&rcpt_addr, arg);
}
static struct argp send_argp = {
send_options,
send_parse_opt,
send_args_doc,
send_doc,
NULL,
NULL,
NULL
static struct mu_option send_options[] = {
{ "from", 'F', N_("ADDRESS"), MU_OPTION_DEFAULT,
N_("send mail from this ADDRESS"),
mu_c_string, NULL, set_from_address },
{ "rcpt", 'T', N_("ADDRESS"), MU_OPTION_DEFAULT,
N_("send mail to this ADDRESS"),
mu_c_string, NULL, set_rcpt_address },
{ "read-recipients", 't', NULL, MU_OPTION_DEFAULT,
N_("read recipients from the message"),
mu_c_bool, &read_recipients },
MU_OPTION_END
};
int
mutool_send (int argc, char **argv)
{
int index;
char *infile;
mu_stream_t instr;
mu_message_t msg;
......@@ -108,12 +79,8 @@ mutool_send (int argc, char **argv)
MU_ASSERT (mu_address_create_null (&rcpt_addr));
mu_register_all_mailer_formats ();
if (argp_parse (&send_argp, argc, argv, 0, &index, NULL))
return 1;
argc -= index;
argv += index;
mu_action_getopt (&argc, &argv, send_options, send_docstring, send_args_doc);
if (argc < 1)
{
......
......@@ -14,17 +14,9 @@
You should have received a copy of the GNU General Public License
along with GNU Mailutils. If not, see <http://www.gnu.org/licenses/>. */
#if defined(HAVE_CONFIG_H)
# include <config.h>
#endif
#include <stdlib.h>
#include <string.h>
#include "mu.h"
#include <signal.h>
#include <mailutils/mailutils.h>
#include <mailutils/tls.h>
#include "mailutils/libargp.h"
#include "muaux.h"
#include "mu.h"
#ifdef WITH_READLINE
# include <readline/readline.h>
......
......@@ -28,34 +28,7 @@
#include <argp.h>
#include "mu.h"
static char smtp_doc[] = N_("mu smtp - run a SMTP session.");
char smtp_docstring[] = N_("run a SMTP session");
static char smtp_args_doc[] = "";
static struct argp_option smtp_options[] = {
{ NULL }
};
static error_t
smtp_parse_opt (int key, char *arg, struct argp_state *state)
{
switch (key)
{
default:
return ARGP_ERR_UNKNOWN;
}
return 0;
}
static struct argp smtp_argp = {
smtp_options,
smtp_parse_opt,
smtp_args_doc,
smtp_doc,
NULL,
NULL,
NULL
};
enum smtp_session_status
{
......@@ -958,16 +931,10 @@ struct mutool_command smtp_comtab[] = {
int
mutool_smtp (int argc, char **argv)
{
int index;
mu_registrar_record (mu_smtp_record);
mu_registrar_record (mu_smtps_record);
if (argp_parse (&smtp_argp, argc, argv, 0, &index, NULL))
return 1;
argc -= index;
mu_action_getopt (&argc, &argv, NULL, smtp_docstring, NULL);
if (argc)
{
mu_error (_("bad arguments"));
......
......@@ -14,14 +14,6 @@
You should have received a copy of the GNU General Public License
along with GNU Mailutils. If not, see <http://www.gnu.org/licenses/>. */
#if defined(HAVE_CONFIG_H)
# include <config.h>
#endif
#include <stdlib.h>
#include <arpa/inet.h>
#include <netinet/in.h>
#include <mailutils/mailutils.h>
#include "mu.h"
int
......
......@@ -14,12 +14,6 @@
You should have received a copy of the GNU General Public License
along with GNU Mailutils. If not, see <http://www.gnu.org/licenses/>. */
#if defined(HAVE_CONFIG_H)
# include <config.h>
#endif
#include <stdlib.h>
#include <string.h>
#include <mailutils/mailutils.h>
#include "mu.h"
/* Manipulations with verbosity flags, which are common for pop and imap. */
......
......@@ -14,59 +14,32 @@
You should have received a copy of the GNU General Public License
along with GNU Mailutils. If not, see <http://www.gnu.org/licenses/>. */
#if defined(HAVE_CONFIG_H)
# include <config.h>
#endif
#include <stdlib.h>
#include <mailutils/mailutils.h>
#include <mailutils/libcfg.h>
#include <argp.h>
static char wicket_doc[] = N_("mu wicket - find matching URL in wicket");
#include "mu.h"
char wicket_docstring[] = N_("scan wickets for matching URLs");
static char wicket_args_doc[] = N_("URL");
static struct argp_option wicket_options[] = {
{ "file", 'f', N_("FILE"), 0, N_("use FILE instead of ~/.mu-tickets") },
{ "verbose", 'v', NULL, 0, N_("increase output verbosity") },
{ "quiet", 'q', NULL, 0, N_("suppress any output") },
{ NULL }
};
static char *wicket_file = "~/.mu-tickets";
static int wicket_verbose = 1;
static error_t
wicket_parse_opt (int key, char *arg, struct argp_state *state)
static void
clear_wicket_verbose (struct mu_parseopt *po, struct mu_option *opt,
char const *arg)
{
switch (key)
{
case 'f':
wicket_file = arg;
break;
case 'v':
wicket_verbose++;
break;
case 'q':
wicket_verbose = 0;
break;
default:
return ARGP_ERR_UNKNOWN;
}
return 0;
wicket_verbose = 0;
}
static struct argp wicket_argp = {
wicket_options,
wicket_parse_opt,
wicket_args_doc,
wicket_doc,
NULL,
NULL,
NULL
static struct mu_option wicket_options[] = {
{ "file", 'f', N_("FILE"), MU_OPTION_DEFAULT,
N_("use FILE instead of ~/.mu-tickets"),
mu_c_string, &wicket_file },
{ "verbose", 'v', NULL, MU_OPTION_DEFAULT,
N_("increase output verbosity"),
mu_c_string, &wicket_verbose },
{ "quiet", 'q', NULL, MU_OPTION_DEFAULT,
N_("suppress any output"),
mu_c_string, NULL, clear_wicket_verbose },
{ NULL }
};
......@@ -129,12 +102,8 @@ mutool_wicket (int argc, char **argv)
mu_stream_t stream;
int rc, i, exit_code;
if (argp_parse (&wicket_argp, argc, argv, ARGP_IN_ORDER, &i, NULL))
return 1;
argc -= i;
argv += i;
mu_action_getopt (&argc, &argv, wicket_options, wicket_docstring,
wicket_args_doc);
if (argc == 0)
{
mu_error (_("not enough arguments"));
......
......@@ -33,29 +33,11 @@ lib/tcpwrap.c
lib/strexit.c
lib/manlock.c
libmu_argp/cmdline.c
libmu_argp/common.c
libmu_argp/mu_argp.c
libmu_argp/sieve.c
libmu_auth/ldap.c
libmu_auth/radius.c
libmu_auth/sql.c
libmu_auth/tls.c
libmu_cfg/acl.c
libmu_cfg/auth.c
libmu_cfg/common.c
libmu_cfg/gsasl.c
libmu_cfg/init.c
libmu_cfg/ldap.c
libmu_cfg/pam.c
libmu_cfg/radius.c
libmu_cfg/sieve.c
libmu_cfg/sql.c
libmu_cfg/tls.c
libmu_cfg/virtdomain.c
libmu_sieve/actions.c
libmu_sieve/comparator.c
libmu_sieve/conf.c
......@@ -117,7 +99,6 @@ libmailutils/cfg/driver.c
libmailutils/cfg/format.c
libmailutils/cfg/lexer.l
libmailutils/cfg/parser.y
libmailutils/cfg/gocs.c
libmailutils/diag/debug.c
libmailutils/diag/diag.c
......
......@@ -65,7 +65,7 @@ pop3d_LDADD = \
popauth_SOURCES = popauth.c
popauth_LDADD = \
${MU_APP_LIBRARIES}\
${MU_APP_NEW_LIBRARIES}\
${MU_LIB_MAILUTILS}\
@MU_COMMON_LIBRARIES@\
${LIBMU_DBM}\
......
......@@ -104,8 +104,7 @@ static struct mu_option pop3d_options[] = {
{ "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 },
{NULL, 0, NULL, 0, NULL, 0}
MU_OPTION_END
}, *options[] = { pop3d_options, NULL };
static int
......@@ -308,7 +307,6 @@ static char *capa[] = {
"mailbox",
"locking",
"logging",
"tls",
NULL
};
......@@ -585,7 +583,6 @@ main (int argc, char **argv)
#ifdef ENABLE_DBM
set_dbm_safety ();
#endif
mu_cli_capa_register (&mu_cli_capa_tls);
mu_cli (argc, argv, &cli, capa, server, &argc, &argv);
if (argc)
......
......@@ -121,6 +121,7 @@ extern int expire_on_exit;
#include <mailutils/filter.h>
#include <mailutils/stdstream.h>
#include <mailutils/stream.h>
#include "mailutils/syslog.h"
/* For Berkley DB2 APOP password file */
#ifdef HAVE_DB_H
......
......@@ -21,6 +21,7 @@
#include "readmsg.h"
#include "mailutils/cli.h"
#include "mailutils/mu_auth.h"
#include "mu_umaxtostr.h"
#define WEEDLIST_SEPARATOR " :,"
......@@ -94,7 +95,6 @@ static char *readmsg_argp_capa[] = {
"debug",
"mailbox",
"locking",
"tls",
NULL
};
......@@ -242,7 +242,7 @@ main (int argc, char **argv)
mu_register_all_mbox_formats ();
mu_register_extra_formats ();
mu_cli_capa_register (&mu_cli_capa_tls);
mu_auth_register_module (&mu_auth_tls_module);
mu_cli (argc, argv, &cli, readmsg_argp_capa, NULL, &argc, &argv);
......
......@@ -44,6 +44,7 @@
#include <mailutils/nls.h>
#include <mailutils/tls.h>
#include <mailutils/cli.h>
#include <mailutils/mu_auth.h>
#define D_DEFAULT "TPt"
......@@ -238,7 +239,6 @@ static char *sieve_argp_capa[] = {
"locking",
"logging",
"mailer",
"tls",
"sieve",
NULL
};
......@@ -394,7 +394,7 @@ main (int argc, char *argv[])
/* Native Language Support */
MU_APP_INIT_NLS ();
mu_cli_capa_register (&mu_cli_capa_tls);
mu_auth_register_module (&mu_auth_tls_module);
mu_cli_capa_register (&mu_cli_capa_sieve);
mu_sieve_debug_init ();
......
......@@ -69,7 +69,7 @@ add_disptab (mu_sql_dispatch_t *tab)
#endif
int
mu_sql_interface_index (char *name)
mu_sql_interface_index (char const *name)
{
int i;
//mu_sql_dispatch_t *tab;
......