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

40 lines
548 B
Go
Raw Normal View History

package commands
import (
"log"
"os/exec"
"os/user"
"strconv"
"syscall"
)
func currentUserIsRoot() bool {
me, err := user.Current()
if err != nil {
log.Fatal(err)
}
return me.Uid == "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
}