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