2
* Unix SMB/CIFS implementation.
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;
36
uint8_t *buffer = NULL;
37
uint32_t entries_read = 0;
38
uint32_t total_entries = 0;
39
uint32_t resume_handle = 0;
42
struct SHARE_INFO_0 *i0 = NULL;
43
struct SHARE_INFO_1 *i1 = NULL;
44
struct SHARE_INFO_2 *i2 = NULL;
49
struct poptOption long_options[] = {
51
POPT_COMMON_LIBNETAPI_EXAMPLES
55
status = libnetapi_init(&ctx);
60
pc = poptGetContext("share_enum", argc, argv, long_options, 0);
62
poptSetOtherOptionHelp(pc, "hostname level");
63
while((opt = poptGetNextOpt(pc)) != -1) {
66
if (!poptPeekArg(pc)) {
67
poptPrintHelp(pc, stderr, 0);
70
hostname = poptGetArg(pc);
72
if (poptPeekArg(pc)) {
73
level = atoi(poptGetArg(pc));
79
status = NetShareEnum(hostname,
86
if (status == 0 || status == ERROR_MORE_DATA) {
87
printf("total entries: %d\n", total_entries);
90
i0 = (struct SHARE_INFO_0 *)buffer;
93
i1 = (struct SHARE_INFO_1 *)buffer;
96
i2 = (struct SHARE_INFO_2 *)buffer;
101
for (i=0; i<entries_read; i++) {
104
printf("#%d netname: %s\n", i, i0->shi0_netname);
108
printf("#%d netname: %s\n", i, i1->shi1_netname);
109
printf("#%d type: %d\n", i, i1->shi1_type);
110
printf("#%d remark: %s\n", i, i1->shi1_remark);
114
printf("#%d netname: %s\n", i, i2->shi2_netname);
115
printf("#%d type: %d\n", i, i2->shi2_type);
116
printf("#%d remark: %s\n", i, i2->shi2_remark);
117
printf("#%d permissions: %d\n", i, i2->shi2_permissions);
118
printf("#%d max users: %d\n", i, i2->shi2_max_uses);
119
printf("#%d current users: %d\n", i, i2->shi2_current_uses);
120
printf("#%d path: %s\n", i, i2->shi2_path);
121
printf("#%d password: %s\n", i, i2->shi2_passwd);
128
NetApiBufferFree(buffer);
130
} while (status == ERROR_MORE_DATA);
133
printf("NetShareEnum failed with: %s\n",
134
libnetapi_get_error_string(ctx, status));