Migrating AIX specific C function calls to Linux

可紊 提交于 2019-12-13 03:26:42

问题


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.hand 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 time getpwent() 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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!