r23792: convert Samba4 to GPLv3
[kai/samba-autobuild/.git] / source4 / ntvfs / common / notify.c
index 13fd44abf0372076e7e804cea29b96a6dced7aff..0d36a20a60c56c7477af6a29428e50e77ad7d270 100644 (file)
@@ -5,7 +5,7 @@
    
    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 2 of the License, or
+   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,
@@ -14,8 +14,7 @@
    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, write to the Free Software
-   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
 
 /*
@@ -33,7 +32,9 @@
 #include "lib/messaging/irpc.h"
 #include "librpc/gen_ndr/ndr_notify.h"
 #include "lib/util/dlinklist.h"
+#include "ntvfs/common/ntvfs_common.h"
 #include "ntvfs/sysdep/sys_notify.h"
+#include "cluster/cluster.h"
 
 struct notify_context {
        struct tdb_wrap *w;
@@ -48,7 +49,7 @@ struct notify_context {
 
 struct notify_list {
        struct notify_list *next, *prev;
-       void *private;
+       void *private_data;
        void (*callback)(void *, const struct notify_event *);
        void *sys_notify_handle;
        int depth;
@@ -60,7 +61,7 @@ struct notify_list {
 #define NOTIFY_ENABLE_DEFAULT  True
 
 static NTSTATUS notify_remove_all(struct notify_context *notify);
-static void notify_handler(struct messaging_context *msg_ctx, void *private, 
+static void notify_handler(struct messaging_context *msg_ctx, void *private_data
                           uint32_t msg_type, struct server_id server_id, DATA_BLOB *data);
 
 /*
@@ -83,7 +84,6 @@ struct notify_context *notify_init(TALLOC_CTX *mem_ctx, struct server_id server,
                                   struct event_context *ev,
                                   struct share_config *scfg)
 {
-       char *path;
        struct notify_context *notify;
 
        if (share_bool_option(scfg, NOTIFY_ENABLE, NOTIFY_ENABLE_DEFAULT) != True) {
@@ -95,11 +95,7 @@ struct notify_context *notify_init(TALLOC_CTX *mem_ctx, struct server_id server,
                return NULL;
        }
 
-       path = smbd_tmp_path(notify, "notify.tdb");
-       notify->w = tdb_wrap_open(notify, path, 0,  
-                                 TDB_SEQNUM,
-                                 O_RDWR|O_CREAT, 0600);
-       talloc_free(path);
+       notify->w = cluster_tdb_tmp_open(notify, "notify.tdb", TDB_SEQNUM);
        if (notify->w == NULL) {
                talloc_free(notify);
                return NULL;
@@ -216,6 +212,7 @@ static NTSTATUS notify_save(struct notify_context *notify)
        }
 
        tmp_ctx = talloc_new(notify);
+       NT_STATUS_HAVE_NO_MEMORY(tmp_ctx);
 
        status = ndr_push_struct_blob(&blob, tmp_ctx, notify->array, 
                                      (ndr_push_flags_fn_t)ndr_push_notify_array);
@@ -240,15 +237,19 @@ static NTSTATUS notify_save(struct notify_context *notify)
 /*
   handle incoming notify messages
 */
