aboutsummaryrefslogtreecommitdiff
path: root/debian/patches/01_polkit-1.patch
blob: 03660cb27dc5ab425163980efa37689f5c26fad7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
--- indicator-session-0.1.4/configure.ac	2009-09-22 09:12:00.000000000 +0200
+++ indicator-session-0.1.4.new/configure.ac	2009-09-22 09:11:42.000000000 +0200
@@ -28,6 +28,7 @@
 GTK_REQUIRED_VERSION=2.12
 INDICATOR_REQUIRED_VERSION=0.2.0
 DBUSMENUGTK_REQUIRED_VERSION=0.1.1
+POLKIT_REQUIRED_VERSION=0.92
 
 PKG_CHECK_MODULES(APPLET, gtk+-2.0 >= $GTK_REQUIRED_VERSION
                           indicator >= $INDICATOR_REQUIRED_VERSION
@@ -53,7 +54,8 @@
 AC_SUBST(SESSIONERVICE_LIBS)
 
 PKG_CHECK_MODULES(GTKLOGOUTHELPER, gtk+-2.0 >= $GTK_REQUIRED_VERSION
-                                   polkit-gnome)
+                                   polkit-gobject-1 >= $POLKIT_REQUIRED_VERSION)
+
 
 AC_SUBST(GTKLOGOUTHELPER_CFLAGS)
 AC_SUBST(GTKLOGOUTHELPER_LIBS)
diff -ur indicator-session-0.1.4/src/gtk-dialog/ck-pk-helper.c indicator-session-0.1.4.new/src/gtk-dialog/ck-pk-helper.c
--- indicator-session-0.1.4/src/gtk-dialog/ck-pk-helper.c	2009-09-22 09:12:00.000000000 +0200
+++ indicator-session-0.1.4.new/src/gtk-dialog/ck-pk-helper.c	2009-09-22 09:11:43.000000000 +0200
@@ -24,7 +24,7 @@
 #include <unistd.h>
 #include <glib.h>
 #include <dbus/dbus-glib.h>
-#include <polkit-gnome/polkit-gnome.h>
+#include <polkit/polkit.h>
 
 #include "logout-dialog.h"
 #include "ck-pk-helper.h"
@@ -170,67 +170,53 @@
 		}
 	}
 
-	PolKitResult polres;
+	PolkitAuthorizationResult *polres = NULL;
+	gboolean ret = FALSE;
 	if (pk_can_do_action(pk_action, &polres)) {
-		if (polres == POLKIT_RESULT_YES) {
-			return FALSE;
+		if (polkit_authorization_result_get_is_challenge (polres)) {
+			ret = TRUE;
 		}
-		return TRUE;
+		g_debug ("pk_require_auth(%s): authorized, is_challenge: %i", pk_action, ret);
+	} else {
+		g_debug ("pk_require_auth(%s): not authorized", pk_action);
+	}
+	if (polres) {
+		g_object_unref (polres);
 	}
-	return FALSE;
+	return ret;
 }
 
 gboolean
-pk_can_do_action (const gchar    *action_id, PolKitResult * pol_result)
+pk_can_do_action (const gchar    *action_id, PolkitAuthorizationResult ** pol_result)
 {
-        PolKitGnomeContext *gnome_context;
-        PolKitAction *action;
-        PolKitCaller *caller;
-        DBusError dbus_error;
-        PolKitError *error;
-        PolKitResult result;
-
-        gnome_context = polkit_gnome_context_get (NULL);
-
-        if (gnome_context == NULL) {
-                return FALSE;
-        }
-
-        if (gnome_context->pk_tracker == NULL) {
-                return FALSE;
-        }
-
-        dbus_error_init (&dbus_error);
-        caller = polkit_tracker_get_caller_from_pid (gnome_context->pk_tracker,
-                                                     getpid (),
-                                                     &dbus_error);
-        dbus_error_free (&dbus_error);
-
-        if (caller == NULL) {
-                return FALSE;
-        }
-
-        action = polkit_action_new ();
-        if (!polkit_action_set_action_id (action, action_id)) {
-                polkit_action_unref (action);
-                polkit_caller_unref (caller);
-                return FALSE;
-        }
-
-        result = POLKIT_RESULT_UNKNOWN;
-        error = NULL;
-        result = polkit_context_is_caller_authorized (gnome_context->pk_context,
-                                                      action, caller, FALSE,
-                                                      &error);
-        if (polkit_error_is_set (error)) {
-                polkit_error_free (error);
-        }
-        polkit_action_unref (action);
-                polkit_caller_unref (caller);
+	PolkitAuthority *authority;
+	PolkitSubject *subject;
+	PolkitAuthorizationResult *result;
+	gboolean ret;
+
+	authority = polkit_authority_get();
+	if (!authority) {
+		g_warning ("Could not get PolicyKit authority instance");
+		return FALSE;
+	}
+	subject = polkit_unix_process_new (getpid());
 
-		if (pol_result != NULL) {
-			*pol_result = result;
-		}
+	result = polkit_authority_check_authorization_sync (authority, subject, action_id, NULL, 0, NULL, NULL);
+	g_object_unref (authority);
 
-        return result != POLKIT_RESULT_NO && result != POLKIT_RESULT_UNKNOWN;
+	ret = FALSE;
+	if (result) {
+		ret = polkit_authorization_result_get_is_authorized (result) || 
+		      polkit_authorization_result_get_is_challenge (result);
+		g_debug ("pk_can_do_action(%s): %i", action_id, ret);
+	} else {
+		g_warning ("pk_can_do_action(%s): check_authorization returned NULL", action_id);
+	}
+	if (pol_result) {
+		*pol_result = result;
+	} else {
+		g_object_unref (result);
+	}
+	return ret;
+	
 }
diff -ur indicator-session-0.1.4/src/gtk-dialog/ck-pk-helper.h indicator-session-0.1.4.new/src/gtk-dialog/ck-pk-helper.h
--- indicator-session-0.1.4/src/gtk-dialog/ck-pk-helper.h	2009-09-22 09:12:00.000000000 +0200
+++ indicator-session-0.1.4.new/src/gtk-dialog/ck-pk-helper.h	2009-09-22 09:11:43.000000000 +0200
@@ -24,9 +24,9 @@
 #ifndef __CK_PK_HELPER_H__
 #define __CK_PK_HELPER_H__ 1
 
-#include <polkit-gnome/polkit-gnome.h>
+#include <polkit/polkit.h>
 
 gboolean pk_require_auth (LogoutDialogAction action);
-gboolean pk_can_do_action (const gchar *action_id, PolKitResult * pol_result);
+gboolean pk_can_do_action (const gchar *action_id, PolkitAuthorizationResult ** pol_result);
 
 #endif /* __CK_PK_HELPER__ */