Fix include paths to new location of libutil.
[bbaumbach/samba-autobuild/.git] / source4 / ntvfs / common / notify.c
index 0d36a20a60c56c7477af6a29428e50e77ad7d270..dbe4722d37e487ac0d4720613308156dd766607e 100644 (file)
 
 #include "includes.h"
 #include "system/filesys.h"
-#include "lib/tdb/include/tdb.h"
-#include "lib/util/util_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 "../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;
@@ -44,6 +45,7 @@ struct notify_context {
        struct notify_array *array;
        int seqnum;
        struct sys_notify_context *sys_notify_ctx;
+       struct smb_iconv_convenience *iconv_convenience;
 };
 
 
@@ -58,7 +60,7 @@ 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_data, 
@@ -81,12 +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)
 {
        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;
        }
 
@@ -95,7 +102,7 @@ struct notify_context *notify_init(TALLOC_CTX *mem_ctx, struct server_id server,
                return NULL;
        }
 
-       notify->w = cluster_tdb_tmp_open(notify, "notify.tdb", TDB_SEQNUM);
+       notify->w = cluster_tdb_tmp_open(notify, lp_ctx, "notify.tdb", TDB_SEQNUM);
        if (notify->w == NULL) {
                talloc_free(notify);
                return NULL;
@@ -105,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);
@@ -146,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);
@@ -169,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;
 }
 
 /*
@@ -192,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;
 
@@ -214,11 +226,11 @@ 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;
@@ -241,7 +253,7 @@ 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_data, struct notify_context);
-       NTSTATUS status;
+       enum ndr_err_code ndr_err;
        struct notify_event ev;
        TALLOC_CTX *tmp_ctx = talloc_new(notify);
        struct notify_list *listel;
@@ -250,9 +262,9 @@ static void notify_handler(struct messaging_context *msg_ctx, void *private_data
                return;
        }
 
-       status = ndr_pull_struct_blob(data, tmp_ctx, &ev, 
+       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;
        }
@@ -540,6 +552,7 @@ 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;
@@ -548,9 +561,8 @@ static void notify_send(struct notify_context *notify, struct notify_entry *e,
 
        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;
        }