~ubuntu-branches/ubuntu/quantal/shadow/quantal

« back to all changes in this revision

Viewing changes to lib/shadow.c

  • Committer: Bazaar Package Importer
  • Author(s): Oliver Grawert
  • Date: 2010-11-24 13:42:42 UTC
  • mfrom: (1.1.9 upstream) (18.1.4 sid)
  • Revision ID: james.westby@ubuntu.com-20101124134242-832f4tew5s81ntj7
Tags: 1:4.1.4.2+svn3283-2ubuntu1
* Merge from debian unstable.  Remaining changes:
  - Ubuntu specific:
    + debian/login.defs: use SHA512 by default for password crypt routine.
  - debian/{source_shadow.py,rules}: Add apport hook
  - debian/rules: fix FTBFS from newer libtools
  - debian/patches/495_stdout-encrypted-password: chpasswd can report
    password hashes on stdout (Debian bug 505640).
  - Rework 495_stdout-encrypted-password to cope with chpasswd using PAM.

Show diffs side-by-side

added added

removed removed

Lines of Context:
35
35
/* Newer versions of Linux libc already have shadow support.  */
36
36
#ifndef HAVE_GETSPNAM
37
37
 
38
 
#ident "$Id: shadow.c 2620 2009-04-10 22:35:14Z nekral-guest $"
 
38
#ident "$Id: shadow.c 3181 2010-03-23 08:56:52Z nekral-guest $"
39
39
 
40
40
#include <sys/types.h>
41
41
#include "prototypes.h"
42
42
#include "defines.h"
43
43
#include <stdio.h>
44
44
#ifdef  USE_NIS
45
 
static int nis_used;
46
 
static int nis_ignore;
 
45
static bool nis_used;
 
46
static bool nis_ignore;
47
47
static enum { native, start, middle, native2 } nis_state;
48
 
static int nis_bound;
 
48
static bool nis_bound;
49
49
static char *nis_domain;
50
50
static char *nis_key;
51
51
static int nis_keylen;
66
66
 * __setspNIS - turn on or off NIS searches
67
67
 */
68
68
 
69
 
void __setspNIS (int flag)
 
69
void __setspNIS (bool flag)
70
70
{
71
71
        nis_ignore = !flag;
72
72
 
73
73
        if (nis_ignore) {
74
 
                nis_used = 0;
 
74
                nis_used = false;
75
75
        }
76
76
}
77
77
 
81
81
 
82
82
static int bind_nis (void)
83
83
{
84
 
        if (yp_get_default_domain (&nis_domain))
 
84
        if (yp_get_default_domain (&nis_domain)) {
85
85
                return -1;
 
86
        }
86
87
 
87
 
        nis_bound = 1;
 
88
        nis_bound = true;
88
89
        return 0;
89
90
}
90
91
#endif
95
96
 
96
97
void setspent (void)
97
98
{
98
 
        if (shadow)
 
99
        if (NULL != shadow) {
99
100
                rewind (shadow);
100
 
        else
 
101
        }else {
101
102
                shadow = fopen (SHADOW_FILE, "r");
 
103
        }
102
104
 
103
105
#ifdef  USE_NIS
104
106
        nis_state = native;
111
113
 
112
114
void endspent (void)
113
115
{
114
 
        if (shadow)
 
116
        if (NULL != shadow) {
115
117
                (void) fclose (shadow);
 
118
        }
116
119
 
117
120
        shadow = (FILE *) 0;
118
121
}
172
175
 
173
176
        spwd.sp_namp = fields[0];
174
177
#ifdef  USE_NIS
175
 
        if (IS_NISCHAR (fields[0][0]))
176
 
                nis_used = 1;
 
178
        if (IS_NISCHAR (fields[0][0])) {
 
179
                nis_used = true;
 
180
        }
177
181
#endif
178
182
        spwd.sp_pwdp = fields[1];
179
183
 
211
215
                                spwd.sp_min = -1;
212
216
                        } else
213
217
#endif
 
218
                        {
214
219
                                return 0;
 
220
                        }
215
221
                } else if (spwd.sp_min < 0) {
216
222
                        return 0;
217
223
                }
263
269
                                spwd.sp_warn = -1;
264
270
                        } else
265
271
#endif
 
272
                        {
266
273
                                return 0;
 
274
                        }
267
275
                } else if (spwd.sp_warn < 0) {
268
276
                        return 0;
269
277
                }
283
291
                                spwd.sp_inact = -1;
284
292
                        } else
285
293
#endif
 
