The branch, master has been updated via 5f494c4 libcli/smb: move smb2cli_ioctl.c from source3 to the toplevel via c16e263 libcli/smb: move smb2cli_query_directory.c from source3 to the toplevel via b2d9c02 libcli/smb: move smb2cli_query_info.c from source3 to the toplevel via 22b76de libcli/smb: move smb2cli_set_info.c from source3 to the toplevel via 1d7c6bf libcli/smb: move smb2cli_flush.c from source3 to the toplevel via f50fc00 libcli/smb: move smb2cli_write.c from source3 to the toplevel via 269000b libcli/smb: move smb2cli_read.c from source3 to the toplevel via 4022edc libcli/smb: move smb2cli_close.c from source3 to the toplevel via 2674d0c libcli/smb: move smb2cli_create.c from source3 to the toplevel via 35b54ae s3:libsmb: avoid interpret_long_date() in smb2cli_create via b488567 s3:cli_np_tstream: include smbXcli_base.h, because we'll use functions from there from 8ae354e s3: Remove some unused code
http://gitweb.samba.org/?p=samba.git;a=shortlog;h=master - Log ----------------------------------------------------------------- commit 5f494c424cf204c1b5164085aecb3ea54c1b0fa9 Author: Björn Baumbach <b...@sernet.de> Date: Tue May 15 12:24:38 2012 +0200 libcli/smb: move smb2cli_ioctl.c from source3 to the toplevel Signed-off-by: Stefan Metzmacher <me...@samba.org> Autobuild-User: Stefan Metzmacher <me...@samba.org> Autobuild-Date: Tue May 15 20:17:01 CEST 2012 on sn-devel-104 commit c16e263d0e84c14e5a1dd45a2ec13a6972aa8885 Author: Björn Baumbach <b...@sernet.de> Date: Tue May 15 12:19:11 2012 +0200 libcli/smb: move smb2cli_query_directory.c from source3 to the toplevel Signed-off-by: Stefan Metzmacher <me...@samba.org> commit b2d9c02665c0a168f29c4fb51d2ba280547ad8c6 Author: Björn Baumbach <b...@sernet.de> Date: Tue May 15 12:14:47 2012 +0200 libcli/smb: move smb2cli_query_info.c from source3 to the toplevel Signed-off-by: Stefan Metzmacher <me...@samba.org> commit 22b76de2ffd25e580bd8db61748fa9a6cf62d153 Author: Björn Baumbach <b...@sernet.de> Date: Tue May 15 12:05:50 2012 +0200 libcli/smb: move smb2cli_set_info.c from source3 to the toplevel Signed-off-by: Stefan Metzmacher <me...@samba.org> commit 1d7c6bfd7ae02a0b026bb999b462dae4027c7d10 Author: Björn Baumbach <b...@sernet.de> Date: Tue May 15 12:00:19 2012 +0200 libcli/smb: move smb2cli_flush.c from source3 to the toplevel Signed-off-by: Stefan Metzmacher <me...@samba.org> commit f50fc00306768424dee0680f7f9cae7ff0b3dcd8 Author: Björn Baumbach <b...@sernet.de> Date: Tue May 15 11:11:24 2012 +0200 libcli/smb: move smb2cli_write.c from source3 to the toplevel Signed-off-by: Stefan Metzmacher <me...@samba.org> commit 269000b1b344fb04efe0f12ca455b584074139d3 Author: Björn Baumbach <b...@sernet.de> Date: Tue May 15 10:50:49 2012 +0200 libcli/smb: move smb2cli_read.c from source3 to the toplevel Signed-off-by: Stefan Metzmacher <me...@samba.org> commit 4022edc9064e7cde147f0c7cbd93b76db30fac4a Author: Stefan Metzmacher <me...@samba.org> Date: Tue May 15 10:26:25 2012 +0200 libcli/smb: move smb2cli_close.c from source3 to the toplevel metze commit 2674d0c458410a96d6e33e190a6924e857bbe8be Author: Stefan Metzmacher <me...@samba.org> Date: Tue May 15 10:23:54 2012 +0200 libcli/smb: move smb2cli_create.c from source3 to the toplevel metze commit 35b54ae5a9bf67373dc824fd2843411fee0aec72 Author: Stefan Metzmacher <me...@samba.org> Date: Tue May 15 11:27:23 2012 +0200 s3:libsmb: avoid interpret_long_date() in smb2cli_create metze commit b488567a18653e4f95ed68964ee5846aac8c3ca6 Author: Stefan Metzmacher <me...@samba.org> Date: Tue May 15 12:41:55 2012 +0200 s3:cli_np_tstream: include smbXcli_base.h, because we'll use functions from there metze ----------------------------------------------------------------------- Summary of changes: libcli/smb/smb2cli_close.c | 135 ++++++++++++ libcli/smb/smb2cli_create.c | 279 ++++++++++++++++++++++++ libcli/smb/smb2cli_flush.c | 131 ++++++++++++ libcli/smb/smb2cli_ioctl.c | 335 +++++++++++++++++++++++++++++ libcli/smb/smb2cli_query_directory.c | 208 ++++++++++++++++++ libcli/smb/smb2cli_query_info.c | 251 ++++++++++++++++++++++ libcli/smb/smb2cli_read.c | 187 +++++++++++++++++ libcli/smb/smb2cli_set_info.c | 182 ++++++++++++++++ libcli/smb/smb2cli_write.c | 161 ++++++++++++++ libcli/smb/smbXcli_base.h | 245 ++++++++++++++++++++++ libcli/smb/wscript_build | 9 + source3/Makefile.in | 18 +- source3/libsmb/cli_np_tstream.c | 1 + source3/libsmb/smb2cli.h | 245 ---------------------- source3/libsmb/smb2cli_close.c | 137 ------------ source3/libsmb/smb2cli_create.c | 281 ------------------------- source3/libsmb/smb2cli_flush.c | 133 ------------ source3/libsmb/smb2cli_ioctl.c | 337 ------------------------------ source3/libsmb/smb2cli_query_directory.c | 210 ------------------- source3/libsmb/smb2cli_query_info.c | 254 ---------------------- source3/libsmb/smb2cli_read.c | 189 ----------------- source3/libsmb/smb2cli_set_info.c | 185 ---------------- source3/libsmb/smb2cli_write.c | 163 -------------- source3/wscript_build | 9 - 24 files changed, 2133 insertions(+), 2152 deletions(-) create mode 100644 libcli/smb/smb2cli_close.c create mode 100644 libcli/smb/smb2cli_create.c create mode 100644 libcli/smb/smb2cli_flush.c create mode 100644 libcli/smb/smb2cli_ioctl.c create mode 100644 libcli/smb/smb2cli_query_directory.c create mode 100644 libcli/smb/smb2cli_query_info.c create mode 100644 libcli/smb/smb2cli_read.c create mode 100644 libcli/smb/smb2cli_set_info.c create mode 100644 libcli/smb/smb2cli_write.c delete mode 100644 source3/libsmb/smb2cli_close.c delete mode 100644 source3/libsmb/smb2cli_create.c delete mode 100644 source3/libsmb/smb2cli_flush.c delete mode 100644 source3/libsmb/smb2cli_ioctl.c delete mode 100644 source3/libsmb/smb2cli_query_directory.c delete mode 100644 source3/libsmb/smb2cli_query_info.c delete mode 100644 source3/libsmb/smb2cli_read.c delete mode 100644 source3/libsmb/smb2cli_set_info.c delete mode 100644 source3/libsmb/smb2cli_write.c Changeset truncated at 500 lines: diff --git a/libcli/smb/smb2cli_close.c b/libcli/smb/smb2cli_close.c new file mode 100644 index 0000000..d4cba41 --- /dev/null +++ b/libcli/smb/smb2cli_close.c @@ -0,0 +1,135 @@ +/* + Unix SMB/CIFS implementation. + smb2 lib + Copyright (C) Volker Lendecke 2011 + + 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 smb2cli_close_state { + uint8_t fixed[24]; +}; + +static void smb2cli_close_done(struct tevent_req *subreq); + +struct tevent_req *smb2cli_close_send(TALLOC_CTX *mem_ctx, + struct tevent_context *ev, + struct smbXcli_conn *conn, + uint32_t timeout_msec, + struct smbXcli_session *session, + uint32_t tcon_id, + uint16_t flags, + uint64_t fid_persistent, + uint64_t fid_volatile) +{ + struct tevent_req *req, *subreq; + struct smb2cli_close_state *state; + uint8_t *fixed; + + req = tevent_req_create(mem_ctx, &state, + struct smb2cli_close_state); + if (req == NULL) { + return NULL; + } + fixed = state->fixed; + SSVAL(fixed, 0, 24); + SSVAL(fixed, 2, flags); + SBVAL(fixed, 8, fid_persistent); + SBVAL(fixed, 16, fid_volatile); + + subreq = smb2cli_req_send(state, ev, conn, SMB2_OP_CLOSE, + 0, 0, /* flags */ + timeout_msec, + 0xFEFF, /* pid */ + tcon_id, + 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_close_done, req); + return req; +} + +static void smb2cli_close_done(struct tevent_req *subreq) +{ + struct tevent_req *req = + tevent_req_callback_data(subreq, + struct tevent_req); + NTSTATUS status; + static const struct smb2cli_req_expected_response expected[] = { + { + .status = NT_STATUS_OK, + .body_size = 0x3C + } + }; + + status = smb2cli_req_recv(subreq, NULL, NULL, + expected, ARRAY_SIZE(expected)); + if (tevent_req_nterror(req, status)) { + return; + } + tevent_req_done(req); +} + +NTSTATUS smb2cli_close_recv(struct tevent_req *req) +{ + return tevent_req_simple_recv_ntstatus(req); +} + +NTSTATUS smb2cli_close(struct smbXcli_conn *conn, + uint32_t timeout_msec, + struct smbXcli_session *session, + uint32_t tcon_id, + uint16_t flags, + uint64_t fid_persistent, + uint64_t fid_volatile) +{ + 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 = smb2cli_close_send(frame, ev, conn, timeout_msec, + session, tcon_id, flags, + fid_persistent, fid_volatile); + if (req == NULL) { + goto fail; + } + if (!tevent_req_poll_ntstatus(req, ev, &status)) { + goto fail; + } + status = smb2cli_close_recv(req); + fail: + TALLOC_FREE(frame); + return status; +} diff --git a/libcli/smb/smb2cli_create.c b/libcli/smb/smb2cli_create.c new file mode 100644 index 0000000..29b0396 --- /dev/null +++ b/libcli/smb/smb2cli_create.c @@ -0,0 +1,279 @@ +/* + Unix SMB/CIFS implementation. + smb2 lib + Copyright (C) Volker Lendecke 2011 + + 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" +#include "smb2_create_blob.h" + +struct smb2cli_create_state { + uint8_t fixed[56]; + + uint8_t oplock_level; + uint32_t create_action; + NTTIME creation_time; + NTTIME last_access_time; + NTTIME last_write_time; + NTTIME change_time; + uint64_t allocation_size; + uint64_t end_of_file; + uint32_t file_attributes; + uint64_t fid_persistent; + uint64_t fid_volatile; + struct smb2_create_blobs blobs; +}; + +static void smb2cli_create_done(struct tevent_req *subreq); + +struct tevent_req *smb2cli_create_send( + TALLOC_CTX *mem_ctx, + struct tevent_context *ev, + struct smbXcli_conn *conn, + uint32_t timeout_msec, + struct smbXcli_session *session, + uint32_t tcon_id, + const char *filename, + uint8_t oplock_level, /* SMB2_OPLOCK_LEVEL_* */ + uint32_t impersonation_level, /* SMB2_IMPERSONATION_* */ + uint32_t desired_access, + uint32_t file_attributes, + uint32_t share_access, + uint32_t create_disposition, + uint32_t create_options, + struct smb2_create_blobs *blobs) +{ + struct tevent_req *req, *subreq; + struct smb2cli_create_state *state; + uint8_t *fixed; + uint8_t *name_utf16; + size_t name_utf16_len; + DATA_BLOB blob; + NTSTATUS status; + size_t blobs_offset; + uint8_t *dyn; + size_t dyn_len; + + req = tevent_req_create(mem_ctx, &state, + struct smb2cli_create_state); + if (req == NULL) { + return NULL; + } + + if (!convert_string_talloc(state, CH_UNIX, CH_UTF16, + filename, strlen(filename), + &name_utf16, &name_utf16_len)) { + tevent_req_oom(req); + return tevent_req_post(req, ev); + } + + if (strlen(filename) == 0) { + TALLOC_FREE(name_utf16); + name_utf16_len = 0; + } + + fixed = state->fixed; + + SSVAL(fixed, 0, 57); + SCVAL(fixed, 3, oplock_level); + SIVAL(fixed, 4, impersonation_level); + SIVAL(fixed, 24, desired_access); + SIVAL(fixed, 28, file_attributes); + SIVAL(fixed, 32, share_access); + SIVAL(fixed, 36, create_disposition); + SIVAL(fixed, 40, create_options); + + SSVAL(fixed, 44, SMB2_HDR_BODY + 56); + SSVAL(fixed, 46, name_utf16_len); + + blob = data_blob_null; + + if (blobs != NULL) { + status = smb2_create_blob_push(state, &blob, *blobs); + if (tevent_req_nterror(req, status)) { + return tevent_req_post(req, ev); + } + } + + blobs_offset = name_utf16_len; + blobs_offset = ((blobs_offset + 3) & ~3); + + if (blob.length > 0) { + SIVAL(fixed, 48, blobs_offset + SMB2_HDR_BODY + 56); + SIVAL(fixed, 52, blob.length); + } + + dyn_len = MAX(1, blobs_offset + blob.length); + dyn = talloc_zero_array(state, uint8_t, dyn_len); + if (tevent_req_nomem(dyn, req)) { + return tevent_req_post(req, ev); + } + + if (name_utf16) { + memcpy(dyn, name_utf16, name_utf16_len); + TALLOC_FREE(name_utf16); + } + + if (blob.data != NULL) { + memcpy(dyn + blobs_offset, + blob.data, blob.length); + data_blob_free(&blob); + } + + subreq = smb2cli_req_send(state, ev, conn, SMB2_OP_CREATE, + 0, 0, /* flags */ + timeout_msec, + 0xFEFF, /* pid */ + tcon_id, + session, + state->fixed, sizeof(state->fixed), + dyn, dyn_len); + if (tevent_req_nomem(subreq, req)) { + return tevent_req_post(req, ev); + } + tevent_req_set_callback(subreq, smb2cli_create_done, req); + return req; +} + +static void smb2cli_create_done(struct tevent_req *subreq) +{ + struct tevent_req *req = + tevent_req_callback_data(subreq, + struct tevent_req); + struct smb2cli_create_state *state = + tevent_req_data(req, + struct smb2cli_create_state); + NTSTATUS status; + struct iovec *iov; + uint8_t *body; + uint32_t offset, length; + static const struct smb2cli_req_expected_response expected[] = { + { + .status = NT_STATUS_OK, + .body_size = 0x59 + } + }; + + status = smb2cli_req_recv(subreq, state, &iov, + expected, ARRAY_SIZE(expected)); + if (tevent_req_nterror(req, status)) { + return; + } + + body = (uint8_t *)iov[1].iov_base; + + state->oplock_level = CVAL(body, 2); + state->create_action = IVAL(body, 4); + state->creation_time = BVAL(body, 8); + state->last_access_time = BVAL(body, 16); + state->last_write_time = BVAL(body, 24); + state->change_time = BVAL(body, 32); + state->allocation_size = BVAL(body, 40); + state->end_of_file = BVAL(body, 48); + state->file_attributes = IVAL(body, 56); + state->fid_persistent = BVAL(body, 64); + state->fid_volatile = BVAL(body, 72); + + offset = IVAL(body, 80); + length = IVAL(body, 84); + + if ((offset != 0) && (length != 0)) { + if ((offset != SMB2_HDR_BODY + 88) || + (length > iov[2].iov_len)) { + tevent_req_nterror( + req, NT_STATUS_INVALID_NETWORK_RESPONSE); + return; + } + status = smb2_create_blob_parse( + state, data_blob_const(iov[2].iov_base, length), + &state->blobs); + if (tevent_req_nterror(req, status)) { + return; + } + } + tevent_req_done(req); +} + +NTSTATUS smb2cli_create_recv(struct tevent_req *req, + uint64_t *fid_persistent, + uint64_t *fid_volatile) +{ + struct smb2cli_create_state *state = + tevent_req_data(req, + struct smb2cli_create_state); + NTSTATUS status; + + if (tevent_req_is_nterror(req, &status)) { + return status; + } + *fid_persistent = state->fid_persistent; + *fid_volatile = state->fid_volatile; + return NT_STATUS_OK; +} + +NTSTATUS smb2cli_create(struct smbXcli_conn *conn, + uint32_t timeout_msec, + struct smbXcli_session *session, + uint32_t tcon_id, + const char *filename, + uint8_t oplock_level, /* SMB2_OPLOCK_LEVEL_* */ + uint32_t impersonation_level, /* SMB2_IMPERSONATION_* */ + uint32_t desired_access, + uint32_t file_attributes, + uint32_t share_access, + uint32_t create_disposition, + uint32_t create_options, + struct smb2_create_blobs *blobs, + uint64_t *fid_persistent, + uint64_t *fid_volatile) +{ + 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 = smb2cli_create_send(frame, ev, conn, timeout_msec, session, + tcon_id, filename, oplock_level, + impersonation_level, desired_access, + file_attributes, share_access, + create_disposition, create_options, + blobs); + if (req == NULL) { + goto fail; + } + if (!tevent_req_poll_ntstatus(req, ev, &status)) { + goto fail; + } + status = smb2cli_create_recv(req, fid_persistent, fid_volatile); + fail: + TALLOC_FREE(frame); + return status; +} diff --git a/libcli/smb/smb2cli_flush.c b/libcli/smb/smb2cli_flush.c new file mode 100644 index 0000000..64d47c2 --- /dev/null +++ b/libcli/smb/smb2cli_flush.c @@ -0,0 +1,131 @@ +/* + Unix SMB/CIFS implementation. + smb2 lib + Copyright (C) Volker Lendecke 2011 + + 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 smb2cli_flush_state { + uint8_t fixed[24]; +}; + +static void smb2cli_flush_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, + uint32_t tcon_id, + uint64_t fid_persistent, + uint64_t fid_volatile) +{ + struct tevent_req *req, *subreq; + struct smb2cli_flush_state *state; + uint8_t *fixed; + + req = tevent_req_create(mem_ctx, &state, + struct smb2cli_flush_state); + if (req == NULL) { + return NULL; + } + fixed = state->fixed; + SSVAL(fixed, 0, 24); + SBVAL(fixed, 8, fid_persistent); + SBVAL(fixed, 16, fid_volatile); + + subreq = smb2cli_req_send(state, ev, conn, SMB2_OP_FLUSH, + 0, 0, /* flags */ + timeout_msec, + 0xFEFF, /* pid */ + tcon_id, + 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); + return req; +} -- Samba Shared Repository