Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
openldap
OpenLDAP
Commits
ea477358
Commit
ea477358
authored
Jul 16, 2001
by
Stig Venaas
Browse files
Fixed UTF8 encoding checks for substrings assertions
parent
f06021e3
Changes
1
Hide whitespace changes
Inline
Side-by-side
servers/slapd/schema_init.c
View file @
ea477358
...
@@ -696,6 +696,61 @@ UTF8StringNormalize(
...
@@ -696,6 +696,61 @@ UTF8StringNormalize(
return
LDAP_SUCCESS
;
return
LDAP_SUCCESS
;
}
}
#if UTF8MATCH
/* Returns Unicode cannonically normalized copy of a substring assertion
* Skipping attribute description */
SubstringsAssertion
*
UTF8SubstringsassertionNormalize
(
SubstringsAssertion
*
sa
,
char
casefold
)
{
SubstringsAssertion
*
nsa
;
int
i
;
nsa
=
(
SubstringsAssertion
*
)
ch_calloc
(
1
,
sizeof
(
SubstringsAssertion
)
);
if
(
nsa
==
NULL
)
{
return
NULL
;
}
if
(
sa
->
sa_initial
!=
NULL
)
{
nsa
->
sa_initial
=
ber_bvstr
(
UTF8normalize
(
sa
->
sa_initial
->
bv_val
,
casefold
)
);
if
(
nsa
->
sa_initial
==
NULL
)
{
goto
err
;
}
}
if
(
sa
->
sa_any
!=
NULL
)
{
for
(
i
=
0
;
sa
->
sa_any
[
i
]
!=
NULL
;
i
++
)
{
/* empty */
}
nsa
->
sa_any
=
(
struct
berval
**
)
ch_malloc
(
(
i
+
1
)
*
sizeof
(
struct
berval
*
)
);
for
(
i
=
0
;
sa
->
sa_any
[
i
]
!=
NULL
;
i
++
)
{
nsa
->
sa_any
[
i
]
=
ber_bvstr
(
UTF8normalize
(
sa
->
sa_any
[
i
]
->
bv_val
,
casefold
)
);
if
(
nsa
->
sa_any
[
i
]
==
NULL
)
{
goto
err
;
}
}
nsa
->
sa_any
[
i
]
=
NULL
;
}
if
(
sa
->
sa_final
!=
NULL
)
{
nsa
->
sa_final
=
ber_bvstr
(
UTF8normalize
(
sa
->
sa_final
->
bv_val
,
casefold
)
);
if
(
nsa
->
sa_final
==
NULL
)
{
goto
err
;
}
}
return
nsa
;
err:
ch_free
(
nsa
->
sa_final
);
ber_bvecfree
(
nsa
->
sa_any
);
ch_free
(
nsa
->
sa_initial
);
ch_free
(
nsa
);
return
NULL
;
}
#endif
#if defined(SLAPD_APPROX_MULTISTRING)
#if defined(SLAPD_APPROX_MULTISTRING)
#if defined(SLAPD_APPROX_INITIALS)
#if defined(SLAPD_APPROX_INITIALS)
...
@@ -1454,7 +1509,7 @@ int caseExactSubstringsFilter(
...
@@ -1454,7 +1509,7 @@ int caseExactSubstringsFilter(
void
*
assertValue
,
void
*
assertValue
,
struct
berval
***
keysp
)
struct
berval
***
keysp
)
{
{
SubstringsAssertion
*
sa
=
assertValue
;
SubstringsAssertion
*
sa
;
char
pre
;
char
pre
;
ber_len_t
nkeys
=
0
;
ber_len_t
nkeys
=
0
;
size_t
slen
,
mlen
,
klen
;
size_t
slen
,
mlen
,
klen
;
...
@@ -1464,6 +1519,16 @@ int caseExactSubstringsFilter(
...
@@ -1464,6 +1519,16 @@ int caseExactSubstringsFilter(
struct
berval
*
value
;
struct
berval
*
value
;
struct
berval
digest
;
struct
berval
digest
;
#if UTF8MATCH
sa
=
UTF8SubstringsassertionNormalize
(
assertValue
,
UTF8_NOCASEFOLD
);
#else
sa
=
assertValue
;
#endif
if
(
sa
==
NULL
)
{
*
keysp
=
NULL
;
return
LDAP_SUCCESS
;
}
if
(
flags
&
SLAP_INDEX_SUBSTR_INITIAL
&&
sa
->
sa_initial
!=
NULL
&&
if
(
flags
&
SLAP_INDEX_SUBSTR_INITIAL
&&
sa
->
sa_initial
!=
NULL
&&
sa
->
sa_initial
->
bv_len
>=
SLAP_INDEX_SUBSTR_MINLEN
)
sa
->
sa_initial
->
bv_len
>=
SLAP_INDEX_SUBSTR_MINLEN
)
{
{
...
@@ -1505,12 +1570,7 @@ int caseExactSubstringsFilter(
...
@@ -1505,12 +1570,7 @@ int caseExactSubstringsFilter(
sa
->
sa_initial
->
bv_len
>=
SLAP_INDEX_SUBSTR_MINLEN
)
sa
->
sa_initial
->
bv_len
>=
SLAP_INDEX_SUBSTR_MINLEN
)
{
{
pre
=
SLAP_INDEX_SUBSTR_INITIAL_PREFIX
;
pre
=
SLAP_INDEX_SUBSTR_INITIAL_PREFIX
;
#if UTF8MATCH
value
=
ber_bvstr
(
UTF8normalize
(
sa
->
sa_initial
->
bv_val
,
UTF8_NOCASEFOLD
)
);
#else
value
=
sa
->
sa_initial
;
value
=
sa
->
sa_initial
;
#endif
klen
=
SLAP_INDEX_SUBSTR_MAXLEN
<
value
->
bv_len
klen
=
SLAP_INDEX_SUBSTR_MAXLEN
<
value
->
bv_len
?
SLAP_INDEX_SUBSTR_MAXLEN
:
value
->
bv_len
;
?
SLAP_INDEX_SUBSTR_MAXLEN
:
value
->
bv_len
;
...
@@ -1530,9 +1590,6 @@ int caseExactSubstringsFilter(
...
@@ -1530,9 +1590,6 @@ int caseExactSubstringsFilter(
value
->
bv_val
,
klen
);
value
->
bv_val
,
klen
);
HASH_Final
(
HASHdigest
,
&
HASHcontext
);
HASH_Final
(
HASHdigest
,
&
HASHcontext
);
#if UTF8MATCH
ber_bvfree
(
value
);
#endif
keys
[
nkeys
++
]
=
ber_bvdup
(
&
digest
);
keys
[
nkeys
++
]
=
ber_bvdup
(
&
digest
);
}
}
...
@@ -1546,12 +1603,7 @@ int caseExactSubstringsFilter(
...
@@ -1546,12 +1603,7 @@ int caseExactSubstringsFilter(
continue
;
continue
;
}
}
#if UTF8MATCH
value
=
ber_bvstr
(
UTF8normalize
(
sa
->
sa_any
[
i
]
->
bv_val
,
UTF8_NOCASEFOLD
)
);
#else
value
=
sa
->
sa_any
[
i
];
value
=
sa
->
sa_any
[
i
];
#endif
for
(
j
=
0
;
for
(
j
=
0
;
j
<=
value
->
bv_len
-
SLAP_INDEX_SUBSTR_MAXLEN
;
j
<=
value
->
bv_len
-
SLAP_INDEX_SUBSTR_MAXLEN
;
...
@@ -1575,9 +1627,6 @@ int caseExactSubstringsFilter(
...
@@ -1575,9 +1627,6 @@ int caseExactSubstringsFilter(
keys
[
nkeys
++
]
=
ber_bvdup
(
&
digest
);
keys
[
nkeys
++
]
=
ber_bvdup
(
&
digest
);
}
}
#if UTF8MATCH
ber_bvfree
(
value
);
#endif
}
}
}
}
...
@@ -1585,12 +1634,7 @@ int caseExactSubstringsFilter(
...
@@ -1585,12 +1634,7 @@ int caseExactSubstringsFilter(
sa
->
sa_final
->
bv_len
>=
SLAP_INDEX_SUBSTR_MINLEN
)
sa
->
sa_final
->
bv_len
>=
SLAP_INDEX_SUBSTR_MINLEN
)
{
{
pre
=
SLAP_INDEX_SUBSTR_FINAL_PREFIX
;
pre
=
SLAP_INDEX_SUBSTR_FINAL_PREFIX
;
#if UTF8MATCH
value
=
ber_bvstr
(
UTF8normalize
(
sa
->
sa_final
->
bv_val
,
UTF8_NOCASEFOLD
)
);
#else
value
=
sa
->
sa_final
;
value
=
sa
->
sa_final
;
#endif
klen
=
SLAP_INDEX_SUBSTR_MAXLEN
<
value
->
bv_len
klen
=
SLAP_INDEX_SUBSTR_MAXLEN
<
value
->
bv_len
?
SLAP_INDEX_SUBSTR_MAXLEN
:
value
->
bv_len
;
?
SLAP_INDEX_SUBSTR_MAXLEN
:
value
->
bv_len
;
...
@@ -1610,9 +1654,6 @@ int caseExactSubstringsFilter(
...
@@ -1610,9 +1654,6 @@ int caseExactSubstringsFilter(
&
value
->
bv_val
[
value
->
bv_len
-
klen
],
klen
);
&
value
->
bv_val
[
value
->
bv_len
-
klen
],
klen
);
HASH_Final
(
HASHdigest
,
&
HASHcontext
);
HASH_Final
(
HASHdigest
,
&
HASHcontext
);
#if UTF8MATCH
ber_bvfree
(
value
);
#endif
keys
[
nkeys
++
]
=
ber_bvdup
(
&
digest
);
keys
[
nkeys
++
]
=
ber_bvdup
(
&
digest
);
}
}
...
@@ -1623,6 +1664,12 @@ int caseExactSubstringsFilter(
...
@@ -1623,6 +1664,12 @@ int caseExactSubstringsFilter(
ch_free
(
keys
);
ch_free
(
keys
);
*
keysp
=
NULL
;
*
keysp
=
NULL
;
}
}
#if UTF8MATCH
ch_free
(
sa
->
sa_final
);
ber_bvecfree
(
sa
->
sa_any
);
ch_free
(
sa
->
sa_initial
);
ch_free
(
sa
);
#endif
return
LDAP_SUCCESS
;
return
LDAP_SUCCESS
;
}
}
...
@@ -2130,7 +2177,7 @@ int caseIgnoreSubstringsFilter(
...
@@ -2130,7 +2177,7 @@ int caseIgnoreSubstringsFilter(
void
*
assertValue
,
void
*
assertValue
,
struct
berval
***
keysp
)
struct
berval
***
keysp
)
{
{
SubstringsAssertion
*
sa
=
assertValue
;
SubstringsAssertion
*
sa
;
char
pre
;
char
pre
;
ber_len_t
nkeys
=
0
;
ber_len_t
nkeys
=
0
;
size_t
slen
,
mlen
,
klen
;
size_t
slen
,
mlen
,
klen
;
...
@@ -2140,6 +2187,16 @@ int caseIgnoreSubstringsFilter(
...
@@ -2140,6 +2187,16 @@ int caseIgnoreSubstringsFilter(
struct
berval
*
value
;
struct
berval
*
value
;
struct
berval
digest
;
struct
berval
digest
;
#if UTF8MATCH
sa
=
UTF8SubstringsassertionNormalize
(
assertValue
,
UTF8_CASEFOLD
);
#else
sa
=
assertValue
;
#endif
if
(
sa
==
NULL
)
{
*
keysp
=
NULL
;
return
LDAP_SUCCESS
;
}
if
((
flags
&
SLAP_INDEX_SUBSTR_INITIAL
)
&&
sa
->
sa_initial
!=
NULL
&&
if
((
flags
&
SLAP_INDEX_SUBSTR_INITIAL
)
&&
sa
->
sa_initial
!=
NULL
&&
sa
->
sa_initial
->
bv_len
>=
SLAP_INDEX_SUBSTR_MINLEN
)
sa
->
sa_initial
->
bv_len
>=
SLAP_INDEX_SUBSTR_MINLEN
)
{
{
...
@@ -2182,7 +2239,7 @@ int caseIgnoreSubstringsFilter(
...
@@ -2182,7 +2239,7 @@ int caseIgnoreSubstringsFilter(
{
{
pre
=
SLAP_INDEX_SUBSTR_INITIAL_PREFIX
;
pre
=
SLAP_INDEX_SUBSTR_INITIAL_PREFIX
;
#if UTF8MATCH
#if UTF8MATCH
value
=
ber_bvstr
(
UTF8normalize
(
sa
->
sa_initial
->
bv_val
,
UTF8_CASEFOLD
)
)
;
value
=
sa
->
sa_initial
;
#else
#else
value
=
ber_bvdup
(
sa
->
sa_initial
);
value
=
ber_bvdup
(
sa
->
sa_initial
);
ldap_pvt_str2upper
(
value
->
bv_val
);
ldap_pvt_str2upper
(
value
->
bv_val
);
...
@@ -2206,7 +2263,9 @@ int caseIgnoreSubstringsFilter(
...
@@ -2206,7 +2263,9 @@ int caseIgnoreSubstringsFilter(
value
->
bv_val
,
klen
);
value
->
bv_val
,
klen
);
HASH_Final
(
HASHdigest
,
&
HASHcontext
);
HASH_Final
(
HASHdigest
,
&
HASHcontext
);
#if !UTF8MATCH
ber_bvfree
(
value
);
ber_bvfree
(
value
);
#endif
keys
[
nkeys
++
]
=
ber_bvdup
(
&
digest
);
keys
[
nkeys
++
]
=
ber_bvdup
(
&
digest
);
}
}
...
@@ -2221,7 +2280,7 @@ int caseIgnoreSubstringsFilter(
...
@@ -2221,7 +2280,7 @@ int caseIgnoreSubstringsFilter(
}
}
#if UTF8MATCH
#if UTF8MATCH
value
=
ber_bvstr
(
UTF8normalize
(
sa
->
sa_any
[
i
]
->
bv_val
,
UTF8_CASEFOLD
)
)
;
value
=
sa
->
sa_any
[
i
]
;
#else
#else
value
=
ber_bvdup
(
sa
->
sa_any
[
i
]
);
value
=
ber_bvdup
(
sa
->
sa_any
[
i
]
);
ldap_pvt_str2upper
(
value
->
bv_val
);
ldap_pvt_str2upper
(
value
->
bv_val
);
...
@@ -2249,7 +2308,9 @@ int caseIgnoreSubstringsFilter(
...
@@ -2249,7 +2308,9 @@ int caseIgnoreSubstringsFilter(
keys
[
nkeys
++
]
=
ber_bvdup
(
&
digest
);
keys
[
nkeys
++
]
=
ber_bvdup
(
&
digest
);
}
}
#if !UTF8MATCH
ber_bvfree
(
value
);
ber_bvfree
(
value
);
#endif
}
}
}
}
...
@@ -2258,7 +2319,7 @@ int caseIgnoreSubstringsFilter(
...
@@ -2258,7 +2319,7 @@ int caseIgnoreSubstringsFilter(
{
{
pre
=
SLAP_INDEX_SUBSTR_FINAL_PREFIX
;
pre
=
SLAP_INDEX_SUBSTR_FINAL_PREFIX
;
#if UTF8MATCH
#if UTF8MATCH
value
=
ber_bvstr
(
UTF8normalize
(
sa
->
sa_final
->
bv_val
,
UTF8_CASEFOLD
)
)
;
value
=
sa
->
sa_final
;
#else
#else
value
=
ber_bvdup
(
sa
->
sa_final
);
value
=
ber_bvdup
(
sa
->
sa_final
);
ldap_pvt_str2upper
(
value
->
bv_val
);
ldap_pvt_str2upper
(
value
->
bv_val
);
...
@@ -2282,7 +2343,9 @@ int caseIgnoreSubstringsFilter(
...
@@ -2282,7 +2343,9 @@ int caseIgnoreSubstringsFilter(
&
value
->
bv_val
[
value
->
bv_len
-
klen
],
klen
);
&
value
->
bv_val
[
value
->
bv_len
-
klen
],
klen
);
HASH_Final
(
HASHdigest
,
&
HASHcontext
);
HASH_Final
(
HASHdigest
,
&
HASHcontext
);
#if !UTF8MATCH
ber_bvfree
(
value
);
ber_bvfree
(
value
);
#endif
keys
[
nkeys
++
]
=
ber_bvdup
(
&
digest
);
keys
[
nkeys
++
]
=
ber_bvdup
(
&
digest
);
}
}
...
@@ -2293,6 +2356,12 @@ int caseIgnoreSubstringsFilter(
...
@@ -2293,6 +2356,12 @@ int caseIgnoreSubstringsFilter(
ch_free
(
keys
);
ch_free
(
keys
);
*
keysp
=
NULL
;
*
keysp
=
NULL
;
}
}
#if UTF8MATCH
ch_free
(
sa
->
sa_final
);
ber_bvecfree
(
sa
->
sa_any
);
ch_free
(
sa
->
sa_initial
);
ch_free
(
sa
);
#endif
return
LDAP_SUCCESS
;
return
LDAP_SUCCESS
;
}
}
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment