Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer

Which backend is getpwent using?

by j0se (Pilgrim)
on Jul 11, 2013 at 13:11 UTC ( #1043720=perlquestion: print w/ replies, xml ) Need Help??
j0se 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 ...

not ok 10 - duplicate uids (0 65534) # Failed test 'duplicate uids (0 65534)' # at line 57. # got: '2' # expected: '0'
... and the reason is that root (0) and nobody (65534) accounts exist both in /etc/passwd and LDAP.

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

Comment on Which backend is getpwent using?
Select or Download Code

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://1043720]
Approved by marto
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (4)
As of 2015-11-28 21:53 GMT
Find Nodes?
    Voting Booth?

    What would be the most significant thing to happen if a rope (or wire) tied the Earth and the Moon together?

    Results (746 votes), past polls