From: Jeremy Allison Date: Wed, 7 Sep 2022 23:04:03 +0000 (-0700) Subject: s3: smbtorture3: Add test_smb1_getatr() DFS test to run_smb1_dfs_operations(). X-Git-Tag: talloc-2.4.0~1047 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=243433bd57aeceb6c37a26dc62bb7bce8f6dac19;p=thirdparty%2Fsamba.git s3: smbtorture3: Add test_smb1_getatr() DFS test to run_smb1_dfs_operations(). Passes against Windows. Signed-off-by: Jeremy Allison Reviewed-by: Noel Power --- diff --git a/source3/torture/test_smb1_dfs.c b/source3/torture/test_smb1_dfs.c index a63b6ec0449..636e9723769 100644 --- a/source3/torture/test_smb1_dfs.c +++ b/source3/torture/test_smb1_dfs.c @@ -3416,6 +3416,147 @@ static bool test_smb1_create(struct cli_state *cli) return retval; } +static NTSTATUS smb1_getatr(struct cli_state *cli, + const char *path, + uint16_t *pattr) +{ + uint8_t *bytes = NULL; + uint16_t *return_words = NULL; + uint8_t return_wcount = 0; + NTSTATUS status; + + bytes = talloc_array(talloc_tos(), uint8_t, 1); + if (bytes == NULL) { + return NT_STATUS_NO_MEMORY; + } + bytes[0] = 4; + bytes = smb_bytes_push_str(bytes, + smbXcli_conn_use_unicode(cli->conn), + path, + strlen(path)+1, + NULL); + if (bytes == NULL) { + return NT_STATUS_NO_MEMORY; + } + + status = cli_smb(talloc_tos(), + cli, + SMBgetatr, /* command. */ + 0, /* additional_flags. */ + 0, /* wct. */ + NULL, /* vwv. */ + talloc_get_size(bytes), /* num_bytes. */ + bytes, /* bytes. */ + NULL, /* result parent. */ + 10, /* min_wct. */ + &return_wcount, /* return wcount. */ + &return_words, /* return wvw. */ + NULL, /* return byte count. */ + NULL); /* return bytes. */ + if (!NT_STATUS_IS_OK(status)) { + return status; + } + *pattr = PULL_LE_U16(return_words, 0); + return status; +} + +static bool test_smb1_getatr(struct cli_state *cli) +{ + NTSTATUS status; + bool retval = false; + bool ok = false; + uint16_t attrs = 0; + + /* Start clean. */ + (void)smb1_dfs_delete(cli, "\\BAD\\BAD\\getatrfile"); + + /* Create a test file. */ + ok = smb1_create_testfile(cli, "\\BAD\\BAD\\getatrfile"); + if (!ok) { + printf("%s:%d failed to create test file %s\n", + __FILE__, + __LINE__, + "\\BAD\\BAD\\getatrfile"); + goto err; + } + + /* + * We expect this to succeed, but get attributes of + * the root directory. + */ + status = smb1_getatr(cli, "getatrfile", &attrs); + if (!NT_STATUS_IS_OK(status)) { + printf("%s:%d SMB1getatr of %s failed (%s)\n", + __FILE__, + __LINE__, + "getatrfile", + nt_errstr(status)); + goto err; + } + if ((attrs & FILE_ATTRIBUTE_DIRECTORY) == 0) { + printf("%s:%d error expected SMB1getatr of file %s " + "to return directory attributes. Got 0x%x\n", + __FILE__, + __LINE__, + "getatrfile", + (unsigned int)attrs); + goto err; + } + + /* + * We expect this to succeed, but get attributes of + * the root directory. + */ + status = smb1_getatr(cli, "\\BAD\\getatrfile", &attrs); + if (!NT_STATUS_IS_OK(status)) { + printf("%s:%d SMB1getatr of %s failed (%s)\n", + __FILE__, + __LINE__, + "\\BAD\\getatrfile", + nt_errstr(status)); + goto err; + } + if ((attrs & FILE_ATTRIBUTE_DIRECTORY) == 0) { + printf("%s:%d error expected SMB1getatr of file %s " + "to return directory attributes. Got 0x%x\n", + __FILE__, + __LINE__, + "\\BAD\\getatrfile", + (unsigned int)attrs); + goto err; + } + + /* + * We expect this to succeed, and get attributes of + * the testfile. + */ + status = smb1_getatr(cli, "\\BAD\\BAD\\getatrfile", &attrs); + if (!NT_STATUS_IS_OK(status)) { + printf("%s:%d SMB1getatr of %s failed (%s)\n", + __FILE__, + __LINE__, + "\\BAD\\BAD\\getatrfile", + nt_errstr(status)); + goto err; + } + if (attrs & FILE_ATTRIBUTE_DIRECTORY) { + printf("%s:%d error expected SMB1getatr of file %s " + "to return non-directory attributes. Got 0x%x\n", + __FILE__, + __LINE__, + "\\BAD\\BAD\\getatrfile", + (unsigned int)attrs); + goto err; + } + + retval = true; + + err: + + (void)smb1_dfs_delete(cli, "\\BAD\\BAD\\getatrfile"); + return retval; +} + /* * "Raw" test of different SMB1 operations to a DFS share. * We must (mostly) use the lower level smb1cli_XXXX() interfaces, @@ -3498,6 +3639,11 @@ bool run_smb1_dfs_operations(int dummy) goto err; } + ok = test_smb1_getatr(cli); + if (!ok) { + goto err; + } + retval = true; err: