Bug 545 - setgroups
Summary: setgroups
Status: CLOSED FIXED
Alias: None
Product: Samba 3.0
Classification: Unclassified
Component: Build environment (show other bugs)
Version: 3.0.0
Hardware: Other other
: P3 normal
Target Milestone: none
Assignee: Tim Potter
QA Contact:
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2003-10-01 03:13 UTC by Joachim Schmitz (mail address dead)
Modified: 2005-08-24 10:20 UTC (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Joachim Schmitz (mail address dead) 2003-10-01 03:13:49 UTC
Hi there 

Searching http://samba.org/cgi-bin/samba-patches for setgroups I found: 
--------------------snip-------------- 
From: "Green, Paul" <Paul.Green@stratus.com> 
To: "Samba Patches (E-mail)" <samba-patches@samba.org> 
Subject: Always define the sys_setgroups function 
Date: Fri, 24 May 2002 14:06:26 -0400 
The program source/nsswitch/wb_client.c calls sys_setgroups unconditionally, 
whether or not the HAVE_SETGROUPS macro is defined or not. But sys_setgroups 
is not defined unless the operating system provides setgroups().  Hence on 
my OS, which does not have setgroups(), I get a compilation error that 
sys_setgroups is not defined. 

I almost sent in a patch to make the call in wb_client.c conditional, but 
then I did some digging (and thinking) and noticed that the custom is to 
make the sys_xxx functions available but return ENOSYS if they have nothing 
to call.  Since wb_client.c is already set up to handle the case where 
sys_setgroups fails, and since it is the only call, I decided to patch 
source/lib/system.c to make sys_setgroups available at all times, even if it 
can do nothing. 

Tested by me on Stratus VOS. Against 2.2.4. I didn't check the 3.0 branch. 

### START OF PATCH ### 

--- oldsamba/source/lib/system.c   Thu May  2 21:03:10 2002 
+++ newsamba/source/lib/system.c   Fri May 24 14:00:33 2002 
@@ -694,8 +694,6 @@ 
 #endif /* HAVE_BROKEN_GETGROUPS */ 
 } 

-#ifdef HAVE_SETGROUPS 
- 
 /************************************************************************** 
  Wrapper for setgroups. Deals with broken (int) case. Automatically used 
  if we have broken getgroups. 
@@ -703,6 +701,8 @@ 

 int sys_setgroups(int setlen, gid_t *gidset) 
 { 
+#ifdef HAVE_SETGROUPS 
+ 
 #if !defined(HAVE_BROKEN_GETGROUPS) 
     return setgroups(setlen, gidset); 
 #else 
@@ -741,9 +741,11 @@ 
     SAFE_FREE(group_list); 
     return 0 ; 
 #endif /* HAVE_BROKEN_GETGROUPS */ 
-} 
- 
+#else /* HAVE_SETGROUPS */ 
+    errno = ENOSYS; 
+    return -1; 
 #endif /* HAVE_SETGROUPS */ 
+} 

 /* 
  * We only wrap pw_name and pw_passwd for now as these 

### END OF PATCH ### 

Thanks 
PG 
-- 
Paul Green, Senior Technical Consultant, Stratus Technologies. 
Voice: +1 978-461-7557; FAX: +1 978-461-3610; Video on request. 
--------------------snip-------------- 

As I stumbled over the same problem (platform nsr-tandem-nsk), I second Paul's 
sugestion. And infact I did report this already against 2.2.8a  in April this 
year (PR#26999, but it doesn't seem to exist anymore?!?, back then I've been in 
contact with Jeremy <jra@dp.samba.org>). The resulting patch in CVS back then 
was slightly different, similar to the one below, but had the same result.

Neither Paul's nor 'my' patch made it into Samba 3.0.0, but is still needed! 

--- source/lib/system.c.orig 2003-08-15 22:39:53.000000000 +0200 
+++ source/lib/system.c      2003-09-30 09:31:40.000000000 +0200 
@@ -741,6 +741,12 @@ 
        return 0 ; 
 #endif /* HAVE_BROKEN_GETGROUPS */ 
 } 
+#else /* no setgroups. */ 
+int sys_setgroups(int setlen, gid_t *gidset) 
+{ 
+       errno = ENOSYS; 
+       return -1; 
+} 

 #endif /* HAVE_SETGROUPS */ 

An additional patch is needed for samba 3.0.0 in lib/system_smbd.c as it uses 
setgroups() instead of sys_setgroups(): 
--- samba-3.0.0/source/lib/system_smbd.c.orig    2003-07-16 17:56:26.000000000 
+0200 
+++ samba-3.0.0/source/lib/system_smbd.c 2003-09-30 12:28:13.000000000 +0200 

@@ -92,7 +92,7 @@ 

        restore_re_gid(); 

-       if (setgroups(ngrp_saved, gids_saved) != 0) { 
+       if (sys_setgroups(ngrp_saved, gids_saved) != 0) { 
                /* yikes! */ 
                DEBUG(0,("ERROR: getgrouplist: failed to reset group list!
\n")); 
                smb_panic("getgrouplist: failed to reset group list!\n"); 

Bye, Jojo
Comment 1 Gerald (Jerry) Carter (dead mail address) 2003-10-01 08:30:20 UTC
Patch applied.  cvs checking coming shortly.
Comment 2 Joachim Schmitz (mail address dead) 2003-10-02 00:16:14 UTC
Hi there

The patch got applied, thanks for that, but the changelog in CVS wrongly 
mentions it to be the fix for bug 550 instead of 545.

Bye, Jojo 
Comment 3 Gerald (Jerry) Carter (dead mail address) 2005-08-24 10:20:46 UTC
sorry for the same, cleaning up the database to prevent unecessary reopens of bugs.