act-user.c 59.1 KB
Newer Older
Ray Strode's avatar
Ray Strode committed
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
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*-
 *
 * Copyright (C) 2004-2005 James M. Cape <jcape@ignore-your.tv>.
 * Copyright (C) 2007-2008 William Jon McCann <mccann@jhu.edu>
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY 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, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */

#include <config.h>

#include <float.h>
#include <string.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>

Ray Strode's avatar
Ray Strode committed
29 30
#include <crypt.h>

Ray Strode's avatar
Ray Strode committed
31 32 33 34 35
#include <glib.h>
#include <glib/gi18n.h>
#include <gio/gio.h>

#include "act-user-private.h"
Matthias Clasen's avatar
Matthias Clasen committed
36
#include "accounts-user-generated.h"
Ray Strode's avatar
Ray Strode committed
37

38 39 40 41 42 43 44 45
/**
 * SECTION:act-user
 * @title: ActUser
 * @short_description: information about a user account
 *
 * An ActUser object represents a user account on the system.
 */

46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68
/**
 * ActUser:
 *
 * Represents a user account on the system.
 */

/**
 * ActUserAccountType:
 * @ACT_USER_ACCOUNT_TYPE_STANDARD: Normal non-administrative user
 * @ACT_USER_ACCOUNT_TYPE_ADMINISTRATOR: Administrative user
 *
 * Type of user account
 */

/**
 * ActUserPasswordMode:
 * @ACT_USER_PASSWORD_MODE_REGULAR: Password set normally
 * @ACT_USER_PASSWORD_MODE_SET_AT_LOGIN: Password will be chosen at next login
 * @ACT_USER_PASSWORD_MODE_NONE: No password set
 *
 * Mode for setting the user's password.
 */

Ray Strode's avatar
Ray Strode committed
69 70 71 72 73 74 75 76 77 78 79 80
#define ACT_USER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), ACT_TYPE_USER, ActUserClass))
#define ACT_IS_USER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), ACT_TYPE_USER))
#define ACT_USER_GET_CLASS(object) (G_TYPE_INSTANCE_GET_CLASS ((object), ACT_TYPE_USER, ActUserClass))

#define ACCOUNTS_NAME           "org.freedesktop.Accounts"
#define ACCOUNTS_USER_INTERFACE "org.freedesktop.Accounts.User"

enum {
        PROP_0,
        PROP_UID,
        PROP_USER_NAME,
        PROP_REAL_NAME,
81 82 83 84 85 86 87 88 89
        PROP_ACCOUNT_TYPE,
        PROP_PASSWORD_MODE,
        PROP_PASSWORD_HINT,
        PROP_HOME_DIR,
        PROP_SHELL,
        PROP_EMAIL,
        PROP_LOCATION,
        PROP_LOCKED,
        PROP_AUTOMATIC_LOGIN,
90
        PROP_SYSTEM_ACCOUNT,
91
        PROP_NONEXISTENT,
Stef Walter's avatar
Stef Walter committed
92
        PROP_LOCAL_ACCOUNT,
Ray Strode's avatar
Ray Strode committed
93
        PROP_LOGIN_FREQUENCY,
94
        PROP_LOGIN_TIME,
95
        PROP_LOGIN_HISTORY,
Ray Strode's avatar
Ray Strode committed
96
        PROP_ICON_FILE,
Ray Strode's avatar
Ray Strode committed
97
        PROP_LANGUAGE,
98
        PROP_X_SESSION,
Ray Strode's avatar
Ray Strode committed
99 100 101 102 103 104 105 106 107 108 109 110
        PROP_IS_LOADED
};

enum {
        CHANGED,
        SESSIONS_CHANGED,
        LAST_SIGNAL
};

struct _ActUser {
        GObject         parent;

Matthias Clasen's avatar
Matthias Clasen committed
111 112
        GDBusConnection *connection;
        AccountsUser    *accounts_proxy;
Ray Strode's avatar
Ray Strode committed
113

114 115
        GList          *our_sessions;
        GList          *other_sessions;
116

Ray Strode's avatar
Ray Strode committed
117
        guint           is_loaded : 1;
118
        guint           nonexistent : 1;
Ray Strode's avatar
Ray Strode committed
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
};

struct _ActUserClass
{
        GObjectClass parent_class;
};

static void act_user_finalize     (GObject      *object);

static guint signals[LAST_SIGNAL] = { 0 };

G_DEFINE_TYPE (ActUser, act_user, G_TYPE_OBJECT)

static int
session_compare (const char *a,
                 const char *b)
{
        if (a == NULL) {
                return 1;
        } else if (b == NULL) {
                return -1;
        }

        return strcmp (a, b);
}

void
_act_user_add_session (ActUser    *user,
147 148
                       const char *ssid,
                       gboolean    is_ours)
Ray Strode's avatar
Ray Strode committed
149 150 151 152 153 154
{
        GList *li;

        g_return_if_fail (ACT_IS_USER (user));
        g_return_if_fail (ssid != NULL);

155 156 157 158
        li = g_list_find_custom (user->our_sessions, ssid, (GCompareFunc)session_compare);
        if (li == NULL)
                li = g_list_find_custom (user->other_sessions, ssid, (GCompareFunc)session_compare);

Ray Strode's avatar
Ray Strode committed
159 160
        if (li == NULL) {
                g_debug ("ActUser: adding session %s", ssid);
161 162 163 164
                if (is_ours)
                        user->our_sessions = g_list_prepend (user->our_sessions, g_strdup (ssid));
                else
                        user->other_sessions = g_list_prepend (user->other_sessions, g_strdup (ssid));
Ray Strode's avatar
Ray Strode committed
165 166 167 168 169 170 171 172 173 174
                g_signal_emit (user, signals[SESSIONS_CHANGED], 0);
        } else {
                g_debug ("ActUser: session already present: %s", ssid);
        }
}

void
_act_user_remove_session (ActUser    *user,
                          const char *ssid)
{
175
        GList *li, **headp;
Ray Strode's avatar
Ray Strode committed
176 177 178 179

        g_return_if_fail (ACT_IS_USER (user));
        g_return_if_fail (ssid != NULL);

180 181 182 183 184 185 186
        headp = &(user->our_sessions);
        li = g_list_find_custom (user->our_sessions, ssid, (GCompareFunc)session_compare);
        if (li == NULL) {
                headp = &(user->other_sessions);
                li = g_list_find_custom (user->other_sessions, ssid, (GCompareFunc)session_compare);
        }

Ray Strode's avatar
Ray Strode committed
187 188 189
        if (li != NULL) {
                g_debug ("ActUser: removing session %s", ssid);
                g_free (li->data);
190
                *headp = g_list_delete_link (*headp, li);
Ray Strode's avatar
Ray Strode committed
191 192 193 194 195 196
                g_signal_emit (user, signals[SESSIONS_CHANGED], 0);
        } else {
                g_debug ("ActUser: session not found: %s", ssid);
        }
}

