]> git.sur5r.net Git - openldap/blobdiff - servers/slapd/ldapsync.c
ITS#3846 don't give hashed passwords to SASL, it only wants cleartext.
[openldap] / servers / slapd / ldapsync.c
index 748361d70a63b05e3bd5a289ab0e007d7ffba031..5ecf2590f799c9c4c5f52edaa29b985b5a397f1b 100644 (file)
 #include "../../libraries/liblber/lber-int.h" /* get ber_strndup() */
 #include "lutil_ldap.h"
 
-#if 0
-struct sync_cookie *slap_sync_cookie = NULL;
-#else
 struct slap_sync_cookie_s slap_sync_cookie =
        LDAP_STAILQ_HEAD_INITIALIZER( slap_sync_cookie );
-#endif
 
 void
 slap_compose_sync_cookie(
@@ -43,7 +39,7 @@ slap_compose_sync_cookie(
 {
        char cookiestr[ LDAP_LUTIL_CSNSTR_BUFSIZE + 20 ];
 
-       if ( csn->bv_val == NULL ) {
+       if ( BER_BVISNULL( csn )) {
                if ( rid == -1 ) {
                        cookiestr[0] = '\0';
                } else {
@@ -71,14 +67,14 @@ slap_sync_cookie_free(
        if ( cookie == NULL )
                return;
 
-       if ( cookie->ctxcsn ) {
-               ber_bvarray_free( cookie->ctxcsn );
-               cookie->ctxcsn = NULL;
+       if ( !BER_BVISNULL( &cookie->ctxcsn )) {
+               ch_free( cookie->ctxcsn.bv_val );
+               BER_BVZERO( &cookie->ctxcsn );
        }
 
-       if ( cookie->octet_str ) {
-               ber_bvarray_free( cookie->octet_str );
-               cookie->octet_str = NULL;
+       if ( !BER_BVISNULL( &cookie->octet_str )) {
+               ch_free( cookie->octet_str.bv_val );
+               BER_BVZERO( &cookie->octet_str );
        }
 
        if ( free_cookie ) {
@@ -100,12 +96,11 @@ slap_parse_sync_cookie(
        char *rid_ptr;
        char *rid_str;
        char *cval;
-       struct berval ctxcsn;
 
        if ( cookie == NULL )
                return -1;
 
-       while (( csn_ptr = strstr( cookie->octet_str[0].bv_val, "csn=" )) != NULL ) {
+       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;
@@ -130,13 +125,12 @@ slap_parse_sync_cookie(
                break;
        }
        if ( valid ) {
-               ber_str2bv( csn_str, csn_str_len, 1, &ctxcsn );
-               ber_bvarray_add( &cookie->ctxcsn, &ctxcsn );
+               ber_str2bv( csn_str, csn_str_len, 1, &cookie->ctxcsn );
        } else {
-               cookie->ctxcsn = NULL;
+               BER_BVZERO( &cookie->ctxcsn );
        }
 
-       if (( rid_ptr = strstr( cookie->octet_str->bv_val, "rid=" )) != NULL ) {
+       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 ) {
@@ -158,8 +152,6 @@ slap_init_sync_cookie_ctxcsn(
        char csnbuf[ LDAP_LUTIL_CSNSTR_BUFSIZE + 4 ];
        struct berval octet_str = BER_BVNULL;
        struct berval ctxcsn = BER_BVNULL;
-       struct berval ctxcsn_dup = BER_BVNULL;
-       struct berval slap_syncCookie;
 
        if ( cookie == NULL )
                return -1;
@@ -168,15 +160,12 @@ slap_init_sync_cookie_ctxcsn(
                                        "csn=%4d%02d%02d%02d%02d%02dZ#%06x#%02x#%06x",
                                        1900, 1, 1, 0, 0, 0, 0, 0, 0 );
        octet_str.bv_val = csnbuf;
-       build_new_dn( &slap_syncCookie, &cookie->octet_str[0], &octet_str, NULL );
-       ber_bvarray_free( cookie->octet_str );
-       cookie->octet_str = NULL;
-       ber_bvarray_add( &cookie->octet_str, &slap_syncCookie );
+       ch_free( cookie->octet_str.bv_val );
+       ber_dupbv( &cookie->octet_str, &octet_str );
 
        ctxcsn.bv_val = octet_str.bv_val + 4;
        ctxcsn.bv_len = octet_str.bv_len - 4;
-       ber_dupbv( &ctxcsn_dup, &ctxcsn );
-       ber_bvarray_add( &cookie->ctxcsn, &ctxcsn_dup );
+       ber_dupbv( &cookie->ctxcsn, &ctxcsn );
 
        return 0;
 }
@@ -195,8 +184,10 @@ slap_dup_sync_cookie(
                return NULL;
 
        if ( dst ) {
-               ber_bvarray_free( dst->ctxcsn );
-               ber_bvarray_free( dst->octet_str );
+               ch_free( dst->ctxcsn.bv_val );
+               ch_free( dst->octet_str.bv_val );
+               BER_BVZERO( &dst->ctxcsn );
+               BER_BVZERO( &dst->octet_str );
                new = dst;
        } else {
                new = ( struct sync_cookie * )
@@ -205,18 +196,12 @@ slap_dup_sync_cookie(
 
        new->rid = src->rid;
 
-       if ( src->ctxcsn ) {
-               for ( i=0; src->ctxcsn[i].bv_val; i++ ) {
-                       ber_dupbv( &tmp_bv, &src->ctxcsn[i] );
-                       ber_bvarray_add( &new->ctxcsn, &tmp_bv );
-               }
+       if ( !BER_BVISNULL( &src->ctxcsn )) {
+               ber_dupbv( &new->ctxcsn, &src->ctxcsn );
        }
 
-       if ( src->octet_str ) {
-               for ( i=0; src->octet_str[i].bv_val; i++ ) {
-                       ber_dupbv( &tmp_bv, &src->octet_str[i] );
-                       ber_bvarray_add( &new->octet_str, &tmp_bv );
-               }
+       if ( !BER_BVISNULL( &src->octet_str )) {
+               ber_dupbv( &new->octet_str, &src->octet_str );
        }
 
        return new;