Blame SOURCES/0001-lib-save-os-when-creating-user.patch

ece282
From 4ff9bc526fec4be51f42739b4258529d7e4695a1 Mon Sep 17 00:00:00 2001
ece282
From: Ray Strode <rstrode@redhat.com>
ece282
Date: Fri, 12 Oct 2018 15:53:52 -0400
ece282
Subject: [PATCH] lib: save os when creating user
ece282
ece282
In order to identify that a user has upgraded from rhel 7 to
ece282
rhel 8, we need to know what os they were using when created.
ece282
ece282
This commit saves that information using a red hat specific
ece282
extension to accountsservice.
ece282
---
ece282
 data/Makefile.am                              |  14 +-
ece282
 .../com.redhat.AccountsServiceUser.System.xml |  10 ++
ece282
 src/libaccountsservice/Makefile.am            |  12 +-
ece282
 src/libaccountsservice/act-user-manager.c     | 123 ++++++++++++++++++
ece282
 4 files changed, 157 insertions(+), 2 deletions(-)
ece282
 create mode 100644 data/com.redhat.AccountsServiceUser.System.xml
ece282
ece282
diff --git a/data/Makefile.am b/data/Makefile.am
ece282
index 521c6c2..a441452 100644
ece282
--- a/data/Makefile.am
ece282
+++ b/data/Makefile.am
ece282
@@ -1,44 +1,56 @@
ece282
 
ece282
 dbusifdir   = $(datadir)/dbus-1/interfaces
ece282
 dbusif_DATA = \
ece282
 	org.freedesktop.Accounts.xml 		\
ece282
-	org.freedesktop.Accounts.User.xml
ece282
+	org.freedesktop.Accounts.User.xml	\
ece282
+	com.redhat.AccountsServiceUser.System.xml
ece282
 
ece282
 dbusconfdir   = $(sysconfdir)/dbus-1/system.d
ece282
 dbusconf_DATA = org.freedesktop.Accounts.conf
ece282
 
ece282
+accountsserviceifdir = $(datadir)/accountsservice/interfaces
ece282
+
ece282
 servicedir       = $(datadir)/dbus-1/system-services
ece282
 service_in_files = org.freedesktop.Accounts.service.in
ece282
 service_DATA     = $(service_in_files:.service.in=.service)
ece282
 
ece282
 $(service_DATA): $(service_in_files) Makefile
ece282
 	@sed -e "s|\@libexecdir\@|$(libexecdir)|" $< >$@
ece282
 
ece282
 policydir       = $(datadir)/polkit-1/actions
ece282
 policy_in_files = org.freedesktop.accounts.policy.in
ece282
 policy_DATA     = $(policy_in_files:.policy.in=.policy)
ece282
 
ece282
 @INTLTOOL_POLICY_RULE@
ece282
 
ece282
 if HAVE_SYSTEMD
ece282
 systemdsystemunit_DATA = \
ece282
 	accounts-daemon.service
ece282
 
ece282
 accounts-daemon.service: accounts-daemon.service.in
ece282
 	@sed -e "s|\@libexecdir\@|$(libexecdir)|" $< >$@
ece282
 
ece282
 endif
ece282
 
ece282
 EXTRA_DIST = 			\
ece282
 	$(dbusif_DATA)		\
ece282
 	$(dbusconf_DATA)	\
ece282
 	$(service_in_files)	\
ece282
 	$(policy_in_files)      \
ece282
 	accounts-daemon.service.in
ece282
 
ece282
 DISTCLEANFILES = 		\
ece282
 	$(service_DATA)		\
ece282
 	$(policy_DATA)
ece282
 
ece282
 CLEANFILES = \
ece282
 	accounts-daemon.service
ece282
+
ece282
+install-data-hook: com.redhat.AccountsServiceUser.System.xml
ece282
+	if test '!' -d $(DESTDIR)$(accountsserviceifdir); then \
ece282
+	        $(mkinstalldirs) $(DESTDIR)$(accountsserviceifdir); \
ece282
+	        chmod 755 $(DESTDIR)$(accountsserviceifdir); \
ece282
+	fi
ece282
+	if test '!' -L $(DESTDIR)$(accountsserviceifdir)/com.redhat.AccountsServiceUser.System.xml; then \
ece282
+	        (cd $(DESTDIR)$(accountsserviceifdir); $(LN_S) ../../dbus-1/interfaces/com.redhat.AccountsServiceUser.System.xml) \
ece282
+	fi
ece282
diff --git a/data/com.redhat.AccountsServiceUser.System.xml b/data/com.redhat.AccountsServiceUser.System.xml
ece282
new file mode 100644
ece282
index 0000000..67f5f30
ece282
--- /dev/null
ece282
+++ b/data/com.redhat.AccountsServiceUser.System.xml
ece282
@@ -0,0 +1,10 @@
ece282
+<node>
ece282
+  <interface name="com.redhat.AccountsServiceUser.System">
ece282
+
ece282
+    <annotation name="org.freedesktop.Accounts.VendorExtension" value="true"/>
ece282
+
ece282
+    <property name="id" type="s" access="readwrite"/>
ece282
+    <property name="version-id" type="s" access="readwrite"/>
ece282
+
ece282
+  </interface>
ece282
+</node>
ece282
diff --git a/src/libaccountsservice/Makefile.am b/src/libaccountsservice/Makefile.am
ece282
index 408d91f..d711d65 100644
ece282
--- a/src/libaccountsservice/Makefile.am
ece282
+++ b/src/libaccountsservice/Makefile.am
ece282
@@ -20,69 +20,79 @@ act-user-enum-types.h: act-user.h act-user-manager.h
ece282
 	$(AM_V_GEN) (cd $(srcdir) && \
ece282
 	         glib-mkenums \
ece282
 	          --fhead "#ifndef __ACT_USER_ENUM_TYPES_H__\n#define __ACT_USER_ENUM_TYPES_H__\n\n#include <glib-object.h>\n\nG_BEGIN_DECLS\n" \
ece282
 	          --fprod "/* enumerations from \"@filename@\" */\n" \
ece282
 	          --vhead "GType @enum_name@_get_type (void);\n#define ACT_USER_TYPE_@ENUMSHORT@ (@enum_name@_get_type())\n"    \
ece282
 	          --ftail "G_END_DECLS\n\n#endif /* __ACT_USER_ENUM_TYPES_H__ */" \
ece282
 	          $(^F) ) > $@
ece282
 
ece282
 act-user-enum-types.c: act-user.h act-user-manager.h act-user-enum-types.h
ece282
 	$(AM_V_GEN) (cd $(srcdir) && \
ece282
 	         glib-mkenums \
ece282
 	          --fhead "#include \"act-user.h\"\n" \
ece282
 	          --fhead "#include \"act-user-manager.h\"\n" \
ece282
 	          --fhead "#include \"act-user-enum-types.h\"\n" \
ece282
 	          --fhead "#include <glib-object.h>" \
ece282
 	          --fprod "\n/* enumerations from \"@filename@\" */" \
ece282
 	          --vhead "GType\n@enum_name@_get_type (void)\n{\n  static GType etype = 0;\n  if (etype == 0) {\n    static const G@Type@Value values[] = {"    \
ece282
 	          --vprod "      { @VALUENAME@, \"@VALUENAME@\", \"@valuenick@\" }," \
ece282
 	          --vtail "      { 0, NULL, NULL }\n    };\n    etype = g_@type@_register_static (\"@EnumName@\", values);\n  }\n  return etype;\n}\n" \
ece282
 	         $(^F) ) > $@
ece282
 
ece282
 ck-manager-generated.c ck-manager-generated.h: org.freedesktop.ConsoleKit.Manager.xml Makefile
ece282
 	$(AM_V_GEN) gdbus-codegen --generate-c-code ck-manager-generated --c-namespace ConsoleKit --interface-prefix=org.freedesktop.ConsoleKit $(srcdir)/org.freedesktop.ConsoleKit.Manager.xml
ece282
 
ece282
 ck-seat-generated.c ck-seat-generated.h: org.freedesktop.ConsoleKit.Seat.xml Makefile
ece282
 	$(AM_V_GEN) gdbus-codegen --generate-c-code ck-seat-generated --c-namespace ConsoleKit --interface-prefix=org.freedesktop.ConsoleKit $(srcdir)/org.freedesktop.ConsoleKit.Seat.xml
ece282
 
ece282
 ck-session-generated.c ck-session-generated.h: org.freedesktop.ConsoleKit.Session.xml Makefile
ece282
 	$(AM_V_GEN) gdbus-codegen --generate-c-code ck-session-generated --c-namespace ConsoleKit --interface-prefix=org.freedesktop.ConsoleKit $(srcdir)/org.freedesktop.ConsoleKit.Session.xml
ece282
 
ece282
+com.redhat.AccountsServiceUser.System.c com.redhat.AccountsServiceUser.System.h: $(top_srcdir)/data/com.redhat.AccountsServiceUser.System.xml Makefile
ece282
+	$(AM_V_GEN)gdbus-codegen                                        \
ece282
+	        --c-namespace=Act                                       \
ece282
+	        --interface-prefix=com.redhat.AccountsService           \
ece282
+	        --generate-c-code=com.redhat.AccountsServiceUser.System \
ece282
+	        $(top_srcdir)/data/com.redhat.AccountsServiceUser.System.xml
ece282
+
ece282
+
ece282
 BUILT_SOURCES += \
ece282
 	act-user-enum-types.c	\
ece282
 	act-user-enum-types.h	\
ece282
 	ck-manager-generated.c		\
ece282
 	ck-manager-generated.h		\
ece282
 	ck-seat-generated.c			\
