Mercurial > dovecot > original-hg > dovecot-1.2
annotate src/pop3-login/client.c @ 7101:09556a64b4e5 HEAD
Use a linked list to keep track of all clients instead of a hash table.
author | Timo Sirainen <tss@iki.fi> |
---|---|
date | Fri, 04 Jan 2008 00:01:02 +0200 |
parents | 4c6364f99ff0 |
children | 75f4e7ce8151 |
rev | line source |
---|---|
7086
7ed926ed7aa4
Updated copyright notices to include year 2008.
Timo Sirainen <tss@iki.fi>
parents:
6992
diff
changeset
|
1 /* Copyright (c) 2002-2008 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" |
2622
033d2fd1cd38
Replaced timestamp in APOP challenge with 128 bits of randomness.
Timo Sirainen <tss@iki.fi>
parents:
2421
diff
changeset
|
4 #include "base64.h" |
1049
c41787e8c3f4
Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
5 #include "buffer.h" |
c41787e8c3f4
Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
6 #include "hash.h" |
c41787e8c3f4
Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
7 #include "ioloop.h" |
c41787e8c3f4
Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
8 #include "istream.h" |
c41787e8c3f4
Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
9 #include "ostream.h" |
2622
033d2fd1cd38
Replaced timestamp in APOP challenge with 128 bits of randomness.
Timo Sirainen <tss@iki.fi>
parents:
2421
diff
changeset
|
10 #include "randgen.h" |
1049
c41787e8c3f4
Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
11 #include "process-title.h" |
c41787e8c3f4
Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
12 #include "safe-memset.h" |
c41787e8c3f4
Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
13 #include "strescape.h" |
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:
1499
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" |
2773
e624a9ad6a30
More smart IMAP and POP3 proxies. Now if remote login fails, it just
Timo Sirainen <tss@iki.fi>
parents:
2768
diff
changeset
|
18 #include "pop3-proxy.h" |
2267
d2e186f716d8
Added APOP authentication for POP3. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
2097
diff
changeset
|
19 #include "hostpid.h" |
1049
c41787e8c3f4
Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
20 |
2421
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2289
diff
changeset
|
21 /* max. length of input command line (spec says 512), or max reply length in |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2289
diff
changeset
|
22 SASL authentication */ |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2289
diff
changeset
|
23 #define MAX_INBUF_SIZE 4096 |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2289
diff
changeset
|
24 |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2289
diff
changeset
|
25 /* 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:
2289
diff
changeset
|
26 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:
2289
diff
changeset
|
27 #define MAX_OUTBUF_SIZE 4096 |
1049
c41787e8c3f4
Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
28 |
7099
3f5b7bebfd82
Use separate per-client timeouts instead of going through all clients in one
Timo Sirainen <tss@iki.fi>
parents:
7086
diff
changeset
|
29 /* Disconnect client after idling this many milliseconds */ |
7100
4c6364f99ff0
Idle timeout should have been 180 seconds, not 180 milliseconds.
Timo Sirainen <tss@iki.fi>
parents:
7099
diff
changeset
|
30 #define CLIENT_LOGIN_IDLE_TIMEOUT_MSECS (3*60*1000) |
1049
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 /* 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
|
33 #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
|
34 |
c41787e8c3f4
Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
35 /* When max. number of simultaneous connections is reached, few of the |
c41787e8c3f4
Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
36 oldest connections are disconnected. Since we have to go through the whole |
c41787e8c3f4
Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
37 client hash, it's faster if we disconnect multiple clients. */ |
c41787e8c3f4
Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
38 #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
|
39 |
7099
3f5b7bebfd82
Use separate per-client timeouts instead of going through all clients in one
Timo Sirainen <tss@iki.fi>
parents:
7086
diff
changeset
|
40 #if CLIENT_LOGIN_IDLE_TIMEOUT_MSECS >= AUTH_REQUEST_TIMEOUT*1000 |
1083
f6ec28683512
auth: kill login connection if it leaves requests hanging too long.
Timo Sirainen <tss@iki.fi>
parents:
1079
diff
changeset
|
41 # error client idle timeout must be smaller than authentication timeout |
f6ec28683512
auth: kill login connection if it leaves requests hanging too long.
Timo Sirainen <tss@iki.fi>
parents:
1079
diff
changeset
|
42 #endif |
f6ec28683512
auth: kill login connection if it leaves requests hanging too long.
Timo Sirainen <tss@iki.fi>
parents:
1079
diff
changeset
|
43 |
3384
3b75956d20c4
Added configurable logging for login process. Added configurable pop3 logout
Timo Sirainen <tss@iki.fi>
parents:
3360
diff
changeset
|
44 const char *login_protocol = "POP3"; |
3b75956d20c4
Added configurable logging for login process. Added configurable pop3 logout
Timo Sirainen <tss@iki.fi>
parents:
3360
diff
changeset
|
45 |
1049
c41787e8c3f4
Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
46 static void client_set_title(struct pop3_client *client) |
c41787e8c3f4
Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
47 { |
1486 | 48 const char *addr; |
1049
c41787e8c3f4
Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
49 |
c41787e8c3f4
Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
50 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
|
51 return; |
c41787e8c3f4
Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
52 |
1486 | 53 addr = net_ip2addr(&client->common.ip); |
54 if (addr == NULL) | |
55 addr = "??"; | |
1049
c41787e8c3f4
Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
56 |
2763
ab14dffd0e91
tls/secured variables are in common client structure. Plaintext logins
Timo Sirainen <tss@iki.fi>
parents:
2733
diff
changeset
|
57 process_title_set(t_strdup_printf(client->common.tls ? |
ab14dffd0e91
tls/secured variables are in common client structure. Plaintext logins
Timo Sirainen <tss@iki.fi>
parents:
2733
diff
changeset
|
58 "[%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
|
59 } |
c41787e8c3f4
Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
60 |
1079
3aece07f3a1b
STARTTLS commands crashed. imap-login STARTTLS also ignored next command.
Timo Sirainen <tss@iki.fi>
parents:
1059
diff
changeset
|
61 static void client_open_streams(struct pop3_client *client, int fd) |
3aece07f3a1b
STARTTLS commands crashed. imap-login STARTTLS also ignored next command.
Timo Sirainen <tss@iki.fi>
parents:
1059
diff
changeset
|
62 { |
6162
896cc473c1f0
Renamed i_stream_create_file() to i_stream_create_fd().
Timo Sirainen <tss@iki.fi>
parents:
6161
diff
changeset
|
63 client->input = i_stream_create_fd(fd, 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
|
64 client->output = o_stream_create_fd(fd, MAX_OUTBUF_SIZE, FALSE); |
2421
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2289
diff
changeset
|
65 } |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2289
diff
changeset
|
66 |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2289
diff
changeset
|
67 static void client_start_tls(struct pop3_client *client) |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2289
diff
changeset
|
68 { |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2289
diff
changeset
|
69 int fd_ssl; |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2289
diff
changeset
|
70 |
4560
507088c0d511
Fixes for handling near-full connection queues.
Timo Sirainen <tss@iki.fi>
parents:
4538
diff
changeset
|
71 client_ref(client); |
507088c0d511
Fixes for handling near-full connection queues.
Timo Sirainen <tss@iki.fi>
parents:
4538
diff
changeset
|
72 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
|
73 if (!client_unref(client) || client->destroyed) |
4560
507088c0d511
Fixes for handling near-full connection queues.
Timo Sirainen <tss@iki.fi>
parents:
4538
diff
changeset
|
74 return; |
507088c0d511
Fixes for handling near-full connection queues.
Timo Sirainen <tss@iki.fi>
parents:
4538
diff
changeset
|
75 |
2421
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2289
diff
changeset
|
76 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:
2289
diff
changeset
|
77 &client->common.proxy); |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2289
diff
changeset
|
78 if (fd_ssl == -1) { |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2289
diff
changeset
|
79 client_send_line(client, "-ERR TLS initialization failed."); |
4538
9d9e72374164
Fixes to login process handling, especially with
Timo Sirainen <tss@iki.fi>
parents:
4467
diff
changeset
|
80 client_destroy(client, |
9d9e72374164
Fixes to login process handling, especially with
Timo Sirainen <tss@iki.fi>
parents:
4467
diff
changeset
|
81 "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:
2289
diff
changeset
|
82 return; |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2289
diff
changeset
|
83 } |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2289
diff
changeset
|
84 |
2763
ab14dffd0e91
tls/secured variables are in common client structure. Plaintext logins
Timo Sirainen <tss@iki.fi>
parents:
2733
diff
changeset
|
85 client->common.tls = TRUE; |
ab14dffd0e91
tls/secured variables are in common client structure. Plaintext logins
Timo Sirainen <tss@iki.fi>
parents:
2733
diff
changeset
|
86 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:
2289
diff
changeset
|
87 client_set_title(client); |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2289
diff
changeset
|
88 |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2289
diff
changeset
|
89 client->common.fd = fd_ssl; |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2289
diff
changeset
|
90 |
3879
928229f8b3e6
deinit, unref, destroy, close, free, etc. functions now take a pointer to
Timo Sirainen <tss@iki.fi>
parents:
3863
diff
changeset
|
91 i_stream_unref(&client->input); |
928229f8b3e6
deinit, unref, destroy, close, free, etc. functions now take a pointer to
Timo Sirainen <tss@iki.fi>
parents:
3863
diff
changeset
|
92 o_stream_unref(&client->output); |
2421
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2289
diff
changeset
|
93 |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2289
diff
changeset
|
94 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
|
95 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:
2289
diff
changeset
|
96 } |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2289
diff
changeset
|
97 |
4907
5b4c9b20eba0
Replaced void *context from a lot of callbacks with the actual context
Timo Sirainen <tss@iki.fi>
parents:
4903
diff
changeset
|
98 static int client_output_starttls(struct pop3_client *client) |
2421
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2289
diff
changeset
|
99 { |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2289
diff
changeset
|
100 int ret; |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2289
diff
changeset
|
101 |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2289
diff
changeset
|
102 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:
2289
diff
changeset
|
103 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:
2783
diff
changeset
|
104 return 1; |
2421
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2289
diff
changeset
|
105 } |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2289
diff
changeset
|
106 |
4125
5071c561c455
Same STARTTLS flush callback fix as with imap-login.
Timo Sirainen <tss@iki.fi>
parents:
3955
diff
changeset
|
107 if (ret > 0) { |
4903
204d7edc7cdc
Added context parameter type safety checks for most callback APIs.
Timo Sirainen <tss@iki.fi>
parents:
4845
diff
changeset
|
108 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:
2289
diff
changeset
|
109 client_start_tls(client); |
4125
5071c561c455
Same STARTTLS flush callback fix as with imap-login.
Timo Sirainen <tss@iki.fi>
parents:
3955
diff
changeset
|
110 } |
2790
02c0b8d532c2
Changed ostream's flush callback to have return value which can tell if
Timo Sirainen <tss@iki.fi>
parents:
2783
diff
changeset
|
111 return 1; |
1079
3aece07f3a1b
STARTTLS commands crashed. imap-login STARTTLS also ignored next command.
Timo Sirainen <tss@iki.fi>
parents:
1059
diff
changeset
|
112 } |
3aece07f3a1b
STARTTLS commands crashed. imap-login STARTTLS also ignored next command.
Timo Sirainen <tss@iki.fi>
parents:
1059
diff
changeset
|
113 |
3863
55df57c028d4
Added "bool" type and changed all ints that were used as booleans to bool.
Timo Sirainen <tss@iki.fi>
parents:
3581
diff
changeset
|
114 static bool cmd_stls(struct pop3_client *client) |
1049
c41787e8c3f4
Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
115 { |
2763
ab14dffd0e91
tls/secured variables are in common client structure. Plaintext logins
Timo Sirainen <tss@iki.fi>
parents:
2733
diff
changeset
|
116 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
|
117 client_send_line(client, "-ERR TLS is already active."); |
c41787e8c3f4
Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
118 return TRUE; |
c41787e8c3f4
Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
119 } |
c41787e8c3f4
Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
120 |
c41787e8c3f4
Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
121 if (!ssl_initialized) { |
c41787e8c3f4
Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
122 client_send_line(client, "-ERR TLS support isn't enabled."); |
c41787e8c3f4
Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
123 return TRUE; |
c41787e8c3f4
Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
124 } |
c41787e8c3f4
Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
125 |
2421
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2289
diff
changeset
|
126 /* 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:
2289
diff
changeset
|
127 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
|
128 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
|
129 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
|
130 |
2421
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2289
diff
changeset
|
131 client_send_line(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
|
132 |
cb143fc37b58
Make sure corking is removed before calling ssl_proxy_new()
Timo Sirainen <tss@iki.fi>
parents:
3384
diff
changeset
|
133 /* uncork the old fd */ |
cb143fc37b58
Make sure corking is removed before calling ssl_proxy_new()
Timo Sirainen <tss@iki.fi>
parents:
3384
diff
changeset
|
134 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
|
135 |
3360 | 136 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:
2289
diff
changeset
|
137 /* the buffer has to be flushed */ |
3360 | 138 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:
2289
diff
changeset
|
139 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:
2289
diff
changeset
|
140 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
|
141 } else { |
2421
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2289
diff
changeset
|
142 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
|
143 } |
c41787e8c3f4
Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
144 return TRUE; |
c41787e8c3f4
Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
145 } |
c41787e8c3f4
Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
146 |
3863
55df57c028d4
Added "bool" type and changed all ints that were used as booleans to bool.
Timo Sirainen <tss@iki.fi>
parents:
3581
diff
changeset
|
147 static bool cmd_quit(struct pop3_client *client) |
1049
c41787e8c3f4
Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
148 { |
c41787e8c3f4
Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
149 client_send_line(client, "+OK Logging out"); |
6992
249e6c711e8d
Instead of logging only "Aborted login", log also if client tried to use
Timo Sirainen <tss@iki.fi>
parents:
6940
diff
changeset
|
150 if (client->common.auth_tried_disabled_plaintext) { |
249e6c711e8d
Instead of logging only "Aborted login", log also if client tried to use
Timo Sirainen <tss@iki.fi>
parents:
6940
diff
changeset
|
151 client_destroy(client, "Aborted login " |
249e6c711e8d
Instead of logging only "Aborted login", log also if client tried to use
Timo Sirainen <tss@iki.fi>
parents:
6940
diff
changeset
|
152 "(tried to use disabled plaintext authentication)"); |
249e6c711e8d
Instead of logging only "Aborted login", log also if client tried to use
Timo Sirainen <tss@iki.fi>
parents:
6940
diff
changeset
|
153 } else { |
249e6c711e8d
Instead of logging only "Aborted login", log also if client tried to use
Timo Sirainen <tss@iki.fi>
parents:
6940
diff
changeset
|
154 client_destroy(client, t_strdup_printf( |
249e6c711e8d
Instead of logging only "Aborted login", log also if client tried to use
Timo Sirainen <tss@iki.fi>
parents:
6940
diff
changeset
|
155 "Aborted login (%u authentication attempts)", |
249e6c711e8d
Instead of logging only "Aborted login", log also if client tried to use
Timo Sirainen <tss@iki.fi>
parents:
6940
diff
changeset
|
156 client->common.auth_attempts)); |
249e6c711e8d
Instead of logging only "Aborted login", log also if client tried to use
Timo Sirainen <tss@iki.fi>
parents:
6940
diff
changeset
|
157 } |
1049
c41787e8c3f4
Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
158 return TRUE; |
c41787e8c3f4
Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
159 } |
c41787e8c3f4
Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
160 |
3863
55df57c028d4
Added "bool" type and changed all ints that were used as booleans to bool.
Timo Sirainen <tss@iki.fi>
parents:
3581
diff
changeset
|
161 static bool client_command_execute(struct pop3_client *client, const char *cmd, |
55df57c028d4
Added "bool" type and changed all ints that were used as booleans to bool.
Timo Sirainen <tss@iki.fi>
parents:
3581
diff
changeset
|
162 const char *args) |
1049
c41787e8c3f4
Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
163 { |
2058
0a1755f79392
cleanup: str_*case(t_strdup_noconst(str)) -> t_str_*case(str)
Timo Sirainen <tss@iki.fi>
parents:
2027
diff
changeset
|
164 cmd = t_str_ucase(cmd); |
1059
d805c2f1d6a9
Support for CAPA command (rfc2449).
Timo Sirainen <tss@iki.fi>
parents:
1054
diff
changeset
|
165 if (strcmp(cmd, "CAPA") == 0) |
d805c2f1d6a9
Support for CAPA command (rfc2449).
Timo Sirainen <tss@iki.fi>
parents:
1054
diff
changeset
|
166 return cmd_capa(client, args); |
1049
c41787e8c3f4
Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
167 if (strcmp(cmd, "USER") == 0) |
c41787e8c3f4
Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
168 return cmd_user(client, args); |
c41787e8c3f4
Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
169 if (strcmp(cmd, "PASS") == 0) |
c41787e8c3f4
Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
170 return cmd_pass(client, args); |
c41787e8c3f4
Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
171 if (strcmp(cmd, "AUTH") == 0) |
c41787e8c3f4
Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
172 return cmd_auth(client, args); |
2267
d2e186f716d8
Added APOP authentication for POP3. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
2097
diff
changeset
|
173 if (strcmp(cmd, "APOP") == 0) |
d2e186f716d8
Added APOP authentication for POP3. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
2097
diff
changeset
|
174 return cmd_apop(client, args); |
1049
c41787e8c3f4
Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
175 if (strcmp(cmd, "STLS") == 0) |
c41787e8c3f4
Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
176 return cmd_stls(client); |
c41787e8c3f4
Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
177 if (strcmp(cmd, "QUIT") == 0) |
c41787e8c3f4
Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
178 return cmd_quit(client); |
c41787e8c3f4
Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
179 |
1054
cd1ac4101adf
compile fix + complain about unknown commands
Timo Sirainen <tss@iki.fi>
parents:
1049
diff
changeset
|
180 client_send_line(client, "-ERR Unknown command."); |
1049
c41787e8c3f4
Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
181 return FALSE; |
c41787e8c3f4
Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
182 } |
c41787e8c3f4
Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
183 |
3863
55df57c028d4
Added "bool" type and changed all ints that were used as booleans to bool.
Timo Sirainen <tss@iki.fi>
parents:
3581
diff
changeset
|
184 bool client_read(struct pop3_client *client) |
1049
c41787e8c3f4
Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
185 { |
c41787e8c3f4
Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
186 switch (i_stream_read(client->input)) { |
c41787e8c3f4
Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
187 case -2: |
c41787e8c3f4
Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
188 /* buffer full */ |
c41787e8c3f4
Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
189 client_send_line(client, "-ERR Input line too long, aborting"); |
c41787e8c3f4
Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
190 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
|
191 return FALSE; |
c41787e8c3f4
Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
192 case -1: |
c41787e8c3f4
Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
193 /* disconnected */ |
c41787e8c3f4
Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
194 client_destroy(client, "Disconnected"); |
c41787e8c3f4
Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
195 return FALSE; |
c41787e8c3f4
Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
196 default: |
c41787e8c3f4
Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
197 /* something was read */ |
c41787e8c3f4
Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
198 return TRUE; |
c41787e8c3f4
Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
199 } |
c41787e8c3f4
Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
200 } |
c41787e8c3f4
Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
201 |
4907
5b4c9b20eba0
Replaced void *context from a lot of callbacks with the actual context
Timo Sirainen <tss@iki.fi>
parents:
4903
diff
changeset
|
202 void client_input(struct pop3_client *client) |
1049
c41787e8c3f4
Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
203 { |
c41787e8c3f4
Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
204 char *line, *args; |
c41787e8c3f4
Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
205 |
7099
3f5b7bebfd82
Use separate per-client timeouts instead of going through all clients in one
Timo Sirainen <tss@iki.fi>
parents:
7086
diff
changeset
|
206 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
|
207 |
c41787e8c3f4
Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
208 if (!client_read(client)) |
c41787e8c3f4
Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
209 return; |
c41787e8c3f4
Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
210 |
1714 | 211 client_ref(client); |
1049
c41787e8c3f4
Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
212 |
c41787e8c3f4
Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
213 o_stream_cork(client->output); |
c41787e8c3f4
Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
214 while (!client->output->closed && |
c41787e8c3f4
Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
215 (line = i_stream_next_line(client->input)) != NULL) { |
c41787e8c3f4
Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
216 args = strchr(line, ' '); |
4819 | 217 if (args != NULL) |
1049
c41787e8c3f4
Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
218 *args++ = '\0'; |
c41787e8c3f4
Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
219 |
4819 | 220 if (client_command_execute(client, line, |
221 args != NULL ? args : "")) | |
1049
c41787e8c3f4
Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
222 client->bad_counter = 0; |
c41787e8c3f4
Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
223 else 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
|
224 client_send_line(client, "-ERR Too many bad commands."); |
c41787e8c3f4
Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
225 client_destroy(client, |
c41787e8c3f4
Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
226 "Disconnected: Too many bad commands"); |
c41787e8c3f4
Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
227 } |
c41787e8c3f4
Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
228 } |
c41787e8c3f4
Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
229 |
c41787e8c3f4
Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
230 if (client_unref(client)) |
2421
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2289
diff
changeset
|
231 o_stream_uncork(client->output); |
1049
c41787e8c3f4
Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
232 } |
c41787e8c3f4
Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
233 |
4560
507088c0d511
Fixes for handling near-full connection queues.
Timo Sirainen <tss@iki.fi>
parents:
4538
diff
changeset
|
234 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
|
235 { |
7101
09556a64b4e5
Use a linked list to keep track of all clients instead of a hash table.
Timo Sirainen <tss@iki.fi>
parents:
7100
diff
changeset
|
236 struct client *client; |
1897
1e6ed8045f2b
Changed hash_foreach() to iterator.
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
237 struct pop3_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
|
238 unsigned int i, destroy_count; |
1897
1e6ed8045f2b
Changed hash_foreach() to iterator.
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
239 |
1e6ed8045f2b
Changed hash_foreach() to iterator.
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
240 /* find the oldest clients and put them to destroy-buffer */ |
1e6ed8045f2b
Changed hash_foreach() to iterator.
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
241 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
|
242 |
4538
9d9e72374164
Fixes to login process handling, especially with
Timo Sirainen <tss@iki.fi>
parents:
4467
diff
changeset
|
243 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
|
244 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:
7100
diff
changeset
|
245 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:
7100
diff
changeset
|
246 struct pop3_client *pop3_client = (struct pop3_client *)client; |
1049
c41787e8c3f4
Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
247 |
4538
9d9e72374164
Fixes to login process handling, especially with
Timo Sirainen <tss@iki.fi>
parents:
4467
diff
changeset
|
248 for (i = 0; i < destroy_count; i++) { |
1897
1e6ed8045f2b
Changed hash_foreach() to iterator.
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
249 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:
7100
diff
changeset
|
250 destroy_buf[i]->created > pop3_client->created) { |
1897
1e6ed8045f2b
Changed hash_foreach() to iterator.
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
251 /* @UNSAFE */ |
1e6ed8045f2b
Changed hash_foreach() to iterator.
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
252 memmove(destroy_buf+i+1, destroy_buf+i, |
1e6ed8045f2b
Changed hash_foreach() to iterator.
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
253 sizeof(destroy_buf) - |
1e6ed8045f2b
Changed hash_foreach() to iterator.
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
254 (i+1) * sizeof(struct pop3_client *)); |
7101
09556a64b4e5
Use a linked list to keep track of all clients instead of a hash table.
Timo Sirainen <tss@iki.fi>
parents:
7100
diff
changeset
|
255 destroy_buf[i] = pop3_client; |
1897
1e6ed8045f2b
Changed hash_foreach() to iterator.
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
256 break; |
1e6ed8045f2b
Changed hash_foreach() to iterator.
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
257 } |
1049
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 } |
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 /* then kill them */ |
4538
9d9e72374164
Fixes to login process handling, especially with
Timo Sirainen <tss@iki.fi>
parents:
4467
diff
changeset
|
262 for (i = 0; i < destroy_count; i++) { |
1897
1e6ed8045f2b
Changed hash_foreach() to iterator.
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
263 if (destroy_buf[i] == NULL) |
1e6ed8045f2b
Changed hash_foreach() to iterator.
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
264 break; |
1049
c41787e8c3f4
Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
265 |
1897
1e6ed8045f2b
Changed hash_foreach() to iterator.
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
266 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
|
267 "Disconnected: Connection queue full"); |
c41787e8c3f4
Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
268 } |
c41787e8c3f4
Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
269 } |
c41787e8c3f4
Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
270 |
2289 | 271 static char *get_apop_challenge(struct pop3_client *client) |
2267
d2e186f716d8
Added APOP authentication for POP3. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
2097
diff
changeset
|
272 { |
2289 | 273 struct auth_connect_id *id = &client->auth_id; |
2622
033d2fd1cd38
Replaced timestamp in APOP challenge with 128 bits of randomness.
Timo Sirainen <tss@iki.fi>
parents:
2421
diff
changeset
|
274 unsigned char buffer[16]; |
033d2fd1cd38
Replaced timestamp in APOP challenge with 128 bits of randomness.
Timo Sirainen <tss@iki.fi>
parents:
2421
diff
changeset
|
275 buffer_t *buf; |
2267
d2e186f716d8
Added APOP authentication for POP3. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
2097
diff
changeset
|
276 |
2289 | 277 if (!auth_client_reserve_connection(auth_client, "APOP", id)) |
2267
d2e186f716d8
Added APOP authentication for POP3. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
2097
diff
changeset
|
278 return NULL; |
d2e186f716d8
Added APOP authentication for POP3. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
2097
diff
changeset
|
279 |
2622
033d2fd1cd38
Replaced timestamp in APOP challenge with 128 bits of randomness.
Timo Sirainen <tss@iki.fi>
parents:
2421
diff
changeset
|
280 random_fill(buffer, sizeof(buffer)); |
033d2fd1cd38
Replaced timestamp in APOP challenge with 128 bits of randomness.
Timo Sirainen <tss@iki.fi>
parents:
2421
diff
changeset
|
281 buf = buffer_create_static_hard(pool_datastack_create(), |
033d2fd1cd38
Replaced timestamp in APOP challenge with 128 bits of randomness.
Timo Sirainen <tss@iki.fi>
parents:
2421
diff
changeset
|
282 MAX_BASE64_ENCODED_SIZE(sizeof(buffer)) + 1); |
033d2fd1cd38
Replaced timestamp in APOP challenge with 128 bits of randomness.
Timo Sirainen <tss@iki.fi>
parents:
2421
diff
changeset
|
283 base64_encode(buffer, sizeof(buffer), buf); |
033d2fd1cd38
Replaced timestamp in APOP challenge with 128 bits of randomness.
Timo Sirainen <tss@iki.fi>
parents:
2421
diff
changeset
|
284 buffer_append_c(buf, '\0'); |
033d2fd1cd38
Replaced timestamp in APOP challenge with 128 bits of randomness.
Timo Sirainen <tss@iki.fi>
parents:
2421
diff
changeset
|
285 |
6940
414c9d631a81
Replaced t_push/t_pop calls with T_FRAME*() macros.
Timo Sirainen <tss@iki.fi>
parents:
6475
diff
changeset
|
286 return i_strdup_printf("<%x.%x.%lx.%s@%s>", |
414c9d631a81
Replaced t_push/t_pop calls with T_FRAME*() macros.
Timo Sirainen <tss@iki.fi>
parents:
6475
diff
changeset
|
287 id->server_pid, id->connect_uid, |
414c9d631a81
Replaced t_push/t_pop calls with T_FRAME*() macros.
Timo Sirainen <tss@iki.fi>
parents:
6475
diff
changeset
|
288 (unsigned long)ioloop_time, |
414c9d631a81
Replaced t_push/t_pop calls with T_FRAME*() macros.
Timo Sirainen <tss@iki.fi>
parents:
6475
diff
changeset
|
289 (const char *)buf->data, my_hostname); |
2267
d2e186f716d8
Added APOP authentication for POP3. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
2097
diff
changeset
|
290 } |
d2e186f716d8
Added APOP authentication for POP3. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
2097
diff
changeset
|
291 |
2268
5bd7fa814d7f
If we're not connected to all auth sockets, wait before sending greeting so
Timo Sirainen <tss@iki.fi>
parents:
2267
diff
changeset
|
292 static void client_auth_ready(struct pop3_client *client) |
5bd7fa814d7f
If we're not connected to all auth sockets, wait before sending greeting so
Timo Sirainen <tss@iki.fi>
parents:
2267
diff
changeset
|
293 { |
2733
9b9d9c164a31
Login process cleanups. Share more authentication code between pop3/imap.
Timo Sirainen <tss@iki.fi>
parents:
2691
diff
changeset
|
294 client->io = io_add(client->common.fd, IO_READ, client_input, client); |
2268
5bd7fa814d7f
If we're not connected to all auth sockets, wait before sending greeting so
Timo Sirainen <tss@iki.fi>
parents:
2267
diff
changeset
|
295 |
2289 | 296 client->apop_challenge = get_apop_challenge(client); |
2674
857f5f7b512b
Added login_greeting and login_greeting_capability settings.
Timo Sirainen <tss@iki.fi>
parents:
2622
diff
changeset
|
297 client_send_line(client, t_strconcat("+OK ", greeting, |
4161
147d53a049ee
Add a space between POP3 greeting and APOP challenge
Timo Sirainen <tss@iki.fi>
parents:
4125
diff
changeset
|
298 client->apop_challenge != NULL ? |
147d53a049ee
Add a space between POP3 greeting and APOP challenge
Timo Sirainen <tss@iki.fi>
parents:
4125
diff
changeset
|
299 " " : NULL, |
2268
5bd7fa814d7f
If we're not connected to all auth sockets, wait before sending greeting so
Timo Sirainen <tss@iki.fi>
parents:
2267
diff
changeset
|
300 client->apop_challenge, NULL)); |
5bd7fa814d7f
If we're not connected to all auth sockets, wait before sending greeting so
Timo Sirainen <tss@iki.fi>
parents:
2267
diff
changeset
|
301 } |
5bd7fa814d7f
If we're not connected to all auth sockets, wait before sending greeting so
Timo Sirainen <tss@iki.fi>
parents:
2267
diff
changeset
|
302 |
7099
3f5b7bebfd82
Use separate per-client timeouts instead of going through all clients in one
Timo Sirainen <tss@iki.fi>
parents:
7086
diff
changeset
|
303 static void client_idle_disconnect_timeout(struct pop3_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
|
304 { |
3f5b7bebfd82
Use separate per-client timeouts instead of going through all clients in one
Timo Sirainen <tss@iki.fi>
parents:
7086
diff
changeset
|
305 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
|
306 } |
3f5b7bebfd82
Use separate per-client timeouts instead of going through all clients in one
Timo Sirainen <tss@iki.fi>
parents:
7086
diff
changeset
|
307 |
3863
55df57c028d4
Added "bool" type and changed all ints that were used as booleans to bool.
Timo Sirainen <tss@iki.fi>
parents:
3581
diff
changeset
|
308 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:
2058
diff
changeset
|
309 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
|
310 { |
c41787e8c3f4
Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
311 struct pop3_client *client; |
c41787e8c3f4
Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
312 |
4664 | 313 i_assert(fd != -1); |
314 | |
4560
507088c0d511
Fixes for handling near-full connection queues.
Timo Sirainen <tss@iki.fi>
parents:
4538
diff
changeset
|
315 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
|
316 |
c41787e8c3f4
Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
317 /* 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
|
318 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
|
319 |
c41787e8c3f4
Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
320 client = i_new(struct pop3_client, 1); |
c41787e8c3f4
Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
321 client->created = ioloop_time; |
c41787e8c3f4
Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
322 client->refcount = 1; |
2763
ab14dffd0e91
tls/secured variables are in common client structure. Plaintext logins
Timo Sirainen <tss@iki.fi>
parents:
2733
diff
changeset
|
323 client->common.tls = ssl; |
4467
eaab43f6f65f
Removed hardcoded 127.* and ::1 IP checks. Instead just check that local IP
Timo Sirainen <tss@iki.fi>
parents:
4161
diff
changeset
|
324 client->common.secured = ssl || net_ip_compare(ip, local_ip); |
1725
cc0690f92d96
disable_plaintext_auth defaults to yes now. ipv4 127.* and ipv6 ::1
Timo Sirainen <tss@iki.fi>
parents:
1714
diff
changeset
|
325 |
2097
4e77cb0aff21
Added %l, %r and %P variables and mail_log_prefix setting.
Timo Sirainen <tss@iki.fi>
parents:
2058
diff
changeset
|
326 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
|
327 client->common.ip = *ip; |
c41787e8c3f4
Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
328 client->common.fd = fd; |
1079
3aece07f3a1b
STARTTLS commands crashed. imap-login STARTTLS also ignored next command.
Timo Sirainen <tss@iki.fi>
parents:
1059
diff
changeset
|
329 client_open_streams(client, fd); |
7101
09556a64b4e5
Use a linked list to keep track of all clients instead of a hash table.
Timo Sirainen <tss@iki.fi>
parents:
7100
diff
changeset
|
330 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
|
331 |
c41787e8c3f4
Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
332 main_ref(); |
c41787e8c3f4
Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
333 |
2268
5bd7fa814d7f
If we're not connected to all auth sockets, wait before sending greeting so
Timo Sirainen <tss@iki.fi>
parents:
2267
diff
changeset
|
334 client->auth_connected = auth_client_is_connected(auth_client); |
5bd7fa814d7f
If we're not connected to all auth sockets, wait before sending greeting so
Timo Sirainen <tss@iki.fi>
parents:
2267
diff
changeset
|
335 if (client->auth_connected) |
5bd7fa814d7f
If we're not connected to all auth sockets, wait before sending greeting so
Timo Sirainen <tss@iki.fi>
parents:
2267
diff
changeset
|
336 client_auth_ready(client); |
1049
c41787e8c3f4
Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
337 client_set_title(client); |
5671
0021765627f3
Check idle timeouts only when there are clients connected.
Timo Sirainen <tss@iki.fi>
parents:
5360
diff
changeset
|
338 |
7099
3f5b7bebfd82
Use separate per-client timeouts instead of going through all clients in one
Timo Sirainen <tss@iki.fi>
parents:
7086
diff
changeset
|
339 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
|
340 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
|
341 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
|
342 return &client->common; |
c41787e8c3f4
Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
343 } |
c41787e8c3f4
Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
344 |
c41787e8c3f4
Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
345 void client_destroy(struct pop3_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
|
346 { |
1148
b5b172ab0ed9
Make sure calling client_destroy() multiple times doesn't break anything.
Timo Sirainen <tss@iki.fi>
parents:
1117
diff
changeset
|
347 if (client->destroyed) |
b5b172ab0ed9
Make sure calling client_destroy() multiple times doesn't break anything.
Timo Sirainen <tss@iki.fi>
parents:
1117
diff
changeset
|
348 return; |
b5b172ab0ed9
Make sure calling client_destroy() multiple times doesn't break anything.
Timo Sirainen <tss@iki.fi>
parents:
1117
diff
changeset
|
349 client->destroyed = TRUE; |
b5b172ab0ed9
Make sure calling client_destroy() multiple times doesn't break anything.
Timo Sirainen <tss@iki.fi>
parents:
1117
diff
changeset
|
350 |
1049
c41787e8c3f4
Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
351 if (reason != NULL) |
3384
3b75956d20c4
Added configurable logging for login process. Added configurable pop3 logout
Timo Sirainen <tss@iki.fi>
parents:
3360
diff
changeset
|
352 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
|
353 |
7101
09556a64b4e5
Use a linked list to keep track of all clients instead of a hash table.
Timo Sirainen <tss@iki.fi>
parents:
7100
diff
changeset
|
354 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
|
355 |
2783 | 356 if (client->input != NULL) |
357 i_stream_close(client->input); | |
358 if (client->output != NULL) | |
359 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
|
360 |
4790
c6d77f917d12
Fixed potential problems with client disconnecting while master was handling
Timo Sirainen <tss@iki.fi>
parents:
4771
diff
changeset
|
361 if (client->common.master_tag != 0) |
c6d77f917d12
Fixed potential problems with client disconnecting while master was handling
Timo Sirainen <tss@iki.fi>
parents:
4771
diff
changeset
|
362 master_request_abort(&client->common); |
c6d77f917d12
Fixed potential problems with client disconnecting while master was handling
Timo Sirainen <tss@iki.fi>
parents:
4771
diff
changeset
|
363 |
1702
43815588dd6b
Moved client side code for auth process handling to lib-auth. Some other login process cleanups.
Timo Sirainen <tss@iki.fi>
parents:
1499
diff
changeset
|
364 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
|
365 i_assert(client->common.authenticating); |
88c29111fcee
Crashfixes and more asserts. Mostly related to use of AUTHENTICATE/AUTH
Timo Sirainen <tss@iki.fi>
parents:
4671
diff
changeset
|
366 sasl_server_auth_client_error(&client->common, NULL); |
88c29111fcee
Crashfixes and more asserts. Mostly related to use of AUTHENTICATE/AUTH
Timo Sirainen <tss@iki.fi>
parents:
4671
diff
changeset
|
367 } else { |
88c29111fcee
Crashfixes and more asserts. Mostly related to use of AUTHENTICATE/AUTH
Timo Sirainen <tss@iki.fi>
parents:
4671
diff
changeset
|
368 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:
1499
diff
changeset
|
369 } |
43815588dd6b
Moved client side code for auth process handling to lib-auth. Some other login process cleanups.
Timo Sirainen <tss@iki.fi>
parents:
1499
diff
changeset
|
370 |
3879
928229f8b3e6
deinit, unref, destroy, close, free, etc. functions now take a pointer to
Timo Sirainen <tss@iki.fi>
parents:
3863
diff
changeset
|
371 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
|
372 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
|
373 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
|
374 timeout_remove(&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
|
375 |
2773
e624a9ad6a30
More smart IMAP and POP3 proxies. Now if remote login fails, it just
Timo Sirainen <tss@iki.fi>
parents:
2768
diff
changeset
|
376 if (client->common.fd != -1) { |
e624a9ad6a30
More smart IMAP and POP3 proxies. Now if remote login fails, it just
Timo Sirainen <tss@iki.fi>
parents:
2768
diff
changeset
|
377 net_disconnect(client->common.fd); |
e624a9ad6a30
More smart IMAP and POP3 proxies. Now if remote login fails, it just
Timo Sirainen <tss@iki.fi>
parents:
2768
diff
changeset
|
378 client->common.fd = -1; |
e624a9ad6a30
More smart IMAP and POP3 proxies. Now if remote login fails, it just
Timo Sirainen <tss@iki.fi>
parents:
2768
diff
changeset
|
379 } |
e624a9ad6a30
More smart IMAP and POP3 proxies. Now if remote login fails, it just
Timo Sirainen <tss@iki.fi>
parents:
2768
diff
changeset
|
380 |
2836 | 381 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
|
382 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
|
383 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
|
384 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
|
385 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
|
386 } |
e624a9ad6a30
More smart IMAP and POP3 proxies. Now if remote login fails, it just
Timo Sirainen <tss@iki.fi>
parents:
2768
diff
changeset
|
387 |
2836 | 388 i_free(client->proxy_user); |
389 client->proxy_user = NULL; | |
390 | |
2773
e624a9ad6a30
More smart IMAP and POP3 proxies. Now if remote login fails, it just
Timo Sirainen <tss@iki.fi>
parents:
2768
diff
changeset
|
391 if (client->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
|
392 login_proxy_free(client->proxy); |
e624a9ad6a30
More smart IMAP and POP3 proxies. Now if remote login fails, it just
Timo Sirainen <tss@iki.fi>
parents:
2768
diff
changeset
|
393 client->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
|
394 } |
1049
c41787e8c3f4
Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
395 |
4790
c6d77f917d12
Fixed potential problems with client disconnecting while master was handling
Timo Sirainen <tss@iki.fi>
parents:
4771
diff
changeset
|
396 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
|
397 ssl_proxy_free(client->common.proxy); |
4790
c6d77f917d12
Fixed potential problems with client disconnecting while master was handling
Timo Sirainen <tss@iki.fi>
parents:
4771
diff
changeset
|
398 client->common.proxy = NULL; |
c6d77f917d12
Fixed potential problems with client disconnecting while master was handling
Timo Sirainen <tss@iki.fi>
parents:
4771
diff
changeset
|
399 } |
1049
c41787e8c3f4
Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
400 client_unref(client); |
4538
9d9e72374164
Fixes to login process handling, especially with
Timo Sirainen <tss@iki.fi>
parents:
4467
diff
changeset
|
401 |
9d9e72374164
Fixes to login process handling, especially with
Timo Sirainen <tss@iki.fi>
parents:
4467
diff
changeset
|
402 main_listen_start(); |
4671 | 403 main_unref(); |
1049
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 |
2768
d344be0bb70f
Added IMAP and POP3 proxying support.
Timo Sirainen <tss@iki.fi>
parents:
2766
diff
changeset
|
406 void client_destroy_internal_failure(struct pop3_client *client) |
d344be0bb70f
Added IMAP and POP3 proxying support.
Timo Sirainen <tss@iki.fi>
parents:
2766
diff
changeset
|
407 { |
d344be0bb70f
Added IMAP and POP3 proxying support.
Timo Sirainen <tss@iki.fi>
parents:
2766
diff
changeset
|
408 client_send_line(client, "-ERR [IN-USE] Internal login failure. " |
d344be0bb70f
Added IMAP and POP3 proxying support.
Timo Sirainen <tss@iki.fi>
parents:
2766
diff
changeset
|
409 "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
|
410 client_destroy(client, "Internal login failure"); |
2768
d344be0bb70f
Added IMAP and POP3 proxying support.
Timo Sirainen <tss@iki.fi>
parents:
2766
diff
changeset
|
411 } |
d344be0bb70f
Added IMAP and POP3 proxying support.
Timo Sirainen <tss@iki.fi>
parents:
2766
diff
changeset
|
412 |
1714 | 413 void client_ref(struct pop3_client *client) |
414 { | |
415 client->refcount++; | |
416 } | |
417 | |
3863
55df57c028d4
Added "bool" type and changed all ints that were used as booleans to bool.
Timo Sirainen <tss@iki.fi>
parents:
3581
diff
changeset
|
418 bool client_unref(struct pop3_client *client) |
1049
c41787e8c3f4
Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
419 { |
3955
295af5c1cce6
If client disconnected while we were trying to send authentication
Timo Sirainen <tss@iki.fi>
parents:
3954
diff
changeset
|
420 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
|
421 if (--client->refcount > 0) |
c41787e8c3f4
Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
422 return TRUE; |
c41787e8c3f4
Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
423 |
3954 | 424 i_assert(client->destroyed); |
425 | |
2783 | 426 if (client->input != NULL) |
3879
928229f8b3e6
deinit, unref, destroy, close, free, etc. functions now take a pointer to
Timo Sirainen <tss@iki.fi>
parents:
3863
diff
changeset
|
427 i_stream_unref(&client->input); |
2783 | 428 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
|
429 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
|
430 |
2897
90697bb3c368
Username given in USER was was not freed when destroying client.
Timo Sirainen <tss@iki.fi>
parents:
2836
diff
changeset
|
431 i_free(client->last_user); |
2267
d2e186f716d8
Added APOP authentication for POP3. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
2097
diff
changeset
|
432 i_free(client->apop_challenge); |
1148
b5b172ab0ed9
Make sure calling client_destroy() multiple times doesn't break anything.
Timo Sirainen <tss@iki.fi>
parents:
1117
diff
changeset
|
433 i_free(client->common.virtual_user); |
2766
26a091f3add6
Implemented support for LOGIN-REFERRALS using "referral" and "reason"
Timo Sirainen <tss@iki.fi>
parents:
2763
diff
changeset
|
434 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
|
435 i_free(client); |
c41787e8c3f4
Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
436 |
c41787e8c3f4
Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
437 return FALSE; |
c41787e8c3f4
Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
438 } |
c41787e8c3f4
Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
439 |
c41787e8c3f4
Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
440 void client_send_line(struct pop3_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
|
441 { |
2421
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2289
diff
changeset
|
442 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:
2289
diff
changeset
|
443 ssize_t ret; |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2289
diff
changeset
|
444 |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2289
diff
changeset
|
445 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:
2289
diff
changeset
|
446 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:
2289
diff
changeset
|
447 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:
2289
diff
changeset
|
448 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:
2289
diff
changeset
|
449 |
2901
872172ffd005
Don't destroy client structure immediately when sending line fails. Fixes some writes to freed memory.
Timo Sirainen <tss@iki.fi>
parents:
2897
diff
changeset
|
450 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:
2897
diff
changeset
|
451 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:
2897
diff
changeset
|
452 /* 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:
2897
diff
changeset
|
453 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:
2897
diff
changeset
|
454 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:
2897
diff
changeset
|
455 without being referenced.. */ |
872172ffd005
Don't destroy client structure immediately when sending line fails. Fixes some writes to freed memory.
Timo Sirainen <tss@iki.fi>
parents:
2897
diff
changeset
|
456 i_stream_close(client->input); |
872172ffd005
Don't destroy client structure immediately when sending line fails. Fixes some writes to freed memory.
Timo Sirainen <tss@iki.fi>
parents:
2897
diff
changeset
|
457 } |
1049
c41787e8c3f4
Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
458 } |
c41787e8c3f4
Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
459 |
1702
43815588dd6b
Moved client side code for auth process handling to lib-auth. Some other login process cleanups.
Timo Sirainen <tss@iki.fi>
parents:
1499
diff
changeset
|
460 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
|
461 { |
7101
09556a64b4e5
Use a linked list to keep track of all clients instead of a hash table.
Timo Sirainen <tss@iki.fi>
parents:
7100
diff
changeset
|
462 struct client *client; |
1897
1e6ed8045f2b
Changed hash_foreach() to iterator.
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
463 |
7101
09556a64b4e5
Use a linked list to keep track of all clients instead of a hash table.
Timo Sirainen <tss@iki.fi>
parents:
7100
diff
changeset
|
464 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:
7100
diff
changeset
|
465 struct pop3_client *pop3_client = (struct pop3_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
|
466 |
7101
09556a64b4e5
Use a linked list to keep track of all clients instead of a hash table.
Timo Sirainen <tss@iki.fi>
parents:
7100
diff
changeset
|
467 if (!pop3_client->auth_connected) { |
09556a64b4e5
Use a linked list to keep track of all clients instead of a hash table.
Timo Sirainen <tss@iki.fi>
parents:
7100
diff
changeset
|
468 pop3_client->auth_connected = TRUE; |
09556a64b4e5
Use a linked list to keep track of all clients instead of a hash table.
Timo Sirainen <tss@iki.fi>
parents:
7100
diff
changeset
|
469 client_auth_ready(pop3_client); |
1897
1e6ed8045f2b
Changed hash_foreach() to iterator.
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
470 } |
1e6ed8045f2b
Changed hash_foreach() to iterator.
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
471 } |
1049
c41787e8c3f4
Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
472 } |
c41787e8c3f4
Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
473 |
c41787e8c3f4
Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
474 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
|
475 { |
7101
09556a64b4e5
Use a linked list to keep track of all clients instead of a hash table.
Timo Sirainen <tss@iki.fi>
parents:
7100
diff
changeset
|
476 struct client *client; |
1897
1e6ed8045f2b
Changed hash_foreach() to iterator.
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
477 |
7101
09556a64b4e5
Use a linked list to keep track of all clients instead of a hash table.
Timo Sirainen <tss@iki.fi>
parents:
7100
diff
changeset
|
478 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:
7100
diff
changeset
|
479 struct pop3_client *pop3_client = (struct pop3_client *)client; |
1897
1e6ed8045f2b
Changed hash_foreach() to iterator.
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
480 |
7101
09556a64b4e5
Use a linked list to keep track of all clients instead of a hash table.
Timo Sirainen <tss@iki.fi>
parents:
7100
diff
changeset
|
481 client_destroy(pop3_client, "Disconnected: Shutting down"); |
1897
1e6ed8045f2b
Changed hash_foreach() to iterator.
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
482 } |
1049
c41787e8c3f4
Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
483 } |