February 2012
Intermediate to advanced
1184 pages
37h 17m
English
getpwnam NAMEThis function translates a username to the corresponding /etc/passwd file entry. 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) = getpwnam("daemon");On systems that support shadow passwords, you will have to be the superuser to retrieve the actual password. Your C library should notice that you’re suitably empowered and open the /etc/shadow file (or wherever it keeps the shadow file). At least, that’s how it’s supposed to work.
For repeated lookups, consider caching the data in a hash using
getpwent.
In scalar context, getpwnam
returns only the numeric user ID. The User::pwent module supports a by-name interface to this function. See
getpwnam(3) and
passwd(5).
Read now
Unlock full access