Mercurial > dovecot > core-2.2
annotate src/login-common/client-common.c @ 22955:812e5c961328
fts: Indexing virtual mailbox didn't always index the last mails
author | Timo Sirainen <timo.sirainen@dovecot.fi> |
---|---|
date | Thu, 03 May 2018 18:33:00 +0300 |
parents | cb108f786fb4 |
children |
rev | line source |
---|---|
22713
cb108f786fb4
Updated copyright notices to include the year 2018.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
22242
diff
changeset
|
1 /* Copyright (c) 2002-2018 Dovecot authors, see the included COPYING file */ |
2737 | 2 |
10549
9ae939146ff7
login-common: Renamed common.h to login-common.h
Timo Sirainen <tss@iki.fi>
parents:
10302
diff
changeset
|
3 #include "login-common.h" |
19572
8bb95d42e5ea
*-login: Allow plugins to hook into client allocation and add module-specific contexts to client.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
19552
diff
changeset
|
4 #include "array.h" |
3384
3b75956d20c4
Added configurable logging for login process. Added configurable pop3 logout
Timo Sirainen <tss@iki.fi>
parents:
2737
diff
changeset
|
5 #include "hostpid.h" |
7120
eb71cda96663
Use linked list macros for handling clients linked list.
Timo Sirainen <tss@iki.fi>
parents:
7117
diff
changeset
|
6 #include "llist.h" |
9756
e30495ae11de
*-login: Moved most of the common code to login-common.
Timo Sirainen <tss@iki.fi>
parents:
9283
diff
changeset
|
7 #include "istream.h" |
e30495ae11de
*-login: Moved most of the common code to login-common.
Timo Sirainen <tss@iki.fi>
parents:
9283
diff
changeset
|
8 #include "ostream.h" |
13539
1ff636720b9f
login: Added -R <dir> parameter to write pre-login rawlogs to given directory.
Timo Sirainen <tss@iki.fi>
parents:
13538
diff
changeset
|
9 #include "iostream-rawlog.h" |
9756
e30495ae11de
*-login: Moved most of the common code to login-common.
Timo Sirainen <tss@iki.fi>
parents:
9283
diff
changeset
|
10 #include "process-title.h" |
21741
ad2aa897a8d7
*-login: Change API for how login_plugins hook into client allocation.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
21722
diff
changeset
|
11 #include "hook-build.h" |
14302
5bbcf636bbeb
Added a "session ID" string for imap/pop3 connections, available in %{session} variable.
Timo Sirainen <tss@iki.fi>
parents:
14300
diff
changeset
|
12 #include "buffer.h" |
3384
3b75956d20c4
Added configurable logging for login process. Added configurable pop3 logout
Timo Sirainen <tss@iki.fi>
parents:
2737
diff
changeset
|
13 #include "str.h" |
21820
de6920764b89
imap-login: Move forward_fields updating code to login-common
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
21765
diff
changeset
|
14 #include "strescape.h" |
14302
5bbcf636bbeb
Added a "session ID" string for imap/pop3 connections, available in %{session} variable.
Timo Sirainen <tss@iki.fi>
parents:
14300
diff
changeset
|
15 #include "base64.h" |
3384
3b75956d20c4
Added configurable logging for login process. Added configurable pop3 logout
Timo Sirainen <tss@iki.fi>
parents:
2737
diff
changeset
|
16 #include "str-sanitize.h" |
9756
e30495ae11de
*-login: Moved most of the common code to login-common.
Timo Sirainen <tss@iki.fi>
parents:
9283
diff
changeset
|
17 #include "safe-memset.h" |
3384
3b75956d20c4
Added configurable logging for login process. Added configurable pop3 logout
Timo Sirainen <tss@iki.fi>
parents:
2737
diff
changeset
|
18 #include "var-expand.h" |
11257 | 19 #include "master-interface.h" |
9756
e30495ae11de
*-login: Moved most of the common code to login-common.
Timo Sirainen <tss@iki.fi>
parents:
9283
diff
changeset
|
20 #include "master-service.h" |
14840 | 21 #include "master-service-ssl-settings.h" |
9756
e30495ae11de
*-login: Moved most of the common code to login-common.
Timo Sirainen <tss@iki.fi>
parents:
9283
diff
changeset
|
22 #include "master-auth.h" |
e30495ae11de
*-login: Moved most of the common code to login-common.
Timo Sirainen <tss@iki.fi>
parents:
9283
diff
changeset
|
23 #include "auth-client.h" |
16555
2dd27b0e7e49
lib-sasl: Use dsasl_ prefix so we don't conflict with Cyrus SASL library.
Timo Sirainen <tss@iki.fi>
parents:
16487
diff
changeset
|
24 #include "dsasl-client.h" |
9756
e30495ae11de
*-login: Moved most of the common code to login-common.
Timo Sirainen <tss@iki.fi>
parents:
9283
diff
changeset
|
25 #include "login-proxy.h" |
4570
cbbe2377f591
If SSL/TLS handshake didn't finish, show "TLS handshaking" instead of "TLS"
Timo Sirainen <tss@iki.fi>
parents:
3863
diff
changeset
|
26 #include "ssl-proxy.h" |
2737 | 27 #include "client-common.h" |
28 | |
3384
3b75956d20c4
Added configurable logging for login process. Added configurable pop3 logout
Timo Sirainen <tss@iki.fi>
parents:
2737
diff
changeset
|
29 |
17351
7f6c5e27b908
treewide sparse cleanup - make single-unit-only data static
Phil Carmody <phil@dovecot.fi>
parents:
17334
diff
changeset
|
30 struct client *clients = NULL; |
7f6c5e27b908
treewide sparse cleanup - make single-unit-only data static
Phil Carmody <phil@dovecot.fi>
parents:
17334
diff
changeset
|
31 static struct client *last_client = NULL; |
8027
62cf70991cf2
extern/static fixes (from a sparse check by Diego Liziero)
Timo Sirainen <tss@iki.fi>
parents:
7920
diff
changeset
|
32 static unsigned int clients_count = 0; |
7104
db5f55daa002
Forgot from imap/pop3-login clients hash -> linked list commit.
Timo Sirainen <tss@iki.fi>
parents:
7086
diff
changeset
|
33 |
21741
ad2aa897a8d7
*-login: Change API for how login_plugins hook into client allocation.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
21722
diff
changeset
|
34 struct login_client_module_hooks { |
ad2aa897a8d7
*-login: Change API for how login_plugins hook into client allocation.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
21722
diff
changeset
|
35 struct module *module; |
ad2aa897a8d7
*-login: Change API for how login_plugins hook into client allocation.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
21722
diff
changeset
|
36 const struct login_client_hooks *hooks; |
ad2aa897a8d7
*-login: Change API for how login_plugins hook into client allocation.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
21722
diff
changeset
|
37 }; |
ad2aa897a8d7
*-login: Change API for how login_plugins hook into client allocation.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
21722
diff
changeset
|
38 |
ad2aa897a8d7
*-login: Change API for how login_plugins hook into client allocation.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
21722
diff
changeset
|
39 static ARRAY(struct login_client_module_hooks) module_hooks = ARRAY_INIT; |
ad2aa897a8d7
*-login: Change API for how login_plugins hook into client allocation.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
21722
diff
changeset
|
40 |
ad2aa897a8d7
*-login: Change API for how login_plugins hook into client allocation.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
21722
diff
changeset
|
41 void login_client_hooks_add(struct module *module, |
ad2aa897a8d7
*-login: Change API for how login_plugins hook into client allocation.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
21722
diff
changeset
|
42 const struct login_client_hooks *hooks) |
19572
8bb95d42e5ea
*-login: Allow plugins to hook into client allocation and add module-specific contexts to client.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
19552
diff
changeset
|
43 { |
21741
ad2aa897a8d7
*-login: Change API for how login_plugins hook into client allocation.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
21722
diff
changeset
|
44 struct login_client_module_hooks *hook; |
ad2aa897a8d7
*-login: Change API for how login_plugins hook into client allocation.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
21722
diff
changeset
|
45 |
ad2aa897a8d7
*-login: Change API for how login_plugins hook into client allocation.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
21722
diff
changeset
|
46 hook = array_append_space(&module_hooks); |
ad2aa897a8d7
*-login: Change API for how login_plugins hook into client allocation.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
21722
diff
changeset
|
47 hook->module = module; |
ad2aa897a8d7
*-login: Change API for how login_plugins hook into client allocation.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
21722
diff
changeset
|
48 hook->hooks = hooks; |
19572
8bb95d42e5ea
*-login: Allow plugins to hook into client allocation and add module-specific contexts to client.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
19552
diff
changeset
|
49 } |
21741
ad2aa897a8d7
*-login: Change API for how login_plugins hook into client allocation.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
21722
diff
changeset
|
50 |
ad2aa897a8d7
*-login: Change API for how login_plugins hook into client allocation.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
21722
diff
changeset
|
51 void login_client_hooks_remove(const struct login_client_hooks *hooks) |
ad2aa897a8d7
*-login: Change API for how login_plugins hook into client allocation.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
21722
diff
changeset
|
52 { |
ad2aa897a8d7
*-login: Change API for how login_plugins hook into client allocation.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
21722
diff
changeset
|
53 const struct login_client_module_hooks *module_hook; |
ad2aa897a8d7
*-login: Change API for how login_plugins hook into client allocation.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
21722
diff
changeset
|
54 unsigned int idx = UINT_MAX; |
19572
8bb95d42e5ea
*-login: Allow plugins to hook into client allocation and add module-specific contexts to client.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
19552
diff
changeset
|
55 |
21741
ad2aa897a8d7
*-login: Change API for how login_plugins hook into client allocation.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
21722
diff
changeset
|
56 array_foreach(&module_hooks, module_hook) { |
ad2aa897a8d7
*-login: Change API for how login_plugins hook into client allocation.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
21722
diff
changeset
|
57 if (module_hook->hooks == hooks) { |
ad2aa897a8d7
*-login: Change API for how login_plugins hook into client allocation.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
21722
diff
changeset
|
58 idx = array_foreach_idx(&module_hooks, module_hook); |
ad2aa897a8d7
*-login: Change API for how login_plugins hook into client allocation.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
21722
diff
changeset
|
59 break; |
ad2aa897a8d7
*-login: Change API for how login_plugins hook into client allocation.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
21722
diff
changeset
|
60 } |
ad2aa897a8d7
*-login: Change API for how login_plugins hook into client allocation.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
21722
diff
changeset
|
61 } |
ad2aa897a8d7
*-login: Change API for how login_plugins hook into client allocation.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
21722
diff
changeset
|
62 i_assert(idx != UINT_MAX); |
ad2aa897a8d7
*-login: Change API for how login_plugins hook into client allocation.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
21722
diff
changeset
|
63 |
ad2aa897a8d7
*-login: Change API for how login_plugins hook into client allocation.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
21722
diff
changeset
|
64 array_delete(&module_hooks, idx, 1); |
ad2aa897a8d7
*-login: Change API for how login_plugins hook into client allocation.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
21722
diff
changeset
|
65 } |
ad2aa897a8d7
*-login: Change API for how login_plugins hook into client allocation.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
21722
diff
changeset
|
66 |
ad2aa897a8d7
*-login: Change API for how login_plugins hook into client allocation.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
21722
diff
changeset
|
67 static void hook_login_client_allocated(struct client *client) |
19572
8bb95d42e5ea
*-login: Allow plugins to hook into client allocation and add module-specific contexts to client.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
19552
diff
changeset
|
68 { |
21741
ad2aa897a8d7
*-login: Change API for how login_plugins hook into client allocation.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
21722
diff
changeset
|
69 const struct login_client_module_hooks *module_hook; |
ad2aa897a8d7
*-login: Change API for how login_plugins hook into client allocation.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
21722
diff
changeset
|
70 struct hook_build_context *ctx; |
19572
8bb95d42e5ea
*-login: Allow plugins to hook into client allocation and add module-specific contexts to client.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
19552
diff
changeset
|
71 |
21741
ad2aa897a8d7
*-login: Change API for how login_plugins hook into client allocation.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
21722
diff
changeset
|
72 ctx = hook_build_init((void *)&client->v, sizeof(client->v)); |
ad2aa897a8d7
*-login: Change API for how login_plugins hook into client allocation.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
21722
diff
changeset
|
73 client->vlast = &client->v; |
ad2aa897a8d7
*-login: Change API for how login_plugins hook into client allocation.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
21722
diff
changeset
|
74 array_foreach(&module_hooks, module_hook) { |
ad2aa897a8d7
*-login: Change API for how login_plugins hook into client allocation.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
21722
diff
changeset
|
75 if (module_hook->hooks->client_allocated != NULL) T_BEGIN { |
ad2aa897a8d7
*-login: Change API for how login_plugins hook into client allocation.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
21722
diff
changeset
|
76 module_hook->hooks->client_allocated(client); |
ad2aa897a8d7
*-login: Change API for how login_plugins hook into client allocation.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
21722
diff
changeset
|
77 hook_build_update(ctx, client->vlast); |
ad2aa897a8d7
*-login: Change API for how login_plugins hook into client allocation.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
21722
diff
changeset
|
78 } T_END; |
ad2aa897a8d7
*-login: Change API for how login_plugins hook into client allocation.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
21722
diff
changeset
|
79 } |
ad2aa897a8d7
*-login: Change API for how login_plugins hook into client allocation.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
21722
diff
changeset
|
80 client->vlast = NULL; |
ad2aa897a8d7
*-login: Change API for how login_plugins hook into client allocation.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
21722
diff
changeset
|
81 hook_build_deinit(&ctx); |
19572
8bb95d42e5ea
*-login: Allow plugins to hook into client allocation and add module-specific contexts to client.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
19552
diff
changeset
|
82 } |
8bb95d42e5ea
*-login: Allow plugins to hook into client allocation and add module-specific contexts to client.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
19552
diff
changeset
|
83 |
9756
e30495ae11de
*-login: Moved most of the common code to login-common.
Timo Sirainen <tss@iki.fi>
parents:
9283
diff
changeset
|
84 static void client_idle_disconnect_timeout(struct client *client) |
e30495ae11de
*-login: Moved most of the common code to login-common.
Timo Sirainen <tss@iki.fi>
parents:
9283
diff
changeset
|
85 { |
14247
855856a9f139
login: If session timeouts after authentication, log a better error about it.
Timo Sirainen <tss@iki.fi>
parents:
14171
diff
changeset
|
86 const char *user_reason, *destroy_reason; |
855856a9f139
login: If session timeouts after authentication, log a better error about it.
Timo Sirainen <tss@iki.fi>
parents:
14171
diff
changeset
|
87 unsigned int secs; |
855856a9f139
login: If session timeouts after authentication, log a better error about it.
Timo Sirainen <tss@iki.fi>
parents:
14171
diff
changeset
|
88 |
855856a9f139
login: If session timeouts after authentication, log a better error about it.
Timo Sirainen <tss@iki.fi>
parents:
14171
diff
changeset
|
89 if (client->master_tag != 0) { |
855856a9f139
login: If session timeouts after authentication, log a better error about it.
Timo Sirainen <tss@iki.fi>
parents:
14171
diff
changeset
|
90 secs = ioloop_time - client->auth_finished; |
855856a9f139
login: If session timeouts after authentication, log a better error about it.
Timo Sirainen <tss@iki.fi>
parents:
14171
diff
changeset
|
91 user_reason = "Timeout while finishing login."; |
855856a9f139
login: If session timeouts after authentication, log a better error about it.
Timo Sirainen <tss@iki.fi>
parents:
14171
diff
changeset
|
92 destroy_reason = t_strdup_printf( |
855856a9f139
login: If session timeouts after authentication, log a better error about it.
Timo Sirainen <tss@iki.fi>
parents:
14171
diff
changeset
|
93 "Timeout while finishing login (waited %u secs)", secs); |
855856a9f139
login: If session timeouts after authentication, log a better error about it.
Timo Sirainen <tss@iki.fi>
parents:
14171
diff
changeset
|
94 client_log_err(client, destroy_reason); |
855856a9f139
login: If session timeouts after authentication, log a better error about it.
Timo Sirainen <tss@iki.fi>
parents:
14171
diff
changeset
|
95 } else if (client->auth_request != NULL) { |
855856a9f139
login: If session timeouts after authentication, log a better error about it.
Timo Sirainen <tss@iki.fi>
parents:
14171
diff
changeset
|
96 user_reason = |
855856a9f139
login: If session timeouts after authentication, log a better error about it.
Timo Sirainen <tss@iki.fi>
parents:
14171
diff
changeset
|
97 "Disconnected for inactivity during authentication."; |
855856a9f139
login: If session timeouts after authentication, log a better error about it.
Timo Sirainen <tss@iki.fi>
parents:
14171
diff
changeset
|
98 destroy_reason = |
855856a9f139
login: If session timeouts after authentication, log a better error about it.
Timo Sirainen <tss@iki.fi>
parents:
14171
diff
changeset
|
99 "Disconnected: Inactivity during authentication"; |
855856a9f139
login: If session timeouts after authentication, log a better error about it.
Timo Sirainen <tss@iki.fi>
parents:
14171
diff
changeset
|
100 } else if (client->login_proxy != NULL) { |
855856a9f139
login: If session timeouts after authentication, log a better error about it.
Timo Sirainen <tss@iki.fi>
parents:
14171
diff
changeset
|
101 secs = ioloop_time - client->created; |
855856a9f139
login: If session timeouts after authentication, log a better error about it.
Timo Sirainen <tss@iki.fi>
parents:
14171
diff
changeset
|
102 user_reason = "Timeout while finishing login."; |
855856a9f139
login: If session timeouts after authentication, log a better error about it.
Timo Sirainen <tss@iki.fi>
parents:
14171
diff
changeset
|
103 destroy_reason = t_strdup_printf( |
855856a9f139
login: If session timeouts after authentication, log a better error about it.
Timo Sirainen <tss@iki.fi>
parents:
14171
diff
changeset
|
104 "proxy: Logging in to %s:%u timed out " |
21722
5571a8162b42
*-login: Add client.proxy_get_state() for providing human-readable proxy state
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
21390
diff
changeset
|
105 "(state=%s, duration=%us)", |
14247
855856a9f139
login: If session timeouts after authentication, log a better error about it.
Timo Sirainen <tss@iki.fi>
parents:
14171
diff
changeset
|
106 login_proxy_get_host(client->login_proxy), |
855856a9f139
login: If session timeouts after authentication, log a better error about it.
Timo Sirainen <tss@iki.fi>
parents:
14171
diff
changeset
|
107 login_proxy_get_port(client->login_proxy), |
21722
5571a8162b42
*-login: Add client.proxy_get_state() for providing human-readable proxy state
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
21390
diff
changeset
|
108 client_proxy_get_state(client), secs); |
14247
855856a9f139
login: If session timeouts after authentication, log a better error about it.
Timo Sirainen <tss@iki.fi>
parents:
14171
diff
changeset
|
109 client_log_err(client, destroy_reason); |
855856a9f139
login: If session timeouts after authentication, log a better error about it.
Timo Sirainen <tss@iki.fi>
parents:
14171
diff
changeset
|
110 } else { |
855856a9f139
login: If session timeouts after authentication, log a better error about it.
Timo Sirainen <tss@iki.fi>
parents:
14171
diff
changeset
|
111 user_reason = "Disconnected for inactivity."; |
855856a9f139
login: If session timeouts after authentication, log a better error about it.
Timo Sirainen <tss@iki.fi>
parents:
14171
diff
changeset
|
112 destroy_reason = "Disconnected: Inactivity"; |
855856a9f139
login: If session timeouts after authentication, log a better error about it.
Timo Sirainen <tss@iki.fi>
parents:
14171
diff
changeset
|
113 } |
14576 | 114 client_notify_disconnect(client, CLIENT_DISCONNECT_TIMEOUT, user_reason); |
14247
855856a9f139
login: If session timeouts after authentication, log a better error about it.
Timo Sirainen <tss@iki.fi>
parents:
14171
diff
changeset
|
115 client_destroy(client, destroy_reason); |
9756
e30495ae11de
*-login: Moved most of the common code to login-common.
Timo Sirainen <tss@iki.fi>
parents:
9283
diff
changeset
|
116 } |
e30495ae11de
*-login: Moved most of the common code to login-common.
Timo Sirainen <tss@iki.fi>
parents:
9283
diff
changeset
|
117 |
e30495ae11de
*-login: Moved most of the common code to login-common.
Timo Sirainen <tss@iki.fi>
parents:
9283
diff
changeset
|
118 static void client_open_streams(struct client *client) |
e30495ae11de
*-login: Moved most of the common code to login-common.
Timo Sirainen <tss@iki.fi>
parents:
9283
diff
changeset
|
119 { |
e30495ae11de
*-login: Moved most of the common code to login-common.
Timo Sirainen <tss@iki.fi>
parents:
9283
diff
changeset
|
120 client->input = |
e30495ae11de
*-login: Moved most of the common code to login-common.
Timo Sirainen <tss@iki.fi>
parents:
9283
diff
changeset
|
121 i_stream_create_fd(client->fd, LOGIN_MAX_INBUF_SIZE, FALSE); |
e30495ae11de
*-login: Moved most of the common code to login-common.
Timo Sirainen <tss@iki.fi>
parents:
9283
diff
changeset
|
122 client->output = |
e30495ae11de
*-login: Moved most of the common code to login-common.
Timo Sirainen <tss@iki.fi>
parents:
9283
diff
changeset
|
123 o_stream_create_fd(client->fd, LOGIN_MAX_OUTBUF_SIZE, FALSE); |
14681
ca37d1577291
Added o_stream_nsend*() and related functions to make delayed error handling safer.
Timo Sirainen <tss@iki.fi>
parents:
14576
diff
changeset
|
124 o_stream_set_no_error_handling(client->output, TRUE); |
13539
1ff636720b9f
login: Added -R <dir> parameter to write pre-login rawlogs to given directory.
Timo Sirainen <tss@iki.fi>
parents:
13538
diff
changeset
|
125 |
1ff636720b9f
login: Added -R <dir> parameter to write pre-login rawlogs to given directory.
Timo Sirainen <tss@iki.fi>
parents:
13538
diff
changeset
|
126 if (login_rawlog_dir != NULL) { |
1ff636720b9f
login: Added -R <dir> parameter to write pre-login rawlogs to given directory.
Timo Sirainen <tss@iki.fi>
parents:
13538
diff
changeset
|
127 if (iostream_rawlog_create(login_rawlog_dir, &client->input, |
1ff636720b9f
login: Added -R <dir> parameter to write pre-login rawlogs to given directory.
Timo Sirainen <tss@iki.fi>
parents:
13538
diff
changeset
|
128 &client->output) < 0) |
1ff636720b9f
login: Added -R <dir> parameter to write pre-login rawlogs to given directory.
Timo Sirainen <tss@iki.fi>
parents:
13538
diff
changeset
|
129 login_rawlog_dir = NULL; |
1ff636720b9f
login: Added -R <dir> parameter to write pre-login rawlogs to given directory.
Timo Sirainen <tss@iki.fi>
parents:
13538
diff
changeset
|
130 } |
9756
e30495ae11de
*-login: Moved most of the common code to login-common.
Timo Sirainen <tss@iki.fi>
parents:
9283
diff
changeset
|
131 } |
e30495ae11de
*-login: Moved most of the common code to login-common.
Timo Sirainen <tss@iki.fi>
parents:
9283
diff
changeset
|
132 |
14153 | 133 static bool client_is_trusted(struct client *client) |
134 { | |
135 const char *const *net; | |
136 struct ip_addr net_ip; | |
137 unsigned int bits; | |
138 | |
139 if (client->set->login_trusted_networks == NULL) | |
140 return FALSE; | |
141 | |
142 net = t_strsplit_spaces(client->set->login_trusted_networks, ", "); | |
143 for (; *net != NULL; net++) { | |
144 if (net_parse_range(*net, &net_ip, &bits) < 0) { | |
145 i_error("login_trusted_networks: " | |
146 "Invalid network '%s'", *net); | |
147 break; | |
148 } | |
149 | |
150 if (net_is_in_network(&client->ip, &net_ip, bits)) | |
151 return TRUE; | |
152 } | |
153 return FALSE; | |
154 } | |
155 | |
10111
9a71228ea41c
imap-login: If imap_capability is set, use it.
Timo Sirainen <tss@iki.fi>
parents:
10101
diff
changeset
|
156 struct client * |
9a71228ea41c
imap-login: If imap_capability is set, use it.
Timo Sirainen <tss@iki.fi>
parents:
10101
diff
changeset
|
157 client_create(int fd, bool ssl, pool_t pool, |
18950
a0e8c6b88072
lmtp, *-login: Use ip/port values from struct master_service_connection instead of from the socket.
Stephan Bosch <stephan@rename-it.nl>
parents:
18137
diff
changeset
|
158 const struct master_service_connection *conn, |
14728
983c6ff12cc9
Moved ssl_* settings from login-common to lib-master.
Timo Sirainen <tss@iki.fi>
parents:
14681
diff
changeset
|
159 const struct login_settings *set, |
983c6ff12cc9
Moved ssl_* settings from login-common to lib-master.
Timo Sirainen <tss@iki.fi>
parents:
14681
diff
changeset
|
160 const struct master_service_ssl_settings *ssl_set, |
18950
a0e8c6b88072
lmtp, *-login: Use ip/port values from struct master_service_connection instead of from the socket.
Stephan Bosch <stephan@rename-it.nl>
parents:
18137
diff
changeset
|
161 void **other_sets) |
7104
db5f55daa002
Forgot from imap/pop3-login clients hash -> linked list commit.
Timo Sirainen <tss@iki.fi>
parents:
7086
diff
changeset
|
162 { |
9756
e30495ae11de
*-login: Moved most of the common code to login-common.
Timo Sirainen <tss@iki.fi>
parents:
9283
diff
changeset
|
163 struct client *client; |
e30495ae11de
*-login: Moved most of the common code to login-common.
Timo Sirainen <tss@iki.fi>
parents:
9283
diff
changeset
|
164 |
e30495ae11de
*-login: Moved most of the common code to login-common.
Timo Sirainen <tss@iki.fi>
parents:
9283
diff
changeset
|
165 i_assert(fd != -1); |
e30495ae11de
*-login: Moved most of the common code to login-common.
Timo Sirainen <tss@iki.fi>
parents:
9283
diff
changeset
|
166 |
12890
6f0396e35fd9
login-common API redesign so that the library doesn't refer to nonexistent variables.
Timo Sirainen <tss@iki.fi>
parents:
12782
diff
changeset
|
167 client = login_binary->client_vfuncs->alloc(pool); |
6f0396e35fd9
login-common API redesign so that the library doesn't refer to nonexistent variables.
Timo Sirainen <tss@iki.fi>
parents:
12782
diff
changeset
|
168 client->v = *login_binary->client_vfuncs; |
9781
19912e4a2fb3
*-login: Allow backend to parse SASL responses from client (for managesieve).
Timo Sirainen <tss@iki.fi>
parents:
9767
diff
changeset
|
169 if (client->v.auth_send_challenge == NULL) |
19912e4a2fb3
*-login: Allow backend to parse SASL responses from client (for managesieve).
Timo Sirainen <tss@iki.fi>
parents:
9767
diff
changeset
|
170 client->v.auth_send_challenge = client_auth_send_challenge; |
19912e4a2fb3
*-login: Allow backend to parse SASL responses from client (for managesieve).
Timo Sirainen <tss@iki.fi>
parents:
9767
diff
changeset
|
171 if (client->v.auth_parse_response == NULL) |
19912e4a2fb3
*-login: Allow backend to parse SASL responses from client (for managesieve).
Timo Sirainen <tss@iki.fi>
parents:
9767
diff
changeset
|
172 client->v.auth_parse_response = client_auth_parse_response; |
9767
50df3e60ab85
*-login: Abstract out SASL continue reply sending (for managesieve).
Timo Sirainen <tss@iki.fi>
parents:
9765
diff
changeset
|
173 |
9756
e30495ae11de
*-login: Moved most of the common code to login-common.
Timo Sirainen <tss@iki.fi>
parents:
9283
diff
changeset
|
174 client->created = ioloop_time; |
e30495ae11de
*-login: Moved most of the common code to login-common.
Timo Sirainen <tss@iki.fi>
parents:
9283
diff
changeset
|
175 client->refcount = 1; |
e30495ae11de
*-login: Moved most of the common code to login-common.
Timo Sirainen <tss@iki.fi>
parents:
9283
diff
changeset
|
176 |
e30495ae11de
*-login: Moved most of the common code to login-common.
Timo Sirainen <tss@iki.fi>
parents:
9283
diff
changeset
|
177 client->pool = pool; |
21765
91b94ecaa39d
login-common: Add preproxy pool
Aki Tuomi <aki.tuomi@dovecot.fi>
parents:
21741
diff
changeset
|
178 client->preproxy_pool = pool_alloconly_create(MEMPOOL_GROWING"preproxy pool", 256); |
9756
e30495ae11de
*-login: Moved most of the common code to login-common.
Timo Sirainen <tss@iki.fi>
parents:
9283
diff
changeset
|
179 client->set = set; |
14728
983c6ff12cc9
Moved ssl_* settings from login-common to lib-master.
Timo Sirainen <tss@iki.fi>
parents:
14681
diff
changeset
|
180 client->ssl_set = ssl_set; |
19572
8bb95d42e5ea
*-login: Allow plugins to hook into client allocation and add module-specific contexts to client.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
19552
diff
changeset
|
181 p_array_init(&client->module_contexts, client->pool, 5); |
18950
a0e8c6b88072
lmtp, *-login: Use ip/port values from struct master_service_connection instead of from the socket.
Stephan Bosch <stephan@rename-it.nl>
parents:
18137
diff
changeset
|
182 |
9756
e30495ae11de
*-login: Moved most of the common code to login-common.
Timo Sirainen <tss@iki.fi>
parents:
9283
diff
changeset
|
183 client->fd = fd; |
e30495ae11de
*-login: Moved most of the common code to login-common.
Timo Sirainen <tss@iki.fi>
parents:
9283
diff
changeset
|
184 client->tls = ssl; |
18950
a0e8c6b88072
lmtp, *-login: Use ip/port values from struct master_service_connection instead of from the socket.
Stephan Bosch <stephan@rename-it.nl>
parents:
18137
diff
changeset
|
185 |
a0e8c6b88072
lmtp, *-login: Use ip/port values from struct master_service_connection instead of from the socket.
Stephan Bosch <stephan@rename-it.nl>
parents:
18137
diff
changeset
|
186 client->local_ip = conn->local_ip; |
a0e8c6b88072
lmtp, *-login: Use ip/port values from struct master_service_connection instead of from the socket.
Stephan Bosch <stephan@rename-it.nl>
parents:
18137
diff
changeset
|
187 client->local_port = conn->local_port; |
a0e8c6b88072
lmtp, *-login: Use ip/port values from struct master_service_connection instead of from the socket.
Stephan Bosch <stephan@rename-it.nl>
parents:
18137
diff
changeset
|
188 client->ip = conn->remote_ip; |
a0e8c6b88072
lmtp, *-login: Use ip/port values from struct master_service_connection instead of from the socket.
Stephan Bosch <stephan@rename-it.nl>
parents:
18137
diff
changeset
|
189 client->remote_port = conn->remote_port; |
a0e8c6b88072
lmtp, *-login: Use ip/port values from struct master_service_connection instead of from the socket.
Stephan Bosch <stephan@rename-it.nl>
parents:
18137
diff
changeset
|
190 client->real_local_ip = conn->real_local_ip; |
a0e8c6b88072
lmtp, *-login: Use ip/port values from struct master_service_connection instead of from the socket.
Stephan Bosch <stephan@rename-it.nl>
parents:
18137
diff
changeset
|
191 client->real_local_port = conn->real_local_port; |
a0e8c6b88072
lmtp, *-login: Use ip/port values from struct master_service_connection instead of from the socket.
Stephan Bosch <stephan@rename-it.nl>
parents:
18137
diff
changeset
|
192 client->real_remote_ip = conn->real_remote_ip; |
19010
a919414e68d2
login_log_format_elements: Added %{listener} variable to expand to the listener socket name.
Timo Sirainen <tss@iki.fi>
parents:
18950
diff
changeset
|
193 client->real_remote_port = conn->real_remote_port; |
a919414e68d2
login_log_format_elements: Added %{listener} variable to expand to the listener socket name.
Timo Sirainen <tss@iki.fi>
parents:
18950
diff
changeset
|
194 client->listener_name = p_strdup(client->pool, conn->name); |
18950
a0e8c6b88072
lmtp, *-login: Use ip/port values from struct master_service_connection instead of from the socket.
Stephan Bosch <stephan@rename-it.nl>
parents:
18137
diff
changeset
|
195 |
9756
e30495ae11de
*-login: Moved most of the common code to login-common.
Timo Sirainen <tss@iki.fi>
parents:
9283
diff
changeset
|
196 client->trusted = client_is_trusted(client); |
e30495ae11de
*-login: Moved most of the common code to login-common.
Timo Sirainen <tss@iki.fi>
parents:
9283
diff
changeset
|
197 client->secured = ssl || client->trusted || |
18950
a0e8c6b88072
lmtp, *-login: Use ip/port values from struct master_service_connection instead of from the socket.
Stephan Bosch <stephan@rename-it.nl>
parents:
18137
diff
changeset
|
198 net_ip_compare(&conn->real_remote_ip, &conn->real_local_ip); |
14162
ba06ea38c722
imap/pop3/lmtp proxy: Implemented detection of proxy loops with TTL.
Timo Sirainen <tss@iki.fi>
parents:
14153
diff
changeset
|
199 client->proxy_ttl = LOGIN_PROXY_TTL; |
9756
e30495ae11de
*-login: Moved most of the common code to login-common.
Timo Sirainen <tss@iki.fi>
parents:
9283
diff
changeset
|
200 |
9923
77228b5431e1
*-login: Fixed dropping oldest connection when reaching all limits.
Timo Sirainen <tss@iki.fi>
parents:
9921
diff
changeset
|
201 if (last_client == NULL) |
77228b5431e1
*-login: Fixed dropping oldest connection when reaching all limits.
Timo Sirainen <tss@iki.fi>
parents:
9921
diff
changeset
|
202 last_client = client; |
7120
eb71cda96663
Use linked list macros for handling clients linked list.
Timo Sirainen <tss@iki.fi>
parents:
7117
diff
changeset
|
203 DLLIST_PREPEND(&clients, client); |
7104
db5f55daa002
Forgot from imap/pop3-login clients hash -> linked list commit.
Timo Sirainen <tss@iki.fi>
parents:
7086
diff
changeset
|
204 clients_count++; |
9756
e30495ae11de
*-login: Moved most of the common code to login-common.
Timo Sirainen <tss@iki.fi>
parents:
9283
diff
changeset
|
205 |
10867
c56358283605
login: Always disconnect clients after 3 minutes if they haven't logged in.
Timo Sirainen <tss@iki.fi>
parents:
10760
diff
changeset
|
206 client->to_disconnect = |
c56358283605
login: Always disconnect clients after 3 minutes if they haven't logged in.
Timo Sirainen <tss@iki.fi>
parents:
10760
diff
changeset
|
207 timeout_add(CLIENT_LOGIN_TIMEOUT_MSECS, |
9756
e30495ae11de
*-login: Moved most of the common code to login-common.
Timo Sirainen <tss@iki.fi>
parents:
9283
diff
changeset
|
208 client_idle_disconnect_timeout, client); |
e30495ae11de
*-login: Moved most of the common code to login-common.
Timo Sirainen <tss@iki.fi>
parents:
9283
diff
changeset
|
209 client_open_streams(client); |
e30495ae11de
*-login: Moved most of the common code to login-common.
Timo Sirainen <tss@iki.fi>
parents:
9283
diff
changeset
|
210 |
21741
ad2aa897a8d7
*-login: Change API for how login_plugins hook into client allocation.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
21722
diff
changeset
|
211 hook_login_client_allocated(client); |
10111
9a71228ea41c
imap-login: If imap_capability is set, use it.
Timo Sirainen <tss@iki.fi>
parents:
10101
diff
changeset
|
212 client->v.create(client, other_sets); |
9756
e30495ae11de
*-login: Moved most of the common code to login-common.
Timo Sirainen <tss@iki.fi>
parents:
9283
diff
changeset
|
213 |
e30495ae11de
*-login: Moved most of the common code to login-common.
Timo Sirainen <tss@iki.fi>
parents:
9283
diff
changeset
|
214 if (auth_client_is_connected(auth_client)) |
14146
e456e1bce47f
login-common API made more extensible for different kinds of protocols.
Timo Sirainen <tss@iki.fi>
parents:
14133
diff
changeset
|
215 client_notify_auth_ready(client); |
9756
e30495ae11de
*-login: Moved most of the common code to login-common.
Timo Sirainen <tss@iki.fi>
parents:
9283
diff
changeset
|
216 else |
e30495ae11de
*-login: Moved most of the common code to login-common.
Timo Sirainen <tss@iki.fi>
parents:
9283
diff
changeset
|
217 client_set_auth_waiting(client); |
10198
3e7e08af2991
*-login: Show better state with verbose_proctitle=yes.
Timo Sirainen <tss@iki.fi>
parents:
10111
diff
changeset
|
218 |
3e7e08af2991
*-login: Show better state with verbose_proctitle=yes.
Timo Sirainen <tss@iki.fi>
parents:
10111
diff
changeset
|
219 login_refresh_proctitle(); |
9756
e30495ae11de
*-login: Moved most of the common code to login-common.
Timo Sirainen <tss@iki.fi>
parents:
9283
diff
changeset
|
220 return client; |
e30495ae11de
*-login: Moved most of the common code to login-common.
Timo Sirainen <tss@iki.fi>
parents:
9283
diff
changeset
|
221 } |
e30495ae11de
*-login: Moved most of the common code to login-common.
Timo Sirainen <tss@iki.fi>
parents:
9283
diff
changeset
|
222 |
e30495ae11de
*-login: Moved most of the common code to login-common.
Timo Sirainen <tss@iki.fi>
parents:
9283
diff
changeset
|
223 void client_destroy(struct client *client, const char *reason) |
e30495ae11de
*-login: Moved most of the common code to login-common.
Timo Sirainen <tss@iki.fi>
parents:
9283
diff
changeset
|
224 { |
e30495ae11de
*-login: Moved most of the common code to login-common.
Timo Sirainen <tss@iki.fi>
parents:
9283
diff
changeset
|
225 if (client->destroyed) |
e30495ae11de
*-login: Moved most of the common code to login-common.
Timo Sirainen <tss@iki.fi>
parents:
9283
diff
changeset
|
226 return; |
e30495ae11de
*-login: Moved most of the common code to login-common.
Timo Sirainen <tss@iki.fi>
parents:
9283
diff
changeset
|
227 client->destroyed = TRUE; |
e30495ae11de
*-login: Moved most of the common code to login-common.
Timo Sirainen <tss@iki.fi>
parents:
9283
diff
changeset
|
228 |
21765
91b94ecaa39d
login-common: Add preproxy pool
Aki Tuomi <aki.tuomi@dovecot.fi>
parents:
21741
diff
changeset
|
229 if (client->preproxy_pool != NULL) |
91b94ecaa39d
login-common: Add preproxy pool
Aki Tuomi <aki.tuomi@dovecot.fi>
parents:
21741
diff
changeset
|
230 pool_unref(&client->preproxy_pool); |
91b94ecaa39d
login-common: Add preproxy pool
Aki Tuomi <aki.tuomi@dovecot.fi>
parents:
21741
diff
changeset
|
231 |
9756
e30495ae11de
*-login: Moved most of the common code to login-common.
Timo Sirainen <tss@iki.fi>
parents:
9283
diff
changeset
|
232 if (!client->login_success && reason != NULL) { |
21909
57ce096eab4b
*-login: Minor logging cleanup if client is disconnected before sending banner.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
21820
diff
changeset
|
233 const char *extra_reason = |
57ce096eab4b
*-login: Minor logging cleanup if client is disconnected before sending banner.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
21820
diff
changeset
|
234 client_get_extra_disconnect_reason(client); |
57ce096eab4b
*-login: Minor logging cleanup if client is disconnected before sending banner.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
21820
diff
changeset
|
235 if (extra_reason[0] != '\0') |
57ce096eab4b
*-login: Minor logging cleanup if client is disconnected before sending banner.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
21820
diff
changeset
|
236 reason = t_strconcat(reason, " ", extra_reason, NULL); |
9756
e30495ae11de
*-login: Moved most of the common code to login-common.
Timo Sirainen <tss@iki.fi>
parents:
9283
diff
changeset
|
237 } |
e30495ae11de
*-login: Moved most of the common code to login-common.
Timo Sirainen <tss@iki.fi>
parents:
9283
diff
changeset
|
238 if (reason != NULL) |
e30495ae11de
*-login: Moved most of the common code to login-common.
Timo Sirainen <tss@iki.fi>
parents:
9283
diff
changeset
|
239 client_log(client, reason); |
e30495ae11de
*-login: Moved most of the common code to login-common.
Timo Sirainen <tss@iki.fi>
parents:
9283
diff
changeset
|
240 |
10198
3e7e08af2991
*-login: Show better state with verbose_proctitle=yes.
Timo Sirainen <tss@iki.fi>
parents:
10111
diff
changeset
|
241 if (last_client == client) |
9923
77228b5431e1
*-login: Fixed dropping oldest connection when reaching all limits.
Timo Sirainen <tss@iki.fi>
parents:
9921
diff
changeset
|
242 last_client = client->prev; |
9756
e30495ae11de
*-login: Moved most of the common code to login-common.
Timo Sirainen <tss@iki.fi>
parents:
9283
diff
changeset
|
243 DLLIST_REMOVE(&clients, client); |
e30495ae11de
*-login: Moved most of the common code to login-common.
Timo Sirainen <tss@iki.fi>
parents:
9283
diff
changeset
|
244 |
17442
5259f6320e52
login-common: Fixed potential crash at client disconnect.
Timo Sirainen <tss@iki.fi>
parents:
17437
diff
changeset
|
245 if (client->output != NULL) |
5259f6320e52
login-common: Fixed potential crash at client disconnect.
Timo Sirainen <tss@iki.fi>
parents:
17437
diff
changeset
|
246 o_stream_uncork(client->output); |
17334
41622541a7a3
*-login: SSL connections didn't get closed when the client got destroyed.
Timo Sirainen <tss@iki.fi>
parents:
17130
diff
changeset
|
247 if (!client->login_success && client->ssl_proxy != NULL) |
41622541a7a3
*-login: SSL connections didn't get closed when the client got destroyed.
Timo Sirainen <tss@iki.fi>
parents:
17130
diff
changeset
|
248 ssl_proxy_destroy(client->ssl_proxy); |
9756
e30495ae11de
*-login: Moved most of the common code to login-common.
Timo Sirainen <tss@iki.fi>
parents:
9283
diff
changeset
|
249 if (client->input != NULL) |
e30495ae11de
*-login: Moved most of the common code to login-common.
Timo Sirainen <tss@iki.fi>
parents:
9283
diff
changeset
|
250 i_stream_close(client->input); |
e30495ae11de
*-login: Moved most of the common code to login-common.
Timo Sirainen <tss@iki.fi>
parents:
9283
diff
changeset
|
251 if (client->output != NULL) |
e30495ae11de
*-login: Moved most of the common code to login-common.
Timo Sirainen <tss@iki.fi>
parents:
9283
diff
changeset
|
252 o_stream_close(client->output); |
e30495ae11de
*-login: Moved most of the common code to login-common.
Timo Sirainen <tss@iki.fi>
parents:
9283
diff
changeset
|
253 |
e30495ae11de
*-login: Moved most of the common code to login-common.
Timo Sirainen <tss@iki.fi>
parents:
9283
diff
changeset
|
254 if (client->master_tag != 0) { |
e30495ae11de
*-login: Moved most of the common code to login-common.
Timo Sirainen <tss@iki.fi>
parents:
9283
diff
changeset
|
255 i_assert(client->auth_request == NULL); |
e30495ae11de
*-login: Moved most of the common code to login-common.
Timo Sirainen <tss@iki.fi>
parents:
9283
diff
changeset
|
256 i_assert(client->authenticating); |
9921
5bcb78c2eabb
*-login: Don't leak client when it's aborted while waiting for reply from master.
Timo Sirainen <tss@iki.fi>
parents:
9838
diff
changeset
|
257 i_assert(client->refcount > 1); |
5bcb78c2eabb
*-login: Don't leak client when it's aborted while waiting for reply from master.
Timo Sirainen <tss@iki.fi>
parents:
9838
diff
changeset
|
258 client->authenticating = FALSE; |
10101
4fe8c4382712
Redesigned how login process passes connections to mail processes and changed related APIs.
Timo Sirainen <tss@iki.fi>
parents:
10034
diff
changeset
|
259 master_auth_request_abort(master_auth, client->master_tag); |
9921
5bcb78c2eabb
*-login: Don't leak client when it's aborted while waiting for reply from master.
Timo Sirainen <tss@iki.fi>
parents:
9838
diff
changeset
|
260 client->refcount--; |
9756
e30495ae11de
*-login: Moved most of the common code to login-common.
Timo Sirainen <tss@iki.fi>
parents:
9283
diff
changeset
|
261 } else if (client->auth_request != NULL) { |
e30495ae11de
*-login: Moved most of the common code to login-common.
Timo Sirainen <tss@iki.fi>
parents:
9283
diff
changeset
|
262 i_assert(client->authenticating); |
e30495ae11de
*-login: Moved most of the common code to login-common.
Timo Sirainen <tss@iki.fi>
parents:
9283
diff
changeset
|
263 sasl_server_auth_abort(client); |
e30495ae11de
*-login: Moved most of the common code to login-common.
Timo Sirainen <tss@iki.fi>
parents:
9283
diff
changeset
|
264 } else { |
e30495ae11de
*-login: Moved most of the common code to login-common.
Timo Sirainen <tss@iki.fi>
parents:
9283
diff
changeset
|
265 i_assert(!client->authenticating); |
e30495ae11de
*-login: Moved most of the common code to login-common.
Timo Sirainen <tss@iki.fi>
parents:
9283
diff
changeset
|
266 } |
e30495ae11de
*-login: Moved most of the common code to login-common.
Timo Sirainen <tss@iki.fi>
parents:
9283
diff
changeset
|
267 |
e30495ae11de
*-login: Moved most of the common code to login-common.
Timo Sirainen <tss@iki.fi>
parents:
9283
diff
changeset
|
268 if (client->io != NULL) |
e30495ae11de
*-login: Moved most of the common code to login-common.
Timo Sirainen <tss@iki.fi>
parents:
9283
diff
changeset
|
269 io_remove(&client->io); |
10867
c56358283605
login: Always disconnect clients after 3 minutes if they haven't logged in.
Timo Sirainen <tss@iki.fi>
parents:
10760
diff
changeset
|
270 if (client->to_disconnect != NULL) |
c56358283605
login: Always disconnect clients after 3 minutes if they haven't logged in.
Timo Sirainen <tss@iki.fi>
parents:
10760
diff
changeset
|
271 timeout_remove(&client->to_disconnect); |
9756
e30495ae11de
*-login: Moved most of the common code to login-common.
Timo Sirainen <tss@iki.fi>
parents:
9283
diff
changeset
|
272 if (client->to_auth_waiting != NULL) |
e30495ae11de
*-login: Moved most of the common code to login-common.
Timo Sirainen <tss@iki.fi>
parents:
9283
diff
changeset
|
273 timeout_remove(&client->to_auth_waiting); |
9782
e4235adb3044
*-login: Allow auth input to be larger than the rest of the input.
Timo Sirainen <tss@iki.fi>
parents:
9781
diff
changeset
|
274 if (client->auth_response != NULL) |
e4235adb3044
*-login: Allow auth input to be larger than the rest of the input.
Timo Sirainen <tss@iki.fi>
parents:
9781
diff
changeset
|
275 str_free(&client->auth_response); |
9756
e30495ae11de
*-login: Moved most of the common code to login-common.
Timo Sirainen <tss@iki.fi>
parents:
9283
diff
changeset
|
276 |
e30495ae11de
*-login: Moved most of the common code to login-common.
Timo Sirainen <tss@iki.fi>
parents:
9283
diff
changeset
|
277 if (client->fd != -1) { |
e30495ae11de
*-login: Moved most of the common code to login-common.
Timo Sirainen <tss@iki.fi>
parents:
9283
diff
changeset
|
278 net_disconnect(client->fd); |
e30495ae11de
*-login: Moved most of the common code to login-common.
Timo Sirainen <tss@iki.fi>
parents:
9283
diff
changeset
|
279 client->fd = -1; |
e30495ae11de
*-login: Moved most of the common code to login-common.
Timo Sirainen <tss@iki.fi>
parents:
9283
diff
changeset
|
280 } |
e30495ae11de
*-login: Moved most of the common code to login-common.
Timo Sirainen <tss@iki.fi>
parents:
9283
diff
changeset
|
281 |
e30495ae11de
*-login: Moved most of the common code to login-common.
Timo Sirainen <tss@iki.fi>
parents:
9283
diff
changeset
|
282 if (client->proxy_password != NULL) { |
e30495ae11de
*-login: Moved most of the common code to login-common.
Timo Sirainen <tss@iki.fi>
parents:
9283
diff
changeset
|
283 safe_memset(client->proxy_password, 0, |
e30495ae11de
*-login: Moved most of the common code to login-common.
Timo Sirainen <tss@iki.fi>
parents:
9283
diff
changeset
|
284 strlen(client->proxy_password)); |
e30495ae11de
*-login: Moved most of the common code to login-common.
Timo Sirainen <tss@iki.fi>
parents:
9283
diff
changeset
|
285 i_free_and_null(client->proxy_password); |
e30495ae11de
*-login: Moved most of the common code to login-common.
Timo Sirainen <tss@iki.fi>
parents:
9283
diff
changeset
|
286 } |
e30495ae11de
*-login: Moved most of the common code to login-common.
Timo Sirainen <tss@iki.fi>
parents:
9283
diff
changeset
|
287 |
16487
266101990d63
imap/pop3-login: Use libsasl for authenticating to remote IMAP/POP3 server.
Timo Sirainen <tss@iki.fi>
parents:
15888
diff
changeset
|
288 if (client->proxy_sasl_client != NULL) |
16555
2dd27b0e7e49
lib-sasl: Use dsasl_ prefix so we don't conflict with Cyrus SASL library.
Timo Sirainen <tss@iki.fi>
parents:
16487
diff
changeset
|
289 dsasl_client_free(&client->proxy_sasl_client); |
9756
e30495ae11de
*-login: Moved most of the common code to login-common.
Timo Sirainen <tss@iki.fi>
parents:
9283
diff
changeset
|
290 if (client->login_proxy != NULL) |
e30495ae11de
*-login: Moved most of the common code to login-common.
Timo Sirainen <tss@iki.fi>
parents:
9283
diff
changeset
|
291 login_proxy_free(&client->login_proxy); |
15049
aa6027a0a78e
Added support to perform token-based service process authentication.
Stephan Bosch <stephan@rename-it.nl>
parents:
14840
diff
changeset
|
292 if (client->v.destroy != NULL) |
aa6027a0a78e
Added support to perform token-based service process authentication.
Stephan Bosch <stephan@rename-it.nl>
parents:
14840
diff
changeset
|
293 client->v.destroy(client); |
13721
80558d1b7040
login: Minor potential authentication fix when service_count>1
Timo Sirainen <tss@iki.fi>
parents:
13704
diff
changeset
|
294 if (client_unref(&client) && initial_service_count == 1) { |
10034
cf376fcbd6ff
*-login: Close auth client connection after (proxying) process no longer needs it.
Timo Sirainen <tss@iki.fi>
parents:
9987
diff
changeset
|
295 /* as soon as this connection is done with proxying |
cf376fcbd6ff
*-login: Close auth client connection after (proxying) process no longer needs it.
Timo Sirainen <tss@iki.fi>
parents:
9987
diff
changeset
|
296 (or whatever), the process will die. there's no need for |
13721
80558d1b7040
login: Minor potential authentication fix when service_count>1
Timo Sirainen <tss@iki.fi>
parents:
13704
diff
changeset
|
297 authentication anymore, so close the connection. |
80558d1b7040
login: Minor potential authentication fix when service_count>1
Timo Sirainen <tss@iki.fi>
parents:
13704
diff
changeset
|
298 do this only with initial service_count=1, in case there |
80558d1b7040
login: Minor potential authentication fix when service_count>1
Timo Sirainen <tss@iki.fi>
parents:
13704
diff
changeset
|
299 are other clients with pending authentications */ |
13959
3dae51fd4565
lib-auth: Improved warning message about aborting auth requests.
Timo Sirainen <tss@iki.fi>
parents:
13933
diff
changeset
|
300 auth_client_disconnect(auth_client, "unnecessary connection"); |
10034
cf376fcbd6ff
*-login: Close auth client connection after (proxying) process no longer needs it.
Timo Sirainen <tss@iki.fi>
parents:
9987
diff
changeset
|
301 } |
10760
fc77d1cd1201
*-login: Disconnect from auth server after idling for a minute.
Timo Sirainen <tss@iki.fi>
parents:
10582
diff
changeset
|
302 login_client_destroyed(); |
10198
3e7e08af2991
*-login: Show better state with verbose_proctitle=yes.
Timo Sirainen <tss@iki.fi>
parents:
10111
diff
changeset
|
303 login_refresh_proctitle(); |
9756
e30495ae11de
*-login: Moved most of the common code to login-common.
Timo Sirainen <tss@iki.fi>
parents:
9283
diff
changeset
|
304 } |
e30495ae11de
*-login: Moved most of the common code to login-common.
Timo Sirainen <tss@iki.fi>
parents:
9283
diff
changeset
|
305 |
e30495ae11de
*-login: Moved most of the common code to login-common.
Timo Sirainen <tss@iki.fi>
parents:
9283
diff
changeset
|
306 void client_destroy_success(struct client *client, const char *reason) |
e30495ae11de
*-login: Moved most of the common code to login-common.
Timo Sirainen <tss@iki.fi>
parents:
9283
diff
changeset
|
307 { |
e30495ae11de
*-login: Moved most of the common code to login-common.
Timo Sirainen <tss@iki.fi>
parents:
9283
diff
changeset
|
308 client->login_success = TRUE; |
e30495ae11de
*-login: Moved most of the common code to login-common.
Timo Sirainen <tss@iki.fi>
parents:
9283
diff
changeset
|
309 client_destroy(client, reason); |
e30495ae11de
*-login: Moved most of the common code to login-common.
Timo Sirainen <tss@iki.fi>
parents:
9283
diff
changeset
|
310 } |
e30495ae11de
*-login: Moved most of the common code to login-common.
Timo Sirainen <tss@iki.fi>
parents:
9283
diff
changeset
|
311 |
e30495ae11de
*-login: Moved most of the common code to login-common.
Timo Sirainen <tss@iki.fi>
parents:
9283
diff
changeset
|
312 void client_destroy_internal_failure(struct client *client) |
e30495ae11de
*-login: Moved most of the common code to login-common.
Timo Sirainen <tss@iki.fi>
parents:
9283
diff
changeset
|
313 { |
14146
e456e1bce47f
login-common API made more extensible for different kinds of protocols.
Timo Sirainen <tss@iki.fi>
parents:
14133
diff
changeset
|
314 client_notify_disconnect(client, CLIENT_DISCONNECT_INTERNAL_ERROR, |
e456e1bce47f
login-common API made more extensible for different kinds of protocols.
Timo Sirainen <tss@iki.fi>
parents:
14133
diff
changeset
|
315 "Internal login failure. " |
e456e1bce47f
login-common API made more extensible for different kinds of protocols.
Timo Sirainen <tss@iki.fi>
parents:
14133
diff
changeset
|
316 "Refer to server log for more information."); |
12504
c6b0e643d2dc
Log login pid/id for internal failures to allow matching errors between processes.
Timo Sirainen <tss@iki.fi>
parents:
12266
diff
changeset
|
317 client_destroy(client, t_strdup_printf( |
c6b0e643d2dc
Log login pid/id for internal failures to allow matching errors between processes.
Timo Sirainen <tss@iki.fi>
parents:
12266
diff
changeset
|
318 "Internal login failure (pid=%s id=%u)", |
c6b0e643d2dc
Log login pid/id for internal failures to allow matching errors between processes.
Timo Sirainen <tss@iki.fi>
parents:
12266
diff
changeset
|
319 my_pid, client->master_auth_id)); |
9756
e30495ae11de
*-login: Moved most of the common code to login-common.
Timo Sirainen <tss@iki.fi>
parents:
9283
diff
changeset
|
320 } |
e30495ae11de
*-login: Moved most of the common code to login-common.
Timo Sirainen <tss@iki.fi>
parents:
9283
diff
changeset
|
321 |
e30495ae11de
*-login: Moved most of the common code to login-common.
Timo Sirainen <tss@iki.fi>
parents:
9283
diff
changeset
|
322 void client_ref(struct client *client) |
e30495ae11de
*-login: Moved most of the common code to login-common.
Timo Sirainen <tss@iki.fi>
parents:
9283
diff
changeset
|
323 { |
e30495ae11de
*-login: Moved most of the common code to login-common.
Timo Sirainen <tss@iki.fi>
parents:
9283
diff
changeset
|
324 client->refcount++; |
7104
db5f55daa002
Forgot from imap/pop3-login clients hash -> linked list commit.
Timo Sirainen <tss@iki.fi>
parents:
7086
diff
changeset
|
325 } |
db5f55daa002
Forgot from imap/pop3-login clients hash -> linked list commit.
Timo Sirainen <tss@iki.fi>
parents:
7086
diff
changeset
|
326 |
9929
d60fa42fbaac
*-login: Fixes to SSL/login proxy connection counting.
Timo Sirainen <tss@iki.fi>
parents:
9923
diff
changeset
|
327 bool client_unref(struct client **_client) |
9756
e30495ae11de
*-login: Moved most of the common code to login-common.
Timo Sirainen <tss@iki.fi>
parents:
9283
diff
changeset
|
328 { |
9929
d60fa42fbaac
*-login: Fixes to SSL/login proxy connection counting.
Timo Sirainen <tss@iki.fi>
parents:
9923
diff
changeset
|
329 struct client *client = *_client; |
d60fa42fbaac
*-login: Fixes to SSL/login proxy connection counting.
Timo Sirainen <tss@iki.fi>
parents:
9923
diff
changeset
|
330 |
9756
e30495ae11de
*-login: Moved most of the common code to login-common.
Timo Sirainen <tss@iki.fi>
parents:
9283
diff
changeset
|
331 i_assert(client->refcount > 0); |
e30495ae11de
*-login: Moved most of the common code to login-common.
Timo Sirainen <tss@iki.fi>
parents:
9283
diff
changeset
|
332 if (--client->refcount > 0) |
e30495ae11de
*-login: Moved most of the common code to login-common.
Timo Sirainen <tss@iki.fi>
parents:
9283
diff
changeset
|
333 return TRUE; |
e30495ae11de
*-login: Moved most of the common code to login-common.
Timo Sirainen <tss@iki.fi>
parents:
9283
diff
changeset
|
334 |
9929
d60fa42fbaac
*-login: Fixes to SSL/login proxy connection counting.
Timo Sirainen <tss@iki.fi>
parents:
9923
diff
changeset
|
335 *_client = NULL; |
d60fa42fbaac
*-login: Fixes to SSL/login proxy connection counting.
Timo Sirainen <tss@iki.fi>
parents:
9923
diff
changeset
|
336 |
9756
e30495ae11de
*-login: Moved most of the common code to login-common.
Timo Sirainen <tss@iki.fi>
parents:
9283
diff
changeset
|
337 i_assert(client->destroyed); |
9929
d60fa42fbaac
*-login: Fixes to SSL/login proxy connection counting.
Timo Sirainen <tss@iki.fi>
parents:
9923
diff
changeset
|
338 i_assert(client->login_proxy == NULL); |
9756
e30495ae11de
*-login: Moved most of the common code to login-common.
Timo Sirainen <tss@iki.fi>
parents:
9283
diff
changeset
|
339 |
22242
589993f80eda
*-login: Add client_vfuncs.free() that is called when client refcount=0
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
21970
diff
changeset
|
340 if (client->v.free != NULL) |
589993f80eda
*-login: Add client_vfuncs.free() that is called when client refcount=0
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
21970
diff
changeset
|
341 client->v.free(client); |
589993f80eda
*-login: Add client_vfuncs.free() that is called when client refcount=0
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
21970
diff
changeset
|
342 |
14367
1d23440ccb89
*-login: Fixed crashing when proxying SSL connections to a remote server.
Timo Sirainen <tss@iki.fi>
parents:
14302
diff
changeset
|
343 if (client->ssl_proxy != NULL) |
1d23440ccb89
*-login: Fixed crashing when proxying SSL connections to a remote server.
Timo Sirainen <tss@iki.fi>
parents:
14302
diff
changeset
|
344 ssl_proxy_free(&client->ssl_proxy); |
9756
e30495ae11de
*-login: Moved most of the common code to login-common.
Timo Sirainen <tss@iki.fi>
parents:
9283
diff
changeset
|
345 if (client->input != NULL) |
e30495ae11de
*-login: Moved most of the common code to login-common.
Timo Sirainen <tss@iki.fi>
parents:
9283
diff
changeset
|
346 i_stream_unref(&client->input); |
e30495ae11de
*-login: Moved most of the common code to login-common.
Timo Sirainen <tss@iki.fi>
parents:
9283
diff
changeset
|
347 if (client->output != NULL) |
e30495ae11de
*-login: Moved most of the common code to login-common.
Timo Sirainen <tss@iki.fi>
parents:
9283
diff
changeset
|
348 o_stream_unref(&client->output); |
e30495ae11de
*-login: Moved most of the common code to login-common.
Timo Sirainen <tss@iki.fi>
parents:
9283
diff
changeset
|
349 |
11324
c872378a8de6
login proxy: If passdb returns proxy_refresh=<secs>, send username to proxy-notify fifo every n secs.
Timo Sirainen <tss@iki.fi>
parents:
11257
diff
changeset
|
350 i_free(client->proxy_user); |
c872378a8de6
login proxy: If passdb returns proxy_refresh=<secs>, send username to proxy-notify fifo every n secs.
Timo Sirainen <tss@iki.fi>
parents:
11257
diff
changeset
|
351 i_free(client->proxy_master_user); |
9756
e30495ae11de
*-login: Moved most of the common code to login-common.
Timo Sirainen <tss@iki.fi>
parents:
9283
diff
changeset
|
352 i_free(client->virtual_user); |
16802
a32eea97afc1
*-login: Added %{orig_user}, %{orig_username} and %{orig_domain} variables.
Timo Sirainen <tss@iki.fi>
parents:
16555
diff
changeset
|
353 i_free(client->virtual_user_orig); |
17100
5350000a999b
auth, login, mail: Added %{auth_user}, %{auth_username} and %{auth_domain}
Timo Sirainen <tss@iki.fi>
parents:
16802
diff
changeset
|
354 i_free(client->virtual_auth_user); |
9756
e30495ae11de
*-login: Moved most of the common code to login-common.
Timo Sirainen <tss@iki.fi>
parents:
9283
diff
changeset
|
355 i_free(client->auth_mech_name); |
14369 | 356 i_free(client->master_data_prefix); |
9756
e30495ae11de
*-login: Moved most of the common code to login-common.
Timo Sirainen <tss@iki.fi>
parents:
9283
diff
changeset
|
357 pool_unref(&client->pool); |
9929
d60fa42fbaac
*-login: Fixes to SSL/login proxy connection counting.
Timo Sirainen <tss@iki.fi>
parents:
9923
diff
changeset
|
358 |
10198
3e7e08af2991
*-login: Show better state with verbose_proctitle=yes.
Timo Sirainen <tss@iki.fi>
parents:
10111
diff
changeset
|
359 i_assert(clients_count > 0); |
3e7e08af2991
*-login: Show better state with verbose_proctitle=yes.
Timo Sirainen <tss@iki.fi>
parents:
10111
diff
changeset
|
360 clients_count--; |
3e7e08af2991
*-login: Show better state with verbose_proctitle=yes.
Timo Sirainen <tss@iki.fi>
parents:
10111
diff
changeset
|
361 |
9929
d60fa42fbaac
*-login: Fixes to SSL/login proxy connection counting.
Timo Sirainen <tss@iki.fi>
parents:
9923
diff
changeset
|
362 master_service_client_connection_destroyed(master_service); |
10198
3e7e08af2991
*-login: Show better state with verbose_proctitle=yes.
Timo Sirainen <tss@iki.fi>
parents:
10111
diff
changeset
|
363 login_refresh_proctitle(); |
9756
e30495ae11de
*-login: Moved most of the common code to login-common.
Timo Sirainen <tss@iki.fi>
parents:
9283
diff
changeset
|
364 return FALSE; |
e30495ae11de
*-login: Moved most of the common code to login-common.
Timo Sirainen <tss@iki.fi>
parents:
9283
diff
changeset
|
365 } |
e30495ae11de
*-login: Moved most of the common code to login-common.
Timo Sirainen <tss@iki.fi>
parents:
9283
diff
changeset
|
366 |
22242
589993f80eda
*-login: Add client_vfuncs.free() that is called when client refcount=0
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
21970
diff
changeset
|
367 void client_common_default_free(struct client *client ATTR_UNUSED) |
589993f80eda
*-login: Add client_vfuncs.free() that is called when client refcount=0
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
21970
diff
changeset
|
368 { |
589993f80eda
*-login: Add client_vfuncs.free() that is called when client refcount=0
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
21970
diff
changeset
|
369 } |
589993f80eda
*-login: Add client_vfuncs.free() that is called when client refcount=0
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
21970
diff
changeset
|
370 |
9756
e30495ae11de
*-login: Moved most of the common code to login-common.
Timo Sirainen <tss@iki.fi>
parents:
9283
diff
changeset
|
371 void client_destroy_oldest(void) |
e30495ae11de
*-login: Moved most of the common code to login-common.
Timo Sirainen <tss@iki.fi>
parents:
9283
diff
changeset
|
372 { |
e30495ae11de
*-login: Moved most of the common code to login-common.
Timo Sirainen <tss@iki.fi>
parents:
9283
diff
changeset
|
373 struct client *client; |
e30495ae11de
*-login: Moved most of the common code to login-common.
Timo Sirainen <tss@iki.fi>
parents:
9283
diff
changeset
|
374 |
9923
77228b5431e1
*-login: Fixed dropping oldest connection when reaching all limits.
Timo Sirainen <tss@iki.fi>
parents:
9921
diff
changeset
|
375 if (last_client == NULL) { |
77228b5431e1
*-login: Fixed dropping oldest connection when reaching all limits.
Timo Sirainen <tss@iki.fi>
parents:
9921
diff
changeset
|
376 /* we have no clients */ |
77228b5431e1
*-login: Fixed dropping oldest connection when reaching all limits.
Timo Sirainen <tss@iki.fi>
parents:
9921
diff
changeset
|
377 return; |
9756
e30495ae11de
*-login: Moved most of the common code to login-common.
Timo Sirainen <tss@iki.fi>
parents:
9283
diff
changeset
|
378 } |
e30495ae11de
*-login: Moved most of the common code to login-common.
Timo Sirainen <tss@iki.fi>
parents:
9283
diff
changeset
|
379 |
9923
77228b5431e1
*-login: Fixed dropping oldest connection when reaching all limits.
Timo Sirainen <tss@iki.fi>
parents:
9921
diff
changeset
|
380 /* destroy the last client that hasn't successfully authenticated yet. |
77228b5431e1
*-login: Fixed dropping oldest connection when reaching all limits.
Timo Sirainen <tss@iki.fi>
parents:
9921
diff
changeset
|
381 this is usually the last client, but don't kill it if it's just |
77228b5431e1
*-login: Fixed dropping oldest connection when reaching all limits.
Timo Sirainen <tss@iki.fi>
parents:
9921
diff
changeset
|
382 waiting for master to finish its job. */ |
77228b5431e1
*-login: Fixed dropping oldest connection when reaching all limits.
Timo Sirainen <tss@iki.fi>
parents:
9921
diff
changeset
|
383 for (client = last_client; client != NULL; client = client->prev) { |
77228b5431e1
*-login: Fixed dropping oldest connection when reaching all limits.
Timo Sirainen <tss@iki.fi>
parents:
9921
diff
changeset
|
384 if (client->master_tag == 0) |
9756
e30495ae11de
*-login: Moved most of the common code to login-common.
Timo Sirainen <tss@iki.fi>
parents:
9283
diff
changeset
|
385 break; |
9923
77228b5431e1
*-login: Fixed dropping oldest connection when reaching all limits.
Timo Sirainen <tss@iki.fi>
parents:
9921
diff
changeset
|
386 } |
77228b5431e1
*-login: Fixed dropping oldest connection when reaching all limits.
Timo Sirainen <tss@iki.fi>
parents:
9921
diff
changeset
|
387 if (client == NULL) |
77228b5431e1
*-login: Fixed dropping oldest connection when reaching all limits.
Timo Sirainen <tss@iki.fi>
parents:
9921
diff
changeset
|
388 client = last_client; |
9756
e30495ae11de
*-login: Moved most of the common code to login-common.
Timo Sirainen <tss@iki.fi>
parents:
9283
diff
changeset
|
389 |
14146
e456e1bce47f
login-common API made more extensible for different kinds of protocols.
Timo Sirainen <tss@iki.fi>
parents:
14133
diff
changeset
|
390 client_notify_disconnect(client, CLIENT_DISCONNECT_RESOURCE_CONSTRAINT, |
e456e1bce47f
login-common API made more extensible for different kinds of protocols.
Timo Sirainen <tss@iki.fi>
parents:
14133
diff
changeset
|
391 "Connection queue full"); |
9923
77228b5431e1
*-login: Fixed dropping oldest connection when reaching all limits.
Timo Sirainen <tss@iki.fi>
parents:
9921
diff
changeset
|
392 client_destroy(client, "Disconnected: Connection queue full"); |
9756
e30495ae11de
*-login: Moved most of the common code to login-common.
Timo Sirainen <tss@iki.fi>
parents:
9283
diff
changeset
|
393 } |
e30495ae11de
*-login: Moved most of the common code to login-common.
Timo Sirainen <tss@iki.fi>
parents:
9283
diff
changeset
|
394 |
14171
4462ceb09c0d
login: If auth client disconnects without having ever succeeded, destroy clients.
Timo Sirainen <tss@iki.fi>
parents:
14133
diff
changeset
|
395 void clients_destroy_all_reason(const char *reason) |
9756
e30495ae11de
*-login: Moved most of the common code to login-common.
Timo Sirainen <tss@iki.fi>
parents:
9283
diff
changeset
|
396 { |
e30495ae11de
*-login: Moved most of the common code to login-common.
Timo Sirainen <tss@iki.fi>
parents:
9283
diff
changeset
|
397 struct client *client, *next; |
e30495ae11de
*-login: Moved most of the common code to login-common.
Timo Sirainen <tss@iki.fi>
parents:
9283
diff
changeset
|
398 |
e30495ae11de
*-login: Moved most of the common code to login-common.
Timo Sirainen <tss@iki.fi>
parents:
9283
diff
changeset
|
399 for (client = clients; client != NULL; client = next) { |
e30495ae11de
*-login: Moved most of the common code to login-common.
Timo Sirainen <tss@iki.fi>
parents:
9283
diff
changeset
|
400 next = client->next; |
14146
e456e1bce47f
login-common API made more extensible for different kinds of protocols.
Timo Sirainen <tss@iki.fi>
parents:
14133
diff
changeset
|
401 client_notify_disconnect(client, |
14217 | 402 CLIENT_DISCONNECT_SYSTEM_SHUTDOWN, reason); |
14171
4462ceb09c0d
login: If auth client disconnects without having ever succeeded, destroy clients.
Timo Sirainen <tss@iki.fi>
parents:
14133
diff
changeset
|
403 client_destroy(client, reason); |
9756
e30495ae11de
*-login: Moved most of the common code to login-common.
Timo Sirainen <tss@iki.fi>
parents:
9283
diff
changeset
|
404 } |
e30495ae11de
*-login: Moved most of the common code to login-common.
Timo Sirainen <tss@iki.fi>
parents:
9283
diff
changeset
|
405 } |
e30495ae11de
*-login: Moved most of the common code to login-common.
Timo Sirainen <tss@iki.fi>
parents:
9283
diff
changeset
|
406 |
14171
4462ceb09c0d
login: If auth client disconnects without having ever succeeded, destroy clients.
Timo Sirainen <tss@iki.fi>
parents:
14133
diff
changeset
|
407 void clients_destroy_all(void) |
4462ceb09c0d
login: If auth client disconnects without having ever succeeded, destroy clients.
Timo Sirainen <tss@iki.fi>
parents:
14133
diff
changeset
|
408 { |
4462ceb09c0d
login: If auth client disconnects without having ever succeeded, destroy clients.
Timo Sirainen <tss@iki.fi>
parents:
14133
diff
changeset
|
409 clients_destroy_all_reason("Disconnected: Shutting down"); |
4462ceb09c0d
login: If auth client disconnects without having ever succeeded, destroy clients.
Timo Sirainen <tss@iki.fi>
parents:
14133
diff
changeset
|
410 } |
4462ceb09c0d
login: If auth client disconnects without having ever succeeded, destroy clients.
Timo Sirainen <tss@iki.fi>
parents:
14133
diff
changeset
|
411 |
9756
e30495ae11de
*-login: Moved most of the common code to login-common.
Timo Sirainen <tss@iki.fi>
parents:
9283
diff
changeset
|
412 static void client_start_tls(struct client *client) |
7104
db5f55daa002
Forgot from imap/pop3-login clients hash -> linked list commit.
Timo Sirainen <tss@iki.fi>
parents:
7086
diff
changeset
|
413 { |
9756
e30495ae11de
*-login: Moved most of the common code to login-common.
Timo Sirainen <tss@iki.fi>
parents:
9283
diff
changeset
|
414 int fd_ssl; |
e30495ae11de
*-login: Moved most of the common code to login-common.
Timo Sirainen <tss@iki.fi>
parents:
9283
diff
changeset
|
415 |
e30495ae11de
*-login: Moved most of the common code to login-common.
Timo Sirainen <tss@iki.fi>
parents:
9283
diff
changeset
|
416 client_ref(client); |
9929
d60fa42fbaac
*-login: Fixes to SSL/login proxy connection counting.
Timo Sirainen <tss@iki.fi>
parents:
9923
diff
changeset
|
417 if (!client_unref(&client) || client->destroyed) |
9756
e30495ae11de
*-login: Moved most of the common code to login-common.
Timo Sirainen <tss@iki.fi>
parents:
9283
diff
changeset
|
418 return; |
e30495ae11de
*-login: Moved most of the common code to login-common.
Timo Sirainen <tss@iki.fi>
parents:
9283
diff
changeset
|
419 |
14368 | 420 fd_ssl = ssl_proxy_alloc(client->fd, &client->ip, client->pool, |
14728
983c6ff12cc9
Moved ssl_* settings from login-common to lib-master.
Timo Sirainen <tss@iki.fi>
parents:
14681
diff
changeset
|
421 client->set, client->ssl_set, |
983c6ff12cc9
Moved ssl_* settings from login-common to lib-master.
Timo Sirainen <tss@iki.fi>
parents:
14681
diff
changeset
|
422 &client->ssl_proxy); |
9756
e30495ae11de
*-login: Moved most of the common code to login-common.
Timo Sirainen <tss@iki.fi>
parents:
9283
diff
changeset
|
423 if (fd_ssl == -1) { |
14146
e456e1bce47f
login-common API made more extensible for different kinds of protocols.
Timo Sirainen <tss@iki.fi>
parents:
14133
diff
changeset
|
424 client_notify_disconnect(client, |
e456e1bce47f
login-common API made more extensible for different kinds of protocols.
Timo Sirainen <tss@iki.fi>
parents:
14133
diff
changeset
|
425 CLIENT_DISCONNECT_INTERNAL_ERROR, |
e456e1bce47f
login-common API made more extensible for different kinds of protocols.
Timo Sirainen <tss@iki.fi>
parents:
14133
diff
changeset
|
426 "TLS initialization failed."); |
9756
e30495ae11de
*-login: Moved most of the common code to login-common.
Timo Sirainen <tss@iki.fi>
parents:
9283
diff
changeset
|
427 client_destroy(client, |
14146
e456e1bce47f
login-common API made more extensible for different kinds of protocols.
Timo Sirainen <tss@iki.fi>
parents:
14133
diff
changeset
|
428 "Disconnected: TLS initialization failed."); |
9756
e30495ae11de
*-login: Moved most of the common code to login-common.
Timo Sirainen <tss@iki.fi>
parents:
9283
diff
changeset
|
429 return; |
e30495ae11de
*-login: Moved most of the common code to login-common.
Timo Sirainen <tss@iki.fi>
parents:
9283
diff
changeset
|
430 } |
9929
d60fa42fbaac
*-login: Fixes to SSL/login proxy connection counting.
Timo Sirainen <tss@iki.fi>
parents:
9923
diff
changeset
|
431 ssl_proxy_set_client(client->ssl_proxy, client); |
10224
3f1c47797dee
ssl: Don't start handshake until client has been set.
Timo Sirainen <tss@iki.fi>
parents:
10198
diff
changeset
|
432 ssl_proxy_start(client->ssl_proxy); |
9756
e30495ae11de
*-login: Moved most of the common code to login-common.
Timo Sirainen <tss@iki.fi>
parents:
9283
diff
changeset
|
433 |
e30495ae11de
*-login: Moved most of the common code to login-common.
Timo Sirainen <tss@iki.fi>
parents:
9283
diff
changeset
|
434 client->starttls = TRUE; |
e30495ae11de
*-login: Moved most of the common code to login-common.
Timo Sirainen <tss@iki.fi>
parents:
9283
diff
changeset
|
435 client->tls = TRUE; |
e30495ae11de
*-login: Moved most of the common code to login-common.
Timo Sirainen <tss@iki.fi>
parents:
9283
diff
changeset
|
436 client->secured = TRUE; |
10198
3e7e08af2991
*-login: Show better state with verbose_proctitle=yes.
Timo Sirainen <tss@iki.fi>
parents:
10111
diff
changeset
|
437 login_refresh_proctitle(); |
9756
e30495ae11de
*-login: Moved most of the common code to login-common.
Timo Sirainen <tss@iki.fi>
parents:
9283
diff
changeset
|
438 |
e30495ae11de
*-login: Moved most of the common code to login-common.
Timo Sirainen <tss@iki.fi>
parents:
9283
diff
changeset
|
439 client->fd = fd_ssl; |
e30495ae11de
*-login: Moved most of the common code to login-common.
Timo Sirainen <tss@iki.fi>
parents:
9283
diff
changeset
|
440 client->io = io_add(client->fd, IO_READ, client_input, client); |
e30495ae11de
*-login: Moved most of the common code to login-common.
Timo Sirainen <tss@iki.fi>
parents:
9283
diff
changeset
|
441 i_stream_unref(&client->input); |
e30495ae11de
*-login: Moved most of the common code to login-common.
Timo Sirainen <tss@iki.fi>
parents:
9283
diff
changeset
|
442 o_stream_unref(&client->output); |
e30495ae11de
*-login: Moved most of the common code to login-common.
Timo Sirainen <tss@iki.fi>
parents:
9283
diff
changeset
|
443 client_open_streams(client); |
e30495ae11de
*-login: Moved most of the common code to login-common.
Timo Sirainen <tss@iki.fi>
parents:
9283
diff
changeset
|
444 |
e30495ae11de
*-login: Moved most of the common code to login-common.
Timo Sirainen <tss@iki.fi>
parents:
9283
diff
changeset
|
445 client->v.starttls(client); |
e30495ae11de
*-login: Moved most of the common code to login-common.
Timo Sirainen <tss@iki.fi>
parents:
9283
diff
changeset
|
446 } |
e30495ae11de
*-login: Moved most of the common code to login-common.
Timo Sirainen <tss@iki.fi>
parents:
9283
diff
changeset
|
447 |
e30495ae11de
*-login: Moved most of the common code to login-common.
Timo Sirainen <tss@iki.fi>
parents:
9283
diff
changeset
|
448 static int client_output_starttls(struct client *client) |
e30495ae11de
*-login: Moved most of the common code to login-common.
Timo Sirainen <tss@iki.fi>
parents:
9283
diff
changeset
|
449 { |
e30495ae11de
*-login: Moved most of the common code to login-common.
Timo Sirainen <tss@iki.fi>
parents:
9283
diff
changeset
|
450 int ret; |
e30495ae11de
*-login: Moved most of the common code to login-common.
Timo Sirainen <tss@iki.fi>
parents:
9283
diff
changeset
|
451 |
e30495ae11de
*-login: Moved most of the common code to login-common.
Timo Sirainen <tss@iki.fi>
parents:
9283
diff
changeset
|
452 if ((ret = o_stream_flush(client->output)) < 0) { |
e30495ae11de
*-login: Moved most of the common code to login-common.
Timo Sirainen <tss@iki.fi>
parents:
9283
diff
changeset
|
453 client_destroy(client, "Disconnected"); |
e30495ae11de
*-login: Moved most of the common code to login-common.
Timo Sirainen <tss@iki.fi>
parents:
9283
diff
changeset
|
454 return 1; |
e30495ae11de
*-login: Moved most of the common code to login-common.
Timo Sirainen <tss@iki.fi>
parents:
9283
diff
changeset
|
455 } |
7104
db5f55daa002
Forgot from imap/pop3-login clients hash -> linked list commit.
Timo Sirainen <tss@iki.fi>
parents:
7086
diff
changeset
|
456 |
9756
e30495ae11de
*-login: Moved most of the common code to login-common.
Timo Sirainen <tss@iki.fi>
parents:
9283
diff
changeset
|
457 if (ret > 0) { |
e30495ae11de
*-login: Moved most of the common code to login-common.
Timo Sirainen <tss@iki.fi>
parents:
9283
diff
changeset
|
458 o_stream_unset_flush_callback(client->output); |
e30495ae11de
*-login: Moved most of the common code to login-common.
Timo Sirainen <tss@iki.fi>
parents:
9283
diff
changeset
|
459 client_start_tls(client); |
e30495ae11de
*-login: Moved most of the common code to login-common.
Timo Sirainen <tss@iki.fi>
parents:
9283
diff
changeset
|
460 } |
e30495ae11de
*-login: Moved most of the common code to login-common.
Timo Sirainen <tss@iki.fi>
parents:
9283
diff
changeset
|
461 return 1; |
e30495ae11de
*-login: Moved most of the common code to login-common.
Timo Sirainen <tss@iki.fi>
parents:
9283
diff
changeset
|
462 } |
e30495ae11de
*-login: Moved most of the common code to login-common.
Timo Sirainen <tss@iki.fi>
parents:
9283
diff
changeset
|
463 |
e30495ae11de
*-login: Moved most of the common code to login-common.
Timo Sirainen <tss@iki.fi>
parents:
9283
diff
changeset
|
464 void client_cmd_starttls(struct client *client) |
e30495ae11de
*-login: Moved most of the common code to login-common.
Timo Sirainen <tss@iki.fi>
parents:
9283
diff
changeset
|
465 { |
e30495ae11de
*-login: Moved most of the common code to login-common.
Timo Sirainen <tss@iki.fi>
parents:
9283
diff
changeset
|
466 if (client->tls) { |
14146
e456e1bce47f
login-common API made more extensible for different kinds of protocols.
Timo Sirainen <tss@iki.fi>
parents:
14133
diff
changeset
|
467 client->v.notify_starttls(client, FALSE, "TLS is already active."); |
9756
e30495ae11de
*-login: Moved most of the common code to login-common.
Timo Sirainen <tss@iki.fi>
parents:
9283
diff
changeset
|
468 return; |
e30495ae11de
*-login: Moved most of the common code to login-common.
Timo Sirainen <tss@iki.fi>
parents:
9283
diff
changeset
|
469 } |
e30495ae11de
*-login: Moved most of the common code to login-common.
Timo Sirainen <tss@iki.fi>
parents:
9283
diff
changeset
|
470 |
14800
258c2e231357
login: Don't allow STARTTLS if ssl=no in client's settings, even if ssl=yes globally.
Timo Sirainen <tss@iki.fi>
parents:
14566
diff
changeset
|
471 if (!client_is_tls_enabled(client)) { |
14146
e456e1bce47f
login-common API made more extensible for different kinds of protocols.
Timo Sirainen <tss@iki.fi>
parents:
14133
diff
changeset
|
472 client->v.notify_starttls(client, FALSE, "TLS support isn't enabled."); |
9756
e30495ae11de
*-login: Moved most of the common code to login-common.
Timo Sirainen <tss@iki.fi>
parents:
9283
diff
changeset
|
473 return; |
e30495ae11de
*-login: Moved most of the common code to login-common.
Timo Sirainen <tss@iki.fi>
parents:
9283
diff
changeset
|
474 } |
e30495ae11de
*-login: Moved most of the common code to login-common.
Timo Sirainen <tss@iki.fi>
parents:
9283
diff
changeset
|
475 |
e30495ae11de
*-login: Moved most of the common code to login-common.
Timo Sirainen <tss@iki.fi>
parents:
9283
diff
changeset
|
476 /* remove input handler, SSL proxy gives us a new fd. we also have to |
e30495ae11de
*-login: Moved most of the common code to login-common.
Timo Sirainen <tss@iki.fi>
parents:
9283
diff
changeset
|
477 remove it in case we have to wait for buffer to be flushed */ |
e30495ae11de
*-login: Moved most of the common code to login-common.
Timo Sirainen <tss@iki.fi>
parents:
9283
diff
changeset
|
478 if (client->io != NULL) |
e30495ae11de
*-login: Moved most of the common code to login-common.
Timo Sirainen <tss@iki.fi>
parents:
9283
diff
changeset
|
479 io_remove(&client->io); |
e30495ae11de
*-login: Moved most of the common code to login-common.
Timo Sirainen <tss@iki.fi>
parents:
9283
diff
changeset
|
480 |
14146
e456e1bce47f
login-common API made more extensible for different kinds of protocols.
Timo Sirainen <tss@iki.fi>
parents:
14133
diff
changeset
|
481 client->v.notify_starttls(client, TRUE, "Begin TLS negotiation now."); |
9756
e30495ae11de
*-login: Moved most of the common code to login-common.
Timo Sirainen <tss@iki.fi>
parents:
9283
diff
changeset
|
482 |
e30495ae11de
*-login: Moved most of the common code to login-common.
Timo Sirainen <tss@iki.fi>
parents:
9283
diff
changeset
|
483 /* uncork the old fd */ |
e30495ae11de
*-login: Moved most of the common code to login-common.
Timo Sirainen <tss@iki.fi>
parents:
9283
diff
changeset
|
484 o_stream_uncork(client->output); |
e30495ae11de
*-login: Moved most of the common code to login-common.
Timo Sirainen <tss@iki.fi>
parents:
9283
diff
changeset
|
485 |
e30495ae11de
*-login: Moved most of the common code to login-common.
Timo Sirainen <tss@iki.fi>
parents:
9283
diff
changeset
|
486 if (o_stream_flush(client->output) <= 0) { |
e30495ae11de
*-login: Moved most of the common code to login-common.
Timo Sirainen <tss@iki.fi>
parents:
9283
diff
changeset
|
487 /* the buffer has to be flushed */ |
e30495ae11de
*-login: Moved most of the common code to login-common.
Timo Sirainen <tss@iki.fi>
parents:
9283
diff
changeset
|
488 o_stream_set_flush_pending(client->output, TRUE); |
e30495ae11de
*-login: Moved most of the common code to login-common.
Timo Sirainen <tss@iki.fi>
parents:
9283
diff
changeset
|
489 o_stream_set_flush_callback(client->output, |
e30495ae11de
*-login: Moved most of the common code to login-common.
Timo Sirainen <tss@iki.fi>
parents:
9283
diff
changeset
|
490 client_output_starttls, client); |
e30495ae11de
*-login: Moved most of the common code to login-common.
Timo Sirainen <tss@iki.fi>
parents:
9283
diff
changeset
|
491 } else { |
e30495ae11de
*-login: Moved most of the common code to login-common.
Timo Sirainen <tss@iki.fi>
parents:
9283
diff
changeset
|
492 client_start_tls(client); |
e30495ae11de
*-login: Moved most of the common code to login-common.
Timo Sirainen <tss@iki.fi>
parents:
9283
diff
changeset
|
493 } |
7104
db5f55daa002
Forgot from imap/pop3-login clients hash -> linked list commit.
Timo Sirainen <tss@iki.fi>
parents:
7086
diff
changeset
|
494 } |
db5f55daa002
Forgot from imap/pop3-login clients hash -> linked list commit.
Timo Sirainen <tss@iki.fi>
parents:
7086
diff
changeset
|
495 |
db5f55daa002
Forgot from imap/pop3-login clients hash -> linked list commit.
Timo Sirainen <tss@iki.fi>
parents:
7086
diff
changeset
|
496 unsigned int clients_get_count(void) |
db5f55daa002
Forgot from imap/pop3-login clients hash -> linked list commit.
Timo Sirainen <tss@iki.fi>
parents:
7086
diff
changeset
|
497 { |
db5f55daa002
Forgot from imap/pop3-login clients hash -> linked list commit.
Timo Sirainen <tss@iki.fi>
parents:
7086
diff
changeset
|
498 return clients_count; |
db5f55daa002
Forgot from imap/pop3-login clients hash -> linked list commit.
Timo Sirainen <tss@iki.fi>
parents:
7086
diff
changeset
|
499 } |
db5f55daa002
Forgot from imap/pop3-login clients hash -> linked list commit.
Timo Sirainen <tss@iki.fi>
parents:
7086
diff
changeset
|
500 |
21820
de6920764b89
imap-login: Move forward_fields updating code to login-common
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
21765
diff
changeset
|
501 void client_add_forward_field(struct client *client, const char *key, |
de6920764b89
imap-login: Move forward_fields updating code to login-common
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
21765
diff
changeset
|
502 const char *value) |
de6920764b89
imap-login: Move forward_fields updating code to login-common
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
21765
diff
changeset
|
503 { |
de6920764b89
imap-login: Move forward_fields updating code to login-common
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
21765
diff
changeset
|
504 if (client->forward_fields == NULL) |
de6920764b89
imap-login: Move forward_fields updating code to login-common
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
21765
diff
changeset
|
505 client->forward_fields = str_new(client->preproxy_pool, 32); |
de6920764b89
imap-login: Move forward_fields updating code to login-common
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
21765
diff
changeset
|
506 else |
de6920764b89
imap-login: Move forward_fields updating code to login-common
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
21765
diff
changeset
|
507 str_append_c(client->forward_fields, '\t'); |
de6920764b89
imap-login: Move forward_fields updating code to login-common
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
21765
diff
changeset
|
508 /* prefixing is done by auth process */ |
de6920764b89
imap-login: Move forward_fields updating code to login-common
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
21765
diff
changeset
|
509 str_append_tabescaped(client->forward_fields, key); |
de6920764b89
imap-login: Move forward_fields updating code to login-common
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
21765
diff
changeset
|
510 str_append_c(client->forward_fields, '='); |
de6920764b89
imap-login: Move forward_fields updating code to login-common
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
21765
diff
changeset
|
511 str_append_tabescaped(client->forward_fields, value); |
de6920764b89
imap-login: Move forward_fields updating code to login-common
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
21765
diff
changeset
|
512 } |
de6920764b89
imap-login: Move forward_fields updating code to login-common
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
21765
diff
changeset
|
513 |
14302
5bbcf636bbeb
Added a "session ID" string for imap/pop3 connections, available in %{session} variable.
Timo Sirainen <tss@iki.fi>
parents:
14300
diff
changeset
|
514 const char *client_get_session_id(struct client *client) |
5bbcf636bbeb
Added a "session ID" string for imap/pop3 connections, available in %{session} variable.
Timo Sirainen <tss@iki.fi>
parents:
14300
diff
changeset
|
515 { |
5bbcf636bbeb
Added a "session ID" string for imap/pop3 connections, available in %{session} variable.
Timo Sirainen <tss@iki.fi>
parents:
14300
diff
changeset
|
516 buffer_t *buf, *base64_buf; |
5bbcf636bbeb
Added a "session ID" string for imap/pop3 connections, available in %{session} variable.
Timo Sirainen <tss@iki.fi>
parents:
14300
diff
changeset
|
517 struct timeval tv; |
5bbcf636bbeb
Added a "session ID" string for imap/pop3 connections, available in %{session} variable.
Timo Sirainen <tss@iki.fi>
parents:
14300
diff
changeset
|
518 uint64_t timestamp; |
5bbcf636bbeb
Added a "session ID" string for imap/pop3 connections, available in %{session} variable.
Timo Sirainen <tss@iki.fi>
parents:
14300
diff
changeset
|
519 unsigned int i; |
5bbcf636bbeb
Added a "session ID" string for imap/pop3 connections, available in %{session} variable.
Timo Sirainen <tss@iki.fi>
parents:
14300
diff
changeset
|
520 |
5bbcf636bbeb
Added a "session ID" string for imap/pop3 connections, available in %{session} variable.
Timo Sirainen <tss@iki.fi>
parents:
14300
diff
changeset
|
521 if (client->session_id != NULL) |
5bbcf636bbeb
Added a "session ID" string for imap/pop3 connections, available in %{session} variable.
Timo Sirainen <tss@iki.fi>
parents:
14300
diff
changeset
|
522 return client->session_id; |
5bbcf636bbeb
Added a "session ID" string for imap/pop3 connections, available in %{session} variable.
Timo Sirainen <tss@iki.fi>
parents:
14300
diff
changeset
|
523 |
5bbcf636bbeb
Added a "session ID" string for imap/pop3 connections, available in %{session} variable.
Timo Sirainen <tss@iki.fi>
parents:
14300
diff
changeset
|
524 buf = buffer_create_dynamic(pool_datastack_create(), 24); |
5bbcf636bbeb
Added a "session ID" string for imap/pop3 connections, available in %{session} variable.
Timo Sirainen <tss@iki.fi>
parents:
14300
diff
changeset
|
525 base64_buf = buffer_create_dynamic(pool_datastack_create(), 24*2); |
5bbcf636bbeb
Added a "session ID" string for imap/pop3 connections, available in %{session} variable.
Timo Sirainen <tss@iki.fi>
parents:
14300
diff
changeset
|
526 |
5bbcf636bbeb
Added a "session ID" string for imap/pop3 connections, available in %{session} variable.
Timo Sirainen <tss@iki.fi>
parents:
14300
diff
changeset
|
527 if (gettimeofday(&tv, NULL) < 0) |
5bbcf636bbeb
Added a "session ID" string for imap/pop3 connections, available in %{session} variable.
Timo Sirainen <tss@iki.fi>
parents:
14300
diff
changeset
|
528 i_fatal("gettimeofday(): %m"); |
5bbcf636bbeb
Added a "session ID" string for imap/pop3 connections, available in %{session} variable.
Timo Sirainen <tss@iki.fi>
parents:
14300
diff
changeset
|
529 timestamp = tv.tv_usec + (long long)tv.tv_sec * 1000ULL*1000ULL; |
5bbcf636bbeb
Added a "session ID" string for imap/pop3 connections, available in %{session} variable.
Timo Sirainen <tss@iki.fi>
parents:
14300
diff
changeset
|
530 |
5bbcf636bbeb
Added a "session ID" string for imap/pop3 connections, available in %{session} variable.
Timo Sirainen <tss@iki.fi>
parents:
14300
diff
changeset
|
531 /* add lowest 48 bits of the timestamp. this gives us a bit less than |
5bbcf636bbeb
Added a "session ID" string for imap/pop3 connections, available in %{session} variable.
Timo Sirainen <tss@iki.fi>
parents:
14300
diff
changeset
|
532 9 years until it wraps */ |
5bbcf636bbeb
Added a "session ID" string for imap/pop3 connections, available in %{session} variable.
Timo Sirainen <tss@iki.fi>
parents:
14300
diff
changeset
|
533 for (i = 0; i < 48; i += 8) |
5bbcf636bbeb
Added a "session ID" string for imap/pop3 connections, available in %{session} variable.
Timo Sirainen <tss@iki.fi>
parents:
14300
diff
changeset
|
534 buffer_append_c(buf, (timestamp >> i) & 0xff); |
5bbcf636bbeb
Added a "session ID" string for imap/pop3 connections, available in %{session} variable.
Timo Sirainen <tss@iki.fi>
parents:
14300
diff
changeset
|
535 |
5bbcf636bbeb
Added a "session ID" string for imap/pop3 connections, available in %{session} variable.
Timo Sirainen <tss@iki.fi>
parents:
14300
diff
changeset
|
536 buffer_append_c(buf, client->remote_port & 0xff); |
19225
038efefc7e70
*-login: Session ID generator wasn't encoding remote port number correctly to it.
Timo Sirainen <tss@iki.fi>
parents:
19191
diff
changeset
|
537 buffer_append_c(buf, (client->remote_port >> 8) & 0xff); |
14302
5bbcf636bbeb
Added a "session ID" string for imap/pop3 connections, available in %{session} variable.
Timo Sirainen <tss@iki.fi>
parents:
14300
diff
changeset
|
538 #ifdef HAVE_IPV6 |
5bbcf636bbeb
Added a "session ID" string for imap/pop3 connections, available in %{session} variable.
Timo Sirainen <tss@iki.fi>
parents:
14300
diff
changeset
|
539 if (IPADDR_IS_V6(&client->ip)) |
5bbcf636bbeb
Added a "session ID" string for imap/pop3 connections, available in %{session} variable.
Timo Sirainen <tss@iki.fi>
parents:
14300
diff
changeset
|
540 buffer_append(buf, &client->ip.u.ip6, sizeof(client->ip.u.ip6)); |
5bbcf636bbeb
Added a "session ID" string for imap/pop3 connections, available in %{session} variable.
Timo Sirainen <tss@iki.fi>
parents:
14300
diff
changeset
|
541 else |
5bbcf636bbeb
Added a "session ID" string for imap/pop3 connections, available in %{session} variable.
Timo Sirainen <tss@iki.fi>
parents:
14300
diff
changeset
|
542 #endif |
5bbcf636bbeb
Added a "session ID" string for imap/pop3 connections, available in %{session} variable.
Timo Sirainen <tss@iki.fi>
parents:
14300
diff
changeset
|
543 buffer_append(buf, &client->ip.u.ip4, sizeof(client->ip.u.ip4)); |
5bbcf636bbeb
Added a "session ID" string for imap/pop3 connections, available in %{session} variable.
Timo Sirainen <tss@iki.fi>
parents:
14300
diff
changeset
|
544 base64_encode(buf->data, buf->used, base64_buf); |
5bbcf636bbeb
Added a "session ID" string for imap/pop3 connections, available in %{session} variable.
Timo Sirainen <tss@iki.fi>
parents:
14300
diff
changeset
|
545 client->session_id = p_strdup(client->pool, str_c(base64_buf)); |
5bbcf636bbeb
Added a "session ID" string for imap/pop3 connections, available in %{session} variable.
Timo Sirainen <tss@iki.fi>
parents:
14300
diff
changeset
|
546 return client->session_id; |
5bbcf636bbeb
Added a "session ID" string for imap/pop3 connections, available in %{session} variable.
Timo Sirainen <tss@iki.fi>
parents:
14300
diff
changeset
|
547 } |
5bbcf636bbeb
Added a "session ID" string for imap/pop3 connections, available in %{session} variable.
Timo Sirainen <tss@iki.fi>
parents:
14300
diff
changeset
|
548 |
14300
9b78e93e5b71
login_log_format_elements: Allow using %{long_variables} without breaking.
Timo Sirainen <tss@iki.fi>
parents:
14247
diff
changeset
|
549 static struct var_expand_table login_var_expand_empty_tab[] = { |
9b78e93e5b71
login_log_format_elements: Allow using %{long_variables} without breaking.
Timo Sirainen <tss@iki.fi>
parents:
14247
diff
changeset
|
550 { 'u', NULL, "user" }, |
9b78e93e5b71
login_log_format_elements: Allow using %{long_variables} without breaking.
Timo Sirainen <tss@iki.fi>
parents:
14247
diff
changeset
|
551 { 'n', NULL, "username" }, |
9b78e93e5b71
login_log_format_elements: Allow using %{long_variables} without breaking.
Timo Sirainen <tss@iki.fi>
parents:
14247
diff
changeset
|
552 { 'd', NULL, "domain" }, |
16802
a32eea97afc1
*-login: Added %{orig_user}, %{orig_username} and %{orig_domain} variables.
Timo Sirainen <tss@iki.fi>
parents:
16555
diff
changeset
|
553 |
14300
9b78e93e5b71
login_log_format_elements: Allow using %{long_variables} without breaking.
Timo Sirainen <tss@iki.fi>
parents:
14247
diff
changeset
|
554 { 's', NULL, "service" }, |
9b78e93e5b71
login_log_format_elements: Allow using %{long_variables} without breaking.
Timo Sirainen <tss@iki.fi>
parents:
14247
diff
changeset
|
555 { 'h', NULL, "home" }, |
9b78e93e5b71
login_log_format_elements: Allow using %{long_variables} without breaking.
Timo Sirainen <tss@iki.fi>
parents:
14247
diff
changeset
|
556 { 'l', NULL, "lip" }, |
9b78e93e5b71
login_log_format_elements: Allow using %{long_variables} without breaking.
Timo Sirainen <tss@iki.fi>
parents:
14247
diff
changeset
|
557 { 'r', NULL, "rip" }, |
9b78e93e5b71
login_log_format_elements: Allow using %{long_variables} without breaking.
Timo Sirainen <tss@iki.fi>
parents:
14247
diff
changeset
|
558 { 'p', NULL, "pid" }, |
9b78e93e5b71
login_log_format_elements: Allow using %{long_variables} without breaking.
Timo Sirainen <tss@iki.fi>
parents:
14247
diff
changeset
|
559 { 'm', NULL, "mech" }, |
9b78e93e5b71
login_log_format_elements: Allow using %{long_variables} without breaking.
Timo Sirainen <tss@iki.fi>
parents:
14247
diff
changeset
|
560 { 'a', NULL, "lport" }, |
9b78e93e5b71
login_log_format_elements: Allow using %{long_variables} without breaking.
Timo Sirainen <tss@iki.fi>
parents:
14247
diff
changeset
|
561 { 'b', NULL, "rport" }, |
9b78e93e5b71
login_log_format_elements: Allow using %{long_variables} without breaking.
Timo Sirainen <tss@iki.fi>
parents:
14247
diff
changeset
|
562 { 'c', NULL, "secured" }, |
9b78e93e5b71
login_log_format_elements: Allow using %{long_variables} without breaking.
Timo Sirainen <tss@iki.fi>
parents:
14247
diff
changeset
|
563 { 'k', NULL, "ssl_security" }, |
9b78e93e5b71
login_log_format_elements: Allow using %{long_variables} without breaking.
Timo Sirainen <tss@iki.fi>
parents:
14247
diff
changeset
|
564 { 'e', NULL, "mail_pid" }, |
14302
5bbcf636bbeb
Added a "session ID" string for imap/pop3 connections, available in %{session} variable.
Timo Sirainen <tss@iki.fi>
parents:
14300
diff
changeset
|
565 { '\0', NULL, "session" }, |
15888
c43fcfa2c4b4
auth: Added real_[lr]ip, real_[lr]port variables.
Timo Sirainen <tss@iki.fi>
parents:
15715
diff
changeset
|
566 { '\0', NULL, "real_lip" }, |
15317
92364817f4ba
login_log_format_elements: Added %{real_rip} variable.
Timo Sirainen <tss@iki.fi>
parents:
14800
diff
changeset
|
567 { '\0', NULL, "real_rip" }, |
15888
c43fcfa2c4b4
auth: Added real_[lr]ip, real_[lr]port variables.
Timo Sirainen <tss@iki.fi>
parents:
15715
diff
changeset
|
568 { '\0', NULL, "real_lport" }, |
c43fcfa2c4b4
auth: Added real_[lr]ip, real_[lr]port variables.
Timo Sirainen <tss@iki.fi>
parents:
15715
diff
changeset
|
569 { '\0', NULL, "real_rport" }, |
16802
a32eea97afc1
*-login: Added %{orig_user}, %{orig_username} and %{orig_domain} variables.
Timo Sirainen <tss@iki.fi>
parents:
16555
diff
changeset
|
570 { '\0', NULL, "orig_user" }, |
a32eea97afc1
*-login: Added %{orig_user}, %{orig_username} and %{orig_domain} variables.
Timo Sirainen <tss@iki.fi>
parents:
16555
diff
changeset
|
571 { '\0', NULL, "orig_username" }, |
a32eea97afc1
*-login: Added %{orig_user}, %{orig_username} and %{orig_domain} variables.
Timo Sirainen <tss@iki.fi>
parents:
16555
diff
changeset
|
572 { '\0', NULL, "orig_domain" }, |
17100
5350000a999b
auth, login, mail: Added %{auth_user}, %{auth_username} and %{auth_domain}
Timo Sirainen <tss@iki.fi>
parents:
16802
diff
changeset
|
573 { '\0', NULL, "auth_user" }, |
5350000a999b
auth, login, mail: Added %{auth_user}, %{auth_username} and %{auth_domain}
Timo Sirainen <tss@iki.fi>
parents:
16802
diff
changeset
|
574 { '\0', NULL, "auth_username" }, |
5350000a999b
auth, login, mail: Added %{auth_user}, %{auth_username} and %{auth_domain}
Timo Sirainen <tss@iki.fi>
parents:
16802
diff
changeset
|
575 { '\0', NULL, "auth_domain" }, |
19010
a919414e68d2
login_log_format_elements: Added %{listener} variable to expand to the listener socket name.
Timo Sirainen <tss@iki.fi>
parents:
18950
diff
changeset
|
576 { '\0', NULL, "listener" }, |
20929
2c626fd876ad
login-common: Include local_name in login_var_expand_table
Aki Tuomi <aki.tuomi@dovecot.fi>
parents:
19572
diff
changeset
|
577 { '\0', NULL, "local_name" }, |
14300
9b78e93e5b71
login_log_format_elements: Allow using %{long_variables} without breaking.
Timo Sirainen <tss@iki.fi>
parents:
14247
diff
changeset
|
578 { '\0', NULL, NULL } |
9b78e93e5b71
login_log_format_elements: Allow using %{long_variables} without breaking.
Timo Sirainen <tss@iki.fi>
parents:
14247
diff
changeset
|
579 }; |
9b78e93e5b71
login_log_format_elements: Allow using %{long_variables} without breaking.
Timo Sirainen <tss@iki.fi>
parents:
14247
diff
changeset
|
580 |
17100
5350000a999b
auth, login, mail: Added %{auth_user}, %{auth_username} and %{auth_domain}
Timo Sirainen <tss@iki.fi>
parents:
16802
diff
changeset
|
581 static void |
5350000a999b
auth, login, mail: Added %{auth_user}, %{auth_username} and %{auth_domain}
Timo Sirainen <tss@iki.fi>
parents:
16802
diff
changeset
|
582 get_var_expand_users(struct var_expand_table *tab, const char *user) |
5350000a999b
auth, login, mail: Added %{auth_user}, %{auth_username} and %{auth_domain}
Timo Sirainen <tss@iki.fi>
parents:
16802
diff
changeset
|
583 { |
5350000a999b
auth, login, mail: Added %{auth_user}, %{auth_username} and %{auth_domain}
Timo Sirainen <tss@iki.fi>
parents:
16802
diff
changeset
|
584 unsigned int i; |
5350000a999b
auth, login, mail: Added %{auth_user}, %{auth_username} and %{auth_domain}
Timo Sirainen <tss@iki.fi>
parents:
16802
diff
changeset
|
585 |
5350000a999b
auth, login, mail: Added %{auth_user}, %{auth_username} and %{auth_domain}
Timo Sirainen <tss@iki.fi>
parents:
16802
diff
changeset
|
586 tab[0].value = user; |
5350000a999b
auth, login, mail: Added %{auth_user}, %{auth_username} and %{auth_domain}
Timo Sirainen <tss@iki.fi>
parents:
16802
diff
changeset
|
587 tab[1].value = t_strcut(user, '@'); |
5350000a999b
auth, login, mail: Added %{auth_user}, %{auth_username} and %{auth_domain}
Timo Sirainen <tss@iki.fi>
parents:
16802
diff
changeset
|
588 tab[2].value = strchr(user, '@'); |
5350000a999b
auth, login, mail: Added %{auth_user}, %{auth_username} and %{auth_domain}
Timo Sirainen <tss@iki.fi>
parents:
16802
diff
changeset
|
589 if (tab[2].value != NULL) tab[2].value++; |
5350000a999b
auth, login, mail: Added %{auth_user}, %{auth_username} and %{auth_domain}
Timo Sirainen <tss@iki.fi>
parents:
16802
diff
changeset
|
590 |
5350000a999b
auth, login, mail: Added %{auth_user}, %{auth_username} and %{auth_domain}
Timo Sirainen <tss@iki.fi>
parents:
16802
diff
changeset
|
591 for (i = 0; i < 3; i++) |
5350000a999b
auth, login, mail: Added %{auth_user}, %{auth_username} and %{auth_domain}
Timo Sirainen <tss@iki.fi>
parents:
16802
diff
changeset
|
592 tab[i].value = str_sanitize(tab[i].value, 80); |
5350000a999b
auth, login, mail: Added %{auth_user}, %{auth_username} and %{auth_domain}
Timo Sirainen <tss@iki.fi>
parents:
16802
diff
changeset
|
593 } |
5350000a999b
auth, login, mail: Added %{auth_user}, %{auth_username} and %{auth_domain}
Timo Sirainen <tss@iki.fi>
parents:
16802
diff
changeset
|
594 |
3384
3b75956d20c4
Added configurable logging for login process. Added configurable pop3 logout
Timo Sirainen <tss@iki.fi>
parents:
2737
diff
changeset
|
595 static const struct var_expand_table * |
3b75956d20c4
Added configurable logging for login process. Added configurable pop3 logout
Timo Sirainen <tss@iki.fi>
parents:
2737
diff
changeset
|
596 get_var_expand_table(struct client *client) |
2737 | 597 { |
3384
3b75956d20c4
Added configurable logging for login process. Added configurable pop3 logout
Timo Sirainen <tss@iki.fi>
parents:
2737
diff
changeset
|
598 struct var_expand_table *tab; |
3b75956d20c4
Added configurable logging for login process. Added configurable pop3 logout
Timo Sirainen <tss@iki.fi>
parents:
2737
diff
changeset
|
599 |
14300
9b78e93e5b71
login_log_format_elements: Allow using %{long_variables} without breaking.
Timo Sirainen <tss@iki.fi>
parents:
14247
diff
changeset
|
600 tab = t_malloc(sizeof(login_var_expand_empty_tab)); |
9b78e93e5b71
login_log_format_elements: Allow using %{long_variables} without breaking.
Timo Sirainen <tss@iki.fi>
parents:
14247
diff
changeset
|
601 memcpy(tab, login_var_expand_empty_tab, |
9b78e93e5b71
login_log_format_elements: Allow using %{long_variables} without breaking.
Timo Sirainen <tss@iki.fi>
parents:
14247
diff
changeset
|
602 sizeof(login_var_expand_empty_tab)); |
2737 | 603 |
17100
5350000a999b
auth, login, mail: Added %{auth_user}, %{auth_username} and %{auth_domain}
Timo Sirainen <tss@iki.fi>
parents:
16802
diff
changeset
|
604 if (client->virtual_user != NULL) |
5350000a999b
auth, login, mail: Added %{auth_user}, %{auth_username} and %{auth_domain}
Timo Sirainen <tss@iki.fi>
parents:
16802
diff
changeset
|
605 get_var_expand_users(tab, client->virtual_user); |
12890
6f0396e35fd9
login-common API redesign so that the library doesn't refer to nonexistent variables.
Timo Sirainen <tss@iki.fi>
parents:
12782
diff
changeset
|
606 tab[3].value = login_binary->protocol; |
3384
3b75956d20c4
Added configurable logging for login process. Added configurable pop3 logout
Timo Sirainen <tss@iki.fi>
parents:
2737
diff
changeset
|
607 tab[4].value = getenv("HOME"); |
3b75956d20c4
Added configurable logging for login process. Added configurable pop3 logout
Timo Sirainen <tss@iki.fi>
parents:
2737
diff
changeset
|
608 tab[5].value = net_ip2addr(&client->local_ip); |
3b75956d20c4
Added configurable logging for login process. Added configurable pop3 logout
Timo Sirainen <tss@iki.fi>
parents:
2737
diff
changeset
|
609 tab[6].value = net_ip2addr(&client->ip); |
3b75956d20c4
Added configurable logging for login process. Added configurable pop3 logout
Timo Sirainen <tss@iki.fi>
parents:
2737
diff
changeset
|
610 tab[7].value = my_pid; |
3b75956d20c4
Added configurable logging for login process. Added configurable pop3 logout
Timo Sirainen <tss@iki.fi>
parents:
2737
diff
changeset
|
611 tab[8].value = client->auth_mech_name == NULL ? NULL : |
3b75956d20c4
Added configurable logging for login process. Added configurable pop3 logout
Timo Sirainen <tss@iki.fi>
parents:
2737
diff
changeset
|
612 str_sanitize(client->auth_mech_name, MAX_MECH_NAME); |
4861
a688269c0dd4
Added %a=local port and %b=remote port variables for
Timo Sirainen <tss@iki.fi>
parents:
4570
diff
changeset
|
613 tab[9].value = dec2str(client->local_port); |
a688269c0dd4
Added %a=local port and %b=remote port variables for
Timo Sirainen <tss@iki.fi>
parents:
4570
diff
changeset
|
614 tab[10].value = dec2str(client->remote_port); |
4570
cbbe2377f591
If SSL/TLS handshake didn't finish, show "TLS handshaking" instead of "TLS"
Timo Sirainen <tss@iki.fi>
parents:
3863
diff
changeset
|
615 if (!client->tls) { |
4861
a688269c0dd4
Added %a=local port and %b=remote port variables for
Timo Sirainen <tss@iki.fi>
parents:
4570
diff
changeset
|
616 tab[11].value = client->secured ? "secured" : NULL; |
8122
3917bf9cf311
login_log_format_elements: Added %k to show SSL protocol/cipher information.
Timo Sirainen <tss@iki.fi>
parents:
8092
diff
changeset
|
617 tab[12].value = ""; |
4570
cbbe2377f591
If SSL/TLS handshake didn't finish, show "TLS handshaking" instead of "TLS"
Timo Sirainen <tss@iki.fi>
parents:
3863
diff
changeset
|
618 } else { |
9756
e30495ae11de
*-login: Moved most of the common code to login-common.
Timo Sirainen <tss@iki.fi>
parents:
9283
diff
changeset
|
619 const char *ssl_state = |
e30495ae11de
*-login: Moved most of the common code to login-common.
Timo Sirainen <tss@iki.fi>
parents:
9283
diff
changeset
|
620 ssl_proxy_is_handshaked(client->ssl_proxy) ? |
7374
0bb3fc72a74f
If TLS connection closes with anything except a clean disconnection, log the
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
621 "TLS" : "TLS handshaking"; |
9756
e30495ae11de
*-login: Moved most of the common code to login-common.
Timo Sirainen <tss@iki.fi>
parents:
9283
diff
changeset
|
622 const char *ssl_error = |
e30495ae11de
*-login: Moved most of the common code to login-common.
Timo Sirainen <tss@iki.fi>
parents:
9283
diff
changeset
|
623 ssl_proxy_get_last_error(client->ssl_proxy); |
7374
0bb3fc72a74f
If TLS connection closes with anything except a clean disconnection, log the
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
624 |
0bb3fc72a74f
If TLS connection closes with anything except a clean disconnection, log the
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
625 tab[11].value = ssl_error == NULL ? ssl_state : |
0bb3fc72a74f
If TLS connection closes with anything except a clean disconnection, log the
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
626 t_strdup_printf("%s: %s", ssl_state, ssl_error); |
9756
e30495ae11de
*-login: Moved most of the common code to login-common.
Timo Sirainen <tss@iki.fi>
parents:
9283
diff
changeset
|
627 tab[12].value = |
e30495ae11de
*-login: Moved most of the common code to login-common.
Timo Sirainen <tss@iki.fi>
parents:
9283
diff
changeset
|
628 ssl_proxy_get_security_string(client->ssl_proxy); |
4570
cbbe2377f591
If SSL/TLS handshake didn't finish, show "TLS handshaking" instead of "TLS"
Timo Sirainen <tss@iki.fi>
parents:
3863
diff
changeset
|
629 } |
12266
c38f630dae09
*-login: If client didn't log in, don't log mpid in logout message.
Timo Sirainen <tss@iki.fi>
parents:
11324
diff
changeset
|
630 tab[13].value = client->mail_pid == 0 ? "" : |
c38f630dae09
*-login: If client didn't log in, don't log mpid in logout message.
Timo Sirainen <tss@iki.fi>
parents:
11324
diff
changeset
|
631 dec2str(client->mail_pid); |
14302
5bbcf636bbeb
Added a "session ID" string for imap/pop3 connections, available in %{session} variable.
Timo Sirainen <tss@iki.fi>
parents:
14300
diff
changeset
|
632 tab[14].value = client_get_session_id(client); |
15888
c43fcfa2c4b4
auth: Added real_[lr]ip, real_[lr]port variables.
Timo Sirainen <tss@iki.fi>
parents:
15715
diff
changeset
|
633 tab[15].value = net_ip2addr(&client->real_local_ip); |
c43fcfa2c4b4
auth: Added real_[lr]ip, real_[lr]port variables.
Timo Sirainen <tss@iki.fi>
parents:
15715
diff
changeset
|
634 tab[16].value = net_ip2addr(&client->real_remote_ip); |
c43fcfa2c4b4
auth: Added real_[lr]ip, real_[lr]port variables.
Timo Sirainen <tss@iki.fi>
parents:
15715
diff
changeset
|
635 tab[17].value = dec2str(client->real_local_port); |
c43fcfa2c4b4
auth: Added real_[lr]ip, real_[lr]port variables.
Timo Sirainen <tss@iki.fi>
parents:
15715
diff
changeset
|
636 tab[18].value = dec2str(client->real_remote_port); |
17100
5350000a999b
auth, login, mail: Added %{auth_user}, %{auth_username} and %{auth_domain}
Timo Sirainen <tss@iki.fi>
parents:
16802
diff
changeset
|
637 if (client->virtual_user_orig != NULL) |
5350000a999b
auth, login, mail: Added %{auth_user}, %{auth_username} and %{auth_domain}
Timo Sirainen <tss@iki.fi>
parents:
16802
diff
changeset
|
638 get_var_expand_users(tab+19, client->virtual_user_orig); |
5350000a999b
auth, login, mail: Added %{auth_user}, %{auth_username} and %{auth_domain}
Timo Sirainen <tss@iki.fi>
parents:
16802
diff
changeset
|
639 else { |
16802
a32eea97afc1
*-login: Added %{orig_user}, %{orig_username} and %{orig_domain} variables.
Timo Sirainen <tss@iki.fi>
parents:
16555
diff
changeset
|
640 tab[19].value = tab[0].value; |
a32eea97afc1
*-login: Added %{orig_user}, %{orig_username} and %{orig_domain} variables.
Timo Sirainen <tss@iki.fi>
parents:
16555
diff
changeset
|
641 tab[20].value = tab[1].value; |
a32eea97afc1
*-login: Added %{orig_user}, %{orig_username} and %{orig_domain} variables.
Timo Sirainen <tss@iki.fi>
parents:
16555
diff
changeset
|
642 tab[21].value = tab[2].value; |
17100
5350000a999b
auth, login, mail: Added %{auth_user}, %{auth_username} and %{auth_domain}
Timo Sirainen <tss@iki.fi>
parents:
16802
diff
changeset
|
643 } |
5350000a999b
auth, login, mail: Added %{auth_user}, %{auth_username} and %{auth_domain}
Timo Sirainen <tss@iki.fi>
parents:
16802
diff
changeset
|
644 if (client->virtual_auth_user != NULL) |
5350000a999b
auth, login, mail: Added %{auth_user}, %{auth_username} and %{auth_domain}
Timo Sirainen <tss@iki.fi>
parents:
16802
diff
changeset
|
645 get_var_expand_users(tab+22, client->virtual_auth_user); |
5350000a999b
auth, login, mail: Added %{auth_user}, %{auth_username} and %{auth_domain}
Timo Sirainen <tss@iki.fi>
parents:
16802
diff
changeset
|
646 else { |
17101
632a1c79cdc3
*-login: Fix to previous commit: Default auth_user to original_user
Timo Sirainen <tss@iki.fi>
parents:
17100
diff
changeset
|
647 tab[22].value = tab[19].value; |
632a1c79cdc3
*-login: Fix to previous commit: Default auth_user to original_user
Timo Sirainen <tss@iki.fi>
parents:
17100
diff
changeset
|
648 tab[23].value = tab[20].value; |
632a1c79cdc3
*-login: Fix to previous commit: Default auth_user to original_user
Timo Sirainen <tss@iki.fi>
parents:
17100
diff
changeset
|
649 tab[24].value = tab[21].value; |
16802
a32eea97afc1
*-login: Added %{orig_user}, %{orig_username} and %{orig_domain} variables.
Timo Sirainen <tss@iki.fi>
parents:
16555
diff
changeset
|
650 } |
19010
a919414e68d2
login_log_format_elements: Added %{listener} variable to expand to the listener socket name.
Timo Sirainen <tss@iki.fi>
parents:
18950
diff
changeset
|
651 tab[25].value = client->listener_name; |
20929
2c626fd876ad
login-common: Include local_name in login_var_expand_table
Aki Tuomi <aki.tuomi@dovecot.fi>
parents:
19572
diff
changeset
|
652 tab[26].value = str_sanitize(client->local_name, 256); |
3384
3b75956d20c4
Added configurable logging for login process. Added configurable pop3 logout
Timo Sirainen <tss@iki.fi>
parents:
2737
diff
changeset
|
653 return tab; |
3b75956d20c4
Added configurable logging for login process. Added configurable pop3 logout
Timo Sirainen <tss@iki.fi>
parents:
2737
diff
changeset
|
654 } |
3b75956d20c4
Added configurable logging for login process. Added configurable pop3 logout
Timo Sirainen <tss@iki.fi>
parents:
2737
diff
changeset
|
655 |
14300
9b78e93e5b71
login_log_format_elements: Allow using %{long_variables} without breaking.
Timo Sirainen <tss@iki.fi>
parents:
14247
diff
changeset
|
656 static bool have_username_key(const char *str) |
3384
3b75956d20c4
Added configurable logging for login process. Added configurable pop3 logout
Timo Sirainen <tss@iki.fi>
parents:
2737
diff
changeset
|
657 { |
3b75956d20c4
Added configurable logging for login process. Added configurable pop3 logout
Timo Sirainen <tss@iki.fi>
parents:
2737
diff
changeset
|
658 char key; |
3b75956d20c4
Added configurable logging for login process. Added configurable pop3 logout
Timo Sirainen <tss@iki.fi>
parents:
2737
diff
changeset
|
659 |
14300
9b78e93e5b71
login_log_format_elements: Allow using %{long_variables} without breaking.
Timo Sirainen <tss@iki.fi>
parents:
14247
diff
changeset
|
660 for (; *str != '\0'; str++) { |
9b78e93e5b71
login_log_format_elements: Allow using %{long_variables} without breaking.
Timo Sirainen <tss@iki.fi>
parents:
14247
diff
changeset
|
661 if (str[0] == '%' && str[1] != '\0') { |
9b78e93e5b71
login_log_format_elements: Allow using %{long_variables} without breaking.
Timo Sirainen <tss@iki.fi>
parents:
14247
diff
changeset
|
662 str++; |
9b78e93e5b71
login_log_format_elements: Allow using %{long_variables} without breaking.
Timo Sirainen <tss@iki.fi>
parents:
14247
diff
changeset
|
663 key = var_get_key(str); |
9b78e93e5b71
login_log_format_elements: Allow using %{long_variables} without breaking.
Timo Sirainen <tss@iki.fi>
parents:
14247
diff
changeset
|
664 if (key == 'u' || key == 'n') |
13735
6e87e399ccd7
login: Show empty username in disconnect message.
Timo Sirainen <tss@iki.fi>
parents:
13733
diff
changeset
|
665 return TRUE; |
3384
3b75956d20c4
Added configurable logging for login process. Added configurable pop3 logout
Timo Sirainen <tss@iki.fi>
parents:
2737
diff
changeset
|
666 } |
3b75956d20c4
Added configurable logging for login process. Added configurable pop3 logout
Timo Sirainen <tss@iki.fi>
parents:
2737
diff
changeset
|
667 } |
3b75956d20c4
Added configurable logging for login process. Added configurable pop3 logout
Timo Sirainen <tss@iki.fi>
parents:
2737
diff
changeset
|
668 return FALSE; |
3b75956d20c4
Added configurable logging for login process. Added configurable pop3 logout
Timo Sirainen <tss@iki.fi>
parents:
2737
diff
changeset
|
669 } |
3b75956d20c4
Added configurable logging for login process. Added configurable pop3 logout
Timo Sirainen <tss@iki.fi>
parents:
2737
diff
changeset
|
670 |
8583
2ff2cac3578b
imap/pop3-login: Cleaned up proxying code. Don't disconnect client on proxy failures.
Timo Sirainen <tss@iki.fi>
parents:
8544
diff
changeset
|
671 static const char * |
19029
170f2b9f4977
*-login: Added %{passdb:*} fields to login_log_format_elements
Timo Sirainen <tss@iki.fi>
parents:
19010
diff
changeset
|
672 client_var_expand_func_passdb(const char *data, void *context) |
170f2b9f4977
*-login: Added %{passdb:*} fields to login_log_format_elements
Timo Sirainen <tss@iki.fi>
parents:
19010
diff
changeset
|
673 { |
170f2b9f4977
*-login: Added %{passdb:*} fields to login_log_format_elements
Timo Sirainen <tss@iki.fi>
parents:
19010
diff
changeset
|
674 struct client *client = context; |
170f2b9f4977
*-login: Added %{passdb:*} fields to login_log_format_elements
Timo Sirainen <tss@iki.fi>
parents:
19010
diff
changeset
|
675 const char *field_name = data; |
21322
5ab8dc1a4a6f
global: Change string position/length from unsigned int to size_t
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
20929
diff
changeset
|
676 unsigned int i; |
5ab8dc1a4a6f
global: Change string position/length from unsigned int to size_t
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
20929
diff
changeset
|
677 size_t field_name_len; |
19029
170f2b9f4977
*-login: Added %{passdb:*} fields to login_log_format_elements
Timo Sirainen <tss@iki.fi>
parents:
19010
diff
changeset
|
678 |
170f2b9f4977
*-login: Added %{passdb:*} fields to login_log_format_elements
Timo Sirainen <tss@iki.fi>
parents:
19010
diff
changeset
|
679 if (client->auth_passdb_args == NULL) |
170f2b9f4977
*-login: Added %{passdb:*} fields to login_log_format_elements
Timo Sirainen <tss@iki.fi>
parents:
19010
diff
changeset
|
680 return NULL; |
170f2b9f4977
*-login: Added %{passdb:*} fields to login_log_format_elements
Timo Sirainen <tss@iki.fi>
parents:
19010
diff
changeset
|
681 |
170f2b9f4977
*-login: Added %{passdb:*} fields to login_log_format_elements
Timo Sirainen <tss@iki.fi>
parents:
19010
diff
changeset
|
682 field_name_len = strlen(field_name); |
170f2b9f4977
*-login: Added %{passdb:*} fields to login_log_format_elements
Timo Sirainen <tss@iki.fi>
parents:
19010
diff
changeset
|
683 for (i = 0; client->auth_passdb_args[i] != NULL; i++) { |
170f2b9f4977
*-login: Added %{passdb:*} fields to login_log_format_elements
Timo Sirainen <tss@iki.fi>
parents:
19010
diff
changeset
|
684 if (strncmp(client->auth_passdb_args[i], field_name, |
170f2b9f4977
*-login: Added %{passdb:*} fields to login_log_format_elements
Timo Sirainen <tss@iki.fi>
parents:
19010
diff
changeset
|
685 field_name_len) == 0 && |
170f2b9f4977
*-login: Added %{passdb:*} fields to login_log_format_elements
Timo Sirainen <tss@iki.fi>
parents:
19010
diff
changeset
|
686 client->auth_passdb_args[i][field_name_len] == '=') |
170f2b9f4977
*-login: Added %{passdb:*} fields to login_log_format_elements
Timo Sirainen <tss@iki.fi>
parents:
19010
diff
changeset
|
687 return client->auth_passdb_args[i] + field_name_len+1; |
170f2b9f4977
*-login: Added %{passdb:*} fields to login_log_format_elements
Timo Sirainen <tss@iki.fi>
parents:
19010
diff
changeset
|
688 } |
170f2b9f4977
*-login: Added %{passdb:*} fields to login_log_format_elements
Timo Sirainen <tss@iki.fi>
parents:
19010
diff
changeset
|
689 return NULL; |
170f2b9f4977
*-login: Added %{passdb:*} fields to login_log_format_elements
Timo Sirainen <tss@iki.fi>
parents:
19010
diff
changeset
|
690 } |
170f2b9f4977
*-login: Added %{passdb:*} fields to login_log_format_elements
Timo Sirainen <tss@iki.fi>
parents:
19010
diff
changeset
|
691 |
170f2b9f4977
*-login: Added %{passdb:*} fields to login_log_format_elements
Timo Sirainen <tss@iki.fi>
parents:
19010
diff
changeset
|
692 static const char * |
8583
2ff2cac3578b
imap/pop3-login: Cleaned up proxying code. Don't disconnect client on proxy failures.
Timo Sirainen <tss@iki.fi>
parents:
8544
diff
changeset
|
693 client_get_log_str(struct client *client, const char *msg) |
3384
3b75956d20c4
Added configurable logging for login process. Added configurable pop3 logout
Timo Sirainen <tss@iki.fi>
parents:
2737
diff
changeset
|
694 { |
19029
170f2b9f4977
*-login: Added %{passdb:*} fields to login_log_format_elements
Timo Sirainen <tss@iki.fi>
parents:
19010
diff
changeset
|
695 static const struct var_expand_table static_tab[3] = { |
8544
983d38de06c9
var_expand(): Added support for long %{variable} names.
Timo Sirainen <tss@iki.fi>
parents:
8302
diff
changeset
|
696 { 's', NULL, NULL }, |
983d38de06c9
var_expand(): Added support for long %{variable} names.
Timo Sirainen <tss@iki.fi>
parents:
8302
diff
changeset
|
697 { '$', NULL, NULL }, |
983d38de06c9
var_expand(): Added support for long %{variable} names.
Timo Sirainen <tss@iki.fi>
parents:
8302
diff
changeset
|
698 { '\0', NULL, NULL } |
3384
3b75956d20c4
Added configurable logging for login process. Added configurable pop3 logout
Timo Sirainen <tss@iki.fi>
parents:
2737
diff
changeset
|
699 }; |
19029
170f2b9f4977
*-login: Added %{passdb:*} fields to login_log_format_elements
Timo Sirainen <tss@iki.fi>
parents:
19010
diff
changeset
|
700 static const struct var_expand_func_table func_table[] = { |
170f2b9f4977
*-login: Added %{passdb:*} fields to login_log_format_elements
Timo Sirainen <tss@iki.fi>
parents:
19010
diff
changeset
|
701 { "passdb", client_var_expand_func_passdb }, |
170f2b9f4977
*-login: Added %{passdb:*} fields to login_log_format_elements
Timo Sirainen <tss@iki.fi>
parents:
19010
diff
changeset
|
702 { NULL, NULL } |
170f2b9f4977
*-login: Added %{passdb:*} fields to login_log_format_elements
Timo Sirainen <tss@iki.fi>
parents:
19010
diff
changeset
|
703 }; |
3384
3b75956d20c4
Added configurable logging for login process. Added configurable pop3 logout
Timo Sirainen <tss@iki.fi>
parents:
2737
diff
changeset
|
704 const struct var_expand_table *var_expand_table; |
3b75956d20c4
Added configurable logging for login process. Added configurable pop3 logout
Timo Sirainen <tss@iki.fi>
parents:
2737
diff
changeset
|
705 struct var_expand_table *tab; |
9283
02721ba17309
login processes: Added initial support for per-connection configuration.
Timo Sirainen <tss@iki.fi>
parents:
9002
diff
changeset
|
706 char *const *e; |
14300
9b78e93e5b71
login_log_format_elements: Allow using %{long_variables} without breaking.
Timo Sirainen <tss@iki.fi>
parents:
14247
diff
changeset
|
707 string_t *str, *str2; |
9b78e93e5b71
login_log_format_elements: Allow using %{long_variables} without breaking.
Timo Sirainen <tss@iki.fi>
parents:
14247
diff
changeset
|
708 unsigned int pos; |
2737 | 709 |
3384
3b75956d20c4
Added configurable logging for login process. Added configurable pop3 logout
Timo Sirainen <tss@iki.fi>
parents:
2737
diff
changeset
|
710 var_expand_table = get_var_expand_table(client); |
3b75956d20c4
Added configurable logging for login process. Added configurable pop3 logout
Timo Sirainen <tss@iki.fi>
parents:
2737
diff
changeset
|
711 |
3b75956d20c4
Added configurable logging for login process. Added configurable pop3 logout
Timo Sirainen <tss@iki.fi>
parents:
2737
diff
changeset
|
712 tab = t_malloc(sizeof(static_tab)); |
3b75956d20c4
Added configurable logging for login process. Added configurable pop3 logout
Timo Sirainen <tss@iki.fi>
parents:
2737
diff
changeset
|
713 memcpy(tab, static_tab, sizeof(static_tab)); |
3b75956d20c4
Added configurable logging for login process. Added configurable pop3 logout
Timo Sirainen <tss@iki.fi>
parents:
2737
diff
changeset
|
714 |
3b75956d20c4
Added configurable logging for login process. Added configurable pop3 logout
Timo Sirainen <tss@iki.fi>
parents:
2737
diff
changeset
|
715 str = t_str_new(256); |
14300
9b78e93e5b71
login_log_format_elements: Allow using %{long_variables} without breaking.
Timo Sirainen <tss@iki.fi>
parents:
14247
diff
changeset
|
716 str2 = t_str_new(128); |
9283
02721ba17309
login processes: Added initial support for per-connection configuration.
Timo Sirainen <tss@iki.fi>
parents:
9002
diff
changeset
|
717 for (e = client->set->log_format_elements_split; *e != NULL; e++) { |
14300
9b78e93e5b71
login_log_format_elements: Allow using %{long_variables} without breaking.
Timo Sirainen <tss@iki.fi>
parents:
14247
diff
changeset
|
718 pos = str_len(str); |
19029
170f2b9f4977
*-login: Added %{passdb:*} fields to login_log_format_elements
Timo Sirainen <tss@iki.fi>
parents:
19010
diff
changeset
|
719 var_expand_with_funcs(str, *e, var_expand_table, |
170f2b9f4977
*-login: Added %{passdb:*} fields to login_log_format_elements
Timo Sirainen <tss@iki.fi>
parents:
19010
diff
changeset
|
720 func_table, client); |
14300
9b78e93e5b71
login_log_format_elements: Allow using %{long_variables} without breaking.
Timo Sirainen <tss@iki.fi>
parents:
14247
diff
changeset
|
721 if (have_username_key(*e)) { |
9b78e93e5b71
login_log_format_elements: Allow using %{long_variables} without breaking.
Timo Sirainen <tss@iki.fi>
parents:
14247
diff
changeset
|
722 /* username is added even if it's empty */ |
9b78e93e5b71
login_log_format_elements: Allow using %{long_variables} without breaking.
Timo Sirainen <tss@iki.fi>
parents:
14247
diff
changeset
|
723 } else { |
9b78e93e5b71
login_log_format_elements: Allow using %{long_variables} without breaking.
Timo Sirainen <tss@iki.fi>
parents:
14247
diff
changeset
|
724 str_truncate(str2, 0); |
9b78e93e5b71
login_log_format_elements: Allow using %{long_variables} without breaking.
Timo Sirainen <tss@iki.fi>
parents:
14247
diff
changeset
|
725 var_expand(str2, *e, login_var_expand_empty_tab); |
9b78e93e5b71
login_log_format_elements: Allow using %{long_variables} without breaking.
Timo Sirainen <tss@iki.fi>
parents:
14247
diff
changeset
|
726 if (strcmp(str_c(str)+pos, str_c(str2)) == 0) { |
9b78e93e5b71
login_log_format_elements: Allow using %{long_variables} without breaking.
Timo Sirainen <tss@iki.fi>
parents:
14247
diff
changeset
|
727 /* empty %variables, don't add */ |
9b78e93e5b71
login_log_format_elements: Allow using %{long_variables} without breaking.
Timo Sirainen <tss@iki.fi>
parents:
14247
diff
changeset
|
728 str_truncate(str, pos); |
3384
3b75956d20c4
Added configurable logging for login process. Added configurable pop3 logout
Timo Sirainen <tss@iki.fi>
parents:
2737
diff
changeset
|
729 continue; |
3b75956d20c4
Added configurable logging for login process. Added configurable pop3 logout
Timo Sirainen <tss@iki.fi>
parents:
2737
diff
changeset
|
730 } |
3b75956d20c4
Added configurable logging for login process. Added configurable pop3 logout
Timo Sirainen <tss@iki.fi>
parents:
2737
diff
changeset
|
731 } |
14300
9b78e93e5b71
login_log_format_elements: Allow using %{long_variables} without breaking.
Timo Sirainen <tss@iki.fi>
parents:
14247
diff
changeset
|
732 |
9b78e93e5b71
login_log_format_elements: Allow using %{long_variables} without breaking.
Timo Sirainen <tss@iki.fi>
parents:
14247
diff
changeset
|
733 if (str_len(str) > 0) |
9b78e93e5b71
login_log_format_elements: Allow using %{long_variables} without breaking.
Timo Sirainen <tss@iki.fi>
parents:
14247
diff
changeset
|
734 str_append(str, ", "); |
3384
3b75956d20c4
Added configurable logging for login process. Added configurable pop3 logout
Timo Sirainen <tss@iki.fi>
parents:
2737
diff
changeset
|
735 } |
3b75956d20c4
Added configurable logging for login process. Added configurable pop3 logout
Timo Sirainen <tss@iki.fi>
parents:
2737
diff
changeset
|
736 |
14300
9b78e93e5b71
login_log_format_elements: Allow using %{long_variables} without breaking.
Timo Sirainen <tss@iki.fi>
parents:
14247
diff
changeset
|
737 if (str_len(str) > 0) |
9b78e93e5b71
login_log_format_elements: Allow using %{long_variables} without breaking.
Timo Sirainen <tss@iki.fi>
parents:
14247
diff
changeset
|
738 str_truncate(str, str_len(str)-2); |
9b78e93e5b71
login_log_format_elements: Allow using %{long_variables} without breaking.
Timo Sirainen <tss@iki.fi>
parents:
14247
diff
changeset
|
739 |
3384
3b75956d20c4
Added configurable logging for login process. Added configurable pop3 logout
Timo Sirainen <tss@iki.fi>
parents:
2737
diff
changeset
|
740 tab[0].value = t_strdup(str_c(str)); |
3b75956d20c4
Added configurable logging for login process. Added configurable pop3 logout
Timo Sirainen <tss@iki.fi>
parents:
2737
diff
changeset
|
741 tab[1].value = msg; |
3b75956d20c4
Added configurable logging for login process. Added configurable pop3 logout
Timo Sirainen <tss@iki.fi>
parents:
2737
diff
changeset
|
742 str_truncate(str, 0); |
3b75956d20c4
Added configurable logging for login process. Added configurable pop3 logout
Timo Sirainen <tss@iki.fi>
parents:
2737
diff
changeset
|
743 |
9283
02721ba17309
login processes: Added initial support for per-connection configuration.
Timo Sirainen <tss@iki.fi>
parents:
9002
diff
changeset
|
744 var_expand(str, client->set->login_log_format, tab); |
8583
2ff2cac3578b
imap/pop3-login: Cleaned up proxying code. Don't disconnect client on proxy failures.
Timo Sirainen <tss@iki.fi>
parents:
8544
diff
changeset
|
745 return str_c(str); |
6940
414c9d631a81
Replaced t_push/t_pop calls with T_FRAME*() macros.
Timo Sirainen <tss@iki.fi>
parents:
6429
diff
changeset
|
746 } |
3384
3b75956d20c4
Added configurable logging for login process. Added configurable pop3 logout
Timo Sirainen <tss@iki.fi>
parents:
2737
diff
changeset
|
747 |
9756
e30495ae11de
*-login: Moved most of the common code to login-common.
Timo Sirainen <tss@iki.fi>
parents:
9283
diff
changeset
|
748 void client_log(struct client *client, const char *msg) |
6940
414c9d631a81
Replaced t_push/t_pop calls with T_FRAME*() macros.
Timo Sirainen <tss@iki.fi>
parents:
6429
diff
changeset
|
749 { |
7226
e6693a0ec8e1
Renamed T_FRAME_BEGIN/END to T_BEGIN/END. Removed T_FRAME() macro and
Timo Sirainen <tss@iki.fi>
parents:
7120
diff
changeset
|
750 T_BEGIN { |
8583
2ff2cac3578b
imap/pop3-login: Cleaned up proxying code. Don't disconnect client on proxy failures.
Timo Sirainen <tss@iki.fi>
parents:
8544
diff
changeset
|
751 i_info("%s", client_get_log_str(client, msg)); |
2ff2cac3578b
imap/pop3-login: Cleaned up proxying code. Don't disconnect client on proxy failures.
Timo Sirainen <tss@iki.fi>
parents:
8544
diff
changeset
|
752 } T_END; |
2ff2cac3578b
imap/pop3-login: Cleaned up proxying code. Don't disconnect client on proxy failures.
Timo Sirainen <tss@iki.fi>
parents:
8544
diff
changeset
|
753 } |
2ff2cac3578b
imap/pop3-login: Cleaned up proxying code. Don't disconnect client on proxy failures.
Timo Sirainen <tss@iki.fi>
parents:
8544
diff
changeset
|
754 |
9756
e30495ae11de
*-login: Moved most of the common code to login-common.
Timo Sirainen <tss@iki.fi>
parents:
9283
diff
changeset
|
755 void client_log_err(struct client *client, const char *msg) |
8583
2ff2cac3578b
imap/pop3-login: Cleaned up proxying code. Don't disconnect client on proxy failures.
Timo Sirainen <tss@iki.fi>
parents:
8544
diff
changeset
|
756 { |
2ff2cac3578b
imap/pop3-login: Cleaned up proxying code. Don't disconnect client on proxy failures.
Timo Sirainen <tss@iki.fi>
parents:
8544
diff
changeset
|
757 T_BEGIN { |
2ff2cac3578b
imap/pop3-login: Cleaned up proxying code. Don't disconnect client on proxy failures.
Timo Sirainen <tss@iki.fi>
parents:
8544
diff
changeset
|
758 i_error("%s", client_get_log_str(client, msg)); |
7226
e6693a0ec8e1
Renamed T_FRAME_BEGIN/END to T_BEGIN/END. Removed T_FRAME() macro and
Timo Sirainen <tss@iki.fi>
parents:
7120
diff
changeset
|
759 } T_END; |
2737 | 760 } |
7920
3644883cf44e
Support transferring original IPs and ports through IMAP proxies.
Timo Sirainen <tss@iki.fi>
parents:
7374
diff
changeset
|
761 |
13933
957e74f0d60f
login: Added logging if auth process doesn't respond fast enough for greeting.
Timo Sirainen <tss@iki.fi>
parents:
13735
diff
changeset
|
762 void client_log_warn(struct client *client, const char *msg) |
957e74f0d60f
login: Added logging if auth process doesn't respond fast enough for greeting.
Timo Sirainen <tss@iki.fi>
parents:
13735
diff
changeset
|
763 { |
957e74f0d60f
login: Added logging if auth process doesn't respond fast enough for greeting.
Timo Sirainen <tss@iki.fi>
parents:
13735
diff
changeset
|
764 T_BEGIN { |
957e74f0d60f
login: Added logging if auth process doesn't respond fast enough for greeting.
Timo Sirainen <tss@iki.fi>
parents:
13735
diff
changeset
|
765 i_warning("%s", client_get_log_str(client, msg)); |
957e74f0d60f
login: Added logging if auth process doesn't respond fast enough for greeting.
Timo Sirainen <tss@iki.fi>
parents:
13735
diff
changeset
|
766 } T_END; |
957e74f0d60f
login: Added logging if auth process doesn't respond fast enough for greeting.
Timo Sirainen <tss@iki.fi>
parents:
13735
diff
changeset
|
767 } |
957e74f0d60f
login: Added logging if auth process doesn't respond fast enough for greeting.
Timo Sirainen <tss@iki.fi>
parents:
13735
diff
changeset
|
768 |
14800
258c2e231357
login: Don't allow STARTTLS if ssl=no in client's settings, even if ssl=yes globally.
Timo Sirainen <tss@iki.fi>
parents:
14566
diff
changeset
|
769 bool client_is_tls_enabled(struct client *client) |
258c2e231357
login: Don't allow STARTTLS if ssl=no in client's settings, even if ssl=yes globally.
Timo Sirainen <tss@iki.fi>
parents:
14566
diff
changeset
|
770 { |
14840 | 771 return ssl_initialized && strcmp(client->ssl_set->ssl, "no") != 0; |
14800
258c2e231357
login: Don't allow STARTTLS if ssl=no in client's settings, even if ssl=yes globally.
Timo Sirainen <tss@iki.fi>
parents:
14566
diff
changeset
|
772 } |
258c2e231357
login: Don't allow STARTTLS if ssl=no in client's settings, even if ssl=yes globally.
Timo Sirainen <tss@iki.fi>
parents:
14566
diff
changeset
|
773 |
8302
0db37acdc59f
Login process: Log auth failure reasons better in disconnect message.
Timo Sirainen <tss@iki.fi>
parents:
8122
diff
changeset
|
774 const char *client_get_extra_disconnect_reason(struct client *client) |
0db37acdc59f
Login process: Log auth failure reasons better in disconnect message.
Timo Sirainen <tss@iki.fi>
parents:
8122
diff
changeset
|
775 { |
13704
346c022df7af
login: Improved auth failed log messages.
Timo Sirainen <tss@iki.fi>
parents:
13671
diff
changeset
|
776 unsigned int auth_secs = client->auth_first_started == 0 ? 0 : |
346c022df7af
login: Improved auth failed log messages.
Timo Sirainen <tss@iki.fi>
parents:
13671
diff
changeset
|
777 ioloop_time - client->auth_first_started; |
346c022df7af
login: Improved auth failed log messages.
Timo Sirainen <tss@iki.fi>
parents:
13671
diff
changeset
|
778 |
12683
fd9c01323475
login: ssl_require_client_cert and ssl_username_from_cert settings should have had auth_ prefix.
Timo Sirainen <tss@iki.fi>
parents:
12504
diff
changeset
|
779 if (client->set->auth_ssl_require_client_cert && |
fd9c01323475
login: ssl_require_client_cert and ssl_username_from_cert settings should have had auth_ prefix.
Timo Sirainen <tss@iki.fi>
parents:
12504
diff
changeset
|
780 client->ssl_proxy != NULL) { |
9756
e30495ae11de
*-login: Moved most of the common code to login-common.
Timo Sirainen <tss@iki.fi>
parents:
9283
diff
changeset
|
781 if (ssl_proxy_has_broken_client_cert(client->ssl_proxy)) |
8302
0db37acdc59f
Login process: Log auth failure reasons better in disconnect message.
Timo Sirainen <tss@iki.fi>
parents:
8122
diff
changeset
|
782 return "(client sent an invalid cert)"; |
9756
e30495ae11de
*-login: Moved most of the common code to login-common.
Timo Sirainen <tss@iki.fi>
parents:
9283
diff
changeset
|
783 if (!ssl_proxy_has_valid_client_cert(client->ssl_proxy)) |
8302
0db37acdc59f
Login process: Log auth failure reasons better in disconnect message.
Timo Sirainen <tss@iki.fi>
parents:
8122
diff
changeset
|
784 return "(client didn't send a cert)"; |
0db37acdc59f
Login process: Log auth failure reasons better in disconnect message.
Timo Sirainen <tss@iki.fi>
parents:
8122
diff
changeset
|
785 } |
0db37acdc59f
Login process: Log auth failure reasons better in disconnect message.
Timo Sirainen <tss@iki.fi>
parents:
8122
diff
changeset
|
786 |
14146
e456e1bce47f
login-common API made more extensible for different kinds of protocols.
Timo Sirainen <tss@iki.fi>
parents:
14133
diff
changeset
|
787 if (!client->notified_auth_ready) |
13933
957e74f0d60f
login: Added logging if auth process doesn't respond fast enough for greeting.
Timo Sirainen <tss@iki.fi>
parents:
13735
diff
changeset
|
788 return t_strdup_printf( |
14146
e456e1bce47f
login-common API made more extensible for different kinds of protocols.
Timo Sirainen <tss@iki.fi>
parents:
14133
diff
changeset
|
789 "(disconnected before auth was ready, waited %u secs)", |
13933
957e74f0d60f
login: Added logging if auth process doesn't respond fast enough for greeting.
Timo Sirainen <tss@iki.fi>
parents:
13735
diff
changeset
|
790 (unsigned int)(ioloop_time - client->created)); |
957e74f0d60f
login: Added logging if auth process doesn't respond fast enough for greeting.
Timo Sirainen <tss@iki.fi>
parents:
13735
diff
changeset
|
791 |
13704
346c022df7af
login: Improved auth failed log messages.
Timo Sirainen <tss@iki.fi>
parents:
13671
diff
changeset
|
792 if (client->auth_attempts == 0) { |
21909
57ce096eab4b
*-login: Minor logging cleanup if client is disconnected before sending banner.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
21820
diff
changeset
|
793 if (!client->banner_sent) { |
57ce096eab4b
*-login: Minor logging cleanup if client is disconnected before sending banner.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
21820
diff
changeset
|
794 /* disconnected by a plugin */ |
57ce096eab4b
*-login: Minor logging cleanup if client is disconnected before sending banner.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
21820
diff
changeset
|
795 return ""; |
57ce096eab4b
*-login: Minor logging cleanup if client is disconnected before sending banner.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
21820
diff
changeset
|
796 } |
13704
346c022df7af
login: Improved auth failed log messages.
Timo Sirainen <tss@iki.fi>
parents:
13671
diff
changeset
|
797 return t_strdup_printf("(no auth attempts in %u secs)", |
346c022df7af
login: Improved auth failed log messages.
Timo Sirainen <tss@iki.fi>
parents:
13671
diff
changeset
|
798 (unsigned int)(ioloop_time - client->created)); |
346c022df7af
login: Improved auth failed log messages.
Timo Sirainen <tss@iki.fi>
parents:
13671
diff
changeset
|
799 } |
8302
0db37acdc59f
Login process: Log auth failure reasons better in disconnect message.
Timo Sirainen <tss@iki.fi>
parents:
8122
diff
changeset
|
800 |
0db37acdc59f
Login process: Log auth failure reasons better in disconnect message.
Timo Sirainen <tss@iki.fi>
parents:
8122
diff
changeset
|
801 /* some auth attempts without SSL/TLS */ |
0db37acdc59f
Login process: Log auth failure reasons better in disconnect message.
Timo Sirainen <tss@iki.fi>
parents:
8122
diff
changeset
|
802 if (client->auth_tried_disabled_plaintext) |
14456
d6376942d9a6
login: Log message change: Tried to use s/disabled/disallowed/ plaintext auth
Timo Sirainen <tss@iki.fi>
parents:
14393
diff
changeset
|
803 return "(tried to use disallowed plaintext auth)"; |
13538
e19a3a2d554d
login: "cert required, client didn't start TLS" error could have been logged wrongly.
Timo Sirainen <tss@iki.fi>
parents:
12890
diff
changeset
|
804 if (client->set->auth_ssl_require_client_cert && |
e19a3a2d554d
login: "cert required, client didn't start TLS" error could have been logged wrongly.
Timo Sirainen <tss@iki.fi>
parents:
12890
diff
changeset
|
805 client->ssl_proxy == NULL) |
8302
0db37acdc59f
Login process: Log auth failure reasons better in disconnect message.
Timo Sirainen <tss@iki.fi>
parents:
8122
diff
changeset
|
806 return "(cert required, client didn't start TLS)"; |
9965
c492325acdcf
*-login: Log more precise reasons for some auth failures.
Timo Sirainen <tss@iki.fi>
parents:
9961
diff
changeset
|
807 if (client->auth_tried_unsupported_mech) |
c492325acdcf
*-login: Log more precise reasons for some auth failures.
Timo Sirainen <tss@iki.fi>
parents:
9961
diff
changeset
|
808 return "(tried to use unsupported auth mechanism)"; |
13733
679837ca1c95
login: Log a different disconnect message if client didn't finish SASL auth.
Timo Sirainen <tss@iki.fi>
parents:
13723
diff
changeset
|
809 if (client->auth_waiting && client->auth_attempts == 1) { |
679837ca1c95
login: Log a different disconnect message if client didn't finish SASL auth.
Timo Sirainen <tss@iki.fi>
parents:
13723
diff
changeset
|
810 return t_strdup_printf("(client didn't finish SASL auth, " |
679837ca1c95
login: Log a different disconnect message if client didn't finish SASL auth.
Timo Sirainen <tss@iki.fi>
parents:
13723
diff
changeset
|
811 "waited %u secs)", auth_secs); |
679837ca1c95
login: Log a different disconnect message if client didn't finish SASL auth.
Timo Sirainen <tss@iki.fi>
parents:
13723
diff
changeset
|
812 } |
13704
346c022df7af
login: Improved auth failed log messages.
Timo Sirainen <tss@iki.fi>
parents:
13671
diff
changeset
|
813 if (client->auth_request != NULL && client->auth_attempts == 1) { |
346c022df7af
login: Improved auth failed log messages.
Timo Sirainen <tss@iki.fi>
parents:
13671
diff
changeset
|
814 return t_strdup_printf("(disconnected while authenticating, " |
346c022df7af
login: Improved auth failed log messages.
Timo Sirainen <tss@iki.fi>
parents:
13671
diff
changeset
|
815 "waited %u secs)", auth_secs); |
346c022df7af
login: Improved auth failed log messages.
Timo Sirainen <tss@iki.fi>
parents:
13671
diff
changeset
|
816 } |
346c022df7af
login: Improved auth failed log messages.
Timo Sirainen <tss@iki.fi>
parents:
13671
diff
changeset
|
817 if (client->authenticating && client->auth_attempts == 1) { |
346c022df7af
login: Improved auth failed log messages.
Timo Sirainen <tss@iki.fi>
parents:
13671
diff
changeset
|
818 return t_strdup_printf("(disconnected while finishing login, " |
346c022df7af
login: Improved auth failed log messages.
Timo Sirainen <tss@iki.fi>
parents:
13671
diff
changeset
|
819 "waited %u secs)", auth_secs); |
346c022df7af
login: Improved auth failed log messages.
Timo Sirainen <tss@iki.fi>
parents:
13671
diff
changeset
|
820 } |
9965
c492325acdcf
*-login: Log more precise reasons for some auth failures.
Timo Sirainen <tss@iki.fi>
parents:
9961
diff
changeset
|
821 if (client->auth_try_aborted && client->auth_attempts == 1) |
c492325acdcf
*-login: Log more precise reasons for some auth failures.
Timo Sirainen <tss@iki.fi>
parents:
9961
diff
changeset
|
822 return "(aborted authentication)"; |
13723
dd66ea0e7d00
login: Differentiate between auth failure and auth process communication failure.
Timo Sirainen <tss@iki.fi>
parents:
13721
diff
changeset
|
823 if (client->auth_process_comm_fail) |
dd66ea0e7d00
login: Differentiate between auth failure and auth process communication failure.
Timo Sirainen <tss@iki.fi>
parents:
13721
diff
changeset
|
824 return "(auth process communication failure)"; |
8302
0db37acdc59f
Login process: Log auth failure reasons better in disconnect message.
Timo Sirainen <tss@iki.fi>
parents:
8122
diff
changeset
|
825 |
14011
cb344eb79daa
login proxy: If remote auth fails, say so in disconnect message instead of "internal failure".
Timo Sirainen <tss@iki.fi>
parents:
13959
diff
changeset
|
826 if (client->proxy_auth_failed) |
cb344eb79daa
login proxy: If remote auth fails, say so in disconnect message instead of "internal failure".
Timo Sirainen <tss@iki.fi>
parents:
13959
diff
changeset
|
827 return "(proxy dest auth failed)"; |
13671
d03524bfcf16
login: If login fails for some reason, but auth was successful, don't log "auth failed".
Timo Sirainen <tss@iki.fi>
parents:
13539
diff
changeset
|
828 if (client->auth_successes > 0) { |
14745
962215040871
login: s/succesful/successful/
Timo Sirainen <tss@iki.fi>
parents:
14728
diff
changeset
|
829 return t_strdup_printf("(internal failure, %u successful auths)", |
13671
d03524bfcf16
login: If login fails for some reason, but auth was successful, don't log "auth failed".
Timo Sirainen <tss@iki.fi>
parents:
13539
diff
changeset
|
830 client->auth_successes); |
d03524bfcf16
login: If login fails for some reason, but auth was successful, don't log "auth failed".
Timo Sirainen <tss@iki.fi>
parents:
13539
diff
changeset
|
831 } |
14566
ca0fef559d43
login: If user is disabled or password expired, say it in logout reason.
Timo Sirainen <tss@iki.fi>
parents:
14456
diff
changeset
|
832 if (client->auth_user_disabled) |
ca0fef559d43
login: If user is disabled or password expired, say it in logout reason.
Timo Sirainen <tss@iki.fi>
parents:
14456
diff
changeset
|
833 return "(user disabled)"; |
ca0fef559d43
login: If user is disabled or password expired, say it in logout reason.
Timo Sirainen <tss@iki.fi>
parents:
14456
diff
changeset
|
834 if (client->auth_pass_expired) |
ca0fef559d43
login: If user is disabled or password expired, say it in logout reason.
Timo Sirainen <tss@iki.fi>
parents:
14456
diff
changeset
|
835 return "(password expired)"; |
13704
346c022df7af
login: Improved auth failed log messages.
Timo Sirainen <tss@iki.fi>
parents:
13671
diff
changeset
|
836 return t_strdup_printf("(auth failed, %u attempts in %u secs)", |
346c022df7af
login: Improved auth failed log messages.
Timo Sirainen <tss@iki.fi>
parents:
13671
diff
changeset
|
837 client->auth_attempts, auth_secs); |
8302
0db37acdc59f
Login process: Log auth failure reasons better in disconnect message.
Timo Sirainen <tss@iki.fi>
parents:
8122
diff
changeset
|
838 } |
9756
e30495ae11de
*-login: Moved most of the common code to login-common.
Timo Sirainen <tss@iki.fi>
parents:
9283
diff
changeset
|
839 |
14146
e456e1bce47f
login-common API made more extensible for different kinds of protocols.
Timo Sirainen <tss@iki.fi>
parents:
14133
diff
changeset
|
840 void client_notify_disconnect(struct client *client, |
e456e1bce47f
login-common API made more extensible for different kinds of protocols.
Timo Sirainen <tss@iki.fi>
parents:
14133
diff
changeset
|
841 enum client_disconnect_reason reason, |
e456e1bce47f
login-common API made more extensible for different kinds of protocols.
Timo Sirainen <tss@iki.fi>
parents:
14133
diff
changeset
|
842 const char *text) |
9756
e30495ae11de
*-login: Moved most of the common code to login-common.
Timo Sirainen <tss@iki.fi>
parents:
9283
diff
changeset
|
843 { |
14146
e456e1bce47f
login-common API made more extensible for different kinds of protocols.
Timo Sirainen <tss@iki.fi>
parents:
14133
diff
changeset
|
844 if (!client->notified_disconnect) { |
15049
aa6027a0a78e
Added support to perform token-based service process authentication.
Stephan Bosch <stephan@rename-it.nl>
parents:
14840
diff
changeset
|
845 if (client->v.notify_disconnect != NULL) |
aa6027a0a78e
Added support to perform token-based service process authentication.
Stephan Bosch <stephan@rename-it.nl>
parents:
14840
diff
changeset
|
846 client->v.notify_disconnect(client, reason, text); |
14146
e456e1bce47f
login-common API made more extensible for different kinds of protocols.
Timo Sirainen <tss@iki.fi>
parents:
14133
diff
changeset
|
847 client->notified_disconnect = TRUE; |
e456e1bce47f
login-common API made more extensible for different kinds of protocols.
Timo Sirainen <tss@iki.fi>
parents:
14133
diff
changeset
|
848 } |
e456e1bce47f
login-common API made more extensible for different kinds of protocols.
Timo Sirainen <tss@iki.fi>
parents:
14133
diff
changeset
|
849 } |
e456e1bce47f
login-common API made more extensible for different kinds of protocols.
Timo Sirainen <tss@iki.fi>
parents:
14133
diff
changeset
|
850 |
e456e1bce47f
login-common API made more extensible for different kinds of protocols.
Timo Sirainen <tss@iki.fi>
parents:
14133
diff
changeset
|
851 void client_notify_auth_ready(struct client *client) |
e456e1bce47f
login-common API made more extensible for different kinds of protocols.
Timo Sirainen <tss@iki.fi>
parents:
14133
diff
changeset
|
852 { |
e456e1bce47f
login-common API made more extensible for different kinds of protocols.
Timo Sirainen <tss@iki.fi>
parents:
14133
diff
changeset
|
853 if (!client->notified_auth_ready) { |
15049
aa6027a0a78e
Added support to perform token-based service process authentication.
Stephan Bosch <stephan@rename-it.nl>
parents:
14840
diff
changeset
|
854 if (client->v.notify_auth_ready != NULL) |
aa6027a0a78e
Added support to perform token-based service process authentication.
Stephan Bosch <stephan@rename-it.nl>
parents:
14840
diff
changeset
|
855 client->v.notify_auth_ready(client); |
14146
e456e1bce47f
login-common API made more extensible for different kinds of protocols.
Timo Sirainen <tss@iki.fi>
parents:
14133
diff
changeset
|
856 client->notified_auth_ready = TRUE; |
e456e1bce47f
login-common API made more extensible for different kinds of protocols.
Timo Sirainen <tss@iki.fi>
parents:
14133
diff
changeset
|
857 } |
e456e1bce47f
login-common API made more extensible for different kinds of protocols.
Timo Sirainen <tss@iki.fi>
parents:
14133
diff
changeset
|
858 } |
e456e1bce47f
login-common API made more extensible for different kinds of protocols.
Timo Sirainen <tss@iki.fi>
parents:
14133
diff
changeset
|
859 |
e456e1bce47f
login-common API made more extensible for different kinds of protocols.
Timo Sirainen <tss@iki.fi>
parents:
14133
diff
changeset
|
860 void client_notify_status(struct client *client, bool bad, const char *text) |
e456e1bce47f
login-common API made more extensible for different kinds of protocols.
Timo Sirainen <tss@iki.fi>
parents:
14133
diff
changeset
|
861 { |
e456e1bce47f
login-common API made more extensible for different kinds of protocols.
Timo Sirainen <tss@iki.fi>
parents:
14133
diff
changeset
|
862 if (client->v.notify_status != NULL) |
e456e1bce47f
login-common API made more extensible for different kinds of protocols.
Timo Sirainen <tss@iki.fi>
parents:
14133
diff
changeset
|
863 client->v.notify_status(client, bad, text); |
9756
e30495ae11de
*-login: Moved most of the common code to login-common.
Timo Sirainen <tss@iki.fi>
parents:
9283
diff
changeset
|
864 } |
e30495ae11de
*-login: Moved most of the common code to login-common.
Timo Sirainen <tss@iki.fi>
parents:
9283
diff
changeset
|
865 |
21970
866421afc7b7
*-login: Add client_vfuncs.send_raw_data()
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
21909
diff
changeset
|
866 void client_common_send_raw_data(struct client *client, |
866421afc7b7
*-login: Add client_vfuncs.send_raw_data()
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
21909
diff
changeset
|
867 const void *data, size_t size) |
9756
e30495ae11de
*-login: Moved most of the common code to login-common.
Timo Sirainen <tss@iki.fi>
parents:
9283
diff
changeset
|
868 { |
e30495ae11de
*-login: Moved most of the common code to login-common.
Timo Sirainen <tss@iki.fi>
parents:
9283
diff
changeset
|
869 ssize_t ret; |
e30495ae11de
*-login: Moved most of the common code to login-common.
Timo Sirainen <tss@iki.fi>
parents:
9283
diff
changeset
|
870 |
e30495ae11de
*-login: Moved most of the common code to login-common.
Timo Sirainen <tss@iki.fi>
parents:
9283
diff
changeset
|
871 ret = o_stream_send(client->output, data, size); |
e30495ae11de
*-login: Moved most of the common code to login-common.
Timo Sirainen <tss@iki.fi>
parents:
9283
diff
changeset
|
872 if (ret < 0 || (size_t)ret != size) { |
e30495ae11de
*-login: Moved most of the common code to login-common.
Timo Sirainen <tss@iki.fi>
parents:
9283
diff
changeset
|
873 /* either disconnection or buffer full. in either case we want |
e30495ae11de
*-login: Moved most of the common code to login-common.
Timo Sirainen <tss@iki.fi>
parents:
9283
diff
changeset
|
874 this connection destroyed. however destroying it here might |
e30495ae11de
*-login: Moved most of the common code to login-common.
Timo Sirainen <tss@iki.fi>
parents:
9283
diff
changeset
|
875 break things if client is still tried to be accessed without |
e30495ae11de
*-login: Moved most of the common code to login-common.
Timo Sirainen <tss@iki.fi>
parents:
9283
diff
changeset
|
876 being referenced.. */ |
e30495ae11de
*-login: Moved most of the common code to login-common.
Timo Sirainen <tss@iki.fi>
parents:
9283
diff
changeset
|
877 i_stream_close(client->input); |
e30495ae11de
*-login: Moved most of the common code to login-common.
Timo Sirainen <tss@iki.fi>
parents:
9283
diff
changeset
|
878 } |
e30495ae11de
*-login: Moved most of the common code to login-common.
Timo Sirainen <tss@iki.fi>
parents:
9283
diff
changeset
|
879 } |
e30495ae11de
*-login: Moved most of the common code to login-common.
Timo Sirainen <tss@iki.fi>
parents:
9283
diff
changeset
|
880 |
21970
866421afc7b7
*-login: Add client_vfuncs.send_raw_data()
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
21909
diff
changeset
|
881 void client_send_raw_data(struct client *client, const void *data, size_t size) |
866421afc7b7
*-login: Add client_vfuncs.send_raw_data()
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
21909
diff
changeset
|
882 { |
866421afc7b7
*-login: Add client_vfuncs.send_raw_data()
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
21909
diff
changeset
|
883 /* FIXME: NULL check is only for backwards compatibility - remove */ |
866421afc7b7
*-login: Add client_vfuncs.send_raw_data()
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
21909
diff
changeset
|
884 if (client->v.send_raw_data != NULL) |
866421afc7b7
*-login: Add client_vfuncs.send_raw_data()
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
21909
diff
changeset
|
885 client->v.send_raw_data(client, data, size); |
866421afc7b7
*-login: Add client_vfuncs.send_raw_data()
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
21909
diff
changeset
|
886 else |
866421afc7b7
*-login: Add client_vfuncs.send_raw_data()
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
21909
diff
changeset
|
887 client_common_send_raw_data(client, data, size); |
866421afc7b7
*-login: Add client_vfuncs.send_raw_data()
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
21909
diff
changeset
|
888 } |
866421afc7b7
*-login: Add client_vfuncs.send_raw_data()
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
21909
diff
changeset
|
889 |
9756
e30495ae11de
*-login: Moved most of the common code to login-common.
Timo Sirainen <tss@iki.fi>
parents:
9283
diff
changeset
|
890 void client_send_raw(struct client *client, const char *data) |
e30495ae11de
*-login: Moved most of the common code to login-common.
Timo Sirainen <tss@iki.fi>
parents:
9283
diff
changeset
|
891 { |
e30495ae11de
*-login: Moved most of the common code to login-common.
Timo Sirainen <tss@iki.fi>
parents:
9283
diff
changeset
|
892 client_send_raw_data(client, data, strlen(data)); |
e30495ae11de
*-login: Moved most of the common code to login-common.
Timo Sirainen <tss@iki.fi>
parents:
9283
diff
changeset
|
893 } |
e30495ae11de
*-login: Moved most of the common code to login-common.
Timo Sirainen <tss@iki.fi>
parents:
9283
diff
changeset
|
894 |
e30495ae11de
*-login: Moved most of the common code to login-common.
Timo Sirainen <tss@iki.fi>
parents:
9283
diff
changeset
|
895 bool client_read(struct client *client) |
e30495ae11de
*-login: Moved most of the common code to login-common.
Timo Sirainen <tss@iki.fi>
parents:
9283
diff
changeset
|
896 { |
e30495ae11de
*-login: Moved most of the common code to login-common.
Timo Sirainen <tss@iki.fi>
parents:
9283
diff
changeset
|
897 switch (i_stream_read(client->input)) { |
e30495ae11de
*-login: Moved most of the common code to login-common.
Timo Sirainen <tss@iki.fi>
parents:
9283
diff
changeset
|
898 case -2: |
e30495ae11de
*-login: Moved most of the common code to login-common.
Timo Sirainen <tss@iki.fi>
parents:
9283
diff
changeset
|
899 /* buffer full */ |
14146
e456e1bce47f
login-common API made more extensible for different kinds of protocols.
Timo Sirainen <tss@iki.fi>
parents:
14133
diff
changeset
|
900 client_notify_disconnect(client, |
e456e1bce47f
login-common API made more extensible for different kinds of protocols.
Timo Sirainen <tss@iki.fi>
parents:
14133
diff
changeset
|
901 CLIENT_DISCONNECT_RESOURCE_CONSTRAINT, |
e456e1bce47f
login-common API made more extensible for different kinds of protocols.
Timo Sirainen <tss@iki.fi>
parents:
14133
diff
changeset
|
902 "Input buffer full, aborting"); |
9756
e30495ae11de
*-login: Moved most of the common code to login-common.
Timo Sirainen <tss@iki.fi>
parents:
9283
diff
changeset
|
903 client_destroy(client, "Disconnected: Input buffer full"); |
e30495ae11de
*-login: Moved most of the common code to login-common.
Timo Sirainen <tss@iki.fi>
parents:
9283
diff
changeset
|
904 return FALSE; |
e30495ae11de
*-login: Moved most of the common code to login-common.
Timo Sirainen <tss@iki.fi>
parents:
9283
diff
changeset
|
905 case -1: |
e30495ae11de
*-login: Moved most of the common code to login-common.
Timo Sirainen <tss@iki.fi>
parents:
9283
diff
changeset
|
906 /* disconnected */ |
e30495ae11de
*-login: Moved most of the common code to login-common.
Timo Sirainen <tss@iki.fi>
parents:
9283
diff
changeset
|
907 client_destroy(client, "Disconnected"); |
e30495ae11de
*-login: Moved most of the common code to login-common.
Timo Sirainen <tss@iki.fi>
parents:
9283
diff
changeset
|
908 return FALSE; |
e30495ae11de
*-login: Moved most of the common code to login-common.
Timo Sirainen <tss@iki.fi>
parents:
9283
diff
changeset
|
909 case 0: |
e30495ae11de
*-login: Moved most of the common code to login-common.
Timo Sirainen <tss@iki.fi>
parents:
9283
diff
changeset
|
910 /* nothing new read */ |
e30495ae11de
*-login: Moved most of the common code to login-common.
Timo Sirainen <tss@iki.fi>
parents:
9283
diff
changeset
|
911 return TRUE; |
e30495ae11de
*-login: Moved most of the common code to login-common.
Timo Sirainen <tss@iki.fi>
parents:
9283
diff
changeset
|
912 default: |
e30495ae11de
*-login: Moved most of the common code to login-common.
Timo Sirainen <tss@iki.fi>
parents:
9283
diff
changeset
|
913 /* something was read */ |
e30495ae11de
*-login: Moved most of the common code to login-common.
Timo Sirainen <tss@iki.fi>
parents:
9283
diff
changeset
|
914 return TRUE; |
e30495ae11de
*-login: Moved most of the common code to login-common.
Timo Sirainen <tss@iki.fi>
parents:
9283
diff
changeset
|
915 } |
e30495ae11de
*-login: Moved most of the common code to login-common.
Timo Sirainen <tss@iki.fi>
parents:
9283
diff
changeset
|
916 } |
e30495ae11de
*-login: Moved most of the common code to login-common.
Timo Sirainen <tss@iki.fi>
parents:
9283
diff
changeset
|
917 |
e30495ae11de
*-login: Moved most of the common code to login-common.
Timo Sirainen <tss@iki.fi>
parents:
9283
diff
changeset
|
918 void client_input(struct client *client) |
e30495ae11de
*-login: Moved most of the common code to login-common.
Timo Sirainen <tss@iki.fi>
parents:
9283
diff
changeset
|
919 { |
e30495ae11de
*-login: Moved most of the common code to login-common.
Timo Sirainen <tss@iki.fi>
parents:
9283
diff
changeset
|
920 client->v.input(client); |
e30495ae11de
*-login: Moved most of the common code to login-common.
Timo Sirainen <tss@iki.fi>
parents:
9283
diff
changeset
|
921 } |
21741
ad2aa897a8d7
*-login: Change API for how login_plugins hook into client allocation.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
21722
diff
changeset
|
922 |
ad2aa897a8d7
*-login: Change API for how login_plugins hook into client allocation.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
21722
diff
changeset
|
923 void client_common_init(void) |
ad2aa897a8d7
*-login: Change API for how login_plugins hook into client allocation.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
21722
diff
changeset
|
924 { |
ad2aa897a8d7
*-login: Change API for how login_plugins hook into client allocation.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
21722
diff
changeset
|
925 i_array_init(&module_hooks, 32); |
ad2aa897a8d7
*-login: Change API for how login_plugins hook into client allocation.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
21722
diff
changeset
|
926 } |
ad2aa897a8d7
*-login: Change API for how login_plugins hook into client allocation.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
21722
diff
changeset
|
927 |
ad2aa897a8d7
*-login: Change API for how login_plugins hook into client allocation.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
21722
diff
changeset
|
928 void client_common_deinit(void) |
ad2aa897a8d7
*-login: Change API for how login_plugins hook into client allocation.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
21722
diff
changeset
|
929 { |
ad2aa897a8d7
*-login: Change API for how login_plugins hook into client allocation.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
21722
diff
changeset
|
930 array_free(&module_hooks); |
ad2aa897a8d7
*-login: Change API for how login_plugins hook into client allocation.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
21722
diff
changeset
|
931 } |