user.Current() fails when CGO is disabled and USER/HOME are not defined

So, ignore it if it fails.

This used to happen on Linux; not sure about other systems.

Fixes #607
This commit is contained in:
Frank Denis 2018-10-08 17:48:05 +02:00
parent b81a72cc3e
commit e4a1245fb2
2 changed files with 4 additions and 10 deletions

View File

@ -16,11 +16,8 @@ var cmd *exec.Cmd
func (proxy *Proxy) dropPrivilege(userStr string, fds []*os.File) {
currentUser, err := user.Current()
if err != nil {
dlog.Fatal(err)
}
if currentUser.Uid != "0" {
dlog.Fatal("I need root permissions. Try again with 'sudo'")
if err != nil && currentUser.Uid != "0" {
dlog.Fatal("Root privileges are required in order to switch to a different user. Maybe try again with 'sudo'")
}
userInfo, err := user.Lookup(userStr)
args := os.Args

View File

@ -18,11 +18,8 @@ var cmd *exec.Cmd
func (proxy *Proxy) dropPrivilege(userStr string, fds []*os.File) {
currentUser, err := user.Current()
if err != nil {
dlog.Fatal(err)
}
if currentUser.Uid != "0" {
dlog.Fatal("I need root permissions. Try again with 'sudo'")
if err != nil && currentUser.Uid != "0" {
dlog.Fatal("Root privileges are required in order to switch to a different user. Maybe try again with 'sudo'")
}
user, err := user.Lookup(userStr)
args := os.Args