From 76ba685eddaa6b98c9d7cf463cb3b48c7e01ba59 Mon Sep 17 00:00:00 2001 From: Pieter Lexis Date: Thu, 6 Jun 2019 12:54:57 +0200 Subject: [PATCH] utility: use gid_t and uid_t --- pdns/common_startup.cc | 12 ++++++------ pdns/unix_utility.cc | 12 ++++++------ pdns/utility.hh | 8 ++++---- 3 files changed, 16 insertions(+), 16 deletions(-) diff --git a/pdns/common_startup.cc b/pdns/common_startup.cc index 07d78c1cd..034e13e41 100644 --- a/pdns/common_startup.cc +++ b/pdns/common_startup.cc @@ -499,12 +499,12 @@ void mainthread() { Utility::srandom(); - int newgid=0; - if(!::arg()["setgid"].empty()) - newgid=Utility::makeGidNumeric(::arg()["setgid"]); - int newuid=0; - if(!::arg()["setuid"].empty()) - newuid=Utility::makeUidNumeric(::arg()["setuid"]); + gid_t newgid = 0; + if(!::arg()["setgid"].empty()) + newgid=Utility::makeGidNumeric(::arg()["setgid"]); + uid_t newuid = 0; + if(!::arg()["setuid"].empty()) + newuid=Utility::makeUidNumeric(::arg()["setuid"]); g_anyToTcp = ::arg().mustDo("any-to-tcp"); g_8bitDNS = ::arg().mustDo("8bit-dns"); diff --git a/pdns/unix_utility.cc b/pdns/unix_utility.cc index 6e5d817a0..201c73fc0 100644 --- a/pdns/unix_utility.cc +++ b/pdns/unix_utility.cc @@ -124,7 +124,7 @@ void Utility::usleep(unsigned long usec) // Drops the program's group privileges. -void Utility::dropGroupPrivs( int uid, int gid ) +void Utility::dropGroupPrivs( uid_t uid, gid_t gid ) { if(gid) { if(setgid(gid)<0) { @@ -152,7 +152,7 @@ void Utility::dropGroupPrivs( int uid, int gid ) // Drops the program's user privileges. -void Utility::dropUserPrivs( int uid ) +void Utility::dropUserPrivs( uid_t uid ) { if(uid) { if(setuid(uid)<0) { @@ -181,9 +181,9 @@ int Utility::gettimeofday( struct timeval *tv, void *tz ) // Retrieves a gid using a groupname. -int Utility::makeGidNumeric(const string &group) +gid_t Utility::makeGidNumeric(const string &group) { - int newgid; + gid_t newgid; if(!(newgid=atoi(group.c_str()))) { errno=0; struct group *gr=getgrnam(group.c_str()); @@ -198,9 +198,9 @@ int Utility::makeGidNumeric(const string &group) // Retrieves an uid using a username. -int Utility::makeUidNumeric(const string &username) +uid_t Utility::makeUidNumeric(const string &username) { - int newuid; + uid_t newuid; if(!(newuid=atoi(username.c_str()))) { struct passwd *pw=getpwnam(username.c_str()); if(!pw) { diff --git a/pdns/utility.hh b/pdns/utility.hh index 024fc089f..626131d8b 100644 --- a/pdns/utility.hh +++ b/pdns/utility.hh @@ -121,10 +121,10 @@ public: static const char *inet_ntop( int af, const char *src, char *dst, size_t size ); //! Retrieves a gid using a groupname. - static int makeGidNumeric( const string & group ); + static gid_t makeGidNumeric( const string & group ); //! Retrieves an uid using an username. - static int makeUidNumeric( const string & username ); + static uid_t makeUidNumeric( const string & username ); //! Writes a vector. static int writev( Utility::sock_t socket, const iovec *vector, size_t count ); @@ -133,10 +133,10 @@ public: static void srandom(void); //! Drops the program's group privileges. - static void dropGroupPrivs( int uid, int gid ); + static void dropGroupPrivs( uid_t uid, gid_t gid ); //! Drops the program's user privileges. - static void dropUserPrivs( int uid ); + static void dropUserPrivs( uid_t uid ); //! Sets the socket into Bind-any mode static void setBindAny ( int af, Utility::sock_t socket ); -- 2.40.0