summaryrefslogtreecommitdiff
path: root/source3/lib/tdb_validate.h
diff options
context:
space:
mode:
authorMichael Adam <obnox@samba.org>2009-01-28 08:52:53 +0100
committerMichael Adam <obnox@samba.org>2009-01-28 09:43:57 +0100
commit59859b547c81bf398d12a1f9b206a32c6fd55433 (patch)
tree649812afff406de30a836a2d13a12a5f992cc434 /source3/lib/tdb_validate.h
parentca3a801a82729b4a8d9db067a0a2838b1e0fee81 (diff)
downloadsamba-59859b547c81bf398d12a1f9b206a32c6fd55433.tar.gz
samba-59859b547c81bf398d12a1f9b206a32c6fd55433.tar.bz2
samba-59859b547c81bf398d12a1f9b206a32c6fd55433.zip
s3: separate tdb validation code out into its own source file
So this gets now linked only into its single user: winbindd (needed by winbindd_cache.c) Michael
Diffstat (limited to 'source3/lib/tdb_validate.h')
-rw-r--r--source3/lib/tdb_validate.h78
1 files changed, 78 insertions, 0 deletions
diff --git a/source3/lib/tdb_validate.h b/source3/lib/tdb_validate.h
new file mode 100644
index 0000000000..1a207fa669
--- /dev/null
+++ b/source3/lib/tdb_validate.h
@@ -0,0 +1,78 @@
+/*
+ * Unix SMB/CIFS implementation.
+ *
+ * A general tdb content validation mechanism
+ *
+ * Copyright (C) Michael Adam 2007
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef __TDB_VALIDATE_H__
+#define __TDB_VALIDATE_H__
+
+#include "includes.h"
+
+/**
+ * Flag field for keeping track of the status of a validation.
+ */
+struct tdb_validation_status {
+ bool tdb_error;
+ bool bad_freelist;
+ bool bad_entry;
+ bool unknown_key;
+ bool success;
+};
+
+/**
+ * Callback function type for the validation mechanism.
+ */
+typedef int (*tdb_validate_data_func)(TDB_CONTEXT *the_tdb, TDB_DATA kbuf,
+ TDB_DATA dbuf, void *state);
+
+/**
+ * tdb validation function.
+ * returns 0 if tdb is ok, != 0 if it isn't.
+ * this function expects an opened tdb.
+ */
+int tdb_validate(struct tdb_context *tdb,
+ tdb_validate_data_func validate_fn);
+
+/**
+ * tdb validation function.
+ * returns 0 if tdb is ok, != 0 if it isn't.
+ * This is a wrapper around the actual validation function that
+ * opens and closes the tdb.
+ */
+int tdb_validate_open(const char *tdb_path,
+ tdb_validate_data_func validate_fn);
+
+/**
+ * validation function with backup handling:
+ *
+ * - calls tdb_validate
+ * - if the tdb is ok, create a backup "name.bak", possibly moving
+ * existing backup to name.bak.old,
+ * return 0 (success) even if the backup fails
+ * - if the tdb is corrupt:
+ * - move the tdb to "name.corrupt"
+ * - check if there is valid backup.
+ * if so, restore the backup.
+ * if restore is successful, return 0 (success),
+ * - otherwise return -1 (failure)
+ */
+int tdb_validate_and_backup(const char *tdb_path,
+ tdb_validate_data_func validate_fn);
+
+#endif /* __TDB_VALIDATE_H__ */