id and ls with -Z report the SMACK security context where available.
mkdir, mkfifo and mknod with -Z set the SMACK context where available.
+ id can now lookup by user ID, in addition to the existing name lookup.
+
join accepts a new option: --zero-terminated (-z). As with the sort,uniq
option of the same name, this makes join consume and produce NUL-terminated
lines rather than newline-terminated lines.
running it if no user is specified. Synopsis:
@example
-id [@var{option}]@dots{} [@var{username}]
+id [@var{option}]@dots{} [@var{user}]
@end example
+@var{user} can be either a user ID or a name, with name lookup
+taking precedence unless the ID is specified with a leading @samp{+}.
+
@vindex POSIXLY_CORRECT
By default, it prints the real user ID, real group ID, effective user ID
if different from the real user ID, effective group ID if different from
#include "quote.h"
#include "group-list.h"
#include "smack.h"
+#include "userspec.h"
/* The official name of this program (e.g., no 'g' prefix). */
#define PROGRAM_NAME "id"
emit_try_help ();
else
{
- printf (_("Usage: %s [OPTION]... [USERNAME]\n"), program_name);
+ printf (_("Usage: %s [OPTION]... [USER]\n"), program_name);
fputs (_("\
-Print user and group information for the specified USERNAME,\n\
-or (when USERNAME omitted) for the current user.\n\
+Print user and group information for the specified USER,\n\
+or (when USER omitted) for the current user.\n\
\n"),
stdout);
fputs (_("\
int selinux_enabled = (is_selinux_enabled () > 0);
bool smack_enabled = is_smack_enabled ();
bool opt_zero = false;
+ char *pw_name = NULL;
/* If true, output the list of all group IDs. -G */
bool just_group_list = false;
if (n_ids == 1)
{
- struct passwd *pwd = getpwnam (argv[optind]);
+ struct passwd *pwd = NULL;
+ const char *spec = argv[optind];
+ /* Disallow an empty spec here as parse_user_spec() doesn't
+ give an error for that as it seems it's a valid way to
+ specify a noop or "reset special bits" depending on the system. */
+ if (*spec)
+ {
+ if (parse_user_spec (spec, &euid, NULL, NULL, NULL) == NULL)
+ {
+ /* parse_user_spec will only extract a numeric spec,
+ so we lookup that here to verify and also retrieve
+ the PW_NAME used subsequently in group lookup. */
+ pwd = getpwuid (euid);
+ }
+ }
if (pwd == NULL)
- error (EXIT_FAILURE, 0, _("%s: no such user"), argv[optind]);
+ error (EXIT_FAILURE, 0, _("%s: no such user"), spec);
+ pw_name = xstrdup (pwd->pw_name);
ruid = euid = pwd->pw_uid;
rgid = egid = pwd->pw_gid;
}
}
else if (just_group_list)
{
- if (!print_group_list (argv[optind], ruid, rgid, egid, use_name,
+ if (!print_group_list (pw_name, ruid, rgid, egid, use_name,
opt_zero ? '\0' : ' '))
ok = false;
}
}
else
{
- print_full_info (argv[optind]);
+ print_full_info (pw_name);
}
putchar (opt_zero ? '\0' : '\n');
+ IF_LINT (free (pw_name));
exit (ok ? EXIT_SUCCESS : EXIT_FAILURE);
}
#!/bin/sh
-# Ensure that "id" outputs groups for a user
-# Copyright (C) 2009-2013 Free Software Foundation, Inc.
+# Ensure that "id" works with numeric user ids
+# Copyright (C) 2013 Free Software Foundation, Inc.
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
. "${srcdir=.}/tests/init.sh"; path_prepend_ ./src
print_ver_ id
-id -G $(id -nu) || fail=1
+uid=$(id -u) || fail=1
+user=$(id -nu) || fail=1
+
+# Ensure the empty user spec is discarded
+id '' && fail=1
+
+for mode in '' '-G' '-g'; do
+ id $mode $user > user_out || fail=1 # lookup name for comparison
+
+ id $mode $uid > uid_out || fail=1 # lookup name "$uid" before id "$uid"
+ compare user_out uid_out || fail=1
+
+ id $mode +$uid > uid_out || fail=1 # lookup only id "$uid"
+ compare user_out uid_out || fail=1
+done
Exit $fail