2
* Unix SMB/CIFS implementation.
4
* Copyright (C) Guenther Deschner 2007
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;
36
uint8_t *buffer = NULL;
37
uint32_t entries_read = 0;
38
uint32_t total_entries = 0;
39
uint32_t resume_handle = 0;
43
struct USER_INFO_0 *info0 = NULL;
44
struct USER_INFO_10 *info10 = NULL;
45
struct USER_INFO_20 *info20 = NULL;
46
struct USER_INFO_23 *info23 = NULL;
51
struct poptOption long_options[] = {
53
POPT_COMMON_LIBNETAPI_EXAMPLES
57
status = libnetapi_init(&ctx);
62
pc = poptGetContext("user_enum", argc, argv, long_options, 0);
64
poptSetOtherOptionHelp(pc, "hostname level");
65
while((opt = poptGetNextOpt(pc)) != -1) {
68
if (!poptPeekArg(pc)) {
69
poptPrintHelp(pc, stderr, 0);
72
hostname = poptGetArg(pc);
74
if (poptPeekArg(pc)) {
75
level = atoi(poptGetArg(pc));
81
status = NetUserEnum(hostname,
83
FILTER_NORMAL_ACCOUNT,
89
if (status == 0 || status == ERROR_MORE_DATA) {
93
info0 = (struct USER_INFO_0 *)buffer;
96
info10 = (struct USER_INFO_10 *)buffer;
99
info20 = (struct USER_INFO_20 *)buffer;
102
info23 = (struct USER_INFO_23 *)buffer;
108
for (i=0; i<entries_read; i++) {
111
printf("#%d user: %s\n", i, info0->usri0_name);
115
printf("#%d user: %s\n", i, info10->usri10_name);
116
printf("#%d comment: %s\n", i, info10->usri10_comment);
117
printf("#%d usr_comment: %s\n", i, info10->usri10_usr_comment);
118
printf("#%d full_name: %s\n", i, info10->usri10_full_name);
122
printf("#%d user: %s\n", i, info20->usri20_name);
123
printf("#%d comment: %s\n", i, info20->usri20_comment);
124
printf("#%d flags: 0x%08x\n", i, info20->usri20_flags);
125
printf("#%d rid: %d\n", i, info20->usri20_user_id);
129
printf("#%d user: %s\n", i, info23->usri23_name);
130
printf("#%d comment: %s\n", i, info23->usri23_comment);
131
printf("#%d flags: 0x%08x\n", i, info23->usri23_flags);
132
if (ConvertSidToStringSid(info23->usri23_user_sid,
134
printf("#%d sid: %s\n", i, sid_str);
143
NetApiBufferFree(buffer);
145
} while (status == ERROR_MORE_DATA);
148
printf("NetUserEnum failed with: %s\n",
149
libnetapi_get_error_string(ctx, status));