X-Git-Url: http://git.samba.org/samba.git/?a=blobdiff_plain;f=source3%2Flib%2Ftdb_validate.c;h=2592402afd8b7b3e13eaabe41f661c2733c99f6c;hb=92ca4f52ae093e14d39b8853a34ffa8be6a3d492;hp=092546e3eb53b6df077f8286c7f3e962bc0f72b4;hpb=3a1b4c00eb96634229fb730e9b38e8df5180756a;p=sfrench%2Fsamba-autobuild%2F.git diff --git a/source3/lib/tdb_validate.c b/source3/lib/tdb_validate.c index 092546e3eb5..2592402afd8 100644 --- a/source3/lib/tdb_validate.c +++ b/source3/lib/tdb_validate.c @@ -19,8 +19,10 @@ * along with this program. If not, see . */ -#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. @@ -44,6 +46,17 @@ static int tdb_validate_child(struct tdb_context *tdb, 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; @@ -58,7 +71,7 @@ static int tdb_validate_child(struct tdb_context *tdb, 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; @@ -103,7 +116,7 @@ int tdb_validate(struct tdb_context *tdb, tdb_validate_data_func validate_fn) * 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")); @@ -181,7 +194,7 @@ int tdb_validate_open(const char *tdb_path, tdb_validate_data_func validate_fn) 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; @@ -270,9 +283,18 @@ static int tdb_backup(TALLOC_CTX *ctx, const char *src_path, } 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) { @@ -344,6 +366,10 @@ static int rename_file_with_suffix(TALLOC_CTX *ctx, const char *path, 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); @@ -383,6 +409,10 @@ static int tdb_backup_with_rotate(TALLOC_CTX *ctx, const char *src_path, { 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 " @@ -439,6 +469,10 @@ int tdb_validate_and_backup(const char *tdb_path, } 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);