1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
|
/* -*- Mode: C; indent-tabs-mode: nil; tab-width: 4 -*-
*
* Copyright (C) 2010-2011 Robert Ancell.
* Author: Robert Ancell <robert.ancell@canonical.com>
*
* 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 3 of the License, or (at your option) any later
* version. See http://www.gnu.org/copyleft/gpl.html the full text of the
* license.
*/
#include <pwd.h>
#include <stdlib.h>
#include "accounts.h"
#include "user-list.h"
struct UserPrivate
{
/* Internal user object */
CommonUser *common_user;
};
G_DEFINE_TYPE (User, user, G_TYPE_OBJECT)
User *
accounts_get_user_by_name (const gchar *username)
{
User *user = NULL;
CommonUser *common_user;
g_return_val_if_fail (username != NULL, NULL);
common_user = common_user_list_get_user_by_name (common_user_list_get_instance (), username);
if (common_user != NULL)
{
user = g_object_new (USER_TYPE, NULL);
user->priv->common_user = common_user;
}
return user;
}
User *
accounts_get_current_user ()
{
struct passwd *entry = getpwuid (getuid ());
if (entry != NULL)
return accounts_get_user_by_name (entry->pw_name);
else
return NULL;
}
const gchar *
user_get_name (User *user)
{
g_return_val_if_fail (user != NULL, NULL);
return common_user_get_name (user->priv->common_user);
}
uid_t
user_get_uid (User *user)
{
g_return_val_if_fail (user != NULL, 0);
return common_user_get_uid (user->priv->common_user);
}
gid_t
user_get_gid (User *user)
{
g_return_val_if_fail (user != NULL, 0);
return common_user_get_gid (user->priv->common_user);
}
const gchar *
user_get_home_directory (User *user)
{
g_return_val_if_fail (user != NULL, NULL);
return common_user_get_home_directory (user->priv->common_user);
}
const gchar *
user_get_shell (User *user)
{
g_return_val_if_fail (user != NULL, NULL);
return common_user_get_shell (user->priv->common_user);
}
void
user_set_language (User *user, const gchar *language)
{
g_return_if_fail (user != NULL);
common_user_set_language (user->priv->common_user, language);
}
const gchar *
user_get_language (User *user)
{
g_return_val_if_fail (user != NULL, NULL);
return common_user_get_language (user->priv->common_user);
}
void
user_set_xsession (User *user, const gchar *xsession)
{
g_return_if_fail (user != NULL);
common_user_set_session (user->priv->common_user, xsession);
}
const gchar *
user_get_xsession (User *user)
{
g_return_val_if_fail (user != NULL, NULL);
return common_user_get_session (user->priv->common_user);
}
static void
user_init (User *user)
{
user->priv = G_TYPE_INSTANCE_GET_PRIVATE (user, USER_TYPE, UserPrivate);
}
static void
user_finalize (GObject *object)
{
User *self = USER (object);
g_clear_object (&self->priv->common_user);
G_OBJECT_CLASS (user_parent_class)->finalize (object);
}
static void
user_class_init (UserClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
object_class->finalize = user_finalize;
g_type_class_add_private (klass, sizeof (UserPrivate));
}
|