From 2211dac9a5f5bf34417da0b9384fb99cfca9d649 Mon Sep 17 00:00:00 2001 From: Pieter Lexis Date: Wed, 19 Jun 2019 15:35:28 +0200 Subject: [PATCH] utility: Remove makeUidNumeric and makeGidNumeric --- pdns/common_startup.cc | 5 +++-- pdns/dynlistener.cc | 2 +- pdns/misc.hh | 2 -- pdns/pdns_recursor.cc | 4 ++-- pdns/unix_utility.cc | 34 ---------------------------------- pdns/utility.hh | 6 ------ 6 files changed, 6 insertions(+), 47 deletions(-) diff --git a/pdns/common_startup.cc b/pdns/common_startup.cc index 034e13e41..a8392579f 100644 --- a/pdns/common_startup.cc +++ b/pdns/common_startup.cc @@ -30,6 +30,7 @@ #include "dynhandler.hh" #include "dnsseckeeper.hh" #include "threadname.hh" +#include "misc.hh" #ifdef HAVE_SYSTEMD #include @@ -501,10 +502,10 @@ void mainthread() gid_t newgid = 0; if(!::arg()["setgid"].empty()) - newgid=Utility::makeGidNumeric(::arg()["setgid"]); + newgid = strToGID(::arg()["setgid"]); uid_t newuid = 0; if(!::arg()["setuid"].empty()) - newuid=Utility::makeUidNumeric(::arg()["setuid"]); + newuid = strToUID(::arg()["setuid"]); g_anyToTcp = ::arg().mustDo("any-to-tcp"); g_8bitDNS = ::arg().mustDo("8bit-dns"); diff --git a/pdns/dynlistener.cc b/pdns/dynlistener.cc index c3a1dc7e3..28d11f32e 100644 --- a/pdns/dynlistener.cc +++ b/pdns/dynlistener.cc @@ -135,7 +135,7 @@ void DynListener::listenOnUnixDomain(const string& fname) if(!arg()["setgid"].empty()) { if(chmod(fname.c_str(),0660)<0) g_log<(-1),Utility::makeGidNumeric(arg()["setgid"]))<0) + if(chown(fname.c_str(),static_cast(-1), strToGID(arg()["setgid"]))<0) g_log<gr_gid; - } - return newgid; -} - - -// Retrieves an uid using a username. -uid_t Utility::makeUidNumeric(const string &username) -{ - uid_t newuid; - if(!(newuid=atoi(username.c_str()))) { - struct passwd *pw=getpwnam(username.c_str()); - if(!pw) { - g_log<pw_uid; - } - return newuid; -} - // Sets the random seed. void Utility::srandom(void) { diff --git a/pdns/utility.hh b/pdns/utility.hh index 626131d8b..8a7083fd3 100644 --- a/pdns/utility.hh +++ b/pdns/utility.hh @@ -120,12 +120,6 @@ public: //! The inet_ntop() function converts an address from network format (usually a struct in_addr or some other binary form, in network byte order) to presentation format. static const char *inet_ntop( int af, const char *src, char *dst, size_t size ); - //! Retrieves a gid using a groupname. - static gid_t makeGidNumeric( const string & group ); - - //! Retrieves an uid using an username. - static uid_t makeUidNumeric( const string & username ); - //! Writes a vector. static int writev( Utility::sock_t socket, const iovec *vector, size_t count ); -- 2.40.0