summaryrefslogtreecommitdiffstats
path: root/src/db
diff options
context:
space:
mode:
authorSumit Bose <sbose@redhat.com>2011-02-14 16:56:02 +0100
committerStephen Gallagher <sgallagh@redhat.com>2011-02-14 11:51:42 -0500
commit29dfae2a89551026f861f1f857187c22e30730c9 (patch)
treea2c931aae6e742b3534c045ae55c9d3f34646c3b /src/db
parent66e691ceeee4cca739fc2606f1b357bbff4a3440 (diff)
downloadsssd-29dfae2a89551026f861f1f857187c22e30730c9.tar.gz
sssd-29dfae2a89551026f861f1f857187c22e30730c9.tar.xz
sssd-29dfae2a89551026f861f1f857187c22e30730c9.zip
Introduce sysdb_ldb_connect()
Diffstat (limited to 'src/db')
-rw-r--r--src/db/sysdb.c87
1 files changed, 42 insertions, 45 deletions
diff --git a/src/db/sysdb.c b/src/db/sysdb.c
index 694ce54c3..e222c8be7 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)
{
@@ -877,22 +907,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");
@@ -978,22 +996,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 */
@@ -1549,19 +1555,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);