Change#2284 aid: allow also for plain old MSG_ and SCM_ #defines.
[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
10899c3d 10 if ($Config{'i_pwd'} ne 'define' or not -f $PW or not open(PW, $PW)
11 # NeXTstep /etc/passwd is used only at boot time,
12 # after that it's up to NetInfo and NIS/YP.
13 or $^O eq 'next'
14 ) {
c5987ebb 15 print "1..0\n";
16 exit 0;
17 }
18}
19
20print "1..1\n";
21
22# Go through at most this many users.
23my $max = 25; #
24
25my $n = 0;
26my $not;
27my $tst = 1;
28
29$not = 0;
30while (<PW>) {
31 last if $n == $max;
32 chomp;
33 @s = split /:/;
34 if (@s == 7) {
35 my ($name_s, $passwd_s, $uid_s, $gid_s, $gcos_s, $home_s, $shell_s) = @s;
36 @n = getpwuid($uid_s);
37 # 'nobody' et al.
38 next unless @n;
39 my ($name,$passwd,$uid,$gid,$quota,$comment,$gcos,$home,$shell) = @n;
40 # Protect against one-to-many and many-to-one mappings.
41 if ($name_s ne $name) {
42 @n = getpwnam($name_s);
43 ($name,$passwd,$uid,$gid,$quota,$comment,$gcos,$home,$shell) = @n;
44 next if $name_s ne $name;
45 }
46 $not = 1, last
47 if $name ne $name_s or
48# Shadow passwords confuse this.
49# Think about non-crypt(3) encryptions, too, before you do anything rash.
50# $passwd ne $passwd_s or
51 $uid ne $uid_s or
52 $gid ne $gid_s or
53 $gcos ne $gcos_s or
54 $home ne $home_s or
55 $shell ne $shell_s;
56 }
57 $n++;
58}
59
60print "not " if $not;
61print "ok ", $tst++, "\n";
62
63close(PW);