Merge branch 'master' of ssh://git.samba.org/data/git/samba into noejs
[sfrench/samba-autobuild/.git] / source4 / lib / messaging / messaging.c
index 6a879ab962774f8008af09b56aea34b949042b37..2125ba1fe6b88803a31bdf5978ad59d97218579c 100644 (file)
@@ -30,8 +30,7 @@
 #include "tdb_wrap.h"
 #include "lib/util/unix_privs.h"
 #include "librpc/rpc/dcerpc.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 "cluster/cluster.h"
 #include "param/param.h"
@@ -462,6 +461,8 @@ NTSTATUS messaging_send(struct messaging_context *msg, struct server_id server,
        rec->retries       = 0;
        rec->msg              = msg;
        rec->header           = (struct messaging_header *)rec->packet.data;
+       /* zero padding */
+       ZERO_STRUCTP(rec->header);
        rec->header->version  = MESSAGING_VERSION;
        rec->header->msg_type = msg_type;
        rec->header->from     = msg->server_id;
@@ -542,6 +543,10 @@ struct messaging_context *messaging_init(TALLOC_CTX *mem_ctx,
        NTSTATUS status;
        struct socket_address *path;
 
+       if (ev == NULL) {
+               return NULL;
+       }
+
        msg = talloc_zero(mem_ctx, struct messaging_context);
        if (msg == NULL) {
                return NULL;
@@ -554,10 +559,6 @@ struct messaging_context *messaging_init(TALLOC_CTX *mem_ctx,
                return NULL;
        }
 
-       if (ev == NULL) {
-               ev = event_context_init(msg);
-       }
-
        /* create the messaging directory if needed */
        mkdir(dir, 0700);
 
@@ -1083,8 +1084,14 @@ void irpc_remove_name(struct messaging_context *msg_ctx, const char *name)
                return;
        }
        rec = tdb_fetch_bystring(t->tdb, name);
+       if (rec.dptr == NULL) {
+               tdb_unlock_bystring(t->tdb, name);
+               talloc_free(t);
+               return;
+       }
        count = rec.dsize / sizeof(struct server_id);
        if (count == 0) {
+               free(rec.dptr);
                tdb_unlock_bystring(t->tdb, name);
                talloc_free(t);
                return;
@@ -1105,3 +1112,8 @@ void irpc_remove_name(struct messaging_context *msg_ctx, const char *name)
        tdb_unlock_bystring(t->tdb, name);
        talloc_free(t);
 }
+
+struct server_id messaging_get_server_id(struct messaging_context *msg_ctx)
+{
+       return msg_ctx->server_id;
+}