r6573: Start on my project to implement an NT4 compatible BDC in Samba4.
[samba.git] / source / passdb / secrets.c
index 14e5642ae2d9953462da4cd8709a148a0120f8a8..7bc7183b982144bb7a18ab5ac0f7d0ad33dd6a6a 100644 (file)
    such as the local SID and machine trust password */
 
 #include "includes.h"
+#include "lib/tdb/include/tdbutil.h"
 #include "secrets.h"
+#include "system/filesys.h"
+#include "pstring.h"
+#include "db_wrap.h"
 
 #undef DBGC_CLASS
 #define DBGC_CLASS DBGC_PASSDB
@@ -135,7 +139,7 @@ BOOL secrets_named_mutex(const char *name, uint_t timeout, size_t *p_ref_count)
                return False;
 
        if (ref_count == 0) {
-               ret = tdb_lock_bystring(tdb->tdb, name, timeout);
+               ret = tdb_lock_bystring(tdb->tdb, name);
                if (ret == 0)
                        DEBUG(10,("secrets_named_mutex: got mutex for %s\n", name ));
        }
@@ -173,21 +177,32 @@ void secrets_named_mutex_release(const char *name, size_t *p_ref_count)
 /*
   connect to the schannel ldb
 */
-struct ldb_wrap *secrets_db_connect(TALLOC_CTX *mem_ctx)
+struct ldb_context *secrets_db_connect(TALLOC_CTX *mem_ctx)
 {
        char *path;
-       struct ldb_wrap *ldb;
+       struct ldb_context *ldb;
+       BOOL existed;
+       const char *init_ldif = 
+               "dn: @ATTRIBUTES\n" \
+               "computerName: CASE_INSENSITIVE\n" \
+               "flatname: CASE_INSENSITIVE\n";
 
        path = private_path(mem_ctx, "secrets.ldb");
        if (!path) {
                return NULL;
        }
        
+       existed = file_exists(path);
+       
        ldb = ldb_wrap_connect(mem_ctx, path, 0, NULL);
        talloc_free(path);
        if (!ldb) {
                return NULL;
        }
+       
+       if (!existed) {
+               gendb_add_ldif(ldb, init_ldif);
+       }
 
        return ldb;
 }