]> git.sur5r.net Git - openldap/commitdiff
ITS#3917 don't check csn syntax if schema isn't inited yet
authorHoward Chu <hyc@openldap.org>
Mon, 8 Aug 2005 23:56:40 +0000 (23:56 +0000)
committerHoward Chu <hyc@openldap.org>
Mon, 8 Aug 2005 23:56:40 +0000 (23:56 +0000)
servers/slapd/ldapsync.c
servers/slapd/main.c
servers/slapd/syncrepl.c

index 290590377728a7f4032a304f2437cb7fa6285161..9d335860dfbb9c8057d27fc211f02f7bc7a1fd82 100644 (file)
@@ -95,17 +95,33 @@ slap_parse_sync_cookie(
        int csn_str_len;
        int valid = 0;
        char *rid_ptr;
-       char *rid_str;
        char *cval;
 
        if ( cookie == NULL )
                return -1;
 
+       cookie->rid = -1;
+       if (( rid_ptr = strstr( cookie->octet_str.bv_val, "rid=" )) != NULL ) {
+               if ( (cval = strchr( rid_ptr, ',' )) != NULL ) {
+                       *cval = '\0';
+               }
+               cookie->rid = atoi( rid_ptr + sizeof("rid=") - 1 );
+               if ( cval != NULL ) {
+                       *cval = ',';
+               }
+       } else {
+               return -1;
+       }
+
        while (( csn_ptr = strstr( cookie->octet_str.bv_val, "csn=" )) != NULL ) {
                AttributeDescription *ad = slap_schema.si_ad_modifyTimestamp;
                slap_syntax_validate_func *validate;
                struct berval stamp;
 
+               /* This only happens when called from main */
+               if ( ad == NULL )
+                       break;
+
                csn_str = csn_ptr + STRLENOF("csn=");
                cval = strchr( csn_str, ',' );
                if ( cval )
@@ -131,17 +147,6 @@ slap_parse_sync_cookie(
                BER_BVZERO( &cookie->ctxcsn );
        }
 
-       if (( rid_ptr = strstr( cookie->octet_str.bv_val, "rid=" )) != NULL ) {
-               rid_str = SLAP_STRNDUP( rid_ptr,
-                                                       SLAP_SYNC_RID_SIZE + sizeof("rid=") - 1 );
-               if ( (cval = strchr( rid_str, ',' )) != NULL ) {
-                       *cval = '\0';
-               }
-               cookie->rid = atoi( rid_str + sizeof("rid=") - 1 );
-               ch_free( rid_str );
-       } else {
-               cookie->rid = -1;
-       }
        return 0;
 }
 
index 4f6360f62693d5827a320adc98697094c6ac39ac..02becaa502dffef82691e5d85472fb5931edd34c 100644 (file)
@@ -362,8 +362,18 @@ int main( int argc, char **argv )
                        scp = (struct sync_cookie *) ch_calloc( 1,
                                                                                sizeof( struct sync_cookie ));
                        ber_str2bv( optarg, 0, 1, &scp->octet_str );
+                       
+                       /* This only parses out the rid at this point */
                        slap_parse_sync_cookie( scp, NULL );
 
+                       if ( scp->rid == -1 ) {
+                               Debug( LDAP_DEBUG_ANY,
+                                               "main: invalid cookie \"%s\"\n",
+                                               optarg, 0, 0 );
+                               slap_sync_cookie_free( scp, 1 );
+                               goto destroy;
+                       }
+
                        LDAP_STAILQ_FOREACH( scp_entry, &slap_sync_cookie, sc_next ) {
                                if ( scp->rid == scp_entry->rid ) {
                                        Debug( LDAP_DEBUG_ANY,
index e944dc57242cb68f5b1f5fb55a1684c6afeeb2c1..cba7f7e813ab42f67812d5ec083b5a3f90fa003c 100644 (file)
@@ -482,6 +482,8 @@ do_syncrep1(
 
                        LDAP_STAILQ_REMOVE( &slap_sync_cookie, sc, sync_cookie, sc_next );
 
+                       /* ctxcsn wasn't parsed yet, do it now */
+                       slap_parse_sync_cookie( sc, op->o_tmpmemctx );
                        if ( BER_BVISNULL( &sc->ctxcsn ) ) {
                                /* if cmdline cookie does not have ctxcsn */
                                /* component, set it to an initial value */