X-Git-Url: https://perl5.git.perl.org/perl5.git/blobdiff_plain/f0debaab11acfe6992f6da4af7eac8825f6da4d8..c61bfa6a701e953e78a132a0e8c5c48f9f31082e:/t/op/grent.t diff --git a/t/op/grent.t b/t/op/grent.t old mode 100755 new mode 100644 index 3ef111d..3b28619 --- a/t/op/grent.t +++ b/t/op/grent.t @@ -3,60 +3,78 @@ BEGIN { chdir 't' if -d 't'; @INC = '../lib'; - eval {my @n = getgrgid 0}; - if ($@ && $@ =~ /(The \w+ function is unimplemented)/) { - print "1..0 # Skip: $1\n"; - exit 0; - } - eval { require Config; import Config; }; - my $reason; - if ($Config{'i_grp'} ne 'define') { + require './test.pl'; +} + +eval {my @n = getgrgid 0}; +if ($@ =~ /(The \w+ function is unimplemented)/) { + skip_all "getgrgid unimplemented"; +} + +eval { require Config; import Config; }; +my $reason; +if ($Config{'i_grp'} ne 'define') { $reason = '$Config{i_grp} not defined'; - } - elsif (not -f "/etc/group" ) { # Play safe. +} +elsif (not -f "/etc/group" ) { # Play safe. $reason = 'no /etc/group file'; - } +} - if (not defined $where) { # Try NIS. - foreach my $ypcat (qw(/usr/bin/ypcat /bin/ypcat /etc/ypcat)) { - if (-x $ypcat && - open(GR, "$ypcat group 2>/dev/null |") && - defined()) { - $where = "NIS group"; - undef $reason; - last; - } - } +if (not defined $where) { # Try NIS. + foreach my $ypcat (qw(/usr/bin/ypcat /bin/ypcat /etc/ypcat)) { + if (-x $ypcat && + open(GR, "$ypcat group 2>/dev/null |") && + defined()) + { + print "# `ypcat group` worked\n"; + + # Check to make sure we are really using NIS. + if( open(NSSW, "/etc/nsswitch.conf" ) ) { + my($group) = grep /^\s*group:/, ; + + # If there is no group line, assume it default to compat. + if( !$group || $group !~ /(nis|compat)/ ) { + print "# Doesn't look like you're using NIS in ". + "/etc/nsswitch.conf\n"; + last; + } + } + $where = "NIS group - $ypcat"; + undef $reason; + last; + } } +} - if (not defined $where) { # Try NetInfo. - foreach my $nidump (qw(/usr/bin/nidump)) { - if (-x $nidump && - open(GR, "$nidump group . 2>/dev/null |") && - defined()) { - $where = "NetInfo group"; - undef $reason; - last; - } - } +if (not defined $where) { # Try NetInfo. + foreach my $nidump (qw(/usr/bin/nidump)) { + if (-x $nidump && + open(GR, "$nidump group . 2>/dev/null |") && + defined()) + { + $where = "NetInfo group - $nidump"; + undef $reason; + last; + } } +} - if (not defined $where) { # Try local. - my $GR = "/etc/group"; - if (-f $GR && open(GR, $GR) && defined()) { - undef $reason; - $where = $GR; - } - } - if ($reason) { - print "1..0 # Skip: $reason\n"; - exit 0; +if (not defined $where) { # Try local. + my $GR = "/etc/group"; + if (-f $GR && open(GR, $GR) && defined()) { + undef $reason; + $where = "local $GR"; } } +if ($reason) { + skip_all $reason; +} + + # By now the GR filehandle should be open and full of juicy group entries. -print "1..2\n"; +plan tests => 3; # Go through at most this many groups. # (note that the first entry has been read away by now) @@ -69,11 +87,11 @@ my %seen; print "# where $where\n"; -setgrent(); +ok( setgrent(), 'setgrent' ) || print "# $!\n"; while () { chomp; - # LIMIT -1 so that groups with no users don't fall off + # LIMIT -1 so that groups with no users do not fall off my @s = split /:/, $_, -1; my ($name_s,$passwd_s,$gid_s,$members_s) = @s; if (@s) { @@ -120,7 +138,7 @@ endgrent(); print "# max = $max, n = $n, perfect = ", scalar keys %perfect, "\n"; -if (keys %perfect < $n) { +if (keys %perfect == 0 && $n) { $max++; print <