drop GSS as well, users will have to use correctly configured sasl.
[apps/madmutt.git] / imap / auth.c
1 /*
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>
6  *
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.
10  */
11
12 /* IMAP login/authentication code */
13
14 #include <lib-lib/lib-lib.h>
15
16 #include "mutt.h"
17 #include "imap_private.h"
18 #include "auth.h"
19
20 static imap_auth_t imap_authenticators[] = {
21   {imap_auth_sasl, NULL},
22   {imap_auth_login, "login"},
23   {NULL, NULL}
24 };
25
26 /* imap_authenticate: Attempt to authenticate using either user-specified
27  *   authentication method if specified, or any. */
28 int imap_authenticate (IMAP_DATA * idata)
29 {
30   imap_auth_t *authenticator;
31   char *methods;
32   char *method;
33   char *delim;
34   int r = -1;
35
36   if (ImapAuthenticators && *ImapAuthenticators) {
37     /* Try user-specified list of authentication methods */
38     methods = m_strdup(ImapAuthenticators);
39
40     for (method = methods; method; method = delim) {
41       delim = strchr (method, ':');
42       if (delim)
43         *delim++ = '\0';
44       if (!method[0])
45         continue;
46
47       authenticator = imap_authenticators;
48
49       while (authenticator->authenticate) {
50         if (!authenticator->method ||
51             !ascii_strcasecmp (authenticator->method, method))
52           if ((r = authenticator->authenticate (idata, method)) !=
53               IMAP_AUTH_UNAVAIL) {
54             p_delete(&methods);
55             return r;
56           }
57
58         authenticator++;
59       }
60     }
61
62     p_delete(&methods);
63   }
64   else {
65     /* Fall back to default: any authenticator */
66     authenticator = imap_authenticators;
67
68     while (authenticator->authenticate) {
69       if ((r =
70            authenticator->authenticate (idata, NULL)) != IMAP_AUTH_UNAVAIL)
71         return r;
72       authenticator++;
73     }
74   }
75
76   if (r == IMAP_AUTH_UNAVAIL) {
77     mutt_error (_("No authenticators available"));
78     mutt_sleep (1);
79   }
80
81   return r;
82 }