NeoMutt  2020-08-07-1-gab41a1
Teaching an old dog new tricks
DOXYGEN
auth_plain.c File Reference

IMAP plain authentication method. More...

#include "config.h"
#include "private.h"
#include "mutt/lib.h"
#include "conn/lib.h"
#include "auth.h"
#include "mutt_logging.h"
#include "mutt_socket.h"
+ Include dependency graph for auth_plain.c:

Go to the source code of this file.

Functions

enum ImapAuthRes imap_auth_plain (struct ImapAccountData *adata, const char *method)
 SASL PLAIN support - Implements ImapAuth::authenticate() More...
 

Detailed Description

IMAP plain authentication method.

Authors
  • Brendan Cully
  • Pietro Cerutti

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_plain.c.

Function Documentation

◆ imap_auth_plain()

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

SASL PLAIN support - Implements ImapAuth::authenticate()

Parameters
adataImap Account data
methodName of this authentication method
Return values
ImapAuthResResult, e.g. IMAP_AUTH_SUCCESS

Definition at line 44 of file auth_plain.c.

45 {
46  int rc = IMAP_RES_CONTINUE;
47  enum ImapAuthRes res = IMAP_AUTH_SUCCESS;
48  static const char auth_plain_cmd[] = "AUTHENTICATE PLAIN";
49  char buf[256] = { 0 };
50 
51  if (mutt_account_getuser(&adata->conn->account) < 0)
52  return IMAP_AUTH_FAILURE;
53  if (mutt_account_getpass(&adata->conn->account) < 0)
54  return IMAP_AUTH_FAILURE;
55 
56  mutt_message(_("Logging in..."));
57 
58  /* Prepare full AUTHENTICATE PLAIN message */
59  mutt_sasl_plain_msg(buf, sizeof(buf), auth_plain_cmd, adata->conn->account.user,
60  adata->conn->account.user, adata->conn->account.pass);
61 
62  if (adata->capabilities & IMAP_CAP_SASL_IR)
63  {
64  imap_cmd_start(adata, buf);
65  }
66  else
67  {
68  /* Split the message so we send AUTHENTICATE PLAIN first, and the
69  * credentials after the first command continuation request */
70  buf[sizeof(auth_plain_cmd) - 1] = '\0';
71  imap_cmd_start(adata, buf);
72  while (rc == IMAP_RES_CONTINUE)
73  {
74  rc = imap_cmd_step(adata);
75  }
76  if (rc == IMAP_RES_RESPOND)
77  {
78  mutt_str_cat(buf + sizeof(auth_plain_cmd),
79  sizeof(buf) - sizeof(auth_plain_cmd), "\r\n");
80  mutt_socket_send(adata->conn, buf + sizeof(auth_plain_cmd));
81  rc = IMAP_RES_CONTINUE;
82  }
83  }
84 
85  while (rc == IMAP_RES_CONTINUE)
86  {
87  rc = imap_cmd_step(adata);
88  }
89 
90  if (rc == IMAP_RES_BAD)
91  {
92  res = IMAP_AUTH_UNAVAIL;
93  }
94  else if (rc == IMAP_RES_NO)
95  {
96  mutt_error(_("Login failed"));
97  res = IMAP_AUTH_FAILURE;
98  }
99 
101  return res;
102 }
#define IMAP_RES_RESPOND
+
Definition: private.h:57
int mutt_account_getuser(struct ConnAccount *cac)
Retrieve username into ConnAccount, if necessary.
Definition: connaccount.c:48
int imap_cmd_step(struct ImapAccountData *adata)
Reads server responses from an IMAP command.
Definition: command.c:1076
struct ConnAccount account
Account details: username, password, etc.
Definition: connection.h:36
#define mutt_socket_send(conn, buf)
Definition: mutt_socket.h:37
#define mutt_message(...)
Definition: logging.h:83
#define IMAP_CAP_SASL_IR
SASL initial response draft.
Definition: private.h:134
char user[128]
Username.
Definition: connaccount.h:55
#define _(a)
Definition: message.h:28
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:56
Authentication method not permitted.
Definition: auth.h:40
int imap_cmd_start(struct ImapAccountData *adata, const char *cmdstr)
Given an IMAP command, send it to the server.
Definition: command.c:1062
char pass[256]
Password.
Definition: connaccount.h:56
Authentication failed.
Definition: auth.h:39
void mutt_clear_error(void)
Clear the message line (bottom line of screen)
Definition: mutt_logging.c:113
ImapAuthRes
Results of IMAP Authentication.
Definition: auth.h:36
ImapCapFlags capabilities
Definition: private.h:185
#define IMAP_RES_NO
<tag> NO ...
Definition: private.h:53
char * mutt_str_cat(char *buf, size_t buflen, const char *s)
Concatenate two strings.
Definition: string.c:390
#define mutt_error(...)
Definition: logging.h:84
#define IMAP_RES_CONTINUE
* ...
Definition: private.h:56
Authentication successful.
Definition: auth.h:38
int mutt_account_getpass(struct ConnAccount *cac)
Fetch password into ConnAccount, if necessary.
Definition: connaccount.c:111
struct Connection * conn
Definition: private.h:171
#define IMAP_RES_BAD
<tag> BAD ...
Definition: private.h:54
+ Here is the call graph for this function: