wscript: Add check for --wrap linker flag
[vlendec/samba-autobuild/.git] / source3 / lib / tdb_validate.c
index 092546e3eb53b6df077f8286c7f3e962bc0f72b4..9db182fb0b3ceb4377bd6f43cddb390183befb67 100644 (file)
  * 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.
@@ -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"));
@@ -122,7 +135,7 @@ int tdb_validate(struct tdb_context *tdb, tdb_validate_data_func validate_fn)
                (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"));
@@ -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);