From 3a8df1219914a92628ced06c2d4daaa06ce00f1c Mon Sep 17 00:00:00 2001 From: Chris Bednarski Date: Fri, 18 Sep 2015 18:59:42 -0700 Subject: [PATCH] Windows does not support exec.Cmd.SysProcAttr.Credential call; this causes cross-compiltion to fail so it's behind a build flag now --- client/executor/exec.go | 35 -------------------------- client/executor/setuid.go | 41 +++++++++++++++++++++++++++++++ client/executor/setuid_windows.go | 13 ++++++++++ 3 files changed, 54 insertions(+), 35 deletions(-) create mode 100644 client/executor/setuid.go create mode 100644 client/executor/setuid_windows.go diff --git a/client/executor/exec.go b/client/executor/exec.go index b62ec399e..d2d0f4a29 100644 --- a/client/executor/exec.go +++ b/client/executor/exec.go @@ -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 -} diff --git a/client/executor/setuid.go b/client/executor/setuid.go new file mode 100644 index 000000000..77cb0f897 --- /dev/null +++ b/client/executor/setuid.go @@ -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 +} diff --git a/client/executor/setuid_windows.go b/client/executor/setuid_windows.go new file mode 100644 index 000000000..9c18bed53 --- /dev/null +++ b/client/executor/setuid_windows.go @@ -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 +}