Move rc file and argp parsing into separate abstract layers.
* include/mailutils/gocs.h, include/mailutils/pam.h, include/mailutils/radius.h, include/mailutils/syslog.h: New files * lib/argpinit.c, lib/muinit.c, lib/muinit.h: New files. * libsieve/conf.c: New file. * libcfg: New directory * libcfg/libcfg.h, libcfg/auth.c, libcfg/common.c, libcfg/init.c, libcfg/gsasl.c, libcfg/pam.c, libcfg/radius.c, libcfg/sieve.c, libcfg/sql.c, libcfg/tls.c, libcfg/virtdomain.c, libcfg/.cvsignore: New files. * libargp: New directory * libargp/auth.c, libargp/cmdline.h, libargp/common.c, libargp/gsasl.c, libargp/mu_argp.h, libargp/mu_argp.c, libargp/pam.c, libargp/radius.c, libargp/sieve.c, libargp/sql.c, libargp/tls.c, libargp/virtdomain.c, libargp/.cvsignore: New files. * mailbox/.cvsignore: Add cfg_parser.c and cfg_parser.h. * Makefile.am (SUBDIRS): Add libargp and libcfg. * configure.ac (MU_APP_LIBRARIES): New variable (MU_COMMON_INCLUDES): add libargp and libcfg (AC_CONFIG_FILES): Add libargp and libcfg. * auth/gsasl.c, auth/pam.c, auth/radius.c, auth/sql.c, auth/sql.h, auth/tls.c, auth/virtual.c, comsat/comsat.h, frm/frm.h, guimb/guimb.h, imap4d/imap4d.h, include/mailutils/gsasl.h, include/mailutils/libsieve.h, include/mailutils/mailutils.h, include/mailutils/mu_auth.h, include/mailutils/tls.h, include/mailutils/sql.h, maidag/maidag.h, mail/mail.h, mail.local/mail.local.h, mailbox/daemon.c, mailbox/system.c, mh/mh_argp.c, mh/mh_getopt.h, pop3d/pop3d.h, readmsg/readmsg.h: Remove argp stuff * comsat/comsat.c, config/mailutils-config.c, dotlock/dotlock.c, examples/muauth.c, examples/muemail.c, frm/frm.c, frm/from.c, guimb/main.c, imap4d/idle.c, imap4d/imap4d.c, imap4d/util.c, imap4d/version.c, maidag/lmtp.c, maidag/maidag.c, maidag/mailquota.c, mail/mail.c, mail/send.c, mail/version.c, mail.local/mailquota.c, mail.local/main.c, mail.remote/mail.remote.c, mailbox/mu_auth.c, messages/messages.c, mimeview/mimeview.c, movemail/movemail.c, pop3d/extra.c, pop3d/pop3d.c, pop3d/popauth.c, readmsg/readmsg.c, sieve/sieve.c: Use mu_app_init for parsing command line and configuration files. * comsat/Makefile.am, config/Makefile.am, dotlock/Makefile.am, examples/Makefile.am, frm/Makefile.am, guimb/Makefile.am, imap4d/Makefile.am, maidag/Makefile.am, mail/Makefile.am, mail.local/Makefile.am, mail.remote/Makefile.am, mailbox/Makefile.am, messages/Makefile.am, mimeview/Makefile.am, movemail/Makefile.am, pop3d/Makefile.am, readmsg/Makefile.am, sieve/Makefile.am: Use MU_APP_LIBRARIES. * include/mailutils/Makefile.am: Add new files. * include/mailutils/argp.h: Remove. * include/mailutils/cfg.h: New file. * include/mailutils/daemon.h (MODE_INTERACTIVE,MODE_DAEMON): New defines (from removed argp.h). (mu_gocs_daemon): New decl. * include/mailutils/error.h (mu_program_name): New variable (mu_set_program_name): New function. * lib/Makefile.am (libmuaux_la_SOURCES): Add new files. * libsieve/Makefile.am (libsieve_la_SOURCES): Remove argp.c, add conf.c instead. * libsieve/argp.c: Remove. * mailbox/cfg_parser.y (mu_cfg_parse_boolean): New function. * mailbox/mu_argp.c: Remove. * mailbox/muerror.c (mu_program_name): New variable (mu_set_program_name): New function (mu_default_error_printer): Print program name before diagnostic string. * mailbox/mutil.c (mu_sql_decode_password_type): New function. * mh/mh_whom.c (mh_alias_expand): Bugfix * po/POTFILES.in: Update * testsuite/lib/mailutils.exp (mu_init): Pass --no-site-rcfile --no-user-rcfile to all programs.
Showing
126 changed files
with
3556 additions
and
2554 deletions
1 | 2007-11-17 Sergey Poznyakoff <gray@gnu.org.ua> | ||
2 | |||
3 | Move rc file and argp parsing into separate abstract layers. | ||
4 | |||
5 | * include/mailutils/gocs.h, include/mailutils/pam.h, | ||
6 | include/mailutils/radius.h, include/mailutils/syslog.h: New files | ||
7 | * lib/argpinit.c, lib/muinit.c, lib/muinit.h: New files. | ||
8 | * libsieve/conf.c: New file. | ||
9 | |||
10 | * libcfg: New directory | ||
11 | * libcfg/libcfg.h, libcfg/auth.c, libcfg/common.c, libcfg/init.c, | ||
12 | libcfg/gsasl.c, libcfg/pam.c, libcfg/radius.c, libcfg/sieve.c, | ||
13 | libcfg/sql.c, libcfg/tls.c, libcfg/virtdomain.c, | ||
14 | libcfg/.cvsignore: New files. | ||
15 | |||
16 | * libargp: New directory | ||
17 | * libargp/auth.c, libargp/cmdline.h, libargp/common.c, | ||
18 | libargp/gsasl.c, libargp/mu_argp.h, libargp/mu_argp.c, | ||
19 | libargp/pam.c, libargp/radius.c, libargp/sieve.c, libargp/sql.c, | ||
20 | libargp/tls.c, libargp/virtdomain.c, libargp/.cvsignore: New | ||
21 | files. | ||
22 | |||
23 | * mailbox/.cvsignore: Add cfg_parser.c and cfg_parser.h. | ||
24 | * Makefile.am (SUBDIRS): Add libargp and libcfg. | ||
25 | * configure.ac (MU_APP_LIBRARIES): New variable | ||
26 | (MU_COMMON_INCLUDES): add libargp and libcfg | ||
27 | (AC_CONFIG_FILES): Add libargp and libcfg. | ||
28 | |||
29 | * auth/gsasl.c, auth/pam.c, auth/radius.c, auth/sql.c, auth/sql.h, | ||
30 | auth/tls.c, auth/virtual.c, comsat/comsat.h, frm/frm.h, | ||
31 | guimb/guimb.h, imap4d/imap4d.h, include/mailutils/gsasl.h, | ||
32 | include/mailutils/libsieve.h, include/mailutils/mailutils.h, | ||
33 | include/mailutils/mu_auth.h, include/mailutils/tls.h, | ||
34 | include/mailutils/sql.h, maidag/maidag.h, mail/mail.h, | ||
35 | mail.local/mail.local.h, mailbox/daemon.c, mailbox/system.c, | ||
36 | mh/mh_argp.c, mh/mh_getopt.h, pop3d/pop3d.h, | ||
37 | readmsg/readmsg.h: Remove argp stuff | ||
38 | |||
39 | * comsat/comsat.c, config/mailutils-config.c, dotlock/dotlock.c, | ||
40 | examples/muauth.c, examples/muemail.c, frm/frm.c, frm/from.c, | ||
41 | guimb/main.c, imap4d/idle.c, imap4d/imap4d.c, imap4d/util.c, | ||
42 | imap4d/version.c, maidag/lmtp.c, maidag/maidag.c, | ||
43 | maidag/mailquota.c, mail/mail.c, mail/send.c, mail/version.c, | ||
44 | mail.local/mailquota.c, mail.local/main.c, | ||
45 | mail.remote/mail.remote.c, mailbox/mu_auth.c, messages/messages.c, | ||
46 | mimeview/mimeview.c, movemail/movemail.c, pop3d/extra.c, | ||
47 | pop3d/pop3d.c, pop3d/popauth.c, readmsg/readmsg.c, sieve/sieve.c: | ||
48 | Use mu_app_init for parsing command line and | ||
49 | configuration files. | ||
50 | * comsat/Makefile.am, config/Makefile.am, dotlock/Makefile.am, | ||
51 | examples/Makefile.am, frm/Makefile.am, guimb/Makefile.am, | ||
52 | imap4d/Makefile.am, maidag/Makefile.am, mail/Makefile.am, | ||
53 | mail.local/Makefile.am, mail.remote/Makefile.am, | ||
54 | mailbox/Makefile.am, messages/Makefile.am, mimeview/Makefile.am, | ||
55 | movemail/Makefile.am, pop3d/Makefile.am, readmsg/Makefile.am, | ||
56 | sieve/Makefile.am: Use MU_APP_LIBRARIES. | ||
57 | |||
58 | * include/mailutils/Makefile.am: Add new files. | ||
59 | * include/mailutils/argp.h: Remove. | ||
60 | * include/mailutils/cfg.h: New file. | ||
61 | * include/mailutils/daemon.h (MODE_INTERACTIVE,MODE_DAEMON): New | ||
62 | defines (from removed argp.h). | ||
63 | (mu_gocs_daemon): New decl. | ||
64 | * include/mailutils/error.h (mu_program_name): New variable | ||
65 | (mu_set_program_name): New function. | ||
66 | * lib/Makefile.am (libmuaux_la_SOURCES): Add new files. | ||
67 | * libsieve/Makefile.am (libsieve_la_SOURCES): Remove argp.c, add | ||
68 | conf.c instead. | ||
69 | * libsieve/argp.c: Remove. | ||
70 | |||
71 | * mailbox/cfg_parser.y (mu_cfg_parse_boolean): New function. | ||
72 | * mailbox/mu_argp.c: Remove. | ||
73 | |||
74 | * mailbox/muerror.c (mu_program_name): New variable | ||
75 | (mu_set_program_name): New function | ||
76 | (mu_default_error_printer): Print program name before diagnostic | ||
77 | string. | ||
78 | * mailbox/mutil.c (mu_sql_decode_password_type): New function. | ||
79 | * mh/mh_whom.c (mh_alias_expand): Bugfix | ||
80 | * po/POTFILES.in: Update | ||
81 | * testsuite/lib/mailutils.exp (mu_init): Pass --no-site-rcfile | ||
82 | --no-user-rcfile to all programs. | ||
83 | |||
1 | 2007-11-12 Sergey Poznyakoff <gray@gnu.org.ua> | 84 | 2007-11-12 Sergey Poznyakoff <gray@gnu.org.ua> |
2 | 85 | ||
3 | * maidag/lmtp.c: Use English reply texts. | 86 | * maidag/lmtp.c: Use English reply texts. | ... | ... |
... | @@ -26,7 +26,6 @@ | ... | @@ -26,7 +26,6 @@ |
26 | #include <string.h> | 26 | #include <string.h> |
27 | #include <limits.h> | 27 | #include <limits.h> |
28 | #include <unistd.h> | 28 | #include <unistd.h> |
29 | #include <mailutils/argp.h> | ||
30 | #include <mailutils/error.h> | 29 | #include <mailutils/error.h> |
31 | #include <mailutils/errno.h> | 30 | #include <mailutils/errno.h> |
32 | #include <mailutils/mu_auth.h> | 31 | #include <mailutils/mu_auth.h> |
... | @@ -36,54 +35,21 @@ | ... | @@ -36,54 +35,21 @@ |
36 | #include <gsasl.h> | 35 | #include <gsasl.h> |
37 | #include <lbuf.h> | 36 | #include <lbuf.h> |
38 | 37 | ||
39 | char *mu_gsasl_cram_md5_pwd = SITE_CRAM_MD5_PWD; | 38 | struct mu_gsasl_module_data mu_gsasl_module_data; |
40 | 39 | ||
41 | #define ARG_CRAM_PASSWD 1 | 40 | int |
42 | 41 | mu_gsasl_module_init (void *data) | |
43 | static struct argp_option _gsasl_argp_options[] = { | ||
44 | {"cram-passwd", ARG_CRAM_PASSWD, N_("FILE"), OPTION_HIDDEN, | ||
45 | N_("Specify password file for CRAM-MD5 authentication"), 0}, | ||
46 | { NULL, 0, NULL, 0, NULL, 0 } | ||
47 | }; | ||
48 | |||
49 | static error_t | ||
50 | _gsasl_argp_parser (int key, char *arg, struct argp_state *state) | ||
51 | { | 42 | { |
52 | switch (key) | 43 | static struct mu_gsasl_module_data _default_module_data = { |
53 | { | 44 | SITE_CRAM_MD5_PWD |
54 | case ARG_CRAM_PASSWD: | 45 | }; |
55 | mu_gsasl_cram_md5_pwd = arg; | ||
56 | break; | ||
57 | 46 | ||
58 | default: | 47 | if (!data) |
59 | return ARGP_ERR_UNKNOWN; | 48 | mu_gsasl_module_data = _default_module_data; |
60 | } | 49 | memcpy (&mu_gsasl_module_data, data, sizeof (mu_gsasl_module_data)); |
61 | return 0; | 50 | return 0; |
62 | } | 51 | } |
63 | 52 | ||
64 | static struct argp _gsasl_argp = { | ||
65 | _gsasl_argp_options, | ||
66 | _gsasl_argp_parser | ||
67 | }; | ||
68 | |||
69 | static struct argp_child _gsasl_argp_child = { | ||
70 | &_gsasl_argp, | ||
71 | 0, | ||
72 | NULL, | ||
73 | 0 | ||
74 | }; | ||
75 | |||
76 | void | ||
77 | mu_gsasl_init_argp () | ||
78 | { | ||
79 | if (mu_register_capa ("gsasl", &_gsasl_argp_child, NULL)) | ||
80 | { | ||
81 | mu_error (_("INTERNAL ERROR: cannot register argp capability gsasl")); | ||
82 | abort (); | ||
83 | } | ||
84 | } | ||
85 | |||
86 | |||
87 | struct _gsasl_stream { | 53 | struct _gsasl_stream { |
88 | Gsasl_session_ctx *sess_ctx; /* Context */ | 54 | Gsasl_session_ctx *sess_ctx; /* Context */ |
89 | int last_err; /* Last Gsasl error code */ | 55 | int last_err; /* Last Gsasl error code */ | ... | ... |
... | @@ -43,11 +43,10 @@ | ... | @@ -43,11 +43,10 @@ |
43 | #include <mailutils/list.h> | 43 | #include <mailutils/list.h> |
44 | #include <mailutils/iterator.h> | 44 | #include <mailutils/iterator.h> |
45 | #include <mailutils/mailbox.h> | 45 | #include <mailutils/mailbox.h> |
46 | #include <mailutils/argp.h> | ||
47 | #include <mailutils/mu_auth.h> | 46 | #include <mailutils/mu_auth.h> |
48 | #include <mailutils/nls.h> | 47 | #include <mailutils/nls.h> |
49 | 48 | ||
50 | char *pam_service = NULL; | 49 | char *mu_pam_service = NULL; |
51 | 50 | ||
52 | #ifdef USE_LIBPAM | 51 | #ifdef USE_LIBPAM |
53 | #define COPY_STRING(s) (s) ? strdup(s) : NULL | 52 | #define COPY_STRING(s) (s) ? strdup(s) : NULL |
... | @@ -120,7 +119,7 @@ mu_authenticate_pam (struct mu_auth_data **return_data MU_ARG_UNUSED, | ... | @@ -120,7 +119,7 @@ mu_authenticate_pam (struct mu_auth_data **return_data MU_ARG_UNUSED, |
120 | 119 | ||
121 | _user = (char *) auth_data->name; | 120 | _user = (char *) auth_data->name; |
122 | _pwd = pass; | 121 | _pwd = pass; |
123 | pamerror = pam_start (pam_service, _user, &PAM_conversation, &pamh); | 122 | pamerror = pam_start (mu_pam_service, _user, &PAM_conversation, &pamh); |
124 | PAM_ERROR; | 123 | PAM_ERROR; |
125 | pamerror = pam_authenticate (pamh, 0); | 124 | pamerror = pam_authenticate (pamh, 0); |
126 | PAM_ERROR; | 125 | PAM_ERROR; |
... | @@ -132,39 +131,6 @@ mu_authenticate_pam (struct mu_auth_data **return_data MU_ARG_UNUSED, | ... | @@ -132,39 +131,6 @@ mu_authenticate_pam (struct mu_auth_data **return_data MU_ARG_UNUSED, |
132 | return pamerror != PAM_SUCCESS; | 131 | return pamerror != PAM_SUCCESS; |
133 | } | 132 | } |
134 | 133 | ||
135 | #define ARG_PAM_SERVICE 1 | ||
136 | |||
137 | static error_t | ||
138 | mu_pam_argp_parser (int key, char *arg, struct argp_state *state) | ||
139 | { | ||
140 | switch (key) | ||
141 | { | ||
142 | case ARG_PAM_SERVICE: | ||
143 | pam_service = arg; | ||
144 | break; | ||
145 | |||
146 | default: | ||
147 | return ARGP_ERR_UNKNOWN; | ||
148 | } | ||
149 | return 0; | ||
150 | } | ||
151 | |||
152 | static struct argp_option mu_pam_argp_option[] = { | ||
153 | { "pam-service", ARG_PAM_SERVICE, N_("STRING"), OPTION_HIDDEN, | ||
154 | N_("Use STRING as PAM service name"), 0}, | ||
155 | { NULL, 0, NULL, 0, NULL, 0 } | ||
156 | }; | ||
157 | |||
158 | struct argp mu_pam_argp = { | ||
159 | mu_pam_argp_option, | ||
160 | mu_pam_argp_parser, | ||
161 | }; | ||
162 | |||
163 | static struct mu_cfg_param pam_cfg_param[] = { | ||
164 | { "service", mu_cfg_string, &pam_service }, | ||
165 | { NULL } | ||
166 | }; | ||
167 | |||
168 | #else | 134 | #else |
169 | 135 | ||
170 | int | 136 | int |
... | @@ -179,15 +145,17 @@ mu_authenticate_pam (struct mu_auth_data **return_data MU_ARG_UNUSED, | ... | @@ -179,15 +145,17 @@ mu_authenticate_pam (struct mu_auth_data **return_data MU_ARG_UNUSED, |
179 | 145 | ||
180 | #endif | 146 | #endif |
181 | 147 | ||
148 | int | ||
149 | mu_pam_module_init (void *data) | ||
150 | { | ||
151 | if (data) | ||
152 | mu_pam_service = strdup (data); | ||
153 | return 0; | ||
154 | } | ||
155 | |||
182 | struct mu_auth_module mu_auth_pam_module = { | 156 | struct mu_auth_module mu_auth_pam_module = { |
183 | "pam", | 157 | "pam", |
184 | #ifdef USE_LIBPAM | 158 | mu_pam_module_init, |
185 | &mu_pam_argp, | ||
186 | pam_cfg_param, | ||
187 | #else | ||
188 | NULL, | ||
189 | NULL, | ||
190 | #endif | ||
191 | mu_authenticate_pam, | 159 | mu_authenticate_pam, |
192 | NULL, | 160 | NULL, |
193 | mu_auth_nosupport, | 161 | mu_auth_nosupport, | ... | ... |
... | @@ -34,7 +34,7 @@ | ... | @@ -34,7 +34,7 @@ |
34 | #include <mailutils/list.h> | 34 | #include <mailutils/list.h> |
35 | #include <mailutils/iterator.h> | 35 | #include <mailutils/iterator.h> |
36 | #include <mailutils/mailbox.h> | 36 | #include <mailutils/mailbox.h> |
37 | #include <mailutils/argp.h> | 37 | #include <mailutils/radius.h> |
38 | #include <mailutils/argcv.h> | 38 | #include <mailutils/argcv.h> |
39 | #include <mailutils/mu_auth.h> | 39 | #include <mailutils/mu_auth.h> |
40 | #include <mailutils/error.h> | 40 | #include <mailutils/error.h> |
... | @@ -45,39 +45,6 @@ | ... | @@ -45,39 +45,6 @@ |
45 | 45 | ||
46 | #include <radius/radius.h> | 46 | #include <radius/radius.h> |
47 | 47 | ||
48 | #define ARG_AUTH_REQUEST 256 | ||
49 | #define ARG_GETPWNAM_REQUEST 257 | ||
50 | #define ARG_GETPWUID_REQUEST 258 | ||
51 | #define ARG_RADIUS_DIR 259 | ||
52 | |||
53 | static struct argp_option mu_radius_argp_option[] = { | ||
54 | { "radius-auth-request", ARG_AUTH_REQUEST, N_("REQUEST"), OPTION_HIDDEN, | ||
55 | N_("Radius request to authenitcate the user"), 0 }, | ||
56 | { "radius-getpwnam-request", ARG_GETPWNAM_REQUEST, N_("REQUEST"), OPTION_HIDDEN, | ||
57 | N_("Radius request to retrieve a passwd entry based on username"), 0 }, | ||
58 | { "radius-getpwuid-request", ARG_GETPWUID_REQUEST, N_("REQUEST"), OPTION_HIDDEN, | ||
59 | N_("Radius request to retrieve a passwd entry based on UID"), 0 }, | ||
60 | { "radius-directory", ARG_RADIUS_DIR, N_("DIR"), OPTION_HIDDEN, | ||
61 | N_("Set path to the radius configuration directory"), 0 }, | ||
62 | { NULL } | ||
63 | }; | ||
64 | |||
65 | static char *auth_request_str; | ||
66 | static grad_avp_t *auth_request; | ||
67 | |||
68 | static char *getpwnam_request_str; | ||
69 | static grad_avp_t *getpwnam_request; | ||
70 | |||
71 | static char *getpwuid_request_str; | ||
72 | static grad_avp_t *getpwuid_request; | ||
73 | |||
74 | /* Assume radius support is needed if any of the above requests is | ||
75 | defined. Actually, all of them should be, but it is the responsibility | ||
76 | of init to check for consistency of the configuration */ | ||
77 | |||
78 | #define NEED_RADIUS_P() \ | ||
79 | (auth_request_str||getpwnam_request_str||getpwuid_request_str) | ||
80 | |||
81 | static int radius_auth_enabled; | 48 | static int radius_auth_enabled; |
82 | 49 | ||
83 | static int MU_User_Name; | 50 | static int MU_User_Name; |
... | @@ -88,13 +55,22 @@ static int MU_Dir; | ... | @@ -88,13 +55,22 @@ static int MU_Dir; |
88 | static int MU_Shell; | 55 | static int MU_Shell; |
89 | static int MU_Mailbox; | 56 | static int MU_Mailbox; |
90 | 57 | ||
91 | void | 58 | static grad_avp_t *auth_request; |
92 | get_attribute (int *pattr, char *name, struct argp_state *state) | 59 | static grad_avp_t *getpwnam_request; |
60 | static grad_avp_t *getpwuid_request; | ||
61 | |||
62 | |||
63 | int | ||
64 | get_attribute (int *pattr, char *name) | ||
93 | { | 65 | { |
94 | grad_dict_attr_t *attr = grad_attr_name_to_dict (name); | 66 | grad_dict_attr_t *attr = grad_attr_name_to_dict (name); |
95 | if (!attr) | 67 | if (!attr) |
96 | argp_error (state, _("Radius attribute %s not defined"), name); | 68 | { |
69 | mu_error (_("Radius attribute %s not defined"), name); | ||
70 | return 1; | ||
71 | } | ||
97 | *pattr = attr->value; | 72 | *pattr = attr->value; |
73 | return 0; | ||
98 | } | 74 | } |
99 | 75 | ||
100 | enum parse_state | 76 | enum parse_state |
... | @@ -106,8 +82,7 @@ enum parse_state | ... | @@ -106,8 +82,7 @@ enum parse_state |
106 | }; | 82 | }; |
107 | 83 | ||
108 | int | 84 | int |
109 | parse_pairlist (grad_avp_t **plist, const char *input, | 85 | parse_pairlist (grad_avp_t **plist, char *input) |
110 | struct argp_state *argp_state) | ||
111 | { | 86 | { |
112 | int rc; | 87 | int rc; |
113 | int i, argc; | 88 | int i, argc; |
... | @@ -121,10 +96,12 @@ parse_pairlist (grad_avp_t **plist, const char *input, | ... | @@ -121,10 +96,12 @@ parse_pairlist (grad_avp_t **plist, const char *input, |
121 | return 1; | 96 | return 1; |
122 | 97 | ||
123 | if ((rc = mu_argcv_get (input, ",", NULL, &argc, &argv))) | 98 | if ((rc = mu_argcv_get (input, ",", NULL, &argc, &argv))) |
124 | argp_error (argp_state, _("Cannot parse input `%s': %s"), | 99 | { |
125 | input, mu_strerror (rc)); | 100 | mu_error (_("Cannot parse input `%s': %s"), input, mu_strerror (rc)); |
101 | return 1; | ||
102 | } | ||
126 | 103 | ||
127 | loc.file = "<command line>"; /* FIXME */ | 104 | loc.file = "<configuration>"; /*FIXME*/ |
128 | loc.line = 0; | 105 | loc.line = 0; |
129 | 106 | ||
130 | for (i = 0, state = state_lhs; i < argc; i++) | 107 | for (i = 0, state = state_lhs; i < argc; i++) |
... | @@ -147,81 +124,78 @@ parse_pairlist (grad_avp_t **plist, const char *input, | ... | @@ -147,81 +124,78 @@ parse_pairlist (grad_avp_t **plist, const char *input, |
147 | loc.line = i; /* Just to keep track of error location */ | 124 | loc.line = i; /* Just to keep track of error location */ |
148 | pair = grad_create_pair (&loc, name, grad_operator_equal, argv[i]); | 125 | pair = grad_create_pair (&loc, name, grad_operator_equal, argv[i]); |
149 | if (!pair) | 126 | if (!pair) |
150 | argp_error (argp_state, _("cannot create radius A/V pair `%s'"), | 127 | { |
151 | name); | 128 | mu_error (_("cannot create radius A/V pair `%s'"), name); |
129 | return 1; | ||
130 | } | ||
152 | grad_avl_merge (plist, &pair); | 131 | grad_avl_merge (plist, &pair); |
153 | state = state_delim; | 132 | state = state_delim; |
154 | break; | 133 | break; |
155 | 134 | ||
156 | case state_delim: | 135 | case state_delim: |
157 | if (strcmp (argv[i], ",")) | 136 | if (strcmp (argv[i], ",")) |
158 | argp_error (argp_state, _("expected `,' but found `%s'"), argv[i]); | 137 | { |
138 | mu_error (_("expected `,' but found `%s'"), argv[i]); | ||
139 | return 1; | ||
140 | } | ||
159 | state = state_lhs; | 141 | state = state_lhs; |
160 | } | 142 | } |
161 | } | 143 | } |
162 | 144 | ||
163 | if (state != state_delim && state != state_delim) | 145 | if (state != state_delim && state != state_delim) |
164 | argp_error (argp_state, _("malformed radius A/V list")); | 146 | { |
147 | mu_error (_("malformed radius A/V list")); | ||
148 | return 1; | ||
149 | } | ||
165 | 150 | ||
166 | mu_argcv_free (argc, argv); | 151 | mu_argcv_free (argc, argv); |
167 | return 0; | 152 | return 0; |
168 | } | 153 | } |
169 | 154 | ||
170 | static void | 155 | /* Assume radius support is needed if any of the above requests is |
171 | init (struct argp_state *state) | 156 | defined. Actually, all of them should be, but it is the responsibility |
157 | of init to check for consistency of the configuration */ | ||
158 | |||
159 | #define NEED_RADIUS_P(cfg) \ | ||
160 | ((cfg) && \ | ||
161 | ((cfg)->auth_request || (cfg)->getpwnam_request || (cfg)->getpwuid_request)) | ||
162 | |||
163 | int | ||
164 | mu_radius_module_init (void *data) | ||
172 | { | 165 | { |
166 | struct mu_radius_module_data *cfg = data; | ||
167 | |||
168 | if (!NEED_RADIUS_P (cfg)) | ||
169 | return 0; | ||
170 | |||
171 | grad_config_dir = grad_estrdup (cfg->config_dir); | ||
172 | |||
173 | grad_path_init (); | 173 | grad_path_init (); |
174 | srand (time (NULL) + getpid ()); | 174 | srand (time (NULL) + getpid ()); |
175 | 175 | ||
176 | if (grad_dict_init ()) | 176 | if (grad_dict_init ()) |
177 | argp_error (state, _("Cannot read radius dictionaries")); | 177 | { |
178 | mu_error (_("Cannot read radius dictionaries")); | ||
179 | return 1; | ||
180 | } | ||
178 | 181 | ||
179 | /* Check whether mailutils attributes are defined */ | 182 | /* Check whether mailutils attributes are defined */ |
180 | get_attribute (&MU_User_Name, "MU-User-Name", state); | 183 | if (get_attribute (&MU_User_Name, "MU-User-Name") |
181 | get_attribute (&MU_UID, "MU-UID", state); | 184 | || get_attribute (&MU_UID, "MU-UID") |
182 | get_attribute (&MU_GID, "MU-GID", state); | 185 | || get_attribute (&MU_GID, "MU-GID") |
183 | get_attribute (&MU_GECOS, "MU-GECOS", state); | 186 | || get_attribute (&MU_GECOS, "MU-GECOS") |
184 | get_attribute (&MU_Dir, "MU-Dir", state); | 187 | || get_attribute (&MU_Dir, "MU-Dir") |
185 | get_attribute (&MU_Shell, "MU-Shell", state); | 188 | || get_attribute (&MU_Shell, "MU-Shell") |
186 | get_attribute (&MU_Mailbox, "MU-Mailbox", state); | 189 | || get_attribute (&MU_Mailbox, "MU-Mailbox")) |
190 | return 1; | ||
187 | 191 | ||
188 | /* Parse saved requests */ | 192 | /* Parse saved requests */ |
189 | parse_pairlist (&auth_request, auth_request_str, state); | 193 | if (parse_pairlist (&auth_request, cfg->auth_request) |
190 | parse_pairlist (&getpwnam_request, getpwnam_request_str, state); | 194 | || parse_pairlist (&getpwnam_request, cfg->getpwnam_request) |
191 | parse_pairlist (&getpwuid_request, getpwuid_request_str, state); | 195 | || parse_pairlist (&getpwuid_request, cfg->getpwuid_request)) |
196 | return 1; | ||
192 | 197 | ||
193 | radius_auth_enabled = 1; | 198 | radius_auth_enabled = 1; |
194 | } | ||
195 | |||
196 | static error_t | ||
197 | mu_radius_argp_parser (int key, char *arg, struct argp_state *state) | ||
198 | { | ||
199 | switch (key) | ||
200 | { | ||
201 | case ARG_AUTH_REQUEST: | ||
202 | auth_request_str = arg; | ||
203 | break; | ||
204 | |||
205 | case ARG_GETPWNAM_REQUEST: | ||
206 | getpwnam_request_str = arg; | ||
207 | break; | ||
208 | |||
209 | case ARG_GETPWUID_REQUEST: | ||
210 | getpwuid_request_str = arg; | ||
211 | break; | ||
212 | |||
213 | case ARG_RADIUS_DIR: | ||
214 | grad_config_dir = grad_estrdup (arg); | ||
215 | break; | ||
216 | |||
217 | case ARGP_KEY_FINI: | ||
218 | if (NEED_RADIUS_P()) | ||
219 | init (state); | ||
220 | break; | ||
221 | |||
222 | default: | ||
223 | return ARGP_ERR_UNKNOWN; | ||
224 | } | ||
225 | return 0; | 199 | return 0; |
226 | } | 200 | } |
227 | 201 | ||
... | @@ -320,20 +294,6 @@ _expand_query (const char *query, const char *ustr, const char *passwd) | ... | @@ -320,20 +294,6 @@ _expand_query (const char *query, const char *ustr, const char *passwd) |
320 | return res; | 294 | return res; |
321 | } | 295 | } |
322 | 296 | ||
323 | static int | ||
324 | cb_directory (mu_cfg_locus_t *locus, void *data, char *arg) | ||
325 | { | ||
326 | grad_config_dir = grad_estrdup (arg); | ||
327 | return 0; | ||
328 | } | ||
329 | |||
330 | static struct mu_cfg_param mu_radius_cfg_param[] = { | ||
331 | { "auth-request", mu_cfg_string, &auth_request_str }, | ||
332 | { "getpwnam-request", mu_cfg_string, &getpwnam_request_str }, | ||
333 | { "getpwuid-request", mu_cfg_string, &getpwuid_request_str }, | ||
334 | { "directory", mu_cfg_callback, NULL, cb_directory }, | ||
335 | { NULL } | ||
336 | }; | ||
337 | 297 | ||
338 | 298 | ||
339 | static grad_avp_t * | 299 | static grad_avp_t * |
... | @@ -577,11 +537,6 @@ mu_auth_radius_user_by_uid (struct mu_auth_data **return_data, | ... | @@ -577,11 +537,6 @@ mu_auth_radius_user_by_uid (struct mu_auth_data **return_data, |
577 | return rc; | 537 | return rc; |
578 | } | 538 | } |
579 | 539 | ||
580 | struct argp mu_radius_argp = { | ||
581 | mu_radius_argp_option, | ||
582 | mu_radius_argp_parser, | ||
583 | }; | ||
584 | |||
585 | #else | 540 | #else |
586 | static int | 541 | static int |
587 | mu_radius_authenticate (struct mu_auth_data **return_data MU_ARG_UNUSED, | 542 | mu_radius_authenticate (struct mu_auth_data **return_data MU_ARG_UNUSED, |
... | @@ -612,11 +567,9 @@ mu_auth_radius_user_by_uid (struct mu_auth_data **return_data, | ... | @@ -612,11 +567,9 @@ mu_auth_radius_user_by_uid (struct mu_auth_data **return_data, |
612 | struct mu_auth_module mu_auth_radius_module = { | 567 | struct mu_auth_module mu_auth_radius_module = { |
613 | "radius", | 568 | "radius", |
614 | #ifdef ENABLE_RADIUS | 569 | #ifdef ENABLE_RADIUS |
615 | &mu_radius_argp, | 570 | mu_radius_module_init, |
616 | mu_radius_cfg_param, | ||
617 | #else | 571 | #else |
618 | NULL, | 572 | NULL, |
619 | NULL, | ||
620 | #endif | 573 | #endif |
621 | mu_radius_authenticate, | 574 | mu_radius_authenticate, |
622 | NULL, | 575 | NULL, | ... | ... |
... | @@ -44,32 +44,18 @@ | ... | @@ -44,32 +44,18 @@ |
44 | #include <mailutils/list.h> | 44 | #include <mailutils/list.h> |
45 | #include <mailutils/iterator.h> | 45 | #include <mailutils/iterator.h> |
46 | #include <mailutils/mailbox.h> | 46 | #include <mailutils/mailbox.h> |
47 | #include <mailutils/argp.h> | 47 | #include <mailutils/sql.h> |
48 | #include <mailutils/mu_auth.h> | 48 | #include <mailutils/mu_auth.h> |
49 | #include <mailutils/error.h> | 49 | #include <mailutils/error.h> |
50 | #include <mailutils/errno.h> | 50 | #include <mailutils/errno.h> |
51 | #include <mailutils/nls.h> | 51 | #include <mailutils/nls.h> |
52 | #include <mailutils/mutil.h> | 52 | #include <mailutils/mutil.h> |
53 | #include <mailutils/sql.h> | 53 | #include <mailutils/sql.h> |
54 | #include "sql.h" | ||
54 | 55 | ||
55 | #ifdef USE_SQL | 56 | #ifdef USE_SQL |
56 | 57 | ||
57 | 58 | struct mu_internal_sql_config mu_sql_module_config; | |
58 | int sql_interface = 0; | ||
59 | char *mu_sql_getpwnam_query; | ||
60 | char *mu_sql_getpass_query; | ||
61 | char *mu_sql_getpwuid_query; | ||
62 | |||
63 | char *mu_sql_host = NULL; /* Hostname to connect to. NULL for UNIX | ||
64 | socket connection */ | ||
65 | char *mu_sql_user = "accounts"; /* Username for mysql access */ | ||
66 | char *mu_sql_passwd = "yurpass"; /* Password for mysql access */ | ||
67 | char *mu_sql_db = "accounts"; /* Database Name */ | ||
68 | int mu_sql_port = 0; /* Port number to connect to. | ||
69 | 0 means default port */ | ||
70 | enum mu_password_type mu_sql_password_type = password_hash; | ||
71 | |||
72 | static mu_assoc_t sql_field_map; | ||
73 | 59 | ||
74 | static char * | 60 | static char * |
75 | sql_escape_string (const char *ustr) | 61 | sql_escape_string (const char *ustr) |
... | @@ -175,176 +161,6 @@ mu_sql_expand_query (const char *query, const char *ustr) | ... | @@ -175,176 +161,6 @@ mu_sql_expand_query (const char *query, const char *ustr) |
175 | return res; | 161 | return res; |
176 | } | 162 | } |
177 | 163 | ||
178 | static int | ||
179 | set_sql_password_type (const char *arg) | ||
180 | { | ||
181 | if (strcmp (arg, "plain") == 0) | ||
182 | mu_sql_password_type = password_plaintext; | ||
183 | else if (strcmp (arg, "hash") == 0) | ||
184 | mu_sql_password_type = password_hash; | ||
185 | else if (strcmp (arg, "scrambled") == 0) | ||
186 | mu_sql_password_type = password_scrambled; | ||
187 | else | ||
188 | return 1; | ||
189 | return 0; | ||
190 | } | ||
191 | |||
192 | |||
193 | /* Command-line configuration */ | ||
194 | # define ARG_SQL_INTERFACE 256 | ||
195 | # define ARG_SQL_GETPWNAM 257 | ||
196 | # define ARG_SQL_GETPWUID 258 | ||
197 | # define ARG_SQL_GETPASS 259 | ||
198 | # define ARG_SQL_HOST 260 | ||
199 | # define ARG_SQL_USER 261 | ||
200 | # define ARG_SQL_PASSWD 262 | ||
201 | # define ARG_SQL_DB 263 | ||
202 | # define ARG_SQL_PORT 264 | ||
203 | # define ARG_SQL_MU_PASSWORD_TYPE 265 | ||
204 | # define ARG_SQL_FIELD_MAP 266 | ||
205 | |||
206 | static struct argp_option mu_sql_argp_option[] = { | ||
207 | {"sql-interface", ARG_SQL_INTERFACE, N_("NAME"), OPTION_HIDDEN, | ||
208 | N_("Type of SQL interface to use"), }, | ||
209 | {"sql-getpwnam", ARG_SQL_GETPWNAM, N_("QUERY"), OPTION_HIDDEN, | ||
210 | N_("SQL query to retrieve a passwd entry based on username"), 0}, | ||
211 | {"sql-getpwuid", ARG_SQL_GETPWUID, N_("QUERY"), OPTION_HIDDEN, | ||
212 | N_("SQL query to retrieve a passwd entry based on UID"), 0}, | ||
213 | {"sql-getpass", ARG_SQL_GETPASS, N_("QUERY"), OPTION_HIDDEN, | ||
214 | N_("SQL query to retrieve a password from the database"), 0}, | ||
215 | {"sql-host", ARG_SQL_HOST, N_("HOSTNAME"), OPTION_HIDDEN, | ||
216 | N_("Name or IP of MySQL server to connect to"), 0}, | ||
217 | {"sql-user", ARG_SQL_USER, N_("NAME"), OPTION_HIDDEN, | ||
218 | N_("SQL user name"), 0}, | ||
219 | {"sql-passwd", ARG_SQL_PASSWD, N_("STRING"), OPTION_HIDDEN, | ||
220 | N_("SQL connection password"), 0}, | ||
221 | {"sql-db", ARG_SQL_DB, N_("STRING"), OPTION_HIDDEN, | ||
222 | N_("Name of the database to connect to"), 0}, | ||
223 | {"sql-port", ARG_SQL_PORT, N_("NUMBER"), OPTION_HIDDEN, | ||
224 | N_("Port to use"), 0}, | ||
225 | {"sql-password-type", ARG_SQL_MU_PASSWORD_TYPE, N_("STRING"), OPTION_HIDDEN, | ||
226 | N_("Type of password returned by --sql-getpass query. STRING is one of: plain, hash, scrambled"), 0}, | ||
227 | {"sql-field-map", ARG_SQL_FIELD_MAP, N_("MAP"), OPTION_HIDDEN, | ||
228 | N_("Declare a name translation map for SQL fields in results of sql-getpwnam and " | ||
229 | "sql-getpwuid queries"), 0}, | ||
230 | { NULL, 0, NULL, 0, NULL, 0 } | ||
231 | }; | ||
232 | |||
233 | static error_t | ||
234 | mu_sql_argp_parser (int key, char *arg, struct argp_state *state) | ||
235 | { | ||
236 | int rc, err; | ||
237 | |||
238 | switch (key) | ||
239 | { | ||
240 | case ARG_SQL_INTERFACE: | ||
241 | sql_interface = mu_sql_interface_index (arg); | ||
242 | if (sql_interface == 0) | ||
243 | argp_error (state, _("Unknown SQL interface `%s'"), arg); | ||
244 | break; | ||
245 | |||
246 | case ARG_SQL_GETPWNAM: | ||
247 | mu_sql_getpwnam_query = arg; | ||
248 | break; | ||
249 | |||
250 | case ARG_SQL_GETPWUID: | ||
251 | mu_sql_getpwuid_query = arg; | ||
252 | break; | ||
253 | |||
254 | case ARG_SQL_GETPASS: | ||
255 | mu_sql_getpass_query = arg; | ||
256 | break; | ||
257 | |||
258 | case ARG_SQL_HOST: | ||
259 | mu_sql_host = arg; | ||
260 | break; | ||
261 | |||
262 | case ARG_SQL_USER: | ||
263 | mu_sql_user = arg; | ||
264 | break; | ||
265 | |||
266 | case ARG_SQL_PASSWD: | ||
267 | mu_sql_passwd = arg; | ||
268 | break; | ||
269 | |||
270 | case ARG_SQL_DB: | ||
271 | mu_sql_db = arg; | ||
272 | break; | ||
273 | |||
274 | case ARG_SQL_PORT: | ||
275 | mu_sql_port = strtoul (arg, NULL, 0); | ||
276 | break; | ||
277 | |||
278 | case ARG_SQL_MU_PASSWORD_TYPE: | ||
279 | if (set_sql_password_type (arg)) | ||
280 | argp_error (state, _("Unknown password type `%s'"), arg); | ||
281 | break; | ||
282 | |||
283 | case ARG_SQL_FIELD_MAP: | ||
284 | rc = mutil_parse_field_map (arg, &sql_field_map, &err); | ||
285 | if (rc) | ||
286 | argp_error (state, _("Error near element %d: %s"), | ||
287 | err, mu_strerror (rc)); | ||
288 | break; | ||
289 | |||
290 | default: | ||
291 | return ARGP_ERR_UNKNOWN; | ||
292 | } | ||
293 | return 0; | ||
294 | } | ||
295 | |||
296 | static struct argp mu_sql_argp = { | ||
297 | mu_sql_argp_option, | ||
298 | mu_sql_argp_parser, | ||
299 | }; | ||
300 | |||
301 | |||
302 | /* Resource file configuration */ | ||
303 | static int | ||
304 | cb_iface (mu_cfg_locus_t *locus, void *data, char *arg) | ||
305 | { | ||
306 | sql_interface = mu_sql_interface_index (arg); | ||
307 | if (sql_interface == 0) | ||
308 | mu_error (_("%s:%d: Unknown SQL interface `%s'"), | ||
309 | locus->file, locus->line, arg); | ||
310 | return 0; | ||
311 | } | ||
312 | |||
313 | static int | ||
314 | cb_password_type (mu_cfg_locus_t *locus, void *data, char *arg) | ||
315 | { | ||
316 | if (set_sql_password_type (arg)) | ||
317 | mu_error (_("%s:%d: Unknown password type `%s'"), | ||
318 | locus->file, locus->line, arg); | ||
319 | return 0; | ||
320 | } | ||
321 | |||
322 | static int | ||
323 | cb_field_map (mu_cfg_locus_t *locus, void *data, char *arg) | ||
324 | { | ||
325 | int err; | ||
326 | int rc = mutil_parse_field_map (arg, &sql_field_map, &err); | ||
327 | if (rc) | ||
328 | mu_error (_("%s:%d: Error near element %d: %s"), | ||
329 | locus->file, locus->line, err, mu_strerror (rc)); | ||
330 | return 0; | ||
331 | } | ||
332 | |||
333 | static struct mu_cfg_param mu_sql_param[] = { | ||
334 | { "interface", mu_cfg_callback, NULL, cb_iface }, | ||
335 | { "getwpnam", mu_cfg_string, &mu_sql_getpwnam_query }, | ||
336 | { "getpwuid", mu_cfg_string, &mu_sql_getpwuid_query }, | ||
337 | { "getpass", mu_cfg_string, &mu_sql_getpass_query }, | ||
338 | { "host", mu_cfg_string, &mu_sql_host }, | ||
339 | { "user", mu_cfg_string, &mu_sql_user }, | ||
340 | { "passwd", mu_cfg_string, &mu_sql_passwd }, | ||
341 | { "db", mu_cfg_string, &mu_sql_db }, | ||
342 | { "port", mu_cfg_int, &mu_sql_port }, | ||
343 | { "password-type", mu_cfg_callback, NULL, cb_password_type }, | ||
344 | { "field-map", mu_cfg_callback, NULL, cb_field_map }, | ||
345 | { NULL } | ||
346 | }; | ||
347 | |||
348 | 164 | ||
349 | static int | 165 | static int |
350 | decode_tuple_v1_0 (mu_sql_connection_t conn, int n, | 166 | decode_tuple_v1_0 (mu_sql_connection_t conn, int n, |
... | @@ -405,7 +221,7 @@ decode_tuple_v1_0 (mu_sql_connection_t conn, int n, | ... | @@ -405,7 +221,7 @@ decode_tuple_v1_0 (mu_sql_connection_t conn, int n, |
405 | static int | 221 | static int |
406 | get_field (mu_sql_connection_t conn, const char *id, char **ret, int mandatory) | 222 | get_field (mu_sql_connection_t conn, const char *id, char **ret, int mandatory) |
407 | { | 223 | { |
408 | const char **name = mu_assoc_ref (sql_field_map, id); | 224 | const char **name = mu_assoc_ref (mu_sql_module_config.field_map, id); |
409 | int rc = mu_sql_get_field (conn, 0, name ? *name : id, ret); | 225 | int rc = mu_sql_get_field (conn, 0, name ? *name : id, ret); |
410 | if (rc) | 226 | if (rc) |
411 | { | 227 | { |
... | @@ -536,7 +352,7 @@ static int | ... | @@ -536,7 +352,7 @@ static int |
536 | decode_tuple (mu_sql_connection_t conn, int n, | 352 | decode_tuple (mu_sql_connection_t conn, int n, |
537 | struct mu_auth_data **return_data) | 353 | struct mu_auth_data **return_data) |
538 | { | 354 | { |
539 | if (sql_field_map) | 355 | if (mu_sql_module_config.field_map) |
540 | return decode_tuple_new (conn, n, return_data); | 356 | return decode_tuple_new (conn, n, return_data); |
541 | else | 357 | else |
542 | return decode_tuple_v1_0 (conn, n, return_data); | 358 | return decode_tuple_v1_0 (conn, n, return_data); |
... | @@ -556,17 +372,18 @@ mu_auth_sql_by_name (struct mu_auth_data **return_data, | ... | @@ -556,17 +372,18 @@ mu_auth_sql_by_name (struct mu_auth_data **return_data, |
556 | if (!key) | 372 | if (!key) |
557 | return EINVAL; | 373 | return EINVAL; |
558 | 374 | ||
559 | query_str = mu_sql_expand_query (mu_sql_getpwnam_query, key); | 375 | query_str = mu_sql_expand_query (mu_sql_module_config.getpwnam_query, key); |
560 | 376 | ||
561 | if (!query_str) | 377 | if (!query_str) |
562 | return MU_ERR_FAILURE; | 378 | return MU_ERR_FAILURE; |
563 | 379 | ||
564 | status = mu_sql_connection_init (&conn, | 380 | status = mu_sql_connection_init (&conn, |
565 | sql_interface, | 381 | mu_sql_module_config.interface, |
566 | mu_sql_host, | 382 | mu_sql_module_config.host, |
567 | mu_sql_port, | 383 | mu_sql_module_config.port, |
568 | mu_sql_user, mu_sql_passwd, | 384 | mu_sql_module_config.user, |
569 | mu_sql_db); | 385 | mu_sql_module_config.passwd, |
386 | mu_sql_module_config.db); | ||
570 | 387 | ||
571 | if (status) | 388 | if (status) |
572 | { | 389 | { |
... | @@ -638,17 +455,19 @@ mu_auth_sql_by_uid (struct mu_auth_data **return_data, | ... | @@ -638,17 +455,19 @@ mu_auth_sql_by_uid (struct mu_auth_data **return_data, |
638 | return EINVAL; | 455 | return EINVAL; |
639 | 456 | ||
640 | snprintf (uidstr, sizeof (uidstr), "%u", *(uid_t*)key); | 457 | snprintf (uidstr, sizeof (uidstr), "%u", *(uid_t*)key); |
641 | query_str = mu_sql_expand_query (mu_sql_getpwuid_query, uidstr); | 458 | query_str = mu_sql_expand_query (mu_sql_module_config.getpwuid_query, |
459 | uidstr); | ||
642 | 460 | ||
643 | if (!query_str) | 461 | if (!query_str) |
644 | return ENOMEM; | 462 | return ENOMEM; |
645 | 463 | ||
646 | status = mu_sql_connection_init (&conn, | 464 | status = mu_sql_connection_init (&conn, |
647 | sql_interface, | 465 | mu_sql_module_config.interface, |
648 | mu_sql_host, | 466 | mu_sql_module_config.host, |
649 | mu_sql_port, | 467 | mu_sql_module_config.port, |
650 | mu_sql_user, mu_sql_passwd, | 468 | mu_sql_module_config.user, |
651 | mu_sql_db); | 469 | mu_sql_module_config.passwd, |
470 | mu_sql_module_config.db); | ||
652 | 471 | ||
653 | if (status) | 472 | if (status) |
654 | { | 473 | { |
... | @@ -713,17 +532,18 @@ mu_sql_getpass (const char *username, char **passwd) | ... | @@ -713,17 +532,18 @@ mu_sql_getpass (const char *username, char **passwd) |
713 | int status; | 532 | int status; |
714 | char *sql_pass; | 533 | char *sql_pass; |
715 | 534 | ||
716 | query_str = mu_sql_expand_query (mu_sql_getpass_query, username); | 535 | query_str = mu_sql_expand_query (mu_sql_module_config.getpass_query, username); |
717 | 536 | ||
718 | if (!query_str) | 537 | if (!query_str) |
719 | return MU_ERR_FAILURE; | 538 | return MU_ERR_FAILURE; |
720 | 539 | ||
721 | status = mu_sql_connection_init (&conn, | 540 | status = mu_sql_connection_init (&conn, |
722 | sql_interface, | 541 | mu_sql_module_config.interface, |
723 | mu_sql_host, | 542 | mu_sql_module_config.host, |
724 | mu_sql_port, | 543 | mu_sql_module_config.port, |
725 | mu_sql_user, mu_sql_passwd, | 544 | mu_sql_module_config.user, |
726 | mu_sql_db); | 545 | mu_sql_module_config.passwd, |
546 | mu_sql_module_config.db); | ||
727 | 547 | ||
728 | if (status) | 548 | if (status) |
729 | { | 549 | { |
... | @@ -804,7 +624,7 @@ mu_sql_authenticate (struct mu_auth_data **return_data MU_ARG_UNUSED, | ... | @@ -804,7 +624,7 @@ mu_sql_authenticate (struct mu_auth_data **return_data MU_ARG_UNUSED, |
804 | if ((rc = mu_sql_getpass (auth_data->name, &sql_pass))) | 624 | if ((rc = mu_sql_getpass (auth_data->name, &sql_pass))) |
805 | return rc; | 625 | return rc; |
806 | 626 | ||
807 | switch (mu_sql_password_type) | 627 | switch (mu_sql_module_config.password_type) |
808 | { | 628 | { |
809 | case password_hash: | 629 | case password_hash: |
810 | rc = strcmp (sql_pass, crypt (pass, sql_pass)); | 630 | rc = strcmp (sql_pass, crypt (pass, sql_pass)); |
... | @@ -832,6 +652,32 @@ mu_sql_authenticate (struct mu_auth_data **return_data MU_ARG_UNUSED, | ... | @@ -832,6 +652,32 @@ mu_sql_authenticate (struct mu_auth_data **return_data MU_ARG_UNUSED, |
832 | return rc == 0 ? 0 : MU_ERR_AUTH_FAILURE; | 652 | return rc == 0 ? 0 : MU_ERR_AUTH_FAILURE; |
833 | } | 653 | } |
834 | 654 | ||
655 | int | ||
656 | mu_sql_module_init (void *data) | ||
657 | { | ||
658 | struct mu_sql_module_config *cfg = data; | ||
659 | |||
660 | mu_sql_module_config.interface = mu_sql_interface_index (cfg->interface); | ||
661 | if (mu_sql_module_config.interface == 0) | ||
662 | { | ||
663 | mu_error (_("Unknown SQL interface `%s'"), cfg->interface); | ||
664 | return 1; | ||
665 | } | ||
666 | |||
667 | mu_sql_module_config.getpwnam_query = cfg->getpwnam_query; | ||
668 | mu_sql_module_config.getpass_query = cfg->getpass_query; | ||
669 | mu_sql_module_config.getpwuid_query = cfg->getpwuid_query; | ||
670 | mu_sql_module_config.host = cfg->host; | ||
671 | mu_sql_module_config.user = cfg->user; | ||
672 | mu_sql_module_config.passwd = cfg->passwd; | ||
673 | mu_sql_module_config.db = cfg->db; | ||
674 | mu_sql_module_config.port = cfg->port; | ||
675 | mu_sql_module_config.password_type = cfg->password_type; | ||
676 | mu_sql_module_config.field_map = cfg->field_map; | ||
677 | |||
678 | return 0; | ||
679 | } | ||
680 | |||
835 | #else | 681 | #else |
836 | 682 | ||
837 | # define mu_sql_authenticate mu_auth_nosupport | 683 | # define mu_sql_authenticate mu_auth_nosupport |
... | @@ -844,11 +690,9 @@ mu_sql_authenticate (struct mu_auth_data **return_data MU_ARG_UNUSED, | ... | @@ -844,11 +690,9 @@ mu_sql_authenticate (struct mu_auth_data **return_data MU_ARG_UNUSED, |
844 | struct mu_auth_module mu_auth_sql_module = { | 690 | struct mu_auth_module mu_auth_sql_module = { |
845 | "sql", | 691 | "sql", |
846 | #ifdef USE_SQL | 692 | #ifdef USE_SQL |
847 | &mu_sql_argp, | 693 | mu_sql_module_init, |
848 | mu_sql_param, | ||
849 | #else | 694 | #else |
850 | NULL, | 695 | NULL, |
851 | NULL, | ||
852 | #endif | 696 | #endif |
853 | mu_sql_authenticate, | 697 | mu_sql_authenticate, |
854 | NULL, | 698 | NULL, | ... | ... |
... | @@ -40,15 +40,20 @@ | ... | @@ -40,15 +40,20 @@ |
40 | #include <mailutils/nls.h> | 40 | #include <mailutils/nls.h> |
41 | #include <mailutils/mailbox.h> | 41 | #include <mailutils/mailbox.h> |
42 | 42 | ||
43 | extern int sql_interface; | 43 | struct mu_internal_sql_config |
44 | extern char *mu_sql_getpwnam_query; | 44 | { |
45 | extern char *mu_sql_getpass_query; | 45 | int interface; |
46 | extern char *mu_sql_getpwuid_query; | 46 | char *getpwnam_query; |
47 | extern char *mu_sql_host; | 47 | char *getpass_query; |
48 | extern char *mu_sql_user; | 48 | char *getpwuid_query; |
49 | extern char *mu_sql_passwd; | 49 | char *host; |
50 | extern char *mu_sql_db; | 50 | char *user; |
51 | extern char *mu_sql_socket; | 51 | char *passwd; |
52 | extern int mu_sql_port; | 52 | char *db; |
53 | 53 | int port; | |
54 | enum mu_password_type password_type; | ||
55 | mu_assoc_t field_map; | ||
56 | }; | ||
57 | |||
58 | extern struct mu_internal_sql_config mu_sql_module_config; | ||
54 | 59 | ... | ... |
... | @@ -27,7 +27,6 @@ | ... | @@ -27,7 +27,6 @@ |
27 | #include <sys/stat.h> | 27 | #include <sys/stat.h> |
28 | #include <string.h> | 28 | #include <string.h> |
29 | 29 | ||
30 | #include <mailutils/argp.h> | ||
31 | #include <mailutils/error.h> | 30 | #include <mailutils/error.h> |
32 | #include <mailutils/mu_auth.h> | 31 | #include <mailutils/mu_auth.h> |
33 | #include <mailutils/tls.h> | 32 | #include <mailutils/tls.h> |
... | @@ -37,155 +36,69 @@ | ... | @@ -37,155 +36,69 @@ |
37 | 36 | ||
38 | #include <lbuf.h> | 37 | #include <lbuf.h> |
39 | 38 | ||
40 | #ifdef WITH_TLS | 39 | struct mu_tls_module_config mu_tls_module_config; |
41 | |||
42 | #include <gnutls/gnutls.h> | ||
43 | |||
44 | #define DH_BITS 768 | ||
45 | |||
46 | static gnutls_dh_params dh_params; | ||
47 | static gnutls_certificate_server_credentials x509_cred; | ||
48 | static char *ssl_cert = NULL; | ||
49 | static char *ssl_key = NULL; | ||
50 | static char *ssl_cafile = NULL; | ||
51 | |||
52 | #define ARG_TLS 1 | ||
53 | #define ARG_SSL_CERT 2 | ||
54 | #define ARG_SSL_KEY 3 | ||
55 | #define ARG_SSL_CAFILE 4 | ||
56 | |||
57 | static struct argp_option _tls_argp_options[] = { | ||
58 | {"ssl-cert", ARG_SSL_CERT, N_("FILE"), OPTION_HIDDEN, | ||
59 | N_("Specify SSL certificate file"), 0}, | ||
60 | {"ssl-key", ARG_SSL_KEY, N_("FILE"), OPTION_HIDDEN, | ||
61 | N_("Specify SSL certificate key"), }, | ||
62 | {"ssl-cafile", ARG_SSL_CAFILE, N_("FILE"), OPTION_HIDDEN, | ||
63 | N_("Specify trusted CAs file"), 0}, | ||
64 | {NULL, 0, NULL, 0, NULL, 0} | ||
65 | }; | ||
66 | 40 | ||
67 | static error_t | 41 | int |
68 | _tls_argp_parser (int key, char *arg, struct argp_state *state) | 42 | mu_tls_module_init (void *data) |
69 | { | 43 | { |
70 | static int tls_enable = 1; | 44 | if (data) |
71 | |||
72 | switch (key) | ||
73 | { | 45 | { |
74 | case ARG_TLS: | 46 | memcpy (&mu_tls_module_config, data, sizeof mu_tls_module_config); |
75 | if (!arg || strcasecmp (arg, "yes") == 0) | 47 | #ifdef WITH_TLS |
76 | tls_enable = 1; | 48 | if (mu_tls_module_config.client_enable) |
77 | else if (strcasecmp (arg, "no") == 0) | ||
78 | tls_enable = 0; | ||
79 | break; | ||
80 | |||
81 | case ARG_SSL_CERT: | ||
82 | ssl_cert = arg; | ||
83 | break; | ||
84 | |||
85 | case ARG_SSL_KEY: | ||
86 | ssl_key = arg; | ||
87 | break; | ||
88 | |||
89 | case ARG_SSL_CAFILE: | ||
90 | ssl_cafile = arg; | ||
91 | break; | ||
92 | |||
93 | case ARGP_KEY_FINI: | ||
94 | if (tls_enable) | ||
95 | mu_init_tls_libs (); | 49 | mu_init_tls_libs (); |
96 | break; | 50 | #endif |
97 | |||
98 | default: | ||
99 | return ARGP_ERR_UNKNOWN; | ||
100 | } | 51 | } |
101 | return 0; | 52 | return 0; |
102 | } | 53 | } |
103 | 54 | ||
104 | static struct argp _tls_argp = { | 55 | #ifdef WITH_TLS |
105 | _tls_argp_options, | ||
106 | _tls_argp_parser | ||
107 | }; | ||
108 | |||
109 | static struct argp_child _tls_argp_child = { | ||
110 | &_tls_argp, | ||
111 | 0, | ||
112 | NULL, | ||
113 | 0 | ||
114 | }; | ||
115 | |||
116 | void | ||
117 | mu_tls_init_argp () | ||
118 | { | ||
119 | if (mu_register_capa ("tls", &_tls_argp_child, NULL)) | ||
120 | { | ||
121 | mu_error (_("INTERNAL ERROR: cannot register argp capability tls")); | ||
122 | abort (); | ||
123 | } | ||
124 | } | ||
125 | |||
126 | static struct argp_option _tls_argp_client_options[] = { | ||
127 | {"tls", ARG_TLS, N_("BOOL"), OPTION_ARG_OPTIONAL, | ||
128 | N_("Enable TLS support") }, | ||
129 | {NULL, 0, NULL, 0, NULL, 0} | ||
130 | }; | ||
131 | 56 | ||
132 | static struct argp _tls_client_argp = { | 57 | #include <gnutls/gnutls.h> |
133 | _tls_argp_client_options, | ||
134 | _tls_argp_parser | ||
135 | }; | ||
136 | 58 | ||
137 | static struct argp_child _tls_argp_client_child = { | 59 | #define DH_BITS 768 |
138 | &_tls_client_argp, | ||
139 | 0, | ||
140 | NULL, | ||
141 | 0 | ||
142 | }; | ||
143 | 60 | ||
144 | void | 61 | static gnutls_dh_params dh_params; |
145 | mu_tls_init_client_argp () | 62 | static gnutls_certificate_server_credentials x509_cred; |
146 | { | ||
147 | if (mu_register_capa ("tls", &_tls_argp_client_child, NULL)) | ||
148 | { | ||
149 | mu_error (_("INTERNAL ERROR: cannot register argp capability tls")); | ||
150 | abort (); | ||
151 | } | ||
152 | } | ||
153 | 63 | ||
154 | int | 64 | int |
155 | mu_check_tls_environment (void) | 65 | mu_check_tls_environment (void) |
156 | { | 66 | { |
157 | /* Return: zero means NOT READY, one means READY */ | 67 | /* Return: zero means NOT READY, one means READY */ |
158 | 68 | ||
159 | if (ssl_cert && ssl_key) | 69 | if (mu_tls_module_config.ssl_cert && mu_tls_module_config.ssl_key) |
160 | { | 70 | { |
161 | struct stat st; | 71 | struct stat st; |
162 | 72 | ||
163 | if (stat (ssl_cert, &st) == -1) | 73 | if (stat (mu_tls_module_config.ssl_cert, &st) == -1) |
164 | { | 74 | { |
165 | mu_error ("%s: %s.", ssl_cert, mu_strerror (errno)); | 75 | mu_error ("%s: %s.", mu_tls_module_config.ssl_cert, |
76 | mu_strerror (errno)); | ||
166 | return 0; | 77 | return 0; |
167 | } | 78 | } |
168 | if (!(st.st_mode & S_IFREG) || !(st.st_mode & S_IFLNK)) | 79 | if (!(st.st_mode & S_IFREG) || !(st.st_mode & S_IFLNK)) |
169 | { | 80 | { |
170 | mu_error (_("%s is not a regular file or a symbolic link."), | 81 | mu_error (_("%s is not a regular file or a symbolic link."), |
171 | ssl_cert); | 82 | mu_tls_module_config.ssl_cert); |
172 | return 0; | 83 | return 0; |
173 | } | 84 | } |
174 | 85 | ||
175 | if (stat (ssl_key, &st) == -1) | 86 | if (stat (mu_tls_module_config.ssl_key, &st) == -1) |
176 | { | 87 | { |
177 | mu_error ("%s: %s.", ssl_key, mu_strerror(errno)); | 88 | mu_error ("%s: %s.", mu_tls_module_config.ssl_key, |
89 | mu_strerror(errno)); | ||
178 | return 0; | 90 | return 0; |
179 | } | 91 | } |
180 | if (!(st.st_mode & S_IFREG) || !(st.st_mode & S_IFLNK)) | 92 | if (!(st.st_mode & S_IFREG) || !(st.st_mode & S_IFLNK)) |
181 | { | 93 | { |
182 | mu_error (_("%s is not a regular file or a symbolic link."), | 94 | mu_error (_("%s is not a regular file or a symbolic link."), |
183 | ssl_key); | 95 | mu_tls_module_config.ssl_key); |
184 | return 0; | 96 | return 0; |
185 | } | 97 | } |
186 | if ((st.st_mode & S_IRWXG) || (st.st_mode & S_IRWXO)) | 98 | if ((st.st_mode & S_IRWXG) || (st.st_mode & S_IRWXO)) |
187 | { | 99 | { |
188 | mu_error (_("Wrong permissions on %s. Set 0600"), ssl_key); | 100 | mu_error (_("Wrong permissions on %s. Set 0600"), |
101 | mu_tls_module_config.ssl_key); | ||
189 | return 0; | 102 | return 0; |
190 | } | 103 | } |
191 | } | 104 | } |
... | @@ -507,12 +420,14 @@ _tls_open (mu_stream_t stream) | ... | @@ -507,12 +420,14 @@ _tls_open (mu_stream_t stream) |
507 | 420 | ||
508 | gnutls_certificate_allocate_credentials (&x509_cred); | 421 | gnutls_certificate_allocate_credentials (&x509_cred); |
509 | 422 | ||
510 | if (ssl_cafile) | 423 | if (mu_tls_module_config.ssl_cafile) |
511 | gnutls_certificate_set_x509_trust_file (x509_cred, ssl_cafile, | 424 | gnutls_certificate_set_x509_trust_file (x509_cred, |
425 | mu_tls_module_config.ssl_cafile, | ||
512 | GNUTLS_X509_FMT_PEM); | 426 | GNUTLS_X509_FMT_PEM); |
513 | 427 | ||
514 | rc = gnutls_certificate_set_x509_key_file (x509_cred, | 428 | rc = gnutls_certificate_set_x509_key_file (x509_cred, |
515 | ssl_cert, ssl_key, | 429 | mu_tls_module_config.ssl_cert, |
430 | mu_tls_module_config.ssl_key, | ||
516 | GNUTLS_X509_FMT_PEM); | 431 | GNUTLS_X509_FMT_PEM); |
517 | if (rc < 0) | 432 | if (rc < 0) |
518 | { | 433 | { |
... | @@ -561,10 +476,10 @@ prepare_client_session (struct _tls_stream *s) | ... | @@ -561,10 +476,10 @@ prepare_client_session (struct _tls_stream *s) |
561 | gnutls_mac_set_priority (s->session, mac_priority); | 476 | gnutls_mac_set_priority (s->session, mac_priority); |
562 | 477 | ||
563 | gnutls_certificate_allocate_credentials (&x509_cred); | 478 | gnutls_certificate_allocate_credentials (&x509_cred); |
564 | if (ssl_cafile) | 479 | if (mu_tls_module_config.ssl_cafile) |
565 | { | 480 | { |
566 | rc = gnutls_certificate_set_x509_trust_file (x509_cred, | 481 | rc = gnutls_certificate_set_x509_trust_file (x509_cred, |
567 | ssl_cafile, | 482 | mu_tls_module_config.ssl_cafile, |
568 | GNUTLS_X509_FMT_PEM); | 483 | GNUTLS_X509_FMT_PEM); |
569 | if (rc < 0) | 484 | if (rc < 0) |
570 | { | 485 | { | ... | ... |
... | @@ -49,15 +49,27 @@ | ... | @@ -49,15 +49,27 @@ |
49 | #include <mailutils/list.h> | 49 | #include <mailutils/list.h> |
50 | #include <mailutils/iterator.h> | 50 | #include <mailutils/iterator.h> |
51 | #include <mailutils/mailbox.h> | 51 | #include <mailutils/mailbox.h> |
52 | #include <mailutils/argp.h> | ||
53 | #include <mailutils/mu_auth.h> | 52 | #include <mailutils/mu_auth.h> |
54 | #include <mailutils/nls.h> | 53 | #include <mailutils/nls.h> |
55 | #include <mailutils/errno.h> | 54 | #include <mailutils/errno.h> |
56 | 55 | ||
57 | #ifdef ENABLE_VIRTUAL_DOMAINS | 56 | #ifdef ENABLE_VIRTUAL_DOMAINS |
58 | 57 | ||
58 | /* FIXME: Make global, prefix with mu_ */ | ||
59 | static char *site_virtual_pwddir = SITE_VIRTUAL_PWDDIR; | 59 | static char *site_virtual_pwddir = SITE_VIRTUAL_PWDDIR; |
60 | 60 | ||
61 | int | ||
62 | mu_virtual_module_init (void *data) | ||
63 | { | ||
64 | if (data) | ||
65 | { | ||
66 | site_virtual_pwddir = strdup (data); | ||
67 | if (!site_virtual_pwddir) | ||
68 | return 1; | ||
69 | } | ||
70 | return 0; | ||
71 | } | ||
72 | |||
61 | static struct passwd * | 73 | static struct passwd * |
62 | getpwnam_virtual (const char *u) | 74 | getpwnam_virtual (const char *u) |
63 | { | 75 | { |
... | @@ -173,34 +185,6 @@ mu_auth_virt_domain_by_name (struct mu_auth_data **return_data, | ... | @@ -173,34 +185,6 @@ mu_auth_virt_domain_by_name (struct mu_auth_data **return_data, |
173 | return rc; | 185 | return rc; |
174 | } | 186 | } |
175 | 187 | ||
176 | #define ARG_PWDDIR 1 | ||
177 | |||
178 | static error_t | ||
179 | mu_virt_argp_parser (int key, char *arg, struct argp_state *state) | ||
180 | { | ||
181 | switch (key) | ||
182 | { | ||
183 | case ARG_PWDDIR: | ||
184 | site_virtual_pwddir = arg; | ||
185 | break; | ||
186 | |||
187 | default: | ||
188 | return ARGP_ERR_UNKNOWN; | ||
189 | } | ||
190 | return 0; | ||
191 | } | ||
192 | |||
193 | static struct argp_option mu_virt_argp_option[] = { | ||
194 | { "virtual-passwd-dir", ARG_PWDDIR, N_("DIR"), OPTION_HIDDEN, | ||
195 | N_("Search for virtual passwd file in DIR"), 0}, | ||
196 | { NULL, 0, NULL, 0, NULL, 0 } | ||
197 | }; | ||
198 | |||
199 | struct argp mu_virt_argp = { | ||
200 | mu_virt_argp_option, | ||
201 | mu_virt_argp_parser, | ||
202 | }; | ||
203 | |||
204 | #else | 188 | #else |
205 | static int | 189 | static int |
206 | mu_auth_virt_domain_by_name (struct mu_auth_data **return_data MU_ARG_UNUSED, | 190 | mu_auth_virt_domain_by_name (struct mu_auth_data **return_data MU_ARG_UNUSED, |
... | @@ -215,11 +199,9 @@ mu_auth_virt_domain_by_name (struct mu_auth_data **return_data MU_ARG_UNUSED, | ... | @@ -215,11 +199,9 @@ mu_auth_virt_domain_by_name (struct mu_auth_data **return_data MU_ARG_UNUSED, |
215 | struct mu_auth_module mu_auth_virtual_module = { | 199 | struct mu_auth_module mu_auth_virtual_module = { |
216 | "virtdomain", | 200 | "virtdomain", |
217 | #ifdef ENABLE_VIRTUAL_DOMAINS | 201 | #ifdef ENABLE_VIRTUAL_DOMAINS |
218 | &mu_virt_argp, | 202 | mu_virtual_module_init, |
219 | NULL, | ||
220 | #else | 203 | #else |
221 | NULL, | 204 | NULL, |
222 | NULL, | ||
223 | #endif | 205 | #endif |
224 | mu_auth_nosupport, | 206 | mu_auth_nosupport, |
225 | NULL, | 207 | NULL, | ... | ... |
... | @@ -24,7 +24,7 @@ sbin_PROGRAMS = comsatd | ... | @@ -24,7 +24,7 @@ sbin_PROGRAMS = comsatd |
24 | comsatd_SOURCES = action.c cfg.c comsat.c comsat.h | 24 | comsatd_SOURCES = action.c cfg.c comsat.c comsat.h |
25 | 25 | ||
26 | comsatd_LDADD = \ | 26 | comsatd_LDADD = \ |
27 | ../lib/libmuaux.la\ | 27 | ${MU_APP_LIBRARIES}\ |
28 | ${MU_LIB_MBOX}\ | 28 | ${MU_LIB_MBOX}\ |
29 | ${MU_LIB_IMAP}\ | 29 | ${MU_LIB_IMAP}\ |
30 | ${MU_LIB_POP}\ | 30 | ${MU_LIB_POP}\ | ... | ... |
... | @@ -18,6 +18,7 @@ | ... | @@ -18,6 +18,7 @@ |
18 | MA 02110-1301 USA */ | 18 | MA 02110-1301 USA */ |
19 | 19 | ||
20 | #include "comsat.h" | 20 | #include "comsat.h" |
21 | #include "muinit.h" | ||
21 | 22 | ||
22 | #ifndef PATH_DEV | 23 | #ifndef PATH_DEV |
23 | # define PATH_DEV "/dev" | 24 | # define PATH_DEV "/dev" |
... | @@ -90,7 +91,7 @@ static const char *comsat_argp_capa[] = { | ... | @@ -90,7 +91,7 @@ static const char *comsat_argp_capa[] = { |
90 | # define MAXHOSTNAMELEN 64 | 91 | # define MAXHOSTNAMELEN 64 |
91 | #endif | 92 | #endif |
92 | 93 | ||
93 | struct daemon_param daemon_param = { | 94 | struct mu_gocs_daemon default_gocs_daemon = { |
94 | MODE_INTERACTIVE, /* Start in interactive (inetd) mode */ | 95 | MODE_INTERACTIVE, /* Start in interactive (inetd) mode */ |
95 | 20, /* Default maximum number of children. | 96 | 20, /* Default maximum number of children. |
96 | Currently unused */ | 97 | Currently unused */ |
... | @@ -121,10 +122,6 @@ comsatd_parse_opt (int key, char *arg, struct argp_state *state) | ... | @@ -121,10 +122,6 @@ comsatd_parse_opt (int key, char *arg, struct argp_state *state) |
121 | { | 122 | { |
122 | switch (key) | 123 | switch (key) |
123 | { | 124 | { |
124 | case ARGP_KEY_INIT: | ||
125 | state->child_inputs[0] = state->input; | ||
126 | break; | ||
127 | |||
128 | case 'c': | 125 | case 'c': |
129 | config_file = arg; | 126 | config_file = arg; |
130 | break; | 127 | break; |
... | @@ -150,8 +147,9 @@ main (int argc, char **argv) | ... | @@ -150,8 +147,9 @@ main (int argc, char **argv) |
150 | mu_init_nls (); | 147 | mu_init_nls (); |
151 | 148 | ||
152 | mu_argp_init (program_version, NULL); | 149 | mu_argp_init (program_version, NULL); |
153 | mu_argp_parse (&argp, &argc, &argv, 0, comsat_argp_capa, | 150 | mu_gocs_daemon = default_gocs_daemon; |
154 | &ind, &daemon_param); | 151 | if (mu_app_init (&argp, comsat_argp_capa, NULL, argc, argv, 0, &ind, NULL)) |
152 | exit (1); | ||
155 | 153 | ||
156 | argc -= ind; | 154 | argc -= ind; |
157 | argv += ind; | 155 | argv += ind; |
... | @@ -191,7 +189,7 @@ main (int argc, char **argv) | ... | @@ -191,7 +189,7 @@ main (int argc, char **argv) |
191 | exit (0); | 189 | exit (0); |
192 | } | 190 | } |
193 | 191 | ||
194 | if (daemon_param.timeout > 0 && daemon_param.mode == MODE_DAEMON) | 192 | if (mu_gocs_daemon.timeout > 0 && mu_gocs_daemon.mode == MODE_DAEMON) |
195 | { | 193 | { |
196 | mu_error (_("--timeout and --daemon are incompatible")); | 194 | mu_error (_("--timeout and --daemon are incompatible")); |
197 | exit (EXIT_FAILURE); | 195 | exit (EXIT_FAILURE); |
... | @@ -199,7 +197,7 @@ main (int argc, char **argv) | ... | @@ -199,7 +197,7 @@ main (int argc, char **argv) |
199 | 197 | ||
200 | comsat_init (); | 198 | comsat_init (); |
201 | 199 | ||
202 | if (daemon_param.mode == MODE_DAEMON) | 200 | if (mu_gocs_daemon.mode == MODE_DAEMON) |
203 | { | 201 | { |
204 | /* Preserve invocation arguments */ | 202 | /* Preserve invocation arguments */ |
205 | xargc = argc; | 203 | xargc = argc; |
... | @@ -216,8 +214,8 @@ main (int argc, char **argv) | ... | @@ -216,8 +214,8 @@ main (int argc, char **argv) |
216 | 214 | ||
217 | chdir ("/"); | 215 | chdir ("/"); |
218 | 216 | ||
219 | if (daemon_param.mode == MODE_DAEMON) | 217 | if (mu_gocs_daemon.mode == MODE_DAEMON) |
220 | comsat_daemon (daemon_param.port); | 218 | comsat_daemon (mu_gocs_daemon.port); |
221 | else | 219 | else |
222 | c = comsat_main (0); | 220 | c = comsat_main (0); |
223 | 221 | ... | ... |
... | @@ -46,7 +46,6 @@ | ... | @@ -46,7 +46,6 @@ |
46 | # include <strings.h> | 46 | # include <strings.h> |
47 | #endif | 47 | #endif |
48 | 48 | ||
49 | #include <mailutils/argp.h> | ||
50 | #include <mailutils/body.h> | 49 | #include <mailutils/body.h> |
51 | #include <mailutils/errno.h> | 50 | #include <mailutils/errno.h> |
52 | #include <mailutils/error.h> | 51 | #include <mailutils/error.h> |
... | @@ -60,6 +59,7 @@ | ... | @@ -60,6 +59,7 @@ |
60 | #include <mailutils/mu_auth.h> | 59 | #include <mailutils/mu_auth.h> |
61 | #include <mailutils/argcv.h> | 60 | #include <mailutils/argcv.h> |
62 | #include <mailutils/nls.h> | 61 | #include <mailutils/nls.h> |
62 | #include <mailutils/daemon.h> | ||
63 | 63 | ||
64 | #ifndef INADDR_NONE | 64 | #ifndef INADDR_NONE |
65 | # define INADDR_NONE -1 | 65 | # define INADDR_NONE -1 | ... | ... |
... | @@ -23,8 +23,8 @@ bin_PROGRAMS = mailutils-config | ... | @@ -23,8 +23,8 @@ bin_PROGRAMS = mailutils-config |
23 | 23 | ||
24 | mailutils_config_SOURCES = mailutils-config.c | 24 | mailutils_config_SOURCES = mailutils-config.c |
25 | mailutils_config_LDADD = \ | 25 | mailutils_config_LDADD = \ |
26 | ../lib/libmuaux.la \ | 26 | ${MU_APP_LIBRARIES}\ |
27 | ${MU_LIB_MAILUTILS} \ | 27 | ${MU_LIB_MAILUTILS}\ |
28 | @MU_COMMON_LIBRARIES@ | 28 | @MU_COMMON_LIBRARIES@ |
29 | 29 | ||
30 | mailutils_config_CFLAGS = -DCOMPILE_FLAGS="\"-I$(includedir)\"" \ | 30 | mailutils_config_CFLAGS = -DCOMPILE_FLAGS="\"-I$(includedir)\"" \ | ... | ... |
... | @@ -21,8 +21,8 @@ | ... | @@ -21,8 +21,8 @@ |
21 | #endif | 21 | #endif |
22 | #include <string.h> | 22 | #include <string.h> |
23 | #include <mailutils/mailutils.h> | 23 | #include <mailutils/mailutils.h> |
24 | #include <mailutils/argp.h> | ||
25 | #include <mu_asprintf.h> | 24 | #include <mu_asprintf.h> |
25 | #include "muinit.h" | ||
26 | 26 | ||
27 | const char *program_version = "mailutils-config (" PACKAGE_STRING ")"; | 27 | const char *program_version = "mailutils-config (" PACKAGE_STRING ")"; |
28 | static char doc[] = N_("GNU mailutils-config -- Display compiler and loader options needed for building a program with mailutils"); | 28 | static char doc[] = N_("GNU mailutils-config -- Display compiler and loader options needed for building a program with mailutils"); |
... | @@ -166,7 +166,7 @@ main (int argc, char **argv) | ... | @@ -166,7 +166,7 @@ main (int argc, char **argv) |
166 | int index; | 166 | int index; |
167 | 167 | ||
168 | mu_argp_init (program_version, NULL); | 168 | mu_argp_init (program_version, NULL); |
169 | if (mu_argp_parse (&argp, &argc, &argv, 0, argp_capa, &index, NULL)) | 169 | if (mu_app_init (&argp, argp_capa, NULL, argc, argv, 0, &index, NULL)) |
170 | { | 170 | { |
171 | argp_help (&argp, stdout, ARGP_HELP_SEE, program_invocation_short_name); | 171 | argp_help (&argp, stdout, ARGP_HELP_SEE, program_invocation_short_name); |
172 | return 1; | 172 | return 1; | ... | ... |
... | @@ -46,13 +46,15 @@ AC_SUBST(MU_LIB_POP,'${top_builddir}/libproto/pop/libmu_pop.la') | ... | @@ -46,13 +46,15 @@ AC_SUBST(MU_LIB_POP,'${top_builddir}/libproto/pop/libmu_pop.la') |
46 | AC_SUBST(MU_LIB_SIEVE,'${top_builddir}/libsieve/libsieve.la') | 46 | AC_SUBST(MU_LIB_SIEVE,'${top_builddir}/libsieve/libsieve.la') |
47 | AC_SUBST(MU_LIB_SCM,'${top_builddir}/libmu_scm/libmu_scm.la') | 47 | AC_SUBST(MU_LIB_SCM,'${top_builddir}/libmu_scm/libmu_scm.la') |
48 | AC_SUBST(MU_LIB_CPP,'${top_builddir}/libmu_cpp/libmu_cpp.la') | 48 | AC_SUBST(MU_LIB_CPP,'${top_builddir}/libmu_cpp/libmu_cpp.la') |
49 | AC_SUBST(MU_LIB_ARGP,'${top_builddir}/libargp/libargp.la') | ||
49 | 50 | ||
50 | dnl Other variables | 51 | dnl Other variables |
51 | AC_SUBST(SIEVE_MODDIR,'$(libdir)/$(PACKAGE)') | 52 | AC_SUBST(SIEVE_MODDIR,'$(libdir)/$(PACKAGE)') |
52 | 53 | ||
53 | AC_SUBST(MU_COMMON_LIBRARIES,'$(LTLIBINTL) $(LTLIBICONV)') | 54 | AC_SUBST(MU_COMMON_LIBRARIES,'$(LTLIBINTL) $(LTLIBICONV)') |
55 | AC_SUBST(MU_APP_LIBRARIES,'../lib/libmuaux.la ../libargp/libargp.a -L${top_builddir}/libcfg -lmucfg') | ||
54 | 56 | ||
55 | AC_SUBST(MU_COMMON_INCLUDES,'-I${srcdir} -I${top_srcdir}/include -I${top_srcdir}/lib -I${top_builddir} -I${top_builddir}/include -I${top_builddir}/include/mailutils/gnu -I${top_srcdir}/mailbox') | 57 | AC_SUBST(MU_COMMON_INCLUDES,'-I${srcdir} -I${top_srcdir}/include -I${top_srcdir}/lib -I${top_builddir} -I${top_builddir}/include -I${top_builddir}/include/mailutils/gnu -I${top_srcdir}/mailbox -I${top_srcdir}/libargp -I${top_srcdir}/libcfg') |
56 | 58 | ||
57 | dnl Check for programs | 59 | dnl Check for programs |
58 | AC_PROG_CC | 60 | AC_PROG_CC |
... | @@ -1169,6 +1171,8 @@ AC_CONFIG_FILES([Makefile | ... | @@ -1169,6 +1171,8 @@ AC_CONFIG_FILES([Makefile |
1169 | libproto/include/Makefile | 1171 | libproto/include/Makefile |
1170 | libsieve/Makefile | 1172 | libsieve/Makefile |
1171 | libsieve/extensions/Makefile | 1173 | libsieve/extensions/Makefile |
1174 | libargp/Makefile | ||
1175 | libcfg/Makefile | ||
1172 | maidag/Makefile | 1176 | maidag/Makefile |
1173 | mail/Makefile | 1177 | mail/Makefile |
1174 | mail/testsuite/Makefile | 1178 | mail/testsuite/Makefile | ... | ... |
... | @@ -22,7 +22,7 @@ INCLUDES = @MU_COMMON_INCLUDES@ | ... | @@ -22,7 +22,7 @@ INCLUDES = @MU_COMMON_INCLUDES@ |
22 | bin_PROGRAMS = dotlock | 22 | bin_PROGRAMS = dotlock |
23 | 23 | ||
24 | dotlock_LDADD = \ | 24 | dotlock_LDADD = \ |
25 | ../lib/libmuaux.la\ | 25 | ${MU_APP_LIBRARIES}\ |
26 | ${MU_LIB_MAILUTILS}\ | 26 | ${MU_LIB_MAILUTILS}\ |
27 | @MU_COMMON_LIBRARIES@ | 27 | @MU_COMMON_LIBRARIES@ |
28 | 28 | ... | ... |
... | @@ -27,11 +27,12 @@ | ... | @@ -27,11 +27,12 @@ |
27 | #endif | 27 | #endif |
28 | #include <unistd.h> | 28 | #include <unistd.h> |
29 | 29 | ||
30 | #include <mailutils/argp.h> | ||
31 | #include <mailutils/errno.h> | 30 | #include <mailutils/errno.h> |
32 | #include <mailutils/locker.h> | 31 | #include <mailutils/locker.h> |
33 | #include <mailutils/nls.h> | 32 | #include <mailutils/nls.h> |
34 | 33 | ||
34 | #include "muinit.h" | ||
35 | |||
35 | const char *program_version = "GNU dotlock (" PACKAGE_STRING ")"; | 36 | const char *program_version = "GNU dotlock (" PACKAGE_STRING ")"; |
36 | static char doc[] = | 37 | static char doc[] = |
37 | N_("GNU dotlock -- lock mail spool files") | 38 | N_("GNU dotlock -- lock mail spool files") |
... | @@ -132,6 +133,7 @@ struct mu_cfg_param dotlock_cfg_param[] = { | ... | @@ -132,6 +133,7 @@ struct mu_cfg_param dotlock_cfg_param[] = { |
132 | 133 | ||
133 | const char *dotlock_capa[] = { | 134 | const char *dotlock_capa[] = { |
134 | "license", | 135 | "license", |
136 | "common", | ||
135 | NULL | 137 | NULL |
136 | }; | 138 | }; |
137 | 139 | ||
... | @@ -151,11 +153,13 @@ main (int argc, char *argv[]) | ... | @@ -151,11 +153,13 @@ main (int argc, char *argv[]) |
151 | if (setegid (usergid) < 0) | 153 | if (setegid (usergid) < 0) |
152 | return MU_DL_EX_ERROR; | 154 | return MU_DL_EX_ERROR; |
153 | 155 | ||
154 | mu_argp_init (program_version, NULL); | ||
155 | argp_err_exit_status = MU_DL_EX_ERROR; | 156 | argp_err_exit_status = MU_DL_EX_ERROR; |
156 | 157 | ||
157 | mu_argp_set_config_param (dotlock_cfg_param); | 158 | mu_argp_init (program_version, NULL); |
158 | mu_argp_parse (&argp, &argc, &argv, 0, dotlock_capa, NULL, NULL); | 159 | if (mu_app_init (&argp, dotlock_capa, dotlock_cfg_param, |
160 | argc, argv, 0, NULL, NULL)) | ||
161 | exit (1); | ||
162 | |||
159 | if (force) | 163 | if (force) |
160 | { | 164 | { |
161 | force *= 60; | 165 | force *= 60; | ... | ... |
... | @@ -125,6 +125,9 @@ lsf_LDADD = \ | ... | @@ -125,6 +125,9 @@ lsf_LDADD = \ |
125 | ${MU_LIB_MAILUTILS} | 125 | ${MU_LIB_MAILUTILS} |
126 | 126 | ||
127 | muauth_LDADD = \ | 127 | muauth_LDADD = \ |
128 | ${MU_APP_LIBRARIES}\ | ||
128 | ${MU_LIB_AUTH}\ | 129 | ${MU_LIB_AUTH}\ |
129 | @MU_AUTHLIBS@ \ | 130 | @MU_AUTHLIBS@ \ |
130 | ${MU_LIB_MAILUTILS} | 131 | ${MU_LIB_MAILUTILS} |
132 | |||
133 | muemail_LDADD = ${MU_APP_LIBRARIES} | ||
... | \ No newline at end of file | ... | \ No newline at end of file | ... | ... |
... | @@ -25,6 +25,7 @@ | ... | @@ -25,6 +25,7 @@ |
25 | #include <ctype.h> | 25 | #include <ctype.h> |
26 | #include <string.h> | 26 | #include <string.h> |
27 | #include <mailutils/mailutils.h> | 27 | #include <mailutils/mailutils.h> |
28 | #include "muinit.h" | ||
28 | 29 | ||
29 | const char *program_version = "muauth (" PACKAGE_STRING ")"; | 30 | const char *program_version = "muauth (" PACKAGE_STRING ")"; |
30 | static char doc[] = | 31 | static char doc[] = |
... | @@ -90,7 +91,9 @@ main (int argc, char * argv []) | ... | @@ -90,7 +91,9 @@ main (int argc, char * argv []) |
90 | 91 | ||
91 | MU_AUTH_REGISTER_ALL_MODULES (); | 92 | MU_AUTH_REGISTER_ALL_MODULES (); |
92 | mu_argp_init (program_version, NULL); | 93 | mu_argp_init (program_version, NULL); |
93 | mu_argp_parse (&argp, &argc, &argv, 0, capa, &index, NULL); | 94 | if (mu_app_init (&argp, capa, NULL, argc, argv, 0, &index, NULL)) |
95 | exit (1); | ||
96 | |||
94 | if (index == argc) | 97 | if (index == argc) |
95 | { | 98 | { |
96 | mu_error ("not enough arguments, try `%s --help' for more info", | 99 | mu_error ("not enough arguments, try `%s --help' for more info", | ... | ... |
... | @@ -17,10 +17,9 @@ | ... | @@ -17,10 +17,9 @@ |
17 | MA 02110-1301 USA */ | 17 | MA 02110-1301 USA */ |
18 | 18 | ||
19 | #include <stdlib.h> | 19 | #include <stdlib.h> |
20 | #include <mailutils/mutil.h> | ||
21 | #include <mailutils/argp.h> | ||
22 | |||
23 | #include <stdio.h> | 20 | #include <stdio.h> |
21 | #include <mailutils/mutil.h> | ||
22 | #include "muinit.h" | ||
24 | 23 | ||
25 | const char *capa[] = { | 24 | const char *capa[] = { |
26 | "address", | 25 | "address", |
... | @@ -32,8 +31,8 @@ main (int argc, char *argv[]) | ... | @@ -32,8 +31,8 @@ main (int argc, char *argv[]) |
32 | { | 31 | { |
33 | int arg = 1; | 32 | int arg = 1; |
34 | 33 | ||
35 | if (mu_argp_parse (NULL, &argc, &argv, 0, capa, &arg, NULL)) | 34 | if (mu_app_init (NULL, capa, NULL, argc, argv, 0, &arg, NULL)) |
36 | abort (); | 35 | exit (1); |
37 | 36 | ||
38 | if (!argv[arg]) | 37 | if (!argv[arg]) |
39 | printf ("current user -> %s\n", mu_get_user_email (0)); | 38 | printf ("current user -> %s\n", mu_get_user_email (0)); | ... | ... |
... | @@ -30,7 +30,7 @@ frm_LDADD = $(common_ldadd) | ... | @@ -30,7 +30,7 @@ frm_LDADD = $(common_ldadd) |
30 | from_LDADD = $(common_ldadd) | 30 | from_LDADD = $(common_ldadd) |
31 | 31 | ||
32 | common_ldadd = \ | 32 | common_ldadd = \ |
33 | ../lib/libmuaux.la\ | 33 | ${MU_APP_LIBRARIES}\ |
34 | ${MU_LIB_MBOX}\ | 34 | ${MU_LIB_MBOX}\ |
35 | ${MU_LIB_IMAP}\ | 35 | ${MU_LIB_IMAP}\ |
36 | ${MU_LIB_POP}\ | 36 | ${MU_LIB_POP}\ | ... | ... |
... | @@ -218,9 +218,6 @@ static const char *frm_argp_capa[] = { | ... | @@ -218,9 +218,6 @@ static const char *frm_argp_capa[] = { |
218 | "common", | 218 | "common", |
219 | "license", | 219 | "license", |
220 | "mailbox", | 220 | "mailbox", |
221 | #ifdef WITH_TLS | ||
222 | "tls", | ||
223 | #endif | ||
224 | NULL | 221 | NULL |
225 | }; | 222 | }; |
226 | 223 | ||
... | @@ -366,12 +363,13 @@ main (int argc, char **argv) | ... | @@ -366,12 +363,13 @@ main (int argc, char **argv) |
366 | 363 | ||
367 | /* register the formats. */ | 364 | /* register the formats. */ |
368 | mu_register_all_mbox_formats (); | 365 | mu_register_all_mbox_formats (); |
369 | |||
370 | mu_argp_init (program_version, NULL); | ||
371 | #ifdef WITH_TLS | 366 | #ifdef WITH_TLS |
372 | mu_tls_init_client_argp (); | 367 | mu_gocs_register ("tls", mu_tls_module_init); |
373 | #endif | 368 | #endif |
374 | mu_argp_parse (&argp, &argc, &argv, 0, frm_argp_capa, &c, NULL); | 369 | |
370 | mu_argp_init (program_version, NULL); | ||
371 | if (mu_app_init (&argp, frm_argp_capa, NULL, argc, argv, 0, &c, NULL)) | ||
372 | exit (1); | ||
375 | 373 | ||
376 | /* have an argument */ | 374 | /* have an argument */ |
377 | if (c == argc) | 375 | if (c == argc) | ... | ... |
... | @@ -47,7 +47,6 @@ | ... | @@ -47,7 +47,6 @@ |
47 | #endif | 47 | #endif |
48 | 48 | ||
49 | #include <mailutils/address.h> | 49 | #include <mailutils/address.h> |
50 | #include <mailutils/argp.h> | ||
51 | #include <mailutils/attribute.h> | 50 | #include <mailutils/attribute.h> |
52 | #include <mailutils/debug.h> | 51 | #include <mailutils/debug.h> |
53 | #include <mailutils/errno.h> | 52 | #include <mailutils/errno.h> |
... | @@ -65,6 +64,8 @@ | ... | @@ -65,6 +64,8 @@ |
65 | #include <mailutils/mutil.h> | 64 | #include <mailutils/mutil.h> |
66 | #include <mailutils/mime.h> | 65 | #include <mailutils/mime.h> |
67 | 66 | ||
67 | #include "muinit.h" | ||
68 | |||
68 | typedef int (*frm_select_t) (size_t index, mu_message_t msg); | 69 | typedef int (*frm_select_t) (size_t index, mu_message_t msg); |
69 | 70 | ||
70 | extern char *show_field; /* Show this header field instead of the default | 71 | extern char *show_field; /* Show this header field instead of the default | ... | ... |
... | @@ -118,10 +118,8 @@ main (int argc, char **argv) | ... | @@ -118,10 +118,8 @@ main (int argc, char **argv) |
118 | mu_register_all_mbox_formats (); | 118 | mu_register_all_mbox_formats (); |
119 | 119 | ||
120 | mu_argp_init (program_version, NULL); | 120 | mu_argp_init (program_version, NULL); |
121 | #ifdef WITH_TLS | 121 | if (mu_app_init (&argp, capa, NULL, argc, argv, 0, &c, NULL)) |
122 | mu_tls_init_client_argp (); | 122 | exit (1); |
123 | #endif | ||
124 | mu_argp_parse (&argp, &argc, &argv, 0, capa, &c, NULL); | ||
125 | 123 | ||
126 | if (argc - c > 1) | 124 | if (argc - c > 1) |
127 | { | 125 | { | ... | ... |
... | @@ -25,7 +25,7 @@ bin_PROGRAMS=@GUIMB@ | ... | @@ -25,7 +25,7 @@ bin_PROGRAMS=@GUIMB@ |
25 | EXTRA_PROGRAMS=guimb | 25 | EXTRA_PROGRAMS=guimb |
26 | guimb_SOURCES=main.c collect.c util.c guimb.h | 26 | guimb_SOURCES=main.c collect.c util.c guimb.h |
27 | guimb_LDADD = \ | 27 | guimb_LDADD = \ |
28 | ../lib/libmuaux.la\ | 28 | ${MU_APP_LIBRARIES}\ |
29 | ../libmu_scm/libmu_scm.la\ | 29 | ../libmu_scm/libmu_scm.la\ |
30 | ${MU_LIB_MBOX}\ | 30 | ${MU_LIB_MBOX}\ |
31 | ${MU_LIB_IMAP}\ | 31 | ${MU_LIB_IMAP}\ | ... | ... |
... | @@ -41,7 +41,6 @@ | ... | @@ -41,7 +41,6 @@ |
41 | #include <mailutils/stream.h> | 41 | #include <mailutils/stream.h> |
42 | #include <mailutils/guile.h> | 42 | #include <mailutils/guile.h> |
43 | #include <mailutils/nls.h> | 43 | #include <mailutils/nls.h> |
44 | #include <mailutils/argp.h> | ||
45 | #include <mailutils/list.h> | 44 | #include <mailutils/list.h> |
46 | #include <mailutils/mutil.h> | 45 | #include <mailutils/mutil.h> |
47 | #include <mailutils/attribute.h> | 46 | #include <mailutils/attribute.h> | ... | ... |
... | @@ -18,6 +18,7 @@ | ... | @@ -18,6 +18,7 @@ |
18 | MA 02110-1301 USA */ | 18 | MA 02110-1301 USA */ |
19 | 19 | ||
20 | #include "guimb.h" | 20 | #include "guimb.h" |
21 | #include "muinit.h" | ||
21 | 22 | ||
22 | char *program_file; | 23 | char *program_file; |
23 | char *program_expr; | 24 | char *program_expr; |
... | @@ -155,8 +156,10 @@ main (int argc, char *argv[]) | ... | @@ -155,8 +156,10 @@ main (int argc, char *argv[]) |
155 | mu_init_nls (); | 156 | mu_init_nls (); |
156 | 157 | ||
157 | append_arg (""); | 158 | append_arg (""); |
159 | |||
158 | mu_argp_init (program_version, NULL); | 160 | mu_argp_init (program_version, NULL); |
159 | mu_argp_parse (&argp, &argc, &argv, 0, guimb_argp_capa, &index, &c); | 161 | if (mu_app_init (&argp, guimb_argp_capa, NULL, argc, argv, 0, &index, &c)) |
162 | exit (1); | ||
160 | 163 | ||
161 | for (; c < argc; c++) | 164 | for (; c < argc; c++) |
162 | append_arg (argv[c]); | 165 | append_arg (argv[c]); | ... | ... |
... | @@ -62,7 +62,7 @@ imap4d_SOURCES = \ | ... | @@ -62,7 +62,7 @@ imap4d_SOURCES = \ |
62 | 62 | ||
63 | imap4d_LDADD = \ | 63 | imap4d_LDADD = \ |
64 | @IMAP_AUTHOBJS@\ | 64 | @IMAP_AUTHOBJS@\ |
65 | ../lib/libmuaux.la\ | 65 | ${MU_APP_LIBRARIES}\ |
66 | ${MU_LIB_MBOX}\ | 66 | ${MU_LIB_MBOX}\ |
67 | ${MU_LIB_MH}\ | 67 | ${MU_LIB_MH}\ |
68 | ${MU_LIB_MAILDIR}\ | 68 | ${MU_LIB_MAILDIR}\ | ... | ... |
... | @@ -49,7 +49,7 @@ imap4d_idle (struct imap4d_command *command, char *arg) | ... | @@ -49,7 +49,7 @@ imap4d_idle (struct imap4d_command *command, char *arg) |
49 | if (rc) | 49 | if (rc) |
50 | break; | 50 | break; |
51 | } | 51 | } |
52 | else if (time (NULL) - start > daemon_param.timeout) | 52 | else if (time (NULL) - start > mu_gocs_daemon.timeout) |
53 | imap4d_bye (ERR_TIMEOUT); | 53 | imap4d_bye (ERR_TIMEOUT); |
54 | 54 | ||
55 | imap4d_sync (); | 55 | imap4d_sync (); | ... | ... |
... | @@ -21,6 +21,7 @@ | ... | @@ -21,6 +21,7 @@ |
21 | #ifdef WITH_GSASL | 21 | #ifdef WITH_GSASL |
22 | # include <mailutils/gsasl.h> | 22 | # include <mailutils/gsasl.h> |
23 | #endif | 23 | #endif |
24 | #include "muinit.h" | ||
24 | 25 | ||
25 | mu_mailbox_t mbox; | 26 | mu_mailbox_t mbox; |
26 | char *homedir; | 27 | char *homedir; |
... | @@ -28,7 +29,7 @@ int state = STATE_NONAUTH; | ... | @@ -28,7 +29,7 @@ int state = STATE_NONAUTH; |
28 | int debug_mode = 0; | 29 | int debug_mode = 0; |
29 | struct mu_auth_data *auth_data; | 30 | struct mu_auth_data *auth_data; |
30 | 31 | ||
31 | struct daemon_param daemon_param = { | 32 | struct mu_gocs_daemon default_gocs_daemon = { |
32 | MODE_INTERACTIVE, /* Start in interactive (inetd) mode */ | 33 | MODE_INTERACTIVE, /* Start in interactive (inetd) mode */ |
33 | 20, /* Default maximum number of children */ | 34 | 20, /* Default maximum number of children */ |
34 | 143, /* Standard IMAP4 port */ | 35 | 143, /* Standard IMAP4 port */ |
... | @@ -87,12 +88,6 @@ static struct argp argp = { | ... | @@ -87,12 +88,6 @@ static struct argp argp = { |
87 | static const char *imap4d_capa[] = { | 88 | static const char *imap4d_capa[] = { |
88 | "daemon", | 89 | "daemon", |
89 | "auth", | 90 | "auth", |
90 | #ifdef WITH_TLS | ||
91 | "tls", | ||
92 | #endif /* WITH_TLS */ | ||
93 | #ifdef WITH_GSASL | ||
94 | "gsasl", | ||
95 | #endif | ||
96 | "common", | 91 | "common", |
97 | "mailbox", | 92 | "mailbox", |
98 | "logging", | 93 | "logging", |
... | @@ -196,16 +191,17 @@ main (int argc, char **argv) | ... | @@ -196,16 +191,17 @@ main (int argc, char **argv) |
196 | 191 | ||
197 | MU_AUTH_REGISTER_ALL_MODULES (); | 192 | MU_AUTH_REGISTER_ALL_MODULES (); |
198 | imap4d_capability_init (); | 193 | imap4d_capability_init (); |
199 | 194 | mu_gocs_daemon = default_gocs_daemon; | |
200 | mu_argp_init (program_version, NULL); | ||
201 | #ifdef WITH_TLS | 195 | #ifdef WITH_TLS |
202 | mu_tls_init_argp (); | 196 | mu_gocs_register ("tls", mu_tls_module_init); |
203 | #endif /* WITH_TLS */ | 197 | #endif /* WITH_TLS */ |
204 | #ifdef WITH_GSASL | 198 | #ifdef WITH_GSASL |
205 | mu_gsasl_init_argp (); | 199 | mu_gocs_register ("gsasl", mu_gsasl_module_init); |
206 | #endif | 200 | #endif |
207 | mu_argp_set_config_param (imap4d_cfg_param); | 201 | mu_argp_init (program_version, NULL); |
208 | mu_argp_parse (&argp, &argc, &argv, 0, imap4d_capa, NULL, &daemon_param); | 202 | if (mu_app_init (&argp, imap4d_capa, imap4d_cfg_param, |
203 | argc, argv, 0, NULL, NULL)) | ||
204 | exit (1); | ||
209 | 205 | ||
210 | if (login_disabled) | 206 | if (login_disabled) |
211 | imap4d_capability_add (IMAP_CAPA_LOGINDISABLED); | 207 | imap4d_capability_add (IMAP_CAPA_LOGINDISABLED); |
... | @@ -218,11 +214,11 @@ main (int argc, char **argv) | ... | @@ -218,11 +214,11 @@ main (int argc, char **argv) |
218 | auth_gsasl_init (); | 214 | auth_gsasl_init (); |
219 | 215 | ||
220 | #ifdef USE_LIBPAM | 216 | #ifdef USE_LIBPAM |
221 | if (!pam_service) | 217 | if (!mu_pam_service) |
222 | pam_service = "gnu-imap4d"; | 218 | mu_pam_service = "gnu-imap4d"; |
223 | #endif | 219 | #endif |
224 | 220 | ||
225 | if (daemon_param.mode == MODE_INTERACTIVE && isatty (0)) | 221 | if (mu_gocs_daemon.mode == MODE_INTERACTIVE && isatty (0)) |
226 | { | 222 | { |
227 | /* If input is a tty, switch to debug mode */ | 223 | /* If input is a tty, switch to debug mode */ |
228 | debug_mode = 1; | 224 | debug_mode = 1; |
... | @@ -261,7 +257,7 @@ main (int argc, char **argv) | ... | @@ -261,7 +257,7 @@ main (int argc, char **argv) |
261 | /*signal (SIGPIPE, SIG_IGN); */ | 257 | /*signal (SIGPIPE, SIG_IGN); */ |
262 | signal (SIGABRT, imap4d_signal); | 258 | signal (SIGABRT, imap4d_signal); |
263 | 259 | ||
264 | if (daemon_param.mode == MODE_DAEMON) | 260 | if (mu_gocs_daemon.mode == MODE_DAEMON) |
265 | imap4d_daemon_init (); | 261 | imap4d_daemon_init (); |
266 | else | 262 | else |
267 | { | 263 | { |
... | @@ -278,9 +274,9 @@ main (int argc, char **argv) | ... | @@ -278,9 +274,9 @@ main (int argc, char **argv) |
278 | 274 | ||
279 | umask (S_IROTH | S_IWOTH | S_IXOTH); /* 007 */ | 275 | umask (S_IROTH | S_IWOTH | S_IXOTH); /* 007 */ |
280 | 276 | ||
281 | if (daemon_param.pidfile) | 277 | if (mu_gocs_daemon.pidfile) |
282 | { | 278 | { |
283 | mu_daemon_create_pidfile (daemon_param.pidfile); | 279 | mu_daemon_create_pidfile (mu_gocs_daemon.pidfile); |
284 | } | 280 | } |
285 | 281 | ||
286 | /* Check TLS environment, i.e. cert and key files */ | 282 | /* Check TLS environment, i.e. cert and key files */ |
... | @@ -289,8 +285,8 @@ main (int argc, char **argv) | ... | @@ -289,8 +285,8 @@ main (int argc, char **argv) |
289 | #endif /* WITH_TLS */ | 285 | #endif /* WITH_TLS */ |
290 | 286 | ||
291 | /* Actually run the daemon. */ | 287 | /* Actually run the daemon. */ |
292 | if (daemon_param.mode == MODE_DAEMON) | 288 | if (mu_gocs_daemon.mode == MODE_DAEMON) |
293 | imap4d_daemon (daemon_param.maxchildren, daemon_param.port); | 289 | imap4d_daemon (mu_gocs_daemon.maxchildren, mu_gocs_daemon.port); |
294 | /* exit (0) -- no way out of daemon except a signal. */ | 290 | /* exit (0) -- no way out of daemon except a signal. */ |
295 | else | 291 | else |
296 | status = imap4d_mainloop (fileno (stdin), stdin, stdout); | 292 | status = imap4d_mainloop (fileno (stdin), stdin, stdout); | ... | ... |
... | @@ -71,7 +71,6 @@ | ... | @@ -71,7 +71,6 @@ |
71 | #endif | 71 | #endif |
72 | 72 | ||
73 | #include <mailutils/address.h> | 73 | #include <mailutils/address.h> |
74 | #include <mailutils/argp.h> | ||
75 | #include <mailutils/attribute.h> | 74 | #include <mailutils/attribute.h> |
76 | #include <mailutils/body.h> | 75 | #include <mailutils/body.h> |
77 | #include <mailutils/daemon.h> | 76 | #include <mailutils/daemon.h> |
... | @@ -93,6 +92,8 @@ | ... | @@ -93,6 +92,8 @@ |
93 | #include <mailutils/stream.h> | 92 | #include <mailutils/stream.h> |
94 | #include <mailutils/tls.h> | 93 | #include <mailutils/tls.h> |
95 | #include <mailutils/url.h> | 94 | #include <mailutils/url.h> |
95 | #include <mailutils/daemon.h> | ||
96 | #include <mailutils/pam.h> | ||
96 | 97 | ||
97 | #include <mu_asprintf.h> | 98 | #include <mu_asprintf.h> |
98 | #include <mu_umaxtostr.h> | 99 | #include <mu_umaxtostr.h> |
... | @@ -161,8 +162,8 @@ extern char *rootdir; | ... | @@ -161,8 +162,8 @@ extern char *rootdir; |
161 | extern int state; | 162 | extern int state; |
162 | extern size_t children; | 163 | extern size_t children; |
163 | extern int is_virtual; | 164 | extern int is_virtual; |
164 | extern struct daemon_param daemon_param; | ||
165 | extern struct mu_auth_data *auth_data; | 165 | extern struct mu_auth_data *auth_data; |
166 | extern const char *program_version; | ||
166 | 167 | ||
167 | extern int login_disabled; | 168 | extern int login_disabled; |
168 | extern int tls_required; | 169 | extern int tls_required; | ... | ... |
... | @@ -360,7 +360,7 @@ util_send (const char *format, ...) | ... | @@ -360,7 +360,7 @@ util_send (const char *format, ...) |
360 | if (!buf) | 360 | if (!buf) |
361 | imap4d_bye (ERR_NO_MEM); | 361 | imap4d_bye (ERR_NO_MEM); |
362 | 362 | ||
363 | if (daemon_param.transcript) | 363 | if (mu_gocs_daemon.transcript) |
364 | syslog (LOG_DEBUG, "sent: %s", buf); | 364 | syslog (LOG_DEBUG, "sent: %s", buf); |
365 | 365 | ||
366 | status = mu_stream_sequential_write (ostream, buf, strlen (buf)); | 366 | status = mu_stream_sequential_write (ostream, buf, strlen (buf)); |
... | @@ -414,7 +414,7 @@ util_out (int rc, const char *format, ...) | ... | @@ -414,7 +414,7 @@ util_out (int rc, const char *format, ...) |
414 | if (!buf) | 414 | if (!buf) |
415 | imap4d_bye (ERR_NO_MEM); | 415 | imap4d_bye (ERR_NO_MEM); |
416 | 416 | ||
417 | if (daemon_param.transcript) | 417 | if (mu_gocs_daemon.transcript) |
418 | syslog (LOG_DEBUG, "sent: %s", buf); | 418 | syslog (LOG_DEBUG, "sent: %s", buf); |
419 | 419 | ||
420 | status = mu_stream_sequential_write (ostream, buf, strlen (buf)); | 420 | status = mu_stream_sequential_write (ostream, buf, strlen (buf)); |
... | @@ -455,7 +455,7 @@ util_finish (struct imap4d_command *command, int rc, const char *format, ...) | ... | @@ -455,7 +455,7 @@ util_finish (struct imap4d_command *command, int rc, const char *format, ...) |
455 | strcat (buf, tempbuf); | 455 | strcat (buf, tempbuf); |
456 | free (tempbuf); | 456 | free (tempbuf); |
457 | 457 | ||
458 | if (daemon_param.transcript) | 458 | if (mu_gocs_daemon.transcript) |
459 | syslog (LOG_DEBUG, "sent: %s\r\n", buf); | 459 | syslog (LOG_DEBUG, "sent: %s\r\n", buf); |
460 | 460 | ||
461 | mu_stream_sequential_write (ostream, buf, strlen (buf)); | 461 | mu_stream_sequential_write (ostream, buf, strlen (buf)); |
... | @@ -503,7 +503,7 @@ imap4d_readline (void) | ... | @@ -503,7 +503,7 @@ imap4d_readline (void) |
503 | size_t sz; | 503 | size_t sz; |
504 | int rc; | 504 | int rc; |
505 | 505 | ||
506 | alarm (daemon_param.timeout); | 506 | alarm (mu_gocs_daemon.timeout); |
507 | rc = mu_stream_sequential_readline (istream, buffer, sizeof (buffer), &sz); | 507 | rc = mu_stream_sequential_readline (istream, buffer, sizeof (buffer), &sz); |
508 | if (sz == 0) | 508 | if (sz == 0) |
509 | { | 509 | { |
... | @@ -577,7 +577,7 @@ imap4d_readline (void) | ... | @@ -577,7 +577,7 @@ imap4d_readline (void) |
577 | } | 577 | } |
578 | } | 578 | } |
579 | while (number > 0 || (total && line[total - 1] != '\n')); | 579 | while (number > 0 || (total && line[total - 1] != '\n')); |
580 | if (daemon_param.transcript) | 580 | if (mu_gocs_daemon.transcript) |
581 | syslog (LOG_DEBUG, "recv: %s", line); | 581 | syslog (LOG_DEBUG, "recv: %s", line); |
582 | return line; | 582 | return line; |
583 | } | 583 | } | ... | ... |
... | @@ -21,6 +21,6 @@ | ... | @@ -21,6 +21,6 @@ |
21 | int | 21 | int |
22 | imap4d_version (struct imap4d_command *command, char *arg) | 22 | imap4d_version (struct imap4d_command *command, char *arg) |
23 | { | 23 | { |
24 | util_send ("* %s GNU %s\r\n", command->name, argp_program_version); | 24 | util_send ("* %s GNU %s\r\n", command->name, program_version); |
25 | return util_finish (command, RESP_OK, "Completed"); | 25 | return util_finish (command, RESP_OK, "Completed"); |
26 | } | 26 | } | ... | ... |
... | @@ -29,53 +29,56 @@ DISTCLEANFILES = types.h | ... | @@ -29,53 +29,56 @@ DISTCLEANFILES = types.h |
29 | 29 | ||
30 | pkginclude_DATA = types.h | 30 | pkginclude_DATA = types.h |
31 | pkginclude_HEADERS = \ | 31 | pkginclude_HEADERS = \ |
32 | address.h \ | 32 | address.h\ |
33 | argcv.h \ | 33 | argcv.h\ |
34 | argp.h \ | 34 | assoc.h\ |
35 | assoc.h \ | 35 | attribute.h\ |
36 | attribute.h \ | 36 | auth.h\ |
37 | auth.h \ | 37 | body.h\ |
38 | body.h \ | 38 | cfg.h\ |
39 | cfg.h \ | 39 | compat.h\ |
40 | compat.h \ | 40 | daemon.h\ |
41 | daemon.h \ | 41 | debug.h\ |
42 | debug.h \ | 42 | envelope.h\ |
43 | envelope.h \ | 43 | errno.h\ |
44 | errno.h \ | 44 | error.h\ |
45 | error.h \ | 45 | filter.h\ |
46 | filter.h \ | 46 | folder.h\ |
47 | folder.h \ | 47 | gocs.h\ |
48 | gsasl.h \ | 48 | gsasl.h\ |
49 | guile.h \ | 49 | guile.h\ |
50 | header.h \ | 50 | header.h\ |
51 | iterator.h \ | 51 | iterator.h\ |
52 | libsieve.h \ | 52 | libsieve.h\ |
53 | list.h \ | 53 | list.h\ |
54 | locker.h \ | 54 | locker.h\ |
55 | mailbox.h \ | 55 | mailbox.h\ |
56 | mailcap.h \ | 56 | mailcap.h\ |
57 | mailer.h \ | 57 | mailer.h\ |
58 | mailutils.h \ | 58 | mailutils.h\ |
59 | message.h \ | 59 | message.h\ |
60 | mime.h \ | 60 | mime.h\ |
61 | monitor.h \ | 61 | monitor.h\ |
62 | mu_auth.h \ | 62 | mu_auth.h\ |
63 | mutil.h \ | 63 | mutil.h\ |
64 | nls.h \ | 64 | nls.h\ |
65 | nntp.h \ | 65 | nntp.h\ |
66 | observer.h \ | 66 | observer.h\ |
67 | parse822.h \ | 67 | pam.h\ |
68 | pop3.h \ | 68 | parse822.h\ |
69 | property.h \ | 69 | pop3.h\ |
70 | refcount.h \ | 70 | property.h\ |
71 | registrar.h \ | 71 | radius.h\ |
72 | stream.h \ | 72 | refcount.h\ |
73 | sql.h \ | 73 | registrar.h\ |
74 | tls.h \ | 74 | stream.h\ |
75 | syslog.h\ | ||
76 | sql.h\ | ||
77 | tls.h\ | ||
75 | url.h | 78 | url.h |
76 | 79 | ||
77 | nobase_pkginclude_HEADERS = \ | 80 | nobase_pkginclude_HEADERS = \ |
78 | sys/nntp.h \ | 81 | sys/nntp.h\ |
79 | sys/pop3.h | 82 | sys/pop3.h |
80 | SUBDIRS = gnu sys | 83 | SUBDIRS = gnu sys |
81 | 84 | ... | ... |
... | @@ -18,6 +18,7 @@ | ... | @@ -18,6 +18,7 @@ |
18 | #ifndef _MAILUTILS_CFG_H | 18 | #ifndef _MAILUTILS_CFG_H |
19 | #define _MAILUTILS_CFG_H | 19 | #define _MAILUTILS_CFG_H |
20 | 20 | ||
21 | #include <mailutils/list.h> | ||
21 | #include <sys/socket.h> | 22 | #include <sys/socket.h> |
22 | #include <netinet/in.h> | 23 | #include <netinet/in.h> |
23 | #include <arpa/inet.h> | 24 | #include <arpa/inet.h> |
... | @@ -186,4 +187,6 @@ int mu_config_register_plain_section (const char *parent_path, | ... | @@ -186,4 +187,6 @@ int mu_config_register_plain_section (const char *parent_path, |
186 | int mu_parse_config (char *file, char *progname, | 187 | int mu_parse_config (char *file, char *progname, |
187 | struct mu_cfg_param *progparam, int global); | 188 | struct mu_cfg_param *progparam, int global); |
188 | 189 | ||
190 | int mu_cfg_parse_boolean (const char *str, int *res); | ||
191 | |||
189 | #endif | 192 | #endif | ... | ... |
... | @@ -20,14 +20,21 @@ | ... | @@ -20,14 +20,21 @@ |
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> | ||
23 | 24 | ||
24 | #ifdef __cplusplus | 25 | #ifdef __cplusplus |
25 | extern "C" { | 26 | extern "C" { |
26 | #endif | 27 | #endif |
27 | 28 | ||
29 | /* FIXME: Namespace */ | ||
30 | #define MODE_INTERACTIVE 0 | ||
31 | #define MODE_DAEMON 1 | ||
32 | |||
28 | extern int mu_daemon_create_pidfile (const char *); | 33 | extern int mu_daemon_create_pidfile (const char *); |
29 | extern void mu_daemon_remove_pidfile (void); | 34 | extern void mu_daemon_remove_pidfile (void); |
30 | 35 | ||
36 | extern struct mu_gocs_daemon mu_gocs_daemon; | ||
37 | |||
31 | #ifdef __cplusplus | 38 | #ifdef __cplusplus |
32 | } | 39 | } |
33 | #endif | 40 | #endif | ... | ... |
... | @@ -29,6 +29,9 @@ extern "C" { | ... | @@ -29,6 +29,9 @@ extern "C" { |
29 | 29 | ||
30 | typedef int (*mu_error_pfn_t) (const char *fmt, va_list ap); | 30 | typedef int (*mu_error_pfn_t) (const char *fmt, va_list ap); |
31 | 31 | ||
32 | extern const char *mu_program_name; | ||
33 | extern void mu_set_program_name (const char *name); | ||
34 | |||
32 | extern int mu_verror (const char *fmt, va_list ap); | 35 | extern int mu_verror (const char *fmt, va_list ap); |
33 | extern int mu_error (const char *fmt, ...) MU_PRINTFLIKE(1,2); | 36 | extern int mu_error (const char *fmt, ...) MU_PRINTFLIKE(1,2); |
34 | extern void mu_error_set_print (mu_error_pfn_t); | 37 | extern void mu_error_set_print (mu_error_pfn_t); | ... | ... |
include/mailutils/gocs.h
0 → 100644
1 | /* GNU Mailutils -- a suite of utilities for electronic mail | ||
2 | Copyright (C) 2007 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, write to the | ||
16 | Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | ||
17 | Boston, MA 02110-1301 USA */ | ||
18 | |||
19 | #ifndef _MAILUTILS_GOCS_H | ||
20 | #define _MAILUTILS_GOCS_H | ||
21 | |||
22 | #include <mailutils/types.h> | ||
23 | #include <mailutils/list.h> | ||
24 | |||
25 | #ifdef __cplusplus | ||
26 | extern "C" { | ||
27 | #endif | ||
28 | |||
29 | struct mu_gocs_daemon | ||
30 | { | ||
31 | int mode; | ||
32 | size_t maxchildren; | ||
33 | unsigned int port; | ||
34 | unsigned int timeout; | ||
35 | int transcript; | ||
36 | char *pidfile; | ||
37 | }; | ||
38 | |||
39 | struct mu_gocs_logging | ||
40 | { | ||
41 | int facility; | ||
42 | char *tag; | ||
43 | }; | ||
44 | |||
45 | struct mu_gocs_mailbox | ||
46 | { | ||
47 | char *mail_spool; | ||
48 | char *mailbox_type; | ||
49 | }; | ||
50 | |||
51 | struct mu_gocs_locking | ||
52 | { | ||
53 | char *lock_flags; | ||
54 | unsigned long lock_retry_timeout; | ||
55 | unsigned long lock_retry_count; | ||
56 | unsigned long lock_expire_timeout; | ||
57 | char *external_locker; | ||
58 | }; | ||
59 | |||
60 | struct mu_gocs_source_email | ||
61 | { | ||
62 | char *address; | ||
63 | char *domain; | ||
64 | }; | ||
65 | |||
66 | struct mu_gocs_mailer | ||
67 | { | ||
68 | char *mailer; | ||
69 | }; | ||
70 | |||
71 | /* Auxiliary variables for use by libargp/libcfg */ | ||
72 | extern int mu_load_user_rcfile; | ||
73 | extern int mu_load_site_rcfile; | ||
74 | extern char *mu_load_rcfile; | ||
75 | |||
76 | extern int log_facility; /* FIXME: 1. Belongs elsewhere; | ||
77 | 2. Does not begin with `mu_' */ | ||
78 | |||
79 | typedef int (*gocs_init_fp) (void *data); | ||
80 | |||
81 | void mu_gocs_register (char *capa, gocs_init_fp init); | ||
82 | void mu_gocs_register_std (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 (void *data); | ||
88 | int mu_gocs_locking_init (void *data); | ||
89 | int mu_gocs_daemon_init (void *data); | ||
90 | int mu_gocs_source_email_init (void *data); | ||
91 | int mu_gocs_mailer_init (void *data); | ||
92 | int mu_gocs_logging_init (void *data); | ||
93 | |||
94 | #ifdef __cplusplus | ||
95 | } | ||
96 | #endif | ||
97 | |||
98 | #endif |
... | @@ -19,14 +19,22 @@ | ... | @@ -19,14 +19,22 @@ |
19 | #ifndef _MAILUTILS_GSASL_H | 19 | #ifndef _MAILUTILS_GSASL_H |
20 | #define _MAILUTILS_GSASL_H | 20 | #define _MAILUTILS_GSASL_H |
21 | 21 | ||
22 | struct mu_gsasl_module_data | ||
23 | { | ||
24 | char *cram_md5_pwd; | ||
25 | }; | ||
26 | |||
27 | int mu_gsasl_module_init (void *data); | ||
28 | |||
29 | struct mu_gsasl_module_data mu_gsasl_module_data; | ||
30 | |||
31 | #ifdef USE_GSASL | ||
22 | #include <gsasl.h> | 32 | #include <gsasl.h> |
23 | 33 | ||
24 | int mu_gsasl_stream_create (mu_stream_t *stream, mu_stream_t transport, | 34 | int mu_gsasl_stream_create (mu_stream_t *stream, mu_stream_t transport, |
25 | Gsasl_session_ctx *ctx, | 35 | Gsasl_session_ctx *ctx, |
26 | int flags); | 36 | int flags); |
27 | 37 | ||
28 | void mu_gsasl_init_argp (void); | 38 | #endif |
29 | |||
30 | extern char *mu_gsasl_cram_md5_pwd; | ||
31 | 39 | ||
32 | #endif /* not _MAILUTILS_GSASL_H */ | 40 | #endif /* not _MAILUTILS_GSASL_H */ | ... | ... |
... | @@ -259,9 +259,19 @@ int mu_sieve_mailbox (mu_sieve_machine_t mach, mu_mailbox_t mbox); | ... | @@ -259,9 +259,19 @@ int mu_sieve_mailbox (mu_sieve_machine_t mach, mu_mailbox_t mbox); |
259 | int mu_sieve_message (mu_sieve_machine_t mach, mu_message_t message); | 259 | int mu_sieve_message (mu_sieve_machine_t mach, mu_message_t message); |
260 | int mu_sieve_disass (mu_sieve_machine_t mach); | 260 | int mu_sieve_disass (mu_sieve_machine_t mach); |
261 | 261 | ||
262 | /* Command line handling */ | 262 | /* Configuration functions */ |
263 | 263 | ||
264 | extern void mu_sieve_argp_init (void); | 264 | #define MU_SIEVE_CLEAR_INCLUDE_PATH 0x1 |
265 | #define MU_SIEVE_CLEAR_LIBRARY_PATH 0x2 | ||
266 | |||
267 | struct mu_gocs_sieve | ||
268 | { | ||
269 | int clearflags; | ||
270 | mu_list_t include_path; | ||
271 | mu_list_t library_path; | ||
272 | }; | ||
273 | |||
274 | int mu_sieve_module_init (void *); | ||
265 | 275 | ||
266 | #ifdef __cplusplus | 276 | #ifdef __cplusplus |
267 | } | 277 | } | ... | ... |
... | @@ -19,7 +19,6 @@ | ... | @@ -19,7 +19,6 @@ |
19 | 19 | ||
20 | #include <mailutils/address.h> | 20 | #include <mailutils/address.h> |
21 | #include <mailutils/argcv.h> | 21 | #include <mailutils/argcv.h> |
22 | #include <mailutils/argp.h> | ||
23 | #include <mailutils/attribute.h> | 22 | #include <mailutils/attribute.h> |
24 | #include <mailutils/auth.h> | 23 | #include <mailutils/auth.h> |
25 | #include <mailutils/body.h> | 24 | #include <mailutils/body.h> |
... | @@ -53,6 +52,7 @@ | ... | @@ -53,6 +52,7 @@ |
53 | #include <mailutils/tls.h> | 52 | #include <mailutils/tls.h> |
54 | #include <mailutils/types.h> | 53 | #include <mailutils/types.h> |
55 | #include <mailutils/url.h> | 54 | #include <mailutils/url.h> |
55 | #include <mailutils/gocs.h> | ||
56 | 56 | ||
57 | #ifdef MU_COMPAT | 57 | #ifdef MU_COMPAT |
58 | # include <mailutils/compat.h> | 58 | # include <mailutils/compat.h> | ... | ... |
... | @@ -20,6 +20,7 @@ | ... | @@ -20,6 +20,7 @@ |
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> | ||
23 | 24 | ||
24 | #define MU_AUTH_NAME "name" | 25 | #define MU_AUTH_NAME "name" |
25 | #define MU_AUTH_PASSWD "passwd" | 26 | #define MU_AUTH_PASSWD "passwd" |
... | @@ -61,8 +62,7 @@ typedef int (*mu_auth_fp) (struct mu_auth_data **data, | ... | @@ -61,8 +62,7 @@ typedef int (*mu_auth_fp) (struct mu_auth_data **data, |
61 | struct mu_auth_module | 62 | struct mu_auth_module |
62 | { | 63 | { |
63 | char *name; | 64 | char *name; |
64 | struct argp *argp; | 65 | gocs_init_fp init; |
65 | struct mu_cfg_param *cfg; | ||
66 | mu_auth_fp authenticate; | 66 | mu_auth_fp authenticate; |
67 | void *authenticate_data; | 67 | void *authenticate_data; |
68 | mu_auth_fp auth_by_name; | 68 | mu_auth_fp auth_by_name; |
... | @@ -130,7 +130,6 @@ extern struct mu_auth_module mu_auth_virtual_module; | ... | @@ -130,7 +130,6 @@ extern struct mu_auth_module mu_auth_virtual_module; |
130 | extern struct mu_auth_module mu_auth_radius_module; | 130 | extern struct mu_auth_module mu_auth_radius_module; |
131 | 131 | ||
132 | #define MU_AUTH_REGISTER_ALL_MODULES() do {\ | 132 | #define MU_AUTH_REGISTER_ALL_MODULES() do {\ |
133 | mu_auth_init (); \ | ||
134 | mu_auth_register_module (&mu_auth_generic_module); \ | 133 | mu_auth_register_module (&mu_auth_generic_module); \ |
135 | mu_auth_register_module (&mu_auth_system_module); \ | 134 | mu_auth_register_module (&mu_auth_system_module); \ |
136 | mu_auth_register_module (&mu_auth_pam_module);\ | 135 | mu_auth_register_module (&mu_auth_pam_module);\ | ... | ... |
include/mailutils/pam.h
0 → 100644
1 | /* GNU Mailutils -- a suite of utilities for electronic mail | ||
2 | Copyright (C) 1999, 2000, 2001, 2004, 2005, | ||
3 | 2007 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, write to the | ||
17 | Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | ||
18 | Boston, MA 02110-1301 USA */ | ||
19 | |||
20 | #ifndef _MAILUTILS_PAM_H | ||
21 | #define _MAILUTILS_PAM_H | ||
22 | #include <mailutils/types.h> | ||
23 | |||
24 | extern char *mu_pam_service; | ||
25 | |||
26 | #endif |
include/mailutils/radius.h
0 → 100644
1 | /* GNU Mailutils -- a suite of utilities for electronic mail | ||
2 | Copyright (C) 1999, 2000, 2001, 2004, 2005, | ||
3 | 2007 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, write to the | ||
17 | Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | ||
18 | Boston, MA 02110-1301 USA */ | ||
19 | |||
20 | #ifndef _MAILUTILS_RADIUS_H | ||
21 | #define _MAILUTILS_RADIUS_H | ||
22 | #include <mailutils/types.h> | ||
23 | |||
24 | struct mu_radius_module_data | ||
25 | { | ||
26 | char *config_dir; | ||
27 | char *auth_request; | ||
28 | char *getpwnam_request; | ||
29 | char *getpwuid_request; | ||
30 | }; | ||
31 | |||
32 | extern int mu_radius_module_init (void *data); | ||
33 | |||
34 | #endif |
... | @@ -19,7 +19,30 @@ | ... | @@ -19,7 +19,30 @@ |
19 | #ifndef _MAILUTILS_SQL_H | 19 | #ifndef _MAILUTILS_SQL_H |
20 | #define _MAILUTILS_SQL_H | 20 | #define _MAILUTILS_SQL_H |
21 | 21 | ||
22 | /* Loadable Modules Suppert */ | 22 | /* Configuration */ |
23 | enum mu_password_type | ||
24 | { | ||
25 | password_plaintext, /* Plaintext passwords */ | ||
26 | password_scrambled, /* Scrambled MySQL (>=3.21) password */ | ||
27 | password_hash, /* MD5 (or DES or whatever) hash */ | ||
28 | }; | ||
29 | |||
30 | struct mu_sql_module_config | ||
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 | mu_assoc_t field_map; | ||
43 | }; | ||
44 | |||
45 | /* Loadable Modules Support */ | ||
23 | #define __s_cat2__(a,b) a ## b | 46 | #define __s_cat2__(a,b) a ## b |
24 | #define __s_cat3__(a,b,c) a ## b ## c | 47 | #define __s_cat3__(a,b,c) a ## b ## c |
25 | #define RDL_EXPORT(module,name) __s_cat3__(module,_LTX_,name) | 48 | #define RDL_EXPORT(module,name) __s_cat3__(module,_LTX_,name) |
... | @@ -27,7 +50,7 @@ | ... | @@ -27,7 +50,7 @@ |
27 | typedef int (*mu_rdl_init_t) (void); | 50 | typedef int (*mu_rdl_init_t) (void); |
28 | typedef void (*mu_rdl_done_t) (void); | 51 | typedef void (*mu_rdl_done_t) (void); |
29 | 52 | ||
30 | #ifdef _HAVE_LIBLTDL //FIXME: Remove leading _ when SQL + ltdl works | 53 | #ifdef _HAVE_LIBLTDL /*FIXME: Remove leading _ when SQL + ltdl works*/ |
31 | # define MU_DECL_SQL_DISPATCH_T(mod) \ | 54 | # define MU_DECL_SQL_DISPATCH_T(mod) \ |
32 | mu_sql_dispatch_t RDL_EXPORT(mod,dispatch_tab) | 55 | mu_sql_dispatch_t RDL_EXPORT(mod,dispatch_tab) |
33 | #else | 56 | #else |
... | @@ -112,18 +135,11 @@ int mu_sql_get_field (mu_sql_connection_t conn, size_t nrow, char *fname, | ... | @@ -112,18 +135,11 @@ int mu_sql_get_field (mu_sql_connection_t conn, size_t nrow, char *fname, |
112 | 135 | ||
113 | const char *mu_sql_strerror (mu_sql_connection_t conn); | 136 | const char *mu_sql_strerror (mu_sql_connection_t conn); |
114 | 137 | ||
115 | enum mu_password_type | ||
116 | { | ||
117 | password_plaintext, /* Plaintext passwords */ | ||
118 | password_scrambled, /* Scrambled MySQL (>=3.21) password */ | ||
119 | password_hash, /* MD5 (or DES or whatever) hash */ | ||
120 | }; | ||
121 | |||
122 | extern enum mu_password_type mu_sql_password_type; | ||
123 | |||
124 | extern char *mu_sql_expand_query (const char *query, const char *ustr); | 138 | extern char *mu_sql_expand_query (const char *query, const char *ustr); |
125 | extern int mu_sql_getpass (const char *username, char **passwd); | 139 | extern int mu_sql_getpass (const char *username, char **passwd); |
126 | extern int mu_check_mysql_scrambled_password (const char *scrambled, | 140 | extern int mu_check_mysql_scrambled_password (const char *scrambled, |
127 | const char *message); | 141 | const char *message); |
128 | 142 | ||
143 | int mu_sql_decode_password_type (const char *arg, enum mu_password_type *t); | ||
144 | |||
129 | #endif | 145 | #endif | ... | ... |
include/mailutils/syslog.h
0 → 100644
1 | /* GNU Mailutils -- a suite of utilities for electronic mail | ||
2 | Copyright (C) 2007 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, write to the | ||
16 | Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | ||
17 | Boston, MA 02110-1301 USA */ | ||
18 | |||
19 | #ifndef _MAILUTILS_SYSLOG_H | ||
20 | #define _MAILUTILS_SYSLOG_H | ||
21 | |||
22 | #include <syslog.h> | ||
23 | |||
24 | #ifdef __cplusplus | ||
25 | extern "C" { | ||
26 | #endif | ||
27 | |||
28 | int mu_string_to_syslog_facility (char *str, int *pfacility); | ||
29 | const char *mu_syslog_facility_to_string (int n); | ||
30 | int mu_string_to_syslog_priority (char *str, int *pprio); | ||
31 | const char *mu_syslog_priority_to_string (int n); | ||
32 | |||
33 | #ifdef __cplusplus | ||
34 | } | ||
35 | #endif | ||
36 | |||
37 | #endif | ||
38 | |||
39 |
... | @@ -19,16 +19,25 @@ | ... | @@ -19,16 +19,25 @@ |
19 | #ifndef _MAILUTILS_TLS_H | 19 | #ifndef _MAILUTILS_TLS_H |
20 | #define _MAILUTILS_TLS_H | 20 | #define _MAILUTILS_TLS_H |
21 | 21 | ||
22 | #ifdef WITH_TLS | ||
23 | |||
24 | #include <mailutils/types.h> | 22 | #include <mailutils/types.h> |
25 | 23 | ||
26 | #ifdef __cplusplus | 24 | #ifdef __cplusplus |
27 | extern "C" { | 25 | extern "C" { |
28 | #endif | 26 | #endif |
29 | 27 | ||
28 | struct mu_tls_module_config | ||
29 | { | ||
30 | int client_enable; | ||
31 | char *ssl_cert; | ||
32 | char *ssl_key; | ||
33 | char *ssl_cafile; | ||
34 | }; | ||
35 | |||
36 | extern int mu_tls_module_init (void *data); | ||
37 | |||
30 | extern int mu_tls_stream_create (mu_stream_t *stream, | 38 | extern int mu_tls_stream_create (mu_stream_t *stream, |
31 | mu_stream_t strin, mu_stream_t strout, int flags); | 39 | mu_stream_t strin, mu_stream_t strout, |
40 | int flags); | ||
32 | extern int mu_tls_stream_create_client (mu_stream_t *stream, | 41 | extern int mu_tls_stream_create_client (mu_stream_t *stream, |
33 | mu_stream_t strin, mu_stream_t strout, | 42 | mu_stream_t strin, mu_stream_t strout, |
34 | int flags); | 43 | int flags); |
... | @@ -39,8 +48,6 @@ extern int mu_tls_stream_create_client_from_tcp (mu_stream_t *stream, | ... | @@ -39,8 +48,6 @@ extern int mu_tls_stream_create_client_from_tcp (mu_stream_t *stream, |
39 | extern int mu_check_tls_environment (void); | 48 | extern int mu_check_tls_environment (void); |
40 | extern int mu_init_tls_libs (void); | 49 | extern int mu_init_tls_libs (void); |
41 | extern void mu_deinit_tls_libs (void); | 50 | extern void mu_deinit_tls_libs (void); |
42 | extern void mu_tls_init_argp (void); | ||
43 | extern void mu_tls_init_client_argp (void); | ||
44 | 51 | ||
45 | typedef int (*mu_tls_readline_fn) (void *iodata); | 52 | typedef int (*mu_tls_readline_fn) (void *iodata); |
46 | typedef int (*mu_tls_writeline_fn) (void *iodata, char *buf); | 53 | typedef int (*mu_tls_writeline_fn) (void *iodata, char *buf); |
... | @@ -58,6 +65,5 @@ extern int mu_tls_enable; | ... | @@ -58,6 +65,5 @@ extern int mu_tls_enable; |
58 | } | 65 | } |
59 | #endif | 66 | #endif |
60 | 67 | ||
61 | #endif /* WITH_TLS */ | ||
62 | #endif /* _MAILUTILS_TLS_H */ | 68 | #endif /* _MAILUTILS_TLS_H */ |
63 | 69 | ... | ... |
... | @@ -23,8 +23,11 @@ noinst_LTLIBRARIES = libmuaux.la | ... | @@ -23,8 +23,11 @@ noinst_LTLIBRARIES = libmuaux.la |
23 | INCLUDES = @MU_COMMON_INCLUDES@ | 23 | INCLUDES = @MU_COMMON_INCLUDES@ |
24 | 24 | ||
25 | libmuaux_la_SOURCES = \ | 25 | libmuaux_la_SOURCES = \ |
26 | argpinit.c\ | ||
26 | daemon.c\ | 27 | daemon.c\ |
27 | mailcap.c\ | 28 | mailcap.c\ |
29 | muinit.h\ | ||
30 | muinit.c\ | ||
28 | mu_dbm.c | 31 | mu_dbm.c |
29 | 32 | ||
30 | EXTRA_DIST = utmp.c | 33 | EXTRA_DIST = utmp.c | ... | ... |
lib/argpinit.c
0 → 100644
1 | /* GNU Mailutils -- a suite of utilities for electronic mail | ||
2 | Copyright (C) 2007 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, write to the | ||
16 | Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | ||
17 | Boston, MA 02110-1301 USA */ | ||
18 | |||
19 | #ifdef HAVE_CONFIG_H | ||
20 | # include <config.h> | ||
21 | #endif | ||
22 | |||
23 | #include "muinit.h" | ||
24 | |||
25 | void | ||
26 | mu_argp_init (const char *vers, const char *bugaddr) | ||
27 | { | ||
28 | argp_program_version = vers ? vers : PACKAGE_STRING; | ||
29 | argp_program_bug_address = bugaddr ? bugaddr : "<" PACKAGE_BUGREPORT ">"; | ||
30 | } | ||
31 |
lib/muinit.c
0 → 100644
1 | /* GNU Mailutils -- a suite of utilities for electronic mail | ||
2 | Copyright (C) 2007 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, write to the | ||
16 | Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | ||
17 | Boston, MA 02110-1301 USA */ | ||
18 | |||
19 | #ifdef HAVE_CONFIG_H | ||
20 | # include <config.h> | ||
21 | #endif | ||
22 | |||
23 | #include "muinit.h" | ||
24 | |||
25 | int | ||
26 | mu_app_init (struct argp *myargp, const char **capa, | ||
27 | struct mu_cfg_param *cfg_param, | ||
28 | int argc, char **argv, int flags, int *pindex, void *data) | ||
29 | { | ||
30 | int rc, i; | ||
31 | struct argp *argp; | ||
32 | const struct argp argpnull = { 0 }; | ||
33 | |||
34 | mu_set_program_name (argv[0]); | ||
35 | mu_libargp_init (); | ||
36 | for (i = 0; capa[i]; i++) | ||
37 | mu_gocs_register_std (capa[i]); /*FIXME*/ | ||
38 | if (!myargp) | ||
39 | myargp = &argpnull; | ||
40 | argp = mu_argp_build (myargp); | ||
41 | rc = argp_parse (argp, argc, argv, flags, pindex, data); | ||
42 | mu_argp_done (argp); | ||
43 | if (rc) | ||
44 | return rc; | ||
45 | |||
46 | mu_libcfg_init (capa); | ||
47 | mu_parse_config_files (cfg_param); | ||
48 | |||
49 | mu_gocs_flush (); | ||
50 | |||
51 | return 0; | ||
52 | } |
lib/muinit.h
0 → 100644
1 | /* GNU Mailutils -- a suite of utilities for electronic mail | ||
2 | Copyright (C) 2007 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, write to the | ||
16 | Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | ||
17 | Boston, MA 02110-1301 USA */ | ||
18 | |||
19 | #include "cmdline.h" | ||
20 | #include "libcfg.h" | ||
21 | |||
22 | void mu_argp_init (const char *vers, const char *bugaddr); | ||
23 | int mu_app_init (struct argp *myargp, const char **capa, | ||
24 | struct mu_cfg_param *cfg_param, | ||
25 | int argc, char **argv, int flags, int *pindex, void *data); | ||
26 | |||
27 |
libargp/auth.c
0 → 100644
1 | /* GNU Mailutils -- a suite of utilities for electronic mail | ||
2 | Copyright (C) 2007 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, write to the | ||
16 | Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | ||
17 | Boston, MA 02110-1301 USA */ | ||
18 | |||
19 | #ifdef HAVE_CONFIG_H | ||
20 | # include <config.h> | ||
21 | #endif | ||
22 | |||
23 | #include "cmdline.h" | ||
24 | |||
25 | |||
26 | /* ************************************************************************* */ | ||
27 | /* Traditional configuration */ | ||
28 | /* ************************************************************************* */ | ||
29 | |||
30 | static error_t mu_auth_argp_parser (int key, char *arg, | ||
31 | struct argp_state *state); | ||
32 | |||
33 | /* Options used by programs that use extended authentication mechanisms. */ | ||
34 | static struct argp_option mu_auth_argp_option[] = { | ||
35 | { "authentication", OPT_AUTHENTICATION, N_("MODLIST"), OPTION_HIDDEN, | ||
36 | N_("Set the list of modules to be used for authentication"), 0 }, | ||
37 | { "authorization", OPT_AUTHORIZATION, N_("MODLIST"), OPTION_HIDDEN, | ||
38 | N_("Set list of modules to be used for authorization"), 0 }, | ||
39 | { "clear-authorization", OPT_CLEAR_AUTHORIZATION, NULL, OPTION_HIDDEN, | ||
40 | N_("Clear the list of authorization modules"), 0 }, | ||
41 | { "clear-authentication", OPT_CLEAR_AUTHENTICATION, NULL, OPTION_HIDDEN, | ||
42 | N_("Clear the list of authentication modules"), 0 }, | ||
43 | { NULL, 0, NULL, 0, NULL, 0 } | ||
44 | }; | ||
45 | |||
46 | static struct argp mu_auth_argp = { | ||
47 | mu_auth_argp_option, | ||
48 | mu_auth_argp_parser, | ||
49 | }; | ||
50 | |||
51 | static struct argp_child mu_auth_argp_child = { | ||
52 | &mu_auth_argp, | ||
53 | 0, | ||
54 | NULL, | ||
55 | 0 | ||
56 | }; | ||
57 | |||
58 | static error_t | ||
59 | mu_auth_argp_parser (int key, char *arg, struct argp_state *state) | ||
60 | { | ||
61 | switch (key) | ||
62 | { | ||
63 | case ARGP_KEY_FINI: | ||
64 | mu_auth_finish_setup (); | ||
65 | break; | ||
66 | |||
67 | /* authentication */ | ||
68 | case OPT_AUTHORIZATION: | ||
69 | mu_authorization_add_module_list (arg); | ||
70 | break; | ||
71 | |||
72 | case OPT_AUTHENTICATION: | ||
73 | mu_authentication_add_module_list (arg); | ||
74 | break; | ||
75 | |||
76 | case OPT_CLEAR_AUTHENTICATION: | ||
77 | mu_authentication_clear_list (); | ||
78 | break; | ||
79 | |||
80 | case OPT_CLEAR_AUTHORIZATION: | ||
81 | mu_authorization_clear_list (); | ||
82 | break; | ||
83 | |||
84 | default: | ||
85 | return ARGP_ERR_UNKNOWN; | ||
86 | } | ||
87 | return 0; | ||
88 | } | ||
89 | |||
90 | struct mu_cmdline_capa mu_auth_cmdline = { | ||
91 | "auth", &mu_auth_argp_child | ||
92 | }; |
libargp/cmdline.h
0 → 100644
1 | /* GNU Mailutils -- a suite of utilities for electronic mail | ||
2 | Copyright (C) 1999, 2000, 2001, 2004, 2005, | ||
3 | 2007 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, write to the | ||
17 | Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | ||
18 | Boston, MA 02110-1301 USA */ | ||
19 | |||
20 | #ifndef _MAILUTILS_CMDLINE_H | ||
21 | #define _MAILUTILS_CMDLINE_H | ||
22 | |||
23 | #ifdef HAVE_CONFIG_H | ||
24 | # include <config.h> | ||
25 | #endif | ||
26 | #include "mailutils/types.h" | ||
27 | #include "mailutils/gocs.h" | ||
28 | #include "mailutils/nls.h" | ||
29 | #include "mailutils/error.h" | ||
30 | #include "mailutils/errno.h" | ||
31 | #include "argp.h" | ||
32 | #include <errno.h> /* May declare program_invocation_name */ | ||
33 | |||
34 | #ifdef __cplusplus | ||
35 | extern "C" { | ||
36 | #endif | ||
37 | |||
38 | enum { | ||
39 | OPT_LOG_FACILITY = 256, | ||
40 | OPT_LOCK_FLAGS, | ||
41 | OPT_LOCK_RETRY_COUNT, | ||
42 | OPT_LOCK_RETRY_TIMEOUT, | ||
43 | OPT_LOCK_EXPIRE_TIMEOUT, | ||
44 | OPT_LOCK_EXTERNAL_PROGRAM, | ||
45 | OPT_SHOW_OPTIONS, | ||
46 | OPT_LICENSE, | ||
47 | OPT_MAILBOX_TYPE, | ||
48 | OPT_CRAM_PASSWD, | ||
49 | OPT_PAM_SERVICE, | ||
50 | OPT_AUTH_REQUEST, | ||
51 | OPT_GETPWNAM_REQUEST, | ||
52 | OPT_GETPWUID_REQUEST, | ||
53 | OPT_RADIUS_DIR, | ||
54 | OPT_SQL_INTERFACE, | ||
55 | OPT_SQL_GETPWNAM, | ||
56 | OPT_SQL_GETPWUID, | ||
57 | OPT_SQL_GETPASS, | ||
58 | OPT_SQL_HOST, | ||
59 | OPT_SQL_USER, | ||
60 | OPT_SQL_PASSWD, | ||
61 | OPT_SQL_DB, | ||
62 | OPT_SQL_PORT, | ||
63 | OPT_SQL_MU_PASSWORD_TYPE, | ||
64 | OPT_SQL_FIELD_MAP, | ||
65 | OPT_TLS, | ||
66 | OPT_SSL_CERT, | ||
67 | OPT_SSL_KEY, | ||
68 | OPT_SSL_CAFILE, | ||
69 | OPT_PWDDIR, | ||
70 | OPT_AUTHORIZATION, | ||
71 | OPT_AUTHENTICATION, | ||
72 | OPT_CLEAR_AUTHORIZATION, | ||
73 | OPT_CLEAR_AUTHENTICATION, | ||
74 | OPT_NO_USER_RCFILE, | ||
75 | OPT_NO_SITE_RCFILE, | ||
76 | OPT_RCFILE, | ||
77 | OPT_CLEAR_INCLUDE_PATH, | ||
78 | OPT_CLEAR_LIBRARY_PATH | ||
79 | }; | ||
80 | |||
81 | struct mu_cmdline_capa | ||
82 | { | ||
83 | char *name; | ||
84 | struct argp_child *child; | ||
85 | }; | ||
86 | |||
87 | extern struct mu_cmdline_capa mu_common_cmdline; | ||
88 | extern struct mu_cmdline_capa mu_logging_cmdline; | ||
89 | extern struct mu_cmdline_capa mu_license_cmdline; | ||
90 | extern struct mu_cmdline_capa mu_mailbox_cmdline; | ||
91 | extern struct mu_cmdline_capa mu_locking_cmdline; | ||
92 | extern struct mu_cmdline_capa mu_address_cmdline; | ||
93 | extern struct mu_cmdline_capa mu_mailer_cmdline; | ||
94 | extern struct mu_cmdline_capa mu_daemon_cmdline; | ||
95 | extern struct mu_cmdline_capa mu_sieve_cmdline; | ||
96 | |||
97 | extern struct mu_cmdline_capa mu_pam_cmdline; | ||
98 | extern struct mu_cmdline_capa mu_gsasl_cmdline; | ||
99 | extern struct mu_cmdline_capa mu_tls_cmdline; | ||
100 | extern struct mu_cmdline_capa mu_radius_cmdline; | ||
101 | extern struct mu_cmdline_capa mu_sql_cmdline; | ||
102 | extern struct mu_cmdline_capa mu_virtdomain_cmdline; | ||
103 | extern struct mu_cmdline_capa mu_auth_cmdline; | ||
104 | |||
105 | extern char *mu_license_text; | ||
106 | |||
107 | extern void mu_libargp_init (void); | ||
108 | |||
109 | extern struct argp *mu_argp_build (const struct argp *argp); | ||
110 | extern void mu_argp_done (struct argp *argp); | ||
111 | |||
112 | extern int mu_register_argp_capa (const char *name, struct argp_child *child); | ||
113 | |||
114 | extern void mu_print_options (void); | ||
115 | extern const char *mu_check_option (char *name); | ||
116 | |||
117 | #ifdef __cplusplus | ||
118 | } | ||
119 | #endif | ||
120 | |||
121 | #endif | ||
122 |
libargp/common.c
0 → 100644
1 | /* GNU Mailutils -- a suite of utilities for electronic mail | ||
2 | Copyright (C) 2007 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, write to the | ||
16 | Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | ||
17 | Boston, MA 02110-1301 USA */ | ||
18 | |||
19 | #ifdef HAVE_CONFIG_H | ||
20 | # include <config.h> | ||
21 | #endif | ||
22 | |||
23 | #include "cmdline.h" | ||
24 | #include <string.h> | ||
25 | #include <mailutils/syslog.h> | ||
26 | #include <mailutils/daemon.h> | ||
27 | |||
28 | static struct mu_gocs_daemon daemon_settings; | ||
29 | static struct mu_gocs_locking locking_settings; | ||
30 | static struct mu_gocs_logging logging_settings; | ||
31 | static struct mu_gocs_mailbox mailbox_settings; | ||
32 | static struct mu_gocs_source_email source_email_settings; | ||
33 | static struct mu_gocs_mailer mailer_settings; | ||
34 | |||
35 | |||
36 | void | ||
37 | assign_string (char **pstr, char *val) | ||
38 | { | ||
39 | if (!val) | ||
40 | { | ||
41 | if (*pstr) | ||
42 | { | ||
43 | free (*pstr); | ||
44 | *pstr = NULL; | ||
45 | } | ||
46 | } | ||
47 | else | ||
48 | { | ||
49 | size_t size = strlen (val); | ||
50 | char *p = realloc (*pstr, size + 1); | ||
51 | if (!p) | ||
52 | { | ||
53 | mu_error ("%s", mu_strerror (ENOMEM)); | ||
54 | exit (1); | ||
55 | } | ||
56 | strcpy (p, val); | ||
57 | *pstr = p; | ||
58 | } | ||
59 | } | ||
60 | |||
61 | |||
62 | /* ************************************************************************* */ | ||
63 | /* Common */ | ||
64 | /* ************************************************************************* */ | ||
65 | |||
66 | static struct argp_option mu_common_argp_options[] = | ||
67 | { | ||
68 | { NULL, 0, NULL, 0, N_("Common options"), 0}, | ||
69 | { "show-config-options", OPT_SHOW_OPTIONS, NULL, OPTION_HIDDEN, | ||
70 | N_("Show compilation options"), 0 }, | ||
71 | { "no-user-rcfile", OPT_NO_USER_RCFILE, NULL, 0, | ||
72 | N_("Do not load user configuration file"), 0 }, | ||
73 | { "no-site-rcfile", OPT_NO_SITE_RCFILE, NULL, 0, | ||
74 | N_("Do not load site configuration file"), 0 }, | ||
75 | { "rcfile", OPT_RCFILE, N_("FILE"), 0, | ||
76 | N_("Load this configuration file"), 0, }, | ||
77 | { NULL, 0, NULL, 0, NULL, 0 } | ||
78 | }; | ||
79 | |||
80 | static error_t | ||
81 | mu_common_argp_parser (int key, char *arg, struct argp_state *state) | ||
82 | { | ||
83 | switch (key) | ||
84 | { | ||
85 | case OPT_SHOW_OPTIONS: | ||
86 | mu_print_options (); | ||
87 | exit (0); | ||
88 | |||
89 | case OPT_NO_USER_RCFILE: | ||
90 | mu_load_user_rcfile = 0; | ||
91 | break; | ||
92 | |||
93 | case OPT_NO_SITE_RCFILE: | ||
94 | mu_load_site_rcfile = 0; | ||
95 | break; | ||
96 | |||
97 | case OPT_RCFILE: | ||
98 | mu_load_rcfile = arg; | ||
99 | break; | ||
100 | |||
101 | default: | ||
102 | return ARGP_ERR_UNKNOWN; | ||
103 | } | ||
104 | return 0; | ||
105 | } | ||
106 | |||
107 | struct argp mu_common_argp = { | ||
108 | mu_common_argp_options, | ||
109 | mu_common_argp_parser, | ||
110 | }; | ||
111 | |||
112 | struct argp_child mu_common_argp_child = { | ||
113 | &mu_common_argp, | ||
114 | 0, | ||
115 | NULL, | ||
116 | 0, | ||
117 | }; | ||
118 | |||
119 | struct mu_cmdline_capa mu_common_cmdline = { | ||
120 | "common", &mu_common_argp_child | ||
121 | }; | ||
122 | |||
123 | |||
124 | /* ************************************************************************* */ | ||
125 | /* Logging */ | ||
126 | /* ************************************************************************* */ | ||
127 | |||
128 | static struct argp_option mu_logging_argp_option[] = { | ||
129 | {"log-facility", OPT_LOG_FACILITY, N_("FACILITY"), 0, | ||
130 | N_("Output logs to syslog FACILITY"), 0}, | ||
131 | { NULL, 0, NULL, 0, NULL, 0 } | ||
132 | }; | ||
133 | |||
134 | static error_t | ||
135 | mu_logging_argp_parser (int key, char *arg, struct argp_state *state) | ||
136 | { | ||
137 | switch (key) | ||
138 | { | ||
139 | /* log */ | ||
140 | case OPT_LOG_FACILITY: | ||
141 | if (mu_string_to_syslog_facility (arg, &logging_settings.facility)) | ||
142 | mu_error (_("Unknown syslog facility `%s'"), arg); | ||
143 | /* FIXME: error reporting */ | ||
144 | break; | ||
145 | |||
146 | case ARGP_KEY_FINI: | ||
147 | mu_gocs_store ("logging", &logging_settings); | ||
148 | break; | ||
149 | |||
150 | default: | ||
151 | return ARGP_ERR_UNKNOWN; | ||
152 | } | ||
153 | return 0; | ||
154 | } | ||
155 | |||
156 | struct argp mu_logging_argp = { | ||
157 | mu_logging_argp_option, | ||
158 | mu_logging_argp_parser, | ||
159 | }; | ||
160 | |||
161 | struct argp_child mu_logging_argp_child = { | ||
162 | &mu_logging_argp, | ||
163 | 0, | ||
164 | NULL, | ||
165 | 0 | ||
166 | }; | ||
167 | |||
168 | struct mu_cmdline_capa mu_logging_cmdline = { | ||
169 | "logging", &mu_logging_argp_child | ||
170 | }; | ||
171 | |||
172 | |||
173 | /* ************************************************************************* */ | ||
174 | /* License */ | ||
175 | /* ************************************************************************* */ | ||
176 | |||
177 | /* Option to print the license. */ | ||
178 | static struct argp_option mu_license_argp_option[] = { | ||
179 | { "license", OPT_LICENSE, NULL, 0, N_("Print license and exit"), -2 }, | ||
180 | { NULL, 0, NULL, 0, NULL, 0 } | ||
181 | }; | ||
182 | |||
183 | static error_t | ||
184 | mu_license_argp_parser (int key, char *arg, struct argp_state *state) | ||
185 | { | ||
186 | switch (key) | ||
187 | { | ||
188 | case OPT_LICENSE: | ||
189 | printf (_("License for %s:\n\n"), argp_program_version); | ||
190 | printf ("%s", mu_license_text); | ||
191 | exit (0); | ||
192 | |||
193 | default: | ||
194 | return ARGP_ERR_UNKNOWN; | ||
195 | } | ||
196 | return 0; | ||
197 | } | ||
198 | |||
199 | struct argp mu_license_argp = { | ||
200 | mu_license_argp_option, | ||
201 | mu_license_argp_parser, | ||
202 | }; | ||
203 | |||
204 | struct argp_child mu_license_argp_child = { | ||
205 | &mu_license_argp, | ||
206 | 0, | ||
207 | NULL, | ||
208 | 0 | ||
209 | }; | ||
210 | |||
211 | struct mu_cmdline_capa mu_license_cmdline = { | ||
212 | "license", &mu_license_argp_child | ||
213 | }; | ||
214 | |||
215 | |||
216 | /* ************************************************************************* */ | ||
217 | /* Mailbox */ | ||
218 | /* ************************************************************************* */ | ||
219 | |||
220 | /* Options used by programs that access mailboxes. */ | ||
221 | static struct argp_option mu_mailbox_argp_option[] = { | ||
222 | { "mail-spool", 'm', N_("URL"), OPTION_HIDDEN, | ||
223 | N_("Use specified URL as a mailspool directory"), 0 }, | ||
224 | { "mailbox-type", OPT_MAILBOX_TYPE, N_("PROTO"), OPTION_HIDDEN, | ||
225 | N_("Default mailbox type to use"), 0 }, | ||
226 | { NULL } | ||
227 | }; | ||
228 | |||
229 | static error_t | ||
230 | mu_mailbox_argp_parser (int key, char *arg, struct argp_state *state) | ||
231 | { | ||
232 | switch (key) | ||
233 | { | ||
234 | /* mailbox */ | ||
235 | case 'm': | ||
236 | assign_string (&mailbox_settings.mail_spool, arg); | ||
237 | break; | ||
238 | |||
239 | case OPT_MAILBOX_TYPE: | ||
240 | assign_string (&mailbox_settings.mailbox_type, arg); | ||
241 | break; | ||
242 | |||
243 | case ARGP_KEY_FINI: | ||
244 | mu_gocs_store ("mailbox", &mailbox_settings); | ||
245 | break; | ||
246 | |||
247 | default: | ||
248 | return ARGP_ERR_UNKNOWN; | ||
249 | } | ||
250 | return 0; | ||
251 | } | ||
252 | |||
253 | struct argp mu_mailbox_argp = { | ||
254 | mu_mailbox_argp_option, | ||
255 | mu_mailbox_argp_parser, | ||
256 | }; | ||
257 | |||
258 | struct argp_child mu_mailbox_argp_child = { | ||
259 | &mu_mailbox_argp, | ||
260 | 0, | ||
261 | NULL, | ||
262 | 0 | ||
263 | }; | ||
264 | |||
265 | struct mu_cmdline_capa mu_mailbox_cmdline = { | ||
266 | "mailbox", &mu_mailbox_argp_child | ||
267 | }; | ||
268 | |||
269 | |||
270 | /* ************************************************************************* */ | ||
271 | /* Locking */ | ||
272 | /* ************************************************************************* */ | ||
273 | |||
274 | /* Options used by programs that access mailboxes. */ | ||
275 | static struct argp_option mu_locking_argp_option[] = { | ||
276 | {"lock-flags", OPT_LOCK_FLAGS, N_("FLAGS"), OPTION_HIDDEN, | ||
277 | N_("Default locker flags (E=external, R=retry, T=time, P=pid)"), 0}, | ||
278 | {"lock-retry-timeout", OPT_LOCK_RETRY_TIMEOUT, N_("SECONDS"), OPTION_HIDDEN, | ||
279 | N_("Set timeout for acquiring the lockfile") }, | ||
280 | {"lock-retry-count", OPT_LOCK_RETRY_COUNT, N_("NUMBER"), OPTION_HIDDEN, | ||
281 | N_("Set the maximum number of times to retry acquiring the lockfile") }, | ||
282 | {"lock-expire-timeout", OPT_LOCK_EXPIRE_TIMEOUT, N_("SECONDS"), | ||
283 | OPTION_HIDDEN, | ||
284 | N_("Number of seconds after which the lock expires"), }, | ||
285 | {"external-locker", OPT_LOCK_EXTERNAL_PROGRAM, N_("PATH"), OPTION_HIDDEN, | ||
286 | N_("Set full path to the external locker program") }, | ||
287 | { NULL, 0, NULL, 0, NULL, 0 } | ||
288 | }; | ||
289 | |||
290 | static error_t | ||
291 | mu_locking_argp_parser (int key, char *arg, struct argp_state *state) | ||
292 | { | ||
293 | switch (key) | ||
294 | { | ||
295 | case OPT_LOCK_FLAGS: | ||
296 | assign_string (&locking_settings.lock_flags, arg); | ||
297 | break; | ||
298 | |||
299 | case OPT_LOCK_RETRY_COUNT: | ||
300 | locking_settings.lock_retry_count = strtoul (arg, NULL, 0); | ||
301 | break; | ||
302 | |||
303 | case OPT_LOCK_RETRY_TIMEOUT: | ||
304 | locking_settings.lock_retry_timeout = strtoul (arg, NULL, 0); | ||
305 | break; | ||
306 | |||
307 | case OPT_LOCK_EXPIRE_TIMEOUT: | ||
308 | locking_settings.lock_expire_timeout = strtoul (arg, NULL, 0); | ||
309 | break; | ||
310 | |||
311 | case OPT_LOCK_EXTERNAL_PROGRAM: | ||
312 | assign_string (&locking_settings.external_locker, arg); | ||
313 | break; | ||
314 | |||
315 | case ARGP_KEY_FINI: | ||
316 | mu_gocs_store ("locking", &locking_settings); | ||
317 | break; | ||
318 | |||
319 | default: | ||
320 | return ARGP_ERR_UNKNOWN; | ||
321 | } | ||
322 | return 0; | ||
323 | } | ||
324 | |||
325 | struct argp mu_locking_argp = { | ||
326 | mu_locking_argp_option, | ||
327 | mu_locking_argp_parser, | ||
328 | }; | ||
329 | |||
330 | struct argp_child mu_locking_argp_child = { | ||
331 | &mu_locking_argp, | ||
332 | 0, | ||
333 | NULL, | ||
334 | 0 | ||
335 | }; | ||
336 | |||
337 | struct mu_cmdline_capa mu_locking_cmdline = { | ||
338 | "locking", &mu_locking_argp_child | ||
339 | }; | ||
340 | |||
341 | |||
342 | /* ************************************************************************* */ | ||
343 | /* Address */ | ||
344 | /* ************************************************************************* */ | ||
345 | |||
346 | /* Options used by programs that do address mapping. */ | ||
347 | static struct argp_option mu_address_argp_option[] = { | ||
348 | {"email-addr", 'E', N_("EMAIL"), OPTION_HIDDEN, | ||
349 | N_("Set current user's email address (default is loginname@defaultdomain)"), 0}, | ||
350 | {"email-domain", 'D', N_("DOMAIN"), OPTION_HIDDEN, | ||
351 | N_("Set domain for unqualified user names (default is this host)"), 0}, | ||
352 | { NULL, 0, NULL, 0, NULL, 0 } | ||
353 | }; | ||
354 | |||
355 | static error_t | ||
356 | mu_address_argp_parser (int key, char *arg, struct argp_state *state) | ||
357 | { | ||
358 | switch (key) | ||
359 | { | ||
360 | case 'E': | ||
361 | assign_string (&source_email_settings.address, arg); | ||
362 | break; | ||
363 | |||
364 | case 'D': | ||
365 | assign_string (&source_email_settings.domain, arg); | ||
366 | break; | ||
367 | |||
368 | case ARGP_KEY_FINI: | ||
369 | mu_gocs_store ("address", &source_email_settings); | ||
370 | break; | ||
371 | |||
372 | default: | ||
373 | return ARGP_ERR_UNKNOWN; | ||
374 | } | ||
375 | return 0; | ||
376 | } | ||
377 | |||
378 | struct argp mu_address_argp = { | ||
379 | mu_address_argp_option, | ||
380 | mu_address_argp_parser, | ||
381 | }; | ||
382 | |||
383 | struct argp_child mu_address_argp_child = { | ||
384 | &mu_address_argp, | ||
385 | 0, | ||
386 | NULL, | ||
387 | 0 | ||
388 | }; | ||
389 | |||
390 | struct mu_cmdline_capa mu_address_cmdline = { | ||
391 | "address", &mu_address_argp_child | ||
392 | }; | ||
393 | |||
394 | |||
395 | /* ************************************************************************* */ | ||
396 | /* Mailer */ | ||
397 | /* ************************************************************************* */ | ||
398 | |||
399 | /* Options used by programs that send mail. */ | ||
400 | static struct argp_option mu_mailer_argp_option[] = { | ||
401 | {"mailer", 'M', N_("MAILER"), 0, | ||
402 | N_("Use specified URL as the default mailer"), 0}, | ||
403 | { NULL, 0, NULL, 0, NULL, 0 } | ||
404 | }; | ||
405 | |||
406 | static error_t | ||
407 | mu_mailer_argp_parser (int key, char *arg, struct argp_state *state) | ||
408 | { | ||
409 | switch (key) | ||
410 | { | ||
411 | /* mailer */ | ||
412 | case 'M': | ||
413 | assign_string (&mailer_settings.mailer, arg); | ||
414 | break; | ||
415 | |||
416 | case ARGP_KEY_FINI: | ||
417 | mu_gocs_store ("mailer", &mailer_settings); | ||
418 | break; | ||
419 | |||
420 | default: | ||
421 | return ARGP_ERR_UNKNOWN; | ||
422 | } | ||
423 | return 0; | ||
424 | } | ||
425 | |||
426 | struct argp mu_mailer_argp = { | ||
427 | mu_mailer_argp_option, | ||
428 | mu_mailer_argp_parser, | ||
429 | }; | ||
430 | |||
431 | struct argp_child mu_mailer_argp_child = { | ||
432 | &mu_mailer_argp, | ||
433 | 0, | ||
434 | NULL, | ||
435 | 0 | ||
436 | }; | ||
437 | |||
438 | struct mu_cmdline_capa mu_mailer_cmdline = { | ||
439 | "mailer", &mu_mailer_argp_child | ||
440 | }; | ||
441 | |||
442 | |||
443 | /* ************************************************************************* */ | ||
444 | /* Daemon */ | ||
445 | /* ************************************************************************* */ | ||
446 | |||
447 | /* Options used by programs that become daemons. */ | ||
448 | static struct argp_option mu_daemon_argp_option[] = { | ||
449 | {"daemon", 'd', N_("NUMBER"), OPTION_ARG_OPTIONAL, | ||
450 | N_("Runs in daemon mode with a maximum of NUMBER children")}, | ||
451 | {"inetd", 'i', 0, 0, | ||
452 | N_("Run in inetd mode"), 0}, | ||
453 | {"port", 'p', N_("PORT"), 0, | ||
454 | N_("Listen on specified port number"), 0}, | ||
455 | {"timeout", 't', N_("NUMBER"), OPTION_HIDDEN, | ||
456 | N_("Set idle timeout value to NUMBER seconds"), 0}, | ||
457 | {"transcript", 'x', NULL, 0, | ||
458 | N_("Output session transcript via syslog"), 0}, | ||
459 | {"pidfile", 'P', N_("FILE"), OPTION_HIDDEN, | ||
460 | N_("Set PID file"), 0}, | ||
461 | { NULL, 0, NULL, 0, NULL, 0 } | ||
462 | }; | ||
463 | |||
464 | static error_t | ||
465 | mu_daemon_argp_parser (int key, char *arg, struct argp_state *state) | ||
466 | { | ||
467 | switch (key) | ||
468 | { | ||
469 | case 'd': | ||
470 | daemon_settings.mode = MODE_DAEMON; | ||
471 | if (arg) | ||
472 | daemon_settings.maxchildren = strtoul (arg, NULL, 10); | ||
473 | break; | ||
474 | |||
475 | case 'i': | ||
476 | daemon_settings.mode = MODE_INTERACTIVE; | ||
477 | break; | ||
478 | |||
479 | case 'p': | ||
480 | daemon_settings.mode = MODE_DAEMON; | ||
481 | daemon_settings.port = strtoul (arg, NULL, 10); /*FIXME: overflow */ | ||
482 | break; | ||
483 | |||
484 | case 'P': | ||
485 | assign_string (&daemon_settings.pidfile, arg); | ||
486 | break; | ||
487 | |||
488 | case 't': | ||
489 | daemon_settings.timeout = strtoul (arg, NULL, 10); | ||
490 | break; | ||
491 | |||
492 | case 'x': | ||
493 | daemon_settings.transcript = 1; | ||
494 | break; | ||
495 | |||
496 | case ARGP_KEY_FINI: | ||
497 | mu_gocs_store ("daemon", &daemon_settings); | ||
498 | break; | ||
499 | |||
500 | default: | ||
501 | return ARGP_ERR_UNKNOWN; | ||
502 | } | ||
503 | return 0; | ||
504 | } | ||
505 | |||
506 | struct argp mu_daemon_argp = { | ||
507 | mu_daemon_argp_option, | ||
508 | mu_daemon_argp_parser, | ||
509 | }; | ||
510 | |||
511 | struct argp_child mu_daemon_argp_child = { | ||
512 | &mu_daemon_argp, | ||
513 | 0, | ||
514 | N_("Daemon configuration options"), | ||
515 | 0 | ||
516 | }; | ||
517 | |||
518 | struct mu_cmdline_capa mu_daemon_cmdline = { | ||
519 | "daemon", &mu_daemon_argp_child | ||
520 | }; | ||
521 |
libargp/gsasl.c
0 → 100644
1 | /* GNU Mailutils -- a suite of utilities for electronic mail | ||
2 | Copyright (C) 2007 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, write to the | ||
16 | Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | ||
17 | Boston, MA 02110-1301 USA */ | ||
18 | |||
19 | #ifdef HAVE_CONFIG_H | ||
20 | # include <config.h> | ||
21 | #endif | ||
22 | |||
23 | #include "cmdline.h" | ||
24 | #include <mailutils/gsasl.h> | ||
25 | |||
26 | static struct argp_option _gsasl_argp_options[] = { | ||
27 | {"cram-passwd", OPT_CRAM_PASSWD, N_("FILE"), OPTION_HIDDEN, | ||
28 | N_("Specify password file for CRAM-MD5 authentication"), 0}, | ||
29 | { NULL, 0, NULL, 0, NULL, 0 } | ||
30 | }; | ||
31 | |||
32 | static struct mu_gsasl_module_data gsasl_data = { | ||
33 | SITE_CRAM_MD5_PWD | ||
34 | }; | ||
35 | |||
36 | static error_t | ||
37 | _gsasl_argp_parser (int key, char *arg, struct argp_state *state) | ||
38 | { | ||
39 | switch (key) | ||
40 | { | ||
41 | case OPT_CRAM_PASSWD: | ||
42 | gsasl_data.cram_md5_pwd = arg; | ||
43 | break; | ||
44 | |||
45 | case ARGP_KEY_FINI: | ||
46 | mu_gocs_store ("gsasl", &gsasl_data); | ||
47 | break; | ||
48 | |||
49 | default: | ||
50 | return ARGP_ERR_UNKNOWN; | ||
51 | } | ||
52 | return 0; | ||
53 | } | ||
54 | |||
55 | static struct argp _gsasl_argp = { | ||
56 | _gsasl_argp_options, | ||
57 | _gsasl_argp_parser | ||
58 | }; | ||
59 | |||
60 | struct argp_child mu_gsasl_argp_child = { | ||
61 | &_gsasl_argp, | ||
62 | 0, | ||
63 | NULL, | ||
64 | 0 | ||
65 | }; | ||
66 | |||
67 | struct mu_cmdline_capa mu_gsasl_cmdline = { | ||
68 | "gsasl", &mu_gsasl_argp_child | ||
69 | }; | ||
70 | |||
71 |
libargp/mu_argp.c
0 → 100644
1 | /* GNU Mailutils -- a suite of utilities for electronic mail | ||
2 | Copyright (C) 1999, 2001, 2002, 2003, 2004, 2005, 2006, | ||
3 | 2007 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, write to the | ||
17 | Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | ||
18 | Boston, MA 02110-1301 USA */ | ||
19 | |||
20 | #ifdef HAVE_CONFIG_H | ||
21 | # include <config.h> | ||
22 | #endif | ||
23 | |||
24 | #include <getline.h> | ||
25 | #include <pwd.h> | ||
26 | #include <stdio.h> | ||
27 | #include <stdlib.h> | ||
28 | #include <string.h> | ||
29 | #include <syslog.h> | ||
30 | #include <unistd.h> | ||
31 | |||
32 | #include <sys/types.h> | ||
33 | #include <sys/stat.h> | ||
34 | |||
35 | #include "cmdline.h" | ||
36 | |||
37 | char *mu_license_text = | ||
38 | N_(" GNU Mailutils is free software; you can redistribute it and/or modify\n" | ||
39 | " it under the terms of the GNU General Public License as published by\n" | ||
40 | " the Free Software Foundation; either version 3 of the License, or\n" | ||
41 | " (at your option) any later version.\n" | ||
42 | "\n" | ||
43 | " GNU Mailutils is distributed in the hope that it will be useful,\n" | ||
44 | " but WITHOUT ANY WARRANTY; without even the implied warranty of\n" | ||
45 | " MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n" | ||
46 | " GNU General Public License for more details.\n" | ||
47 | "\n" | ||
48 | " You should have received a copy of the GNU General Public License along\n" | ||
49 | " with GNU Mailutils; if not, write to the Free Software Foundation,\n" | ||
50 | " Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA\n" | ||
51 | "\n" | ||
52 | "\n" | ||
53 | ); | ||
54 | |||
55 | static char *mu_conf_option[] = { | ||
56 | "VERSION=" VERSION, | ||
57 | #ifdef USE_LIBPAM | ||
58 | "USE_LIBPAM", | ||
59 | #endif | ||
60 | #ifdef HAVE_LIBLTDL | ||
61 | "HAVE_LIBLTDL", | ||
62 | #endif | ||
63 | #ifdef WITH_BDB2 | ||
64 | "WITH_BDB2", | ||
65 | #endif | ||
66 | #ifdef WITH_NDBM | ||
67 | "WITH_NDBM", | ||
68 | #endif | ||
69 | #ifdef WITH_OLD_DBM | ||
70 | "WITH_OLD_DBM", | ||
71 | #endif | ||
72 | #ifdef WITH_GDBM | ||
73 | "WITH_GDBM", | ||
74 | #endif | ||
75 | #ifdef WITH_GNUTLS | ||
76 | "WITH_GNUTLS", | ||
77 | #endif | ||
78 | #ifdef WITH_GSASL | ||
79 | "WITH_GSASL", | ||
80 | #endif | ||
81 | #ifdef WITH_GSSAPI | ||
82 | "WITH_GSSAPI", | ||
83 | #endif | ||
84 | #ifdef WITH_GUILE | ||
85 | "WITH_GUILE", | ||
86 | #endif | ||
87 | #ifdef WITH_PTHREAD | ||
88 | "WITH_PTHREAD", | ||
89 | #endif | ||
90 | #ifdef WITH_READLINE | ||
91 | "WITH_READLINE", | ||
92 | #endif | ||
93 | #ifdef HAVE_MYSQL | ||
94 | "HAVE_MYSQL", | ||
95 | #endif | ||
96 | #ifdef HAVE_PGSQL | ||
97 | "HAVE_PGSQL", | ||
98 | #endif | ||
99 | #ifdef ENABLE_VIRTUAL_DOMAINS | ||
100 | "ENABLE_VIRTUAL_DOMAINS", | ||
101 | #endif | ||
102 | #ifdef ENABLE_IMAP | ||
103 | "ENABLE_IMAP", | ||
104 | #endif | ||
105 | #ifdef ENABLE_POP | ||
106 | "ENABLE_POP", | ||
107 | #endif | ||
108 | #ifdef ENABLE_MH | ||
109 | "ENABLE_MH", | ||
110 | #endif | ||
111 | #ifdef ENABLE_MAILDIR | ||
112 | "ENABLE_MAILDIR", | ||
113 | #endif | ||
114 | #ifdef ENABLE_SMTP | ||
115 | "ENABLE_SMTP", | ||
116 | #endif | ||
117 | #ifdef ENABLE_SENDMAIL | ||
118 | "ENABLE_SENDMAIL", | ||
119 | #endif | ||
120 | #ifdef ENABLE_NNTP | ||
121 | "ENABLE_NNTP", | ||
122 | #endif | ||
123 | #ifdef ENABLE_RADIUS | ||
124 | "ENABLE_RADIUS", | ||
125 | #endif | ||
126 | #ifdef WITH_INCLUDED_LIBINTL | ||
127 | "WITH_INCLUDED_LIBINTL", | ||
128 | #endif | ||
129 | NULL | ||
130 | }; | ||
131 | |||
132 | void | ||
133 | mu_print_options () | ||
134 | { | ||
135 | int i; | ||
136 | |||
137 | for (i = 0; mu_conf_option[i]; i++) | ||
138 | printf ("%s\n", mu_conf_option[i]); | ||
139 | } | ||
140 | |||
141 | const char * | ||
142 | mu_check_option (char *name) | ||
143 | { | ||
144 | int i; | ||
145 | |||
146 | for (i = 0; mu_conf_option[i]; i++) | ||
147 | { | ||
148 | int len; | ||
149 | char *q, *p = strchr (mu_conf_option[i], '='); | ||
150 | if (p) | ||
151 | len = p - mu_conf_option[i]; | ||
152 | else | ||
153 | len = strlen (mu_conf_option[i]); | ||
154 | |||
155 | if (strncasecmp (mu_conf_option[i], name, len) == 0) | ||
156 | return mu_conf_option[i]; | ||
157 | else if ((q = strchr (mu_conf_option[i], '_')) != NULL | ||
158 | && strncasecmp (q + 1, name, | ||
159 | len - (q - mu_conf_option[i]) - 1) == 0) | ||
160 | return mu_conf_option[i]; | ||
161 | } | ||
162 | return NULL; | ||
163 | } | ||
164 | |||
165 | |||
166 | /* ************************************************************************* */ | ||
167 | /* Capability array and auxiliary functions. */ | ||
168 | /* ************************************************************************* */ | ||
169 | |||
170 | #define MU_MAX_CAPA 24 | ||
171 | |||
172 | struct argp_capa { | ||
173 | char *capability; | ||
174 | struct argp_child *child; | ||
175 | } mu_argp_capa[MU_MAX_CAPA] = { | ||
176 | {NULL,} | ||
177 | }; | ||
178 | |||
179 | int | ||
180 | mu_register_argp_capa (const char *name, struct argp_child *child) | ||
181 | { | ||
182 | int i; | ||
183 | |||
184 | for (i = 0; i < MU_MAX_CAPA; i++) | ||
185 | if (mu_argp_capa[i].capability == NULL) | ||
186 | { | ||
187 | mu_argp_capa[i].capability = strdup (name); | ||
188 | mu_argp_capa[i].child = child; | ||
189 | return 0; | ||
190 | } | ||
191 | return 1; | ||
192 | } | ||
193 | |||
194 | static struct argp_capa * | ||
195 | find_capa (const char *name) | ||
196 | { | ||
197 | int i; | ||
198 | for (i = 0; mu_argp_capa[i].capability; i++) | ||
199 | if (strcmp (mu_argp_capa[i].capability, name) == 0) | ||
200 | return &mu_argp_capa[i]; | ||
201 | return NULL; | ||
202 | } | ||
203 | |||
204 | static struct argp * | ||
205 | mu_build_argp (const struct argp *template, const char *capa[]) | ||
206 | { | ||
207 | int n; | ||
208 | int nchild; | ||
209 | struct argp_child *ap; | ||
210 | const struct argp_option *opt; | ||
211 | struct argp *argp; | ||
212 | int group = 0; | ||
213 | |||
214 | /* Count the capabilities. */ | ||
215 | for (n = 0; capa && capa[n]; n++) | ||
216 | ; | ||
217 | if (template->children) | ||
218 | for (; template->children[n].argp; n++) | ||
219 | ; | ||
220 | |||
221 | ap = calloc (n + 1, sizeof (*ap)); | ||
222 | if (!ap) | ||
223 | { | ||
224 | mu_error (_("Out of memory")); | ||
225 | abort (); | ||
226 | } | ||
227 | |||
228 | /* Copy the template's children. */ | ||
229 | nchild = 0; | ||
230 | if (template->children) | ||
231 | for (n = 0; template->children[n].argp; n++, nchild++) | ||
232 | ap[nchild] = template->children[n]; | ||
233 | |||
234 | /* Find next group number */ | ||
235 | for (opt = template->options; | ||
236 | opt && ((opt->name && opt->key) || opt->doc); opt++) | ||
237 | if (opt->group > group) | ||
238 | group = opt->group; | ||
239 | |||
240 | group++; | ||
241 | |||
242 | /* Append any capabilities to the children or options, as appropriate. */ | ||
243 | for (n = 0; capa && capa[n]; n++) | ||
244 | { | ||
245 | struct argp_capa *cp = find_capa (capa[n]); | ||
246 | if (!cp) | ||
247 | { | ||
248 | mu_error (_("INTERNAL ERROR: requested unknown argp " | ||
249 | "capability %s (please report)"), | ||
250 | capa[n]); | ||
251 | abort (); | ||
252 | } | ||
253 | ap[nchild] = *cp->child; | ||
254 | ap[nchild].group = group++; | ||
255 | nchild++; | ||
256 | |||
257 | } | ||
258 | ap[nchild].argp = NULL; | ||
259 | |||
260 | /* Copy the template, and give it the expanded children. */ | ||
261 | argp = malloc (sizeof (*argp)); | ||
262 | if (!argp) | ||
263 | { | ||
264 | mu_error (_("Out of memory")); | ||
265 | abort (); | ||
266 | } | ||
267 | |||
268 | memcpy (argp, template, sizeof (*argp)); | ||
269 | |||
270 | argp->children = ap; | ||
271 | |||
272 | return argp; | ||
273 | } | ||
274 | |||
275 | struct cap_buf | ||
276 | { | ||
277 | const char **capa; | ||
278 | size_t numcapa; | ||
279 | size_t maxcapa; | ||
280 | }; | ||
281 | |||
282 | static void | ||
283 | cap_buf_init (struct cap_buf *bp) | ||
284 | { | ||
285 | bp->numcapa = 0; | ||
286 | bp->maxcapa = 2; | ||
287 | bp->capa = calloc (bp->maxcapa, sizeof bp->capa[0]); | ||
288 | if (!bp->capa) | ||
289 | { | ||
290 | mu_error ("%s", mu_strerror (errno)); | ||
291 | abort (); | ||
292 | } | ||
293 | bp->capa[0] = NULL; | ||
294 | } | ||
295 | |||
296 | static void | ||
297 | cap_buf_add (struct cap_buf *bp, const char *str) | ||
298 | { | ||
299 | if (bp->numcapa == bp->maxcapa) | ||
300 | { | ||
301 | bp->maxcapa *= 2; | ||
302 | bp->capa = realloc (bp->capa, bp->maxcapa * sizeof bp->capa[0]); | ||
303 | if (!bp->capa) | ||
304 | { | ||
305 | mu_error ("%s", mu_strerror (errno)); | ||
306 | abort (); | ||
307 | } | ||
308 | } | ||
309 | bp->capa[bp->numcapa] = str; | ||
310 | if (str) | ||
311 | bp->numcapa++; | ||
312 | } | ||
313 | |||
314 | static void | ||
315 | cap_buf_free (struct cap_buf *bp) | ||
316 | { | ||
317 | free (bp->capa); | ||
318 | } | ||
319 | |||
320 | static int | ||
321 | argp_reg_action (void *item, void *data) | ||
322 | { | ||
323 | struct cap_buf *bp = data; | ||
324 | cap_buf_add (bp, item); | ||
325 | return 0; | ||
326 | } | ||
327 | |||
328 | struct argp * | ||
329 | mu_argp_build (const struct argp *init_argp) | ||
330 | { | ||
331 | struct cap_buf cb; | ||
332 | struct argp *argp; | ||
333 | |||
334 | cap_buf_init (&cb); | ||
335 | mu_gocs_enumerate (argp_reg_action, &cb); | ||
336 | cap_buf_add (&cb, NULL); | ||
337 | mu_libargp_init (); | ||
338 | argp = mu_build_argp (init_argp, cb.capa); | ||
339 | cap_buf_free (&cb); | ||
340 | return argp; | ||
341 | } | ||
342 | |||
343 | void | ||
344 | mu_argp_done (struct argp *argp) | ||
345 | { | ||
346 | free ((void*) argp->children); | ||
347 | free ((void*) argp); | ||
348 | } |
... | @@ -21,46 +21,23 @@ | ... | @@ -21,46 +21,23 @@ |
21 | #define _MAILUTILS_ARGP_H | 21 | #define _MAILUTILS_ARGP_H |
22 | 22 | ||
23 | #include <mailutils/types.h> | 23 | #include <mailutils/types.h> |
24 | #include <mailutils/cfg.h> | ||
25 | #include <argp.h> | 24 | #include <argp.h> |
26 | #include <errno.h> /* May declare program_invocation_name */ | 25 | #include <errno.h> /* May declare program_invocation_name */ |
27 | 26 | ||
28 | #define MODE_INTERACTIVE 0 | ||
29 | #define MODE_DAEMON 1 | ||
30 | |||
31 | struct daemon_param { | ||
32 | int mode; | ||
33 | size_t maxchildren; | ||
34 | unsigned int port; | ||
35 | unsigned int timeout; | ||
36 | int transcript; | ||
37 | char *pidfile; | ||
38 | }; | ||
39 | |||
40 | #ifdef USE_LIBPAM | ||
41 | extern char *pam_service; | ||
42 | #endif | ||
43 | extern int log_facility; | ||
44 | extern int mu_argp_error_code; | ||
45 | extern char *mu_license_text; | 27 | extern char *mu_license_text; |
46 | 28 | ||
47 | #ifdef __cplusplus | 29 | #ifdef __cplusplus |
48 | extern "C" { | 30 | extern "C" { |
49 | #endif | 31 | #endif |
50 | 32 | ||
51 | extern void mu_argp_init (const char *vers, const char *bugaddr); | 33 | extern void mu_argp_init (struct argp *argp, const char *vers, |
34 | const char *bugaddr, const char *capa[]); | ||
35 | extern void mu_argp_done (struct argp *argp); | ||
52 | 36 | ||
53 | extern error_t mu_argp_parse (const struct argp * argp, | 37 | extern int mu_register_argp_capa (const char *name, struct argp_child *child); |
54 | int *p_argc, char ***p_argv, | ||
55 | unsigned flags, | ||
56 | const char *capa[], | ||
57 | int *arg_index, void *input); | ||
58 | extern int mu_register_capa (const char *name, struct argp_child *child, | ||
59 | struct mu_cfg_param *param); | ||
60 | 38 | ||
61 | extern void mu_print_options (void); | 39 | extern void mu_print_options (void); |
62 | extern const char *mu_check_option (char *name); | 40 | extern const char *mu_check_option (char *name); |
63 | extern void mu_argp_set_config_param (struct mu_cfg_param *); | ||
64 | 41 | ||
65 | #ifdef __cplusplus | 42 | #ifdef __cplusplus |
66 | } | 43 | } | ... | ... |
libargp/pam.c
0 → 100644
1 | /* GNU Mailutils -- a suite of utilities for electronic mail | ||
2 | Copyright (C) 2007 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, write to the | ||
16 | Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | ||
17 | Boston, MA 02110-1301 USA */ | ||
18 | |||
19 | #ifdef HAVE_CONFIG_H | ||
20 | # include <config.h> | ||
21 | #endif | ||
22 | |||
23 | #include "cmdline.h" | ||
24 | #include <mailutils/pam.h> | ||
25 | |||
26 | static char *service_name; | ||
27 | |||
28 | static error_t | ||
29 | mu_pam_argp_parser (int key, char *arg, struct argp_state *state) | ||
30 | { | ||
31 | switch (key) | ||
32 | { | ||
33 | case OPT_PAM_SERVICE: | ||
34 | service_name = arg; | ||
35 | break; | ||
36 | |||
37 | case ARGP_KEY_FINI: | ||
38 | mu_gocs_store ("pam", service_name); | ||
39 | break; | ||
40 | |||
41 | default: | ||
42 | return ARGP_ERR_UNKNOWN; | ||
43 | } | ||
44 | return 0; | ||
45 | } | ||
46 | |||
47 | static struct argp_option mu_pam_argp_option[] = { | ||
48 | { "pam-service", OPT_PAM_SERVICE, N_("STRING"), OPTION_HIDDEN, | ||
49 | N_("Use STRING as PAM service name"), 0}, | ||
50 | { NULL, 0, NULL, 0, NULL, 0 } | ||
51 | }; | ||
52 | |||
53 | static struct argp mu_pam_argp = { | ||
54 | mu_pam_argp_option, | ||
55 | mu_pam_argp_parser, | ||
56 | }; | ||
57 | |||
58 | struct argp_child mu_pam_argp_child = { | ||
59 | &mu_pam_argp, | ||
60 | 0, | ||
61 | NULL, | ||
62 | 0 | ||
63 | }; | ||
64 | |||
65 | struct mu_cmdline_capa mu_pam_cmdline = { | ||
66 | "pam", &mu_pam_argp_child | ||
67 | }; |
libargp/radius.c
0 → 100644
1 | /* GNU Mailutils -- a suite of utilities for electronic mail | ||
2 | Copyright (C) 2007 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, write to the | ||
16 | Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | ||
17 | Boston, MA 02110-1301 USA */ | ||
18 | |||
19 | #ifdef HAVE_CONFIG_H | ||
20 | # include <config.h> | ||
21 | #endif | ||
22 | |||
23 | #include "cmdline.h" | ||
24 | #include <mailutils/radius.h> | ||
25 | |||
26 | static struct argp_option mu_radius_argp_option[] = { | ||
27 | { "radius-auth-request", OPT_AUTH_REQUEST, N_("REQUEST"), OPTION_HIDDEN, | ||
28 | N_("Radius request to authenitcate the user"), 0 }, | ||
29 | { "radius-getpwnam-request", OPT_GETPWNAM_REQUEST, N_("REQUEST"), OPTION_HIDDEN, | ||
30 | N_("Radius request to retrieve a passwd entry based on username"), 0 }, | ||
31 | { "radius-getpwuid-request", OPT_GETPWUID_REQUEST, N_("REQUEST"), OPTION_HIDDEN, | ||
32 | N_("Radius request to retrieve a passwd entry based on UID"), 0 }, | ||
33 | { "radius-directory", OPT_RADIUS_DIR, N_("DIR"), OPTION_HIDDEN, | ||
34 | N_("Set path to the radius configuration directory"), 0 }, | ||
35 | { NULL } | ||
36 | }; | ||
37 | |||
38 | |||
39 | static struct mu_radius_module_data radius_data; | ||
40 | |||
41 | static error_t | ||
42 | mu_radius_argp_parser (int key, char *arg, struct argp_state *state) | ||
43 | { | ||
44 | switch (key) | ||
45 | { | ||
46 | case OPT_AUTH_REQUEST: | ||
47 | radius_data.auth_request = arg; | ||
48 | break; | ||
49 | |||
50 | case OPT_GETPWNAM_REQUEST: | ||
51 | radius_data.getpwnam_request = arg; | ||
52 | break; | ||
53 | |||
54 | case OPT_GETPWUID_REQUEST: | ||
55 | radius_data.getpwuid_request = arg; | ||
56 | break; | ||
57 | |||
58 | case OPT_RADIUS_DIR: | ||
59 | radius_data.config_dir = arg; | ||
60 | break; | ||
61 | |||
62 | case ARGP_KEY_FINI: | ||
63 | mu_gocs_store ("radius", &radius_data); | ||
64 | break; | ||
65 | |||
66 | default: | ||
67 | return ARGP_ERR_UNKNOWN; | ||
68 | } | ||
69 | return 0; | ||
70 | } | ||
71 | |||
72 | static struct argp mu_radius_argp = { | ||
73 | mu_radius_argp_option, | ||
74 | mu_radius_argp_parser, | ||
75 | }; | ||
76 | |||
77 | struct argp_child mu_radius_argp_child = { | ||
78 | &mu_radius_argp, | ||
79 | 0, | ||
80 | NULL, | ||
81 | 0 | ||
82 | }; | ||
83 | |||
84 | struct mu_cmdline_capa mu_radius_cmdline = { | ||
85 | "radius", &mu_radius_argp_child | ||
86 | }; |
... | @@ -20,74 +20,53 @@ | ... | @@ -20,74 +20,53 @@ |
20 | #ifdef HAVE_CONFIG_H | 20 | #ifdef HAVE_CONFIG_H |
21 | # include <config.h> | 21 | # include <config.h> |
22 | #endif | 22 | #endif |
23 | #include <sieve.h> | 23 | #include "cmdline.h" |
24 | #include <mailutils/argp.h> | 24 | #include "mailutils/libsieve.h" |
25 | #include <string.h> | ||
26 | 25 | ||
27 | mu_list_t mu_sieve_include_path = NULL; | ||
28 | mu_list_t mu_sieve_library_path = NULL; | ||
29 | 26 | ||
30 | static error_t sieve_argp_parser (int key, char *arg, struct argp_state *state); | ||
31 | |||
32 | #define CLEARPATH_OPTION 256 | ||
33 | |||
34 | /* Options used by programs that use extended authentication mechanisms. */ | ||
35 | static struct argp_option sieve_argp_option[] = { | 27 | static struct argp_option sieve_argp_option[] = { |
36 | { "includedir", 'I', N_("DIR"), 0, | 28 | { "includedir", 'I', N_("DIR"), 0, |
37 | N_("Append directory DIR to the list of directories searched for include files"), 0 }, | 29 | N_("Append directory DIR to the list of directories searched for include files"), 0 }, |
38 | { "libdir", 'L', N_("DIR"), 0, | 30 | { "libdir", 'L', N_("DIR"), 0, |
39 | N_("Append directory DIR to the list of directories searched for library files"), 0 }, | 31 | N_("Append directory DIR to the list of directories searched for library files"), 0 }, |
40 | { "clearpath", CLEARPATH_OPTION, NULL, 0, | 32 | { "clear-include-path", OPT_CLEAR_INCLUDE_PATH, NULL, 0, |
41 | N_("Clear Sieve load path"), 0 }, | 33 | N_("Clear Sieve include path"), 0 }, |
34 | { "clear-library-path", OPT_CLEAR_LIBRARY_PATH, NULL, 0, | ||
35 | N_("Clear Sieve lobrary path"), 0 }, | ||
36 | { "clearpath", 0, NULL, OPTION_ALIAS, NULL }, | ||
42 | { NULL, 0, NULL, 0, NULL, 0 } | 37 | { NULL, 0, NULL, 0, NULL, 0 } |
43 | }; | 38 | }; |
44 | 39 | ||
45 | static struct argp sieve_argp = { | ||
46 | sieve_argp_option, | ||
47 | sieve_argp_parser, | ||
48 | }; | ||
49 | |||
50 | static struct argp_child sieve_argp_child = { | ||
51 | &sieve_argp, | ||
52 | 0, | ||
53 | "Sieve options", | ||
54 | 0 | ||
55 | }; | ||
56 | |||
57 | static void | ||
58 | destroy_string (void *str) | ||
59 | { | ||
60 | free (str); | ||
61 | } | ||
62 | |||
63 | static error_t | 40 | static error_t |
64 | sieve_argp_parser (int key, char *arg, struct argp_state *state) | 41 | sieve_argp_parser (int key, char *arg, struct argp_state *state) |
65 | { | 42 | { |
43 | static struct mu_gocs_sieve gocs_data; | ||
66 | mu_list_t *plist = NULL; | 44 | mu_list_t *plist = NULL; |
67 | 45 | ||
68 | switch (key) | 46 | switch (key) |
69 | { | 47 | { |
70 | case 'I': | 48 | case 'I': |
71 | plist = &mu_sieve_include_path; | 49 | plist = &gocs_data.include_path; |
72 | break; | 50 | break; |
73 | 51 | ||
74 | case 'L': | 52 | case 'L': |
75 | plist = &mu_sieve_library_path; | 53 | plist = &gocs_data.library_path; |
54 | break; | ||
55 | |||
56 | case OPT_CLEAR_INCLUDE_PATH: | ||
57 | gocs_data.clearflags |= MU_SIEVE_CLEAR_INCLUDE_PATH; | ||
76 | break; | 58 | break; |
77 | 59 | ||
78 | case CLEARPATH_OPTION: | 60 | case OPT_CLEAR_LIBRARY_PATH: |
79 | mu_list_destroy (&mu_sieve_library_path); | 61 | gocs_data.clearflags |= MU_SIEVE_CLEAR_LIBRARY_PATH; |
80 | break; | 62 | break; |
81 | 63 | ||
82 | case ARGP_KEY_INIT: | 64 | case ARGP_KEY_INIT: |
83 | #ifdef SIEVE_MODDIR | 65 | memset (&gocs_data, 0, sizeof gocs_data); |
84 | plist = &mu_sieve_library_path; | ||
85 | arg = SIEVE_MODDIR; | ||
86 | #endif | ||
87 | break; | 66 | break; |
88 | 67 | ||
89 | case ARGP_KEY_FINI: | 68 | case ARGP_KEY_FINI: |
90 | sieve_load_add_path (mu_sieve_library_path); | 69 | mu_gocs_store ("sieve", &gocs_data); |
91 | break; | 70 | break; |
92 | 71 | ||
93 | default: | 72 | default: |
... | @@ -101,24 +80,30 @@ sieve_argp_parser (int key, char *arg, struct argp_state *state) | ... | @@ -101,24 +80,30 @@ sieve_argp_parser (int key, char *arg, struct argp_state *state) |
101 | int rc = mu_list_create (plist); | 80 | int rc = mu_list_create (plist); |
102 | if (rc) | 81 | if (rc) |
103 | { | 82 | { |
104 | argp_error (state, "can't create list: %s", | 83 | argp_error (state, _("cannot create list: %s"), |
105 | mu_strerror (rc)); | 84 | mu_strerror (rc)); |
106 | exit (1); | 85 | exit (1); |
107 | } | 86 | } |
108 | mu_list_set_destroy_item (*plist, destroy_string); | ||
109 | } | 87 | } |
110 | mu_list_append (*plist, strdup (arg)); | 88 | mu_list_append (*plist, arg); |
111 | } | 89 | } |
112 | 90 | ||
113 | return 0; | 91 | return 0; |
114 | } | 92 | } |
115 | 93 | ||
116 | void | 94 | static struct argp sieve_argp = { |
117 | mu_sieve_argp_init () | 95 | sieve_argp_option, |
118 | { | 96 | sieve_argp_parser, |
119 | if (mu_register_capa ("sieve", &sieve_argp_child, NULL)) | 97 | }; |
120 | { | 98 | |
121 | mu_error ("INTERNAL ERROR: cannot register argp capability sieve"); | 99 | static struct argp_child sieve_argp_child = { |
122 | abort (); | 100 | &sieve_argp, |
123 | } | 101 | 0, |
124 | } | 102 | N_("Sieve options"), |
103 | 0 | ||
104 | }; | ||
105 | |||
106 | struct mu_cmdline_capa mu_sieve_cmdline = { | ||
107 | "sieve", &sieve_argp_child | ||
108 | }; | ||
109 | ... | ... |
libargp/sql.c
0 → 100644
1 | /* GNU Mailutils -- a suite of utilities for electronic mail | ||
2 | Copyright (C) 2007 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, write to the | ||
16 | Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | ||
17 | Boston, MA 02110-1301 USA */ | ||
18 | |||
19 | #ifdef HAVE_CONFIG_H | ||
20 | # include <config.h> | ||
21 | #endif | ||
22 | |||
23 | #include "cmdline.h" | ||
24 | #include "mailutils/sql.h" | ||
25 | #include "mailutils/mutil.h" | ||
26 | |||
27 | static int sql_requested; | ||
28 | static struct mu_sql_module_config sql_config; | ||
29 | /* Command-line configuration */ | ||
30 | |||
31 | static struct argp_option mu_sql_argp_option[] = { | ||
32 | {"sql-interface", OPT_SQL_INTERFACE, N_("NAME"), OPTION_HIDDEN, | ||
33 | N_("Type of SQL interface to use"), }, | ||
34 | {"sql-getpwnam", OPT_SQL_GETPWNAM, N_("QUERY"), OPTION_HIDDEN, | ||
35 | N_("SQL query to retrieve a passwd entry based on username"), 0}, | ||
36 | {"sql-getpwuid", OPT_SQL_GETPWUID, N_("QUERY"), OPTION_HIDDEN, | ||
37 | N_("SQL query to retrieve a passwd entry based on UID"), 0}, | ||
38 | {"sql-getpass", OPT_SQL_GETPASS, N_("QUERY"), OPTION_HIDDEN, | ||
39 | N_("SQL query to retrieve a password from the database"), 0}, | ||
40 | {"sql-host", OPT_SQL_HOST, N_("HOSTNAME"), OPTION_HIDDEN, | ||
41 | N_("Name or IP of MySQL server to connect to"), 0}, | ||
42 | {"sql-user", OPT_SQL_USER, N_("NAME"), OPTION_HIDDEN, | ||
43 | N_("SQL user name"), 0}, | ||
44 | {"sql-passwd", OPT_SQL_PASSWD, N_("STRING"), OPTION_HIDDEN, | ||
45 | N_("SQL connection password"), 0}, | ||
46 | {"sql-db", OPT_SQL_DB, N_("STRING"), OPTION_HIDDEN, | ||
47 | N_("Name of the database to connect to"), 0}, | ||
48 | {"sql-port", OPT_SQL_PORT, N_("NUMBER"), OPTION_HIDDEN, | ||
49 | N_("Port to use"), 0}, | ||
50 | {"sql-password-type", OPT_SQL_MU_PASSWORD_TYPE, N_("STRING"), OPTION_HIDDEN, | ||
51 | N_("Type of password returned by --sql-getpass query. STRING is one of: plain, hash, scrambled"), 0}, | ||
52 | {"sql-field-map", OPT_SQL_FIELD_MAP, N_("MAP"), OPTION_HIDDEN, | ||
53 | N_("Declare a name translation map for SQL fields in results of sql-getpwnam and " | ||
54 | "sql-getpwuid queries"), 0}, | ||
55 | { NULL, 0, NULL, 0, NULL, 0 } | ||
56 | }; | ||
57 | |||
58 | static error_t | ||
59 | mu_sql_argp_parser (int key, char *arg, struct argp_state *state) | ||
60 | { | ||
61 | int rc, err; | ||
62 | |||
63 | switch (key) | ||
64 | { | ||
65 | case OPT_SQL_INTERFACE: | ||
66 | sql_config.interface = arg; | ||
67 | sql_requested = 1; | ||
68 | break; | ||
69 | |||
70 | case OPT_SQL_GETPWNAM: | ||
71 | sql_requested = 1; | ||
72 | sql_config.getpwnam_query = arg; | ||
73 | break; | ||
74 | |||
75 | case OPT_SQL_GETPWUID: | ||
76 | sql_requested = 1; | ||
77 | sql_config.getpwuid_query = arg; | ||
78 | break; | ||
79 | |||
80 | case OPT_SQL_GETPASS: | ||
81 | sql_requested = 1; | ||
82 | sql_config.getpass_query = arg; | ||
83 | break; | ||
84 | |||
85 | case OPT_SQL_HOST: | ||
86 | sql_requested = 1; | ||
87 | sql_config.host = arg; | ||
88 | break; | ||
89 | |||
90 | case OPT_SQL_USER: | ||
91 | sql_requested = 1; | ||
92 | sql_config.user = arg; | ||
93 | break; | ||
94 | |||
95 | case OPT_SQL_PASSWD: | ||
96 | sql_requested = 1; | ||
97 | sql_config.passwd = arg; | ||
98 | break; | ||
99 | |||
100 | case OPT_SQL_DB: | ||
101 | sql_requested = 1; | ||
102 | sql_config.db = arg; | ||
103 | break; | ||
104 | |||
105 | case OPT_SQL_PORT: | ||
106 | sql_requested = 1; | ||
107 | sql_config.port = strtoul (arg, NULL, 0); | ||
108 | break; | ||
109 | |||
110 | case OPT_SQL_MU_PASSWORD_TYPE: | ||
111 | if (mu_sql_decode_password_type (arg, &sql_config.password_type)) | ||
112 | argp_error (state, _("Unknown password type `%s'"), arg); | ||
113 | sql_requested = 1; | ||
114 | break; | ||
115 | |||
116 | case OPT_SQL_FIELD_MAP: | ||
117 | rc = mutil_parse_field_map (arg, &sql_config.field_map, &err); | ||
118 | if (rc) | ||
119 | argp_error (state, _("Error near element %d: %s"), | ||
120 | err, mu_strerror (rc)); | ||
121 | sql_requested = 1; | ||
122 | break; | ||
123 | |||
124 | case ARGP_KEY_FINI: | ||
125 | if (sql_requested) | ||
126 | mu_gocs_store ("sql", &sql_config); | ||
127 | break; | ||
128 | |||
129 | default: | ||
130 | return ARGP_ERR_UNKNOWN; | ||
131 | } | ||
132 | return 0; | ||
133 | } | ||
134 | |||
135 | static struct argp mu_sql_argp = { | ||
136 | mu_sql_argp_option, | ||
137 | mu_sql_argp_parser, | ||
138 | }; | ||
139 | |||
140 | struct argp_child mu_sql_argp_child = { | ||
141 | &mu_sql_argp, | ||
142 | 0, | ||
143 | NULL, | ||
144 | 0 | ||
145 | }; | ||
146 | |||
147 | struct mu_cmdline_capa mu_sql_cmdline = { | ||
148 | "sql", &mu_sql_argp_child | ||
149 | }; |
libargp/tls.c
0 → 100644
1 | /* GNU Mailutils -- a suite of utilities for electronic mail | ||
2 | Copyright (C) 2007 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, write to the | ||
16 | Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | ||
17 | Boston, MA 02110-1301 USA */ | ||
18 | |||
19 | #ifdef HAVE_CONFIG_H | ||
20 | # include <config.h> | ||
21 | #endif | ||
22 | |||
23 | #include "cmdline.h" | ||
24 | #include <mailutils/tls.h> | ||
25 | #include "strcase.h" /* FIXME */ | ||
26 | |||
27 | static struct argp_option _tls_argp_options[] = { | ||
28 | {"ssl-cert", OPT_SSL_CERT, N_("FILE"), OPTION_HIDDEN, | ||
29 | N_("Specify SSL certificate file"), 0}, | ||
30 | {"ssl-key", OPT_SSL_KEY, N_("FILE"), OPTION_HIDDEN, | ||
31 | N_("Specify SSL certificate key"), }, | ||
32 | {"ssl-cafile", OPT_SSL_CAFILE, N_("FILE"), OPTION_HIDDEN, | ||
33 | N_("Specify trusted CAs file"), 0}, | ||
34 | {"tls", OPT_TLS, N_("BOOL"), OPTION_ARG_OPTIONAL, | ||
35 | N_("Enable TLS support") }, | ||
36 | {NULL, 0, NULL, 0, NULL, 0} | ||
37 | }; | ||
38 | |||
39 | static struct mu_tls_module_config tls_data = { 1, }; | ||
40 | |||
41 | static error_t | ||
42 | _tls_argp_parser (int key, char *arg, struct argp_state *state) | ||
43 | { | ||
44 | switch (key) | ||
45 | { | ||
46 | case OPT_TLS: | ||
47 | if (!arg || strcasecmp (arg, "yes") == 0) | ||
48 | tls_data.client_enable = 1; | ||
49 | else if (strcasecmp (arg, "no") == 0) | ||
50 | tls_data.client_enable = 0; | ||
51 | break; | ||
52 | |||
53 | case OPT_SSL_CERT: | ||
54 | tls_data.ssl_cert = arg; | ||
55 | break; | ||
56 | |||
57 | case OPT_SSL_KEY: | ||
58 | tls_data.ssl_key = arg; | ||
59 | break; | ||
60 | |||
61 | case OPT_SSL_CAFILE: | ||
62 | tls_data.ssl_cafile = arg; | ||
63 | break; | ||
64 | |||
65 | case ARGP_KEY_FINI: | ||
66 | mu_gocs_store ("tls", &tls_data); | ||
67 | break; | ||
68 | |||
69 | default: | ||
70 | return ARGP_ERR_UNKNOWN; | ||
71 | } | ||
72 | return 0; | ||
73 | } | ||
74 | |||
75 | static struct argp _tls_argp = { | ||
76 | _tls_argp_options, | ||
77 | _tls_argp_parser | ||
78 | }; | ||
79 | |||
80 | static struct argp_child _tls_argp_child = { | ||
81 | &_tls_argp, | ||
82 | 0, | ||
83 | NULL, | ||
84 | 0 | ||
85 | }; | ||
86 | |||
87 | struct mu_cmdline_capa mu_tls_cmdline = { | ||
88 | "tls", &_tls_argp_child | ||
89 | }; | ||
90 |
libargp/virtdomain.c
0 → 100644
1 | /* GNU Mailutils -- a suite of utilities for electronic mail | ||
2 | Copyright (C) 2007 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, write to the | ||
16 | Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | ||
17 | Boston, MA 02110-1301 USA */ | ||
18 | |||
19 | #ifdef HAVE_CONFIG_H | ||
20 | # include <config.h> | ||
21 | #endif | ||
22 | |||
23 | #include "cmdline.h" | ||
24 | |||
25 | static char *virtdir; | ||
26 | |||
27 | static error_t | ||
28 | mu_virt_argp_parser (int key, char *arg, struct argp_state *state) | ||
29 | { | ||
30 | switch (key) | ||
31 | { | ||
32 | case OPT_PWDDIR: | ||
33 | virtdir = arg; | ||
34 | break; | ||
35 | |||
36 | case ARGP_KEY_FINI: | ||
37 | mu_gocs_store ("virtdomain", virtdir); | ||
38 | break; | ||
39 | |||
40 | default: | ||
41 | return ARGP_ERR_UNKNOWN; | ||
42 | } | ||
43 | return 0; | ||
44 | } | ||
45 | |||
46 | static struct argp_option mu_virt_argp_option[] = { | ||
47 | { "virtual-passwd-dir", OPT_PWDDIR, N_("DIR"), OPTION_HIDDEN, | ||
48 | N_("Search for virtual passwd file in DIR"), 0}, | ||
49 | { NULL, 0, NULL, 0, NULL, 0 } | ||
50 | }; | ||
51 | |||
52 | static struct argp mu_virt_argp = { | ||
53 | mu_virt_argp_option, | ||
54 | mu_virt_argp_parser, | ||
55 | }; | ||
56 | |||
57 | struct argp_child mu_virt_argp_child = { | ||
58 | &mu_virt_argp, | ||
59 | 0, | ||
60 | NULL, | ||
61 | 0 | ||
62 | }; | ||
63 | |||
64 | struct mu_cmdline_capa mu_virtdomain_cmdline = { | ||
65 | "virtdomain", &mu_virt_argp_child | ||
66 | }; |
libcfg/Makefile.am
0 → 100644
1 | # This file is part of GNU Mailutils | ||
2 | # Copyright (C) 2007 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, write to the Free Software | ||
16 | # Foundation, Inc. 51 Franklin Street, Fifth Floor, Boston, MA | ||
17 | # 02110-1301 USA | ||
18 | |||
19 | INCLUDES = @MU_COMMON_INCLUDES@ | ||
20 | AM_CFLAGS = -DSITE_VIRTUAL_PWDDIR=\"@SITE_VIRTUAL_PWDDIR@\" \ | ||
21 | -DSITE_CRAM_MD5_PWD=\"@SITE_CRAM_MD5_PWD@\" | ||
22 | |||
23 | lib_LTLIBRARIES = libmucfg.la | ||
24 | noinst_HEADERS = libcfg.h | ||
25 | libmucfg_la_SOURCES=\ | ||
26 | auth.c\ | ||
27 | common.c\ | ||
28 | init.c\ | ||
29 | gsasl.c\ | ||
30 | pam.c\ | ||
31 | radius.c\ | ||
32 | sieve.c\ | ||
33 | sql.c\ | ||
34 | tls.c\ | ||
35 | virtdomain.c |
libcfg/auth.c
0 → 100644
1 | /* This file is part of GNU Mailutils | ||
2 | Copyright (C) 2007 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 | This program 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 this program. If not, see <http://www.gnu.org/licenses/>. | ||
16 | */ | ||
17 | |||
18 | #include "libcfg.h" | ||
19 | #include <mailutils/mu_auth.h> | ||
20 | #include <string.h> | ||
21 | |||
22 | /* FIXME: mu_auth.c should be reviewed */ | ||
23 | |||
24 | |||
25 | /* ************************************************************************* */ | ||
26 | /* Resource-style configuration */ | ||
27 | /* ************************************************************************* */ | ||
28 | static int | ||
29 | cb_authentication (mu_cfg_locus_t *locus, void *data, char *arg) | ||
30 | { | ||
31 | if (strcmp (arg, "clear") == 0) | ||
32 | mu_authentication_clear_list (); | ||
33 | else | ||
34 | mu_authentication_add_module_list (arg);/*FIXME: error reporting*/ | ||
35 | return 0; | ||
36 | } | ||
37 | |||
38 | static int | ||
39 | cb_authorization (mu_cfg_locus_t *locus, void *data, char *arg) | ||
40 | { | ||
41 | if (strcmp (arg, "clear") == 0) | ||
42 | mu_authorization_clear_list (); | ||
43 | else | ||
44 | mu_authorization_add_module_list (arg); | ||
45 | return 0; | ||
46 | } | ||
47 | |||
48 | static struct mu_cfg_param mu_auth_param[] = { | ||
49 | { "authentication", mu_cfg_callback, NULL, cb_authentication }, | ||
50 | { "authorization", mu_cfg_callback, NULL, cb_authorization }, | ||
51 | { NULL } | ||
52 | }; | ||
53 | |||
54 | /* FIXME: init? */ | ||
55 |
libcfg/common.c
0 → 100644
1 | /* This file is part of GNU Mailutils | ||
2 | Copyright (C) 2007 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 | This program 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 this program. If not, see <http://www.gnu.org/licenses/>. | ||
16 | */ | ||
17 | |||
18 | #include "libcfg.h" | ||
19 | #include <string.h> | ||
20 | #include <mailutils/daemon.h> | ||
21 | |||
22 | static struct mu_gocs_daemon daemon_settings; | ||
23 | static struct mu_gocs_locking locking_settings; | ||
24 | static struct mu_gocs_logging logging_settings; | ||
25 | static struct mu_gocs_mailbox mailbox_settings; | ||
26 | static struct mu_gocs_source_email address_settings; | ||
27 | static struct mu_gocs_mailer mailer_settings; | ||
28 | |||
29 | |||
30 | /* ************************************************************************* */ | ||
31 | /* Mailbox */ | ||
32 | /* ************************************************************************* */ | ||
33 | |||
34 | static struct mu_cfg_param mu_mailbox_param[] = { | ||
35 | { "mail-spool", mu_cfg_string, &mailbox_settings.mail_spool }, | ||
36 | { "mailbox-type", mu_cfg_string, &mailbox_settings.mailbox_type }, | ||
37 | { NULL } | ||
38 | }; | ||
39 | |||
40 | DCL_CFG_CAPA (mailbox); | ||
41 | |||
42 | |||
43 | /* ************************************************************************* */ | ||
44 | /* Locking */ | ||
45 | /* ************************************************************************* */ | ||
46 | |||
47 | static struct mu_cfg_param mu_locking_param[] = { | ||
48 | { "lock-flags", mu_cfg_string, &locking_settings.lock_flags }, | ||
49 | { "lock-retry-timeout", mu_cfg_ulong, &locking_settings.lock_retry_timeout }, | ||
50 | { "lock-retry-count", mu_cfg_ulong, &locking_settings.lock_retry_count }, | ||
51 | { "lock-expire-timeout", mu_cfg_ulong, | ||
52 | &locking_settings.lock_expire_timeout }, | ||
53 | { "external-locker", mu_cfg_string, &locking_settings.external_locker }, | ||
54 | { NULL, } | ||
55 | }; | ||
56 | |||
57 | DCL_CFG_CAPA (locking); | ||
58 | |||
59 | |||
60 | /* ************************************************************************* */ | ||
61 | /* Address */ | ||
62 | /* ************************************************************************* */ | ||
63 | |||
64 | static struct mu_cfg_param mu_address_param[] = { | ||
65 | { "email-addr", mu_cfg_string, &address_settings.address }, | ||
66 | { "email-domain", mu_cfg_string, &address_settings.domain }, | ||
67 | { NULL } | ||
68 | }; | ||
69 | |||
70 | DCL_CFG_CAPA (address); | ||
71 | |||
72 | |||
73 | /* ************************************************************************* */ | ||
74 | /* Mailer */ | ||
75 | /* ************************************************************************* */ | ||
76 | |||
77 | static struct mu_cfg_param mu_mailer_param[] = { | ||
78 | { "url", mu_cfg_string, &mailer_settings.mailer }, | ||
79 | { NULL } | ||
80 | }; | ||
81 | |||
82 | DCL_CFG_CAPA (mailer); | ||
83 | |||
84 | |||
85 | /* ************************************************************************* */ | ||
86 | /* Logging */ | ||
87 | /* ************************************************************************* */ | ||
88 | |||
89 | static struct mu_cfg_param mu_logging_param[] = { | ||
90 | { "facility", mu_cfg_string, &logging_settings.facility }, | ||
91 | { NULL } | ||
92 | }; | ||
93 | |||
94 | DCL_CFG_CAPA (logging); | ||
95 | |||
96 | |||
97 | /* ************************************************************************* */ | ||
98 | /* Daemon */ | ||
99 | /* ************************************************************************* */ | ||
100 | |||
101 | static int | ||
102 | _cb_daemon_mode (mu_cfg_locus_t *locus, void *data, char *arg) | ||
103 | { | ||
104 | if (strcmp (arg, "inetd") == 0 | ||
105 | || strcmp (arg, "interactive") == 0) | ||
106 | daemon_settings.mode = MODE_INTERACTIVE; | ||
107 | else if (strcmp (arg, "daemon") == 0) | ||
108 | daemon_settings.mode = MODE_DAEMON; | ||
109 | else | ||
110 | { | ||
111 | mu_error ("%s:%d: unknown daemon mode", locus->file, locus->line); | ||
112 | return 1; | ||
113 | } | ||
114 | return 0; | ||
115 | } | ||
116 | |||
117 | static struct mu_cfg_param mu_daemon_param[] = { | ||
118 | { "max-children", mu_cfg_ulong, &daemon_settings.maxchildren }, | ||
119 | { "mode", mu_cfg_callback, NULL, _cb_daemon_mode }, | ||
120 | { "transcript", mu_cfg_bool, &daemon_settings.transcript }, | ||
121 | { "pidfile", mu_cfg_string, &daemon_settings.pidfile }, | ||
122 | { "port", mu_cfg_ushort, &daemon_settings.port }, | ||
123 | { "timeout", mu_cfg_ulong, &daemon_settings.timeout }, | ||
124 | { NULL } | ||
125 | }; | ||
126 |
libcfg/gsasl.c
0 → 100644
1 | /* This file is part of GNU Mailutils | ||
2 | Copyright (C) 2007 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 | This program 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 this program. If not, see <http://www.gnu.org/licenses/>. | ||
16 | */ | ||
17 | |||
18 | #include "libcfg.h" | ||
19 | #include <mailutils/gsasl.h> | ||
20 | |||
21 | static struct mu_gsasl_module_data gsasl_settings; | ||
22 | |||
23 | static struct mu_cfg_param mu_gsasl_param[] = { | ||
24 | { "cram-passwd", mu_cfg_string, &gsasl_settings.cram_md5_pwd }, | ||
25 | { NULL } | ||
26 | }; | ||
27 | |||
28 | DCL_CFG_CAPA (gsasl); | ||
29 | |||
30 |
libcfg/init.c
0 → 100644
1 | /* This file is part of GNU Mailutils | ||
2 | Copyright (C) 2007 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 | This program 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 this program. If not, see <http://www.gnu.org/licenses/>. | ||
16 | */ | ||
17 | |||
18 | #include "libcfg.h" | ||
19 | #include <string.h> | ||
20 | #include <stdlib.h> | ||
21 | |||
22 | struct mu_cfg_capa *cfg_capa_table[] = { | ||
23 | #define S(c) &__mu_common_cat3__(mu_,c,_cfg_capa) | ||
24 | S (mailbox), | ||
25 | S (locking), | ||
26 | S (address), | ||
27 | S (mailer), | ||
28 | S (logging), | ||
29 | S (gsasl), | ||
30 | S (pam), | ||
31 | S (radius), | ||
32 | S (sql), | ||
33 | S (tls), | ||
34 | S (virtdomain), | ||
35 | NULL | ||
36 | }; | ||
37 | |||
38 | struct mu_cfg_capa * | ||
39 | find_cfg_capa (const char *name) | ||
40 | { | ||
41 | int i; | ||
42 | |||
43 | for (i = 0; cfg_capa_table[i]; i++) | ||
44 | if (strcmp (cfg_capa_table[i]->name, name) == 0) | ||
45 | return cfg_capa_table[i]; | ||
46 | return NULL; | ||
47 | } | ||
48 | |||
49 | static int | ||
50 | reserved_name (const char *name) | ||
51 | { | ||
52 | static char *reserved[] = { "auth", "common", "daemon", "license", NULL }; | ||
53 | char **p; | ||
54 | for (p = reserved; *p; p++) | ||
55 | if (strcmp (name, *p) == 0) | ||
56 | return 1; | ||
57 | return 0; | ||
58 | } | ||
59 | |||
60 | void | ||
61 | mu_libcfg_init (const char **cnames) | ||
62 | { | ||
63 | int i; | ||
64 | for (i = 0; cnames[i]; i++) | ||
65 | { | ||
66 | if (!reserved_name (cnames[i])) | ||
67 | { | ||
68 | struct mu_cfg_capa *cp = find_cfg_capa (cnames[i]); | ||
69 | if (!cp) | ||
70 | mu_error (_("Requested unknown configuration group `%s'"), | ||
71 | cnames[i]); | ||
72 | else | ||
73 | mu_config_register_section (NULL, cp->name, cp->parser, NULL, | ||
74 | cp->cfgparam); | ||
75 | } | ||
76 | } | ||
77 | } | ||
78 | |||
79 | int | ||
80 | mu_parse_config_files (struct mu_cfg_param *param) | ||
81 | { | ||
82 | if (mu_load_site_rcfile) | ||
83 | mu_parse_config (MU_CONFIG_FILE, mu_program_name, param, 1); | ||
84 | |||
85 | if (mu_load_user_rcfile && mu_program_name) | ||
86 | { | ||
87 | size_t size = 3 + strlen (mu_program_name) + 1; | ||
88 | char *file_name = malloc (size); | ||
89 | if (file_name) | ||
90 | { | ||
91 | strcpy (file_name, "~/."); | ||
92 | strcat (file_name, mu_program_name); | ||
93 | |||
94 | mu_parse_config (file_name, mu_program_name, param, 0); | ||
95 | |||
96 | free (file_name); | ||
97 | } | ||
98 | } | ||
99 | |||
100 | if (mu_load_rcfile) | ||
101 | mu_parse_config (mu_load_rcfile, mu_program_name, param, 0); | ||
102 | |||
103 | return 0; | ||
104 | } |
libcfg/libcfg.h
0 → 100644
1 | /* GNU Mailutils -- a suite of utilities for electronic mail | ||
2 | Copyright (C) 2007 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, write to the | ||
16 | Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | ||
17 | Boston, MA 02110-1301 USA */ | ||
18 | |||
19 | #ifdef HAVE_CONFIG_H | ||
20 | # include <config.h> | ||
21 | #endif | ||
22 | #include <mailutils/cfg.h> | ||
23 | #include <mailutils/gocs.h> | ||
24 | #include <mailutils/nls.h> | ||
25 | #include <mailutils/error.h> | ||
26 | #include <mailutils/errno.h> | ||
27 | |||
28 | #ifndef MU_CONFIG_FILE | ||
29 | # define MU_CONFIG_FILE SYSCONFDIR "/mailutils.rc" | ||
30 | #endif | ||
31 | |||
32 | #ifndef MU_USER_CONFIG_FILE | ||
33 | # define MU_USER_CONFIG_FILE "~/.mailutils" | ||
34 | #endif | ||
35 | |||
36 | struct mu_cfg_capa | ||
37 | { | ||
38 | char *name; | ||
39 | struct mu_cfg_param *cfgparam; | ||
40 | mu_cfg_section_fp parser; | ||
41 | }; | ||
42 | |||
43 | extern int mu_register_cfg_capa (const char *name, | ||
44 | struct mu_cfg_param *cfgparam, | ||
45 | mu_cfg_section_fp *parser); | ||
46 | |||
47 | extern void mu_libcfg_init (const char **cnames); | ||
48 | extern int mu_parse_config_files (struct mu_cfg_param *param); | ||
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 | void *section_data, void *call_data) \ | ||
57 | { \ | ||
58 | switch (stage) \ | ||
59 | { \ | ||
60 | case mu_cfg_section_start: \ | ||
61 | break; \ | ||
62 | \ | ||
63 | case mu_cfg_section_end: \ | ||
64 | mu_gocs_store (#capa, &__mu_common_cat2__(capa, _settings)); \ | ||
65 | } \ | ||
66 | return 0; \ | ||
67 | } | ||
68 | |||
69 | #define DCL_DEFAULT_CFG_CAPA(capa) \ | ||
70 | struct mu_cfg_capa __mu_common_cat3__(mu_,capa,_cfg_capa) = { \ | ||
71 | #capa, \ | ||
72 | __mu_common_cat3__(mu_,capa,_param), \ | ||
73 | __mu_common_cat3__(mu_,capa,_section_parser) \ | ||
74 | } | ||
75 | |||
76 | #define DCL_CFG_CAPA(capa) \ | ||
77 | DCL_PARSER (capa) \ | ||
78 | DCL_DEFAULT_CFG_CAPA (capa) | ||
79 | |||
80 | extern struct mu_cfg_capa mu_mailbox_cfg_capa; | ||
81 | extern struct mu_cfg_capa mu_locking_cfg_capa; | ||
82 | extern struct mu_cfg_capa mu_address_cfg_capa; | ||
83 | extern struct mu_cfg_capa mu_mailer_cfg_capa; | ||
84 | extern struct mu_cfg_capa mu_logging_cfg_capa; | ||
85 | extern struct mu_cfg_capa mu_gsasl_cfg_capa; | ||
86 | extern struct mu_cfg_capa mu_pam_cfg_capa; | ||
87 | extern struct mu_cfg_capa mu_radius_cfg_capa; | ||
88 | extern struct mu_cfg_capa mu_sql_cfg_capa; | ||
89 | extern struct mu_cfg_capa mu_tls_cfg_capa; | ||
90 | extern struct mu_cfg_capa mu_virtdomain_cfg_capa; | ||
91 |
libcfg/pam.c
0 → 100644
1 | /* This file is part of GNU Mailutils | ||
2 | Copyright (C) 2007 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 | This program 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 this program. If not, see <http://www.gnu.org/licenses/>. | ||
16 | */ | ||
17 | |||
18 | #include "libcfg.h" | ||
19 | |||
20 | static char *pam_settings; | ||
21 | |||
22 | static struct mu_cfg_param mu_pam_param[] = { | ||
23 | { "service", mu_cfg_string, &pam_settings }, | ||
24 | { NULL } | ||
25 | }; | ||
26 | |||
27 | DCL_CFG_CAPA (pam); | ||
28 |
libcfg/radius.c
0 → 100644
1 | /* This file is part of GNU Mailutils | ||
2 | Copyright (C) 2007 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 | This program 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 this program. If not, see <http://www.gnu.org/licenses/>. | ||
16 | */ | ||
17 | |||
18 | #include "libcfg.h" | ||
19 | #include <mailutils/radius.h> | ||
20 | |||
21 | static struct mu_radius_module_data radius_settings; | ||
22 | |||
23 | static struct mu_cfg_param mu_radius_param[] = { | ||
24 | { "auth-request", mu_cfg_string, &radius_settings.auth_request }, | ||
25 | { "getpwnam-request", mu_cfg_string, &radius_settings.getpwnam_request }, | ||
26 | { "getpwuid-request", mu_cfg_string, &radius_settings.getpwuid_request }, | ||
27 | { "directory", mu_cfg_string, &radius_settings.config_dir }, | ||
28 | { NULL } | ||
29 | }; | ||
30 | |||
31 | DCL_CFG_CAPA (radius); |
libcfg/sieve.c
0 → 100644
1 | /* This file is part of GNU Mailutils | ||
2 | Copyright (C) 2007 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 | This program 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 this program. If not, see <http://www.gnu.org/licenses/>. | ||
16 | */ | ||
17 | |||
18 | #include "libcfg.h" | ||
19 | #include <mailutils/libsieve.h> | ||
20 | |||
21 | static struct mu_gocs_sieve sieve_settings; | ||
22 | |||
23 | static int | ||
24 | cb_clear_library_path (mu_cfg_locus_t *locus, void *data, char *arg) | ||
25 | { | ||
26 | int flag; | ||
27 | if (mu_cfg_parse_boolean (arg, &flag)) | ||
28 | { | ||
29 | mu_error ("%s:%u: %s", locus->file, locus->line, _("not a boolean")); | ||
30 | return 1; | ||
31 | } | ||
32 | if (flag) | ||
33 | sieve_settings.clearflags |= MU_SIEVE_CLEAR_LIBRARY_PATH; | ||
34 | return 0; | ||
35 | } | ||
36 | |||
37 | static int | ||
38 | cb_clear_include_path (mu_cfg_locus_t *locus, void *data, char *arg) | ||
39 | { | ||
40 | int flag; | ||
41 | if (mu_cfg_parse_boolean (arg, &flag)) | ||
42 | { | ||
43 | mu_error ("%s:%u: %s", locus->file, locus->line, _("not a boolean")); | ||
44 | return 1; | ||
45 | } | ||
46 | if (flag) | ||
47 | sieve_settings.clearflags |= MU_SIEVE_CLEAR_INCLUDE_PATH; | ||
48 | return 0; | ||
49 | } | ||
50 | |||
51 | static void | ||
52 | destroy_string (void *str) | ||
53 | { | ||
54 | free (str); | ||
55 | } | ||
56 | |||
57 | static int | ||
58 | _add_path (mu_list_t *plist, mu_cfg_locus_t *locus, void *data, char *arg) | ||
59 | { | ||
60 | char *p; | ||
61 | |||
62 | if (!*plist) | ||
63 | { | ||
64 | int rc = mu_list_create (plist); | ||
65 | if (rc) | ||
66 | { | ||
67 | mu_error (_("cannot create list: %s"), mu_strerror (rc)); | ||
68 | exit (1); | ||
69 | } | ||
70 | mu_list_set_destroy_item (*plist, destroy_string); | ||
71 | } | ||
72 | for (p = strtok (arg, ":"); p; p = strtok (NULL, ":")) | ||
73 | mu_list_append (*plist, strdup (p)); | ||
74 | return 0; | ||
75 | } | ||
76 | |||
77 | static int | ||
78 | cb_include_path (mu_cfg_locus_t *locus, void *data, char *arg) | ||
79 | { | ||
80 | return _add_path (&sieve_settings.include_path, locus, data, arg); | ||
81 | } | ||
82 | |||
83 | static int | ||
84 | cb_library_path (mu_cfg_locus_t *locus, void *data, char *arg) | ||
85 | { | ||
86 | return _add_path (&sieve_settings.library_path, locus, data, arg); | ||
87 | } | ||
88 | |||
89 | static struct mu_cfg_param mu_sieve_param[] = { | ||
90 | { "clear-library-path", mu_cfg_callback, NULL, cb_clear_library_path }, | ||
91 | { "clear-include-path", mu_cfg_callback, NULL, cb_clear_include_path }, | ||
92 | { "library-path", mu_cfg_callback, NULL, cb_library_path }, | ||
93 | { "include-path", mu_cfg_callback, NULL, cb_include_path }, | ||
94 | { NULL } | ||
95 | }; | ||
96 | |||
97 | DCL_CFG_CAPA (sieve); |
libcfg/sql.c
0 → 100644
1 | /* This file is part of GNU Mailutils | ||
2 | Copyright (C) 2007 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 | This program 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 this program. If not, see <http://www.gnu.org/licenses/>. | ||
16 | */ | ||
17 | |||
18 | #include "libcfg.h" | ||
19 | #include <mailutils/sql.h> | ||
20 | #include <mailutils/mutil.h> | ||
21 | |||
22 | static struct mu_sql_module_config sql_settings; | ||
23 | |||
24 | |||
25 | |||
26 | /* Resource file configuration */ | ||
27 | static int | ||
28 | cb_password_type (mu_cfg_locus_t *locus, void *data, char *arg) | ||
29 | { | ||
30 | if (mu_sql_decode_password_type (arg, &sql_settings.password_type)) | ||
31 | mu_error (_("%s:%d: Unknown password type `%s'"), | ||
32 | locus->file, locus->line, arg); | ||
33 | return 0; | ||
34 | } | ||
35 | |||
36 | static int | ||
37 | cb_field_map (mu_cfg_locus_t *locus, void *data, char *arg) | ||
38 | { | ||
39 | int err; | ||
40 | int rc = mutil_parse_field_map (arg, &sql_settings.field_map, &err); | ||
41 | if (rc) | ||
42 | mu_error (_("%s:%d: Error near element %d: %s"), | ||
43 | locus->file, locus->line, err, mu_strerror (rc)); | ||
44 | return 0; | ||
45 | } | ||
46 | |||
47 | static struct mu_cfg_param mu_sql_param[] = { | ||
48 | { "interface", mu_cfg_string, &sql_settings.interface }, | ||
49 | { "getwpnam", mu_cfg_string, &sql_settings.getpwnam_query }, | ||
50 | { "getpwuid", mu_cfg_string, &sql_settings.getpwuid_query }, | ||
51 | { "getpass", mu_cfg_string, &sql_settings.getpass_query }, | ||
52 | { "host", mu_cfg_string, &sql_settings.host }, | ||
53 | { "user", mu_cfg_string, &sql_settings.user }, | ||
54 | { "passwd", mu_cfg_string, &sql_settings.passwd }, | ||
55 | { "db", mu_cfg_string, &sql_settings.db }, | ||
56 | { "port", mu_cfg_int, &sql_settings.port }, | ||
57 | { "password-type", mu_cfg_callback, NULL, cb_password_type }, | ||
58 | { "field-map", mu_cfg_callback, NULL, cb_field_map }, | ||
59 | { NULL } | ||
60 | }; | ||
61 | |||
62 | DCL_CFG_CAPA (sql); | ||
63 | |||
64 |
libcfg/tls.c
0 → 100644
1 | /* This file is part of GNU Mailutils | ||
2 | Copyright (C) 2007 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 | This program 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 this program. If not, see <http://www.gnu.org/licenses/>. | ||
16 | */ | ||
17 | |||
18 | #include "libcfg.h" | ||
19 | #include <mailutils/tls.h> | ||
20 | |||
21 | static struct mu_tls_module_config tls_settings; | ||
22 | |||
23 | static struct mu_cfg_param mu_tls_param[] = { | ||
24 | { "tls", mu_cfg_bool, &tls_settings.client_enable }, | ||
25 | { "ssl-cert", mu_cfg_string, &tls_settings.ssl_cert }, | ||
26 | { "ssl-key", mu_cfg_string, &tls_settings.ssl_key }, | ||
27 | { "ssl-cafile", mu_cfg_string, &tls_settings.ssl_cafile }, | ||
28 | { NULL } | ||
29 | }; | ||
30 | |||
31 | DCL_CFG_CAPA (tls); | ||
32 |
libcfg/virtdomain.c
0 → 100644
1 | /* This file is part of GNU Mailutils | ||
2 | Copyright (C) 2007 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 | This program 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 this program. If not, see <http://www.gnu.org/licenses/>. | ||
16 | */ | ||
17 | |||
18 | #include "libcfg.h" | ||
19 | |||
20 | static char *virtdomain_settings; | ||
21 | |||
22 | static struct mu_cfg_param mu_virtdomain_param[] = { | ||
23 | { "passwd-dir", mu_cfg_string, &virtdomain_settings }, | ||
24 | { NULL } | ||
25 | }; | ||
26 | |||
27 | DCL_CFG_CAPA (virtdomain); | ||
28 |
libsieve/conf.c
0 → 100644
1 | /* GNU Mailutils -- a suite of utilities for electronic mail | ||
2 | Copyright (C) 1999, 2000, 2001, 2002, 2005, | ||
3 | 2007 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, write to the | ||
17 | Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | ||
18 | Boston, MA 02110-1301 USA */ | ||
19 | |||
20 | #ifdef HAVE_CONFIG_H | ||
21 | # include <config.h> | ||
22 | #endif | ||
23 | #include <sieve.h> | ||
24 | #include <string.h> | ||
25 | |||
26 | mu_list_t mu_sieve_include_path = NULL; | ||
27 | mu_list_t mu_sieve_library_path = NULL; | ||
28 | |||
29 | static void | ||
30 | destroy_string (void *str) | ||
31 | { | ||
32 | free (str); | ||
33 | } | ||
34 | |||
35 | static int | ||
36 | _path_append (void *item, void *data) | ||
37 | { | ||
38 | mu_list_t *plist = data; | ||
39 | if (!*plist) | ||
40 | { | ||
41 | int rc = mu_list_create (plist); | ||
42 | if (rc) | ||
43 | { | ||
44 | mu_error (_("cannot create list: %s"), mu_strerror (rc)); | ||
45 | exit (1); | ||
46 | } | ||
47 | mu_list_set_destroy_item (*plist, destroy_string); | ||
48 | } | ||
49 | return mu_list_append (*plist, strdup (item)); | ||
50 | } | ||
51 | |||
52 | int | ||
53 | mu_sieve_module_init (void *data) | ||
54 | { | ||
55 | struct mu_gocs_sieve *p; | ||
56 | if (!data) | ||
57 | return 0; | ||
58 | p = data; | ||
59 | if (p->clearflags & MU_SIEVE_CLEAR_INCLUDE_PATH) | ||
60 | mu_list_destroy (&mu_sieve_include_path); | ||
61 | mu_list_do (p->include_path, _path_append, &mu_sieve_include_path); | ||
62 | if (p->clearflags & MU_SIEVE_CLEAR_LIBRARY_PATH) | ||
63 | mu_list_destroy (&mu_sieve_library_path); | ||
64 | mu_list_do (p->library_path, _path_append, &mu_sieve_library_path); | ||
65 | sieve_load_add_path (mu_sieve_library_path); | ||
66 | mu_list_destroy (&p->library_path); | ||
67 | mu_list_destroy (&p->include_path); | ||
68 | return 0; | ||
69 | } |
... | @@ -31,7 +31,7 @@ maidag_SOURCES=\ | ... | @@ -31,7 +31,7 @@ maidag_SOURCES=\ |
31 | maidag_LDADD = \ | 31 | maidag_LDADD = \ |
32 | @LIBMU_SCM@ @GUILE_LIBS@\ | 32 | @LIBMU_SCM@ @GUILE_LIBS@\ |
33 | @LIBMU_SCM_DEPS@\ | 33 | @LIBMU_SCM_DEPS@\ |
34 | ../lib/libmuaux.la \ | 34 | ${MU_APP_LIBRARIES}\ |
35 | ${MU_LIB_SIEVE}\ | 35 | ${MU_LIB_SIEVE}\ |
36 | ${MU_LIB_MBOX}\ | 36 | ${MU_LIB_MBOX}\ |
37 | ${MU_LIB_IMAP}\ | 37 | ${MU_LIB_IMAP}\ | ... | ... |
... | @@ -252,7 +252,7 @@ lmtp_reply (FILE *fp, char *code, char *enh, char *fmt, ...) | ... | @@ -252,7 +252,7 @@ lmtp_reply (FILE *fp, char *code, char *enh, char *fmt, ...) |
252 | vasprintf (&str, fmt, ap); | 252 | vasprintf (&str, fmt, ap); |
253 | va_end (ap); | 253 | va_end (ap); |
254 | 254 | ||
255 | if (daemon_param.transcript) | 255 | if (mu_gocs_daemon.transcript) |
256 | { | 256 | { |
257 | if (enh) | 257 | if (enh) |
258 | syslog (LOG_INFO, "LMTP reply: %s %s %s", code, enh, str); | 258 | syslog (LOG_INFO, "LMTP reply: %s %s %s", code, enh, str); |
... | @@ -737,7 +737,7 @@ lmtp_loop (FILE *in, FILE *out) | ... | @@ -737,7 +737,7 @@ lmtp_loop (FILE *in, FILE *out) |
737 | 737 | ||
738 | trimnl (buf); | 738 | trimnl (buf); |
739 | 739 | ||
740 | if (daemon_param.transcript) | 740 | if (mu_gocs_daemon.transcript) |
741 | syslog (LOG_INFO, "LMTP recieve: %s", buf); | 741 | syslog (LOG_INFO, "LMTP recieve: %s", buf); |
742 | 742 | ||
743 | if (next_state != state_none) | 743 | if (next_state != state_none) |
... | @@ -784,7 +784,7 @@ lmtp_daemon (char *urlstr) | ... | @@ -784,7 +784,7 @@ lmtp_daemon (char *urlstr) |
784 | socklen_t addrlen; | 784 | socklen_t addrlen; |
785 | pid_t pid; | 785 | pid_t pid; |
786 | 786 | ||
787 | if (daemon_param.mode == MODE_DAEMON) | 787 | if (mu_gocs_daemon.mode == MODE_DAEMON) |
788 | { | 788 | { |
789 | if (daemon (0, 0) < 0) | 789 | if (daemon (0, 0) < 0) |
790 | { | 790 | { |
... | @@ -819,7 +819,7 @@ lmtp_daemon (char *urlstr) | ... | @@ -819,7 +819,7 @@ lmtp_daemon (char *urlstr) |
819 | for (;;) | 819 | for (;;) |
820 | { | 820 | { |
821 | process_cleanup (); | 821 | process_cleanup (); |
822 | if (children > daemon_param.maxchildren) | 822 | if (children > mu_gocs_daemon.maxchildren) |
823 | { | 823 | { |
824 | mu_error (_("too many children (%lu)"), | 824 | mu_error (_("too many children (%lu)"), |
825 | (unsigned long) children); | 825 | (unsigned long) children); |
... | @@ -879,11 +879,11 @@ maidag_lmtp_server () | ... | @@ -879,11 +879,11 @@ maidag_lmtp_server () |
879 | 879 | ||
880 | if (lmtp_url_string) | 880 | if (lmtp_url_string) |
881 | return lmtp_daemon (lmtp_url_string); | 881 | return lmtp_daemon (lmtp_url_string); |
882 | else if (daemon_param.mode == MODE_INTERACTIVE) | 882 | else if (mu_gocs_daemon.mode == MODE_INTERACTIVE) |
883 | return lmtp_loop (stdin, stdout); | 883 | return lmtp_loop (stdin, stdout); |
884 | else | 884 | else |
885 | { | 885 | { |
886 | const char *pstr = mu_umaxtostr (0, daemon_param.port); | 886 | const char *pstr = mu_umaxtostr (0, mu_gocs_daemon.port); |
887 | char *urls = malloc (sizeof (DEFAULT_URL) + strlen (pstr)); | 887 | char *urls = malloc (sizeof (DEFAULT_URL) + strlen (pstr)); |
888 | if (!urls) | 888 | if (!urls) |
889 | { | 889 | { | ... | ... |
... | @@ -50,7 +50,7 @@ char *lmtp_url_string; | ... | @@ -50,7 +50,7 @@ char *lmtp_url_string; |
50 | int reuse_lmtp_address = 1; | 50 | int reuse_lmtp_address = 1; |
51 | char *lmtp_group = "mail"; | 51 | char *lmtp_group = "mail"; |
52 | 52 | ||
53 | struct daemon_param daemon_param = { | 53 | struct mu_gocs_daemon daemon_param = { |
54 | MODE_INTERACTIVE, /* Start in interactive (inetd) mode */ | 54 | MODE_INTERACTIVE, /* Start in interactive (inetd) mode */ |
55 | 20, /* Default maximum number of children */ | 55 | 20, /* Default maximum number of children */ |
56 | 0, /* No standard port */ | 56 | 0, /* No standard port */ |
... | @@ -111,7 +111,7 @@ static struct argp argp = { | ... | @@ -111,7 +111,7 @@ static struct argp argp = { |
111 | NULL, NULL | 111 | NULL, NULL |
112 | }; | 112 | }; |
113 | 113 | ||
114 | static const char *argp_capa[] = { | 114 | static const char *maidag_argp_capa[] = { |
115 | "daemon", | 115 | "daemon", |
116 | "auth", | 116 | "auth", |
117 | "common", | 117 | "common", |
... | @@ -119,7 +119,6 @@ static const char *argp_capa[] = { | ... | @@ -119,7 +119,6 @@ static const char *argp_capa[] = { |
119 | "logging", | 119 | "logging", |
120 | "mailbox", | 120 | "mailbox", |
121 | "mailer", | 121 | "mailer", |
122 | "sieve", | ||
123 | NULL | 122 | NULL |
124 | }; | 123 | }; |
125 | 124 | ||
... | @@ -255,10 +254,10 @@ struct mu_cfg_param maidag_cfg_param[] = { | ... | @@ -255,10 +254,10 @@ struct mu_cfg_param maidag_cfg_param[] = { |
255 | #ifdef USE_SQL | 254 | #ifdef USE_SQL |
256 | { "quota-query", mu_cfg_string, "a_query }, | 255 | { "quota-query", mu_cfg_string, "a_query }, |
257 | #endif | 256 | #endif |
258 | { "sieve", mu_cfg_string, &sieve_pattern }, | 257 | { "sieve-filter", mu_cfg_string, &sieve_pattern }, |
259 | { "message-id-header", mu_cfg_string, &message_id_header }, | 258 | { "message-id-header", mu_cfg_string, &message_id_header }, |
260 | #ifdef WITH_GUILE | 259 | #ifdef WITH_GUILE |
261 | { "source", mu_cfg_string, &progfile_pattern }, | 260 | { "guile-filter", mu_cfg_string, &progfile_pattern }, |
262 | #endif | 261 | #endif |
263 | { "debug", mu_cfg_callback, NULL, cb_debug }, | 262 | { "debug", mu_cfg_callback, NULL, cb_debug }, |
264 | { "stderr", mu_cfg_bool, &log_to_stderr }, | 263 | { "stderr", mu_cfg_bool, &log_to_stderr }, |
... | @@ -461,8 +460,6 @@ main (int argc, char *argv[]) | ... | @@ -461,8 +460,6 @@ main (int argc, char *argv[]) |
461 | mu_locker_set_default_retry_timeout (1); | 460 | mu_locker_set_default_retry_timeout (1); |
462 | mu_locker_set_default_retry_count (300); | 461 | mu_locker_set_default_retry_count (300); |
463 | 462 | ||
464 | /* Default error code for command line errors */ | ||
465 | mu_argp_error_code = EX_CONFIG; | ||
466 | /* Register needed modules */ | 463 | /* Register needed modules */ |
467 | MU_AUTH_REGISTER_ALL_MODULES (); | 464 | MU_AUTH_REGISTER_ALL_MODULES (); |
468 | 465 | ||
... | @@ -473,12 +470,13 @@ main (int argc, char *argv[]) | ... | @@ -473,12 +470,13 @@ main (int argc, char *argv[]) |
473 | mu_registrar_record (mu_sendmail_record); | 470 | mu_registrar_record (mu_sendmail_record); |
474 | mu_registrar_record (mu_smtp_record); | 471 | mu_registrar_record (mu_smtp_record); |
475 | 472 | ||
476 | mu_argp_init (program_version, NULL); | 473 | mu_gocs_register ("sieve", mu_sieve_module_init); |
477 | mu_sieve_argp_init (); | ||
478 | 474 | ||
479 | /* Parse command line */ | 475 | /* Parse command line */ |
480 | mu_argp_set_config_param (maidag_cfg_param); | 476 | mu_argp_init (program_version, NULL); |
481 | mu_argp_parse (&argp, &argc, &argv, 0, argp_capa, &arg_index, &daemon_param); | 477 | if (mu_app_init (&argp, maidag_argp_capa, maidag_cfg_param, |
478 | argc, argv, 0, &arg_index, NULL)) | ||
479 | exit (EX_CONFIG); | ||
482 | 480 | ||
483 | current_uid = getuid (); | 481 | current_uid = getuid (); |
484 | 482 | ... | ... |
... | @@ -82,6 +82,7 @@ | ... | @@ -82,6 +82,7 @@ |
82 | #include <mailutils/mu_auth.h> | 82 | #include <mailutils/mu_auth.h> |
83 | #include <mailutils/libsieve.h> | 83 | #include <mailutils/libsieve.h> |
84 | #include <mailutils/nls.h> | 84 | #include <mailutils/nls.h> |
85 | #include <mailutils/daemon.h> | ||
85 | 86 | ||
86 | #include <mu_dbm.h> | 87 | #include <mu_dbm.h> |
87 | #include <mu_asprintf.h> | 88 | #include <mu_asprintf.h> |
... | @@ -91,7 +92,8 @@ | ... | @@ -91,7 +92,8 @@ |
91 | # define USE_MAILBOX_QUOTAS 1 | 92 | # define USE_MAILBOX_QUOTAS 1 |
92 | #endif | 93 | #endif |
93 | 94 | ||
94 | #include <mailutils/argp.h> | 95 | #include "muinit.h" |
96 | |||
95 | /* Debug */ | 97 | /* Debug */ |
96 | extern int debug_level; | 98 | extern int debug_level; |
97 | #define dbg() if (debug_level) debug | 99 | #define dbg() if (debug_level) debug |
... | @@ -120,7 +122,6 @@ extern int lmtp_mode; | ... | @@ -120,7 +122,6 @@ extern int lmtp_mode; |
120 | extern char *lmtp_url_string; | 122 | extern char *lmtp_url_string; |
121 | extern int reuse_lmtp_address; | 123 | extern int reuse_lmtp_address; |
122 | extern char *lmtp_group; | 124 | extern char *lmtp_group; |
123 | extern struct daemon_param daemon_param; | ||
124 | 125 | ||
125 | void close_fds (void); | 126 | void close_fds (void); |
126 | int switch_user_id (struct mu_auth_data *auth, int user); | 127 | int switch_user_id (struct mu_auth_data *auth, int user); | ... | ... |
... | @@ -162,12 +162,12 @@ sql_retrieve_quota (char *name, mu_off_t *quota) | ... | @@ -162,12 +162,12 @@ sql_retrieve_quota (char *name, mu_off_t *quota) |
162 | return RETR_FAILURE; | 162 | return RETR_FAILURE; |
163 | 163 | ||
164 | status = mu_sql_connection_init (&conn, | 164 | status = mu_sql_connection_init (&conn, |
165 | sql_interface, | 165 | mu_sql_module_config.interface, |
166 | mu_sql_host, | 166 | mu_sql_module_config.host, |
167 | mu_sql_port, | 167 | mu_sql_module_config.port, |
168 | mu_sql_user, | 168 | mu_sql_module_config.user, |
169 | mu_sql_passwd, | 169 | mu_sql_module_config.passwd, |
170 | mu_sql_db); | 170 | mu_sql_module_config.db); |
171 | 171 | ||
172 | if (status) | 172 | if (status) |
173 | { | 173 | { | ... | ... |
... | @@ -26,7 +26,7 @@ mail_local_SOURCES = main.c mailquota.c script.c mail.local.h | ... | @@ -26,7 +26,7 @@ mail_local_SOURCES = main.c mailquota.c script.c mail.local.h |
26 | mail_local_LDADD = \ | 26 | mail_local_LDADD = \ |
27 | @LIBMU_SCM@ @GUILE_LIBS@\ | 27 | @LIBMU_SCM@ @GUILE_LIBS@\ |
28 | @LIBMU_SCM_DEPS@\ | 28 | @LIBMU_SCM_DEPS@\ |
29 | ../lib/libmuaux.la \ | 29 | ${MU_APP_LIBRARIES}\ |
30 | ${MU_LIB_SIEVE}\ | 30 | ${MU_LIB_SIEVE}\ |
31 | ${MU_LIB_MBOX}\ | 31 | ${MU_LIB_MBOX}\ |
32 | ${MU_LIB_IMAP}\ | 32 | ${MU_LIB_IMAP}\ | ... | ... |
... | @@ -92,7 +92,6 @@ | ... | @@ -92,7 +92,6 @@ |
92 | # define USE_MAILBOX_QUOTAS 1 | 92 | # define USE_MAILBOX_QUOTAS 1 |
93 | #endif | 93 | #endif |
94 | 94 | ||
95 | #include <mailutils/argp.h> | ||
96 | /* Debug */ | 95 | /* Debug */ |
97 | extern int debug_level; | 96 | extern int debug_level; |
98 | #define dbg() if (debug_level) debug | 97 | #define dbg() if (debug_level) debug | ... | ... |
... | @@ -162,12 +162,12 @@ sql_retrieve_quota (char *name, mu_off_t *quota) | ... | @@ -162,12 +162,12 @@ sql_retrieve_quota (char *name, mu_off_t *quota) |
162 | return RETR_FAILURE; | 162 | return RETR_FAILURE; |
163 | 163 | ||
164 | status = mu_sql_connection_init (&conn, | 164 | status = mu_sql_connection_init (&conn, |
165 | sql_interface, | 165 | mu_sql_module_config.interface, |
166 | mu_sql_host, | 166 | mu_sql_module_config.host, |
167 | mu_sql_port, | 167 | mu_sql_module_config.port, |
168 | mu_sql_user, | 168 | mu_sql_module_config.user, |
169 | mu_sql_passwd, | 169 | mu_sql_module_config.passwd, |
170 | mu_sql_db); | 170 | mu_sql_module_config.db); |
171 | 171 | ||
172 | if (status) | 172 | if (status) |
173 | { | 173 | { | ... | ... |
... | @@ -18,6 +18,7 @@ | ... | @@ -18,6 +18,7 @@ |
18 | MA 02110-1301 USA */ | 18 | MA 02110-1301 USA */ |
19 | 19 | ||
20 | #include <mail.local.h> | 20 | #include <mail.local.h> |
21 | #include "muinit.h" | ||
21 | 22 | ||
22 | int multiple_delivery; /* Don't return errors when delivering to multiple | 23 | int multiple_delivery; /* Don't return errors when delivering to multiple |
23 | recipients */ | 24 | recipients */ |
... | @@ -117,7 +118,6 @@ static const char *argp_capa[] = { | ... | @@ -117,7 +118,6 @@ static const char *argp_capa[] = { |
117 | "logging", | 118 | "logging", |
118 | "mailbox", | 119 | "mailbox", |
119 | "mailer", | 120 | "mailer", |
120 | "sieve", | ||
121 | NULL | 121 | NULL |
122 | }; | 122 | }; |
123 | 123 | ||
... | @@ -365,15 +365,14 @@ main (int argc, char *argv[]) | ... | @@ -365,15 +365,14 @@ main (int argc, char *argv[]) |
365 | mu_locker_set_default_retry_timeout (1); | 365 | mu_locker_set_default_retry_timeout (1); |
366 | mu_locker_set_default_retry_count (300); | 366 | mu_locker_set_default_retry_count (300); |
367 | 367 | ||
368 | /* Default error code for command line errors */ | ||
369 | mu_argp_error_code = EX_CONFIG; | ||
370 | /* Register needed modules */ | 368 | /* Register needed modules */ |
371 | MU_AUTH_REGISTER_ALL_MODULES(); | 369 | MU_AUTH_REGISTER_ALL_MODULES(); |
372 | mu_argp_init (program_version, NULL); | ||
373 | mu_sieve_argp_init (); | ||
374 | /* Parse command line */ | 370 | /* Parse command line */ |
375 | mu_argp_set_config_param (mail_local_cfg_param); | 371 | mu_gocs_register ("sieve", mu_sieve_module_init); |
376 | mu_argp_parse (&argp, &argc, &argv, 0, argp_capa, &arg_index, NULL); | 372 | mu_argp_init (program_version, NULL); |
373 | if (mu_app_init (&argp, argp_capa, mail_local_cfg_param, | ||
374 | argc, argv, 0, &arg_index, NULL)) | ||
375 | exit (EX_CONFIG); | ||
377 | 376 | ||
378 | uid = getuid (); | 377 | uid = getuid (); |
379 | 378 | ... | ... |
... | @@ -27,7 +27,7 @@ libexec_PROGRAMS = @BUILD_SMTP_PROGRAMS@ | ... | @@ -27,7 +27,7 @@ libexec_PROGRAMS = @BUILD_SMTP_PROGRAMS@ |
27 | mail_remote_SOURCES = mail.remote.c | 27 | mail_remote_SOURCES = mail.remote.c |
28 | 28 | ||
29 | mail_remote_LDADD = \ | 29 | mail_remote_LDADD = \ |
30 | ../lib/libmuaux.la\ | 30 | ${MU_APP_LIBRARIES}\ |
31 | ${MU_LIB_AUTH}\ | 31 | ${MU_LIB_AUTH}\ |
32 | ${MU_LIB_MAILER}\ | 32 | ${MU_LIB_MAILER}\ |
33 | @MU_AUTHLIBS@\ | 33 | @MU_AUTHLIBS@\ | ... | ... |
... | @@ -31,7 +31,6 @@ | ... | @@ -31,7 +31,6 @@ |
31 | #include <unistd.h> | 31 | #include <unistd.h> |
32 | 32 | ||
33 | #include <mailutils/address.h> | 33 | #include <mailutils/address.h> |
34 | #include <mailutils/argp.h> | ||
35 | #include <mailutils/debug.h> | 34 | #include <mailutils/debug.h> |
36 | #include <mailutils/errno.h> | 35 | #include <mailutils/errno.h> |
37 | #include <mailutils/list.h> | 36 | #include <mailutils/list.h> |
... | @@ -44,6 +43,7 @@ | ... | @@ -44,6 +43,7 @@ |
44 | #include <mailutils/error.h> | 43 | #include <mailutils/error.h> |
45 | #include <mailutils/nls.h> | 44 | #include <mailutils/nls.h> |
46 | #include <mailutils/mu_auth.h> | 45 | #include <mailutils/mu_auth.h> |
46 | #include "muinit.h" | ||
47 | 47 | ||
48 | const char *program_version = "mail.remote (" PACKAGE_STRING ")"; | 48 | const char *program_version = "mail.remote (" PACKAGE_STRING ")"; |
49 | static char doc[] = | 49 | static char doc[] = |
... | @@ -171,8 +171,9 @@ main (int argc, char **argv) | ... | @@ -171,8 +171,9 @@ main (int argc, char **argv) |
171 | 171 | ||
172 | MU_AUTH_REGISTER_ALL_MODULES(); | 172 | MU_AUTH_REGISTER_ALL_MODULES(); |
173 | mu_argp_init (program_version, NULL); | 173 | mu_argp_init (program_version, NULL); |
174 | mu_argp_set_config_param (mail_remote_cfg_param); | 174 | if (mu_app_init (&argp, capa, mail_remote_cfg_param, |
175 | mu_argp_parse (&argp, &argc, &argv, 0, capa, &optind, NULL); | 175 | argc, argv, 0, &optind, NULL)) |
176 | exit (1); | ||
176 | 177 | ||
177 | if (optfrom) | 178 | if (optfrom) |
178 | { | 179 | { | ... | ... |
... | @@ -24,7 +24,7 @@ AM_CFLAGS = -DSITE_MAIL_RC=\"@SITE_MAIL_RC@\" | ... | @@ -24,7 +24,7 @@ AM_CFLAGS = -DSITE_MAIL_RC=\"@SITE_MAIL_RC@\" |
24 | bin_PROGRAMS = mail | 24 | bin_PROGRAMS = mail |
25 | 25 | ||
26 | mail_LDADD = \ | 26 | mail_LDADD = \ |
27 | ../lib/libmuaux.la\ | 27 | ${MU_APP_LIBRARIES}\ |
28 | ${MU_LIB_MBOX}\ | 28 | ${MU_LIB_MBOX}\ |
29 | ${MU_LIB_IMAP}\ | 29 | ${MU_LIB_IMAP}\ |
30 | ${MU_LIB_POP}\ | 30 | ${MU_LIB_POP}\ | ... | ... |
... | @@ -18,6 +18,7 @@ | ... | @@ -18,6 +18,7 @@ |
18 | MA 02110-1301 USA */ | 18 | MA 02110-1301 USA */ |
19 | 19 | ||
20 | #include "mail.h" | 20 | #include "mail.h" |
21 | #include "muinit.h" | ||
21 | 22 | ||
22 | /* Global variables and constants*/ | 23 | /* Global variables and constants*/ |
23 | mu_mailbox_t mbox; /* Mailbox being operated upon */ | 24 | mu_mailbox_t mbox; /* Mailbox being operated upon */ |
... | @@ -178,9 +179,6 @@ static const char *mail_capa[] = { | ... | @@ -178,9 +179,6 @@ static const char *mail_capa[] = { |
178 | "common", | 179 | "common", |
179 | "license", | 180 | "license", |
180 | "mailbox", | 181 | "mailbox", |
181 | #ifdef WITH_TLS | ||
182 | "tls", | ||
183 | #endif | ||
184 | NULL | 182 | NULL |
185 | }; | 183 | }; |
186 | 184 | ||
... | @@ -353,12 +351,12 @@ main (int argc, char **argv) | ... | @@ -353,12 +351,12 @@ main (int argc, char **argv) |
353 | args.send_mode = 0; | 351 | args.send_mode = 0; |
354 | 352 | ||
355 | /* argument parsing */ | 353 | /* argument parsing */ |
356 | |||
357 | mu_argp_init (program_version, NULL); | ||
358 | #ifdef WITH_TLS | 354 | #ifdef WITH_TLS |
359 | mu_tls_init_client_argp (); | 355 | mu_gocs_register ("tls", mu_tls_module_init); |
360 | #endif | 356 | #endif |
361 | mu_argp_parse (&argp, &argc, &argv, 0, mail_capa, NULL, &args); | 357 | mu_argp_init (program_version, NULL); |
358 | if (mu_app_init (&argp, mail_capa, NULL, argc, argv, 0, NULL, &args)) | ||
359 | exit (1); | ||
362 | 360 | ||
363 | /* read system-wide mail.rc and user's .mailrc */ | 361 | /* read system-wide mail.rc and user's .mailrc */ |
364 | if (util_getenv (NULL, "rc", Mail_env_boolean, 0) == 0) | 362 | if (util_getenv (NULL, "rc", Mail_env_boolean, 0) == 0) | ... | ... |
... | @@ -61,7 +61,6 @@ | ... | @@ -61,7 +61,6 @@ |
61 | #endif | 61 | #endif |
62 | 62 | ||
63 | #include <mailutils/address.h> | 63 | #include <mailutils/address.h> |
64 | #include <mailutils/argp.h> | ||
65 | #include <mailutils/assoc.h> | 64 | #include <mailutils/assoc.h> |
66 | #include <mailutils/attribute.h> | 65 | #include <mailutils/attribute.h> |
67 | #include <mailutils/body.h> | 66 | #include <mailutils/body.h> |
... | @@ -179,6 +178,7 @@ extern mu_mailbox_t mbox; | ... | @@ -179,6 +178,7 @@ extern mu_mailbox_t mbox; |
179 | extern size_t total; | 178 | extern size_t total; |
180 | extern FILE *ofile; | 179 | extern FILE *ofile; |
181 | extern int interactive; | 180 | extern int interactive; |
181 | extern const char *program_version; | ||
182 | 182 | ||
183 | /* Functions */ | 183 | /* Functions */ |
184 | extern int mail_alias (int argc, char **argv); | 184 | extern int mail_alias (int argc, char **argv); | ... | ... |
... | @@ -514,7 +514,7 @@ mail_send0 (compose_env_t * env, int save_to) | ... | @@ -514,7 +514,7 @@ mail_send0 (compose_env_t * env, int save_to) |
514 | /* Prepare the header */ | 514 | /* Prepare the header */ |
515 | if (util_getenv (NULL, "xmailer", Mail_env_boolean, 0) == 0) | 515 | if (util_getenv (NULL, "xmailer", Mail_env_boolean, 0) == 0) |
516 | mu_header_set_value (env->header, MU_HEADER_X_MAILER, | 516 | mu_header_set_value (env->header, MU_HEADER_X_MAILER, |
517 | argp_program_version, 1); | 517 | program_version, 1); |
518 | 518 | ||
519 | if (util_header_expand (&env->header) == 0) | 519 | if (util_header_expand (&env->header) == 0) |
520 | { | 520 | { | ... | ... |
... | @@ -40,7 +40,7 @@ static const char *with_defs[] = | ... | @@ -40,7 +40,7 @@ static const char *with_defs[] = |
40 | int | 40 | int |
41 | mail_version (int argc MU_ARG_UNUSED, char **argv MU_ARG_UNUSED) | 41 | mail_version (int argc MU_ARG_UNUSED, char **argv MU_ARG_UNUSED) |
42 | { | 42 | { |
43 | fprintf (ofile, "%s", argp_program_version); | 43 | fprintf (ofile, "%s", program_version); |
44 | if (with_defs[0] != NULL) | 44 | if (with_defs[0] != NULL) |
45 | { | 45 | { |
46 | int i; | 46 | int i; | ... | ... |
... | @@ -35,64 +35,65 @@ AM_CPPFLAGS = \ | ... | @@ -35,64 +35,65 @@ AM_CPPFLAGS = \ |
35 | EXTRA_DIST = @MU_EXTRA_DIST@ errors muerrno.cin parsedate.y fgetpwent.c cfg_parser.y cfg_parser.h | 35 | EXTRA_DIST = @MU_EXTRA_DIST@ errors muerrno.cin parsedate.y fgetpwent.c cfg_parser.y cfg_parser.h |
36 | 36 | ||
37 | libmailutils_la_SOURCES = \ | 37 | libmailutils_la_SOURCES = \ |
38 | address.c \ | 38 | address.c\ |
39 | amd.c \ | 39 | amd.c\ |
40 | argcv.c \ | 40 | argcv.c\ |
41 | assoc.c \ | 41 | assoc.c\ |
42 | attachment.c \ | 42 | attachment.c\ |
43 | attribute.c \ | 43 | attribute.c\ |
44 | auth.c \ | 44 | auth.c\ |
45 | body.c \ | 45 | body.c\ |
46 | daemon.c \ | 46 | daemon.c\ |
47 | date.c \ | 47 | date.c\ |
48 | debug.c \ | 48 | debug.c\ |
49 | cfg_lexer.c \ | 49 | cfg_lexer.c\ |
50 | cfg_parser.c \ | 50 | cfg_parser.c\ |
51 | envelope.c \ | 51 | envelope.c\ |
52 | file_stream.c \ | 52 | file_stream.c\ |
53 | filter.c \ | 53 | filter.c\ |
54 | filter_iconv.c \ | 54 | filter_iconv.c\ |
55 | filter_rfc822.c \ | 55 | filter_rfc822.c\ |
56 | filter_trans.c \ | 56 | filter_trans.c\ |
57 | folder.c \ | 57 | folder.c\ |
58 | header.c \ | 58 | gocs.c\ |
59 | iterator.c \ | 59 | header.c\ |
60 | list.c \ | 60 | iterator.c\ |
61 | locale.c \ | 61 | list.c\ |
62 | locker.c \ | 62 | locale.c\ |
63 | mailbox.c \ | 63 | locker.c\ |
64 | mailcap.c \ | 64 | mailbox.c\ |
65 | mailer.c \ | 65 | mailcap.c\ |
66 | mapfile_stream.c \ | 66 | mailer.c\ |
67 | mbx_default.c \ | 67 | mapfile_stream.c\ |
68 | message.c \ | 68 | mbx_default.c\ |
69 | memory_stream.c \ | 69 | message.c\ |
70 | message_stream.c \ | 70 | memory_stream.c\ |
71 | mime.c \ | 71 | message_stream.c\ |
72 | monitor.c \ | 72 | mime.c\ |
73 | mu_argp.c \ | 73 | monitor.c\ |
74 | mu_auth.c \ | 74 | mu_auth.c\ |
75 | mu_umaxtostr.h \ | 75 | mu_umaxtostr.h\ |
76 | mu_umaxtostr.c \ | 76 | mu_umaxtostr.c\ |
77 | munre.c \ | 77 | munre.c\ |
78 | mutil.c \ | 78 | mutil.c\ |
79 | muerror.c \ | 79 | muerror.c\ |
80 | muerrno.c \ | 80 | muerrno.c\ |
81 | nls.c \ | 81 | nls.c\ |
82 | observer.c \ | 82 | observer.c\ |
83 | parse822.c \ | 83 | parse822.c\ |
84 | parsedate.c \ | 84 | parsedate.c\ |
85 | property.c \ | 85 | property.c\ |
86 | registrar.c \ | 86 | registrar.c\ |
87 | refcount.c \ | 87 | refcount.c\ |
88 | rfc2047.c \ | 88 | rfc2047.c\ |
89 | socket_stream.c \ | 89 | socket_stream.c\ |
90 | stream.c \ | 90 | stream.c\ |
91 | system.c \ | 91 | syslog.c\ |
92 | tcp.c \ | 92 | system.c\ |
93 | ticket.c \ | 93 | tcp.c\ |
94 | url.c \ | 94 | ticket.c\ |
95 | wicket.c | 95 | url.c\ |
96 | wicket.c | ||
96 | 97 | ||
97 | BUILT_SOURCES = parsedate.c muerrno.c cfg_parser.c cfg_parser.h | 98 | BUILT_SOURCES = parsedate.c muerrno.c cfg_parser.c cfg_parser.h |
98 | MOSTLYCLEANFILES= | 99 | MOSTLYCLEANFILES= | ... | ... |
... | @@ -806,22 +806,30 @@ parse_cidr (struct scan_tree_data *sdata, const mu_cfg_node_t *node, | ... | @@ -806,22 +806,30 @@ parse_cidr (struct scan_tree_data *sdata, const mu_cfg_node_t *node, |
806 | return 0; | 806 | return 0; |
807 | } | 807 | } |
808 | 808 | ||
809 | static int | 809 | int |
810 | parse_bool (struct scan_tree_data *sdata, const mu_cfg_node_t *node, int *res) | 810 | mu_cfg_parse_boolean (const char *str, int *res) |
811 | { | 811 | { |
812 | if (strcmp (node->tag_label, "yes") == 0 | 812 | if (strcmp (str, "yes") == 0 |
813 | || strcmp (node->tag_label, "on") == 0 | 813 | || strcmp (str, "on") == 0 |
814 | || strcmp (node->tag_label, "t") == 0 | 814 | || strcmp (str, "t") == 0 |
815 | || strcmp (node->tag_label, "true") == 0 | 815 | || strcmp (str, "true") == 0 |
816 | || strcmp (node->tag_label, "1") == 0) | 816 | || strcmp (str, "1") == 0) |
817 | *res = 1; | 817 | *res = 1; |
818 | else if (strcmp (node->tag_label, "no") == 0 | 818 | else if (strcmp (str, "no") == 0 |
819 | || strcmp (node->tag_label, "off") == 0 | 819 | || strcmp (str, "off") == 0 |
820 | || strcmp (node->tag_label, "nil") == 0 | 820 | || strcmp (str, "nil") == 0 |
821 | || strcmp (node->tag_label, "false") == 0 | 821 | || strcmp (str, "false") == 0 |
822 | || strcmp (node->tag_label, "0") == 0) | 822 | || strcmp (str, "0") == 0) |
823 | *res = 0; | 823 | *res = 0; |
824 | else | 824 | else |
825 | return 1; | ||
826 | return 0; | ||
827 | } | ||
828 | |||
829 | static int | ||
830 | parse_bool (struct scan_tree_data *sdata, const mu_cfg_node_t *node, int *res) | ||
831 | { | ||
832 | if (mu_cfg_parse_boolean (node->tag_label, res)) | ||
825 | { | 833 | { |
826 | mu_cfg_perror (sdata->call_data, &node->locus, _("not a boolean")); | 834 | mu_cfg_perror (sdata->call_data, &node->locus, _("not a boolean")); |
827 | return 1; | 835 | return 1; | ... | ... |
... | @@ -77,3 +77,24 @@ mu_daemon_remove_pidfile (void) | ... | @@ -77,3 +77,24 @@ mu_daemon_remove_pidfile (void) |
77 | } | 77 | } |
78 | } | 78 | } |
79 | 79 | ||
80 | |||
81 | struct mu_gocs_daemon mu_gocs_daemon; | ||
82 | |||
83 | int | ||
84 | mu_gocs_daemon_init (void *data) | ||
85 | { | ||
86 | if (data) | ||
87 | { | ||
88 | struct mu_gocs_daemon *cfg = data; | ||
89 | mu_gocs_daemon = *cfg; | ||
90 | |||
91 | if (mu_gocs_daemon.maxchildren) | ||
92 | mu_gocs_daemon.mode = MODE_DAEMON; | ||
93 | |||
94 | if (mu_gocs_daemon.pidfile) | ||
95 | mu_gocs_daemon.mode = MODE_DAEMON; | ||
96 | } | ||
97 | return 0; | ||
98 | } | ||
99 | |||
100 | ... | ... |
mailbox/mu_argp.c
deleted
100644 → 0
1 | /* GNU Mailutils -- a suite of utilities for electronic mail | ||
2 | Copyright (C) 1999, 2001, 2002, 2003, 2004, 2005, 2006, | ||
3 | 2007 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, write to the | ||
17 | Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | ||
18 | Boston, MA 02110-1301 USA */ | ||
19 | |||
20 | #ifdef HAVE_CONFIG_H | ||
21 | # include <config.h> | ||
22 | #endif | ||
23 | |||
24 | #include <getline.h> | ||
25 | #include <pwd.h> | ||
26 | #include <stdio.h> | ||
27 | #include <stdlib.h> | ||
28 | #include <string.h> | ||
29 | #include <syslog.h> | ||
30 | #include <unistd.h> | ||
31 | |||
32 | #include <sys/types.h> | ||
33 | #include <sys/stat.h> | ||
34 | |||
35 | #ifdef HAVE_STRINGS_H | ||
36 | # include <strings.h> | ||
37 | #endif | ||
38 | |||
39 | #include <mailutils/argp.h> | ||
40 | #include <mailutils/error.h> | ||
41 | #include <mailutils/errno.h> | ||
42 | #include <mailutils/mutil.h> | ||
43 | #include <mailutils/locker.h> | ||
44 | #include <mailutils/mailer.h> | ||
45 | #include <mailutils/mailbox.h> | ||
46 | #include <mailutils/nls.h> | ||
47 | #include <mailutils/argcv.h> | ||
48 | #include <mailutils/cfg.h> | ||
49 | |||
50 | |||
51 | /* ************************************************************************* */ | ||
52 | /* Variables and auxiliary functions. */ | ||
53 | /* FIXME: The variables should be global. */ | ||
54 | /* ************************************************************************* */ | ||
55 | |||
56 | static char *mail_spool_option; | ||
57 | static char *mailbox_type_option; | ||
58 | static char *lock_flags_option; | ||
59 | static unsigned long lock_retry_timeout_option; | ||
60 | static unsigned long lock_retry_count_option; | ||
61 | static unsigned long lock_expire_timeout_option; | ||
62 | static char *external_locker_option; | ||
63 | |||
64 | static char *email_addr_option; | ||
65 | static char *email_domain_option; | ||
66 | |||
67 | static char *mailer_option; | ||
68 | |||
69 | static char *log_facility_option; | ||
70 | |||
71 | static unsigned int daemon_max_children_option; | ||
72 | static char *daemon_mode_option; | ||
73 | static unsigned int daemon_transcript_option; | ||
74 | static char *daemon_pidfile_option; | ||
75 | static unsigned short daemon_port_option; | ||
76 | static unsigned int daemon_timeout_option; | ||
77 | |||
78 | int log_facility = LOG_FACILITY; | ||
79 | int mu_argp_error_code = 1; | ||
80 | |||
81 | static int | ||
82 | parse_log_facility (const char *str) | ||
83 | { | ||
84 | int i; | ||
85 | static struct { | ||
86 | char *name; | ||
87 | int facility; | ||
88 | } syslog_kw[] = { | ||
89 | { "USER", LOG_USER }, | ||
90 | { "DAEMON", LOG_DAEMON }, | ||
91 | { "AUTH", LOG_AUTH }, | ||
92 | { "LOCAL0", LOG_LOCAL0 }, | ||
93 | { "LOCAL1", LOG_LOCAL1 }, | ||
94 | { "LOCAL2", LOG_LOCAL2 }, | ||
95 | { "LOCAL3", LOG_LOCAL3 }, | ||
96 | { "LOCAL4", LOG_LOCAL4 }, | ||
97 | { "LOCAL5", LOG_LOCAL5 }, | ||
98 | { "LOCAL6", LOG_LOCAL6 }, | ||
99 | { "LOCAL7", LOG_LOCAL7 }, | ||
100 | { "MAIL", LOG_MAIL } | ||
101 | }; | ||
102 | |||
103 | if (strncmp (str, "LOG_", 4) == 0) | ||
104 | str += 4; | ||
105 | |||
106 | for (i = 0; i < sizeof (syslog_kw) / sizeof (syslog_kw[0]); i++) | ||
107 | if (strcasecmp (syslog_kw[i].name, str) == 0) | ||
108 | return syslog_kw[i].facility; | ||
109 | fprintf (stderr, _("Unknown facility `%s'\n"), str); | ||
110 | return LOG_FACILITY; | ||
111 | } | ||
112 | |||
113 | char *mu_license_text = | ||
114 | N_(" GNU Mailutils is free software; you can redistribute it and/or modify\n" | ||
115 | " it under the terms of the GNU General Public License as published by\n" | ||
116 | " the Free Software Foundation; either version 3 of the License, or\n" | ||
117 | " (at your option) any later version.\n" | ||
118 | "\n" | ||
119 | " GNU Mailutils is distributed in the hope that it will be useful,\n" | ||
120 | " but WITHOUT ANY WARRANTY; without even the implied warranty of\n" | ||
121 | " MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n" | ||
122 | " GNU General Public License for more details.\n" | ||
123 | "\n" | ||
124 | " You should have received a copy of the GNU General Public License along\n" | ||
125 | " with GNU Mailutils; if not, write to the Free Software Foundation,\n" | ||
126 | " Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA\n" | ||
127 | "\n" | ||
128 | "\n" | ||
129 | ); | ||
130 | |||
131 | static char *mu_conf_option[] = { | ||
132 | "VERSION=" VERSION, | ||
133 | #ifdef USE_LIBPAM | ||
134 | "USE_LIBPAM", | ||
135 | #endif | ||
136 | #ifdef HAVE_LIBLTDL | ||
137 | "HAVE_LIBLTDL", | ||
138 | #endif | ||
139 | #ifdef WITH_BDB2 | ||
140 | "WITH_BDB2", | ||
141 | #endif | ||
142 | #ifdef WITH_NDBM | ||
143 | "WITH_NDBM", | ||
144 | #endif | ||
145 | #ifdef WITH_OLD_DBM | ||
146 | "WITH_OLD_DBM", | ||
147 | #endif | ||
148 | #ifdef WITH_GDBM | ||
149 | "WITH_GDBM", | ||
150 | #endif | ||
151 | #ifdef WITH_GNUTLS | ||
152 | "WITH_GNUTLS", | ||
153 | #endif | ||
154 | #ifdef WITH_GSASL | ||
155 | "WITH_GSASL", | ||
156 | #endif | ||
157 | #ifdef WITH_GSSAPI | ||
158 | "WITH_GSSAPI", | ||
159 | #endif | ||
160 | #ifdef WITH_GUILE | ||
161 | "WITH_GUILE", | ||
162 | #endif | ||
163 | #ifdef WITH_PTHREAD | ||
164 | "WITH_PTHREAD", | ||
165 | #endif | ||
166 | #ifdef WITH_READLINE | ||
167 | "WITH_READLINE", | ||
168 | #endif | ||
169 | #ifdef HAVE_MYSQL | ||
170 | "HAVE_MYSQL", | ||
171 | #endif | ||
172 | #ifdef HAVE_PGSQL | ||
173 | "HAVE_PGSQL", | ||
174 | #endif | ||
175 | #ifdef ENABLE_VIRTUAL_DOMAINS | ||
176 | "ENABLE_VIRTUAL_DOMAINS", | ||
177 | #endif | ||
178 | #ifdef ENABLE_IMAP | ||
179 | "ENABLE_IMAP", | ||
180 | #endif | ||
181 | #ifdef ENABLE_POP | ||
182 | "ENABLE_POP", | ||
183 | #endif | ||
184 | #ifdef ENABLE_MH | ||
185 | "ENABLE_MH", | ||
186 | #endif | ||
187 | #ifdef ENABLE_MAILDIR | ||
188 | "ENABLE_MAILDIR", | ||
189 | #endif | ||
190 | #ifdef ENABLE_SMTP | ||
191 | "ENABLE_SMTP", | ||
192 | #endif | ||
193 | #ifdef ENABLE_SENDMAIL | ||
194 | "ENABLE_SENDMAIL", | ||
195 | #endif | ||
196 | #ifdef ENABLE_NNTP | ||
197 | "ENABLE_NNTP", | ||
198 | #endif | ||
199 | #ifdef ENABLE_RADIUS | ||
200 | "ENABLE_RADIUS", | ||
201 | #endif | ||
202 | #ifdef WITH_INCLUDED_LIBINTL | ||
203 | "WITH_INCLUDED_LIBINTL", | ||
204 | #endif | ||
205 | NULL | ||
206 | }; | ||
207 | |||
208 | void | ||
209 | mu_print_options () | ||
210 | { | ||
211 | int i; | ||
212 | |||
213 | for (i = 0; mu_conf_option[i]; i++) | ||
214 | printf ("%s\n", mu_conf_option[i]); | ||
215 | } | ||
216 | |||
217 | const char * | ||
218 | mu_check_option (char *name) | ||
219 | { | ||
220 | int i; | ||
221 | |||
222 | for (i = 0; mu_conf_option[i]; i++) | ||
223 | { | ||
224 | int len; | ||
225 | char *q, *p = strchr (mu_conf_option[i], '='); | ||
226 | if (p) | ||
227 | len = p - mu_conf_option[i]; | ||
228 | else | ||
229 | len = strlen (mu_conf_option[i]); | ||
230 | |||
231 | if (strncasecmp (mu_conf_option[i], name, len) == 0) | ||
232 | return mu_conf_option[i]; | ||
233 | else if ((q = strchr (mu_conf_option[i], '_')) != NULL | ||
234 | && strncasecmp (q + 1, name, len - (q - mu_conf_option[i]) - 1) == 0) | ||
235 | return mu_conf_option[i]; | ||
236 | } | ||
237 | return NULL; | ||
238 | } | ||
239 | |||
240 | void | ||
241 | assign_string (char **pstr, char *val) | ||
242 | { | ||
243 | if (!val) | ||
244 | { | ||
245 | if (*pstr) | ||
246 | { | ||
247 | free (*pstr); | ||
248 | *pstr = NULL; | ||
249 | } | ||
250 | } | ||
251 | else | ||
252 | { | ||
253 | size_t size = strlen (val); | ||
254 | char *p = realloc (*pstr, size + 1); | ||
255 | if (!p) | ||
256 | { | ||
257 | mu_error ("%s", mu_strerror (ENOMEM)); | ||
258 | exit (1); | ||
259 | } | ||
260 | strcpy (p, val); | ||
261 | *pstr = p; | ||
262 | } | ||
263 | } | ||
264 | |||
265 | #ifndef MU_CONFIG_FILE | ||
266 | # define MU_CONFIG_FILE SYSCONFDIR "/mailutils.rc" | ||
267 | #endif | ||
268 | |||
269 | #ifndef MU_USER_CONFIG_FILE | ||
270 | # define MU_USER_CONFIG_FILE "~/.mailutils" | ||
271 | #endif | ||
272 | |||
273 | static int | ||
274 | member (const char *array[], const char *text, size_t len) | ||
275 | { | ||
276 | int i; | ||
277 | for (i = 0; array[i]; i++) | ||
278 | if (strncmp (array[i], text, len) == 0) | ||
279 | return 1; | ||
280 | return 0; | ||
281 | } | ||
282 | |||
283 | |||
284 | /* ************************************************************************* */ | ||
285 | /* Traditional (command-line style) configuration */ | ||
286 | /* ************************************************************************* */ | ||
287 | |||
288 | #define ARG_LOG_FACILITY 1 | ||
289 | #define ARG_LOCK_FLAGS 2 | ||
290 | #define ARG_LOCK_RETRY_COUNT 3 | ||
291 | #define ARG_LOCK_RETRY_TIMEOUT 4 | ||
292 | #define ARG_LOCK_EXPIRE_TIMEOUT 5 | ||
293 | #define ARG_LOCK_EXTERNAL_PROGRAM 6 | ||
294 | #define ARG_SHOW_OPTIONS 7 | ||
295 | #define ARG_LICENSE 8 | ||
296 | #define ARG_MAILBOX_TYPE 9 | ||
297 | |||
298 | static struct argp_option mu_common_argp_options[] = | ||
299 | { | ||
300 | { NULL, 0, NULL, 0, N_("Common options"), 0}, | ||
301 | { "show-config-options", ARG_SHOW_OPTIONS, NULL, OPTION_HIDDEN, | ||
302 | N_("Show compilation options"), 0 }, | ||
303 | { NULL, 0, NULL, 0, NULL, 0 } | ||
304 | }; | ||
305 | |||
306 | /* Option to print the license. */ | ||
307 | static struct argp_option mu_license_argp_option[] = { | ||
308 | { "license", ARG_LICENSE, NULL, 0, N_("Print license and exit"), -2 }, | ||
309 | { NULL, 0, NULL, 0, NULL, 0 } | ||
310 | }; | ||
311 | |||
312 | /* Options used by programs that access mailboxes. */ | ||
313 | static struct argp_option mu_mailbox_argp_option[] = { | ||
314 | {"mail-spool", 'm', N_("URL"), OPTION_HIDDEN, | ||
315 | N_("Use specified URL as a mailspool directory"), 0}, | ||
316 | {"mailbox-type", ARG_MAILBOX_TYPE, N_("PROTO"), OPTION_HIDDEN, | ||
317 | N_("Default mailbox type to use"), 0 }, | ||
318 | {"lock-flags", ARG_LOCK_FLAGS, N_("FLAGS"), OPTION_HIDDEN, | ||
319 | N_("Default locker flags (E=external, R=retry, T=time, P=pid)"), 0}, | ||
320 | {"lock-retry-timeout", ARG_LOCK_RETRY_TIMEOUT, N_("SECONDS"), OPTION_HIDDEN, | ||
321 | N_("Set timeout for acquiring the lockfile") }, | ||
322 | {"lock-retry-count", ARG_LOCK_RETRY_COUNT, N_("NUMBER"), OPTION_HIDDEN, | ||
323 | N_("Set the maximum number of times to retry acquiring the lockfile") }, | ||
324 | {"lock-expire-timeout", ARG_LOCK_EXPIRE_TIMEOUT, N_("SECONDS"), OPTION_HIDDEN, | ||
325 | N_("Number of seconds after which the lock expires"), }, | ||
326 | {"external-locker", ARG_LOCK_EXTERNAL_PROGRAM, N_("PATH"), OPTION_HIDDEN, | ||
327 | N_("Set full path to the external locker program") }, | ||
328 | { NULL, 0, NULL, 0, NULL, 0 } | ||
329 | }; | ||
330 | |||
331 | /* Options used by programs that do address mapping. */ | ||
332 | static struct argp_option mu_address_argp_option[] = { | ||
333 | {"email-addr", 'E', N_("EMAIL"), OPTION_HIDDEN, | ||
334 | N_("Set current user's email address (default is loginname@defaultdomain)"), 0}, | ||
335 | {"email-domain", 'D', N_("DOMAIN"), OPTION_HIDDEN, | ||
336 | N_("Set domain for unqualified user names (default is this host)"), 0}, | ||
337 | { NULL, 0, NULL, 0, NULL, 0 } | ||
338 | }; | ||
339 | |||
340 | /* Options used by programs that send mail. */ | ||
341 | static struct argp_option mu_mailer_argp_option[] = { | ||
342 | {"mailer", 'M', N_("MAILER"), 0, | ||
343 | N_("Use specified URL as the default mailer"), 0}, | ||
344 | { NULL, 0, NULL, 0, NULL, 0 } | ||
345 | }; | ||
346 | |||
347 | /* Options used by programs that log to syslog. */ | ||
348 | static struct argp_option mu_logging_argp_option[] = { | ||
349 | {"log-facility", ARG_LOG_FACILITY, N_("FACILITY"), 0, | ||
350 | N_("Output logs to syslog FACILITY"), 0}, | ||
351 | { NULL, 0, NULL, 0, NULL, 0 } | ||
352 | }; | ||
353 | |||
354 | /* Options used by programs that become daemons. */ | ||
355 | static struct argp_option mu_daemon_argp_option[] = { | ||
356 | {"daemon", 'd', N_("NUMBER"), OPTION_ARG_OPTIONAL, | ||
357 | N_("Runs in daemon mode with a maximum of NUMBER children")}, | ||
358 | {"inetd", 'i', 0, 0, | ||
359 | N_("Run in inetd mode"), 0}, | ||
360 | {"port", 'p', N_("PORT"), 0, | ||
361 | N_("Listen on specified port number"), 0}, | ||
362 | {"timeout", 't', N_("NUMBER"), OPTION_HIDDEN, | ||
363 | N_("Set idle timeout value to NUMBER seconds"), 0}, | ||
364 | {"transcript", 'x', NULL, 0, | ||
365 | N_("Output session transcript via syslog"), 0}, | ||
366 | {"pidfile", 'P', N_("FILE"), OPTION_HIDDEN, | ||
367 | N_("Set PID file"), 0}, | ||
368 | { NULL, 0, NULL, 0, NULL, 0 } | ||
369 | }; | ||
370 | |||
371 | static error_t mu_common_argp_parser (int key, char *arg, | ||
372 | struct argp_state *state); | ||
373 | static error_t mu_daemon_argp_parser (int key, char *arg, | ||
374 | struct argp_state *state); | ||
375 | |||
376 | struct argp mu_common_argp = { | ||
377 | mu_common_argp_options, | ||
378 | mu_common_argp_parser, | ||
379 | }; | ||
380 | |||
381 | struct argp_child mu_common_argp_child = { | ||
382 | &mu_common_argp, | ||
383 | 0, | ||
384 | NULL, | ||
385 | 0, | ||
386 | }; | ||
387 | |||
388 | struct argp mu_license_argp = { | ||
389 | mu_license_argp_option, | ||
390 | mu_common_argp_parser, | ||
391 | }; | ||
392 | |||
393 | struct argp_child mu_license_argp_child = { | ||
394 | &mu_license_argp, | ||
395 | 0, | ||
396 | NULL, | ||
397 | 0 | ||
398 | }; | ||
399 | |||
400 | struct argp mu_mailbox_argp = { | ||
401 | mu_mailbox_argp_option, | ||
402 | mu_common_argp_parser, | ||
403 | }; | ||
404 | |||
405 | struct argp_child mu_mailbox_argp_child = { | ||
406 | &mu_mailbox_argp, | ||
407 | 0, | ||
408 | NULL, | ||
409 | 0 | ||
410 | }; | ||
411 | |||
412 | struct argp mu_address_argp = { | ||
413 | mu_address_argp_option, | ||
414 | mu_common_argp_parser, | ||
415 | }; | ||
416 | |||
417 | struct argp_child mu_address_argp_child = { | ||
418 | &mu_address_argp, | ||
419 | 0, | ||
420 | NULL, | ||
421 | 0 | ||
422 | }; | ||
423 | |||
424 | struct argp mu_mailer_argp = { | ||
425 | mu_mailer_argp_option, | ||
426 | mu_common_argp_parser, | ||
427 | }; | ||
428 | |||
429 | struct argp_child mu_mailer_argp_child = { | ||
430 | &mu_mailer_argp, | ||
431 | 0, | ||
432 | NULL, | ||
433 | 0 | ||
434 | }; | ||
435 | |||
436 | struct argp mu_logging_argp = { | ||
437 | mu_logging_argp_option, | ||
438 | mu_common_argp_parser, | ||
439 | }; | ||
440 | |||
441 | struct argp_child mu_logging_argp_child = { | ||
442 | &mu_logging_argp, | ||
443 | 0, | ||
444 | NULL, | ||
445 | 0 | ||
446 | }; | ||
447 | |||
448 | struct argp mu_daemon_argp = { | ||
449 | mu_daemon_argp_option, | ||
450 | mu_daemon_argp_parser, | ||
451 | }; | ||
452 | |||
453 | struct argp_child mu_daemon_argp_child = { | ||
454 | &mu_daemon_argp, | ||
455 | 0, | ||
456 | N_("Daemon configuration options"), | ||
457 | 0 | ||
458 | }; | ||
459 | |||
460 | static error_t | ||
461 | mu_common_argp_parser (int key, char *arg, struct argp_state *state) | ||
462 | { | ||
463 | int err = 0; | ||
464 | |||
465 | switch (key) | ||
466 | { | ||
467 | /* common */ | ||
468 | case ARG_LICENSE: | ||
469 | printf (_("License for %s:\n\n"), argp_program_version); | ||
470 | printf ("%s", mu_license_text); | ||
471 | exit (0); | ||
472 | |||
473 | case ARG_SHOW_OPTIONS: | ||
474 | mu_print_options (); | ||
475 | exit (0); | ||
476 | |||
477 | /* mailbox */ | ||
478 | case 'm': | ||
479 | assign_string (&mail_spool_option, arg); | ||
480 | break; | ||
481 | |||
482 | case ARG_MAILBOX_TYPE: | ||
483 | assign_string (&mailbox_type_option, arg); | ||
484 | break; | ||
485 | |||
486 | case ARG_LOCK_FLAGS: | ||
487 | assign_string (&lock_flags_option, arg); | ||
488 | break; | ||
489 | |||
490 | case ARG_LOCK_RETRY_COUNT: | ||
491 | lock_retry_count_option = strtoul (arg, NULL, 0); | ||
492 | break; | ||
493 | |||
494 | case ARG_LOCK_RETRY_TIMEOUT: | ||
495 | lock_retry_timeout_option = strtoul (arg, NULL, 0); | ||
496 | break; | ||
497 | |||
498 | case ARG_LOCK_EXPIRE_TIMEOUT: | ||
499 | lock_expire_timeout_option = strtoul (arg, NULL, 0); | ||
500 | break; | ||
501 | |||
502 | case ARG_LOCK_EXTERNAL_PROGRAM: | ||
503 | assign_string (&external_locker_option, arg); | ||
504 | break; | ||
505 | |||
506 | /* address */ | ||
507 | case 'E': | ||
508 | assign_string (&email_addr_option, arg); | ||
509 | break; | ||
510 | |||
511 | case 'D': | ||
512 | assign_string (&email_domain_option, arg); | ||
513 | break; | ||
514 | |||
515 | /* mailer */ | ||
516 | case 'M': | ||
517 | assign_string (&mailer_option, arg); | ||
518 | break; | ||
519 | |||
520 | /* log */ | ||
521 | case ARG_LOG_FACILITY: | ||
522 | assign_string (&log_facility_option, arg); | ||
523 | break; | ||
524 | |||
525 | case ARGP_KEY_FINI: | ||
526 | if (mail_spool_option) | ||
527 | { | ||
528 | err = mu_set_mail_directory (mail_spool_option); | ||
529 | if (err) | ||
530 | argp_error (state, _("Cannot set mail directory name: %s"), | ||
531 | mu_strerror (err)); | ||
532 | free (mail_spool_option); | ||
533 | mail_spool_option = NULL; | ||
534 | } | ||
535 | |||
536 | if (mailbox_type_option) | ||
537 | { | ||
538 | if (mu_mailbox_set_default_proto (mailbox_type_option)) | ||
539 | argp_error (state, _("Invalid mailbox type: %s"), | ||
540 | mailbox_type_option); | ||
541 | free (mailbox_type_option); | ||
542 | mailbox_type_option = NULL; | ||
543 | } | ||
544 | |||
545 | if (lock_flags_option) | ||
546 | { | ||
547 | int flags = 0; | ||
548 | char *p; | ||
549 | |||
550 | for (p = lock_flags_option; *p; p++) | ||
551 | { | ||
552 | switch (*p) | ||
553 | { | ||
554 | case 'E': | ||
555 | flags |= MU_LOCKER_EXTERNAL; | ||
556 | break; | ||
557 | |||
558 | case 'R': | ||
559 | flags |= MU_LOCKER_RETRY; | ||
560 | break; | ||
561 | |||
562 | case 'T': | ||
563 | flags |= MU_LOCKER_TIME; | ||
564 | break; | ||
565 | |||
566 | case 'P': | ||
567 | flags |= MU_LOCKER_PID; | ||
568 | break; | ||
569 | |||
570 | default: | ||
571 | argp_error (state, _("Invalid lock flag `%c'"), *p); | ||
572 | } | ||
573 | } | ||
574 | mu_locker_set_default_flags (flags, mu_locker_assign); | ||
575 | free (lock_flags_option); | ||
576 | lock_flags_option = NULL; | ||
577 | } | ||
578 | |||
579 | if (lock_retry_count_option) | ||
580 | { | ||
581 | mu_locker_set_default_retry_count (lock_retry_count_option); | ||
582 | mu_locker_set_default_flags (MU_LOCKER_RETRY, mu_locker_set_bit); | ||
583 | lock_retry_count_option = 0; | ||
584 | } | ||
585 | |||
586 | if (lock_retry_timeout_option) | ||
587 | { | ||
588 | mu_locker_set_default_retry_timeout (lock_retry_timeout_option); | ||
589 | mu_locker_set_default_flags (MU_LOCKER_RETRY, mu_locker_set_bit); | ||
590 | lock_retry_timeout_option = 0; | ||
591 | } | ||
592 | |||
593 | if (lock_expire_timeout_option) | ||
594 | { | ||
595 | mu_locker_set_default_expire_timeout (lock_expire_timeout_option); | ||
596 | mu_locker_set_default_flags (MU_LOCKER_EXTERNAL, mu_locker_set_bit); | ||
597 | lock_expire_timeout_option = 0; | ||
598 | } | ||
599 | |||
600 | if (external_locker_option) | ||
601 | { | ||
602 | mu_locker_set_default_external_program (external_locker_option); | ||
603 | mu_locker_set_default_flags (MU_LOCKER_TIME, mu_locker_set_bit); | ||
604 | free (external_locker_option); | ||
605 | external_locker_option = NULL; | ||
606 | } | ||
607 | |||
608 | if (email_addr_option) | ||
609 | { | ||
610 | if ((err = mu_set_user_email (email_addr_option)) != 0) | ||
611 | { | ||
612 | argp_error (state, _("Invalid email address `%s': %s"), | ||
613 | email_addr_option, mu_strerror (err)); | ||
614 | } | ||
615 | free (email_addr_option); | ||
616 | email_addr_option = NULL; | ||
617 | } | ||
618 | |||
619 | if (email_domain_option) | ||
620 | { | ||
621 | if ((err = mu_set_user_email_domain (email_domain_option)) != 0) | ||
622 | { | ||
623 | argp_error (state, _("Invalid email domain `%s': %s"), | ||
624 | email_domain_option, mu_strerror (err)); | ||
625 | } | ||
626 | free (email_domain_option); | ||
627 | email_domain_option = NULL; | ||
628 | } | ||
629 | |||
630 | if (mailer_option) | ||
631 | { | ||
632 | if ((err = mu_mailer_set_url_default (mailer_option)) != 0) | ||
633 | { | ||
634 | argp_error (state, _("Invalid mailer URL `%s': %s"), | ||
635 | mailer_option, mu_strerror (err)); | ||
636 | } | ||
637 | free (mailer_option); | ||
638 | mailer_option = NULL; | ||
639 | } | ||
640 | |||
641 | if (log_facility_option) | ||
642 | { | ||
643 | log_facility = parse_log_facility (log_facility_option); | ||
644 | free (log_facility_option); | ||
645 | log_facility_option = NULL; | ||
646 | } | ||
647 | break; | ||
648 | |||
649 | default: | ||
650 | return ARGP_ERR_UNKNOWN; | ||
651 | } | ||
652 | return 0; | ||
653 | } | ||
654 | |||
655 | static error_t | ||
656 | mu_daemon_argp_parser (int key, char *arg, struct argp_state *state) | ||
657 | { | ||
658 | struct daemon_param *p = state->input; | ||
659 | if (!p) | ||
660 | return ARGP_ERR_UNKNOWN; | ||
661 | switch (key) | ||
662 | { | ||
663 | case 'd': | ||
664 | assign_string (&daemon_mode_option, "daemon"); | ||
665 | if (arg) | ||
666 | { | ||
667 | unsigned long n = strtoul (arg, NULL, 10); | ||
668 | if (n > 0) | ||
669 | daemon_max_children_option = n; | ||
670 | } | ||
671 | break; | ||
672 | |||
673 | case 'i': | ||
674 | assign_string (&daemon_mode_option, "interactive"); | ||
675 | break; | ||
676 | |||
677 | case 'p': | ||
678 | assign_string (&daemon_mode_option, "daemon"); | ||
679 | daemon_port_option = strtoul (arg, NULL, 10); /*FIXME: overflow */ | ||
680 | break; | ||
681 | |||
682 | case 'P': | ||
683 | assign_string (&daemon_pidfile_option, arg); | ||
684 | break; | ||
685 | |||
686 | case 't': | ||
687 | daemon_timeout_option = strtoul (arg, NULL, 10); | ||
688 | break; | ||
689 | |||
690 | case 'x': | ||
691 | daemon_transcript_option = 1; | ||
692 | break; | ||
693 | |||
694 | case ARGP_KEY_FINI: | ||
695 | if (daemon_mode_option) | ||
696 | { | ||
697 | if (strcmp (daemon_mode_option, "daemon") == 0) | ||
698 | p->mode = MODE_DAEMON; | ||
699 | else if (strcmp (daemon_mode_option, "interactive") == 0) | ||
700 | p->mode = MODE_INTERACTIVE; | ||
701 | else /* FIXME */ | ||
702 | argp_error (state, _("Invalid daemon mode: `%s'"), | ||
703 | daemon_mode_option); | ||
704 | free (daemon_mode_option); | ||
705 | daemon_mode_option = 0; | ||
706 | } | ||
707 | |||
708 | if (daemon_max_children_option) | ||
709 | { | ||
710 | p->mode = MODE_DAEMON; | ||
711 | p->maxchildren = daemon_max_children_option; | ||
712 | daemon_max_children_option = 0; | ||
713 | } | ||
714 | |||
715 | if (daemon_pidfile_option) | ||
716 | { | ||
717 | p->mode = MODE_DAEMON; | ||
718 | p->pidfile = daemon_pidfile_option; | ||
719 | daemon_pidfile_option = NULL; | ||
720 | } | ||
721 | |||
722 | p->transcript = daemon_transcript_option; | ||
723 | if (daemon_timeout_option) | ||
724 | { | ||
725 | p->timeout = daemon_timeout_option; | ||
726 | daemon_timeout_option = 0; | ||
727 | } | ||
728 | break; | ||
729 | |||
730 | default: | ||
731 | return ARGP_ERR_UNKNOWN; | ||
732 | } | ||
733 | return 0; | ||
734 | } | ||
735 | |||
736 | |||
737 | /* ************************************************************************* */ | ||
738 | /* New (resource-file style) configuration */ | ||
739 | /* ************************************************************************* */ | ||
740 | |||
741 | static struct mu_cfg_param mu_mailbox_param[] = { | ||
742 | { "mail-spool", mu_cfg_string, &mail_spool_option }, | ||
743 | { "mailbox-type", mu_cfg_string, &mailbox_type_option }, | ||
744 | { "lock-flags", mu_cfg_string, &lock_flags_option }, | ||
745 | { "lock-retry-timeout", mu_cfg_ulong, &lock_retry_timeout_option }, | ||
746 | { "lock-retry-count", mu_cfg_ulong, &lock_retry_count_option }, | ||
747 | { "lock-expire-timeout", mu_cfg_ulong, &lock_expire_timeout_option }, | ||
748 | { "external-locker", mu_cfg_string, &external_locker_option }, | ||
749 | { NULL, } | ||
750 | }; | ||
751 | |||
752 | static struct mu_cfg_param mu_address_param[] = { | ||
753 | { "email-addr", mu_cfg_string, &email_addr_option }, | ||
754 | { "email-domain", mu_cfg_string, &email_domain_option }, | ||
755 | { NULL } | ||
756 | }; | ||
757 | |||
758 | static struct mu_cfg_param mu_mailer_param[] = { | ||
759 | { "url", mu_cfg_string, &mailer_option }, | ||
760 | { NULL } | ||
761 | }; | ||
762 | |||
763 | static struct mu_cfg_param mu_logging_param[] = { | ||
764 | { "facility", mu_cfg_string, &log_facility_option }, | ||
765 | { NULL } | ||
766 | }; | ||
767 | |||
768 | static struct mu_cfg_param mu_daemon_param[] = { | ||
769 | { "max-children", mu_cfg_ulong, &daemon_max_children_option }, | ||
770 | { "mode", mu_cfg_string, &daemon_mode_option }, | ||
771 | { "transcript", mu_cfg_bool, &daemon_transcript_option }, | ||
772 | { "pidfile", mu_cfg_string, &daemon_pidfile_option }, | ||
773 | { "port", mu_cfg_ushort, &daemon_port_option }, | ||
774 | { "timeout", mu_cfg_ulong, &daemon_timeout_option }, | ||
775 | { NULL } | ||
776 | }; | ||
777 | |||
778 | |||
779 | /* ************************************************************************* */ | ||
780 | /* Capability array and auxiliary functions. */ | ||
781 | /* ************************************************************************* */ | ||
782 | |||
783 | #define MU_MAX_CAPA 24 | ||
784 | |||
785 | struct argp_capa { | ||
786 | char *capability; | ||
787 | struct argp_child *child; | ||
788 | struct mu_cfg_param *param; | ||
789 | } mu_argp_capa[MU_MAX_CAPA] = { | ||
790 | {"common", &mu_common_argp_child}, | ||
791 | {"license", &mu_license_argp_child}, | ||
792 | {"mailbox", &mu_mailbox_argp_child, mu_mailbox_param }, | ||
793 | {"address", &mu_address_argp_child, mu_address_param}, | ||
794 | {"mailer", &mu_mailer_argp_child, mu_mailer_param }, | ||
795 | {"logging", &mu_logging_argp_child, mu_logging_param }, | ||
796 | {"daemon", &mu_daemon_argp_child, mu_daemon_param }, | ||
797 | {NULL,} | ||
798 | }; | ||
799 | |||
800 | int | ||
801 | mu_register_capa (const char *name, struct argp_child *child, | ||
802 | struct mu_cfg_param *param) | ||
803 | { | ||
804 | int i; | ||
805 | |||
806 | for (i = 0; i < MU_MAX_CAPA; i++) | ||
807 | if (mu_argp_capa[i].capability == NULL) | ||
808 | { | ||
809 | mu_argp_capa[i].capability = strdup (name); | ||
810 | mu_argp_capa[i].child = child; | ||
811 | mu_argp_capa[i].param = param; | ||
812 | return 0; | ||
813 | } | ||
814 | return 1; | ||
815 | } | ||
816 | |||
817 | static struct argp_capa * | ||
818 | find_capa (const char *name) | ||
819 | { | ||
820 | int i; | ||
821 | for (i = 0; mu_argp_capa[i].capability; i++) | ||
822 | if (strcmp (mu_argp_capa[i].capability, name) == 0) | ||
823 | return &mu_argp_capa[i]; | ||
824 | return NULL; | ||
825 | } | ||
826 | |||
827 | void | ||
828 | build_config_struct (const char *capa[]) | ||
829 | { | ||
830 | struct argp_capa *acp; | ||
831 | |||
832 | for (acp = mu_argp_capa; acp->capability; acp++) | ||
833 | { | ||
834 | struct mu_cfg_param *param; | ||
835 | if (member (capa, acp->capability, strlen (acp->capability))) | ||
836 | param = acp->param; | ||
837 | else | ||
838 | param = NULL; | ||
839 | mu_config_register_plain_section (NULL, acp->capability, param); | ||
840 | } | ||
841 | } | ||
842 | |||
843 | static struct argp * | ||
844 | mu_build_argp (const struct argp *template, const char *capa[]) | ||
845 | { | ||
846 | int n; | ||
847 | int nchild; | ||
848 | struct argp_child *ap; | ||
849 | const struct argp_option *opt; | ||
850 | struct argp *argp; | ||
851 | int group = 0; | ||
852 | |||
853 | /* Count the capabilities. */ | ||
854 | for (n = 0; capa && capa[n]; n++) | ||
855 | ; | ||
856 | if (template->children) | ||
857 | for (; template->children[n].argp; n++) | ||
858 | ; | ||
859 | |||
860 | ap = calloc (n + 1, sizeof (*ap)); | ||
861 | if (!ap) | ||
862 | { | ||
863 | mu_error (_("Out of memory")); | ||
864 | abort (); | ||
865 | } | ||
866 | |||
867 | /* Copy the template's children. */ | ||
868 | nchild = 0; | ||
869 | if (template->children) | ||
870 | for (n = 0; template->children[n].argp; n++, nchild++) | ||
871 | ap[nchild] = template->children[n]; | ||
872 | |||
873 | /* Find next group number */ | ||
874 | for (opt = template->options; | ||
875 | opt && ((opt->name && opt->key) || opt->doc); opt++) | ||
876 | if (opt->group > group) | ||
877 | group = opt->group; | ||
878 | |||
879 | group++; | ||
880 | |||
881 | /* Append any capabilities to the children or options, as appropriate. */ | ||
882 | for (n = 0; capa && capa[n]; n++) | ||
883 | { | ||
884 | struct argp_capa *cp = find_capa (capa[n]); | ||
885 | if (!cp) | ||
886 | { | ||
887 | mu_error (_("INTERNAL ERROR: requested unknown argp " | ||
888 | "capability %s (please report)"), | ||
889 | capa[n]); | ||
890 | abort (); | ||
891 | } | ||
892 | ap[nchild] = *cp->child; | ||
893 | ap[nchild].group = group++; | ||
894 | nchild++; | ||
895 | |||
896 | } | ||
897 | ap[nchild].argp = NULL; | ||
898 | |||
899 | build_config_struct (capa); | ||
900 | |||
901 | /* Copy the template, and give it the expanded children. */ | ||
902 | argp = malloc (sizeof (*argp)); | ||
903 | if (!argp) | ||
904 | { | ||
905 | mu_error (_("Out of memory")); | ||
906 | abort (); | ||
907 | } | ||
908 | |||
909 | memcpy (argp, template, sizeof (*argp)); | ||
910 | |||
911 | argp->children = ap; | ||
912 | |||
913 | return argp; | ||
914 | } | ||
915 | |||
916 | |||
917 | /* ************************************************************************* */ | ||
918 | /* Configuration style detection */ | ||
919 | /* ************************************************************************* */ | ||
920 | |||
921 | #define CF_GLOBAL 0 | ||
922 | #define CF_USER 1 | ||
923 | #define CF_SIZE 2 | ||
924 | |||
925 | enum mu_config_flavor | ||
926 | { | ||
927 | mu_config_none, | ||
928 | mu_config_auto, | ||
929 | mu_config_options, | ||
930 | mu_config_resource | ||
931 | }; | ||
932 | |||
933 | #define isword(c) (isalnum (c) || (c) == '-' || (c) == '_') | ||
934 | |||
935 | static int | ||
936 | getword (FILE *fp, int c) | ||
937 | { | ||
938 | if (c == EOF || isspace (c) || c == '\\') | ||
939 | return 0; | ||
940 | if (c == '"' || c == '\'') | ||
941 | { | ||
942 | int delim = c; | ||
943 | while ((c = getc (fp)) != EOF && c != delim) | ||
944 | { | ||
945 | if (c == '\\') | ||
946 | if ((c = getc (fp)) == EOF) | ||
947 | break; | ||
948 | } | ||
949 | } | ||
950 | else | ||
951 | while ((c = getc (fp)) != EOF && !isspace (c)) | ||
952 | ; | ||
953 | return 1; | ||
954 | } | ||
955 | |||
956 | static enum mu_config_flavor | ||
957 | deduce_config_flavor (const char *file) | ||
958 | { | ||
959 | int c; | ||
960 | FILE *fp; | ||
961 | size_t optcnt = 0; | ||
962 | size_t wordcnt = 0; | ||
963 | char *file_name = mu_tilde_expansion (file, "/", NULL); | ||
964 | |||
965 | fp = fopen (file_name, "r"); | ||
966 | free (file_name); | ||
967 | if (!fp) | ||
968 | return mu_config_none; | ||
969 | |||
970 | while (!feof (fp)) | ||
971 | { | ||
972 | while ((c = getc (fp)) != EOF && isspace (c)) | ||
973 | ; | ||
974 | if (c == '-') | ||
975 | { | ||
976 | if ((c = getc (fp)) == EOF) | ||
977 | break; | ||
978 | if (c == '-') | ||
979 | { | ||
980 | if ((c = getc (fp)) == EOF) | ||
981 | break; | ||
982 | } | ||
983 | if (isword (c)) | ||
984 | optcnt++; | ||
985 | if (getword (fp, c)) | ||
986 | wordcnt++; | ||
987 | } | ||
988 | else if (getword (fp, c)) | ||
989 | wordcnt++; | ||
990 | } | ||
991 | fclose (fp); | ||
992 | if (wordcnt == 0) | ||
993 | return mu_config_none; | ||
994 | else if (optcnt == 0) | ||
995 | return mu_config_resource; | ||
996 | else if (wordcnt / optcnt <= 2) | ||
997 | return mu_config_options; | ||
998 | return mu_config_resource; | ||
999 | } | ||
1000 | |||
1001 | static enum mu_config_flavor | ||
1002 | decode_config_flavor (const char *str) | ||
1003 | { | ||
1004 | if (strcmp (str, "none") == 0) | ||
1005 | return mu_config_none; | ||
1006 | else if (strcmp (str, "auto") == 0) | ||
1007 | return mu_config_auto; | ||
1008 | else if (strcmp (str, "resource") == 0 | ||
1009 | || strcmp (str, "new") == 0) | ||
1010 | return mu_config_resource; | ||
1011 | else if (strcmp (str, "options") == 0 | ||
1012 | || strcmp (str, "old") == 0) | ||
1013 | return mu_config_options; | ||
1014 | else | ||
1015 | mu_error (_("invalid configuration flavor: %s"), str); | ||
1016 | return mu_config_auto; | ||
1017 | } | ||
1018 | |||
1019 | static void | ||
1020 | get_default_config_flavor (const char *progname, enum mu_config_flavor cfl[]) | ||
1021 | { | ||
1022 | char *val = getenv ("MU_CONFIG_FLAVOR"); | ||
1023 | |||
1024 | cfl[CF_GLOBAL] = cfl[CF_USER] = mu_config_auto; | ||
1025 | if (val) | ||
1026 | { | ||
1027 | int i; | ||
1028 | int argc; | ||
1029 | char **argv; | ||
1030 | size_t proglen; | ||
1031 | |||
1032 | mu_argcv_get (val, ":", NULL, &argc, &argv); | ||
1033 | |||
1034 | proglen = strlen (progname); | ||
1035 | for (i = 0; i < argc; i++) | ||
1036 | { | ||
1037 | char *p = strchr (argv[i], '='); | ||
1038 | if (p) | ||
1039 | { | ||
1040 | size_t len = p - argv[i]; | ||
1041 | if (len == proglen && | ||
1042 | memcmp (progname, argv[i], len) == 0) | ||
1043 | cfl[CF_USER] = decode_config_flavor (p + 1); | ||
1044 | } | ||
1045 | else | ||
1046 | cfl[CF_GLOBAL] = decode_config_flavor (argv[i]); | ||
1047 | } | ||
1048 | mu_argcv_free (argc, argv); | ||
1049 | } | ||
1050 | if (cfl[CF_USER] == mu_config_auto) | ||
1051 | cfl[CF_USER] = cfl[CF_GLOBAL]; | ||
1052 | } | ||
1053 | |||
1054 | |||
1055 | /* ************************************************************************* */ | ||
1056 | /* Functions for handling traditional-style configuration files. */ | ||
1057 | /* ************************************************************************* */ | ||
1058 | |||
1059 | /* Appends applicable options found in file NAME to argv. If progname | ||
1060 | is NULL, all the options found are assumed to apply. Otherwise they | ||
1061 | apply only if the line starts with ":something", and something is | ||
1062 | found in the CAPA array, or the line starts with PROGNAME. */ | ||
1063 | void | ||
1064 | read_rc (const char *progname, const char *name, enum mu_config_flavor rf, | ||
1065 | const char *capa[], | ||
1066 | int *argc, char ***argv) | ||
1067 | { | ||
1068 | FILE *fp; | ||
1069 | char *linebuf = NULL; | ||
1070 | char *buf = NULL; | ||
1071 | size_t n = 0; | ||
1072 | int x_argc = *argc; | ||
1073 | char **x_argv = *argv; | ||
1074 | char* rcfile = mu_tilde_expansion (name, "/", NULL); | ||
1075 | |||
1076 | if (!rcfile) | ||
1077 | return; | ||
1078 | |||
1079 | fp = fopen (rcfile, "r"); | ||
1080 | if (!fp) | ||
1081 | { | ||
1082 | free (rcfile); | ||
1083 | return; | ||
1084 | } | ||
1085 | |||
1086 | if (rf == mu_config_auto) | ||
1087 | mu_error (_("Notice: reading options from `%s'"), rcfile); | ||
1088 | |||
1089 | while (getline (&buf, &n, fp) > 0) | ||
1090 | { | ||
1091 | char *kwp, *p; | ||
1092 | int len; | ||
1093 | |||
1094 | for (kwp = buf; *kwp && isspace (*kwp); kwp++) | ||
1095 | ; | ||
1096 | |||
1097 | if (*kwp == '#' || *kwp == 0) | ||
1098 | continue; | ||
1099 | |||
1100 | len = strlen (kwp); | ||
1101 | if (kwp[len-1] == '\n') | ||
1102 | kwp[--len] = 0; | ||
1103 | |||
1104 | if (kwp[len-1] == '\\' || linebuf) | ||
1105 | { | ||
1106 | int cont; | ||
1107 | |||
1108 | if (kwp[len-1] == '\\') | ||
1109 | { | ||
1110 | kwp[--len] = 0; | ||
1111 | cont = 1; | ||
1112 | } | ||
1113 | else | ||
1114 | cont = 0; | ||
1115 | |||
1116 | if (!linebuf) | ||
1117 | linebuf = calloc (len + 1, 1); | ||
1118 | else | ||
1119 | linebuf = realloc (linebuf, strlen (linebuf) + len + 1); | ||
1120 | |||
1121 | if (!linebuf) | ||
1122 | { | ||
1123 | fprintf (stderr, _("%s: not enough memory\n"), progname); | ||
1124 | exit (1); | ||
1125 | } | ||
1126 | |||
1127 | strcpy (linebuf + strlen (linebuf), kwp); | ||
1128 | if (cont) | ||
1129 | continue; | ||
1130 | kwp = linebuf; | ||
1131 | } | ||
1132 | |||
1133 | len = 0; | ||
1134 | if (progname) | ||
1135 | { | ||
1136 | for (p = kwp; *p && !isspace (*p); p++) | ||
1137 | len++; | ||
1138 | } | ||
1139 | else | ||
1140 | p = kwp; /* Use the whole line. */ | ||
1141 | |||
1142 | if (progname == NULL | ||
1143 | || (kwp[0] == ':' && member (capa, kwp+1, len-1)) | ||
1144 | || strncmp (progname, kwp, len) == 0) | ||
1145 | { | ||
1146 | int i, n_argc = 0; | ||
1147 | char **n_argv; | ||
1148 | |||
1149 | if (mu_argcv_get (p, "", NULL, &n_argc, &n_argv)) | ||
1150 | { | ||
1151 | mu_argcv_free (n_argc, n_argv); | ||
1152 | if (linebuf) | ||
1153 | free (linebuf); | ||
1154 | linebuf = NULL; | ||
1155 | continue; | ||
1156 | } | ||
1157 | x_argv = realloc (x_argv, (x_argc + n_argc) * sizeof (x_argv[0])); | ||
1158 | if (!x_argv) | ||
1159 | { | ||
1160 | fprintf (stderr, _("%s: not enough memory\n"), progname); | ||
1161 | exit (1); | ||
1162 | } | ||
1163 | |||
1164 | for (i = 0; i < n_argc; i++) | ||
1165 | x_argv[x_argc++] = mu_tilde_expansion (n_argv[i], "/", NULL); | ||
1166 | |||
1167 | free (n_argv); | ||
1168 | } | ||
1169 | if (linebuf) | ||
1170 | free (linebuf); | ||
1171 | linebuf = NULL; | ||
1172 | } | ||
1173 | fclose (fp); | ||
1174 | free (rcfile); | ||
1175 | |||
1176 | *argc = x_argc; | ||
1177 | *argv = x_argv; | ||
1178 | } | ||
1179 | |||
1180 | void | ||
1181 | mu_create_argcv (const char *capa[], | ||
1182 | const char *progname, | ||
1183 | enum mu_config_flavor cfl[CF_SIZE], | ||
1184 | int argc, char **argv, int *p_argc, char ***p_argv) | ||
1185 | { | ||
1186 | int x_argc; | ||
1187 | char **x_argv; | ||
1188 | int i; | ||
1189 | int rcdir = 0; | ||
1190 | |||
1191 | x_argv = malloc (sizeof (x_argv[0])); | ||
1192 | if (!x_argv) | ||
1193 | { | ||
1194 | fprintf (stderr, _("%s: not enough memory\n"), progname); | ||
1195 | exit (1); | ||
1196 | } | ||
1197 | |||
1198 | /* Add command name */ | ||
1199 | x_argc = 0; | ||
1200 | x_argv[x_argc] = argv[x_argc]; | ||
1201 | x_argc++; | ||
1202 | |||
1203 | /* Add global config file. */ | ||
1204 | if (cfl[CF_GLOBAL] == mu_config_options || cfl[CF_GLOBAL] == mu_config_auto) | ||
1205 | read_rc (progname, MU_CONFIG_FILE, cfl[CF_GLOBAL], capa, &x_argc, &x_argv); | ||
1206 | |||
1207 | if (cfl[CF_USER] == mu_config_options || cfl[CF_USER] == mu_config_auto) | ||
1208 | { | ||
1209 | /* Look for per-user config files in ~/.mailutils/ or in ~/, but | ||
1210 | not both. This allows mailutils' utilities to have their config | ||
1211 | files segregated, if necessary. */ | ||
1212 | struct stat s; | ||
1213 | char *rcdirname = mu_tilde_expansion (MU_USER_CONFIG_FILE, "/", NULL); | ||
1214 | |||
1215 | if (!rcdirname | ||
1216 | || (stat (rcdirname, &s) == 0 && S_ISDIR (s.st_mode))) | ||
1217 | rcdir = 1; | ||
1218 | |||
1219 | free (rcdirname); | ||
1220 | |||
1221 | /* Add per-user config file. */ | ||
1222 | if (!rcdir) | ||
1223 | read_rc (progname, MU_USER_CONFIG_FILE, cfl[CF_USER], capa, | ||
1224 | &x_argc, &x_argv); | ||
1225 | else | ||
1226 | { | ||
1227 | char *userrc = NULL; | ||
1228 | |||
1229 | userrc = malloc (sizeof (MU_USER_CONFIG_FILE) | ||
1230 | /* provides an extra slot | ||
1231 | for null byte as well */ | ||
1232 | + 1 /* slash */ | ||
1233 | + 9 /* mailutils */); | ||
1234 | |||
1235 | if (!userrc) | ||
1236 | { | ||
1237 | mu_error (_("%s: not enough memory"), progname); | ||
1238 | exit (1); | ||
1239 | } | ||
1240 | |||
1241 | sprintf (userrc, "%s/mailutils", MU_USER_CONFIG_FILE); | ||
1242 | read_rc (progname, userrc, cfl[CF_USER], capa, &x_argc, &x_argv); | ||
1243 | |||
1244 | free (userrc); | ||
1245 | } | ||
1246 | |||
1247 | /* Add per-user, per-program config file. */ | ||
1248 | { | ||
1249 | char *progrc = NULL; | ||
1250 | int size; | ||
1251 | |||
1252 | if (rcdir) | ||
1253 | size = sizeof (MU_USER_CONFIG_FILE) | ||
1254 | + 1 | ||
1255 | + strlen (progname) | ||
1256 | + 2 /* rc */; | ||
1257 | else | ||
1258 | size = 6 /*~/.mu.*/ | ||
1259 | + strlen (progname) | ||
1260 | + 3 /* "rc" + null terminator */; | ||
1261 | |||
1262 | progrc = malloc (size); | ||
1263 | |||
1264 | if (!progrc) | ||
1265 | { | ||
1266 | mu_error (_("%s: not enough memory"), progname); | ||
1267 | exit (1); | ||
1268 | } | ||
1269 | |||
1270 | if (rcdir) | ||
1271 | sprintf (progrc, "%s/%src", MU_USER_CONFIG_FILE, progname); | ||
1272 | else | ||
1273 | sprintf (progrc, "~/.mu.%src", progname); | ||
1274 | |||
1275 | read_rc (NULL, progrc, cfl[CF_USER], capa, &x_argc, &x_argv); | ||
1276 | free (progrc); | ||
1277 | } | ||
1278 | } | ||
1279 | |||
1280 | /* Finally, add the command line options */ | ||
1281 | x_argv = realloc (x_argv, (x_argc + argc) * sizeof (x_argv[0])); | ||
1282 | for (i = 1; i < argc; i++) | ||
1283 | x_argv[x_argc++] = argv[i]; | ||
1284 | |||
1285 | x_argv[x_argc] = NULL; | ||
1286 | |||
1287 | *p_argc = x_argc; | ||
1288 | *p_argv = x_argv; | ||
1289 | } | ||
1290 | |||
1291 | |||
1292 | /* ************************************************************************* */ | ||
1293 | |||
1294 | static struct mu_cfg_param *prog_param; | ||
1295 | |||
1296 | void | ||
1297 | mu_argp_set_config_param (struct mu_cfg_param *p) | ||
1298 | { | ||
1299 | prog_param = p; | ||
1300 | } | ||
1301 | |||
1302 | static void | ||
1303 | read_configs (char *progname, enum mu_config_flavor cfl[CF_SIZE]) | ||
1304 | { | ||
1305 | size_t size; | ||
1306 | char *file_name; | ||
1307 | enum mu_config_flavor f; | ||
1308 | |||
1309 | if (cfl[CF_GLOBAL] != mu_config_none) | ||
1310 | { | ||
1311 | f = deduce_config_flavor (MU_CONFIG_FILE); | ||
1312 | if (f == mu_config_resource) | ||
1313 | { | ||
1314 | switch (cfl[CF_GLOBAL]) | ||
1315 | { | ||
1316 | case mu_config_auto: | ||
1317 | case mu_config_resource: | ||
1318 | mu_parse_config (MU_CONFIG_FILE, progname, prog_param, 1); | ||
1319 | break; | ||
1320 | |||
1321 | default: | ||
1322 | break; | ||
1323 | } | ||
1324 | cfl[CF_GLOBAL] = mu_config_none; /* Avoid reading the file by | ||
1325 | read_rc */ | ||
1326 | } | ||
1327 | else if (cfl[CF_GLOBAL] != mu_config_auto && cfl[CF_GLOBAL] != f) | ||
1328 | cfl[CF_GLOBAL] = mu_config_none; | ||
1329 | } | ||
1330 | |||
1331 | if (cfl[CF_USER] == mu_config_auto || cfl[CF_USER] == mu_config_resource) | ||
1332 | { | ||
1333 | size = 3 + strlen (progname) + 1; | ||
1334 | file_name = malloc (size); | ||
1335 | if (file_name) | ||
1336 | { | ||
1337 | strcpy (file_name, "~/."); | ||
1338 | strcat (file_name, progname); | ||
1339 | |||
1340 | mu_parse_config (file_name, progname, prog_param, 0); | ||
1341 | |||
1342 | free (file_name); | ||
1343 | } | ||
1344 | } | ||
1345 | } | ||
1346 | |||
1347 | void | ||
1348 | mu_argp_init (const char *vers, const char *bugaddr) | ||
1349 | { | ||
1350 | argp_program_version = vers ? vers : PACKAGE_STRING; | ||
1351 | argp_program_bug_address = bugaddr ? bugaddr : "<" PACKAGE_BUGREPORT ">"; | ||
1352 | } | ||
1353 | |||
1354 | error_t | ||
1355 | mu_argp_parse (const struct argp *argp, | ||
1356 | int *pargc, char **pargv[], | ||
1357 | unsigned flags, | ||
1358 | const char *capa[], | ||
1359 | int *arg_index, | ||
1360 | void *input) | ||
1361 | { | ||
1362 | error_t ret; | ||
1363 | const struct argp argpnull = { 0 }; | ||
1364 | char *progname; | ||
1365 | enum mu_config_flavor cfl[CF_SIZE]; | ||
1366 | |||
1367 | /* Make sure we have program version and bug address initialized */ | ||
1368 | mu_argp_init (argp_program_version, argp_program_bug_address); | ||
1369 | |||
1370 | progname = strrchr ((*pargv)[0], '/'); | ||
1371 | if (progname) | ||
1372 | progname++; | ||
1373 | else | ||
1374 | progname = (*pargv)[0]; | ||
1375 | |||
1376 | if (strlen (progname) > 3 && memcmp (progname, "lt-", 3) == 0) | ||
1377 | progname += 3; | ||
1378 | |||
1379 | get_default_config_flavor (progname, cfl); | ||
1380 | |||
1381 | if (!argp) | ||
1382 | argp = &argpnull; | ||
1383 | |||
1384 | argp = mu_build_argp (argp, capa); | ||
1385 | |||
1386 | read_configs (progname, cfl); | ||
1387 | |||
1388 | mu_create_argcv (capa, progname, cfl, *pargc, *pargv, pargc, pargv); | ||
1389 | ret = argp_parse (argp, *pargc, *pargv, flags, arg_index, input); | ||
1390 | free ((void*) argp->children); | ||
1391 | free ((void*) argp); | ||
1392 | return ret; | ||
1393 | } |
... | @@ -43,7 +43,6 @@ | ... | @@ -43,7 +43,6 @@ |
43 | #include <mailutils/list.h> | 43 | #include <mailutils/list.h> |
44 | #include <mailutils/iterator.h> | 44 | #include <mailutils/iterator.h> |
45 | #include <mailutils/mailbox.h> | 45 | #include <mailutils/mailbox.h> |
46 | #include <mailutils/argp.h> | ||
47 | #include <mailutils/mu_auth.h> | 46 | #include <mailutils/mu_auth.h> |
48 | #include <mailutils/error.h> | 47 | #include <mailutils/error.h> |
49 | #include <mailutils/errno.h> | 48 | #include <mailutils/errno.h> |
... | @@ -54,9 +53,6 @@ | ... | @@ -54,9 +53,6 @@ |
54 | /*#define DEBUG(c) do { printf c; printf("\n"); } while (0)*/ | 53 | /*#define DEBUG(c) do { printf c; printf("\n"); } while (0)*/ |
55 | #define DEBUG(c) | 54 | #define DEBUG(c) |
56 | 55 | ||
57 | static void mu_auth_begin_setup (void); | ||
58 | static void mu_auth_finish_setup (void); | ||
59 | |||
60 | /* memory allocation */ | 56 | /* memory allocation */ |
61 | int | 57 | int |
62 | mu_auth_data_alloc (struct mu_auth_data **ptr, | 58 | mu_auth_data_alloc (struct mu_auth_data **ptr, |
... | @@ -243,117 +239,6 @@ mu_authenticate (struct mu_auth_data *auth_data, char *pass) | ... | @@ -243,117 +239,6 @@ mu_authenticate (struct mu_auth_data *auth_data, char *pass) |
243 | 239 | ||
244 | 240 | ||
245 | /* ************************************************************************* */ | 241 | /* ************************************************************************* */ |
246 | /* Traditional configuration */ | ||
247 | /* ************************************************************************* */ | ||
248 | |||
249 | #define ARG_AUTHORIZATION 1 | ||
250 | #define ARG_AUTHENTICATION 2 | ||
251 | #define ARG_CLEAR_AUTHORIZATION 3 | ||
252 | #define ARG_CLEAR_AUTHENTICATION 4 | ||
253 | |||
254 | static error_t mu_auth_argp_parser (int key, char *arg, | ||
255 | struct argp_state *state); | ||
256 | |||
257 | /* Options used by programs that use extended authentication mechanisms. */ | ||
258 | static struct argp_option mu_auth_argp_option[] = { | ||
259 | { "authentication", ARG_AUTHENTICATION, N_("MODLIST"), OPTION_HIDDEN, | ||
260 | N_("Set the list of modules to be used for authentication"), 0 }, | ||
261 | { "authorization", ARG_AUTHORIZATION, N_("MODLIST"), OPTION_HIDDEN, | ||
262 | N_("Set list of modules to be used for authorization"), 0 }, | ||
263 | { "clear-authorization", ARG_CLEAR_AUTHORIZATION, NULL, OPTION_HIDDEN, | ||
264 | N_("Clear the list of authorization modules"), 0 }, | ||
265 | { "clear-authentication", ARG_CLEAR_AUTHENTICATION, NULL, OPTION_HIDDEN, | ||
266 | N_("Clear the list of authentication modules"), 0 }, | ||
267 | { NULL, 0, NULL, 0, NULL, 0 } | ||
268 | }; | ||
269 | |||
270 | static struct argp mu_auth_argp = { | ||
271 | mu_auth_argp_option, | ||
272 | mu_auth_argp_parser, | ||
273 | }; | ||
274 | |||
275 | static struct argp_child mu_auth_argp_child = { | ||
276 | &mu_auth_argp, | ||
277 | 0, | ||
278 | NULL, | ||
279 | 0 | ||
280 | }; | ||
281 | |||
282 | static error_t | ||
283 | mu_auth_argp_parser (int key, char *arg, struct argp_state *state) | ||
284 | { | ||
285 | switch (key) | ||
286 | { | ||
287 | case ARGP_KEY_FINI: | ||
288 | mu_auth_finish_setup (); | ||
289 | break; | ||
290 | |||
291 | /* authentication */ | ||
292 | case ARG_AUTHORIZATION: | ||
293 | mu_authorization_add_module_list (arg); | ||
294 | break; | ||
295 | |||
296 | case ARG_AUTHENTICATION: | ||
297 | mu_authentication_add_module_list (arg); | ||
298 | break; | ||
299 | |||
300 | case ARG_CLEAR_AUTHENTICATION: | ||
301 | mu_authentication_clear_list (); | ||
302 | break; | ||
303 | |||
304 | case ARG_CLEAR_AUTHORIZATION: | ||
305 | mu_authorization_clear_list (); | ||
306 | break; | ||
307 | |||
308 | default: | ||
309 | return ARGP_ERR_UNKNOWN; | ||
310 | } | ||
311 | return 0; | ||
312 | } | ||
313 | |||
314 | |||
315 | /* ************************************************************************* */ | ||
316 | /* Resource-style configuration */ | ||
317 | /* ************************************************************************* */ | ||
318 | static int | ||
319 | cb_authentication (mu_cfg_locus_t *locus, void *data, char *arg) | ||
320 | { | ||
321 | if (strcmp (arg, "clear") == 0) | ||
322 | mu_authentication_clear_list (); | ||
323 | else | ||
324 | mu_authentication_add_module_list (arg);/*FIXME: error reporting*/ | ||
325 | return 0; | ||
326 | } | ||
327 | |||
328 | static int | ||
329 | cb_authorization (mu_cfg_locus_t *locus, void *data, char *arg) | ||
330 | { | ||
331 | if (strcmp (arg, "clear") == 0) | ||
332 | mu_authorization_clear_list (); | ||
333 | else | ||
334 | mu_authorization_add_module_list (arg); | ||
335 | return 0; | ||
336 | } | ||
337 | |||
338 | static struct mu_cfg_param mu_auth_param[] = { | ||
339 | { "authentication", mu_cfg_callback, NULL, cb_authentication }, | ||
340 | { "authorization", mu_cfg_callback, NULL, cb_authorization }, | ||
341 | { NULL } | ||
342 | }; | ||
343 | |||
344 | |||
345 | void | ||
346 | mu_auth_init () | ||
347 | { | ||
348 | if (mu_register_capa ("auth", &mu_auth_argp_child, mu_auth_param)) | ||
349 | { | ||
350 | mu_error (_("INTERNAL ERROR: cannot register argp capability auth (please report)")); | ||
351 | abort (); | ||
352 | } | ||
353 | } | ||
354 | |||
355 | |||
356 | /* ************************************************************************* */ | ||
357 | 242 | ||
358 | struct _module_handler { | 243 | struct _module_handler { |
359 | struct auth_stack_entry authenticate; | 244 | struct auth_stack_entry authenticate; |
... | @@ -368,42 +253,10 @@ mu_auth_register_module (struct mu_auth_module *mod) | ... | @@ -368,42 +253,10 @@ mu_auth_register_module (struct mu_auth_module *mod) |
368 | { | 253 | { |
369 | struct _module_handler *entry; | 254 | struct _module_handler *entry; |
370 | 255 | ||
371 | if (mod->argp) | 256 | if (mod->init) |
372 | { | 257 | mu_gocs_register (mod->name, mod->init); |
373 | int i; | 258 | /* FIXME: Argp? */ |
374 | struct argp_child *cp; | 259 | /* FIXME: cfg? */ |
375 | |||
376 | if (mu_auth_argp.children) | ||
377 | { | ||
378 | struct argp_child *tmp; | ||
379 | for (i = 0; mu_auth_argp.children[i].argp; i++) | ||
380 | ; | ||
381 | tmp = realloc ((void*) mu_auth_argp.children, | ||
382 | (i + 2) * sizeof(mu_auth_argp.children[0])); | ||
383 | mu_auth_argp.children = tmp; | ||
384 | } | ||
385 | else | ||
386 | { | ||
387 | mu_auth_argp.children = calloc (2, sizeof(mu_auth_argp.children[0])); | ||
388 | i = 0; | ||
389 | } | ||
390 | |||
391 | if (!mu_auth_argp.children) | ||
392 | { | ||
393 | mu_error ("not enough memory"); | ||
394 | exit (1); | ||
395 | } | ||
396 | cp = (struct argp_child *) &mu_auth_argp.children[i]; | ||
397 | cp->argp = mod->argp; | ||
398 | cp->flags = 0; | ||
399 | cp->header = NULL; | ||
400 | cp->group = 0; /* FIXME */ | ||
401 | cp++; | ||
402 | cp->argp = NULL; | ||
403 | } | ||
404 | |||
405 | if (mod->cfg) | ||
406 | mu_config_register_plain_section (NULL, mod->name, mod->cfg); | ||
407 | 260 | ||
408 | if (!module_handler_list && mu_list_create (&module_handler_list)) | 261 | if (!module_handler_list && mu_list_create (&module_handler_list)) |
409 | abort (); | 262 | abort (); | ... | ... |
... | @@ -25,17 +25,31 @@ | ... | @@ -25,17 +25,31 @@ |
25 | #include <syslog.h> | 25 | #include <syslog.h> |
26 | #include <mailutils/error.h> | 26 | #include <mailutils/error.h> |
27 | 27 | ||
28 | const char *mu_program_name; | ||
29 | |||
30 | void | ||
31 | mu_set_program_name (const char *name) | ||
32 | { | ||
33 | char *progname = strrchr (name, '/'); | ||
34 | if (progname) | ||
35 | progname++; | ||
36 | else | ||
37 | progname = name; | ||
38 | |||
39 | if (strlen (progname) > 3 && memcmp (progname, "lt-", 3) == 0) | ||
40 | progname += 3; | ||
41 | |||
42 | mu_program_name = progname; | ||
43 | } | ||
44 | |||
28 | int | 45 | int |
29 | mu_default_error_printer (const char *fmt, va_list ap) | 46 | mu_default_error_printer (const char *fmt, va_list ap) |
30 | { | 47 | { |
31 | int status; | 48 | if (mu_program_name) |
32 | status = vfprintf (stderr, fmt, ap); | 49 | fprintf (stderr, "%s: ", mu_program_name); |
33 | if (status >= 0) | 50 | vfprintf (stderr, fmt, ap); |
34 | { | 51 | fputc ('\n', stderr); |
35 | if (fputc ('\n', stderr) != EOF) | 52 | return 0; |
36 | status++; | ||
37 | } | ||
38 | return status; | ||
39 | } | 53 | } |
40 | 54 | ||
41 | int | 55 | int | ... | ... |
... | @@ -58,6 +58,7 @@ | ... | @@ -58,6 +58,7 @@ |
58 | #include <mailutils/nls.h> | 58 | #include <mailutils/nls.h> |
59 | #include <mailutils/stream.h> | 59 | #include <mailutils/stream.h> |
60 | #include <mailutils/filter.h> | 60 | #include <mailutils/filter.h> |
61 | #include <mailutils/sql.h> | ||
61 | 62 | ||
62 | #include <registrar0.h> | 63 | #include <registrar0.h> |
63 | 64 | ||
... | @@ -1479,3 +1480,19 @@ mutil_parse_field_map (const char *map, mu_assoc_t *passoc_tab, int *perr) | ... | @@ -1479,3 +1480,19 @@ mutil_parse_field_map (const char *map, mu_assoc_t *passoc_tab, int *perr) |
1479 | *perr = i; | 1480 | *perr = i; |
1480 | return rc; | 1481 | return rc; |
1481 | } | 1482 | } |
1483 | |||
1484 | /* FIXME: should it be here? */ | ||
1485 | int | ||
1486 | mu_sql_decode_password_type (const char *arg, enum mu_password_type *t) | ||
1487 | { | ||
1488 | if (strcmp (arg, "plain") == 0) | ||
1489 | *t = password_plaintext; | ||
1490 | else if (strcmp (arg, "hash") == 0) | ||
1491 | *t = password_hash; | ||
1492 | else if (strcmp (arg, "scrambled") == 0) | ||
1493 | *t = password_scrambled; | ||
1494 | else | ||
1495 | return 1; | ||
1496 | return 0; | ||
1497 | } | ||
1498 | ... | ... |
... | @@ -40,7 +40,6 @@ | ... | @@ -40,7 +40,6 @@ |
40 | #include <mailutils/list.h> | 40 | #include <mailutils/list.h> |
41 | #include <mailutils/iterator.h> | 41 | #include <mailutils/iterator.h> |
42 | #include <mailutils/mailbox.h> | 42 | #include <mailutils/mailbox.h> |
43 | #include <mailutils/argp.h> | ||
44 | #include <mailutils/mu_auth.h> | 43 | #include <mailutils/mu_auth.h> |
45 | #include <mailutils/errno.h> | 44 | #include <mailutils/errno.h> |
46 | 45 | ||
... | @@ -138,7 +137,6 @@ mu_authenticate_system (struct mu_auth_data **return_data MU_ARG_UNUSED, | ... | @@ -138,7 +137,6 @@ mu_authenticate_system (struct mu_auth_data **return_data MU_ARG_UNUSED, |
138 | struct mu_auth_module mu_auth_system_module = { | 137 | struct mu_auth_module mu_auth_system_module = { |
139 | "system", | 138 | "system", |
140 | NULL, | 139 | NULL, |
141 | NULL, | ||
142 | mu_authenticate_system, | 140 | mu_authenticate_system, |
143 | NULL, | 141 | NULL, |
144 | mu_auth_system_by_name, | 142 | mu_auth_system_by_name, |
... | @@ -151,7 +149,6 @@ struct mu_auth_module mu_auth_system_module = { | ... | @@ -151,7 +149,6 @@ struct mu_auth_module mu_auth_system_module = { |
151 | struct mu_auth_module mu_auth_generic_module = { | 149 | struct mu_auth_module mu_auth_generic_module = { |
152 | "generic", | 150 | "generic", |
153 | NULL, | 151 | NULL, |
154 | NULL, | ||
155 | mu_authenticate_generic, | 152 | mu_authenticate_generic, |
156 | NULL, | 153 | NULL, |
157 | mu_auth_nosupport, | 154 | mu_auth_nosupport, | ... | ... |
... | @@ -24,7 +24,7 @@ SUBDIRS = testsuite | ... | @@ -24,7 +24,7 @@ SUBDIRS = testsuite |
24 | bin_PROGRAMS = messages | 24 | bin_PROGRAMS = messages |
25 | messages_SOURCES = messages.c | 25 | messages_SOURCES = messages.c |
26 | messages_LDADD =\ | 26 | messages_LDADD =\ |
27 | ../lib/libmuaux.la\ | 27 | ${MU_APP_LIBRARIES}\ |
28 | ${MU_LIB_MBOX}\ | 28 | ${MU_LIB_MBOX}\ |
29 | ${MU_LIB_IMAP}\ | 29 | ${MU_LIB_IMAP}\ |
30 | ${MU_LIB_POP}\ | 30 | ${MU_LIB_POP}\ | ... | ... |
... | @@ -27,6 +27,7 @@ | ... | @@ -27,6 +27,7 @@ |
27 | #endif | 27 | #endif |
28 | 28 | ||
29 | #include <mailutils/mailutils.h> | 29 | #include <mailutils/mailutils.h> |
30 | #include "muinit.h" | ||
30 | 31 | ||
31 | static int messages_count (const char *); | 32 | static int messages_count (const char *); |
32 | 33 | ||
... | @@ -47,9 +48,6 @@ static const char *argp_capa[] = { | ... | @@ -47,9 +48,6 @@ static const char *argp_capa[] = { |
47 | "common", | 48 | "common", |
48 | "license", | 49 | "license", |
49 | "mailbox", | 50 | "mailbox", |
50 | #ifdef WITH_TLS | ||
51 | "tls", | ||
52 | #endif | ||
53 | NULL | 51 | NULL |
54 | }; | 52 | }; |
55 | 53 | ||
... | @@ -72,6 +70,7 @@ parse_opt (int key, char *arg, struct argp_state *state) | ... | @@ -72,6 +70,7 @@ parse_opt (int key, char *arg, struct argp_state *state) |
72 | case 's': | 70 | case 's': |
73 | silent = 1; | 71 | silent = 1; |
74 | break; | 72 | break; |
73 | |||
75 | case ARGP_KEY_ARG: | 74 | case ARGP_KEY_ARG: |
76 | args->argv = realloc (args->argv, | 75 | args->argv = realloc (args->argv, |
77 | sizeof (char *) * (state->arg_num + 2)); | 76 | sizeof (char *) * (state->arg_num + 2)); |
... | @@ -79,6 +78,7 @@ parse_opt (int key, char *arg, struct argp_state *state) | ... | @@ -79,6 +78,7 @@ parse_opt (int key, char *arg, struct argp_state *state) |
79 | args->argv[state->arg_num + 1] = NULL; | 78 | args->argv[state->arg_num + 1] = NULL; |
80 | args->argc++; | 79 | args->argc++; |
81 | break; | 80 | break; |
81 | |||
82 | default: | 82 | default: |
83 | return ARGP_ERR_UNKNOWN; | 83 | return ARGP_ERR_UNKNOWN; |
84 | } | 84 | } |
... | @@ -104,15 +104,16 @@ main (int argc, char **argv) | ... | @@ -104,15 +104,16 @@ main (int argc, char **argv) |
104 | /* Native Language Support */ | 104 | /* Native Language Support */ |
105 | mu_init_nls (); | 105 | mu_init_nls (); |
106 | 106 | ||
107 | mu_argp_init (program_version, NULL); | ||
108 | #ifdef WITH_TLS | ||
109 | mu_tls_init_client_argp (); | ||
110 | #endif | ||
111 | mu_argp_parse (&argp, &argc, &argv, 0, argp_capa, NULL, &args); | ||
112 | |||
113 | /* register the formats. */ | 107 | /* register the formats. */ |
114 | mu_register_all_mbox_formats (); | 108 | mu_register_all_mbox_formats (); |
115 | 109 | ||
110 | #ifdef WITH_TLS | ||
111 | mu_gocs_register ("tls", mu_tls_module_init); | ||
112 | #endif | ||
113 | mu_argp_init (program_version, NULL); | ||
114 | if (mu_app_init (&argp, argp_capa, NULL, argc, argv, 0, NULL, &args)) | ||
115 | exit (1); | ||
116 | |||
116 | if (args.argc < 1 && messages_count (NULL) < 0) | 117 | if (args.argc < 1 && messages_count (NULL) < 0) |
117 | err = 1; | 118 | err = 1; |
118 | else if (args.argc >= 1) | 119 | else if (args.argc >= 1) | ... | ... |
... | @@ -27,6 +27,7 @@ | ... | @@ -27,6 +27,7 @@ |
27 | #include <mh.h> | 27 | #include <mh.h> |
28 | #include <string.h> | 28 | #include <string.h> |
29 | #include <mailutils/argcv.h> | 29 | #include <mailutils/argcv.h> |
30 | #include "argp.h" | ||
30 | 31 | ||
31 | static error_t | 32 | static error_t |
32 | parse_opt (int key, char *arg, struct argp_state *state) | 33 | parse_opt (int key, char *arg, struct argp_state *state) | ... | ... |
... | @@ -16,8 +16,9 @@ | ... | @@ -16,8 +16,9 @@ |
16 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, | 16 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, |
17 | MA 02110-1301 USA */ | 17 | MA 02110-1301 USA */ |
18 | 18 | ||
19 | #include <mailutils/argp.h> | ||
20 | #include <mailutils/nls.h> | 19 | #include <mailutils/nls.h> |
20 | #include "argp.h" | ||
21 | #include "muinit.h" | ||
21 | 22 | ||
22 | #define MH_OPT_BOOL 1 | 23 | #define MH_OPT_BOOL 1 |
23 | #define MH_OPT_ARG 2 | 24 | #define MH_OPT_ARG 2 |
... | @@ -189,5 +190,6 @@ int mh_argp_parse (int *argc, char **argv[], | ... | @@ -189,5 +190,6 @@ int mh_argp_parse (int *argc, char **argv[], |
189 | struct mh_option *mh_option, | 190 | struct mh_option *mh_option, |
190 | char *argp_doc, char *doc, | 191 | char *argp_doc, char *doc, |
191 | int (*handler)(), void *closure, int *index); | 192 | int (*handler)(), void *closure, int *index); |
193 | |||
192 | void mh_help (struct mh_option *mh_option, const char *doc); | 194 | void mh_help (struct mh_option *mh_option, const char *doc); |
193 | void mh_license (const char *name); | 195 | void mh_license (const char *name); | ... | ... |
... | @@ -54,9 +54,9 @@ ismydomain (char *p) | ... | @@ -54,9 +54,9 @@ ismydomain (char *p) |
54 | int | 54 | int |
55 | mh_alias_expand (const char *str, mu_address_t *paddr, int *incl) | 55 | mh_alias_expand (const char *str, mu_address_t *paddr, int *incl) |
56 | { | 56 | { |
57 | size_t argc; | 57 | int argc; |
58 | char **argv; | 58 | char **argv; |
59 | size_t i; | 59 | int i; |
60 | char *buf; | 60 | char *buf; |
61 | mu_address_t exaddr = NULL; | 61 | mu_address_t exaddr = NULL; |
62 | 62 | ... | ... |
... | @@ -49,7 +49,7 @@ mimetypes-lex.c: $(srcdir)/mimetypes.l mimetypes-decl.h | ... | @@ -49,7 +49,7 @@ mimetypes-lex.c: $(srcdir)/mimetypes.l mimetypes-decl.h |
49 | BUILT_SOURCES = mimetypes-gram.c mimetypes-lex.c mimetypes-decl.h | 49 | BUILT_SOURCES = mimetypes-gram.c mimetypes-lex.c mimetypes-decl.h |
50 | 50 | ||
51 | mimeview_LDADD = \ | 51 | mimeview_LDADD = \ |
52 | ../lib/libmuaux.la \ | 52 | ${MU_APP_LIBRARIES}\ |
53 | ${MU_LIB_MAILUTILS}\ | 53 | ${MU_LIB_MAILUTILS}\ |
54 | @LTLIBINTL@ | 54 | @LTLIBINTL@ |
55 | 55 | ... | ... |
... | @@ -25,6 +25,8 @@ | ... | @@ -25,6 +25,8 @@ |
25 | #include <sys/stat.h> | 25 | #include <sys/stat.h> |
26 | #include <sys/wait.h> | 26 | #include <sys/wait.h> |
27 | 27 | ||
28 | #include "muinit.h" | ||
29 | |||
28 | const char *program_version = "mimeview (" PACKAGE_STRING ")"; | 30 | const char *program_version = "mimeview (" PACKAGE_STRING ")"; |
29 | static char doc[] = N_("GNU mimeview -- display files, using mailcap mechanism.") | 31 | static char doc[] = N_("GNU mimeview -- display files, using mailcap mechanism.") |
30 | "\v" | 32 | "\v" |
... | @@ -262,8 +264,9 @@ main (int argc, char **argv) | ... | @@ -262,8 +264,9 @@ main (int argc, char **argv) |
262 | 264 | ||
263 | mu_init_nls (); | 265 | mu_init_nls (); |
264 | mu_argp_init (program_version, NULL); | 266 | mu_argp_init (program_version, NULL); |
265 | mu_argp_set_config_param (mimeview_cfg_param); | 267 | if (mu_app_init (&argp, capa, mimeview_cfg_param, |
266 | mu_argp_parse (&argp, &argc, &argv, 0, capa, &index, NULL); | 268 | argc, argv, 0, &index, NULL)) |
269 | exit (1); | ||
267 | 270 | ||
268 | argc -= index; | 271 | argc -= index; |
269 | argv += index; | 272 | argv += index; | ... | ... |
... | @@ -22,7 +22,7 @@ INCLUDES = @MU_COMMON_INCLUDES@ @MU_AUTHINCS@ | ... | @@ -22,7 +22,7 @@ INCLUDES = @MU_COMMON_INCLUDES@ @MU_AUTHINCS@ |
22 | bin_PROGRAMS = movemail | 22 | bin_PROGRAMS = movemail |
23 | 23 | ||
24 | movemail_LDADD = \ | 24 | movemail_LDADD = \ |
25 | ../lib/libmuaux.la\ | 25 | ${MU_APP_LIBRARIES}\ |
26 | ${MU_LIB_MBOX}\ | 26 | ${MU_LIB_MBOX}\ |
27 | ${MU_LIB_IMAP}\ | 27 | ${MU_LIB_IMAP}\ |
28 | ${MU_LIB_POP}\ | 28 | ${MU_LIB_POP}\ | ... | ... |
... | @@ -25,6 +25,7 @@ | ... | @@ -25,6 +25,7 @@ |
25 | #include <mailutils/mailutils.h> | 25 | #include <mailutils/mailutils.h> |
26 | #include <mailutils/tls.h> | 26 | #include <mailutils/tls.h> |
27 | #include <mu_asprintf.h> | 27 | #include <mu_asprintf.h> |
28 | #include "muinit.h" | ||
28 | 29 | ||
29 | const char *program_version = "movemail (" PACKAGE_STRING ")"; | 30 | const char *program_version = "movemail (" PACKAGE_STRING ")"; |
30 | static char doc[] = N_("GNU movemail"); | 31 | static char doc[] = N_("GNU movemail"); |
... | @@ -85,13 +86,10 @@ struct mu_cfg_param movemail_cfg_param[] = { | ... | @@ -85,13 +86,10 @@ struct mu_cfg_param movemail_cfg_param[] = { |
85 | }; | 86 | }; |
86 | 87 | ||
87 | 88 | ||
88 | static const char *mail_capa[] = { | 89 | static const char *movemail_capa[] = { |
89 | "common", | 90 | "common", |
90 | "license", | 91 | "license", |
91 | "mailbox", | 92 | "mailbox", |
92 | #ifdef WITH_TLS | ||
93 | "tls", | ||
94 | #endif | ||
95 | NULL | 93 | NULL |
96 | }; | 94 | }; |
97 | 95 | ||
... | @@ -292,12 +290,13 @@ main (int argc, char **argv) | ... | @@ -292,12 +290,13 @@ main (int argc, char **argv) |
292 | 290 | ||
293 | mu_error_set_print (movemail_error_printer); | 291 | mu_error_set_print (movemail_error_printer); |
294 | 292 | ||
295 | mu_argp_init (program_version, NULL); | ||
296 | #ifdef WITH_TLS | 293 | #ifdef WITH_TLS |
297 | mu_tls_init_client_argp (); | 294 | mu_gocs_register ("tls", mu_tls_module_init); |
298 | #endif | 295 | #endif |
299 | mu_argp_set_config_param (movemail_cfg_param); | 296 | mu_argp_init (program_version, NULL); |
300 | mu_argp_parse (&argp, &argc, &argv, 0, mail_capa, &index, NULL); | 297 | if (mu_app_init (&argp, movemail_capa, movemail_cfg_param, |
298 | argc, argv, 0, NULL, NULL)) | ||
299 | exit (1); | ||
301 | 300 | ||
302 | argc -= index; | 301 | argc -= index; |
303 | argv += index; | 302 | argv += index; | ... | ... |
... | @@ -29,6 +29,25 @@ imap4d/signal.c | ... | @@ -29,6 +29,25 @@ imap4d/signal.c |
29 | imap4d/util.c | 29 | imap4d/util.c |
30 | lib/mailcap.c | 30 | lib/mailcap.c |
31 | lib/xmalloc.c | 31 | lib/xmalloc.c |
32 | libargp/mu_argp.c | ||
33 | libargp/auth.c | ||
34 | libargp/cmdline.c | ||
35 | libargp/common.c | ||
36 | libargp/gsasl.c | ||
37 | libargp/pam.c | ||
38 | libargp/radius.c | ||
39 | libargp/sql.c | ||
40 | libargp/tls.c | ||
41 | libargp/virtdomain.c | ||
42 | libcfg/auth.c | ||
43 | libcfg/common.c | ||
44 | libcfg/gsasl.c | ||
45 | libcfg/init.c | ||
46 | libcfg/pam.c | ||
47 | libcfg/radius.c | ||
48 | libcfg/sql.c | ||
49 | libcfg/tls.c | ||
50 | libcfg/virtdomain.c | ||
32 | libproto/imap/folder.c | 51 | libproto/imap/folder.c |
33 | libproto/mbox/mbox.c | 52 | libproto/mbox/mbox.c |
34 | libsieve/actions.c | 53 | libsieve/actions.c |
... | @@ -82,7 +101,6 @@ mailbox/file_stream.c | ... | @@ -82,7 +101,6 @@ mailbox/file_stream.c |
82 | mailbox/filter_iconv.c | 101 | mailbox/filter_iconv.c |
83 | mailbox/getopt.c | 102 | mailbox/getopt.c |
84 | mailbox/message.c | 103 | mailbox/message.c |
85 | mailbox/mu_argp.c | ||
86 | mailbox/mu_auth.c | 104 | mailbox/mu_auth.c |
87 | mailbox/mutil.c | 105 | mailbox/mutil.c |
88 | messages/messages.c | 106 | messages/messages.c | ... | ... |
... | @@ -50,7 +50,7 @@ pop3d_SOURCES =\ | ... | @@ -50,7 +50,7 @@ pop3d_SOURCES =\ |
50 | user.c | 50 | user.c |
51 | 51 | ||
52 | pop3d_LDADD = \ | 52 | pop3d_LDADD = \ |
53 | ../lib/libmuaux.la\ | 53 | ${MU_APP_LIBRARIES}\ |
54 | ${MU_LIB_MBOX}\ | 54 | ${MU_LIB_MBOX}\ |
55 | ${MU_LIB_MH}\ | 55 | ${MU_LIB_MH}\ |
56 | ${MU_LIB_MAILDIR}\ | 56 | ${MU_LIB_MAILDIR}\ |
... | @@ -60,7 +60,7 @@ pop3d_LDADD = \ | ... | @@ -60,7 +60,7 @@ pop3d_LDADD = \ |
60 | @MU_COMMON_LIBRARIES@ | 60 | @MU_COMMON_LIBRARIES@ |
61 | 61 | ||
62 | popauth_SOURCES = popauth.c | 62 | popauth_SOURCES = popauth.c |
63 | popauth_LDADD = ../lib/libmuaux.la ${MU_LIB_MAILUTILS} @MU_COMMON_LIBRARIES@ | 63 | popauth_LDADD = ${MU_APP_LIBRARIES} ${MU_LIB_MAILUTILS} @MU_COMMON_LIBRARIES@ |
64 | pop3d_DEPENDENCIES = \ | 64 | pop3d_DEPENDENCIES = \ |
65 | @MU_AUTHLIBS_DEPENDENCY@ \ | 65 | @MU_AUTHLIBS_DEPENDENCY@ \ |
66 | ../lib/libmuaux.la \ | 66 | ../lib/libmuaux.la \ | ... | ... |
... | @@ -18,6 +18,7 @@ | ... | @@ -18,6 +18,7 @@ |
18 | MA 02110-1301 USA */ | 18 | MA 02110-1301 USA */ |
19 | 19 | ||
20 | #include "pop3d.h" | 20 | #include "pop3d.h" |
21 | #include "muinit.h" | ||
21 | 22 | ||
22 | static mu_stream_t istream, ostream; | 23 | static mu_stream_t istream, ostream; |
23 | 24 | ||
... | @@ -215,7 +216,7 @@ pop3d_outf (const char *fmt, ...) | ... | @@ -215,7 +216,7 @@ pop3d_outf (const char *fmt, ...) |
215 | if (!buf) | 216 | if (!buf) |
216 | pop3d_abquit (ERR_NO_MEM); | 217 | pop3d_abquit (ERR_NO_MEM); |
217 | 218 | ||
218 | if (daemon_param.transcript) | 219 | if (mu_gocs_daemon.transcript) |
219 | syslog (LOG_DEBUG, "sent: %s", buf); | 220 | syslog (LOG_DEBUG, "sent: %s", buf); |
220 | 221 | ||
221 | rc = mu_stream_sequential_write (ostream, buf, strlen (buf)); | 222 | rc = mu_stream_sequential_write (ostream, buf, strlen (buf)); |
... | @@ -239,7 +240,7 @@ pop3d_readline (char *buffer, size_t size) | ... | @@ -239,7 +240,7 @@ pop3d_readline (char *buffer, size_t size) |
239 | int rc; | 240 | int rc; |
240 | size_t nbytes; | 241 | size_t nbytes; |
241 | 242 | ||
242 | alarm (daemon_param.timeout); | 243 | alarm (mu_gocs_daemon.timeout); |
243 | rc = mu_stream_sequential_readline (istream, buffer, size, &nbytes); | 244 | rc = mu_stream_sequential_readline (istream, buffer, size, &nbytes); |
244 | alarm (0); | 245 | alarm (0); |
245 | 246 | ||
... | @@ -258,7 +259,7 @@ pop3d_readline (char *buffer, size_t size) | ... | @@ -258,7 +259,7 @@ pop3d_readline (char *buffer, size_t size) |
258 | pop3d_abquit (ERR_NO_OFILE); | 259 | pop3d_abquit (ERR_NO_OFILE); |
259 | } | 260 | } |
260 | 261 | ||
261 | if (daemon_param.transcript) | 262 | if (mu_gocs_daemon.transcript) |
262 | syslog (LOG_DEBUG, "recv: %s", buffer); | 263 | syslog (LOG_DEBUG, "recv: %s", buffer); |
263 | 264 | ||
264 | /* Caller should not free () this ... should we strdup() then? */ | 265 | /* Caller should not free () this ... should we strdup() then? */ | ... | ... |
... | @@ -18,13 +18,15 @@ | ... | @@ -18,13 +18,15 @@ |
18 | MA 02110-1301 USA */ | 18 | MA 02110-1301 USA */ |
19 | 19 | ||
20 | #include "pop3d.h" | 20 | #include "pop3d.h" |
21 | #include "mailutils/pam.h" | ||
22 | #include "muinit.h" | ||
21 | 23 | ||
22 | mu_mailbox_t mbox; | 24 | mu_mailbox_t mbox; |
23 | int state; | 25 | int state; |
24 | char *username; | 26 | char *username; |
25 | char *md5shared; | 27 | char *md5shared; |
26 | 28 | ||
27 | struct daemon_param daemon_param = { | 29 | struct mu_gocs_daemon default_gocs_daemon = { |
28 | MODE_INTERACTIVE, /* Start in interactive (inetd) mode */ | 30 | MODE_INTERACTIVE, /* Start in interactive (inetd) mode */ |
29 | 20, /* Default maximum number of children */ | 31 | 20, /* Default maximum number of children */ |
30 | 110, /* Standard POP3 port */ | 32 | 110, /* Standard POP3 port */ |
... | @@ -161,9 +163,6 @@ static struct argp argp = { | ... | @@ -161,9 +163,6 @@ static struct argp argp = { |
161 | static const char *pop3d_argp_capa[] = { | 163 | static const char *pop3d_argp_capa[] = { |
162 | "daemon", | 164 | "daemon", |
163 | "auth", | 165 | "auth", |
164 | #ifdef WITH_TLS | ||
165 | "tls", | ||
166 | #endif /* WITH_TLS */ | ||
167 | "common", | 166 | "common", |
168 | "mailbox", | 167 | "mailbox", |
169 | "logging", | 168 | "logging", |
... | @@ -248,26 +247,28 @@ main (int argc, char **argv) | ... | @@ -248,26 +247,28 @@ main (int argc, char **argv) |
248 | /* Native Language Support */ | 247 | /* Native Language Support */ |
249 | mu_init_nls (); | 248 | mu_init_nls (); |
250 | 249 | ||
251 | mu_argp_init (program_version, NULL); | ||
252 | MU_AUTH_REGISTER_ALL_MODULES(); | 250 | MU_AUTH_REGISTER_ALL_MODULES(); |
253 | /* Register the desired formats. */ | 251 | /* Register the desired formats. */ |
254 | mu_register_local_mbox_formats (); | 252 | mu_register_local_mbox_formats (); |
255 | 253 | ||
256 | #ifdef WITH_TLS | 254 | #ifdef WITH_TLS |
257 | mu_tls_init_argp (); | 255 | mu_gocs_register ("tls", mu_tls_module_init); |
258 | #endif /* WITH_TLS */ | 256 | #endif /* WITH_TLS */ |
259 | mu_argp_set_config_param (pop3d_cfg_param); | 257 | mu_gocs_daemon = default_gocs_daemon; |
260 | mu_argp_parse (&argp, &argc, &argv, 0, pop3d_argp_capa, NULL, &daemon_param); | 258 | mu_argp_init (program_version, NULL); |
259 | if (mu_app_init (&argp, pop3d_argp_capa, pop3d_cfg_param, | ||
260 | argc, argv, 0, NULL, NULL)) | ||
261 | exit (1); | ||
261 | 262 | ||
262 | if (expire == 0) | 263 | if (expire == 0) |
263 | expire_on_exit = 1; | 264 | expire_on_exit = 1; |
264 | 265 | ||
265 | #ifdef USE_LIBPAM | 266 | #ifdef USE_LIBPAM |
266 | if (!pam_service) | 267 | if (!mu_pam_service) |
267 | pam_service = "gnu-pop3d"; | 268 | mu_pam_service = "gnu-pop3d"; |
268 | #endif | 269 | #endif |
269 | 270 | ||
270 | if (daemon_param.mode == MODE_INTERACTIVE && isatty (0)) | 271 | if (mu_gocs_daemon.mode == MODE_INTERACTIVE && isatty (0)) |
271 | { | 272 | { |
272 | /* If input is a tty, switch to debug mode */ | 273 | /* If input is a tty, switch to debug mode */ |
273 | debug_mode = 1; | 274 | debug_mode = 1; |
... | @@ -300,7 +301,7 @@ main (int argc, char **argv) | ... | @@ -300,7 +301,7 @@ main (int argc, char **argv) |
300 | signal (SIGPIPE, pop3d_signal); | 301 | signal (SIGPIPE, pop3d_signal); |
301 | signal (SIGABRT, pop3d_signal); | 302 | signal (SIGABRT, pop3d_signal); |
302 | 303 | ||
303 | if (daemon_param.mode == MODE_DAEMON) | 304 | if (mu_gocs_daemon.mode == MODE_DAEMON) |
304 | pop3d_daemon_init (); | 305 | pop3d_daemon_init (); |
305 | else | 306 | else |
306 | { | 307 | { |
... | @@ -316,9 +317,9 @@ main (int argc, char **argv) | ... | @@ -316,9 +317,9 @@ main (int argc, char **argv) |
316 | 317 | ||
317 | umask (S_IROTH | S_IWOTH | S_IXOTH); /* 007 */ | 318 | umask (S_IROTH | S_IWOTH | S_IXOTH); /* 007 */ |
318 | 319 | ||
319 | if (daemon_param.pidfile) | 320 | if (mu_gocs_daemon.pidfile) |
320 | { | 321 | { |
321 | mu_daemon_create_pidfile (daemon_param.pidfile); | 322 | mu_daemon_create_pidfile (mu_gocs_daemon.pidfile); |
322 | } | 323 | } |
323 | 324 | ||
324 | /* Check TLS environment, i.e. cert and key files */ | 325 | /* Check TLS environment, i.e. cert and key files */ |
... | @@ -329,8 +330,8 @@ main (int argc, char **argv) | ... | @@ -329,8 +330,8 @@ main (int argc, char **argv) |
329 | #endif /* WITH_TLS */ | 330 | #endif /* WITH_TLS */ |
330 | 331 | ||
331 | /* Actually run the daemon. */ | 332 | /* Actually run the daemon. */ |
332 | if (daemon_param.mode == MODE_DAEMON) | 333 | if (mu_gocs_daemon.mode == MODE_DAEMON) |
333 | pop3d_daemon (daemon_param.maxchildren, daemon_param.port); | 334 | pop3d_daemon (mu_gocs_daemon.maxchildren, mu_gocs_daemon.port); |
334 | /* exit (EXIT_SUCCESS) -- no way out of daemon except a signal. */ | 335 | /* exit (EXIT_SUCCESS) -- no way out of daemon except a signal. */ |
335 | else | 336 | else |
336 | status = pop3d_mainloop (fileno (stdin), stdin, stdout); | 337 | status = pop3d_mainloop (fileno (stdin), stdin, stdout); | ... | ... |
... | @@ -139,7 +139,6 @@ extern int expire_on_exit; | ... | @@ -139,7 +139,6 @@ extern int expire_on_exit; |
139 | # include <strings.h> | 139 | # include <strings.h> |
140 | #endif | 140 | #endif |
141 | 141 | ||
142 | #include <mailutils/argp.h> | ||
143 | #include <mailutils/attribute.h> | 142 | #include <mailutils/attribute.h> |
144 | #include <mailutils/body.h> | 143 | #include <mailutils/body.h> |
145 | #include <mailutils/daemon.h> | 144 | #include <mailutils/daemon.h> | ... | ... |
... | @@ -19,6 +19,7 @@ | ... | @@ -19,6 +19,7 @@ |
19 | #include "pop3d.h" | 19 | #include "pop3d.h" |
20 | #include <mailutils/argcv.h> | 20 | #include <mailutils/argcv.h> |
21 | #include <xalloc.h> | 21 | #include <xalloc.h> |
22 | #include "muinit.h" | ||
22 | 23 | ||
23 | int db_list (char *input_name, char *output_name); | 24 | int db_list (char *input_name, char *output_name); |
24 | int db_make (char *input_name, char *output_name); | 25 | int db_make (char *input_name, char *output_name); |
... | @@ -201,8 +202,9 @@ main(int argc, char **argv) | ... | @@ -201,8 +202,9 @@ main(int argc, char **argv) |
201 | mu_init_nls (); | 202 | mu_init_nls (); |
202 | 203 | ||
203 | mu_argp_init (program_version, NULL); | 204 | mu_argp_init (program_version, NULL); |
204 | mu_argp_parse (&argp, &argc, &argv, 0, | 205 | if (mu_app_init (&argp, popauth_argp_capa, NULL, |
205 | popauth_argp_capa, NULL, &adata); | 206 | argc, argv, 0, NULL, &adata)) |
207 | exit (1); | ||
206 | 208 | ||
207 | return (*ftab[adata.action]) (&adata); | 209 | return (*ftab[adata.action]) (&adata); |
208 | } | 210 | } | ... | ... |
... | @@ -25,7 +25,7 @@ bin_PROGRAMS = readmsg | ... | @@ -25,7 +25,7 @@ bin_PROGRAMS = readmsg |
25 | readmsg_SOURCES = readmsg.c msglist.c readmsg.h | 25 | readmsg_SOURCES = readmsg.c msglist.c readmsg.h |
26 | 26 | ||
27 | readmsg_LDADD =\ | 27 | readmsg_LDADD =\ |
28 | ../lib/libmuaux.la\ | 28 | ${MU_APP_LIBRARIES}\ |
29 | ${MU_LIB_MBOX}\ | 29 | ${MU_LIB_MBOX}\ |
30 | ${MU_LIB_IMAP}\ | 30 | ${MU_LIB_IMAP}\ |
31 | ${MU_LIB_POP}\ | 31 | ${MU_LIB_POP}\ | ... | ... |
... | @@ -23,6 +23,7 @@ | ... | @@ -23,6 +23,7 @@ |
23 | 23 | ||
24 | #include "readmsg.h" | 24 | #include "readmsg.h" |
25 | #include "xalloc.h" | 25 | #include "xalloc.h" |
26 | #include "muinit.h" | ||
26 | 27 | ||
27 | #define WEEDLIST_SEPARATOR " :," | 28 | #define WEEDLIST_SEPARATOR " :," |
28 | 29 | ||
... | @@ -61,9 +62,6 @@ static struct argp argp = { | ... | @@ -61,9 +62,6 @@ static struct argp argp = { |
61 | static const char *readmsg_argp_capa[] = { | 62 | static const char *readmsg_argp_capa[] = { |
62 | "common", | 63 | "common", |
63 | "mailbox", | 64 | "mailbox", |
64 | #ifdef WITH_TLS | ||
65 | "tls", | ||
66 | #endif | ||
67 | NULL | 65 | NULL |
68 | }; | 66 | }; |
69 | 67 | ||
... | @@ -276,17 +274,18 @@ main (int argc, char **argv) | ... | @@ -276,17 +274,18 @@ main (int argc, char **argv) |
276 | /* Native Language Support */ | 274 | /* Native Language Support */ |
277 | mu_init_nls (); | 275 | mu_init_nls (); |
278 | 276 | ||
279 | mu_argp_init (program_version, NULL); | ||
280 | #ifdef WITH_TLS | ||
281 | mu_tls_init_client_argp (); | ||
282 | #endif | ||
283 | mu_argp_set_config_param (readmsg_cfg_param); | ||
284 | mu_argp_parse (&argp, &argc, &argv, 0, readmsg_argp_capa, &index, NULL); | ||
285 | |||
286 | /* register the formats. */ | 277 | /* register the formats. */ |
287 | mu_register_all_mbox_formats (); | 278 | mu_register_all_mbox_formats (); |
288 | mu_register_extra_formats (); | 279 | mu_register_extra_formats (); |
289 | 280 | ||
281 | #ifdef WITH_TLS | ||
282 | mu_gocs_register ("tls", mu_tls_module_init); | ||
283 | #endif | ||
284 | mu_argp_init (program_version, NULL); | ||
285 | if (mu_app_init (&argp, readmsg_argp_capa, readmsg_cfg_param, | ||
286 | argc, argv, 0, &index, NULL)) | ||
287 | exit (1); | ||
288 | |||
290 | status = mu_mailbox_create_default (&mbox, mailbox_name); | 289 | status = mu_mailbox_create_default (&mbox, mailbox_name); |
291 | if (status != 0) | 290 | if (status != 0) |
292 | { | 291 | { | ... | ... |
... | @@ -47,7 +47,6 @@ | ... | @@ -47,7 +47,6 @@ |
47 | #include <mailutils/url.h> | 47 | #include <mailutils/url.h> |
48 | #include <mailutils/nls.h> | 48 | #include <mailutils/nls.h> |
49 | #include <mailutils/tls.h> | 49 | #include <mailutils/tls.h> |
50 | #include <mailutils/argp.h> | ||
51 | #include <mailutils/error.h> | 50 | #include <mailutils/error.h> |
52 | #include <mailutils/envelope.h> | 51 | #include <mailutils/envelope.h> |
53 | #include <mailutils/argcv.h> | 52 | #include <mailutils/argcv.h> | ... | ... |
... | @@ -23,7 +23,7 @@ SUBDIRS = testsuite | ... | @@ -23,7 +23,7 @@ SUBDIRS = testsuite |
23 | bin_PROGRAMS = sieve | 23 | bin_PROGRAMS = sieve |
24 | sieve_SOURCES = sieve.c | 24 | sieve_SOURCES = sieve.c |
25 | sieve_LDADD =\ | 25 | sieve_LDADD =\ |
26 | ../lib/libmuaux.la\ | 26 | ${MU_APP_LIBRARIES}\ |
27 | ${MU_LIB_SIEVE}\ | 27 | ${MU_LIB_SIEVE}\ |
28 | ${MU_LIB_MBOX}\ | 28 | ${MU_LIB_MBOX}\ |
29 | ${MU_LIB_IMAP}\ | 29 | ${MU_LIB_IMAP}\ | ... | ... |
... | @@ -34,7 +34,6 @@ | ... | @@ -34,7 +34,6 @@ |
34 | #include <mu_asprintf.h> | 34 | #include <mu_asprintf.h> |
35 | #include <mailutils/argcv.h> | 35 | #include <mailutils/argcv.h> |
36 | #include <mailutils/libsieve.h> | 36 | #include <mailutils/libsieve.h> |
37 | #include <mailutils/argp.h> | ||
38 | #include <mailutils/auth.h> | 37 | #include <mailutils/auth.h> |
39 | #include <mailutils/errno.h> | 38 | #include <mailutils/errno.h> |
40 | #include <mailutils/folder.h> | 39 | #include <mailutils/folder.h> |
... | @@ -46,6 +45,8 @@ | ... | @@ -46,6 +45,8 @@ |
46 | #include <mailutils/nls.h> | 45 | #include <mailutils/nls.h> |
47 | #include <mailutils/tls.h> | 46 | #include <mailutils/tls.h> |
48 | 47 | ||
48 | #include "muinit.h" | ||
49 | |||
49 | const char *program_version = "sieve (" PACKAGE_STRING ")"; | 50 | const char *program_version = "sieve (" PACKAGE_STRING ")"; |
50 | 51 | ||
51 | static char doc[] = | 52 | static char doc[] = |
... | @@ -283,10 +284,6 @@ static const char *sieve_argp_capa[] = | ... | @@ -283,10 +284,6 @@ static const char *sieve_argp_capa[] = |
283 | "license", | 284 | "license", |
284 | "logging", | 285 | "logging", |
285 | "mailer", | 286 | "mailer", |
286 | "sieve", | ||
287 | #ifdef WITH_TLS | ||
288 | "tls", | ||
289 | #endif | ||
290 | NULL | 287 | NULL |
291 | }; | 288 | }; |
292 | 289 | ||
... | @@ -389,9 +386,10 @@ main (int argc, char *argv[]) | ... | @@ -389,9 +386,10 @@ main (int argc, char *argv[]) |
389 | 386 | ||
390 | mu_argp_init (program_version, NULL); | 387 | mu_argp_init (program_version, NULL); |
391 | #ifdef WITH_TLS | 388 | #ifdef WITH_TLS |
392 | mu_tls_init_client_argp (); | 389 | mu_gocs_register ("tls", mu_tls_module_init); |
393 | #endif | 390 | #endif |
394 | mu_sieve_argp_init (); | 391 | mu_gocs_register ("sieve", mu_sieve_module_init); |
392 | |||
395 | mu_register_all_formats (); | 393 | mu_register_all_formats (); |
396 | 394 | ||
397 | tickets = mu_tilde_expansion ("~/.tickets", "/", NULL); | 395 | tickets = mu_tilde_expansion ("~/.tickets", "/", NULL); |
... | @@ -399,14 +397,9 @@ main (int argc, char *argv[]) | ... | @@ -399,14 +397,9 @@ main (int argc, char *argv[]) |
399 | debug_level = MU_DEBUG_ERROR; | 397 | debug_level = MU_DEBUG_ERROR; |
400 | log_facility = 0; | 398 | log_facility = 0; |
401 | 399 | ||
402 | mu_argp_set_config_param (sieve_cfg_param); | 400 | if (mu_app_init (&argp, sieve_argp_capa, sieve_cfg_param, |
403 | rc = mu_argp_parse (&argp, &argc, &argv, ARGP_IN_ORDER, sieve_argp_capa, | 401 | argc, argv, ARGP_IN_ORDER, NULL, NULL)) |
404 | 0, 0); | 402 | exit (1); |
405 | |||
406 | if (rc) | ||
407 | return 1; | ||
408 | |||
409 | mu_register_all_formats (); | ||
410 | 403 | ||
411 | /* Sieve interpreter setup. */ | 404 | /* Sieve interpreter setup. */ |
412 | rc = mu_sieve_machine_init (&mach, NULL); | 405 | rc = mu_sieve_machine_init (&mach, NULL); | ... | ... |
... | @@ -78,9 +78,9 @@ proc mu_init {args} { | ... | @@ -78,9 +78,9 @@ proc mu_init {args} { |
78 | set MU_FOLDER_DIR "$MU_DATA_DIR/folder" | 78 | set MU_FOLDER_DIR "$MU_DATA_DIR/folder" |
79 | 79 | ||
80 | if {[llength $args] == 1 && [lindex $args 0] == "-noflags"} { | 80 | if {[llength $args] == 1 && [lindex $args 0] == "-noflags"} { |
81 | set MU_TOOL_FLAGS "" | 81 | set MU_TOOL_FLAGS "--no-site-rcfile --no-user-rcfile" |
82 | } else { | 82 | } else { |
83 | set MU_TOOL_FLAGS "--mail-spool $MU_SPOOL_DIR" | 83 | set MU_TOOL_FLAGS "--mail-spool $MU_SPOOL_DIR --no-site-rcfile --no-user-rcfile" |
84 | for {set i 0} {$i < [llength $args]} {incr i} { | 84 | for {set i 0} {$i < [llength $args]} {incr i} { |
85 | append MU_TOOL_FLAGS " [lindex $args $i]" | 85 | append MU_TOOL_FLAGS " [lindex $args $i]" |
86 | } | 86 | } | ... | ... |
-
Please register or sign in to post a comment