132 lines
3.2 KiB
Diff
132 lines
3.2 KiB
Diff
From 49ce10425a046df243714f43924919720ea04784 Mon Sep 17 00:00:00 2001
|
|
From: Sumit Bose <sbose@redhat.com>
|
|
Date: Mon, 14 Feb 2011 16:56:02 +0100
|
|
Subject: [PATCH 7/8] Introduce sysdb_ldb_connect()
|
|
|
|
---
|
|
src/db/sysdb.c | 87 +++++++++++++++++++++++++++-----------------------------
|
|
1 files changed, 42 insertions(+), 45 deletions(-)
|
|
|
|
diff --git a/src/db/sysdb.c b/src/db/sysdb.c
|
|
index e20356157f76d72c79caca810b534f41940cd151..670b58727a8d795d8b837026ef78a94aaec0e174 100644
|
|
--- a/src/db/sysdb.c
|
|
+++ b/src/db/sysdb.c
|
|
@@ -25,6 +25,36 @@
|
|
#include "confdb/confdb.h"
|
|
#include <time.h>
|
|
|
|
+static errno_t sysdb_ldb_connect(TALLOC_CTX *mem_ctx, const char *filename,
|
|
+ struct ldb_context **_ldb)
|
|
+{
|
|
+ int ret;
|
|
+ struct ldb_context *ldb;
|
|
+
|
|
+ if (_ldb == NULL) {
|
|
+ return EINVAL;
|
|
+ }
|
|
+
|
|
+ ldb = ldb_init(mem_ctx, NULL);
|
|
+ if (!ldb) {
|
|
+ return EIO;
|
|
+ }
|
|
+
|
|
+ ret = ldb_set_debug(ldb, ldb_debug_messages, NULL);
|
|
+ if (ret != LDB_SUCCESS) {
|
|
+ return EIO;
|
|
+ }
|
|
+
|
|
+ ret = ldb_connect(ldb, filename, 0, NULL);
|
|
+ if (ret != LDB_SUCCESS) {
|
|
+ return EIO;
|
|
+ }
|
|
+
|
|
+ *_ldb = ldb;
|
|
+
|
|
+ return EOK;
|
|
+}
|
|
+
|
|
errno_t sysdb_dn_sanitize(void *mem_ctx, const char *input,
|
|
char **sanitized)
|
|
{
|
|
@@ -874,22 +904,10 @@ static int sysdb_check_upgrade_02(TALLOC_CTX *mem_ctx,
|
|
goto exit;
|
|
}
|
|
|
|
- ldb = ldb_init(tmp_ctx, NULL);
|
|
- if (!ldb) {
|
|
- ret = EIO;
|
|
- goto exit;
|
|
- }
|
|
-
|
|
- ret = ldb_set_debug(ldb, ldb_debug_messages, NULL);
|
|
- if (ret != LDB_SUCCESS) {
|
|
- ret = EIO;
|
|
- goto exit;
|
|
- }
|
|
-
|
|
- ret = ldb_connect(ldb, ldb_file, 0, NULL);
|
|
- if (ret != LDB_SUCCESS) {
|
|
- ret = EIO;
|
|
- goto exit;
|
|
+ ret = sysdb_ldb_connect(tmp_ctx, ldb_file, &ldb);
|
|
+ if (ret != EOK) {
|
|
+ DEBUG(1, ("sysdb_ldb_connect failed.\n"));
|
|
+ return ret;
|
|
}
|
|
|
|
verdn = ldb_dn_new(tmp_ctx, ldb, "cn=sysdb");
|
|
@@ -975,22 +993,10 @@ static int sysdb_check_upgrade_02(TALLOC_CTX *mem_ctx,
|
|
}
|
|
|
|
/* reopen */
|
|
- ldb = ldb_init(tmp_ctx, NULL);
|
|
- if (!ldb) {
|
|
- ret = EIO;
|
|
- goto exit;
|
|
- }
|
|
-
|
|
- ret = ldb_set_debug(ldb, ldb_debug_messages, NULL);
|
|
- if (ret != LDB_SUCCESS) {
|
|
- ret = EIO;
|
|
- goto exit;
|
|
- }
|
|
-
|
|
- ret = ldb_connect(ldb, ldb_file, 0, NULL);
|
|
- if (ret != LDB_SUCCESS) {
|
|
- ret = EIO;
|
|
- goto exit;
|
|
+ ret = sysdb_ldb_connect(tmp_ctx, ldb_file, &ldb);
|
|
+ if (ret != EOK) {
|
|
+ DEBUG(1, ("sysdb_ldb_connect failed.\n"));
|
|
+ return ret;
|
|
}
|
|
|
|
/* open a transaction */
|
|
@@ -1438,19 +1444,10 @@ static int sysdb_domain_init_internal(TALLOC_CTX *mem_ctx,
|
|
}
|
|
DEBUG(5, ("DB File for %s: %s\n", domain->name, ctx->ldb_file));
|
|
|
|
- ctx->ldb = ldb_init(ctx, NULL);
|
|
- if (!ctx->ldb) {
|
|
- return EIO;
|
|
- }
|
|
-
|
|
- ret = ldb_set_debug(ctx->ldb, ldb_debug_messages, NULL);
|
|
- if (ret != LDB_SUCCESS) {
|
|
- return EIO;
|
|
- }
|
|
-
|
|
- ret = ldb_connect(ctx->ldb, ctx->ldb_file, 0, NULL);
|
|
- if (ret != LDB_SUCCESS) {
|
|
- return EIO;
|
|
+ ret = sysdb_ldb_connect(ctx, ctx->ldb_file, &ctx->ldb);
|
|
+ if (ret != EOK) {
|
|
+ DEBUG(1, ("sysdb_ldb_connect failed.\n"));
|
|
+ return ret;
|
|
}
|
|
|
|
tmp_ctx = talloc_new(ctx);
|
|
--
|
|
1.7.4
|
|
|