]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
s3: smbtorture3: Add test_smb1_getatr() DFS test to run_smb1_dfs_operations().
authorJeremy Allison <jra@samba.org>
Wed, 7 Sep 2022 23:04:03 +0000 (16:04 -0700)
committerJeremy Allison <jra@samba.org>
Wed, 14 Sep 2022 17:33:37 +0000 (17:33 +0000)
Passes against Windows.

Signed-off-by: Jeremy Allison <jra@samba.org>
Reviewed-by: Noel Power <npower@samba.org>
source3/torture/test_smb1_dfs.c

index a63b6ec044985aa997f7655c2ede93d2743819cc..636e972376936c787c00692bc31e05bac9833a8a 100644 (file)
@@ -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: