dbwrap: Use INCOMPATIBLE_HASH for dbwrap_watchers.tdb
[kai/samba.git] / source3 / lib / dbwrap / dbwrap_watch.c
index db0d376e3ca563aa68f4991067a0aac396013ef5..d8f1b74a42c7765537a9653c0e5be2fe88972938 100644 (file)
@@ -19,7 +19,7 @@
 
 #include "includes.h"
 #include "system/filesys.h"
-#include "dbwrap.h"
+#include "dbwrap/dbwrap.h"
 #include "dbwrap_watch.h"
 #include "dbwrap_open.h"
 #include "msg_channel.h"
@@ -31,9 +31,10 @@ static struct db_context *dbwrap_record_watchers_db(void)
        static struct db_context *watchers_db;
 
        if (watchers_db == NULL) {
-               watchers_db = db_open(NULL, lock_path("dbwrap_watchers.tdb"),
-                                     0, TDB_CLEAR_IF_FIRST, O_RDWR|O_CREAT,
-                                     0600, DBWRAP_LOCK_ORDER_3);
+               watchers_db = db_open(
+                       NULL, lock_path("dbwrap_watchers.tdb"), 0,
+                       TDB_CLEAR_IF_FIRST | TDB_INCOMPATIBLE_HASH,
+                       O_RDWR|O_CREAT, 0600, DBWRAP_LOCK_ORDER_3);
        }
        return watchers_db;
 }
@@ -119,12 +120,13 @@ static NTSTATUS dbwrap_record_add_watcher(TDB_DATA w_key, struct server_id id)
        ids = (struct server_id *)value.dptr;
        num_ids = value.dsize / sizeof(struct server_id);
 
-       ids = talloc_realloc(talloc_tos(), ids, struct server_id,
-                            num_ids + 1);
+       ids = talloc_array(talloc_tos(), struct server_id,
+                          num_ids + 1);
        if (ids == NULL) {
                status = NT_STATUS_NO_MEMORY;
                goto fail;
        }
+       memcpy(ids, value.dptr, value.dsize);
        ids[num_ids] = id;
        num_ids += 1;
 
@@ -166,7 +168,7 @@ static NTSTATUS dbwrap_record_del_watcher(TDB_DATA w_key, struct server_id id)
        num_ids = value.dsize / sizeof(struct server_id);
 
        for (i=0; i<num_ids; i++) {
-               if (procid_equal(&id, &ids[i])) {
+               if (serverid_equal(&id, &ids[i])) {
                        ids[i] = ids[num_ids-1];
                        value.dsize -= sizeof(struct server_id);
                        break;
@@ -318,6 +320,9 @@ static void dbwrap_watch_record_stored(struct db_context *db,
 
        status = dbwrap_record_get_watchers(db, rec, talloc_tos(),
                                            &ids, &num_ids);
+       if (NT_STATUS_EQUAL(status, NT_STATUS_NOT_FOUND)) {
+               goto done;
+       }
        if (!NT_STATUS_IS_OK(status)) {
                DEBUG(1, ("dbwrap_record_get_watchers failed: %s\n",
                          nt_errstr(status)));
@@ -397,7 +402,7 @@ NTSTATUS dbwrap_record_watch_recv(struct tevent_req *req,
                return status;
        }
        rec = dbwrap_fetch_locked(state->db, mem_ctx, state->key);
-       if (req == NULL) {
+       if (rec == NULL) {
                return NT_STATUS_INTERNAL_DB_ERROR;
        }
        *prec = rec;