summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--source4/auth/gensec/schannel_state.c11
-rw-r--r--source4/lib/gendb.c13
-rw-r--r--source4/lib/util_file.c9
3 files changed, 33 insertions, 0 deletions
diff --git a/source4/auth/gensec/schannel_state.c b/source4/auth/gensec/schannel_state.c
index b2d632a1f0..dea204e622 100644
--- a/source4/auth/gensec/schannel_state.c
+++ b/source4/auth/gensec/schannel_state.c
@@ -36,17 +36,28 @@ static struct ldb_context *schannel_db_connect(TALLOC_CTX *mem_ctx)
{
char *path;
struct ldb_context *ldb;
+ BOOL existed;
+ const char *init_ldif =
+ "dn: @ATTRIBUTES\n" \
+ "computerName: CASE_INSENSITIVE\n" \
+ "flatname: CASE_INSENSITIVE\n";
path = smbd_tmp_path(mem_ctx, "schannel.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;
}
diff --git a/source4/lib/gendb.c b/source4/lib/gendb.c
index befdd63c9e..5b4f7b251e 100644
--- a/source4/lib/gendb.c
+++ b/source4/lib/gendb.c
@@ -78,3 +78,16 @@ int gendb_search(struct ldb_context *sam_ldb,
return count;
}
+/*
+ setup some initial ldif in a ldb
+*/
+int gendb_add_ldif(struct ldb_context *ldb, const char *ldif_string)
+{
+ struct ldb_ldif *ldif;
+ int ret;
+ ldif = ldb_ldif_read_string(ldb, ldif_string);
+ if (ldif == NULL) return -1;
+ ret = ldb_add(ldb, ldif->msg);
+ talloc_free(ldif);
+ return ret;
+}
diff --git a/source4/lib/util_file.c b/source4/lib/util_file.c
index 6d234b571c..e02198754d 100644
--- a/source4/lib/util_file.c
+++ b/source4/lib/util_file.c
@@ -386,3 +386,12 @@ BOOL file_save(const char *fname, void *packet, size_t length)
close(fd);
return True;
}
+
+/*
+ see if a file exists
+*/
+BOOL file_exists(const char *path)
+{
+ struct stat st;
+ return (stat(path, &st) == 0);
+}