Added TLS/SSL support (via GnuTLS)
Showing
10 changed files
with
224 additions
and
151 deletions
1 | ## Process this file with GNU Automake to create Makefile.in | 1 | ## Process this file with GNU Automake to create Makefile.in |
2 | 2 | ||
3 | ## Copyright (C) 1999, 2000, 2001, 2002 Free Software Foundation, Inc. | 3 | ## Copyright (C) 1999, 2000, 2001, 2002, 2003 Free Software Foundation, Inc. |
4 | ## | 4 | ## |
5 | ## GNU Mailtuils is free software; you can redistribute it and/or | 5 | ## GNU Mailutils is free software; you can redistribute it and/or |
6 | ## modify it under the terms of the GNU General Public License as | 6 | ## modify it under the terms of the GNU General Public License as |
7 | ## published by the Free Software Foundation; either version 2, or (at | 7 | ## published by the Free Software Foundation; either version 2, or (at |
8 | ## your option) any later version. | 8 | ## your option) any later version. |
9 | ## | 9 | ## |
10 | ## This program is distributed in the hope that it will be useful, but | 10 | ## GNU Mailutils is distributed in the hope that it will be useful, but |
11 | ## WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | ## WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | ## General Public License for more details. | 13 | ## General Public License for more details. |
14 | ## | 14 | ## |
15 | ## You should have received a copy of the GNU General Public License | 15 | ## You should have received a copy of the GNU General Public License |
16 | ## along with this program; if not, write to the Free Software | 16 | ## along with GNU Mailutils; if not, write to the Free Software |
17 | ## Foundation, Inc. | 17 | ## Foundation, Inc. |
18 | ## 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | 18 | ## 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
19 | 19 | ||
... | @@ -26,8 +26,8 @@ imap4d_LDADD = @AUTHOBJS@ ../mailbox/libmailbox.la @AUTHLIBS@ ../lib/libmailuti | ... | @@ -26,8 +26,8 @@ imap4d_LDADD = @AUTHOBJS@ ../mailbox/libmailbox.la @AUTHLIBS@ ../lib/libmailuti |
26 | imap4d_SOURCES = append.c authenticate.c bye.c capability.c check.c close.c \ | 26 | imap4d_SOURCES = append.c authenticate.c bye.c capability.c check.c close.c \ |
27 | commands.c copy.c create.c delete.c examine.c expunge.c fetch.c imap4d.c \ | 27 | commands.c copy.c create.c delete.c examine.c expunge.c fetch.c imap4d.c \ |
28 | imap4d.h list.c logout.c login.c lsub.c namespace.c noop.c rename.c search.c \ | 28 | imap4d.h list.c logout.c login.c lsub.c namespace.c noop.c rename.c search.c \ |
29 | select.c signal.c status.c store.c subscribe.c sync.c uid.c unsubscribe.c \ | 29 | select.c signal.c starttls.c status.c store.c subscribe.c sync.c uid.c \ |
30 | util.c version.c | 30 | unsubscribe.c util.c version.c |
31 | 31 | ||
32 | ## This kludge is necessary to correctly establish imap4d -> AUTHOBJS | 32 | ## This kludge is necessary to correctly establish imap4d -> AUTHOBJS |
33 | ## dependency. Think about better approach --gray | 33 | ## dependency. Think about better approach --gray | ... | ... |
1 | /* GNU Mailutils -- a suite of utilities for electronic mail | 1 | /* GNU Mailutils -- a suite of utilities for electronic mail |
2 | Copyright (C) 1999, 2001, 2002 Free Software Foundation, Inc. | 2 | Copyright (C) 1999, 2001, 2002, 2003 Free Software Foundation, Inc. |
3 | 3 | ||
4 | GNU Mailutils is free software; you can redistribute it and/or modify | 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 | 5 | it under the terms of the GNU General Public License as published by |
... | @@ -13,9 +13,10 @@ | ... | @@ -13,9 +13,10 @@ |
13 | 13 | ||
14 | You should have received a copy of the GNU General Public License | 14 | You should have received a copy of the GNU General Public License |
15 | along with GNU Mailutils; if not, write to the Free Software | 15 | along with GNU Mailutils; if not, write to the Free Software |
16 | Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ | 16 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ |
17 | 17 | ||
18 | /* GSSAPI authentication for imap (rfc 1731). | 18 | /* |
19 | GSSAPI authentication for imap (rfc 1731). | ||
19 | */ | 20 | */ |
20 | 21 | ||
21 | #include "imap4d.h" | 22 | #include "imap4d.h" |
... | @@ -46,11 +47,8 @@ display_status_1 (char *m, OM_uint32 code, int type) | ... | @@ -46,11 +47,8 @@ display_status_1 (char *m, OM_uint32 code, int type) |
46 | do | 47 | do |
47 | { | 48 | { |
48 | maj_stat = gss_display_status (&min_stat, code, | 49 | maj_stat = gss_display_status (&min_stat, code, |
49 | type, GSS_C_NULL_OID, | 50 | type, GSS_C_NULL_OID, &msg_ctx, &msg); |
50 | &msg_ctx, &msg); | 51 | syslog (LOG_ERR, _("GSS-API error %s: %s\n"), m, (char *) msg.value); |
51 | syslog (LOG_ERR, | ||
52 | _("GSS-API error %s: %s\n"), m, | ||
53 | (char *)msg.value); | ||
54 | gss_release_buffer (&min_stat, &msg); | 52 | gss_release_buffer (&min_stat, &msg); |
55 | } | 53 | } |
56 | while (msg_ctx); | 54 | while (msg_ctx); |
... | @@ -64,14 +62,14 @@ display_status (char *msg, OM_uint32 maj_stat, OM_uint32 min_stat) | ... | @@ -64,14 +62,14 @@ display_status (char *msg, OM_uint32 maj_stat, OM_uint32 min_stat) |
64 | } | 62 | } |
65 | 63 | ||
66 | static int | 64 | static int |
67 | imap4d_gss_userok(gss_buffer_t client_name, char *name) | 65 | imap4d_gss_userok (gss_buffer_t client_name, char *name) |
68 | { | 66 | { |
69 | int rc = -1; | 67 | int rc = -1; |
70 | krb5_principal p; | 68 | krb5_principal p; |
71 | krb5_context kcontext; | 69 | krb5_context kcontext; |
72 | 70 | ||
73 | krb5_init_context (&kcontext); | 71 | krb5_init_context (&kcontext); |
74 | 72 | ||
75 | if (krb5_parse_name (kcontext, client_name->value, &p) != 0) | 73 | if (krb5_parse_name (kcontext, client_name->value, &p) != 0) |
76 | return -1; | 74 | return -1; |
77 | if (krb5_kuserok (kcontext, p, name)) | 75 | if (krb5_kuserok (kcontext, p, name)) |
... | @@ -99,57 +97,54 @@ auth_gssapi (struct imap4d_command *command, char **username) | ... | @@ -99,57 +97,54 @@ auth_gssapi (struct imap4d_command *command, char **username) |
99 | gss_qop_t quality; | 97 | gss_qop_t quality; |
100 | gss_name_t client; | 98 | gss_name_t client; |
101 | gss_buffer_desc client_name; | 99 | gss_buffer_desc client_name; |
102 | 100 | ||
103 | /* Obtain server credentials. RFC 1732 states, that | 101 | /* Obtain server credentials. RFC 1732 states, that |
104 | "The server must issue a ready response with no data and pass the | 102 | "The server must issue a ready response with no data and pass the |
105 | resulting client supplied token to GSS_Accept_sec_context as | 103 | resulting client supplied token to GSS_Accept_sec_context as |
106 | input_token, setting acceptor_cred_handle to NULL (for "use default | 104 | input_token, setting acceptor_cred_handle to NULL (for "use default |
107 | credentials"), and 0 for input_context_handle (initially)." | 105 | credentials"), and 0 for input_context_handle (initially)." |
108 | In MIT implementation, passing NULL as acceptor_cred_handle won't | 106 | In MIT implementation, passing NULL as acceptor_cred_handle won't |
109 | work (possibly due to a bug in krb5_gss_accept_sec_context()), so | 107 | work (possibly due to a bug in krb5_gss_accept_sec_context()), so |
110 | we acquire server credentials explicitly. */ | 108 | we acquire server credentials explicitly. */ |
111 | 109 | ||
112 | asprintf ((char**)&tmp, "imap@%s", util_localname ()); | 110 | asprintf ((char **) &tmp, "imap@%s", util_localname ()); |
113 | tokbuf.value = tmp; | 111 | tokbuf.value = tmp; |
114 | tokbuf.length = strlen (tokbuf.value) + 1; | 112 | tokbuf.length = strlen (tokbuf.value) + 1; |
115 | maj_stat = gss_import_name (&min_stat, &tokbuf, | 113 | maj_stat = gss_import_name (&min_stat, &tokbuf, |
116 | gss_nt_service_name, | 114 | gss_nt_service_name, &server_name); |
117 | &server_name); | ||
118 | if (maj_stat != GSS_S_COMPLETE) | 115 | if (maj_stat != GSS_S_COMPLETE) |
119 | { | 116 | { |
120 | display_status ("import name", maj_stat, min_stat); | 117 | display_status ("import name", maj_stat, min_stat); |
121 | util_finish (command, RESP_NO, | 118 | util_finish (command, RESP_NO, "GSSAPI authentication not available"); |
122 | "GSSAPI authentication not available"); | ||
123 | return 1; | 119 | return 1; |
124 | } | 120 | } |
125 | 121 | ||
126 | maj_stat = gss_acquire_cred (&min_stat, server_name, 0, | 122 | maj_stat = gss_acquire_cred (&min_stat, server_name, 0, |
127 | GSS_C_NULL_OID_SET, GSS_C_ACCEPT, | 123 | GSS_C_NULL_OID_SET, GSS_C_ACCEPT, |
128 | &server_creds, NULL, NULL); | 124 | &server_creds, NULL, NULL); |
129 | gss_release_name(&min_stat2, &server_name); | 125 | gss_release_name (&min_stat2, &server_name); |
130 | 126 | ||
131 | if (maj_stat != GSS_S_COMPLETE) | 127 | if (maj_stat != GSS_S_COMPLETE) |
132 | { | 128 | { |
133 | display_status ("acquire credentials", maj_stat, min_stat); | 129 | display_status ("acquire credentials", maj_stat, min_stat); |
134 | util_finish (command, RESP_NO, | 130 | util_finish (command, RESP_NO, "GSSAPI authentication not available"); |
135 | "GSSAPI authentication not available"); | ||
136 | return 1; | 131 | return 1; |
137 | } | 132 | } |
138 | 133 | ||
139 | /* Start the dialogue */ | 134 | /* Start the dialogue */ |
140 | 135 | ||
141 | util_send ("+ GO AHEAD\r\n"); | 136 | util_send ("+ GO AHEAD\r\n"); |
142 | 137 | ||
143 | context = GSS_C_NO_CONTEXT; | 138 | context = GSS_C_NO_CONTEXT; |
144 | 139 | ||
145 | for (;;) | 140 | for (;;) |
146 | { | 141 | { |
147 | token_str = imap4d_readline_ex (ifile); | 142 | token_str = imap4d_readline_ex (); |
148 | util_base64_decode (token_str, strlen (token_str), &tmp, &size); | 143 | util_base64_decode (token_str, strlen (token_str), &tmp, &size); |
149 | tokbuf.value = tmp; | 144 | tokbuf.value = tmp; |
150 | tokbuf.length = size; | 145 | tokbuf.length = size; |
151 | free (token_str); | 146 | free (token_str); |
152 | 147 | ||
153 | maj_stat = gss_accept_sec_context (&min_stat, | 148 | maj_stat = gss_accept_sec_context (&min_stat, |
154 | &context, | 149 | &context, |
155 | server_creds, | 150 | server_creds, |
... | @@ -158,9 +153,7 @@ auth_gssapi (struct imap4d_command *command, char **username) | ... | @@ -158,9 +153,7 @@ auth_gssapi (struct imap4d_command *command, char **username) |
158 | &client, | 153 | &client, |
159 | &mech_type, | 154 | &mech_type, |
160 | &outbuf, | 155 | &outbuf, |
161 | &cflags, | 156 | &cflags, NULL, &cred_handle); |
162 | NULL, | ||
163 | &cred_handle); | ||
164 | free (tmp); | 157 | free (tmp); |
165 | if (maj_stat == GSS_S_CONTINUE_NEEDED) | 158 | if (maj_stat == GSS_S_CONTINUE_NEEDED) |
166 | { | 159 | { |
... | @@ -176,12 +169,11 @@ auth_gssapi (struct imap4d_command *command, char **username) | ... | @@ -176,12 +169,11 @@ auth_gssapi (struct imap4d_command *command, char **username) |
176 | else if (maj_stat == GSS_S_COMPLETE) | 169 | else if (maj_stat == GSS_S_COMPLETE) |
177 | break; | 170 | break; |
178 | /* Bail out otherwise */ | 171 | /* Bail out otherwise */ |
179 | 172 | ||
180 | display_status ("accept context", maj_stat, min_stat); | 173 | display_status ("accept context", maj_stat, min_stat); |
181 | maj_stat = gss_delete_sec_context (&min_stat, &context, &outbuf); | 174 | maj_stat = gss_delete_sec_context (&min_stat, &context, &outbuf); |
182 | gss_release_buffer (&min_stat, &outbuf); | 175 | gss_release_buffer (&min_stat, &outbuf); |
183 | util_finish (command, RESP_NO, | 176 | util_finish (command, RESP_NO, "GSSAPI authentication failed"); |
184 | "GSSAPI authentication failed"); | ||
185 | return 1; | 177 | return 1; |
186 | } | 178 | } |
187 | 179 | ||
... | @@ -191,7 +183,7 @@ auth_gssapi (struct imap4d_command *command, char **username) | ... | @@ -191,7 +183,7 @@ auth_gssapi (struct imap4d_command *command, char **username) |
191 | util_send ("+ %*.*s\r\n", size, size, tmp); | 183 | util_send ("+ %*.*s\r\n", size, size, tmp); |
192 | free (tmp); | 184 | free (tmp); |
193 | gss_release_buffer (&min_stat, &outbuf); | 185 | gss_release_buffer (&min_stat, &outbuf); |
194 | token_str = imap4d_readline_ex (ifile); | 186 | token_str = imap4d_readline_ex (); |
195 | free (token_str); | 187 | free (token_str); |
196 | } | 188 | } |
197 | 189 | ||
... | @@ -205,15 +197,15 @@ auth_gssapi (struct imap4d_command *command, char **username) | ... | @@ -205,15 +197,15 @@ auth_gssapi (struct imap4d_command *command, char **username) |
205 | util_send ("+ %*.*s\r\n", size, size, tmp); | 197 | util_send ("+ %*.*s\r\n", size, size, tmp); |
206 | free (tmp); | 198 | free (tmp); |
207 | 199 | ||
208 | token_str = imap4d_readline_ex (ifile); | 200 | token_str = imap4d_readline_ex (); |
209 | util_base64_decode (token_str, strlen (token_str), | 201 | util_base64_decode (token_str, strlen (token_str), |
210 | (unsigned char **)&tokbuf.value, &tokbuf.length); | 202 | (unsigned char **) &tokbuf.value, &tokbuf.length); |
211 | free (token_str); | 203 | free (token_str); |
212 | 204 | ||
213 | gss_unwrap (&min_stat, context, &tokbuf, &outbuf, &cflags, &quality); | 205 | gss_unwrap (&min_stat, context, &tokbuf, &outbuf, &cflags, &quality); |
214 | free (tokbuf.value); | 206 | free (tokbuf.value); |
215 | 207 | ||
216 | sec_level = ntohl (*(OM_uint32*)outbuf.value); | 208 | sec_level = ntohl (*(OM_uint32 *) outbuf.value); |
217 | 209 | ||
218 | /* FIXME: parse sec_level and act accordingly to its settings */ | 210 | /* FIXME: parse sec_level and act accordingly to its settings */ |
219 | mech = sec_level >> 24; | 211 | mech = sec_level >> 24; |
... | @@ -226,25 +218,23 @@ auth_gssapi (struct imap4d_command *command, char **username) | ... | @@ -226,25 +218,23 @@ auth_gssapi (struct imap4d_command *command, char **username) |
226 | maj_stat = gss_delete_sec_context (&min_stat, &context, &outbuf); | 218 | maj_stat = gss_delete_sec_context (&min_stat, &context, &outbuf); |
227 | gss_release_buffer (&min_stat, &outbuf); | 219 | gss_release_buffer (&min_stat, &outbuf); |
228 | util_finish (command, RESP_NO, | 220 | util_finish (command, RESP_NO, |
229 | "GSSAPI authentication failed: unsupported protection mechanism"); | 221 | "GSSAPI authentication failed: unsupported protection mechanism"); |
230 | return 1; | 222 | return 1; |
231 | } | 223 | } |
232 | protection_mech = mech; | 224 | protection_mech = mech; |
233 | client_buffer_size = sec_level & 0x00ffffffff; | 225 | client_buffer_size = sec_level & 0x00ffffffff; |
234 | 226 | ||
235 | *username = strdup ((char*)outbuf.value + 4); | 227 | *username = strdup ((char *) outbuf.value + 4); |
236 | gss_release_buffer (&min_stat, &outbuf); | 228 | gss_release_buffer (&min_stat, &outbuf); |
237 | 229 | ||
238 | maj_stat = gss_display_name(&min_stat, client, | 230 | maj_stat = gss_display_name (&min_stat, client, &client_name, &mech_type); |
239 | &client_name, &mech_type); | ||
240 | if (maj_stat != GSS_S_COMPLETE) | 231 | if (maj_stat != GSS_S_COMPLETE) |
241 | { | 232 | { |
242 | display_status ("get client name", maj_stat, min_stat); | 233 | display_status ("get client name", maj_stat, min_stat); |
243 | maj_stat = gss_delete_sec_context (&min_stat, &context, &outbuf); | 234 | maj_stat = gss_delete_sec_context (&min_stat, &context, &outbuf); |
244 | gss_release_buffer (&min_stat, &outbuf); | 235 | gss_release_buffer (&min_stat, &outbuf); |
245 | free (*username); | 236 | free (*username); |
246 | util_finish (command, RESP_NO, | 237 | util_finish (command, RESP_NO, "GSSAPI authentication failed"); |
247 | "GSSAPI authentication failed"); | ||
248 | return 1; | 238 | return 1; |
249 | } | 239 | } |
250 | 240 | ||
... | @@ -270,8 +260,6 @@ auth_gssapi (struct imap4d_command *command, char **username) | ... | @@ -270,8 +260,6 @@ auth_gssapi (struct imap4d_command *command, char **username) |
270 | gss_release_buffer (&min_stat, &client_name); | 260 | gss_release_buffer (&min_stat, &client_name); |
271 | maj_stat = gss_delete_sec_context (&min_stat, &context, &outbuf); | 261 | maj_stat = gss_delete_sec_context (&min_stat, &context, &outbuf); |
272 | gss_release_buffer (&min_stat, &outbuf); | 262 | gss_release_buffer (&min_stat, &outbuf); |
273 | util_finish (command, RESP_OK, | 263 | util_finish (command, RESP_OK, "GSSAPI authentication successful"); |
274 | "GSSAPI authentication successful"); | ||
275 | return 0; | 264 | return 0; |
276 | } | 265 | } |
277 | ... | ... |
... | @@ -44,7 +44,7 @@ imap4d_bye0 (int reason, struct imap4d_command *command) | ... | @@ -44,7 +44,7 @@ imap4d_bye0 (int reason, struct imap4d_command *command) |
44 | break; | 44 | break; |
45 | 45 | ||
46 | case ERR_SIGNAL: | 46 | case ERR_SIGNAL: |
47 | if (ofile) | 47 | if (util_is_ofile()) |
48 | util_out (RESP_BYE, "Quitting on signal"); | 48 | util_out (RESP_BYE, "Quitting on signal"); |
49 | syslog (LOG_ERR, _("Quitting on signal")); | 49 | syslog (LOG_ERR, _("Quitting on signal")); |
50 | break; | 50 | break; |
... | @@ -78,6 +78,14 @@ imap4d_bye0 (int reason, struct imap4d_command *command) | ... | @@ -78,6 +78,14 @@ imap4d_bye0 (int reason, struct imap4d_command *command) |
78 | 78 | ||
79 | if (status == EXIT_SUCCESS && command) | 79 | if (status == EXIT_SUCCESS && command) |
80 | util_finish (command, RESP_OK, "Completed"); | 80 | util_finish (command, RESP_OK, "Completed"); |
81 | |||
82 | #ifdef WITH_TLS | ||
83 | if (tls_done) | ||
84 | imap4d_deinit_tls_server (); | ||
85 | if (tls_available) | ||
86 | mu_deinit_tls_libs (); | ||
87 | #endif /* WITH_TLS */ | ||
88 | |||
81 | closelog (); | 89 | closelog (); |
82 | exit (status); | 90 | exit (status); |
83 | } | 91 | } | ... | ... |
1 | /* GNU Mailutils -- a suite of utilities for electronic mail | 1 | /* GNU Mailutils -- a suite of utilities for electronic mail |
2 | Copyright (C) 1999, 2001 Free Software Foundation, Inc. | 2 | Copyright (C) 1999, 2001, 2003 Free Software Foundation, Inc. |
3 | 3 | ||
4 | GNU Mailutils is free software; you can redistribute it and/or modify | 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 | 5 | it under the terms of the GNU General Public License as published by |
... | @@ -13,7 +13,7 @@ | ... | @@ -13,7 +13,7 @@ |
13 | 13 | ||
14 | You should have received a copy of the GNU General Public License | 14 | You should have received a copy of the GNU General Public License |
15 | along with GNU Mailutils; if not, write to the Free Software | 15 | along with GNU Mailutils; if not, write to the Free Software |
16 | Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ | 16 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ |
17 | 17 | ||
18 | #include "imap4d.h" | 18 | #include "imap4d.h" |
19 | 19 | ||
... | @@ -28,13 +28,20 @@ int | ... | @@ -28,13 +28,20 @@ int |
28 | imap4d_capability (struct imap4d_command *command, char *arg) | 28 | imap4d_capability (struct imap4d_command *command, char *arg) |
29 | { | 29 | { |
30 | int i; | 30 | int i; |
31 | 31 | ||
32 | (void)arg; | 32 | (void) arg; |
33 | util_send ("* CAPABILITY"); | 33 | util_send ("* CAPABILITY"); |
34 | |||
34 | for (i = 0; capa[i]; i++) | 35 | for (i = 0; capa[i]; i++) |
35 | util_send(" %s", capa[i]); | 36 | util_send (" %s", capa[i]); |
37 | |||
38 | #ifdef WITH_TLS | ||
39 | if (tls_available) | ||
40 | util_send (" STARTTLS"); | ||
41 | #endif /* WITH_TLS */ | ||
42 | |||
36 | imap4d_auth_capability (); | 43 | imap4d_auth_capability (); |
37 | util_send("\r\n"); | 44 | util_send ("\r\n"); |
38 | 45 | ||
39 | return util_finish (command, RESP_OK, "Completed"); | 46 | return util_finish (command, RESP_OK, "Completed"); |
40 | } | 47 | } | ... | ... |
1 | /* GNU Mailutils -- a suite of utilities for electronic mail | 1 | /* GNU Mailutils -- a suite of utilities for electronic mail |
2 | Copyright (C) 1999, 2001 Free Software Foundation, Inc. | 2 | Copyright (C) 1999, 2001, 2003 Free Software Foundation, Inc. |
3 | 3 | ||
4 | GNU Mailutils is free software; you can redistribute it and/or modify | 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 | 5 | it under the terms of the GNU General Public License as published by |
... | @@ -13,7 +13,7 @@ | ... | @@ -13,7 +13,7 @@ |
13 | 13 | ||
14 | You should have received a copy of the GNU General Public License | 14 | You should have received a copy of the GNU General Public License |
15 | along with GNU Mailutils; if not, write to the Free Software | 15 | along with GNU Mailutils; if not, write to the Free Software |
16 | Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ | 16 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ |
17 | 17 | ||
18 | #include "imap4d.h" | 18 | #include "imap4d.h" |
19 | 19 | ||
... | @@ -45,5 +45,8 @@ struct imap4d_command imap4d_command_table [] = | ... | @@ -45,5 +45,8 @@ struct imap4d_command imap4d_command_table [] = |
45 | { "UID", imap4d_uid, STATE_SEL, STATE_NONE, STATE_NONE, NULL }, | 45 | { "UID", imap4d_uid, STATE_SEL, STATE_NONE, STATE_NONE, NULL }, |
46 | { "NAMESPACE", imap4d_namespace, STATE_AUTH | STATE_SEL, STATE_NONE, STATE_NONE, NULL }, | 46 | { "NAMESPACE", imap4d_namespace, STATE_AUTH | STATE_SEL, STATE_NONE, STATE_NONE, NULL }, |
47 | { "X-VERSION", imap4d_version, STATE_AUTH | STATE_SEL, STATE_NONE, STATE_NONE, NULL }, | 47 | { "X-VERSION", imap4d_version, STATE_AUTH | STATE_SEL, STATE_NONE, STATE_NONE, NULL }, |
48 | #ifdef WITH_TLS | ||
49 | { "STARTTLS", imap4d_starttls, STATE_NONAUTH, STATE_NONE, STATE_NONE, NULL }, | ||
50 | #endif /* WITH_TLS */ | ||
48 | { NULL, 0, 0, 0, 0, NULL } | 51 | { NULL, 0, 0, 0, 0, NULL } |
49 | }; | 52 | }; | ... | ... |
1 | /* GNU Mailutils -- a suite of utilities for electronic mail | 1 | /* GNU Mailutils -- a suite of utilities for electronic mail |
2 | Copyright (C) 1999, 2001, 2002 Free Software Foundation, Inc. | 2 | Copyright (C) 1999, 2001, 2002, 2003 Free Software Foundation, Inc. |
3 | 3 | ||
4 | GNU Mailutils is free software; you can redistribute it and/or modify | 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 | 5 | it under the terms of the GNU General Public License as published by |
... | @@ -13,47 +13,50 @@ | ... | @@ -13,47 +13,50 @@ |
13 | 13 | ||
14 | You should have received a copy of the GNU General Public License | 14 | You should have received a copy of the GNU General Public License |
15 | along with GNU Mailutils; if not, write to the Free Software | 15 | along with GNU Mailutils; if not, write to the Free Software |
16 | Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ | 16 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ |
17 | 17 | ||
18 | #include "imap4d.h" | 18 | #include "imap4d.h" |
19 | 19 | ||
20 | FILE *ifile; | ||
21 | FILE *ofile; | ||
22 | mailbox_t mbox; | 20 | mailbox_t mbox; |
23 | char *homedir; | 21 | char *homedir; |
24 | int state = STATE_NONAUTH; | 22 | int state = STATE_NONAUTH; |
25 | int debug_mode = 0; | 23 | int debug_mode = 0; |
26 | struct mu_auth_data *auth_data; | 24 | struct mu_auth_data *auth_data; |
27 | 25 | ||
28 | struct daemon_param daemon_param = { | 26 | struct daemon_param daemon_param = { |
29 | MODE_INTERACTIVE, /* Start in interactive (inetd) mode */ | 27 | MODE_INTERACTIVE, /* Start in interactive (inetd) mode */ |
30 | 20, /* Default maximum number of children */ | 28 | 20, /* Default maximum number of children */ |
31 | 143, /* Standard IMAP4 port */ | 29 | 143, /* Standard IMAP4 port */ |
32 | 1800, /* RFC2060: 30 minutes. */ | 30 | 1800, /* RFC2060: 30 minutes. */ |
33 | 0 /* No transcript by default */ | 31 | 0 /* No transcript by default */ |
34 | }; | 32 | }; |
35 | 33 | ||
34 | #ifdef WITH_TLS | ||
35 | int tls_available; | ||
36 | int tls_done; | ||
37 | #endif /* WITH_TLS */ | ||
38 | |||
36 | /* Number of child processes. */ | 39 | /* Number of child processes. */ |
37 | volatile size_t children; | 40 | volatile size_t children; |
38 | 41 | ||
39 | const char *argp_program_version = "imap4d (" PACKAGE_STRING ")"; | 42 | const char *argp_program_version = "imap4d (" PACKAGE_STRING ")"; |
40 | static char doc[] = N_("GNU imap4d -- the IMAP4D daemon"); | 43 | static char doc[] = N_("GNU imap4d -- the IMAP4D daemon"); |
41 | 44 | ||
42 | static struct argp_option options[] = | 45 | static struct argp_option options[] = { |
43 | { | ||
44 | {"other-namespace", 'O', N_("PATHLIST"), 0, | 46 | {"other-namespace", 'O', N_("PATHLIST"), 0, |
45 | N_("set the `other' namespace"), 0}, | 47 | N_("set the `other' namespace"), 0}, |
46 | {"shared-namespace", 'S', N_("PATHLIST"), 0, | 48 | {"shared-namespace", 'S', N_("PATHLIST"), 0, |
47 | N_("set the `shared' namespace"), 0}, | 49 | N_("set the `shared' namespace"), 0}, |
48 | { NULL, 0, NULL, 0, NULL, 0 } | 50 | {NULL, 0, NULL, 0, NULL, 0} |
49 | }; | 51 | }; |
50 | 52 | ||
51 | static error_t imap4d_parse_opt (int key, char *arg, struct argp_state *state); | 53 | static error_t imap4d_parse_opt (int key, char *arg, |
54 | struct argp_state *state); | ||
52 | 55 | ||
53 | static struct argp argp = { | 56 | static struct argp argp = { |
54 | options, | 57 | options, |
55 | imap4d_parse_opt, | 58 | imap4d_parse_opt, |
56 | NULL, | 59 | NULL, |
57 | doc, | 60 | doc, |
58 | NULL, | 61 | NULL, |
59 | NULL, NULL | 62 | NULL, NULL |
... | @@ -62,6 +65,9 @@ static struct argp argp = { | ... | @@ -62,6 +65,9 @@ static struct argp argp = { |
62 | static const char *imap4d_capa[] = { | 65 | static const char *imap4d_capa[] = { |
63 | "daemon", | 66 | "daemon", |
64 | "auth", | 67 | "auth", |
68 | #ifdef WITH_TLS | ||
69 | "tls", | ||
70 | #endif /* WITH_TLS */ | ||
65 | "common", | 71 | "common", |
66 | "mailbox", | 72 | "mailbox", |
67 | "logging", | 73 | "logging", |
... | @@ -69,10 +75,10 @@ static const char *imap4d_capa[] = { | ... | @@ -69,10 +75,10 @@ static const char *imap4d_capa[] = { |
69 | NULL | 75 | NULL |
70 | }; | 76 | }; |
71 | 77 | ||
72 | static int imap4d_mainloop __P ((int, int)); | 78 | static int imap4d_mainloop __P ((int, int)); |
73 | static void imap4d_daemon_init __P ((void)); | 79 | static void imap4d_daemon_init __P ((void)); |
74 | static void imap4d_daemon __P ((unsigned int, unsigned int)); | 80 | static void imap4d_daemon __P ((unsigned int, unsigned int)); |
75 | static int imap4d_mainloop __P ((int, int)); | 81 | static int imap4d_mainloop __P ((int, int)); |
76 | 82 | ||
77 | static error_t | 83 | static error_t |
78 | imap4d_parse_opt (int key, char *arg, struct argp_state *state) | 84 | imap4d_parse_opt (int key, char *arg, struct argp_state *state) |
... | @@ -82,15 +88,15 @@ imap4d_parse_opt (int key, char *arg, struct argp_state *state) | ... | @@ -82,15 +88,15 @@ imap4d_parse_opt (int key, char *arg, struct argp_state *state) |
82 | case ARGP_KEY_INIT: | 88 | case ARGP_KEY_INIT: |
83 | state->child_inputs[0] = state->input; | 89 | state->child_inputs[0] = state->input; |
84 | break; | 90 | break; |
85 | 91 | ||
86 | case 'O': | 92 | case 'O': |
87 | set_namespace (NS_OTHER, arg); | 93 | set_namespace (NS_OTHER, arg); |
88 | break; | 94 | break; |
89 | 95 | ||
90 | case 'S': | 96 | case 'S': |
91 | set_namespace (NS_SHARED, arg); | 97 | set_namespace (NS_SHARED, arg); |
92 | break; | 98 | break; |
93 | 99 | ||
94 | default: | 100 | default: |
95 | return ARGP_ERR_UNKNOWN; | 101 | return ARGP_ERR_UNKNOWN; |
96 | } | 102 | } |
... | @@ -106,9 +112,12 @@ main (int argc, char **argv) | ... | @@ -106,9 +112,12 @@ main (int argc, char **argv) |
106 | /* Native Language Support */ | 112 | /* Native Language Support */ |
107 | mu_init_nls (); | 113 | mu_init_nls (); |
108 | 114 | ||
109 | state = STATE_NONAUTH; /* Starting state in non-auth. */ | 115 | state = STATE_NONAUTH; /* Starting state in non-auth. */ |
110 | 116 | ||
111 | MU_AUTH_REGISTER_ALL_MODULES(); | 117 | MU_AUTH_REGISTER_ALL_MODULES (); |
118 | #ifdef WITH_TLS | ||
119 | mu_tls_init_argp (); | ||
120 | #endif /* WITH_TLS */ | ||
112 | mu_argp_parse (&argp, &argc, &argv, 0, imap4d_capa, NULL, &daemon_param); | 121 | mu_argp_parse (&argp, &argc, &argv, 0, imap4d_capa, NULL, &daemon_param); |
113 | 122 | ||
114 | #ifdef USE_LIBPAM | 123 | #ifdef USE_LIBPAM |
... | @@ -131,7 +140,7 @@ main (int argc, char **argv) | ... | @@ -131,7 +140,7 @@ main (int argc, char **argv) |
131 | perror (_("Error getting mail group")); | 140 | perror (_("Error getting mail group")); |
132 | exit (1); | 141 | exit (1); |
133 | } | 142 | } |
134 | 143 | ||
135 | if (setgid (gr->gr_gid) == -1) | 144 | if (setgid (gr->gr_gid) == -1) |
136 | { | 145 | { |
137 | perror (_("Error setting mail group")); | 146 | perror (_("Error setting mail group")); |
... | @@ -143,7 +152,7 @@ main (int argc, char **argv) | ... | @@ -143,7 +152,7 @@ main (int argc, char **argv) |
143 | { | 152 | { |
144 | list_t bookie; | 153 | list_t bookie; |
145 | registrar_get_list (&bookie); | 154 | registrar_get_list (&bookie); |
146 | list_append (bookie, mbox_record); | 155 | list_append (bookie, mbox_record); |
147 | list_append (bookie, path_record); | 156 | list_append (bookie, path_record); |
148 | } | 157 | } |
149 | 158 | ||
... | @@ -174,8 +183,15 @@ main (int argc, char **argv) | ... | @@ -174,8 +183,15 @@ main (int argc, char **argv) |
174 | /* Redirect any stdout error from the library to syslog, they | 183 | /* Redirect any stdout error from the library to syslog, they |
175 | should not go to the client. */ | 184 | should not go to the client. */ |
176 | mu_error_set_print (mu_syslog_error_printer); | 185 | mu_error_set_print (mu_syslog_error_printer); |
177 | 186 | ||
178 | umask (S_IROTH | S_IWOTH | S_IXOTH); /* 007 */ | 187 | umask (S_IROTH | S_IWOTH | S_IXOTH); /* 007 */ |
188 | |||
189 | /* Check TLS environment, i.e. cert and key files */ | ||
190 | #ifdef WITH_TLS | ||
191 | tls_available = mu_check_tls_environment (); | ||
192 | if (tls_available) | ||
193 | tls_available = mu_init_tls_libs (); | ||
194 | #endif /* WITH_TLS */ | ||
179 | 195 | ||
180 | /* Actually run the daemon. */ | 196 | /* Actually run the daemon. */ |
181 | if (daemon_param.mode == MODE_DAEMON) | 197 | if (daemon_param.mode == MODE_DAEMON) |
... | @@ -194,18 +210,13 @@ static int | ... | @@ -194,18 +210,13 @@ static int |
194 | imap4d_mainloop (int infile, int outfile) | 210 | imap4d_mainloop (int infile, int outfile) |
195 | { | 211 | { |
196 | char *text; | 212 | char *text; |
197 | 213 | ||
198 | /* Reset hup to exit. */ | 214 | /* Reset hup to exit. */ |
199 | signal (SIGHUP, imap4d_signal); | 215 | signal (SIGHUP, imap4d_signal); |
200 | /* Timeout alarm. */ | 216 | /* Timeout alarm. */ |
201 | signal (SIGALRM, imap4d_signal); | 217 | signal (SIGALRM, imap4d_signal); |
202 | 218 | ||
203 | ifile = fdopen (infile, "r"); | 219 | util_setio (infile, outfile); |
204 | ofile = fdopen (outfile, "w"); | ||
205 | if (!ofile || !ifile) | ||
206 | imap4d_bye (ERR_NO_OFILE); | ||
207 | |||
208 | setvbuf(ofile, NULL, _IOLBF, 0); | ||
209 | 220 | ||
210 | /* log information on the connecting client */ | 221 | /* log information on the connecting client */ |
211 | if (!debug_mode) | 222 | if (!debug_mode) |
... | @@ -214,11 +225,11 @@ imap4d_mainloop (int infile, int outfile) | ... | @@ -214,11 +225,11 @@ imap4d_mainloop (int infile, int outfile) |
214 | int len = sizeof cs; | 225 | int len = sizeof cs; |
215 | 226 | ||
216 | syslog (LOG_INFO, _("Incoming connection opened")); | 227 | syslog (LOG_INFO, _("Incoming connection opened")); |
217 | if (getpeername (infile, (struct sockaddr*)&cs, &len) < 0) | 228 | if (getpeername (infile, (struct sockaddr *) &cs, &len) < 0) |
218 | syslog (LOG_ERR, _("can't obtain IP address of client: %s"), | 229 | syslog (LOG_ERR, _("can't obtain IP address of client: %s"), |
219 | strerror (errno)); | 230 | strerror (errno)); |
220 | else | 231 | else |
221 | syslog (LOG_INFO, _("connect from %s"), inet_ntoa(cs.sin_addr)); | 232 | syslog (LOG_INFO, _("connect from %s"), inet_ntoa (cs.sin_addr)); |
222 | text = "IMAP4rev1"; | 233 | text = "IMAP4rev1"; |
223 | } | 234 | } |
224 | else | 235 | else |
... | @@ -226,23 +237,22 @@ imap4d_mainloop (int infile, int outfile) | ... | @@ -226,23 +237,22 @@ imap4d_mainloop (int infile, int outfile) |
226 | syslog (LOG_INFO, _("Started in debugging mode")); | 237 | syslog (LOG_INFO, _("Started in debugging mode")); |
227 | text = "IMAP4rev1 Debugging mode"; | 238 | text = "IMAP4rev1 Debugging mode"; |
228 | } | 239 | } |
229 | 240 | ||
230 | /* Greetings. */ | 241 | /* Greetings. */ |
231 | util_out (RESP_OK, text); | 242 | util_out (RESP_OK, text); |
232 | fflush (ofile); | 243 | util_flush_output (); |
233 | 244 | ||
234 | while (1) | 245 | while (1) |
235 | { | 246 | { |
236 | char *cmd = imap4d_readline (ifile); | 247 | char *cmd = imap4d_readline (); |
237 | /* check for updates */ | 248 | /* check for updates */ |
238 | imap4d_sync (); | 249 | imap4d_sync (); |
239 | util_do_command (cmd); | 250 | util_do_command (cmd); |
240 | imap4d_sync (); | 251 | imap4d_sync (); |
241 | free (cmd); | 252 | free (cmd); |
242 | fflush (ofile); | 253 | util_flush_output (); |
243 | } | 254 | } |
244 | 255 | ||
245 | closelog (); | ||
246 | return EXIT_SUCCESS; | 256 | return EXIT_SUCCESS; |
247 | } | 257 | } |
248 | 258 | ||
... | @@ -256,7 +266,7 @@ imap4d_daemon_init (void) | ... | @@ -256,7 +266,7 @@ imap4d_daemon_init (void) |
256 | first three one, in, out, err */ | 266 | first three one, in, out, err */ |
257 | if (daemon (0, 0) < 0) | 267 | if (daemon (0, 0) < 0) |
258 | { | 268 | { |
259 | perror(_("fork failed:")); | 269 | perror (_("fork failed:")); |
260 | exit (1); | 270 | exit (1); |
261 | } | 271 | } |
262 | 272 | ||
... | @@ -289,18 +299,18 @@ imap4d_daemon (unsigned int maxchildren, unsigned int port) | ... | @@ -289,18 +299,18 @@ imap4d_daemon (unsigned int maxchildren, unsigned int port) |
289 | listenfd = socket (AF_INET, SOCK_STREAM, 0); | 299 | listenfd = socket (AF_INET, SOCK_STREAM, 0); |
290 | if (listenfd == -1) | 300 | if (listenfd == -1) |
291 | { | 301 | { |
292 | syslog (LOG_ERR, "socket: %s", strerror(errno)); | 302 | syslog (LOG_ERR, "socket: %s", strerror (errno)); |
293 | exit (1); | 303 | exit (1); |
294 | } | 304 | } |
295 | size = 1; /* Use size here to avoid making a new variable. */ | 305 | size = 1; /* Use size here to avoid making a new variable. */ |
296 | setsockopt (listenfd, SOL_SOCKET, SO_REUSEADDR, &size, sizeof(size)); | 306 | setsockopt (listenfd, SOL_SOCKET, SO_REUSEADDR, &size, sizeof (size)); |
297 | size = sizeof (server); | 307 | size = sizeof (server); |
298 | memset (&server, 0, size); | 308 | memset (&server, 0, size); |
299 | server.sin_family = AF_INET; | 309 | server.sin_family = AF_INET; |
300 | server.sin_addr.s_addr = htonl (INADDR_ANY); | 310 | server.sin_addr.s_addr = htonl (INADDR_ANY); |
301 | server.sin_port = htons (port); | 311 | server.sin_port = htons (port); |
302 | 312 | ||
303 | if (bind (listenfd, (struct sockaddr *)&server, size) == -1) | 313 | if (bind (listenfd, (struct sockaddr *) &server, size) == -1) |
304 | { | 314 | { |
305 | syslog (LOG_ERR, "bind: %s", strerror (errno)); | 315 | syslog (LOG_ERR, "bind: %s", strerror (errno)); |
306 | exit (1); | 316 | exit (1); |
... | @@ -315,38 +325,37 @@ imap4d_daemon (unsigned int maxchildren, unsigned int port) | ... | @@ -315,38 +325,37 @@ imap4d_daemon (unsigned int maxchildren, unsigned int port) |
315 | for (;;) | 325 | for (;;) |
316 | { | 326 | { |
317 | if (children > maxchildren) | 327 | if (children > maxchildren) |
318 | { | 328 | { |
319 | syslog (LOG_ERR, _("too many children (%lu)"), | 329 | syslog (LOG_ERR, _("too many children (%lu)"), |
320 | (unsigned long) children); | 330 | (unsigned long) children); |
321 | pause (); | 331 | pause (); |
322 | continue; | 332 | continue; |
323 | } | 333 | } |
324 | connfd = accept (listenfd, (struct sockaddr *)&client, | 334 | connfd = accept (listenfd, (struct sockaddr *) &client, |
325 | (socklen_t*) &size); | 335 | (socklen_t *) & size); |
326 | if (connfd == -1) | 336 | if (connfd == -1) |
327 | { | 337 | { |
328 | if (errno == EINTR) | 338 | if (errno == EINTR) |
329 | continue; | 339 | continue; |
330 | syslog (LOG_ERR, "accept: %s", strerror (errno)); | 340 | syslog (LOG_ERR, "accept: %s", strerror (errno)); |
331 | exit (1); | 341 | exit (1); |
332 | } | 342 | } |
333 | 343 | ||
334 | pid = fork (); | 344 | pid = fork (); |
335 | if (pid == -1) | 345 | if (pid == -1) |
336 | syslog(LOG_ERR, "fork: %s", strerror (errno)); | 346 | syslog (LOG_ERR, "fork: %s", strerror (errno)); |
337 | else if (pid == 0) /* Child. */ | 347 | else if (pid == 0) /* Child. */ |
338 | { | 348 | { |
339 | int status; | 349 | int status; |
340 | close (listenfd); | 350 | close (listenfd); |
341 | status = imap4d_mainloop (connfd, connfd); | 351 | status = imap4d_mainloop (connfd, connfd); |
342 | closelog (); | 352 | closelog (); |
343 | exit (status); | 353 | exit (status); |
344 | } | 354 | } |
345 | else | 355 | else |
346 | { | 356 | { |
347 | ++children; | 357 | ++children; |
348 | } | 358 | } |
349 | close (connfd); | 359 | close (connfd); |
350 | } | 360 | } |
351 | } | 361 | } |
352 | ... | ... |
1 | /* GNU Mailutils -- a suite of utilities for electronic mail | 1 | /* GNU Mailutils -- a suite of utilities for electronic mail |
2 | Copyright (C) 1999, 2001, 2002 Free Software Foundation, Inc. | 2 | Copyright (C) 1999, 2001, 2002, 2003 Free Software Foundation, Inc. |
3 | 3 | ||
4 | GNU Mailutils is free software; you can redistribute it and/or modify | 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 | 5 | it under the terms of the GNU General Public License as published by |
... | @@ -13,7 +13,7 @@ | ... | @@ -13,7 +13,7 @@ |
13 | 13 | ||
14 | You should have received a copy of the GNU General Public License | 14 | You should have received a copy of the GNU General Public License |
15 | along with GNU Mailutils; if not, write to the Free Software | 15 | along with GNU Mailutils; if not, write to the Free Software |
16 | Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ | 16 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ |
17 | 17 | ||
18 | #ifndef _IMAP4D_H | 18 | #ifndef _IMAP4D_H |
19 | #define _IMAP4D_H 1 | 19 | #define _IMAP4D_H 1 |
... | @@ -87,6 +87,7 @@ | ... | @@ -87,6 +87,7 @@ |
87 | #include <mailutils/stream.h> | 87 | #include <mailutils/stream.h> |
88 | #include <mailutils/mu_auth.h> | 88 | #include <mailutils/mu_auth.h> |
89 | #include <mailutils/url.h> | 89 | #include <mailutils/url.h> |
90 | #include <mailutils/tls.h> | ||
90 | #include <mailutils/nls.h> | 91 | #include <mailutils/nls.h> |
91 | 92 | ||
92 | #ifdef __cplusplus | 93 | #ifdef __cplusplus |
... | @@ -126,7 +127,8 @@ struct imap4d_command | ... | @@ -126,7 +127,8 @@ struct imap4d_command |
126 | #define ERR_NO_OFILE 2 | 127 | #define ERR_NO_OFILE 2 |
127 | #define ERR_TIMEOUT 3 | 128 | #define ERR_TIMEOUT 3 |
128 | #define ERR_SIGNAL 4 | 129 | #define ERR_SIGNAL 4 |
129 | 130 | #define ERR_TLS 5 | |
131 | |||
130 | /* Namespace numbers */ | 132 | /* Namespace numbers */ |
131 | #define NS_PRIVATE 0 | 133 | #define NS_PRIVATE 0 |
132 | #define NS_OTHER 1 | 134 | #define NS_OTHER 1 |
... | @@ -139,8 +141,6 @@ struct imap4d_command | ... | @@ -139,8 +141,6 @@ struct imap4d_command |
139 | #define WCARD_RECURSE_MATCH 2 | 141 | #define WCARD_RECURSE_MATCH 2 |
140 | 142 | ||
141 | extern struct imap4d_command imap4d_command_table[]; | 143 | extern struct imap4d_command imap4d_command_table[]; |
142 | extern FILE *ifile; | ||
143 | extern FILE *ofile; | ||
144 | extern mailbox_t mbox; | 144 | extern mailbox_t mbox; |
145 | extern char *homedir; | 145 | extern char *homedir; |
146 | extern char *rootdir; | 146 | extern char *rootdir; |
... | @@ -149,7 +149,12 @@ extern volatile size_t children; | ... | @@ -149,7 +149,12 @@ extern volatile size_t children; |
149 | extern int is_virtual; | 149 | extern int is_virtual; |
150 | extern struct daemon_param daemon_param; | 150 | extern struct daemon_param daemon_param; |
151 | extern struct mu_auth_data *auth_data; | 151 | extern struct mu_auth_data *auth_data; |
152 | 152 | ||
153 | #ifdef WITH_TLS | ||
154 | extern int tls_available; | ||
155 | extern int tls_done; | ||
156 | #endif /* WITH_TLS */ | ||
157 | |||
153 | #ifndef HAVE_STRTOK_R | 158 | #ifndef HAVE_STRTOK_R |
154 | extern char *strtok_r __P((char *s, const char *delim, char **save_ptr)); | 159 | extern char *strtok_r __P((char *s, const char *delim, char **save_ptr)); |
155 | #endif | 160 | #endif |
... | @@ -181,6 +186,9 @@ extern int imap4d_search0 __P((char *arg, int isuid, char *replybuf, size_t rep | ... | @@ -181,6 +186,9 @@ extern int imap4d_search0 __P((char *arg, int isuid, char *replybuf, size_t rep |
181 | extern int imap4d_select __P ((struct imap4d_command *, char *)); | 186 | extern int imap4d_select __P ((struct imap4d_command *, char *)); |
182 | extern int imap4d_select0 __P ((struct imap4d_command *, char *, int)); | 187 | extern int imap4d_select0 __P ((struct imap4d_command *, char *, int)); |
183 | extern int imap4d_select_status __P((void)); | 188 | extern int imap4d_select_status __P((void)); |
189 | #ifdef WITH_TLS | ||
190 | extern int imap4d_starttls __P ((struct imap4d_command *, char *)); | ||
191 | #endif /* WITH_TLS */ | ||
184 | extern int imap4d_status __P ((struct imap4d_command *, char *)); | 192 | extern int imap4d_status __P ((struct imap4d_command *, char *)); |
185 | extern int imap4d_store __P ((struct imap4d_command *, char *)); | 193 | extern int imap4d_store __P ((struct imap4d_command *, char *)); |
186 | extern int imap4d_store0 __P ((char *, int, char *, size_t)); | 194 | extern int imap4d_store0 __P ((char *, int, char *, size_t)); |
... | @@ -220,8 +228,8 @@ extern int util_start __P ((char *)); | ... | @@ -220,8 +228,8 @@ extern int util_start __P ((char *)); |
220 | extern int util_finish __P ((struct imap4d_command *, int, const char *, ...)); | 228 | extern int util_finish __P ((struct imap4d_command *, int, const char *, ...)); |
221 | extern int util_getstate __P ((void)); | 229 | extern int util_getstate __P ((void)); |
222 | extern int util_do_command __P ((char *)); | 230 | extern int util_do_command __P ((char *)); |
223 | extern char *imap4d_readline __P ((FILE*)); | 231 | extern char *imap4d_readline __P ((void)); |
224 | extern char *imap4d_readline_ex __P ((FILE*)); | 232 | extern char *imap4d_readline_ex __P ((void)); |
225 | extern char *util_getword __P ((char *, char **)); | 233 | extern char *util_getword __P ((char *, char **)); |
226 | extern char *util_getitem __P ((char *, const char *, char **)); | 234 | extern char *util_getitem __P ((char *, const char *, char **)); |
227 | extern int util_token __P ((char *, size_t, char **)); | 235 | extern int util_token __P ((char *, size_t, char **)); |
... | @@ -256,7 +264,15 @@ int util_attribute_to_type __P((const char *item, int *type)); | ... | @@ -256,7 +264,15 @@ int util_attribute_to_type __P((const char *item, int *type)); |
256 | int util_type_to_attribute __P((int type, char **attr_str)); | 264 | int util_type_to_attribute __P((int type, char **attr_str)); |
257 | int util_attribute_matches_flag __P((attribute_t attr, const char *item)); | 265 | int util_attribute_matches_flag __P((attribute_t attr, const char *item)); |
258 | int util_uidvalidity __P((mailbox_t smbox, unsigned long *uidvp)); | 266 | int util_uidvalidity __P((mailbox_t smbox, unsigned long *uidvp)); |
259 | 267 | ||
268 | void util_setio __P((int, int)); | ||
269 | void util_flush_output __P((void)); | ||
270 | FILE *util_is_ofile __P((void)); | ||
271 | #ifdef WITH_TLS | ||
272 | int imap4d_init_tls_server __P((void)); | ||
273 | void imap4d_deinit_tls_server __P((void)); | ||
274 | #endif /* WITH_TLS */ | ||
275 | |||
260 | #ifdef __cplusplus | 276 | #ifdef __cplusplus |
261 | } | 277 | } |
262 | #endif | 278 | #endif | ... | ... |
... | @@ -41,7 +41,7 @@ imap4d_signal (int signo) | ... | @@ -41,7 +41,7 @@ imap4d_signal (int signo) |
41 | { | 41 | { |
42 | syslog (LOG_CRIT, _("got signal %s"), strsignal (signo)); | 42 | syslog (LOG_CRIT, _("got signal %s"), strsignal (signo)); |
43 | /* Master process. */ | 43 | /* Master process. */ |
44 | if (!ofile) | 44 | if (!(util_is_ofile())) |
45 | { | 45 | { |
46 | syslog (LOG_CRIT, _("MASTER: exiting on signal")); | 46 | syslog (LOG_CRIT, _("MASTER: exiting on signal")); |
47 | exit (1); /* abort(); */ | 47 | exit (1); /* abort(); */ | ... | ... |
imap4d/starttls.c
0 → 100644
1 | /* GNU Mailutils -- a suite of utilities for electronic mail | ||
2 | Copyright (C) 2003 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 2, 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 A 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; if not, write to the Free Software | ||
16 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ | ||
17 | |||
18 | #include "imap4d.h" | ||
19 | |||
20 | #ifdef WITH_TLS | ||
21 | |||
22 | int | ||
23 | imap4d_starttls (struct imap4d_command *command, char *arg) | ||
24 | { | ||
25 | int status; | ||
26 | char *sp = NULL; | ||
27 | |||
28 | if (!tls_available || tls_done) | ||
29 | return util_finish (command, RESP_BAD, "Invalid command"); | ||
30 | |||
31 | if (util_getword (arg, &sp)) | ||
32 | return util_finish (command, RESP_BAD, "Too many args"); | ||
33 | |||
34 | status = util_finish (command, RESP_OK, "Begin TLS negotiation"); | ||
35 | tls_done = imap4d_init_tls_server (); | ||
36 | |||
37 | return status; | ||
38 | } | ||
39 | |||
40 | #endif /* WITH_TLS */ | ||
41 | |||
42 | /* EOF */ |
This diff is collapsed.
Click to expand it.
-
Please register or sign in to post a comment