setresgid and setresuid not portable

Reported by reed on 2012-05-15
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
Light Display Manager
Undecided
Matt Fischer

Bug Description

I saw this thread
http://lists.freedesktop.org/archives/lightdm/2011-November/000188.html

I have same problem but on NetBSD.

Here is a patch, but untested:

--- src/privileges.c.orig 2012-04-18 18:29:23.000000000 -0500
+++ src/privileges.c 2012-05-14 19:33:25.000000000 -0500
@@ -20,14 +20,34 @@
     g_return_if_fail (user != NULL);

     g_debug ("Dropping privileges to uid %i", user_get_uid (user));
+#ifdef HAVE_SETRESGID
     g_assert (setresgid (user_get_gid (user), user_get_gid (user), -1) == 0);
+#else
+ g_assert (setgid (user_get_gid (user)) == 0);
+ g_assert (setegid (user_get_gid (user)) == 0);
+#endif
+#ifdef HAVE_SETRESUID
     g_assert (setresuid (user_get_uid (user), user_get_uid (user), -1) == 0);
+#else
+ g_assert (setuid (user_get_uid (user)) == 0);
+ g_assert (seteuid (user_get_uid (user)) == 0);
+#endif
 }

 void
 privileges_reclaim (void)
 {
     g_debug ("Restoring privileges");
+#ifdef HAVE_SETRESUID
     g_assert (setresuid (0, 0, -1) == 0);
+#else
+ g_assert (setuid (0) == 0);
+ g_assert (seteuid (0) == 0);
+#endif
+#ifdef HAVE_SETRESGID
     g_assert (setresgid (0, 0, -1) == 0);
+#else
+ g_assert (setgid (0) == 0);
+ g_assert (setegid (0) == 0);
+#endif
 }

Related branches

reed (reed-reedmedia) wrote :

The configure.ac / config.h.in would need to be setup to check for these two also.

Matt Fischer (mfisch) on 2012-06-06
Changed in lightdm:
status: New → In Progress
assignee: nobody → Matt Fischer (mfisch)
Matt Fischer (mfisch) wrote :

The patch looks good and works fine here. I will push it up for review.

Robert Ancell (robert-ancell) wrote :

Fixed in 1.3.1

Changed in lightdm:
status: In Progress → Fix Released
To post a comment you must log in.
This report contains Public information  Edit
Everyone can see this information.

Other bug subscribers