This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Add -lm to dynix/ptx POSIX hints.
[perl5.git] / t / op / pwent.t
CommitLineData
c5987ebb
JH
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
0ee42efb
GW
10 if (($^O eq 'next' and not open(PW, "nidump passwd .|"))
11 or (defined $Config{'i_pwd'} and $Config{'i_pwd'} ne 'define')
12 or not -f $PW or not open(PW, $PW)
10899c3d 13 ) {
c5987ebb
JH
14 print "1..0\n";
15 exit 0;
16 }
17}
18
19print "1..1\n";
20
21# Go through at most this many users.
22my $max = 25; #
23
24my $n = 0;
25my $not;
26my $tst = 1;
27
28$not = 0;
29while (<PW>) {
30 last if $n == $max;
31 chomp;
32 @s = split /:/;
33 if (@s == 7) {
34 my ($name_s, $passwd_s, $uid_s, $gid_s, $gcos_s, $home_s, $shell_s) = @s;
35 @n = getpwuid($uid_s);
36 # 'nobody' et al.
37 next unless @n;
38 my ($name,$passwd,$uid,$gid,$quota,$comment,$gcos,$home,$shell) = @n;
39 # Protect against one-to-many and many-to-one mappings.
40 if ($name_s ne $name) {
41 @n = getpwnam($name_s);
42 ($name,$passwd,$uid,$gid,$quota,$comment,$gcos,$home,$shell) = @n;
43 next if $name_s ne $name;
44 }
45 $not = 1, last
46 if $name ne $name_s or
47# Shadow passwords confuse this.
48# Think about non-crypt(3) encryptions, too, before you do anything rash.
49# $passwd ne $passwd_s or
50 $uid ne $uid_s or
51 $gid ne $gid_s or
52 $gcos ne $gcos_s or
53 $home ne $home_s or
54 $shell ne $shell_s;
55 }
56 $n++;
57}
58
59print "not " if $not;
60print "ok ", $tst++, "\n";
61
62close(PW);