ece282
 	ck-seat-generated.h			\
ece282
 	ck-session-generated.c		\
ece282
-	ck-session-generated.h
ece282
+	ck-session-generated.h	\
ece282
+	com.redhat.AccountsServiceUser.System.h \
ece282
+	com.redhat.AccountsServiceUser.System.c
ece282
 
ece282
 CLEANFILES += $(BUILT_SOURCES)
ece282
 
ece282
 libaccountsservicedir = $(includedir)/accountsservice-1.0/act
ece282
 libaccountsservice_headers =                                                  \
ece282
         act-user.h                                                            \
ece282
         act-user-manager.h                                                    \
ece282
         act-user-enum-types.h                                                 \
ece282
         $(END_OF_LIST)
ece282
 
ece282
 libaccountsservice_HEADERS =                                                  \
ece282
         act.h                                                                 \
ece282
         $(libaccountsservice_headers)                                         \
ece282
         $(END_OF_LIST)
ece282
 
ece282
 
ece282
 libaccountsservice_la_CFLAGS = $(LIBACCOUNTSSERVICE_CFLAGS)
ece282
 libaccountsservice_la_LDFLAGS =                                               \
ece282
         -export-symbols-regex '^[^_].*'                                       \
ece282
         -version-info $(LT_CURRENT):$(LT_REVISION):$(LT_AGE)                  \
ece282
         -no-undefined                                                         \
ece282
         $(END_OF_LIST)
ece282
 
ece282
 libaccountsservice_la_LIBADD =                                                \
ece282
 	../libaccounts-generated.la						\
ece282
         $(LIBACCOUNTSSERVICE_LIBS)                                            \
ece282
         -lcrypt                                                               \
ece282
         $(END_OF_LIST)
ece282
 
ece282
 libaccountsservice_la_sources =                                               \
ece282
diff --git a/src/libaccountsservice/act-user-manager.c b/src/libaccountsservice/act-user-manager.c
ece282
index 325421b..091b46a 100644
ece282
--- a/src/libaccountsservice/act-user-manager.c
ece282
+++ b/src/libaccountsservice/act-user-manager.c
ece282
@@ -27,60 +27,61 @@
ece282
 #include <string.h>
ece282
 #include <signal.h>
ece282
 #include <errno.h>
ece282
 #include <sys/stat.h>
ece282
 #include <sys/types.h>
ece282
 
ece282
 #ifdef HAVE_PATHS_H
ece282
 #include <paths.h>
ece282
 #endif /* HAVE_PATHS_H */
ece282
 
ece282
 #include <glib.h>
ece282
 #include <glib/gi18n-lib.h>
ece282
 #include <glib/gstdio.h>
ece282
 #include <glib-object.h>
ece282
 #include <gio/gio.h>
ece282
 #include <gio/gunixinputstream.h>
ece282
 
ece282
 #ifdef WITH_SYSTEMD
ece282
 #include <systemd/sd-login.h>
ece282
 
ece282
 /* check if logind is running */
ece282
 #define LOGIND_RUNNING() (access("/run/systemd/seats/", F_OK) >= 0)
ece282
 #endif
ece282
 
ece282
 #include "act-user-manager.h"
ece282
 #include "act-user-private.h"
ece282
 #include "accounts-generated.h"
ece282
 #include "ck-manager-generated.h"
ece282
 #include "ck-seat-generated.h"
ece282
 #include "ck-session-generated.h"
ece282
+#include "com.redhat.AccountsServiceUser.System.h"
ece282
 
ece282
 /**
ece282
  * SECTION:act-user-manager
ece282
  * @title: ActUserManager
ece282
  * @short_description: manages ActUser objects
ece282
  *
ece282
  * ActUserManager is a manager object that gives access to user
ece282
  * creation, deletion, enumeration, etc.
ece282
  *
ece282
  * There is typically a singleton ActUserManager object, which
ece282
  * can be obtained by act_user_manager_get_default().
ece282
  */
ece282
 
ece282
 /**
ece282
  * ActUserManager:
ece282
  *
ece282
  * A user manager object.
ece282
  */
ece282
 
ece282
 /**
ece282
  * ACT_USER_MANAGER_ERROR:
ece282
  *
ece282
  * The GError domain for #ActUserManagerError errors
ece282
  */
ece282
 
