|
|
531551 |
diff -up util-linux-2.23.2/configure.ac.kzak util-linux-2.23.2/configure.ac
|
|
|
531551 |
--- util-linux-2.23.2/configure.ac.kzak 2014-12-12 15:27:43.505631342 +0100
|
|
|
531551 |
+++ util-linux-2.23.2/configure.ac 2014-12-12 15:28:30.571177081 +0100
|
|
|
531551 |
@@ -1027,6 +1027,11 @@ UL_REQUIRES_HAVE([lscpu], [cpu_set_t], [
|
|
|
531551 |
AM_CONDITIONAL(BUILD_LSCPU, test "x$build_lscpu" = xyes)
|
|
|
531551 |
|
|
|
531551 |
|
|
|
531551 |
+UL_BUILD_INIT([lslogins], [check])
|
|
|
531551 |
+UL_REQUIRES_BUILD([lslogins], [libsmartcols])
|
|
|
531551 |
+AM_CONDITIONAL([BUILD_LSLOGINS], [test "x$build_lslogins" = xyes])
|
|
|
531551 |
+
|
|
|
531551 |
+
|
|
|
531551 |
UL_BUILD_INIT([chcpu], [check])
|
|
|
531551 |
UL_REQUIRES_LINUX([chcpu])
|
|
|
531551 |
UL_REQUIRES_HAVE([chcpu], [cpu_set_t], [cpu_set_t type])
|
|
|
531551 |
@@ -1404,6 +1409,37 @@ fi
|
|
|
531551 |
AM_CONDITIONAL(HAVE_SYSTEMD, [test -n "$with_systemdsystemunitdir" -a "x$with_systemdsystemunitdir" != "xno" ])
|
|
|
531551 |
|
|
|
531551 |
|
|
|
531551 |
+#
|
|
|
531551 |
+# Backport from upstrem to RHEL7.1
|
|
|
531551 |
+#
|
|
|
531551 |
+AC_ARG_WITH([systemd],
|
|
|
531551 |
+ AS_HELP_STRING([--with-systemd], [build with support for systemd]),
|
|
|
531551 |
+ [], [with_systemd=check]
|
|
|
531551 |
+)
|
|
|
531551 |
+
|
|
|
531551 |
+have_systemd=no
|
|
|
531551 |
+AS_IF([test "x$with_systemd" != xno], [
|
|
|
531551 |
+ # new version -- all libsystemd-* libs merged into libsystemd
|
|
|
531551 |
+ PKG_CHECK_MODULES([SYSTEMD], [libsystemd], [have_systemd=yes], [have_systemd=no])
|
|
|
531551 |
+ # old versions
|
|
|
531551 |
+ AS_IF([test "x$have_systemd" != "xyes"], [
|
|
|
531551 |
+ PKG_CHECK_MODULES([SYSTEMD_DAEMON], [libsystemd-daemon],
|
|
|
531551 |
+ [have_systemd_daemon=yes], [have_systemd_daemon=no])
|
|
|
531551 |
+ PKG_CHECK_MODULES([SYSTEMD_JOURNAL], [libsystemd-journal],
|
|
|
531551 |
+ [have_systemd_journal=yes], [have_systemd_journal=no])
|
|
|
531551 |
+ AS_IF([test "x$have_systemd_daemon" = "xyes" -a "x$have_systemd_journal" = "xyes" ],[
|
|
|
531551 |
+ have_systemd=yes])
|
|
|
531551 |
+ ])
|
|
|
531551 |
+ AS_CASE([$with_systemd:$have_systemd],
|
|
|
531551 |
+ [yes:no],
|
|
|
531551 |
+ [AC_MSG_ERROR([systemd expected but libsystemd not found])],
|
|
|
531551 |
+ [*:yes],
|
|
|
531551 |
+ AC_DEFINE([HAVE_LIBSYSTEMD], [1], [Define if libsystemd is available])
|
|
|
531551 |
+ )
|
|
|
531551 |
+])
|
|
|
531551 |
+
|
|
|
531551 |
+
|
|
|
531551 |
+
|
|
|
531551 |
AC_ARG_WITH([bashcompletiondir],
|
|
|
531551 |
AS_HELP_STRING([--with-bashcompletiondir=DIR], [Bash completions directory]),
|
|
|
531551 |
[],
|
|
|
531551 |
diff -up util-linux-2.23.2/include/Makemodule.am.kzak util-linux-2.23.2/include/Makemodule.am
|
|
|
531551 |
--- util-linux-2.23.2/include/Makemodule.am.kzak 2013-07-15 10:25:46.277049008 +0200
|
|
|
531551 |
+++ util-linux-2.23.2/include/Makemodule.am 2014-12-12 15:28:30.571177081 +0100
|
|
|
531551 |
@@ -35,6 +35,7 @@ dist_noinst_HEADERS += \
|
|
|
531551 |
include/procutils.h \
|
|
|
531551 |
include/randutils.h \
|
|
|
531551 |
include/rpmatch.h \
|
|
|
531551 |
+ include/readutmp.h \
|
|
|
531551 |
include/setproctitle.h \
|
|
|
531551 |
include/strutils.h \
|
|
|
531551 |
include/swapheader.h \
|
|
|
531551 |
diff -up util-linux-2.23.2/include/readutmp.h.kzak util-linux-2.23.2/include/readutmp.h
|
|
|
531551 |
--- util-linux-2.23.2/include/readutmp.h.kzak 2014-12-12 15:28:30.571177081 +0100
|
|
|
531551 |
+++ util-linux-2.23.2/include/readutmp.h 2014-12-12 15:28:30.571177081 +0100
|
|
|
531551 |
@@ -0,0 +1,28 @@
|
|
|
531551 |
+/* Declarations for GNU's read utmp module.
|
|
|
531551 |
+
|
|
|
531551 |
+ Copyright (C) 1992-2007, 2009-2014 Free Software Foundation, Inc.
|
|
|
531551 |
+
|
|
|
531551 |
+ This program is free software: you can redistribute it and/or modify
|
|
|
531551 |
+ it under the terms of the GNU General Public License as published by
|
|
|
531551 |
+ the Free Software Foundation; either version 3 of the License, or
|
|
|
531551 |
+ (at your option) any later version.
|
|
|
531551 |
+
|
|
|
531551 |
+ This program is distributed in the hope that it will be useful,
|
|
|
531551 |
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
531551 |
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
531551 |
+ GNU General Public License for more details.
|
|
|
531551 |
+
|
|
|
531551 |
+ You should have received a copy of the GNU General Public License
|
|
|
531551 |
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
|
|
531551 |
+
|
|
|
531551 |
+/* Written by jla; revised by djm */
|
|
|
531551 |
+
|
|
|
531551 |
+#ifndef READUTMP_H
|
|
|
531551 |
+#define READUTMP_H
|
|
|
531551 |
+
|
|
|
531551 |
+#include <sys/types.h>
|
|
|
531551 |
+#include <utmp.h>
|
|
|
531551 |
+
|
|
|
531551 |
+int read_utmp (char const *file, size_t *n_entries, struct utmp **utmp_buf);
|
|
|
531551 |
+
|
|
|
531551 |
+#endif /* READUTMP_H */
|
|
|
531551 |
diff -up util-linux-2.23.2/lib/Makemodule.am.kzak util-linux-2.23.2/lib/Makemodule.am
|
|
|
531551 |
--- util-linux-2.23.2/lib/Makemodule.am.kzak 2013-07-30 10:39:26.202738200 +0200
|
|
|
531551 |
+++ util-linux-2.23.2/lib/Makemodule.am 2014-12-12 15:28:30.572177092 +0100
|
|
|
531551 |
@@ -25,7 +25,8 @@ libcommon_la_SOURCES = \
|
|
|
531551 |
lib/wholedisk.c \
|
|
|
531551 |
lib/ttyutils.c \
|
|
|
531551 |
lib/xgetpass.c \
|
|
|
531551 |
- lib/exec_shell.c
|
|
|
531551 |
+ lib/exec_shell.c \
|
|
|
531551 |
+ lib/readutmp.c
|
|
|
531551 |
|
|
|
531551 |
if LINUX
|
|
|
531551 |
libcommon_la_SOURCES += \
|
|
|
531551 |
diff -up util-linux-2.23.2/lib/readutmp.c.kzak util-linux-2.23.2/lib/readutmp.c
|
|
|
531551 |
--- util-linux-2.23.2/lib/readutmp.c.kzak 2014-12-12 15:28:30.572177092 +0100
|
|
|
531551 |
+++ util-linux-2.23.2/lib/readutmp.c 2014-12-12 15:28:30.572177092 +0100
|
|
|
531551 |
@@ -0,0 +1,76 @@
|
|
|
531551 |
+/* GNU's read utmp module.
|
|
|
531551 |
+
|
|
|
531551 |
+ Copyright (C) 1992-2001, 2003-2006, 2009-2014 Free Software Foundation, Inc.
|
|
|
531551 |
+
|
|
|
531551 |
+ This program is free software: you can redistribute it and/or modify
|
|
|
531551 |
+ it under the terms of the GNU General Public License as published by
|
|
|
531551 |
+ the Free Software Foundation; either version 3 of the License, or
|
|
|
531551 |
+ (at your option) any later version.
|
|
|
531551 |
+
|
|
|
531551 |
+ This program is distributed in the hope that it will be useful,
|
|
|
531551 |
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
531551 |
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
531551 |
+ GNU General Public License for more details.
|
|
|
531551 |
+
|
|
|
531551 |
+ You should have received a copy of the GNU General Public License
|
|
|
531551 |
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
|
|
531551 |
+
|
|
|
531551 |
+/* Written by jla; revised by djm */
|
|
|
531551 |
+/* extracted for util-linux by ooprala */
|
|
|
531551 |
+
|
|
|
531551 |
+#include <errno.h>
|
|
|
531551 |
+#include <stdio.h>
|
|
|
531551 |
+
|
|
|
531551 |
+#include <sys/types.h>
|
|
|
531551 |
+#include <sys/stat.h>
|
|
|
531551 |
+#include <signal.h>
|
|
|
531551 |
+#include <stdbool.h>
|
|
|
531551 |
+#include <string.h>
|
|
|
531551 |
+#include <stdlib.h>
|
|
|
531551 |
+#include <stdint.h>
|
|
|
531551 |
+
|
|
|
531551 |
+#include "xalloc.h"
|
|
|
531551 |
+#include "readutmp.h"
|
|
|
531551 |
+
|
|
|
531551 |
+/* Read the utmp entries corresponding to file FILE into freshly-
|
|
|
531551 |
+ malloc'd storage, set *UTMP_BUF to that pointer, set *N_ENTRIES to
|
|
|
531551 |
+ the number of entries, and return zero. If there is any error,
|
|
|
531551 |
+ return -1, setting errno, and don't modify the parameters.
|
|
|
531551 |
+ If OPTIONS & READ_UTMP_CHECK_PIDS is nonzero, omit entries whose
|
|
|
531551 |
+ process-IDs do not currently exist. */
|
|
|
531551 |
+int
|
|
|
531551 |
+read_utmp (char const *file, size_t *n_entries, struct utmp **utmp_buf)
|
|
|
531551 |
+{
|
|
|
531551 |
+ size_t n_read = 0;
|
|
|
531551 |
+ size_t n_alloc = 0;
|
|
|
531551 |
+ struct utmp *utmp = NULL;
|
|
|
531551 |
+ struct utmp *u;
|
|
|
531551 |
+
|
|
|
531551 |
+ /* Ignore the return value for now.
|
|
|
531551 |
+ Solaris' utmpname returns 1 upon success -- which is contrary
|
|
|
531551 |
+ to what the GNU libc version does. In addition, older GNU libc
|
|
|
531551 |
+ versions are actually void. */
|
|
|
531551 |
+ utmpname(file);
|
|
|
531551 |
+
|
|
|
531551 |
+ setutent();
|
|
|
531551 |
+
|
|
|
531551 |
+ errno = 0;
|
|
|
531551 |
+ while ((u = getutent()) != NULL) {
|
|
|
531551 |
+ if (n_read == n_alloc) {
|
|
|
531551 |
+ n_alloc += 32;
|
|
|
531551 |
+ utmp = xrealloc(utmp, n_alloc * sizeof (struct utmp));
|
|
|
531551 |
+ if (!utmp)
|
|
|
531551 |
+ return -1;
|
|
|
531551 |
+ }
|
|
|
531551 |
+ utmp[n_read++] = *u;
|
|
|
531551 |
+ }
|
|
|
531551 |
+ if (!u && errno)
|
|
|
531551 |
+ return -1;
|
|
|
531551 |
+
|
|
|
531551 |
+ endutent();
|
|
|
531551 |
+
|
|
|
531551 |
+ *n_entries = n_read;
|
|
|
531551 |
+ *utmp_buf = utmp;
|
|
|
531551 |
+
|
|
|
531551 |
+ return 0;
|
|
|
531551 |
+}
|
|
|
531551 |
diff -up util-linux-2.23.2/login-utils/login.c.kzak util-linux-2.23.2/login-utils/login.c
|
|
|
531551 |
--- util-linux-2.23.2/login-utils/login.c.kzak 2014-12-12 15:27:43.436630542 +0100
|
|
|
531551 |
+++ util-linux-2.23.2/login-utils/login.c 2014-12-12 15:28:30.573177104 +0100
|
|
|
531551 |
@@ -923,124 +923,6 @@ static void loginpam_session(struct logi
|
|
|
531551 |
}
|
|
|
531551 |
|
|
|
531551 |
/*
|
|
|
531551 |
- * We need to check effective UID/GID. For example $HOME could be on root
|
|
|
531551 |
- * squashed NFS or on NFS with UID mapping and access(2) uses real UID/GID.
|
|
|
531551 |
- * The open(2) seems as the surest solution.
|
|
|
531551 |
- * -- kzak@redhat.com (10-Apr-2009)
|
|
|
531551 |
- */
|
|
|
531551 |
-static int effective_access(const char *path, int mode)
|
|
|
531551 |
-{
|
|
|
531551 |
- int fd = open(path, mode);
|
|
|
531551 |
- if (fd != -1)
|
|
|
531551 |
- close(fd);
|
|
|
531551 |
- return fd == -1 ? -1 : 0;
|
|
|
531551 |
-}
|
|
|
531551 |
-
|
|
|
531551 |
-/*
|
|
|
531551 |
- * Check per accout or global hush-login setting.
|
|
|
531551 |
- *
|
|
|
531551 |
- * Hushed mode is enabled:
|
|
|
531551 |
- *
|
|
|
531551 |
- * a) if global (e.g. /etc/hushlogins) hush file exists:
|
|
|
531551 |
- * 1) for ALL ACCOUNTS if the file is empty
|
|
|
531551 |
- * 2) for the current user if the username or shell are found in the file
|
|
|
531551 |
- *
|
|
|
531551 |
- * b) if ~/.hushlogin file exists
|
|
|
531551 |
- *
|
|
|
531551 |
- * The ~/.hushlogin is ignored if the global hush file exists.
|
|
|
531551 |
- *
|
|
|
531551 |
- * The HUSHLOGIN_FILE login.def variable overwrites the default hush filename.
|
|
|
531551 |
- *
|
|
|
531551 |
- * Note that shadow-utils login(1) does not support "a1)". The "a1)" is
|
|
|
531551 |
- * necessary if you want to use PAM for "Last login" message.
|
|
|
531551 |
- *
|
|
|
531551 |
- * -- Karel Zak <kzak@redhat.com> (26-Aug-2011)
|
|
|
531551 |
- *
|
|
|
531551 |
- *
|
|
|
531551 |
- * Per-account check requires some explanation: As root we may not be able to
|
|
|
531551 |
- * read the directory of the user if it is on an NFS mounted filesystem. We
|
|
|
531551 |
- * temporarily set our effective uid to the user-uid making sure that we keep
|
|
|
531551 |
- * root privs. in the real uid.
|
|
|
531551 |
- *
|
|
|
531551 |
- * A portable solution would require a fork(), but we rely on Linux having the
|
|
|
531551 |
- * BSD setreuid()
|
|
|
531551 |
- */
|
|
|
531551 |
-static int get_hushlogin_status(struct passwd *pwd)
|
|
|
531551 |
-{
|
|
|
531551 |
- const char *files[] = { _PATH_HUSHLOGINS, _PATH_HUSHLOGIN, NULL };
|
|
|
531551 |
- const char *file;
|
|
|
531551 |
- char buf[BUFSIZ];
|
|
|
531551 |
- int i;
|
|
|
531551 |
-
|
|
|
531551 |
- file = getlogindefs_str("HUSHLOGIN_FILE", NULL);
|
|
|
531551 |
- if (file) {
|
|
|
531551 |
- if (!*file)
|
|
|
531551 |
- return 0; /* empty HUSHLOGIN_FILE defined */
|
|
|
531551 |
-
|
|
|
531551 |
- files[0] = file;
|
|
|
531551 |
- files[1] = NULL;
|
|
|
531551 |
- }
|
|
|
531551 |
-
|
|
|
531551 |
- for (i = 0; files[i]; i++) {
|
|
|
531551 |
- int ok = 0;
|
|
|
531551 |
-
|
|
|
531551 |
- file = files[i];
|
|
|
531551 |
-
|
|
|
531551 |
- /* Global hush-file*/
|
|
|
531551 |
- if (*file == '/') {
|
|
|
531551 |
- struct stat st;
|
|
|
531551 |
- FILE *f;
|
|
|
531551 |
-
|
|
|
531551 |
- if (stat(file, &st) != 0)
|
|
|
531551 |
- continue; /* file does not exist */
|
|
|
531551 |
-
|
|
|
531551 |
- if (st.st_size == 0)
|
|
|
531551 |
- return 1; /* for all accounts */
|
|
|
531551 |
-
|
|
|
531551 |
- f = fopen(file, "r");
|
|
|
531551 |
- if (!f)
|
|
|
531551 |
- continue; /* ignore errors... */
|
|
|
531551 |
-
|
|
|
531551 |
- while (ok == 0 && fgets(buf, sizeof(buf), f)) {
|
|
|
531551 |
- buf[strlen(buf) - 1] = '\0';
|
|
|
531551 |
- ok = !strcmp(buf, *buf == '/' ? pwd->pw_shell :
|
|
|
531551 |
- pwd->pw_name);
|
|
|
531551 |
- }
|
|
|
531551 |
- fclose(f);
|
|
|
531551 |
- if (ok)
|
|
|
531551 |
- return 1; /* found username/shell */
|
|
|
531551 |
-
|
|
|
531551 |
- return 0; /* ignore per-account files */
|
|
|
531551 |
- }
|
|
|
531551 |
-
|
|
|
531551 |
- /* Per-account setting */
|
|
|
531551 |
- if (strlen(pwd->pw_dir) + sizeof(file) + 2 > sizeof(buf))
|
|
|
531551 |
- continue;
|
|
|
531551 |
- else {
|
|
|
531551 |
- uid_t ruid = getuid();
|
|
|
531551 |
- gid_t egid = getegid();
|
|
|
531551 |
-
|
|
|
531551 |
- sprintf(buf, "%s/%s", pwd->pw_dir, file);
|
|
|
531551 |
-
|
|
|
531551 |
- if (setregid(-1, pwd->pw_gid) == 0 &&
|
|
|
531551 |
- setreuid(0, pwd->pw_uid) == 0)
|
|
|
531551 |
- ok = effective_access(buf, O_RDONLY) == 0;
|
|
|
531551 |
-
|
|
|
531551 |
- if (setuid(0) != 0 ||
|
|
|
531551 |
- setreuid(ruid, 0) != 0 ||
|
|
|
531551 |
- setregid(-1, egid) != 0) {
|
|
|
531551 |
- syslog(LOG_ALERT, _("hush login status: restore original IDs failed"));
|
|
|
531551 |
- exit(EXIT_FAILURE);
|
|
|
531551 |
- }
|
|
|
531551 |
- if (ok)
|
|
|
531551 |
- return 1; /* enabled by user */
|
|
|
531551 |
- }
|
|
|
531551 |
- }
|
|
|
531551 |
-
|
|
|
531551 |
- return 0;
|
|
|
531551 |
-}
|
|
|
531551 |
-
|
|
|
531551 |
-/*
|
|
|
531551 |
* Detach the controlling terminal, fork, restore syslog stuff and create a new
|
|
|
531551 |
* session.
|
|
|
531551 |
*/
|
|
|
531551 |
@@ -1372,7 +1254,7 @@ int main(int argc, char **argv)
|
|
|
531551 |
|
|
|
531551 |
endpwent();
|
|
|
531551 |
|
|
|
531551 |
- cxt.quiet = get_hushlogin_status(pwd);
|
|
|
531551 |
+ cxt.quiet = get_hushlogin_status(pwd, 1);
|
|
|
531551 |
|
|
|
531551 |
log_utmp(&cxt);
|
|
|
531551 |
log_audit(&cxt, 1);
|
|
|
531551 |
diff -up util-linux-2.23.2/login-utils/logindefs.c.kzak util-linux-2.23.2/login-utils/logindefs.c
|
|
|
531551 |
--- util-linux-2.23.2/login-utils/logindefs.c.kzak 2013-06-13 09:46:10.442650810 +0200
|
|
|
531551 |
+++ util-linux-2.23.2/login-utils/logindefs.c 2014-12-12 15:28:30.573177104 +0100
|
|
|
531551 |
@@ -27,6 +27,9 @@
|
|
|
531551 |
#include <stdlib.h>
|
|
|
531551 |
#include <string.h>
|
|
|
531551 |
#include <sys/syslog.h>
|
|
|
531551 |
+#include <sys/stat.h>
|
|
|
531551 |
+#include <sys/types.h>
|
|
|
531551 |
+#include <pwd.h>
|
|
|
531551 |
|
|
|
531551 |
#include "c.h"
|
|
|
531551 |
#include "closestream.h"
|
|
|
531551 |
@@ -259,6 +262,135 @@ int logindefs_setenv(const char *name, c
|
|
|
531551 |
return val ? setenv(name, val, 1) : -1;
|
|
|
531551 |
}
|
|
|
531551 |
|
|
|
531551 |
+/*
|
|
|
531551 |
+ * We need to check the effective UID/GID. For example, $HOME could be on a
|
|
|
531551 |
+ * root-squashed NFS or on an NFS with UID mapping, and access(2) uses the
|
|
|
531551 |
+ * real UID/GID. Then open(2) seems as the surest solution.
|
|
|
531551 |
+ * -- kzak@redhat.com (10-Apr-2009)
|
|
|
531551 |
+ */
|
|
|
531551 |
+int effective_access(const char *path, int mode)
|
|
|
531551 |
+{
|
|
|
531551 |
+ int fd = open(path, mode);
|
|
|
531551 |
+ if (fd != -1)
|
|
|
531551 |
+ close(fd);
|
|
|
531551 |
+ return fd == -1 ? -1 : 0;
|
|
|
531551 |
+}
|
|
|
531551 |
+
|
|
|
531551 |
+
|
|
|
531551 |
+/*
|
|
|
531551 |
+ * Check the per-account or the global hush-login setting.
|
|
|
531551 |
+ *
|
|
|
531551 |
+ * Hushed mode is enabled:
|
|
|
531551 |
+ *
|
|
|
531551 |
+ * a) if a global (e.g. /etc/hushlogins) hush file exists:
|
|
|
531551 |
+ * 1) for ALL ACCOUNTS if the file is empty
|
|
|
531551 |
+ * 2) for the current user if the username or shell is found in the file
|
|
|
531551 |
+ *
|
|
|
531551 |
+ * b) if a ~/.hushlogin file exists
|
|
|
531551 |
+ *
|
|
|
531551 |
+ * The ~/.hushlogin file is ignored if the global hush file exists.
|
|
|
531551 |
+ *
|
|
|
531551 |
+ * The HUSHLOGIN_FILE login.def variable overrides the default hush filename.
|
|
|
531551 |
+ *
|
|
|
531551 |
+ * Note that shadow-utils login(1) does not support "a1)". The "a1)" is
|
|
|
531551 |
+ * necessary if you want to use PAM for "Last login" message.
|
|
|
531551 |
+ *
|
|
|
531551 |
+ * -- Karel Zak <kzak@redhat.com> (26-Aug-2011)
|
|
|
531551 |
+ *
|
|
|
531551 |
+ *
|
|
|
531551 |
+ * The per-account check requires some explanation: As root we may not be able
|
|
|
531551 |
+ * to read the directory of the user if it is on an NFS-mounted filesystem. We
|
|
|
531551 |
+ * temporarily set our effective uid to the user-uid, making sure that we keep
|
|
|
531551 |
+ * root privileges in the real uid.
|
|
|
531551 |
+ *
|
|
|
531551 |
+ * A portable solution would require a fork(), but we rely on Linux having the
|
|
|
531551 |
+ * BSD setreuid().
|
|
|
531551 |
+ */
|
|
|
531551 |
+
|
|
|
531551 |
+int get_hushlogin_status(struct passwd *pwd, int force_check)
|
|
|
531551 |
+{
|
|
|
531551 |
+ const char *files[] = { _PATH_HUSHLOGINS, _PATH_HUSHLOGIN, NULL };
|
|
|
531551 |
+ const char *file;
|
|
|
531551 |
+ char buf[BUFSIZ];
|
|
|
531551 |
+ int i;
|
|
|
531551 |
+
|
|
|
531551 |
+ file = getlogindefs_str("HUSHLOGIN_FILE", NULL);
|
|
|
531551 |
+ if (file) {
|
|
|
531551 |
+ if (!*file)
|
|
|
531551 |
+ return 0; /* empty HUSHLOGIN_FILE defined */
|
|
|
531551 |
+
|
|
|
531551 |
+ files[0] = file;
|
|
|
531551 |
+ files[1] = NULL;
|
|
|
531551 |
+ }
|
|
|
531551 |
+
|
|
|
531551 |
+ for (i = 0; files[i]; i++) {
|
|
|
531551 |
+ int ok = 0;
|
|
|
531551 |
+
|
|
|
531551 |
+ file = files[i];
|
|
|
531551 |
+
|
|
|
531551 |
+ /* global hush-file */
|
|
|
531551 |
+ if (*file == '/') {
|
|
|
531551 |
+ struct stat st;
|
|
|
531551 |
+ FILE *f;
|
|
|
531551 |
+
|
|
|
531551 |
+ if (stat(file, &st) != 0)
|
|
|
531551 |
+ continue; /* file does not exist */
|
|
|
531551 |
+
|
|
|
531551 |
+ if (st.st_size == 0)
|
|
|
531551 |
+ return 1; /* for all accounts */
|
|
|
531551 |
+
|
|
|
531551 |
+ f = fopen(file, "r");
|
|
|
531551 |
+ if (!f)
|
|
|
531551 |
+ continue; /* ignore errors... */
|
|
|
531551 |
+
|
|
|
531551 |
+ while (ok == 0 && fgets(buf, sizeof(buf), f)) {
|
|
|
531551 |
+ buf[strlen(buf) - 1] = '\0';
|
|
|
531551 |
+ ok = !strcmp(buf, *buf == '/' ? pwd->pw_shell :
|
|
|
531551 |
+ pwd->pw_name);
|
|
|
531551 |
+ }
|
|
|
531551 |
+ fclose(f);
|
|
|
531551 |
+ if (ok)
|
|
|
531551 |
+ return 1; /* found username/shell */
|
|
|
531551 |
+
|
|
|
531551 |
+ return 0; /* ignore per-account files */
|
|
|
531551 |
+ }
|
|
|
531551 |
+
|
|
|
531551 |
+ /* per-account setting */
|
|
|
531551 |
+ if (strlen(pwd->pw_dir) + sizeof(file) + 2 > sizeof(buf))
|
|
|
531551 |
+ continue;
|
|
|
531551 |
+
|
|
|
531551 |
+ sprintf(buf, "%s/%s", pwd->pw_dir, file);
|
|
|
531551 |
+
|
|
|
531551 |
+ if (force_check) {
|
|
|
531551 |
+ uid_t ruid = getuid();
|
|
|
531551 |
+ gid_t egid = getegid();
|
|
|
531551 |
+
|
|
|
531551 |
+ if (setregid(-1, pwd->pw_gid) == 0 &&
|
|
|
531551 |
+ setreuid(0, pwd->pw_uid) == 0)
|
|
|
531551 |
+ ok = effective_access(buf, O_RDONLY) == 0;
|
|
|
531551 |
+
|
|
|
531551 |
+ if (setuid(0) != 0 ||
|
|
|
531551 |
+ setreuid(ruid, 0) != 0 ||
|
|
|
531551 |
+ setregid(-1, egid) != 0) {
|
|
|
531551 |
+ syslog(LOG_ALERT, _("hush login status: restore original IDs failed"));
|
|
|
531551 |
+ exit(EXIT_FAILURE);
|
|
|
531551 |
+ }
|
|
|
531551 |
+ if (ok)
|
|
|
531551 |
+ return 1; /* enabled by user */
|
|
|
531551 |
+ }
|
|
|
531551 |
+ else {
|
|
|
531551 |
+ int rc;
|
|
|
531551 |
+ rc = effective_access(buf, O_RDONLY);
|
|
|
531551 |
+ if (rc == 0)
|
|
|
531551 |
+ return 1;
|
|
|
531551 |
+ else if (rc == -1 && errno == EACCES)
|
|
|
531551 |
+ return -1;
|
|
|
531551 |
+ }
|
|
|
531551 |
+
|
|
|
531551 |
+ }
|
|
|
531551 |
+
|
|
|
531551 |
+ return 0;
|
|
|
531551 |
+}
|
|
|
531551 |
#ifdef TEST_PROGRAM
|
|
|
531551 |
int main(int argc, char *argv[])
|
|
|
531551 |
{
|
|
|
531551 |
diff -up util-linux-2.23.2/login-utils/logindefs.h.kzak util-linux-2.23.2/login-utils/logindefs.h
|
|
|
531551 |
--- util-linux-2.23.2/login-utils/logindefs.h.kzak 2013-02-27 17:46:29.887020770 +0100
|
|
|
531551 |
+++ util-linux-2.23.2/login-utils/logindefs.h 2014-12-12 15:28:30.573177104 +0100
|
|
|
531551 |
@@ -8,5 +8,7 @@ extern unsigned long getlogindefs_num(co
|
|
|
531551 |
extern const char *getlogindefs_str(const char *name, const char *dflt);
|
|
|
531551 |
extern void free_getlogindefs_data(void);
|
|
|
531551 |
extern int logindefs_setenv(const char *name, const char *conf, const char *dflt);
|
|
|
531551 |
+extern int effective_access(const char *path, int mode);
|
|
|
531551 |
+extern int get_hushlogin_status(struct passwd *pwd, int force_check);
|
|
|
531551 |
|
|
|
531551 |
#endif /* UTIL_LINUX_LOGINDEFS_H */
|
|
|
531551 |
diff -up util-linux-2.23.2/login-utils/lslogins.1.kzak util-linux-2.23.2/login-utils/lslogins.1
|
|
|
531551 |
--- util-linux-2.23.2/login-utils/lslogins.1.kzak 2014-12-12 15:28:30.574177115 +0100
|
|
|
531551 |
+++ util-linux-2.23.2/login-utils/lslogins.1 2014-12-12 15:28:30.574177115 +0100
|
|
|
531551 |
@@ -0,0 +1,132 @@
|
|
|
531551 |
+.\" Copyright 2014 Ondrej Oprala (ondrej.oprala@gmail.com)
|
|
|
531551 |
+.\" May be distributed under the GNU General Public License
|
|
|
531551 |
+.TH LSLOGINS "1" "April 2014" "util-linux" "User Commands"
|
|
|
531551 |
+.SH NAME
|
|
|
531551 |
+lslogins \- display information about known users in the system
|
|
|
531551 |
+.SH SYNOPSIS
|
|
|
531551 |
+.B lslogins
|
|
|
531551 |
+[\fIoptions\fR] [\fB-s\fR|\fB-u\fR[=\fIUID\fR]] [\fB-g \fIgroups\fR] [\fB-l \fIlogins\fR]
|
|
|
531551 |
+.SH DESCRIPTION
|
|
|
531551 |
+.PP
|
|
|
531551 |
+Examine the wtmp and btmp logs, /etc/shadow (if necessary) and /etc/passwd
|
|
|
531551 |
+and output the desired data.
|
|
|
531551 |
+.PP
|
|
|
531551 |
+The default action is to list info about all the users in the system.
|
|
|
531551 |
+.SH OPTIONS
|
|
|
531551 |
+Mandatory arguments to long options are mandatory for short options too.
|
|
|
531551 |
+.TP
|
|
|
531551 |
+\fB\-a\fR, \fB\-\-acc\-expiration\fR
|
|
|
531551 |
+Display data about the date of last password change and the account expiration
|
|
|
531551 |
+date (see \fBshadow\fR(5) for more info). (Requires root priviliges.)
|
|
|
531551 |
+.TP
|
|
|
531551 |
+\fB\-\-btmp\-file \fIpath\fP
|
|
|
531551 |
+Alternate path for btmp.
|
|
|
531551 |
+.TP
|
|
|
531551 |
+\fB\-c\fR, \fB\-\-colon\-separate\fR
|
|
|
531551 |
+Separate info about each user with a colon instead of a newline.
|
|
|
531551 |
+.TP
|
|
|
531551 |
+\fB\-e\fR, \fB\-\-export\fR
|
|
|
531551 |
+Output data in the format of NAME=VALUE.
|
|
|
531551 |
+.TP
|
|
|
531551 |
+\fB\-f\fR, \fB\-\-failed\fR
|
|
|
531551 |
+Display data about the users' last failed login attempts.
|
|
|
531551 |
+.TP
|
|
|
531551 |
+\fB\-G\fR, \fB\-\-groups\-info\fR
|
|
|
531551 |
+Show information about groups.
|
|
|
531551 |
+.TP
|
|
|
531551 |
+\fB\-g\fR, \fB\-\-groups\fR=\fIgroups\fR
|
|
|
531551 |
+Only show data of users belonging to \fIgroups\fR. More than one group
|
|
|
531551 |
+may be specified; the list has to be comma-separated.
|
|
|
531551 |
+.TP
|
|
|
531551 |
+\fB\-h\fR, \fB\-\-help\fR
|
|
|
531551 |
+Display help information and exit.
|
|
|
531551 |
+.TP
|
|
|
531551 |
+\fB\-L\fR, \fB\-\-last\fR
|
|
|
531551 |
+Display data containing information about the users' last login sessions.
|
|
|
531551 |
+.TP
|
|
|
531551 |
+\fB\-l\fR, \fB\-\-logins\fR=\fIlogins\fR
|
|
|
531551 |
+Only show data of users with a login specified in \fIlogins\fR (user names or user
|
|
|
531551 |
+IDS). More than one login may be specified; the list has to be comma-separated.
|
|
|
531551 |
+.TP
|
|
|
531551 |
+\fB\-m\fR, \fB\-\-supp\-groups\fR
|
|
|
531551 |
+Show supplementary groups.
|
|
|
531551 |
+.TP
|
|
|
531551 |
+\fB\-n\fR, \fB\-\-newline\fR
|
|
|
531551 |
+Display each piece of information on a separate line.
|
|
|
531551 |
+.TP
|
|
|
531551 |
+\fB\-\-noheadings\fR
|
|
|
531551 |
+Do not print a header line.
|
|
|
531551 |
+.TP
|
|
|
531551 |
+\fB\-\-notruncate\fR
|
|
|
531551 |
+Don't truncate output.
|
|
|
531551 |
+.TP
|
|
|
531551 |
+\fB\-o\fR, \fB\-\-output \fIlist\fP
|
|
|
531551 |
+Specify which output columns to print. Use
|
|
|
531551 |
+.B \-\-help
|
|
|
531551 |
+to get a list of all supported columns.
|
|
|
531551 |
+.TP
|
|
|
531551 |
+\fB\-p\fR, \fB\-\-pwd\fR
|
|
|
531551 |
+Display information related to login by password (see also \fB\-afL).
|
|
|
531551 |
+.TP
|
|
|
531551 |
+\fB\-r\fR, \fB\-\-raw\fR
|
|
|
531551 |
+Raw output (no columnation).
|
|
|
531551 |
+.TP
|
|
|
531551 |
+\fB\-s\fR, \fB\-\-system\-accs\fR[=\fIthreshold\fR]
|
|
|
531551 |
+Show system accounts. These are by default all accounts with a UID below 1000
|
|
|
531551 |
+(non-inclusive), with the exception of either nobody or nfsnobody (UID 65534). The UID
|
|
|
531551 |
+threshold can also be specified explicitly (necessary for some distributions that
|
|
|
531551 |
+allocate UIDs starting from 100, 500 - or an entirely different value - rather than 1000).
|
|
|
531551 |
+.TP
|
|
|
531551 |
+\fB\-\-time-format\fR \fItype\fP
|
|
|
531551 |
+Display dates in short, full or iso format. The default is short, this time
|
|
|
531551 |
+format is designed to be space efficient and human readable.
|
|
|
531551 |
+.TP
|
|
|
531551 |
+\fB\-u\fR, \fB\-\-user\-accs\fR[=\fIthreshold\fR]
|
|
|
531551 |
+Show user accounts. These are by default all accounts with UID above 1000
|
|
|
531551 |
+(inclusive), with the exception of either nobody or nfsnobody (UID 65534). The UID
|
|
|
531551 |
+threshold can also be specified explicitly (necessary for some distributions that
|
|
|
531551 |
+allocate UIDs starting from 100, 500 - or an entirely different value - rather than 1000).
|
|
|
531551 |
+.TP
|
|
|
531551 |
+\fB\-V\fR, \fB\-\-version\fR
|
|
|
531551 |
+Display version information and exit.
|
|
|
531551 |
+.TP
|
|
|
531551 |
+\fB\-\-wtmp\-file \fIpath\fP
|
|
|
531551 |
+Alternate path for wtmp.
|
|
|
531551 |
+.TP
|
|
|
531551 |
+\fB\-Z\fR, \fB\-\-context\fR
|
|
|
531551 |
+Display the users' security context.
|
|
|
531551 |
+.TP
|
|
|
531551 |
+\fB\-z\fR, \fB\-\-print0\fR
|
|
|
531551 |
+Delimit user entries with a nul character, instead of a newline.
|
|
|
531551 |
+
|
|
|
531551 |
+.SH NOTES
|
|
|
531551 |
+The default UID thresholds are read from /etc/login.defs.
|
|
|
531551 |
+
|
|
|
531551 |
+.SH EXIT STATUS
|
|
|
531551 |
+.TP
|
|
|
531551 |
+0
|
|
|
531551 |
+if OK,
|
|
|
531551 |
+.TP
|
|
|
531551 |
+1
|
|
|
531551 |
+if incorrect arguments specified,
|
|
|
531551 |
+.TP
|
|
|
531551 |
+2
|
|
|
531551 |
+if a serious error occurs (e.g. a corrupt log).
|
|
|
531551 |
+.SH SEE ALSO
|
|
|
531551 |
+\fBgroup\fP(5), \fBpasswd\fP(5), \fBshadow\fP(5), \fButmp\fP(5)
|
|
|
531551 |
+.SH HISTORY
|
|
|
531551 |
+The \fBlslogins\fP utility is inspired by the \fBlogins\fP utility, which first appeared in FreeBSD 4.10.
|
|
|
531551 |
+.SH AUTHORS
|
|
|
531551 |
+.MT ooprala@redhat.com
|
|
|
531551 |
+Ondrej Oprala
|
|
|
531551 |
+.ME
|
|
|
531551 |
+.br
|
|
|
531551 |
+.MT kzak@redhat.com
|
|
|
531551 |
+Karel Zak
|
|
|
531551 |
+.ME
|
|
|
531551 |
+
|
|
|
531551 |
+.SH AVAILABILITY
|
|
|
531551 |
+The lslogins command is part of the util-linux package and is available from
|
|
|
531551 |
+.UR ftp://\:ftp.kernel.org\:/pub\:/linux\:/utils\:/util-linux/
|
|
|
531551 |
+Linux Kernel Archive
|
|
|
531551 |
+.UE .
|
|
|
531551 |
diff -up util-linux-2.23.2/login-utils/lslogins.c.kzak util-linux-2.23.2/login-utils/lslogins.c
|
|
|
531551 |
--- util-linux-2.23.2/login-utils/lslogins.c.kzak 2014-12-12 15:28:30.575177127 +0100
|
|
|
531551 |
+++ util-linux-2.23.2/login-utils/lslogins.c 2014-12-12 15:29:19.084739609 +0100
|
|
|
531551 |
@@ -0,0 +1,1476 @@
|
|
|
531551 |
+/*
|
|
|
531551 |
+ * lslogins - List information about users on the system
|
|
|
531551 |
+ *
|
|
|
531551 |
+ * Copyright (C) 2014 Ondrej Oprala <ooprala@redhat.com>
|
|
|
531551 |
+ * Copyright (C) 2014 Karel Zak <kzak@redhat.com>
|
|
|
531551 |
+ *
|
|
|
531551 |
+ * This program is free software; you can redistribute it and/or modify
|
|
|
531551 |
+ * it under the terms of the GNU General Public License as published by
|
|
|
531551 |
+ * the Free Software Foundation; either version 2 of the License, or
|
|
|
531551 |
+ * (at your option) any later version.
|
|
|
531551 |
+ *
|
|
|
531551 |
+ * This program is distributed in the hope that it would be useful,
|
|
|
531551 |
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
531551 |
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
531551 |
+ * GNU General Public License for more details.
|
|
|
531551 |
+ *
|
|
|
531551 |
+ * You should have received a copy of the GNU General Public License along
|
|
|
531551 |
+ * with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
531551 |
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
531551 |
+ */
|
|
|
531551 |
+
|
|
|
531551 |
+#include <stdio.h>
|
|
|
531551 |
+#include <stdlib.h>
|
|
|
531551 |
+#include <unistd.h>
|
|
|
531551 |
+#include <getopt.h>
|
|
|
531551 |
+#include <sys/types.h>
|
|
|
531551 |
+#include <sys/stat.h>
|
|
|
531551 |
+#include <sys/syslog.h>
|
|
|
531551 |
+#include <pwd.h>
|
|
|
531551 |
+#include <grp.h>
|
|
|
531551 |
+#include <shadow.h>
|
|
|
531551 |
+#include <paths.h>
|
|
|
531551 |
+#include <time.h>
|
|
|
531551 |
+#include <utmp.h>
|
|
|
531551 |
+#include <signal.h>
|
|
|
531551 |
+#include <err.h>
|
|
|
531551 |
+#include <limits.h>
|
|
|
531551 |
+#include <ctype.h>
|
|
|
531551 |
+
|
|
|
531551 |
+#include <search.h>
|
|
|
531551 |
+
|
|
|
531551 |
+#include <libsmartcols.h>
|
|
|
531551 |
+#ifdef HAVE_LIBSELINUX
|
|
|
531551 |
+# include <selinux/selinux.h>
|
|
|
531551 |
+#endif
|
|
|
531551 |
+
|
|
|
531551 |
+#ifdef HAVE_LIBSYSTEMD
|
|
|
531551 |
+# include <systemd/sd-journal.h>
|
|
|
531551 |
+#endif
|
|
|
531551 |
+
|
|
|
531551 |
+#include "c.h"
|
|
|
531551 |
+#include "nls.h"
|
|
|
531551 |
+#include "closestream.h"
|
|
|
531551 |
+#include "xalloc.h"
|
|
|
531551 |
+#include "list.h"
|
|
|
531551 |
+#include "strutils.h"
|
|
|
531551 |
+#include "optutils.h"
|
|
|
531551 |
+#include "pathnames.h"
|
|
|
531551 |
+#include "logindefs.h"
|
|
|
531551 |
+#include "readutmp.h"
|
|
|
531551 |
+#include "procutils.h"
|
|
|
531551 |
+
|
|
|
531551 |
+/*
|
|
|
531551 |
+ * column description
|
|
|
531551 |
+ */
|
|
|
531551 |
+struct lslogins_coldesc {
|
|
|
531551 |
+ const char *name;
|
|
|
531551 |
+ const char *help;
|
|
|
531551 |
+ const char *pretty_name;
|
|
|
531551 |
+
|
|
|
531551 |
+ double whint; /* width hint */
|
|
|
531551 |
+ long flag;
|
|
|
531551 |
+};
|
|
|
531551 |
+
|
|
|
531551 |
+static int lslogins_flag;
|
|
|
531551 |
+
|
|
|
531551 |
+#define UL_UID_MIN 1000
|
|
|
531551 |
+#define UL_UID_MAX 60000
|
|
|
531551 |
+#define UL_SYS_UID_MIN 201
|
|
|
531551 |
+#define UL_SYS_UID_MAX 999
|
|
|
531551 |
+
|
|
|
531551 |
+/* we use the value of outmode to determine
|
|
|
531551 |
+ * appropriate flags for the libsmartcols table
|
|
|
531551 |
+ * (e.g., a value of out_newline would imply a raw
|
|
|
531551 |
+ * table with the column separator set to '\n').
|
|
|
531551 |
+ */
|
|
|
531551 |
+static int outmode;
|
|
|
531551 |
+/*
|
|
|
531551 |
+ * output modes
|
|
|
531551 |
+ */
|
|
|
531551 |
+enum {
|
|
|
531551 |
+ OUT_COLON = 1,
|
|
|
531551 |
+ OUT_EXPORT,
|
|
|
531551 |
+ OUT_NEWLINE,
|
|
|
531551 |
+ OUT_RAW,
|
|
|
531551 |
+ OUT_NUL,
|
|
|
531551 |
+ OUT_PRETTY
|
|
|
531551 |
+};
|
|
|
531551 |
+
|
|
|
531551 |
+struct lslogins_user {
|
|
|
531551 |
+ char *login;
|
|
|
531551 |
+ uid_t uid;
|
|
|
531551 |
+ char *group;
|
|
|
531551 |
+ gid_t gid;
|
|
|
531551 |
+ char *gecos;
|
|
|
531551 |
+
|
|
|
531551 |
+ int pwd_empty;
|
|
|
531551 |
+ int nologin;
|
|
|
531551 |
+ int pwd_lock;
|
|
|
531551 |
+ int pwd_deny;
|
|
|
531551 |
+
|
|
|
531551 |
+ gid_t *sgroups;
|
|
|
531551 |
+ size_t nsgroups;
|
|
|
531551 |
+
|
|
|
531551 |
+ char *pwd_ctime;
|
|
|
531551 |
+ char *pwd_warn;
|
|
|
531551 |
+ char *pwd_expire;
|
|
|
531551 |
+ char *pwd_ctime_min;
|
|
|
531551 |
+ char *pwd_ctime_max;
|
|
|
531551 |
+
|
|
|
531551 |
+ char *last_login;
|
|
|
531551 |
+ char *last_tty;
|
|
|
531551 |
+ char *last_hostname;
|
|
|
531551 |
+
|
|
|
531551 |
+ char *failed_login;
|
|
|
531551 |
+ char *failed_tty;
|
|
|
531551 |
+
|
|
|
531551 |
+#ifdef HAVE_LIBSELINUX
|
|
|
531551 |
+ security_context_t context;
|
|
|
531551 |
+#endif
|
|
|
531551 |
+ char *homedir;
|
|
|
531551 |
+ char *shell;
|
|
|
531551 |
+ char *pwd_status;
|
|
|
531551 |
+ int hushed;
|
|
|
531551 |
+ char *nprocs;
|
|
|
531551 |
+
|
|
|
531551 |
+};
|
|
|
531551 |
+
|
|
|
531551 |
+/*
|
|
|
531551 |
+ * time modes
|
|
|
531551 |
+ * */
|
|
|
531551 |
+enum {
|
|
|
531551 |
+ TIME_INVALID = 0,
|
|
|
531551 |
+ TIME_SHORT,
|
|
|
531551 |
+ TIME_FULL,
|
|
|
531551 |
+ TIME_ISO,
|
|
|
531551 |
+};
|
|
|
531551 |
+
|
|
|
531551 |
+/*
|
|
|
531551 |
+ * flags
|
|
|
531551 |
+ */
|
|
|
531551 |
+enum {
|
|
|
531551 |
+ F_SYSAC = (1 << 3),
|
|
|
531551 |
+ F_USRAC = (1 << 4),
|
|
|
531551 |
+};
|
|
|
531551 |
+
|
|
|
531551 |
+/*
|
|
|
531551 |
+ * IDs
|
|
|
531551 |
+ */
|
|
|
531551 |
+enum {
|
|
|
531551 |
+ COL_USER = 0,
|
|
|
531551 |
+ COL_UID,
|
|
|
531551 |
+ COL_GECOS,
|
|
|
531551 |
+ COL_HOME,
|
|
|
531551 |
+ COL_SHELL,
|
|
|
531551 |
+ COL_NOLOGIN,
|
|
|
531551 |
+ COL_PWDLOCK,
|
|
|
531551 |
+ COL_PWDEMPTY,
|
|
|
531551 |
+ COL_PWDDENY,
|
|
|
531551 |
+ COL_GROUP,
|
|
|
531551 |
+ COL_GID,
|
|
|
531551 |
+ COL_SGROUPS,
|
|
|
531551 |
+ COL_SGIDS,
|
|
|
531551 |
+ COL_LAST_LOGIN,
|
|
|
531551 |
+ COL_LAST_TTY,
|
|
|
531551 |
+ COL_LAST_HOSTNAME,
|
|
|
531551 |
+ COL_FAILED_LOGIN,
|
|
|
531551 |
+ COL_FAILED_TTY,
|
|
|
531551 |
+ COL_HUSH_STATUS,
|
|
|
531551 |
+ COL_PWD_WARN,
|
|
|
531551 |
+ COL_PWD_CTIME,
|
|
|
531551 |
+ COL_PWD_CTIME_MIN,
|
|
|
531551 |
+ COL_PWD_CTIME_MAX,
|
|
|
531551 |
+ COL_PWD_EXPIR,
|
|
|
531551 |
+ COL_SELINUX,
|
|
|
531551 |
+ COL_NPROCS,
|
|
|
531551 |
+};
|
|
|
531551 |
+
|
|
|
531551 |
+#define is_wtmp_col(x) ((x) == COL_LAST_LOGIN || \
|
|
|
531551 |
+ (x) == COL_LAST_TTY || \
|
|
|
531551 |
+ (x) == COL_LAST_HOSTNAME)
|
|
|
531551 |
+
|
|
|
531551 |
+#define is_btmp_col(x) ((x) == COL_FAILED_LOGIN || \
|
|
|
531551 |
+ (x) == COL_FAILED_TTY)
|
|
|
531551 |
+
|
|
|
531551 |
+enum {
|
|
|
531551 |
+ STATUS_FALSE = 0,
|
|
|
531551 |
+ STATUS_TRUE,
|
|
|
531551 |
+ STATUS_UNKNOWN
|
|
|
531551 |
+};
|
|
|
531551 |
+
|
|
|
531551 |
+static const char *const status[] = {
|
|
|
531551 |
+ [STATUS_FALSE] = "0",
|
|
|
531551 |
+ [STATUS_TRUE] = "1",
|
|
|
531551 |
+ [STATUS_UNKNOWN]= NULL
|
|
|
531551 |
+};
|
|
|
531551 |
+
|
|
|
531551 |
+static const char *const pretty_status[] = {
|
|
|
531551 |
+ [STATUS_FALSE] = N_("no"),
|
|
|
531551 |
+ [STATUS_TRUE] = N_("yes"),
|
|
|
531551 |
+ [STATUS_UNKNOWN]= NULL
|
|
|
531551 |
+};
|
|
|
531551 |
+
|
|
|
531551 |
+#define get_status(x) (outmode == OUT_PRETTY ? pretty_status[(x)] : status[(x)])
|
|
|
531551 |
+
|
|
|
531551 |
+static const struct lslogins_coldesc coldescs[] =
|
|
|
531551 |
+{
|
|
|
531551 |
+ [COL_USER] = { "USER", N_("user name"), N_("Username"), 0.1, SCOLS_FL_NOEXTREMES },
|
|
|
531551 |
+ [COL_UID] = { "UID", N_("user ID"), "UID", 1, SCOLS_FL_RIGHT},
|
|
|
531551 |
+ [COL_PWDEMPTY] = { "PWD-EMPTY", N_("password not required"), N_("Password not required"), 1, SCOLS_FL_RIGHT },
|
|
|
531551 |
+ [COL_PWDDENY] = { "PWD-DENY", N_("login by password disabled"), N_("Login by password disabled"), 1, SCOLS_FL_RIGHT },
|
|
|
531551 |
+ [COL_PWDLOCK] = { "PWD-LOCK", N_("password defined, but locked"), N_("Password is locked"), 1, SCOLS_FL_RIGHT },
|
|
|
531551 |
+ [COL_NOLOGIN] = { "NOLOGIN", N_("log in disabled by nologin(8) or pam_nologin(8)"), N_("No login"), 1, SCOLS_FL_RIGHT },
|
|
|
531551 |
+ [COL_GROUP] = { "GROUP", N_("primary group name"), N_("Primary group"), 0.1 },
|
|
|
531551 |
+ [COL_GID] = { "GID", N_("primary group ID"), "GID", 1, SCOLS_FL_RIGHT },
|
|
|
531551 |
+ [COL_SGROUPS] = { "SUPP-GROUPS", N_("supplementary group names"), N_("Supplementary groups"), 0.1 },
|
|
|
531551 |
+ [COL_SGIDS] = { "SUPP-GIDS", N_("supplementary group IDs"), N_("Supplementary group IDs"), 0.1 },
|
|
|
531551 |
+ [COL_HOME] = { "HOMEDIR", N_("home directory"), N_("Home directory"), 0.1 },
|
|
|
531551 |
+ [COL_SHELL] = { "SHELL", N_("login shell"), N_("Shell"), 0.1 },
|
|
|
531551 |
+ [COL_GECOS] = { "GECOS", N_("full user name"), N_("Gecos field"), 0.1, SCOLS_FL_TRUNC },
|
|
|
531551 |
+ [COL_LAST_LOGIN] = { "LAST-LOGIN", N_("date of last login"), N_("Last login"), 0.1, SCOLS_FL_RIGHT },
|
|
|
531551 |
+ [COL_LAST_TTY] = { "LAST-TTY", N_("last tty used"), N_("Last terminal"), 0.05 },
|
|
|
531551 |
+ [COL_LAST_HOSTNAME] = { "LAST-HOSTNAME",N_("hostname during the last session"), N_("Last hostname"), 0.1},
|
|
|
531551 |
+ [COL_FAILED_LOGIN] = { "FAILED-LOGIN", N_("date of last failed login"), N_("Failed login"), 0.1 },
|
|
|
531551 |
+ [COL_FAILED_TTY] = { "FAILED-TTY", N_("where did the login fail?"), N_("Failed login terminal"), 0.05 },
|
|
|
531551 |
+ [COL_HUSH_STATUS] = { "HUSHED", N_("user's hush settings"), N_("Hushed"), 1, SCOLS_FL_RIGHT },
|
|
|
531551 |
+ [COL_PWD_WARN] = { "PWD-WARN", N_("days user is warned of password expiration"), N_("Password expiration warn interval"), 0.1, SCOLS_FL_RIGHT },
|
|
|
531551 |
+ [COL_PWD_EXPIR] = { "PWD-EXPIR", N_("password expiration date"), N_("Password expiration"), 0.1, SCOLS_FL_RIGHT },
|
|
|
531551 |
+ [COL_PWD_CTIME] = { "PWD-CHANGE", N_("date of last password change"), N_("Password changed"), 0.1, SCOLS_FL_RIGHT},
|
|
|
531551 |
+ [COL_PWD_CTIME_MIN] = { "PWD-MIN", N_("number of days required between changes"), N_("Minimum change time"), 0.1, SCOLS_FL_RIGHT },
|
|
|
531551 |
+ [COL_PWD_CTIME_MAX] = { "PWD-MAX", N_("max number of days a password may remain unchanged"), N_("Maximum change time"), 0.1, SCOLS_FL_RIGHT },
|
|
|
531551 |
+ [COL_SELINUX] = { "CONTEXT", N_("the user's security context"), N_("Selinux context"), 0.1 },
|
|
|
531551 |
+ [COL_NPROCS] = { "PROC", N_("number of processes run by the user"), N_("Running processes"), 1, SCOLS_FL_RIGHT },
|
|
|
531551 |
+};
|
|
|
531551 |
+
|
|
|
531551 |
+struct lslogins_control {
|
|
|
531551 |
+ struct utmp *wtmp;
|
|
|
531551 |
+ size_t wtmp_size;
|
|
|
531551 |
+
|
|
|
531551 |
+ struct utmp *btmp;
|
|
|
531551 |
+ size_t btmp_size;
|
|
|
531551 |
+
|
|
|
531551 |
+ void *usertree;
|
|
|
531551 |
+
|
|
|
531551 |
+ uid_t uid;
|
|
|
531551 |
+ uid_t UID_MIN;
|
|
|
531551 |
+ uid_t UID_MAX;
|
|
|
531551 |
+
|
|
|
531551 |
+ uid_t SYS_UID_MIN;
|
|
|
531551 |
+ uid_t SYS_UID_MAX;
|
|
|
531551 |
+
|
|
|
531551 |
+ char **ulist;
|
|
|
531551 |
+ size_t ulsiz;
|
|
|
531551 |
+
|
|
|
531551 |
+ unsigned int time_mode;
|
|
|
531551 |
+
|
|
|
531551 |
+ const char *journal_path;
|
|
|
531551 |
+
|
|
|
531551 |
+ unsigned int selinux_enabled : 1,
|
|
|
531551 |
+ ulist_on : 1,
|
|
|
531551 |
+ noheadings : 1,
|
|
|
531551 |
+ notrunc : 1;
|
|
|
531551 |
+};
|
|
|
531551 |
+
|
|
|
531551 |
+/* these have to remain global since there's no other reasonable way to pass
|
|
|
531551 |
+ * them for each call of fill_table() via twalk() */
|
|
|
531551 |
+static struct libscols_table *tb;
|
|
|
531551 |
+
|
|
|
531551 |
+/* columns[] array specifies all currently wanted output column. The columns
|
|
|
531551 |
+ * are defined by coldescs[] array and you can specify (on command line) each
|
|
|
531551 |
+ * column twice. That's enough, dynamically allocated array of the columns is
|
|
|
531551 |
+ * unnecessary overkill and over-engineering in this case */
|
|
|
531551 |
+static int columns[ARRAY_SIZE(coldescs) * 2];
|
|
|
531551 |
+static int ncolumns;
|
|
|
531551 |
+
|
|
|
531551 |
+static inline size_t err_columns_index(size_t arysz, size_t idx)
|
|
|
531551 |
+{
|
|
|
531551 |
+ if (idx >= arysz)
|
|
|
531551 |
+ errx(EXIT_FAILURE, _("too many columns specified, "
|
|
|
531551 |
+ "the limit is %zu columns"),
|
|
|
531551 |
+ arysz - 1);
|
|
|
531551 |
+ return idx;
|
|
|
531551 |
+}
|
|
|
531551 |
+
|
|
|
531551 |
+#define add_column(ary, n, id) \
|
|
|
531551 |
+ ((ary)[ err_columns_index(ARRAY_SIZE(ary), (n)) ] = (id))
|
|
|
531551 |
+
|
|
|
531551 |
+static struct timeval now;
|
|
|
531551 |
+
|
|
|
531551 |
+static int date_is_today(time_t t)
|
|
|
531551 |
+{
|
|
|
531551 |
+ if (now.tv_sec == 0)
|
|
|
531551 |
+ gettimeofday(&now, NULL);
|
|
|
531551 |
+ return t / (3600 * 24) == now.tv_sec / (3600 * 24);
|
|
|
531551 |
+}
|
|
|
531551 |
+
|
|
|
531551 |
+static int date_is_thisyear(time_t t)
|
|
|
531551 |
+{
|
|
|
531551 |
+ if (now.tv_sec == 0)
|
|
|
531551 |
+ gettimeofday(&now, NULL);
|
|
|
531551 |
+ return t / (3600 * 24 * 365) == now.tv_sec / (3600 * 24 * 365);
|
|
|
531551 |
+}
|
|
|
531551 |
+
|
|
|
531551 |
+static int column_name_to_id(const char *name, size_t namesz)
|
|
|
531551 |
+{
|
|
|
531551 |
+ size_t i;
|
|
|
531551 |
+
|
|
|
531551 |
+ for (i = 0; i < ARRAY_SIZE(coldescs); i++) {
|
|
|
531551 |
+ const char *cn = coldescs[i].name;
|
|
|
531551 |
+
|
|
|
531551 |
+ if (!strncasecmp(name, cn, namesz) && !*(cn + namesz))
|
|
|
531551 |
+ return i;
|
|
|
531551 |
+ }
|
|
|
531551 |
+ warnx(_("unknown column: %s"), name);
|
|
|
531551 |
+ return -1;
|
|
|
531551 |
+}
|
|
|
531551 |
+
|
|
|
531551 |
+static char *make_time(int mode, time_t time)
|
|
|
531551 |
+{
|
|
|
531551 |
+ char *s;
|
|
|
531551 |
+ struct tm tm;
|
|
|
531551 |
+ char buf[64] = {0};
|
|
|
531551 |
+
|
|
|
531551 |
+ localtime_r(&time, &tm;;
|
|
|
531551 |
+
|
|
|
531551 |
+ switch(mode) {
|
|
|
531551 |
+ case TIME_FULL:
|
|
|
531551 |
+ asctime_r(&tm, buf);
|
|
|
531551 |
+ if (*(s = buf + strlen(buf) - 1) == '\n')
|
|
|
531551 |
+ *s = '\0';
|
|
|
531551 |
+ break;
|
|
|
531551 |
+ case TIME_SHORT:
|
|
|
531551 |
+ if (date_is_today(time))
|
|
|
531551 |
+ strftime(buf, sizeof(buf), "%H:%M:%S", &tm;;
|
|
|
531551 |
+ else if (date_is_thisyear(time))
|
|
|
531551 |
+ strftime(buf, sizeof(buf), "%b%d/%H:%M", &tm;;
|
|
|
531551 |
+ else
|
|
|
531551 |
+ strftime(buf, sizeof(buf), "%Y-%b%d", &tm;;
|
|
|
531551 |
+ break;
|
|
|
531551 |
+ case TIME_ISO:
|
|
|
531551 |
+ strftime(buf, sizeof(buf), "%Y-%m-%dT%H:%M:%S%z", &tm;;
|
|
|
531551 |
+ break;
|
|
|
531551 |
+ default:
|
|
|
531551 |
+ errx(EXIT_FAILURE, _("unsupported time type"));
|
|
|
531551 |
+ }
|
|
|
531551 |
+ return xstrdup(buf);
|
|
|
531551 |
+}
|
|
|
531551 |
+
|
|
|
531551 |
+
|
|
|
531551 |
+static char *uidtostr(uid_t uid)
|
|
|
531551 |
+{
|
|
|
531551 |
+ char *str_uid = NULL;
|
|
|
531551 |
+ xasprintf(&str_uid, "%u", uid);
|
|
|
531551 |
+ return str_uid;
|
|
|
531551 |
+}
|
|
|
531551 |
+
|
|
|
531551 |
+static char *gidtostr(gid_t gid)
|
|
|
531551 |
+{
|
|
|
531551 |
+ char *str_gid = NULL;
|
|
|
531551 |
+ xasprintf(&str_gid, "%u", gid);
|
|
|
531551 |
+ return str_gid;
|
|
|
531551 |
+}
|
|
|
531551 |
+
|
|
|
531551 |
+static char *build_sgroups_string(gid_t *sgroups, size_t nsgroups, int want_names)
|
|
|
531551 |
+{
|
|
|
531551 |
+ size_t n = 0, maxlen, len;
|
|
|
531551 |
+ char *res, *p;
|
|
|
531551 |
+
|
|
|
531551 |
+ if (!nsgroups)
|
|
|
531551 |
+ return NULL;
|
|
|
531551 |
+
|
|
|
531551 |
+ len = maxlen = nsgroups * 10;
|
|
|
531551 |
+ res = p = xmalloc(maxlen);
|
|
|
531551 |
+
|
|
|
531551 |
+ while (n < nsgroups) {
|
|
|
531551 |
+ int x;
|
|
|
531551 |
+again:
|
|
|
531551 |
+ if (!want_names)
|
|
|
531551 |
+ x = snprintf(p, len, "%u,", sgroups[n]);
|
|
|
531551 |
+ else {
|
|
|
531551 |
+ struct group *grp = getgrgid(sgroups[n]);
|
|
|
531551 |
+ if (!grp) {
|
|
|
531551 |
+ free(res);
|
|
|
531551 |
+ return NULL;
|
|
|
531551 |
+ }
|
|
|
531551 |
+ x = snprintf(p, len, "%s,", grp->gr_name);
|
|
|
531551 |
+ }
|
|
|
531551 |
+
|
|
|
531551 |
+ if (x < 0 || (size_t) x + 1 > len) {
|
|
|
531551 |
+ size_t cur = p - res;
|
|
|
531551 |
+
|
|
|
531551 |
+ maxlen *= 2;
|
|
|
531551 |
+ res = xrealloc(res, maxlen);
|
|
|
531551 |
+ p = res + cur;
|
|
|
531551 |
+ len = maxlen - cur;
|
|
|
531551 |
+ goto again;
|
|
|
531551 |
+ }
|
|
|
531551 |
+
|
|
|
531551 |
+ len -= x;
|
|
|
531551 |
+ p += x;
|
|
|
531551 |
+ ++n;
|
|
|
531551 |
+ }
|
|
|
531551 |
+
|
|
|
531551 |
+ if (p > res)
|
|
|
531551 |
+ *(p - 1) = '\0';
|
|
|
531551 |
+
|
|
|
531551 |
+ return res;
|
|
|
531551 |
+}
|
|
|
531551 |
+
|
|
|
531551 |
+static struct utmp *get_last_wtmp(struct lslogins_control *ctl, const char *username)
|
|
|
531551 |
+{
|
|
|
531551 |
+ size_t n = 0;
|
|
|
531551 |
+ size_t len;
|
|
|
531551 |
+
|
|
|
531551 |
+ if (!username)
|
|
|
531551 |
+ return NULL;
|
|
|
531551 |
+
|
|
|
531551 |
+ len = strlen(username);
|
|
|
531551 |
+ n = ctl->wtmp_size - 1;
|
|
|
531551 |
+ do {
|
|
|
531551 |
+ if (!strncmp(username, ctl->wtmp[n].ut_user,
|
|
|
531551 |
+ len < UT_NAMESIZE ? len : UT_NAMESIZE))
|
|
|
531551 |
+ return ctl->wtmp + n;
|
|
|
531551 |
+ } while (n--);
|
|
|
531551 |
+ return NULL;
|
|
|
531551 |
+
|
|
|
531551 |
+}
|
|
|
531551 |
+
|
|
|
531551 |
+static int require_wtmp(void)
|
|
|
531551 |
+{
|
|
|
531551 |
+ size_t i;
|
|
|
531551 |
+ for (i = 0; i < (size_t) ncolumns; i++)
|
|
|
531551 |
+ if (is_wtmp_col(columns[i]))
|
|
|
531551 |
+ return 1;
|
|
|
531551 |
+ return 0;
|
|
|
531551 |
+}
|
|
|
531551 |
+
|
|
|
531551 |
+static int require_btmp(void)
|
|
|
531551 |
+{
|
|
|
531551 |
+ size_t i;
|
|
|
531551 |
+ for (i = 0; i < (size_t) ncolumns; i++)
|
|
|
531551 |
+ if (is_btmp_col(columns[i]))
|
|
|
531551 |
+ return 1;
|
|
|
531551 |
+ return 0;
|
|
|
531551 |
+}
|
|
|
531551 |
+
|
|
|
531551 |
+static struct utmp *get_last_btmp(struct lslogins_control *ctl, const char *username)
|
|
|
531551 |
+{
|
|
|
531551 |
+ size_t n = 0;
|
|
|
531551 |
+ size_t len;
|
|
|
531551 |
+
|
|
|
531551 |
+ if (!username)
|
|
|
531551 |
+ return NULL;
|
|
|
531551 |
+
|
|
|
531551 |
+ len = strlen(username);
|
|
|
531551 |
+ n = ctl->btmp_size - 1;
|
|
|
531551 |
+ do {
|
|
|
531551 |
+ if (!strncmp(username, ctl->btmp[n].ut_user,
|
|
|
531551 |
+ len < UT_NAMESIZE ? len : UT_NAMESIZE))
|
|
|
531551 |
+ return ctl->btmp + n;
|
|
|
531551 |
+ }while (n--);
|
|
|
531551 |
+ return NULL;
|
|
|
531551 |
+
|
|
|
531551 |
+}
|
|
|
531551 |
+
|
|
|
531551 |
+static int parse_wtmp(struct lslogins_control *ctl, char *path)
|
|
|
531551 |
+{
|
|
|
531551 |
+ int rc = 0;
|
|
|
531551 |
+
|
|
|
531551 |
+ rc = read_utmp(path, &ctl->wtmp_size, &ctl->wtmp);
|
|
|
531551 |
+ if (rc < 0 && errno != EACCES)
|
|
|
531551 |
+ err(EXIT_FAILURE, "%s", path);
|
|
|
531551 |
+ return rc;
|
|
|
531551 |
+}
|
|
|
531551 |
+
|
|
|
531551 |
+static int parse_btmp(struct lslogins_control *ctl, char *path)
|
|
|
531551 |
+{
|
|
|
531551 |
+ int rc = 0;
|
|
|
531551 |
+
|
|
|
531551 |
+ rc = read_utmp(path, &ctl->btmp_size, &ctl->btmp);
|
|
|
531551 |
+ if (rc < 0 && errno != EACCES)
|
|
|
531551 |
+ err(EXIT_FAILURE, "%s", path);
|
|
|
531551 |
+ return rc;
|
|
|
531551 |
+}
|
|
|
531551 |
+
|
|
|
531551 |
+static int get_sgroups(gid_t **list, size_t *len, struct passwd *pwd)
|
|
|
531551 |
+{
|
|
|
531551 |
+ size_t n = 0;
|
|
|
531551 |
+
|
|
|
531551 |
+ *len = 0;
|
|
|
531551 |
+ *list = NULL;
|
|
|
531551 |
+
|
|
|
531551 |
+ /* first let's get a supp. group count */
|
|
|
531551 |
+ getgrouplist(pwd->pw_name, pwd->pw_gid, *list, (int *) len);
|
|
|
531551 |
+ if (!*len)
|
|
|
531551 |
+ return -1;
|
|
|
531551 |
+
|
|
|
531551 |
+ *list = xcalloc(1, *len * sizeof(gid_t));
|
|
|
531551 |
+
|
|
|
531551 |
+ /* now for the actual list of GIDs */
|
|
|
531551 |
+ if (-1 == getgrouplist(pwd->pw_name, pwd->pw_gid, *list, (int *) len))
|
|
|
531551 |
+ return -1;
|
|
|
531551 |
+
|
|
|
531551 |
+ /* getgroups also returns the user's primary GID - dispose of it */
|
|
|
531551 |
+ while (n < *len) {
|
|
|
531551 |
+ if ((*list)[n] == pwd->pw_gid)
|
|
|
531551 |
+ break;
|
|
|
531551 |
+ ++n;
|
|
|
531551 |
+ }
|
|
|
531551 |
+
|
|
|
531551 |
+ if (*len)
|
|
|
531551 |
+ (*list)[n] = (*list)[--(*len)];
|
|
|
531551 |
+ return 0;
|
|
|
531551 |
+}
|
|
|
531551 |
+
|
|
|
531551 |
+static int get_nprocs(const uid_t uid)
|
|
|
531551 |
+{
|
|
|
531551 |
+ int nprocs = 0;
|
|
|
531551 |
+ pid_t pid;
|
|
|
531551 |
+ struct proc_processes *proc = proc_open_processes();
|
|
|
531551 |
+
|
|
|
531551 |
+ proc_processes_filter_by_uid(proc, uid);
|
|
|
531551 |
+
|
|
|
531551 |
+ while (!proc_next_pid(proc, &pid))
|
|
|
531551 |
+ ++nprocs;
|
|
|
531551 |
+
|
|
|
531551 |
+ proc_close_processes(proc);
|
|
|
531551 |
+ return nprocs;
|
|
|
531551 |
+}
|
|
|
531551 |
+
|
|
|
531551 |
+static int valid_pwd(const char *str)
|
|
|
531551 |
+{
|
|
|
531551 |
+ const char *p;
|
|
|
531551 |
+
|
|
|
531551 |
+ for (p = str; p && *p; p++)
|
|
|
531551 |
+ if (!isalnum((unsigned int) *p))
|
|
|
531551 |
+ return 0;
|
|
|
531551 |
+ return p > str ? 1 : 0;
|
|
|
531551 |
+}
|
|
|
531551 |
+
|
|
|
531551 |
+static struct lslogins_user *get_user_info(struct lslogins_control *ctl, const char *username)
|
|
|
531551 |
+{
|
|
|
531551 |
+ struct lslogins_user *user;
|
|
|
531551 |
+ struct passwd *pwd;
|
|
|
531551 |
+ struct group *grp;
|
|
|
531551 |
+ struct spwd *shadow;
|
|
|
531551 |
+ struct utmp *user_wtmp = NULL, *user_btmp = NULL;
|
|
|
531551 |
+ int n = 0;
|
|
|
531551 |
+ time_t time;
|
|
|
531551 |
+ uid_t uid;
|
|
|
531551 |
+ errno = 0;
|
|
|
531551 |
+
|
|
|
531551 |
+ pwd = username ? getpwnam(username) : getpwent();
|
|
|
531551 |
+ if (!pwd)
|
|
|
531551 |
+ return NULL;
|
|
|
531551 |
+
|
|
|
531551 |
+ ctl->uid = uid = pwd->pw_uid;
|
|
|
531551 |
+
|
|
|
531551 |
+ /* nfsnobody is an exception to the UID_MAX limit. This is "nobody" on
|
|
|
531551 |
+ * some systems; the decisive point is the UID - 65534 */
|
|
|
531551 |
+ if ((lslogins_flag & F_USRAC) &&
|
|
|
531551 |
+ strcmp("nfsnobody", pwd->pw_name) != 0 &&
|
|
|
531551 |
+ uid != 0) {
|
|
|
531551 |
+ if (uid < ctl->UID_MIN || uid > ctl->UID_MAX) {
|
|
|
531551 |
+ errno = EAGAIN;
|
|
|
531551 |
+ return NULL;
|
|
|
531551 |
+ }
|
|
|
531551 |
+
|
|
|
531551 |
+ } else if ((lslogins_flag & F_SYSAC) &&
|
|
|
531551 |
+ (uid < ctl->SYS_UID_MIN || uid > ctl->SYS_UID_MAX)) {
|
|
|
531551 |
+ errno = EAGAIN;
|
|
|
531551 |
+ return NULL;
|
|
|
531551 |
+ }
|
|
|
531551 |
+
|
|
|
531551 |
+ user = xcalloc(1, sizeof(struct lslogins_user));
|
|
|
531551 |
+
|
|
|
531551 |
+ grp = getgrgid(pwd->pw_gid);
|
|
|
531551 |
+ if (!grp)
|
|
|
531551 |
+ return NULL;
|
|
|
531551 |
+
|
|
|
531551 |
+ if (ctl->wtmp)
|
|
|
531551 |
+ user_wtmp = get_last_wtmp(ctl, pwd->pw_name);
|
|
|
531551 |
+ if (ctl->btmp)
|
|
|
531551 |
+ user_btmp = get_last_btmp(ctl, pwd->pw_name);
|
|
|
531551 |
+
|
|
|
531551 |
+ lckpwdf();
|
|
|
531551 |
+ shadow = getspnam(pwd->pw_name);
|
|
|
531551 |
+ ulckpwdf();
|
|
|
531551 |
+
|
|
|
531551 |
+ /* required by tseach() stuff */
|
|
|
531551 |
+ user->uid = pwd->pw_uid;
|
|
|
531551 |
+
|
|
|
531551 |
+ while (n < ncolumns) {
|
|
|
531551 |
+ switch (columns[n++]) {
|
|
|
531551 |
+ case COL_USER:
|
|
|
531551 |
+ user->login = xstrdup(pwd->pw_name);
|
|
|
531551 |
+ break;
|
|
|
531551 |
+ case COL_UID:
|
|
|
531551 |
+ user->uid = pwd->pw_uid;
|
|
|
531551 |
+ break;
|
|
|
531551 |
+ case COL_GROUP:
|
|
|
531551 |
+ user->group = xstrdup(grp->gr_name);
|
|
|
531551 |
+ break;
|
|
|
531551 |
+ case COL_GID:
|
|
|
531551 |
+ user->gid = pwd->pw_gid;
|
|
|
531551 |
+ break;
|
|
|
531551 |
+ case COL_SGROUPS:
|
|
|
531551 |
+ case COL_SGIDS:
|
|
|
531551 |
+ if (get_sgroups(&user->sgroups, &user->nsgroups, pwd))
|
|
|
531551 |
+ err(EXIT_FAILURE, _("failed to get supplementary groups"));
|
|
|
531551 |
+ break;
|
|
|
531551 |
+ case COL_HOME:
|
|
|
531551 |
+ user->homedir = xstrdup(pwd->pw_dir);
|
|
|
531551 |
+ break;
|
|
|
531551 |
+ case COL_SHELL:
|
|
|
531551 |
+ user->shell = xstrdup(pwd->pw_shell);
|
|
|
531551 |
+ break;
|
|
|
531551 |
+ case COL_GECOS:
|
|
|
531551 |
+ user->gecos = xstrdup(pwd->pw_gecos);
|
|
|
531551 |
+ break;
|
|
|
531551 |
+ case COL_LAST_LOGIN:
|
|
|
531551 |
+ if (user_wtmp) {
|
|
|
531551 |
+ time = user_wtmp->ut_tv.tv_sec;
|
|
|
531551 |
+ user->last_login = make_time(ctl->time_mode, time);
|
|
|
531551 |
+ }
|
|
|
531551 |
+ break;
|
|
|
531551 |
+ case COL_LAST_TTY:
|
|
|
531551 |
+ if (user_wtmp)
|
|
|
531551 |
+ user->last_tty = xstrdup(user_wtmp->ut_line);
|
|
|
531551 |
+ break;
|
|
|
531551 |
+ case COL_LAST_HOSTNAME:
|
|
|
531551 |
+ if (user_wtmp)
|
|
|
531551 |
+ user->last_hostname = xstrdup(user_wtmp->ut_host);
|
|
|
531551 |
+ break;
|
|
|
531551 |
+ case COL_FAILED_LOGIN:
|
|
|
531551 |
+ if (user_btmp) {
|
|
|
531551 |
+ time = user_btmp->ut_tv.tv_sec;
|
|
|
531551 |
+ user->failed_login = make_time(ctl->time_mode, time);
|
|
|
531551 |
+ }
|
|
|
531551 |
+ break;
|
|
|
531551 |
+ case COL_FAILED_TTY:
|
|
|
531551 |
+ if (user_btmp)
|
|
|
531551 |
+ user->failed_tty = xstrdup(user_btmp->ut_line);
|
|
|
531551 |
+ break;
|
|
|
531551 |
+ case COL_HUSH_STATUS:
|
|
|
531551 |
+ user->hushed = get_hushlogin_status(pwd, 0);
|
|
|
531551 |
+ if (user->hushed == -1)
|
|
|
531551 |
+ user->hushed = STATUS_UNKNOWN;
|
|
|
531551 |
+ break;
|
|
|
531551 |
+ case COL_PWDEMPTY:
|
|
|
531551 |
+ if (shadow) {
|
|
|
531551 |
+ if (!*shadow->sp_pwdp) /* '\0' */
|
|
|
531551 |
+ user->pwd_empty = STATUS_TRUE;
|
|
|
531551 |
+ } else
|
|
|
531551 |
+ user->pwd_empty = STATUS_UNKNOWN;
|
|
|
531551 |
+ break;
|
|
|
531551 |
+ case COL_PWDDENY:
|
|
|
531551 |
+ if (shadow) {
|
|
|
531551 |
+ if ((*shadow->sp_pwdp == '!' ||
|
|
|
531551 |
+ *shadow->sp_pwdp == '*') &&
|
|
|
531551 |
+ !valid_pwd(shadow->sp_pwdp + 1))
|
|
|
531551 |
+ user->pwd_deny = STATUS_TRUE;
|
|
|
531551 |
+ } else
|
|
|
531551 |
+ user->pwd_deny = STATUS_UNKNOWN;
|
|
|
531551 |
+ break;
|
|
|
531551 |
+
|
|
|
531551 |
+ case COL_PWDLOCK:
|
|
|
531551 |
+ if (shadow) {
|
|
|
531551 |
+ if (*shadow->sp_pwdp == '!' && valid_pwd(shadow->sp_pwdp + 1))
|
|
|
531551 |
+ user->pwd_lock = STATUS_TRUE;
|
|
|
531551 |
+ } else
|
|
|
531551 |
+ user->pwd_lock = STATUS_UNKNOWN;
|
|
|
531551 |
+ break;
|
|
|
531551 |
+ case COL_NOLOGIN:
|
|
|
531551 |
+ if (strstr(pwd->pw_shell, "nologin"))
|
|
|
531551 |
+ user->nologin = 1;
|
|
|
531551 |
+ else if (pwd->pw_uid)
|
|
|
531551 |
+ user->nologin = access("/etc/nologin", F_OK) == 0 ||
|
|
|
531551 |
+ access("/var/run/nologin", F_OK) == 0;
|
|
|
531551 |
+ break;
|
|
|
531551 |
+ case COL_PWD_WARN:
|
|
|
531551 |
+ if (shadow && shadow->sp_warn >= 0)
|
|
|
531551 |
+ xasprintf(&user->pwd_warn, "%ld", shadow->sp_warn);
|
|
|
531551 |
+ break;
|
|
|
531551 |
+ case COL_PWD_EXPIR:
|
|
|
531551 |
+ if (shadow && shadow->sp_expire >= 0)
|
|
|
531551 |
+ user->pwd_expire = make_time(TIME_SHORT,
|
|
|
531551 |
+ shadow->sp_expire * 86400);
|
|
|
531551 |
+ break;
|
|
|
531551 |
+ case COL_PWD_CTIME:
|
|
|
531551 |
+ /* sp_lstchg is specified in days, showing hours
|
|
|
531551 |
+ * (especially in non-GMT timezones) would only serve
|
|
|
531551 |
+ * to confuse */
|
|
|
531551 |
+ if (shadow)
|
|
|
531551 |
+ user->pwd_ctime = make_time(TIME_SHORT,
|
|
|
531551 |
+ shadow->sp_lstchg * 86400);
|
|
|
531551 |
+ break;
|
|
|
531551 |
+ case COL_PWD_CTIME_MIN:
|
|
|
531551 |
+ if (shadow && shadow->sp_min > 0)
|
|
|
531551 |
+ xasprintf(&user->pwd_ctime_min, "%ld", shadow->sp_min);
|
|
|
531551 |
+ break;
|
|
|
531551 |
+ case COL_PWD_CTIME_MAX:
|
|
|
531551 |
+ if (shadow && shadow->sp_max > 0)
|
|
|
531551 |
+ xasprintf(&user->pwd_ctime_max, "%ld", shadow->sp_max);
|
|
|
531551 |
+ break;
|
|
|
531551 |
+ case COL_SELINUX:
|
|
|
531551 |
+#ifdef HAVE_LIBSELINUX
|
|
|
531551 |
+ if (ctl->selinux_enabled) {
|
|
|
531551 |
+ /* typedefs and pointers are pure evil */
|
|
|
531551 |
+ security_context_t con = NULL;
|
|
|
531551 |
+ if (getcon(&con) == 0)
|
|
|
531551 |
+ user->context = con;
|
|
|
531551 |
+ }
|
|
|
531551 |
+#endif
|
|
|
531551 |
+ break;
|
|
|
531551 |
+ case COL_NPROCS:
|
|
|
531551 |
+ xasprintf(&user->nprocs, "%d", get_nprocs(pwd->pw_uid));
|
|
|
531551 |
+ break;
|
|
|
531551 |
+ default:
|
|
|
531551 |
+ /* something went very wrong here */
|
|
|
531551 |
+ err(EXIT_FAILURE, "fatal: unknown error");
|
|
|
531551 |
+ break;
|
|
|
531551 |
+ }
|
|
|
531551 |
+ }
|
|
|
531551 |
+
|
|
|
531551 |
+ return user;
|
|
|
531551 |
+}
|
|
|
531551 |
+
|
|
|
531551 |
+/* some UNIX implementations set errno iff a passwd/grp/...
|
|
|
531551 |
+ * entry was not found. The original UNIX logins(1) utility always
|
|
|
531551 |
+ * ignores invalid login/group names, so we're going to as well.*/
|
|
|
531551 |
+#define IS_REAL_ERRNO(e) !((e) == ENOENT || (e) == ESRCH || \
|
|
|
531551 |
+ (e) == EBADF || (e) == EPERM || (e) == EAGAIN)
|
|
|
531551 |
+
|
|
|
531551 |
+/* get a definitive list of users we want info about... */
|
|
|
531551 |
+
|
|
|
531551 |
+static int str_to_uint(char *s, unsigned int *ul)
|
|
|
531551 |
+{
|
|
|
531551 |
+ char *end;
|
|
|
531551 |
+ if (!s || !*s)
|
|
|
531551 |
+ return -1;
|
|
|
531551 |
+ *ul = strtoul(s, &end, 0);
|
|
|
531551 |
+ if (!*end)
|
|
|
531551 |
+ return 0;
|
|
|
531551 |
+ return 1;
|
|
|
531551 |
+}
|
|
|
531551 |
+
|
|
|
531551 |
+static int get_ulist(struct lslogins_control *ctl, char *logins, char *groups)
|
|
|
531551 |
+{
|
|
|
531551 |
+ char *u, *g;
|
|
|
531551 |
+ size_t i = 0, n = 0, *arsiz;
|
|
|
531551 |
+ struct group *grp;
|
|
|
531551 |
+ struct passwd *pwd;
|
|
|
531551 |
+ char ***ar;
|
|
|
531551 |
+ uid_t uid;
|
|
|
531551 |
+ gid_t gid;
|
|
|
531551 |
+
|
|
|
531551 |
+ ar = &ctl->ulist;
|
|
|
531551 |
+ arsiz = &ctl->ulsiz;
|
|
|
531551 |
+
|
|
|
531551 |
+ /* an arbitrary starting value */
|
|
|
531551 |
+ *arsiz = 32;
|
|
|
531551 |
+ *ar = xcalloc(1, sizeof(char *) * (*arsiz));
|
|
|
531551 |
+
|
|
|
531551 |
+ if (logins) {
|
|
|
531551 |
+ while ((u = strtok(logins, ","))) {
|
|
|
531551 |
+ logins = NULL;
|
|
|
531551 |
+
|
|
|
531551 |
+ /* user specified by UID? */
|
|
|
531551 |
+ if (!str_to_uint(u, &uid)) {
|
|
|
531551 |
+ pwd = getpwuid(uid);
|
|
|
531551 |
+ if (!pwd)
|
|
|
531551 |
+ continue;
|
|
|
531551 |
+ u = pwd->pw_name;
|
|
|
531551 |
+ }
|
|
|
531551 |
+ (*ar)[i++] = xstrdup(u);
|
|
|
531551 |
+
|
|
|
531551 |
+ if (i == *arsiz)
|
|
|
531551 |
+ *ar = xrealloc(*ar, sizeof(char *) * (*arsiz += 32));
|
|
|
531551 |
+ }
|
|
|
531551 |
+ ctl->ulist_on = 1;
|
|
|
531551 |
+ }
|
|
|
531551 |
+
|
|
|
531551 |
+ if (groups) {
|
|
|
531551 |
+ /* FIXME: this might lead to duplicit entries, although not visible
|
|
|
531551 |
+ * in output, crunching a user's info multiple times is very redundant */
|
|
|
531551 |
+ while ((g = strtok(groups, ","))) {
|
|
|
531551 |
+ n = 0;
|
|
|
531551 |
+ groups = NULL;
|
|
|
531551 |
+
|
|
|
531551 |
+ /* user specified by GID? */
|
|
|
531551 |
+ if (!str_to_uint(g, &gid))
|
|
|
531551 |
+ grp = getgrgid(gid);
|
|
|
531551 |
+ else
|
|
|
531551 |
+ grp = getgrnam(g);
|
|
|
531551 |
+
|
|
|
531551 |
+ if (!grp)
|
|
|
531551 |
+ continue;
|
|
|
531551 |
+
|
|
|
531551 |
+ while ((u = grp->gr_mem[n++])) {
|
|
|
531551 |
+ (*ar)[i++] = xstrdup(u);
|
|
|
531551 |
+
|
|
|
531551 |
+ if (i == *arsiz)
|
|
|
531551 |
+ *ar = xrealloc(*ar, sizeof(char *) * (*arsiz += 32));
|
|
|
531551 |
+ }
|
|
|
531551 |
+ }
|
|
|
531551 |
+ ctl->ulist_on = 1;
|
|
|
531551 |
+ }
|
|
|
531551 |
+ *arsiz = i;
|
|
|
531551 |
+ return 0;
|
|
|
531551 |
+}
|
|
|
531551 |
+
|
|
|
531551 |
+static void free_ctl(struct lslogins_control *ctl)
|
|
|
531551 |
+{
|
|
|
531551 |
+ size_t n = 0;
|
|
|
531551 |
+
|
|
|
531551 |
+ free(ctl->wtmp);
|
|
|
531551 |
+ free(ctl->btmp);
|
|
|
531551 |
+
|
|
|
531551 |
+ while (n < ctl->ulsiz)
|
|
|
531551 |
+ free(ctl->ulist[n++]);
|
|
|
531551 |
+
|
|
|
531551 |
+ free(ctl->ulist);
|
|
|
531551 |
+ free(ctl);
|
|
|
531551 |
+}
|
|
|
531551 |
+
|
|
|
531551 |
+static struct lslogins_user *get_next_user(struct lslogins_control *ctl)
|
|
|
531551 |
+{
|
|
|
531551 |
+ struct lslogins_user *u;
|
|
|
531551 |
+ errno = 0;
|
|
|
531551 |
+ while (!(u = get_user_info(ctl, NULL))) {
|
|
|
531551 |
+ /* no "false" errno-s here, iff we're unable to
|
|
|
531551 |
+ * get a valid user entry for any reason, quit */
|
|
|
531551 |
+ if (errno == EAGAIN)
|
|
|
531551 |
+ continue;
|
|
|
531551 |
+ return NULL;
|
|
|
531551 |
+ }
|
|
|
531551 |
+ return u;
|
|
|
531551 |
+}
|
|
|
531551 |
+
|
|
|
531551 |
+static int get_user(struct lslogins_control *ctl, struct lslogins_user **user,
|
|
|
531551 |
+ const char *username)
|
|
|
531551 |
+{
|
|
|
531551 |
+ *user = get_user_info(ctl, username);
|
|
|
531551 |
+ if (!*user && errno)
|
|
|
531551 |
+ if (IS_REAL_ERRNO(errno))
|
|
|
531551 |
+ return -1;
|
|
|
531551 |
+ return 0;
|
|
|
531551 |
+}
|
|
|
531551 |
+
|
|
|
531551 |
+static int cmp_uid(const void *a, const void *b)
|
|
|
531551 |
+{
|
|
|
531551 |
+ uid_t x = ((struct lslogins_user *)a)->uid;
|
|
|
531551 |
+ uid_t z = ((struct lslogins_user *)b)->uid;
|
|
|
531551 |
+ return x > z ? 1 : (x < z ? -1 : 0);
|
|
|
531551 |
+}
|
|
|
531551 |
+
|
|
|
531551 |
+static int create_usertree(struct lslogins_control *ctl)
|
|
|
531551 |
+{
|
|
|
531551 |
+ struct lslogins_user *user = NULL;
|
|
|
531551 |
+ size_t n = 0;
|
|
|
531551 |
+
|
|
|
531551 |
+ if (ctl->ulist_on) {
|
|
|
531551 |
+ while (n < ctl->ulsiz) {
|
|
|
531551 |
+ if (get_user(ctl, &user, ctl->ulist[n]))
|
|
|
531551 |
+ return -1;
|
|
|
531551 |
+ if (user) /* otherwise an invalid user name has probably been given */
|
|
|
531551 |
+ tsearch(user, &ctl->usertree, cmp_uid);
|
|
|
531551 |
+ ++n;
|
|
|
531551 |
+ }
|
|
|
531551 |
+ } else {
|
|
|
531551 |
+ while ((user = get_next_user(ctl)))
|
|
|
531551 |
+ tsearch(user, &ctl->usertree, cmp_uid);
|
|
|
531551 |
+ }
|
|
|
531551 |
+ return 0;
|
|
|
531551 |
+}
|
|
|
531551 |
+
|
|
|
531551 |
+static struct libscols_table *setup_table(struct lslogins_control *ctl)
|
|
|
531551 |
+{
|
|
|
531551 |
+ struct libscols_table *tb = scols_new_table();
|
|
|
531551 |
+ int n = 0;
|
|
|
531551 |
+
|
|
|
531551 |
+ if (!tb)
|
|
|
531551 |
+ errx(EXIT_FAILURE, _("failed to initialize output table"));
|
|
|
531551 |
+ if (ctl->noheadings)
|
|
|
531551 |
+ scols_table_enable_noheadings(tb, 1);
|
|
|
531551 |
+
|
|
|
531551 |
+ switch(outmode) {
|
|
|
531551 |
+ case OUT_COLON:
|
|
|
531551 |
+ scols_table_enable_raw(tb, 1);
|
|
|
531551 |
+ scols_table_set_column_separator(tb, ":");
|
|
|
531551 |
+ break;
|
|
|
531551 |
+ case OUT_NEWLINE:
|
|
|
531551 |
+ scols_table_set_column_separator(tb, "\n");
|
|
|
531551 |
+ /* fallthrough */
|
|
|
531551 |
+ case OUT_EXPORT:
|
|
|
531551 |
+ scols_table_enable_export(tb, 1);
|
|
|
531551 |
+ break;
|
|
|
531551 |
+ case OUT_NUL:
|
|
|
531551 |
+ scols_table_set_line_separator(tb, "\0");
|
|
|
531551 |
+ /* fallthrough */
|
|
|
531551 |
+ case OUT_RAW:
|
|
|
531551 |
+ scols_table_enable_raw(tb, 1);
|
|
|
531551 |
+ break;
|
|
|
531551 |
+ case OUT_PRETTY:
|
|
|
531551 |
+ scols_table_enable_noheadings(tb, 1);
|
|
|
531551 |
+ default:
|
|
|
531551 |
+ break;
|
|
|
531551 |
+ }
|
|
|
531551 |
+
|
|
|
531551 |
+ while (n < ncolumns) {
|
|
|
531551 |
+ int flags = coldescs[columns[n]].flag;
|
|
|
531551 |
+
|
|
|
531551 |
+ if (ctl->notrunc)
|
|
|
531551 |
+ flags &= ~SCOLS_FL_TRUNC;
|
|
|
531551 |
+
|
|
|
531551 |
+ if (!scols_table_new_column(tb,
|
|
|
531551 |
+ coldescs[columns[n]].name,
|
|
|
531551 |
+ coldescs[columns[n]].whint,
|
|
|
531551 |
+ flags))
|
|
|
531551 |
+ goto fail;
|
|
|
531551 |
+ ++n;
|
|
|
531551 |
+ }
|
|
|
531551 |
+
|
|
|
531551 |
+ return tb;
|
|
|
531551 |
+fail:
|
|
|
531551 |
+ scols_unref_table(tb);
|
|
|
531551 |
+ return NULL;
|
|
|
531551 |
+}
|
|
|
531551 |
+
|
|
|
531551 |
+static void fill_table(const void *u, const VISIT which, const int depth __attribute__((unused)))
|
|
|
531551 |
+{
|
|
|
531551 |
+ struct libscols_line *ln;
|
|
|
531551 |
+ struct lslogins_user *user = *(struct lslogins_user **)u;
|
|
|
531551 |
+ int n = 0;
|
|
|
531551 |
+
|
|
|
531551 |
+ if (which == preorder || which == endorder)
|
|
|
531551 |
+ return;
|
|
|
531551 |
+
|
|
|
531551 |
+ ln = scols_table_new_line(tb, NULL);
|
|
|
531551 |
+ while (n < ncolumns) {
|
|
|
531551 |
+ int rc = 0;
|
|
|
531551 |
+
|
|
|
531551 |
+ switch (columns[n]) {
|
|
|
531551 |
+ case COL_USER:
|
|
|
531551 |
+ rc = scols_line_set_data(ln, n, user->login);
|
|
|
531551 |
+ break;
|
|
|
531551 |
+ case COL_UID:
|
|
|
531551 |
+ rc = scols_line_refer_data(ln, n, uidtostr(user->uid));
|
|
|
531551 |
+ break;
|
|
|
531551 |
+ case COL_PWDEMPTY:
|
|
|
531551 |
+ rc = scols_line_set_data(ln, n, get_status(user->pwd_empty));
|
|
|
531551 |
+ break;
|
|
|
531551 |
+ case COL_NOLOGIN:
|
|
|
531551 |
+ rc = scols_line_set_data(ln, n, get_status(user->nologin));
|
|
|
531551 |
+ break;
|
|
|
531551 |
+ case COL_PWDLOCK:
|
|
|
531551 |
+ rc = scols_line_set_data(ln, n, get_status(user->pwd_lock));
|
|
|
531551 |
+ break;
|
|
|
531551 |
+ case COL_PWDDENY:
|
|
|
531551 |
+ rc = scols_line_set_data(ln, n, get_status(user->pwd_deny));
|
|
|
531551 |
+ break;
|
|
|
531551 |
+ case COL_GROUP:
|
|
|
531551 |
+ rc = scols_line_set_data(ln, n, user->group);
|
|
|
531551 |
+ break;
|
|
|
531551 |
+ case COL_GID:
|
|
|
531551 |
+ rc = scols_line_refer_data(ln, n, gidtostr(user->gid));
|
|
|
531551 |
+ break;
|
|
|
531551 |
+ case COL_SGROUPS:
|
|
|
531551 |
+ rc = scols_line_refer_data(ln, n,
|
|
|
531551 |
+ build_sgroups_string(user->sgroups,
|
|
|
531551 |
+ user->nsgroups,
|
|
|
531551 |
+ TRUE));
|
|
|
531551 |
+ break;
|
|
|
531551 |
+ case COL_SGIDS:
|
|
|
531551 |
+ rc = scols_line_refer_data(ln, n,
|
|
|
531551 |
+ build_sgroups_string(user->sgroups,
|
|
|
531551 |
+ user->nsgroups,
|
|
|
531551 |
+ FALSE));
|
|
|
531551 |
+ break;
|
|
|
531551 |
+ case COL_HOME:
|
|
|
531551 |
+ rc = scols_line_set_data(ln, n, user->homedir);
|
|
|
531551 |
+ break;
|
|
|
531551 |
+ case COL_SHELL:
|
|
|
531551 |
+ rc = scols_line_set_data(ln, n, user->shell);
|
|
|
531551 |
+ break;
|
|
|
531551 |
+ case COL_GECOS:
|
|
|
531551 |
+ rc = scols_line_set_data(ln, n, user->gecos);
|
|
|
531551 |
+ break;
|
|
|
531551 |
+ case COL_LAST_LOGIN:
|
|
|
531551 |
+ rc = scols_line_set_data(ln, n, user->last_login);
|
|
|
531551 |
+ break;
|
|
|
531551 |
+ case COL_LAST_TTY:
|
|
|
531551 |
+ rc = scols_line_set_data(ln, n, user->last_tty);
|
|
|
531551 |
+ break;
|
|
|
531551 |
+ case COL_LAST_HOSTNAME:
|
|
|
531551 |
+ rc = scols_line_set_data(ln, n, user->last_hostname);
|
|
|
531551 |
+ break;
|
|
|
531551 |
+ case COL_FAILED_LOGIN:
|
|
|
531551 |
+ rc = scols_line_set_data(ln, n, user->failed_login);
|
|
|
531551 |
+ break;
|
|
|
531551 |
+ case COL_FAILED_TTY:
|
|
|
531551 |
+ rc = scols_line_set_data(ln, n, user->failed_tty);
|
|
|
531551 |
+ break;
|
|
|
531551 |
+ case COL_HUSH_STATUS:
|
|
|
531551 |
+ rc = scols_line_set_data(ln, n, get_status(user->hushed));
|
|
|
531551 |
+ break;
|
|
|
531551 |
+ case COL_PWD_WARN:
|
|
|
531551 |
+ rc = scols_line_set_data(ln, n, user->pwd_warn);
|
|
|
531551 |
+ break;
|
|
|
531551 |
+ case COL_PWD_EXPIR:
|
|
|
531551 |
+ rc = scols_line_set_data(ln, n, user->pwd_expire);
|
|
|
531551 |
+ break;
|
|
|
531551 |
+ case COL_PWD_CTIME:
|
|
|
531551 |
+ rc = scols_line_set_data(ln, n, user->pwd_ctime);
|
|
|
531551 |
+ break;
|
|
|
531551 |
+ case COL_PWD_CTIME_MIN:
|
|
|
531551 |
+ rc = scols_line_set_data(ln, n, user->pwd_ctime_min);
|
|
|
531551 |
+ break;
|
|
|
531551 |
+ case COL_PWD_CTIME_MAX:
|
|
|
531551 |
+ rc = scols_line_set_data(ln, n, user->pwd_ctime_max);
|
|
|
531551 |
+ break;
|
|
|
531551 |
+ case COL_SELINUX:
|
|
|
531551 |
+#ifdef HAVE_LIBSELINUX
|
|
|
531551 |
+ rc = scols_line_set_data(ln, n, user->context);
|
|
|
531551 |
+#endif
|
|
|
531551 |
+ break;
|
|
|
531551 |
+ case COL_NPROCS:
|
|
|
531551 |
+ rc = scols_line_set_data(ln, n, user->nprocs);
|
|
|
531551 |
+ break;
|
|
|
531551 |
+ default:
|
|
|
531551 |
+ /* something went very wrong here */
|
|
|
531551 |
+ err(EXIT_FAILURE, _("internal error: unknown column"));
|
|
|
531551 |
+ }
|
|
|
531551 |
+
|
|
|
531551 |
+ if (rc != 0)
|
|
|
531551 |
+ err(EXIT_FAILURE, _("failed to set data"));
|
|
|
531551 |
+ ++n;
|
|
|
531551 |
+ }
|
|
|
531551 |
+ return;
|
|
|
531551 |
+}
|
|
|
531551 |
+#ifdef HAVE_LIBSYSTEMD
|
|
|
531551 |
+static void print_journal_tail(const char *journal_path, uid_t uid, size_t len)
|
|
|
531551 |
+{
|
|
|
531551 |
+ sd_journal *j;
|
|
|
531551 |
+ char *match, *buf;
|
|
|
531551 |
+ uint64_t x;
|
|
|
531551 |
+ time_t t;
|
|
|
531551 |
+ const char *identifier, *pid, *message;
|
|
|
531551 |
+ size_t identifier_len, pid_len, message_len;
|
|
|
531551 |
+
|
|
|
531551 |
+ if (journal_path)
|
|
|
531551 |
+ sd_journal_open_directory(&j, journal_path, 0);
|
|
|
531551 |
+ else
|
|
|
531551 |
+ sd_journal_open(&j, SD_JOURNAL_LOCAL_ONLY);
|
|
|
531551 |
+
|
|
|
531551 |
+ buf = xmalloc(sizeof(char) * 16);
|
|
|
531551 |
+ xasprintf(&match, "_UID=%d", uid);
|
|
|
531551 |
+
|
|
|
531551 |
+ sd_journal_add_match(j, match, 0);
|
|
|
531551 |
+ sd_journal_seek_tail(j);
|
|
|
531551 |
+ sd_journal_previous_skip(j, len);
|
|
|
531551 |
+
|
|
|
531551 |
+ do {
|
|
|
531551 |
+ if (0 > sd_journal_get_data(j, "SYSLOG_IDENTIFIER",
|
|
|
531551 |
+ (const void **) &identifier, &identifier_len))
|
|
|
531551 |
+ return;
|
|
|
531551 |
+ if (0 > sd_journal_get_data(j, "_PID",
|
|
|
531551 |
+ (const void **) &pid, &pid_len))
|
|
|
531551 |
+ return;
|
|
|
531551 |
+ if (0 > sd_journal_get_data(j, "MESSAGE",
|
|
|
531551 |
+ (const void **) &message, &message_len))
|
|
|
531551 |
+ return;
|
|
|
531551 |
+
|
|
|
531551 |
+ sd_journal_get_realtime_usec(j, &x);
|
|
|
531551 |
+ t = x / 1000000;
|
|
|
531551 |
+ strftime(buf, 16, "%b %d %H:%M:%S", localtime(&t);;
|
|
|
531551 |
+
|
|
|
531551 |
+ fprintf(stdout, "%s", buf);
|
|
|
531551 |
+
|
|
|
531551 |
+ identifier = strchr(identifier, '=') + 1;
|
|
|
531551 |
+ pid = strchr(pid, '=') + 1 ;
|
|
|
531551 |
+ message = strchr(message, '=') + 1;
|
|
|
531551 |
+
|
|
|
531551 |
+ fprintf(stdout, " %s", identifier);
|
|
|
531551 |
+ fprintf(stdout, "[%s]:", pid);
|
|
|
531551 |
+ fprintf(stdout, "%s\n", message);
|
|
|
531551 |
+ } while (sd_journal_next(j));
|
|
|
531551 |
+
|
|
|
531551 |
+ free(buf);
|
|
|
531551 |
+ free(match);
|
|
|
531551 |
+ sd_journal_flush_matches(j);
|
|
|
531551 |
+ sd_journal_close(j);
|
|
|
531551 |
+}
|
|
|
531551 |
+#endif
|
|
|
531551 |
+
|
|
|
531551 |
+static int print_pretty(struct libscols_table *tb)
|
|
|
531551 |
+{
|
|
|
531551 |
+ struct libscols_iter *itr = scols_new_iter(SCOLS_ITER_FORWARD);
|
|
|
531551 |
+ struct libscols_column *col;
|
|
|
531551 |
+ struct libscols_cell *data;
|
|
|
531551 |
+ struct libscols_line *ln;
|
|
|
531551 |
+ const char *hstr, *dstr;
|
|
|
531551 |
+ int n = 0;
|
|
|
531551 |
+
|
|
|
531551 |
+ ln = scols_table_get_line(tb, 0);
|
|
|
531551 |
+ while (!scols_table_next_column(tb, itr, &col)) {
|
|
|
531551 |
+
|
|
|
531551 |
+ data = scols_line_get_cell(ln, n);
|
|
|
531551 |
+
|
|
|
531551 |
+ hstr = _(coldescs[columns[n]].pretty_name);
|
|
|
531551 |
+ dstr = scols_cell_get_data(data);
|
|
|
531551 |
+
|
|
|
531551 |
+ if (dstr)
|
|
|
531551 |
+ printf("%s:%*c%-36s\n", hstr, 35 - (int)strlen(hstr), ' ', dstr);
|
|
|
531551 |
+ ++n;
|
|
|
531551 |
+ }
|
|
|
531551 |
+
|
|
|
531551 |
+ scols_free_iter(itr);
|
|
|
531551 |
+ return 0;
|
|
|
531551 |
+
|
|
|
531551 |
+}
|
|
|
531551 |
+
|
|
|
531551 |
+static int print_user_table(struct lslogins_control *ctl)
|
|
|
531551 |
+{
|
|
|
531551 |
+ tb = setup_table(ctl);
|
|
|
531551 |
+ if (!tb)
|
|
|
531551 |
+ return -1;
|
|
|
531551 |
+
|
|
|
531551 |
+ twalk(ctl->usertree, fill_table);
|
|
|
531551 |
+ if (outmode == OUT_PRETTY) {
|
|
|
531551 |
+ print_pretty(tb);
|
|
|
531551 |
+#ifdef HAVE_LIBSYSTEMD
|
|
|
531551 |
+ fprintf(stdout, _("\nLast logs:\n"));
|
|
|
531551 |
+ print_journal_tail(ctl->journal_path, ctl->uid, 3);
|
|
|
531551 |
+ fputc('\n', stdout);
|
|
|
531551 |
+#endif
|
|
|
531551 |
+ } else
|
|
|
531551 |
+ scols_print_table(tb);
|
|
|
531551 |
+ return 0;
|
|
|
531551 |
+}
|
|
|
531551 |
+
|
|
|
531551 |
+static void free_user(void *f)
|
|
|
531551 |
+{
|
|
|
531551 |
+ struct lslogins_user *u = f;
|
|
|
531551 |
+ free(u->login);
|
|
|
531551 |
+ free(u->group);
|
|
|
531551 |
+ free(u->gecos);
|
|
|
531551 |
+ free(u->sgroups);
|
|
|
531551 |
+ free(u->pwd_ctime);
|
|
|
531551 |
+ free(u->pwd_warn);
|
|
|
531551 |
+ free(u->pwd_ctime_min);
|
|
|
531551 |
+ free(u->pwd_ctime_max);
|
|
|
531551 |
+ free(u->last_login);
|
|
|
531551 |
+ free(u->last_tty);
|
|
|
531551 |
+ free(u->last_hostname);
|
|
|
531551 |
+ free(u->failed_login);
|
|
|
531551 |
+ free(u->failed_tty);
|
|
|
531551 |
+ free(u->homedir);
|
|
|
531551 |
+ free(u->shell);
|
|
|
531551 |
+ free(u->pwd_status);
|
|
|
531551 |
+#ifdef HAVE_LIBSELINUX
|
|
|
531551 |
+ freecon(u->context);
|
|
|
531551 |
+#endif
|
|
|
531551 |
+ free(u);
|
|
|
531551 |
+}
|
|
|
531551 |
+
|
|
|
531551 |
+struct lslogins_timefmt {
|
|
|
531551 |
+ const char *name;
|
|
|
531551 |
+ int val;
|
|
|
531551 |
+};
|
|
|
531551 |
+
|
|
|
531551 |
+static struct lslogins_timefmt timefmts[] = {
|
|
|
531551 |
+ { "short", TIME_SHORT },
|
|
|
531551 |
+ { "full", TIME_FULL },
|
|
|
531551 |
+ { "iso", TIME_ISO },
|
|
|
531551 |
+};
|
|
|
531551 |
+
|
|
|
531551 |
+static void __attribute__((__noreturn__)) usage(FILE *out)
|
|
|
531551 |
+{
|
|
|
531551 |
+ size_t i;
|
|
|
531551 |
+
|
|
|
531551 |
+ fputs(USAGE_HEADER, out);
|
|
|
531551 |
+ fprintf(out, _(" %s [options]\n"), program_invocation_short_name);
|
|
|
531551 |
+
|
|
|
531551 |
+ fputs(USAGE_OPTIONS, out);
|
|
|
531551 |
+ fputs(_(" -a, --acc-expiration display info about passwords expiration\n"), out);
|
|
|
531551 |
+ fputs(_(" -c, --colon-separate display data in a format similar to /etc/passwd\n"), out);
|
|
|
531551 |
+ fputs(_(" -e, --export display in an export-able output format\n"), out);
|
|
|
531551 |
+ fputs(_(" -f, --failed display data about the users' last failed logins\n"), out);
|
|
|
531551 |
+ fputs(_(" -G, --groups-info display information about groups\n"), out);
|
|
|
531551 |
+ fputs(_(" -g, --groups=<groups> display users belonging to a group in <groups>\n"), out);
|
|
|
531551 |
+ fputs(_(" -L, --last show info about the users' last login sessions\n"), out);
|
|
|
531551 |
+ fputs(_(" -l, --logins=<logins> display only users from <logins>\n"), out);
|
|
|
531551 |
+ fputs(_(" -m, --supp-groups display supplementary groups as well\n"), out);
|
|
|
531551 |
+ fputs(_(" -n, --newline display each piece of information on a new line\n"), out);
|
|
|
531551 |
+ fputs(_(" --noheadings don't print headings\n"), out);
|
|
|
531551 |
+ fputs(_(" --notruncate don't truncate output\n"), out);
|
|
|
531551 |
+ fputs(_(" -o, --output[=<list>] define the columns to output\n"), out);
|
|
|
531551 |
+ fputs(_(" -p, --pwd display information related to login by password.\n"), out);
|
|
|
531551 |
+ fputs(_(" -r, --raw display in raw mode\n"), out);
|
|
|
531551 |
+ fputs(_(" -s, --system-accs display system accounts\n"), out);
|
|
|
531551 |
+ fputs(_(" --time-format=<type> display dates in short, full or iso format\n"), out);
|
|
|
531551 |
+ fputs(_(" -u, --user-accs display user accounts\n"), out);
|
|
|
531551 |
+ fputs(_(" -Z, --context display SELinux contexts\n"), out);
|
|
|
531551 |
+ fputs(_(" -z, --print0 delimit user entries with a nul character\n"), out);
|
|
|
531551 |
+ fputs(_(" --wtmp-file <path> set an alternate path for wtmp\n"), out);
|
|
|
531551 |
+ fputs(_(" --btmp-file <path> set an alternate path for btmp\n"), out);
|
|
|
531551 |
+ fputs(USAGE_SEPARATOR, out);
|
|
|
531551 |
+ fputs(USAGE_HELP, out);
|
|
|
531551 |
+ fputs(USAGE_VERSION, out);
|
|
|
531551 |
+
|
|
|
531551 |
+ fprintf(out, _("\nAvailable columns:\n"));
|
|
|
531551 |
+
|
|
|
531551 |
+ for (i = 0; i < ARRAY_SIZE(coldescs); i++)
|
|
|
531551 |
+ fprintf(out, " %14s %s\n", coldescs[i].name,
|
|
|
531551 |
+ _(coldescs[i].help));
|
|
|
531551 |
+
|
|
|
531551 |
+ fprintf(out, _("\nFor more details see lslogins(1).\n"));
|
|
|
531551 |
+
|
|
|
531551 |
+ exit(out == stderr ? EXIT_FAILURE : EXIT_SUCCESS);
|
|
|
531551 |
+}
|
|
|
531551 |
+
|
|
|
531551 |
+int main(int argc, char *argv[])
|
|
|
531551 |
+{
|
|
|
531551 |
+ int c, opt_o = 0;
|
|
|
531551 |
+ char *logins = NULL, *groups = NULL;
|
|
|
531551 |
+ char *path_wtmp = _PATH_WTMP, *path_btmp = _PATH_BTMP;
|
|
|
531551 |
+ struct lslogins_control *ctl = xcalloc(1, sizeof(struct lslogins_control));
|
|
|
531551 |
+ size_t i;
|
|
|
531551 |
+
|
|
|
531551 |
+ /* long only options. */
|
|
|
531551 |
+ enum {
|
|
|
531551 |
+ OPT_VER = CHAR_MAX + 1,
|
|
|
531551 |
+ OPT_WTMP,
|
|
|
531551 |
+ OPT_BTMP,
|
|
|
531551 |
+ OPT_NOTRUNC,
|
|
|
531551 |
+ OPT_NOHEAD,
|
|
|
531551 |
+ OPT_TIME_FMT,
|
|
|
531551 |
+ };
|
|
|
531551 |
+
|
|
|
531551 |
+ static const struct option longopts[] = {
|
|
|
531551 |
+ { "acc-expiration", no_argument, 0, 'a' },
|
|
|
531551 |
+ { "colon-separate", no_argument, 0, 'c' },
|
|
|
531551 |
+ { "export", no_argument, 0, 'e' },
|
|
|
531551 |
+ { "failed", no_argument, 0, 'f' },
|
|
|
531551 |
+ { "groups", required_argument, 0, 'g' },
|
|
|
531551 |
+ { "help", no_argument, 0, 'h' },
|
|
|
531551 |
+ { "logins", required_argument, 0, 'l' },
|
|
|
531551 |
+ { "supp-groups", no_argument, 0, 'G' },
|
|
|
531551 |
+ { "newline", no_argument, 0, 'n' },
|
|
|
531551 |
+ { "notruncate", no_argument, 0, OPT_NOTRUNC },
|
|
|
531551 |
+ { "noheadings", no_argument, 0, OPT_NOHEAD },
|
|
|
531551 |
+ { "output", required_argument, 0, 'o' },
|
|
|
531551 |
+ { "last", no_argument, 0, 'L', },
|
|
|
531551 |
+ { "raw", no_argument, 0, 'r' },
|
|
|
531551 |
+ { "system-accs", no_argument, 0, 's' },
|
|
|
531551 |
+ { "time-format", required_argument, 0, OPT_TIME_FMT },
|
|
|
531551 |
+ { "user-accs", no_argument, 0, 'u' },
|
|
|
531551 |
+ { "version", no_argument, 0, 'V' },
|
|
|
531551 |
+ { "pwd", no_argument, 0, 'p' },
|
|
|
531551 |
+ { "print0", no_argument, 0, 'z' },
|
|
|
531551 |
+ { "wtmp-file", required_argument, 0, OPT_WTMP },
|
|
|
531551 |
+ { "btmp-file", required_argument, 0, OPT_BTMP },
|
|
|
531551 |
+#ifdef HAVE_LIBSELINUX
|
|
|
531551 |
+ { "context", no_argument, 0, 'Z' },
|
|
|
531551 |
+#endif
|
|
|
531551 |
+ { NULL, 0, 0, 0 }
|
|
|
531551 |
+ };
|
|
|
531551 |
+
|
|
|
531551 |
+ static const ul_excl_t excl[] = { /* rows and cols in ASCII order */
|
|
|
531551 |
+ { 'G', 'o' },
|
|
|
531551 |
+ { 'L', 'o' },
|
|
|
531551 |
+ { 'Z', 'o' },
|
|
|
531551 |
+ { 'a', 'o' },
|
|
|
531551 |
+ { 'c','n','r','z' },
|
|
|
531551 |
+ { 'o', 'p' },
|
|
|
531551 |
+ { 0 }
|
|
|
531551 |
+ };
|
|
|
531551 |
+ int excl_st[ARRAY_SIZE(excl)] = UL_EXCL_STATUS_INIT;
|
|
|
531551 |
+
|
|
|
531551 |
+ setlocale(LC_ALL, "");
|
|
|
531551 |
+ bindtextdomain(PACKAGE, LOCALEDIR);
|
|
|
531551 |
+ textdomain(PACKAGE);
|
|
|
531551 |
+ atexit(close_stdout);
|
|
|
531551 |
+
|
|
|
531551 |
+ ctl->time_mode = TIME_SHORT;
|
|
|
531551 |
+
|
|
|
531551 |
+ /* very basic default */
|
|
|
531551 |
+ add_column(columns, ncolumns++, COL_UID);
|
|
|
531551 |
+ add_column(columns, ncolumns++, COL_USER);
|
|
|
531551 |
+
|
|
|
531551 |
+ while ((c = getopt_long(argc, argv, "acfGg:hLl:no:prsuVxzZ",
|
|
|
531551 |
+ longopts, NULL)) != -1) {
|
|
|
531551 |
+
|
|
|
531551 |
+ err_exclusive_options(c, longopts, excl, excl_st);
|
|
|
531551 |
+
|
|
|
531551 |
+ switch (c) {
|
|
|
531551 |
+ case 'a':
|
|
|
531551 |
+ add_column(columns, ncolumns++, COL_PWD_WARN);
|
|
|
531551 |
+ add_column(columns, ncolumns++, COL_PWD_CTIME_MIN);
|
|
|
531551 |
+ add_column(columns, ncolumns++, COL_PWD_CTIME_MAX);
|
|
|
531551 |
+ add_column(columns, ncolumns++, COL_PWD_CTIME);
|
|
|
531551 |
+ add_column(columns, ncolumns++, COL_PWD_EXPIR);
|
|
|
531551 |
+ break;
|
|
|
531551 |
+ case 'c':
|
|
|
531551 |
+ outmode = OUT_COLON;
|
|
|
531551 |
+ break;
|
|
|
531551 |
+ case 'e':
|
|
|
531551 |
+ outmode = OUT_EXPORT;
|
|
|
531551 |
+ break;
|
|
|
531551 |
+ case 'f':
|
|
|
531551 |
+ add_column(columns, ncolumns++, COL_FAILED_LOGIN);
|
|
|
531551 |
+ add_column(columns, ncolumns++, COL_FAILED_TTY);
|
|
|
531551 |
+ break;
|
|
|
531551 |
+ case 'G':
|
|
|
531551 |
+ add_column(columns, ncolumns++, COL_GID);
|
|
|
531551 |
+ add_column(columns, ncolumns++, COL_GROUP);
|
|
|
531551 |
+ add_column(columns, ncolumns++, COL_SGIDS);
|
|
|
531551 |
+ add_column(columns, ncolumns++, COL_SGROUPS);
|
|
|
531551 |
+ break;
|
|
|
531551 |
+ case 'g':
|
|
|
531551 |
+ groups = optarg;
|
|
|
531551 |
+ break;
|
|
|
531551 |
+ case 'h':
|
|
|
531551 |
+ usage(stdout);
|
|
|
531551 |
+ break;
|
|
|
531551 |
+ case 'L':
|
|
|
531551 |
+ add_column(columns, ncolumns++, COL_LAST_TTY);
|
|
|
531551 |
+ add_column(columns, ncolumns++, COL_LAST_HOSTNAME);
|
|
|
531551 |
+ add_column(columns, ncolumns++, COL_LAST_LOGIN);
|
|
|
531551 |
+ break;
|
|
|
531551 |
+ case 'l':
|
|
|
531551 |
+ logins = optarg;
|
|
|
531551 |
+ break;
|
|
|
531551 |
+ case 'n':
|
|
|
531551 |
+ outmode = OUT_NEWLINE;
|
|
|
531551 |
+ break;
|
|
|
531551 |
+ case 'o':
|
|
|
531551 |
+ if (optarg) {
|
|
|
531551 |
+ if (*optarg == '=')
|
|
|
531551 |
+ optarg++;
|
|
|
531551 |
+ ncolumns = string_to_idarray(optarg,
|
|
|
531551 |
+ columns, ARRAY_SIZE(columns),
|
|
|
531551 |
+ column_name_to_id);
|
|
|
531551 |
+ if (ncolumns < 0)
|
|
|
531551 |
+ return EXIT_FAILURE;
|
|
|
531551 |
+ }
|
|
|
531551 |
+ opt_o = 1;
|
|
|
531551 |
+ break;
|
|
|
531551 |
+ case 'r':
|
|
|
531551 |
+ outmode = OUT_RAW;
|
|
|
531551 |
+ break;
|
|
|
531551 |
+ case 's':
|
|
|
531551 |
+ ctl->SYS_UID_MIN = getlogindefs_num("SYS_UID_MIN", UL_SYS_UID_MIN);
|
|
|
531551 |
+ ctl->SYS_UID_MAX = getlogindefs_num("SYS_UID_MAX", UL_SYS_UID_MAX);
|
|
|
531551 |
+ lslogins_flag |= F_SYSAC;
|
|
|
531551 |
+ break;
|
|
|
531551 |
+ case 'u':
|
|
|
531551 |
+ ctl->UID_MIN = getlogindefs_num("UID_MIN", UL_UID_MIN);
|
|
|
531551 |
+ ctl->UID_MAX = getlogindefs_num("UID_MAX", UL_UID_MAX);
|
|
|
531551 |
+ lslogins_flag |= F_USRAC;
|
|
|
531551 |
+ break;
|
|
|
531551 |
+ case 'p':
|
|
|
531551 |
+ add_column(columns, ncolumns++, COL_PWDEMPTY);
|
|
|
531551 |
+ add_column(columns, ncolumns++, COL_PWDLOCK);
|
|
|
531551 |
+ add_column(columns, ncolumns++, COL_PWDDENY);
|
|
|
531551 |
+ add_column(columns, ncolumns++, COL_NOLOGIN);
|
|
|
531551 |
+ add_column(columns, ncolumns++, COL_HUSH_STATUS);
|
|
|
531551 |
+ break;
|
|
|
531551 |
+ case 'z':
|
|
|
531551 |
+ outmode = OUT_NUL;
|
|
|
531551 |
+ break;
|
|
|
531551 |
+ case OPT_WTMP:
|
|
|
531551 |
+ path_wtmp = optarg;
|
|
|
531551 |
+ break;
|
|
|
531551 |
+ case OPT_BTMP:
|
|
|
531551 |
+ path_btmp = optarg;
|
|
|
531551 |
+ break;
|
|
|
531551 |
+ case OPT_NOTRUNC:
|
|
|
531551 |
+ ctl->notrunc = 1;
|
|
|
531551 |
+ break;
|
|
|
531551 |
+ case OPT_NOHEAD:
|
|
|
531551 |
+ ctl->noheadings = 1;
|
|
|
531551 |
+ break;
|
|
|
531551 |
+ case OPT_TIME_FMT:
|
|
|
531551 |
+ {
|
|
|
531551 |
+ size_t i;
|
|
|
531551 |
+
|
|
|
531551 |
+ for (i = 0; i < ARRAY_SIZE(timefmts); i++) {
|
|
|
531551 |
+ if (strcmp(timefmts[i].name, optarg) == 0) {
|
|
|
531551 |
+ ctl->time_mode = timefmts[i].val;
|
|
|
531551 |
+ break;
|
|
|
531551 |
+ }
|
|
|
531551 |
+ }
|
|
|
531551 |
+ if (ctl->time_mode == TIME_INVALID)
|
|
|
531551 |
+ usage(stderr);
|
|
|
531551 |
+ }
|
|
|
531551 |
+ break;
|
|
|
531551 |
+ case 'V':
|
|
|
531551 |
+ printf(UTIL_LINUX_VERSION);
|
|
|
531551 |
+ return EXIT_SUCCESS;
|
|
|
531551 |
+ case 'Z':
|
|
|
531551 |
+ {
|
|
|
531551 |
+#ifdef HAVE_LIBSELINUX
|
|
|
531551 |
+ int sl = is_selinux_enabled();
|
|
|
531551 |
+ if (sl < 0)
|
|
|
531551 |
+ warn(_("failed to request selinux state"));
|
|
|
531551 |
+ else
|
|
|
531551 |
+ ctl->selinux_enabled = sl == 1;
|
|
|
531551 |
+#endif
|
|
|
531551 |
+ add_column(columns, ncolumns++, COL_SELINUX);
|
|
|
531551 |
+ break;
|
|
|
531551 |
+ }
|
|
|
531551 |
+ default:
|
|
|
531551 |
+ usage(stderr);
|
|
|
531551 |
+ }
|
|
|
531551 |
+ }
|
|
|
531551 |
+
|
|
|
531551 |
+ if (argc - optind == 1) {
|
|
|
531551 |
+ if (strchr(argv[optind], ','))
|
|
|
531551 |
+ errx(EXIT_FAILURE, _("Only one user may be specified. Use -l for multiple users."));
|
|
|
531551 |
+ logins = argv[optind];
|
|
|
531551 |
+ outmode = OUT_PRETTY;
|
|
|
531551 |
+ } else if (argc != optind)
|
|
|
531551 |
+ usage(stderr);
|
|
|
531551 |
+
|
|
|
531551 |
+ scols_init_debug(0);
|
|
|
531551 |
+
|
|
|
531551 |
+ /* lslogins -u -s == lslogins */
|
|
|
531551 |
+ if (lslogins_flag & F_USRAC && lslogins_flag & F_SYSAC)
|
|
|
531551 |
+ lslogins_flag &= ~(F_USRAC | F_SYSAC);
|
|
|
531551 |
+
|
|
|
531551 |
+ if (outmode == OUT_PRETTY && !opt_o) {
|
|
|
531551 |
+ /* all columns for lslogins <username> */
|
|
|
531551 |
+ for (ncolumns = 0, i = 0; i < ARRAY_SIZE(coldescs); i++)
|
|
|
531551 |
+ columns[ncolumns++] = i;
|
|
|
531551 |
+
|
|
|
531551 |
+ } else if (ncolumns == 2 && !opt_o) {
|
|
|
531551 |
+ /* default colummns */
|
|
|
531551 |
+ add_column(columns, ncolumns++, COL_NPROCS);
|
|
|
531551 |
+ add_column(columns, ncolumns++, COL_PWDLOCK);
|
|
|
531551 |
+ add_column(columns, ncolumns++, COL_PWDDENY);
|
|
|
531551 |
+ add_column(columns, ncolumns++, COL_LAST_LOGIN);
|
|
|
531551 |
+ add_column(columns, ncolumns++, COL_GECOS);
|
|
|
531551 |
+ }
|
|
|
531551 |
+
|
|
|
531551 |
+ if (require_wtmp())
|
|
|
531551 |
+ parse_wtmp(ctl, path_wtmp);
|
|
|
531551 |
+ if (require_btmp())
|
|
|
531551 |
+ parse_btmp(ctl, path_btmp);
|
|
|
531551 |
+
|
|
|
531551 |
+ if (logins || groups)
|
|
|
531551 |
+ get_ulist(ctl, logins, groups);
|
|
|
531551 |
+
|
|
|
531551 |
+ if (create_usertree(ctl))
|
|
|
531551 |
+ return EXIT_FAILURE;
|
|
|
531551 |
+
|
|
|
531551 |
+ print_user_table(ctl);
|
|
|
531551 |
+
|
|
|
531551 |
+ scols_unref_table(tb);
|
|
|
531551 |
+ tdestroy(ctl->usertree, free_user);
|
|
|
531551 |
+ free_ctl(ctl);
|
|
|
531551 |
+
|
|
|
531551 |
+ return EXIT_SUCCESS;
|
|
|
531551 |
+}
|
|
|
531551 |
diff -up util-linux-2.23.2/login-utils/Makemodule.am.kzak util-linux-2.23.2/login-utils/Makemodule.am
|
|
|
531551 |
--- util-linux-2.23.2/login-utils/Makemodule.am.kzak 2013-06-13 09:46:10.441650801 +0200
|
|
|
531551 |
+++ util-linux-2.23.2/login-utils/Makemodule.am 2014-12-12 15:28:30.576177139 +0100
|
|
|
531551 |
@@ -145,6 +145,25 @@ endif
|
|
|
531551 |
endif # BUILD_NEWGRP
|
|
|
531551 |
|
|
|
531551 |
|
|
|
531551 |
+if BUILD_LSLOGINS
|
|
|
531551 |
+usrbin_exec_PROGRAMS += lslogins
|
|
|
531551 |
+dist_man_MANS += login-utils/lslogins.1
|
|
|
531551 |
+lslogins_SOURCES = \
|
|
|
531551 |
+ login-utils/lslogins.c \
|
|
|
531551 |
+ login-utils/logindefs.c \
|
|
|
531551 |
+ login-utils/logindefs.h
|
|
|
531551 |
+lslogins_LDADD = $(LDADD) libcommon.la libsmartcols.la
|
|
|
531551 |
+lslogins_CFLAGS = $(AM_CFLAGS) -I$(ul_libsmartcols_incdir)
|
|
|
531551 |
+if HAVE_SELINUX
|
|
|
531551 |
+lslogins_LDADD += -lselinux
|
|
|
531551 |
+endif
|
|
|
531551 |
+if HAVE_SYSTEMD
|
|
|
531551 |
+lslogins_LDADD += $(SYSTEMD_LIBS) $(SYSTEMD_JOURNAL_LIBS)
|
|
|
531551 |
+lslogins_CFLAGS += $(SYSTEMD_CFLAGS) $(SYSTEMD_JOURNAL_CFLAGS)
|
|
|
531551 |
+endif
|
|
|
531551 |
+endif # BUILD_LSLOGINS
|
|
|
531551 |
+
|
|
|
531551 |
+
|
|
|
531551 |
if BUILD_VIPW
|
|
|
531551 |
usrsbin_exec_PROGRAMS += vipw
|
|
|
531551 |
dist_man_MANS += \
|