diff options
-rw-r--r-- | coreutils/id.c | 37 | ||||
-rw-r--r-- | include/usage.h | 4 |
2 files changed, 21 insertions, 20 deletions
diff --git a/coreutils/id.c b/coreutils/id.c index b2f3b20e1..cf642c209 100644 --- a/coreutils/id.c +++ b/coreutils/id.c | |||
@@ -45,7 +45,7 @@ int id_main(int argc UNUSED_PARAM, char **argv) | |||
45 | uid_t uid; | 45 | uid_t uid; |
46 | gid_t gid; | 46 | gid_t gid; |
47 | gid_t *groups; | 47 | gid_t *groups; |
48 | int grp; | 48 | int n; |
49 | unsigned long flags; | 49 | unsigned long flags; |
50 | short status; | 50 | short status; |
51 | #if ENABLE_SELINUX | 51 | #if ENABLE_SELINUX |
@@ -72,17 +72,17 @@ int id_main(int argc UNUSED_PARAM, char **argv) | |||
72 | /* in this case PRINT_REAL is the same */ | 72 | /* in this case PRINT_REAL is the same */ |
73 | } | 73 | } |
74 | 74 | ||
75 | grp = getgroups(0, 0); | 75 | n = getgroups(0, NULL); |
76 | groups = (gid_t *)xmalloc(sizeof(gid_t) * grp); | 76 | groups = xmalloc(sizeof(groups[0]) * n); |
77 | getgroups(grp, (gid_t *)groups); | 77 | getgroups(n, groups); |
78 | 78 | ||
79 | if (flags & (JUST_ALL_GROUPS)) { | 79 | if (flags & JUST_ALL_GROUPS) { |
80 | while (grp--) { | 80 | while (n--) { |
81 | if (flags & NAME_NOT_NUMBER) | 81 | if (flags & NAME_NOT_NUMBER) |
82 | printf("%s", bb_getgrgid(NULL, 0, *groups++)); | 82 | printf("%s", bb_getgrgid(NULL, 0, *groups++)); |
83 | else | 83 | else |
84 | printf("%d", *groups++); | 84 | printf("%d", (int) *groups++); |
85 | bb_putchar((grp > 0) ? ' ' : '\n'); | 85 | bb_putchar((n > 0) ? ' ' : '\n'); |
86 | } | 86 | } |
87 | /* exit */ | 87 | /* exit */ |
88 | fflush_stdout_and_exit(EXIT_SUCCESS); | 88 | fflush_stdout_and_exit(EXIT_SUCCESS); |
@@ -105,7 +105,7 @@ int id_main(int argc UNUSED_PARAM, char **argv) | |||
105 | #if ENABLE_SELINUX | 105 | #if ENABLE_SELINUX |
106 | if (flags & JUST_CONTEXT) { | 106 | if (flags & JUST_CONTEXT) { |
107 | selinux_or_die(); | 107 | selinux_or_die(); |
108 | if (argc - optind == 1) { | 108 | if (argv[optind]) { |
109 | bb_error_msg_and_die("user name can't be passed with -Z"); | 109 | bb_error_msg_and_die("user name can't be passed with -Z"); |
110 | } | 110 | } |
111 | 111 | ||
@@ -122,16 +122,17 @@ int id_main(int argc UNUSED_PARAM, char **argv) | |||
122 | /* Print full info like GNU id */ | 122 | /* Print full info like GNU id */ |
123 | /* bb_getpwuid(0) doesn't exit on failure (returns NULL) */ | 123 | /* bb_getpwuid(0) doesn't exit on failure (returns NULL) */ |
124 | status = printf_full(uid, bb_getpwuid(NULL, 0, uid), "uid="); | 124 | status = printf_full(uid, bb_getpwuid(NULL, 0, uid), "uid="); |
125 | bb_putchar(' '); | 125 | status |= printf_full(gid, bb_getgrgid(NULL, 0, gid), " gid="); |
126 | status |= printf_full(gid, bb_getgrgid(NULL, 0, gid), "gid="); | 126 | { |
127 | printf(" groups="); | 127 | const char *msg = " groups="; |
128 | while (grp--) { | 128 | while (n--) { |
129 | status |= printf_full(*groups, bb_getgrgid(NULL, 0, *groups), ""); | 129 | status |= printf_full(*groups, bb_getgrgid(NULL, 0, *groups), msg); |
130 | if (grp > 0) | 130 | msg = ","; |
131 | bb_putchar(','); | 131 | groups++; |
132 | groups++; | 132 | } |
133 | } | 133 | } |
134 | /* Don't free groups */ | 134 | /* we leak groups vector... */ |
135 | |||
135 | #if ENABLE_SELINUX | 136 | #if ENABLE_SELINUX |
136 | if (is_selinux_enabled()) { | 137 | if (is_selinux_enabled()) { |
137 | security_context_t mysid; | 138 | security_context_t mysid; |
diff --git a/include/usage.h b/include/usage.h index 951be53de..f4fc2e67a 100644 --- a/include/usage.h +++ b/include/usage.h | |||
@@ -1602,9 +1602,9 @@ | |||
1602 | USE_SELINUX( \ | 1602 | USE_SELINUX( \ |
1603 | "\n -Z Print the security context" \ | 1603 | "\n -Z Print the security context" \ |
1604 | ) \ | 1604 | ) \ |
1605 | "\n -G Print all group IDs" \ | ||
1606 | "\n -g Print group ID" \ | ||
1607 | "\n -u Print user ID" \ | 1605 | "\n -u Print user ID" \ |
1606 | "\n -g Print group ID" \ | ||
1607 | "\n -G Print supplementary group IDs" \ | ||
1608 | "\n -n Print name instead of a number" \ | 1608 | "\n -n Print name instead of a number" \ |
1609 | "\n -r Print real user ID instead of effective ID" \ | 1609 | "\n -r Print real user ID instead of effective ID" \ |
1610 | 1610 | ||