2 Unix SMB/CIFS implementation.
3 Test suite for libnet calls.
5 Copyright (C) Gregory LEOCADIE <gleocadie@idealx.com> 2005
6 Copyright (C) Rafal Szczesniak 2005
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 3 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program. If not, see <http://www.gnu.org/licenses/>.
23 #include "torture/rpc/torture_rpc.h"
24 #include "libnet/libnet.h"
25 #include "lib/cmdline/cmdline.h"
26 #include "librpc/gen_ndr/ndr_srvsvc_c.h"
27 #include "torture/libnet/proto.h"
30 #define TEST_SHARENAME "libnetsharetest"
33 static void test_displayshares(struct torture_context *tctx,
34 struct libnet_ListShares s)
39 enum srvsvc_ShareType type;
42 { STYPE_DISKTREE, "STYPE_DISKTREE" },
43 { STYPE_DISKTREE_TEMPORARY, "STYPE_DISKTREE_TEMPORARY" },
44 { STYPE_DISKTREE_HIDDEN, "STYPE_DISKTREE_HIDDEN" },
45 { STYPE_PRINTQ, "STYPE_PRINTQ" },
46 { STYPE_PRINTQ_TEMPORARY, "STYPE_PRINTQ_TEMPORARY" },
47 { STYPE_PRINTQ_HIDDEN, "STYPE_PRINTQ_HIDDEN" },
48 { STYPE_DEVICE, "STYPE_DEVICE" },
49 { STYPE_DEVICE_TEMPORARY, "STYPE_DEVICE_TEMPORARY" },
50 { STYPE_DEVICE_HIDDEN, "STYPE_DEVICE_HIDDEN" },
51 { STYPE_IPC, "STYPE_IPC" },
52 { STYPE_IPC_TEMPORARY, "STYPE_IPC_TEMPORARY" },
53 { STYPE_IPC_HIDDEN, "STYPE_IPC_HIDDEN" }
58 for (i = 0; i < s.out.ctr.ctr0->count; i++) {
59 struct srvsvc_NetShareInfo0 *info = &s.out.ctr.ctr0->array[i];
60 torture_comment(tctx, "\t[%d] %s\n", i, info->name);
65 for (i = 0; i < s.out.ctr.ctr1->count; i++) {
66 struct srvsvc_NetShareInfo1 *info = &s.out.ctr.ctr1->array[i];
67 for (j = 0; j < ARRAY_SIZE(share_types); j++) {
68 if (share_types[j].type == info->type) {
70 "\t[%d] %s (%s)\t%s\n",
82 for (i = 0; i < s.out.ctr.ctr2->count; i++) {
83 struct srvsvc_NetShareInfo2 *info = &s.out.ctr.ctr2->array[i];
84 for (j = 0; j < ARRAY_SIZE(share_types); j++) {
85 if (share_types[j].type == info->type) {
110 for (i = 0; i < s.out.ctr.ctr501->count; i++) {
111 struct srvsvc_NetShareInfo501 *info = &s.out.ctr.ctr501->array[i];
112 for (j = 0; j < ARRAY_SIZE(share_types); j++) {
113 if (share_types[j].type == info->type) {
114 torture_comment(tctx,
117 "[csc_policy=0x%08x]\n"
131 for (i = 0; i < s.out.ctr.ctr502->count; i++) {
132 struct srvsvc_NetShareInfo502 *info = &s.out.ctr.ctr502->array[i];
133 for (j = 0; j < ARRAY_SIZE(share_types); j++) {
134 if (share_types[j].type == info->type) {
135 torture_comment(tctx,
141 "path=%s, pass=%s]\n",
160 bool torture_listshares(struct torture_context *torture)
162 struct libnet_ListShares share;
164 uint32_t levels[] = { 0, 1, 2, 501, 502 };
167 struct libnet_context* libnetctx;
168 struct dcerpc_binding *binding;
171 mem_ctx = talloc_init("test_listshares");
172 status = torture_rpc_binding(torture, &binding);
173 if (!NT_STATUS_IS_OK(status)) {
178 libnetctx = libnet_context_init(torture->ev, torture->lp_ctx);
180 torture_comment(torture, "Couldn't allocate libnet context\n");
185 libnetctx->cred = samba_cmdline_get_creds();
187 torture_comment(torture, "Testing libnet_ListShare\n");
189 share.in.server_name = dcerpc_binding_get_string_option(binding, "host");
191 for (i = 0; i < ARRAY_SIZE(levels); i++) {
192 share.in.level = levels[i];
193 torture_comment(torture, "Testing libnet_ListShare level %u\n", share.in.level);
195 status = libnet_ListShares(libnetctx, mem_ctx, &share);
196 if (!NT_STATUS_IS_OK(status)) {
197 torture_comment(torture, "libnet_ListShare level %u failed - %s\n", share.in.level, share.out.error_string);
202 torture_comment(torture, "listing shares:\n");
203 test_displayshares(torture, share);
207 talloc_free(mem_ctx);
212 static bool test_addshare(struct torture_context *tctx,
213 struct dcerpc_binding_handle *b, TALLOC_CTX *mem_ctx, const char *host,
217 struct srvsvc_NetShareAdd add;
218 union srvsvc_NetShareInfo info;
219 struct srvsvc_NetShareInfo2 i;
226 i.type = STYPE_DISKTREE;
227 i.path = "C:\\WINDOWS\\TEMP";
229 i.comment = "Comment to the test share";
235 add.in.server_unc = host;
238 add.in.parm_error = NULL;
240 status = dcerpc_srvsvc_NetShareAdd_r(b, mem_ctx, &add);
241 if (!NT_STATUS_IS_OK(status)) {
242 torture_comment(tctx, "Failed to add a new share\n");
246 torture_comment(tctx, "share added\n");
251 bool torture_delshare(struct torture_context *torture)
253 struct dcerpc_pipe *p;
254 struct dcerpc_binding *binding;
255 struct libnet_context* libnetctx;
259 struct libnet_DelShare share;
261 host = torture_setting_string(torture, "host", NULL);
262 status = torture_rpc_binding(torture, &binding);
263 torture_assert_ntstatus_ok(torture, status, "Failed to get binding");
265 libnetctx = libnet_context_init(torture->ev, torture->lp_ctx);
266 libnetctx->cred = samba_cmdline_get_creds();
268 status = torture_rpc_connection(torture,
272 torture_assert_ntstatus_ok(torture, status, "Failed to get rpc connection");
274 if (!test_addshare(torture, p->binding_handle, torture, host, TEST_SHARENAME)) {
278 share.in.server_name = dcerpc_binding_get_string_option(binding, "host");
279 share.in.share_name = TEST_SHARENAME;
281 status = libnet_DelShare(libnetctx, torture, &share);
282 torture_assert_ntstatus_ok(torture, status, "Failed to delete share");