From 8a5828de2bdd95223e5f30996d0490fef53742dd Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Thu, 25 Apr 2019 14:57:02 +0200 Subject: [PATCH] s4:torture/smb2: add smb2.getinfo.normalized test BUG: https://bugzilla.samba.org/show_bug.cgi?id=13919 Signed-off-by: Stefan Metzmacher Reviewed-by: Jeremy Allison --- selftest/knownfail.d/smb2-getinfo | 1 + source4/torture/smb2/getinfo.c | 311 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 312 insertions(+) create mode 100644 selftest/knownfail.d/smb2-getinfo diff --git a/selftest/knownfail.d/smb2-getinfo b/selftest/knownfail.d/smb2-getinfo new file mode 100644 index 00000000000..10ee423e55a --- /dev/null +++ b/selftest/knownfail.d/smb2-getinfo @@ -0,0 +1 @@ +^samba3.smb2.getinfo.normalized diff --git a/source4/torture/smb2/getinfo.c b/source4/torture/smb2/getinfo.c index 2e36082e067..5c9097f4200 100644 --- a/source4/torture/smb2/getinfo.c +++ b/source4/torture/smb2/getinfo.c @@ -170,6 +170,315 @@ static bool torture_smb2_fileinfo_grant_read(struct torture_context *tctx) return true; } +static bool torture_smb2_fileinfo_normalized(struct torture_context *tctx) +{ + struct smb2_tree *tree = NULL; + bool ret; + struct smb2_handle hroot; + const char *d1 = NULL, *d1l = NULL, *d1u = NULL; + struct smb2_handle hd1, hd1l, hd1u; + const char *d2 = NULL, *d2l = NULL, *d2u = NULL; + struct smb2_handle hd2, hd2l, hd2u; + const char *d3 = NULL, *d3l = NULL, *d3u = NULL; + struct smb2_handle hd3, hd3l, hd3u; + const char *d3s = NULL, *d3sl = NULL, *d3su = NULL, *d3sd = NULL; + struct smb2_handle hd3s, hd3sl, hd3su, hd3sd; + const char *f4 = NULL, *f4l = NULL, *f4u = NULL, *f4d = NULL; + struct smb2_handle hf4, hf4l, hf4u, hf4d; + const char *f4s = NULL, *f4sl = NULL, *f4su = NULL, *f4sd = NULL; + struct smb2_handle hf4s, hf4sl, hf4su, hf4sd; + union smb_fileinfo info = { + .normalized_name_info = { + .level = RAW_FILEINFO_NORMALIZED_NAME_INFORMATION, + }, + }; + NTSTATUS status; + enum protocol_types protocol; + struct smb2_tree *tree_3_0 = NULL; + struct smbcli_options options3_0; + struct smb2_handle hroot_3_0; + + ret = torture_smb2_connection(tctx, &tree); + torture_assert(tctx, ret, "connection failed"); + + protocol = smbXcli_conn_protocol(tree->session->transport->conn); + + d1 = talloc_asprintf(tctx, "torture_dIr1N"); + torture_assert_not_null(tctx, d1, "d1"); + d1l = strlower_talloc(tctx, d1); + torture_assert_not_null(tctx, d1l, "d1l"); + d1u = strupper_talloc(tctx, d1); + torture_assert_not_null(tctx, d1u, "d1u"); + + d2 = talloc_asprintf(tctx, "%s\\dIr2Na", d1); + torture_assert_not_null(tctx, d2, "d2"); + d2l = strlower_talloc(tctx, d2); + torture_assert_not_null(tctx, d2l, "d2l"); + d2u = strupper_talloc(tctx, d2); + torture_assert_not_null(tctx, d2u, "d2u"); + + d3 = talloc_asprintf(tctx, "%s\\dIr3NaM", d2); + torture_assert_not_null(tctx, d3, "d3"); + d3l = strlower_talloc(tctx, d3); + torture_assert_not_null(tctx, d3l, "d3l"); + d3u = strupper_talloc(tctx, d3); + torture_assert_not_null(tctx, d3u, "d3u"); + + d3s = talloc_asprintf(tctx, "%s:sTrEaM3", d3); + torture_assert_not_null(tctx, d3s, "d3s"); + d3sl = strlower_talloc(tctx, d3s); + torture_assert_not_null(tctx, d3sl, "d3sl"); + d3su = strupper_talloc(tctx, d3s); + torture_assert_not_null(tctx, d3su, "d3su"); + d3sd = talloc_asprintf(tctx, "%s:$DaTa", d3s); + torture_assert_not_null(tctx, d3sd, "d3sd"); + + f4 = talloc_asprintf(tctx, "%s\\fIlE4NaMe", d3); + torture_assert_not_null(tctx, f4, "f4"); + f4l = strlower_talloc(tctx, f4); + torture_assert_not_null(tctx, f4l, "f4l"); + f4u = strupper_talloc(tctx, f4); + torture_assert_not_null(tctx, f4u, "f4u"); + f4d = talloc_asprintf(tctx, "%s::$dAtA", f4); + torture_assert_not_null(tctx, f4d, "f4d"); + + f4s = talloc_asprintf(tctx, "%s:StReAm4", f4); + torture_assert_not_null(tctx, f4s, "f4s"); + f4sl = strlower_talloc(tctx, f4s); + torture_assert_not_null(tctx, f4sl, "f4sl"); + f4su = strupper_talloc(tctx, f4s); + torture_assert_not_null(tctx, f4su, "f4su"); + f4sd = talloc_asprintf(tctx, "%s:$dAtA", f4s); + torture_assert_not_null(tctx, f4sd, "f4sd"); + + status = smb2_util_roothandle(tree, &hroot); + torture_assert_ntstatus_ok(tctx, status, "Unable to create root handle"); + + info.normalized_name_info.in.file.handle = hroot; + ZERO_STRUCT(info.normalized_name_info.out); + status = smb2_getinfo_file(tree, tree, &info); + if (protocol < PROTOCOL_SMB3_11) { + /* + * Only SMB 3.1.1 and above should offer this. + */ + torture_assert_ntstatus_equal(tctx, status, + NT_STATUS_NOT_SUPPORTED, + "getinfo hroot"); + torture_skip(tctx, "SMB 3.1.1 not supported"); + } + if (NT_STATUS_EQUAL(status, NT_STATUS_NOT_SUPPORTED)) { + /* + * Not all servers support this. + * (only Windows 10 1803 and higher) + */ + torture_skip(tctx, "NORMALIZED_NAME_INFORMATION not supported"); + } + torture_assert_ntstatus_ok(tctx, status, "getinfo hroot"); + torture_assert(tctx, info.normalized_name_info.out.fname.s == NULL, + "getinfo hroot should be empty"); + + smb2_deltree(tree, d1); + + status = torture_smb2_testdir(tree, d1, &hd1); + torture_assert_ntstatus_ok(tctx, status, "Unable to create hd1"); + status = torture_smb2_open(tree, d1l, SEC_RIGHTS_FILE_ALL, &hd1l); + torture_assert_ntstatus_ok(tctx, status, "Unable to open hd1l"); + status = torture_smb2_open(tree, d1u, SEC_RIGHTS_FILE_ALL, &hd1u); + torture_assert_ntstatus_ok(tctx, status, "Unable to open hd1u"); + + status = torture_smb2_testdir(tree, d2, &hd2); + torture_assert_ntstatus_ok(tctx, status, "Unable to create hd2"); + status = torture_smb2_open(tree, d2l, SEC_RIGHTS_FILE_ALL, &hd2l); + torture_assert_ntstatus_ok(tctx, status, "Unable to open hd2l"); + status = torture_smb2_open(tree, d2u, SEC_RIGHTS_FILE_ALL, &hd2u); + torture_assert_ntstatus_ok(tctx, status, "Unable to open hd2u"); + + status = torture_smb2_testdir(tree, d3, &hd3); + torture_assert_ntstatus_ok(tctx, status, "Unable to create hd3"); + status = torture_smb2_open(tree, d3l, SEC_RIGHTS_FILE_ALL, &hd3l); + torture_assert_ntstatus_ok(tctx, status, "Unable to open hd3l"); + status = torture_smb2_open(tree, d3u, SEC_RIGHTS_FILE_ALL, &hd3u); + torture_assert_ntstatus_ok(tctx, status, "Unable to open hd3u"); + + status = torture_smb2_testfile(tree, d3s, &hd3s); + torture_assert_ntstatus_ok(tctx, status, "Unable to create hd3s"); + status = torture_smb2_open(tree, d3sl, SEC_RIGHTS_FILE_ALL, &hd3sl); + torture_assert_ntstatus_ok(tctx, status, "Unable to open hd3sl"); + status = torture_smb2_open(tree, d3su, SEC_RIGHTS_FILE_ALL, &hd3su); + torture_assert_ntstatus_ok(tctx, status, "Unable to open hd3su"); + status = torture_smb2_open(tree, d3sd, SEC_RIGHTS_FILE_ALL, &hd3sd); + torture_assert_ntstatus_ok(tctx, status, "Unable to open hd3sd"); + + status = torture_smb2_testfile(tree, f4, &hf4); + torture_assert_ntstatus_ok(tctx, status, "Unable to create hf4"); + status = torture_smb2_open(tree, f4l, SEC_RIGHTS_FILE_ALL, &hf4l); + torture_assert_ntstatus_ok(tctx, status, "Unable to open hf4l"); + status = torture_smb2_open(tree, f4u, SEC_RIGHTS_FILE_ALL, &hf4u); + torture_assert_ntstatus_ok(tctx, status, "Unable to open hf4u"); + status = torture_smb2_open(tree, f4d, SEC_RIGHTS_FILE_ALL, &hf4d); + torture_assert_ntstatus_ok(tctx, status, "Unable to open hf4d"); + + status = torture_smb2_testfile(tree, f4s, &hf4s); + torture_assert_ntstatus_ok(tctx, status, "Unable to create hf4s"); + status = torture_smb2_open(tree, f4sl, SEC_RIGHTS_FILE_ALL, &hf4sl); + torture_assert_ntstatus_ok(tctx, status, "Unable to open hf4sl"); + status = torture_smb2_open(tree, f4su, SEC_RIGHTS_FILE_ALL, &hf4su); + torture_assert_ntstatus_ok(tctx, status, "Unable to open hf4su"); + status = torture_smb2_open(tree, f4sd, SEC_RIGHTS_FILE_ALL, &hf4sd); + torture_assert_ntstatus_ok(tctx, status, "Unable to open hf4sd"); + + info.normalized_name_info.in.file.handle = hd1; + ZERO_STRUCT(info.normalized_name_info.out); + status = smb2_getinfo_file(tree, tree, &info); + torture_assert_ntstatus_ok(tctx, status, "getinfo hd1"); + torture_assert_str_equal(tctx, info.normalized_name_info.out.fname.s, + d1, "getinfo hd1"); + info.normalized_name_info.in.file.handle = hd1l; + ZERO_STRUCT(info.normalized_name_info.out); + status = smb2_getinfo_file(tree, tree, &info); + torture_assert_ntstatus_ok(tctx, status, "getinfo hd1l"); + torture_assert_str_equal(tctx, info.normalized_name_info.out.fname.s, + d1, "getinfo hd1l"); + info.normalized_name_info.in.file.handle = hd1u; + ZERO_STRUCT(info.normalized_name_info.out); + status = smb2_getinfo_file(tree, tree, &info); + torture_assert_ntstatus_ok(tctx, status, "getinfo hd1u"); + torture_assert_str_equal(tctx, info.normalized_name_info.out.fname.s, + d1, "getinfo hd1u"); + + info.normalized_name_info.in.file.handle = hd2; + ZERO_STRUCT(info.normalized_name_info.out); + status = smb2_getinfo_file(tree, tree, &info); + torture_assert_ntstatus_ok(tctx, status, "getinfo hd2"); + torture_assert_str_equal(tctx, info.normalized_name_info.out.fname.s, + d2, "getinfo hd2"); + info.normalized_name_info.in.file.handle = hd2l; + ZERO_STRUCT(info.normalized_name_info.out); + status = smb2_getinfo_file(tree, tree, &info); + torture_assert_ntstatus_ok(tctx, status, "getinfo hd2l"); + torture_assert_str_equal(tctx, info.normalized_name_info.out.fname.s, + d2, "getinfo hd2l"); + info.normalized_name_info.in.file.handle = hd2u; + ZERO_STRUCT(info.normalized_name_info.out); + status = smb2_getinfo_file(tree, tree, &info); + torture_assert_ntstatus_ok(tctx, status, "getinfo hd2u"); + torture_assert_str_equal(tctx, info.normalized_name_info.out.fname.s, + d2, "getinfo hd2u"); + + info.normalized_name_info.in.file.handle = hd3; + ZERO_STRUCT(info.normalized_name_info.out); + status = smb2_getinfo_file(tree, tree, &info); + torture_assert_ntstatus_ok(tctx, status, "getinfo hd3"); + torture_assert_str_equal(tctx, info.normalized_name_info.out.fname.s, + d3, "getinfo hd3"); + info.normalized_name_info.in.file.handle = hd3l; + ZERO_STRUCT(info.normalized_name_info.out); + status = smb2_getinfo_file(tree, tree, &info); + torture_assert_ntstatus_ok(tctx, status, "getinfo hd3l"); + torture_assert_str_equal(tctx, info.normalized_name_info.out.fname.s, + d3, "getinfo hd3l"); + info.normalized_name_info.in.file.handle = hd3u; + ZERO_STRUCT(info.normalized_name_info.out); + status = smb2_getinfo_file(tree, tree, &info); + torture_assert_ntstatus_ok(tctx, status, "getinfo hd3u"); + torture_assert_str_equal(tctx, info.normalized_name_info.out.fname.s, + d3, "getinfo hd3u"); + + info.normalized_name_info.in.file.handle = hd3s; + ZERO_STRUCT(info.normalized_name_info.out); + status = smb2_getinfo_file(tree, tree, &info); + torture_assert_ntstatus_ok(tctx, status, "getinfo hd3s"); + torture_assert_str_equal(tctx, info.normalized_name_info.out.fname.s, + d3s, "getinfo hd3s"); + info.normalized_name_info.in.file.handle = hd3sl; + ZERO_STRUCT(info.normalized_name_info.out); + status = smb2_getinfo_file(tree, tree, &info); + torture_assert_ntstatus_ok(tctx, status, "getinfo hd3sl"); + torture_assert_str_equal(tctx, info.normalized_name_info.out.fname.s, + d3s, "getinfo hd3sl"); + info.normalized_name_info.in.file.handle = hd3su; + ZERO_STRUCT(info.normalized_name_info.out); + status = smb2_getinfo_file(tree, tree, &info); + torture_assert_ntstatus_ok(tctx, status, "getinfo hd3su"); + torture_assert_str_equal(tctx, info.normalized_name_info.out.fname.s, + d3s, "getinfo hd3su"); + info.normalized_name_info.in.file.handle = hd3sd; + ZERO_STRUCT(info.normalized_name_info.out); + status = smb2_getinfo_file(tree, tree, &info); + torture_assert_ntstatus_ok(tctx, status, "getinfo hd3sd"); + torture_assert_str_equal(tctx, info.normalized_name_info.out.fname.s, + d3s, "getinfo hd3sd"); + + info.normalized_name_info.in.file.handle = hf4; + ZERO_STRUCT(info.normalized_name_info.out); + status = smb2_getinfo_file(tree, tree, &info); + torture_assert_ntstatus_ok(tctx, status, "getinfo hf4"); + torture_assert_str_equal(tctx, info.normalized_name_info.out.fname.s, + f4, "getinfo hf4"); + info.normalized_name_info.in.file.handle = hf4l; + ZERO_STRUCT(info.normalized_name_info.out); + status = smb2_getinfo_file(tree, tree, &info); + torture_assert_ntstatus_ok(tctx, status, "getinfo hf4l"); + torture_assert_str_equal(tctx, info.normalized_name_info.out.fname.s, + f4, "getinfo hf4l"); + info.normalized_name_info.in.file.handle = hf4u; + ZERO_STRUCT(info.normalized_name_info.out); + status = smb2_getinfo_file(tree, tree, &info); + torture_assert_ntstatus_ok(tctx, status, "getinfo hf4u"); + torture_assert_str_equal(tctx, info.normalized_name_info.out.fname.s, + f4, "getinfo hf4u"); + info.normalized_name_info.in.file.handle = hf4d; + ZERO_STRUCT(info.normalized_name_info.out); + status = smb2_getinfo_file(tree, tree, &info); + torture_assert_ntstatus_ok(tctx, status, "getinfo hf4d"); + torture_assert_str_equal(tctx, info.normalized_name_info.out.fname.s, + f4, "getinfo hf4d"); + + info.normalized_name_info.in.file.handle = hf4s; + ZERO_STRUCT(info.normalized_name_info.out); + status = smb2_getinfo_file(tree, tree, &info); + torture_assert_ntstatus_ok(tctx, status, "getinfo hf4s"); + torture_assert_str_equal(tctx, info.normalized_name_info.out.fname.s, + f4s, "getinfo hf4s"); + info.normalized_name_info.in.file.handle = hf4sl; + ZERO_STRUCT(info.normalized_name_info.out); + status = smb2_getinfo_file(tree, tree, &info); + torture_assert_ntstatus_ok(tctx, status, "getinfo hf4sl"); + torture_assert_str_equal(tctx, info.normalized_name_info.out.fname.s, + f4s, "getinfo hf4sl"); + info.normalized_name_info.in.file.handle = hf4su; + ZERO_STRUCT(info.normalized_name_info.out); + status = smb2_getinfo_file(tree, tree, &info); + torture_assert_ntstatus_ok(tctx, status, "getinfo hf4su"); + torture_assert_str_equal(tctx, info.normalized_name_info.out.fname.s, + f4s, "getinfo hf4su"); + info.normalized_name_info.in.file.handle = hf4sd; + ZERO_STRUCT(info.normalized_name_info.out); + status = smb2_getinfo_file(tree, tree, &info); + torture_assert_ntstatus_ok(tctx, status, "getinfo hf4sd"); + torture_assert_str_equal(tctx, info.normalized_name_info.out.fname.s, + f4s, "getinfo hf4sd"); + + /* Set max protocol to SMB 3.0.2 */ + options3_0 = tree->session->transport->options; + options3_0.max_protocol = PROTOCOL_SMB3_02; + options3_0.client_guid = GUID_zero(); + ret = torture_smb2_connection_ext(tctx, 0, &options3_0, &tree_3_0); + torture_assert(tctx, ret, "connection with SMB < 3.1.1 failed"); + + status = smb2_util_roothandle(tree_3_0, &hroot_3_0); + torture_assert_ntstatus_ok(tctx, status, "Unable to create root handle 3_0"); + + info.normalized_name_info.in.file.handle = hroot_3_0; + ZERO_STRUCT(info.normalized_name_info.out); + status = smb2_getinfo_file(tree_3_0, tree_3_0, &info); + torture_assert_ntstatus_equal(tctx, status, + NT_STATUS_NOT_SUPPORTED, + "getinfo hroot"); + + return true; +} + /* test fsinfo levels */ @@ -489,5 +798,7 @@ struct torture_suite *torture_smb2_getinfo_init(TALLOC_CTX *ctx) torture_smb2_qsec_buffercheck); torture_suite_add_simple_test(suite, "granted", torture_smb2_fileinfo_grant_read); + torture_suite_add_simple_test(suite, "normalized", + torture_smb2_fileinfo_normalized); return suite; } -- 2.11.4.GIT