1/* 2 * Unix SMB/CIFS implementation. 3 * 4 * A general tdb content validation mechanism 5 * 6 * Copyright (C) Michael Adam 2007 7 * 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. 12 * 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. 17 * 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/>. 20 */ 21 22#ifndef __TDB_VALIDATE_H__ 23#define __TDB_VALIDATE_H__ 24 25#include "lib/replace/replace.h" 26#include "tdb.h" 27 28/** 29 * Flag field for keeping track of the status of a validation. 30 */ 31struct tdb_validation_status { 32 bool tdb_error; 33 bool bad_freelist; 34 bool bad_entry; 35 bool unknown_key; 36 bool success; 37}; 38 39/** 40 * Callback function type for the validation mechanism. 41 */ 42typedef int (*tdb_validate_data_func)(TDB_CONTEXT *the_tdb, TDB_DATA kbuf, 43 TDB_DATA dbuf, void *state); 44 45/** 46 * tdb validation function. 47 * returns 0 if tdb is ok, != 0 if it isn't. 48 * this function expects an opened tdb. 49 */ 50int tdb_validate(struct tdb_context *tdb, 51 tdb_validate_data_func validate_fn); 52 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. 58 */ 59int tdb_validate_open(const char *tdb_path, 60 tdb_validate_data_func validate_fn); 61 62/** 63 * validation function with backup handling: 64 * 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) 75 */ 76int tdb_validate_and_backup(const char *tdb_path, 77 tdb_validate_data_func validate_fn); 78 79#endif /* __TDB_VALIDATE_H__ */ 80