This might not be used a lot and might not survive for long, but at least it
authorVolker Lendecke <vlendec@samba.org>
Sun, 7 Mar 2004 08:16:10 +0000 (08:16 +0000)
committerVolker Lendecke <vlendec@samba.org>
Sun, 7 Mar 2004 08:16:10 +0000 (08:16 +0000)
should work as expected :-)

Fix wb_delgrpmember.

Volker
(This used to be commit 9fc0025d12d17b0c68956af481a836eebc32e675)

source3/nsswitch/wbinfo.c
source3/nsswitch/winbindd_acct.c

index 4f6cc4225a7825232af8c61f9ed77556c8eb733b..772332ee59272fe981fb1675c4592765a0ad0cec 100644 (file)
@@ -1179,7 +1179,7 @@ int main(int argc, char **argv)
                        break;
                case 'O':
                        if ( !wbinfo_remove_user_from_group(string_arg) ) {
                        break;
                case 'O':
                        if ( !wbinfo_remove_user_from_group(string_arg) ) {
-                               d_printf("Could not remove user kfrom group\n");
+                               d_printf("Could not remove user from group\n");
                                goto done;
                        }
                        break;
                                goto done;
                        }
                        break;
index 34c7238b846f78f2bb2aced5662e50db5330e224..e6496695cb6aff283d87df22ee36aade7381f54e 100644 (file)
@@ -219,7 +219,7 @@ static WINBINDD_GR* string2group( char *string )
                if ( num_gr_members ) {
                        fstring buffer;
                        
                if ( num_gr_members ) {
                        fstring buffer;
                        
-                       gr_members = (char**)smb_xmalloc(sizeof(char*)*num_gr_members+1);
+                       gr_members = (char**)smb_xmalloc(sizeof(char*)*(num_gr_members+1));
                        
                        i = 0;
                        while ( next_token(&str, buffer, ",", sizeof(buffer)) && i<num_gr_members ) {
                        
                        i = 0;
                        while ( next_token(&str, buffer, ",", sizeof(buffer)) && i<num_gr_members ) {
@@ -661,9 +661,11 @@ static BOOL wb_delgrpmember( WINBINDD_GR *grp, const char *user )
        if ( !grp || !user )
                return False;
        
        if ( !grp || !user )
                return False;
        
-       for ( i=0; i<grp->num_gr_mem && !found; i++ ) {
-               if ( StrCaseCmp( grp->gr_mem[i], user ) == 0 ) 
+       for ( i=0; i<grp->num_gr_mem; i++ ) {
+               if ( StrCaseCmp( grp->gr_mem[i], user ) == 0 ) {
                        found = True;
                        found = True;
+                       break;
+               }
        }
        
        if ( !found ) 
        }
        
        if ( !found ) 
@@ -672,8 +674,10 @@ static BOOL wb_delgrpmember( WINBINDD_GR *grp, const char *user )
        /* still some remaining members */
 
        if ( grp->num_gr_mem > 1 ) {
        /* still some remaining members */
 
        if ( grp->num_gr_mem > 1 ) {
-               memmove( grp->gr_mem[i], grp->gr_mem[i+1], sizeof(char*)*(grp->num_gr_mem-(i+1)) );
+               SAFE_FREE(grp->gr_mem[i]);
                grp->num_gr_mem--;
                grp->num_gr_mem--;
+               grp->gr_mem[i] = grp->gr_mem[grp->num_gr_mem];
+               grp->gr_mem[grp->num_gr_mem] = NULL;
        }
        else {  /* last one */
                free_winbindd_gr( grp );
        }
        else {  /* last one */
                free_winbindd_gr( grp );
@@ -1083,7 +1087,7 @@ enum winbindd_result winbindd_remove_user_from_group(struct winbindd_cli_state *
        group = state->request.data.acct_mgt.groupname;
        user = state->request.data.acct_mgt.username;
        
        group = state->request.data.acct_mgt.groupname;
        user = state->request.data.acct_mgt.username;
        
-       DEBUG(3, ("[%5lu]:  remove_user_to_group: delete %s from %s\n", (unsigned long)state->pid, 
+       DEBUG(3, ("[%5lu]:  remove_user_from_group: delete %s from %s\n", (unsigned long)state->pid, 
                user, group));
        
        /* don't worry about checking the username since we're removing it anyways */
                user, group));
        
        /* don't worry about checking the username since we're removing it anyways */
@@ -1091,7 +1095,7 @@ enum winbindd_result winbindd_remove_user_from_group(struct winbindd_cli_state *
        /* make sure it is a valid group */
        
        if ( !(grp = wb_getgrnam( group )) ) {
        /* make sure it is a valid group */
        
        if ( !(grp = wb_getgrnam( group )) ) {
-               DEBUG(4,("winbindd_remove_user_to_group: Cannot remove a user to a non-extistent group\n"));
+               DEBUG(4,("winbindd_remove_user_from_group: Cannot remove a user from a non-extistent group\n"));
                return WINBINDD_ERROR;  
        }
        
                return WINBINDD_ERROR;  
        }