# Include <stdio. h>
# Include <PWD. h>
Int main ()
{
Struct passwd * PW;
Char * username = "zxl ";
PW = getpwnam (username );
If (! PW ){
Printf ("% s is not exist/N", username );
Return-1;
}
Printf ("PW-> pw_name = % s/n", PW-> pw_name );
Printf ("PW-> pw_passwd = % s/n", PW-> pw_passwd );
Printf ("PW-> pw_uid = % d/N", PW-> pw_uid );
Printf ("PW-> pw_gid = % d/N", PW-> pw_gid );
Printf ("PW-> pw_gecos = % s/n", PW-> pw_gecos );
Printf ("PW-> pw_dir = % s/n", PW-> pw_dir );
Printf ("PW-> pw_shell = % s/n", PW-> pw_shell );
}
/* The passwd structure .*/
Struct passwd {
Char * pw_name;/* username .*/
Char * pw_passwd;/* password .*/
_ Uid_t-pw_uid;/* User ID .*/
_ Gid_t-pw_gid;/* Group ID .*/
Char * pw_gecos;/* real name .*/
Char * pw_dir;/* home directory .-*/
Char * pw_shell;/* shell program .*/
};
The passwd structure in PWD. h indicates the user's attributes. The getpwname function can obtain this structure.I thought it was possible to directly access the user's password. In fact, passwd is a structure composed of a line of information of/etc/passwd. Alas, this getpwname function can actually be written by myself.