Permalink
Browse files

HW3-2

  • Loading branch information...
amillerrhodes committed May 4, 2012
1 parent 97ae2bc commit 33cbbfef8d2d3e52c20b9daf270be39dddcd7b95
Showing with 35 additions and 0 deletions.
  1. +35 −0 hw3/Homework3-2.c
View
@@ -0,0 +1,35 @@
+#include <stdio.h>
+#include <unistd.h>
+#include <stdlib.h>
+#include <sys/types.h>
+#include <grp.h>
+#include <pwd.h>
+
+int
+main (void) {
+ int i;
+
+
+ /* Get Username */
+ struct passwd* userinfo;
+ gid_t* groups = malloc(32*sizeof(gid_t));
+ struct group* groupinfo;
+ int n, nr;
+ while ((userinfo = getpwent()) != NULL) {
+ printf("\n%s (%ld)\n", userinfo->pw_name, userinfo->pw_uid);
+
+ /* Get Groups */
+ //gid_t* groups = malloc(32*sizeof(gid_t));
+ n = 32;
+ nr = getgrouplist(userinfo->pw_name, userinfo->pw_gid, groups, &n);
+ if (nr == n) {
+ for (i=0; i<n; i++) {
+ groupinfo = getgrgid(groups[i]);
+ printf(" %s (%ld)\n", groupinfo->gr_name, groups[i]);
+ }
+ }
+ }
+
+ return 0;
+}
+

0 comments on commit 33cbbfe

Please sign in to comment.