s4-dsdb: Check if metadata.tdb exists, before trying to open it
authorAmitay Isaacs <amitay@gmail.com>
Mon, 13 Feb 2012 00:07:06 +0000 (11:07 +1100)
committerAmitay Isaacs <amitay@samba.org>
Mon, 13 Feb 2012 02:02:09 +0000 (03:02 +0100)
This fixes the error output from tdb2 when metadata module tries
to create metadata.tdb first time. This error is reported since
metadata module tries to check if tdb exists by trying to open
tdb file.

Autobuild-User: Amitay Isaacs <amitay@samba.org>
Autobuild-Date: Mon Feb 13 03:02:09 CET 2012 on sn-devel-104

source4/dsdb/samdb/ldb_modules/partition_metadata.c

index acf414b1c2442b38e92ccb0082c184e80104fe66..e3f0fb5c0168e0c685252d173322fb9738a52849 100644 (file)
@@ -152,6 +152,7 @@ static int partition_metadata_open(struct ldb_module *module, bool create)
        const char *sam_name;
        char *filename, *dirname;
        int open_flags;
+       struct stat statbuf;
 
        data = talloc_get_type_abort(ldb_module_get_private(module),
                                     struct partition_private_data);
@@ -193,6 +194,11 @@ static int partition_metadata_open(struct ldb_module *module, bool create)
 
                mkdir(dirname, 0700);
                talloc_free(dirname);
+       } else {
+               if (stat(filename, &statbuf) != 0) {
+                       talloc_free(tmp_ctx);
+                       return LDB_ERR_OPERATIONS_ERROR;
+               }
        }
 
        lp_ctx = talloc_get_type_abort(ldb_get_opaque(ldb, "loadparm"),