diff options
author | Andrew G. Morgan <morgan@kernel.org> | 2020-11-09 22:47:15 -0800 |
---|---|---|
committer | Andrew G. Morgan <morgan@kernel.org> | 2020-11-09 22:47:15 -0800 |
commit | edd329dbcda3e25a8d21636c2d69a102fb1eb65a (patch) | |
tree | f06d08ab4ecd45887e7f43144280c3b78aeca596 | |
parent | cf8fb28e420d7b54e856cd30cef18ac732f24d2c (diff) | |
download | libcap2-edd329dbcda3e25a8d21636c2d69a102fb1eb65a.tar.gz |
Remove the golang POSIX semantics validation tests.
These were here as a commentary mostly, and now that the golang
upstream sources (targeted for 1.16 release) contain my patch
that enables POSIX semantics, [
https://go-review.googlesource.com/c/go/+/210639
], and the syscall.TestSetuidEtc() test code has been enhanced to
run on all Go supported Linux architectures, there is no need to
keep a seed copy of it here.
Signed-off-by: Andrew G. Morgan <morgan@kernel.org>
-rw-r--r-- | contrib/golang/.gitignore | 4 | ||||
-rw-r--r-- | contrib/golang/Makefile | 15 | ||||
-rw-r--r-- | contrib/golang/README | 23 | ||||
-rw-r--r-- | contrib/golang/posix-cgo.stub_go | 52 | ||||
-rw-r--r-- | contrib/golang/posix.stub_go | 5 | ||||
-rw-r--r-- | contrib/golang/ptest.go | 140 |
6 files changed, 0 insertions, 239 deletions
diff --git a/contrib/golang/.gitignore b/contrib/golang/.gitignore deleted file mode 100644 index 6b07a71..0000000 --- a/contrib/golang/.gitignore +++ /dev/null @@ -1,4 +0,0 @@ -posix -posix-cgo -posix-cgo.go -posix.go diff --git a/contrib/golang/Makefile b/contrib/golang/Makefile deleted file mode 100644 index 4c497cf..0000000 --- a/contrib/golang/Makefile +++ /dev/null @@ -1,15 +0,0 @@ -GO := go - -all: posix.go posix-cgo.go - CGO_ENABLED=0 $(GO) build posix.go - $(GO) build posix-cgo.go - -posix.go: ptest.go posix.stub_go Makefile - sed -e '/\/\/ main_here/ r posix.stub_go' ptest.go > $@ - -posix-cgo.go: ptest.go posix-cgo.stub_go Makefile - sed -e '/\/\/ main_here/ r posix-cgo.stub_go' ptest.go > $@ - -clean: - rm -f posix.go posix - rm -f posix-cgo.go posix-cgo diff --git a/contrib/golang/README b/contrib/golang/README deleted file mode 100644 index 9c55ad5..0000000 --- a/contrib/golang/README +++ /dev/null @@ -1,23 +0,0 @@ -This directory contains some test code for system calls that need -POSIX semantics to work under Go. There are 9 system calls wrapped in -a nptl:setxid mechanism in glibc, and the following development patch -adds support for these 9 to native Go. - -https://go-review.googlesource.com/c/go/+/210639/ - -The Go support works with or without CGO_ENABLED. - -With a patched Go runtime library: - - make - sudo ./posix - sudo ./posix-cgo - -should validate that all is working as intended. - -The above Go patch also exposes the mechanism that achieves this in -the Go runtime, to ensure that the native Go "libcap/cap" package can -work with and without CGO_ENABLED. - -Andrew G. Morgan <morgan@kernel.org> -2019-12-10 diff --git a/contrib/golang/posix-cgo.stub_go b/contrib/golang/posix-cgo.stub_go deleted file mode 100644 index 2878b1e..0000000 --- a/contrib/golang/posix-cgo.stub_go +++ /dev/null @@ -1,52 +0,0 @@ - -// #include <stdio.h> -// #include <stdlib.h> -// #include <pthread.h> -// #include <unistd.h> -// #include <sys/types.h> -// -// pthread_t *t = NULL; -// pthread_mutex_t mu; -// int nts = 0; -// int all_done = 0; -// -// static void *aFn(void *vargp) { -// int done = 0; -// while (!done) { -// usleep(100); -// pthread_mutex_lock(&mu); -// done = all_done; -// pthread_mutex_unlock(&mu); -// } -// printf("tid=%d done\n", pthread_self()); -// return NULL; -// } -// -// void trial(int argc) { -// nts = argc; -// t = calloc(nts, sizeof(pthread_t)); -// pthread_mutex_init(&mu, NULL); -// for (int i = 0; i < nts; i++) { -// printf("launch C-pthread [%d]\n", i); -// pthread_create(&t[i], NULL, aFn, NULL); -// } -// } -// -// void cleanup(void) { -// pthread_mutex_lock(&mu); -// all_done = 1; -// pthread_mutex_unlock(&mu); -// for (int i = 0; i < nts; i++) { -// printf("join C-pthread [%d]\n", i); -// pthread_join(t[i], NULL); -// } -// pthread_mutex_destroy(&mu); -// } -import "C" - -func main() { - const cts = 3 - C.trial(cts) - defer C.cleanup() - ptest() -} diff --git a/contrib/golang/posix.stub_go b/contrib/golang/posix.stub_go deleted file mode 100644 index d76c469..0000000 --- a/contrib/golang/posix.stub_go +++ /dev/null @@ -1,5 +0,0 @@ - -func main() { - log.Print("Running pure Go test") - ptest() -} diff --git a/contrib/golang/ptest.go b/contrib/golang/ptest.go deleted file mode 100644 index c8d7d71..0000000 --- a/contrib/golang/ptest.go +++ /dev/null @@ -1,140 +0,0 @@ -// Program posix is a test case to confirm that Go is capable of -// exhibiting posix semantics for system calls. -// -// This code is a template for two programs: posix.go and posix-cgo.go -// which are built by the Makefile to using sed. -package main - -import ( - "fmt" - "io/ioutil" - "log" - "os" - "strings" - "syscall" -) - -// main_here - -func dumpStatus(testCase string, err error, filter, expect string) bool { - fmt.Printf("%s [%v]:\n", testCase, err) - var failed bool - pid := syscall.Getpid() - fs, err := ioutil.ReadDir(fmt.Sprintf("/proc/%d/task", pid)) - if err != nil { - log.Fatal(err) - } - for _, f := range fs { - tf := fmt.Sprintf("/proc/%s/status", f.Name()) - d, err := ioutil.ReadFile(tf) - if err != nil { - fmt.Println(tf, err) - failed = true - continue - } - lines := strings.Split(string(d), "\n") - for _, line := range lines { - if strings.HasPrefix(line, filter) { - fails := line != expect - failure := "" - if fails { - failed = fails - failure = " (bad)" - } - fmt.Printf("%s %s%s\n", tf, line, failure) - break - } - } - } - return failed -} - -func ptest() { - var err error - var bad bool - - // egid setting - bad = bad || dumpStatus("initial state", nil, "Gid:", "Gid:\t0\t0\t0\t0") - err = syscall.Setegid(1001) - bad = bad || dumpStatus("setegid(1001) state", err, "Gid:", "Gid:\t0\t1001\t0\t1001") - err = syscall.Setegid(1002) - bad = bad || dumpStatus("setegid(1002) state", err, "Gid:", "Gid:\t0\t1002\t0\t1002") - err = syscall.Setegid(0) - bad = bad || dumpStatus("setegid(0) state", err, "Gid:", "Gid:\t0\t0\t0\t0") - - // euid setting (no way back from this one) - bad = bad || dumpStatus("initial euid", nil, "Uid:", "Uid:\t0\t0\t0\t0") - err = syscall.Seteuid(1) - bad = bad || dumpStatus("seteuid(1)", err, "Uid:", "Uid:\t0\t1\t0\t1") - err = syscall.Seteuid(0) - bad = bad || dumpStatus("seteuid(0)", err, "Uid:", "Uid:\t0\t0\t0\t0") - - // gid setting - bad = bad || dumpStatus("initial state", nil, "Gid:", "Gid:\t0\t0\t0\t0") - err = syscall.Setgid(1001) - bad = bad || dumpStatus("setgid(1001) state", err, "Gid:", "Gid:\t1001\t1001\t1001\t1001") - err = syscall.Setgid(1002) - bad = bad || dumpStatus("setgid(1002) state", err, "Gid:", "Gid:\t1002\t1002\t1002\t1002") - err = syscall.Setgid(0) - bad = bad || dumpStatus("setgid(0) state", err, "Gid:", "Gid:\t0\t0\t0\t0") - - // groups setting - bad = bad || dumpStatus("initial groups", nil, "Groups:", "Groups:\t0 ") - err = syscall.Setgroups([]int{0, 1, 2, 3}) - bad = bad || dumpStatus("setgroups(0,1,2,3)", err, "Groups:", "Groups:\t0 1 2 3 ") - err = syscall.Setgroups([]int{3, 2, 1}) - bad = bad || dumpStatus("setgroups(2,3,1)", err, "Groups:", "Groups:\t1 2 3 ") - err = syscall.Setgroups(nil) - bad = bad || dumpStatus("setgroups(nil)", err, "Groups:", "Groups:\t ") - err = syscall.Setgroups([]int{0}) - bad = bad || dumpStatus("setgroups(0)", err, "Groups:", "Groups:\t0 ") - - // regid setting - bad = bad || dumpStatus("initial state", nil, "Gid:", "Gid:\t0\t0\t0\t0") - err = syscall.Setregid(1001, 0) - bad = bad || dumpStatus("setregid(1001) state", err, "Gid:", "Gid:\t1001\t0\t0\t0") - err = syscall.Setregid(0, 1002) - bad = bad || dumpStatus("setregid(1002) state", err, "Gid:", "Gid:\t0\t1002\t1002\t1002") - err = syscall.Setregid(0, 0) - bad = bad || dumpStatus("setregid(0) state", err, "Gid:", "Gid:\t0\t0\t0\t0") - - // reuid setting - bad = bad || dumpStatus("initial state", nil, "Uid:", "Uid:\t0\t0\t0\t0") - err = syscall.Setreuid(1, 0) - bad = bad || dumpStatus("setreuid(1,0) state", err, "Uid:", "Uid:\t1\t0\t0\t0") - err = syscall.Setreuid(0, 2) - bad = bad || dumpStatus("setreuid(0,2) state", err, "Uid:", "Uid:\t0\t2\t2\t2") - err = syscall.Setreuid(0, 0) - bad = bad || dumpStatus("setreuid(0) state", err, "Uid:", "Uid:\t0\t0\t0\t0") - - // resgid setting - bad = bad || dumpStatus("initial state", nil, "Gid:", "Gid:\t0\t0\t0\t0") - err = syscall.Setresgid(1, 0, 2) - bad = bad || dumpStatus("setresgid(1,0,2) state", err, "Gid:", "Gid:\t1\t0\t2\t0") - err = syscall.Setresgid(0, 2, 1) - bad = bad || dumpStatus("setresgid(0,2,1) state", err, "Gid:", "Gid:\t0\t2\t1\t2") - err = syscall.Setresgid(0, 0, 0) - bad = bad || dumpStatus("setresgid(0) state", err, "Gid:", "Gid:\t0\t0\t0\t0") - - // resuid setting - bad = bad || dumpStatus("initial state", nil, "Uid:", "Uid:\t0\t0\t0\t0") - err = syscall.Setresuid(1, 0, 2) - bad = bad || dumpStatus("setresuid(1,0,2) state", err, "Uid:", "Uid:\t1\t0\t2\t0") - err = syscall.Setresuid(0, 2, 1) - bad = bad || dumpStatus("setresuid(0,2,1) state", err, "Uid:", "Uid:\t0\t2\t1\t2") - err = syscall.Setresuid(0, 0, 0) - bad = bad || dumpStatus("setresuid(0) state", err, "Uid:", "Uid:\t0\t0\t0\t0") - - // uid setting (no way back from this one) - bad = bad || dumpStatus("initial uid", nil, "Uid:", "Uid:\t0\t0\t0\t0") - err = syscall.Setuid(1) - bad = bad || dumpStatus("setuid(1)", err, "Uid:", "Uid:\t1\t1\t1\t1") - err = syscall.Setuid(0) - bad = bad || dumpStatus("setuid(0)", err, "Uid:", "Uid:\t1\t1\t1\t1") - - if bad { - log.Print("TEST FAILED") - os.Exit(1) - } - log.Print("TEST PASSED") -} |