client-common.h revision b84eff65e25ae86dfd6f798386577209b94838c6
2e37d45867d081db150ab78dad303b9077aea24fTimo Sirainen#ifndef CLIENT_COMMON_H
ecc81625167ed96c04c02aa190a1ea5baa65b474Timo Sirainen#define CLIENT_COMMON_H
ecc81625167ed96c04c02aa190a1ea5baa65b474Timo Sirainen
07e4875d250e7a7157cd99132aafc773cf3cdf83Timo Sirainenstruct module;
e0c3d5460d1cc0c440cb7723c8c2eef8d0afe9b9Timo Sirainen
0536ccb51d41e3078c3a9fa33e509fb4b2420f95Timo Sirainen#include "net.h"
ecc81625167ed96c04c02aa190a1ea5baa65b474Timo Sirainen#include "login-proxy.h"
8cb72c59d5ea4e9e5f638d7ec840bb853f5a188eTimo Sirainen#include "sasl-server.h"
8cb72c59d5ea4e9e5f638d7ec840bb853f5a188eTimo Sirainen#include "master-login.h" /* for LOGIN_MAX_SESSION_ID_LEN */
8cb72c59d5ea4e9e5f638d7ec840bb853f5a188eTimo Sirainen
8cb72c59d5ea4e9e5f638d7ec840bb853f5a188eTimo Sirainen#define LOGIN_MAX_SESSION_ID_LEN 64
8cb72c59d5ea4e9e5f638d7ec840bb853f5a188eTimo Sirainen#define LOGIN_MAX_MASTER_PREFIX_LEN 128
8cb72c59d5ea4e9e5f638d7ec840bb853f5a188eTimo Sirainen#define LOGIN_MAX_CLIENT_ID_LEN 256
8cb72c59d5ea4e9e5f638d7ec840bb853f5a188eTimo Sirainen
8cb72c59d5ea4e9e5f638d7ec840bb853f5a188eTimo Sirainen/* max. size of input buffer. this means:
8cb72c59d5ea4e9e5f638d7ec840bb853f5a188eTimo Sirainen
8cb72c59d5ea4e9e5f638d7ec840bb853f5a188eTimo Sirainen IMAP: Max. length of command's all parameters. SASL-IR is read into
8cb72c59d5ea4e9e5f638d7ec840bb853f5a188eTimo Sirainen a separate larger buffer.
8cb72c59d5ea4e9e5f638d7ec840bb853f5a188eTimo Sirainen POP3: Max. length of a command line (spec says 512 would be enough)
8cb72c59d5ea4e9e5f638d7ec840bb853f5a188eTimo Sirainen*/
8cb72c59d5ea4e9e5f638d7ec840bb853f5a188eTimo Sirainen#define LOGIN_MAX_INBUF_SIZE \
8cb72c59d5ea4e9e5f638d7ec840bb853f5a188eTimo Sirainen (MASTER_AUTH_MAX_DATA_SIZE - LOGIN_MAX_MASTER_PREFIX_LEN - \
8cb72c59d5ea4e9e5f638d7ec840bb853f5a188eTimo Sirainen LOGIN_MAX_SESSION_ID_LEN)
cd56a23e21f1df3f79648cf07e2f4385e2fadebbTimo Sirainen/* max. size of output buffer. if it gets full, the client is disconnected.
cd56a23e21f1df3f79648cf07e2f4385e2fadebbTimo Sirainen SASL authentication gives the largest output. */
cd56a23e21f1df3f79648cf07e2f4385e2fadebbTimo Sirainen#define LOGIN_MAX_OUTBUF_SIZE 4096
cd56a23e21f1df3f79648cf07e2f4385e2fadebbTimo Sirainen
cd56a23e21f1df3f79648cf07e2f4385e2fadebbTimo Sirainen/* Max. length of SASL authentication buffer. */
cd56a23e21f1df3f79648cf07e2f4385e2fadebbTimo Sirainen#define LOGIN_MAX_AUTH_BUF_SIZE 8192
c0435c854a0e7246373b9752d163095cc4fbe985Timo Sirainen
ecc81625167ed96c04c02aa190a1ea5baa65b474Timo Sirainen/* Disconnect client after this many milliseconds if it hasn't managed
252db51b6c0a605163326b3ea5d09e9936ca3b29Timo Sirainen to log in yet. */
ecc81625167ed96c04c02aa190a1ea5baa65b474Timo Sirainen#define CLIENT_LOGIN_TIMEOUT_MSECS (MASTER_LOGIN_TIMEOUT_SECS*1000)
ecc81625167ed96c04c02aa190a1ea5baa65b474Timo Sirainen
d5cebe7f98e63d4e2822863ef2faa4971e8b3a5dTimo Sirainen#define AUTH_SERVER_WAITING_MSG \
ecc81625167ed96c04c02aa190a1ea5baa65b474Timo Sirainen "Waiting for authentication process to respond.."
252db51b6c0a605163326b3ea5d09e9936ca3b29Timo Sirainen#define AUTH_MASTER_WAITING_MSG \
e0c3d5460d1cc0c440cb7723c8c2eef8d0afe9b9Timo Sirainen "Waiting for authentication master process to respond.."
e0c3d5460d1cc0c440cb7723c8c2eef8d0afe9b9Timo Sirainen
e0c3d5460d1cc0c440cb7723c8c2eef8d0afe9b9Timo Sirainenstruct master_service_connection;
d5cebe7f98e63d4e2822863ef2faa4971e8b3a5dTimo Sirainen
e0c3d5460d1cc0c440cb7723c8c2eef8d0afe9b9Timo Sirainenenum client_disconnect_reason {
252db51b6c0a605163326b3ea5d09e9936ca3b29Timo Sirainen CLIENT_DISCONNECT_TIMEOUT,
d5cebe7f98e63d4e2822863ef2faa4971e8b3a5dTimo Sirainen CLIENT_DISCONNECT_SYSTEM_SHUTDOWN,
ecc81625167ed96c04c02aa190a1ea5baa65b474Timo Sirainen CLIENT_DISCONNECT_RESOURCE_CONSTRAINT,
ecc81625167ed96c04c02aa190a1ea5baa65b474Timo Sirainen CLIENT_DISCONNECT_INTERNAL_ERROR
5ac0b0bf32898c63da086ae169674ecac151a31eTimo Sirainen};
5ac0b0bf32898c63da086ae169674ecac151a31eTimo Sirainen
5ac0b0bf32898c63da086ae169674ecac151a31eTimo Sirainenenum client_auth_fail_code {
5ac0b0bf32898c63da086ae169674ecac151a31eTimo Sirainen CLIENT_AUTH_FAIL_CODE_NONE = 0,
5ac0b0bf32898c63da086ae169674ecac151a31eTimo Sirainen CLIENT_AUTH_FAIL_CODE_AUTHZFAILED,
5ac0b0bf32898c63da086ae169674ecac151a31eTimo Sirainen CLIENT_AUTH_FAIL_CODE_TEMPFAIL,
5ac0b0bf32898c63da086ae169674ecac151a31eTimo Sirainen CLIENT_AUTH_FAIL_CODE_USER_DISABLED,
5ac0b0bf32898c63da086ae169674ecac151a31eTimo Sirainen CLIENT_AUTH_FAIL_CODE_PASS_EXPIRED,
5ac0b0bf32898c63da086ae169674ecac151a31eTimo Sirainen CLIENT_AUTH_FAIL_CODE_INVALID_BASE64,
5ac0b0bf32898c63da086ae169674ecac151a31eTimo Sirainen CLIENT_AUTH_FAIL_CODE_LOGIN_DISABLED,
c28f6aa0b70af4811c9ace9114fe827c2f503455Timo Sirainen CLIENT_AUTH_FAIL_CODE_MECH_INVALID,
c28f6aa0b70af4811c9ace9114fe827c2f503455Timo Sirainen CLIENT_AUTH_FAIL_CODE_MECH_SSL_REQUIRED,
c28f6aa0b70af4811c9ace9114fe827c2f503455Timo Sirainen};
c28f6aa0b70af4811c9ace9114fe827c2f503455Timo Sirainen
c28f6aa0b70af4811c9ace9114fe827c2f503455Timo Sirainenenum client_auth_result {
c28f6aa0b70af4811c9ace9114fe827c2f503455Timo Sirainen CLIENT_AUTH_RESULT_SUCCESS,
c28f6aa0b70af4811c9ace9114fe827c2f503455Timo Sirainen CLIENT_AUTH_RESULT_REFERRAL_SUCCESS,
c28f6aa0b70af4811c9ace9114fe827c2f503455Timo Sirainen CLIENT_AUTH_RESULT_REFERRAL_NOLOGIN,
c0435c854a0e7246373b9752d163095cc4fbe985Timo Sirainen CLIENT_AUTH_RESULT_ABORTED,
ecc81625167ed96c04c02aa190a1ea5baa65b474Timo Sirainen CLIENT_AUTH_RESULT_AUTHFAILED,
252db51b6c0a605163326b3ea5d09e9936ca3b29Timo Sirainen CLIENT_AUTH_RESULT_AUTHFAILED_REASON,
ecc81625167ed96c04c02aa190a1ea5baa65b474Timo Sirainen CLIENT_AUTH_RESULT_AUTHZFAILED,
ecc81625167ed96c04c02aa190a1ea5baa65b474Timo Sirainen CLIENT_AUTH_RESULT_TEMPFAIL,
ecc81625167ed96c04c02aa190a1ea5baa65b474Timo Sirainen CLIENT_AUTH_RESULT_PASS_EXPIRED,
ecc81625167ed96c04c02aa190a1ea5baa65b474Timo Sirainen CLIENT_AUTH_RESULT_SSL_REQUIRED,
c0435c854a0e7246373b9752d163095cc4fbe985Timo Sirainen CLIENT_AUTH_RESULT_INVALID_BASE64,
ecc81625167ed96c04c02aa190a1ea5baa65b474Timo Sirainen CLIENT_AUTH_RESULT_LOGIN_DISABLED,
252db51b6c0a605163326b3ea5d09e9936ca3b29Timo Sirainen CLIENT_AUTH_RESULT_MECH_INVALID,
ecc81625167ed96c04c02aa190a1ea5baa65b474Timo Sirainen CLIENT_AUTH_RESULT_MECH_SSL_REQUIRED
7db932bd4934cd967eeae643300aef5b91caeaeaTimo Sirainen};
7db932bd4934cd967eeae643300aef5b91caeaeaTimo Sirainen
74066569545099304b20e790df7c261883d1746bTimo Sirainenstruct client_auth_reply {
ecc81625167ed96c04c02aa190a1ea5baa65b474Timo Sirainen const char *master_user, *reason;
ecc81625167ed96c04c02aa190a1ea5baa65b474Timo Sirainen enum client_auth_fail_code fail_code;
7662010b03ffe5f2a6ecf4b4eb220d1c65efea76Timo Sirainen
7662010b03ffe5f2a6ecf4b4eb220d1c65efea76Timo Sirainen /* for proxying */
7662010b03ffe5f2a6ecf4b4eb220d1c65efea76Timo Sirainen const char *host, *hostip, *source_ip;
7662010b03ffe5f2a6ecf4b4eb220d1c65efea76Timo Sirainen const char *destuser, *password, *proxy_mech;
7662010b03ffe5f2a6ecf4b4eb220d1c65efea76Timo Sirainen in_port_t port;
c0435c854a0e7246373b9752d163095cc4fbe985Timo Sirainen unsigned int proxy_timeout_msecs;
ecc81625167ed96c04c02aa190a1ea5baa65b474Timo Sirainen unsigned int proxy_refresh_secs;
252db51b6c0a605163326b3ea5d09e9936ca3b29Timo Sirainen enum login_proxy_ssl_flags ssl_flags;
ecc81625167ed96c04c02aa190a1ea5baa65b474Timo Sirainen
ecc81625167ed96c04c02aa190a1ea5baa65b474Timo Sirainen /* all the key=value fields returned by passdb */
0a49b316fc729e5d57268ffa63c7122ac73f994cTimo Sirainen const char *const *all_fields;
0a49b316fc729e5d57268ffa63c7122ac73f994cTimo Sirainen
0a49b316fc729e5d57268ffa63c7122ac73f994cTimo Sirainen bool proxy:1;
0a49b316fc729e5d57268ffa63c7122ac73f994cTimo Sirainen bool proxy_nopipelining:1;
0a49b316fc729e5d57268ffa63c7122ac73f994cTimo Sirainen bool proxy_not_trusted:1;
51e1a1c280ccb461a15827f7987d09cb9708b6e3Timo Sirainen bool nologin:1;
51e1a1c280ccb461a15827f7987d09cb9708b6e3Timo Sirainen};
51e1a1c280ccb461a15827f7987d09cb9708b6e3Timo Sirainen
51e1a1c280ccb461a15827f7987d09cb9708b6e3Timo Sirainenstruct client_vfuncs {
51e1a1c280ccb461a15827f7987d09cb9708b6e3Timo Sirainen struct client *(*alloc)(pool_t pool);
4334b9b032298defd4d3906f5357698ff016ead0Timo Sirainen void (*create)(struct client *client, void **other_sets);
4334b9b032298defd4d3906f5357698ff016ead0Timo Sirainen void (*destroy)(struct client *client);
4334b9b032298defd4d3906f5357698ff016ead0Timo Sirainen void (*notify_auth_ready)(struct client *client);
4334b9b032298defd4d3906f5357698ff016ead0Timo Sirainen void (*notify_disconnect)(struct client *client,
4334b9b032298defd4d3906f5357698ff016ead0Timo Sirainen enum client_disconnect_reason reason,
4334b9b032298defd4d3906f5357698ff016ead0Timo Sirainen const char *text);
4334b9b032298defd4d3906f5357698ff016ead0Timo Sirainen void (*notify_status)(struct client *client,
4334b9b032298defd4d3906f5357698ff016ead0Timo Sirainen bool bad, const char *text);
4334b9b032298defd4d3906f5357698ff016ead0Timo Sirainen void (*notify_starttls)(struct client *client,
4334b9b032298defd4d3906f5357698ff016ead0Timo Sirainen bool success, const char *text);
4334b9b032298defd4d3906f5357698ff016ead0Timo Sirainen void (*starttls)(struct client *client);
c0435c854a0e7246373b9752d163095cc4fbe985Timo Sirainen void (*input)(struct client *client);
ecc81625167ed96c04c02aa190a1ea5baa65b474Timo Sirainen void (*auth_send_challenge)(struct client *client, const char *data);
252db51b6c0a605163326b3ea5d09e9936ca3b29Timo Sirainen void (*auth_parse_response)(struct client *client);
0892446b45c195461bb7be6599f02d97e1e2c9b2Timo Sirainen void (*auth_result)(struct client *client,
c09f9f95db314e7482c95e502e1c56ed6c555797Timo Sirainen enum client_auth_result result,
ecc81625167ed96c04c02aa190a1ea5baa65b474Timo Sirainen const struct client_auth_reply *reply,
c9bf63e9094761767a63ac6b189bcf60bcffdc44Timo Sirainen const char *text);
ecc81625167ed96c04c02aa190a1ea5baa65b474Timo Sirainen void (*proxy_reset)(struct client *client);
ecc81625167ed96c04c02aa190a1ea5baa65b474Timo Sirainen int (*proxy_parse_line)(struct client *client, const char *line);
9e095dd6a77097356aca8216356d4d71ef1bea45Timo Sirainen void (*proxy_error)(struct client *client, const char *text);
c09f9f95db314e7482c95e502e1c56ed6c555797Timo Sirainen const char *(*proxy_get_state)(struct client *client);
c09f9f95db314e7482c95e502e1c56ed6c555797Timo Sirainen void (*send_raw_data)(struct client *client,
4334b9b032298defd4d3906f5357698ff016ead0Timo Sirainen const void *data, size_t size);
4334b9b032298defd4d3906f5357698ff016ead0Timo Sirainen bool (*input_next_cmd)(struct client *client);
4334b9b032298defd4d3906f5357698ff016ead0Timo Sirainen void (*free)(struct client *client);
0892446b45c195461bb7be6599f02d97e1e2c9b2Timo Sirainen};
c09f9f95db314e7482c95e502e1c56ed6c555797Timo Sirainen
0a0cd45a633112a2ae6aad801c1e6afe53ab95deTimo Sirainenstruct client {
0a0cd45a633112a2ae6aad801c1e6afe53ab95deTimo Sirainen struct client *prev, *next;
0a0cd45a633112a2ae6aad801c1e6afe53ab95deTimo Sirainen pool_t pool;
0a0cd45a633112a2ae6aad801c1e6afe53ab95deTimo Sirainen /* this pool gets free'd once proxying starts */
0a0cd45a633112a2ae6aad801c1e6afe53ab95deTimo Sirainen pool_t preproxy_pool;
c09f9f95db314e7482c95e502e1c56ed6c555797Timo Sirainen struct client_vfuncs v;
c09f9f95db314e7482c95e502e1c56ed6c555797Timo Sirainen struct client_vfuncs *vlast;
c09f9f95db314e7482c95e502e1c56ed6c555797Timo Sirainen
c09f9f95db314e7482c95e502e1c56ed6c555797Timo Sirainen time_t created;
c09f9f95db314e7482c95e502e1c56ed6c555797Timo Sirainen int refcount;
c09f9f95db314e7482c95e502e1c56ed6c555797Timo Sirainen
c09f9f95db314e7482c95e502e1c56ed6c555797Timo Sirainen struct ip_addr local_ip;
0a0cd45a633112a2ae6aad801c1e6afe53ab95deTimo Sirainen struct ip_addr ip;
0a0cd45a633112a2ae6aad801c1e6afe53ab95deTimo Sirainen struct ip_addr real_remote_ip, real_local_ip;
0a0cd45a633112a2ae6aad801c1e6afe53ab95deTimo Sirainen in_port_t local_port, remote_port;
0a0cd45a633112a2ae6aad801c1e6afe53ab95deTimo Sirainen in_port_t real_local_port, real_remote_port;
e4c81823af1fc43ca3f2ce9eb4af7fc8f57b13a5Timo Sirainen struct ssl_proxy *ssl_proxy;
e4c81823af1fc43ca3f2ce9eb4af7fc8f57b13a5Timo Sirainen const struct login_settings *set;
2524ef7b34965a1b1895d6140fd8296bf57c78d2Timo Sirainen const struct master_service_ssl_settings *ssl_set;
0892446b45c195461bb7be6599f02d97e1e2c9b2Timo Sirainen const char *session_id, *listener_name, *postlogin_socket_path;
e4c81823af1fc43ca3f2ce9eb4af7fc8f57b13a5Timo Sirainen const char *local_name;
c09f9f95db314e7482c95e502e1c56ed6c555797Timo Sirainen string_t *client_id;
4334b9b032298defd4d3906f5357698ff016ead0Timo Sirainen string_t *forward_fields;
4334b9b032298defd4d3906f5357698ff016ead0Timo Sirainen
c09f9f95db314e7482c95e502e1c56ed6c555797Timo Sirainen int fd;
ecc81625167ed96c04c02aa190a1ea5baa65b474Timo Sirainen struct istream *input;
ecc81625167ed96c04c02aa190a1ea5baa65b474Timo Sirainen struct ostream *output;
61e6367a259e2473f33df42fda8ceeb3b8b48416Timo Sirainen struct io *io;
61e6367a259e2473f33df42fda8ceeb3b8b48416Timo Sirainen struct timeout *to_auth_waiting;
61e6367a259e2473f33df42fda8ceeb3b8b48416Timo Sirainen struct timeout *to_disconnect;
61e6367a259e2473f33df42fda8ceeb3b8b48416Timo Sirainen
61e6367a259e2473f33df42fda8ceeb3b8b48416Timo Sirainen unsigned char *master_data_prefix;
61e6367a259e2473f33df42fda8ceeb3b8b48416Timo Sirainen unsigned int master_data_prefix_len;
61e6367a259e2473f33df42fda8ceeb3b8b48416Timo Sirainen
61e6367a259e2473f33df42fda8ceeb3b8b48416Timo Sirainen struct login_proxy *login_proxy;
61e6367a259e2473f33df42fda8ceeb3b8b48416Timo Sirainen char *proxy_user, *proxy_master_user, *proxy_password;
61e6367a259e2473f33df42fda8ceeb3b8b48416Timo Sirainen const struct dsasl_client_mech *proxy_mech;
61e6367a259e2473f33df42fda8ceeb3b8b48416Timo Sirainen struct dsasl_client *proxy_sasl_client;
61e6367a259e2473f33df42fda8ceeb3b8b48416Timo Sirainen unsigned int proxy_ttl;
61e6367a259e2473f33df42fda8ceeb3b8b48416Timo Sirainen
61e6367a259e2473f33df42fda8ceeb3b8b48416Timo Sirainen char *auth_mech_name;
61e6367a259e2473f33df42fda8ceeb3b8b48416Timo Sirainen struct auth_client_request *auth_request;
61e6367a259e2473f33df42fda8ceeb3b8b48416Timo Sirainen string_t *auth_response;
61e6367a259e2473f33df42fda8ceeb3b8b48416Timo Sirainen time_t auth_first_started, auth_finished;
61e6367a259e2473f33df42fda8ceeb3b8b48416Timo Sirainen const char *sasl_final_resp;
61e6367a259e2473f33df42fda8ceeb3b8b48416Timo Sirainen const char *const *auth_passdb_args;
61e6367a259e2473f33df42fda8ceeb3b8b48416Timo Sirainen
61e6367a259e2473f33df42fda8ceeb3b8b48416Timo Sirainen unsigned int master_auth_id;
61e6367a259e2473f33df42fda8ceeb3b8b48416Timo Sirainen unsigned int master_tag;
61e6367a259e2473f33df42fda8ceeb3b8b48416Timo Sirainen sasl_server_callback_t *sasl_callback;
61e6367a259e2473f33df42fda8ceeb3b8b48416Timo Sirainen
61e6367a259e2473f33df42fda8ceeb3b8b48416Timo Sirainen unsigned int bad_counter;
61e6367a259e2473f33df42fda8ceeb3b8b48416Timo Sirainen unsigned int auth_attempts, auth_successes;
61e6367a259e2473f33df42fda8ceeb3b8b48416Timo Sirainen enum client_auth_fail_code last_auth_fail;
61e6367a259e2473f33df42fda8ceeb3b8b48416Timo Sirainen pid_t mail_pid;
61e6367a259e2473f33df42fda8ceeb3b8b48416Timo Sirainen
61e6367a259e2473f33df42fda8ceeb3b8b48416Timo Sirainen /* Module-specific contexts. */
61e6367a259e2473f33df42fda8ceeb3b8b48416Timo Sirainen ARRAY(union login_client_module_context *) module_contexts;
61e6367a259e2473f33df42fda8ceeb3b8b48416Timo Sirainen
c0435c854a0e7246373b9752d163095cc4fbe985Timo Sirainen char *virtual_user, *virtual_user_orig, *virtual_auth_user;
ecc81625167ed96c04c02aa190a1ea5baa65b474Timo Sirainen /* passdb user_* fields are set here after a successful auth.
252db51b6c0a605163326b3ea5d09e9936ca3b29Timo Sirainen This is a NULL-terminated array where fields are in the same order
ecc81625167ed96c04c02aa190a1ea5baa65b474Timo Sirainen as in global_alt_usernames. If some field doesn't exist, it's "".
ecc81625167ed96c04c02aa190a1ea5baa65b474Timo Sirainen Can also be NULL if there are no user_* fields. */
20344c0e814139e3c365fbb9287478f91512089eTimo Sirainen const char **alt_usernames;
20344c0e814139e3c365fbb9287478f91512089eTimo Sirainen bool destroyed:1;
dd62b77c932d1b518f2a3e4bf80e36542becc256Timo Sirainen bool input_blocked:1;
ecc81625167ed96c04c02aa190a1ea5baa65b474Timo Sirainen bool login_success:1;
ecc81625167ed96c04c02aa190a1ea5baa65b474Timo Sirainen bool starttls:1;
ecc81625167ed96c04c02aa190a1ea5baa65b474Timo Sirainen bool tls:1;
ecc81625167ed96c04c02aa190a1ea5baa65b474Timo Sirainen bool secured:1;
ecc81625167ed96c04c02aa190a1ea5baa65b474Timo Sirainen bool trusted:1;
dd62b77c932d1b518f2a3e4bf80e36542becc256Timo Sirainen bool ssl_servername_settings_read:1;
ecc81625167ed96c04c02aa190a1ea5baa65b474Timo Sirainen bool banner_sent:1;
20344c0e814139e3c365fbb9287478f91512089eTimo Sirainen bool authenticating:1;
ecc81625167ed96c04c02aa190a1ea5baa65b474Timo Sirainen bool auth_try_aborted:1;
ecc81625167ed96c04c02aa190a1ea5baa65b474Timo Sirainen bool auth_initializing:1;
c9bf63e9094761767a63ac6b189bcf60bcffdc44Timo Sirainen bool auth_process_comm_fail:1;
dd62b77c932d1b518f2a3e4bf80e36542becc256Timo Sirainen bool proxy_auth_failed:1;
dd62b77c932d1b518f2a3e4bf80e36542becc256Timo Sirainen bool proxy_nopipelining:1;
c09f9f95db314e7482c95e502e1c56ed6c555797Timo Sirainen bool proxy_not_trusted:1;
602a0434db30d8e3292d1c161a803d96a879a74fTimo Sirainen bool auth_waiting:1;
ecc81625167ed96c04c02aa190a1ea5baa65b474Timo Sirainen bool notified_auth_ready:1;
ecc81625167ed96c04c02aa190a1ea5baa65b474Timo Sirainen bool notified_disconnect:1;
4334b9b032298defd4d3906f5357698ff016ead0Timo Sirainen /* ... */
e3fc1874694a8ddba9552ec23f9952f74f33d1d5Timo Sirainen};
4334b9b032298defd4d3906f5357698ff016ead0Timo Sirainen
e3fc1874694a8ddba9552ec23f9952f74f33d1d5Timo Sirainenunion login_client_module_context {
e3fc1874694a8ddba9552ec23f9952f74f33d1d5Timo Sirainen struct client_vfuncs super;
4334b9b032298defd4d3906f5357698ff016ead0Timo Sirainen struct login_module_register *reg;
4334b9b032298defd4d3906f5357698ff016ead0Timo Sirainen};
4334b9b032298defd4d3906f5357698ff016ead0Timo Sirainen
e3fc1874694a8ddba9552ec23f9952f74f33d1d5Timo Sirainenstruct login_client_hooks {
e3fc1874694a8ddba9552ec23f9952f74f33d1d5Timo Sirainen void (*client_allocated)(struct client *client);
4334b9b032298defd4d3906f5357698ff016ead0Timo Sirainen};
e3fc1874694a8ddba9552ec23f9952f74f33d1d5Timo Sirainen
e3fc1874694a8ddba9552ec23f9952f74f33d1d5Timo Sirainenextern struct client *clients;
c0435c854a0e7246373b9752d163095cc4fbe985Timo Sirainen
ecc81625167ed96c04c02aa190a1ea5baa65b474Timo Sirainentypedef void login_client_allocated_func_t(struct client *client);
252db51b6c0a605163326b3ea5d09e9936ca3b29Timo Sirainen
ecc81625167ed96c04c02aa190a1ea5baa65b474Timo Sirainenvoid login_client_hooks_add(struct module *module,
e3fc1874694a8ddba9552ec23f9952f74f33d1d5Timo Sirainen const struct login_client_hooks *hooks);
4334b9b032298defd4d3906f5357698ff016ead0Timo Sirainenvoid login_client_hooks_remove(const struct login_client_hooks *hooks);
601f5f14c6cde28f0e0c6ca7c5d735315d3d48dfTimo Sirainen
4334b9b032298defd4d3906f5357698ff016ead0Timo Sirainenstruct client *
4334b9b032298defd4d3906f5357698ff016ead0Timo Sirainenclient_create(int fd, bool ssl, pool_t pool,
4334b9b032298defd4d3906f5357698ff016ead0Timo Sirainen const struct master_service_connection *conn,
ecc81625167ed96c04c02aa190a1ea5baa65b474Timo Sirainen const struct login_settings *set,
4334b9b032298defd4d3906f5357698ff016ead0Timo Sirainen const struct master_service_ssl_settings *ssl_set,
4334b9b032298defd4d3906f5357698ff016ead0Timo Sirainen void **other_sets);
4334b9b032298defd4d3906f5357698ff016ead0Timo Sirainenvoid client_destroy(struct client *client, const char *reason);
4334b9b032298defd4d3906f5357698ff016ead0Timo Sirainenvoid client_destroy_success(struct client *client, const char *reason);
602a0434db30d8e3292d1c161a803d96a879a74fTimo Sirainenvoid client_destroy_internal_failure(struct client *client);
602a0434db30d8e3292d1c161a803d96a879a74fTimo Sirainen
602a0434db30d8e3292d1c161a803d96a879a74fTimo Sirainenvoid client_ref(struct client *client);
602a0434db30d8e3292d1c161a803d96a879a74fTimo Sirainenbool client_unref(struct client **client) ATTR_NOWARN_UNUSED_RESULT;
252db51b6c0a605163326b3ea5d09e9936ca3b29Timo Sirainen
602a0434db30d8e3292d1c161a803d96a879a74fTimo Sirainenvoid client_cmd_starttls(struct client *client);
c9bf63e9094761767a63ac6b189bcf60bcffdc44Timo Sirainen
602a0434db30d8e3292d1c161a803d96a879a74fTimo Sirainenunsigned int clients_get_count(void) ATTR_PURE;
602a0434db30d8e3292d1c161a803d96a879a74fTimo Sirainen
602a0434db30d8e3292d1c161a803d96a879a74fTimo Sirainenvoid client_add_forward_field(struct client *client, const char *key,
602a0434db30d8e3292d1c161a803d96a879a74fTimo Sirainen const char *value);
4334b9b032298defd4d3906f5357698ff016ead0Timo Sirainenvoid client_set_title(struct client *client);
ecc81625167ed96c04c02aa190a1ea5baa65b474Timo Sirainenvoid client_log(struct client *client, const char *msg);
ecc81625167ed96c04c02aa190a1ea5baa65b474Timo Sirainenvoid client_log_err(struct client *client, const char *msg);
07e4875d250e7a7157cd99132aafc773cf3cdf83Timo Sirainenvoid client_log_warn(struct client *client, const char *msg);
dd62b77c932d1b518f2a3e4bf80e36542becc256Timo Sirainenconst char *client_get_extra_disconnect_reason(struct client *client);
252db51b6c0a605163326b3ea5d09e9936ca3b29Timo Sirainen
dd62b77c932d1b518f2a3e4bf80e36542becc256Timo Sirainenvoid client_auth_respond(struct client *client, const char *response);
c9bf63e9094761767a63ac6b189bcf60bcffdc44Timo Sirainenvoid client_auth_abort(struct client *client);
c9bf63e9094761767a63ac6b189bcf60bcffdc44Timo Sirainenbool client_is_tls_enabled(struct client *client);
c9bf63e9094761767a63ac6b189bcf60bcffdc44Timo Sirainenvoid client_auth_fail(struct client *client, const char *text);
4334b9b032298defd4d3906f5357698ff016ead0Timo Sirainenconst char *client_get_session_id(struct client *client);
07e4875d250e7a7157cd99132aafc773cf3cdf83Timo Sirainen
4334b9b032298defd4d3906f5357698ff016ead0Timo Sirainenbool client_read(struct client *client);
4334b9b032298defd4d3906f5357698ff016ead0Timo Sirainenvoid client_input(struct client *client);
07e4875d250e7a7157cd99132aafc773cf3cdf83Timo Sirainen
07e4875d250e7a7157cd99132aafc773cf3cdf83Timo Sirainenvoid client_notify_auth_ready(struct client *client);
6ef7e31619edfaa17ed044b45861d106a86191efTimo Sirainenvoid client_notify_status(struct client *client, bool bad, const char *text);
07e4875d250e7a7157cd99132aafc773cf3cdf83Timo Sirainenvoid client_notify_disconnect(struct client *client,
252db51b6c0a605163326b3ea5d09e9936ca3b29Timo Sirainen enum client_disconnect_reason reason,
07e4875d250e7a7157cd99132aafc773cf3cdf83Timo Sirainen const char *text);
c9bf63e9094761767a63ac6b189bcf60bcffdc44Timo Sirainen
548e394330621952db0f03dd667b70184c4a37b6Timo Sirainenvoid client_send_raw_data(struct client *client, const void *data, size_t size);
548e394330621952db0f03dd667b70184c4a37b6Timo Sirainenvoid client_send_raw(struct client *client, const char *data);
7d207b1e77a7b5e3fda640e353acfc86d261fedfTimo Sirainenvoid client_common_send_raw_data(struct client *client,
dd62b77c932d1b518f2a3e4bf80e36542becc256Timo Sirainen const void *data, size_t size);
dd62b77c932d1b518f2a3e4bf80e36542becc256Timo Sirainenvoid client_common_default_free(struct client *client);
4b9f99761df5014c659cd87fddaf6854af428cfcTimo Sirainen
4b9f99761df5014c659cd87fddaf6854af428cfcTimo Sirainenvoid client_set_auth_waiting(struct client *client);
4b9f99761df5014c659cd87fddaf6854af428cfcTimo Sirainenvoid client_auth_send_challenge(struct client *client, const char *data);
4b9f99761df5014c659cd87fddaf6854af428cfcTimo Sirainenvoid client_auth_parse_response(struct client *client);
4b9f99761df5014c659cd87fddaf6854af428cfcTimo Sirainenint client_auth_begin(struct client *client, const char *mech_name,
4b9f99761df5014c659cd87fddaf6854af428cfcTimo Sirainen const char *init_resp);
4b9f99761df5014c659cd87fddaf6854af428cfcTimo Sirainenbool client_check_plaintext_auth(struct client *client, bool pass_sent);
4b9f99761df5014c659cd87fddaf6854af428cfcTimo Sirainenint client_auth_read_line(struct client *client);
4b9f99761df5014c659cd87fddaf6854af428cfcTimo Sirainen
4b9f99761df5014c659cd87fddaf6854af428cfcTimo Sirainenvoid client_proxy_finish_destroy_client(struct client *client);
68a4946b12583b88fa802e52ebee45cd96056772Timo Sirainenvoid client_proxy_log_failure(struct client *client, const char *line);
7e1f68ad71d3485f1882142837b01f7a98ca8467Timo Sirainenvoid client_proxy_failed(struct client *client, bool send_line);
68a4946b12583b88fa802e52ebee45cd96056772Timo Sirainenconst char *client_proxy_get_state(struct client *client);
7e1f68ad71d3485f1882142837b01f7a98ca8467Timo Sirainen
7e1f68ad71d3485f1882142837b01f7a98ca8467Timo Sirainenvoid clients_notify_auth_connected(void);
7e1f68ad71d3485f1882142837b01f7a98ca8467Timo Sirainenvoid client_destroy_oldest(void);
7e1f68ad71d3485f1882142837b01f7a98ca8467Timo Sirainenvoid clients_destroy_all(void);
a3c197999dfe2b0c8ea38cb77cfa5e95026005c0Timo Sirainenvoid clients_destroy_all_reason(const char *reason);
a3c197999dfe2b0c8ea38cb77cfa5e95026005c0Timo Sirainen
a3c197999dfe2b0c8ea38cb77cfa5e95026005c0Timo Sirainenvoid client_common_init(void);
a3c197999dfe2b0c8ea38cb77cfa5e95026005c0Timo Sirainenvoid client_common_deinit(void);
a3c197999dfe2b0c8ea38cb77cfa5e95026005c0Timo Sirainen
a3c197999dfe2b0c8ea38cb77cfa5e95026005c0Timo Sirainen#endif
a3c197999dfe2b0c8ea38cb77cfa5e95026005c0Timo Sirainen