Unix SMB/CIFS implementation.
Samba internal messaging functions
Copyright (C) 2007 by Volker Lendecke
-
+
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 3 of the License, or
(at your option) any later version.
-
+
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
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, see <http://www.gnu.org/licenses/>.
*/
@defgroup messages Internal messaging framework
@{
@file messages.c
-
+
@brief Module for internal messaging between Samba daemons.
The idea is that if a part of Samba wants to do communication with
*/
#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(TALLOC_CTX *mem_ctx)
+{
+ struct tdb_wrap *db;
+
+ /*
+ * 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",
+ strerror(errno)));
+ return false;
+ }
+ return true;
+}
+
/*******************************************************************
Form a static tdb key from a pid.
******************************************************************/
key = talloc_asprintf(talloc_tos(), "PID/%s", procid_str_static(&pid));
SMB_ASSERT(key != NULL);
-
+
kbuf.dptr = (uint8 *)key;
kbuf.dsize = strlen(key)+1;
return kbuf;
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;
if (!NT_STATUS_IS_OK(status)) {
goto done;
}
-
+
status = message_notify(pid);
if (NT_STATUS_EQUAL(status, NT_STATUS_INVALID_HANDLE)) {
}
/****************************************************************************
- 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)));