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