summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/db/sysdb.c29
-rw-r--r--src/db/sysdb.h4
-rw-r--r--src/providers/ipa/ipa_access.c2
-rw-r--r--src/providers/ldap/ldap_common.c29
4 files changed, 34 insertions, 30 deletions
diff --git a/src/db/sysdb.c b/src/db/sysdb.c
index 034e5da0d..8ca4c17fb 100644
--- a/src/db/sysdb.c
+++ b/src/db/sysdb.c
@@ -1765,3 +1765,32 @@ done:
talloc_free(tmp_ctx);
return ret;
}
+
+errno_t sysdb_msg2attrs(TALLOC_CTX *mem_ctx, size_t count,
+ struct ldb_message **msgs,
+ struct sysdb_attrs ***attrs)
+{
+ int i;
+ struct sysdb_attrs **a;
+
+ a = talloc_array(mem_ctx, struct sysdb_attrs *, count);
+ if (a == NULL) {
+ DEBUG(1, ("talloc_array failed.\n"));
+ return ENOMEM;
+ }
+
+ for (i = 0; i < count; i++) {
+ a[i] = talloc(a, struct sysdb_attrs);
+ if (a[i] == NULL) {
+ DEBUG(1, ("talloc_array failed.\n"));
+ talloc_free(a);
+ return ENOMEM;
+ }
+ a[i]->num = msgs[i]->num_elements;
+ a[i]->a = talloc_steal(a[i], msgs[i]->elements);
+ }
+
+ *attrs = a;
+
+ return EOK;
+}
diff --git a/src/db/sysdb.h b/src/db/sysdb.h
index 6094a4aaa..3d2a76826 100644
--- a/src/db/sysdb.h
+++ b/src/db/sysdb.h
@@ -254,6 +254,10 @@ errno_t sysdb_get_real_name(TALLOC_CTX *mem_ctx,
const char *name,
const char **_cname);
+errno_t sysdb_msg2attrs(TALLOC_CTX *mem_ctx, size_t count,
+ struct ldb_message **msgs,
+ struct sysdb_attrs ***attrs);
+
/* convert an ldb error into an errno error */
int sysdb_error_to_errno(int ldberr);
diff --git a/src/providers/ipa/ipa_access.c b/src/providers/ipa/ipa_access.c
index 880f07d31..bb496e594 100644
--- a/src/providers/ipa/ipa_access.c
+++ b/src/providers/ipa/ipa_access.c
@@ -644,7 +644,7 @@ static errno_t hbac_get_cached_rules(TALLOC_CTX *mem_ctx,
count = 0;
}
- ret = msgs2attrs_array(mem_ctx, count, msgs, &hbac_ctx->rules);
+ ret = sysdb_msg2attrs(mem_ctx, count, msgs, &hbac_ctx->rules);
if (ret != EOK) {
DEBUG(1, ("Could not convert ldb message to sysdb_attrs\n"));
goto done;
diff --git a/src/providers/ldap/ldap_common.c b/src/providers/ldap/ldap_common.c
index f9627ac1d..dc55f6eca 100644
--- a/src/providers/ldap/ldap_common.c
+++ b/src/providers/ldap/ldap_common.c
@@ -1402,32 +1402,3 @@ char *sdap_get_id_specific_filter(TALLOC_CTX *mem_ctx,
}
return filter; /* NULL or not */
}
-
-errno_t msgs2attrs_array(TALLOC_CTX *mem_ctx, size_t count,
- struct ldb_message **msgs,
- struct sysdb_attrs ***attrs)
-{
- int i;
- struct sysdb_attrs **a;
-
- a = talloc_array(mem_ctx, struct sysdb_attrs *, count);
- if (a == NULL) {
- DEBUG(1, ("talloc_array failed.\n"));
- return ENOMEM;
- }
-
- for (i = 0; i < count; i++) {
- a[i] = talloc(a, struct sysdb_attrs);
- if (a[i] == NULL) {
- DEBUG(1, ("talloc_array failed.\n"));
- talloc_free(a);
- return ENOMEM;
- }
- a[i]->num = msgs[i]->num_elements;
- a[i]->a = talloc_steal(a[i], msgs[i]->elements);
- }
-
- *attrs = a;
-
- return EOK;
-}