shad-go/tools/testtool/commands/sandbox.go
Fedor Korotkiy 0136bbfac5 Debugging
2020-02-13 02:56:04 +03:00

34 lines
485 B
Go

package commands
import (
"os"
"os/exec"
"os/user"
"strconv"
"syscall"
)
func currentUserIsRoot() bool {
return os.Getuid() == 0
}
func sandbox(cmd *exec.Cmd) error {
nobody, err := user.Lookup("nobody")
if err != nil {
return err
}
uid, _ := strconv.Atoi(nobody.Uid)
gid, _ := strconv.Atoi(nobody.Gid)
cmd.SysProcAttr = &syscall.SysProcAttr{
Credential: &syscall.Credential{
Uid: uint32(uid),
Gid: uint32(gid),
},
}
cmd.Env = []string{}
return nil
}