2 Unix SMB/CIFS implementation.
3 Database interface wrapper
4 Copyright (C) Jim McDonough <jmcd@us.ibm.com> 2006
6 Major code contributions from Aleksey Fedoseev (fedoseev@ru.ibm.com)
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 2 of the License, or
11 (at your option) any later version.
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.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
26 * Fall back using fetch_locked if no genuine fetch operation is provided
29 static int dbwrap_fallback_fetch(struct db_context
*db
, TALLOC_CTX
*mem_ctx
,
30 TDB_DATA key
, TDB_DATA
*data
)
32 struct db_record
*rec
;
34 if (!(rec
= db
->fetch_locked(db
, mem_ctx
, key
))) {
38 data
->dsize
= rec
->value
.dsize
;
39 data
->dptr
= talloc_move(mem_ctx
, &rec
->value
.dptr
);
44 struct db_context
*db_open(TALLOC_CTX
*mem_ctx
,
46 int hash_size
, int tdb_flags
,
47 int open_flags
, mode_t mode
)
49 struct db_context
*result
= NULL
;
51 #ifdef CLUSTER_SUPPORT
53 if (lp_clustering()) {
55 /* ctdb only wants the file part of the name */
56 partname
= strrchr(name
, '/');
62 /* allow ctdb for individual databases to be disabled */
63 if (lp_parm_bool(-1, "ctdb", partname
, True
)) {
64 result
= db_open_ctdb(mem_ctx
, partname
, hash_size
,
65 tdb_flags
, open_flags
, mode
);
67 DEBUG(0,("failed to attach to ctdb %s\n",
69 smb_panic("failed to attach to a ctdb "
78 result
= db_open_tdb(mem_ctx
, name
, hash_size
,
79 tdb_flags
, open_flags
, mode
);
82 if ((result
!= NULL
) && (result
->fetch
== NULL
)) {
83 result
->fetch
= dbwrap_fallback_fetch
;