LCOV - code coverage report
Current view: top level - util - sss_tc_utf8.c (source / functions) Hit Total Coverage
Test: coverage.info Lines: 23 27 85.2 %
Date: 2016-06-29 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/util.h"
      23             : #include "util/sss_utf8.h"
      24             : 
      25             : char *
      26          93 : sss_tc_utf8_str_tolower(TALLOC_CTX *mem_ctx, const char *s)
      27             : {
      28             :     size_t nlen;
      29             :     uint8_t *ret;
      30             : 
      31          93 :     ret = sss_tc_utf8_tolower(mem_ctx, (const uint8_t *) s, strlen(s), &nlen);
      32          93 :     if (!ret) return NULL;
      33             : 
      34          93 :     ret = talloc_realloc(mem_ctx, ret, uint8_t, nlen+1);
      35          93 :     if (!ret) return NULL;
      36             : 
      37          93 :     ret[nlen] = '\0';
      38          93 :     return (char *) ret;
      39             : }
      40             : 
      41             : uint8_t *
      42          94 : sss_tc_utf8_tolower(TALLOC_CTX *mem_ctx, const uint8_t *s, size_t len, size_t *_nlen)
      43             : {
      44             :     uint8_t *lower;
      45             :     uint8_t *ret;
      46             :     size_t nlen;
      47             : 
      48          94 :     lower = sss_utf8_tolower(s, len, &nlen);
      49          94 :     if (!lower) return NULL;
      50             : 
      51          94 :     ret = talloc_memdup(mem_ctx, lower, nlen);
      52          94 :     sss_utf8_free(lower);
      53          94 :     if (!ret) return NULL;
      54             : 
      55          94 :     *_nlen = nlen;
      56          94 :     return ret;
      57             : }
      58             : 
      59         951 : errno_t sss_filter_sanitize_for_dom(TALLOC_CTX *mem_ctx,
      60             :                                     const char *input,
      61             :                                     struct sss_domain_info *dom,
      62             :                                     char **sanitized,
      63             :                                     char **lc_sanitized)
      64             : {
      65             :     int ret;
      66             : 
      67         951 :     ret = sss_filter_sanitize(mem_ctx, input, sanitized);
      68         951 :     if (ret != EOK) {
      69           0 :         DEBUG(SSSDBG_OP_FAILURE, "sss_filter_sanitize failed.\n");
      70           0 :         return ret;
      71             :     }
      72             : 
      73         951 :     if (dom->case_sensitive) {
      74         929 :         *lc_sanitized = talloc_strdup(mem_ctx, *sanitized);
      75             :     } else {
      76          22 :         *lc_sanitized = sss_tc_utf8_str_tolower(mem_ctx, *sanitized);
      77             :     }
      78             : 
      79         951 :     if (*lc_sanitized == NULL) {
      80           0 :         DEBUG(SSSDBG_OP_FAILURE, "%s failed.\n",
      81             :                                               dom->case_sensitive ?
      82             :                                                     "talloc_strdup" :
      83             :                                                     "sss_tc_utf8_str_tolower");
      84           0 :         return ENOMEM;
      85             :     }
      86             : 
      87         951 :     return EOK;
      88             : }

Generated by: LCOV version 1.10