February 2012
Intermediate to advanced
1184 pages
37h 17m
English
getpwent setpwent endpwent
These functions conceptually iterate through your /etc/passwd file, though this may involve the /etc/shadow file if you’re the superuser and are using shadow passwords; it may get a lot fancier than that if you’re using some database- or network-based login system. The return value in list context is:
# 0 1 2 3 4 5 6 7 8 ($name,$passwd,$uid,$gid,$quota,$comment,$gcos,$dir,$shell) = getpwent();
Some machines may use the quota and comment fields for purposes other than their named purposes, but the remaining fields will always be the same. To set up a hash for translating login names to UIDs, say this:
while (($name, $passwd, $uid) = getpwent()) {
$uid{$name} = $uid;
}In scalar context, getpwent
returns only the username. The User::pwent module supports a by-name interface to this function. See
getpwent(3).