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;
}
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+//;
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;
$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);
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;
}
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;
($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.
$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);