From: Jarkko Hietaniemi Date: Sun, 2 Aug 1998 22:05:28 +0000 (+0300) Subject: 5.005_02-TRIAL1 or 5.004_05-MAINT_TRIAL_5: t/op/{pw,gr}ent.t X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=c5987ebb451d843cbf0a792310f25ebaec3f7378;p=p5sagit%2Fp5-mst-13.2.git 5.005_02-TRIAL1 or 5.004_05-MAINT_TRIAL_5: t/op/{pw,gr}ent.t Message-Id: <199808021905.WAA10592@alpha.hut.fi> p4raw-id: //depot/perl@1762 --- diff --git a/MANIFEST b/MANIFEST index f99b045..3f0d481 100644 --- a/MANIFEST +++ b/MANIFEST @@ -1064,6 +1064,7 @@ t/op/fork.t See if fork works t/op/glob.t See if <*> works t/op/goto.t See if goto works t/op/goto_xs.t See if "goto &sub" works on XSUBs +t/op/grent.t See if getgr*() functions work t/op/groups.t See if $( works t/op/gv.t See if typeglobs work t/op/hashwarn.t See if warnings for bad hash assignments work @@ -1085,6 +1086,7 @@ t/op/pack.t See if pack and unpack work t/op/pat.t See if esoteric patterns work t/op/pos.t See if pos works t/op/push.t See if push and pop work +t/op/pwent.t See if getpw*() functions work t/op/quotemeta.t See if quotemeta works t/op/rand.t See if rand works t/op/range.t See if .. works diff --git a/t/op/grent.t b/t/op/grent.t new file mode 100755 index 0000000..3930653 --- /dev/null +++ b/t/op/grent.t @@ -0,0 +1,56 @@ +#!./perl + +BEGIN { + chdir 't' if -d 't'; + @INC = "../lib" if -d "../lib"; + eval { require Config; import Config; }; + + my $GR = "/etc/group"; + + if ($Config{'i_grp'} ne 'define' or not -f $GR or not open(GR, $GR)) { + print "1..0\n"; + exit 0; + } +} + +print "1..1\n"; + +# Go through at most this many groups. +my $max = 25; # + +my $n = 0; +my $not; +my $tst = 1; + +$not = 0; +while () { + last if $n == $max; + chomp; + @s = split /:/; + if (@s == 4) { + my ($name_s,$passwd_s,$gid_s,$members_s) = @s; + @n = getgrgid($gid_s); + # 'nogroup' et al. + next unless @n; + my ($name,$passwd,$gid,$members) = @n; + # Protect against one-to-many and many-to-one mappings. + if ($name_s ne $name) { + @n = getgrnam($name_s); + ($name,$passwd,$gid,$members) = @n; + next if $name_s ne $name; + } + $members =~ s/ /,/g; + $not = 1, last + if $name ne $name_s or +# Shadow passwords confuse this. +# $passwd ne $passwd_s or + $gid ne $gid_s or + $members ne $members_s; + } + $n++; +} + +print "not " if $not; +print "ok ", $tst++, "\n"; + +close(GR); diff --git a/t/op/pwent.t b/t/op/pwent.t new file mode 100755 index 0000000..8fd9ce0 --- /dev/null +++ b/t/op/pwent.t @@ -0,0 +1,59 @@ +#!./perl + +BEGIN { + chdir 't' if -d 't'; + @INC = "../lib" if -d "../lib"; + eval { require Config; import Config; }; + + my $PW = "/etc/passwd"; + + if ($Config{'i_pwd'} ne 'define' or not -f $PW or not open(PW, $PW)) { + print "1..0\n"; + exit 0; + } +} + +print "1..1\n"; + +# Go through at most this many users. +my $max = 25; # + +my $n = 0; +my $not; +my $tst = 1; + +$not = 0; +while () { + last if $n == $max; + chomp; + @s = split /:/; + if (@s == 7) { + my ($name_s, $passwd_s, $uid_s, $gid_s, $gcos_s, $home_s, $shell_s) = @s; + @n = getpwuid($uid_s); + # 'nobody' et al. + next unless @n; + my ($name,$passwd,$uid,$gid,$quota,$comment,$gcos,$home,$shell) = @n; + # Protect against one-to-many and many-to-one mappings. + if ($name_s ne $name) { + @n = getpwnam($name_s); + ($name,$passwd,$uid,$gid,$quota,$comment,$gcos,$home,$shell) = @n; + next if $name_s ne $name; + } + $not = 1, last + if $name ne $name_s or +# Shadow passwords confuse this. +# Think about non-crypt(3) encryptions, too, before you do anything rash. +# $passwd ne $passwd_s or + $uid ne $uid_s or + $gid ne $gid_s or + $gcos ne $gcos_s or + $home ne $home_s or + $shell ne $shell_s; + } + $n++; +} + +print "not " if $not; +print "ok ", $tst++, "\n"; + +close(PW);