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

« back to all changes in this revision

Viewing changes to ldap/servers/slapd/back-ldbm/ldbm_modify.c

  • Committer: Package Import Robot
  • Author(s): Timo Aaltonen
  • Date: 2014-07-08 15:50:11 UTC
  • mto: (19.1.1 experimental) (0.3.1)
  • mto: This revision was merged to the branch mainline in revision 11.
  • Revision ID: package-import@ubuntu.com-20140708155011-48naeyka2x89ew8g
Tags: upstream-1.3.2.19
ImportĀ upstreamĀ versionĀ 1.3.2.19

Show diffs side-by-side

added added

removed removed

Lines of Context:
116
116
        ldbm_instance *inst = (ldbm_instance *) be->be_instance_info;
117
117
        int ret = 0;
118
118
        if (mc->old_entry!=NULL && mc->new_entry!=NULL) {
119
 
            ret = cache_replace(&(inst->inst_cache), mc->old_entry, mc->new_entry);
120
 
            if (ret == 0) mc->new_entry_in_cache = 1;
121
 
        }
 
119
                ret = cache_replace(&(inst->inst_cache), mc->old_entry, mc->new_entry);
 
120
                if (ret == 0) {
 
121
                        mc->new_entry_in_cache = 1;
 
122
                } else {
 
123
                        LDAPDebug(LDAP_DEBUG_CACHE, "modify_switch_entries: replacing %s with %s failed (%d)\n",
 
124
                                  slapi_entry_get_dn(mc->old_entry->ep_entry), 
 
125
                                  slapi_entry_get_dn(mc->new_entry->ep_entry), ret);
 
126
                }
 
127
        }
 
128
        return ret;
 
129
}
 
130
 
 
131
/*
 
132
 * Switch the new with the old(original) - undoing modify_switch_entries()
 
133
 * This expects modify_term() to be called next, as the old "new" entry
 
134
 * is now gone(replaced by the original entry).
 
135
 */
 
136
int
 
137
modify_unswitch_entries(modify_context *mc,backend *be)
 
138
{
 
139
        struct backentry *tmp_be;
 
140
        ldbm_instance *inst = (ldbm_instance *) be->be_instance_info;
 
141
        int ret = 0;
 
142
 
 
143
        if (mc->old_entry!=NULL && mc->new_entry!=NULL) {
 
144
                /* switch the entries, and reset the new, new, entry */
 
145
                tmp_be = mc->new_entry;
 
146
                mc->new_entry = mc->old_entry;
 
147
                mc->new_entry->ep_state = 0;
 
148
                mc->new_entry->ep_refcnt = 0;
 
149
                mc->new_entry_in_cache = 0;
 
150
                mc->old_entry = tmp_be;
 
151
 
 
152
                ret = cache_replace(&(inst->inst_cache), mc->old_entry, mc->new_entry);
 
153
                if (ret == 0) {
 
154
                        /*
 
155
                         * The new entry was originally locked, so since we did the
 
156
                         * switch we need to unlock the "new" entry, and return the
 
157
                         * "old" one.  modify_term() will then return the "new" entry.
 
158
                         */
 
159
                        cache_unlock_entry(&inst->inst_cache, mc->new_entry);
 
160
                        CACHE_RETURN( &(inst->inst_cache), &(mc->old_entry) );
 
161
                        mc->new_entry_in_cache = 1;
 
162
                        mc->old_entry = NULL;
 
163
                } else {
 
164
                        LDAPDebug(LDAP_DEBUG_CACHE, "modify_unswitch_entries: replacing %s with %s failed (%d)\n",
 
165
                                  slapi_entry_get_dn(mc->old_entry->ep_entry), 
 
166
                                  slapi_entry_get_dn(mc->new_entry->ep_entry), ret);
 
167
                }
 
168
        }
 
169
 
122
170
        return ret;
123
171
}
124
172
 
253
301
         * If the objectClass attribute type was modified in any way, expand
254
302
         * the objectClass values to reflect the inheritance hierarchy.
255
303
         */
