Remove the os.user dependency and manually lookup /etc/passwd instead
This commit is contained in:
parent
8e6c249e48
commit
eb38750d99
2 changed files with 23 additions and 5 deletions
|
@ -3,10 +3,10 @@ package docker
|
|||
import (
|
||||
"flag"
|
||||
"fmt"
|
||||
"github.com/dotcloud/docker/utils"
|
||||
"log"
|
||||
"os"
|
||||
"os/exec"
|
||||
"os/user"
|
||||
"strconv"
|
||||
"strings"
|
||||
"syscall"
|
||||
|
@ -27,10 +27,7 @@ func changeUser(u string) {
|
|||
if u == "" {
|
||||
return
|
||||
}
|
||||
userent, err := user.LookupId(u)
|
||||
if err != nil {
|
||||
userent, err = user.Lookup(u)
|
||||
}
|
||||
userent, err := utils.UserLookup(u)
|
||||
if err != nil {
|
||||
log.Fatalf("Unable to find user %v: %v", u, err)
|
||||
}
|
||||
|
|
|
@ -14,6 +14,7 @@ import (
|
|||
"net/http"
|
||||
"os"
|
||||
"os/exec"
|
||||
"os/user"
|
||||
"path/filepath"
|
||||
"runtime"
|
||||
"strconv"
|
||||
|
@ -700,3 +701,23 @@ func ParseRepositoryTag(repos string) (string, string) {
|
|||
}
|
||||
return repos, ""
|
||||
}
|
||||
|
||||
func UserLookup(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")
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue