1999-07-11 09:37:19 +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, 2007, 2010-2015
|
2017-12-03 17:53:40 -07:00
|
|
|
* Todd C. Miller <Todd.Miller@sudo.ws>
|
1999-07-11 09:37:19 +00:00
|
|
|
*
|
2004-02-13 21:36:49 +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.
|
|
|
|
*
|
|
|
|
* 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 09:37:19 +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 09:37:19 +00:00
|
|
|
|
2015-05-21 11:07:13 -06:00
|
|
|
#ifdef HAVE_SIA_SES_INIT
|
|
|
|
|
2001-12-14 19:52:54 +00:00
|
|
|
#include <sys/types.h>
|
1999-07-11 09:37:19 +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 09:37:19 +00:00
|
|
|
#include <pwd.h>
|
2014-09-27 10:16:31 -06:00
|
|
|
#include <signal.h>
|
1999-07-11 09:37:19 +00:00
|
|
|
#include <siad.h>
|
|
|
|
|
2010-03-14 19:58:47 -04:00
|
|
|
#include "sudoers.h"
|
1999-07-11 10:43:42 +00:00
|
|
|
#include "sudo_auth.h"
|
1999-07-11 09:37:19 +00:00
|
|
|
|
2011-04-26 09:51:34 -04:00
|
|
|
static char **sudo_argv;
|
|
|
|
static int sudo_argc;
|
1999-07-11 09:37:19 +00:00
|
|
|
|
|
|
|
int
|
2011-11-13 11:46:39 -05:00
|
|
|
sudo_sia_setup(struct passwd *pw, char **promptp, sudo_auth *auth)
|
1999-07-11 09:37:19 +00:00
|
|
|
{
|
2015-10-06 10:25:53 -06:00
|
|
|
SIAENTITY *siah;
|
2011-04-26 09:51:34 -04:00
|
|
|
int i;
|
2019-12-22 08:48:16 -07:00
|
|
|
debug_decl(sudo_sia_setup, SUDOERS_DEBUG_AUTH);
|
1999-07-11 09:37:19 +00:00
|
|
|
|
2011-04-26 09:51:34 -04:00
|
|
|
/* Rebuild argv for sia_ses_init() */
|
|
|
|
sudo_argc = NewArgc + 1;
|
2015-05-20 10:59:03 -06:00
|
|
|
sudo_argv = reallocarray(NULL, sudo_argc + 1, sizeof(char *));
|
|
|
|
if (sudo_argv == NULL) {
|
2015-06-17 06:49:59 -06:00
|
|
|
log_warningx(0, N_("unable to allocate memory"));
|
2015-05-20 10:59:03 -06:00
|
|
|
debug_return_int(AUTH_FATAL);
|
|
|
|
}
|
2011-04-26 09:51:34 -04:00
|
|
|
sudo_argv[0] = "sudo";
|
|
|
|
for (i = 0; i < NewArgc; i++)
|
|
|
|
sudo_argv[i + 1] = NewArgv[i];
|
|
|
|
sudo_argv[sudo_argc] = NULL;
|
|
|
|
|
2015-10-06 10:25:53 -06:00
|
|
|
/* We don't let SIA prompt the user for input. */
|
|
|
|
if (sia_ses_init(&siah, sudo_argc, sudo_argv, NULL, pw->pw_name, user_ttypath, 0, NULL) != SIASUCCESS) {
|
2014-05-02 20:54:01 -06:00
|
|
|
log_warning(0, N_("unable to initialize SIA session"));
|
2011-10-22 14:40:21 -04:00
|
|
|
debug_return_int(AUTH_FATAL);
|
1999-07-11 09:37:19 +00:00
|
|
|
}
|
|
|
|
|
2015-10-06 10:25:53 -06:00
|
|
|
auth->data = siah;
|
2011-10-22 14:40:21 -04:00
|
|
|
debug_return_int(AUTH_SUCCESS);
|
1999-07-11 09:37:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2015-10-06 10:25:53 -06:00
|
|
|
sudo_sia_verify(struct passwd *pw, char *prompt, sudo_auth *auth,
|
|
|
|
struct sudo_conv_callback *callback)
|
1999-07-11 09:37:19 +00:00
|
|
|
{
|
2015-10-06 10:25:53 -06:00
|
|
|
SIAENTITY *siah = auth->data;
|
|
|
|
char *pass;
|
|
|
|
int rc;
|
2019-12-22 08:48:16 -07:00
|
|
|
debug_decl(sudo_sia_verify, SUDOERS_DEBUG_AUTH);
|
1999-07-11 10:43:42 +00:00
|
|
|
|
2015-10-06 10:25:53 -06:00
|
|
|
/* Get password, return AUTH_INTR if we got ^C */
|
2018-01-22 12:18:48 -07:00
|
|
|
pass = auth_getpass(prompt, SUDO_CONV_PROMPT_ECHO_OFF, callback);
|
2015-10-06 10:25:53 -06:00
|
|
|
if (pass == NULL)
|
|
|
|
debug_return_int(AUTH_INTR);
|
|
|
|
|
|
|
|
/* Check password and zero out plaintext copy. */
|
|
|
|
rc = sia_ses_authent(NULL, pass, siah);
|
2020-08-10 19:24:33 -06:00
|
|
|
freezero(pass, strlen(pass));
|
1999-07-11 09:37:19 +00:00
|
|
|
|
2015-10-06 10:25:53 -06:00
|
|
|
if (rc == SIASUCCESS)
|
2011-10-22 14:40:21 -04:00
|
|
|
debug_return_int(AUTH_SUCCESS);
|
2015-10-06 10:25:53 -06:00
|
|
|
if (ISSET(rc, SIASTOP))
|
|
|
|
debug_return_int(AUTH_FATAL);
|
|
|
|
debug_return_int(AUTH_FAILURE);
|
1999-07-11 09:37:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2020-04-01 14:41:38 -06:00
|
|
|
sudo_sia_cleanup(struct passwd *pw, sudo_auth *auth, bool force)
|
1999-07-11 09:37:19 +00:00
|
|
|
{
|
2015-10-06 10:25:53 -06:00
|
|
|
SIAENTITY *siah = auth->data;
|
2019-12-22 08:48:16 -07:00
|
|
|
debug_decl(sudo_sia_cleanup, SUDOERS_DEBUG_AUTH);
|
1999-07-11 09:37:19 +00:00
|
|
|
|
|
|
|
(void) sia_ses_release(&siah);
|
2015-10-06 10:25:53 -06:00
|
|
|
auth->data = NULL;
|
2015-05-20 10:59:03 -06:00
|
|
|
free(sudo_argv);
|
2011-10-22 14:40:21 -04:00
|
|
|
debug_return_int(AUTH_SUCCESS);
|
1999-07-11 09:37:19 +00:00
|
|
|
}
|
2015-05-21 11:07:13 -06:00
|
|
|
|
2015-10-06 10:25:53 -06:00
|
|
|
int
|
|
|
|
sudo_sia_begin_session(struct passwd *pw, char **user_envp[], sudo_auth *auth)
|
|
|
|
{
|
|
|
|
SIAENTITY *siah;
|
|
|
|
int status = AUTH_FATAL;
|
2019-12-22 08:48:16 -07:00
|
|
|
debug_decl(sudo_sia_begin_session, SUDOERS_DEBUG_AUTH);
|
2015-10-06 10:25:53 -06:00
|
|
|
|
|
|
|
/* Re-init sia for the target user's session. */
|
|
|
|
if (sia_ses_init(&siah, NewArgc, NewArgv, NULL, pw->pw_name, user_ttypath, 0, NULL) != SIASUCCESS) {
|
|
|
|
log_warning(0, N_("unable to initialize SIA session"));
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (sia_make_entity_pwd(pw, siah) != SIASUCCESS) {
|
|
|
|
sudo_warn("sia_make_entity_pwd");
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
|
|
|
status = AUTH_FAILURE; /* no more fatal errors. */
|
|
|
|
|
|
|
|
siah->authtype = SIA_A_NONE;
|
|
|
|
if (sia_ses_estab(sia_collect_trm, siah) != SIASUCCESS) {
|
|
|
|
sudo_warn("sia_ses_estab");
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (sia_ses_launch(sia_collect_trm, siah) != SIASUCCESS) {
|
|
|
|
sudo_warn("sia_ses_launch");
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
|
|
|
status = AUTH_SUCCESS;
|
|
|
|
|
|
|
|
done:
|
|
|
|
(void) sia_ses_release(&siah);
|
|
|
|
debug_return_int(status);
|
|
|
|
}
|
|
|
|
|
2015-05-21 11:07:13 -06:00
|
|
|
#endif /* HAVE_SIA_SES_INIT */
|