From: Pierangelo Masarati Date: Sat, 2 Feb 2008 10:23:35 +0000 (+0000) Subject: allow 2.1 CSN format (ITS#5348) X-Git-Tag: OPENLDAP_REL_ENG_2_4_9~20^2~197 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=137172f952d0e70a736d872a5a10bfbdfb90a68c;p=openldap allow 2.1 CSN format (ITS#5348) --- diff --git a/servers/slapd/schema_init.c b/servers/slapd/schema_init.c index 938180a543..c345065d3b 100644 --- a/servers/slapd/schema_init.c +++ b/servers/slapd/schema_init.c @@ -3561,6 +3561,114 @@ csnValidate( return hexValidate( NULL, &bv ); } +/* Normalize a CSN in OpenLDAP 2.1 format */ +static int +csnNormalize21( + slap_mask_t usage, + Syntax *syntax, + MatchingRule *mr, + struct berval *val, + struct berval *normalized, + void *ctx ) +{ + struct berval gt, cnt, sid, mod; + struct berval bv; + char buf[ STRLENOF( "YYYYmmddHHMMSS.uuuuuuZ#SSSSSS#SID#ssssss" ) + 1 ]; + char *ptr; + int i; + + assert( SLAP_MR_IS_VALUE_OF_SYNTAX( usage ) != 0 ); + assert( !BER_BVISEMPTY( val ) ); + + gt = *val; + + ptr = ber_bvchr( >, '#' ); + if ( ptr == NULL || ptr - gt.bv_val == gt.bv_len ) { + return LDAP_INVALID_SYNTAX; + } + + gt.bv_len = ptr - gt.bv_val; + if ( gt.bv_len != STRLENOF( "YYYYmmddHH:MM:SSZ" ) ) { + return LDAP_INVALID_SYNTAX; + } + + if ( gt.bv_val[ 10 ] != ':' || gt.bv_val[ 13 ] != ':' ) { + return LDAP_INVALID_SYNTAX; + } + + cnt.bv_val = ptr + 1; + cnt.bv_len = val->bv_len - ( cnt.bv_val - val->bv_val ); + + ptr = ber_bvchr( &cnt, '#' ); + if ( ptr == NULL || ptr - val->bv_val == val->bv_len ) { + return LDAP_INVALID_SYNTAX; + } + + cnt.bv_len = ptr - cnt.bv_val; + if ( cnt.bv_len != STRLENOF( "0x0000" ) ) { + return LDAP_INVALID_SYNTAX; + } + + if ( strncmp( cnt.bv_val, "0x", STRLENOF( "0x" ) ) != 0 ) { + return LDAP_INVALID_SYNTAX; + } + + cnt.bv_val += STRLENOF( "0x" ); + cnt.bv_len -= STRLENOF( "0x" ); + + sid.bv_val = ptr + 1; + sid.bv_len = val->bv_len - ( sid.bv_val - val->bv_val ); + + ptr = ber_bvchr( &sid, '#' ); + if ( ptr == NULL || ptr - val->bv_val == val->bv_len ) { + return LDAP_INVALID_SYNTAX; + } + + sid.bv_len = ptr - sid.bv_val; + if ( sid.bv_len != STRLENOF( "0" ) ) { + return LDAP_INVALID_SYNTAX; + } + + mod.bv_val = ptr + 1; + mod.bv_len = val->bv_len - ( mod.bv_val - val->bv_val ); + if ( mod.bv_len != STRLENOF( "0000" ) ) { + return LDAP_INVALID_SYNTAX; + } + + bv.bv_len = STRLENOF( "YYYYmmddHHMMSS.uuuuuuZ#SSSSSS#SID#ssssss" ); + bv.bv_val = buf; + + ptr = bv.bv_val; + ptr = lutil_strncopy( ptr, gt.bv_val, STRLENOF( "YYYYmmddHH" ) ); + ptr = lutil_strncopy( ptr, >.bv_val[ STRLENOF( "YYYYmmddHH:" ) ], + STRLENOF( "MM" ) ); + ptr = lutil_strncopy( ptr, >.bv_val[ STRLENOF( "YYYYmmddHH:MM:" ) ], + STRLENOF( "SS" ) ); + ptr = lutil_strcopy( ptr, ".000000Z#00" ); + ptr = lutil_strncopy( ptr, cnt.bv_val, cnt.bv_len ); + *ptr++ = '#'; + *ptr++ = '0'; + *ptr++ = '0'; + *ptr++ = sid.bv_val[ 0 ]; + *ptr++ = '#'; + *ptr++ = '0'; + *ptr++ = '0'; + for ( i = 0; i < mod.bv_len; i++ ) { + *ptr++ = TOLOWER( mod.bv_val[ i ] ); + } + *ptr = '\0'; + + assert( ptr - bv.bv_val == bv.bv_len ); + + if ( csnValidate( syntax, &bv ) != LDAP_SUCCESS ) { + return LDAP_INVALID_SYNTAX; + } + + ber_dupbv_x( normalized, &bv, ctx ); + + return LDAP_SUCCESS; +} + /* Normalize a CSN in OpenLDAP 2.3 format */ static int csnNormalize23( @@ -3572,6 +3680,8 @@ csnNormalize23( void *ctx ) { struct berval gt, cnt, sid, mod; + struct berval bv; + char buf[ STRLENOF( "YYYYmmddHHMMSS.uuuuuuZ#SSSSSS#SID#ssssss" ) + 1 ]; char *ptr; int i; @@ -3622,10 +3732,10 @@ csnNormalize23( return LDAP_INVALID_SYNTAX; } - normalized->bv_len = STRLENOF( "YYYYmmddHHMMSS.uuuuuuZ#SSSSSS#SID#ssssss" ); - normalized->bv_val = ber_memalloc_x( normalized->bv_len + 1, ctx ); + bv.bv_len = STRLENOF( "YYYYmmddHHMMSS.uuuuuuZ#SSSSSS#SID#ssssss" ); + bv.bv_val = buf; - ptr = normalized->bv_val; + ptr = bv.bv_val; ptr = lutil_strncopy( ptr, gt.bv_val, gt.bv_len - 1 ); ptr = lutil_strcopy( ptr, ".000000Z#" ); ptr = lutil_strncopy( ptr, cnt.bv_val, cnt.bv_len ); @@ -3640,11 +3750,13 @@ csnNormalize23( } *ptr = '\0'; - if ( ptr - normalized->bv_val != normalized->bv_len ) { - ber_memfree_x( normalized->bv_val, ctx ); + assert( ptr - bv.bv_val == bv.bv_len ); + if ( csnValidate( syntax, &bv ) != LDAP_SUCCESS ) { return LDAP_INVALID_SYNTAX; } + ber_dupbv_x( normalized, &bv, ctx ); + return LDAP_SUCCESS; } @@ -3677,6 +3789,12 @@ csnNormalize( return csnNormalize23( usage, syntax, mr, val, normalized, ctx ); } + if ( val->bv_len == STRLENOF( "YYYYmmddHH:MM:SSZ#0xSSSS#I#ssss" ) ) { + /* Openldap 2.1 */ + + return csnNormalize21( usage, syntax, mr, val, normalized, ctx ); + } + if ( val->bv_len != STRLENOF( "YYYYmmddHHMMSS.uuuuuuZ#SSSSSS#SID#ssssss" ) ) { return LDAP_INVALID_SYNTAX; }