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