2 * Copyright notice from original mutt:
3 * Copyright (C) 1996-8 Michael R. Elkins <me@mutt.org>
4 * Copyright (C) 1996-9 Brandon Long <blong@fiction.net>
5 * Copyright (C) 1999-2001 Brendan Cully <brendan@kublai.com>
7 * This file is part of mutt-ng, see http://www.muttng.org/.
8 * It's licensed under the GNU General Public License,
9 * please see the file GPL in the top level source directory.
12 /* IMAP login/authentication code */
20 #include "lib/debug.h"
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) {
56 /* Try user-specified list of authentication methods */
57 methods = str_dup (ImapAuthenticators);
59 for (method = methods; method; method = delim) {
60 delim = strchr (method, ':');
66 debug_print (2, ("Trying method %s\n", method));
67 authenticator = imap_authenticators;
69 while (authenticator->authenticate) {
70 if (!authenticator->method ||
71 !ascii_strcasecmp (authenticator->method, method))
72 if ((r = authenticator->authenticate (idata, method)) !=
85 /* Fall back to default: any authenticator */
86 debug_print (2, ("Using any available method.\n"));
87 authenticator = imap_authenticators;
89 while (authenticator->authenticate) {
91 authenticator->authenticate (idata, NULL)) != IMAP_AUTH_UNAVAIL)
97 if (r == IMAP_AUTH_UNAVAIL) {
98 mutt_error (_("No authenticators available"));