annotate src/imap-login/client.c @ 9266:cd29b745c8dd HEAD

configure: clock_gettime()'s -lrt adding dropped everything else from $LIBS.
author Timo Sirainen <tss@iki.fi>
date Mon, 27 Jul 2009 06:32:42 -0400
parents 754234248510
children ab32d7e2c0d6
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
8590
b9faf4db2a9f Updated copyright notices to include year 2009.
Timo Sirainen <tss@iki.fi>
parents: 8583
diff changeset
1 /* Copyright (c) 2002-2009 Dovecot authors, see the included COPYING file */
1049
c41787e8c3f4 Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
2
c41787e8c3f4 Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
3 #include "common.h"
c41787e8c3f4 Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
4 #include "buffer.h"
c41787e8c3f4 Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
5 #include "ioloop.h"
c41787e8c3f4 Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
6 #include "istream.h"
c41787e8c3f4 Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
7 #include "ostream.h"
c41787e8c3f4 Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
8 #include "process-title.h"
c41787e8c3f4 Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
9 #include "safe-memset.h"
2674
857f5f7b512b Added login_greeting and login_greeting_capability settings.
Timo Sirainen <tss@iki.fi>
parents: 2421
diff changeset
10 #include "str.h"
1049
c41787e8c3f4 Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
11 #include "strescape.h"
c41787e8c3f4 Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
12 #include "imap-parser.h"
7917
ca2ff54ee9b4 Added support for IMAP ID extension.
Timo Sirainen <tss@iki.fi>
parents: 7438
diff changeset
13 #include "imap-id.h"
1049
c41787e8c3f4 Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
14 #include "client.h"
c41787e8c3f4 Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
15 #include "client-authenticate.h"
1702
43815588dd6b Moved client side code for auth process handling to lib-auth. Some other login process cleanups.
Timo Sirainen <tss@iki.fi>
parents: 1591
diff changeset
16 #include "auth-client.h"
1049
c41787e8c3f4 Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
17 #include "ssl-proxy.h"
2768
d344be0bb70f Added IMAP and POP3 proxying support.
Timo Sirainen <tss@iki.fi>
parents: 2766
diff changeset
18 #include "imap-proxy.h"
1049
c41787e8c3f4 Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
19
7917
ca2ff54ee9b4 Added support for IMAP ID extension.
Timo Sirainen <tss@iki.fi>
parents: 7438
diff changeset
20 #include <stdlib.h>
ca2ff54ee9b4 Added support for IMAP ID extension.
Timo Sirainen <tss@iki.fi>
parents: 7438
diff changeset
21
2421
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2097
diff changeset
22 /* max. size of output buffer. if it gets full, the client is disconnected.
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2097
diff changeset
23 SASL authentication gives the largest output. */
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2097
diff changeset
24 #define MAX_OUTBUF_SIZE 4096
1079
3aece07f3a1b STARTTLS commands crashed. imap-login STARTTLS also ignored next command.
Timo Sirainen <tss@iki.fi>
parents: 1049
diff changeset
25
1591
6eca99b727a0 IMAP parser memory limits are now enforced by bytes per line rather than
Timo Sirainen <tss@iki.fi>
parents: 1575
diff changeset
26 /* maximum length for IMAP command line. */
6eca99b727a0 IMAP parser memory limits are now enforced by bytes per line rather than
Timo Sirainen <tss@iki.fi>
parents: 1575
diff changeset
27 #define MAX_IMAP_LINE 8192
1049
c41787e8c3f4 Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
28
c41787e8c3f4 Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
29 /* Disconnect client when it sends too many bad commands */
c41787e8c3f4 Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
30 #define CLIENT_MAX_BAD_COMMANDS 10
c41787e8c3f4 Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
31
c41787e8c3f4 Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
32 /* When max. number of simultaneous connections is reached, few of the
7102
75f4e7ce8151 Minor cleanups
Timo Sirainen <tss@iki.fi>
parents: 7101
diff changeset
33 oldest connections are disconnected. Since we have to go through all of the
75f4e7ce8151 Minor cleanups
Timo Sirainen <tss@iki.fi>
parents: 7101
diff changeset
34 clients, it's faster if we disconnect multiple clients. */
1049
c41787e8c3f4 Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
35 #define CLIENT_DESTROY_OLDEST_COUNT 16
c41787e8c3f4 Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
36
7099
3f5b7bebfd82 Use separate per-client timeouts instead of going through all clients in one
Timo Sirainen <tss@iki.fi>
parents: 7086
diff changeset
37 /* If we've been waiting auth server to respond for over this many milliseconds,
6625
f40f4e1a0a3c If we've been waiting auth server to respond for over 30 seconds, send a "OK
Timo Sirainen <tss@iki.fi>
parents: 6475
diff changeset
38 send a "waiting" message. */
7114
9bbe74f6f2a9 "Waiting for auth process" was supposed to come after 30s, not 30ms.
Timo Sirainen <tss@iki.fi>
parents: 7102
diff changeset
39 #define AUTH_WAITING_TIMEOUT_MSECS (30*1000)
6625
f40f4e1a0a3c If we've been waiting auth server to respond for over 30 seconds, send a "OK
Timo Sirainen <tss@iki.fi>
parents: 6475
diff changeset
40
9155
1c91fa0d804b login client idle timeout should be larger than auth request timeout, not vice versa.
Timo Sirainen <tss@iki.fi>
parents: 9142
diff changeset
41 #if CLIENT_LOGIN_IDLE_TIMEOUT_MSECS < AUTH_REQUEST_TIMEOUT*1000
1c91fa0d804b login client idle timeout should be larger than auth request timeout, not vice versa.
Timo Sirainen <tss@iki.fi>
parents: 9142
diff changeset
42 # error client idle timeout must be larger than authentication timeout
1083
f6ec28683512 auth: kill login connection if it leaves requests hanging too long.
Timo Sirainen <tss@iki.fi>
parents: 1079
diff changeset
43 #endif
f6ec28683512 auth: kill login connection if it leaves requests hanging too long.
Timo Sirainen <tss@iki.fi>
parents: 1079
diff changeset
44
7099
3f5b7bebfd82 Use separate per-client timeouts instead of going through all clients in one
Timo Sirainen <tss@iki.fi>
parents: 7086
diff changeset
45 #define AUTH_WAITING_MSG \
3f5b7bebfd82 Use separate per-client timeouts instead of going through all clients in one
Timo Sirainen <tss@iki.fi>
parents: 7086
diff changeset
46 "* OK Waiting for authentication process to respond.."
3f5b7bebfd82 Use separate per-client timeouts instead of going through all clients in one
Timo Sirainen <tss@iki.fi>
parents: 7086
diff changeset
47
3384
3b75956d20c4 Added configurable logging for login process. Added configurable pop3 logout
Timo Sirainen <tss@iki.fi>
parents: 3360
diff changeset
48 const char *login_protocol = "IMAP";
4197
c3ded5b815aa If we have plugins set and imap_capability unset, figure out the IMAP
Timo Sirainen <tss@iki.fi>
parents: 4124
diff changeset
49 const char *capability_string = CAPABILITY_STRING;
3384
3b75956d20c4 Added configurable logging for login process. Added configurable pop3 logout
Timo Sirainen <tss@iki.fi>
parents: 3360
diff changeset
50
1049
c41787e8c3f4 Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
51 static void client_set_title(struct imap_client *client)
c41787e8c3f4 Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
52 {
1486
2f5b3da28dd9 s/host/addr/ in variables
Timo Sirainen <tss@iki.fi>
parents: 1485
diff changeset
53 const char *addr;
1049
c41787e8c3f4 Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
54
c41787e8c3f4 Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
55 if (!verbose_proctitle || !process_per_connection)
c41787e8c3f4 Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
56 return;
c41787e8c3f4 Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
57
1486
2f5b3da28dd9 s/host/addr/ in variables
Timo Sirainen <tss@iki.fi>
parents: 1485
diff changeset
58 addr = net_ip2addr(&client->common.ip);
2f5b3da28dd9 s/host/addr/ in variables
Timo Sirainen <tss@iki.fi>
parents: 1485
diff changeset
59 if (addr == NULL)
2f5b3da28dd9 s/host/addr/ in variables
Timo Sirainen <tss@iki.fi>
parents: 1485
diff changeset
60 addr = "??";
1049
c41787e8c3f4 Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
61
2733
9b9d9c164a31 Login process cleanups. Share more authentication code between pop3/imap.
Timo Sirainen <tss@iki.fi>
parents: 2691
diff changeset
62 process_title_set(t_strdup_printf(client->common.tls ?
9b9d9c164a31 Login process cleanups. Share more authentication code between pop3/imap.
Timo Sirainen <tss@iki.fi>
parents: 2691
diff changeset
63 "[%s TLS]" : "[%s]", addr));
1049
c41787e8c3f4 Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
64 }
c41787e8c3f4 Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
65
1079
3aece07f3a1b STARTTLS commands crashed. imap-login STARTTLS also ignored next command.
Timo Sirainen <tss@iki.fi>
parents: 1049
diff changeset
66 static void client_open_streams(struct imap_client *client, int fd)
3aece07f3a1b STARTTLS commands crashed. imap-login STARTTLS also ignored next command.
Timo Sirainen <tss@iki.fi>
parents: 1049
diff changeset
67 {
7927
2351a81ce699 If commands are pipelined after the login command, pass them to the
Timo Sirainen <tss@iki.fi>
parents: 7923
diff changeset
68 client->common.input =
2351a81ce699 If commands are pipelined after the login command, pass them to the
Timo Sirainen <tss@iki.fi>
parents: 7923
diff changeset
69 i_stream_create_fd(fd, LOGIN_MAX_INBUF_SIZE, FALSE);
6161
c62f7ee79446 Split o_stream_create_file() to _create_fd() and _create_fd_file().
Timo Sirainen <tss@iki.fi>
parents: 6153
diff changeset
70 client->output = o_stream_create_fd(fd, MAX_OUTBUF_SIZE, FALSE);
7927
2351a81ce699 If commands are pipelined after the login command, pass them to the
Timo Sirainen <tss@iki.fi>
parents: 7923
diff changeset
71 client->parser = imap_parser_create(client->common.input,
2351a81ce699 If commands are pipelined after the login command, pass them to the
Timo Sirainen <tss@iki.fi>
parents: 7923
diff changeset
72 client->output, MAX_IMAP_LINE);
1079
3aece07f3a1b STARTTLS commands crashed. imap-login STARTTLS also ignored next command.
Timo Sirainen <tss@iki.fi>
parents: 1049
diff changeset
73 }
3aece07f3a1b STARTTLS commands crashed. imap-login STARTTLS also ignored next command.
Timo Sirainen <tss@iki.fi>
parents: 1049
diff changeset
74
3aece07f3a1b STARTTLS commands crashed. imap-login STARTTLS also ignored next command.
Timo Sirainen <tss@iki.fi>
parents: 1049
diff changeset
75 /* Skip incoming data until newline is found,
3aece07f3a1b STARTTLS commands crashed. imap-login STARTTLS also ignored next command.
Timo Sirainen <tss@iki.fi>
parents: 1049
diff changeset
76 returns TRUE if newline was found. */
3863
55df57c028d4 Added "bool" type and changed all ints that were used as booleans to bool.
Timo Sirainen <tss@iki.fi>
parents: 3706
diff changeset
77 bool client_skip_line(struct imap_client *client)
1079
3aece07f3a1b STARTTLS commands crashed. imap-login STARTTLS also ignored next command.
Timo Sirainen <tss@iki.fi>
parents: 1049
diff changeset
78 {
3aece07f3a1b STARTTLS commands crashed. imap-login STARTTLS also ignored next command.
Timo Sirainen <tss@iki.fi>
parents: 1049
diff changeset
79 const unsigned char *data;
3aece07f3a1b STARTTLS commands crashed. imap-login STARTTLS also ignored next command.
Timo Sirainen <tss@iki.fi>
parents: 1049
diff changeset
80 size_t i, data_size;
3aece07f3a1b STARTTLS commands crashed. imap-login STARTTLS also ignored next command.
Timo Sirainen <tss@iki.fi>
parents: 1049
diff changeset
81
7927
2351a81ce699 If commands are pipelined after the login command, pass them to the
Timo Sirainen <tss@iki.fi>
parents: 7923
diff changeset
82 data = i_stream_get_data(client->common.input, &data_size);
1079
3aece07f3a1b STARTTLS commands crashed. imap-login STARTTLS also ignored next command.
Timo Sirainen <tss@iki.fi>
parents: 1049
diff changeset
83
3aece07f3a1b STARTTLS commands crashed. imap-login STARTTLS also ignored next command.
Timo Sirainen <tss@iki.fi>
parents: 1049
diff changeset
84 for (i = 0; i < data_size; i++) {
3aece07f3a1b STARTTLS commands crashed. imap-login STARTTLS also ignored next command.
Timo Sirainen <tss@iki.fi>
parents: 1049
diff changeset
85 if (data[i] == '\n') {
7927
2351a81ce699 If commands are pipelined after the login command, pass them to the
Timo Sirainen <tss@iki.fi>
parents: 7923
diff changeset
86 i_stream_skip(client->common.input, i+1);
1079
3aece07f3a1b STARTTLS commands crashed. imap-login STARTTLS also ignored next command.
Timo Sirainen <tss@iki.fi>
parents: 1049
diff changeset
87 return TRUE;
3aece07f3a1b STARTTLS commands crashed. imap-login STARTTLS also ignored next command.
Timo Sirainen <tss@iki.fi>
parents: 1049
diff changeset
88 }
3aece07f3a1b STARTTLS commands crashed. imap-login STARTTLS also ignored next command.
Timo Sirainen <tss@iki.fi>
parents: 1049
diff changeset
89 }
3aece07f3a1b STARTTLS commands crashed. imap-login STARTTLS also ignored next command.
Timo Sirainen <tss@iki.fi>
parents: 1049
diff changeset
90
3aece07f3a1b STARTTLS commands crashed. imap-login STARTTLS also ignored next command.
Timo Sirainen <tss@iki.fi>
parents: 1049
diff changeset
91 return FALSE;
3aece07f3a1b STARTTLS commands crashed. imap-login STARTTLS also ignored next command.
Timo Sirainen <tss@iki.fi>
parents: 1049
diff changeset
92 }
3aece07f3a1b STARTTLS commands crashed. imap-login STARTTLS also ignored next command.
Timo Sirainen <tss@iki.fi>
parents: 1049
diff changeset
93
7922
4b4d2a4423ec Removed login_greeting_capability setting. Instead now a minimal pre-login
Timo Sirainen <tss@iki.fi>
parents: 7921
diff changeset
94 static const char *get_capability(struct imap_client *client, bool full)
1049
c41787e8c3f4 Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
95 {
2674
857f5f7b512b Added login_greeting and login_greeting_capability settings.
Timo Sirainen <tss@iki.fi>
parents: 2421
diff changeset
96 const char *auths;
1049
c41787e8c3f4 Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
97
2733
9b9d9c164a31 Login process cleanups. Share more authentication code between pop3/imap.
Timo Sirainen <tss@iki.fi>
parents: 2691
diff changeset
98 auths = client_authenticate_get_capabilities(client->common.secured);
7922
4b4d2a4423ec Removed login_greeting_capability setting. Instead now a minimal pre-login
Timo Sirainen <tss@iki.fi>
parents: 7921
diff changeset
99 return t_strconcat(full ? capability_string : CAPABILITY_BANNER_STRING,
2733
9b9d9c164a31 Login process cleanups. Share more authentication code between pop3/imap.
Timo Sirainen <tss@iki.fi>
parents: 2691
diff changeset
100 (ssl_initialized && !client->common.tls) ?
9b9d9c164a31 Login process cleanups. Share more authentication code between pop3/imap.
Timo Sirainen <tss@iki.fi>
parents: 2691
diff changeset
101 " STARTTLS" : "",
9b9d9c164a31 Login process cleanups. Share more authentication code between pop3/imap.
Timo Sirainen <tss@iki.fi>
parents: 2691
diff changeset
102 disable_plaintext_auth && !client->common.secured ?
2674
857f5f7b512b Added login_greeting and login_greeting_capability settings.
Timo Sirainen <tss@iki.fi>
parents: 2421
diff changeset
103 " LOGINDISABLED" : "", auths, NULL);
857f5f7b512b Added login_greeting and login_greeting_capability settings.
Timo Sirainen <tss@iki.fi>
parents: 2421
diff changeset
104 }
857f5f7b512b Added login_greeting and login_greeting_capability settings.
Timo Sirainen <tss@iki.fi>
parents: 2421
diff changeset
105
857f5f7b512b Added login_greeting and login_greeting_capability settings.
Timo Sirainen <tss@iki.fi>
parents: 2421
diff changeset
106 static int cmd_capability(struct imap_client *client)
857f5f7b512b Added login_greeting and login_greeting_capability settings.
Timo Sirainen <tss@iki.fi>
parents: 2421
diff changeset
107 {
9142
5ee5def4f0ff imap-login: Using CAPABILITY command after STARTTLS shouldn't trigger CAPABILITY pushing workaround.
Timo Sirainen <tss@iki.fi>
parents: 8985
diff changeset
108 /* Client is required to send CAPABILITY after STARTTLS, so the
5ee5def4f0ff imap-login: Using CAPABILITY command after STARTTLS shouldn't trigger CAPABILITY pushing workaround.
Timo Sirainen <tss@iki.fi>
parents: 8985
diff changeset
109 capability resp-code workaround checks only pre-STARTTLS
5ee5def4f0ff imap-login: Using CAPABILITY command after STARTTLS shouldn't trigger CAPABILITY pushing workaround.
Timo Sirainen <tss@iki.fi>
parents: 8985
diff changeset
110 CAPABILITY commands. */
5ee5def4f0ff imap-login: Using CAPABILITY command after STARTTLS shouldn't trigger CAPABILITY pushing workaround.
Timo Sirainen <tss@iki.fi>
parents: 8985
diff changeset
111 if (!client->starttls)
5ee5def4f0ff imap-login: Using CAPABILITY command after STARTTLS shouldn't trigger CAPABILITY pushing workaround.
Timo Sirainen <tss@iki.fi>
parents: 8985
diff changeset
112 client->client_ignores_capability_resp_code = TRUE;
7922
4b4d2a4423ec Removed login_greeting_capability setting. Instead now a minimal pre-login
Timo Sirainen <tss@iki.fi>
parents: 7921
diff changeset
113 client_send_line(client, t_strconcat(
4b4d2a4423ec Removed login_greeting_capability setting. Instead now a minimal pre-login
Timo Sirainen <tss@iki.fi>
parents: 7921
diff changeset
114 "* CAPABILITY ", get_capability(client, TRUE), NULL));
1049
c41787e8c3f4 Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
115 client_send_tagline(client, "OK Capability completed.");
3863
55df57c028d4 Added "bool" type and changed all ints that were used as booleans to bool.
Timo Sirainen <tss@iki.fi>
parents: 3706
diff changeset
116 return 1;
1049
c41787e8c3f4 Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
117 }
c41787e8c3f4 Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
118
2421
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2097
diff changeset
119 static void client_start_tls(struct imap_client *client)
1049
c41787e8c3f4 Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
120 {
c41787e8c3f4 Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
121 int fd_ssl;
c41787e8c3f4 Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
122
4560
507088c0d511 Fixes for handling near-full connection queues.
Timo Sirainen <tss@iki.fi>
parents: 4538
diff changeset
123 client_ref(client);
507088c0d511 Fixes for handling near-full connection queues.
Timo Sirainen <tss@iki.fi>
parents: 4538
diff changeset
124 connection_queue_add(1);
6153
fc7c4af3e870 If STARTTLS failed because max. number of connections for process was
Timo Sirainen <tss@iki.fi>
parents: 6142
diff changeset
125 if (!client_unref(client) || client->destroyed)
4560
507088c0d511 Fixes for handling near-full connection queues.
Timo Sirainen <tss@iki.fi>
parents: 4538
diff changeset
126 return;
507088c0d511 Fixes for handling near-full connection queues.
Timo Sirainen <tss@iki.fi>
parents: 4538
diff changeset
127
2421
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2097
diff changeset
128 fd_ssl = ssl_proxy_new(client->common.fd, &client->common.ip,
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2097
diff changeset
129 &client->common.proxy);
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2097
diff changeset
130 if (fd_ssl == -1) {
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2097
diff changeset
131 client_send_line(client, "* BYE TLS initialization failed.");
4538
9d9e72374164 Fixes to login process handling, especially with
Timo Sirainen <tss@iki.fi>
parents: 4467
diff changeset
132 client_destroy(client,
9d9e72374164 Fixes to login process handling, especially with
Timo Sirainen <tss@iki.fi>
parents: 4467
diff changeset
133 "Disconnected: TLS initialization failed.");
2421
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2097
diff changeset
134 return;
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2097
diff changeset
135 }
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2097
diff changeset
136
9142
5ee5def4f0ff imap-login: Using CAPABILITY command after STARTTLS shouldn't trigger CAPABILITY pushing workaround.
Timo Sirainen <tss@iki.fi>
parents: 8985
diff changeset
137 client->starttls = TRUE;
2733
9b9d9c164a31 Login process cleanups. Share more authentication code between pop3/imap.
Timo Sirainen <tss@iki.fi>
parents: 2691
diff changeset
138 client->common.tls = TRUE;
9b9d9c164a31 Login process cleanups. Share more authentication code between pop3/imap.
Timo Sirainen <tss@iki.fi>
parents: 2691
diff changeset
139 client->common.secured = TRUE;
2421
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2097
diff changeset
140 client_set_title(client);
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2097
diff changeset
141
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2097
diff changeset
142 client->common.fd = fd_ssl;
7927
2351a81ce699 If commands are pipelined after the login command, pass them to the
Timo Sirainen <tss@iki.fi>
parents: 7923
diff changeset
143 i_stream_unref(&client->common.input);
3879
928229f8b3e6 deinit, unref, destroy, close, free, etc. functions now take a pointer to
Timo Sirainen <tss@iki.fi>
parents: 3863
diff changeset
144 o_stream_unref(&client->output);
928229f8b3e6 deinit, unref, destroy, close, free, etc. functions now take a pointer to
Timo Sirainen <tss@iki.fi>
parents: 3863
diff changeset
145 imap_parser_destroy(&client->parser);
2421
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2097
diff changeset
146
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2097
diff changeset
147 /* CRLF is lost from buffer when streams are reopened. */
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2097
diff changeset
148 client->skip_line = FALSE;
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2097
diff changeset
149
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2097
diff changeset
150 client_open_streams(client, fd_ssl);
2733
9b9d9c164a31 Login process cleanups. Share more authentication code between pop3/imap.
Timo Sirainen <tss@iki.fi>
parents: 2691
diff changeset
151 client->io = io_add(client->common.fd, IO_READ, client_input, client);
2421
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2097
diff changeset
152 }
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2097
diff changeset
153
4907
5b4c9b20eba0 Replaced void *context from a lot of callbacks with the actual context
Timo Sirainen <tss@iki.fi>
parents: 4903
diff changeset
154 static int client_output_starttls(struct imap_client *client)
2421
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2097
diff changeset
155 {
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2097
diff changeset
156 int ret;
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2097
diff changeset
157
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2097
diff changeset
158 if ((ret = o_stream_flush(client->output)) < 0) {
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2097
diff changeset
159 client_destroy(client, "Disconnected");
2790
02c0b8d532c2 Changed ostream's flush callback to have return value which can tell if
Timo Sirainen <tss@iki.fi>
parents: 2787
diff changeset
160 return 1;
2421
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2097
diff changeset
161 }
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2097
diff changeset
162
4124
e65a7848e9e4 Output flush handler wasn't unset after STARTTLS, which could have caused
Timo Sirainen <tss@iki.fi>
parents: 3955
diff changeset
163 if (ret > 0) {
4903
204d7edc7cdc Added context parameter type safety checks for most callback APIs.
Timo Sirainen <tss@iki.fi>
parents: 4845
diff changeset
164 o_stream_unset_flush_callback(client->output);
2421
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2097
diff changeset
165 client_start_tls(client);
4124
e65a7848e9e4 Output flush handler wasn't unset after STARTTLS, which could have caused
Timo Sirainen <tss@iki.fi>
parents: 3955
diff changeset
166 }
2790
02c0b8d532c2 Changed ostream's flush callback to have return value which can tell if
Timo Sirainen <tss@iki.fi>
parents: 2787
diff changeset
167 return 1;
2421
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2097
diff changeset
168 }
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2097
diff changeset
169
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2097
diff changeset
170 static int cmd_starttls(struct imap_client *client)
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2097
diff changeset
171 {
2733
9b9d9c164a31 Login process cleanups. Share more authentication code between pop3/imap.
Timo Sirainen <tss@iki.fi>
parents: 2691
diff changeset
172 if (client->common.tls) {
1049
c41787e8c3f4 Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
173 client_send_tagline(client, "BAD TLS is already active.");
3863
55df57c028d4 Added "bool" type and changed all ints that were used as booleans to bool.
Timo Sirainen <tss@iki.fi>
parents: 3706
diff changeset
174 return 1;
1049
c41787e8c3f4 Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
175 }
c41787e8c3f4 Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
176
c41787e8c3f4 Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
177 if (!ssl_initialized) {
c41787e8c3f4 Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
178 client_send_tagline(client, "BAD TLS support isn't enabled.");
3863
55df57c028d4 Added "bool" type and changed all ints that were used as booleans to bool.
Timo Sirainen <tss@iki.fi>
parents: 3706
diff changeset
179 return 1;
1049
c41787e8c3f4 Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
180 }
c41787e8c3f4 Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
181
2421
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2097
diff changeset
182 /* remove input handler, SSL proxy gives us a new fd. we also have to
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2097
diff changeset
183 remove it in case we have to wait for buffer to be flushed */
3879
928229f8b3e6 deinit, unref, destroy, close, free, etc. functions now take a pointer to
Timo Sirainen <tss@iki.fi>
parents: 3863
diff changeset
184 if (client->io != NULL)
928229f8b3e6 deinit, unref, destroy, close, free, etc. functions now take a pointer to
Timo Sirainen <tss@iki.fi>
parents: 3863
diff changeset
185 io_remove(&client->io);
1049
c41787e8c3f4 Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
186
2421
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2097
diff changeset
187 client_send_tagline(client, "OK Begin TLS negotiation now.");
3581
cb143fc37b58 Make sure corking is removed before calling ssl_proxy_new()
Timo Sirainen <tss@iki.fi>
parents: 3384
diff changeset
188
cb143fc37b58 Make sure corking is removed before calling ssl_proxy_new()
Timo Sirainen <tss@iki.fi>
parents: 3384
diff changeset
189 /* uncork the old fd */
cb143fc37b58 Make sure corking is removed before calling ssl_proxy_new()
Timo Sirainen <tss@iki.fi>
parents: 3384
diff changeset
190 o_stream_uncork(client->output);
cb143fc37b58 Make sure corking is removed before calling ssl_proxy_new()
Timo Sirainen <tss@iki.fi>
parents: 3384
diff changeset
191
3360
8df4cfb22171 STARTTLS was broken
Timo Sirainen <tss@iki.fi>
parents: 3128
diff changeset
192 if (o_stream_flush(client->output) <= 0) {
2421
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2097
diff changeset
193 /* the buffer has to be flushed */
3360
8df4cfb22171 STARTTLS was broken
Timo Sirainen <tss@iki.fi>
parents: 3128
diff changeset
194 o_stream_set_flush_pending(client->output, TRUE);
2421
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2097
diff changeset
195 o_stream_set_flush_callback(client->output,
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2097
diff changeset
196 client_output_starttls, client);
1049
c41787e8c3f4 Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
197 } else {
2421
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2097
diff changeset
198 client_start_tls(client);
1049
c41787e8c3f4 Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
199 }
3863
55df57c028d4 Added "bool" type and changed all ints that were used as booleans to bool.
Timo Sirainen <tss@iki.fi>
parents: 3706
diff changeset
200 return 1;
1049
c41787e8c3f4 Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
201 }
c41787e8c3f4 Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
202
7920
3644883cf44e Support transferring original IPs and ports through IMAP proxies.
Timo Sirainen <tss@iki.fi>
parents: 7917
diff changeset
203 static void
3644883cf44e Support transferring original IPs and ports through IMAP proxies.
Timo Sirainen <tss@iki.fi>
parents: 7917
diff changeset
204 client_update_info(struct imap_client *client, const struct imap_arg *args)
3644883cf44e Support transferring original IPs and ports through IMAP proxies.
Timo Sirainen <tss@iki.fi>
parents: 7917
diff changeset
205 {
3644883cf44e Support transferring original IPs and ports through IMAP proxies.
Timo Sirainen <tss@iki.fi>
parents: 7917
diff changeset
206 const char *key, *value;
3644883cf44e Support transferring original IPs and ports through IMAP proxies.
Timo Sirainen <tss@iki.fi>
parents: 7917
diff changeset
207
3644883cf44e Support transferring original IPs and ports through IMAP proxies.
Timo Sirainen <tss@iki.fi>
parents: 7917
diff changeset
208 if (args->type != IMAP_ARG_LIST)
3644883cf44e Support transferring original IPs and ports through IMAP proxies.
Timo Sirainen <tss@iki.fi>
parents: 7917
diff changeset
209 return;
3644883cf44e Support transferring original IPs and ports through IMAP proxies.
Timo Sirainen <tss@iki.fi>
parents: 7917
diff changeset
210 args = IMAP_ARG_LIST_ARGS(args);
3644883cf44e Support transferring original IPs and ports through IMAP proxies.
Timo Sirainen <tss@iki.fi>
parents: 7917
diff changeset
211
3644883cf44e Support transferring original IPs and ports through IMAP proxies.
Timo Sirainen <tss@iki.fi>
parents: 7917
diff changeset
212 while (args->type == IMAP_ARG_STRING &&
3644883cf44e Support transferring original IPs and ports through IMAP proxies.
Timo Sirainen <tss@iki.fi>
parents: 7917
diff changeset
213 args[1].type == IMAP_ARG_STRING) {
3644883cf44e Support transferring original IPs and ports through IMAP proxies.
Timo Sirainen <tss@iki.fi>
parents: 7917
diff changeset
214 key = IMAP_ARG_STR_NONULL(&args[0]);
3644883cf44e Support transferring original IPs and ports through IMAP proxies.
Timo Sirainen <tss@iki.fi>
parents: 7917
diff changeset
215 value = IMAP_ARG_STR_NONULL(&args[1]);
3644883cf44e Support transferring original IPs and ports through IMAP proxies.
Timo Sirainen <tss@iki.fi>
parents: 7917
diff changeset
216 if (strcasecmp(key, "x-originating-ip") == 0)
3644883cf44e Support transferring original IPs and ports through IMAP proxies.
Timo Sirainen <tss@iki.fi>
parents: 7917
diff changeset
217 (void)net_addr2ip(value, &client->common.ip);
3644883cf44e Support transferring original IPs and ports through IMAP proxies.
Timo Sirainen <tss@iki.fi>
parents: 7917
diff changeset
218 else if (strcasecmp(key, "x-originating-port") == 0)
3644883cf44e Support transferring original IPs and ports through IMAP proxies.
Timo Sirainen <tss@iki.fi>
parents: 7917
diff changeset
219 client->common.remote_port = atoi(value);
7921
9a7469e52f91 Renamed x-local-ip/port to x-connected-ip/port
Timo Sirainen <tss@iki.fi>
parents: 7920
diff changeset
220 else if (strcasecmp(key, "x-connected-ip") == 0)
7920
3644883cf44e Support transferring original IPs and ports through IMAP proxies.
Timo Sirainen <tss@iki.fi>
parents: 7917
diff changeset
221 (void)net_addr2ip(value, &client->common.local_ip);
7921
9a7469e52f91 Renamed x-local-ip/port to x-connected-ip/port
Timo Sirainen <tss@iki.fi>
parents: 7920
diff changeset
222 else if (strcasecmp(key, "x-connected-port") == 0)
7920
3644883cf44e Support transferring original IPs and ports through IMAP proxies.
Timo Sirainen <tss@iki.fi>
parents: 7917
diff changeset
223 client->common.local_port = atoi(value);
3644883cf44e Support transferring original IPs and ports through IMAP proxies.
Timo Sirainen <tss@iki.fi>
parents: 7917
diff changeset
224 args += 2;
3644883cf44e Support transferring original IPs and ports through IMAP proxies.
Timo Sirainen <tss@iki.fi>
parents: 7917
diff changeset
225 }
3644883cf44e Support transferring original IPs and ports through IMAP proxies.
Timo Sirainen <tss@iki.fi>
parents: 7917
diff changeset
226 }
3644883cf44e Support transferring original IPs and ports through IMAP proxies.
Timo Sirainen <tss@iki.fi>
parents: 7917
diff changeset
227
7917
ca2ff54ee9b4 Added support for IMAP ID extension.
Timo Sirainen <tss@iki.fi>
parents: 7438
diff changeset
228 static int cmd_id(struct imap_client *client, const struct imap_arg *args)
ca2ff54ee9b4 Added support for IMAP ID extension.
Timo Sirainen <tss@iki.fi>
parents: 7438
diff changeset
229 {
ca2ff54ee9b4 Added support for IMAP ID extension.
Timo Sirainen <tss@iki.fi>
parents: 7438
diff changeset
230 const char *env, *value;
ca2ff54ee9b4 Added support for IMAP ID extension.
Timo Sirainen <tss@iki.fi>
parents: 7438
diff changeset
231
ca2ff54ee9b4 Added support for IMAP ID extension.
Timo Sirainen <tss@iki.fi>
parents: 7438
diff changeset
232 if (!client->id_logged) {
ca2ff54ee9b4 Added support for IMAP ID extension.
Timo Sirainen <tss@iki.fi>
parents: 7438
diff changeset
233 client->id_logged = TRUE;
7920
3644883cf44e Support transferring original IPs and ports through IMAP proxies.
Timo Sirainen <tss@iki.fi>
parents: 7917
diff changeset
234 if (client->common.trusted)
3644883cf44e Support transferring original IPs and ports through IMAP proxies.
Timo Sirainen <tss@iki.fi>
parents: 7917
diff changeset
235 client_update_info(client, args);
3644883cf44e Support transferring original IPs and ports through IMAP proxies.
Timo Sirainen <tss@iki.fi>
parents: 7917
diff changeset
236
7917
ca2ff54ee9b4 Added support for IMAP ID extension.
Timo Sirainen <tss@iki.fi>
parents: 7438
diff changeset
237 env = getenv("IMAP_ID_LOG");
ca2ff54ee9b4 Added support for IMAP ID extension.
Timo Sirainen <tss@iki.fi>
parents: 7438
diff changeset
238 value = imap_id_args_get_log_reply(args, env);
ca2ff54ee9b4 Added support for IMAP ID extension.
Timo Sirainen <tss@iki.fi>
parents: 7438
diff changeset
239 if (value != NULL) {
ca2ff54ee9b4 Added support for IMAP ID extension.
Timo Sirainen <tss@iki.fi>
parents: 7438
diff changeset
240 client_syslog(&client->common,
ca2ff54ee9b4 Added support for IMAP ID extension.
Timo Sirainen <tss@iki.fi>
parents: 7438
diff changeset
241 t_strdup_printf("ID sent: %s", value));
ca2ff54ee9b4 Added support for IMAP ID extension.
Timo Sirainen <tss@iki.fi>
parents: 7438
diff changeset
242 }
ca2ff54ee9b4 Added support for IMAP ID extension.
Timo Sirainen <tss@iki.fi>
parents: 7438
diff changeset
243 }
ca2ff54ee9b4 Added support for IMAP ID extension.
Timo Sirainen <tss@iki.fi>
parents: 7438
diff changeset
244
ca2ff54ee9b4 Added support for IMAP ID extension.
Timo Sirainen <tss@iki.fi>
parents: 7438
diff changeset
245 env = getenv("IMAP_ID_SEND");
ca2ff54ee9b4 Added support for IMAP ID extension.
Timo Sirainen <tss@iki.fi>
parents: 7438
diff changeset
246 client_send_line(client, t_strdup_printf("* ID %s",
ca2ff54ee9b4 Added support for IMAP ID extension.
Timo Sirainen <tss@iki.fi>
parents: 7438
diff changeset
247 imap_id_reply_generate(env)));
ca2ff54ee9b4 Added support for IMAP ID extension.
Timo Sirainen <tss@iki.fi>
parents: 7438
diff changeset
248 client_send_tagline(client, "OK ID completed.");
ca2ff54ee9b4 Added support for IMAP ID extension.
Timo Sirainen <tss@iki.fi>
parents: 7438
diff changeset
249 return 1;
ca2ff54ee9b4 Added support for IMAP ID extension.
Timo Sirainen <tss@iki.fi>
parents: 7438
diff changeset
250 }
ca2ff54ee9b4 Added support for IMAP ID extension.
Timo Sirainen <tss@iki.fi>
parents: 7438
diff changeset
251
1049
c41787e8c3f4 Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
252 static int cmd_noop(struct imap_client *client)
c41787e8c3f4 Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
253 {
c41787e8c3f4 Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
254 client_send_tagline(client, "OK NOOP completed.");
3863
55df57c028d4 Added "bool" type and changed all ints that were used as booleans to bool.
Timo Sirainen <tss@iki.fi>
parents: 3706
diff changeset
255 return 1;
1049
c41787e8c3f4 Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
256 }
c41787e8c3f4 Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
257
c41787e8c3f4 Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
258 static int cmd_logout(struct imap_client *client)
c41787e8c3f4 Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
259 {
c41787e8c3f4 Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
260 client_send_line(client, "* BYE Logging out");
c41787e8c3f4 Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
261 client_send_tagline(client, "OK Logout completed.");
8302
0db37acdc59f Login process: Log auth failure reasons better in disconnect message.
Timo Sirainen <tss@iki.fi>
parents: 8106
diff changeset
262 client_destroy(client, "Aborted login");
3863
55df57c028d4 Added "bool" type and changed all ints that were used as booleans to bool.
Timo Sirainen <tss@iki.fi>
parents: 3706
diff changeset
263 return 1;
1049
c41787e8c3f4 Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
264 }
c41787e8c3f4 Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
265
7923
67a2d45e8e95 Don't return BAD if ENABLE command is used in pre-auth state. Just ignore it.
Timo Sirainen <tss@iki.fi>
parents: 7922
diff changeset
266 static int cmd_enable(struct imap_client *client)
67a2d45e8e95 Don't return BAD if ENABLE command is used in pre-auth state. Just ignore it.
Timo Sirainen <tss@iki.fi>
parents: 7922
diff changeset
267 {
67a2d45e8e95 Don't return BAD if ENABLE command is used in pre-auth state. Just ignore it.
Timo Sirainen <tss@iki.fi>
parents: 7922
diff changeset
268 client_send_line(client, "* ENABLED");
67a2d45e8e95 Don't return BAD if ENABLE command is used in pre-auth state. Just ignore it.
Timo Sirainen <tss@iki.fi>
parents: 7922
diff changeset
269 client_send_tagline(client,
67a2d45e8e95 Don't return BAD if ENABLE command is used in pre-auth state. Just ignore it.
Timo Sirainen <tss@iki.fi>
parents: 7922
diff changeset
270 "OK ENABLE ignored in non-authenticated state.");
67a2d45e8e95 Don't return BAD if ENABLE command is used in pre-auth state. Just ignore it.
Timo Sirainen <tss@iki.fi>
parents: 7922
diff changeset
271 return 1;
67a2d45e8e95 Don't return BAD if ENABLE command is used in pre-auth state. Just ignore it.
Timo Sirainen <tss@iki.fi>
parents: 7922
diff changeset
272 }
67a2d45e8e95 Don't return BAD if ENABLE command is used in pre-auth state. Just ignore it.
Timo Sirainen <tss@iki.fi>
parents: 7922
diff changeset
273
1049
c41787e8c3f4 Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
274 static int client_command_execute(struct imap_client *client, const char *cmd,
5835
d59ed6a31b66 Added more consts to imap-parser API
Timo Sirainen <tss@iki.fi>
parents: 5671
diff changeset
275 const struct imap_arg *args)
1049
c41787e8c3f4 Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
276 {
2058
0a1755f79392 cleanup: str_*case(t_strdup_noconst(str)) -> t_str_*case(str)
Timo Sirainen <tss@iki.fi>
parents: 2027
diff changeset
277 cmd = t_str_ucase(cmd);
1049
c41787e8c3f4 Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
278 if (strcmp(cmd, "LOGIN") == 0)
c41787e8c3f4 Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
279 return cmd_login(client, args);
c41787e8c3f4 Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
280 if (strcmp(cmd, "AUTHENTICATE") == 0)
c41787e8c3f4 Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
281 return cmd_authenticate(client, args);
c41787e8c3f4 Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
282 if (strcmp(cmd, "CAPABILITY") == 0)
c41787e8c3f4 Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
283 return cmd_capability(client);
c41787e8c3f4 Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
284 if (strcmp(cmd, "STARTTLS") == 0)
c41787e8c3f4 Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
285 return cmd_starttls(client);
7917
ca2ff54ee9b4 Added support for IMAP ID extension.
Timo Sirainen <tss@iki.fi>
parents: 7438
diff changeset
286 if (strcmp(cmd, "ID") == 0)
ca2ff54ee9b4 Added support for IMAP ID extension.
Timo Sirainen <tss@iki.fi>
parents: 7438
diff changeset
287 return cmd_id(client, args);
1049
c41787e8c3f4 Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
288 if (strcmp(cmd, "NOOP") == 0)
c41787e8c3f4 Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
289 return cmd_noop(client);
c41787e8c3f4 Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
290 if (strcmp(cmd, "LOGOUT") == 0)
c41787e8c3f4 Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
291 return cmd_logout(client);
7923
67a2d45e8e95 Don't return BAD if ENABLE command is used in pre-auth state. Just ignore it.
Timo Sirainen <tss@iki.fi>
parents: 7922
diff changeset
292 if (strcmp(cmd, "ENABLE") == 0)
67a2d45e8e95 Don't return BAD if ENABLE command is used in pre-auth state. Just ignore it.
Timo Sirainen <tss@iki.fi>
parents: 7922
diff changeset
293 return cmd_enable(client);
1049
c41787e8c3f4 Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
294
2733
9b9d9c164a31 Login process cleanups. Share more authentication code between pop3/imap.
Timo Sirainen <tss@iki.fi>
parents: 2691
diff changeset
295 return -1;
1049
c41787e8c3f4 Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
296 }
c41787e8c3f4 Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
297
3863
55df57c028d4 Added "bool" type and changed all ints that were used as booleans to bool.
Timo Sirainen <tss@iki.fi>
parents: 3706
diff changeset
298 static bool client_handle_input(struct imap_client *client)
1049
c41787e8c3f4 Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
299 {
5835
d59ed6a31b66 Added more consts to imap-parser API
Timo Sirainen <tss@iki.fi>
parents: 5671
diff changeset
300 const struct imap_arg *args;
1814
b523a248424c Don't disconnect client immediately if there's an error in IMAP syntax.
Timo Sirainen <tss@iki.fi>
parents: 1782
diff changeset
301 const char *msg;
3863
55df57c028d4 Added "bool" type and changed all ints that were used as booleans to bool.
Timo Sirainen <tss@iki.fi>
parents: 3706
diff changeset
302 int ret;
55df57c028d4 Added "bool" type and changed all ints that were used as booleans to bool.
Timo Sirainen <tss@iki.fi>
parents: 3706
diff changeset
303 bool fatal;
1049
c41787e8c3f4 Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
304
2733
9b9d9c164a31 Login process cleanups. Share more authentication code between pop3/imap.
Timo Sirainen <tss@iki.fi>
parents: 2691
diff changeset
305 i_assert(!client->common.authenticating);
1275
af685269ead0 login: Wait until we're connected to auth process before executing command
Timo Sirainen <tss@iki.fi>
parents: 1235
diff changeset
306
1049
c41787e8c3f4 Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
307 if (client->cmd_finished) {
c41787e8c3f4 Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
308 /* clear the previous command from memory. don't do this
c41787e8c3f4 Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
309 immediately after handling command since we need the
c41787e8c3f4 Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
310 cmd_tag to stay some time after authentication commands. */
c41787e8c3f4 Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
311 client->cmd_tag = NULL;
c41787e8c3f4 Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
312 client->cmd_name = NULL;
c41787e8c3f4 Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
313 imap_parser_reset(client->parser);
c41787e8c3f4 Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
314
c41787e8c3f4 Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
315 /* remove \r\n */
c41787e8c3f4 Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
316 if (client->skip_line) {
c41787e8c3f4 Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
317 if (!client_skip_line(client))
1571
1cadf76d7c4c imap-login could get into infinite loop if connection was closed improperly.
Timo Sirainen <tss@iki.fi>
parents: 1499
diff changeset
318 return FALSE;
1049
c41787e8c3f4 Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
319 client->skip_line = FALSE;
c41787e8c3f4 Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
320 }
c41787e8c3f4 Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
321
c41787e8c3f4 Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
322 client->cmd_finished = FALSE;
c41787e8c3f4 Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
323 }
c41787e8c3f4 Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
324
c41787e8c3f4 Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
325 if (client->cmd_tag == NULL) {
c41787e8c3f4 Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
326 client->cmd_tag = imap_parser_read_word(client->parser);
c41787e8c3f4 Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
327 if (client->cmd_tag == NULL)
1275
af685269ead0 login: Wait until we're connected to auth process before executing command
Timo Sirainen <tss@iki.fi>
parents: 1235
diff changeset
328 return FALSE; /* need more data */
1049
c41787e8c3f4 Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
329 }
c41787e8c3f4 Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
330
c41787e8c3f4 Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
331 if (client->cmd_name == NULL) {
c41787e8c3f4 Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
332 client->cmd_name = imap_parser_read_word(client->parser);
c41787e8c3f4 Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
333 if (client->cmd_name == NULL)
1275
af685269ead0 login: Wait until we're connected to auth process before executing command
Timo Sirainen <tss@iki.fi>
parents: 1235
diff changeset
334 return FALSE; /* need more data */
1049
c41787e8c3f4 Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
335 }
c41787e8c3f4 Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
336
c41787e8c3f4 Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
337 switch (imap_parser_read_args(client->parser, 0, 0, &args)) {
c41787e8c3f4 Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
338 case -1:
c41787e8c3f4 Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
339 /* error */
1814
b523a248424c Don't disconnect client immediately if there's an error in IMAP syntax.
Timo Sirainen <tss@iki.fi>
parents: 1782
diff changeset
340 msg = imap_parser_get_error(client->parser, &fatal);
b523a248424c Don't disconnect client immediately if there's an error in IMAP syntax.
Timo Sirainen <tss@iki.fi>
parents: 1782
diff changeset
341 if (fatal) {
b523a248424c Don't disconnect client immediately if there's an error in IMAP syntax.
Timo Sirainen <tss@iki.fi>
parents: 1782
diff changeset
342 client_send_line(client, t_strconcat("* BYE ",
b523a248424c Don't disconnect client immediately if there's an error in IMAP syntax.
Timo Sirainen <tss@iki.fi>
parents: 1782
diff changeset
343 msg, NULL));
7438
65fbb6226141 Log clearly with "auth failed, # attempts" if user gets disconnected before
Timo Sirainen <tss@iki.fi>
parents: 7137
diff changeset
344 client_destroy(client,
65fbb6226141 Log clearly with "auth failed, # attempts" if user gets disconnected before
Timo Sirainen <tss@iki.fi>
parents: 7137
diff changeset
345 t_strconcat("Disconnected: ", msg, NULL));
1814
b523a248424c Don't disconnect client immediately if there's an error in IMAP syntax.
Timo Sirainen <tss@iki.fi>
parents: 1782
diff changeset
346 return FALSE;
b523a248424c Don't disconnect client immediately if there's an error in IMAP syntax.
Timo Sirainen <tss@iki.fi>
parents: 1782
diff changeset
347 }
b523a248424c Don't disconnect client immediately if there's an error in IMAP syntax.
Timo Sirainen <tss@iki.fi>
parents: 1782
diff changeset
348
b523a248424c Don't disconnect client immediately if there's an error in IMAP syntax.
Timo Sirainen <tss@iki.fi>
parents: 1782
diff changeset
349 client_send_tagline(client, t_strconcat("BAD ", msg, NULL));
b523a248424c Don't disconnect client immediately if there's an error in IMAP syntax.
Timo Sirainen <tss@iki.fi>
parents: 1782
diff changeset
350 client->cmd_finished = TRUE;
b523a248424c Don't disconnect client immediately if there's an error in IMAP syntax.
Timo Sirainen <tss@iki.fi>
parents: 1782
diff changeset
351 client->skip_line = TRUE;
b523a248424c Don't disconnect client immediately if there's an error in IMAP syntax.
Timo Sirainen <tss@iki.fi>
parents: 1782
diff changeset
352 return TRUE;
1049
c41787e8c3f4 Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
353 case -2:
c41787e8c3f4 Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
354 /* not enough data */
1275
af685269ead0 login: Wait until we're connected to auth process before executing command
Timo Sirainen <tss@iki.fi>
parents: 1235
diff changeset
355 return FALSE;
1049
c41787e8c3f4 Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
356 }
7927
2351a81ce699 If commands are pipelined after the login command, pass them to the
Timo Sirainen <tss@iki.fi>
parents: 7923
diff changeset
357 /* we read the entire line - skip over the CRLF */
2351a81ce699 If commands are pipelined after the login command, pass them to the
Timo Sirainen <tss@iki.fi>
parents: 7923
diff changeset
358 if (!client_skip_line(client))
2351a81ce699 If commands are pipelined after the login command, pass them to the
Timo Sirainen <tss@iki.fi>
parents: 7923
diff changeset
359 i_unreached();
1049
c41787e8c3f4 Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
360
2733
9b9d9c164a31 Login process cleanups. Share more authentication code between pop3/imap.
Timo Sirainen <tss@iki.fi>
parents: 2691
diff changeset
361 if (*client->cmd_tag == '\0')
9b9d9c164a31 Login process cleanups. Share more authentication code between pop3/imap.
Timo Sirainen <tss@iki.fi>
parents: 2691
diff changeset
362 ret = -1;
9b9d9c164a31 Login process cleanups. Share more authentication code between pop3/imap.
Timo Sirainen <tss@iki.fi>
parents: 2691
diff changeset
363 else
9b9d9c164a31 Login process cleanups. Share more authentication code between pop3/imap.
Timo Sirainen <tss@iki.fi>
parents: 2691
diff changeset
364 ret = client_command_execute(client, client->cmd_name, args);
9b9d9c164a31 Login process cleanups. Share more authentication code between pop3/imap.
Timo Sirainen <tss@iki.fi>
parents: 2691
diff changeset
365
9b9d9c164a31 Login process cleanups. Share more authentication code between pop3/imap.
Timo Sirainen <tss@iki.fi>
parents: 2691
diff changeset
366 client->cmd_finished = TRUE;
9b9d9c164a31 Login process cleanups. Share more authentication code between pop3/imap.
Timo Sirainen <tss@iki.fi>
parents: 2691
diff changeset
367 if (ret < 0) {
1814
b523a248424c Don't disconnect client immediately if there's an error in IMAP syntax.
Timo Sirainen <tss@iki.fi>
parents: 1782
diff changeset
368 if (*client->cmd_tag == '\0')
b523a248424c Don't disconnect client immediately if there's an error in IMAP syntax.
Timo Sirainen <tss@iki.fi>
parents: 1782
diff changeset
369 client->cmd_tag = "*";
1049
c41787e8c3f4 Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
370 if (++client->bad_counter >= CLIENT_MAX_BAD_COMMANDS) {
c41787e8c3f4 Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
371 client_send_line(client,
c41787e8c3f4 Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
372 "* BYE Too many invalid IMAP commands.");
7438
65fbb6226141 Log clearly with "auth failed, # attempts" if user gets disconnected before
Timo Sirainen <tss@iki.fi>
parents: 7137
diff changeset
373 client_destroy(client,
65fbb6226141 Log clearly with "auth failed, # attempts" if user gets disconnected before
Timo Sirainen <tss@iki.fi>
parents: 7137
diff changeset
374 "Disconnected: Too many invalid commands");
1275
af685269ead0 login: Wait until we're connected to auth process before executing command
Timo Sirainen <tss@iki.fi>
parents: 1235
diff changeset
375 return FALSE;
2733
9b9d9c164a31 Login process cleanups. Share more authentication code between pop3/imap.
Timo Sirainen <tss@iki.fi>
parents: 2691
diff changeset
376 }
1049
c41787e8c3f4 Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
377 client_send_tagline(client,
c41787e8c3f4 Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
378 "BAD Error in IMAP command received by server.");
c41787e8c3f4 Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
379 }
c41787e8c3f4 Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
380
2733
9b9d9c164a31 Login process cleanups. Share more authentication code between pop3/imap.
Timo Sirainen <tss@iki.fi>
parents: 2691
diff changeset
381 return ret != 0;
1049
c41787e8c3f4 Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
382 }
c41787e8c3f4 Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
383
3863
55df57c028d4 Added "bool" type and changed all ints that were used as booleans to bool.
Timo Sirainen <tss@iki.fi>
parents: 3706
diff changeset
384 bool client_read(struct imap_client *client)
1049
c41787e8c3f4 Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
385 {
7927
2351a81ce699 If commands are pipelined after the login command, pass them to the
Timo Sirainen <tss@iki.fi>
parents: 7923
diff changeset
386 switch (i_stream_read(client->common.input)) {
1049
c41787e8c3f4 Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
387 case -2:
c41787e8c3f4 Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
388 /* buffer full */
c41787e8c3f4 Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
389 client_send_line(client, "* BYE Input buffer full, aborting");
c41787e8c3f4 Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
390 client_destroy(client, "Disconnected: Input buffer full");
c41787e8c3f4 Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
391 return FALSE;
c41787e8c3f4 Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
392 case -1:
c41787e8c3f4 Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
393 /* disconnected */
c41787e8c3f4 Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
394 client_destroy(client, "Disconnected");
c41787e8c3f4 Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
395 return FALSE;
8577
164569761647 login: Reset idle timeout only when input is actually read from client.
Timo Sirainen <tss@iki.fi>
parents: 8574
diff changeset
396 case 0:
164569761647 login: Reset idle timeout only when input is actually read from client.
Timo Sirainen <tss@iki.fi>
parents: 8574
diff changeset
397 /* nothing new read */
164569761647 login: Reset idle timeout only when input is actually read from client.
Timo Sirainen <tss@iki.fi>
parents: 8574
diff changeset
398 return TRUE;
1049
c41787e8c3f4 Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
399 default:
c41787e8c3f4 Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
400 /* something was read */
8577
164569761647 login: Reset idle timeout only when input is actually read from client.
Timo Sirainen <tss@iki.fi>
parents: 8574
diff changeset
401 timeout_reset(client->to_idle_disconnect);
1049
c41787e8c3f4 Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
402 return TRUE;
c41787e8c3f4 Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
403 }
c41787e8c3f4 Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
404 }
c41787e8c3f4 Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
405
4907
5b4c9b20eba0 Replaced void *context from a lot of callbacks with the actual context
Timo Sirainen <tss@iki.fi>
parents: 4903
diff changeset
406 void client_input(struct imap_client *client)
1049
c41787e8c3f4 Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
407 {
c41787e8c3f4 Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
408 if (!client_read(client))
c41787e8c3f4 Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
409 return;
c41787e8c3f4 Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
410
2421
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2097
diff changeset
411 client_ref(client);
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2097
diff changeset
412
1702
43815588dd6b Moved client side code for auth process handling to lib-auth. Some other login process cleanups.
Timo Sirainen <tss@iki.fi>
parents: 1591
diff changeset
413 if (!auth_client_is_connected(auth_client)) {
1275
af685269ead0 login: Wait until we're connected to auth process before executing command
Timo Sirainen <tss@iki.fi>
parents: 1235
diff changeset
414 /* we're not yet connected to auth process -
af685269ead0 login: Wait until we're connected to auth process before executing command
Timo Sirainen <tss@iki.fi>
parents: 1235
diff changeset
415 don't allow any commands */
7099
3f5b7bebfd82 Use separate per-client timeouts instead of going through all clients in one
Timo Sirainen <tss@iki.fi>
parents: 7086
diff changeset
416 client_send_line(client, AUTH_WAITING_MSG);
3f5b7bebfd82 Use separate per-client timeouts instead of going through all clients in one
Timo Sirainen <tss@iki.fi>
parents: 7086
diff changeset
417 if (client->to_auth_waiting != NULL)
3f5b7bebfd82 Use separate per-client timeouts instead of going through all clients in one
Timo Sirainen <tss@iki.fi>
parents: 7086
diff changeset
418 timeout_remove(&client->to_auth_waiting);
3f5b7bebfd82 Use separate per-client timeouts instead of going through all clients in one
Timo Sirainen <tss@iki.fi>
parents: 7086
diff changeset
419
1275
af685269ead0 login: Wait until we're connected to auth process before executing command
Timo Sirainen <tss@iki.fi>
parents: 1235
diff changeset
420 client->input_blocked = TRUE;
2421
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2097
diff changeset
421 } else {
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2097
diff changeset
422 o_stream_cork(client->output);
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2097
diff changeset
423 while (client_handle_input(client)) ;
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2097
diff changeset
424 o_stream_uncork(client->output);
1275
af685269ead0 login: Wait until we're connected to auth process before executing command
Timo Sirainen <tss@iki.fi>
parents: 1235
diff changeset
425 }
af685269ead0 login: Wait until we're connected to auth process before executing command
Timo Sirainen <tss@iki.fi>
parents: 1235
diff changeset
426
2421
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2097
diff changeset
427 client_unref(client);
1049
c41787e8c3f4 Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
428 }
c41787e8c3f4 Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
429
4560
507088c0d511 Fixes for handling near-full connection queues.
Timo Sirainen <tss@iki.fi>
parents: 4538
diff changeset
430 void client_destroy_oldest(void)
1049
c41787e8c3f4 Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
431 {
7101
09556a64b4e5 Use a linked list to keep track of all clients instead of a hash table.
Timo Sirainen <tss@iki.fi>
parents: 7099
diff changeset
432 struct client *client;
1897
1e6ed8045f2b Changed hash_foreach() to iterator.
Timo Sirainen <tss@iki.fi>
parents: 1814
diff changeset
433 struct imap_client *destroy_buf[CLIENT_DESTROY_OLDEST_COUNT];
4538
9d9e72374164 Fixes to login process handling, especially with
Timo Sirainen <tss@iki.fi>
parents: 4467
diff changeset
434 unsigned int i, destroy_count;
1897
1e6ed8045f2b Changed hash_foreach() to iterator.
Timo Sirainen <tss@iki.fi>
parents: 1814
diff changeset
435
1e6ed8045f2b Changed hash_foreach() to iterator.
Timo Sirainen <tss@iki.fi>
parents: 1814
diff changeset
436 /* find the oldest clients and put them to destroy-buffer */
1e6ed8045f2b Changed hash_foreach() to iterator.
Timo Sirainen <tss@iki.fi>
parents: 1814
diff changeset
437 memset(destroy_buf, 0, sizeof(destroy_buf));
1049
c41787e8c3f4 Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
438
4538
9d9e72374164 Fixes to login process handling, especially with
Timo Sirainen <tss@iki.fi>
parents: 4467
diff changeset
439 destroy_count = max_connections > CLIENT_DESTROY_OLDEST_COUNT*2 ?
9d9e72374164 Fixes to login process handling, especially with
Timo Sirainen <tss@iki.fi>
parents: 4467
diff changeset
440 CLIENT_DESTROY_OLDEST_COUNT : I_MIN(max_connections/2, 1);
7101
09556a64b4e5 Use a linked list to keep track of all clients instead of a hash table.
Timo Sirainen <tss@iki.fi>
parents: 7099
diff changeset
441 for (client = clients; client != NULL; client = client->next) {
09556a64b4e5 Use a linked list to keep track of all clients instead of a hash table.
Timo Sirainen <tss@iki.fi>
parents: 7099
diff changeset
442 struct imap_client *imap_client = (struct imap_client *)client;
1049
c41787e8c3f4 Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
443
4538
9d9e72374164 Fixes to login process handling, especially with
Timo Sirainen <tss@iki.fi>
parents: 4467
diff changeset
444 for (i = 0; i < destroy_count; i++) {
1897
1e6ed8045f2b Changed hash_foreach() to iterator.
Timo Sirainen <tss@iki.fi>
parents: 1814
diff changeset
445 if (destroy_buf[i] == NULL ||
7101
09556a64b4e5 Use a linked list to keep track of all clients instead of a hash table.
Timo Sirainen <tss@iki.fi>
parents: 7099
diff changeset
446 destroy_buf[i]->created > imap_client->created) {
1897
1e6ed8045f2b Changed hash_foreach() to iterator.
Timo Sirainen <tss@iki.fi>
parents: 1814
diff changeset
447 /* @UNSAFE */
1e6ed8045f2b Changed hash_foreach() to iterator.
Timo Sirainen <tss@iki.fi>
parents: 1814
diff changeset
448 memmove(destroy_buf+i+1, destroy_buf+i,
1e6ed8045f2b Changed hash_foreach() to iterator.
Timo Sirainen <tss@iki.fi>
parents: 1814
diff changeset
449 sizeof(destroy_buf) -
1e6ed8045f2b Changed hash_foreach() to iterator.
Timo Sirainen <tss@iki.fi>
parents: 1814
diff changeset
450 (i+1) * sizeof(struct imap_client *));
7101
09556a64b4e5 Use a linked list to keep track of all clients instead of a hash table.
Timo Sirainen <tss@iki.fi>
parents: 7099
diff changeset
451 destroy_buf[i] = imap_client;
1897
1e6ed8045f2b Changed hash_foreach() to iterator.
Timo Sirainen <tss@iki.fi>
parents: 1814
diff changeset
452 break;
1e6ed8045f2b Changed hash_foreach() to iterator.
Timo Sirainen <tss@iki.fi>
parents: 1814
diff changeset
453 }
1049
c41787e8c3f4 Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
454 }
c41787e8c3f4 Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
455 }
c41787e8c3f4 Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
456
c41787e8c3f4 Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
457 /* then kill them */
4538
9d9e72374164 Fixes to login process handling, especially with
Timo Sirainen <tss@iki.fi>
parents: 4467
diff changeset
458 for (i = 0; i < destroy_count; i++) {
1897
1e6ed8045f2b Changed hash_foreach() to iterator.
Timo Sirainen <tss@iki.fi>
parents: 1814
diff changeset
459 if (destroy_buf[i] == NULL)
1e6ed8045f2b Changed hash_foreach() to iterator.
Timo Sirainen <tss@iki.fi>
parents: 1814
diff changeset
460 break;
1049
c41787e8c3f4 Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
461
1897
1e6ed8045f2b Changed hash_foreach() to iterator.
Timo Sirainen <tss@iki.fi>
parents: 1814
diff changeset
462 client_destroy(destroy_buf[i],
1049
c41787e8c3f4 Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
463 "Disconnected: Connection queue full");
c41787e8c3f4 Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
464 }
c41787e8c3f4 Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
465 }
c41787e8c3f4 Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
466
3706
2422546e3c44 If capability is sent in greeting, don't send it before we have received
Timo Sirainen <tss@iki.fi>
parents: 3581
diff changeset
467 static void client_send_greeting(struct imap_client *client)
2422546e3c44 If capability is sent in greeting, don't send it before we have received
Timo Sirainen <tss@iki.fi>
parents: 3581
diff changeset
468 {
2422546e3c44 If capability is sent in greeting, don't send it before we have received
Timo Sirainen <tss@iki.fi>
parents: 3581
diff changeset
469 string_t *greet;
2422546e3c44 If capability is sent in greeting, don't send it before we have received
Timo Sirainen <tss@iki.fi>
parents: 3581
diff changeset
470
2422546e3c44 If capability is sent in greeting, don't send it before we have received
Timo Sirainen <tss@iki.fi>
parents: 3581
diff changeset
471 greet = t_str_new(128);
2422546e3c44 If capability is sent in greeting, don't send it before we have received
Timo Sirainen <tss@iki.fi>
parents: 3581
diff changeset
472 str_append(greet, "* OK ");
7922
4b4d2a4423ec Removed login_greeting_capability setting. Instead now a minimal pre-login
Timo Sirainen <tss@iki.fi>
parents: 7921
diff changeset
473 str_printfa(greet, "[CAPABILITY %s] ", get_capability(client, FALSE));
3706
2422546e3c44 If capability is sent in greeting, don't send it before we have received
Timo Sirainen <tss@iki.fi>
parents: 3581
diff changeset
474 str_append(greet, greeting);
2422546e3c44 If capability is sent in greeting, don't send it before we have received
Timo Sirainen <tss@iki.fi>
parents: 3581
diff changeset
475
2422546e3c44 If capability is sent in greeting, don't send it before we have received
Timo Sirainen <tss@iki.fi>
parents: 3581
diff changeset
476 client_send_line(client, str_c(greet));
2422546e3c44 If capability is sent in greeting, don't send it before we have received
Timo Sirainen <tss@iki.fi>
parents: 3581
diff changeset
477 client->greeting_sent = TRUE;
2422546e3c44 If capability is sent in greeting, don't send it before we have received
Timo Sirainen <tss@iki.fi>
parents: 3581
diff changeset
478 }
2422546e3c44 If capability is sent in greeting, don't send it before we have received
Timo Sirainen <tss@iki.fi>
parents: 3581
diff changeset
479
7099
3f5b7bebfd82 Use separate per-client timeouts instead of going through all clients in one
Timo Sirainen <tss@iki.fi>
parents: 7086
diff changeset
480 static void client_idle_disconnect_timeout(struct imap_client *client)
3f5b7bebfd82 Use separate per-client timeouts instead of going through all clients in one
Timo Sirainen <tss@iki.fi>
parents: 7086
diff changeset
481 {
3f5b7bebfd82 Use separate per-client timeouts instead of going through all clients in one
Timo Sirainen <tss@iki.fi>
parents: 7086
diff changeset
482 client_send_line(client, "* BYE Disconnected for inactivity.");
3f5b7bebfd82 Use separate per-client timeouts instead of going through all clients in one
Timo Sirainen <tss@iki.fi>
parents: 7086
diff changeset
483 client_destroy(client, "Disconnected: Inactivity");
3f5b7bebfd82 Use separate per-client timeouts instead of going through all clients in one
Timo Sirainen <tss@iki.fi>
parents: 7086
diff changeset
484 }
3f5b7bebfd82 Use separate per-client timeouts instead of going through all clients in one
Timo Sirainen <tss@iki.fi>
parents: 7086
diff changeset
485
3f5b7bebfd82 Use separate per-client timeouts instead of going through all clients in one
Timo Sirainen <tss@iki.fi>
parents: 7086
diff changeset
486 static void client_auth_waiting_timeout(struct imap_client *client)
3f5b7bebfd82 Use separate per-client timeouts instead of going through all clients in one
Timo Sirainen <tss@iki.fi>
parents: 7086
diff changeset
487 {
3f5b7bebfd82 Use separate per-client timeouts instead of going through all clients in one
Timo Sirainen <tss@iki.fi>
parents: 7086
diff changeset
488 client_send_line(client, AUTH_WAITING_MSG);
3f5b7bebfd82 Use separate per-client timeouts instead of going through all clients in one
Timo Sirainen <tss@iki.fi>
parents: 7086
diff changeset
489 timeout_remove(&client->to_auth_waiting);
3f5b7bebfd82 Use separate per-client timeouts instead of going through all clients in one
Timo Sirainen <tss@iki.fi>
parents: 7086
diff changeset
490 }
3f5b7bebfd82 Use separate per-client timeouts instead of going through all clients in one
Timo Sirainen <tss@iki.fi>
parents: 7086
diff changeset
491
3f5b7bebfd82 Use separate per-client timeouts instead of going through all clients in one
Timo Sirainen <tss@iki.fi>
parents: 7086
diff changeset
492 void client_set_auth_waiting(struct imap_client *client)
3f5b7bebfd82 Use separate per-client timeouts instead of going through all clients in one
Timo Sirainen <tss@iki.fi>
parents: 7086
diff changeset
493 {
3f5b7bebfd82 Use separate per-client timeouts instead of going through all clients in one
Timo Sirainen <tss@iki.fi>
parents: 7086
diff changeset
494 i_assert(client->to_auth_waiting == NULL);
3f5b7bebfd82 Use separate per-client timeouts instead of going through all clients in one
Timo Sirainen <tss@iki.fi>
parents: 7086
diff changeset
495 client->to_auth_waiting =
3f5b7bebfd82 Use separate per-client timeouts instead of going through all clients in one
Timo Sirainen <tss@iki.fi>
parents: 7086
diff changeset
496 timeout_add(AUTH_WAITING_TIMEOUT_MSECS,
3f5b7bebfd82 Use separate per-client timeouts instead of going through all clients in one
Timo Sirainen <tss@iki.fi>
parents: 7086
diff changeset
497 client_auth_waiting_timeout, client);
3f5b7bebfd82 Use separate per-client timeouts instead of going through all clients in one
Timo Sirainen <tss@iki.fi>
parents: 7086
diff changeset
498 }
3f5b7bebfd82 Use separate per-client timeouts instead of going through all clients in one
Timo Sirainen <tss@iki.fi>
parents: 7086
diff changeset
499
3863
55df57c028d4 Added "bool" type and changed all ints that were used as booleans to bool.
Timo Sirainen <tss@iki.fi>
parents: 3706
diff changeset
500 struct client *client_create(int fd, bool ssl, const struct ip_addr *local_ip,
2097
4e77cb0aff21 Added %l, %r and %P variables and mail_log_prefix setting.
Timo Sirainen <tss@iki.fi>
parents: 2088
diff changeset
501 const struct ip_addr *ip)
1049
c41787e8c3f4 Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
502 {
c41787e8c3f4 Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
503 struct imap_client *client;
c41787e8c3f4 Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
504
4664
881ed99266a2 New asserts / cleanup
Timo Sirainen <tss@iki.fi>
parents: 4560
diff changeset
505 i_assert(fd != -1);
881ed99266a2 New asserts / cleanup
Timo Sirainen <tss@iki.fi>
parents: 4560
diff changeset
506
4560
507088c0d511 Fixes for handling near-full connection queues.
Timo Sirainen <tss@iki.fi>
parents: 4538
diff changeset
507 connection_queue_add(1);
1049
c41787e8c3f4 Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
508
c41787e8c3f4 Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
509 /* always use nonblocking I/O */
c41787e8c3f4 Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
510 net_set_nonblock(fd, TRUE);
c41787e8c3f4 Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
511
c41787e8c3f4 Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
512 client = i_new(struct imap_client, 1);
c41787e8c3f4 Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
513 client->created = ioloop_time;
c41787e8c3f4 Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
514 client->refcount = 1;
1725
cc0690f92d96 disable_plaintext_auth defaults to yes now. ipv4 127.* and ipv6 ::1
Timo Sirainen <tss@iki.fi>
parents: 1714
diff changeset
515
2097
4e77cb0aff21 Added %l, %r and %P variables and mail_log_prefix setting.
Timo Sirainen <tss@iki.fi>
parents: 2088
diff changeset
516 client->common.local_ip = *local_ip;
1049
c41787e8c3f4 Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
517 client->common.ip = *ip;
c41787e8c3f4 Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
518 client->common.fd = fd;
7920
3644883cf44e Support transferring original IPs and ports through IMAP proxies.
Timo Sirainen <tss@iki.fi>
parents: 7917
diff changeset
519 client->common.tls = ssl;
3644883cf44e Support transferring original IPs and ports through IMAP proxies.
Timo Sirainen <tss@iki.fi>
parents: 7917
diff changeset
520 client->common.trusted = client_is_trusted(&client->common);
3644883cf44e Support transferring original IPs and ports through IMAP proxies.
Timo Sirainen <tss@iki.fi>
parents: 7917
diff changeset
521 client->common.secured = ssl || client->common.trusted ||
3644883cf44e Support transferring original IPs and ports through IMAP proxies.
Timo Sirainen <tss@iki.fi>
parents: 7917
diff changeset
522 net_ip_compare(ip, local_ip);
1079
3aece07f3a1b STARTTLS commands crashed. imap-login STARTTLS also ignored next command.
Timo Sirainen <tss@iki.fi>
parents: 1049
diff changeset
523
3aece07f3a1b STARTTLS commands crashed. imap-login STARTTLS also ignored next command.
Timo Sirainen <tss@iki.fi>
parents: 1049
diff changeset
524 client_open_streams(client, fd);
2733
9b9d9c164a31 Login process cleanups. Share more authentication code between pop3/imap.
Timo Sirainen <tss@iki.fi>
parents: 2691
diff changeset
525 client->io = io_add(fd, IO_READ, client_input, client);
1049
c41787e8c3f4 Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
526
7101
09556a64b4e5 Use a linked list to keep track of all clients instead of a hash table.
Timo Sirainen <tss@iki.fi>
parents: 7099
diff changeset
527 client_link(&client->common);
1049
c41787e8c3f4 Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
528
c41787e8c3f4 Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
529 main_ref();
c41787e8c3f4 Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
530
7922
4b4d2a4423ec Removed login_greeting_capability setting. Instead now a minimal pre-login
Timo Sirainen <tss@iki.fi>
parents: 7921
diff changeset
531 if (auth_client_is_connected(auth_client))
7099
3f5b7bebfd82 Use separate per-client timeouts instead of going through all clients in one
Timo Sirainen <tss@iki.fi>
parents: 7086
diff changeset
532 client_send_greeting(client);
3f5b7bebfd82 Use separate per-client timeouts instead of going through all clients in one
Timo Sirainen <tss@iki.fi>
parents: 7086
diff changeset
533 else
3f5b7bebfd82 Use separate per-client timeouts instead of going through all clients in one
Timo Sirainen <tss@iki.fi>
parents: 7086
diff changeset
534 client_set_auth_waiting(client);
1049
c41787e8c3f4 Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
535 client_set_title(client);
2901
872172ffd005 Don't destroy client structure immediately when sending line fails. Fixes some writes to freed memory.
Timo Sirainen <tss@iki.fi>
parents: 2837
diff changeset
536
7099
3f5b7bebfd82 Use separate per-client timeouts instead of going through all clients in one
Timo Sirainen <tss@iki.fi>
parents: 7086
diff changeset
537 client->to_idle_disconnect =
3f5b7bebfd82 Use separate per-client timeouts instead of going through all clients in one
Timo Sirainen <tss@iki.fi>
parents: 7086
diff changeset
538 timeout_add(CLIENT_LOGIN_IDLE_TIMEOUT_MSECS,
3f5b7bebfd82 Use separate per-client timeouts instead of going through all clients in one
Timo Sirainen <tss@iki.fi>
parents: 7086
diff changeset
539 client_idle_disconnect_timeout, client);
1049
c41787e8c3f4 Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
540 return &client->common;
c41787e8c3f4 Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
541 }
c41787e8c3f4 Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
542
c41787e8c3f4 Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
543 void client_destroy(struct imap_client *client, const char *reason)
c41787e8c3f4 Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
544 {
1148
b5b172ab0ed9 Make sure calling client_destroy() multiple times doesn't break anything.
Timo Sirainen <tss@iki.fi>
parents: 1117
diff changeset
545 if (client->destroyed)
b5b172ab0ed9 Make sure calling client_destroy() multiple times doesn't break anything.
Timo Sirainen <tss@iki.fi>
parents: 1117
diff changeset
546 return;
b5b172ab0ed9 Make sure calling client_destroy() multiple times doesn't break anything.
Timo Sirainen <tss@iki.fi>
parents: 1117
diff changeset
547 client->destroyed = TRUE;
b5b172ab0ed9 Make sure calling client_destroy() multiple times doesn't break anything.
Timo Sirainen <tss@iki.fi>
parents: 1117
diff changeset
548
7438
65fbb6226141 Log clearly with "auth failed, # attempts" if user gets disconnected before
Timo Sirainen <tss@iki.fi>
parents: 7137
diff changeset
549 if (!client->login_success && reason != NULL) {
8302
0db37acdc59f Login process: Log auth failure reasons better in disconnect message.
Timo Sirainen <tss@iki.fi>
parents: 8106
diff changeset
550 reason = t_strconcat(reason, " ",
0db37acdc59f Login process: Log auth failure reasons better in disconnect message.
Timo Sirainen <tss@iki.fi>
parents: 8106
diff changeset
551 client_get_extra_disconnect_reason(&client->common),
0db37acdc59f Login process: Log auth failure reasons better in disconnect message.
Timo Sirainen <tss@iki.fi>
parents: 8106
diff changeset
552 NULL);
7438
65fbb6226141 Log clearly with "auth failed, # attempts" if user gets disconnected before
Timo Sirainen <tss@iki.fi>
parents: 7137
diff changeset
553 }
1049
c41787e8c3f4 Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
554 if (reason != NULL)
3384
3b75956d20c4 Added configurable logging for login process. Added configurable pop3 logout
Timo Sirainen <tss@iki.fi>
parents: 3360
diff changeset
555 client_syslog(&client->common, reason);
1049
c41787e8c3f4 Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
556
7101
09556a64b4e5 Use a linked list to keep track of all clients instead of a hash table.
Timo Sirainen <tss@iki.fi>
parents: 7099
diff changeset
557 client_unlink(&client->common);
1049
c41787e8c3f4 Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
558
7927
2351a81ce699 If commands are pipelined after the login command, pass them to the
Timo Sirainen <tss@iki.fi>
parents: 7923
diff changeset
559 if (client->common.input != NULL)
2351a81ce699 If commands are pipelined after the login command, pass them to the
Timo Sirainen <tss@iki.fi>
parents: 7923
diff changeset
560 i_stream_close(client->common.input);
2768
d344be0bb70f Added IMAP and POP3 proxying support.
Timo Sirainen <tss@iki.fi>
parents: 2766
diff changeset
561 if (client->output != NULL)
d344be0bb70f Added IMAP and POP3 proxying support.
Timo Sirainen <tss@iki.fi>
parents: 2766
diff changeset
562 o_stream_close(client->output);
1049
c41787e8c3f4 Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
563
8985
f43bebab3dac imap/pop3 proxy: Support SSL/TLS connections to remote servers.
Timo Sirainen <tss@iki.fi>
parents: 8979
diff changeset
564 if (client->common.master_tag != 0) {
f43bebab3dac imap/pop3 proxy: Support SSL/TLS connections to remote servers.
Timo Sirainen <tss@iki.fi>
parents: 8979
diff changeset
565 i_assert(client->common.auth_request == NULL);
f43bebab3dac imap/pop3 proxy: Support SSL/TLS connections to remote servers.
Timo Sirainen <tss@iki.fi>
parents: 8979
diff changeset
566 i_assert(client->common.authenticating);
4790
c6d77f917d12 Fixed potential problems with client disconnecting while master was handling
Timo Sirainen <tss@iki.fi>
parents: 4771
diff changeset
567 master_request_abort(&client->common);
8985
f43bebab3dac imap/pop3 proxy: Support SSL/TLS connections to remote servers.
Timo Sirainen <tss@iki.fi>
parents: 8979
diff changeset
568 } else if (client->common.auth_request != NULL) {
4770
88c29111fcee Crashfixes and more asserts. Mostly related to use of AUTHENTICATE/AUTH
Timo Sirainen <tss@iki.fi>
parents: 4671
diff changeset
569 i_assert(client->common.authenticating);
9218
754234248510 login processes: Auth code cleanups. Custom IMAP auth errors now have [ALERT] prefix.
Timo Sirainen <tss@iki.fi>
parents: 9155
diff changeset
570 sasl_server_auth_abort(&client->common);
4770
88c29111fcee Crashfixes and more asserts. Mostly related to use of AUTHENTICATE/AUTH
Timo Sirainen <tss@iki.fi>
parents: 4671
diff changeset
571 } else {
88c29111fcee Crashfixes and more asserts. Mostly related to use of AUTHENTICATE/AUTH
Timo Sirainen <tss@iki.fi>
parents: 4671
diff changeset
572 i_assert(!client->common.authenticating);
1702
43815588dd6b Moved client side code for auth process handling to lib-auth. Some other login process cleanups.
Timo Sirainen <tss@iki.fi>
parents: 1591
diff changeset
573 }
43815588dd6b Moved client side code for auth process handling to lib-auth. Some other login process cleanups.
Timo Sirainen <tss@iki.fi>
parents: 1591
diff changeset
574
3879
928229f8b3e6 deinit, unref, destroy, close, free, etc. functions now take a pointer to
Timo Sirainen <tss@iki.fi>
parents: 3863
diff changeset
575 if (client->io != NULL)
928229f8b3e6 deinit, unref, destroy, close, free, etc. functions now take a pointer to
Timo Sirainen <tss@iki.fi>
parents: 3863
diff changeset
576 io_remove(&client->io);
7099
3f5b7bebfd82 Use separate per-client timeouts instead of going through all clients in one
Timo Sirainen <tss@iki.fi>
parents: 7086
diff changeset
577 if (client->to_idle_disconnect != NULL)
3f5b7bebfd82 Use separate per-client timeouts instead of going through all clients in one
Timo Sirainen <tss@iki.fi>
parents: 7086
diff changeset
578 timeout_remove(&client->to_idle_disconnect);
3f5b7bebfd82 Use separate per-client timeouts instead of going through all clients in one
Timo Sirainen <tss@iki.fi>
parents: 7086
diff changeset
579 if (client->to_auth_waiting != NULL)
3f5b7bebfd82 Use separate per-client timeouts instead of going through all clients in one
Timo Sirainen <tss@iki.fi>
parents: 7086
diff changeset
580 timeout_remove(&client->to_auth_waiting);
8574
1b744c38bcac Increase failed login's reply delay by 5 seconds for each failure.
Timo Sirainen <tss@iki.fi>
parents: 8546
diff changeset
581 if (client->to_authfail_delay != NULL)
1b744c38bcac Increase failed login's reply delay by 5 seconds for each failure.
Timo Sirainen <tss@iki.fi>
parents: 8546
diff changeset
582 timeout_remove(&client->to_authfail_delay);
1049
c41787e8c3f4 Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
583
1117
71c438e6a40f STARTTLS handshake failure fixes.
Timo Sirainen <tss@iki.fi>
parents: 1084
diff changeset
584 if (client->common.fd != -1) {
71c438e6a40f STARTTLS handshake failure fixes.
Timo Sirainen <tss@iki.fi>
parents: 1084
diff changeset
585 net_disconnect(client->common.fd);
71c438e6a40f STARTTLS handshake failure fixes.
Timo Sirainen <tss@iki.fi>
parents: 1084
diff changeset
586 client->common.fd = -1;
71c438e6a40f STARTTLS handshake failure fixes.
Timo Sirainen <tss@iki.fi>
parents: 1084
diff changeset
587 }
1049
c41787e8c3f4 Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
588
2837
0fe39d90ee15 another proxy crashfix
Timo Sirainen <tss@iki.fi>
parents: 2836
diff changeset
589 if (client->proxy_password != NULL) {
2773
e624a9ad6a30 More smart IMAP and POP3 proxies. Now if remote login fails, it just
Timo Sirainen <tss@iki.fi>
parents: 2768
diff changeset
590 safe_memset(client->proxy_password, 0,
e624a9ad6a30 More smart IMAP and POP3 proxies. Now if remote login fails, it just
Timo Sirainen <tss@iki.fi>
parents: 2768
diff changeset
591 strlen(client->proxy_password));
e624a9ad6a30 More smart IMAP and POP3 proxies. Now if remote login fails, it just
Timo Sirainen <tss@iki.fi>
parents: 2768
diff changeset
592 i_free(client->proxy_password);
e624a9ad6a30 More smart IMAP and POP3 proxies. Now if remote login fails, it just
Timo Sirainen <tss@iki.fi>
parents: 2768
diff changeset
593 client->proxy_password = NULL;
e624a9ad6a30 More smart IMAP and POP3 proxies. Now if remote login fails, it just
Timo Sirainen <tss@iki.fi>
parents: 2768
diff changeset
594 }
e624a9ad6a30 More smart IMAP and POP3 proxies. Now if remote login fails, it just
Timo Sirainen <tss@iki.fi>
parents: 2768
diff changeset
595
8546
50f49805b13b imap/pop3 proxy: Support master user logins.
Timo Sirainen <tss@iki.fi>
parents: 8302
diff changeset
596 i_free_and_null(client->proxy_user);
50f49805b13b imap/pop3 proxy: Support master user logins.
Timo Sirainen <tss@iki.fi>
parents: 8302
diff changeset
597 i_free_and_null(client->proxy_master_user);
8979
f8404c0f14de imap-proxy: Send backend's CAPABILITY if it's different from what was sent to client before.
Timo Sirainen <tss@iki.fi>
parents: 8891
diff changeset
598 i_free_and_null(client->proxy_backend_capability);
2836
42a86c987c78 crashfixes
Timo Sirainen <tss@iki.fi>
parents: 2790
diff changeset
599
8583
2ff2cac3578b imap/pop3-login: Cleaned up proxying code. Don't disconnect client on proxy failures.
Timo Sirainen <tss@iki.fi>
parents: 8577
diff changeset
600 if (client->proxy != NULL)
2ff2cac3578b imap/pop3-login: Cleaned up proxying code. Don't disconnect client on proxy failures.
Timo Sirainen <tss@iki.fi>
parents: 8577
diff changeset
601 login_proxy_free(&client->proxy);
2773
e624a9ad6a30 More smart IMAP and POP3 proxies. Now if remote login fails, it just
Timo Sirainen <tss@iki.fi>
parents: 2768
diff changeset
602
e624a9ad6a30 More smart IMAP and POP3 proxies. Now if remote login fails, it just
Timo Sirainen <tss@iki.fi>
parents: 2768
diff changeset
603 if (client->common.proxy != NULL) {
2027
dc5d0da1abe9 Added ssl_require_client_cert auth-specific setting. Hide
Timo Sirainen <tss@iki.fi>
parents: 1897
diff changeset
604 ssl_proxy_free(client->common.proxy);
2773
e624a9ad6a30 More smart IMAP and POP3 proxies. Now if remote login fails, it just
Timo Sirainen <tss@iki.fi>
parents: 2768
diff changeset
605 client->common.proxy = NULL;
e624a9ad6a30 More smart IMAP and POP3 proxies. Now if remote login fails, it just
Timo Sirainen <tss@iki.fi>
parents: 2768
diff changeset
606 }
1049
c41787e8c3f4 Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
607 client_unref(client);
4538
9d9e72374164 Fixes to login process handling, especially with
Timo Sirainen <tss@iki.fi>
parents: 4467
diff changeset
608
9d9e72374164 Fixes to login process handling, especially with
Timo Sirainen <tss@iki.fi>
parents: 4467
diff changeset
609 main_listen_start();
4671
830cee5ef3c0 Reference counting fix
Timo Sirainen <tss@iki.fi>
parents: 4669
diff changeset
610 main_unref();
1049
c41787e8c3f4 Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
611 }
c41787e8c3f4 Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
612
7438
65fbb6226141 Log clearly with "auth failed, # attempts" if user gets disconnected before
Timo Sirainen <tss@iki.fi>
parents: 7137
diff changeset
613 void client_destroy_success(struct imap_client *client, const char *reason)
65fbb6226141 Log clearly with "auth failed, # attempts" if user gets disconnected before
Timo Sirainen <tss@iki.fi>
parents: 7137
diff changeset
614 {
65fbb6226141 Log clearly with "auth failed, # attempts" if user gets disconnected before
Timo Sirainen <tss@iki.fi>
parents: 7137
diff changeset
615 client->login_success = TRUE;
65fbb6226141 Log clearly with "auth failed, # attempts" if user gets disconnected before
Timo Sirainen <tss@iki.fi>
parents: 7137
diff changeset
616 client_destroy(client, reason);
65fbb6226141 Log clearly with "auth failed, # attempts" if user gets disconnected before
Timo Sirainen <tss@iki.fi>
parents: 7137
diff changeset
617 }
65fbb6226141 Log clearly with "auth failed, # attempts" if user gets disconnected before
Timo Sirainen <tss@iki.fi>
parents: 7137
diff changeset
618
2768
d344be0bb70f Added IMAP and POP3 proxying support.
Timo Sirainen <tss@iki.fi>
parents: 2766
diff changeset
619 void client_destroy_internal_failure(struct imap_client *client)
d344be0bb70f Added IMAP and POP3 proxying support.
Timo Sirainen <tss@iki.fi>
parents: 2766
diff changeset
620 {
d344be0bb70f Added IMAP and POP3 proxying support.
Timo Sirainen <tss@iki.fi>
parents: 2766
diff changeset
621 client_send_line(client, "* BYE Internal login failure. "
d344be0bb70f Added IMAP and POP3 proxying support.
Timo Sirainen <tss@iki.fi>
parents: 2766
diff changeset
622 "Refer to server log for more information.");
3384
3b75956d20c4 Added configurable logging for login process. Added configurable pop3 logout
Timo Sirainen <tss@iki.fi>
parents: 3360
diff changeset
623 client_destroy(client, "Internal login failure");
2768
d344be0bb70f Added IMAP and POP3 proxying support.
Timo Sirainen <tss@iki.fi>
parents: 2766
diff changeset
624 }
d344be0bb70f Added IMAP and POP3 proxying support.
Timo Sirainen <tss@iki.fi>
parents: 2766
diff changeset
625
1714
96dab004a87a fixes. maybe it works now.
Timo Sirainen <tss@iki.fi>
parents: 1702
diff changeset
626 void client_ref(struct imap_client *client)
96dab004a87a fixes. maybe it works now.
Timo Sirainen <tss@iki.fi>
parents: 1702
diff changeset
627 {
96dab004a87a fixes. maybe it works now.
Timo Sirainen <tss@iki.fi>
parents: 1702
diff changeset
628 client->refcount++;
96dab004a87a fixes. maybe it works now.
Timo Sirainen <tss@iki.fi>
parents: 1702
diff changeset
629 }
96dab004a87a fixes. maybe it works now.
Timo Sirainen <tss@iki.fi>
parents: 1702
diff changeset
630
3863
55df57c028d4 Added "bool" type and changed all ints that were used as booleans to bool.
Timo Sirainen <tss@iki.fi>
parents: 3706
diff changeset
631 bool client_unref(struct imap_client *client)
1049
c41787e8c3f4 Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
632 {
3955
295af5c1cce6 If client disconnected while we were trying to send authentication
Timo Sirainen <tss@iki.fi>
parents: 3954
diff changeset
633 i_assert(client->refcount > 0);
1049
c41787e8c3f4 Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
634 if (--client->refcount > 0)
c41787e8c3f4 Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
635 return TRUE;
c41787e8c3f4 Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
636
3954
99ed24b66363 Added asserts
Timo Sirainen <tss@iki.fi>
parents: 3879
diff changeset
637 i_assert(client->destroyed);
99ed24b66363 Added asserts
Timo Sirainen <tss@iki.fi>
parents: 3879
diff changeset
638
3879
928229f8b3e6 deinit, unref, destroy, close, free, etc. functions now take a pointer to
Timo Sirainen <tss@iki.fi>
parents: 3863
diff changeset
639 imap_parser_destroy(&client->parser);
1281
043b71a06568 We didn't work at all in non-inetd mode. Also fix crash when quitting.
Timo Sirainen <tss@iki.fi>
parents: 1275
diff changeset
640
7927
2351a81ce699 If commands are pipelined after the login command, pass them to the
Timo Sirainen <tss@iki.fi>
parents: 7923
diff changeset
641 if (client->common.input != NULL)
2351a81ce699 If commands are pipelined after the login command, pass them to the
Timo Sirainen <tss@iki.fi>
parents: 7923
diff changeset
642 i_stream_unref(&client->common.input);
2768
d344be0bb70f Added IMAP and POP3 proxying support.
Timo Sirainen <tss@iki.fi>
parents: 2766
diff changeset
643 if (client->output != NULL)
3879
928229f8b3e6 deinit, unref, destroy, close, free, etc. functions now take a pointer to
Timo Sirainen <tss@iki.fi>
parents: 3863
diff changeset
644 o_stream_unref(&client->output);
1049
c41787e8c3f4 Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
645
1148
b5b172ab0ed9 Make sure calling client_destroy() multiple times doesn't break anything.
Timo Sirainen <tss@iki.fi>
parents: 1117
diff changeset
646 i_free(client->common.virtual_user);
2766
26a091f3add6 Implemented support for LOGIN-REFERRALS using "referral" and "reason"
Timo Sirainen <tss@iki.fi>
parents: 2733
diff changeset
647 i_free(client->common.auth_mech_name);
1049
c41787e8c3f4 Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
648 i_free(client);
c41787e8c3f4 Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
649
c41787e8c3f4 Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
650 return FALSE;
c41787e8c3f4 Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
651 }
c41787e8c3f4 Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
652
c41787e8c3f4 Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
653 void client_send_line(struct imap_client *client, const char *line)
c41787e8c3f4 Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
654 {
2421
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2097
diff changeset
655 struct const_iovec iov[2];
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2097
diff changeset
656 ssize_t ret;
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2097
diff changeset
657
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2097
diff changeset
658 iov[0].iov_base = line;
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2097
diff changeset
659 iov[0].iov_len = strlen(line);
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2097
diff changeset
660 iov[1].iov_base = "\r\n";
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2097
diff changeset
661 iov[1].iov_len = 2;
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2097
diff changeset
662
2901
872172ffd005 Don't destroy client structure immediately when sending line fails. Fixes some writes to freed memory.
Timo Sirainen <tss@iki.fi>
parents: 2837
diff changeset
663 ret = o_stream_sendv(client->output, iov, 2);
872172ffd005 Don't destroy client structure immediately when sending line fails. Fixes some writes to freed memory.
Timo Sirainen <tss@iki.fi>
parents: 2837
diff changeset
664 if (ret < 0 || (size_t)ret != iov[0].iov_len + iov[1].iov_len) {
872172ffd005 Don't destroy client structure immediately when sending line fails. Fixes some writes to freed memory.
Timo Sirainen <tss@iki.fi>
parents: 2837
diff changeset
665 /* either disconnection or buffer full. in either case we
872172ffd005 Don't destroy client structure immediately when sending line fails. Fixes some writes to freed memory.
Timo Sirainen <tss@iki.fi>
parents: 2837
diff changeset
666 want this connection destroyed. however destroying it here
872172ffd005 Don't destroy client structure immediately when sending line fails. Fixes some writes to freed memory.
Timo Sirainen <tss@iki.fi>
parents: 2837
diff changeset
667 might break things if client is still tried to be accessed
872172ffd005 Don't destroy client structure immediately when sending line fails. Fixes some writes to freed memory.
Timo Sirainen <tss@iki.fi>
parents: 2837
diff changeset
668 without being referenced.. */
7927
2351a81ce699 If commands are pipelined after the login command, pass them to the
Timo Sirainen <tss@iki.fi>
parents: 7923
diff changeset
669 i_stream_close(client->common.input);
2901
872172ffd005 Don't destroy client structure immediately when sending line fails. Fixes some writes to freed memory.
Timo Sirainen <tss@iki.fi>
parents: 2837
diff changeset
670 }
1049
c41787e8c3f4 Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
671 }
c41787e8c3f4 Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
672
c41787e8c3f4 Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
673 void client_send_tagline(struct imap_client *client, const char *line)
c41787e8c3f4 Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
674 {
c41787e8c3f4 Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
675 client_send_line(client, t_strconcat(client->cmd_tag, " ", line, NULL));
c41787e8c3f4 Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
676 }
c41787e8c3f4 Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
677
1702
43815588dd6b Moved client side code for auth process handling to lib-auth. Some other login process cleanups.
Timo Sirainen <tss@iki.fi>
parents: 1591
diff changeset
678 void clients_notify_auth_connected(void)
1275
af685269ead0 login: Wait until we're connected to auth process before executing command
Timo Sirainen <tss@iki.fi>
parents: 1235
diff changeset
679 {
7101
09556a64b4e5 Use a linked list to keep track of all clients instead of a hash table.
Timo Sirainen <tss@iki.fi>
parents: 7099
diff changeset
680 struct client *client;
1897
1e6ed8045f2b Changed hash_foreach() to iterator.
Timo Sirainen <tss@iki.fi>
parents: 1814
diff changeset
681
7101
09556a64b4e5 Use a linked list to keep track of all clients instead of a hash table.
Timo Sirainen <tss@iki.fi>
parents: 7099
diff changeset
682 for (client = clients; client != NULL; client = client->next) {
09556a64b4e5 Use a linked list to keep track of all clients instead of a hash table.
Timo Sirainen <tss@iki.fi>
parents: 7099
diff changeset
683 struct imap_client *imap_client = (struct imap_client *)client;
1275
af685269ead0 login: Wait until we're connected to auth process before executing command
Timo Sirainen <tss@iki.fi>
parents: 1235
diff changeset
684
7101
09556a64b4e5 Use a linked list to keep track of all clients instead of a hash table.
Timo Sirainen <tss@iki.fi>
parents: 7099
diff changeset
685 if (imap_client->to_auth_waiting != NULL)
09556a64b4e5 Use a linked list to keep track of all clients instead of a hash table.
Timo Sirainen <tss@iki.fi>
parents: 7099
diff changeset
686 timeout_remove(&imap_client->to_auth_waiting);
09556a64b4e5 Use a linked list to keep track of all clients instead of a hash table.
Timo Sirainen <tss@iki.fi>
parents: 7099
diff changeset
687 if (!imap_client->greeting_sent)
09556a64b4e5 Use a linked list to keep track of all clients instead of a hash table.
Timo Sirainen <tss@iki.fi>
parents: 7099
diff changeset
688 client_send_greeting(imap_client);
09556a64b4e5 Use a linked list to keep track of all clients instead of a hash table.
Timo Sirainen <tss@iki.fi>
parents: 7099
diff changeset
689 if (imap_client->input_blocked) {
09556a64b4e5 Use a linked list to keep track of all clients instead of a hash table.
Timo Sirainen <tss@iki.fi>
parents: 7099
diff changeset
690 imap_client->input_blocked = FALSE;
09556a64b4e5 Use a linked list to keep track of all clients instead of a hash table.
Timo Sirainen <tss@iki.fi>
parents: 7099
diff changeset
691 client_input(imap_client);
1897
1e6ed8045f2b Changed hash_foreach() to iterator.
Timo Sirainen <tss@iki.fi>
parents: 1814
diff changeset
692 }
1e6ed8045f2b Changed hash_foreach() to iterator.
Timo Sirainen <tss@iki.fi>
parents: 1814
diff changeset
693 }
1049
c41787e8c3f4 Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
694 }
c41787e8c3f4 Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
695
c41787e8c3f4 Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
696 void clients_destroy_all(void)
c41787e8c3f4 Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
697 {
8891
fbb2343b85d9 imap/pop3-login: Don't crash when shutting down and destroying clients.
Timo Sirainen <tss@iki.fi>
parents: 8590
diff changeset
698 struct client *client, *next;
1897
1e6ed8045f2b Changed hash_foreach() to iterator.
Timo Sirainen <tss@iki.fi>
parents: 1814
diff changeset
699
8891
fbb2343b85d9 imap/pop3-login: Don't crash when shutting down and destroying clients.
Timo Sirainen <tss@iki.fi>
parents: 8590
diff changeset
700 for (client = clients; client != NULL; client = next) {
7101
09556a64b4e5 Use a linked list to keep track of all clients instead of a hash table.
Timo Sirainen <tss@iki.fi>
parents: 7099
diff changeset
701 struct imap_client *imap_client = (struct imap_client *)client;
1897
1e6ed8045f2b Changed hash_foreach() to iterator.
Timo Sirainen <tss@iki.fi>
parents: 1814
diff changeset
702
8891
fbb2343b85d9 imap/pop3-login: Don't crash when shutting down and destroying clients.
Timo Sirainen <tss@iki.fi>
parents: 8590
diff changeset
703 next = client->next;
7101
09556a64b4e5 Use a linked list to keep track of all clients instead of a hash table.
Timo Sirainen <tss@iki.fi>
parents: 7099
diff changeset
704 client_destroy(imap_client, "Disconnected: Shutting down");
1897
1e6ed8045f2b Changed hash_foreach() to iterator.
Timo Sirainen <tss@iki.fi>
parents: 1814
diff changeset
705 }
1049
c41787e8c3f4 Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
706 }
7137
c33c87781ab4 Added clients_init() and clients_deinit() back (for Managesieve).
Timo Sirainen <tss@iki.fi>
parents: 7114
diff changeset
707
c33c87781ab4 Added clients_init() and clients_deinit() back (for Managesieve).
Timo Sirainen <tss@iki.fi>
parents: 7114
diff changeset
708 void clients_init(void)
c33c87781ab4 Added clients_init() and clients_deinit() back (for Managesieve).
Timo Sirainen <tss@iki.fi>
parents: 7114
diff changeset
709 {
c33c87781ab4 Added clients_init() and clients_deinit() back (for Managesieve).
Timo Sirainen <tss@iki.fi>
parents: 7114
diff changeset
710 /* Nothing to initialize for IMAP */
c33c87781ab4 Added clients_init() and clients_deinit() back (for Managesieve).
Timo Sirainen <tss@iki.fi>
parents: 7114
diff changeset
711 }
c33c87781ab4 Added clients_init() and clients_deinit() back (for Managesieve).
Timo Sirainen <tss@iki.fi>
parents: 7114
diff changeset
712
c33c87781ab4 Added clients_init() and clients_deinit() back (for Managesieve).
Timo Sirainen <tss@iki.fi>
parents: 7114
diff changeset
713 void clients_deinit(void)
c33c87781ab4 Added clients_init() and clients_deinit() back (for Managesieve).
Timo Sirainen <tss@iki.fi>
parents: 7114
diff changeset
714 {
c33c87781ab4 Added clients_init() and clients_deinit() back (for Managesieve).
Timo Sirainen <tss@iki.fi>
parents: 7114
diff changeset
715 clients_destroy_all();
c33c87781ab4 Added clients_init() and clients_deinit() back (for Managesieve).
Timo Sirainen <tss@iki.fi>
parents: 7114
diff changeset
716 }