256
 
        for ( i = 0; mods[i] != NULL && !repl_op; ++i ) {
 
304
        for ( i = 0; (mods != NULL) && (mods[i] != NULL) && !repl_op; ++i ) {
257
305
                if ( 0 == strcasecmp( SLAPI_ATTR_OBJECTCLASS, mods[i]->mod_type )) {
258
306
                        slapi_schema_expand_objectclasses( ec->ep_entry );
259
307
                        break;
520
568
                
521
569
                        if ( !is_fixup_operation )
522
570
                        {
523
 
                                if (slapi_entry_flag_is_set(e->ep_entry, SLAPI_ENTRY_FLAG_TOMBSTONE) ) {
 
571
                                if (!repl_op && slapi_entry_flag_is_set(e->ep_entry, SLAPI_ENTRY_FLAG_TOMBSTONE) ) {
524
572
                                        ldap_result_code = LDAP_UNWILLING_TO_PERFORM;
525
573
                                        ldap_result_message = "Operation not allowed on tombstone entry.";
526
574
                                        slapi_log_error(SLAPI_LOG_FATAL, "ldbm_back_modify",
757
805
                MOD_SET_ERROR(ldap_result_code, LDAP_OPERATIONS_ERROR, retry_count);
758
806
                goto error_return;
759
807
        }
 
808
        /* e uncached */
 
809
        /* we must return both e (which has been deleted) and new entry ec */
 
810
        /* cache_replace removes e from the caches */
 
811
        cache_unlock_entry( &inst->inst_cache, e );
 
812
        CACHE_RETURN( &inst->inst_cache, &e );
 
813
 
760
814
        /* lock new entry in cache to prevent usage until we are complete */
761
815
        cache_lock_entry( &inst->inst_cache, ec );
762
816
        ec_in_cache = 1;
767
821
        /* invalidate virtual cache */
768
822
        ec->ep_entry->e_virtual_watermark = 0;
769
823
 
770
 
        /* we must return both e (which has been deleted) and new entry ec */
771
 
        /* cache_replace removes e from the caches */
772
 
        cache_unlock_entry( &inst->inst_cache, e );
773
 
        CACHE_RETURN( &inst->inst_cache, &e );
774
824
        /* 
775
825
         * LP Fix of crash when the commit will fail:
776
826
         * If the commit fail, the common error path will
851
901
                                LDAPDebug1Arg( LDAP_DEBUG_TRACE, "SLAPI_PLUGIN_BE_TXN_POST_MODIFY_FN plugin "
852
902
                                                           "returned error code %d\n", retval );
853
903
                                slapi_pblock_get(pb, SLAPI_RESULT_CODE, &ldap_result_code);
 
904
                                slapi_pblock_get(pb, SLAPI_PB_RESULT_TEXT, &ldap_result_message);
854
905
                                slapi_pblock_get(pb, SLAPI_PLUGIN_OPRETURN, &opreturn);
855
906
                                if (!opreturn) {
856
907
                                        slapi_pblock_set(pb, SLAPI_PLUGIN_OPRETURN, ldap_result_code ? &ldap_result_code : &retval);
873
924
                CACHE_REMOVE( &inst->inst_cache, ec );
874
925
                /* if ec was in cache, e was not - add back e */
875
926
                if (e) {
876
 
                        CACHE_ADD( &inst->inst_cache, e, NULL );
877
 
                        cache_lock_entry( &inst->inst_cache, e );
 
927
                        if (CACHE_ADD( &inst->inst_cache, e, NULL )) {
 
928
                                LDAPDebug1Arg(LDAP_DEBUG_CACHE, "ldbm_modify: CACHE_ADD %s failed\n",
 
929
                                              slapi_entry_get_dn(e->ep_entry));
 
930
                        }
878
931
                }
879
932
        }
880
933
 
881
934
common_return:
882
935
        slapi_mods_done(&smods);
883
936
        
884
 
        if (inst && ec_in_cache)
885
 
        {
886
 
                cache_unlock_entry( &inst->inst_cache, ec);
887
 
                CACHE_RETURN( &inst->inst_cache, &ec );
888
 
        }
889
 
        else
890
 
        {
891
 
                backentry_free(&ec);
892
 
        }
893
 
        
894
937
        if (inst) {
895
 
                if (e) {
896
 
                        cache_unlock_entry( &inst->inst_cache, e);
897
 
                        CACHE_RETURN( &inst->inst_cache, &e);
 
938
                if (ec_in_cache) {
 
939
                        cache_unlock_entry( &inst->inst_cache, ec);
 
940
                        CACHE_RETURN( &inst->inst_cache, &ec );
 
941
                } else {
 
942
                        backentry_free(&ec);
 
943
                        /* if ec was not in cache, cache_replace was not done.
 
944
                         * i.e., e was not unlocked. */
 
945
                        if (e) {
 
946
                                cache_unlock_entry( &inst->inst_cache, e);
 
947
                                CACHE_RETURN( &inst->inst_cache, &e);
 
948
                        }
898
949
                }
899
950
                if (inst->inst_ref_count) {
900
951
                        slapi_counter_decrement(inst->inst_ref_count);
938
989
        LDAPMod         *tmp;
939
990
 
940
991
        /* remove any attempts by the user to modify these attrs */
941
 
        for ( i = 0; mods[i] != NULL; i++ ) {
 
992
        for ( i = 0; (mods != NULL) && (mods[i] != NULL); i++ ) {
942
993
                if ( strcasecmp( mods[i]->mod_type, numsubordinates ) == 0
943
994
                    || strcasecmp( mods[i]->mod_type, hassubordinates ) == 0 )
944
995
                {