* 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. */
| 2283 | * space is available. |
| 2284 | */ |
| 2285 | static void |
| 2286 | crsetgroups_locked(struct ucred *cr, int ngrp, gid_t *groups) |
| 2287 | { |
| 2288 | int i; |
| 2289 | int j; |
| 2290 | gid_t g; |
| 2291 | |
| 2292 | KASSERT(cr->cr_agroups >= ngrp, ("cr_ngroups is too small")); |
| 2293 | |
| 2294 | bcopy(groups, cr->cr_groups, ngrp * sizeof(gid_t)); |
| 2295 | cr->cr_ngroups = ngrp; |
| 2296 | |
| 2297 | /* |
| 2298 | * Sort all groups except cr_groups[0] to allow groupmember to |
| 2299 | * perform a binary search. |
| 2300 | * |
| 2301 | * XXX: If large numbers of groups become common this should |
| 2302 | * be replaced with shell sort like linux uses or possibly |
| 2303 | * heap sort. |
| 2304 | */ |
| 2305 | for (i = 2; i < ngrp; i++) { |
| 2306 | g = cr->cr_groups[i]; |
| 2307 | for (j = i-1; j >= 1 && g < cr->cr_groups[j]; j--) |
| 2308 | cr->cr_groups[j + 1] = cr->cr_groups[j]; |
| 2309 | cr->cr_groups[j + 1] = g; |
| 2310 | } |
| 2311 | } |
| 2312 | |
| 2313 | /* |
| 2314 | * Copy groups in to a credential after expanding it if required. |
no outgoing calls
no test coverage detected