client-authenticate.c revision bc6294e4f0d7a54ff601257adaa44331a91b234e
c25356d5978632df6203437e1953bcb29e0c736fTimo Sirainen/* Copyright (C) 2002 Timo Sirainen */
7b29ccd796fc75af86f827192d2f8c0e8f0087bbTimo Sirainenconst char *client_authenticate_get_capabilities(int secured)
ecc81625167ed96c04c02aa190a1ea5baa65b474Timo Sirainen unsigned int i, count;
0dffa25d211be541ee3c953b23566a1a990789dfTimo Sirainen mech = auth_client_get_available_mechs(auth_client, &count);
0dffa25d211be541ee3c953b23566a1a990789dfTimo Sirainen for (i = 0; i < count; i++) {
da2aa032ccfa8e7e4a4380ef738014549f4d2c2dTimo Sirainen /* a) transport is secured
0dffa25d211be541ee3c953b23566a1a990789dfTimo Sirainen b) auth mechanism isn't plaintext
7b29ccd796fc75af86f827192d2f8c0e8f0087bbTimo Sirainen c) we allow insecure authentication
7b29ccd796fc75af86f827192d2f8c0e8f0087bbTimo Sirainen - but don't advertise AUTH=PLAIN, as RFC 2595 requires
09801f106cd531a28b4e03ec665e44c421264560Timo Sirainenstatic void client_auth_abort(struct imap_client *client, const char *msg)
a9a928e40e3b691924c8e5e444e3e1a4320aa3bdStephan Bosch auth_client_request_abort(client->common.auth_request);
a9a928e40e3b691924c8e5e444e3e1a4320aa3bdStephan Bosch "NO Authentication failed.");
a9a928e40e3b691924c8e5e444e3e1a4320aa3bdStephan Bosch /* get back to normal client input */
a9a928e40e3b691924c8e5e444e3e1a4320aa3bdStephan Bosch client->common.io = client->common.fd == -1 ? NULL :
a9a928e40e3b691924c8e5e444e3e1a4320aa3bdStephan Bosch io_add(client->common.fd, IO_READ, client_input, client);
0c1835a90dd1dcedaeaedd1cd91672299cbeb5beTimo Sirainenstatic void master_callback(struct client *_client, int success)
f4735bf7ec2019fdc730e9ebdb39e5a4ea580405Timo Sirainen struct imap_client *client = (struct imap_client *) _client;
8cb72c59d5ea4e9e5f638d7ec840bb853f5a188eTimo Sirainen reason = t_strconcat("Login: ", client->common.virtual_user,
8cb72c59d5ea4e9e5f638d7ec840bb853f5a188eTimo Sirainen reason = t_strconcat("Internal login failure: ",
8cb72c59d5ea4e9e5f638d7ec840bb853f5a188eTimo Sirainen client_send_line(client, "* BYE Internal login failure.");
c0435c854a0e7246373b9752d163095cc4fbe985Timo Sirainenstatic void client_send_auth_data(struct imap_client *client,
1a0ece3e873e3864269ed7eaed957dc10c56d25fTimo Sirainen buf = buffer_create_dynamic(pool_datastack_create(),
1a0ece3e873e3864269ed7eaed957dc10c56d25fTimo Sirainen o_stream_send(client->output, buffer_get_data(buf, NULL),
5af5137f6dc0c9f358b7813e941e26f7bd735b3aTimo Sirainenstatic void login_callback(struct auth_request *request,
e2ce8d4a6ac5d82a906178148453e7613fab9ba0Timo Sirainen const void *ptr;
07e4875d250e7a7157cd99132aafc773cf3cdf83Timo Sirainen switch (auth_callback(request, reply, data, &client->common,
7662010b03ffe5f2a6ecf4b4eb220d1c65efea76Timo Sirainen /* login failed */
71aed7ba87b5fd5e96e97a22d89ac025b883d60aTimo Sirainen /* success, we should be able to log in. if we fail, just
c0435c854a0e7246373b9752d163095cc4fbe985Timo Sirainen disconnect the client. */
51e1a1c280ccb461a15827f7987d09cb9708b6e3Timo Sirainenclient_get_auth_flags(struct imap_client *client)
463f6ea04af934a68facaca0ff089bc306de3f98Timo Sirainen enum auth_client_request_new_flags auth_flags = 0;
0b6924ad1943fe5c6917fc49f675d8f316b0d939Timo Sirainen ssl_proxy_has_valid_client_cert(client->common.proxy))
0b6924ad1943fe5c6917fc49f675d8f316b0d939Timo Sirainen auth_flags |= AUTH_CLIENT_FLAG_SSL_VALID_CLIENT_CERT;
e0fab14602b73ff590b2a9c5d9e67e2dfb5d1f9eTimo Sirainenint cmd_login(struct imap_client *client, struct imap_arg *args)
c0435c854a0e7246373b9752d163095cc4fbe985Timo Sirainen /* two arguments: username and password */
ecc81625167ed96c04c02aa190a1ea5baa65b474Timo Sirainen if (args[0].type != IMAP_ARG_ATOM && args[0].type != IMAP_ARG_STRING)
c0435c854a0e7246373b9752d163095cc4fbe985Timo Sirainen if (args[1].type != IMAP_ARG_ATOM && args[1].type != IMAP_ARG_STRING)
602a0434db30d8e3292d1c161a803d96a879a74fTimo Sirainen if (!client->secured && disable_plaintext_auth) {
01f4ee4a0243f3fe9af763e1a540cd5cff0d63f5Timo Sirainen "* BAD [ALERT] Plaintext authentication is disabled, "
07e4875d250e7a7157cd99132aafc773cf3cdf83Timo Sirainen "but your client sent password in plaintext anyway. "
7d207b1e77a7b5e3fda640e353acfc86d261fedfTimo Sirainen "If anyone was listening, the password was exposed.");
7d207b1e77a7b5e3fda640e353acfc86d261fedfTimo Sirainen "NO Plaintext authentication disabled.");
4b9f99761df5014c659cd87fddaf6854af428cfcTimo Sirainen /* authorization ID \0 authentication ID \0 pass */
923115fd382904fa13bb09bf307bf2835b52df60Timo Sirainen auth_client_request_new(auth_client, "PLAIN", "IMAP",
6f08b98ac63c25b747120d0c8f8e319b4e26ab0fTimo Sirainen /* don't read any input from client until login is finished */
c06f4017027263cf3a08becc551f5126409e2a83Timo Sirainenstatic void authenticate_callback(struct auth_request *request,
09142ea11662746ea07475b1a4f69a6a406fb996Phil Carmody switch (auth_callback(request, reply, data, &client->common,
09142ea11662746ea07475b1a4f69a6a406fb996Phil Carmody /* login failed */
09142ea11662746ea07475b1a4f69a6a406fb996Phil Carmody /* continue */
573424407a2d3c1453638a643583a7cf10c129e1Phil Carmody client_send_auth_data(client, data, reply->data_size);
09142ea11662746ea07475b1a4f69a6a406fb996Phil Carmody /* success, we should be able to log in. if we fail, just
09142ea11662746ea07475b1a4f69a6a406fb996Phil Carmody disconnect the client. */
return FALSE;
return FALSE;
return FALSE;
return TRUE;
return TRUE;
return TRUE;