[SCM] Samba Shared Repository - branch master updated
Jeremy Allison
jra at samba.org
Tue Jul 25 23:34:02 UTC 2017
The branch, master has been updated
via 5005a3a libsmb: Enable "cli_notify" for SMB2+
via 1801134 libsmb: Add cli_smb2_notify
via ad33964 libsmb: Add smb2cli_notify()
from e684658 messaging: Remove "struct messaging_backend"
https://git.samba.org/?p=samba.git;a=shortlog;h=master
- Log -----------------------------------------------------------------
commit 5005a3a6961d40fe349f76db67c980be7dc9f3ea
Author: Volker Lendecke <vl at samba.org>
Date: Tue Jul 25 12:30:47 2017 +0200
libsmb: Enable "cli_notify" for SMB2+
Signed-off-by: Volker Lendecke <vl at samba.org>
Reviewed-by: Jeremy Allison <jra at samba.org>
Autobuild-User(master): Jeremy Allison <jra at samba.org>
Autobuild-Date(master): Wed Jul 26 01:33:25 CEST 2017 on sn-devel-144
commit 18011343d80a28fb46894d712b22c84dce067342
Author: Volker Lendecke <vl at samba.org>
Date: Tue Jul 25 12:12:02 2017 +0200
libsmb: Add cli_smb2_notify
We have to do the parsing manually. Looking at librpc/gen_ndr/ndr_notify.c we
have the following code snippet:
size_FileName1_0 = strlen_m(r->FileName1);
NDR_CHECK(ndr_pull_charset(ndr, NDR_SCALARS, &r->FileName1,
size_FileName1_0, sizeof(uint16_t),
CH_UTF16));
which means that we take strlen_m(r->FileName1) before we pull
it off the wire. Not sure how to fix this, but that is clearly
broken pidl output. Once that is fixed, we can convert this
to ndr_pull_struct.
Signed-off-by: Volker Lendecke <vl at samba.org>
Reviewed-by: Jeremy Allison <jra at samba.org>
commit ad33964f8c85b67a2d2b451bece208d8bfb8cad6
Author: Volker Lendecke <vl at samba.org>
Date: Tue Jul 25 12:11:37 2017 +0200
libsmb: Add smb2cli_notify()
Signed-off-by: Volker Lendecke <vl at samba.org>
Reviewed-by: Jeremy Allison <jra at samba.org>
-----------------------------------------------------------------------
Summary of changes:
...{smb2cli_query_directory.c => smb2cli_notify.c} | 140 ++++++++-------------
libcli/smb/smbXcli_base.h | 26 ++++
libcli/smb/wscript | 1 +
source3/libsmb/cli_smb2_fnum.c | 92 ++++++++++++++
source3/libsmb/cli_smb2_fnum.h | 5 +
source3/libsmb/clifile.c | 10 +-
6 files changed, 187 insertions(+), 87 deletions(-)
copy libcli/smb/{smb2cli_query_directory.c => smb2cli_notify.c} (51%)
Changeset truncated at 500 lines:
diff --git a/libcli/smb/smb2cli_query_directory.c b/libcli/smb/smb2cli_notify.c
similarity index 51%
copy from libcli/smb/smb2cli_query_directory.c
copy to libcli/smb/smb2cli_notify.c
index e6321ff..0a23cf9 100644
--- a/libcli/smb/smb2cli_query_directory.c
+++ b/libcli/smb/smb2cli_notify.c
@@ -1,7 +1,7 @@
/*
Unix SMB/CIFS implementation.
smb2 lib
- Copyright (C) Volker Lendecke 2011
+ Copyright (C) Volker Lendecke 2017
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
@@ -22,94 +22,69 @@
#include "lib/util/tevent_ntstatus.h"
#include "smb_common.h"
#include "smbXcli_base.h"
+#include "librpc/gen_ndr/ndr_notify.h"
-struct smb2cli_query_directory_state {
+struct smb2cli_notify_state {
uint8_t fixed[32];
- uint8_t dyn_pad[1];
+
struct iovec *recv_iov;
uint8_t *data;
uint32_t data_length;
};
-static void smb2cli_query_directory_done(struct tevent_req *subreq);
-
-struct tevent_req *smb2cli_query_directory_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,
- uint8_t level,
- uint8_t flags,
- uint32_t file_index,
- uint64_t fid_persistent,
- uint64_t fid_volatile,
- const char *mask,
- uint32_t outbuf_len)
+static void smb2cli_notify_done(struct tevent_req *subreq);
+
+struct tevent_req *smb2cli_notify_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,
+ uint32_t output_buffer_length,
+ uint64_t fid_persistent,
+ uint64_t fid_volatile,
+ uint32_t completion_filter,
+ bool recursive)
{
struct tevent_req *req, *subreq;
- struct smb2cli_query_directory_state *state;
+ struct smb2cli_notify_state *state;
uint8_t *fixed;
- uint8_t *dyn;
- size_t dyn_len;
req = tevent_req_create(mem_ctx, &state,
- struct smb2cli_query_directory_state);
+ struct smb2cli_notify_state);
if (req == NULL) {
return NULL;
}
-
- if (!convert_string_talloc(state, CH_UNIX, CH_UTF16,
- mask, strlen(mask),
- &dyn, &dyn_len)) {
- tevent_req_oom(req);
- return tevent_req_post(req, ev);
- }
-
- if (strlen(mask) == 0) {
- TALLOC_FREE(dyn);
- dyn_len = 0;
- }
-
fixed = state->fixed;
- SSVAL(fixed, 0, 33);
- SCVAL(fixed, 2, level);
- SCVAL(fixed, 3, flags);
- SIVAL(fixed, 4, file_index);
+ SSVAL(fixed, 0, 32);
+ SSVAL(fixed, 2, recursive ? SMB2_WATCH_TREE : 0);
+ SIVAL(fixed, 4, output_buffer_length);
SBVAL(fixed, 8, fid_persistent);
SBVAL(fixed, 16, fid_volatile);
- SSVAL(fixed, 24, SMB2_HDR_BODY + 32);
- SSVAL(fixed, 26, dyn_len);
- SIVAL(fixed, 28, outbuf_len);
-
- if (dyn_len == 0) {
- dyn = state->dyn_pad;
- dyn_len = sizeof(state->dyn_pad);
- }
+ SIVAL(fixed, 24, completion_filter);
+ SIVAL(fixed, 28, 0); /* reserved */
- subreq = smb2cli_req_send(state, ev, conn, SMB2_OP_QUERY_DIRECTORY,
+ subreq = smb2cli_req_send(state, ev, conn, SMB2_OP_NOTIFY,
0, 0, /* flags */
timeout_msec,
tcon,
session,
state->fixed, sizeof(state->fixed),
- dyn, dyn_len,
- outbuf_len); /* max_dyn_len */
+ NULL, 0, /* dyn* */
+ 0); /* max_dyn_len */
if (tevent_req_nomem(subreq, req)) {
return tevent_req_post(req, ev);
}
- tevent_req_set_callback(subreq, smb2cli_query_directory_done, req);
+ tevent_req_set_callback(subreq, smb2cli_notify_done, req);
return req;
}
-static void smb2cli_query_directory_done(struct tevent_req *subreq)
+static void smb2cli_notify_done(struct tevent_req *subreq)
{
- struct tevent_req *req =
- tevent_req_callback_data(subreq,
- struct tevent_req);
- struct smb2cli_query_directory_state *state =
- tevent_req_data(req,
- struct smb2cli_query_directory_state);
+ struct tevent_req *req = tevent_req_callback_data(
+ subreq, struct tevent_req);
+ struct smb2cli_notify_state *state = tevent_req_data(
+ req, struct smb2cli_notify_state);
NTSTATUS status;
struct iovec *iov;
uint16_t data_offset;
@@ -141,14 +116,11 @@ static void smb2cli_query_directory_done(struct tevent_req *subreq)
tevent_req_done(req);
}
-NTSTATUS smb2cli_query_directory_recv(struct tevent_req *req,
- TALLOC_CTX *mem_ctx,
- uint8_t **data,
- uint32_t *data_length)
+NTSTATUS smb2cli_notify_recv(struct tevent_req *req, TALLOC_CTX *mem_ctx,
+ uint8_t **data, uint32_t *data_length)
{
- struct smb2cli_query_directory_state *state =
- tevent_req_data(req,
- struct smb2cli_query_directory_state);
+ struct smb2cli_notify_state *state = tevent_req_data(
+ req, struct smb2cli_notify_state);
NTSTATUS status;
if (tevent_req_is_nterror(req, &status)) {
@@ -160,20 +132,18 @@ NTSTATUS smb2cli_query_directory_recv(struct tevent_req *req,
return NT_STATUS_OK;
}
-NTSTATUS smb2cli_query_directory(struct smbXcli_conn *conn,
- uint32_t timeout_msec,
- struct smbXcli_session *session,
- struct smbXcli_tcon *tcon,
- uint8_t level,
- uint8_t flags,
- uint32_t file_index,
- uint64_t fid_persistent,
- uint64_t fid_volatile,
- const char *mask,
- uint32_t outbuf_len,
- TALLOC_CTX *mem_ctx,
- uint8_t **data,
- uint32_t *data_length)
+NTSTATUS smb2cli_notify(struct smbXcli_conn *conn,
+ uint32_t timeout_msec,
+ struct smbXcli_session *session,
+ struct smbXcli_tcon *tcon,
+ uint32_t output_buffer_length,
+ uint64_t fid_persistent,
+ uint64_t fid_volatile,
+ uint32_t completion_filter,
+ bool recursive,
+ TALLOC_CTX *mem_ctx,
+ uint8_t **data,
+ uint32_t *data_length)
{
TALLOC_CTX *frame = talloc_stackframe();
struct tevent_context *ev;
@@ -191,19 +161,17 @@ NTSTATUS smb2cli_query_directory(struct smbXcli_conn *conn,
if (ev == NULL) {
goto fail;
}
- req = smb2cli_query_directory_send(frame, ev, conn, timeout_msec,
- session, tcon,
- level, flags,
- file_index, fid_persistent,
- fid_volatile, mask, outbuf_len);
+ req = smb2cli_notify_send(frame, ev, conn, timeout_msec,
+ session, tcon, output_buffer_length,
+ fid_persistent, fid_volatile,
+ completion_filter, recursive);
if (req == NULL) {
goto fail;
}
if (!tevent_req_poll_ntstatus(req, ev, &status)) {
goto fail;
}
- status = smb2cli_query_directory_recv(req, mem_ctx,
- data, data_length);
+ status = smb2cli_notify_recv(req, mem_ctx, data, data_length);
fail:
TALLOC_FREE(frame);
return status;
diff --git a/libcli/smb/smbXcli_base.h b/libcli/smb/smbXcli_base.h
index 52fec9a..338f0a4 100644
--- a/libcli/smb/smbXcli_base.h
+++ b/libcli/smb/smbXcli_base.h
@@ -806,6 +806,32 @@ NTSTATUS smb2cli_query_directory(struct smbXcli_conn *conn,
uint8_t **data,
uint32_t *data_length);
+struct tevent_req *smb2cli_notify_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,
+ uint32_t output_buffer_length,
+ uint64_t fid_persistent,
+ uint64_t fid_volatile,
+ uint32_t completion_filter,
+ bool recursive);
+NTSTATUS smb2cli_notify_recv(struct tevent_req *req, TALLOC_CTX *mem_ctx,
+ uint8_t **data, uint32_t *data_length);
+NTSTATUS smb2cli_notify(struct smbXcli_conn *conn,
+ uint32_t timeout_msec,
+ struct smbXcli_session *session,
+ struct smbXcli_tcon *tcon,
+ uint32_t output_buffer_length,
+ uint64_t fid_persistent,
+ uint64_t fid_volatile,
+ uint32_t completion_filter,
+ bool recursive,
+ TALLOC_CTX *mem_ctx,
+ uint8_t **data,
+ uint32_t *data_length);
+
struct tevent_req *smb2cli_ioctl_send(TALLOC_CTX *mem_ctx,
struct tevent_context *ev,
struct smbXcli_conn *conn,
diff --git a/libcli/smb/wscript b/libcli/smb/wscript
index e662826..53a5c21 100644
--- a/libcli/smb/wscript
+++ b/libcli/smb/wscript
@@ -39,6 +39,7 @@ def build(bld):
smb2cli_flush.c
smb2cli_set_info.c
smb2cli_query_info.c
+ smb2cli_notify.c
smb2cli_query_directory.c
smb2cli_ioctl.c
smb2cli_echo.c
diff --git a/source3/libsmb/cli_smb2_fnum.c b/source3/libsmb/cli_smb2_fnum.c
index 8ee97ca..2d2667e 100644
--- a/source3/libsmb/cli_smb2_fnum.c
+++ b/source3/libsmb/cli_smb2_fnum.c
@@ -3817,3 +3817,95 @@ NTSTATUS cli_smb2_ftruncate(struct cli_state *cli,
TALLOC_FREE(frame);
return status;
}
+
+NTSTATUS cli_smb2_notify(struct cli_state *cli, uint16_t fnum,
+ uint32_t buffer_size, uint32_t completion_filter,
+ bool recursive, TALLOC_CTX *mem_ctx,
+ struct notify_change **pchanges,
+ uint32_t *pnum_changes)
+{
+ NTSTATUS status;
+ struct smb2_hnd *ph = NULL;
+ TALLOC_CTX *frame = talloc_stackframe();
+ uint8_t *base;
+ uint32_t len, ofs;
+ struct notify_change *changes = NULL;
+ size_t num_changes = 0;
+
+ if (smbXcli_conn_has_async_calls(cli->conn)) {
+ /*
+ * Can't use sync call while an async call is in flight
+ */
+ status = NT_STATUS_INVALID_PARAMETER;
+ goto fail;
+ }
+
+ if (smbXcli_conn_protocol(cli->conn) < PROTOCOL_SMB2_02) {
+ status = NT_STATUS_INVALID_PARAMETER;
+ goto fail;
+ }
+
+ status = map_fnum_to_smb2_handle(cli, fnum, &ph);
+ if (!NT_STATUS_IS_OK(status)) {
+ goto fail;
+ }
+
+ status = smb2cli_notify(cli->conn, cli->timeout,
+ cli->smb2.session, cli->smb2.tcon,
+ buffer_size,
+ ph->fid_persistent, ph->fid_volatile,
+ completion_filter, recursive,
+ frame, &base, &len);
+
+ ofs = 0;
+
+ while (len - ofs >= 12) {
+ struct notify_change *tmp;
+ struct notify_change *c;
+ uint32_t next_ofs = IVAL(base, ofs);
+ uint32_t file_name_length = IVAL(base, ofs+8);
+ size_t namelen;
+ bool ok;
+
+ tmp = talloc_realloc(frame, changes, struct notify_change,
+ num_changes + 1);
+ if (tmp == NULL) {
+ status = NT_STATUS_NO_MEMORY;
+ goto fail;
+ }
+ changes = tmp;
+ c = &changes[num_changes];
+ num_changes += 1;
+
+ if (smb_buffer_oob(len, ofs, next_ofs) ||
+ smb_buffer_oob(len, ofs+12, file_name_length)) {
+ status = NT_STATUS_INVALID_NETWORK_RESPONSE;
+ goto fail;
+ }
+
+ c->action = IVAL(base, ofs+4);
+
+ ok = convert_string_talloc(changes, CH_UTF16LE, CH_UNIX,
+ base + ofs + 12, file_name_length,
+ &c->name, &namelen);
+ if (!ok) {
+ status = NT_STATUS_INVALID_NETWORK_RESPONSE;
+ goto fail;
+ }
+
+ if (next_ofs == 0) {
+ break;
+ }
+ ofs += next_ofs;
+ }
+
+ *pchanges = talloc_move(mem_ctx, &changes);
+ *pnum_changes = num_changes;
+ status = NT_STATUS_OK;
+
+fail:
+ cli->raw_status = status;
+
+ TALLOC_FREE(frame);
+ return status;
+}
diff --git a/source3/libsmb/cli_smb2_fnum.h b/source3/libsmb/cli_smb2_fnum.h
index 8e240c6..402801b 100644
--- a/source3/libsmb/cli_smb2_fnum.h
+++ b/source3/libsmb/cli_smb2_fnum.h
@@ -224,4 +224,9 @@ NTSTATUS cli_smb2_shadow_copy_data(TALLOC_CTX *mem_ctx,
NTSTATUS cli_smb2_ftruncate(struct cli_state *cli,
uint16_t fnum,
uint64_t newsize);
+NTSTATUS cli_smb2_notify(struct cli_state *cli, uint16_t fnum,
+ uint32_t buffer_size, uint32_t completion_filter,
+ bool recursive, TALLOC_CTX *mem_ctx,
+ struct notify_change **pchanges,
+ uint32_t *pnum_changes);
#endif /* __SMB2CLI_FNUM_H__ */
diff --git a/source3/libsmb/clifile.c b/source3/libsmb/clifile.c
index 1455fbd..828448f 100644
--- a/source3/libsmb/clifile.c
+++ b/source3/libsmb/clifile.c
@@ -5602,11 +5602,19 @@ NTSTATUS cli_notify(struct cli_state *cli, uint16_t fnum, uint32_t buffer_size,
TALLOC_CTX *mem_ctx, uint32_t *pnum_changes,
struct notify_change **pchanges)
{
- TALLOC_CTX *frame = talloc_stackframe();
+ TALLOC_CTX *frame;
struct tevent_context *ev;
struct tevent_req *req;
NTSTATUS status = NT_STATUS_NO_MEMORY;
+ if (smbXcli_conn_protocol(cli->conn) >= PROTOCOL_SMB2_02) {
+ return cli_smb2_notify(cli, fnum, buffer_size,
+ completion_filter, recursive,
+ mem_ctx, pchanges, pnum_changes);
+ }
+
+ frame = talloc_stackframe();
+
if (smbXcli_conn_has_async_calls(cli->conn)) {
/*
* Can't use sync call while an async call is in flight
--
Samba Shared Repository
More information about the samba-cvs
mailing list