The branch, master has been updated
       via  bbc065da6ea test: Check that notifyd messages actually change the 
database
       via  609867ef7c7 test: Add a first unit test for notifyd
       via  741428eaede notifyd: Add fcn_wait_send()/recv()
       via  49859ac11d6 notifyd: Factor out notify_walk() into its own file
       via  3e648e9d616 notifyd: Factor out notifyd_parse_entry() into its own 
file
       via  4dac4859db2 notifyd: Fix a typo
       via  79b0829ea2d notify: Remove an unused structure definition
       via  5bb796cb259 lib: Fix includes for messages.h
      from  0dad9a31cb7 smbd: add and use SMB2_FILE_ALL_INFORMATION

https://git.samba.org/?p=samba.git;a=shortlog;h=master


- Log -----------------------------------------------------------------
commit bbc065da6eaf17ace3beb6715aef6105fc2c36bc
Author: Volker Lendecke <[email protected]>
Date:   Fri Oct 23 15:14:21 2020 +0200

    test: Check that notifyd messages actually change the database
    
    Signed-off-by: Volker Lendecke <[email protected]>
    Reviewed-by: Jeremy Allison <[email protected]>
    
    Autobuild-User(master): Jeremy Allison <[email protected]>
    Autobuild-Date(master): Sat Oct 24 07:20:17 UTC 2020 on sn-devel-184

commit 609867ef7c76265a422ade6819ad98288c2d6257
Author: Volker Lendecke <[email protected]>
Date:   Thu Oct 22 17:23:44 2020 +0200

    test: Add a first unit test for notifyd
    
    Use the notifyd "messaging" protocol to check if notifyd works at all
    
    Signed-off-by: Volker Lendecke <[email protected]>
    Reviewed-by: Jeremy Allison <[email protected]>

commit 741428eaedeaf16edb7ecf3a367fe107d3631bc7
Author: Volker Lendecke <[email protected]>
Date:   Thu Oct 22 11:52:27 2020 +0200

    notifyd: Add fcn_wait_send()/recv()
    
    tevent_req based functions to listen for file change
    notifications. Mainly right now for testing purposes, but it could be
    used to also implement smbd's file change notify in a more tevent_req
    based fashion than it is implemented now.
    
    Signed-off-by: Volker Lendecke <[email protected]>
    Reviewed-by: Jeremy Allison <[email protected]>

commit 49859ac11d682e46ec79266395b0abe2083f2cdd
Author: Volker Lendecke <[email protected]>
Date:   Wed Oct 21 17:28:14 2020 +0200

    notifyd: Factor out notify_walk() into its own file
    
    To be used in smbtorture, avoid having to include almost all of smbd
    just for this
    
    Signed-off-by: Volker Lendecke <[email protected]>
    Reviewed-by: Jeremy Allison <[email protected]>

commit 3e648e9d616ab7943adcb3b5f0fcf9b03f420313
Author: Volker Lendecke <[email protected]>
Date:   Wed Oct 21 17:26:30 2020 +0200

    notifyd: Factor out notifyd_parse_entry() into its own file
    
    The next step will be to factor out notifyd_parse_db() and and
    notify_walk() for consumption outside of smbd. notifyd_parse_db()
    needs access to the internal representation of notifyd's database, so
    move it into a commonly usable file.
    
    Signed-off-by: Volker Lendecke <[email protected]>
    Reviewed-by: Jeremy Allison <[email protected]>

commit 4dac4859db22e632b9f16783155d2befee8c5924
Author: Volker Lendecke <[email protected]>
Date:   Wed Oct 21 16:10:25 2020 +0200

    notifyd: Fix a typo
    
    Signed-off-by: Volker Lendecke <[email protected]>
    Reviewed-by: Jeremy Allison <[email protected]>

commit 79b0829ea2da2c18934dbc95cc5fe83a4c48d1f6
Author: Volker Lendecke <[email protected]>
Date:   Wed Oct 21 12:59:45 2020 +0200

    notify: Remove an unused structure definition
    
    Signed-off-by: Volker Lendecke <[email protected]>
    Reviewed-by: Jeremy Allison <[email protected]>

