if(!::arg()["chroot"].empty()) {
if(::arg().mustDo("master") || ::arg().mustDo("slave"))
gethostbyname("a.root-servers.net"); // this forces all lookup libraries to be loaded
+ Utility::dropGroupPrivs(newuid, newgid);
if(chroot(::arg()["chroot"].c_str())<0 || chdir("/")<0) {
L<<Logger::Error<<"Unable to chroot to '"+::arg()["chroot"]+"': "<<strerror(errno)<<", exiting"<<endl;
exit(1);
}
else
L<<Logger::Error<<"Chrooted to '"<<::arg()["chroot"]<<"'"<<endl;
- }
+ } else {
+ Utility::dropGroupPrivs(newuid, newgid);
+ }
StatWebServer sws;
- Utility::dropPrivs(newuid, newgid);
+ Utility::dropUserPrivs(newuid);
if(::arg().mustDo("recursor")){
DP=new DNSProxy(::arg()["recursor"]);
if(!::arg()["setuid"].empty())
newuid=Utility::makeUidNumeric(::arg()["setuid"]);
+ Utility::dropGroupPrivs(newuid, newgid);
+
if (!::arg()["chroot"].empty()) {
if (chroot(::arg()["chroot"].c_str())<0 || chdir("/") < 0) {
L<<Logger::Error<<"Unable to chroot to '"+::arg()["chroot"]+"': "<<strerror (errno)<<", exiting"<<endl;
}
}
- Utility::dropPrivs(newuid, newgid);
+ Utility::dropUserPrivs(newuid);
g_numThreads = ::arg().asNum("threads") + ::arg().mustDo("pdns-distributes-queries");
makeThreadPipes();
}
-// Drops the program's privileges.
-void Utility::dropPrivs( int uid, int gid )
+// Drops the program's group privileges.
+void Utility::dropGroupPrivs( int uid, int gid )
{
if(gid) {
if(setgid(gid)<0) {
}
}
}
+}
+
+// Drops the program's user privileges.
+void Utility::dropUserPrivs( int uid )
+{
if(uid) {
if(setuid(uid)<0) {
theL()<<Logger::Critical<<"Unable to set effective user id to "<<uid<<": "<<stringerror()<<endl;
//! Sets the random seed.
static void srandom( unsigned int seed );
- //! Drops the program's privileges.
- static void dropPrivs( int uid, int gid );
+ //! Drops the program's group privileges.
+ static void dropGroupPrivs( int uid, int gid );
+
+ //! Drops the program's user privileges.
+ static void dropUserPrivs( int uid );
//! Sets the socket into blocking mode.
static bool setBlocking( Utility::sock_t socket );