summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Makefile.am2
-rw-r--r--src/providers/ipa/ipa_id.h2
-rw-r--r--src/providers/ipa/ipa_utils.c63
-rw-r--r--src/tests/cmocka/test_sysdb_views.c32
4 files changed, 99 insertions, 0 deletions
diff --git a/Makefile.am b/Makefile.am
index 156ef3c4e..53ace65b9 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -2064,6 +2064,7 @@ endif # BUILD_IFP
test_sysdb_views_SOURCES = \
src/tests/cmocka/test_sysdb_views.c \
+ src/providers/ipa/ipa_utils.c \
$(NULL)
test_sysdb_views_CFLAGS = \
$(AM_CFLAGS) \
@@ -2387,6 +2388,7 @@ libsss_ipa_la_SOURCES = \
src/providers/ipa/ipa_subdomains_id.c \
src/providers/ipa/ipa_subdomains_ext_groups.c \
src/providers/ipa/ipa_views.c \
+ src/providers/ipa/ipa_utils.c \
src/providers/ipa/ipa_s2n_exop.c \
src/providers/ipa/ipa_hbac_hosts.c \
src/providers/ipa/ipa_hbac_private.h \
diff --git a/src/providers/ipa/ipa_id.h b/src/providers/ipa/ipa_id.h
index e13aded21..033ac40f1 100644
--- a/src/providers/ipa/ipa_id.h
+++ b/src/providers/ipa/ipa_id.h
@@ -103,4 +103,6 @@ struct tevent_req *ipa_subdomain_account_send(TALLOC_CTX *memctx,
errno_t ipa_subdomain_account_recv(struct tevent_req *req, int *dp_error_out);
+errno_t split_ipa_anchor(TALLOC_CTX *mem_ctx, const char *anchor,
+ char **_anchor_domain, char **_ipa_uuid);
#endif
diff --git a/src/providers/ipa/ipa_utils.c b/src/providers/ipa/ipa_utils.c
new file mode 100644
index 000000000..86ba51c8a
--- /dev/null
+++ b/src/providers/ipa/ipa_utils.c
@@ -0,0 +1,63 @@
+/*
+ SSSD
+
+ IPA Module utility functions
+
+ Authors:
+ Sumit Bose <sbose@redhat.com>
+
+ Copyright (C) 2014 Red Hat
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
+*/
+
+#include "util/util.h"
+
+#define OVERRIDE_ANCHOR_IPA_PREFIX ":IPA:"
+#define OVERRIDE_ANCHOR_IPA_PREFIX_LEN (sizeof(OVERRIDE_ANCHOR_IPA_PREFIX) -1 )
+
+errno_t split_ipa_anchor(TALLOC_CTX *mem_ctx, const char *anchor,
+ char **_anchor_domain, char **_ipa_uuid)
+{
+ const char *sep;
+
+ if (anchor == NULL) {
+ return EINVAL;
+ }
+ if (strncmp(OVERRIDE_ANCHOR_IPA_PREFIX, anchor,
+ OVERRIDE_ANCHOR_IPA_PREFIX_LEN) != 0) {
+ DEBUG(SSSDBG_CRIT_FAILURE, "No IPA anchor [%s].\n", anchor);
+ return ENOMSG;
+ }
+
+ sep = strchr(anchor + OVERRIDE_ANCHOR_IPA_PREFIX_LEN, ':');
+ if (sep == NULL || sep[1] == '\0') {
+ DEBUG(SSSDBG_CRIT_FAILURE, "Broken IPA anchor [%s].\n", anchor);
+ return EINVAL;
+ }
+
+ *_anchor_domain = talloc_strndup(mem_ctx,
+ anchor + OVERRIDE_ANCHOR_IPA_PREFIX_LEN,
+ sep - anchor - OVERRIDE_ANCHOR_IPA_PREFIX_LEN);
+ *_ipa_uuid = talloc_strdup(mem_ctx, sep + 1);
+
+ if (*_anchor_domain == NULL || *_ipa_uuid == NULL) {
+ DEBUG(SSSDBG_OP_FAILURE, "talloc_strndup failed.\n");
+ talloc_free(*_anchor_domain);
+ talloc_free(*_ipa_uuid);
+ return ENOMEM;
+ }
+
+ return EOK;
+}
diff --git a/src/tests/cmocka/test_sysdb_views.c b/src/tests/cmocka/test_sysdb_views.c
index 9fb2d7201..0dc51443b 100644
--- a/src/tests/cmocka/test_sysdb_views.c
+++ b/src/tests/cmocka/test_sysdb_views.c
@@ -29,6 +29,7 @@
#include <popt.h>
#include "tests/cmocka/common_mock.h"
+#include "providers/ipa/ipa_id.h"
#define TESTS_PATH "tests_sysdb_views"
#define TEST_CONF_FILE "tests_conf.ldb"
@@ -189,6 +190,35 @@ void test_sysdb_add_overrides_to_object(void **state)
assert_int_equal(ldb_val_string_cmp(&el->values[1], "OVERRIDEKEY2"), 0);
}
+void test_split_ipa_anchor(void **state)
+{
+ int ret;
+ char *dom;
+ char *uuid;
+ struct sysdb_test_ctx *test_ctx = talloc_get_type_abort(*state,
+ struct sysdb_test_ctx);
+
+ ret = split_ipa_anchor(test_ctx, NULL, &dom, &uuid);
+ assert_int_equal(ret, EINVAL);
+
+ ret = split_ipa_anchor(test_ctx, "fwfkwjfkw", &dom, &uuid);
+ assert_int_equal(ret, ENOMSG);
+
+ ret = split_ipa_anchor(test_ctx, ":IPA:", &dom, &uuid);
+ assert_int_equal(ret, EINVAL);
+
+ ret = split_ipa_anchor(test_ctx, ":IPA:abc", &dom, &uuid);
+ assert_int_equal(ret, EINVAL);
+
+ ret = split_ipa_anchor(test_ctx, ":IPA:abc:", &dom, &uuid);
+ assert_int_equal(ret, EINVAL);
+
+ ret = split_ipa_anchor(test_ctx, ":IPA:abc:def", &dom, &uuid);
+ assert_int_equal(ret, EOK);
+ assert_string_equal(dom, "abc");
+ assert_string_equal(uuid, "def");
+}
+
int main(int argc, const char *argv[])
{
int rv;
@@ -206,6 +236,8 @@ int main(int argc, const char *argv[])
const UnitTest tests[] = {
unit_test_setup_teardown(test_sysdb_add_overrides_to_object,
test_sysdb_setup, test_sysdb_teardown),
+ unit_test_setup_teardown(test_split_ipa_anchor,
+ test_sysdb_setup, test_sysdb_teardown),
};
/* Set debug level to invalid value so we can deside if -d 0 was used. */