* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-#include "tdb_validate.h"
#include "includes.h"
+#include "system/filesys.h"
+#include "util_tdb.h"
+#include "tdb_validate.h"
/*
* internal validation function, executed by the child.
goto out;
}
+ /*
+ * we can simplify this by passing a check function,
+ * but I don't want to change all the callers...
+ */
+ ret = tdb_check(tdb, NULL, NULL);
+ if (ret != 0) {
+ v_status.tdb_error = True;
+ v_status.success = False;
+ goto out;
+ }
+
/* Check if the tdb's freelist is good. */
if (tdb_validate_freelist(tdb, &num_entries) == -1) {
v_status.bad_freelist = True;
num_entries = tdb_traverse(tdb, validate_fn, (void *)&v_status);
if (!v_status.success) {
goto out;
- } else if (num_entries == -1) {
+ } else if (num_entries < 0) {
v_status.tdb_error = True;
v_status.success = False;
goto out;
* just let the child panic. we catch the signal. */
DEBUG(10, ("tdb_validate: forking to let child do validation.\n"));
- child_pid = sys_fork();
+ child_pid = fork();
if (child_pid == 0) {
/* child code */
DEBUG(10, ("tdb_validate (validation child): created\n"));
(unsigned int)child_pid));
DEBUG(10, ("tdb_validate: waiting for child to finish...\n"));
- while ((wait_pid = sys_waitpid(child_pid, &child_status, 0)) < 0) {
+ while ((wait_pid = waitpid(child_pid, &child_status, 0)) < 0) {
if (errno == EINTR) {
DEBUG(10, ("tdb_validate: got signal during waitpid, "
"retrying\n"));
DEBUG(5, ("tdb_validate_open called for tdb '%s'\n", tdb_path));
- tdb = tdb_open_log(tdb_path, 0, TDB_DEFAULT, O_RDONLY, 0);
+ tdb = tdb_open_log(tdb_path, 0, TDB_DEFAULT, O_RDWR, 0);
if (!tdb) {
DEBUG(1, ("Error opening tdb %s\n", tdb_path));
return ret;
}
tmp_path = talloc_asprintf(ctx, "%s%s", dst_path, ".tmp");
+ if (!tmp_path) {
+ DEBUG(3, ("talloc fail\n"));
+ goto done;
+ }
+
unlink(tmp_path);
- dst_tdb = tdb_open_log(tmp_path,
- hash_size ? hash_size : tdb_hash_size(src_tdb),
+
+ if (!hash_size) {
+ hash_size = tdb_hash_size(src_tdb);
+ }
+
+ dst_tdb = tdb_open_log(tmp_path, hash_size,
TDB_DEFAULT, O_RDWR | O_CREAT | O_EXCL,
st.st_mode & 0777);
if (dst_tdb == NULL) {
char *dst_path;
dst_path = talloc_asprintf(ctx, "%s%s", path, suffix);
+ if (dst_path == NULL) {
+ DEBUG(3, ("error out of memory\n"));
+ return ret;
+ }
ret = (rename(path, dst_path) != 0);
{
char *rotate_path = talloc_asprintf(ctx, "%s%s", dst_path,
rotate_suffix);
+ if (rotate_path == NULL) {
+ DEBUG(10, ("talloc fail\n"));
+ return -1;
+ }
DEBUG(10, ("backup of %s failed due to lack of space\n",
src_path));
DEBUGADD(10, ("trying to free some space by removing rotated "
}
tdb_path_backup = talloc_asprintf(ctx, "%s%s", tdb_path, backup_suffix);
+ if (!tdb_path_backup) {
+ DEBUG(0, ("tdb_validate_and_backup: out of memory\n"));
+ goto done;
+ }
ret = tdb_validate_open(tdb_path, validate_fn);