2 * Copyright (c) 2004, 2006, 2008 Kungliga Tekniska Högskolan
3 * (Royal Institute of Technology, Stockholm, Sweden).
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
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.
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.
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
43 * Process a input UCS4 string according a string-prep profile.
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.
51 * @return returns 0 on success, an wind error code otherwise
56 wind_stringprep(const uint32_t *in, size_t in_len,
57 uint32_t *out, size_t *out_len,
58 wind_profile_flags flags)
60 size_t tmp_len = in_len * 3;
70 tmp = malloc(tmp_len * sizeof(uint32_t));
74 ret = _wind_stringprep_map(in, in_len, tmp, &tmp_len, flags);
81 ret = _wind_stringprep_normalize(tmp, tmp_len, tmp, &olen);
86 ret = _wind_stringprep_prohibited(tmp, olen, flags);
91 ret = _wind_stringprep_testbidi(tmp, olen, flags);
97 /* Insignificant Character Handling for ldap-prep */
98 if (flags & WIND_PROFILE_LDAP_CASE_EXACT_ATTRIBUTE) {
99 ret = _wind_ldap_case_exact_attribute(tmp, olen, out, out_len);
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) {
106 memcpy(out, tmp, sizeof(out[0]) * olen);
114 static const struct {
116 wind_profile_flags flags;
118 { "nameprep", WIND_PROFILE_NAME },
119 { "saslprep", WIND_PROFILE_SASL },
120 { "ldapprep", WIND_PROFILE_LDAP }
124 * Try to find the profile given a name.
126 * @param name name of the profile.
127 * @param flags the resulting profile.
129 * @return returns 0 on success, an wind error code otherwise
134 wind_profile(const char *name, wind_profile_flags *flags)
138 for (i = 0; i < sizeof(profiles)/sizeof(profiles[0]); i++) {
139 if (strcasecmp(profiles[i].name, name) == 0) {
140 *flags = profiles[i].flags;
144 return WIND_ERR_NO_PROFILE;