diff --git a/client/allocdir/alloc_dir_posix.go b/client/allocdir/alloc_dir_posix.go index e6205b220be6..d5e4a92967a1 100644 --- a/client/allocdir/alloc_dir_posix.go +++ b/client/allocdir/alloc_dir_posix.go @@ -5,7 +5,6 @@ package allocdir import ( "fmt" - "github.com/hashicorp/nomad/helper/user-lookup" "os" "os/user" "strconv" @@ -27,7 +26,7 @@ func (d *AllocDir) dropDirPermissions(path string) error { return nil } - u, err := userlookup.Lookup("nobody") + u, err := user.Lookup("nobody") if err != nil { return err } diff --git a/client/driver/executor/exec_linux.go b/client/driver/executor/exec_linux.go index 256cc39f49b7..cbd33be80754 100644 --- a/client/driver/executor/exec_linux.go +++ b/client/driver/executor/exec_linux.go @@ -24,7 +24,6 @@ import ( "github.com/hashicorp/nomad/client/driver/spawn" cstructs "github.com/hashicorp/nomad/client/driver/structs" "github.com/hashicorp/nomad/helper/args" - "github.com/hashicorp/nomad/helper/user-lookup" "github.com/hashicorp/nomad/nomad/structs" ) @@ -124,7 +123,7 @@ func (e *LinuxExecutor) ID() (string, error) { // runAs takes a user id as a string and looks up the user, and sets the command // to execute as that user. func (e *LinuxExecutor) runAs(userid string) error { - u, err := userlookup.Lookup(userid) + u, err := user.Lookup(userid) if err != nil { return fmt.Errorf("Failed to identify user %v: %v", userid, err) } diff --git a/helper/user-lookup/user-lookup.go b/helper/user-lookup/user-lookup.go deleted file mode 100644 index b0826e6c925b..000000000000 --- a/helper/user-lookup/user-lookup.go +++ /dev/null @@ -1,35 +0,0 @@ -// +build !windows - -package userlookup - -import ( - "fmt" - "io/ioutil" - "os/user" - "strings" -) - -// Lookup checks if the given username or uid is present in /etc/passwd -// and returns the user struct. -// If the username is not found, an error is returned. -// Credit to @creak, https://github.com/docker/docker/pull/1096 -func Lookup(uid string) (*user.User, error) { - file, err := ioutil.ReadFile("/etc/passwd") - if err != nil { - return nil, err - } - - for _, line := range strings.Split(string(file), "\n") { - data := strings.Split(line, ":") - if len(data) > 5 && (data[0] == uid || data[2] == uid) { - return &user.User{ - Uid: data[2], - Gid: data[3], - Username: data[0], - Name: data[4], - HomeDir: data[5], - }, nil - } - } - return nil, fmt.Errorf("User not found in /etc/passwd") -} diff --git a/scripts/build.sh b/scripts/build.sh index 36566413a2db..4a79e8351e28 100755 --- a/scripts/build.sh +++ b/scripts/build.sh @@ -44,6 +44,7 @@ gox \ -arch="${XC_ARCH}" \ -osarch="!linux/arm !darwin/386" \ -ldflags "-X main.GitCommit ${GIT_COMMIT}${GIT_DIRTY}" \ + -cgo \ -output "pkg/{{.OS}}_{{.Arch}}/nomad" \ .