|
|
6cf099 |
From 5654903a0be960a2ec5be5bfb77cc3263e11e58c Mon Sep 17 00:00:00 2001
|
|
|
6cf099 |
From: Sumit Bose <sbose@redhat.com>
|
|
|
6cf099 |
Date: Thu, 30 Jul 2015 16:52:42 +0200
|
|
|
6cf099 |
Subject: [PATCH 48/57] krb5 utils: add sss_krb5_realm_has_proxy()
|
|
|
6cf099 |
|
|
|
6cf099 |
Reviewed-by: Alexander Bokovoy <abokovoy@redhat.com>
|
|
|
6cf099 |
Reviewed-by: Jakub Hrozek <jhrozek@redhat.com>
|
|
|
6cf099 |
---
|
|
|
6cf099 |
Makefile.am | 1 +
|
|
|
6cf099 |
src/tests/krb5_proxy_check_test_data.conf | 8 +++++
|
|
|
6cf099 |
src/tests/krb5_utils-tests.c | 17 +++++++++
|
|
|
6cf099 |
src/util/sss_krb5.c | 57 +++++++++++++++++++++++++++++++
|
|
|
6cf099 |
src/util/sss_krb5.h | 2 ++
|
|
|
6cf099 |
5 files changed, 85 insertions(+)
|
|
|
6cf099 |
create mode 100644 src/tests/krb5_proxy_check_test_data.conf
|
|
|
6cf099 |
|
|
|
6cf099 |
diff --git a/Makefile.am b/Makefile.am
|
|
|
6cf099 |
index 5345d90d22cd285a5268ac50a6b527645acdb351..8b64317d6dce9a1ee8614916395b9afd9f11f382 100644
|
|
|
6cf099 |
--- a/Makefile.am
|
|
|
6cf099 |
+++ b/Makefile.am
|
|
|
6cf099 |
@@ -366,6 +366,7 @@ dist_noinst_SCRIPTS = \
|
|
|
6cf099 |
src/tests/pysss_murmur-test.py2.sh \
|
|
|
6cf099 |
src/tests/pysss_murmur-test.py3.sh \
|
|
|
6cf099 |
src/tests/python-test.py \
|
|
|
6cf099 |
+ src/tests/krb5_proxy_check_test_data.conf \
|
|
|
6cf099 |
$(NULL)
|
|
|
6cf099 |
|
|
|
6cf099 |
dist_noinst_DATA = \
|
|
|
6cf099 |
diff --git a/src/tests/krb5_proxy_check_test_data.conf b/src/tests/krb5_proxy_check_test_data.conf
|
|
|
6cf099 |
new file mode 100644
|
|
|
6cf099 |
index 0000000000000000000000000000000000000000..eb74dbfa47d643668688d5c789b5962698c3d17c
|
|
|
6cf099 |
--- /dev/null
|
|
|
6cf099 |
+++ b/src/tests/krb5_proxy_check_test_data.conf
|
|
|
6cf099 |
@@ -0,0 +1,8 @@
|
|
|
6cf099 |
+[realms]
|
|
|
6cf099 |
+ REALM = {
|
|
|
6cf099 |
+ kdc = hello
|
|
|
6cf099 |
+ }
|
|
|
6cf099 |
+
|
|
|
6cf099 |
+ REALM_PROXY = {
|
|
|
6cf099 |
+ kdc = https://hello
|
|
|
6cf099 |
+ }
|
|
|
6cf099 |
diff --git a/src/tests/krb5_utils-tests.c b/src/tests/krb5_utils-tests.c
|
|
|
6cf099 |
index 650ed48592768c214156d5274e654a447be98e36..9a25b09cdc136651a7117327036dd51b8ff23606 100644
|
|
|
6cf099 |
--- a/src/tests/krb5_utils-tests.c
|
|
|
6cf099 |
+++ b/src/tests/krb5_utils-tests.c
|
|
|
6cf099 |
@@ -684,6 +684,22 @@ START_TEST(test_parse_krb5_map_user)
|
|
|
6cf099 |
}
|
|
|
6cf099 |
END_TEST
|
|
|
6cf099 |
|
|
|
6cf099 |
+START_TEST(test_sss_krb5_realm_has_proxy)
|
|
|
6cf099 |
+{
|
|
|
6cf099 |
+ krb5_error_code kerr;
|
|
|
6cf099 |
+ long perr;
|
|
|
6cf099 |
+
|
|
|
6cf099 |
+ fail_unless(sss_krb5_realm_has_proxy(NULL) == false);
|
|
|
6cf099 |
+
|
|
|
6cf099 |
+ setenv("KRB5_CONFIG", "/dev/null", 1);
|
|
|
6cf099 |
+ fail_unless(sss_krb5_realm_has_proxy("REALM") == false);
|
|
|
6cf099 |
+
|
|
|
6cf099 |
+ setenv("KRB5_CONFIG", ABS_SRC_DIR"/src/tests/krb5_proxy_check_test_data.conf", 1);
|
|
|
6cf099 |
+ fail_unless(sss_krb5_realm_has_proxy("REALM") == false);
|
|
|
6cf099 |
+ fail_unless(sss_krb5_realm_has_proxy("REALM_PROXY") == true);
|
|
|
6cf099 |
+}
|
|
|
6cf099 |
+END_TEST
|
|
|
6cf099 |
+
|
|
|
6cf099 |
Suite *krb5_utils_suite (void)
|
|
|
6cf099 |
{
|
|
|
6cf099 |
Suite *s = suite_create ("krb5_utils");
|
|
|
6cf099 |
@@ -723,6 +739,7 @@ Suite *krb5_utils_suite (void)
|
|
|
6cf099 |
TCase *tc_krb5_helpers = tcase_create("Helper functions");
|
|
|
6cf099 |
tcase_add_test(tc_krb5_helpers, test_compare_principal_realm);
|
|
|
6cf099 |
tcase_add_test(tc_krb5_helpers, test_parse_krb5_map_user);
|
|
|
6cf099 |
+ tcase_add_test(tc_krb5_helpers, test_sss_krb5_realm_has_proxy);
|
|
|
6cf099 |
suite_add_tcase(s, tc_krb5_helpers);
|
|
|
6cf099 |
|
|
|
6cf099 |
return s;
|
|
|
6cf099 |
diff --git a/src/util/sss_krb5.c b/src/util/sss_krb5.c
|
|
|
6cf099 |
index e5c2121da575b174c8b6a9a90835f2c97f807f37..2e128db3c9fcb0dfa88cab1ed799abd714ad8ba6 100644
|
|
|
6cf099 |
--- a/src/util/sss_krb5.c
|
|
|
6cf099 |
+++ b/src/util/sss_krb5.c
|
|
|
6cf099 |
@@ -20,6 +20,7 @@
|
|
|
6cf099 |
#include <stdio.h>
|
|
|
6cf099 |
#include <errno.h>
|
|
|
6cf099 |
#include <talloc.h>
|
|
|
6cf099 |
+#include <profile.h>
|
|
|
6cf099 |
|
|
|
6cf099 |
#include "config.h"
|
|
|
6cf099 |
|
|
|
6cf099 |
@@ -1069,3 +1070,59 @@ krb5_error_code sss_krb5_kt_have_content(krb5_context context,
|
|
|
6cf099 |
return 0;
|
|
|
6cf099 |
#endif
|
|
|
6cf099 |
}
|
|
|
6cf099 |
+
|
|
|
6cf099 |
+#define KDC_PROXY_INDICATOR "https://"
|
|
|
6cf099 |
+#define KDC_PROXY_INDICATOR_LEN (sizeof(KDC_PROXY_INDICATOR) - 1)
|
|
|
6cf099 |
+
|
|
|
6cf099 |
+bool sss_krb5_realm_has_proxy(const char *realm)
|
|
|
6cf099 |
+{
|
|
|
6cf099 |
+ krb5_context context = NULL;
|
|
|
6cf099 |
+ krb5_error_code kerr;
|
|
|
6cf099 |
+ struct _profile_t *profile = NULL;
|
|
|
6cf099 |
+ const char *profile_path[4] = {"realms", NULL, "kdc", NULL};
|
|
|
6cf099 |
+ char **list = NULL;
|
|
|
6cf099 |
+ bool res = false;
|
|
|
6cf099 |
+ size_t c;
|
|
|
6cf099 |
+
|
|
|
6cf099 |
+ if (realm == NULL) {
|
|
|
6cf099 |
+ return false;
|
|
|
6cf099 |
+ }
|
|
|
6cf099 |
+
|
|
|
6cf099 |
+ kerr = krb5_init_context(&context);
|
|
|
6cf099 |
+ if (kerr != 0) {
|
|
|
6cf099 |
+ DEBUG(SSSDBG_OP_FAILURE, "krb5_init_context failed.\n");
|
|
|
6cf099 |
+ return false;
|
|
|
6cf099 |
+ }
|
|
|
6cf099 |
+
|
|
|
6cf099 |
+ kerr = krb5_get_profile(context, &profile);
|
|
|
6cf099 |
+ if (kerr != 0) {
|
|
|
6cf099 |
+ DEBUG(SSSDBG_OP_FAILURE, "krb5_get_profile failed.\n");
|
|
|
6cf099 |
+ goto done;
|
|
|
6cf099 |
+ }
|
|
|
6cf099 |
+
|
|
|
6cf099 |
+ profile_path[1] = realm;
|
|
|
6cf099 |
+
|
|
|
6cf099 |
+ kerr = profile_get_values(profile, profile_path, &list);
|
|
|
6cf099 |
+ if (kerr != 0) {
|
|
|
6cf099 |
+ DEBUG(SSSDBG_OP_FAILURE, "profile_get_values failed.\n");
|
|
|
6cf099 |
+ goto done;
|
|
|
6cf099 |
+ }
|
|
|
6cf099 |
+
|
|
|
6cf099 |
+ for (c = 0; list[c] != NULL; c++) {
|
|
|
6cf099 |
+ if (strncasecmp(KDC_PROXY_INDICATOR, list[c],
|
|
|
6cf099 |
+ KDC_PROXY_INDICATOR_LEN) == 0) {
|
|
|
6cf099 |
+ DEBUG(SSSDBG_TRACE_ALL,
|
|
|
6cf099 |
+ "Found KDC Proxy indicator [%s] in [%s].\n",
|
|
|
6cf099 |
+ KDC_PROXY_INDICATOR, list[c]);
|
|
|
6cf099 |
+ res = true;
|
|
|
6cf099 |
+ break;
|
|
|
6cf099 |
+ }
|
|
|
6cf099 |
+ }
|
|
|
6cf099 |
+
|
|
|
6cf099 |
+done:
|
|
|
6cf099 |
+ profile_free_list(list);
|
|
|
6cf099 |
+ profile_release(profile);
|
|
|
6cf099 |
+ krb5_free_context(context);
|
|
|
6cf099 |
+
|
|
|
6cf099 |
+ return res;
|
|
|
6cf099 |
+}
|
|
|
6cf099 |
diff --git a/src/util/sss_krb5.h b/src/util/sss_krb5.h
|
|
|
6cf099 |
index 462dbbe0bda8969432c8ac2f062a0123c1f098f0..fdaeb49314764e096448f342a054dc6938f0c248 100644
|
|
|
6cf099 |
--- a/src/util/sss_krb5.h
|
|
|
6cf099 |
+++ b/src/util/sss_krb5.h
|
|
|
6cf099 |
@@ -189,4 +189,6 @@ sss_krb5_get_primary(TALLOC_CTX *mem_ctx,
|
|
|
6cf099 |
|
|
|
6cf099 |
krb5_error_code sss_krb5_kt_have_content(krb5_context context,
|
|
|
6cf099 |
krb5_keytab keytab);
|
|
|
6cf099 |
+
|
|
|
6cf099 |
+bool sss_krb5_realm_has_proxy(const char *realm);
|
|
|
6cf099 |
#endif /* __SSS_KRB5_H__ */
|
|
|
6cf099 |
--
|
|
|
6cf099 |
2.4.3
|
|
|
6cf099 |
|