client-common.h revision b045b66988bfbaa2795791e42ee724fae6f0db1c
02c335c23bf5fa225a467c19f2c063fb0dc7b8c3Timo Sirainen#ifndef CLIENT_COMMON_H
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainen#define CLIENT_COMMON_H
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainen
c3a636e4c9ae776e0eed06b6d7ad1ccfb6003afdTimo Sirainenstruct module;
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainen
d6601a0bc4fd60e58bedbddf2481abd82cba76d7Timo Sirainen#include "net.h"
fa2a11210f20fb8998ed656f75e163191c8047e6Timo Sirainen#include "login-proxy.h"
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainen#include "sasl-server.h"
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainen#include "master-login.h" /* for LOGIN_MAX_SESSION_ID_LEN */
abf015c9682f0f723db87a7c97bc284ef814818fTimo Sirainen
70afae43cc78ea6ecca83f6c587072c442a15ec1Timo Sirainen#define LOGIN_MAX_SESSION_ID_LEN 64
fa2a11210f20fb8998ed656f75e163191c8047e6Timo Sirainen#define LOGIN_MAX_MASTER_PREFIX_LEN 128
fa2a11210f20fb8998ed656f75e163191c8047e6Timo Sirainen
fa2a11210f20fb8998ed656f75e163191c8047e6Timo Sirainen/* max. size of input buffer. this means:
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainen
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainen IMAP: Max. length of command's all parameters. SASL-IR is read into
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainen a separate larger buffer.
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainen POP3: Max. length of a command line (spec says 512 would be enough)
5d03d9f439e41c90215a3c938ffebe4c2a8ae257Timo Sirainen*/
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainen#define LOGIN_MAX_INBUF_SIZE \
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainen (MASTER_AUTH_MAX_DATA_SIZE - LOGIN_MAX_MASTER_PREFIX_LEN - \
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainen LOGIN_MAX_SESSION_ID_LEN)
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainen/* max. size of output buffer. if it gets full, the client is disconnected.
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainen SASL authentication gives the largest output. */
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainen#define LOGIN_MAX_OUTBUF_SIZE 4096
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainen
542e28b384a6b26695f3e8de38fd5727d06f3333Timo Sirainen/* Max. length of SASL authentication buffer. */
542e28b384a6b26695f3e8de38fd5727d06f3333Timo Sirainen#define LOGIN_MAX_AUTH_BUF_SIZE 8192
542e28b384a6b26695f3e8de38fd5727d06f3333Timo Sirainen
542e28b384a6b26695f3e8de38fd5727d06f3333Timo Sirainen/* Disconnect client after this many milliseconds if it hasn't managed
542e28b384a6b26695f3e8de38fd5727d06f3333Timo Sirainen to log in yet. */
542e28b384a6b26695f3e8de38fd5727d06f3333Timo Sirainen#define CLIENT_LOGIN_TIMEOUT_MSECS (MASTER_LOGIN_TIMEOUT_SECS*1000)
542e28b384a6b26695f3e8de38fd5727d06f3333Timo Sirainen
c3a636e4c9ae776e0eed06b6d7ad1ccfb6003afdTimo Sirainen#define AUTH_SERVER_WAITING_MSG \
c3a636e4c9ae776e0eed06b6d7ad1ccfb6003afdTimo Sirainen "Waiting for authentication process to respond.."
c3a636e4c9ae776e0eed06b6d7ad1ccfb6003afdTimo Sirainen#define AUTH_MASTER_WAITING_MSG \
c3a636e4c9ae776e0eed06b6d7ad1ccfb6003afdTimo Sirainen "Waiting for authentication master process to respond.."
3b22894b8805b186c73d8b754001e8d7e944be85Timo Sirainen
3b22894b8805b186c73d8b754001e8d7e944be85Timo Sirainenstruct master_service_connection;
3b22894b8805b186c73d8b754001e8d7e944be85Timo Sirainen
13b063ba3ea51256fd97d7fa883f14cb08842b0dTimo Sirainenenum client_disconnect_reason {
13b063ba3ea51256fd97d7fa883f14cb08842b0dTimo Sirainen CLIENT_DISCONNECT_TIMEOUT,
13b063ba3ea51256fd97d7fa883f14cb08842b0dTimo Sirainen CLIENT_DISCONNECT_SYSTEM_SHUTDOWN,
13b063ba3ea51256fd97d7fa883f14cb08842b0dTimo Sirainen CLIENT_DISCONNECT_RESOURCE_CONSTRAINT,
13b063ba3ea51256fd97d7fa883f14cb08842b0dTimo Sirainen CLIENT_DISCONNECT_INTERNAL_ERROR
13b063ba3ea51256fd97d7fa883f14cb08842b0dTimo Sirainen};
13b063ba3ea51256fd97d7fa883f14cb08842b0dTimo Sirainen
13b063ba3ea51256fd97d7fa883f14cb08842b0dTimo Sirainenenum client_auth_fail_code {
13b063ba3ea51256fd97d7fa883f14cb08842b0dTimo Sirainen CLIENT_AUTH_FAIL_CODE_NONE = 0,
4da8c6cdefabd31262318c32da3c13de1d9ea953Timo Sirainen CLIENT_AUTH_FAIL_CODE_AUTHZFAILED,
5d03d9f439e41c90215a3c938ffebe4c2a8ae257Timo Sirainen CLIENT_AUTH_FAIL_CODE_TEMPFAIL,
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainen CLIENT_AUTH_FAIL_CODE_USER_DISABLED,
1388b590dbd85245b591346f860bc1319953318aTimo Sirainen CLIENT_AUTH_FAIL_CODE_PASS_EXPIRED,
1388b590dbd85245b591346f860bc1319953318aTimo Sirainen CLIENT_AUTH_FAIL_CODE_INVALID_BASE64,
49621bf0ef1d55aaaa2dc7d76011cbfeabdcfbe1Timo Sirainen CLIENT_AUTH_FAIL_CODE_LOGIN_DISABLED,
fa2433aebcf3fccfa30ca9eed9b1a9166cf92ee2Timo Sirainen CLIENT_AUTH_FAIL_CODE_MECH_INVALID,
4da8c6cdefabd31262318c32da3c13de1d9ea953Timo Sirainen CLIENT_AUTH_FAIL_CODE_MECH_SSL_REQUIRED,
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainen};
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainen
5d03d9f439e41c90215a3c938ffebe4c2a8ae257Timo Sirainenenum client_auth_result {
5d03d9f439e41c90215a3c938ffebe4c2a8ae257Timo Sirainen CLIENT_AUTH_RESULT_SUCCESS,
5d03d9f439e41c90215a3c938ffebe4c2a8ae257Timo Sirainen CLIENT_AUTH_RESULT_REFERRAL_SUCCESS,
3482fee0e3733456512ba110780824e6daa7ff9fTimo Sirainen CLIENT_AUTH_RESULT_REFERRAL_NOLOGIN,
3482fee0e3733456512ba110780824e6daa7ff9fTimo Sirainen CLIENT_AUTH_RESULT_ABORTED,
3482fee0e3733456512ba110780824e6daa7ff9fTimo Sirainen CLIENT_AUTH_RESULT_AUTHFAILED,
0dffa25d211be541ee3c953b23566a1a990789dfTimo Sirainen CLIENT_AUTH_RESULT_AUTHFAILED_REASON,
0dffa25d211be541ee3c953b23566a1a990789dfTimo Sirainen CLIENT_AUTH_RESULT_AUTHZFAILED,
0dffa25d211be541ee3c953b23566a1a990789dfTimo Sirainen CLIENT_AUTH_RESULT_TEMPFAIL,
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainen CLIENT_AUTH_RESULT_PASS_EXPIRED,
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainen CLIENT_AUTH_RESULT_SSL_REQUIRED,
4da8c6cdefabd31262318c32da3c13de1d9ea953Timo Sirainen CLIENT_AUTH_RESULT_INVALID_BASE64,
367e28a16854ee9f7247b2518f36f5e9163fcc10Timo Sirainen CLIENT_AUTH_RESULT_LOGIN_DISABLED,
1388b590dbd85245b591346f860bc1319953318aTimo Sirainen CLIENT_AUTH_RESULT_MECH_INVALID,
d1fff80640050631b06bfab904a34b2ad24601e8Timo Sirainen CLIENT_AUTH_RESULT_MECH_SSL_REQUIRED
b9b841558c5f91db7f5fc71c0ac62aad1bbf6418Timo Sirainen};
d1fff80640050631b06bfab904a34b2ad24601e8Timo Sirainen
1388b590dbd85245b591346f860bc1319953318aTimo Sirainenstruct client_auth_reply {
2f90189c6ee66a17f7bf838a8eb8a69868630fb8Timo Sirainen const char *master_user, *reason;
1388b590dbd85245b591346f860bc1319953318aTimo Sirainen enum client_auth_fail_code fail_code;
f3e17726502b6cf1912f30aae7e283b5d31ea69cTimo Sirainen
367e28a16854ee9f7247b2518f36f5e9163fcc10Timo Sirainen /* for proxying */
2fb9ae42f9e36388ec6db24188b9108434043fd0Timo Sirainen const char *host, *hostip, *source_ip;
367e28a16854ee9f7247b2518f36f5e9163fcc10Timo Sirainen const char *destuser, *password, *proxy_mech;
e438c85a6b0f77889e25913bbbba808d6078282dStephan Bosch in_port_t port;
c977ee6ce06cbc0b4668fde1ec34f2f5e1773684Timo Sirainen unsigned int proxy_timeout_msecs;
c977ee6ce06cbc0b4668fde1ec34f2f5e1773684Timo Sirainen unsigned int proxy_refresh_secs;
0dffa25d211be541ee3c953b23566a1a990789dfTimo Sirainen enum login_proxy_ssl_flags ssl_flags;
0dffa25d211be541ee3c953b23566a1a990789dfTimo Sirainen
367e28a16854ee9f7247b2518f36f5e9163fcc10Timo Sirainen /* all the key=value fields returned by passdb */
367e28a16854ee9f7247b2518f36f5e9163fcc10Timo Sirainen const char *const *all_fields;
38f227941bcf673e0e523c1ac7267bca9cbcd2c4Timo Sirainen
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainen bool proxy:1;
0f5dc4da3982053036be65190e44bf28a67b1ca2Timo Sirainen bool proxy_nopipelining:1;
265cb53cf8d5cb35edd4c4ff086ca6165605b708Timo Sirainen bool proxy_not_trusted:1;
265cb53cf8d5cb35edd4c4ff086ca6165605b708Timo Sirainen bool nologin:1;
265cb53cf8d5cb35edd4c4ff086ca6165605b708Timo Sirainen};
265cb53cf8d5cb35edd4c4ff086ca6165605b708Timo Sirainen
0f5dc4da3982053036be65190e44bf28a67b1ca2Timo Sirainenstruct client_vfuncs {
0f5dc4da3982053036be65190e44bf28a67b1ca2Timo Sirainen struct client *(*alloc)(pool_t pool);
265cb53cf8d5cb35edd4c4ff086ca6165605b708Timo Sirainen void (*create)(struct client *client, void **other_sets);
c07d7eb3ca9754367697c98f5e66a3982a45d142Timo Sirainen void (*destroy)(struct client *client);
c07d7eb3ca9754367697c98f5e66a3982a45d142Timo Sirainen void (*notify_auth_ready)(struct client *client);
c07d7eb3ca9754367697c98f5e66a3982a45d142Timo Sirainen void (*notify_disconnect)(struct client *client,
c07d7eb3ca9754367697c98f5e66a3982a45d142Timo Sirainen enum client_disconnect_reason reason,
c07d7eb3ca9754367697c98f5e66a3982a45d142Timo Sirainen const char *text);
c07d7eb3ca9754367697c98f5e66a3982a45d142Timo Sirainen void (*notify_status)(struct client *client,
c07d7eb3ca9754367697c98f5e66a3982a45d142Timo Sirainen bool bad, const char *text);
c07d7eb3ca9754367697c98f5e66a3982a45d142Timo Sirainen void (*notify_starttls)(struct client *client,
c07d7eb3ca9754367697c98f5e66a3982a45d142Timo Sirainen bool success, const char *text);
c07d7eb3ca9754367697c98f5e66a3982a45d142Timo Sirainen void (*starttls)(struct client *client);
c07d7eb3ca9754367697c98f5e66a3982a45d142Timo Sirainen void (*input)(struct client *client);
c07d7eb3ca9754367697c98f5e66a3982a45d142Timo Sirainen void (*auth_send_challenge)(struct client *client, const char *data);
c07d7eb3ca9754367697c98f5e66a3982a45d142Timo Sirainen void (*auth_parse_response)(struct client *client);
2eb2cf8eeb763bd5ca9b6848dce32f0303e88ec1Timo Sirainen void (*auth_result)(struct client *client,
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainen enum client_auth_result result,
c07d7eb3ca9754367697c98f5e66a3982a45d142Timo Sirainen const struct client_auth_reply *reply,
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainen const char *text);
c07d7eb3ca9754367697c98f5e66a3982a45d142Timo Sirainen void (*proxy_reset)(struct client *client);
c07d7eb3ca9754367697c98f5e66a3982a45d142Timo Sirainen int (*proxy_parse_line)(struct client *client, const char *line);
c07d7eb3ca9754367697c98f5e66a3982a45d142Timo Sirainen void (*proxy_error)(struct client *client, const char *text);
c07d7eb3ca9754367697c98f5e66a3982a45d142Timo Sirainen const char *(*proxy_get_state)(struct client *client);
c07d7eb3ca9754367697c98f5e66a3982a45d142Timo Sirainen};
c07d7eb3ca9754367697c98f5e66a3982a45d142Timo Sirainen
c07d7eb3ca9754367697c98f5e66a3982a45d142Timo Sirainenstruct client {
c07d7eb3ca9754367697c98f5e66a3982a45d142Timo Sirainen struct client *prev, *next;
c07d7eb3ca9754367697c98f5e66a3982a45d142Timo Sirainen pool_t pool;
c07d7eb3ca9754367697c98f5e66a3982a45d142Timo Sirainen /* this pool gets free'd once proxying starts */
096e109f9f332bc758ca5e22ec64337379c5f231Timo Sirainen pool_t preproxy_pool;
096e109f9f332bc758ca5e22ec64337379c5f231Timo Sirainen struct client_vfuncs v;
367e28a16854ee9f7247b2518f36f5e9163fcc10Timo Sirainen struct client_vfuncs *vlast;
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainen
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainen time_t created;
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainen int refcount;
c07d7eb3ca9754367697c98f5e66a3982a45d142Timo Sirainen
c07d7eb3ca9754367697c98f5e66a3982a45d142Timo Sirainen struct ip_addr local_ip;
c07d7eb3ca9754367697c98f5e66a3982a45d142Timo Sirainen struct ip_addr ip;
c07d7eb3ca9754367697c98f5e66a3982a45d142Timo Sirainen struct ip_addr real_remote_ip, real_local_ip;
c07d7eb3ca9754367697c98f5e66a3982a45d142Timo Sirainen in_port_t local_port, remote_port;
c07d7eb3ca9754367697c98f5e66a3982a45d142Timo Sirainen in_port_t real_local_port, real_remote_port;
1f5597beba229acd914e30a6da3c0e62d83b6e8fTimo Sirainen struct ssl_proxy *ssl_proxy;
2ac5f36aa7c2e7a07ba8815d43a6d7483f62e74cTimo Sirainen const struct login_settings *set;
c07d7eb3ca9754367697c98f5e66a3982a45d142Timo Sirainen const struct master_service_ssl_settings *ssl_set;
c07d7eb3ca9754367697c98f5e66a3982a45d142Timo Sirainen const char *session_id, *listener_name, *postlogin_socket_path;
c07d7eb3ca9754367697c98f5e66a3982a45d142Timo Sirainen const char *local_name;
c07d7eb3ca9754367697c98f5e66a3982a45d142Timo Sirainen
c07d7eb3ca9754367697c98f5e66a3982a45d142Timo Sirainen int fd;
c07d7eb3ca9754367697c98f5e66a3982a45d142Timo Sirainen struct istream *input;
47569a4b2b4d3cc55e786177798c922c3c44233dTimo Sirainen struct ostream *output;
47569a4b2b4d3cc55e786177798c922c3c44233dTimo Sirainen struct io *io;
7af5f78e9fee296e42430d94ef252ff0333d8024Timo Sirainen struct timeout *to_auth_waiting;
7af5f78e9fee296e42430d94ef252ff0333d8024Timo Sirainen struct timeout *to_disconnect;
7af5f78e9fee296e42430d94ef252ff0333d8024Timo Sirainen
7af5f78e9fee296e42430d94ef252ff0333d8024Timo Sirainen unsigned char *master_data_prefix;
7af5f78e9fee296e42430d94ef252ff0333d8024Timo Sirainen unsigned int master_data_prefix_len;
47569a4b2b4d3cc55e786177798c922c3c44233dTimo Sirainen
c07d7eb3ca9754367697c98f5e66a3982a45d142Timo Sirainen struct login_proxy *login_proxy;
c07d7eb3ca9754367697c98f5e66a3982a45d142Timo Sirainen char *proxy_user, *proxy_master_user, *proxy_password;
c07d7eb3ca9754367697c98f5e66a3982a45d142Timo Sirainen const struct dsasl_client_mech *proxy_mech;
c07d7eb3ca9754367697c98f5e66a3982a45d142Timo Sirainen struct dsasl_client *proxy_sasl_client;
c07d7eb3ca9754367697c98f5e66a3982a45d142Timo Sirainen unsigned int proxy_ttl;
c07d7eb3ca9754367697c98f5e66a3982a45d142Timo Sirainen
c07d7eb3ca9754367697c98f5e66a3982a45d142Timo Sirainen char *auth_mech_name;
c07d7eb3ca9754367697c98f5e66a3982a45d142Timo Sirainen struct auth_client_request *auth_request;
c07d7eb3ca9754367697c98f5e66a3982a45d142Timo Sirainen string_t *auth_response;
c07d7eb3ca9754367697c98f5e66a3982a45d142Timo Sirainen time_t auth_first_started, auth_finished;
c07d7eb3ca9754367697c98f5e66a3982a45d142Timo Sirainen const char *sasl_final_resp;
c07d7eb3ca9754367697c98f5e66a3982a45d142Timo Sirainen const char *const *auth_passdb_args;
c07d7eb3ca9754367697c98f5e66a3982a45d142Timo Sirainen
c07d7eb3ca9754367697c98f5e66a3982a45d142Timo Sirainen unsigned int master_auth_id;
c07d7eb3ca9754367697c98f5e66a3982a45d142Timo Sirainen unsigned int master_tag;
c07d7eb3ca9754367697c98f5e66a3982a45d142Timo Sirainen sasl_server_callback_t *sasl_callback;
1f5597beba229acd914e30a6da3c0e62d83b6e8fTimo Sirainen
47569a4b2b4d3cc55e786177798c922c3c44233dTimo Sirainen unsigned int bad_counter;
47569a4b2b4d3cc55e786177798c922c3c44233dTimo Sirainen unsigned int auth_attempts, auth_successes;
47569a4b2b4d3cc55e786177798c922c3c44233dTimo Sirainen enum client_auth_fail_code last_auth_fail;
47569a4b2b4d3cc55e786177798c922c3c44233dTimo Sirainen pid_t mail_pid;
79fff45046397ba48c8693d5f37a1fd93096987fTimo Sirainen
1f5597beba229acd914e30a6da3c0e62d83b6e8fTimo Sirainen /* Module-specific contexts. */
1f5597beba229acd914e30a6da3c0e62d83b6e8fTimo Sirainen ARRAY(union login_client_module_context *) module_contexts;
1f5597beba229acd914e30a6da3c0e62d83b6e8fTimo Sirainen
1f5597beba229acd914e30a6da3c0e62d83b6e8fTimo Sirainen char *virtual_user, *virtual_user_orig, *virtual_auth_user;
1f5597beba229acd914e30a6da3c0e62d83b6e8fTimo Sirainen /* passdb user_* fields are set here after a successful auth.
47569a4b2b4d3cc55e786177798c922c3c44233dTimo Sirainen This is a NULL-terminated array where fields are in the same order
47569a4b2b4d3cc55e786177798c922c3c44233dTimo Sirainen as in global_alt_usernames. If some field doesn't exist, it's "".
47569a4b2b4d3cc55e786177798c922c3c44233dTimo Sirainen Can also be NULL if there are no user_* fields. */
47569a4b2b4d3cc55e786177798c922c3c44233dTimo Sirainen const char **alt_usernames;
47569a4b2b4d3cc55e786177798c922c3c44233dTimo Sirainen bool destroyed:1;
c07d7eb3ca9754367697c98f5e66a3982a45d142Timo Sirainen bool input_blocked:1;
c07d7eb3ca9754367697c98f5e66a3982a45d142Timo Sirainen bool login_success:1;
417642ddac19708bea6dd2c2bbeaf6a9578d521bTimo Sirainen bool starttls:1;
417642ddac19708bea6dd2c2bbeaf6a9578d521bTimo Sirainen bool tls:1;
417642ddac19708bea6dd2c2bbeaf6a9578d521bTimo Sirainen bool secured:1;
417642ddac19708bea6dd2c2bbeaf6a9578d521bTimo Sirainen bool trusted:1;
417642ddac19708bea6dd2c2bbeaf6a9578d521bTimo Sirainen bool ssl_servername_settings_read:1;
c07d7eb3ca9754367697c98f5e66a3982a45d142Timo Sirainen bool authenticating:1;
c07d7eb3ca9754367697c98f5e66a3982a45d142Timo Sirainen bool auth_try_aborted:1;
c07d7eb3ca9754367697c98f5e66a3982a45d142Timo Sirainen bool auth_initializing:1;
c07d7eb3ca9754367697c98f5e66a3982a45d142Timo Sirainen bool auth_process_comm_fail:1;
c07d7eb3ca9754367697c98f5e66a3982a45d142Timo Sirainen bool proxy_auth_failed:1;
c07d7eb3ca9754367697c98f5e66a3982a45d142Timo Sirainen bool proxy_nopipelining:1;
c07d7eb3ca9754367697c98f5e66a3982a45d142Timo Sirainen bool proxy_not_trusted:1;
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainen bool auth_waiting:1;
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainen bool notified_auth_ready:1;
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainen bool notified_disconnect:1;
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainen /* ... */
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainen};
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainen
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainenunion login_client_module_context {
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainen struct client_vfuncs super;
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainen struct login_module_register *reg;
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainen};
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainen
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainenstruct login_client_hooks {
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainen void (*client_allocated)(struct client *client);
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainen};
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainen
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainenextern struct client *clients;
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainen
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainentypedef void login_client_allocated_func_t(struct client *client);
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainen
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainenvoid login_client_hooks_add(struct module *module,
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainen const struct login_client_hooks *hooks);
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainenvoid login_client_hooks_remove(const struct login_client_hooks *hooks);
c07d7eb3ca9754367697c98f5e66a3982a45d142Timo Sirainen
c07d7eb3ca9754367697c98f5e66a3982a45d142Timo Sirainenstruct client *
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainenclient_create(int fd, bool ssl, pool_t pool,
4da8c6cdefabd31262318c32da3c13de1d9ea953Timo Sirainen const struct master_service_connection *conn,
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainen const struct login_settings *set,
002179a890bf4f1942cad6463787719eaa9fd6c0Timo Sirainen const struct master_service_ssl_settings *ssl_set,
002179a890bf4f1942cad6463787719eaa9fd6c0Timo Sirainen void **other_sets);
002179a890bf4f1942cad6463787719eaa9fd6c0Timo Sirainenvoid client_destroy(struct client *client, const char *reason);
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainenvoid client_destroy_success(struct client *client, const char *reason);
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainenvoid client_destroy_internal_failure(struct client *client);
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainen
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainenvoid client_ref(struct client *client);
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainenbool client_unref(struct client **client) ATTR_NOWARN_UNUSED_RESULT;
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainen
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainenvoid client_cmd_starttls(struct client *client);
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainen
f3e17726502b6cf1912f30aae7e283b5d31ea69cTimo Sirainenunsigned int clients_get_count(void) ATTR_PURE;
c07d7eb3ca9754367697c98f5e66a3982a45d142Timo Sirainen
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainenvoid client_set_title(struct client *client);
f3e17726502b6cf1912f30aae7e283b5d31ea69cTimo Sirainenvoid client_log(struct client *client, const char *msg);
f3e17726502b6cf1912f30aae7e283b5d31ea69cTimo Sirainenvoid client_log_err(struct client *client, const char *msg);
c07d7eb3ca9754367697c98f5e66a3982a45d142Timo Sirainenvoid client_log_warn(struct client *client, const char *msg);
f3e17726502b6cf1912f30aae7e283b5d31ea69cTimo Sirainenconst char *client_get_extra_disconnect_reason(struct client *client);
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainen
002179a890bf4f1942cad6463787719eaa9fd6c0Timo Sirainenvoid client_auth_respond(struct client *client, const char *response);
002179a890bf4f1942cad6463787719eaa9fd6c0Timo Sirainenvoid client_auth_abort(struct client *client);
002179a890bf4f1942cad6463787719eaa9fd6c0Timo Sirainenbool client_is_tls_enabled(struct client *client);
002179a890bf4f1942cad6463787719eaa9fd6c0Timo Sirainenvoid client_auth_fail(struct client *client, const char *text);
002179a890bf4f1942cad6463787719eaa9fd6c0Timo Sirainenconst char *client_get_session_id(struct client *client);
002179a890bf4f1942cad6463787719eaa9fd6c0Timo Sirainen
002179a890bf4f1942cad6463787719eaa9fd6c0Timo Sirainenbool client_read(struct client *client);
002179a890bf4f1942cad6463787719eaa9fd6c0Timo Sirainenvoid client_input(struct client *client);
002179a890bf4f1942cad6463787719eaa9fd6c0Timo Sirainen
002179a890bf4f1942cad6463787719eaa9fd6c0Timo Sirainenvoid client_notify_auth_ready(struct client *client);
e30b9e07f9657c35ca09ac36d57d60cbe2ebbc66Timo Sirainenvoid client_notify_status(struct client *client, bool bad, const char *text);
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainenvoid client_notify_disconnect(struct client *client,
002179a890bf4f1942cad6463787719eaa9fd6c0Timo Sirainen enum client_disconnect_reason reason,
002179a890bf4f1942cad6463787719eaa9fd6c0Timo Sirainen const char *text);
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainen
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainenvoid client_send_raw_data(struct client *client, const void *data, size_t size);
002179a890bf4f1942cad6463787719eaa9fd6c0Timo Sirainenvoid client_send_raw(struct client *client, const char *data);
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainen
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainenvoid client_set_auth_waiting(struct client *client);
002179a890bf4f1942cad6463787719eaa9fd6c0Timo Sirainenvoid client_auth_send_challenge(struct client *client, const char *data);
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainenvoid client_auth_parse_response(struct client *client);
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainenint client_auth_begin(struct client *client, const char *mech_name,
e438c85a6b0f77889e25913bbbba808d6078282dStephan Bosch const char *init_resp);
e438c85a6b0f77889e25913bbbba808d6078282dStephan Boschbool client_check_plaintext_auth(struct client *client, bool pass_sent);
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainenint client_auth_read_line(struct client *client);
4c261fb48e6e36570a0841aa51ca483024d6a0a6Timo Sirainen
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainenvoid client_proxy_finish_destroy_client(struct client *client);
4da8c6cdefabd31262318c32da3c13de1d9ea953Timo Sirainenvoid client_proxy_log_failure(struct client *client, const char *line);
4da8c6cdefabd31262318c32da3c13de1d9ea953Timo Sirainenvoid client_proxy_failed(struct client *client, bool send_line);
4da8c6cdefabd31262318c32da3c13de1d9ea953Timo Sirainenconst char *client_proxy_get_state(struct client *client);
542e28b384a6b26695f3e8de38fd5727d06f3333Timo Sirainen
542e28b384a6b26695f3e8de38fd5727d06f3333Timo Sirainenvoid clients_notify_auth_connected(void);
c93aca832ee532010ead91b85fa9f614132e1be2Stephan Boschvoid client_destroy_oldest(void);
c93aca832ee532010ead91b85fa9f614132e1be2Stephan Boschvoid clients_destroy_all(void);
c93aca832ee532010ead91b85fa9f614132e1be2Stephan Boschvoid clients_destroy_all_reason(const char *reason);
c93aca832ee532010ead91b85fa9f614132e1be2Stephan Bosch
c93aca832ee532010ead91b85fa9f614132e1be2Stephan Boschvoid client_common_init(void);
542e28b384a6b26695f3e8de38fd5727d06f3333Timo Sirainenvoid client_common_deinit(void);
542e28b384a6b26695f3e8de38fd5727d06f3333Timo Sirainen
542e28b384a6b26695f3e8de38fd5727d06f3333Timo Sirainen#endif
542e28b384a6b26695f3e8de38fd5727d06f3333Timo Sirainen