Changeset View
Changeset View
Standalone View
Standalone View
sys/kern/kern_loginclass.c
Show First 20 Lines • Show All 206 Lines • ▼ Show 20 Lines | |||||
int | int | ||||
sys_setloginclass(struct thread *td, struct setloginclass_args *uap) | sys_setloginclass(struct thread *td, struct setloginclass_args *uap) | ||||
{ | { | ||||
struct proc *p = td->td_proc; | struct proc *p = td->td_proc; | ||||
int error; | int error; | ||||
char lcname[MAXLOGNAME]; | char lcname[MAXLOGNAME]; | ||||
struct loginclass *newlc; | struct loginclass *newlc; | ||||
struct ucred *newcred, *oldcred; | struct ucred *newcred, *oldcred; | ||||
struct credwrap *newcredwrap, *oldcredwrap; | |||||
error = priv_check(td, PRIV_PROC_SETLOGINCLASS); | error = priv_check(td, PRIV_PROC_SETLOGINCLASS); | ||||
if (error != 0) | if (error != 0) | ||||
return (error); | return (error); | ||||
error = copyinstr(uap->namebuf, lcname, sizeof(lcname), NULL); | error = copyinstr(uap->namebuf, lcname, sizeof(lcname), NULL); | ||||
if (error != 0) | if (error != 0) | ||||
return (error); | return (error); | ||||
newlc = loginclass_find(lcname); | newlc = loginclass_find(lcname); | ||||
if (newlc == NULL) | if (newlc == NULL) | ||||
return (EINVAL); | return (EINVAL); | ||||
newcred = crget(); | newcred = crget(); | ||||
newcredwrap = crwget(newcred); | |||||
PROC_LOCK(p); | PROC_LOCK(p); | ||||
oldcred = crcopysafe(p, newcred); | oldcred = crcopysafe(p, newcred); | ||||
oldcredwrap = p->p_credwrap; | |||||
newcred->cr_loginclass = newlc; | newcred->cr_loginclass = newlc; | ||||
proc_set_cred(p, newcred); | proc_set_cred(p, newcred, newcredwrap); | ||||
#ifdef RACCT | #ifdef RACCT | ||||
racct_proc_ucred_changed(p, oldcred, newcred); | racct_proc_ucred_changed(p, oldcred, newcred); | ||||
crhold(newcred); | crhold(newcred); | ||||
#endif | #endif | ||||
PROC_UNLOCK(p); | PROC_UNLOCK(p); | ||||
#ifdef RCTL | #ifdef RCTL | ||||
rctl_proc_ucred_changed(p, newcred); | rctl_proc_ucred_changed(p, newcred); | ||||
crfree(newcred); | crfree(newcred); | ||||
#endif | #endif | ||||
loginclass_free(oldcred->cr_loginclass); | loginclass_free(oldcred->cr_loginclass); | ||||
crfree(oldcred); | crfree(oldcred); | ||||
crwfree(oldcredwrap); | |||||
return (0); | return (0); | ||||
} | } | ||||
void | void | ||||
loginclass_racct_foreach(void (*callback)(struct racct *racct, | loginclass_racct_foreach(void (*callback)(struct racct *racct, | ||||
void *arg2, void *arg3), void (*pre)(void), void (*post)(void), | void *arg2, void *arg3), void (*pre)(void), void (*post)(void), | ||||
void *arg2, void *arg3) | void *arg2, void *arg3) | ||||
Show All 12 Lines |