From f24dacdee2837a5cde9efa08e92e55dc9c2fcc53 Mon Sep 17 00:00:00 2001 From: "Todd C. Miller" Date: Sun, 29 Mar 2020 05:05:08 -0600 Subject: [PATCH] Create files for check_iolog_plugin in the build dir, not src dir. --- plugins/sudoers/Makefile.in | 5 +- .../regress/iolog_plugin/check_iolog_plugin.c | 53 +++++++++++++------ 2 files changed, 41 insertions(+), 17 deletions(-) diff --git a/plugins/sudoers/Makefile.in b/plugins/sudoers/Makefile.in index 00259810a..af584b3a7 100644 --- a/plugins/sudoers/Makefile.in +++ b/plugins/sudoers/Makefile.in @@ -1,7 +1,7 @@ # # SPDX-License-Identifier: ISC # -# Copyright (c) 1996, 1998-2005, 2007-2018 +# Copyright (c) 1996, 1998-2005, 2007-2020 # Todd C. Miller # # Permission to use, copy, modify, and distribute this software for any @@ -468,7 +468,8 @@ check: $(TEST_PROGS) visudo testsudoers cvtsudoers ./check_fill || rval=`expr $$rval + $$?`; \ ./check_gentime || rval=`expr $$rval + $$?`; \ ./check_hexchar || rval=`expr $$rval + $$?`; \ - ./check_iolog_plugin $(srcdir)/regress/iolog_plugin/iolog || rval=`expr $$rval + $$?`; \ + mkdir -p regress/iolog_plugin; \ + ./check_iolog_plugin regress/iolog_plugin/iolog || rval=`expr $$rval + $$?`; \ ./check_starttime || rval=`expr $$rval + $$?`; \ if test -f check_symbols; then \ ./check_symbols .libs/sudoers.so $(shlib_exp) || rval=`expr $$rval + $$?`; \ diff --git a/plugins/sudoers/regress/iolog_plugin/check_iolog_plugin.c b/plugins/sudoers/regress/iolog_plugin/check_iolog_plugin.c index 7f2ad8dc2..398537bbe 100644 --- a/plugins/sudoers/regress/iolog_plugin/check_iolog_plugin.c +++ b/plugins/sudoers/regress/iolog_plugin/check_iolog_plugin.c @@ -81,8 +81,8 @@ sudo_printf_int(int msg_type, const char *fmt, ...) return len; } -bool -validate_iolog_info(const char *log_dir) +static bool +validate_iolog_info(const char *log_dir, bool legacy) { struct iolog_info *info; time_t now; @@ -93,33 +93,48 @@ validate_iolog_info(const char *log_dir) if ((info = iolog_parse_loginfo(-1, log_dir)) == NULL) return false; - if (strcmp(info->cwd, "/") != 0) { - sudo_warnx("bad cwd: want \"/\", got \"%s\"", info->cwd); + if (info->cwd == NULL || strcmp(info->cwd, "/") != 0) { + sudo_warnx("bad cwd: want \"/\", got \"%s\"", + info->cwd ? info->cwd : "NULL"); return false; } - if (strcmp(info->user, "nobody") != 0) { - sudo_warnx("bad user: want \"nobody\" got \"%s\"", info->user); + /* No host in the legacy log file. */ + if (!legacy) { + if (info->host == NULL || strcmp(info->host, "localhost") != 0) { + sudo_warnx("bad host: want \"localhost\", got \"%s\"", + info->host ? info->host : "NULL"); + return false; + } + } + + if (info->user == NULL || strcmp(info->user, "nobody") != 0) { + sudo_warnx("bad user: want \"nobody\" got \"%s\"", + info->user ? info->user : "NULL"); return false; } - if (strcmp(info->runas_user, "root") != 0) { - sudo_warnx("bad runas_user: want \"root\" got \"%s\"", info->runas_user); + if (info->runas_user == NULL || strcmp(info->runas_user, "root") != 0) { + sudo_warnx("bad runas_user: want \"root\" got \"%s\"", + info->runas_user ? info->runas_user : "NULL"); return false; } + /* No runas group specified, should be NULL. */ if (info->runas_group != NULL) { - sudo_warnx("bad runas_group: want \"\" got \"%s\"", info->runas_user); + sudo_warnx("bad runas_group: want \"\" got \"%s\"", info->runas_group); return false; } - if (strcmp(info->tty, "/dev/console") != 0) { - sudo_warnx("bad tty: want \"/dev/console\" got \"%s\"", info->tty); + if (info->tty == NULL || strcmp(info->tty, "/dev/console") != 0) { + sudo_warnx("bad tty: want \"/dev/console\" got \"%s\"", + info->tty ? info->tty : "NULL"); return false; } - if (strcmp(info->cmd, "/usr/bin/id") != 0) { - sudo_warnx("bad command: want \"/usr/bin/id\" got \"%s\"", info->cmd); + if (info->cmd == NULL || strcmp(info->cmd, "/usr/bin/id") != 0) { + sudo_warnx("bad command: want \"/usr/bin/id\" got \"%s\"", + info->cmd ? info->cmd : "NULL"); return false; } @@ -211,6 +226,7 @@ test_endpoints(int *ntests, int *nerrors, const char *iolog_dir, char *envp[]) "cols=80", "lines=24", "cwd=/", + "host=localhost", "tty=/dev/console", "user=nobody", NULL @@ -253,9 +269,16 @@ test_endpoints(int *ntests, int *nerrors, const char *iolog_dir, char *envp[]) return; } - /* Validate I/O log info file. */ + /* Validate I/O log info file (json). */ (*ntests)++; - if (!validate_iolog_info(iolog_dir)) + if (!validate_iolog_info(iolog_dir, false)) + (*nerrors)++; + + /* Validate I/O log info file (legacy). */ + snprintf(iolog_path, sizeof(iolog_path), "%s/log.json", iolog_dir); + unlink(iolog_path); + (*ntests)++; + if (!validate_iolog_info(iolog_dir, true)) (*nerrors)++; /* Test log_ttyout endpoint. */