Ray Strode 81bc98
From 26213aa0e0d8dca5f36cc23f6942525224cbe9f5 Mon Sep 17 00:00:00 2001
Ray Strode 81bc98
From: Ray Strode <rstrode@redhat.com>
Ray Strode 81bc98
Date: Tue, 19 Jun 2012 12:02:24 -0400
Ray Strode 81bc98
Subject: [PATCH 1/3] util: CVE-2012-2737: validate SetIconFile caller over
Ray Strode 81bc98
 bus
Ray Strode 81bc98
Ray Strode 81bc98
The AccountsService SetIconFile call associates an icon
Ray Strode 81bc98
with a user.
Ray Strode 81bc98
Ray Strode 81bc98
SetIconFile allows users to have icons visible at the login
Ray Strode 81bc98
screen that don't necessarily originate in globally
Ray Strode 81bc98
readable or always available locations. This is accomplished
Ray Strode 81bc98
by copying the originating icon to the local disk in /var.
Ray Strode 81bc98
Ray Strode 81bc98
Since AccountsService runs with with root privileges, the
Ray Strode 81bc98
implemention of the SetIconFile method queries the uid of
Ray Strode 81bc98
the method caller, forks, switches to that uid and performs
Ray Strode 81bc98
the image copy as if it were the user.
Ray Strode 81bc98
Ray Strode 81bc98
Unfortunately, the uid lookup peformed is done "just in time"
Ray Strode 81bc98
instead of looking at peer credentials from the time the call
Ray Strode 81bc98
was initiated. There is a race condition that means a caller
Ray Strode 81bc98
could invoke the method call, quickly exec a setuid binary, and
Ray Strode 81bc98
then cause the copy to be performed as the uid of the setuid
Ray Strode 81bc98
process.
Ray Strode 81bc98
Ray Strode 81bc98
This commit changes the uid lookup logic to query the system
Ray Strode 81bc98
bus daemon for the peer credentials that were cached from the
Ray Strode 81bc98
caller at the time of the initial connection.
Ray Strode 81bc98
---
Ray Strode 81bc98
 src/util.c |   37 ++++++++++++++++++++++++++-----------
Ray Strode 81bc98
 1 file changed, 26 insertions(+), 11 deletions(-)
