aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--coreutils/id.c20
-rw-r--r--libbb/bb_getgroups.c2
-rw-r--r--win32/mingw.c2
3 files changed, 23 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
146int id_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; 148int id_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
147int id_main(int argc UNUSED_PARAM, char **argv) 149int 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()) {
diff --git a/libbb/bb_getgroups.c b/libbb/bb_getgroups.c
index c255d4e4c..757b80be8 100644
--- a/libbb/bb_getgroups.c
+++ b/libbb/bb_getgroups.c
@@ -10,6 +10,7 @@
10 10
11#include "libbb.h" 11#include "libbb.h"
12 12
13#if !ENABLE_PLATFORM_MINGW32
13gid_t* FAST_FUNC bb_getgroups(int *ngroups, gid_t *group_array) 14gid_t* FAST_FUNC bb_getgroups(int *ngroups, gid_t *group_array)
14{ 15{
15 int n = ngroups ? *ngroups : 0; 16 int n = ngroups ? *ngroups : 0;
@@ -45,6 +46,7 @@ gid_t* FAST_FUNC bb_getgroups(int *ngroups, gid_t *group_array)
45 *ngroups = n; 46 *ngroups = n;
46 return group_array; 47 return group_array;
47} 48}
49#endif
48 50
49uid_t FAST_FUNC get_cached_euid(uid_t *euid) 51uid_t FAST_FUNC get_cached_euid(uid_t *euid)
50{ 52{
diff --git a/win32/mingw.c b/win32/mingw.c
index c14ad1f1f..d323014b7 100644
--- a/win32/mingw.c
+++ b/win32/mingw.c
@@ -1273,6 +1273,7 @@ struct group *getgrgid(gid_t gid)
1273 return &g; 1273 return &g;
1274} 1274}
1275 1275
1276#if 0
1276int getgrouplist(const char *user UNUSED_PARAM, gid_t group, 1277int getgrouplist(const char *user UNUSED_PARAM, gid_t group,
1277 gid_t *groups, int *ngroups) 1278 gid_t *groups, int *ngroups)
1278{ 1279{
@@ -1295,6 +1296,7 @@ int getgroups(int n, gid_t *groups)
1295 groups[0] = getgid(); 1296 groups[0] = getgid();
1296 return 1; 1297 return 1;
1297} 1298}
1299#endif
1298 1300
1299int getlogin_r(char *buf, size_t len) 1301int getlogin_r(char *buf, size_t len)
1300{ 1302{