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

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