From 161d93466c6428e4af99d6fe0dffdbfbc909d0f1 Mon Sep 17 00:00:00 2001 From: Paul Sajna <paulsajna@gmail.com> Date: Fri, 9 Mar 2018 04:47:59 -0800 Subject: [PATCH] fixes and tests --- src/platform/src/linux/mod.rs | 2 +- src/unistd/src/lib.rs | 2 +- tests/.gitignore | 2 ++ tests/Makefile | 6 ++++-- tests/link.c | 3 ++- tests/setid.c | 26 ++++++++++++++++++++++++++ tests/unlink.c | 7 +++++++ 7 files changed, 43 insertions(+), 5 deletions(-) create mode 100644 tests/setid.c create mode 100644 tests/unlink.c diff --git a/src/platform/src/linux/mod.rs b/src/platform/src/linux/mod.rs index e0953453..daff60cb 100644 --- a/src/platform/src/linux/mod.rs +++ b/src/platform/src/linux/mod.rs @@ -116,7 +116,7 @@ pub fn getuid() -> uid_t { } pub fn link(path1: *const c_char, path2: *const c_char) -> c_int { - e(unsafe { syscall!(LINKAT, AT_FDCWD, path1, path2) }) as c_int + e(unsafe { syscall!(LINKAT, AT_FDCWD, path1, AT_FDCWD, path2, 0) }) as c_int } pub fn mkdir(path: *const c_char, mode: mode_t) -> c_int { diff --git a/src/unistd/src/lib.rs b/src/unistd/src/lib.rs index 62912097..8a1d149f 100644 --- a/src/unistd/src/lib.rs +++ b/src/unistd/src/lib.rs @@ -225,7 +225,7 @@ pub extern "C" fn getpgid(pid: pid_t) -> pid_t { #[no_mangle] pub extern "C" fn getpgrp() -> pid_t { - unimplemented!(); + platform::getpgid(platform::getpid()) } #[no_mangle] diff --git a/tests/.gitignore b/tests/.gitignore index 7b70bccf..473a19d7 100644 --- a/tests/.gitignore +++ b/tests/.gitignore @@ -23,4 +23,6 @@ /pipe /printf /rmdir +/setid +/unlink /write diff --git a/tests/Makefile b/tests/Makefile index 6c2a838d..be24852d 100644 --- a/tests/Makefile +++ b/tests/Makefile @@ -16,9 +16,11 @@ BINS=\ getid \ link \ math \ - rmdir \ pipe \ printf \ + rmdir \ + setid \ + unlink \ write all: $(BINS) @@ -28,7 +30,7 @@ clean: run: $(BINS) for bin in $(BINS); \ - do + do \ echo "# $${bin} #"; \ "./$${bin}" test args; \ done diff --git a/tests/link.c b/tests/link.c index 3e36df81..383575e8 100644 --- a/tests/link.c +++ b/tests/link.c @@ -1,5 +1,6 @@ #include <unistd.h> int main(int argc, char** argv) { - int status = link("link.c", "link.out"); + link("./link.c", "./link.out"); + perror("link"); } diff --git a/tests/setid.c b/tests/setid.c new file mode 100644 index 00000000..ce2b42ea --- /dev/null +++ b/tests/setid.c @@ -0,0 +1,26 @@ +/* + * The process joins process group 0. + */ +#include <stdio.h> +#include <sys/types.h> +#include <unistd.h> +#include <stdlib.h> + +int main( void ) + { + if( setpgid( getpid(), 0 ) == -1 ) { + perror( "setpgid" ); + } + printf( "%d belongs to process group %d\n", + getpid(), getpgrp() ); + + if( setregid(-1, -1) == -1 ) { + perror( "setregid" ); + } + printf("%d has egid %d and gid %d\n", getpid(), getegid(), getgid()); + + if( setreuid(-1, -1) == -1 ) { + perror( "setreuid" ); + } + printf("%d has euid %d and uid %d\n", getpid(), geteuid(), getuid()); + } diff --git a/tests/unlink.c b/tests/unlink.c new file mode 100644 index 00000000..0eceae0a --- /dev/null +++ b/tests/unlink.c @@ -0,0 +1,7 @@ +#include <unistd.h> +#include <stdio.h> + +int main(int argc, char** argv) { + link("./unlink.c", "./unlink.out"); + perror("unlink"); +} -- GitLab