问题
I have got source files from an application on IBM AIX and I am trying to build them on Linux. However, header files named usersec.h
and userpw.h
which are there on AIX are not present on Linux. Hence, on Linux I am getting compiler error for these functions:
Declared in usersec.h
int getuserattr (char *, char *, void *, int);
More info about getuserattr
is here
Declared in userpw.h
struct userpw
{
char *upw_passwd; /* user's passwd */
unsigned int upw_flags; /* flags of restrictions */
time_t upw_lastupdate; /* date of last passwd update */
char upw_name[PW_NAMELEN]; /* user's name */
};
struct userpw *getuserpw ();
int setpwdb ();
int endpwdb ();
Please find more information: getuserpw, setpwdb and endpwdb
If anyone knows how to write equivalent functions on Linux, it would be really great.
回答1:
You likely want to use getpwent, and its related functions.
The
getpwent()
function returns a pointer to a structure containing the broken-out fields of a record from the password database (e.g., the local password file/etc/passwd
, NIS, and LDAP). The first timegetpwent()
is called, it returns the first entry; thereafter, it returns successive entries.The
setpwent()
function rewinds to the beginning of the password database.The
endpwent()
function is used to close the password database after all processing has been performed.
If you want to get the password entry of a particular user, you can use getpwnam or one of its variants.
The
getpwnam()
function returns a pointer to a structure containing the broken-out fields of the record in the password database (e.g., the local password file/etc/passwd
, NIS, and LDAP) that matches the username name.
来源:https://stackoverflow.com/questions/57062930/migrating-aix-specific-c-function-calls-to-linux