6 eval {my @n = getgrgid 0};
7 if ($@ && $@ =~ /(The \w+ function is unimplemented)/) {
8 print "1..0 # Skip: $1\n";
11 eval { require Config; import Config; };
13 if ($Config{'i_grp'} ne 'define') {
14 $reason = '$Config{i_grp} not defined';
16 elsif (not -f "/etc/group" ) { # Play safe.
17 $reason = 'no /etc/group file';
20 if (not defined $where) { # Try NIS.
21 foreach my $ypcat (qw(/usr/bin/ypcat /bin/ypcat /etc/ypcat)) {
23 open(GR, "$ypcat group 2>/dev/null |") &&
32 if (not defined $where) { # Try NetInfo.
33 foreach my $nidump (qw(/usr/bin/nidump)) {
35 open(GR, "$nidump group . 2>/dev/null |") &&
37 $where = "NetInfo group";
44 if (not defined $where) { # Try local.
45 my $GR = "/etc/group";
46 if (-f $GR && open(GR, $GR) && defined(<GR>)) {
52 print "1..0 # Skip: $reason\n";
57 # By now the GR filehandle should be open and full of juicy group entries.
61 # Go through at most this many groups.
62 # (note that the first entry has been read away by now)
73 # LIMIT -1 so that groups with no users don't fall off
74 my @s = split /:/, $_, -1;
75 my ($name_s,$passwd_s,$gid_s,$members_s) = @s;
77 push @{ $seen{$name_s} }, $.;
79 warn "# Your $where line $. is empty.\n";
87 # In principle we could whine if @s != 4 but do we know enough
88 # of group file formats everywhere?
90 $members_s =~ s/\s*,\s*/,/g;
91 $members_s =~ s/\s+$//;
92 $members_s =~ s/^\s+//;
93 @n = getgrgid($gid_s);
96 my ($name,$passwd,$gid,$members) = @n;
97 # Protect against one-to-many and many-to-one mappings.
98 if ($name_s ne $name) {
99 @n = getgrnam($name_s);
100 ($name,$passwd,$gid,$members) = @n;
101 next if $name_s ne $name;
103 # NOTE: group names *CAN* contain whitespace.
104 $members =~ s/\s+/,/g;
105 # what about different orders of members?
107 if $name eq $name_s and
108 # Do not compare passwords: think shadow passwords.
109 # Not that group passwords are used much but better not assume anything.
111 $members eq $members_s;
118 if (keys %perfect == 0) {
122 # The failure of op/grent test is not necessarily serious.
123 # It may fail due to local group administration conventions.
124 # If you are for example using both NIS and local groups,
125 # test failure is possible. Any distributed group scheme
126 # can cause such failures.
128 # What the grent test is doing is that it compares the $max first
130 # with the results of getgrgid() and getgrnam() call. If it finds no
131 # matches at all, it suspects something is wrong.
140 print "\t# (not necessarily serious: run t/op/grent.t by itself)" if $not;
143 # Test both the scalar and list contexts.
149 my $gr = scalar getgrent();
150 last unless defined $gr;
159 my ($gr) = (getgrent());
160 last unless defined $gr;
165 print "not " unless "@gr1" eq "@gr2";
166 print "ok ", $tst++, "\n";