197 198 199 200
/**
 * act_user_get_num_sessions:
 * @user: a user
 *
201 202
 * Get the number of sessions for a user that are graphical and on the
 * same seat as the session of the calling process.
203 204 205
 *
 * Returns: the number of sessions
 */
Ray Strode's avatar
Ray Strode committed
206 207 208
guint
act_user_get_num_sessions (ActUser    *user)
{
209 210 211 212 213 214 215 216 217 218
        return g_list_length (user->our_sessions);
}

/**
 * act_user_get_num_sessions_anywhere:
 * @user: a user
 *
 * Get the number of sessions for a user on any seat of any type.
 * See also act_user_get_num_sessions().
 *
219 220 221
 * (Currently, this function is only implemented for systemd-logind.
 * For ConsoleKit, it is equivalent to act_user_get_num_sessions.)
 *
222 223 224 225 226 227 228
 * Returns: the number of sessions
 */
guint
act_user_get_num_sessions_anywhere (ActUser    *user)
{
        return (g_list_length (user->our_sessions)
                + g_list_length (user->other_sessions));
Ray Strode's avatar
Ray Strode committed
229 230 231 232 233 234 235 236 237 238 239 240 241
}

static void
act_user_get_property (GObject    *object,
                       guint       param_id,
                       GValue     *value,
                       GParamSpec *pspec)
{
        ActUser *user;

        user = ACT_USER (object);

        switch (param_id) {
242 243 244
        case PROP_NONEXISTENT:
                g_value_set_boolean (value, user->nonexistent);
                break;
Ray Strode's avatar
Ray Strode committed
245 246 247 248
        case PROP_IS_LOADED:
                g_value_set_boolean (value, user->is_loaded);
                break;
        default:
Ray Strode's avatar
Ray Strode committed
249 250 251 252 253 254 255 256
                if (user->accounts_proxy != NULL) {
                        const char *property_name;

                        property_name = g_param_spec_get_name (pspec);

                        g_object_get_property (G_OBJECT (user->accounts_proxy), property_name, value);

                }
Ray Strode's avatar
Ray Strode committed
257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277
                break;
        }
}