Ray Strode 81bc98
Ray Strode 81bc98
diff --git a/src/util.c b/src/util.c
Ray Strode 81bc98
index 66ddd98..1ce375b 100644
Ray Strode 81bc98
--- a/src/util.c
Ray Strode 81bc98
+++ b/src/util.c
Ray Strode 81bc98
@@ -251,22 +251,37 @@ get_user_groups (const gchar  *user,
Ray Strode 81bc98
Ray Strode 81bc98
Ray Strode 81bc98
 gboolean
Ray Strode 81bc98
-get_caller_uid (GDBusMethodInvocation *context, gint *uid)
Ray Strode 81bc98
+get_caller_uid (GDBusMethodInvocation *context,
Ray Strode 81bc98
+                gint                  *uid)
Ray Strode 81bc98
 {
Ray Strode 81bc98
-        PolkitSubject *subject;
Ray Strode 81bc98
-        PolkitSubject *process;
Ray Strode 81bc98
+        GVariant      *reply;
Ray Strode 81bc98
+        GError        *error;
Ray Strode 81bc98
+
Ray Strode 81bc98
+        error = NULL;
Ray Strode 81bc98
+        reply = g_dbus_connection_call_sync (g_dbus_method_invocation_get_connection (context),
Ray Strode 81bc98
+                                             "org.freedesktop.DBus",
Ray Strode 81bc98
+                                             "/org/freedesktop/DBus",
Ray Strode 81bc98
+                                             "org.freedesktop.DBus",
Ray Strode 81bc98
+                                             "GetConnectionUnixUser",
Ray Strode 81bc98
+                                             g_variant_new ("(s)",
Ray Strode 81bc98
+                                                            g_dbus_method_invocation_get_sender (context)),
Ray Strode 81bc98
+                                             G_VARIANT_TYPE ("(u)"),
Ray Strode 81bc98
+                                             G_DBUS_CALL_FLAGS_NONE,
Ray Strode 81bc98
+                                             -1,
Ray Strode 81bc98
+                                             NULL,
Ray Strode 81bc98
+                                             &error);
Ray Strode 81bc98
+
Ray Strode 81bc98
+        if (reply == NULL) {
Ray Strode 81bc98
+                g_warning ("Could not talk to message bus to find uid of sender %s: %s",
Ray Strode 81bc98
+                           g_dbus_method_invocation_get_sender (context),
Ray Strode 81bc98
+                           error->message);
Ray Strode 81bc98
+                g_error_free (error);
Ray Strode 81bc98
Ray Strode 81bc98
-        subject = polkit_system_bus_name_new (g_dbus_method_invocation_get_sender (context));
Ray Strode 81bc98
-        process = polkit_system_bus_name_get_process_sync (POLKIT_SYSTEM_BUS_NAME (subject), NULL, NULL);
Ray Strode 81bc98
-        if (!process) {
Ray Strode 81bc98
-                g_object_unref (subject);
Ray Strode 81bc98
                 return FALSE;
Ray Strode 81bc98
         }
Ray Strode 81bc98
Ray Strode 81bc98
-        *uid = polkit_unix_process_get_uid (POLKIT_UNIX_PROCESS (process));
Ray Strode 81bc98
-
Ray Strode 81bc98
-        g_object_unref (subject);
Ray Strode 81bc98
-        g_object_unref (process);
Ray Strode 81bc98
+        g_variant_get (reply, "(u)", uid);
Ray Strode 81bc98
+        g_variant_unref (reply);
Ray Strode 81bc98
Ray Strode 81bc98
         return TRUE;
Ray Strode 81bc98
 }
Ray Strode 81bc98
--
Ray Strode 81bc98
1.7.10.2
Ray Strode 81bc98
Ray Strode 81bc98
Ray Strode 81bc98
From bd51aa4cdac380f55d607f4ffdf2ab3c00d08721 Mon Sep 17 00:00:00 2001
Ray Strode 81bc98
From: Ray Strode <rstrode@redhat.com>
Ray Strode 81bc98
Date: Tue, 19 Jun 2012 14:02:42 -0400
Ray Strode 81bc98
Subject: [PATCH 2/3] user: CVE-2012-2737: verify caller through bus in more
Ray Strode 81bc98
 cases
Ray Strode 81bc98
Ray Strode 81bc98
The previous commit changed the SetIconFile call to identify
Ray Strode 81bc98
the uid of the calling process via cached peer credentials
Ray Strode 81bc98
stored by the bus daemon.
Ray Strode 81bc98
Ray Strode 81bc98
This commit fixes other similar cases where we try to figure
Ray Strode 81bc98
out process identity on our own instead of through the bus
Ray Strode 81bc98
daemon.
Ray Strode 81bc98
---
Ray Strode 81bc98
 src/user.c |   78 ++++++++++++++++++++++++++++++++----------------------------
Ray Strode 81bc98
 1 file changed, 42 insertions(+), 36 deletions(-)
Ray Strode 81bc98
Ray Strode 81bc98
diff --git a/src/user.c b/src/user.c
Ray Strode 81bc98
index 55c238d..9713ecd 100644
Ray Strode 81bc98
--- a/src/user.c
Ray Strode 81bc98
+++ b/src/user.c
Ray Strode 81bc98
@@ -552,35 +552,21 @@ user_change_real_name_authorized_cb (Daemon                *daemon,
Ray Strode 81bc98
         accounts_user_complete_set_real_name (ACCOUNTS_USER (user), context);
Ray Strode 81bc98
 }
Ray Strode 81bc98
Ray Strode 81bc98
-static uid_t
Ray Strode 81bc98
-method_invocation_get_uid (GDBusMethodInvocation *context)
Ray Strode 81bc98
-{
Ray Strode 81bc98
-  const gchar *sender;
Ray Strode 81bc98
-  PolkitSubject *busname;
Ray Strode 81bc98
-  PolkitSubject *process;
Ray Strode 81bc98
-  uid_t uid;
Ray Strode 81bc98
-
Ray Strode 81bc98
-  sender = g_dbus_method_invocation_get_sender (context);
Ray Strode 81bc98
-  busname = polkit_system_bus_name_new (sender);
Ray Strode 81bc98
-  process = polkit_system_bus_name_get_process_sync (POLKIT_SYSTEM_BUS_NAME (busname), NULL, NULL);
Ray Strode 81bc98
-  uid = polkit_unix_process_get_uid (POLKIT_UNIX_PROCESS (process));
Ray Strode 81bc98
-  g_object_unref (busname);
Ray Strode 81bc98
-  g_object_unref (process);
Ray Strode 81bc98
-
Ray Strode 81bc98
-  return uid;
Ray Strode 81bc98
-}
Ray Strode 81bc98
-
Ray Strode 81bc98
 static gboolean
Ray Strode 81bc98
 user_set_real_name (AccountsUser          *auser,
Ray Strode 81bc98
                     GDBusMethodInvocation *context,
Ray Strode 81bc98
                     const gchar           *real_name)
Ray Strode 81bc98
 {
Ray Strode 81bc98
         User *user = (User*)auser;
Ray Strode 81bc98
-        uid_t uid;
Ray Strode 81bc98
+        int uid;
Ray Strode 81bc98
         const gchar *action_id;
Ray Strode 81bc98
Ray Strode 81bc98
-        uid = method_invocation_get_uid (context);
Ray Strode 81bc98
-        if (user->uid == uid)
Ray Strode 81bc98
+        if (!get_caller_uid (context, &uid)) {
Ray Strode 81bc98
+                throw_error (context, ERROR_FAILED, "identifying caller failed");
Ray Strode 81bc98
+                return FALSE;
Ray Strode 81bc98
+        }
Ray Strode 81bc98
+
Ray Strode 81bc98
+        if (user->uid == (uid_t) uid)
Ray Strode 81bc98
                 action_id = "org.freedesktop.accounts.change-own-user-data";
Ray Strode 81bc98
         else
Ray Strode 81bc98
                 action_id = "org.freedesktop.accounts.user-administration";
Ray Strode 81bc98
@@ -692,11 +678,15 @@ user_set_email (AccountsUser          *auser,
Ray Strode 81bc98
                 const gchar           *email)
Ray Strode 81bc98
 {
Ray Strode 81bc98
         User *user = (User*)auser;
Ray Strode 81bc98
-        uid_t uid;
Ray Strode 81bc98
+        int uid;
Ray Strode 81bc98
         const gchar *action_id;
Ray Strode 81bc98
Ray Strode 81bc98
-        uid = method_invocation_get_uid (context);
Ray Strode 81bc98
-        if (user->uid == uid)
Ray Strode 81bc98
+        if (!get_caller_uid (context, &uid)) {
Ray Strode 81bc98
+                throw_error (context, ERROR_FAILED, "identifying caller failed");
Ray Strode 81bc98
+                return FALSE;
Ray Strode 81bc98
+        }
Ray Strode 81bc98
+
Ray Strode 81bc98
+        if (user->uid == (uid_t) uid)
Ray Strode 81bc98
                 action_id = "org.freedesktop.accounts.change-own-user-data";
Ray Strode 81bc98
         else
Ray Strode 81bc98
                 action_id = "org.freedesktop.accounts.user-administration";
Ray Strode 81bc98
@@ -744,11 +734,15 @@ user_set_language (AccountsUser          *auser,
Ray Strode 81bc98
                    const gchar           *language)
Ray Strode 81bc98
 {
Ray Strode 81bc98
         User *user = (User*)auser;
Ray Strode 81bc98
-        uid_t uid;
Ray Strode 81bc98
+        int uid;
Ray Strode 81bc98
         const gchar *action_id;
Ray Strode 81bc98
Ray Strode 81bc98
-        uid = method_invocation_get_uid (context);
Ray Strode 81bc98
-        if (user->uid == uid)
Ray Strode 81bc98
+        if (!get_caller_uid (context, &uid)) {
Ray Strode 81bc98
+                throw_error (context, ERROR_FAILED, "identifying caller failed");
Ray Strode 81bc98
+                return FALSE;
Ray Strode 81bc98
+        }
Ray Strode 81bc98
+
Ray Strode 81bc98
+        if (user->uid == (uid_t) uid)
Ray Strode 81bc98
                 action_id = "org.freedesktop.accounts.change-own-user-data";
Ray Strode 81bc98
         else
Ray Strode 81bc98
                 action_id = "org.freedesktop.accounts.user-administration";
Ray Strode 81bc98
@@ -794,11 +788,15 @@ user_set_x_session (AccountsUser          *auser,
Ray Strode 81bc98
                     const gchar           *x_session)
Ray Strode 81bc98
 {
Ray Strode 81bc98
         User *user = (User*)auser;
Ray Strode 81bc98
-        uid_t uid;
Ray Strode 81bc98
+        int uid;
Ray Strode 81bc98
         const gchar *action_id;
Ray Strode 81bc98
Ray Strode 81bc98
-        uid = method_invocation_get_uid (context);
Ray Strode 81bc98
-        if (user->uid == uid)
Ray Strode 81bc98
+        if (!get_caller_uid (context, &uid)) {
Ray Strode 81bc98
+                throw_error (context, ERROR_FAILED, "identifying caller failed");
Ray Strode 81bc98
+                return FALSE;
Ray Strode 81bc98
+        }
Ray Strode 81bc98
+
Ray Strode 81bc98
+        if (user->uid == (uid_t) uid)
Ray Strode 81bc98
                 action_id = "org.freedesktop.accounts.change-own-user-data";
Ray Strode 81bc98
         else
Ray Strode 81bc98
                 action_id = "org.freedesktop.accounts.user-administration";
Ray Strode 81bc98
@@ -844,11 +842,15 @@ user_set_location (AccountsUser          *auser,
Ray Strode 81bc98
                    const gchar           *location)
Ray Strode 81bc98
 {
Ray Strode 81bc98
         User *user = (User*)auser;
Ray Strode 81bc98
-        uid_t uid;
Ray Strode 81bc98
+        int uid;
Ray Strode 81bc98
         const gchar *action_id;
Ray Strode 81bc98
Ray Strode 81bc98
-        uid = method_invocation_get_uid (context);
Ray Strode 81bc98
-        if (user->uid == uid)
Ray Strode 81bc98
+        if (!get_caller_uid (context, &uid)) {
Ray Strode 81bc98
+                throw_error (context, ERROR_FAILED, "identifying caller failed");
Ray Strode 81bc98
+                return FALSE;
Ray Strode 81bc98
+        }
Ray Strode 81bc98
+
Ray Strode 81bc98
+        if (user->uid == (uid_t) uid)
Ray Strode 81bc98
                 action_id = "org.freedesktop.accounts.change-own-user-data";
Ray Strode 81bc98
         else
Ray Strode 81bc98
                 action_id = "org.freedesktop.accounts.user-administration";
Ray Strode 81bc98
@@ -1163,11 +1165,15 @@ user_set_icon_file (AccountsUser          *auser,
Ray Strode 81bc98
                     const gchar           *filename)
Ray Strode 81bc98
 {
Ray Strode 81bc98
         User *user = (User*)auser;
Ray Strode 81bc98
-        uid_t uid;
Ray Strode 81bc98
+        int uid;
Ray Strode 81bc98
         const gchar *action_id;
Ray Strode 81bc98
Ray Strode 81bc98
-        uid = method_invocation_get_uid (context);
Ray Strode 81bc98
-        if (user->uid == uid)
Ray Strode 81bc98
+        if (!get_caller_uid (context, &uid)) {
Ray Strode 81bc98
+                throw_error (context, ERROR_FAILED, "identifying caller failed");
Ray Strode 81bc98
+                return FALSE;
Ray Strode 81bc98
+        }
Ray Strode 81bc98
+
Ray Strode 81bc98
+        if (user->uid == (uid_t) uid)
Ray Strode 81bc98
                 action_id = "org.freedesktop.accounts.change-own-user-data";
Ray Strode 81bc98
         else
Ray Strode 81bc98
                 action_id = "org.freedesktop.accounts.user-administration";
Ray Strode 81bc98
--
Ray Strode 81bc98
1.7.10.2
Ray Strode 81bc98
Ray Strode 81bc98
Ray Strode 81bc98
From 4c5b12e363410e490e776e4b4a86dcce157a543d Mon Sep 17 00:00:00 2001
Ray Strode 81bc98
From: Ray Strode <rstrode@redhat.com>
Ray Strode 81bc98
Date: Tue, 19 Jun 2012 14:34:18 -0400
Ray Strode 81bc98
Subject: [PATCH 3/3] util: CVE-2012-2737: drop _polkit_subject_get_cmdline
Ray Strode 81bc98
Ray Strode 81bc98
_polkit_subject_get_cmdline is a function copy and pasted
Ray Strode 81bc98
from the polkit code that returns the command line, uid, and
Ray Strode 81bc98
pid of a particular polkit subject.  It's used for helping to
Ray Strode 81bc98
generate log entries that detail what processes are invoking methods
Ray Strode 81bc98
on the accounts service.
Ray Strode 81bc98
Ray Strode 81bc98
It's also used, on older kernels, for setting up the the loginuid
Ray Strode 81bc98
of subprocesses that are run on behalf of AccountsService clients,
Ray Strode 81bc98
so the audit trail leads back to the user initiating a request.
Ray Strode 81bc98
Ray Strode 81bc98
_polkit_subject_get_cmdline directly looks up the uid of the caller,
Ray Strode 81bc98
instead of querying the system bus.  As such, it's vulnerable to
Ray Strode 81bc98
the same race condition discussed in the previous two commits.
Ray Strode 81bc98
Ray Strode 81bc98
This commit guts _polkit_subject_get_cmdline, keeping only the part
Ray Strode 81bc98
that reads /proc/pid/cmdline. We now get the uid and pid from the
Ray Strode 81bc98
bus daemon.
Ray Strode 81bc98
---
Ray Strode 81bc98
 src/util.c |  135 ++++++++++++++++++++++++++++++++++--------------------------
Ray Strode 81bc98
 1 file changed, 76 insertions(+), 59 deletions(-)
Ray Strode 81bc98
Ray Strode 81bc98
diff --git a/src/util.c b/src/util.c
Ray Strode 81bc98
index 1ce375b..adc559a 100644
Ray Strode 81bc98
--- a/src/util.c
Ray Strode 81bc98
+++ b/src/util.c
Ray Strode 81bc98
@@ -34,11 +34,9 @@
Ray Strode 81bc98
Ray Strode 81bc98
 #include "util.h"
Ray Strode 81bc98
Ray Strode 81bc98
-
Ray Strode 81bc98
 static gchar *
Ray Strode 81bc98
-_polkit_subject_get_cmdline (PolkitSubject *subject, gint *pid, gint *uid)
Ray Strode 81bc98
+get_cmdline_of_pid (GPid pid)
Ray Strode 81bc98
 {
Ray Strode 81bc98
-  PolkitSubject *process;
Ray Strode 81bc98
   gchar *ret;
Ray Strode 81bc98
   gchar *filename;
Ray Strode 81bc98
   gchar *contents;
Ray Strode 81bc98
@@ -46,43 +44,7 @@ _polkit_subject_get_cmdline (PolkitSubject *subject, gint *pid, gint *uid)
Ray Strode 81bc98
   GError *error;
Ray Strode 81bc98
   guint n;
Ray Strode 81bc98
Ray Strode 81bc98
-  g_return_val_if_fail (subject != NULL, NULL);
Ray Strode 81bc98
-
Ray Strode 81bc98
-  error = NULL;
Ray Strode 81bc98
-
Ray Strode 81bc98
-  ret = NULL;
Ray Strode 81bc98
-  process = NULL;
Ray Strode 81bc98
-  filename = NULL;
Ray Strode 81bc98
-  contents = NULL;
Ray Strode 81bc98
-
Ray Strode 81bc98
-  if (POLKIT_IS_UNIX_PROCESS (subject))
Ray Strode 81bc98
-   {
Ray Strode 81bc98
-      process = g_object_ref (subject);
Ray Strode 81bc98
-    }
Ray Strode 81bc98
-  else if (POLKIT_IS_SYSTEM_BUS_NAME (subject))
Ray Strode 81bc98
-    {
Ray Strode 81bc98
-      process = polkit_system_bus_name_get_process_sync (POLKIT_SYSTEM_BUS_NAME (subject),
Ray Strode 81bc98
-                                                         NULL,
Ray Strode 81bc98
-                                                         &error);
Ray Strode 81bc98
-      if (process == NULL)
Ray Strode 81bc98
-        {
Ray Strode 81bc98
-          g_warning ("Error getting process for system bus name `%s': %s",
Ray Strode 81bc98
-                     polkit_system_bus_name_get_name (POLKIT_SYSTEM_BUS_NAME (subject)),
Ray Strode 81bc98
-                     error->message);
Ray Strode 81bc98
-          g_error_free (error);
Ray Strode 81bc98
-          goto out;
Ray Strode 81bc98
-        }
Ray Strode 81bc98
-    }
Ray Strode 81bc98
-  else
Ray Strode 81bc98
-    {
Ray Strode 81bc98
-      g_warning ("Unknown subject type passed to guess_program_name()");
Ray Strode 81bc98
-      goto out;
Ray Strode 81bc98
-    }
Ray Strode 81bc98
-
Ray Strode 81bc98
-  *pid = polkit_unix_process_get_pid (POLKIT_UNIX_PROCESS (process));
Ray Strode 81bc98
-  *uid = polkit_unix_process_get_uid (POLKIT_UNIX_PROCESS (process));
Ray Strode 81bc98
-
Ray Strode 81bc98
-  filename = g_strdup_printf ("/proc/%d/cmdline", *pid);
Ray Strode 81bc98
+  filename = g_strdup_printf ("/proc/%d/cmdline", (int) pid);
Ray Strode 81bc98
Ray Strode 81bc98
   if (!g_file_get_contents (filename,
Ray Strode 81bc98
                             &contents,
Ray Strode 81bc98
@@ -108,11 +70,49 @@ _polkit_subject_get_cmdline (PolkitSubject *subject, gint *pid, gint *uid)
Ray Strode 81bc98
  out:
Ray Strode 81bc98
   g_free (filename);
Ray Strode 81bc98
   g_free (contents);
Ray Strode 81bc98
-  if (process != NULL)
Ray Strode 81bc98
-    g_object_unref (process);
Ray Strode 81bc98
+
Ray Strode 81bc98
   return ret;
Ray Strode 81bc98
 }
Ray Strode 81bc98
Ray Strode 81bc98
+static gboolean
Ray Strode 81bc98
+get_caller_pid (GDBusMethodInvocation *context,
Ray Strode 81bc98
+                GPid                  *pid)
Ray Strode 81bc98
+{
Ray Strode 81bc98
+        GVariant      *reply;
Ray Strode 81bc98
+        GError        *error;
Ray Strode 81bc98
+        guint32        pid_as_int;
Ray Strode 81bc98
+
Ray Strode 81bc98
+        error = NULL;
Ray Strode 81bc98
+        reply = g_dbus_connection_call_sync (g_dbus_method_invocation_get_connection (context),
Ray Strode 81bc98
+                                             "org.freedesktop.DBus",
Ray Strode 81bc98
+                                             "/org/freedesktop/DBus",
Ray Strode 81bc98
+                                             "org.freedesktop.DBus",
Ray Strode 81bc98
+                                             "GetConnectionUnixProcessID",
Ray Strode 81bc98
+                                             g_variant_new ("(s)",
Ray Strode 81bc98
+                                                            g_dbus_method_invocation_get_sender (context)),
Ray Strode 81bc98
+                                             G_VARIANT_TYPE ("(u)"),
Ray Strode 81bc98
+                                             G_DBUS_CALL_FLAGS_NONE,
Ray Strode 81bc98
+                                             -1,
Ray Strode 81bc98
+                                             NULL,
Ray Strode 81bc98
+                                             &error);
Ray Strode 81bc98
+
Ray Strode 81bc98
+        if (reply == NULL) {
Ray Strode 81bc98
+                g_warning ("Could not talk to message bus to find uid of sender %s: %s",
Ray Strode 81bc98
+                           g_dbus_method_invocation_get_sender (context),
Ray Strode 81bc98
+                           error->message);
Ray Strode 81bc98
+                g_error_free (error);
Ray Strode 81bc98
+
Ray Strode 81bc98
+                return FALSE;
Ray Strode 81bc98
+        }
Ray Strode 81bc98
+
Ray Strode 81bc98
+        g_variant_get (reply, "(u)", &pid_as_int);
Ray Strode 81bc98
+        *pid = pid_as_int;
Ray Strode 81bc98
+
Ray Strode 81bc98
+        g_variant_unref (reply);
Ray Strode 81bc98
+
Ray Strode 81bc98
+        return TRUE;
Ray Strode 81bc98
+}
Ray Strode 81bc98
+
Ray Strode 81bc98
 void
Ray Strode 81bc98
 sys_log (GDBusMethodInvocation *context,
Ray Strode 81bc98
          const gchar           *format,
Ray Strode 81bc98
@@ -127,21 +127,36 @@ sys_log (GDBusMethodInvocation *context,
Ray Strode 81bc98
Ray Strode 81bc98
         if (context) {
Ray Strode 81bc98
                 PolkitSubject *subject;
Ray Strode 81bc98
-                gchar *cmdline;
Ray Strode 81bc98
+                gchar *cmdline = NULL;
Ray Strode 81bc98
                 gchar *id;
Ray Strode 81bc98
-                gint pid = 0;
Ray Strode 81bc98
-                gint uid = 0;
Ray Strode 81bc98
+                GPid pid = 0;
Ray Strode 81bc98
+                gint uid = -1;
Ray Strode 81bc98
                 gchar *tmp;
Ray Strode 81bc98
Ray Strode 81bc98
                 subject = polkit_system_bus_name_new (g_dbus_method_invocation_get_sender (context));
Ray Strode 81bc98
                 id = polkit_subject_to_string (subject);
Ray Strode 81bc98
-                cmdline = _polkit_subject_get_cmdline (subject, &pid, &uid);
Ray Strode 81bc98
Ray Strode 81bc98
-                if (cmdline == NULL) {
Ray Strode 81bc98
-                        tmp = g_strdup_printf ("request by %s: %s", id, msg);
Ray Strode 81bc98
+                if (get_caller_pid (context, &pid)) {
Ray Strode 81bc98
+                        cmdline = get_cmdline_of_pid (pid);
Ray Strode 81bc98
+                } else {
Ray Strode 81bc98
+                        pid = 0;
Ray Strode 81bc98
+                        cmdline = NULL;
Ray Strode 81bc98
                 }
Ray Strode 81bc98
-                else {
Ray Strode 81bc98
-                        tmp = g_strdup_printf ("request by %s [%s pid:%d uid:%d]: %s", id, cmdline, pid, uid, msg);
Ray Strode 81bc98
+
Ray Strode 81bc98
+                if (cmdline != NULL) {
Ray Strode 81bc98
+                        if (get_caller_uid (context, &uid)) {
Ray Strode 81bc98
+                                tmp = g_strdup_printf ("request by %s [%s pid:%d uid:%d]: %s", id, cmdline, (int) pid, uid, msg);
Ray Strode 81bc98
+                        } else {
Ray Strode 81bc98
+                                tmp = g_strdup_printf ("request by %s [%s pid:%d]: %s", id, cmdline, (int) pid, msg);
Ray Strode 81bc98
+                        }
Ray Strode 81bc98
+                } else {
Ray Strode 81bc98
+                        if (get_caller_uid (context, &uid) && pid != 0) {
Ray Strode 81bc98
+                                tmp = g_strdup_printf ("request by %s [pid:%d uid:%d]: %s", id, (int) pid, uid, msg);
Ray Strode 81bc98
+                        } else if (pid != 0) {
Ray Strode 81bc98
+                                tmp = g_strdup_printf ("request by %s [pid:%d]: %s", id, (int) pid, msg);
Ray Strode 81bc98
+                        } else {
Ray Strode 81bc98
+                                tmp = g_strdup_printf ("request by %s: %s", id, msg);
Ray Strode 81bc98
+                        }
Ray Strode 81bc98
                 }
Ray Strode 81bc98
Ray Strode 81bc98
                 g_free (msg);
Ray Strode 81bc98
@@ -160,20 +175,22 @@ sys_log (GDBusMethodInvocation *context,
Ray Strode 81bc98
 static void
Ray Strode 81bc98
 get_caller_loginuid (GDBusMethodInvocation *context, gchar *loginuid, gint size)
Ray Strode 81bc98
 {
Ray Strode 81bc98
-        PolkitSubject *subject;
Ray Strode 81bc98
-        gchar *cmdline;
Ray Strode 81bc98
-        gint pid;
Ray Strode 81bc98
+        GPid pid;
Ray Strode 81bc98
         gint uid;
Ray Strode 81bc98
         gchar *path;
Ray Strode 81bc98
         gchar *buf;
Ray Strode 81bc98
Ray Strode 81bc98
-        subject = polkit_system_bus_name_new (g_dbus_method_invocation_get_sender (context));
Ray Strode 81bc98
-        cmdline = _polkit_subject_get_cmdline (subject, &pid, &uid);
Ray Strode 81bc98
-        g_free (cmdline);
Ray Strode 81bc98
-        g_object_unref (subject);
Ray Strode 81bc98
+        if (!get_caller_uid (context, &uid)) {
Ray Strode 81bc98
+                uid = getuid ();
Ray Strode 81bc98
+        }
Ray Strode 81bc98
+
Ray Strode 81bc98
+        if (get_caller_pid (context, &pid)) {
Ray Strode 81bc98
+                path = g_strdup_printf ("/proc/%d/loginuid", (int) pid);
Ray Strode 81bc98
+        } else {
Ray Strode 81bc98
+                path = NULL;
Ray Strode 81bc98
+        }
Ray Strode 81bc98
Ray Strode 81bc98
-        path = g_strdup_printf ("/proc/%d/loginuid", pid);
Ray Strode 81bc98
-        if (g_file_get_contents (path, &buf, NULL, NULL)) {
Ray Strode 81bc98
+        if (path != NULL && g_file_get_contents (path, &buf, NULL, NULL)) {
Ray Strode 81bc98
                 strncpy (loginuid, buf, size);
Ray Strode 81bc98
                 g_free (buf);
Ray Strode 81bc98
         }
Ray Strode 81bc98
--
Ray Strode 81bc98
1.7.10.2