NeoMutt  2020-06-26-250-g349c94
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 "lib.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()

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

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

Definition at line 45 of file auth_anon.c.

46 {
47  int rc;
48 
49  if (!(adata->capabilities & IMAP_CAP_AUTH_ANONYMOUS))
50  return IMAP_AUTH_UNAVAIL;
51 
52  if (mutt_account_getuser(&adata->conn->account) < 0)
53  return IMAP_AUTH_FAILURE;
54 
55  if (adata->conn->account.user[0] != '\0')
56  return IMAP_AUTH_UNAVAIL;
57 
58  // L10N: (%s) is the method name, e.g. Anonymous, CRAM-MD5, GSSAPI, SASL
59  mutt_message(_("Authenticating (%s)..."), "anonymous");
60 
61  imap_cmd_start(adata, "AUTHENTICATE ANONYMOUS");
62 
63  do
64  {
65  rc = imap_cmd_step(adata);
66  } while (rc == IMAP_RES_CONTINUE);
67 
68  if (rc != IMAP_RES_RESPOND)
69  {
70  mutt_debug(LL_DEBUG1, "Invalid response from server\n");
71  goto bail;
72  }
73 
74  mutt_socket_send(adata->conn, "ZHVtbXkK\r\n"); /* base64 ("dummy") */
75 
76  do
77  {
78  rc = imap_cmd_step(adata);
79  } while (rc == IMAP_RES_CONTINUE);
80 
81  if (rc != IMAP_RES_OK)
82  {
83  mutt_debug(LL_DEBUG1, "Error receiving server response\n");
84  goto bail;
85  }
86 
87  if (imap_code(adata->buf))
88  return IMAP_AUTH_SUCCESS;
89 
90 bail:
91  // L10N: %s is the method name, e.g. Anonymous, CRAM-MD5, GSSAPI, SASL
92  mutt_error(_("%s authentication failed"), "anonymous");
93  return IMAP_AUTH_FAILURE;
94 }
#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
#define IMAP_RES_OK
<tag> OK ...
Definition: private.h:55
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 IMAP_CAP_AUTH_ANONYMOUS
AUTH=ANONYMOUS.
Definition: private.h:129
#define mutt_message(...)
Definition: logging.h:83
char user[128]
Username.
Definition: connaccount.h:55
#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:1062
Authentication failed.
Definition: auth.h:39
ImapCapFlags capabilities
Definition: private.h:185
Log at debug level 1.
Definition: logging.h:40
char * buf
Definition: private.h:189
#define mutt_error(...)
Definition: logging.h:84
#define mutt_debug(LEVEL,...)
Definition: logging.h:81
#define IMAP_RES_CONTINUE
* ...
Definition: private.h:56
Authentication successful.
Definition: auth.h:38
bool imap_code(const char *s)
Was the command successful.
Definition: command.c:1199
struct Connection * conn
Definition: private.h:171
+ Here is the call graph for this function: