2 * Copyright (C) 1996-8 Michael R. Elkins <me@mutt.org>
3 * Copyright (C) 1996-9 Brandon Long <blong@fiction.net>
4 * Copyright (C) 1999-2001 Brendan Cully <brendan@kublai.com>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
21 /* IMAP login/authentication code */
28 #include "imap_private.h"
31 static imap_auth_t imap_authenticators[] = {
33 { imap_auth_sasl, NULL },
35 { imap_auth_anon, "anonymous" },
38 { imap_auth_gss, "gssapi" },
40 /* SASL includes CRAM-MD5 (and GSSAPI, but that's not enabled by default) */
42 { imap_auth_cram_md5, "cram-md5" },
44 { imap_auth_login, "login" },
49 /* imap_authenticate: Attempt to authenticate using either user-specified
50 * authentication method if specified, or any. */
51 int imap_authenticate (IMAP_DATA* idata)
53 imap_auth_t* authenticator;
59 if (ImapAuthenticators && *ImapAuthenticators)
61 /* Try user-specified list of authentication methods */
62 methods = safe_strdup (ImapAuthenticators);
64 for (method = methods; method; method = delim)
66 delim = strchr (method, ':');
72 dprint (2, (debugfile, "imap_authenticate: Trying method %s\n", method));
73 authenticator = imap_authenticators;
75 while (authenticator->authenticate)
77 if (!authenticator->method ||
78 !ascii_strcasecmp (authenticator->method, method))
79 if ((r = authenticator->authenticate (idata, method)) !=
94 /* Fall back to default: any authenticator */
95 dprint (2, (debugfile, "imap_authenticate: Using any available method.\n"));
96 authenticator = imap_authenticators;
98 while (authenticator->authenticate)
100 if ((r = authenticator->authenticate (idata, NULL)) != IMAP_AUTH_UNAVAIL)
106 if (r == IMAP_AUTH_UNAVAIL)
108 mutt_error (_("No authenticators available"));