Skip to content

Instantly share code, notes, and snippets.

@chaitanyav
Created June 10, 2013 03:23
Show Gist options
  • Save chaitanyav/5746332 to your computer and use it in GitHub Desktop.
Save chaitanyav/5746332 to your computer and use it in GitHub Desktop.
/*
*
* Author: NagaChaitanya Vellanki
*
*
* Read entries in the passwd one at a time using getpwent
*/
#include <pwd.h>
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char *argv[]) {
struct passwd *pwd;
while((pwd = getpwent()) != NULL) {
printf("-------------------------------\n");
printf("User login: %s\n", pwd->pw_name);
printf("Encrypted password: %s\n", pwd->pw_passwd);
printf("User id: %d\n", pwd->pw_uid);
printf("Group id: %d\n", pwd->pw_gid);
printf("User information: %s\n", pwd->pw_gecos);
printf("Home directory: %s\n", pwd->pw_dir);
printf("Login Shell: %s\n", pwd->pw_shell);
printf("-------------------------------\n");
}
endpwent();
exit(EXIT_SUCCESS);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment