37
39
g_dbus_error_register_error (quark,
38
40
CD_MAIN_ERROR_FAILED,
39
41
COLORD_DBUS_SERVICE ".Failed");
42
g_dbus_error_register_error (quark,
43
CD_MAIN_ERROR_ALREADY_EXISTS,
44
COLORD_DBUS_SERVICE ".AlreadyExists");
66
* cd_main_get_sender_uid:
69
cd_main_get_sender_uid (GDBusMethodInvocation *invocation, GError **error)
72
GDBusConnection *connection;
73
guint uid = G_MAXUINT;
76
/* call into DBus to get the user ID that issued the request */
77
connection = g_dbus_method_invocation_get_connection (invocation);
78
sender = g_dbus_method_invocation_get_sender (invocation);
79
value = g_dbus_connection_call_sync (connection,
80
"org.freedesktop.DBus",
81
"/org/freedesktop/DBus",
82
"org.freedesktop.DBus",
83
"GetConnectionUnixUser",
87
G_DBUS_CALL_FLAGS_NONE,
92
g_variant_get (value, "(u)", &uid);
93
g_variant_unref (value);
61
99
* cd_main_sender_authenticated:
64
102
cd_main_sender_authenticated (GDBusMethodInvocation *invocation,
66
103
const gchar *action_id)
69
106
gboolean ret = FALSE;
70
107
GError *error = NULL;
71
110
PolkitAuthorizationResult *result = NULL;
72
111
PolkitSubject *subject = NULL;
73
112
PolkitAuthority *authority = NULL;
115
/* uid 0 is allowed to do all actions */
116
sender = g_dbus_method_invocation_get_sender (invocation);
117
uid = cd_main_get_sender_uid (invocation, &error);
118
if (uid == G_MAXUINT) {
119
g_dbus_method_invocation_return_error (invocation,
121
CD_MAIN_ERROR_FAILED,
122
"could not get uid to authenticate %s: %s",
125
g_error_free (error);
129
/* the root user can always do all actions */
131
g_debug ("CdCommon: not checking %s for %s as uid 0",
75
138
/* get authority */
76
139
authority = polkit_authority_get_sync (NULL, &error);
77
140
if (authority == NULL) {
177
g_warning ("CdCommon: not checking %s for %s as no PolicyKit support",
117
185
if (authority != NULL)
118
186
g_object_unref (authority);
119
187
if (result != NULL)
120
188
g_object_unref (result);
121
189
if (subject != NULL)
122
190
g_object_unref (subject);
125
g_warning ("CdCommon: not checking %s for %s as no PolicyKit support",