NeoMutt
Teaching an old dog new tricks
DOXYGEN
Loading...
Searching...
No Matches
auth_plain.c
Go to the documentation of this file.
1
30#include "config.h"
31#include "private.h"
32#include "mutt/lib.h"
33#include "conn/lib.h"
34#include "adata.h"
35#include "auth.h"
36#include "mutt_logging.h"
37
41enum ImapAuthRes imap_auth_plain(struct ImapAccountData *adata, const char *method)
42{
43 int rc = IMAP_RES_CONTINUE;
45 static const char auth_plain_cmd[] = "AUTHENTICATE PLAIN";
46 char buf[256] = { 0 };
47
48 if (mutt_account_getuser(&adata->conn->account) < 0)
49 return IMAP_AUTH_FAILURE;
50 if (mutt_account_getpass(&adata->conn->account) < 0)
51 return IMAP_AUTH_FAILURE;
52
53 mutt_message(_("Logging in..."));
54
55 /* Prepare full AUTHENTICATE PLAIN message */
56 mutt_sasl_plain_msg(buf, sizeof(buf), auth_plain_cmd, adata->conn->account.user,
57 adata->conn->account.user, adata->conn->account.pass);
58
59 if (adata->capabilities & IMAP_CAP_SASL_IR)
60 {
61 imap_cmd_start(adata, buf);
62 }
63 else
64 {
65 /* Split the message so we send AUTHENTICATE PLAIN first, and the
66 * credentials after the first command continuation request */
67 buf[sizeof(auth_plain_cmd) - 1] = '\0';
68 imap_cmd_start(adata, buf);
69 while (rc == IMAP_RES_CONTINUE)
70 {
71 rc = imap_cmd_step(adata);
72 }
73 if (rc == IMAP_RES_RESPOND)
74 {
75 mutt_str_cat(buf + sizeof(auth_plain_cmd),
76 sizeof(buf) - sizeof(auth_plain_cmd), "\r\n");
77 mutt_socket_send(adata->conn, buf + sizeof(auth_plain_cmd));
79 }
80 }
81
82 while (rc == IMAP_RES_CONTINUE)
83 {
84 rc = imap_cmd_step(adata);
85 }
86
87 if (rc == IMAP_RES_BAD)
88 {
90 }
91 else if (rc == IMAP_RES_NO)
92 {
93 mutt_error(_("Login failed"));
95 }
96
98 return res;
99}
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_plain(struct ImapAccountData *adata, const char *method)
SASL PLAIN support - Implements ImapAuth::authenticate()
Definition: auth_plain.c:41
Connection Library.
int mutt_account_getpass(struct ConnAccount *cac)
Fetch password into ConnAccount, if necessary.
Definition: connaccount.c:129
int mutt_account_getuser(struct ConnAccount *cac)
Retrieve username into ConnAccount, if necessary.
Definition: connaccount.c:50
#define mutt_error(...)
Definition: logging2.h:92
#define mutt_message(...)
Definition: logging2.h:91
int imap_cmd_start(struct ImapAccountData *adata, const char *cmdstr)
Given an IMAP command, send it to the server.
Definition: command.c:1115
int imap_cmd_step(struct ImapAccountData *adata)
Reads server responses from an IMAP command.
Definition: command.c:1129
#define IMAP_RES_RESPOND
+
Definition: private.h:57
#define IMAP_RES_NO
<tag> NO ...
Definition: private.h:53
#define IMAP_CAP_SASL_IR
SASL initial response draft.
Definition: private.h:134
#define IMAP_RES_CONTINUE
* ...
Definition: private.h:56
#define IMAP_RES_BAD
<tag> BAD ...
Definition: private.h:54
Convenience wrapper for the library headers.
#define _(a)
Definition: message.h:28
char * mutt_str_cat(char *buf, size_t buflen, const char *s)
Concatenate two strings.
Definition: string.c:266
void mutt_clear_error(void)
Clear the message line (bottom line of screen)
Definition: mutt_logging.c:73
NeoMutt Logging.
Pop-specific Account data.
size_t mutt_sasl_plain_msg(char *buf, size_t buflen, const char *cmd, const char *authz, const char *user, const char *pass)
Construct a base64 encoded SASL PLAIN message.
Definition: sasl_plain.c:55
GUI display the mailboxes in a side panel.
#define mutt_socket_send(conn, buf)
Definition: socket.h:59
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