mirror of
https://github.com/freebsd/freebsd-src
synced 2024-10-15 12:54:27 +00:00
setusercontext(): Set umask in a separate function, setclassumask()
Reviewed by: emaste Approved by: emaste (mentor) MFC after: 3 days Sponsored by: Kumacom SAS Differential Revision: https://reviews.freebsd.org/D40686
This commit is contained in:
parent
97256feb7a
commit
0dd1705f58
|
@ -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
|
* 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)
|
if (flags & LOGIN_SETRESOURCES)
|
||||||
setclassresources(lc);
|
setclassresources(lc);
|
||||||
/* See if there's a umask override */
|
/* See if there's a umask override */
|
||||||
if (flags & LOGIN_SETUMASK) {
|
if (flags & LOGIN_SETUMASK)
|
||||||
/*
|
setclassumask(lc, 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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
/* Set paths */
|
/* Set paths */
|
||||||
if (flags & LOGIN_SETPATH)
|
if (flags & LOGIN_SETPATH)
|
||||||
setclassenvironment(lc, pwd, 1);
|
setclassenvironment(lc, pwd, 1);
|
||||||
|
|
Loading…
Reference in a new issue