summaryrefslogtreecommitdiffstats
path: root/lib/libutil
diff options
context:
space:
mode:
authortrasz <trasz@FreeBSD.org>2011-03-05 12:40:35 +0000
committertrasz <trasz@FreeBSD.org>2011-03-05 12:40:35 +0000
commit62f6a13e39978ed28ac30de98bfd177259f00de2 (patch)
tree8810ff86b50f45ade154877395ba9bd0885b1dea /lib/libutil
parent154e7a9e1b3b5b34692d8c1e59704d1567bbc073 (diff)
downloadFreeBSD-src-62f6a13e39978ed28ac30de98bfd177259f00de2.zip
FreeBSD-src-62f6a13e39978ed28ac30de98bfd177259f00de2.tar.gz
Add two new system calls, setloginclass(2) and getloginclass(2). This makes
it possible for the kernel to track login class the process is assigned to, which is required for RCTL. This change also make setusercontext(3) call setloginclass(2) and makes it possible to retrieve current login class using id(1). Reviewed by: kib (as part of a larger patch)
Diffstat (limited to 'lib/libutil')
-rw-r--r--lib/libutil/login_cap.h3
-rw-r--r--lib/libutil/login_class.c23
2 files changed, 25 insertions, 1 deletions
diff --git a/lib/libutil/login_cap.h b/lib/libutil/login_cap.h
index 082e34b..ec1421b 100644
--- a/lib/libutil/login_cap.h
+++ b/lib/libutil/login_cap.h
@@ -49,7 +49,8 @@
#define LOGIN_SETENV 0x0080 /* set user environment */
#define LOGIN_SETMAC 0x0100 /* set user default MAC label */
#define LOGIN_SETCPUMASK 0x0200 /* set user cpumask */
-#define LOGIN_SETALL 0x03ff /* set everything */
+#define LOGIN_SETLOGINCLASS 0x0400 /* set login class in the kernel */
+#define LOGIN_SETALL 0x07ff /* set everything */
#define BI_AUTH "authorize" /* accepted authentication */
#define BI_REJECT "reject" /* rejected authentication */
diff --git a/lib/libutil/login_class.c b/lib/libutil/login_class.c
index d952940..68fdf2b 100644
--- a/lib/libutil/login_class.c
+++ b/lib/libutil/login_class.c
@@ -40,6 +40,7 @@ __FBSDID("$FreeBSD$");
#include <login_cap.h>
#include <paths.h>
#include <pwd.h>
+#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@@ -425,6 +426,7 @@ setusercontext(login_cap_t *lc, const struct passwd *pwd, uid_t uid, unsigned in
quad_t p;
mode_t mymask;
login_cap_t *llc = NULL;
+ struct sigaction sa, prevsa;
struct rtprio rtp;
int error;
@@ -512,6 +514,27 @@ setusercontext(login_cap_t *lc, const struct passwd *pwd, uid_t uid, unsigned in
return (-1);
}
+ /* Inform the kernel about current login class */
+ if (lc != NULL && lc->lc_class != NULL && (flags & LOGIN_SETLOGINCLASS)) {
+ /*
+ * XXX: This is a workaround to fail gracefully in case the kernel
+ * does not support setloginclass(2).
+ */
+ bzero(&sa, sizeof(sa));
+ sa.sa_handler = SIG_IGN;
+ sigfillset(&sa.sa_mask);
+ sigaction(SIGSYS, &sa, &prevsa);
+ error = setloginclass(lc->lc_class);
+ sigaction(SIGSYS, &prevsa, NULL);
+ if (error != 0) {
+ syslog(LOG_ERR, "setloginclass(%s): %m", lc->lc_class);
+#ifdef notyet
+ login_close(llc);
+ return (-1);
+#endif
+ }
+ }
+
mymask = (flags & LOGIN_SETUMASK) ? umask(LOGIN_DEFUMASK) : 0;
mymask = setlogincontext(lc, pwd, mymask, flags);
login_close(llc);
OpenPOWER on IntegriCloud