|
|
71e593 |
From d5b15619809b169dca96af648c24f927e85d0e4b Mon Sep 17 00:00:00 2001
|
|
|
71e593 |
From: Sumit Bose <sbose@redhat.com>
|
|
|
71e593 |
Date: Fri, 29 Jun 2018 17:49:50 +0200
|
|
|
71e593 |
Subject: [PATCH 03/19] sysdb: extract sysdb_ldb_msg_attr_to_certmap_info()
|
|
|
71e593 |
call
|
|
|
71e593 |
|
|
|
71e593 |
Related to https://pagure.io/SSSD/sssd/issue/3500
|
|
|
71e593 |
|
|
|
71e593 |
Reviewed-by: Jakub Hrozek <jhrozek@redhat.com>
|
|
|
71e593 |
(cherry picked from commit 7c619ae08f05a7595d15cf11b64461a7d19cfaa7)
|
|
|
71e593 |
---
|
|
|
71e593 |
src/db/sysdb.h | 4 ++
|
|
|
71e593 |
src/db/sysdb_certmap.c | 191 ++++++++++++++++++++++++++++---------------------
|
|
|
71e593 |
2 files changed, 112 insertions(+), 83 deletions(-)
|
|
|
71e593 |
|
|
|
71e593 |
diff --git a/src/db/sysdb.h b/src/db/sysdb.h
|
|
|
71e593 |
index d72af5a05009d80af0226c52736fbba6641d30fd..cb04e1b60546bd5de968eaf67ea5d2fc2b5e24ba 100644
|
|
|
71e593 |
--- a/src/db/sysdb.h
|
|
|
71e593 |
+++ b/src/db/sysdb.h
|
|
|
71e593 |
@@ -702,6 +702,10 @@ errno_t sysdb_update_certmap(struct sysdb_ctx *sysdb,
|
|
|
71e593 |
struct certmap_info **certmaps,
|
|
|
71e593 |
bool user_name_hint);
|
|
|
71e593 |
|
|
|
71e593 |
+errno_t sysdb_ldb_msg_attr_to_certmap_info(TALLOC_CTX *mem_ctx,
|
|
|
71e593 |
+ struct ldb_message *msg,
|
|
|
71e593 |
+ struct certmap_info **certmap);
|
|
|
71e593 |
+
|
|
|
71e593 |
errno_t sysdb_get_certmap(TALLOC_CTX *mem_ctx, struct sysdb_ctx *sysdb,
|
|
|
71e593 |
struct certmap_info ***certmaps,
|
|
|
71e593 |
bool *user_name_hint);
|
|
|
71e593 |
diff --git a/src/db/sysdb_certmap.c b/src/db/sysdb_certmap.c
|
|
|
71e593 |
index 6d83ba0884fbacfd068a5b24bd9c7627b70680f5..e61cc05cc0c056a78965ff5989bd46aac2a44b3d 100644
|
|
|
71e593 |
--- a/src/db/sysdb_certmap.c
|
|
|
71e593 |
+++ b/src/db/sysdb_certmap.c
|
|
|
71e593 |
@@ -262,19 +262,119 @@ done:
|
|
|
71e593 |
return ret;
|
|
|
71e593 |
}
|
|
|
71e593 |
|
|
|
71e593 |
+errno_t sysdb_ldb_msg_attr_to_certmap_info(TALLOC_CTX *mem_ctx,
|
|
|
71e593 |
+ struct ldb_message *msg,
|
|
|
71e593 |
+ struct certmap_info **certmap)
|
|
|
71e593 |
+{
|
|
|
71e593 |
+ int ret;
|
|
|
71e593 |
+ size_t d;
|
|
|
71e593 |
+ size_t num_values;
|
|
|
71e593 |
+ struct certmap_info *map = NULL;
|
|
|
71e593 |
+ const char *tmp_str;
|
|
|
71e593 |
+ uint64_t tmp_uint;
|
|
|
71e593 |
+ struct ldb_message_element *tmp_el;
|
|
|
71e593 |
+
|
|
|
71e593 |
+
|
|
|
71e593 |
+ map = talloc_zero(mem_ctx, struct certmap_info);
|
|
|
71e593 |
+ if (map == NULL) {
|
|
|
71e593 |
+ return ENOMEM;
|
|
|
71e593 |
+ }
|
|
|
71e593 |
+
|
|
|
71e593 |
+ tmp_str = ldb_msg_find_attr_as_string(msg, SYSDB_NAME, NULL);
|
|
|
71e593 |
+ if (tmp_str == NULL) {
|
|
|
71e593 |
+ DEBUG(SSSDBG_MINOR_FAILURE, "The object [%s] doesn't have a name.\n",
|
|
|
71e593 |
+ ldb_dn_get_linearized(msg->dn));
|
|
|
71e593 |
+ ret = EINVAL;
|
|
|
71e593 |
+ goto done;
|
|
|
71e593 |
+ }
|
|
|
71e593 |
+
|
|
|
71e593 |
+ map->name = talloc_strdup(map, tmp_str);
|
|
|
71e593 |
+ if (map->name == NULL) {
|
|
|
71e593 |
+ ret = ENOMEM;
|
|
|
71e593 |
+ goto done;
|
|
|
71e593 |
+ }
|
|
|
71e593 |
+
|
|
|
71e593 |
+ tmp_str = ldb_msg_find_attr_as_string(msg, SYSDB_CERTMAP_MAPPING_RULE,
|
|
|
71e593 |
+ NULL);
|
|
|
71e593 |
+ if (tmp_str != NULL) {
|
|
|
71e593 |
+ map->map_rule = talloc_strdup(map, tmp_str);
|
|
|
71e593 |
+ if (map->map_rule == NULL) {
|
|
|
71e593 |
+ DEBUG(SSSDBG_OP_FAILURE, "talloc_strdup failed.\n");
|
|
|
71e593 |
+ ret = ENOMEM;
|
|
|
71e593 |
+ goto done;
|
|
|
71e593 |
+ }
|
|
|
71e593 |
+ }
|
|
|
71e593 |
+
|
|
|
71e593 |
+ tmp_str = ldb_msg_find_attr_as_string(msg, SYSDB_CERTMAP_MATCHING_RULE,
|
|
|
71e593 |
+ NULL);
|
|
|
71e593 |
+ if (tmp_str != NULL) {
|
|
|
71e593 |
+ map->match_rule = talloc_strdup(map, tmp_str);
|
|
|
71e593 |
+ if (map->match_rule == NULL) {
|
|
|
71e593 |
+ DEBUG(SSSDBG_OP_FAILURE, "talloc_strdup failed.\n");
|
|
|
71e593 |
+ ret = ENOMEM;
|
|
|
71e593 |
+ goto done;
|
|
|
71e593 |
+ }
|
|
|
71e593 |
+ }
|
|
|
71e593 |
+
|
|
|
71e593 |
+ tmp_uint = ldb_msg_find_attr_as_uint64(msg, SYSDB_CERTMAP_PRIORITY,
|
|
|
71e593 |
+ (uint64_t) -1);
|
|
|
71e593 |
+ if (tmp_uint != (uint64_t) -1) {
|
|
|
71e593 |
+ if (tmp_uint > UINT32_MAX) {
|
|
|
71e593 |
+ DEBUG(SSSDBG_OP_FAILURE, "Priority value [%lu] too large.\n",
|
|
|
71e593 |
+ (unsigned long) tmp_uint);
|
|
|
71e593 |
+ ret = EINVAL;
|
|
|
71e593 |
+ goto done;
|
|
|
71e593 |
+ }
|
|
|
71e593 |
+
|
|
|
71e593 |
+ map->priority = (uint32_t) tmp_uint;
|
|
|
71e593 |
+ }
|
|
|
71e593 |
+
|
|
|
71e593 |
+ tmp_el = ldb_msg_find_element(msg, SYSDB_CERTMAP_DOMAINS);
|
|
|
71e593 |
+ if (tmp_el != NULL) {
|
|
|
71e593 |
+ num_values = tmp_el->num_values;
|
|
|
71e593 |
+ } else {
|
|
|
71e593 |
+ num_values = 0;
|
|
|
71e593 |
+ }
|
|
|
71e593 |
+
|
|
|
71e593 |
+ map->domains = talloc_zero_array(map, const char *, num_values + 1);
|
|
|
71e593 |
+ if (map->domains == NULL) {
|
|
|
71e593 |
+ DEBUG(SSSDBG_OP_FAILURE, "talloc_zero_array failed.\n");
|
|
|
71e593 |
+ ret = ENOMEM;
|
|
|
71e593 |
+ goto done;
|
|
|
71e593 |
+ }
|
|
|
71e593 |
+
|
|
|
71e593 |
+ for (d = 0; d < num_values; d++) {
|
|
|
71e593 |
+ map->domains[d] = talloc_strndup(map->domains,
|
|
|
71e593 |
+ (char *) tmp_el->values[d].data,
|
|
|
71e593 |
+ tmp_el->values[d].length);
|
|
|
71e593 |
+ if (map->domains[d] == NULL) {
|
|
|
71e593 |
+ DEBUG(SSSDBG_OP_FAILURE, "talloc_strndup failed.\n");
|
|
|
71e593 |
+ ret = ENOMEM;
|
|
|
71e593 |
+ goto done;
|
|
|
71e593 |
+ }
|
|
|
71e593 |
+ }
|
|
|
71e593 |
+
|
|
|
71e593 |
+ *certmap = map;
|
|
|
71e593 |
+
|
|
|
71e593 |
+ ret = EOK;
|
|
|
71e593 |
+
|
|
|
71e593 |
+done:
|
|
|
71e593 |
+ if (ret != EOK) {
|
|
|
71e593 |
+ talloc_free(map);
|
|
|
71e593 |
+ }
|
|
|
71e593 |
+
|
|
|
71e593 |
+ return ret;
|
|
|
71e593 |
+}
|
|
|
71e593 |
+
|
|
|
71e593 |
errno_t sysdb_get_certmap(TALLOC_CTX *mem_ctx, struct sysdb_ctx *sysdb,
|
|
|
71e593 |
struct certmap_info ***certmaps, bool *user_name_hint)
|
|
|
71e593 |
{
|
|
|
71e593 |
size_t c;
|
|
|
71e593 |
- size_t d;
|
|
|
71e593 |
struct ldb_dn *container_dn = NULL;
|
|
|
71e593 |
int ret;
|
|
|
71e593 |
struct certmap_info **maps = NULL;
|
|
|
71e593 |
TALLOC_CTX *tmp_ctx = NULL;
|
|
|
71e593 |
struct ldb_result *res;
|
|
|
71e593 |
- const char *tmp_str;
|
|
|
71e593 |
- uint64_t tmp_uint;
|
|
|
71e593 |
- struct ldb_message_element *tmp_el;
|
|
|
71e593 |
const char *attrs[] = {SYSDB_NAME,
|
|
|
71e593 |
SYSDB_CERTMAP_PRIORITY,
|
|
|
71e593 |
SYSDB_CERTMAP_MATCHING_RULE,
|
|
|
71e593 |
@@ -283,7 +383,6 @@ errno_t sysdb_get_certmap(TALLOC_CTX *mem_ctx, struct sysdb_ctx *sysdb,
|
|
|
71e593 |
NULL};
|
|
|
71e593 |
const char *config_attrs[] = {SYSDB_CERTMAP_USER_NAME_HINT,
|
|
|
71e593 |
NULL};
|
|
|
71e593 |
- size_t num_values;
|
|
|
71e593 |
bool hint = false;
|
|
|
71e593 |
|
|
|
71e593 |
tmp_ctx = talloc_new(NULL);
|
|
|
71e593 |
@@ -332,86 +431,12 @@ errno_t sysdb_get_certmap(TALLOC_CTX *mem_ctx, struct sysdb_ctx *sysdb,
|
|
|
71e593 |
}
|
|
|
71e593 |
|
|
|
71e593 |
for (c = 0; c < res->count; c++) {
|
|
|
71e593 |
- maps[c] = talloc_zero(maps, struct certmap_info);
|
|
|
71e593 |
- if (maps[c] == NULL) {
|
|
|
71e593 |
- ret = ENOMEM;
|
|
|
71e593 |
+ ret = sysdb_ldb_msg_attr_to_certmap_info(maps, res->msgs[c], &maps[c]);
|
|
|
71e593 |
+ if (ret != EOK) {
|
|
|
71e593 |
+ DEBUG(SSSDBG_OP_FAILURE,
|
|
|
71e593 |
+ "sysdb_ldb_msg_attr_to_certmap_info failed.\n");
|
|
|
71e593 |
goto done;
|
|
|
71e593 |
}
|
|
|
71e593 |
- tmp_str = ldb_msg_find_attr_as_string(res->msgs[c], SYSDB_NAME, NULL);
|
|
|
71e593 |
- if (tmp_str == NULL) {
|
|
|
71e593 |
- DEBUG(SSSDBG_MINOR_FAILURE, "The object [%s] doesn't have a name.\n",
|
|
|
71e593 |
- ldb_dn_get_linearized(res->msgs[c]->dn));
|
|
|
71e593 |
- ret = EINVAL;
|
|
|
71e593 |
- goto done;
|
|
|
71e593 |
- }
|
|
|
71e593 |
-
|
|
|
71e593 |
- maps[c]->name = talloc_strdup(maps, tmp_str);
|
|
|
71e593 |
- if (maps[c]->name == NULL) {
|
|
|
71e593 |
- ret = ENOMEM;
|
|
|
71e593 |
- goto done;
|
|
|
71e593 |
- }
|
|
|
71e593 |
-
|
|
|
71e593 |
- tmp_str = ldb_msg_find_attr_as_string(res->msgs[c],
|
|
|
71e593 |
- SYSDB_CERTMAP_MAPPING_RULE, NULL);
|
|
|
71e593 |
- if (tmp_str != NULL) {
|
|
|
71e593 |
- maps[c]->map_rule = talloc_strdup(maps, tmp_str);
|
|
|
71e593 |
- if (maps[c]->map_rule == NULL) {
|
|
|
71e593 |
- DEBUG(SSSDBG_OP_FAILURE, "talloc_strdup failed.\n");
|
|
|
71e593 |
- ret = ENOMEM;
|
|
|
71e593 |
- goto done;
|
|
|
71e593 |
- }
|
|
|
71e593 |
- }
|
|
|
71e593 |
-
|
|
|
71e593 |
- tmp_str = ldb_msg_find_attr_as_string(res->msgs[c],
|
|
|
71e593 |
- SYSDB_CERTMAP_MATCHING_RULE, NULL);
|
|
|
71e593 |
- if (tmp_str != NULL) {
|
|
|
71e593 |
- maps[c]->match_rule = talloc_strdup(maps, tmp_str);
|
|
|
71e593 |
- if (maps[c]->match_rule == NULL) {
|
|
|
71e593 |
- DEBUG(SSSDBG_OP_FAILURE, "talloc_strdup failed.\n");
|
|
|
71e593 |
- ret = ENOMEM;
|
|
|
71e593 |
- goto done;
|
|
|
71e593 |
- }
|
|
|
71e593 |
- }
|
|
|
71e593 |
-
|
|
|
71e593 |
- tmp_uint = ldb_msg_find_attr_as_uint64(res->msgs[c],
|
|
|
71e593 |
- SYSDB_CERTMAP_PRIORITY,
|
|
|
71e593 |
- (uint64_t) -1);
|
|
|
71e593 |
- if (tmp_uint != (uint64_t) -1) {
|
|
|
71e593 |
- if (tmp_uint > UINT32_MAX) {
|
|
|
71e593 |
- DEBUG(SSSDBG_OP_FAILURE, "Priority value [%lu] too large.\n",
|
|
|
71e593 |
- (unsigned long) tmp_uint);
|
|
|
71e593 |
- ret = EINVAL;
|
|
|
71e593 |
- goto done;
|
|
|
71e593 |
- }
|
|
|
71e593 |
-
|
|
|
71e593 |
- maps[c]->priority = (uint32_t) tmp_uint;
|
|
|
71e593 |
- }
|
|
|
71e593 |
-
|
|
|
71e593 |
- tmp_el = ldb_msg_find_element(res->msgs[c], SYSDB_CERTMAP_DOMAINS);
|
|
|
71e593 |
- if (tmp_el != NULL) {
|
|
|
71e593 |
- num_values = tmp_el->num_values;
|
|
|
71e593 |
- } else {
|
|
|
71e593 |
- num_values = 0;
|
|
|
71e593 |
- }
|
|
|
71e593 |
-
|
|
|
71e593 |
- maps[c]->domains = talloc_zero_array(maps[c], const char *,
|
|
|
71e593 |
- num_values + 1);
|
|
|
71e593 |
- if (maps[c]->domains == NULL) {
|
|
|
71e593 |
- DEBUG(SSSDBG_OP_FAILURE, "talloc_zero_array failed.\n");
|
|
|
71e593 |
- ret = ENOMEM;
|
|
|
71e593 |
- goto done;
|
|
|
71e593 |
- }
|
|
|
71e593 |
-
|
|
|
71e593 |
- for (d = 0; d < num_values; d++) {
|
|
|
71e593 |
- maps[c]->domains[d] = talloc_strndup(maps[c]->domains,
|
|
|
71e593 |
- (char *) tmp_el->values[d].data,
|
|
|
71e593 |
- tmp_el->values[d].length);
|
|
|
71e593 |
- if (maps[c]->domains[d] == NULL) {
|
|
|
71e593 |
- DEBUG(SSSDBG_OP_FAILURE, "talloc_strndup failed.\n");
|
|
|
71e593 |
- ret = ENOMEM;
|
|
|
71e593 |
- goto done;
|
|
|
71e593 |
- }
|
|
|
71e593 |
- }
|
|
|
71e593 |
}
|
|
|
71e593 |
|
|
|
71e593 |
ret = EOK;
|
|
|
71e593 |
--
|
|
|
71e593 |
2.14.4
|
|
|
71e593 |
|