NeXTstep /etc/group and /etc/passwd are used only at boot time,
[p5sagit/p5-mst-13.2.git] / t / op / grent.t
1 #!./perl
2
3 BEGIN {
4     chdir 't' if -d 't';
5     @INC = "../lib" if -d "../lib";
6     eval { require Config; import Config; };
7
8     my $GR = "/etc/group";
9
10     if ($Config{'i_grp'} ne 'define' or not -f $GR or not open(GR, $GR)
11         # NeXTstep /etc/group is used only at boot time,
12         # after that it's up to NetInfo and NIS/YP.
13         or $^O eq 'next'
14         ) {
15         print "1..0\n";
16         exit 0;
17     }
18 }
19
20 print "1..1\n";
21
22 # Go through at most this many groups.
23 my $max = 25; #
24
25 my $n = 0;
26 my $not;
27 my $tst = 1;
28
29 $not = 0;
30 while (<GR>) {
31     last if $n == $max;
32     chomp;
33     @s = split /:/;
34     if (@s == 4) {
35         my ($name_s,$passwd_s,$gid_s,$members_s) = @s;
36         $members_s =~ s/\s*,\s*/,/g;
37         $members_s =~ s/\s+$//;
38         $members_s =~ s/^\s+//;
39         @n = getgrgid($gid_s);
40         # 'nogroup' et al.
41         next unless @n;
42         my ($name,$passwd,$gid,$members) = @n;
43         # Protect against one-to-many and many-to-one mappings.
44         if ($name_s ne $name) {
45             @n = getgrnam($name_s);
46             ($name,$passwd,$gid,$members) = @n;
47             next if $name_s ne $name;
48         }
49         $members =~ s/\s+/,/g;
50         $not = 1, last
51             if $name    ne $name_s    or
52 # Shadow passwords confuse this.
53 #              $passwd  ne $passwd_s  or
54                $gid     ne $gid_s     or
55                $members ne $members_s;
56     }
57     $n++;
58 }
59
60 print "not " if $not;
61 print "ok ", $tst++, "\n";
62
63 close(GR);