client-common.h revision 3609e0b9b8fcd1a183a785af690cdcad33c345aa
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen#include "master-login.h" /* for LOGIN_MAX_SESSION_ID_LEN */
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen/* max. size of input buffer. this means:
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen IMAP: Max. length of command's all parameters. SASL-IR is read into
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen a separate larger buffer.
bbce20cb4e5739e9a06058cf8ee1f38a7f6884f6Timo Sirainen POP3: Max. length of a command line (spec says 512 would be enough)
213b139965e8bde6c8aff02ffd9fd39a74c887a9Timo Sirainen (MASTER_AUTH_MAX_DATA_SIZE - LOGIN_MAX_MASTER_PREFIX_LEN - \
a24f6b02ed8d0dde933a715be1c86f01977bf610Timo Sirainen/* max. size of output buffer. if it gets full, the client is disconnected.
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen SASL authentication gives the largest output. */
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen/* Max. length of SASL authentication buffer. */
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen/* Disconnect client after this many milliseconds if it hasn't managed
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen to log in yet. */
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen#define CLIENT_LOGIN_TIMEOUT_MSECS (MASTER_LOGIN_TIMEOUT_SECS*1000)
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen "Waiting for authentication process to respond.."
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen "Waiting for authentication master process to respond.."
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen /* for proxying */
93b29720c5141f787bd1861796867e4595c9d084Timo Sirainen /* all the key=value fields returned by passdb */
93b29720c5141f787bd1861796867e4595c9d084Timo Sirainen const char *const *all_fields;
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen void (*create)(struct client *client, void **other_sets);
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen void (*notify_auth_ready)(struct client *client);
a050ca9def13949dbaa67bd6574a41c4f397ae26Timo Sirainen void (*notify_disconnect)(struct client *client,
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen const char *text);
a050ca9def13949dbaa67bd6574a41c4f397ae26Timo Sirainen void (*notify_starttls)(struct client *client,
0d658231054332c3f4c04aab0422af649de89a8cTimo Sirainen void (*auth_send_challenge)(struct client *client, const char *data);
0d658231054332c3f4c04aab0422af649de89a8cTimo Sirainen void (*auth_parse_response)(struct client *client);
0d658231054332c3f4c04aab0422af649de89a8cTimo Sirainen const char *text);
0d658231054332c3f4c04aab0422af649de89a8cTimo Sirainen int (*proxy_parse_line)(struct client *client, const char *line);
0d658231054332c3f4c04aab0422af649de89a8cTimo Sirainen void (*proxy_error)(struct client *client, const char *text);
f2786c07cbd4a7a0a6a46c3e06dc4545aaf2f278Timo Sirainen const char *(*proxy_get_state)(struct client *client);
45e62043058738e294f89504c319d852e25943ccTimo Sirainen bool (*input_next_cmd)(struct client *client);
9df8c9225140d9d1df5ddf4c6c9da61662ae6c44Timo Sirainen /* If disconnected=FALSE, the client is in "clients" list.
9df8c9225140d9d1df5ddf4c6c9da61662ae6c44Timo Sirainen If fd_proxying=TRUE, the client is in "client_fd_proxies" list.
9df8c9225140d9d1df5ddf4c6c9da61662ae6c44Timo Sirainen Otherwise, either the client will soon be freed or it's only
9df8c9225140d9d1df5ddf4c6c9da61662ae6c44Timo Sirainen referenced via "login_proxies" which doesn't use these pointers. */
fc7b17677ac1a5fa3f7fe13d5ef7dcfea8d9b4a1Timo Sirainen /* this pool gets free'd once proxying starts */
95a284736b8b11319a3f575ba249ba2eb7dbac1bTimo Sirainen const struct master_service_ssl_settings *ssl_set;
95a284736b8b11319a3f575ba249ba2eb7dbac1bTimo Sirainen const char *session_id, *listener_name, *postlogin_socket_path;
fc7b17677ac1a5fa3f7fe13d5ef7dcfea8d9b4a1Timo Sirainen char *proxy_user, *proxy_master_user, *proxy_password;
fc7b17677ac1a5fa3f7fe13d5ef7dcfea8d9b4a1Timo Sirainen const char *const *auth_passdb_args;
1b56f5fdd415270c743a38719d41b4d9497bcacdTimo Sirainen /* Module-specific contexts. */
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen ARRAY(union login_client_module_context *) module_contexts;
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen char *virtual_user, *virtual_user_orig, *virtual_auth_user;
f2786c07cbd4a7a0a6a46c3e06dc4545aaf2f278Timo Sirainen /* passdb user_* fields are set here after a successful auth.
f2786c07cbd4a7a0a6a46c3e06dc4545aaf2f278Timo Sirainen This is a NULL-terminated array where fields are in the same order
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen as in global_alt_usernames. If some field doesn't exist, it's "".
a050ca9def13949dbaa67bd6574a41c4f397ae26Timo Sirainen Can also be NULL if there are no user_* fields. */
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen /* director_username_hash cached, if non-zero */
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen void (*client_allocated)(struct client *client);
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainentypedef void login_client_allocated_func_t(struct client *client);
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainenvoid login_client_hooks_add(struct module *module,
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainenvoid login_client_hooks_remove(const struct login_client_hooks *hooks);
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen const struct master_service_ssl_settings *ssl_set);
c1d45cada20777e1973579d40d0ebe43f89bb053Timo Sirainenvoid client_init(struct client *client, void **other_sets);
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainenvoid client_disconnect(struct client *client, const char *reason);
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainenvoid client_destroy(struct client *client, const char *reason);
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen/* Destroy the client after a successful login. Either the client fd was
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen sent to the post-login process, or the connection will be proxied. */
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainenvoid client_destroy_success(struct client *client, const char *reason);
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainenbool client_unref(struct client **client) ATTR_NOWARN_UNUSED_RESULT;
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainenvoid client_cmd_starttls(struct client *client);
a8012fea2a7315033bc467acbf46be8e7323318cTimo Sirainenint client_get_plaintext_fd(struct client *client, int *fd_r, bool *close_fd_r);
834b90e1f426d1e3308670e09c050bcdea546eb8Timo Sirainenunsigned int clients_get_count(void) ATTR_PURE;
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainenunsigned int clients_get_fd_proxies_count(void);
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainenstruct client *clients_get_first_fd_proxy(void);
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainenvoid client_add_forward_field(struct client *client, const char *key,
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen const char *value);
a942db367328a91e3a0b6c810bb8abbcb7663707Timo Sirainenvoid client_log(struct client *client, const char *msg);
44ff75ca53188056ff5a3e50428e3f2078800b3cTimo Sirainenvoid client_log_err(struct client *client, const char *msg);
f1e1d821d93e4a1dc6ed8f23febde868b5d64cd5Timo Sirainenvoid client_log_warn(struct client *client, const char *msg);
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainenconst char *client_get_extra_disconnect_reason(struct client *client);
f2786c07cbd4a7a0a6a46c3e06dc4545aaf2f278Timo Sirainenvoid client_auth_respond(struct client *client, const char *response);
fadd878cd6098f5b873c21c121209a922679dae4Timo Sirainenbool client_is_tls_enabled(struct client *client);
fadd878cd6098f5b873c21c121209a922679dae4Timo Sirainenvoid client_auth_fail(struct client *client, const char *text);
fadd878cd6098f5b873c21c121209a922679dae4Timo Sirainenconst char *client_get_session_id(struct client *client);
fadd878cd6098f5b873c21c121209a922679dae4Timo Sirainenstatic inline bool
fadd878cd6098f5b873c21c121209a922679dae4Timo Sirainenvoid client_notify_auth_ready(struct client *client);
fadd878cd6098f5b873c21c121209a922679dae4Timo Sirainenvoid client_notify_status(struct client *client, bool bad, const char *text);
fadd878cd6098f5b873c21c121209a922679dae4Timo Sirainenvoid client_notify_disconnect(struct client *client,
d6f50f100ce17fa4b3a89e9567a5ff993b38b872Timo Sirainen const char *text);
fadd878cd6098f5b873c21c121209a922679dae4Timo Sirainenvoid client_send_raw_data(struct client *client, const void *data, size_t size);
fadd878cd6098f5b873c21c121209a922679dae4Timo Sirainenvoid client_send_raw(struct client *client, const char *data);
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainenvoid client_common_send_raw_data(struct client *client,
b7cf555b699d73f2d71de0dabc088af6a7be3627Timo Sirainenvoid client_common_default_free(struct client *client);
f1e1d821d93e4a1dc6ed8f23febde868b5d64cd5Timo Sirainenvoid client_set_auth_waiting(struct client *client);
f1e1d821d93e4a1dc6ed8f23febde868b5d64cd5Timo Sirainenvoid client_auth_send_challenge(struct client *client, const char *data);
a24f6b02ed8d0dde933a715be1c86f01977bf610Timo Sirainenvoid client_auth_parse_response(struct client *client);
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainenint client_auth_begin(struct client *client, const char *mech_name,
f1e1d821d93e4a1dc6ed8f23febde868b5d64cd5Timo Sirainenbool client_check_plaintext_auth(struct client *client, bool pass_sent);
a24f6b02ed8d0dde933a715be1c86f01977bf610Timo Sirainenint client_auth_read_line(struct client *client);
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainenvoid client_proxy_finish_destroy_client(struct client *client);
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainenvoid client_proxy_log_failure(struct client *client, const char *line);
6eb30032b4a50c383dea4c9c74342d906de6ad36Timo Sirainenvoid client_proxy_failed(struct client *client, bool send_line);
a24f6b02ed8d0dde933a715be1c86f01977bf610Timo Sirainenconst char *client_proxy_get_state(struct client *client);