* Change process credentials. * Callers are responsible for providing the reference for passed credentials * and for freeing old ones. * * Process has to be locked except when it does not have credentials (as it * should not be visible just yet) or when newcred is NULL (as this can be * only used when the process is about to be freed, at which point it should * not be visible anymore). */
| 2177 | * not be visible anymore). |
| 2178 | */ |
| 2179 | void |
| 2180 | proc_set_cred(struct proc *p, struct ucred *newcred) |
| 2181 | { |
| 2182 | struct ucred *cr; |
| 2183 | |
| 2184 | cr = p->p_ucred; |
| 2185 | MPASS(cr != NULL); |
| 2186 | PROC_LOCK_ASSERT(p, MA_OWNED); |
| 2187 | KASSERT(newcred->cr_users == 0, ("%s: users %d not 0 on cred %p", |
| 2188 | __func__, newcred->cr_users, newcred)); |
| 2189 | mtx_lock(&cr->cr_mtx); |
| 2190 | KASSERT(cr->cr_users > 0, ("%s: users %d not > 0 on cred %p", |
| 2191 | __func__, cr->cr_users, cr)); |
| 2192 | cr->cr_users--; |
| 2193 | mtx_unlock(&cr->cr_mtx); |
| 2194 | p->p_ucred = newcred; |
| 2195 | newcred->cr_users = 1; |
| 2196 | PROC_UPDATE_COW(p); |
| 2197 | } |
| 2198 | |
| 2199 | void |
| 2200 | proc_unset_cred(struct proc *p) |
no test coverage detected