Commit cd6f3aa2 cd6f3aa2be6ee19afc67b2d187542418f8b5a609 by Sergey Poznyakoff

Move rc file and argp parsing into separate abstract layers.

* include/mailutils/gocs.h, include/mailutils/pam.h,
include/mailutils/radius.h, include/mailutils/syslog.h: New files
* lib/argpinit.c, lib/muinit.c, lib/muinit.h: New files.
* libsieve/conf.c: New file.

* libcfg: New directory
* libcfg/libcfg.h, libcfg/auth.c, libcfg/common.c, libcfg/init.c,
libcfg/gsasl.c, libcfg/pam.c, libcfg/radius.c, libcfg/sieve.c,
libcfg/sql.c, libcfg/tls.c, libcfg/virtdomain.c,
libcfg/.cvsignore: New files.

* libargp: New directory
* libargp/auth.c, libargp/cmdline.h, libargp/common.c,
libargp/gsasl.c, libargp/mu_argp.h, libargp/mu_argp.c,
libargp/pam.c, libargp/radius.c, libargp/sieve.c, libargp/sql.c,
libargp/tls.c, libargp/virtdomain.c, libargp/.cvsignore: New
files.

* mailbox/.cvsignore: Add cfg_parser.c and cfg_parser.h.
* Makefile.am (SUBDIRS): Add libargp and libcfg.
* configure.ac (MU_APP_LIBRARIES): New variable
(MU_COMMON_INCLUDES): add libargp and libcfg
(AC_CONFIG_FILES): Add libargp and libcfg.

* auth/gsasl.c, auth/pam.c, auth/radius.c, auth/sql.c, auth/sql.h,
auth/tls.c, auth/virtual.c, comsat/comsat.h, frm/frm.h,
guimb/guimb.h, imap4d/imap4d.h, include/mailutils/gsasl.h,
include/mailutils/libsieve.h, include/mailutils/mailutils.h,
include/mailutils/mu_auth.h, include/mailutils/tls.h,
include/mailutils/sql.h, maidag/maidag.h, mail/mail.h,
mail.local/mail.local.h, mailbox/daemon.c, mailbox/system.c,
mh/mh_argp.c, mh/mh_getopt.h, pop3d/pop3d.h,
readmsg/readmsg.h: Remove argp stuff

* comsat/comsat.c, config/mailutils-config.c, dotlock/dotlock.c,
examples/muauth.c, examples/muemail.c, frm/frm.c, frm/from.c,
guimb/main.c, imap4d/idle.c, imap4d/imap4d.c, imap4d/util.c,
imap4d/version.c, maidag/lmtp.c, maidag/maidag.c,
maidag/mailquota.c, mail/mail.c, mail/send.c, mail/version.c,
mail.local/mailquota.c, mail.local/main.c,
mail.remote/mail.remote.c, mailbox/mu_auth.c, messages/messages.c,
mimeview/mimeview.c, movemail/movemail.c, pop3d/extra.c,
pop3d/pop3d.c, pop3d/popauth.c, readmsg/readmsg.c, sieve/sieve.c:
Use mu_app_init for parsing command line and
configuration files.
* comsat/Makefile.am, config/Makefile.am, dotlock/Makefile.am,
examples/Makefile.am, frm/Makefile.am, guimb/Makefile.am,
imap4d/Makefile.am, maidag/Makefile.am, mail/Makefile.am,
mail.local/Makefile.am, mail.remote/Makefile.am,
mailbox/Makefile.am, messages/Makefile.am, mimeview/Makefile.am,
movemail/Makefile.am, pop3d/Makefile.am, readmsg/Makefile.am,
sieve/Makefile.am: Use MU_APP_LIBRARIES.

* include/mailutils/Makefile.am: Add new files.
* include/mailutils/argp.h: Remove.
* include/mailutils/cfg.h: New file.
* include/mailutils/daemon.h (MODE_INTERACTIVE,MODE_DAEMON): New
defines (from removed argp.h).
(mu_gocs_daemon): New decl.
* include/mailutils/error.h (mu_program_name): New variable
(mu_set_program_name): New function.
* lib/Makefile.am (libmuaux_la_SOURCES): Add new files.
* libsieve/Makefile.am (libsieve_la_SOURCES): Remove argp.c, add
conf.c instead.
* libsieve/argp.c: Remove.

* mailbox/cfg_parser.y (mu_cfg_parse_boolean): New function.
* mailbox/mu_argp.c: Remove.

