Last change
on this file was 206, checked in by Herwig Bauernfeind, 16 years ago |
Import Samba 3.3 branch at 3.0.0 level (psmedley's port)
|
File size:
750 bytes
|
Rev | Line | |
---|
[206] | 1 | #include <stdio.h>
|
---|
| 2 | #include <unistd.h>
|
---|
| 3 | #include <grp.h>
|
---|
| 4 | #include <pwd.h>
|
---|
| 5 | #include <sys/types.h>
|
---|
| 6 |
|
---|
| 7 | int main(int argc, char **argv)
|
---|
| 8 | {
|
---|
| 9 | int result, ngroups, i;
|
---|
| 10 | gid_t *groups;
|
---|
| 11 | struct passwd *pw;
|
---|
| 12 |
|
---|
| 13 | if (!(pw = getpwnam(argv[1]))) {
|
---|
| 14 | printf("FAIL: no passwd entry for %s\n", argv[1]);
|
---|
| 15 | return 1;
|
---|
| 16 | }
|
---|
| 17 |
|
---|
| 18 | result = initgroups(argv[1], pw->pw_gid);
|
---|
| 19 |
|
---|
| 20 | if (result == -1) {
|
---|
| 21 | printf("FAIL");
|
---|
| 22 | return 1;
|
---|
| 23 | }
|
---|
| 24 |
|
---|
| 25 | ngroups = getgroups(0, NULL);
|
---|
| 26 |
|
---|
| 27 | groups = (gid_t *)malloc(sizeof(gid_t) * ngroups);
|
---|
| 28 | ngroups = getgroups(ngroups, groups);
|
---|
| 29 |
|
---|
| 30 | printf("%s is a member of groups:\n", argv[1]);
|
---|
| 31 |
|
---|
| 32 | for (i = 0; i < ngroups; i++) {
|
---|
| 33 | struct group *grp;
|
---|
| 34 |
|
---|
| 35 | grp = getgrgid(groups[i]);
|
---|
| 36 |
|
---|
| 37 | printf("%d (%s)\n", groups[i], grp ? grp->gr_name : "?");
|
---|
| 38 | }
|
---|
| 39 |
|
---|
| 40 | printf("PASS\n");
|
---|
| 41 | return 0;
|
---|
| 42 | }
|
---|
Note:
See
TracBrowser
for help on using the repository browser.