Blame SOURCES/0096-ipa-add-split_ipa_anchor.patch

905b4d
From 7c8abc07058b37e743b1530c9e4a66e2d517e3c3 Mon Sep 17 00:00:00 2001
905b4d
From: Sumit Bose <sbose@redhat.com>
905b4d
Date: Thu, 6 Nov 2014 13:13:27 +0100
905b4d
Subject: [PATCH 096/104] ipa: add split_ipa_anchor()
905b4d
905b4d
This call extracts the domain and the UUID part from an IPA override
905b4d
anchor.
905b4d
905b4d
Related to https://fedorahosted.org/sssd/ticket/2481
905b4d
905b4d
Reviewed-by: Jakub Hrozek <jhrozek@redhat.com>
905b4d
---
905b4d
 Makefile.am                         |  2 ++
905b4d
 src/providers/ipa/ipa_id.h          |  2 ++
905b4d
 src/providers/ipa/ipa_utils.c       | 63 +++++++++++++++++++++++++++++++++++++
905b4d
 src/tests/cmocka/test_sysdb_views.c | 32 +++++++++++++++++++
905b4d
 4 files changed, 99 insertions(+)
905b4d
 create mode 100644 src/providers/ipa/ipa_utils.c
905b4d
905b4d
diff --git a/Makefile.am b/Makefile.am
905b4d
index 156ef3c4eab1510126d2bfb47c06163885b8acfe..53ace65b9a9647ffdaff0776d5a55d3e7393a38c 100644
905b4d
--- a/Makefile.am
905b4d
+++ b/Makefile.am
905b4d
@@ -2064,6 +2064,7 @@ endif # BUILD_IFP
905b4d
 
905b4d
 test_sysdb_views_SOURCES = \
905b4d
     src/tests/cmocka/test_sysdb_views.c \
905b4d
+    src/providers/ipa/ipa_utils.c \
905b4d
     $(NULL)
905b4d
 test_sysdb_views_CFLAGS = \
905b4d
     $(AM_CFLAGS) \
905b4d
@@ -2387,6 +2388,7 @@ libsss_ipa_la_SOURCES = \
905b4d
     src/providers/ipa/ipa_subdomains_id.c \
905b4d
     src/providers/ipa/ipa_subdomains_ext_groups.c \
905b4d
     src/providers/ipa/ipa_views.c \
905b4d
+    src/providers/ipa/ipa_utils.c \
905b4d
     src/providers/ipa/ipa_s2n_exop.c \
905b4d
     src/providers/ipa/ipa_hbac_hosts.c \
905b4d
     src/providers/ipa/ipa_hbac_private.h \
905b4d
diff --git a/src/providers/ipa/ipa_id.h b/src/providers/ipa/ipa_id.h
905b4d
index e13aded213ace8557dfccfc68e04d9ff69fae221..033ac40f1d7a7d8c4a968374ee190a5bcb17819c 100644
905b4d
--- a/src/providers/ipa/ipa_id.h
905b4d
+++ b/src/providers/ipa/ipa_id.h
905b4d
@@ -103,4 +103,6 @@ struct tevent_req *ipa_subdomain_account_send(TALLOC_CTX *memctx,
905b4d
 
905b4d
 errno_t ipa_subdomain_account_recv(struct tevent_req *req, int *dp_error_out);
905b4d
 
905b4d
+errno_t split_ipa_anchor(TALLOC_CTX *mem_ctx, const char *anchor,
905b4d
+                         char **_anchor_domain, char **_ipa_uuid);
905b4d
 #endif
905b4d
diff --git a/src/providers/ipa/ipa_utils.c b/src/providers/ipa/ipa_utils.c
905b4d
new file mode 100644
905b4d
index 0000000000000000000000000000000000000000..86ba51c8adb49c4e0cabccf1ade522b582a8f4d7
905b4d
--- /dev/null
905b4d
+++ b/src/providers/ipa/ipa_utils.c
905b4d
@@ -0,0 +1,63 @@
905b4d
+/*
905b4d
+    SSSD
905b4d
+
905b4d
+    IPA Module utility functions
905b4d
+
905b4d
+    Authors:
905b4d
+        Sumit Bose <sbose@redhat.com>
905b4d
+
905b4d
+    Copyright (C) 2014 Red Hat
905b4d
+
905b4d
+    This program is free software; you can redistribute it and/or modify
905b4d
+    it under the terms of the GNU General Public License as published by
905b4d
+    the Free Software Foundation; either version 3 of the License, or
905b4d
+    (at your option) any later version.
905b4d
+
905b4d
+    This program is distributed in the hope that it will be useful,
905b4d
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
905b4d
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
905b4d
+    GNU General Public License for more details.
905b4d
+
905b4d
+    You should have received a copy of the GNU General Public License
905b4d
+    along with this program.  If not, see <http://www.gnu.org/licenses/>.
905b4d
+*/
905b4d
+
905b4d
+#include "util/util.h"
905b4d
+
905b4d
+#define OVERRIDE_ANCHOR_IPA_PREFIX ":IPA:"
905b4d
+#define OVERRIDE_ANCHOR_IPA_PREFIX_LEN (sizeof(OVERRIDE_ANCHOR_IPA_PREFIX) -1 )
905b4d
+
905b4d
+errno_t split_ipa_anchor(TALLOC_CTX *mem_ctx, const char *anchor,
905b4d
+                         char **_anchor_domain, char **_ipa_uuid)
905b4d
+{
905b4d
+    const char *sep;
905b4d
+
905b4d
+    if (anchor == NULL) {
905b4d
+        return EINVAL;
905b4d
+    }
905b4d
+    if (strncmp(OVERRIDE_ANCHOR_IPA_PREFIX, anchor,
905b4d
+                OVERRIDE_ANCHOR_IPA_PREFIX_LEN) != 0) {
905b4d
+        DEBUG(SSSDBG_CRIT_FAILURE, "No IPA anchor [%s].\n", anchor);
905b4d
+        return ENOMSG;
905b4d
+    }
905b4d
+
905b4d
+    sep = strchr(anchor + OVERRIDE_ANCHOR_IPA_PREFIX_LEN, ':');
905b4d
+    if (sep == NULL || sep[1] == '\0') {
905b4d
+        DEBUG(SSSDBG_CRIT_FAILURE, "Broken IPA anchor [%s].\n", anchor);
905b4d
+        return EINVAL;
905b4d
+    }
905b4d
+
905b4d
+    *_anchor_domain = talloc_strndup(mem_ctx,
905b4d
+                                 anchor + OVERRIDE_ANCHOR_IPA_PREFIX_LEN,
905b4d
+                                 sep - anchor - OVERRIDE_ANCHOR_IPA_PREFIX_LEN);
905b4d
+    *_ipa_uuid = talloc_strdup(mem_ctx, sep + 1);
905b4d
+
905b4d
+    if (*_anchor_domain == NULL || *_ipa_uuid == NULL) {
905b4d
+        DEBUG(SSSDBG_OP_FAILURE, "talloc_strndup failed.\n");
905b4d
+        talloc_free(*_anchor_domain);
905b4d
+        talloc_free(*_ipa_uuid);
905b4d
+        return ENOMEM;
905b4d
+    }
905b4d
+
905b4d
+    return EOK;
905b4d
+}
905b4d
diff --git a/src/tests/cmocka/test_sysdb_views.c b/src/tests/cmocka/test_sysdb_views.c
905b4d
index 9fb2d7201d06e84be83d6a516c5e3a0f15ec0639..0dc51443b406673f131cc69be4d781f7c49e538c 100644
905b4d
--- a/src/tests/cmocka/test_sysdb_views.c
905b4d
+++ b/src/tests/cmocka/test_sysdb_views.c
905b4d
@@ -29,6 +29,7 @@
905b4d
 #include <popt.h>
905b4d
 
905b4d
 #include "tests/cmocka/common_mock.h"
905b4d
+#include "providers/ipa/ipa_id.h"
905b4d
 
905b4d
 #define TESTS_PATH "tests_sysdb_views"
905b4d
 #define TEST_CONF_FILE "tests_conf.ldb"
905b4d
@@ -189,6 +190,35 @@ void test_sysdb_add_overrides_to_object(void **state)
905b4d
     assert_int_equal(ldb_val_string_cmp(&el->values[1], "OVERRIDEKEY2"), 0);
905b4d
 }
905b4d
 
905b4d
+void test_split_ipa_anchor(void **state)
905b4d
+{
905b4d
+    int ret;
905b4d
+    char *dom;
905b4d
+    char *uuid;
905b4d
+    struct sysdb_test_ctx *test_ctx = talloc_get_type_abort(*state,
905b4d
+                                                         struct sysdb_test_ctx);
905b4d
+
905b4d
+    ret = split_ipa_anchor(test_ctx, NULL, &dom, &uuid);
905b4d
+    assert_int_equal(ret, EINVAL);
905b4d
+
905b4d
+    ret = split_ipa_anchor(test_ctx, "fwfkwjfkw", &dom, &uuid);
905b4d
+    assert_int_equal(ret, ENOMSG);
905b4d
+
905b4d
+    ret = split_ipa_anchor(test_ctx, ":IPA:", &dom, &uuid);
905b4d
+    assert_int_equal(ret, EINVAL);
905b4d
+
905b4d
+    ret = split_ipa_anchor(test_ctx, ":IPA:abc", &dom, &uuid);
905b4d
+    assert_int_equal(ret, EINVAL);
905b4d
+
905b4d
+    ret = split_ipa_anchor(test_ctx, ":IPA:abc:", &dom, &uuid);
905b4d
+    assert_int_equal(ret, EINVAL);
905b4d
+
905b4d
+    ret = split_ipa_anchor(test_ctx, ":IPA:abc:def", &dom, &uuid);
905b4d
+    assert_int_equal(ret, EOK);
905b4d
+    assert_string_equal(dom, "abc");
905b4d
+    assert_string_equal(uuid, "def");
905b4d
+}
905b4d
+
905b4d
 int main(int argc, const char *argv[])
905b4d
 {
905b4d
     int rv;
905b4d
@@ -206,6 +236,8 @@ int main(int argc, const char *argv[])
905b4d
     const UnitTest tests[] = {
905b4d
         unit_test_setup_teardown(test_sysdb_add_overrides_to_object,
905b4d
                                  test_sysdb_setup, test_sysdb_teardown),
905b4d
+        unit_test_setup_teardown(test_split_ipa_anchor,
905b4d
+                                 test_sysdb_setup, test_sysdb_teardown),
905b4d
     };
905b4d
 
905b4d
     /* Set debug level to invalid value so we can deside if -d 0 was used. */
905b4d
-- 
905b4d
1.9.3
905b4d