2
* Copyright (C) 2000-2002 Red Hat, Inc.
4
* This is free software; you can redistribute it and/or modify it under
5
* the terms of the GNU Library General Public License as published by
6
* the Free Software Foundation; either version 2 of the License, or
7
* (at your option) any later version.
9
* This program is distributed in the hope that it will be useful, but
10
* WITHOUT ANY WARRANTY; without even the implied warranty of
11
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12
* General Public License for more details.
14
* You should have received a copy of the GNU Library General Public
15
* License along with this program; if not, write to the Free Software
16
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19
#ident "$Id: testuser.c,v 1.17 2004/11/13 23:50:30 mitr Exp $"
27
#include "../lib/user_private.h"
30
dump_attribute(const char *attribute, struct lu_ent *ent)
36
array = lu_ent_get(ent, attribute);
38
for (i = 0; i < array->n_values; i++) {
39
value = g_value_array_get_nth(array, i);
40
if (G_VALUE_HOLDS_STRING(value))
41
g_print("attribute %s = `%s'\n", attribute,
42
g_value_get_string(value));
43
else if (G_VALUE_HOLDS_LONG(value))
44
g_print("attribute %s = %ld\n", attribute,
45
g_value_get_long(value));
46
else if (G_VALUE_HOLDS_INT64(value))
47
g_print("attribute %s = %lld\n", attribute,
48
(long long)g_value_get_int64(value));
56
struct lu_context *ctx;
57
struct lu_ent *ent, *tmp, *temp;
58
struct lu_error *error = NULL;
63
bindtextdomain(PACKAGE, LOCALEDIR);
65
setlocale(LC_ALL, "");
67
control = g_malloc0(65536);
70
lu_start(NULL, 0, NULL, NULL, lu_prompt_console, NULL, &error);
73
fprintf(stderr, gettext("Error initializing %s: %s.\n"),
74
PACKAGE, lu_strerror(error));
78
g_print(gettext("Default user object classes:\n"));
79
ret = lu_cfg_read(ctx, "userdefaults/objectclass", "bar");
80
for (i = 0; i < g_list_length(ret); i++) {
81
g_print(" %s\n", (char *) g_list_nth(ret, i)->data);
84
g_print(gettext("Default user attribute names:\n"));
85
ret = lu_cfg_read_keys(ctx, "userdefaults");
86
for (i = 0; i < g_list_length(ret); i++) {
87
g_print(" %s\n", (char *) g_list_nth(ret, i)->data);
90
g_print(gettext("Getting default user attributes:\n"));
92
lu_user_default(ctx, "newuser", FALSE, ent);
93
lu_ent_dump(ent, stdout);
95
dump_attribute(LU_UIDNUMBER, ent);
97
g_print(gettext("Copying user structure:\n"));
99
lu_ent_copy(ent, tmp);
101
lu_ent_copy(tmp, temp);
102
lu_ent_dump(temp, stdout);