~ubuntu-branches/ubuntu/wily/389-ds-base/wily

« back to all changes in this revision

Viewing changes to ldap/servers/plugins/replication/repl5_replica_config.c

  • Committer: Package Import Robot
  • Author(s): Timo Aaltonen
  • Date: 2015-06-24 11:47:50 UTC
  • mfrom: (0.3.2)
  • Revision ID: package-import@ubuntu.com-20150624114750-sla8v3fuxgp9ah4t
Tags: 1.3.3.12-1
* New upstream release
  - fix CVE-2015-3230 (Closes: #789202)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1496
1496
    Slapi_Task *task = NULL;
1497
1497
    const Slapi_DN *task_dn;
1498
1498
    Slapi_DN *dn = NULL;
1499
 
    ReplicaId rid;
 
1499
    ReplicaId rid = -1;
1500
1500
    Object *r;
1501
1501
    const char *force_cleaning;
1502
1502
    const char *base_dn;
1518
1518
    /*
1519
1519
     *  Get our task settings
1520
1520
     */
 
1521
    if ((rid_str = fetch_attr(e, "replica-id", 0)) == NULL){
 
1522
        PR_snprintf(returntext, SLAPI_DSE_RETURNTEXT_SIZE, "Missing replica-id attribute");
 
1523
        cleanruv_log(task, -1, CLEANALLRUV_ID, "%s", returntext);
 
1524
        *returncode = LDAP_OBJECT_CLASS_VIOLATION;
 
1525
        rc = SLAPI_DSE_CALLBACK_ERROR;
 
1526
        goto out;
 
1527
    }
 
1528
    rid = atoi(rid_str);
1521
1529
    if ((base_dn = fetch_attr(e, "replica-base-dn", 0)) == NULL){
1522
1530
        PR_snprintf(returntext, SLAPI_DSE_RETURNTEXT_SIZE, "Missing replica-base-dn attribute");
1523
 
        cleanruv_log(task, CLEANALLRUV_ID, "%s", returntext);
1524
 
        *returncode = LDAP_OBJECT_CLASS_VIOLATION;
1525
 
        rc = SLAPI_DSE_CALLBACK_ERROR;
1526
 
        goto out;
1527
 
    }
1528
 
    if ((rid_str = fetch_attr(e, "replica-id", 0)) == NULL){
1529
 
        PR_snprintf(returntext, SLAPI_DSE_RETURNTEXT_SIZE, "Missing replica-id attribute");
1530
 
        cleanruv_log(task, CLEANALLRUV_ID, "%s", returntext);
1531
 
        *returncode = LDAP_OBJECT_CLASS_VIOLATION;
1532
 
        rc = SLAPI_DSE_CALLBACK_ERROR;
1533
 
        goto out;
1534
 
    }
1535
 
 
 
1531
        cleanruv_log(task, (int)rid, CLEANALLRUV_ID, "%s", returntext);
 
1532
        *returncode = LDAP_OBJECT_CLASS_VIOLATION;
 
1533
        rc = SLAPI_DSE_CALLBACK_ERROR;
 
1534
        goto out;
 
1535
    }
