Do not attempt to use dbus while setid
authorKevin Wasserman <kevin.wasserman@painless-security.com>
Wed, 23 Oct 2013 17:55:29 +0000 (13:55 -0400)
committerKevin Wasserman <kevin.wasserman@painless-security.com>
Wed, 23 Oct 2013 17:55:29 +0000 (13:55 -0400)
configure.ac
libmoonshot/libmoonshot-dbus.c

index 5d3f7e1..51863c9 100644 (file)
@@ -19,6 +19,7 @@ AM_MAINTAINER_MODE([enable])
 
 LT_PREREQ([2.2])
 LT_INIT([win32-dll])
+AC_CHECK_FUNCS_ONCE(geteuid)
 
 # Checks for programs.
 PKG_PROG_PKG_CONFIG([0.23])
index 97dba1e..df1d46e 100644 (file)
@@ -111,6 +111,16 @@ static DBusGConnection *dbus_launch_moonshot()
        return connection;
 }
 
+static int is_setid()
+{
+#ifdef HAVE_GETEUID
+  if ((getuid() != geteuid()) || 
+      (getgid() != getegid())) {
+    return 1;
+  }
+#endif
+  return 0;
+}
 
 static DBusGProxy *dbus_connect (MoonshotError **error)
 {
@@ -130,6 +140,12 @@ static DBusGProxy *dbus_connect (MoonshotError **error)
      * If/when we move to GDBus this code can become a one-liner.
      */
 
+    if (is_setid()) {
+        *error = moonshot_error_new (MOONSHOT_ERROR_IPC_ERROR,
+                                    "Cannot use IPC while setid");
+        return NULL;
+    }
+
     connection = dbus_g_bus_get (DBUS_BUS_SESSION, &g_error);
 
     if (g_error_matches(g_error, DBUS_GERROR, DBUS_GERROR_NOT_SUPPORTED)) {