* Copyright (C) 2000 by Randolph Chung <tausq@debian.org>
* Copyright (C) 2008 by Tito Ragusa <farmatito@tiscali.it>
*
- * Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
+ * Licensed under GPLv2 or later, see file LICENSE in this source tree.
*/
/* BB_AUDIT SUSv3 compliant. */
#include "libbb.h"
+#if !ENABLE_USE_BB_PWD_GRP
+#if defined(__UCLIBC_MAJOR__) && (__UCLIBC_MAJOR__ == 0)
+#if (__UCLIBC_MINOR__ < 9) || (__UCLIBC_MINOR__ == 9 && __UCLIBC_SUBLEVEL__ < 30)
+#error "Sorry, you need at least uClibc version 0.9.30 for id applet to build"
+#endif
+#endif
+#endif
+
enum {
PRINT_REAL = (1 << 0),
NAME_NOT_NUMBER = (1 << 1),
#endif
};
-static int print_common(unsigned id,
- char* FAST_FUNC bb_getXXXid(char *name, int bufsize, long uid),
- const char *prefix)
+static int print_common(unsigned id, const char *name, const char *prefix)
{
- const char *name = bb_getXXXid(NULL, 0, id);
-
if (prefix) {
printf("%s", prefix);
}
static int print_group(gid_t id, const char *prefix)
{
- return print_common(id, bb_getgrgid, prefix);
+ return print_common(id, gid2group(id), prefix);
}
-static int print_user(gid_t id, const char *prefix)
+static int print_user(uid_t id, const char *prefix)
{
- return print_common(id, bb_getpwuid, prefix);
+ return print_common(id, uid2uname(id), prefix);
}
/* On error set *n < 0 and return >= 0
/* Don't allow -n -r -nr -ug -rug -nug -rnug -uZ -gZ -GZ*/
/* Don't allow more than one username */
opt_complementary = "?1:u--g:g--u:G--u:u--G:g--G:G--g:r?ugG:n?ugG"
- USE_SELINUX(":u--Z:Z--u:g--Z:Z--g:G--Z:Z--G");
- opt = getopt32(argv, "rnugG" USE_SELINUX("Z"));
+ IF_SELINUX(":u--Z:Z--u:g--Z:Z--g:G--Z:Z--G");
+ opt = getopt32(argv, "rnugG" IF_SELINUX("Z"));
username = argv[optind];
if (username) {
- struct passwd *p = getpwnam(username);
- if (!p)
- bb_error_msg_and_die("unknown user %s", username);
+ struct passwd *p = xgetpwnam(username);
euid = ruid = p->pw_uid;
egid = rgid = p->pw_gid;
} else {
}
/* JUST_ALL_GROUPS ignores -r PRINT_REAL flag even if man page for */
/* id says: print the real ID instead of the effective ID, with -ugG */
- /* in fact in ths case egid is always printed if egid != rgid */
+ /* in fact in this case egid is always printed if egid != rgid */
if (!opt || (opt & JUST_ALL_GROUPS)) {
gid_t *groups;
int n;
}
} else if (n < 0) { /* error in get_groups() */
if (!ENABLE_DESKTOP)
- bb_error_msg_and_die("cannot get groups");
+ bb_error_msg_and_die("can't get groups");
else
return EXIT_FAILURE;
}