diff options
Diffstat (limited to 'coreutils/id.c')
-rw-r--r-- | coreutils/id.c | 20 |
1 files changed, 19 insertions, 1 deletions
diff --git a/coreutils/id.c b/coreutils/id.c index a4f178bda..0e1286294 100644 --- a/coreutils/id.c +++ b/coreutils/id.c | |||
@@ -112,6 +112,7 @@ static int print_user(uid_t id, const char *prefix) | |||
112 | return print_common(id, uid2uname(id), prefix); | 112 | return print_common(id, uid2uname(id), prefix); |
113 | } | 113 | } |
114 | 114 | ||
115 | #if !ENABLE_PLATFORM_MINGW32 | ||
115 | /* On error set *n < 0 and return >= 0 | 116 | /* On error set *n < 0 and return >= 0 |
116 | * If *n is too small, update it and return < 0 | 117 | * If *n is too small, update it and return < 0 |
117 | * (ok to trash groups[] in both cases) | 118 | * (ok to trash groups[] in both cases) |
@@ -142,6 +143,7 @@ static int get_groups(const char *username, gid_t rgid, gid_t *groups, int *n) | |||
142 | /* if *n >= 0, return -1 (got new *n), else return 0 (error): */ | 143 | /* if *n >= 0, return -1 (got new *n), else return 0 (error): */ |
143 | return -(*n >= 0); | 144 | return -(*n >= 0); |
144 | } | 145 | } |
146 | #endif | ||
145 | 147 | ||
146 | int id_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; | 148 | int id_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; |
147 | int id_main(int argc UNUSED_PARAM, char **argv) | 149 | int id_main(int argc UNUSED_PARAM, char **argv) |
@@ -184,16 +186,26 @@ int id_main(int argc UNUSED_PARAM, char **argv) | |||
184 | euid = ruid = p->pw_uid; | 186 | euid = ruid = p->pw_uid; |
185 | egid = rgid = p->pw_gid; | 187 | egid = rgid = p->pw_gid; |
186 | } else { | 188 | } else { |
189 | #if ENABLE_PLATFORM_MINGW32 | ||
190 | // We don't distinguish real/effective ids on Windows. | ||
191 | euid = ruid = getuid(); | ||
192 | egid = rgid = getegid(); | ||
193 | #else | ||
187 | egid = getegid(); | 194 | egid = getegid(); |
188 | rgid = getgid(); | 195 | rgid = getgid(); |
189 | euid = geteuid(); | 196 | euid = geteuid(); |
190 | ruid = getuid(); | 197 | ruid = getuid(); |
198 | #endif | ||
191 | } | 199 | } |
192 | /* JUST_ALL_GROUPS ignores -r PRINT_REAL flag even if man page for */ | 200 | /* JUST_ALL_GROUPS ignores -r PRINT_REAL flag even if man page for */ |
193 | /* id says: print the real ID instead of the effective ID, with -ugG */ | 201 | /* id says: print the real ID instead of the effective ID, with -ugG */ |
194 | /* in fact in this case egid is always printed if egid != rgid */ | 202 | /* in fact in this case egid is always printed if egid != rgid */ |
195 | if (!opt || (opt & JUST_ALL_GROUPS)) { | 203 | if (!opt || (opt & JUST_ALL_GROUPS)) { |
204 | #if ENABLE_PLATFORM_MINGW32 | ||
205 | gid_t groups[1]; | ||
206 | #else | ||
196 | gid_t *groups; | 207 | gid_t *groups; |
208 | #endif | ||
197 | int n; | 209 | int n; |
198 | 210 | ||
199 | if (!opt) { | 211 | if (!opt) { |
@@ -210,6 +222,11 @@ int id_main(int argc UNUSED_PARAM, char **argv) | |||
210 | if (egid != rgid) | 222 | if (egid != rgid) |
211 | status |= print_group(egid, " "); | 223 | status |= print_group(egid, " "); |
212 | } | 224 | } |
225 | #if ENABLE_PLATFORM_MINGW32 | ||
226 | // We only admit to having one group id on Windows. | ||
227 | n = 1; | ||
228 | groups[0] = rgid; | ||
229 | #else | ||
213 | /* We are supplying largish buffer, trying | 230 | /* We are supplying largish buffer, trying |
214 | * to not run get_groups() twice. That might be slow | 231 | * to not run get_groups() twice. That might be slow |
215 | * ("user database in remote SQL server" case) */ | 232 | * ("user database in remote SQL server" case) */ |
@@ -220,6 +237,7 @@ int id_main(int argc UNUSED_PARAM, char **argv) | |||
220 | groups = xrealloc(groups, n * sizeof(groups[0])); | 237 | groups = xrealloc(groups, n * sizeof(groups[0])); |
221 | get_groups(username, rgid, groups, &n); | 238 | get_groups(username, rgid, groups, &n); |
222 | } | 239 | } |
240 | #endif | ||
223 | if (n > 0) { | 241 | if (n > 0) { |
224 | /* Print the list */ | 242 | /* Print the list */ |
225 | prefix = " groups="; | 243 | prefix = " groups="; |
@@ -234,7 +252,7 @@ int id_main(int argc UNUSED_PARAM, char **argv) | |||
234 | bb_simple_error_msg_and_die("can't get groups"); | 252 | bb_simple_error_msg_and_die("can't get groups"); |
235 | return EXIT_FAILURE; | 253 | return EXIT_FAILURE; |
236 | } | 254 | } |
237 | if (ENABLE_FEATURE_CLEAN_UP) | 255 | if (ENABLE_FEATURE_CLEAN_UP && !ENABLE_PLATFORM_MINGW32) |
238 | free(groups); | 256 | free(groups); |
239 | #if ENABLE_SELINUX | 257 | #if ENABLE_SELINUX |
240 | if (is_selinux_enabled()) { | 258 | if (is_selinux_enabled()) { |