From: Karel Zak Date: Wed, 16 Jul 2014 09:04:53 +0000 (+0200) Subject: lslogins: use bit-array, cleanup SELinux code X-Git-Tag: v2.25~59 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=37019cbc27f26c8800019a8f2f358f014d6f1120;p=thirdparty%2Futil-linux.git lslogins: use bit-array, cleanup SELinux code Signed-off-by: Karel Zak --- diff --git a/login-utils/lslogins.c b/login-utils/lslogins.c index 4ade02cf93..7651f091e0 100644 --- a/login-utils/lslogins.c +++ b/login-utils/lslogins.c @@ -261,10 +261,11 @@ struct lslogins_control { char **ulist; size_t ulsiz; - int sel_enabled; unsigned int time_mode; const char *journal_path; + + unsigned int selinux_enabled : 1; }; /* these have to remain global since there's no other reasonable way to pass @@ -692,15 +693,15 @@ static struct lslogins_user *get_user_info(struct lslogins_control *ctl, const c xasprintf(&user->pwd_ctime_max, "%ld", shadow->sp_max); break; case COL_SELINUX: - { #ifdef HAVE_LIBSELINUX + if (ctl->selinux_enabled) { /* typedefs and pointers are pure evil */ - security_context_t con = NULL; - if (getcon(&con) == 0) - user->context = con; + security_context_t con = NULL; + if (getcon(&con) == 0) + user->context = con; + } #endif break; - } case COL_NPROCS: xasprintf(&user->nprocs, "%d", get_nprocs(pwd->pw_uid)); break; @@ -1364,13 +1365,17 @@ int main(int argc, char *argv[]) printf(UTIL_LINUX_VERSION); return EXIT_SUCCESS; case 'Z': - columns[ncolumns++] = COL_SELINUX; + { #ifdef HAVE_LIBSELINUX - ctl->sel_enabled = is_selinux_enabled(); - if (ctl->sel_enabled == -1) - err(EXIT_FAILURE, _("failed to request selinux state")); + int sl = is_selinux_enabled(); + if (sl < 0) + warn(_("failed to request selinux state")); + else + ctl->selinux_enabled = sl == 1; #endif + columns[ncolumns++] = COL_SELINUX; break; + } default: usage(stderr); }