9 eval {my @n = getgrgid 0};
10 if ($@ =~ /(The \w+ function is unimplemented)/) {
11 skip_all "getgrgid unimplemented";
14 eval { require Config; import Config; };
16 if ($Config{'i_grp'} ne 'define') {
17 $reason = '$Config{i_grp} not defined';
19 elsif (not -f "/etc/group" ) { # Play safe.
20 $reason = 'no /etc/group file';
23 if (not defined $where) { # Try NIS.
24 foreach my $ypcat (qw(/usr/bin/ypcat /bin/ypcat /etc/ypcat)) {
26 open(GR, "$ypcat group 2>/dev/null |") &&
29 print "# `ypcat group` worked\n";
31 # Check to make sure we're really using NIS.
32 if( open(NSSW, "/etc/nsswitch.conf" ) ) {
33 my($group) = grep /^\s*group:/, <NSSW>;
35 # If there's no group line, assume it default to compat.
36 if( !$group || $group !~ /(nis|compat)/ ) {
37 print "# Doesn't look like you're using NIS in ".
38 "/etc/nsswitch.conf\n";
42 $where = "NIS group - $ypcat";
49 if (not defined $where) { # Try NetInfo.
50 foreach my $nidump (qw(/usr/bin/nidump)) {
52 open(GR, "$nidump group . 2>/dev/null |") &&
55 $where = "NetInfo group - $nidump";
62 if (not defined $where) { # Try local.
63 my $GR = "/etc/group";
64 if (-f $GR && open(GR, $GR) && defined(<GR>)) {
75 # By now the GR filehandle should be open and full of juicy group entries.
79 # Go through at most this many groups.
80 # (note that the first entry has been read away by now)
88 print "# where $where\n";
90 ok( setgrent(), 'setgrent' ) || print "# $!\n";
94 # LIMIT -1 so that groups with no users don't fall off
95 my @s = split /:/, $_, -1;
96 my ($name_s,$passwd_s,$gid_s,$members_s) = @s;
98 push @{ $seen{$name_s} }, $.;
100 warn "# Your $where line $. is empty.\n";
108 # In principle we could whine if @s != 4 but do we know enough
109 # of group file formats everywhere?
111 $members_s =~ s/\s*,\s*/,/g;
112 $members_s =~ s/\s+$//;
113 $members_s =~ s/^\s+//;
114 @n = getgrgid($gid_s);
117 my ($name,$passwd,$gid,$members) = @n;
118 # Protect against one-to-many and many-to-one mappings.
119 if ($name_s ne $name) {
120 @n = getgrnam($name_s);
121 ($name,$passwd,$gid,$members) = @n;
122 next if $name_s ne $name;
124 # NOTE: group names *CAN* contain whitespace.
125 $members =~ s/\s+/,/g;
126 # what about different orders of members?
128 if $name eq $name_s and
129 # Do not compare passwords: think shadow passwords.
130 # Not that group passwords are used much but better not assume anything.
132 $members eq $members_s;
139 print "# max = $max, n = $n, perfect = ", scalar keys %perfect, "\n";
141 if (keys %perfect == 0 && $n) {
145 # The failure of op/grent test is not necessarily serious.
146 # It may fail due to local group administration conventions.
147 # If you are for example using both NIS and local groups,
148 # test failure is possible. Any distributed group scheme
149 # can cause such failures.
151 # What the grent test is doing is that it compares the $max first
153 # with the results of getgrgid() and getgrnam() call. If it finds no
154 # matches at all, it suspects something is wrong.
159 print "#\t (not necessarily serious: run t/op/grent.t by itself)\n";
164 # Test both the scalar and list contexts.
170 my $gr = scalar getgrent();
171 last unless defined $gr;
180 my ($gr) = (getgrent());
181 last unless defined $gr;