summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStefan Metzmacher <metze@samba.org>2014-09-25 03:28:37 +0200
committerMichael Adam <obnox@samba.org>2014-09-30 23:35:08 +0200
commitb77bb5a2e3db0656a799f3749140637ac85b5c05 (patch)
treefc770f35fb44c4d4dac5c58c919796fab61a6b68
parent7ee18fbf1e0fa108c4b3748269035fcee2a57ab5 (diff)
downloadsamba-b77bb5a2e3db0656a799f3749140637ac85b5c05.tar.gz
libcli/smb: move smb2cli_tcon.c to the toplevel
removing use of cli_state from the code. Signed-off-by: Stefan Metzmacher <metze@samba.org> Reviewed-by: Michael Adam <obnox@samba.org>
-rw-r--r--libcli/smb/smb2cli_tcon.c (renamed from source3/libsmb/smb2cli_tcon.c)97
-rw-r--r--libcli/smb/smbXcli_base.h28
-rwxr-xr-xlibcli/smb/wscript1
-rw-r--r--source3/libsmb/cliconnect.c24
-rw-r--r--source3/libsmb/smb2cli.h13
-rw-r--r--source3/torture/test_smb2.c10
-rwxr-xr-xsource3/wscript_build1
7 files changed, 111 insertions, 63 deletions
diff --git a/source3/libsmb/smb2cli_tcon.c b/libcli/smb/smb2cli_tcon.c
index d0c294de843..21c675e8d1e 100644
--- a/source3/libsmb/smb2cli_tcon.c
+++ b/libcli/smb/smb2cli_tcon.c
@@ -18,15 +18,15 @@
*/
#include "includes.h"
-#include "client.h"
-#include "async_smb.h"
+#include "system/network.h"
+#include "../lib/util/tevent_ntstatus.h"
+#include "../libcli/smb/smb_common.h"
#include "../libcli/smb/smbXcli_base.h"
-#include "smb2cli.h"
-#include "libsmb/proto.h"
-#include "lib/util/tevent_ntstatus.h"
struct smb2cli_tcon_state {
- struct cli_state *cli;
+ struct smbXcli_conn *conn;
+ struct smbXcli_session *session;
+ struct smbXcli_tcon *tcon;
uint8_t fixed[8];
uint8_t dyn_pad[1];
};
@@ -35,13 +35,16 @@ static void smb2cli_tcon_done(struct tevent_req *subreq);
struct tevent_req *smb2cli_tcon_send(TALLOC_CTX *mem_ctx,
struct tevent_context *ev,
- struct cli_state *cli,
- const char *share)
+ struct smbXcli_conn *conn,
+ uint32_t timeout_msec,
+ struct smbXcli_session *session,
+ struct smbXcli_tcon *tcon,
+ uint16_t flags,
+ const char *unc)
{
struct tevent_req *req, *subreq;
struct smb2cli_tcon_state *state;
uint8_t *fixed;
- const char *tcon_share;
uint8_t *dyn;
size_t dyn_len;
uint32_t additional_flags = 0;
@@ -51,22 +54,18 @@ struct tevent_req *smb2cli_tcon_send(TALLOC_CTX *mem_ctx,
if (req == NULL) {
return NULL;
}
- state->cli = cli;
+ state->conn = conn;
+ state->session = session;
+ state->tcon = tcon;
- tcon_share = talloc_asprintf(state, "\\\\%s\\%s",
- smbXcli_conn_remote_name(cli->conn),
- share);
- if (tevent_req_nomem(tcon_share, req)) {
- return tevent_req_post(req, ev);
- }
if (!convert_string_talloc(state, CH_UNIX, CH_UTF16,
- tcon_share, strlen(tcon_share),
+ unc, strlen(unc),
&dyn, &dyn_len)) {
tevent_req_oom(req);
return tevent_req_post(req, ev);
}
- if (strlen(tcon_share) == 0) {
+ if (strlen(unc) == 0) {
TALLOC_FREE(dyn);
dyn_len = 0;
}
@@ -81,15 +80,15 @@ struct tevent_req *smb2cli_tcon_send(TALLOC_CTX *mem_ctx,
dyn_len = sizeof(state->dyn_pad);
}
- if (smbXcli_session_is_authenticated(cli->smb2.session)) {
+ if (smbXcli_session_is_authenticated(state->session)) {
additional_flags |= SMB2_HDR_FLAG_SIGNED;
}
- subreq = smb2cli_req_send(state, ev, cli->conn, SMB2_OP_TCON,
+ subreq = smb2cli_req_send(state, ev, conn, SMB2_OP_TCON,
additional_flags, clear_flags,
- cli->timeout,
+ timeout_msec,
NULL, /* tcon */
- cli->smb2.session,
+ session,
state->fixed, sizeof(state->fixed),
dyn, dyn_len,
0); /* max_dyn_len */
@@ -106,7 +105,6 @@ static void smb2cli_tcon_done(struct tevent_req *subreq)
subreq, struct tevent_req);
struct smb2cli_tcon_state *state = tevent_req_data(
req, struct smb2cli_tcon_state);
- struct cli_state *cli = state->cli;
NTSTATUS status;
struct iovec *iov;
uint8_t *body;
@@ -138,13 +136,8 @@ static void smb2cli_tcon_done(struct tevent_req *subreq)
share_capabilities = IVAL(body, 0x08);
maximal_access = IVAL(body, 0x0C);
- cli->smb2.tcon = smbXcli_tcon_create(cli);
- if (tevent_req_nomem(cli->smb2.tcon, req)) {
- return;
- }
-
- smb2cli_tcon_set_values(cli->smb2.tcon,
- cli->smb2.session,
+ smb2cli_tcon_set_values(state->tcon,
+ state->session,
tcon_id,
share_type,
share_flags,
@@ -159,14 +152,19 @@ NTSTATUS smb2cli_tcon_recv(struct tevent_req *req)
return tevent_req_simple_recv_ntstatus(req);
}
-NTSTATUS smb2cli_tcon(struct cli_state *cli, const char *share)
+NTSTATUS smb2cli_tcon(struct smbXcli_conn *conn,
+ uint32_t timeout_msec,
+ struct smbXcli_session *session,
+ struct smbXcli_tcon *tcon,
+ uint16_t flags,
+ const char *unc)
{
TALLOC_CTX *frame = talloc_stackframe();
struct tevent_context *ev;
struct tevent_req *req;
NTSTATUS status = NT_STATUS_NO_MEMORY;
- if (smbXcli_conn_has_async_calls(cli->conn)) {
+ if (smbXcli_conn_has_async_calls(conn)) {
/*
* Can't use sync call while an async call is in flight
*/
@@ -177,7 +175,9 @@ NTSTATUS smb2cli_tcon(struct cli_state *cli, const char *share)
if (ev == NULL) {
goto fail;
}
- req = smb2cli_tcon_send(frame, ev, cli, share);
+ req = smb2cli_tcon_send(frame, ev, conn,
+ timeout_msec, session, tcon,
+ flags, unc);
if (req == NULL) {
goto fail;
}
@@ -191,15 +191,18 @@ NTSTATUS smb2cli_tcon(struct cli_state *cli, const char *share)
}
struct smb2cli_tdis_state {
- struct cli_state *cli;
+ struct smbXcli_tcon *tcon;
uint8_t fixed[4];
};
static void smb2cli_tdis_done(struct tevent_req *subreq);
struct tevent_req *smb2cli_tdis_send(TALLOC_CTX *mem_ctx,
- struct tevent_context *ev,
- struct cli_state *cli)
+ struct tevent_context *ev,
+ struct smbXcli_conn *conn,
+ uint32_t timeout_msec,
+ struct smbXcli_session *session,
+ struct smbXcli_tcon *tcon)
{
struct tevent_req *req, *subreq;
struct smb2cli_tdis_state *state;
@@ -209,14 +212,14 @@ struct tevent_req *smb2cli_tdis_send(TALLOC_CTX *mem_ctx,
if (req == NULL) {
return NULL;
}
- state->cli = cli;
+ state->tcon = tcon;
+
SSVAL(state->fixed, 0, 4);
- subreq = smb2cli_req_send(state, ev, cli->conn, SMB2_OP_TDIS,
+ subreq = smb2cli_req_send(state, ev, conn, SMB2_OP_TDIS,
0, 0, /* flags */
- cli->timeout,
- cli->smb2.tcon,
- cli->smb2.session,
+ timeout_msec,
+ tcon, session,
state->fixed, sizeof(state->fixed),
NULL, 0, /* dyn* */
0); /* max_dyn_len */
@@ -249,7 +252,7 @@ static void smb2cli_tdis_done(struct tevent_req *subreq)
if (tevent_req_nterror(req, status)) {
return;
}
- smb2cli_tcon_set_values(state->cli->smb2.tcon, NULL,
+ smb2cli_tcon_set_values(state->tcon, NULL,
UINT32_MAX, 0, 0, 0, 0);
tevent_req_done(req);
}
@@ -259,14 +262,17 @@ NTSTATUS smb2cli_tdis_recv(struct tevent_req *req)
return tevent_req_simple_recv_ntstatus(req);
}
-NTSTATUS smb2cli_tdis(struct cli_state *cli)
+NTSTATUS smb2cli_tdis(struct smbXcli_conn *conn,
+ uint32_t timeout_msec,
+ struct smbXcli_session *session,
+ struct smbXcli_tcon *tcon)
{
TALLOC_CTX *frame = talloc_stackframe();
struct tevent_context *ev;
struct tevent_req *req;
NTSTATUS status = NT_STATUS_NO_MEMORY;
- if (smbXcli_conn_has_async_calls(cli->conn)) {
+ if (smbXcli_conn_has_async_calls(conn)) {
/*
* Can't use sync call while an async call is in flight
*/
@@ -277,7 +283,8 @@ NTSTATUS smb2cli_tdis(struct cli_state *cli)
if (ev == NULL) {
goto fail;
}
- req = smb2cli_tdis_send(frame, ev, cli);
+ req = smb2cli_tdis_send(frame, ev, conn,
+ timeout_msec, session, tcon);
if (req == NULL) {
goto fail;
}
diff --git a/libcli/smb/smbXcli_base.h b/libcli/smb/smbXcli_base.h
index bb3647e53d0..448ff527a41 100644
--- a/libcli/smb/smbXcli_base.h
+++ b/libcli/smb/smbXcli_base.h
@@ -452,6 +452,34 @@ NTSTATUS smb2cli_logoff(struct smbXcli_conn *conn,
uint32_t timeout_msec,
struct smbXcli_session *session);
+struct tevent_req *smb2cli_tcon_send(TALLOC_CTX *mem_ctx,
+ struct tevent_context *ev,
+ struct smbXcli_conn *conn,
+ uint32_t timeout_msec,
+ struct smbXcli_session *session,
+ struct smbXcli_tcon *tcon,
+ uint16_t flags,
+ const char *unc);
+NTSTATUS smb2cli_tcon_recv(struct tevent_req *req);
+NTSTATUS smb2cli_tcon(struct smbXcli_conn *conn,
+ uint32_t timeout_msec,
+ struct smbXcli_session *session,
+ struct smbXcli_tcon *tcon,
+ uint16_t flags,
+ const char *unc);
+
+struct tevent_req *smb2cli_tdis_send(TALLOC_CTX *mem_ctx,
+ struct tevent_context *ev,
+ struct smbXcli_conn *conn,
+ uint32_t timeout_msec,
+ struct smbXcli_session *session,
+ struct smbXcli_tcon *tcon);
+NTSTATUS smb2cli_tdis_recv(struct tevent_req *req);
+NTSTATUS smb2cli_tdis(struct smbXcli_conn *conn,
+ uint32_t timeout_msec,
+ struct smbXcli_session *session,
+ struct smbXcli_tcon *tcon);
+
struct tevent_req *smb2cli_create_send(
TALLOC_CTX *mem_ctx,
struct tevent_context *ev,
diff --git a/libcli/smb/wscript b/libcli/smb/wscript
index e6556cecb72..f2d1102e9b5 100755
--- a/libcli/smb/wscript
+++ b/libcli/smb/wscript
@@ -28,6 +28,7 @@ def build(bld):
smb1cli_write.c
smb1cli_read.c
smb2cli_session.c
+ smb2cli_tcon.c
smb2cli_create.c
smb2cli_close.c
smb2cli_read.c
diff --git a/source3/libsmb/cliconnect.c b/source3/libsmb/cliconnect.c
index 6ca3bab8288..15b63e12278 100644
--- a/source3/libsmb/cliconnect.c
+++ b/source3/libsmb/cliconnect.c
@@ -2664,7 +2664,24 @@ static struct tevent_req *cli_tree_connect_send(
}
if (smbXcli_conn_protocol(cli->conn) >= PROTOCOL_SMB2_02) {
- subreq = smb2cli_tcon_send(state, ev, cli, share);
+ char *unc;
+
+ cli->smb2.tcon = smbXcli_tcon_create(cli);
+ if (tevent_req_nomem(cli->smb2.tcon, req)) {
+ return tevent_req_post(req, ev);
+ }
+
+ unc = talloc_asprintf(state, "\\\\%s\\%s",
+ smbXcli_conn_remote_name(cli->conn),
+ share);
+ if (tevent_req_nomem(unc, req)) {
+ return tevent_req_post(req, ev);
+ }
+
+ subreq = smb2cli_tcon_send(state, ev, cli->conn, cli->timeout,
+ cli->smb2.session, cli->smb2.tcon,
+ 0, /* flags */
+ unc);
if (tevent_req_nomem(subreq, req)) {
return tevent_req_post(req, ev);
}
@@ -2824,7 +2841,10 @@ NTSTATUS cli_tdis(struct cli_state *cli)
NTSTATUS status = NT_STATUS_NO_MEMORY;
if (smbXcli_conn_protocol(cli->conn) >= PROTOCOL_SMB2_02) {
- return smb2cli_tdis(cli);
+ return smb2cli_tdis(cli->conn,
+ cli->timeout,
+ cli->smb2.session,
+ cli->smb2.tcon);
}
if (smbXcli_conn_has_async_calls(cli->conn)) {
diff --git a/source3/libsmb/smb2cli.h b/source3/libsmb/smb2cli.h
index 10ea6457347..2f57972039f 100644
--- a/source3/libsmb/smb2cli.h
+++ b/source3/libsmb/smb2cli.h
@@ -24,17 +24,4 @@ struct smbXcli_conn;
struct smbXcli_session;
struct cli_state;
-struct tevent_req *smb2cli_tcon_send(TALLOC_CTX *mem_ctx,
- struct tevent_context *ev,
- struct cli_state *cli,
- const char *share);
-NTSTATUS smb2cli_tcon_recv(struct tevent_req *req);
-NTSTATUS smb2cli_tcon(struct cli_state *cli, const char *share);
-
-struct tevent_req *smb2cli_tdis_send(TALLOC_CTX *mem_ctx,
- struct tevent_context *ev,
- struct cli_state *cli);
-NTSTATUS smb2cli_tdis_recv(struct tevent_req *req);
-NTSTATUS smb2cli_tdis(struct cli_state *cli);
-
#endif /* __SMB2CLI_H__ */
diff --git a/source3/torture/test_smb2.c b/source3/torture/test_smb2.c
index 294e692d32f..247084b012c 100644
--- a/source3/torture/test_smb2.c
+++ b/source3/torture/test_smb2.c
@@ -181,7 +181,10 @@ bool run_smb2_basic(int dummy)
0, /* flags */
0, /* capabilities */
0 /* maximal_access */);
- status = smb2cli_tdis(cli);
+ status = smb2cli_tdis(cli->conn,
+ cli->timeout,
+ cli->smb2.session,
+ cli->smb2.tcon);
if (!NT_STATUS_IS_OK(status)) {
printf("smb2cli_tdis returned %s\n", nt_errstr(status));
return false;
@@ -189,7 +192,10 @@ bool run_smb2_basic(int dummy)
talloc_free(cli->smb2.tcon);
cli->smb2.tcon = saved_tcon;
- status = smb2cli_tdis(cli);
+ status = smb2cli_tdis(cli->conn,
+ cli->timeout,
+ cli->smb2.session,
+ cli->smb2.tcon);
if (!NT_STATUS_EQUAL(status, NT_STATUS_NETWORK_NAME_DELETED)) {
printf("2nd smb2cli_tdis returned %s\n", nt_errstr(status));
return false;
diff --git a/source3/wscript_build b/source3/wscript_build
index b340ea58564..9103b1480ae 100755
--- a/source3/wscript_build
+++ b/source3/wscript_build
@@ -397,7 +397,6 @@ bld.SAMBA3_LIBRARY('libsmb',
libsmb/clioplock.c
libsmb/clirap2.c
libsmb/async_smb.c
- libsmb/smb2cli_tcon.c
libsmb/reparse_symlink.c
libsmb/clisymlink.c
libsmb/smbsock_connect.c