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
static NET_API_STATUS test_netshareenum(const char *hostname,
32
const char *sharename)
34
NET_API_STATUS status;
35
uint32_t entries_read = 0;
36
uint32_t total_entries = 0;
37
uint32_t resume_handle = 0;
39
const char *current_name = NULL;
40
uint8_t *buffer = NULL;
43
struct SHARE_INFO_0 *i0 = NULL;
44
struct SHARE_INFO_1 *i1 = NULL;
45
struct SHARE_INFO_2 *i2 = NULL;
47
printf("testing NetShareEnum level %d\n", level);
50
status = NetShareEnum(hostname,
57
if (status == 0 || status == ERROR_MORE_DATA) {
60
i0 = (struct SHARE_INFO_0 *)buffer;
63
i1 = (struct SHARE_INFO_1 *)buffer;
66
i2 = (struct SHARE_INFO_2 *)buffer;
72
for (i=0; i<entries_read; i++) {
76
current_name = i0->shi0_netname;
79
current_name = i1->shi1_netname;
82
current_name = i2->shi2_netname;
88
if (strcasecmp(current_name, sharename) == 0) {
104
NetApiBufferFree(buffer);
106
} while (status == ERROR_MORE_DATA);
113
printf("failed to get share\n");
120
NET_API_STATUS netapitest_share(struct libnetapi_ctx *ctx,
121
const char *hostname)
123
NET_API_STATUS status = 0;
124
const char *sharename, *comment;
125
uint8_t *buffer = NULL;
126
struct SHARE_INFO_2 i2;
127
struct SHARE_INFO_1004 i1004;
128
struct SHARE_INFO_501 *i501 = NULL;
129
uint32_t parm_err = 0;
130
uint32_t levels[] = { 0, 1, 2, 501, 1005 };
131
uint32_t enum_levels[] = { 0, 1, 2 };
134
printf("NetShare tests\n");
136
sharename = "torture_test_share";
139
NetShareDel(hostname, sharename, 0);
143
printf("testing NetShareAdd\n");
147
i2.shi2_netname = sharename;
148
i2.shi2_path = "c:\\";
150
status = NetShareAdd(hostname, 2, (uint8_t *)&i2, &parm_err);
152
NETAPI_STATUS(ctx, status, "NetShareAdd");
158
for (i=0; i<ARRAY_SIZE(enum_levels); i++) {
160
status = test_netshareenum(hostname, enum_levels[i], sharename);
162
NETAPI_STATUS(ctx, status, "NetShareEnum");
169
for (i=0; i<ARRAY_SIZE(levels); i++) {
171
printf("testing NetShareGetInfo level %d\n", levels[i]);
173
status = NetShareGetInfo(hostname, sharename, levels[i], &buffer);
174
if (status && status != 124) {
175
NETAPI_STATUS(ctx, status, "NetShareGetInfo");
181
comment = "NetApi generated comment";
183
i1004.shi1004_remark = comment;
185
printf("testing NetShareSetInfo level 1004\n");
187
status = NetShareSetInfo(hostname, sharename, 1004, (uint8_t *)&i1004, &parm_err);
189
NETAPI_STATUS(ctx, status, "NetShareSetInfo");
193
status = NetShareGetInfo(hostname, sharename, 501, (uint8_t **)&i501);
195
NETAPI_STATUS(ctx, status, "NetShareGetInfo");
199
if (strcasecmp(i501->shi501_remark, comment) != 0) {
200
NETAPI_STATUS(ctx, status, "NetShareGetInfo");
206
printf("testing NetShareDel\n");
208
status = NetShareDel(hostname, sharename, 0);
210
NETAPI_STATUS(ctx, status, "NetShareDel");
214
/* should not exist anymore */
216
status = NetShareGetInfo(hostname, sharename, 0, &buffer);
218
NETAPI_STATUS(ctx, status, "NetShareGetInfo");
224
printf("NetShare tests succeeded\n");
227
printf("NetShare testsuite failed with: %s\n",
228
libnetapi_get_error_string(ctx, status));