Commit dc78d43f dc78d43ff77a65e3400af0401142aca2ebb6cd1e by Sergey Poznyakoff

Convert remaining utilities (except mh) to mu_cli.

* Makefile.am: Remove libmu_argp and libmu_cfg
* configure.ac: Likewise.
* libmu_argp/: Remove.
* libmu_cfg/: Remove.
* include/mailutils/Makefile.am (pkginclude_HEADERS): Remove gocs.h,
libargp.h, libcfg.h

* frm/frm.c: Register tls auth module
* frm/from.c: Likewise.
* maidag/maidag.c: Likewise.
* mail/mail.c: Likewise.
* messages/messages.c: Likewise.
* movemail/movemail.c: Likewise.
* readmsg/readmsg.c: Likewise.
* sieve/sieve.c: Likewise.
* frm/frm.h: Remove obsolete includes

* imap4d/Makefile.am: Update.
* imap4d/imap4d.c: Use mu_cli for command line and configuration
parsing.
* imap4d/imap4d.h: Update.

* include/mailutils/gocs.h: Remove.
* libmailutils/cfg/gocs.c: Remove.
* libmailutils/cfg/Makefile.am: Remove gocs.c

* include/mailutils/cli.h (mu_cli_capa_apply): Rename to
mu_cli_capa_extend_settings
(mu_cli_setup) <inorder, prog_doc_hook>: New fields.
* include/mailutils/daemon.h: Remove obsolete includes.
* include/mailutils/gsasl.h: Likewise.
* include/mailutils/mailutils.h: Update.
* include/mailutils/mu_auth.h (mu_auth_mode): New enum
(mu_auth_module): Redo structure.
* include/mailutils/opt.h (mu_parseopt) <po_prog_doc_hook>: New field.
* include/mailutils/sql.h (mu_sql_module_config): New extern.
(mu_sql_interface_index): Change proto.
* libmailutils/auth/mu_auth.c: Rewrite.
* libmailutils/auth/system.c (mu_auth_system_module): Update structure
* libmailutils/cli/capa.c (mu_cli_capa_apply): Rename to
mu_cli_capa_extend_settings
* libmailutils/cli/cli.c: Extend settings from auth modules as well.
* libmailutils/opt/help.c (mu_program_help): Invoke po_prog_doc_hook
if defined.
* libmailutils/opt/opt.c (parseopt_init): Check the
MU_PARSEOPT_PROG_DOC_HOOK flag.
(find_long_option): Fix recognition of ambiguous options in case
of exact match.
* libmu_auth/gsasl.c: Add configuration.
* libmu_auth/ldap.c: Likewise.
* libmu_auth/pam.c: Likewise.
* libmu_auth/radius.c: Likewise.
* libmu_auth/sql.c: Likewise.
* libmu_auth/tls.c: Likewise.
* libmu_auth/virtual.c: Likewise.

* mu/Makefile.am: Update.
* mu/mu.c: Rewrite using mu_cli
* mu/mu.h: Likewise.
* mu/acl.c: Likewise.
* mu/cflags.c: Likewise.
* mu/dbm.c: Likewise.
* mu/dispatch.c: Likewise.
* mu/filter.c: Likewise.
* mu/flt2047.c: Likewise.
* mu/getans.c: Likewise.
* mu/getarg.c: Likewise.
* mu/getyn.c: Likewise.
* mu/help.c: Likewise.
* mu/imap.c: Likewise.
* mu/info.c: Likewise.
* mu/ldflags.c: Likewise.
* mu/logger.c: Likewise.
* mu/pop.c: Likewise.
* mu/query.c: Likewise.
* mu/send.c: Likewise.
* mu/shell.c: Likewise.
* mu/smtp.c: Likewise.
* mu/util.c: Likewise.
* mu/verbose.c: Likewise.
* mu/wicket.c: Likewise.

* pop3d/Makefile.am: Update.
* pop3d/pop3d.c: Convert to mu_cli interface.
* pop3d/pop3d.h: Likewise.

