Skip to content

Commit cee857b

Browse files
committed
add supplementary groups support
1 parent 8db49a6 commit cee857b

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

pdns/unix_utility.cc

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -99,11 +99,19 @@ void Utility::dropPrivs( int uid, int gid )
9999
else
100100
theL()<<Logger::Info<<"Set effective group id to "<<gid<<endl;
101101

102-
if(setgroups(0, NULL)<0) {
103-
theL()<<Logger::Critical<<"Unable to drop supplementary gids: "<<stringerror()<<endl;
104-
exit(1);
102+
struct passwd *pw=getpwuid(uid);
103+
if(!pw) {
104+
theL()<<Logger::Warning<<"Unable to determine user name for uid "<<uid<<endl;
105+
if (setgroups(0, NULL)<0) {
106+
theL()<<Logger::Critical<<"Unable to drop supplementary gids: "<<stringerror()<<endl;
107+
exit(1);
108+
}
109+
} else {
110+
if (initgroups(pw->pw_name, gid)<0) {
111+
theL()<<Logger::Critical<<"Unable to set supplementary groups: "<<stringerror()<<endl;
112+
exit(1);
113+
}
105114
}
106-
107115
}
108116

109117
if(uid) {

0 commit comments

Comments
 (0)