LCOV - code coverage report
Current view: top level - util - sss_tc_utf8.c (source / functions) Hit Total Coverage
Test: .coverage.total Lines: 23 27 85.2 %
Date: 2015-10-19 Functions: 3 3 100.0 %

          Line data    Source code
       1             : /*
       2             :     Authors:
       3             :         Jakub Hrozek <jhrozek@redhat.com>
       4             : 
       5             :     Copyright (C) 2011 Red Hat
       6             : 
       7             :     This program is free software; you can redistribute it and/or modify
       8             :     it under the terms of the GNU General Public License as published by
       9             :     the Free Software Foundation; either version 3 of the License, or
      10             :     (at your option) any later version.
      11             : 
      12             :     This program is distributed in the hope that it will be useful,
      13             :     but WITHOUT ANY WARRANTY; without even the implied warranty of
      14             :     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      15             :     GNU General Public License for more details.
      16             : 
      17             :     You should have received a copy of the GNU General Public License
      18             :     along with this program.  If not, see <http://www.gnu.org/licenses/>.
      19             : */
      20             : 
      21             : #include <talloc.h>
      22             : #include "util/sss_utf8.h"
      23             : 
      24             : char *
      25          89 : sss_tc_utf8_str_tolower(TALLOC_CTX *mem_ctx, const char *s)
      26             : {
      27             :     size_t nlen;
      28             :     uint8_t *ret;
      29             : 
      30          89 :     ret = sss_tc_utf8_tolower(mem_ctx, (const uint8_t *) s, strlen(s), &nlen);
      31          89 :     if (!ret) return NULL;
      32             : 
      33          89 :     ret = talloc_realloc(mem_ctx, ret, uint8_t, nlen+1);
      34          89 :     if (!ret) return NULL;
      35             : 
      36          89 :     ret[nlen] = '\0';
      37          89 :     return (char *) ret;
      38             : }
      39             : 
      40             : uint8_t *
      41          90 : sss_tc_utf8_tolower(TALLOC_CTX *mem_ctx, const uint8_t *s, size_t len, size_t *_nlen)
      42             : {
      43             :     uint8_t *lower;
      44             :     uint8_t *ret;
      45             :     size_t nlen;
      46             : 
      47          90 :     lower = sss_utf8_tolower(s, len, &nlen);
      48          90 :     if (!lower) return NULL;
      49             : 
      50          90 :     ret = talloc_memdup(mem_ctx, lower, nlen);
      51          90 :     sss_utf8_free(lower);
      52          90 :     if (!ret) return NULL;
      53             : 
      54          90 :     *_nlen = nlen;
      55          90 :     return ret;
      56             : }
      57             : 
      58         829 : errno_t sss_filter_sanitize_for_dom(TALLOC_CTX *mem_ctx,
      59             :                                     const char *input,
      60             :                                     struct sss_domain_info *dom,
      61             :                                     char **sanitized,
      62             :                                     char **lc_sanitized)
      63             : {
      64             :     int ret;
      65             : 
      66         829 :     ret = sss_filter_sanitize(mem_ctx, input, sanitized);
      67         829 :     if (ret != EOK) {
      68           0 :         DEBUG(SSSDBG_OP_FAILURE, "sss_filter_sanitize failed.\n");
      69           0 :         return ret;
      70             :     }
      71             : 
      72         829 :     if (dom->case_sensitive) {
      73         807 :         *lc_sanitized = talloc_strdup(mem_ctx, *sanitized);
      74             :     } else {
      75          22 :         *lc_sanitized = sss_tc_utf8_str_tolower(mem_ctx, *sanitized);
      76             :     }
      77             : 
      78         829 :     if (*lc_sanitized == NULL) {
      79           0 :         DEBUG(SSSDBG_OP_FAILURE, "%s failed.\n",
      80             :                                               dom->case_sensitive ?
      81             :                                                     "talloc_strdup" :
      82             :                                                     "sss_tc_utf8_str_tolower");
      83           0 :         return ENOMEM;
      84             :     }
      85             : 
      86         829 :     return EOK;
      87             : }

Generated by: LCOV version 1.10