NeoMutt  2021-02-05-666-ge300cd
Teaching an old dog new tricks
DOXYGEN
auth_anon.c File Reference

IMAP anonymous authentication method. More...

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

Go to the source code of this file.

Functions

enum ImapAuthRes imap_auth_anon (struct ImapAccountData *adata, const char *method)
 Authenticate anonymously - Implements ImapAuth::authenticate() More...
 

Detailed Description

IMAP anonymous 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_anon.c.

Function Documentation

◆ imap_auth_anon()

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

Authenticate anonymously - Implements ImapAuth::authenticate()

This is basically a stripped-down version of the cram-md5 method.

Definition at line 42 of file auth_anon.c.

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:47
#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:1079
struct ConnAccount account
Account details: username, password, etc.
Definition: connection.h:40
#define mutt_socket_send(conn, buf)
Definition: mutt_socket.h:37
#define mutt_error(...)
Definition: logging.h:88
#define IMAP_CAP_AUTH_ANONYMOUS
AUTH=ANONYMOUS.
Definition: private.h:130
char user[128]
Username.
Definition: connaccount.h:55
#define _(a)
Definition: message.h:28
Authentication method not permitted.
Definition: auth.h:41
int imap_cmd_start(struct ImapAccountData *adata, const char *cmdstr)
Given an IMAP command, send it to the server.
Definition: command.c:1065
Authentication failed.
Definition: auth.h:40
ImapCapFlags capabilities
Definition: adata.h:55
#define mutt_debug(LEVEL,...)
Definition: logging.h:85
Log at debug level 1.
Definition: logging.h:40
char * buf
Definition: adata.h:59
#define mutt_message(...)
Definition: logging.h:87
#define IMAP_RES_CONTINUE
* ...
Definition: private.h:57
Authentication successful.
Definition: auth.h:39
bool imap_code(const char *s)
Was the command successful.
Definition: command.c:1202
struct Connection * conn
Definition: adata.h:41
+ Here is the call graph for this function: