1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
|
/* ciboolean.c - enable case-insensitive boolean values */
/* $OpenLDAP$ */
/* This work is part of OpenLDAP Software <http://www.openldap.org/>.
*
* Copyright 1998-2022 The OpenLDAP Foundation.
* Copyright 2022 Symas Corp. All Rights Reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted only as authorized by the OpenLDAP
* Public License.
*
* A copy of this license is available in the file LICENSE in the
* top-level directory of the distribution or, alternatively, at
* <http://www.OpenLDAP.org/license.html>.
*/
/* ACKNOWLEDGEMENTS:
* This work was developed in 2022 by Nadezhda Ivanova for Symas Corp.
*/
#include "portable.h"
#ifdef SLAPD_MOD_CIBOOLEAN
#include "slap.h"
#include "ac/ctype.h"
static int
cibooleanValidate(
Syntax *syntax,
struct berval *in )
{
/* Allow for case insensitive comparison with TRUE and FALSE */
struct berval bv;
int i;
if( in->bv_len == slap_true_bv.bv_len ) {
bv = slap_true_bv;
} else if( in->bv_len == slap_false_bv.bv_len ) {
bv = slap_false_bv;
} else {
return LDAP_INVALID_SYNTAX;
}
if ( ber_bvstrcasecmp( in, &bv ) != 0 ) {
return LDAP_INVALID_SYNTAX;
}
return LDAP_SUCCESS;
}
static int
cibooleanMatchNormalize(
slap_mask_t use,
Syntax *syntax,
MatchingRule *mr,
struct berval *val,
struct berval *normalized,
void *ctx )
{
struct berval nvalue;
ber_len_t i;
assert( SLAP_MR_IS_VALUE_OF_SYNTAX( use ) != 0 );
if ( BER_BVISNULL( val ) ) {
return LDAP_INVALID_SYNTAX;
}
nvalue.bv_len = val->bv_len;
nvalue.bv_val = slap_sl_malloc( nvalue.bv_len + 1, ctx );
nvalue.bv_val[nvalue.bv_len] = '\0';
for ( i = 0; i < nvalue.bv_len; i++ ) {
nvalue.bv_val[i] = TOUPPER( val->bv_val[i] );
}
*normalized = nvalue;
return LDAP_SUCCESS;
}
int ciboolean_initialize()
{
MatchingRule *bm = mr_find( "2.5.13.13" );
Syntax *syn = syn_find( "1.3.6.1.4.1.1466.115.121.1.7" );
if ( bm == NULL ) {
Debug( LDAP_DEBUG_ANY,
"ciboolean_initialize: unable to find booleanMatch matching rule\n");
return -1;
}
if ( syn == NULL ) {
Debug( LDAP_DEBUG_ANY,
"ciboolean_initialize: unable to find Boolean syntax\n");
return -1;
}
bm->smr_normalize = cibooleanMatchNormalize;
syn->ssyn_validate = cibooleanValidate;
return 0;
}
#if SLAPD_MOD_CIBOOLEAN == SLAPD_MOD_DYNAMIC
int init_module(int argc, char *argv[])
{
return ciboolean_initialize();
}
#endif
#endif /* SLAPD_MOD_CIBOOLEAN */
|