* sql/sql.c (mu_sql_interface_index): Change argument qualifiers.
1 parent d1339b3f
Showing 99 changed files with 1070 additions and 4844 deletions
...@@ -97,8 +97,6 @@ SUBDIRS = . \ ...@@ -97,8 +97,6 @@ SUBDIRS = . \
97 libmu_compat\ 97 libmu_compat\
98 testsuite\ 98 testsuite\
99 lib\ 99 lib\
100 libmu_argp\
101 libmu_cfg\
102 $(LIBMU_CPP_DIR)\ 100 $(LIBMU_CPP_DIR)\
103 $(GINT_DIR)\ 101 $(GINT_DIR)\
104 $(LIBMU_SCM_DIR)\ 102 $(LIBMU_SCM_DIR)\
......
...@@ -1480,9 +1480,7 @@ AC_CONFIG_FILES([ ...@@ -1480,9 +1480,7 @@ AC_CONFIG_FILES([
1480 include/mailutils/cpp/Makefile 1480 include/mailutils/cpp/Makefile
1481 lib/Makefile 1481 lib/Makefile
1482 lib/gnu/Makefile 1482 lib/gnu/Makefile
1483 libmu_argp/Makefile
1484 libmu_auth/Makefile 1483 libmu_auth/Makefile
1485 libmu_cfg/Makefile
1486 libmu_cpp/Makefile 1484 libmu_cpp/Makefile
1487 libmu_scm/Makefile 1485 libmu_scm/Makefile
1488 libmu_scm/mailutils/Makefile 1486 libmu_scm/mailutils/Makefile
......
...@@ -181,7 +181,6 @@ static char *frm_argp_capa[] = { ...@@ -181,7 +181,6 @@ static char *frm_argp_capa[] = {
181 "debug", 181 "debug",
182 "mailbox", 182 "mailbox",
183 "locking", 183 "locking",
184 "tls",
185 NULL 184 NULL
186 }; 185 };
187 186
...@@ -328,7 +327,7 @@ main (int argc, char **argv) ...@@ -328,7 +327,7 @@ main (int argc, char **argv)
328 /* register the formats. */ 327 /* register the formats. */
329 mu_register_all_mbox_formats (); 328 mu_register_all_mbox_formats ();
330 329
331 mu_cli_capa_register (&mu_cli_capa_tls); 330 mu_auth_register_module (&mu_auth_tls_module);
332 mu_cli (argc, argv, &cli, frm_argp_capa, NULL, &argc, &argv); 331 mu_cli (argc, argv, &cli, frm_argp_capa, NULL, &argc, &argv);
333 332
334 if (align && (s = util_getcols ())) 333 if (align && (s = util_getcols ()))
......
...@@ -63,6 +63,7 @@ ...@@ -63,6 +63,7 @@
63 #include <mailutils/error.h> 63 #include <mailutils/error.h>
64 #include <mailutils/util.h> 64 #include <mailutils/util.h>
65 #include <mailutils/mime.h> 65 #include <mailutils/mime.h>
66 #include <mailutils/mu_auth.h>
66 67
67 #include "mailutils/cli.h" 68 #include "mailutils/cli.h"
68 69
......
...@@ -48,7 +48,6 @@ static char *capa[] = { ...@@ -48,7 +48,6 @@ static char *capa[] = {
48 "debug", 48 "debug",
49 "mailbox", 49 "mailbox",
50 "locking", 50 "locking",
51 "tls",
52 NULL 51 NULL
53 }; 52 };
54 53
...@@ -89,7 +88,7 @@ main (int argc, char **argv) ...@@ -89,7 +88,7 @@ main (int argc, char **argv)
89 /* register the formats. */ 88 /* register the formats. */
90 mu_register_all_mbox_formats (); 89 mu_register_all_mbox_formats ();
91 90
92 mu_cli_capa_register (&mu_cli_capa_tls); 91 mu_auth_register_module (&mu_auth_tls_module);
93 mu_cli (argc, argv, &cli, capa, NULL, &argc, &argv); 92 mu_cli (argc, argv, &cli, capa, NULL, &argc, &argv);
94 93
95 if (argc > 1) 94 if (argc > 1)
......
...@@ -72,7 +72,7 @@ imap4d_SOURCES = \ ...@@ -72,7 +72,7 @@ imap4d_SOURCES = \
72 util.c 72 util.c
73 73
74 imap4d_LDADD = \ 74 imap4d_LDADD = \
75 ${MU_APP_LIBRARIES}\ 75 ${MU_APP_NEW_LIBRARIES}\
76 ${MU_LIB_MBOX}\ 76 ${MU_LIB_MBOX}\
77 ${MU_LIB_MH}\ 77 ${MU_LIB_MH}\
78 ${MU_LIB_MAILDIR}\ 78 ${MU_LIB_MAILDIR}\
......
...@@ -17,7 +17,7 @@ ...@@ -17,7 +17,7 @@
17 17
18 #include "imap4d.h" 18 #include "imap4d.h"
19 #include <mailutils/gsasl.h> 19 #include <mailutils/gsasl.h>
20 #include "mailutils/libargp.h" 20 #include "mailutils/cli.h"
21 #include "mailutils/kwd.h" 21 #include "mailutils/kwd.h"
22 #include "tcpwrap.h" 22 #include "tcpwrap.h"
23 23
...@@ -56,92 +56,78 @@ int ident_encrypt_only; ...@@ -56,92 +56,78 @@ int ident_encrypt_only;
56 int test_mode; 56 int test_mode;
57 57
58 const char *program_version = "imap4d (" PACKAGE_STRING ")"; 58 const char *program_version = "imap4d (" PACKAGE_STRING ")";
59 static char doc[] = N_("GNU imap4d -- the IMAP4D daemon.");
60
61 #define OPT_PREAUTH 259
62 #define OPT_FOREGROUND 260
63 #define OPT_TEST_MODE 261
64
65 static struct argp_option options[] = {
66 { "foreground", OPT_FOREGROUND, 0, 0, N_("remain in foreground"), 0},
67 { "inetd", 'i', 0, 0, N_("run in inetd mode"), 0},
68 { "daemon", 'd', N_("NUMBER"), OPTION_ARG_OPTIONAL,
69 N_("runs in daemon mode with a maximum of NUMBER children"), 0 },
70 { "test", OPT_TEST_MODE, 0, 0,
71 N_("run in test mode"), 0 },
72 { "preauth", OPT_PREAUTH, NULL, 0,
73 N_("start in preauth mode") },
74
75 {NULL, 0, NULL, 0, NULL, 0}
76 };
77
78 59
79 static error_t imap4d_parse_opt (int key, char *arg,
80 struct argp_state *state);
81
82 static struct argp argp = {
83 options,
84 imap4d_parse_opt,
85 NULL,
86 doc,
87 NULL,
88 NULL, NULL
89 };
90 60
91 static const char *imap4d_capa[] = { 61 static void
92 "mailutils", 62 set_foreground (struct mu_parseopt *po, struct mu_option *opt,
93 "auth", 63 char const *arg)
94 "common", 64 {
95 "debug", 65 mu_m_server_set_foreground (server, 1);
96 "mailbox", 66 }
97 "locking",
98 "logging",
99 NULL
100 };
101 67
102 static error_t 68 static void
103 imap4d_parse_opt (int key, char *arg, struct argp_state *state) 69 set_inetd_mode (struct mu_parseopt *po, struct mu_option *opt,
70 char const *arg)
104 { 71 {
105 static mu_list_t lst; 72 mu_m_server_set_mode (server, MODE_INTERACTIVE);
73 }
106 74
107 switch (key) 75 static void
108 { 76 set_daemon_mode (struct mu_parseopt *po, struct mu_option *opt,
109 case 'd': 77 char const *arg)
110 mu_argp_node_list_new (lst, "mode", "daemon"); 78 {
79 mu_m_server_set_mode (server, MODE_DAEMON);
111 if (arg) 80 if (arg)
112 mu_argp_node_list_new (lst, "max-children", arg); 81 {
113 break; 82 size_t max_children;
83 char *errmsg;
84 int rc = mu_str_to_c (arg, mu_c_size, &max_children, &errmsg);
85 if (rc)
86 {
87 mu_parseopt_error (po, _("%s: bad argument"), arg);
88 exit (po->po_exit_error);
89 }
90 mu_m_server_set_max_children (server, max_children);
91 }
92 }
114 93
115 case 'i': 94 static void
116 mu_argp_node_list_new (lst, "mode", "inetd"); 95 set_preauth (struct mu_parseopt *po, struct mu_option *opt, char const *arg)
117 break; 96 {
97 preauth_mode = preauth_stdio;
98 }
118 99
119 case OPT_FOREGROUND: 100 static struct mu_option imap4d_options[] = {
120 mu_argp_node_list_new (lst, "foreground", "yes"); 101 { "foreground", 0, NULL, MU_OPTION_DEFAULT,
121 break; 102 N_("remain in foreground"),
103 mu_c_bool, NULL, set_foreground },
104 { "inetd", 'i', NULL, MU_OPTION_DEFAULT,
105 N_("run in inetd mode"),
106 mu_c_bool, NULL, set_inetd_mode },
107 { "daemon", 'd', N_("NUMBER"), MU_OPTION_ARG_OPTIONAL,
108 N_("runs in daemon mode with a maximum of NUMBER children"),
109 mu_c_string, NULL, set_daemon_mode },
122 110
123 case OPT_PREAUTH: 111 { "test", 0, NULL, MU_OPTION_DEFAULT,
124 preauth_mode = preauth_stdio; 112 N_("run in test mode"),
125 break; 113 mu_c_bool, &test_mode },
126 114
127 case OPT_TEST_MODE: 115 { "preauth", 0, NULL, MU_OPTION_DEFAULT,
128 mu_argp_node_list_new (lst, "mode", "inetd"); 116 N_("start in preauth mode"),
129 test_mode = 1; 117 mu_c_string, NULL, set_preauth },
130 break;
131 118
132 case ARGP_KEY_INIT: 119 MU_OPTION_END
133 mu_argp_node_list_init (&lst); 120 }, *options[] = { imap4d_options, NULL };
134 break;
135 121
136 case ARGP_KEY_FINI:
137 mu_argp_node_list_finish (lst, NULL, NULL);
138 break;
139 122
140 default: 123 static char *capa[] = {
141 return ARGP_ERR_UNKNOWN; 124 "auth",
142 } 125 "debug",
143 return 0; 126 "mailbox",
144 } 127 "locking",
128 "logging",
129 NULL
130 };
145 131
146 static int 132 static int
147 cb_mode (void *data, mu_config_value_t *val) 133 cb_mode (void *data, mu_config_value_t *val)
...@@ -455,6 +441,12 @@ static struct mu_cfg_param imap4d_cfg_param[] = { ...@@ -455,6 +441,12 @@ static struct mu_cfg_param imap4d_cfg_param[] = {
455 { NULL } 441 { NULL }
456 }; 442 };
457 443
444 struct mu_cli_setup cli = {
445 options,
446 imap4d_cfg_param,
447 N_("GNU imap4d -- the IMAP4D daemon.")
448 };
449
458 int 450 int
459 mu_get_user_groups (const char *user, mu_list_t retain, mu_list_t *pgrouplist) 451 mu_get_user_groups (const char *user, mu_list_t retain, mu_list_t *pgrouplist)
460 { 452 {
...@@ -933,18 +925,10 @@ main (int argc, char **argv) ...@@ -933,18 +925,10 @@ main (int argc, char **argv)
933 mu_register_local_mbox_formats (); 925 mu_register_local_mbox_formats ();
934 926
935 imap4d_capability_init (); 927 imap4d_capability_init ();
936 #ifdef WITH_TLS
937 mu_gocs_register ("tls", mu_tls_module_init);
938 #endif /* WITH_TLS */
939 #ifdef WITH_GSASL
940 mu_gocs_register ("gsasl", mu_gsasl_module_init);
941 #endif
942 mu_tcpwrapper_cfg_init (); 928 mu_tcpwrapper_cfg_init ();
943 manlock_cfg_init (); 929 manlock_cfg_init ();
944 mu_acl_cfg_init (); 930 mu_acl_cfg_init ();
945 931
946 mu_argp_init (NULL, NULL);
947
948 mu_m_server_create (&server, program_version); 932 mu_m_server_create (&server, program_version);
949 mu_m_server_set_config_size (server, sizeof (struct imap4d_srv_config)); 933 mu_m_server_set_config_size (server, sizeof (struct imap4d_srv_config));
950 mu_m_server_set_conn (server, imap4d_connection); 934 mu_m_server_set_conn (server, imap4d_connection);
...@@ -961,9 +945,15 @@ main (int argc, char **argv) ...@@ -961,9 +945,15 @@ main (int argc, char **argv)
961 945
962 mu_log_syslog = 1; 946 mu_log_syslog = 1;
963 947
964 if (mu_app_init (&argp, imap4d_capa, imap4d_cfg_param, 948 mu_cli (argc, argv, &cli, capa, server, &argc, &argv);
965 argc, argv, 0, NULL, server)) 949 if (argc)
966 exit (EX_CONFIG); /* FIXME: No way to discern from EX_USAGE? */ 950 {
951 mu_error (_("too many arguments"));
952 exit (EX_USAGE);
953 }
954
955 if (test_mode)
956 mu_m_server_set_mode (server, MODE_INTERACTIVE);
967 957
968 if (login_disabled) 958 if (login_disabled)
969 imap4d_capability_add (IMAP_CAPA_LOGINDISABLED); 959 imap4d_capability_add (IMAP_CAPA_LOGINDISABLED);
......
...@@ -106,6 +106,7 @@ ...@@ -106,6 +106,7 @@
106 #include <mailutils/imapio.h> 106 #include <mailutils/imapio.h>
107 #include <mailutils/imaputil.h> 107 #include <mailutils/imaputil.h>
108 #include <mailutils/msgset.h> 108 #include <mailutils/msgset.h>
109 #include <mailutils/syslog.h>
109 110
110 #include <mu_umaxtostr.h> 111 #include <mu_umaxtostr.h>
111 #include <muaux.h> 112 #include <muaux.h>
......
...@@ -48,7 +48,6 @@ pkginclude_HEADERS = \ ...@@ -48,7 +48,6 @@ pkginclude_HEADERS = \
48 error.h\ 48 error.h\
49 filter.h\ 49 filter.h\
50 folder.h\ 50 folder.h\
51 gocs.h\
52 gsasl.h\ 51 gsasl.h\
53 guile.h\ 52 guile.h\
54 header.h\ 53 header.h\
...@@ -59,8 +58,6 @@ pkginclude_HEADERS = \ ...@@ -59,8 +58,6 @@ pkginclude_HEADERS = \
59 iterator.h\ 58 iterator.h\
60 kwd.h\ 59 kwd.h\
61 ldap.h\ 60 ldap.h\
62 libargp.h\
63 libcfg.h\
64 list.h\ 61 list.h\
65 locker.h\ 62 locker.h\
66 log.h\ 63 log.h\
......
...@@ -35,7 +35,8 @@ struct mu_cli_capa ...@@ -35,7 +35,8 @@ struct mu_cli_capa
35 35
36 void mu_cli_capa_init (void); 36 void mu_cli_capa_init (void);
37 void mu_cli_capa_register (struct mu_cli_capa *capa); 37 void mu_cli_capa_register (struct mu_cli_capa *capa);
38 void mu_cli_capa_apply (char const *name, mu_list_t opts, mu_list_t commits); 38 void mu_cli_capa_extend_settings (char const *name, mu_list_t opts,
39 mu_list_t commits);
39 40
40 struct mu_cli_setup 41 struct mu_cli_setup
41 { 42 {
...@@ -49,6 +50,8 @@ struct mu_cli_setup ...@@ -49,6 +50,8 @@ struct mu_cli_setup
49 int ex_usage; /* If not 0, exit code on usage errors */ 50 int ex_usage; /* If not 0, exit code on usage errors */
50 int ex_config; /* If not 0, exit code on configuration 51 int ex_config; /* If not 0, exit code on configuration
51 errors */ 52 errors */
53 int inorder;
54 void (*prog_doc_hook) (mu_stream_t);
52 }; 55 };
53 56
54 void mu_version_func (struct mu_parseopt *po, mu_stream_t stream); 57 void mu_version_func (struct mu_parseopt *po, mu_stream_t stream);
......
...@@ -20,7 +20,6 @@ ...@@ -20,7 +20,6 @@
20 #define _MAILUTILS_DAEMON_H 20 #define _MAILUTILS_DAEMON_H
21 21
22 #include <mailutils/types.h> 22 #include <mailutils/types.h>
23 #include <mailutils/gocs.h>
24 23
25 #ifdef __cplusplus 24 #ifdef __cplusplus
26 extern "C" { 25 extern "C" {
...@@ -33,8 +32,6 @@ extern "C" { ...@@ -33,8 +32,6 @@ extern "C" {
33 extern int mu_daemon_create_pidfile (const char *); 32 extern int mu_daemon_create_pidfile (const char *);
34 extern void mu_daemon_remove_pidfile (void); 33 extern void mu_daemon_remove_pidfile (void);
35 34
36 extern struct mu_gocs_daemon mu_gocs_daemon;
37
38 #ifdef __cplusplus 35 #ifdef __cplusplus
39 } 36 }
40 #endif 37 #endif
......
1 /* GNU Mailutils -- a suite of utilities for electronic mail
2 Copyright (C) 2007-2008, 2010-2012, 2014-2016 Free Software
3 Foundation, Inc.
4
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 3 of the License, or (at your option) any later version.
9
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General
16 Public License along with this library. If not, see
17 <http://www.gnu.org/licenses/>. */
18
19 #ifndef _MAILUTILS_GOCS_H
20 #define _MAILUTILS_GOCS_H
21
22 #include <mailutils/types.h>
23 #include <mailutils/list.h>
24 #include <mailutils/syslog.h>
25
26 #ifdef __cplusplus
27 extern "C" {
28 #endif
29
30 struct mu_gocs_debug
31 {
32 char *string;
33 int line_info;
34 };
35
36 struct mu_gocs_mailbox
37 {
38 char *mail_spool;
39 char *mailbox_pattern;
40 char *mailbox_type;
41 };
42
43 struct mu_gocs_locking
44 {
45 char *lock_flags;
46 unsigned long lock_retry_timeout;
47 unsigned long lock_retry_count;
48 unsigned long lock_expire_timeout;
49 char *external_locker;
50 };
51
52 struct mu_gocs_source_email
53 {
54 char *address;
55 char *domain;
56 };
57
58 struct mu_gocs_mailer
59 {
60 char *mailer;
61 };
62
63 struct mu_gocs_pam
64 {
65 char *service;
66 };
67
68 struct mu_gocs_virtual
69 {
70 char *pwddir;
71 };
72
73 /* Auxiliary variables for use by libargp/libcfg */
74 extern char *mu_site_rcfile;
75 extern int mu_load_user_rcfile;
76 extern int mu_load_site_rcfile;
77 extern char *mu_load_rcfile;
78
79 typedef int (*mu_gocs_init_fp) (enum mu_gocs_op op, void *data);
80
81 void mu_gocs_register (const char *capa, mu_gocs_init_fp init);
82 void mu_gocs_register_std (const char *name);
83 void mu_gocs_store (char *capa, void *data);
84 void mu_gocs_flush (void);
85 int mu_gocs_enumerate (mu_list_action_t action, void *data);
86
87 int mu_gocs_mailbox_init (enum mu_gocs_op, void *data);
88 int mu_gocs_locking_init (enum mu_gocs_op, void *data);
89 int mu_gocs_source_email_init (enum mu_gocs_op, void *data);
90 int mu_gocs_mailer_init (enum mu_gocs_op, void *data);
91 int mu_gocs_logging_init (enum mu_gocs_op, void *data);
92 int mu_gocs_debug_init (enum mu_gocs_op, void *data);
93
94 #ifdef __cplusplus
95 }
96 #endif
97
98 #endif
...@@ -18,6 +18,7 @@ ...@@ -18,6 +18,7 @@
18 18
19 #ifndef _MAILUTILS_GSASL_H 19 #ifndef _MAILUTILS_GSASL_H
20 #define _MAILUTILS_GSASL_H 20 #define _MAILUTILS_GSASL_H
21 #include <mailutils/cli.h>
21 22
22 struct mu_gsasl_module_data 23 struct mu_gsasl_module_data
23 { 24 {
...@@ -28,16 +29,13 @@ struct mu_gsasl_module_data ...@@ -28,16 +29,13 @@ struct mu_gsasl_module_data
28 char *anon_user; 29 char *anon_user;
29 char *cram_md5_pwd; 30 char *cram_md5_pwd;
30 }; 31 };
32 extern struct mu_gsasl_module_data mu_gsasl_module_data;
31 33
32 int mu_gsasl_enabled (void); 34 int mu_gsasl_enabled (void);
33 35
34 #ifdef WITH_GSASL 36 #ifdef WITH_GSASL
35 #include <gsasl.h> 37 #include <gsasl.h>
36 38
37 int mu_gsasl_module_init (enum mu_gocs_op, void *);
38 extern struct mu_gsasl_module_data mu_gsasl_module_data;
39
40
41 int gsasl_encoder_stream (mu_stream_t *pstr, mu_stream_t transport, 39 int gsasl_encoder_stream (mu_stream_t *pstr, mu_stream_t transport,
42 Gsasl_session *ctx, int flags); 40 Gsasl_session *ctx, int flags);
43 int gsasl_decoder_stream (mu_stream_t *pstr, mu_stream_t transport, 41 int gsasl_decoder_stream (mu_stream_t *pstr, mu_stream_t transport,
......
1 /* GNU Mailutils -- a suite of utilities for electronic mail
2 Copyright (C) 1999-2001, 2004-2005, 2007-2008, 2010-2012, 2014-2016
3 Free Software Foundation, Inc.
4
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 3 of the License, or (at your option) any later version.
9
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General
16 Public License along with this library. If not, see
17 <http://www.gnu.org/licenses/>. */
18
19 #ifndef _MAILUTILS_LIBARGP_H
20 #define _MAILUTILS_LIBARGP_H
21
22 #include "mailutils/types.h"
23 #include "mailutils/gocs.h"
24 #include "mailutils/nls.h"
25 #include "mailutils/error.h"
26 #include "mailutils/errno.h"
27 #include "mailutils/version.h"
28 #include "argp.h"
29 #include "errno.h"
30 #include "strings.h"
31
32 #include "mailutils/libcfg.h"
33
34 #ifdef __cplusplus
35 extern "C" {
36 #endif
37
38 struct mu_cmdline_capa
39 {
40 char *name;
41 struct argp_child *child;
42 void (*modflags) (int *);
43 };
44
45 extern int mu_help_config_mode;
46 extern int mu_rcfile_lint;
47 extern int (*mu_app_cfg_verifier) (void);
48
49 extern struct mu_cmdline_capa mu_mailutils_cmdline;
50 extern struct mu_cmdline_capa mu_common_cmdline;
51 extern struct mu_cmdline_capa mu_logging_cmdline;
52 extern struct mu_cmdline_capa mu_mailbox_cmdline;
53 extern struct mu_cmdline_capa mu_locking_cmdline;
54 extern struct mu_cmdline_capa mu_address_cmdline;
55 extern struct mu_cmdline_capa mu_mailer_cmdline;
56 extern struct mu_cmdline_capa mu_sieve_cmdline;
57 extern struct mu_cmdline_capa mu_debug_cmdline;
58
59 extern struct mu_cmdline_capa mu_pam_cmdline;
60 extern struct mu_cmdline_capa mu_gsasl_cmdline;
61 extern struct mu_cmdline_capa mu_radius_cmdline;
62 extern struct mu_cmdline_capa mu_sql_cmdline;
63 extern struct mu_cmdline_capa mu_virtdomain_cmdline;
64
65 extern void mu_libargp_init (void);
66
67 extern struct argp *mu_argp_build (const struct argp *argp, char ***pcapa,
68 int *flags);
69 extern void mu_argp_done (struct argp *argp);
70
71 extern int mu_register_argp_capa (const char *name, struct argp_child *child,
72 void (*modflags) (int*));
73
74 void mu_argp_init (const char *vers, const char *bugaddr);
75 int mu_app_init (struct argp *myargp, const char **capa,
76 struct mu_cfg_param *cfg_param,
77 int argc, char **argv, int flags, int *pindex, void *data);
78 extern void mu_program_version_hook (FILE *stream, struct argp_state *state);
79
80 error_t mu_argp_parse (const struct argp *myargp,
81 int *pargc, char **pargv[],
82 unsigned flags,
83 const char *capa[],
84 int *arg_index,
85 void *input) MU_DEPRECATED;
86
87 void mu_argp_node_list_init (mu_list_t *);
88 void mu_argp_node_list_add (mu_list_t, mu_cfg_node_t *);
89 void mu_argp_node_list_new (mu_list_t, const char *, const char *);
90 void mu_argp_node_list_finish (mu_list_t, char *, char *);
91
92 #ifdef __cplusplus
93 }
94 #endif
95
96 #endif
97
1 /* GNU Mailutils -- a suite of utilities for electronic mail
2 Copyright (C) 2007-2012, 2014-2016 Free Software Foundation, Inc.
3
4 This library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Lesser General Public
6 License as published by the Free Software Foundation; either
7 version 3 of the License, or (at your option) any later version.
8
9 This library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Lesser General Public License for more details.
13
14 You should have received a copy of the GNU Lesser General
15 Public License along with this library. If not, see
16 <http://www.gnu.org/licenses/>. */
17
18 #ifndef _MAILUTILS_LIBCFG_H
19 #define _MAILUTILS_LIBCFG_H
20
21 #include <mailutils/cfg.h>
22 #include <mailutils/gocs.h>
23 #include <mailutils/nls.h>
24 #include <mailutils/error.h>
25 #include <mailutils/errno.h>
26
27 #ifndef MU_USER_CONFIG_FILE
28 # define MU_USER_CONFIG_FILE "~/.mailutils"
29 #endif
30
31 #ifdef __cplusplus
32 extern "C" {
33 #endif
34
35 struct mu_cfg_capa
36 {
37 char *name;
38 struct mu_cfg_param *cfgparam;
39 mu_cfg_section_fp parser;
40 };
41
42 extern int mu_libcfg_register_capa (struct mu_cfg_capa *capa);
43 extern void mu_libcfg_init (char **cnames);
44 extern int mu_parse_config_files (struct mu_cfg_param *param,
45 void *target_ptr) MU_CFG_DEPRECATED;
46 int mu_libcfg_parse_config (mu_cfg_tree_t **ptree);
47
48 extern void mu_acl_cfg_init (void);
49
50 #define __mu_common_cat2__(a,b) a ## b
51 #define __mu_common_cat3__(a,b,c) a ## b ## c
52 #define DCL_PARSER(capa) \
53 int \
54 __mu_common_cat3__(mu_,capa,_section_parser) \
55 (enum mu_cfg_section_stage stage, const mu_cfg_node_t *node, \
56 const char *section_label, void **section_data, \
57 void *call_data, mu_cfg_tree_t *tree) \
58 { \
59 switch (stage) \
60 { \
61 case mu_cfg_section_start: \
62 break; \
63 \
64 case mu_cfg_section_end: \
65 mu_gocs_store (#capa, &__mu_common_cat2__(capa, _settings)); \
66 } \
67 return 0; \
68 }
69
70 #define DCL_DEFAULT_CFG_CAPA(capa) \
71 struct mu_cfg_capa __mu_common_cat3__(mu_,capa,_cfg_capa) = { \
72 #capa, \
73 __mu_common_cat3__(mu_,capa,_param), \
74 __mu_common_cat3__(mu_,capa,_section_parser) \
75 }
76
77 #define DCL_CFG_CAPA(capa) \
78 DCL_PARSER (capa) \
79 DCL_DEFAULT_CFG_CAPA (capa)
80
81 extern struct mu_cfg_capa mu_mailbox_cfg_capa;
82 extern struct mu_cfg_capa mu_locking_cfg_capa;
83 extern struct mu_cfg_capa mu_address_cfg_capa;
84 extern struct mu_cfg_capa mu_mailer_cfg_capa;
85 extern struct mu_cfg_capa mu_logging_cfg_capa;
86 extern struct mu_cfg_capa mu_debug_cfg_capa;
87 extern struct mu_cfg_capa mu_gsasl_cfg_capa;
88 extern struct mu_cfg_capa mu_pam_cfg_capa;
89 extern struct mu_cfg_capa mu_radius_cfg_capa;
90 extern struct mu_cfg_capa mu_sql_cfg_capa;
91 extern struct mu_cfg_capa mu_tls_cfg_capa;
92 extern struct mu_cfg_capa mu_virtdomain_cfg_capa;
93 extern struct mu_cfg_capa mu_sieve_cfg_capa;
94 extern struct mu_cfg_capa mu_auth_cfg_capa;
95 extern struct mu_cfg_capa mu_ldap_cfg_capa;
96
97 #ifdef __cplusplus
98 }
99 #endif
100
101 #endif
...@@ -58,7 +58,6 @@ ...@@ -58,7 +58,6 @@
58 #include <mailutils/stream.h> 58 #include <mailutils/stream.h>
59 #include <mailutils/tls.h> 59 #include <mailutils/tls.h>
60 #include <mailutils/url.h> 60 #include <mailutils/url.h>
61 #include <mailutils/gocs.h>
62 #include <mailutils/version.h> 61 #include <mailutils/version.h>
63 #include <mailutils/io.h> 62 #include <mailutils/io.h>
64 #include <mailutils/secret.h> 63 #include <mailutils/secret.h>
...@@ -66,6 +65,7 @@ ...@@ -66,6 +65,7 @@
66 #include <mailutils/cstr.h> 65 #include <mailutils/cstr.h>
67 #include <mailutils/wordsplit.h> 66 #include <mailutils/wordsplit.h>
68 #include <mailutils/log.h> 67 #include <mailutils/log.h>
68 #include <mailutils/syslog.h>
69 #include <mailutils/stdstream.h> 69 #include <mailutils/stdstream.h>
70 #include <mailutils/prog.h> 70 #include <mailutils/prog.h>
71 #include <mailutils/sockaddr.h> 71 #include <mailutils/sockaddr.h>
......
...@@ -20,8 +20,8 @@ ...@@ -20,8 +20,8 @@
20 #define _MAILUTILS_MU_AUTH_H 20 #define _MAILUTILS_MU_AUTH_H
21 21
22 #include <mailutils/types.h> 22 #include <mailutils/types.h>
23 #include <mailutils/gocs.h>
24 #include <mailutils/debug.h> 23 #include <mailutils/debug.h>
24 #include <mailutils/cli.h>
25 25
26 #define MU_AUTH_NAME "name" 26 #define MU_AUTH_NAME "name"
27 #define MU_AUTH_PASSWD "passwd" 27 #define MU_AUTH_PASSWD "passwd"
...@@ -64,30 +64,41 @@ typedef int (*mu_auth_fp) (struct mu_auth_data **data, ...@@ -64,30 +64,41 @@ typedef int (*mu_auth_fp) (struct mu_auth_data **data,
64 void *func_data, 64 void *func_data,
65 void *call_data); 65 void *call_data);
66 66
67 enum mu_auth_mode
68 {
69 mu_auth_authenticate,
70 mu_auth_getpwnam,
71 mu_auth_getpwuid
72 };
73
74 #define MU_AUTH_MODE_COUNT 3
75
67 struct mu_auth_module 76 struct mu_auth_module
68 { 77 {
69 char *name; 78 char *name;
70 mu_gocs_init_fp init; 79 mu_auth_fp handler[MU_AUTH_MODE_COUNT];
71 mu_auth_fp authenticate; 80 void *data[MU_AUTH_MODE_COUNT];
72 void *authenticate_data; 81
73 mu_auth_fp auth_by_name; 82 struct mu_option *opt;
74 void *auth_by_name_data; 83 struct mu_cfg_param *cfg;
75 mu_auth_fp auth_by_uid; 84 mu_cfg_section_fp parser;
76 void *auth_by_uid_data; 85 mu_cli_capa_commit_fp commit;
77 }; 86 };
78 87
79 enum mu_auth_key_type 88 enum mu_auth_key_type
80 { 89 {
81 mu_auth_key_name, 90 mu_auth_key_name = mu_auth_getpwnam,
82 mu_auth_key_uid 91 mu_auth_key_uid = mu_auth_getpwuid
83 }; 92 };
84 93
85 void mu_auth_begin_setup (void); 94 void mu_auth_begin_setup (void);
86 void mu_auth_finish_setup (void); 95 void mu_auth_finish_setup (void);
96 void mu_auth_extend_settings (mu_list_t opts, mu_list_t commits);
87 97
88 extern int mu_auth_runlist (mu_list_t flist, 98 int mu_auth_runlist (mu_list_t flist,
89 struct mu_auth_data **return_data, 99 enum mu_auth_mode mode,
90 const void *key, void *data); 100 const void *key, void *data,
101 struct mu_auth_data **return_data);
91 102
92 extern int mu_get_auth (struct mu_auth_data **auth, enum mu_auth_key_type type, 103 extern int mu_get_auth (struct mu_auth_data **auth, enum mu_auth_key_type type,
93 const void *key); 104 const void *key);
...@@ -116,7 +127,6 @@ extern void mu_authentication_add_module_list (const char *modlist); ...@@ -116,7 +127,6 @@ extern void mu_authentication_add_module_list (const char *modlist);
116 extern void mu_authentication_clear_list (void); 127 extern void mu_authentication_clear_list (void);
117 extern void mu_authorization_clear_list (void); 128 extern void mu_authorization_clear_list (void);
118 129
119 extern void mu_auth_init (void);
120 extern int mu_auth_data_alloc (struct mu_auth_data **ptr, 130 extern int mu_auth_data_alloc (struct mu_auth_data **ptr,
121 const char *name, 131 const char *name,
122 const char *passwd, 132 const char *passwd,
...@@ -138,6 +148,8 @@ extern struct mu_auth_module mu_auth_sql_module; ...@@ -138,6 +148,8 @@ extern struct mu_auth_module mu_auth_sql_module;
138 extern struct mu_auth_module mu_auth_virtual_module; 148 extern struct mu_auth_module mu_auth_virtual_module;
139 extern struct mu_auth_module mu_auth_radius_module; 149 extern struct mu_auth_module mu_auth_radius_module;
140 extern struct mu_auth_module mu_auth_ldap_module; 150 extern struct mu_auth_module mu_auth_ldap_module;
151 extern struct mu_auth_module mu_auth_gsasl_module;
152 extern struct mu_auth_module mu_auth_tls_module;
141 153
142 #define MU_AUTH_REGISTER_ALL_MODULES() do {\ 154 #define MU_AUTH_REGISTER_ALL_MODULES() do {\
143 mu_auth_register_module (&mu_auth_generic_module); \ 155 mu_auth_register_module (&mu_auth_generic_module); \
...@@ -147,6 +159,8 @@ extern struct mu_auth_module mu_auth_ldap_module; ...@@ -147,6 +159,8 @@ extern struct mu_auth_module mu_auth_ldap_module;
147 mu_auth_register_module (&mu_auth_virtual_module);\ 159 mu_auth_register_module (&mu_auth_virtual_module);\
148 mu_auth_register_module (&mu_auth_radius_module);\ 160 mu_auth_register_module (&mu_auth_radius_module);\
149 mu_auth_register_module (&mu_auth_ldap_module);\ 161 mu_auth_register_module (&mu_auth_ldap_module);\
162 mu_auth_register_module (&mu_auth_gsasl_module);\
163 mu_auth_register_module (&mu_auth_tls_module);\
150 } while (0) 164 } while (0)
151 165
152 #endif 166 #endif
......
...@@ -102,6 +102,7 @@ struct mu_option_cache ...@@ -102,6 +102,7 @@ struct mu_option_cache
102 #define MU_PARSEOPT_HELP_HOOK 0x00200000 102 #define MU_PARSEOPT_HELP_HOOK 0x00200000
103 #define MU_PARSEOPT_DATA 0x00400000 103 #define MU_PARSEOPT_DATA 0x00400000
104 #define MU_PARSEOPT_VERSION_HOOK 0x00800000 104 #define MU_PARSEOPT_VERSION_HOOK 0x00800000
105 #define MU_PARSEOPT_PROG_DOC_HOOK 0x01000000
105 106
106 /* Reuse mu_parseopt struct initialized previously */ 107 /* Reuse mu_parseopt struct initialized previously */
107 #define MU_PARSEOPT_REUSE 0x80000000 108 #define MU_PARSEOPT_REUSE 0x80000000
...@@ -131,6 +132,7 @@ struct mu_parseopt ...@@ -131,6 +132,7 @@ struct mu_parseopt
131 char const *po_package_url; 132 char const *po_package_url;
132 char const *po_extra_info; 133 char const *po_extra_info;
133 134
135 void (*po_prog_doc_hook) (struct mu_parseopt *po, mu_stream_t stream);
134 void (*po_help_hook) (struct mu_parseopt *po, mu_stream_t stream); 136 void (*po_help_hook) (struct mu_parseopt *po, mu_stream_t stream);
135 void (*po_version_hook) (struct mu_parseopt *po, mu_stream_t stream); 137 void (*po_version_hook) (struct mu_parseopt *po, mu_stream_t stream);
136 138
......
...@@ -28,6 +28,4 @@ struct mu_radius_module_data ...@@ -28,6 +28,4 @@ struct mu_radius_module_data
28 char *getpwuid_request; 28 char *getpwuid_request;
29 }; 29 };
30 30
31 extern int mu_radius_module_init (enum mu_gocs_op, void *data);
32
33 #endif 31 #endif
......
...@@ -272,17 +272,6 @@ int mu_sieve_disass (mu_sieve_machine_t mach); ...@@ -272,17 +272,6 @@ int mu_sieve_disass (mu_sieve_machine_t mach);
272 #define MU_SIEVE_CLEAR_INCLUDE_PATH 0x1 272 #define MU_SIEVE_CLEAR_INCLUDE_PATH 0x1
273 #define MU_SIEVE_CLEAR_LIBRARY_PATH 0x2 273 #define MU_SIEVE_CLEAR_LIBRARY_PATH 0x2
274 274
275 struct mu_gocs_sieve
276 {
277 int clearflags;
278 /* mu_list_t include_path_prefix;*/
279 mu_list_t include_path;
280 mu_list_t library_path_prefix;
281 mu_list_t library_path;
282 };
283
284 int mu_sieve_module_init (enum mu_gocs_op, void *);
285
286 extern struct mu_cli_capa mu_cli_capa_sieve; 275 extern struct mu_cli_capa mu_cli_capa_sieve;
287 276
288 #ifdef __cplusplus 277 #ifdef __cplusplus
......
...@@ -29,24 +29,6 @@ enum mu_password_type ...@@ -29,24 +29,6 @@ enum mu_password_type
29 29
30 struct mu_sql_module_config 30 struct mu_sql_module_config
31 { 31 {
32 char *interface;
33 char *getpwnam_query;
34 char *getpass_query;
35 char *getpwuid_query;
36 char *host;
37 char *user;
38 char *passwd;
39 char *db;
40 int port;
41 enum mu_password_type password_type;
42 int positional;
43 mu_assoc_t field_map;
44 };
45
46 /* FIXME: Should not be here, but needed for several other sources
47 (imap4d/auth_gsasl.c, for instance) */
48 struct mu_internal_sql_config
49 {
50 int interface; 32 int interface;
51 char *getpwnam_query; 33 char *getpwnam_query;
52 char *getpass_query; 34 char *getpass_query;
...@@ -61,7 +43,7 @@ struct mu_internal_sql_config ...@@ -61,7 +43,7 @@ struct mu_internal_sql_config
61 mu_assoc_t field_map; 43 mu_assoc_t field_map;
62 }; 44 };
63 45
64 extern struct mu_internal_sql_config mu_sql_module_config; 46 extern struct mu_sql_module_config mu_sql_module_config;
65 47
66 /* Loadable Modules Support */ 48 /* Loadable Modules Support */
67 #define __s_cat2__(a,b) a ## b 49 #define __s_cat2__(a,b) a ## b
...@@ -131,7 +113,7 @@ struct mu_sql_dispatch ...@@ -131,7 +113,7 @@ struct mu_sql_dispatch
131 }; 113 };
132 114
133 /* Public interfaces */ 115 /* Public interfaces */
134 int mu_sql_interface_index (char *name); 116 int mu_sql_interface_index (char const *name);
135 117
136 int mu_sql_connection_init (mu_sql_connection_t *conn, int interface, 118 int mu_sql_connection_init (mu_sql_connection_t *conn, int interface,
137 char *server, int port, char *login, 119 char *server, int port, char *login,
......
...@@ -42,8 +42,6 @@ struct mu_tls_module_config ...@@ -42,8 +42,6 @@ struct mu_tls_module_config
42 char *priorities; 42 char *priorities;
43 }; 43 };
44 44
45 extern int mu_tls_module_init (enum mu_gocs_op, void *);
46
47 extern int mu_tls_server_stream_create (mu_stream_t *stream, 45 extern int mu_tls_server_stream_create (mu_stream_t *stream,
48 mu_stream_t strin, mu_stream_t strout, 46 mu_stream_t strin, mu_stream_t strout,
49 int flags); 47 int flags);
......
...@@ -151,12 +151,6 @@ struct mu_locus ...@@ -151,12 +151,6 @@ struct mu_locus
151 unsigned mu_col; 151 unsigned mu_col;
152 }; 152 };
153 153
154 enum mu_gocs_op
155 {
156 mu_gocs_op_set,
157 mu_gocs_op_flush
158 };
159
160 #ifdef __cplusplus 154 #ifdef __cplusplus
161 } 155 }
162 #endif 156 #endif
......
1 /* GNU Mailutils -- a suite of utilities for electronic mail
2 Copyright (C) 2007, 2009-2012, 2014-2016 Free Software Foundation,
3 Inc.
4
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 3 of the License, or (at your option) any later version.
9
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General
16 Public License along with this library. If not, see
17 <http://www.gnu.org/licenses/>. */
18
19 #ifdef HAVE_CONFIG_H
20 # include <config.h>
21 #endif
22 #include <unistd.h>
23 #include <string.h>
24
25 char *
26 __argp_base_name (const char *arg)
27 {
28 char *p = strrchr (arg, '/');
29 return (char *)(p ? p + 1 : arg);
30 }
31
...@@ -161,23 +161,19 @@ mu_auth_data_destroy (struct mu_auth_data **pptr) ...@@ -161,23 +161,19 @@ mu_auth_data_destroy (struct mu_auth_data **pptr)
161 161
162 /* Generic functions */ 162 /* Generic functions */
163 163
164 struct auth_stack_entry { 164 static void
165 char *name; /* for diagnostics purposes */ 165 append_auth_module (mu_list_t *pflist, struct mu_auth_module *mod)
166 mu_auth_fp fun;
167 void *func_data;
168 };
169
170 void
171 mu_insert_stack_entry (mu_list_t *pflist, struct auth_stack_entry *entry)
172 { 166 {
173 if (!*pflist && mu_list_create (pflist)) 167 if (!*pflist && mu_list_create (pflist))
174 return; 168 return;
175 mu_list_append (*pflist, entry); 169 mu_list_append (*pflist, mod);
176 } 170 }
177 171
178 int 172 int
179 mu_auth_runlist (mu_list_t flist, struct mu_auth_data **return_data, 173 mu_auth_runlist (mu_list_t flist,
180 const void *key, void *data) 174 enum mu_auth_mode mode,
175 const void *key, void *data,
176 struct mu_auth_data **return_data)
181 { 177 {
182 int status = MU_ERR_AUTH_FAILURE; 178 int status = MU_ERR_AUTH_FAILURE;
183 int rc; 179 int rc;
...@@ -185,15 +181,17 @@ mu_auth_runlist (mu_list_t flist, struct mu_auth_data **return_data, ...@@ -185,15 +181,17 @@ mu_auth_runlist (mu_list_t flist, struct mu_auth_data **return_data,
185 181
186 if (mu_list_get_iterator (flist, &itr) == 0) 182 if (mu_list_get_iterator (flist, &itr) == 0)
187 { 183 {
188 struct auth_stack_entry *ep; 184 struct mu_auth_module *ep;
189 185
190 for (mu_iterator_first (itr); !mu_iterator_is_done (itr); 186 for (mu_iterator_first (itr); !mu_iterator_is_done (itr);
191 mu_iterator_next (itr)) 187 mu_iterator_next (itr))
192 { 188 {
193 mu_iterator_current (itr, (void **)&ep); 189 mu_iterator_current (itr, (void **)&ep);
190 if (!ep->handler[mode])
191 continue;
194 mu_debug (MU_DEBCAT_AUTH, MU_DEBUG_TRACE2, 192 mu_debug (MU_DEBCAT_AUTH, MU_DEBUG_TRACE2,
195 ("Trying %s...", ep->name)); 193 ("Trying %s...", ep->name));
196 rc = ep->fun (return_data, key, ep->func_data, data); 194 rc = ep->handler[mode] (return_data, key, ep->data[mode], data);
197 mu_debug (MU_DEBCAT_AUTH, MU_DEBUG_TRACE2, 195 mu_debug (MU_DEBCAT_AUTH, MU_DEBUG_TRACE2,
198 ("%s yields %d=%s", ep->name, rc, mu_strerror (rc))); 196 ("%s yields %d=%s", ep->name, rc, mu_strerror (rc)));
199 if (rc == 0) 197 if (rc == 0)
...@@ -230,30 +228,25 @@ mu_auth_nosupport (struct mu_auth_data **return_data MU_ARG_UNUSED, ...@@ -230,30 +228,25 @@ mu_auth_nosupport (struct mu_auth_data **return_data MU_ARG_UNUSED,
230 228
231 /* II. Authorization: retrieving information about user */ 229 /* II. Authorization: retrieving information about user */
232 230
233 static mu_list_t mu_auth_by_name_list, _tmp_auth_by_name_list; 231 static mu_list_t mu_getpw_modules, selected_getpw_modules;
234 static mu_list_t mu_auth_by_uid_list, _tmp_auth_by_uid_list;
235 232
236 int 233 int
237 mu_get_auth (struct mu_auth_data **auth, enum mu_auth_key_type type, 234 mu_get_auth (struct mu_auth_data **auth, enum mu_auth_key_type type,
238 const void *key) 235 const void *key)
239 { 236 {
240 mu_list_t list; 237 if (!mu_getpw_modules)
241
242 if (!mu_auth_by_name_list)
243 mu_auth_begin_setup (); 238 mu_auth_begin_setup ();
244 switch (type) 239 switch (type)
245 { 240 {
246 case mu_auth_key_name: 241 case mu_auth_key_name:
247 mu_debug (MU_DEBCAT_AUTH, MU_DEBUG_TRACE1, 242 mu_debug (MU_DEBCAT_AUTH, MU_DEBUG_TRACE1,
248 ("Getting auth info for user %s", (char*) key)); 243 ("Getting auth info for user %s", (char*) key));
249 list = mu_auth_by_name_list;
250 break; 244 break;
251 245
252 case mu_auth_key_uid: 246 case mu_auth_key_uid:
253 mu_debug (MU_DEBCAT_AUTH, MU_DEBUG_TRACE1, 247 mu_debug (MU_DEBCAT_AUTH, MU_DEBUG_TRACE1,
254 ("Getting auth info for UID %lu", 248 ("Getting auth info for UID %lu",
255 (unsigned long) *(uid_t*) key)); 249 (unsigned long) *(uid_t*) key));
256 list = mu_auth_by_uid_list;
257 break; 250 break;
258 251
259 default: 252 default:
...@@ -261,7 +254,7 @@ mu_get_auth (struct mu_auth_data **auth, enum mu_auth_key_type type, ...@@ -261,7 +254,7 @@ mu_get_auth (struct mu_auth_data **auth, enum mu_auth_key_type type,
261 ("Unknown mu_auth_key_type: %d", type)); 254 ("Unknown mu_auth_key_type: %d", type));
262 return EINVAL; 255 return EINVAL;
263 } 256 }
264 return mu_auth_runlist (list, auth, key, NULL); 257 return mu_auth_runlist (mu_getpw_modules, type, key, NULL, auth);
265 } 258 }
266 259
267 struct mu_auth_data * 260 struct mu_auth_data *
...@@ -282,7 +275,7 @@ mu_get_auth_by_uid (uid_t uid) ...@@ -282,7 +275,7 @@ mu_get_auth_by_uid (uid_t uid)
282 275
283 /* III. Authentication: determining the authenticity of a user */ 276 /* III. Authentication: determining the authenticity of a user */
284 277
285 static mu_list_t mu_authenticate_list, _tmp_authenticate_list; 278 static mu_list_t mu_auth_modules, selected_auth_modules;
286 279
287 int 280 int
288 mu_authenticate (struct mu_auth_data *auth_data, const char *pass) 281 mu_authenticate (struct mu_auth_data *auth_data, const char *pass)
...@@ -292,68 +285,52 @@ mu_authenticate (struct mu_auth_data *auth_data, const char *pass) ...@@ -292,68 +285,52 @@ mu_authenticate (struct mu_auth_data *auth_data, const char *pass)
292 mu_debug (MU_DEBCAT_AUTH, MU_DEBUG_TRACE1, 285 mu_debug (MU_DEBCAT_AUTH, MU_DEBUG_TRACE1,
293 ("mu_authenticate, user %s, source %s", 286 ("mu_authenticate, user %s, source %s",
294 auth_data->name, auth_data->source)); 287 auth_data->name, auth_data->source));
295 if (!mu_authenticate_list) 288 if (!mu_auth_modules)
296 mu_auth_begin_setup (); 289 mu_auth_begin_setup ();
297 return mu_auth_runlist (mu_authenticate_list, NULL, auth_data, (void*) pass); 290 return mu_auth_runlist (mu_auth_modules,
291 mu_auth_authenticate,
292 auth_data, pass, NULL);
298 } 293 }
299 294
300 295
301 /* ************************************************************************* */ 296 /* ************************************************************************* */
302 297
303 struct _module_handler { 298 static mu_list_t module_list;
304 struct auth_stack_entry authenticate;
305 struct auth_stack_entry auth_by_name;
306 struct auth_stack_entry auth_by_uid;
307 };
308
309 static mu_list_t module_handler_list;
310 299
311 void 300 static void
312 mu_auth_register_module (struct mu_auth_module *mod) 301 module_list_init (void)
313 { 302 {
314 struct _module_handler *entry; 303 if (!module_list)
315
316 if (mod->init)
317 mu_gocs_register (mod->name, mod->init);
318
319 if (!module_handler_list && mu_list_create (&module_handler_list))
320 abort ();
321
322 entry = malloc (sizeof (*entry));
323 if (!entry)
324 { 304 {
325 mu_error ("not enough memory"); 305 if (mu_list_create (&module_list))
326 exit (1); 306 abort ();
307 mu_list_append (module_list, &mu_auth_generic_module);
308 mu_list_append (module_list, &mu_auth_system_module);
327 } 309 }
328 entry->authenticate.name = mod->name; 310 }
329 entry->authenticate.fun = mod->authenticate;
330 entry->authenticate.func_data = mod->authenticate_data;
331 entry->auth_by_name.name = mod->name;
332 entry->auth_by_name.fun = mod->auth_by_name;
333 entry->auth_by_name.func_data = mod->auth_by_name_data;
334 entry->auth_by_uid.name = mod->name;
335 entry->auth_by_uid.fun = mod->auth_by_uid;
336 entry->auth_by_uid.func_data = mod->auth_by_uid_data;
337
338 mu_list_append (module_handler_list, entry);
339 311
312 void
313 mu_auth_register_module (struct mu_auth_module *mod)
314 {
315 module_list_init ();
316 mu_list_append (module_list, mod);
340 } 317 }
341 318
342 static struct _module_handler * 319 static struct mu_auth_module *
343 _locate (const char *name) 320 _locate (const char *name)
344 { 321 {
345 struct _module_handler *rp = NULL; 322 struct mu_auth_module *rp = NULL;
346 mu_iterator_t itr; 323 mu_iterator_t itr;
347 324
348 if (mu_list_get_iterator (module_handler_list, &itr) == 0) 325 if (mu_list_get_iterator (module_list, &itr) == 0)
349 { 326 {
350 struct _module_handler *p; 327 struct mu_auth_module *p;
351 328
352 for (mu_iterator_first (itr); !rp && !mu_iterator_is_done (itr); 329 for (mu_iterator_first (itr); !rp && !mu_iterator_is_done (itr);
353 mu_iterator_next (itr)) 330 mu_iterator_next (itr))
354 { 331 {
355 mu_iterator_current (itr, (void **)&p); 332 mu_iterator_current (itr, (void **)&p);
356 if (strcmp (p->authenticate.name, name) == 0) 333 if (strcmp (p->name, name) == 0)
357 rp = p; 334 rp = p;
358 } 335 }
359 336
...@@ -397,15 +374,14 @@ _add_module_list (const char *modlist, int (*fun)(const char *name)) ...@@ -397,15 +374,14 @@ _add_module_list (const char *modlist, int (*fun)(const char *name))
397 int 374 int
398 mu_authorization_add_module (const char *name) 375 mu_authorization_add_module (const char *name)
399 { 376 {
400 struct _module_handler *mod = _locate (name); 377 struct mu_auth_module *mod = _locate (name);
401 378
402 if (!mod) 379 if (!mod)
403 { 380 {
404 errno = MU_ERR_NOENT; 381 errno = MU_ERR_NOENT;
405 return 1; 382 return 1;
406 } 383 }
407 mu_insert_stack_entry (&_tmp_auth_by_name_list, &mod->auth_by_name); 384 append_auth_module (&selected_getpw_modules, mod);
408 mu_insert_stack_entry (&_tmp_auth_by_uid_list, &mod->auth_by_uid);
409 return 0; 385 return 0;
410 } 386 }
411 387
...@@ -418,22 +394,21 @@ mu_authorization_add_module_list (const char *modlist) ...@@ -418,22 +394,21 @@ mu_authorization_add_module_list (const char *modlist)
418 void 394 void
419 mu_authorization_clear_list () 395 mu_authorization_clear_list ()
420 { 396 {
421 mu_list_destroy (&_tmp_auth_by_name_list); 397 mu_list_destroy (&selected_getpw_modules);
422 mu_list_destroy (&_tmp_auth_by_uid_list);
423 } 398 }
424 399
425 400
426 int 401 int
427 mu_authentication_add_module (const char *name) 402 mu_authentication_add_module (const char *name)
428 { 403 {
429 struct _module_handler *mod = _locate (name); 404 struct mu_auth_module *mod = _locate (name);
430 405
431 if (!mod) 406 if (!mod)
432 { 407 {
433 errno = MU_ERR_NOENT; 408 errno = MU_ERR_NOENT;
434 return 1; 409 return 1;
435 } 410 }
436 mu_insert_stack_entry (&_tmp_authenticate_list, &mod->authenticate); 411 append_auth_module (&selected_auth_modules, mod);
437 return 0; 412 return 0;
438 } 413 }
439 414
...@@ -446,7 +421,7 @@ mu_authentication_add_module_list (const char *modlist) ...@@ -446,7 +421,7 @@ mu_authentication_add_module_list (const char *modlist)
446 void 421 void
447 mu_authentication_clear_list () 422 mu_authentication_clear_list ()
448 { 423 {
449 mu_list_destroy (&_tmp_authenticate_list); 424 mu_list_destroy (&selected_auth_modules);
450 } 425 }
451 426
452 427
...@@ -462,45 +437,39 @@ mu_authentication_clear_list () ...@@ -462,45 +437,39 @@ mu_authentication_clear_list ()
462 argp_parse() exits. */ 437 argp_parse() exits. */
463 438
464 void 439 void
465 mu_auth_begin_setup () 440 mu_auth_begin_setup (void)
466 { 441 {
467 mu_iterator_t itr; 442 mu_iterator_t itr;
468 443
469 if (!module_handler_list) 444 module_list_init ();
470 {
471 mu_auth_register_module (&mu_auth_generic_module);
472 mu_auth_register_module (&mu_auth_system_module);
473 }
474 445
475 if (!mu_authenticate_list) 446 if (!mu_auth_modules)
476 { 447 {
477 if (mu_list_get_iterator (module_handler_list, &itr) == 0) 448 if (mu_list_get_iterator (module_list, &itr) == 0)
478 { 449 {
479 struct _module_handler *mod; 450 struct mu_auth_module *mod;
480 451
481 for (mu_iterator_first (itr); !mu_iterator_is_done (itr); 452 for (mu_iterator_first (itr); !mu_iterator_is_done (itr);
482 mu_iterator_next (itr)) 453 mu_iterator_next (itr))
483 { 454 {
484 mu_iterator_current (itr, (void **)&mod); 455 mu_iterator_current (itr, (void **)&mod);
485 mu_insert_stack_entry (&mu_authenticate_list, 456 append_auth_module (&mu_auth_modules, mod);
486 &mod->authenticate);
487 } 457 }
488 mu_iterator_destroy (&itr); 458 mu_iterator_destroy (&itr);
489 } 459 }
490 } 460 }
491 461
492 if (!mu_auth_by_name_list) 462 if (!mu_getpw_modules)
493 { 463 {
494 if (mu_list_get_iterator (module_handler_list, &itr) == 0) 464 if (mu_list_get_iterator (module_list, &itr) == 0)
495 { 465 {
496 struct _module_handler *mod; 466 struct mu_auth_module *mod;
497 467
498 for (mu_iterator_first (itr); !mu_iterator_is_done (itr); 468 for (mu_iterator_first (itr); !mu_iterator_is_done (itr);
499 mu_iterator_next (itr)) 469 mu_iterator_next (itr))
500 { 470 {
501 mu_iterator_current (itr, (void **)&mod); 471 mu_iterator_current (itr, (void **)&mod);
502 mu_insert_stack_entry (&mu_auth_by_name_list, &mod->auth_by_name); 472 append_auth_module (&mu_getpw_modules, mod);
503 mu_insert_stack_entry (&mu_auth_by_uid_list, &mod->auth_by_uid);
504 } 473 }
505 mu_iterator_destroy (&itr); 474 mu_iterator_destroy (&itr);
506 } 475 }
...@@ -508,20 +477,48 @@ mu_auth_begin_setup () ...@@ -508,20 +477,48 @@ mu_auth_begin_setup ()
508 } 477 }
509 478
510 void 479 void
511 mu_auth_finish_setup () 480 mu_auth_finish_setup (void)
512 { 481 {
513 mu_list_destroy (&mu_authenticate_list); 482 mu_list_destroy (&mu_auth_modules);
514 mu_list_destroy (&mu_auth_by_name_list); 483 mu_auth_modules = selected_auth_modules;
515 mu_list_destroy (&mu_auth_by_uid_list); 484 selected_auth_modules = NULL;
516 485
517 mu_authenticate_list = _tmp_authenticate_list; 486 mu_list_destroy (&mu_getpw_modules);
518 _tmp_authenticate_list = NULL; 487 mu_getpw_modules = selected_getpw_modules;
519 mu_auth_by_name_list = _tmp_auth_by_name_list; 488 selected_getpw_modules = NULL;
520 _tmp_auth_by_name_list = NULL;
521 mu_auth_by_uid_list = _tmp_auth_by_uid_list;
522 _tmp_auth_by_uid_list = NULL;
523 489
524 mu_auth_begin_setup (); 490 mu_auth_begin_setup ();
525 } 491 }
526 492
493 struct settings
494 {
495 mu_list_t opts;
496 mu_list_t commits;
497 };
498
499 static int
500 do_extend (void *item, void *data)
501 {
502 struct mu_auth_module *mod = item;
503 struct settings *set = data;
504
505 if (mod->opt)
506 mu_list_append (set->opts, mod->opt);
507 if (mod->commit)
508 mu_list_append (set->commits, mod->commit);
509 if (mod->parser || mod->cfg)
510 mu_config_root_register_section (NULL, mod->name, NULL,
511 mod->parser, mod->cfg);
512 return 0;
513 }
514
515 void
516 mu_auth_extend_settings (mu_list_t opts, mu_list_t commits)
517 {
518 struct settings s;
519 s.opts = opts;
520 s.commits = commits;
521 mu_list_foreach (module_list, do_extend, &s);
522 }
523
527 524
......
...@@ -141,25 +141,19 @@ mu_authenticate_system (struct mu_auth_data **return_data MU_ARG_UNUSED, ...@@ -141,25 +141,19 @@ mu_authenticate_system (struct mu_auth_data **return_data MU_ARG_UNUSED,
141 141
142 142
143 struct mu_auth_module mu_auth_system_module = { 143 struct mu_auth_module mu_auth_system_module = {
144 "system", 144 .name = "system",
145 NULL, 145 .handler = {
146 mu_authenticate_system, 146 [mu_auth_authenticate] = mu_authenticate_system,
147 NULL, 147 [mu_auth_getpwnam] = mu_auth_system_by_name,
148 mu_auth_system_by_name, 148 [mu_auth_getpwuid] = mu_auth_system_by_uid
149 NULL, 149 }
150 mu_auth_system_by_uid,
151 NULL
152 }; 150 };
153 151
154 152
155 struct mu_auth_module mu_auth_generic_module = { 153 struct mu_auth_module mu_auth_generic_module = {
156 "generic", 154 .name = "generic",
157 NULL, 155 .handler = {
158 mu_authenticate_generic, 156 [mu_auth_authenticate] = mu_authenticate_generic
159 NULL, 157 }
160 mu_auth_nosupport,
161 NULL,
162 mu_auth_nosupport,
163 NULL
164 }; 158 };
165 159
......
...@@ -21,8 +21,7 @@ libcfg_la_SOURCES = \ ...@@ -21,8 +21,7 @@ libcfg_la_SOURCES = \
21 driver.c\ 21 driver.c\
22 format.c\ 22 format.c\
23 lexer.c\ 23 lexer.c\
24 parser.c\ 24 parser.c
25 gocs.c
26 25
27 localedir = $(datadir)/locale 26 localedir = $(datadir)/locale
28 AM_CPPFLAGS = \ 27 AM_CPPFLAGS = \
......
1 /* GNU Mailutils -- a suite of utilities for electronic mail
2 Copyright (C) 2007-2012, 2014-2016 Free Software Foundation, Inc.
3
4 This library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Lesser General Public
6 License as published by the Free Software Foundation; either
7 version 3 of the License, or (at your option) any later version.
8
9 This library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Lesser General Public License for more details.
13
14 You should have received a copy of the GNU Lesser General
15 Public License along with this library. If not, see
16 <http://www.gnu.org/licenses/>. */
17
18 #ifdef HAVE_CONFIG_H
19 # include <config.h>
20 #endif
21 #include <stdlib.h>
22 #include <string.h>
23 #include <mailutils/types.h>
24 #include <mailutils/gocs.h>
25 #include <mailutils/mailbox.h>
26 #include <mailutils/locker.h>
27 #include <mailutils/util.h>
28 #include <mailutils/mailer.h>
29 #include <mailutils/error.h>
30 #include <mailutils/errno.h>
31 #include <mailutils/nls.h>
32 #include <mailutils/debug.h>
33 #include <mailutils/syslog.h>
34 #include <mailutils/registrar.h>
35 #include <mailutils/stdstream.h>
36 #include <mailutils/stream.h>
37 #include <mailutils/log.h>
38 #include <syslog.h>
39
40 #ifndef MU_CONFIG_FILE
41 # define MU_CONFIG_FILE SYSCONFDIR "/mailutils.rc"
42 #endif
43
44 char *mu_site_rcfile = MU_CONFIG_FILE;
45 int mu_load_user_rcfile = 1;
46 int mu_load_site_rcfile = 1;
47 char *mu_load_rcfile = NULL;
48
49
50 int
51 mu_gocs_dummy (enum mu_gocs_op op, void *data)
52 {
53 return 0;
54 }
55
56 int
57 mu_gocs_mailbox_init (enum mu_gocs_op op, void *data)
58 {
59 int rc;
60 struct mu_gocs_mailbox *p = data;
61
62 if (op == mu_gocs_op_set && p)
63 {
64 if (p->mail_spool)
65 {
66 rc = mu_set_mail_directory (p->mail_spool);
67 if (rc)
68 mu_error (_("cannot set mail directory name to `%s': %s"),
69 p->mail_spool, mu_strerror (rc));
70 free (p->mail_spool);
71 p->mail_spool = NULL;
72 }
73 if (p->mailbox_pattern)
74 {
75 rc = mu_set_mailbox_pattern (p->mailbox_pattern);
76 if (rc)
77 mu_error (_("cannot set mailbox pattern to `%s': %s"),
78 p->mailbox_pattern, mu_strerror (rc));
79 free (p->mailbox_pattern);
80 p->mailbox_pattern = NULL;
81 }
82 if (p->mailbox_type)
83 {
84 if (mu_registrar_set_default_scheme (p->mailbox_type))
85 mu_error (_("invalid mailbox type: %s"), p->mailbox_type);
86 free (p->mailbox_type);
87 p->mailbox_type = NULL;
88 }
89 }
90 return 0;
91 }
92
93 int
94 mu_gocs_locking_init (enum mu_gocs_op op, void *data)
95 {
96 struct mu_gocs_locking *p = data;
97
98 if (!(op == mu_gocs_op_set && p))
99 return 0;
100
101 if (p->lock_flags)
102 {
103 int flags = 0;
104 char *s;
105
106 for (s = p->lock_flags; *s; s++)
107 {
108 switch (*s)
109 {
110 case 'E':
111 flags |= MU_LOCKER_EXTERNAL;
112 break;
113
114 case 'R':
115 flags |= MU_LOCKER_RETRY;
116 break;
117
118 case 'T':
119 flags |= MU_LOCKER_TIME;
120 break;
121
122 case 'P':
123 flags |= MU_LOCKER_PID;
124 break;
125
126 default:
127 mu_error (_("invalid lock flag `%c'"), *s);
128 }
129 }
130 mu_locker_set_default_flags (flags, mu_locker_assign);
131 free (p->lock_flags);
132 p->lock_flags = NULL;
133 }
134
135 if (p->lock_retry_count)
136 {
137 mu_locker_set_default_retry_count (p->lock_retry_count);
138 mu_locker_set_default_flags (MU_LOCKER_RETRY, mu_locker_set_bit);
139 p->lock_retry_count = 0;
140 }
141
142 if (p->lock_retry_timeout)
143 {
144 mu_locker_set_default_retry_timeout (p->lock_retry_timeout);
145 mu_locker_set_default_flags (MU_LOCKER_RETRY, mu_locker_set_bit);
146 p->lock_retry_timeout = 0;
147 }
148
149 if (p->lock_expire_timeout)
150 {
151 mu_locker_set_default_expire_timeout (p->lock_expire_timeout);
152 mu_locker_set_default_flags (MU_LOCKER_EXTERNAL, mu_locker_set_bit);
153 p->lock_expire_timeout = 0;
154 }
155
156 if (p->external_locker)
157 {
158 mu_locker_set_default_external_program (p->external_locker);
159 mu_locker_set_default_flags (MU_LOCKER_TIME, mu_locker_set_bit);
160 free (p->external_locker);
161 p->external_locker = NULL;
162 }
163 return 0;
164 }
165
166 int
167 mu_gocs_source_email_init (enum mu_gocs_op op, void *data)
168 {
169 struct mu_gocs_source_email *p = data;
170 int rc;
171
172 if (!(op == mu_gocs_op_set && p))
173 return 0;
174
175 if (p->address)
176 {
177 if ((rc = mu_set_user_email (p->address)) != 0)
178 mu_error (_("invalid email address `%s': %s"),
179 p->address, mu_strerror (rc));
180 free (p->address);
181 p->address = NULL;
182 }
183
184 if (p->domain)
185 {
186 if ((rc = mu_set_user_email_domain (p->domain)) != 0)
187 mu_error (_("invalid email domain `%s': %s"),
188 p->domain, mu_strerror (rc));
189
190 free (p->domain);
191 p->domain = NULL;
192 }
193 return 0;
194 }
195
196 int
197 mu_gocs_mailer_init (enum mu_gocs_op op, void *data)
198 {
199 struct mu_gocs_mailer *p = data;
200 int rc;
201
202 if (!(op == mu_gocs_op_set && p))
203 return 0;
204
205 if (p->mailer)
206 {
207 if ((rc = mu_mailer_set_url_default (p->mailer)) != 0)
208 mu_error (_("invalid mailer URL `%s': %s"),
209 p->mailer, mu_strerror (rc));
210 free (p->mailer);
211 p->mailer = NULL;
212 }
213 return 0;
214 }
215
216 int
217 mu_gocs_logging_init (enum mu_gocs_op op, void *data)
218 {
219 if (mu_log_syslog >= 0)
220 mu_stdstream_strerr_setup (mu_log_syslog ?
221 MU_STRERR_SYSLOG : MU_STRERR_STDERR);
222 return 0;
223 }
224
225 int
226 mu_gocs_debug_init (enum mu_gocs_op op, void *data)
227 {
228 if (op == mu_gocs_op_set && data)
229 {
230 struct mu_gocs_debug *p = data;
231 if (p->string)
232 mu_debug_parse_spec (p->string);
233 if (p->line_info >= 0)
234 mu_debug_line_info = p->line_info;
235 }
236 return 0;
237 }
238
239
240 struct mu_gocs_entry
241 {
242 const char *name;
243 mu_gocs_init_fp init;
244 };
245
246 #define MAX_GOCS 512
247
248 static struct mu_gocs_entry _gocs_table[MAX_GOCS];
249
250 void
251 mu_gocs_register (const char *capa, mu_gocs_init_fp init)
252 {
253 int i;
254 for (i = 0; _gocs_table[i].name; i++)
255 {
256 if (i == MAX_GOCS-1)
257 {
258 mu_error (_("gocs table overflow"));
259 abort ();
260 }
261 else if (strcmp (_gocs_table[i].name, capa) == 0)
262 return;
263 }
264 _gocs_table[i].name = capa;
265 _gocs_table[i].init = init;
266 }
267
268 int
269 mu_gocs_enumerate (mu_list_action_t action, void *data)
270 {
271 int i;
272
273 for (i = 0; _gocs_table[i].name; i++)
274 {
275 int rc = action ((void*) _gocs_table[i].name, data);
276 if (rc)
277 return rc;
278 }
279 return 0;
280 }
281
282 static mu_gocs_init_fp
283 find_init_function (struct mu_gocs_entry *tab, const char *capa)
284 {
285 for (; tab->name; tab++)
286 if (strcmp (tab->name, capa) == 0)
287 return tab->init;
288 return NULL;
289 }
290
291 static struct mu_gocs_entry std_gocs_table[] = {
292 { "mailutils", mu_gocs_dummy },
293 { "common", mu_gocs_dummy },
294 { "mailbox", mu_gocs_mailbox_init },
295 { "locking", mu_gocs_locking_init },
296 { "address", mu_gocs_source_email_init },
297 { "mailer", mu_gocs_mailer_init },
298 { "logging", mu_gocs_logging_init },
299 { "debug", mu_gocs_debug_init },
300 { "auth", mu_gocs_dummy },
301 { NULL }
302 };
303
304 void
305 mu_gocs_register_std (const char *name)
306 {
307 mu_gocs_init_fp init = find_init_function (std_gocs_table, name);
308 if (!init)
309 {
310 mu_error (_("INTERNAL ERROR at %s:%d: unknown standard capability `%s'"),
311 __FILE__, __LINE__, name);
312 abort ();
313 }
314 mu_gocs_register (name, init);
315 }
316
317
318 struct mu_gocs_data
319 {
320 char *capa;
321 void *data;
322 };
323
324 static mu_list_t /* of struct mu_gocs_data */ data_list;
325
326 static int
327 _gocs_comp (const void *a, const void *b)
328 {
329 const struct mu_gocs_data *da = a, *db = b;
330 return !(strcmp (da->capa, db->capa) == 0 && da->data == db->data);
331 }
332
333 void
334 mu_gocs_store (char *capa, void *data)
335 {
336 struct mu_gocs_data *s;
337 if (!data_list)
338 {
339 mu_list_create (&data_list);
340 mu_list_set_destroy_item (data_list, mu_list_free_item);
341 mu_list_set_comparator (data_list, _gocs_comp);
342 }
343 s = malloc (sizeof *s);
344 if (!s)
345 {
346 mu_error ("%s", mu_strerror (ENOMEM));
347 exit (1);
348 }
349 s->capa = capa;
350 s->data = data;
351 if (mu_list_locate (data_list, s, NULL) == 0)
352 free (s);
353 else
354 mu_list_prepend (data_list, s);
355 }
356
357 int
358 _gocs_flush (void *item, void *data)
359 {
360 struct mu_gocs_data *s = item;
361 mu_gocs_init_fp initfun = find_init_function (_gocs_table, s->capa);
362
363 if (!initfun)
364 {
365 mu_error (_("INTERNAL ERROR at %s:%d: unknown capability `%s'"),
366 __FILE__, __LINE__, s->capa);
367 abort ();
368 }
369
370 if (initfun (mu_gocs_op_set, s->data))
371 {
372 mu_error (_("initialization of GOCS `%s' failed"), s->capa);
373 return 1;
374 }
375
376 return 0;
377 }
378
379 void
380 mu_gocs_flush ()
381 {
382 int i;
383 mu_list_foreach (data_list, _gocs_flush, NULL);
384
385 for (i = 0; _gocs_table[i].name; i++)
386 _gocs_table[i].init (mu_gocs_op_flush, NULL);
387 }
...@@ -60,7 +60,7 @@ struct capa_apply ...@@ -60,7 +60,7 @@ struct capa_apply
60 }; 60 };
61 61
62 static int 62 static int
63 capa_apply (void *item, void *data) 63 capa_extend (void *item, void *data)
64 { 64 {
65 struct mu_cli_capa *cp = item; 65 struct mu_cli_capa *cp = item;
66 struct capa_apply *ap = data; 66 struct capa_apply *ap = data;
...@@ -80,14 +80,15 @@ capa_apply (void *item, void *data) ...@@ -80,14 +80,15 @@ capa_apply (void *item, void *data)
80 } 80 }
81 81
82 void 82 void
83 mu_cli_capa_apply (char const *name, mu_list_t opts, mu_list_t commits) 83 mu_cli_capa_extend_settings (char const *name, mu_list_t opts,
84 mu_list_t commits)
84 { 85 {
85 struct capa_apply app; 86 struct capa_apply app;
86 app.name = name; 87 app.name = name;
87 app.opts = opts; 88 app.opts = opts;
88 app.commits = commits; 89 app.commits = commits;
89 app.found = 0; 90 app.found = 0;
90 mu_list_foreach (capa_list, capa_apply, &app); 91 mu_list_foreach (capa_list, capa_extend, &app);
91 if (!app.found) 92 if (!app.found)
92 mu_error (_("INTERNAL ERROR at %s:%d: unknown standard capability `%s'"), 93 mu_error (_("INTERNAL ERROR at %s:%d: unknown standard capability `%s'"),
93 __FILE__, __LINE__, name); 94 __FILE__, __LINE__, name);
......
...@@ -31,6 +31,7 @@ ...@@ -31,6 +31,7 @@
31 #include <mailutils/stdstream.h> 31 #include <mailutils/stdstream.h>
32 #include <mailutils/io.h> 32 #include <mailutils/io.h>
33 #include <mailutils/syslog.h> 33 #include <mailutils/syslog.h>
34 #include <mailutils/mu_auth.h>
34 35
35 #ifndef MU_SITE_CONFIG_FILE 36 #ifndef MU_SITE_CONFIG_FILE
36 # define MU_SITE_CONFIG_FILE SYSCONFDIR "/mailutils.rc" 37 # define MU_SITE_CONFIG_FILE SYSCONFDIR "/mailutils.rc"
...@@ -87,6 +88,14 @@ extra_help_hook (struct mu_parseopt *po, mu_stream_t stream) ...@@ -87,6 +88,14 @@ extra_help_hook (struct mu_parseopt *po, mu_stream_t stream)
87 } 88 }
88 89
89 static void 90 static void
91 prog_doc_hook (struct mu_parseopt *po, mu_stream_t stream)
92 {
93 struct mu_cfg_parse_hints *hints = po->po_data;
94 struct mu_cli_setup *setup = hints->data;
95 setup->prog_doc_hook (stream);
96 }
97
98 static void
90 change_progname (struct mu_parseopt *po, struct mu_option *opt, 99 change_progname (struct mu_parseopt *po, struct mu_option *opt,
91 char const *arg) 100 char const *arg)
92 { 101 {
...@@ -283,6 +292,7 @@ init_options (char **capa, struct mu_cli_setup *setup, ...@@ -283,6 +292,7 @@ init_options (char **capa, struct mu_cli_setup *setup,
283 { 292 {
284 size_t i, s; 293 size_t i, s;
285 mu_list_t oplist; 294 mu_list_t oplist;
295 mu_list_t comlist;
286 struct mu_parseopt po; 296 struct mu_parseopt po;
287 297
288 mu_list_create (&oplist); 298 mu_list_create (&oplist);
...@@ -291,16 +301,16 @@ init_options (char **capa, struct mu_cli_setup *setup, ...@@ -291,16 +301,16 @@ init_options (char **capa, struct mu_cli_setup *setup,
291 for (i = 0; setup->optv[i]; i++) 301 for (i = 0; setup->optv[i]; i++)
292 mu_list_append (oplist, setup->optv[i]); 302 mu_list_append (oplist, setup->optv[i]);
293 } 303 }
304
305 mu_list_create (&comlist);
306 mu_auth_extend_settings (oplist, comlist);
294 if (capa) 307 if (capa)
295 { 308 {
296 mu_list_t comlist;
297 mu_list_create (&comlist);
298 for (i = 0; capa[i]; i++) 309 for (i = 0; capa[i]; i++)
299 mu_cli_capa_apply (capa[i], oplist, comlist); 310 mu_cli_capa_extend_settings (capa[i], oplist, comlist);
300 *ret_comlist = comlist;
301 } 311 }
302 else 312
303 *ret_comlist = NULL; 313 *ret_comlist = comlist;
304 314
305 mu_list_append (oplist, mu_common_options); 315 mu_list_append (oplist, mu_common_options);
306 mu_list_append (oplist, mu_extra_help_options); 316 mu_list_append (oplist, mu_extra_help_options);
...@@ -346,6 +356,8 @@ mu_cli (int argc, char **argv, struct mu_cli_setup *setup, char **capa, ...@@ -346,6 +356,8 @@ mu_cli (int argc, char **argv, struct mu_cli_setup *setup, char **capa,
346 setup->ex_usage = EX_USAGE; 356 setup->ex_usage = EX_USAGE;
347 if (setup->ex_config == 0) 357 if (setup->ex_config == 0)
348 setup->ex_config = EX_CONFIG; 358 setup->ex_config = EX_CONFIG;
359 if (setup->inorder)
360 flags |= MU_PARSEOPT_IN_ORDER;
349 361
350 /* Set program name */ 362 /* Set program name */
351 mu_set_program_name (argv[0]); 363 mu_set_program_name (argv[0]);
...@@ -370,6 +382,7 @@ mu_cli (int argc, char **argv, struct mu_cli_setup *setup, char **capa, ...@@ -370,6 +382,7 @@ mu_cli (int argc, char **argv, struct mu_cli_setup *setup, char **capa,
370 hints.data = setup; 382 hints.data = setup;
371 383
372 /* Initialize po */ 384 /* Initialize po */
385
373 if (setup->prog_doc) 386 if (setup->prog_doc)
374 { 387 {
375 po.po_prog_doc = setup->prog_doc; 388 po.po_prog_doc = setup->prog_doc;
...@@ -424,6 +437,12 @@ mu_cli (int argc, char **argv, struct mu_cli_setup *setup, char **capa, ...@@ -424,6 +437,12 @@ mu_cli (int argc, char **argv, struct mu_cli_setup *setup, char **capa,
424 flags |= MU_PARSEOPT_HELP_HOOK; 437 flags |= MU_PARSEOPT_HELP_HOOK;
425 } 438 }
426 439
440 if (setup->prog_doc_hook)
441 {
442 po.po_prog_doc_hook = prog_doc_hook;
443 flags |= MU_PARSEOPT_PROG_DOC_HOOK;
444 }
445
427 po.po_data = &hints; 446 po.po_data = &hints;
428 flags |= MU_PARSEOPT_DATA; 447 flags |= MU_PARSEOPT_DATA;
429 448
......
...@@ -352,6 +352,12 @@ mu_program_help (struct mu_parseopt *po, mu_stream_t outstr) ...@@ -352,6 +352,12 @@ mu_program_help (struct mu_parseopt *po, mu_stream_t outstr)
352 } 352 }
353 mu_stream_printf (str, "\n"); 353 mu_stream_printf (str, "\n");
354 354
355 if (po->po_prog_doc_hook)
356 {
357 po->po_prog_doc_hook (po, str);
358 mu_stream_printf (str, "\n");
359 }
360
355 mu_option_describe_options (str, po->po_optv, po->po_optc); 361 mu_option_describe_options (str, po->po_optv, po->po_optc);
356 362
357 if (po->po_help_hook) 363 if (po->po_help_hook)
......
...@@ -213,6 +213,8 @@ find_long_option (struct mu_parseopt *po, char const *optstr, ...@@ -213,6 +213,8 @@ find_long_option (struct mu_parseopt *po, char const *optstr,
213 case 0: 213 case 0:
214 ind = i; 214 ind = i;
215 found++; 215 found++;
216 if (optlen == strlen (po->po_optv[i]->opt_long))
217 i = po->po_optc - 1; /* exact match: break the loop */
216 break; 218 break;
217 219
218 case 1: 220 case 1:
...@@ -511,6 +513,8 @@ parseopt_init (struct mu_parseopt *po, struct mu_option **options, ...@@ -511,6 +513,8 @@ parseopt_init (struct mu_parseopt *po, struct mu_option **options,
511 po->po_exit_error = EXIT_ERROR; 513 po->po_exit_error = EXIT_ERROR;
512 if (!(flags & MU_PARSEOPT_VERSION_HOOK)) 514 if (!(flags & MU_PARSEOPT_VERSION_HOOK))
513 po->po_version_hook = NULL; 515 po->po_version_hook = NULL;
516 if (!(flags & MU_PARSEOPT_PROG_DOC_HOOK))
517 po->po_prog_doc_hook = NULL;
514 518
515 /* Count the options */ 519 /* Count the options */
516 po->po_optc = 0; 520 po->po_optc = 0;
......
1 *.la
2 *.lo
3 .deps
4 .libs
5 Makefile
6 Makefile.in
7 .gdbinit
1 # This file is part of GNU Mailutils
2 # Copyright (C) 2007, 2009-2012, 2014-2016 Free Software Foundation,
3 # Inc.
4 #
5 # GNU Mailutils is free software; you can redistribute it and/or
6 # modify it under the terms of the GNU General Public License as
7 # published by the Free Software Foundation; either version 3, or (at
8 # your option) any later version.
9 #
10 # GNU Mailutils is distributed in the hope that it will be useful, but
11 # WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 # General Public License for more details.
14 #
15 # You should have received a copy of the GNU General Public License
16 # along with GNU Mailutils. If not, see <http://www.gnu.org/licenses/>.
17
18 # This library uses gnulib calls and is always linked with gnulib, therefore
19 # we use application includes here.
20 AM_CPPFLAGS = \
21 @MU_APP_COMMON_INCLUDES@\
22 -DSYSCONFDIR=\"$(sysconfdir)\"\
23 -DSITE_VIRTUAL_PWDDIR=\"@SITE_VIRTUAL_PWDDIR@\"\
24 -DSITE_CRAM_MD5_PWD=\"@SITE_CRAM_MD5_PWD@\"
25
26 lib_LTLIBRARIES = libmu_argp.la
27
28 libmu_argp_la_SOURCES =\
29 cmdline.c\
30 cmdline.h\
31 common.c\
32 mailutils.c\
33 mu_argp.c\
34 muinit.c\
35 sieve.c
36
37 libmu_argp_la_LIBADD=../lib/libmuaux.la
38
39 libmu_argp_la_LDFLAGS=-version-info @VI_CURRENT@:@VI_REVISION@:@VI_AGE@
1 /* GNU Mailutils -- a suite of utilities for electronic mail
2 Copyright (C) 2007-2012, 2014-2016 Free Software Foundation, Inc.
3
4 This library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Lesser General Public
6 License as published by the Free Software Foundation; either
7 version 3 of the License, or (at your option) any later version.
8
9 This library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Lesser General Public License for more details.
13
14 You should have received a copy of the GNU Lesser General
15 Public License along with this library. If not, see
16 <http://www.gnu.org/licenses/>. */
17
18 #ifdef HAVE_CONFIG_H
19 # include <config.h>
20 #endif
21 #include <stdlib.h>
22 #include "cmdline.h"
23
24 static struct mu_cmdline_capa *all_cmdline_capa[] = {
25 &mu_mailutils_cmdline,
26 &mu_common_cmdline,
27 &mu_logging_cmdline,
28 &mu_mailer_cmdline,
29 &mu_debug_cmdline,
30 &mu_sieve_cmdline,
31 NULL
32 };
33
34 static int libargp_init_passed = 0;
35
36 void
37 mu_libargp_init ()
38 {
39 struct mu_cmdline_capa **cpp;
40 if (libargp_init_passed)
41 return;
42 libargp_init_passed = 1;
43 for (cpp = all_cmdline_capa; *cpp; cpp++)
44 {
45 struct mu_cmdline_capa *cp = *cpp;
46 if (mu_register_argp_capa (cp->name, cp->child, cp->modflags))
47 {
48 mu_error (_("INTERNAL ERROR: cannot register argp capability `%s'"),
49 cp->name);
50 abort ();
51 }
52 }
53 }
54
55 void
56 mu_argp_node_list_init (mu_list_t *plist)
57 {
58 int rc = mu_cfg_create_node_list (plist);
59 if (rc)
60 {
61 mu_diag_funcall (MU_DIAG_ERROR, "mu_cfg_create_node_list", NULL, rc);
62 abort ();
63 }
64 }
65
66 void
67 mu_argp_node_list_add (mu_list_t lst, mu_cfg_node_t *node)
68 {
69 int rc = mu_list_append (lst, node);
70 if (rc)
71 {
72 mu_diag_funcall (MU_DIAG_ERROR, "mu_list_append", NULL, rc);
73 abort ();
74 }
75 }
76
77 void
78 mu_argp_node_list_new (mu_list_t lst, const char *tag, const char *label)
79 {
80 mu_cfg_node_t *node;
81 size_t n;
82 struct mu_locus loc = { "command line", 0 };
83
84 mu_list_count (lst, &n);
85 loc.mu_line = n;
86 node = mu_cfg_tree_create_node (mu_argp_tree, mu_cfg_node_param,
87 &loc, tag, label, NULL);
88 mu_argp_node_list_add (lst, node);
89 }
90
91 void
92 mu_argp_node_list_finish (mu_list_t lst, char *tag, char *label)
93 {
94 if (mu_list_is_empty (lst))
95 return;
96 if (tag)
97 {
98 mu_cfg_node_t *node = mu_cfg_tree_create_node (mu_argp_tree,
99 mu_cfg_node_statement,
100 NULL,
101 tag, label,
102 lst);
103 mu_cfg_tree_add_node (mu_argp_tree, node);
104 }
105 else
106 {
107 mu_cfg_tree_add_nodelist (mu_argp_tree, lst);
108 mu_list_destroy (&lst);
109 }
110 }
111
1 /* GNU Mailutils -- a suite of utilities for electronic mail
2 Copyright (C) 2007, 2010-2012, 2014-2016 Free Software Foundation,
3 Inc.
4
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 3 of the License, or (at your option) any later version.
9
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General
16 Public License along with this library. If not, see
17 <http://www.gnu.org/licenses/>. */
18
19 #include "mailutils/libcfg.h"
20 #include "mailutils/libargp.h"
21
22 extern struct mu_cfg_tree *mu_argp_tree;
1 /* GNU Mailutils -- a suite of utilities for electronic mail
2 Copyright (C) 2007-2012, 2014-2016 Free Software Foundation, Inc.
3
4 This library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Lesser General Public
6 License as published by the Free Software Foundation; either
7 version 3 of the License, or (at your option) any later version.
8
9 This library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Lesser General Public License for more details.
13
14 You should have received a copy of the GNU Lesser General
15 Public License along with this library. If not, see
16 <http://www.gnu.org/licenses/>. */
17
18 #ifdef HAVE_CONFIG_H
19 # include <config.h>
20 #endif
21 #include "cmdline.h"
22 #include <unistd.h>
23 #include <stdlib.h>
24 #include <string.h>
25 #include <mailutils/syslog.h>
26 #include <mailutils/mailbox.h>
27
28
29 /* ************************************************************************* */
30 /* Common */
31 /* ************************************************************************* */
32
33 enum {
34 OPT_SHOW_OPTIONS=256,
35 OPT_NO_USER_RCFILE,
36 OPT_NO_SITE_RCFILE,
37 OPT_RCFILE,
38 OPT_RCFILE_LINT,
39 OPT_RCFILE_VERBOSE,
40 OPT_LOG_FACILITY,
41 OPT_LICENSE,
42 OPT_DEBUG_LEVEL,
43 OPT_LINE_INFO,
44 OPT_HELP_CONFIG,
45 OPT_SET
46 };
47
48 static struct argp_option mu_common_argp_options[] =
49 {
50 { NULL, 0, NULL, 0, N_("Common options"), 0},
51 { "show-config-options", OPT_SHOW_OPTIONS, NULL, 0,
52 N_("show compilation options"), 0 },
53 { "config-help", OPT_HELP_CONFIG, NULL, 0,
54 N_("show configuration file summary"), 0 },
55 { "no-user-config", OPT_NO_USER_RCFILE, NULL, 0,
56 N_("do not load user configuration file"), 0 },
57 { "no-user-rcfile", 0, NULL, OPTION_ALIAS, NULL },
58 { "no-site-config", OPT_NO_SITE_RCFILE, NULL, 0,
59 N_("do not load site configuration file"), 0 },
60 { "no-site-rcfile", 0, NULL, OPTION_ALIAS, NULL },
61 { "config-file", OPT_RCFILE, N_("FILE"), 0,
62 N_("load this configuration file"), 0, },
63 { "rcfile", 0, NULL, OPTION_ALIAS, NULL },
64 { "config-verbose", OPT_RCFILE_VERBOSE, NULL, 0,
65 N_("verbosely log parsing of the configuration files"), 0 },
66 { "rcfile-verbose", 0, NULL, OPTION_ALIAS, NULL },
67 { "config-lint", OPT_RCFILE_LINT, NULL, 0,
68 N_("check configuration file syntax and exit"), 0 },
69 { "rcfile-lint", 0, NULL, OPTION_ALIAS, NULL },
70 { "set", OPT_SET, N_("PARAM=VALUE"), 0,
71 N_("set configuration parameter"), 0 },
72 { NULL, 0, NULL, 0, NULL, 0 }
73 };
74
75 static void
76 set_config_param (const char *path, struct argp_state *state)
77 {
78 mu_cfg_node_t *node;
79 int rc = mu_cfg_create_subtree (path, &node);
80 if (rc)
81 argp_error (state, "cannot create node: %s", mu_strerror (rc));
82 mu_cfg_tree_add_node (mu_argp_tree, node);
83 }
84
85 static error_t
86 mu_common_argp_parser (int key, char *arg, struct argp_state *state)
87 {
88 switch (key)
89 {
90 case OPT_SHOW_OPTIONS:
91 mu_print_options ();
92 exit (0);
93
94 case OPT_NO_USER_RCFILE:
95 mu_load_user_rcfile = 0;
96 break;
97
98 case OPT_NO_SITE_RCFILE:
99 mu_load_site_rcfile = 0;
100 break;
101
102 case OPT_RCFILE:
103 mu_load_rcfile = arg;
104 break;
105
106 case OPT_RCFILE_LINT:
107 mu_cfg_parser_verbose++;
108 mu_rcfile_lint = 1;
109 break;
110
111 case OPT_RCFILE_VERBOSE:
112 mu_cfg_parser_verbose++;
113 break;
114
115 case OPT_HELP_CONFIG:
116 mu_help_config_mode = 1;
117 break;
118
119 case OPT_SET:
120 set_config_param (arg, state);
121 break;
122
123 default:
124 return ARGP_ERR_UNKNOWN;
125 }
126 return 0;
127 }
128
129 struct argp mu_common_argp = {
130 mu_common_argp_options,
131 mu_common_argp_parser,
132 };
133
134 struct argp_child mu_common_argp_child = {
135 &mu_common_argp,
136 0,
137 NULL,
138 0,
139 };
140
141 struct mu_cmdline_capa mu_common_cmdline = {
142 "common", &mu_common_argp_child
143 };
144
145
146 /* ************************************************************************* */
147 /* Logging */
148 /* ************************************************************************* */
149
150 static struct argp_option mu_logging_argp_option[] = {
151 {"log-facility", OPT_LOG_FACILITY, N_("FACILITY"), 0,
152 N_("output logs to syslog FACILITY"), 0},
153 { NULL, 0, NULL, 0, NULL, 0 }
154 };
155
156 static error_t
157 mu_logging_argp_parser (int key, char *arg, struct argp_state *state)
158 {
159 static mu_list_t lst;
160
161 switch (key)
162 {
163 /* log */
164 case OPT_LOG_FACILITY:
165 mu_argp_node_list_new (lst, "facility", arg);
166 break;
167
168 case ARGP_KEY_INIT:
169 mu_argp_node_list_init (&lst);
170 break;
171
172 case ARGP_KEY_FINI:
173 mu_argp_node_list_finish (lst, "logging", NULL);
174 break;
175
176 default:
177 return ARGP_ERR_UNKNOWN;
178 }
179 return 0;
180 }
181
182 struct argp mu_logging_argp = {
183 mu_logging_argp_option,
184 mu_logging_argp_parser,
185 };
186
187 struct argp_child mu_logging_argp_child = {
188 &mu_logging_argp,
189 0,
190 NULL,
191 0
192 };
193
194 struct mu_cmdline_capa mu_logging_cmdline = {
195 "logging", &mu_logging_argp_child
196 };
197
198
199 /* ************************************************************************* */
200 /* Mailer */
201 /* ************************************************************************* */
202
203 /* Options used by programs that send mail. */
204 static struct argp_option mu_mailer_argp_option[] = {
205 {"mailer", 'M', N_("MAILER"), 0,
206 N_("use specified URL as the default mailer"), 0},
207 { NULL, 0, NULL, 0, NULL, 0 }
208 };
209
210 static error_t
211 mu_mailer_argp_parser (int key, char *arg, struct argp_state *state)
212 {
213 static mu_list_t lst;
214
215 switch (key)
216 {
217 /* mailer */
218 case 'M':
219 mu_argp_node_list_new (lst, "url", arg);
220 break;
221
222 case ARGP_KEY_INIT:
223 mu_argp_node_list_init (&lst);
224 break;
225
226 case ARGP_KEY_FINI:
227 mu_argp_node_list_finish (lst, "mailer", NULL);
228 break;
229
230 default:
231 return ARGP_ERR_UNKNOWN;
232 }
233 return 0;
234 }
235
236 struct argp mu_mailer_argp = {
237 mu_mailer_argp_option,
238 mu_mailer_argp_parser,
239 };
240
241 struct argp_child mu_mailer_argp_child = {
242 &mu_mailer_argp,
243 0,
244 NULL,
245 0
246 };
247
248 struct mu_cmdline_capa mu_mailer_cmdline = {
249 "mailer", &mu_mailer_argp_child
250 };
251
252
253 static struct argp_option mu_debug_argp_options[] =
254 {
255 { "debug-level", OPT_DEBUG_LEVEL, N_("LEVEL"), 0,
256 N_("set Mailutils debugging level"), 0 },
257 { "debug-line-info", OPT_LINE_INFO, NULL, 0,
258 N_("show source info with debugging messages"), 0 },
259 { NULL }
260 };
261
262 static error_t
263 mu_debug_argp_parser (int key, char *arg, struct argp_state *state)
264 {
265 static mu_list_t lst;
266
267 switch (key)
268 {
269 case OPT_DEBUG_LEVEL:
270 mu_debug_parse_spec (arg);
271 /*mu_argp_node_list_new (lst, "level", arg);*/
272 break;
273
274 case OPT_LINE_INFO:
275 mu_argp_node_list_new (lst, "line-info", "yes");
276 break;
277
278 case ARGP_KEY_INIT:
279 mu_argp_node_list_init (&lst);
280 break;
281
282 case ARGP_KEY_FINI:
283 mu_argp_node_list_finish (lst, "debug", NULL);
284 break;
285
286 default:
287 return ARGP_ERR_UNKNOWN;
288 }
289 return 0;
290 }
291
292 struct argp mu_debug_argp = {
293 mu_debug_argp_options,
294 mu_debug_argp_parser,
295 };
296
297 struct argp_child mu_debug_argp_child = {
298 &mu_debug_argp,
299 0,
300 N_("Global debugging settings"),
301 0
302 };
303
304 struct mu_cmdline_capa mu_debug_cmdline = {
305 "debug", &mu_debug_argp_child
306 };
1 /* GNU Mailutils -- a suite of utilities for electronic mail
2 Copyright (C) 2007-2012, 2014-2016 Free Software Foundation, Inc.
3
4 This library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Lesser General Public
6 License as published by the Free Software Foundation; either
7 version 3 of the License, or (at your option) any later version.
8
9 This library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Lesser General Public License for more details.
13
14 You should have received a copy of the GNU Lesser General
15 Public License along with this library. If not, see
16 <http://www.gnu.org/licenses/>. */
17
18 #ifdef HAVE_CONFIG_H
19 # include <config.h>
20 #endif
21 #include "cmdline.h"
22 #include <unistd.h>
23 #include <stdlib.h>
24 /* Provide declaration of __argp_base_name: */
25 #include <argp-namefrob.h>
26
27
28 /* ************************************************************************* */
29 /* GNU Mailutils help and version output */
30 /* ************************************************************************* */
31
32 #define OPT_PROGNAME -2
33 #define OPT_USAGE -3
34 #define OPT_HANG -4
35
36 static struct argp_option mu_mailutils_argp_options[] =
37 {
38 {"help", '?', 0, 0, N_("give this help list"), -1},
39 {"usage", OPT_USAGE, 0, 0, N_("give a short usage message"), 0},
40 {"version", 'V', 0, 0, N_("print program version"), -1},
41 {"program-name",OPT_PROGNAME,N_("NAME"), OPTION_HIDDEN, N_("set the program name"), 0},
42 {"HANG", OPT_HANG, N_("SECS"), OPTION_ARG_OPTIONAL | OPTION_HIDDEN,
43 N_("hang for SECS seconds (default 3600)"), 0},
44 { NULL }
45 };
46
47 static error_t
48 mu_mailutils_argp_parser (int key, char *arg, struct argp_state *state)
49 {
50 switch (key)
51 {
52 case '?':
53 argp_state_help (state, state->out_stream,
54 ARGP_HELP_SHORT_USAGE | ARGP_HELP_LONG | ARGP_HELP_DOC);
55 /* TRANSLATORS: The placeholder indicates the bug-reporting address
56 for this package. Please add _another line_ saying
57 "Report translation bugs to <...>\n" with the address for translation
58 bugs (typically your translation team's web or email address). */
59 printf (_("\nReport bugs to: %s\n"), "<" PACKAGE_BUGREPORT ">");
60
61 #ifdef PACKAGE_PACKAGER_BUG_REPORTS
62 printf (_("Report %s bugs to: %s\n"), PACKAGE_PACKAGER,
63 PACKAGE_PACKAGER_BUG_REPORTS);
64 #endif
65
66 #ifdef PACKAGE_URL
67 printf (_("%s home page: <%s>\n"), PACKAGE_NAME, PACKAGE_URL);
68 #endif
69 fputs (_("General help using GNU software: <http://www.gnu.org/gethelp/>\n"),
70 stdout);
71 exit (0);
72
73 case OPT_USAGE:
74 argp_state_help (state, state->out_stream,
75 ARGP_HELP_USAGE | ARGP_HELP_EXIT_OK);
76 break;
77
78 case 'V':
79 if (argp_program_version_hook)
80 (*argp_program_version_hook) (state->out_stream, state);
81 else if (argp_program_version)
82 fprintf (state->out_stream, "%s\n", argp_program_version);
83 else
84 argp_error (state, "%s",
85 dgettext (state->root_argp->argp_domain,
86 "(PROGRAM ERROR) No version known!?"));
87 exit(0);
88
89 case OPT_PROGNAME: /* Set the program name. */
90 #if HAVE_DECL_PROGRAM_INVOCATION_NAME
91 program_invocation_name = arg;
92 #endif
93 /* Update what we use for messages. */
94 state->name = __argp_base_name (arg);
95
96 #if HAVE_DECL_PROGRAM_INVOCATION_SHORT_NAME
97 program_invocation_short_name = state->name;
98 #endif
99
100 if ((state->flags & (ARGP_PARSE_ARGV0 | ARGP_NO_ERRS))
101 == ARGP_PARSE_ARGV0)
102 /* Update what getopt uses too. */
103 state->argv[0] = arg;
104 break;
105
106 case OPT_HANG:
107 {
108 int hang = atoi (arg ? arg : "3600");
109 while (hang-- > 0)
110 sleep (1);
111 break;
112 }
113
114 default:
115 return ARGP_ERR_UNKNOWN;
116 }
117 return 0;
118 }
119
120 struct argp mu_mailutils_argp = {
121 mu_mailutils_argp_options,
122 mu_mailutils_argp_parser,
123 };
124
125 struct argp_child mu_mailutils_argp_child = {
126 &mu_mailutils_argp,
127 0,
128 NULL,
129 -1,
130 };
131
132 static void
133 mu_mailutils_modflags(int *flags)
134 {
135 *flags |= ARGP_NO_HELP;
136 }
137
138 struct mu_cmdline_capa mu_mailutils_cmdline = {
139 "mailutils", &mu_mailutils_argp_child, mu_mailutils_modflags
140 };
141
142
143
144
145
146
1 /* GNU Mailutils -- a suite of utilities for electronic mail
2 Copyright (C) 1999, 2001-2007, 2009-2012, 2014-2016 Free Software
3 Foundation, Inc.
4
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 3 of the License, or (at your option) any later version.
9
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General
16 Public License along with this library. If not, see
17 <http://www.gnu.org/licenses/>. */
18
19 #ifdef HAVE_CONFIG_H
20 # include <config.h>
21 #endif
22 #include <pwd.h>
23 #include <stdio.h>
24 #include <stdlib.h>
25 #include <string.h>
26 #include <syslog.h>
27 #include <unistd.h>
28
29 #include <sys/types.h>
30 #include <sys/stat.h>
31
32 #include "mailutils/libargp.h"
33
34
35 /* ************************************************************************* */
36 /* Capability array and auxiliary functions. */
37 /* ************************************************************************* */
38
39 #define MU_MAX_CAPA 24
40
41 struct argp_capa {
42 char *capability;
43 struct argp_child *child;
44 void (*modflags)(int*);
45 } mu_argp_capa[MU_MAX_CAPA] = {
46 {NULL,}
47 };
48
49 int
50 mu_register_argp_capa (const char *name, struct argp_child *child,
51 void (*modflags)(int*))
52 {
53 int i;
54
55 for (i = 0; i < MU_MAX_CAPA; i++)
56 if (mu_argp_capa[i].capability == NULL)
57 {
58 if ((mu_argp_capa[i].capability = strdup (name)) == NULL)
59 return ENOMEM;
60 mu_argp_capa[i].child = child;
61 mu_argp_capa[i].modflags = modflags;
62 return 0;
63 }
64 return 1;
65 }
66
67 static struct argp_capa *
68 find_capa (const char *name)
69 {
70 int i;
71 for (i = 0; mu_argp_capa[i].capability; i++)
72 if (strcmp (mu_argp_capa[i].capability, name) == 0)
73 return &mu_argp_capa[i];
74 return NULL;
75 }
76
77 static struct argp *
78 mu_build_argp (const struct argp *template, char **capa, int *flags)
79 {
80 int n;
81 int nchild;
82 struct argp_child *ap;
83 const struct argp_option *opt;
84 struct argp *argp;
85 int group = 0;
86
87 /* Count the capabilities. */
88 for (n = 0; capa && capa[n]; n++)
89 ;
90 if (template->children)
91 for (; template->children[n].argp; n++)
92 ;
93
94 ap = calloc (n + 1, sizeof (*ap));
95 if (!ap)
96 {
97 mu_error (_("not enough memory"));
98 abort ();
99 }
100
101 /* Copy the template's children. */
102 nchild = 0;
103 if (template->children)
104 for (n = 0; template->children[n].argp; n++, nchild++)
105 ap[nchild] = template->children[n];
106
107 /* Find next group number */
108 for (opt = template->options;
109 opt && ((opt->name && opt->key) || opt->doc); opt++)
110 if (opt->group > group)
111 group = opt->group;
112
113 group++;
114
115 /* Append any capabilities to the children or options, as appropriate. */
116 for (n = 0; capa && capa[n]; n++)
117 {
118 struct argp_capa *cp = find_capa (capa[n]);
119 if (cp)
120 {
121 if (cp->modflags)
122 cp->modflags (flags);
123 if (cp->child)
124 {
125 ap[nchild] = *cp->child;
126 if (ap[nchild].group < 0)
127 ap[nchild].group = 0;
128 else
129 ap[nchild].group = group++;
130 nchild++;
131 }
132 }
133 }
134 ap[nchild].argp = NULL;
135
136 /* Copy the template, and give it the expanded children. */
137 argp = malloc (sizeof (*argp));
138 if (!argp)
139 {
140 mu_error (_("not enough memory"));
141 abort ();
142 }
143
144 memcpy (argp, template, sizeof (*argp));
145
146 argp->children = ap;
147
148 return argp;
149 }
150
151 struct cap_buf
152 {
153 char **capa;
154 size_t numcapa;
155 size_t maxcapa;
156 };
157
158 static void
159 cap_buf_init (struct cap_buf *bp)
160 {
161 bp->numcapa = 0;
162 bp->maxcapa = 2;
163 bp->capa = calloc (bp->maxcapa, sizeof bp->capa[0]);
164 if (!bp->capa)
165 {
166 mu_error ("%s", mu_strerror (errno));
167 abort ();
168 }
169 bp->capa[0] = NULL;
170 }
171
172 static void
173 cap_buf_add (struct cap_buf *bp, char *str)
174 {
175 if (bp->numcapa == bp->maxcapa)
176 {
177 bp->maxcapa *= 2;
178 bp->capa = realloc (bp->capa, bp->maxcapa * sizeof bp->capa[0]);
179 if (!bp->capa)
180 {
181 mu_error ("%s", mu_strerror (errno));
182 abort ();
183 }
184 }
185 bp->capa[bp->numcapa] = str;
186 if (str)
187 bp->numcapa++;
188 }
189
190 static void
191 cap_buf_free (struct cap_buf *bp)
192 {
193 free (bp->capa);
194 }
195
196 static int
197 argp_reg_action (void *item, void *data)
198 {
199 struct cap_buf *bp = data;
200 cap_buf_add (bp, item);
201 return 0;
202 }
203
204 struct argp *
205 mu_argp_build (const struct argp *init_argp, char ***pcapa, int *flags)
206 {
207 struct cap_buf cb;
208 struct argp *argp;
209
210 cap_buf_init (&cb);
211 mu_gocs_enumerate (argp_reg_action, &cb);
212 cap_buf_add (&cb, NULL);
213 mu_libargp_init ();
214 argp = mu_build_argp (init_argp, cb.capa, flags);
215 if (pcapa)
216 *pcapa = cb.capa;
217 else
218 cap_buf_free (&cb);
219 return argp;
220 }
221
222 void
223 mu_argp_done (struct argp *argp)
224 {
225 free ((void*) argp->children);
226 free ((void*) argp);
227 }
1 /* GNU Mailutils -- a suite of utilities for electronic mail
2 Copyright (C) 2007-2012, 2014-2016 Free Software Foundation, Inc.
3
4 This library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Lesser General Public
6 License as published by the Free Software Foundation; either
7 version 3 of the License, or (at your option) any later version.
8
9 This library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Lesser General Public License for more details.
13
14 You should have received a copy of the GNU Lesser General
15 Public License along with this library. If not, see
16 <http://www.gnu.org/licenses/>. */
17
18 #ifdef HAVE_CONFIG_H
19 # include <config.h>
20 #endif
21 #include "cmdline.h"
22 #include <unistd.h>
23 #include <stdlib.h>
24 #include <mailutils/alloc.h>
25 #include <mailutils/stream.h>
26 #include <mailutils/io.h>
27 #include <mailutils/stdstream.h>
28 #include <string.h>
29 #ifdef MU_ALPHA_RELEASE
30 # include <git-describe.h>
31 #endif
32 struct mu_cfg_tree *mu_argp_tree;
33
34 const char version_etc_copyright[] =
35 /* Do *not* mark this string for translation. %s is a copyright
36 symbol suitable for this locale, and %d is the copyright
37 year. */
38 "Copyright %s 2007-2015 Free Software Foundation, inc.";
39
40 void
41 mu_program_version_hook (FILE *stream, struct argp_state *state)
42 {
43 #ifdef GIT_DESCRIBE
44 fprintf (stream, "%s (%s) %s [%s]\n",
45 mu_program_name, PACKAGE_NAME, PACKAGE_VERSION, GIT_DESCRIBE);
46 #else
47 fprintf (stream, "%s (%s) %s\n", mu_program_name,
48 PACKAGE_NAME, PACKAGE_VERSION);
49 #endif
50 /* TRANSLATORS: Translate "(C)" to the copyright symbol
51 (C-in-a-circle), if this symbol is available in the user's
52 locale. Otherwise, do not translate "(C)"; leave it as-is. */
53 fprintf (stream, version_etc_copyright, _("(C)"));
54
55 fputs (_("\
56 \n\
57 License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>\nThis is free software: you are free to change and redistribute it.\n\
58 There is NO WARRANTY, to the extent permitted by law.\n\
59 \n\
60 "),
61 stream);
62 }
63
64 void
65 mu_argp_init (const char *vers, const char *bugaddr)
66 {
67 if (vers)
68 argp_program_version = vers;
69 else
70 argp_program_version_hook = mu_program_version_hook;
71 argp_program_bug_address = bugaddr ? bugaddr : "<" PACKAGE_BUGREPORT ">";
72 }
73
74 static char *
75 get_canonical_name ()
76 {
77 char *name;
78 size_t len;
79 char *p;
80
81 if (!argp_program_version ||
82 !(p = strchr (argp_program_version, ' ')))
83 return strdup (mu_program_name);
84 len = p - argp_program_version;
85 name = mu_alloc (len + 1);
86 memcpy (name, argp_program_version, len);
87 name[len] = 0;
88 return name;
89 }
90
91 int mu_help_config_mode;
92 int mu_rcfile_lint;
93
94 int (*mu_app_cfg_verifier) (void) = NULL;
95
96 int
97 mu_app_init (struct argp *myargp, const char **capa,
98 struct mu_cfg_param *cfg_param,
99 int argc, char **argv, int flags, int *pindex, void *data)
100 {
101 int rc, i;
102 struct argp *argp;
103 struct argp argpnull = { 0 };
104 char **excapa;
105 struct mu_cfg_tree *parse_tree = NULL;
106
107 if (!mu_program_name)
108 mu_set_program_name (argv[0]);
109 if (!mu_log_tag)
110 mu_log_tag = (char*)mu_program_name;
111 mu_stdstream_setup (MU_STDSTREAM_RESET_NONE);
112
113 mu_libargp_init ();
114 if (capa)
115 for (i = 0; capa[i]; i++)
116 mu_gocs_register_std (capa[i]); /*FIXME*/
117 if (!myargp)
118 myargp = &argpnull;
119 argp = mu_argp_build (myargp, &excapa, &flags);
120
121 mu_cfg_tree_create (&mu_argp_tree);
122 rc = argp_parse (argp, argc, argv, flags, pindex, data);
123 mu_argp_done (argp);
124 if (rc)
125 return rc;
126
127 /* Reset program name, it may have been changed using the `--program-name'
128 option. */
129 mu_set_program_name (program_invocation_name);
130
131 mu_libcfg_init (excapa);
132 free (excapa);
133
134 if (mu_help_config_mode)
135 {
136 char *comment;
137 char *canonical_name = get_canonical_name ();
138 mu_stream_t stream;
139 struct mu_cfg_cont *cont;
140 static struct mu_cfg_param dummy_include_param[] = {
141 { "include", mu_c_string, NULL, 0, NULL,
142 N_("Include contents of the given file. If a directory is given, "
143 "include contents of the file <file>/<program>, where "
144 "<program> is the name of the program. This latter form is "
145 "allowed only in the site-wide configuration file."),
146 N_("file-or-directory") },
147 { NULL }
148 };
149
150 mu_stdio_stream_create (&stream, MU_STDOUT_FD, 0);
151
152 mu_asprintf (&comment,
153 "Configuration file structure for %s utility.",
154 mu_program_name);
155 mu_cfg_format_docstring (stream, comment, 0);
156 free (comment);
157 mu_asprintf (&comment,
158 "For use in global configuration file (%s), enclose it "
159 "in `program %s { ... };",
160 mu_site_rcfile,
161 mu_program_name);
162 mu_cfg_format_docstring (stream, comment, 0);
163 free (comment);
164 mu_asprintf (&comment, "For more information, use `info %s'.",
165 canonical_name);
166 mu_cfg_format_docstring (stream, comment, 0);
167 free (comment);
168
169 cont = mu_config_clone_root_container ();
170 mu_config_container_register_section (&cont, NULL, NULL, NULL, NULL,
171 dummy_include_param, NULL);
172 mu_config_container_register_section (&cont, NULL, NULL, NULL, NULL,
173 cfg_param, NULL);
174 mu_cfg_format_container (stream, cont);
175 mu_config_destroy_container (&cont);
176
177 mu_stream_destroy (&stream);
178 exit (0);
179 }
180
181 rc = mu_libcfg_parse_config (&parse_tree);
182 if (rc == 0)
183 {
184 struct mu_cfg_parse_hints hints = { MU_PARSE_CONFIG_PLAIN };
185
186 hints.flags |= MU_CFG_PARSE_PROGRAM;
187 hints.program = (char*)mu_program_name;
188
189 if (mu_cfg_parser_verbose)
190 hints.flags |= MU_PARSE_CONFIG_VERBOSE;
191 if (mu_cfg_parser_verbose > 1)
192 hints.flags |= MU_PARSE_CONFIG_DUMP;
193 mu_cfg_tree_postprocess (mu_argp_tree, &hints);
194 mu_cfg_tree_union (&parse_tree, &mu_argp_tree);
195 rc = mu_cfg_tree_reduce (parse_tree, &hints, cfg_param, data);
196 }
197
198 if (mu_rcfile_lint)
199 {
200 if (rc || mu_cfg_error_count)
201 exit (1);
202 if (mu_app_cfg_verifier)
203 rc = mu_app_cfg_verifier ();
204 exit (rc ? 1 : 0);
205 }
206
207 mu_gocs_flush ();
208 mu_cfg_destroy_tree (&mu_argp_tree);
209 mu_cfg_destroy_tree (&parse_tree);
210
211 return !!(rc || mu_cfg_error_count);
212 }
213
1 /* GNU Mailutils -- a suite of utilities for electronic mail
2 Copyright (C) 1999-2002, 2005, 2007, 2009-2012, 2014-2016 Free
3 Software Foundation, Inc.
4
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 3 of the License, or (at your option) any later version.
9
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General
16 Public License along with this library. If not, see
17 <http://www.gnu.org/licenses/>. */
18
19 #ifdef HAVE_CONFIG_H
20 # include <config.h>
21 #endif
22 #include "cmdline.h"
23 #include "mailutils/sieve.h"
24
25 enum {
26 OPT_CLEAR_INCLUDE_PATH = 256,
27 OPT_CLEAR_LIBRARY_PATH,
28 OPT_PREFIX_LIBRARY_PATH
29 };
30
31 static struct argp_option sieve_argp_option[] = {
32 { "includedir", 'I', N_("DIR"), 0,
33 N_("append DIR to the list of directories searched for include files"), 0 },
34 { "libdir", 'L', N_("DIR"), 0,
35 N_("append DIR to the list of directories searched for library files"), 0 },
36 { "libdir-prefix", OPT_PREFIX_LIBRARY_PATH, N_("DIR"), 0,
37 N_("add DIR to the beginning of the list of directories searched for "
38 "library files"), 0 },
39 { "clear-include-path", OPT_CLEAR_INCLUDE_PATH, NULL, 0,
40 N_("clear Sieve include path"), 0 },
41 { "clear-library-path", OPT_CLEAR_LIBRARY_PATH, NULL, 0,
42 N_("clear Sieve library path"), 0 },
43 { "clearpath", 0, NULL, OPTION_ALIAS, NULL },
44 { NULL, 0, NULL, 0, NULL, 0 }
45 };
46
47 static error_t
48 sieve_argp_parser (int key, char *arg, struct argp_state *state)
49 {
50 static mu_list_t lst;
51
52 switch (key)
53 {
54 case 'I':
55 mu_argp_node_list_new (lst, "include-path", arg);
56 break;
57
58 case 'L':
59 mu_argp_node_list_new (lst, "library-path", arg);
60 break;
61
62 case OPT_PREFIX_LIBRARY_PATH:
63 mu_argp_node_list_new (lst, "library-path-prefix", arg);
64 break;
65
66 case OPT_CLEAR_INCLUDE_PATH:
67 mu_argp_node_list_new (lst, "clear-include-path", "yes");
68 break;
69
70 case OPT_CLEAR_LIBRARY_PATH:
71 mu_argp_node_list_new (lst, "clear-library-path", "yes");
72 break;
73
74 case ARGP_KEY_INIT:
75 mu_argp_node_list_init (&lst);
76 break;
77
78 case ARGP_KEY_FINI:
79 mu_argp_node_list_finish (lst, "sieve", NULL);
80 break;
81
82 default:
83 return ARGP_ERR_UNKNOWN;
84 }
85 return 0;
86 }
87
88 static struct argp sieve_argp = {
89 sieve_argp_option,
90 sieve_argp_parser,
91 };
92
93 static struct argp_child sieve_argp_child = {
94 &sieve_argp,
95 0,
96 N_("Sieve options"),
97 0
98 };
99
100 struct mu_cmdline_capa mu_sieve_cmdline = {
101 "sieve", &sieve_argp_child
102 };
103
...@@ -19,6 +19,7 @@ ...@@ -19,6 +19,7 @@
19 #if HAVE_CONFIG_H 19 #if HAVE_CONFIG_H
20 # include <config.h> 20 # include <config.h>
21 #endif 21 #endif
22 #include <mailutils/cli.h>
22 23
23 #ifdef WITH_GSASL 24 #ifdef WITH_GSASL
24 25
...@@ -46,13 +47,27 @@ struct mu_gsasl_module_data mu_gsasl_module_data = { ...@@ -46,13 +47,27 @@ struct mu_gsasl_module_data mu_gsasl_module_data = {
46 SITE_CRAM_MD5_PWD 47 SITE_CRAM_MD5_PWD
47 }; 48 };
48 49
49 int 50 static struct mu_cfg_param mu_gsasl_param[] = {
50 mu_gsasl_module_init (enum mu_gocs_op op, void *data) 51 { "enable", mu_c_bool, &mu_gsasl_module_data.enable, 0, NULL,
51 { 52 N_("Enable GSASL (default)") },
52 if (op == mu_gocs_op_set && data) 53 { "cram-passwd", mu_c_string, &mu_gsasl_module_data.cram_md5_pwd, 0, NULL,
53 memcpy (&mu_gsasl_module_data, data, sizeof (mu_gsasl_module_data)); 54 N_("Name of GSASL password file."),
54 return 0; 55 N_("file") },
55 } 56 { "service", mu_c_string, &mu_gsasl_module_data.service, 0, NULL,
57 N_("SASL service name."),
58 N_("name") },
59 { "realm", mu_c_string, &mu_gsasl_module_data.realm, 0, NULL,
60 N_("SASL realm name."),
61 N_("name") },
62 { "hostname", mu_c_string, &mu_gsasl_module_data.hostname, 0, NULL,
63 N_("SASL host name."),
64 N_("name") },
65 { "anonymous-user", mu_c_string, &mu_gsasl_module_data.anon_user, 0, NULL,
66 N_("Anonymous user name."),
67 N_("name") },
68
69 { NULL }
70 };
56 71
57 int 72 int
58 mu_gsasl_enabled (void) 73 mu_gsasl_enabled (void)
...@@ -231,4 +246,10 @@ mu_gsasl_enabled (void) ...@@ -231,4 +246,10 @@ mu_gsasl_enabled (void)
231 { 246 {
232 return 0; 247 return 0;
233 } 248 }
249 #define mu_gsasl_param NULL
234 #endif 250 #endif
251
252 struct mu_auth_module mu_auth_gsasl_module = {
253 .name = "gsasl",
254 .cfg = mu_gsasl_param
255 };
......
...@@ -61,17 +61,82 @@ const char *default_field_map = ...@@ -61,17 +61,82 @@ const char *default_field_map =
61 61
62 static struct mu_ldap_module_config ldap_param; 62 static struct mu_ldap_module_config ldap_param;
63 63
64 int 64
65 mu_ldap_module_init (enum mu_gocs_op op, void *data) 65
66 static int
67 _cb2_field_map (const char *arg, void *data)
68 {
69 int err;
70 int rc = mutil_parse_field_map (arg, &ldap_param.field_map, &err);
71 if (rc)
72 /* FIXME: this message can be misleading */
73 mu_error (_("error near element %d: %s"), err, mu_strerror (rc));
74 return 0;
75 }
76
77 static int
78 cb_field_map (void *data, mu_config_value_t *val)
66 { 79 {
67 struct mu_ldap_module_config *cfg = data; 80 return mu_cfg_string_value_cb (val, _cb2_field_map, NULL);
81 }
82
83 static struct mu_cfg_param mu_ldap_param[] = {
84 { "enable", mu_c_bool, &ldap_param.enable, 0, NULL,
85 N_("Enable LDAP lookups.") },
86 { "url", mu_c_string, &ldap_param.url, 0, NULL,
87 N_("Set URL of the LDAP server."),
88 N_("url") },
89 { "base", mu_c_string, &ldap_param.base, 0, NULL,
90 N_("Base DN for LDAP lookups."),
91 N_("dn") },
92 { "binddn", mu_c_string, &ldap_param.binddn, 0, NULL,
93 N_("DN for accessing LDAP database."),
94 N_("dn") },
95 { "passwd", mu_c_string, &ldap_param.passwd, 0, NULL,
96 N_("Password for use with binddn.") },
97 { "tls", mu_c_bool, &ldap_param.tls, 0, NULL,
98 N_("Use TLS encryption.") },
99 { "debug", mu_c_int, &ldap_param.debug, 0, NULL,
100 N_("Set LDAP debugging level.") },
101 { "field-map", mu_cfg_callback, NULL, 0, cb_field_map,
102 N_("Set a field-map for parsing LDAP replies. The map is a "
103 "column-separated list of definitions. Each definition has the "
104 "following form:\n"
105 " <name: string>=<attr: string>\n"
106 "where <name> is one of the following: name, passwd, uid, gid, "
107 "gecos, dir, shell, mailbox, quota, and <attr> is the name of "
108 "the corresponding LDAP attribute."),
109 N_("map") },
110 { "getpwnam", mu_c_string, &ldap_param.getpwnam_filter, 0, NULL,
111 N_("LDAP filter to use for getpwnam requests."),
112 N_("filter") },
113 { "getpwuid", mu_c_string, &ldap_param.getpwuid_filter, 0, NULL,
114 N_("LDAP filter to use for getpwuid requests."),
115 N_("filter") },
116 { NULL }
117 };
68 118
69 if (op != mu_gocs_op_set) 119 int
120 mu_ldap_section_parser
121 (enum mu_cfg_section_stage stage, const mu_cfg_node_t *node,
122 const char *section_label, void **section_data,
123 void *call_data, mu_cfg_tree_t *tree)
124 {
125 switch (stage)
126 {
127 case mu_cfg_section_start:
128 ldap_param.enable = 1;
129 break;
130 default:
131 break;
132 }
70 return 0; 133 return 0;
134 }
71 135
72 if (cfg)
73 ldap_param = *cfg;
74 136
137 static void
138 module_init (void *ptr)
139 {
75 if (ldap_param.enable) 140 if (ldap_param.enable)
76 { 141 {
77 if (!ldap_param.getpwnam_filter) 142 if (!ldap_param.getpwnam_filter)
...@@ -85,7 +150,6 @@ mu_ldap_module_init (enum mu_gocs_op op, void *data) ...@@ -85,7 +150,6 @@ mu_ldap_module_init (enum mu_gocs_op op, void *data)
85 mutil_parse_field_map (default_field_map, &ldap_param.field_map, &d); 150 mutil_parse_field_map (default_field_map, &ldap_param.field_map, &d);
86 } 151 }
87 } 152 }
88 return 0;
89 } 153 }
90 154
91 static int 155 static int
...@@ -272,8 +336,6 @@ _mu_conn_setup (LDAP **pld) ...@@ -272,8 +336,6 @@ _mu_conn_setup (LDAP **pld)
272 return 0; 336 return 0;
273 } 337 }
274 338
275
276
277 static int 339 static int
278 _mu_ldap_bind (LDAP *ld) 340 _mu_ldap_bind (LDAP *ld)
279 { 341 {
...@@ -862,15 +924,16 @@ mu_auth_ldap_user_by_uid (struct mu_auth_data **return_data, ...@@ -862,15 +924,16 @@ mu_auth_ldap_user_by_uid (struct mu_auth_data **return_data,
862 # define mu_ldap_authenticate mu_auth_nosupport 924 # define mu_ldap_authenticate mu_auth_nosupport
863 # define mu_auth_ldap_user_by_name mu_auth_nosupport 925 # define mu_auth_ldap_user_by_name mu_auth_nosupport
864 # define mu_auth_ldap_user_by_uid mu_auth_nosupport 926 # define mu_auth_ldap_user_by_uid mu_auth_nosupport
927
865 #endif 928 #endif
866 929
867 struct mu_auth_module mu_auth_ldap_module = { 930 struct mu_auth_module mu_auth_ldap_module = {
868 "ldap", 931 .name = "ldap",
869 mu_ldap_module_init, 932 .commit = module_init,
870 mu_ldap_authenticate, 933 .handler = {
871 NULL, 934 [mu_auth_authenticate] = mu_ldap_authenticate,
872 mu_auth_ldap_user_by_name, 935 [mu_auth_getpwnam] = mu_auth_ldap_user_by_name,
873 NULL, 936 [mu_auth_getpwuid] = mu_auth_ldap_user_by_uid
874 mu_auth_ldap_user_by_uid, 937 },
875 NULL 938 .cfg = mu_ldap_param
876 }; 939 };
......
...@@ -49,6 +49,14 @@ ...@@ -49,6 +49,14 @@
49 char *mu_pam_service = PACKAGE; 49 char *mu_pam_service = PACKAGE;
50 50
51 #ifdef USE_LIBPAM 51 #ifdef USE_LIBPAM
52 static struct mu_cfg_param mu_pam_param[] = {
53 { "service", mu_c_string, &mu_pam_service, 0, NULL,
54 N_("Set PAM service name."),
55 N_("name") },
56 { NULL }
57 };
58
59
52 #define COPY_STRING(s) (s) ? strdup(s) : NULL 60 #define COPY_STRING(s) (s) ? strdup(s) : NULL
53 61
54 static char *_pwd; 62 static char *_pwd;
...@@ -175,43 +183,13 @@ mu_authenticate_pam (struct mu_auth_data **return_data MU_ARG_UNUSED, ...@@ -175,43 +183,13 @@ mu_authenticate_pam (struct mu_auth_data **return_data MU_ARG_UNUSED,
175 } 183 }
176 184
177 #else 185 #else
178 186 # define mu_pam_param NULL
179 int 187 # define mu_authenticate_pam NULL
180 mu_authenticate_pam (struct mu_auth_data **return_data MU_ARG_UNUSED,
181 const void *key MU_ARG_UNUSED,
182 void *func_data MU_ARG_UNUSED,
183 void *call_data MU_ARG_UNUSED)
184 {
185 return ENOSYS;
186 }
187
188 #endif 188 #endif
189 189
190 int
191 mu_pam_module_init (enum mu_gocs_op op, void *data)
192 {
193 if (op == mu_gocs_op_set && data)
194 {
195 struct mu_gocs_pam *p = data;
196 if (p->service)
197 {
198 if ((mu_pam_service = strdup (p->service)) == NULL)
199 return ENOMEM;
200 }
201 else
202 mu_pam_service = NULL;
203 }
204 return 0;
205 }
206
207 struct mu_auth_module mu_auth_pam_module = { 190 struct mu_auth_module mu_auth_pam_module = {
208 "pam", 191 .name = "pam",
209 mu_pam_module_init, 192 .handler = { [mu_auth_authenticate] = mu_authenticate_pam },
210 mu_authenticate_pam, 193 .cfg = mu_pam_param
211 NULL,
212 mu_auth_nosupport,
213 NULL,
214 mu_auth_nosupport,
215 NULL
216 }; 194 };
217 195
......
...@@ -42,6 +42,9 @@ ...@@ -42,6 +42,9 @@
42 #include <mailutils/nls.h> 42 #include <mailutils/nls.h>
43 #include <mailutils/io.h> 43 #include <mailutils/io.h>
44 #include <mailutils/cctype.h> 44 #include <mailutils/cctype.h>
45 #include <mailutils/cli.h>
46 #include <mailutils/stream.h>
47 #include <mailutils/stdstream.h>
45 48
46 #ifdef ENABLE_RADIUS 49 #ifdef ENABLE_RADIUS
47 50
...@@ -62,7 +65,6 @@ static grad_avp_t *auth_request; ...@@ -62,7 +65,6 @@ static grad_avp_t *auth_request;
62 static grad_avp_t *getpwnam_request; 65 static grad_avp_t *getpwnam_request;
63 static grad_avp_t *getpwuid_request; 66 static grad_avp_t *getpwuid_request;
64 67
65
66 int 68 int
67 get_attribute (int *pattr, char *name) 69 get_attribute (int *pattr, char *name)
68 { 70 {
...@@ -84,30 +86,41 @@ enum parse_state ...@@ -84,30 +86,41 @@ enum parse_state
84 state_delim 86 state_delim
85 }; 87 };
86 88
87 int 89 static int
88 parse_pairlist (grad_avp_t **plist, char *input) 90 cb_request (void *data, mu_config_value_t *val)
89 { 91 {
92 grad_avp_t **plist = data;
90 size_t i; 93 size_t i;
91 struct mu_wordsplit ws; 94 struct mu_wordsplit ws;
92 enum parse_state state; 95 enum parse_state state;
93 grad_locus_t loc; 96 grad_locus_t loc;
94 char *name; 97 char *name;
95 char *op; /* FIXME: It is actually ignored. Should it be? */ 98 struct mu_locus locus;
96 99
97 if (!input) 100 if (mu_cfg_assert_value_type (val, MU_CFG_STRING))
98 return 1; 101 return 1;
99 102
100 ws.ws_delim = ","; 103 ws.ws_delim = ",";
101 if (mu_wordsplit (input, &ws, 104 if (mu_wordsplit (val->v.string, &ws,
102 MU_WRDSF_DEFFLAGS|MU_WRDSF_DELIM|MU_WRDSF_RETURN_DELIMS)) 105 MU_WRDSF_DEFFLAGS|MU_WRDSF_DELIM|MU_WRDSF_RETURN_DELIMS))
103 { 106 {
104 mu_error (_("cannot parse input `%s': %s"), input, 107 mu_error (_("cannot parse input `%s': %s"), val->v.string,
105 mu_wordsplit_strerror (&ws)); 108 mu_wordsplit_strerror (&ws));
106 return 1; 109 return 1;
107 } 110 }
108 111
109 loc.file = "<configuration>"; /*FIXME*/ 112 if (mu_stream_ioctl (mu_strerr, MU_IOCTL_LOGSTREAM,
113 MU_IOCTL_LOGSTREAM_GET_LOCUS,
114 &locus) == 0)
115 {
116 loc.file = locus.mu_file;
117 loc.line = locus.mu_line;
118 }
119 else
120 {
121 loc.file = "<unknown>";
110 loc.line = 0; 122 loc.line = 0;
123 }
111 124
112 for (i = 0, state = state_lhs; i < ws.ws_wordc; i++) 125 for (i = 0, state = state_lhs; i < ws.ws_wordc; i++)
113 { 126 {
...@@ -121,7 +134,7 @@ parse_pairlist (grad_avp_t **plist, char *input) ...@@ -121,7 +134,7 @@ parse_pairlist (grad_avp_t **plist, char *input)
121 break; 134 break;
122 135
123 case state_op: 136 case state_op:
124 op = ws.ws_wordv[i]; 137 //op = ws.ws_wordv[i];
125 state = state_rhs; 138 state = state_rhs;
126 break; 139 break;
127 140
...@@ -158,13 +171,42 @@ parse_pairlist (grad_avp_t **plist, char *input) ...@@ -158,13 +171,42 @@ parse_pairlist (grad_avp_t **plist, char *input)
158 return 0; 171 return 0;
159 } 172 }
160 173
174 static int
175 cb_config_dir (void *data, mu_config_value_t *val)
176 {
177 if (mu_cfg_assert_value_type (val, MU_CFG_STRING))
178 return 1;
179 grad_config_dir = grad_estrdup (val->v.string);
180 return 0;
181 }
182
183 static struct mu_cfg_param mu_radius_param[] = {
184 { "auth", mu_cfg_callback, &auth_request, 0, cb_request,
185 N_("Radius request for authorization."),
186 N_("request: string") },
187 { "getpwnam", mu_cfg_callback, &getpwnam_request, 0, cb_request,
188 N_("Radius request for getpwnam."),
189 N_("request: string") },
190 { "getpwuid", mu_cfg_callback, &getpwuid_request, 0, cb_request,
191 N_("Radius request for getpwuid."),
192 N_("request: string") },
193 { "directory", mu_cfg_callback, NULL, 0, cb_config_dir,
194 N_("Set radius configuration directory.") },
195 { NULL }
196 };
197
198 struct mu_cli_capa mu_cli_capa_radius = {
199 "radius",
200 NULL,
201 mu_radius_param
202 };
203
161 /* Assume radius support is needed if any of the above requests is 204 /* Assume radius support is needed if any of the above requests is
162 defined. Actually, all of them should be, but it is the responsibility 205 defined. Actually, all of them should be, but it is the responsibility
163 of init to check for consistency of the configuration */ 206 of init to check for consistency of the configuration */
164 207
165 #define NEED_RADIUS_P(cfg) \ 208 #define NEED_RADIUS_P() \
166 ((cfg) && \ 209 (auth_request || getpwnam_request || getpwuid_request)
167 ((cfg)->auth_request || (cfg)->getpwnam_request || (cfg)->getpwuid_request))
168 210
169 static void 211 static void
170 mu_grad_logger(int level, 212 mu_grad_logger(int level,
...@@ -196,21 +238,16 @@ mu_grad_logger(int level, ...@@ -196,21 +238,16 @@ mu_grad_logger(int level,
196 } 238 }
197 mu_diag_voutput (mlevel[level & GRAD_LOG_PRIMASK], pfx ? pfx : fmt, ap); 239 mu_diag_voutput (mlevel[level & GRAD_LOG_PRIMASK], pfx ? pfx : fmt, ap);
198 if (pfx) 240 if (pfx)
199 free(pfx); 241 free (pfx);
200 } 242 }
201 243
202 int 244 static void
203 mu_radius_module_init (enum mu_gocs_op op, void *data) 245 module_init (void *ptr)
204 { 246 {
205 struct mu_radius_module_data *cfg = data; 247 if (!NEED_RADIUS_P ())
206 248 return;
207 if (op != mu_gocs_op_set)
208 return 0;
209 if (!NEED_RADIUS_P (cfg))
210 return 0;
211 249
212 grad_set_logger (mu_grad_logger); 250 grad_set_logger (mu_grad_logger);
213 grad_config_dir = grad_estrdup (cfg->config_dir);
214 251
215 grad_path_init (); 252 grad_path_init ();
216 srand (time (NULL) + getpid ()); 253 srand (time (NULL) + getpid ());
...@@ -218,7 +255,7 @@ mu_radius_module_init (enum mu_gocs_op op, void *data) ...@@ -218,7 +255,7 @@ mu_radius_module_init (enum mu_gocs_op op, void *data)
218 if (grad_dict_init ()) 255 if (grad_dict_init ())
219 { 256 {
220 mu_error (_("cannot read radius dictionaries")); 257 mu_error (_("cannot read radius dictionaries"));
221 return 1; 258 return;
222 } 259 }
223 260
224 /* Check whether mailutils attributes are defined */ 261 /* Check whether mailutils attributes are defined */
...@@ -229,16 +266,9 @@ mu_radius_module_init (enum mu_gocs_op op, void *data) ...@@ -229,16 +266,9 @@ mu_radius_module_init (enum mu_gocs_op op, void *data)
229 || get_attribute (&MU_Dir, "MU-Dir") 266 || get_attribute (&MU_Dir, "MU-Dir")
230 || get_attribute (&MU_Shell, "MU-Shell") 267 || get_attribute (&MU_Shell, "MU-Shell")
231 || get_attribute (&MU_Mailbox, "MU-Mailbox")) 268 || get_attribute (&MU_Mailbox, "MU-Mailbox"))
232 return 1; 269 return;
233
234 /* Parse saved requests */
235 if (parse_pairlist (&auth_request, cfg->auth_request)
236 || parse_pairlist (&getpwnam_request, cfg->getpwnam_request)
237 || parse_pairlist (&getpwuid_request, cfg->getpwuid_request))
238 return 1;
239 270
240 radius_auth_enabled = 1; 271 radius_auth_enabled = 1;
241 return 0;
242 } 272 }
243 273
244 static char * 274 static char *
...@@ -518,44 +548,19 @@ mu_auth_radius_user_by_uid (struct mu_auth_data **return_data, ...@@ -518,44 +548,19 @@ mu_auth_radius_user_by_uid (struct mu_auth_data **return_data,
518 return rc; 548 return rc;
519 } 549 }
520 550
521 #else
522 static int
523 mu_radius_authenticate (struct mu_auth_data **return_data MU_ARG_UNUSED,
524 const void *key,
525 void *func_data MU_ARG_UNUSED, void *call_data)
526 {
527 return ENOSYS;
528 }
529
530 static int
531 mu_auth_radius_user_by_name (struct mu_auth_data **return_data MU_ARG_UNUSED,
532 const void *key MU_ARG_UNUSED,
533 void *func_data MU_ARG_UNUSED,
534 void *call_data MU_ARG_UNUSED)
535 {
536 return ENOSYS;
537 }
538
539 static int
540 mu_auth_radius_user_by_uid (struct mu_auth_data **return_data,
541 const void *key,
542 void *func_data, void *call_data)
543 {
544 return ENOSYS;
545 }
546 #endif
547
548 struct mu_auth_module mu_auth_radius_module = { 551 struct mu_auth_module mu_auth_radius_module = {
549 "radius", 552 .name = "radius",
550 #ifdef ENABLE_RADIUS 553 .cfg = mu_radius_param,
551 mu_radius_module_init, 554 .commit = module_init,
555 .handler = {
556 [mu_auth_authenticate] = mu_radius_authenticate,
557 [mu_auth_getpwnam] = mu_auth_radius_user_by_name,
558 [mu_auth_getpwuid] = mu_auth_radius_user_by_uid
559 }
560 };
552 #else 561 #else
553 NULL, 562 struct mu_auth_module mu_auth_radius_module = {
554 #endif 563 .name = "radius"
555 mu_radius_authenticate,
556 NULL,
557 mu_auth_radius_user_by_name,
558 NULL,
559 mu_auth_radius_user_by_uid,
560 NULL
561 }; 564 };
565 #endif
566
......
...@@ -50,11 +50,96 @@ ...@@ -50,11 +50,96 @@
50 #include <mailutils/sql.h> 50 #include <mailutils/sql.h>
51 #include <mailutils/cstr.h> 51 #include <mailutils/cstr.h>
52 #include <mailutils/wordsplit.h> 52 #include <mailutils/wordsplit.h>
53 #include <mailutils/cli.h>
53 #include "sql.h" 54 #include "sql.h"
54 55
55 #ifdef USE_SQL 56 #ifdef USE_SQL
56 57
57 struct mu_internal_sql_config mu_sql_module_config; 58 struct mu_sql_module_config mu_sql_module_config;
59 /* Resource file configuration */
60 static int
61 cb_password_type (void *data, mu_config_value_t *val)
62 {
63 if (mu_cfg_assert_value_type (val, MU_CFG_STRING))
64 return 1;
65
66 if (mu_sql_decode_password_type (val->v.string, &mu_sql_module_config.password_type))
67 mu_error (_("unknown password type `%s'"), val->v.string);
68 return 0;
69 }
70
71 static int
72 _cb2_field_map (const char *arg, void *data)
73 {
74 int err;
75 int rc = mutil_parse_field_map (arg, &mu_sql_module_config.field_map, &err);
76 if (rc)
77 /* FIXME: this message may be misleading */
78 mu_error (_("error near element %d: %s"), err, mu_strerror (rc));
79 return 0;
80 }
81
82 static int
83 cb_field_map (void *data, mu_config_value_t *val)
84 {
85 return mu_cfg_string_value_cb (val, _cb2_field_map, NULL);
86 }
87
88 static int
89 cb_interface (void *data, mu_config_value_t *val)
90 {
91 if (mu_cfg_assert_value_type (val, MU_CFG_STRING))
92 return 1;
93 mu_sql_module_config.interface = mu_sql_interface_index (val->v.string);
94 if (mu_sql_module_config.interface == 0)
95 {
96 mu_error (_("unknown SQL interface `%s'"), val->v.string);
97 return 1;
98 }
99 return 0;
100 }
101
102 static struct mu_cfg_param mu_sql_param[] = {
103 { "interface", mu_cfg_callback, &mu_sql_module_config.interface, 0,
104 cb_interface,
105 N_("Set SQL interface to use."),
106 N_("iface: mysql|odbc|postgres") },
107 { "getpwnam", mu_c_string, &mu_sql_module_config.getpwnam_query, 0, NULL,
108 N_("SQL query to use for getpwnam requests."),
109 N_("query") },
110 { "getpwuid", mu_c_string, &mu_sql_module_config.getpwuid_query, 0, NULL,
111 N_("SQL query to use for getpwuid requests."),
112 N_("query") },
113 { "getpass", mu_c_string, &mu_sql_module_config.getpass_query, 0, NULL,
114 N_("SQL query returning the user's password."),
115 N_("query") },
116 { "host", mu_c_string, &mu_sql_module_config.host, 0, NULL,
117 N_("SQL server host name.") },
118 { "user", mu_c_string, &mu_sql_module_config.user, 0, NULL,
119 N_("SQL user name.") },
120 { "passwd", mu_c_string, &mu_sql_module_config.passwd, 0, NULL,
121 N_("Password for the SQL user.") },
122 { "port", mu_c_int, &mu_sql_module_config.port, 0, NULL,
123 N_("SQL server port.") },
124 { "db", mu_c_string, &mu_sql_module_config.db, 0, NULL,
125 N_("Database name.") },
126 { "password-type", mu_cfg_callback, NULL, 0, cb_password_type,
127 N_("Type of password returned by getpass query (one of: plain, hash, "
128 "scrambled).") },
129 { "positional", mu_c_bool, &mu_sql_module_config.positional, 0, NULL,
130 N_("Use positional (v1.0 compatible) field interface.") },
131 { "field-map", mu_cfg_callback, NULL, 0, cb_field_map,
132 N_("Set a field-map for parsing SQL replies. The map is a "
133 "column-separated list of definitions. Each definition has the "
134 "following form:\n"
135 " <name: string>=<column: string>\n"
136 "where <name> is one of the following: name, passwd, uid, gid, "
137 "gecos, dir, shell, mailbox, quota, and <column> is the name of "
138 "the corresponding SQL column."),
139 N_("map") },
140 { NULL }
141 };
142
58 143
59 static char * 144 static char *
60 sql_escape_string (const char *ustr) 145 sql_escape_string (const char *ustr)
...@@ -668,55 +753,22 @@ mu_sql_authenticate (struct mu_auth_data **return_data MU_ARG_UNUSED, ...@@ -668,55 +753,22 @@ mu_sql_authenticate (struct mu_auth_data **return_data MU_ARG_UNUSED,
668 return rc == 0 ? 0 : MU_ERR_AUTH_FAILURE; 753 return rc == 0 ? 0 : MU_ERR_AUTH_FAILURE;
669 } 754 }
670 755
671 int
672 mu_sql_module_init (enum mu_gocs_op op, void *data)
673 {
674 struct mu_sql_module_config *cfg = data;
675
676 if (op != mu_gocs_op_set)
677 return 0;
678 mu_sql_module_config.interface = mu_sql_interface_index (cfg->interface);
679 if (mu_sql_module_config.interface == 0)
680 {
681 mu_error (_("unknown SQL interface `%s'"), cfg->interface);
682 return 1;
683 }
684
685 mu_sql_module_config.getpwnam_query = cfg->getpwnam_query;
686 mu_sql_module_config.getpass_query = cfg->getpass_query;
687 mu_sql_module_config.getpwuid_query = cfg->getpwuid_query;
688 mu_sql_module_config.host = cfg->host;
689 mu_sql_module_config.user = cfg->user;
690 mu_sql_module_config.passwd = cfg->passwd;
691 mu_sql_module_config.db = cfg->db;
692 mu_sql_module_config.port = cfg->port;
693 mu_sql_module_config.password_type = cfg->password_type;
694 mu_sql_module_config.field_map = cfg->field_map;
695
696 return 0;
697 }
698
699 #else 756 #else
700 757
701 # define mu_sql_authenticate mu_auth_nosupport 758 # define mu_sql_authenticate mu_auth_nosupport
702 # define mu_auth_sql_by_name mu_auth_nosupport 759 # define mu_auth_sql_by_name mu_auth_nosupport
703 # define mu_auth_sql_by_uid mu_auth_nosupport 760 # define mu_auth_sql_by_uid mu_auth_nosupport
704 761 # define mu_sql_param NULL
705 #endif 762 #endif
706 763
707 764
708 struct mu_auth_module mu_auth_sql_module = { 765 struct mu_auth_module mu_auth_sql_module = {
709 "sql", 766 .name = "sql",
710 #ifdef USE_SQL 767 .cfg = mu_sql_param,
711 mu_sql_module_init, 768 .handler = {
712 #else 769 [mu_auth_authenticate] = mu_sql_authenticate,
713 NULL, 770 [mu_auth_getpwnam] = mu_auth_sql_by_name,
714 #endif 771 [mu_auth_getpwuid] = mu_auth_sql_by_uid
715 mu_sql_authenticate, 772 }
716 NULL,
717 mu_auth_sql_by_name,
718 NULL,
719 mu_auth_sql_by_uid,
720 NULL
721 }; 773 };
722 774
......
...@@ -64,22 +64,6 @@ struct mu_tls_module_config mu_tls_module_config = { ...@@ -64,22 +64,6 @@ struct mu_tls_module_config mu_tls_module_config = {
64 0 64 0
65 #endif 65 #endif
66 }; 66 };
67 //FIXME: REMOVE
68 int
69 mu_tls_module_init (enum mu_gocs_op op, void *data)
70 {
71 switch (op)
72 {
73 case mu_gocs_op_set:
74 if (data)
75 memcpy (&mu_tls_module_config, data, sizeof mu_tls_module_config);
76 break;
77
78 case mu_gocs_op_flush:
79 break;
80 }
81 return 0;
82 }
83 67
84 #ifdef WITH_TLS 68 #ifdef WITH_TLS
85 69
...@@ -870,16 +854,14 @@ static struct mu_cfg_param mu_tls_param[] = { ...@@ -870,16 +854,14 @@ static struct mu_cfg_param mu_tls_param[] = {
870 { NULL } 854 { NULL }
871 }; 855 };
872 856
873 struct mu_cli_capa mu_cli_capa_tls = { 857 struct mu_auth_module mu_auth_tls_module = {
874 "tls", 858 .name = "tls",
875 NULL, 859 .cfg = mu_tls_param
876 mu_tls_param,
877 NULL, NULL
878 }; 860 };
861
879 #else 862 #else
880 struct mu_cli_capa mu_cli_capa_tls = { 863 struct mu_auth_module mu_auth_tls_module = {
881 "tls", 864 .name = "tls"
882 NULL
883 }; 865 };
884 #endif /* WITH_TLS */ 866 #endif /* WITH_TLS */
885 867
......
...@@ -53,21 +53,19 @@ ...@@ -53,21 +53,19 @@
53 #include <mailutils/nls.h> 53 #include <mailutils/nls.h>
54 #include <mailutils/errno.h> 54 #include <mailutils/errno.h>
55 #include <mailutils/util.h> 55 #include <mailutils/util.h>
56 #include <mailutils/cli.h>
56 57
57 #ifdef ENABLE_VIRTUAL_DOMAINS 58 #ifdef ENABLE_VIRTUAL_DOMAINS
58 59
59 struct mu_gocs_virtual mu_virtual_module_config = { SITE_VIRTUAL_PWDDIR }; 60 static char *pwddir = { SITE_VIRTUAL_PWDDIR };
60 61
61 int 62 static struct mu_cfg_param mu_virtdomain_param[] = {
62 mu_virtual_module_init (enum mu_gocs_op op, void *data) 63 { "passwd-dir", mu_c_string, &pwddir, 0, NULL,
63 { 64 N_("Name of the directory where virtual domain password files are "
64 if (op == mu_gocs_op_set && data) 65 "located."),
65 { 66 N_("dir") },
66 struct mu_gocs_virtual *p = data; 67 { NULL }
67 mu_virtual_module_config = *p; 68 };
68 }
69 return 0;
70 }
71 69
72 #if !HAVE_FGETPWENT 70 #if !HAVE_FGETPWENT
73 /* FIXME: A temporary solution. Need proper declaration in .h */ 71 /* FIXME: A temporary solution. Need proper declaration in .h */
...@@ -90,7 +88,7 @@ getpwnam_virtual (const char *u) ...@@ -90,7 +88,7 @@ getpwnam_virtual (const char *u)
90 if (delim == 0) 88 if (delim == 0)
91 return NULL; 89 return NULL;
92 90
93 filename = mu_make_file_name (mu_virtual_module_config.pwddir, &u[delim + 1]); 91 filename = mu_make_file_name (pwddir, &u[delim + 1]);
94 if (filename == NULL) 92 if (filename == NULL)
95 return NULL; 93 return NULL;
96 94
...@@ -191,28 +189,15 @@ mu_auth_virt_domain_by_name (struct mu_auth_data **return_data, ...@@ -191,28 +189,15 @@ mu_auth_virt_domain_by_name (struct mu_auth_data **return_data,
191 } 189 }
192 190
193 #else 191 #else
194 static int 192 # define mu_virtdomain_param NULL
195 mu_auth_virt_domain_by_name (struct mu_auth_data **return_data MU_ARG_UNUSED, 193 # define mu_auth_virt_domain_by_name NULL
196 const void *key MU_ARG_UNUSED,
197 void *func_data MU_ARG_UNUSED,
198 void *call_data MU_ARG_UNUSED)
199 {
200 return ENOSYS;
201 }
202 #endif 194 #endif
203 195
204 struct mu_auth_module mu_auth_virtual_module = { 196 struct mu_auth_module mu_auth_virtual_module = {
205 "virtdomain", 197 .name = "virtdomain",
206 #ifdef ENABLE_VIRTUAL_DOMAINS 198 .cfg = mu_virtdomain_param,
207 mu_virtual_module_init, 199 .handler = {
208 #else 200 [mu_auth_getpwnam] = mu_auth_virt_domain_by_name,
209 NULL, 201 }
210 #endif
211 mu_auth_nosupport,
212 NULL,
213 mu_auth_virt_domain_by_name,
214 NULL,
215 mu_auth_nosupport,
216 NULL
217 }; 202 };
218 203
......
1 *.la
2 *.lo
3 .deps
4 .libs
5 Makefile
6 Makefile.in
7 .gdbinit
1 # This file is part of GNU Mailutils
2 # Copyright (C) 2007, 2009-2012, 2014-2016 Free Software Foundation,
3 # Inc.
4 #
5 # GNU Mailutils is free software; you can redistribute it and/or
6 # modify it under the terms of the GNU General Public License as
7 # published by the Free Software Foundation; either version 3, or (at
8 # your option) any later version.
9 #
10 # GNU Mailutils is distributed in the hope that it will be useful, but
11 # WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 # General Public License for more details.
14 #
15 # You should have received a copy of the GNU General Public License
16 # along with GNU Mailutils. If not, see <http://www.gnu.org/licenses/>.
17
18 AM_CPPFLAGS = \
19 @MU_LIB_COMMON_INCLUDES@\
20 -DSITE_VIRTUAL_PWDDIR=\"@SITE_VIRTUAL_PWDDIR@\" \
21 -DSITE_CRAM_MD5_PWD=\"@SITE_CRAM_MD5_PWD@\"
22
23 lib_LTLIBRARIES = libmu_cfg.la
24 libmu_cfg_la_SOURCES=\
25 acl.c\
26 auth.c\
27 common.c\
28 init.c\
29 gsasl.c\
30 ldap.c\
31 pam.c\
32 radius.c\
33 sieve.c\
34 sql.c\
35 tls.c\
36 virtdomain.c
37
38 libmu_cfg_la_LDFLAGS=-version-info @VI_CURRENT@:@VI_REVISION@:@VI_AGE@
1 /* This file is part of GNU Mailutils
2 Copyright (C) 2007-2012, 2014-2016 Free Software Foundation, Inc.
3
4 GNU Mailutils is free software; you can redistribute it and/or
5 modify it under the terms of the GNU General Public License as
6 published by the Free Software Foundation; either version 3, or (at
7 your option) any later version.
8
9 GNU Mailutils is distributed in the hope that it will be useful, but
10 WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 General Public License for more details.
13
14 You should have received a copy of the GNU General Public License
15 along with GNU Mailutils. If not, see <http://www.gnu.org/licenses/>.
16 */
17
18 #ifdef HAVE_CONFIG_H
19 # include <config.h>
20 #endif
21 #include "mailutils/libcfg.h"
22 #include "mailutils/acl.h"
23 #include "mailutils/argcv.h"
24 #include "mailutils/cidr.h"
25 #include <stdlib.h>
26 #include <stdio.h>
27 #include <string.h>
28 #include <unistd.h>
29 #include <sys/time.h>
30 #include <sys/types.h>
31 #include <sys/socket.h>
32 #include <netinet/in.h>
33 #include <arpa/inet.h>
34
35 #define ISSPACE(c) ((c)==' '||(c)=='\t')
36
37 #define SKIPWS(p) while (*(p) && ISSPACE (*(p))) (p)++;
38
39 static const char *
40 getword (mu_config_value_t *val, int *pn)
41 {
42 int n = (*pn)++;
43 mu_config_value_t *v;
44
45 if (n >= val->v.arg.c)
46 {
47 mu_error (_("not enough arguments"));
48 return NULL;
49 }
50 v = &val->v.arg.v[n];
51 if (mu_cfg_assert_value_type (v, MU_CFG_STRING))
52 return NULL;
53 return v->v.string;
54 }
55
56 static int
57 parsearg (mu_config_value_t *val, struct mu_cidr *cidr, char **prest)
58 {
59 const char *w;
60 int n = 0;
61 int rc;
62
63 if (mu_cfg_assert_value_type (val, MU_CFG_ARRAY))
64 return 1;
65
66 w = getword (val, &n);
67 if (!w)
68 return 1;
69 if (strcmp (w, "from") == 0) {
70 w = getword (val, &n);
71 if (!w)
72 return 1;
73 }
74
75 if (strcmp (w, "any") == 0)
76 cidr->len = 0;
77 else
78 {
79 rc = mu_cidr_from_string (cidr, w);
80 if (rc)
81 {
82 mu_error (_("invalid source CIDR: %s"), mu_strerror (rc));
83 return 1;
84 }
85 }
86
87 if (prest)
88 {
89 if (n == val->v.arg.c)
90 *prest = NULL;
91 else
92 {
93 size_t size = 0;
94 int i;
95 char *buf;
96
97 for (i = n; i < val->v.arg.c; i++)
98 {
99 if (mu_cfg_assert_value_type (&val->v.arg.v[i], MU_CFG_STRING))
100 return 1;
101 size += strlen (val->v.arg.v[i].v.string) + 1;
102 }
103
104 buf = malloc (size);
105 if (!buf)
106 {
107 mu_error ("%s", mu_strerror (errno));
108 return 1;
109 }
110
111 *prest = buf;
112 for (i = n; i < val->v.arg.c; i++)
113 {
114 if (i > n)
115 *buf++ = ' ';
116 strcpy (buf, val->v.arg.v[i].v.string);
117 buf += strlen (buf);
118 }
119 *buf = 0;
120 }
121 }
122 else if (n != val->v.arg.c)
123 {
124 mu_error (_("junk after IP address"));
125 return 1;
126 }
127 return 0;
128 }
129
130 static int
131 cb_allow (void *data, mu_config_value_t *val)
132 {
133 int rc;
134 mu_acl_t acl = *(mu_acl_t*)data;
135 struct mu_cidr cidr;
136
137 if (parsearg (val, &cidr, NULL))
138 return 1;
139 rc = mu_acl_append (acl, mu_acl_accept, NULL, &cidr);
140 if (rc)
141 mu_error (_("cannot append acl entry: %s"), mu_strerror (rc));
142 return rc;
143 }
144
145 static int
146 cb_deny (void *data, mu_config_value_t *val)
147 {
148 int rc;
149 mu_acl_t acl = *(mu_acl_t*)data;
150 struct mu_cidr cidr;
151
152 if (parsearg (val, &cidr, NULL))
153 return 1;
154 rc = mu_acl_append (acl, mu_acl_deny, NULL, &cidr);
155 if (rc)
156 mu_error (_("cannot append acl entry: %s"), mu_strerror (rc));
157 return rc;
158 }
159
160 static int
161 cb_log (void *data, mu_config_value_t *val)
162 {
163 int rc;
164 mu_acl_t acl = *(mu_acl_t*)data;
165 struct mu_cidr cidr;
166 char *rest;
167
168 if (parsearg (val, &cidr, &rest))
169 return 1;
170 rc = mu_acl_append (acl, mu_acl_log, rest, &cidr);
171 if (rc)
172 mu_error (_("cannot append acl entry: %s"), mu_strerror (rc));
173 return rc;
174 }
175
176 static int
177 cb_exec (void *data, mu_config_value_t *val)
178 {
179 int rc;
180 mu_acl_t acl = *(mu_acl_t*)data;
181 struct mu_cidr cidr;
182 char *rest;
183
184 if (parsearg (val, &cidr, &rest))
185 return 1;
186 rc = mu_acl_append (acl, mu_acl_exec, rest, &cidr);
187 if (rc)
188 mu_error (_("cannot append acl entry: %s"), mu_strerror (rc));
189 return rc;
190 }
191
192 static int
193 cb_ifexec (void *data, mu_config_value_t *val)
194 {
195 int rc;
196 mu_acl_t acl = *(mu_acl_t*)data;
197 struct mu_cidr cidr;
198 char *rest;
199
200 if (parsearg (val, &cidr, &rest))
201 return 1;
202 rc = mu_acl_append (acl, mu_acl_ifexec, rest, &cidr);
203 if (rc)
204 mu_error (_("cannot append acl entry: %s"), mu_strerror (rc));
205 return rc;
206 }
207
208 static struct mu_cfg_param acl_param[] = {
209 { "allow", mu_cfg_callback, NULL, 0, cb_allow,
210 N_("Allow connections from this IP address. Optional word `from' is "
211 "allowed between it and its argument. The same holds true for other "
212 "actions below."),
213 N_("addr: IP") },
214 { "deny", mu_cfg_callback, NULL, 0, cb_deny,
215 N_("Deny connections from this IP address."),
216 N_("addr: IP") },
217 { "log", mu_cfg_callback, NULL, 0, cb_log,
218 N_("Log connections from this IP address."),
219 N_("addr: IP") },
220 { "exec", mu_cfg_callback, NULL, 0, cb_exec,
221 N_("Execute supplied program if a connection from this IP address is "
222 "requested. Arguments are:\n"
223 " <addr: IP> <program: string>\n"
224 "Following macros are expanded in <program> before executing:\n"
225 " address - Source IP address\n"
226 " port - Source port number\n") },
227 { "ifexec", mu_cfg_callback, NULL, 0, cb_ifexec,
228 N_("If a connection from this IP address is requested, execute supplied "
229 "program and allow or deny the connection depending on its exit code. "
230 "See `exec' for a description of its arguments.") },
231 { NULL }
232 };
233
234 static int
235 acl_section_parser (enum mu_cfg_section_stage stage,
236 const mu_cfg_node_t *node,
237 const char *section_label, void **section_data,
238 void *call_data,
239 mu_cfg_tree_t *tree)
240 {
241 switch (stage)
242 {
243 case mu_cfg_section_start:
244 {
245 void *data = *section_data;
246 mu_acl_create ((mu_acl_t*)data);
247 }
248 break;
249
250 case mu_cfg_section_end:
251 break;
252 }
253 return 0;
254 }
255
256 void
257 mu_acl_cfg_init ()
258 {
259 struct mu_cfg_section *section;
260 if (mu_create_canned_section ("acl", &section) == 0)
261 {
262 section->parser = acl_section_parser;
263 mu_cfg_section_add_params (section, acl_param);
264 }
265 }
1 /* This file is part of GNU Mailutils
2 Copyright (C) 2007-2008, 2010-2012, 2014-2016 Free Software
3 Foundation, Inc.
4
5 GNU Mailutils is free software; you can redistribute it and/or
6 modify it under the terms of the GNU General Public License as
7 published by the Free Software Foundation; either version 3, or (at
8 your option) any later version.
9
10 GNU Mailutils is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with GNU Mailutils. If not, see <http://www.gnu.org/licenses/>.
17 */
18
19 #ifdef HAVE_CONFIG_H
20 # include <config.h>
21 #endif
22 #include "mailutils/libcfg.h"
23 #include <mailutils/mu_auth.h>
24 #include <string.h>
25
26 /* FIXME: mu_auth.c should be reviewed */
27
28
29 /* ************************************************************************* */
30 /* Resource-style configuration */
31 /* ************************************************************************* */
32 static int
33 cb_authentication (void *data, mu_config_value_t *val)
34 {
35 if (val->type == MU_CFG_STRING)
36 {
37 if (strcmp (val->v.string, "clear") == 0)
38 mu_authentication_clear_list ();
39 else
40 /*FIXME: use err for error reporting*/
41 mu_authentication_add_module_list (val->v.string);
42 }
43 else if (val->type == MU_CFG_LIST)
44 {
45 int i;
46 for (i = 0; i < val->v.arg.c; i++)
47 {
48 if (mu_cfg_assert_value_type (&val->v.arg.v[i], MU_CFG_STRING))
49 return 1;
50 if (strcmp (val->v.arg.v[i].v.string, "clear") == 0)
51 mu_authentication_clear_list ();
52 else
53 mu_authentication_add_module (val->v.arg.v[i].v.string);
54 }
55 }
56 else
57 {
58 mu_error (_("expected string value"));
59 return 1;
60 }
61 return 0;
62 }
63
64 static int
65 cb_authorization (void *data, mu_config_value_t *val)
66 {
67 if (val->type == MU_CFG_STRING)
68 {
69 if (strcmp (val->v.string, "clear") == 0)
70 mu_authorization_clear_list ();
71 else
72 /*FIXME: use err for error reporting*/
73 mu_authorization_add_module_list (val->v.string);
74 }
75 else if (val->type == MU_CFG_LIST)
76 {
77 int i;
78 for (i = 0; i < val->v.arg.c; i++)
79 {
80 if (mu_cfg_assert_value_type (&val->v.arg.v[i], MU_CFG_STRING))
81 return 1;
82 if (strcmp (val->v.arg.v[i].v.string, "clear") == 0)
83 mu_authorization_clear_list ();
84 else
85 mu_authorization_add_module (val->v.arg.v[i].v.string);
86 }
87 }
88 else
89 {
90 mu_error (_("expected string value"));
91 return 1;
92 }
93 return 0;
94 }
95
96 static struct mu_cfg_param mu_auth_param[] = {
97 { "authentication", mu_cfg_callback, NULL, 0, cb_authentication,
98 /* FIXME: The description is incomplete. MU-list is also allowed as
99 argument */
100 N_("Set a list of modules for authentication. Modlist is a "
101 "colon-separated list of module names or a word `clear' to "
102 "clear the previously set up values."),
103 N_("modlist") },
104 { "authorization", mu_cfg_callback, NULL, 0, cb_authorization,
105 N_("Set a list of modules for authorization. Modlist is a "
106 "colon-separated list of module names or a word `clear' to "
107 "clear the previously set up values."),
108 N_("modlist") },
109 { NULL }
110 };
111
112 int
113 mu_auth_section_parser
114 (enum mu_cfg_section_stage stage, const mu_cfg_node_t *node,
115 const char *section_label, void **section_data, void *call_data,
116 mu_cfg_tree_t *tree)
117 {
118 switch (stage)
119 {
120 case mu_cfg_section_start:
121 break;
122
123 case mu_cfg_section_end:
124 mu_auth_finish_setup ();
125 }
126 return 0;
127 }
128
129 struct mu_cfg_capa mu_auth_cfg_capa = {
130 "auth", mu_auth_param, mu_auth_section_parser
131 };
1 /* This file is part of GNU Mailutils
2 Copyright (C) 2007-2012, 2014-2016 Free Software Foundation, Inc.
3
4 GNU Mailutils is free software; you can redistribute it and/or
5 modify it under the terms of the GNU General Public License as
6 published by the Free Software Foundation; either version 3, or (at
7 your option) any later version.
8
9 GNU Mailutils is distributed in the hope that it will be useful, but
10 WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 General Public License for more details.
13
14 You should have received a copy of the GNU General Public License
15 along with GNU Mailutils. If not, see <http://www.gnu.org/licenses/>.
16 */
17
18 #ifdef HAVE_CONFIG_H
19 # include <config.h>
20 #endif
21 #include <stdlib.h>
22 #include <string.h>
23 #include "mailutils/libcfg.h"
24 #include <mailutils/debug.h>
25 #include <mailutils/syslog.h>
26 #include <mailutils/mailbox.h>
27 #include <mailutils/io.h>
28 #include <mailutils/stream.h>
29 #include <mailutils/stdstream.h>
30
31 static struct mu_gocs_locking locking_settings;
32 static struct mu_gocs_mailbox mailbox_settings;
33 static struct mu_gocs_source_email address_settings;
34 static struct mu_gocs_mailer mailer_settings;
35 static struct mu_gocs_debug debug_settings;
36
37
38 /* ************************************************************************* */
39 /* Mailbox */
40 /* ************************************************************************* */
41
42 static int
43 _cb_folder (void *data, mu_config_value_t *val)
44 {
45 if (mu_cfg_assert_value_type (val, MU_CFG_STRING))
46 return 1;
47 mu_set_folder_directory (val->v.string);
48 return 0;
49 }
50
51 static struct mu_cfg_param mu_mailbox_param[] = {
52 { "mail-spool", mu_c_string, &mailbox_settings.mail_spool, 0, NULL,
53 N_("Use specified URL as a mailspool directory."),
54 N_("url") },
55 { "mailbox-pattern", mu_c_string, &mailbox_settings.mailbox_pattern,
56 0, NULL,
57 N_("Create mailbox URL using <pattern>."),
58 N_("pattern") },
59 { "mailbox-type", mu_c_string, &mailbox_settings.mailbox_type, 0, NULL,
60 N_("Default mailbox type."), N_("protocol") },
61 { "folder", mu_cfg_callback, NULL, 0, _cb_folder,
62 N_("Default user mail folder"),
63 N_("dir") },
64 { NULL }
65 };
66
67 DCL_CFG_CAPA (mailbox);
68
69
70 /* ************************************************************************* */
71 /* Locking */
72 /* ************************************************************************* */
73
74 static struct mu_cfg_param mu_locking_param[] = {
75 /* FIXME: Flags are superfluous. */
76 { "flags", mu_c_string, &locking_settings.lock_flags, 0, NULL,
77 N_("Default locker flags (E=external, R=retry, T=time, P=pid).") },
78 { "retry-timeout", mu_c_ulong, &locking_settings.lock_retry_timeout,
79 0, NULL,
80 N_("Set timeout for acquiring the lock.") },
81 { "retry-count", mu_c_ulong, &locking_settings.lock_retry_count, 0, NULL,
82 N_("Set the maximum number of times to retry acquiring the lock.") },
83 { "expire-timeout", mu_c_ulong, &locking_settings.lock_expire_timeout,
84 0, NULL,
85 N_("Expire locks older than this amount of time.") },
86 { "external-locker", mu_c_string, &locking_settings.external_locker,
87 0, NULL,
88 N_("Use external locker program."),
89 N_("prog") },
90 { NULL, }
91 };
92
93 DCL_CFG_CAPA (locking);
94
95
96 /* ************************************************************************* */
97 /* Address */
98 /* ************************************************************************* */
99
100 static struct mu_cfg_param mu_address_param[] = {
101 { "email-addr", mu_c_string, &address_settings.address, 0, NULL,
102 N_("Set the current user email address (default is "
103 "loginname@defaultdomain)."),
104 N_("email") },
105 { "email-domain", mu_c_string, &address_settings.domain, 0, NULL,
106 N_("Set e-mail domain for unqualified user names (default is this host)"),
107 N_("domain") },
108 { NULL }
109 };
110
111 DCL_CFG_CAPA (address);
112
113
114 /* ************************************************************************* */
115 /* Mailer */
116 /* ************************************************************************* */
117
118 static struct mu_cfg_param mu_mailer_param[] = {
119 { "url", mu_c_string, &mailer_settings.mailer, 0, NULL,
120 N_("Use this URL as the default mailer"),
121 N_("url") },
122 { NULL }
123 };
124
125 DCL_CFG_CAPA (mailer);
126
127
128 /* ************************************************************************* */
129 /* Logging */
130 /* ************************************************************************* */
131
132 static int
133 cb_facility (void *data, mu_config_value_t *val)
134 {
135 if (mu_cfg_assert_value_type (val, MU_CFG_STRING))
136 return 1;
137
138 if (mu_string_to_syslog_facility (val->v.string, &mu_log_facility))
139 {
140 mu_error (_("unknown syslog facility `%s'"), val->v.string);
141 return 1;
142 }
143 return 0;
144 }
145
146 static int
147 cb_severity (void *data, mu_config_value_t *val)
148 {
149 unsigned n;
150
151 if (mu_cfg_assert_value_type (val, MU_CFG_STRING))
152 return 1;
153 if (mu_severity_from_string (val->v.string, &n))
154 {
155 mu_error (_("unknown severity `%s'"), val->v.string);
156 return 1;
157 }
158 mu_log_severity_threshold = n;
159 return 0;
160 }
161
162 static struct mu_cfg_param mu_logging_param[] = {
163 { "syslog", mu_c_bool, &mu_log_syslog, 0, NULL,
164 N_("Send diagnostics to syslog.") },
165 { "print-severity", mu_c_bool, &mu_log_print_severity, 0, NULL,
166 N_("Print message severity levels.") },
167 { "severity", mu_cfg_callback, NULL, 0, cb_severity,
168 N_("Output only messages with a severity equal to or greater than "
169 "this one.") },
170 { "facility", mu_cfg_callback, NULL, 0, cb_facility,
171 N_("Set syslog facility. Arg is one of the following: user, daemon, "
172 "auth, authpriv, mail, cron, local0 through local7 (case-insensitive), "
173 "or a facility number.") },
174 { "session-id", mu_c_bool, &mu_log_session_id, 0, NULL,
175 N_("Log session ID") },
176 { "tag", mu_c_string, &mu_log_tag, 0, NULL,
177 N_("Tag syslog messages with this string.") },
178 { NULL }
179 };
180
181 static int logging_settings; /* Dummy variable */
182 DCL_CFG_CAPA (logging);
183
184
185 /* ************************************************************************* */
186 /* Debug */
187 /* ************************************************************************* */
188
189 static int
190 _cb2_debug_level (const char *arg, void *data MU_ARG_UNUSED)
191 {
192 mu_debug_parse_spec (arg);
193 return 0;
194 }
195
196 static int
197 cb_debug_level (void *data, mu_config_value_t *val)
198 {
199 return mu_cfg_string_value_cb (val, _cb2_debug_level, NULL);
200 }
201
202 static struct mu_cfg_param mu_debug_param[] = {
203 { "level", mu_cfg_callback, NULL, 0, &cb_debug_level,
204 N_("Set Mailutils debugging level. Argument is a colon-separated list "
205 "of debugging specifications in the form:\n"
206 " <object: string>[[:]=<level: number>].") },
207 { "line-info", mu_c_bool, &debug_settings.line_info, 0, NULL,
208 N_("Prefix debug messages with Mailutils source locations.") },
209 { NULL }
210 };
211
212 DCL_CFG_CAPA (debug);
213
1 /* This file is part of GNU Mailutils
2 Copyright (C) 2007, 2010-2012, 2014-2016 Free Software Foundation,
3 Inc.
4
5 GNU Mailutils is free software; you can redistribute it and/or
6 modify it under the terms of the GNU General Public License as
7 published by the Free Software Foundation; either version 3, or (at
8 your option) any later version.
9
10 GNU Mailutils is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with GNU Mailutils. If not, see <http://www.gnu.org/licenses/>.
17 */
18
19 #ifdef HAVE_CONFIG_H
20 # include <config.h>
21 #endif
22 #include <stdlib.h>
23 #include "mailutils/libcfg.h"
24 #include <mailutils/gsasl.h>
25
26 static struct mu_gsasl_module_data gsasl_settings;
27
28 static struct mu_cfg_param mu_gsasl_param[] = {
29 { "enable", mu_c_bool, &gsasl_settings.enable, 0, NULL,
30 N_("Enable GSASL (default)") },
31 { "cram-passwd", mu_c_string, &gsasl_settings.cram_md5_pwd, 0, NULL,
32 N_("Name of GSASL password file."),
33 N_("file") },
34 { "service", mu_c_string, &gsasl_settings.service, 0, NULL,
35 N_("SASL service name."),
36 N_("name") },
37 { "realm", mu_c_string, &gsasl_settings.realm, 0, NULL,
38 N_("SASL realm name."),
39 N_("name") },
40 { "hostname", mu_c_string, &gsasl_settings.hostname, 0, NULL,
41 N_("SASL host name."),
42 N_("name") },
43 { "anonymous-user", mu_c_string, &gsasl_settings.anon_user, 0, NULL,
44 N_("Anonymous user name."),
45 N_("name") },
46
47 { NULL }
48 };
49
50 DCL_CFG_CAPA (gsasl);
51
52
1 /* This file is part of GNU Mailutils
2 Copyright (C) 2007-2012, 2014-2016 Free Software Foundation, Inc.
3
4 GNU Mailutils is free software; you can redistribute it and/or
5 modify it under the terms of the GNU General Public License as
6 published by the Free Software Foundation; either version 3, or (at
7 your option) any later version.
8
9 GNU Mailutils is distributed in the hope that it will be useful, but
10 WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 General Public License for more details.
13
14 You should have received a copy of the GNU General Public License
15 along with GNU Mailutils. If not, see <http://www.gnu.org/licenses/>.
16 */
17
18 #ifdef HAVE_CONFIG_H
19 # include <config.h>
20 #endif
21 #define MU_CFG_COMPATIBILITY /* This source uses deprecated cfg interfaces */
22 #include "mailutils/libcfg.h"
23 #include <string.h>
24 #include <stdlib.h>
25
26 #define CFG_CAPA_MAX 512
27 static struct mu_cfg_capa *cfg_capa_table[CFG_CAPA_MAX] = {
28 #define S(c) &__mu_common_cat3__(mu_,c,_cfg_capa)
29 S (auth),
30 S (mailbox),
31 S (locking),
32 S (address),
33 S (mailer),
34 S (logging),
35 S (gsasl),
36 S (pam),
37 S (radius),
38 S (sql),
39 S (tls),
40 S (virtdomain),
41 S (sieve),
42 S (ldap),
43 S (debug),
44 NULL
45 };
46
47 static int cfg_capa_index = MU_ARRAY_SIZE(cfg_capa_table) - 1;
48
49 static struct mu_cfg_capa *
50 find_cfg_capa (const char *name)
51 {
52 int i;
53
54 for (i = 0; cfg_capa_table[i]; i++)
55 if (strcmp (cfg_capa_table[i]->name, name) == 0)
56 return cfg_capa_table[i];
57 return NULL;
58 }
59
60 static int
61 reserved_name (const char *name)
62 {
63 static char *reserved[] = { "common", NULL };
64 char **p;
65
66 if (name[0] == '.')
67 return 1;
68
69 for (p = reserved; *p; p++)
70 if (strcmp (name, *p) == 0)
71 return 1;
72 return 0;
73 }
74
75 int
76 mu_libcfg_register_capa (struct mu_cfg_capa *capa)
77 {
78 if (cfg_capa_index == CFG_CAPA_MAX)
79 return MU_ERR_NOENT;
80 cfg_capa_table[cfg_capa_index++] = capa;
81 return 0;
82 }
83
84 void
85 mu_libcfg_init (char **cnames)
86 {
87 int i;
88 for (i = 0; cnames[i]; i++)
89 {
90 if (!reserved_name (cnames[i]))
91 {
92 struct mu_cfg_capa *cp = find_cfg_capa (cnames[i]);
93 if (cp)
94 mu_config_root_register_section (NULL, cp->name, NULL,
95 cp->parser, cp->cfgparam);
96 #if 0
97 else
98 mu_error (_("unknown configuration group requested `%s'"),
99 cnames[i]);
100 #endif
101 }
102 }
103 }
104
105 int
106 mu_libcfg_parse_config (mu_cfg_tree_t **ptree)
107 {
108 struct mu_cfg_parse_hints hints;
109
110 memset (&hints, 0, sizeof (hints));
111
112 if (mu_cfg_parser_verbose)
113 hints.flags |= MU_PARSE_CONFIG_VERBOSE;
114 if (mu_cfg_parser_verbose > 1)
115 hints.flags |= MU_PARSE_CONFIG_DUMP;
116
117 if (mu_load_site_rcfile)
118 {
119 hints.flags |= MU_CFG_PARSE_SITE_RCFILE;
120 hints.site_rcfile = mu_site_rcfile;
121 }
122
123 if (mu_load_user_rcfile && mu_program_name)
124 {
125 hints.flags |= MU_CFG_PARSE_PROGRAM;
126 hints.program = (char*) mu_program_name;
127 }
128
129 if (mu_load_rcfile)
130 {
131 hints.flags |= MU_CFG_PARSE_CUSTOM_RCFILE;
132 hints.custom_rcfile = mu_load_rcfile;
133 }
134
135 return mu_cfg_parse_config (ptree, &hints);
136 }
137
138
139
140 /* FIXME: Deprecated */
141 int
142 mu_parse_config_files (struct mu_cfg_param *param, void *target)
143 {
144 int flags = 0;
145 int rc;
146
147 if (mu_cfg_parser_verbose)
148 flags |= MU_PARSE_CONFIG_VERBOSE;
149 if (mu_cfg_parser_verbose > 1)
150 flags |= MU_PARSE_CONFIG_DUMP;
151
152 if (mu_load_site_rcfile)
153 {
154 rc = mu_parse_config (mu_site_rcfile, mu_program_name, param,
155 flags | MU_PARSE_CONFIG_GLOBAL, target);
156 if (rc == ENOMEM)
157 {
158 mu_error ("%s", mu_strerror (rc));
159 return rc;
160 }
161 }
162
163 if (mu_load_user_rcfile && mu_program_name)
164 {
165 size_t size = 3 + strlen (mu_program_name) + 1;
166 char *file_name = malloc (size);
167 if (file_name)
168 {
169 strcpy (file_name, "~/.");
170 strcat (file_name, mu_program_name);
171
172 rc = mu_parse_config (file_name, mu_program_name, param, flags,
173 target);
174 if (rc == ENOMEM)
175 {
176 mu_error ("%s", mu_strerror (rc));
177 return rc;
178 }
179
180 free (file_name);
181 }
182 }
183
184 if (mu_load_rcfile)
185 {
186 rc = mu_parse_config (mu_load_rcfile, mu_program_name, param,
187 flags, target);
188 if (rc)
189 {
190 mu_error (_("errors parsing file %s: %s"), mu_load_rcfile,
191 mu_strerror (rc));
192 return rc;
193 }
194 }
195
196 return 0;
197 }
1 /* This file is part of GNU Mailutils
2 Copyright (C) 2007-2012, 2014-2016 Free Software Foundation, Inc.
3
4 GNU Mailutils is free software; you can redistribute it and/or
5 modify it under the terms of the GNU General Public License as
6 published by the Free Software Foundation; either version 3, or (at
7 your option) any later version.
8
9 GNU Mailutils is distributed in the hope that it will be useful, but
10 WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 General Public License for more details.
13
14 You should have received a copy of the GNU General Public License
15 along with GNU Mailutils. If not, see <http://www.gnu.org/licenses/>.
16 */
17
18 #ifdef HAVE_CONFIG_H
19 # include <config.h>
20 #endif
21 #include <stdlib.h>
22 #include "mailutils/libcfg.h"
23 #include "mailutils/util.h"
24 #include "mailutils/ldap.h"
25
26 static struct mu_ldap_module_config ldap_settings;
27
28 static int
29 _cb2_field_map (const char *arg, void *data)
30 {
31 int err;
32 int rc = mutil_parse_field_map (arg, &ldap_settings.field_map, &err);
33 if (rc)
34 /* FIXME: this message can be misleading */
35 mu_error (_("error near element %d: %s"), err, mu_strerror (rc));
36 return 0;
37 }
38
39 static int
40 cb_field_map (void *data, mu_config_value_t *val)
41 {
42 return mu_cfg_string_value_cb (val, _cb2_field_map, NULL);
43 }
44
45 static struct mu_cfg_param mu_ldap_param[] = {
46 { "enable", mu_c_bool, &ldap_settings.enable, 0, NULL,
47 N_("Enable LDAP lookups.") },
48 { "url", mu_c_string, &ldap_settings.url, 0, NULL,
49 N_("Set URL of the LDAP server."),
50 N_("url") },
51 { "base", mu_c_string, &ldap_settings.base, 0, NULL,
52 N_("Base DN for LDAP lookups."),
53 N_("dn") },
54 { "binddn", mu_c_string, &ldap_settings.binddn, 0, NULL,
55 N_("DN for accessing LDAP database."),
56 N_("dn") },
57 { "passwd", mu_c_string, &ldap_settings.passwd, 0, NULL,
58 N_("Password for use with binddn.") },
59 { "tls", mu_c_bool, &ldap_settings.tls, 0, NULL,
60 N_("Use TLS encryption.") },
61 { "debug", mu_c_int, &ldap_settings.debug, 0, NULL,
62 N_("Set LDAP debugging level.") },
63 { "field-map", mu_cfg_callback, NULL, 0, cb_field_map,
64 N_("Set a field-map for parsing LDAP replies. The map is a "
65 "column-separated list of definitions. Each definition has the "
66 "following form:\n"
67 " <name: string>=<attr: string>\n"
68 "where <name> is one of the following: name, passwd, uid, gid, "
69 "gecos, dir, shell, mailbox, quota, and <attr> is the name of "
70 "the corresponding LDAP attribute."),
71 N_("map") },
72 { "getpwnam", mu_c_string, &ldap_settings.getpwnam_filter, 0, NULL,
73 N_("LDAP filter to use for getpwnam requests."),
74 N_("filter") },
75 { "getpwuid", mu_c_string, &ldap_settings.getpwuid_filter, 0, NULL,
76 N_("LDAP filter to use for getpwuid requests."),
77 N_("filter") },
78 { NULL }
79 };
80
81 int
82 mu_ldap_section_parser
83 (enum mu_cfg_section_stage stage, const mu_cfg_node_t *node,
84 const char *section_label, void **section_data,
85 void *call_data, mu_cfg_tree_t *tree)
86 {
87 switch (stage)
88 {
89 case mu_cfg_section_start:
90 ldap_settings.enable = 1;
91 break;
92
93 case mu_cfg_section_end:
94 mu_gocs_store ("ldap", &ldap_settings);
95 }
96 return 0;
97 }
98
99 struct mu_cfg_capa mu_ldap_cfg_capa = {
100 "ldap", mu_ldap_param, mu_ldap_section_parser
101 };
1 /* This file is part of GNU Mailutils
2 Copyright (C) 2007, 2010-2012, 2014-2016 Free Software Foundation,
3 Inc.
4
5 GNU Mailutils is free software; you can redistribute it and/or
6 modify it under the terms of the GNU General Public License as
7 published by the Free Software Foundation; either version 3, or (at
8 your option) any later version.
9
10 GNU Mailutils is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with GNU Mailutils. If not, see <http://www.gnu.org/licenses/>.
17 */
18
19 #ifdef HAVE_CONFIG_H
20 # include <config.h>
21 #endif
22 #include <stdlib.h>
23 #include "mailutils/libcfg.h"
24
25 static char *pam_settings;
26
27 static struct mu_cfg_param mu_pam_param[] = {
28 { "service", mu_c_string, &pam_settings, 0, NULL,
29 N_("Set PAM service name."),
30 N_("name") },
31 { NULL }
32 };
33
34 DCL_CFG_CAPA (pam);
35
1 /* This file is part of GNU Mailutils
2 Copyright (C) 2007, 2010-2012, 2014-2016 Free Software Foundation,
3 Inc.
4
5 GNU Mailutils is free software; you can redistribute it and/or
6 modify it under the terms of the GNU General Public License as
7 published by the Free Software Foundation; either version 3, or (at
8 your option) any later version.
9
10 GNU Mailutils is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with GNU Mailutils. If not, see <http://www.gnu.org/licenses/>.
17 */
18
19 #ifdef HAVE_CONFIG_H
20 # include <config.h>
21 #endif
22 #include <stdlib.h>
23 #include "mailutils/libcfg.h"
24 #include <mailutils/radius.h>
25
26 static struct mu_radius_module_data radius_settings;
27
28 static struct mu_cfg_param mu_radius_param[] = {
29 { "auth", mu_c_string, &radius_settings.auth_request, 0, NULL,
30 N_("Radius request for authorization."),
31 N_("request") },
32 { "getpwnam", mu_c_string, &radius_settings.getpwnam_request, 0, NULL,
33 N_("Radius request for getpwnam."),
34 N_("request") },
35 { "getpwuid", mu_c_string, &radius_settings.getpwuid_request, 0, NULL,
36 N_("Radius request for getpwuid."),
37 N_("request") },
38 { "directory", mu_c_string, &radius_settings.config_dir, 0, NULL,
39 N_("Set radius configuration directory.") },
40 { NULL }
41 };
42
43 DCL_CFG_CAPA (radius);
1 /* This file is part of GNU Mailutils
2 Copyright (C) 2007-2008, 2010-2012, 2014-2016 Free Software
3 Foundation, Inc.
4
5 GNU Mailutils is free software; you can redistribute it and/or
6 modify it under the terms of the GNU General Public License as
7 published by the Free Software Foundation; either version 3, or (at
8 your option) any later version.
9
10 GNU Mailutils is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with GNU Mailutils. If not, see <http://www.gnu.org/licenses/>.
17 */
18
19 #ifdef HAVE_CONFIG_H
20 # include <config.h>
21 #endif
22 #include <stdlib.h>
23 #include "mailutils/libcfg.h"
24 #include <mailutils/sieve.h>
25
26 static struct mu_gocs_sieve sieve_settings;
27
28 static int
29 cb_clear_library_path (void *data, mu_config_value_t *val)
30 {
31 int flag;
32
33 if (mu_cfg_assert_value_type (val, MU_CFG_STRING))
34 return 1;
35 if (mu_str_to_c (val->v.string, mu_c_bool, &flag, NULL))
36 {
37 mu_error (_("not a boolean"));
38 return 1;
39 }
40 if (flag)
41 sieve_settings.clearflags |= MU_SIEVE_CLEAR_LIBRARY_PATH;
42 return 0;
43 }
44
45 static int
46 cb_clear_include_path (void *data, mu_config_value_t *val)
47 {
48 int flag;
49
50 if (mu_cfg_assert_value_type (val, MU_CFG_STRING))
51 return 1;
52 if (mu_str_to_c (val->v.string, mu_c_bool, &flag, NULL))
53 {
54 mu_error (_("not a boolean"));
55 return 1;
56 }
57 if (flag)
58 sieve_settings.clearflags |= MU_SIEVE_CLEAR_INCLUDE_PATH;
59 return 0;
60 }
61
62 static int
63 _add_path (const char *arg, void *data)
64 {
65 mu_list_t *plist = data;
66
67 if (!*plist)
68 {
69 int rc = mu_list_create (plist);
70 if (rc)
71 {
72 mu_error (_("cannot create list: %s"), mu_strerror (rc));
73 exit (1);
74 }
75 mu_list_set_destroy_item (*plist, mu_list_free_item);
76 }
77 return mu_string_split (arg, ":", *plist);
78 }
79
80 static int
81 cb_include_path (void *data, mu_config_value_t *val)
82 {
83 return mu_cfg_string_value_cb (val, _add_path,
84 &sieve_settings.include_path);
85 }
86
87 static int
88 cb_library_path (void *data, mu_config_value_t *val)
89 {
90 return mu_cfg_string_value_cb (val, _add_path,
91 &sieve_settings.library_path);
92 }
93
94 static int
95 cb_library_path_prefix (void *data, mu_config_value_t *val)
96 {
97 return mu_cfg_string_value_cb (val, _add_path,
98 &sieve_settings.library_path_prefix);
99 }
100
101 static struct mu_cfg_param mu_sieve_param[] = {
102 { "clear-library-path", mu_cfg_callback, NULL, 0, cb_clear_library_path,
103 N_("Clear library search path.") },
104 { "clear-include-path", mu_cfg_callback, NULL, 0, cb_clear_include_path,
105 N_("Clear include search path.") },
106 { "library-path", mu_cfg_callback, NULL, 0, cb_library_path,
107 N_("Add directories to the library search path. Argument is a "
108 "colon-separated list of directories."),
109 N_("list") },
110 { "library-path-prefix", mu_cfg_callback, NULL, 0, cb_library_path_prefix,
111 N_("Add directories to the beginning of the library search path. "
112 "Argument is a colon-separated list of directories."),
113 N_("list") },
114 { "include-path", mu_cfg_callback, NULL, 0, cb_include_path,
115 N_("Add directories to the include search path. Argument is a "
116 "colon-separated list of directories."),
117 N_("list") },
118 { NULL }
119 };
120
121 DCL_CFG_CAPA (sieve);
1 /* This file is part of GNU Mailutils
2 Copyright (C) 2007-2012, 2014-2016 Free Software Foundation, Inc.
3
4 GNU Mailutils is free software; you can redistribute it and/or
5 modify it under the terms of the GNU General Public License as
6 published by the Free Software Foundation; either version 3, or (at
7 your option) any later version.
8
9 GNU Mailutils is distributed in the hope that it will be useful, but
10 WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 General Public License for more details.
13
14 You should have received a copy of the GNU General Public License
15 along with GNU Mailutils. If not, see <http://www.gnu.org/licenses/>.
16 */
17
18 #ifdef HAVE_CONFIG_H
19 # include <config.h>
20 #endif
21 #include <stdlib.h>
22 #include "mailutils/libcfg.h"
23 #include <mailutils/sql.h>
24 #include <mailutils/util.h>
25
26 static struct mu_sql_module_config sql_settings;
27
28
29
30 /* Resource file configuration */
31 static int
32 cb_password_type (void *data, mu_config_value_t *val)
33 {
34 if (mu_cfg_assert_value_type (val, MU_CFG_STRING))
35 return 1;
36
37 if (mu_sql_decode_password_type (val->v.string, &sql_settings.password_type))
38 mu_error (_("unknown password type `%s'"), val->v.string);
39 return 0;
40 }
41
42 static int
43 _cb2_field_map (const char *arg, void *data)
44 {
45 int err;
46 int rc = mutil_parse_field_map (arg, &sql_settings.field_map, &err);
47 if (rc)
48 /* FIXME: this message may be misleading */
49 mu_error (_("error near element %d: %s"), err, mu_strerror (rc));
50 return 0;
51 }
52
53 static int
54 cb_field_map (void *data, mu_config_value_t *val)
55 {
56 return mu_cfg_string_value_cb (val, _cb2_field_map, NULL);
57 }
58
59 static struct mu_cfg_param mu_sql_param[] = {
60 { "interface", mu_c_string, &sql_settings.interface, 0, NULL,
61 N_("Set SQL interface to use (one of: mysql, odbc, or postgres).") },
62 { "getpwnam", mu_c_string, &sql_settings.getpwnam_query, 0, NULL,
63 N_("SQL query to use for getpwnam requests."),
64 N_("query") },
65 { "getpwuid", mu_c_string, &sql_settings.getpwuid_query, 0, NULL,
66 N_("SQL query to use for getpwuid requests."),
67 N_("query") },
68 { "getpass", mu_c_string, &sql_settings.getpass_query, 0, NULL,
69 N_("SQL query returning the user's password."),
70 N_("query") },
71 { "host", mu_c_string, &sql_settings.host, 0, NULL,
72 N_("SQL server host name.") },
73 { "user", mu_c_string, &sql_settings.user, 0, NULL,
74 N_("SQL user name.") },
75 { "passwd", mu_c_string, &sql_settings.passwd, 0, NULL,
76 N_("Password for the SQL user.") },
77 { "port", mu_c_int, &sql_settings.port, 0, NULL,
78 N_("SQL server port.") },
79 { "db", mu_c_string, &sql_settings.db, 0, NULL,
80 N_("Database name.") },
81 { "password-type", mu_cfg_callback, NULL, 0, cb_password_type,
82 N_("Type of password returned by getpass query (one of: plain, hash, "
83 "scrambled).") },
84 { "positional", mu_c_bool, &sql_settings.positional, 0, NULL,
85 N_("Use positional (v1.0 compatible) field interface.") },
86 { "field-map", mu_cfg_callback, NULL, 0, cb_field_map,
87 N_("Set a field-map for parsing SQL replies. The map is a "
88 "column-separated list of definitions. Each definition has the "
89 "following form:\n"
90 " <name: string>=<column: string>\n"
91 "where <name> is one of the following: name, passwd, uid, gid, "
92 "gecos, dir, shell, mailbox, quota, and <column> is the name of "
93 "the corresponding SQL column."),
94 N_("map") },
95 { NULL }
96 };
97
98 DCL_CFG_CAPA (sql);
99
100
1 /* This file is part of GNU Mailutils
2 Copyright (C) 2007-2008, 2010-2012, 2014-2016 Free Software
3 Foundation, Inc.
4
5 GNU Mailutils is free software; you can redistribute it and/or
6 modify it under the terms of the GNU General Public License as
7 published by the Free Software Foundation; either version 3, or (at
8 your option) any later version.
9
10 GNU Mailutils is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with GNU Mailutils. If not, see <http://www.gnu.org/licenses/>.
17 */
18
19 #ifdef HAVE_CONFIG_H
20 # include <config.h>
21 #endif
22 #include <stdlib.h>
23 #include "mailutils/libcfg.h"
24 #include <mailutils/tls.h>
25 #include <mailutils/util.h>
26 #include <mailutils/kwd.h>
27
28 #define SSL_CERT_FILE_CHECKS (MU_FILE_SAFETY_GROUP_WRITABLE | \
29 MU_FILE_SAFETY_GROUP_WRITABLE | \
30 MU_FILE_SAFETY_LINKED_WRDIR)
31
32 #define SSL_KEY_FILE_CHECKS (MU_FILE_SAFETY_ALL & ~MU_FILE_SAFETY_OWNER_MISMATCH)
33
34 #define SSL_CA_FILE_CHECKS (MU_FILE_SAFETY_GROUP_WRITABLE | \
35 MU_FILE_SAFETY_GROUP_WRITABLE | \
36 MU_FILE_SAFETY_LINKED_WRDIR)
37
38 static struct mu_tls_module_config tls_settings = {
39 1, /* enabled by default */
40
41 NULL, /* Certificate file */
42 SSL_CERT_FILE_CHECKS,
43
44 NULL, /* Key file */
45 SSL_KEY_FILE_CHECKS, /* Stringent safety checks for keys */
46
47 NULL, /* CA file */
48 SSL_CA_FILE_CHECKS
49 };
50
51 static int
52 cb2_safety_checks (const char *name, void *data)
53 {
54 int defval;
55
56 if (data == &tls_settings.ssl_key_safety_checks)
57 defval = SSL_KEY_FILE_CHECKS;
58 else if (data == &tls_settings.ssl_cert_safety_checks)
59 defval = SSL_CERT_FILE_CHECKS;
60 else if (data == &tls_settings.ssl_cafile_safety_checks)
61 defval = SSL_CA_FILE_CHECKS;
62 else
63 {
64 mu_error (_("INTERNAL ERROR at %s:%d: unknown default value?"),
65 __FILE__, __LINE__);
66 defval = MU_FILE_SAFETY_ALL;
67 }
68 if (mu_file_safety_compose (data, name, defval))
69 mu_error (_("unknown keyword: %s"), name);
70 return 0;
71 }
72
73 static int
74 cb_safety_checks (void *data, mu_config_value_t *arg)
75 {
76 return mu_cfg_string_value_cb (arg, cb2_safety_checks, data);
77 }
78
79 static struct mu_cfg_param mu_tls_param[] = {
80 { "enable", mu_c_bool, &tls_settings.enable, 0, NULL,
81 N_("Enable TLS encryption.") },
82 { "ssl-cert", mu_c_string, &tls_settings.ssl_cert, 0, NULL,
83 N_("Specify SSL certificate file."),
84 N_("file") },
85 { "ssl-key", mu_c_string, &tls_settings.ssl_key, 0, NULL,
86 N_("Specify SSL certificate key file."),
87 N_("file") },
88 { "ssl-cafile", mu_c_string, &tls_settings.ssl_cafile, 0, NULL,
89 N_("Specify trusted CAs file."),
90 N_("file") },
91 { "ssl-priorities", mu_c_string, &tls_settings.priorities, 0, NULL,
92 N_("Set the priorities to use on the ciphers, key exchange methods, "
93 "macs and compression methods."),
94 NULL },
95 { "key-file-safety-checks", mu_cfg_callback,
96 &tls_settings.ssl_key_safety_checks, 0,
97 cb_safety_checks,
98 N_("Configure safety checks for SSL key file. Argument is a list or "
99 "sequence of check names optionally prefixed with '+' to enable or "
100 "'-' to disable the corresponding check. Valid check names are:\n"
101 "\n"
102 " none disable all checks\n"
103 " all enable all checks\n"
104 " gwrfil forbid group writable files\n"
105 " awrfil forbid world writable files\n"
106 " grdfil forbid group readable files\n"
107 " ardfil forbid world writable files\n"
108 " linkwrdir forbid symbolic links in group or world writable directories\n"
109 " gwrdir forbid files in group writable directories\n"
110 " awrdir forbid files in world writable directories\n"),
111 N_("arg: list") },
112 { "cert-file-safety-checks", mu_cfg_callback,
113 &tls_settings.ssl_cert_safety_checks, 0,
114 cb_safety_checks,
115 N_("Configure safety checks for SSL certificate. See above for a description of <arg>."),
116 N_("arg: list") },
117 { "ca-file-safety-checks", mu_cfg_callback,
118 &tls_settings.ssl_cafile_safety_checks, 0,
119 cb_safety_checks,
120 N_("Configure safety checks for SSL certificate authority file. See above for a description of <arg>."),
121 N_("arg: list") },
122 { NULL }
123 };
124
125 DCL_CFG_CAPA (tls);
126
1 /* This file is part of GNU Mailutils
2 Copyright (C) 2007, 2010-2012, 2014-2016 Free Software Foundation,
3 Inc.
4
5 GNU Mailutils is free software; you can redistribute it and/or
6 modify it under the terms of the GNU General Public License as
7 published by the Free Software Foundation; either version 3, or (at
8 your option) any later version.
9
10 GNU Mailutils is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with GNU Mailutils. If not, see <http://www.gnu.org/licenses/>.
17 */
18
19 #ifdef HAVE_CONFIG_H
20 # include <config.h>
21 #endif
22 #include <stdlib.h>
23 #include "mailutils/libcfg.h"
24
25 static struct mu_gocs_virtual virtdomain_settings;
26
27 static struct mu_cfg_param mu_virtdomain_param[] = {
28 { "passwd-dir", mu_c_string, &virtdomain_settings, 0, NULL,
29 N_("Name of the directory where virtual domain password files are "
30 "located."),
31 N_("dir") },
32 { NULL }
33 };
34
35 DCL_CFG_CAPA (virtdomain);
36
...@@ -29,9 +29,6 @@ mu_list_t mu_sieve_library_path = NULL; ...@@ -29,9 +29,6 @@ mu_list_t mu_sieve_library_path = NULL;
29 mu_list_t mu_sieve_library_path_prefix = NULL; 29 mu_list_t mu_sieve_library_path_prefix = NULL;
30 mu_debug_handle_t mu_sieve_debug_handle; 30 mu_debug_handle_t mu_sieve_debug_handle;
31 31
32 //FIXME: provide definition (from gocs.h)
33 static struct mu_gocs_sieve sieve_settings;
34
35 void 32 void
36 mu_sieve_debug_init (void) 33 mu_sieve_debug_init (void)
37 { 34 {
...@@ -39,6 +36,15 @@ mu_sieve_debug_init (void) ...@@ -39,6 +36,15 @@ mu_sieve_debug_init (void)
39 mu_sieve_debug_handle = mu_debug_register_category ("sieve"); 36 mu_sieve_debug_handle = mu_debug_register_category ("sieve");
40 } 37 }
41 38
39 struct sieve_settings
40 {
41 int clearflags;
42 mu_list_t include_path;
43 mu_list_t library_path_prefix;
44 mu_list_t library_path;
45 };
46 static struct sieve_settings sieve_settings;
47
42 /*FIXME: REMOVE BEGIN */ 48 /*FIXME: REMOVE BEGIN */
43 static int 49 static int
44 _path_append (void *item, void *data) 50 _path_append (void *item, void *data)
...@@ -61,33 +67,6 @@ _path_append (void *item, void *data) ...@@ -61,33 +67,6 @@ _path_append (void *item, void *data)
61 return mu_list_append (*plist, p); 67 return mu_list_append (*plist, p);
62 } 68 }
63 69
64 int
65 mu_sieve_module_init (enum mu_gocs_op op, void *data)
66 {
67 struct mu_gocs_sieve *p;
68 if (!(op == mu_gocs_op_set && data))
69 return 0;
70 p = data;
71
72 if (p->clearflags & MU_SIEVE_CLEAR_INCLUDE_PATH)
73 mu_list_destroy (&mu_sieve_include_path);
74 mu_list_foreach (p->include_path, _path_append, &mu_sieve_include_path);
75 if (p->clearflags & MU_SIEVE_CLEAR_LIBRARY_PATH)
76 {
77 mu_list_destroy (&mu_sieve_library_path);
78 mu_list_destroy (&mu_sieve_library_path_prefix);
79 }
80 mu_list_foreach (p->library_path_prefix, _path_append,
81 &mu_sieve_library_path_prefix);
82 mu_list_foreach (p->library_path, _path_append, &mu_sieve_library_path);
83 mu_list_destroy (&p->library_path);
84 mu_list_destroy (&p->library_path_prefix);
85 mu_list_destroy (&p->include_path);
86 mu_sieve_debug_init ();
87 return 0;
88 }
89 /* FIXME: REMOVE END */
90
91 static int 70 static int
92 cb_clear_library_path (void *data, mu_config_value_t *val) 71 cb_clear_library_path (void *data, mu_config_value_t *val)
93 { 72 {
...@@ -238,9 +217,30 @@ static struct mu_option sieve_option[] = { ...@@ -238,9 +217,30 @@ static struct mu_option sieve_option[] = {
238 MU_OPTION_END 217 MU_OPTION_END
239 }; 218 };
240 219
220 static void
221 sieve_commit (void *ptr)
222 {
223 if (sieve_settings.clearflags & MU_SIEVE_CLEAR_INCLUDE_PATH)
224 mu_list_destroy (&mu_sieve_include_path);
225 mu_list_foreach (sieve_settings.include_path, _path_append, &mu_sieve_include_path);
226 if (sieve_settings.clearflags & MU_SIEVE_CLEAR_LIBRARY_PATH)
227 {
228 mu_list_destroy (&mu_sieve_library_path);
229 mu_list_destroy (&mu_sieve_library_path_prefix);
230 }
231 mu_list_foreach (sieve_settings.library_path_prefix, _path_append,
232 &mu_sieve_library_path_prefix);
233 mu_list_foreach (sieve_settings.library_path, _path_append, &mu_sieve_library_path);
234 mu_list_destroy (&sieve_settings.library_path);
235 mu_list_destroy (&sieve_settings.library_path_prefix);
236 mu_list_destroy (&sieve_settings.include_path);
237 mu_sieve_debug_init ();
238 }
239
241 struct mu_cli_capa mu_cli_capa_sieve = { 240 struct mu_cli_capa mu_cli_capa_sieve = {
242 "sieve", 241 "sieve",
243 sieve_option, 242 sieve_option,
244 mu_sieve_param, 243 mu_sieve_param,
245 NULL, NULL 244 NULL,
245 sieve_commit
246 }; 246 };
......
...@@ -270,7 +270,6 @@ static char *capa[] = { ...@@ -270,7 +270,6 @@ static char *capa[] = {
270 "locking", 270 "locking",
271 "mailer", 271 "mailer",
272 "sieve", 272 "sieve",
273 "tls",
274 NULL 273 NULL
275 }; 274 };
276 275
...@@ -553,7 +552,7 @@ main (int argc, char *argv[]) ...@@ -553,7 +552,7 @@ main (int argc, char *argv[])
553 mu_log_print_severity = 1; 552 mu_log_print_severity = 1;
554 553
555 /* Parse command line */ 554 /* Parse command line */
556 mu_cli_capa_register (&mu_cli_capa_tls); 555
557 mu_cli_capa_register (&mu_cli_capa_sieve); 556 mu_cli_capa_register (&mu_cli_capa_sieve);
558 mu_cli (argc, argv, &cli, capa, NULL, &argc, &argv); 557 mu_cli (argc, argv, &cli, capa, NULL, &argc, &argv);
559 558
......
...@@ -17,6 +17,7 @@ ...@@ -17,6 +17,7 @@
17 17
18 #include "mail.h" 18 #include "mail.h"
19 #include "mailutils/cli.h" 19 #include "mailutils/cli.h"
20 #include "mailutils/mu_auth.h"
20 21
21 /* Global variables and constants*/ 22 /* Global variables and constants*/
22 mu_mailbox_t mbox; /* Mailbox being operated upon */ 23 mu_mailbox_t mbox; /* Mailbox being operated upon */
...@@ -240,7 +241,6 @@ static char *mail_capa[] = { ...@@ -240,7 +241,6 @@ static char *mail_capa[] = {
240 "debug", 241 "debug",
241 "mailbox", 242 "mailbox",
242 "locking", 243 "locking",
243 "tls",
244 NULL 244 NULL
245 }; 245 };
246 246
...@@ -368,6 +368,8 @@ main (int argc, char **argv) ...@@ -368,6 +368,8 @@ main (int argc, char **argv)
368 /* Register the desired formats. */ 368 /* Register the desired formats. */
369 mu_register_all_formats (); 369 mu_register_all_formats ();
370 370
371 mu_auth_register_module (&mu_auth_tls_module);
372
371 interactive = isatty (fileno (stdin)); 373 interactive = isatty (fileno (stdin));
372 #ifdef HAVE_SIGACTION 374 #ifdef HAVE_SIGACTION
373 { 375 {
...@@ -417,7 +419,6 @@ main (int argc, char **argv) ...@@ -417,7 +419,6 @@ main (int argc, char **argv)
417 MOPTF_OVERWRITE); 419 MOPTF_OVERWRITE);
418 420
419 /* argument parsing */ 421 /* argument parsing */
420 mu_cli_capa_register (&mu_cli_capa_tls);
421 mu_cli (argc, argv, &cli, mail_capa, NULL, &argc, &argv); 422 mu_cli (argc, argv, &cli, mail_capa, NULL, &argc, &argv);
422 423
423 if ((hint & (HINT_SEND_MODE|HINT_FILE_OPTION)) == 424 if ((hint & (HINT_SEND_MODE|HINT_FILE_OPTION)) ==
......
...@@ -41,7 +41,6 @@ static char *capa[] = { ...@@ -41,7 +41,6 @@ static char *capa[] = {
41 "debug", 41 "debug",
42 "mailbox", 42 "mailbox",
43 "locking", 43 "locking",
44 "tls",
45 NULL 44 NULL
46 }; 45 };
47 46
...@@ -65,7 +64,7 @@ main (int argc, char **argv) ...@@ -65,7 +64,7 @@ main (int argc, char **argv)
65 /* register the formats. */ 64 /* register the formats. */
66 mu_register_all_mbox_formats (); 65 mu_register_all_mbox_formats ();
67 66
68 mu_cli_capa_register (&mu_cli_capa_tls); 67 mu_auth_register_module (&mu_auth_tls_module);
69 mu_cli (argc, argv, &cli, capa, NULL, &argc, &argv); 68 mu_cli (argc, argv, &cli, capa, NULL, &argc, &argv);
70 69
71 if (argc == 0 && messages_count (NULL) < 0) 70 if (argc == 0 && messages_count (NULL) < 0)
......
...@@ -843,10 +843,10 @@ main (int argc, char **argv) ...@@ -843,10 +843,10 @@ main (int argc, char **argv)
843 843
844 /* Register the desired "mailbox" formats. */ 844 /* Register the desired "mailbox" formats. */
845 mu_register_all_formats (); 845 mu_register_all_formats ();
846 /* Register authentication modules */
847 mu_auth_register_module (&mu_auth_tls_module);
846 848
847 /* argument parsing */ 849 /* argument parsing */
848
849 mu_cli_capa_register (&mu_cli_capa_tls);
850 mu_cli (argc, argv, &cli, movemail_capa, NULL, &argc, &argv); 850 mu_cli (argc, argv, &cli, movemail_capa, NULL, &argc, &argv);
851 851
852 if (argc < 2 || argc > 3) 852 if (argc < 2 || argc > 3)
......
...@@ -75,7 +75,7 @@ mailutils_SOURCES = \ ...@@ -75,7 +75,7 @@ mailutils_SOURCES = \
75 $(MODULES) 75 $(MODULES)
76 76
77 mailutils_LDADD = \ 77 mailutils_LDADD = \
78 ${MU_APP_LIBRARIES}\ 78 ${MU_APP_NEW_LIBRARIES}\
79 ${MU_LIB_MBOX}\ 79 ${MU_LIB_MBOX}\
80 ${MU_LIB_IMAP}\ 80 ${MU_LIB_IMAP}\
81 ${MU_LIB_POP}\ 81 ${MU_LIB_POP}\
......
...@@ -14,63 +14,24 @@ ...@@ -14,63 +14,24 @@
14 You should have received a copy of the GNU General Public License 14 You should have received a copy of the GNU General Public License
15 along with GNU Mailutils. If not, see <http://www.gnu.org/licenses/>. */ 15 along with GNU Mailutils. If not, see <http://www.gnu.org/licenses/>. */
16 16
17 #if defined(HAVE_CONFIG_H)
18 # include <config.h>
19 #endif
20 #include <stdlib.h>
21 #include <string.h>
22 #include <sys/socket.h>
23 #include <netinet/in.h>
24 #include <sys/un.h>
25 #include <arpa/inet.h>
26 #include <mailutils/mailutils.h>
27 #include <mailutils/libcfg.h>
28 #include "argp.h"
29 #include "mu.h" 17 #include "mu.h"
30 18
31 static char acl_doc[] = N_("mu acl - test access control lists.");
32 char acl_docstring[] = N_("test access control lists"); 19 char acl_docstring[] = N_("test access control lists");
33 static char acl_args_doc[] = N_("ADDRESS [ADDRESS...]"); 20 static char acl_args_doc[] = N_("ADDRESS [ADDRESS...]");
34 21
35 static struct argp_option acl_options[] = {
36 { "file", 'f', N_("FILE"), 0, N_("read ACLs from FILE") },
37 { "path", 'p', N_("PATH"), 0,
38 N_("path to the ACL in the configuration tree") },
39 { NULL }
40 };
41
42 static char *input_file_name; 22 static char *input_file_name;
43 static struct mu_sockaddr *target_sa; 23 static struct mu_sockaddr *target_sa;
44 static mu_acl_t acl; 24 static mu_acl_t acl;
45 static const char *path = "acl"; 25 static const char *path = "acl";
46 26
47 static error_t 27 static struct mu_option acl_options[] = {
48 acl_parse_opt (int key, char *arg, struct argp_state *state) 28 { "file", 'f', N_("FILE"), MU_OPTION_DEFAULT,
49 { 29 N_("read ACLs from FILE"),
50 switch (key) 30 mu_c_string, &input_file_name },
51 { 31 { "path", 'p', N_("PATH"), MU_OPTION_DEFAULT,
52 case 'f': 32 N_("path to the ACL in the configuration tree"),
53 input_file_name = arg; 33 mu_c_string, &path },
54 break; 34 { NULL }
55
56 case 'p':
57 path = arg;
58 break;
59
60 default:
61 return ARGP_ERR_UNKNOWN;
62 }
63 return 0;
64 }
65
66 static struct argp acl_argp = {
67 acl_options,
68 acl_parse_opt,
69 acl_args_doc,
70 acl_doc,
71 NULL,
72 NULL,
73 NULL
74 }; 35 };
75 36
76 37
...@@ -82,16 +43,13 @@ static struct mu_cfg_param acl_cfg_param[] = { ...@@ -82,16 +43,13 @@ static struct mu_cfg_param acl_cfg_param[] = {
82 int 43 int
83 mutool_acl (int argc, char **argv) 44 mutool_acl (int argc, char **argv)
84 { 45 {
85 int rc, index; 46 int rc;
86 mu_acl_result_t result; 47 mu_acl_result_t result;
87 mu_cfg_tree_t *tree = NULL, *temp_tree = NULL; 48 mu_cfg_tree_t *tree = NULL, *temp_tree = NULL;
88 mu_cfg_node_t *node; 49 mu_cfg_node_t *node;
50 struct mu_cfg_parse_hints hints;
89 51
90 if (argp_parse (&acl_argp, argc, argv, ARGP_IN_ORDER, &index, NULL)) 52 mu_action_getopt (&argc, &argv, acl_options, acl_docstring, acl_args_doc);
91 return 1;
92
93 argc -= index;
94 argv += index;
95 53
96 if (argc == 0) 54 if (argc == 0)
97 { 55 {
...@@ -99,16 +57,13 @@ mutool_acl (int argc, char **argv) ...@@ -99,16 +57,13 @@ mutool_acl (int argc, char **argv)
99 return 1; 57 return 1;
100 } 58 }
101 59
102 if (input_file_name) 60 memset (&hints, 0, sizeof (hints));
103 { 61 hints.flags = MU_CFG_PARSE_CUSTOM_RCFILE;
104 mu_load_site_rcfile = 0; 62 hints.custom_rcfile = input_file_name;
105 mu_load_user_rcfile = 0;
106 mu_load_rcfile = input_file_name;
107 }
108 63
109 mu_acl_cfg_init (); 64 mu_acl_cfg_init ();
110 if (mu_libcfg_parse_config (&tree)) 65 if (mu_cfg_parse_config (&tree, &hints))
111 return 1; 66 exit (EX_CONFIG);
112 if (!tree) 67 if (!tree)
113 return 0; 68 return 0;
114 69
......
...@@ -14,32 +14,19 @@ ...@@ -14,32 +14,19 @@
14 You should have received a copy of the GNU General Public License 14 You should have received a copy of the GNU General Public License
15 along with GNU Mailutils. If not, see <http://www.gnu.org/licenses/>. */ 15 along with GNU Mailutils. If not, see <http://www.gnu.org/licenses/>. */
16 16
17 #if defined(HAVE_CONFIG_H) 17 #include "mu.h"
18 # include <config.h>
19 #endif
20 #include <stdlib.h>
21 #include <mailutils/mailutils.h>
22 #include <mailutils/libcfg.h>
23 #include <argp.h>
24
25 static char cflags_doc[] = N_("mu cflags - show compiler options");
26 char cflags_docstring[] = N_("show compiler options");
27 18
28 static struct argp cflags_argp = { 19 char cflags_docstring[] = N_("show compiler options");
29 NULL,
30 NULL,
31 NULL,
32 cflags_doc,
33 NULL,
34 NULL,
35 NULL
36 };
37 20
38 int 21 int
39 mutool_cflags (int argc, char **argv) 22 mutool_cflags (int argc, char **argv)
40 { 23 {
41 if (argp_parse (&cflags_argp, argc, argv, ARGP_IN_ORDER, NULL, NULL)) 24 mu_action_getopt (&argc, &argv, NULL, cflags_docstring, NULL);
42 return 1; 25 if (argc)
26 {
27 mu_error (_("too many arguments"));
28 return EX_USAGE;
29 }
43 mu_printf ("%s\n", COMPILE_FLAGS); 30 mu_printf ("%s\n", COMPILE_FLAGS);
44 return 0; 31 return 0;
45 } 32 }
......
...@@ -14,21 +14,12 @@ ...@@ -14,21 +14,12 @@
14 You should have received a copy of the GNU General Public License 14 You should have received a copy of the GNU General Public License
15 along with GNU Mailutils. If not, see <http://www.gnu.org/licenses/>. */ 15 along with GNU Mailutils. If not, see <http://www.gnu.org/licenses/>. */
16 16
17 #if defined(HAVE_CONFIG_H) 17 #include "mu.h"
18 # include <config.h> 18 #include <mailutils/dbm.h>
19 #endif
20 #include <sys/types.h>
21 #include <sys/stat.h>
22 #include <stdlib.h>
23 #include <string.h>
24 #include <grp.h>
25 #include <sysexits.h>
26 #include <fnmatch.h> 19 #include <fnmatch.h>
27 #include <regex.h> 20 #include <regex.h>
28 #include <mailutils/mailutils.h> 21 #include <sys/stat.h>
29 #include <mailutils/dbm.h> 22 #include <grp.h>
30 #include "argp.h"
31 #include "mu.h"
32 23
33 static char dbm_doc[] = N_("mu dbm - DBM management tool\n" 24 static char dbm_doc[] = N_("mu dbm - DBM management tool\n"
34 "Valid COMMANDs are:\n" 25 "Valid COMMANDs are:\n"
...@@ -39,6 +30,7 @@ static char dbm_doc[] = N_("mu dbm - DBM management tool\n" ...@@ -39,6 +30,7 @@ static char dbm_doc[] = N_("mu dbm - DBM management tool\n"
39 " delete - delete specified keys from the database\n" 30 " delete - delete specified keys from the database\n"
40 " add - add records to the database\n" 31 " add - add records to the database\n"
41 " replace - add records replacing ones with matching keys\n"); 32 " replace - add records replacing ones with matching keys\n");
33
42 char dbm_docstring[] = N_("DBM management tool"); 34 char dbm_docstring[] = N_("DBM management tool");
43 static char dbm_args_doc[] = N_("COMMAND FILE [KEY...]"); 35 static char dbm_args_doc[] = N_("COMMAND FILE [KEY...]");
44 36
...@@ -1603,75 +1595,23 @@ delete_database (int argc, char **argv) ...@@ -1603,75 +1595,23 @@ delete_database (int argc, char **argv)
1603 mu dbm --replace a.db < input 1595 mu dbm --replace a.db < input
1604 */ 1596 */
1605 1597
1606 static struct argp_option dbm_options[] = { 1598 static void
1607 { NULL, 0, NULL, 0, N_("Create Options"), 0}, 1599 set_permissions (struct mu_parseopt *po, struct mu_option *opt, char const *arg)
1608 { "file", 'f', N_("FILE"), 0,
1609 N_("read input from FILE (with create, delete, add and replace)") },
1610 { "permissions", 'p', N_("NUM"), 0,
1611 N_("set permissions on the created database") },
1612 { "user", 'u', N_("USER"), 0,
1613 N_("set database owner name") },
1614 { "group", 'g', N_("GROUP"), 0,
1615 N_("set database owner group") },
1616 { "copy-permissions", 'P', NULL, 0,
1617 N_("copy database permissions and ownership from the input file") },
1618 { "ignore-meta", 'm', NULL, 0,
1619 N_("ignore meta-information from input file headers") },
1620 { "ignore-directives", 'I', N_("NAMES"), 0,
1621 N_("ignore the listed directives") },
1622 { NULL, 0, NULL, 0, N_("List and Dump Options"), 0},
1623 { "format", 'H', N_("TYPE"), 0,
1624 N_("select output format") },
1625 { "no-header", 'q', NULL, 0,
1626 N_("suppress format header") },
1627 { NULL, 0, NULL, 0, N_("List, Dump and Delete Options"), 0},
1628 { "glob", 'G', NULL, 0,
1629 N_("treat keys as globbing patterns") },
1630 { "regex", 'R', NULL, 0,
1631 N_("treat keys as regular expressions") },
1632 { "ignore-case", 'i', NULL, 0,
1633 N_("case-insensitive matches") },
1634 { NULL, 0, NULL, 0, N_("Options for Use with Format 0.0"), 0 },
1635 { "count-null", 'N', NULL, 0,
1636 N_("data length accounts for terminating zero") },
1637 { "no-count-null", 'n', NULL, 0,
1638 N_("data length does not account for terminating zero") },
1639 { NULL }
1640 };
1641
1642 static error_t
1643 dbm_parse_opt (int key, char *arg, struct argp_state *state)
1644 { 1600 {
1645 switch (key)
1646 {
1647 case 'f':
1648 input_file = arg;
1649 break;
1650
1651 case 'H':
1652 select_format (arg);
1653 break;
1654
1655 case 'p':
1656 {
1657 char *p; 1601 char *p;
1658 unsigned long d = strtoul (arg, &p, 8); 1602 unsigned long d = strtoul (arg, &p, 8);
1659 if (*p || (d & ~0777)) 1603 if (*p || (d & ~0777))
1660 argp_error (state, _("invalid file mode: %s"), arg); 1604 {
1605 mu_parseopt_error (po, _("invalid file mode: %s"), arg);
1606 exit (po->po_exit_error);
1607 }
1661 file_mode = d; 1608 file_mode = d;
1662 known_meta_data |= META_FILE_MODE; 1609 known_meta_data |= META_FILE_MODE;
1663 } 1610 }
1664 break;
1665
1666 case 'P':
1667 copy_permissions = 1;
1668 break;
1669
1670 case 'q':
1671 suppress_header = 1;
1672 break;
1673 1611
1674 case 'u': 1612 static void
1613 set_user (struct mu_parseopt *po, struct mu_option *opt, char const *arg)
1614 {
1675 auth = mu_get_auth_by_name (arg); 1615 auth = mu_get_auth_by_name (arg);
1676 if (auth) 1616 if (auth)
1677 known_meta_data |= META_AUTH; 1617 known_meta_data |= META_AUTH;
...@@ -1685,13 +1625,17 @@ dbm_parse_opt (int key, char *arg, struct argp_state *state) ...@@ -1685,13 +1625,17 @@ dbm_parse_opt (int key, char *arg, struct argp_state *state)
1685 known_meta_data |= META_UID; 1625 known_meta_data |= META_UID;
1686 } 1626 }
1687 else 1627 else
1688 argp_error (state, _("no such user: %s"), arg); 1628 {
1629 mu_parseopt_error (po, _("no such user: %s"), arg);
1630 exit (po->po_exit_error);
1631 }
1689 } 1632 }
1690 ignore_directives ("user,uid"); 1633 ignore_directives ("user,uid");
1691 break; 1634 }
1692 1635
1693 case 'g': 1636 static void
1694 { 1637 set_group (struct mu_parseopt *po, struct mu_option *opt, char const *arg)
1638 {
1695 struct group *gr = getgrnam (arg); 1639 struct group *gr = getgrnam (arg);
1696 if (!gr) 1640 if (!gr)
1697 { 1641 {
...@@ -1700,57 +1644,112 @@ dbm_parse_opt (int key, char *arg, struct argp_state *state) ...@@ -1700,57 +1644,112 @@ dbm_parse_opt (int key, char *arg, struct argp_state *state)
1700 if (*p == 0) 1644 if (*p == 0)
1701 owner_gid = n; 1645 owner_gid = n;
1702 else 1646 else
1703 argp_error (state, _("no such group: %s"), arg); 1647 {
1648 mu_parseopt_error (po, _("no such group: %s"), arg);
1649 exit (po->po_exit_error);
1650 }
1704 } 1651 }
1705 else 1652 else
1706 owner_gid = gr->gr_gid; 1653 owner_gid = gr->gr_gid;
1707 known_meta_data |= META_GID; 1654 known_meta_data |= META_GID;
1708 ignore_directives ("group,gid"); 1655 ignore_directives ("group,gid");
1709 } 1656 }
1710 break;
1711
1712 case 'G':
1713 key_type = key_glob;
1714 break;
1715
1716 case 'R':
1717 key_type = key_regex;
1718 break;
1719 1657
1720 case 'm':/* FIXME: Why m? */ 1658 static void
1659 set_ignore_meta (struct mu_parseopt *po, struct mu_option *opt, char const *arg)
1660 {
1721 ignore_flagged_directives (DF_META); 1661 ignore_flagged_directives (DF_META);
1722 break; 1662 }
1723 1663
1724 case 'I': 1664 static void
1665 set_ignore_directives (struct mu_parseopt *po, struct mu_option *opt,
1666 char const *arg)
1667 {
1725 ignore_directives (arg); 1668 ignore_directives (arg);
1726 break; 1669 }
1727 1670
1728 case 'i': 1671 static void
1729 case_sensitive = 0; 1672 set_format (struct mu_parseopt *po, struct mu_option *opt, char const *arg)
1730 break; 1673 {
1674 select_format (arg);
1675 }
1731 1676
1732 case 'N': 1677 static void
1733 include_zero = 1; 1678 set_glob (struct mu_parseopt *po, struct mu_option *opt, char const *arg)
1734 break; 1679 {
1680 key_type = key_glob;
1681 }
1735 1682
1736 case 'n': 1683 static void
1737 include_zero = 0; 1684 set_regex (struct mu_parseopt *po, struct mu_option *opt, char const *arg)
1738 break; 1685 {
1686 key_type = key_regex;
1687 }
1739 1688
1740 default: 1689 static void
1741 return ARGP_ERR_UNKNOWN; 1690 set_ignore_case (struct mu_parseopt *po, struct mu_option *opt, char const *arg)
1742 } 1691 {
1743 return 0; 1692 case_sensitive = 0;
1744 } 1693 }
1745 1694
1746 static struct argp dbm_argp = { 1695 static void
1747 dbm_options, 1696 clear_include_zero (struct mu_parseopt *po, struct mu_option *opt,
1748 dbm_parse_opt, 1697 char const *arg)
1749 dbm_args_doc, 1698 {
1750 dbm_doc, 1699 include_zero = 0;
1751 NULL, 1700 }
1752 NULL, 1701
1753 NULL 1702 static struct mu_option dbm_options[] = {
1703 MU_OPTION_GROUP (N_("Create Options")),
1704 { "file", 'f', N_("FILE"), MU_OPTION_DEFAULT,
1705 N_("read input from FILE (with create, delete, add and replace)"),
1706 mu_c_string, &input_file },
1707 { "permissions", 'p', N_("NUM"), MU_OPTION_DEFAULT,
1708 N_("set permissions on the created database"),
1709 mu_c_string, NULL, set_permissions },
1710 { "user", 'u', N_("USER"), MU_OPTION_DEFAULT,
1711 N_("set database owner name"),
1712 mu_c_string, NULL, set_user },
1713 { "group", 'g', N_("GROUP"), MU_OPTION_DEFAULT,
1714 N_("set database owner group"),
1715 mu_c_string, NULL, set_group },
1716 { "copy-permissions", 'P', NULL, MU_OPTION_DEFAULT,
1717 N_("copy database permissions and ownership from the input file"),
1718 mu_c_bool, &copy_permissions },
1719 { "ignore-meta", 'm', NULL, MU_OPTION_DEFAULT,
1720 N_("ignore meta-information from input file headers"),
1721 mu_c_string, NULL, set_ignore_meta },
1722 { "ignore-directives", 'I', N_("NAMES"), MU_OPTION_DEFAULT,
1723 N_("ignore the listed directives"),
1724 mu_c_string, NULL, set_ignore_directives },
1725
1726 MU_OPTION_GROUP (N_("List and Dump Options")),
1727 { "format", 'H', N_("TYPE"), MU_OPTION_DEFAULT,
1728 N_("select output format"),
1729 mu_c_string, NULL, set_format },
1730 { "no-header", 'q', NULL, MU_OPTION_DEFAULT,
1731 N_("suppress format header"),
1732 mu_c_bool, &suppress_header },
1733
1734 MU_OPTION_GROUP (N_("List, Dump and Delete Options")),
1735 { "glob", 'G', NULL, MU_OPTION_DEFAULT,
1736 N_("treat keys as globbing patterns"),
1737 mu_c_string, NULL, set_glob },
1738 { "regex", 'R', NULL, MU_OPTION_DEFAULT,
1739 N_("treat keys as regular expressions"),
1740 mu_c_string, NULL, set_regex },
1741 { "ignore-case", 'i', NULL, MU_OPTION_DEFAULT,
1742 N_("case-insensitive matches"),
1743 mu_c_string, NULL, set_ignore_case },
1744
1745 MU_OPTION_GROUP (N_("Options for Use with Format 0.0")),
1746 { "count-null", 'N', NULL, MU_OPTION_DEFAULT,
1747 N_("data length accounts for terminating zero"),
1748 mu_c_bool, &include_zero },
1749 { "no-count-null", 'n', NULL, MU_OPTION_DEFAULT,
1750 N_("data length does not account for terminating zero"),
1751 mu_c_string, NULL, clear_include_zero },
1752 MU_OPTION_END
1754 }; 1753 };
1755 1754
1756 struct mu_kwd mode_tab[] = 1755 struct mu_kwd mode_tab[] =
...@@ -1770,11 +1769,7 @@ mutool_dbm (int argc, char **argv) ...@@ -1770,11 +1769,7 @@ mutool_dbm (int argc, char **argv)
1770 { 1769 {
1771 int index; 1770 int index;
1772 1771
1773 if (argp_parse (&dbm_argp, argc, argv, 0, &index, NULL)) 1772 mu_action_getopt (&argc, &argv, dbm_options, dbm_doc, dbm_args_doc);
1774 return 1;
1775
1776 argc -= index;
1777 argv += index;
1778 1773
1779 if (argc == 0) 1774 if (argc == 0)
1780 { 1775 {
......
...@@ -49,33 +49,34 @@ dispatch_find_action (const char *name) ...@@ -49,33 +49,34 @@ dispatch_find_action (const char *name)
49 return NULL; 49 return NULL;
50 } 50 }
51 51
52 char * 52 void
53 dispatch_docstring (const char *text) 53 subcommand_help (mu_stream_t str)
54 { 54 {
55 mu_stream_t str;
56 struct mutool_action_tab *p; 55 struct mutool_action_tab *p;
57 mu_off_t size; 56 unsigned margin;
58 size_t n;
59 char *ret;
60 57
61 mu_memory_stream_create (&str, MU_STREAM_RDWR); 58 mu_stream_printf (str, "%s\n\n", _("Commands are:"));
62 mu_stream_printf (str, "%s\n%s\n\n", text, _("Commands are:"));
63 for (p = mutool_action_tab; p->name; p++) 59 for (p = mutool_action_tab; p->name; p++)
64 mu_stream_printf (str, " %s %-16s - %s\n", 60 {
65 mu_program_name, 61 margin = 2;
66 p->name, gettext (p->docstring)); 62 mu_stream_ioctl (str, MU_IOCTL_WORDWRAPSTREAM,
63 MU_IOCTL_WORDWRAP_SET_MARGIN,
64 &margin);
65 mu_stream_printf (str, "%s %s", mu_program_name, p->name);
66 margin = 29;
67 mu_stream_ioctl (str, MU_IOCTL_WORDWRAPSTREAM,
68 MU_IOCTL_WORDWRAP_SET_MARGIN,
69 &margin);
70 mu_stream_printf (str, "%s", gettext (p->docstring));
71 }
72 margin = 0;
73 mu_stream_ioctl (str, MU_IOCTL_WORDWRAPSTREAM,
74 MU_IOCTL_WORDWRAP_SET_MARGIN,
75 &margin);
67 mu_stream_printf (str, 76 mu_stream_printf (str,
68 _("\nTry `%s COMMAND --help' to get help on a particular " 77 _("\nTry `%s COMMAND --help' to get help on a particular "
69 "COMMAND.\n\n"), 78 "COMMAND.\n\n"),
70 mu_program_name); 79 mu_program_name);
71 mu_stream_printf (str, "%s\n", _("Options are:")); 80 mu_stream_printf (str, "%s\n", _("OPTIONs are:"));
72 mu_stream_flush (str);
73 mu_stream_size (str, &size);
74 ret = mu_alloc (size + 1);
75 mu_stream_seek (str, 0, MU_SEEK_SET, NULL);
76 mu_stream_read (str, ret, size, &n);
77 ret[n] = 0;
78 mu_stream_destroy (&str);
79 return ret;
80 } 81 }
81 82
......
...@@ -23,57 +23,41 @@ ...@@ -23,57 +23,41 @@
23 #include "argp.h" 23 #include "argp.h"
24 #include "mu.h" 24 #include "mu.h"
25 25
26 static char filter_doc[] = N_("mu filter - apply a chain of filters to the input");
27 char filter_docstring[] = N_("apply a chain of filters to the input"); 26 char filter_docstring[] = N_("apply a chain of filters to the input");
28 static char filter_args_doc[] = N_("[~]NAME [ARGS] [+ [~]NAME [ARGS]...]"); 27 static char filter_args_doc[] = N_("[~]NAME [ARGS] [+ [~]NAME [ARGS]...]");
29 28
30 static struct argp_option filter_options[] = {
31 { "encode", 'e', NULL, 0, N_("encode the input (default)") },
32 { "decode", 'd', NULL, 0, N_("decode the input") },
33 { "newline", 'n', NULL, 0, N_("print additional newline") },
34 { "list", 'L', NULL, 0, N_("list supported filters") },
35 { NULL }
36 };
37
38 static int filter_mode = MU_FILTER_ENCODE; 29 static int filter_mode = MU_FILTER_ENCODE;
39 static int newline_option = 0; 30 static int newline_option = 0;
40 static int list_option; 31 static int list_option;
41 32
42 static error_t 33 static void
43 filter_parse_opt (int key, char *arg, struct argp_state *state) 34 set_encode_mode (struct mu_parseopt *po, struct mu_option *opt,
35 char const *arg)
44 { 36 {
45 switch (key)
46 {
47 case 'e':
48 filter_mode = MU_FILTER_ENCODE; 37 filter_mode = MU_FILTER_ENCODE;
49 break; 38 }
50 39
51 case 'd': 40 static void
41 set_decode_mode (struct mu_parseopt *po, struct mu_option *opt,
42 char const *arg)
43 {
52 filter_mode = MU_FILTER_DECODE; 44 filter_mode = MU_FILTER_DECODE;
53 break;
54
55 case 'n':
56 newline_option = 1;
57 break;
58
59 case 'L':
60 list_option = 1;
61 break;
62
63 default:
64 return ARGP_ERR_UNKNOWN;
65 }
66 return 0;
67 } 45 }
68 46
69 static struct argp filter_argp = { 47 static struct mu_option filter_options[] = {
70 filter_options, 48 { "encode", 'e', NULL, MU_OPTION_DEFAULT,
71 filter_parse_opt, 49 N_("encode the input (default)"),
72 filter_args_doc, 50 mu_c_string, NULL, set_encode_mode },
73 filter_doc, 51 { "decode", 'd', NULL, MU_OPTION_DEFAULT,
74 NULL, 52 N_("decode the input"),
75 NULL, 53 mu_c_string, NULL, set_decode_mode },
76 NULL 54 { "newline", 'n', NULL, MU_OPTION_DEFAULT,
55 N_("print additional newline"),
56 mu_c_bool, &newline_option },
57 { "list", 'L', NULL, MU_OPTION_DEFAULT,
58 N_("list supported filters"),
59 mu_c_bool, &list_option },
60 MU_OPTION_END
77 }; 61 };
78 62
79 static int 63 static int
...@@ -85,7 +69,7 @@ filter_printer (void *item, void *data) ...@@ -85,7 +69,7 @@ filter_printer (void *item, void *data)
85 } 69 }
86 70
87 static int 71 static int
88 list_filters () 72 list_filters (void)
89 { 73 {
90 mu_list_t list; 74 mu_list_t list;
91 int rc = mu_filter_get_list (&list); 75 int rc = mu_filter_get_list (&list);
...@@ -111,16 +95,13 @@ negate_filter_mode (int mode) ...@@ -111,16 +95,13 @@ negate_filter_mode (int mode)
111 int 95 int
112 mutool_filter (int argc, char **argv) 96 mutool_filter (int argc, char **argv)
113 { 97 {
114 int rc, index; 98 int rc;
115 mu_stream_t flt, prev_stream; 99 mu_stream_t flt, prev_stream;
116 const char *fltname; 100 const char *fltname;
117 int mode; 101 int mode;
118 102
119 if (argp_parse (&filter_argp, argc, argv, ARGP_IN_ORDER, &index, NULL)) 103 mu_action_getopt (&argc, &argv, filter_options, filter_docstring,
120 return 1; 104 filter_args_doc);
121
122 argc -= index;
123 argv += index;
124 105
125 if (list_option) 106 if (list_option)
126 { 107 {
......
...@@ -14,87 +14,50 @@ ...@@ -14,87 +14,50 @@
14 You should have received a copy of the GNU General Public License 14 You should have received a copy of the GNU General Public License
15 along with GNU Mailutils. If not, see <http://www.gnu.org/licenses/>. */ 15 along with GNU Mailutils. If not, see <http://www.gnu.org/licenses/>. */
16 16
17 #if defined(HAVE_CONFIG_H)
18 # include <config.h>
19 #endif
20 #include <stdlib.h>
21 #include <string.h>
22 #include <mailutils/mailutils.h>
23 #include "argp.h"
24 #include "mu.h" 17 #include "mu.h"
25 18
26 static char flt2047_doc[] = N_("mu 2047 - decode/encode message headers.");
27 char flt2047_docstring[] = N_("decode/encode email message headers"); 19 char flt2047_docstring[] = N_("decode/encode email message headers");
28 static char flt2047_args_doc[] = N_("[text]"); 20 static char flt2047_args_doc[] = N_("[text]");
29 21
30 static struct argp_option flt2047_options[] = {
31 { "encode", 'e', NULL, 0, N_("encode the input (default)") },
32 { "decode", 'd', NULL, 0, N_("decode the input") },
33 { "newline", 'n', NULL, 0, N_("print additional newline") },
34 { "charset", 'c', N_("NAME"), 0,
35 N_("set charset (default: iso-8859-1)") },
36 { "encoding", 'E', N_("NAME"), 0,
37 N_("set encoding (default: quoted-printable)") },
38 { NULL }
39 };
40
41 static int decode_mode = 0; 22 static int decode_mode = 0;
42 static int newline_option = 0; 23 static int newline_option = 0;
43 static const char *charset = "iso-8859-1"; 24 static const char *charset = "iso-8859-1";
44 static const char *encoding = "quoted-printable"; 25 static const char *encoding = "quoted-printable";
45 26
46 static error_t 27 static void
47 flt2047_parse_opt (int key, char *arg, struct argp_state *state) 28 set_encode_mode (struct mu_parseopt *po, struct mu_option *opt,
29 char const *arg)
48 { 30 {
49 switch (key)
50 {
51 case 'c':
52 charset = arg;
53 break;
54
55 case 'e':
56 decode_mode = 0; 31 decode_mode = 0;
57 break;
58
59 case 'E':
60 encoding = arg;
61 break;
62
63 case 'd':
64 decode_mode = 1;
65 break;
66
67 case 'n':
68 newline_option = 0;
69 break;
70
71 default:
72 return ARGP_ERR_UNKNOWN;
73 }
74 return 0;
75 } 32 }
76 33
77 static struct argp flt2047_argp = { 34 static struct mu_option flt2047_options[] = {
78 flt2047_options, 35 { "encode", 'e', NULL, MU_OPTION_DEFAULT,
79 flt2047_parse_opt, 36 N_("encode the input (default)"),
80 flt2047_args_doc, 37 mu_c_string, NULL, set_encode_mode },
81 flt2047_doc, 38 { "decode", 'd', NULL, MU_OPTION_DEFAULT,
82 NULL, 39 N_("decode the input"),
83 NULL, 40 mu_c_bool, &decode_mode },
84 NULL 41 { "newline", 'n', NULL, MU_OPTION_DEFAULT,
42 N_("print additional newline"),
43 mu_c_bool, &newline_option },
44 { "charset", 'c', N_("NAME"), MU_OPTION_DEFAULT,
45 N_("set charset (default: iso-8859-1)"),
46 mu_c_string, &charset },
47 { "encoding", 'E', N_("NAME"), MU_OPTION_DEFAULT,
48 N_("set encoding (default: quoted-printable)"),
49 mu_c_string, &encoding },
50 MU_OPTION_END
85 }; 51 };
86 52
87 int 53 int
88 mutool_flt2047 (int argc, char **argv) 54 mutool_flt2047 (int argc, char **argv)
89 { 55 {
90 int rc, index; 56 int rc;
91 char *p; 57 char *p;
92 58
93 if (argp_parse (&flt2047_argp, argc, argv, ARGP_IN_ORDER, &index, NULL)) 59 mu_action_getopt (&argc, &argv, flt2047_options, flt2047_docstring,
94 return 1; 60 flt2047_args_doc);
95
96 argc -= index;
97 argv += index;
98 61
99 if (argc) 62 if (argc)
100 { 63 {
......
...@@ -14,10 +14,6 @@ ...@@ -14,10 +14,6 @@
14 You should have received a copy of the GNU General Public License 14 You should have received a copy of the GNU General Public License
15 along with GNU Mailutils. If not, see <http://www.gnu.org/licenses/>. */ 15 along with GNU Mailutils. If not, see <http://www.gnu.org/licenses/>. */
16 16
17 #ifdef HAVE_CONFIG_H
18 # include <config.h>
19 #endif
20 #include <mailutils/mailutils.h>
21 #include "mu.h" 17 #include "mu.h"
22 18
23 int 19 int
......
...@@ -14,16 +14,8 @@ ...@@ -14,16 +14,8 @@
14 You should have received a copy of the GNU General Public License 14 You should have received a copy of the GNU General Public License
15 along with GNU Mailutils. If not, see <http://www.gnu.org/licenses/>. */ 15 along with GNU Mailutils. If not, see <http://www.gnu.org/licenses/>. */
16 16
17 #if defined(HAVE_CONFIG_H)
18 # include <config.h>
19 #endif
20 #include <stdlib.h>
21 #include <string.h>
22 #include <unistd.h>
23 #include <netdb.h>
24 #include <netinet/in.h>
25 #include <mailutils/mailutils.h>
26 #include "mu.h" 17 #include "mu.h"
18 #include <netdb.h>
27 19
28 int 20 int
29 get_bool (const char *str, int *pb) 21 get_bool (const char *str, int *pb)
......
...@@ -14,10 +14,6 @@ ...@@ -14,10 +14,6 @@
14 You should have received a copy of the GNU General Public License 14 You should have received a copy of the GNU General Public License
15 along with GNU Mailutils. If not, see <http://www.gnu.org/licenses/>. */ 15 along with GNU Mailutils. If not, see <http://www.gnu.org/licenses/>. */
16 16
17 #ifdef HAVE_CONFIG_H
18 # include <config.h>
19 #endif
20 #include <mailutils/mailutils.h>
21 #include "mu.h" 17 #include "mu.h"
22 18
23 int 19 int
......
...@@ -29,37 +29,24 @@ static char help_doc[] = N_("mu help - display a terse help summary"); ...@@ -29,37 +29,24 @@ static char help_doc[] = N_("mu help - display a terse help summary");
29 char help_docstring[] = N_("display a terse help summary"); 29 char help_docstring[] = N_("display a terse help summary");
30 static char help_args_doc[] = N_("[COMMAND]"); 30 static char help_args_doc[] = N_("[COMMAND]");
31 31
32 static struct argp help_argp = {
33 NULL,
34 NULL,
35 help_args_doc,
36 help_doc,
37 NULL,
38 NULL,
39 NULL
40 };
41
42 int 32 int
43 mutool_help (int argc, char **argv) 33 mutool_help (int argc, char **argv)
44 { 34 {
45 int index; 35 mu_action_getopt (&argc, &argv, NULL, help_doc, help_args_doc);
46
47 if (argp_parse (&help_argp, argc, argv, ARGP_IN_ORDER, &index, NULL))
48 return 1;
49 36
50 if (index == argc - 1) 37 if (argc == 1)
51 { 38 {
52 mutool_action_t action = dispatch_find_action (argv[index]); 39 mutool_action_t action = dispatch_find_action (argv[0]);
53 if (!action) 40 if (!action)
54 { 41 {
55 mu_error (_("don't know what %s is"), argv[index]); 42 mu_error (_("don't know what %s is"), argv[0]);
56 exit (1); 43 exit (1);
57 } 44 }
58 mu_asprintf (&argv[0], "%s %s", mu_program_name, argv[index]); 45 mu_asprintf (&argv[0], "%s %s", mu_program_name, argv[0]);
59 argv[1] = "--help"; 46 argv[1] = "--help";
60 return action (2, argv); 47 return action (2, argv);
61 } 48 }
62 else if (argc != index) 49 else if (argc > 1)
63 { 50 {
64 mu_error (_("too many arguments")); 51 mu_error (_("too many arguments"));
65 exit (1); 52 exit (1);
......
...@@ -31,35 +31,7 @@ ...@@ -31,35 +31,7 @@
31 #include "mu.h" 31 #include "mu.h"
32 #include "argp.h" 32 #include "argp.h"
33 33
34 static char imap_doc[] = N_("mu imap - IMAP4 client shell.");
35 char imap_docstring[] = N_("IMAP4 client shell"); 34 char imap_docstring[] = N_("IMAP4 client shell");
36 static char imap_args_doc[] = "";
37
38 static struct argp_option imap_options[] = {
39 { NULL }
40 };
41
42 static error_t
43 imap_parse_opt (int key, char *arg, struct argp_state *state)
44 {
45 switch (key)
46 {
47 default:
48 return ARGP_ERR_UNKNOWN;
49 }
50 return 0;
51 }
52
53 static struct argp imap_argp = {
54 imap_options,
55 imap_parse_opt,
56 imap_args_doc,
57 imap_doc,
58 NULL,
59 NULL,
60 NULL
61 };
62
63 35
64 static mu_imap_t imap; 36 static mu_imap_t imap;
65 static int uid_mode; 37 static int uid_mode;
...@@ -1336,13 +1308,7 @@ struct mutool_command imap_comtab[] = { ...@@ -1336,13 +1308,7 @@ struct mutool_command imap_comtab[] = {
1336 int 1308 int
1337 mutool_imap (int argc, char **argv) 1309 mutool_imap (int argc, char **argv)
1338 { 1310 {
1339 int index; 1311 mu_action_getopt (&argc, &argv, NULL, imap_docstring, NULL);
1340
1341 if (argp_parse (&imap_argp, argc, argv, ARGP_IN_ORDER, &index, NULL))
1342 return 1;
1343
1344 argc -= index;
1345 argv += index;
1346 1312
1347 if (argc) 1313 if (argc)
1348 { 1314 {
......
...@@ -14,13 +14,6 @@ ...@@ -14,13 +14,6 @@
14 You should have received a copy of the GNU General Public License 14 You should have received a copy of the GNU General Public License
15 along with GNU Mailutils. If not, see <http://www.gnu.org/licenses/>. */ 15 along with GNU Mailutils. If not, see <http://www.gnu.org/licenses/>. */
16 16
17 #if defined(HAVE_CONFIG_H)
18 # include <config.h>
19 #endif
20 #include <stdlib.h>
21 #include <string.h>
22 #include <mailutils/mailutils.h>
23 #include "argp.h"
24 #include "mu.h" 17 #include "mu.h"
25 18
26 static char info_doc[] = N_("mu info - print a list of configuration\ 19 static char info_doc[] = N_("mu info - print a list of configuration\
...@@ -29,49 +22,19 @@ static char info_doc[] = N_("mu info - print a list of configuration\ ...@@ -29,49 +22,19 @@ static char info_doc[] = N_("mu info - print a list of configuration\
29 char info_docstring[] = N_("show Mailutils configuration"); 22 char info_docstring[] = N_("show Mailutils configuration");
30 static char info_args_doc[] = N_("[capa...]"); 23 static char info_args_doc[] = N_("[capa...]");
31 24
32 static struct argp_option info_options[] = {
33 { "verbose", 'v', NULL, 0,
34 N_("increase output verbosity"), 0},
35 { NULL }
36 };
37
38 static int verbose; 25 static int verbose;
39 26
40 static error_t 27 static struct mu_option info_options[] = {
41 info_parse_opt (int key, char *arg, struct argp_state *state) 28 { "verbose", 'v', NULL, MU_OPTION_DEFAULT,
42 { 29 N_("increase output verbosity"),
43 switch (key) 30 mu_c_bool, &verbose },
44 { 31 MU_OPTION_END
45 case 'v':
46 verbose++;
47 break;
48
49 default:
50 return ARGP_ERR_UNKNOWN;
51 }
52 return 0;
53 }
54
55 static struct argp info_argp = {
56 info_options,
57 info_parse_opt,
58 info_args_doc,
59 info_doc,
60 NULL,
61 NULL,
62 NULL
63 }; 32 };
64 33
65 int 34 int
66 mutool_info (int argc, char **argv) 35 mutool_info (int argc, char **argv)
67 { 36 {
68 int index; 37 mu_action_getopt (&argc, &argv, info_options, info_doc, info_args_doc);
69
70 if (argp_parse (&info_argp, argc, argv, ARGP_IN_ORDER, &index, NULL))
71 return 1;
72
73 argc -= index;
74 argv += index;
75 38
76 if (argc == 0) 39 if (argc == 0)
77 mu_format_options (mu_strout, verbose); 40 mu_format_options (mu_strout, verbose);
......
...@@ -14,28 +14,11 @@ ...@@ -14,28 +14,11 @@
14 You should have received a copy of the GNU General Public License 14 You should have received a copy of the GNU General Public License
15 along with GNU Mailutils. If not, see <http://www.gnu.org/licenses/>. */ 15 along with GNU Mailutils. If not, see <http://www.gnu.org/licenses/>. */
16 16
17 #if defined(HAVE_CONFIG_H) 17 #include "mu.h"
18 # include <config.h>
19 #endif
20 #include <stdlib.h>
21 #include <mailutils/mailutils.h>
22 #include <mailutils/libcfg.h>
23 #include <argp.h>
24 18
25 static char ldflags_doc[] = N_("mu ldflags - list libraries required to link");
26 char ldflags_docstring[] = N_("list libraries required to link"); 19 char ldflags_docstring[] = N_("list libraries required to link");
27 static char ldflags_args_doc[] = N_("KEYWORD [KEYWORD...]"); 20 static char ldflags_args_doc[] = N_("KEYWORD [KEYWORD...]");
28 21
29 static struct argp ldflags_argp = {
30 NULL,
31 NULL,
32 ldflags_args_doc,
33 ldflags_doc,
34 NULL,
35 NULL,
36 NULL
37 };
38
39 22
40 #ifdef WITH_TLS 23 #ifdef WITH_TLS
41 # define NEEDAUTH "-lmu_auth " AUTHLIBS 24 # define NEEDAUTH "-lmu_auth " AUTHLIBS
...@@ -140,13 +123,9 @@ sort_entries () ...@@ -140,13 +123,9 @@ sort_entries ()
140 int 123 int
141 mutool_ldflags (int argc, char **argv) 124 mutool_ldflags (int argc, char **argv)
142 { 125 {
143 int i, j; 126 int j;
144
145 if (argp_parse (&ldflags_argp, argc, argv, ARGP_IN_ORDER, &i, NULL))
146 return 1;
147 127
148 argc -= i; 128 mu_action_getopt (&argc, &argv, NULL, ldflags_docstring, ldflags_args_doc);
149 argv += i;
150 129
151 add_entry (-100, LINK_FLAGS); 130 add_entry (-100, LINK_FLAGS);
152 add_entry (100, LINK_POSTFLAGS); 131 add_entry (100, LINK_POSTFLAGS);
......
...@@ -14,35 +14,11 @@ ...@@ -14,35 +14,11 @@
14 You should have received a copy of the GNU General Public License 14 You should have received a copy of the GNU General Public License
15 along with GNU Mailutils. If not, see <http://www.gnu.org/licenses/>. */ 15 along with GNU Mailutils. If not, see <http://www.gnu.org/licenses/>. */
16 16
17 #if defined(HAVE_CONFIG_H)
18 # include <config.h>
19 #endif
20 #include <mailutils/mailutils.h>
21 #include "argp.h"
22 #include "mu.h" 17 #include "mu.h"
23 18
24 static char logger_doc[] = N_("mu logger - log data using Mailutils log facility");
25 char logger_docstring[] = N_("log data using Mailutils log facility"); 19 char logger_docstring[] = N_("log data using Mailutils log facility");
26 static char logger_args_doc[] = N_("[TEXT]"); 20 static char logger_args_doc[] = N_("[TEXT]");
27 21
28 #define OPT_SYSLOG 256
29 #define OPT_STDERR 257
30
31 static struct argp_option logger_options[] = {
32 { "file", 'f', N_("FILE"), 0, N_("read message from FILE") },
33 { "priority", 'p', N_("FACILITY[.LEVEL]"), 0,
34 N_("log at the specified syslog priority (implies --syslog)") },
35 { "syslog", OPT_SYSLOG, NULL, 0, N_("log via syslog") },
36 { "stderr", OPT_STDERR, NULL, 0, N_("log to the standard error") },
37 { "severity", 's', N_("SEV"), 0,
38 N_("log at Mailutils severity level SEV") },
39 { "locus", 'l', N_("FILE:LINE[:COL]"), 0,
40 N_("set locus for logging") },
41 { "tag", 't', N_("syslog tag"), 0,
42 N_("set syslog tag") },
43 { NULL }
44 };
45
46 static char *input_file = NULL; 22 static char *input_file = NULL;
47 static int logger_type = MU_STRERR_STDERR; 23 static int logger_type = MU_STRERR_STDERR;
48 static int log_severity = MU_LOG_ERROR; 24 static int log_severity = MU_LOG_ERROR;
...@@ -51,60 +27,64 @@ static int syslog_facility = LOG_USER; ...@@ -51,60 +27,64 @@ static int syslog_facility = LOG_USER;
51 static int syslog_priority = LOG_ERR; 27 static int syslog_priority = LOG_ERR;
52 static char *syslog_tag = NULL; 28 static char *syslog_tag = NULL;
53 29
54 static error_t 30 static void
55 logger_parse_opt (int key, char *arg, struct argp_state *state) 31 set_priority (struct mu_parseopt *po, struct mu_option *opt,
32 char const *arg)
56 { 33 {
57 switch (key) 34 char *s = strchr (arg, '.');
35 if (s)
36 *s++ = 0;
37 if (mu_string_to_syslog_facility (arg, &syslog_facility))
38 {
39 mu_parseopt_error (po, _("unknown facility: %s"), arg);
40 exit (po->po_exit_error);
41 }
42 if (s && mu_string_to_syslog_priority (s, &syslog_priority))
58 { 43 {
59 case 'f': 44 mu_parseopt_error (po, _("unknown priority: %s"), s);
60 input_file = arg; 45 exit (po->po_exit_error);
61 break; 46 }
47
48 logger_type = MU_STRERR_SYSLOG;
49 }
62 50
63 case OPT_SYSLOG: 51 static void
52 set_syslog (struct mu_parseopt *po, struct mu_option *opt,
53 char const *arg)
54 {
64 logger_type = MU_STRERR_SYSLOG; 55 logger_type = MU_STRERR_SYSLOG;
65 break; 56 }
66 57
67 case OPT_STDERR: 58 static void
59 set_stderr (struct mu_parseopt *po, struct mu_option *opt,
60 char const *arg)
61 {
68 logger_type = MU_STRERR_STDERR; 62 logger_type = MU_STRERR_STDERR;
69 break; 63 }
70 64
71 case 's': 65 static void
72 { 66 set_severity (struct mu_parseopt *po, struct mu_option *opt,
67 char const *arg)
68 {
73 int i; 69 int i;
74 70
75 for (i = 0; i < _mu_severity_num; i++) 71 for (i = 0; i < _mu_severity_num; i++)
76 if (mu_c_strcasecmp (_mu_severity_str[i], arg) == 0) 72 if (mu_c_strcasecmp (_mu_severity_str[i], arg) == 0)
77 { 73 {
78 log_severity = i; 74 log_severity = i;
79 return 0; 75 return;
80 }
81 argp_error (state, _("unknown severity: %s"), arg);
82 break;
83 }
84
85 case 't':
86 syslog_tag = arg;
87 break;
88
89 case 'p':
90 {
91 char *s = strchr (arg, '.');
92 if (s)
93 *s++ = 0;
94 if (mu_string_to_syslog_facility (arg, &syslog_facility))
95 argp_error (state, _("unknown facility: %s"), arg);
96 if (s &&
97 mu_string_to_syslog_priority (s, &syslog_priority))
98 argp_error (state, _("unknown priority: %s"), s);
99 logger_type = MU_STRERR_SYSLOG;
100 break;
101 } 76 }
77 mu_parseopt_error (po, _("unknown severity: %s"), arg);
78 exit (po->po_exit_error);
79 }
102 80
103 case 'l': 81 static void
104 { 82 set_locus (struct mu_parseopt *po, struct mu_option *opt,
83 char const *arg)
84 {
105 char *s; 85 char *s;
106 86
107 locus.mu_file = arg; 87 locus.mu_file = mu_strdup (arg);
108 s = strchr (arg, ':'); 88 s = strchr (arg, ':');
109 if (s) 89 if (s)
110 { 90 {
...@@ -114,41 +94,52 @@ logger_parse_opt (int key, char *arg, struct argp_state *state) ...@@ -114,41 +94,52 @@ logger_parse_opt (int key, char *arg, struct argp_state *state)
114 { 94 {
115 locus.mu_col = strtoul (s + 1, &s, 10); 95 locus.mu_col = strtoul (s + 1, &s, 10);
116 if (*s) 96 if (*s)
117 argp_error (state, _("bad column number: %s"), arg); 97 {
98 mu_parseopt_error (po, _("bad column number: %s"), arg);
99 exit (po->po_exit_error);
118 } 100 }
119 else if (*s)
120 argp_error (state, _("bad line number: %s"), arg);
121 } 101 }
122 break; 102 else if (*s)
103 {
104 mu_parseopt_error (po, _("bad line number: %s"), arg);
105 exit (po->po_exit_error);
123 } 106 }
124
125 default:
126 return ARGP_ERR_UNKNOWN;
127 } 107 }
128 return 0;
129 } 108 }
130 109
131 static struct argp logger_argp = { 110 static struct mu_option logger_options[] = {
132 logger_options, 111 { "file", 'f', N_("FILE"), MU_OPTION_DEFAULT,
133 logger_parse_opt, 112 N_("read message from FILE"),
134 logger_args_doc, 113 mu_c_string, &input_file },
135 logger_doc, 114 { "priority", 'p', N_("FACILITY[.LEVEL]"), MU_OPTION_DEFAULT,
136 NULL, 115 N_("log at the specified syslog priority (implies --syslog)"),
137 NULL, 116 mu_c_string, NULL, set_priority },
138 NULL 117 { "syslog", 0, NULL, MU_OPTION_DEFAULT,
118 N_("log via syslog"),
119 mu_c_string, NULL, set_syslog },
120 { "stderr", 0, NULL, MU_OPTION_DEFAULT,
121 N_("log to the standard error"),
122 mu_c_string, NULL, set_stderr },
123 { "severity", 's', N_("SEV"), MU_OPTION_DEFAULT,
124 N_("log at Mailutils severity level SEV"),
125 mu_c_string, NULL, set_severity },
126 { "locus", 'l', N_("FILE:LINE[:COL]"), MU_OPTION_DEFAULT,
127 N_("set locus for logging"),
128 mu_c_string, NULL, set_locus },
129 { "tag", 't', N_("TAG"), MU_OPTION_DEFAULT,
130 N_("set syslog tag"),
131 mu_c_string, &syslog_tag },
132 MU_OPTION_END
139 }; 133 };
140 134
141 int 135 int
142 mutool_logger (int argc, char **argv) 136 mutool_logger (int argc, char **argv)
143 { 137 {
144 int index;
145 mu_stream_t logger, input; 138 mu_stream_t logger, input;
146 int rc, mode; 139 int rc, mode;
147 140
148 if (argp_parse (&logger_argp, argc, argv, ARGP_IN_ORDER, &index, NULL)) 141 mu_action_getopt (&argc, &argv, logger_options, logger_docstring,
149 return 1; 142 logger_args_doc);
150 argc -= index;
151 argv += index;
152 143
153 if (argc && input_file) 144 if (argc && input_file)
154 { 145 {
......
...@@ -21,58 +21,17 @@ ...@@ -21,58 +21,17 @@
21 #include <string.h> 21 #include <string.h>
22 #include <mailutils/mailutils.h> 22 #include <mailutils/mailutils.h>
23 #include <mailutils/tls.h> 23 #include <mailutils/tls.h>
24 #include "mailutils/libargp.h" 24 #include "mailutils/cli.h"
25 #include "mu.h" 25 #include "mu.h"
26 26
27 static char args_doc[] = N_("COMMAND [CMDOPTS]"); 27 struct mu_cli_setup cli = {
28 static char doc[] = N_("GNU Mailutils multi-purpose tool."); 28 .prog_doc = N_("GNU Mailutils multi-purpose tool."),
29 29 .prog_args = N_("COMMAND [CMDOPTS]"),
30 static struct argp_option options[] = { 30 .inorder = 1,
31 { NULL } 31 .prog_doc_hook = subcommand_help
32 };
33
34 static error_t
35 parse_opt (int key, char *arg, struct argp_state *state)
36 {
37 switch (key)
38 {
39 default:
40 return ARGP_ERR_UNKNOWN;
41 }
42 return 0;
43 }
44
45 static char *
46 mu_help_filter (int key, const char *text, void *input)
47 {
48 char *s;
49
50 switch (key)
51 {
52 case ARGP_KEY_HELP_PRE_DOC:
53 s = dispatch_docstring (text);
54 break;
55
56 default:
57 s = (char*) text;
58 }
59 return s;
60 }
61
62
63 static struct argp argp = {
64 options,
65 parse_opt,
66 args_doc,
67 doc,
68 NULL,
69 mu_help_filter,
70 NULL
71 }; 32 };
72 33
73 static const char *mu_tool_capa[] = { 34 static char *capa[] = {
74 "mailutils",
75 "common",
76 "debug", 35 "debug",
77 "locking", 36 "locking",
78 "mailbox", 37 "mailbox",
...@@ -80,26 +39,9 @@ static const char *mu_tool_capa[] = { ...@@ -80,26 +39,9 @@ static const char *mu_tool_capa[] = {
80 NULL 39 NULL
81 }; 40 };
82 41
83 struct mu_cfg_param mu_tool_param[] = {
84 { NULL }
85 };
86
87 int
88 mu_help ()
89 {
90 char *x_argv[3];
91
92 x_argv[0] = (char*) mu_program_name;
93 x_argv[1] = "--help";
94 x_argv[2] = NULL;
95 return mu_app_init (&argp, mu_tool_capa, mu_tool_param,
96 2, x_argv, 0, NULL, NULL);
97 }
98
99 int 42 int
100 main (int argc, char **argv) 43 main (int argc, char **argv)
101 { 44 {
102 int index;
103 mutool_action_t action; 45 mutool_action_t action;
104 46
105 /* Native Language Support */ 47 /* Native Language Support */
...@@ -109,16 +51,7 @@ main (int argc, char **argv) ...@@ -109,16 +51,7 @@ main (int argc, char **argv)
109 /* Register the desired mailbox formats. */ 51 /* Register the desired mailbox formats. */
110 mu_register_all_mbox_formats (); 52 mu_register_all_mbox_formats ();
111 53
112 #ifdef WITH_TLS 54 mu_cli (argc, argv, &cli, capa, NULL, &argc, &argv);
113 mu_gocs_register ("tls", mu_tls_module_init);
114 #endif
115 mu_argp_init (NULL, NULL);
116 if (mu_app_init (&argp, mu_tool_capa, mu_tool_param,
117 argc, argv, ARGP_IN_ORDER, &index, NULL))
118 exit (1);
119
120 argc -= index;
121 argv += index;
122 55
123 if (argc < 1) 56 if (argc < 1)
124 { 57 {
...@@ -133,16 +66,60 @@ main (int argc, char **argv) ...@@ -133,16 +66,60 @@ main (int argc, char **argv)
133 exit (1); 66 exit (1);
134 } 67 }
135 68
136 /* Disable --version option in action. */
137 argp_program_version = NULL;
138 argp_program_version_hook = NULL;
139
140 /* Reset argv[0] for diagnostic purposes */
141 mu_asprintf (&argv[0], "%s %s", mu_program_name, argv[0]);
142
143 /* Run the action. */ 69 /* Run the action. */
144 exit (action (argc, argv)); 70 exit (action (argc, argv));
145 } 71 }
146 72
73 int
74 mu_help (void)
75 {
76 char *argv[3];
77 argv[0] = mu_full_program_name;
78 argv[1] = "--help";
79 argv[2] = NULL;
80 mu_cli (2, argv, &cli, capa, NULL, NULL, NULL);
81 return 0;
82 }
83
84 void
85 mu_action_getopt (int *pargc, char ***pargv, struct mu_option *opt,
86 char const *docstring, char const *argdoc)
87 {
88 struct mu_parseopt po;
89 int flags = MU_PARSEOPT_IMMEDIATE;
90 struct mu_option *options[2];
91 char const *prog_args[2];
92 char *progname;
93
94 options[0] = opt;
95 options[1] = NULL;
96
97 mu_asprintf (&progname, "%s %s", mu_program_name, (*pargv)[0]);
98 po.po_prog_name = progname;
99 flags |= MU_PARSEOPT_PROG_NAME;
100
101 po.po_prog_doc = docstring;
102 flags |= MU_PARSEOPT_PROG_DOC;
103
104 if (argdoc)
105 {
106 prog_args[0] = argdoc;
107 prog_args[1] = NULL;
108 po.po_prog_args = prog_args;
109 flags |= MU_PARSEOPT_PROG_ARGS;
110 }
111
112 po.po_bug_address = PACKAGE_BUGREPORT;
113 flags |= MU_PARSEOPT_BUG_ADDRESS;
114
115 if (mu_parseopt (&po, *pargc, *pargv, options, flags))
116 exit (po.po_exit_error);
117
118 *pargc -= po.po_arg_start;
119 *pargv += po.po_arg_start;
120
121 mu_parseopt_free (&po);
122 }
123
147 124
148 125
......
...@@ -14,7 +14,17 @@ ...@@ -14,7 +14,17 @@
14 You should have received a copy of the GNU General Public License 14 You should have received a copy of the GNU General Public License
15 along with GNU Mailutils. If not, see <http://www.gnu.org/licenses/>. */ 15 along with GNU Mailutils. If not, see <http://www.gnu.org/licenses/>. */
16 16
17 #include <mailutils/types.h> 17 #if defined(HAVE_CONFIG_H)
18 # include <config.h>
19 #endif
20 #include <stdlib.h>
21 #include <string.h>
22 #include <sys/socket.h>
23 #include <netinet/in.h>
24 #include <sys/un.h>
25 #include <arpa/inet.h>
26 #include <sysexits.h>
27 #include <mailutils/mailutils.h>
18 28
19 typedef int (*mutool_action_t) (int argc, char **argv); 29 typedef int (*mutool_action_t) (int argc, char **argv);
20 30
...@@ -40,7 +50,7 @@ mu_stream_t mutool_open_pager (void); ...@@ -40,7 +50,7 @@ mu_stream_t mutool_open_pager (void);
40 50
41 int mu_help (void); 51 int mu_help (void);
42 mutool_action_t dispatch_find_action (const char *name); 52 mutool_action_t dispatch_find_action (const char *name);
43 char *dispatch_docstring (const char *text); 53 void subcommand_help (mu_stream_t str);
44 54
45 int port_from_sa (struct mu_sockaddr *sa); 55 int port_from_sa (struct mu_sockaddr *sa);
46 56
...@@ -64,3 +74,6 @@ int get_port (const char *port_str, int *pn); ...@@ -64,3 +74,6 @@ int get_port (const char *port_str, int *pn);
64 74
65 int mu_getans (const char *variants, const char *fmt, ...); 75 int mu_getans (const char *variants, const char *fmt, ...);
66 76
77 void mu_action_getopt (int *pargc, char ***pargv, struct mu_option *opt,
78 char const *docstring, char const *argdoc);
79
......
...@@ -14,48 +14,9 @@ ...@@ -14,48 +14,9 @@
14 You should have received a copy of the GNU General Public License 14 You should have received a copy of the GNU General Public License
15 along with GNU Mailutils. If not, see <http://www.gnu.org/licenses/>. */ 15 along with GNU Mailutils. If not, see <http://www.gnu.org/licenses/>. */
16 16
17 #if defined(HAVE_CONFIG_H)
18 # include <config.h>
19 #endif
20 #include <stdlib.h>
21 #include <string.h>
22 #include <unistd.h>
23 #include <sys/types.h>
24 #include <sys/time.h>
25 #include <netinet/in.h>
26 #include <netdb.h>
27 #include <mailutils/mailutils.h>
28 #include "mu.h" 17 #include "mu.h"
29 #include "argp.h"
30 18
31 static char pop_doc[] = N_("mu pop - POP3 client shell.");
32 char pop_docstring[] = N_("POP3 client shell"); 19 char pop_docstring[] = N_("POP3 client shell");
33 static char pop_args_doc[] = "";
34
35 static struct argp_option pop_options[] = {
36 { NULL }
37 };
38
39 static error_t
40 pop_parse_opt (int key, char *arg, struct argp_state *state)
41 {
42 switch (key)
43 {
44 default:
45 return ARGP_ERR_UNKNOWN;
46 }
47 return 0;
48 }
49
50 static struct argp pop_argp = {
51 pop_options,
52 pop_parse_opt,
53 pop_args_doc,
54 pop_doc,
55 NULL,
56 NULL,
57 NULL
58 };
59 20
60 /* Global handle for pop3. */ 21 /* Global handle for pop3. */
61 static mu_pop3_t pop3; 22 static mu_pop3_t pop3;
...@@ -656,13 +617,7 @@ struct mutool_command pop_comtab[] = { ...@@ -656,13 +617,7 @@ struct mutool_command pop_comtab[] = {
656 int 617 int
657 mutool_pop (int argc, char **argv) 618 mutool_pop (int argc, char **argv)
658 { 619 {
659 int index; 620 mu_action_getopt (&argc, &argv, NULL, pop_docstring, NULL);
660
661 if (argp_parse (&pop_argp, argc, argv, ARGP_IN_ORDER, &index, NULL))
662 return 1;
663
664 argc -= index;
665 argv += index;
666 621
667 if (argc) 622 if (argc)
668 { 623 {
......
...@@ -14,98 +14,44 @@ ...@@ -14,98 +14,44 @@
14 You should have received a copy of the GNU General Public License 14 You should have received a copy of the GNU General Public License
15 along with GNU Mailutils. If not, see <http://www.gnu.org/licenses/>. */ 15 along with GNU Mailutils. If not, see <http://www.gnu.org/licenses/>. */
16 16
17 #if defined(HAVE_CONFIG_H)
18 # include <config.h>
19 #endif
20 #include <stdlib.h>
21 #include <string.h>
22 #include <mailutils/mailutils.h>
23 #include <mailutils/libcfg.h>
24 #include "argp.h"
25 #include "mu.h" 17 #include "mu.h"
26 18
27 static char query_doc[] = N_("mu query - query configuration values.");
28 char query_docstring[] = N_("query configuration values"); 19 char query_docstring[] = N_("query configuration values");
29 static char query_args_doc[] = N_("path [path...]"); 20 static char query_args_doc[] = N_("path [path...]");
30 21
31 static char *file_name; 22 static char *file_name;
32 static struct mu_cfg_parse_hints hints; 23 int value_option;
24 int path_option;
25 int verbose_option;
26 char *progname;
33 27
34 enum { 28 static struct mu_option query_options[] = {
35 VALUE_OPTION = 256, 29 { "file", 'f', N_("FILE"), MU_OPTION_DEFAULT,
36 PATH_OPTION
37 };
38
39 static struct argp_option query_options[] = {
40 { "file", 'f', N_("FILE"), 0,
41 N_("query configuration values from FILE (default mailutils.rc)"), 30 N_("query configuration values from FILE (default mailutils.rc)"),
42 0 }, 31 mu_c_string, &file_name },
43 { "value", VALUE_OPTION, NULL, 0, 32 { "value", 0, NULL, MU_OPTION_DEFAULT,
44 N_("display parameter values only"), 33 N_("display parameter values only"),
45 0 }, 34 mu_c_bool, &value_option },
46 { "program", 'p', N_("NAME"), 0, 35 { "program", 'p', N_("NAME"), MU_OPTION_DEFAULT,
47 N_("set program name for configuration lookup"), 36 N_("set program name for configuration lookup"),
48 0 }, 37 mu_c_string, &progname },
49 { "path", PATH_OPTION, NULL, 0, 38 { "path", 0, NULL, MU_OPTION_DEFAULT,
50 N_("display parameters as paths") }, 39 N_("display parameters as paths"),
51 { "verbose", 'v', NULL, 0, 40 mu_c_bool, &path_option },
52 N_("increase output verbosity"), 0}, 41 { "verbose", 'v', NULL, MU_OPTION_DEFAULT,
53 { NULL } 42 N_("increase output verbosity"),
54 }; 43 mu_c_bool, &verbose_option },
55 44 MU_OPTION_END
56 static error_t
57 query_parse_opt (int key, char *arg, struct argp_state *state)
58 {
59 switch (key)
60 {
61 case 'f':
62 file_name = arg;
63 break;
64
65 case 'p':
66 hints.flags |= MU_CFG_PARSE_PROGRAM;
67 hints.program = arg;
68 break;
69
70 case 'v':
71 hints.flags |= MU_CFG_FMT_LOCUS;
72 break;
73
74 case VALUE_OPTION:
75 hints.flags |= MU_CFG_FMT_VALUE_ONLY;
76 break;
77
78 case PATH_OPTION:
79 hints.flags |= MU_CFG_FMT_PARAM_PATH;
80 break;
81
82 default:
83 return ARGP_ERR_UNKNOWN;
84 }
85 return 0;
86 }
87
88 static struct argp query_argp = {
89 query_options,
90 query_parse_opt,
91 query_args_doc,
92 query_doc,
93 NULL,
94 NULL,
95 NULL
96 }; 45 };
97 46
98 int 47 int
99 mutool_query (int argc, char **argv) 48 mutool_query (int argc, char **argv)
100 { 49 {
101 int index; 50 static struct mu_cfg_parse_hints hints;
102 mu_cfg_tree_t *tree = NULL; 51 mu_cfg_tree_t *tree = NULL;
103 52
104 if (argp_parse (&query_argp, argc, argv, ARGP_IN_ORDER, &index, NULL)) 53 mu_action_getopt (&argc, &argv, query_options, query_docstring,
105 return 1; 54 query_args_doc);
106
107 argc -= index;
108 argv += index;
109 55
110 if (argc == 0) 56 if (argc == 0)
111 { 57 {
...@@ -113,8 +59,21 @@ mutool_query (int argc, char **argv) ...@@ -113,8 +59,21 @@ mutool_query (int argc, char **argv)
113 return 1; 59 return 1;
114 } 60 }
115 61
116 hints.flags |= MU_CFG_PARSE_SITE_RCFILE | MU_PARSE_CONFIG_GLOBAL; 62 hints.flags = MU_CFG_PARSE_SITE_RCFILE | MU_PARSE_CONFIG_GLOBAL;
117 hints.site_rcfile = file_name ? file_name : mu_site_rcfile; 63 hints.site_rcfile = file_name ? file_name : mu_site_config_file ();
64
65 if (progname)
66 {
67 hints.flags |= MU_CFG_PARSE_PROGRAM;
68 hints.program = progname;
69 }
70
71 if (verbose_option)
72 hints.flags |= MU_CFG_FMT_LOCUS;
73 if (value_option)
74 hints.flags |= MU_CFG_FMT_VALUE_ONLY;
75 if (path_option)
76 hints.flags |= MU_CFG_FMT_PARAM_PATH;
118 77
119 if (mu_cfg_parse_config (&tree, &hints)) 78 if (mu_cfg_parse_config (&tree, &hints))
120 return 1; 79 return 1;
......
...@@ -14,17 +14,6 @@ ...@@ -14,17 +14,6 @@
14 You should have received a copy of the GNU General Public License 14 You should have received a copy of the GNU General Public License
15 along with GNU Mailutils. If not, see <http://www.gnu.org/licenses/>. */ 15 along with GNU Mailutils. If not, see <http://www.gnu.org/licenses/>. */
16 16
17 #ifdef HAVE_CONFIG_H
18 # include <config.h>
19 #endif
20 #include <unistd.h>
21 #include <stdio.h>
22 #include <stdlib.h>
23 #include <netdb.h>
24 #include <netinet/in.h>
25 #include <mailutils/cctype.h>
26 #include <mailutils/mailutils.h>
27 #include <argp.h>
28 #include "mu.h" 17 #include "mu.h"
29 18
30 static int read_recipients; 19 static int read_recipients;
...@@ -47,58 +36,40 @@ send_address_add (mu_address_t *paddr, const char *value) ...@@ -47,58 +36,40 @@ send_address_add (mu_address_t *paddr, const char *value)
47 mu_address_destroy (&addr); 36 mu_address_destroy (&addr);
48 } 37 }
49 38
50 static char send_doc[] = N_("mu send - send a message.");
51 char send_docstring[] = N_("send a message"); 39 char send_docstring[] = N_("send a message");
52 static char send_args_doc[] = "URL-or-HOST [FILE]"; 40 static char send_args_doc[] = "URL-or-HOST [FILE]";
53 41
54 static struct argp_option send_options[] = { 42 static void
55 { "from", 'F', N_("ADDRESS"), 0, 43 set_from_address (struct mu_parseopt *po, struct mu_option *opt,
56 N_("send mail from this ADDRESS") }, 44 char const *arg)
57 { "rcpt", 'T', N_("ADDRESS"), 0,
58 N_("send mail to this ADDRESS") },
59 { "read-recipients", 't', NULL, 0,
60 N_("read recipients from the message") },
61 { NULL }
62 };
63
64 static error_t
65 send_parse_opt (int key, char *arg, struct argp_state *state)
66 { 45 {
67 switch (key)
68 {
69 case 'F':
70 MU_ASSERT (mu_address_create_null (&from_addr)); 46 MU_ASSERT (mu_address_create_null (&from_addr));
71 send_address_add (&from_addr, arg); 47 send_address_add (&from_addr, arg);
72 break; 48 }
73 49
74 case 'T': 50 static void
51 set_rcpt_address (struct mu_parseopt *po, struct mu_option *opt,
52 char const *arg)
53 {
75 send_address_add (&rcpt_addr, arg); 54 send_address_add (&rcpt_addr, arg);
76 break;
77
78 case 't':
79 read_recipients = 1;
80 break;
81
82 default:
83 return ARGP_ERR_UNKNOWN;
84 }
85 return 0;
86 } 55 }
87 56
88 static struct argp send_argp = { 57 static struct mu_option send_options[] = {
89 send_options, 58 { "from", 'F', N_("ADDRESS"), MU_OPTION_DEFAULT,
90 send_parse_opt, 59 N_("send mail from this ADDRESS"),
91 send_args_doc, 60 mu_c_string, NULL, set_from_address },
92 send_doc, 61 { "rcpt", 'T', N_("ADDRESS"), MU_OPTION_DEFAULT,
93 NULL, 62 N_("send mail to this ADDRESS"),
94 NULL, 63 mu_c_string, NULL, set_rcpt_address },
95 NULL 64 { "read-recipients", 't', NULL, MU_OPTION_DEFAULT,
65 N_("read recipients from the message"),
66 mu_c_bool, &read_recipients },
67 MU_OPTION_END
96 }; 68 };
97 69
98 int 70 int
99 mutool_send (int argc, char **argv) 71 mutool_send (int argc, char **argv)
100 { 72 {
101 int index;
102 char *infile; 73 char *infile;
103 mu_stream_t instr; 74 mu_stream_t instr;
104 mu_message_t msg; 75 mu_message_t msg;
...@@ -109,11 +80,7 @@ mutool_send (int argc, char **argv) ...@@ -109,11 +80,7 @@ mutool_send (int argc, char **argv)
109 MU_ASSERT (mu_address_create_null (&rcpt_addr)); 80 MU_ASSERT (mu_address_create_null (&rcpt_addr));
110 mu_register_all_mailer_formats (); 81 mu_register_all_mailer_formats ();
111 82
112 if (argp_parse (&send_argp, argc, argv, 0, &index, NULL)) 83 mu_action_getopt (&argc, &argv, send_options, send_docstring, send_args_doc);
113 return 1;
114
115 argc -= index;
116 argv += index;
117 84
118 if (argc < 1) 85 if (argc < 1)
119 { 86 {
......
...@@ -14,17 +14,9 @@ ...@@ -14,17 +14,9 @@
14 You should have received a copy of the GNU General Public License 14 You should have received a copy of the GNU General Public License
15 along with GNU Mailutils. If not, see <http://www.gnu.org/licenses/>. */ 15 along with GNU Mailutils. If not, see <http://www.gnu.org/licenses/>. */
16 16
17 #if defined(HAVE_CONFIG_H) 17 #include "mu.h"
18 # include <config.h>
19 #endif
20 #include <stdlib.h>
21 #include <string.h>
22 #include <signal.h> 18 #include <signal.h>
23 #include <mailutils/mailutils.h>
24 #include <mailutils/tls.h>
25 #include "mailutils/libargp.h"
26 #include "muaux.h" 19 #include "muaux.h"
27 #include "mu.h"
28 20
29 #ifdef WITH_READLINE 21 #ifdef WITH_READLINE
30 # include <readline/readline.h> 22 # include <readline/readline.h>
......
...@@ -28,34 +28,7 @@ ...@@ -28,34 +28,7 @@
28 #include <argp.h> 28 #include <argp.h>
29 #include "mu.h" 29 #include "mu.h"
30 30
31 static char smtp_doc[] = N_("mu smtp - run a SMTP session.");
32 char smtp_docstring[] = N_("run a SMTP session"); 31 char smtp_docstring[] = N_("run a SMTP session");
33 static char smtp_args_doc[] = "";
34
35 static struct argp_option smtp_options[] = {
36 { NULL }
37 };
38
39 static error_t
40 smtp_parse_opt (int key, char *arg, struct argp_state *state)
41 {
42 switch (key)
43 {
44 default:
45 return ARGP_ERR_UNKNOWN;
46 }
47 return 0;
48 }
49
50 static struct argp smtp_argp = {
51 smtp_options,
52 smtp_parse_opt,
53 smtp_args_doc,
54 smtp_doc,
55 NULL,
56 NULL,
57 NULL
58 };
59 32
60 enum smtp_session_status 33 enum smtp_session_status
61 { 34 {
...@@ -958,16 +931,10 @@ struct mutool_command smtp_comtab[] = { ...@@ -958,16 +931,10 @@ struct mutool_command smtp_comtab[] = {
958 int 931 int
959 mutool_smtp (int argc, char **argv) 932 mutool_smtp (int argc, char **argv)
960 { 933 {
961 int index;
962
963 mu_registrar_record (mu_smtp_record); 934 mu_registrar_record (mu_smtp_record);
964 mu_registrar_record (mu_smtps_record); 935 mu_registrar_record (mu_smtps_record);
965 936
966 if (argp_parse (&smtp_argp, argc, argv, 0, &index, NULL)) 937 mu_action_getopt (&argc, &argv, NULL, smtp_docstring, NULL);
967 return 1;
968
969 argc -= index;
970
971 if (argc) 938 if (argc)
972 { 939 {
973 mu_error (_("bad arguments")); 940 mu_error (_("bad arguments"));
......
...@@ -14,14 +14,6 @@ ...@@ -14,14 +14,6 @@
14 You should have received a copy of the GNU General Public License 14 You should have received a copy of the GNU General Public License
15 along with GNU Mailutils. If not, see <http://www.gnu.org/licenses/>. */ 15 along with GNU Mailutils. If not, see <http://www.gnu.org/licenses/>. */
16 16
17 #if defined(HAVE_CONFIG_H)
18 # include <config.h>
19 #endif
20
21 #include <stdlib.h>
22 #include <arpa/inet.h>
23 #include <netinet/in.h>
24 #include <mailutils/mailutils.h>
25 #include "mu.h" 17 #include "mu.h"
26 18
27 int 19 int
......
...@@ -14,12 +14,6 @@ ...@@ -14,12 +14,6 @@
14 You should have received a copy of the GNU General Public License 14 You should have received a copy of the GNU General Public License
15 along with GNU Mailutils. If not, see <http://www.gnu.org/licenses/>. */ 15 along with GNU Mailutils. If not, see <http://www.gnu.org/licenses/>. */
16 16
17 #if defined(HAVE_CONFIG_H)
18 # include <config.h>
19 #endif
20 #include <stdlib.h>
21 #include <string.h>
22 #include <mailutils/mailutils.h>
23 #include "mu.h" 17 #include "mu.h"
24 18
25 /* Manipulations with verbosity flags, which are common for pop and imap. */ 19 /* Manipulations with verbosity flags, which are common for pop and imap. */
......
...@@ -14,59 +14,32 @@ ...@@ -14,59 +14,32 @@
14 You should have received a copy of the GNU General Public License 14 You should have received a copy of the GNU General Public License
15 along with GNU Mailutils. If not, see <http://www.gnu.org/licenses/>. */ 15 along with GNU Mailutils. If not, see <http://www.gnu.org/licenses/>. */
16 16
17 #if defined(HAVE_CONFIG_H) 17 #include "mu.h"
18 # include <config.h> 18
19 #endif
20 #include <stdlib.h>
21 #include <mailutils/mailutils.h>
22 #include <mailutils/libcfg.h>
23 #include <argp.h>
24
25 static char wicket_doc[] = N_("mu wicket - find matching URL in wicket");
26 char wicket_docstring[] = N_("scan wickets for matching URLs"); 19 char wicket_docstring[] = N_("scan wickets for matching URLs");
27 static char wicket_args_doc[] = N_("URL"); 20 static char wicket_args_doc[] = N_("URL");
28 21
29 static struct argp_option wicket_options[] = {
30 { "file", 'f', N_("FILE"), 0, N_("use FILE instead of ~/.mu-tickets") },
31 { "verbose", 'v', NULL, 0, N_("increase output verbosity") },
32 { "quiet", 'q', NULL, 0, N_("suppress any output") },
33 { NULL }
34 };
35
36 static char *wicket_file = "~/.mu-tickets"; 22 static char *wicket_file = "~/.mu-tickets";
37 static int wicket_verbose = 1; 23 static int wicket_verbose = 1;
38 24
39 static error_t 25 static void
40 wicket_parse_opt (int key, char *arg, struct argp_state *state) 26 clear_wicket_verbose (struct mu_parseopt *po, struct mu_option *opt,
27 char const *arg)
41 { 28 {
42 switch (key)
43 {
44 case 'f':
45 wicket_file = arg;
46 break;
47
48 case 'v':
49 wicket_verbose++;
50 break;
51
52 case 'q':
53 wicket_verbose = 0; 29 wicket_verbose = 0;
54 break;
55
56 default:
57 return ARGP_ERR_UNKNOWN;
58 }
59 return 0;
60 } 30 }
61 31
62 static struct argp wicket_argp = { 32 static struct mu_option wicket_options[] = {
63 wicket_options, 33 { "file", 'f', N_("FILE"), MU_OPTION_DEFAULT,
64 wicket_parse_opt, 34 N_("use FILE instead of ~/.mu-tickets"),
65 wicket_args_doc, 35 mu_c_string, &wicket_file },
66 wicket_doc, 36 { "verbose", 'v', NULL, MU_OPTION_DEFAULT,
67 NULL, 37 N_("increase output verbosity"),
68 NULL, 38 mu_c_string, &wicket_verbose },
69 NULL 39 { "quiet", 'q', NULL, MU_OPTION_DEFAULT,
40 N_("suppress any output"),
41 mu_c_string, NULL, clear_wicket_verbose },
42 { NULL }
70 }; 43 };
71 44
72 45
...@@ -129,12 +102,8 @@ mutool_wicket (int argc, char **argv) ...@@ -129,12 +102,8 @@ mutool_wicket (int argc, char **argv)
129 mu_stream_t stream; 102 mu_stream_t stream;
130 int rc, i, exit_code; 103 int rc, i, exit_code;
131 104
132 if (argp_parse (&wicket_argp, argc, argv, ARGP_IN_ORDER, &i, NULL)) 105 mu_action_getopt (&argc, &argv, wicket_options, wicket_docstring,
133 return 1; 106 wicket_args_doc);
134
135 argc -= i;
136 argv += i;
137
138 if (argc == 0) 107 if (argc == 0)
139 { 108 {
140 mu_error (_("not enough arguments")); 109 mu_error (_("not enough arguments"));
......
...@@ -33,29 +33,11 @@ lib/tcpwrap.c ...@@ -33,29 +33,11 @@ lib/tcpwrap.c
33 lib/strexit.c 33 lib/strexit.c
34 lib/manlock.c 34 lib/manlock.c
35 35
36 libmu_argp/cmdline.c
37 libmu_argp/common.c
38 libmu_argp/mu_argp.c
39 libmu_argp/sieve.c
40
41 libmu_auth/ldap.c 36 libmu_auth/ldap.c
42 libmu_auth/radius.c 37 libmu_auth/radius.c
43 libmu_auth/sql.c 38 libmu_auth/sql.c
44 libmu_auth/tls.c 39 libmu_auth/tls.c
45 40
46 libmu_cfg/acl.c
47 libmu_cfg/auth.c
48 libmu_cfg/common.c
49 libmu_cfg/gsasl.c
50 libmu_cfg/init.c
51 libmu_cfg/ldap.c
52 libmu_cfg/pam.c
53 libmu_cfg/radius.c
54 libmu_cfg/sieve.c
55 libmu_cfg/sql.c
56 libmu_cfg/tls.c
57 libmu_cfg/virtdomain.c
58
59 libmu_sieve/actions.c 41 libmu_sieve/actions.c
60 libmu_sieve/comparator.c 42 libmu_sieve/comparator.c
61 libmu_sieve/conf.c 43 libmu_sieve/conf.c
...@@ -117,7 +99,6 @@ libmailutils/cfg/driver.c ...@@ -117,7 +99,6 @@ libmailutils/cfg/driver.c
117 libmailutils/cfg/format.c 99 libmailutils/cfg/format.c
118 libmailutils/cfg/lexer.l 100 libmailutils/cfg/lexer.l
119 libmailutils/cfg/parser.y 101 libmailutils/cfg/parser.y
120 libmailutils/cfg/gocs.c
121 102
122 libmailutils/diag/debug.c 103 libmailutils/diag/debug.c
123 libmailutils/diag/diag.c 104 libmailutils/diag/diag.c
......
...@@ -65,7 +65,7 @@ pop3d_LDADD = \ ...@@ -65,7 +65,7 @@ pop3d_LDADD = \
65 65
66 popauth_SOURCES = popauth.c 66 popauth_SOURCES = popauth.c
67 popauth_LDADD = \ 67 popauth_LDADD = \
68 ${MU_APP_LIBRARIES}\ 68 ${MU_APP_NEW_LIBRARIES}\
69 ${MU_LIB_MAILUTILS}\ 69 ${MU_LIB_MAILUTILS}\
70 @MU_COMMON_LIBRARIES@\ 70 @MU_COMMON_LIBRARIES@\
71 ${LIBMU_DBM}\ 71 ${LIBMU_DBM}\
......
...@@ -104,8 +104,7 @@ static struct mu_option pop3d_options[] = { ...@@ -104,8 +104,7 @@ static struct mu_option pop3d_options[] = {
104 { "daemon", 'd', N_("NUMBER"), MU_OPTION_ARG_OPTIONAL, 104 { "daemon", 'd', N_("NUMBER"), MU_OPTION_ARG_OPTIONAL,
105 N_("runs in daemon mode with a maximum of NUMBER children"), 105 N_("runs in daemon mode with a maximum of NUMBER children"),
106 mu_c_string, NULL, set_daemon_mode }, 106 mu_c_string, NULL, set_daemon_mode },
107 107 MU_OPTION_END
108 {NULL, 0, NULL, 0, NULL, 0}
109 }, *options[] = { pop3d_options, NULL }; 108 }, *options[] = { pop3d_options, NULL };
110 109
111 static int 110 static int
...@@ -308,7 +307,6 @@ static char *capa[] = { ...@@ -308,7 +307,6 @@ static char *capa[] = {
308 "mailbox", 307 "mailbox",
309 "locking", 308 "locking",
310 "logging", 309 "logging",
311 "tls",
312 NULL 310 NULL
313 }; 311 };
314 312
...@@ -585,7 +583,6 @@ main (int argc, char **argv) ...@@ -585,7 +583,6 @@ main (int argc, char **argv)
585 #ifdef ENABLE_DBM 583 #ifdef ENABLE_DBM
586 set_dbm_safety (); 584 set_dbm_safety ();
587 #endif 585 #endif
588 mu_cli_capa_register (&mu_cli_capa_tls);
589 586
590 mu_cli (argc, argv, &cli, capa, server, &argc, &argv); 587 mu_cli (argc, argv, &cli, capa, server, &argc, &argv);
591 if (argc) 588 if (argc)
......
...@@ -121,6 +121,7 @@ extern int expire_on_exit; ...@@ -121,6 +121,7 @@ extern int expire_on_exit;
121 #include <mailutils/filter.h> 121 #include <mailutils/filter.h>
122 #include <mailutils/stdstream.h> 122 #include <mailutils/stdstream.h>
123 #include <mailutils/stream.h> 123 #include <mailutils/stream.h>
124 #include "mailutils/syslog.h"
124 125
125 /* For Berkley DB2 APOP password file */ 126 /* For Berkley DB2 APOP password file */
126 #ifdef HAVE_DB_H 127 #ifdef HAVE_DB_H
......
...@@ -21,6 +21,7 @@ ...@@ -21,6 +21,7 @@
21 21
22 #include "readmsg.h" 22 #include "readmsg.h"
23 #include "mailutils/cli.h" 23 #include "mailutils/cli.h"
24 #include "mailutils/mu_auth.h"
24 #include "mu_umaxtostr.h" 25 #include "mu_umaxtostr.h"
25 26
26 #define WEEDLIST_SEPARATOR " :," 27 #define WEEDLIST_SEPARATOR " :,"
...@@ -94,7 +95,6 @@ static char *readmsg_argp_capa[] = { ...@@ -94,7 +95,6 @@ static char *readmsg_argp_capa[] = {
94 "debug", 95 "debug",
95 "mailbox", 96 "mailbox",
96 "locking", 97 "locking",
97 "tls",
98 NULL 98 NULL
99 }; 99 };
100 100
...@@ -242,7 +242,7 @@ main (int argc, char **argv) ...@@ -242,7 +242,7 @@ main (int argc, char **argv)
242 mu_register_all_mbox_formats (); 242 mu_register_all_mbox_formats ();
243 mu_register_extra_formats (); 243 mu_register_extra_formats ();
244 244
245 mu_cli_capa_register (&mu_cli_capa_tls); 245 mu_auth_register_module (&mu_auth_tls_module);
246 246
247 mu_cli (argc, argv, &cli, readmsg_argp_capa, NULL, &argc, &argv); 247 mu_cli (argc, argv, &cli, readmsg_argp_capa, NULL, &argc, &argv);
248 248
......
...@@ -44,6 +44,7 @@ ...@@ -44,6 +44,7 @@
44 #include <mailutils/nls.h> 44 #include <mailutils/nls.h>
45 #include <mailutils/tls.h> 45 #include <mailutils/tls.h>
46 #include <mailutils/cli.h> 46 #include <mailutils/cli.h>
47 #include <mailutils/mu_auth.h>
47 48
48 #define D_DEFAULT "TPt" 49 #define D_DEFAULT "TPt"
49 50
...@@ -238,7 +239,6 @@ static char *sieve_argp_capa[] = { ...@@ -238,7 +239,6 @@ static char *sieve_argp_capa[] = {
238 "locking", 239 "locking",
239 "logging", 240 "logging",
240 "mailer", 241 "mailer",
241 "tls",
242 "sieve", 242 "sieve",
243 NULL 243 NULL
244 }; 244 };
...@@ -394,7 +394,7 @@ main (int argc, char *argv[]) ...@@ -394,7 +394,7 @@ main (int argc, char *argv[])
394 /* Native Language Support */ 394 /* Native Language Support */
395 MU_APP_INIT_NLS (); 395 MU_APP_INIT_NLS ();
396 396
397 mu_cli_capa_register (&mu_cli_capa_tls); 397 mu_auth_register_module (&mu_auth_tls_module);
398 mu_cli_capa_register (&mu_cli_capa_sieve); 398 mu_cli_capa_register (&mu_cli_capa_sieve);
399 mu_sieve_debug_init (); 399 mu_sieve_debug_init ();
400 400
......
...@@ -69,7 +69,7 @@ add_disptab (mu_sql_dispatch_t *tab) ...@@ -69,7 +69,7 @@ add_disptab (mu_sql_dispatch_t *tab)
69 #endif 69 #endif
70 70
71 int 71 int
72 mu_sql_interface_index (char *name) 72 mu_sql_interface_index (char const *name)
73 { 73 {
74 int i; 74 int i;
75 //mu_sql_dispatch_t *tab; 75 //mu_sql_dispatch_t *tab;
......