400
else if (strcmp (name, "LIST-SEATS") == 0)
402
GVariant *result, *value;
408
result = g_dbus_connection_call_sync (g_bus_get_sync (G_BUS_TYPE_SYSTEM, NULL, NULL),
409
"org.freedesktop.DisplayManager",
410
"/org/freedesktop/DisplayManager",
411
"org.freedesktop.DBus.Properties",
413
g_variant_new ("(ss)", "org.freedesktop.DisplayManager", "Seats"),
414
G_VARIANT_TYPE ("(v)"),
415
G_DBUS_CALL_FLAGS_NONE,
420
status = g_string_new ("RUNNER LIST-SEATS SEATS=");
421
g_variant_get (result, "(v)", &value);
422
g_variant_get (value, "ao", &iter);
423
while (g_variant_iter_loop (iter, "&o", &path))
426
g_string_append (status, ",");
427
g_string_append (status, path);
430
g_variant_unref (value);
431
g_variant_unref (result);
433
check_status (status->str);
434
g_string_free (status, TRUE);
436
else if (strcmp (name, "LIST-SESSIONS") == 0)
438
GVariant *result, *value;
444
result = g_dbus_connection_call_sync (g_bus_get_sync (G_BUS_TYPE_SYSTEM, NULL, NULL),
445
"org.freedesktop.DisplayManager",
446
"/org/freedesktop/DisplayManager",
447
"org.freedesktop.DBus.Properties",
449
g_variant_new ("(ss)", "org.freedesktop.DisplayManager", "Sessions"),
450
G_VARIANT_TYPE ("(v)"),
451
G_DBUS_CALL_FLAGS_NONE,
456
status = g_string_new ("RUNNER LIST-SESSIONS SESSIONS=");
457
g_variant_get (result, "(v)", &value);
458
g_variant_get (value, "ao", &iter);
459
while (g_variant_iter_loop (iter, "&o", &path))
462
g_string_append (status, ",");
463
g_string_append (status, path);
466
g_variant_unref (value);
467
g_variant_unref (result);
469
check_status (status->str);
470
g_string_free (status, TRUE);
384
472
else if (strcmp (name, "SWITCH-TO-GREETER") == 0)
386
474
g_dbus_connection_call_sync (g_bus_get_sync (G_BUS_TYPE_SYSTEM, NULL, NULL),
679
798
g_strfreev (lines);
802
handle_upower_call (GDBusConnection *connection,
804
const gchar *object_path,
805
const gchar *interface_name,
806
const gchar *method_name,
807
GVariant *parameters,
808
GDBusMethodInvocation *invocation,
811
if (strcmp (method_name, "SuspendAllowed") == 0)
813
check_status ("UPOWER SUSPEND-ALLOWED");
814
g_dbus_method_invocation_return_value (invocation, g_variant_new ("(b)", TRUE));
816
else if (strcmp (method_name, "Suspend") == 0)
818
check_status ("UPOWER SUSPEND");
819
g_dbus_method_invocation_return_value (invocation, g_variant_new ("()"));
821
else if (strcmp (method_name, "HibernateAllowed") == 0)
823
check_status ("UPOWER HIBERNATE-ALLOWED");
824
g_dbus_method_invocation_return_value (invocation, g_variant_new ("(b)", TRUE));
826
else if (strcmp (method_name, "Hibernate") == 0)
828
check_status ("UPOWER HIBERNATE");
829
g_dbus_method_invocation_return_value (invocation, g_variant_new ("()"));
832
g_dbus_method_invocation_return_error (invocation, G_DBUS_ERROR, G_DBUS_ERROR_FAILED, "No such method: %s", method_name);
836
upower_name_acquired_cb (GDBusConnection *connection,
840
const gchar *upower_interface =
842
" <interface name='org.freedesktop.UPower'>"
843
" <method name='SuspendAllowed'>"
844
" <arg name='allowed' direction='out' type='b'/>"
846
" <method name='Suspend'/>"
847
" <method name='HibernateAllowed'>"
848
" <arg name='allowed' direction='out' type='b'/>"
850
" <method name='Hibernate'/>"
853
static const GDBusInterfaceVTable upower_vtable =
857
GDBusNodeInfo *upower_info;
858
GError *error = NULL;
860
upower_info = g_dbus_node_info_new_for_xml (upower_interface, &error);
862
g_warning ("Failed to parse D-Bus interface: %s", error->message);
863
g_clear_error (&error);
866
g_dbus_connection_register_object (connection,
867
"/org/freedesktop/UPower",
868
upower_info->interfaces[0],
873
g_warning ("Failed to register UPower service: %s", error->message);
874
g_clear_error (&error);
875
g_dbus_node_info_unref (upower_info);
878
if (service_count == 0)
883
start_upower_daemon (void)
886
g_bus_own_name (G_BUS_TYPE_SYSTEM,
887
"org.freedesktop.UPower",
888
G_BUS_NAME_OWNER_FLAGS_NONE,
889
upower_name_acquired_cb,
682
896
static CKSession *
683
897
open_ck_session (GVariant *params)
1133
handle_login1_session_call (GDBusConnection *connection,
1134
const gchar *sender,
1135
const gchar *object_path,
1136
const gchar *interface_name,
1137
const gchar *method_name,
1138
GVariant *parameters,
1139
GDBusMethodInvocation *invocation,
1142
Login1Session *session = user_data;
1144
if (strcmp (method_name, "Lock") == 0)
1146
if (!session->locked)
1147
check_status ("LOGIN1 LOCK-SESSION");
1148
session->locked = TRUE;
1149
g_dbus_method_invocation_return_value (invocation, g_variant_new ("()"));
1151
else if (strcmp (method_name, "Unlock") == 0)
1153
if (session->locked)
1154
check_status ("LOGIN1 UNLOCK-SESSION");
1155
session->locked = FALSE;
1156
g_dbus_method_invocation_return_value (invocation, g_variant_new ("()"));
1159
g_dbus_method_invocation_return_error (invocation, G_DBUS_ERROR, G_DBUS_ERROR_FAILED, "No such method: %s", method_name);
1162
static Login1Session *
1163
open_login1_session (GDBusConnection *connection,
1166
Login1Session *session;
1167
GError *error = NULL;
1168
GDBusNodeInfo *login1_session_info;
1170
const gchar *login1_session_interface =
1172
" <interface name='org.freedesktop.login1.Session'>"
1173
" <method name='Lock'/>"
1174
" <method name='Unlock'/>"
1177
static const GDBusInterfaceVTable login1_session_vtable =
1179
handle_login1_session_call,
1182
session = g_malloc0 (sizeof (Login1Session));
1183
login1_sessions = g_list_append (login1_sessions, session);
1185
session->path = g_strdup_printf("/org/freedesktop/login1/Session/c%d",
1186
login1_session_index++);
1190
login1_session_info = g_dbus_node_info_new_for_xml (login1_session_interface,
1193
g_warning ("Failed to parse login1 session D-Bus interface: %s",
1195
g_clear_error (&error);
1196
if (!login1_session_info)
1199
g_dbus_connection_register_object (connection,
1201
login1_session_info->interfaces[0],
1202
&login1_session_vtable,
1207
g_warning ("Failed to register login1 session: %s", error->message);
1208
g_clear_error (&error);
1209
g_dbus_node_info_unref (login1_session_info);
1216
handle_login1_call (GDBusConnection *connection,
1217
const gchar *sender,
1218
const gchar *object_path,
1219
const gchar *interface_name,
1220
const gchar *method_name,
1221
GVariant *parameters,
1222
GDBusMethodInvocation *invocation,
1226
if (strcmp (method_name, "GetSessionByPID") == 0)
1228
/* Look for a session with our PID, and create one if we don't have one
1232
Login1Session *ret = NULL;
1234
g_variant_get (parameters, "(u)", &pid);
1236
for (link = login1_sessions; link; link = link->next)
1238
Login1Session *session;
1239
session = link->data;
1240
if (session->pid == pid)
1248
ret = open_login1_session (connection, parameters);
1250
g_dbus_method_invocation_return_value (invocation,
1251
g_variant_new("(o)", ret->path));
1254
else if (strcmp (method_name, "CanReboot") == 0)
1256
check_status ("LOGIN1 CAN-REBOOT");
1257
g_dbus_method_invocation_return_value (invocation, g_variant_new ("(s)", "yes"));
1259
else if (strcmp (method_name, "Reboot") == 0)
1261
gboolean interactive;
1262
g_variant_get (parameters, "(b)", &interactive);
1263
check_status ("LOGIN1 REBOOT");
1264
g_dbus_method_invocation_return_value (invocation, g_variant_new ("()"));
1266
else if (strcmp (method_name, "CanPowerOff") == 0)
1268
check_status ("LOGIN1 CAN-POWER-OFF");
1269
g_dbus_method_invocation_return_value (invocation, g_variant_new ("(s)", "yes"));
1271
else if (strcmp (method_name, "Suspend") == 0)
1273
gboolean interactive;
1274
g_variant_get (parameters, "(b)", &interactive);
1275
check_status ("LOGIN1 SUSPEND");
1276
g_dbus_method_invocation_return_value (invocation, g_variant_new ("()"));
1278
else if (strcmp (method_name, "CanSuspend") == 0)
1280
check_status ("LOGIN1 CAN-SUSPEND");
1281
g_dbus_method_invocation_return_value (invocation, g_variant_new ("(s)", "yes"));
1283
else if (strcmp (method_name, "PowerOff") == 0)
1285
gboolean interactive;
1286
g_variant_get (parameters, "(b)", &interactive);
1287
check_status ("LOGIN1 POWER-OFF");
1288
g_dbus_method_invocation_return_value (invocation, g_variant_new ("()"));
1290
else if (strcmp (method_name, "CanHibernate") == 0)
1292
check_status ("LOGIN1 CAN-HIBERNATE");
1293
g_dbus_method_invocation_return_value (invocation, g_variant_new ("(s)", "yes"));
1295
else if (strcmp (method_name, "Hibernate") == 0)
1297
gboolean interactive;
1298
g_variant_get (parameters, "(b)", &interactive);
1299
check_status ("LOGIN1 HIBERNATE");
1300
g_dbus_method_invocation_return_value (invocation, g_variant_new ("()"));
1303
g_dbus_method_invocation_return_error (invocation, G_DBUS_ERROR, G_DBUS_ERROR_FAILED, "No such method: %s", method_name);
1307
login1_name_acquired_cb (GDBusConnection *connection,
1311
const gchar *login1_interface =
1313
" <interface name='org.freedesktop.login1.Manager'>"
1314
" <method name='GetSessionByPID'>"
1315
" <arg name='pid' type='u' direction='in'/>"
1316
" <arg name='session' type='o' direction='out'/>"
1318
" <method name='CanReboot'>"
1319
" <arg name='result' direction='out' type='s'/>"
1321
" <method name='Reboot'>"
1322
" <arg name='interactive' direction='in' type='b'/>"
1324
" <method name='CanPowerOff'>"
1325
" <arg name='result' direction='out' type='s'/>"
1327
" <method name='PowerOff'>"
1328
" <arg name='interactive' direction='in' type='b'/>"
1330
" <method name='CanSuspend'>"
1331
" <arg name='result' direction='out' type='s'/>"
1333
" <method name='Suspend'>"
1334
" <arg name='interactive' direction='in' type='b'/>"
1336
" <method name='CanHibernate'>"
1337
" <arg name='result' direction='out' type='s'/>"
1339
" <method name='Hibernate'>"
1340
" <arg name='interactive' direction='in' type='b'/>"
1344
static const GDBusInterfaceVTable login1_vtable =
1348
GDBusNodeInfo *login1_info;
1349
GError *error = NULL;
1351
login1_info = g_dbus_node_info_new_for_xml (login1_interface, &error);
1353
g_warning ("Failed to parse login1 D-Bus interface: %s", error->message);
1354
g_clear_error (&error);
1357
g_dbus_connection_register_object (connection,
1358
"/org/freedesktop/login1",
1359
login1_info->interfaces[0],
1364
g_warning ("Failed to register login1 service: %s", error->message);
1365
g_clear_error (&error);
1366
g_dbus_node_info_unref (login1_info);
1369
if (service_count == 0)
1374
start_login1_daemon (void)
1377
g_bus_own_name (G_BUS_TYPE_SYSTEM,
1378
"org.freedesktop.login1",
1379
G_BUS_NAME_OWNER_FLAGS_NONE,
1380
login1_name_acquired_cb,
1387
static AccountsUser *
1388
get_accounts_user_by_uid (guint uid)
1392
for (link = accounts_users; link; link = link->next)
1394
AccountsUser *u = link->data;
1402
static AccountsUser *
1403
get_accounts_user_by_name (const gchar *username)
1407
for (link = accounts_users; link; link = link->next)
1409
AccountsUser *u = link->data;
1410
if (strcmp (u->user_name, username) == 0)
1418
accounts_user_set_hidden (AccountsUser *user, gboolean hidden, gboolean emit_signal)
1420
GError *error = NULL;
1422
user->hidden = hidden;
1424
if (user->hidden && user->id != 0)
1426
g_dbus_connection_unregister_object (accounts_connection, user->id);
1427
g_dbus_connection_emit_signal (accounts_connection,
1429
"/org/freedesktop/Accounts",
1430
"org.freedesktop.Accounts",
1432
g_variant_new ("(o)", user->path),
1435
g_warning ("Failed to emit UserDeleted: %s", error->message);
1436
g_clear_error (&error);
1440
if (!user->hidden && user->id == 0)
1442
user->id = g_dbus_connection_register_object (accounts_connection,
1444
user_info->interfaces[0],
1450
g_warning ("Failed to register user: %s", error->message);
1451
g_clear_error (&error);
1453
g_dbus_connection_emit_signal (accounts_connection,
1455
"/org/freedesktop/Accounts",
1456
"org.freedesktop.Accounts",
1458
g_variant_new ("(o)", user->path),
1461
g_warning ("Failed to emit UserAdded: %s", error->message);
1462
g_clear_error (&error);
907
1467
load_passwd_file (void)
909
1469
gchar *path, *data, **lines;
1470
gchar **user_filter = NULL;
1473
if (g_key_file_has_key (config, "test-runner-config", "accounts-service-user-filter", NULL))
1477
filter = g_key_file_get_string (config, "test-runner-config", "accounts-service-user-filter", NULL);
1478
user_filter = g_strsplit (filter, " ", -1);
912
1482
path = g_build_filename (g_getenv ("LIGHTDM_TEST_ROOT"), "etc", "passwd", NULL);
913
1483
g_file_get_contents (path, &data, NULL, NULL);