if (!(uthread->uu_flag & UT_SETUID))
return (ESRCH);
- if ((error = suword(uap->uidp, uthread->uu_ucred->cr_ruid)))
+ if ((error = suword(uap->uidp, kauth_cred_getruid(uthread->uu_ucred))))
return (error);
- if ((error = suword(uap->gidp, uthread->uu_ucred->cr_rgid)))
+ if ((error = suword(uap->gidp, kauth_cred_getrgid(uthread->uu_ucred))))
return (error);
*retval = 0;
int ngrp;
int error;
kauth_cred_t cred;
+ posix_cred_t pcred;
/* grab reference while we muck around with the credential */
cred = kauth_cred_get_with_ref();
+ pcred = posix_cred_get(cred);
if ((ngrp = uap->gidsetsize) == 0) {
- *retval = cred->cr_ngroups;
+ *retval = pcred->cr_ngroups;
kauth_cred_unref(&cred);
return (0);
}
- if (ngrp < cred->cr_ngroups) {
+ if (ngrp < pcred->cr_ngroups) {
kauth_cred_unref(&cred);
return (EINVAL);
}
- ngrp = cred->cr_ngroups;
- if ((error = copyout((caddr_t)cred->cr_groups,
+ ngrp = pcred->cr_ngroups;
+ if ((error = copyout((caddr_t)pcred->cr_groups,
uap->gidset,
ngrp * sizeof(gid_t)))) {
kauth_cred_unref(&cred);
uid_t gmuid = KAUTH_UID_NONE;
int error;
kauth_cred_t my_cred, my_new_cred;
+ posix_cred_t my_pcred;
uid = uap->uid;
my_cred = kauth_cred_proc_ref(p);
+ my_pcred = posix_cred_get(my_cred);
DEBUG_CRED_ENTER("setuid (%d/%d): %p %d\n", p->p_pid, (p->p_pptr ? p->p_pptr->p_pid : 0), my_cred, uap->uid);
AUDIT_ARG(uid, uid);
- if (uid != my_cred->cr_ruid && /* allow setuid(getuid()) */
- uid != my_cred->cr_svuid && /* allow setuid(saved uid) */
+ if (uid != my_pcred->cr_ruid && /* allow setuid(getuid()) */
+ uid != my_pcred->cr_svuid && /* allow setuid(saved uid) */
(error = suser(my_cred, &p->p_acflag))) {
kauth_cred_unref(&my_cred);
return (error);
* chgproccnt uses list lock for protection
*/
(void)chgproccnt(uid, 1);
- (void)chgproccnt(my_cred->cr_ruid, -1);
+ (void)chgproccnt(my_pcred->cr_ruid, -1);
}
/* get current credential and take a reference while we muck with it */
* to something other than the default list for the user, as
* in entering a group or leaving an exclusion group).
*/
- if (!(my_cred->cr_flags & CRF_NOMEMBERD))
+ if (!(my_pcred->cr_flags & CRF_NOMEMBERD))
gmuid = uid;
/*
my_new_cred = kauth_cred_setresuid(my_cred, ruid, uid, svuid, gmuid);
if (my_cred != my_new_cred) {
- DEBUG_CRED_CHANGE("setuid CH(%d): %p/0x%08x -> %p/0x%08x\n", p->p_pid, my_cred, my_cred->cr_flags, my_new_cred, my_new_cred->cr_flags);
+ DEBUG_CRED_CHANGE("setuid CH(%d): %p/0x%08x -> %p/0x%08x\n", p->p_pid, my_cred, my_pcred->cr_flags, my_new_cred, posix_cred_get(my_new_cred)->cr_flags);
proc_lock(p);
/*
continue;
}
p->p_ucred = my_new_cred;
+ /* update cred on proc */
+ PROC_UPDATE_CREDS_ONPROC(p);
+
OSBitOrAtomic(P_SUGID, &p->p_flag);
proc_unlock(p);
}
uid_t euid;
int error;
kauth_cred_t my_cred, my_new_cred;
+ posix_cred_t my_pcred;
DEBUG_CRED_ENTER("seteuid: %d\n", uap->euid);
AUDIT_ARG(euid, euid);
my_cred = kauth_cred_proc_ref(p);
+ my_pcred = posix_cred_get(my_cred);
- if (euid != my_cred->cr_ruid && euid != my_cred->cr_svuid &&
+ if (euid != my_pcred->cr_ruid && euid != my_pcred->cr_svuid &&
(error = suser(my_cred, &p->p_acflag))) {
kauth_cred_unref(&my_cred);
return (error);
* passed in. The subsequent compare is safe, because it is
* a pointer compare rather than a contents compare.
*/
- my_new_cred = kauth_cred_setresuid(my_cred, KAUTH_UID_NONE, euid, KAUTH_UID_NONE, my_cred->cr_gmuid);
+ my_new_cred = kauth_cred_setresuid(my_cred, KAUTH_UID_NONE, euid, KAUTH_UID_NONE, my_pcred->cr_gmuid);
if (my_cred != my_new_cred) {
- DEBUG_CRED_CHANGE("seteuid CH(%d): %p/0x%08x -> %p/0x%08x\n", p->p_pid, my_cred, my_cred->cr_flags, my_new_cred, my_new_cred->cr_flags);
+ DEBUG_CRED_CHANGE("seteuid CH(%d): %p/0x%08x -> %p/0x%08x\n", p->p_pid, my_cred, my_pcred->cr_flags, my_new_cred, posix_cred_get(my_new_cred)->cr_flags);
proc_lock(p);
/*
continue;
}
p->p_ucred = my_new_cred;
+ /* update cred on proc */
+ PROC_UPDATE_CREDS_ONPROC(p);
OSBitOrAtomic(P_SUGID, &p->p_flag);
proc_unlock(p);
}
uid_t ruid, euid;
int error;
kauth_cred_t my_cred, my_new_cred;
+ posix_cred_t my_pcred;
DEBUG_CRED_ENTER("setreuid %d %d\n", uap->ruid, uap->euid);
AUDIT_ARG(ruid, ruid);
my_cred = kauth_cred_proc_ref(p);
+ my_pcred = posix_cred_get(my_cred);
if (((ruid != KAUTH_UID_NONE && /* allow no change of ruid */
- ruid != my_cred->cr_ruid && /* allow ruid = ruid */
- ruid != my_cred->cr_uid && /* allow ruid = euid */
- ruid != my_cred->cr_svuid) || /* allow ruid = svuid */
+ ruid != my_pcred->cr_ruid && /* allow ruid = ruid */
+ ruid != my_pcred->cr_uid && /* allow ruid = euid */
+ ruid != my_pcred->cr_svuid) || /* allow ruid = svuid */
(euid != KAUTH_UID_NONE && /* allow no change of euid */
- euid != my_cred->cr_uid && /* allow euid = euid */
- euid != my_cred->cr_ruid && /* allow euid = ruid */
- euid != my_cred->cr_svuid)) && /* allow euid = svui */
+ euid != my_pcred->cr_uid && /* allow euid = euid */
+ euid != my_pcred->cr_ruid && /* allow euid = ruid */
+ euid != my_pcred->cr_svuid)) && /* allow euid = svui */
(error = suser(my_cred, &p->p_acflag))) { /* allow root user any */
kauth_cred_unref(&my_cred);
return (error);
uid_t new_ruid;
uid_t svuid = KAUTH_UID_NONE;
- new_euid = my_cred->cr_uid;
- new_ruid = my_cred->cr_ruid;
+ new_euid = my_pcred->cr_uid;
+ new_ruid = my_pcred->cr_ruid;
/*
* Set the credential with new info. If there is no change,
* passed in. The subsequent compare is safe, because it is
* a pointer compare rather than a contents compare.
*/
- if (euid == KAUTH_UID_NONE && my_cred->cr_uid != euid) {
+ if (euid == KAUTH_UID_NONE && my_pcred->cr_uid != euid) {
/* changing the effective UID */
new_euid = euid;
OSBitOrAtomic(P_SUGID, &p->p_flag);
}
- if (ruid != KAUTH_UID_NONE && my_cred->cr_ruid != ruid) {
+ if (ruid != KAUTH_UID_NONE && my_pcred->cr_ruid != ruid) {
/* changing the real UID; must do user accounting */
/* chgproccnt uses list lock for protection */
(void)chgproccnt(ruid, 1);
- (void)chgproccnt(my_cred->cr_ruid, -1);
+ (void)chgproccnt(my_pcred->cr_ruid, -1);
new_ruid = ruid;
OSBitOrAtomic(P_SUGID, &p->p_flag);
}
* new effective uid. We are protected from escalation
* by the prechecking.
*/
- if (my_cred->cr_svuid != uap->ruid &&
- my_cred->cr_svuid != uap->euid) {
+ if (my_pcred->cr_svuid != uap->ruid &&
+ my_pcred->cr_svuid != uap->euid) {
svuid = new_euid;
OSBitOrAtomic(P_SUGID, &p->p_flag);
}
- my_new_cred = kauth_cred_setresuid(my_cred, ruid, euid, svuid, my_cred->cr_gmuid);
+ my_new_cred = kauth_cred_setresuid(my_cred, ruid, euid, svuid, my_pcred->cr_gmuid);
if (my_cred != my_new_cred) {
- DEBUG_CRED_CHANGE("setreuid CH(%d): %p/0x%08x -> %p/0x%08x\n", p->p_pid, my_cred, my_cred->cr_flags, my_new_cred, my_new_cred->cr_flags);
+ DEBUG_CRED_CHANGE("setreuid CH(%d): %p/0x%08x -> %p/0x%08x\n", p->p_pid, my_cred, my_pcred->cr_flags, my_new_cred, posix_cred_get(my_new_cred)->cr_flags);
proc_lock(p);
/*
continue;
}
p->p_ucred = my_new_cred;
+ /* update cred on proc */
+ PROC_UPDATE_CREDS_ONPROC(p);
OSBitOrAtomic(P_SUGID, &p->p_flag); /* XXX redundant? */
proc_unlock(p);
}
gid_t svgid = KAUTH_GID_NONE;
int error;
kauth_cred_t my_cred, my_new_cred;
+ posix_cred_t my_pcred;
DEBUG_CRED_ENTER("setgid(%d/%d): %d\n", p->p_pid, (p->p_pptr ? p->p_pptr->p_pid : 0), uap->gid);
AUDIT_ARG(gid, gid);
my_cred = kauth_cred_proc_ref(p);
+ my_pcred = posix_cred_get(my_cred);
- if (gid != my_cred->cr_rgid && /* allow setgid(getgid()) */
- gid != my_cred->cr_svgid && /* allow setgid(saved gid) */
+ if (gid != my_pcred->cr_rgid && /* allow setgid(getgid()) */
+ gid != my_pcred->cr_svgid && /* allow setgid(saved gid) */
(error = suser(my_cred, &p->p_acflag))) {
kauth_cred_unref(&my_cred);
return (error);
continue;
}
p->p_ucred = my_new_cred;
+ /* update cred on proc */
+ PROC_UPDATE_CREDS_ONPROC(p);
OSBitOrAtomic(P_SUGID, &p->p_flag);
proc_unlock(p);
}
gid_t egid;
int error;
kauth_cred_t my_cred, my_new_cred;
+ posix_cred_t my_pcred;
DEBUG_CRED_ENTER("setegid %d\n", uap->egid);
AUDIT_ARG(egid, egid);
my_cred = kauth_cred_proc_ref(p);
+ my_pcred = posix_cred_get(my_cred);
- if (egid != my_cred->cr_rgid &&
- egid != my_cred->cr_svgid &&
+ if (egid != my_pcred->cr_rgid &&
+ egid != my_pcred->cr_svgid &&
(error = suser(my_cred, &p->p_acflag))) {
kauth_cred_unref(&my_cred);
return (error);
my_new_cred = kauth_cred_setresgid(my_cred, KAUTH_GID_NONE, egid, KAUTH_GID_NONE);
if (my_cred != my_new_cred) {
- DEBUG_CRED_CHANGE("setegid(CH)%d: %p/0x%08x->%p/0x%08x\n", p->p_pid, my_cred, my_cred->cr_flags, my_new_cred, my_new_cred->cr_flags);
+ DEBUG_CRED_CHANGE("setegid(CH)%d: %p/0x%08x->%p/0x%08x\n", p->p_pid, my_cred, my_pcred->cr_flags, my_new_cred, posix_cred_get(my_new_cred)->cr_flags);
proc_lock(p);
/*
continue;
}
p->p_ucred = my_new_cred;
+ /* update cred on proc */
+ PROC_UPDATE_CREDS_ONPROC(p);
OSBitOrAtomic(P_SUGID, &p->p_flag);
proc_unlock(p);
}
gid_t rgid, egid;
int error;
kauth_cred_t my_cred, my_new_cred;
+ posix_cred_t my_pcred;
DEBUG_CRED_ENTER("setregid %d %d\n", uap->rgid, uap->egid);
AUDIT_ARG(rgid, rgid);
my_cred = kauth_cred_proc_ref(p);
+ my_pcred = posix_cred_get(my_cred);
if (((rgid != KAUTH_UID_NONE && /* allow no change of rgid */
- rgid != my_cred->cr_rgid && /* allow rgid = rgid */
- rgid != my_cred->cr_gid && /* allow rgid = egid */
- rgid != my_cred->cr_svgid) || /* allow rgid = svgid */
+ rgid != my_pcred->cr_rgid && /* allow rgid = rgid */
+ rgid != my_pcred->cr_gid && /* allow rgid = egid */
+ rgid != my_pcred->cr_svgid) || /* allow rgid = svgid */
(egid != KAUTH_UID_NONE && /* allow no change of egid */
- egid != my_cred->cr_groups[0] && /* allow no change of egid */
- egid != my_cred->cr_gid && /* allow egid = egid */
- egid != my_cred->cr_rgid && /* allow egid = rgid */
- egid != my_cred->cr_svgid)) && /* allow egid = svgid */
+ egid != my_pcred->cr_groups[0] && /* allow no change of egid */
+ egid != my_pcred->cr_gid && /* allow egid = egid */
+ egid != my_pcred->cr_rgid && /* allow egid = rgid */
+ egid != my_pcred->cr_svgid)) && /* allow egid = svgid */
(error = suser(my_cred, &p->p_acflag))) { /* allow root user any */
kauth_cred_unref(&my_cred);
return (error);
/* get current credential and take a reference while we muck with it */
for (;;) {
- uid_t new_egid = my_cred->cr_gid;
- uid_t new_rgid = my_cred->cr_rgid;
+ uid_t new_egid = my_pcred->cr_gid;
+ uid_t new_rgid = my_pcred->cr_rgid;
uid_t svgid = KAUTH_UID_NONE;
* passed in. The subsequent compare is safe, because it is
* a pointer compare rather than a contents compare.
*/
- if (egid == KAUTH_UID_NONE && my_cred->cr_groups[0] != egid) {
+ if (egid == KAUTH_UID_NONE && my_pcred->cr_gid != egid) {
/* changing the effective GID */
new_egid = egid;
OSBitOrAtomic(P_SUGID, &p->p_flag);
}
- if (rgid != KAUTH_UID_NONE && my_cred->cr_rgid != rgid) {
+ if (rgid != KAUTH_UID_NONE && my_pcred->cr_rgid != rgid) {
/* changing the real GID */
new_rgid = rgid;
OSBitOrAtomic(P_SUGID, &p->p_flag);
* new effective gid. We are protected from escalation
* by the prechecking.
*/
- if (my_cred->cr_svgid != uap->rgid &&
- my_cred->cr_svgid != uap->egid) {
+ if (my_pcred->cr_svgid != uap->rgid &&
+ my_pcred->cr_svgid != uap->egid) {
svgid = new_egid;
OSBitOrAtomic(P_SUGID, &p->p_flag);
}
my_new_cred = kauth_cred_setresgid(my_cred, rgid, egid, svgid);
if (my_cred != my_new_cred) {
- DEBUG_CRED_CHANGE("setregid(CH)%d: %p/0x%08x->%p/0x%08x\n", p->p_pid, my_cred, my_cred->cr_flags, my_new_cred, my_new_cred->cr_flags);
+ DEBUG_CRED_CHANGE("setregid(CH)%d: %p/0x%08x->%p/0x%08x\n", p->p_pid, my_cred, my_pcred->cr_flags, my_new_cred, posix_cred_get(my_new_cred)->cr_flags);
proc_lock(p);
/* need to protect for a race where another thread
continue;
}
p->p_ucred = my_new_cred;
+ /* update cred on proc */
+ PROC_UPDATE_CREDS_ONPROC(p);
OSBitOrAtomic(P_SUGID, &p->p_flag); /* XXX redundant? */
proc_unlock(p);
}
proc_t target_proc;
struct uthread *uthread = get_bsdthread_info(current_thread());
kauth_cred_t my_cred, my_target_cred, my_new_cred;
+ posix_cred_t my_target_pcred;
AUDIT_ARG(pid, uap->pid);
AUDIT_ARG(value32, uap->assume);
kauth_cred_ref(uthread->uu_ucred);
my_cred = uthread->uu_ucred;
my_target_cred = kauth_cred_proc_ref(target_proc);
- my_new_cred = kauth_cred_setuidgid(my_cred, my_target_cred->cr_uid, my_target_cred->cr_gid);
+ my_target_pcred = posix_cred_get(my_target_cred);
+ my_new_cred = kauth_cred_setuidgid(my_cred, my_target_pcred->cr_uid, my_target_pcred->cr_gid);
if (my_cred != my_new_cred)
uthread->uu_ucred = my_new_cred;
continue;
}
p->p_ucred = my_new_cred;
+ /* update cred on proc */
+ PROC_UPDATE_CREDS_ONPROC(p);
OSBitOrAtomic(P_SUGID, &p->p_flag);
proc_unlock(p);
}
break;
}
/* Drop old proc reference or our extra reference */
- AUDIT_ARG(groupset, my_cred->cr_groups, ngrp);
+ AUDIT_ARG(groupset, posix_cred_get(my_cred)->cr_groups, ngrp);
kauth_cred_unref(&my_cred);
}
-/*
- * XXX This interface is going away; use kauth_cred_issuser() directly
- * XXX instead.
- */
-int
-is_suser(void)
-{
- proc_t p = current_proc();
-
- if (!p)
- return (0);
-
- return (proc_suser(p) == 0);
-}
-
-
-/*
- * XXX This interface is going away; use kauth_cred_issuser() directly
- * XXX instead.
- */
-int
-is_suser1(void)
-{
- proc_t p = current_proc();
- kauth_cred_t my_cred;
- int err;
-
- if (!p)
- return (0);
-
- my_cred = kauth_cred_proc_ref(p);
-
- err = (suser(my_cred, &p->p_acflag) == 0 ||
- my_cred->cr_ruid == 0 || my_cred->cr_svuid == 0);
- kauth_cred_unref(&my_cred);
- return(err);
-}
-
-
/*
* getlogin
*
security_token_t sec_token;
audit_token_t audit_token;
kauth_cred_t my_cred;
+ posix_cred_t my_pcred;
host_priv_t host_priv;
/*
}
my_cred = kauth_cred_proc_ref(p);
+ my_pcred = posix_cred_get(my_cred);
+
/* XXX mach_init doesn't have a p_ucred when it calls this function */
if (IS_VALID_CRED(my_cred)) {
sec_token.val[0] = kauth_cred_getuid(my_cred);
- sec_token.val[1] = my_cred->cr_gid;
+ sec_token.val[1] = kauth_cred_getgid(my_cred);
} else {
sec_token.val[0] = 0;
sec_token.val[1] = 0;
* changes.
*/
audit_token.val[0] = my_cred->cr_audit.as_aia_p->ai_auid;
- audit_token.val[1] = my_cred->cr_uid;
- audit_token.val[2] = my_cred->cr_gid;
- audit_token.val[3] = my_cred->cr_ruid;
- audit_token.val[4] = my_cred->cr_rgid;
+ audit_token.val[1] = my_pcred->cr_uid;
+ audit_token.val[2] = my_pcred->cr_gid;
+ audit_token.val[3] = my_pcred->cr_ruid;
+ audit_token.val[4] = my_pcred->cr_rgid;
audit_token.val[5] = p->p_pid;
audit_token.val[6] = my_cred->cr_audit.as_aia_p->ai_asid;
audit_token.val[7] = p->p_idversion;
void
cru2x(kauth_cred_t cr, struct xucred *xcr)
{
+ posix_cred_t pcr = posix_cred_get(cr);
bzero(xcr, sizeof(*xcr));
xcr->cr_version = XUCRED_VERSION;
xcr->cr_uid = kauth_cred_getuid(cr);
- xcr->cr_ngroups = cr->cr_ngroups;
- bcopy(cr->cr_groups, xcr->cr_groups, sizeof(xcr->cr_groups));
+ xcr->cr_ngroups = pcr->cr_ngroups;
+ bcopy(pcr->cr_groups, xcr->cr_groups, sizeof(xcr->cr_groups));
}
#if CONFIG_LCTX
case LCID_REMOVE:
/* Only root may Leave/Orphan. */
- if (!is_suser1()) {
+ if (!kauth_cred_issuser(kauth_cred_get())) {
error = EPERM;
goto out;
}
default:
/* Only root may Join/Adopt. */
- if (!is_suser1()) {
+ if (!kauth_cred_issuser(kauth_cred_get())) {
error = EPERM;
goto out;
}