b55f914c0ade77252cfd798ea8eb9a84bda56315Timo Sirainen#include "master-login.h" /* for LOGIN_MAX_SESSION_ID_LEN */
cd94aeaa294f7cc507206b4b2075852f00e14d61Timo Sirainen/* max. size of input buffer. this means:
decb23442f9e6cd5c4845a9cb162029b8c6d5f0fTimo Sirainen IMAP: Max. length of command's all parameters. SASL-IR is read into
decb23442f9e6cd5c4845a9cb162029b8c6d5f0fTimo Sirainen a separate larger buffer.
cd94aeaa294f7cc507206b4b2075852f00e14d61Timo Sirainen POP3: Max. length of a command line (spec says 512 would be enough)
b55f914c0ade77252cfd798ea8eb9a84bda56315Timo Sirainen (MASTER_AUTH_MAX_DATA_SIZE - LOGIN_MAX_MASTER_PREFIX_LEN - \
e248fe370c4047cee921a91b48edc37944ab0526Timo Sirainen/* max. size of output buffer. if it gets full, the client is disconnected.
e248fe370c4047cee921a91b48edc37944ab0526Timo Sirainen SASL authentication gives the largest output. */
7fa573e6ea36024f618492e7d3649a69c1b41028Timo Sirainen/* Max. length of SASL authentication buffer. */
5a9e240ebf8d0daaf029973973b52e415148070bTimo Sirainen/* Disconnect client after this many milliseconds if it hasn't managed
5a9e240ebf8d0daaf029973973b52e415148070bTimo Sirainen to log in yet. */
d99107ddf4d9bccb710994482daf65276a9d6321Timo Sirainen#define CLIENT_LOGIN_TIMEOUT_MSECS (MASTER_LOGIN_TIMEOUT_SECS*1000)
e248fe370c4047cee921a91b48edc37944ab0526Timo Sirainen "Waiting for authentication process to respond.."
e248fe370c4047cee921a91b48edc37944ab0526Timo Sirainen "Waiting for authentication master process to respond.."
e248fe370c4047cee921a91b48edc37944ab0526Timo Sirainen /* for proxying */
fd3d068169c6ec587c9c446f2ee45560a444334aTimo Sirainen /* all the key=value fields returned by passdb */
f059a046515f4b2b15a6c2a10a6f12f6166e39a5Timo Sirainen void (*create)(struct client *client, void **other_sets);
9f627b360ed38fdc54cb02ec5e67246c3f0d5b0fTimo Sirainen void (*notify_auth_ready)(struct client *client);
9f627b360ed38fdc54cb02ec5e67246c3f0d5b0fTimo Sirainen void (*notify_disconnect)(struct client *client,
9f627b360ed38fdc54cb02ec5e67246c3f0d5b0fTimo Sirainen const char *text);
9f627b360ed38fdc54cb02ec5e67246c3f0d5b0fTimo Sirainen void (*notify_starttls)(struct client *client,
46ec792dd4ccf6c34706c4774228301fafde6aa9Timo Sirainen void (*auth_send_challenge)(struct client *client, const char *data);
9f627b360ed38fdc54cb02ec5e67246c3f0d5b0fTimo Sirainen void (*auth_parse_response)(struct client *client);
9f627b360ed38fdc54cb02ec5e67246c3f0d5b0fTimo Sirainen const char *text);
e248fe370c4047cee921a91b48edc37944ab0526Timo Sirainen int (*proxy_parse_line)(struct client *client, const char *line);
9f627b360ed38fdc54cb02ec5e67246c3f0d5b0fTimo Sirainen void (*proxy_error)(struct client *client, const char *text);
2b96880f2d789d125aff6a95eaa7b51f558a6a1cTimo Sirainen const char *(*proxy_get_state)(struct client *client);
edfdc577ffe7408fd6463eb9dba11260d380ab53Timo Sirainen bool (*input_next_cmd)(struct client *client);
a7efba62b6235e5efc124cbf702ddeb547ca3665Timo Sirainen /* If disconnected=FALSE, the client is in "clients" list.
a7efba62b6235e5efc124cbf702ddeb547ca3665Timo Sirainen If fd_proxying=TRUE, the client is in "client_fd_proxies" list.
a7efba62b6235e5efc124cbf702ddeb547ca3665Timo Sirainen Otherwise, either the client will soon be freed or it's only
a7efba62b6235e5efc124cbf702ddeb547ca3665Timo Sirainen referenced via "login_proxies" which doesn't use these pointers. */
b045b66988bfbaa2795791e42ee724fae6f0db1cAki Tuomi /* this pool gets free'd once proxying starts */
f29756821a4c6b12b73e4a2a3e1c230117a43773Timo Sirainen const struct master_service_ssl_settings *ssl_set;
8ce3071e80b9973230048ecadfcb073fb82cc69fTimo Sirainen const char *session_id, *listener_name, *postlogin_socket_path;
e248fe370c4047cee921a91b48edc37944ab0526Timo Sirainen char *proxy_user, *proxy_master_user, *proxy_password;
9132f9df4e12ed5293c70957813aa3736444a13cTimo Sirainen /* Module-specific contexts. */
9132f9df4e12ed5293c70957813aa3736444a13cTimo Sirainen ARRAY(union login_client_module_context *) module_contexts;
2f90189c6ee66a17f7bf838a8eb8a69868630fb8Timo Sirainen char *virtual_user, *virtual_user_orig, *virtual_auth_user;
ce1a6c9b82117d253df9acd77e54ac84dd8a247eTimo Sirainen /* passdb user_* fields are set here after a successful auth.
ce1a6c9b82117d253df9acd77e54ac84dd8a247eTimo Sirainen This is a NULL-terminated array where fields are in the same order
ce1a6c9b82117d253df9acd77e54ac84dd8a247eTimo Sirainen as in global_alt_usernames. If some field doesn't exist, it's "".
ce1a6c9b82117d253df9acd77e54ac84dd8a247eTimo Sirainen Can also be NULL if there are no user_* fields. */
ec9429535e925610513bd6bfde6729e273082ccbTimo Sirainen /* director_username_hash cached, if non-zero */
c5e62353a11087958ea4e619660e084a613e1a37Timo Sirainen void (*client_allocated)(struct client *client);
9132f9df4e12ed5293c70957813aa3736444a13cTimo Sirainentypedef void login_client_allocated_func_t(struct client *client);
c5e62353a11087958ea4e619660e084a613e1a37Timo Sirainenvoid login_client_hooks_add(struct module *module,
c5e62353a11087958ea4e619660e084a613e1a37Timo Sirainenvoid login_client_hooks_remove(const struct login_client_hooks *hooks);
66ea9eaaa2d7531b3be8f633937628c94d907031Timo Sirainen const struct master_service_ssl_settings *ssl_set);
66ea9eaaa2d7531b3be8f633937628c94d907031Timo Sirainenvoid client_init(struct client *client, void **other_sets);
dfafc4ac89195b8cdd48afa619599d5b392ef479Stephan Boschvoid client_disconnect(struct client *client, const char *reason);
e248fe370c4047cee921a91b48edc37944ab0526Timo Sirainenvoid client_destroy(struct client *client, const char *reason);
87dbf3e85526ccde5908a611eb9a798f1d0ccac3Timo Sirainen/* Destroy the client after a successful login. Either the client fd was
87dbf3e85526ccde5908a611eb9a798f1d0ccac3Timo Sirainen sent to the post-login process, or the connection will be proxied. */
e248fe370c4047cee921a91b48edc37944ab0526Timo Sirainenvoid client_destroy_success(struct client *client, const char *reason);
b66d803de86bfb411165b3465b0d9ef64ecfe2a1Timo Sirainenbool client_unref(struct client **client) ATTR_NOWARN_UNUSED_RESULT;
e248fe370c4047cee921a91b48edc37944ab0526Timo Sirainenvoid client_cmd_starttls(struct client *client);
87dbf3e85526ccde5908a611eb9a798f1d0ccac3Timo Sirainenint client_get_plaintext_fd(struct client *client, int *fd_r, bool *close_fd_r);
68a4946b12583b88fa802e52ebee45cd96056772Timo Sirainenunsigned int clients_get_count(void) ATTR_PURE;
0256180043b9f55b606b523b775e8b23b1b12f83Timo Sirainenunsigned int clients_get_fd_proxies_count(void);
0256180043b9f55b606b523b775e8b23b1b12f83Timo Sirainenstruct client *clients_get_first_fd_proxy(void);
c4ec7cb598805b1387dc3aab59ec8f32d8cc24e1Timo Sirainenvoid client_add_forward_field(struct client *client, const char *key,
c4ec7cb598805b1387dc3aab59ec8f32d8cc24e1Timo Sirainen const char *value);
e248fe370c4047cee921a91b48edc37944ab0526Timo Sirainenvoid client_log(struct client *client, const char *msg);
e248fe370c4047cee921a91b48edc37944ab0526Timo Sirainenvoid client_log_err(struct client *client, const char *msg);
b9c76fe9d9ca194816606342da1ddbd9be6bc8abTimo Sirainenvoid client_log_warn(struct client *client, const char *msg);
e248fe370c4047cee921a91b48edc37944ab0526Timo Sirainenconst char *client_get_extra_disconnect_reason(struct client *client);
9f627b360ed38fdc54cb02ec5e67246c3f0d5b0fTimo Sirainenvoid client_auth_respond(struct client *client, const char *response);
6a9e034441607c0c5a61858ff559af4615ac31caTimo Sirainenbool client_is_tls_enabled(struct client *client);
9f627b360ed38fdc54cb02ec5e67246c3f0d5b0fTimo Sirainenvoid client_auth_fail(struct client *client, const char *text);
b55f914c0ade77252cfd798ea8eb9a84bda56315Timo Sirainenconst char *client_get_session_id(struct client *client);
a1852ab4cf0a942a3fcf4ca5636a7932ebcc7970Stephan Boschstatic inline bool
9f627b360ed38fdc54cb02ec5e67246c3f0d5b0fTimo Sirainenvoid client_notify_auth_ready(struct client *client);
9f627b360ed38fdc54cb02ec5e67246c3f0d5b0fTimo Sirainenvoid client_notify_status(struct client *client, bool bad, const char *text);
9f627b360ed38fdc54cb02ec5e67246c3f0d5b0fTimo Sirainenvoid client_notify_disconnect(struct client *client,
9f627b360ed38fdc54cb02ec5e67246c3f0d5b0fTimo Sirainen const char *text);
e248fe370c4047cee921a91b48edc37944ab0526Timo Sirainenvoid client_send_raw_data(struct client *client, const void *data, size_t size);
e248fe370c4047cee921a91b48edc37944ab0526Timo Sirainenvoid client_send_raw(struct client *client, const char *data);
ae797f3368ebb86e7786ca25d7c9c703f672b9f5Timo Sirainenvoid client_common_send_raw_data(struct client *client,
b84eff65e25ae86dfd6f798386577209b94838c6Timo Sirainenvoid client_common_default_free(struct client *client);
e248fe370c4047cee921a91b48edc37944ab0526Timo Sirainenvoid client_set_auth_waiting(struct client *client);
46ec792dd4ccf6c34706c4774228301fafde6aa9Timo Sirainenvoid client_auth_send_challenge(struct client *client, const char *data);
9f627b360ed38fdc54cb02ec5e67246c3f0d5b0fTimo Sirainenvoid client_auth_parse_response(struct client *client);
e248fe370c4047cee921a91b48edc37944ab0526Timo Sirainenint client_auth_begin(struct client *client, const char *mech_name,
e248fe370c4047cee921a91b48edc37944ab0526Timo Sirainenbool client_check_plaintext_auth(struct client *client, bool pass_sent);
decb23442f9e6cd5c4845a9cb162029b8c6d5f0fTimo Sirainenint client_auth_read_line(struct client *client);
e248fe370c4047cee921a91b48edc37944ab0526Timo Sirainenvoid client_proxy_finish_destroy_client(struct client *client);
e248fe370c4047cee921a91b48edc37944ab0526Timo Sirainenvoid client_proxy_log_failure(struct client *client, const char *line);
e248fe370c4047cee921a91b48edc37944ab0526Timo Sirainenvoid client_proxy_failed(struct client *client, bool send_line);
2b96880f2d789d125aff6a95eaa7b51f558a6a1cTimo Sirainenconst char *client_proxy_get_state(struct client *client);