Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
239 changes: 239 additions & 0 deletions dirsrvtests/tests/suites/filter/basic_filter_test.py

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions dirsrvtests/tests/suites/filter/filter_match_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -769,6 +769,7 @@ def test_extensible_search(topology_st, _searches, attr, value):
:expectedresults:
1. Pass
"""
topology_st.standalone.config.set("nsslapd-verify-filter-schema", "warn-invalid")
cos = CosTemplates(topology_st.standalone, DEFAULT_SUFFIX)
assert len(cos.filter(attr)) == value

Expand Down
13 changes: 12 additions & 1 deletion ldap/servers/plugins/syntaxes/bitstring.c
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,17 @@ bitstring_normalize(
int trim_spaces,
char **alt)
{
value_normalize_ext(s, SYNTAX_CES, trim_spaces, alt);
int trim_mask = 0;
if (trim_spaces == COMPATIBLE_NOT_TRIM_SPACES) {
/* value 0x00 */
trim_mask = NO_TRIM_SHRINK_BLANK;
} else if (trim_spaces == COMPATIBLE_TRIM_SPACES) {
/* value 0x01 */
trim_mask = TRIM_LEADING_BLANK | TRIM_TRAILING_BLANK;
} else {
/* value 0x10-0x80 */
trim_mask = trim_spaces;
}
value_normalize_ext(s, SYNTAX_CES, trim_mask, alt);
return;
}
13 changes: 12 additions & 1 deletion ldap/servers/plugins/syntaxes/ces.c
Original file line number Diff line number Diff line change
Expand Up @@ -440,6 +440,17 @@ ces_normalize(
int trim_spaces,
char **alt)
{
value_normalize_ext(s, SYNTAX_CES, trim_spaces, alt);
int trim_mask = 0;
if (trim_spaces == COMPATIBLE_NOT_TRIM_SPACES) {
/* value 0x00 */
trim_mask = NO_TRIM_SHRINK_BLANK;
} else if (trim_spaces == COMPATIBLE_TRIM_SPACES) {
/* value 0x01 */
trim_mask = COMPATIBLE_TRIM_MASK;
} else {
/* value 0x10-0x80 */
trim_mask = trim_spaces;
}
value_normalize_ext(s, SYNTAX_CES, trim_mask, alt);
return;
}
13 changes: 12 additions & 1 deletion ldap/servers/plugins/syntaxes/cis.c
Original file line number Diff line number Diff line change
Expand Up @@ -1290,6 +1290,17 @@ cis_normalize(
int trim_spaces,
char **alt)
{
value_normalize_ext(s, SYNTAX_CIS, trim_spaces, alt);
int trim_mask = 0;
if (trim_spaces == COMPATIBLE_NOT_TRIM_SPACES) {
/* value 0x00 */
trim_mask = NO_TRIM_SHRINK_BLANK;
} else if (trim_spaces == COMPATIBLE_TRIM_SPACES) {
/* value 0x01 */
trim_mask = COMPATIBLE_TRIM_MASK;
} else {
/* value 0x10-0x80 */
trim_mask = trim_spaces;
}
value_normalize_ext(s, SYNTAX_CIS, trim_mask, alt);
return;
}
13 changes: 12 additions & 1 deletion ldap/servers/plugins/syntaxes/deliverymethod.c
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,17 @@ delivery_normalize(
int trim_spaces,
char **alt)
{
value_normalize_ext(s, SYNTAX_CIS, trim_spaces, alt);
int trim_mask = 0;
if (trim_spaces == COMPATIBLE_NOT_TRIM_SPACES) {
/* value 0x00 */
trim_mask = NO_TRIM_SHRINK_BLANK;
} else if (trim_spaces == COMPATIBLE_TRIM_SPACES) {
/* value 0x01 */
trim_mask = COMPATIBLE_TRIM_MASK;
} else {
/* value 0x10-0x80 */
trim_mask = trim_spaces;
}
value_normalize_ext(s, SYNTAX_CIS, trim_mask, alt);
return;
}
13 changes: 12 additions & 1 deletion ldap/servers/plugins/syntaxes/dn.c
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,17 @@ dn_normalize(
int trim_spaces,
char **alt)
{
value_normalize_ext(s, SYNTAX_CIS | SYNTAX_DN, trim_spaces, alt);
int trim_mask = 0;
if (trim_spaces == COMPATIBLE_NOT_TRIM_SPACES) {
/* value 0x00 */
trim_mask = NO_TRIM_SHRINK_BLANK;
} else if (trim_spaces == COMPATIBLE_TRIM_SPACES) {
/* value 0x01 */
trim_mask = COMPATIBLE_TRIM_MASK;
} else {
/* value 0x10-0x80 */
trim_mask = trim_spaces;
}
value_normalize_ext(s, SYNTAX_CIS | SYNTAX_DN, trim_mask, alt);
return;
}
13 changes: 12 additions & 1 deletion ldap/servers/plugins/syntaxes/facsimile.c
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,17 @@ facsimile_normalize(
int trim_spaces,
char **alt)
{
value_normalize_ext(s, SYNTAX_CIS, trim_spaces, alt);
int trim_mask = 0;
if (trim_spaces == COMPATIBLE_NOT_TRIM_SPACES) {
/* value 0x00 */
trim_mask = NO_TRIM_SHRINK_BLANK;
} else if (trim_spaces == COMPATIBLE_TRIM_SPACES) {
/* value 0x01 */
trim_mask = COMPATIBLE_TRIM_MASK;
} else {
/* value 0x10-0x80 */
trim_mask = trim_spaces;
}
value_normalize_ext(s, SYNTAX_CIS, trim_mask, alt);
return;
}
13 changes: 12 additions & 1 deletion ldap/servers/plugins/syntaxes/guide.c
Original file line number Diff line number Diff line change
Expand Up @@ -712,6 +712,17 @@ guide_normalize(
int trim_spaces,
char **alt)
{
value_normalize_ext(s, SYNTAX_CIS, trim_spaces, alt);
int trim_mask = 0;
if (trim_spaces == COMPATIBLE_NOT_TRIM_SPACES) {
/* value 0x00 */
trim_mask = NO_TRIM_SHRINK_BLANK;
} else if (trim_spaces == COMPATIBLE_TRIM_SPACES) {
/* value 0x01 */
trim_mask = COMPATIBLE_TRIM_MASK;
} else {
/* value 0x10-0x80 */
trim_mask = trim_spaces;
}
value_normalize_ext(s, SYNTAX_CIS, trim_mask, alt);
return;
}
13 changes: 12 additions & 1 deletion ldap/servers/plugins/syntaxes/inchain.c
Original file line number Diff line number Diff line change
Expand Up @@ -411,7 +411,18 @@ inchain_normalize(
int trim_spaces,
char **alt)
{
int trim_mask = 0;
if (trim_spaces == COMPATIBLE_NOT_TRIM_SPACES) {
/* value 0x00 */
trim_mask = NO_TRIM_SHRINK_BLANK;
} else if (trim_spaces == COMPATIBLE_TRIM_SPACES) {
/* value 0x01 */
trim_mask = COMPATIBLE_TRIM_MASK;
} else {
/* value 0x10-0x80 */
trim_mask = trim_spaces;
}
slapi_log_err(SLAPI_LOG_ERR, "inchain", "inchain_normalize %s \n", s);
value_normalize_ext(s, SYNTAX_CIS | SYNTAX_DN, trim_spaces, alt);
value_normalize_ext(s, SYNTAX_CIS | SYNTAX_DN, trim_mask, alt);
return;
}
13 changes: 12 additions & 1 deletion ldap/servers/plugins/syntaxes/int.c
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,17 @@ int_normalize(
int trim_spaces,
char **alt)
{
value_normalize_ext(s, SYNTAX_INT | SYNTAX_CES, trim_spaces, alt);
int trim_mask = 0;
if (trim_spaces == COMPATIBLE_NOT_TRIM_SPACES) {
/* value 0x00 */
trim_mask = NO_TRIM_SHRINK_BLANK;
} else if (trim_spaces == COMPATIBLE_TRIM_SPACES) {
/* value 0x01 */
trim_mask = COMPATIBLE_TRIM_MASK;
} else {
/* value 0x10-0x80 */
trim_mask = trim_spaces;
}
value_normalize_ext(s, SYNTAX_INT | SYNTAX_CES, trim_mask, alt);
return;
}
13 changes: 12 additions & 1 deletion ldap/servers/plugins/syntaxes/nameoptuid.c
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,17 @@ nameoptuid_normalize(
int trim_spaces,
char **alt)
{
value_normalize_ext(s, SYNTAX_CIS | SYNTAX_DN, trim_spaces, alt);
int trim_mask = 0;
if (trim_spaces == COMPATIBLE_NOT_TRIM_SPACES) {
/* value 0x00 */
trim_mask = NO_TRIM_SHRINK_BLANK;
} else if (trim_spaces == COMPATIBLE_TRIM_SPACES) {
/* value 0x01 */
trim_mask = COMPATIBLE_TRIM_MASK;
} else {
/* value 0x10-0x80 */
trim_mask = trim_spaces;
}
value_normalize_ext(s, SYNTAX_CIS | SYNTAX_DN, trim_mask, alt);
return;
}
13 changes: 12 additions & 1 deletion ldap/servers/plugins/syntaxes/numericstring.c
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,17 @@ numstr_normalize(
int trim_spaces,
char **alt)
{
value_normalize_ext(s, SYNTAX_SI | SYNTAX_CES, trim_spaces, alt);
int trim_mask = 0;
if (trim_spaces == COMPATIBLE_NOT_TRIM_SPACES) {
/* value 0x00 */
trim_mask = NO_TRIM_SHRINK_BLANK;
} else if (trim_spaces == COMPATIBLE_TRIM_SPACES) {
/* value 0x01 */
trim_mask = COMPATIBLE_TRIM_MASK;
} else {
/* value 0x10-0x80 */
trim_mask = trim_spaces;
}
value_normalize_ext(s, SYNTAX_SI | SYNTAX_CES, trim_mask, alt);
return;
}
13 changes: 12 additions & 1 deletion ldap/servers/plugins/syntaxes/sicis.c
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,17 @@ sicis_normalize(
int trim_spaces,
char **alt)
{
value_normalize_ext(s, SYNTAX_SI | SYNTAX_CIS, trim_spaces, alt);
int trim_mask = 0;
if (trim_spaces == COMPATIBLE_NOT_TRIM_SPACES) {
/* value 0x00 */
trim_mask = NO_TRIM_SHRINK_BLANK;
} else if (trim_spaces == COMPATIBLE_TRIM_SPACES) {
/* value 0x01 */
trim_mask = COMPATIBLE_TRIM_MASK;
} else {
/* value 0x10-0x80 */
trim_mask = trim_spaces;
}
value_normalize_ext(s, SYNTAX_SI | SYNTAX_CIS, trim_mask, alt);
return;
}
46 changes: 37 additions & 9 deletions ldap/servers/plugins/syntaxes/string.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ string_filter_ava(struct berval *bvfilter, Slapi_Value **bvals, int syntax, int
} else {
slapi_ber_bvcpy(&bvfilter_norm, bvfilter);
/* 3rd arg: 1 - trim leading blanks */
value_normalize_ext(bvfilter_norm.bv_val, syntax, 1, &alt);
value_normalize_ext(bvfilter_norm.bv_val, syntax, TRIM_LEADING_BLANK, &alt);
if (alt) {
slapi_ber_bvdone(&bvfilter_norm);
bvfilter_norm.bv_val = alt;
Expand Down Expand Up @@ -259,7 +259,15 @@ string_filter_sub(Slapi_PBlock *pb, char *initial, char **any, char * final, Sla
if (initial != NULL) {
/* 3rd arg: 1 - trim leading blanks */
if (!filter_normalized) {
value_normalize_ext(initial, syntax, 1, &alt);
/*
* rfc4518 2.6.1 Insignificant Space Handling
* For input strings that are substring assertion values:
*
* If the input string is an initial or an any substring that ends in
* one or more space characters, it is modified to end with exactly
* one SPACE character;
*/
value_normalize_ext(initial, syntax, TRIM_LEADING_BLANK & SHRINK_TRAILING_BLANK, &alt);
}
*p++ = '^';
if (alt) {
Expand All @@ -274,7 +282,19 @@ string_filter_sub(Slapi_PBlock *pb, char *initial, char **any, char * final, Sla
for (i = 0; any[i] != NULL; i++) {
/* 3rd arg: 0 - DO NOT trim leading blanks */
if (!filter_normalized) {
value_normalize_ext(any[i], syntax, 0, &alt);
/*
* rfc4518 2.6.1 Insignificant Space Handling
* For input strings that are substring assertion values:
*
* If the input string is an initial or an any substring that ends in
* one or more space characters, it is modified to end with exactly
* one SPACE character;
*
* If the input string is an any or a final substring that starts in
* one or more space characters, it is modified to start with exactly
* one SPACE character;
*/
value_normalize_ext(any[i], syntax, SHRINK_LEADING_BLANK & SHRINK_TRAILING_BLANK, &alt);
}
/* ".*" + value */
*p++ = '.';
Expand All @@ -291,7 +311,15 @@ string_filter_sub(Slapi_PBlock *pb, char *initial, char **any, char * final, Sla
if (final != NULL) {
/* 3rd arg: 0 - DO NOT trim leading blanks */
if (!filter_normalized) {
value_normalize_ext(final, syntax, 0, &alt);
/*
* rfc4518 2.6.1 Insignificant Space Handling
* For input strings that are substring assertion values:
*
* If the input string is an any or a final substring that starts in
* one or more space characters, it is modified to start with exactly
* one SPACE character;
*/
value_normalize_ext(final, syntax, SHRINK_LEADING_BLANK, &alt);
}
/* ".*" + value */
*p++ = '.';
Expand Down Expand Up @@ -357,7 +385,7 @@ string_filter_sub(Slapi_PBlock *pb, char *initial, char **any, char * final, Sla
}
/* 3rd arg: 1 - trim leading blanks */
if (!(slapi_value_get_flags(bvals[j]) & SLAPI_ATTR_FLAG_NORMALIZED)) {
value_normalize_ext(realval, syntax, 1, &alt);
value_normalize_ext(realval, syntax, TRIM_LEADING_BLANK, &alt);
} else if (syntax & SYNTAX_DN) {
slapi_dn_ignore_case(realval);
}
Expand Down Expand Up @@ -434,7 +462,7 @@ string_values2keys(Slapi_PBlock *pb, Slapi_Value **bvals, Slapi_Value ***ivals,
/* if the NORMALIZED flag is set, skip normalizing */
if (!(value_flags & SLAPI_ATTR_FLAG_NORMALIZED)) {
/* 3rd arg: 1 - trim leading blanks */
value_normalize_ext(c, syntax, 1, &alt);
value_normalize_ext(c, syntax, TRIM_LEADING_BLANK, &alt);
value_flags |= SLAPI_ATTR_FLAG_NORMALIZED;
} else if ((syntax & SYNTAX_DN) &&
(value_flags & SLAPI_ATTR_FLAG_NORMALIZED_CES)) {
Expand Down Expand Up @@ -566,7 +594,7 @@ string_values2keys(Slapi_PBlock *pb, Slapi_Value **bvals, Slapi_Value ***ivals,
/* 3rd arg: 1 - trim leading blanks */
if (!(value_flags & SLAPI_ATTR_FLAG_NORMALIZED)) {
c = slapi_ch_strdup(slapi_value_get_string(*bvlp));
value_normalize_ext(c, syntax, 1, &alt);
value_normalize_ext(c, syntax, TRIM_LEADING_BLANK, &alt);
if (alt) {
slapi_ch_free_string(&c);
slapi_value_set_string_passin(bvdup, alt);
Expand Down Expand Up @@ -668,7 +696,7 @@ string_assertion2keys_ava(
tmpval->bv.bv_val[len] = '\0';
if (!(flags & SLAPI_ATTR_FLAG_NORMALIZED)) {
/* 3rd arg: 1 - trim leading blanks */
value_normalize_ext(tmpval->bv.bv_val, syntax, 1, &alt);
value_normalize_ext(tmpval->bv.bv_val, syntax, TRIM_LEADING_BLANK, &alt);
if (alt) {
if (len >= tmpval->bv.bv_len) {
slapi_ch_free_string(&tmpval->bv.bv_val);
Expand All @@ -693,7 +721,7 @@ string_assertion2keys_ava(
(*ivals)[0] = val ? slapi_value_dup(val) : NULL;
if (val && !(flags & SLAPI_ATTR_FLAG_NORMALIZED)) {
/* 3rd arg: 1 - trim leading blanks */
value_normalize_ext((*ivals)[0]->bv.bv_val, syntax, 1, &alt);
value_normalize_ext((*ivals)[0]->bv.bv_val, syntax, TRIM_LEADING_BLANK, &alt);
if (alt) {
slapi_ch_free_string(&(*ivals)[0]->bv.bv_val);
(*ivals)[0]->bv.bv_val = alt;
Expand Down
5 changes: 3 additions & 2 deletions ldap/servers/plugins/syntaxes/syntax.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,14 +76,15 @@
IS_RPAREN(c) || (c == '+') || (c == ',') || (c == '-') || (c == '.') || \
(c == '=') || (c == '/') || (c == ':') || (c == '?') || IS_SPACE(c))


int string_filter_sub(Slapi_PBlock *pb, char *initial, char **any, char * final, Slapi_Value **bvals, int syntax);
int string_filter_ava(struct berval *bvfilter, Slapi_Value **bvals, int syntax, int ftype, Slapi_Value **retVal);
int string_values2keys(Slapi_PBlock *pb, Slapi_Value **bvals, Slapi_Value ***ivals, int syntax, int ftype);
int string_assertion2keys_ava(Slapi_PBlock *pb, Slapi_Value *val, Slapi_Value ***ivals, int syntax, int ftype);
int string_assertion2keys_sub(Slapi_PBlock *pb, char *initial, char **any, char * final, Slapi_Value ***ivals, int syntax);
int value_cmp(struct berval *v1, struct berval *v2, int syntax, int normalize);
void value_normalize(char *s, int syntax, int trim_leading_blanks);
void value_normalize_ext(char *s, int syntax, int trim_leading_blanks, char **alt);
void value_normalize(char *s, int syntax, int trim_mask_blanks);
void value_normalize_ext(char *s, int syntax, int trim_mask_blanks, char **alt);

char *first_word(char *s);
char *next_word(char *s);
Expand Down
13 changes: 12 additions & 1 deletion ldap/servers/plugins/syntaxes/tel.c
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,17 @@ tel_normalize(
int trim_spaces,
char **alt)
{
value_normalize_ext(s, SYNTAX_TEL | SYNTAX_CIS, trim_spaces, alt);
int trim_mask = 0;
if (trim_spaces == COMPATIBLE_NOT_TRIM_SPACES) {
/* value 0x00 */
trim_mask = NO_TRIM_SHRINK_BLANK;
} else if (trim_spaces == COMPATIBLE_TRIM_SPACES) {
/* value 0x01 */
trim_mask = COMPATIBLE_TRIM_MASK;
} else {
/* value 0x10-0x80 */
trim_mask = trim_spaces;
}
value_normalize_ext(s, SYNTAX_TEL | SYNTAX_CIS, trim_mask, alt);
return;
}
Loading
Loading