Merge pull request #65 from hashicorp/b-windows-sysattr-credentials

Fix sysattr cross compilation issue on Windows
This commit is contained in:
Armon Dadgar 2015-09-20 15:43:57 -07:00
commit dd1342d3e7
3 changed files with 54 additions and 35 deletions

View file

@ -18,11 +18,8 @@
package executor
import (
"fmt"
"os/exec"
"path/filepath"
"strconv"
"syscall"
"github.com/hashicorp/nomad/nomad/structs"
)
@ -112,35 +109,3 @@ type cmd struct {
// RunAs may be a username or Uid. The implementation will decide how to use it.
RunAs string
}
// SetUID changes the Uid for this command (must be set before starting)
func (c *cmd) SetUID(userid string) error {
uid, err := strconv.ParseUint(userid, 10, 32)
if err != nil {
return fmt.Errorf("Unable to convert userid to uint32: %s", err)
}
if c.SysProcAttr == nil {
c.SysProcAttr = &syscall.SysProcAttr{}
}
if c.SysProcAttr.Credential == nil {
c.SysProcAttr.Credential = &syscall.Credential{}
}
c.SysProcAttr.Credential.Uid = uint32(uid)
return nil
}
// SetGID changes the Gid for this command (must be set before starting)
func (c *cmd) SetGID(groupid string) error {
gid, err := strconv.ParseUint(groupid, 10, 32)
if err != nil {
return fmt.Errorf("Unable to convert groupid to uint32: %s", err)
}
if c.SysProcAttr == nil {
c.SysProcAttr = &syscall.SysProcAttr{}
}
if c.SysProcAttr.Credential == nil {
c.SysProcAttr.Credential = &syscall.Credential{}
}
c.SysProcAttr.Credential.Uid = uint32(gid)
return nil
}

41
client/executor/setuid.go Normal file
View file

@ -0,0 +1,41 @@
// +build !windows
package executor
import (
"fmt"
"strconv"
"syscall"
)
// SetUID changes the Uid for this command (must be set before starting)
func (c *cmd) SetUID(userid string) error {
uid, err := strconv.ParseUint(userid, 10, 32)
if err != nil {
return fmt.Errorf("Unable to convert userid to uint32: %s", err)
}
if c.SysProcAttr == nil {
c.SysProcAttr = &syscall.SysProcAttr{}
}
if c.SysProcAttr.Credential == nil {
c.SysProcAttr.Credential = &syscall.Credential{}
}
c.SysProcAttr.Credential.Uid = uint32(uid)
return nil
}
// SetGID changes the Gid for this command (must be set before starting)
func (c *cmd) SetGID(groupid string) error {
gid, err := strconv.ParseUint(groupid, 10, 32)
if err != nil {
return fmt.Errorf("Unable to convert groupid to uint32: %s", err)
}
if c.SysProcAttr == nil {
c.SysProcAttr = &syscall.SysProcAttr{}
}
if c.SysProcAttr.Credential == nil {
c.SysProcAttr.Credential = &syscall.Credential{}
}
c.SysProcAttr.Credential.Uid = uint32(gid)
return nil
}

View file

@ -0,0 +1,13 @@
package executor
// SetUID changes the Uid for this command (must be set before starting)
func (c *cmd) SetUID(userid string) error {
// TODO implement something for windows
return nil
}
// SetGID changes the Gid for this command (must be set before starting)
func (c *cmd) SetGID(groupid string) error {
// TODO implement something for windows
return nil
}