github.com/kardianos/nomad@v0.1.3-0.20151022182107-b13df73ee850/client/executor/setuid.go (about) 1 // +build !windows 2 3 package executor 4 5 import ( 6 "fmt" 7 "strconv" 8 "syscall" 9 ) 10 11 // SetUID changes the Uid for this command (must be set before starting) 12 func (c *cmd) SetUID(userid string) error { 13 uid, err := strconv.ParseUint(userid, 10, 32) 14 if err != nil { 15 return fmt.Errorf("Unable to convert userid to uint32: %s", err) 16 } 17 if c.SysProcAttr == nil { 18 c.SysProcAttr = &syscall.SysProcAttr{} 19 } 20 if c.SysProcAttr.Credential == nil { 21 c.SysProcAttr.Credential = &syscall.Credential{} 22 } 23 c.SysProcAttr.Credential.Uid = uint32(uid) 24 return nil 25 } 26 27 // SetGID changes the Gid for this command (must be set before starting) 28 func (c *cmd) SetGID(groupid string) error { 29 gid, err := strconv.ParseUint(groupid, 10, 32) 30 if err != nil { 31 return fmt.Errorf("Unable to convert groupid to uint32: %s", err) 32 } 33 if c.SysProcAttr == nil { 34 c.SysProcAttr = &syscall.SysProcAttr{} 35 } 36 if c.SysProcAttr.Credential == nil { 37 c.SysProcAttr.Credential = &syscall.Credential{} 38 } 39 c.SysProcAttr.Credential.Gid = uint32(gid) 40 return nil 41 }