r25068: Older samba3 DCs will return DCERPC_FAULT_OP_RNG_ERROR for every opcode on the
[Samba.git] / source / lib / dbwrap.c
blobc06cd4bb164587b19eafe0eec87acd6b1cf07d07
1 /*
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.
23 #include "includes.h"
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))) {
35 return -1;
38 data->dsize = rec->value.dsize;
39 data->dptr = talloc_move(mem_ctx, &rec->value.dptr);
40 TALLOC_FREE(rec);
41 return 0;
44 struct db_context *db_open(TALLOC_CTX *mem_ctx,
45 const char *name,
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()) {
54 const char *partname;
55 /* ctdb only wants the file part of the name */
56 partname = strrchr(name, '/');
57 if (partname) {
58 partname++;
59 } else {
60 partname = 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);
66 if (result == NULL) {
67 DEBUG(0,("failed to attach to ctdb %s\n",
68 partname));
69 smb_panic("failed to attach to a ctdb "
70 "database");
75 #endif
77 if (result == NULL) {
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;
86 return result;