2 * Unix SMB/CIFS implementation.
3 * NetUserGetGroups query
4 * Copyright (C) Guenther Deschner 2008
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 3 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, see <http://www.gnu.org/licenses/>.
20 #include <sys/types.h>
30 int main(int argc, const char **argv)
32 NET_API_STATUS status;
33 struct libnetapi_ctx *ctx = NULL;
34 const char *hostname = NULL;
35 const char *username = NULL;
37 uint8_t *buffer = NULL;
38 uint32_t entries_read = 0;
39 uint32_t total_entries = 0;
42 struct GROUP_USERS_INFO_0 *info0 = NULL;
43 struct GROUP_USERS_INFO_1 *info1 = NULL;
48 struct poptOption long_options[] = {
50 POPT_COMMON_LIBNETAPI_EXAMPLES
54 status = libnetapi_init(&ctx);
59 pc = poptGetContext("user_getgroups", argc, argv, long_options, 0);
61 poptSetOtherOptionHelp(pc, "hostname username level");
62 while((opt = poptGetNextOpt(pc)) != -1) {
65 if (!poptPeekArg(pc)) {
66 poptPrintHelp(pc, stderr, 0);
69 hostname = poptGetArg(pc);
71 if (!poptPeekArg(pc)) {
72 poptPrintHelp(pc, stderr, 0);
75 username = poptGetArg(pc);
77 if (poptPeekArg(pc)) {
78 level = atoi(poptGetArg(pc));
81 /* NetUserGetGroups */
84 status = NetUserGetGroups(hostname,
91 if (status == 0 || status == ERROR_MORE_DATA) {
95 info0 = (struct GROUP_USERS_INFO_0 *)buffer;
98 info1 = (struct GROUP_USERS_INFO_1 *)buffer;
104 for (i=0; i<entries_read; i++) {
107 printf("#%d group: %s\n", i, info0->grui0_name);
111 printf("#%d group: %s\n", i, info1->grui1_name);
112 printf("#%d attributes: %d\n", i, info1->grui1_attributes);
119 NetApiBufferFree(buffer);
121 } while (status == ERROR_MORE_DATA);
124 printf("NetUserGetGroups failed with: %s\n",
125 libnetapi_get_error_string(ctx, status));