]> granicus.if.org Git - pdns/commitdiff
add supplementary groups support
authorKees Monshouwer <mind04@monshouwer.org>
Mon, 22 Apr 2013 19:54:50 +0000 (21:54 +0200)
committermind04 <mind04@monshouwer.org>
Tue, 14 May 2013 11:13:54 +0000 (13:13 +0200)
pdns/unix_utility.cc

index d7b906773d8fbc36403174fc2b8074b097a18492..507b43132466cfde5e60a345edd279e60ff3bc31 100644 (file)
@@ -99,11 +99,19 @@ void Utility::dropPrivs( int uid, int gid )
     else
       theL()<<Logger::Info<<"Set effective group id to "<<gid<<endl;
 
-    if(setgroups(0, NULL)<0) {
-      theL()<<Logger::Critical<<"Unable to drop supplementary gids: "<<stringerror()<<endl;
-      exit(1);
+    struct passwd *pw=getpwuid(uid);
+    if(!pw) {
+      theL()<<Logger::Warning<<"Unable to determine user name for uid "<<uid<<endl;
+      if (setgroups(0, NULL)<0) {
+        theL()<<Logger::Critical<<"Unable to drop supplementary gids: "<<stringerror()<<endl;
+        exit(1);
+      }
+    } else {
+      if (initgroups(pw->pw_name, gid)<0) {
+        theL()<<Logger::Critical<<"Unable to set supplementary groups: "<<stringerror()<<endl;
+        exit(1);
+      }
     }
-
   }
 
   if(uid) {