• 函数原型
  • 结构体passwd

    函数原型

    1. #include <sys/types.h>
    2. #include <pwd.h>
    3. struct passwd *getpwnam(const char *name);
    4. struct passwd *getpwuid(uid_t uid);
    5. int getpwnam_r(const char *name, struct passwd *pwd,
    6. char *buf, size_t buflen, struct passwd **result);
    7. int getpwuid_r(uid_t uid, struct passwd *pwd,
    8. char *buf, size_t buflen, struct passwd **result);

    缩写的含义
    getpwnam—->get password name
    getpwuid—->get password uid

    结构体passwd

    定义在头文件pwd.h

    1. struct passwd {
    2. char *pw_name; /* 用户名 */
    3. char *pw_passwd; /* 用户密码 */
    4. uid_t pw_uid; /* 用户ID */
    5. gid_t pw_gid; /* 用户组ID */
    6. char *pw_gecos; /* 用户信息 */
    7. char *pw_dir; /* home目录 */
    8. char *pw_shell; /* shell程序 */
    9. };