]> git.sur5r.net Git - openldap/blobdiff - servers/slapd/syncrepl.c
update for new backend types
[openldap] / servers / slapd / syncrepl.c
index 767ed876669f68d67088c21ad8694993b70c97d1..55541c19b7989951f2e7e445badd10336a74f176 100644 (file)
@@ -42,37 +42,38 @@ struct nonpresent_entry {
 };
 
 typedef struct syncinfo_s {
-        struct slap_backend_db *si_be;
-        long                           si_rid;
-        struct berval          si_provideruri;
-               slap_bindconf           si_bindconf;
-        struct berval          si_filterstr;
-        struct berval          si_base;
-        int                                    si_scope;
-        int                                    si_attrsonly;
-               char                            *si_anfile;
-               AttributeName           *si_anlist;
-               AttributeName           *si_exanlist;
-               char                            **si_attrs;
-               char                            **si_exattrs;
-               int                                     si_allattrs;
-               int                                     si_allopattrs;
-               int                                     si_schemachecking;
-        int                                    si_type;
-        time_t                         si_interval;
-               time_t                          *si_retryinterval;
-               int                                     *si_retrynum_init;
-               int                                     *si_retrynum;
-               struct sync_cookie      si_syncCookie;
-        int                                    si_manageDSAit;
-        int                                    si_slimit;
-               int                                     si_tlimit;
-               int                                     si_refreshDelete;
-               int                                     si_refreshPresent;
-        Avlnode                                *si_presentlist;
-               LDAP                            *si_ld;
-               LDAP_LIST_HEAD(np, nonpresent_entry) si_nonpresentlist;
-               ldap_pvt_thread_mutex_t si_mutex;
+       struct slap_backend_db *si_be;
+       struct re_s                     *si_re;
+       long                            si_rid;
+       struct berval           si_provideruri;
+       slap_bindconf           si_bindconf;
+       struct berval           si_filterstr;
+       struct berval           si_base;
+       int                                     si_scope;
+       int                                     si_attrsonly;
+       char                            *si_anfile;
+       AttributeName           *si_anlist;
+       AttributeName           *si_exanlist;
+       char                            **si_attrs;
+       char                            **si_exattrs;
+       int                                     si_allattrs;
+       int                                     si_allopattrs;
+       int                                     si_schemachecking;
+       int                                     si_type;
+       time_t                          si_interval;
+       time_t                          *si_retryinterval;
+       int                                     *si_retrynum_init;
+       int                                     *si_retrynum;
+       struct sync_cookie      si_syncCookie;
+       int                                     si_manageDSAit;
+       int                                     si_slimit;
+       int                                     si_tlimit;
+       int                                     si_refreshDelete;
+       int                                     si_refreshPresent;
+       Avlnode                         *si_presentlist;
+       LDAP                            *si_ld;
+       LDAP_LIST_HEAD(np, nonpresent_entry) si_nonpresentlist;
+       ldap_pvt_thread_mutex_t si_mutex;
 } syncinfo_t;
 
 static int syncuuid_cmp( const void *, const void * );
@@ -882,7 +883,7 @@ done:
        return rc;
 }
 
-void *
+static void *
 do_syncrepl(
        void    *ctx,
        void    *arg )
@@ -1021,7 +1022,7 @@ do_syncrepl(
        return NULL;
 }
 
