0e59321f64f68f9edc1e6ca0edaa71152d1f04f6
[obnox/samba/samba-obnox.git] / source4 / cluster / local.c
1 /* 
2    Unix SMB/CIFS implementation.
3
4    local (dummy) clustering operations
5
6    Copyright (C) Andrew Tridgell 2006
7    
8    This program is free software; you can redistribute it and/or modify
9    it under the terms of the GNU General Public License as published by
10    the Free Software Foundation; either version 3 of the License, or
11    (at your option) any later version.
12    
13    This program is distributed in the hope that it will be useful,
14    but WITHOUT ANY WARRANTY; without even the implied warranty of
15    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16    GNU General Public License for more details.
17    
18    You should have received a copy of the GNU General Public License
19    along with this program.  If not, see <http://www.gnu.org/licenses/>.
20 */
21
22 #include "includes.h"
23 #include "cluster/cluster.h"
24 #include "cluster/cluster_private.h"
25 #include "lib/tdb_wrap/tdb_wrap.h"
26 #include "system/filesys.h"
27 #include "param/param.h"
28 #include "librpc/gen_ndr/server_id.h"
29
30 /*
31   server a server_id for the local node
32 */
33 static struct server_id local_id(struct cluster_ops *ops, uint64_t pid, uint32_t task_id)
34 {
35         struct server_id server_id;
36         ZERO_STRUCT(server_id);
37         server_id.pid = pid;
38         server_id.task_id = task_id;
39         server_id.vnn = NONCLUSTER_VNN;
40         /* This is because we are not in the s3 serverid database */
41         server_id.unique_id = SERVERID_UNIQUE_ID_NOT_TO_VERIFY;
42         return server_id;
43 }
44
45
46 /*
47   open a tmp tdb for the local node. By using smbd_tmp_path() we don't need
48   TDB_CLEAR_IF_FIRST as the tmp path is wiped at startup
49 */
50 static struct tdb_wrap *local_tdb_tmp_open(struct cluster_ops *ops,
51                                            TALLOC_CTX *mem_ctx, 
52                                            struct loadparm_context *lp_ctx,
53                                            const char *dbname, int flags)
54 {
55         char *path = smbd_tmp_path(mem_ctx, lp_ctx, dbname);
56         struct tdb_wrap *w;
57         w = tdb_wrap_open(mem_ctx, path, 0, flags,
58                           O_RDWR|O_CREAT, 0600, lp_ctx);
59         talloc_free(path);
60         return w;
61 }
62
63 /*
64   dummy backend handle function
65 */
66 static void *local_backend_handle(struct cluster_ops *ops)
67 {
68         return NULL;
69 }
70
71 /*
72   dummy message init function - not needed as all messages are local
73 */
74 static NTSTATUS local_message_init(struct cluster_ops *ops,
75                                    struct imessaging_context *msg,
76                                    struct server_id server,
77                                    cluster_message_fn_t handler)
78 {
79         return NT_STATUS_OK;
80 }
81
82 /*
83   dummy message send
84 */
85 static NTSTATUS local_message_send(struct cluster_ops *ops,
86                                    struct server_id server, DATA_BLOB *data)
87 {
88         return NT_STATUS_INVALID_DEVICE_REQUEST;
89 }
90
91 static struct cluster_ops cluster_local_ops = {
92         .cluster_id           = local_id,
93         .cluster_tdb_tmp_open = local_tdb_tmp_open,
94         .backend_handle       = local_backend_handle,
95         .message_init         = local_message_init,
96         .message_send         = local_message_send,
97         .private_data         = NULL
98 };
99
100 void cluster_local_init(void)
101 {
102         cluster_set_ops(&cluster_local_ops);
103 }
104