client-authenticate.c revision cd94aeaa294f7cc507206b4b2075852f00e14d61
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen/* Copyright (c) 2002-2008 Dovecot authors, see the included COPYING file */
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainenconst char *capability_string = POP3_CAPABILITY_REPLY;
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainenbool cmd_capa(struct pop3_client *client, const char *args ATTR_UNUSED)
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen unsigned int i, count;
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen if (!disable_plaintext_auth || client->common.secured)
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen mech = auth_client_get_available_mechs(auth_client, &count);
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen for (i = 0; i < count; i++) {
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen /* a) transport is secured
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen b) auth mechanism isn't plaintext
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen c) we allow insecure authentication
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen if ((mech[i].flags & MECH_SEC_PRIVATE) == 0 &&
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen (client->common.secured || !disable_plaintext_auth ||
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainenstatic void client_auth_input(struct pop3_client *client)
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen /* @UNSAFE */
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen line = i_stream_next_line(client->common.input);
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen sasl_server_auth_client_error(&client->common,
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen "Authentication aborted");
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen auth_client_request_continue(client->common.auth_request, line);
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen /* clear sensitive data */
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainenstatic bool client_handle_args(struct pop3_client *client,
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen const char *reason = NULL, *host = NULL, *destuser = NULL, *pass = NULL;
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen bool proxy = FALSE, temp = FALSE, nologin = !success;
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen !login_proxy_is_ourself(&client->common, host, port, destuser)) {
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen /* we want to proxy the connection to another server.
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen don't do this unless authentication succeeded. with
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen master user proxying we can get FAIL with proxy still set.
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen proxy host=.. [port=..] [destuser=..] pass=.. */
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen if (pop3_proxy_new(client, host, port, destuser, pass) < 0)
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen /* get back to normal client input. */
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen client->io = io_add(client->common.fd, IO_READ,
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainenstatic void sasl_callback(struct client *_client, enum sasl_server_reply reply,
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen struct pop3_client *client = (struct pop3_client *)_client;
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen const char *msg;
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen /* get back to normal client input. */
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen client->io = io_add(client->common.fd, IO_READ,
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen /* don't check return value here. it gets tricky if we try
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen to call client_destroy() in here. */
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen client->io = io_add(client->common.fd, IO_READ,
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainenbool cmd_auth(struct pop3_client *client, const char *args)
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen const char *mech_name, *p;
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen /* Old-style SASL discovery, used by MS Outlook */
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen unsigned int i, count;
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen mech = auth_client_get_available_mechs(auth_client, &count);
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen for (i = 0; i < count; i++) {
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen if ((mech[i].flags & MECH_SEC_PRIVATE) == 0 &&
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen (client->common.secured || disable_plaintext_auth ||
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen /* <mechanism name> <initial response> */
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen sasl_server_auth_begin(&client->common, POP3_SERVICE_NAME, mech_name,
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen /* don't handle input until we get the initial auth reply */
9f19a50d5966643c4d1c5ca06868ac2ad31bc4d5Timo Sirainenstatic bool check_plaintext_auth(struct pop3_client *client)
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen if (client->common.secured || !disable_plaintext_auth)
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen client_syslog(&client->common, "Login failed: "
9f19a50d5966643c4d1c5ca06868ac2ad31bc4d5Timo Sirainen "Plaintext authentication disabled");
9f19a50d5966643c4d1c5ca06868ac2ad31bc4d5Timo Sirainen client_send_line(client, "-ERR "AUTH_PLAINTEXT_DISABLED_MSG);
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen client->common.auth_tried_disabled_plaintext = TRUE;
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainenbool cmd_user(struct pop3_client *client, const char *args)
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainenbool cmd_pass(struct pop3_client *client, const char *args)
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen /* client may ignore the USER reply and only display the error
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen message from PASS */
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen client_send_line(client, "-ERR No username given.");
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen /* authorization ID \0 authentication ID \0 pass */
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen base64 = buffer_create_dynamic(pool_datastack_create(),
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen base64_encode(plain_login->data, plain_login->used, base64);
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen sasl_server_auth_begin(&client->common, POP3_SERVICE_NAME, "PLAIN",
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen /* don't read any input from client until login is finished */
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainenbool cmd_apop(struct pop3_client *client, const char *args)
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen const char *p;
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen "APOP failed: APOP not enabled");
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen client_send_line(client, "-ERR APOP not enabled.");
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen /* <username> <md5 sum in hex> */
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen "APOP failed: Invalid parameters");
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen client_send_line(client, "-ERR Invalid parameters.");
if (verbose_auth) {
return TRUE;
return TRUE;
return TRUE;