#define UL_UID_MIN 1000
#define UL_UID_MAX 60000
-#define UL_SYS_UID_MIN 201
+#define UL_SYS_UID_MIN 101
#define UL_SYS_UID_MAX 999
/* we use the value of outmode to determine
const char *journal_path;
unsigned int selinux_enabled : 1,
+ fail_on_unknown : 1, /* fail if user does not exist */
ulist_on : 1,
noheadings : 1,
notrunc : 1;
}
p++;
- if (!*p || *p != '$')
+ if (*p != '$')
return NULL;
if (next)
*next = ++p;
#define is_valid_pwd_char(x) (isalnum((unsigned char) (x)) || (x) == '.' || (x) == '/')
+/*
+ * This function do not accept empty passwords or locked accouns.
+ */
static int valid_pwd(const char *str)
{
const char *p = str;
unsigned int sz = 0, n;
+ if (!str || !*str)
+ return 0;
+
/* $id$ */
if (get_pwd_method(str, &p, &sz) == NULL)
return 0;
- if (!*p)
+ if (!p || !*p)
return 0;
/* salt$ */
- for (; p && *p; p++) {
+ for (; *p; p++) {
if (*p == '$') {
p++;
break;
return 0;
/* encrypted */
- for (n = 0; p && *p; p++, n++) {
+ for (n = 0; *p; p++, n++) {
if (!is_valid_pwd_char(*p))
return 0;
}
uid_t uid;
errno = 0;
+ errno = 0;
pwd = username ? getpwnam(username) : getpwent();
if (!pwd)
return NULL;
return NULL;
}
+ errno = 0;
grp = getgrgid(pwd->pw_gid);
if (!grp)
return NULL;
static int cmp_uid(const void *a, const void *b)
{
- uid_t x = ((struct lslogins_user *)a)->uid;
- uid_t z = ((struct lslogins_user *)b)->uid;
+ uid_t x = ((const struct lslogins_user *)a)->uid;
+ uid_t z = ((const struct lslogins_user *)b)->uid;
return x > z ? 1 : (x < z ? -1 : 0);
}
if (ctl->ulist_on) {
for (n = 0; n < ctl->ulsiz; n++) {
- if (get_user(ctl, &user, ctl->ulist[n]))
+ int rc = get_user(ctl, &user, ctl->ulist[n]);
+
+ if (ctl->fail_on_unknown && !user) {
+ warnx(_("cannot found '%s'"), ctl->ulist[n]);
+ return -1;
+ }
+ if (rc || !user)
continue;
- if (user) /* otherwise an invalid user name has probably been given */
- tsearch(user, &ctl->usertree, cmp_uid);
+
+ tsearch(user, &ctl->usertree, cmp_uid);
}
} else {
while ((user = get_next_user(ctl)))
static void fill_table(const void *u, const VISIT which, const int depth __attribute__((unused)))
{
struct libscols_line *ln;
- struct lslogins_user *user = *(struct lslogins_user **)u;
+ const struct lslogins_user *user = *(struct lslogins_user * const *)u;
size_t n = 0;
if (which == preorder || which == endorder)
size_t i;
fputs(USAGE_HEADER, out);
- fprintf(out, _(" %s [options]\n"), program_invocation_short_name);
+ fprintf(out, _(" %s [options] [<username>]\n"), program_invocation_short_name);
fputs(USAGE_SEPARATOR, out);
fputs(_("Display information about known users in the system.\n"), out);
setlocale(LC_ALL, "");
bindtextdomain(PACKAGE, LOCALEDIR);
textdomain(PACKAGE);
- atexit(close_stdout);
+ close_stdout_atexit();
ctl->time_mode = TIME_SHORT;
ctl->time_mode = parse_time_mode(optarg);
break;
case 'V':
- printf(UTIL_LINUX_VERSION);
- return EXIT_SUCCESS;
+ print_version(EXIT_SUCCESS);
case 'Z':
{
#ifdef HAVE_LIBSELINUX
errx(EXIT_FAILURE, _("Only one user may be specified. Use -l for multiple users."));
logins = argv[optind];
outmode = OUT_PRETTY;
+ ctl->fail_on_unknown = 1;
} else if (argc != optind)
errx(EXIT_FAILURE, _("Only one user may be specified. Use -l for multiple users."));
columns[ncolumns++] = i;
} else if (ncolumns == 2) {
- /* default colummns */
+ /* default columns */
add_column(columns, ncolumns++, COL_NPROCS);
add_column(columns, ncolumns++, COL_PWDLOCK);
add_column(columns, ncolumns++, COL_PWDDENY);