fclose -> m_fclose
[apps/madmutt.git] / imap / auth_anon.c
1 /*
2  * Copyright notice from original mutt:
3  * Copyright (C) 1999-2000 Brendan Cully <brendan@kublai.com>
4  *
5  * This file is part of mutt-ng, see http://www.muttng.org/.
6  * It's licensed under the GNU General Public License,
7  * please see the file GPL in the top level source directory.
8  */
9
10 /* IMAP login/authentication code */
11
12 #include <lib-lib/lib-lib.h>
13
14 #include "mutt.h"
15 #include "imap_private.h"
16 #include "auth.h"
17
18 /* this is basically a stripped-down version of the cram-md5 method. */
19 imap_auth_res_t imap_auth_anon (IMAP_DATA * idata, const char *method __attribute__ ((unused)))
20 {
21   int rc;
22
23   if (!mutt_bit_isset (idata->capabilities, AUTH_ANON))
24     return IMAP_AUTH_UNAVAIL;
25
26   if (mutt_account_getuser (&idata->conn->account))
27     return IMAP_AUTH_FAILURE;
28
29   if (idata->conn->account.user[0] != '\0')
30     return IMAP_AUTH_UNAVAIL;
31
32   mutt_message _("Authenticating (anonymous)...");
33
34   imap_cmd_start (idata, "AUTHENTICATE ANONYMOUS");
35
36   do
37     rc = imap_cmd_step (idata);
38   while (rc == IMAP_CMD_CONTINUE);
39
40   if (rc != IMAP_CMD_RESPOND) {
41     goto bail;
42   }
43
44   mutt_socket_write (idata->conn, "ZHVtbXkK\r\n");      /* base64 ("dummy") */
45
46   do
47     rc = imap_cmd_step (idata);
48   while (rc == IMAP_CMD_CONTINUE);
49
50   if (rc != IMAP_CMD_OK) {
51     goto bail;
52   }
53
54   if (imap_code (idata->cmd.buf))
55     return IMAP_AUTH_SUCCESS;
56
57 bail:
58   mutt_error _("Anonymous authentication failed.");
59   mutt_sleep (2);
60   return IMAP_AUTH_FAILURE;
61 }