mutt stable branch with some hacks
at jcs 114 lines 3.0 kB view raw
1/* 2 * Copyright (C) 1996-1998 Michael R. Elkins <me@mutt.org> 3 * Copyright (C) 1996-1999 Brandon Long <blong@fiction.net> 4 * Copyright (C) 1999-2001 Brendan Cully <brendan@kublai.com> 5 * 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. 10 * 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. 15 * 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 19 */ 20 21/* IMAP login/authentication code */ 22 23#if HAVE_CONFIG_H 24# include "config.h" 25#endif 26 27#include "mutt.h" 28#include "imap_private.h" 29#include "auth.h" 30 31static const imap_auth_t imap_authenticators[] = { 32 { imap_auth_oauth, "oauthbearer" }, 33#ifdef USE_SASL 34 { imap_auth_sasl, NULL }, 35#else 36 { imap_auth_anon, "anonymous" }, 37#endif 38#ifdef USE_GSS 39 { imap_auth_gss, "gssapi" }, 40#endif 41 /* SASL includes CRAM-MD5 (and GSSAPI, but that's not enabled by default) */ 42#ifndef USE_SASL 43 { imap_auth_cram_md5, "cram-md5" }, 44#endif 45 { imap_auth_login, "login" }, 46 47 { NULL, NULL } 48}; 49 50/* imap_authenticate: Attempt to authenticate using either user-specified 51 * authentication method if specified, or any. */ 52int imap_authenticate (IMAP_DATA* idata) 53{ 54 const imap_auth_t* authenticator; 55 char* methods; 56 char* method; 57 char* delim; 58 int r = -1; 59 60 if (ImapAuthenticators) 61 { 62 /* Try user-specified list of authentication methods */ 63 methods = safe_strdup (ImapAuthenticators); 64 65 for (method = methods; method; method = delim) 66 { 67 delim = strchr (method, ':'); 68 if (delim) 69 *delim++ = '\0'; 70 if (! method[0]) 71 continue; 72 73 dprint (2, (debugfile, "imap_authenticate: Trying method %s\n", method)); 74 authenticator = imap_authenticators; 75 76 while (authenticator->authenticate) 77 { 78 if (!authenticator->method || 79 !ascii_strcasecmp (authenticator->method, method)) 80 if ((r = authenticator->authenticate (idata, method)) != 81 IMAP_AUTH_UNAVAIL) 82 { 83 FREE (&methods); 84 return r; 85 } 86 87 authenticator++; 88 } 89 } 90 91 FREE (&methods); 92 } 93 else 94 { 95 /* Fall back to default: any authenticator */ 96 dprint (2, (debugfile, "imap_authenticate: Using any available method.\n")); 97 authenticator = imap_authenticators; 98 99 while (authenticator->authenticate) 100 { 101 if ((r = authenticator->authenticate (idata, NULL)) != IMAP_AUTH_UNAVAIL) 102 return r; 103 authenticator++; 104 } 105 } 106 107 if (r == IMAP_AUTH_UNAVAIL) 108 { 109 mutt_error (_("No authenticators available")); 110 mutt_sleep (1); 111 } 112 113 return r; 114}