|
|
5ad689 |
From 2fca2f1b77c0e9ae82e1a24bbf89fbc3115a5e24 Mon Sep 17 00:00:00 2001
|
|
|
5ad689 |
From: Sumit Bose <sbose@redhat.com>
|
|
|
5ad689 |
Date: Wed, 6 Sep 2017 16:42:20 +0200
|
|
|
5ad689 |
Subject: [PATCH 193/194] IPA: fix handling of certmap_ctx
|
|
|
5ad689 |
MIME-Version: 1.0
|
|
|
5ad689 |
Content-Type: text/plain; charset=UTF-8
|
|
|
5ad689 |
Content-Transfer-Encoding: 8bit
|
|
|
5ad689 |
|
|
|
5ad689 |
This patch fixes a use-after-free in the AD provider part and
|
|
|
5ad689 |
initializes the certmap_ctx with data from the cache at startup.
|
|
|
5ad689 |
|
|
|
5ad689 |
Related to https://pagure.io/SSSD/sssd/issue/3508
|
|
|
5ad689 |
|
|
|
5ad689 |
Reviewed-by: Lukáš Slebodník <lslebodn@redhat.com>
|
|
|
5ad689 |
Reviewed-by: Jakub Hrozek <jhrozek@redhat.com>
|
|
|
5ad689 |
(cherry picked from commit f2e70ec742cd7aab82b74d7e4b424ba3258da7aa)
|
|
|
5ad689 |
---
|
|
|
5ad689 |
Makefile.am | 20 +++
|
|
|
5ad689 |
src/providers/ipa/ipa_init.c | 7 +
|
|
|
5ad689 |
src/providers/ipa/ipa_subdomains.c | 53 +------
|
|
|
5ad689 |
src/providers/ipa/ipa_subdomains_server.c | 4 +-
|
|
|
5ad689 |
src/providers/ldap/ldap_common.h | 5 +
|
|
|
5ad689 |
src/providers/ldap/ldap_id.c | 5 +-
|
|
|
5ad689 |
src/providers/ldap/sdap.h | 4 +-
|
|
|
5ad689 |
src/providers/ldap/sdap_certmap.c | 152 +++++++++++++++++++
|
|
|
5ad689 |
src/tests/cmocka/test_sdap_certmap.c | 244 ++++++++++++++++++++++++++++++
|
|
|
5ad689 |
9 files changed, 441 insertions(+), 53 deletions(-)
|
|
|
5ad689 |
create mode 100644 src/providers/ldap/sdap_certmap.c
|
|
|
5ad689 |
create mode 100644 src/tests/cmocka/test_sdap_certmap.c
|
|
|
5ad689 |
|
|
|
5ad689 |
diff --git a/Makefile.am b/Makefile.am
|
|
|
5ad689 |
index 503c8cfd795b503f566431c08a56a56147180322..907c3256a154ebe2aae5a1667744e1dfbe8abaae 100644
|
|
|
5ad689 |
--- a/Makefile.am
|
|
|
5ad689 |
+++ b/Makefile.am
|
|
|
5ad689 |
@@ -257,6 +257,7 @@ if HAVE_CMOCKA
|
|
|
5ad689 |
test_search_bases \
|
|
|
5ad689 |
test_ldap_auth \
|
|
|
5ad689 |
test_sdap_access \
|
|
|
5ad689 |
+ test_sdap_certmap \
|
|
|
5ad689 |
sdap-tests \
|
|
|
5ad689 |
test_sysdb_ts_cache \
|
|
|
5ad689 |
test_sysdb_views \
|
|
|
5ad689 |
@@ -2662,6 +2663,24 @@ test_sdap_access_LDADD = \
|
|
|
5ad689 |
libdlopen_test_providers.la \
|
|
|
5ad689 |
$(NULL)
|
|
|
5ad689 |
|
|
|
5ad689 |
+test_sdap_certmap_SOURCES = \
|
|
|
5ad689 |
+ src/tests/cmocka/test_sdap_certmap.c \
|
|
|
5ad689 |
+ src/providers/ldap/sdap_certmap.c \
|
|
|
5ad689 |
+ $(NULL)
|
|
|
5ad689 |
+test_sdap_certmap_CFLAGS = \
|
|
|
5ad689 |
+ $(AM_CFLAGS) \
|
|
|
5ad689 |
+ $(TALLOC_CFLAGS) \
|
|
|
5ad689 |
+ $(POPT_CFLAGS) \
|
|
|
5ad689 |
+ $(NULL)
|
|
|
5ad689 |
+test_sdap_certmap_LDADD = \
|
|
|
5ad689 |
+ $(CMOCKA_LIBS) \
|
|
|
5ad689 |
+ $(TALLOC_LIBS) \
|
|
|
5ad689 |
+ $(POPT_LIBS) \
|
|
|
5ad689 |
+ $(SSSD_INTERNAL_LTLIBS) \
|
|
|
5ad689 |
+ libsss_test_common.la \
|
|
|
5ad689 |
+ libsss_certmap.la \
|
|
|
5ad689 |
+ $(NULL)
|
|
|
5ad689 |
+
|
|
|
5ad689 |
ad_access_filter_tests_SOURCES = \
|
|
|
5ad689 |
src/tests/cmocka/test_ad_access_filter.c
|
|
|
5ad689 |
ad_access_filter_tests_LDADD = \
|
|
|
5ad689 |
@@ -3706,6 +3725,7 @@ libsss_ldap_common_la_SOURCES = \
|
|
|
5ad689 |
src/providers/ldap/sdap_child_helpers.c \
|
|
|
5ad689 |
src/providers/ldap/sdap_fd_events.c \
|
|
|
5ad689 |
src/providers/ldap/sdap_id_op.c \
|
|
|
5ad689 |
+ src/providers/ldap/sdap_certmap.c \
|
|
|
5ad689 |
src/providers/ldap/sdap_idmap.c \
|
|
|
5ad689 |
src/providers/ldap/sdap_idmap.h \
|
|
|
5ad689 |
src/providers/ldap/sdap_range.c \
|
|
|
5ad689 |
diff --git a/src/providers/ipa/ipa_init.c b/src/providers/ipa/ipa_init.c
|
|
|
5ad689 |
index 7dec4d1fb8541a48470d4e44f10838e5bea67ad5..2b58b1341463f8947d51dee2076dbe92e3093558 100644
|
|
|
5ad689 |
--- a/src/providers/ipa/ipa_init.c
|
|
|
5ad689 |
+++ b/src/providers/ipa/ipa_init.c
|
|
|
5ad689 |
@@ -649,6 +649,13 @@ static errno_t ipa_init_misc(struct be_ctx *be_ctx,
|
|
|
5ad689 |
return ENOMEM;
|
|
|
5ad689 |
}
|
|
|
5ad689 |
|
|
|
5ad689 |
+ ret = sdap_init_certmap(sdap_id_ctx, sdap_id_ctx);
|
|
|
5ad689 |
+ if (ret != EOK) {
|
|
|
5ad689 |
+ DEBUG(SSSDBG_CRIT_FAILURE,
|
|
|
5ad689 |
+ "Failed to initialized certificate mapping.\n");
|
|
|
5ad689 |
+ return ret;
|
|
|
5ad689 |
+ }
|
|
|
5ad689 |
+
|
|
|
5ad689 |
return EOK;
|
|
|
5ad689 |
}
|
|
|
5ad689 |
|
|
|
5ad689 |
diff --git a/src/providers/ipa/ipa_subdomains.c b/src/providers/ipa/ipa_subdomains.c
|
|
|
5ad689 |
index ef348adf4a36e870f44387bd700f5c2beea3bfd6..6f0ff50bde234f72d62f43635d9a787316c78430 100644
|
|
|
5ad689 |
--- a/src/providers/ipa/ipa_subdomains.c
|
|
|
5ad689 |
+++ b/src/providers/ipa/ipa_subdomains.c
|
|
|
5ad689 |
@@ -311,25 +311,6 @@ struct priv_sss_debug {
|
|
|
5ad689 |
int level;
|
|
|
5ad689 |
};
|
|
|
5ad689 |
|
|
|
5ad689 |
-void ext_debug(void *private, const char *file, long line, const char *function,
|
|
|
5ad689 |
- const char *format, ...)
|
|
|
5ad689 |
-{
|
|
|
5ad689 |
- va_list ap;
|
|
|
5ad689 |
- struct priv_sss_debug *data = private;
|
|
|
5ad689 |
- int level = SSSDBG_OP_FAILURE;
|
|
|
5ad689 |
-
|
|
|
5ad689 |
- if (data != NULL) {
|
|
|
5ad689 |
- level = data->level;
|
|
|
5ad689 |
- }
|
|
|
5ad689 |
-
|
|
|
5ad689 |
- if (DEBUG_IS_SET(level)) {
|
|
|
5ad689 |
- va_start(ap, format);
|
|
|
5ad689 |
- sss_vdebug_fn(file, line, function, level, APPEND_LINE_FEED,
|
|
|
5ad689 |
- format, ap);
|
|
|
5ad689 |
- va_end(ap);
|
|
|
5ad689 |
- }
|
|
|
5ad689 |
-}
|
|
|
5ad689 |
-
|
|
|
5ad689 |
static errno_t ipa_certmap_parse_results(TALLOC_CTX *mem_ctx,
|
|
|
5ad689 |
struct sss_domain_info *domain,
|
|
|
5ad689 |
struct sdap_options *sdap_opts,
|
|
|
5ad689 |
@@ -344,7 +325,6 @@ static errno_t ipa_certmap_parse_results(TALLOC_CTX *mem_ctx,
|
|
|
5ad689 |
size_t c;
|
|
|
5ad689 |
size_t lc = 0;
|
|
|
5ad689 |
int ret;
|
|
|
5ad689 |
- struct sss_certmap_ctx *certmap_ctx = NULL;
|
|
|
5ad689 |
const char **ocs = NULL;
|
|
|
5ad689 |
bool user_name_hint = false;
|
|
|
5ad689 |
|
|
|
5ad689 |
@@ -444,50 +424,29 @@ static errno_t ipa_certmap_parse_results(TALLOC_CTX *mem_ctx,
|
|
|
5ad689 |
|
|
|
5ad689 |
certmap_list[lc] = NULL;
|
|
|
5ad689 |
|
|
|
5ad689 |
- ret = sss_certmap_init(mem_ctx, ext_debug, NULL, &certmap_ctx);
|
|
|
5ad689 |
- if (ret != 0) {
|
|
|
5ad689 |
- DEBUG(SSSDBG_OP_FAILURE, "sss_certmap_init failed.\n");
|
|
|
5ad689 |
+ ret = sdap_setup_certmap(sdap_opts->sdap_certmap_ctx, certmap_list);
|
|
|
5ad689 |
+ if (ret != EOK) {
|
|
|
5ad689 |
+ DEBUG(SSSDBG_OP_FAILURE, "sdap_setup_certmap failed.\n");
|
|
|
5ad689 |
goto done;
|
|
|
5ad689 |
}
|
|
|
5ad689 |
|
|
|
5ad689 |
- for (c = 0; certmap_list[c] != NULL; c++) {
|
|
|
5ad689 |
- DEBUG(SSSDBG_TRACE_ALL, "Trying to add rule [%s][%d][%s][%s].\n",
|
|
|
5ad689 |
- certmap_list[c]->name,
|
|
|
5ad689 |
- certmap_list[c]->priority,
|
|
|
5ad689 |
- certmap_list[c]->match_rule,
|
|
|
5ad689 |
- certmap_list[c]->map_rule);
|
|
|
5ad689 |
-
|
|
|
5ad689 |
- ret = sss_certmap_add_rule(certmap_ctx, certmap_list[c]->priority,
|
|
|
5ad689 |
- certmap_list[c]->match_rule,
|
|
|
5ad689 |
- certmap_list[c]->map_rule,
|
|
|
5ad689 |
- certmap_list[c]->domains);
|
|
|
5ad689 |
- if (ret != 0) {
|
|
|
5ad689 |
- DEBUG(SSSDBG_CRIT_FAILURE,
|
|
|
5ad689 |
- "sss_certmap_add_rule failed for rule [%s], skipping. "
|
|
|
5ad689 |
- "Please check for typos and if rule syntax is supported.\n",
|
|
|
5ad689 |
- certmap_list[c]->name);
|
|
|
5ad689 |
- goto done;
|
|
|
5ad689 |
- }
|
|
|
5ad689 |
- }
|
|
|
5ad689 |
-
|
|
|
5ad689 |
ret = sysdb_update_certmap(domain->sysdb, certmap_list, user_name_hint);
|
|
|
5ad689 |
if (ret != EOK) {
|
|
|
5ad689 |
DEBUG(SSSDBG_OP_FAILURE, "sysdb_update_certmap failed");
|
|
|
5ad689 |
goto done;
|
|
|
5ad689 |
}
|
|
|
5ad689 |
|
|
|
5ad689 |
- sss_certmap_free_ctx(sdap_opts->certmap_ctx);
|
|
|
5ad689 |
- sdap_opts->certmap_ctx = talloc_steal(sdap_opts, certmap_ctx);
|
|
|
5ad689 |
-
|
|
|
5ad689 |
if (_certmap_list != NULL) {
|
|
|
5ad689 |
*_certmap_list = certmap_list;
|
|
|
5ad689 |
+ } else {
|
|
|
5ad689 |
+ talloc_free(certmap_list);
|
|
|
5ad689 |
}
|
|
|
5ad689 |
+
|
|
|
5ad689 |
ret = EOK;
|
|
|
5ad689 |
|
|
|
5ad689 |
done:
|
|
|
5ad689 |
talloc_free(ocs);
|
|
|
5ad689 |
if (ret != EOK) {
|
|
|
5ad689 |
- sss_certmap_free_ctx(certmap_ctx);
|
|
|
5ad689 |
talloc_free(certmap_list);
|
|
|
5ad689 |
}
|
|
|
5ad689 |
|
|
|
5ad689 |
diff --git a/src/providers/ipa/ipa_subdomains_server.c b/src/providers/ipa/ipa_subdomains_server.c
|
|
|
5ad689 |
index 443d83824f329b9d8c3d8e820113e1029f832240..56470ac824feaa59eecbd9f442682220237c2412 100644
|
|
|
5ad689 |
--- a/src/providers/ipa/ipa_subdomains_server.c
|
|
|
5ad689 |
+++ b/src/providers/ipa/ipa_subdomains_server.c
|
|
|
5ad689 |
@@ -361,8 +361,8 @@ ipa_ad_ctx_new(struct be_ctx *be_ctx,
|
|
|
5ad689 |
id_ctx->sdap_id_ctx->opts->idmap_ctx;
|
|
|
5ad689 |
|
|
|
5ad689 |
/* Set up the certificate mapping context */
|
|
|
5ad689 |
- ad_id_ctx->sdap_id_ctx->opts->certmap_ctx =
|
|
|
5ad689 |
- id_ctx->sdap_id_ctx->opts->certmap_ctx;
|
|
|
5ad689 |
+ ad_id_ctx->sdap_id_ctx->opts->sdap_certmap_ctx =
|
|
|
5ad689 |
+ id_ctx->sdap_id_ctx->opts->sdap_certmap_ctx;
|
|
|
5ad689 |
|
|
|
5ad689 |
*_ad_id_ctx = ad_id_ctx;
|
|
|
5ad689 |
return EOK;
|
|
|
5ad689 |
diff --git a/src/providers/ldap/ldap_common.h b/src/providers/ldap/ldap_common.h
|
|
|
5ad689 |
index 1acda4147576503b18f61e0bb56f8efd2263fd44..0510b7d5ab5121bd96f699e8e59520a2a18a604f 100644
|
|
|
5ad689 |
--- a/src/providers/ldap/ldap_common.h
|
|
|
5ad689 |
+++ b/src/providers/ldap/ldap_common.h
|
|
|
5ad689 |
@@ -362,4 +362,9 @@ sdap_id_ctx_new(TALLOC_CTX *mem_ctx, struct be_ctx *bectx,
|
|
|
5ad689 |
errno_t sdap_refresh_init(struct be_refresh_ctx *refresh_ctx,
|
|
|
5ad689 |
struct sdap_id_ctx *id_ctx);
|
|
|
5ad689 |
|
|
|
5ad689 |
+errno_t sdap_init_certmap(TALLOC_CTX *mem_ctx, struct sdap_id_ctx *id_ctx);
|
|
|
5ad689 |
+
|
|
|
5ad689 |
+errno_t sdap_setup_certmap(struct sdap_certmap_ctx *sdap_certmap_ctx,
|
|
|
5ad689 |
+ struct certmap_info **certmap_list);
|
|
|
5ad689 |
+struct sss_certmap_ctx *sdap_get_sss_certmap(struct sdap_certmap_ctx *ctx);
|
|
|
5ad689 |
#endif /* _LDAP_COMMON_H_ */
|
|
|
5ad689 |
diff --git a/src/providers/ldap/ldap_id.c b/src/providers/ldap/ldap_id.c
|
|
|
5ad689 |
index 557712e8dc2b2bde664b4054fa2f8eb39df84d73..93204d35ea3782c9aa5d622a962c295869472631 100644
|
|
|
5ad689 |
--- a/src/providers/ldap/ldap_id.c
|
|
|
5ad689 |
+++ b/src/providers/ldap/ldap_id.c
|
|
|
5ad689 |
@@ -252,9 +252,8 @@ struct tevent_req *users_get_send(TALLOC_CTX *memctx,
|
|
|
5ad689 |
}
|
|
|
5ad689 |
|
|
|
5ad689 |
ret = sss_cert_derb64_to_ldap_filter(state, filter_value, attr_name,
|
|
|
5ad689 |
- ctx->opts->certmap_ctx,
|
|
|
5ad689 |
- state->domain,
|
|
|
5ad689 |
- &user_filter);
|
|
|
5ad689 |
+ sdap_get_sss_certmap(ctx->opts->sdap_certmap_ctx),
|
|
|
5ad689 |
+ state->domain, &user_filter);
|
|
|
5ad689 |
if (ret != EOK) {
|
|
|
5ad689 |
DEBUG(SSSDBG_OP_FAILURE,
|
|
|
5ad689 |
"sss_cert_derb64_to_ldap_filter failed.\n");
|
|
|
5ad689 |
diff --git a/src/providers/ldap/sdap.h b/src/providers/ldap/sdap.h
|
|
|
5ad689 |
index afdc01948eefe9dda943c8c7ad01a42dd76a1da8..c85fbe9e78e5eefa7e33ea8055730118b0871a4c 100644
|
|
|
5ad689 |
--- a/src/providers/ldap/sdap.h
|
|
|
5ad689 |
+++ b/src/providers/ldap/sdap.h
|
|
|
5ad689 |
@@ -446,6 +446,8 @@ struct sdap_ext_member_ctx {
|
|
|
5ad689 |
ext_member_recv_fn_t ext_member_resolve_recv;
|
|
|
5ad689 |
};
|
|
|
5ad689 |
|
|
|
5ad689 |
+struct sdap_certmap_ctx;
|
|
|
5ad689 |
+
|
|
|
5ad689 |
struct sdap_options {
|
|
|
5ad689 |
struct dp_option *basic;
|
|
|
5ad689 |
struct sdap_attr_map *gen_map;
|
|
|
5ad689 |
@@ -481,7 +483,7 @@ struct sdap_options {
|
|
|
5ad689 |
enum dc_functional_level dc_functional_level;
|
|
|
5ad689 |
|
|
|
5ad689 |
/* Certificate mapping support */
|
|
|
5ad689 |
- struct sss_certmap_ctx *certmap_ctx;
|
|
|
5ad689 |
+ struct sdap_certmap_ctx *sdap_certmap_ctx;
|
|
|
5ad689 |
};
|
|
|
5ad689 |
|
|
|
5ad689 |
struct sdap_server_opts {
|
|
|
5ad689 |
diff --git a/src/providers/ldap/sdap_certmap.c b/src/providers/ldap/sdap_certmap.c
|
|
|
5ad689 |
new file mode 100644
|
|
|
5ad689 |
index 0000000000000000000000000000000000000000..fcf88a9c69482c8668d486cd2ab0ba37c847e46d
|
|
|
5ad689 |
--- /dev/null
|
|
|
5ad689 |
+++ b/src/providers/ldap/sdap_certmap.c
|
|
|
5ad689 |
@@ -0,0 +1,152 @@
|
|
|
5ad689 |
+
|
|
|
5ad689 |
+/*
|
|
|
5ad689 |
+ SSSD
|
|
|
5ad689 |
+
|
|
|
5ad689 |
+ Authors:
|
|
|
5ad689 |
+ Sumit Bose <sbose@redhat.com>
|
|
|
5ad689 |
+
|
|
|
5ad689 |
+ Copyright (C) 2017 Red Hat
|
|
|
5ad689 |
+
|
|
|
5ad689 |
+ This program is free software; you can redistribute it and/or modify
|
|
|
5ad689 |
+ it under the terms of the GNU General Public License as published by
|
|
|
5ad689 |
+ the Free Software Foundation; either version 3 of the License, or
|
|
|
5ad689 |
+ (at your option) any later version.
|
|
|
5ad689 |
+
|
|
|
5ad689 |
+ This program is distributed in the hope that it will be useful,
|
|
|
5ad689 |
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
5ad689 |
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
5ad689 |
+ GNU General Public License for more details.
|
|
|
5ad689 |
+
|
|
|
5ad689 |
+ You should have received a copy of the GNU General Public License
|
|
|
5ad689 |
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
5ad689 |
+*/
|
|
|
5ad689 |
+
|
|
|
5ad689 |
+#include "util/util.h"
|
|
|
5ad689 |
+#include "lib/certmap/sss_certmap.h"
|
|
|
5ad689 |
+#include "providers/ldap/ldap_common.h"
|
|
|
5ad689 |
+
|
|
|
5ad689 |
+struct sdap_certmap_ctx {
|
|
|
5ad689 |
+ struct sss_certmap_ctx *certmap_ctx;
|
|
|
5ad689 |
+};
|
|
|
5ad689 |
+
|
|
|
5ad689 |
+struct priv_sss_debug {
|
|
|
5ad689 |
+ int level;
|
|
|
5ad689 |
+};
|
|
|
5ad689 |
+
|
|
|
5ad689 |
+static void ext_debug(void *private, const char *file, long line,
|
|
|
5ad689 |
+ const char *function, const char *format, ...)
|
|
|
5ad689 |
+{
|
|
|
5ad689 |
+ va_list ap;
|
|
|
5ad689 |
+ struct priv_sss_debug *data = private;
|
|
|
5ad689 |
+ int level = SSSDBG_OP_FAILURE;
|
|
|
5ad689 |
+
|
|
|
5ad689 |
+ if (data != NULL) {
|
|
|
5ad689 |
+ level = data->level;
|
|
|
5ad689 |
+ }
|
|
|
5ad689 |
+
|
|
|
5ad689 |
+ if (DEBUG_IS_SET(level)) {
|
|
|
5ad689 |
+ va_start(ap, format);
|
|
|
5ad689 |
+ sss_vdebug_fn(file, line, function, level, APPEND_LINE_FEED,
|
|
|
5ad689 |
+ format, ap);
|
|
|
5ad689 |
+ va_end(ap);
|
|
|
5ad689 |
+ }
|
|
|
5ad689 |
+}
|
|
|
5ad689 |
+
|
|
|
5ad689 |
+struct sss_certmap_ctx *sdap_get_sss_certmap(struct sdap_certmap_ctx *ctx)
|
|
|
5ad689 |
+{
|
|
|
5ad689 |
+ return ctx == NULL ? NULL : ctx->certmap_ctx;
|
|
|
5ad689 |
+}
|
|
|
5ad689 |
+
|
|
|
5ad689 |
+errno_t sdap_setup_certmap(struct sdap_certmap_ctx *sdap_certmap_ctx,
|
|
|
5ad689 |
+ struct certmap_info **certmap_list)
|
|
|
5ad689 |
+{
|
|
|
5ad689 |
+ int ret;
|
|
|
5ad689 |
+ struct sss_certmap_ctx *sss_certmap_ctx = NULL;
|
|
|
5ad689 |
+ size_t c;
|
|
|
5ad689 |
+
|
|
|
5ad689 |
+ if (sdap_certmap_ctx == NULL) {
|
|
|
5ad689 |
+ DEBUG(SSSDBG_CRIT_FAILURE, "Missing sdap_certmap_ctx.\n");
|
|
|
5ad689 |
+ return EINVAL;
|
|
|
5ad689 |
+ }
|
|
|
5ad689 |
+
|
|
|
5ad689 |
+ if (certmap_list == NULL || *certmap_list == NULL) {
|
|
|
5ad689 |
+ DEBUG(SSSDBG_TRACE_ALL, "No certmap data, nothing to do.\n");
|
|
|
5ad689 |
+ ret = EOK;
|
|
|
5ad689 |
+ goto done;
|
|
|
5ad689 |
+ }
|
|
|
5ad689 |
+
|
|
|
5ad689 |
+ ret = sss_certmap_init(sdap_certmap_ctx, ext_debug, NULL, &sss_certmap_ctx);
|
|
|
5ad689 |
+ if (ret != EOK) {
|
|
|
5ad689 |
+ DEBUG(SSSDBG_OP_FAILURE, "sss_certmap_init failed.\n");
|
|
|
5ad689 |
+ goto done;
|
|
|
5ad689 |
+ }
|
|
|
5ad689 |
+
|
|
|
5ad689 |
+ for (c = 0; certmap_list[c] != NULL; c++) {
|
|
|
5ad689 |
+ DEBUG(SSSDBG_TRACE_ALL, "Trying to add rule [%s][%d][%s][%s].\n",
|
|
|
5ad689 |
+ certmap_list[c]->name,
|
|
|
5ad689 |
+ certmap_list[c]->priority,
|
|
|
5ad689 |
+ certmap_list[c]->match_rule,
|
|
|
5ad689 |
+ certmap_list[c]->map_rule);
|
|
|
5ad689 |
+
|
|
|
5ad689 |
+ ret = sss_certmap_add_rule(sss_certmap_ctx, certmap_list[c]->priority,
|
|
|
5ad689 |
+ certmap_list[c]->match_rule,
|
|
|
5ad689 |
+ certmap_list[c]->map_rule,
|
|
|
5ad689 |
+ certmap_list[c]->domains);
|
|
|
5ad689 |
+ if (ret != 0) {
|
|
|
5ad689 |
+ DEBUG(SSSDBG_CRIT_FAILURE,
|
|
|
5ad689 |
+ "sss_certmap_add_rule failed for rule [%s] "
|
|
|
5ad689 |
+ "with error [%d][%s], skipping. "
|
|
|
5ad689 |
+ "Please check for typos and if rule syntax is supported.\n",
|
|
|
5ad689 |
+ certmap_list[c]->name, ret, sss_strerror(ret));
|
|
|
5ad689 |
+ continue;
|
|
|
5ad689 |
+ }
|
|
|
5ad689 |
+ }
|
|
|
5ad689 |
+
|
|
|
5ad689 |
+ ret = EOK;
|
|
|
5ad689 |
+
|
|
|
5ad689 |
+done:
|
|
|
5ad689 |
+ if (ret == EOK) {
|
|
|
5ad689 |
+ sss_certmap_free_ctx(sdap_certmap_ctx->certmap_ctx);
|
|
|
5ad689 |
+ sdap_certmap_ctx->certmap_ctx = sss_certmap_ctx;
|
|
|
5ad689 |
+ } else {
|
|
|
5ad689 |
+ sss_certmap_free_ctx(sss_certmap_ctx);
|
|
|
5ad689 |
+ }
|
|
|
5ad689 |
+
|
|
|
5ad689 |
+ return ret;
|
|
|
5ad689 |
+}
|
|
|
5ad689 |
+
|
|
|
5ad689 |
+errno_t sdap_init_certmap(TALLOC_CTX *mem_ctx, struct sdap_id_ctx *id_ctx)
|
|
|
5ad689 |
+{
|
|
|
5ad689 |
+ int ret;
|
|
|
5ad689 |
+ bool hint;
|
|
|
5ad689 |
+ struct certmap_info **certmap_list = NULL;
|
|
|
5ad689 |
+
|
|
|
5ad689 |
+ if (id_ctx->opts->sdap_certmap_ctx == NULL) {
|
|
|
5ad689 |
+ id_ctx->opts->sdap_certmap_ctx = talloc_zero(mem_ctx,
|
|
|
5ad689 |
+ struct sdap_certmap_ctx);
|
|
|
5ad689 |
+ if (id_ctx->opts->sdap_certmap_ctx == NULL) {
|
|
|
5ad689 |
+ DEBUG(SSSDBG_OP_FAILURE, "talloc_zero failed.\n");
|
|
|
5ad689 |
+ return ENOMEM;
|
|
|
5ad689 |
+ }
|
|
|
5ad689 |
+ }
|
|
|
5ad689 |
+
|
|
|
5ad689 |
+ ret = sysdb_get_certmap(mem_ctx, id_ctx->be->domain->sysdb,
|
|
|
5ad689 |
+ &certmap_list, &hint);
|
|
|
5ad689 |
+ if (ret != EOK) {
|
|
|
5ad689 |
+ DEBUG(SSSDBG_OP_FAILURE, "sysdb_get_certmap failed.\n");
|
|
|
5ad689 |
+ goto done;
|
|
|
5ad689 |
+ }
|
|
|
5ad689 |
+
|
|
|
5ad689 |
+ ret = sdap_setup_certmap(id_ctx->opts->sdap_certmap_ctx, certmap_list);
|
|
|
5ad689 |
+ if (ret != EOK) {
|
|
|
5ad689 |
+ DEBUG(SSSDBG_OP_FAILURE, "sdap_setup_certmap failed.\n");
|
|
|
5ad689 |
+ goto done;
|
|
|
5ad689 |
+ }
|
|
|
5ad689 |
+
|
|
|
5ad689 |
+ ret = EOK;
|
|
|
5ad689 |
+
|
|
|
5ad689 |
+done:
|
|
|
5ad689 |
+ talloc_free(certmap_list);
|
|
|
5ad689 |
+
|
|
|
5ad689 |
+ return ret;
|
|
|
5ad689 |
+}
|
|
|
5ad689 |
diff --git a/src/tests/cmocka/test_sdap_certmap.c b/src/tests/cmocka/test_sdap_certmap.c
|
|
|
5ad689 |
new file mode 100644
|
|
|
5ad689 |
index 0000000000000000000000000000000000000000..9df5666844c8582a3fdb5b086720f1f2819f53f3
|
|
|
5ad689 |
--- /dev/null
|
|
|
5ad689 |
+++ b/src/tests/cmocka/test_sdap_certmap.c
|
|
|
5ad689 |
@@ -0,0 +1,244 @@
|
|
|
5ad689 |
+/*
|
|
|
5ad689 |
+ Authors:
|
|
|
5ad689 |
+ Sumit Bose <sbose@redhat.com>
|
|
|
5ad689 |
+
|
|
|
5ad689 |
+ Copyright (C) 2017 Red Hat
|
|
|
5ad689 |
+
|
|
|
5ad689 |
+ SSSD tests - sdap certmap
|
|
|
5ad689 |
+
|
|
|
5ad689 |
+ This program is free software; you can redistribute it and/or modify
|
|
|
5ad689 |
+ it under the terms of the GNU General Public License as published by
|
|
|
5ad689 |
+ the Free Software Foundation; either version 3 of the License, or
|
|
|
5ad689 |
+ (at your option) any later version.
|
|
|
5ad689 |
+
|
|
|
5ad689 |
+ This program is distributed in the hope that it will be useful,
|
|
|
5ad689 |
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
5ad689 |
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
5ad689 |
+ GNU General Public License for more details.
|
|
|
5ad689 |
+
|
|
|
5ad689 |
+ You should have received a copy of the GNU General Public License
|
|
|
5ad689 |
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
5ad689 |
+*/
|
|
|
5ad689 |
+
|
|
|
5ad689 |
+#include <stdarg.h>
|
|
|
5ad689 |
+#include <stdbool.h>
|
|
|
5ad689 |
+#include <setjmp.h>
|
|
|
5ad689 |
+#include <unistd.h>
|
|
|
5ad689 |
+#include <cmocka.h>
|
|
|
5ad689 |
+#include <popt.h>
|
|
|
5ad689 |
+
|
|
|
5ad689 |
+#include "providers/ldap/ldap_common.h"
|
|
|
5ad689 |
+#include "tests/common.h"
|
|
|
5ad689 |
+#include "db/sysdb.h"
|
|
|
5ad689 |
+
|
|
|
5ad689 |
+#define TESTS_PATH "certmap_" BASE_FILE_STEM
|
|
|
5ad689 |
+#define TEST_CONF_DB "test_sysdb_certmap.ldb"
|
|
|
5ad689 |
+#define TEST_ID_PROVIDER "ldap"
|
|
|
5ad689 |
+#define TEST_DOM_NAME "certmap_test"
|
|
|
5ad689 |
+
|
|
|
5ad689 |
+struct certmap_info map_a = { discard_const("map_a"), 11,
|
|
|
5ad689 |
+ NULL, discard_const("(abc=def)"),
|
|
|
5ad689 |
+ NULL };
|
|
|
5ad689 |
+struct certmap_info map_b = { discard_const("map_b"), UINT_MAX,
|
|
|
5ad689 |
+ NULL, NULL, NULL };
|
|
|
5ad689 |
+struct certmap_info *certmap[] = { &map_a, &map_b, NULL };
|
|
|
5ad689 |
+
|
|
|
5ad689 |
+struct certmap_test_ctx {
|
|
|
5ad689 |
+ struct sss_test_ctx *tctx;
|
|
|
5ad689 |
+ struct sdap_id_ctx *id_ctx;
|
|
|
5ad689 |
+};
|
|
|
5ad689 |
+
|
|
|
5ad689 |
+static int test_sysdb_setup(void **state)
|
|
|
5ad689 |
+{
|
|
|
5ad689 |
+ int ret;
|
|
|
5ad689 |
+ struct certmap_test_ctx *test_ctx;
|
|
|
5ad689 |
+ struct sss_test_conf_param params[] = {
|
|
|
5ad689 |
+ { NULL, NULL }, /* Sentinel */
|
|
|
5ad689 |
+ };
|
|
|
5ad689 |
+
|
|
|
5ad689 |
+ assert_true(leak_check_setup());
|
|
|
5ad689 |
+
|
|
|
5ad689 |
+ test_ctx = talloc_zero(global_talloc_context,
|
|
|
5ad689 |
+ struct certmap_test_ctx);
|
|
|
5ad689 |
+ assert_non_null(test_ctx);
|
|
|
5ad689 |
+ check_leaks_push(test_ctx);
|
|
|
5ad689 |
+
|
|
|
5ad689 |
+ test_dom_suite_setup(TESTS_PATH);
|
|
|
5ad689 |
+
|
|
|
5ad689 |
+ test_ctx->tctx = create_dom_test_ctx(test_ctx, TESTS_PATH,
|
|
|
5ad689 |
+ TEST_CONF_DB, TEST_DOM_NAME,
|
|
|
5ad689 |
+ TEST_ID_PROVIDER, params);
|
|
|
5ad689 |
+ assert_non_null(test_ctx->tctx);
|
|
|
5ad689 |
+
|
|
|
5ad689 |
+ ret = sysdb_update_certmap(test_ctx->tctx->sysdb, certmap, false);
|
|
|
5ad689 |
+ assert_int_equal(ret, EOK);
|
|
|
5ad689 |
+
|
|
|
5ad689 |
+ test_ctx->id_ctx = talloc_zero(test_ctx->tctx, struct sdap_id_ctx);
|
|
|
5ad689 |
+ assert_non_null(test_ctx->id_ctx);
|
|
|
5ad689 |
+
|
|
|
5ad689 |
+ test_ctx->id_ctx->opts = talloc_zero(test_ctx->tctx, struct sdap_options);
|
|
|
5ad689 |
+ assert_non_null(test_ctx->id_ctx->opts);
|
|
|
5ad689 |
+
|
|
|
5ad689 |
+ test_ctx->id_ctx->be = talloc_zero(test_ctx->tctx, struct be_ctx);
|
|
|
5ad689 |
+ assert_non_null(test_ctx->id_ctx->be);
|
|
|
5ad689 |
+ test_ctx->id_ctx->be->domain = test_ctx->tctx->dom;
|
|
|
5ad689 |
+
|
|
|
5ad689 |
+ *state = test_ctx;
|
|
|
5ad689 |
+ return 0;
|
|
|
5ad689 |
+}
|
|
|
5ad689 |
+
|
|
|
5ad689 |
+static int test_sysdb_teardown(void **state)
|
|
|
5ad689 |
+{
|
|
|
5ad689 |
+ struct certmap_test_ctx *test_ctx =
|
|
|
5ad689 |
+ talloc_get_type(*state, struct certmap_test_ctx);
|
|
|
5ad689 |
+
|
|
|
5ad689 |
+ test_dom_suite_cleanup(TESTS_PATH, TEST_CONF_DB, TEST_DOM_NAME);
|
|
|
5ad689 |
+ talloc_free(test_ctx->tctx);
|
|
|
5ad689 |
+ assert_true(check_leaks_pop(test_ctx));
|
|
|
5ad689 |
+ talloc_free(test_ctx);
|
|
|
5ad689 |
+ assert_true(leak_check_teardown());
|
|
|
5ad689 |
+ return 0;
|
|
|
5ad689 |
+}
|
|
|
5ad689 |
+
|
|
|
5ad689 |
+static void test_sdap_certmap_init(void **state)
|
|
|
5ad689 |
+{
|
|
|
5ad689 |
+ int ret;
|
|
|
5ad689 |
+ struct certmap_test_ctx *test_ctx = talloc_get_type(*state,
|
|
|
5ad689 |
+ struct certmap_test_ctx);
|
|
|
5ad689 |
+
|
|
|
5ad689 |
+ ret = sdap_init_certmap(test_ctx, test_ctx->id_ctx);
|
|
|
5ad689 |
+ assert_int_equal(ret, EOK);
|
|
|
5ad689 |
+
|
|
|
5ad689 |
+ talloc_free(test_ctx->id_ctx->opts->sdap_certmap_ctx);
|
|
|
5ad689 |
+}
|
|
|
5ad689 |
+
|
|
|
5ad689 |
+static void test_sdap_get_sss_certmap(void **state)
|
|
|
5ad689 |
+{
|
|
|
5ad689 |
+ int ret;
|
|
|
5ad689 |
+ struct certmap_test_ctx *test_ctx = talloc_get_type(*state,
|
|
|
5ad689 |
+ struct certmap_test_ctx);
|
|
|
5ad689 |
+ struct sss_certmap_ctx *sss_certmap_ctx;
|
|
|
5ad689 |
+
|
|
|
5ad689 |
+ sss_certmap_ctx = sdap_get_sss_certmap(NULL);
|
|
|
5ad689 |
+ assert_null(sss_certmap_ctx);
|
|
|
5ad689 |
+
|
|
|
5ad689 |
+ ret = sdap_init_certmap(test_ctx, test_ctx->id_ctx);
|
|
|
5ad689 |
+ assert_int_equal(ret, EOK);
|
|
|
5ad689 |
+
|
|
|
5ad689 |
+ sss_certmap_ctx = sdap_get_sss_certmap(
|
|
|
5ad689 |
+ test_ctx->id_ctx->opts->sdap_certmap_ctx);
|
|
|
5ad689 |
+ assert_non_null(sss_certmap_ctx);
|
|
|
5ad689 |
+
|
|
|
5ad689 |
+ talloc_free(test_ctx->id_ctx->opts->sdap_certmap_ctx);
|
|
|
5ad689 |
+}
|
|
|
5ad689 |
+
|
|
|
5ad689 |
+static void test_sdap_certmap_init_twice(void **state)
|
|
|
5ad689 |
+{
|
|
|
5ad689 |
+ int ret;
|
|
|
5ad689 |
+ struct certmap_test_ctx *test_ctx = talloc_get_type(*state,
|
|
|
5ad689 |
+ struct certmap_test_ctx);
|
|
|
5ad689 |
+ struct sdap_certmap_ctx *sdap_certmap_ref;
|
|
|
5ad689 |
+ struct sss_certmap_ctx *sss_certmap_ref;
|
|
|
5ad689 |
+
|
|
|
5ad689 |
+ ret = sdap_init_certmap(test_ctx, test_ctx->id_ctx);
|
|
|
5ad689 |
+ assert_int_equal(ret, EOK);
|
|
|
5ad689 |
+
|
|
|
5ad689 |
+ sdap_certmap_ref = test_ctx->id_ctx->opts->sdap_certmap_ctx;
|
|
|
5ad689 |
+ sss_certmap_ref = sdap_get_sss_certmap(sdap_certmap_ref);
|
|
|
5ad689 |
+
|
|
|
5ad689 |
+ ret = sdap_init_certmap(test_ctx, test_ctx->id_ctx);
|
|
|
5ad689 |
+ assert_int_equal(ret, EOK);
|
|
|
5ad689 |
+
|
|
|
5ad689 |
+ assert_ptr_equal(sdap_certmap_ref,
|
|
|
5ad689 |
+ test_ctx->id_ctx->opts->sdap_certmap_ctx);
|
|
|
5ad689 |
+ assert_ptr_not_equal(sss_certmap_ref,
|
|
|
5ad689 |
+ sdap_get_sss_certmap(sdap_certmap_ref));
|
|
|
5ad689 |
+
|
|
|
5ad689 |
+ talloc_free(test_ctx->id_ctx->opts->sdap_certmap_ctx);
|
|
|
5ad689 |
+}
|
|
|
5ad689 |
+
|
|
|
5ad689 |
+
|
|
|
5ad689 |
+static void test_sdap_setup_certmap(void **state)
|
|
|
5ad689 |
+{
|
|
|
5ad689 |
+ int ret;
|
|
|
5ad689 |
+ struct certmap_test_ctx *test_ctx = talloc_get_type(*state,
|
|
|
5ad689 |
+ struct certmap_test_ctx);
|
|
|
5ad689 |
+ struct sdap_certmap_ctx *sdap_certmap_ref;
|
|
|
5ad689 |
+ struct sss_certmap_ctx *sss_certmap_ref;
|
|
|
5ad689 |
+
|
|
|
5ad689 |
+ ret = sdap_init_certmap(test_ctx, test_ctx->id_ctx);
|
|
|
5ad689 |
+ assert_int_equal(ret, EOK);
|
|
|
5ad689 |
+
|
|
|
5ad689 |
+ sdap_certmap_ref = test_ctx->id_ctx->opts->sdap_certmap_ctx;
|
|
|
5ad689 |
+ sss_certmap_ref = sdap_get_sss_certmap(sdap_certmap_ref);
|
|
|
5ad689 |
+
|
|
|
5ad689 |
+ ret = sdap_setup_certmap(NULL, NULL);
|
|
|
5ad689 |
+ assert_int_equal(ret, EINVAL);
|
|
|
5ad689 |
+ assert_ptr_equal(sdap_certmap_ref,
|
|
|
5ad689 |
+ test_ctx->id_ctx->opts->sdap_certmap_ctx);
|
|
|
5ad689 |
+ assert_ptr_equal(sss_certmap_ref, sdap_get_sss_certmap(sdap_certmap_ref));
|
|
|
5ad689 |
+
|
|
|
5ad689 |
+ ret = sdap_setup_certmap(NULL, certmap);
|
|
|
5ad689 |
+ assert_int_equal(ret, EINVAL);
|
|
|
5ad689 |
+ assert_ptr_equal(sdap_certmap_ref,
|
|
|
5ad689 |
+ test_ctx->id_ctx->opts->sdap_certmap_ctx);
|
|
|
5ad689 |
+ assert_ptr_equal(sss_certmap_ref, sdap_get_sss_certmap(sdap_certmap_ref));
|
|
|
5ad689 |
+
|
|
|
5ad689 |
+ ret = sdap_setup_certmap(sdap_certmap_ref, certmap);
|
|
|
5ad689 |
+ assert_int_equal(ret, EOK);
|
|
|
5ad689 |
+ assert_ptr_equal(sdap_certmap_ref,
|
|
|
5ad689 |
+ test_ctx->id_ctx->opts->sdap_certmap_ctx);
|
|
|
5ad689 |
+ assert_ptr_not_equal(sss_certmap_ref,
|
|
|
5ad689 |
+ sdap_get_sss_certmap(sdap_certmap_ref));
|
|
|
5ad689 |
+
|
|
|
5ad689 |
+ talloc_free(test_ctx->id_ctx->opts->sdap_certmap_ctx);
|
|
|
5ad689 |
+}
|
|
|
5ad689 |
+
|
|
|
5ad689 |
+int main(int argc, const char *argv[])
|
|
|
5ad689 |
+{
|
|
|
5ad689 |
+ int rv;
|
|
|
5ad689 |
+ poptContext pc;
|
|
|
5ad689 |
+ int opt;
|
|
|
5ad689 |
+ struct poptOption long_options[] = {
|
|
|
5ad689 |
+ POPT_AUTOHELP
|
|
|
5ad689 |
+ SSSD_DEBUG_OPTS
|
|
|
5ad689 |
+ POPT_TABLEEND
|
|
|
5ad689 |
+ };
|
|
|
5ad689 |
+
|
|
|
5ad689 |
+ const struct CMUnitTest tests[] = {
|
|
|
5ad689 |
+ cmocka_unit_test_setup_teardown(test_sdap_certmap_init,
|
|
|
5ad689 |
+ test_sysdb_setup,
|
|
|
5ad689 |
+ test_sysdb_teardown),
|
|
|
5ad689 |
+ cmocka_unit_test_setup_teardown(test_sdap_get_sss_certmap,
|
|
|
5ad689 |
+ test_sysdb_setup,
|
|
|
5ad689 |
+ test_sysdb_teardown),
|
|
|
5ad689 |
+ cmocka_unit_test_setup_teardown(test_sdap_certmap_init_twice,
|
|
|
5ad689 |
+ test_sysdb_setup,
|
|
|
5ad689 |
+ test_sysdb_teardown),
|
|
|
5ad689 |
+ cmocka_unit_test_setup_teardown(test_sdap_setup_certmap,
|
|
|
5ad689 |
+ test_sysdb_setup,
|
|
|
5ad689 |
+ test_sysdb_teardown),
|
|
|
5ad689 |
+ };
|
|
|
5ad689 |
+
|
|
|
5ad689 |
+ /* Set debug level to invalid value so we can deside if -d 0 was used. */
|
|
|
5ad689 |
+ debug_level = SSSDBG_INVALID;
|
|
|
5ad689 |
+
|
|
|
5ad689 |
+ pc = poptGetContext(argv[0], argc, argv, long_options, 0);
|
|
|
5ad689 |
+ while((opt = poptGetNextOpt(pc)) != -1) {
|
|
|
5ad689 |
+ switch(opt) {
|
|
|
5ad689 |
+ default:
|
|
|
5ad689 |
+ fprintf(stderr, "\nInvalid option %s: %s\n\n",
|
|
|
5ad689 |
+ poptBadOption(pc, 0), poptStrerror(opt));
|
|
|
5ad689 |
+ poptPrintUsage(pc, stderr, 0);
|
|
|
5ad689 |
+ return 1;
|
|
|
5ad689 |
+ }
|
|
|
5ad689 |
+ }
|
|
|
5ad689 |
+ poptFreeContext(pc);
|
|
|
5ad689 |
+
|
|
|
5ad689 |
+ DEBUG_CLI_INIT(debug_level);
|
|
|
5ad689 |
+
|
|
|
5ad689 |
+ tests_set_cwd();
|
|
|
5ad689 |
+ rv = cmocka_run_group_tests(tests, NULL, NULL);
|
|
|
5ad689 |
+
|
|
|
5ad689 |
+ return rv;
|
|
|
5ad689 |
+}
|
|
|
5ad689 |
--
|
|
|
5ad689 |
2.13.5
|
|
|
5ad689 |
|