Mercurial > dovecot > original-hg > dovecot-1.2
annotate src/imap-login/client.c @ 9658:8ba4253adc9b HEAD tip
*-login: SSL connections didn't get closed when the client got destroyed.
author | Timo Sirainen <tss@iki.fi> |
---|---|
date | Thu, 08 May 2014 16:41:29 +0300 |
parents | 00cd9aacd03c |
children |
rev | line source |
---|---|
9532
00cd9aacd03c
Updated copyright notices to include year 2010.
Timo Sirainen <tss@iki.fi>
parents:
9448
diff
changeset
|
1 /* Copyright (c) 2002-2010 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 | 33 oldest connections are disconnected. Since we have to go through all of the |
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 | 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 | 58 addr = net_ip2addr(&client->common.ip); |
59 if (addr == NULL) | |
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 { |
9448
ab32d7e2c0d6
imap-login: If imap_capability is set, show it in the banner instead of the default.
Timo Sirainen <tss@iki.fi>
parents:
9218
diff
changeset
|
96 const char *auths, *cap_str; |
1049
c41787e8c3f4
Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
97 |
9448
ab32d7e2c0d6
imap-login: If imap_capability is set, show it in the banner instead of the default.
Timo Sirainen <tss@iki.fi>
parents:
9218
diff
changeset
|
98 cap_str = full || capability_string_overridden ? capability_string : |
ab32d7e2c0d6
imap-login: If imap_capability is set, show it in the banner instead of the default.
Timo Sirainen <tss@iki.fi>
parents:
9218
diff
changeset
|
99 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 auths = client_authenticate_get_capabilities(client->common.secured); |
9448
ab32d7e2c0d6
imap-login: If imap_capability is set, show it in the banner instead of the default.
Timo Sirainen <tss@iki.fi>
parents:
9218
diff
changeset
|
101 return t_strconcat(cap_str, (ssl_initialized && !client->common.tls) ? |
2733
9b9d9c164a31
Login process cleanups. Share more authentication code between pop3/imap.
Timo Sirainen <tss@iki.fi>
parents:
2691
diff
changeset
|
102 " STARTTLS" : "", |
9b9d9c164a31
Login process cleanups. Share more authentication code between pop3/imap.
Timo Sirainen <tss@iki.fi>
parents:
2691
diff
changeset
|
103 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
|
104 " LOGINDISABLED" : "", auths, NULL); |
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 |
857f5f7b512b
Added login_greeting and login_greeting_capability settings.
Timo Sirainen <tss@iki.fi>
parents:
2421
diff
changeset
|
107 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
|
108 { |
9142
5ee5def4f0ff
imap-login: Using CAPABILITY command after STARTTLS shouldn't trigger CAPABILITY pushing workaround.
Timo Sirainen <tss@iki.fi>
parents:
8985
diff
changeset
|
109 /* 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
|
110 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
|
111 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
|
112 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
|
113 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
|
114 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
|
115 "* 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
|
116 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
|
117 return 1; |
1049
c41787e8c3f4
Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
118 } |
c41787e8c3f4
Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
119 |
2421
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2097
diff
changeset
|
120 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
|
121 { |
c41787e8c3f4
Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
122 int fd_ssl; |
c41787e8c3f4
Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
123 |
4560
507088c0d511
Fixes for handling near-full connection queues.
Timo Sirainen <tss@iki.fi>
parents:
4538
diff
changeset
|
124 client_ref(client); |
507088c0d511
Fixes for handling near-full connection queues.
Timo Sirainen <tss@iki.fi>
parents:
4538
diff
changeset
|
125 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
|
126 if (!client_unref(client) || client->destroyed) |
4560
507088c0d511
Fixes for handling near-full connection queues.
Timo Sirainen <tss@iki.fi>
parents:
4538
diff
changeset
|
127 return; |
507088c0d511
Fixes for handling near-full connection queues.
Timo Sirainen <tss@iki.fi>
parents:
4538
diff
changeset
|
128 |
2421
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2097
diff
changeset
|
129 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
|
130 &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
|
131 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
|
132 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
|
133 client_destroy(client, |
9d9e72374164
Fixes to login process handling, especially with
Timo Sirainen <tss@iki.fi>
parents:
4467
diff
changeset
|
134 "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
|
135 return; |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2097
diff
changeset
|
136 } |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2097
diff
changeset
|
137 |
9142
5ee5def4f0ff
imap-login: Using CAPABILITY command after STARTTLS shouldn't trigger CAPABILITY pushing workaround.
Timo Sirainen <tss@iki.fi>
parents:
8985
diff
changeset
|
138 client->starttls = TRUE; |
2733
9b9d9c164a31
Login process cleanups. Share more authentication code between pop3/imap.
Timo Sirainen <tss@iki.fi>
parents:
2691
diff
changeset
|
139 client->common.tls = TRUE; |
9b9d9c164a31
Login process cleanups. Share more authentication code between pop3/imap.
Timo Sirainen <tss@iki.fi>
parents:
2691
diff
changeset
|
140 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
|
141 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
|
142 |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2097
diff
changeset
|
143 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
|
144 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
|
145 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
|
146 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
|
147 |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2097
diff
changeset
|
148 /* 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
|
149 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
|
150 |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2097
diff
changeset
|
151 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
|
152 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
|
153 } |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2097
diff
changeset
|
154 |
4907
5b4c9b20eba0
Replaced void *context from a lot of callbacks with the actual context
Timo Sirainen <tss@iki.fi>
parents:
4903
diff
changeset
|
155 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
|
156 { |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2097
diff
changeset
|
157 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
|
158 |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2097
diff
changeset
|
159 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
|
160 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
|
161 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
|
162 } |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2097
diff
changeset
|
163 |
4124
e65a7848e9e4
Output flush handler wasn't unset after STARTTLS, which could have caused
Timo Sirainen <tss@iki.fi>
parents:
3955
diff
changeset
|
164 if (ret > 0) { |
4903
204d7edc7cdc
Added context parameter type safety checks for most callback APIs.
Timo Sirainen <tss@iki.fi>
parents:
4845
diff
changeset
|
165 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
|
166 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
|
167 } |
2790
02c0b8d532c2
Changed ostream's flush callback to have return value which can tell if
Timo Sirainen <tss@iki.fi>
parents:
2787
diff
changeset
|
168 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
|
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 |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2097
diff
changeset
|
171 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
|
172 { |
2733
9b9d9c164a31
Login process cleanups. Share more authentication code between pop3/imap.
Timo Sirainen <tss@iki.fi>
parents:
2691
diff
changeset
|
173 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
|
174 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
|
175 return 1; |
1049
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 |
c41787e8c3f4
Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
178 if (!ssl_initialized) { |
c41787e8c3f4
Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
179 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
|
180 return 1; |
1049
c41787e8c3f4
Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
181 } |
c41787e8c3f4
Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
182 |
2421
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 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
|
184 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
|
185 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
|
186 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
|
187 |
2421
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2097
diff
changeset
|
188 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
|
189 |
cb143fc37b58
Make sure corking is removed before calling ssl_proxy_new()
Timo Sirainen <tss@iki.fi>
parents:
3384
diff
changeset
|
190 /* uncork the old fd */ |
cb143fc37b58
Make sure corking is removed before calling ssl_proxy_new()
Timo Sirainen <tss@iki.fi>
parents:
3384
diff
changeset
|
191 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
|
192 |
3360 | 193 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
|
194 /* the buffer has to be flushed */ |
3360 | 195 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
|
196 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
|
197 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
|
198 } 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
|
199 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
|
200 } |
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
|
201 return 1; |
1049
c41787e8c3f4
Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
202 } |
c41787e8c3f4
Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
203 |
7920
3644883cf44e
Support transferring original IPs and ports through IMAP proxies.
Timo Sirainen <tss@iki.fi>
parents:
7917
diff
changeset
|
204 static void |
3644883cf44e
Support transferring original IPs and ports through IMAP proxies.
Timo Sirainen <tss@iki.fi>
parents:
7917
diff
changeset
|
205 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
|
206 { |
3644883cf44e
Support transferring original IPs and ports through IMAP proxies.
Timo Sirainen <tss@iki.fi>
parents:
7917
diff
changeset
|
207 const char *key, *value; |
3644883cf44e
Support transferring original IPs and ports through IMAP proxies.
Timo Sirainen <tss@iki.fi>
parents:
7917
diff
changeset
|
208 |
3644883cf44e
Support transferring original IPs and ports through IMAP proxies.
Timo Sirainen <tss@iki.fi>
parents:
7917
diff
changeset
|
209 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
|
210 return; |
3644883cf44e
Support transferring original IPs and ports through IMAP proxies.
Timo Sirainen <tss@iki.fi>
parents:
7917
diff
changeset
|
211 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
|
212 |
3644883cf44e
Support transferring original IPs and ports through IMAP proxies.
Timo Sirainen <tss@iki.fi>
parents:
7917
diff
changeset
|
213 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
|
214 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
|
215 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
|
216 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
|
217 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
|
218 (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
|
219 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
|
220 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
|
221 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
|
222 (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
|
223 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
|
224 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
|
225 args += 2; |
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 } |
3644883cf44e
Support transferring original IPs and ports through IMAP proxies.
Timo Sirainen <tss@iki.fi>
parents:
7917
diff
changeset
|
228 |
7917
ca2ff54ee9b4
Added support for IMAP ID extension.
Timo Sirainen <tss@iki.fi>
parents:
7438
diff
changeset
|
229 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
|
230 { |
ca2ff54ee9b4
Added support for IMAP ID extension.
Timo Sirainen <tss@iki.fi>
parents:
7438
diff
changeset
|
231 const char *env, *value; |
ca2ff54ee9b4
Added support for IMAP ID extension.
Timo Sirainen <tss@iki.fi>
parents:
7438
diff
changeset
|
232 |
ca2ff54ee9b4
Added support for IMAP ID extension.
Timo Sirainen <tss@iki.fi>
parents:
7438
diff
changeset
|
233 if (!client->id_logged) { |
ca2ff54ee9b4
Added support for IMAP ID extension.
Timo Sirainen <tss@iki.fi>
parents:
7438
diff
changeset
|
234 client->id_logged = TRUE; |
7920
3644883cf44e
Support transferring original IPs and ports through IMAP proxies.
Timo Sirainen <tss@iki.fi>
parents:
7917
diff
changeset
|
235 if (client->common.trusted) |
3644883cf44e
Support transferring original IPs and ports through IMAP proxies.
Timo Sirainen <tss@iki.fi>
parents:
7917
diff
changeset
|
236 client_update_info(client, args); |
3644883cf44e
Support transferring original IPs and ports through IMAP proxies.
Timo Sirainen <tss@iki.fi>
parents:
7917
diff
changeset
|
237 |
7917
ca2ff54ee9b4
Added support for IMAP ID extension.
Timo Sirainen <tss@iki.fi>
parents:
7438
diff
changeset
|
238 env = getenv("IMAP_ID_LOG"); |
ca2ff54ee9b4
Added support for IMAP ID extension.
Timo Sirainen <tss@iki.fi>
parents:
7438
diff
changeset
|
239 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
|
240 if (value != NULL) { |
ca2ff54ee9b4
Added support for IMAP ID extension.
Timo Sirainen <tss@iki.fi>
parents:
7438
diff
changeset
|
241 client_syslog(&client->common, |
ca2ff54ee9b4
Added support for IMAP ID extension.
Timo Sirainen <tss@iki.fi>
parents:
7438
diff
changeset
|
242 t_strdup_printf("ID sent: %s", value)); |
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 |
ca2ff54ee9b4
Added support for IMAP ID extension.
Timo Sirainen <tss@iki.fi>
parents:
7438
diff
changeset
|
246 env = getenv("IMAP_ID_SEND"); |
ca2ff54ee9b4
Added support for IMAP ID extension.
Timo Sirainen <tss@iki.fi>
parents:
7438
diff
changeset
|
247 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
|
248 imap_id_reply_generate(env))); |
ca2ff54ee9b4
Added support for IMAP ID extension.
Timo Sirainen <tss@iki.fi>
parents:
7438
diff
changeset
|
249 client_send_tagline(client, "OK ID completed."); |
ca2ff54ee9b4
Added support for IMAP ID extension.
Timo Sirainen <tss@iki.fi>
parents:
7438
diff
changeset
|
250 return 1; |
ca2ff54ee9b4
Added support for IMAP ID extension.
Timo Sirainen <tss@iki.fi>
parents:
7438
diff
changeset
|
251 } |
ca2ff54ee9b4
Added support for IMAP ID extension.
Timo Sirainen <tss@iki.fi>
parents:
7438
diff
changeset
|
252 |
1049
c41787e8c3f4
Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
253 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
|
254 { |
c41787e8c3f4
Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
255 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
|
256 return 1; |
1049
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 |
c41787e8c3f4
Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
259 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
|
260 { |
c41787e8c3f4
Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
261 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
|
262 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
|
263 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
|
264 return 1; |
1049
c41787e8c3f4
Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
265 } |
c41787e8c3f4
Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
266 |
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
|
267 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
|
268 { |
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_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
|
270 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
|
271 "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
|
272 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
|
273 } |
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
|
274 |
1049
c41787e8c3f4
Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
275 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
|
276 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
|
277 { |
2058
0a1755f79392
cleanup: str_*case(t_strdup_noconst(str)) -> t_str_*case(str)
Timo Sirainen <tss@iki.fi>
parents:
2027
diff
changeset
|
278 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
|
279 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
|
280 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
|
281 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
|
282 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
|
283 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
|
284 return cmd_capability(client); |
c41787e8c3f4
Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
285 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
|
286 return cmd_starttls(client); |
7917
ca2ff54ee9b4
Added support for IMAP ID extension.
Timo Sirainen <tss@iki.fi>
parents:
7438
diff
changeset
|
287 if (strcmp(cmd, "ID") == 0) |
ca2ff54ee9b4
Added support for IMAP ID extension.
Timo Sirainen <tss@iki.fi>
parents:
7438
diff
changeset
|
288 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
|
289 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
|
290 return cmd_noop(client); |
c41787e8c3f4
Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
291 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
|
292 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
|
293 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
|
294 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
|
295 |
2733
9b9d9c164a31
Login process cleanups. Share more authentication code between pop3/imap.
Timo Sirainen <tss@iki.fi>
parents:
2691
diff
changeset
|
296 return -1; |
1049
c41787e8c3f4
Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
297 } |
c41787e8c3f4
Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
298 |
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
|
299 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
|
300 { |
5835
d59ed6a31b66
Added more consts to imap-parser API
Timo Sirainen <tss@iki.fi>
parents:
5671
diff
changeset
|
301 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
|
302 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
|
303 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
|
304 bool fatal; |
1049
c41787e8c3f4
Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
305 |
2733
9b9d9c164a31
Login process cleanups. Share more authentication code between pop3/imap.
Timo Sirainen <tss@iki.fi>
parents:
2691
diff
changeset
|
306 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
|
307 |
1049
c41787e8c3f4
Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
308 if (client->cmd_finished) { |
c41787e8c3f4
Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
309 /* 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
|
310 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
|
311 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
|
312 client->cmd_tag = NULL; |
c41787e8c3f4
Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
313 client->cmd_name = NULL; |
c41787e8c3f4
Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
314 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
|
315 |
c41787e8c3f4
Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
316 /* remove \r\n */ |
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) { |
c41787e8c3f4
Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
318 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
|
319 return FALSE; |
1049
c41787e8c3f4
Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
320 client->skip_line = FALSE; |
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 |
c41787e8c3f4
Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
323 client->cmd_finished = FALSE; |
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 |
c41787e8c3f4
Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
326 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
|
327 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
|
328 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
|
329 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
|
330 } |
c41787e8c3f4
Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
331 |
c41787e8c3f4
Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
332 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
|
333 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
|
334 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
|
335 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
|
336 } |
c41787e8c3f4
Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
337 |
c41787e8c3f4
Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
338 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
|
339 case -1: |
c41787e8c3f4
Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
340 /* 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
|
341 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
|
342 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
|
343 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
|
344 msg, NULL)); |
7438
65fbb6226141
Log clearly with "auth failed, # attempts" if user gets disconnected before
Timo Sirainen <tss@iki.fi>
parents:
7137
diff
changeset
|
345 client_destroy(client, |
65fbb6226141
Log clearly with "auth failed, # attempts" if user gets disconnected before
Timo Sirainen <tss@iki.fi>
parents:
7137
diff
changeset
|
346 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
|
347 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
|
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 |
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_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
|
351 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
|
352 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
|
353 return TRUE; |
1049
c41787e8c3f4
Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
354 case -2: |
c41787e8c3f4
Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
355 /* 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
|
356 return FALSE; |
1049
c41787e8c3f4
Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
357 } |
7927
2351a81ce699
If commands are pipelined after the login command, pass them to the
Timo Sirainen <tss@iki.fi>
parents:
7923
diff
changeset
|
358 /* 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
|
359 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
|
360 i_unreached(); |
1049
c41787e8c3f4
Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
361 |
2733
9b9d9c164a31
Login process cleanups. Share more authentication code between pop3/imap.
Timo Sirainen <tss@iki.fi>
parents:
2691
diff
changeset
|
362 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
|
363 ret = -1; |
9b9d9c164a31
Login process cleanups. Share more authentication code between pop3/imap.
Timo Sirainen <tss@iki.fi>
parents:
2691
diff
changeset
|
364 else |
9b9d9c164a31
Login process cleanups. Share more authentication code between pop3/imap.
Timo Sirainen <tss@iki.fi>
parents:
2691
diff
changeset
|
365 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
|
366 |
9b9d9c164a31
Login process cleanups. Share more authentication code between pop3/imap.
Timo Sirainen <tss@iki.fi>
parents:
2691
diff
changeset
|
367 client->cmd_finished = TRUE; |
9b9d9c164a31
Login process cleanups. Share more authentication code between pop3/imap.
Timo Sirainen <tss@iki.fi>
parents:
2691
diff
changeset
|
368 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
|
369 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
|
370 client->cmd_tag = "*"; |
1049
c41787e8c3f4
Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
371 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
|
372 client_send_line(client, |
c41787e8c3f4
Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
373 "* 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
|
374 client_destroy(client, |
65fbb6226141
Log clearly with "auth failed, # attempts" if user gets disconnected before
Timo Sirainen <tss@iki.fi>
parents:
7137
diff
changeset
|
375 "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
|
376 return FALSE; |
2733
9b9d9c164a31
Login process cleanups. Share more authentication code between pop3/imap.
Timo Sirainen <tss@iki.fi>
parents:
2691
diff
changeset
|
377 } |
1049
c41787e8c3f4
Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
378 client_send_tagline(client, |
c41787e8c3f4
Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
379 "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
|
380 } |
c41787e8c3f4
Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
381 |
2733
9b9d9c164a31
Login process cleanups. Share more authentication code between pop3/imap.
Timo Sirainen <tss@iki.fi>
parents:
2691
diff
changeset
|
382 return ret != 0; |
1049
c41787e8c3f4
Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
383 } |
c41787e8c3f4
Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
384 |
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
|
385 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
|
386 { |
7927
2351a81ce699
If commands are pipelined after the login command, pass them to the
Timo Sirainen <tss@iki.fi>
parents:
7923
diff
changeset
|
387 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
|
388 case -2: |
c41787e8c3f4
Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
389 /* buffer full */ |
c41787e8c3f4
Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
390 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
|
391 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
|
392 return FALSE; |
c41787e8c3f4
Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
393 case -1: |
c41787e8c3f4
Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
394 /* disconnected */ |
c41787e8c3f4
Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
395 client_destroy(client, "Disconnected"); |
c41787e8c3f4
Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
396 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
|
397 case 0: |
164569761647
login: Reset idle timeout only when input is actually read from client.
Timo Sirainen <tss@iki.fi>
parents:
8574
diff
changeset
|
398 /* 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
|
399 return TRUE; |
1049
c41787e8c3f4
Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
400 default: |
c41787e8c3f4
Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
401 /* 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
|
402 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
|
403 return TRUE; |
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 } |
c41787e8c3f4
Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
406 |
4907
5b4c9b20eba0
Replaced void *context from a lot of callbacks with the actual context
Timo Sirainen <tss@iki.fi>
parents:
4903
diff
changeset
|
407 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
|
408 { |
c41787e8c3f4
Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
409 if (!client_read(client)) |
c41787e8c3f4
Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
410 return; |
c41787e8c3f4
Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
411 |
2421
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2097
diff
changeset
|
412 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
|
413 |
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
|
414 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
|
415 /* 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
|
416 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
|
417 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
|
418 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
|
419 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
|
420 |
1275
af685269ead0
login: Wait until we're connected to auth process before executing command
Timo Sirainen <tss@iki.fi>
parents:
1235
diff
changeset
|
421 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
|
422 } else { |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2097
diff
changeset
|
423 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
|
424 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
|
425 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
|
426 } |
af685269ead0
login: Wait until we're connected to auth process before executing command
Timo Sirainen <tss@iki.fi>
parents:
1235
diff
changeset
|
427 |
2421
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2097
diff
changeset
|
428 client_unref(client); |
1049
c41787e8c3f4
Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
429 } |
c41787e8c3f4
Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
430 |
4560
507088c0d511
Fixes for handling near-full connection queues.
Timo Sirainen <tss@iki.fi>
parents:
4538
diff
changeset
|
431 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
|
432 { |
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
|
433 struct client *client; |
1897
1e6ed8045f2b
Changed hash_foreach() to iterator.
Timo Sirainen <tss@iki.fi>
parents:
1814
diff
changeset
|
434 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
|
435 unsigned int i, destroy_count; |
1897
1e6ed8045f2b
Changed hash_foreach() to iterator.
Timo Sirainen <tss@iki.fi>
parents:
1814
diff
changeset
|
436 |
1e6ed8045f2b
Changed hash_foreach() to iterator.
Timo Sirainen <tss@iki.fi>
parents:
1814
diff
changeset
|
437 /* 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
|
438 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
|
439 |
4538
9d9e72374164
Fixes to login process handling, especially with
Timo Sirainen <tss@iki.fi>
parents:
4467
diff
changeset
|
440 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
|
441 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
|
442 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
|
443 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
|
444 |
4538
9d9e72374164
Fixes to login process handling, especially with
Timo Sirainen <tss@iki.fi>
parents:
4467
diff
changeset
|
445 for (i = 0; i < destroy_count; i++) { |
1897
1e6ed8045f2b
Changed hash_foreach() to iterator.
Timo Sirainen <tss@iki.fi>
parents:
1814
diff
changeset
|
446 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
|
447 destroy_buf[i]->created > imap_client->created) { |
1897
1e6ed8045f2b
Changed hash_foreach() to iterator.
Timo Sirainen <tss@iki.fi>
parents:
1814
diff
changeset
|
448 /* @UNSAFE */ |
1e6ed8045f2b
Changed hash_foreach() to iterator.
Timo Sirainen <tss@iki.fi>
parents:
1814
diff
changeset
|
449 memmove(destroy_buf+i+1, destroy_buf+i, |
1e6ed8045f2b
Changed hash_foreach() to iterator.
Timo Sirainen <tss@iki.fi>
parents:
1814
diff
changeset
|
450 sizeof(destroy_buf) - |
1e6ed8045f2b
Changed hash_foreach() to iterator.
Timo Sirainen <tss@iki.fi>
parents:
1814
diff
changeset
|
451 (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
|
452 destroy_buf[i] = imap_client; |
1897
1e6ed8045f2b
Changed hash_foreach() to iterator.
Timo Sirainen <tss@iki.fi>
parents:
1814
diff
changeset
|
453 break; |
1e6ed8045f2b
Changed hash_foreach() to iterator.
Timo Sirainen <tss@iki.fi>
parents:
1814
diff
changeset
|
454 } |
1049
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 |
c41787e8c3f4
Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
458 /* then kill them */ |
4538
9d9e72374164
Fixes to login process handling, especially with
Timo Sirainen <tss@iki.fi>
parents:
4467
diff
changeset
|
459 for (i = 0; i < destroy_count; i++) { |
1897
1e6ed8045f2b
Changed hash_foreach() to iterator.
Timo Sirainen <tss@iki.fi>
parents:
1814
diff
changeset
|
460 if (destroy_buf[i] == NULL) |
1e6ed8045f2b
Changed hash_foreach() to iterator.
Timo Sirainen <tss@iki.fi>
parents:
1814
diff
changeset
|
461 break; |
1049
c41787e8c3f4
Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
462 |
1897
1e6ed8045f2b
Changed hash_foreach() to iterator.
Timo Sirainen <tss@iki.fi>
parents:
1814
diff
changeset
|
463 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
|
464 "Disconnected: Connection queue full"); |
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 } |
c41787e8c3f4
Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
467 |
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
|
468 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
|
469 { |
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 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
|
471 |
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 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
|
473 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
|
474 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
|
475 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
|
476 |
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_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
|
478 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
|
479 } |
2422546e3c44
If capability is sent in greeting, don't send it before we have received
Timo Sirainen <tss@iki.fi>
parents:
3581
diff
changeset
|
480 |
7099
3f5b7bebfd82
Use separate per-client timeouts instead of going through all clients in one
Timo Sirainen <tss@iki.fi>
parents:
7086
diff
changeset
|
481 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
|
482 { |
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_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
|
484 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
|
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 |
3f5b7bebfd82
Use separate per-client timeouts instead of going through all clients in one
Timo Sirainen <tss@iki.fi>
parents:
7086
diff
changeset
|
487 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
|
488 { |
3f5b7bebfd82
Use separate per-client timeouts instead of going through all clients in one
Timo Sirainen <tss@iki.fi>
parents:
7086
diff
changeset
|
489 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
|
490 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
|
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 |
3f5b7bebfd82
Use separate per-client timeouts instead of going through all clients in one
Timo Sirainen <tss@iki.fi>
parents:
7086
diff
changeset
|
493 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
|
494 { |
3f5b7bebfd82
Use separate per-client timeouts instead of going through all clients in one
Timo Sirainen <tss@iki.fi>
parents:
7086
diff
changeset
|
495 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
|
496 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
|
497 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
|
498 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
|
499 } |
3f5b7bebfd82
Use separate per-client timeouts instead of going through all clients in one
Timo Sirainen <tss@iki.fi>
parents:
7086
diff
changeset
|
500 |
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
|
501 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
|
502 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
|
503 { |
c41787e8c3f4
Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
504 struct imap_client *client; |
c41787e8c3f4
Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
505 |
4664 | 506 i_assert(fd != -1); |
507 | |
4560
507088c0d511
Fixes for handling near-full connection queues.
Timo Sirainen <tss@iki.fi>
parents:
4538
diff
changeset
|
508 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
|
509 |
c41787e8c3f4
Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
510 /* 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
|
511 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
|
512 |
c41787e8c3f4
Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
513 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
|
514 client->created = ioloop_time; |
c41787e8c3f4
Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
515 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
|
516 |
2097
4e77cb0aff21
Added %l, %r and %P variables and mail_log_prefix setting.
Timo Sirainen <tss@iki.fi>
parents:
2088
diff
changeset
|
517 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
|
518 client->common.ip = *ip; |
c41787e8c3f4
Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
519 client->common.fd = fd; |
7920
3644883cf44e
Support transferring original IPs and ports through IMAP proxies.
Timo Sirainen <tss@iki.fi>
parents:
7917
diff
changeset
|
520 client->common.tls = ssl; |
3644883cf44e
Support transferring original IPs and ports through IMAP proxies.
Timo Sirainen <tss@iki.fi>
parents:
7917
diff
changeset
|
521 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
|
522 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
|
523 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
|
524 |
3aece07f3a1b
STARTTLS commands crashed. imap-login STARTTLS also ignored next command.
Timo Sirainen <tss@iki.fi>
parents:
1049
diff
changeset
|
525 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
|
526 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
|
527 |
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
|
528 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
|
529 |
c41787e8c3f4
Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
530 main_ref(); |
c41787e8c3f4
Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
531 |
7922
4b4d2a4423ec
Removed login_greeting_capability setting. Instead now a minimal pre-login
Timo Sirainen <tss@iki.fi>
parents:
7921
diff
changeset
|
532 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
|
533 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
|
534 else |
3f5b7bebfd82
Use separate per-client timeouts instead of going through all clients in one
Timo Sirainen <tss@iki.fi>
parents:
7086
diff
changeset
|
535 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
|
536 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
|
537 |
7099
3f5b7bebfd82
Use separate per-client timeouts instead of going through all clients in one
Timo Sirainen <tss@iki.fi>
parents:
7086
diff
changeset
|
538 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
|
539 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
|
540 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
|
541 return &client->common; |
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 |
c41787e8c3f4
Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
544 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
|
545 { |
1148
b5b172ab0ed9
Make sure calling client_destroy() multiple times doesn't break anything.
Timo Sirainen <tss@iki.fi>
parents:
1117
diff
changeset
|
546 if (client->destroyed) |
b5b172ab0ed9
Make sure calling client_destroy() multiple times doesn't break anything.
Timo Sirainen <tss@iki.fi>
parents:
1117
diff
changeset
|
547 return; |
b5b172ab0ed9
Make sure calling client_destroy() multiple times doesn't break anything.
Timo Sirainen <tss@iki.fi>
parents:
1117
diff
changeset
|
548 client->destroyed = TRUE; |
b5b172ab0ed9
Make sure calling client_destroy() multiple times doesn't break anything.
Timo Sirainen <tss@iki.fi>
parents:
1117
diff
changeset
|
549 |
7438
65fbb6226141
Log clearly with "auth failed, # attempts" if user gets disconnected before
Timo Sirainen <tss@iki.fi>
parents:
7137
diff
changeset
|
550 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
|
551 reason = t_strconcat(reason, " ", |
0db37acdc59f
Login process: Log auth failure reasons better in disconnect message.
Timo Sirainen <tss@iki.fi>
parents:
8106
diff
changeset
|
552 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
|
553 NULL); |
7438
65fbb6226141
Log clearly with "auth failed, # attempts" if user gets disconnected before
Timo Sirainen <tss@iki.fi>
parents:
7137
diff
changeset
|
554 } |
1049
c41787e8c3f4
Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
555 if (reason != NULL) |
3384
3b75956d20c4
Added configurable logging for login process. Added configurable pop3 logout
Timo Sirainen <tss@iki.fi>
parents:
3360
diff
changeset
|
556 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
|
557 |
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
|
558 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
|
559 |
9658
8ba4253adc9b
*-login: SSL connections didn't get closed when the client got destroyed.
Timo Sirainen <tss@iki.fi>
parents:
9532
diff
changeset
|
560 if (!client->login_success && client->common.proxy != NULL) |
8ba4253adc9b
*-login: SSL connections didn't get closed when the client got destroyed.
Timo Sirainen <tss@iki.fi>
parents:
9532
diff
changeset
|
561 ssl_proxy_destroy(client->common.proxy); |
7927
2351a81ce699
If commands are pipelined after the login command, pass them to the
Timo Sirainen <tss@iki.fi>
parents:
7923
diff
changeset
|
562 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
|
563 i_stream_close(client->common.input); |
2768
d344be0bb70f
Added IMAP and POP3 proxying support.
Timo Sirainen <tss@iki.fi>
parents:
2766
diff
changeset
|
564 if (client->output != NULL) |
d344be0bb70f
Added IMAP and POP3 proxying support.
Timo Sirainen <tss@iki.fi>
parents:
2766
diff
changeset
|
565 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
|
566 |
8985
f43bebab3dac
imap/pop3 proxy: Support SSL/TLS connections to remote servers.
Timo Sirainen <tss@iki.fi>
parents:
8979
diff
changeset
|
567 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
|
568 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
|
569 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
|
570 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
|
571 } 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
|
572 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
|
573 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
|
574 } else { |
88c29111fcee
Crashfixes and more asserts. Mostly related to use of AUTHENTICATE/AUTH
Timo Sirainen <tss@iki.fi>
parents:
4671
diff
changeset
|
575 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
|
576 } |
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
|
577 |
3879
928229f8b3e6
deinit, unref, destroy, close, free, etc. functions now take a pointer to
Timo Sirainen <tss@iki.fi>
parents:
3863
diff
changeset
|
578 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
|
579 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
|
580 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
|
581 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
|
582 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
|
583 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
|
584 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
|
585 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
|
586 |
1117
71c438e6a40f
STARTTLS handshake failure fixes.
Timo Sirainen <tss@iki.fi>
parents:
1084
diff
changeset
|
587 if (client->common.fd != -1) { |
71c438e6a40f
STARTTLS handshake failure fixes.
Timo Sirainen <tss@iki.fi>
parents:
1084
diff
changeset
|
588 net_disconnect(client->common.fd); |
71c438e6a40f
STARTTLS handshake failure fixes.
Timo Sirainen <tss@iki.fi>
parents:
1084
diff
changeset
|
589 client->common.fd = -1; |
71c438e6a40f
STARTTLS handshake failure fixes.
Timo Sirainen <tss@iki.fi>
parents:
1084
diff
changeset
|
590 } |
1049
c41787e8c3f4
Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
591 |
2837 | 592 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
|
593 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
|
594 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
|
595 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
|
596 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
|
597 } |
e624a9ad6a30
More smart IMAP and POP3 proxies. Now if remote login fails, it just
Timo Sirainen <tss@iki.fi>
parents:
2768
diff
changeset
|
598 |
8546
50f49805b13b
imap/pop3 proxy: Support master user logins.
Timo Sirainen <tss@iki.fi>
parents:
8302
diff
changeset
|
599 i_free_and_null(client->proxy_user); |
50f49805b13b
imap/pop3 proxy: Support master user logins.
Timo Sirainen <tss@iki.fi>
parents:
8302
diff
changeset
|
600 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
|
601 i_free_and_null(client->proxy_backend_capability); |
2836 | 602 |
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
|
603 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
|
604 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
|
605 |
e624a9ad6a30
More smart IMAP and POP3 proxies. Now if remote login fails, it just
Timo Sirainen <tss@iki.fi>
parents:
2768
diff
changeset
|
606 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
|
607 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
|
608 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
|
609 } |
1049
c41787e8c3f4
Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
610 client_unref(client); |
4538
9d9e72374164
Fixes to login process handling, especially with
Timo Sirainen <tss@iki.fi>
parents:
4467
diff
changeset
|
611 |
9d9e72374164
Fixes to login process handling, especially with
Timo Sirainen <tss@iki.fi>
parents:
4467
diff
changeset
|
612 main_listen_start(); |
4671 | 613 main_unref(); |
1049
c41787e8c3f4
Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
614 } |
c41787e8c3f4
Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
615 |
7438
65fbb6226141
Log clearly with "auth failed, # attempts" if user gets disconnected before
Timo Sirainen <tss@iki.fi>
parents:
7137
diff
changeset
|
616 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
|
617 { |
65fbb6226141
Log clearly with "auth failed, # attempts" if user gets disconnected before
Timo Sirainen <tss@iki.fi>
parents:
7137
diff
changeset
|
618 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
|
619 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
|
620 } |
65fbb6226141
Log clearly with "auth failed, # attempts" if user gets disconnected before
Timo Sirainen <tss@iki.fi>
parents:
7137
diff
changeset
|
621 |
2768
d344be0bb70f
Added IMAP and POP3 proxying support.
Timo Sirainen <tss@iki.fi>
parents:
2766
diff
changeset
|
622 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
|
623 { |
d344be0bb70f
Added IMAP and POP3 proxying support.
Timo Sirainen <tss@iki.fi>
parents:
2766
diff
changeset
|
624 client_send_line(client, "* BYE Internal login failure. " |
d344be0bb70f
Added IMAP and POP3 proxying support.
Timo Sirainen <tss@iki.fi>
parents:
2766
diff
changeset
|
625 "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
|
626 client_destroy(client, "Internal login failure"); |
2768
d344be0bb70f
Added IMAP and POP3 proxying support.
Timo Sirainen <tss@iki.fi>
parents:
2766
diff
changeset
|
627 } |
d344be0bb70f
Added IMAP and POP3 proxying support.
Timo Sirainen <tss@iki.fi>
parents:
2766
diff
changeset
|
628 |
1714 | 629 void client_ref(struct imap_client *client) |
630 { | |
631 client->refcount++; | |
632 } | |
633 | |
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
|
634 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
|
635 { |
3955
295af5c1cce6
If client disconnected while we were trying to send authentication
Timo Sirainen <tss@iki.fi>
parents:
3954
diff
changeset
|
636 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
|
637 if (--client->refcount > 0) |
c41787e8c3f4
Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
638 return TRUE; |
c41787e8c3f4
Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
639 |
3954 | 640 i_assert(client->destroyed); |
641 | |
3879
928229f8b3e6
deinit, unref, destroy, close, free, etc. functions now take a pointer to
Timo Sirainen <tss@iki.fi>
parents:
3863
diff
changeset
|
642 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
|
643 |
7927
2351a81ce699
If commands are pipelined after the login command, pass them to the
Timo Sirainen <tss@iki.fi>
parents:
7923
diff
changeset
|
644 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
|
645 i_stream_unref(&client->common.input); |
2768
d344be0bb70f
Added IMAP and POP3 proxying support.
Timo Sirainen <tss@iki.fi>
parents:
2766
diff
changeset
|
646 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
|
647 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
|
648 |
1148
b5b172ab0ed9
Make sure calling client_destroy() multiple times doesn't break anything.
Timo Sirainen <tss@iki.fi>
parents:
1117
diff
changeset
|
649 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
|
650 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
|
651 i_free(client); |
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 return FALSE; |
c41787e8c3f4
Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
654 } |
c41787e8c3f4
Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
655 |
c41787e8c3f4
Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
656 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
|
657 { |
2421
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2097
diff
changeset
|
658 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
|
659 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
|
660 |
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[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
|
662 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
|
663 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
|
664 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
|
665 |
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
|
666 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
|
667 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
|
668 /* 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
|
669 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
|
670 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
|
671 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
|
672 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
|
673 } |
1049
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 |
c41787e8c3f4
Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
676 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
|
677 { |
c41787e8c3f4
Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
678 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
|
679 } |
c41787e8c3f4
Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
680 |
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
|
681 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
|
682 { |
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
|
683 struct client *client; |
1897
1e6ed8045f2b
Changed hash_foreach() to iterator.
Timo Sirainen <tss@iki.fi>
parents:
1814
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 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
|
686 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
|
687 |
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
|
688 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
|
689 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
|
690 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
|
691 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
|
692 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
|
693 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
|
694 client_input(imap_client); |
1897
1e6ed8045f2b
Changed hash_foreach() to iterator.
Timo Sirainen <tss@iki.fi>
parents:
1814
diff
changeset
|
695 } |
1e6ed8045f2b
Changed hash_foreach() to iterator.
Timo Sirainen <tss@iki.fi>
parents:
1814
diff
changeset
|
696 } |
1049
c41787e8c3f4
Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
697 } |
c41787e8c3f4
Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
698 |
c41787e8c3f4
Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
699 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
|
700 { |
8891
fbb2343b85d9
imap/pop3-login: Don't crash when shutting down and destroying clients.
Timo Sirainen <tss@iki.fi>
parents:
8590
diff
changeset
|
701 struct client *client, *next; |
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 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
|
704 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
|
705 |
8891
fbb2343b85d9
imap/pop3-login: Don't crash when shutting down and destroying clients.
Timo Sirainen <tss@iki.fi>
parents:
8590
diff
changeset
|
706 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
|
707 client_destroy(imap_client, "Disconnected: Shutting down"); |
1897
1e6ed8045f2b
Changed hash_foreach() to iterator.
Timo Sirainen <tss@iki.fi>
parents:
1814
diff
changeset
|
708 } |
1049
c41787e8c3f4
Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
709 } |
7137
c33c87781ab4
Added clients_init() and clients_deinit() back (for Managesieve).
Timo Sirainen <tss@iki.fi>
parents:
7114
diff
changeset
|
710 |
c33c87781ab4
Added clients_init() and clients_deinit() back (for Managesieve).
Timo Sirainen <tss@iki.fi>
parents:
7114
diff
changeset
|
711 void clients_init(void) |
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 /* Nothing to initialize for IMAP */ |
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 |
c33c87781ab4
Added clients_init() and clients_deinit() back (for Managesieve).
Timo Sirainen <tss@iki.fi>
parents:
7114
diff
changeset
|
716 void clients_deinit(void) |
c33c87781ab4
Added clients_init() and clients_deinit() back (for Managesieve).
Timo Sirainen <tss@iki.fi>
parents:
7114
diff
changeset
|
717 { |
c33c87781ab4
Added clients_init() and clients_deinit() back (for Managesieve).
Timo Sirainen <tss@iki.fi>
parents:
7114
diff
changeset
|
718 clients_destroy_all(); |
c33c87781ab4
Added clients_init() and clients_deinit() back (for Managesieve).
Timo Sirainen <tss@iki.fi>
parents:
7114
diff
changeset
|
719 } |