*/
#include "includes.h"
-#include "librpc/gen_ndr/messaging.h"
-#include "librpc/gen_ndr/ndr_messaging.h"
+#include "system/filesys.h"
+#include "messages.h"
+#include "lib/util/tdb_wrap.h"
struct messaging_tdb_context {
struct messaging_context *msg_ctx;
struct messaging_backend *result;
struct messaging_tdb_context *ctx;
- if (!(result = TALLOC_P(mem_ctx, struct messaging_backend))) {
+ if (!(result = talloc(mem_ctx, struct messaging_backend))) {
DEBUG(0, ("talloc failed\n"));
return NT_STATUS_NO_MEMORY;
}
- ctx = TALLOC_ZERO_P(result, struct messaging_tdb_context);
+ ctx = talloc_zero(result, struct messaging_tdb_context);
if (!ctx) {
DEBUG(0, ("talloc failed\n"));
TALLOC_FREE(result);
ctx->msg_ctx = msg_ctx;
ctx->tdb = tdb_wrap_open(ctx, lock_path("messages.tdb"), 0,
- TDB_CLEAR_IF_FIRST|TDB_DEFAULT|TDB_VOLATILE,
+ TDB_CLEAR_IF_FIRST|TDB_DEFAULT|TDB_VOLATILE|TDB_INCOMPATIBLE_HASH,
O_RDWR|O_CREAT,0600);
if (!ctx->tdb) {
NTSTATUS status = map_nt_error_from_unix(errno);
- DEBUG(0, ("ERROR: Failed to initialise messages database: "
+ DEBUG(2, ("ERROR: Failed to initialise messages database: "
"%s\n", strerror(errno)));
TALLOC_FREE(result);
return status;
return NT_STATUS_OK;
}
-bool messaging_tdb_parent_init(void)
+bool messaging_tdb_parent_init(TALLOC_CTX *mem_ctx)
{
struct tdb_wrap *db;
- db = tdb_wrap_open(talloc_autofree_context(),
- lock_path("messages.tdb"), 0,
- TDB_CLEAR_IF_FIRST|TDB_DEFAULT|TDB_VOLATILE,
+ /*
+ * Open the tdb in the parent process (smbd) so that our
+ * CLEAR_IF_FIRST optimization in tdb_reopen_all can properly
+ * work.
+ */
+
+ db = tdb_wrap_open(mem_ctx, lock_path("messages.tdb"), 0,
+ TDB_CLEAR_IF_FIRST|TDB_DEFAULT|TDB_VOLATILE|TDB_INCOMPATIBLE_HASH,
O_RDWR|O_CREAT,0600);
if (db == NULL) {
DEBUG(1, ("could not open messaging.tdb: %s\n",
DATA_BLOB blob;
enum ndr_err_code ndr_err;
- if (!(result = TALLOC_ZERO_P(mem_ctx, struct messaging_array))) {
+ if (!(result = talloc_zero(mem_ctx, struct messaging_array))) {
return NT_STATUS_NO_MEMORY;
}
blob = data_blob_const(data.dptr, data.dsize);
ndr_err = ndr_pull_struct_blob(
- &blob, result, NULL, result,
+ &blob, result, result,
(ndr_pull_flags_fn_t)ndr_pull_messaging_array);
SAFE_FREE(data.dptr);
return NT_STATUS_NO_MEMORY;
}
- ndr_err = ndr_push_struct_blob(
- &blob, mem_ctx, NULL, array,
+ ndr_err = ndr_push_struct_blob(&blob, mem_ctx, array,
(ndr_push_flags_fn_t)ndr_push_messaging_array);
if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
goto done;
}
- if (!(rec = TALLOC_REALLOC_ARRAY(talloc_tos(), msg_array->messages,
+ if (!(rec = talloc_realloc(talloc_tos(), msg_array->messages,
struct messaging_rec,
msg_array->num_messages+1))) {
status = NT_STATUS_NO_MEMORY;
rec[msg_array->num_messages].msg_version = MESSAGE_VERSION;
rec[msg_array->num_messages].msg_type = msg_type & MSG_TYPE_MASK;
rec[msg_array->num_messages].dest = pid;
- rec[msg_array->num_messages].src = procid_self();
+ rec[msg_array->num_messages].src = msg_ctx->id;
rec[msg_array->num_messages].buf = *data;
msg_array->messages = rec;
}
/****************************************************************************
- Retrieve all messages for the current process.
+ Retrieve all messages for a process.
****************************************************************************/
static NTSTATUS retrieve_all_messages(TDB_CONTEXT *msg_tdb,
+ struct server_id id,
TALLOC_CTX *mem_ctx,
struct messaging_array **presult)
{
struct messaging_array *result;
- TDB_DATA key = message_key_pid(mem_ctx, procid_self());
+ TDB_DATA key = message_key_pid(mem_ctx, id);
NTSTATUS status;
if (tdb_chainlock(msg_tdb, key) == -1) {
DEBUG(10, ("message_dispatch: received_messages = %d\n",
ctx->received_messages));
- status = retrieve_all_messages(tdb->tdb, NULL, &msg_array);
+ status = retrieve_all_messages(tdb->tdb, msg_ctx->id, NULL, &msg_array);
if (!NT_STATUS_IS_OK(status)) {
DEBUG(0, ("message_dispatch: failed to retrieve messages: %s\n",
nt_errstr(status)));