From e4a1245fb2a3ebc0af364fa060950c1bcf9a3e37 Mon Sep 17 00:00:00 2001 From: Frank Denis Date: Mon, 8 Oct 2018 17:48:05 +0200 Subject: [PATCH] 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 --- dnscrypt-proxy/privilege_linux.go | 7 ++----- dnscrypt-proxy/privilege_others.go | 7 ++----- 2 files changed, 4 insertions(+), 10 deletions(-) diff --git a/dnscrypt-proxy/privilege_linux.go b/dnscrypt-proxy/privilege_linux.go index ed6bed03..a8efea62 100644 --- a/dnscrypt-proxy/privilege_linux.go +++ b/dnscrypt-proxy/privilege_linux.go @@ -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 diff --git a/dnscrypt-proxy/privilege_others.go b/dnscrypt-proxy/privilege_others.go index b9dcd1c0..4f769ee9 100644 --- a/dnscrypt-proxy/privilege_others.go +++ b/dnscrypt-proxy/privilege_others.go @@ -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