From 09a691822627cdc6637adb73556f98536f28e3ee Mon Sep 17 00:00:00 2001 From: Frank Denis Date: Tue, 18 Oct 2022 14:56:39 +0200 Subject: [PATCH] Use os.Geteuid() Fixes #2224 --- dnscrypt-proxy/privilege_linux.go | 3 +-- dnscrypt-proxy/privilege_others.go | 3 +-- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/dnscrypt-proxy/privilege_linux.go b/dnscrypt-proxy/privilege_linux.go index dcadd3b7..1908a4b7 100644 --- a/dnscrypt-proxy/privilege_linux.go +++ b/dnscrypt-proxy/privilege_linux.go @@ -15,8 +15,7 @@ import ( ) func (proxy *Proxy) dropPrivilege(userStr string, fds []*os.File) { - currentUser, err := user.Current() - if err != nil && currentUser.Uid != "0" { + if os.Geteuid() != 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) diff --git a/dnscrypt-proxy/privilege_others.go b/dnscrypt-proxy/privilege_others.go index 81b1741b..195aa1ce 100644 --- a/dnscrypt-proxy/privilege_others.go +++ b/dnscrypt-proxy/privilege_others.go @@ -17,8 +17,7 @@ import ( ) func (proxy *Proxy) dropPrivilege(userStr string, fds []*os.File) { - currentUser, err := user.Current() - if err != nil && currentUser.Uid != "0" { + if os.Geteuid() != 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)