Detypo.
[p5sagit/p5-mst-13.2.git] / t / op / pwent.t
CommitLineData
c5987ebb 1#!./perl
2
3BEGIN {
4 chdir 't' if -d 't';
5 @INC = "../lib" if -d "../lib";
6 eval { require Config; import Config; };
7
8 my $PW = "/etc/passwd";
9
55ec6b63 10 $where = $PW;
11
aa240144 12 if (-x "/usr/bin/nidump") { # nidump is not just NeXT/OpenStep
55ec6b63 13 if (open(PW, "nidump passwd . |")) {
aa240144 14 $where = "NetInfo passwd";
55ec6b63 15 } else {
16 print "1..0\n";
17 exit 0;
18 }
19 } elsif ((defined $Config{'i_pwd'} and $Config{'i_pwd'} ne 'define')
20 or not -f $PW or not open(PW, $PW)) {
c5987ebb 21 print "1..0\n";
22 exit 0;
23 }
24}
25
26print "1..1\n";
27
28# Go through at most this many users.
29my $max = 25; #
30
31my $n = 0;
c5987ebb 32my $tst = 1;
55ec6b63 33my %suspect;
34my %seen;
c5987ebb 35
c5987ebb 36while (<PW>) {
c5987ebb 37 chomp;
6b3b4714 38 next if /^\+/; # ignore NIS includes
55ec6b63 39 my @s = split /:/;
40 my ($name_s, $passwd_s, $uid_s, $gid_s, $gcos_s, $home_s, $shell_s) = @s;
41 if (@s) {
42 push @{ $seen{$name_s} }, $.;
43 } else {
44 warn "# Your $where line $. is empty.\n";
45 next;
46 }
47 next if $n == $max;
48 # In principle we could whine if @s != 7 but do we know enough
49 # of passwd file formats everywhere?
c5987ebb 50 if (@s == 7) {
c5987ebb 51 @n = getpwuid($uid_s);
52 # 'nobody' et al.
53 next unless @n;
54 my ($name,$passwd,$uid,$gid,$quota,$comment,$gcos,$home,$shell) = @n;
55 # Protect against one-to-many and many-to-one mappings.
56 if ($name_s ne $name) {
57 @n = getpwnam($name_s);
58 ($name,$passwd,$uid,$gid,$quota,$comment,$gcos,$home,$shell) = @n;
59 next if $name_s ne $name;
60 }
55ec6b63 61 $suspect{$name_s}++
c5987ebb 62 if $name ne $name_s or
63# Shadow passwords confuse this.
64# Think about non-crypt(3) encryptions, too, before you do anything rash.
65# $passwd ne $passwd_s or
66 $uid ne $uid_s or
67 $gid ne $gid_s or
68 $gcos ne $gcos_s or
69 $home ne $home_s or
70 $shell ne $shell_s;
71 }
72 $n++;
73}
74
55ec6b63 75# Drop the multiply defined users.
76
77foreach (sort keys %seen) {
78 my $times = @{ $seen{$_} };
79 if ($times > 1) {
80 # Multiply defined users are rarely intentional.
81 local $" = ", ";
521ee3dc 82 print "# User '$_' defined multiple times in $where, lines: @{$seen{$_}}.\n";
55ec6b63 83 delete $suspect{$_};
84 }
85}
86
87print "not " if keys %suspect;
c5987ebb 88print "ok ", $tst++, "\n";
89
90close(PW);