summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRay Strode <rstrode@redhat.com>2023-03-15 10:44:05 -0400
committerRay Strode <rstrode@redhat.com>2023-03-15 11:09:35 -0400
commit15e6a4c3a2982bdc6619258af34f13ba0f71046f (patch)
tree58f4f9a9731add436310ada7ef44048d2da17006
parent78794fafaf1d3228a4b0b70c9eea53dba37c9497 (diff)
downloadaccountsservice-15e6a4c3a2982bdc6619258af34f13ba0f71046f.tar.gz
user: Support new LocalAccount property in cache file23.11.69
At the moment an admin can decide whether or not a user is a system account by setting SystemAccount= to true or false in the users cache file, but there's no way to to do the same sort of configuration for deciding whether or not a user is a local account. This commit adds support for a new LocalAccount= key in the cache file. Note, by default this key won't get written into the cache file and instead accountsservice will continue to rely on it's "user is in /etc/shadow" heuristic. The key only gets rewritten into the file during cache file serialization if an admin added it there first. Closes: https://gitlab.freedesktop.org/accountsservice/accountsservice/-/issues/110
-rw-r--r--src/daemon.c10
-rw-r--r--src/user.c19
-rw-r--r--src/user.h1
3 files changed, 30 insertions, 0 deletions
diff --git a/src/daemon.c b/src/daemon.c
index 7a05baf..151f294 100644
--- a/src/daemon.c
+++ b/src/daemon.c
@@ -388,6 +388,16 @@ entry_generator_cachedir (Daemon *daemon,
User *user = value;
user_update_from_cache (user);
+
+ if (user_get_local_account_overridden (user)) {
+ const char *username = user_get_user_name (user);
+
+ if (user_get_local_account (user)) {
+ g_hash_table_add (local_users, g_strdup (username));
+ } else {
+ g_hash_table_remove (local_users, username);
+ }
+ }
}
*state = NULL;
diff --git a/src/user.c b/src/user.c
index 0a8e586..917d427 100644
--- a/src/user.c
+++ b/src/user.c
@@ -73,6 +73,7 @@ struct User
gboolean account_expiration_policy_known;
gboolean cached;
gboolean template_loaded;
+ gboolean local_account_overridden;
guint *extension_ids;
guint n_extension_ids;
@@ -585,6 +586,15 @@ user_update_from_keyfile (User *user,
g_clear_pointer (&s, g_free);
}
+ if (g_key_file_has_key (keyfile, "User", "LocalAccount", NULL)) {
+ gboolean local_account;
+
+ user->local_account_overridden = TRUE;
+
+ local_account = g_key_file_get_boolean (keyfile, "User", "LocalAccount", NULL);
+ accounts_user_set_local_account (ACCOUNTS_USER (user), local_account);
+ }
+
if (g_key_file_has_key (keyfile, "User", "SystemAccount", NULL)) {
gboolean system_account;
@@ -669,6 +679,9 @@ user_save_to_keyfile (User *user,
if (accounts_user_get_icon_file (ACCOUNTS_USER (user)))
g_key_file_set_string (keyfile, "User", "Icon", accounts_user_get_icon_file (ACCOUNTS_USER (user)));
+ if (user->local_account_overridden)
+ g_key_file_set_boolean (keyfile, "User", "LocalAccount", accounts_user_get_local_account (ACCOUNTS_USER (user)));
+
g_key_file_set_boolean (keyfile, "User", "SystemAccount", accounts_user_get_system_account (ACCOUNTS_USER (user)));
user_set_cached (user, TRUE);
@@ -1077,6 +1090,12 @@ user_get_system_account (User *user)
}
gboolean
+user_get_local_account_overridden (User *user)
+{
+ return user->local_account_overridden;
+}
+
+gboolean
user_get_local_account (User *user)
{
return accounts_user_get_local_account (ACCOUNTS_USER (user));
diff --git a/src/user.h b/src/user.h
index 760a4eb..2f4ad8e 100644
--- a/src/user.h
+++ b/src/user.h
@@ -78,6 +78,7 @@ void user_save (User *user);
const gchar * user_get_user_name (User *user);
gboolean user_get_system_account (User *user);
gboolean user_get_local_account (User *user);
+gboolean user_get_local_account_overridden (User *user);
const gchar * user_get_object_path (User *user);
uid_t user_get_uid (User *user);
const gchar * user_get_shell (User *user);