50#include <sys/eventhandler.h>
51#include <sys/kernel.h>
53#include <sys/loginclass.h>
54#include <sys/malloc.h>
61#include <sys/refcount.h>
62#include <sys/rwlock.h>
63#include <sys/sysproto.h>
66static MALLOC_DEFINE(M_LOGINCLASS,
"loginclass",
"loginclass structures");
73static struct rwlock loginclasses_lock;
74RW_SYSINIT(loginclasses_init, &loginclasses_lock,
"loginclasses lock");
77loginclass_hold(
struct loginclass *
lc)
80 refcount_acquire(&
lc->lc_refcount);
87 if (refcount_release_if_not_last(&
lc->lc_refcount))
90 rw_wlock(&loginclasses_lock);
91 if (!refcount_release(&
lc->lc_refcount)) {
92 rw_wunlock(&loginclasses_lock);
96 racct_destroy(&
lc->lc_racct);
97 LIST_REMOVE(
lc, lc_next);
98 rw_wunlock(&loginclasses_lock);
108static struct loginclass *
111 struct loginclass *
lc;
113 rw_assert(&loginclasses_lock, RA_LOCKED);
114 LIST_FOREACH(
lc, &loginclasses, lc_next)
115 if (strcmp(
name,
lc->lc_name) == 0) {
133 struct loginclass *
lc, *new_lc;
135 if (
name[0] ==
'\0' || strlen(
name) >= MAXLOGNAME)
138 lc = curthread->td_ucred->cr_loginclass;
139 if (strcmp(
name,
lc->lc_name) == 0) {
144 rw_rlock(&loginclasses_lock);
146 rw_runlock(&loginclasses_lock);
150 new_lc =
malloc(
sizeof(*new_lc), M_LOGINCLASS, M_ZERO | M_WAITOK);
151 racct_create(&new_lc->lc_racct);
152 refcount_init(&new_lc->lc_refcount, 1);
153 strcpy(new_lc->lc_name,
name);
155 rw_wlock(&loginclasses_lock);
162 LIST_INSERT_HEAD(&loginclasses, new_lc, lc_next);
163 rw_wunlock(&loginclasses_lock);
166 rw_wunlock(&loginclasses_lock);
167 racct_destroy(&new_lc->lc_racct);
168 free(new_lc, M_LOGINCLASS);
177#ifndef _SYS_SYSPROTO_H_
187 struct loginclass *
lc;
190 lc = td->td_ucred->cr_loginclass;
191 lcnamelen = strlen(
lc->lc_name) + 1;
194 return (copyout(
lc->lc_name, uap->
namebuf, lcnamelen));
200#ifndef _SYS_SYSPROTO_H_
209 struct proc *p = td->td_proc;
211 char lcname[MAXLOGNAME];
212 struct loginclass *newlc;
213 struct ucred *newcred, *oldcred;
215 error =
priv_check(td, PRIV_PROC_SETLOGINCLASS);
218 error = copyinstr(uap->
namebuf, lcname,
sizeof(lcname), NULL);
229 newcred->cr_loginclass = newlc;
232 racct_proc_ucred_changed(p, oldcred, newcred);
237 rctl_proc_ucred_changed(p, newcred);
248 void *arg2,
void *arg3),
void (*pre)(
void),
void (*post)(
void),
249 void *arg2,
void *arg3)
251 struct loginclass *
lc;
253 rw_rlock(&loginclasses_lock);
256 LIST_FOREACH(
lc, &loginclasses, lc_next)
260 rw_runlock(&loginclasses_lock);
RW_SYSINIT(khelplistlock, &khelp_list_lock, "helper list lock")
int sys_getloginclass(struct thread *td, struct getloginclass_args *uap)
static MALLOC_DEFINE(M_LOGINCLASS, "loginclass", "loginclass structures")
static struct loginclass * loginclass_lookup(const char *name)
void loginclass_free(struct loginclass *lc)
struct loginclass * loginclass_find(const char *name)
void loginclass_racct_foreach(void(*callback)(struct racct *racct, void *arg2, void *arg3), void(*pre)(void), void(*post)(void), void *arg2, void *arg3)
int sys_setloginclass(struct thread *td, struct setloginclass_args *uap)
void *() malloc(size_t size, struct malloc_type *mtp, int flags)
void free(void *addr, struct malloc_type *mtp)
int priv_check(struct thread *td, int priv)
struct ucred * crget(void)
void proc_set_cred(struct proc *p, struct ucred *newcred)
struct ucred * crcopysafe(struct proc *p, struct ucred *cr)
struct ucred * crhold(struct ucred *cr)
void crfree(struct ucred *cr)
linker_function_name_callback_t callback