| #!/bin/sh |
| |
| |
| |
| |
|
|
| |
|
|
| |
| |
| |
| |
|
|
| |
| |
| |
| |
|
|
| |
| |
|
|
| . "${srcdir=.}/tests/init.sh"; path_prepend_ ./src |
| print_ver_ cp |
| require_root_ |
| require_selinux_ |
|
|
| cwd=$(pwd) |
| cleanup_() { cd /; umount "$cwd/mnt"; } |
|
|
| |
| ctx='root:object_r:tmp_t' |
| mls_enabled_ && ctx="$ctx:s0" |
|
|
| |
| touch c || framework_failure_ |
| chcon $ctx c || skip_ "Failed to set context: $ctx" |
| cp -a c d 2>err || framework_failure_ |
| cp --preserve=context c e || framework_failure_ |
| cp --preserve=all c f || framework_failure_ |
| ls -Z d | grep $ctx || fail=1 |
| |
| compare /dev/null err || fail=1 |
| ls -Z e | grep $ctx || fail=1 |
| ls -Z f | grep $ctx || fail=1 |
| rm -f f |
|
|
| |
| |
| |
| |
| mkdir -p backup/existing_dir/ || framework_failure_ |
| ls -Zd backup/existing_dir > ed_ctx || fail=1 |
| grep $ctx ed_ctx && framework_failure_ |
| touch backup/existing_dir/file || framework_failure_ |
| chcon $ctx backup/existing_dir/file || framework_failure_ |
| |
| mkdir -p --context="$ctx" restore/existing_dir || framework_failure_ |
| |
| cp -a backup/. restore/ || fail=1 |
| ls -Zd restore/existing_dir > ed_ctx || fail=1 |
| grep $ctx ed_ctx && |
| { ls -lZd restore/existing_dir; fail=1; } |
|
|
| |
| |
| mkdir -p parents/a/b || framework_failure_ |
| ls -Zd parents/a/b > ed_ctx || fail=1 |
| grep $ctx ed_ctx && framework_failure_ |
| touch parents/a/b/file || framework_failure_ |
| chcon $ctx parents/a/b || framework_failure_ |
| |
| mkdir -p --context="$ctx" parents_dest/parents/a || framework_failure_ |
| |
| cp -r --parents --preserve=context parents/a/b/file parents_dest || fail=1 |
| |
| ls -Zd parents_dest/parents/a/b > ed_ctx || fail=1 |
| grep $ctx ed_ctx || |
| { ls -lZd parents_dest/parents/a/b; fail=1; } |
| |
| ls -Zd parents_dest/parents/a > ed_ctx || fail=1 |
| grep $ctx ed_ctx && |
| { ls -lZd parents_dest/parents/a; fail=1; } |
|
|
| |
| |
| mkdir c_d || framework_failure_ |
| chcon $ctx c_d || framework_failure_ |
| |
| old_type_f=$(get_selinux_type c) |
| old_type_d=$(get_selinux_type c_d) |
| |
| |
| cp -a c Z1 || fail=1 |
| cp -a c_d Z1_d || fail=1 |
| if restorecon Z1 Z1_d 2>restorecon.err \ |
| && compare /dev/null restorecon.err; then |
| new_type_f=$(get_selinux_type Z1) |
| new_type_d=$(get_selinux_type Z1_d) |
|
|
| |
| cp -Z c Z2 || fail=1 |
| cpZ_type_f=$(get_selinux_type Z2) |
| test "$cpZ_type_f" = "$new_type_f" || fail=1 |
|
|
| |
| cp -aZ c Z3 || fail=1 |
| cp -aZ c_d Z3_d || fail=1 |
| cpaZ_type_f=$(get_selinux_type Z3) |
| cpaZ_type_d=$(get_selinux_type Z3_d) |
| test "$cpaZ_type_f" = "$new_type_f" || fail=1 |
| test "$cpaZ_type_d" = "$new_type_d" || fail=1 |
|
|
| |
| mkdir -p existing/c_d || framework_failure_ |
| touch existing/c || framework_failure_ |
| cp -aZ c c_d existing || fail=1 |
| cpaZ_type_f=$(get_selinux_type existing/c) |
| cpaZ_type_d=$(get_selinux_type existing/c_d) |
| test "$cpaZ_type_f" = "$new_type_f" || fail=1 |
| test "$cpaZ_type_d" = "$new_type_d" || fail=1 |
| fi |
|
|
| skip=0 |
| |
| dd if=/dev/zero of=blob bs=8192 count=200 || skip=1 |
| mkdir mnt || skip=1 |
| mkfs -t ext2 -F blob || |
| skip_ "failed to create an ext2 file system" |
|
|
| mount -oloop,context=$ctx blob mnt || skip=1 |
| test $skip = 1 \ |
| && skip_ "insufficient mount/ext2 support" |
|
|
| cd mnt || framework_failure_ |
|
|
| |
| echo > ../f || framework_failure_ |
| echo > g || framework_failure_ |
| test "$(stat -c%C ../f)" = "$(stat -c%C g)" && |
| skip_ "files on separate file systems have the same security context" |
|
|
| |
| |
| cp -a ../f g 2>err || fail=1 |
| test -s g || fail=1 |
| compare /dev/null err || fail=1 |
|
|
| |
| |
| rm -f g |
| echo > g |
| cp --preserve=all ../f g 2>err || fail=1 |
| test -s g || fail=1 |
| grep "Operation not supported" err && fail=1 |
|
|
| |
| |
| rm -f g |
| cp --preserve=all ../f g 2>err || fail=1 |
| test -s g || fail=1 |
| grep "Operation not supported" err && fail=1 |
|
|
| |
| |
| |
| |
| |
| |
| |
| cat <<\EOF > exp || framework_failure_ |
| cp: failed to set the security context of |
| EOF |
|
|
| rm -f g |
| echo > g |
| |
| |
| |
| cp --preserve=context ../f g 2> out && fail=1 |
| |
| compare /dev/null g || fail=1 |
| sed "s/ .g'.*//" out > k |
| mv k out |
| compare exp out || fail=1 |
|
|
| rm -f g |
| echo > g |
| |
| cp -a --preserve=context ../f g 2> out2 && fail=1 |
| |
| compare /dev/null g || fail=1 |
| sed "s/ .g'.*//" out2 > k |
| mv k out2 |
| compare exp out2 || fail=1 |
|
|
| for no_g_cmd in '' 'rm -f g'; do |
| |
| |
| |
|
|
| |
| $no_g_cmd |
| cp -Z ../f $(realpath g) || fail=1 |
| |
| $no_g_cmd |
| cp -Z ../f g || fail=1 |
| |
| $no_g_cmd |
| cp -Z -a ../f g || fail=1 |
| |
| $no_g_cmd |
| returns_ 1 cp -Z "$ctx" ../f g || fail=1 |
|
|
| |
| $no_g_cmd |
| |
| cp --context="$ctx" ../f g || fail=1 |
| |
| $no_g_cmd |
| cp -a --context="$ctx" ../f g || fail=1 |
| done |
|
|
| |
| returns_ 1 cp -Z --preserve=context ../f g || fail=1 |
| returns_ 1 cp --preserve=context -Z ../f g || fail=1 |
| returns_ 1 cp --preserve=context --context="$ctx" ../f g || fail=1 |
|
|
| Exit $fail |
|
|