1536
1536
    if ((force_cleaning = fetch_attr(e, "replica-force-cleaning", 0)) != NULL){
1537
1537
        if(strcasecmp(force_cleaning,"yes") != 0 && strcasecmp(force_cleaning,"no") != 0){
1538
1538
            PR_snprintf(returntext, SLAPI_DSE_RETURNTEXT_SIZE, "Invalid value for replica-force-cleaning "
1539
1539
                "(%s).  Value must be \"yes\" or \"no\" for task - (%s)",
1540
1540
                force_cleaning, slapi_sdn_get_dn(task_dn));
1541
 
            cleanruv_log(task, CLEANALLRUV_ID, "%s", returntext);
 
1541
            cleanruv_log(task, (int)rid, CLEANALLRUV_ID, "%s", returntext);
1542
1542
            *returncode = LDAP_OPERATIONS_ERROR;
1543
1543
            rc = SLAPI_DSE_CALLBACK_ERROR;
1544
1544
            goto out;
1549
1549
    /*
1550
1550
     *  Check the rid
1551
1551
     */
1552
 
    rid = atoi(rid_str);
1553
1552
    if (rid <= 0 || rid >= READ_ONLY_REPLICA_ID){
1554
1553
        PR_snprintf(returntext, SLAPI_DSE_RETURNTEXT_SIZE, "Invalid replica id (%d) for task - (%s)",
1555
1554
            rid, slapi_sdn_get_dn(task_dn));
1556
 
        cleanruv_log(task, CLEANALLRUV_ID, "%s", returntext);
 
1555
        cleanruv_log(task, rid, CLEANALLRUV_ID, "%s", returntext);
1557
1556
        *returncode = LDAP_OPERATIONS_ERROR;
1558
1557
        rc = SLAPI_DSE_CALLBACK_ERROR;
1559
1558
        goto out;
1561
1560
    if(is_cleaned_rid(rid)){
1562
1561
         /* we are already cleaning this rid */
1563
1562
         PR_snprintf(returntext, SLAPI_DSE_RETURNTEXT_SIZE, "Replica id (%d) is already being cleaned", rid);
1564
 
         cleanruv_log(task, CLEANALLRUV_ID, "%s", returntext);
 
1563
         cleanruv_log(task, rid, CLEANALLRUV_ID, "%s", returntext);
1565
1564
         *returncode = LDAP_UNWILLING_TO_PERFORM;
1566
1565
         rc = SLAPI_DSE_CALLBACK_ERROR;
1567
1566
         goto out;
1572
1571
    dn = slapi_sdn_new_dn_byval(base_dn);
1573
1572
    if((r = replica_get_replica_from_dn(dn)) == NULL){
1574
1573
        PR_snprintf(returntext, SLAPI_DSE_RETURNTEXT_SIZE, "Could not find replica from dn(%s)",slapi_sdn_get_dn(dn));
1575
 
        cleanruv_log(task, CLEANALLRUV_ID, "%s", returntext);
 
1574
        cleanruv_log(task, rid, CLEANALLRUV_ID, "%s", returntext);
1576
1575
        *returncode = LDAP_OPERATIONS_ERROR;
1577
1576
        rc = SLAPI_DSE_CALLBACK_ERROR;
1578
1577
        goto out;
1583
1582
 
1584
1583
out:
1585
1584
    if(rc){
1586
 
        cleanruv_log(task, CLEANALLRUV_ID, "Task failed...(%d)", rc);
 
1585
        cleanruv_log(task, rid, CLEANALLRUV_ID, "Task failed...(%d)", rc);
1587
1586
        slapi_task_finish(task, *returncode);
1588
1587
    } else {
1589
1588
        rc = SLAPI_DSE_CALLBACK_OK;
1615
1614
    char *basedn = NULL;
1616
1615
    int rc = 0;
1617
1616
 
1618
 
    cleanruv_log(pre_task, CLEANALLRUV_ID,"Initiating CleanAllRUV Task...");
 
1617
    cleanruv_log(pre_task, rid, CLEANALLRUV_ID,"Initiating CleanAllRUV Task...");
1619
1618
 
1620
1619
    if(get_cleanruv_task_count() >= CLEANRIDSIZ){
1621
1620
        /* we are already running the maximum number of tasks */
1622
 
        cleanruv_log(pre_task, CLEANALLRUV_ID,
 
1621
        cleanruv_log(pre_task, rid, CLEANALLRUV_ID,
1623
1622
            "Exceeded maximum number of active CLEANALLRUV tasks(%d)",CLEANRIDSIZ);
1624
1623
        return LDAP_UNWILLING_TO_PERFORM;
1625
1624
    }
1629
1628
    if(r){
1630
1629
        replica = (Replica*)object_get_data (r);
1631
1630
    } else {
1632
 
        cleanruv_log(pre_task, CLEANALLRUV_ID, "Replica object is NULL, aborting task");
 
1631
        cleanruv_log(pre_task, rid, CLEANALLRUV_ID, "Replica object is NULL, aborting task");
1633
1632
        return -1;
1634
1633
    }
1635
1634
    /*
1637
1636
     */
1638
1637
    if(replica_get_type(replica) == REPLICA_TYPE_READONLY){
1639
1638
        /* this is a consumer, send error */
1640
 
        cleanruv_log(pre_task, CLEANALLRUV_ID, "Failed to clean rid (%d), task can not be run on a consumer",rid);
 
1639
        cleanruv_log(pre_task, rid, CLEANALLRUV_ID, "Failed to clean rid (%d), task can not be run on a consumer",rid);
1641
1640
        if(task){
1642
1641
            rc = -1;
1643
1642
            slapi_task_finish(task, rc);
1647
1646
    /*
1648
1647
     *  Grab the max csn of the deleted replica
1649
1648
     */
1650
 
    cleanruv_log(pre_task, CLEANALLRUV_ID, "Retrieving maxcsn...");
 
1649
    cleanruv_log(pre_task, rid, CLEANALLRUV_ID, "Retrieving maxcsn...");
1651
1650
    basedn = (char *)slapi_sdn_get_dn(replica_get_root(replica));
1652
1651
    maxcsn = replica_cleanallruv_find_maxcsn(replica, rid, basedn);
1653
1652
    if(maxcsn == NULL || csn_get_replicaid(maxcsn) == 0){
1660
1659
        csn_init_by_string(maxcsn, "");
1661
1660
    }
1662
1661
    csn_as_string(maxcsn, PR_FALSE, csnstr);
1663
 
    cleanruv_log(pre_task, CLEANALLRUV_ID, "Found maxcsn (%s)",csnstr);
 
1662
    cleanruv_log(pre_task, rid, CLEANALLRUV_ID, "Found maxcsn (%s)",csnstr);
1664
1663
    /*
1665
1664
     *  Create payload
1666
1665
     */
1669
1668
    slapi_ch_free_string(&ridstr);
1670
1669
 
1671
1670
    if(payload == NULL){
1672
 
        cleanruv_log(pre_task, CLEANALLRUV_ID, "Failed to create extended op payload, aborting task");
 
1671
        cleanruv_log(pre_task, rid, CLEANALLRUV_ID, "Failed to create extended op payload, aborting task");
1673
1672
        rc = -1;
1674
1673
        goto fail;
1675
1674
    }
1679
1678
     */
1680
1679
    data = (cleanruv_data*)slapi_ch_calloc(1, sizeof(cleanruv_data));
1681
1680
    if (data == NULL) {
1682
 
        cleanruv_log(pre_task, CLEANALLRUV_ID, "Failed to allocate cleanruv_data.  Aborting task.");
 
1681
        cleanruv_log(pre_task, rid, CLEANALLRUV_ID, "Failed to allocate cleanruv_data.  Aborting task.");
1683
1682
        rc = -1;
1684
1683
        goto fail;
1685
1684
    }
1706
1705
    }
1707
1706
 
1708
1707
fail:
1709
 
    cleanruv_log(pre_task, CLEANALLRUV_ID, "Failed to clean rid (%d)",rid);
 
1708
    cleanruv_log(pre_task, rid, CLEANALLRUV_ID, "Failed to clean rid (%d)", rid);
1710
1709
    if(task){
1711
1710
        slapi_task_finish(task, rc);
1712
1711
    }
1779
1778
        PR_Unlock( notify_lock );
1780
1779
        data->repl_obj = replica_get_replica_from_dn(data->sdn);
1781
1780
        if(data->repl_obj == NULL){
1782
 
                cleanruv_log(data->task, CLEANALLRUV_ID, "Unable to retrieve repl object from dn(%s).", data->sdn);
1783
 
                aborted = 1;
1784
 
                goto done;
 
1781
            cleanruv_log(data->task, data->rid, CLEANALLRUV_ID, "Unable to retrieve repl object from dn(%s).", data->sdn);
 
1782
            aborted = 1;
 
1783
            goto done;
1785
1784
        }
1786
1785
        data->replica = (Replica*)object_get_data(data->repl_obj);
1787
1786
        free_obj = 1;
1793
1792
    }
1794
1793
    /* verify we have set our repl objects */
1795
1794
    if(data->repl_obj == NULL || data->replica == NULL){
1796
 
        cleanruv_log(data->task, CLEANALLRUV_ID, "Unable to set the replica objects.");
1797
 
        aborted = 1;
1798
 
        goto done;
 
1795
        cleanruv_log(data->task, data->rid, CLEANALLRUV_ID, "Unable to set the replica objects.");
 
1796
        aborted = 1;
 
1797
        goto done;
1799
1798
    }
1800
1799
    if(data->repl_root == NULL){
1801
1800
        /* we must have resumed from start up, fill in the repl root */
1815
1814
     *  Add the cleanallruv task to the repl config - so we can handle restarts
1816
1815
     */
1817
1816
    add_cleaned_rid(data->rid, data->replica, csnstr, data->force); /* marks config that we started cleaning a rid */
1818
 
    cleanruv_log(data->task, CLEANALLRUV_ID, "Cleaning rid (%d)...", data->rid);
 
1817
    cleanruv_log(data->task, data->rid, CLEANALLRUV_ID, "Cleaning rid (%d)...", data->rid);
1819
1818
    /*
1820
1819
     *  First, wait for the maxcsn to be covered
1821
1820
     */
1822
 
    cleanruv_log(data->task, CLEANALLRUV_ID, "Waiting to process all the updates from the deleted replica...");
 
1821
    cleanruv_log(data->task, data->rid, CLEANALLRUV_ID, "Waiting to process all the updates from the deleted replica...");
1823
1822
    ruv_obj = replica_get_ruv(data->replica);
1824
1823
    ruv = object_get_data (ruv_obj);
1825
1824
    while(data->maxcsn && !is_task_aborted(data->rid) && !is_cleaned_rid(data->rid) && !slapi_is_shutting_down()){
1837
1836
     *
1838
1837
     *  Even if we are forcing the cleaning, the replicas still need to be up
1839
1838
     */
1840
 
    cleanruv_log(data->task, CLEANALLRUV_ID,"Waiting for all the replicas to be online...");
 
1839
    cleanruv_log(data->task, data->rid, CLEANALLRUV_ID,"Waiting for all the replicas to be online...");
1841
1840
    if(check_agmts_are_alive(data->replica, data->rid, data->task)){
1842
1841
        /* error, aborted or shutdown */
1843
1842
        aborted = 1;
1846
1845
    /*
1847
1846
     *  Make sure all the replicas have seen the max csn
1848
1847
     */
1849
 
    cleanruv_log(data->task, CLEANALLRUV_ID,"Waiting for all the replicas to receive all the deleted replica updates...");
 
1848
    cleanruv_log(data->task, data->rid, CLEANALLRUV_ID,"Waiting for all the replicas to receive all the deleted replica updates...");
1850
1849
    if(strcasecmp(data->force,"no") == 0 && check_agmts_are_caught_up(data, csnstr)){
1851
1850
        /* error, aborted or shutdown */
1852
1851
        aborted = 1;
1860
1859
    /*
1861
1860
     *  Now send the cleanruv extended op to all the agreements
1862
1861
     */
1863
 
    cleanruv_log(data->task, CLEANALLRUV_ID, "Sending cleanAllRUV task to all the replicas...");
 
1862
    cleanruv_log(data->task, data->rid, CLEANALLRUV_ID, "Sending cleanAllRUV task to all the replicas...");
1864
1863
    while(agmt_not_notified && !is_task_aborted(data->rid) && !slapi_is_shutting_down()){
1865
1864
        agmt_obj = agmtlist_get_first_agreement_for_replica (data->replica);
1866
1865
        if(agmt_obj == NULL){
1878
1877
                agmt_not_notified = 0;
1879
1878
            } else {
1880
1879
                agmt_not_notified = 1;
1881
 
                cleanruv_log(data->task, CLEANALLRUV_ID, "Failed to send task to replica (%s)",agmt_get_long_name(agmt));
 
1880
                cleanruv_log(data->task, data->rid, CLEANALLRUV_ID, "Failed to send task to replica (%s)",agmt_get_long_name(agmt));
1882
1881
                break;
1883
1882
            }
1884
1883
            agmt_obj = agmtlist_get_next_agreement_for_replica (data->replica, agmt_obj);
1894
1893
        /*
1895
1894
         *  need to sleep between passes
1896
1895
         */
1897
 
        cleanruv_log(data->task, CLEANALLRUV_ID, "Not all replicas have received the "
 
1896
        cleanruv_log(data->task, data->rid, CLEANALLRUV_ID, "Not all replicas have received the "
1898
1897
            "cleanallruv extended op, retrying in %d seconds",interval);
1899
1898
        PR_Lock( notify_lock );
1900
1899
        PR_WaitCondVar( notify_cvar, PR_SecondsToInterval(interval) );
1909
1908
    /*
1910
1909
     *  Run the CLEANRUV task
1911
1910
     */
1912
 
    cleanruv_log(data->task, CLEANALLRUV_ID,"Cleaning local ruv's...");
 
1911
    cleanruv_log(data->task, data->rid, CLEANALLRUV_ID,"Cleaning local ruv's...");
1913
1912
    replica_execute_cleanruv_task (data->repl_obj, data->rid, returntext);
1914
1913
    /*
1915
1914
     *  Wait for all the replicas to be cleaned
1916
1915
     */
1917
 
    cleanruv_log(data->task, CLEANALLRUV_ID,"Waiting for all the replicas to be cleaned...");
 
1916
    cleanruv_log(data->task, data->rid, CLEANALLRUV_ID,
 
1917
            "Waiting for all the replicas to be cleaned...");
1918
1918
 
1919
1919
    interval = 10;
1920
1920
    while(found_dirty_rid && !is_task_aborted(data->rid) && !slapi_is_shutting_down()){
1933
1933
                found_dirty_rid = 0;
1934
1934
            } else {
1935
1935
                found_dirty_rid = 1;
1936
 
                cleanruv_log(data->task, CLEANALLRUV_ID,"Replica is not cleaned yet (%s)",agmt_get_long_name(agmt));
 
1936
                cleanruv_log(data->task, data->rid, CLEANALLRUV_ID,"Replica is not cleaned yet (%s)",
 
1937
                        agmt_get_long_name(agmt));
1937
1938
                break;
1938
1939
            }
1939
1940
            agmt_obj = agmtlist_get_next_agreement_for_replica (data->replica, agmt_obj);
1949
1950
        /*
1950
1951
         *  need to sleep between passes
1951
1952
         */
1952
 
        cleanruv_log(data->task, CLEANALLRUV_ID, "Replicas have not been cleaned yet, "
 
1953
        cleanruv_log(data->task, data->rid, CLEANALLRUV_ID, "Replicas have not been cleaned yet, "
1953
1954
            "retrying in %d seconds", interval);
1954
1955
        PR_Lock( notify_lock );
1955
1956
        PR_WaitCondVar( notify_cvar, PR_SecondsToInterval(interval) );
1971
1972
        delete_cleaned_rid_config(data);
1972
1973
        /* make sure all the replicas have been "pre_cleaned" before finishing */
1973
1974
        check_replicas_are_done_cleaning(data);
1974
 
        cleanruv_log(data->task, CLEANALLRUV_ID, "Successfully cleaned rid(%d).", data->rid);
 
1975
        cleanruv_log(data->task, data->rid, CLEANALLRUV_ID, "Successfully cleaned rid(%d).", data->rid);
1975
1976
        remove_cleaned_rid(data->rid);
1976
1977
    } else {
1977
1978
        /*
1978
1979
         *  Shutdown or abort
1979
1980
         */
1980
1981
        if(!is_task_aborted(data->rid)){
1981
 
            cleanruv_log(data->task, CLEANALLRUV_ID,"Server shutting down.  Process will resume at server startup");
 
1982
            cleanruv_log(data->task, data->rid, CLEANALLRUV_ID,"Server shutting down.  Process will resume at server startup");
1982
1983
        } else {
1983
 
            cleanruv_log(data->task, CLEANALLRUV_ID,"Task aborted for rid(%d).",data->rid);
 
1984
            cleanruv_log(data->task, data->rid, CLEANALLRUV_ID,"Task aborted for rid(%d).",data->rid);
1984
1985
            delete_cleaned_rid_config(data);
1985
1986
            remove_cleaned_rid(data->rid);
1986
1987
        }
2048
2049
    int not_all_cleaned = 1;
2049
2050
    int interval = 10;
2050
2051
 
2051
 
    cleanruv_log(data->task, CLEANALLRUV_ID, "Waiting for all the replicas to finish cleaning...");
 
2052
    cleanruv_log(data->task, data->rid, CLEANALLRUV_ID, "Waiting for all the replicas to finish cleaning...");
2052
2053
 
2053
2054
    csn_as_string(data->maxcsn, PR_FALSE, csnstr);
2054
2055
    filter = PR_smprintf("(%s=%d:%s:%s)", type_replicaCleanRUV,(int)data->rid, csnstr, data->force);
2076
2077
        if(not_all_cleaned == 0 || is_task_aborted(data->rid) ){
2077
2078
            break;
2078
2079
        }
2079
 
        cleanruv_log(data->task, CLEANALLRUV_ID, "Not all replicas finished cleaning, retrying in %d seconds",interval);
 
2080
        cleanruv_log(data->task, data->rid, CLEANALLRUV_ID, "Not all replicas finished cleaning, retrying in %d seconds",interval);
2080
2081
        PR_Lock( notify_lock );
2081
2082
        PR_WaitCondVar( notify_cvar, PR_SecondsToInterval(interval) );
2082
2083
        PR_Unlock( notify_lock );
2151
2152
    int not_all_aborted = 1;
2152
2153
    int interval = 10;
2153
2154
 
2154
 
    cleanruv_log(data->task, ABORT_CLEANALLRUV_ID,"Waiting for all the replicas to finish aborting...");
 
2155
    cleanruv_log(data->task, data->rid, ABORT_CLEANALLRUV_ID,"Waiting for all the replicas to finish aborting...");
2155
2156
 
2156
2157
    filter = PR_smprintf("(%s=%d:%s)", type_replicaAbortCleanRUV, data->rid, data->repl_root);
2157
2158
 
2179
2180
        if(not_all_aborted == 0){
2180
2181
            break;
2181
2182
        }
2182
 
        cleanruv_log(data->task, ABORT_CLEANALLRUV_ID, "Not all replicas finished aborting, retrying in %d seconds",interval);
 
2183
        cleanruv_log(data->task, data->rid, ABORT_CLEANALLRUV_ID, "Not all replicas finished aborting, retrying in %d seconds",interval);
2183
2184
        PR_Lock( notify_lock );
2184
2185
        PR_WaitCondVar( notify_cvar, PR_SecondsToInterval(interval) );
2185
2186
        PR_Unlock( notify_lock );
2223
2224
                not_all_caughtup = 0;
2224
2225
            } else {
2225
2226
                not_all_caughtup = 1;
2226
 
                cleanruv_log(data->task, CLEANALLRUV_ID, "Replica not caught up (%s)",agmt_get_long_name(agmt));
 
2227
                cleanruv_log(data->task, data->rid, CLEANALLRUV_ID, "Replica not caught up (%s)",agmt_get_long_name(agmt));
2227
2228
                break;
2228
2229
            }
2229
2230
            agmt_obj = agmtlist_get_next_agreement_for_replica (data->replica, agmt_obj);
2232
2233
        if(not_all_caughtup == 0 || is_task_aborted(data->rid) ){
2233
2234
            break;
2234
2235
        }
2235
 
        cleanruv_log(data->task, CLEANALLRUV_ID, "Not all replicas caught up, retrying in %d seconds",interval);
 
2236
        cleanruv_log(data->task, data->rid, CLEANALLRUV_ID,
 
2237
                "Not all replicas caught up, retrying in %d seconds",interval);
2236
2238
        PR_Lock( notify_lock );
2237
2239
        PR_WaitCondVar( notify_cvar, PR_SecondsToInterval(interval) );
2238
2240
        PR_Unlock( notify_lock );
2280
2282
                not_all_alive = 0;
2281
2283
            } else {
2282
2284
                not_all_alive = 1;
2283
 
                cleanruv_log(task, CLEANALLRUV_ID, "Replica not online (%s)",agmt_get_long_name(agmt));
 
2285
                cleanruv_log(task, rid, CLEANALLRUV_ID, "Replica not online (%s)",
 
2286
                        agmt_get_long_name(agmt));
2284
2287
                break;
2285
2288
            }
2286
2289
            agmt_obj = agmtlist_get_next_agreement_for_replica (replica, agmt_obj);
2289
2292
        if(not_all_alive == 0 || is_task_aborted(rid)){
2290
2293
            break;
2291
2294
        }
2292
 
        cleanruv_log(task, CLEANALLRUV_ID, "Not all replicas online, retrying in %d seconds...",interval);
 
2295
        cleanruv_log(task, rid, CLEANALLRUV_ID, "Not all replicas online, retrying in %d seconds...",
 
2296
                interval);
2293
2297
        PR_Lock( notify_lock );
2294
2298
        PR_WaitCondVar( notify_cvar, PR_SecondsToInterval(interval) );
2295
2299
        PR_Unlock( notify_lock );
2393
2397
    if(rc != LDAP_SUCCESS){
2394
2398
        char *hostname = agmt_get_hostname(agmt);
2395
2399
 
2396
 
        cleanruv_log(clean_data->task, CLEANALLRUV_ID, "Failed to add CLEANRUV task (%s) to replica "
2397
 
            "(%s).  You will need to manually run the CLEANRUV task on this replica (%s) error (%d)",
 
2400
        cleanruv_log(clean_data->task, clean_data->rid, CLEANALLRUV_ID,
 
2401
            "Failed to add CLEANRUV task (%s) to replica (%s).  You will need "
 
2402
            "to manually run the CLEANRUV task on this replica (%s) error (%d)",
2398
2403
            repl_dn, agmt_get_long_name(agmt), hostname, rc);
2399
2404
        slapi_ch_free_string(&hostname);
2400
2405
    }
2666
2671
    int rc = -1, ret, rid;
2667
2672
 
2668
2673
    if(clean_data == NULL){
2669
 
        cleanruv_log(NULL, CLEANALLRUV_ID, "delete_cleaned_rid_config: cleanruv data is NULL, "
 
2674
        cleanruv_log(NULL, -1, CLEANALLRUV_ID, "delete_cleaned_rid_config: cleanruv data is NULL, "
2670
2675
                "failed to clean the config.");
2671
2676
        return;
2672
2677
    }
2685
2690
    slapi_search_internal_pb(pb);
2686
2691
    slapi_pblock_get(pb, SLAPI_PLUGIN_INTOP_RESULT, &ret);
2687
2692
    if (ret != LDAP_SUCCESS){
2688
 
        cleanruv_log(clean_data->task, CLEANALLRUV_ID,"delete_cleaned_rid_config: internal search failed(%d).",ret);
 
2693
        cleanruv_log(clean_data->task, clean_data->rid, CLEANALLRUV_ID,
 
2694
                "delete_cleaned_rid_config: internal search failed(%d).",ret);
2689
2695
        goto bail;
2690
2696
    } else {
2691
2697
        slapi_pblock_get(pb, SLAPI_PLUGIN_INTOP_SEARCH_ENTRIES, &entries);
2693
2699
            /*
2694
2700
             *  No matching entries!
2695
2701
             */
2696
 
            cleanruv_log(clean_data->task, CLEANALLRUV_ID,"delete_cleaned_rid_config: failed to find any "
 
2702
            cleanruv_log(clean_data->task, clean_data->rid, CLEANALLRUV_ID,
 
2703
                    "delete_cleaned_rid_config: failed to find any "
2697
2704
                    "entries with nsds5ReplicaCleanRUV under (%s)", dn);
2698
2705
            goto bail;
2699
2706
        } else {
2744
2751
                }
2745
2752
 
2746
2753
                if (rc != LDAP_SUCCESS && rc != LDAP_NO_SUCH_OBJECT){
2747
 
                    cleanruv_log(clean_data->task, CLEANALLRUV_ID, "delete_cleaned_rid_config: failed to remove task data "
 
2754
                    cleanruv_log(clean_data->task, clean_data->rid, CLEANALLRUV_ID,
 
2755
                            "delete_cleaned_rid_config: failed to remove task data "
2748
2756
                            "from (%s) error (%d), rid (%d)", edn, rc, clean_data->rid);
2749
2757
                    goto bail;
2750
2758
                }
2754
2762
 
2755
2763
bail:
2756
2764
    if (rc != LDAP_SUCCESS && rc != LDAP_NO_SUCH_OBJECT){
2757
 
        cleanruv_log(clean_data->task, CLEANALLRUV_ID, "delete_cleaned_rid_config: failed to remove replica config "
 
2765
        cleanruv_log(clean_data->task, clean_data->rid, CLEANALLRUV_ID,
 
2766
            "delete_cleaned_rid_config: failed to remove replica config "
2758
2767
            "(%d), rid (%d)", rc, clean_data->rid);
2759
2768
    }
2760
2769
    slapi_free_search_results_internal(pb);
2802
2811
    Slapi_Task *task = NULL;
2803
2812
    Slapi_DN *sdn = NULL;
2804
2813
    Replica *replica;
2805
 
    ReplicaId rid;;
 
2814
    ReplicaId rid = -1;
2806
2815
    Object *r;
2807
2816
    const char *certify_all;
2808
2817
    const char *base_dn;
2812
2821
 
2813
2822
    if(get_abort_cleanruv_task_count() >= CLEANRIDSIZ){
2814
2823
        /* we are already running the maximum number of tasks */
2815
 
        PR_snprintf(returntext, SLAPI_DSE_RETURNTEXT_SIZE, "Exceeded maximum number of active ABORT CLEANALLRUV tasks(%d)",CLEANRIDSIZ);
2816
 
        cleanruv_log(task, ABORT_CLEANALLRUV_ID, "%s", returntext);
 
2824
        PR_snprintf(returntext, SLAPI_DSE_RETURNTEXT_SIZE,
 
2825
                "Exceeded maximum number of active ABORT CLEANALLRUV tasks(%d)",
 
2826
                CLEANRIDSIZ);
 
2827
        cleanruv_log(task, -1, ABORT_CLEANALLRUV_ID, "%s", returntext);
2817
2828
        *returncode = LDAP_OPERATIONS_ERROR;
2818
2829
        return SLAPI_DSE_CALLBACK_ERROR;
2819
2830
    }
2829
2840
     */
2830
2841
    if ((rid_str = fetch_attr(e, "replica-id", 0)) == NULL){
2831
2842
        PR_snprintf(returntext, SLAPI_DSE_RETURNTEXT_SIZE, "Missing required attr \"replica-id\"");
2832
 
        cleanruv_log(task, ABORT_CLEANALLRUV_ID, "%s", returntext);
 
2843
        cleanruv_log(task, -1, ABORT_CLEANALLRUV_ID, "%s", returntext);
2833
2844
        *returncode = LDAP_OBJECT_CLASS_VIOLATION;
2834
2845
        rc = SLAPI_DSE_CALLBACK_ERROR;
2835
2846
        goto out;
2842
2853
    if (rid <= 0 || rid >= READ_ONLY_REPLICA_ID){
2843
2854
        PR_snprintf(returntext, SLAPI_DSE_RETURNTEXT_SIZE, "Invalid replica id (%d) for task - (%s)",
2844
2855
            rid, slapi_sdn_get_dn(slapi_entry_get_sdn(e)));
2845
 
        cleanruv_log(task, ABORT_CLEANALLRUV_ID,"%s", returntext);
 
2856
        cleanruv_log(task, rid, ABORT_CLEANALLRUV_ID,"%s", returntext);
2846
2857
        *returncode = LDAP_OPERATIONS_ERROR;
2847
2858
        rc = SLAPI_DSE_CALLBACK_ERROR;
2848
2859
        goto out;
2849
2860
    }
2850
2861
    if ((base_dn = fetch_attr(e, "replica-base-dn", 0)) == NULL){
2851
2862
        PR_snprintf(returntext, SLAPI_DSE_RETURNTEXT_SIZE, "Missing required attr \"replica-base-dn\"");
2852
 
        cleanruv_log(task, ABORT_CLEANALLRUV_ID, "%s", returntext);
 
2863
        cleanruv_log(task, rid, ABORT_CLEANALLRUV_ID, "%s", returntext);
2853
2864
        *returncode = LDAP_OBJECT_CLASS_VIOLATION;
2854
2865
        rc = SLAPI_DSE_CALLBACK_ERROR;
2855
2866
        goto out;
2857
2868
    if(!is_cleaned_rid(rid) && !is_pre_cleaned_rid(rid)){
2858
2869
        /* we are not cleaning this rid */
2859
2870
        PR_snprintf(returntext, SLAPI_DSE_RETURNTEXT_SIZE, "Replica id (%d) is not being cleaned, nothing to abort.", rid);
2860
 
        cleanruv_log(task, ABORT_CLEANALLRUV_ID, "%s", returntext);
 
2871
        cleanruv_log(task, rid, ABORT_CLEANALLRUV_ID, "%s", returntext);
2861
2872
        *returncode = LDAP_UNWILLING_TO_PERFORM;
2862
2873
        rc = SLAPI_DSE_CALLBACK_ERROR;
2863
2874
        goto out;
2865
2876
    if(is_task_aborted(rid)){
2866
2877
        /* we are already aborting this rid */
2867
2878
        PR_snprintf(returntext, SLAPI_DSE_RETURNTEXT_SIZE, "Replica id (%d) is already being aborted", rid);
2868
 
        cleanruv_log(task, ABORT_CLEANALLRUV_ID, "%s", returntext);
 
2879
        cleanruv_log(task, rid, ABORT_CLEANALLRUV_ID, "%s", returntext);
2869
2880
        *returncode = LDAP_UNWILLING_TO_PERFORM;
2870
2881
        rc = SLAPI_DSE_CALLBACK_ERROR;
2871
2882
        goto out;
2876
2887
    sdn = slapi_sdn_new_dn_byval(base_dn);
2877
2888
    if((r = replica_get_replica_from_dn(sdn)) == NULL){
2878
2889
        PR_snprintf(returntext, SLAPI_DSE_RETURNTEXT_SIZE, "Failed to find replica from dn(%s)", base_dn);
2879
 
        cleanruv_log(task, ABORT_CLEANALLRUV_ID, "%s", returntext);
 
2890
        cleanruv_log(task, rid, ABORT_CLEANALLRUV_ID, "%s", returntext);
2880
2891
        *returncode = LDAP_OPERATIONS_ERROR;
2881
2892
        rc = SLAPI_DSE_CALLBACK_ERROR;
2882
2893
        goto out;
2888
2899
        if(strcasecmp(certify_all,"yes") && strcasecmp(certify_all,"no")){
2889
2900
            PR_snprintf(returntext, SLAPI_DSE_RETURNTEXT_SIZE, "Invalid value for \"replica-certify-all\", the value "
2890
2901
                "must be \"yes\" or \"no\".");
2891
 
            cleanruv_log(task, ABORT_CLEANALLRUV_ID, "%s", returntext);
 
2902
            cleanruv_log(task, rid, ABORT_CLEANALLRUV_ID, "%s", returntext);
2892
2903
            *returncode = LDAP_OPERATIONS_ERROR;
2893
2904
            rc = SLAPI_DSE_CALLBACK_ERROR;
2894
2905
            goto out;
2903
2914
    payload = create_cleanruv_payload(ridstr);
2904
2915
 
2905
2916
    if(payload == NULL){
2906
 
        cleanruv_log(task, ABORT_CLEANALLRUV_ID, "Failed to create extended op payload, aborting task");
 
2917
        cleanruv_log(task, rid, ABORT_CLEANALLRUV_ID, "Failed to create extended op payload, aborting task");
2907
2918
        *returncode = LDAP_OPERATIONS_ERROR;
2908
2919
        rc = SLAPI_DSE_CALLBACK_ERROR;
2909
2920
        goto out;
2919
2930
     */
2920
2931
    data = (cleanruv_data*)slapi_ch_calloc(1, sizeof(cleanruv_data));
2921
2932
    if (data == NULL) {
2922
 
        cleanruv_log(task, ABORT_CLEANALLRUV_ID,"Failed to allocate abort_cleanruv_data.  Aborting task.");
 
2933
        cleanruv_log(task, rid, ABORT_CLEANALLRUV_ID,"Failed to allocate abort_cleanruv_data.  Aborting task.");
2923
2934
        *returncode = LDAP_OPERATIONS_ERROR;
2924
2935
        rc = SLAPI_DSE_CALLBACK_ERROR;
2925
2936
        goto out;
2938
2949
                PR_UNJOINABLE_THREAD, SLAPD_DEFAULT_THREAD_STACKSIZE);
2939
2950
    if (thread == NULL) {
2940
2951
        object_release(r);
2941
 
        cleanruv_log(task, ABORT_CLEANALLRUV_ID,"Unable to create abort thread.  Aborting task.");
 
2952
        cleanruv_log(task, rid, ABORT_CLEANALLRUV_ID,"Unable to create abort thread.  Aborting task.");
2942
2953
        *returncode = LDAP_OPERATIONS_ERROR;
2943
2954
        slapi_ch_free_string(&data->certify);
2944
2955
        rc = SLAPI_DSE_CALLBACK_ERROR;
2949
2960
    slapi_sdn_free(&sdn);
2950
2961
 
2951
2962
    if(rc != SLAPI_DSE_CALLBACK_OK){
2952
 
        cleanruv_log(task, ABORT_CLEANALLRUV_ID, "Abort Task failed (%d)", rc);
 
2963
        cleanruv_log(task, rid, ABORT_CLEANALLRUV_ID, "Abort Task failed (%d)", rc);
2953
2964
        slapi_task_finish(task, rc);
2954
2965
    }
2955
2966
 
2977
2988
        slapi_task_inc_refcount(data->task);
2978
2989
        slapi_log_error(SLAPI_LOG_PLUGIN, repl_plugin_name, "replica_abort_task_thread --> refcount incremented.\n");
2979
2990
    }
2980
 
    cleanruv_log(data->task, ABORT_CLEANALLRUV_ID, "Aborting task for rid(%d)...",data->rid);
 
2991
    cleanruv_log(data->task, data->rid, ABORT_CLEANALLRUV_ID, "Aborting task for rid(%d)...",data->rid);
2981
2992
 
2982
2993
    /*
2983
2994
     *   Need to build the replica from the dn
2988
2999
         * to timing issues, we need to wait to grab the replica obj until we get here.
2989
3000
         */
2990
3001
        if((data->repl_obj = replica_get_replica_from_dn(data->sdn)) == NULL){
2991
 
            cleanruv_log(data->task, ABORT_CLEANALLRUV_ID, "Failed to get replica object from dn (%s).", slapi_sdn_get_dn(data->sdn));
 
3002
            cleanruv_log(data->task, data->rid, ABORT_CLEANALLRUV_ID, "Failed to get replica object from dn (%s).", slapi_sdn_get_dn(data->sdn));
2992
3003
            goto done;
2993
3004
        }
2994
3005
        if(data->replica == NULL && data->repl_obj){
3036
3047
        /*
3037
3048
         *  need to sleep between passes
3038
3049
         */
3039
 
        cleanruv_log(data->task, ABORT_CLEANALLRUV_ID,"Retrying in %d seconds",interval);
 
3050
        cleanruv_log(data->task, data->rid, ABORT_CLEANALLRUV_ID,"Retrying in %d seconds",interval);
3040
3051
        PR_Lock( notify_lock );
3041
3052
        PR_WaitCondVar( notify_cvar, PR_SecondsToInterval(interval) );
3042
3053
        PR_Unlock( notify_lock );
3051
3062
done:
3052
3063
    if(agmt_not_notified){
3053
3064
        /* failure */
3054
 
        cleanruv_log(data->task, ABORT_CLEANALLRUV_ID,"Abort task failed, will resume the task at the next server startup.");
 
3065
        cleanruv_log(data->task, data->rid, ABORT_CLEANALLRUV_ID,"Abort task failed, will resume the task at the next server startup.");
3055
3066
    } else {
3056
3067
        /*
3057
3068
         *  Wait for this server to stop its cleanallruv task(which removes the rid from the cleaned list)
3058
3069
         */
3059
 
        cleanruv_log(data->task, ABORT_CLEANALLRUV_ID, "Waiting for CleanAllRUV task to abort...");
 
3070
        cleanruv_log(data->task, data->rid, ABORT_CLEANALLRUV_ID, "Waiting for CleanAllRUV task to abort...");
3060
3071
        while(is_cleaned_rid(data->rid)){
3061
3072
            DS_Sleep(PR_SecondsToInterval(1));
3062
3073
            count++;
3063
3074
            if(count == 60){ /* it should not take this long */
3064
 
                cleanruv_log(data->task, ABORT_CLEANALLRUV_ID, "CleanAllRUV task failed to abort.  You might need to "
 
3075
                cleanruv_log(data->task, data->rid, ABORT_CLEANALLRUV_ID, "CleanAllRUV task failed to abort.  You might need to "
3065
3076
                        "rerun the task.");
3066
3077
                rc = -1;
3067
3078
                break;
3076
3087
        }
3077
3088
        delete_aborted_rid(data->replica, data->rid, data->repl_root, 0); /* remove the in-memory aborted rid */
3078
3089
        if(rc == 0){
3079
 
            cleanruv_log(data->task, ABORT_CLEANALLRUV_ID, "Successfully aborted task for rid(%d)", data->rid);
 
3090
            cleanruv_log(data->task, data->rid, ABORT_CLEANALLRUV_ID, "Successfully aborted task for rid(%d)", data->rid);
3080
3091
        } else {
3081
 
            cleanruv_log(data->task, ABORT_CLEANALLRUV_ID, "Failed to abort task for rid(%d)",data->rid);
 
3092
            cleanruv_log(data->task, data->rid, ABORT_CLEANALLRUV_ID, "Failed to abort task for rid(%d)",data->rid);
3082
3093
        }
3083
3094
    }
3084
3095
 
3116
3127
         */
3117
3128
        rc = crc;
3118
3129
        if(rc){
3119
 
                cleanruv_log(task, ABORT_CLEANALLRUV_ID, "Failed to send extop to replica(%s).", agmt_get_long_name(ra));
 
3130
            cleanruv_log(task, agmt_get_consumer_rid(ra, conn), ABORT_CLEANALLRUV_ID,
 
3131
                    "Failed to send extop to replica(%s).", agmt_get_long_name(ra));
3120
3132
        }
3121
3133
    } else {
3122
 
        cleanruv_log(task, ABORT_CLEANALLRUV_ID, "Failed to connect to replica(%s).", agmt_get_long_name(ra));
 
3134
        cleanruv_log(task, agmt_get_consumer_rid(ra, conn), ABORT_CLEANALLRUV_ID,
 
3135
                "Failed to connect to replica(%s).", agmt_get_long_name(ra));
3123
3136
        rc = -1;
3124
3137
    }
3125
3138
    conn_delete_internal_ext(conn);
3154
3167
                    /* extop was accepted */
3155
3168
                    rc = 0;
3156
3169
                } else {
3157
 
                    cleanruv_log(clean_data->task, CLEANALLRUV_ID,"Replica %s does not support the CLEANALLRUV task.  "
 
3170
                    cleanruv_log(clean_data->task, clean_data->rid, CLEANALLRUV_ID,"Replica %s does not support the CLEANALLRUV task.  "
3158
3171
                        "Sending replica CLEANRUV task...", slapi_sdn_get_dn(agmt_get_dn_byref(ra)));
3159
3172
                    /*
3160
3173
                     *  Ok, this replica doesn't know about CLEANALLRUV, so just manually
3320
3333
                    csn_init_by_string(repl_max, remote_maxcsn);
3321
3334
                    if(csn_compare (repl_max, max) < 0){
3322
3335
                        /* we are not caught up yet, free, and return */
3323
 
                        cleanruv_log(task, CLEANALLRUV_ID,"Replica maxcsn (%s) is not caught up with deleted replica's maxcsn(%s)",
 
3336
                        cleanruv_log(task, atoi(rid_text), CLEANALLRUV_ID,"Replica maxcsn (%s) is not caught up with deleted replica's maxcsn(%s)",
3324
3337
                            remote_maxcsn, maxcsn);
3325
3338
                        rc = -1;
3326
3339
                    } else {
3440
3453
 
3441
3454
   slapi_rwlock_wrlock(rid_lock);
3442
3455
   for(i = 0; i < CLEANRIDSIZ; i++){
3443
 
       if(cleaned_rids[i] != 0){
 
3456
       if(pre_cleaned_rids[i] != 0){
3444
3457
           count++;
3445
3458
       }
3446
3459
   }
3482
3495
 *  Write our logging to the task and error log
3483
3496
 */
3484
3497
void
3485
 
cleanruv_log(Slapi_Task *task, char *task_type, char *fmt, ...)
 
3498
cleanruv_log(Slapi_Task *task, int rid, char *task_type, char *fmt, ...)
3486
3499
{
3487
3500
    va_list ap1;
3488
3501
    va_list ap2;
3500
3513
        slapi_task_log_status_ext(task, fmt, ap2);
3501
3514
        slapi_task_inc_progress(task);
3502
3515
    }
3503
 
    errlog_fmt = PR_smprintf("%s: %s\n",task_type, fmt);
 
3516
    errlog_fmt = PR_smprintf("%s (rid %d): %s \n",task_type, rid, fmt);
3504
3517
    slapi_log_error_ext(SLAPI_LOG_FATAL, repl_plugin_name, errlog_fmt, ap3, ap4);
3505
3518
    slapi_ch_free_string(&errlog_fmt);
3506
3519
 
3562
3575
        }
3563
3576
    } else {
3564
3577
        /* internal search failed */
3565
 
        cleanruv_log(NULL, CLEANALLRUV_ID, "replica_cleanallruv_get_local_maxcsn: internal search failed (%d)\n", res);
 
3578
        cleanruv_log(NULL, (int)rid, CLEANALLRUV_ID, "replica_cleanallruv_get_local_maxcsn: internal search failed (%d)\n", res);
3566
3579
    }
3567
3580
 
3568
3581
        slapi_free_search_results_internal(search_pb);