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
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
|
/*
* Copyright 2009 Canonical Ltd.
*
* Authors:
* Cody Russell <crussell@canonical.com>
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 3, as published
* by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranties of
* MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
* PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <dbus/dbus-glib.h>
#include "dbus-shared-names.h"
#include "users-service-dbus.h"
#include "users-service-client.h"
static void users_service_dbus_class_init (UsersServiceDbusClass *klass);
static void users_service_dbus_init (UsersServiceDbus *self);
static void users_service_dbus_dispose (GObject *object);
static void users_service_dbus_finalize (GObject *object);
static gboolean _users_service_server_count_users (UsersServiceDbus *service,
gint *count,
GError **error);
static gboolean _users_service_server_get_user_list (UsersServiceDbus *service,
GArray **list,
GError **error);
static gboolean _users_service_server_get_user_info (UsersServiceDbus *service,
const gint64 uid,
gchar **username,
gchar **real_name,
gchar **shell,
char **icon_url,
GError **error);
static gboolean _users_service_server_get_users_info (UsersServiceDbus *service,
const GArray *uids,
GPtrArray **user_info,
GError **error);
static void users_loaded (DBusGProxy *proxy,
gpointer user_data);
static void user_added (DBusGProxy *proxy,
guint uid,
gpointer user_data);
static void user_removed (DBusGProxy *proxy,
guint uid,
gpointer user_data);
#include "users-service-server.h"
/* Private */
typedef struct _UsersServiceDbusPrivate UsersServiceDbusPrivate;
struct _UsersServiceDbusPrivate
{
GList *users;
gint count;
DBusGConnection *session_bus;
DBusGConnection *system_bus;
DBusGProxy *dbus_proxy_session;
DBusGProxy *dbus_proxy_system;
};
#define USERS_SERVICE_DBUS_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), USERS_SERVICE_DBUS_TYPE, UsersServiceDbusPrivate))
/* Signals */
enum {
USERS_LOADED,
USER_ADDED,
USER_REMOVED,
LAST_SIGNAL
};
static guint signals[LAST_SIGNAL] = { 0 };
/* GObject Boilerplate */
G_DEFINE_TYPE (UsersServiceDbus, users_service_dbus, G_TYPE_OBJECT);
static void
users_service_dbus_class_init (UsersServiceDbusClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
g_type_class_add_private (object_class, sizeof (UsersServiceDbusPrivate));
object_class->dispose = users_service_dbus_dispose;
object_class->finalize = users_service_dbus_finalize;
signals[USERS_LOADED] = g_signal_new ("users-loaded",
G_TYPE_FROM_CLASS (klass),
G_SIGNAL_RUN_LAST,
G_STRUCT_OFFSET (UsersServiceDbusClass, users_loaded),
NULL, NULL,
g_cclosure_marshal_VOID__VOID,
G_TYPE_NONE, 0);
signals[USER_ADDED] = g_signal_new ("user-added",
G_TYPE_FROM_CLASS (klass),
G_SIGNAL_RUN_LAST,
G_STRUCT_OFFSET (UsersServiceDbusClass, user_added),
NULL, NULL,
g_cclosure_marshal_VOID__INT,
G_TYPE_NONE, 1, G_TYPE_INT);
signals[USER_REMOVED] = g_signal_new ("user-removed",
G_TYPE_FROM_CLASS (klass),
G_SIGNAL_RUN_LAST,
G_STRUCT_OFFSET (UsersServiceDbusClass, user_removed),
NULL, NULL,
g_cclosure_marshal_VOID__INT,
G_TYPE_NONE, 1, G_TYPE_INT);
dbus_g_object_type_install_info (USERS_SERVICE_DBUS_TYPE, &dbus_glib__users_service_server_object_info);
}
static void
users_service_dbus_init (UsersServiceDbus *self)
{
GError *error = NULL;
UsersServiceDbusPrivate *priv = USERS_SERVICE_DBUS_GET_PRIVATE (self);
priv->users = NULL;
priv->count = 0;
/* Get the buses */
priv->session_bus = dbus_g_bus_get (DBUS_BUS_SESSION, &error);
if (error != NULL) {
g_error ("Unable to get session bus: %s", error->message);
g_error_free (error);
return;
}
priv->system_bus = dbus_g_bus_get (DBUS_BUS_SYSTEM, &error);
if (error != NULL) {
g_error("Unable to get system bus: %s", error->message);
g_error_free(error);
return;
}
dbus_g_connection_register_g_object (priv->session_bus,
INDICATOR_USERS_SERVICE_DBUS_OBJECT,
G_OBJECT (self));
/* Set up the DBUS service proxies */
priv->dbus_proxy_session = dbus_g_proxy_new_for_name_owner (priv->session_bus,
DBUS_SERVICE_DBUS,
DBUS_PATH_DBUS,
DBUS_INTERFACE_DBUS,
&error);
if (error != NULL) {
g_error ("Unable to get dbus proxy on session bus: %s", error->message);
g_error_free (error);
return;
}
priv->dbus_proxy_system = dbus_g_proxy_new_for_name_owner (priv->system_bus,
DBUS_SERVICE_DBUS,
DBUS_PATH_DBUS,
DBUS_INTERFACE_DBUS,
&error);
if (error != NULL) {
g_error ("Unable to get dbus proxy on system bus: %s", error->message);
g_error_free (error);
return;
}
dbus_g_proxy_connect_signal (priv->dbus_proxy_system,
"UsersLoaded",
G_CALLBACK (users_loaded),
self,
NULL);
dbus_g_proxy_connect_signal (priv->dbus_proxy_system,
"UserAdded",
G_CALLBACK (user_added),
self,
NULL);
dbus_g_proxy_connect_signal (priv->dbus_proxy_system,
"UserRemoved",
G_CALLBACK (user_removed),
self,
NULL);
}
static void
users_service_dbus_dispose (GObject *object)
{
G_OBJECT_CLASS (users_service_dbus_parent_class)->dispose (object);
}
static void
users_service_dbus_finalize (GObject *object)
{
G_OBJECT_CLASS (users_service_dbus_parent_class)->finalize (object);
}
static void
users_loaded (DBusGProxy *proxy,
gpointer user_data)
{
UsersServiceDbus *service;
UsersServiceDbusPrivate *priv;
GError *error = NULL;
GArray *uids;
GPtrArray *users_info;
gint count;
int i;
service = (UsersServiceDbus *)user_data;
priv = USERS_SERVICE_DBUS_GET_PRIVATE (service);
if (!org_gnome_DisplayManager_UserManager_count_users (proxy,
&count,
&error))
{
g_warning ("failed to retrieve user count: %s", error->message);
g_error_free (error);
return;
}
priv->count = count;
if (!org_gnome_DisplayManager_UserManager_get_user_list (proxy,
&uids,
&error))
{
g_warning ("failed to retrieve user list: %s", error->message);
g_error_free (error);
return;
}
if (!org_gnome_DisplayManager_UserManager_get_users_info (proxy,
uids,
&users_info,
&error))
{
g_warning ("failed to retrieve user info: %s", error->message);
g_error_free (error);
return;
}
for (i = 0; i < users_info->len; i++)
{
UserData *data = g_ptr_array_index (users_info, i);
priv->users = g_list_prepend (priv->users, data);
}
}
gint
users_service_dbus_get_user_count (UsersServiceDbus *self)
{
UsersServiceDbusPrivate *priv = USERS_SERVICE_DBUS_GET_PRIVATE (self);
return priv->count;
}
GList *
users_service_dbus_get_user_list (UsersServiceDbus *self)
{
UsersServiceDbusPrivate *priv = USERS_SERVICE_DBUS_GET_PRIVATE (self);
return priv->users;
}
static void
user_added (DBusGProxy *proxy,
guint uid,
gpointer user_data)
{
UsersServiceDbus *service = (UsersServiceDbus *)user_data;
UsersServiceDbusPrivate *priv = USERS_SERVICE_DBUS_GET_PRIVATE (service);
UserData *user = g_new0 (UserData, 1);
GError *error = NULL;
priv->count++;
if (!org_gnome_DisplayManager_UserManager_get_user_info (proxy,
uid,
&user->user_name,
&user->real_name,
&user->shell,
&user->icon_url,
&error))
{
g_warning ("unable to retrieve user info: %s", error->message);
g_error_free (error);
g_free (user);
return;
}
user->uid = uid;
priv->users = g_list_prepend (priv->users, user);
g_signal_emit (G_OBJECT (service), signals[USER_ADDED], 0, user, TRUE);
}
static void
user_removed (DBusGProxy *proxy,
guint uid,
gpointer user_data)
{
UsersServiceDbus *service = (UsersServiceDbus *)user_data;
UsersServiceDbusPrivate *priv = USERS_SERVICE_DBUS_GET_PRIVATE (service);
GList *l;
priv->count--;
for (l = priv->users; l != NULL; l = g_list_next (l))
{
UserData *user = (UserData *)l->data;
if (user->uid == uid)
{
priv->users = g_list_remove (priv->users, l->data);
g_signal_emit (G_OBJECT (service), signals[USER_REMOVED], 0, user, TRUE);
}
}
}
static gboolean
_users_service_server_count_users (UsersServiceDbus *service,
gint *uids,
GError **error)
{
return TRUE;
}
static gboolean
_users_service_server_get_user_list (UsersServiceDbus *service,
GArray **list,
GError **error)
{
return TRUE;
}
static gboolean
_users_service_server_get_user_info (UsersServiceDbus *service,
const gint64 uid,
gchar **username,
gchar **real_name,
gchar **shell,
char **icon_url,
GError **error)
{
return TRUE;
}
static gboolean
_users_service_server_get_users_info (UsersServiceDbus *service,
const GArray *uids,
GPtrArray **user_info,
GError **error)
{
return TRUE;
}
|