Commit 9c87b2de authored by Quanah Gibson-Mount's avatar Quanah Gibson-Mount
Browse files

ITS#5348

parent a2217a78
......@@ -11,6 +11,7 @@ OpenLDAP 2.4.8 Engineering
Fixed libldap paged results crash (ITS#5315)
Fixed libldap use of %n (ITS#5324)
Fixed ldapdelete with sizelimit (ITS#5294)
Fixed slapd support for 2.1 CSN (ITS#5348)
Fixed slapd idlcache on adds (ITS#5086)
Fixed slapd include handling (ITS#5276)
Fixed slapd indexing with component matching (ITS#4112)
......
......@@ -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( &gt, '#' );
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, &gt.bv_val[ STRLENOF( "YYYYmmddHH:" ) ],
STRLENOF( "MM" ) );
ptr = lutil_strncopy( ptr, &gt.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;
......@@ -3586,7 +3696,9 @@ csnNormalize23(
}
gt.bv_len = ptr - gt.bv_val;
assert( gt.bv_len == STRLENOF( "YYYYmmddHHMMSSZ" ) );
if ( gt.bv_len != STRLENOF( "YYYYmmddHHMMSSZ" ) ) {
return LDAP_INVALID_SYNTAX;
}
cnt.bv_val = ptr + 1;
cnt.bv_len = val->bv_len - ( cnt.bv_val - val->bv_val );
......@@ -3597,7 +3709,9 @@ csnNormalize23(
}
cnt.bv_len = ptr - cnt.bv_val;
assert( cnt.bv_len == STRLENOF( "000000" ) );
if ( cnt.bv_len != STRLENOF( "000000" ) ) {
return LDAP_INVALID_SYNTAX;
}
sid.bv_val = ptr + 1;
sid.bv_len = val->bv_len - ( sid.bv_val - val->bv_val );
......@@ -3608,16 +3722,20 @@ csnNormalize23(
}
sid.bv_len = ptr - sid.bv_val;
assert( sid.bv_len == STRLENOF( "00" ) );
if ( sid.bv_len != STRLENOF( "00" ) ) {
return LDAP_INVALID_SYNTAX;
}
mod.bv_val = ptr + 1;
mod.bv_len = val->bv_len - ( mod.bv_val - val->bv_val );
assert( mod.bv_len == STRLENOF( "000000" ) );
if ( mod.bv_len != STRLENOF( "000000" ) ) {
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 );
......@@ -3632,7 +3750,12 @@ csnNormalize23(
}
*ptr = '\0';
assert( ptr - normalized->bv_val == normalized->bv_len );
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;
}
......@@ -3666,14 +3789,24 @@ csnNormalize(
return csnNormalize23( usage, syntax, mr, val, normalized, ctx );
}
assert( val->bv_len == STRLENOF( "YYYYmmddHHMMSS.uuuuuuZ#SSSSSS#SID#ssssss" ) );
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;
}
ptr = ber_bvchr( val, '#' );
if ( ptr == NULL || ptr - val->bv_val == val->bv_len ) {
return LDAP_INVALID_SYNTAX;
}
assert( ptr - val->bv_val == STRLENOF( "YYYYmmddHHMMSS.uuuuuuZ" ) );
if ( ptr - val->bv_val != STRLENOF( "YYYYmmddHHMMSS.uuuuuuZ" ) ) {
return LDAP_INVALID_SYNTAX;
}
cnt.bv_val = ptr + 1;
cnt.bv_len = val->bv_len - ( cnt.bv_val - val->bv_val );
......@@ -3683,7 +3816,9 @@ csnNormalize(
return LDAP_INVALID_SYNTAX;
}
assert( ptr - cnt.bv_val == STRLENOF( "000000" ) );
if ( ptr - cnt.bv_val != STRLENOF( "000000" ) ) {
return LDAP_INVALID_SYNTAX;
}
sid.bv_val = ptr + 1;
sid.bv_len = val->bv_len - ( sid.bv_val - val->bv_val );
......@@ -3694,12 +3829,16 @@ csnNormalize(
}
sid.bv_len = ptr - sid.bv_val;
assert( sid.bv_len == STRLENOF( "000" ) );
if ( sid.bv_len != STRLENOF( "000" ) ) {
return LDAP_INVALID_SYNTAX;
}
mod.bv_val = ptr + 1;
mod.bv_len = val->bv_len - ( mod.bv_val - val->bv_val );
assert( mod.bv_len == STRLENOF( "000000" ) );
if ( mod.bv_len != STRLENOF( "000000" ) ) {
return LDAP_INVALID_SYNTAX;
}
ber_dupbv_x( normalized, val, ctx );
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment