LCOV - code coverage report
Current view: top level - third_party/heimdal/lib/wind - stringprep.c (source / functions) Hit Total Coverage
Test: coverage report for master 2f515e9b Lines: 20 41 48.8 %
Date: 2024-04-21 15:09:00 Functions: 1 2 50.0 %

          Line data    Source code
       1             : /*
       2             :  * Copyright (c) 2004, 2006, 2008 Kungliga Tekniska Högskolan
       3             :  * (Royal Institute of Technology, Stockholm, Sweden).
       4             :  * All rights reserved.
       5             :  *
       6             :  * Redistribution and use in source and binary forms, with or without
       7             :  * modification, are permitted provided that the following conditions
       8             :  * are met:
       9             :  *
      10             :  * 1. Redistributions of source code must retain the above copyright
      11             :  *    notice, this list of conditions and the following disclaimer.
      12             :  *
      13             :  * 2. Redistributions in binary form must reproduce the above copyright
      14             :  *    notice, this list of conditions and the following disclaimer in the
      15             :  *    documentation and/or other materials provided with the distribution.
      16             :  *
      17             :  * 3. Neither the name of the Institute nor the names of its contributors
      18             :  *    may be used to endorse or promote products derived from this software
      19             :  *    without specific prior written permission.
      20             :  *
      21             :  * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
      22             :  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
      23             :  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
      24             :  * ARE DISCLAIMED.  IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
      25             :  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
      26             :  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
      27             :  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
      28             :  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
      29             :  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
      30             :  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
      31             :  * SUCH DAMAGE.
      32             :  */
      33             : 
      34             : #ifdef HAVE_CONFIG_H
      35             : #include <config.h>
      36             : #endif
      37             : #include "windlocl.h"
      38             : #include <stdlib.h>
      39             : #include <string.h>
      40             : #include <errno.h>
      41             : 
      42             : /**
      43             :  * Process a input UCS4 string according a string-prep profile.
      44             :  *
      45             :  * @param in input UCS4 string to process
      46             :  * @param in_len length of the input string
      47             :  * @param out output UCS4 string
      48             :  * @param out_len length of the output string.
      49             :  * @param flags stringprep profile.
      50             :  *
      51             :  * @return returns 0 on success, an wind error code otherwise
      52             :  * @ingroup wind
      53             :  */
      54             : 
      55             : int
      56        3934 : wind_stringprep(const uint32_t *in, size_t in_len,
      57             :                 uint32_t *out, size_t *out_len,
      58             :                 wind_profile_flags flags)
      59             : {
      60        3934 :     size_t tmp_len = in_len * 3;
      61           0 :     uint32_t *tmp;
      62           0 :     int ret;
      63           0 :     size_t olen;
      64             : 
      65        3934 :     if (in_len == 0) {
      66           0 :         *out_len = 0;
      67           0 :         return 0;
      68             :     }
      69             : 
      70        3934 :     tmp = malloc(tmp_len * sizeof(uint32_t));
      71        3934 :     if (tmp == NULL)
      72           0 :         return ENOMEM;
      73             : 
      74        3934 :     ret = _wind_stringprep_map(in, in_len, tmp, &tmp_len, flags);
      75        3934 :     if (ret) {
      76           0 :         free(tmp);
      77           0 :         return ret;
      78             :     }
      79             : 
      80        3934 :     olen = *out_len;
      81        3934 :     ret = _wind_stringprep_normalize(tmp, tmp_len, tmp, &olen);
      82        3934 :     if (ret) {
      83           0 :         free(tmp);
      84           0 :         return ret;
      85             :     }
      86        3934 :     ret = _wind_stringprep_prohibited(tmp, olen, flags);
      87        3934 :     if (ret) {
      88           0 :         free(tmp);
      89           0 :         return ret;
      90             :     }
      91        3934 :     ret = _wind_stringprep_testbidi(tmp, olen, flags);
      92        3934 :     if (ret) {
      93           0 :         free(tmp);
      94           0 :         return ret;
      95             :     }
      96             : 
      97             :     /* Insignificant Character Handling for ldap-prep */
      98        3934 :     if (flags & WIND_PROFILE_LDAP_CASE_EXACT_ATTRIBUTE) {
      99         562 :         ret = _wind_ldap_case_exact_attribute(tmp, olen, out, out_len);
     100             : #if 0
     101             :     } else if (flags & WIND_PROFILE_LDAP_CASE_EXACT_ASSERTION) {
     102             :     } else if (flags & WIND_PROFILE_LDAP_NUMERIC) {
     103             :     } else if (flags & WIND_PROFILE_LDAP_TELEPHONE) {
     104             : #endif
     105             :     } else {
     106        3372 :         memcpy(out, tmp, sizeof(out[0]) * olen);
     107        3372 :         *out_len = olen;
     108             :     }
     109        3934 :     free(tmp);
     110             : 
     111        3934 :     return ret;
     112             : }
     113             : 
     114             : static const struct {
     115             :     const char *name;
     116             :     wind_profile_flags flags;
     117             : } profiles[] = {
     118             :     { "nameprep", WIND_PROFILE_NAME },
     119             :     { "saslprep", WIND_PROFILE_SASL },
     120             :     { "ldapprep", WIND_PROFILE_LDAP }
     121             : };
     122             : 
     123             : /**
     124             :  * Try to find the profile given a name.
     125             :  *
     126             :  * @param name name of the profile.
     127             :  * @param flags the resulting profile.
     128             :  *
     129             :  * @return returns 0 on success, an wind error code otherwise
     130             :  * @ingroup wind
     131             :  */
     132             : 
     133             : int
     134           0 : wind_profile(const char *name, wind_profile_flags *flags)
     135             : {
     136           0 :     unsigned int i;
     137             : 
     138           0 :     for (i = 0; i < sizeof(profiles)/sizeof(profiles[0]); i++) {
     139           0 :         if (strcasecmp(profiles[i].name, name) == 0) {
     140           0 :             *flags = profiles[i].flags;
     141           0 :             return 0;
     142             :         }
     143             :     }
     144           0 :     return WIND_ERR_NO_PROFILE;
     145             : }

Generated by: LCOV version 1.14