NeoMutt  2020-08-21-74-g346364
Teaching an old dog new tricks
DOXYGEN
auth_anon.c
Go to the documentation of this file.
1 
29 #include "config.h"
30 #include "private.h"
31 #include "mutt/lib.h"
32 #include "conn/lib.h"
33 #include "lib.h"
34 #include "auth.h"
35 #include "mutt_socket.h"
36 
42 enum ImapAuthRes imap_auth_anon(struct ImapAccountData *adata, const char *method)
43 {
44  int rc;
45 
46  if (!(adata->capabilities & IMAP_CAP_AUTH_ANONYMOUS))
47  return IMAP_AUTH_UNAVAIL;
48 
49  if (mutt_account_getuser(&adata->conn->account) < 0)
50  return IMAP_AUTH_FAILURE;
51 
52  if (adata->conn->account.user[0] != '\0')
53  return IMAP_AUTH_UNAVAIL;
54 
55  // L10N: (%s) is the method name, e.g. Anonymous, CRAM-MD5, GSSAPI, SASL
56  mutt_message(_("Authenticating (%s)..."), "anonymous");
57 
58  imap_cmd_start(adata, "AUTHENTICATE ANONYMOUS");
59 
60  do
61  {
62  rc = imap_cmd_step(adata);
63  } while (rc == IMAP_RES_CONTINUE);
64 
65  if (rc != IMAP_RES_RESPOND)
66  {
67  mutt_debug(LL_DEBUG1, "Invalid response from server\n");
68  goto bail;
69  }
70 
71  mutt_socket_send(adata->conn, "ZHVtbXkK\r\n"); /* base64 ("dummy") */
72 
73  do
74  {
75  rc = imap_cmd_step(adata);
76  } while (rc == IMAP_RES_CONTINUE);
77 
78  if (rc != IMAP_RES_OK)
79  {
80  mutt_debug(LL_DEBUG1, "Error receiving server response\n");
81  goto bail;
82  }
83 
84  if (imap_code(adata->buf))
85  return IMAP_AUTH_SUCCESS;
86 
87 bail:
88  // L10N: %s is the method name, e.g. Anonymous, CRAM-MD5, GSSAPI, SASL
89  mutt_error(_("%s authentication failed"), "anonymous");
90  return IMAP_AUTH_FAILURE;
91 }
#define IMAP_RES_RESPOND
+
Definition: private.h:58
int mutt_account_getuser(struct ConnAccount *cac)
Retrieve username into ConnAccount, if necessary.
Definition: connaccount.c:48
#define IMAP_RES_OK
<tag> OK ...
Definition: private.h:56
int imap_cmd_step(struct ImapAccountData *adata)
Reads server responses from an IMAP command.
Definition: command.c:1071
struct ConnAccount account
Account details: username, password, etc.
Definition: connection.h:36
#define mutt_socket_send(conn, buf)
Definition: mutt_socket.h:37
#define IMAP_CAP_AUTH_ANONYMOUS
AUTH=ANONYMOUS.
Definition: private.h:130
#define mutt_message(...)
Definition: logging.h:83
char user[128]
Username.
Definition: connaccount.h:55
IMAP authenticator multiplexor.
#define _(a)
Definition: message.h:28
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:1057
Authentication failed.
Definition: auth.h:39
Shared constants/structs that are private to IMAP.
enum ImapAuthRes imap_auth_anon(struct ImapAccountData *adata, const char *method)
Authenticate anonymously - Implements ImapAuth::authenticate()
Definition: auth_anon.c:42
ImapAuthRes
Results of IMAP Authentication.
Definition: auth.h:36
void * adata
Private data (for Mailbox backends)
Definition: account.h:43
ImapCapFlags capabilities
Definition: private.h:186
IMAP-specific Account data -.
Definition: private.h:170
Log at debug level 1.
Definition: logging.h:40
char * buf
Definition: private.h:190
#define mutt_error(...)
Definition: logging.h:84
Connection Library.
#define mutt_debug(LEVEL,...)
Definition: logging.h:81
NeoMutt connections.
Convenience wrapper for the library headers.
#define IMAP_RES_CONTINUE
* ...
Definition: private.h:57
Authentication successful.
Definition: auth.h:38
bool imap_code(const char *s)
Was the command successful.
Definition: command.c:1194
struct Connection * conn
Definition: private.h:172