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 */
18 #include <lib-lib/mem.h>
22 #include "lib/debug.h"
26 #include "imap_private.h"
29 static imap_auth_t imap_authenticators[] = {
31 {imap_auth_sasl, NULL},
33 {imap_auth_anon, "anonymous"},
36 {imap_auth_gss, "gssapi"},
38 /* SASL includes CRAM-MD5 (and GSSAPI, but that's not enabled by default) */
40 {imap_auth_cram_md5, "cram-md5"},
42 {imap_auth_login, "login"},
47 /* imap_authenticate: Attempt to authenticate using either user-specified
48 * authentication method if specified, or any. */
49 int imap_authenticate (IMAP_DATA * idata)
51 imap_auth_t *authenticator;
57 if (ImapAuthenticators && *ImapAuthenticators) {
58 /* Try user-specified list of authentication methods */
59 methods = str_dup (ImapAuthenticators);
61 for (method = methods; method; method = delim) {
62 delim = strchr (method, ':');
68 debug_print (2, ("Trying method %s\n", method));
69 authenticator = imap_authenticators;
71 while (authenticator->authenticate) {
72 if (!authenticator->method ||
73 !ascii_strcasecmp (authenticator->method, method))
74 if ((r = authenticator->authenticate (idata, method)) !=
87 /* Fall back to default: any authenticator */
88 debug_print (2, ("Using any available method.\n"));
89 authenticator = imap_authenticators;
91 while (authenticator->authenticate) {
93 authenticator->authenticate (idata, NULL)) != IMAP_AUTH_UNAVAIL)
99 if (r == IMAP_AUTH_UNAVAIL) {
100 mutt_error (_("No authenticators available"));