#include <sys/types.h>
#include <pwd.h>
struct passwd *getpwnam(const char *name);
struct passwd {
char *pw_name; /* 用户名 */
char *pw_passwd; /* 用户密码 */
uid_t pw_uid; /* UID */
gid_t pw_gid; /* GID */
char *pw_gecos; /* 用户信息 */
char *pw_dir; /* 用户 home 目录 */
char *pw_shell; /* 使用的 shell 路径 */
};
#include <stdio.h>
#include <pwd.h>
#include <sys/types.h>
int main()
{
struct passwd *user;
user = getpwnam("beyes");
printf ("name: %s\n", user->pw_name);
printf ("uid: %d\n", user->pw_uid);
printf ("gid: %d\n", user->pw_gid);
printf ("user infomation: %s\n", user->pw_gecos);
printf ("user home: %s\n", user->pw_dir);
printf ("user shell: %s\n", user->pw_shell);
return 0;
}
./getpwnam
name: beyes
uid: 1000
gid: 100
user infomation: beyes
user home: /home/beyes
user shell: /bin/bash
欢迎光临 曲径通幽论坛 (http://www.groad.net/bbs/) | Powered by Discuz! X3.2 |