Skip to content

Instantly share code, notes, and snippets.

@chaitanyav
Created June 10, 2013 03:36
Show Gist options
  • Save chaitanyav/5746366 to your computer and use it in GitHub Desktop.
Save chaitanyav/5746366 to your computer and use it in GitHub Desktop.
/*
* Author: NagaChaitanya Vellanki
*
*
* Read entries in the groups file one at a time
*/
#include <grp.h>
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char *argv[]) {
struct group *grp;
while((grp = getgrent()) != NULL) {
printf("-------------------------------\n");
printf("Group name: %s\n", grp->gr_name);
printf("Group id: %d\n", grp->gr_gid);
printf("Encrypted password: %s\n", grp->gr_passwd);
for(; *(grp->gr_mem) != NULL; (grp->gr_mem)++) {
printf("User: %s\n", *(grp->gr_mem));
}
printf("-------------------------------\n");
}
endgrent();
exit(EXIT_SUCCESS);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment