s4-kcc: correctly populate the neighbor object when taking information from repsTo
[Samba/gebeck_regimport.git] / source3 / lib / dbwrap / dbwrap.c
blob6a6d4c64e5732b666cc819d6e3677e55278c96eb
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 3 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, see <http://www.gnu.org/licenses/>.
22 #include "includes.h"
23 #include "dbwrap/dbwrap.h"
24 #include "dbwrap/dbwrap_private.h"
27 * Fall back using fetch_locked if no genuine fetch operation is provided
30 int dbwrap_fallback_fetch(struct db_context *db, TALLOC_CTX *mem_ctx,
31 TDB_DATA key, TDB_DATA *data)
33 struct db_record *rec;
35 if (!(rec = db->fetch_locked(db, mem_ctx, key))) {
36 return -1;
39 data->dsize = rec->value.dsize;
40 data->dptr = talloc_move(mem_ctx, &rec->value.dptr);
41 TALLOC_FREE(rec);
42 return 0;
46 * Fall back using fetch if no genuine parse operation is provided
49 int dbwrap_fallback_parse_record(struct db_context *db, TDB_DATA key,
50 int (*parser)(TDB_DATA key,
51 TDB_DATA data,
52 void *private_data),
53 void *private_data)
55 TDB_DATA data;
56 int res;
58 res = db->fetch(db, talloc_tos(), key, &data);
59 if (res != 0) {
60 return res;
63 res = parser(key, data, private_data);
64 TALLOC_FREE(data.dptr);
65 return res;