GNU/Linux |
CentOS 3.3 |
|
getpwnam(3) |
getpwnam, getpwuid − get password file entry
#include
<pwd.h>
#include <sys/types.h>
struct passwd *getpwnam(const char *name);
struct passwd *getpwuid(uid_t uid);
The getpwnam() function returns a pointer to a structure containing the broken out fields of a line from /etc/passwd for the entry that matches the user name name.
The getpwuid() function returns a pointer to a structure containing the broken out fields of a line from /etc/passwd for the entry that matches the user uid uid.
The passwd structure is defined in <pwd.h> as follows:
struct passwd {
/* user name */ | |||
/* user password */ | |||
/* user id */ | |||
/* group id */ |
char *pw_gecos; /* real name */
/* home directory */ |
char *pw_shell; /* shell
program */
};
The getpwnam() and getpwuid() functions return a pointer to the passwd structure, or NULL if the matching entry is not found or an error occurs. If an error occurs, errno is set appropriately.
The return value may point to static area, and may be overwritten by subsequent calls.
0 or ENOENT or ESRCH or EBADF or EPERM or ...
The given name or gid was not found.
ENOMEM |
Insufficient memory to allocate passwd structure. | ||
EIO |
I/O error. | ||
EINTR |
A signal was caught. | ||
EMFILE |
The maximum number (OPEN_MAX) of files was open already in the calling process. | ||
ENFILE |
The maximum number of files was open already in the system. |
/etc/passwd
password database file
SVID 3, POSIX, BSD 4.3
The formulation given above under "RETURN VALUE" is from POSIX 1003.1-2001. It does not call "not found" an error, hence does not specify what value errno might have in this situation. But that makes it impossible to recognize errors. One might argue that according to POSIX errno should be left unchanged if an entry is not found. Experiments on various Unix-like systems shows that lots of different values occur in this situation: 0, ENOENT, EBADF, ESRCH, EWOULDBLOCK, EPERM and probably others.
fgetpwent(3), getgrnam(3), getpwent(3), setpwent(3), endpwent(3), getpw(3), putpwent(3), passwd(5)
getpwnam(3) |