diff options
author | Michael G. Schwern <schwern@pobox.com> | 2001-12-12 00:27:02 -0500 |
---|---|---|
committer | Jarkko Hietaniemi <jhi@iki.fi> | 2001-12-12 14:05:28 +0000 |
commit | ae4ed236b7ef647fa2879af623202de5e0cd155b (patch) | |
tree | a1ec8de364fdb5cdef19b771b71893fb30511cf9 | |
parent | 267513dcf93555b9d782ab7af9dedf89d948c674 (diff) | |
download | perl-ae4ed236b7ef647fa2879af623202de5e0cd155b.tar.gz |
ypcat working, but NIS not used
Message-ID: <20011212102702.GW17250@blackrider>
(the op/grent part)
p4raw-id: //depot/perl@13656
-rwxr-xr-x | t/op/grent.t | 117 |
1 files changed, 66 insertions, 51 deletions
diff --git a/t/op/grent.t b/t/op/grent.t index 68569e924a..3611c1b890 100755 --- 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(<GR>)) { - $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(<GR>)) + { + print "# `ypcat group` worked\n"; + + # Check to make sure we're really using NIS. + if( open(NSSW, "/etc/nsswitch.conf" ) ) { + my($group) = grep /^\s*group:/, <NSSW>; + + # If there's 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(<GR>)) { - $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(<GR>)) + { + $where = "NetInfo group - $nidump"; + undef $reason; + last; + } } +} - if (not defined $where) { # Try local. - my $GR = "/etc/group"; - if (-f $GR && open(GR, $GR) && defined(<GR>)) { - 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(<GR>)) { + 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,7 +87,7 @@ my %seen; print "# where $where\n"; -setgrent(); +ok( setgrent(), 'setgrent' ) || print "# $!\n"; while (<GR>) { chomp; @@ -136,14 +154,12 @@ if (keys %perfect == 0 && $n) { # matches at all, it suspects something is wrong. # EOEX - print "not "; - $not = 1; + + fail(); + print "#\t (not necessarily serious: run t/op/grent.t by itself)\n"; } else { - $not = 0; + pass(); } -print "ok ", $tst++; -print "\t# (not necessarily serious: run t/op/grent.t by itself)" if $not; -print "\n"; # Test both the scalar and list contexts. @@ -167,7 +183,6 @@ for (1..$max) { } endgrent(); -print "not " unless "@gr1" eq "@gr2"; -print "ok ", $tst++, "\n"; +is("@gr1", "@gr2"); close(GR); |