s4 torure: Add SMB2 utility functions
authorZack Kirsch <zack.kirsch@isilon.com>
Wed, 1 Jul 2009 20:30:12 +0000 (13:30 -0700)
committerTim Prouty <tprouty@samba.org>
Tue, 8 Dec 2009 00:54:16 +0000 (16:54 -0800)
- Add a torture_setup_dir() equivalent in SMB2, called smb2_util_setup_dir().
- Add verify_sd() and verify_attrib() helper functions for SMB2.

source4/libcli/smb2/util.c
source4/torture/smb2/util.c

index 9b8d6887b146eb427e27474dae39fc9339189db5..992bd5c1d96b774436edd8c0629911c1bf79a9c4 100644 (file)
@@ -25,6 +25,7 @@
 #include "libcli/smb2/smb2.h"
 #include "libcli/smb2/smb2_calls.h"
 #include "libcli/smb_composite/smb_composite.h"
+#include "librpc/gen_ndr/ndr_security.h"
 
 /*
   simple close wrapper with SMB2
index e7ac4db9802759169d3564d1ca23fc7d8e81d3ce..4fb7cfbef251533094242b25f027fb3d58250b7b 100644 (file)
@@ -354,7 +354,7 @@ NTSTATUS torture_smb2_testdir(struct smb2_tree *tree, const char *fname,
 
 
 /*
-  create a complex file using the old SMB protocol, to make it easier to 
+  create a complex file using SMB2, to make it easier to
   find fields in SMB2 getinfo levels
 */
 NTSTATUS torture_setup_complex_file(struct smb2_tree *tree, const char *fname)
@@ -367,7 +367,7 @@ NTSTATUS torture_setup_complex_file(struct smb2_tree *tree, const char *fname)
 
 
 /*
-  create a complex dir using the old SMB protocol, to make it easier to 
+  create a complex dir using SMB2, to make it easier to
   find fields in SMB2 getinfo levels
 */
 NTSTATUS torture_setup_complex_dir(struct smb2_tree *tree, const char *fname)
@@ -403,3 +403,106 @@ NTSTATUS smb2_util_roothandle(struct smb2_tree *tree, struct smb2_handle *handle
 
        return NT_STATUS_OK;
 }
+
+/* Comparable to torture_setup_dir, but for SMB2. */
+bool smb2_util_setup_dir(struct torture_context *tctx, struct smb2_tree *tree,
+    const char *dname)
+{
+       NTSTATUS status;
+
+       /* XXX: smb_raw_exit equivalent?
+       smb_raw_exit(cli->session); */
+       if (smb2_deltree(tree, dname) == -1) {
+               torture_result(tctx, TORTURE_ERROR, "Unable to deltree when setting up %s.\n", dname);
+               return false;
+       }
+
+       status = smb2_util_mkdir(tree, dname);
+       if (NT_STATUS_IS_ERR(status)) {
+               torture_result(tctx, TORTURE_ERROR, "Unable to mkdir when setting up %s - %s\n", dname,
+                   nt_errstr(status));
+               return false;
+       }
+
+       return true;
+}
+
+#define CHECK_STATUS(status, correct) do { \
+       if (!NT_STATUS_EQUAL(status, correct)) { \
+               torture_result(tctx, TORTURE_FAIL, "(%s) Incorrect status %s - should be %s\n", \
+                      __location__, nt_errstr(status), nt_errstr(correct)); \
+               ret = false; \
+               goto done; \
+       }} while (0)
+
+/*
+ * Helper function to verify a security descriptor, by querying
+ * and comparing against the passed in sd.
+ */
+bool smb2_util_verify_sd(TALLOC_CTX *tctx, struct smb2_tree *tree,
+    struct smb2_handle handle, struct security_descriptor *sd)
+{
+       NTSTATUS status;
+       bool ret = true;
+       union smb_fileinfo q = {}, q2 = {};
+
+       if (sd) {
+               q.query_secdesc.level = RAW_FILEINFO_SEC_DESC;
+               q.query_secdesc.in.file.handle = handle;
+               q.query_secdesc.in.secinfo_flags =
+                   SECINFO_OWNER |
+                   SECINFO_GROUP |
+                   SECINFO_DACL;
+               status = smb2_getinfo_file(tree, tctx, &q);
+               CHECK_STATUS(status, NT_STATUS_OK);
+
+               if (!security_acl_equal(
+                   q.query_secdesc.out.sd->dacl, sd->dacl)) {
+                       torture_warning(tctx, "%s: security descriptors don't match!\n",
+                           __location__);
+                       torture_warning(tctx, "got:\n");
+                       NDR_PRINT_DEBUG(security_descriptor,
+                           q.query_secdesc.out.sd);
+                       torture_warning(tctx, "expected:\n");
+                       NDR_PRINT_DEBUG(security_descriptor, sd);
+                       ret = false;
+               }
+       }
+
+ done:
+       return ret;
+}
+
+/*
+ * Helper function to verify attributes, by querying
+ * and comparing against the passed in attrib.
+ */
+bool smb2_util_verify_attrib(TALLOC_CTX *tctx, struct smb2_tree *tree,
+    struct smb2_handle handle, uint32_t attrib)
+{
+       NTSTATUS status;
+       bool ret = true;
+       union smb_fileinfo q = {}, q2 = {};
+
+       if (attrib) {
+               q2.standard.level = RAW_FILEINFO_STANDARD;
+               q2.standard.in.file.handle = handle;
+               status = smb2_getinfo_file(tree, tctx, &q2);
+               CHECK_STATUS(status, NT_STATUS_OK);
+
+               q2.standard.out.attrib &= ~FILE_ATTRIBUTE_ARCHIVE;
+
+               if (q2.standard.out.attrib != attrib) {
+                       torture_warning(tctx, "%s: attributes don't match! "
+                           "got %x, expected %x\n", __location__,
+                           (uint32_t)q2.standard.out.attrib,
+                           (uint32_t)attrib);
+                       ret = false;
+               }
+       }
+
+ done:
+       return ret;
+}
+
+