auth-server-connection.c revision 63b70dd3e4b4d68a02b1bf7d78e92076210e3e1a
bcb4e51a409d94ae670de96afb8483a4f7855294Stephan Bosch/* Copyright (c) 2003-2010 Dovecot authors, see the included COPYING file */
43a66a0b16299bd4f7615acd85e98bd3832c54d5Timo Sirainen#define AUTH_SERVER_CONN_MAX_LINE_LENGTH AUTH_CLIENT_MAX_LINE_LENGTH
7bd72e4deca3cbf757dd1ea298486d9f3bc24226Timo Sirainenauth_server_connection_reconnect(struct auth_server_connection *conn);
43a66a0b16299bd4f7615acd85e98bd3832c54d5Timo Sirainenauth_server_input_mech(struct auth_server_connection *conn,
43a66a0b16299bd4f7615acd85e98bd3832c54d5Timo Sirainen const char *const *args)
5c99eaa4e3e07ee065580d163240b4ce95b66befTimo Sirainen i_error("BUG: Authentication server already sent handshake");
5c99eaa4e3e07ee065580d163240b4ce95b66befTimo Sirainen i_error("BUG: Authentication server sent broken MECH line");
43a66a0b16299bd4f7615acd85e98bd3832c54d5Timo Sirainen mech_desc.name = p_strdup(conn->pool, args[0]);
43a66a0b16299bd4f7615acd85e98bd3832c54d5Timo Sirainen else if (strcmp(*args, "forward-secrecy") == 0)
2521482f3f897c83f7d5a2f9e17fe99fa4ba2cbeTimo Sirainen array_append(&conn->available_auth_mechs, &mech_desc, 1);
9261dbf0675204898c6557591c7aa376e23a52b2Timo Sirainenauth_server_input_spid(struct auth_server_connection *conn,
9261dbf0675204898c6557591c7aa376e23a52b2Timo Sirainen const char *const *args)
70afae43cc78ea6ecca83f6c587072c442a15ec1Timo Sirainen i_error("BUG: Authentication server already sent handshake");
12aad74464367f7e8be11eafe1af985bf7b1adecTimo Sirainen conn->server_pid = (unsigned int)strtoul(args[0], NULL, 10);
70afae43cc78ea6ecca83f6c587072c442a15ec1Timo Sirainenauth_server_input_cuid(struct auth_server_connection *conn,
70afae43cc78ea6ecca83f6c587072c442a15ec1Timo Sirainen const char *const *args)
12aad74464367f7e8be11eafe1af985bf7b1adecTimo Sirainen i_error("BUG: Authentication server already sent handshake");
2521482f3f897c83f7d5a2f9e17fe99fa4ba2cbeTimo Sirainen i_error("BUG: Authentication server sent broken CUID line");
137ea7ca34005345aa2304a940149b7f3774d727Timo Sirainen conn->connect_uid = (unsigned int)strtoul(args[0], NULL, 10);
70afae43cc78ea6ecca83f6c587072c442a15ec1Timo Sirainenauth_server_input_cookie(struct auth_server_connection *conn,
70afae43cc78ea6ecca83f6c587072c442a15ec1Timo Sirainen const char *const *args)
12aad74464367f7e8be11eafe1af985bf7b1adecTimo Sirainen i_error("BUG: Authentication server already sent cookie");
12aad74464367f7e8be11eafe1af985bf7b1adecTimo Sirainenstatic int auth_server_input_done(struct auth_server_connection *conn)
12aad74464367f7e8be11eafe1af985bf7b1adecTimo Sirainen if (array_count(&conn->available_auth_mechs) == 0) {
9ed2951bd0bb1878a27437d7c00611b2baadd614Timo Sirainen i_error("BUG: Authentication server returned no mechanisms");
9ed2951bd0bb1878a27437d7c00611b2baadd614Timo Sirainen i_error("BUG: Authentication server didn't send a cookie");
9ed2951bd0bb1878a27437d7c00611b2baadd614Timo Sirainen if (conn->client->connect_notify_callback != NULL) {
9ed2951bd0bb1878a27437d7c00611b2baadd614Timo Sirainen conn->client->connect_notify_callback(conn->client, TRUE,
3cf67672fdc87583cb23ce088c95bb5dee60e74dTimo Sirainenauth_server_lookup_request(struct auth_server_connection *conn,
04052d7cacaa866a3f00afb4e104fa46c04c1dd7Timo Sirainen unsigned int id;
966cb0c1aa58578339cea6f79b4a423a851ab074Timo Sirainen i_error("BUG: Authentication server input missing ID");
d5abbb932a0a598f002da39a8b3326643b1b5efcTimo Sirainen request = hash_table_lookup(conn->requests, POINTER_CAST(id));
04052d7cacaa866a3f00afb4e104fa46c04c1dd7Timo Sirainen i_error("BUG: Authentication server sent unknown id %u", id);
04052d7cacaa866a3f00afb4e104fa46c04c1dd7Timo Sirainen if (remove || auth_client_request_is_aborted(request))
04052d7cacaa866a3f00afb4e104fa46c04c1dd7Timo Sirainen hash_table_remove(conn->requests, POINTER_CAST(id));
9ed2951bd0bb1878a27437d7c00611b2baadd614Timo Sirainenauth_server_input_ok(struct auth_server_connection *conn,
e48d89622047bd8bbd0475b881ca9377d592f535Timo Sirainen const char *const *args)
e48d89622047bd8bbd0475b881ca9377d592f535Timo Sirainen if (auth_server_lookup_request(conn, args[0], TRUE, &request) < 0)
04052d7cacaa866a3f00afb4e104fa46c04c1dd7Timo Sirainen auth_client_request_server_input(request, AUTH_REQUEST_STATUS_OK,
08aea01ef9a9d20703e0fcf8618e6195c0037a44Timo Sirainenstatic int auth_server_input_cont(struct auth_server_connection *conn,
f3d506e525a720f214020ca0f989a1966b30edaeTimo Sirainen const char *const *args)
25757faf029c369a8318349dafe952e2358df1d8Timo Sirainen i_error("BUG: Authentication server sent broken CONT line");
9ed2951bd0bb1878a27437d7c00611b2baadd614Timo Sirainen if (auth_server_lookup_request(conn, args[0], FALSE, &request) < 0)
9ed2951bd0bb1878a27437d7c00611b2baadd614Timo Sirainen auth_client_request_server_input(request, AUTH_REQUEST_STATUS_CONTINUE,
9ed2951bd0bb1878a27437d7c00611b2baadd614Timo Sirainenstatic int auth_server_input_fail(struct auth_server_connection *conn,
9ed2951bd0bb1878a27437d7c00611b2baadd614Timo Sirainen const char *const *args)
849969f639a00eab26791db3cb1b66430420c0cdTimo Sirainen if (auth_server_lookup_request(conn, args[0], TRUE, &request) < 0)
9d75363d3fbabc2fbc2d80f06672e3ed8965804aTimo Sirainen auth_client_request_server_input(request, AUTH_REQUEST_STATUS_FAIL,
be5c76fabc7439fd33bc799bc3ab3f570799977bTimo Sirainenauth_server_connection_input_line(struct auth_server_connection *conn,
be5c76fabc7439fd33bc799bc3ab3f570799977bTimo Sirainen const char *const *args;
be5c76fabc7439fd33bc799bc3ab3f570799977bTimo Sirainen return auth_server_input_cont(conn, args + 1);
be5c76fabc7439fd33bc799bc3ab3f570799977bTimo Sirainen return auth_server_input_fail(conn, args + 1);
43a66a0b16299bd4f7615acd85e98bd3832c54d5Timo Sirainen return auth_server_input_mech(conn, args + 1);
43a66a0b16299bd4f7615acd85e98bd3832c54d5Timo Sirainen return auth_server_input_spid(conn, args + 1);
43a66a0b16299bd4f7615acd85e98bd3832c54d5Timo Sirainen return auth_server_input_cuid(conn, args + 1);
51ead2f4c04ee85615d23c453924633b9ed8a4c2Timo Sirainen return auth_server_input_cookie(conn, args + 1);
9698cd24356147d8a5471260062ea7e10e692fdfAki Tuomi i_error("Auth server sent unknown command: %s", args[0]);
9ed2951bd0bb1878a27437d7c00611b2baadd614Timo Sirainenstatic void auth_server_connection_input(struct auth_server_connection *conn)
9698cd24356147d8a5471260062ea7e10e692fdfAki Tuomi /* disconnected */
43a66a0b16299bd4f7615acd85e98bd3832c54d5Timo Sirainen /* buffer full - can't happen unless auth is buggy */
43a66a0b16299bd4f7615acd85e98bd3832c54d5Timo Sirainen i_error("BUG: Auth server sent us more than %d bytes of data",
T_BEGIN {
} T_END;
if (ret < 0) {
struct auth_server_connection *
return conn;
const char *handshake;
int fd;
FALSE);
unsigned int id;
if (id == 0) {
return id;