From b527294153be3b79563c82c66102adc0004736c0 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Mon, 15 Apr 2024 19:54:12 +0200 Subject: Adding upstream version 2.6.7+dfsg. Signed-off-by: Daniel Baumann --- contrib/slapd-modules/ciboolean/ciboolean.c | 110 ++++++++++++++++++++++++++++ 1 file changed, 110 insertions(+) create mode 100644 contrib/slapd-modules/ciboolean/ciboolean.c (limited to 'contrib/slapd-modules/ciboolean/ciboolean.c') diff --git a/contrib/slapd-modules/ciboolean/ciboolean.c b/contrib/slapd-modules/ciboolean/ciboolean.c new file mode 100644 index 0000000..21e0f1a --- /dev/null +++ b/contrib/slapd-modules/ciboolean/ciboolean.c @@ -0,0 +1,110 @@ +/* ciboolean.c - enable case-insensitive boolean values */ +/* $OpenLDAP$ */ +/* This work is part of OpenLDAP Software . + * + * 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 + * . + */ +/* 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 */ -- cgit v1.2.3