* comsat/Makefile.am: Remove cfg.c
* comsat/cfg.c: Remove. * comsat/comsat.c: Use MU configuration and acls. * comsat/comsat.h: Include acl.h * libproto/maildir/mbox.c (maildir_qfetch): Bugfix.
Showing
10 changed files
with
185 additions
and
60 deletions
1 | 2007-12-30 Sergey Poznyakoff <gray@gnu.org.ua> | 1 | 2007-12-30 Sergey Poznyakoff <gray@gnu.org.ua> |
2 | 2 | ||
3 | * examples/config/comsat.conf: Remove obsolete example file. | ||
4 | * examples/config/mailutils.rc: Remove obsolete example file. | ||
5 | |||
6 | * comsat/oldcfg.c: New file. | ||
7 | * comsat/Makefile.am: Add oldcfg.c. | ||
8 | * comsat/comsat.c: Handle old -c option and provide a new option | ||
9 | for converting old-style config file to the new format. | ||
10 | |||
3 | * comsat/Makefile.am: Remove cfg.c | 11 | * comsat/Makefile.am: Remove cfg.c |
4 | * comsat/cfg.c: Remove. | 12 | * comsat/cfg.c: Remove. |
5 | * comsat/comsat.c: Use MU configuration and acls. | 13 | * comsat/comsat.c: Use MU configuration and acls. | ... | ... |
... | @@ -21,7 +21,8 @@ INCLUDES = @MU_COMMON_INCLUDES@ | ... | @@ -21,7 +21,8 @@ INCLUDES = @MU_COMMON_INCLUDES@ |
21 | 21 | ||
22 | sbin_PROGRAMS = comsatd | 22 | sbin_PROGRAMS = comsatd |
23 | 23 | ||
24 | comsatd_SOURCES = action.c comsat.c comsat.h | 24 | comsatd_SOURCES = action.c comsat.c comsat.h oldcfg.c |
25 | AM_CPPFLAGS = -DSYSCONFDIR=\"$(sysconfdir)\" | ||
25 | 26 | ||
26 | comsatd_LDADD = \ | 27 | comsatd_LDADD = \ |
27 | ${MU_APP_LIBRARIES}\ | 28 | ${MU_APP_LIBRARIES}\ | ... | ... |
... | @@ -58,12 +58,15 @@ static char doc[] = "GNU comsatd"; | ... | @@ -58,12 +58,15 @@ static char doc[] = "GNU comsatd"; |
58 | 58 | ||
59 | static struct argp_option options[] = | 59 | static struct argp_option options[] = |
60 | { | 60 | { |
61 | { "config", 'c', N_("FILE"), 0, N_("Read configuration from FILE"), 0 }, | 61 | { "config", 'c', N_("FILE"), OPTION_HIDDEN, "", 0 }, |
62 | { "convert-config", 'C', N_("FILE"), 0, | ||
63 | N_("Convert the configuration FILE to new format."), 0 }, | ||
62 | { "test", 't', NULL, 0, N_("Run in test mode"), 0 }, | 64 | { "test", 't', NULL, 0, N_("Run in test mode"), 0 }, |
63 | { NULL, 0, NULL, 0, NULL, 0 } | 65 | { NULL, 0, NULL, 0, NULL, 0 } |
64 | }; | 66 | }; |
65 | 67 | ||
66 | static error_t comsatd_parse_opt (int key, char *arg, struct argp_state *state); | 68 | static error_t comsatd_parse_opt (int key, char *arg, |
69 | struct argp_state *state); | ||
67 | 70 | ||
68 | static struct argp argp = { | 71 | static struct argp argp = { |
69 | options, | 72 | options, |
... | @@ -119,25 +122,6 @@ static int xargc; | ... | @@ -119,25 +122,6 @@ static int xargc; |
119 | static char **xargv; | 122 | static char **xargv; |
120 | int test_mode; | 123 | int test_mode; |
121 | 124 | ||
122 | static error_t | ||
123 | comsatd_parse_opt (int key, char *arg, struct argp_state *state) | ||
124 | { | ||
125 | switch (key) | ||
126 | { | ||
127 | case 'c': | ||
128 | /* FIXME: convert config to the new format and parse it */ | ||
129 | break; | ||
130 | |||
131 | case 't': | ||
132 | test_mode = 1; | ||
133 | break; | ||
134 | |||
135 | default: | ||
136 | return ARGP_ERR_UNKNOWN; | ||
137 | } | ||
138 | return 0; | ||
139 | } | ||
140 | |||
141 | struct mu_cfg_param comsat_cfg_param[] = { | 125 | struct mu_cfg_param comsat_cfg_param[] = { |
142 | { "allow-biffrc", mu_cfg_bool, &allow_biffrc, 0, NULL, | 126 | { "allow-biffrc", mu_cfg_bool, &allow_biffrc, 0, NULL, |
143 | N_("Read .biffrc file from the user home directory") }, | 127 | N_("Read .biffrc file from the user home directory") }, |
... | @@ -159,6 +143,48 @@ struct mu_cfg_param comsat_cfg_param[] = { | ... | @@ -159,6 +143,48 @@ struct mu_cfg_param comsat_cfg_param[] = { |
159 | { NULL } | 143 | { NULL } |
160 | }; | 144 | }; |
161 | 145 | ||
146 | static error_t | ||
147 | comsatd_parse_opt (int key, char *arg, struct argp_state *state) | ||
148 | { | ||
149 | switch (key) | ||
150 | { | ||
151 | case 'c': | ||
152 | { | ||
153 | char *cfg; | ||
154 | int fd; | ||
155 | FILE *fp; | ||
156 | |||
157 | mu_diag_output (MU_DIAG_WARNING, | ||
158 | _("The old configuration file format and the --config command\n" | ||
159 | "line option are deprecated and will be removed in the future\n" | ||
160 | "release. Please use --convert-config option to convert your\n" | ||
161 | "settings to the new format.")); | ||
162 | /* FIXME: Refer to the docs */ | ||
163 | |||
164 | fd = mu_tempfile (NULL, &cfg); | ||
165 | fp = fdopen (fd, "w"); | ||
166 | convert_config (arg, fp); | ||
167 | fclose (fp); | ||
168 | mu_get_config (cfg, mu_program_name, comsat_cfg_param, 0, NULL); | ||
169 | unlink (cfg); | ||
170 | free (cfg); | ||
171 | } | ||
172 | break; | ||
173 | |||
174 | case 'C': | ||
175 | convert_config (arg, stdout); | ||
176 | exit (0); | ||
177 | |||
178 | case 't': | ||
179 | test_mode = 1; | ||
180 | break; | ||
181 | |||
182 | default: | ||
183 | return ARGP_ERR_UNKNOWN; | ||
184 | } | ||
185 | return 0; | ||
186 | } | ||
187 | |||
162 | int | 188 | int |
163 | main (int argc, char **argv) | 189 | main (int argc, char **argv) |
164 | { | 190 | { | ... | ... |
... | @@ -79,3 +79,5 @@ extern char hostname[]; | ... | @@ -79,3 +79,5 @@ extern char hostname[]; |
79 | extern struct daemon_param daemon_param; | 79 | extern struct daemon_param daemon_param; |
80 | 80 | ||
81 | void run_user_action (FILE *tty, const char *cr, mu_message_t msg); | 81 | void run_user_action (FILE *tty, const char *cr, mu_message_t msg); |
82 | void convert_config (const char *config_file, FILE *outfile); | ||
83 | ... | ... |
comsat/oldcfg.c
0 → 100644
1 | /* This file is part of GNU Mailutils. | ||
2 | Copyright (C) 1998, 2001, 2002, 2005, 2007 Free Software Foundation, Inc. | ||
3 | |||
4 | GNU Mailutils is free software; you can redistribute it and/or modify | ||
5 | it under the terms of the GNU General Public License as published by | ||
6 | the Free Software Foundation; either version 3, or (at your option) | ||
7 | any later version. | ||
8 | |||
9 | GNU Mailutils 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 PARTICULAR PURPOSE. See the | ||
12 | GNU 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; see the file COPYING. If not, write | ||
16 | to the Free Software Foundation, Inc., 51 Franklin Street, | ||
17 | Fifth Floor, Boston, MA 02110-1301 USA. */ | ||
18 | |||
19 | #include "comsat.h" | ||
20 | |||
21 | static int | ||
22 | print_and_free_acl (void *item, void *data) | ||
23 | { | ||
24 | FILE *outfile = data; | ||
25 | char **argv = item; | ||
26 | |||
27 | fprintf (outfile, " %s from %s;\n", argv[1], argv[2]); | ||
28 | mu_argv_free (argv); | ||
29 | return 0; | ||
30 | } | ||
31 | |||
32 | void | ||
33 | convert_config (const char *config_file, FILE *outfile) | ||
34 | { | ||
35 | FILE *fp; | ||
36 | int line; | ||
37 | char buf[128]; | ||
38 | char *ptr; | ||
39 | mu_list_t aclist = NULL; | ||
40 | |||
41 | if (!config_file) | ||
42 | return; | ||
43 | |||
44 | fp = fopen (config_file, "r"); | ||
45 | if (!fp) | ||
46 | { | ||
47 | mu_error (_("Cannot open config file %s: %s"), config_file, | ||
48 | mu_strerror (errno)); | ||
49 | return; | ||
50 | } | ||
51 | |||
52 | fprintf (outfile, | ||
53 | "# Configuration file for GNU comsatd, converted from %s\n", | ||
54 | config_file); | ||
55 | fprintf (outfile, | ||
56 | "# Copy it to the comsatd configuration file\n"); | ||
57 | fprintf (outfile, | ||
58 | "# or to %s/mailutils.rc, in section `program %s'\n\n", | ||
59 | SYSCONFDIR, mu_program_name); | ||
60 | |||
61 | line = 0; | ||
62 | while ((ptr = fgets (buf, sizeof buf, fp))) | ||
63 | { | ||
64 | int len; | ||
65 | int argc; | ||
66 | char **argv; | ||
67 | |||
68 | line++; | ||
69 | len = strlen (ptr); | ||
70 | if (len > 0 && ptr[len-1] == '\n') | ||
71 | ptr[--len] = 0; | ||
72 | |||
73 | while (*ptr && isspace (*ptr)) | ||
74 | ptr++; | ||
75 | if (!*ptr || *ptr == '#') | ||
76 | { | ||
77 | fprintf (outfile, "%s\n", ptr); | ||
78 | continue; | ||
79 | } | ||
80 | |||
81 | mu_argcv_get (ptr, "", NULL, &argc, &argv); | ||
82 | if (argc < 2) | ||
83 | { | ||
84 | mu_error (_("%s:%d: too few fields"), config_file, line); | ||
85 | mu_argcv_free (argc, argv); | ||
86 | continue; | ||
87 | } | ||
88 | |||
89 | if (strcmp (argv[0], "acl") == 0) | ||
90 | { | ||
91 | if (!aclist) | ||
92 | mu_list_create (&aclist); | ||
93 | mu_list_append (aclist, argv); | ||
94 | } | ||
95 | else | ||
96 | { | ||
97 | mu_argcv_free (argc, argv); | ||
98 | fprintf (outfile, "%s;\n", ptr); | ||
99 | } | ||
100 | } | ||
101 | fclose (fp); | ||
102 | |||
103 | if (aclist) | ||
104 | { | ||
105 | fprintf (outfile, "acl {\n"); | ||
106 | mu_list_do (aclist, print_and_free_acl, outfile); | ||
107 | fprintf (outfile, "};\n"); | ||
108 | mu_list_destroy (&aclist); | ||
109 | } | ||
110 | } | ||
111 |
examples/config/comsat.conf
deleted
100644 → 0
1 | # This is an example configuration file for GNU comsatd utility. | ||
2 | # To use, run comsatd -c <path>/comsat.conf | ||
3 | |||
4 | ## General settings | ||
5 | # Dump on screen at most 5 lines of the message body | ||
6 | max-lines 5 | ||
7 | # Honour per-user .biffrc files | ||
8 | allow-biffrc yes | ||
9 | |||
10 | ## Security settings | ||
11 | # Allow no more than 10 requests in 10 seconds, then register overflow. | ||
12 | max-requests 10 | ||
13 | request-control-interval 10 | ||
14 | # Sleep for 5 seconds when the first overflow occurs. | ||
15 | overflow-delay-time 5 | ||
16 | # If two overflows happen within a 15 seconds interval, double the | ||
17 | # sleep time. | ||
18 | overflow-control-interval 15 | ||
19 | ## Access Control Lists | ||
20 | acl allow 127.0.0.1 | ||
21 | acl deny any |
examples/config/mailutils.rc
deleted
100644 → 0
1 | ## This is a sample mailutils configuration file | ||
2 | ## Upon startup, a mailutils program scans this file for a line that | ||
3 | ## begins either with a program name or with word `mailutils'. When | ||
4 | ## found, the rest of the line following the first word is split up | ||
5 | ## at whitespace characters and resulting words are added to the | ||
6 | ## program arguments _before_ the command line options. | ||
7 | :mailutils --maildir /var/spool/mail | ||
8 | :auth --sql-host sql.sample.net --sql-db Passwd \ | ||
9 | --sql-port 3306 --sql-user mailutils \ | ||
10 | --sql-passwd guessme \ | ||
11 | --sql-getpwnam 'select user_name,password,uid,10000,"/dev/null","/dev/null" from pass where user_name="%u" and service="EMAIL"' \ | ||
12 | --sql-getpwuid 'select user_name,password,uid,10000,"/dev/null","/dev/null" from pass where uid=%u and service="EMAIL"' | ||
13 | imap4d --daemon=20 --timeout=1800 | ||
14 | mail.local --source %h/.filter.scm |
... | @@ -42,7 +42,9 @@ extern int mu_argcv_get_np (const char *command, int len, | ... | @@ -42,7 +42,9 @@ extern int mu_argcv_get_np (const char *command, int len, |
42 | int *pargc, char ***pargv, char **endp); | 42 | int *pargc, char ***pargv, char **endp); |
43 | 43 | ||
44 | extern int mu_argcv_string (int argc, char **argv, char **string); | 44 | extern int mu_argcv_string (int argc, char **argv, char **string); |
45 | extern int mu_argcv_free (int argc, char **argv); | 45 | extern void mu_argcv_free (int argc, char **argv); |
46 | extern void mu_argv_free (char **argv); | ||
47 | |||
46 | extern int mu_argcv_unquote_char (int c); | 48 | extern int mu_argcv_unquote_char (int c); |
47 | extern int mu_argcv_quote_char (int c); | 49 | extern int mu_argcv_quote_char (int c); |
48 | extern size_t mu_argcv_quoted_length (const char *str, int *quote); | 50 | extern size_t mu_argcv_quoted_length (const char *str, int *quote); | ... | ... |
... | @@ -31,6 +31,7 @@ | ... | @@ -31,6 +31,7 @@ |
31 | #define argcv_get_np mu_argcv_get_np | 31 | #define argcv_get_np mu_argcv_get_np |
32 | #define argcv_string mu_argcv_string | 32 | #define argcv_string mu_argcv_string |
33 | #define argcv_free mu_argcv_free | 33 | #define argcv_free mu_argcv_free |
34 | #define argv_free mu_argv_free | ||
34 | #define argcv_unquote_char mu_argcv_unquote_char | 35 | #define argcv_unquote_char mu_argcv_unquote_char |
35 | #define argcv_quote_char mu_argcv_quote_char | 36 | #define argcv_quote_char mu_argcv_quote_char |
36 | #define argcv_quoted_length mu_argcv_quoted_length | 37 | #define argcv_quoted_length mu_argcv_quoted_length |
... | @@ -443,14 +444,23 @@ argcv_get (const char *command, const char *delim, const char *cmnt, | ... | @@ -443,14 +444,23 @@ argcv_get (const char *command, const char *delim, const char *cmnt, |
443 | * argc is the number of elements | 444 | * argc is the number of elements |
444 | * argv is the array | 445 | * argv is the array |
445 | */ | 446 | */ |
446 | int | 447 | void |
447 | argcv_free (int argc, char **argv) | 448 | argcv_free (int argc, char **argv) |
448 | { | 449 | { |
449 | while (--argc >= 0) | 450 | while (--argc >= 0) |
450 | if (argv[argc]) | 451 | if (argv[argc]) |
451 | free (argv[argc]); | 452 | free (argv[argc]); |
452 | free (argv); | 453 | free (argv); |
453 | return 0; | 454 | } |
455 | |||
456 | void | ||
457 | argv_free (char **argv) | ||
458 | { | ||
459 | int i; | ||
460 | |||
461 | for (i = 0; argv[i]; i++) | ||
462 | free (argv[i]); | ||
463 | free (argv); | ||
454 | } | 464 | } |
455 | 465 | ||
456 | /* Make a argv an make string separated by ' '. */ | 466 | /* Make a argv an make string separated by ' '. */ | ... | ... |
-
Please register or sign in to post a comment