From 89229c2b0b139c527e98fc3bf1a829bc2b68394e Mon Sep 17 00:00:00 2001
From: Tomas Bzatek <tbzatek@redhat.com>
Date: Wed, 15 Jan 2014 16:16:34 +0000
Subject: Use reentrant version of getpwuid() for thread safety
...and get rid of static variables.
https://bugs.freedesktop.org/show_bug.cgi?id=73669
Signed-off-by: David Zeuthen <zeuthen@gmail.com>
---
diff --git a/src/udisksdaemonutil.c b/src/udisksdaemonutil.c
index 574bf2c..b3a3acb 100644
--- a/src/udisksdaemonutil.c
+++ b/src/udisksdaemonutil.c
@@ -830,7 +830,7 @@ udisks_daemon_util_get_caller_uid_sync (UDisksDaemon *daemon,
{
struct passwd pwstruct;
gchar pwbuf[8192];
- static struct passwd *pw;
+ struct passwd *pw = NULL;
int rc;
rc = getpwuid_r (uid, &pwstruct, pwbuf, sizeof pwbuf, &pw);
diff --git a/src/udiskslinuxfilesystem.c b/src/udiskslinuxfilesystem.c
index 4c8d8aa..f243046 100644
--- a/src/udiskslinuxfilesystem.c
+++ b/src/udiskslinuxfilesystem.c
@@ -348,13 +348,16 @@ find_mount_options_for_fs (const gchar *fstype)
static gid_t
find_primary_gid (uid_t uid)
{
- struct passwd *pw;
+ struct passwd *pw = NULL;
+ struct passwd pwstruct;
+ gchar pwbuf[8192];
+ int rc;
gid_t gid;
gid = (gid_t) - 1;
- pw = getpwuid (uid);
- if (pw == NULL)
+ rc = getpwuid_r (uid, &pwstruct, pwbuf, sizeof pwbuf, &pw);
+ if (rc != 0 || pw == NULL)
{
udisks_warning ("Error looking up uid %d: %m", uid);
goto out;
@@ -370,7 +373,10 @@ is_uid_in_gid (uid_t uid,
gid_t gid)
{
gboolean ret;
- struct passwd *pw;
+ struct passwd *pw = NULL;
+ struct passwd pwstruct;
+ gchar pwbuf[8192];
+ int rc;
static gid_t supplementary_groups[128];
int num_supplementary_groups = 128;
int n;
@@ -379,8 +385,8 @@ is_uid_in_gid (uid_t uid,
ret = FALSE;
- pw = getpwuid (uid);
- if (pw == NULL)
+ rc = getpwuid_r (uid, &pwstruct, pwbuf, sizeof pwbuf, &pw);
+ if (rc != 0 || pw == NULL)
{
udisks_warning ("Error looking up uid %d: %m", uid);
goto out;
diff --git a/src/udisksspawnedjob.c b/src/udisksspawnedjob.c
index 802551f..b181933 100644
--- a/src/udisksspawnedjob.c
+++ b/src/udisksspawnedjob.c
@@ -371,22 +371,25 @@ static void
child_setup (gpointer user_data)
{
UDisksSpawnedJob *job = UDISKS_SPAWNED_JOB (user_data);
- struct passwd *pw;
+ struct passwd pwstruct;
+ gchar pwbuf[8192];
+ struct passwd *pw = NULL;
+ int rc;
gid_t egid;
if (job->run_as_uid == getuid () && job->run_as_euid == geteuid ())
goto out;
- pw = getpwuid (job->run_as_euid);
- if (pw == NULL)
+ rc = getpwuid_r (job->run_as_euid, &pwstruct, pwbuf, sizeof pwbuf, &pw);
+ if (rc != 0 || pw == NULL)
{
g_printerr ("No password record for uid %d: %m\n", (gint) job->run_as_euid);
abort ();
}
egid = pw->pw_gid;
- pw = getpwuid (job->run_as_uid);
- if (pw == NULL)
+ rc = getpwuid_r (job->run_as_uid, &pwstruct, pwbuf, sizeof pwbuf, &pw);
+ if (rc != 0 || pw == NULL)
{
g_printerr ("No password record for uid %d: %m\n", (gint) job->run_as_uid);
abort ();
--
cgit v0.9.0.2-2-gbebe