ece282
 /**
ece282
  * ActUserManagerError:
ece282
  * @ACT_USER_MANAGER_ERROR_FAILED: Generic failure
ece282
  * @ACT_USER_MANAGER_ERROR_USER_EXISTS: The user already exists
ece282
  * @ACT_USER_MANAGER_ERROR_USER_DOES_NOT_EXIST: The user does not exist
ece282
@@ -167,60 +168,63 @@ typedef struct
ece282
         ActUser                    *user;
ece282
         ActUserManagerFetchUserRequestType type;
ece282
         union {
ece282
                 char               *username;
ece282
                 uid_t               uid;
ece282
         };
ece282
         char                       *object_path;
ece282
         char                       *description;
ece282
 } ActUserManagerFetchUserRequest;
ece282
 
ece282
 struct ActUserManagerPrivate
ece282
 {
ece282
         GHashTable            *normal_users_by_name;
ece282
         GHashTable            *system_users_by_name;
ece282
         GHashTable            *users_by_object_path;
ece282
         GHashTable            *sessions;
ece282
         GDBusConnection       *connection;
ece282
         AccountsAccounts      *accounts_proxy;
ece282
         ConsoleKitManager     *ck_manager_proxy;
ece282
 
ece282
         ActUserManagerSeat     seat;
ece282
 
ece282
         GSList                *new_sessions;
ece282
         GSList                *new_users;
ece282
         GSList                *new_users_inhibiting_load;
ece282
         GSList                *fetch_user_requests;
ece282
 
ece282
         GSList                *exclude_usernames;
ece282
         GSList                *include_usernames;
ece282
 
ece282
+        char                  *os_id;
ece282
+        char                  *os_version_id;
ece282
+
ece282
         guint                  load_id;
ece282
 
ece282
         gboolean               is_loaded;
ece282
         gboolean               has_multiple_users;
ece282
         gboolean               getting_sessions;
ece282
         gboolean               list_cached_users_done;
ece282
 };
ece282
 
ece282
 enum {
ece282
         PROP_0,
ece282
         PROP_INCLUDE_USERNAMES_LIST,
ece282
         PROP_EXCLUDE_USERNAMES_LIST,
ece282
         PROP_IS_LOADED,
ece282
         PROP_HAS_MULTIPLE_USERS
ece282
 };
ece282
 
ece282
 enum {
ece282
         USER_ADDED,
ece282
         USER_REMOVED,
ece282
         USER_IS_LOGGED_IN_CHANGED,
ece282
         USER_CHANGED,
ece282
         LAST_SIGNAL
ece282
 };
ece282
 
ece282
 static guint signals [LAST_SIGNAL] = { 0, };
ece282
 
ece282
 static void     act_user_manager_class_init (ActUserManagerClass *klass);
ece282
 static void     act_user_manager_init       (ActUserManager      *user_manager);
ece282
 static void     act_user_manager_finalize   (GObject             *object);
ece282
 
ece282
@@ -2763,101 +2767,174 @@ ensure_accounts_proxy (ActUserManager *manager)
ece282
                                                                           G_DBUS_PROXY_FLAGS_NONE,
ece282
                                                                           ACCOUNTS_NAME,
ece282
                                                                           ACCOUNTS_PATH,
ece282
                                                                           NULL,
ece282
                                                                           &error);
ece282
         if (error != NULL) {
ece282
                 g_debug ("ActUserManager: getting account proxy failed: %s", error->message);
ece282
                 return FALSE;
ece282
         }
ece282
 
ece282
         g_dbus_proxy_set_default_timeout (G_DBUS_PROXY (manager->priv->accounts_proxy), G_MAXINT);
ece282
 
ece282
         g_object_bind_property (G_OBJECT (manager->priv->accounts_proxy),
ece282
                                 "has-multiple-users",
ece282
                                 G_OBJECT (manager),
ece282
                                 "has-multiple-users",
ece282
                                 G_BINDING_SYNC_CREATE);
ece282
 
ece282
         g_signal_connect (manager->priv->accounts_proxy,
ece282
                           "user-added",
ece282
                           G_CALLBACK (on_new_user_in_accounts_service),
ece282
                           manager);
ece282
         g_signal_connect (manager->priv->accounts_proxy,
ece282
                           "user-deleted",
ece282
                           G_CALLBACK (on_user_removed_in_accounts_service),
ece282
                           manager);
ece282
 
ece282
         return TRUE;
ece282
 }
ece282
 
ece282
+static inline gboolean
ece282
+is_valid_char (gchar    c,
ece282
+               gboolean first)
ece282
+{
ece282
+        return (!first && g_ascii_isdigit (c)) ||
ece282
+                c == '_' ||
ece282
+                g_ascii_isalpha (c);
ece282
+}
ece282
+
ece282
+static void
ece282
+load_os_release (ActUserManager *manager)
ece282
+{
ece282
+        ActUserManagerPrivate *priv = manager->priv;
ece282
+        g_autoptr(GFile) file = NULL;
ece282
+        g_autoptr(GError) error = NULL;
ece282
+        g_autofree char *contents = NULL;
ece282
+        g_auto(GStrv) lines = NULL;
ece282
+        size_t i;
ece282
+
ece282
+        file = g_file_new_for_path ("/etc/os-release");
ece282
+
ece282
+        if (!g_file_load_contents (file, NULL, &contents, NULL, NULL, &error)) {
ece282
+                g_debug ("ActUserManager: couldn't load /etc/os-release: %s", error->message);
ece282
+                return;
ece282
+        }
ece282
+
ece282
+        lines = g_strsplit (contents, "\n", -1);
ece282
+        for (i = 0; lines[i] != NULL; i++) {
ece282
+                char *p, *name, *name_end, *value, *value_end;
ece282
+
ece282
+                p = lines[i];
ece282
+
ece282
+                while (g_ascii_isspace (*p))
ece282
+                        p++;
ece282
+
ece282
+                if (*p == '#' || *p == '\0')
ece282
+                        continue;
ece282
+                name = p;
ece282
+                while (is_valid_char (*p, p == name))
ece282
+                        p++;
ece282
+                name_end = p;
ece282
+                while (g_ascii_isspace (*p))
ece282
+                        p++;
ece282
+                if (name == name_end || *p != '=') {
ece282
+                        continue;
ece282
+                }
ece282
+                *name_end = '\0';
ece282
+
ece282
+                p++;
ece282
+
ece282
+                while (g_ascii_isspace (*p))
ece282
+                        p++;
ece282
+
ece282
+                value = p;
ece282
+                value_end = value + strlen (value) - 1;
ece282
+
ece282
+                if (value != value_end && *value == '"' && *value_end == '"') {
ece282
+                        value++;
ece282
+                        *value_end = '\0';
ece282
+                }
ece282
+
ece282
+                if (strcmp (name, "ID") == 0) {
ece282
+                        g_debug ("ActUserManager: system OS is '%s'", value);
ece282
+                        priv->os_id = g_strdup (value);
ece282
+                } else if (strcmp (name, "VERSION_ID") == 0) {
ece282
+                        g_debug ("ActUserManager: system OS version is '%s'", value);
ece282
+                        priv->os_version_id = g_strdup (value);
ece282
+                }
ece282
+        }
ece282
+}
ece282
+
ece282
 static void
ece282
 act_user_manager_init (ActUserManager *manager)
ece282
 {
ece282
         g_autoptr(GError) error = NULL;
ece282
 
ece282
         manager->priv = ACT_USER_MANAGER_GET_PRIVATE (manager);
ece282
 
ece282
         act_user_manager_error_quark (); /* register dbus errors */
