bcb4e51a409d94ae670de96afb8483a4f7855294Stephan Bosch/* Copyright (c) 2005-2018 Dovecot authors, see the included COPYING file */
6bee43694f513ae65566f09a39e1f34a64ef7a20Timo Sirainen#define MASTER_AUTH_REQUEST_TIMEOUT_MSECS (MASTER_LOGIN_TIMEOUT_SECS/2*1000)
a75d470c9223a75801418fcdda258885c36317e0Timo Sirainen HASH_TABLE(void *, struct master_auth_connection *) connections;
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainenmaster_auth_init(struct master_service *service, const char *path)
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainen pool = pool_alloconly_create("master auth", 1024);
678d0463849ba777106eb7875f27db07a5d8e3dfTimo Sirainen hash_table_create_direct(&auth->connections, pool, 0);
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainenmaster_auth_connection_deinit(struct master_auth_connection **_conn)
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainenvoid master_auth_deinit(struct master_auth **_auth)
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainen iter = hash_table_iterate_init(auth->connections);
a75d470c9223a75801418fcdda258885c36317e0Timo Sirainen while (hash_table_iterate(iter, auth->connections, &key, &conn)) {
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainenstatic void master_auth_connection_input(struct master_auth_connection *conn)
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainen ret = read(conn->fd, conn->buf + conn->buf_pos,
f9ee758af881bcecc3f47d45e62cd110673bb92cTimo Sirainen i_error("read(%s) failed: Remote closed connection "
086dacad037a033f783be55842918ba40bbf4ed4Timo Sirainen "(destination service { process_limit } reached?)",
d176f84ce5ca2073f4dfbafb457b9c74f6bf0d76Timo Sirainen /* reply is now read */
6bee43694f513ae65566f09a39e1f34a64ef7a20Timo Sirainen i_error("master(%s): Received reply with unknown tag %u",
892b4c153ad432f5e7e6ce3f84c0f7a9657d0158Timo Sirainen /* request aborted */
6bee43694f513ae65566f09a39e1f34a64ef7a20Timo Sirainenstatic void master_auth_connection_timeout(struct master_auth_connection *conn)
6bee43694f513ae65566f09a39e1f34a64ef7a20Timo Sirainen i_error("master(%s): Auth request timed out (received %u/%u bytes)",
2d8e25bef14245b078868a64396da025f547ad27Timo Sirainenvoid master_auth_request_full(struct master_auth *auth,
2d8e25bef14245b078868a64396da025f547ad27Timo Sirainen const struct master_auth_request_params *params,
2d8e25bef14245b078868a64396da025f547ad27Timo Sirainen master_auth_callback_t *callback, void *context,
2d8e25bef14245b078868a64396da025f547ad27Timo Sirainen unsigned int *tag_r)
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainen conn = i_new(struct master_auth_connection, 1);
9498baa8f374be5b878c0571d07e8ad060a1fdecTimo Sirainen i_strdup(params->socket_path) : i_strdup(auth->default_path);
c147bff818798a979d93537f72f5c1f68f5d5ba8Aki Tuomi buf = t_buffer_create(sizeof(req) + req.data_size);
2d8e25bef14245b078868a64396da025f547ad27Timo Sirainen buffer_append(buf, params->data, req.data_size);
9498baa8f374be5b878c0571d07e8ad060a1fdecTimo Sirainen conn->fd = net_connect_unix_with_retries(conn->path,
b52230a2649019208b13dcbc0469eecde80f76d2Timo Sirainen " - http://wiki2.dovecot.org/SocketUnavailable");
2d8e25bef14245b078868a64396da025f547ad27Timo Sirainen ret = fd_send(conn->fd, params->client_fd, buf->data, buf->used);
9498baa8f374be5b878c0571d07e8ad060a1fdecTimo Sirainen i_error("fd_send(%s, %d) failed: %m", conn->path,
6bee43694f513ae65566f09a39e1f34a64ef7a20Timo Sirainen i_error("fd_send(%s) sent only %d of %d bytes",
6bee43694f513ae65566f09a39e1f34a64ef7a20Timo Sirainen conn->to = timeout_add(MASTER_AUTH_REQUEST_TIMEOUT_MSECS,
fd05c47210cad1f6d8effbda5cba7f7d938ca9a0Timo Sirainen i_assert(hash_table_lookup(auth->connections, POINTER_CAST(req.tag)) == NULL);
a75d470c9223a75801418fcdda258885c36317e0Timo Sirainen hash_table_insert(auth->connections, POINTER_CAST(req.tag), conn);
2d8e25bef14245b078868a64396da025f547ad27Timo Sirainenvoid master_auth_request(struct master_auth *auth, int fd,
2d8e25bef14245b078868a64396da025f547ad27Timo Sirainen const unsigned char *data,
2d8e25bef14245b078868a64396da025f547ad27Timo Sirainen master_auth_request_full(auth, ¶ms, callback, context, tag_r);
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainenvoid master_auth_request_abort(struct master_auth *auth, unsigned int tag)
a75d470c9223a75801418fcdda258885c36317e0Timo Sirainen conn = hash_table_lookup(auth->connections, POINTER_CAST(tag));
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainen i_panic("master_auth_request_abort(): tag %u not found", tag);