shad-go/tools/testtool/commands/sandbox.go

35 lines
485 B
Go
Raw Normal View History

package commands
import (
2020-02-12 23:56:04 +00:00
"os"
"os/exec"
"os/user"
"strconv"
"syscall"
)
func currentUserIsRoot() bool {
2020-02-12 23:56:04 +00:00
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
}