aboutsummaryrefslogtreecommitdiff
path: root/lib/libutil
diff options
context:
space:
mode:
authorOlivier Certner <olce.freebsd@certner.fr>2023-06-20 16:46:31 +0000
committerOlivier Certner <olce@FreeBSD.org>2024-01-29 21:58:06 +0000
commit0dd1705f584947625892988afe59e4cedb5cdd09 (patch)
treeaf51c2abd1612bf87bf339a2d6e5fec798985661 /lib/libutil
parent97256feb7a65cccac51a03846c5308894a2cb445 (diff)
downloadsrc-0dd1705f584947625892988afe59e4cedb5cdd09.tar.gz
src-0dd1705f584947625892988afe59e4cedb5cdd09.zip
Diffstat (limited to 'lib/libutil')
-rw-r--r--lib/libutil/login_class.c59
1 files changed, 33 insertions, 26 deletions
diff --git a/lib/libutil/login_class.c b/lib/libutil/login_class.c
index e578925214bd..c8dd2cd66563 100644
--- a/lib/libutil/login_class.c
+++ b/lib/libutil/login_class.c
@@ -380,6 +380,37 @@ setclasscontext(const char *classname, unsigned int flags)
}
+/*
+ * Private function setting umask from the login class.
+ */
+static void
+setclassumask(login_cap_t *lc, const struct passwd *pwd)
+{
+ /*
+ * Make it unlikely that someone would input our default sentinel
+ * indicating no specification.
+ */
+ const rlim_t def_val = INT64_MIN + 1, err_val = INT64_MIN;
+ const rlim_t val = login_getcapnum(lc, "umask", def_val, err_val);
+
+ if (val != def_val) {
+ if (val < 0 || val > UINT16_MAX) {
+ /* We get here also on 'err_val'. */
+ syslog(LOG_WARNING,
+ "%s%s%sLogin class '%s': "
+ "Invalid umask specification: '%s'",
+ pwd ? "Login '" : "",
+ pwd ? pwd->pw_name : "",
+ pwd ? "': " : "",
+ lc->lc_class,
+ login_getcapstr(lc, "umask", "", ""));
+ } else {
+ const mode_t mode = val;
+
+ umask(mode);
+ }
+ }
+}
/*
* Private function which takes care of processing
@@ -393,32 +424,8 @@ setlogincontext(login_cap_t *lc, const struct passwd *pwd, unsigned long flags)
if (flags & LOGIN_SETRESOURCES)
setclassresources(lc);
/* See if there's a umask override */
- if (flags & LOGIN_SETUMASK) {
- /*
- * Make it unlikely that someone would input our default sentinel
- * indicating no specification.
- */
- const rlim_t def_val = INT64_MIN + 1, err_val = INT64_MIN;
- const rlim_t val = login_getcapnum(lc, "umask", def_val, err_val);
-
- if (val != def_val) {
- if (val < 0 || val > UINT16_MAX) {
- /* We get here also on 'err_val'. */
- syslog(LOG_WARNING,
- "%s%s%sLogin class '%s': "
- "Invalid umask specification: '%s'",
- pwd ? "Login '" : "",
- pwd ? pwd->pw_name : "",
- pwd ? "': " : "",
- lc->lc_class,
- login_getcapstr(lc, "umask", "", ""));
- } else {
- const mode_t mode = val;
-
- umask(mode);
- }
- }
- }
+ if (flags & LOGIN_SETUMASK)
+ setclassumask(lc, pwd);
/* Set paths */
if (flags & LOGIN_SETPATH)
setclassenvironment(lc, pwd, 1);