* examples/aclck.c, examples/addr.c, examples/base64.c,
examples/decode2047.c, examples/echosrv.c, examples/encode2047.c, examples/header.c, examples/http.c, examples/iconv.c, examples/listop.c, examples/lsf.c, examples/mailcap.c, examples/mimetest.c, examples/msg-send.c, examples/muemail.c, examples/murun.c, examples/nntpclient.c, examples/pop3client.c, examples/sfrom.c, examples/url-parse.c: Include config.h. Use MU_ASSERT instead of assert. * include/mailutils/cfg.h (struct mu_cfg_section.offset): New member. * include/mailutils/debug.hm4 (MU_ASSERT): New member. * lib/utmp.c: Include config.h. * libcfg/Makefile.am (libmucfg_la_SOURCES): Add acl.c. * libcfg/acl.c: New file. * libcfg/common.c (cb_debug_level): Immediately set debugging level. * mailbox/acl.c: mu_acl_log expands its argument. * mailbox/cfg_driver.c (mu_create_canned_section) (mu_create_canned_param): Avoid creating container twice. * mailbox/cfg_format.c (format_param): Do not pring type if argname contains a colon. * mailbox/cfg_parser.y (_scan_tree_helper): Compute target pointer. * imap4d/imap4d.c, imap4d/imap4d.h, pop3d/pop3d.c, pop3d/pop3d.h: Use MU ACLs
Showing
35 changed files
with
626 additions
and
123 deletions
1 | 2007-12-13 Sergey Poznyakoff <gray@gnu.org.ua> | ||
2 | |||
3 | * examples/aclck.c, examples/addr.c, examples/base64.c, | ||
4 | examples/decode2047.c, examples/echosrv.c, examples/encode2047.c, | ||
5 | examples/header.c, examples/http.c, examples/iconv.c, | ||
6 | examples/listop.c, examples/lsf.c, examples/mailcap.c, | ||
7 | examples/mimetest.c, examples/msg-send.c, examples/muemail.c, | ||
8 | examples/murun.c, examples/nntpclient.c, examples/pop3client.c, | ||
9 | examples/sfrom.c, examples/url-parse.c: Include config.h. Use | ||
10 | MU_ASSERT instead of assert. | ||
11 | |||
12 | * include/mailutils/cfg.h (struct mu_cfg_section.offset): New | ||
13 | member. | ||
14 | * include/mailutils/debug.hm4 (MU_ASSERT): New member. | ||
15 | * lib/utmp.c: Include config.h. | ||
16 | * libcfg/Makefile.am (libmucfg_la_SOURCES): Add acl.c. | ||
17 | * libcfg/acl.c: New file. | ||
18 | * libcfg/common.c (cb_debug_level): Immediately set debugging | ||
19 | level. | ||
20 | * mailbox/acl.c: mu_acl_log expands its argument. | ||
21 | * mailbox/cfg_driver.c (mu_create_canned_section) | ||
22 | (mu_create_canned_param): Avoid creating container twice. | ||
23 | * mailbox/cfg_format.c (format_param): Do not pring type if | ||
24 | argname contains a colon. | ||
25 | * mailbox/cfg_parser.y (_scan_tree_helper): Compute target | ||
26 | pointer. | ||
27 | |||
28 | * imap4d/imap4d.c, imap4d/imap4d.h, pop3d/pop3d.c, | ||
29 | pop3d/pop3d.h: Use MU ACLs | ||
30 | |||
31 | |||
1 | 2007-12-11 Sergey Poznyakoff <gray@gnu.org.ua> | 32 | 2007-12-11 Sergey Poznyakoff <gray@gnu.org.ua> |
2 | 33 | ||
3 | * comsat/comsat.c, imap4d/imap4d.c, maidag/maidag.c, | 34 | * comsat/comsat.c, imap4d/imap4d.c, maidag/maidag.c, | ... | ... |
... | @@ -17,6 +17,9 @@ | ... | @@ -17,6 +17,9 @@ |
17 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, | 17 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, |
18 | MA 02110-1301 USA */ | 18 | MA 02110-1301 USA */ |
19 | 19 | ||
20 | #ifdef HAVE_CONFIG_H | ||
21 | # include <config.h> | ||
22 | #endif | ||
20 | #include <mailutils/mailutils.h> | 23 | #include <mailutils/mailutils.h> |
21 | 24 | ||
22 | #include <sys/socket.h> | 25 | #include <sys/socket.h> | ... | ... |
... | @@ -17,6 +17,9 @@ | ... | @@ -17,6 +17,9 @@ |
17 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, | 17 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, |
18 | MA 02110-1301 USA */ | 18 | MA 02110-1301 USA */ |
19 | 19 | ||
20 | #ifdef HAVE_CONFIG_H | ||
21 | # include <config.h> | ||
22 | #endif | ||
20 | #include <stdio.h> | 23 | #include <stdio.h> |
21 | #include <string.h> | 24 | #include <string.h> |
22 | #include <errno.h> | 25 | #include <errno.h> | ... | ... |
... | @@ -17,6 +17,9 @@ | ... | @@ -17,6 +17,9 @@ |
17 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, | 17 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, |
18 | MA 02110-1301 USA */ | 18 | MA 02110-1301 USA */ |
19 | 19 | ||
20 | #ifdef HAVE_CONFIG_H | ||
21 | # include <config.h> | ||
22 | #endif | ||
20 | #include <unistd.h> | 23 | #include <unistd.h> |
21 | #include <stdio.h> | 24 | #include <stdio.h> |
22 | #include <assert.h> | 25 | #include <assert.h> |
... | @@ -78,19 +81,18 @@ main (int argc, char * argv []) | ... | @@ -78,19 +81,18 @@ main (int argc, char * argv []) |
78 | } | 81 | } |
79 | 82 | ||
80 | if (input) | 83 | if (input) |
81 | c = mu_file_stream_create (&in, input, MU_STREAM_READ); | 84 | MU_ASSERT (mu_file_stream_create (&in, input, MU_STREAM_READ)); |
82 | else | 85 | else |
83 | c = mu_stdio_stream_create (&in, stdin, 0); | 86 | MU_ASSERT (mu_stdio_stream_create (&in, stdin, 0)); |
84 | assert (c == 0); | 87 | MU_ASSERT (mu_filter_create (&flt, in, encoding, mode, MU_STREAM_READ)); |
85 | assert (mu_filter_create (&flt, in, encoding, mode, MU_STREAM_READ) == 0); | 88 | MU_ASSERT (mu_stream_open (in)); |
86 | assert (mu_stream_open (in) == 0); | ||
87 | 89 | ||
88 | if (output) | 90 | if (output) |
89 | c = mu_file_stream_create (&out, output, MU_STREAM_WRITE|MU_STREAM_CREAT); | 91 | MU_ASSERT (mu_file_stream_create (&out, output, |
92 | MU_STREAM_WRITE|MU_STREAM_CREAT)); | ||
90 | else | 93 | else |
91 | c = mu_stdio_stream_create (&out, stdout, 0); | 94 | MU_ASSERT (mu_stdio_stream_create (&out, stdout, 0)); |
92 | assert (c == 0); | 95 | MU_ASSERT (mu_stream_open (out)); |
93 | assert (mu_stream_open (out) == 0); | ||
94 | 96 | ||
95 | while (mu_stream_read (flt, &buffer, sizeof (buffer), total, &size) == 0 | 97 | while (mu_stream_read (flt, &buffer, sizeof (buffer), total, &size) == 0 |
96 | && size > 0) | 98 | && size > 0) | ... | ... |
... | @@ -16,6 +16,9 @@ | ... | @@ -16,6 +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 | #ifdef HAVE_CONFIG_H | ||
20 | # include <config.h> | ||
21 | #endif | ||
19 | #include <stdio.h> | 22 | #include <stdio.h> |
20 | #include <stdlib.h> | 23 | #include <stdlib.h> |
21 | #include <errno.h> | 24 | #include <errno.h> | ... | ... |
... | @@ -32,18 +32,6 @@ | ... | @@ -32,18 +32,6 @@ |
32 | #include <mailutils/mailutils.h> | 32 | #include <mailutils/mailutils.h> |
33 | #include <mailutils/server.h> | 33 | #include <mailutils/server.h> |
34 | 34 | ||
35 | #define MU_ASSERT(expr) \ | ||
36 | do \ | ||
37 | { \ | ||
38 | int rc = expr; \ | ||
39 | if (rc) \ | ||
40 | { \ | ||
41 | mu_error (#expr " failed: %s", mu_strerror (rc)); \ | ||
42 | abort (); \ | ||
43 | } \ | ||
44 | } \ | ||
45 | while (0); | ||
46 | |||
47 | mu_server_t server; | 35 | mu_server_t server; |
48 | 36 | ||
49 | int | 37 | int |
... | @@ -52,8 +40,7 @@ echo_conn (int fd, struct sockaddr_in *s, void *server_data, void *call_data, | ... | @@ -52,8 +40,7 @@ echo_conn (int fd, struct sockaddr_in *s, void *server_data, void *call_data, |
52 | { | 40 | { |
53 | struct sockaddr_in srv_addr; | 41 | struct sockaddr_in srv_addr; |
54 | pid_t pid; | 42 | pid_t pid; |
55 | char *buf = NULL; | 43 | char buf[512]; |
56 | size_t size = 0; | ||
57 | FILE *in, *out; | 44 | FILE *in, *out; |
58 | 45 | ||
59 | mu_tcp_server_get_sockaddr (srv, &srv_addr); | 46 | mu_tcp_server_get_sockaddr (srv, &srv_addr); |
... | @@ -82,10 +69,10 @@ echo_conn (int fd, struct sockaddr_in *s, void *server_data, void *call_data, | ... | @@ -82,10 +69,10 @@ echo_conn (int fd, struct sockaddr_in *s, void *server_data, void *call_data, |
82 | setvbuf (out, NULL, _IOLBF, 0); | 69 | setvbuf (out, NULL, _IOLBF, 0); |
83 | 70 | ||
84 | pid = getpid (); | 71 | pid = getpid (); |
85 | while (getline (&buf, &size, in) > 0) | 72 | while (fgets (buf, sizeof (buf), in) > 0) |
86 | { | 73 | { |
87 | int len = strlen (buf); | 74 | int len = strlen (buf); |
88 | if (len > 0) | 75 | if (len > 0 && buf[len-1] == '\n') |
89 | { | 76 | { |
90 | buf[--len] = 0; | 77 | buf[--len] = 0; |
91 | if (buf[len-1] == '\r') | 78 | if (buf[len-1] == '\r') |
... | @@ -93,7 +80,6 @@ echo_conn (int fd, struct sockaddr_in *s, void *server_data, void *call_data, | ... | @@ -93,7 +80,6 @@ echo_conn (int fd, struct sockaddr_in *s, void *server_data, void *call_data, |
93 | } | 80 | } |
94 | fprintf (out, "%lu: you said: \"%s\"\r\n", (unsigned long) pid, buf); | 81 | fprintf (out, "%lu: you said: \"%s\"\r\n", (unsigned long) pid, buf); |
95 | } | 82 | } |
96 | free (buf); | ||
97 | exit (0); | 83 | exit (0); |
98 | } | 84 | } |
99 | 85 | ... | ... |
... | @@ -16,6 +16,9 @@ | ... | @@ -16,6 +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 | #ifdef HAVE_CONFIG_H | ||
20 | # include <config.h> | ||
21 | #endif | ||
19 | #include <stdio.h> | 22 | #include <stdio.h> |
20 | #include <stdlib.h> | 23 | #include <stdlib.h> |
21 | #include <errno.h> | 24 | #include <errno.h> | ... | ... |
... | @@ -16,6 +16,9 @@ | ... | @@ -16,6 +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 | #ifdef HAVE_CONFIG_H | ||
20 | # include <config.h> | ||
21 | #endif | ||
19 | #include <stdio.h> | 22 | #include <stdio.h> |
20 | #include <string.h> | 23 | #include <string.h> |
21 | #include <errno.h> | 24 | #include <errno.h> | ... | ... |
... | @@ -20,6 +20,9 @@ | ... | @@ -20,6 +20,9 @@ |
20 | It connects to a remote HTTP server and prints the contents of its | 20 | It connects to a remote HTTP server and prints the contents of its |
21 | index page */ | 21 | index page */ |
22 | 22 | ||
23 | #ifdef HAVE_CONFIG_H | ||
24 | # include <config.h> | ||
25 | #endif | ||
23 | #include <stdio.h> | 26 | #include <stdio.h> |
24 | #include <stdlib.h> | 27 | #include <stdlib.h> |
25 | #include <string.h> | 28 | #include <string.h> | ... | ... |
... | @@ -16,12 +16,14 @@ | ... | @@ -16,12 +16,14 @@ |
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 | #ifdef HAVE_CONFIG_H | ||
20 | # include <config.h> | ||
21 | #endif | ||
19 | #include <stdio.h> | 22 | #include <stdio.h> |
20 | #include <stdlib.h> | 23 | #include <stdlib.h> |
21 | #include <string.h> | 24 | #include <string.h> |
22 | #include <errno.h> | 25 | #include <errno.h> |
23 | #include <unistd.h> | 26 | #include <unistd.h> |
24 | #include <assert.h> | ||
25 | 27 | ||
26 | #include <mailutils/mailutils.h> | 28 | #include <mailutils/mailutils.h> |
27 | 29 | ||
... | @@ -40,15 +42,14 @@ main (int argc, char **argv) | ... | @@ -40,15 +42,14 @@ main (int argc, char **argv) |
40 | return 1; | 42 | return 1; |
41 | } | 43 | } |
42 | 44 | ||
43 | rc = mu_stdio_stream_create (&in, stdin, 0); | 45 | MU_ASSERT (mu_stdio_stream_create (&in, stdin, 0)); |
44 | assert (rc == 0); | 46 | MU_ASSERT (mu_stream_open (in)); |
45 | assert (mu_stream_open (in) == 0); | 47 | MU_ASSERT (mu_filter_iconv_create (&cvt, in, argv[1], argv[2], |
46 | assert (mu_filter_iconv_create (&cvt, in, argv[1], argv[2], 0, mu_fallback_none) == 0); | 48 | 0, mu_fallback_none)); |
47 | assert (mu_stream_open (cvt) == 0); | 49 | MU_ASSERT (mu_stream_open (cvt)); |
48 | 50 | ||
49 | rc = mu_stdio_stream_create (&out, stdout, 0); | 51 | MU_ASSERT (mu_stdio_stream_create (&out, stdout, 0)); |
50 | assert (rc == 0); | 52 | MU_ASSERT (mu_stream_open (out)); |
51 | assert (mu_stream_open (out) == 0); | ||
52 | 53 | ||
53 | while ((rc = mu_stream_read (cvt, buffer, sizeof (buffer), total, &size)) == 0 | 54 | while ((rc = mu_stream_read (cvt, buffer, sizeof (buffer), total, &size)) == 0 |
54 | && size > 0) | 55 | && size > 0) | ... | ... |
... | @@ -16,6 +16,9 @@ | ... | @@ -16,6 +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 | #ifdef HAVE_CONFIG_H | ||
20 | # include <config.h> | ||
21 | #endif | ||
19 | #include <unistd.h> | 22 | #include <unistd.h> |
20 | #include <stdio.h> | 23 | #include <stdio.h> |
21 | #include <stdlib.h> | 24 | #include <stdlib.h> | ... | ... |
... | @@ -16,21 +16,14 @@ | ... | @@ -16,21 +16,14 @@ |
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 | #ifdef HAVE_CONFIG_H | ||
20 | # include <config.h> | ||
21 | #endif | ||
19 | #include <errno.h> | 22 | #include <errno.h> |
20 | #include <stdlib.h> | 23 | #include <stdlib.h> |
21 | #include <string.h> | 24 | #include <string.h> |
22 | #include <mailutils/mailutils.h> | 25 | #include <mailutils/mailutils.h> |
23 | 26 | ||
24 | #define C(X) do \ | ||
25 | { \ | ||
26 | int e; \ | ||
27 | if ((e = X) != 0) \ | ||
28 | { \ | ||
29 | mu_error ("%s failed: %s\n", #X, mu_strerror (e)); \ | ||
30 | return 1; \ | ||
31 | } \ | ||
32 | } while (0) | ||
33 | |||
34 | static int | 27 | static int |
35 | ls_printer (void *item, void *data) | 28 | ls_printer (void *item, void *data) |
36 | { | 29 | { | ... | ... |
... | @@ -16,6 +16,9 @@ | ... | @@ -16,6 +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 | #ifdef HAVE_CONFIG_H | ||
20 | # include <config.h> | ||
21 | #endif | ||
19 | #include <stdlib.h> | 22 | #include <stdlib.h> |
20 | #include <stdio.h> | 23 | #include <stdio.h> |
21 | #include <mailutils/mailcap.h> | 24 | #include <mailutils/mailcap.h> | ... | ... |
... | @@ -16,6 +16,9 @@ | ... | @@ -16,6 +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 | #ifdef HAVE_CONFIG_H | ||
20 | # include <config.h> | ||
21 | #endif | ||
19 | #include <limits.h> | 22 | #include <limits.h> |
20 | #include <stdio.h> | 23 | #include <stdio.h> |
21 | #include <stdlib.h> | 24 | #include <stdlib.h> |
... | @@ -52,18 +55,6 @@ print_file (const char *fname, int indent) | ... | @@ -52,18 +55,6 @@ print_file (const char *fname, int indent) |
52 | unlink (fname); | 55 | unlink (fname); |
53 | } | 56 | } |
54 | 57 | ||
55 | #define CATCH(expr) \ | ||
56 | do \ | ||
57 | { \ | ||
58 | int rc; \ | ||
59 | if ((rc = expr) != 0) \ | ||
60 | { \ | ||
61 | fprintf (stderr, "%s: %s\n", #expr, mu_strerror (rc)); \ | ||
62 | exit (2); \ | ||
63 | } \ | ||
64 | } \ | ||
65 | while (0) | ||
66 | |||
67 | int | 58 | int |
68 | main (int argc, char **argv) | 59 | main (int argc, char **argv) |
69 | { | 60 | { |
... | @@ -93,7 +84,7 @@ main (int argc, char **argv) | ... | @@ -93,7 +84,7 @@ main (int argc, char **argv) |
93 | mu_registrar_record (mu_path_record); | 84 | mu_registrar_record (mu_path_record); |
94 | mu_registrar_record (mu_pop_record); | 85 | mu_registrar_record (mu_pop_record); |
95 | 86 | ||
96 | CATCH (mu_mailbox_create_default (&mbox, mailbox_name)); | 87 | MU_ASSERT (mu_mailbox_create_default (&mbox, mailbox_name)); |
97 | 88 | ||
98 | /* Debugging trace. */ | 89 | /* Debugging trace. */ |
99 | if (debug) | 90 | if (debug) |
... | @@ -104,7 +95,7 @@ main (int argc, char **argv) | ... | @@ -104,7 +95,7 @@ main (int argc, char **argv) |
104 | } | 95 | } |
105 | 96 | ||
106 | /* Open the mailbox for reading only. */ | 97 | /* Open the mailbox for reading only. */ |
107 | CATCH (mu_mailbox_open (mbox, MU_STREAM_RDWR)); | 98 | MU_ASSERT (mu_mailbox_open (mbox, MU_STREAM_RDWR)); |
108 | 99 | ||
109 | /* Iterate through the entire message set. */ | 100 | /* Iterate through the entire message set. */ |
110 | mu_mailbox_messages_count (mbox, &count); | 101 | mu_mailbox_messages_count (mbox, &count); |
... | @@ -116,10 +107,10 @@ main (int argc, char **argv) | ... | @@ -116,10 +107,10 @@ main (int argc, char **argv) |
116 | size_t nparts; | 107 | size_t nparts; |
117 | size_t msize, nlines; | 108 | size_t msize, nlines; |
118 | 109 | ||
119 | CATCH (mu_mailbox_get_message (mbox, i, &msg)); | 110 | MU_ASSERT (mu_mailbox_get_message (mbox, i, &msg)); |
120 | CATCH (mu_message_size (msg, &msize)); | 111 | MU_ASSERT (mu_message_size (msg, &msize)); |
121 | CATCH (mu_message_lines (msg, &nlines)); | 112 | MU_ASSERT (mu_message_lines (msg, &nlines)); |
122 | CATCH (mu_message_get_header (msg, &hdr)); | 113 | MU_ASSERT (mu_message_get_header (msg, &hdr)); |
123 | if (mu_header_sget_value (hdr, MU_HEADER_FROM, &from)) | 114 | if (mu_header_sget_value (hdr, MU_HEADER_FROM, &from)) |
124 | from = ""; | 115 | from = ""; |
125 | if (mu_header_sget_value (hdr, MU_HEADER_SUBJECT, &subject)) | 116 | if (mu_header_sget_value (hdr, MU_HEADER_SUBJECT, &subject)) |
... | @@ -128,7 +119,7 @@ main (int argc, char **argv) | ... | @@ -128,7 +119,7 @@ main (int argc, char **argv) |
128 | printf ("From: %s\n", from); | 119 | printf ("From: %s\n", from); |
129 | printf ("Subject: %s\n", subject); | 120 | printf ("Subject: %s\n", subject); |
130 | 121 | ||
131 | CATCH (mu_message_get_num_parts (msg, &nparts)); | 122 | MU_ASSERT (mu_message_get_num_parts (msg, &nparts)); |
132 | printf ("Number of parts in message - %lu\n", | 123 | printf ("Number of parts in message - %lu\n", |
133 | (unsigned long) nparts); | 124 | (unsigned long) nparts); |
134 | printf ("Total message size - %lu/%lu\n", | 125 | printf ("Total message size - %lu/%lu\n", |
... | @@ -149,14 +140,14 @@ print_message_part_sizes (mu_message_t part, int indent) | ... | @@ -149,14 +140,14 @@ print_message_part_sizes (mu_message_t part, int indent) |
149 | mu_header_t hdr; | 140 | mu_header_t hdr; |
150 | size_t msize, mlines, hsize, hlines, bsize, blines; | 141 | size_t msize, mlines, hsize, hlines, bsize, blines; |
151 | 142 | ||
152 | CATCH (mu_message_size (part, &msize)); | 143 | MU_ASSERT (mu_message_size (part, &msize)); |
153 | CATCH (mu_message_lines (part, &mlines)); | 144 | MU_ASSERT (mu_message_lines (part, &mlines)); |
154 | CATCH (mu_message_get_header (part, &hdr)); | 145 | MU_ASSERT (mu_message_get_header (part, &hdr)); |
155 | CATCH (mu_header_size (hdr, &hsize)); | 146 | MU_ASSERT (mu_header_size (hdr, &hsize)); |
156 | CATCH (mu_header_lines (hdr, &hlines)); | 147 | MU_ASSERT (mu_header_lines (hdr, &hlines)); |
157 | CATCH (mu_message_get_body (part, &body)); | 148 | MU_ASSERT (mu_message_get_body (part, &body)); |
158 | CATCH (mu_body_size (body, &bsize)); | 149 | MU_ASSERT (mu_body_size (body, &bsize)); |
159 | CATCH (mu_body_lines (body, &blines)); | 150 | MU_ASSERT (mu_body_lines (body, &blines)); |
160 | printf ("%*.*sMessage part size - %lu/%lu: %lu/%lu, %lu/%lu\n", | 151 | printf ("%*.*sMessage part size - %lu/%lu: %lu/%lu, %lu/%lu\n", |
161 | indent, indent, "", | 152 | indent, indent, "", |
162 | (unsigned long) msize, (unsigned long) mlines, | 153 | (unsigned long) msize, (unsigned long) mlines, |
... | @@ -191,8 +182,8 @@ message_display_parts (mu_message_t msg, int indent) | ... | @@ -191,8 +182,8 @@ message_display_parts (mu_message_t msg, int indent) |
191 | for (j = 1; j <= nparts; j++) | 182 | for (j = 1; j <= nparts; j++) |
192 | { | 183 | { |
193 | int status; | 184 | int status; |
194 | CATCH (mu_message_get_part (msg, j, &part)); | 185 | MU_ASSERT (mu_message_get_part (msg, j, &part)); |
195 | CATCH (mu_message_get_header (part, &hdr)); | 186 | MU_ASSERT (mu_message_get_header (part, &hdr)); |
196 | status = mu_header_sget_value (hdr, MU_HEADER_CONTENT_TYPE, &type); | 187 | status = mu_header_sget_value (hdr, MU_HEADER_CONTENT_TYPE, &type); |
197 | if (status == MU_ERR_NOENT) | 188 | if (status == MU_ERR_NOENT) |
198 | type = ""; | 189 | type = ""; |
... | @@ -212,9 +203,9 @@ message_display_parts (mu_message_t msg, int indent) | ... | @@ -212,9 +203,9 @@ message_display_parts (mu_message_t msg, int indent) |
212 | || (mu_message_is_multipart (part, &ismulti) == 0 && ismulti)) | 203 | || (mu_message_is_multipart (part, &ismulti) == 0 && ismulti)) |
213 | { | 204 | { |
214 | if (!ismulti) | 205 | if (!ismulti) |
215 | CATCH (mu_message_unencapsulate (part, &part, NULL)); | 206 | MU_ASSERT (mu_message_unencapsulate (part, &part, NULL)); |
216 | 207 | ||
217 | CATCH (mu_message_get_header (part, &hdr)); | 208 | MU_ASSERT (mu_message_get_header (part, &hdr)); |
218 | if (mu_header_sget_value (hdr, MU_HEADER_FROM, &from)) | 209 | if (mu_header_sget_value (hdr, MU_HEADER_FROM, &from)) |
219 | from = ""; | 210 | from = ""; |
220 | if (mu_header_sget_value (hdr, MU_HEADER_SUBJECT, &subject)) | 211 | if (mu_header_sget_value (hdr, MU_HEADER_SUBJECT, &subject)) |
... | @@ -222,7 +213,7 @@ message_display_parts (mu_message_t msg, int indent) | ... | @@ -222,7 +213,7 @@ message_display_parts (mu_message_t msg, int indent) |
222 | printf ("%*.*sEncapsulated message : %s\t%s\n", | 213 | printf ("%*.*sEncapsulated message : %s\t%s\n", |
223 | indent, indent, "", from, subject); | 214 | indent, indent, "", from, subject); |
224 | printf ("%*.*sBegin\n", indent, indent, ""); | 215 | printf ("%*.*sBegin\n", indent, indent, ""); |
225 | CATCH (mu_message_get_num_parts (part, &nsubparts)); | 216 | MU_ASSERT (mu_message_get_num_parts (part, &nsubparts)); |
226 | message_display_parts (part, indent+indent_level); | 217 | message_display_parts (part, indent+indent_level); |
227 | mu_message_destroy (&part, NULL); | 218 | mu_message_destroy (&part, NULL); |
228 | } | 219 | } | ... | ... |
... | @@ -16,6 +16,10 @@ | ... | @@ -16,6 +16,10 @@ |
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 | #ifdef HAVE_CONFIG_H | ||
20 | # include <config.h> | ||
21 | #endif | ||
22 | |||
19 | #include <sys/types.h> | 23 | #include <sys/types.h> |
20 | #include <sys/stat.h> | 24 | #include <sys/stat.h> |
21 | 25 | ||
... | @@ -34,14 +38,6 @@ | ... | @@ -34,14 +38,6 @@ |
34 | #include <mailutils/registrar.h> | 38 | #include <mailutils/registrar.h> |
35 | #include <mailutils/stream.h> | 39 | #include <mailutils/stream.h> |
36 | 40 | ||
37 | #define C(X) do {\ | ||
38 | int e;\ | ||
39 | if((e = X) != 0) { \ | ||
40 | fprintf(stderr, "%s failed: %s\n", #X, mu_strerror(e)); \ | ||
41 | exit(1);\ | ||
42 | }\ | ||
43 | } while (0) | ||
44 | |||
45 | const char USAGE[] = | 41 | const char USAGE[] = |
46 | "usage: mailer [-hd] [-m mailer] [-f from] [to]..." | 42 | "usage: mailer [-hd] [-m mailer] [-f from] [to]..." |
47 | ; | 43 | ; |
... | @@ -101,21 +97,21 @@ main (int argc, char *argv[]) | ... | @@ -101,21 +97,21 @@ main (int argc, char *argv[]) |
101 | 97 | ||
102 | if (optfrom) | 98 | if (optfrom) |
103 | { | 99 | { |
104 | C (mu_address_create (&from, optfrom)); | 100 | MU_ASSERT (mu_address_create (&from, optfrom)); |
105 | } | 101 | } |
106 | 102 | ||
107 | if (argv[optind]) | 103 | if (argv[optind]) |
108 | { | 104 | { |
109 | char **av = argv + optind; | 105 | char **av = argv + optind; |
110 | 106 | ||
111 | C (mu_address_createv (&to, (const char **) av, -1)); | 107 | MU_ASSERT (mu_address_createv (&to, (const char **) av, -1)); |
112 | } | 108 | } |
113 | 109 | ||
114 | C (mu_stdio_stream_create (&in, stdin, MU_STREAM_SEEKABLE)); | 110 | MU_ASSERT (mu_stdio_stream_create (&in, stdin, MU_STREAM_SEEKABLE)); |
115 | C (mu_stream_open (in)); | 111 | MU_ASSERT (mu_stream_open (in)); |
116 | C (mu_message_create (&msg, NULL)); | 112 | MU_ASSERT (mu_message_create (&msg, NULL)); |
117 | C (mu_message_set_stream (msg, in, NULL)); | 113 | MU_ASSERT (mu_message_set_stream (msg, in, NULL)); |
118 | C (mu_mailer_create (&mailer, optmailer)); | 114 | MU_ASSERT (mu_mailer_create (&mailer, optmailer)); |
119 | 115 | ||
120 | if (optdebug) | 116 | if (optdebug) |
121 | { | 117 | { |
... | @@ -124,9 +120,9 @@ main (int argc, char *argv[]) | ... | @@ -124,9 +120,9 @@ main (int argc, char *argv[]) |
124 | mu_debug_set_level (debug, MU_DEBUG_LEVEL_UPTO (MU_DEBUG_PROT)); | 120 | mu_debug_set_level (debug, MU_DEBUG_LEVEL_UPTO (MU_DEBUG_PROT)); |
125 | } | 121 | } |
126 | 122 | ||
127 | C (mu_mailer_open (mailer, 0)); | 123 | MU_ASSERT (mu_mailer_open (mailer, 0)); |
128 | 124 | ||
129 | C (mu_mailer_send_message (mailer, msg, from, to)); | 125 | MU_ASSERT (mu_mailer_send_message (mailer, msg, from, to)); |
130 | 126 | ||
131 | return 0; | 127 | return 0; |
132 | } | 128 | } | ... | ... |
... | @@ -16,6 +16,9 @@ | ... | @@ -16,6 +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 | #ifdef HAVE_CONFIG_H | ||
20 | # include <config.h> | ||
21 | #endif | ||
19 | #include <stdlib.h> | 22 | #include <stdlib.h> |
20 | #include <stdio.h> | 23 | #include <stdio.h> |
21 | #include <mailutils/mutil.h> | 24 | #include <mailutils/mutil.h> | ... | ... |
... | @@ -16,11 +16,13 @@ | ... | @@ -16,11 +16,13 @@ |
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 | #ifdef HAVE_CONFIG_H | ||
20 | # include <config.h> | ||
21 | #endif | ||
19 | #include <sys/types.h> | 22 | #include <sys/types.h> |
20 | #include <sys/wait.h> | 23 | #include <sys/wait.h> |
21 | #include <unistd.h> | 24 | #include <unistd.h> |
22 | #include <stdio.h> | 25 | #include <stdio.h> |
23 | #include <assert.h> | ||
24 | #include <ctype.h> | 26 | #include <ctype.h> |
25 | #include <string.h> | 27 | #include <string.h> |
26 | #include <mailutils/mailutils.h> | 28 | #include <mailutils/mailutils.h> |
... | @@ -62,12 +64,12 @@ main (int argc, char *argv[]) | ... | @@ -62,12 +64,12 @@ main (int argc, char *argv[]) |
62 | exit (1); | 64 | exit (1); |
63 | } | 65 | } |
64 | 66 | ||
65 | assert (mu_argcv_string (argc - i, &argv[i], &cmdline) == 0); | 67 | MU_ASSERT (mu_argcv_string (argc - i, &argv[i], &cmdline)); |
66 | if (read_stdin) | 68 | if (read_stdin) |
67 | { | 69 | { |
68 | mu_stream_t in; | 70 | mu_stream_t in; |
69 | assert (mu_stdio_stream_create (&in, stdin, 0) == 0); | 71 | MU_ASSERT (mu_stdio_stream_create (&in, stdin, 0)); |
70 | assert (mu_stream_open (in) == 0); | 72 | MU_ASSERT (mu_stream_open (in)); |
71 | rc = mu_filter_prog_stream_create (&stream, cmdline, in); | 73 | rc = mu_filter_prog_stream_create (&stream, cmdline, in); |
72 | } | 74 | } |
73 | else | 75 | else |
... | @@ -87,9 +89,8 @@ main (int argc, char *argv[]) | ... | @@ -87,9 +89,8 @@ main (int argc, char *argv[]) |
87 | exit (1); | 89 | exit (1); |
88 | } | 90 | } |
89 | 91 | ||
90 | assert (mu_stdio_stream_create (&out, stdout, 0) == 0); | 92 | MU_ASSERT (mu_stdio_stream_create (&out, stdout, 0)); |
91 | assert (rc == 0); | 93 | MU_ASSERT (mu_stream_open (out)); |
92 | assert (mu_stream_open (out) == 0); | ||
93 | 94 | ||
94 | read_and_print (stream, out); | 95 | read_and_print (stream, out); |
95 | mu_stream_close (stream); | 96 | mu_stream_close (stream); | ... | ... |
... | @@ -20,7 +20,7 @@ | ... | @@ -20,7 +20,7 @@ |
20 | MA 02110-1301 USA */ | 20 | MA 02110-1301 USA */ |
21 | 21 | ||
22 | #ifdef HAVE_CONFIG_H | 22 | #ifdef HAVE_CONFIG_H |
23 | # include <config.h> /* For MU_ARG_UNUSED only */ | 23 | # include <config.h> |
24 | #endif | 24 | #endif |
25 | #include <sys/types.h> | 25 | #include <sys/types.h> |
26 | #include <unistd.h> | 26 | #include <unistd.h> | ... | ... |
... | @@ -20,7 +20,7 @@ | ... | @@ -20,7 +20,7 @@ |
20 | MA 02110-1301 USA */ | 20 | MA 02110-1301 USA */ |
21 | 21 | ||
22 | #ifdef HAVE_CONFIG_H | 22 | #ifdef HAVE_CONFIG_H |
23 | # include <config.h> /* For MU_ARG_UNUSED only */ | 23 | # include <config.h> |
24 | #endif | 24 | #endif |
25 | #include <sys/types.h> | 25 | #include <sys/types.h> |
26 | #include <unistd.h> | 26 | #include <unistd.h> | ... | ... |
... | @@ -17,6 +17,9 @@ | ... | @@ -17,6 +17,9 @@ |
17 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, | 17 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, |
18 | MA 02110-1301 USA */ | 18 | MA 02110-1301 USA */ |
19 | 19 | ||
20 | #ifdef HAVE_CONFIG_H | ||
21 | # include <config.h> | ||
22 | #endif | ||
20 | #include <stdio.h> | 23 | #include <stdio.h> |
21 | #include <stdlib.h> | 24 | #include <stdlib.h> |
22 | #include <string.h> | 25 | #include <string.h> | ... | ... |
... | @@ -16,6 +16,9 @@ | ... | @@ -16,6 +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 | #ifdef HAVE_CONFIG_H | ||
20 | # include <config.h> | ||
21 | #endif | ||
19 | #include <stdlib.h> | 22 | #include <stdlib.h> |
20 | #include <stdio.h> | 23 | #include <stdio.h> |
21 | #include <string.h> | 24 | #include <string.h> | ... | ... |
... | @@ -51,6 +51,8 @@ int ident_port; | ... | @@ -51,6 +51,8 @@ int ident_port; |
51 | char *ident_keyfile; | 51 | char *ident_keyfile; |
52 | int ident_encrypt_only; | 52 | int ident_encrypt_only; |
53 | 53 | ||
54 | mu_acl_t imap4d_acl; | ||
55 | |||
54 | /* Number of child processes. */ | 56 | /* Number of child processes. */ |
55 | size_t children; | 57 | size_t children; |
56 | 58 | ||
... | @@ -300,6 +302,7 @@ static struct mu_cfg_param imap4d_cfg_param[] = { | ... | @@ -300,6 +302,7 @@ static struct mu_cfg_param imap4d_cfg_param[] = { |
300 | N_("Name of DES keyfile for decoding ecrypted ident responses.") }, | 302 | N_("Name of DES keyfile for decoding ecrypted ident responses.") }, |
301 | { "ident-entrypt-only", mu_cfg_bool, &ident_encrypt_only, 0, NULL, | 303 | { "ident-entrypt-only", mu_cfg_bool, &ident_encrypt_only, 0, NULL, |
302 | N_("Use only encrypted ident responses.") }, | 304 | N_("Use only encrypted ident responses.") }, |
305 | { "acl", mu_cfg_section, }, | ||
303 | TCP_WRAPPERS_CONFIG | 306 | TCP_WRAPPERS_CONFIG |
304 | { NULL } | 307 | { NULL } |
305 | }; | 308 | }; |
... | @@ -325,9 +328,10 @@ main (int argc, char **argv) | ... | @@ -325,9 +328,10 @@ main (int argc, char **argv) |
325 | mu_gocs_register ("gsasl", mu_gsasl_module_init); | 328 | mu_gocs_register ("gsasl", mu_gsasl_module_init); |
326 | #endif | 329 | #endif |
327 | mu_tcpwrapper_cfg_init (); | 330 | mu_tcpwrapper_cfg_init (); |
331 | mu_acl_cfg_init (); | ||
328 | mu_argp_init (program_version, NULL); | 332 | mu_argp_init (program_version, NULL); |
329 | if (mu_app_init (&argp, imap4d_capa, imap4d_cfg_param, | 333 | if (mu_app_init (&argp, imap4d_capa, imap4d_cfg_param, |
330 | argc, argv, 0, NULL, NULL)) | 334 | argc, argv, 0, NULL, &imap4d_acl)) |
331 | exit (1); | 335 | exit (1); |
332 | 336 | ||
333 | if (login_disabled) | 337 | if (login_disabled) |
... | @@ -397,6 +401,13 @@ main (int argc, char **argv) | ... | @@ -397,6 +401,13 @@ main (int argc, char **argv) |
397 | 401 | ||
398 | mu_diag_get_debug (&debug); | 402 | mu_diag_get_debug (&debug); |
399 | mu_debug_set_print (debug, mu_diag_syslog_printer, NULL); | 403 | mu_debug_set_print (debug, mu_diag_syslog_printer, NULL); |
404 | |||
405 | /* FIXME: this should be done automatically by cfg */ | ||
406 | if (imap4d_acl) | ||
407 | { | ||
408 | mu_acl_get_debug (imap4d_acl, &debug); | ||
409 | mu_debug_set_print (debug, mu_debug_syslog_printer, NULL); | ||
410 | } | ||
400 | } | 411 | } |
401 | 412 | ||
402 | umask (S_IROTH | S_IWOTH | S_IXOTH); /* 007 */ | 413 | umask (S_IROTH | S_IWOTH | S_IXOTH); /* 007 */ |
... | @@ -466,9 +477,6 @@ get_client_address (int fd, struct sockaddr_in *pcs) | ... | @@ -466,9 +477,6 @@ get_client_address (int fd, struct sockaddr_in *pcs) |
466 | strerror (errno)); | 477 | strerror (errno)); |
467 | return 1; | 478 | return 1; |
468 | } | 479 | } |
469 | |||
470 | mu_diag_output (MU_DIAG_INFO, _("Connect from %s"), | ||
471 | inet_ntoa (pcs->sin_addr)); | ||
472 | return 0; | 480 | return 0; |
473 | } | 481 | } |
474 | 482 | ||
... | @@ -484,13 +492,44 @@ imap4d_mainloop (int fd, FILE *infile, FILE *outfile) | ... | @@ -484,13 +492,44 @@ imap4d_mainloop (int fd, FILE *infile, FILE *outfile) |
484 | { | 492 | { |
485 | if (get_client_address (fd, &cs) == 0) | 493 | if (get_client_address (fd, &cs) == 0) |
486 | { | 494 | { |
495 | if (imap4d_acl) | ||
496 | { | ||
497 | mu_acl_result_t res; | ||
498 | int rc = mu_acl_check_sockaddr (imap4d_acl, | ||
499 | (struct sockaddr*) &cs, | ||
500 | sizeof (cs), | ||
501 | &res); | ||
502 | if (rc) | ||
503 | { | ||
504 | mu_error (_("Access from %s blocked: cannot check ACLs: %s"), | ||
505 | inet_ntoa (cs.sin_addr), mu_strerror (rc)); | ||
506 | return 1; | ||
507 | } | ||
508 | switch (res) | ||
509 | { | ||
510 | case mu_acl_result_undefined: | ||
511 | mu_diag_output (MU_DIAG_INFO, | ||
512 | _("%s: undefined ACL result; access allowed"), | ||
513 | inet_ntoa (cs.sin_addr)); | ||
514 | break; | ||
515 | |||
516 | case mu_acl_result_accept: | ||
517 | break; | ||
518 | |||
519 | case mu_acl_result_deny: | ||
520 | mu_error (_("Access from %s blocked."), | ||
521 | inet_ntoa (cs.sin_addr)); | ||
522 | return 1; | ||
523 | } | ||
524 | } | ||
525 | |||
487 | if (!mu_tcpwrapper_access (fd)) | 526 | if (!mu_tcpwrapper_access (fd)) |
488 | { | 527 | { |
489 | mu_error (_("Access from %s blocked."), inet_ntoa (cs.sin_addr)); | 528 | mu_error (_("Access from %s blocked."), inet_ntoa (cs.sin_addr)); |
490 | return 1; | 529 | return 1; |
491 | } | 530 | } |
492 | } | 531 | } |
493 | else if (mu_tcp_wrapper_enable) | 532 | else if (mu_tcp_wrapper_enable || imap4d_acl) |
494 | { | 533 | { |
495 | mu_error (_("Rejecting connection from unknown address")); | 534 | mu_error (_("Rejecting connection from unknown address")); |
496 | return 1; | 535 | return 1; | ... | ... |
... | @@ -96,6 +96,7 @@ | ... | @@ -96,6 +96,7 @@ |
96 | #include <mailutils/url.h> | 96 | #include <mailutils/url.h> |
97 | #include <mailutils/daemon.h> | 97 | #include <mailutils/daemon.h> |
98 | #include <mailutils/pam.h> | 98 | #include <mailutils/pam.h> |
99 | #include <mailutils/acl.h> | ||
99 | 100 | ||
100 | #include <mu_asprintf.h> | 101 | #include <mu_asprintf.h> |
101 | #include <mu_umaxtostr.h> | 102 | #include <mu_umaxtostr.h> | ... | ... |
... | @@ -159,6 +159,7 @@ struct mu_cfg_section | ... | @@ -159,6 +159,7 @@ struct mu_cfg_section |
159 | char *label; | 159 | char *label; |
160 | mu_cfg_section_fp parser; | 160 | mu_cfg_section_fp parser; |
161 | void *target; | 161 | void *target; |
162 | size_t offset; | ||
162 | mu_list_t /* of mu_cfg_cont */ children; | 163 | mu_list_t /* of mu_cfg_cont */ children; |
163 | char *docstring; | 164 | char *docstring; |
164 | }; | 165 | }; | ... | ... |
... | @@ -92,6 +92,21 @@ int mu_global_debug_from_string (const char *, const char *); | ... | @@ -92,6 +92,21 @@ int mu_global_debug_from_string (const char *, const char *); |
92 | int mu_debug_level_from_string (const char *string, mu_log_level_t *plev, | 92 | int mu_debug_level_from_string (const char *string, mu_log_level_t *plev, |
93 | mu_debug_t debug); | 93 | mu_debug_t debug); |
94 | 94 | ||
95 | |||
96 | #define MU_ASSERT(expr) \ | ||
97 | do \ | ||
98 | { \ | ||
99 | int rc = expr; \ | ||
100 | if (rc) \ | ||
101 | { \ | ||
102 | mu_error ("%s:%d: " #expr " failed: %s", \ | ||
103 | __FILE__, __LINE__, mu_strerror (rc)); \ | ||
104 | abort (); \ | ||
105 | } \ | ||
106 | } \ | ||
107 | while (0) | ||
108 | |||
109 | |||
95 | forloop(`i',1,11,`MKDEBUG(i)') | 110 | forloop(`i',1,11,`MKDEBUG(i)') |
96 | 111 | ||
97 | #ifdef __cplusplus | 112 | #ifdef __cplusplus | ... | ... |
... | @@ -17,6 +17,9 @@ Licensealong with this program; if not, write to the Free | ... | @@ -17,6 +17,9 @@ Licensealong with this program; if not, write to the Free |
17 | SoftwareFoundation, Inc., 51 Franklin Street, Fifth Floor, Boston, | 17 | SoftwareFoundation, Inc., 51 Franklin Street, Fifth Floor, Boston, |
18 | MA 02110-1301 USA. */ | 18 | MA 02110-1301 USA. */ |
19 | 19 | ||
20 | #ifdef HAVE_CONFIG_H | ||
21 | # include <config.h> | ||
22 | #endif | ||
20 | #include <sys/types.h> | 23 | #include <sys/types.h> |
21 | #include <sys/time.h> | 24 | #include <sys/time.h> |
22 | #include <utmp.h> | 25 | #include <utmp.h> | ... | ... |
... | @@ -22,6 +22,7 @@ AM_CFLAGS = -DSITE_VIRTUAL_PWDDIR=\"@SITE_VIRTUAL_PWDDIR@\" \ | ... | @@ -22,6 +22,7 @@ AM_CFLAGS = -DSITE_VIRTUAL_PWDDIR=\"@SITE_VIRTUAL_PWDDIR@\" \ |
22 | 22 | ||
23 | lib_LTLIBRARIES = libmucfg.la | 23 | lib_LTLIBRARIES = libmucfg.la |
24 | libmucfg_la_SOURCES=\ | 24 | libmucfg_la_SOURCES=\ |
25 | acl.c\ | ||
25 | auth.c\ | 26 | auth.c\ |
26 | common.c\ | 27 | common.c\ |
27 | init.c\ | 28 | init.c\ | ... | ... |
libcfg/acl.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 | #ifdef HAVE_CONFIG_H | ||
19 | # include <config.h> | ||
20 | #endif | ||
21 | #include "mailutils/libcfg.h" | ||
22 | #include "mailutils/acl.h" | ||
23 | #include "mailutils/argcv.h" | ||
24 | #include <stdlib.h> | ||
25 | #include <stdio.h> | ||
26 | #include <string.h> | ||
27 | #include <unistd.h> | ||
28 | #include <sys/time.h> | ||
29 | #include <sys/types.h> | ||
30 | #include <sys/socket.h> | ||
31 | #include <netinet/in.h> | ||
32 | #include <arpa/inet.h> | ||
33 | |||
34 | #define ISSPACE(c) ((c)==' '||(c)=='\t') | ||
35 | |||
36 | #define SKIPWS(p) while (*(p) && ISSPACE (*(p))) (p)++; | ||
37 | |||
38 | static char * | ||
39 | getword (char **parg) | ||
40 | { | ||
41 | char *arg = *parg; | ||
42 | char *word; | ||
43 | |||
44 | SKIPWS (arg); | ||
45 | word = arg; | ||
46 | if (*arg) | ||
47 | { | ||
48 | while (*arg && !ISSPACE (*arg)) | ||
49 | arg++; | ||
50 | *arg++ = 0; | ||
51 | } | ||
52 | *parg = arg; | ||
53 | return word; | ||
54 | } | ||
55 | |||
56 | struct netdef | ||
57 | { | ||
58 | struct sockaddr *sa; | ||
59 | int len; | ||
60 | unsigned long netmask; | ||
61 | }; | ||
62 | |||
63 | #ifndef INADDR_ANY | ||
64 | # define INADDR_ANY 0 | ||
65 | #endif | ||
66 | |||
67 | int | ||
68 | parse_address (mu_debug_t err, char *str, struct netdef *nd) | ||
69 | { | ||
70 | struct sockaddr_in in; | ||
71 | |||
72 | in.sin_family = AF_INET; | ||
73 | if (strcmp (str, "any") == 0) | ||
74 | { | ||
75 | in.sin_addr.s_addr = INADDR_ANY; | ||
76 | nd->netmask = 0; | ||
77 | } | ||
78 | else if (inet_aton (str, &in.sin_addr) == 0) | ||
79 | { | ||
80 | mu_cfg_format_error (err, MU_DEBUG_ERROR, _("Invalid IPv4: %s"), str); | ||
81 | return 1; | ||
82 | } | ||
83 | in.sin_port = 0; | ||
84 | nd->len = sizeof (in); | ||
85 | nd->sa = malloc (nd->len); | ||
86 | if (!nd->sa) | ||
87 | { | ||
88 | mu_cfg_format_error (err, MU_DEBUG_ERROR, "%s", mu_strerror (errno)); | ||
89 | return 1; | ||
90 | } | ||
91 | memcpy (nd->sa, &in, sizeof (in)); | ||
92 | return 0; | ||
93 | } | ||
94 | |||
95 | static int | ||
96 | parsearg (mu_debug_t err, char *arg, struct netdef *pnd, char **prest) | ||
97 | { | ||
98 | char *w, *p; | ||
99 | unsigned long netmask; | ||
100 | |||
101 | w = getword (&arg); | ||
102 | if (strcmp (w, "from") == 0) | ||
103 | w = getword (&arg); | ||
104 | |||
105 | p = strchr (w, '/'); | ||
106 | if (p) | ||
107 | { | ||
108 | char *q; | ||
109 | unsigned netlen; | ||
110 | |||
111 | *p++ = 0; | ||
112 | netlen = strtoul (p, &q, 10); | ||
113 | if (*q == 0) | ||
114 | { | ||
115 | if (netlen == 0) | ||
116 | netmask = 0; | ||
117 | else | ||
118 | { | ||
119 | netmask = 0xfffffffful >> (32 - netlen); | ||
120 | netmask <<= (32 - netlen); | ||
121 | netmask = htonl (netmask); | ||
122 | } | ||
123 | } | ||
124 | else if (*q == '.') | ||
125 | { | ||
126 | struct in_addr addr; | ||
127 | |||
128 | if (inet_aton (p, &addr) == 0) | ||
129 | { | ||
130 | mu_cfg_format_error (err, MU_DEBUG_ERROR, _("invalid netmask")); | ||
131 | return 1; | ||
132 | } | ||
133 | netmask = addr.s_addr; | ||
134 | } | ||
135 | else | ||
136 | { | ||
137 | mu_cfg_format_error (err, MU_DEBUG_ERROR, _("invalid netmask")); | ||
138 | return 1; | ||
139 | } | ||
140 | } | ||
141 | else | ||
142 | netmask = 0xfffffffful; | ||
143 | |||
144 | pnd->netmask = netmask; | ||
145 | if (parse_address (err, w, pnd)) | ||
146 | return 1; | ||
147 | |||
148 | SKIPWS (arg); | ||
149 | if (prest) | ||
150 | { | ||
151 | if (*arg == 0) | ||
152 | *prest = NULL; | ||
153 | else | ||
154 | { | ||
155 | int len = strlen (arg); | ||
156 | *prest = malloc (len); | ||
157 | if (!prest) | ||
158 | { | ||
159 | mu_cfg_format_error (err, MU_DEBUG_ERROR, | ||
160 | "%s", mu_strerror (errno)); | ||
161 | return 1; | ||
162 | } | ||
163 | if (arg[0] == '"' || arg[0] == '\'') | ||
164 | mu_argcv_unquote_copy (*prest, arg, len); | ||
165 | else | ||
166 | strcpy (*prest, arg); | ||
167 | } | ||
168 | } | ||
169 | else if (*arg != 0) | ||
170 | { | ||
171 | mu_cfg_format_error (err, MU_DEBUG_ERROR, _("junk after IP address")); | ||
172 | return 1; | ||
173 | } | ||
174 | return 0; | ||
175 | } | ||
176 | |||
177 | static int | ||
178 | cb_allow (mu_debug_t err, void *data, char *arg) | ||
179 | { | ||
180 | int rc; | ||
181 | mu_acl_t acl = *(mu_acl_t*)data; | ||
182 | struct netdef ndef; | ||
183 | |||
184 | if (parsearg (err, arg, &ndef, NULL)) | ||
185 | return 1; | ||
186 | rc = mu_acl_append (acl, mu_acl_accept, NULL, ndef.sa, ndef.len, | ||
187 | ndef.netmask); | ||
188 | if (rc) | ||
189 | mu_cfg_format_error (err, MU_DEBUG_ERROR, | ||
190 | _("cannot append acl entry: %s"), | ||
191 | mu_strerror (rc)); | ||
192 | free (ndef.sa); | ||
193 | return rc; | ||
194 | } | ||
195 | |||
196 | static int | ||
197 | cb_deny (mu_debug_t err, void *data, char *arg) | ||
198 | { | ||
199 | int rc; | ||
200 | mu_acl_t acl = *(mu_acl_t*)data; | ||
201 | struct netdef ndef; | ||
202 | |||
203 | if (parsearg (err, arg, &ndef, NULL)) | ||
204 | return 1; | ||
205 | rc = mu_acl_append (acl, mu_acl_deny, NULL, ndef.sa, ndef.len, | ||
206 | ndef.netmask); | ||
207 | if (rc) | ||
208 | mu_cfg_format_error (err, MU_DEBUG_ERROR, | ||
209 | _("cannot append acl entry: %s"), | ||
210 | mu_strerror (rc)); | ||
211 | free (ndef.sa); | ||
212 | return rc; | ||
213 | } | ||
214 | |||
215 | static int | ||
216 | cb_log (mu_debug_t err, void *data, char *arg) | ||
217 | { | ||
218 | int rc; | ||
219 | mu_acl_t acl = *(mu_acl_t*)data; | ||
220 | struct netdef ndef; | ||
221 | char *rest; | ||
222 | |||
223 | if (parsearg (err, arg, &ndef, &rest)) | ||
224 | return 1; | ||
225 | rc = mu_acl_append (acl, mu_acl_log, rest, ndef.sa, ndef.len, | ||
226 | ndef.netmask); | ||
227 | if (rc) | ||
228 | mu_cfg_format_error (err, MU_DEBUG_ERROR, | ||
229 | _("cannot append acl entry: %s"), | ||
230 | mu_strerror (rc)); | ||
231 | free (ndef.sa); | ||
232 | return rc; | ||
233 | } | ||
234 | |||
235 | static int | ||
236 | cb_exec (mu_debug_t err, void *data, char *arg) | ||
237 | { | ||
238 | int rc; | ||
239 | mu_acl_t acl = *(mu_acl_t*)data; | ||
240 | struct netdef ndef; | ||
241 | char *rest; | ||
242 | |||
243 | if (parsearg (err, arg, &ndef, &rest)) | ||
244 | return 1; | ||
245 | rc = mu_acl_append (acl, mu_acl_exec, rest, ndef.sa, ndef.len, | ||
246 | ndef.netmask); | ||
247 | if (rc) | ||
248 | mu_cfg_format_error (err, MU_DEBUG_ERROR, | ||
249 | _("cannot append acl entry: %s"), | ||
250 | mu_strerror (rc)); | ||
251 | free (ndef.sa); | ||
252 | return rc; | ||
253 | } | ||
254 | |||
255 | static int | ||
256 | cb_ifexec (mu_debug_t err, void *data, char *arg) | ||
257 | { | ||
258 | int rc; | ||
259 | mu_acl_t acl = *(mu_acl_t*)data; | ||
260 | struct netdef ndef; | ||
261 | char *rest; | ||
262 | |||
263 | if (parsearg (err, arg, &ndef, &rest)) | ||
264 | return 1; | ||
265 | rc = mu_acl_append (acl, mu_acl_ifexec, rest, ndef.sa, ndef.len, | ||
266 | ndef.netmask); | ||
267 | if (rc) | ||
268 | mu_cfg_format_error (err, MU_DEBUG_ERROR, | ||
269 | _("cannot append acl entry: %s"), | ||
270 | mu_strerror (rc)); | ||
271 | free (ndef.sa); | ||
272 | return rc; | ||
273 | } | ||
274 | |||
275 | static struct mu_cfg_param acl_param[] = { | ||
276 | { "allow", mu_cfg_callback, NULL, 0, cb_allow, | ||
277 | N_("Allow connections from this IP address. Optional word `from' is " | ||
278 | "allowed between it and its argument. The same holds true for other " | ||
279 | "actions below."), | ||
280 | N_("addr: IP") }, | ||
281 | { "deny", mu_cfg_callback, NULL, 0, cb_deny, | ||
282 | N_("Deny connections from this IP address."), | ||
283 | N_("addr: IP") }, | ||
284 | { "log", mu_cfg_callback, NULL, 0, cb_log, | ||
285 | N_("Log connections from this IP address."), | ||
286 | N_("addr: IP") }, | ||
287 | { "exec", mu_cfg_callback, NULL, 0, cb_exec, | ||
288 | N_("Execute supplied program if a connection from this IP address is " | ||
289 | "requested. Arguments are:\n" | ||
290 | " <addr: IP> <program: string>\n" | ||
291 | "Following macros are expanded in <program> before executing:\n" | ||
292 | " address - Source IP address\n" | ||
293 | " port - Source port number\n") }, | ||
294 | { "ifexec", mu_cfg_callback, NULL, 0, cb_ifexec, | ||
295 | N_("If a connection from this IP address is requested, execute supplied " | ||
296 | "program and allow or deny the connection depending on its exit code. " | ||
297 | "See `exec' for a description of its arguments.") }, | ||
298 | { NULL } | ||
299 | }; | ||
300 | |||
301 | static int | ||
302 | acl_section_parser (enum mu_cfg_section_stage stage, | ||
303 | const mu_cfg_node_t *node, | ||
304 | const char *section_label, void **section_data, | ||
305 | void *call_data, | ||
306 | mu_cfg_tree_t *tree) | ||
307 | { | ||
308 | switch (stage) | ||
309 | { | ||
310 | case mu_cfg_section_start: | ||
311 | { | ||
312 | void *data = *section_data; | ||
313 | mu_acl_create ((mu_acl_t*)data); | ||
314 | } | ||
315 | break; | ||
316 | |||
317 | case mu_cfg_section_end: | ||
318 | break; | ||
319 | } | ||
320 | return 0; | ||
321 | } | ||
322 | |||
323 | void | ||
324 | mu_acl_cfg_init () | ||
325 | { | ||
326 | struct mu_cfg_section *section; | ||
327 | if (mu_create_canned_section ("acl", §ion) == 0) | ||
328 | { | ||
329 | section->parser = acl_section_parser; | ||
330 | mu_cfg_section_add_params (section, acl_param); | ||
331 | } | ||
332 | } |
... | @@ -232,7 +232,11 @@ cb_debug_level (mu_debug_t debug, void *data, char *arg) | ... | @@ -232,7 +232,11 @@ cb_debug_level (mu_debug_t debug, void *data, char *arg) |
232 | } | 232 | } |
233 | else | 233 | else |
234 | pfx = strdup ("command line");/*FIXME*/ | 234 | pfx = strdup ("command line");/*FIXME*/ |
235 | debug_settings.errpfx = pfx; | 235 | /*FIXME:*/ |
236 | mu_global_debug_from_string (debug_settings.string, pfx); | ||
237 | free (debug_settings.string); | ||
238 | free (debug_settings.errpfx); | ||
239 | memset (&debug_settings, 0, sizeof debug_settings); | ||
236 | return 0; | 240 | return 0; |
237 | } | 241 | } |
238 | 242 | ... | ... |
... | @@ -426,11 +426,10 @@ _expand_aclno (const char *name, void *data, char **p) | ... | @@ -426,11 +426,10 @@ _expand_aclno (const char *name, void *data, char **p) |
426 | #endif | 426 | #endif |
427 | 427 | ||
428 | static int | 428 | static int |
429 | spawn_prog (const char *cmdline, int *pstatus, struct run_closure *rp) | 429 | expand_arg (const char *cmdline, struct run_closure *rp, char **s) |
430 | { | 430 | { |
431 | char *s; | 431 | int rc; |
432 | mu_vartab_t vtab; | 432 | mu_vartab_t vtab; |
433 | pid_t pid; | ||
434 | 433 | ||
435 | MU_DEBUG1 (rp->debug, MU_DEBUG_TRACE0, "Expanding \"%s\" => ", cmdline); | 434 | MU_DEBUG1 (rp->debug, MU_DEBUG_TRACE0, "Expanding \"%s\" => ", cmdline); |
436 | 435 | ||
... | @@ -463,10 +462,24 @@ spawn_prog (const char *cmdline, int *pstatus, struct run_closure *rp) | ... | @@ -463,10 +462,24 @@ spawn_prog (const char *cmdline, int *pstatus, struct run_closure *rp) |
463 | break; | 462 | break; |
464 | } | 463 | } |
465 | 464 | ||
466 | mu_vartab_expand (vtab, cmdline, &s); | 465 | rc = mu_vartab_expand (vtab, cmdline, s); |
467 | mu_vartab_destroy (&vtab); | 466 | mu_vartab_destroy (&vtab); |
468 | 467 | ||
469 | MU_DEBUG1 (rp->debug, MU_DEBUG_TRACE0, "\"%s\". ", s); | 468 | if (rc == 0) |
469 | MU_DEBUG1 (rp->debug, MU_DEBUG_TRACE0, "\"%s\". ", *s); | ||
470 | else | ||
471 | MU_DEBUG (rp->debug, MU_DEBUG_TRACE0, "failed. "); | ||
472 | return rc; | ||
473 | } | ||
474 | |||
475 | static int | ||
476 | spawn_prog (const char *cmdline, int *pstatus, struct run_closure *rp) | ||
477 | { | ||
478 | char *s; | ||
479 | pid_t pid; | ||
480 | |||
481 | if (expand_arg (cmdline, rp, &s)) | ||
482 | s = strdup (cmdline); | ||
470 | 483 | ||
471 | pid = fork (); | 484 | pid = fork (); |
472 | if (pid == 0) | 485 | if (pid == 0) |
... | @@ -549,13 +562,20 @@ _run_entry (void *item, void *data) | ... | @@ -549,13 +562,20 @@ _run_entry (void *item, void *data) |
549 | 562 | ||
550 | case mu_acl_log: | 563 | case mu_acl_log: |
551 | { | 564 | { |
565 | char *s; | ||
552 | mu_debug_t dbg = NULL; | 566 | mu_debug_t dbg = NULL; |
553 | mu_diag_get_debug (&dbg); | 567 | mu_diag_get_debug (&dbg); |
568 | if (ent->arg && expand_arg (ent->arg, rp, &s) == 0) | ||
569 | { | ||
570 | mu_debug_printf (dbg, MU_DIAG_INFO, "%s\n", s); | ||
571 | free (s); | ||
572 | } | ||
573 | else | ||
574 | { | ||
554 | debug_sockaddr (dbg, MU_DIAG_INFO, rp->sa); | 575 | debug_sockaddr (dbg, MU_DIAG_INFO, rp->sa); |
555 | if (ent->arg) | ||
556 | mu_debug_printf (dbg, MU_DIAG_INFO, ": %s", (char*) ent->arg); | ||
557 | mu_debug_printf (dbg, MU_DIAG_INFO, "\n"); | 576 | mu_debug_printf (dbg, MU_DIAG_INFO, "\n"); |
558 | } | 577 | } |
578 | } | ||
559 | break; | 579 | break; |
560 | 580 | ||
561 | case mu_acl_exec: | 581 | case mu_acl_exec: | ... | ... |
... | @@ -56,12 +56,14 @@ mu_create_canned_section (char *name, struct mu_cfg_section **psection) | ... | @@ -56,12 +56,14 @@ mu_create_canned_section (char *name, struct mu_cfg_section **psection) |
56 | struct mu_cfg_cont **pcont; | 56 | struct mu_cfg_cont **pcont; |
57 | alloc_section_tab (); | 57 | alloc_section_tab (); |
58 | rc = mu_assoc_ref_install (section_tab, name, (void **)&pcont); | 58 | rc = mu_assoc_ref_install (section_tab, name, (void **)&pcont); |
59 | if (rc == 0 || rc == MU_ERR_EXISTS) | 59 | if (rc == 0) |
60 | { | 60 | { |
61 | mu_config_create_container (pcont, mu_cfg_cont_section); | 61 | mu_config_create_container (pcont, mu_cfg_cont_section); |
62 | *psection = &(*pcont)->v.section; | 62 | *psection = &(*pcont)->v.section; |
63 | (*psection)->ident = name; | 63 | (*psection)->ident = name; |
64 | } | 64 | } |
65 | else if (rc == MU_ERR_EXISTS) | ||
66 | *psection = &(*pcont)->v.section; | ||
65 | return rc; | 67 | return rc; |
66 | } | 68 | } |
67 | 69 | ||
... | @@ -72,12 +74,14 @@ mu_create_canned_param (char *name, struct mu_cfg_param **pparam) | ... | @@ -72,12 +74,14 @@ mu_create_canned_param (char *name, struct mu_cfg_param **pparam) |
72 | struct mu_cfg_cont **pcont; | 74 | struct mu_cfg_cont **pcont; |
73 | alloc_section_tab (); | 75 | alloc_section_tab (); |
74 | rc = mu_assoc_ref_install (section_tab, name, (void **)&pcont); | 76 | rc = mu_assoc_ref_install (section_tab, name, (void **)&pcont); |
75 | if (rc == 0 || rc == MU_ERR_EXISTS) | 77 | if (rc == 0) |
76 | { | 78 | { |
77 | mu_config_create_container (pcont, mu_cfg_cont_param); | 79 | mu_config_create_container (pcont, mu_cfg_cont_param); |
78 | *pparam = &(*pcont)->v.param; | 80 | *pparam = &(*pcont)->v.param; |
79 | (*pparam)->ident = name; | 81 | (*pparam)->ident = name; |
80 | } | 82 | } |
83 | else if (rc == MU_ERR_EXISTS) | ||
84 | *pparam = &(*pcont)->v.param; | ||
81 | return rc; | 85 | return rc; |
82 | } | 86 | } |
83 | 87 | ||
... | @@ -256,6 +260,7 @@ mu_cfg_section_add_params (struct mu_cfg_section *sect, | ... | @@ -256,6 +260,7 @@ mu_cfg_section_add_params (struct mu_cfg_section *sect, |
256 | abort (); | 260 | abort (); |
257 | } | 261 | } |
258 | mu_config_clone_container (container); | 262 | mu_config_clone_container (container); |
263 | container->v.section.offset = param->offset; | ||
259 | } | 264 | } |
260 | else | 265 | else |
261 | { | 266 | { | ... | ... |
... | @@ -234,6 +234,11 @@ format_param (mu_stream_t stream, struct mu_cfg_param *param, int level) | ... | @@ -234,6 +234,11 @@ format_param (mu_stream_t stream, struct mu_cfg_param *param, int level) |
234 | if (param->docstring) | 234 | if (param->docstring) |
235 | mu_cfg_format_docstring (stream, gettext (param->docstring), level); | 235 | mu_cfg_format_docstring (stream, gettext (param->docstring), level); |
236 | format_level (stream, level); | 236 | format_level (stream, level); |
237 | if (param->argname && strchr (param->argname, ':')) | ||
238 | mu_stream_sequential_printf (stream, "%s <%s>;\n", | ||
239 | param->ident, | ||
240 | gettext (param->argname)); | ||
241 | else | ||
237 | mu_stream_sequential_printf (stream, "%s <%s: %s>;\n", | 242 | mu_stream_sequential_printf (stream, "%s <%s: %s>;\n", |
238 | param->ident, | 243 | param->ident, |
239 | gettext (param->argname ? | 244 | gettext (param->argname ? | ... | ... |
... | @@ -999,6 +999,10 @@ _scan_tree_helper (const mu_cfg_node_t *node, void *data) | ... | @@ -999,6 +999,10 @@ _scan_tree_helper (const mu_cfg_node_t *node, void *data) |
999 | } | 999 | } |
1000 | if (!sec->children) | 1000 | if (!sec->children) |
1001 | return MU_CFG_ITER_SKIP; | 1001 | return MU_CFG_ITER_SKIP; |
1002 | if (sdata->list->sec->target) | ||
1003 | sec->target = (char*)sdata->list->sec->target + sec->offset; | ||
1004 | else if (sdata->target) | ||
1005 | sec->target = (char*)sdata->target + sec->offset; | ||
1002 | if (sec->parser && | 1006 | if (sec->parser && |
1003 | sec->parser (mu_cfg_section_start, node, | 1007 | sec->parser (mu_cfg_section_start, node, |
1004 | sec->label, &sec->target, | 1008 | sec->label, &sec->target, | ... | ... |
... | @@ -58,6 +58,8 @@ char *login_stat_file = LOGIN_STAT_FILE; | ... | @@ -58,6 +58,8 @@ char *login_stat_file = LOGIN_STAT_FILE; |
58 | unsigned expire = EXPIRE_NEVER; /* Expire messages after this number of days */ | 58 | unsigned expire = EXPIRE_NEVER; /* Expire messages after this number of days */ |
59 | int expire_on_exit = 0; /* Delete expired messages on exit */ | 59 | int expire_on_exit = 0; /* Delete expired messages on exit */ |
60 | 60 | ||
61 | mu_acl_t pop3d_acl; | ||
62 | |||
61 | static int pop3d_mainloop (int fd, FILE *, FILE *); | 63 | static int pop3d_mainloop (int fd, FILE *, FILE *); |
62 | static void pop3d_daemon_init (void); | 64 | static void pop3d_daemon_init (void); |
63 | static void pop3d_daemon (unsigned int, unsigned int); | 65 | static void pop3d_daemon (unsigned int, unsigned int); |
... | @@ -261,11 +263,12 @@ main (int argc, char **argv) | ... | @@ -261,11 +263,12 @@ main (int argc, char **argv) |
261 | mu_gocs_register ("tls", mu_tls_module_init); | 263 | mu_gocs_register ("tls", mu_tls_module_init); |
262 | #endif /* WITH_TLS */ | 264 | #endif /* WITH_TLS */ |
263 | mu_tcpwrapper_cfg_init (); | 265 | mu_tcpwrapper_cfg_init (); |
266 | mu_acl_cfg_init (); | ||
264 | 267 | ||
265 | mu_gocs_daemon = default_gocs_daemon; | 268 | mu_gocs_daemon = default_gocs_daemon; |
266 | mu_argp_init (program_version, NULL); | 269 | mu_argp_init (program_version, NULL); |
267 | if (mu_app_init (&argp, pop3d_argp_capa, pop3d_cfg_param, | 270 | if (mu_app_init (&argp, pop3d_argp_capa, pop3d_cfg_param, |
268 | argc, argv, 0, NULL, NULL)) | 271 | argc, argv, 0, NULL, &pop3d_acl)) |
269 | exit (1); | 272 | exit (1); |
270 | 273 | ||
271 | if (expire == 0) | 274 | if (expire == 0) |
... | @@ -326,6 +329,13 @@ main (int argc, char **argv) | ... | @@ -326,6 +329,13 @@ main (int argc, char **argv) |
326 | 329 | ||
327 | mu_diag_get_debug (&debug); | 330 | mu_diag_get_debug (&debug); |
328 | mu_debug_set_print (debug, mu_diag_syslog_printer, NULL); | 331 | mu_debug_set_print (debug, mu_diag_syslog_printer, NULL); |
332 | |||
333 | /* FIXME: this should be done automatically by cfg */ | ||
334 | if (pop3d_acl) | ||
335 | { | ||
336 | mu_acl_get_debug (pop3d_acl, &debug); | ||
337 | mu_debug_set_print (debug, mu_debug_syslog_printer, NULL); | ||
338 | } | ||
329 | } | 339 | } |
330 | 340 | ||
331 | umask (S_IROTH | S_IWOTH | S_IXOTH); /* 007 */ | 341 | umask (S_IROTH | S_IWOTH | S_IXOTH); /* 007 */ |
... | @@ -403,9 +413,6 @@ pop3d_get_client_address (int fd, struct sockaddr_in *pcs) | ... | @@ -403,9 +413,6 @@ pop3d_get_client_address (int fd, struct sockaddr_in *pcs) |
403 | strerror (errno)); | 413 | strerror (errno)); |
404 | return 1; | 414 | return 1; |
405 | } | 415 | } |
406 | else | ||
407 | mu_diag_output (MU_DIAG_INFO, | ||
408 | _("connect from %s"), inet_ntoa (pcs->sin_addr)); | ||
409 | } | 416 | } |
410 | return 0; | 417 | return 0; |
411 | } | 418 | } |
... | @@ -425,13 +432,44 @@ pop3d_mainloop (int fd, FILE *infile, FILE *outfile) | ... | @@ -425,13 +432,44 @@ pop3d_mainloop (int fd, FILE *infile, FILE *outfile) |
425 | 432 | ||
426 | if (pop3d_get_client_address (fd, &cs) == 0) | 433 | if (pop3d_get_client_address (fd, &cs) == 0) |
427 | { | 434 | { |
435 | if (pop3d_acl) | ||
436 | { | ||
437 | mu_acl_result_t res; | ||
438 | int rc = mu_acl_check_sockaddr (pop3d_acl, | ||
439 | (struct sockaddr*) &cs, | ||
440 | sizeof (cs), | ||
441 | &res); | ||
442 | if (rc) | ||
443 | { | ||
444 | mu_error (_("Access from %s blocked: cannot check ACLs: %s"), | ||
445 | inet_ntoa (cs.sin_addr), mu_strerror (rc)); | ||
446 | return 1; | ||
447 | } | ||
448 | switch (res) | ||
449 | { | ||
450 | case mu_acl_result_undefined: | ||
451 | mu_diag_output (MU_DIAG_INFO, | ||
452 | _("%s: undefined ACL result; access allowed"), | ||
453 | inet_ntoa (cs.sin_addr)); | ||
454 | break; | ||
455 | |||
456 | case mu_acl_result_accept: | ||
457 | break; | ||
458 | |||
459 | case mu_acl_result_deny: | ||
460 | mu_error (_("Access from %s blocked."), | ||
461 | inet_ntoa (cs.sin_addr)); | ||
462 | return 1; | ||
463 | } | ||
464 | } | ||
465 | |||
428 | if (!mu_tcpwrapper_access (fd)) | 466 | if (!mu_tcpwrapper_access (fd)) |
429 | { | 467 | { |
430 | mu_error (_("Access from %s blocked."), inet_ntoa (cs.sin_addr)); | 468 | mu_error (_("Access from %s blocked."), inet_ntoa (cs.sin_addr)); |
431 | return 1; | 469 | return 1; |
432 | } | 470 | } |
433 | } | 471 | } |
434 | else if (!debug_mode && mu_tcp_wrapper_enable) | 472 | else if (!debug_mode && (mu_tcp_wrapper_enable || pop3d_acl)) |
435 | { | 473 | { |
436 | mu_error (_("Rejecting connection from unknown address")); | 474 | mu_error (_("Rejecting connection from unknown address")); |
437 | return 1; | 475 | return 1; | ... | ... |
... | @@ -155,6 +155,7 @@ extern int expire_on_exit; | ... | @@ -155,6 +155,7 @@ extern int expire_on_exit; |
155 | #include <mailutils/tls.h> | 155 | #include <mailutils/tls.h> |
156 | #include <mailutils/url.h> | 156 | #include <mailutils/url.h> |
157 | #include <mailutils/md5.h> | 157 | #include <mailutils/md5.h> |
158 | #include <mailutils/acl.h> | ||
158 | 159 | ||
159 | /* For Berkley DB2 APOP password file */ | 160 | /* For Berkley DB2 APOP password file */ |
160 | #ifdef HAVE_DB_H | 161 | #ifdef HAVE_DB_H | ... | ... |
-
Please register or sign in to post a comment