Accesses the basic user information in the user database.
#include <sys/types.h> #include <pwd.h>
struct passwd *getpwent ( )
struct passwd *getpwuid ( UserID)
uid_t UserID;
struct passwd *getpwnam ( Name)
char *Name;
int putpwent ( Password, File)
struct passwd *Password;
FILE *File;
void setpwent ( )
void endpwent ( )
Attention: All information generated by the getpwent, getpwnam, and getpwuid subroutines is stored in a static area. Subsequent calls to these subroutines overwrite this static area. To save the information in the static area, applications should copy it.
These subroutines access the basic user attributes.
The setpwent subroutine opens the user database if it is not already open. Then, this subroutine sets the cursor to point to the first user entry in the database. The endpwent subroutine closes the user database.
The getpwent,
getpwnam, and getpwuid subroutines return information
about a user. These subroutines do the following:
The putpwent subroutine writes a password entry into a file in the colon-separated format of the /etc/passwd file.
The getpwent,
getpwnam, and getpwuid subroutines return a
user structure. This structure The user structure
is defined in the pwd.h file and has the following
fields:
Note: If Network Information Services (NIS) is enabled on the system, these subroutines attempt to retrieve the information from the NIS authentication server before attempting to retrieve the information locally.
Files Accessed: |
Mode | File |
---|---|
rw | /etc/passwd (write access for the putpwent subroutine only) |
r | /etc/security/passwd (if the password is desired) |
The getpwent, getpwnam, and getpwuid subroutines return a pointer to a valid password structure if successful. Otherwise, a null pointer is returned.
The getpwent subroutine will return a null pointer and an errno value of ENOATTR when it detects a corrupt entry. To get subsequent entries following the corrupt entry, call the getpwent subroutine again.
These subroutines are part of Base Operating System (BOS) Runtime.
/etc/passwd | Contains user IDs and their passwords |
The getgrent (getgrent, getgrgid, getgrnam, setgrent, or endgrent Subroutine) subroutine, getgroupattr (getgroupattr, IDtogroup, nextgroup, or putgroupattr Subroutine) subroutine, getuserattr (getuserattr, IDtouser, nextuser, or putuserattr Subroutine) subroutine, getuserpw, putuserpw, or putuserpwhist (getuserpw, putuserpw, or putuserpwhist Subroutine) subroutine, setuserdb subroutine.
List of Security and Auditing Subroutines, Subroutines, Example Programs, and Libraries in AIX 5L Version 5.1 General Programming Concepts: Writing and Debugging Programs.