smbd: Make reopen_from_fsp() public
[samba4-gss.git] / source3 / lib / netapi / examples / user / user_getlocalgroups.c
blob133104d7c18e2ff5716567a096bda010254805b4
1 /*
2 * Unix SMB/CIFS implementation.
3 * NetUserGetLocalGroups 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>
21 #include <inttypes.h>
22 #include <stdio.h>
23 #include <stdlib.h>
24 #include <string.h>
26 #include <netapi.h>
28 #include "common.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;
36 uint32_t level = 0;
37 uint8_t *buffer = NULL;
38 uint32_t entries_read = 0;
39 uint32_t total_entries = 0;
40 uint32_t flags = 0;
41 int i;
43 struct LOCALGROUP_USERS_INFO_0 *info0 = NULL;
45 poptContext pc;
46 int opt;
48 struct poptOption long_options[] = {
49 POPT_AUTOHELP
50 POPT_COMMON_LIBNETAPI_EXAMPLES
51 POPT_TABLEEND
54 status = libnetapi_init(&ctx);
55 if (status != 0) {
56 return status;
59 pc = poptGetContext("user_getlocalgroups", argc, argv, long_options, 0);
61 poptSetOtherOptionHelp(pc, "hostname username");
62 while((opt = poptGetNextOpt(pc)) != -1) {
65 if (!poptPeekArg(pc)) {
66 poptPrintHelp(pc, stderr, 0);
67 goto out;
69 hostname = poptGetArg(pc);
71 if (!poptPeekArg(pc)) {
72 poptPrintHelp(pc, stderr, 0);
73 goto out;
75 username = poptGetArg(pc);
77 /* NetUserGetLocalGroups */
79 do {
80 status = NetUserGetLocalGroups(hostname,
81 username,
82 level,
83 flags,
84 &buffer,
85 (uint32_t)-1,
86 &entries_read,
87 &total_entries);
88 if (status == 0 || status == ERROR_MORE_DATA) {
90 switch (level) {
91 case 0:
92 info0 = (struct LOCALGROUP_USERS_INFO_0 *)buffer;
93 break;
94 default:
95 break;
98 for (i=0; i<entries_read; i++) {
99 switch (level) {
100 case 0:
101 printf("#%d group: %s\n", i, info0->lgrui0_name);
102 info0++;
103 break;
104 default:
105 break;
108 NetApiBufferFree(buffer);
110 } while (status == ERROR_MORE_DATA);
112 if (status != 0) {
113 printf("NetUserGetLocalGroups failed with: %s\n",
114 libnetapi_get_error_string(ctx, status));
117 out:
118 libnetapi_free(ctx);
119 poptFreeContext(pc);
121 return status;