|
|
baf615 |
From 7849fa559cdcc197524135295bdb8e8aa13e2c13 Mon Sep 17 00:00:00 2001
|
|
|
baf615 |
From: Ray Strode <rstrode@redhat.com>
|
|
|
baf615 |
Date: Mon, 2 Oct 2017 16:17:43 -0400
|
|
|
baf615 |
Subject: [PATCH 07/13] lib: use new has-multiple-users property from
|
|
|
baf615 |
accountsservice
|
|
|
baf615 |
|
|
|
baf615 |
This commit changes accountsservice to use the new has-multiple-users
|
|
|
baf615 |
property provided by the daemon.
|
|
|
baf615 |
---
|
|
|
baf615 |
src/libaccountsservice/act-user-manager.c | 27 ++++++++++-----------------
|
|
|
baf615 |
1 file changed, 10 insertions(+), 17 deletions(-)
|
|
|
baf615 |
|
|
|
baf615 |
diff --git a/src/libaccountsservice/act-user-manager.c b/src/libaccountsservice/act-user-manager.c
|
|
|
baf615 |
index ac06e24..30bbd78 100644
|
|
|
baf615 |
--- a/src/libaccountsservice/act-user-manager.c
|
|
|
baf615 |
+++ b/src/libaccountsservice/act-user-manager.c
|
|
|
baf615 |
@@ -856,146 +856,130 @@ add_user (ActUserManager *manager,
|
|
|
baf615 |
{
|
|
|
baf615 |
const char *object_path;
|
|
|
baf615 |
|
|
|
baf615 |
g_debug ("ActUserManager: tracking user '%s'", act_user_get_user_name (user));
|
|
|
baf615 |
if (act_user_is_system_account (user)) {
|
|
|
baf615 |
g_hash_table_insert (manager->priv->system_users_by_name,
|
|
|
baf615 |
g_strdup (act_user_get_user_name (user)),
|
|
|
baf615 |
g_object_ref (user));
|
|
|
baf615 |
} else {
|
|
|
baf615 |
g_hash_table_insert (manager->priv->normal_users_by_name,
|
|
|
baf615 |
g_strdup (act_user_get_user_name (user)),
|
|
|
baf615 |
g_object_ref (user));
|
|
|
baf615 |
}
|
|
|
baf615 |
|
|
|
baf615 |
object_path = act_user_get_object_path (user);
|
|
|
baf615 |
if (object_path != NULL) {
|
|
|
baf615 |
g_hash_table_replace (manager->priv->users_by_object_path,
|
|
|
baf615 |
(gpointer) object_path,
|
|
|
baf615 |
g_object_ref (user));
|
|
|
baf615 |
}
|
|
|
baf615 |
|
|
|
baf615 |
g_signal_connect_object (user,
|
|
|
baf615 |
"sessions-changed",
|
|
|
baf615 |
G_CALLBACK (on_user_sessions_changed),
|
|
|
baf615 |
manager, 0);
|
|
|
baf615 |
g_signal_connect_object (user,
|
|
|
baf615 |
"changed",
|
|
|
baf615 |
G_CALLBACK (on_user_changed),
|
|
|
baf615 |
manager, 0);
|
|
|
baf615 |
|
|
|
baf615 |
- if (g_hash_table_size (manager->priv->normal_users_by_name) > 1) {
|
|
|
baf615 |
- set_has_multiple_users (manager, TRUE);
|
|
|
baf615 |
- }
|
|
|
baf615 |
-
|
|
|
baf615 |
if (manager->priv->is_loaded) {
|
|
|
baf615 |
g_debug ("ActUserManager: loaded, so emitting user-added signal");
|
|
|
baf615 |
g_signal_emit (manager, signals[USER_ADDED], 0, user);
|
|
|
baf615 |
} else {
|
|
|
baf615 |
g_debug ("ActUserManager: not yet loaded, so not emitting user-added signal");
|
|
|
baf615 |
}
|
|
|
baf615 |
}
|
|
|
baf615 |
|
|
|
baf615 |
static void
|
|
|
baf615 |
remove_user (ActUserManager *manager,
|
|
|
baf615 |
ActUser *user)
|
|
|
baf615 |
{
|
|
|
baf615 |
g_debug ("ActUserManager: no longer tracking user '%s' (with object path %s)",
|
|
|
baf615 |
act_user_get_user_name (user),
|
|
|
baf615 |
act_user_get_object_path (user));
|
|
|
baf615 |
|
|
|
baf615 |
g_object_ref (user);
|
|
|
baf615 |
|
|
|
baf615 |
g_signal_handlers_disconnect_by_func (user, on_user_changed, manager);
|
|
|
baf615 |
g_signal_handlers_disconnect_by_func (user, on_user_sessions_changed, manager);
|
|
|
baf615 |
if (act_user_get_object_path (user) != NULL) {
|
|
|
baf615 |
g_hash_table_remove (manager->priv->users_by_object_path, act_user_get_object_path (user));
|
|
|
baf615 |
}
|
|
|
baf615 |
if (act_user_get_user_name (user) != NULL) {
|
|
|
baf615 |
g_hash_table_remove (manager->priv->normal_users_by_name, act_user_get_user_name (user));
|
|
|
baf615 |
g_hash_table_remove (manager->priv->system_users_by_name, act_user_get_user_name (user));
|
|
|
baf615 |
|
|
|
baf615 |
}
|
|
|
baf615 |
|
|
|
baf615 |
- if (g_hash_table_size (manager->priv->normal_users_by_name) <= 1) {
|
|
|
baf615 |
- set_has_multiple_users (manager, FALSE);
|
|
|
baf615 |
- }
|
|
|
baf615 |
-
|
|
|
baf615 |
if (manager->priv->is_loaded) {
|
|
|
baf615 |
g_debug ("ActUserManager: loaded, so emitting user-removed signal");
|
|
|
baf615 |
g_signal_emit (manager, signals[USER_REMOVED], 0, user);
|
|
|
baf615 |
} else {
|
|
|
baf615 |
g_debug ("ActUserManager: not yet loaded, so not emitting user-removed signal");
|
|
|
baf615 |
}
|
|
|
baf615 |
|
|
|
baf615 |
g_debug ("ActUserManager: user '%s' (with object path %s) now removed",
|
|
|
baf615 |
act_user_get_user_name (user),
|
|
|
baf615 |
act_user_get_object_path (user));
|
|
|
baf615 |
g_object_unref (user);
|
|
|
baf615 |
}
|
|
|
baf615 |
|
|
|
baf615 |
static void
|
|
|
baf615 |
update_user (ActUserManager *manager,
|
|
|
baf615 |
ActUser *user)
|
|
|
baf615 |
{
|
|
|
baf615 |
const char *username;
|
|
|
baf615 |
|
|
|
baf615 |
g_debug ("ActUserManager: updating %s", describe_user (user));
|
|
|
baf615 |
|
|
|
baf615 |
username = act_user_get_user_name (user);
|
|
|
baf615 |
if (g_hash_table_lookup (manager->priv->system_users_by_name, username) != NULL) {
|
|
|
baf615 |
if (!act_user_is_system_account (user)) {
|
|
|
baf615 |
g_debug ("ActUserManager: %s is no longer a system account, treating as normal user",
|
|
|
baf615 |
describe_user (user));
|
|
|
baf615 |
g_hash_table_insert (manager->priv->normal_users_by_name,
|
|
|
baf615 |
g_strdup (act_user_get_user_name (user)),
|
|
|
baf615 |
g_object_ref (user));
|
|
|
baf615 |
g_hash_table_remove (manager->priv->system_users_by_name, username);
|
|
|
baf615 |
g_signal_emit (manager, signals[USER_ADDED], 0, user);
|
|
|
baf615 |
-
|
|
|
baf615 |
- if (g_hash_table_size (manager->priv->normal_users_by_name) > 1) {
|
|
|
baf615 |
- set_has_multiple_users (manager, TRUE);
|
|
|
baf615 |
- }
|
|
|
baf615 |
}
|
|
|
baf615 |
} else {
|
|
|
baf615 |
if (act_user_is_system_account (user)) {
|
|
|
baf615 |
g_debug ("ActUserManager: %s is no longer a normal account, treating as system user",
|
|
|
baf615 |
describe_user (user));
|
|
|
baf615 |
g_hash_table_insert (manager->priv->system_users_by_name,
|
|
|
baf615 |
g_strdup (act_user_get_user_name (user)),
|
|
|
baf615 |
g_object_ref (user));
|
|
|
baf615 |
g_hash_table_remove (manager->priv->normal_users_by_name, username);
|
|
|
baf615 |
g_signal_emit (manager, signals[USER_REMOVED], 0, user);
|
|
|
baf615 |
-
|
|
|
baf615 |
- if (g_hash_table_size (manager->priv->normal_users_by_name) <= 1) {
|
|
|
baf615 |
- set_has_multiple_users (manager, FALSE);
|
|
|
baf615 |
- }
|
|
|
baf615 |
}
|
|
|
baf615 |
}
|
|
|
baf615 |
}
|
|
|
baf615 |
|
|
|
baf615 |
static ActUser *
|
|
|
baf615 |
lookup_user_by_name (ActUserManager *manager,
|
|
|
baf615 |
const char *username)
|
|
|
baf615 |
{
|
|
|
baf615 |
ActUser *user;
|
|
|
baf615 |
|
|
|
baf615 |
user = g_hash_table_lookup (manager->priv->normal_users_by_name, username);
|
|
|
baf615 |
|
|
|
baf615 |
if (user == NULL) {
|
|
|
baf615 |
user = g_hash_table_lookup (manager->priv->system_users_by_name, username);
|
|
|
baf615 |
}
|
|
|
baf615 |
|
|
|
baf615 |
return user;
|
|
|
baf615 |
}
|
|
|
baf615 |
|
|
|
baf615 |
static void
|
|
|
baf615 |
on_new_user_loaded (ActUser *user,
|
|
|
baf615 |
GParamSpec *pspec,
|
|
|
baf615 |
ActUserManager *manager)
|
|
|
baf615 |
{
|
|
|
baf615 |
const char *username;
|
|
|
baf615 |
ActUser *old_user;
|
|
|
baf615 |
|
|
|
baf615 |
if (!act_user_is_loaded (user)) {
|
|
|
baf615 |
g_debug ("ActUserManager: %s loaded function called when not loaded",
|
|
|
baf615 |
describe_user (user));
|
|
|
baf615 |
@@ -2682,89 +2666,92 @@ set_include_usernames (ActUserManager *manager,
|
|
|
baf615 |
}
|
|
|
baf615 |
|
|
|
baf615 |
static void
|
|
|
baf615 |
set_exclude_usernames (ActUserManager *manager,
|
|
|
baf615 |
GSList *list)
|
|
|
baf615 |
{
|
|
|
baf615 |
if (manager->priv->exclude_usernames != NULL) {
|
|
|
baf615 |
g_slist_foreach (manager->priv->exclude_usernames, (GFunc) g_free, NULL);
|
|
|
baf615 |
g_slist_free (manager->priv->exclude_usernames);
|
|
|
baf615 |
}
|
|
|
baf615 |
manager->priv->exclude_usernames = slist_deep_copy (list);
|
|
|
baf615 |
}
|
|
|
baf615 |
|
|
|
baf615 |
static void
|
|
|
baf615 |
act_user_manager_set_property (GObject *object,
|
|
|
baf615 |
guint prop_id,
|
|
|
baf615 |
const GValue *value,
|
|
|
baf615 |
GParamSpec *pspec)
|
|
|
baf615 |
{
|
|
|
baf615 |
ActUserManager *self;
|
|
|
baf615 |
|
|
|
baf615 |
self = ACT_USER_MANAGER (object);
|
|
|
baf615 |
|
|
|
baf615 |
switch (prop_id) {
|
|
|
baf615 |
case PROP_INCLUDE_USERNAMES_LIST:
|
|
|
baf615 |
set_include_usernames (self, g_value_get_pointer (value));
|
|
|
baf615 |
break;
|
|
|
baf615 |
case PROP_EXCLUDE_USERNAMES_LIST:
|
|
|
baf615 |
set_exclude_usernames (self, g_value_get_pointer (value));
|
|
|
baf615 |
break;
|
|
|
baf615 |
+ case PROP_HAS_MULTIPLE_USERS:
|
|
|
baf615 |
+ set_has_multiple_users (self, g_value_get_boolean (value));
|
|
|
baf615 |
+ break;
|
|
|
baf615 |
default:
|
|
|
baf615 |
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
|
|
baf615 |
break;
|
|
|
baf615 |
}
|
|
|
baf615 |
}
|
|
|
baf615 |
|
|
|
baf615 |
static void
|
|
|
baf615 |
act_user_manager_class_init (ActUserManagerClass *klass)
|
|
|
baf615 |
{
|
|
|
baf615 |
GObjectClass *object_class = G_OBJECT_CLASS (klass);
|
|
|
baf615 |
|
|
|
baf615 |
object_class->finalize = act_user_manager_finalize;
|
|
|
baf615 |
object_class->get_property = act_user_manager_get_property;
|
|
|
baf615 |
object_class->set_property = act_user_manager_set_property;
|
|
|
baf615 |
|
|
|
baf615 |
g_object_class_install_property (object_class,
|
|
|
baf615 |
PROP_IS_LOADED,
|
|
|
baf615 |
g_param_spec_boolean ("is-loaded",
|
|
|
baf615 |
"Is loaded",
|
|
|
baf615 |
"Determines whether or not the manager object is loaded and ready to read from.",
|
|
|
baf615 |
FALSE,
|
|
|
baf615 |
G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
|
|
|
baf615 |
g_object_class_install_property (object_class,
|
|
|
baf615 |
PROP_HAS_MULTIPLE_USERS,
|
|
|
baf615 |
g_param_spec_boolean ("has-multiple-users",
|
|
|
baf615 |
"Has multiple users",
|
|
|
baf615 |
"Whether more than one normal user is present",
|
|
|
baf615 |
FALSE,
|
|
|
baf615 |
- G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
|
|
|
baf615 |
+ G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
|
|
baf615 |
g_object_class_install_property (object_class,
|
|
|
baf615 |
PROP_INCLUDE_USERNAMES_LIST,
|
|
|
baf615 |
g_param_spec_pointer ("include-usernames-list",
|
|
|
baf615 |
"Include usernames list",
|
|
|
baf615 |
"Usernames who are specifically included",
|
|
|
baf615 |
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
|
|
baf615 |
|
|
|
baf615 |
g_object_class_install_property (object_class,
|
|
|
baf615 |
PROP_EXCLUDE_USERNAMES_LIST,
|
|
|
baf615 |
g_param_spec_pointer ("exclude-usernames-list",
|
|
|
baf615 |
"Exclude usernames list",
|
|
|
baf615 |
"Usernames who are specifically excluded",
|
|
|
baf615 |
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
|
|
baf615 |
|
|
|
baf615 |
/**
|
|
|
baf615 |
* ActUserManager::user-added:
|
|
|
baf615 |
* @gobject: the object which received the signal
|
|
|
baf615 |
* @user: the #ActUser that was added
|
|
|
baf615 |
*
|
|
|
baf615 |
* Emitted when a user is added to the user manager.
|
|
|
baf615 |
*/
|
|
|
baf615 |
signals [USER_ADDED] =
|
|
|
baf615 |
g_signal_new ("user-added",
|
|
|
baf615 |
G_TYPE_FROM_CLASS (klass),
|
|
|
baf615 |
G_SIGNAL_RUN_LAST,
|
|
|
baf615 |
G_STRUCT_OFFSET (ActUserManagerClass, user_added),
|
|
|
baf615 |
NULL, NULL,
|
|
|
baf615 |
g_cclosure_marshal_VOID__OBJECT,
|
|
|
baf615 |
G_TYPE_NONE, 1, ACT_TYPE_USER);
|
|
|
baf615 |
/**
|
|
|
baf615 |
@@ -2865,60 +2852,66 @@ act_user_manager_init (ActUserManager *manager)
|
|
|
baf615 |
|
|
|
baf615 |
error = NULL;
|
|
|
baf615 |
manager->priv->connection = g_bus_get_sync (G_BUS_TYPE_SYSTEM, NULL, &error);
|
|
|
baf615 |
if (manager->priv->connection == NULL) {
|
|
|
baf615 |
if (error != NULL) {
|
|
|
baf615 |
g_warning ("Failed to connect to the D-Bus daemon: %s", error->message);
|
|
|
baf615 |
g_error_free (error);
|
|
|
baf615 |
} else {
|
|
|
baf615 |
g_warning ("Failed to connect to the D-Bus daemon");
|
|
|
baf615 |
}
|
|
|
baf615 |
return;
|
|
|
baf615 |
}
|
|
|
baf615 |
|
|
|
baf615 |
manager->priv->accounts_proxy = accounts_accounts_proxy_new_sync (manager->priv->connection,
|
|
|
baf615 |
G_DBUS_PROXY_FLAGS_NONE,
|
|
|
baf615 |
ACCOUNTS_NAME,
|
|
|
baf615 |
ACCOUNTS_PATH,
|
|
|
baf615 |
NULL,
|
|
|
baf615 |
&error);
|
|
|
baf615 |
if (manager->priv->accounts_proxy == NULL) {
|
|
|
baf615 |
if (error != NULL) {
|
|
|
baf615 |
g_warning ("Failed to create accounts proxy: %s", error->message);
|
|
|
baf615 |
g_error_free (error);
|
|
|
baf615 |
} else {
|
|
|
baf615 |
g_warning ("Failed to create_accounts_proxy");
|
|
|
baf615 |
}
|
|
|
baf615 |
return;
|
|
|
baf615 |
}
|
|
|
baf615 |
g_dbus_proxy_set_default_timeout (G_DBUS_PROXY (manager->priv->accounts_proxy), G_MAXINT);
|
|
|
baf615 |
|
|
|
baf615 |
+ g_object_bind_property (G_OBJECT (manager->priv->accounts_proxy),
|
|
|
baf615 |
+ "has-multiple-users",
|
|
|
baf615 |
+ G_OBJECT (manager),
|
|
|
baf615 |
+ "has-multiple-users",
|
|
|
baf615 |
+ G_BINDING_SYNC_CREATE);
|
|
|
baf615 |
+
|
|
|
baf615 |
g_signal_connect (manager->priv->accounts_proxy,
|
|
|
baf615 |
"user-added",
|
|
|
baf615 |
G_CALLBACK (on_new_user_in_accounts_service),
|
|
|
baf615 |
manager);
|
|
|
baf615 |
g_signal_connect (manager->priv->accounts_proxy,
|
|
|
baf615 |
"user-deleted",
|
|
|
baf615 |
G_CALLBACK (on_user_removed_in_accounts_service),
|
|
|
baf615 |
manager);
|
|
|
baf615 |
|
|
|
baf615 |
manager->priv->seat.state = ACT_USER_MANAGER_SEAT_STATE_UNLOADED;
|
|
|
baf615 |
}
|
|
|
baf615 |
|
|
|
baf615 |
static void
|
|
|
baf615 |
act_user_manager_finalize (GObject *object)
|
|
|
baf615 |
{
|
|
|
baf615 |
ActUserManager *manager;
|
|
|
baf615 |
GSList *node;
|
|
|
baf615 |
|
|
|
baf615 |
g_debug ("ActUserManager: finalizing user manager");
|
|
|
baf615 |
|
|
|
baf615 |
g_return_if_fail (object != NULL);
|
|
|
baf615 |
g_return_if_fail (ACT_IS_USER_MANAGER (object));
|
|
|
baf615 |
|
|
|
baf615 |
manager = ACT_USER_MANAGER (object);
|
|
|
baf615 |
|
|
|
baf615 |
g_return_if_fail (manager->priv != NULL);
|
|
|
baf615 |
|
|
|
baf615 |
g_slist_foreach (manager->priv->new_sessions,
|
|
|
baf615 |
(GFunc) unload_new_session, NULL);
|
|
|
baf615 |
g_slist_free (manager->priv->new_sessions);
|
|
|
baf615 |
--
|
|
|
baf615 |
2.14.1
|
|
|
baf615 |
|