Skip to content

Commit 6ee50ce

Browse files
committed
Merge pull request #1198 from mind04/suppgroups
set group and supplementary groups before chroot
2 parents 726b301 + f1d6a7c commit 6ee50ce

File tree

4 files changed

+20
-7
lines changed

4 files changed

+20
-7
lines changed

pdns/common_startup.cc

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -347,16 +347,19 @@ void mainthread()
347347
if(!::arg()["chroot"].empty()) {
348348
if(::arg().mustDo("master") || ::arg().mustDo("slave"))
349349
gethostbyname("a.root-servers.net"); // this forces all lookup libraries to be loaded
350+
Utility::dropGroupPrivs(newuid, newgid);
350351
if(chroot(::arg()["chroot"].c_str())<0 || chdir("/")<0) {
351352
L<<Logger::Error<<"Unable to chroot to '"+::arg()["chroot"]+"': "<<strerror(errno)<<", exiting"<<endl;
352353
exit(1);
353354
}
354355
else
355356
L<<Logger::Error<<"Chrooted to '"<<::arg()["chroot"]<<"'"<<endl;
356-
}
357+
} else {
358+
Utility::dropGroupPrivs(newuid, newgid);
359+
}
357360

358361
StatWebServer sws;
359-
Utility::dropPrivs(newuid, newgid);
362+
Utility::dropUserPrivs(newuid);
360363

361364
if(::arg().mustDo("recursor")){
362365
DP=new DNSProxy(::arg()["recursor"]);

pdns/pdns_recursor.cc

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1830,14 +1830,16 @@ int serviceMain(int argc, char*argv[])
18301830
if(!::arg()["setuid"].empty())
18311831
newuid=Utility::makeUidNumeric(::arg()["setuid"]);
18321832

1833+
Utility::dropGroupPrivs(newuid, newgid);
1834+
18331835
if (!::arg()["chroot"].empty()) {
18341836
if (chroot(::arg()["chroot"].c_str())<0 || chdir("/") < 0) {
18351837
L<<Logger::Error<<"Unable to chroot to '"+::arg()["chroot"]+"': "<<strerror (errno)<<", exiting"<<endl;
18361838
exit(1);
18371839
}
18381840
}
18391841

1840-
Utility::dropPrivs(newuid, newgid);
1842+
Utility::dropUserPrivs(newuid);
18411843
g_numThreads = ::arg().asNum("threads") + ::arg().mustDo("pdns-distributes-queries");
18421844

18431845
makeThreadPipes();

pdns/unix_utility.cc

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,8 +123,8 @@ void Utility::usleep(unsigned long usec)
123123
}
124124

125125

126-
// Drops the program's privileges.
127-
void Utility::dropPrivs( int uid, int gid )
126+
// Drops the program's group privileges.
127+
void Utility::dropGroupPrivs( int uid, int gid )
128128
{
129129
if(gid) {
130130
if(setgid(gid)<0) {
@@ -148,7 +148,12 @@ void Utility::dropPrivs( int uid, int gid )
148148
}
149149
}
150150
}
151+
}
152+
151153

154+
// Drops the program's user privileges.
155+
void Utility::dropUserPrivs( int uid )
156+
{
152157
if(uid) {
153158
if(setuid(uid)<0) {
154159
theL()<<Logger::Critical<<"Unable to set effective user id to "<<uid<<": "<<stringerror()<<endl;

pdns/utility.hh

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,8 +134,11 @@ public:
134134
//! Sets the random seed.
135135
static void srandom( unsigned int seed );
136136

137-
//! Drops the program's privileges.
138-
static void dropPrivs( int uid, int gid );
137+
//! Drops the program's group privileges.
138+
static void dropGroupPrivs( int uid, int gid );
139+
140+
//! Drops the program's user privileges.
141+
static void dropUserPrivs( int uid );
139142

140143
//! Sets the socket into blocking mode.
141144
static bool setBlocking( Utility::sock_t socket );

0 commit comments

Comments
 (0)