notify: Re-add notify_walk()
authorVolker Lendecke <vl@samba.org>
Fri, 9 Jan 2015 12:48:56 +0000 (12:48 +0000)
committerJeremy Allison <jra@samba.org>
Tue, 7 Jul 2015 21:51:24 +0000 (23:51 +0200)
This used to be a tdb traverse wrapper. Now we get the notify db from
notifyd via messages.

Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
source3/smbd/notify_msg.c
source3/smbd/proto.h
source3/utils/status.c

index b31cb572ab4e553c7fcd41625535b62d0a0f72b1..2fe44724a3cff6197ea37b7fad8515aab8ca80d8 100644 (file)
@@ -252,14 +252,72 @@ void notify_walk_idx(struct notify_context *notify,
        return;
 }
 
-void notify_walk(struct notify_context *notify,
-                void (*fn)(const char *path,
-                           struct notify_db_entry *entries,
-                           size_t num_entries,
-                           time_t deleted_time, void *private_data),
-                void *private_data)
+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)
 {
-       return;
+       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)) {
+               DEBUG(10, ("%s: messaging_send_buf failed\n",
+                          nt_errstr(status)));
+               TALLOC_FREE(ev);
+               return status;
+       }
+
+       ok = tevent_req_poll(req, ev);
+       if (!ok) {
+               DEBUG(10, ("%s: tevent_req_poll failed\n", __func__));
+               TALLOC_FREE(ev);
+               return NT_STATUS_INTERNAL_ERROR;
+       }
+
+       ret = messaging_read_recv(req, ev, &rec);
+       if (ret != 0) {
+               DEBUG(10, ("%s: messaging_read_recv failed: %s\n",
+                          __func__, 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) {
+               DEBUG(10, ("%s: notifyd_parse_db failed: %s\n",
+                          __func__, strerror(ret)));
+               TALLOC_FREE(ev);
+               return map_nt_error_from_unix(ret);
+       }
+
+       TALLOC_FREE(ev);
+       return NT_STATUS_OK;
 }
 
 void notify_cleanup(struct notify_context *notify)
index e4a434ab5ec6ab38b00734a83598b264663325c7..79be349ce4065015de0a049d91196c717c7204f2 100644 (file)
@@ -574,12 +574,14 @@ void notify_walk_idx(struct notify_context *notify,
                                uint32_t *vnns, size_t num_vnns,
                                void *private_data),
                     void *private_data);
-void notify_walk(struct notify_context *notify,
-                void (*fn)(const char *path,
-                           struct notify_db_entry *entries,
-                           size_t num_entries,
-                           time_t deleted_time, void *private_data),
-                void *private_data);
+
+struct notify_instance;
+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);
+
 void notify_cleanup(struct notify_context *notify);
 
 /* The following definitions come from smbd/ntquotas.c  */
index afbba69126a0d3de91dfe11eed66b8eababe26e2..c11b4ee70ffe35f7e62d1165988984398a523274 100644 (file)
@@ -45,6 +45,7 @@
 #include "lib/conn_tdb.h"
 #include "serverid.h"
 #include "status_profile.h"
+#include "smbd/notifyd/notifyd.h"
 
 #define SMB_MAXPIDS            2048
 static uid_t           Ucrit_uid = 0;               /* added by OH */
@@ -326,27 +327,17 @@ static int traverse_sessionid(const char *key, struct sessionid *session,
 }
 
 
-static void print_notify_recs(const char *path,
-                             struct notify_db_entry *entries,
-                             size_t num_entries,
-                             time_t deleted_time, void *private_data)
+static bool print_notify_rec(const char *path, struct server_id server,
+                            const struct notify_instance *instance,
+                            void *private_data)
 {
-       size_t i;
-       d_printf("%s\n", path);
+       struct server_id_buf idbuf;
 
-       if (num_entries == 0) {
-               d_printf("deleted %s\n", time_to_asc(deleted_time));
-       }
-
-       for (i=0; i<num_entries; i++) {
-               struct notify_db_entry *e = &entries[i];
-               struct server_id_buf idbuf;
+       d_printf("%s\\%s\\%x\\%x\n", path, server_id_str_buf(server, &idbuf),
+                (unsigned)instance->filter,
+                (unsigned)instance->subdir_filter);
 
-               printf("%s %x %x\n", server_id_str_buf(e->server, &idbuf),
-                      (unsigned)e->filter,
-                      (unsigned)e->subdir_filter);
-       }
-       printf("\n");
+       return true;
 }
 
 int main(int argc, const char *argv[])
@@ -375,7 +366,7 @@ int main(int argc, const char *argv[])
        };
        TALLOC_CTX *frame = talloc_stackframe();
        int ret = 0;
-       struct messaging_context *msg_ctx;
+       struct messaging_context *msg_ctx = NULL;
        char *db_path;
        bool ok;
 
@@ -586,11 +577,22 @@ int main(int argc, const char *argv[])
        if (show_notify) {
                struct notify_context *n;
 
-               n = notify_init(talloc_tos(), NULL, NULL);
+               if (msg_ctx == NULL) {
+                       msg_ctx = messaging_init(
+                               NULL, samba_tevent_context_init(NULL));
+                       if (msg_ctx == NULL) {
+                               fprintf(stderr, "messaging_init failed\n");
+                               ret = -1;
+                               goto done;
+                       }
+               }
+
+               n = notify_init(talloc_tos(), msg_ctx,
+                               messaging_tevent_context(msg_ctx));
                if (n == NULL) {
                        goto done;
                }
-               notify_walk(n, print_notify_recs, NULL);
+               notify_walk(n, print_notify_rec, NULL);
                TALLOC_FREE(n);
        }