Skip to content

Commit

Permalink
Adds support for Setuid/Setgid calls that has been removed from
Browse files Browse the repository at this point in the history
go HEAD and won't be available in go 1.4.

Docker-DCO-1.1-Signed-off-by: Mrunal Patel <[email protected]> (github: mrunalp)
  • Loading branch information
mrunalp committed Oct 20, 2014
1 parent 0f49d1f commit 7d268af
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 0 deletions.
24 changes: 24 additions & 0 deletions system/syscall_linux_386.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// +build linux,386
package system

import (
"syscall"
)

// Setuid sets the uid of the calling thread to the specified uid.
func Setuid(uid int) (err error) {
_, _, e1 := syscall.RawSyscall(syscall.SYS_SETUID, 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 := syscall.RawSyscall(syscall.SYS_SETGID32, uintptr(gid), 0, 0)
if e1 != 0 {
err = e1
}
return
}
24 changes: 24 additions & 0 deletions system/syscall_linux_amd64.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// +build linux,amd64
package system

import (
"syscall"
)

// Setuid sets the uid of the calling thread to the specified uid.
func Setuid(uid int) (err error) {
_, _, e1 := syscall.RawSyscall(syscall.SYS_SETUID, 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 := syscall.RawSyscall(syscall.SYS_SETGID, uintptr(gid), 0, 0)
if e1 != 0 {
err = e1
}
return
}
24 changes: 24 additions & 0 deletions system/syscall_linux_arm.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// +build linux,arm
package system

import (
"syscall"
)

// Setuid sets the uid of the calling thread to the specified uid.
func Setuid(uid int) (err error) {
_, _, e1 := syscall.RawSyscall(syscall.SYS_SETUID, 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 := syscall.RawSyscall(syscall.SYS_SETGID32, uintptr(gid), 0, 0)
if e1 != 0 {
err = e1
}
return
}

0 comments on commit 7d268af

Please sign in to comment.