Hi Samuel,
Sep 12, 2026, 10:07 by [email protected]:
>
> That case would have to be handled specially by the software in charge
> of the login process, indeed. But at least that's not many different
> software to fix :)
>
The attached patch fixes login(1) for me by explicitly adding the pw_gid first
and then merging the other groups (the merging makes sure that it is not added
twice)
It seems a bit weird having to add the pw_gid to the list only to special case
it anyway,
> If it's not there yet, yes, e.g. running this as root:
>
> #define _GNU_SOURCE
> #include <grp.h>
> #include <stdio.h>
> #include <unistd.h>
>
> int
> main()
> {
> setegid(1);
> gid_t foo[3] = {2,3};
> setgroups(2, foo);
> printf("%d\n", getegid());
> int n = getgroups(3, foo);
> printf("%d\n", n);
> for (int i = 0; i < n; i++)
> printf(" %d", foo[i]);
> printf("\n");
> }
>
> currently prints
>
> 2
> 2
> 2 3
>
> while it should really print either
>
> 1
> 2
> 2 3
>
> or
>
> 1
> 3
> 1 2 3
>
> It's the former on Linux but it's fine to have the latter on the Hurd.
>
> Samuel
>
I tried adding the egid in the setgroups copy of the egids which seems to work
but I am not sure about a few things.
Would it need to deduplicate the list again?
what if geteuid fails?
Does that need to be in libc or should/can auth make sure that the hurd
conventions are upheld?
Y.
>From 07ceeaf8245d678e65acde21ef2c15227709da91 Mon Sep 17 00:00:00 2001
From: Yelninei <[email protected]>
Date: Sat, 12 Sep 2026 14:30:03 +0000
Subject: [PATCH] merge_implied_gids: Merge pw_gid before supplementary groups.
Do not rely on getgrouplist returning the pw_gid as the first
element.
---
libshouldbeinlibc/idvec-impgids.c | 10 +++++++---
1 file changed, 7 insertions(+), 3 deletions(-)
diff --git a/libshouldbeinlibc/idvec-impgids.c b/libshouldbeinlibc/idvec-impgids.c
index c5800b6a..3a3e8c31 100644
--- a/libshouldbeinlibc/idvec-impgids.c
+++ b/libshouldbeinlibc/idvec-impgids.c
@@ -74,9 +74,13 @@ _merge_implied_gids (struct idvec *implied_gids, uid_t uid)
if (! err)
{
- err = idvec_merge_ids (cache, gids, ngids);
- if (gids != _gids)
- free (gids);
+ err = idvec_add_new (cache, pw->pw_gid);
+ if (!err)
+ {
+ err = idvec_merge_ids (cache, gids, ngids);
+ if (gids != _gids)
+ free (gids);
+ }
}
if (! err)
--
2.54.0