]> git.ipfire.org Git - thirdparty/coreutils.git/commitdiff
tests: initial SMACK tests
authorJarkko Sakkinen <jarkko.sakkinen@linux.intel.com>
Tue, 31 Dec 2013 16:09:14 +0000 (18:09 +0200)
committerPádraig Brady <P@draigBrady.com>
Mon, 5 May 2014 13:26:15 +0000 (14:26 +0100)
* init.cfg (require_smack_): New function.
* local.mk: Referenced new tests.
* tests/id/smack.sh: SMACK tests (new file).
* tests/mkdir/smack-no-root.sh: SMACK tests (new file).
* tests/mkdir/smack-root.sh: SMACK tests (new file).

init.cfg
tests/id/smack.sh [new file with mode: 0755]
tests/local.mk
tests/mkdir/smack-no-root.sh [new file with mode: 0755]
tests/mkdir/smack-root.sh [new file with mode: 0755]

index 6a9b004ff22776783db316853bc4818c70c16a36..bf1887f8dee0339a05ca7725bee262b3f01cdf1c 100644 (file)
--- a/init.cfg
+++ b/init.cfg
@@ -119,6 +119,15 @@ require_selinux_enforcing_()
     || skip_ "This test is useful only with SELinux in Enforcing mode."
 }
 
+require_smack_()
+{
+  grep 'smackfs$' /proc/filesystems > /dev/null \
+    || skip_ "this system lacks SMACK support"
+
+  test "$(ls -Zd .)" != '? .' \
+    || skip_ "this file system lacks SMACK support"
+}
+
 require_openat_support_()
 {
   # Skip this test if your system has neither the openat-style functions
diff --git a/tests/id/smack.sh b/tests/id/smack.sh
new file mode 100755 (executable)
index 0000000..227db3e
--- /dev/null
@@ -0,0 +1,37 @@
+#!/bin/sh
+# SMACK test for the id-command.
+# Derived from tests/id/context.sh and tests/id/no-context.sh.
+# Copyright (C) 2014 Free Software Foundation, Inc.
+
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+
+# You should have received a copy of the GNU General Public License
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+. "${srcdir=.}/tests/init.sh"; path_prepend_ ./src
+print_ver_ id
+
+require_smack_
+
+# Check the string "context=" presence without specified user.
+id > out || fail=1
+grep 'context=' out || { cat out; fail=1; }
+
+# Check context=" is absent without specified user in conforming mode.
+POSIXLY_CORRECT=1 id > out || fail=1
+grep 'context=' out && fail=1
+
+# Check the string "context=" absence with specified user.
+# But if the current user is nameless, skip this part.
+id -nu > /dev/null && id $(id -nu) > out
+grep 'context=' out && fail=1
+
+Exit $fail
index d58b603bce17c81cd4b8160e97f772b3da3ef2c4..6d4414488ad5b367b7f07ab1139b8ea5c3535ab7 100644 (file)
@@ -125,6 +125,7 @@ all_root_tests =                            \
   tests/misc/selinux.sh                                \
   tests/misc/truncate-owned-by-other.sh                \
   tests/mkdir/writable-under-readonly.sh       \
+  tests/mkdir/smack-root.sh                    \
   tests/mv/sticky-to-xpart.sh                  \
   tests/rm/fail-2eperm.sh                      \
   tests/rm/no-give-up.sh                       \
@@ -517,6 +518,7 @@ all_tests =                                 \
   tests/id/uid.sh                              \
   tests/id/setgid.sh                           \
   tests/id/zero.sh                             \
+  tests/id/smack.sh                            \
   tests/install/basic-1.sh                     \
   tests/install/create-leading.sh              \
   tests/install/d-slashdot.sh                  \
@@ -576,6 +578,8 @@ all_tests =                                 \
   tests/mkdir/restorecon.sh                    \
   tests/mkdir/special-1.sh                     \
   tests/mkdir/t-slash.sh                       \
+  tests/mkdir/smack-no-root.sh                 \
+  tests/mkdir/smack-root.sh                    \
   tests/mv/acl.sh                              \
   tests/mv/atomic.sh                           \
   tests/mv/atomic2.sh                          \
diff --git a/tests/mkdir/smack-no-root.sh b/tests/mkdir/smack-no-root.sh
new file mode 100755 (executable)
index 0000000..527940b
--- /dev/null
@@ -0,0 +1,39 @@
+#!/bin/sh
+# SMACK test for the mkdir,mknod, mkfifo commands.
+# Derived from tests/mkdir/selinux.sh.
+# Ensure that an unsettable SMACK label doesn't cause a segfault.
+
+# Copyright (C) 2014 Free Software Foundation, Inc.
+
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+
+# You should have received a copy of the GNU General Public License
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+. "${srcdir=.}/tests/init.sh"; path_prepend_ ./src
+print_ver_ mkdir mkfifo mknod
+
+require_smack_
+
+c=arbitrary-smack-label
+msg="failed to set default file creation context to '$c':"
+
+for cmd in 'mkdir dir' 'mknod b p' 'mkfifo f'; do
+  $cmd --context="$c" 2> out && fail=1
+  set $cmd
+  echo "$1: $msg" > exp || fail=1
+
+  sed -e 's/ Operation not permitted$//' out > k || fail=1
+  mv k out || fail=1
+  compare exp out || fail=1
+done
+
+Exit $fail
diff --git a/tests/mkdir/smack-root.sh b/tests/mkdir/smack-root.sh
new file mode 100755 (executable)
index 0000000..8d7ec9b
--- /dev/null
@@ -0,0 +1,36 @@
+#!/bin/sh
+# SMACK test for the mkdir,mknod, mkfifo commands.
+# Derived from tests/mkdir/selinux.sh.
+# Ensure that SMACK label gets set.
+
+# Copyright (C) 2014 Free Software Foundation, Inc.
+
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+
+# You should have received a copy of the GNU General Public License
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+. "${srcdir=.}/tests/init.sh"; path_prepend_ ./src
+print_ver_ mkdir mkfifo mknod
+
+require_smack_
+require_root_
+
+c=arbitrary-smack-label
+
+for cmd in 'mkdir dir' 'mknod b p' 'mkfifo f'; do
+  $cmd --context="$c" || { fail=1; continue; }
+  set $cmd
+  ls -dZ $2 > out || fail=1
+  test "$(cut -f1 -d' ' out)" = "$c" || { cat out; fail=1; }
+done
+
+Exit $fail