1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
|
diff --git a/src/daemon.c b/src/daemon.c
index ec5cc82..f85050a 100644
--- a/src/daemon.c
+++ b/src/daemon.c
@@ -256,6 +256,13 @@ typedef struct {
GHashTable *logout_hash;
} WTmpGeneratorState;
+static void
+user_previous_login_free (UserPreviousLogin *previous_login)
+{
+ g_free (previous_login->id);
+ g_free (previous_login);
+}
+
static struct passwd *
entry_generator_wtmp (GHashTable *users,
gpointer *state)
@@ -365,11 +372,7 @@ entry_generator_wtmp (GHashTable *users,
user = g_hash_table_lookup (users, key);
if (user == NULL) {
- for (l = accounting->previous_logins; l != NULL; l = l->next) {
- previous_login = l->data;
- g_free (previous_login->id);
- }
- g_list_free (accounting->previous_logins);
+ g_list_free_full (accounting->previous_logins, (GDestroyNotify) user_previous_login_free);
continue;
}
@@ -384,11 +387,10 @@ entry_generator_wtmp (GHashTable *users,
g_variant_builder_add (builder2, "{sv}", "type", g_variant_new_string (previous_login->id));
g_variant_builder_add (builder, "(xxa{sv})", previous_login->login_time, previous_login->logout_time, builder2);
g_variant_builder_unref (builder2);
- g_free (previous_login->id);
}
g_object_set (user, "login-history", g_variant_new ("a(xxa{sv})", builder), NULL);
g_variant_builder_unref (builder);
- g_list_free (accounting->previous_logins);
+ g_list_free_full (accounting->previous_logins, (GDestroyNotify) user_previous_login_free);
user_changed (user);
}
@@ -491,7 +493,7 @@ entry_generator_cachedir (GHashTable *users,
key_file = g_key_file_new ();
if (g_key_file_load_from_file (key_file, filename, 0, NULL))
user_update_from_keyfile (user, key_file);
- g_key_file_free (key_file);
+ g_key_file_unref (key_file);
g_free (filename);
}
diff --git a/src/libaccountsservice/act-user-manager.c b/src/libaccountsservice/act-user-manager.c
index fd660e5..cf2cbfa 100644
--- a/src/libaccountsservice/act-user-manager.c
+++ b/src/libaccountsservice/act-user-manager.c
@@ -1178,6 +1178,28 @@ get_current_session_id (ActUserManager *manager)
return;
}
#endif
+
+ if (manager->priv->ck_manager_proxy == NULL) {
+ GError *error = NULL;
+
+ manager->priv->ck_manager_proxy = console_kit_manager_proxy_new_sync (manager->priv->connection,
+ G_DBUS_PROXY_FLAGS_NONE,
+ CK_NAME,
+ CK_MANAGER_PATH,
+ NULL,
+ &error);
+ if (manager->priv->ck_manager_proxy == NULL) {
+ if (error != NULL) {
+ g_warning ("Failed to create ConsoleKit proxy: %s", error->message);
+ g_error_free (error);
+ } else {
+ g_warning ("Failed to create_ConsoleKit_proxy");
+ }
+ unload_seat (manager);
+ return;
+ }
+ }
+
console_kit_manager_call_get_current_session (manager->priv->ck_manager_proxy, NULL,
on_get_current_session_finished,
g_object_ref (manager));
@@ -1933,12 +1955,13 @@ reload_systemd_sessions (ActUserManager *manager)
}
#endif
-static void
+static gboolean
on_session_monitor_event (GPollableInputStream *stream,
ActUserManager *manager)
{
sd_login_monitor_flush (manager->priv->seat.session_monitor);
reload_systemd_sessions (manager);
+ return TRUE;
}
static void
@@ -2535,9 +2558,13 @@ load_seat_incrementally (ActUserManager *manager)
static gboolean
load_idle (ActUserManager *manager)
{
+ /* The order below is important: load_seat_incrementally might
+ set "is-loaded" immediately and we thus need to call
+ load_users before it.
+ */
+ load_users (manager);
manager->priv->seat.state = ACT_USER_MANAGER_SEAT_STATE_UNLOADED + 1;
load_seat_incrementally (manager);
- load_users (manager);
manager->priv->load_id = 0;
return FALSE;
@@ -2805,22 +2832,6 @@ act_user_manager_init (ActUserManager *manager)
G_CALLBACK (on_user_removed_in_accounts_service),
manager);
- manager->priv->ck_manager_proxy = console_kit_manager_proxy_new_sync (manager->priv->connection,
- G_DBUS_PROXY_FLAGS_NONE,
- CK_NAME,
- CK_MANAGER_PATH,
- NULL,
- &error);
- if (manager->priv->ck_manager_proxy == NULL) {
- if (error != NULL) {
- g_warning ("Failed to create ConsoleKit proxy: %s", error->message);
- g_error_free (error);
- } else {
- g_warning ("Failed to create_ConsoleKit_proxy");
- }
- return;
- }
-
manager->priv->seat.state = ACT_USER_MANAGER_SEAT_STATE_UNLOADED;
}
diff --git a/src/libaccountsservice/act-user.h b/src/libaccountsservice/act-user.h
index 31b2cc6..e2966f4 100644
--- a/src/libaccountsservice/act-user.h
+++ b/src/libaccountsservice/act-user.h
@@ -64,7 +64,9 @@ const char *act_user_get_shell (ActUser *user);
const char *act_user_get_email (ActUser *user);
const char *act_user_get_location (ActUser *user);
guint act_user_get_num_sessions (ActUser *user);
+guint act_user_get_num_sessions_anywhere (ActUser *user);
gboolean act_user_is_logged_in (ActUser *user);
+gboolean act_user_is_logged_in_anywhere (ActUser *user);
int act_user_get_login_frequency (ActUser *user);
gint64 act_user_get_login_time (ActUser *user);
const GVariant*act_user_get_login_history (ActUser *user);
diff --git a/src/user.c b/src/user.c
index 5271b63..661067a 100644
--- a/src/user.c
+++ b/src/user.c
@@ -78,6 +78,8 @@ struct User {
Daemon *daemon;
+ GKeyFile *keyfile;
+
uid_t uid;
gid_t gid;
gchar *user_name;
@@ -360,6 +362,9 @@ user_update_from_keyfile (User *user,
}
}
+ g_clear_pointer (&user->keyfile, g_key_file_unref);
+ user->keyfile = g_key_file_ref (keyfile);
+
g_object_thaw_notify (G_OBJECT (user));
}
@@ -387,6 +392,8 @@ static void
user_save_to_keyfile (User *user,
GKeyFile *keyfile)
{
+ g_key_file_remove_group (keyfile, "User", NULL);
+
if (user->email)
g_key_file_set_string (keyfile, "User", "Email", user->email);
@@ -412,15 +419,13 @@ static void
save_extra_data (User *user)
{
gchar *filename;
- GKeyFile *keyfile;
gchar *data;
GError *error;
- keyfile = g_key_file_new ();
- user_save_to_keyfile (user, keyfile);
+ user_save_to_keyfile (user, user->keyfile);
error = NULL;
- data = g_key_file_to_data (keyfile, NULL, &error);
+ data = g_key_file_to_data (user->keyfile, NULL, &error);
if (error == NULL) {
filename = g_build_filename (USERDIR,
user->user_name,
@@ -433,7 +438,6 @@ save_extra_data (User *user)
user->user_name, error->message);
g_error_free (error);
}
- g_key_file_free (keyfile);
}
static void
@@ -1816,6 +1820,8 @@ user_finalize (GObject *object)
user = USER (object);
+ g_clear_pointer (&user->keyfile, g_key_file_unref);
+
g_free (user->object_path);
g_free (user->user_name);
g_free (user->real_name);
@@ -1829,6 +1835,9 @@ user_finalize (GObject *object)
g_free (user->location);
g_free (user->password_hint);
+ if (user->login_history)
+ g_variant_unref (user->login_history);
+
if (G_OBJECT_CLASS (user_parent_class)->finalize)
(*G_OBJECT_CLASS (user_parent_class)->finalize) (object);
}
@@ -1861,6 +1870,8 @@ user_set_property (GObject *object,
user->login_time = g_value_get_int64 (value);
break;
case PROP_LOGIN_HISTORY:
+ if (user->login_history)
+ g_variant_unref (user->login_history);
user->login_history = g_variant_ref (g_value_get_variant (value));
break;
case PROP_AUTOMATIC_LOGIN:
@@ -2031,4 +2042,5 @@ user_init (User *user)
user->automatic_login = FALSE;
user->system_account = FALSE;
user->login_history = NULL;
+ user->keyfile = g_key_file_new ();
}
|