ece282
 
ece282
         /* sessions */
ece282
         manager->priv->sessions = g_hash_table_new_full (g_str_hash,
ece282
                                                          g_str_equal,
ece282
                                                          g_free,
ece282
                                                          g_object_unref);
ece282
 
ece282
         /* users */
ece282
         manager->priv->normal_users_by_name = g_hash_table_new_full (g_str_hash,
ece282
                                                                      g_str_equal,
ece282
                                                                      g_free,
ece282
                                                                      g_object_unref);
ece282
         manager->priv->system_users_by_name = g_hash_table_new_full (g_str_hash,
ece282
                                                                      g_str_equal,
ece282
                                                                      g_free,
ece282
                                                                      g_object_unref);
ece282
         manager->priv->users_by_object_path = g_hash_table_new_full (g_str_hash,
ece282
                                                                      g_str_equal,
ece282
                                                                      NULL,
ece282
                                                                      g_object_unref);
ece282
 
ece282
         manager->priv->connection = g_bus_get_sync (G_BUS_TYPE_SYSTEM, NULL, &error);
ece282
         if (manager->priv->connection == NULL) {
ece282
                 if (error != NULL) {
ece282
                         g_warning ("Failed to connect to the D-Bus daemon: %s", error->message);
ece282
                 } else {
ece282
                         g_warning ("Failed to connect to the D-Bus daemon");
ece282
                 }
ece282
                 return;
ece282
         }
ece282
 
ece282
         ensure_accounts_proxy (manager);
ece282
 
ece282
+        load_os_release (manager);
ece282
+
ece282
         manager->priv->seat.state = ACT_USER_MANAGER_SEAT_STATE_UNLOADED;
ece282
 }
ece282
 
ece282
 static void
ece282
 act_user_manager_finalize (GObject *object)