294
                        {
286
295
                                return 0;
 
296
                        }
287
297
                } else if (spwd.sp_inact < 0) {
288
298
                        return 0;
289
299
                }
303
313
                                spwd.sp_expire = -1;
304
314
                        } else
305
315
#endif
 
316
                        {
306
317
                                return 0;
 
318
                        }
307
319
                } else if (spwd.sp_expire < 0) {
308
320
                        return 0;
309
321
                }
324
336
                                spwd.sp_flag = SHADOW_SP_FLAG_UNSET;
325
337
                        } else
326
338
#endif
 
339
                        {
327
340
                                return 0;
 
341
                        }
328
342
                } else if (spwd.sp_flag < 0) {
329
343
                        return 0;
330
344
                }
377
391
        struct spwd *val;
378
392
        char buf[BUFSIZ];
379
393
#endif
380
 
        if (!shadow)
 
394
        if (NULL == shadow) {
381
395
                setspent ();
 
396
        }
382
397
 
383
398
#ifdef  USE_NIS
384
399
      again:
432
447
 
433
448
                return 0;
434
449
        } else {
435
 
                if (nis_bound == 0) {
 
450
                if (!nis_bound) {
436
451
                        if (bind_nis ()) {
437
452
                                nis_state = native2;
438
453
                                goto again;
440
455
                }
441
456
                if (nis_state == start) {
442
457
                        if (yp_first (nis_domain, "shadow.bynam", &nis_key,
443
 
                                      &nis_keylen, &nis_val, &nis_vallen)) {
 
458
                                      &nis_keylen, &nis_val, &nis_vallen)) {
444
459
                                nis_state = native2;
445
460
                                goto again;
446
461
                        }
447
462
                        nis_state = middle;
448
463
                } else if (nis_state == middle) {
449
464
                        if (yp_next (nis_domain, "shadow.bynam", nis_key,
450
 
                                     nis_keylen, &nis_key, &nis_keylen,
451
 
                                     &nis_val, &nis_vallen)) {
 
465
                                     nis_keylen, &nis_key, &nis_keylen,
 
466
                                     &nis_val, &nis_vallen)) {
452
467
                                nis_state = native2;
453
468
                                goto again;
454
469
                        }
471
486
#ifdef  USE_NIS
472
487
        char buf[BUFSIZ];
473
488
        static char save_name[16];
474
 
        int nis_disabled = 0;
 
489
        bool nis_disabled = false;
475
490
#endif
476
491
 
477
492
        setspent ();
481
496
         * Search the shadow.byname map for this user.
482
497
         */
483
498
 
484
 
        if (!nis_ignore && !nis_bound)
 
499
        if (!nis_ignore && !nis_bound) {
485
500
                bind_nis ();
 
501
        }
486
502
 
487
503
        if (!nis_ignore && nis_bound) {
488
504
                char *cp;
489
505
 
490
506
                if (yp_match (nis_domain, "shadow.byname", name,
491
 
                              strlen (name), &nis_val, &nis_vallen) == 0) {
 
507
                              strlen (name), &nis_val, &nis_vallen) == 0) {
492
508
 
493
509
                        cp = strchr (nis_val, '\n');
494
 
                        if (NULL != cp)
 
510
                        if (NULL != cp) {
495
511
                                *cp = '\0';
 
512
                        }
496
513
 
497
514
                        nis_state = middle;
498
515
                        sp = my_sgetspent (nis_val);
503
520
                        }
504
521
                        endspent ();
505
522
                        return sp;
506
 
                } else
 
523
                } else {
507
524
                        nis_state = native2;
 
525
                }
508
526
        }
509
527
#endif
510
528
#ifdef  USE_NIS
516
534
         */
517
535
 
518
536
        if (nis_used) {
519
 
                nis_ignore++;
520
 
                nis_disabled++;
 
537
                nis_ignore = true;
 
538
                nis_disabled = true;
521
539
        }
522
540
#endif
523
541
        while ((sp = getspent ()) != (struct spwd *) 0) {
524
 
                if (strcmp (name, sp->sp_namp) == 0)
 
542
                if (strcmp (name, sp->sp_namp) == 0) {
525
543
                        break;
 
544
                }
526
545
        }
527
546
#ifdef  USE_NIS
528
 
        if (nis_disabled)
529
 
                nis_ignore--;
 
547
        if (nis_disabled) {
 
548
                nis_ignore = false;
 
549
        }
530
550
#endif
531
551
        endspent ();
532
552
        return (sp);