The branch, master has been updated via 6fbb1b5 s3:libsmb: use smbXcli_conn_remote_name() in smb2_tcon_send() via 4e1306c s3:libsmb: make cli_echo* protocol independent via b186fdd libcli/smb: add smb1cli_echo* via a7fa026 libcli/smb: add smb2cli_echo* via faa039e libcli/smb: use an explicit TALLOC_FREE(subreq) in smb2cli_* from f0f310c build: Remove duplicate check for struct getquota_rslt member getquota_rslt_u
http://gitweb.samba.org/?p=samba.git;a=shortlog;h=master - Log ----------------------------------------------------------------- commit 6fbb1b5fd55897def70b9603423f23ed8335428e Author: Stefan Metzmacher <me...@samba.org> Date: Fri Sep 28 19:11:14 2012 +0200 s3:libsmb: use smbXcli_conn_remote_name() in smb2_tcon_send() metze Autobuild-User(master): Stefan Metzmacher <me...@samba.org> Autobuild-Date(master): Sat Sep 29 11:52:43 CEST 2012 on sn-devel-104 commit 4e1306c46a0ab00c2e1a5d78a2f3a9bd9bb45cbe Author: Stefan Metzmacher <me...@samba.org> Date: Fri Sep 28 20:00:21 2012 +0200 s3:libsmb: make cli_echo* protocol independent metze commit b186fdd185d2d5c7d9abd7f652aed58fec6de2ff Author: Stefan Metzmacher <me...@samba.org> Date: Fri Sep 28 19:53:16 2012 +0200 libcli/smb: add smb1cli_echo* metze commit a7fa02664ad8c8bbdad14e4c7f732d0da1867449 Author: Stefan Metzmacher <me...@samba.org> Date: Fri Sep 28 19:18:37 2012 +0200 libcli/smb: add smb2cli_echo* metze commit faa039ef463e681a28cacd7dda44961219f7b8c6 Author: Stefan Metzmacher <me...@samba.org> Date: Fri Sep 28 19:48:26 2012 +0200 libcli/smb: use an explicit TALLOC_FREE(subreq) in smb2cli_* metze ----------------------------------------------------------------------- Summary of changes: libcli/smb/smb1cli_echo.c | 170 ++++++++++++++++++++++++ libcli/smb/smb2cli_close.c | 1 + libcli/smb/smb2cli_create.c | 1 + libcli/smb/{smb2cli_flush.c => smb2cli_echo.c} | 56 +++----- libcli/smb/smb2cli_flush.c | 1 + libcli/smb/smb2cli_ioctl.c | 1 + libcli/smb/smb2cli_query_directory.c | 1 + libcli/smb/smb2cli_query_info.c | 1 + libcli/smb/smb2cli_read.c | 1 + libcli/smb/smb2cli_set_info.c | 1 + libcli/smb/smb2cli_write.c | 1 + libcli/smb/smbXcli_base.h | 18 +++ libcli/smb/wscript | 2 + source3/Makefile.in | 2 + source3/libsmb/clientgen.c | 55 +++----- source3/libsmb/smb2cli_tcon.c | 6 +- 16 files changed, 249 insertions(+), 69 deletions(-) create mode 100644 libcli/smb/smb1cli_echo.c copy libcli/smb/{smb2cli_flush.c => smb2cli_echo.c} (63%) Changeset truncated at 500 lines: diff --git a/libcli/smb/smb1cli_echo.c b/libcli/smb/smb1cli_echo.c new file mode 100644 index 0000000..cab8ae6 --- /dev/null +++ b/libcli/smb/smb1cli_echo.c @@ -0,0 +1,170 @@ +/* + Unix SMB/CIFS implementation. + smb2 lib + Copyright (C) Stefan Metzmacher 2012 + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see <http://www.gnu.org/licenses/>. +*/ + +#include "includes.h" +#include "system/network.h" +#include "lib/util/tevent_ntstatus.h" +#include "smb_common.h" +#include "smbXcli_base.h" + +struct smb1cli_echo_state { + uint16_t vwv[1]; + DATA_BLOB data; + uint16_t num_echos; +}; + +static void smb1cli_echo_done(struct tevent_req *subreq); + +struct tevent_req *smb1cli_echo_send(TALLOC_CTX *mem_ctx, + struct tevent_context *ev, + struct smbXcli_conn *conn, + uint32_t timeout_msec, + uint16_t num_echos, + DATA_BLOB data) +{ + struct tevent_req *req, *subreq; + struct smb1cli_echo_state *state; + + req = tevent_req_create(mem_ctx, &state, struct smb1cli_echo_state); + if (req == NULL) { + return NULL; + } + SSVAL(state->vwv, 0, num_echos); + state->data = data; + state->num_echos = num_echos; + + subreq = smb1cli_req_send(state, ev, conn, SMBecho, + 0, 0, /* *_flags */ + 0, 0, /* *_flags2 */ + timeout_msec, + 0, /* pid */ + NULL, /* tcon */ + NULL, /* session */ + ARRAY_SIZE(state->vwv), state->vwv, + data.length, data.data); + if (subreq == NULL) { + goto fail; + } + tevent_req_set_callback(subreq, smb1cli_echo_done, req); + return req; + fail: + TALLOC_FREE(req); + return NULL; +} + +static void smb1cli_echo_done(struct tevent_req *subreq) +{ + struct tevent_req *req = tevent_req_callback_data( + subreq, struct tevent_req); + struct smb1cli_echo_state *state = tevent_req_data( + req, struct smb1cli_echo_state); + NTSTATUS status; + uint32_t num_bytes; + uint8_t *bytes; + struct iovec *recv_iov; + struct smb1cli_req_expected_response expected[] = { + { + .status = NT_STATUS_OK, + .wct = 1, + }, + }; + + status = smb1cli_req_recv(subreq, state, + &recv_iov, + NULL, /* phdr */ + NULL, /* pwct */ + NULL, /* pvwv */ + NULL, /* pvwv_offset */ + &num_bytes, + &bytes, + NULL, /* pbytes_offset */ + NULL, /* pinbuf */ + expected, ARRAY_SIZE(expected)); + TALLOC_FREE(subreq); + if (!NT_STATUS_IS_OK(status)) { + tevent_req_nterror(req, status); + return; + } + + if (num_bytes != state->data.length) { + tevent_req_nterror(req, NT_STATUS_INVALID_NETWORK_RESPONSE); + return; + } + + if (memcmp(bytes, state->data.data, num_bytes) != 0) { + tevent_req_nterror(req, NT_STATUS_INVALID_NETWORK_RESPONSE); + return; + } + + /* TODO: do we want to verify the sequence number? */ + + state->num_echos -=1; + if (state->num_echos == 0) { + tevent_req_done(req); + return; + } + + if (!smbXcli_req_set_pending(subreq)) { + tevent_req_nterror(req, NT_STATUS_NO_MEMORY); + return; + } +} + +/** + * Get the result out from an echo request + * @param[in] req The async_req from smb1cli_echo_send + * @retval Did the server reply correctly? + */ + +NTSTATUS smb1cli_echo_recv(struct tevent_req *req) +{ + return tevent_req_simple_recv_ntstatus(req); +} + +NTSTATUS smb1cli_echo(struct smbXcli_conn *conn, uint32_t timeout_msec, + uint16_t num_echos, DATA_BLOB data) +{ + 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(conn)) { + /* + * Can't use sync call while an async call is in flight + */ + status = NT_STATUS_INVALID_PARAMETER; + goto fail; + } + ev = tevent_context_init(frame); + if (ev == NULL) { + goto fail; + } + req = smb1cli_echo_send(frame, ev, conn, timeout_msec, num_echos, data); + if (req == NULL) { + goto fail; + } + if (!tevent_req_poll_ntstatus(req, ev, &status)) { + goto fail; + } + status = smb1cli_echo_recv(req); + fail: + TALLOC_FREE(frame); + return status; +} diff --git a/libcli/smb/smb2cli_close.c b/libcli/smb/smb2cli_close.c index fbeee55..c10a21f 100644 --- a/libcli/smb/smb2cli_close.c +++ b/libcli/smb/smb2cli_close.c @@ -83,6 +83,7 @@ static void smb2cli_close_done(struct tevent_req *subreq) status = smb2cli_req_recv(subreq, NULL, NULL, expected, ARRAY_SIZE(expected)); + TALLOC_FREE(subreq); if (tevent_req_nterror(req, status)) { return; } diff --git a/libcli/smb/smb2cli_create.c b/libcli/smb/smb2cli_create.c index 4d264ef..62efc48 100644 --- a/libcli/smb/smb2cli_create.c +++ b/libcli/smb/smb2cli_create.c @@ -172,6 +172,7 @@ static void smb2cli_create_done(struct tevent_req *subreq) status = smb2cli_req_recv(subreq, state, &iov, expected, ARRAY_SIZE(expected)); + TALLOC_FREE(subreq); if (tevent_req_nterror(req, status)) { return; } diff --git a/libcli/smb/smb2cli_flush.c b/libcli/smb/smb2cli_echo.c similarity index 63% copy from libcli/smb/smb2cli_flush.c copy to libcli/smb/smb2cli_echo.c index a280e15..b978d50 100644 --- a/libcli/smb/smb2cli_flush.c +++ b/libcli/smb/smb2cli_echo.c @@ -1,7 +1,7 @@ /* Unix SMB/CIFS implementation. smb2 lib - Copyright (C) Volker Lendecke 2011 + Copyright (C) Stefan Metzmacher 2012 This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -23,50 +23,45 @@ #include "smb_common.h" #include "smbXcli_base.h" -struct smb2cli_flush_state { - uint8_t fixed[24]; +struct smb2cli_echo_state { + uint8_t fixed[0x4]; }; -static void smb2cli_flush_done(struct tevent_req *subreq); +static void smb2cli_echo_done(struct tevent_req *subreq); -struct tevent_req *smb2cli_flush_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, - uint64_t fid_persistent, - uint64_t fid_volatile) +struct tevent_req *smb2cli_echo_send(TALLOC_CTX *mem_ctx, + struct tevent_context *ev, + struct smbXcli_conn *conn, + uint32_t timeout_msec) { struct tevent_req *req, *subreq; - struct smb2cli_flush_state *state; + struct smb2cli_echo_state *state; uint8_t *fixed; req = tevent_req_create(mem_ctx, &state, - struct smb2cli_flush_state); + struct smb2cli_echo_state); if (req == NULL) { return NULL; } fixed = state->fixed; - SSVAL(fixed, 0, 24); - SBVAL(fixed, 8, fid_persistent); - SBVAL(fixed, 16, fid_volatile); + SSVAL(fixed, 0, 4); + SSVAL(fixed, 2, 0); - subreq = smb2cli_req_send(state, ev, conn, SMB2_OP_FLUSH, + subreq = smb2cli_req_send(state, ev, conn, SMB2_OP_KEEPALIVE, 0, 0, /* flags */ timeout_msec, - tcon, - session, + NULL, /* tcon */ + NULL, /* session */ state->fixed, sizeof(state->fixed), NULL, 0); if (tevent_req_nomem(subreq, req)) { return tevent_req_post(req, ev); } - tevent_req_set_callback(subreq, smb2cli_flush_done, req); + tevent_req_set_callback(subreq, smb2cli_echo_done, req); return req; } -static void smb2cli_flush_done(struct tevent_req *subreq) +static void smb2cli_echo_done(struct tevent_req *subreq) { struct tevent_req *req = tevent_req_callback_data(subreq, @@ -81,23 +76,20 @@ static void smb2cli_flush_done(struct tevent_req *subreq) status = smb2cli_req_recv(subreq, NULL, NULL, expected, ARRAY_SIZE(expected)); + TALLOC_FREE(subreq); if (tevent_req_nterror(req, status)) { return; } tevent_req_done(req); } -NTSTATUS smb2cli_flush_recv(struct tevent_req *req) +NTSTATUS smb2cli_echo_recv(struct tevent_req *req) { return tevent_req_simple_recv_ntstatus(req); } -NTSTATUS smb2cli_flush(struct smbXcli_conn *conn, - uint32_t timeout_msec, - struct smbXcli_session *session, - struct smbXcli_tcon *tcon, - uint64_t fid_persistent, - uint64_t fid_volatile) +NTSTATUS smb2cli_echo(struct smbXcli_conn *conn, + uint32_t timeout_msec) { TALLOC_CTX *frame = talloc_stackframe(); struct tevent_context *ev; @@ -115,16 +107,14 @@ NTSTATUS smb2cli_flush(struct smbXcli_conn *conn, if (ev == NULL) { goto fail; } - req = smb2cli_flush_send(frame, ev, conn, timeout_msec, - session, tcon, - fid_persistent, fid_volatile); + req = smb2cli_echo_send(frame, ev, conn, timeout_msec); if (req == NULL) { goto fail; } if (!tevent_req_poll_ntstatus(req, ev, &status)) { goto fail; } - status = smb2cli_flush_recv(req); + status = smb2cli_echo_recv(req); fail: TALLOC_FREE(frame); return status; diff --git a/libcli/smb/smb2cli_flush.c b/libcli/smb/smb2cli_flush.c index a280e15..4b14347 100644 --- a/libcli/smb/smb2cli_flush.c +++ b/libcli/smb/smb2cli_flush.c @@ -81,6 +81,7 @@ static void smb2cli_flush_done(struct tevent_req *subreq) status = smb2cli_req_recv(subreq, NULL, NULL, expected, ARRAY_SIZE(expected)); + TALLOC_FREE(subreq); if (tevent_req_nterror(req, status)) { return; } diff --git a/libcli/smb/smb2cli_ioctl.c b/libcli/smb/smb2cli_ioctl.c index 687c9d5..dd1788f 100644 --- a/libcli/smb/smb2cli_ioctl.c +++ b/libcli/smb/smb2cli_ioctl.c @@ -178,6 +178,7 @@ static void smb2cli_ioctl_done(struct tevent_req *subreq) status = smb2cli_req_recv(subreq, state, &iov, expected, ARRAY_SIZE(expected)); + TALLOC_FREE(subreq); if (tevent_req_nterror(req, status)) { return; } diff --git a/libcli/smb/smb2cli_query_directory.c b/libcli/smb/smb2cli_query_directory.c index 3278378..49d5365 100644 --- a/libcli/smb/smb2cli_query_directory.c +++ b/libcli/smb/smb2cli_query_directory.c @@ -121,6 +121,7 @@ static void smb2cli_query_directory_done(struct tevent_req *subreq) status = smb2cli_req_recv(subreq, state, &iov, expected, ARRAY_SIZE(expected)); + TALLOC_FREE(subreq); if (tevent_req_nterror(req, status)) { return; } diff --git a/libcli/smb/smb2cli_query_info.c b/libcli/smb/smb2cli_query_info.c index 80cec9c..96847fc 100644 --- a/libcli/smb/smb2cli_query_info.c +++ b/libcli/smb/smb2cli_query_info.c @@ -133,6 +133,7 @@ static void smb2cli_query_info_done(struct tevent_req *subreq) status = smb2cli_req_recv(subreq, state, &iov, expected, ARRAY_SIZE(expected)); + TALLOC_FREE(subreq); if (tevent_req_nterror(req, status)) { return; } diff --git a/libcli/smb/smb2cli_read.c b/libcli/smb/smb2cli_read.c index e808b0c..11bcae7 100644 --- a/libcli/smb/smb2cli_read.c +++ b/libcli/smb/smb2cli_read.c @@ -103,6 +103,7 @@ static void smb2cli_read_done(struct tevent_req *subreq) status = smb2cli_req_recv(subreq, state, &iov, expected, ARRAY_SIZE(expected)); + TALLOC_FREE(subreq); if (tevent_req_nterror(req, status)) { return; } diff --git a/libcli/smb/smb2cli_set_info.c b/libcli/smb/smb2cli_set_info.c index 41fe83e..0ac4703 100644 --- a/libcli/smb/smb2cli_set_info.c +++ b/libcli/smb/smb2cli_set_info.c @@ -111,6 +111,7 @@ static void smb2cli_set_info_done(struct tevent_req *subreq) status = smb2cli_req_recv(subreq, NULL, NULL, expected, ARRAY_SIZE(expected)); + TALLOC_FREE(subreq); if (tevent_req_nterror(req, status)) { return; } diff --git a/libcli/smb/smb2cli_write.c b/libcli/smb/smb2cli_write.c index a149924..e7d7f75 100644 --- a/libcli/smb/smb2cli_write.c +++ b/libcli/smb/smb2cli_write.c @@ -104,6 +104,7 @@ static void smb2cli_write_done(struct tevent_req *subreq) status = smb2cli_req_recv(subreq, NULL, NULL, expected, ARRAY_SIZE(expected)); + TALLOC_FREE(subreq); if (tevent_req_nterror(req, status)) { return; } diff --git a/libcli/smb/smbXcli_base.h b/libcli/smb/smbXcli_base.h index 5ef201e..03cb280 100644 --- a/libcli/smb/smbXcli_base.h +++ b/libcli/smb/smbXcli_base.h @@ -187,6 +187,16 @@ NTSTATUS smb1cli_trans(TALLOC_CTX *mem_ctx, struct smbXcli_conn *conn, uint8_t **rparam, uint32_t min_rparam, uint32_t *num_rparam, uint8_t **rdata, uint32_t min_rdata, uint32_t *num_rdata); +struct tevent_req *smb1cli_echo_send(TALLOC_CTX *mem_ctx, + struct tevent_context *ev, + struct smbXcli_conn *conn, + uint32_t timeout_msec, + uint16_t num_echos, + DATA_BLOB data); +NTSTATUS smb1cli_echo_recv(struct tevent_req *req); +NTSTATUS smb1cli_echo(struct smbXcli_conn *conn, uint32_t timeout_msec, + uint16_t num_echos, DATA_BLOB data); + uint32_t smb2cli_conn_server_capabilities(struct smbXcli_conn *conn); uint16_t smb2cli_conn_server_security_mode(struct smbXcli_conn *conn); uint32_t smb2cli_conn_max_trans_size(struct smbXcli_conn *conn); @@ -567,4 +577,12 @@ NTSTATUS smb2cli_ioctl(struct smbXcli_conn *conn, DATA_BLOB *out_input_buffer, DATA_BLOB *out_output_buffer); +struct tevent_req *smb2cli_echo_send(TALLOC_CTX *mem_ctx, + struct tevent_context *ev, + struct smbXcli_conn *conn, + uint32_t timeout_msec); +NTSTATUS smb2cli_echo_recv(struct tevent_req *req); +NTSTATUS smb2cli_echo(struct smbXcli_conn *conn, + uint32_t timeout_msec); + #endif /* _SMBXCLI_BASE_H_ */ diff --git a/libcli/smb/wscript b/libcli/smb/wscript index ae65d68..3616ad1 100755 --- a/libcli/smb/wscript +++ b/libcli/smb/wscript @@ -21,6 +21,7 @@ def build(bld): util.c smbXcli_base.c smb1cli_trans.c + smb1cli_echo.c smb2cli_session.c smb2cli_create.c smb2cli_close.c @@ -31,6 +32,7 @@ def build(bld): smb2cli_query_info.c smb2cli_query_directory.c smb2cli_ioctl.c + smb2cli_echo.c ''', deps='LIBCRYPTO errors gensec krb5samba smb_transport', public_deps='talloc samba-util', diff --git a/source3/Makefile.in b/source3/Makefile.in index 0e72fea..a29aae2 100644 --- a/source3/Makefile.in +++ b/source3/Makefile.in @@ -629,6 +629,7 @@ LIBSMB_OBJ = libsmb/clientgen.o libsmb/cliconnect.o libsmb/clifile.o \ ../libcli/smb/read_smb.o \ ../libcli/smb/smbXcli_base.o \ ../libcli/smb/smb1cli_trans.o \ + ../libcli/smb/smb1cli_echo.o \ ../libcli/smb/smb2cli_session.o \ libsmb/smb2cli_tcon.o \ ../libcli/smb/smb2cli_create.o \ @@ -642,6 +643,7 @@ LIBSMB_OBJ = libsmb/clientgen.o libsmb/cliconnect.o libsmb/clifile.o \ ../libcli/smb/smb2cli_ioctl.o \ ../libcli/smb/smb2cli_query_info.o \ ../libcli/smb/smb2cli_set_info.o \ + ../libcli/smb/smb2cli_echo.o \ libsmb/cli_np_tstream.o \ libsmb/smbsock_connect.o \ $(LIBSAMBA_OBJ) \ diff --git a/source3/libsmb/clientgen.c b/source3/libsmb/clientgen.c index 31af1e7..6bc8d0c 100644 --- a/source3/libsmb/clientgen.c +++ b/source3/libsmb/clientgen.c @@ -454,9 +454,7 @@ time_t cli_state_server_time(struct cli_state *cli) } struct cli_echo_state { - uint16_t vwv[1]; - DATA_BLOB data; - int num_echos; + bool is_smb2; -- Samba Shared Repository