commit d832f81d973441bceb09b50e977151815cc8abae
parent f0712c34b20d752b263913fd1f387843c78d17a4
Author: qorg11 <qorg@vxempire.xyz>
Date: Sat, 8 Aug 2020 21:38:00 +0200
added groups
Diffstat:
1 file changed, 27 insertions(+), 0 deletions(-)
diff --git a/src/groups.c b/src/groups.c
@@ -0,0 +1,27 @@
+#include <stdio.h>
+#include <pwd.h>
+#include <unistd.h>
+#include <grp.h>
+#include <stdlib.h>
+
+int
+main(int argc, char *argv[])
+{
+ struct passwd *pwd;
+ if(argc == 2 )
+ pwd = getpwnam(argv[1]);
+ else
+ pwd = getpwuid(getuid());
+
+ int ngroups = 10;
+ uid_t *groups = malloc(ngroups);
+ getgrouplist(pwd->pw_name,pwd->pw_gid,groups,&ngroups);
+ struct group *gr;
+ for(int i = 0; i <ngroups;i++)
+ {
+ gr = getgrgid(groups[i]);
+ printf("%s ",gr->gr_name);
+ }
+ printf("\n");
+ return 0;
+}