From: Ralph Boehme Date: Thu, 1 Dec 2022 05:13:22 +0000 (+0100) Subject: torture: test that a find with a mangled name works X-Git-Tag: talloc-2.4.0~361 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=4bb3e4df3e44dc7935d3852c8f45b5e4652a4df3;p=thirdparty%2Fsamba.git torture: test that a find with a mangled name works This was spawned by https://bugzilla.samba.org/show_bug.cgi?id=13472 back then. Samba implement this correctly, just add this test found in the attic. Signed-off-by: Ralph Boehme Reviewed-by: Jeremy Allison Autobuild-User(master): Jeremy Allison Autobuild-Date(master): Sat Dec 10 00:07:09 UTC 2022 on sn-devel-184 --- diff --git a/source4/torture/smb2/mangle.c b/source4/torture/smb2/mangle.c index 118aeb2d066..09097ee6d78 100644 --- a/source4/torture/smb2/mangle.c +++ b/source4/torture/smb2/mangle.c @@ -246,6 +246,88 @@ static bool torture_smb2_mangle(struct torture_context *torture, return (failures == 0); } +static bool test_mangled_mask(struct torture_context *tctx, + struct smb2_tree *tree) +{ + bool ret = true; + const char *dname = "single_find_with_mangled_name"; + const char *fname = "single_find_with_mangled_name\\verylongfilename"; + const char *shortname = NULL; + NTSTATUS status; + struct smb2_handle dh = {{0}}; + struct smb2_handle fh = {{0}}; + struct smb2_find f; + union smb_search_data *d; + unsigned count, i; + + torture_comment(tctx, "Checking find with mangled search mask\n"); + + smb2_deltree(tree, dname); + + status = torture_smb2_testdir(tree, dname, &dh); + torture_assert_ntstatus_ok_goto(tctx, status, ret, done, + "torture_smb2_testdir failed"); + + status = torture_smb2_testfile(tree, fname, &fh); + smb2_util_close(tree, fh); + + ZERO_STRUCT(f); + f.in.file.handle = dh; + f.in.pattern = "*"; + f.in.max_response_size = 0x1000; + f.in.level = SMB2_FIND_BOTH_DIRECTORY_INFO; + + status = smb2_find_level(tree, tree, &f, &count, &d); + torture_assert_ntstatus_ok_goto(tctx, status, ret, done, + "smb2_find_level failed\n"); + smb2_util_close(tree, dh); + ZERO_STRUCT(dh); + + for (i = 0; i < count; i++) { + const char *found = d[i].both_directory_info.name.s; + + if (!strcmp(found, ".") || !strcmp(found, "..")) { + continue; + } + + torture_assert_str_equal_goto(tctx, found, "verylongfilename", ret, done, + "Bad filename\n"); + shortname = d[i].both_directory_info.short_name.s; + break; + } + + torture_assert_not_null_goto(tctx, shortname, ret, done, + "shortname is NULL\n"); + + torture_comment(tctx, "Got shortname: %s\n", shortname); + + status = torture_smb2_testdir(tree, dname, &dh); + + ZERO_STRUCT(f); + f.in.file.handle = dh; + f.in.continue_flags = SMB2_CONTINUE_FLAG_SINGLE; + f.in.pattern = shortname; + f.in.max_response_size = 0x1000; + f.in.level = SMB2_FIND_BOTH_DIRECTORY_INFO; + + status = smb2_find_level(tree, tree, &f, &count, &d); + torture_assert_ntstatus_ok_goto(tctx, status, ret, done, + "smb2_find_level failed\n"); + smb2_util_close(tree, dh); + ZERO_STRUCT(dh); + +done: + if (!smb2_util_handle_empty(fh)) { + smb2_util_close(tree, fh); + } + if (!smb2_util_handle_empty(dh)) { + smb2_util_close(tree, dh); + } + smb2_deltree(tree, dname); + return ret; + +} + struct torture_suite *torture_smb2_name_mangling_init(TALLOC_CTX *ctx) { struct torture_suite *suite = NULL; @@ -254,5 +336,6 @@ struct torture_suite *torture_smb2_name_mangling_init(TALLOC_CTX *ctx) suite->description = talloc_strdup(suite, "SMB2 name mangling tests"); torture_suite_add_1smb2_test(suite, "mangle", torture_smb2_mangle); + torture_suite_add_1smb2_test(suite, "mangled-mask", test_mangled_mask); return suite; }