45 #include <sys/cdefs.h>
48 #include <sys/param.h>
49 #include <sys/eventhandler.h>
50 #include <sys/kernel.h>
52 #include <sys/loginclass.h>
53 #include <sys/malloc.h>
54 #include <sys/mutex.h>
55 #include <sys/types.h>
58 #include <sys/queue.h>
59 #include <sys/racct.h>
60 #include <sys/refcount.h>
61 #include <sys/sysproto.h>
62 #include <sys/systm.h>
64 static MALLOC_DEFINE(M_LOGINCLASS,
"loginclass",
"loginclass structures");
71 static struct mtx loginclasses_lock;
77 loginclass_hold(struct loginclass *
lc)
80 refcount_acquire(&lc->lc_refcount);
88 old = lc->lc_refcount;
89 if (old > 1 && atomic_cmpset_int(&lc->lc_refcount, old, old - 1))
92 mtx_lock(&loginclasses_lock);
93 if (refcount_release(&lc->lc_refcount)) {
95 LIST_REMOVE(lc, lc_next);
96 mtx_unlock(&loginclasses_lock);
97 free(lc, M_LOGINCLASS);
101 mtx_unlock(&loginclasses_lock);
114 struct loginclass *
lc, *newlc;
116 if (name[0] ==
'\0' || strlen(name) >= MAXLOGNAME)
119 newlc =
malloc(
sizeof(*newlc), M_LOGINCLASS, M_ZERO | M_WAITOK);
122 mtx_lock(&loginclasses_lock);
123 LIST_FOREACH(lc, &loginclasses, lc_next) {
124 if (strcmp(name, lc->lc_name) != 0)
129 mtx_unlock(&loginclasses_lock);
131 free(newlc, M_LOGINCLASS);
136 strcpy(newlc->lc_name, name);
137 refcount_init(&newlc->lc_refcount, 1);
138 LIST_INSERT_HEAD(&loginclasses, newlc, lc_next);
139 mtx_unlock(&loginclasses_lock);
147 #ifndef _SYS_SYSPROTO_H_
160 struct loginclass *
lc;
164 lc = p->p_ucred->cr_loginclass;
168 lcnamelen = strlen(lc->lc_name) + 1;
172 error = copyout(lc->lc_name, uap->
namebuf, lcnamelen);
180 #ifndef _SYS_SYSPROTO_H_
189 struct proc *p = td->td_proc;
191 char lcname[MAXLOGNAME];
192 struct loginclass *newlc;
193 struct ucred *newcred, *oldcred;
195 error =
priv_check(td, PRIV_PROC_SETLOGINCLASS);
198 error = copyinstr(uap->
namebuf, lcname,
sizeof(lcname), NULL);
209 newcred->cr_loginclass = newlc;
210 p->p_ucred = newcred;
213 racct_proc_ucred_changed(p, oldcred, newcred);
223 void *arg2,
void *arg3),
void *arg2,
void *arg3)
225 struct loginclass *
lc;
227 mtx_lock(&loginclasses_lock);
228 LIST_FOREACH(lc, &loginclasses, lc_next)
229 (
callback)(lc->lc_racct, arg2, arg3);
230 mtx_unlock(&loginclasses_lock);
237 mtx_init(&loginclasses_lock,
"loginclasses lock", NULL, MTX_DEF);
void * malloc(unsigned long size, struct malloc_type *mtp, int flags)
SYSINIT(placeholder, SI_SUB_DUMMY, SI_ORDER_ANY, NULL, NULL)
struct ucred * crcopysafe(struct proc *p, struct ucred *cr)
linker_function_name_callback_t callback
int priv_check(struct thread *td, int priv)
int sys_setloginclass(struct thread *td, struct setloginclass_args *uap)
static MALLOC_DEFINE(M_LOGINCLASS,"loginclass","loginclass structures")
void crfree(struct ucred *cr)
static void lc_init(void)
int sys_getloginclass(struct thread *td, struct getloginclass_args *uap)
struct loginclass * loginclass_find(const char *name)
void racct_destroy(struct racct **racctp)
void free(void *addr, struct malloc_type *mtp)
void mtx_init(struct mtx *m, const char *name, const char *type, int opts)
void loginclass_racct_foreach(void(*callback)(struct racct *racct, void *arg2, void *arg3), void *arg2, void *arg3)
void loginclass_free(struct loginclass *lc)
struct ucred * crget(void)
void racct_create(struct racct **racctp)
LIST_HEAD(SYSINIT(loginclass)