bcb4e51a409d94ae670de96afb8483a4f7855294Stephan Bosch/* Copyright (c) 2003-2018 Dovecot authors, see the included COPYING file */
9137c55411aa39d41c1e705ddc34d5bd26c65021Timo Sirainenstatic void auth_server_send_new_request(struct auth_server_connection *conn,
38505846b6d083e19f0a7d1373761bdda5d9a5a9Timo Sirainen if ((info->flags & AUTH_REQUEST_FLAG_SUPPORT_FINAL_RESP) != 0)
ff2f20bbc039ad8e362ead199366e21bc41f18edAki Tuomi if ((info->flags & AUTH_REQUEST_FLAG_SECURED) != 0) {
ff2f20bbc039ad8e362ead199366e21bc41f18edAki Tuomi if ((info->flags & AUTH_REQUEST_FLAG_TRANSPORT_SECURITY_TLS) != 0)
ff2f20bbc039ad8e362ead199366e21bc41f18edAki Tuomi i_assert((info->flags & AUTH_REQUEST_FLAG_TRANSPORT_SECURITY_TLS) == 0);
d8702d15ee7721ed1fcfc8f00a589970bd6b3598Timo Sirainen if ((info->flags & AUTH_REQUEST_FLAG_NO_PENALTY) != 0)
9137c55411aa39d41c1e705ddc34d5bd26c65021Timo Sirainen if ((info->flags & AUTH_REQUEST_FLAG_VALID_CLIENT_CERT) != 0)
2087543679f0b35a8f70e1277b234e66ffdf96edTimo Sirainen if ((info->flags & AUTH_REQUEST_FLAG_DEBUG) != 0)
d03a871a77f8ec36f48f5fea98d810e51b186fdbTimo Sirainen str_append_tabescaped(str, info->cert_username);
9137c55411aa39d41c1e705ddc34d5bd26c65021Timo Sirainen str_printfa(str, "\tlip=%s", net_ip2addr(&info->local_ip));
9137c55411aa39d41c1e705ddc34d5bd26c65021Timo Sirainen str_printfa(str, "\trip=%s", net_ip2addr(&info->remote_ip));
9137c55411aa39d41c1e705ddc34d5bd26c65021Timo Sirainen str_printfa(str, "\tlport=%u", info->local_port);
9137c55411aa39d41c1e705ddc34d5bd26c65021Timo Sirainen str_printfa(str, "\trport=%u", info->remote_port);
325d17cdbb7a338f7c413788f5e8e42d2e80a7f8Timo Sirainen /* send the real_* variants only when they differ from the unreal
325d17cdbb7a338f7c413788f5e8e42d2e80a7f8Timo Sirainen !net_ip_compare(&info->real_local_ip, &info->local_ip)) {
325d17cdbb7a338f7c413788f5e8e42d2e80a7f8Timo Sirainen !net_ip_compare(&info->real_remote_ip, &info->remote_ip)) {
325d17cdbb7a338f7c413788f5e8e42d2e80a7f8Timo Sirainen str_printfa(str, "\treal_lport=%u", info->real_local_port);
325d17cdbb7a338f7c413788f5e8e42d2e80a7f8Timo Sirainen str_printfa(str, "\treal_rport=%u", info->real_remote_port);
8c79de417ae66b4e54daeb9d998af2ab301151b4Aki Tuomi if (info->ssl_cipher_bits != 0 && info->ssl_cipher != NULL) {
8c79de417ae66b4e54daeb9d998af2ab301151b4Aki Tuomi str_printfa(str, "\tssl_cipher_bits=%u", info->ssl_cipher_bits);
d03a871a77f8ec36f48f5fea98d810e51b186fdbTimo Sirainen str_append_tabescaped(str, info->initial_resp_base64);
9137c55411aa39d41c1e705ddc34d5bd26c65021Timo Sirainen if (o_stream_send(conn->output, str_data(str), str_len(str)) < 0)
9137c55411aa39d41c1e705ddc34d5bd26c65021Timo Sirainen i_error("Error sending request to auth server: %m");
9137c55411aa39d41c1e705ddc34d5bd26c65021Timo Sirainenauth_client_request_new(struct auth_client *client,
9137c55411aa39d41c1e705ddc34d5bd26c65021Timo Sirainen auth_request_callback_t *callback, void *context)
9137c55411aa39d41c1e705ddc34d5bd26c65021Timo Sirainen pool = pool_alloconly_create("auth client request", 512);
9137c55411aa39d41c1e705ddc34d5bd26c65021Timo Sirainen request = p_new(pool, struct auth_client_request, 1);
9137c55411aa39d41c1e705ddc34d5bd26c65021Timo Sirainen auth_server_connection_add_request(request->conn, request);
6215a7ed04836eb66776e92b8686eff09b39a93fTimo Sirainen auth_server_send_new_request(request->conn, request, request_info);
9137c55411aa39d41c1e705ddc34d5bd26c65021Timo Sirainenvoid auth_client_request_continue(struct auth_client_request *request,
9137c55411aa39d41c1e705ddc34d5bd26c65021Timo Sirainen prefix = t_strdup_printf("CONT\t%u\t", request->id);
9137c55411aa39d41c1e705ddc34d5bd26c65021Timo Sirainen if (o_stream_sendv(request->conn->output, iov, 3) < 0)
9137c55411aa39d41c1e705ddc34d5bd26c65021Timo Sirainen i_error("Error sending continue request to auth server: %m");
a10ed8c47534b4c6b6bf2711ccfe577e720a47b4Timo Sirainencall_callback(struct auth_client_request *request,
a10ed8c47534b4c6b6bf2711ccfe577e720a47b4Timo Sirainen const char *const *args)
4a0641e1ff10f0b0299fd36baf38057c54268e48Timo Sirainen auth_request_callback_t *callback = request->callback;
4a0641e1ff10f0b0299fd36baf38057c54268e48Timo Sirainen callback(request, status, data_base64, args, request->context);
9137c55411aa39d41c1e705ddc34d5bd26c65021Timo Sirainenvoid auth_client_request_abort(struct auth_client_request **_request)
9137c55411aa39d41c1e705ddc34d5bd26c65021Timo Sirainen struct auth_client_request *request = *_request;
4a0641e1ff10f0b0299fd36baf38057c54268e48Timo Sirainen auth_client_send_cancel(request->conn->client, request->id);
7c849dbc7be089175c1a83a84ee7249ed695810dTimo Sirainen call_callback(request, AUTH_REQUEST_STATUS_ABORT, NULL, NULL);
a9b135760aea6d1790d447d351c56b78889dac22Aki Tuomi /* remove the request */
a9b135760aea6d1790d447d351c56b78889dac22Aki Tuomi auth_server_connection_remove_request(request->conn, request->id);
9137c55411aa39d41c1e705ddc34d5bd26c65021Timo Sirainenunsigned int auth_client_request_get_id(struct auth_client_request *request)
9137c55411aa39d41c1e705ddc34d5bd26c65021Timo Sirainenauth_client_request_get_server_pid(struct auth_client_request *request)
66c3f635f2f33905af527d49b27f95322aa7dfa7Timo Sirainenconst char *auth_client_request_get_cookie(struct auth_client_request *request)
9137c55411aa39d41c1e705ddc34d5bd26c65021Timo Sirainenbool auth_client_request_is_aborted(struct auth_client_request *request)
9ddd3d7d8651985e373a6c48e0ddc76b8a4ef1c7Timo Sirainentime_t auth_client_request_get_create_time(struct auth_client_request *request)
9137c55411aa39d41c1e705ddc34d5bd26c65021Timo Sirainenvoid auth_client_request_server_input(struct auth_client_request *request,
9137c55411aa39d41c1e705ddc34d5bd26c65021Timo Sirainen const char *const *args)
9137c55411aa39d41c1e705ddc34d5bd26c65021Timo Sirainen /* aborted already */
4a0641e1ff10f0b0299fd36baf38057c54268e48Timo Sirainen call_callback(request, status, base64_data, args);
3b8d05391336c0e4d24c8ddcc962f350409ffbd3Timo Sirainenvoid auth_client_send_cancel(struct auth_client *client, unsigned int id)
3b8d05391336c0e4d24c8ddcc962f350409ffbd3Timo Sirainen const char *str = t_strdup_printf("CANCEL\t%u\n", id);
3b8d05391336c0e4d24c8ddcc962f350409ffbd3Timo Sirainen if (o_stream_send_str(client->conn->output, str) < 0)
3b8d05391336c0e4d24c8ddcc962f350409ffbd3Timo Sirainen i_error("Error sending request to auth server: %m");