File tree Expand file tree Collapse file tree 4 files changed +20
-7
lines changed Expand file tree Collapse file tree 4 files changed +20
-7
lines changed Original file line number Diff line number Diff line change @@ -347,16 +347,19 @@ void mainthread()
347
347
if (!::arg ()[" chroot" ].empty ()) {
348
348
if (::arg ().mustDo (" master" ) || ::arg ().mustDo (" slave" ))
349
349
gethostbyname (" a.root-servers.net" ); // this forces all lookup libraries to be loaded
350
+ Utility::dropGroupPrivs (newuid, newgid);
350
351
if (chroot (::arg ()[" chroot" ].c_str ())<0 || chdir (" /" )<0 ) {
351
352
L<<Logger::Error<<" Unable to chroot to '" +::arg ()[" chroot" ]+" ': " <<strerror (errno)<<" , exiting" <<endl;
352
353
exit (1 );
353
354
}
354
355
else
355
356
L<<Logger::Error<<" Chrooted to '" <<::arg ()[" chroot" ]<<" '" <<endl;
356
- }
357
+ } else {
358
+ Utility::dropGroupPrivs (newuid, newgid);
359
+ }
357
360
358
361
StatWebServer sws;
359
- Utility::dropPrivs (newuid, newgid );
362
+ Utility::dropUserPrivs (newuid);
360
363
361
364
if (::arg ().mustDo (" recursor" )){
362
365
DP=new DNSProxy (::arg ()[" recursor" ]);
Original file line number Diff line number Diff line change @@ -1830,14 +1830,16 @@ int serviceMain(int argc, char*argv[])
1830
1830
if (!::arg ()[" setuid" ].empty ())
1831
1831
newuid=Utility::makeUidNumeric (::arg ()[" setuid" ]);
1832
1832
1833
+ Utility::dropGroupPrivs (newuid, newgid);
1834
+
1833
1835
if (!::arg ()[" chroot" ].empty ()) {
1834
1836
if (chroot (::arg ()[" chroot" ].c_str ())<0 || chdir (" /" ) < 0 ) {
1835
1837
L<<Logger::Error<<" Unable to chroot to '" +::arg ()[" chroot" ]+" ': " <<strerror (errno)<<" , exiting" <<endl;
1836
1838
exit (1 );
1837
1839
}
1838
1840
}
1839
1841
1840
- Utility::dropPrivs (newuid, newgid );
1842
+ Utility::dropUserPrivs (newuid);
1841
1843
g_numThreads = ::arg ().asNum (" threads" ) + ::arg ().mustDo (" pdns-distributes-queries" );
1842
1844
1843
1845
makeThreadPipes ();
Original file line number Diff line number Diff line change @@ -123,8 +123,8 @@ void Utility::usleep(unsigned long usec)
123
123
}
124
124
125
125
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 )
128
128
{
129
129
if (gid) {
130
130
if (setgid (gid)<0 ) {
@@ -148,7 +148,12 @@ void Utility::dropPrivs( int uid, int gid )
148
148
}
149
149
}
150
150
}
151
+ }
152
+
151
153
154
+ // Drops the program's user privileges.
155
+ void Utility::dropUserPrivs ( int uid )
156
+ {
152
157
if (uid) {
153
158
if (setuid (uid)<0 ) {
154
159
theL ()<<Logger::Critical<<" Unable to set effective user id to " <<uid<<" : " <<stringerror ()<<endl;
Original file line number Diff line number Diff line change @@ -134,8 +134,11 @@ public:
134
134
// ! Sets the random seed.
135
135
static void srandom ( unsigned int seed );
136
136
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 );
139
142
140
143
// ! Sets the socket into blocking mode.
141
144
static bool setBlocking ( Utility::sock_t socket );
You can’t perform that action at this time.
0 commit comments