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/rpc.h"
24 #include "libnet/libnet.h"
25 #include "lib/cmdline/popt_common.h"
26 #include "librpc/gen_ndr/ndr_srvsvc_c.h"
29 #define TEST_SHARENAME "libnetsharetest"
32 static void test_displayshares(struct libnet_ListShares s)
37 enum srvsvc_ShareType type;
40 { STYPE_DISKTREE, "STYPE_DISKTREE" },
41 { STYPE_DISKTREE_TEMPORARY, "STYPE_DISKTREE_TEMPORARY" },
42 { STYPE_DISKTREE_HIDDEN, "STYPE_DISKTREE_HIDDEN" },
43 { STYPE_PRINTQ, "STYPE_PRINTQ" },
44 { STYPE_PRINTQ_TEMPORARY, "STYPE_PRINTQ_TEMPORARY" },
45 { STYPE_PRINTQ_HIDDEN, "STYPE_PRINTQ_HIDDEN" },
46 { STYPE_DEVICE, "STYPE_DEVICE" },
47 { STYPE_DEVICE_TEMPORARY, "STYPE_DEVICE_TEMPORARY" },
48 { STYPE_DEVICE_HIDDEN, "STYPE_DEVICE_HIDDEN" },
49 { STYPE_IPC, "STYPE_IPC" },
50 { STYPE_IPC_TEMPORARY, "STYPE_IPC_TEMPORARY" },
51 { STYPE_IPC_HIDDEN, "STYPE_IPC_HIDDEN" }
56 for (i = 0; i < s.out.ctr.ctr0->count; i++) {
57 struct srvsvc_NetShareInfo0 *info = &s.out.ctr.ctr0->array[i];
58 d_printf("\t[%d] %s\n", i, info->name);
63 for (i = 0; i < s.out.ctr.ctr1->count; i++) {
64 struct srvsvc_NetShareInfo1 *info = &s.out.ctr.ctr1->array[i];
65 for (j = 0; j < ARRAY_SIZE(share_types); j++) {
66 if (share_types[j].type == info->type) break;
68 d_printf("\t[%d] %s (%s)\t%s\n", i, info->name,
69 info->comment, share_types[j].desc);
74 for (i = 0; i < s.out.ctr.ctr2->count; i++) {
75 struct srvsvc_NetShareInfo2 *info = &s.out.ctr.ctr2->array[i];
76 for (j = 0; j < ARRAY_SIZE(share_types); j++) {
77 if (share_types[j].type == info->type) break;
79 d_printf("\t[%d] %s\t%s\n\t %s\n\t [perms=0x%08x, max_usr=%d, cur_usr=%d, path=%s, pass=%s]\n",
80 i, info->name, share_types[j].desc, info->comment,
81 info->permissions, info->max_users,
82 info->current_users, info->path,
88 for (i = 0; i < s.out.ctr.ctr501->count; i++) {
89 struct srvsvc_NetShareInfo501 *info = &s.out.ctr.ctr501->array[i];
90 for (j = 0; j < ARRAY_SIZE(share_types); j++) {
91 if (share_types[j].type == info->type) break;
93 d_printf("\t[%d] %s\t%s [csc_policy=0x%08x]\n\t %s\n", i, info->name,
94 share_types[j].desc, info->csc_policy,
100 for (i = 0; i < s.out.ctr.ctr502->count; i++) {
101 struct srvsvc_NetShareInfo502 *info = &s.out.ctr.ctr502->array[i];
102 for (j = 0; j < ARRAY_SIZE(share_types); j++) {
103 if (share_types[j].type == info->type) break;
105 d_printf("\t[%d] %s\t%s\n\t %s\n\t [perms=0x%08x, max_usr=%d, cur_usr=%d, path=%s, pass=%s, unknown=0x%08x]\n",
106 i, info->name, share_types[j].desc, info->comment,
107 info->permissions, info->max_users,
108 info->current_users, info->path,
109 info->password, info->unknown);
116 BOOL torture_listshares(struct torture_context *torture)
118 struct libnet_ListShares share;
120 uint32_t levels[] = { 0, 1, 2, 501, 502 };
123 struct libnet_context* libnetctx;
125 struct dcerpc_binding *bind;
128 mem_ctx = talloc_init("test_listshares");
129 binding = torture_setting_string(torture, "binding", NULL);
130 status = dcerpc_parse_binding(mem_ctx, binding, &bind);
131 if (!NT_STATUS_IS_OK(status)) {
132 printf("Error while parsing the binding string\n");
137 libnetctx = libnet_context_init(NULL);
139 printf("Couldn't allocate libnet context\n");
144 libnetctx->cred = cmdline_credentials;
146 printf("Testing libnet_ListShare\n");
148 share.in.server_name = talloc_asprintf(mem_ctx, "%s", bind->host);
150 for (i = 0; i < ARRAY_SIZE(levels); i++) {
151 share.in.level = levels[i];
152 printf("testing libnet_ListShare level %u\n", share.in.level);
154 status = libnet_ListShares(libnetctx, mem_ctx, &share);
155 if (!NT_STATUS_IS_OK(status)) {
156 printf("libnet_ListShare level %u failed - %s\n", share.in.level, share.out.error_string);
161 printf("listing shares:\n");
162 test_displayshares(share);
166 talloc_free(mem_ctx);
171 static BOOL test_addshare(struct dcerpc_pipe *svc_pipe, TALLOC_CTX *mem_ctx, const char *host,
175 struct srvsvc_NetShareAdd add;
176 struct srvsvc_NetShareInfo2 i;
179 i.type = STYPE_DISKTREE;
180 i.path = "C:\\WINDOWS\\TEMP";
182 i.comment = "Comment to the test share";
186 add.in.server_unc = host;
188 add.in.info.info2 = &i;
190 status = dcerpc_srvsvc_NetShareAdd(svc_pipe, mem_ctx, &add);
191 if (!NT_STATUS_IS_OK(status)) {
192 printf("Failed to add a new share\n");
196 printf("share added\n");
201 BOOL torture_delshare(struct torture_context *torture)
203 struct dcerpc_pipe *p;
204 struct dcerpc_binding *bind;
205 struct libnet_context* libnetctx;
206 const char *host, *binding;
210 struct libnet_DelShare share;
212 mem_ctx = talloc_init("test_listshares");
213 host = torture_setting_string(torture, "host", NULL);
214 binding = torture_setting_string(torture, "binding", NULL);
215 status = dcerpc_parse_binding(mem_ctx, binding, &bind);
216 if (!NT_STATUS_IS_OK(status)) {
217 printf("Error while parsing the binding string\n");
222 libnetctx = libnet_context_init(NULL);
223 libnetctx->cred = cmdline_credentials;
225 status = torture_rpc_connection(mem_ctx,
229 if (!test_addshare(p, mem_ctx, host, TEST_SHARENAME)) {
234 share.in.server_name = bind->host;
235 share.in.share_name = TEST_SHARENAME;
237 status = libnet_DelShare(libnetctx, mem_ctx, &share);
238 if (!NT_STATUS_IS_OK(status)) {
245 talloc_free(mem_ctx);