* mailbox/muerror.c (mu_program_name): New variable
(mu_set_program_name): New function
(mu_default_error_printer): Print program name before diagnostic
string.
* mailbox/mutil.c (mu_sql_decode_password_type): New function.
* mh/mh_whom.c (mh_alias_expand): Bugfix
* po/POTFILES.in: Update
* testsuite/lib/mailutils.exp (mu_init): Pass --no-site-rcfile
--no-user-rcfile to all programs.
1 parent 7e7a878f
Showing 126 changed files with 3556 additions and 2554 deletions
2007-11-17 Sergey Poznyakoff <gray@gnu.org.ua>
Move rc file and argp parsing into separate abstract layers.
* include/mailutils/gocs.h, include/mailutils/pam.h,
include/mailutils/radius.h, include/mailutils/syslog.h: New files
* lib/argpinit.c, lib/muinit.c, lib/muinit.h: New files.
* libsieve/conf.c: New file.
* libcfg: New directory
* libcfg/libcfg.h, libcfg/auth.c, libcfg/common.c, libcfg/init.c,
libcfg/gsasl.c, libcfg/pam.c, libcfg/radius.c, libcfg/sieve.c,
libcfg/sql.c, libcfg/tls.c, libcfg/virtdomain.c,
libcfg/.cvsignore: New files.
* libargp: New directory
* libargp/auth.c, libargp/cmdline.h, libargp/common.c,
libargp/gsasl.c, libargp/mu_argp.h, libargp/mu_argp.c,
libargp/pam.c, libargp/radius.c, libargp/sieve.c, libargp/sql.c,
libargp/tls.c, libargp/virtdomain.c, libargp/.cvsignore: New
files.
* mailbox/.cvsignore: Add cfg_parser.c and cfg_parser.h.
* Makefile.am (SUBDIRS): Add libargp and libcfg.
* configure.ac (MU_APP_LIBRARIES): New variable
(MU_COMMON_INCLUDES): add libargp and libcfg
(AC_CONFIG_FILES): Add libargp and libcfg.
* auth/gsasl.c, auth/pam.c, auth/radius.c, auth/sql.c, auth/sql.h,
auth/tls.c, auth/virtual.c, comsat/comsat.h, frm/frm.h,
guimb/guimb.h, imap4d/imap4d.h, include/mailutils/gsasl.h,
include/mailutils/libsieve.h, include/mailutils/mailutils.h,
include/mailutils/mu_auth.h, include/mailutils/tls.h,
include/mailutils/sql.h, maidag/maidag.h, mail/mail.h,
mail.local/mail.local.h, mailbox/daemon.c, mailbox/system.c,
mh/mh_argp.c, mh/mh_getopt.h, pop3d/pop3d.h,
readmsg/readmsg.h: Remove argp stuff
* comsat/comsat.c, config/mailutils-config.c, dotlock/dotlock.c,
examples/muauth.c, examples/muemail.c, frm/frm.c, frm/from.c,
guimb/main.c, imap4d/idle.c, imap4d/imap4d.c, imap4d/util.c,
imap4d/version.c, maidag/lmtp.c, maidag/maidag.c,
maidag/mailquota.c, mail/mail.c, mail/send.c, mail/version.c,
mail.local/mailquota.c, mail.local/main.c,
mail.remote/mail.remote.c, mailbox/mu_auth.c, messages/messages.c,
mimeview/mimeview.c, movemail/movemail.c, pop3d/extra.c,
pop3d/pop3d.c, pop3d/popauth.c, readmsg/readmsg.c, sieve/sieve.c:
Use mu_app_init for parsing command line and
configuration files.
* comsat/Makefile.am, config/Makefile.am, dotlock/Makefile.am,
examples/Makefile.am, frm/Makefile.am, guimb/Makefile.am,
imap4d/Makefile.am, maidag/Makefile.am, mail/Makefile.am,
mail.local/Makefile.am, mail.remote/Makefile.am,
mailbox/Makefile.am, messages/Makefile.am, mimeview/Makefile.am,
movemail/Makefile.am, pop3d/Makefile.am, readmsg/Makefile.am,
sieve/Makefile.am: Use MU_APP_LIBRARIES.
* include/mailutils/Makefile.am: Add new files.
* include/mailutils/argp.h: Remove.
* include/mailutils/cfg.h: New file.
* include/mailutils/daemon.h (MODE_INTERACTIVE,MODE_DAEMON): New
defines (from removed argp.h).
(mu_gocs_daemon): New decl.
* include/mailutils/error.h (mu_program_name): New variable
(mu_set_program_name): New function.
* lib/Makefile.am (libmuaux_la_SOURCES): Add new files.
* libsieve/Makefile.am (libsieve_la_SOURCES): Remove argp.c, add
conf.c instead.
* libsieve/argp.c: Remove.
* mailbox/cfg_parser.y (mu_cfg_parse_boolean): New function.
* mailbox/mu_argp.c: Remove.
* mailbox/muerror.c (mu_program_name): New variable
(mu_set_program_name): New function
(mu_default_error_printer): Print program name before diagnostic
string.
* mailbox/mutil.c (mu_sql_decode_password_type): New function.
* mh/mh_whom.c (mh_alias_expand): Bugfix
* po/POTFILES.in: Update
* testsuite/lib/mailutils.exp (mu_init): Pass --no-site-rcfile
--no-user-rcfile to all programs.
2007-11-12 Sergey Poznyakoff <gray@gnu.org.ua>
* maidag/lmtp.c: Use English reply texts.
......
......@@ -33,6 +33,8 @@ SUBDIRS = \
libsieve\
libmu_cpp\
libmu_scm\
libargp\
libcfg\
doc\
config\
examples\
......
......@@ -26,7 +26,6 @@
#include <string.h>
#include <limits.h>
#include <unistd.h>
#include <mailutils/argp.h>
#include <mailutils/error.h>
#include <mailutils/errno.h>
#include <mailutils/mu_auth.h>
......@@ -36,54 +35,21 @@
#include <gsasl.h>
#include <lbuf.h>
char *mu_gsasl_cram_md5_pwd = SITE_CRAM_MD5_PWD;
struct mu_gsasl_module_data mu_gsasl_module_data;
#define ARG_CRAM_PASSWD 1
static struct argp_option _gsasl_argp_options[] = {
{"cram-passwd", ARG_CRAM_PASSWD, N_("FILE"), OPTION_HIDDEN,
N_("Specify password file for CRAM-MD5 authentication"), 0},
{ NULL, 0, NULL, 0, NULL, 0 }
};
static error_t
_gsasl_argp_parser (int key, char *arg, struct argp_state *state)
int
mu_gsasl_module_init (void *data)
{
switch (key)
{
case ARG_CRAM_PASSWD:
mu_gsasl_cram_md5_pwd = arg;
break;
static struct mu_gsasl_module_data _default_module_data = {
SITE_CRAM_MD5_PWD
};
default:
return ARGP_ERR_UNKNOWN;
}
if (!data)
mu_gsasl_module_data = _default_module_data;
memcpy (&mu_gsasl_module_data, data, sizeof (mu_gsasl_module_data));
return 0;
}
static struct argp _gsasl_argp = {
_gsasl_argp_options,
_gsasl_argp_parser
};
static struct argp_child _gsasl_argp_child = {
&_gsasl_argp,
0,
NULL,
0
};
void
mu_gsasl_init_argp ()
{
if (mu_register_capa ("gsasl", &_gsasl_argp_child, NULL))
{
mu_error (_("INTERNAL ERROR: cannot register argp capability gsasl"));
abort ();
}
}
struct _gsasl_stream {
Gsasl_session_ctx *sess_ctx; /* Context */
int last_err; /* Last Gsasl error code */
......
......@@ -43,11 +43,10 @@
#include <mailutils/list.h>
#include <mailutils/iterator.h>
#include <mailutils/mailbox.h>
#include <mailutils/argp.h>
#include <mailutils/mu_auth.h>
#include <mailutils/nls.h>
char *pam_service = NULL;
char *mu_pam_service = NULL;
#ifdef USE_LIBPAM
#define COPY_STRING(s) (s) ? strdup(s) : NULL
......@@ -120,7 +119,7 @@ mu_authenticate_pam (struct mu_auth_data **return_data MU_ARG_UNUSED,
_user = (char *) auth_data->name;
_pwd = pass;
pamerror = pam_start (pam_service, _user, &PAM_conversation, &pamh);
pamerror = pam_start (mu_pam_service, _user, &PAM_conversation, &pamh);
PAM_ERROR;
pamerror = pam_authenticate (pamh, 0);
PAM_ERROR;
......@@ -132,39 +131,6 @@ mu_authenticate_pam (struct mu_auth_data **return_data MU_ARG_UNUSED,
return pamerror != PAM_SUCCESS;
}
#define ARG_PAM_SERVICE 1
static error_t
mu_pam_argp_parser (int key, char *arg, struct argp_state *state)
{
switch (key)
{
case ARG_PAM_SERVICE:
pam_service = arg;
break;
default:
return ARGP_ERR_UNKNOWN;
}
return 0;
}
static struct argp_option mu_pam_argp_option[] = {
{ "pam-service", ARG_PAM_SERVICE, N_("STRING"), OPTION_HIDDEN,
N_("Use STRING as PAM service name"), 0},
{ NULL, 0, NULL, 0, NULL, 0 }
};
struct argp mu_pam_argp = {
mu_pam_argp_option,
mu_pam_argp_parser,
};
static struct mu_cfg_param pam_cfg_param[] = {
{ "service", mu_cfg_string, &pam_service },
{ NULL }
};
#else
int
......@@ -179,15 +145,17 @@ mu_authenticate_pam (struct mu_auth_data **return_data MU_ARG_UNUSED,
#endif
int
mu_pam_module_init (void *data)
{
if (data)
mu_pam_service = strdup (data);
return 0;
}
struct mu_auth_module mu_auth_pam_module = {
"pam",
#ifdef USE_LIBPAM
&mu_pam_argp,
pam_cfg_param,
#else
NULL,
NULL,
#endif
mu_pam_module_init,
mu_authenticate_pam,
NULL,
mu_auth_nosupport,
......
......@@ -34,7 +34,7 @@
#include <mailutils/list.h>
#include <mailutils/iterator.h>
#include <mailutils/mailbox.h>
#include <mailutils/argp.h>
#include <mailutils/radius.h>
#include <mailutils/argcv.h>
#include <mailutils/mu_auth.h>
#include <mailutils/error.h>
......@@ -45,39 +45,6 @@
#include <radius/radius.h>
#define ARG_AUTH_REQUEST 256
#define ARG_GETPWNAM_REQUEST 257
#define ARG_GETPWUID_REQUEST 258
#define ARG_RADIUS_DIR 259
static struct argp_option mu_radius_argp_option[] = {
{ "radius-auth-request", ARG_AUTH_REQUEST, N_("REQUEST"), OPTION_HIDDEN,
N_("Radius request to authenitcate the user"), 0 },
{ "radius-getpwnam-request", ARG_GETPWNAM_REQUEST, N_("REQUEST"), OPTION_HIDDEN,
N_("Radius request to retrieve a passwd entry based on username"), 0 },
{ "radius-getpwuid-request", ARG_GETPWUID_REQUEST, N_("REQUEST"), OPTION_HIDDEN,
N_("Radius request to retrieve a passwd entry based on UID"), 0 },
{ "radius-directory", ARG_RADIUS_DIR, N_("DIR"), OPTION_HIDDEN,
N_("Set path to the radius configuration directory"), 0 },
{ NULL }
};
static char *auth_request_str;
static grad_avp_t *auth_request;
static char *getpwnam_request_str;
static grad_avp_t *getpwnam_request;
static char *getpwuid_request_str;
static grad_avp_t *getpwuid_request;
/* 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() \
(auth_request_str||getpwnam_request_str||getpwuid_request_str)
static int radius_auth_enabled;
static int MU_User_Name;
......@@ -88,13 +55,22 @@ static int MU_Dir;
static int MU_Shell;
static int MU_Mailbox;
void
get_attribute (int *pattr, char *name, struct argp_state *state)
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)
{
grad_dict_attr_t *attr = grad_attr_name_to_dict (name);
if (!attr)
argp_error (state, _("Radius attribute %s not defined"), name);
{
mu_error (_("Radius attribute %s not defined"), name);
return 1;
}
*pattr = attr->value;
return 0;
}
enum parse_state
......@@ -106,8 +82,7 @@ enum parse_state
};
int
parse_pairlist (grad_avp_t **plist, const char *input,
struct argp_state *argp_state)
parse_pairlist (grad_avp_t **plist, char *input)
{
int rc;
int i, argc;
......@@ -121,10 +96,12 @@ parse_pairlist (grad_avp_t **plist, const char *input,
return 1;
if ((rc = mu_argcv_get (input, ",", NULL, &argc, &argv)))
argp_error (argp_state, _("Cannot parse input `%s': %s"),
input, mu_strerror (rc));
{
mu_error (_("Cannot parse input `%s': %s"), input, mu_strerror (rc));
return 1;
}
loc.file = "<command line>"; /* FIXME */
loc.file = "<configuration>"; /*FIXME*/
loc.line = 0;
for (i = 0, state = state_lhs; i < argc; i++)
......@@ -147,81 +124,78 @@ parse_pairlist (grad_avp_t **plist, const char *input,
loc.line = i; /* Just to keep track of error location */
pair = grad_create_pair (&loc, name, grad_operator_equal, argv[i]);
if (!pair)
argp_error (argp_state, _("cannot create radius A/V pair `%s'"),
name);
{
mu_error (_("cannot create radius A/V pair `%s'"), name);
return 1;
}
grad_avl_merge (plist, &pair);
state = state_delim;
break;
case state_delim:
if (strcmp (argv[i], ","))
argp_error (argp_state, _("expected `,' but found `%s'"), argv[i]);
{
mu_error (_("expected `,' but found `%s'"), argv[i]);
return 1;
}
state = state_lhs;
}
}
if (state != state_delim && state != state_delim)
argp_error (argp_state, _("malformed radius A/V list"));
{
mu_error (_("malformed radius A/V list"));
return 1;
}
mu_argcv_free (argc, argv);
return 0;
}
static void
init (struct argp_state *state)
/* 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))
int
mu_radius_module_init (void *data)
{
struct mu_radius_module_data *cfg = data;
if (!NEED_RADIUS_P (cfg))
return 0;
grad_config_dir = grad_estrdup (cfg->config_dir);
grad_path_init ();
srand (time (NULL) + getpid ());
if (grad_dict_init ())
argp_error (state, _("Cannot read radius dictionaries"));
{
mu_error (_("Cannot read radius dictionaries"));
return 1;
}
/* Check whether mailutils attributes are defined */
get_attribute (&MU_User_Name, "MU-User-Name", state);
get_attribute (&MU_UID, "MU-UID", state);
get_attribute (&MU_GID, "MU-GID", state);
get_attribute (&MU_GECOS, "MU-GECOS", state);
get_attribute (&MU_Dir, "MU-Dir", state);
get_attribute (&MU_Shell, "MU-Shell", state);
get_attribute (&MU_Mailbox, "MU-Mailbox", state);
if (get_attribute (&MU_User_Name, "MU-User-Name")
|| get_attribute (&MU_UID, "MU-UID")
|| get_attribute (&MU_GID, "MU-GID")
|| get_attribute (&MU_GECOS, "MU-GECOS")
|| get_attribute (&MU_Dir, "MU-Dir")
|| get_attribute (&MU_Shell, "MU-Shell")
|| get_attribute (&MU_Mailbox, "MU-Mailbox"))
return 1;
/* Parse saved requests */
parse_pairlist (&auth_request, auth_request_str, state);
parse_pairlist (&getpwnam_request, getpwnam_request_str, state);
parse_pairlist (&getpwuid_request, getpwuid_request_str, state);
if (parse_pairlist (&auth_request, cfg->auth_request)
|| parse_pairlist (&getpwnam_request, cfg->getpwnam_request)
|| parse_pairlist (&getpwuid_request, cfg->getpwuid_request))
return 1;
radius_auth_enabled = 1;
}
static error_t
mu_radius_argp_parser (int key, char *arg, struct argp_state *state)
{
switch (key)
{
case ARG_AUTH_REQUEST:
auth_request_str = arg;
break;
case ARG_GETPWNAM_REQUEST:
getpwnam_request_str = arg;
break;
case ARG_GETPWUID_REQUEST:
getpwuid_request_str = arg;
break;
case ARG_RADIUS_DIR:
grad_config_dir = grad_estrdup (arg);
break;
case ARGP_KEY_FINI:
if (NEED_RADIUS_P())
init (state);
break;
default:
return ARGP_ERR_UNKNOWN;
}
return 0;
}
......@@ -320,20 +294,6 @@ _expand_query (const char *query, const char *ustr, const char *passwd)
return res;
}
static int
cb_directory (mu_cfg_locus_t *locus, void *data, char *arg)
{
grad_config_dir = grad_estrdup (arg);
return 0;
}
static struct mu_cfg_param mu_radius_cfg_param[] = {
{ "auth-request", mu_cfg_string, &auth_request_str },
{ "getpwnam-request", mu_cfg_string, &getpwnam_request_str },
{ "getpwuid-request", mu_cfg_string, &getpwuid_request_str },
{ "directory", mu_cfg_callback, NULL, cb_directory },
{ NULL }
};
static grad_avp_t *
......@@ -577,11 +537,6 @@ mu_auth_radius_user_by_uid (struct mu_auth_data **return_data,
return rc;
}
struct argp mu_radius_argp = {
mu_radius_argp_option,
mu_radius_argp_parser,
};
#else
static int
mu_radius_authenticate (struct mu_auth_data **return_data MU_ARG_UNUSED,
......@@ -612,11 +567,9 @@ mu_auth_radius_user_by_uid (struct mu_auth_data **return_data,
struct mu_auth_module mu_auth_radius_module = {
"radius",
#ifdef ENABLE_RADIUS
&mu_radius_argp,
mu_radius_cfg_param,
mu_radius_module_init,
#else
NULL,
NULL,
#endif
mu_radius_authenticate,
NULL,
......
......@@ -44,32 +44,18 @@
#include <mailutils/list.h>
#include <mailutils/iterator.h>
#include <mailutils/mailbox.h>
#include <mailutils/argp.h>
#include <mailutils/sql.h>
#include <mailutils/mu_auth.h>
#include <mailutils/error.h>
#include <mailutils/errno.h>
#include <mailutils/nls.h>
#include <mailutils/mutil.h>
#include <mailutils/sql.h>
#include "sql.h"
#ifdef USE_SQL
int sql_interface = 0;
char *mu_sql_getpwnam_query;
char *mu_sql_getpass_query;
char *mu_sql_getpwuid_query;
char *mu_sql_host = NULL; /* Hostname to connect to. NULL for UNIX
socket connection */
char *mu_sql_user = "accounts"; /* Username for mysql access */
char *mu_sql_passwd = "yurpass"; /* Password for mysql access */
char *mu_sql_db = "accounts"; /* Database Name */
int mu_sql_port = 0; /* Port number to connect to.
0 means default port */
enum mu_password_type mu_sql_password_type = password_hash;
static mu_assoc_t sql_field_map;
struct mu_internal_sql_config mu_sql_module_config;
static char *
sql_escape_string (const char *ustr)
......@@ -175,176 +161,6 @@ mu_sql_expand_query (const char *query, const char *ustr)
return res;
}
static int
set_sql_password_type (const char *arg)
{
if (strcmp (arg, "plain") == 0)
mu_sql_password_type = password_plaintext;
else if (strcmp (arg, "hash") == 0)
mu_sql_password_type = password_hash;
else if (strcmp (arg, "scrambled") == 0)
mu_sql_password_type = password_scrambled;
else
return 1;
return 0;
}
/* Command-line configuration */
# define ARG_SQL_INTERFACE 256
# define ARG_SQL_GETPWNAM 257
# define ARG_SQL_GETPWUID 258
# define ARG_SQL_GETPASS 259
# define ARG_SQL_HOST 260
# define ARG_SQL_USER 261
# define ARG_SQL_PASSWD 262
# define ARG_SQL_DB 263
# define ARG_SQL_PORT 264
# define ARG_SQL_MU_PASSWORD_TYPE 265
# define ARG_SQL_FIELD_MAP 266
static struct argp_option mu_sql_argp_option[] = {
{"sql-interface", ARG_SQL_INTERFACE, N_("NAME"), OPTION_HIDDEN,
N_("Type of SQL interface to use"), },
{"sql-getpwnam", ARG_SQL_GETPWNAM, N_("QUERY"), OPTION_HIDDEN,
N_("SQL query to retrieve a passwd entry based on username"), 0},
{"sql-getpwuid", ARG_SQL_GETPWUID, N_("QUERY"), OPTION_HIDDEN,
N_("SQL query to retrieve a passwd entry based on UID"), 0},
{"sql-getpass", ARG_SQL_GETPASS, N_("QUERY"), OPTION_HIDDEN,
N_("SQL query to retrieve a password from the database"), 0},
{"sql-host", ARG_SQL_HOST, N_("HOSTNAME"), OPTION_HIDDEN,
N_("Name or IP of MySQL server to connect to"), 0},
{"sql-user", ARG_SQL_USER, N_("NAME"), OPTION_HIDDEN,
N_("SQL user name"), 0},
{"sql-passwd", ARG_SQL_PASSWD, N_("STRING"), OPTION_HIDDEN,
N_("SQL connection password"), 0},
{"sql-db", ARG_SQL_DB, N_("STRING"), OPTION_HIDDEN,
N_("Name of the database to connect to"), 0},
{"sql-port", ARG_SQL_PORT, N_("NUMBER"), OPTION_HIDDEN,
N_("Port to use"), 0},
{"sql-password-type", ARG_SQL_MU_PASSWORD_TYPE, N_("STRING"), OPTION_HIDDEN,
N_("Type of password returned by --sql-getpass query. STRING is one of: plain, hash, scrambled"), 0},
{"sql-field-map", ARG_SQL_FIELD_MAP, N_("MAP"), OPTION_HIDDEN,
N_("Declare a name translation map for SQL fields in results of sql-getpwnam and "
"sql-getpwuid queries"), 0},
{ NULL, 0, NULL, 0, NULL, 0 }
};
static error_t
mu_sql_argp_parser (int key, char *arg, struct argp_state *state)
{
int rc, err;
switch (key)
{
case ARG_SQL_INTERFACE:
sql_interface = mu_sql_interface_index (arg);
if (sql_interface == 0)
argp_error (state, _("Unknown SQL interface `%s'"), arg);
break;
case ARG_SQL_GETPWNAM:
mu_sql_getpwnam_query = arg;
break;
case ARG_SQL_GETPWUID:
mu_sql_getpwuid_query = arg;
break;
case ARG_SQL_GETPASS:
mu_sql_getpass_query = arg;
break;
case ARG_SQL_HOST:
mu_sql_host = arg;
break;
case ARG_SQL_USER:
mu_sql_user = arg;
break;
case ARG_SQL_PASSWD:
mu_sql_passwd = arg;
break;
case ARG_SQL_DB:
mu_sql_db = arg;
break;
case ARG_SQL_PORT:
mu_sql_port = strtoul (arg, NULL, 0);
break;
case ARG_SQL_MU_PASSWORD_TYPE:
if (set_sql_password_type (arg))
argp_error (state, _("Unknown password type `%s'"), arg);
break;
case ARG_SQL_FIELD_MAP:
rc = mutil_parse_field_map (arg, &sql_field_map, &err);
if (rc)
argp_error (state, _("Error near element %d: %s"),
err, mu_strerror (rc));
break;
default:
return ARGP_ERR_UNKNOWN;
}
return 0;
}
static struct argp mu_sql_argp = {
mu_sql_argp_option,
mu_sql_argp_parser,
};
/* Resource file configuration */
static int
cb_iface (mu_cfg_locus_t *locus, void *data, char *arg)
{
sql_interface = mu_sql_interface_index (arg);
if (sql_interface == 0)
mu_error (_("%s:%d: Unknown SQL interface `%s'"),
locus->file, locus->line, arg);
return 0;
}
static int
cb_password_type (mu_cfg_locus_t *locus, void *data, char *arg)
{
if (set_sql_password_type (arg))
mu_error (_("%s:%d: Unknown password type `%s'"),
locus->file, locus->line, arg);
return 0;
}
static int
cb_field_map (mu_cfg_locus_t *locus, void *data, char *arg)
{
int err;
int rc = mutil_parse_field_map (arg, &sql_field_map, &err);
if (rc)
mu_error (_("%s:%d: Error near element %d: %s"),
locus->file, locus->line, err, mu_strerror (rc));
return 0;
}
static struct mu_cfg_param mu_sql_param[] = {
{ "interface", mu_cfg_callback, NULL, cb_iface },
{ "getwpnam", mu_cfg_string, &mu_sql_getpwnam_query },
{ "getpwuid", mu_cfg_string, &mu_sql_getpwuid_query },
{ "getpass", mu_cfg_string, &mu_sql_getpass_query },
{ "host", mu_cfg_string, &mu_sql_host },
{ "user", mu_cfg_string, &mu_sql_user },
{ "passwd", mu_cfg_string, &mu_sql_passwd },
{ "db", mu_cfg_string, &mu_sql_db },
{ "port", mu_cfg_int, &mu_sql_port },
{ "password-type", mu_cfg_callback, NULL, cb_password_type },
{ "field-map", mu_cfg_callback, NULL, cb_field_map },
{ NULL }
};
static int
decode_tuple_v1_0 (mu_sql_connection_t conn, int n,
......@@ -405,7 +221,7 @@ decode_tuple_v1_0 (mu_sql_connection_t conn, int n,
static int
get_field (mu_sql_connection_t conn, const char *id, char **ret, int mandatory)
{
const char **name = mu_assoc_ref (sql_field_map, id);
const char **name = mu_assoc_ref (mu_sql_module_config.field_map, id);
int rc = mu_sql_get_field (conn, 0, name ? *name : id, ret);
if (rc)
{
......@@ -536,7 +352,7 @@ static int
decode_tuple (mu_sql_connection_t conn, int n,
struct mu_auth_data **return_data)
{
if (sql_field_map)
if (mu_sql_module_config.field_map)
return decode_tuple_new (conn, n, return_data);
else
return decode_tuple_v1_0 (conn, n, return_data);
......@@ -556,17 +372,18 @@ mu_auth_sql_by_name (struct mu_auth_data **return_data,
if (!key)
return EINVAL;
query_str = mu_sql_expand_query (mu_sql_getpwnam_query, key);
query_str = mu_sql_expand_query (mu_sql_module_config.getpwnam_query, key);
if (!query_str)
return MU_ERR_FAILURE;
status = mu_sql_connection_init (&conn,
sql_interface,
mu_sql_host,
mu_sql_port,
mu_sql_user, mu_sql_passwd,
mu_sql_db);
mu_sql_module_config.interface,
mu_sql_module_config.host,
mu_sql_module_config.port,
mu_sql_module_config.user,
mu_sql_module_config.passwd,
mu_sql_module_config.db);
if (status)
{
......@@ -638,17 +455,19 @@ mu_auth_sql_by_uid (struct mu_auth_data **return_data,
return EINVAL;
snprintf (uidstr, sizeof (uidstr), "%u", *(uid_t*)key);
query_str = mu_sql_expand_query (mu_sql_getpwuid_query, uidstr);
query_str = mu_sql_expand_query (mu_sql_module_config.getpwuid_query,
uidstr);
if (!query_str)
return ENOMEM;
status = mu_sql_connection_init (&conn,
sql_interface,
mu_sql_host,
mu_sql_port,
mu_sql_user, mu_sql_passwd,
mu_sql_db);
mu_sql_module_config.interface,
mu_sql_module_config.host,
mu_sql_module_config.port,
mu_sql_module_config.user,
mu_sql_module_config.passwd,
mu_sql_module_config.db);
if (status)
{
......@@ -713,17 +532,18 @@ mu_sql_getpass (const char *username, char **passwd)
int status;
char *sql_pass;
query_str = mu_sql_expand_query (mu_sql_getpass_query, username);
query_str = mu_sql_expand_query (mu_sql_module_config.getpass_query, username);
if (!query_str)
return MU_ERR_FAILURE;
status = mu_sql_connection_init (&conn,
sql_interface,
mu_sql_host,
mu_sql_port,
mu_sql_user, mu_sql_passwd,
mu_sql_db);
mu_sql_module_config.interface,
mu_sql_module_config.host,
mu_sql_module_config.port,
mu_sql_module_config.user,
mu_sql_module_config.passwd,
mu_sql_module_config.db);
if (status)
{
......@@ -804,7 +624,7 @@ mu_sql_authenticate (struct mu_auth_data **return_data MU_ARG_UNUSED,
if ((rc = mu_sql_getpass (auth_data->name, &sql_pass)))
return rc;
switch (mu_sql_password_type)
switch (mu_sql_module_config.password_type)
{
case password_hash:
rc = strcmp (sql_pass, crypt (pass, sql_pass));
......@@ -832,6 +652,32 @@ 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 (void *data)
{
struct mu_sql_module_config *cfg = data;
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
......@@ -844,11 +690,9 @@ mu_sql_authenticate (struct mu_auth_data **return_data MU_ARG_UNUSED,
struct mu_auth_module mu_auth_sql_module = {
"sql",
#ifdef USE_SQL
&mu_sql_argp,
mu_sql_param,
mu_sql_module_init,
#else
NULL,
NULL,
#endif
mu_sql_authenticate,
NULL,
......
......@@ -40,15 +40,20 @@
#include <mailutils/nls.h>
#include <mailutils/mailbox.h>
extern int sql_interface;
extern char *mu_sql_getpwnam_query;
extern char *mu_sql_getpass_query;
extern char *mu_sql_getpwuid_query;
extern char *mu_sql_host;
extern char *mu_sql_user;
extern char *mu_sql_passwd;
extern char *mu_sql_db;
extern char *mu_sql_socket;
extern int mu_sql_port;
struct mu_internal_sql_config
{
int 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;
mu_assoc_t field_map;
};
extern struct mu_internal_sql_config mu_sql_module_config;
......
......@@ -27,7 +27,6 @@
#include <sys/stat.h>
#include <string.h>
#include <mailutils/argp.h>
#include <mailutils/error.h>
#include <mailutils/mu_auth.h>
#include <mailutils/tls.h>
......@@ -37,155 +36,69 @@
#include <lbuf.h>
#ifdef WITH_TLS
#include <gnutls/gnutls.h>
#define DH_BITS 768
static gnutls_dh_params dh_params;
static gnutls_certificate_server_credentials x509_cred;
static char *ssl_cert = NULL;
static char *ssl_key = NULL;
static char *ssl_cafile = NULL;
#define ARG_TLS 1
#define ARG_SSL_CERT 2
#define ARG_SSL_KEY 3
#define ARG_SSL_CAFILE 4
static struct argp_option _tls_argp_options[] = {
{"ssl-cert", ARG_SSL_CERT, N_("FILE"), OPTION_HIDDEN,
N_("Specify SSL certificate file"), 0},
{"ssl-key", ARG_SSL_KEY, N_("FILE"), OPTION_HIDDEN,
N_("Specify SSL certificate key"), },
{"ssl-cafile", ARG_SSL_CAFILE, N_("FILE"), OPTION_HIDDEN,
N_("Specify trusted CAs file"), 0},
{NULL, 0, NULL, 0, NULL, 0}
};
struct mu_tls_module_config mu_tls_module_config;
static error_t
_tls_argp_parser (int key, char *arg, struct argp_state *state)
int
mu_tls_module_init (void *data)
{
static int tls_enable = 1;
switch (key)
if (data)
{
case ARG_TLS:
if (!arg || strcasecmp (arg, "yes") == 0)
tls_enable = 1;
else if (strcasecmp (arg, "no") == 0)
tls_enable = 0;
break;
case ARG_SSL_CERT:
ssl_cert = arg;
break;
case ARG_SSL_KEY:
ssl_key = arg;
break;
case ARG_SSL_CAFILE:
ssl_cafile = arg;
break;
case ARGP_KEY_FINI:
if (tls_enable)
memcpy (&mu_tls_module_config, data, sizeof mu_tls_module_config);
#ifdef WITH_TLS
if (mu_tls_module_config.client_enable)
mu_init_tls_libs ();
break;
default:
return ARGP_ERR_UNKNOWN;
#endif
}
return 0;
}
static struct argp _tls_argp = {
_tls_argp_options,
_tls_argp_parser
};
static struct argp_child _tls_argp_child = {
&_tls_argp,
0,
NULL,
0
};
void
mu_tls_init_argp ()
{
if (mu_register_capa ("tls", &_tls_argp_child, NULL))
{
mu_error (_("INTERNAL ERROR: cannot register argp capability tls"));
abort ();
}
}
static struct argp_option _tls_argp_client_options[] = {
{"tls", ARG_TLS, N_("BOOL"), OPTION_ARG_OPTIONAL,
N_("Enable TLS support") },
{NULL, 0, NULL, 0, NULL, 0}
};
#ifdef WITH_TLS
static struct argp _tls_client_argp = {
_tls_argp_client_options,
_tls_argp_parser
};
#include <gnutls/gnutls.h>
static struct argp_child _tls_argp_client_child = {
&_tls_client_argp,
0,
NULL,
0
};
#define DH_BITS 768
void
mu_tls_init_client_argp ()
{
if (mu_register_capa ("tls", &_tls_argp_client_child, NULL))
{
mu_error (_("INTERNAL ERROR: cannot register argp capability tls"));
abort ();
}
}
static gnutls_dh_params dh_params;
static gnutls_certificate_server_credentials x509_cred;
int
mu_check_tls_environment (void)
{
/* Return: zero means NOT READY, one means READY */
if (ssl_cert && ssl_key)
if (mu_tls_module_config.ssl_cert && mu_tls_module_config.ssl_key)
{
struct stat st;
if (stat (ssl_cert, &st) == -1)
if (stat (mu_tls_module_config.ssl_cert, &st) == -1)
{
mu_error ("%s: %s.", ssl_cert, mu_strerror (errno));
mu_error ("%s: %s.", mu_tls_module_config.ssl_cert,
mu_strerror (errno));
return 0;
}
if (!(st.st_mode & S_IFREG) || !(st.st_mode & S_IFLNK))
{
mu_error (_("%s is not a regular file or a symbolic link."),
ssl_cert);
mu_tls_module_config.ssl_cert);
return 0;
}
if (stat (ssl_key, &st) == -1)
if (stat (mu_tls_module_config.ssl_key, &st) == -1)
{
mu_error ("%s: %s.", ssl_key, mu_strerror(errno));
mu_error ("%s: %s.", mu_tls_module_config.ssl_key,
mu_strerror(errno));
return 0;
}
if (!(st.st_mode & S_IFREG) || !(st.st_mode & S_IFLNK))
{
mu_error (_("%s is not a regular file or a symbolic link."),
ssl_key);
mu_tls_module_config.ssl_key);
return 0;
}
if ((st.st_mode & S_IRWXG) || (st.st_mode & S_IRWXO))
{
mu_error (_("Wrong permissions on %s. Set 0600"), ssl_key);
mu_error (_("Wrong permissions on %s. Set 0600"),
mu_tls_module_config.ssl_key);
return 0;
}
}
......@@ -507,12 +420,14 @@ _tls_open (mu_stream_t stream)
gnutls_certificate_allocate_credentials (&x509_cred);
if (ssl_cafile)
gnutls_certificate_set_x509_trust_file (x509_cred, ssl_cafile,
if (mu_tls_module_config.ssl_cafile)
gnutls_certificate_set_x509_trust_file (x509_cred,
mu_tls_module_config.ssl_cafile,
GNUTLS_X509_FMT_PEM);
rc = gnutls_certificate_set_x509_key_file (x509_cred,
ssl_cert, ssl_key,
mu_tls_module_config.ssl_cert,
mu_tls_module_config.ssl_key,
GNUTLS_X509_FMT_PEM);
if (rc < 0)
{
......@@ -561,10 +476,10 @@ prepare_client_session (struct _tls_stream *s)
gnutls_mac_set_priority (s->session, mac_priority);
gnutls_certificate_allocate_credentials (&x509_cred);
if (ssl_cafile)
if (mu_tls_module_config.ssl_cafile)
{
rc = gnutls_certificate_set_x509_trust_file (x509_cred,
ssl_cafile,
mu_tls_module_config.ssl_cafile,
GNUTLS_X509_FMT_PEM);
if (rc < 0)
{
......
......@@ -49,15 +49,27 @@
#include <mailutils/list.h>
#include <mailutils/iterator.h>
#include <mailutils/mailbox.h>
#include <mailutils/argp.h>
#include <mailutils/mu_auth.h>
#include <mailutils/nls.h>
#include <mailutils/errno.h>
#ifdef ENABLE_VIRTUAL_DOMAINS
/* FIXME: Make global, prefix with mu_ */
static char *site_virtual_pwddir = SITE_VIRTUAL_PWDDIR;
int
mu_virtual_module_init (void *data)
{
if (data)
{
site_virtual_pwddir = strdup (data);
if (!site_virtual_pwddir)
return 1;
}
return 0;
}
static struct passwd *
getpwnam_virtual (const char *u)
{
......@@ -173,34 +185,6 @@ mu_auth_virt_domain_by_name (struct mu_auth_data **return_data,
return rc;
}
#define ARG_PWDDIR 1
static error_t
mu_virt_argp_parser (int key, char *arg, struct argp_state *state)
{
switch (key)
{
case ARG_PWDDIR:
site_virtual_pwddir = arg;
break;
default:
return ARGP_ERR_UNKNOWN;
}
return 0;
}
static struct argp_option mu_virt_argp_option[] = {
{ "virtual-passwd-dir", ARG_PWDDIR, N_("DIR"), OPTION_HIDDEN,
N_("Search for virtual passwd file in DIR"), 0},
{ NULL, 0, NULL, 0, NULL, 0 }
};
struct argp mu_virt_argp = {
mu_virt_argp_option,
mu_virt_argp_parser,
};
#else
static int
mu_auth_virt_domain_by_name (struct mu_auth_data **return_data MU_ARG_UNUSED,
......@@ -215,11 +199,9 @@ mu_auth_virt_domain_by_name (struct mu_auth_data **return_data MU_ARG_UNUSED,
struct mu_auth_module mu_auth_virtual_module = {
"virtdomain",
#ifdef ENABLE_VIRTUAL_DOMAINS
&mu_virt_argp,
NULL,
mu_virtual_module_init,
#else
NULL,
NULL,
#endif
mu_auth_nosupport,
NULL,
......
......@@ -24,7 +24,7 @@ sbin_PROGRAMS = comsatd
comsatd_SOURCES = action.c cfg.c comsat.c comsat.h
comsatd_LDADD = \
../lib/libmuaux.la\
${MU_APP_LIBRARIES}\
${MU_LIB_MBOX}\
${MU_LIB_IMAP}\
${MU_LIB_POP}\
......
......@@ -18,6 +18,7 @@
MA 02110-1301 USA */
#include "comsat.h"
#include "muinit.h"
#ifndef PATH_DEV
# define PATH_DEV "/dev"
......@@ -90,7 +91,7 @@ static const char *comsat_argp_capa[] = {
# define MAXHOSTNAMELEN 64
#endif
struct daemon_param daemon_param = {
struct mu_gocs_daemon default_gocs_daemon = {
MODE_INTERACTIVE, /* Start in interactive (inetd) mode */
20, /* Default maximum number of children.
Currently unused */
......@@ -121,10 +122,6 @@ comsatd_parse_opt (int key, char *arg, struct argp_state *state)
{
switch (key)
{
case ARGP_KEY_INIT:
state->child_inputs[0] = state->input;
break;
case 'c':
config_file = arg;
break;
......@@ -150,8 +147,9 @@ main (int argc, char **argv)
mu_init_nls ();
mu_argp_init (program_version, NULL);
mu_argp_parse (&argp, &argc, &argv, 0, comsat_argp_capa,
&ind, &daemon_param);
mu_gocs_daemon = default_gocs_daemon;
if (mu_app_init (&argp, comsat_argp_capa, NULL, argc, argv, 0, &ind, NULL))
exit (1);
argc -= ind;
argv += ind;
......@@ -191,7 +189,7 @@ main (int argc, char **argv)
exit (0);
}
if (daemon_param.timeout > 0 && daemon_param.mode == MODE_DAEMON)
if (mu_gocs_daemon.timeout > 0 && mu_gocs_daemon.mode == MODE_DAEMON)
{
mu_error (_("--timeout and --daemon are incompatible"));
exit (EXIT_FAILURE);
......@@ -199,7 +197,7 @@ main (int argc, char **argv)
comsat_init ();
if (daemon_param.mode == MODE_DAEMON)
if (mu_gocs_daemon.mode == MODE_DAEMON)
{
/* Preserve invocation arguments */
xargc = argc;
......@@ -216,8 +214,8 @@ main (int argc, char **argv)
chdir ("/");
if (daemon_param.mode == MODE_DAEMON)
comsat_daemon (daemon_param.port);
if (mu_gocs_daemon.mode == MODE_DAEMON)
comsat_daemon (mu_gocs_daemon.port);
else
c = comsat_main (0);
......
......@@ -46,7 +46,6 @@
# include <strings.h>
#endif
#include <mailutils/argp.h>
#include <mailutils/body.h>
#include <mailutils/errno.h>
#include <mailutils/error.h>
......@@ -60,6 +59,7 @@
#include <mailutils/mu_auth.h>
#include <mailutils/argcv.h>
#include <mailutils/nls.h>
#include <mailutils/daemon.h>
#ifndef INADDR_NONE
# define INADDR_NONE -1
......
......@@ -23,8 +23,8 @@ bin_PROGRAMS = mailutils-config
mailutils_config_SOURCES = mailutils-config.c
mailutils_config_LDADD = \
../lib/libmuaux.la \
${MU_LIB_MAILUTILS} \
${MU_APP_LIBRARIES}\
${MU_LIB_MAILUTILS}\
@MU_COMMON_LIBRARIES@
mailutils_config_CFLAGS = -DCOMPILE_FLAGS="\"-I$(includedir)\"" \
......
......@@ -21,8 +21,8 @@
#endif
#include <string.h>
#include <mailutils/mailutils.h>
#include <mailutils/argp.h>
#include <mu_asprintf.h>
#include "muinit.h"
const char *program_version = "mailutils-config (" PACKAGE_STRING ")";
static char doc[] = N_("GNU mailutils-config -- Display compiler and loader options needed for building a program with mailutils");
......@@ -166,7 +166,7 @@ main (int argc, char **argv)
int index;
mu_argp_init (program_version, NULL);
if (mu_argp_parse (&argp, &argc, &argv, 0, argp_capa, &index, NULL))
if (mu_app_init (&argp, argp_capa, NULL, argc, argv, 0, &index, NULL))
{
argp_help (&argp, stdout, ARGP_HELP_SEE, program_invocation_short_name);
return 1;
......
......@@ -46,13 +46,15 @@ AC_SUBST(MU_LIB_POP,'${top_builddir}/libproto/pop/libmu_pop.la')
AC_SUBST(MU_LIB_SIEVE,'${top_builddir}/libsieve/libsieve.la')
AC_SUBST(MU_LIB_SCM,'${top_builddir}/libmu_scm/libmu_scm.la')
AC_SUBST(MU_LIB_CPP,'${top_builddir}/libmu_cpp/libmu_cpp.la')
AC_SUBST(MU_LIB_ARGP,'${top_builddir}/libargp/libargp.la')
dnl Other variables
AC_SUBST(SIEVE_MODDIR,'$(libdir)/$(PACKAGE)')
AC_SUBST(MU_COMMON_LIBRARIES,'$(LTLIBINTL) $(LTLIBICONV)')
AC_SUBST(MU_APP_LIBRARIES,'../lib/libmuaux.la ../libargp/libargp.a -L${top_builddir}/libcfg -lmucfg')
AC_SUBST(MU_COMMON_INCLUDES,'-I${srcdir} -I${top_srcdir}/include -I${top_srcdir}/lib -I${top_builddir} -I${top_builddir}/include -I${top_builddir}/include/mailutils/gnu -I${top_srcdir}/mailbox')
AC_SUBST(MU_COMMON_INCLUDES,'-I${srcdir} -I${top_srcdir}/include -I${top_srcdir}/lib -I${top_builddir} -I${top_builddir}/include -I${top_builddir}/include/mailutils/gnu -I${top_srcdir}/mailbox -I${top_srcdir}/libargp -I${top_srcdir}/libcfg')
dnl Check for programs
AC_PROG_CC
......@@ -1169,6 +1171,8 @@ AC_CONFIG_FILES([Makefile
libproto/include/Makefile
libsieve/Makefile
libsieve/extensions/Makefile
libargp/Makefile
libcfg/Makefile
maidag/Makefile
mail/Makefile
mail/testsuite/Makefile
......
......@@ -22,7 +22,7 @@ INCLUDES = @MU_COMMON_INCLUDES@
bin_PROGRAMS = dotlock
dotlock_LDADD = \
../lib/libmuaux.la\
${MU_APP_LIBRARIES}\
${MU_LIB_MAILUTILS}\
@MU_COMMON_LIBRARIES@
......
......@@ -27,11 +27,12 @@
#endif
#include <unistd.h>
#include <mailutils/argp.h>
#include <mailutils/errno.h>
#include <mailutils/locker.h>
#include <mailutils/nls.h>
#include "muinit.h"
const char *program_version = "GNU dotlock (" PACKAGE_STRING ")";
static char doc[] =
N_("GNU dotlock -- lock mail spool files")
......@@ -132,6 +133,7 @@ struct mu_cfg_param dotlock_cfg_param[] = {
const char *dotlock_capa[] = {
"license",
"common",
NULL
};
......@@ -151,11 +153,13 @@ main (int argc, char *argv[])
if (setegid (usergid) < 0)
return MU_DL_EX_ERROR;
mu_argp_init (program_version, NULL);
argp_err_exit_status = MU_DL_EX_ERROR;
mu_argp_set_config_param (dotlock_cfg_param);
mu_argp_parse (&argp, &argc, &argv, 0, dotlock_capa, NULL, NULL);
mu_argp_init (program_version, NULL);
if (mu_app_init (&argp, dotlock_capa, dotlock_cfg_param,
argc, argv, 0, NULL, NULL))
exit (1);
if (force)
{
force *= 60;
......
......@@ -125,6 +125,9 @@ lsf_LDADD = \
${MU_LIB_MAILUTILS}
muauth_LDADD = \
${MU_APP_LIBRARIES}\
${MU_LIB_AUTH}\
@MU_AUTHLIBS@ \
${MU_LIB_MAILUTILS}
muemail_LDADD = ${MU_APP_LIBRARIES}
\ No newline at end of file
......
......@@ -25,6 +25,7 @@
#include <ctype.h>
#include <string.h>
#include <mailutils/mailutils.h>
#include "muinit.h"
const char *program_version = "muauth (" PACKAGE_STRING ")";
static char doc[] =
......@@ -90,7 +91,9 @@ main (int argc, char * argv [])
MU_AUTH_REGISTER_ALL_MODULES ();
mu_argp_init (program_version, NULL);
mu_argp_parse (&argp, &argc, &argv, 0, capa, &index, NULL);
if (mu_app_init (&argp, capa, NULL, argc, argv, 0, &index, NULL))
exit (1);
if (index == argc)
{
mu_error ("not enough arguments, try `%s --help' for more info",
......
......@@ -17,10 +17,9 @@
MA 02110-1301 USA */
#include <stdlib.h>
#include <mailutils/mutil.h>
#include <mailutils/argp.h>
#include <stdio.h>
#include <mailutils/mutil.h>
#include "muinit.h"
const char *capa[] = {
"address",
......@@ -32,8 +31,8 @@ main (int argc, char *argv[])
{
int arg = 1;
if (mu_argp_parse (NULL, &argc, &argv, 0, capa, &arg, NULL))
abort ();
if (mu_app_init (NULL, capa, NULL, argc, argv, 0, &arg, NULL))
exit (1);
if (!argv[arg])
printf ("current user -> %s\n", mu_get_user_email (0));
......
......@@ -30,7 +30,7 @@ frm_LDADD = $(common_ldadd)
from_LDADD = $(common_ldadd)
common_ldadd = \
../lib/libmuaux.la\
${MU_APP_LIBRARIES}\
${MU_LIB_MBOX}\
${MU_LIB_IMAP}\
${MU_LIB_POP}\
......
......@@ -218,9 +218,6 @@ static const char *frm_argp_capa[] = {
"common",
"license",
"mailbox",
#ifdef WITH_TLS
"tls",
#endif
NULL
};
......@@ -366,12 +363,13 @@ main (int argc, char **argv)
/* register the formats. */
mu_register_all_mbox_formats ();
mu_argp_init (program_version, NULL);
#ifdef WITH_TLS
mu_tls_init_client_argp ();
mu_gocs_register ("tls", mu_tls_module_init);
#endif
mu_argp_parse (&argp, &argc, &argv, 0, frm_argp_capa, &c, NULL);
mu_argp_init (program_version, NULL);
if (mu_app_init (&argp, frm_argp_capa, NULL, argc, argv, 0, &c, NULL))
exit (1);
/* have an argument */
if (c == argc)
......
......@@ -47,7 +47,6 @@
#endif
#include <mailutils/address.h>
#include <mailutils/argp.h>
#include <mailutils/attribute.h>
#include <mailutils/debug.h>
#include <mailutils/errno.h>
......@@ -65,6 +64,8 @@
#include <mailutils/mutil.h>
#include <mailutils/mime.h>
#include "muinit.h"
typedef int (*frm_select_t) (size_t index, mu_message_t msg);
extern char *show_field; /* Show this header field instead of the default
......
......@@ -118,10 +118,8 @@ main (int argc, char **argv)
mu_register_all_mbox_formats ();
mu_argp_init (program_version, NULL);
#ifdef WITH_TLS
mu_tls_init_client_argp ();
#endif
mu_argp_parse (&argp, &argc, &argv, 0, capa, &c, NULL);
if (mu_app_init (&argp, capa, NULL, argc, argv, 0, &c, NULL))
exit (1);
if (argc - c > 1)
{
......
......@@ -25,7 +25,7 @@ bin_PROGRAMS=@GUIMB@
EXTRA_PROGRAMS=guimb
guimb_SOURCES=main.c collect.c util.c guimb.h
guimb_LDADD = \
../lib/libmuaux.la\
${MU_APP_LIBRARIES}\
../libmu_scm/libmu_scm.la\
${MU_LIB_MBOX}\
${MU_LIB_IMAP}\
......
......@@ -41,7 +41,6 @@
#include <mailutils/stream.h>
#include <mailutils/guile.h>
#include <mailutils/nls.h>
#include <mailutils/argp.h>
#include <mailutils/list.h>
#include <mailutils/mutil.h>
#include <mailutils/attribute.h>
......
......@@ -18,6 +18,7 @@
MA 02110-1301 USA */
#include "guimb.h"
#include "muinit.h"
char *program_file;
char *program_expr;
......@@ -155,8 +156,10 @@ main (int argc, char *argv[])
mu_init_nls ();
append_arg ("");
mu_argp_init (program_version, NULL);
mu_argp_parse (&argp, &argc, &argv, 0, guimb_argp_capa, &index, &c);
if (mu_app_init (&argp, guimb_argp_capa, NULL, argc, argv, 0, &index, &c))
exit (1);
for (; c < argc; c++)
append_arg (argv[c]);
......
......@@ -62,7 +62,7 @@ imap4d_SOURCES = \
imap4d_LDADD = \
@IMAP_AUTHOBJS@\
../lib/libmuaux.la\
${MU_APP_LIBRARIES}\
${MU_LIB_MBOX}\
${MU_LIB_MH}\
${MU_LIB_MAILDIR}\
......
......@@ -49,7 +49,7 @@ imap4d_idle (struct imap4d_command *command, char *arg)
if (rc)
break;
}
else if (time (NULL) - start > daemon_param.timeout)
else if (time (NULL) - start > mu_gocs_daemon.timeout)
imap4d_bye (ERR_TIMEOUT);
imap4d_sync ();
......
......@@ -21,6 +21,7 @@
#ifdef WITH_GSASL
# include <mailutils/gsasl.h>
#endif
#include "muinit.h"
mu_mailbox_t mbox;
char *homedir;
......@@ -28,7 +29,7 @@ int state = STATE_NONAUTH;
int debug_mode = 0;
struct mu_auth_data *auth_data;
struct daemon_param daemon_param = {
struct mu_gocs_daemon default_gocs_daemon = {
MODE_INTERACTIVE, /* Start in interactive (inetd) mode */
20, /* Default maximum number of children */
143, /* Standard IMAP4 port */
......@@ -87,12 +88,6 @@ static struct argp argp = {
static const char *imap4d_capa[] = {
"daemon",
"auth",
#ifdef WITH_TLS
"tls",
#endif /* WITH_TLS */
#ifdef WITH_GSASL
"gsasl",
#endif
"common",
"mailbox",
"logging",
......@@ -196,16 +191,17 @@ main (int argc, char **argv)
MU_AUTH_REGISTER_ALL_MODULES ();
imap4d_capability_init ();
mu_argp_init (program_version, NULL);
mu_gocs_daemon = default_gocs_daemon;
#ifdef WITH_TLS
mu_tls_init_argp ();
mu_gocs_register ("tls", mu_tls_module_init);
#endif /* WITH_TLS */
#ifdef WITH_GSASL
mu_gsasl_init_argp ();
mu_gocs_register ("gsasl", mu_gsasl_module_init);
#endif
mu_argp_set_config_param (imap4d_cfg_param);
mu_argp_parse (&argp, &argc, &argv, 0, imap4d_capa, NULL, &daemon_param);
mu_argp_init (program_version, NULL);
if (mu_app_init (&argp, imap4d_capa, imap4d_cfg_param,
argc, argv, 0, NULL, NULL))
exit (1);
if (login_disabled)
imap4d_capability_add (IMAP_CAPA_LOGINDISABLED);
......@@ -218,11 +214,11 @@ main (int argc, char **argv)
auth_gsasl_init ();
#ifdef USE_LIBPAM
if (!pam_service)
pam_service = "gnu-imap4d";
if (!mu_pam_service)
mu_pam_service = "gnu-imap4d";
#endif
if (daemon_param.mode == MODE_INTERACTIVE && isatty (0))
if (mu_gocs_daemon.mode == MODE_INTERACTIVE && isatty (0))
{
/* If input is a tty, switch to debug mode */
debug_mode = 1;
......@@ -261,7 +257,7 @@ main (int argc, char **argv)
/*signal (SIGPIPE, SIG_IGN); */
signal (SIGABRT, imap4d_signal);
if (daemon_param.mode == MODE_DAEMON)
if (mu_gocs_daemon.mode == MODE_DAEMON)
imap4d_daemon_init ();
else
{
......@@ -278,9 +274,9 @@ main (int argc, char **argv)
umask (S_IROTH | S_IWOTH | S_IXOTH); /* 007 */
if (daemon_param.pidfile)
if (mu_gocs_daemon.pidfile)
{
mu_daemon_create_pidfile (daemon_param.pidfile);
mu_daemon_create_pidfile (mu_gocs_daemon.pidfile);
}
/* Check TLS environment, i.e. cert and key files */
......@@ -289,8 +285,8 @@ main (int argc, char **argv)
#endif /* WITH_TLS */
/* Actually run the daemon. */
if (daemon_param.mode == MODE_DAEMON)
imap4d_daemon (daemon_param.maxchildren, daemon_param.port);
if (mu_gocs_daemon.mode == MODE_DAEMON)
imap4d_daemon (mu_gocs_daemon.maxchildren, mu_gocs_daemon.port);
/* exit (0) -- no way out of daemon except a signal. */
else
status = imap4d_mainloop (fileno (stdin), stdin, stdout);
......
......@@ -71,7 +71,6 @@
#endif
#include <mailutils/address.h>
#include <mailutils/argp.h>
#include <mailutils/attribute.h>
#include <mailutils/body.h>
#include <mailutils/daemon.h>
......@@ -93,6 +92,8 @@
#include <mailutils/stream.h>
#include <mailutils/tls.h>
#include <mailutils/url.h>
#include <mailutils/daemon.h>
#include <mailutils/pam.h>
#include <mu_asprintf.h>
#include <mu_umaxtostr.h>
......@@ -161,8 +162,8 @@ extern char *rootdir;
extern int state;
extern size_t children;
extern int is_virtual;
extern struct daemon_param daemon_param;
extern struct mu_auth_data *auth_data;
extern const char *program_version;
extern int login_disabled;
extern int tls_required;
......
......@@ -360,7 +360,7 @@ util_send (const char *format, ...)
if (!buf)
imap4d_bye (ERR_NO_MEM);
if (daemon_param.transcript)
if (mu_gocs_daemon.transcript)
syslog (LOG_DEBUG, "sent: %s", buf);
status = mu_stream_sequential_write (ostream, buf, strlen (buf));
......@@ -414,7 +414,7 @@ util_out (int rc, const char *format, ...)
if (!buf)
imap4d_bye (ERR_NO_MEM);
if (daemon_param.transcript)
if (mu_gocs_daemon.transcript)
syslog (LOG_DEBUG, "sent: %s", buf);
status = mu_stream_sequential_write (ostream, buf, strlen (buf));
......@@ -455,7 +455,7 @@ util_finish (struct imap4d_command *command, int rc, const char *format, ...)
strcat (buf, tempbuf);
free (tempbuf);
if (daemon_param.transcript)
if (mu_gocs_daemon.transcript)
syslog (LOG_DEBUG, "sent: %s\r\n", buf);
mu_stream_sequential_write (ostream, buf, strlen (buf));
......@@ -503,7 +503,7 @@ imap4d_readline (void)
size_t sz;
int rc;
alarm (daemon_param.timeout);
alarm (mu_gocs_daemon.timeout);
rc = mu_stream_sequential_readline (istream, buffer, sizeof (buffer), &sz);
if (sz == 0)
{
......@@ -577,7 +577,7 @@ imap4d_readline (void)
}
}
while (number > 0 || (total && line[total - 1] != '\n'));
if (daemon_param.transcript)
if (mu_gocs_daemon.transcript)
syslog (LOG_DEBUG, "recv: %s", line);
return line;
}
......
......@@ -21,6 +21,6 @@
int
imap4d_version (struct imap4d_command *command, char *arg)
{
util_send ("* %s GNU %s\r\n", command->name, argp_program_version);
util_send ("* %s GNU %s\r\n", command->name, program_version);
return util_finish (command, RESP_OK, "Completed");
}
......
......@@ -29,53 +29,56 @@ DISTCLEANFILES = types.h
pkginclude_DATA = types.h
pkginclude_HEADERS = \
address.h \
argcv.h \
argp.h \
assoc.h \
attribute.h \
auth.h \
body.h \
cfg.h \
compat.h \
daemon.h \
debug.h \
envelope.h \
errno.h \
error.h \
filter.h \
folder.h \
gsasl.h \
guile.h \
header.h \
iterator.h \
libsieve.h \
list.h \
locker.h \
mailbox.h \
mailcap.h \
mailer.h \
mailutils.h \
message.h \
mime.h \
monitor.h \
mu_auth.h \
mutil.h \
nls.h \
nntp.h \
observer.h \
parse822.h \
pop3.h \
property.h \
refcount.h \
registrar.h \
stream.h \
sql.h \
tls.h \
address.h\
argcv.h\
assoc.h\
attribute.h\
auth.h\
body.h\
cfg.h\
compat.h\
daemon.h\
debug.h\
envelope.h\
errno.h\
error.h\
filter.h\
folder.h\
gocs.h\
gsasl.h\
guile.h\
header.h\
iterator.h\
libsieve.h\
list.h\
locker.h\
mailbox.h\
mailcap.h\
mailer.h\
mailutils.h\
message.h\
mime.h\
monitor.h\
mu_auth.h\
mutil.h\
nls.h\
nntp.h\
observer.h\
pam.h\
parse822.h\
pop3.h\
property.h\
radius.h\
refcount.h\
registrar.h\
stream.h\
syslog.h\
sql.h\
tls.h\
url.h
nobase_pkginclude_HEADERS = \
sys/nntp.h \
sys/nntp.h\
sys/pop3.h
SUBDIRS = gnu sys
......
......@@ -18,6 +18,7 @@
#ifndef _MAILUTILS_CFG_H
#define _MAILUTILS_CFG_H
#include <mailutils/list.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
......@@ -186,4 +187,6 @@ int mu_config_register_plain_section (const char *parent_path,
int mu_parse_config (char *file, char *progname,
struct mu_cfg_param *progparam, int global);
int mu_cfg_parse_boolean (const char *str, int *res);
#endif
......
......@@ -20,14 +20,21 @@
#define _MAILUTILS_DAEMON_H
#include <mailutils/types.h>
#include <mailutils/gocs.h>
#ifdef __cplusplus
extern "C" {
#endif
/* FIXME: Namespace */
#define MODE_INTERACTIVE 0
#define MODE_DAEMON 1
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
......
......@@ -29,6 +29,9 @@ extern "C" {
typedef int (*mu_error_pfn_t) (const char *fmt, va_list ap);
extern const char *mu_program_name;
extern void mu_set_program_name (const char *name);
extern int mu_verror (const char *fmt, va_list ap);
extern int mu_error (const char *fmt, ...) MU_PRINTFLIKE(1,2);
extern void mu_error_set_print (mu_error_pfn_t);
......
/* GNU Mailutils -- a suite of utilities for electronic mail
Copyright (C) 2007 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, write to the
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301 USA */
#ifndef _MAILUTILS_GOCS_H
#define _MAILUTILS_GOCS_H
#include <mailutils/types.h>
#include <mailutils/list.h>
#ifdef __cplusplus
extern "C" {
#endif
struct mu_gocs_daemon
{
int mode;
size_t maxchildren;
unsigned int port;
unsigned int timeout;
int transcript;
char *pidfile;
};
struct mu_gocs_logging
{
int facility;
char *tag;
};
struct mu_gocs_mailbox
{
char *mail_spool;
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;
};
/* Auxiliary variables for use by libargp/libcfg */
extern int mu_load_user_rcfile;
extern int mu_load_site_rcfile;
extern char *mu_load_rcfile;
extern int log_facility; /* FIXME: 1. Belongs elsewhere;
2. Does not begin with `mu_' */
typedef int (*gocs_init_fp) (void *data);
void mu_gocs_register (char *capa, gocs_init_fp init);
void mu_gocs_register_std (char *name);
void mu_gocs_store (char *capa, void *data);
void mu_gocs_flush (void);
int mu_gocs_enumerate (mu_list_action_t action, void *data);
int mu_gocs_mailbox_init (void *data);
int mu_gocs_locking_init (void *data);
int mu_gocs_daemon_init (void *data);
int mu_gocs_source_email_init (void *data);
int mu_gocs_mailer_init (void *data);
int mu_gocs_logging_init (void *data);
#ifdef __cplusplus
}
#endif
#endif
......@@ -19,14 +19,22 @@
#ifndef _MAILUTILS_GSASL_H
#define _MAILUTILS_GSASL_H
struct mu_gsasl_module_data
{
char *cram_md5_pwd;
};
int mu_gsasl_module_init (void *data);
struct mu_gsasl_module_data mu_gsasl_module_data;
#ifdef USE_GSASL
#include <gsasl.h>
int mu_gsasl_stream_create (mu_stream_t *stream, mu_stream_t transport,
Gsasl_session_ctx *ctx,
int flags);
void mu_gsasl_init_argp (void);
extern char *mu_gsasl_cram_md5_pwd;
#endif
#endif /* not _MAILUTILS_GSASL_H */
......
......@@ -259,9 +259,19 @@ int mu_sieve_mailbox (mu_sieve_machine_t mach, mu_mailbox_t mbox);
int mu_sieve_message (mu_sieve_machine_t mach, mu_message_t message);
int mu_sieve_disass (mu_sieve_machine_t mach);
/* Command line handling */
/* Configuration functions */
extern void mu_sieve_argp_init (void);
#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;
mu_list_t library_path;
};
int mu_sieve_module_init (void *);
#ifdef __cplusplus
}
......
......@@ -19,7 +19,6 @@
#include <mailutils/address.h>
#include <mailutils/argcv.h>
#include <mailutils/argp.h>
#include <mailutils/attribute.h>
#include <mailutils/auth.h>
#include <mailutils/body.h>
......@@ -53,6 +52,7 @@
#include <mailutils/tls.h>
#include <mailutils/types.h>
#include <mailutils/url.h>
#include <mailutils/gocs.h>
#ifdef MU_COMPAT
# include <mailutils/compat.h>
......
......@@ -20,6 +20,7 @@
#define _MAILUTILS_MU_AUTH_H
#include <mailutils/types.h>
#include <mailutils/gocs.h>
#define MU_AUTH_NAME "name"
#define MU_AUTH_PASSWD "passwd"
......@@ -61,8 +62,7 @@ typedef int (*mu_auth_fp) (struct mu_auth_data **data,
struct mu_auth_module
{
char *name;
struct argp *argp;
struct mu_cfg_param *cfg;
gocs_init_fp init;
mu_auth_fp authenticate;
void *authenticate_data;
mu_auth_fp auth_by_name;
......@@ -130,7 +130,6 @@ extern struct mu_auth_module mu_auth_virtual_module;
extern struct mu_auth_module mu_auth_radius_module;
#define MU_AUTH_REGISTER_ALL_MODULES() do {\
mu_auth_init (); \
mu_auth_register_module (&mu_auth_generic_module); \
mu_auth_register_module (&mu_auth_system_module); \
mu_auth_register_module (&mu_auth_pam_module);\
......
/* GNU Mailutils -- a suite of utilities for electronic mail
Copyright (C) 1999, 2000, 2001, 2004, 2005,
2007 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, write to the
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301 USA */
#ifndef _MAILUTILS_PAM_H
#define _MAILUTILS_PAM_H
#include <mailutils/types.h>
extern char *mu_pam_service;
#endif
/* GNU Mailutils -- a suite of utilities for electronic mail
Copyright (C) 1999, 2000, 2001, 2004, 2005,
2007 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, write to the
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301 USA */
#ifndef _MAILUTILS_RADIUS_H
#define _MAILUTILS_RADIUS_H
#include <mailutils/types.h>
struct mu_radius_module_data
{
char *config_dir;
char *auth_request;
char *getpwnam_request;
char *getpwuid_request;
};
extern int mu_radius_module_init (void *data);
#endif
......@@ -19,7 +19,30 @@
#ifndef _MAILUTILS_SQL_H
#define _MAILUTILS_SQL_H
/* Loadable Modules Suppert */
/* Configuration */
enum mu_password_type
{
password_plaintext, /* Plaintext passwords */
password_scrambled, /* Scrambled MySQL (>=3.21) password */
password_hash, /* MD5 (or DES or whatever) hash */
};
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;
mu_assoc_t field_map;
};
/* Loadable Modules Support */
#define __s_cat2__(a,b) a ## b
#define __s_cat3__(a,b,c) a ## b ## c
#define RDL_EXPORT(module,name) __s_cat3__(module,_LTX_,name)
......@@ -27,7 +50,7 @@
typedef int (*mu_rdl_init_t) (void);
typedef void (*mu_rdl_done_t) (void);
#ifdef _HAVE_LIBLTDL //FIXME: Remove leading _ when SQL + ltdl works
#ifdef _HAVE_LIBLTDL /*FIXME: Remove leading _ when SQL + ltdl works*/
# define MU_DECL_SQL_DISPATCH_T(mod) \
mu_sql_dispatch_t RDL_EXPORT(mod,dispatch_tab)
#else
......@@ -112,18 +135,11 @@ int mu_sql_get_field (mu_sql_connection_t conn, size_t nrow, char *fname,
const char *mu_sql_strerror (mu_sql_connection_t conn);
enum mu_password_type
{
password_plaintext, /* Plaintext passwords */
password_scrambled, /* Scrambled MySQL (>=3.21) password */
password_hash, /* MD5 (or DES or whatever) hash */
};
extern enum mu_password_type mu_sql_password_type;
extern char *mu_sql_expand_query (const char *query, const char *ustr);
extern int mu_sql_getpass (const char *username, char **passwd);
extern int mu_check_mysql_scrambled_password (const char *scrambled,
const char *message);
int mu_sql_decode_password_type (const char *arg, enum mu_password_type *t);
#endif
......
/* GNU Mailutils -- a suite of utilities for electronic mail
Copyright (C) 2007 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, write to the
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301 USA */
#ifndef _MAILUTILS_SYSLOG_H
#define _MAILUTILS_SYSLOG_H
#include <syslog.h>
#ifdef __cplusplus
extern "C" {
#endif
int mu_string_to_syslog_facility (char *str, int *pfacility);
const char *mu_syslog_facility_to_string (int n);
int mu_string_to_syslog_priority (char *str, int *pprio);
const char *mu_syslog_priority_to_string (int n);
#ifdef __cplusplus
}
#endif
#endif
......@@ -19,16 +19,25 @@
#ifndef _MAILUTILS_TLS_H
#define _MAILUTILS_TLS_H
#ifdef WITH_TLS
#include <mailutils/types.h>
#ifdef __cplusplus
extern "C" {
#endif
struct mu_tls_module_config
{
int client_enable;
char *ssl_cert;
char *ssl_key;
char *ssl_cafile;
};
extern int mu_tls_module_init (void *data);
extern int mu_tls_stream_create (mu_stream_t *stream,
mu_stream_t strin, mu_stream_t strout, int flags);
mu_stream_t strin, mu_stream_t strout,
int flags);
extern int mu_tls_stream_create_client (mu_stream_t *stream,
mu_stream_t strin, mu_stream_t strout,
int flags);
......@@ -39,8 +48,6 @@ extern int mu_tls_stream_create_client_from_tcp (mu_stream_t *stream,
extern int mu_check_tls_environment (void);
extern int mu_init_tls_libs (void);
extern void mu_deinit_tls_libs (void);
extern void mu_tls_init_argp (void);
extern void mu_tls_init_client_argp (void);
typedef int (*mu_tls_readline_fn) (void *iodata);
typedef int (*mu_tls_writeline_fn) (void *iodata, char *buf);
......@@ -58,6 +65,5 @@ extern int mu_tls_enable;
}
#endif
#endif /* WITH_TLS */
#endif /* _MAILUTILS_TLS_H */
......
......@@ -23,8 +23,11 @@ noinst_LTLIBRARIES = libmuaux.la
INCLUDES = @MU_COMMON_INCLUDES@
libmuaux_la_SOURCES = \
argpinit.c\
daemon.c\
mailcap.c\
muinit.h\
muinit.c\
mu_dbm.c
EXTRA_DIST = utmp.c
......
/* GNU Mailutils -- a suite of utilities for electronic mail
Copyright (C) 2007 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, write to the
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301 USA */
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
#include "muinit.h"
void
mu_argp_init (const char *vers, const char *bugaddr)
{
argp_program_version = vers ? vers : PACKAGE_STRING;
argp_program_bug_address = bugaddr ? bugaddr : "<" PACKAGE_BUGREPORT ">";
}
/* GNU Mailutils -- a suite of utilities for electronic mail
Copyright (C) 2007 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, write to the
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301 USA */
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
#include "muinit.h"
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;
const struct argp argpnull = { 0 };
mu_set_program_name (argv[0]);
mu_libargp_init ();
for (i = 0; capa[i]; i++)
mu_gocs_register_std (capa[i]); /*FIXME*/
if (!myargp)
myargp = &argpnull;
argp = mu_argp_build (myargp);
rc = argp_parse (argp, argc, argv, flags, pindex, data);
mu_argp_done (argp);
if (rc)
return rc;
mu_libcfg_init (capa);
mu_parse_config_files (cfg_param);
mu_gocs_flush ();
return 0;
}
/* GNU Mailutils -- a suite of utilities for electronic mail
Copyright (C) 2007 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, write to the
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301 USA */
#include "cmdline.h"
#include "libcfg.h"
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);
*.la
*.lo
.deps
.libs
Makefile
Makefile.in
.gdbinit
/* GNU Mailutils -- a suite of utilities for electronic mail
Copyright (C) 2007 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, write to the
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301 USA */
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
#include "cmdline.h"
/* ************************************************************************* */
/* Traditional configuration */
/* ************************************************************************* */
static error_t mu_auth_argp_parser (int key, char *arg,
struct argp_state *state);
/* Options used by programs that use extended authentication mechanisms. */
static struct argp_option mu_auth_argp_option[] = {
{ "authentication", OPT_AUTHENTICATION, N_("MODLIST"), OPTION_HIDDEN,
N_("Set the list of modules to be used for authentication"), 0 },
{ "authorization", OPT_AUTHORIZATION, N_("MODLIST"), OPTION_HIDDEN,
N_("Set list of modules to be used for authorization"), 0 },
{ "clear-authorization", OPT_CLEAR_AUTHORIZATION, NULL, OPTION_HIDDEN,
N_("Clear the list of authorization modules"), 0 },
{ "clear-authentication", OPT_CLEAR_AUTHENTICATION, NULL, OPTION_HIDDEN,
N_("Clear the list of authentication modules"), 0 },
{ NULL, 0, NULL, 0, NULL, 0 }
};
static struct argp mu_auth_argp = {
mu_auth_argp_option,
mu_auth_argp_parser,
};
static struct argp_child mu_auth_argp_child = {
&mu_auth_argp,
0,
NULL,
0
};
static error_t
mu_auth_argp_parser (int key, char *arg, struct argp_state *state)
{
switch (key)
{
case ARGP_KEY_FINI:
mu_auth_finish_setup ();
break;
/* authentication */
case OPT_AUTHORIZATION:
mu_authorization_add_module_list (arg);
break;
case OPT_AUTHENTICATION:
mu_authentication_add_module_list (arg);
break;
case OPT_CLEAR_AUTHENTICATION:
mu_authentication_clear_list ();
break;
case OPT_CLEAR_AUTHORIZATION:
mu_authorization_clear_list ();
break;
default:
return ARGP_ERR_UNKNOWN;
}
return 0;
}
struct mu_cmdline_capa mu_auth_cmdline = {
"auth", &mu_auth_argp_child
};
/* GNU Mailutils -- a suite of utilities for electronic mail
Copyright (C) 1999, 2000, 2001, 2004, 2005,
2007 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, write to the
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301 USA */
#ifndef _MAILUTILS_CMDLINE_H
#define _MAILUTILS_CMDLINE_H
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
#include "mailutils/types.h"
#include "mailutils/gocs.h"
#include "mailutils/nls.h"
#include "mailutils/error.h"
#include "mailutils/errno.h"
#include "argp.h"
#include <errno.h> /* May declare program_invocation_name */
#ifdef __cplusplus
extern "C" {
#endif
enum {
OPT_LOG_FACILITY = 256,
OPT_LOCK_FLAGS,
OPT_LOCK_RETRY_COUNT,
OPT_LOCK_RETRY_TIMEOUT,
OPT_LOCK_EXPIRE_TIMEOUT,
OPT_LOCK_EXTERNAL_PROGRAM,
OPT_SHOW_OPTIONS,
OPT_LICENSE,
OPT_MAILBOX_TYPE,
OPT_CRAM_PASSWD,
OPT_PAM_SERVICE,
OPT_AUTH_REQUEST,
OPT_GETPWNAM_REQUEST,
OPT_GETPWUID_REQUEST,
OPT_RADIUS_DIR,
OPT_SQL_INTERFACE,
OPT_SQL_GETPWNAM,
OPT_SQL_GETPWUID,
OPT_SQL_GETPASS,
OPT_SQL_HOST,
OPT_SQL_USER,
OPT_SQL_PASSWD,
OPT_SQL_DB,
OPT_SQL_PORT,
OPT_SQL_MU_PASSWORD_TYPE,
OPT_SQL_FIELD_MAP,
OPT_TLS,
OPT_SSL_CERT,
OPT_SSL_KEY,
OPT_SSL_CAFILE,
OPT_PWDDIR,
OPT_AUTHORIZATION,
OPT_AUTHENTICATION,
OPT_CLEAR_AUTHORIZATION,
OPT_CLEAR_AUTHENTICATION,
OPT_NO_USER_RCFILE,
OPT_NO_SITE_RCFILE,
OPT_RCFILE,
OPT_CLEAR_INCLUDE_PATH,
OPT_CLEAR_LIBRARY_PATH
};
struct mu_cmdline_capa
{
char *name;
struct argp_child *child;
};
extern struct mu_cmdline_capa mu_common_cmdline;
extern struct mu_cmdline_capa mu_logging_cmdline;
extern struct mu_cmdline_capa mu_license_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_daemon_cmdline;
extern struct mu_cmdline_capa mu_sieve_cmdline;
extern struct mu_cmdline_capa mu_pam_cmdline;
extern struct mu_cmdline_capa mu_gsasl_cmdline;
extern struct mu_cmdline_capa mu_tls_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 struct mu_cmdline_capa mu_auth_cmdline;
extern char *mu_license_text;
extern void mu_libargp_init (void);
extern struct argp *mu_argp_build (const struct argp *argp);
extern void mu_argp_done (struct argp *argp);
extern int mu_register_argp_capa (const char *name, struct argp_child *child);
extern void mu_print_options (void);
extern const char *mu_check_option (char *name);
#ifdef __cplusplus
}
#endif
#endif
/* GNU Mailutils -- a suite of utilities for electronic mail
Copyright (C) 2007 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, write to the
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301 USA */
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
#include "cmdline.h"
#include <string.h>
#include <mailutils/syslog.h>
#include <mailutils/daemon.h>
static struct mu_gocs_daemon daemon_settings;
static struct mu_gocs_locking locking_settings;
static struct mu_gocs_logging logging_settings;
static struct mu_gocs_mailbox mailbox_settings;
static struct mu_gocs_source_email source_email_settings;
static struct mu_gocs_mailer mailer_settings;
void
assign_string (char **pstr, char *val)
{
if (!val)
{
if (*pstr)
{
free (*pstr);
*pstr = NULL;
}
}
else
{
size_t size = strlen (val);
char *p = realloc (*pstr, size + 1);
if (!p)
{
mu_error ("%s", mu_strerror (ENOMEM));
exit (1);
}
strcpy (p, val);
*pstr = p;
}
}
/* ************************************************************************* */
/* Common */
/* ************************************************************************* */
static struct argp_option mu_common_argp_options[] =
{
{ NULL, 0, NULL, 0, N_("Common options"), 0},
{ "show-config-options", OPT_SHOW_OPTIONS, NULL, OPTION_HIDDEN,
N_("Show compilation options"), 0 },
{ "no-user-rcfile", OPT_NO_USER_RCFILE, NULL, 0,
N_("Do not load user configuration file"), 0 },
{ "no-site-rcfile", OPT_NO_SITE_RCFILE, NULL, 0,
N_("Do not load site configuration file"), 0 },
{ "rcfile", OPT_RCFILE, N_("FILE"), 0,
N_("Load this configuration file"), 0, },
{ NULL, 0, NULL, 0, NULL, 0 }
};
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;
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)
{
switch (key)
{
/* log */
case OPT_LOG_FACILITY:
if (mu_string_to_syslog_facility (arg, &logging_settings.facility))
mu_error (_("Unknown syslog facility `%s'"), arg);
/* FIXME: error reporting */
break;
case ARGP_KEY_FINI:
mu_gocs_store ("logging", &logging_settings);
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
};
/* ************************************************************************* */
/* License */
/* ************************************************************************* */
/* Option to print the license. */
static struct argp_option mu_license_argp_option[] = {
{ "license", OPT_LICENSE, NULL, 0, N_("Print license and exit"), -2 },
{ NULL, 0, NULL, 0, NULL, 0 }
};
static error_t
mu_license_argp_parser (int key, char *arg, struct argp_state *state)
{
switch (key)
{
case OPT_LICENSE:
printf (_("License for %s:\n\n"), argp_program_version);
printf ("%s", mu_license_text);
exit (0);
default:
return ARGP_ERR_UNKNOWN;
}
return 0;
}
struct argp mu_license_argp = {
mu_license_argp_option,
mu_license_argp_parser,
};
struct argp_child mu_license_argp_child = {
&mu_license_argp,
0,
NULL,
0
};
struct mu_cmdline_capa mu_license_cmdline = {
"license", &mu_license_argp_child
};
/* ************************************************************************* */
/* Mailbox */
/* ************************************************************************* */
/* Options used by programs that access mailboxes. */
static struct argp_option mu_mailbox_argp_option[] = {
{ "mail-spool", 'm', N_("URL"), OPTION_HIDDEN,
N_("Use specified URL as a mailspool directory"), 0 },
{ "mailbox-type", OPT_MAILBOX_TYPE, N_("PROTO"), OPTION_HIDDEN,
N_("Default mailbox type to use"), 0 },
{ NULL }
};
static error_t
mu_mailbox_argp_parser (int key, char *arg, struct argp_state *state)
{
switch (key)
{
/* mailbox */
case 'm':
assign_string (&mailbox_settings.mail_spool, arg);
break;
case OPT_MAILBOX_TYPE:
assign_string (&mailbox_settings.mailbox_type, arg);
break;
case ARGP_KEY_FINI:
mu_gocs_store ("mailbox", &mailbox_settings);
break;
default:
return ARGP_ERR_UNKNOWN;
}
return 0;
}
struct argp mu_mailbox_argp = {
mu_mailbox_argp_option,
mu_mailbox_argp_parser,
};
struct argp_child mu_mailbox_argp_child = {
&mu_mailbox_argp,
0,
NULL,
0
};
struct mu_cmdline_capa mu_mailbox_cmdline = {
"mailbox", &mu_mailbox_argp_child
};
/* ************************************************************************* */
/* Locking */
/* ************************************************************************* */
/* Options used by programs that access mailboxes. */
static struct argp_option mu_locking_argp_option[] = {
{"lock-flags", OPT_LOCK_FLAGS, N_("FLAGS"), OPTION_HIDDEN,
N_("Default locker flags (E=external, R=retry, T=time, P=pid)"), 0},
{"lock-retry-timeout", OPT_LOCK_RETRY_TIMEOUT, N_("SECONDS"), OPTION_HIDDEN,
N_("Set timeout for acquiring the lockfile") },
{"lock-retry-count", OPT_LOCK_RETRY_COUNT, N_("NUMBER"), OPTION_HIDDEN,
N_("Set the maximum number of times to retry acquiring the lockfile") },
{"lock-expire-timeout", OPT_LOCK_EXPIRE_TIMEOUT, N_("SECONDS"),
OPTION_HIDDEN,
N_("Number of seconds after which the lock expires"), },
{"external-locker", OPT_LOCK_EXTERNAL_PROGRAM, N_("PATH"), OPTION_HIDDEN,
N_("Set full path to the external locker program") },
{ NULL, 0, NULL, 0, NULL, 0 }
};
static error_t
mu_locking_argp_parser (int key, char *arg, struct argp_state *state)
{
switch (key)
{
case OPT_LOCK_FLAGS:
assign_string (&locking_settings.lock_flags, arg);
break;
case OPT_LOCK_RETRY_COUNT:
locking_settings.lock_retry_count = strtoul (arg, NULL, 0);
break;
case OPT_LOCK_RETRY_TIMEOUT:
locking_settings.lock_retry_timeout = strtoul (arg, NULL, 0);
break;
case OPT_LOCK_EXPIRE_TIMEOUT:
locking_settings.lock_expire_timeout = strtoul (arg, NULL, 0);
break;
case OPT_LOCK_EXTERNAL_PROGRAM:
assign_string (&locking_settings.external_locker, arg);
break;
case ARGP_KEY_FINI:
mu_gocs_store ("locking", &locking_settings);
break;
default:
return ARGP_ERR_UNKNOWN;
}
return 0;
}
struct argp mu_locking_argp = {
mu_locking_argp_option,
mu_locking_argp_parser,
};
struct argp_child mu_locking_argp_child = {
&mu_locking_argp,
0,
NULL,
0
};
struct mu_cmdline_capa mu_locking_cmdline = {
"locking", &mu_locking_argp_child
};
/* ************************************************************************* */
/* Address */
/* ************************************************************************* */
/* Options used by programs that do address mapping. */
static struct argp_option mu_address_argp_option[] = {
{"email-addr", 'E', N_("EMAIL"), OPTION_HIDDEN,
N_("Set current user's email address (default is loginname@defaultdomain)"), 0},
{"email-domain", 'D', N_("DOMAIN"), OPTION_HIDDEN,
N_("Set domain for unqualified user names (default is this host)"), 0},
{ NULL, 0, NULL, 0, NULL, 0 }
};
static error_t
mu_address_argp_parser (int key, char *arg, struct argp_state *state)
{
switch (key)
{
case 'E':
assign_string (&source_email_settings.address, arg);
break;
case 'D':
assign_string (&source_email_settings.domain, arg);
break;
case ARGP_KEY_FINI:
mu_gocs_store ("address", &source_email_settings);
break;
default:
return ARGP_ERR_UNKNOWN;
}
return 0;
}
struct argp mu_address_argp = {
mu_address_argp_option,
mu_address_argp_parser,
};
struct argp_child mu_address_argp_child = {
&mu_address_argp,
0,
NULL,
0
};
struct mu_cmdline_capa mu_address_cmdline = {
"address", &mu_address_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)
{
switch (key)
{
/* mailer */
case 'M':
assign_string (&mailer_settings.mailer, arg);
break;
case ARGP_KEY_FINI:
mu_gocs_store ("mailer", &mailer_settings);
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
};
/* ************************************************************************* */
/* Daemon */
/* ************************************************************************* */
/* Options used by programs that become daemons. */
static struct argp_option mu_daemon_argp_option[] = {
{"daemon", 'd', N_("NUMBER"), OPTION_ARG_OPTIONAL,
N_("Runs in daemon mode with a maximum of NUMBER children")},
{"inetd", 'i', 0, 0,
N_("Run in inetd mode"), 0},
{"port", 'p', N_("PORT"), 0,
N_("Listen on specified port number"), 0},
{"timeout", 't', N_("NUMBER"), OPTION_HIDDEN,
N_("Set idle timeout value to NUMBER seconds"), 0},
{"transcript", 'x', NULL, 0,
N_("Output session transcript via syslog"), 0},
{"pidfile", 'P', N_("FILE"), OPTION_HIDDEN,
N_("Set PID file"), 0},
{ NULL, 0, NULL, 0, NULL, 0 }
};
static error_t
mu_daemon_argp_parser (int key, char *arg, struct argp_state *state)
{
switch (key)
{
case 'd':
daemon_settings.mode = MODE_DAEMON;
if (arg)
daemon_settings.maxchildren = strtoul (arg, NULL, 10);
break;
case 'i':
daemon_settings.mode = MODE_INTERACTIVE;
break;
case 'p':
daemon_settings.mode = MODE_DAEMON;
daemon_settings.port = strtoul (arg, NULL, 10); /*FIXME: overflow */
break;
case 'P':
assign_string (&daemon_settings.pidfile, arg);
break;
case 't':
daemon_settings.timeout = strtoul (arg, NULL, 10);
break;
case 'x':
daemon_settings.transcript = 1;
break;
case ARGP_KEY_FINI:
mu_gocs_store ("daemon", &daemon_settings);
break;
default:
return ARGP_ERR_UNKNOWN;
}
return 0;
}
struct argp mu_daemon_argp = {
mu_daemon_argp_option,
mu_daemon_argp_parser,
};
struct argp_child mu_daemon_argp_child = {
&mu_daemon_argp,
0,
N_("Daemon configuration options"),
0
};
struct mu_cmdline_capa mu_daemon_cmdline = {
"daemon", &mu_daemon_argp_child
};
/* GNU Mailutils -- a suite of utilities for electronic mail
Copyright (C) 2007 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, write to the
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301 USA */
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
#include "cmdline.h"
#include <mailutils/gsasl.h>
static struct argp_option _gsasl_argp_options[] = {
{"cram-passwd", OPT_CRAM_PASSWD, N_("FILE"), OPTION_HIDDEN,
N_("Specify password file for CRAM-MD5 authentication"), 0},
{ NULL, 0, NULL, 0, NULL, 0 }
};
static struct mu_gsasl_module_data gsasl_data = {
SITE_CRAM_MD5_PWD
};
static error_t
_gsasl_argp_parser (int key, char *arg, struct argp_state *state)
{
switch (key)
{
case OPT_CRAM_PASSWD:
gsasl_data.cram_md5_pwd = arg;
break;
case ARGP_KEY_FINI:
mu_gocs_store ("gsasl", &gsasl_data);
break;
default:
return ARGP_ERR_UNKNOWN;
}
return 0;
}
static struct argp _gsasl_argp = {
_gsasl_argp_options,
_gsasl_argp_parser
};
struct argp_child mu_gsasl_argp_child = {
&_gsasl_argp,
0,
NULL,
0
};
struct mu_cmdline_capa mu_gsasl_cmdline = {
"gsasl", &mu_gsasl_argp_child
};
/* GNU Mailutils -- a suite of utilities for electronic mail
Copyright (C) 1999, 2001, 2002, 2003, 2004, 2005, 2006,
2007 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, write to the
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301 USA */
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
#include <getline.h>
#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 "cmdline.h"
char *mu_license_text =
N_(" GNU Mailutils is free software; you can redistribute it and/or modify\n"
" it under the terms of the GNU General Public License as published by\n"
" the Free Software Foundation; either version 3 of the License, or\n"
" (at your option) any later version.\n"
"\n"
" GNU Mailutils is distributed in the hope that it will be useful,\n"
" but WITHOUT ANY WARRANTY; without even the implied warranty of\n"
" MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n"
" GNU General Public License for more details.\n"
"\n"
" You should have received a copy of the GNU General Public License along\n"
" with GNU Mailutils; if not, write to the Free Software Foundation,\n"
" Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA\n"
"\n"
"\n"
);
static char *mu_conf_option[] = {
"VERSION=" VERSION,
#ifdef USE_LIBPAM
"USE_LIBPAM",
#endif
#ifdef HAVE_LIBLTDL
"HAVE_LIBLTDL",
#endif
#ifdef WITH_BDB2
"WITH_BDB2",
#endif
#ifdef WITH_NDBM
"WITH_NDBM",
#endif
#ifdef WITH_OLD_DBM
"WITH_OLD_DBM",
#endif
#ifdef WITH_GDBM
"WITH_GDBM",
#endif
#ifdef WITH_GNUTLS
"WITH_GNUTLS",
#endif
#ifdef WITH_GSASL
"WITH_GSASL",
#endif
#ifdef WITH_GSSAPI
"WITH_GSSAPI",
#endif
#ifdef WITH_GUILE
"WITH_GUILE",
#endif
#ifdef WITH_PTHREAD
"WITH_PTHREAD",
#endif
#ifdef WITH_READLINE
"WITH_READLINE",
#endif
#ifdef HAVE_MYSQL
"HAVE_MYSQL",
#endif
#ifdef HAVE_PGSQL
"HAVE_PGSQL",
#endif
#ifdef ENABLE_VIRTUAL_DOMAINS
"ENABLE_VIRTUAL_DOMAINS",
#endif
#ifdef ENABLE_IMAP
"ENABLE_IMAP",
#endif
#ifdef ENABLE_POP
"ENABLE_POP",
#endif
#ifdef ENABLE_MH
"ENABLE_MH",
#endif
#ifdef ENABLE_MAILDIR
"ENABLE_MAILDIR",
#endif
#ifdef ENABLE_SMTP
"ENABLE_SMTP",
#endif
#ifdef ENABLE_SENDMAIL
"ENABLE_SENDMAIL",
#endif
#ifdef ENABLE_NNTP
"ENABLE_NNTP",
#endif
#ifdef ENABLE_RADIUS
"ENABLE_RADIUS",
#endif
#ifdef WITH_INCLUDED_LIBINTL
"WITH_INCLUDED_LIBINTL",
#endif
NULL
};
void
mu_print_options ()
{
int i;
for (i = 0; mu_conf_option[i]; i++)
printf ("%s\n", mu_conf_option[i]);
}
const char *
mu_check_option (char *name)
{
int i;
for (i = 0; mu_conf_option[i]; i++)
{
int len;
char *q, *p = strchr (mu_conf_option[i], '=');
if (p)
len = p - mu_conf_option[i];
else
len = strlen (mu_conf_option[i]);
if (strncasecmp (mu_conf_option[i], name, len) == 0)
return mu_conf_option[i];
else if ((q = strchr (mu_conf_option[i], '_')) != NULL
&& strncasecmp (q + 1, name,
len - (q - mu_conf_option[i]) - 1) == 0)
return mu_conf_option[i];
}
return NULL;
}
/* ************************************************************************* */
/* Capability array and auxiliary functions. */
/* ************************************************************************* */
#define MU_MAX_CAPA 24
struct argp_capa {
char *capability;
struct argp_child *child;
} mu_argp_capa[MU_MAX_CAPA] = {
{NULL,}
};
int
mu_register_argp_capa (const char *name, struct argp_child *child)
{
int i;
for (i = 0; i < MU_MAX_CAPA; i++)
if (mu_argp_capa[i].capability == NULL)
{
mu_argp_capa[i].capability = strdup (name);
mu_argp_capa[i].child = child;
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, const char *capa[])
{
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 (_("Out of 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)
{
mu_error (_("INTERNAL ERROR: requested unknown argp "
"capability %s (please report)"),
capa[n]);
abort ();
}
ap[nchild] = *cp->child;
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 (_("Out of memory"));
abort ();
}
memcpy (argp, template, sizeof (*argp));
argp->children = ap;
return argp;
}
struct cap_buf
{
const 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, const 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)
{
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);
cap_buf_free (&cb);
return argp;
}
void
mu_argp_done (struct argp *argp)
{
free ((void*) argp->children);
free ((void*) argp);
}
......@@ -21,46 +21,23 @@
#define _MAILUTILS_ARGP_H
#include <mailutils/types.h>
#include <mailutils/cfg.h>
#include <argp.h>
#include <errno.h> /* May declare program_invocation_name */
#define MODE_INTERACTIVE 0
#define MODE_DAEMON 1
struct daemon_param {
int mode;
size_t maxchildren;
unsigned int port;
unsigned int timeout;
int transcript;
char *pidfile;
};
#ifdef USE_LIBPAM
extern char *pam_service;
#endif
extern int log_facility;
extern int mu_argp_error_code;
extern char *mu_license_text;
#ifdef __cplusplus
extern "C" {
#endif
extern void mu_argp_init (const char *vers, const char *bugaddr);
extern void mu_argp_init (struct argp *argp, const char *vers,
const char *bugaddr, const char *capa[]);
extern void mu_argp_done (struct argp *argp);
extern error_t mu_argp_parse (const struct argp * argp,
int *p_argc, char ***p_argv,
unsigned flags,
const char *capa[],
int *arg_index, void *input);
extern int mu_register_capa (const char *name, struct argp_child *child,
struct mu_cfg_param *param);
extern int mu_register_argp_capa (const char *name, struct argp_child *child);
extern void mu_print_options (void);
extern const char *mu_check_option (char *name);
extern void mu_argp_set_config_param (struct mu_cfg_param *);
#ifdef __cplusplus
}
......
/* GNU Mailutils -- a suite of utilities for electronic mail
Copyright (C) 2007 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, write to the
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301 USA */
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
#include "cmdline.h"
#include <mailutils/pam.h>
static char *service_name;
static error_t
mu_pam_argp_parser (int key, char *arg, struct argp_state *state)
{
switch (key)
{
case OPT_PAM_SERVICE:
service_name = arg;
break;
case ARGP_KEY_FINI:
mu_gocs_store ("pam", service_name);
break;
default:
return ARGP_ERR_UNKNOWN;
}
return 0;
}
static struct argp_option mu_pam_argp_option[] = {
{ "pam-service", OPT_PAM_SERVICE, N_("STRING"), OPTION_HIDDEN,
N_("Use STRING as PAM service name"), 0},
{ NULL, 0, NULL, 0, NULL, 0 }
};
static struct argp mu_pam_argp = {
mu_pam_argp_option,
mu_pam_argp_parser,
};
struct argp_child mu_pam_argp_child = {
&mu_pam_argp,
0,
NULL,
0
};
struct mu_cmdline_capa mu_pam_cmdline = {
"pam", &mu_pam_argp_child
};
/* GNU Mailutils -- a suite of utilities for electronic mail
Copyright (C) 2007 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, write to the
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301 USA */
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
#include "cmdline.h"
#include <mailutils/radius.h>
static struct argp_option mu_radius_argp_option[] = {
{ "radius-auth-request", OPT_AUTH_REQUEST, N_("REQUEST"), OPTION_HIDDEN,
N_("Radius request to authenitcate the user"), 0 },
{ "radius-getpwnam-request", OPT_GETPWNAM_REQUEST, N_("REQUEST"), OPTION_HIDDEN,
N_("Radius request to retrieve a passwd entry based on username"), 0 },
{ "radius-getpwuid-request", OPT_GETPWUID_REQUEST, N_("REQUEST"), OPTION_HIDDEN,
N_("Radius request to retrieve a passwd entry based on UID"), 0 },
{ "radius-directory", OPT_RADIUS_DIR, N_("DIR"), OPTION_HIDDEN,
N_("Set path to the radius configuration directory"), 0 },
{ NULL }
};
static struct mu_radius_module_data radius_data;
static error_t
mu_radius_argp_parser (int key, char *arg, struct argp_state *state)
{
switch (key)
{
case OPT_AUTH_REQUEST:
radius_data.auth_request = arg;
break;
case OPT_GETPWNAM_REQUEST:
radius_data.getpwnam_request = arg;
break;
case OPT_GETPWUID_REQUEST:
radius_data.getpwuid_request = arg;
break;
case OPT_RADIUS_DIR:
radius_data.config_dir = arg;
break;
case ARGP_KEY_FINI:
mu_gocs_store ("radius", &radius_data);
break;
default:
return ARGP_ERR_UNKNOWN;
}
return 0;
}
static struct argp mu_radius_argp = {
mu_radius_argp_option,
mu_radius_argp_parser,
};
struct argp_child mu_radius_argp_child = {
&mu_radius_argp,
0,
NULL,
0
};
struct mu_cmdline_capa mu_radius_cmdline = {
"radius", &mu_radius_argp_child
};
......@@ -20,74 +20,53 @@
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
#include <sieve.h>
#include <mailutils/argp.h>
#include <string.h>
#include "cmdline.h"
#include "mailutils/libsieve.h"
mu_list_t mu_sieve_include_path = NULL;
mu_list_t mu_sieve_library_path = NULL;
static error_t sieve_argp_parser (int key, char *arg, struct argp_state *state);
#define CLEARPATH_OPTION 256
/* Options used by programs that use extended authentication mechanisms. */
static struct argp_option sieve_argp_option[] = {
{ "includedir", 'I', N_("DIR"), 0,
N_("Append directory DIR to the list of directories searched for include files"), 0 },
{ "libdir", 'L', N_("DIR"), 0,
N_("Append directory DIR to the list of directories searched for library files"), 0 },
{ "clearpath", CLEARPATH_OPTION, NULL, 0,
N_("Clear Sieve load path"), 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 lobrary path"), 0 },
{ "clearpath", 0, NULL, OPTION_ALIAS, NULL },
{ NULL, 0, NULL, 0, NULL, 0 }
};
static struct argp sieve_argp = {
sieve_argp_option,
sieve_argp_parser,
};
static struct argp_child sieve_argp_child = {
&sieve_argp,
0,
"Sieve options",
0
};
static void
destroy_string (void *str)
{
free (str);
}
static error_t
sieve_argp_parser (int key, char *arg, struct argp_state *state)
{
static struct mu_gocs_sieve gocs_data;
mu_list_t *plist = NULL;
switch (key)
{
case 'I':
plist = &mu_sieve_include_path;
plist = &gocs_data.include_path;
break;
case 'L':
plist = &mu_sieve_library_path;
plist = &gocs_data.library_path;
break;
case OPT_CLEAR_INCLUDE_PATH:
gocs_data.clearflags |= MU_SIEVE_CLEAR_INCLUDE_PATH;
break;
case CLEARPATH_OPTION:
mu_list_destroy (&mu_sieve_library_path);
case OPT_CLEAR_LIBRARY_PATH:
gocs_data.clearflags |= MU_SIEVE_CLEAR_LIBRARY_PATH;
break;
case ARGP_KEY_INIT:
#ifdef SIEVE_MODDIR
plist = &mu_sieve_library_path;
arg = SIEVE_MODDIR;
#endif
memset (&gocs_data, 0, sizeof gocs_data);
break;
case ARGP_KEY_FINI:
sieve_load_add_path (mu_sieve_library_path);
mu_gocs_store ("sieve", &gocs_data);
break;
default:
......@@ -101,24 +80,30 @@ sieve_argp_parser (int key, char *arg, struct argp_state *state)
int rc = mu_list_create (plist);
if (rc)
{
argp_error (state, "can't create list: %s",
argp_error (state, _("cannot create list: %s"),
mu_strerror (rc));
exit (1);
}
mu_list_set_destroy_item (*plist, destroy_string);
}
mu_list_append (*plist, strdup (arg));
mu_list_append (*plist, arg);
}
return 0;
}
void
mu_sieve_argp_init ()
{
if (mu_register_capa ("sieve", &sieve_argp_child, NULL))
{
mu_error ("INTERNAL ERROR: cannot register argp capability sieve");
abort ();
}
}
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
};
......
/* GNU Mailutils -- a suite of utilities for electronic mail
Copyright (C) 2007 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, write to the
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301 USA */
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
#include "cmdline.h"
#include "mailutils/sql.h"
#include "mailutils/mutil.h"
static int sql_requested;
static struct mu_sql_module_config sql_config;
/* Command-line configuration */
static struct argp_option mu_sql_argp_option[] = {
{"sql-interface", OPT_SQL_INTERFACE, N_("NAME"), OPTION_HIDDEN,
N_("Type of SQL interface to use"), },
{"sql-getpwnam", OPT_SQL_GETPWNAM, N_("QUERY"), OPTION_HIDDEN,
N_("SQL query to retrieve a passwd entry based on username"), 0},
{"sql-getpwuid", OPT_SQL_GETPWUID, N_("QUERY"), OPTION_HIDDEN,
N_("SQL query to retrieve a passwd entry based on UID"), 0},
{"sql-getpass", OPT_SQL_GETPASS, N_("QUERY"), OPTION_HIDDEN,
N_("SQL query to retrieve a password from the database"), 0},
{"sql-host", OPT_SQL_HOST, N_("HOSTNAME"), OPTION_HIDDEN,
N_("Name or IP of MySQL server to connect to"), 0},
{"sql-user", OPT_SQL_USER, N_("NAME"), OPTION_HIDDEN,
N_("SQL user name"), 0},
{"sql-passwd", OPT_SQL_PASSWD, N_("STRING"), OPTION_HIDDEN,
N_("SQL connection password"), 0},
{"sql-db", OPT_SQL_DB, N_("STRING"), OPTION_HIDDEN,
N_("Name of the database to connect to"), 0},
{"sql-port", OPT_SQL_PORT, N_("NUMBER"), OPTION_HIDDEN,
N_("Port to use"), 0},
{"sql-password-type", OPT_SQL_MU_PASSWORD_TYPE, N_("STRING"), OPTION_HIDDEN,
N_("Type of password returned by --sql-getpass query. STRING is one of: plain, hash, scrambled"), 0},
{"sql-field-map", OPT_SQL_FIELD_MAP, N_("MAP"), OPTION_HIDDEN,
N_("Declare a name translation map for SQL fields in results of sql-getpwnam and "
"sql-getpwuid queries"), 0},
{ NULL, 0, NULL, 0, NULL, 0 }
};
static error_t
mu_sql_argp_parser (int key, char *arg, struct argp_state *state)
{
int rc, err;
switch (key)
{
case OPT_SQL_INTERFACE:
sql_config.interface = arg;
sql_requested = 1;
break;
case OPT_SQL_GETPWNAM:
sql_requested = 1;
sql_config.getpwnam_query = arg;
break;
case OPT_SQL_GETPWUID:
sql_requested = 1;
sql_config.getpwuid_query = arg;
break;
case OPT_SQL_GETPASS:
sql_requested = 1;
sql_config.getpass_query = arg;
break;
case OPT_SQL_HOST:
sql_requested = 1;
sql_config.host = arg;
break;
case OPT_SQL_USER:
sql_requested = 1;
sql_config.user = arg;
break;
case OPT_SQL_PASSWD:
sql_requested = 1;
sql_config.passwd = arg;
break;
case OPT_SQL_DB:
sql_requested = 1;
sql_config.db = arg;
break;
case OPT_SQL_PORT:
sql_requested = 1;
sql_config.port = strtoul (arg, NULL, 0);
break;
case OPT_SQL_MU_PASSWORD_TYPE:
if (mu_sql_decode_password_type (arg, &sql_config.password_type))
argp_error (state, _("Unknown password type `%s'"), arg);
sql_requested = 1;
break;
case OPT_SQL_FIELD_MAP:
rc = mutil_parse_field_map (arg, &sql_config.field_map, &err);
if (rc)
argp_error (state, _("Error near element %d: %s"),
err, mu_strerror (rc));
sql_requested = 1;
break;
case ARGP_KEY_FINI:
if (sql_requested)
mu_gocs_store ("sql", &sql_config);
break;
default:
return ARGP_ERR_UNKNOWN;
}
return 0;
}
static struct argp mu_sql_argp = {
mu_sql_argp_option,
mu_sql_argp_parser,
};
struct argp_child mu_sql_argp_child = {
&mu_sql_argp,
0,
NULL,
0
};
struct mu_cmdline_capa mu_sql_cmdline = {
"sql", &mu_sql_argp_child
};
/* GNU Mailutils -- a suite of utilities for electronic mail
Copyright (C) 2007 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, write to the
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301 USA */
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
#include "cmdline.h"
#include <mailutils/tls.h>
#include "strcase.h" /* FIXME */
static struct argp_option _tls_argp_options[] = {
{"ssl-cert", OPT_SSL_CERT, N_("FILE"), OPTION_HIDDEN,
N_("Specify SSL certificate file"), 0},
{"ssl-key", OPT_SSL_KEY, N_("FILE"), OPTION_HIDDEN,
N_("Specify SSL certificate key"), },
{"ssl-cafile", OPT_SSL_CAFILE, N_("FILE"), OPTION_HIDDEN,
N_("Specify trusted CAs file"), 0},
{"tls", OPT_TLS, N_("BOOL"), OPTION_ARG_OPTIONAL,
N_("Enable TLS support") },
{NULL, 0, NULL, 0, NULL, 0}
};
static struct mu_tls_module_config tls_data = { 1, };
static error_t
_tls_argp_parser (int key, char *arg, struct argp_state *state)
{
switch (key)
{
case OPT_TLS:
if (!arg || strcasecmp (arg, "yes") == 0)
tls_data.client_enable = 1;
else if (strcasecmp (arg, "no") == 0)
tls_data.client_enable = 0;
break;
case OPT_SSL_CERT:
tls_data.ssl_cert = arg;
break;
case OPT_SSL_KEY:
tls_data.ssl_key = arg;
break;
case OPT_SSL_CAFILE:
tls_data.ssl_cafile = arg;
break;
case ARGP_KEY_FINI:
mu_gocs_store ("tls", &tls_data);
break;
default:
return ARGP_ERR_UNKNOWN;
}
return 0;
}
static struct argp _tls_argp = {
_tls_argp_options,
_tls_argp_parser
};
static struct argp_child _tls_argp_child = {
&_tls_argp,
0,
NULL,
0
};
struct mu_cmdline_capa mu_tls_cmdline = {
"tls", &_tls_argp_child
};
/* GNU Mailutils -- a suite of utilities for electronic mail
Copyright (C) 2007 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, write to the
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301 USA */
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
#include "cmdline.h"
static char *virtdir;
static error_t
mu_virt_argp_parser (int key, char *arg, struct argp_state *state)
{
switch (key)
{
case OPT_PWDDIR:
virtdir = arg;
break;
case ARGP_KEY_FINI:
mu_gocs_store ("virtdomain", virtdir);
break;
default:
return ARGP_ERR_UNKNOWN;
}
return 0;
}
static struct argp_option mu_virt_argp_option[] = {
{ "virtual-passwd-dir", OPT_PWDDIR, N_("DIR"), OPTION_HIDDEN,
N_("Search for virtual passwd file in DIR"), 0},
{ NULL, 0, NULL, 0, NULL, 0 }
};
static struct argp mu_virt_argp = {
mu_virt_argp_option,
mu_virt_argp_parser,
};
struct argp_child mu_virt_argp_child = {
&mu_virt_argp,
0,
NULL,
0
};
struct mu_cmdline_capa mu_virtdomain_cmdline = {
"virtdomain", &mu_virt_argp_child
};
*.la
*.lo
.deps
.libs
Makefile
Makefile.in
.gdbinit
# This file is part of GNU Mailutils
# Copyright (C) 2007 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, write to the Free Software
# Foundation, Inc. 51 Franklin Street, Fifth Floor, Boston, MA
# 02110-1301 USA
INCLUDES = @MU_COMMON_INCLUDES@
AM_CFLAGS = -DSITE_VIRTUAL_PWDDIR=\"@SITE_VIRTUAL_PWDDIR@\" \
-DSITE_CRAM_MD5_PWD=\"@SITE_CRAM_MD5_PWD@\"
lib_LTLIBRARIES = libmucfg.la
noinst_HEADERS = libcfg.h
libmucfg_la_SOURCES=\
auth.c\
common.c\
init.c\
gsasl.c\
pam.c\
radius.c\
sieve.c\
sql.c\
tls.c\
virtdomain.c
/* This file is part of GNU Mailutils
Copyright (C) 2007 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.
This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "libcfg.h"
#include <mailutils/mu_auth.h>
#include <string.h>
/* FIXME: mu_auth.c should be reviewed */
/* ************************************************************************* */
/* Resource-style configuration */
/* ************************************************************************* */
static int
cb_authentication (mu_cfg_locus_t *locus, void *data, char *arg)
{
if (strcmp (arg, "clear") == 0)
mu_authentication_clear_list ();
else
mu_authentication_add_module_list (arg);/*FIXME: error reporting*/
return 0;
}
static int
cb_authorization (mu_cfg_locus_t *locus, void *data, char *arg)
{
if (strcmp (arg, "clear") == 0)
mu_authorization_clear_list ();
else
mu_authorization_add_module_list (arg);
return 0;
}
static struct mu_cfg_param mu_auth_param[] = {
{ "authentication", mu_cfg_callback, NULL, cb_authentication },
{ "authorization", mu_cfg_callback, NULL, cb_authorization },
{ NULL }
};
/* FIXME: init? */
/* This file is part of GNU Mailutils
Copyright (C) 2007 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.
This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "libcfg.h"
#include <string.h>
#include <mailutils/daemon.h>
static struct mu_gocs_daemon daemon_settings;
static struct mu_gocs_locking locking_settings;
static struct mu_gocs_logging logging_settings;
static struct mu_gocs_mailbox mailbox_settings;
static struct mu_gocs_source_email address_settings;
static struct mu_gocs_mailer mailer_settings;
/* ************************************************************************* */
/* Mailbox */
/* ************************************************************************* */
static struct mu_cfg_param mu_mailbox_param[] = {
{ "mail-spool", mu_cfg_string, &mailbox_settings.mail_spool },
{ "mailbox-type", mu_cfg_string, &mailbox_settings.mailbox_type },
{ NULL }
};
DCL_CFG_CAPA (mailbox);
/* ************************************************************************* */
/* Locking */
/* ************************************************************************* */
static struct mu_cfg_param mu_locking_param[] = {
{ "lock-flags", mu_cfg_string, &locking_settings.lock_flags },
{ "lock-retry-timeout", mu_cfg_ulong, &locking_settings.lock_retry_timeout },
{ "lock-retry-count", mu_cfg_ulong, &locking_settings.lock_retry_count },
{ "lock-expire-timeout", mu_cfg_ulong,
&locking_settings.lock_expire_timeout },
{ "external-locker", mu_cfg_string, &locking_settings.external_locker },
{ NULL, }
};
DCL_CFG_CAPA (locking);
/* ************************************************************************* */
/* Address */
/* ************************************************************************* */
static struct mu_cfg_param mu_address_param[] = {
{ "email-addr", mu_cfg_string, &address_settings.address },
{ "email-domain", mu_cfg_string, &address_settings.domain },
{ NULL }
};
DCL_CFG_CAPA (address);
/* ************************************************************************* */
/* Mailer */
/* ************************************************************************* */
static struct mu_cfg_param mu_mailer_param[] = {
{ "url", mu_cfg_string, &mailer_settings.mailer },
{ NULL }
};
DCL_CFG_CAPA (mailer);
/* ************************************************************************* */
/* Logging */
/* ************************************************************************* */
static struct mu_cfg_param mu_logging_param[] = {
{ "facility", mu_cfg_string, &logging_settings.facility },
{ NULL }
};
DCL_CFG_CAPA (logging);
/* ************************************************************************* */
/* Daemon */
/* ************************************************************************* */
static int
_cb_daemon_mode (mu_cfg_locus_t *locus, void *data, char *arg)
{
if (strcmp (arg, "inetd") == 0
|| strcmp (arg, "interactive") == 0)
daemon_settings.mode = MODE_INTERACTIVE;
else if (strcmp (arg, "daemon") == 0)
daemon_settings.mode = MODE_DAEMON;
else
{
mu_error ("%s:%d: unknown daemon mode", locus->file, locus->line);
return 1;
}
return 0;
}
static struct mu_cfg_param mu_daemon_param[] = {
{ "max-children", mu_cfg_ulong, &daemon_settings.maxchildren },
{ "mode", mu_cfg_callback, NULL, _cb_daemon_mode },
{ "transcript", mu_cfg_bool, &daemon_settings.transcript },
{ "pidfile", mu_cfg_string, &daemon_settings.pidfile },
{ "port", mu_cfg_ushort, &daemon_settings.port },
{ "timeout", mu_cfg_ulong, &daemon_settings.timeout },
{ NULL }
};
/* This file is part of GNU Mailutils
Copyright (C) 2007 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.
This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "libcfg.h"
#include <mailutils/gsasl.h>
static struct mu_gsasl_module_data gsasl_settings;
static struct mu_cfg_param mu_gsasl_param[] = {
{ "cram-passwd", mu_cfg_string, &gsasl_settings.cram_md5_pwd },
{ NULL }
};
DCL_CFG_CAPA (gsasl);
/* This file is part of GNU Mailutils
Copyright (C) 2007 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.
This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "libcfg.h"
#include <string.h>
#include <stdlib.h>
struct mu_cfg_capa *cfg_capa_table[] = {
#define S(c) &__mu_common_cat3__(mu_,c,_cfg_capa)
S (mailbox),
S (locking),
S (address),
S (mailer),
S (logging),
S (gsasl),
S (pam),
S (radius),
S (sql),
S (tls),
S (virtdomain),
NULL
};
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[] = { "auth", "common", "daemon", "license", NULL };
char **p;
for (p = reserved; *p; p++)
if (strcmp (name, *p) == 0)
return 1;
return 0;
}
void
mu_libcfg_init (const 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_error (_("Requested unknown configuration group `%s'"),
cnames[i]);
else
mu_config_register_section (NULL, cp->name, cp->parser, NULL,
cp->cfgparam);
}
}
}
int
mu_parse_config_files (struct mu_cfg_param *param)
{
if (mu_load_site_rcfile)
mu_parse_config (MU_CONFIG_FILE, mu_program_name, param, 1);
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);
mu_parse_config (file_name, mu_program_name, param, 0);
free (file_name);
}
}
if (mu_load_rcfile)
mu_parse_config (mu_load_rcfile, mu_program_name, param, 0);
return 0;
}
/* GNU Mailutils -- a suite of utilities for electronic mail
Copyright (C) 2007 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, write to the
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301 USA */
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
#include <mailutils/cfg.h>
#include <mailutils/gocs.h>
#include <mailutils/nls.h>
#include <mailutils/error.h>
#include <mailutils/errno.h>
#ifndef MU_CONFIG_FILE
# define MU_CONFIG_FILE SYSCONFDIR "/mailutils.rc"
#endif
#ifndef MU_USER_CONFIG_FILE
# define MU_USER_CONFIG_FILE "~/.mailutils"
#endif
struct mu_cfg_capa
{
char *name;
struct mu_cfg_param *cfgparam;
mu_cfg_section_fp parser;
};
extern int mu_register_cfg_capa (const char *name,
struct mu_cfg_param *cfgparam,
mu_cfg_section_fp *parser);
extern void mu_libcfg_init (const char **cnames);
extern int mu_parse_config_files (struct mu_cfg_param *param);
#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, \
void *section_data, void *call_data) \
{ \
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_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;
/* This file is part of GNU Mailutils
Copyright (C) 2007 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.
This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "libcfg.h"
static char *pam_settings;
static struct mu_cfg_param mu_pam_param[] = {
{ "service", mu_cfg_string, &pam_settings },
{ NULL }
};
DCL_CFG_CAPA (pam);
/* This file is part of GNU Mailutils
Copyright (C) 2007 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.
This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "libcfg.h"
#include <mailutils/radius.h>
static struct mu_radius_module_data radius_settings;
static struct mu_cfg_param mu_radius_param[] = {
{ "auth-request", mu_cfg_string, &radius_settings.auth_request },
{ "getpwnam-request", mu_cfg_string, &radius_settings.getpwnam_request },
{ "getpwuid-request", mu_cfg_string, &radius_settings.getpwuid_request },
{ "directory", mu_cfg_string, &radius_settings.config_dir },
{ NULL }
};
DCL_CFG_CAPA (radius);
/* This file is part of GNU Mailutils
Copyright (C) 2007 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.
This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "libcfg.h"
#include <mailutils/libsieve.h>
static struct mu_gocs_sieve sieve_settings;
static int
cb_clear_library_path (mu_cfg_locus_t *locus, void *data, char *arg)
{
int flag;
if (mu_cfg_parse_boolean (arg, &flag))
{
mu_error ("%s:%u: %s", locus->file, locus->line, _("not a boolean"));
return 1;
}
if (flag)
sieve_settings.clearflags |= MU_SIEVE_CLEAR_LIBRARY_PATH;
return 0;
}
static int
cb_clear_include_path (mu_cfg_locus_t *locus, void *data, char *arg)
{
int flag;
if (mu_cfg_parse_boolean (arg, &flag))
{
mu_error ("%s:%u: %s", locus->file, locus->line, _("not a boolean"));
return 1;
}
if (flag)
sieve_settings.clearflags |= MU_SIEVE_CLEAR_INCLUDE_PATH;
return 0;
}
static void
destroy_string (void *str)
{
free (str);
}
static int
_add_path (mu_list_t *plist, mu_cfg_locus_t *locus, void *data, char *arg)
{
char *p;
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, destroy_string);
}
for (p = strtok (arg, ":"); p; p = strtok (NULL, ":"))
mu_list_append (*plist, strdup (p));
return 0;
}
static int
cb_include_path (mu_cfg_locus_t *locus, void *data, char *arg)
{
return _add_path (&sieve_settings.include_path, locus, data, arg);
}
static int
cb_library_path (mu_cfg_locus_t *locus, void *data, char *arg)
{
return _add_path (&sieve_settings.library_path, locus, data, arg);
}
static struct mu_cfg_param mu_sieve_param[] = {
{ "clear-library-path", mu_cfg_callback, NULL, cb_clear_library_path },
{ "clear-include-path", mu_cfg_callback, NULL, cb_clear_include_path },
{ "library-path", mu_cfg_callback, NULL, cb_library_path },
{ "include-path", mu_cfg_callback, NULL, cb_include_path },
{ NULL }
};
DCL_CFG_CAPA (sieve);
/* This file is part of GNU Mailutils
Copyright (C) 2007 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.
This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "libcfg.h"
#include <mailutils/sql.h>
#include <mailutils/mutil.h>
static struct mu_sql_module_config sql_settings;
/* Resource file configuration */
static int
cb_password_type (mu_cfg_locus_t *locus, void *data, char *arg)
{
if (mu_sql_decode_password_type (arg, &sql_settings.password_type))
mu_error (_("%s:%d: Unknown password type `%s'"),
locus->file, locus->line, arg);
return 0;
}
static int
cb_field_map (mu_cfg_locus_t *locus, void *data, char *arg)
{
int err;
int rc = mutil_parse_field_map (arg, &sql_settings.field_map, &err);
if (rc)
mu_error (_("%s:%d: Error near element %d: %s"),
locus->file, locus->line, err, mu_strerror (rc));
return 0;
}
static struct mu_cfg_param mu_sql_param[] = {
{ "interface", mu_cfg_string, &sql_settings.interface },
{ "getwpnam", mu_cfg_string, &sql_settings.getpwnam_query },
{ "getpwuid", mu_cfg_string, &sql_settings.getpwuid_query },
{ "getpass", mu_cfg_string, &sql_settings.getpass_query },
{ "host", mu_cfg_string, &sql_settings.host },
{ "user", mu_cfg_string, &sql_settings.user },
{ "passwd", mu_cfg_string, &sql_settings.passwd },
{ "db", mu_cfg_string, &sql_settings.db },
{ "port", mu_cfg_int, &sql_settings.port },
{ "password-type", mu_cfg_callback, NULL, cb_password_type },
{ "field-map", mu_cfg_callback, NULL, cb_field_map },
{ NULL }
};
DCL_CFG_CAPA (sql);
/* This file is part of GNU Mailutils
Copyright (C) 2007 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.
This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "libcfg.h"
#include <mailutils/tls.h>
static struct mu_tls_module_config tls_settings;
static struct mu_cfg_param mu_tls_param[] = {
{ "tls", mu_cfg_bool, &tls_settings.client_enable },
{ "ssl-cert", mu_cfg_string, &tls_settings.ssl_cert },
{ "ssl-key", mu_cfg_string, &tls_settings.ssl_key },
{ "ssl-cafile", mu_cfg_string, &tls_settings.ssl_cafile },
{ NULL }
};
DCL_CFG_CAPA (tls);
/* This file is part of GNU Mailutils
Copyright (C) 2007 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.
This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "libcfg.h"
static char *virtdomain_settings;
static struct mu_cfg_param mu_virtdomain_param[] = {
{ "passwd-dir", mu_cfg_string, &virtdomain_settings },
{ NULL }
};
DCL_CFG_CAPA (virtdomain);
......@@ -29,7 +29,7 @@ lib_LTLIBRARIES = libsieve.la
libsieve_la_SOURCES = \
actions.c\
argp.c\
conf.c\
comparator.c\
load.c\
prog.c\
......
/* GNU Mailutils -- a suite of utilities for electronic mail
Copyright (C) 1999, 2000, 2001, 2002, 2005,
2007 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, write to the
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301 USA */
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
#include <sieve.h>
#include <string.h>
mu_list_t mu_sieve_include_path = NULL;
mu_list_t mu_sieve_library_path = NULL;
static void
destroy_string (void *str)
{
free (str);
}
static int
_path_append (void *item, 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, destroy_string);
}
return mu_list_append (*plist, strdup (item));
}
int
mu_sieve_module_init (void *data)
{
struct mu_gocs_sieve *p;
if (!data)
return 0;
p = data;
if (p->clearflags & MU_SIEVE_CLEAR_INCLUDE_PATH)
mu_list_destroy (&mu_sieve_include_path);
mu_list_do (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_do (p->library_path, _path_append, &mu_sieve_library_path);
sieve_load_add_path (mu_sieve_library_path);
mu_list_destroy (&p->library_path);
mu_list_destroy (&p->include_path);
return 0;
}
......@@ -31,7 +31,7 @@ maidag_SOURCES=\
maidag_LDADD = \
@LIBMU_SCM@ @GUILE_LIBS@\
@LIBMU_SCM_DEPS@\
../lib/libmuaux.la \
${MU_APP_LIBRARIES}\
${MU_LIB_SIEVE}\
${MU_LIB_MBOX}\
${MU_LIB_IMAP}\
......
......@@ -252,7 +252,7 @@ lmtp_reply (FILE *fp, char *code, char *enh, char *fmt, ...)
vasprintf (&str, fmt, ap);
va_end (ap);
if (daemon_param.transcript)
if (mu_gocs_daemon.transcript)
{
if (enh)
syslog (LOG_INFO, "LMTP reply: %s %s %s", code, enh, str);
......@@ -737,7 +737,7 @@ lmtp_loop (FILE *in, FILE *out)
trimnl (buf);
if (daemon_param.transcript)
if (mu_gocs_daemon.transcript)
syslog (LOG_INFO, "LMTP recieve: %s", buf);
if (next_state != state_none)
......@@ -784,7 +784,7 @@ lmtp_daemon (char *urlstr)
socklen_t addrlen;
pid_t pid;
if (daemon_param.mode == MODE_DAEMON)
if (mu_gocs_daemon.mode == MODE_DAEMON)
{
if (daemon (0, 0) < 0)
{
......@@ -819,7 +819,7 @@ lmtp_daemon (char *urlstr)
for (;;)
{
process_cleanup ();
if (children > daemon_param.maxchildren)
if (children > mu_gocs_daemon.maxchildren)
{
mu_error (_("too many children (%lu)"),
(unsigned long) children);
......@@ -879,11 +879,11 @@ maidag_lmtp_server ()
if (lmtp_url_string)
return lmtp_daemon (lmtp_url_string);
else if (daemon_param.mode == MODE_INTERACTIVE)
else if (mu_gocs_daemon.mode == MODE_INTERACTIVE)
return lmtp_loop (stdin, stdout);
else
{
const char *pstr = mu_umaxtostr (0, daemon_param.port);
const char *pstr = mu_umaxtostr (0, mu_gocs_daemon.port);
char *urls = malloc (sizeof (DEFAULT_URL) + strlen (pstr));
if (!urls)
{
......
......@@ -50,7 +50,7 @@ char *lmtp_url_string;
int reuse_lmtp_address = 1;
char *lmtp_group = "mail";
struct daemon_param daemon_param = {
struct mu_gocs_daemon daemon_param = {
MODE_INTERACTIVE, /* Start in interactive (inetd) mode */
20, /* Default maximum number of children */
0, /* No standard port */
......@@ -111,7 +111,7 @@ static struct argp argp = {
NULL, NULL
};
static const char *argp_capa[] = {
static const char *maidag_argp_capa[] = {
"daemon",
"auth",
"common",
......@@ -119,7 +119,6 @@ static const char *argp_capa[] = {
"logging",
"mailbox",
"mailer",
"sieve",
NULL
};
......@@ -255,10 +254,10 @@ struct mu_cfg_param maidag_cfg_param[] = {
#ifdef USE_SQL
{ "quota-query", mu_cfg_string, &quota_query },
#endif
{ "sieve", mu_cfg_string, &sieve_pattern },
{ "sieve-filter", mu_cfg_string, &sieve_pattern },
{ "message-id-header", mu_cfg_string, &message_id_header },
#ifdef WITH_GUILE
{ "source", mu_cfg_string, &progfile_pattern },
{ "guile-filter", mu_cfg_string, &progfile_pattern },
#endif
{ "debug", mu_cfg_callback, NULL, cb_debug },
{ "stderr", mu_cfg_bool, &log_to_stderr },
......@@ -461,8 +460,6 @@ main (int argc, char *argv[])
mu_locker_set_default_retry_timeout (1);
mu_locker_set_default_retry_count (300);
/* Default error code for command line errors */
mu_argp_error_code = EX_CONFIG;
/* Register needed modules */
MU_AUTH_REGISTER_ALL_MODULES ();
......@@ -473,12 +470,13 @@ main (int argc, char *argv[])
mu_registrar_record (mu_sendmail_record);
mu_registrar_record (mu_smtp_record);
mu_argp_init (program_version, NULL);
mu_sieve_argp_init ();
mu_gocs_register ("sieve", mu_sieve_module_init);
/* Parse command line */
mu_argp_set_config_param (maidag_cfg_param);
mu_argp_parse (&argp, &argc, &argv, 0, argp_capa, &arg_index, &daemon_param);
mu_argp_init (program_version, NULL);
if (mu_app_init (&argp, maidag_argp_capa, maidag_cfg_param,
argc, argv, 0, &arg_index, NULL))
exit (EX_CONFIG);
current_uid = getuid ();
......
......@@ -82,6 +82,7 @@
#include <mailutils/mu_auth.h>
#include <mailutils/libsieve.h>
#include <mailutils/nls.h>
#include <mailutils/daemon.h>
#include <mu_dbm.h>
#include <mu_asprintf.h>
......@@ -91,7 +92,8 @@
# define USE_MAILBOX_QUOTAS 1
#endif
#include <mailutils/argp.h>
#include "muinit.h"
/* Debug */
extern int debug_level;
#define dbg() if (debug_level) debug
......@@ -120,7 +122,6 @@ extern int lmtp_mode;
extern char *lmtp_url_string;
extern int reuse_lmtp_address;
extern char *lmtp_group;
extern struct daemon_param daemon_param;
void close_fds (void);
int switch_user_id (struct mu_auth_data *auth, int user);
......
......@@ -162,12 +162,12 @@ sql_retrieve_quota (char *name, mu_off_t *quota)
return RETR_FAILURE;
status = mu_sql_connection_init (&conn,
sql_interface,
mu_sql_host,
mu_sql_port,
mu_sql_user,
mu_sql_passwd,
mu_sql_db);
mu_sql_module_config.interface,
mu_sql_module_config.host,
mu_sql_module_config.port,
mu_sql_module_config.user,
mu_sql_module_config.passwd,
mu_sql_module_config.db);
if (status)
{
......
......@@ -26,7 +26,7 @@ mail_local_SOURCES = main.c mailquota.c script.c mail.local.h
mail_local_LDADD = \
@LIBMU_SCM@ @GUILE_LIBS@\
@LIBMU_SCM_DEPS@\
../lib/libmuaux.la \
${MU_APP_LIBRARIES}\
${MU_LIB_SIEVE}\
${MU_LIB_MBOX}\
${MU_LIB_IMAP}\
......
......@@ -92,7 +92,6 @@
# define USE_MAILBOX_QUOTAS 1
#endif
#include <mailutils/argp.h>
/* Debug */
extern int debug_level;
#define dbg() if (debug_level) debug
......
......@@ -162,12 +162,12 @@ sql_retrieve_quota (char *name, mu_off_t *quota)
return RETR_FAILURE;
status = mu_sql_connection_init (&conn,
sql_interface,
mu_sql_host,
mu_sql_port,
mu_sql_user,
mu_sql_passwd,
mu_sql_db);
mu_sql_module_config.interface,
mu_sql_module_config.host,
mu_sql_module_config.port,
mu_sql_module_config.user,
mu_sql_module_config.passwd,
mu_sql_module_config.db);
if (status)
{
......
......@@ -18,6 +18,7 @@
MA 02110-1301 USA */
#include <mail.local.h>
#include "muinit.h"
int multiple_delivery; /* Don't return errors when delivering to multiple
recipients */
......@@ -117,7 +118,6 @@ static const char *argp_capa[] = {
"logging",
"mailbox",
"mailer",
"sieve",
NULL
};
......@@ -365,15 +365,14 @@ main (int argc, char *argv[])
mu_locker_set_default_retry_timeout (1);
mu_locker_set_default_retry_count (300);
/* Default error code for command line errors */
mu_argp_error_code = EX_CONFIG;
/* Register needed modules */
MU_AUTH_REGISTER_ALL_MODULES();
mu_argp_init (program_version, NULL);
mu_sieve_argp_init ();
/* Parse command line */
mu_argp_set_config_param (mail_local_cfg_param);
mu_argp_parse (&argp, &argc, &argv, 0, argp_capa, &arg_index, NULL);
mu_gocs_register ("sieve", mu_sieve_module_init);
mu_argp_init (program_version, NULL);
if (mu_app_init (&argp, argp_capa, mail_local_cfg_param,
argc, argv, 0, &arg_index, NULL))
exit (EX_CONFIG);
uid = getuid ();
......
......@@ -27,7 +27,7 @@ libexec_PROGRAMS = @BUILD_SMTP_PROGRAMS@
mail_remote_SOURCES = mail.remote.c
mail_remote_LDADD = \
../lib/libmuaux.la\
${MU_APP_LIBRARIES}\
${MU_LIB_AUTH}\
${MU_LIB_MAILER}\
@MU_AUTHLIBS@\
......
......@@ -31,7 +31,6 @@
#include <unistd.h>
#include <mailutils/address.h>
#include <mailutils/argp.h>
#include <mailutils/debug.h>
#include <mailutils/errno.h>
#include <mailutils/list.h>
......@@ -44,6 +43,7 @@
#include <mailutils/error.h>
#include <mailutils/nls.h>
#include <mailutils/mu_auth.h>
#include "muinit.h"
const char *program_version = "mail.remote (" PACKAGE_STRING ")";
static char doc[] =
......@@ -171,8 +171,9 @@ main (int argc, char **argv)
MU_AUTH_REGISTER_ALL_MODULES();
mu_argp_init (program_version, NULL);
mu_argp_set_config_param (mail_remote_cfg_param);
mu_argp_parse (&argp, &argc, &argv, 0, capa, &optind, NULL);
if (mu_app_init (&argp, capa, mail_remote_cfg_param,
argc, argv, 0, &optind, NULL))
exit (1);
if (optfrom)
{
......
......@@ -24,7 +24,7 @@ AM_CFLAGS = -DSITE_MAIL_RC=\"@SITE_MAIL_RC@\"
bin_PROGRAMS = mail
mail_LDADD = \
../lib/libmuaux.la\
${MU_APP_LIBRARIES}\
${MU_LIB_MBOX}\
${MU_LIB_IMAP}\
${MU_LIB_POP}\
......
......@@ -18,6 +18,7 @@
MA 02110-1301 USA */
#include "mail.h"
#include "muinit.h"
/* Global variables and constants*/
mu_mailbox_t mbox; /* Mailbox being operated upon */
......@@ -178,9 +179,6 @@ static const char *mail_capa[] = {
"common",
"license",
"mailbox",
#ifdef WITH_TLS
"tls",
#endif
NULL
};
......@@ -353,12 +351,12 @@ main (int argc, char **argv)
args.send_mode = 0;
/* argument parsing */
mu_argp_init (program_version, NULL);
#ifdef WITH_TLS
mu_tls_init_client_argp ();
mu_gocs_register ("tls", mu_tls_module_init);
#endif
mu_argp_parse (&argp, &argc, &argv, 0, mail_capa, NULL, &args);
mu_argp_init (program_version, NULL);
if (mu_app_init (&argp, mail_capa, NULL, argc, argv, 0, NULL, &args))
exit (1);
/* read system-wide mail.rc and user's .mailrc */
if (util_getenv (NULL, "rc", Mail_env_boolean, 0) == 0)
......
......@@ -61,7 +61,6 @@
#endif
#include <mailutils/address.h>
#include <mailutils/argp.h>
#include <mailutils/assoc.h>
#include <mailutils/attribute.h>
#include <mailutils/body.h>
......@@ -179,6 +178,7 @@ extern mu_mailbox_t mbox;
extern size_t total;
extern FILE *ofile;
extern int interactive;
extern const char *program_version;
/* Functions */
extern int mail_alias (int argc, char **argv);
......
......@@ -514,7 +514,7 @@ mail_send0 (compose_env_t * env, int save_to)
/* Prepare the header */
if (util_getenv (NULL, "xmailer", Mail_env_boolean, 0) == 0)
mu_header_set_value (env->header, MU_HEADER_X_MAILER,
argp_program_version, 1);
program_version, 1);
if (util_header_expand (&env->header) == 0)
{
......
......@@ -40,7 +40,7 @@ static const char *with_defs[] =
int
mail_version (int argc MU_ARG_UNUSED, char **argv MU_ARG_UNUSED)
{
fprintf (ofile, "%s", argp_program_version);
fprintf (ofile, "%s", program_version);
if (with_defs[0] != NULL)
{
int i;
......
......@@ -11,3 +11,5 @@ mailutils-config
parsedate.c
*y.output
muerrno.c
cfg_parser.c
cfg_parser.h
......
......@@ -35,64 +35,65 @@ AM_CPPFLAGS = \
EXTRA_DIST = @MU_EXTRA_DIST@ errors muerrno.cin parsedate.y fgetpwent.c cfg_parser.y cfg_parser.h
libmailutils_la_SOURCES = \
address.c \
amd.c \
argcv.c \
assoc.c \
attachment.c \
attribute.c \
auth.c \
body.c \
daemon.c \
date.c \
debug.c \
cfg_lexer.c \
cfg_parser.c \
envelope.c \
file_stream.c \
filter.c \
filter_iconv.c \
filter_rfc822.c \
filter_trans.c \
folder.c \
header.c \
iterator.c \
list.c \
locale.c \
locker.c \
mailbox.c \
mailcap.c \
mailer.c \
mapfile_stream.c \
mbx_default.c \
message.c \
memory_stream.c \
message_stream.c \
mime.c \
monitor.c \
mu_argp.c \
mu_auth.c \
mu_umaxtostr.h \
mu_umaxtostr.c \
munre.c \
mutil.c \
muerror.c \
muerrno.c \
nls.c \
observer.c \
parse822.c \
parsedate.c \
property.c \
registrar.c \
refcount.c \
rfc2047.c \
socket_stream.c \
stream.c \
system.c \
tcp.c \
ticket.c \
url.c \
wicket.c
address.c\
amd.c\
argcv.c\
assoc.c\
attachment.c\
attribute.c\
auth.c\
body.c\
daemon.c\
date.c\
debug.c\
cfg_lexer.c\
cfg_parser.c\
envelope.c\
file_stream.c\
filter.c\
filter_iconv.c\
filter_rfc822.c\
filter_trans.c\
folder.c\
gocs.c\
header.c\
iterator.c\
list.c\
locale.c\
locker.c\
mailbox.c\
mailcap.c\
mailer.c\
mapfile_stream.c\
mbx_default.c\
message.c\
memory_stream.c\
message_stream.c\
mime.c\
monitor.c\
mu_auth.c\
mu_umaxtostr.h\
mu_umaxtostr.c\
munre.c\
mutil.c\
muerror.c\
muerrno.c\
nls.c\
observer.c\
parse822.c\
parsedate.c\
property.c\
registrar.c\
refcount.c\
rfc2047.c\
socket_stream.c\
stream.c\
syslog.c\
system.c\
tcp.c\
ticket.c\
url.c\
wicket.c
BUILT_SOURCES = parsedate.c muerrno.c cfg_parser.c cfg_parser.h
MOSTLYCLEANFILES=
......
......@@ -806,22 +806,30 @@ parse_cidr (struct scan_tree_data *sdata, const mu_cfg_node_t *node,
return 0;
}
static int
parse_bool (struct scan_tree_data *sdata, const mu_cfg_node_t *node, int *res)
int
mu_cfg_parse_boolean (const char *str, int *res)
{
if (strcmp (node->tag_label, "yes") == 0
|| strcmp (node->tag_label, "on") == 0
|| strcmp (node->tag_label, "t") == 0
|| strcmp (node->tag_label, "true") == 0
|| strcmp (node->tag_label, "1") == 0)
if (strcmp (str, "yes") == 0
|| strcmp (str, "on") == 0
|| strcmp (str, "t") == 0
|| strcmp (str, "true") == 0
|| strcmp (str, "1") == 0)
*res = 1;
else if (strcmp (node->tag_label, "no") == 0
|| strcmp (node->tag_label, "off") == 0
|| strcmp (node->tag_label, "nil") == 0
|| strcmp (node->tag_label, "false") == 0
|| strcmp (node->tag_label, "0") == 0)
else if (strcmp (str, "no") == 0
|| strcmp (str, "off") == 0
|| strcmp (str, "nil") == 0
|| strcmp (str, "false") == 0
|| strcmp (str, "0") == 0)
*res = 0;
else
return 1;
return 0;
}
static int
parse_bool (struct scan_tree_data *sdata, const mu_cfg_node_t *node, int *res)
{
if (mu_cfg_parse_boolean (node->tag_label, res))
{
mu_cfg_perror (sdata->call_data, &node->locus, _("not a boolean"));
return 1;
......
......@@ -77,3 +77,24 @@ mu_daemon_remove_pidfile (void)
}
}
struct mu_gocs_daemon mu_gocs_daemon;
int
mu_gocs_daemon_init (void *data)
{
if (data)
{
struct mu_gocs_daemon *cfg = data;
mu_gocs_daemon = *cfg;
if (mu_gocs_daemon.maxchildren)
mu_gocs_daemon.mode = MODE_DAEMON;
if (mu_gocs_daemon.pidfile)
mu_gocs_daemon.mode = MODE_DAEMON;
}
return 0;
}
......
/* GNU Mailutils -- a suite of utilities for electronic mail
Copyright (C) 1999, 2001, 2002, 2003, 2004, 2005, 2006,
2007 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, write to the
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301 USA */
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
#include <getline.h>
#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>
#ifdef HAVE_STRINGS_H
# include <strings.h>
#endif
#include <mailutils/argp.h>
#include <mailutils/error.h>
#include <mailutils/errno.h>
#include <mailutils/mutil.h>
#include <mailutils/locker.h>
#include <mailutils/mailer.h>
#include <mailutils/mailbox.h>
#include <mailutils/nls.h>
#include <mailutils/argcv.h>
#include <mailutils/cfg.h>
/* ************************************************************************* */
/* Variables and auxiliary functions. */
/* FIXME: The variables should be global. */
/* ************************************************************************* */
static char *mail_spool_option;
static char *mailbox_type_option;
static char *lock_flags_option;
static unsigned long lock_retry_timeout_option;
static unsigned long lock_retry_count_option;
static unsigned long lock_expire_timeout_option;
static char *external_locker_option;
static char *email_addr_option;
static char *email_domain_option;
static char *mailer_option;
static char *log_facility_option;
static unsigned int daemon_max_children_option;
static char *daemon_mode_option;
static unsigned int daemon_transcript_option;
static char *daemon_pidfile_option;
static unsigned short daemon_port_option;
static unsigned int daemon_timeout_option;
int log_facility = LOG_FACILITY;
int mu_argp_error_code = 1;
static int
parse_log_facility (const char *str)
{
int i;
static struct {
char *name;
int facility;
} syslog_kw[] = {
{ "USER", LOG_USER },
{ "DAEMON", LOG_DAEMON },
{ "AUTH", LOG_AUTH },
{ "LOCAL0", LOG_LOCAL0 },
{ "LOCAL1", LOG_LOCAL1 },
{ "LOCAL2", LOG_LOCAL2 },
{ "LOCAL3", LOG_LOCAL3 },
{ "LOCAL4", LOG_LOCAL4 },
{ "LOCAL5", LOG_LOCAL5 },
{ "LOCAL6", LOG_LOCAL6 },
{ "LOCAL7", LOG_LOCAL7 },
{ "MAIL", LOG_MAIL }
};
if (strncmp (str, "LOG_", 4) == 0)
str += 4;
for (i = 0; i < sizeof (syslog_kw) / sizeof (syslog_kw[0]); i++)
if (strcasecmp (syslog_kw[i].name, str) == 0)
return syslog_kw[i].facility;
fprintf (stderr, _("Unknown facility `%s'\n"), str);
return LOG_FACILITY;
}
char *mu_license_text =
N_(" GNU Mailutils is free software; you can redistribute it and/or modify\n"
" it under the terms of the GNU General Public License as published by\n"
" the Free Software Foundation; either version 3 of the License, or\n"
" (at your option) any later version.\n"
"\n"
" GNU Mailutils is distributed in the hope that it will be useful,\n"
" but WITHOUT ANY WARRANTY; without even the implied warranty of\n"
" MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n"
" GNU General Public License for more details.\n"
"\n"
" You should have received a copy of the GNU General Public License along\n"
" with GNU Mailutils; if not, write to the Free Software Foundation,\n"
" Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA\n"
"\n"
"\n"
);
static char *mu_conf_option[] = {
"VERSION=" VERSION,
#ifdef USE_LIBPAM
"USE_LIBPAM",
#endif
#ifdef HAVE_LIBLTDL
"HAVE_LIBLTDL",
#endif
#ifdef WITH_BDB2
"WITH_BDB2",
#endif
#ifdef WITH_NDBM
"WITH_NDBM",
#endif
#ifdef WITH_OLD_DBM
"WITH_OLD_DBM",
#endif
#ifdef WITH_GDBM
"WITH_GDBM",
#endif
#ifdef WITH_GNUTLS
"WITH_GNUTLS",
#endif
#ifdef WITH_GSASL
"WITH_GSASL",
#endif
#ifdef WITH_GSSAPI
"WITH_GSSAPI",
#endif
#ifdef WITH_GUILE
"WITH_GUILE",
#endif
#ifdef WITH_PTHREAD
"WITH_PTHREAD",
#endif
#ifdef WITH_READLINE
"WITH_READLINE",
#endif
#ifdef HAVE_MYSQL
"HAVE_MYSQL",
#endif
#ifdef HAVE_PGSQL
"HAVE_PGSQL",
#endif
#ifdef ENABLE_VIRTUAL_DOMAINS
"ENABLE_VIRTUAL_DOMAINS",
#endif
#ifdef ENABLE_IMAP
"ENABLE_IMAP",
#endif
#ifdef ENABLE_POP
"ENABLE_POP",
#endif
#ifdef ENABLE_MH
"ENABLE_MH",
#endif
#ifdef ENABLE_MAILDIR
"ENABLE_MAILDIR",
#endif
#ifdef ENABLE_SMTP
"ENABLE_SMTP",
#endif
#ifdef ENABLE_SENDMAIL
"ENABLE_SENDMAIL",
#endif
#ifdef ENABLE_NNTP
"ENABLE_NNTP",
#endif
#ifdef ENABLE_RADIUS
"ENABLE_RADIUS",
#endif
#ifdef WITH_INCLUDED_LIBINTL
"WITH_INCLUDED_LIBINTL",
#endif
NULL
};
void
mu_print_options ()
{
int i;
for (i = 0; mu_conf_option[i]; i++)
printf ("%s\n", mu_conf_option[i]);
}
const char *
mu_check_option (char *name)
{
int i;
for (i = 0; mu_conf_option[i]; i++)
{
int len;
char *q, *p = strchr (mu_conf_option[i], '=');
if (p)
len = p - mu_conf_option[i];
else
len = strlen (mu_conf_option[i]);
if (strncasecmp (mu_conf_option[i], name, len) == 0)
return mu_conf_option[i];
else if ((q = strchr (mu_conf_option[i], '_')) != NULL
&& strncasecmp (q + 1, name, len - (q - mu_conf_option[i]) - 1) == 0)
return mu_conf_option[i];
}
return NULL;
}
void
assign_string (char **pstr, char *val)
{
if (!val)
{
if (*pstr)
{
free (*pstr);
*pstr = NULL;
}
}
else
{
size_t size = strlen (val);
char *p = realloc (*pstr, size + 1);
if (!p)
{
mu_error ("%s", mu_strerror (ENOMEM));
exit (1);
}
strcpy (p, val);
*pstr = p;
}
}
#ifndef MU_CONFIG_FILE
# define MU_CONFIG_FILE SYSCONFDIR "/mailutils.rc"
#endif
#ifndef MU_USER_CONFIG_FILE
# define MU_USER_CONFIG_FILE "~/.mailutils"
#endif
static int
member (const char *array[], const char *text, size_t len)
{
int i;
for (i = 0; array[i]; i++)
if (strncmp (array[i], text, len) == 0)
return 1;
return 0;
}
/* ************************************************************************* */
/* Traditional (command-line style) configuration */
/* ************************************************************************* */
#define ARG_LOG_FACILITY 1
#define ARG_LOCK_FLAGS 2
#define ARG_LOCK_RETRY_COUNT 3
#define ARG_LOCK_RETRY_TIMEOUT 4
#define ARG_LOCK_EXPIRE_TIMEOUT 5
#define ARG_LOCK_EXTERNAL_PROGRAM 6
#define ARG_SHOW_OPTIONS 7
#define ARG_LICENSE 8
#define ARG_MAILBOX_TYPE 9
static struct argp_option mu_common_argp_options[] =
{
{ NULL, 0, NULL, 0, N_("Common options"), 0},
{ "show-config-options", ARG_SHOW_OPTIONS, NULL, OPTION_HIDDEN,
N_("Show compilation options"), 0 },
{ NULL, 0, NULL, 0, NULL, 0 }
};
/* Option to print the license. */
static struct argp_option mu_license_argp_option[] = {
{ "license", ARG_LICENSE, NULL, 0, N_("Print license and exit"), -2 },
{ NULL, 0, NULL, 0, NULL, 0 }
};
/* Options used by programs that access mailboxes. */
static struct argp_option mu_mailbox_argp_option[] = {
{"mail-spool", 'm', N_("URL"), OPTION_HIDDEN,
N_("Use specified URL as a mailspool directory"), 0},
{"mailbox-type", ARG_MAILBOX_TYPE, N_("PROTO"), OPTION_HIDDEN,
N_("Default mailbox type to use"), 0 },
{"lock-flags", ARG_LOCK_FLAGS, N_("FLAGS"), OPTION_HIDDEN,
N_("Default locker flags (E=external, R=retry, T=time, P=pid)"), 0},
{"lock-retry-timeout", ARG_LOCK_RETRY_TIMEOUT, N_("SECONDS"), OPTION_HIDDEN,
N_("Set timeout for acquiring the lockfile") },
{"lock-retry-count", ARG_LOCK_RETRY_COUNT, N_("NUMBER"), OPTION_HIDDEN,
N_("Set the maximum number of times to retry acquiring the lockfile") },
{"lock-expire-timeout", ARG_LOCK_EXPIRE_TIMEOUT, N_("SECONDS"), OPTION_HIDDEN,
N_("Number of seconds after which the lock expires"), },
{"external-locker", ARG_LOCK_EXTERNAL_PROGRAM, N_("PATH"), OPTION_HIDDEN,
N_("Set full path to the external locker program") },
{ NULL, 0, NULL, 0, NULL, 0 }
};
/* Options used by programs that do address mapping. */
static struct argp_option mu_address_argp_option[] = {
{"email-addr", 'E', N_("EMAIL"), OPTION_HIDDEN,
N_("Set current user's email address (default is loginname@defaultdomain)"), 0},
{"email-domain", 'D', N_("DOMAIN"), OPTION_HIDDEN,
N_("Set domain for unqualified user names (default is this host)"), 0},
{ NULL, 0, NULL, 0, NULL, 0 }
};
/* 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 }
};
/* Options used by programs that log to syslog. */
static struct argp_option mu_logging_argp_option[] = {
{"log-facility", ARG_LOG_FACILITY, N_("FACILITY"), 0,
N_("Output logs to syslog FACILITY"), 0},
{ NULL, 0, NULL, 0, NULL, 0 }
};
/* Options used by programs that become daemons. */
static struct argp_option mu_daemon_argp_option[] = {
{"daemon", 'd', N_("NUMBER"), OPTION_ARG_OPTIONAL,
N_("Runs in daemon mode with a maximum of NUMBER children")},
{"inetd", 'i', 0, 0,
N_("Run in inetd mode"), 0},
{"port", 'p', N_("PORT"), 0,
N_("Listen on specified port number"), 0},
{"timeout", 't', N_("NUMBER"), OPTION_HIDDEN,
N_("Set idle timeout value to NUMBER seconds"), 0},
{"transcript", 'x', NULL, 0,
N_("Output session transcript via syslog"), 0},
{"pidfile", 'P', N_("FILE"), OPTION_HIDDEN,
N_("Set PID file"), 0},
{ NULL, 0, NULL, 0, NULL, 0 }
};
static error_t mu_common_argp_parser (int key, char *arg,
struct argp_state *state);
static error_t mu_daemon_argp_parser (int key, char *arg,
struct argp_state *state);
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 argp mu_license_argp = {
mu_license_argp_option,
mu_common_argp_parser,
};
struct argp_child mu_license_argp_child = {
&mu_license_argp,
0,
NULL,
0
};
struct argp mu_mailbox_argp = {
mu_mailbox_argp_option,
mu_common_argp_parser,
};
struct argp_child mu_mailbox_argp_child = {
&mu_mailbox_argp,
0,
NULL,
0
};
struct argp mu_address_argp = {
mu_address_argp_option,
mu_common_argp_parser,
};
struct argp_child mu_address_argp_child = {
&mu_address_argp,
0,
NULL,
0
};
struct argp mu_mailer_argp = {
mu_mailer_argp_option,
mu_common_argp_parser,
};
struct argp_child mu_mailer_argp_child = {
&mu_mailer_argp,
0,
NULL,
0
};
struct argp mu_logging_argp = {
mu_logging_argp_option,
mu_common_argp_parser,
};
struct argp_child mu_logging_argp_child = {
&mu_logging_argp,
0,
NULL,
0
};
struct argp mu_daemon_argp = {
mu_daemon_argp_option,
mu_daemon_argp_parser,
};
struct argp_child mu_daemon_argp_child = {
&mu_daemon_argp,
0,
N_("Daemon configuration options"),
0
};
static error_t
mu_common_argp_parser (int key, char *arg, struct argp_state *state)
{
int err = 0;
switch (key)
{
/* common */
case ARG_LICENSE:
printf (_("License for %s:\n\n"), argp_program_version);
printf ("%s", mu_license_text);
exit (0);
case ARG_SHOW_OPTIONS:
mu_print_options ();
exit (0);
/* mailbox */
case 'm':
assign_string (&mail_spool_option, arg);
break;
case ARG_MAILBOX_TYPE:
assign_string (&mailbox_type_option, arg);
break;
case ARG_LOCK_FLAGS:
assign_string (&lock_flags_option, arg);
break;
case ARG_LOCK_RETRY_COUNT:
lock_retry_count_option = strtoul (arg, NULL, 0);
break;
case ARG_LOCK_RETRY_TIMEOUT:
lock_retry_timeout_option = strtoul (arg, NULL, 0);
break;
case ARG_LOCK_EXPIRE_TIMEOUT:
lock_expire_timeout_option = strtoul (arg, NULL, 0);
break;
case ARG_LOCK_EXTERNAL_PROGRAM:
assign_string (&external_locker_option, arg);
break;
/* address */
case 'E':
assign_string (&email_addr_option, arg);
break;
case 'D':
assign_string (&email_domain_option, arg);
break;
/* mailer */
case 'M':
assign_string (&mailer_option, arg);
break;
/* log */
case ARG_LOG_FACILITY:
assign_string (&log_facility_option, arg);
break;
case ARGP_KEY_FINI:
if (mail_spool_option)
{
err = mu_set_mail_directory (mail_spool_option);
if (err)
argp_error (state, _("Cannot set mail directory name: %s"),
mu_strerror (err));
free (mail_spool_option);
mail_spool_option = NULL;
}
if (mailbox_type_option)
{
if (mu_mailbox_set_default_proto (mailbox_type_option))
argp_error (state, _("Invalid mailbox type: %s"),
mailbox_type_option);
free (mailbox_type_option);
mailbox_type_option = NULL;
}
if (lock_flags_option)
{
int flags = 0;
char *p;
for (p = lock_flags_option; *p; p++)
{
switch (*p)
{
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:
argp_error (state, _("Invalid lock flag `%c'"), *p);
}
}
mu_locker_set_default_flags (flags, mu_locker_assign);
free (lock_flags_option);
lock_flags_option = NULL;
}
if (lock_retry_count_option)
{
mu_locker_set_default_retry_count (lock_retry_count_option);
mu_locker_set_default_flags (MU_LOCKER_RETRY, mu_locker_set_bit);
lock_retry_count_option = 0;
}
if (lock_retry_timeout_option)
{
mu_locker_set_default_retry_timeout (lock_retry_timeout_option);
mu_locker_set_default_flags (MU_LOCKER_RETRY, mu_locker_set_bit);
lock_retry_timeout_option = 0;
}
if (lock_expire_timeout_option)
{
mu_locker_set_default_expire_timeout (lock_expire_timeout_option);
mu_locker_set_default_flags (MU_LOCKER_EXTERNAL, mu_locker_set_bit);
lock_expire_timeout_option = 0;
}
if (external_locker_option)
{
mu_locker_set_default_external_program (external_locker_option);
mu_locker_set_default_flags (MU_LOCKER_TIME, mu_locker_set_bit);
free (external_locker_option);
external_locker_option = NULL;
}
if (email_addr_option)
{
if ((err = mu_set_user_email (email_addr_option)) != 0)
{
argp_error (state, _("Invalid email address `%s': %s"),
email_addr_option, mu_strerror (err));
}
free (email_addr_option);
email_addr_option = NULL;
}
if (email_domain_option)
{
if ((err = mu_set_user_email_domain (email_domain_option)) != 0)
{
argp_error (state, _("Invalid email domain `%s': %s"),
email_domain_option, mu_strerror (err));
}
free (email_domain_option);
email_domain_option = NULL;
}
if (mailer_option)
{
if ((err = mu_mailer_set_url_default (mailer_option)) != 0)
{
argp_error (state, _("Invalid mailer URL `%s': %s"),
mailer_option, mu_strerror (err));
}
free (mailer_option);
mailer_option = NULL;
}
if (log_facility_option)
{
log_facility = parse_log_facility (log_facility_option);
free (log_facility_option);
log_facility_option = NULL;
}
break;
default:
return ARGP_ERR_UNKNOWN;
}
return 0;
}
static error_t
mu_daemon_argp_parser (int key, char *arg, struct argp_state *state)
{
struct daemon_param *p = state->input;
if (!p)
return ARGP_ERR_UNKNOWN;
switch (key)
{
case 'd':
assign_string (&daemon_mode_option, "daemon");
if (arg)
{
unsigned long n = strtoul (arg, NULL, 10);
if (n > 0)
daemon_max_children_option = n;
}
break;
case 'i':
assign_string (&daemon_mode_option, "interactive");
break;
case 'p':
assign_string (&daemon_mode_option, "daemon");
daemon_port_option = strtoul (arg, NULL, 10); /*FIXME: overflow */
break;
case 'P':
assign_string (&daemon_pidfile_option, arg);
break;
case 't':
daemon_timeout_option = strtoul (arg, NULL, 10);
break;
case 'x':
daemon_transcript_option = 1;
break;
case ARGP_KEY_FINI:
if (daemon_mode_option)
{
if (strcmp (daemon_mode_option, "daemon") == 0)
p->mode = MODE_DAEMON;
else if (strcmp (daemon_mode_option, "interactive") == 0)
p->mode = MODE_INTERACTIVE;
else /* FIXME */
argp_error (state, _("Invalid daemon mode: `%s'"),
daemon_mode_option);
free (daemon_mode_option);
daemon_mode_option = 0;
}
if (daemon_max_children_option)
{
p->mode = MODE_DAEMON;
p->maxchildren = daemon_max_children_option;
daemon_max_children_option = 0;
}
if (daemon_pidfile_option)
{
p->mode = MODE_DAEMON;
p->pidfile = daemon_pidfile_option;
daemon_pidfile_option = NULL;
}
p->transcript = daemon_transcript_option;
if (daemon_timeout_option)
{
p->timeout = daemon_timeout_option;
daemon_timeout_option = 0;
}
break;
default:
return ARGP_ERR_UNKNOWN;
}
return 0;
}
/* ************************************************************************* */
/* New (resource-file style) configuration */
/* ************************************************************************* */
static struct mu_cfg_param mu_mailbox_param[] = {
{ "mail-spool", mu_cfg_string, &mail_spool_option },
{ "mailbox-type", mu_cfg_string, &mailbox_type_option },
{ "lock-flags", mu_cfg_string, &lock_flags_option },
{ "lock-retry-timeout", mu_cfg_ulong, &lock_retry_timeout_option },
{ "lock-retry-count", mu_cfg_ulong, &lock_retry_count_option },
{ "lock-expire-timeout", mu_cfg_ulong, &lock_expire_timeout_option },
{ "external-locker", mu_cfg_string, &external_locker_option },
{ NULL, }
};
static struct mu_cfg_param mu_address_param[] = {
{ "email-addr", mu_cfg_string, &email_addr_option },
{ "email-domain", mu_cfg_string, &email_domain_option },
{ NULL }
};
static struct mu_cfg_param mu_mailer_param[] = {
{ "url", mu_cfg_string, &mailer_option },
{ NULL }
};
static struct mu_cfg_param mu_logging_param[] = {
{ "facility", mu_cfg_string, &log_facility_option },
{ NULL }
};
static struct mu_cfg_param mu_daemon_param[] = {
{ "max-children", mu_cfg_ulong, &daemon_max_children_option },
{ "mode", mu_cfg_string, &daemon_mode_option },
{ "transcript", mu_cfg_bool, &daemon_transcript_option },
{ "pidfile", mu_cfg_string, &daemon_pidfile_option },
{ "port", mu_cfg_ushort, &daemon_port_option },
{ "timeout", mu_cfg_ulong, &daemon_timeout_option },
{ NULL }
};
/* ************************************************************************* */
/* Capability array and auxiliary functions. */
/* ************************************************************************* */
#define MU_MAX_CAPA 24
struct argp_capa {
char *capability;
struct argp_child *child;
struct mu_cfg_param *param;
} mu_argp_capa[MU_MAX_CAPA] = {
{"common", &mu_common_argp_child},
{"license", &mu_license_argp_child},
{"mailbox", &mu_mailbox_argp_child, mu_mailbox_param },
{"address", &mu_address_argp_child, mu_address_param},
{"mailer", &mu_mailer_argp_child, mu_mailer_param },
{"logging", &mu_logging_argp_child, mu_logging_param },
{"daemon", &mu_daemon_argp_child, mu_daemon_param },
{NULL,}
};
int
mu_register_capa (const char *name, struct argp_child *child,
struct mu_cfg_param *param)
{
int i;
for (i = 0; i < MU_MAX_CAPA; i++)
if (mu_argp_capa[i].capability == NULL)
{
mu_argp_capa[i].capability = strdup (name);
mu_argp_capa[i].child = child;
mu_argp_capa[i].param = param;
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;
}
void
build_config_struct (const char *capa[])
{
struct argp_capa *acp;
for (acp = mu_argp_capa; acp->capability; acp++)
{
struct mu_cfg_param *param;
if (member (capa, acp->capability, strlen (acp->capability)))
param = acp->param;
else
param = NULL;
mu_config_register_plain_section (NULL, acp->capability, param);
}
}
static struct argp *
mu_build_argp (const struct argp *template, const char *capa[])
{
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 (_("Out of 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)
{
mu_error (_("INTERNAL ERROR: requested unknown argp "
"capability %s (please report)"),
capa[n]);
abort ();
}
ap[nchild] = *cp->child;
ap[nchild].group = group++;
nchild++;
}
ap[nchild].argp = NULL;
build_config_struct (capa);
/* Copy the template, and give it the expanded children. */
argp = malloc (sizeof (*argp));
if (!argp)
{
mu_error (_("Out of memory"));
abort ();
}
memcpy (argp, template, sizeof (*argp));
argp->children = ap;
return argp;
}
/* ************************************************************************* */
/* Configuration style detection */
/* ************************************************************************* */
#define CF_GLOBAL 0
#define CF_USER 1
#define CF_SIZE 2
enum mu_config_flavor
{
mu_config_none,
mu_config_auto,
mu_config_options,
mu_config_resource
};
#define isword(c) (isalnum (c) || (c) == '-' || (c) == '_')
static int
getword (FILE *fp, int c)
{
if (c == EOF || isspace (c) || c == '\\')
return 0;
if (c == '"' || c == '\'')
{
int delim = c;
while ((c = getc (fp)) != EOF && c != delim)
{
if (c == '\\')
if ((c = getc (fp)) == EOF)
break;
}
}
else
while ((c = getc (fp)) != EOF && !isspace (c))
;
return 1;
}
static enum mu_config_flavor
deduce_config_flavor (const char *file)
{
int c;
FILE *fp;
size_t optcnt = 0;
size_t wordcnt = 0;
char *file_name = mu_tilde_expansion (file, "/", NULL);
fp = fopen (file_name, "r");
free (file_name);
if (!fp)
return mu_config_none;
while (!feof (fp))
{
while ((c = getc (fp)) != EOF && isspace (c))
;
if (c == '-')
{
if ((c = getc (fp)) == EOF)
break;
if (c == '-')
{
if ((c = getc (fp)) == EOF)
break;
}
if (isword (c))
optcnt++;
if (getword (fp, c))
wordcnt++;
}
else if (getword (fp, c))
wordcnt++;
}
fclose (fp);
if (wordcnt == 0)
return mu_config_none;
else if (optcnt == 0)
return mu_config_resource;
else if (wordcnt / optcnt <= 2)
return mu_config_options;
return mu_config_resource;
}
static enum mu_config_flavor
decode_config_flavor (const char *str)
{
if (strcmp (str, "none") == 0)
return mu_config_none;
else if (strcmp (str, "auto") == 0)
return mu_config_auto;
else if (strcmp (str, "resource") == 0
|| strcmp (str, "new") == 0)
return mu_config_resource;
else if (strcmp (str, "options") == 0
|| strcmp (str, "old") == 0)
return mu_config_options;
else
mu_error (_("invalid configuration flavor: %s"), str);
return mu_config_auto;
}
static void
get_default_config_flavor (const char *progname, enum mu_config_flavor cfl[])
{
char *val = getenv ("MU_CONFIG_FLAVOR");
cfl[CF_GLOBAL] = cfl[CF_USER] = mu_config_auto;
if (val)
{
int i;
int argc;
char **argv;
size_t proglen;
mu_argcv_get (val, ":", NULL, &argc, &argv);
proglen = strlen (progname);
for (i = 0; i < argc; i++)
{
char *p = strchr (argv[i], '=');
if (p)
{
size_t len = p - argv[i];
if (len == proglen &&
memcmp (progname, argv[i], len) == 0)
cfl[CF_USER] = decode_config_flavor (p + 1);
}
else
cfl[CF_GLOBAL] = decode_config_flavor (argv[i]);
}
mu_argcv_free (argc, argv);
}
if (cfl[CF_USER] == mu_config_auto)
cfl[CF_USER] = cfl[CF_GLOBAL];
}
/* ************************************************************************* */
/* Functions for handling traditional-style configuration files. */
/* ************************************************************************* */
/* Appends applicable options found in file NAME to argv. If progname
is NULL, all the options found are assumed to apply. Otherwise they
apply only if the line starts with ":something", and something is
found in the CAPA array, or the line starts with PROGNAME. */
void
read_rc (const char *progname, const char *name, enum mu_config_flavor rf,
const char *capa[],
int *argc, char ***argv)
{
FILE *fp;
char *linebuf = NULL;
char *buf = NULL;
size_t n = 0;
int x_argc = *argc;
char **x_argv = *argv;
char* rcfile = mu_tilde_expansion (name, "/", NULL);
if (!rcfile)
return;
fp = fopen (rcfile, "r");
if (!fp)
{
free (rcfile);
return;
}
if (rf == mu_config_auto)
mu_error (_("Notice: reading options from `%s'"), rcfile);
while (getline (&buf, &n, fp) > 0)
{
char *kwp, *p;
int len;
for (kwp = buf; *kwp && isspace (*kwp); kwp++)
;
if (*kwp == '#' || *kwp == 0)
continue;
len = strlen (kwp);
if (kwp[len-1] == '\n')
kwp[--len] = 0;
if (kwp[len-1] == '\\' || linebuf)
{
int cont;
if (kwp[len-1] == '\\')
{
kwp[--len] = 0;
cont = 1;
}
else
cont = 0;
if (!linebuf)
linebuf = calloc (len + 1, 1);
else
linebuf = realloc (linebuf, strlen (linebuf) + len + 1);
if (!linebuf)
{
fprintf (stderr, _("%s: not enough memory\n"), progname);
exit (1);
}
strcpy (linebuf + strlen (linebuf), kwp);
if (cont)
continue;
kwp = linebuf;
}
len = 0;
if (progname)
{
for (p = kwp; *p && !isspace (*p); p++)
len++;
}
else
p = kwp; /* Use the whole line. */
if (progname == NULL
|| (kwp[0] == ':' && member (capa, kwp+1, len-1))
|| strncmp (progname, kwp, len) == 0)
{
int i, n_argc = 0;
char **n_argv;
if (mu_argcv_get (p, "", NULL, &n_argc, &n_argv))
{
mu_argcv_free (n_argc, n_argv);
if (linebuf)
free (linebuf);
linebuf = NULL;
continue;
}
x_argv = realloc (x_argv, (x_argc + n_argc) * sizeof (x_argv[0]));
if (!x_argv)
{
fprintf (stderr, _("%s: not enough memory\n"), progname);
exit (1);
}
for (i = 0; i < n_argc; i++)
x_argv[x_argc++] = mu_tilde_expansion (n_argv[i], "/", NULL);
free (n_argv);
}
if (linebuf)
free (linebuf);
linebuf = NULL;
}
fclose (fp);
free (rcfile);
*argc = x_argc;
*argv = x_argv;
}
void
mu_create_argcv (const char *capa[],
const char *progname,
enum mu_config_flavor cfl[CF_SIZE],
int argc, char **argv, int *p_argc, char ***p_argv)
{
int x_argc;
char **x_argv;
int i;
int rcdir = 0;
x_argv = malloc (sizeof (x_argv[0]));
if (!x_argv)
{
fprintf (stderr, _("%s: not enough memory\n"), progname);
exit (1);
}
/* Add command name */
x_argc = 0;
x_argv[x_argc] = argv[x_argc];
x_argc++;
/* Add global config file. */
if (cfl[CF_GLOBAL] == mu_config_options || cfl[CF_GLOBAL] == mu_config_auto)
read_rc (progname, MU_CONFIG_FILE, cfl[CF_GLOBAL], capa, &x_argc, &x_argv);
if (cfl[CF_USER] == mu_config_options || cfl[CF_USER] == mu_config_auto)
{
/* Look for per-user config files in ~/.mailutils/ or in ~/, but
not both. This allows mailutils' utilities to have their config
files segregated, if necessary. */
struct stat s;
char *rcdirname = mu_tilde_expansion (MU_USER_CONFIG_FILE, "/", NULL);
if (!rcdirname
|| (stat (rcdirname, &s) == 0 && S_ISDIR (s.st_mode)))
rcdir = 1;
free (rcdirname);
/* Add per-user config file. */
if (!rcdir)
read_rc (progname, MU_USER_CONFIG_FILE, cfl[CF_USER], capa,
&x_argc, &x_argv);
else
{
char *userrc = NULL;
userrc = malloc (sizeof (MU_USER_CONFIG_FILE)
/* provides an extra slot
for null byte as well */
+ 1 /* slash */
+ 9 /* mailutils */);
if (!userrc)
{
mu_error (_("%s: not enough memory"), progname);
exit (1);
}
sprintf (userrc, "%s/mailutils", MU_USER_CONFIG_FILE);
read_rc (progname, userrc, cfl[CF_USER], capa, &x_argc, &x_argv);
free (userrc);
}
/* Add per-user, per-program config file. */
{
char *progrc = NULL;
int size;
if (rcdir)
size = sizeof (MU_USER_CONFIG_FILE)
+ 1
+ strlen (progname)
+ 2 /* rc */;
else
size = 6 /*~/.mu.*/
+ strlen (progname)
+ 3 /* "rc" + null terminator */;
progrc = malloc (size);
if (!progrc)
{
mu_error (_("%s: not enough memory"), progname);
exit (1);
}
if (rcdir)
sprintf (progrc, "%s/%src", MU_USER_CONFIG_FILE, progname);
else
sprintf (progrc, "~/.mu.%src", progname);
read_rc (NULL, progrc, cfl[CF_USER], capa, &x_argc, &x_argv);
free (progrc);
}
}
/* Finally, add the command line options */
x_argv = realloc (x_argv, (x_argc + argc) * sizeof (x_argv[0]));
for (i = 1; i < argc; i++)
x_argv[x_argc++] = argv[i];
x_argv[x_argc] = NULL;
*p_argc = x_argc;
*p_argv = x_argv;
}
/* ************************************************************************* */
static struct mu_cfg_param *prog_param;
void
mu_argp_set_config_param (struct mu_cfg_param *p)
{
prog_param = p;
}
static void
read_configs (char *progname, enum mu_config_flavor cfl[CF_SIZE])
{
size_t size;
char *file_name;
enum mu_config_flavor f;
if (cfl[CF_GLOBAL] != mu_config_none)
{
f = deduce_config_flavor (MU_CONFIG_FILE);
if (f == mu_config_resource)
{
switch (cfl[CF_GLOBAL])
{
case mu_config_auto:
case mu_config_resource:
mu_parse_config (MU_CONFIG_FILE, progname, prog_param, 1);
break;
default:
break;
}
cfl[CF_GLOBAL] = mu_config_none; /* Avoid reading the file by
read_rc */
}
else if (cfl[CF_GLOBAL] != mu_config_auto && cfl[CF_GLOBAL] != f)
cfl[CF_GLOBAL] = mu_config_none;
}
if (cfl[CF_USER] == mu_config_auto || cfl[CF_USER] == mu_config_resource)
{
size = 3 + strlen (progname) + 1;
file_name = malloc (size);
if (file_name)
{
strcpy (file_name, "~/.");
strcat (file_name, progname);
mu_parse_config (file_name, progname, prog_param, 0);
free (file_name);
}
}
}
void
mu_argp_init (const char *vers, const char *bugaddr)
{
argp_program_version = vers ? vers : PACKAGE_STRING;
argp_program_bug_address = bugaddr ? bugaddr : "<" PACKAGE_BUGREPORT ">";
}
error_t
mu_argp_parse (const struct argp *argp,
int *pargc, char **pargv[],
unsigned flags,
const char *capa[],
int *arg_index,
void *input)
{
error_t ret;
const struct argp argpnull = { 0 };
char *progname;
enum mu_config_flavor cfl[CF_SIZE];
/* Make sure we have program version and bug address initialized */
mu_argp_init (argp_program_version, argp_program_bug_address);
progname = strrchr ((*pargv)[0], '/');
if (progname)
progname++;
else
progname = (*pargv)[0];
if (strlen (progname) > 3 && memcmp (progname, "lt-", 3) == 0)
progname += 3;
get_default_config_flavor (progname, cfl);
if (!argp)
argp = &argpnull;
argp = mu_build_argp (argp, capa);
read_configs (progname, cfl);
mu_create_argcv (capa, progname, cfl, *pargc, *pargv, pargc, pargv);
ret = argp_parse (argp, *pargc, *pargv, flags, arg_index, input);
free ((void*) argp->children);
free ((void*) argp);
return ret;
}
......@@ -43,7 +43,6 @@
#include <mailutils/list.h>
#include <mailutils/iterator.h>
#include <mailutils/mailbox.h>
#include <mailutils/argp.h>
#include <mailutils/mu_auth.h>
#include <mailutils/error.h>
#include <mailutils/errno.h>
......@@ -54,9 +53,6 @@
/*#define DEBUG(c) do { printf c; printf("\n"); } while (0)*/
#define DEBUG(c)
static void mu_auth_begin_setup (void);
static void mu_auth_finish_setup (void);
/* memory allocation */
int
mu_auth_data_alloc (struct mu_auth_data **ptr,
......@@ -243,117 +239,6 @@ mu_authenticate (struct mu_auth_data *auth_data, char *pass)
/* ************************************************************************* */
/* Traditional configuration */
/* ************************************************************************* */
#define ARG_AUTHORIZATION 1
#define ARG_AUTHENTICATION 2
#define ARG_CLEAR_AUTHORIZATION 3
#define ARG_CLEAR_AUTHENTICATION 4
static error_t mu_auth_argp_parser (int key, char *arg,
struct argp_state *state);
/* Options used by programs that use extended authentication mechanisms. */
static struct argp_option mu_auth_argp_option[] = {
{ "authentication", ARG_AUTHENTICATION, N_("MODLIST"), OPTION_HIDDEN,
N_("Set the list of modules to be used for authentication"), 0 },
{ "authorization", ARG_AUTHORIZATION, N_("MODLIST"), OPTION_HIDDEN,
N_("Set list of modules to be used for authorization"), 0 },
{ "clear-authorization", ARG_CLEAR_AUTHORIZATION, NULL, OPTION_HIDDEN,
N_("Clear the list of authorization modules"), 0 },
{ "clear-authentication", ARG_CLEAR_AUTHENTICATION, NULL, OPTION_HIDDEN,
N_("Clear the list of authentication modules"), 0 },
{ NULL, 0, NULL, 0, NULL, 0 }
};
static struct argp mu_auth_argp = {
mu_auth_argp_option,
mu_auth_argp_parser,
};
static struct argp_child mu_auth_argp_child = {
&mu_auth_argp,
0,
NULL,
0
};
static error_t
mu_auth_argp_parser (int key, char *arg, struct argp_state *state)
{
switch (key)
{
case ARGP_KEY_FINI:
mu_auth_finish_setup ();
break;
/* authentication */
case ARG_AUTHORIZATION:
mu_authorization_add_module_list (arg);
break;
case ARG_AUTHENTICATION:
mu_authentication_add_module_list (arg);
break;
case ARG_CLEAR_AUTHENTICATION:
mu_authentication_clear_list ();
break;
case ARG_CLEAR_AUTHORIZATION:
mu_authorization_clear_list ();
break;
default:
return ARGP_ERR_UNKNOWN;
}
return 0;
}
/* ************************************************************************* */
/* Resource-style configuration */
/* ************************************************************************* */
static int
cb_authentication (mu_cfg_locus_t *locus, void *data, char *arg)
{
if (strcmp (arg, "clear") == 0)
mu_authentication_clear_list ();
else
mu_authentication_add_module_list (arg);/*FIXME: error reporting*/
return 0;
}
static int
cb_authorization (mu_cfg_locus_t *locus, void *data, char *arg)
{
if (strcmp (arg, "clear") == 0)
mu_authorization_clear_list ();
else
mu_authorization_add_module_list (arg);
return 0;
}
static struct mu_cfg_param mu_auth_param[] = {
{ "authentication", mu_cfg_callback, NULL, cb_authentication },
{ "authorization", mu_cfg_callback, NULL, cb_authorization },
{ NULL }
};
void
mu_auth_init ()
{
if (mu_register_capa ("auth", &mu_auth_argp_child, mu_auth_param))
{
mu_error (_("INTERNAL ERROR: cannot register argp capability auth (please report)"));
abort ();
}
}
/* ************************************************************************* */
struct _module_handler {
struct auth_stack_entry authenticate;
......@@ -368,42 +253,10 @@ mu_auth_register_module (struct mu_auth_module *mod)
{
struct _module_handler *entry;
if (mod->argp)
{
int i;
struct argp_child *cp;
if (mu_auth_argp.children)
{
struct argp_child *tmp;
for (i = 0; mu_auth_argp.children[i].argp; i++)
;
tmp = realloc ((void*) mu_auth_argp.children,
(i + 2) * sizeof(mu_auth_argp.children[0]));
mu_auth_argp.children = tmp;
}
else
{
mu_auth_argp.children = calloc (2, sizeof(mu_auth_argp.children[0]));
i = 0;
}
if (!mu_auth_argp.children)
{
mu_error ("not enough memory");
exit (1);
}
cp = (struct argp_child *) &mu_auth_argp.children[i];
cp->argp = mod->argp;
cp->flags = 0;
cp->header = NULL;
cp->group = 0; /* FIXME */
cp++;
cp->argp = NULL;
}
if (mod->cfg)
mu_config_register_plain_section (NULL, mod->name, mod->cfg);
if (mod->init)
mu_gocs_register (mod->name, mod->init);
/* FIXME: Argp? */
/* FIXME: cfg? */
if (!module_handler_list && mu_list_create (&module_handler_list))
abort ();
......
......@@ -25,17 +25,31 @@
#include <syslog.h>
#include <mailutils/error.h>
const char *mu_program_name;
void
mu_set_program_name (const char *name)
{
char *progname = strrchr (name, '/');
if (progname)
progname++;
else
progname = name;
if (strlen (progname) > 3 && memcmp (progname, "lt-", 3) == 0)
progname += 3;
mu_program_name = progname;
}
int
mu_default_error_printer (const char *fmt, va_list ap)
{
int status;
status = vfprintf (stderr, fmt, ap);
if (status >= 0)
{
if (fputc ('\n', stderr) != EOF)
status++;
}
return status;
if (mu_program_name)
fprintf (stderr, "%s: ", mu_program_name);
vfprintf (stderr, fmt, ap);
fputc ('\n', stderr);
return 0;
}
int
......
......@@ -58,6 +58,7 @@
#include <mailutils/nls.h>
#include <mailutils/stream.h>
#include <mailutils/filter.h>
#include <mailutils/sql.h>
#include <registrar0.h>
......@@ -1479,3 +1480,19 @@ mutil_parse_field_map (const char *map, mu_assoc_t *passoc_tab, int *perr)
*perr = i;
return rc;
}
/* FIXME: should it be here? */
int
mu_sql_decode_password_type (const char *arg, enum mu_password_type *t)
{
if (strcmp (arg, "plain") == 0)
*t = password_plaintext;
else if (strcmp (arg, "hash") == 0)
*t = password_hash;
else if (strcmp (arg, "scrambled") == 0)
*t = password_scrambled;
else
return 1;
return 0;
}
......
......@@ -40,7 +40,6 @@
#include <mailutils/list.h>
#include <mailutils/iterator.h>
#include <mailutils/mailbox.h>
#include <mailutils/argp.h>
#include <mailutils/mu_auth.h>
#include <mailutils/errno.h>
......@@ -138,7 +137,6 @@ mu_authenticate_system (struct mu_auth_data **return_data MU_ARG_UNUSED,
struct mu_auth_module mu_auth_system_module = {
"system",
NULL,
NULL,
mu_authenticate_system,
NULL,
mu_auth_system_by_name,
......@@ -151,7 +149,6 @@ struct mu_auth_module mu_auth_system_module = {
struct mu_auth_module mu_auth_generic_module = {
"generic",
NULL,
NULL,
mu_authenticate_generic,
NULL,
mu_auth_nosupport,
......
......@@ -24,7 +24,7 @@ SUBDIRS = testsuite
bin_PROGRAMS = messages
messages_SOURCES = messages.c
messages_LDADD =\
../lib/libmuaux.la\
${MU_APP_LIBRARIES}\
${MU_LIB_MBOX}\
${MU_LIB_IMAP}\
${MU_LIB_POP}\
......
......@@ -27,6 +27,7 @@
#endif
#include <mailutils/mailutils.h>
#include "muinit.h"
static int messages_count (const char *);
......@@ -47,9 +48,6 @@ static const char *argp_capa[] = {
"common",
"license",
"mailbox",
#ifdef WITH_TLS
"tls",
#endif
NULL
};
......@@ -72,6 +70,7 @@ parse_opt (int key, char *arg, struct argp_state *state)
case 's':
silent = 1;
break;
case ARGP_KEY_ARG:
args->argv = realloc (args->argv,
sizeof (char *) * (state->arg_num + 2));
......@@ -79,6 +78,7 @@ parse_opt (int key, char *arg, struct argp_state *state)
args->argv[state->arg_num + 1] = NULL;
args->argc++;
break;
default:
return ARGP_ERR_UNKNOWN;
}
......@@ -104,15 +104,16 @@ main (int argc, char **argv)
/* Native Language Support */
mu_init_nls ();
mu_argp_init (program_version, NULL);
#ifdef WITH_TLS
mu_tls_init_client_argp ();
#endif
mu_argp_parse (&argp, &argc, &argv, 0, argp_capa, NULL, &args);
/* register the formats. */
mu_register_all_mbox_formats ();
#ifdef WITH_TLS
mu_gocs_register ("tls", mu_tls_module_init);
#endif
mu_argp_init (program_version, NULL);
if (mu_app_init (&argp, argp_capa, NULL, argc, argv, 0, NULL, &args))
exit (1);
if (args.argc < 1 && messages_count (NULL) < 0)
err = 1;
else if (args.argc >= 1)
......
......@@ -27,6 +27,7 @@
#include <mh.h>
#include <string.h>
#include <mailutils/argcv.h>
#include "argp.h"
static error_t
parse_opt (int key, char *arg, struct argp_state *state)
......
......@@ -16,8 +16,9 @@
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
MA 02110-1301 USA */
#include <mailutils/argp.h>
#include <mailutils/nls.h>
#include "argp.h"
#include "muinit.h"
#define MH_OPT_BOOL 1
#define MH_OPT_ARG 2
......@@ -189,5 +190,6 @@ int mh_argp_parse (int *argc, char **argv[],
struct mh_option *mh_option,
char *argp_doc, char *doc,
int (*handler)(), void *closure, int *index);
void mh_help (struct mh_option *mh_option, const char *doc);
void mh_license (const char *name);
......
......@@ -54,9 +54,9 @@ ismydomain (char *p)
int
mh_alias_expand (const char *str, mu_address_t *paddr, int *incl)
{
size_t argc;
int argc;
char **argv;
size_t i;
int i;
char *buf;
mu_address_t exaddr = NULL;
......
......@@ -49,7 +49,7 @@ mimetypes-lex.c: $(srcdir)/mimetypes.l mimetypes-decl.h
BUILT_SOURCES = mimetypes-gram.c mimetypes-lex.c mimetypes-decl.h
mimeview_LDADD = \
../lib/libmuaux.la \
${MU_APP_LIBRARIES}\
${MU_LIB_MAILUTILS}\
@LTLIBINTL@
......
......@@ -25,6 +25,8 @@
#include <sys/stat.h>
#include <sys/wait.h>
#include "muinit.h"
const char *program_version = "mimeview (" PACKAGE_STRING ")";
static char doc[] = N_("GNU mimeview -- display files, using mailcap mechanism.")
"\v"
......@@ -262,8 +264,9 @@ main (int argc, char **argv)
mu_init_nls ();
mu_argp_init (program_version, NULL);
mu_argp_set_config_param (mimeview_cfg_param);
mu_argp_parse (&argp, &argc, &argv, 0, capa, &index, NULL);
if (mu_app_init (&argp, capa, mimeview_cfg_param,
argc, argv, 0, &index, NULL))
exit (1);
argc -= index;
argv += index;
......
......@@ -22,7 +22,7 @@ INCLUDES = @MU_COMMON_INCLUDES@ @MU_AUTHINCS@
bin_PROGRAMS = movemail
movemail_LDADD = \
../lib/libmuaux.la\
${MU_APP_LIBRARIES}\
${MU_LIB_MBOX}\
${MU_LIB_IMAP}\
${MU_LIB_POP}\
......
......@@ -25,6 +25,7 @@
#include <mailutils/mailutils.h>
#include <mailutils/tls.h>
#include <mu_asprintf.h>
#include "muinit.h"
const char *program_version = "movemail (" PACKAGE_STRING ")";
static char doc[] = N_("GNU movemail");
......@@ -85,13 +86,10 @@ struct mu_cfg_param movemail_cfg_param[] = {
};
static const char *mail_capa[] = {
static const char *movemail_capa[] = {
"common",
"license",
"mailbox",
#ifdef WITH_TLS
"tls",
#endif
NULL
};
......@@ -292,12 +290,13 @@ main (int argc, char **argv)
mu_error_set_print (movemail_error_printer);
mu_argp_init (program_version, NULL);
#ifdef WITH_TLS
mu_tls_init_client_argp ();
mu_gocs_register ("tls", mu_tls_module_init);
#endif
mu_argp_set_config_param (movemail_cfg_param);
mu_argp_parse (&argp, &argc, &argv, 0, mail_capa, &index, NULL);
mu_argp_init (program_version, NULL);
if (mu_app_init (&argp, movemail_capa, movemail_cfg_param,
argc, argv, 0, NULL, NULL))
exit (1);
argc -= index;
argv += index;
......
......@@ -29,6 +29,25 @@ imap4d/signal.c
imap4d/util.c
lib/mailcap.c
lib/xmalloc.c
libargp/mu_argp.c
libargp/auth.c
libargp/cmdline.c
libargp/common.c
libargp/gsasl.c
libargp/pam.c
libargp/radius.c
libargp/sql.c
libargp/tls.c
libargp/virtdomain.c
libcfg/auth.c
libcfg/common.c
libcfg/gsasl.c
libcfg/init.c
libcfg/pam.c
libcfg/radius.c
libcfg/sql.c
libcfg/tls.c
libcfg/virtdomain.c
libproto/imap/folder.c
libproto/mbox/mbox.c
libsieve/actions.c
......@@ -82,7 +101,6 @@ mailbox/file_stream.c
mailbox/filter_iconv.c
mailbox/getopt.c
mailbox/message.c
mailbox/mu_argp.c
mailbox/mu_auth.c
mailbox/mutil.c
messages/messages.c
......
......@@ -50,7 +50,7 @@ pop3d_SOURCES =\
user.c
pop3d_LDADD = \
../lib/libmuaux.la\
${MU_APP_LIBRARIES}\
${MU_LIB_MBOX}\
${MU_LIB_MH}\
${MU_LIB_MAILDIR}\
......@@ -60,7 +60,7 @@ pop3d_LDADD = \
@MU_COMMON_LIBRARIES@
popauth_SOURCES = popauth.c
popauth_LDADD = ../lib/libmuaux.la ${MU_LIB_MAILUTILS} @MU_COMMON_LIBRARIES@
popauth_LDADD = ${MU_APP_LIBRARIES} ${MU_LIB_MAILUTILS} @MU_COMMON_LIBRARIES@
pop3d_DEPENDENCIES = \
@MU_AUTHLIBS_DEPENDENCY@ \
../lib/libmuaux.la \
......
......@@ -18,6 +18,7 @@
MA 02110-1301 USA */
#include "pop3d.h"
#include "muinit.h"
static mu_stream_t istream, ostream;
......@@ -215,7 +216,7 @@ pop3d_outf (const char *fmt, ...)
if (!buf)
pop3d_abquit (ERR_NO_MEM);
if (daemon_param.transcript)
if (mu_gocs_daemon.transcript)
syslog (LOG_DEBUG, "sent: %s", buf);
rc = mu_stream_sequential_write (ostream, buf, strlen (buf));
......@@ -239,7 +240,7 @@ pop3d_readline (char *buffer, size_t size)
int rc;
size_t nbytes;
alarm (daemon_param.timeout);
alarm (mu_gocs_daemon.timeout);
rc = mu_stream_sequential_readline (istream, buffer, size, &nbytes);
alarm (0);
......@@ -258,7 +259,7 @@ pop3d_readline (char *buffer, size_t size)
pop3d_abquit (ERR_NO_OFILE);
}
if (daemon_param.transcript)
if (mu_gocs_daemon.transcript)
syslog (LOG_DEBUG, "recv: %s", buffer);
/* Caller should not free () this ... should we strdup() then? */
......
......@@ -18,13 +18,15 @@
MA 02110-1301 USA */
#include "pop3d.h"
#include "mailutils/pam.h"
#include "muinit.h"
mu_mailbox_t mbox;
int state;
char *username;
char *md5shared;
struct daemon_param daemon_param = {
struct mu_gocs_daemon default_gocs_daemon = {
MODE_INTERACTIVE, /* Start in interactive (inetd) mode */
20, /* Default maximum number of children */
110, /* Standard POP3 port */
......@@ -161,9 +163,6 @@ static struct argp argp = {
static const char *pop3d_argp_capa[] = {
"daemon",
"auth",
#ifdef WITH_TLS
"tls",
#endif /* WITH_TLS */
"common",
"mailbox",
"logging",
......@@ -248,26 +247,28 @@ main (int argc, char **argv)
/* Native Language Support */
mu_init_nls ();
mu_argp_init (program_version, NULL);
MU_AUTH_REGISTER_ALL_MODULES();
/* Register the desired formats. */
mu_register_local_mbox_formats ();
#ifdef WITH_TLS
mu_tls_init_argp ();
mu_gocs_register ("tls", mu_tls_module_init);
#endif /* WITH_TLS */
mu_argp_set_config_param (pop3d_cfg_param);
mu_argp_parse (&argp, &argc, &argv, 0, pop3d_argp_capa, NULL, &daemon_param);
mu_gocs_daemon = default_gocs_daemon;
mu_argp_init (program_version, NULL);
if (mu_app_init (&argp, pop3d_argp_capa, pop3d_cfg_param,
argc, argv, 0, NULL, NULL))
exit (1);
if (expire == 0)
expire_on_exit = 1;
#ifdef USE_LIBPAM
if (!pam_service)
pam_service = "gnu-pop3d";
if (!mu_pam_service)
mu_pam_service = "gnu-pop3d";
#endif
if (daemon_param.mode == MODE_INTERACTIVE && isatty (0))
if (mu_gocs_daemon.mode == MODE_INTERACTIVE && isatty (0))
{
/* If input is a tty, switch to debug mode */
debug_mode = 1;
......@@ -300,7 +301,7 @@ main (int argc, char **argv)
signal (SIGPIPE, pop3d_signal);
signal (SIGABRT, pop3d_signal);
if (daemon_param.mode == MODE_DAEMON)
if (mu_gocs_daemon.mode == MODE_DAEMON)
pop3d_daemon_init ();
else
{
......@@ -316,9 +317,9 @@ main (int argc, char **argv)
umask (S_IROTH | S_IWOTH | S_IXOTH); /* 007 */
if (daemon_param.pidfile)
if (mu_gocs_daemon.pidfile)
{
mu_daemon_create_pidfile (daemon_param.pidfile);
mu_daemon_create_pidfile (mu_gocs_daemon.pidfile);
}
/* Check TLS environment, i.e. cert and key files */
......@@ -329,8 +330,8 @@ main (int argc, char **argv)
#endif /* WITH_TLS */
/* Actually run the daemon. */
if (daemon_param.mode == MODE_DAEMON)
pop3d_daemon (daemon_param.maxchildren, daemon_param.port);
if (mu_gocs_daemon.mode == MODE_DAEMON)
pop3d_daemon (mu_gocs_daemon.maxchildren, mu_gocs_daemon.port);
/* exit (EXIT_SUCCESS) -- no way out of daemon except a signal. */
else
status = pop3d_mainloop (fileno (stdin), stdin, stdout);
......
......@@ -139,7 +139,6 @@ extern int expire_on_exit;
# include <strings.h>
#endif
#include <mailutils/argp.h>
#include <mailutils/attribute.h>
#include <mailutils/body.h>
#include <mailutils/daemon.h>
......
......@@ -19,6 +19,7 @@
#include "pop3d.h"
#include <mailutils/argcv.h>
#include <xalloc.h>
#include "muinit.h"
int db_list (char *input_name, char *output_name);
int db_make (char *input_name, char *output_name);
......@@ -201,8 +202,9 @@ main(int argc, char **argv)
mu_init_nls ();
mu_argp_init (program_version, NULL);
mu_argp_parse (&argp, &argc, &argv, 0,
popauth_argp_capa, NULL, &adata);
if (mu_app_init (&argp, popauth_argp_capa, NULL,
argc, argv, 0, NULL, &adata))
exit (1);
return (*ftab[adata.action]) (&adata);
}
......
......@@ -25,7 +25,7 @@ bin_PROGRAMS = readmsg
readmsg_SOURCES = readmsg.c msglist.c readmsg.h
readmsg_LDADD =\
../lib/libmuaux.la\
${MU_APP_LIBRARIES}\
${MU_LIB_MBOX}\
${MU_LIB_IMAP}\
${MU_LIB_POP}\
......
......@@ -23,6 +23,7 @@
#include "readmsg.h"
#include "xalloc.h"
#include "muinit.h"
#define WEEDLIST_SEPARATOR " :,"
......@@ -61,9 +62,6 @@ static struct argp argp = {
static const char *readmsg_argp_capa[] = {
"common",
"mailbox",
#ifdef WITH_TLS
"tls",
#endif
NULL
};
......@@ -276,17 +274,18 @@ main (int argc, char **argv)
/* Native Language Support */
mu_init_nls ();
mu_argp_init (program_version, NULL);
#ifdef WITH_TLS
mu_tls_init_client_argp ();
#endif
mu_argp_set_config_param (readmsg_cfg_param);
mu_argp_parse (&argp, &argc, &argv, 0, readmsg_argp_capa, &index, NULL);
/* register the formats. */
mu_register_all_mbox_formats ();
mu_register_extra_formats ();
#ifdef WITH_TLS
mu_gocs_register ("tls", mu_tls_module_init);
#endif
mu_argp_init (program_version, NULL);
if (mu_app_init (&argp, readmsg_argp_capa, readmsg_cfg_param,
argc, argv, 0, &index, NULL))
exit (1);
status = mu_mailbox_create_default (&mbox, mailbox_name);
if (status != 0)
{
......
......@@ -47,7 +47,6 @@
#include <mailutils/url.h>
#include <mailutils/nls.h>
#include <mailutils/tls.h>
#include <mailutils/argp.h>
#include <mailutils/error.h>
#include <mailutils/envelope.h>
#include <mailutils/argcv.h>
......
......@@ -23,7 +23,7 @@ SUBDIRS = testsuite
bin_PROGRAMS = sieve
sieve_SOURCES = sieve.c
sieve_LDADD =\
../lib/libmuaux.la\
${MU_APP_LIBRARIES}\
${MU_LIB_SIEVE}\
${MU_LIB_MBOX}\
${MU_LIB_IMAP}\
......
......@@ -34,7 +34,6 @@
#include <mu_asprintf.h>
#include <mailutils/argcv.h>
#include <mailutils/libsieve.h>
#include <mailutils/argp.h>
#include <mailutils/auth.h>
#include <mailutils/errno.h>
#include <mailutils/folder.h>
......@@ -46,6 +45,8 @@
#include <mailutils/nls.h>
#include <mailutils/tls.h>
#include "muinit.h"
const char *program_version = "sieve (" PACKAGE_STRING ")";
static char doc[] =
......@@ -283,10 +284,6 @@ static const char *sieve_argp_capa[] =
"license",
"logging",
"mailer",
"sieve",
#ifdef WITH_TLS
"tls",
#endif
NULL
};
......@@ -389,9 +386,10 @@ main (int argc, char *argv[])
mu_argp_init (program_version, NULL);
#ifdef WITH_TLS
mu_tls_init_client_argp ();
mu_gocs_register ("tls", mu_tls_module_init);
#endif
mu_sieve_argp_init ();
mu_gocs_register ("sieve", mu_sieve_module_init);
mu_register_all_formats ();
tickets = mu_tilde_expansion ("~/.tickets", "/", NULL);
......@@ -399,14 +397,9 @@ main (int argc, char *argv[])
debug_level = MU_DEBUG_ERROR;
log_facility = 0;
mu_argp_set_config_param (sieve_cfg_param);
rc = mu_argp_parse (&argp, &argc, &argv, ARGP_IN_ORDER, sieve_argp_capa,
0, 0);
if (rc)
return 1;
mu_register_all_formats ();
if (mu_app_init (&argp, sieve_argp_capa, sieve_cfg_param,
argc, argv, ARGP_IN_ORDER, NULL, NULL))
exit (1);
/* Sieve interpreter setup. */
rc = mu_sieve_machine_init (&mach, NULL);
......
......@@ -78,9 +78,9 @@ proc mu_init {args} {
set MU_FOLDER_DIR "$MU_DATA_DIR/folder"
if {[llength $args] == 1 && [lindex $args 0] == "-noflags"} {
set MU_TOOL_FLAGS ""
set MU_TOOL_FLAGS "--no-site-rcfile --no-user-rcfile"
} else {
set MU_TOOL_FLAGS "--mail-spool $MU_SPOOL_DIR"
set MU_TOOL_FLAGS "--mail-spool $MU_SPOOL_DIR --no-site-rcfile --no-user-rcfile"
for {set i 0} {$i < [llength $args]} {incr i} {
append MU_TOOL_FLAGS " [lindex $args $i]"
}
......