From 32db528689ca6dfd562356f4a5584dffc9d5f33c Mon Sep 17 00:00:00 2001 From: "Todd C. Miller" Date: Sun, 27 Sep 2020 10:31:14 -0600 Subject: [PATCH] Add tests for entries without a newline. --- MANIFEST | 4 ++++ .../sudoers/regress/testsudoers/test14.out.ok | 18 +++++++++++++++ plugins/sudoers/regress/testsudoers/test14.sh | 23 +++++++++++++++++++ .../sudoers/regress/testsudoers/test15.out.ok | 17 ++++++++++++++ plugins/sudoers/regress/testsudoers/test15.sh | 22 ++++++++++++++++++ 5 files changed, 84 insertions(+) create mode 100644 plugins/sudoers/regress/testsudoers/test14.out.ok create mode 100755 plugins/sudoers/regress/testsudoers/test14.sh create mode 100644 plugins/sudoers/regress/testsudoers/test15.out.ok create mode 100755 plugins/sudoers/regress/testsudoers/test15.sh diff --git a/MANIFEST b/MANIFEST index 408bd622d..fcb56e665 100644 --- a/MANIFEST +++ b/MANIFEST @@ -831,6 +831,10 @@ plugins/sudoers/regress/testsudoers/test12.out.ok plugins/sudoers/regress/testsudoers/test12.sh plugins/sudoers/regress/testsudoers/test13.out.ok plugins/sudoers/regress/testsudoers/test13.sh +plugins/sudoers/regress/testsudoers/test14.out.ok +plugins/sudoers/regress/testsudoers/test14.sh +plugins/sudoers/regress/testsudoers/test15.out.ok +plugins/sudoers/regress/testsudoers/test15.sh plugins/sudoers/regress/testsudoers/test2.inc plugins/sudoers/regress/testsudoers/test2.out.ok plugins/sudoers/regress/testsudoers/test2.sh diff --git a/plugins/sudoers/regress/testsudoers/test14.out.ok b/plugins/sudoers/regress/testsudoers/test14.out.ok new file mode 100644 index 000000000..add1bb2c1 --- /dev/null +++ b/plugins/sudoers/regress/testsudoers/test14.out.ok @@ -0,0 +1,18 @@ + +Testing user privilege without a newline + +Parses OK + +millert ALL = ALL + +Testing alias without a newline + +Parses OK + +Cmnd_Alias FOO = /bin/bar + +Testing Defaults without a newline + +Parses OK + +Defaults log_output diff --git a/plugins/sudoers/regress/testsudoers/test14.sh b/plugins/sudoers/regress/testsudoers/test14.sh new file mode 100755 index 000000000..78350d706 --- /dev/null +++ b/plugins/sudoers/regress/testsudoers/test14.sh @@ -0,0 +1,23 @@ +#!/bin/sh +# +# Test entries with no trailing newline. +# + +exec 2>&1 + +echo "" +echo "Testing user privilege without a newline" +echo "" +printf "millert ALL = ALL" | ./testsudoers -d + +echo "" +echo "Testing alias without a newline" +echo "" +printf "Cmnd_Alias FOO=/bin/bar" | ./testsudoers -d + +echo "" +echo "Testing Defaults without a newline" +echo "" +printf "Defaults log_output" | ./testsudoers -d + +exit 0 diff --git a/plugins/sudoers/regress/testsudoers/test15.out.ok b/plugins/sudoers/regress/testsudoers/test15.out.ok new file mode 100644 index 000000000..ca02857dc --- /dev/null +++ b/plugins/sudoers/regress/testsudoers/test15.out.ok @@ -0,0 +1,17 @@ +Testing @include of a file with a missing newline + +Parses OK + +Entries for user root: + +ALL = /usr/bin/id + host matched + runas matched + cmnd unmatched + +ALL = ALL + host matched + runas matched + cmnd allowed + +Command allowed diff --git a/plugins/sudoers/regress/testsudoers/test15.sh b/plugins/sudoers/regress/testsudoers/test15.sh new file mode 100755 index 000000000..b8cdf7ebf --- /dev/null +++ b/plugins/sudoers/regress/testsudoers/test15.sh @@ -0,0 +1,22 @@ +#!/bin/sh +# +# Test @include of a file with a missing newline +# + +# Create test file +TESTDIR="`pwd`/regress/testsudoers" +printf "root ALL = ALL" >"$TESTDIR/test15.inc" + +MYUID=`\ls -lnd "$TESTDIR/test15.inc" | awk '{print $3}'` +MYGID=`\ls -lnd "$TESTDIR/test15.inc" | awk '{print $4}'` +exec 2>&1 + +echo "Testing @include of a file with a missing newline" +echo "" +./testsudoers -U $MYUID -G $MYGID root id <<-EOF + @include $TESTDIR/test15.inc + ALL ALL = /usr/bin/id +EOF + +rm -f "$TESTDIR/test15.inc" +exit 0