You've already forked runc
mirror of
https://github.com/opencontainers/runc.git
synced 2025-07-17 13:20:57 +03:00
There are essentially two possible implementations for Setuid/Setgid on Linux, either using SYS_SETUID32/SYS_SETGID32 or SYS_SETUID/SYS_SETGID, depending on the architecture (see golang/go#1435 for why Setuid/Setgid aren currently implemented for Linux neither in syscall nor in golang.org/x/sys/unix). Reduce duplication by merging the currently implemented variants and adjusting the build tags accordingly. Signed-off-by: Tobias Klauser <tklauser@distanz.ch>
27 lines
505 B
Go
27 lines
505 B
Go
// +build linux
|
|
// +build 386 arm
|
|
|
|
package system
|
|
|
|
import (
|
|
"golang.org/x/sys/unix"
|
|
)
|
|
|
|
// Setuid sets the uid of the calling thread to the specified uid.
|
|
func Setuid(uid int) (err error) {
|
|
_, _, e1 := unix.RawSyscall(unix.SYS_SETUID32, uintptr(uid), 0, 0)
|
|
if e1 != 0 {
|
|
err = e1
|
|
}
|
|
return
|
|
}
|
|
|
|
// Setgid sets the gid of the calling thread to the specified gid.
|
|
func Setgid(gid int) (err error) {
|
|
_, _, e1 := unix.RawSyscall(unix.SYS_SETGID32, uintptr(gid), 0, 0)
|
|
if e1 != 0 {
|
|
err = e1
|
|
}
|
|
return
|
|
}
|