~ubuntu-branches/ubuntu/raring/libuser/raring

« back to all changes in this revision

Viewing changes to apps/lchfn.c

  • Committer: Bazaar Package Importer
  • Author(s): Anibal Monsalve Salazar
  • Date: 2006-12-28 19:18:14 UTC
  • mfrom: (2.1.1 edgy)
  • Revision ID: james.westby@ubuntu.com-20061228191814-i7ssaghc6shbsv95
Tags: 1:0.54.6-2.1.dfsg.1-1.2
* Non-maintainer upload.
* Moved all manpages of commands in /usr/sbin/ from section 1 to
  section 8 (Closes: #404020).
* Added autotools-dev as build-dependency.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*
2
 
 * Copyright (C) 2001, 2002, 2004 Red Hat, Inc.
 
2
 * Copyright (C) 2001, 2002, 2004, 2006 Red Hat, Inc.
3
3
 *
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.
17
17
 */
18
18
 
19
 
#ident "$Id: lchfn.c,v 1.23 2005/09/12 21:52:02 mitr Exp $"
 
19
#ident "$Id: lchfn.c,v 1.25 2006/03/06 03:02:52 mitr Exp $"
20
20
 
21
21
#ifdef HAVE_CONFIG_H
22
22
#include "config.h"
43
43
int
44
44
main(int argc, const char **argv)
45
45
{
46
 
        const char *user = NULL, *gecos = NULL, *sn, *gn, *email, *filtered;
 
46
        const char *user, *gecos;
47
47
        const char *name, *office, *officephone, *homephone;
48
 
        struct lu_context *ctx = NULL;
 
48
        struct lu_context *ctx;
49
49
        struct lu_error *error = NULL;
50
 
        struct lu_ent *ent = NULL;
 
50
        struct lu_ent *ent;
51
51
        GValueArray *values;
52
52
        GValue *value, val;
53
53
        int interactive = FALSE;
62
62
        char **fields;
63
63
        size_t fields_len;
64
64
        size_t pcount, i;
65
 
        struct passwd *pwd = NULL;
66
65
 
67
66
        /* Set up i18n. */
68
67
        bindtextdomain(PACKAGE, LOCALEDIR);
84
83
        /* If no user name was specified, or we're running in a setuid
85
84
         * environment, force the user name to be the current user. */
86
85
        if ((user == NULL) || (geteuid() != getuid())) {
 
86
                struct passwd *pwd;
 
87
 
87
88
                pwd = getpwuid(getuid());
88
89
                if (pwd != NULL) {
89
90
                        user = g_strdup(pwd->pw_name);
149
150
        /* If we have it, prompt for the user's surname. */
150
151
        values = lu_ent_get(ent, LU_SN);
151
152
        if (values != NULL) {
 
153
                const char *sn;
 
154
 
152
155
                value = g_value_array_get_nth(values, 0);
153
156
                sn = lu_value_strdup(value);
154
157
                prompts[pcount].key = SURNAME_KEY;
162
165
        /* If we have it, prompt for the user's givenname. */
163
166
        values = lu_ent_get(ent, LU_GIVENNAME);
164
167
        if (values != NULL) {
 
168
                const char *gn;
 
169
 
165
170
                value = g_value_array_get_nth(values, 0);
166
171
                gn = lu_value_strdup(value);
167
172
                prompts[pcount].key = GIVENNAME_KEY;
202
207
        /* If we have it, prompt for the user's email. */
203
208
        values = lu_ent_get(ent, LU_EMAIL);
204
209
        if (values != NULL) {
 
210
                const char *email;
 
211
 
205
212
                value = g_value_array_get_nth(values, 0);
206
213
                email = lu_value_strdup(value);
207
214
                prompts[pcount].key = EMAIL_KEY;
228
235
 
229
236
        /* Now iterate over the answers and figure things out. */
230
237
        for (i = 0; i < pcount; i++) {
 
238
                const char *filtered;
 
239
 
231
240
                if (prompts[i].value == NULL) {
232
241
                        filtered = "";
233
242
                } else
238
247
                }
239
248
                g_value_set_string(&val, filtered);
240
249
 
241
 
                if (strcmp(prompts[i].key, NAME_KEY) == 0) {
242
 
                        name = filtered;
243
 
                        lu_ent_clear(ent, LU_COMMONNAME);
244
 
                        if (strlen(filtered) > 0) {
245
 
                                lu_ent_add(ent, LU_COMMONNAME, &val);
246
 
                        }
247
 
                }
248
 
 
249
 
                if (strcmp(prompts[i].key, SURNAME_KEY) == 0) {
250
 
                        sn = filtered;
251
 
                        lu_ent_clear(ent, LU_SN);
252
 
                        if (strlen(filtered) > 0) {
253
 
                                lu_ent_add(ent, LU_SN, &val);
254
 
                        }
255
 
                }
256
 
 
257
 
                if (strcmp(prompts[i].key, GIVENNAME_KEY) == 0) {
258
 
                        gn = filtered;
259
 
                        lu_ent_clear(ent, LU_GIVENNAME);
260
 
                        if (strlen(filtered) > 0) {
261
 
                                lu_ent_add(ent, LU_GIVENNAME, &val);
262
 
                        }
263
 
                }
264
 
 
265
 
                if (strcmp(prompts[i].key, OFFICE_KEY) == 0) {
266
 
                        office = filtered;
267
 
                        lu_ent_clear(ent, LU_ROOMNUMBER);
268
 
                        if (strlen(filtered) > 0) {
269
 
                                lu_ent_add(ent, LU_ROOMNUMBER, &val);
270
 
                        }
271
 
                }
272
 
 
273
 
                if (strcmp(prompts[i].key, OFFICEPHONE_KEY) == 0) {
274
 
                        officephone = filtered;
275
 
                        lu_ent_clear(ent, LU_TELEPHONENUMBER);
276
 
                        if (strlen(filtered) > 0) {
277
 
                                lu_ent_add(ent, LU_TELEPHONENUMBER, &val);
278
 
                        }
279
 
                }
280
 
 
281
 
                if (strcmp(prompts[i].key, HOMEPHONE_KEY) == 0) {
282
 
                        homephone = filtered;
283
 
                        lu_ent_clear(ent, LU_HOMEPHONE);
284
 
                        if (strlen(filtered) > 0) {
285
 
                                lu_ent_add(ent, LU_HOMEPHONE, &val);
286
 
                        }
287
 
                }
288
 
 
289
 
                if (strcmp(prompts[i].key, EMAIL_KEY) == 0) {
290
 
                        email = filtered;
291
 
                        lu_ent_clear(ent, LU_EMAIL);
292
 
                        if (strlen(filtered) > 0) {
293
 
                                lu_ent_add(ent, LU_EMAIL, &val);
294
 
                        }
295
 
                }
 
250
#define ATTR__(KEY, EXTRA, ATTR)                                \
 
251
                if (strcmp(prompts[i].key, KEY) == 0) {         \
 
252
                        EXTRA;                                  \
 
253
                        lu_ent_clear(ent, ATTR);                \
 
254
                        if (strlen(filtered) > 0)               \
 
255
                                lu_ent_add(ent, ATTR, &val);    \
 
256
                }
 
257
#define ATTR(KEY, ATTR_) ATTR__(KEY, , ATTR_)
 
258
#define NAMED_ATTR(KEY, NAME, ATTR_) ATTR__(KEY, NAME = filtered, ATTR_)
 
259
 
 
260
                NAMED_ATTR(NAME_KEY, name, LU_COMMONNAME);
 
261
                ATTR(SURNAME_KEY, LU_SN);
 
262
                ATTR(GIVENNAME_KEY, LU_GIVENNAME);
 
263
                NAMED_ATTR(OFFICE_KEY, office, LU_ROOMNUMBER);
 
264
                NAMED_ATTR(OFFICEPHONE_KEY, officephone, LU_TELEPHONENUMBER);
 
265
                NAMED_ATTR(HOMEPHONE_KEY, homephone, LU_HOMEPHONE);
 
266
                ATTR(EMAIL_KEY, LU_EMAIL);
 
267
#undef NAMED_ATTR
 
268
#undef ATTR
 
269
#undef ATTR__
296
270
        }
297
271
 
298
272
        g_value_reset(&val);
328
302
        } else {
329
303
                fprintf(stderr, _("Finger information not changed: %s.\n"),
330
304
                        lu_strerror(error));
 
305
                return 1;
331
306
        }
332
307
 
333
308
        g_value_unset(&val);