Fix debug statements to use correct function name.
[Samba/fernandojvsilva.git] / source3 / lib / tdb_validate.h
blob9eda79d7db1eecd8d2ae3704c2e3868295461943
1 /*
2 * Unix SMB/CIFS implementation.
4 * A general tdb content validation mechanism
6 * Copyright (C) Michael Adam 2007
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 #ifndef __TDB_VALIDATE_H__
23 #define __TDB_VALIDATE_H__
25 #include "lib/replace/replace.h"
26 #include "tdb.h"
28 /**
29 * Flag field for keeping track of the status of a validation.
31 struct tdb_validation_status {
32 bool tdb_error;
33 bool bad_freelist;
34 bool bad_entry;
35 bool unknown_key;
36 bool success;
39 /**
40 * Callback function type for the validation mechanism.
42 typedef int (*tdb_validate_data_func)(TDB_CONTEXT *the_tdb, TDB_DATA kbuf,
43 TDB_DATA dbuf, void *state);
45 /**
46 * tdb validation function.
47 * returns 0 if tdb is ok, != 0 if it isn't.
48 * this function expects an opened tdb.
50 int tdb_validate(struct tdb_context *tdb,
51 tdb_validate_data_func validate_fn);
53 /**
54 * tdb validation function.
55 * returns 0 if tdb is ok, != 0 if it isn't.
56 * This is a wrapper around the actual validation function that
57 * opens and closes the tdb.
59 int tdb_validate_open(const char *tdb_path,
60 tdb_validate_data_func validate_fn);
62 /**
63 * validation function with backup handling:
65 * - calls tdb_validate
66 * - if the tdb is ok, create a backup "name.bak", possibly moving
67 * existing backup to name.bak.old,
68 * return 0 (success) even if the backup fails
69 * - if the tdb is corrupt:
70 * - move the tdb to "name.corrupt"
71 * - check if there is valid backup.
72 * if so, restore the backup.
73 * if restore is successful, return 0 (success),
74 * - otherwise return -1 (failure)
76 int tdb_validate_and_backup(const char *tdb_path,
77 tdb_validate_data_func validate_fn);
79 #endif /* __TDB_VALIDATE_H__ */