| 1 |
/* |
| 2 |
Unix SMB/CIFS implementation. |
| 3 |
|
| 4 |
libcli composite function testing |
| 5 |
|
| 6 |
Copyright (C) Andrew Tridgell 2005 |
| 7 |
|
| 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. |
| 12 |
|
| 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. |
| 17 |
|
| 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/>. |
| 20 |
*/ |
| 21 |
|
| 22 |
#include "includes.h" |
| 23 |
#include "torture/torture.h" |
| 24 |
#include "lib/events/events.h" |
| 25 |
#include "libcli/raw/libcliraw.h" |
| 26 |
#include "libcli/libcli.h" |
| 27 |
#include "libcli/security/security.h" |
| 28 |
#include "libcli/composite/composite.h" |
| 29 |
#include "libcli/smb_composite/smb_composite.h" |
| 30 |
#include "librpc/gen_ndr/ndr_misc.h" |
| 31 |
#include "lib/cmdline/cmdline.h" |
| 32 |
#include "torture/util.h" |
| 33 |
#include "param/param.h" |
| 34 |
#include "libcli/resolve/resolve.h" |
| 35 |
#include "torture/raw/proto.h" |
| 36 |
|
| 37 |
#define BASEDIR "\\composite" |
| 38 |
|
| 39 |
static void loadfile_complete(struct composite_context *c) |
| 40 |
{ |
| 41 |
int *count = talloc_get_type(c->async.private_data, int); |
| 42 |
(*count)++; |
| 43 |
} |
| 44 |
|
| 45 |
/* |
| 46 |
test a simple savefile/loadfile combination |
| 47 |
*/ |
| 48 |
static bool test_loadfile(struct torture_context *tctx, struct smbcli_state *cli) |
| 49 |
{ |
| 50 |
const char *fname = BASEDIR "\\test.txt"; |
| 51 |
NTSTATUS status; |
| 52 |
struct smb_composite_savefile io1; |
| 53 |
struct smb_composite_loadfile *io2; |
| 54 |
struct composite_context **c; |
| 55 |
uint8_t *data; |
| 56 |
size_t len = random() % 100000; |
| 57 |
const int num_ops = 50; |
| 58 |
int i; |
| 59 |
int *count = talloc_zero(tctx, int); |
| 60 |
|
| 61 |
data = talloc_array(tctx, uint8_t, len); |
| 62 |
|
| 63 |
generate_random_buffer(data, len); |
| 64 |
|
| 65 |
io1.in.fname = fname; |
| 66 |
io1.in.data = data; |
| 67 |
io1.in.size = len; |
| 68 |
|
| 69 |
torture_comment(tctx, "Testing savefile\n"); |
| 70 |
|
| 71 |
status = smb_composite_savefile(cli->tree, &io1); |
| 72 |
torture_assert_ntstatus_equal(tctx, status, NT_STATUS_OK, "savefile failed"); |
| 73 |
|
| 74 |
torture_comment(tctx, "Testing parallel loadfile with %d ops\n", num_ops); |
| 75 |
|
| 76 |
c = talloc_array(tctx, struct composite_context *, num_ops); |
| 77 |
io2 = talloc_zero_array(tctx, struct smb_composite_loadfile, num_ops); |
| 78 |
|
| 79 |
for (i=0;i<num_ops;i++) { |
| 80 |
io2[i].in.fname = fname; |
| 81 |
c[i] = smb_composite_loadfile_send(cli->tree, &io2[i]); |
| 82 |
c[i]->async.fn = loadfile_complete; |
| 83 |
c[i]->async.private_data = count; |
| 84 |
} |
| 85 |
|
| 86 |
torture_comment(tctx, "waiting for completion\n"); |
| 87 |
while (*count != num_ops) { |
| 88 |
tevent_loop_once(tctx->ev); |
| 89 |
if (torture_setting_bool(tctx, "progress", true)) { |
| 90 |
torture_comment(tctx, "(%s) count=%d\r", __location__, *count); |
| 91 |
fflush(stdout); |
| 92 |
} |
| 93 |
} |
| 94 |
torture_comment(tctx, "count=%d\n", *count); |
| 95 |
|
| 96 |
for (i=0;i<num_ops;i++) { |
| 97 |
status = smb_composite_loadfile_recv(c[i], tctx); |
| 98 |
torture_assert_ntstatus_equal(tctx, status, NT_STATUS_OK, "loadfile failed"); |
| 99 |
|
| 100 |
torture_assert_int_equal(tctx, io2[i].out.size, len, "wrong length in returned data"); |
| 101 |
torture_assert_mem_equal(tctx, io2[i].out.data, data, len, "wrong data in loadfile"); |
| 102 |
} |
| 103 |
|
| 104 |
talloc_free(data); |
| 105 |
|
| 106 |
return true; |
| 107 |
} |
| 108 |
|
| 109 |
static bool test_loadfile_t(struct torture_context *tctx, struct smbcli_state *cli) |
| 110 |
{ |
| 111 |
int ret; |
| 112 |
torture_assert(tctx, torture_setup_dir(cli, BASEDIR), "failed to setup " BASEDIR); |
| 113 |
|
| 114 |
ret = test_loadfile(tctx, cli); |
| 115 |
smb_raw_exit(cli->session); |
| 116 |
smbcli_deltree(cli->tree, BASEDIR); |
| 117 |
|
| 118 |
return ret; |
| 119 |
} |
| 120 |
|
| 121 |
/* |
| 122 |
test a simple savefile/loadfile combination |
| 123 |
*/ |
| 124 |
static bool test_fetchfile(struct torture_context *tctx, struct smbcli_state *cli) |
| 125 |
{ |
| 126 |
const char *fname = BASEDIR "\\test.txt"; |
| 127 |
NTSTATUS status; |
| 128 |
struct smb_composite_savefile io1; |
| 129 |
struct smb_composite_fetchfile io2; |
| 130 |
struct composite_context **c; |
| 131 |
uint8_t *data; |
| 132 |
int i; |
| 133 |
size_t len = random() % 10000; |
| 134 |
extern int torture_numops; |
| 135 |
struct tevent_context *event_ctx; |
| 136 |
int *count = talloc_zero(tctx, int); |
| 137 |
bool ret = true; |
| 138 |
|
| 139 |
data = talloc_array(tctx, uint8_t, len); |
| 140 |
|
| 141 |
generate_random_buffer(data, len); |
| 142 |
|
| 143 |
ZERO_STRUCT(io1); |
| 144 |
io1.in.fname = fname; |
| 145 |
io1.in.data = data; |
| 146 |
io1.in.size = len; |
| 147 |
|
| 148 |
torture_comment(tctx, "Testing savefile\n"); |
| 149 |
|
| 150 |
status = smb_composite_savefile(cli->tree, &io1); |
| 151 |
torture_assert_ntstatus_equal(tctx, status, NT_STATUS_OK, "savefile failed"); |
| 152 |
|
| 153 |
ZERO_STRUCT(io2); |
| 154 |
|
| 155 |
io2.in.dest_host = torture_setting_string(tctx, "host", NULL); |
| 156 |
io2.in.called_name = torture_setting_string(tctx, "host", NULL); |
| 157 |
io2.in.service = torture_setting_string(tctx, "share", NULL); |
| 158 |
io2.in.service_type = "A:"; |
| 159 |
io2.in.socket_options = lpcfg_socket_options(tctx->lp_ctx); |
| 160 |
|
| 161 |
io2.in.credentials = samba_cmdline_get_creds(); |
| 162 |
io2.in.workgroup = lpcfg_workgroup(tctx->lp_ctx); |
| 163 |
io2.in.filename = fname; |
| 164 |
lpcfg_smbcli_options(tctx->lp_ctx, &io2.in.options); |
| 165 |
lpcfg_smbcli_session_options(tctx->lp_ctx, &io2.in.session_options); |
| 166 |
io2.in.resolve_ctx = lpcfg_resolve_context(tctx->lp_ctx); |
| 167 |
io2.in.gensec_settings = lpcfg_gensec_settings(tctx, tctx->lp_ctx); |
| 168 |
|
| 169 |
torture_comment(tctx, "Testing parallel fetchfile with %d ops\n", torture_numops); |
| 170 |
|
| 171 |
event_ctx = tctx->ev; |
| 172 |
c = talloc_array(tctx, struct composite_context *, torture_numops); |
| 173 |
|
| 174 |
for (i=0; i<torture_numops; i++) { |
| 175 |
c[i] = smb_composite_fetchfile_send(&io2, tctx->lp_ctx, event_ctx); |
| 176 |
c[i]->async.fn = loadfile_complete; |
| 177 |
c[i]->async.private_data = count; |
| 178 |
} |
| 179 |
|
| 180 |
torture_comment(tctx, "waiting for completion\n"); |
| 181 |
|
| 182 |
while (*count != torture_numops) { |
| 183 |
tevent_loop_once(event_ctx); |
| 184 |
if (torture_setting_bool(tctx, "progress", true)) { |
| 185 |
torture_comment(tctx, "(%s) count=%d\r", __location__, *count); |
| 186 |
fflush(stdout); |
| 187 |
} |
| 188 |
} |
| 189 |
torture_comment(tctx, "count=%d\n", *count); |
| 190 |
|
| 191 |
for (i=0;i<torture_numops;i++) { |
| 192 |
status = smb_composite_fetchfile_recv(c[i], tctx); |
| 193 |
torture_assert_ntstatus_equal(tctx, status, NT_STATUS_OK, "loadfile failed"); |
| 194 |
|
| 195 |
torture_assert_int_equal(tctx, io2.out.size, len, "wrong length in returned data"); |
| 196 |
torture_assert_mem_equal(tctx, io2.out.data, data, len, "wrong data in loadfile"); |
| 197 |
} |
| 198 |
|
| 199 |
return ret; |
| 200 |
} |
| 201 |
|
| 202 |
static bool test_fetchfile_t(struct torture_context *tctx, struct smbcli_state *cli) |
| 203 |
{ |
| 204 |
int ret; |
| 205 |
torture_assert(tctx, torture_setup_dir(cli, BASEDIR), "failed to setup " BASEDIR); |
| 206 |
ret = test_fetchfile(tctx, cli); |
| 207 |
smb_raw_exit(cli->session); |
| 208 |
smbcli_deltree(cli->tree, BASEDIR); |
| 209 |
|
| 210 |
return ret; |
| 211 |
} |
| 212 |
|
| 213 |
/* |
| 214 |
test setfileacl |
| 215 |
*/ |
| 216 |
static bool test_appendacl(struct torture_context *tctx, struct smbcli_state *cli) |
| 217 |
{ |
| 218 |
struct smb_composite_appendacl **io; |
| 219 |
struct smb_composite_appendacl **io_orig; |
| 220 |
struct composite_context **c; |
| 221 |
struct tevent_context *event_ctx; |
| 222 |
|
| 223 |
struct security_descriptor *test_sd; |
| 224 |
struct security_ace *ace; |
| 225 |
struct dom_sid *test_sid; |
| 226 |
|
| 227 |
const int num_ops = 50; |
| 228 |
int *count = talloc_zero(tctx, int); |
| 229 |
struct smb_composite_savefile io1; |
| 230 |
|
| 231 |
NTSTATUS status; |
| 232 |
int i; |
| 233 |
|
| 234 |
io_orig = talloc_array(tctx, struct smb_composite_appendacl *, num_ops); |
| 235 |
|
| 236 |
printf ("creating %d empty files and getting their acls with appendacl\n", num_ops); |
| 237 |
|
| 238 |
for (i = 0; i < num_ops; i++) { |
| 239 |
io1.in.fname = talloc_asprintf(io_orig, BASEDIR "\\test%d.txt", i); |
| 240 |
io1.in.data = NULL; |
| 241 |
io1.in.size = 0; |
| 242 |
|
| 243 |
status = smb_composite_savefile(cli->tree, &io1); |
| 244 |
torture_assert_ntstatus_equal(tctx, status, NT_STATUS_OK, "savefile failed"); |
| 245 |
|
| 246 |
io_orig[i] = talloc (io_orig, struct smb_composite_appendacl); |
| 247 |
io_orig[i]->in.fname = talloc_steal(io_orig[i], io1.in.fname); |
| 248 |
io_orig[i]->in.sd = security_descriptor_initialise(io_orig[i]); |
| 249 |
status = smb_composite_appendacl(cli->tree, io_orig[i], io_orig[i]); |
| 250 |
torture_assert_ntstatus_equal(tctx, status, NT_STATUS_OK, "appendacl failed"); |
| 251 |
} |
| 252 |
|
| 253 |
|
| 254 |
/* fill Security Descriptor with aces to be added */ |
| 255 |
|
| 256 |
test_sd = security_descriptor_initialise(tctx); |
| 257 |
test_sid = dom_sid_parse_talloc (tctx, "S-1-5-32-1234-5432"); |
| 258 |
|
| 259 |
ace = talloc_zero(tctx, struct security_ace); |
| 260 |
|
| 261 |
ace->type = SEC_ACE_TYPE_ACCESS_ALLOWED; |
| 262 |
ace->flags = 0; |
| 263 |
ace->access_mask = SEC_STD_ALL; |
| 264 |
ace->trustee = *test_sid; |
| 265 |
|
| 266 |
status = security_descriptor_dacl_add(test_sd, ace); |
| 267 |
torture_assert_ntstatus_equal(tctx, status, NT_STATUS_OK, "appendacl failed"); |
| 268 |
|
| 269 |
/* set parameters for appendacl async call */ |
| 270 |
|
| 271 |
torture_comment(tctx, "Testing parallel appendacl with %d ops\n", num_ops); |
| 272 |
|
| 273 |
c = talloc_array(tctx, struct composite_context *, num_ops); |
| 274 |
io = talloc_array(tctx, struct smb_composite_appendacl *, num_ops); |
| 275 |
|
| 276 |
for (i=0; i < num_ops; i++) { |
| 277 |
io[i] = talloc (io, struct smb_composite_appendacl); |
| 278 |
io[i]->in.sd = test_sd; |
| 279 |
io[i]->in.fname = talloc_asprintf(io[i], BASEDIR "\\test%d.txt", i); |
| 280 |
|
| 281 |
c[i] = smb_composite_appendacl_send(cli->tree, io[i]); |
| 282 |
c[i]->async.fn = loadfile_complete; |
| 283 |
c[i]->async.private_data = count; |
| 284 |
} |
| 285 |
|
| 286 |
event_ctx = tctx->ev; |
| 287 |
torture_comment(tctx, "waiting for completion\n"); |
| 288 |
while (*count != num_ops) { |
| 289 |
tevent_loop_once(event_ctx); |
| 290 |
if (torture_setting_bool(tctx, "progress", true)) { |
| 291 |
torture_comment(tctx, "(%s) count=%d\r", __location__, *count); |
| 292 |
fflush(stdout); |
| 293 |
} |
| 294 |
} |
| 295 |
torture_comment(tctx, "count=%d\n", *count); |
| 296 |
|
| 297 |
for (i=0; i < num_ops; i++) { |
| 298 |
status = smb_composite_appendacl_recv(c[i], io[i]); |
| 299 |
if (!NT_STATUS_IS_OK(status)) { |
| 300 |
torture_comment(tctx, "(%s) appendacl[%d] failed - %s\n", __location__, i, nt_errstr(status)); |
| 301 |
return false; |
| 302 |
} |
| 303 |
|
| 304 |
security_descriptor_dacl_add(io_orig[i]->out.sd, ace); |
| 305 |
torture_assert(tctx, |
| 306 |
security_acl_equal(io_orig[i]->out.sd->dacl, |
| 307 |
io[i]->out.sd->dacl), |
| 308 |
"appendacl failed - needed acl isn't set"); |
| 309 |
} |
| 310 |
|
| 311 |
|
| 312 |
talloc_free (ace); |
| 313 |
talloc_free (test_sid); |
| 314 |
talloc_free (test_sd); |
| 315 |
|
| 316 |
return true; |
| 317 |
} |
| 318 |
|
| 319 |
static bool test_appendacl_t(struct torture_context *tctx, struct smbcli_state *cli) |
| 320 |
{ |
| 321 |
int ret; |
| 322 |
torture_assert(tctx, torture_setup_dir(cli, BASEDIR), "failed to setup " BASEDIR); |
| 323 |
ret = test_appendacl(tctx, cli); |
| 324 |
smb_raw_exit(cli->session); |
| 325 |
smbcli_deltree(cli->tree, BASEDIR); |
| 326 |
|
| 327 |
return ret; |
| 328 |
} |
| 329 |
|
| 330 |
/* test a query FS info by asking for share's GUID */ |
| 331 |
static bool test_fsinfo(struct torture_context *tctx, struct smbcli_state *cli) |
| 332 |
{ |
| 333 |
char *guid = NULL; |
| 334 |
NTSTATUS status; |
| 335 |
struct smb_composite_fsinfo io1; |
| 336 |
struct composite_context **c; |
| 337 |
|
| 338 |
int i; |
| 339 |
extern int torture_numops; |
| 340 |
struct tevent_context *event_ctx; |
| 341 |
int *count = talloc_zero(tctx, int); |
| 342 |
bool ret = true; |
| 343 |
|
| 344 |
io1.in.dest_host = torture_setting_string(tctx, "host", NULL); |
| 345 |
io1.in.socket_options = lpcfg_socket_options(tctx->lp_ctx); |
| 346 |
io1.in.called_name = torture_setting_string(tctx, "host", NULL); |
| 347 |
io1.in.service = torture_setting_string(tctx, "share", NULL); |
| 348 |
io1.in.service_type = "A:"; |
| 349 |
io1.in.credentials = samba_cmdline_get_creds(); |
| 350 |
io1.in.workgroup = lpcfg_workgroup(tctx->lp_ctx); |
| 351 |
io1.in.level = RAW_QFS_OBJECTID_INFORMATION; |
| 352 |
io1.in.gensec_settings = lpcfg_gensec_settings(tctx, tctx->lp_ctx); |
| 353 |
|
| 354 |
torture_comment(tctx, "Testing parallel queryfsinfo [Object ID] with %d ops\n", |
| 355 |
torture_numops); |
| 356 |
|
| 357 |
event_ctx = tctx->ev; |
| 358 |
c = talloc_array(tctx, struct composite_context *, torture_numops); |
| 359 |
|
| 360 |
for (i=0; i<torture_numops; i++) { |
| 361 |
c[i] = smb_composite_fsinfo_send(cli->tree, &io1, tctx->lp_ctx, |
| 362 |
lpcfg_resolve_context(tctx->lp_ctx), event_ctx); |
| 363 |
torture_assert(tctx, c[i], "smb_composite_fsinfo_send failed!"); |
| 364 |
c[i]->async.fn = loadfile_complete; |
| 365 |
c[i]->async.private_data = count; |
| 366 |
} |
| 367 |
|
| 368 |
torture_comment(tctx, "waiting for completion\n"); |
| 369 |
|
| 370 |
while (*count < torture_numops) { |
| 371 |
tevent_loop_once(event_ctx); |
| 372 |
if (torture_setting_bool(tctx, "progress", true)) { |
| 373 |
torture_comment(tctx, "(%s) count=%d\r", __location__, *count); |
| 374 |
fflush(stdout); |
| 375 |
} |
| 376 |
} |
| 377 |
torture_comment(tctx, "count=%d\n", *count); |
| 378 |
|
| 379 |
for (i=0;i<torture_numops;i++) { |
| 380 |
status = smb_composite_fsinfo_recv(c[i], tctx); |
| 381 |
torture_assert_ntstatus_equal(tctx, status, NT_STATUS_OK, "smb_composite_fsinfo_recv failed"); |
| 382 |
|
| 383 |
torture_assert_int_equal(tctx, io1.out.fsinfo->generic.level, RAW_QFS_OBJECTID_INFORMATION, "wrong level in returned info"); |
| 384 |
|
| 385 |
guid=GUID_string(tctx, &io1.out.fsinfo->objectid_information.out.guid); |
| 386 |
torture_comment(tctx, "[%d] GUID: %s\n", i, guid); |
| 387 |
} |
| 388 |
|
| 389 |
return ret; |
| 390 |
} |
| 391 |
|
| 392 |
static bool test_fsinfo_t(struct torture_context *tctx, struct smbcli_state *cli) |
| 393 |
{ |
| 394 |
int ret; |
| 395 |
torture_assert(tctx, torture_setup_dir(cli, BASEDIR), "failed to setup " BASEDIR); |
| 396 |
ret = test_fsinfo(tctx, cli); |
| 397 |
smb_raw_exit(cli->session); |
| 398 |
smbcli_deltree(cli->tree, BASEDIR); |
| 399 |
|
| 400 |
return ret; |
| 401 |
} |
| 402 |
|
| 403 |
/* |
| 404 |
basic testing of all RAW_SEARCH_* calls using a single file |
| 405 |
*/ |
| 406 |
struct torture_suite *torture_raw_composite(TALLOC_CTX *mem_ctx) |
| 407 |
{ |
| 408 |
struct torture_suite *suite = torture_suite_create(mem_ctx, "composite"); |
| 409 |
|
| 410 |
torture_suite_add_1smb_test(suite, "fetchfile", test_fetchfile_t); |
| 411 |
torture_suite_add_1smb_test(suite, "loadfile", test_loadfile_t); |
| 412 |
torture_suite_add_1smb_test(suite, "appendacl", test_appendacl_t); |
| 413 |
torture_suite_add_1smb_test(suite, "fsinfo", test_fsinfo_t); |
| 414 |
|
| 415 |
return suite; |
| 416 |
} |