1 /* vi: set et sw=4 ts=4 cino=t0,(0: */
2 /* -*- Mode: C; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
4 * This file is part of tlm (Tizen Login Manager)
6 * Copyright (C) 2013 Intel Corporation.
8 * Contact: Amarnath Valluri <amarnath.valluri@linux.intel.com>
10 * This library is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU Lesser General Public
12 * License as published by the Free Software Foundation; either
13 * version 2.1 of the License, or (at your option) any later version.
15 * This library is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 * Lesser General Public License for more details.
20 * You should have received a copy of the GNU Lesser General Public
21 * License along with this library; if not, write to the Free Software
22 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
32 #include "tlm-account-plugin-default.h"
36 * SECTION:tlm-account-plugin-default
37 * @short_description: an default plugin for user account operation
39 * #TlmAccountPluginDefault provides a default implementation of user account
41 * - setting up guest account is performed by running 'useradd'
42 * - cleaning up guest account is performed by running 'rm -rf' on the account's
44 * - check the account validity is done using getpwnam().
46 * It is recommended to use a GUM plugin instead: see #TlmAccountPluginGumd.
51 * TlmAccountPluginDefault:
53 * Opaque data structure
56 * TlmAccountPluginDefaultClass:
57 * @parent_class: a reference to a parent class
59 * The class structure for the #TlmAccountPluginDefault objects,
67 struct _TlmAccountPluginDefault
75 _setup_guest_account (TlmAccountPlugin *plugin, const gchar *user_name)
77 gchar *command = NULL;
79 g_return_val_if_fail (plugin, FALSE);
80 g_return_val_if_fail (TLM_IS_ACCOUNT_PLUGIN_DEFAULT(plugin), FALSE);
81 g_return_val_if_fail (user_name && user_name[0], FALSE);
83 command = g_strdup_printf ("useradd %s", user_name);
84 res = system (command);
92 _cleanup_guest_user (TlmAccountPlugin *plugin,
93 const gchar *user_name,
96 struct passwd *pwd_entry = NULL;
102 g_return_val_if_fail (plugin, FALSE);
103 g_return_val_if_fail (TLM_IS_ACCOUNT_PLUGIN_DEFAULT(plugin), FALSE);
104 g_return_val_if_fail (user_name && user_name[0], FALSE);
109 pwd_entry = getpwnam (user_name);
112 DBG("Could not get info for user '%s', error : %s",
113 user_name, strerror(errno));
117 if (!pwd_entry->pw_dir) {
118 DBG("No home folder entry found for user '%s'", user_name);
122 command = g_strdup_printf ("rm -rf %s/*", pwd_entry->pw_dir);
124 res = system (command);
132 _is_valid_user (TlmAccountPlugin *plugin, const gchar *user_name)
134 struct passwd *pwd_entry = NULL;
136 g_return_val_if_fail (plugin, FALSE);
137 g_return_val_if_fail (TLM_IS_ACCOUNT_PLUGIN_DEFAULT(plugin), FALSE);
138 g_return_val_if_fail (user_name && user_name[0], FALSE);
143 pwd_entry = getpwnam (user_name);
146 DBG("Could not get info for user '%s', error : %s",
147 user_name, strerror(errno));
155 _plugin_interface_init (TlmAccountPluginInterface *iface)
157 iface->setup_guest_user_account = _setup_guest_account;
158 iface->cleanup_guest_user = _cleanup_guest_user;
159 iface->is_valid_user = _is_valid_user;
162 G_DEFINE_TYPE_WITH_CODE (TlmAccountPluginDefault, tlm_account_plugin_default,
164 G_IMPLEMENT_INTERFACE (TLM_TYPE_ACCOUNT_PLUGIN,
165 _plugin_interface_init));
169 _plugin_finalize (GObject *self)
171 TlmAccountPluginDefault *plugin = TLM_ACCOUNT_PLUGIN_DEFAULT(self);
173 if (plugin->config) g_hash_table_unref (plugin->config);
175 G_OBJECT_CLASS (tlm_account_plugin_default_parent_class)->finalize(self);
179 _plugin_set_property (GObject *object,
184 TlmAccountPluginDefault *self = TLM_ACCOUNT_PLUGIN_DEFAULT (object);
188 gpointer p = g_value_get_boxed (value);
190 self->config = g_hash_table_ref ((GHashTable *)p);
194 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
200 _plugin_get_property (GObject *object,
205 TlmAccountPluginDefault *self = TLM_ACCOUNT_PLUGIN_DEFAULT (object);
209 g_value_set_boxed (value, self->config);
212 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
218 tlm_account_plugin_default_class_init (TlmAccountPluginDefaultClass *kls)
220 GObjectClass *g_class = G_OBJECT_CLASS (kls);
222 g_class->set_property = _plugin_set_property;
223 g_class->get_property = _plugin_get_property;
224 g_class->finalize = _plugin_finalize;
226 g_object_class_override_property (g_class, PROP_CONFIG, "config");
230 tlm_account_plugin_default_init (TlmAccountPluginDefault *self)
232 tlm_log_init(G_LOG_DOMAIN);