#include #include #include #include /* * uinfo.c -- get user information from the system * */ int main ( int argc, char *argv[] ) { char *username; struct passwd *pwd; if ( argc != 2 ) { printf("Usage: %s username\n", argv[0]); exit(-1); } username = argv[1]; // get user information pwd = getpwnam(username); if ( pwd == NULL ) { printf("User %s does no seem to exist.\n", username); exit(1); } // print user information printf("user name: %s\n", pwd->pw_name); printf("user id: %d\n", pwd->pw_uid); printf("group id: %d\n", pwd->pw_gid); printf("user info: %s\n", pwd->pw_gecos); printf("home dir: %s\n", pwd->pw_dir); printf("def shell: %s\n", pwd->pw_shell); return 0; }