diff options
author | Jakob Unterwurzacher | 2025-04-06 11:14:03 +0200 |
---|---|---|
committer | Jakob Unterwurzacher | 2025-04-06 11:14:03 +0200 |
commit | 27abe23de847eff630f6768e7296cf3e6a6322b4 (patch) | |
tree | c1e6e2f71c70178271f4f593adff28b3178548bb /internal/syscallcompat/thread_credentials_linux_32.go | |
parent | 4551e4f8edc13aeb95f1fa372ce3bd8a0e9cba4b (diff) |
syscallcompat: fix build contraints on thread_credentials_linux_368_arm.go
This file was only compiled for arm because
( https://pkg.go.dev/cmd/go#hdr-Build_constraints ):
If a file's
name, after stripping the extension and a possible _test suffix,
matches any of the following patterns:
*_GOOS
*_GOARCH
*_GOOS_GOARCH
(example: source_windows_amd64.go) where GOOS and GOARCH
represent any known operating system and architecture values
respectively, then the file is considered to have an implicit
build constraint requiring those terms (in addition to any
explicit constraints in the file).
Error was:
+ GOOS=linux
+ GOARCH=386
+ build
+ go build -tags without_openssl -o /dev/null
# github.com/rfjakob/gocryptfs/v2/internal/syscallcompat
Error: internal/syscallcompat/asuser_linux.go:41:8: undefined: Setregid
Error: internal/syscallcompat/asuser_linux.go:47:8: undefined: Setreuid
Error: internal/syscallcompat/thread_credentials_linux.go:29:10: undefined: setgroups
Error: internal/syscallcompat/thread_credentials_linux.go:36:9: undefined: setgroups
Error: internal/syscallcompat/thread_credentials_linux.go:49:9: undefined: Setregid
Error: internal/syscallcompat/thread_credentials_linux.go:57:9: undefined: Setreuid
Rename the file to fix the problem. And add a comment about why this file exists.
Fixes https://github.com/rfjakob/gocryptfs/issues/907
Diffstat (limited to 'internal/syscallcompat/thread_credentials_linux_32.go')
-rw-r--r-- | internal/syscallcompat/thread_credentials_linux_32.go | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/internal/syscallcompat/thread_credentials_linux_32.go b/internal/syscallcompat/thread_credentials_linux_32.go new file mode 100644 index 0000000..69fffca --- /dev/null +++ b/internal/syscallcompat/thread_credentials_linux_32.go @@ -0,0 +1,40 @@ +//go:build (linux && 386) || (linux && arm) + +// Linux on i386 and 32-bit ARM has SYS_SETREUID and friends returning 16-bit values. +// We need to use SYS_SETREUID32 instead. + +package syscallcompat + +import ( + "unsafe" + + "golang.org/x/sys/unix" +) + +// See thread_credentials_linux.go for docs + +// Setreuid is like setreuid(2) but affects only the current thread +func Setreuid(ruid int, euid int) (err error) { + _, _, e1 := unix.RawSyscall(unix.SYS_SETREUID32, uintptr(ruid), uintptr(euid), 0) + if e1 != 0 { + err = e1 + } + return +} + +// Setreuid is like setregid(2) but affects only the current thread +func Setregid(rgid int, egid int) (err error) { + _, _, e1 := unix.RawSyscall(unix.SYS_SETREGID32, uintptr(rgid), uintptr(egid), 0) + if e1 != 0 { + err = e1 + } + return +} + +func setgroups(n int, list *uint32) (err error) { + _, _, e1 := unix.RawSyscall(unix.SYS_SETGROUPS32, uintptr(n), uintptr(unsafe.Pointer(list)), 0) + if e1 != 0 { + err = e1 + } + return +} |