FreeBSD/sys/kern/kern_prot.c
/*
 * Copy groups in to a credential, preserving any necessary invariants.
 * Currently this includes the sorting of all supplemental gids.
 * crextend() must have been called before hand to ensure sufficient
 * space is available.
 */
Copy groups in to a credential, preserving any necessary invariants.
Currently this includes the sorting of all supplemental gids.
crextend() must have been called before hand to ensure sufficient
space is available.
Copy groups in to a credential preserving any necessary invariants . Currently this includes the sorting of all supplemental gids . crextend () must have been called before hand to ensure sufficient space is available .
static void
crsetgroups_locked(struct ucred *cr, int ngrp, gid_t *groups)
{
	int i;
	int j;
	gid_t g;
	KASSERT(cr->cr_agroups >= ngrp, ("cr_ngroups is too small"));
	bcopy(groups, cr->cr_groups, ngrp * sizeof(gid_t));
	cr->cr_ngroups = ngrp;
	for (i = 2; i < ngrp; i++) {
		g = cr->cr_groups[i];
		for (j = i-1; j >= 1 && g < cr->cr_groups[j]; j--)
			cr->cr_groups[j + 1] = cr->cr_groups[j];
		cr->cr_groups[j + 1] = g;
	}
}
static void crsetgroups_locked ( struct ucred * cr , int ngrp , gid_t * groups ) { int i ; int j ; gid_t g ; KASSERT ( cr -> cr_agroups >= ngrp , ( " " ) ) ; bcopy ( groups , cr -> cr_groups , ngrp * sizeof ( gid_t ) ) ; cr -> cr_ngroups = ngrp ; for ( i = 2 ; i < ngrp ; i ++ ) { g = cr -> cr_groups [ i ] ; for ( j = i - 1 ; j >= 1 && g < cr -> cr_groups [ j ] ; j -- ) cr -> cr_groups [ j + 1 ] = cr -> cr_groups [ j ] ; cr -> cr_groups [ j + 1 ] = g ; } }
Copy groups in to a credential, preserving any necessary invariants.
Copy groups in to a credential preserving any necessary invariants .
/*
	 * Sort all groups except cr_groups[0] to allow groupmember to
	 * perform a binary search.
	 *
	 * XXX: If large numbers of groups become common this should
	 * be replaced with shell sort like linux uses or possibly
	 * heap sort.
	 */