6 eval {my @n = getpwuid 0; setpwent()};
7 if ($@ && $@ =~ /(The \w+ function is unimplemented)/) {
8 print "1..0 # Skip: $1\n";
11 eval { require Config; import Config; };
13 if ($Config{'i_pwd'} ne 'define') {
14 $reason = '$Config{i_pwd} undefined';
16 elsif (not -f "/etc/passwd" ) { # Play safe.
17 $reason = 'no /etc/passwd file';
20 if (not defined $where) { # Try NIS.
21 foreach my $ypcat (qw(/usr/bin/ypcat /bin/ypcat /etc/ypcat)) {
23 open(PW, "$ypcat passwd 2>/dev/null |") &&
25 $where = "NIS passwd";
32 if (not defined $where) { # Try NetInfo.
33 foreach my $nidump (qw(/usr/bin/nidump)) {
35 open(PW, "$nidump passwd . 2>/dev/null |") &&
37 $where = "NetInfo passwd";
44 if (not defined $where) { # Try local.
45 my $PW = "/etc/passwd";
46 if (-f $PW && open(PW, $PW) && defined(<PW>)) {
52 if (not defined $where) { # Try NIS+
53 foreach my $niscat (qw(/bin/niscat)) {
55 open(PW, "$niscat passwd.org_dir 2>/dev/null |") &&
57 $where = "NIS+ $niscat passwd.org_dir";
64 if ($reason) { # Give up.
65 print "1..0 # Skip: $reason\n";
70 # By now the PW filehandle should be open and full of juicy password entries.
74 # Go through at most this many users.
75 # (note that the first entry has been read away by now)
83 print "# where $where\n";
89 # LIMIT -1 so that users with empty shells don't fall off
90 my @s = split /:/, $_, -1;
91 my ($name_s, $passwd_s, $uid_s, $gid_s, $gcos_s, $home_s, $shell_s);
92 (my $v) = $Config{osvers} =~ /^(\d+)/;
93 if ($^O eq 'darwin' && $v < 9) {
94 ($name_s, $passwd_s, $uid_s, $gid_s, $gcos_s, $home_s, $shell_s) = @s[0,1,2,3,7,8,9];
96 ($name_s, $passwd_s, $uid_s, $gid_s, $gcos_s, $home_s, $shell_s) = @s;
98 next if /^\+/; # ignore NIS includes
100 push @{ $seen{$name_s} }, $.;
102 warn "# Your $where line $. is empty.\n";
110 # In principle we could whine if @s != 7 but do we know enough
111 # of passwd file formats everywhere?
112 if (@s == 7 || ($^O eq 'darwin' && @s == 10)) {
113 @n = getpwuid($uid_s);
116 my ($name,$passwd,$uid,$gid,$quota,$comment,$gcos,$home,$shell) = @n;
117 # Protect against one-to-many and many-to-one mappings.
118 if ($name_s ne $name) {
119 @n = getpwnam($name_s);
120 ($name,$passwd,$uid,$gid,$quota,$comment,$gcos,$home,$shell) = @n;
121 next if $name_s ne $name;
124 if $name eq $name_s and
126 # Do not compare passwords: think shadow passwords.
137 print "# max = $max, n = $n, perfect = ", scalar keys %perfect, "\n";
139 if (keys %perfect == 0 && $n) {
143 # The failure of op/pwent test is not necessarily serious.
144 # It may fail due to local password administration conventions.
145 # If you are for example using both NIS and local passwords,
146 # test failure is possible. Any distributed password scheme
147 # can cause such failures.
149 # What the pwent test is doing is that it compares the $max first
151 # with the results of getpwuid() and getpwnam() call. If it finds no
152 # matches at all, it suspects something is wrong.
161 print "\t# (not necessarily serious: run t/op/pwent.t by itself)" if $not;
164 # Test both the scalar and list contexts.
170 my $pw = scalar getpwent();
171 last unless defined $pw;
180 my ($pw) = (getpwent());
181 last unless defined $pw;
186 print "not " unless "@pw1" eq "@pw2";
187 print "ok ", $tst++, "\n";