summaryrefslogtreecommitdiffstats
path: root/src/providers/ipa/ipa_utils.c
diff options
context:
space:
mode:
authorSumit Bose <sbose@redhat.com>2014-11-06 13:13:27 +0100
committerJakub Hrozek <jhrozek@redhat.com>2014-11-20 10:52:38 +0100
commit8eb981dd8bc85aee7a913c6f0096ad47f3382339 (patch)
tree5a97040329b13209dbea291ec2d9b827428c8029 /src/providers/ipa/ipa_utils.c
parent907a7c626db407d19d4cae85c2db7d3561120349 (diff)
downloadsssd-8eb981dd8bc85aee7a913c6f0096ad47f3382339.tar.gz
sssd-8eb981dd8bc85aee7a913c6f0096ad47f3382339.tar.xz
sssd-8eb981dd8bc85aee7a913c6f0096ad47f3382339.zip
ipa: add split_ipa_anchor()
This call extracts the domain and the UUID part from an IPA override anchor. Related to https://fedorahosted.org/sssd/ticket/2481 Reviewed-by: Jakub Hrozek <jhrozek@redhat.com>
Diffstat (limited to 'src/providers/ipa/ipa_utils.c')
-rw-r--r--src/providers/ipa/ipa_utils.c63
1 files changed, 63 insertions, 0 deletions
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;
+}