client-authenticate.c revision 46552a931924c2d743f045e95b08c3ce6beda91a
5f5870385cff47efd2f58e7892f251cf13761528Timo Sirainen/* Copyright (c) 2002-2009 Dovecot authors, see the included COPYING file */
d22301419109ed4a38351715e6760011421dadecTimo Sirainenconst char *capability_string = POP3_CAPABILITY_REPLY;
a0b0d629931773c17a236f6214adbe0e13b9b3fdTimo Sirainenbool cmd_capa(struct pop3_client *client, const char *args ATTR_UNUSED)
a0b0d629931773c17a236f6214adbe0e13b9b3fdTimo Sirainen unsigned int i, count;
c04f9a724a7b3cc649485a61b0a540868d25d71bTimo Sirainen if (!client->common.set->disable_plaintext_auth ||
6ef7e31619edfaa17ed044b45861d106a86191efTimo Sirainen mech = sasl_server_get_advertised_mechs(&client->common, &count);
01cbf4ac5d44137ab434791be7f838d98d0fcf3bTimo Sirainen for (i = 0; i < count; i++) {
b12a6d0e54318273acf0d0fb8b3f4c29f67b62b0Timo Sirainenbool pop3_client_auth_handle_reply(struct client *client,
73247459cf41eb1e5ae5bc61354db46d3b05ee75Timo Sirainen client_send_line(client, CLIENT_CMD_REPLY_AUTH_FAILED,
fe6c1556d3529a6376d4cbb3766c34aebde0de99Timo Sirainen client_send_line(client, CLIENT_CMD_REPLY_AUTH_FAIL_TEMP,
fe6c1556d3529a6376d4cbb3766c34aebde0de99Timo Sirainen client_send_line(client, CLIENT_CMD_REPLY_AUTH_FAILED,
fe6c1556d3529a6376d4cbb3766c34aebde0de99Timo Sirainenbool cmd_auth(struct pop3_client *pop3_client, const char *args)
73247459cf41eb1e5ae5bc61354db46d3b05ee75Timo Sirainen const char *mech_name, *p;
73247459cf41eb1e5ae5bc61354db46d3b05ee75Timo Sirainen /* Old-style SASL discovery, used by MS Outlook */
73247459cf41eb1e5ae5bc61354db46d3b05ee75Timo Sirainen unsigned int i, count;
d30da25fb6be1f1c667d93767c9194000194b618Timo Sirainen mech = sasl_server_get_advertised_mechs(client, &count);
fe6c1556d3529a6376d4cbb3766c34aebde0de99Timo Sirainen for (i = 0; i < count; i++) {
fe6c1556d3529a6376d4cbb3766c34aebde0de99Timo Sirainen /* <mechanism name> <initial response> */
fe6c1556d3529a6376d4cbb3766c34aebde0de99Timo Sirainen (void)client_auth_begin(client, mech_name, args);
fe6c1556d3529a6376d4cbb3766c34aebde0de99Timo Sirainenbool cmd_user(struct pop3_client *pop3_client, const char *args)
8fcff4c5b52f24d9c681805fdf06b486f1d0fcbeTimo Sirainen if (!client_check_plaintext_auth(&pop3_client->common, FALSE))
d22301419109ed4a38351715e6760011421dadecTimo Sirainen client_send_raw(&pop3_client->common, "+OK\r\n");
8fcff4c5b52f24d9c681805fdf06b486f1d0fcbeTimo Sirainenbool cmd_pass(struct pop3_client *pop3_client, const char *args)
345212e8f61ebf14ff4f80df26df9e655eb5121eTimo Sirainen /* client may ignore the USER reply and only display the error
345212e8f61ebf14ff4f80df26df9e655eb5121eTimo Sirainen message from PASS */
345212e8f61ebf14ff4f80df26df9e655eb5121eTimo Sirainen if (!client_check_plaintext_auth(client, TRUE))
83bb013a99f0936995f9c7a1077822662d8fefdbTimo Sirainen client_send_line(client, CLIENT_CMD_REPLY_BAD,
83bb013a99f0936995f9c7a1077822662d8fefdbTimo Sirainen "No username given.");
90adcaa0a00eba29b7fbd50ca66be11c8d086d6aTimo Sirainen /* authorization ID \0 authentication ID \0 pass */
90adcaa0a00eba29b7fbd50ca66be11c8d086d6aTimo Sirainen str_append(plain_login, pop3_client->last_user);
90adcaa0a00eba29b7fbd50ca66be11c8d086d6aTimo Sirainen base64 = buffer_create_dynamic(pool_datastack_create(),
83bb013a99f0936995f9c7a1077822662d8fefdbTimo Sirainen base64_encode(plain_login->data, plain_login->used, base64);
90adcaa0a00eba29b7fbd50ca66be11c8d086d6aTimo Sirainen (void)client_auth_begin(client, "PLAIN", str_c(base64));
5daa12cc1c862eec4f63df42227812d3514da2ccTimo Sirainenbool cmd_apop(struct pop3_client *pop3_client, const char *args)
5daa12cc1c862eec4f63df42227812d3514da2ccTimo Sirainen const char *p;
e6aa82aeb50948cb47a45a1b61a9c16d6a162388Timo Sirainen client_log(client, "APOP failed: APOP not enabled");
e6aa82aeb50948cb47a45a1b61a9c16d6a162388Timo Sirainen client_send_line(client, CLIENT_CMD_REPLY_BAD,
bf9402875418faf11825cf11fbe06326b6086e3dTimo Sirainen "APOP not enabled.");
5daa12cc1c862eec4f63df42227812d3514da2ccTimo Sirainen /* <username> <md5 sum in hex> */
5daa12cc1c862eec4f63df42227812d3514da2ccTimo Sirainen client_log(client, "APOP failed: Invalid parameters");
5daa12cc1c862eec4f63df42227812d3514da2ccTimo Sirainen client_send_line(client, CLIENT_CMD_REPLY_BAD,
5daa12cc1c862eec4f63df42227812d3514da2ccTimo Sirainen "Invalid parameters.");
83bb013a99f0936995f9c7a1077822662d8fefdbTimo Sirainen /* APOP challenge \0 username \0 APOP response */
83bb013a99f0936995f9c7a1077822662d8fefdbTimo Sirainen apop_data = buffer_create_dynamic(pool_datastack_create(), 128);
83bb013a99f0936995f9c7a1077822662d8fefdbTimo Sirainen buffer_append(apop_data, pop3_client->apop_challenge,
8fcff4c5b52f24d9c681805fdf06b486f1d0fcbeTimo Sirainen buffer_append(apop_data, args, (size_t)(p-args));
a0b0d629931773c17a236f6214adbe0e13b9b3fdTimo Sirainen "Invalid characters in MD5 response");
83bb013a99f0936995f9c7a1077822662d8fefdbTimo Sirainen client_send_line(client, CLIENT_CMD_REPLY_BAD,
8fcff4c5b52f24d9c681805fdf06b486f1d0fcbeTimo Sirainen "Invalid characters in MD5 response.");
a0b0d629931773c17a236f6214adbe0e13b9b3fdTimo Sirainen base64 = buffer_create_dynamic(pool_datastack_create(),
ea5f188fc29dfaa0c4071e6413e16e1d04263722Timo Sirainen base64_encode(apop_data->data, apop_data->used, base64);
ea5f188fc29dfaa0c4071e6413e16e1d04263722Timo Sirainen auth_client_get_connect_id(auth_client, &server_pid, &connect_uid);
a0b0d629931773c17a236f6214adbe0e13b9b3fdTimo Sirainen if (pop3_client->apop_server_pid != server_pid ||
a0b0d629931773c17a236f6214adbe0e13b9b3fdTimo Sirainen pop3_client->apop_connect_uid != connect_uid) {
36f4f01d56ec9156ab75bc2047a8388192df3178Timo Sirainen /* we reconnected to auth server and can't authenticate
36f4f01d56ec9156ab75bc2047a8388192df3178Timo Sirainen with APOP in this session anymore. disconnecting the user
36f4f01d56ec9156ab75bc2047a8388192df3178Timo Sirainen is probably the best solution now. */
36f4f01d56ec9156ab75bc2047a8388192df3178Timo Sirainen "Reconnected to auth server, can't do APOP");
a0b0d629931773c17a236f6214adbe0e13b9b3fdTimo Sirainen (void)client_auth_begin(client, "APOP", str_c(base64));