1 /* GNU Mailutils -- a suite of utilities for electronic mail
2 Copyright (C) 1999-2021 Free Software Foundation, Inc.
3
4 GNU Mailutils is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 3, or (at your option)
7 any later version.
8
9 GNU Mailutils is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
13
14 You should have received a copy of the GNU General Public License
15 along with GNU Mailutils. If not, see <http://www.gnu.org/licenses/>. */
16
17 #include "imap4d.h"
18
19 /*
20 6.2.2. LOGIN Command
21
22 Arguments: user name
23 password
24
25 Responses: no specific responses for this command
26
27 Result: OK - login completed, now in authenticated state
28 NO - login failure: user name or password rejected
29 BAD - command unknown or arguments invalid
30 */
31 int
imap4d_login(struct imap4d_session * session,struct imap4d_command * command,imap4d_tokbuf_t tok)32 imap4d_login (struct imap4d_session *session,
33 struct imap4d_command *command, imap4d_tokbuf_t tok)
34 {
35 char *username, *pass;
36 int rc;
37
38 if (login_disabled || session->tls_mode == tls_required)
39 return io_completion_response (command, RESP_NO, "Command disabled");
40
41 if (imap4d_tokbuf_argc (tok) != 4)
42 return io_completion_response (command, RESP_BAD, "Invalid arguments");
43
44 username = imap4d_tokbuf_getarg (tok, IMAP4_ARG_1);
45 pass = imap4d_tokbuf_getarg (tok, IMAP4_ARG_2);
46
47 auth_data = mu_get_auth_by_name (username);
48
49 if (auth_data == NULL)
50 {
51 mu_diag_output (MU_DIAG_INFO, _("user `%s' nonexistent"), username);
52 return io_completion_response (command, RESP_NO,
53 "User name or passwd rejected");
54 }
55
56 rc = mu_authenticate (auth_data, pass);
57 openlog (MU_LOG_TAG (), LOG_PID, mu_log_facility);
58 if (rc)
59 {
60 mu_diag_output (MU_DIAG_INFO, _("login failed: %s"), username);
61 return io_completion_response (command, RESP_NO,
62 "User name or passwd rejected");
63 }
64
65 if (imap4d_session_setup0 ())
66 return io_completion_response (command, RESP_NO,
67 "User name or passwd rejected");
68 return io_completion_response (command, RESP_OK, "Completed");
69 }
70
71