From 7c11f9067d78a7c87cd4dee9c1a80959e8b63d32 Mon Sep 17 00:00:00 2001 From: David Zeuthen Date: Mon, 6 Feb 2012 12:44:21 -0500 Subject: [PATCH] Set error if we cannot obtain a PolkitUnixSession for a given PID (#787222) --- ...n-Set-error-if-we-cannot-find-a-sess.patch | 68 +++++++++++++++++++ ...n-Actually-return-TRUE-if-a-session-.patch | 44 ++++++++++++ polkit.spec | 10 ++- 3 files changed, 121 insertions(+), 1 deletion(-) create mode 100644 0001-PolkitUnixSession-Set-error-if-we-cannot-find-a-sess.patch create mode 100644 0002-PolkitUnixSession-Actually-return-TRUE-if-a-session-.patch diff --git a/0001-PolkitUnixSession-Set-error-if-we-cannot-find-a-sess.patch b/0001-PolkitUnixSession-Set-error-if-we-cannot-find-a-sess.patch new file mode 100644 index 0000000..99cee30 --- /dev/null +++ b/0001-PolkitUnixSession-Set-error-if-we-cannot-find-a-sess.patch @@ -0,0 +1,68 @@ +From 579eb3b0f9addb832ab6aab319b5d9f7d71f2eb8 Mon Sep 17 00:00:00 2001 +From: David Zeuthen +Date: Mon, 6 Feb 2012 11:24:53 -0500 +Subject: [PATCH 1/2] PolkitUnixSession: Set error if we cannot find a session + for the given pid + +Also, don't treat the integer returned by sd_pid_get_session() as a +boolean because that's just confusing. Also, don't confuse memory +supposed to be freed by g_free() and free(3) with each other. See + + https://bugzilla.redhat.com/show_bug.cgi?id=787222 + +for more details. + +Signed-off-by: David Zeuthen +--- + src/polkit/polkitunixsession-systemd.c | 21 ++++++++++++++++----- + 1 files changed, 16 insertions(+), 5 deletions(-) + +diff --git a/src/polkit/polkitunixsession-systemd.c b/src/polkit/polkitunixsession-systemd.c +index e7e913f..94a7ee4 100644 +--- a/src/polkit/polkitunixsession-systemd.c ++++ b/src/polkit/polkitunixsession-systemd.c +@@ -23,6 +23,7 @@ + # include "config.h" + #endif + ++#include + #include + #include "polkitunixsession.h" + #include "polkitsubject.h" +@@ -450,9 +451,8 @@ polkit_unix_session_initable_init (GInitable *initable, + GError **error) + { + PolkitUnixSession *session = POLKIT_UNIX_SESSION (initable); +- gboolean ret; +- +- ret = FALSE; ++ gboolean ret = FALSE; ++ char *s; + + if (session->session_id != NULL) + { +@@ -461,8 +461,19 @@ polkit_unix_session_initable_init (GInitable *initable, + goto out; + } + +- if (!sd_pid_get_session (session->pid, &session->session_id)) +- ret = TRUE; ++ if (sd_pid_get_session (session->pid, &s) == 0) ++ { ++ session->session_id = g_strdup (s); ++ free (s); ++ ret = TRUE; ++ goto out; ++ } ++ ++ g_set_error (error, ++ POLKIT_ERROR, ++ POLKIT_ERROR_FAILED, ++ "No session for pid %d", ++ (gint) session->pid); + + out: + return ret; +-- +1.7.8.4 + diff --git a/0002-PolkitUnixSession-Actually-return-TRUE-if-a-session-.patch b/0002-PolkitUnixSession-Actually-return-TRUE-if-a-session-.patch new file mode 100644 index 0000000..d4d81ec --- /dev/null +++ b/0002-PolkitUnixSession-Actually-return-TRUE-if-a-session-.patch @@ -0,0 +1,44 @@ +From 414f38ee69155eef8badd6f938953c98ce0c1e76 Mon Sep 17 00:00:00 2001 +From: David Zeuthen +Date: Mon, 6 Feb 2012 11:26:06 -0500 +Subject: [PATCH 2/2] PolkitUnixSession: Actually return TRUE if a session + exists + +Also, don't treat the integer returned by sd_session_get_uid() as a +boolean because that's just confusing. + +Signed-off-by: David Zeuthen +--- + src/polkit/polkitunixsession-systemd.c | 12 +++++------- + 1 files changed, 5 insertions(+), 7 deletions(-) + +diff --git a/src/polkit/polkitunixsession-systemd.c b/src/polkit/polkitunixsession-systemd.c +index 94a7ee4..8a8bf65 100644 +--- a/src/polkit/polkitunixsession-systemd.c ++++ b/src/polkit/polkitunixsession-systemd.c +@@ -361,17 +361,15 @@ polkit_unix_session_to_string (PolkitSubject *subject) + + static gboolean + polkit_unix_session_exists_sync (PolkitSubject *subject, +- GCancellable *cancellable, +- GError **error) ++ GCancellable *cancellable, ++ GError **error) + { + PolkitUnixSession *session = POLKIT_UNIX_SESSION (subject); +- gboolean ret; ++ gboolean ret = FALSE; + uid_t uid; + +- ret = FALSE; +- +- if (!sd_session_get_uid (session->session_id, &uid)) +- ret = FALSE; ++ if (sd_session_get_uid (session->session_id, &uid) == 0) ++ ret = TRUE; + + return ret; + } +-- +1.7.8.4 + diff --git a/polkit.spec b/polkit.spec index 4029564..4d1151d 100644 --- a/polkit.spec +++ b/polkit.spec @@ -1,7 +1,7 @@ Summary: PolicyKit Authorization Framework Name: polkit Version: 0.104 -Release: 3%{?dist} +Release: 4%{?dist} License: LGPLv2+ URL: http://www.freedesktop.org/wiki/Software/PolicyKit Source0: http://hal.freedesktop.org/releases/%{name}-%{version}.tar.gz @@ -26,6 +26,9 @@ Conflicts: polkit-gnome < 0.97 Obsoletes: polkit-desktop-policy < 0.103 Provides: polkit-desktop-policy = 0.103 +Patch0: 0001-PolkitUnixSession-Set-error-if-we-cannot-find-a-sess.patch +Patch1: 0002-PolkitUnixSession-Actually-return-TRUE-if-a-session-.patch + %description PolicyKit is a toolkit for defining and handling authorizations. It is used for allowing unprivileged processes to speak to privileged @@ -55,6 +58,8 @@ Development documentation for PolicyKit. %prep %setup -q +%patch0 -p1 +%patch1 -p1 %build %configure --enable-gtk-doc \ @@ -125,6 +130,9 @@ rm -f $RPM_BUILD_ROOT%{_libdir}/polkit-1/extensions/*.la %{_datadir}/gtk-doc %changelog +* Mon Feb 06 2012 David Zeuthen 0.104-4%{?dist} +- Set error if we cannot obtain a PolkitUnixSession for a given PID (#787222) + * Sat Jan 14 2012 Fedora Release Engineering - 0.104-3 - Rebuilt for https://fedoraproject.org/wiki/Fedora_17_Mass_Rebuild