Commit | Line | Data |
---|---|---|
4acbfa2a | 1 | /* |
0f78b815 WD |
2 | * Print out the gids of all groups for the current user. This is like |
3 | * `id -G` on Linux, but it's too hard to find a portable equivalent. | |
4 | * | |
5 | * Copyright (C) 2002 Martin Pool | |
6 | * Copyright (C) 2003, 2004 Wayne Davison | |
7 | * | |
4acbfa2a MP |
8 | * This program is free software; you can redistribute it and/or modify |
9 | * it under the terms of the GNU General Public License as published by | |
10 | * the Free Software Foundation; either version 2 of the License, or | |
11 | * (at your option) any later version. | |
0f78b815 | 12 | * |
4acbfa2a MP |
13 | * This program is distributed in the hope that it will be useful, |
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
16 | * GNU General Public License for more details. | |
0f78b815 | 17 | * |
e7c67065 WD |
18 | * You should have received a copy of the GNU General Public License along |
19 | * with this program; if not, write to the Free Software Foundation, Inc., | |
20 | * 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. | |
4acbfa2a MP |
21 | */ |
22 | ||
4acbfa2a MP |
23 | #include "rsync.h" |
24 | ||
f69204ad WD |
25 | int |
26 | main(UNUSED(int argc), UNUSED(char *argv[])) | |
4acbfa2a MP |
27 | { |
28 | int n, i; | |
40ae4f93 | 29 | gid_t *list; |
670d8abf | 30 | gid_t gid = MY_GID(); |
58743a87 | 31 | int gid_in_list = 0; |
4acbfa2a | 32 | |
4f5b0756 | 33 | #ifdef HAVE_GETGROUPS |
40ae4f93 | 34 | if ((n = getgroups(0, NULL)) < 0) { |
4acbfa2a MP |
35 | perror("getgroups"); |
36 | return 1; | |
37 | } | |
1df395f7 WD |
38 | #else |
39 | n = 0; | |
40 | #endif | |
4acbfa2a | 41 | |
40ae4f93 WD |
42 | list = (gid_t*)malloc(sizeof (gid_t) * (n + 1)); |
43 | if (!list) { | |
44 | fprintf(stderr, "out of memory!\n"); | |
45 | exit(1); | |
46 | } | |
47 | ||
4f5b0756 | 48 | #ifdef HAVE_GETGROUPS |
40ae4f93 WD |
49 | if (n > 0) |
50 | n = getgroups(n, list); | |
51 | #endif | |
52 | ||
58743a87 | 53 | for (i = 0; i < n; i++) { |
f358487f | 54 | printf("%lu ", (unsigned long)list[i]); |
58743a87 WD |
55 | if (list[i] == gid) |
56 | gid_in_list = 1; | |
57 | } | |
58 | /* The default gid might not be in the list on some systems. */ | |
59 | if (!gid_in_list) | |
60 | printf("%lu", (unsigned long)gid); | |
4acbfa2a | 61 | printf("\n"); |
0f78b815 | 62 | |
4acbfa2a MP |
63 | return 0; |
64 | } |