ece282
 {
ece282
         ActUserManager *manager;
ece282
         GSList         *node;
ece282
 
ece282
         g_debug ("ActUserManager: finalizing user manager");
ece282
 
ece282
         g_return_if_fail (object != NULL);
ece282
         g_return_if_fail (ACT_IS_USER_MANAGER (object));
ece282
 
ece282
         manager = ACT_USER_MANAGER (object);
ece282
 
ece282
         g_return_if_fail (manager->priv != NULL);
ece282
 
ece282
         g_slist_foreach (manager->priv->new_sessions,
ece282
                          (GFunc) unload_new_session, NULL);
ece282
         g_slist_free (manager->priv->new_sessions);
ece282
 
ece282
         g_slist_foreach (manager->priv->fetch_user_requests,
ece282
                          (GFunc) free_fetch_user_request, NULL);
ece282
         g_slist_free (manager->priv->fetch_user_requests);
ece282
 
ece282
         g_slist_free (manager->priv->new_users_inhibiting_load);
ece282
 
ece282
         node = manager->priv->new_users;
ece282
         while (node != NULL) {
ece282
@@ -2899,141 +2976,179 @@ act_user_manager_finalize (GObject *object)
ece282
 
ece282
 #ifdef WITH_SYSTEMD
ece282
         if (manager->priv->seat.session_monitor != NULL) {
ece282
                 sd_login_monitor_unref (manager->priv->seat.session_monitor);
ece282
         }
ece282
 
ece282
         if (manager->priv->seat.session_monitor_stream != NULL) {
ece282
                 g_object_unref (manager->priv->seat.session_monitor_stream);
ece282
         }
ece282
 
ece282
         if (manager->priv->seat.session_monitor_source_id != 0) {
ece282
                 g_source_remove (manager->priv->seat.session_monitor_source_id);
ece282
         }
ece282
 #endif
ece282
 
ece282
         if (manager->priv->accounts_proxy != NULL) {
ece282
                 g_object_unref (manager->priv->accounts_proxy);
ece282
         }
ece282
 
ece282
         if (manager->priv->load_id > 0) {
ece282
                 g_source_remove (manager->priv->load_id);
ece282
                 manager->priv->load_id = 0;
ece282
         }
ece282
 
ece282
         g_hash_table_destroy (manager->priv->sessions);
ece282
 
ece282
         g_hash_table_destroy (manager->priv->normal_users_by_name);
ece282
         g_hash_table_destroy (manager->priv->system_users_by_name);
ece282
         g_hash_table_destroy (manager->priv->users_by_object_path);
ece282
 
ece282
+        g_free (manager->priv->os_id);
ece282
+        g_free (manager->priv->os_version_id);
ece282
+
ece282
         G_OBJECT_CLASS (act_user_manager_parent_class)->finalize (object);
ece282
 }
ece282
 
ece282
 /**
ece282
  * act_user_manager_get_default:
ece282
  *
ece282
  * Returns the user manager singleton instance.  Calling this function will
ece282
  * automatically being loading the user list if it isn't loaded already.
ece282
  * The #ActUserManager:is-loaded property will be set to %TRUE when the users
ece282
  * are finished loading and then act_user_manager_list_users() can be called.
ece282
  *
ece282
  * Returns: (transfer none): user manager object
ece282
  */
ece282
 ActUserManager *
ece282
 act_user_manager_get_default (void)
ece282
 {
ece282
         if (user_manager_object == NULL) {
ece282
                 user_manager_object = g_object_new (ACT_TYPE_USER_MANAGER, NULL);
ece282
                 g_object_add_weak_pointer (user_manager_object,
ece282
                                            (gpointer *) &user_manager_object);
ece282
                 act_user_manager_queue_load (user_manager_object);
ece282
         }
ece282
 
ece282
         return ACT_USER_MANAGER (user_manager_object);
ece282
 }
ece282
 
ece282
 /**
ece282
  * act_user_manager_no_service:
ece282
  * @manager: a #ActUserManager
ece282
  *
ece282
  * Check whether or not the accounts service is running.
ece282
  *
ece282
  * Returns: whether or not accounts service is running
ece282
  */
ece282
 gboolean
ece282
 act_user_manager_no_service (ActUserManager *manager)
ece282
 {
ece282
        return manager->priv->accounts_proxy == NULL;
ece282
 }
ece282
 
ece282
+static void
ece282
+save_system_info (ActUserManager *manager,
ece282
+                  const char     *user_path)
ece282
+{
ece282
+        ActUserManagerPrivate *priv = manager->priv;
ece282
+        ActUserSystem *user_system_proxy = NULL;
ece282
+        g_autoptr(GError) error = NULL;
ece282
+
ece282
+        if (priv->os_id == NULL && priv->os_version_id == NULL)
ece282
+                return;
ece282
+
ece282
+        user_system_proxy = act_user_system_proxy_new_sync (priv->connection,
ece282
+                                                            G_DBUS_PROXY_FLAGS_NONE,
ece282
+                                                            ACCOUNTS_NAME,
ece282
+                                                            user_path,
ece282
+                                                            NULL,
ece282
+                                                            &error);
ece282
+        if (user_system_proxy != NULL) {
ece282
+                if (priv->os_id != NULL)
ece282
+                        act_user_system_set_id (user_system_proxy, priv->os_id);
ece282
+
ece282
+                if (priv->os_version_id != NULL)
ece282
+                        act_user_system_set_version_id (user_system_proxy, priv->os_version_id);
ece282
+        } else {
ece282
+                /* probably means accountsservice and lib are out of sync */
ece282
+                g_debug ("ActUserManager: failed to create user system proxy: %s",
ece282
+                         error? error->message: "");
ece282
+                g_clear_error (&error);
ece282
+        }
ece282
+
ece282
+        g_clear_object (&user_system_proxy);
ece282
+}
ece282
+
ece282
 /**
ece282
  * act_user_manager_create_user:
ece282
  * @manager: a #ActUserManager
ece282
  * @username: a unix user name
ece282
  * @fullname: a unix GECOS value
ece282
  * @accounttype: a #ActUserAccountType
ece282
  * @error: a #GError
ece282
  *
ece282
  * Creates a user account on the system.
ece282
  *
ece282
  * Returns: (transfer full): user object
ece282
  */
ece282
 ActUser *
ece282
 act_user_manager_create_user (ActUserManager      *manager,
ece282
                               const char          *username,
ece282
                               const char          *fullname,
ece282
                               ActUserAccountType   accounttype,
ece282
                               GError             **error)
ece282
 {
ece282
         GError *local_error = NULL;
ece282
         gboolean res;
ece282
         g_autofree gchar *path = NULL;
ece282
         ActUser *user;
ece282
 
ece282
         g_debug ("ActUserManager: Creating user '%s', '%s', %d",
ece282
                  username, fullname, accounttype);
ece282
 
ece282
         g_assert (manager->priv->accounts_proxy != NULL);
ece282
 
ece282
         res = accounts_accounts_call_create_user_sync (manager->priv->accounts_proxy,
ece282
                                                        username,
ece282
                                                        fullname,
ece282
                                                        accounttype,
ece282
                                                        &path,
ece282
                                                        NULL,
ece282
                                                        &local_error);
ece282
         if (!res) {
ece282
                 g_propagate_error (error, local_error);
ece282
                 return NULL;
ece282
         }
ece282
 
ece282
+        save_system_info (manager, path);
ece282
+
ece282
         user = add_new_user_for_object_path (path, manager);
ece282
 
ece282
         return user;
ece282
 }
ece282
 
ece282
 static void
ece282
 act_user_manager_async_complete_handler (GObject      *source,
ece282
                                          GAsyncResult *result,
ece282
                                          gpointer      user_data)
ece282
 {
ece282
         GTask *task = user_data;
ece282
 
ece282
         g_task_return_pointer (task, g_object_ref (result), g_object_unref);
ece282
         g_object_unref (task);
ece282
 }
ece282
 
ece282
 /**
ece282
  * act_user_manager_create_user_async:
ece282
  * @manager: a #ActUserManager
ece282
  * @username: a unix user name
ece282
  * @fullname: a unix GECOS value
ece282
  * @accounttype: a #ActUserAccountType
ece282
  * @cancellable: (allow-none): optional #GCancellable object,
ece282
  *     %NULL to ignore
ece282
  * @callback: (scope async): a #GAsyncReadyCallback to call
ece282
  *     when the request is satisfied
ece282
  * @user_data: (closure): the data to pass to @callback
ece282
  *
ece282
  * Asynchronously creates a user account on the system.
ece282
  *
ece282
@@ -3077,105 +3192,110 @@ act_user_manager_create_user_async (ActUserManager      *manager,
ece282
  * act_user_manager_create_user_finish:
ece282
  * @manager: a #ActUserManager
ece282
  * @result: a #GAsyncResult
ece282
  * @error: a #GError
ece282
  *
ece282
  * Finishes an asynchronous user creation.
ece282
  *
ece282
  * See act_user_manager_create_user_async().
ece282
  *
ece282
  * Returns: (transfer full): user object
ece282
  *
ece282
  * Since: 0.6.27
ece282
  */
ece282
 ActUser *
ece282
 act_user_manager_create_user_finish (ActUserManager  *manager,
ece282
                                      GAsyncResult    *result,
ece282
                                      GError         **error)
ece282
 {
ece282
         GAsyncResult *inner_result;
ece282
         ActUser *user = NULL;
ece282
         g_autofree gchar *path = NULL;
ece282
         GError *remote_error = NULL;
ece282
 
ece282
         inner_result = g_task_propagate_pointer (G_TASK (result), error);
ece282
         if (inner_result == NULL) {
ece282
                 return FALSE;
ece282
         }
ece282
 
ece282
         if (accounts_accounts_call_create_user_finish (manager->priv->accounts_proxy,
ece282
                                                        &path, inner_result, &remote_error)) {
ece282
+
ece282
+                save_system_info (manager, path);
ece282
+
ece282
                 user = add_new_user_for_object_path (path, manager);
ece282
         }
ece282
 
ece282
         if (remote_error) {
ece282
                 g_dbus_error_strip_remote_error (remote_error);
ece282
                 g_propagate_error (error, remote_error);
ece282
         }
ece282
 
ece282
         return user;
ece282
 }
ece282
 
ece282
 /**
ece282
  * act_user_manager_cache_user:
ece282
  * @manager: a #ActUserManager
ece282
  * @username: a user name
ece282
  * @error: a #GError
ece282
  *
ece282
  * Caches a user account so it shows up via act_user_manager_list_users().
ece282
  *
ece282
  * Returns: (transfer full): user object
ece282
  */
ece282
 ActUser *
ece282
 act_user_manager_cache_user (ActUserManager     *manager,
ece282
                              const char         *username,
ece282
                              GError            **error)
ece282
 {
ece282
         GError *local_error = NULL;
ece282
         gboolean res;
ece282
         g_autofree gchar *path = NULL;
ece282
 
ece282
         g_debug ("ActUserManager: Caching user '%s'",
ece282
                  username);
ece282
 
ece282
         g_assert (manager->priv->accounts_proxy != NULL);
ece282
 
ece282
         res = accounts_accounts_call_cache_user_sync (manager->priv->accounts_proxy,
ece282
                                                       username,
ece282
                                                       &path,
ece282
                                                       NULL,
ece282
                                                       &local_error);
ece282
         if (!res) {
ece282
                 g_propagate_error (error, local_error);
ece282
                 return NULL;
ece282
         }
ece282
 
ece282
+        save_system_info (manager, path);
ece282
+
ece282
         return add_new_user_for_object_path (path, manager);
ece282
 }
ece282
 
ece282
 
ece282
 /**
ece282
  * act_user_manager_cache_user_async:
ece282
  * @manager: a #ActUserManager
ece282
  * @username: a unix user name
ece282
  * @cancellable: (allow-none): optional #GCancellable object,
ece282
  *     %NULL to ignore
ece282
  * @callback: (scope async): a #GAsyncReadyCallback to call
ece282
  *     when the request is satisfied
ece282
  * @user_data: (closure): the data to pass to @callback
ece282
  *
ece282
  * Asynchronously caches a user account so it shows up via
ece282
  * act_user_manager_list_users().
ece282
  *
ece282
  * For more details, see act_user_manager_cache_user(), which
ece282
  * is the synchronous version of this call.
ece282
  *
ece282
  * Since: 0.6.27
ece282
  */
ece282
 void
ece282
 act_user_manager_cache_user_async (ActUserManager      *manager,
ece282
                                    const char          *username,
ece282
                                    GCancellable        *cancellable,
ece282
                                    GAsyncReadyCallback  callback,
ece282
                                    gpointer             user_data)
ece282
 {
ece282
         GTask *task;
ece282
@@ -3199,60 +3319,63 @@ act_user_manager_cache_user_async (ActUserManager      *manager,
ece282
  * act_user_manager_cache_user_finish:
ece282
  * @manager: a #ActUserManager
ece282
  * @result: a #GAsyncResult
ece282
  * @error: a #GError
ece282
  *
ece282
  * Finishes an asynchronous user caching.
ece282
  *
ece282
  * See act_user_manager_cache_user_async().
ece282
  *
ece282
  * Returns: (transfer full): user object
ece282
  *
ece282
  * Since: 0.6.27
ece282
  */
ece282
 ActUser *
ece282
 act_user_manager_cache_user_finish (ActUserManager  *manager,
ece282
                                     GAsyncResult    *result,
ece282
                                     GError         **error)
ece282
 {
ece282
         GAsyncResult *inner_result;
ece282
         ActUser *user = NULL;
ece282
         g_autofree gchar *path = NULL;
ece282
         GError *remote_error = NULL;
ece282
 
ece282
         inner_result = g_task_propagate_pointer (G_TASK (result), error);
ece282
         if (inner_result == NULL) {
ece282
                 return FALSE;
ece282
         }
ece282
 
ece282
         if (accounts_accounts_call_cache_user_finish (manager->priv->accounts_proxy,
ece282
                                                       &path, inner_result, &remote_error)) {
ece282
+
ece282
+                save_system_info (manager, path);
ece282
+
ece282
                 user = add_new_user_for_object_path (path, manager);
ece282
         }
ece282
 
ece282
         if (remote_error) {
ece282
                 g_dbus_error_strip_remote_error (remote_error);
ece282
                 g_propagate_error (error, remote_error);
ece282
         }
ece282
 
ece282
         return user;
ece282
 }
ece282
 
ece282
 /**
ece282
  * act_user_manager_uncache_user:
ece282
  * @manager: a #ActUserManager
ece282
  * @username: a user name
ece282
  * @error: a #GError
ece282
  *
ece282
  * Releases all metadata about a user account, including icon,
ece282
  * language and session. If the user account is from a remote
ece282
  * server and the user has never logged in before, then that
ece282
  * account will no longer show up in ListCachedUsers() output.
ece282
  *
ece282
  * Returns: %TRUE if successful, otherwise %FALSE
ece282
  */
ece282
 gboolean
ece282
 act_user_manager_uncache_user (ActUserManager     *manager,
ece282
                                const char         *username,
ece282
                                GError            **error)
ece282
 {
ece282
         GError *local_error = NULL;
ece282
-- 
ece282
2.17.1
ece282