commit 5bb796cb259052e5ea5dc9c3c322e96373bbe4d3
Author: Volker Lendecke <[email protected]>
Date:   Thu Oct 22 11:47:27 2020 +0200

    lib: Fix includes for messages.h
    
    It references struct tevent_context
    
    Signed-off-by: Volker Lendecke <[email protected]>
    Reviewed-by: Jeremy Allison <[email protected]>

-----------------------------------------------------------------------

Summary of changes:
 librpc/idl/notify.idl                              |   6 -
 source3/include/messages.h                         |   3 +
 source3/selftest/tests.py                          |   5 +
 source3/smbd/notify_msg.c                          |  68 ----
 source3/smbd/notifyd/fcn_wait.c                    | 270 ++++++++++++++++
 .../smbd/notifyd/fcn_wait.h                        |  27 +-
 source3/smbd/notifyd/notifyd.c                     | 111 +------
 source3/smbd/notifyd/notifyd.h                     |  13 -
 source3/smbd/notifyd/notifyd_db.c                  | 165 ++++++++++
 .../smbd/notifyd/notifyd_db.h                      |  18 +-
 .../smbd/notifyd/notifyd_entry.c                   |  38 ++-
 .../smbd/notifyd/notifyd_private.h                 |  39 ++-
 source3/smbd/notifyd/test_notifyd.c                | 347 +++++++++++++++++++++
 source3/smbd/notifyd/wscript_build                 |  27 +-
 source3/smbd/proto.h                               |   7 -
 source3/utils/status.c                             |  12 +-
 16 files changed, 894 insertions(+), 262 deletions(-)
 create mode 100644 source3/smbd/notifyd/fcn_wait.c
 copy libcli/named_pipe_auth/tstream_u32_read.h => 
source3/smbd/notifyd/fcn_wait.h (68%)
 create mode 100644 source3/smbd/notifyd/notifyd_db.c
 copy lib/util/talloc_report_printf.h => source3/smbd/notifyd/notifyd_db.h (69%)
 copy lib/util/iov_buf.h => source3/smbd/notifyd/notifyd_entry.c (54%)
 copy libcli/smb/smb2_lock.h => source3/smbd/notifyd/notifyd_private.h (52%)
 create mode 100644 source3/smbd/notifyd/test_notifyd.c


Changeset truncated at 500 lines:

diff --git a/librpc/idl/notify.idl b/librpc/idl/notify.idl
index 09d06bed662..5f83f4fd24e 100644
--- a/librpc/idl/notify.idl
+++ b/librpc/idl/notify.idl
@@ -70,12 +70,6 @@ interface notify
                pointer private_data;
        } notify_event;
 
-       typedef [public] struct {
-               uint32 action;
-               uint32 filter;
-               utf8string path;
-       } notify_remote_event;
-
        typedef [v1_enum] enum {
                FILE_ACTION_ADDED               = 0x00000001,
                FILE_ACTION_REMOVED             = 0x00000002,
diff --git a/source3/include/messages.h b/source3/include/messages.h
index f7b40664b0b..79e63eccd53 100644
--- a/source3/include/messages.h
+++ b/source3/include/messages.h
@@ -21,6 +21,9 @@
 #ifndef _MESSAGES_H_
 #define _MESSAGES_H_
 
+#include "replace.h"
+#include <tevent.h>
+
 /* change the message version with any incompatible changes in the protocol */
 #define MESSAGE_VERSION 2
 
diff --git a/source3/selftest/tests.py b/source3/selftest/tests.py
index b9c44398e81..6cfb98e2bb6 100755
--- a/source3/selftest/tests.py
+++ b/source3/selftest/tests.py
@@ -905,6 +905,11 @@ plantestsuite(
     [os.path.join(samba3srcdir, "../nsswitch/tests/test_ticket_expiry.sh"),
      '$DOMAIN'])
 
+plansmbtorture4testsuite(
+    "notifyd",
+    "fileserver:local",
+    '//foo/bar -U%')
+
 test = 'rpc.lsa.lookupsids'
 auth_options = ["", "ntlm", "spnego", "spnego,ntlm", "spnego,smb1", 
"spnego,smb2"]
 signseal_options = ["", ",connect", ",packet", ",sign", ",seal"]
diff --git a/source3/smbd/notify_msg.c b/source3/smbd/notify_msg.c
index 7238cff6828..0ea992c4929 100644
--- a/source3/smbd/notify_msg.c
+++ b/source3/smbd/notify_msg.c
@@ -245,71 +245,3 @@ void notify_trigger(struct notify_context *ctx,
                ctx->msg_ctx, ctx->notifyd, MSG_SMB_NOTIFY_TRIGGER,
                iov, ARRAY_SIZE(iov), NULL, 0);
 }
