2
* Copyright (C) 2001, 2002, 2004 Red Hat, Inc.
2
* Copyright (C) 2001, 2002, 2004, 2006 Red Hat, Inc.
4
4
* This is free software; you can redistribute it and/or modify it under
5
5
* the terms of the GNU Library General Public License as published by
16
16
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19
#ident "$Id: lid.c,v 1.18 2004/11/13 23:50:28 mitr Exp $"
19
#ident "$Id: lid.c,v 1.20 2006/03/06 03:02:52 mitr Exp $"
21
21
#ifdef HAVE_CONFIG_H
22
22
#include "config.h"
31
31
#include "../lib/user.h"
32
32
#include "apputil.h"
35
do_id (struct lu_context *ctx, const char *name, int nameonly,
36
GValueArray *(*enumerate) (lu_context_t *, const char *, lu_error_t **),
37
gboolean (*lookup) (lu_context_t *, const char *, struct lu_ent *,
39
const char *id_attribute, const char *id_descr)
42
struct lu_error *error;
45
values = enumerate(ctx, name, &error);
47
fprintf(stderr, _("Error looking up %s: %s\n"), name,
49
lu_error_free(&error);
57
for (i = 0; i < values->n_values; i++) {
61
value = g_value_array_get_nth(values, i);
62
found = g_value_get_string(value);
63
if (!nameonly && lookup(ctx, found, ent, &error)) {
66
attrs = lu_ent_get(ent, id_attribute);
70
value = g_value_array_get_nth(attrs,
72
tmp = lu_value_strdup(value);
73
g_print(" %s(%s=%s)\n", found,
77
g_print(" %s\n", found);
80
lu_error_free(&error);
81
g_print(" %s\n", found);
83
lu_ent_clear_all(ent);
86
g_value_array_free(values);
35
91
main(int argc, const char **argv)
37
const char *name = NULL;
39
struct lu_context *ctx = NULL;
94
struct lu_context *ctx;
40
95
struct lu_error *error = NULL;
41
struct lu_ent *ent = NULL;
42
GValueArray *values, *attrs;
44
96
int interactive = FALSE;
45
97
int groupflag = FALSE, nameonly = FALSE;
49
struct passwd *pwd = NULL;
50
struct group *grp = NULL;
51
100
struct poptOption options[] = {
52
101
{"interactive", 'i', POPT_ARG_NONE, &interactive, 0,
53
102
"prompt for all information", NULL},
117
values = lu_users_enumerate_by_group(ctx, name, &error);
118
if (values != NULL) {
120
for (i = 0; i < values->n_values; i++) {
121
value = g_value_array_get_nth(values, i);
122
name = g_value_get_string(value);
124
&& lu_user_lookup_name(ctx,
128
attrs = lu_ent_get(ent, LU_UIDNUMBER);
130
value = g_value_array_get_nth(attrs,
132
tmp = lu_value_strdup(value);
133
g_print(" %s(uid=%s)\n",
137
g_print(" %s\n", name);
141
lu_error_free(&error);
143
g_print(" %s\n", name);
145
lu_ent_clear_all(ent);
148
g_value_array_free(values);
151
values = lu_groups_enumerate_by_user(ctx, name, &error);
152
if (values != NULL) {
154
for (i = 0; i < values->n_values; i++) {
155
value = g_value_array_get_nth(values, i);
156
name = g_value_get_string(value);
158
lu_group_lookup_name(ctx,
162
attrs = lu_ent_get(ent, LU_GIDNUMBER);
164
value = g_value_array_get_nth(attrs,
166
tmp = lu_value_strdup(value);
167
g_print(" %s(gid=%s)\n",
172
g_print(" %s\n", name);
176
lu_error_free(&error);
178
g_print(" %s\n", name);
180
lu_ent_clear_all(ent);
183
g_value_array_free(values);
170
do_id(ctx, name, nameonly, lu_users_enumerate_by_group,
171
lu_user_lookup_name, LU_UIDNUMBER, "uid");
173
do_id(ctx, name, nameonly, lu_groups_enumerate_by_user,
174
lu_group_lookup_name, LU_GIDNUMBER, "gid");