Lines Matching refs:cr
96 static void crfree_final(struct ucred *cr);
111 static void crsetgroups_internal(struct ucred *cr, int ngrp,
1781 securelevel_gt(struct ucred *cr, int level) in securelevel_gt() argument
1784 return (cr->cr_prison->pr_securelevel > level ? EPERM : 0); in securelevel_gt()
1788 securelevel_ge(struct ucred *cr, int level) in securelevel_ge() argument
1791 return (cr->cr_prison->pr_securelevel >= level ? EPERM : 0); in securelevel_ge()
2329 crcowget(struct ucred *cr) in crcowget() argument
2332 mtx_lock(&cr->cr_mtx); in crcowget()
2333 KASSERT(cr->cr_users > 0, ("%s: users %d not > 0 on cred %p", in crcowget()
2334 __func__, cr->cr_users, cr)); in crcowget()
2335 cr->cr_users++; in crcowget()
2336 cr->cr_ref++; in crcowget()
2337 mtx_unlock(&cr->cr_mtx); in crcowget()
2338 return (cr); in crcowget()
2344 struct ucred *cr, *crold; in crunuse() local
2347 cr = td->td_realucred; in crunuse()
2348 mtx_lock(&cr->cr_mtx); in crunuse()
2349 cr->cr_ref += td->td_ucredref; in crunuse()
2351 KASSERT(cr->cr_users > 0, ("%s: users %d not > 0 on cred %p", in crunuse()
2352 __func__, cr->cr_users, cr)); in crunuse()
2353 cr->cr_users--; in crunuse()
2354 if (cr->cr_users == 0) { in crunuse()
2355 KASSERT(cr->cr_ref > 0, ("%s: ref %ld not > 0 on cred %p", in crunuse()
2356 __func__, cr->cr_ref, cr)); in crunuse()
2357 crold = cr; in crunuse()
2359 cr->cr_ref--; in crunuse()
2362 mtx_unlock(&cr->cr_mtx); in crunuse()
2368 crunusebatch(struct ucred *cr, int users, int ref) in crunusebatch() argument
2372 __func__, users, cr)); in crunusebatch()
2373 mtx_lock(&cr->cr_mtx); in crunusebatch()
2374 KASSERT(cr->cr_users >= users, ("%s: users %d not > %d on cred %p", in crunusebatch()
2375 __func__, cr->cr_users, users, cr)); in crunusebatch()
2376 cr->cr_users -= users; in crunusebatch()
2377 cr->cr_ref += ref; in crunusebatch()
2378 cr->cr_ref -= users; in crunusebatch()
2379 if (cr->cr_users > 0) { in crunusebatch()
2380 mtx_unlock(&cr->cr_mtx); in crunusebatch()
2383 KASSERT(cr->cr_ref >= 0, ("%s: ref %ld not >= 0 on cred %p", in crunusebatch()
2384 __func__, cr->cr_ref, cr)); in crunusebatch()
2385 if (cr->cr_ref > 0) { in crunusebatch()
2386 mtx_unlock(&cr->cr_mtx); in crunusebatch()
2389 crfree_final(cr); in crunusebatch()
2395 struct ucred *cr; in crcowfree() local
2397 cr = crunuse(td); in crcowfree()
2398 if (cr != NULL) in crcowfree()
2399 crfree(cr); in crcowfree()
2430 struct ucred *cr; in credbatch_add() local
2435 cr = td->td_realucred; in credbatch_add()
2436 KASSERT(cr->cr_users > 0, ("%s: users %d not > 0 on cred %p", in credbatch_add()
2437 __func__, cr->cr_users, cr)); in credbatch_add()
2438 if (crb->cred != cr) { in credbatch_add()
2446 crb->cred = cr; in credbatch_add()
2468 struct ucred *cr; in crget() local
2470 cr = malloc(sizeof(*cr), M_CRED, M_WAITOK | M_ZERO); in crget()
2471 mtx_init(&cr->cr_mtx, "cred", NULL, MTX_DEF); in crget()
2472 cr->cr_ref = 1; in crget()
2474 audit_cred_init(cr); in crget()
2477 mac_cred_init(cr); in crget()
2479 cr->cr_groups = cr->cr_smallgroups; in crget()
2480 cr->cr_agroups = nitems(cr->cr_smallgroups); in crget()
2481 return (cr); in crget()
2488 crhold(struct ucred *cr) in crhold() argument
2493 if (__predict_true(td->td_realucred == cr)) { in crhold()
2494 KASSERT(cr->cr_users > 0, ("%s: users %d not > 0 on cred %p", in crhold()
2495 __func__, cr->cr_users, cr)); in crhold()
2497 return (cr); in crhold()
2499 mtx_lock(&cr->cr_mtx); in crhold()
2500 cr->cr_ref++; in crhold()
2501 mtx_unlock(&cr->cr_mtx); in crhold()
2502 return (cr); in crhold()
2509 crfree(struct ucred *cr) in crfree() argument
2514 if (__predict_true(td->td_realucred == cr)) { in crfree()
2515 KASSERT(cr->cr_users > 0, ("%s: users %d not > 0 on cred %p", in crfree()
2516 __func__, cr->cr_users, cr)); in crfree()
2520 mtx_lock(&cr->cr_mtx); in crfree()
2521 KASSERT(cr->cr_users >= 0, ("%s: users %d not >= 0 on cred %p", in crfree()
2522 __func__, cr->cr_users, cr)); in crfree()
2523 cr->cr_ref--; in crfree()
2524 if (cr->cr_users > 0) { in crfree()
2525 mtx_unlock(&cr->cr_mtx); in crfree()
2528 KASSERT(cr->cr_ref >= 0, ("%s: ref %ld not >= 0 on cred %p", in crfree()
2529 __func__, cr->cr_ref, cr)); in crfree()
2530 if (cr->cr_ref > 0) { in crfree()
2531 mtx_unlock(&cr->cr_mtx); in crfree()
2534 crfree_final(cr); in crfree()
2538 crfree_final(struct ucred *cr) in crfree_final() argument
2541 KASSERT(cr->cr_users == 0, ("%s: users %d not == 0 on cred %p", in crfree_final()
2542 __func__, cr->cr_users, cr)); in crfree_final()
2543 KASSERT(cr->cr_ref == 0, ("%s: ref %ld not == 0 on cred %p", in crfree_final()
2544 __func__, cr->cr_ref, cr)); in crfree_final()
2550 if (cr->cr_uidinfo != NULL) in crfree_final()
2551 uifree(cr->cr_uidinfo); in crfree_final()
2552 if (cr->cr_ruidinfo != NULL) in crfree_final()
2553 uifree(cr->cr_ruidinfo); in crfree_final()
2554 if (cr->cr_prison != NULL) in crfree_final()
2555 prison_free(cr->cr_prison); in crfree_final()
2556 if (cr->cr_loginclass != NULL) in crfree_final()
2557 loginclass_free(cr->cr_loginclass); in crfree_final()
2559 audit_cred_destroy(cr); in crfree_final()
2562 mac_cred_destroy(cr); in crfree_final()
2564 mtx_destroy(&cr->cr_mtx); in crfree_final()
2565 if (cr->cr_groups != cr->cr_smallgroups) in crfree_final()
2566 free(cr->cr_groups, M_CRED); in crfree_final()
2567 free(cr, M_CRED); in crfree_final()
2603 crdup(struct ucred *cr) in crdup() argument
2608 crcopy(newcr, cr); in crdup()
2616 cru2x(struct ucred *cr, struct xucred *xcr) in cru2x() argument
2622 xcr->cr_uid = cr->cr_uid; in cru2x()
2624 ngroups = MIN(cr->cr_ngroups, XU_NGROUPS); in cru2x()
2626 bcopy(cr->cr_groups, xcr->cr_groups, in cru2x()
2627 ngroups * sizeof(*cr->cr_groups)); in cru2x()
2711 struct ucred *cr; in proc_unset_cred() local
2714 cr = p->p_ucred; in proc_unset_cred()
2716 KASSERT(cr->cr_users > 0, ("%s: users %d not > 0 on cred %p", in proc_unset_cred()
2717 __func__, cr->cr_users, cr)); in proc_unset_cred()
2718 mtx_lock(&cr->cr_mtx); in proc_unset_cred()
2719 cr->cr_users--; in proc_unset_cred()
2720 if (cr->cr_users == 0) in proc_unset_cred()
2721 KASSERT(cr->cr_ref > 0, ("%s: ref %ld not > 0 on cred %p", in proc_unset_cred()
2722 __func__, cr->cr_ref, cr)); in proc_unset_cred()
2723 mtx_unlock(&cr->cr_mtx); in proc_unset_cred()
2725 (void)chgproccnt(cr->cr_ruidinfo, -1, 0); in proc_unset_cred()
2726 crfree(cr); in proc_unset_cred()
2730 crcopysafe(struct proc *p, struct ucred *cr) in crcopysafe() argument
2738 while (cr->cr_agroups < oldcred->cr_agroups) { in crcopysafe()
2741 crextend(cr, groups); in crcopysafe()
2745 crcopy(cr, oldcred); in crcopysafe()
2756 crextend(struct ucred *cr, int n) in crextend() argument
2760 MPASS2(cr->cr_ref == 1, "'cr_ref' must be 1 (referenced, unshared)"); in crextend()
2761 MPASS2(cr->cr_ngroups == 0, "groups on 'cr' already set!"); in crextend()
2765 if (n <= cr->cr_agroups) in crextend()
2788 if (cr->cr_groups != cr->cr_smallgroups) in crextend()
2789 free(cr->cr_groups, M_CRED); in crextend()
2791 cr->cr_groups = malloc(nbytes, M_CRED, M_WAITOK | M_ZERO); in crextend()
2792 cr->cr_agroups = nbytes / sizeof(gid_t); in crextend()
2850 crsetgroups_internal(struct ucred *cr, int ngrp, const gid_t *groups) in crsetgroups_internal() argument
2853 MPASS2(cr->cr_ref == 1, "'cr_ref' must be 1 (referenced, unshared)"); in crsetgroups_internal()
2854 MPASS2(cr->cr_agroups >= ngrp, "'cr_agroups' too small"); in crsetgroups_internal()
2857 bcopy(groups, cr->cr_groups, ngrp * sizeof(gid_t)); in crsetgroups_internal()
2858 cr->cr_ngroups = ngrp; in crsetgroups_internal()
2870 crsetgroups(struct ucred *cr, int ngrp, const gid_t *groups) in crsetgroups() argument
2881 cr->cr_ngroups = 0; in crsetgroups()
2882 crextend(cr, ngrp); in crsetgroups()
2883 crsetgroups_internal(cr, ngrp, groups); in crsetgroups()
2884 groups_normalize(&cr->cr_ngroups, cr->cr_groups); in crsetgroups()
2895 crsetgroups_fallback(struct ucred *cr, int ngrp, const gid_t *groups, in crsetgroups_fallback() argument
2900 crsetgroups_internal(cr, 1, &fallback); in crsetgroups_fallback()
2902 crsetgroups(cr, ngrp, groups); in crsetgroups_fallback()