/* $OpenLDAP$ */
/* This work is part of OpenLDAP Software <http://www.openldap.org/>.
*
- * Copyright 1998-2005 The OpenLDAP Foundation.
+ * Copyright 1998-2006 The OpenLDAP Foundation.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
return LDAP_SUCCESS;
}
-void
-hashDigestify(
+static void
+hashPreset(
HASH_CONTEXT *HASHcontext,
- unsigned char *HASHdigest,
struct berval *prefix,
char pre,
Syntax *syntax,
- MatchingRule *mr,
- unsigned char *value,
- int value_len)
+ MatchingRule *mr)
{
HASH_Init(HASHcontext);
if(prefix && prefix->bv_len > 0) {
if(pre) HASH_Update(HASHcontext, (unsigned char*)&pre, sizeof(pre));
HASH_Update(HASHcontext, (unsigned char*)syntax->ssyn_oid, syntax->ssyn_oidlen);
HASH_Update(HASHcontext, (unsigned char*)mr->smr_oid, mr->smr_oidlen);
- HASH_Update(HASHcontext, value, value_len);
- HASH_Final(HASHdigest, HASHcontext);
return;
}
+static void
+hashIter(
+ HASH_CONTEXT *HASHcontext,
+ unsigned char *HASHdigest,
+ unsigned char *value,
+ int len)
+{
+ HASH_CONTEXT ctx = *HASHcontext;
+ HASH_Update( &ctx, value, len );
+ HASH_Final( HASHdigest, &ctx );
+}
+
/* Index generation function */
int octetStringIndexer(
slap_mask_t use,
slen = syntax->ssyn_oidlen;
mlen = mr->smr_oidlen;
+ hashPreset( &HASHcontext, prefix, 0, syntax, mr);
for( i=0; !BER_BVISNULL( &values[i] ); i++ ) {
- hashDigestify( &HASHcontext, HASHdigest, prefix, 0,
- syntax, mr, (unsigned char *)values[i].bv_val, values[i].bv_len );
+ hashIter( &HASHcontext, HASHdigest,
+ (unsigned char *)values[i].bv_val, values[i].bv_len );
ber_dupbv_x( &keys[i], &digest, ctx );
}
keys = slap_sl_malloc( sizeof( struct berval ) * 2, ctx );
- hashDigestify( &HASHcontext, HASHdigest, prefix, 0,
- syntax, mr, (unsigned char *)value->bv_val, value->bv_len );
+ hashPreset( &HASHcontext, prefix, 0, syntax, mr );
+ hashIter( &HASHcontext, HASHdigest,
+ (unsigned char *)value->bv_val, value->bv_len );
ber_dupbv_x( keys, &digest, ctx );
BER_BVZERO( &keys[1] );
size_t slen, mlen;
BerVarray keys;
- HASH_CONTEXT HASHcontext;
+ HASH_CONTEXT HCany, HCini, HCfin;
unsigned char HASHdigest[HASH_BYTES];
struct berval digest;
digest.bv_val = (char *)HASHdigest;
slen = syntax->ssyn_oidlen;
mlen = mr->smr_oidlen;
+ if ( flags & SLAP_INDEX_SUBSTR_ANY )
+ hashPreset( &HCany, prefix, SLAP_INDEX_SUBSTR_PREFIX, syntax, mr );
+ if( flags & SLAP_INDEX_SUBSTR_INITIAL )
+ hashPreset( &HCini, prefix, SLAP_INDEX_SUBSTR_INITIAL_PREFIX, syntax, mr );
+ if( flags & SLAP_INDEX_SUBSTR_FINAL )
+ hashPreset( &HCfin, prefix, SLAP_INDEX_SUBSTR_FINAL_PREFIX, syntax, mr );
+
nkeys = 0;
for ( i = 0; !BER_BVISNULL( &values[i] ); i++ ) {
ber_len_t j,max;
if( ( flags & SLAP_INDEX_SUBSTR_ANY ) &&
( values[i].bv_len >= index_substr_any_len ) )
{
- char pre = SLAP_INDEX_SUBSTR_PREFIX;
max = values[i].bv_len - (index_substr_any_len - 1);
for( j=0; j<max; j++ ) {
- hashDigestify( &HASHcontext, HASHdigest, prefix, pre,
- syntax, mr, (unsigned char *)&values[i].bv_val[j], index_substr_any_len);
+ hashIter( &HCany, HASHdigest,
+ (unsigned char *)&values[i].bv_val[j],
+ index_substr_any_len );
ber_dupbv_x( &keys[nkeys++], &digest, ctx );
}
}
? index_substr_if_maxlen : values[i].bv_len;
for( j=index_substr_if_minlen; j<=max; j++ ) {
- char pre;
if( flags & SLAP_INDEX_SUBSTR_INITIAL ) {
- pre = SLAP_INDEX_SUBSTR_INITIAL_PREFIX;
- hashDigestify( &HASHcontext, HASHdigest, prefix, pre,
- syntax, mr, (unsigned char *)values[i].bv_val, j );
+ hashIter( &HCini, HASHdigest,
+ (unsigned char *)values[i].bv_val, j );
ber_dupbv_x( &keys[nkeys++], &digest, ctx );
}
if( flags & SLAP_INDEX_SUBSTR_FINAL ) {
- pre = SLAP_INDEX_SUBSTR_FINAL_PREFIX;
- hashDigestify( &HASHcontext, HASHdigest, prefix, pre,
- syntax, mr, (unsigned char *)&values[i].bv_val[values[i].bv_len-j], j );
+ hashIter( &HCfin, HASHdigest,
+ (unsigned char *)&values[i].bv_val[values[i].bv_len-j], j );
ber_dupbv_x( &keys[nkeys++], &digest, ctx );
}
klen = index_substr_if_maxlen < value->bv_len
? index_substr_if_maxlen : value->bv_len;
- hashDigestify( &HASHcontext, HASHdigest, prefix, pre,
- syntax, mr, (unsigned char *)value->bv_val, klen );
+ hashPreset( &HASHcontext, prefix, pre, syntax, mr );
+ hashIter( &HASHcontext, HASHdigest,
+ (unsigned char *)value->bv_val, klen );
ber_dupbv_x( &keys[nkeys++], &digest, ctx );
/* If initial is too long and we have subany indexed, use it
{
ber_len_t j;
pre = SLAP_INDEX_SUBSTR_PREFIX;
+ hashPreset( &HASHcontext, prefix, pre, syntax, mr);
for ( j=index_substr_if_maxlen-1; j <= value->bv_len - index_substr_any_len; j+=index_substr_any_step )
{
- hashDigestify( &HASHcontext, HASHdigest, prefix, pre,
- syntax, mr, (unsigned char *)&value->bv_val[j], index_substr_any_len );
+ hashIter( &HASHcontext, HASHdigest,
+ (unsigned char *)&value->bv_val[j], index_substr_any_len );
ber_dupbv_x( &keys[nkeys++], &digest, ctx );
}
}
value = &sa->sa_any[i];
+ hashPreset( &HASHcontext, prefix, pre, syntax, mr);
for(j=0;
j <= value->bv_len - index_substr_any_len;
j += index_substr_any_step )
{
- hashDigestify( &HASHcontext, HASHdigest, prefix, pre,
- syntax, mr, (unsigned char *)&value->bv_val[j], klen );
+ hashIter( &HASHcontext, HASHdigest,
+ (unsigned char *)&value->bv_val[j], klen );
ber_dupbv_x( &keys[nkeys++], &digest, ctx );
}
}
klen = index_substr_if_maxlen < value->bv_len
? index_substr_if_maxlen : value->bv_len;
- hashDigestify( &HASHcontext, HASHdigest, prefix, pre,
- syntax, mr, (unsigned char *)&value->bv_val[value->bv_len-klen], klen );
+ hashPreset( &HASHcontext, prefix, pre, syntax, mr );
+ hashIter( &HASHcontext, HASHdigest,
+ (unsigned char *)&value->bv_val[value->bv_len-klen], klen );
ber_dupbv_x( &keys[nkeys++], &digest, ctx );
/* If final is too long and we have subany indexed, use it
{
ber_len_t j;
pre = SLAP_INDEX_SUBSTR_PREFIX;
+ hashPreset( &HASHcontext, prefix, pre, syntax, mr);
for ( j=0; j <= value->bv_len - index_substr_if_maxlen; j+=index_substr_any_step )
{
- hashDigestify( &HASHcontext, HASHdigest, prefix, pre,
- syntax, mr, (unsigned char *)&value->bv_val[j], index_substr_any_len );
+ hashIter( &HASHcontext, HASHdigest,
+ (unsigned char *)&value->bv_val[j], index_substr_any_len );
ber_dupbv_x( &keys[nkeys++], &digest, ctx );
}
}
struct berval *asserted = (struct berval *) assertedValue;
struct berval assertedDN = *asserted;
struct berval assertedUID = BER_BVNULL;
- struct berval valueDN = BER_BVNULL;
+ struct berval valueDN = *value;
struct berval valueUID = BER_BVNULL;
int approx = ((flags & SLAP_MR_EQUALITY_APPROX) == SLAP_MR_EQUALITY_APPROX);
}
if ( !BER_BVISEMPTY( value ) ) {
- valueDN = *value;
valueUID.bv_val = strrchr( valueDN.bv_val, '#' );
if ( !BER_BVISNULL( &valueUID ) ) {
}
static int
+UUIDPretty(
+ Syntax *syntax,
+ struct berval *in,
+ struct berval *out,
+ void *ctx )
+{
+ int i;
+ int rc=LDAP_INVALID_SYNTAX;
+
+ assert( in != NULL );
+ assert( out != NULL );
+
+ if( in->bv_len != 36 ) return LDAP_INVALID_SYNTAX;
+
+ out->bv_len = 36;
+ out->bv_val = slap_sl_malloc( out->bv_len + 1, ctx );
+
+ for( i=0; i<36; i++ ) {
+ switch(i) {
+ case 8:
+ case 13:
+ case 18:
+ case 23:
+ if( in->bv_val[i] != '-' ) {
+ goto handle_error;
+ }
+ out->bv_val[i] = '-';
+ break;
+
+ default:
+ if( !ASCII_HEX( in->bv_val[i]) ) {
+ goto handle_error;
+ }
+ out->bv_val[i] = TOLOWER( in->bv_val[i] );
+ }
+ }
+
+ rc = LDAP_SUCCESS;
+ out->bv_val[ out->bv_len ] = '\0';
+
+ if( 0 ) {
+handle_error:
+ slap_sl_free( out->bv_val, ctx );
+ out->bv_val = NULL;
+ }
+
+ return rc;
+}
+
+int
UUIDNormalize(
slap_mask_t usage,
Syntax *syntax,
struct berval sn, i;
if( in->bv_len < 3 ) return LDAP_INVALID_SYNTAX;
- i.bv_val = strchr( in->bv_val, '$' );
+ i.bv_val = ber_bvchr( in, '$' );
if( BER_BVISNULL( &i ) ) return LDAP_INVALID_SYNTAX;
sn.bv_val = in->bv_val;
if( val->bv_len < 3 ) return LDAP_INVALID_SYNTAX;
- i.bv_val = strchr( val->bv_val, '$' );
+ i.bv_val = ber_bvchr( val, '$' );
if( BER_BVISNULL( &i ) ) return LDAP_INVALID_SYNTAX;
sn.bv_val = val->bv_val;
if( val->bv_len < 3 ) return LDAP_INVALID_SYNTAX;
- i.bv_val = strchr( val->bv_val, '$' );
+ i.bv_val = ber_bvchr( val, '$' );
if( BER_BVISNULL( &i ) ) return LDAP_INVALID_SYNTAX;
sn.bv_val = val->bv_val;
SLAP_SYNTAX_HIDE, NULL, NULL},
#endif
- {"( 1.3.6.1.4.1.4203.666.2.6 DESC 'UUID' )",
- SLAP_SYNTAX_HIDE, UUIDValidate, NULL},
+ {"( 1.3.6.1.1.16.1 DESC 'UUID' )",
+ 0, UUIDValidate, UUIDPretty},
{"( 1.3.6.1.4.1.4203.666.11.2.1 DESC 'CSN' )",
SLAP_SYNTAX_HIDE, csnValidate, NULL},
NULL, NULL,
"integerMatch" },
- {"( 1.3.6.1.4.1.4203.666.4.6 NAME 'UUIDMatch' "
- "SYNTAX 1.3.6.1.4.1.4203.666.2.6 )",
- SLAP_MR_HIDE | SLAP_MR_EQUALITY, NULL,
+ {"( 1.3.6.1.1.16.2 NAME 'UUIDMatch' "
+ "SYNTAX 1.3.6.1.1.16.1 )",
+ SLAP_MR_EQUALITY | SLAP_MR_MUTATION_NORMALIZER, NULL,
NULL, UUIDNormalize, octetStringMatch,
octetStringIndexer, octetStringFilter,
NULL},
- {"( 1.3.6.1.4.1.4203.666.4.7 NAME 'UUIDOrderingMatch' "
- "SYNTAX 1.3.6.1.4.1.4203.666.2.6 )",
- SLAP_MR_HIDE | SLAP_MR_ORDERING, NULL,
+ {"( 1.3.6.1.1.16.3 NAME 'UUIDOrderingMatch' "
+ "SYNTAX 1.3.6.1.1.16.1 )",
+ SLAP_MR_ORDERING | SLAP_MR_MUTATION_NORMALIZER, NULL,
NULL, UUIDNormalize, octetStringOrderingMatch,
octetStringIndexer, octetStringFilter,
"UUIDMatch"},