dcavalca / rpms / util-linux

Forked from rpms/util-linux 2 years ago
Clone
531551
diff -up util-linux-2.23.2/include/pathnames.h.kzak util-linux-2.23.2/include/pathnames.h
531551
--- util-linux-2.23.2/include/pathnames.h.kzak	2016-03-16 15:17:42.648298525 +0100
531551
+++ util-linux-2.23.2/include/pathnames.h	2016-03-16 15:18:13.769055345 +0100
531551
@@ -36,6 +36,7 @@
531551
 #endif
531551
 #define	_PATH_MOTDFILE		"/etc/motd"
531551
 #define	_PATH_NOLOGIN		"/etc/nologin"
531551
+#define _PATH_VAR_NOLOGIN       "/var/run/nologin"
531551
 
531551
 #define _PATH_LOGIN		"/bin/login"
531551
 #define _PATH_INITTAB		"/etc/inittab"
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	2016-03-16 15:17:42.639298595 +0100
531551
+++ util-linux-2.23.2/login-utils/lslogins.1	2016-03-16 15:18:13.769055345 +0100
531551
@@ -5,7 +5,10 @@
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
+[options]
531551
+.RB [ \-s | \-u [ =\fIUID ]]
531551
+.RB [ \-g " \fIgroups\fR]"
531551
+.RB [ \-l " \fIlogins\fR]"
531551
 .SH DESCRIPTION
531551
 .PP
531551
 Examine the wtmp and btmp logs, /etc/shadow (if necessary) and /etc/passwd
531551
@@ -17,7 +20,7 @@ Mandatory arguments to long options are
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
+date (see \fBshadow\fR(5) for more info).  (Requires root privileges.)
531551
 .TP
531551
 \fB\-\-btmp\-file \fIpath\fP
531551
 Alternate path for btmp.
531551
@@ -31,7 +34,7 @@ Output data in the format of NAME=VALUE.
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
+\fB\-G\fR, \fB\-\-supp\-groups\fR
531551
 Show information about groups.
531551
 .TP
531551
 \fB\-g\fR, \fB\-\-groups\fR=\fIgroups\fR
531551
@@ -48,9 +51,6 @@ Display data containing information abou
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
@@ -71,21 +71,21 @@ Display information related to login by
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
+\fB\-s\fR, \fB\-\-system\-accs\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
+(non-inclusive), with the exception of either nobody or nfsnobody (UID 65534).
531551
+This hardcoded default maybe overwritten by parameters SYS_UID_MIN and SYS_UID_MAX in
531551
+the file /etc/login.defs.
531551
 .TP
531551
-\fB\-\-time-format\fR \fItype\fP
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
+\fB\-u\fR, \fB\-\-user\-accs\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
+(inclusive), with the exception of either nobody or nfsnobody (UID 65534).
531551
+This hardcoded default maybe overwritten by parameters UID_MIN and UID_MAX in
531551
+the file /etc/login.defs.
531551
 .TP
531551
 \fB\-V\fR, \fB\-\-version\fR
531551
 Display version information and exit.
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	2016-03-16 15:17:42.639298595 +0100
531551
+++ util-linux-2.23.2/login-utils/lslogins.c	2016-03-16 15:22:49.845899268 +0100
531551
@@ -144,6 +144,7 @@ enum {
531551
 	TIME_SHORT,
531551
 	TIME_FULL,
531551
 	TIME_ISO,
531551
+	TIME_ISO_SHORT,
531551
 };
531551
 
531551
 /*
531551
@@ -350,6 +351,9 @@ static char *make_time(int mode, time_t
531551
 	case TIME_ISO:
531551
 		strftime(buf, sizeof(buf), "%Y-%m-%dT%H:%M:%S%z", &tm;;
531551
 		break;
531551
+	case TIME_ISO_SHORT:
531551
+		strftime(buf, sizeof(buf), "%Y-%m-%d", &tm;;
531551
+		break;
531551
 	default:
531551
 		errx(EXIT_FAILURE, _("unsupported time type"));
531551
 	}
531551
@@ -396,7 +400,7 @@ again:
531551
 			x = snprintf(p, len, "%s,", grp->gr_name);
531551
 		}
531551
 
531551
-		if (x < 0 || (size_t) x + 1 > len) {
531551
+		if (x < 0 || (size_t) x >= len) {
531551
 			size_t cur = p - res;
531551
 
531551
 			maxlen *= 2;
531551
@@ -496,21 +500,24 @@ static int parse_btmp(struct lslogins_co
531551
 static int get_sgroups(gid_t **list, size_t *len, struct passwd *pwd)
531551
 {
531551
 	size_t n = 0;
531551
+	int ngroups = 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
+	getgrouplist(pwd->pw_name, pwd->pw_gid, *list, &ngroups);
531551
+	if (!ngroups)
531551
 		return -1;
531551
 
531551
-	*list = xcalloc(1, *len * sizeof(gid_t));
531551
+	*list = xcalloc(1, ngroups * 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
+	if (-1 == getgrouplist(pwd->pw_name, pwd->pw_gid, *list, &ngroups))
531551
 		return -1;
531551
 
531551
+	*len = (size_t) ngroups;
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
@@ -520,6 +527,7 @@ static int get_sgroups(gid_t **list, siz
531551
 
531551
 	if (*len)
531551
 		(*list)[n] = (*list)[--(*len)];
531551
+
531551
 	return 0;
531551
 }
531551
 
531551
@@ -685,8 +693,8 @@ static struct lslogins_user *get_user_in
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
+				user->nologin = access(_PATH_NOLOGIN, F_OK) == 0 ||
531551
+						access(_PATH_VAR_NOLOGIN, F_OK) == 0;
531551
 			break;
531551
 		case COL_PWD_WARN:
531551
 			if (shadow && shadow->sp_warn >= 0)
531551
@@ -694,7 +702,8 @@ static struct lslogins_user *get_user_in
531551
 			break;
531551
 		case COL_PWD_EXPIR:
531551
 			if (shadow && shadow->sp_expire >= 0)
531551
-				user->pwd_expire = make_time(TIME_SHORT,
531551
+				user->pwd_expire = make_time(ctl->time_mode == TIME_ISO ?
531551
+						TIME_ISO_SHORT : ctl->time_mode,
531551
 						shadow->sp_expire * 86400);
531551
 			break;
531551
 		case COL_PWD_CTIME:
531551
@@ -702,7 +711,8 @@ static struct lslogins_user *get_user_in
531551
 			 * (especially in non-GMT timezones) would only serve
531551
 			 * to confuse */
531551
 			if (shadow)
531551
-				user->pwd_ctime = make_time(TIME_SHORT,
531551
+				user->pwd_ctime = make_time(ctl->time_mode == TIME_ISO ?
531551
+						TIME_ISO_SHORT : ctl->time_mode,
531551
 						shadow->sp_lstchg * 86400);
531551
 			break;
531551
 		case COL_PWD_CTIME_MIN:
531551
@@ -852,7 +862,7 @@ static int get_user(struct lslogins_cont
531551
 		    const char *username)
531551
 {
531551
 	*user = get_user_info(ctl, username);
531551
-	if (!*user && errno)
531551
+	if (!*user)
531551
 		if (IS_REAL_ERRNO(errno))
531551
 			return -1;
531551
 	return 0;
531551
@@ -887,33 +897,33 @@ static int create_usertree(struct lslogi
531551
 
531551
 static struct libscols_table *setup_table(struct lslogins_control *ctl)
531551
 {
531551
-	struct libscols_table *tb = scols_new_table();
531551
+	struct libscols_table *table = scols_new_table();
531551
 	int n = 0;
531551
 
531551
-	if (!tb)
531551
+	if (!table)
531551
 		errx(EXIT_FAILURE, _("failed to initialize output table"));
531551
 	if (ctl->noheadings)
531551
-		scols_table_enable_noheadings(tb, 1);
531551
+		scols_table_enable_noheadings(table, 1);
531551
 
531551
 	switch(outmode) {
531551
 	case OUT_COLON:
531551
-		scols_table_enable_raw(tb, 1);
531551
-		scols_table_set_column_separator(tb, ":");
531551
+		scols_table_enable_raw(table, 1);
531551
+		scols_table_set_column_separator(table, ":");
531551
 		break;
531551
 	case OUT_NEWLINE:
531551
-		scols_table_set_column_separator(tb, "\n");
531551
+		scols_table_set_column_separator(table, "\n");
531551
 		/* fallthrough */
531551
 	case OUT_EXPORT:
531551
-		scols_table_enable_export(tb, 1);
531551
+		scols_table_enable_export(table, 1);
531551
 		break;
531551
 	case OUT_NUL:
531551
-		scols_table_set_line_separator(tb, "\0");
531551
+		scols_table_set_line_separator(table, "\0");
531551
 		/* fallthrough */
531551
 	case OUT_RAW:
531551
-		scols_table_enable_raw(tb, 1);
531551
+		scols_table_enable_raw(table, 1);
531551
 		break;
531551
 	case OUT_PRETTY:
531551
-		scols_table_enable_noheadings(tb, 1);
531551
+		scols_table_enable_noheadings(table, 1);
531551
 	default:
531551
 		break;
531551
 	}
531551
@@ -924,7 +934,7 @@ static struct libscols_table *setup_tabl
531551
 		if (ctl->notrunc)
531551
 			flags &= ~SCOLS_FL_TRUNC;
531551
 
531551
-		if (!scols_table_new_column(tb,
531551
+		if (!scols_table_new_column(table,
531551
 				coldescs[columns[n]].name,
531551
 				coldescs[columns[n]].whint,
531551
 				flags))
531551
@@ -932,9 +942,9 @@ static struct libscols_table *setup_tabl
531551
 		++n;
531551
 	}
531551
 
531551
-	return tb;
531551
+	return table;
531551
 fail:
531551
-	scols_unref_table(tb);
531551
+	scols_unref_table(table);
531551
 	return NULL;
531551
 }
531551
 
531551
@@ -1050,10 +1060,10 @@ static void fill_table(const void *u, co
531551
 	return;
531551
 }
531551
 #ifdef HAVE_LIBSYSTEMD
531551
-static void print_journal_tail(const char *journal_path, uid_t uid, size_t len)
531551
+static void print_journal_tail(const char *journal_path, uid_t uid, size_t len, int time_mode)
531551
 {
531551
 	sd_journal *j;
531551
-	char *match, *buf;
531551
+	char *match, *timestamp;
531551
 	uint64_t x;
531551
 	time_t t;
531551
 	const char *identifier, *pid, *message;
531551
@@ -1064,7 +1074,6 @@ static void print_journal_tail(const cha
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
@@ -1074,37 +1083,35 @@ static void print_journal_tail(const cha
531551
 	do {
531551
 		if (0 > sd_journal_get_data(j, "SYSLOG_IDENTIFIER",
531551
 				(const void **) &identifier, &identifier_len))
531551
-			return;
531551
+			goto done;
531551
 		if (0 > sd_journal_get_data(j, "_PID",
531551
 				(const void **) &pid, &pid_len))
531551
-			return;
531551
+			goto done;
531551
 		if (0 > sd_journal_get_data(j, "MESSAGE",
531551
 				(const void **) &message, &message_len))
531551
-			return;
531551
+			goto done;
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
+		timestamp = make_time(time_mode, t);
531551
+		/* Get rid of journal entry field identifiers */
531551
 		identifier = strchr(identifier, '=') + 1;
531551
-		pid = strchr(pid, '=') + 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
+		fprintf(stdout, "%s %s[%s]: %s\n", timestamp, identifier, pid,
531551
+			message);
531551
+		free(timestamp);
531551
 	} while (sd_journal_next(j));
531551
 
531551
-	free(buf);
531551
+done:
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
+static int print_pretty(struct libscols_table *table)
531551
 {
531551
 	struct libscols_iter *itr = scols_new_iter(SCOLS_ITER_FORWARD);
531551
 	struct libscols_column *col;
531551
@@ -1113,8 +1120,8 @@ static int print_pretty(struct libscols_
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
+	ln = scols_table_get_line(table, 0);
531551
+	while (!scols_table_next_column(table, itr, &col)) {
531551
 
531551
 		data = scols_line_get_cell(ln, n);
531551
 
531551
@@ -1142,7 +1149,7 @@ static int print_user_table(struct lslog
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
+		print_journal_tail(ctl->journal_path, ctl->uid, 3, ctl->time_mode);
531551
 		fputc('\n', stdout);
531551
 #endif
531551
 	} else
531551
@@ -1175,16 +1182,25 @@ static void free_user(void *f)
531551
 	free(u);
531551
 }
531551
 
531551
-struct lslogins_timefmt {
531551
-	const char *name;
531551
-	int val;
531551
-};
531551
+static int parse_time_mode(const char *optarg)
531551
+{
531551
+	struct lslogins_timefmt {
531551
+		const char *name;
531551
+		const int val;
531551
+	};
531551
+	static const struct lslogins_timefmt timefmts[] = {
531551
+		{"iso", TIME_ISO},
531551
+		{"full", TIME_FULL},
531551
+		{"short", TIME_SHORT},
531551
+	};
531551
+	size_t i;
531551
 
531551
-static struct lslogins_timefmt timefmts[] = {
531551
-	{ "short", TIME_SHORT },
531551
-	{ "full", TIME_FULL },
531551
-	{ "iso", TIME_ISO },
531551
-};
531551
+	for (i = 0; i < ARRAY_SIZE(timefmts); i++) {
531551
+		if (strcmp(timefmts[i].name, optarg) == 0)
531551
+			return timefmts[i].val;
531551
+	}
531551
+	errx(EXIT_FAILURE, _("unknown time format: %s"), optarg);
531551
+}
531551
 
531551
 static void __attribute__((__noreturn__)) usage(FILE *out)
531551
 {
531551
@@ -1193,16 +1209,18 @@ static void __attribute__((__noreturn__)
531551
 	fputs(USAGE_HEADER, out);
531551
 	fprintf(out, _(" %s [options]\n"), program_invocation_short_name);
531551
 
531551
+	fputs(USAGE_SEPARATOR, out);
531551
+	fputs(_("Display information about known users in the system.\n"), out);
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, --supp-groups        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
@@ -1226,7 +1244,7 @@ static void __attribute__((__noreturn__)
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
+	fprintf(out, USAGE_MAN_TAIL("lslogins(1)"));
531551
 
531551
 	exit(out == stderr ? EXIT_FAILURE : EXIT_SUCCESS);
531551
 }
531551
@@ -1241,8 +1259,7 @@ int main(int argc, char *argv[])
531551
 
531551
 	/* long only options. */
531551
 	enum {
531551
-		OPT_VER = CHAR_MAX + 1,
531551
-		OPT_WTMP,
531551
+		OPT_WTMP = CHAR_MAX + 1,
531551
 		OPT_BTMP,
531551
 		OPT_NOTRUNC,
531551
 		OPT_NOHEAD,
531551
@@ -1300,7 +1317,7 @@ int main(int argc, char *argv[])
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
+	while ((c = getopt_long(argc, argv, "acefGg:hLl:no:prsuVzZ",
531551
 				longopts, NULL)) != -1) {
531551
 
531551
 		err_exclusive_options(c, longopts, excl, excl_st);
531551
@@ -1394,18 +1411,7 @@ int main(int argc, char *argv[])
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
+			ctl->time_mode = parse_time_mode(optarg);
531551
 			break;
531551
 		case 'V':
531551
 			printf(UTIL_LINUX_VERSION);
531551
@@ -1433,7 +1439,7 @@ int main(int argc, char *argv[])
531551
 		logins = argv[optind];
531551
 		outmode = OUT_PRETTY;
531551
 	} else if (argc != optind)
531551
-		usage(stderr);
531551
+		errx(EXIT_FAILURE, _("Only one user may be specified. Use -l for multiple users."));
531551
 
531551
 	scols_init_debug(0);
531551