]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
utility: Remove makeUidNumeric and makeGidNumeric 7879/head
authorPieter Lexis <pieter.lexis@powerdns.com>
Wed, 19 Jun 2019 13:35:28 +0000 (15:35 +0200)
committerPieter Lexis <pieter.lexis@powerdns.com>
Wed, 19 Jun 2019 13:35:28 +0000 (15:35 +0200)
pdns/common_startup.cc
pdns/dynlistener.cc
pdns/misc.hh
pdns/pdns_recursor.cc
pdns/unix_utility.cc
pdns/utility.hh

index 034e13e4199a5a450ed99e39d37959e31e6a562c..a8392579f4e0145f8132c5bfa81ef3500ea2bec4 100644 (file)
@@ -30,6 +30,7 @@
 #include "dynhandler.hh"
 #include "dnsseckeeper.hh"
 #include "threadname.hh"
+#include "misc.hh"
 
 #ifdef HAVE_SYSTEMD
 #include <systemd/sd-daemon.h>
@@ -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");
index c3a1dc7e3e34245c81b98a7a1de4e0d9709b10d9..28d11f32e3c0d1993899105d99aa4cd5b4d5860f 100644 (file)
@@ -135,7 +135,7 @@ void DynListener::listenOnUnixDomain(const string& fname)
   if(!arg()["setgid"].empty()) {
     if(chmod(fname.c_str(),0660)<0)
       g_log<<Logger::Error<<"Unable to change group access mode of controlsocket at '"<<fname<<"', reason: "<<strerror(errno)<<endl;
-    if(chown(fname.c_str(),static_cast<uid_t>(-1),Utility::makeGidNumeric(arg()["setgid"]))<0)
+    if(chown(fname.c_str(),static_cast<uid_t>(-1), strToGID(arg()["setgid"]))<0)
       g_log<<Logger::Error<<"Unable to change group ownership of controlsocket at '"<<fname<<"', reason: "<<strerror(errno)<<endl;
   }
   
index ee255e9b90930a0d7972e1527529a805929386a4..205f033d2daf22f814dfc4e6b382394dd96e8188 100644 (file)
@@ -162,8 +162,6 @@ string uitoa(unsigned int i);
 string bitFlip(const string &str);
 
 void dropPrivs(int uid, int gid);
-int makeGidNumeric(const string &group);
-int makeUidNumeric(const string &user);
 void cleanSlashes(string &str);
 
 #if defined(_POSIX_THREAD_CPUTIME) && defined(CLOCK_THREAD_CPUTIME_ID)
index 82d4de2fb3e1725318a3281a719929598e9d25c3..e201f550ba2b07aa68b4b996115c49a1cbbfb4d7 100644 (file)
@@ -4020,10 +4020,10 @@ static int serviceMain(int argc, char*argv[])
 
   int newgid=0;
   if(!::arg()["setgid"].empty())
-    newgid=Utility::makeGidNumeric(::arg()["setgid"]);
+    newgid = strToGID(::arg()["setgid"]);
   int newuid=0;
   if(!::arg()["setuid"].empty())
-    newuid=Utility::makeUidNumeric(::arg()["setuid"]);
+    newuid = strToUID(::arg()["setuid"]);
 
   Utility::dropGroupPrivs(newuid, newgid);
 
index 0d180cfc84450aa2b87c83b277c88fa9b3e5a257..3287711b13699de146e094ed31a8790cba7a117e 100644 (file)
@@ -178,40 +178,6 @@ int Utility::gettimeofday( struct timeval *tv, void *tz )
   return ::gettimeofday(tv,0);
 }
 
-
-
-// Retrieves a gid using a groupname.
-gid_t Utility::makeGidNumeric(const string &group)
-{
-  gid_t newgid;
-  if(!(newgid=atoi(group.c_str()))) {
-    errno=0;
-    struct group *gr=getgrnam(group.c_str());
-    if(!gr) {
-      g_log<<Logger::Critical<<"Unable to look up gid of group '"<<group<<"': "<< (errno ? strerror(errno) : "not found") <<endl;
-      exit(1);
-    }
-    newgid=gr->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<<Logger::Critical<<"Unable to look up uid of user '"<<username<<"': "<< (errno ? strerror(errno) : "not found") <<endl;
-      exit(1);
-    }
-    newuid=pw->pw_uid;
-  }
-  return newuid;
-}
-
 // Sets the random seed.
 void Utility::srandom(void)
 {
index 626131d8bb42c6fc7efb8c240c522899a0356ef1..8a7083fd3a7996a69e44050c8a84e4f227328f92 100644 (file)
@@ -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 );