LCOV - code coverage report
Current view: top level - providers/ipa - ipa_utils.c (source / functions) Hit Total Coverage
Test: coverage.info Lines: 15 19 78.9 %
Date: 2016-06-29 Functions: 1 1 100.0 %

          Line data    Source code
       1             : /*
       2             :     SSSD
       3             : 
       4             :     IPA Module utility functions
       5             : 
       6             :     Authors:
       7             :         Sumit Bose <sbose@redhat.com>
       8             : 
       9             :     Copyright (C) 2014 Red Hat
      10             : 
      11             :     This program is free software; you can redistribute it and/or modify
      12             :     it under the terms of the GNU General Public License as published by
      13             :     the Free Software Foundation; either version 3 of the License, or
      14             :     (at your option) any later version.
      15             : 
      16             :     This program is distributed in the hope that it will be useful,
      17             :     but WITHOUT ANY WARRANTY; without even the implied warranty of
      18             :     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      19             :     GNU General Public License for more details.
      20             : 
      21             :     You should have received a copy of the GNU General Public License
      22             :     along with this program.  If not, see <http://www.gnu.org/licenses/>.
      23             : */
      24             : 
      25             : #include "util/util.h"
      26             : 
      27             : #define OVERRIDE_ANCHOR_IPA_PREFIX ":IPA:"
      28             : #define OVERRIDE_ANCHOR_IPA_PREFIX_LEN (sizeof(OVERRIDE_ANCHOR_IPA_PREFIX) -1 )
      29             : 
      30           6 : errno_t split_ipa_anchor(TALLOC_CTX *mem_ctx, const char *anchor,
      31             :                          char **_anchor_domain, char **_ipa_uuid)
      32             : {
      33             :     const char *sep;
      34             : 
      35           6 :     if (anchor == NULL) {
      36           1 :         return EINVAL;
      37             :     }
      38           5 :     if (strncmp(OVERRIDE_ANCHOR_IPA_PREFIX, anchor,
      39             :                 OVERRIDE_ANCHOR_IPA_PREFIX_LEN) != 0) {
      40           1 :         DEBUG(SSSDBG_CRIT_FAILURE, "No IPA anchor [%s].\n", anchor);
      41           1 :         return ENOMSG;
      42             :     }
      43             : 
      44           4 :     sep = strchr(anchor + OVERRIDE_ANCHOR_IPA_PREFIX_LEN, ':');
      45           4 :     if (sep == NULL || sep[1] == '\0') {
      46           3 :         DEBUG(SSSDBG_CRIT_FAILURE, "Broken IPA anchor [%s].\n", anchor);
      47           3 :         return EINVAL;
      48             :     }
      49             : 
      50           1 :     *_anchor_domain = talloc_strndup(mem_ctx,
      51             :                                  anchor + OVERRIDE_ANCHOR_IPA_PREFIX_LEN,
      52           1 :                                  sep - anchor - OVERRIDE_ANCHOR_IPA_PREFIX_LEN);
      53           1 :     *_ipa_uuid = talloc_strdup(mem_ctx, sep + 1);
      54             : 
      55           1 :     if (*_anchor_domain == NULL || *_ipa_uuid == NULL) {
      56           0 :         DEBUG(SSSDBG_OP_FAILURE, "talloc_strndup failed.\n");
      57           0 :         talloc_free(*_anchor_domain);
      58           0 :         talloc_free(*_ipa_uuid);
      59           0 :         return ENOMEM;
      60             :     }
      61             : 
      62           1 :     return EOK;
      63             : }

Generated by: LCOV version 1.10