#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;
#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;
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)))
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);