* comsat/comsat.c, imap4d/imap4d.c, maidag/maidag.c,
pop3d/pop3d.c: Call mu_tcpwrapper_cfg_init. * include/mailutils/cfg.h (mu_cfg_section_add_container) (mu_cfg_section_add_params, mu_create_canned_section) (mu_create_canned_param, mu_get_canned_container): New functions. * lib/tcpwrap.c (mu_tcpwrapper_cfg_init): New function. * lib/tcpwrap.h (TCP_WRAPPERS_CONFIG): Change definition. * mailbox/cfg_driver.c (mu_create_canned_section) (mu_create_canned_param): Change prototypes. (add_parameters): Rename to mu_cfg_section_add_params, make extern. All callers changed.
Showing
9 changed files
with
116 additions
and
44 deletions
1 | 2007-12-11 Sergey Poznyakoff <gray@gnu.org.ua> | 1 | 2007-12-11 Sergey Poznyakoff <gray@gnu.org.ua> |
2 | 2 | ||
3 | * comsat/comsat.c, imap4d/imap4d.c, maidag/maidag.c, | ||
4 | pop3d/pop3d.c: Call mu_tcpwrapper_cfg_init. | ||
5 | |||
6 | * include/mailutils/cfg.h (mu_cfg_section_add_container) | ||
7 | (mu_cfg_section_add_params, mu_create_canned_section) | ||
8 | (mu_create_canned_param, mu_get_canned_container): New functions. | ||
9 | * lib/tcpwrap.c (mu_tcpwrapper_cfg_init): New function. | ||
10 | * lib/tcpwrap.h (TCP_WRAPPERS_CONFIG): Change definition. | ||
11 | * mailbox/cfg_driver.c (mu_create_canned_section) | ||
12 | (mu_create_canned_param): Change prototypes. | ||
13 | (add_parameters): Rename to mu_cfg_section_add_params, make | ||
14 | extern. All callers changed. | ||
15 | |||
16 | |||
3 | * include/mailutils/cfg.h (mu_cfg_section): New type. | 17 | * include/mailutils/cfg.h (mu_cfg_section): New type. |
4 | (struct mu_cfg_param.offset): New member | 18 | (struct mu_cfg_param.offset): New member |
5 | (mu_offsetof): New define | 19 | (mu_offsetof): New define | ... | ... |
... | @@ -150,6 +150,7 @@ main (int argc, char **argv) | ... | @@ -150,6 +150,7 @@ main (int argc, char **argv) |
150 | 150 | ||
151 | mu_argp_init (program_version, NULL); | 151 | mu_argp_init (program_version, NULL); |
152 | mu_gocs_daemon = default_gocs_daemon; | 152 | mu_gocs_daemon = default_gocs_daemon; |
153 | |||
153 | if (mu_app_init (&argp, comsat_argp_capa, NULL, argc, argv, 0, &ind, NULL)) | 154 | if (mu_app_init (&argp, comsat_argp_capa, NULL, argc, argv, 0, &ind, NULL)) |
154 | exit (1); | 155 | exit (1); |
155 | 156 | ... | ... |
... | @@ -324,6 +324,7 @@ main (int argc, char **argv) | ... | @@ -324,6 +324,7 @@ main (int argc, char **argv) |
324 | #ifdef WITH_GSASL | 324 | #ifdef WITH_GSASL |
325 | mu_gocs_register ("gsasl", mu_gsasl_module_init); | 325 | mu_gocs_register ("gsasl", mu_gsasl_module_init); |
326 | #endif | 326 | #endif |
327 | mu_tcpwrapper_cfg_init (); | ||
327 | mu_argp_init (program_version, NULL); | 328 | mu_argp_init (program_version, NULL); |
328 | if (mu_app_init (&argp, imap4d_capa, imap4d_cfg_param, | 329 | if (mu_app_init (&argp, imap4d_capa, imap4d_cfg_param, |
329 | argc, argv, 0, NULL, NULL)) | 330 | argc, argv, 0, NULL, NULL)) | ... | ... |
... | @@ -194,6 +194,16 @@ int mu_config_create_container (struct mu_cfg_cont **pcont, | ... | @@ -194,6 +194,16 @@ int mu_config_create_container (struct mu_cfg_cont **pcont, |
194 | int mu_config_clone_container (struct mu_cfg_cont *cont); | 194 | int mu_config_clone_container (struct mu_cfg_cont *cont); |
195 | void mu_config_destroy_container (struct mu_cfg_cont **pcont); | 195 | void mu_config_destroy_container (struct mu_cfg_cont **pcont); |
196 | 196 | ||
197 | int mu_cfg_section_add_container (struct mu_cfg_section *sect, | ||
198 | struct mu_cfg_cont *cont); | ||
199 | int mu_cfg_section_add_params (struct mu_cfg_section *sect, | ||
200 | struct mu_cfg_param *param); | ||
201 | |||
202 | |||
203 | int mu_create_canned_section (char *name, struct mu_cfg_section **psection); | ||
204 | int mu_create_canned_param (char *name, struct mu_cfg_param **pparam); | ||
205 | struct mu_cfg_cont *mu_get_canned_container (const char *name); | ||
206 | |||
197 | int mu_cfg_scan_tree (mu_cfg_tree_t *tree, struct mu_cfg_section *sections, | 207 | int mu_cfg_scan_tree (mu_cfg_tree_t *tree, struct mu_cfg_section *sections, |
198 | void *target, void *call_data); | 208 | void *target, void *call_data); |
199 | 209 | ... | ... |
... | @@ -87,8 +87,50 @@ mu_tcpwrapper_access (int fd) | ... | @@ -87,8 +87,50 @@ mu_tcpwrapper_access (int fd) |
87 | return hosts_access (&req); | 87 | return hosts_access (&req); |
88 | } | 88 | } |
89 | 89 | ||
90 | struct mu_cfg_param tcpwrapper_param[] = { | ||
91 | { "enable", mu_cfg_bool, &mu_tcp_wrapper_enable, 0, NULL, | ||
92 | N_("Enable TCP wrapper access control. Default is \"yes\".") }, | ||
93 | { "daemon", mu_cfg_string, &mu_tcp_wrapper_daemon, 0, NULL, | ||
94 | N_("Set daemon name for TCP wrapper lookups. Default is program name."), | ||
95 | N_("name") }, | ||
96 | { "allow-table", mu_cfg_callback, NULL, 0, | ||
97 | mu_tcp_wrapper_cb_hosts_allow, | ||
98 | N_("Use file for positive client address access control " | ||
99 | "(default: /etc/hosts.allow)."), | ||
100 | N_("file") }, | ||
101 | { "deny-table", mu_cfg_callback, NULL, 0, | ||
102 | mu_tcp_wrapper_cb_hosts_deny, | ||
103 | N_("Use file for negative client address access control " | ||
104 | "(default: /etc/hosts.deny)."), | ||
105 | N_("file") }, | ||
106 | { "allow-syslog-level", mu_cfg_callback, NULL, 0, | ||
107 | mu_tcp_wrapper_cb_hosts_allow_syslog, | ||
108 | N_("Log host allows at this syslog level. See logging { facility } for " | ||
109 | "a description of argument syntax."), | ||
110 | N_("level") }, | ||
111 | { "allow-deny-level", mu_cfg_callback, NULL, 0, | ||
112 | mu_tcp_wrapper_cb_hosts_deny_syslog, | ||
113 | N_("Log host denies at this syslog level. See logging { facility } for " | ||
114 | "a description of argument syntax."), | ||
115 | N_("level") }, | ||
116 | { NULL } | ||
117 | }; | ||
118 | |||
119 | void | ||
120 | mu_tcpwrapper_cfg_init () | ||
121 | { | ||
122 | struct mu_cfg_section *section; | ||
123 | mu_create_canned_section ("tcp-wrappers", §ion); | ||
124 | mu_cfg_section_add_params (section, tcpwrapper_param); | ||
125 | } | ||
126 | |||
90 | #else | 127 | #else |
91 | 128 | ||
129 | void | ||
130 | mu_tcpwrapper_cfg_init () | ||
131 | { | ||
132 | } | ||
133 | |||
92 | int | 134 | int |
93 | mu_tcpwrapper_access (int fd) | 135 | mu_tcpwrapper_access (int fd) |
94 | { | 136 | { | ... | ... |
... | @@ -31,33 +31,10 @@ extern int mu_tcp_wrapper_cb_hosts_deny_syslog (mu_debug_t debug, void *data, | ... | @@ -31,33 +31,10 @@ extern int mu_tcp_wrapper_cb_hosts_deny_syslog (mu_debug_t debug, void *data, |
31 | char *arg); | 31 | char *arg); |
32 | extern int mu_tcpwrapper_access (int fd); | 32 | extern int mu_tcpwrapper_access (int fd); |
33 | 33 | ||
34 | extern void mu_tcpwrapper_cfg_init (void); | ||
35 | |||
34 | #ifdef WITH_LIBWRAP | 36 | #ifdef WITH_LIBWRAP |
35 | # define TCP_WRAPPERS_CONFIG \ | 37 | # define TCP_WRAPPERS_CONFIG { "tcp-wrappers", mu_cfg_section }, |
36 | { "tcp-wrapper-enable", mu_cfg_bool, &mu_tcp_wrapper_enable, 0, NULL, \ | ||
37 | N_("Enable TCP wrapper access control. Default is \"yes\".") }, \ | ||
38 | { "tcp-wrapper-daemon", mu_cfg_string, &mu_tcp_wrapper_daemon, 0, NULL, \ | ||
39 | N_("Set daemon name for TCP wrapper lookups. Default is program name."), \ | ||
40 | N_("name") }, \ | ||
41 | { "hosts-allow-table", mu_cfg_callback, NULL, 0, \ | ||
42 | mu_tcp_wrapper_cb_hosts_allow, \ | ||
43 | N_("Use file for positive client address access control " \ | ||
44 | "(default: /etc/hosts.allow)."), \ | ||
45 | N_("file") }, \ | ||
46 | { "hosts-deny-table", mu_cfg_callback, NULL, 0, \ | ||
47 | mu_tcp_wrapper_cb_hosts_deny, \ | ||
48 | N_("Use file for negative client address access control " \ | ||
49 | "(default: /etc/hosts.deny)."), \ | ||
50 | N_("file") }, \ | ||
51 | { "hosts-allow-syslog-level", mu_cfg_callback, NULL, 0, \ | ||
52 | mu_tcp_wrapper_cb_hosts_allow_syslog, \ | ||
53 | N_("Log host allows at this syslog level. See logging { facility } for " \ | ||
54 | "a description of argument syntax."), \ | ||
55 | N_("level") }, \ | ||
56 | { "hosts-allow-deny-level", mu_cfg_callback, NULL, 0, \ | ||
57 | mu_tcp_wrapper_cb_hosts_deny_syslog, \ | ||
58 | N_("Log host denies at this syslog level. See logging { facility } for " \ | ||
59 | "a description of argument syntax."), \ | ||
60 | N_("level") }, | ||
61 | #else | 38 | #else |
62 | # define TCP_WRAPPERS_CONFIG | 39 | # define TCP_WRAPPERS_CONFIG |
63 | #endif | 40 | #endif | ... | ... |
... | @@ -457,7 +457,9 @@ main (int argc, char *argv[]) | ... | @@ -457,7 +457,9 @@ main (int argc, char *argv[]) |
457 | mu_gocs_register ("sieve", mu_sieve_module_init); | 457 | mu_gocs_register ("sieve", mu_sieve_module_init); |
458 | 458 | ||
459 | mu_gocs_daemon = daemon_param; | 459 | mu_gocs_daemon = daemon_param; |
460 | 460 | ||
461 | mu_tcpwrapper_cfg_init (); | ||
462 | |||
461 | /* Parse command line */ | 463 | /* Parse command line */ |
462 | mu_argp_init (program_version, NULL); | 464 | mu_argp_init (program_version, NULL); |
463 | if (mu_app_init (&argp, maidag_argp_capa, maidag_cfg_param, | 465 | if (mu_app_init (&argp, maidag_argp_capa, maidag_cfg_param, | ... | ... |
... | @@ -45,28 +45,40 @@ static void | ... | @@ -45,28 +45,40 @@ static void |
45 | alloc_section_tab () | 45 | alloc_section_tab () |
46 | { | 46 | { |
47 | if (!section_tab) | 47 | if (!section_tab) |
48 | mu_assoc_create (§ion_tab, sizeof (struct mu_cfg_cont *), | 48 | mu_assoc_create (§ion_tab, sizeof (struct mu_cfg_cont **), |
49 | MU_ASSOC_COPY_KEY); | 49 | MU_ASSOC_COPY_KEY); |
50 | } | 50 | } |
51 | 51 | ||
52 | int | 52 | int |
53 | mu_create_canned_section (struct mu_cfg_section *section) | 53 | mu_create_canned_section (char *name, struct mu_cfg_section **psection) |
54 | { | 54 | { |
55 | struct mu_cfg_cont *cont; | 55 | int rc; |
56 | struct mu_cfg_cont **pcont; | ||
56 | alloc_section_tab (); | 57 | alloc_section_tab (); |
57 | mu_config_create_container (&cont, mu_cfg_cont_section); | 58 | rc = mu_assoc_ref_install (section_tab, name, (void **)&pcont); |
58 | cont->v.section = *section; | 59 | if (rc == 0 || rc == MU_ERR_EXISTS) |
59 | return mu_assoc_install (section_tab, cont->v.section.ident, &cont); | 60 | { |
61 | mu_config_create_container (pcont, mu_cfg_cont_section); | ||
62 | *psection = &(*pcont)->v.section; | ||
63 | (*psection)->ident = name; | ||
64 | } | ||
65 | return rc; | ||
60 | } | 66 | } |
61 | 67 | ||
62 | int | 68 | int |
63 | mu_create_canned_param (struct mu_cfg_param *param) | 69 | mu_create_canned_param (char *name, struct mu_cfg_param **pparam) |
64 | { | 70 | { |
65 | struct mu_cfg_cont *cont; | 71 | int rc; |
72 | struct mu_cfg_cont **pcont; | ||
66 | alloc_section_tab (); | 73 | alloc_section_tab (); |
67 | mu_config_create_container (&cont, mu_cfg_cont_param); | 74 | rc = mu_assoc_ref_install (section_tab, name, (void **)&pcont); |
68 | cont->v.param = *param; | 75 | if (rc == 0 || rc == MU_ERR_EXISTS) |
69 | return mu_assoc_install (section_tab, cont->v.param.ident, &cont); | 76 | { |
77 | mu_config_create_container (pcont, mu_cfg_cont_param); | ||
78 | *pparam = &(*pcont)->v.param; | ||
79 | (*pparam)->ident = name; | ||
80 | } | ||
81 | return rc; | ||
70 | } | 82 | } |
71 | 83 | ||
72 | struct mu_cfg_cont * | 84 | struct mu_cfg_cont * |
... | @@ -210,13 +222,24 @@ mu_config_destroy_container (struct mu_cfg_cont **pcont) | ... | @@ -210,13 +222,24 @@ mu_config_destroy_container (struct mu_cfg_cont **pcont) |
210 | } | 222 | } |
211 | 223 | ||
212 | 224 | ||
213 | static int | 225 | int |
214 | add_parameters (struct mu_cfg_section *sect, struct mu_cfg_param *param) | 226 | mu_cfg_section_add_container (struct mu_cfg_section *sect, |
227 | struct mu_cfg_cont *cont) | ||
215 | { | 228 | { |
216 | if (!param) | 229 | if (!cont) |
217 | return 0; | 230 | return 0; |
218 | if (!sect->children) | 231 | if (!sect->children) |
219 | mu_list_create (§->children); | 232 | mu_list_create (§->children); |
233 | return mu_list_append (sect->children, cont); | ||
234 | } | ||
235 | |||
236 | int | ||
237 | mu_cfg_section_add_params (struct mu_cfg_section *sect, | ||
238 | struct mu_cfg_param *param) | ||
239 | { | ||
240 | if (!param) | ||
241 | return 0; | ||
242 | |||
220 | for (; param->ident; param++) | 243 | for (; param->ident; param++) |
221 | { | 244 | { |
222 | int rc; | 245 | int rc; |
... | @@ -241,7 +264,7 @@ add_parameters (struct mu_cfg_section *sect, struct mu_cfg_param *param) | ... | @@ -241,7 +264,7 @@ add_parameters (struct mu_cfg_section *sect, struct mu_cfg_param *param) |
241 | return rc; | 264 | return rc; |
242 | container->v.param = *param; | 265 | container->v.param = *param; |
243 | } | 266 | } |
244 | mu_list_append (sect->children, container); | 267 | mu_cfg_section_add_container (sect, container); |
245 | } | 268 | } |
246 | return 0; | 269 | return 0; |
247 | } | 270 | } |
... | @@ -335,13 +358,13 @@ _mu_config_register_section (struct mu_cfg_cont **proot, | ... | @@ -335,13 +358,13 @@ _mu_config_register_section (struct mu_cfg_cont **proot, |
335 | s->label = label ? strdup (label) : NULL; | 358 | s->label = label ? strdup (label) : NULL; |
336 | s->parser = parser; | 359 | s->parser = parser; |
337 | s->children = NULL; | 360 | s->children = NULL; |
338 | add_parameters (s, param); | 361 | mu_cfg_section_add_params (s, param); |
339 | if (psection) | 362 | if (psection) |
340 | *psection = s; | 363 | *psection = s; |
341 | } | 364 | } |
342 | else | 365 | else |
343 | { | 366 | { |
344 | add_parameters (parent, param); | 367 | mu_cfg_section_add_params (parent, param); |
345 | /* FIXME: */ | 368 | /* FIXME: */ |
346 | if (!parent->parser) | 369 | if (!parent->parser) |
347 | parent->parser = parser; | 370 | parent->parser = parser; | ... | ... |
... | @@ -260,6 +260,8 @@ main (int argc, char **argv) | ... | @@ -260,6 +260,8 @@ main (int argc, char **argv) |
260 | #ifdef WITH_TLS | 260 | #ifdef WITH_TLS |
261 | mu_gocs_register ("tls", mu_tls_module_init); | 261 | mu_gocs_register ("tls", mu_tls_module_init); |
262 | #endif /* WITH_TLS */ | 262 | #endif /* WITH_TLS */ |
263 | mu_tcpwrapper_cfg_init (); | ||
264 | |||
263 | mu_gocs_daemon = default_gocs_daemon; | 265 | mu_gocs_daemon = default_gocs_daemon; |
264 | mu_argp_init (program_version, NULL); | 266 | mu_argp_init (program_version, NULL); |
265 | if (mu_app_init (&argp, pop3d_argp_capa, pop3d_cfg_param, | 267 | if (mu_app_init (&argp, pop3d_argp_capa, pop3d_cfg_param, | ... | ... |
-
Please register or sign in to post a comment