327
328 /*
329 * Broadcast to other threads, if any.
330 */
331 if (p->p_lwpcnt > 1) {
332 mutex_enter(&p->p_lock); /* to keep thread list safe */
333 first = curthread;
334 for (t = first->t_forw; t != first; t = t->t_forw)
335 t->t_pre_sys = 1; /* so syscall will get new cred */
336 mutex_exit(&p->p_lock);
337 }
338 }
339
340 /*
341 * Put a hold on a cred structure.
342 */
343 void
344 crhold(cred_t *cr)
345 {
346 ASSERT(cr->cr_ref != 0xdeadbeef && cr->cr_ref != 0);
347 atomic_add_32(&cr->cr_ref, 1);
348 }
349
350 /*
351 * Release previous hold on a cred structure. Free it if refcnt == 0.
352 * If cred uses label different from zone label, free it.
353 */
354 void
355 crfree(cred_t *cr)
356 {
357 ASSERT(cr->cr_ref != 0xdeadbeef && cr->cr_ref != 0);
358 if (atomic_add_32_nv(&cr->cr_ref, -1) == 0) {
359 ASSERT(cr != kcred);
360 if (cr->cr_label)
361 label_rele(cr->cr_label);
362 if (cr->cr_klpd)
363 crklpd_rele(cr->cr_klpd);
364 if (cr->cr_zone)
365 zone_cred_rele(cr->cr_zone);
366 if (cr->cr_ksid)
367 kcrsid_rele(cr->cr_ksid);
368 if (cr->cr_grps)
369 crgrprele(cr->cr_grps);
370
371 kmem_cache_free(cred_cache, cr);
372 }
373 }
374
375 /*
376 * Copy a cred structure to a new one and free the old one.
377 * The new cred will have two references. One for the calling process,
378 * and one for the thread.
1450 const gid_t *
1451 crgetggroups(const credgrp_t *grps)
1452 {
1453 return (grps->crg_groups);
1454 }
1455
1456 void
1457 crsetcredgrp(cred_t *cr, credgrp_t *grps)
1458 {
1459 ASSERT(cr->cr_ref <= 2);
1460
1461 if (cr->cr_grps != NULL)
1462 crgrprele(cr->cr_grps);
1463
1464 cr->cr_grps = grps;
1465 }
1466
1467 void
1468 crgrprele(credgrp_t *grps)
1469 {
1470 if (atomic_add_32_nv(&grps->crg_ref, -1) == 0)
1471 kmem_free(grps, CREDGRPSZ(grps->crg_ngroups));
1472 }
1473
1474 static void
1475 crgrphold(credgrp_t *grps)
1476 {
1477 atomic_add_32(&grps->crg_ref, 1);
1478 }
|
327
328 /*
329 * Broadcast to other threads, if any.
330 */
331 if (p->p_lwpcnt > 1) {
332 mutex_enter(&p->p_lock); /* to keep thread list safe */
333 first = curthread;
334 for (t = first->t_forw; t != first; t = t->t_forw)
335 t->t_pre_sys = 1; /* so syscall will get new cred */
336 mutex_exit(&p->p_lock);
337 }
338 }
339
340 /*
341 * Put a hold on a cred structure.
342 */
343 void
344 crhold(cred_t *cr)
345 {
346 ASSERT(cr->cr_ref != 0xdeadbeef && cr->cr_ref != 0);
347 atomic_inc_32(&cr->cr_ref);
348 }
349
350 /*
351 * Release previous hold on a cred structure. Free it if refcnt == 0.
352 * If cred uses label different from zone label, free it.
353 */
354 void
355 crfree(cred_t *cr)
356 {
357 ASSERT(cr->cr_ref != 0xdeadbeef && cr->cr_ref != 0);
358 if (atomic_dec_32_nv(&cr->cr_ref) == 0) {
359 ASSERT(cr != kcred);
360 if (cr->cr_label)
361 label_rele(cr->cr_label);
362 if (cr->cr_klpd)
363 crklpd_rele(cr->cr_klpd);
364 if (cr->cr_zone)
365 zone_cred_rele(cr->cr_zone);
366 if (cr->cr_ksid)
367 kcrsid_rele(cr->cr_ksid);
368 if (cr->cr_grps)
369 crgrprele(cr->cr_grps);
370
371 kmem_cache_free(cred_cache, cr);
372 }
373 }
374
375 /*
376 * Copy a cred structure to a new one and free the old one.
377 * The new cred will have two references. One for the calling process,
378 * and one for the thread.
1450 const gid_t *
1451 crgetggroups(const credgrp_t *grps)
1452 {
1453 return (grps->crg_groups);
1454 }
1455
1456 void
1457 crsetcredgrp(cred_t *cr, credgrp_t *grps)
1458 {
1459 ASSERT(cr->cr_ref <= 2);
1460
1461 if (cr->cr_grps != NULL)
1462 crgrprele(cr->cr_grps);
1463
1464 cr->cr_grps = grps;
1465 }
1466
1467 void
1468 crgrprele(credgrp_t *grps)
1469 {
1470 if (atomic_dec_32_nv(&grps->crg_ref) == 0)
1471 kmem_free(grps, CREDGRPSZ(grps->crg_ngroups));
1472 }
1473
1474 static void
1475 crgrphold(credgrp_t *grps)
1476 {
1477 atomic_inc_32(&grps->crg_ref);
1478 }
|