NeoMutt  2023-05-17-56-ga67199
Teaching an old dog new tricks
DOXYGEN
auth_login.c File Reference

IMAP login authentication method. More...

#include "config.h"
#include <stdbool.h>
#include <stdio.h>
#include "private.h"
#include "mutt/lib.h"
#include "config/lib.h"
#include "core/lib.h"
#include "conn/lib.h"
#include "adata.h"
#include "auth.h"
#include "mutt_logging.h"
+ Include dependency graph for auth_login.c:

Go to the source code of this file.

Functions

enum ImapAuthRes imap_auth_login (struct ImapAccountData *adata, const char *method)
 Plain LOGIN support - Implements ImapAuth::authenticate() More...
 

Detailed Description

IMAP login authentication method.

Authors
  • Brendan Cully

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see http://www.gnu.org/licenses/.

Definition in file auth_login.c.

Function Documentation

◆ imap_auth_login()

enum ImapAuthRes imap_auth_login ( struct ImapAccountData adata,
const char *  method 
)

Plain LOGIN support - Implements ImapAuth::authenticate()

Definition at line 44 of file auth_login.c.

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_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
short cs_subset_number(const struct ConfigSubset *sub, const char *name)
Get a number config item by name.
Definition: helpers.c:169
int mutt_account_getpass(struct ConnAccount *cac)
Fetch password into ConnAccount, if necessary.
Definition: connaccount.c:128
int mutt_account_getuser(struct ConnAccount *cac)
Retrieve username into ConnAccount, if necessary.
Definition: connaccount.c:49
#define mutt_error(...)
Definition: logging2.h:90
#define mutt_message(...)
Definition: logging2.h:89
#define mutt_debug(LEVEL,...)
Definition: logging2.h:87
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:1284
void imap_quote_string(char *dest, size_t dlen, const char *src, bool quote_backtick)
Quote string according to IMAP rules.
Definition: util.c:832
#define IMAP_CMD_PASS
Command contains a password. Suppress logging.
Definition: private.h:72
@ IMAP_EXEC_SUCCESS
Imap command executed or queued successfully.
Definition: private.h:82
#define IMAP_LOG_PASS
Definition: private.h:50
#define IMAP_CAP_LOGINDISABLED
RFC2595: LOGINDISABLED.
Definition: private.h:132
@ LL_DEBUG2
Log at debug level 2.
Definition: logging2.h:44
#define _(a)
Definition: message.h:28
void mutt_clear_error(void)
Clear the message line (bottom line of screen)
Definition: mutt_logging.c:73
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
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
+ Here is the call graph for this function: