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__
28 * Flag field for keeping track of the status of a validation.
30 struct tdb_validation_status {
39 * Callback function type for the validation mechanism.
41 typedef int (*tdb_validate_data_func)(TDB_CONTEXT *the_tdb, TDB_DATA kbuf,
42 TDB_DATA dbuf, void *state);
45 * tdb validation function.
46 * returns 0 if tdb is ok, != 0 if it isn't.
47 * this function expects an opened tdb.
49 int tdb_validate(struct tdb_context *tdb,
50 tdb_validate_data_func validate_fn);
53 * tdb validation function.
54 * returns 0 if tdb is ok, != 0 if it isn't.
55 * This is a wrapper around the actual validation function that
56 * opens and closes the tdb.
58 int tdb_validate_open(const char *tdb_path,
59 tdb_validate_data_func validate_fn);
62 * validation function with backup handling:
64 * - calls tdb_validate
65 * - if the tdb is ok, create a backup "name.bak", possibly moving
66 * existing backup to name.bak.old,
67 * return 0 (success) even if the backup fails
68 * - if the tdb is corrupt:
69 * - move the tdb to "name.corrupt"
70 * - check if there is valid backup.
71 * if so, restore the backup.
72 * if restore is successful, return 0 (success),
73 * - otherwise return -1 (failure)
75 int tdb_validate_and_backup(const char *tdb_path,
76 tdb_validate_data_func validate_fn);
78 #endif /* __TDB_VALIDATE_H__ */