tests/overlay: replace Python script with a C program
PATCH 1/1 tests/overlay: replace Python script with a C program
This was the only Python script in the whole testsuite. No need to depend on Python just for access(2)...
Signed-off-by Ondrej Mosnacek <[email protected]>
--- tests/overlay/.gitignore | 1 + tests/overlay/Makefile | 4 +++- tests/overlay/access | 7 ------- tests/overlay/access.c | 16 ++++++++++++++++ tests/overlay/test | 26 +++++++++++++------------- 5 files changed, 33 insertions(+), 21 deletions(-) create mode 100644 tests/overlay/.gitignore delete mode 100755 tests/overlay/access create mode 100644 tests/overlay/access.c
tests/overlay/.gitignore new file +1 -0
@@ -0,0 +1 @@ +access
tests/overlay/Makefile +3 -1
@@ -1,2 +1,4 @@ -all: +TARGETS=$(patsubst %.c,%,$(wildcard *.c)) +all: $(TARGETS) clean: + rm -f $(TARGETS)
tests/overlay/access deleted +0 -7
@@ -1,7 +0,0 @@ -#!/usr/bin/python3 -import os, sys -try: - acc=eval("os.%s" % sys.argv[2]) - print(os.access(sys.argv[1], acc)) -except AttributeError as e: - print(e)
tests/overlay/access.c new file +16 -0
@@ -0,0 +1,16 @@ +#include <unistd.h> +#include <stdio.h> +#include <string.h> +#include <errno.h> + +int main (int argc,const char **argv) +{ +if (argc !=3 || (strcmp (argv[2 ],"R_OK" ) &&strcmp (argv[2 ],"W_OK" ))) { +fprintf (stderr,"Usage %s <file> R_OK|W_OK\n" , argv[0 ]); +return EINVAL ; + } + + errno =0 ; +access (argv[1 ],strcmp (argv[2 ],"R_OK" ) ==0 ?R_OK :W_OK ); +return errno; +}
tests/overlay/test +13 -13
@@ -34,10 +34,10 @@ sub getfilecon { sub access { my ( $filename, $accesstype ) = @_; - $output = -`runcon -t test_overlay_client_t -l s0:c10,c20 $basedir/access $filename $accesstype`; - $output =~ s/\n//g; - return $output; + $result = system( +"runcon -t test_overlay_client_t -l s0:c10,c20 $basedir/access $filename $accesstype" + ); + return $result >> 8; } sub xattr_test_setup {
@@ -496,63 +496,63 @@ sub test_52 { sub test_60 { print "Check read access on readfile, should succeed.\n"; $result = access( "$basedir/container1/merged/readfile", "R_OK" ); - ok( $result eq "True" ); + ok( $result eq 0 ); return; } sub test_61 { print "Check read access on writefile, should succeed.\n"; $result = access( "$basedir/container1/merged/writefile", "R_OK" ); - ok( $result eq "True" ); + ok( $result eq 0 ); return; } sub test_62 { print "Check read access on noaccessfile, should fail.\n"; $result = access( "$basedir/container1/merged/noaccessfile", "R_OK" ); - ok( $result eq "False" ); + ok( $result eq 13 ); return; } sub test_63 { print "Check write access on readfile, should fail.\n"; $result = access( "$basedir/container1/merged/readfile", "W_OK" ); - ok( $result eq "False" ); + ok( $result eq 13 ); return; } sub test_63_ctx { print "Check write access on readfile, should succeed.\n"; $result = access( "$basedir/container1/merged/readfile", "W_OK" ); - ok( $result eq "True" ); + ok( $result eq 0 ); return; } sub test_64 { print "Check write access on writefile, should succeed.\n"; $result = access( "$basedir/container1/merged/writefile", "W_OK" ); - ok( $result eq "True" ); + ok( $result eq 0 ); return; } sub test_65 { print "Check write access on noaccessfile, should fail.\n"; $result = access( "$basedir/container1/merged/noaccessfile", "W_OK" ); - ok( $result eq "False" ); + ok( $result eq 13 ); return; } sub test_66 { print "Check read to read null device should fail\n"; $result = access( "$basedir/container1/merged/null_read", "R_OK" ); - ok( $result eq "True" ); + ok( $result eq 0 ); return; } sub test_67 { print "Check write to read null device should fail\n"; $result = access( "$basedir/container1/merged/null_read", "W_OK" ); - ok( $result eq "False" ); + ok( $result eq 13 ); return; }
Signature · 1 line
2.26.2
Ondrej Mosnacek
AppliedQuoted 4 lines · Ondrej Mosnacek
This was the only Python script in the whole testsuite. No need to depend on Python just for access(2)...
Signed-off-by Ondrej Mosnacek <[email protected]>
Quoted 10 lines
--- tests/overlay/.gitignore | 1 + tests/overlay/Makefile | 4 +++- tests/overlay/access | 7 ------- tests/overlay/access.c | 16 ++++++++++++++++ tests/overlay/test | 26 +++++++++++++------------- 5 files changed, 33 insertions(+), 21 deletions(-) create mode 100644 tests/overlay/.gitignore delete mode 100755 tests/overlay/access create mode 100644 tests/overlay/access.c
Applied:
https://github.com/SELinuxProject/selinux-testsuite/commit/ce70a925a4c7766fab698330a626d9a5f5194cc5
Signature · 3 lines
Ondrej Mosnacek Software Engineer, Platform Security - SELinux kernel Red Hat, Inc.