static void
act_user_class_init (ActUserClass *class)
{
        GObjectClass *gobject_class;

        gobject_class = G_OBJECT_CLASS (class);

        gobject_class->finalize = act_user_finalize;
        gobject_class->get_property = act_user_get_property;

        g_object_class_install_property (gobject_class,
                                         PROP_REAL_NAME,
                                         g_param_spec_string ("real-name",
                                                              "Real Name",
                                                              "The real name to display for this user.",
                                                              NULL,
278
                                                              G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
Ray Strode's avatar
Ray Strode committed
279

280 281 282 283 284 285
        g_object_class_install_property (gobject_class,
                                         PROP_ACCOUNT_TYPE,
                                         g_param_spec_int ("account-type",
                                                           "Account Type",
                                                           "The account type for this user.",
                                                           ACT_USER_ACCOUNT_TYPE_STANDARD,
286
                                                           ACT_USER_ACCOUNT_TYPE_ADMINISTRATOR,
287
                                                           ACT_USER_ACCOUNT_TYPE_STANDARD,
288
                                                           G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
289 290 291 292 293 294 295 296
        g_object_class_install_property (gobject_class,
                                         PROP_PASSWORD_MODE,
                                         g_param_spec_int ("password-mode",
                                                           "Password Mode",
                                                           "The password mode for this user.",
                                                           ACT_USER_PASSWORD_MODE_REGULAR,
                                                           ACT_USER_PASSWORD_MODE_NONE,
                                                           ACT_USER_PASSWORD_MODE_REGULAR,
297
                                                           G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
298 299 300 301 302 303 304

        g_object_class_install_property (gobject_class,
                                         PROP_PASSWORD_HINT,
                                         g_param_spec_string ("password-hint",
                                                              "Password Hint",
                                                              "Hint to help this user remember his password",
                                                              NULL,
305
                                                              G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
306

Ray Strode's avatar
Ray Strode committed
307 308
        g_object_class_install_property (gobject_class,
                                         PROP_UID,
Ray Strode's avatar
Ray Strode committed
309 310 311 312
                                         g_param_spec_int ("uid",
                                                           "User ID",
                                                           "The UID for this user.",
                                                           0, G_MAXINT, 0,
313
                                                           G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
Ray Strode's avatar
Ray Strode committed
314 315 316 317 318 319
        g_object_class_install_property (gobject_class,
                                         PROP_USER_NAME,
                                         g_param_spec_string ("user-name",
                                                              "User Name",
                                                              "The login name for this user.",
                                                              NULL,
320
                                                              G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
321 322 323 324 325 326
        g_object_class_install_property (gobject_class,
                                         PROP_HOME_DIR,
                                         g_param_spec_string ("home-directory",
                                                              "Home Directory",
                                                              "The home directory for this user.",
                                                              NULL,
327
                                                              G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
328 329 330 331 332 333
        g_object_class_install_property (gobject_class,
                                         PROP_SHELL,
                                         g_param_spec_string ("shell",
                                                              "Shell",
                                                              "The shell for this user.",
                                                              NULL,
334
                                                              G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
335 336 337 338 339 340
        g_object_class_install_property (gobject_class,
                                         PROP_EMAIL,
                                         g_param_spec_string ("email",
                                                              "Email",
                                                              "The email address for this user.",
                                                              NULL,
341
                                                              G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
342 343 344 345 346 347
        g_object_class_install_property (gobject_class,
                                         PROP_LOCATION,
                                         g_param_spec_string ("location",
                                                              "Location",
                                                              "The location of this user.",
                                                              NULL,
348
                                                              G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
Ray Strode's avatar
Ray Strode committed
349 350
        g_object_class_install_property (gobject_class,
                                         PROP_LOGIN_FREQUENCY,
351 352 353 354 355 356
                                         g_param_spec_int ("login-frequency",
                                                           "login frequency",
                                                           "login frequency",
                                                           0,
                                                           G_MAXINT,
                                                           0,
357
                                                           G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
358 359 360 361 362 363 364 365
        g_object_class_install_property (gobject_class,
                                         PROP_LOGIN_TIME,
                                         g_param_spec_int64 ("login-time",
                                                             "Login time",
                                                             "The last login time for this user.",
                                                             0,
                                                             G_MAXINT64,
                                                             0,
366
                                                             G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
367 368 369 370 371 372 373
        g_object_class_install_property (gobject_class,
                                         PROP_LOGIN_HISTORY,
                                         g_param_spec_variant ("login-history",
                                                               "Login history",
                                                               "The login history for this user.",
                                                               G_VARIANT_TYPE ("a(xxa{sv})"),
                                                               NULL,
374
                                                               G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
Ray Strode's avatar
Ray Strode committed
375 376 377 378 379 380
        g_object_class_install_property (gobject_class,
                                         PROP_ICON_FILE,
                                         g_param_spec_string ("icon-file",
                                                              "Icon File",
                                                              "The path to an icon for this user.",
                                                              NULL,
381
                                                              G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
Ray Strode's avatar
Ray Strode committed
382 383 384 385 386 387
        g_object_class_install_property (gobject_class,
                                         PROP_LANGUAGE,
                                         g_param_spec_string ("language",
                                                              "Language",
                                                              "User's locale.",
                                                              NULL,
388
                                                              G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
389 390 391 392 393 394
        g_object_class_install_property (gobject_class,
                                         PROP_X_SESSION,
                                         g_param_spec_string ("x-session",
                                                              "X session",
                                                              "User's X session.",
                                                              NULL,
395
                                                              G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
Ray Strode's avatar
Ray Strode committed
396 397 398
        g_object_class_install_property (gobject_class,
                                         PROP_IS_LOADED,
                                         g_param_spec_boolean ("is-loaded",
399 400
                                                               "Is loaded",
                                                               "Determines whether or not the user object is loaded and ready to read from.",
Ray Strode's avatar
Ray Strode committed
401
                                                               FALSE,
402
                                                               G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
403 404 405 406 407 408
        g_object_class_install_property (gobject_class,
                                         PROP_NONEXISTENT,
                                         g_param_spec_boolean ("nonexistent",
                                                               "Doesn't exist",
                                                               "Determines whether or not the user object represents a valid user account.",
                                                               FALSE,
409
                                                               G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
410 411 412 413 414 415
        g_object_class_install_property (gobject_class,
                                         PROP_LOCKED,
                                         g_param_spec_boolean ("locked",
                                                               "Locked",
                                                               "Locked",
                                                               FALSE,
416
                                                              G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
417 418 419 420 421 422 423

        g_object_class_install_property (gobject_class,
                                         PROP_AUTOMATIC_LOGIN,
                                         g_param_spec_boolean ("automatic-login",
                                                               "Automatic Login",
                                                               "Automatic Login",
                                                               FALSE,
424
                                                               G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
Ray Strode's avatar
Ray Strode committed
425

Stef Walter's avatar
Stef Walter committed
426 427 428 429 430 431
        g_object_class_install_property (gobject_class,
                                         PROP_LOCAL_ACCOUNT,
                                         g_param_spec_boolean ("local-account",
                                                               "Local Account",
                                                               "Local Account",
                                                               FALSE,
432
                                                               G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
Stef Walter's avatar
Stef Walter committed
433

434 435 436 437 438 439
        g_object_class_install_property (gobject_class,
                                         PROP_SYSTEM_ACCOUNT,
                                         g_param_spec_boolean ("system-account",
                                                               "System Account",
                                                               "System Account",
                                                               FALSE,
440
                                                               G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
441 442


443 444 445 446 447
        /**
         * ActUser::changed:
         *
         * Emitted when the user accounts changes in some way.
         */
Ray Strode's avatar
Ray Strode committed
448 449 450 451 452 453 454 455
        signals [CHANGED] =
                g_signal_new ("changed",
                              G_TYPE_FROM_CLASS (class),
                              G_SIGNAL_RUN_LAST,
                              0,
                              NULL, NULL,
                              g_cclosure_marshal_VOID__VOID,
                              G_TYPE_NONE, 0);
456 457 458 459 460
        /**
         * ActUser::sessions-changed:
         *
         * Emitted when the list of sessions for this user changes.
         */
Ray Strode's avatar
Ray Strode committed
461 462 463 464 465 466 467 468 469 470 471 472 473
        signals [SESSIONS_CHANGED] =
                g_signal_new ("sessions-changed",
                              G_TYPE_FROM_CLASS (class),
                              G_SIGNAL_RUN_LAST,
                              0,
                              NULL, NULL,
                              g_cclosure_marshal_VOID__VOID,
                              G_TYPE_NONE, 0);
}

static void
act_user_init (ActUser *user)
{
474
        g_autoptr(GError) error = NULL;
Ray Strode's avatar
Ray Strode committed
475

476 477
        user->our_sessions = NULL;
        user->other_sessions = NULL;
Ray Strode's avatar
Ray Strode committed
478

Matthias Clasen's avatar
Matthias Clasen committed
479
        user->connection = g_bus_get_sync (G_BUS_TYPE_SYSTEM, NULL, &error);
Ray Strode's avatar
Ray Strode committed
480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496
        if (user->connection == NULL) {
                g_warning ("Couldn't connect to system bus: %s", error->message);
        }
}

static void
act_user_finalize (GObject *object)
{
        ActUser *user;

        user = ACT_USER (object);

        if (user->accounts_proxy != NULL) {
                g_object_unref (user->accounts_proxy);
        }

        if (user->connection != NULL) {
Matthias Clasen's avatar
Matthias Clasen committed
497
                g_object_unref (user->connection);
Ray Strode's avatar
Ray Strode committed
498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519
        }

        if (G_OBJECT_CLASS (act_user_parent_class)->finalize)
                (*G_OBJECT_CLASS (act_user_parent_class)->finalize) (object);
}

static void
set_is_loaded (ActUser  *user,
               gboolean  is_loaded)
{
        if (user->is_loaded != is_loaded) {
                user->is_loaded = is_loaded;
                g_object_notify (G_OBJECT (user), "is-loaded");
        }
}

/**
 * act_user_get_uid:
 * @user: the user object to examine.
 *
 * Retrieves the ID of @user.
 *
Robert Ancell's avatar
Robert Ancell committed
520
 * Returns: a pointer to an array of characters which must not be modified or
Ray Strode's avatar
Ray Strode committed
521 522 523
 *  freed, or %NULL.
 **/

Ray Strode's avatar
Ray Strode committed
524
uid_t
Ray Strode's avatar
Ray Strode committed
525 526 527 528
act_user_get_uid (ActUser *user)
{
        g_return_val_if_fail (ACT_IS_USER (user), -1);

Ray Strode's avatar
Ray Strode committed
529 530 531 532
        if (user->accounts_proxy == NULL)
                return -1;

        return accounts_user_get_uid (user->accounts_proxy);
Ray Strode's avatar
Ray Strode committed
533 534 535 536 537 538 539 540 541 542 543 544 545 546
}

/**
 * act_user_get_real_name:
 * @user: the user object to examine.
 *
 * Retrieves the display name of @user.
 *
 * Returns: (transfer none): a pointer to an array of characters which must not be modified or
 *  freed, or %NULL.
 **/
const char *
act_user_get_real_name (ActUser *user)
{
Ray Strode's avatar
Ray Strode committed
547 548
        const char *real_name = NULL;

Ray Strode's avatar
Ray Strode committed
549 550
        g_return_val_if_fail (ACT_IS_USER (user), NULL);

551 552 553
        if (user->accounts_proxy == NULL)
                return NULL;

Ray Strode's avatar
Ray Strode committed
554 555 556 557
        real_name = accounts_user_get_real_name (user->accounts_proxy);

        if (real_name == NULL || real_name[0] == '\0') {
                real_name = accounts_user_get_user_name (user->accounts_proxy);
558 559
        }

Ray Strode's avatar
Ray Strode committed
560
        return real_name;
Ray Strode's avatar
Ray Strode committed
561 562
}

563 564 565 566 567 568 569 570 571 572 573 574 575
/**
 * act_user_get_account_type:
 * @user: the user object to examine.
 *
 * Retrieves the account type of @user.
 *
 * Returns: a #ActUserAccountType
 **/
ActUserAccountType
act_user_get_account_type (ActUser *user)
{
        g_return_val_if_fail (ACT_IS_USER (user), ACT_USER_ACCOUNT_TYPE_STANDARD);

Ray Strode's avatar
Ray Strode committed
576 577 578 579
        if (user->accounts_proxy == NULL)
                return ACT_USER_ACCOUNT_TYPE_STANDARD;

        return accounts_user_get_account_type (user->accounts_proxy);
580 581 582 583 584 585 586 587 588 589 590 591 592 593 594
}

/**
 * act_user_get_password_mode:
 * @user: the user object to examine.
 *
 * Retrieves the password mode of @user.
 *
 * Returns: a #ActUserPasswordMode
 **/
ActUserPasswordMode
act_user_get_password_mode (ActUser *user)
{
        g_return_val_if_fail (ACT_IS_USER (user), ACT_USER_PASSWORD_MODE_REGULAR);

Ray Strode's avatar
Ray Strode committed
595 596 597 598
        if (user->accounts_proxy == NULL)
                return ACT_USER_PASSWORD_MODE_REGULAR;

        return accounts_user_get_password_mode (user->accounts_proxy);
599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614
}

/**
 * act_user_get_password_hint:
 * @user: the user object to examine.
 *
 * Retrieves the password hint set by @user.
 *
 * Returns: (transfer none): a pointer to an array of characters which must not be modified or
 *  freed, or %NULL.
 **/
const char *
act_user_get_password_hint (ActUser *user)
{
        g_return_val_if_fail (ACT_IS_USER (user), NULL);

Ray Strode's avatar
Ray Strode committed
615 616 617 618
        if (user->accounts_proxy == NULL)
                return NULL;

        return accounts_user_get_password_hint (user->accounts_proxy);
619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634
}

/**
 * act_user_get_home_dir:
 * @user: the user object to examine.
 *
 * Retrieves the home directory for @user.
 *
 * Returns: (transfer none): a pointer to an array of characters which must not be modified or
 *  freed, or %NULL.
 **/
const char *
act_user_get_home_dir (ActUser *user)
{
        g_return_val_if_fail (ACT_IS_USER (user), NULL);

Ray Strode's avatar
Ray Strode committed
635 636 637 638
        if (user->accounts_proxy == NULL)
                return NULL;

        return accounts_user_get_home_directory (user->accounts_proxy);
639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654
}

/**
 * act_user_get_shell:
 * @user: the user object to examine.
 *
 * Retrieves the shell assigned to @user.
 *
 * Returns: (transfer none): a pointer to an array of characters which must not be modified or
 *  freed, or %NULL.
 **/
const char *
act_user_get_shell (ActUser *user)
{
        g_return_val_if_fail (ACT_IS_USER (user), NULL);

Ray Strode's avatar
Ray Strode committed
655 656 657 658
        if (user->accounts_proxy == NULL)
                return NULL;

        return accounts_user_get_shell (user->accounts_proxy);
659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674
}

/**
 * act_user_get_email:
 * @user: the user object to examine.
 *
 * Retrieves the email address set by @user.
 *
 * Returns: (transfer none): a pointer to an array of characters which must not be modified or
 *  freed, or %NULL.
 **/
const char *
act_user_get_email (ActUser *user)
{
        g_return_val_if_fail (ACT_IS_USER (user), NULL);

Ray Strode's avatar
Ray Strode committed
675 676 677 678
        if (user->accounts_proxy == NULL)
                return NULL;

        return accounts_user_get_email (user->accounts_proxy);
679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694
}

/**
 * act_user_get_location:
 * @user: the user object to examine.
 *
 * Retrieves the location set by @user.
 *
 * Returns: (transfer none): a pointer to an array of characters which must not be modified or
 *  freed, or %NULL.
 **/
const char *
act_user_get_location (ActUser *user)
{
        g_return_val_if_fail (ACT_IS_USER (user), NULL);

Ray Strode's avatar
Ray Strode committed
695 696 697 698
        if (user->accounts_proxy == NULL)
                return NULL;

        return accounts_user_get_location (user->accounts_proxy);
699 700
}

Ray Strode's avatar
Ray Strode committed
701 702 703 704 705 706 707 708 709 710 711 712 713 714 715
/**
 * act_user_get_user_name:
 * @user: the user object to examine.
 *
 * Retrieves the login name of @user.
 *
 * Returns: (transfer none): a pointer to an array of characters which must not be modified or
 *  freed, or %NULL.
 **/

const char *
act_user_get_user_name (ActUser *user)
{
        g_return_val_if_fail (ACT_IS_USER (user), NULL);

Ray Strode's avatar
Ray Strode committed
716 717 718 719
        if (user->accounts_proxy == NULL)
                return NULL;

        return accounts_user_get_user_name (user->accounts_proxy);
Ray Strode's avatar
Ray Strode committed
720 721 722 723 724 725 726 727 728 729
}

/**
 * act_user_get_login_frequency:
 * @user: a #ActUser
 *
 * Returns the number of times @user has logged in.
 *
 * Returns: the login frequency
 */
730
int
Ray Strode's avatar
Ray Strode committed
731 732 733 734
act_user_get_login_frequency (ActUser *user)
{
        g_return_val_if_fail (ACT_IS_USER (user), 0);

Ray Strode's avatar
Ray Strode committed
735
        if (user->accounts_proxy == NULL)
736
                return 1;
Ray Strode's avatar
Ray Strode committed
737 738

        return accounts_user_get_login_frequency (user->accounts_proxy);
Ray Strode's avatar
Ray Strode committed
739 740
}

741 742 743 744 745 746
/**
 * act_user_get_login_time:
 * @user: a #ActUser
 *
 * Returns the last login time for @user.
 *
Robert Ancell's avatar
Robert Ancell committed
747
 * Returns: the login time
748 749
 */
gint64
Ray Strode's avatar
Ray Strode committed
750 751
act_user_get_login_time (ActUser *user)
{
752 753
        g_return_val_if_fail (ACT_IS_USER (user), 0);

Ray Strode's avatar
Ray Strode committed
754 755 756 757
        if (user->accounts_proxy == NULL)
                return 0;

        return accounts_user_get_login_time (user->accounts_proxy);
758 759
}

760 761 762 763 764 765 766 767 768 769
/**
 * act_user_get_login_history:
 * @user: a #ActUser
 *
 * Returns the login history for @user.
 *
 * Returns: (transfer none): a pointer to GVariant of type "a(xxa{sv})"
 * which must not be modified or freed, or %NULL.
 */
const GVariant *
Ray Strode's avatar
Ray Strode committed
770 771
act_user_get_login_history (ActUser *user)
{
772 773
        g_return_val_if_fail (ACT_IS_USER (user), NULL);

Ray Strode's avatar
Ray Strode committed
774 775 776 777
        if (user->accounts_proxy == NULL)
                return NULL;

        return accounts_user_get_login_history (user->accounts_proxy);
778 779
}

780 781 782 783 784 785 786 787 788 789
/**
 * act_user_collate:
 * @user1: a user
 * @user2: a user
 *
 * Organize the user by login frequency and names.
 *
 * Returns: negative if @user1 is before @user2, zero if equal
 *    or positive if @user1 is after @user2
 */
Ray Strode's avatar
Ray Strode committed
790 791 792 793 794 795
int
act_user_collate (ActUser *user1,
                  ActUser *user2)
{
        const char *str1;
        const char *str2;
796 797
        int         num1;
        int         num2;
Ray Strode's avatar
Ray Strode committed
798 799 800 801 802 803
        guint       len1;
        guint       len2;

        g_return_val_if_fail (ACT_IS_USER (user1), 0);
        g_return_val_if_fail (ACT_IS_USER (user2), 0);

Ray Strode's avatar
Ray Strode committed
804 805
        num1 = act_user_get_login_frequency (user1);
        num2 = act_user_get_login_frequency (user2);
Ray Strode's avatar
Ray Strode committed
806 807 808 809 810 811 812 813 814 815

        if (num1 > num2) {
                return -1;
        }

        if (num1 < num2) {
                return 1;
        }


816 817
        len1 = g_list_length (user1->our_sessions);
        len2 = g_list_length (user2->our_sessions);
Ray Strode's avatar
Ray Strode committed
818 819 820 821 822 823 824 825 826 827

        if (len1 > len2) {
                return -1;
        }

        if (len1 < len2) {
                return 1;
        }

        /* if login frequency is equal try names */
Ray Strode's avatar
Ray Strode committed
828 829
        str1 = act_user_get_real_name (user1);
        str2 = act_user_get_real_name (user2);
Ray Strode's avatar
Ray Strode committed
830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849

        if (str1 == NULL && str2 != NULL) {
                return -1;
        }

        if (str1 != NULL && str2 == NULL) {
                return 1;
        }

        if (str1 == NULL && str2 == NULL) {
                return 0;
        }

        return g_utf8_collate (str1, str2);
}

/**
 * act_user_is_logged_in:
 * @user: a #ActUser
 *
850 851
 * Returns whether or not #ActUser is currently graphically logged in
 * on the same seat as the seat of the session of the calling process.
Ray Strode's avatar
Ray Strode committed
852 853 854 855 856 857
 *
 * Returns: %TRUE or %FALSE
 */
gboolean
act_user_is_logged_in (ActUser *user)
{
858 859 860 861 862 863 864 865 866 867
        return user->our_sessions != NULL;
}

/**
 * act_user_is_logged_in_anywhere:
 * @user: a #ActUser
 *
 * Returns whether or not #ActUser is currently logged in in any way
 * whatsoever.  See also act_user_is_logged_in().
 *
868 869 870
 * (Currently, this function is only implemented for systemd-logind.
 * For ConsoleKit, it is equivalent to act_user_is_logged_in.)
 *
871 872 873 874 875 876
 * Returns: %TRUE or %FALSE
 */
gboolean
act_user_is_logged_in_anywhere (ActUser *user)
{
        return user->our_sessions != NULL || user->other_sessions != NULL;
Ray Strode's avatar
Ray Strode committed
877 878
}

Ray Strode's avatar
Ray Strode committed
879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897
/**
 * act_user_get_saved:
 * @user: a #ActUser
 *
 * Returns whether or not the #ActUser account has retained state in accountsservice.
 *
 * Returns: %TRUE or %FALSE
 */
gboolean
act_user_get_saved (ActUser *user)
{
        g_return_val_if_fail (ACT_IS_USER (user), TRUE);

        if (user->accounts_proxy == NULL)
                return FALSE;

        return accounts_user_get_saved (user->accounts_proxy);
}

898 899 900 901 902 903 904 905 906 907 908
/**
 * act_user_get_locked:
 * @user: a #ActUser
 *
 * Returns whether or not the #ActUser account is locked.
 *
 * Returns: %TRUE or %FALSE
 */
gboolean
act_user_get_locked (ActUser *user)
{
909 910 911 912 913
        g_return_val_if_fail (ACT_IS_USER (user), TRUE);

        if (user->accounts_proxy == NULL)
                return TRUE;

Ray Strode's avatar
Ray Strode committed
914
        return accounts_user_get_locked (user->accounts_proxy);
915 916 917 918 919 920 921 922 923 924 925 926 927
}

/**
 * act_user_get_automatic_login:
 * @user: a #ActUser
 *
 * Returns whether or not #ActUser is automatically logged in at boot time.
 *
 * Returns: %TRUE or %FALSE
 */
gboolean
act_user_get_automatic_login (ActUser *user)
{
Ray Strode's avatar
Ray Strode committed
928 929 930 931 932 933
        g_return_val_if_fail (ACT_IS_USER (user), FALSE);

        if (user->accounts_proxy == NULL)
                return FALSE;

       return accounts_user_get_automatic_login (user->accounts_proxy);
934 935
}

936 937 938 939 940 941 942 943 944 945 946 947
/**
 * act_user_is_system_account:
 * @user: a #ActUser
 *
 * Returns whether or not #ActUser represents a 'system account' like
 * 'root' or 'nobody'.
 *
 * Returns: %TRUE or %FALSE
 */
gboolean
act_user_is_system_account (ActUser *user)
{
Ray Strode's avatar
Ray Strode committed
948 949 950 951 952 953
        g_return_val_if_fail (ACT_IS_USER (user), TRUE);

        if (user->accounts_proxy == NULL)
                return TRUE;

        return accounts_user_get_system_account (user->accounts_proxy);
954 955
}

Stef Walter's avatar
Stef Walter committed
956 957 958 959 960 961
/**
 * act_user_is_local_account:
 * @user: the user object to examine.
 *
 * Retrieves whether the user is a local account or not.
 *
Robert Ancell's avatar
Robert Ancell committed
962
 * Returns: %TRUE if the user is local
Stef Walter's avatar
Stef Walter committed
963 964 965 966 967 968
 **/
gboolean
act_user_is_local_account (ActUser   *user)
{
        g_return_val_if_fail (ACT_IS_USER (user), FALSE);

Ray Strode's avatar
Ray Strode committed
969 970 971 972
        if (user->accounts_proxy == NULL)
                return FALSE;

        return accounts_user_get_local_account (user->accounts_proxy);
Stef Walter's avatar
Stef Walter committed
973 974
}

975 976 977 978 979 980
/**
 * act_user_is_nonexistent:
 * @user: the user object to examine.
 *
 * Retrieves whether the user is nonexistent or not.
 *
Robert Ancell's avatar
Robert Ancell committed
981
 * Returns: %TRUE if the user is nonexistent
982 983 984 985 986 987 988 989 990
 **/
gboolean
act_user_is_nonexistent (ActUser   *user)
{
        g_return_val_if_fail (ACT_IS_USER (user), FALSE);

        return user->nonexistent;
}

Ray Strode's avatar
Ray Strode committed
991 992 993 994 995 996 997 998 999 1000 1001 1002 1003
/**
 * act_user_get_icon_file:
 * @user: a #ActUser
 *
 * Returns the path to the account icon belonging to @user.
 *
 * Returns: (transfer none): a path to an icon
 */
const char *
act_user_get_icon_file (ActUser *user)
{
        g_return_val_if_fail (ACT_IS_USER (user), NULL);

Ray Strode's avatar
Ray Strode committed
1004 1005 1006 1007
        if (user->accounts_proxy == NULL)
                return NULL;

        return accounts_user_get_icon_file (user->accounts_proxy);
Ray Strode's avatar
Ray Strode committed
1008 1009
}

Ray Strode's avatar
Ray Strode committed
1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022
/**
 * act_user_get_language:
 * @user: a #ActUser
 *
 * Returns the path to the configured locale of @user.
 *
 * Returns: (transfer none): a path to an icon
 */
const char *
act_user_get_language (ActUser *user)
{
        g_return_val_if_fail (ACT_IS_USER (user), NULL);

Ray Strode's avatar
Ray Strode committed
1023 1024 1025 1026
        if (user->accounts_proxy == NULL)
                return NULL;

        return accounts_user_get_language (user->accounts_proxy);
Ray Strode's avatar
Ray Strode committed
1027 1028
}

1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041
/**
 * act_user_get_x_session:
 * @user: a #ActUser
 *
 * Returns the path to the configured X session for @user.
 *
 * Returns: (transfer none): a path to an icon
 */
const char *
act_user_get_x_session (ActUser *user)
{
        g_return_val_if_fail (ACT_IS_USER (user), NULL);

Ray Strode's avatar
Ray Strode committed
1042 1043 1044 1045
        if (user->accounts_proxy == NULL)
                return NULL;

        return accounts_user_get_xsession (user->accounts_proxy);
1046 1047
}

1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085
/**
 * act_user_get_session:
 * @user: a #ActUser
 *
 * Returns the path to the configured session for @user.
 *
 * Returns: (transfer none): a path to an icon
 */
const char *
act_user_get_session (ActUser *user)
{
        g_return_val_if_fail (ACT_IS_USER (user), NULL);

        if (user->accounts_proxy == NULL)
                return NULL;

        return accounts_user_get_session (user->accounts_proxy);
}

/**
 * act_user_get_session_type:
 * @user: a #ActUser
 *
 * Returns the type of the configured session for @user.
 *
 * Returns: (transfer none): a path to an icon
 */
const char *
act_user_get_session_type (ActUser *user)
{
        g_return_val_if_fail (ACT_IS_USER (user), NULL);

        if (user->accounts_proxy == NULL)
                return NULL;

        return accounts_user_get_session_type (user->accounts_proxy);
}

Ray Strode's avatar
Ray Strode committed
1086 1087 1088 1089 1090 1091 1092 1093
/**
 * act_user_get_object_path:
 * @user: a #ActUser
 *
 * Returns the user accounts service object path of @user,
 * or %NULL if @user doesn't have an object path associated
 * with it.
 *
1094
 * Returns: (transfer none): the object path of the user
Ray Strode's avatar
Ray Strode committed
1095 1096 1097 1098 1099 1100
 */
const char *
act_user_get_object_path (ActUser *user)
{
        g_return_val_if_fail (ACT_IS_USER (user), NULL);

Ray Strode's avatar
Ray Strode committed
1101 1102 1103 1104
        if (user->accounts_proxy == NULL)
                return NULL;

        return g_dbus_proxy_get_object_path (G_DBUS_PROXY (user->accounts_proxy));
Ray Strode's avatar
Ray Strode committed
1105 1106 1107 1108 1109 1110
}

/**
 * act_user_get_primary_session_id:
 * @user: a #ActUser
 *
1111 1112 1113 1114
 * Returns the id of the primary session of @user, or %NULL if @user
 * has no primary session.  The primary session will always be
 * graphical and will be chosen from the sessions on the same seat as
 * the seat of the session of the calling process.
Ray Strode's avatar
Ray Strode committed
1115
 *
1116
 * Returns: (transfer none): the id of the primary session of the user
Ray Strode's avatar
Ray Strode committed
1117 1118 1119 1120
 */
const char *
act_user_get_primary_session_id (ActUser *user)
{
1121 1122
        if (user->our_sessions == NULL) {
                g_debug ("User %s is not logged in here, so has no primary session",
Ray Strode's avatar
Ray Strode committed
1123 1124 1125 1126 1127
                         act_user_get_user_name (user));
                return NULL;
        }

        /* FIXME: better way to choose? */
1128
        return user->our_sessions->data;
Ray Strode's avatar
Ray Strode committed
1129 1130
}

1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142
/**
 * _act_user_update_as_nonexistent:
 * @user: the user object to update.
 *
 * Set's the 'non-existent' property of @user to #TRUE
 * Can only be called before the user is loaded.
 **/
void
_act_user_update_as_nonexistent (ActUser *user)
{
        g_return_if_fail (ACT_IS_USER (user));
        g_return_if_fail (!act_user_is_loaded (user));
Ray Strode's avatar
Ray Strode committed
1143
        g_return_if_fail (act_user_get_object_path (user) == NULL);
1144 1145 1146 1147 1148 1149 1150

        user->nonexistent = TRUE;
        g_object_notify (G_OBJECT (user), "nonexistent");

        set_is_loaded (user, TRUE);
}

Ray Strode's avatar
Ray Strode committed
1151 1152 1153 1154 1155 1156
static void
on_accounts_proxy_changed (ActUser *user)
{
        g_signal_emit (user, signals[CHANGED], 0);
}

Ray Strode's avatar
Ray Strode committed
1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168
/**
 * _act_user_update_from_object_path:
 * @user: the user object to update.
 * @object_path: the object path of the user to use.
 *
 * Updates the properties of @user from the accounts service via
 * the object path in @object_path.
 **/
void
_act_user_update_from_object_path (ActUser    *user,
                                   const char *object_path)
{
Ray Strode's avatar
Ray Strode committed
1169
        AccountsUser    *accounts_proxy;
1170
        g_autoptr(GError) error = NULL;
Matthias Clasen's avatar
Matthias Clasen committed
1171

Ray Strode's avatar
Ray Strode committed
1172 1173
        g_return_if_fail (ACT_IS_USER (user));
        g_return_if_fail (object_path != NULL);
Ray Strode's avatar
Ray Strode committed
1174 1175 1176 1177 1178 1179 1180 1181 1182
        g_return_if_fail (act_user_get_object_path (user) == NULL);

        accounts_proxy = accounts_user_proxy_new_sync (user->connection,
                                                       G_DBUS_PROXY_FLAGS_NONE,
                                                       ACCOUNTS_NAME,
                                                       object_path,
                                                       NULL,
                                                       &error);
        if (!accounts_proxy) {
Matthias Clasen's avatar
Matthias Clasen committed
1183 1184 1185 1186
                g_warning ("Couldn't create accounts proxy: %s", error->message);
                return;
        }

Ray Strode's avatar
Ray Strode committed
1187 1188 1189 1190 1191 1192 1193
        user->accounts_proxy = accounts_proxy;

        g_signal_connect_object (user->accounts_proxy,
                                 "changed",
                                 G_CALLBACK (on_accounts_proxy_changed),
                                 user,
                                 G_CONNECT_SWAPPED);
1194

Ray Strode's avatar
Ray Strode committed
1195 1196 1197
        g_dbus_proxy_set_default_timeout (G_DBUS_PROXY (user->accounts_proxy), INT_MAX);

        set_is_loaded (user, TRUE);
Ray Strode's avatar
Ray Strode committed
1198 1199 1200 1201
}

void
_act_user_update_login_frequency (ActUser    *user,
1202
                                  int         login_frequency)
Ray Strode's avatar
Ray Strode committed
1203
{
Ray Strode's avatar
Ray Strode committed
1204 1205
        if (act_user_get_login_frequency (user) == login_frequency) {
                return;
Ray Strode's avatar
Ray Strode committed
1206
        }
Ray Strode's avatar
Ray Strode committed
1207 1208 1209

        accounts_user_set_login_frequency (user->accounts_proxy,
                                           login_frequency);
Ray Strode's avatar
Ray Strode committed
1210 1211
}

1212
static void
1213 1214
copy_sessions_lists (ActUser *user,
                     ActUser *user_to_copy)
1215 1216 1217
{
        GList *node;

1218 1219 1220 1221 1222 1223 1224
        for (node = g_list_last (user_to_copy->our_sessions);
             node != NULL;
             node = node->prev) {
                user->our_sessions = g_list_prepend (user->our_sessions, g_strdup (node->data));
        }

        for (node = g_list_last (user_to_copy->other_sessions);
1225 1226
             node != NULL;
             node = node->prev) {
1227
                user->other_sessions = g_list_prepend (user->other_sessions, g_strdup (node->data));
1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238
        }
}

void
_act_user_load_from_user (ActUser    *user,
                          ActUser    *user_to_copy)
{
        if (!user_to_copy->is_loaded) {
                return;
        }

Ray Strode's avatar
Ray Strode committed
1239
        user->accounts_proxy = g_object_ref (user_to_copy->accounts_proxy);
1240

Ray Strode's avatar
Ray Strode committed
1241 1242 1243 1244 1245
        g_signal_connect_object (user->accounts_proxy,
                                 "changed",
                                 G_CALLBACK (on_accounts_proxy_changed),
                                 user,
                                 G_CONNECT_SWAPPED);
1246

1247 1248
        if (user->our_sessions == NULL && user->other_sessions == NULL) {
                copy_sessions_lists (user, user_to_copy);
1249 1250 1251 1252 1253 1254
                g_signal_emit (user, signals[SESSIONS_CHANGED], 0);
        }

        set_is_loaded (user, TRUE);
}

Ray Strode's avatar
Ray Strode committed
1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269
/**
 * act_user_is_loaded:
 * @user: a #ActUser
 *
 * Determines whether or not the user object is loaded and ready to read from.
 * #ActUserManager:is-loaded property must be %TRUE before calling
 * act_user_manager_list_users()
 *
 * Returns: %TRUE or %FALSE
 */
gboolean
act_user_is_loaded (ActUser *user)
{
        return user->is_loaded;
}
Ray Strode's avatar
Ray Strode committed
1270

1271
/**
Robert Ancell's avatar
Robert Ancell committed
1272
 * act_user_get_password_expiration_policy:
1273
 * @user: the user object to query.
1274 1275 1276 1277 1278 1279
 * @expiration_time: (out) (optional): location to write time users password expires
 * @last_change_time: (out) (optional): location to write time users password was last changed.
 * @min_days_between_changes: (out) (optional): location to write minimum number of days needed between password changes.
 * @max_days_between_changes: (out) (optional): location to write maximum number of days password can stay unchanged.
 * @days_to_warn: (out) (optional): location to write number of days to warn user password is about to expire.
 * @days_after_expiration_until_lock: (out) (optional): location to write number of days account will be locked after password expires.
Robert Ancell's avatar
Robert Ancell committed
1280 1281
 *
 * Get the password expiration policy for a user.
1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293
 *
 * Note this function is synchronous and ignores errors.
 **/
void
act_user_get_password_expiration_policy (ActUser *user,
                                         gint64  *expiration_time,
                                         gint64  *last_change_time,
                                         gint64  *min_days_between_changes,
                                         gint64  *max_days_between_changes,
                                         gint64  *days_to_warn,
                                         gint64  *days_after_expiration_until_lock)
{
1294
        g_autoptr(GError) error = NULL;
1295 1296 1297 1298 1299

        g_return_if_fail (ACT_IS_USER (user));
        g_return_if_fail (ACCOUNTS_IS_USER (user->accounts_proxy));

        if (!accounts_user_call_get_password_expiration_policy_sync (user->accounts_proxy,
1300 1301
                                                                     G_DBUS_CALL_FLAGS_ALLOW_INTERACTIVE_AUTHORIZATION,
                                                                     -1,
1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314
                                                                     expiration_time,
                                                                     last_change_time,
                                                                     min_days_between_changes,
                                                                     max_days_between_changes,
                                                                     days_to_warn,
                                                                     days_after_expiration_until_lock,
                                                                     NULL,
                                                                     &error)) {
                g_warning ("GetPasswordExpirationPolicy call failed: %s", error->message);
                return;
        }
}

Ray Strode's avatar
Ray Strode committed
1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327
/**
 * act_user_set_email:
 * @user: the user object to alter.
 * @email: an email address
 *
 * Assigns a new email to @user.
 *
 * Note this function is synchronous and ignores errors.
 **/
void
act_user_set_email (ActUser    *user,
                    const char *email)
{
1328
        g_autoptr(GError) error = NULL;
Ray Strode's avatar
Ray Strode committed
1329 1330 1331

        g_return_if_fail (ACT_IS_USER (user));
        g_return_if_fail (email != NULL);
Matthias Clasen's avatar
Matthias Clasen committed
1332 1333 1334 1335
        g_return_if_fail (ACCOUNTS_IS_USER (user->accounts_proxy));

        if (!accounts_user_call_set_email_sync (user->accounts_proxy,
                                                email,
1336 1337
                                                G_DBUS_CALL_FLAGS_ALLOW_INTERACTIVE_AUTHORIZATION,
                                                -1,
Matthias Clasen's avatar
Matthias Clasen committed
1338 1339
                                                NULL,
                                                &error)) {
Ray Strode's avatar
Ray Strode committed
1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357
                g_warning ("SetEmail call failed: %s", error->message);
                return;
        }
}

/**
 * act_user_set_language:
 * @user: the user object to alter.
 * @language: a locale (e.g. en_US.utf8)
 *
 * Assigns a new locale for @user.
 *
 * Note this function is synchronous and ignores errors.
 **/
void
act_user_set_language (ActUser    *user,
                       const char *language)
{
1358
        g_autoptr(GError) error = NULL;
Ray Strode's avatar
Ray Strode committed
1359 1360 1361

        g_return_if_fail (ACT_IS_USER (user));
        g_return_if_fail (language != NULL);
Matthias Clasen's avatar
Matthias Clasen committed
1362 1363 1364 1365
        g_return_if_fail (ACCOUNTS_IS_USER (user->accounts_proxy));

        if (!accounts_user_call_set_language_sync (user->accounts_proxy,
                                                   language,
1366 1367
                                                   G_DBUS_CALL_FLAGS_ALLOW_INTERACTIVE_AUTHORIZATION,
                                                   -1,
Matthias Clasen's avatar
Matthias Clasen committed
1368 1369
                                                   NULL,
                                                   &error)) {
1370
                g_warning ("SetLanguage for language %s failed: %s", language, error->message);
Ray Strode's avatar
Ray Strode committed
1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387
                return;
        }
}

/**
 * act_user_set_x_session:
 * @user: the user object to alter.
 * @x_session: an x session (e.g. gnome)
 *
 * Assigns a new x session for @user.
 *
 * Note this function is synchronous and ignores errors.
 **/
void
act_user_set_x_session (ActUser    *user,
                        const char *x_session)
{
1388
        g_autoptr(GError) error = NULL;
Ray Strode's avatar
Ray Strode committed
1389 1390 1391

        g_return_if_fail (ACT_IS_USER (user));
        g_return_if_fail (x_session != NULL);
Matthias Clasen's avatar
Matthias Clasen committed
1392 1393 1394 1395
        g_return_if_fail (ACCOUNTS_IS_USER (user->accounts_proxy));

        if (!accounts_user_call_set_xsession_sync (user->accounts_proxy,
                                                   x_session,
1396 1397
                                                   G_DBUS_CALL_FLAGS_ALLOW_INTERACTIVE_AUTHORIZATION,
                                                   -1,
Matthias Clasen's avatar
Matthias Clasen committed
1398 1399
                                                   NULL,
                                                   &error)) {
Ray Strode's avatar
Ray Strode committed
1400 1401 1402 1403 1404
                g_warning ("SetXSession call failed: %s", error->message);
                return;
        }
}

1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425
/**
 * act_user_set_session:
 * @user: the user object to alter.
 * @session: a session (e.g. gnome)
 *
 * Assigns a new session for @user.
 *
 * Note this function is synchronous and ignores errors.
 **/
void
act_user_set_session (ActUser    *user,
                      const char *session)
{
        g_autoptr(GError) error = NULL;

        g_return_if_fail (ACT_IS_USER (user));
        g_return_if_fail (session != NULL);
        g_return_if_fail (ACCOUNTS_IS_USER (user->accounts_proxy));

        if (!accounts_user_call_set_session_sync (user->accounts_proxy,
                                                  session,
1426 1427
                                                  G_DBUS_CALL_FLAGS_ALLOW_INTERACTIVE_AUTHORIZATION,
                                                  -1,
1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455
                                                  NULL,
                                                  &error)) {
                g_warning ("SetSession call failed: %s", error->message);
                return;
        }
}

/**
 * act_user_set_session_type:
 * @user: the user object to alter.
 * @session_type: a type of session (e.g. "wayland" or "x11")
 *
 * Assigns a type to the session for @user.
 *
 * Note this function is synchronous and ignores errors.
 **/
void
act_user_set_session_type (ActUser    *user,
                           const char *session_type)
{
        g_autoptr(GError) error = NULL;

        g_return_if_fail (ACT_IS_USER (user));
        g_return_if_fail (session_type != NULL);
        g_return_if_fail (ACCOUNTS_IS_USER (user->accounts_proxy));

        if (!accounts_user_call_set_session_type_sync (user->accounts_proxy,
                                                       session_type,
1456 1457
                                                       G_DBUS_CALL_FLAGS_ALLOW_INTERACTIVE_AUTHORIZATION,
                                                       -1,
1458 1459 1460 1461 1462 1463
                                                       NULL,
                                                       &error)) {
                g_warning ("SetSessionType call failed: %s", error->message);
                return;
        }
}
Ray Strode's avatar
Ray Strode committed
1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477

/**
 * act_user_set_location:
 * @user: the user object to alter.
 * @location: a location
 *
 * Assigns a new location for @user.
 *
 * Note this function is synchronous and ignores errors.