client-authenticate.c revision f0339f522dc9c8e2e8a29ef9a3f937c431c6bd1b
b9f30617c2c96d54acbc4f85ed17b939c4f28916Timo Sirainen/* Copyright (c) 2002-2016 Dovecot authors, see the included COPYING file */
9f0f2de10e4ea0c99052bf4b2bef8179f2536228Timo Sirainenvoid client_authenticate_get_capabilities(struct client *client, string_t *str)
9f0f2de10e4ea0c99052bf4b2bef8179f2536228Timo Sirainen unsigned int i, count;
9f0f2de10e4ea0c99052bf4b2bef8179f2536228Timo Sirainen mech = sasl_server_get_advertised_mechs(client, &count);
9f0f2de10e4ea0c99052bf4b2bef8179f2536228Timo Sirainen for (i = 0; i < count; i++) {
9f0f2de10e4ea0c99052bf4b2bef8179f2536228Timo Sirainenvoid imap_client_auth_result(struct client *client,
9f0f2de10e4ea0c99052bf4b2bef8179f2536228Timo Sirainen /* nothing to be done for IMAP */
9f0f2de10e4ea0c99052bf4b2bef8179f2536228Timo Sirainen /* IMAP referral
9f0f2de10e4ea0c99052bf4b2bef8179f2536228Timo Sirainen [nologin] referral host=.. [port=..] [destuser=..]
9f0f2de10e4ea0c99052bf4b2bef8179f2536228Timo Sirainen NO [REFERRAL imap://destuser;AUTH=..@host:port/] Can't login.
9f0f2de10e4ea0c99052bf4b2bef8179f2536228Timo Sirainen OK [...] Logged in, but you should use this server instead.
9f0f2de10e4ea0c99052bf4b2bef8179f2536228Timo Sirainen .. [REFERRAL ..] (Reason from auth server)
9f0f2de10e4ea0c99052bf4b2bef8179f2536228Timo Sirainen if (result == CLIENT_AUTH_RESULT_REFERRAL_SUCCESS) {
9f0f2de10e4ea0c99052bf4b2bef8179f2536228Timo Sirainen client_send_reply_code(client, IMAP_CMD_REPLY_OK,
9f0f2de10e4ea0c99052bf4b2bef8179f2536228Timo Sirainen client_send_reply_code(client, IMAP_CMD_REPLY_NO,
9f0f2de10e4ea0c99052bf4b2bef8179f2536228Timo Sirainen client_send_reply(client, IMAP_CMD_REPLY_BAD, text);
9f0f2de10e4ea0c99052bf4b2bef8179f2536228Timo Sirainen client_send_reply(client, IMAP_CMD_REPLY_NO, text);
9f0f2de10e4ea0c99052bf4b2bef8179f2536228Timo Sirainen client_send_reply_code(client, IMAP_CMD_REPLY_NO,
9f0f2de10e4ea0c99052bf4b2bef8179f2536228Timo Sirainen client_send_reply_code(client, IMAP_CMD_REPLY_NO,
9f0f2de10e4ea0c99052bf4b2bef8179f2536228Timo Sirainen client_send_reply_code(client, IMAP_CMD_REPLY_NO,
a64adf62fa33f2463a86f990217b0c9078531a40Timo Sirainen client_send_reply_code(client, IMAP_CMD_REPLY_NO,
a64adf62fa33f2463a86f990217b0c9078531a40Timo Sirainen client_send_reply_code(client, IMAP_CMD_REPLY_NO,
1cfdcb36985904eff281fc6d7ea2d13b3c375980Timo Sirainenimap_client_auth_begin(struct imap_client *imap_client, const char *mech_name,
a64adf62fa33f2463a86f990217b0c9078531a40Timo Sirainen imap_client->client_ignores_capability_resp_code ? 1 : 0,
a64adf62fa33f2463a86f990217b0c9078531a40Timo Sirainen i_free(imap_client->common.master_data_prefix);
a64adf62fa33f2463a86f990217b0c9078531a40Timo Sirainen imap_client->common.master_data_prefix = (void *)prefix;
a64adf62fa33f2463a86f990217b0c9078531a40Timo Sirainen imap_client->common.master_data_prefix_len = strlen(prefix)+1;
a64adf62fa33f2463a86f990217b0c9078531a40Timo Sirainen return client_auth_begin(&imap_client->common, mech_name, init_resp);
a64adf62fa33f2463a86f990217b0c9078531a40Timo Sirainenint cmd_authenticate(struct imap_client *imap_client, bool *parsed_r)
a64adf62fa33f2463a86f990217b0c9078531a40Timo Sirainen /* NOTE: This command's input is handled specially because the
a64adf62fa33f2463a86f990217b0c9078531a40Timo Sirainen SASL-IR can be large. */
a64adf62fa33f2463a86f990217b0c9078531a40Timo Sirainen const unsigned char *data;
383d0e8c24451468d6bea17e4b55d74de744abe6Timo Sirainen /* <auth mechanism name> [<initial SASL response>] */
a64adf62fa33f2463a86f990217b0c9078531a40Timo Sirainen data = i_stream_get_data(client->input, &size);
a64adf62fa33f2463a86f990217b0c9078531a40Timo Sirainen for (i = 0; i < size; i++) {
a64adf62fa33f2463a86f990217b0c9078531a40Timo Sirainen if (i == 0) {
57d2429fae575e96ca276355af675deb66b76d00Timo Sirainen /* empty mechanism name */
a64adf62fa33f2463a86f990217b0c9078531a40Timo Sirainen /* get SASL-IR, if any */
a64adf62fa33f2463a86f990217b0c9078531a40Timo Sirainen if ((ret = client_auth_read_line(client)) <= 0)
a64adf62fa33f2463a86f990217b0c9078531a40Timo Sirainenint cmd_login(struct imap_client *imap_client, const struct imap_arg *args)
a64adf62fa33f2463a86f990217b0c9078531a40Timo Sirainen /* two arguments: username and password */
a64adf62fa33f2463a86f990217b0c9078531a40Timo Sirainen if (!client_check_plaintext_auth(client, TRUE)) {
50e20db49f29917fe9adcf1b56b11badf28bd0e4Timo Sirainen /* authorization ID \0 authentication ID \0 pass */
a64adf62fa33f2463a86f990217b0c9078531a40Timo Sirainen plain_login = buffer_create_dynamic(pool_datastack_create(), 64);
a64adf62fa33f2463a86f990217b0c9078531a40Timo Sirainen buffer_append(plain_login, user, strlen(user));
a64adf62fa33f2463a86f990217b0c9078531a40Timo Sirainen buffer_append(plain_login, pass, strlen(pass));
a64adf62fa33f2463a86f990217b0c9078531a40Timo Sirainen base64 = buffer_create_dynamic(pool_datastack_create(),
a64adf62fa33f2463a86f990217b0c9078531a40Timo Sirainen base64_encode(plain_login->data, plain_login->used, base64);