From: Brendan Cully Date: Tue, 28 Jun 2005 19:26:54 +0000 (+0000) Subject: Add $imap_login variable to specify which user to authenticate as X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=64b98e4c24bb9313aa4a4ae043d53e3aaf3b5695;p=neomutt Add $imap_login variable to specify which user to authenticate as ($imap_user controls which user's mail gets accessed). Currently this can't be specified interactively, since I can't think of a way to do it that wouldn't annoy users where login == user (the default value of $imap_login). --- diff --git a/account.c b/account.c index 4a7493ff7..3b4a4fa97 100644 --- a/account.c +++ b/account.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2000-3 Brendan Cully + * Copyright (C) 2000-5 Brendan Cully * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -26,10 +26,11 @@ #include "account.h" #include "url.h" -/* mutt_account_match: compare account info (host/port/user) */ +/* mutt_account_match: compare account info (host/port/user/login) */ int mutt_account_match (const ACCOUNT* a1, const ACCOUNT* a2) { const char* user = NONULL (Username); + const char* login = NONULL (Username); if (a1->type != a2->type) return 0; @@ -39,8 +40,13 @@ int mutt_account_match (const ACCOUNT* a1, const ACCOUNT* a2) return 0; #ifdef USE_IMAP - if (a1->type == M_ACCT_TYPE_IMAP && ImapUser) - user = ImapUser; + if (a1->type == M_ACCT_TYPE_IMAP) + { + if (ImapUser) + user = ImapUser; + if (ImapLogin) + login = ImapLogin; + } #endif #ifdef USE_POP @@ -126,7 +132,7 @@ void mutt_account_tourl (ACCOUNT* account, ciss_url_t* url) url->pass = account->pass; } -/* mutt_account_getuser: retrieve username into ACCOUNT, if neccessary */ +/* mutt_account_getuser: retrieve username into ACCOUNT, if necessary */ int mutt_account_getuser (ACCOUNT* account) { char prompt[SHORT_STRING]; @@ -156,7 +162,27 @@ int mutt_account_getuser (ACCOUNT* account) return 0; } -/* mutt_account_getpass: fetch password into ACCOUNT, if neccessary */ +int mutt_account_getlogin (ACCOUNT* account) +{ + /* already set */ + if (account->flags & M_ACCT_LOGIN) + return 0; +#ifdef USE_IMAP + else if (account->type == M_ACCT_TYPE_IMAP) + { + if (ImapLogin) + strfcpy (account->login, ImapLogin, sizeof (account->login)); + else + strfcpy (account->login, ImapUser, sizeof (account->login)); + } +#endif + + account->flags |= M_ACCT_LOGIN; + + return 0; +} + +/* mutt_account_getpass: fetch password into ACCOUNT, if necessary */ int mutt_account_getpass (ACCOUNT* account) { char prompt[SHORT_STRING]; @@ -174,7 +200,7 @@ int mutt_account_getpass (ACCOUNT* account) else { snprintf (prompt, sizeof (prompt), _("Password for %s@%s: "), - account->user, account->host); + account->login, account->host); account->pass[0] = '\0'; if (mutt_get_password (prompt, account->pass, sizeof (account->pass))) return -1; diff --git a/account.h b/account.h index 145e5145d..e9fac082c 100644 --- a/account.h +++ b/account.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2000-3 Brendan Cully + * Copyright (C) 2000-5 Brendan Cully * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -32,14 +32,16 @@ enum }; /* account flags */ -#define M_ACCT_PORT (1<<0) -#define M_ACCT_USER (1<<1) -#define M_ACCT_PASS (1<<2) -#define M_ACCT_SSL (1<<3) +#define M_ACCT_PORT (1<<0) +#define M_ACCT_USER (1<<1) +#define M_ACCT_LOGIN (1<<2) +#define M_ACCT_PASS (1<<3) +#define M_ACCT_SSL (1<<4) typedef struct { char user[64]; + char login[64]; char pass[64]; char host[128]; unsigned short port; @@ -51,6 +53,7 @@ int mutt_account_match (const ACCOUNT* a1, const ACCOUNT* m2); int mutt_account_fromurl (ACCOUNT* account, ciss_url_t* url); void mutt_account_tourl (ACCOUNT* account, ciss_url_t* url); int mutt_account_getuser (ACCOUNT* account); +int mutt_account_getlogin (ACCOUNT* account); int mutt_account_getpass (ACCOUNT* account); void mutt_account_unsetpass (ACCOUNT* account); diff --git a/globals.h b/globals.h index 03c7d241f..1e570d314 100644 --- a/globals.h +++ b/globals.h @@ -57,6 +57,7 @@ WHERE char *ImapAuthenticators INITVAL (NULL); WHERE char *ImapDelimChars INITVAL (NULL); WHERE char *ImapHeaders; WHERE char *ImapHomeNamespace INITVAL (NULL); +WHERE char *ImapLogin INITVAL (NULL); WHERE char *ImapPass INITVAL (NULL); WHERE char *ImapUser INITVAL (NULL); #endif diff --git a/init.h b/init.h index 13d04eac6..66ca068dc 100644 --- a/init.h +++ b/init.h @@ -851,6 +851,13 @@ struct option_t MuttVars[] = { ** only subscribed folders or all folders. This can be toggled in the ** IMAP browser with the \fItoggle-subscribed\fP function. */ + { "imap_login", DT_STR, R_NONE, UL &ImapLogin, UL 0 }, + /* + ** .pp + ** Your login name on the IMAP server. + ** .pp + ** This variable defaults to the value of \fIimap_user\fP. + */ { "imap_pass", DT_STR, R_NONE, UL &ImapPass, UL 0 }, /* ** .pp @@ -889,7 +896,8 @@ struct option_t MuttVars[] = { { "imap_user", DT_STR, R_NONE, UL &ImapUser, UL 0 }, /* ** .pp - ** Your login name on the IMAP server. + ** The name of the user whose mail you intend to access on the IMAP + ** server. ** .pp ** This variable defaults to your user name on the local machine. */ diff --git a/mutt_sasl.c b/mutt_sasl.c index 435b4bd8b..cd5c1aa9e 100644 --- a/mutt_sasl.c +++ b/mutt_sasl.c @@ -334,12 +334,12 @@ sasl_callback_t* mutt_sasl_get_callbacks (ACCOUNT* account) callback = mutt_sasl_callbacks; - callback->id = SASL_CB_AUTHNAME; + callback->id = SASL_CB_USER; callback->proc = mutt_sasl_cb_authname; callback->context = account; callback++; - callback->id = SASL_CB_USER; + callback->id = SASL_CB_AUTHNAME; callback->proc = mutt_sasl_cb_authname; callback->context = account; callback++; @@ -450,8 +450,7 @@ static int mutt_sasl_cb_log (void* context, int priority, const char* message) return SASL_OK; } -/* mutt_sasl_cb_authname: callback to retrieve authname or user (mutt - * doesn't distinguish, even if some SASL plugins do) from ACCOUNT */ +/* mutt_sasl_cb_authname: callback to retrieve authname or user from ACCOUNT */ static int mutt_sasl_cb_authname (void* context, int id, const char** result, unsigned* len) { @@ -468,11 +467,19 @@ static int mutt_sasl_cb_authname (void* context, int id, const char** result, id == SASL_CB_AUTHNAME ? "authname" : "user", account->host, account->port)); - if (mutt_account_getuser (account)) - return SASL_FAIL; - - *result = account->user; - + if (id == SASL_CB_AUTHNAME) + { + if (mutt_account_getlogin (account)) + return SASL_FAIL; + *result = account->login; + } + else + { + if (mutt_account_getuser (account)) + return SASL_FAIL; + *result = account->user; + } + if (len) *len = strlen (*result); @@ -489,7 +496,7 @@ static int mutt_sasl_cb_pass (sasl_conn_t* conn, void* context, int id, return SASL_BADPARAM; dprint (2, (debugfile, - "mutt_sasl_cb_pass: getting password for %s@%s:%u\n", account->user, + "mutt_sasl_cb_pass: getting password for %s@%s:%u\n", account->login, account->host, account->port)); if (mutt_account_getpass (account))