r3708: BUG 1838: patch from Gavrie Philipson <gavrie@disksites.com> to remove stale...
[ira/wip.git] / source / lib / username.c
index 98b8f33aae30990e5b245febdec17903150b310d..317935d396ffade1d1b2ac349b1c70408b20a3ff 100644 (file)
@@ -283,6 +283,11 @@ struct passwd *Get_Pwnam(const char *user)
        fstring user2;
        struct passwd *ret;
 
+       if ( *user == '\0' ) {
+               DEBUG(10,("Get_Pwnam: empty username!\n"));
+               return NULL;
+       }
+
        fstrcpy(user2, user);
 
        DEBUG(5,("Finding user %s\n", user));
@@ -293,13 +298,16 @@ struct passwd *Get_Pwnam(const char *user)
 }
 
 /****************************************************************************
- Check if a user is in a netgroup user list.
+ Check if a user is in a netgroup user list. If at first we don't succeed,
+ try lower case.
 ****************************************************************************/
 
 static BOOL user_in_netgroup_list(const char *user, const char *ngname)
 {
 #ifdef HAVE_NETGROUP
        static char *mydomain = NULL;
+       fstring lowercase_user;
+
        if (mydomain == NULL)
                yp_get_default_domain(&mydomain);
 
@@ -310,11 +318,28 @@ static BOOL user_in_netgroup_list(const char *user, const char *ngname)
 
        DEBUG(5,("looking for user %s of domain %s in netgroup %s\n",
                user, mydomain, ngname));
-       DEBUG(5,("innetgr is %s\n", innetgr(ngname, NULL, user, mydomain)
-               ? "TRUE" : "FALSE"));
 
-       if (innetgr(ngname, NULL, user, mydomain))
+       if (innetgr(ngname, NULL, user, mydomain)) {
+               DEBUG(5,("user_in_netgroup_list: Found\n"));
                return (True);
+       } else {
+
+               /*
+                * Ok, innetgr is case sensitive. Try once more with lowercase
+                * just in case. Attempt to fix #703. JRA.
+                */
+
+               fstrcpy(lowercase_user, user);
+               strlower_m(lowercase_user);
+       
+               DEBUG(5,("looking for user %s of domain %s in netgroup %s\n",
+                       lowercase_user, mydomain, ngname));
+
+               if (innetgr(ngname, NULL, lowercase_user, mydomain)) {
+                       DEBUG(5,("user_in_netgroup_list: Found\n"));
+                       return (True);
+               }
+       }
 #endif /* HAVE_NETGROUP */
        return False;
 }
@@ -386,7 +411,7 @@ static BOOL user_in_winbind_group_list(const char *user, const char *gname, BOOL
        if ( DEBUGLEVEL >= 10 ) {
                DEBUG(10,("user_in_winbind_group_list: using groups -- "));
                for ( i=0; i<num_groups; i++ )
-                       DEBUGADD(10,("%d ", groups[i]));
+                       DEBUGADD(10,("%lu ", (unsigned long)groups[i]));
                DEBUGADD(10,("\n"));    
        }
  
@@ -593,7 +618,7 @@ BOOL user_in_list(const char *user,const char **list, gid_t *groups, size_t n_gr
                                   will return domain local groups; while NT4 or mixed mode 2k DCs
                                   will not */
                        
-                               if ( winbind_lookup_name(NULL, *list, &g_sid, &name_type) 
+                               if ( winbind_lookup_name(domain, groupname, &g_sid, &name_type) 
                                        && ( name_type==SID_NAME_DOM_GRP || 
                                           (strequal(lp_workgroup(), domain) && name_type==SID_NAME_ALIAS) ) )
                                {