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 */
24 #include "imap_private.h"
27 static imap_auth_t imap_authenticators[] = {
29 { imap_auth_sasl, NULL },
31 { imap_auth_anon, "anonymous" },
34 { imap_auth_gss, "gssapi" },
36 /* SASL includes CRAM-MD5 (and GSSAPI, but that's not enabled by default) */
38 { imap_auth_cram_md5, "cram-md5" },
40 { imap_auth_login, "login" },
45 /* imap_authenticate: Attempt to authenticate using either user-specified
46 * authentication method if specified, or any. */
47 int imap_authenticate (IMAP_DATA* idata)
49 imap_auth_t* authenticator;
55 if (ImapAuthenticators && *ImapAuthenticators)
57 /* Try user-specified list of authentication methods */
58 methods = safe_strdup (ImapAuthenticators);
60 for (method = methods; method; method = delim)
62 delim = strchr (method, ':');
68 dprint (2, (debugfile, "imap_authenticate: Trying method %s\n", method));
69 authenticator = imap_authenticators;
71 while (authenticator->authenticate)
73 if (!authenticator->method ||
74 !ascii_strcasecmp (authenticator->method, method))
75 if ((r = authenticator->authenticate (idata, method)) !=
90 /* Fall back to default: any authenticator */
91 dprint (2, (debugfile, "imap_authenticate: Using any available method.\n"));
92 authenticator = imap_authenticators;
94 while (authenticator->authenticate)
96 if ((r = authenticator->authenticate (idata, NULL)) != IMAP_AUTH_UNAVAIL)
102 if (r == IMAP_AUTH_UNAVAIL)
104 mutt_error (_("No authenticators available"));