Created
October 10, 2012 14:55
-
-
Save jonpryor/3866137 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
+ public static Group [] getgrouplist (string username) | |
+ { | |
+ // Syscall to getpwnam to retrieve user uid | |
+ Passwd pw = Syscall.getpwnam (username); | |
+ if (pw == null) | |
+ return new Group [0]; | |
+ // initialising the lngroups by 1 to get the group count | |
+ int ngroups = 1; | |
+ // allocating buffer to store group uid's | |
+ uint [] groups = new uint [ngroups]; | |
+ int res = sys_getgrouplist (username, pw.pw_gid, groups, ref ngroups); | |
+ if (res == -1) { | |
+ // using value ngroups to resize buffer. | |
+ Array.Resize(ref groups, ngroups); | |
+ res = sys_getgrouplist (username, pw.pw_gid, groups, ref ngroups); | |
+ if (res == -1) | |
+ return new Group [0]; | |
+ } | |
+ Group [] result = new Group [ngroups]; | |
+ for (int i = 0; i < res; i++) | |
+ result [i] = Syscall.getgrgid (groups [i]); | |
+ return result; | |
+ } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment