This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
tolerate whitespace in /etc/group entries (suggested by Jarkko
[perl5.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         print "1..0\n";
12         exit 0;
13     }
14 }
15
16 print "1..1\n";
17
18 # Go through at most this many groups.
19 my $max = 25; #
20
21 my $n = 0;
22 my $not;
23 my $tst = 1;
24
25 $not = 0;
26 while (<GR>) {
27     last if $n == $max;
28     chomp;
29     @s = split /:/;
30     if (@s == 4) {
31         my ($name_s,$passwd_s,$gid_s,$members_s) = @s;
32         $members_s =~ s/\s*,\s*/,/g;
33         @n = getgrgid($gid_s);
34         # 'nogroup' et al.
35         next unless @n;
36         my ($name,$passwd,$gid,$members) = @n;
37         # Protect against one-to-many and many-to-one mappings.
38         if ($name_s ne $name) {
39             @n = getgrnam($name_s);
40             ($name,$passwd,$gid,$members) = @n;
41             next if $name_s ne $name;
42         }
43         $members =~ s/\s+/,/g;
44         $not = 1, last
45             if $name    ne $name_s    or
46 # Shadow passwords confuse this.
47 #              $passwd  ne $passwd_s  or
48                $gid     ne $gid_s     or
49                $members ne $members_s;
50     }
51     $n++;
52 }
53
54 print "not " if $not;
55 print "ok ", $tst++, "\n";
56
57 close(GR);