936
948
polkit_error_free (error);
938
950
polkit_action_unref (action);
939
polkit_caller_unref (caller);
951
polkit_caller_unref (caller);
957
gsm_consolekit_can_do_action (GsmConsolekit *manager,
958
const char *action_id)
965
res = gsm_consolekit_ensure_ck_connection (manager, &error);
967
g_warning ("Could not connect to ConsoleKit: %s",
969
g_error_free (error);
973
result = gsm_consolekit_get_result_for_action (manager, action_id);
941
975
return result != POLKIT_RESULT_NO && result != POLKIT_RESULT_UNKNOWN;
979
gsm_consolekit_is_session_for_other_user (GsmConsolekit *manager,
980
const char *object_path,
981
unsigned int current_uid)
988
proxy = dbus_g_proxy_new_for_name (manager->priv->dbus_connection,
991
CK_SESSION_INTERFACE);
993
res = dbus_g_proxy_call_with_timeout (proxy,
1003
/* error is bad: we consider there's another user */
1007
if (uid == current_uid)
1010
/* filter out login sessions */
1011
res = dbus_g_proxy_call_with_timeout (proxy,
1017
/* return values: */
1018
G_TYPE_STRING, &type,
1021
/* error is bad: we consider there's another user */
1025
if (g_strcmp0 (type, GSM_CONSOLEKIT_SESSION_TYPE_LOGIN_WINDOW) == 0) {
1036
gsm_consolekit_is_single_user (GsmConsolekit *manager)
1043
unsigned int current_uid;
1046
/* We use the same logic than the one used by ConsoleKit here -- it'd
1047
* be nice to have a ConsoleKit API to help us, but well...
1048
* If there's any error, we just assume it's multiple users. */
1050
proxy = dbus_g_proxy_new_for_name (manager->priv->dbus_connection,
1053
CK_MANAGER_INTERFACE);
1056
res = dbus_g_proxy_call_with_timeout (proxy,
1062
/* return values: */
1063
dbus_g_type_get_collection ("GPtrArray", DBUS_TYPE_G_OBJECT_PATH), &array,
1067
g_warning ("Unable to list sessions: %s", error->message);
1068
g_error_free (error);
1073
current_uid = getuid ();
1075
for (i = 0; i < array->len; i++) {
1078
object_path = g_ptr_array_index (array, i);
1080
if (gsm_consolekit_is_session_for_other_user (manager,
1088
g_ptr_array_foreach (array, (GFunc) g_free, NULL);
1089
g_ptr_array_free (array, TRUE);
1095
obtain_privileges_cb (PolKitAction *action,
1096
gboolean gained_privilege,
1098
GsmConsolekit *manager)
1100
g_signal_emit (G_OBJECT (manager),
1101
signals [PRIVILEGES_COMPLETED],
1102
0, gained_privilege, FALSE, error);
1106
gsm_consolekit_obtain_privileges_for_action (GsmConsolekit *manager,
1107
const char *action_id)
1109
PolKitAction *action;
1114
action = polkit_action_new ();
1115
polkit_action_set_action_id (action, action_id);
1120
res = polkit_gnome_auth_obtain (action,
1123
(PolKitGnomeAuthCB) obtain_privileges_cb,
1127
polkit_action_unref (action);
1133
gsm_consolekit_get_privileges_for_actions (GsmConsolekit *manager,
1134
const char *single_action_id,
1135
const char *multiple_action_id)
1137
PolKitResult result;
1140
const char *action_id;
1143
res = gsm_consolekit_ensure_ck_connection (manager, &error);
1145
g_warning ("Could not connect to ConsoleKit: %s",
1147
g_error_free (error);
1151
if (gsm_consolekit_is_single_user (manager)) {
1152
action_id = single_action_id;
1154
action_id = multiple_action_id;
1157
result = gsm_consolekit_get_result_for_action (manager, action_id);
1160
case POLKIT_RESULT_UNKNOWN:
1161
case POLKIT_RESULT_NO:
1163
case POLKIT_RESULT_ONLY_VIA_ADMIN_AUTH:
1164
case POLKIT_RESULT_ONLY_VIA_ADMIN_AUTH_KEEP_SESSION:
1165
case POLKIT_RESULT_ONLY_VIA_ADMIN_AUTH_KEEP_ALWAYS:
1166
case POLKIT_RESULT_ONLY_VIA_SELF_AUTH:
1167
case POLKIT_RESULT_ONLY_VIA_SELF_AUTH_KEEP_SESSION:
1168
case POLKIT_RESULT_ONLY_VIA_SELF_AUTH_KEEP_ALWAYS:
1169
if (!gsm_consolekit_obtain_privileges_for_action (manager,
1171
/* if the call doesn't work, then we were not even able
1172
* to do the call requesting the privileges: the setup
1173
* is likely broken */
1177
case POLKIT_RESULT_YES:
1178
g_signal_emit (G_OBJECT (manager),
1179
signals [PRIVILEGES_COMPLETED],
1180
0, TRUE, FALSE, NULL);
1182
case POLKIT_RESULT_ONLY_VIA_ADMIN_AUTH_ONE_SHOT:
1183
case POLKIT_RESULT_ONLY_VIA_SELF_AUTH_ONE_SHOT:
1184
g_signal_emit (G_OBJECT (manager),
1185
signals [PRIVILEGES_COMPLETED],
1186
0, TRUE, TRUE, NULL);
1189
g_assert_not_reached ();
1198
gsm_consolekit_get_restart_privileges (GsmConsolekit *manager)
1200
#ifdef HAVE_POLKIT_GNOME
1201
return gsm_consolekit_get_privileges_for_actions (manager,
1202
"org.freedesktop.consolekit.system.restart",
1203
"org.freedesktop.consolekit.system.restart-multiple-users");
1205
g_debug ("GsmConsolekit: built without PolicyKit-gnome support");
1211
gsm_consolekit_get_stop_privileges (GsmConsolekit *manager)
1213
#ifdef HAVE_POLKIT_GNOME
1214
return gsm_consolekit_get_privileges_for_actions (manager,
1215
"org.freedesktop.consolekit.system.stop",
1216
"org.freedesktop.consolekit.system.stop-multiple-users");
1218
g_debug ("GsmConsolekit: built without PolicyKit-gnome support");
946
1224
gsm_consolekit_can_restart (GsmConsolekit *manager)
948
1226
#ifdef HAVE_POLKIT_GNOME
953
res = gsm_consolekit_ensure_ck_connection (manager, &error);
955
g_warning ("Could not connect to ConsoleKit: %s",
957
g_error_free (error);
961
1227
return gsm_consolekit_can_do_action (manager, "org.freedesktop.consolekit.system.restart") ||
962
1228
gsm_consolekit_can_do_action (manager, "org.freedesktop.consolekit.system.restart-multiple-users");