]> git.sur5r.net Git - openldap/commitdiff
Moved cookie validation into slap_parse_sync_cookie so consumer uses it too
authorHoward Chu <hyc@openldap.org>
Fri, 10 Dec 2004 03:18:33 +0000 (03:18 +0000)
committerHoward Chu <hyc@openldap.org>
Fri, 10 Dec 2004 03:18:33 +0000 (03:18 +0000)
servers/slapd/ldapsync.c
servers/slapd/overlays/syncprov.c

index 9141f937d9fab5cee0c5a420c1593f0061edce9e..6f6cefea3430f4024604d77824511bc045fe00e6 100644 (file)
@@ -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;
        }
index 2165411ae0498c589875f05052a5163aa34af1d7..a746c2602e14d178a642fe1ed95c80e56b3cf68d 100644 (file)
@@ -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, &timestamp ))
-                               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;