diff --git a/src/managesieve-login/client-authenticate.c b/src/managesieve-login/client-authenticate.c index fe68ca4d1c99adec4d84496b2b8d13defc1991a1..57eeca3cd267fd26f0072e8f0ad03318d480d386 100644 --- a/src/managesieve-login/client-authenticate.c +++ b/src/managesieve-login/client-authenticate.c @@ -19,9 +19,7 @@ #include "client-authenticate.h" #include "managesieve-proxy.h" - -const char *client_authenticate_get_capabilities -(struct client *client) +const char *client_authenticate_get_capabilities(struct client *client) { const struct auth_mech_desc *mech; unsigned int i, count; @@ -40,8 +38,9 @@ const char *client_authenticate_get_capabilities } void managesieve_client_auth_result(struct client *client, - enum client_auth_result result, - const struct client_auth_reply *reply, const char *text) + enum client_auth_result result, + const struct client_auth_reply *reply, + const char *text) { struct managesieve_client *msieve_client = (struct managesieve_client *)client; @@ -55,7 +54,7 @@ void managesieve_client_auth_result(struct client *client, case CLIENT_AUTH_RESULT_REFERRAL_NOLOGIN: /* MANAGESIEVE referral - [nologin] referral host=.. [port=..] [destuser=..] + [nologin] referral host .. [port=..] [destuser=..] [reason=..] NO [REFERRAL sieve://user;AUTH=mech@host:port/] "Can't login." @@ -69,11 +68,10 @@ void managesieve_client_auth_result(struct client *client, if (reply->proxy.port != 4190) str_printfa(referral, ":%u", reply->proxy.port); - if ( result == CLIENT_AUTH_RESULT_REFERRAL_SUCCESS ) { - client_send_okresp(client, str_c(referral), text);; - } else { + if (result == CLIENT_AUTH_RESULT_REFERRAL_SUCCESS) + client_send_okresp(client, str_c(referral), text); + else client_send_noresp(client, str_c(referral), text); - } break; case CLIENT_AUTH_RESULT_ABORTED: case CLIENT_AUTH_RESULT_AUTHFAILED_REASON: @@ -96,11 +94,11 @@ void managesieve_client_auth_result(struct client *client, managesieve_parser_reset(msieve_client->parser); } -void managesieve_client_auth_send_challenge -(struct client *client, const char *data) +void managesieve_client_auth_send_challenge( + struct client *client, const char *data) { struct managesieve_client *msieve_client = - (struct managesieve_client *) client; + (struct managesieve_client *)client; T_BEGIN { string_t *str = t_str_new(256); @@ -115,8 +113,9 @@ void managesieve_client_auth_send_challenge managesieve_parser_reset(msieve_client->parser); } -static int managesieve_client_auth_read_response -(struct managesieve_client *msieve_client, bool initial, const char **error_r) +static int +managesieve_client_auth_read_response(struct managesieve_client *msieve_client, + bool initial, const char **error_r) { struct client *client = &msieve_client->common; const struct managesieve_arg *args; @@ -129,29 +128,31 @@ static int managesieve_client_auth_read_response *error_r = NULL; - if ( i_stream_read(client->input) == -1 ) { - /* disconnected */ + if (i_stream_read(client->input) == -1) { + /* Disconnected */ client_destroy_iostream_error(client); return -1; } - if ( msieve_client->auth_response_input == NULL ) { + if (msieve_client->auth_response_input == NULL) { - if ( msieve_client->skip_line ) { - if ( i_stream_next_line(client->input) == NULL ) + if (msieve_client->skip_line) { + if (i_stream_next_line(client->input) == NULL) return 0; - msieve_client->skip_line = FALSE; } - switch ( managesieve_parser_read_args(msieve_client->parser, 0, - MANAGESIEVE_PARSE_FLAG_STRING_STREAM, &args) ) { + switch (managesieve_parser_read_args( + msieve_client->parser, 0, + MANAGESIEVE_PARSE_FLAG_STRING_STREAM, &args)) { case -1: - error = managesieve_parser_get_error(msieve_client->parser, &fatal); + error = managesieve_parser_get_error( + msieve_client->parser, &fatal); if (fatal) { client_send_bye(client, error); client_destroy(client, t_strconcat( - "parse error during auth: ", error, NULL)); + "parse error during auth: ", + error, NULL)); } else { *error_r = error; } @@ -159,14 +160,14 @@ static int managesieve_client_auth_read_response return -1; case -2: - /* not enough data */ + /* Not enough data */ return 0; default: break; } - if ( MANAGESIEVE_ARG_IS_EOL(&args[0]) ) { + if (MANAGESIEVE_ARG_IS_EOL(&args[0])) { if (!initial) { *error_r = "Received empty AUTHENTICATE client response line."; msieve_client->skip_line = TRUE; @@ -176,10 +177,10 @@ static int managesieve_client_auth_read_response return 1; } - if ( !managesieve_arg_get_string_stream - (&args[0], &msieve_client->auth_response_input) - || !MANAGESIEVE_ARG_IS_EOL(&args[1]) ) { - if ( !initial ) + if (!managesieve_arg_get_string_stream( + &args[0], &msieve_client->auth_response_input) || + !MANAGESIEVE_ARG_IS_EOL(&args[1])) { + if (!initial) *error_r = "Invalid AUTHENTICATE client response."; else *error_r = "Invalid AUTHENTICATE initial response."; @@ -187,19 +188,22 @@ static int managesieve_client_auth_read_response return -1; } - if ( i_stream_get_size - (msieve_client->auth_response_input, FALSE, &resp_size) <= 0 ) + if (i_stream_get_size(msieve_client->auth_response_input, + FALSE, &resp_size) <= 0) resp_size = 0; - if (client->auth_response == NULL) - client->auth_response = str_new(default_pool, I_MAX(resp_size+1, 256)); + if (client->auth_response == NULL) { + client->auth_response = + str_new(default_pool, I_MAX(resp_size+1, 256)); + } } - while ( (ret=i_stream_read_more - (msieve_client->auth_response_input, &data, &size) ) > 0 ) { - - if (str_len(client->auth_response) + size > LOGIN_MAX_AUTH_BUF_SIZE) { - client_destroy(client, "Authentication response too large"); + while ((ret = i_stream_read_more(msieve_client->auth_response_input, + &data, &size)) > 0) { + if ((str_len(client->auth_response) + size) > + LOGIN_MAX_AUTH_BUF_SIZE) { + client_destroy(client, + "Authentication response too large"); return -1; } @@ -207,15 +211,18 @@ static int managesieve_client_auth_read_response i_stream_skip(msieve_client->auth_response_input, size); } - if ( ret == 0 ) return 0; + if (ret == 0) + return 0; - if ( msieve_client->auth_response_input->stream_errno != 0 ) { - if ( !client->input->eof && - msieve_client->auth_response_input->stream_errno == EINVAL ) { + if (msieve_client->auth_response_input->stream_errno != 0) { + if (!client->input->eof && + msieve_client->auth_response_input->stream_errno == EINVAL) { msieve_client->skip_line = TRUE; - *error_r = t_strconcat - ("Error in AUTHENTICATE response string: ", - i_stream_get_error(msieve_client->auth_response_input), NULL); + *error_r = t_strconcat( + "Error in AUTHENTICATE response string: ", + i_stream_get_error( + msieve_client->auth_response_input), + NULL); return -1; } @@ -223,7 +230,7 @@ static int managesieve_client_auth_read_response return -1; } - if ( i_stream_next_line(client->input) == NULL ) + if (i_stream_next_line(client->input) == NULL) return 0; return 1; @@ -232,20 +239,21 @@ static int managesieve_client_auth_read_response void managesieve_client_auth_parse_response(struct client *client) { struct managesieve_client *msieve_client = - (struct managesieve_client *) client; + (struct managesieve_client *)client; const char *error = NULL; int ret; - if ( (ret=managesieve_client_auth_read_response(msieve_client, FALSE, &error)) - < 0 ) { - if ( error != NULL ) + ret = managesieve_client_auth_read_response(msieve_client, FALSE, + &error); + if (ret < 0) { + if (error != NULL) client_auth_fail(client, error); return; } + if (ret == 0) + return; - if ( ret == 0 ) return; - - if ( strcmp(str_c(client->auth_response), "*") == 0 ) { + if (strcmp(str_c(client->auth_response), "*") == 0) { client_auth_abort(client); return; } @@ -256,8 +264,8 @@ void managesieve_client_auth_parse_response(struct client *client) str_len(client->auth_response)); } -int cmd_authenticate -(struct managesieve_client *msieve_client, const struct managesieve_arg *args) +int cmd_authenticate(struct managesieve_client *msieve_client, + const struct managesieve_arg *args) { /* NOTE: This command's input is handled specially because the SASL-IR can be large. */ @@ -269,10 +277,9 @@ int cmd_authenticate if (!msieve_client->auth_mech_name_parsed) { i_assert(args != NULL); - /* one mandatory argument: authentication mechanism name */ - if ( !managesieve_arg_get_string(&args[0], &mech_name) ) + /* One mandatory argument: authentication mechanism name */ + if (!managesieve_arg_get_string(&args[0], &mech_name)) return -1; - if (*mech_name == '\0') return -1; @@ -285,25 +292,25 @@ int cmd_authenticate } msieve_client->skip_line = FALSE; - if ( (ret=managesieve_client_auth_read_response(msieve_client, TRUE, &error)) - < 0 ) { + ret = managesieve_client_auth_read_response(msieve_client, TRUE, + &error); + if (ret < 0) { msieve_client->auth_mech_name_parsed = FALSE; - if ( error != NULL ) { + if (error != NULL) client_send_no(client, error); - } return 1; } + if (ret == 0) + return 0; - if ( ret == 0 ) return 0; - - init_response = ( client->auth_response == NULL ? NULL : - t_strdup(str_c(client->auth_response)) ); + init_response = (client->auth_response == NULL ? + NULL : t_strdup(str_c(client->auth_response))); msieve_client->auth_mech_name_parsed = FALSE; - if ( (ret=client_auth_begin - (client, t_strdup(client->auth_mech_name), init_response)) < 0 ) + ret = client_auth_begin(client, t_strdup(client->auth_mech_name), + init_response); + if (ret < 0) return ret; msieve_client->cmd_finished = TRUE; return 0; } -