2 * Unix SMB/CIFS implementation.
3 * NetLocalGroupGetMembers 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 *groupname
= NULL
;
37 uint8_t *buffer
= NULL
;
38 uint32_t entries_read
= 0;
39 uint32_t total_entries
= 0;
40 uint32_t resume_handle
= 0;
44 struct LOCALGROUP_MEMBERS_INFO_0
*info0
= NULL
;
45 struct LOCALGROUP_MEMBERS_INFO_1
*info1
= NULL
;
46 struct LOCALGROUP_MEMBERS_INFO_2
*info2
= NULL
;
47 struct LOCALGROUP_MEMBERS_INFO_3
*info3
= NULL
;
52 struct poptOption long_options
[] = {
54 POPT_COMMON_LIBNETAPI_EXAMPLES
58 status
= libnetapi_init(&ctx
);
63 pc
= poptGetContext("localgroup_getmembers", argc
, argv
, long_options
, 0);
65 poptSetOtherOptionHelp(pc
, "hostname groupname level");
66 while((opt
= poptGetNextOpt(pc
)) != -1) {
69 if (!poptPeekArg(pc
)) {
70 poptPrintHelp(pc
, stderr
, 0);
73 hostname
= poptGetArg(pc
);
74 if (!poptPeekArg(pc
)) {
75 poptPrintHelp(pc
, stderr
, 0);
78 groupname
= poptGetArg(pc
);
80 if (poptPeekArg(pc
)) {
81 level
= atoi(poptGetArg(pc
));
84 /* NetLocalGroupGetMembers */
87 status
= NetLocalGroupGetMembers(hostname
,
95 if (status
== 0 || status
== ERROR_MORE_DATA
) {
96 printf("total entries: %d\n", total_entries
);
99 info0
= (struct LOCALGROUP_MEMBERS_INFO_0
*)buffer
;
102 info1
= (struct LOCALGROUP_MEMBERS_INFO_1
*)buffer
;
105 info2
= (struct LOCALGROUP_MEMBERS_INFO_2
*)buffer
;
108 info3
= (struct LOCALGROUP_MEMBERS_INFO_3
*)buffer
;
113 for (i
=0; i
<entries_read
; i
++) {
116 if (ConvertSidToStringSid(info0
->lgrmi0_sid
,
118 printf("#%d member sid: %s\n", i
, sid_str
);
124 if (ConvertSidToStringSid(info1
->lgrmi1_sid
,
126 printf("#%d member sid: %s\n", i
, sid_str
);
129 printf("#%d sid type: %d\n", i
, info1
->lgrmi1_sidusage
);
130 printf("#%d name: %s\n", i
, info1
->lgrmi1_name
);
134 if (ConvertSidToStringSid(info2
->lgrmi2_sid
,
136 printf("#%d member sid: %s\n", i
, sid_str
);
139 printf("#%d sid type: %d\n", i
, info2
->lgrmi2_sidusage
);
140 printf("#%d full name: %s\n", i
, info2
->lgrmi2_domainandname
);
144 printf("#%d full name: %s\n", i
, info3
->lgrmi3_domainandname
);
151 NetApiBufferFree(buffer
);
153 } while (status
== ERROR_MORE_DATA
);
156 printf("NetLocalGroupGetMembers failed with: %s\n",
157 libnetapi_get_error_string(ctx
, status
));