1
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*-
3
* Copyright (C) 2004-2005 James M. Cape <jcape@ignore-your.tv>.
4
* Copyright (C) 2007-2008 William Jon McCann <mccann@jhu.edu>
6
* This program is free software; you can redistribute it and/or modify
7
* it under the terms of the GNU General Public License as published by
8
* the Free Software Foundation; either version 2 of the License, or
9
* (at your option) any later version.
11
* This program is distributed in the hope that it will be useful,
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
* GNU General Public License for more details.
16
* You should have received a copy of the GNU General Public License
17
* along with this program; if not, write to the Free Software
18
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
25
#include <sys/types.h>
29
#include <dbus/dbus-glib.h>
32
#include <glib/gi18n.h>
35
#include "act-user-private.h"
37
#define ACT_USER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), ACT_TYPE_USER, ActUserClass))
38
#define ACT_IS_USER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), ACT_TYPE_USER))
39
#define ACT_USER_GET_CLASS(object) (G_TYPE_INSTANCE_GET_CLASS ((object), ACT_TYPE_USER, ActUserClass))
41
#define ACCOUNTS_NAME "org.freedesktop.Accounts"
42
#define ACCOUNTS_USER_INTERFACE "org.freedesktop.Accounts.User"
74
DBusGConnection *connection;
75
DBusGProxy *accounts_proxy;
76
DBusGProxy *object_proxy;
77
DBusGProxyCall *get_all_call;
94
ActUserAccountType account_type;
95
ActUserPasswordMode password_mode;
99
guint automatic_login : 1;
104
GObjectClass parent_class;
107
static void act_user_finalize (GObject *object);
109
static guint signals[LAST_SIGNAL] = { 0 };
111
G_DEFINE_TYPE (ActUser, act_user, G_TYPE_OBJECT)
114
session_compare (const char *a,
119
} else if (b == NULL) {
123
return strcmp (a, b);
127
_act_user_add_session (ActUser *user,
132
g_return_if_fail (ACT_IS_USER (user));
133
g_return_if_fail (ssid != NULL);
135
li = g_list_find_custom (user->sessions, ssid, (GCompareFunc)session_compare);
137
g_debug ("ActUser: adding session %s", ssid);
138
user->sessions = g_list_prepend (user->sessions, g_strdup (ssid));
139
g_signal_emit (user, signals[SESSIONS_CHANGED], 0);
141
g_debug ("ActUser: session already present: %s", ssid);
146
_act_user_remove_session (ActUser *user,
151
g_return_if_fail (ACT_IS_USER (user));
152
g_return_if_fail (ssid != NULL);
154
li = g_list_find_custom (user->sessions, ssid, (GCompareFunc)session_compare);
156
g_debug ("ActUser: removing session %s", ssid);
158
user->sessions = g_list_delete_link (user->sessions, li);
159
g_signal_emit (user, signals[SESSIONS_CHANGED], 0);
161
g_debug ("ActUser: session not found: %s", ssid);
166
act_user_get_num_sessions (ActUser *user)
168
return g_list_length (user->sessions);
172
act_user_set_property (GObject *object,
179
user = ACT_USER (object);
183
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
189
act_user_get_property (GObject *object,
196
user = ACT_USER (object);
200
g_value_set_int (value, user->uid);
203
g_value_set_string (value, user->user_name);
206
g_value_set_string (value, user->real_name);
208
case PROP_ACCOUNT_TYPE:
209
g_value_set_int (value, user->account_type);
211
case PROP_PASSWORD_MODE:
212
g_value_set_int (value, user->password_mode);
214
case PROP_PASSWORD_HINT:
215
g_value_set_string (value, user->password_hint);
218
g_value_set_string (value, user->home_dir);
220
case PROP_LOGIN_FREQUENCY:
221
g_value_set_int (value, user->login_frequency);
224
g_value_set_string (value, user->shell);
227
g_value_set_string (value, user->email);
230
g_value_set_string (value, user->location);
233
g_value_set_string (value, user->icon_file);
236
g_value_set_string (value, user->language);
239
g_value_set_string (value, user->x_session);
242
g_value_set_boolean (value, user->locked);
244
case PROP_AUTOMATIC_LOGIN:
245
g_value_set_boolean (value, user->automatic_login);
248
g_value_set_boolean (value, user->is_loaded);
251
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
258
act_user_class_init (ActUserClass *class)
260
GObjectClass *gobject_class;
262
gobject_class = G_OBJECT_CLASS (class);
264
gobject_class->finalize = act_user_finalize;
265
gobject_class->set_property = act_user_set_property;
266
gobject_class->get_property = act_user_get_property;
268
g_object_class_install_property (gobject_class,
270
g_param_spec_string ("real-name",
272
"The real name to display for this user.",
276
g_object_class_install_property (gobject_class,
278
g_param_spec_int ("account-type",
280
"The account type for this user.",
281
ACT_USER_ACCOUNT_TYPE_STANDARD,
282
ACT_USER_ACCOUNT_TYPE_SUPERVISED,
283
ACT_USER_ACCOUNT_TYPE_STANDARD,
285
g_object_class_install_property (gobject_class,
287
g_param_spec_int ("password-mode",
289
"The password mode for this user.",
290
ACT_USER_PASSWORD_MODE_REGULAR,
291
ACT_USER_PASSWORD_MODE_NONE,
292
ACT_USER_PASSWORD_MODE_REGULAR,
295
g_object_class_install_property (gobject_class,
297
g_param_spec_string ("password-hint",
299
"Hint to help this user remember his password",
303
g_object_class_install_property (gobject_class,
305
g_param_spec_int ("uid",
307
"The UID for this user.",
310
g_object_class_install_property (gobject_class,
312
g_param_spec_string ("user-name",
314
"The login name for this user.",
317
g_object_class_install_property (gobject_class,
319
g_param_spec_string ("home-directory",
321
"The home directory for this user.",
324
g_object_class_install_property (gobject_class,
326
g_param_spec_string ("shell",
328
"The shell for this user.",
331
g_object_class_install_property (gobject_class,
333
g_param_spec_string ("email",
335
"The email address for this user.",
338
g_object_class_install_property (gobject_class,
340
g_param_spec_string ("location",
342
"The location of this user.",
345
g_object_class_install_property (gobject_class,
346
PROP_LOGIN_FREQUENCY,
347
g_param_spec_int ("login-frequency",
354
g_object_class_install_property (gobject_class,
356
g_param_spec_string ("icon-file",
358
"The path to an icon for this user.",
361
g_object_class_install_property (gobject_class,
363
g_param_spec_string ("language",
368
g_object_class_install_property (gobject_class,
370
g_param_spec_string ("x-session",
375
g_object_class_install_property (gobject_class,
377
g_param_spec_boolean ("is-loaded",
382
g_object_class_install_property (gobject_class,
384
g_param_spec_boolean ("locked",
390
g_object_class_install_property (gobject_class,
391
PROP_AUTOMATIC_LOGIN,
392
g_param_spec_boolean ("automatic-login",
399
g_signal_new ("changed",
400
G_TYPE_FROM_CLASS (class),
404
g_cclosure_marshal_VOID__VOID,
406
signals [SESSIONS_CHANGED] =
407
g_signal_new ("sessions-changed",
408
G_TYPE_FROM_CLASS (class),
412
g_cclosure_marshal_VOID__VOID,
417
act_user_init (ActUser *user)
421
user->user_name = NULL;
422
user->real_name = NULL;
423
user->sessions = NULL;
426
user->connection = dbus_g_bus_get (DBUS_BUS_SYSTEM, &error);
427
if (user->connection == NULL) {
428
g_warning ("Couldn't connect to system bus: %s", error->message);
433
act_user_finalize (GObject *object)
437
user = ACT_USER (object);
439
g_free (user->user_name);
440
g_free (user->real_name);
441
g_free (user->icon_file);
442
g_free (user->language);
443
g_free (user->object_path);
444
g_free (user->password_hint);
445
g_free (user->home_dir);
446
g_free (user->shell);
447
g_free (user->email);
448
g_free (user->location);
449
g_free (user->language);
451
if (user->accounts_proxy != NULL) {
452
g_object_unref (user->accounts_proxy);
455
if (user->object_proxy != NULL) {
456
g_object_unref (user->object_proxy);
459
if (user->connection != NULL) {
460
dbus_g_connection_unref (user->connection);
463
if (G_OBJECT_CLASS (act_user_parent_class)->finalize)
464
(*G_OBJECT_CLASS (act_user_parent_class)->finalize) (object);
468
set_is_loaded (ActUser *user,
471
if (user->is_loaded != is_loaded) {
472
user->is_loaded = is_loaded;
473
g_object_notify (G_OBJECT (user), "is-loaded");
479
* @user: the user object to examine.
481
* Retrieves the ID of @user.
483
* Returns: (transfer none): a pointer to an array of characters which must not be modified or
488
act_user_get_uid (ActUser *user)
490
g_return_val_if_fail (ACT_IS_USER (user), -1);
496
* act_user_get_real_name:
497
* @user: the user object to examine.
499
* Retrieves the display name of @user.
501
* Returns: (transfer none): a pointer to an array of characters which must not be modified or
505
act_user_get_real_name (ActUser *user)
507
g_return_val_if_fail (ACT_IS_USER (user), NULL);
509
return (user->real_name ? user->real_name : user->user_name);
513
* act_user_get_account_type:
514
* @user: the user object to examine.
516
* Retrieves the account type of @user.
518
* Returns: a #ActUserAccountType
521
act_user_get_account_type (ActUser *user)
523
g_return_val_if_fail (ACT_IS_USER (user), ACT_USER_ACCOUNT_TYPE_STANDARD);
525
return user->account_type;
529
* act_user_get_password_mode:
530
* @user: the user object to examine.
532
* Retrieves the password mode of @user.
534
* Returns: a #ActUserPasswordMode
537
act_user_get_password_mode (ActUser *user)
539
g_return_val_if_fail (ACT_IS_USER (user), ACT_USER_PASSWORD_MODE_REGULAR);
541
return user->password_mode;
545
* act_user_get_password_hint:
546
* @user: the user object to examine.
548
* Retrieves the password hint set by @user.
550
* Returns: (transfer none): a pointer to an array of characters which must not be modified or
554
act_user_get_password_hint (ActUser *user)
556
g_return_val_if_fail (ACT_IS_USER (user), NULL);
558
return user->password_hint;
562
* act_user_get_home_dir:
563
* @user: the user object to examine.
565
* Retrieves the home directory for @user.
567
* Returns: (transfer none): a pointer to an array of characters which must not be modified or
571
act_user_get_home_dir (ActUser *user)
573
g_return_val_if_fail (ACT_IS_USER (user), NULL);
575
return user->home_dir;
579
* act_user_get_shell:
580
* @user: the user object to examine.
582
* Retrieves the shell assigned to @user.
584
* Returns: (transfer none): a pointer to an array of characters which must not be modified or
588
act_user_get_shell (ActUser *user)
590
g_return_val_if_fail (ACT_IS_USER (user), NULL);
596
* act_user_get_email:
597
* @user: the user object to examine.
599
* Retrieves the email address set by @user.
601
* Returns: (transfer none): a pointer to an array of characters which must not be modified or
605
act_user_get_email (ActUser *user)
607
g_return_val_if_fail (ACT_IS_USER (user), NULL);
613
* act_user_get_location:
614
* @user: the user object to examine.
616
* Retrieves the location set by @user.
618
* Returns: (transfer none): a pointer to an array of characters which must not be modified or
622
act_user_get_location (ActUser *user)
624
g_return_val_if_fail (ACT_IS_USER (user), NULL);
626
return user->location;
630
* act_user_get_user_name:
631
* @user: the user object to examine.
633
* Retrieves the login name of @user.
635
* Returns: (transfer none): a pointer to an array of characters which must not be modified or
640
act_user_get_user_name (ActUser *user)
642
g_return_val_if_fail (ACT_IS_USER (user), NULL);
644
return user->user_name;
648
* act_user_get_login_frequency:
651
* Returns the number of times @user has logged in.
653
* Returns: the login frequency
656
act_user_get_login_frequency (ActUser *user)
658
g_return_val_if_fail (ACT_IS_USER (user), 0);
660
return user->login_frequency;
664
act_user_collate (ActUser *user1,
674
g_return_val_if_fail (ACT_IS_USER (user1), 0);
675
g_return_val_if_fail (ACT_IS_USER (user2), 0);
677
num1 = user1->login_frequency;
678
num2 = user2->login_frequency;
689
len1 = g_list_length (user1->sessions);
690
len2 = g_list_length (user2->sessions);
700
/* if login frequency is equal try names */
701
if (user1->real_name != NULL) {
702
str1 = user1->real_name;
704
str1 = user1->user_name;
707
if (user2->real_name != NULL) {
708
str2 = user2->real_name;
710
str2 = user2->user_name;
713
if (str1 == NULL && str2 != NULL) {
717
if (str1 != NULL && str2 == NULL) {
721
if (str1 == NULL && str2 == NULL) {
725
return g_utf8_collate (str1, str2);
729
* act_user_is_logged_in:
732
* Returns whether or not #ActUser is currently logged in.
734
* Returns: %TRUE or %FALSE
737
act_user_is_logged_in (ActUser *user)
739
return user->sessions != NULL;
743
* act_user_get_locked:
746
* Returns whether or not the #ActUser account is locked.
748
* Returns: %TRUE or %FALSE
751
act_user_get_locked (ActUser *user)
753
return user->locked;;
757
* act_user_get_automatic_login:
760
* Returns whether or not #ActUser is automatically logged in at boot time.
762
* Returns: %TRUE or %FALSE
765
act_user_get_automatic_login (ActUser *user)
767
return user->automatic_login;
771
* act_user_get_icon_file:
774
* Returns the path to the account icon belonging to @user.
776
* Returns: (transfer none): a path to an icon
779
act_user_get_icon_file (ActUser *user)
781
g_return_val_if_fail (ACT_IS_USER (user), NULL);
783
return user->icon_file;
787
* act_user_get_language:
790
* Returns the path to the configured locale of @user.
792
* Returns: (transfer none): a path to an icon
795
act_user_get_language (ActUser *user)
797
g_return_val_if_fail (ACT_IS_USER (user), NULL);
799
return user->language;
803
* act_user_get_x_session:
806
* Returns the path to the configured X session for @user.
808
* Returns: (transfer none): a path to an icon
811
act_user_get_x_session (ActUser *user)
813
g_return_val_if_fail (ACT_IS_USER (user), NULL);
815
return user->x_session;
819
* act_user_get_object_path:
822
* Returns the user accounts service object path of @user,
823
* or %NULL if @user doesn't have an object path associated
826
* Returns: (transfer none): the primary ConsoleKit session id of the user
829
act_user_get_object_path (ActUser *user)
831
g_return_val_if_fail (ACT_IS_USER (user), NULL);
833
return user->object_path;
837
* act_user_get_primary_session_id:
840
* Returns the primary ConsoleKit session id of @user, or %NULL if @user isn't
843
* Returns: (transfer none): the primary ConsoleKit session id of the user
846
act_user_get_primary_session_id (ActUser *user)
848
if (!act_user_is_logged_in (user)) {
849
g_debug ("User %s is not logged in, so has no primary session",
850
act_user_get_user_name (user));
854
/* FIXME: better way to choose? */
855
return user->sessions->data;
859
collect_props (const gchar *key,
863
gboolean handled = TRUE;
865
if (strcmp (key, "Uid") == 0) {
868
new_uid = g_value_get_uint64 (value);
869
if ((guint64) user->uid != new_uid) {
870
user->uid = (uid_t) new_uid;
871
g_object_notify (G_OBJECT (user), "uid");
873
} else if (strcmp (key, "UserName") == 0) {
874
const char *new_user_name;
876
new_user_name = g_value_get_string (value);
877
if (g_strcmp0 (user->user_name, new_user_name) != 0) {
878
g_free (user->user_name);
879
user->user_name = g_strdup (new_user_name);
880
g_object_notify (G_OBJECT (user), "user-name");
882
} else if (strcmp (key, "RealName") == 0) {
883
const char *new_real_name;
885
new_real_name = g_value_get_string (value);
886
if (g_strcmp0 (user->real_name, new_real_name) != 0) {
887
g_free (user->real_name);
888
user->real_name = g_strdup (new_real_name);
889
g_object_notify (G_OBJECT (user), "real-name");
891
} else if (strcmp (key, "AccountType") == 0) {
892
int new_account_type;
894
new_account_type = g_value_get_int (value);
895
if ((int) user->account_type != new_account_type) {
896
user->account_type = (ActUserAccountType) new_account_type;
897
g_object_notify (G_OBJECT (user), "account-type");
899
} else if (strcmp (key, "PasswordMode") == 0) {
900
int new_password_mode;
902
new_password_mode = g_value_get_int (value);
903
if ((int) user->password_mode != new_password_mode) {
904
user->password_mode = (ActUserPasswordMode) new_password_mode;
905
g_object_notify (G_OBJECT (user), "password-mode");
907
} else if (strcmp (key, "PasswordHint") == 0) {
908
const char *new_password_hint;
910
new_password_hint = g_value_get_string (value);
911
if (g_strcmp0 (user->password_hint, new_password_hint) != 0) {
912
g_free (user->password_hint);
913
user->password_hint = g_value_dup_string (value);
914
g_object_notify (G_OBJECT (user), "password-hint");
916
} else if (strcmp (key, "HomeDirectory") == 0) {
917
const char *new_home_dir;
919
new_home_dir = g_value_get_string (value);
920
if (g_strcmp0 (user->home_dir, new_home_dir) != 0) {
921
g_free (user->home_dir);
922
user->home_dir = g_strdup (new_home_dir);
923
g_object_notify (G_OBJECT (user), "home-directory");
925
} else if (strcmp (key, "Shell") == 0) {
926
const char *new_shell;
928
new_shell = g_value_get_string (value);
929
if (g_strcmp0 (user->shell, new_shell) != 0) {
930
g_free (user->shell);
931
user->shell = g_strdup (new_shell);
932
g_object_notify (G_OBJECT (user), "shell");
934
} else if (strcmp (key, "Email") == 0) {
935
const char *new_email;
937
new_email = g_value_get_string (value);
938
if (g_strcmp0 (user->email, new_email) != 0) {
939
g_free (user->email);
940
user->email = g_strdup (new_email);
941
g_object_notify (G_OBJECT (user), "email");
943
} else if (strcmp (key, "Location") == 0) {
944
const char *new_location;
946
new_location = g_value_get_string (value);
947
if (g_strcmp0 (user->location, new_location) != 0) {
948
g_free (user->location);
949
user->location = g_strdup (new_location);
950
g_object_notify (G_OBJECT (user), "location");
952
} else if (strcmp (key, "Locked") == 0) {
953
gboolean new_locked_state;
955
new_locked_state = g_value_get_boolean (value);
956
if (new_locked_state != user->locked) {
957
user->locked = new_locked_state;
958
g_object_notify (G_OBJECT (user), "locked");
960
} else if (strcmp (key, "AutomaticLogin") == 0) {
961
gboolean new_automatic_login_state;
963
new_automatic_login_state = g_value_get_boolean (value);
964
if (new_automatic_login_state != user->automatic_login) {
965
user->automatic_login = new_automatic_login_state;
966
g_object_notify (G_OBJECT (user), "automatic-login");
968
} else if (strcmp (key, "LoginFrequency") == 0) {
969
int new_login_frequency;
971
new_login_frequency = (int) g_value_get_uint64 (value);
972
if ((int) user->login_frequency != (int) new_login_frequency) {
973
user->login_frequency = new_login_frequency;
974
g_object_notify (G_OBJECT (user), "login-frequency");
976
} else if (strcmp (key, "IconFile") == 0) {
977
const char *new_icon_file;
979
new_icon_file = g_value_get_string (value);
980
if (g_strcmp0 (user->icon_file, new_icon_file) != 0) {
981
g_free (user->icon_file);
982
user->icon_file = g_value_dup_string (value);
983
g_object_notify (G_OBJECT (user), "icon-file");
985
} else if (strcmp (key, "Language") == 0) {
986
const char *new_language;
988
new_language = g_value_get_string (value);
989
if (g_strcmp0 (user->language, new_language) != 0) {
990
g_free (user->language);
991
user->language = g_value_dup_string (value);
992
g_object_notify (G_OBJECT (user), "language");
994
} else if (strcmp (key, "XSession") == 0) {
995
const char *new_x_session;
997
new_x_session = g_value_get_string (value);
998
if (g_strcmp0 (user->x_session, new_x_session) != 0) {
999
g_free (user->x_session);
1000
user->x_session = g_value_dup_string (value);
1001
g_object_notify (G_OBJECT (user), "x-session");
1008
g_debug ("unhandled property %s", key);
1013
on_get_all_finished (DBusGProxy *proxy,
1014
DBusGProxyCall *call,
1018
GHashTable *hash_table;
1021
g_assert (user->get_all_call == call);
1022
g_assert (user->object_proxy == proxy);
1025
res = dbus_g_proxy_end_call (proxy,
1028
dbus_g_type_get_map ("GHashTable", G_TYPE_STRING, G_TYPE_VALUE),
1031
user->get_all_call = NULL;
1032
user->object_proxy = NULL;
1035
g_debug ("Error calling GetAll() when retrieving properties for %s: %s",
1036
user->object_path, error->message);
1037
g_error_free (error);
1040
g_hash_table_foreach (hash_table, (GHFunc) collect_props, user);
1041
g_hash_table_unref (hash_table);
1043
if (!user->is_loaded) {
1044
set_is_loaded (user, TRUE);
1047
g_signal_emit (user, signals[CHANGED], 0);
1050
g_object_unref (proxy);
1054
update_info (ActUser *user)
1057
DBusGProxyCall *call;
1059
proxy = dbus_g_proxy_new_for_name (user->connection,
1062
DBUS_INTERFACE_PROPERTIES);
1064
call = dbus_g_proxy_begin_call (proxy,
1066
(DBusGProxyCallNotify)
1067
on_get_all_finished,
1071
ACCOUNTS_USER_INTERFACE,
1075
g_warning ("ActUser: failed to make GetAll call");
1079
user->get_all_call = call;
1080
user->object_proxy = proxy;
1084
if (proxy != NULL) {
1085
g_object_unref (proxy);
1092
changed_handler (DBusGProxy *proxy,
1095
ActUser *user = ACT_USER (data);
1101
* _act_user_update_from_object_path:
1102
* @user: the user object to update.
1103
* @object_path: the object path of the user to use.
1105
* Updates the properties of @user from the accounts service via
1106
* the object path in @object_path.
1109
_act_user_update_from_object_path (ActUser *user,
1110
const char *object_path)
1112
g_return_if_fail (ACT_IS_USER (user));
1113
g_return_if_fail (object_path != NULL);
1114
g_return_if_fail (user->object_path == NULL);
1116
user->object_path = g_strdup (object_path);
1118
user->accounts_proxy = dbus_g_proxy_new_for_name (user->connection,
1121
ACCOUNTS_USER_INTERFACE);
1122
dbus_g_proxy_set_default_timeout (user->accounts_proxy, INT_MAX);
1123
dbus_g_proxy_add_signal (user->accounts_proxy, "Changed", G_TYPE_INVALID);
1125
dbus_g_proxy_connect_signal (user->accounts_proxy, "Changed",
1126
G_CALLBACK (changed_handler), user, NULL);
1128
if (!update_info (user)) {
1129
g_warning ("Couldn't update info for user with object path %s", object_path);
1134
_act_user_update_login_frequency (ActUser *user,
1135
int login_frequency)
1137
if (user->login_frequency != login_frequency) {
1138
user->login_frequency = login_frequency;
1139
g_object_notify (G_OBJECT (user), "login-frequency");
1144
* act_user_is_loaded:
1147
* Determines whether or not the user object is loaded and ready to read from.
1148
* #ActUserManager:is-loaded property must be %TRUE before calling
1149
* act_user_manager_list_users()
1151
* Returns: %TRUE or %FALSE
1154
act_user_is_loaded (ActUser *user)
1156
return user->is_loaded;
1160
* act_user_set_email:
1161
* @user: the user object to alter.
1162
* @email: an email address
1164
* Assigns a new email to @user.
1166
* Note this function is synchronous and ignores errors.
1169
act_user_set_email (ActUser *user,
1172
GError *error = NULL;
1174
g_return_if_fail (ACT_IS_USER (user));
1175
g_return_if_fail (email != NULL);
1176
g_return_if_fail (DBUS_IS_G_PROXY (user->accounts_proxy));
1178
if (!dbus_g_proxy_call (user->accounts_proxy,
1181
G_TYPE_STRING, email,
1184
g_warning ("SetEmail call failed: %s", error->message);
1185
g_error_free (error);
1191
* act_user_set_language:
1192
* @user: the user object to alter.
1193
* @language: a locale (e.g. en_US.utf8)
1195
* Assigns a new locale for @user.
1197
* Note this function is synchronous and ignores errors.
1200
act_user_set_language (ActUser *user,
1201
const char *language)
1203
GError *error = NULL;
1205
g_return_if_fail (ACT_IS_USER (user));
1206
g_return_if_fail (language != NULL);
1207
g_return_if_fail (DBUS_IS_G_PROXY (user->accounts_proxy));
1209
if (!dbus_g_proxy_call (user->accounts_proxy,
1212
G_TYPE_STRING, language,
1215
g_warning ("SetLanguage call failed: %s", error->message);
1216
g_error_free (error);
1222
* act_user_set_x_session:
1223
* @user: the user object to alter.
1224
* @x_session: an x session (e.g. gnome)
1226
* Assigns a new x session for @user.
1228
* Note this function is synchronous and ignores errors.
1231
act_user_set_x_session (ActUser *user,
1232
const char *x_session)
1234
GError *error = NULL;
1236
g_return_if_fail (ACT_IS_USER (user));
1237
g_return_if_fail (x_session != NULL);
1238
g_return_if_fail (DBUS_IS_G_PROXY (user->accounts_proxy));
1240
if (!dbus_g_proxy_call (user->accounts_proxy,
1243
G_TYPE_STRING, x_session,
1246
g_warning ("SetXSession call failed: %s", error->message);
1247
g_error_free (error);
1254
* act_user_set_location:
1255
* @user: the user object to alter.
1256
* @location: a location
1258
* Assigns a new location for @user.
1260
* Note this function is synchronous and ignores errors.
1263
act_user_set_location (ActUser *user,
1264
const char *location)
1266
GError *error = NULL;
1268
g_return_if_fail (ACT_IS_USER (user));
1269
g_return_if_fail (location != NULL);
1270
g_return_if_fail (DBUS_IS_G_PROXY (user->accounts_proxy));
1272
if (!dbus_g_proxy_call (user->accounts_proxy,
1275
G_TYPE_STRING, location,
1278
g_warning ("SetLocation call failed: %s", error->message);
1279
g_error_free (error);
1285
* act_user_set_user_name:
1286
* @user: the user object to alter.
1287
* @user_name: a new user name
1289
* Assigns a new username for @user.
1291
* Note this function is synchronous and ignores errors.
1294
act_user_set_user_name (ActUser *user,
1295
const char *user_name)
1297
GError *error = NULL;
1299
g_return_if_fail (ACT_IS_USER (user));
1300
g_return_if_fail (user_name != NULL);
1301
g_return_if_fail (DBUS_IS_G_PROXY (user->accounts_proxy));
1303
if (!dbus_g_proxy_call (user->accounts_proxy,
1306
G_TYPE_STRING, user_name,
1309
g_warning ("SetUserName call failed: %s", error->message);
1310
g_error_free (error);
1316
* act_user_set_real_name:
1317
* @user: the user object to alter.
1318
* @real_name: a new name
1320
* Assigns a new name for @user.
1322
* Note this function is synchronous and ignores errors.
1325
act_user_set_real_name (ActUser *user,
1326
const char *real_name)
1328
GError *error = NULL;
1330
g_return_if_fail (ACT_IS_USER (user));
1331
g_return_if_fail (real_name != NULL);
1332
g_return_if_fail (DBUS_IS_G_PROXY (user->accounts_proxy));
1334
if (!dbus_g_proxy_call (user->accounts_proxy,
1337
G_TYPE_STRING, real_name,
1340
g_warning ("SetRealName call failed: %s", error->message);
1341
g_error_free (error);
1347
* act_user_set_icon_file:
1348
* @user: the user object to alter.
1349
* @icon_file: path to an icon
1351
* Assigns a new icon for @user.
1353
* Note this function is synchronous and ignores errors.
1356
act_user_set_icon_file (ActUser *user,
1357
const char *icon_file)
1359
GError *error = NULL;
1361
g_return_if_fail (ACT_IS_USER (user));
1362
g_return_if_fail (icon_file != NULL);
1363
g_return_if_fail (DBUS_IS_G_PROXY (user->accounts_proxy));
1365
if (!dbus_g_proxy_call (user->accounts_proxy,
1368
G_TYPE_STRING, icon_file,
1371
g_warning ("SetIconFile call failed: %s", error->message);
1372
g_error_free (error);
1378
* act_user_set_account_type:
1379
* @user: the user object to alter.
1380
* @account_type: a #ActUserAccountType
1382
* Changes the account type of @user.
1384
* Note this function is synchronous and ignores errors.
1387
act_user_set_account_type (ActUser *user,
1388
ActUserAccountType account_type)
1390
GError *error = NULL;
1392
g_return_if_fail (ACT_IS_USER (user));
1393
g_return_if_fail (DBUS_IS_G_PROXY (user->accounts_proxy));
1395
if (!dbus_g_proxy_call (user->accounts_proxy,
1398
G_TYPE_INT, account_type,
1401
g_warning ("SetAccountType call failed: %s", error->message);
1402
g_error_free (error);
1408
salt_char (GRand *rand)
1410
gchar salt[] = "ABCDEFGHIJKLMNOPQRSTUVXYZ"
1411
"abcdefghijklmnopqrstuvxyz"
1414
return salt[g_rand_int_range (rand, 0, G_N_ELEMENTS (salt))];
1418
make_crypted (const gchar *plain)
1425
rand = g_rand_new ();
1426
salt = g_string_sized_new (21);
1429
g_string_append (salt, "$6$");
1430
for (i = 0; i < 16; i++) {
1431
g_string_append_c (salt, salt_char (rand));
1433
g_string_append_c (salt, '$');
1435
result = g_strdup (crypt (plain, salt->str));
1437
g_string_free (salt, TRUE);
1444
* act_user_set_password:
1445
* @user: the user object to alter.
1446
* @password: a password
1447
* @hint: a hint to help user recall password
1449
* Changes the password of @user to @password.
1450
* @hint is displayed to the user if they forget the password.
1452
* Note this function is synchronous and ignores errors.
1455
act_user_set_password (ActUser *user,
1456
const gchar *password,
1459
GError *error = NULL;
1462
g_return_if_fail (ACT_IS_USER (user));
1463
g_return_if_fail (password != NULL);
1464
g_return_if_fail (DBUS_IS_G_PROXY (user->accounts_proxy));
1466
crypted = make_crypted (password);
1467
if (!dbus_g_proxy_call (user->accounts_proxy,
1470
G_TYPE_STRING, crypted,
1471
G_TYPE_STRING, hint,
1474
g_warning ("SetPassword call failed: %s", error->message);
1475
g_error_free (error);
1477
memset (crypted, 0, strlen (crypted));
1482
* act_user_set_password_mode:
1483
* @user: the user object to alter.
1484
* @password_mode: a #ActUserPasswordMode
1486
* Changes the password of @user. If @password_mode is
1487
* ACT_USER_PASSWORD_MODE_SET_AT_LOGIN then the user will
1488
* be asked for a new password at the next login. If @password_mode
1489
* is ACT_USER_PASSWORD_MODE_NONE then the user will not require
1490
* a password to log in.
1492
* Note this function is synchronous and ignores errors.
1495
act_user_set_password_mode (ActUser *user,
1496
ActUserPasswordMode password_mode)
1498
GError *error = NULL;
1500
g_return_if_fail (ACT_IS_USER (user));
1501
g_return_if_fail (DBUS_IS_G_PROXY (user->accounts_proxy));
1503
if (!dbus_g_proxy_call (user->accounts_proxy,
1506
G_TYPE_INT, (int) password_mode,
1509
g_warning ("SetPasswordMode call failed: %s", error->message);
1510
g_error_free (error);
1515
* act_user_set_locked:
1516
* @user: the user object to alter.
1517
* @locked: whether or not the account is locked
1519
* Note this function is synchronous and ignores errors.
1522
act_user_set_locked (ActUser *user,
1525
GError *error = NULL;
1527
g_return_if_fail (ACT_IS_USER (user));
1528
g_return_if_fail (DBUS_IS_G_PROXY (user->accounts_proxy));
1530
if (!dbus_g_proxy_call (user->accounts_proxy,
1533
G_TYPE_BOOLEAN, locked,
1536
g_warning ("SetLocked call failed: %s", error->message);
1537
g_error_free (error);
1542
* act_user_set_automatic_login:
1543
* @enabled: whether or not to autologin for user.
1545
* If enabled is set to %TRUE then this user will automatically be logged in
1546
* at boot up time. Only one user can be configured to auto login at any given
1547
* time, so subsequent calls to act_user_set_automatic_login() override previous
1550
* Note this function is synchronous and ignores errors.
1553
act_user_set_automatic_login (ActUser *user,
1556
GError *error = NULL;
1558
g_return_if_fail (ACT_IS_USER (user));
1559
g_return_if_fail (DBUS_IS_G_PROXY (user->accounts_proxy));
1561
if (!dbus_g_proxy_call (user->accounts_proxy,
1562
"SetAutomaticLogin",
1564
G_TYPE_BOOLEAN, enabled,
1567
g_warning ("SetAutomaticLogin call failed: %s", error->message);
1568
g_error_free (error);