diff --git a/lib/libutil/login_class.c b/lib/libutil/login_class.c --- a/lib/libutil/login_class.c +++ b/lib/libutil/login_class.c @@ -391,45 +391,50 @@ static void setlogincontext(login_cap_t *lc, const struct passwd *pwd, unsigned long flags) { - if (lc) { - /* Set resources */ - 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 - * (which indicates no specification). - */ - rlim_t const def_val = INT64_MIN + 1, err_val = INT64_MIN; - 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 { - mode_t mode = val; - umask(mode); + if (lc == NULL) + return; + + /* Set resources. */ + if ((flags & LOGIN_SETRESOURCES) != 0) + setclassresources(lc); + + /* See if there's a umask override. */ + if ((flags & LOGIN_SETUMASK) != 0) { + /* + * Make it unlikely that someone would input our default + * sentinel (which indicates no specification). + */ + rlim_t const def_val = INT64_MIN + 1, err_val = INT64_MIN; + 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 { + mode_t mode = val; + umask(mode); + } } - } } - /* Set paths */ - if (flags & LOGIN_SETPATH) - setclassenvironment(lc, pwd, 1); - /* Set environment */ - if (flags & LOGIN_SETENV) - setclassenvironment(lc, pwd, 0); - /* Set cpu affinity */ - if (flags & LOGIN_SETCPUMASK) - setclasscpumask(lc); - } + + /* Set paths. */ + if ((flags & LOGIN_SETPATH) != 0) + setclassenvironment(lc, pwd, 1); + + /* Set environment. */ + if ((flags & LOGIN_SETENV) != 0) + setclassenvironment(lc, pwd, 0); + + /* Set cpu affinity. */ + if ((flags & LOGIN_SETCPUMASK) != 0) + setclasscpumask(lc); }