1999-07-11 00:32:11 +00:00
|
|
|
/*
|
2019-04-29 07:21:51 -06:00
|
|
|
* SPDX-License-Identifier: ISC
|
|
|
|
*
|
2015-02-01 08:24:49 -07:00
|
|
|
* Copyright (c) 1999-2005, 2008, 2010-2015
|
2017-12-03 17:53:40 -07:00
|
|
|
* Todd C. Miller <Todd.Miller@sudo.ws>
|
1999-07-11 00:32:11 +00:00
|
|
|
*
|
2004-02-13 21:36:47 +00:00
|
|
|
* Permission to use, copy, modify, and distribute this software for any
|
|
|
|
* purpose with or without fee is hereby granted, provided that the above
|
|
|
|
* copyright notice and this permission notice appear in all copies.
|
1999-07-31 16:19:50 +00:00
|
|
|
*
|
2004-02-13 21:36:47 +00:00
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
|
|
|
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
|
|
|
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
|
|
|
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
|
|
|
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
|
|
|
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
|
|
|
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
2003-04-16 00:42:10 +00:00
|
|
|
*
|
|
|
|
* Sponsored in part by the Defense Advanced Research Projects
|
|
|
|
* Agency (DARPA) and Air Force Research Laboratory, Air Force
|
|
|
|
* Materiel Command, USAF, under agreement number F39502-99-1-0512.
|
1999-07-11 00:32:11 +00:00
|
|
|
*/
|
|
|
|
|
2018-10-26 08:39:09 -06:00
|
|
|
/*
|
|
|
|
* This is an open source non-commercial project. Dear PVS-Studio, please check it.
|
|
|
|
* PVS-Studio Static Code Analyzer for C, C++ and C#: http://www.viva64.com
|
|
|
|
*/
|
2018-10-21 08:46:05 -06:00
|
|
|
|
2004-11-19 18:39:14 +00:00
|
|
|
#include <config.h>
|
1999-07-11 00:32:11 +00:00
|
|
|
|
2015-05-21 11:07:13 -06:00
|
|
|
#ifdef HAVE_FWTK
|
|
|
|
|
2001-12-14 19:52:54 +00:00
|
|
|
#include <sys/types.h>
|
1999-07-11 00:32:11 +00:00
|
|
|
#include <stdio.h>
|
2015-06-19 14:29:27 -06:00
|
|
|
#include <stdlib.h>
|
2020-05-18 07:59:24 -06:00
|
|
|
#include <string.h>
|
2015-07-02 09:08:28 -06:00
|
|
|
#include <unistd.h>
|
1999-07-11 00:32:11 +00:00
|
|
|
#include <pwd.h>
|
|
|
|
|
1999-10-12 00:53:41 +00:00
|
|
|
#include <auth.h>
|
1999-07-11 00:32:11 +00:00
|
|
|
#include <firewall.h>
|
|
|
|
|
2010-03-14 19:58:47 -04:00
|
|
|
#include "sudoers.h"
|
1999-07-11 00:32:11 +00:00
|
|
|
#include "sudo_auth.h"
|
|
|
|
|
|
|
|
int
|
2011-11-13 11:46:39 -05:00
|
|
|
sudo_fwtk_init(struct passwd *pw, sudo_auth *auth)
|
1999-07-11 00:32:11 +00:00
|
|
|
{
|
|
|
|
static Cfg *confp; /* Configuration entry struct */
|
|
|
|
char resp[128]; /* Response from the server */
|
2019-12-22 08:48:16 -07:00
|
|
|
debug_decl(sudo_fwtk_init, SUDOERS_DEBUG_AUTH);
|
1999-07-11 00:32:11 +00:00
|
|
|
|
2021-09-21 20:05:35 -06:00
|
|
|
/* Only initialize once. */
|
|
|
|
if (auth->data != NULL)
|
|
|
|
debug_return_int(AUTH_SUCCESS);
|
|
|
|
|
1999-07-11 00:32:11 +00:00
|
|
|
if ((confp = cfg_read("sudo")) == (Cfg *)-1) {
|
2020-08-12 13:45:09 -06:00
|
|
|
sudo_warnx("%s", U_("unable to read fwtk config"));
|
2011-10-22 14:40:21 -04:00
|
|
|
debug_return_int(AUTH_FATAL);
|
1999-07-11 00:32:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (auth_open(confp)) {
|
2020-08-12 13:45:09 -06:00
|
|
|
sudo_warnx("%s", U_("unable to connect to authentication server"));
|
2011-10-22 14:40:21 -04:00
|
|
|
debug_return_int(AUTH_FATAL);
|
1999-07-11 00:32:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Get welcome message from auth server */
|
|
|
|
if (auth_recv(resp, sizeof(resp))) {
|
2020-08-12 13:45:09 -06:00
|
|
|
sudo_warnx("%s", U_("lost connection to authentication server"));
|
2011-10-22 14:40:21 -04:00
|
|
|
debug_return_int(AUTH_FATAL);
|
1999-07-11 00:32:11 +00:00
|
|
|
}
|
|
|
|
if (strncmp(resp, "Authsrv ready", 13) != 0) {
|
2014-06-27 09:30:52 -06:00
|
|
|
sudo_warnx(U_("authentication server error:\n%s"), resp);
|
2011-10-22 14:40:21 -04:00
|
|
|
debug_return_int(AUTH_FATAL);
|
1999-07-11 00:32:11 +00:00
|
|
|
}
|
2021-09-21 20:05:35 -06:00
|
|
|
auth->data = (void *) confp;
|
1999-07-11 00:32:11 +00:00
|
|
|
|
2011-10-22 14:40:21 -04:00
|
|
|
debug_return_int(AUTH_SUCCESS);
|
1999-07-11 00:32:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2015-09-07 06:06:08 -06:00
|
|
|
sudo_fwtk_verify(struct passwd *pw, char *prompt, sudo_auth *auth, struct sudo_conv_callback *callback)
|
1999-07-11 00:32:11 +00:00
|
|
|
{
|
2003-12-31 22:46:10 +00:00
|
|
|
char *pass; /* Password from the user */
|
2013-08-03 08:30:06 -06:00
|
|
|
char buf[SUDO_CONV_REPL_MAX + 12]; /* General prupose buffer */
|
1999-07-11 00:32:11 +00:00
|
|
|
char resp[128]; /* Response from the server */
|
2002-01-21 22:25:14 +00:00
|
|
|
int error;
|
2019-12-22 08:48:16 -07:00
|
|
|
debug_decl(sudo_fwtk_verify, SUDOERS_DEBUG_AUTH);
|
1999-07-11 00:32:11 +00:00
|
|
|
|
|
|
|
/* Send username to authentication server. */
|
1999-07-22 11:02:24 +00:00
|
|
|
(void) snprintf(buf, sizeof(buf), "authorize %s 'sudo'", pw->pw_name);
|
2004-01-15 20:13:47 +00:00
|
|
|
restart:
|
1999-07-11 00:32:11 +00:00
|
|
|
if (auth_send(buf) || auth_recv(resp, sizeof(resp))) {
|
2020-08-12 13:45:09 -06:00
|
|
|
sudo_warnx("%s", U_("lost connection to authentication server"));
|
2011-10-22 14:40:21 -04:00
|
|
|
debug_return_int(AUTH_FATAL);
|
1999-07-11 00:32:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Get the password/response from the user. */
|
|
|
|
if (strncmp(resp, "challenge ", 10) == 0) {
|
1999-07-22 11:02:24 +00:00
|
|
|
(void) snprintf(buf, sizeof(buf), "%s\nResponse: ", &resp[10]);
|
2018-01-22 12:18:48 -07:00
|
|
|
pass = auth_getpass(buf, SUDO_CONV_PROMPT_ECHO_OFF, callback);
|
2001-12-09 05:17:00 +00:00
|
|
|
if (pass && *pass == '\0') {
|
2016-01-27 15:36:50 -07:00
|
|
|
free(pass);
|
2010-03-14 19:58:47 -04:00
|
|
|
pass = auth_getpass("Response [echo on]: ",
|
2018-01-22 12:18:48 -07:00
|
|
|
SUDO_CONV_PROMPT_ECHO_ON, callback);
|
2000-10-30 03:45:11 +00:00
|
|
|
}
|
2004-01-15 20:13:47 +00:00
|
|
|
} else if (strncmp(resp, "chalnecho ", 10) == 0) {
|
2018-01-22 12:18:48 -07:00
|
|
|
pass = auth_getpass(&resp[10], SUDO_CONV_PROMPT_ECHO_OFF, callback);
|
1999-07-11 00:32:11 +00:00
|
|
|
} else if (strncmp(resp, "password", 8) == 0) {
|
2018-01-22 12:18:48 -07:00
|
|
|
pass = auth_getpass(prompt, SUDO_CONV_PROMPT_ECHO_OFF, callback);
|
2004-01-15 20:13:47 +00:00
|
|
|
} else if (strncmp(resp, "display ", 8) == 0) {
|
2019-08-26 19:30:11 -06:00
|
|
|
sudo_printf(SUDO_CONV_INFO_MSG|SUDO_CONV_PREFER_TTY, "%s\n", &resp[8]);
|
2020-10-30 10:15:30 -06:00
|
|
|
strlcpy(buf, "response noop", sizeof(buf));
|
2004-01-15 20:13:47 +00:00
|
|
|
goto restart;
|
1999-07-11 00:32:11 +00:00
|
|
|
} else {
|
2014-06-27 09:30:52 -06:00
|
|
|
sudo_warnx("%s", resp);
|
2011-10-22 14:40:21 -04:00
|
|
|
debug_return_int(AUTH_FATAL);
|
1999-07-11 00:32:11 +00:00
|
|
|
}
|
2001-12-09 05:17:00 +00:00
|
|
|
if (!pass) { /* ^C or error */
|
2011-10-22 14:40:21 -04:00
|
|
|
debug_return_int(AUTH_INTR);
|
2008-11-07 17:45:52 +00:00
|
|
|
}
|
1999-07-11 00:32:11 +00:00
|
|
|
|
|
|
|
/* Send the user's response to the server */
|
1999-07-22 11:02:24 +00:00
|
|
|
(void) snprintf(buf, sizeof(buf), "response '%s'", pass);
|
1999-07-11 00:32:11 +00:00
|
|
|
if (auth_send(buf) || auth_recv(resp, sizeof(resp))) {
|
2020-08-12 13:45:09 -06:00
|
|
|
sudo_warnx("%s", U_("lost connection to authentication server"));
|
2002-01-21 22:25:14 +00:00
|
|
|
error = AUTH_FATAL;
|
|
|
|
goto done;
|
1999-07-11 00:32:11 +00:00
|
|
|
}
|
|
|
|
|
2002-01-21 22:25:14 +00:00
|
|
|
if (strncmp(resp, "ok", 2) == 0) {
|
|
|
|
error = AUTH_SUCCESS;
|
|
|
|
goto done;
|
|
|
|
}
|
1999-07-11 00:32:11 +00:00
|
|
|
|
|
|
|
/* Main loop prints "Permission Denied" or insult. */
|
|
|
|
if (strcmp(resp, "Permission Denied.") != 0)
|
2014-06-27 09:30:52 -06:00
|
|
|
sudo_warnx("%s", resp);
|
2002-01-21 22:25:14 +00:00
|
|
|
error = AUTH_FAILURE;
|
|
|
|
done:
|
2020-08-10 19:24:32 -06:00
|
|
|
explicit_bzero(buf, sizeof(buf));
|
2020-08-10 19:24:33 -06:00
|
|
|
freezero(pass, strlen(pass));
|
2011-10-22 14:40:21 -04:00
|
|
|
debug_return_int(error);
|
1999-07-11 00:32:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2020-04-01 14:41:38 -06:00
|
|
|
sudo_fwtk_cleanup(struct passwd *pw, sudo_auth *auth, bool force)
|
1999-07-11 00:32:11 +00:00
|
|
|
{
|
2019-12-22 08:48:16 -07:00
|
|
|
debug_decl(sudo_fwtk_cleanup, SUDOERS_DEBUG_AUTH);
|
1999-07-11 00:32:11 +00:00
|
|
|
|
|
|
|
auth_close();
|
2011-10-22 14:40:21 -04:00
|
|
|
debug_return_int(AUTH_SUCCESS);
|
1999-07-11 00:32:11 +00:00
|
|
|
}
|
2015-05-21 11:07:13 -06:00
|
|
|
|
|
|
|
#endif /* HAVE_FWTK */
|