setresgid and setresuid not portable

Bug #999713 reported by reed
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
Light Display Manager
Fix Released
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

Revision history for this message
reed (reed-reedmedia) wrote :

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

Matt Fischer (mfisch)
Changed in lightdm:
status: New → In Progress
assignee: nobody → Matt Fischer (mfisch)
Revision history for this message
Matt Fischer (mfisch) wrote :

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

Revision history for this message
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  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.