Fix last few includes to use new tdb location.
[ira/wip.git] / source4 / ntvfs / common / notify.c
index 0ee66a5a41d67737061f9d30a55f2a41d2299599..a35ef365b0225457a1ed0df22fadf617d8e2d326 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/>.
 */
 
 /*
 
 #include "includes.h"
 #include "system/filesys.h"
-#include "lib/tdb/include/tdb.h"
+#include "../tdb/include/tdb.h"
 #include "lib/util/util_tdb.h"
 #include "messaging/messaging.h"
-#include "db_wrap.h"
+#include "tdb_wrap.h"
 #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"
+#include "param/param.h"
 
 struct notify_context {
        struct tdb_wrap *w;
@@ -45,12 +45,13 @@ struct notify_context {
        struct notify_array *array;
        int seqnum;
        struct sys_notify_context *sys_notify_ctx;
+       struct smb_iconv_convenience *iconv_convenience;
 };
 
 
 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;
@@ -59,10 +60,10 @@ struct notify_list {
 #define NOTIFY_KEY "notify array"
 
 #define NOTIFY_ENABLE          "notify:enable"
-#define NOTIFY_ENABLE_DEFAULT  True
+#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);
 
 /*
@@ -82,13 +83,17 @@ static int notify_destructor(struct notify_context *notify)
 */
 struct notify_context *notify_init(TALLOC_CTX *mem_ctx, struct server_id server, 
                                   struct messaging_context *messaging_ctx,
+                                  struct loadparm_context *lp_ctx,
                                   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) {
+       if (share_bool_option(scfg, NOTIFY_ENABLE, NOTIFY_ENABLE_DEFAULT) != true) {
+               return NULL;
+       }
+
+       if (ev == NULL) {
                return NULL;
        }
 
@@ -97,11 +102,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, lp_ctx, "notify.tdb", TDB_SEQNUM);
        if (notify->w == NULL) {
                talloc_free(notify);
                return NULL;
@@ -111,6 +112,7 @@ struct notify_context *notify_init(TALLOC_CTX *mem_ctx, struct server_id server,
        notify->messaging_ctx = messaging_ctx;
        notify->list = NULL;
        notify->array = NULL;
+       notify->iconv_convenience = lp_iconv_convenience(lp_ctx);
        notify->seqnum = tdb_get_seqnum(notify->w->tdb);
 
        talloc_set_destructor(notify, notify_destructor);
@@ -152,7 +154,7 @@ static NTSTATUS notify_load(struct notify_context *notify)
 {
        TDB_DATA dbuf;
        DATA_BLOB blob;
-       NTSTATUS status;
+       enum ndr_err_code ndr_err;
        int seqnum;
 
        seqnum = tdb_get_seqnum(notify->w->tdb);
@@ -175,11 +177,15 @@ static NTSTATUS notify_load(struct notify_context *notify)
        blob.data = dbuf.dptr;
        blob.length = dbuf.dsize;
 
-       status = ndr_pull_struct_blob(&blob, notify->array, notify->array, 
-                                     (ndr_pull_flags_fn_t)ndr_pull_notify_array);
+       ndr_err = ndr_pull_struct_blob(&blob, notify->array, notify->iconv_convenience,
+                                      notify->array,
+                                      (ndr_pull_flags_fn_t)ndr_pull_notify_array);
        free(dbuf.dptr);
+       if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
+               return ndr_map_error2ntstatus(ndr_err);
+       }
 
-       return status;
+       return NT_STATUS_OK;
 }
 
 /*
@@ -198,7 +204,7 @@ static NTSTATUS notify_save(struct notify_context *notify)
 {
        TDB_DATA dbuf;
        DATA_BLOB blob;
-       NTSTATUS status;
+       enum ndr_err_code ndr_err;
        int ret;
        TALLOC_CTX *tmp_ctx;
 
@@ -218,12 +224,13 @@ 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);
-       if (!NT_STATUS_IS_OK(status)) {
+       ndr_err = ndr_push_struct_blob(&blob, tmp_ctx, notify->iconv_convenience, notify->array,
+                                      (ndr_push_flags_fn_t)ndr_push_notify_array);
+       if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
                talloc_free(tmp_ctx);
-               return status;
+               return ndr_map_error2ntstatus(ndr_err);
        }
 
        dbuf.dptr = blob.data;
@@ -242,25 +249,29 @@ 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);
-       NTSTATUS status;
+       struct notify_context *notify = talloc_get_type(private_data, struct notify_context);
+       enum ndr_err_code ndr_err;
        struct notify_event ev;
        TALLOC_CTX *tmp_ctx = talloc_new(notify);
        struct notify_list *listel;
 
-       status = ndr_pull_struct_blob(data, tmp_ctx, &ev, 
+       if (tmp_ctx == NULL) {
+               return;
+       }
+
+       ndr_err = ndr_pull_struct_blob(data, tmp_ctx, notify->iconv_convenience, &ev,
                                      (ndr_pull_flags_fn_t)ndr_pull_notify_event);
-       if (!NT_STATUS_IS_OK(status)) {
+       if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
                talloc_free(tmp_ctx);
                return;
        }
 
        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;
                }
        }
@@ -275,15 +286,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;
@@ -309,7 +320,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++;
@@ -339,7 +350,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;
@@ -380,7 +391,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);
@@ -404,7 +415,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:
@@ -417,7 +428,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;
@@ -430,7 +441,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;
                }
@@ -461,7 +472,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;
                }
@@ -541,17 +552,17 @@ static void notify_send(struct notify_context *notify, struct notify_entry *e,
        struct notify_event ev;
        DATA_BLOB data;
        NTSTATUS status;
+       enum ndr_err_code ndr_err;
        TALLOC_CTX *tmp_ctx;
 
        ev.action = action;
        ev.path = path;
-       ev.private = e->private;
+       ev.private_data = e->private_data;
 
        tmp_ctx = talloc_new(notify);
 
-       status = ndr_push_struct_blob(&data, tmp_ctx, &ev, 
-                                     (ndr_push_flags_fn_t)ndr_push_notify_event);
-       if (!NT_STATUS_IS_OK(status)) {
+       ndr_err = ndr_push_struct_blob(&data, tmp_ctx, notify->iconv_convenience, &ev, (ndr_push_flags_fn_t)ndr_push_notify_event);
+       if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
                talloc_free(tmp_ctx);
                return;
        }