r25068: Older samba3 DCs will return DCERPC_FAULT_OP_RNG_ERROR for every opcode on the
[Samba.git] / source / lib / messages_ctdbd.c
blob4ac9ea9904364ce5b6ba3f0192de73774a184ebd
1 /*
2 Unix SMB/CIFS implementation.
3 Samba internal messaging functions
4 Copyright (C) 2007 by Volker Lendecke
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 #include "includes.h"
23 #ifdef CLUSTER_SUPPORT
25 #include "librpc/gen_ndr/messaging.h"
27 struct messaging_ctdbd_context {
28 struct ctdbd_connection *conn;
32 * This is a Samba3 hack/optimization. Routines like process_exists need to
33 * talk to ctdbd, and they don't get handed a messaging context.
35 struct ctdbd_connection *global_ctdbd_connection;
37 struct ctdbd_connection *messaging_ctdbd_connection(void)
39 return global_ctdbd_connection;
42 static NTSTATUS messaging_ctdb_send(struct messaging_context *msg_ctx,
43 struct server_id pid, int msg_type,
44 const DATA_BLOB *data,
45 struct messaging_backend *backend)
47 struct messaging_ctdbd_context *ctx = talloc_get_type_abort(
48 backend->private_data, struct messaging_ctdbd_context);
50 struct messaging_rec msg;
52 msg.msg_version = MESSAGE_VERSION;
53 msg.msg_type = msg_type;
54 msg.dest = pid;
55 msg.src = procid_self();
56 msg.buf = *data;
58 return ctdbd_messaging_send(ctx->conn, pid.vnn, pid.pid, &msg);
61 static int messaging_ctdbd_destructor(struct messaging_ctdbd_context *ctx)
64 * The global connection just went away
66 global_ctdbd_connection = NULL;
67 return 0;
70 NTSTATUS messaging_ctdbd_init(struct messaging_context *msg_ctx,
71 TALLOC_CTX *mem_ctx,
72 struct messaging_backend **presult)
74 struct messaging_backend *result;
75 struct messaging_ctdbd_context *ctx;
76 NTSTATUS status;
78 if (!(result = TALLOC_P(mem_ctx, struct messaging_backend))) {
79 DEBUG(0, ("talloc failed\n"));
80 return NT_STATUS_NO_MEMORY;
83 if (!(ctx = TALLOC_P(result, struct messaging_ctdbd_context))) {
84 DEBUG(0, ("talloc failed\n"));
85 TALLOC_FREE(result);
86 return NT_STATUS_NO_MEMORY;
89 status = ctdbd_messaging_connection(ctx, &ctx->conn);
91 if (!NT_STATUS_IS_OK(status)) {
92 DEBUG(10, ("ctdbd_init_connection failed: %s\n",
93 nt_errstr(status)));
94 TALLOC_FREE(result);
95 return status;
98 global_ctdbd_connection = ctx->conn;
99 talloc_set_destructor(ctx, messaging_ctdbd_destructor);
101 set_my_vnn(ctdbd_vnn(ctx->conn));
103 result->send_fn = messaging_ctdb_send;
104 result->private_data = (void *)ctx;
106 *presult = result;
107 return NT_STATUS_OK;
110 #else
112 NTSTATUS messaging_ctdbd_init(struct messaging_context *msg_ctx,
113 TALLOC_CTX *mem_ctx,
114 struct messaging_backend **presult)
116 return NT_STATUS_NOT_IMPLEMENTED;
119 #endif