From: Howard Chu Date: Fri, 10 Dec 2004 03:18:33 +0000 (+0000) Subject: Moved cookie validation into slap_parse_sync_cookie so consumer uses it too X-Git-Tag: OPENLDAP_REL_ENG_2_3_0ALPHA~64 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=73bab2b619fa3ff15b322bfc0fda249ae5eeac0c;p=openldap Moved cookie validation into slap_parse_sync_cookie so consumer uses it too --- diff --git a/servers/slapd/ldapsync.c b/servers/slapd/ldapsync.c index 9141f937d9..6f6cefea34 100644 --- a/servers/slapd/ldapsync.c +++ b/servers/slapd/ldapsync.c @@ -117,31 +117,44 @@ slap_parse_sync_cookie( char *csn_ptr; char *csn_str; int csn_str_len; + int valid = 0; char *sid_ptr; char *sid_str; char *rid_ptr; char *rid_str; char *cval; - struct berval *ctxcsn; + struct berval ctxcsn; if ( cookie == NULL ) return -1; - if (( csn_ptr = strstr( cookie->octet_str[0].bv_val, "csn=" )) != NULL ) { - csn_str = SLAP_STRNDUP( csn_ptr, LDAP_LUTIL_CSNSTR_BUFSIZE ); - if ( (cval = strchr( csn_str, ',' )) != NULL ) { - *cval = '\0'; - csn_str_len = cval - csn_str - (sizeof("csn=") - 1); - } else { - csn_str_len = cookie->octet_str[0].bv_len - - (csn_ptr - cookie->octet_str[0].bv_val) - - (sizeof("csn=") - 1); - } - ctxcsn = ber_str2bv( csn_str + (sizeof("csn=")-1), - csn_str_len, 1, NULL ); - ch_free( csn_str ); - ber_bvarray_add( &cookie->ctxcsn, ctxcsn ); - ch_free( ctxcsn ); + while (( csn_ptr = strstr( cookie->octet_str[0].bv_val, "csn=" )) != NULL ) { + AttributeDescription *ad = slap_schema.si_ad_modifyTimestamp; + slap_syntax_validate_func *validate; + struct berval stamp; + + csn_str = csn_ptr + STRLENOF("csn="); + cval = strchr( csn_str, ',' ); + if ( cval ) + csn_str_len = cval - csn_str; + else + csn_str_len = 0; + + /* FIXME use csnValidate when it gets implemented */ + csn_ptr = strchr( csn_str, '#' ); + if ( !csn_ptr ) break; + + stamp.bv_val = csn_str; + stamp.bv_len = csn_ptr - csn_str; + validate = ad->ad_type->sat_syntax->ssyn_validate; + if ( validate( ad->ad_type->sat_syntax, &stamp ) != LDAP_SUCCESS ) + break; + valid = 1; + break; + } + if ( valid ) { + ber_str2bv( csn_str, csn_str_len, 1, &ctxcsn ); + ber_bvarray_add( &cookie->ctxcsn, &ctxcsn ); } else { cookie->ctxcsn = NULL; } diff --git a/servers/slapd/overlays/syncprov.c b/servers/slapd/overlays/syncprov.c index 2165411ae0..a746c2602e 100644 --- a/servers/slapd/overlays/syncprov.c +++ b/servers/slapd/overlays/syncprov.c @@ -1761,33 +1761,9 @@ syncprov_op_search( Operation *op, SlapReply *rs ) /* If we have a cookie, handle the PRESENT lookups */ if ( srs->sr_state.ctxcsn ) { sessionlog *sl; - int valid = 0; - /* Is the CSN in a valid format? */ - /* FIXME: should use csnValidate when that is implemented */ - while (!valid) { - char *ptr; - struct berval timestamp; - slap_syntax_validate_func *validate; - AttributeDescription *ad = slap_schema.si_ad_modifyTimestamp; + /* The cookie was validated when it was parsed, just use it */ - if ( srs->sr_state.ctxcsn->bv_len >= LDAP_LUTIL_CSNSTR_BUFSIZE ) - break; - ptr = strchr( srs->sr_state.ctxcsn->bv_val, '#' ); - if ( !ptr ) - break; - timestamp.bv_val = srs->sr_state.ctxcsn->bv_val; - timestamp.bv_len = ptr - timestamp.bv_val; - validate = ad->ad_type->sat_syntax->ssyn_validate; - if ( validate( ad->ad_type->sat_syntax, ×tamp )) - break; - valid = 1; - break; - } - /* Skip any present searches, there's nothing to compare */ - if ( !valid ) { - goto shortcut; - } /* If just Refreshing and nothing has changed, shortcut it */ if ( bvmatch( srs->sr_state.ctxcsn, &ctxcsn )) { nochange = 1;