Commit ae2e6490 authored by Gerald Carter's avatar Gerald Carter Committed by Gerald (Jerry) Carter
Browse files

r288: combination of BUG 1081 and patch from J. Klinger -- added...

r288: combination of BUG 1081 and patch from J. Klinger -- added remove_duplicate_gids() to smbd and winbindd
(This used to be commit 95c68103ea9dbd02651e26fcaa15dd054b157529)
parent 335b10ef
Loading
Loading
Loading
Loading
+5 −0
Original line number Diff line number Diff line
@@ -100,6 +100,11 @@ static int getgrouplist_internals(const char *user, gid_t gid, gid_t *groups, in
		return -1;
	}
	
	/* this will remove any duplicates gids in the list and 
	   update the group counter */
	   
	remove_duplicate_gids( grpcnt, groups );

	free(gids_saved);
	return ret;
}
+45 −0
Original line number Diff line number Diff line
@@ -304,3 +304,48 @@ void free_userlist(struct sys_userlist *list_head)
		SAFE_FREE(old_head);
	}
}

/****************************************************************
****************************************************************/

static int int_compare( int *a, int *b ) 
{
	if ( *a == *b )
		return 0;
	else if ( *a < *b )
		return -1;
	else 
		return 1;
}

void remove_duplicate_gids( int *num_groups, gid_t *groups )
{
	int i;
	int count = *num_groups;

	if ( *num_groups <= 0 || !groups )
		return;

	
	DEBUG(8,("remove_duplicate_gids: Enter %d gids\n", *num_groups));

	qsort( groups, *num_groups, sizeof(gid_t), QSORT_CAST int_compare );

	for ( i=1; i<count; ) {
		if ( groups[i-1] == groups[i] ) {
			memmove( &groups[i-1], &groups[i], (count - i + 1)*sizeof(gid_t) );

			/* decrement the total number of groups and do not increment 
			   the loop counter */
			count--;
			continue;
		}
		i++;
	}

	*num_groups = count;

	DEBUG(8,("remove_duplicate_gids: Exit %d gids\n", *num_groups));

	return;
}
+2 −0
Original line number Diff line number Diff line
@@ -1118,6 +1118,8 @@ enum winbindd_result winbindd_getgroups(struct winbindd_cli_state *state)
		}
	}

	remove_duplicate_gids( &num_gids, gid_list );

	/* Send data back to client */

	state->response.data.num_entries = num_gids;