-
-NTSTATUS notify_walk(struct notify_context *notify,
-                    bool (*fn)(const char *path, struct server_id server,
-                               const struct notify_instance *instance,
-                               void *private_data),
-                    void *private_data)
-{
-       struct tevent_context *ev;
-       struct tevent_req *req;
-       struct messaging_rec *rec;
-       uint64_t log_idx;
-       NTSTATUS status;
-       int ret;
-       bool ok;
-
-       ev = samba_tevent_context_init(notify);
-       if (ev == NULL) {
-               return NT_STATUS_NO_MEMORY;
-       }
-
-       req = messaging_read_send(ev, ev, notify->msg_ctx, MSG_SMB_NOTIFY_DB);
-       if (req == NULL) {
-               TALLOC_FREE(ev);
-               return NT_STATUS_NO_MEMORY;
-       }
-
-       ok = tevent_req_set_endtime(req, ev, timeval_current_ofs(10, 0));
-       if (!ok) {
-               TALLOC_FREE(ev);
-               return NT_STATUS_NO_MEMORY;
-       }
-
-       status = messaging_send_buf(notify->msg_ctx, notify->notifyd,
-                                   MSG_SMB_NOTIFY_GET_DB, NULL, 0);
-       if (!NT_STATUS_IS_OK(status)) {
-               DBG_DEBUG("messaging_send_buf failed: %s\n",
-                         nt_errstr(status));
-               TALLOC_FREE(ev);
-               return status;
-       }
-
-       ok = tevent_req_poll(req, ev);
-       if (!ok) {
-               DBG_DEBUG("tevent_req_poll failed\n");
-               TALLOC_FREE(ev);
-               return NT_STATUS_INTERNAL_ERROR;
-       }
-
-       ret = messaging_read_recv(req, ev, &rec);
-       if (ret != 0) {
-               DBG_DEBUG("messaging_read_recv failed: %s\n",
-                         strerror(ret));
-               TALLOC_FREE(ev);
-               return map_nt_error_from_unix(ret);
-       }
-
-       ret = notifyd_parse_db(rec->buf.data, rec->buf.length, &log_idx,
-                              fn, private_data);
-       if (ret != 0) {
-               DBG_DEBUG("notifyd_parse_db failed: %s\n",
-                         strerror(ret));
-               TALLOC_FREE(ev);
-               return map_nt_error_from_unix(ret);
-       }
-
-       TALLOC_FREE(ev);
-       return NT_STATUS_OK;
-}
diff --git a/source3/smbd/notifyd/fcn_wait.c b/source3/smbd/notifyd/fcn_wait.c
new file mode 100644
index 00000000000..e32240d911a
--- /dev/null
+++ b/source3/smbd/notifyd/fcn_wait.c
@@ -0,0 +1,270 @@
+/*
+ * 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 "replace.h"
+#include "fcn_wait.h"
+#include "notifyd.h"
+#include "lib/util/tevent_ntstatus.h"
+
+struct fcn_event {
+       struct fcn_event *prev, *next;
+       struct notify_event_msg msg;
+};
+
+struct fcn_wait_state {
+       struct tevent_context *ev;
+       struct messaging_context *msg_ctx;
+       struct server_id notifyd;
+       const char *path;
+
+       struct tevent_req *recv_subreq;
+
+       struct fcn_event *events;
+};
+
+static bool fcn_wait_cancel(struct tevent_req *req);
+static void fcn_wait_cleanup(
+       struct tevent_req *req, enum tevent_req_state req_state);
+static bool fcn_wait_filter(struct messaging_rec *rec, void *private_data);
+static void fcn_wait_done(struct tevent_req *subreq);
+
+struct tevent_req *fcn_wait_send(
+       TALLOC_CTX *mem_ctx,
+       struct tevent_context *ev,
+       struct messaging_context *msg_ctx,
+       struct server_id notifyd,
+       const char *path,
+       uint32_t filter,
+       uint32_t subdir_filter)
+{
+       struct tevent_req *req = NULL;
+       struct fcn_wait_state *state = NULL;
+       struct notify_rec_change_msg msg = {
+               .instance.filter = filter,
+               .instance.subdir_filter = subdir_filter,
+       };
+       struct iovec iov[2];
+       NTSTATUS status;
+
+       req = tevent_req_create(mem_ctx, &state, struct fcn_wait_state);
+       if (req == NULL) {
+               return NULL;
+       }
+       state->ev = ev;
+       state->msg_ctx = msg_ctx;
+       state->notifyd = notifyd;
+       state->path = path;
+
+       state->recv_subreq = messaging_filtered_read_send(
+               state, ev, msg_ctx, fcn_wait_filter, req);
+       if (tevent_req_nomem(state->recv_subreq, req)) {
+               return tevent_req_post(req, ev);
+       }
+       tevent_req_set_callback(state->recv_subreq, fcn_wait_done, req);
+       tevent_req_set_cleanup_fn(req, fcn_wait_cleanup);
+
+       clock_gettime_mono(&msg.instance.creation_time);
+       msg.instance.private_data = state;
+
+       iov[0].iov_base = &msg;
+       iov[0].iov_len = offsetof(struct notify_rec_change_msg, path);
+       iov[1].iov_base = discard_const_p(char, path);
+       iov[1].iov_len = strlen(path)+1;
+
+       status = messaging_send_iov(
+               msg_ctx,                        /* msg_ctx */
+               notifyd,                        /* dst */
+               MSG_SMB_NOTIFY_REC_CHANGE,      /* mst_type */
+               iov,                            /* iov */
+               ARRAY_SIZE(iov),                /* iovlen */
+               NULL,                           /* fds */
+               0);                             /* num_fds */
+       if (tevent_req_nterror(req, status)) {
+               DBG_DEBUG("messaging_send_iov failed: %s\n",
+                         nt_errstr(status));
+               return tevent_req_post(req, ev);
+       }
+       tevent_req_set_cancel_fn(req, fcn_wait_cancel);
+
+       return req;
+}
+
+static bool fcn_wait_cancel(struct tevent_req *req)
+{
+       struct fcn_wait_state *state = tevent_req_data(
+               req, struct fcn_wait_state);
+       struct notify_rec_change_msg msg = {
+               .instance.filter = 0, /* filter==0 is a delete msg */
+               .instance.subdir_filter = 0,
+       };
+       struct iovec iov[2];
+       NTSTATUS status;
+
+       clock_gettime_mono(&msg.instance.creation_time);
+       msg.instance.private_data = state;
+
+       iov[0].iov_base = &msg;
+       iov[0].iov_len = offsetof(struct notify_rec_change_msg, path);
+       iov[1].iov_base = discard_const_p(char, state->path);
+       iov[1].iov_len = strlen(state->path)+1;
+
+       status = messaging_send_iov(
+               state->msg_ctx,                 /* msg_ctx */
+               state->notifyd,                 /* dst */
+               MSG_SMB_NOTIFY_REC_CHANGE,      /* mst_type */
+               iov,                            /* iov */
+               ARRAY_SIZE(iov),                /* iovlen */
+               NULL,                           /* fds */
+               0);                             /* num_fds */
+       if (!NT_STATUS_IS_OK(status)) {
+               DBG_DEBUG("messaging_send_iov failed: %s\n",
+                         nt_errstr(status));
+               return false;
+       }
+
+       fcn_wait_cleanup(req, 0); /* fcn_wait_cleanup ignores req_state */
+       tevent_req_defer_callback(req, state->ev);
+       tevent_req_nterror(req, NT_STATUS_CANCELLED);
+
+       return true;
+}
+
+static void fcn_wait_cleanup(
+       struct tevent_req *req, enum tevent_req_state req_state)
+{
+       struct fcn_wait_state *state = tevent_req_data(
+               req, struct fcn_wait_state);
+       TALLOC_FREE(state->recv_subreq);
+}
+
+static bool fcn_wait_filter(struct messaging_rec *rec, void *private_data)
+{
+       struct tevent_req *req = talloc_get_type_abort(
+               private_data, struct tevent_req);
+       struct fcn_wait_state *state = tevent_req_data(
+               req, struct fcn_wait_state);
+       struct notify_event_msg msg = { .action = 0 };
+       struct fcn_event *evt = NULL;
+
+       if (rec->msg_type != MSG_PVFS_NOTIFY) {
+               DBG_DEBUG("Ignoring msg %"PRIu32"\n", rec->msg_type);
+               return false;
+       }
+
+       /*
+        * We need at least the trailing '\0' for the path
+        */
+       if (rec->buf.length < (offsetof(struct notify_event_msg, path) + 1)) {
+               DBG_DEBUG("Ignoring short (%zu) msg\n", rec->buf.length);
+               return false;
+       }
+       if (rec->buf.data[rec->buf.length-1] != '\0') {
+               DBG_DEBUG("Expected 0-terminated path\n");
+               return false;
+       }
+
+       memcpy(&msg, rec->buf.data, sizeof(msg));
+
+       if (msg.private_data != state) {
+               DBG_DEBUG("Got private_data=%p, expected %p\n",
+                         msg.private_data,
+                         state);
+               return false;
+       }
+
+       evt = talloc_memdup(state, rec->buf.data, rec->buf.length);
+       if (evt == NULL) {
+               DBG_DEBUG("talloc_memdup failed\n");
+               return false;
+       }
+       talloc_set_name_const(evt, "struct fcn_event");
+
+       /*
+        * TODO: Sort by timestamp
+        */
+
+       DLIST_ADD_END(state->events, evt);
+
+       tevent_req_defer_callback(req, state->ev);
+       tevent_req_notify_callback(req);
+
+       return false;
+}
+
+static void fcn_wait_done(struct tevent_req *subreq)
+{
+       struct tevent_req *req = tevent_req_callback_data(
+               subreq, struct tevent_req);
+       int ret;
+
+       ret = messaging_filtered_read_recv(subreq, NULL, NULL);
+       TALLOC_FREE(subreq);
+       if (ret != 0) {
+               DBG_DEBUG("messaging_filtered_read failed: %s\n",
+                         strerror(ret));
+               tevent_req_nterror(req, map_nt_error_from_unix(ret));
+               return;
+       }
+
+       /*
+        * We should never have gotten here, all work is done from the
+        * filter function.
+        */
+       tevent_req_nterror(req, NT_STATUS_INTERNAL_ERROR);
+}
+
+NTSTATUS fcn_wait_recv(
+       struct tevent_req *req,
+       TALLOC_CTX *mem_ctx,
+       struct timespec *when,
+       uint32_t *action,
+       char **path)
+{
+       struct fcn_wait_state *state = tevent_req_data(
+               req, struct fcn_wait_state);
+       struct fcn_event *evt = NULL;
+       NTSTATUS status;
+
+       if (!tevent_req_is_in_progress(req) &&
+           tevent_req_is_nterror(req, &status)) {
+               return status;
+       }
+       evt = state->events;
+       if (evt == NULL) {
+               return NT_STATUS_RETRY;
+       }
+
+       if (path != NULL) {
+               *path = talloc_strdup(mem_ctx, evt->msg.path);
+               if ((*path) == NULL) {
+                       return NT_STATUS_NO_MEMORY;
+               }
+       }
+       if (when != NULL) {
+               *when = evt->msg.when;
+       }
+       if (action != NULL) {
+               *action = evt->msg.action;
+       }
+
+       DLIST_REMOVE(state->events, evt);
+
+       if (state->events != NULL) {
+               tevent_req_defer_callback(req, state->ev);
+               tevent_req_notify_callback(req);
+       }
+
+       return NT_STATUS_OK;
+}
diff --git a/libcli/named_pipe_auth/tstream_u32_read.h 
b/source3/smbd/notifyd/fcn_wait.h
similarity index 68%
copy from libcli/named_pipe_auth/tstream_u32_read.h
copy to source3/smbd/notifyd/fcn_wait.h
index 1356ff03631..daadee4fe05 100644
--- a/libcli/named_pipe_auth/tstream_u32_read.h
+++ b/source3/smbd/notifyd/fcn_wait.h
@@ -1,8 +1,4 @@
 /*
- * Unix SMB/CIFS implementation.
- *
- * Copyright (C) Volker Lendecke 2019
- *
  * 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
@@ -17,21 +13,26 @@
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
 
-#ifndef TSTREAM_U32_READ_H
-#define TSTREAM_U32_READ_H
+#ifndef __NOTIFYD_FCN_WAIT_H__
+#define __NOTIFYD_FCN_WAIT_H__
 
 #include "replace.h"
-#include "tsocket.h"
+#include "messages.h"
+#include "librpc/gen_ndr/server_id.h"
 
-struct tevent_req *tstream_u32_read_send(
+struct tevent_req *fcn_wait_send(
        TALLOC_CTX *mem_ctx,
        struct tevent_context *ev,
-       uint32_t max_msglen,
-       struct tstream_context *stream);
-int tstream_u32_read_recv(
+       struct messaging_context *msg_ctx,
+       struct server_id notifyd,
+       const char *path,
+       uint32_t filter,
+       uint32_t subdir_filter);
+NTSTATUS fcn_wait_recv(
        struct tevent_req *req,
        TALLOC_CTX *mem_ctx,
-       uint8_t **buf,
-       size_t *buflen);
+       struct timespec *when,
+       uint32_t *action,
+       char **path);
 
 #endif
diff --git a/source3/smbd/notifyd/notifyd.c b/source3/smbd/notifyd/notifyd.c
index ba030fa1ecc..601bd168cd8 100644
--- a/source3/smbd/notifyd/notifyd.c
+++ b/source3/smbd/notifyd/notifyd.c
@@ -19,6 +19,7 @@
 
 #include "replace.h"
 #include <tevent.h>
+#include "notifyd_private.h"
 #include "lib/util/server_id.h"
 #include "lib/util/data_blob.h"
 #include "librpc/gen_ndr/notify.h"
@@ -63,7 +64,7 @@ struct notifyd_state {
         *
         * struct notifyd_instance
         *
-        * to be maintained and parsed by notifyd_entry_parse()
+        * to be maintained and parsed by notifyd_parse_entry()
         */
        struct db_context *entries;
 
@@ -99,22 +100,6 @@ struct notifyd_state {
        struct sys_notify_context *sys_notify_ctx;
 };
 
-/*
- * notifyd's representation of a notify instance
- */
-struct notifyd_instance {
-       struct server_id client;
-       struct notify_instance instance;
-
-       void *sys_watch; /* inotify/fam/etc handle */
-
-       /*
-        * Filters after sys_watch took responsibility of some bits
-        */
-       uint32_t internal_filter;
-       uint32_t internal_subdir_filter;
-};
-
 struct notifyd_peer {
        struct notifyd_state *state;
        struct server_id pid;
@@ -342,28 +327,6 @@ int notifyd_recv(struct tevent_req *req)
        return tevent_req_simple_recv_unix(req);
 }
 
-/*


-- 
Samba Shared Repository

Reply via email to