-static void notify_handler(struct messaging_context *msg_ctx, void *private, 
+static void notify_handler(struct messaging_context *msg_ctx, void *private_data
                           uint32_t msg_type, struct server_id server_id, DATA_BLOB *data)
 {
-       struct notify_context *notify = talloc_get_type(private, struct notify_context);
+       struct notify_context *notify = talloc_get_type(private_data, struct notify_context);
        NTSTATUS status;
        struct notify_event ev;
        TALLOC_CTX *tmp_ctx = talloc_new(notify);
        struct notify_list *listel;
 
+       if (tmp_ctx == NULL) {
+               return;
+       }
+
        status = ndr_pull_struct_blob(data, tmp_ctx, &ev, 
                                      (ndr_pull_flags_fn_t)ndr_pull_notify_event);
        if (!NT_STATUS_IS_OK(status)) {
@@ -257,8 +258,8 @@ static void notify_handler(struct messaging_context *msg_ctx, void *private,
        }
 
        for (listel=notify->list;listel;listel=listel->next) {
-               if (listel->private == ev.private) {
-                       listel->callback(listel->private, &ev);
+               if (listel->private_data == ev.private_data) {
+                       listel->callback(listel->private_data, &ev);
                        break;
                }
        }
@@ -273,15 +274,15 @@ static void sys_notify_callback(struct sys_notify_context *ctx,
                                void *ptr, struct notify_event *ev)
 {
        struct notify_list *listel = talloc_get_type(ptr, struct notify_list);
-       ev->private = listel;
-       listel->callback(listel->private, ev);
+       ev->private_data = listel;
+       listel->callback(listel->private_data, ev);
 }
 
 /*
   add an entry to the notify array
 */
 static NTSTATUS notify_add_array(struct notify_context *notify, struct notify_entry *e,
-                                void *private, int depth)
+                                void *private_data, int depth)
 {
        int i;
        struct notify_depth *d;
@@ -307,7 +308,7 @@ static NTSTATUS notify_add_array(struct notify_context *notify, struct notify_en
        d->entries = ee;
 
        d->entries[d->num_entries] = *e;
-       d->entries[d->num_entries].private = private;
+       d->entries[d->num_entries].private_data = private_data;
        d->entries[d->num_entries].server = notify->server;
        d->entries[d->num_entries].path_len = strlen(e->path);
        d->num_entries++;
@@ -337,7 +338,7 @@ static NTSTATUS notify_add_array(struct notify_context *notify, struct notify_en
 */
 NTSTATUS notify_add(struct notify_context *notify, struct notify_entry *e0,
                    void (*callback)(void *, const struct notify_event *), 
-                   void *private)
+                   void *private_data)
 {
        struct notify_entry e = *e0;
        NTSTATUS status;
@@ -378,7 +379,7 @@ NTSTATUS notify_add(struct notify_context *notify, struct notify_entry *e0,
                goto done;
        }
 
-       listel->private = private;
+       listel->private_data = private_data;
        listel->callback = callback;
        listel->depth = depth;
        DLIST_ADD(notify->list, listel);
@@ -402,7 +403,7 @@ NTSTATUS notify_add(struct notify_context *notify, struct notify_entry *e0,
           then we need to install it in the array used for the
           intra-samba notify handling */
        if (e.filter != 0 || e.subdir_filter != 0) {
-               status = notify_add_array(notify, &e, private, depth);
+               status = notify_add_array(notify, &e, private_data, depth);
        }
 
 done:
@@ -415,7 +416,7 @@ done:
 /*
   remove a notify watch. Called when the directory handle is closed
 */
-NTSTATUS notify_remove(struct notify_context *notify, void *private)
+NTSTATUS notify_remove(struct notify_context *notify, void *private_data)
 {
        NTSTATUS status;
        struct notify_list *listel;
@@ -428,7 +429,7 @@ NTSTATUS notify_remove(struct notify_context *notify, void *private)
        }
 
        for (listel=notify->list;listel;listel=listel->next) {
-               if (listel->private == private) {
+               if (listel->private_data == private_data) {
                        DLIST_REMOVE(notify->list, listel);
                        break;
                }
@@ -459,7 +460,7 @@ NTSTATUS notify_remove(struct notify_context *notify, void *private)
        d = &notify->array->depth[depth];
 
        for (i=0;i<d->num_entries;i++) {
-               if (private == d->entries[i].private &&
+               if (private_data == d->entries[i].private_data &&
                    cluster_id_equal(&notify->server, &d->entries[i].server)) {
                        break;
                }
@@ -543,7 +544,7 @@ static void notify_send(struct notify_context *notify, struct notify_entry *e,
 
        ev.action = action;
        ev.path = path;
-       ev.private = e->private;
+       ev.private_data = e->private_data;
 
        tmp_ctx = talloc_new(notify);