-int
+static int
 syncrepl_message_to_entry(
        syncinfo_t      *si,
        Operation       *op,
@@ -1093,6 +1094,7 @@ syncrepl_message_to_entry(
                mod  = (Modifications *) ch_malloc( sizeof( Modifications ));
 
                mod->sml_op = LDAP_MOD_REPLACE;
+               mod->sml_flags = 0;
                mod->sml_next = NULL;
                mod->sml_desc = NULL;
                mod->sml_type = tmp.sml_type;
@@ -1191,7 +1193,7 @@ typedef struct dninfo {
        AttributeDescription **ads;
 } dninfo;
 
-int
+static int
 syncrepl_entry(
        syncinfo_t* si,
        Operation *op,
@@ -1463,12 +1465,13 @@ retry_add:;
 
                        op->o_tag = LDAP_REQ_MODIFY;
 
-                       assert( *modlist );
+                       assert( *modlist != NULL );
 
                        /* Delete all the old attrs */
                        for ( i = 0; i < dni.attrs; i++ ) {
                                mod = ch_malloc( sizeof( Modifications ) );
                                mod->sml_op = LDAP_MOD_DELETE;
+                               mod->sml_flags = 0;
                                mod->sml_desc = dni.ads[i];
                                mod->sml_type = mod->sml_desc->ad_cname;
                                mod->sml_values = NULL;
@@ -1495,6 +1498,7 @@ retry_add:;
 
                        mod = (Modifications *)ch_calloc(1, sizeof(Modifications));
                        mod->sml_op = LDAP_MOD_REPLACE;
+                       mod->sml_flags = 0;
                        mod->sml_desc = slap_schema.si_ad_entryUUID;
                        mod->sml_type = mod->sml_desc->ad_cname;
                        ber_dupbv( &uuid_bv, &syncUUID_strrep );
@@ -1675,6 +1679,7 @@ syncrepl_del_nonpresent(
                        if ( rs_delete.sr_err == LDAP_NOT_ALLOWED_ON_NONLEAF ) {
                                Modifications mod1, mod2;
                                mod1.sml_op = LDAP_MOD_REPLACE;
+                               mod1.sml_flags = 0;
                                mod1.sml_desc = slap_schema.si_ad_objectClass;
                                mod1.sml_type = mod1.sml_desc->ad_cname;
                                mod1.sml_values = &gcbva[0];
@@ -1682,6 +1687,7 @@ syncrepl_del_nonpresent(
                                mod1.sml_next = &mod2;
 
                                mod2.sml_op = LDAP_MOD_REPLACE;
+                               mod2.sml_flags = 0;
                                mod2.sml_desc = slap_schema.si_ad_structuralObjectClass;
                                mod2.sml_type = mod2.sml_desc->ad_cname;
                                mod2.sml_values = &gcbva[1];
@@ -1852,7 +1858,7 @@ syncrepl_add_glue(
        return;
 }
 
-void
+static void
 syncrepl_updateCookie(
        syncinfo_t *si,
        Operation *op,
@@ -2066,7 +2072,7 @@ null_callback(
        return LDAP_SUCCESS;
 }
 
-struct berval *
+static struct berval *
 slap_uuidstr_from_normalized(
        struct berval* uuidstr,
        struct berval* normalized,
@@ -2234,21 +2240,22 @@ syncinfo_free( syncinfo_t *sie )
 /* NOTE: used & documented in slapd.conf(5) */
 #define IDSTR                  "rid"
 #define PROVIDERSTR            "provider"
-#define TYPESTR                        "type"
-#define INTERVALSTR            "interval"
-#define SEARCHBASESTR          "searchbase"
+#define SCHEMASTR              "schemachecking"
 #define FILTERSTR              "filter"
+#define SEARCHBASESTR          "searchbase"
 #define SCOPESTR               "scope"
-#define ATTRSSTR               "attrs"
 #define ATTRSONLYSTR           "attrsonly"
+#define ATTRSSTR               "attrs"
+#define TYPESTR                        "type"
+#define INTERVALSTR            "interval"
+#define RETRYSTR               "retry"
 #define SLIMITSTR              "sizelimit"
 #define TLIMITSTR              "timelimit"
-#define SCHEMASTR              "schemachecking"
 
 /* FIXME: undocumented */
 #define OLDAUTHCSTR            "bindprincipal"
 #define EXATTRSSTR             "exattrs"
-#define RETRYSTR               "retry"
+#define MANAGEDSAITSTR         "manageDSAit"
 
 /* FIXME: unused */
 #define LASTMODSTR             "lastmod"
@@ -2257,7 +2264,6 @@ syncinfo_free( syncinfo_t *sie )
 #define LMREQSTR               "req"
 #define SRVTABSTR              "srvtab"
 #define SUFFIXSTR              "suffix"
-#define MANAGEDSAITSTR         "manageDSAit"
 
 /* mandatory */
 #define GOT_ID                 0x0001
@@ -2272,11 +2278,13 @@ static struct {
 } scopes[] = {
        { BER_BVC("base"), LDAP_SCOPE_BASE },
        { BER_BVC("one"), LDAP_SCOPE_ONELEVEL },
+       { BER_BVC("onelevel"), LDAP_SCOPE_ONELEVEL },   /* OpenLDAP extension */
 #ifdef LDAP_SCOPE_SUBORDINATE
        { BER_BVC("children"), LDAP_SCOPE_SUBORDINATE },
-       { BER_BVC("subordinate"), 0 },
+       { BER_BVC("subordinate"), LDAP_SCOPE_SUBORDINATE },
 #endif
        { BER_BVC("sub"), LDAP_SCOPE_SUBTREE },
+       { BER_BVC("subtree"), LDAP_SCOPE_SUBTREE },     /* OpenLDAP extension */
        { BER_BVNULL, 0 }
 };
 
@@ -2351,9 +2359,7 @@ parse_syncrepl_line(
                        int j;
                        val = cargv[ i ] + STRLENOF( SCOPESTR "=" );
                        for ( j=0; !BER_BVISNULL(&scopes[j].key); j++ ) {
-                               if (!strncasecmp( val, scopes[j].key.bv_val,
-                                       scopes[j].key.bv_len )) {
-                                       while (!scopes[j].val) j--;
+                               if (!strcasecmp( val, scopes[j].key.bv_val )) {
                                        si->si_scope = scopes[j].val;
                                        break;
                                }
@@ -2623,6 +2629,14 @@ add_syncrepl(
 
        rc = parse_syncrepl_line( cargv, cargc, si );
 
+       if ( rc == 0 ) {
+               si->si_be = be;
+               init_syncrepl( si );
+               si->si_re = ldap_pvt_runqueue_insert( &slapd_rq, si->si_interval,
+                       do_syncrepl, si, "do_syncrepl", be->be_suffix[0].bv_val );
+               if ( !si->si_re )
+                       rc = -1;
+       }
        if ( rc < 0 ) {
                Debug( LDAP_DEBUG_ANY, "failed to add syncinfo\n", 0, 0, 0 );
                syncinfo_free( si );    
@@ -2635,10 +2649,7 @@ add_syncrepl(
                if ( !si->si_schemachecking ) {
                        SLAP_DBFLAGS(be) |= SLAP_DBFLAG_NO_SCHEMA_CHECK;
                }
-               si->si_be = be;
                be->be_syncinfo = si;
-               init_syncrepl( si );
-               ldap_pvt_runqueue_insert( &slapd_rq,si->si_interval,do_syncrepl,si );
                return 0;
        }
 }
@@ -2648,11 +2659,11 @@ syncrepl_unparse( syncinfo_t *si, struct berval *bv )
 {
        struct berval bc;
        char buf[BUFSIZ*2], *ptr;
-       int i, len;
+       int i;
 
        bindconf_unparse( &si->si_bindconf, &bc );
        ptr = buf;
-       ptr += sprintf( ptr, IDSTR "=%03d " PROVIDERSTR "=%s",
+       ptr += sprintf( ptr, IDSTR "=%03ld " PROVIDERSTR "=%s",
                si->si_rid, si->si_provideruri.bv_val );
        if ( !BER_BVISNULL( &bc )) {
                ptr = lutil_strcopy( ptr, bc.bv_val );
@@ -2726,11 +2737,11 @@ syncrepl_unparse( syncinfo_t *si, struct berval *bv )
                for (i=0; si->si_retryinterval[i]; i++) {
                        if ( space ) *ptr++ = ' ';
                        space = 1;
-                       ptr += sprintf( ptr, "%d", si->si_retryinterval[i] );
+                       ptr += sprintf( ptr, "%ld ", (long) si->si_retryinterval[i] );
                        if ( si->si_retrynum_init[i] == -1 )
                                *ptr++ = '+';
                        else
-                               ptr += sprintf( ptr, "%d", si->si_retrynum_init );
+                               ptr += sprintf( ptr, "%d", si->si_retrynum_init[i] );
                }
                *ptr++ = '"';
        }
@@ -2763,7 +2774,7 @@ syncrepl_config(ConfigArgs *c) {
                struct re_s *re;
 
                if ( c->be->be_syncinfo ) {
-                       re = ldap_pvt_runqueue_find( &slapd_rq, do_syncrepl, c->be->be_syncinfo );
+                       re = c->be->be_syncinfo->si_re;
                        if ( re ) {
                                if ( ldap_pvt_runqueue_isrunning( &slapd_rq, re ))
                                        ldap_pvt_runqueue_stoptask( &slapd_rq, re );
@@ -2772,6 +2783,7 @@ syncrepl_config(ConfigArgs *c) {
                        syncinfo_free( c->be->be_syncinfo );
                        c->be->be_syncinfo = NULL;
                }
+               SLAP_DBFLAGS(c->be) &= ~(SLAP_DBFLAG_SHADOW|SLAP_DBFLAG_SYNC_SHADOW);
                return 0;
        }
        if(SLAP_SHADOW(c->be)) {