/src/neomutt/imap/auth_login.c
Line | Count | Source (jump to first uncovered line) |
1 | | /** |
2 | | * @file |
3 | | * IMAP login authentication method |
4 | | * |
5 | | * @authors |
6 | | * Copyright (C) 1999-2001,2005,2009 Brendan Cully <brendan@kublai.com> |
7 | | * |
8 | | * @copyright |
9 | | * This program is free software: you can redistribute it and/or modify it under |
10 | | * the terms of the GNU General Public License as published by the Free Software |
11 | | * Foundation, either version 2 of the License, or (at your option) any later |
12 | | * version. |
13 | | * |
14 | | * This program is distributed in the hope that it will be useful, but WITHOUT |
15 | | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
16 | | * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more |
17 | | * details. |
18 | | * |
19 | | * You should have received a copy of the GNU General Public License along with |
20 | | * this program. If not, see <http://www.gnu.org/licenses/>. |
21 | | */ |
22 | | |
23 | | /** |
24 | | * @page imap_auth_login Login authentication |
25 | | * |
26 | | * IMAP login authentication method |
27 | | */ |
28 | | |
29 | | #include "config.h" |
30 | | #include <stdbool.h> |
31 | | #include <stdio.h> |
32 | | #include "private.h" |
33 | | #include "mutt/lib.h" |
34 | | #include "config/lib.h" |
35 | | #include "core/lib.h" |
36 | | #include "conn/lib.h" |
37 | | #include "adata.h" |
38 | | #include "auth.h" |
39 | | #include "mutt_logging.h" |
40 | | |
41 | | /** |
42 | | * imap_auth_login - Plain LOGIN support - Implements ImapAuth::authenticate() |
43 | | */ |
44 | | enum ImapAuthRes imap_auth_login(struct ImapAccountData *adata, const char *method) |
45 | 0 | { |
46 | 0 | char q_user[256], q_pass[256]; |
47 | 0 | char buf[1024] = { 0 }; |
48 | |
|
49 | 0 | if ((adata->capabilities & IMAP_CAP_LOGINDISABLED)) |
50 | 0 | { |
51 | 0 | mutt_message(_("LOGIN disabled on this server")); |
52 | 0 | return IMAP_AUTH_UNAVAIL; |
53 | 0 | } |
54 | | |
55 | 0 | if (mutt_account_getuser(&adata->conn->account) < 0) |
56 | 0 | return IMAP_AUTH_FAILURE; |
57 | 0 | if (mutt_account_getpass(&adata->conn->account) < 0) |
58 | 0 | return IMAP_AUTH_FAILURE; |
59 | | |
60 | 0 | mutt_message(_("Logging in...")); |
61 | |
|
62 | 0 | imap_quote_string(q_user, sizeof(q_user), adata->conn->account.user, false); |
63 | 0 | imap_quote_string(q_pass, sizeof(q_pass), adata->conn->account.pass, false); |
64 | | |
65 | | /* don't print the password unless we're at the ungodly debugging level |
66 | | * of 5 or higher */ |
67 | |
|
68 | 0 | const short c_debug_level = cs_subset_number(NeoMutt->sub, "debug_level"); |
69 | 0 | if (c_debug_level < IMAP_LOG_PASS) |
70 | 0 | mutt_debug(LL_DEBUG2, "Sending LOGIN command for %s\n", adata->conn->account.user); |
71 | |
|
72 | 0 | snprintf(buf, sizeof(buf), "LOGIN %s %s", q_user, q_pass); |
73 | 0 | if (imap_exec(adata, buf, IMAP_CMD_PASS) == IMAP_EXEC_SUCCESS) |
74 | 0 | { |
75 | 0 | mutt_clear_error(); |
76 | 0 | return IMAP_AUTH_SUCCESS; |
77 | 0 | } |
78 | | |
79 | 0 | mutt_error(_("Login failed")); |
80 | 0 | return IMAP_AUTH_FAILURE; |
81 | 0 | } |