summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJan Rybar <jrybar@redhat.com>2023-10-03 16:30:07 +0000
committerJan Rybar <jrybar@redhat.com>2023-10-03 16:30:07 +0000
commit89b7a37b91210ac054645c617d150a0d4906a84e (patch)
treebd68f6db36295d98482f879261269fa178cac41c
parent67ff238cb30acc55fec853585a18afa7c71880d6 (diff)
user_of_subject is NULL if DBus provides groups
-rw-r--r--src/polkitbackend/polkitbackendduktapeauthority.c21
1 files changed, 12 insertions, 9 deletions
diff --git a/src/polkitbackend/polkitbackendduktapeauthority.c b/src/polkitbackend/polkitbackendduktapeauthority.c
index b5eea39..c40b907 100644
--- a/src/polkitbackend/polkitbackendduktapeauthority.c
+++ b/src/polkitbackend/polkitbackendduktapeauthority.c
@@ -420,6 +420,17 @@ push_subject (duk_context *cx,
groups = g_ptr_array_new_with_free_func (g_free);
gids_from_dbus = polkit_unix_process_get_gids (POLKIT_UNIX_PROCESS (process));
+passwd = getpwuid (uid);
+if (passwd == NULL)
+ {
+ user_name = g_strdup_printf ("%d", (gint) uid);
+ g_warning ("Error looking up info for uid %d: %m", (gint) uid);
+ }
+else
+ {
+ user_name = g_strdup (passwd->pw_name);
+ }
+
/* D-Bus will give us supplementary groups too, so prefer that to looking up
* the group from the uid. */
if (gids_from_dbus && gids_from_dbus->len > 0)
@@ -441,19 +452,11 @@ push_subject (duk_context *cx,
}
else
{
- passwd = getpwuid (uid);
- if (passwd == NULL)
- {
- user_name = g_strdup_printf ("%d", (gint) uid);
- g_warning ("Error looking up info for uid %d: %m", (gint) uid);
- }
- else
+ if (passwd != NULL)
{
gid_t gids[512];
int num_gids = 512;
- user_name = g_strdup (passwd->pw_name);
-
if (getgrouplist (passwd->pw_name,
passwd->pw_gid,
gids,