X-Git-Url: https://git.saurik.com/apple/xnu.git/blobdiff_plain/743b15655a24ee3fe9f458f383003e011db0558f..13fec9890cf095cc781fdf7b8917cb03bf32dd4c:/bsd/kern/ubc_subr.c?ds=sidebyside diff --git a/bsd/kern/ubc_subr.c b/bsd/kern/ubc_subr.c index 1660c5b7a..2cbd62364 100644 --- a/bsd/kern/ubc_subr.c +++ b/bsd/kern/ubc_subr.c @@ -45,6 +45,7 @@ #include #include #include +#include #include #include @@ -54,6 +55,7 @@ #include #include +#include #include #include /* last */ @@ -346,6 +348,35 @@ ubc_getcred(struct vnode *vp) return (NOCRED); } +int +ubc_setthreadcred(struct vnode *vp, struct proc *p, thread_t thread) +{ + struct ubc_info *uip; + kauth_cred_t credp; + struct uthread *uthread = get_bsdthread_info(thread); + + if (!UBCINFOEXISTS(vp)) + return (1); + + vnode_lock(vp); + + uip = vp->v_ubcinfo; + credp = uip->ui_ucred; + + if (credp == NOCRED) { + /* use per-thread cred, if assumed identity, else proc cred */ + if (uthread == NULL || (uthread->uu_flag & UT_SETUID) == 0) { + uip->ui_ucred = kauth_cred_proc_ref(p); + } else { + uip->ui_ucred = uthread->uu_ucred; + kauth_cred_ref(uip->ui_ucred); + } + } + vnode_unlock(vp); + + return (0); +} + /* * Set the credentials * existing credentials are not changed