reisinge has asked for the wisdom of the Perl Monks concerning the following question:
Hello Monks,
I have the following code to find duplicate UIDs:
use strict; use warnings; use User::pwent; # overrides normal getpwent() use Test::More 'no_plan'; # Duplicate UIDs my @dups = duplicate_uids(); is( @dups, 0, "duplicate uids (@dups)" ); sub duplicate_uids { my @uids; while ( my $pwent = getpwent() ) { push @uids, $pwent->uid; } endpwent(); my %seen = (); my @dups = grep { $seen{$_}++ } @uids; if (@dups) { return @dups; } else { return 0; } }
I'm getting this output ...
... and the reason is that root (0) and nobody (65534) accounts exist both in /etc/passwd and LDAP.not ok 10 - duplicate uids (0 65534) # Failed test 'duplicate uids (0 65534)' # at sys-test.pl line 57. # got: '2' # expected: '0'
Is there a way to distinguish between various user account backends (e.g. /etc/passwd, LDAP) from within a Perl program using getpwent?
Well done is better than well said. -- Benjamin Franklin
|
|---|