#include "dynhandler.hh"
#include "dnsseckeeper.hh"
#include "threadname.hh"
+#include "misc.hh"
#ifdef HAVE_SYSTEMD
#include <systemd/sd-daemon.h>
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");
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;
}
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)
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);
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)
{
//! 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 );