s4:torture: add torture_smb2_tree_connect() utility function
authorMichael Adam <obnox@samba.org>
Fri, 27 Jan 2012 16:20:23 +0000 (17:20 +0100)
committerMichael Adam <obnox@samba.org>
Fri, 3 Feb 2012 10:10:30 +0000 (11:10 +0100)
This does a tcon based on an existing session, using the
name an host present in the torture context.

source4/torture/smb2/util.c

index 094161e6eb9ab0e8281d46c71ec7dc93da8f7fbd..8ab61c7934e31a0992471562c4f2c28843c855a1 100644 (file)
@@ -259,6 +259,48 @@ void torture_smb2_all_info(struct smb2_tree *tree, struct smb2_handle handle)
        talloc_free(tmp_ctx);   
 }
 
+/**
+ * open a smb2 tree connect
+ */
+bool torture_smb2_tree_connect(struct torture_context *tctx,
+                              struct smb2_session *session,
+                              TALLOC_CTX *mem_ctx,
+                              struct smb2_tree **_tree)
+{
+       NTSTATUS status;
+       const char *host = torture_setting_string(tctx, "host", NULL);
+       const char *share = torture_setting_string(tctx, "share", NULL);
+       struct smb2_tree_connect tcon;
+       struct smb2_tree *tree;
+
+       ZERO_STRUCT(tcon);
+       tcon.in.reserved = 0;
+       tcon.in.path = talloc_asprintf(tctx, "\\\\%s\\%s", host, share);
+       if (tcon.in.path == NULL) {
+               printf("talloc failed\n");
+               return false;
+       }
+
+       status = smb2_tree_connect(session, &tcon);
+       if (!NT_STATUS_IS_OK(status)) {
+               printf("Failed to tree_connect to SMB2 share \\\\%s\\%s - %s\n",
+                      host, share, nt_errstr(status));
+               return false;
+       }
+
+       tree = smb2_tree_init(session, mem_ctx, true);
+       if (tree == NULL) {
+               printf("talloc failed\n");
+               return false;
+       }
+
+       tree->tid = tcon.out.tid;
+
+       *_tree = tree;
+
+       return true;
+}
+
 
 /*
   open a smb2 connection