From 7c7e1fd5c7028fa242213bfa13551dbcff181077 Mon Sep 17 00:00:00 2001 From: Michael Adam Date: Fri, 27 Jan 2012 17:20:23 +0100 Subject: s4:torture: add torture_smb2_tree_connect() utility function This does a tcon based on an existing session, using the name an host present in the torture context. --- source4/torture/smb2/util.c | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) (limited to 'source4/torture/smb2/util.c') diff --git a/source4/torture/smb2/util.c b/source4/torture/smb2/util.c index 094161e6eb..8ab61c7934 100644 --- a/source4/torture/smb2/util.c +++ b/source4/torture/smb2/util.c @@ -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 -- cgit