aboutsummaryrefslogtreecommitdiff
path: root/lib/libutil
diff options
context:
space:
mode:
Diffstat (limited to 'lib/libutil')
-rw-r--r--lib/libutil/Makefile3
-rw-r--r--lib/libutil/login_class.c55
2 files changed, 32 insertions, 26 deletions
diff --git a/lib/libutil/Makefile b/lib/libutil/Makefile
index f6251c093345..d54d9af38a34 100644
--- a/lib/libutil/Makefile
+++ b/lib/libutil/Makefile
@@ -147,7 +147,8 @@ MLINKS+=uucplock.3 uu_lock.3
MLINKS+=uucplock.3 uu_lock_txfr.3
MLINKS+=uucplock.3 uu_lockerr.3
MLINKS+=uucplock.3 uu_unlock.3
-MAN+= login.conf.5
+
+MANNODEV= login.conf.5
HAS_TESTS=
SUBDIR.${MK_TESTS}+= tests
diff --git a/lib/libutil/login_class.c b/lib/libutil/login_class.c
index c3c1b0ddda27..9478b4dc98ca 100644
--- a/lib/libutil/login_class.c
+++ b/lib/libutil/login_class.c
@@ -543,7 +543,7 @@ setusercontext(login_cap_t *lc, const struct passwd *pwd, uid_t uid, unsigned in
/* we need a passwd entry to set these */
if (pwd == NULL)
- flags &= ~(LOGIN_SETGROUP | LOGIN_SETLOGIN | LOGIN_SETMAC);
+ flags &= ~(LOGIN_SETGROUP | LOGIN_SETLOGIN);
/* Set the process priority */
if (flags & LOGIN_SETPRIORITY)
@@ -564,6 +564,27 @@ setusercontext(login_cap_t *lc, const struct passwd *pwd, uid_t uid, unsigned in
}
}
+ /* Set the sessions login */
+ if ((flags & LOGIN_SETLOGIN) && setlogin(pwd->pw_name) != 0) {
+ syslog(LOG_ERR, "setlogin(%s): %m", pwd->pw_name);
+ login_close(llc);
+ return (-1);
+ }
+
+ /* Inform the kernel about current login class */
+ if (lc != NULL && lc->lc_class != NULL && (flags & LOGIN_SETLOGINCLASS)) {
+ error = setloginclass(lc->lc_class);
+ if (error != 0) {
+ syslog(LOG_ERR, "setloginclass(%s): %m", lc->lc_class);
+#ifdef notyet
+ login_close(llc);
+ return (-1);
+#endif
+ }
+ }
+
+ setlogincontext(lc, pwd, flags);
+
/* Set up the user's MAC label. */
if ((flags & LOGIN_SETMAC) && mac_is_present(NULL) == 1) {
const char *label_string;
@@ -572,8 +593,10 @@ setusercontext(login_cap_t *lc, const struct passwd *pwd, uid_t uid, unsigned in
label_string = login_getcapstr(lc, "label", NULL, NULL);
if (label_string != NULL) {
if (mac_from_text(&label, label_string) == -1) {
- syslog(LOG_ERR, "mac_from_text('%s') for %s: %m",
- pwd->pw_name, label_string);
+ syslog(LOG_ERR, "mac_from_text('%s') for %s %s: %m",
+ label_string, pwd != NULL ? "user" : "class",
+ pwd != NULL ? pwd->pw_name : lc->lc_class);
+ login_close(llc);
return (-1);
}
if (mac_set_proc(label) == -1)
@@ -582,33 +605,15 @@ setusercontext(login_cap_t *lc, const struct passwd *pwd, uid_t uid, unsigned in
error = 0;
mac_free(label);
if (error != 0) {
- syslog(LOG_ERR, "mac_set_proc('%s') for %s: %s",
- label_string, pwd->pw_name, strerror(error));
+ syslog(LOG_ERR, "mac_set_proc('%s') for %s %s: %s",
+ label_string, pwd != NULL ? "user" : "class",
+ pwd != NULL ? pwd->pw_name : lc->lc_class, strerror(error));
+ login_close(llc);
return (-1);
}
}
}
- /* Set the sessions login */
- if ((flags & LOGIN_SETLOGIN) && setlogin(pwd->pw_name) != 0) {
- syslog(LOG_ERR, "setlogin(%s): %m", pwd->pw_name);
- login_close(llc);
- return (-1);
- }
-
- /* Inform the kernel about current login class */
- if (lc != NULL && lc->lc_class != NULL && (flags & LOGIN_SETLOGINCLASS)) {
- error = setloginclass(lc->lc_class);
- if (error != 0) {
- syslog(LOG_ERR, "setloginclass(%s): %m", lc->lc_class);
-#ifdef notyet
- login_close(llc);
- return (-1);
-#endif
- }
- }
-
- setlogincontext(lc, pwd, flags);
login_close(llc);
/* This needs to be done after anything that needs root privs */