summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJarkko Hietaniemi <jhi@iki.fi>1998-11-28 14:27:36 +0000
committerJarkko Hietaniemi <jhi@iki.fi>1998-11-28 14:27:36 +0000
commit55ec6b6309c634e33b4056d21286b6381092bd30 (patch)
tree26a0d18c6bf7103f1b1a0256efec3c227826812d
parent6c776211791715260f0e5a2bf027aca4e5c731d8 (diff)
downloadperl-55ec6b6309c634e33b4056d21286b6381092bd30.tar.gz
Passwd and group file groveling.
p4raw-id: //depot/cfgperl@2349
-rwxr-xr-xt/op/grent.t56
-rwxr-xr-xt/op/pwent.t49
2 files changed, 80 insertions, 25 deletions
diff --git a/t/op/grent.t b/t/op/grent.t
index 9d2b01d51a..e0cd7a82c5 100755
--- a/t/op/grent.t
+++ b/t/op/grent.t
@@ -7,10 +7,18 @@ BEGIN {
my $GR = "/etc/group";
- if (($^O eq 'next' and not open(GR, "nidump group .|"))
- or (defined $Config{'i_grp'} and $Config{'i_grp'} ne 'define')
- or not -f $GR or not open(GR, $GR)
- ) {
+ $where = $GR;
+
+ if (-x "/usr/bin/nidump") {
+ if (open(GR, "nidump group . |")) {
+ $where = "NetInfo";
+ } else {
+ print "1..0\n";
+ exit 0;
+ }
+ } elsif ((defined $Config{'i_grp'} and $Config{'i_grp'} ne 'define')
+ or not -f $GR or not open(GR, $GR)
+ ) {
print "1..0\n";
exit 0;
}
@@ -19,19 +27,27 @@ BEGIN {
print "1..1\n";
# Go through at most this many groups.
-my $max = 25; #
+my $max = 25;
-my $n = 0;
-my $not;
+my $n = 0;
my $tst = 1;
+my %suspect;
+my %seen;
-$not = 0;
while (<GR>) {
- last if $n == $max;
chomp;
- @s = split /:/;
+ my @s = split /:/;
+ my ($name_s,$passwd_s,$gid_s,$members_s) = @s;
+ if (@s) {
+ push @{ $seen{$name_s} }, $.;
+ } else {
+ warn "# Your $where line $. is empty.\n";
+ next;
+ }
+ next if $n == $max;
+ # In principle we could whine if @s != 4 but do we know enough
+ # of group file formats everywhere?
if (@s == 4) {
- my ($name_s,$passwd_s,$gid_s,$members_s) = @s;
$members_s =~ s/\s*,\s*/,/g;
$members_s =~ s/\s+$//;
$members_s =~ s/^\s+//;
@@ -46,10 +62,10 @@ while (<GR>) {
next if $name_s ne $name;
}
$members =~ s/\s+/,/g;
- $not = 1, last
+ $suspect{$name_s}++
if $name ne $name_s or
# Shadow passwords confuse this.
-# Not that group passwords are used much but still.
+# Not that group passwords are used much but better not assume anything.
# $passwd ne $passwd_s or
$gid ne $gid_s or
$members ne $members_s;
@@ -57,7 +73,19 @@ while (<GR>) {
$n++;
}
-print "not " if $not;
+# Drop the multiply defined groups.
+
+foreach (sort keys %seen) {
+ my $times = @{ $seen{$_} };
+ if ($times > 1) {
+ # Multiply defined groups are rarely intentional.
+ local $" = ", ";
+ warn "# Group '$_' defined multiple times in $where, lines: @{$seen{$_}}.\n";
+ delete $suspect{$_};
+ }
+}
+
+print "not " if keys %suspect;
print "ok ", $tst++, "\n";
close(GR);
diff --git a/t/op/pwent.t b/t/op/pwent.t
index 87b2ac1f78..1365588004 100755
--- a/t/op/pwent.t
+++ b/t/op/pwent.t
@@ -7,10 +7,17 @@ BEGIN {
my $PW = "/etc/passwd";
- if (($^O eq 'next' and not open(PW, "nidump passwd .|"))
- or (defined $Config{'i_pwd'} and $Config{'i_pwd'} ne 'define')
- or not -f $PW or not open(PW, $PW)
- ) {
+ $where = $PW;
+
+ if (-x "/usr/bin/nidump") {
+ if (open(PW, "nidump passwd . |")) {
+ $where = "NetInfo";
+ } else {
+ print "1..0\n";
+ exit 0;
+ }
+ } elsif ((defined $Config{'i_pwd'} and $Config{'i_pwd'} ne 'define')
+ or not -f $PW or not open(PW, $PW)) {
print "1..0\n";
exit 0;
}
@@ -22,16 +29,24 @@ print "1..1\n";
my $max = 25; #
my $n = 0;
-my $not;
my $tst = 1;
+my %suspect;
+my %seen;
-$not = 0;
while (<PW>) {
- last if $n == $max;
chomp;
- @s = split /:/;
+ my @s = split /:/;
+ my ($name_s, $passwd_s, $uid_s, $gid_s, $gcos_s, $home_s, $shell_s) = @s;
+ if (@s) {
+ push @{ $seen{$name_s} }, $.;
+ } else {
+ warn "# Your $where line $. is empty.\n";
+ next;
+ }
+ next if $n == $max;
+ # In principle we could whine if @s != 7 but do we know enough
+ # of passwd file formats everywhere?
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;
@@ -42,7 +57,7 @@ while (<PW>) {
($name,$passwd,$uid,$gid,$quota,$comment,$gcos,$home,$shell) = @n;
next if $name_s ne $name;
}
- $not = 1, last
+ $suspect{$name_s}++
if $name ne $name_s or
# Shadow passwords confuse this.
# Think about non-crypt(3) encryptions, too, before you do anything rash.
@@ -56,7 +71,19 @@ while (<PW>) {
$n++;
}
-print "not " if $not;
+# Drop the multiply defined users.
+
+foreach (sort keys %seen) {
+ my $times = @{ $seen{$_} };
+ if ($times > 1) {
+ # Multiply defined users are rarely intentional.
+ local $" = ", ";
+ warn "# User '$_' defined multiple times in $where, lines: @{$seen{$_}}.\n";
+ delete $suspect{$_};
+ }
+}
+
+print "not " if keys %suspect;
print "ok ", $tst++, "\n";
close(PW);