source: proiecte/PPPP/gdm/debian/patches/08_use_polkit_for_settings.patch @ 134

Last change on this file since 134 was 134, checked in by (none), 14 years ago

gdm sources with the modifications for webcam

File size: 12.5 KB
RevLine 
[134]1#
2# Description: Add PolicyKit support to GDM settings D-Bus interface
3# Ubuntu: https://bugs.launchpad.net/ubuntu/+source/gdm/+bug/395299
4# Upstream: http://bugzilla.gnome.org/show_bug.cgi?id=587750
5#
6diff -Nur -x '*.orig' -x '*~' gdm-2.28.0/common/gdm-settings.c gdm-2.28.0.new/common/gdm-settings.c
7--- gdm-2.28.0/common/gdm-settings.c    2009-09-21 22:05:27.000000000 +0200
8+++ gdm-2.28.0.new/common/gdm-settings.c        2009-09-22 16:16:05.000000000 +0200
9@@ -36,6 +36,7 @@
10 #define DBUS_API_SUBJECT_TO_CHANGE
11 #include <dbus/dbus-glib.h>
12 #include <dbus/dbus-glib-lowlevel.h>
13+#include <polkit/polkit.h>
14 
15 #include "gdm-settings.h"
16 #include "gdm-settings-glue.h"
17@@ -110,6 +111,90 @@
18         return res;
19 }
20 
21+static void
22+unlock_auth_cb (PolkitAuthority *authority,
23+                GAsyncResult *result,
24+                DBusGMethodInvocation *context)
25+{
26+        PolkitAuthorizationResult *auth_result;
27+        GError  *error = NULL;
28+
29+        auth_result = polkit_authority_check_authorization_finish (authority, result, &error);
30+
31+        if (!auth_result)
32+                dbus_g_method_return_error (context, error);
33+        else {
34+                dbus_g_method_return (context,
35+                                      polkit_authorization_result_get_is_authorized (auth_result));
36+        }
37+   
38+        if (auth_result)
39+                g_object_unref (auth_result);
40+        if (error)
41+                g_error_free (error);
42+}
43+
44+gboolean
45+gdm_settings_unlock (GdmSettings *settings,
46+                     DBusGMethodInvocation *context)
47+{
48+        polkit_authority_check_authorization (polkit_authority_get (),
49+                                              polkit_system_bus_name_new (dbus_g_method_get_sender (context)),
50+                                              "org.gnome.displaymanager.settings.write",
51+                                              NULL,
52+                                              POLKIT_CHECK_AUTHORIZATION_FLAGS_ALLOW_USER_INTERACTION,
53+                                              NULL,
54+                                              (GAsyncReadyCallback) unlock_auth_cb,
55+                                              context);
56+}
57+
58+typedef struct
59+{
60+        GdmSettings *settings;
61+        DBusGMethodInvocation *context;
62+        gchar *key, *value;
63+} SetValueData;
64+
65+static void
66+set_value_auth_cb (PolkitAuthority *authority,
67+                   GAsyncResult *result,
68+                   SetValueData *data)
69+{
70+        PolkitAuthorizationResult *auth_result;
71+        GError  *error = NULL;
72+
73+        auth_result = polkit_authority_check_authorization_finish (authority, result, &error);
74+
75+        if (!auth_result)
76+                dbus_g_method_return_error (data->context, error);
77+        else {
78+                if (polkit_authorization_result_get_is_authorized (auth_result)) {
79+                        gboolean result;
80+                   
81+                        result = gdm_settings_backend_set_value (data->settings->priv->backend,
82+                                                                 data->key,
83+                                                                 data->value,
84+                                                                 &error);
85+                        if (result)
86+                                dbus_g_method_return (data->context);
87+                        else
88+                                dbus_g_method_return_error (data->context, error);
89+                }
90+                else {
91+                        error = g_error_new (DBUS_GERROR_REMOTE_EXCEPTION, 0, "Not authorized");
92+                        dbus_g_method_return_error (data->context, error);
93+                }
94+        }
95+   
96+        if (auth_result)
97+                g_object_unref (auth_result);
98+        if (error)
99+                g_error_free (error);
100+        g_free (data->key);
101+        g_free (data->value);
102+        g_free (data);
103+}
104+
105 /*
106 dbus-send --system --print-reply --dest=org.gnome.DisplayManager /org/gnome/DisplayManager/Settings org.gnome.DisplayManager.Settings.SetValue string:"xdmcp/Enable" string:"false"
107 */
108@@ -118,26 +203,30 @@
109 gdm_settings_set_value (GdmSettings *settings,
110                         const char  *key,
111                         const char  *value,
112-                        GError     **error)
113+                        DBusGMethodInvocation *context)
114 {
115-        GError  *local_error;
116-        gboolean res;
117-
118+        SetValueData *data;
119+   
120         g_return_val_if_fail (GDM_IS_SETTINGS (settings), FALSE);
121         g_return_val_if_fail (key != NULL, FALSE);
122 
123         g_debug ("Setting value %s", key);
124-
125-        local_error = NULL;
126-        res = gdm_settings_backend_set_value (settings->priv->backend,
127-                                              key,
128-                                              value,
129-                                              &local_error);
130-        if (! res) {
131-                g_propagate_error (error, local_error);
132-        }
133-
134-        return res;
135+   
136+        /* Authorize with PolicyKit */
137+        data = g_malloc (sizeof(SetValueData));
138+        data->settings = settings;
139+        data->context = context;
140+        data->key = g_strdup(key);
141+        data->value = g_strdup(value);   
142+        polkit_authority_check_authorization (polkit_authority_get (),
143+                                              polkit_system_bus_name_new (dbus_g_method_get_sender (context)),
144+                                              "org.gnome.displaymanager.settings.write",
145+                                              NULL,
146+                                              POLKIT_CHECK_AUTHORIZATION_FLAGS_ALLOW_USER_INTERACTION,
147+                                              NULL,
148+                                              (GAsyncReadyCallback) set_value_auth_cb,
149+                                              data);
150+        return TRUE;
151 }
152 
153 static gboolean
154diff -Nur -x '*.orig' -x '*~' gdm-2.28.0/common/gdm-settings.h gdm-2.28.0.new/common/gdm-settings.h
155--- gdm-2.28.0/common/gdm-settings.h    2009-09-21 22:05:27.000000000 +0200
156+++ gdm-2.28.0.new/common/gdm-settings.h        2009-09-22 16:16:05.000000000 +0200
157@@ -23,6 +23,7 @@
158 #define __GDM_SETTINGS_H
159 
160 #include <glib-object.h>
161+#include <dbus/dbus-glib.h>
162 
163 G_BEGIN_DECLS
164 
165@@ -70,10 +71,12 @@
166                                                                  const char  *key,
167                                                                  char       **value,
168                                                                  GError     **error);
169+gboolean            gdm_settings_unlock                         (GdmSettings *settings,
170+                                                                 DBusGMethodInvocation *context);
171 gboolean            gdm_settings_set_value                      (GdmSettings *settings,
172                                                                  const char  *key,
173                                                                  const char  *value,
174-                                                                 GError     **error);
175+                                                                 DBusGMethodInvocation *context);
176 
177 G_END_DECLS
178 
179diff -Nur -x '*.orig' -x '*~' gdm-2.28.0/common/gdm-settings.xml gdm-2.28.0.new/common/gdm-settings.xml
180--- gdm-2.28.0/common/gdm-settings.xml  2009-09-21 22:05:27.000000000 +0200
181+++ gdm-2.28.0.new/common/gdm-settings.xml      2009-09-22 16:16:05.000000000 +0200
182@@ -5,7 +5,12 @@
183       <arg name="key" direction="in" type="s"/>
184       <arg name="value" direction="out" type="s"/>
185     </method>
186+    <method name="Unlock">
187+      <annotation name="org.freedesktop.DBus.GLib.Async" value=""/>
188+      <arg name="is_unlocked" direction="out" type="b"/>
189+    </method>
190     <method name="SetValue">
191+      <annotation name="org.freedesktop.DBus.GLib.Async" value=""/>
192       <arg name="key" direction="in" type="s"/>
193       <arg name="value" direction="in" type="s"/>
194     </method>
195diff -Nur -x '*.orig' -x '*~' gdm-2.28.0/configure.ac gdm-2.28.0.new/configure.ac
196--- gdm-2.28.0/configure.ac     2009-09-22 16:16:04.000000000 +0200
197+++ gdm-2.28.0.new/configure.ac 2009-09-22 16:16:05.000000000 +0200
198@@ -40,6 +40,7 @@
199 dnl ---------------------------------------------------------------------------
200 
201 DBUS_GLIB_REQUIRED_VERSION=0.74
202+POLKIT_GOBJECT_REQUIRED_VERSION=0.92
203 GLIB_REQUIRED_VERSION=2.15.4
204 GTK_REQUIRED_VERSION=2.10.0
205 PANGO_REQUIRED_VERSION=1.3.0
206@@ -60,6 +61,7 @@
207 
208 PKG_CHECK_MODULES(COMMON,
209         dbus-glib-1 >= $DBUS_GLIB_REQUIRED_VERSION
210+        polkit-gobject-1 >= $POLKIT_GOBJECT_REQUIRED_VERSION
211         gobject-2.0 >= $GLIB_REQUIRED_VERSION
212         gio-2.0 >= $GLIB_REQUIRED_VERSION
213 )
214@@ -68,6 +70,7 @@
215 
216 PKG_CHECK_MODULES(DAEMON,
217         dbus-glib-1 >= $DBUS_GLIB_REQUIRED_VERSION
218+        polkit-gobject-1 >= $POLKIT_GOBJECT_REQUIRED_VERSION
219         gobject-2.0 >= $GLIB_REQUIRED_VERSION
220         gio-2.0 >= $GLIB_REQUIRED_VERSION
221         hal
222diff -Nur -x '*.orig' -x '*~' gdm-2.28.0/data/gdm.conf.in gdm-2.28.0.new/data/gdm.conf.in
223--- gdm-2.28.0/data/gdm.conf.in 2009-09-21 22:05:27.000000000 +0200
224+++ gdm-2.28.0.new/data/gdm.conf.in     2009-09-22 16:16:05.000000000 +0200
225@@ -34,8 +34,6 @@
226     <deny send_destination="org.gnome.DisplayManager"
227           send_interface="org.gnome.DisplayManager.LocalDisplayFactory"/>
228     <deny send_destination="org.gnome.DisplayManager"
229-          send_interface="org.gnome.DisplayManager.Settings"/>
230-    <deny send_destination="org.gnome.DisplayManager"
231           send_interface="org.gnome.DisplayManager.Slave"/>
232     <deny send_destination="org.gnome.DisplayManager"
233           send_interface="org.gnome.DisplayManager.Session"/>
234@@ -44,6 +42,10 @@
235     <allow send_destination="org.gnome.DisplayManager"
236            send_interface="org.freedesktop.DBus.Introspectable"/>
237 
238+    <!-- Controlled by PolicyKit -->
239+    <allow send_destination="org.gnome.DisplayManager"
240+           send_interface="org.gnome.DisplayManager.Settings"/>
241+
242     <allow send_destination="org.gnome.DisplayManager"
243            send_interface="org.gnome.DisplayManager.Display"
244            send_member="GetId"/>
245diff -Nur -x '*.orig' -x '*~' gdm-2.28.0/data/gdm.policy.in gdm-2.28.0.new/data/gdm.policy.in
246--- gdm-2.28.0/data/gdm.policy.in       1970-01-01 01:00:00.000000000 +0100
247+++ gdm-2.28.0.new/data/gdm.policy.in   2009-09-22 16:16:05.000000000 +0200
248@@ -0,0 +1,18 @@
249+<?xml version="1.0" encoding="UTF-8"?>
250+<!DOCTYPE policyconfig PUBLIC
251+ "-//freedesktop//DTD PolicyKit Policy Configuration 1.0//EN"
252+ "http://www.freedesktop.org/standards/PolicyKit/1.0/policyconfig.dtd">
253+<policyconfig>
254+  <vendor>The GNOME Project</vendor>
255+  <vendor_url>http://www.gnome.org/</vendor_url>
256+  <icon_name>gdm</icon_name>
257+
258+  <action id="org.gnome.displaymanager.settings.write">
259+    <_description>Change login screen configuration</_description>
260+    <_message>Privileges are required to change the login screen configuration.</_message>
261+    <defaults>
262+      <allow_inactive>no</allow_inactive>
263+      <allow_active>auth_admin_keep</allow_active>
264+    </defaults>
265+  </action>
266+</policyconfig>
267diff -Nur -x '*.orig' -x '*~' gdm-2.28.0/data/Makefile.am gdm-2.28.0.new/data/Makefile.am
268--- gdm-2.28.0/data/Makefile.am 2009-09-21 22:05:27.000000000 +0200
269+++ gdm-2.28.0.new/data/Makefile.am     2009-09-22 16:16:05.000000000 +0200
270@@ -45,6 +45,8 @@
271 schemas_in_files = gdm.schemas.in
272 schemas_DATA = $(schemas_in_files:.schemas.in=.schemas)
273 
274+@INTLTOOL_POLICY_RULE@
275+
276 gdm.schemas.in: $(srcdir)/gdm.schemas.in.in
277        sed     -e 's,[@]GDMPREFETCHCMD[@],$(GDMPREFETCHCMD),g' \
278                -e 's,[@]GDM_CUSTOM_CONF[@],$(GDM_CUSTOM_CONF),g' \
279@@ -74,10 +76,17 @@
280                -e 's,[@]sbindir[@],$(sbindir),g' \
281                <$(srcdir)/gdm.schemas.in.in >gdm.schemas.in
282 
283+polkitdir = $(datadir)/polkit-1/actions
284+polkit_in_files = gdm.policy.in
285+polkit_DATA = $(polkit_in_files:.policy.in=.policy)
286+check:
287+       $(POLKIT_POLICY_FILE_VALIDATE) $(polkit_DATA)
288+
289 EXTRA_DIST =                   \
290        $(schemas_in_files)     \
291        $(schemas_DATA)         \
292        $(dbusconf_in_files)    \
293+       $(polkit_in_files)      \
294        gdm.schemas.in.in       \
295        gdm.conf-custom.in      \
296        Xsession.in             \
297@@ -100,7 +109,8 @@
298        $(NULL)
299 
300 DISTCLEANFILES =                       \
301-       $(dbusconf_DATA)                        \
302+       $(dbusconf_DATA)                \
303+       $(polkit_DATA)                  \
304        gdm.schemas                     \
305        $(NULL)
306 
307diff -Nur -x '*.orig' -x '*~' gdm-2.28.0/po/POTFILES.in gdm-2.28.0.new/po/POTFILES.in
308--- gdm-2.28.0/po/POTFILES.in   2009-09-21 22:05:27.000000000 +0200
309+++ gdm-2.28.0.new/po/POTFILES.in       2009-09-22 16:16:16.000000000 +0200
310@@ -49,6 +49,7 @@
311 daemon/simple-slave-main.c
312 daemon/test-session.c
313 daemon/xdmcp-chooser-slave-main.c
314+data/gdm.policy.in
315 data/gdm.schemas.in.in
316 data/greeter-autostart/at-spi-registryd-wrapper.desktop.in.in
317 data/greeter-autostart/gdm-simple-greeter.desktop.in.in
Note: See TracBrowser for help on using the repository browser.