NeoMutt  2022-04-29-249-gaae397
Teaching an old dog new tricks
DOXYGEN
auth_login.c
Go to the documentation of this file.
1
29#include "config.h"
30#include <stdbool.h>
31#include <stdio.h>
32#include "private.h"
33#include "mutt/lib.h"
34#include "config/lib.h"
35#include "core/lib.h"
36#include "conn/lib.h"
37#include "adata.h"
38#include "auth.h"
39#include "mutt_logging.h"
40
44enum ImapAuthRes imap_auth_login(struct ImapAccountData *adata, const char *method)
45{
46 char q_user[256], q_pass[256];
47 char buf[1024] = { 0 };
48
50 {
51 mutt_message(_("LOGIN disabled on this server"));
52 return IMAP_AUTH_UNAVAIL;
53 }
54
55 if (mutt_account_getuser(&adata->conn->account) < 0)
56 return IMAP_AUTH_FAILURE;
57 if (mutt_account_getpass(&adata->conn->account) < 0)
58 return IMAP_AUTH_FAILURE;
59
60 mutt_message(_("Logging in..."));
61
62 imap_quote_string(q_user, sizeof(q_user), adata->conn->account.user, false);
63 imap_quote_string(q_pass, sizeof(q_pass), adata->conn->account.pass, false);
64
65 /* don't print the password unless we're at the ungodly debugging level
66 * of 5 or higher */
67
68 const short c_debug_level = cs_subset_number(NeoMutt->sub, "debug_level");
69 if (c_debug_level < IMAP_LOG_PASS)
70 mutt_debug(LL_DEBUG2, "Sending LOGIN command for %s\n", adata->conn->account.user);
71
72 snprintf(buf, sizeof(buf), "LOGIN %s %s", q_user, q_pass);
73 if (imap_exec(adata, buf, IMAP_CMD_PASS) == IMAP_EXEC_SUCCESS)
74 {
76 return IMAP_AUTH_SUCCESS;
77 }
78
79 mutt_error(_("Login failed"));
80 return IMAP_AUTH_FAILURE;
81}
IMAP authenticator multiplexor.
ImapAuthRes
Results of IMAP Authentication.
Definition: auth.h:38
@ IMAP_AUTH_FAILURE
Authentication failed.
Definition: auth.h:40
@ IMAP_AUTH_SUCCESS
Authentication successful.
Definition: auth.h:39
@ IMAP_AUTH_UNAVAIL
Authentication method not permitted.
Definition: auth.h:41
enum ImapAuthRes imap_auth_login(struct ImapAccountData *adata, const char *method)
Plain LOGIN support - Implements ImapAuth::authenticate()
Definition: auth_login.c:44
short cs_subset_number(const struct ConfigSubset *sub, const char *name)
Get a number config item by name.
Definition: helpers.c:169
Convenience wrapper for the config headers.
Connection Library.
int mutt_account_getpass(struct ConnAccount *cac)
Fetch password into ConnAccount, if necessary.
Definition: connaccount.c:130
int mutt_account_getuser(struct ConnAccount *cac)
Retrieve username into ConnAccount, if necessary.
Definition: connaccount.c:50
Convenience wrapper for the core headers.
#define mutt_error(...)
Definition: logging.h:87
#define mutt_message(...)
Definition: logging.h:86
#define mutt_debug(LEVEL,...)
Definition: logging.h:84
int imap_exec(struct ImapAccountData *adata, const char *cmdstr, ImapCmdFlags flags)
Execute a command and wait for the response from the server.
Definition: command.c:1247
void imap_quote_string(char *dest, size_t dlen, const char *src, bool quote_backtick)
Quote string according to IMAP rules.
Definition: util.c:837
#define IMAP_CMD_PASS
Command contains a password. Suppress logging.
Definition: private.h:74
@ IMAP_EXEC_SUCCESS
Imap command executed or queued successfully.
Definition: private.h:84
#define IMAP_LOG_PASS
Definition: private.h:51
#define IMAP_CAP_LOGINDISABLED
RFC2595: LOGINDISABLED.
Definition: private.h:134
@ LL_DEBUG2
Log at debug level 2.
Definition: logging.h:41
Convenience wrapper for the library headers.
#define _(a)
Definition: message.h:28
void mutt_clear_error(void)
Clear the message line (bottom line of screen)
Definition: mutt_logging.c:74
NeoMutt Logging.
Pop-specific Account data.
GUI display the mailboxes in a side panel.
char user[128]
Username.
Definition: connaccount.h:56
char pass[256]
Password.
Definition: connaccount.h:57
struct ConnAccount account
Account details: username, password, etc.
Definition: connection.h:50
IMAP-specific Account data -.
Definition: adata.h:40
ImapCapFlags capabilities
Capability flags.
Definition: adata.h:55
struct Connection * conn
Connection to IMAP server.
Definition: adata.h:41
Container for Accounts, Notifications.
Definition: neomutt.h:37
struct ConfigSubset * sub
Inherited config items.
Definition: neomutt.h:39