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

« back to all changes in this revision

Viewing changes to ldap/servers/plugins/chainingdb/cb_modrdn.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:
54
54
int
55
55
chaining_back_modrdn ( Slapi_PBlock *pb )
56
56
{
57
 
        Slapi_Backend       * be;
58
 
        cb_backend_instance *cb;
59
 
        LDAPControl         **ctrls, **serverctrls;
60
 
        int                 rc,parse_rc,msgid,i;
61
 
        LDAP                *ld=NULL;
62
 
        char                **referrals=NULL;
63
 
        LDAPMessage         *res;
64
 
        char                *matched_msg, *error_msg;
65
 
        char                *ndn = NULL;
66
 
        Slapi_DN            *sdn = NULL;
67
 
        int                 deleteoldrdn = 0;
68
 
        Slapi_DN            *newsuperior = NULL;
69
 
        char                *newrdn = NULL;
70
 
        char                * cnxerrbuf=NULL;
71
 
        time_t              endtime = 0;
72
 
        cb_outgoing_conn    *cnx;
73
 
 
74
 
        if ( LDAP_SUCCESS != (rc=cb_forward_operation(pb) )) {
75
 
                cb_send_ldap_result( pb, rc, NULL, "Chaining forbidden", 0, NULL );
76
 
                return -1;
77
 
        }
78
 
 
79
 
        slapi_pblock_get( pb, SLAPI_BACKEND, &be );
80
 
        cb = cb_get_instance(be);
81
 
 
82
 
        cb_update_monitor_info(pb,cb,SLAPI_OPERATION_MODRDN);
83
 
 
84
 
        /* Check wether the chaining BE is available or not */
85
 
        if ( cb_check_availability( cb, pb ) == FARMSERVER_UNAVAILABLE ){
86
 
                return -1;
87
 
        }
88
 
 
89
 
        slapi_pblock_get( pb, SLAPI_MODRDN_TARGET_SDN, &sdn );
90
 
        /* newrdn is passed to ldap_rename, which does not require case-ignored
91
 
         * newrdn. */
92
 
        slapi_pblock_get( pb, SLAPI_MODRDN_NEWRDN, &newrdn );
93
 
        slapi_pblock_get( pb, SLAPI_MODRDN_NEWSUPERIOR_SDN, &newsuperior );
94
 
        slapi_pblock_get( pb, SLAPI_MODRDN_DELOLDRDN, &deleteoldrdn );
95
 
 
96
 
        ndn = (char *)slapi_sdn_get_ndn(sdn);
 
57
        cb_outgoing_conn    *cnx;
 
58
        Slapi_Backend       *be;
 
59
        cb_backend_instance *cb;
 
60
        LDAPControl         **ctrls, **serverctrls;
 
61
        LDAPMessage         *res;
 
62
        LDAP                *ld = NULL;
 
63
        Slapi_DN            *newsuperior = NULL;
 
64
        Slapi_DN            *sdn = NULL;
 
65
        char                **referrals = NULL;
 
66
        char                *matched_msg, *error_msg;
 
67
        char                *ndn = NULL;
 
68
        char                *newrdn = NULL;
 
69
        char                *cnxerrbuf = NULL;
 
70
        time_t              endtime = 0;
 
71
        int                 deleteoldrdn = 0;
 
72
        int                 rc, parse_rc, msgid, i;
 
73
 
 
74
 
 
75
        if ( LDAP_SUCCESS != (rc=cb_forward_operation(pb) )) {
 
76
                cb_send_ldap_result( pb, rc, NULL, "Chaining forbidden", 0, NULL );
 
77
                return -1;
 
78
        }
 
79
 
 
80
        slapi_pblock_get( pb, SLAPI_BACKEND, &be );
 
81
        cb = cb_get_instance(be);
 
82
 
 
83
        cb_update_monitor_info(pb,cb,SLAPI_OPERATION_MODRDN);
 
84
 
 
85
        /* Check wether the chaining BE is available or not */
 
86
        if ( cb_check_availability( cb, pb ) == FARMSERVER_UNAVAILABLE ){
 
87
                return -1;
 
88
        }
 
89
 
 
90
        slapi_pblock_get( pb, SLAPI_MODRDN_TARGET_SDN, &sdn );
 
91
        /* newrdn is passed to ldap_rename, which does not require case-ignored
 
92
         * newrdn. */
 
93
        slapi_pblock_get( pb, SLAPI_MODRDN_NEWRDN, &newrdn );
 
94
        slapi_pblock_get( pb, SLAPI_MODRDN_NEWSUPERIOR_SDN, &newsuperior );
 
95
        slapi_pblock_get( pb, SLAPI_MODRDN_DELOLDRDN, &deleteoldrdn );
 
96
 
 
97
        ndn = (char *)slapi_sdn_get_ndn(sdn);
97
98
        if (cb->local_acl && !cb->associated_be_is_disabled) {
98
99
                /* 
99
100
                * Check local acls
108
109
 
109
110
                if ( rc != LDAP_SUCCESS ) {
110
111
                        cb_send_ldap_result( pb, rc, NULL, errbuf, 0, NULL );
111
 
                        slapi_ch_free((void **)&errbuf);
 
112
                        slapi_ch_free_string(&errbuf);
112
113
                        return -1;
113
114
                }
114
 
        }
 
115
        }
115
116
 
116
117
        /*
117
118
         * Grab a connection handle
135
136
        }
136
137
 
137
138
        /*
138
 
         * Control management
139
 
         */
140
 
 
141
 
        if ( (rc = cb_update_controls( pb,ld,&ctrls,CB_UPDATE_CONTROLS_ADDAUTH )) != LDAP_SUCCESS ) {
142
 
                cb_send_ldap_result( pb, rc, NULL,NULL, 0, NULL);
143
 
                cb_release_op_connection(cb->pool,ld,CB_LDAP_CONN_ERROR(rc));
144
 
                return -1;
145
 
        }
146
 
 
147
 
 
148
 
        if ( slapi_op_abandoned( pb )) { 
149
 
                cb_release_op_connection(cb->pool,ld,0);
150
 
                if ( NULL != ctrls)
151
 
                        ldap_controls_free(ctrls);
152
 
                return -1;
153
 
        } 
 
139
         * Control management
 
140
         */
 
141
        if ( (rc = cb_update_controls( pb,ld,&ctrls,CB_UPDATE_CONTROLS_ADDAUTH )) != LDAP_SUCCESS ) {
 
142
                cb_send_ldap_result( pb, rc, NULL,NULL, 0, NULL);
 
143
                cb_release_op_connection(cb->pool,ld,CB_LDAP_CONN_ERROR(rc));
 
144
                return -1;
 
145
        }
 
146
 
 
147
 
 
148
        if ( slapi_op_abandoned( pb )) {
 
149
                cb_release_op_connection(cb->pool,ld,0);
 
150
                ldap_controls_free(ctrls);
 
151
                return -1;
 
152
        }
154
153
 
155
154
        /* heart-beat management */
156
155
        if (cb->max_idle_time>0)
157
 
                endtime=current_time() + cb->max_idle_time;
 
156
                endtime=current_time() + cb->max_idle_time;
 
157
 
 
158
        /*
 
159
         * Call the backend preoperation plugins
 
160
         */
 
161
        if((rc = slapi_plugin_call_preop_be_plugins(pb, SLAPI_PLUGIN_MODRDN_OP))){
 
162
                slapi_log_error( SLAPI_LOG_FATAL, CB_PLUGIN_SUBSYSTEM, "modrdn (%s): pre betxn failed, error (%d)\n",ndn,rc);
 
163
                cb_release_op_connection(cb->pool,ld,0);
 
164
                ldap_controls_free(ctrls);
 
165
                return -1;
 
166
        }
158
167
 
159
168
        /*
160
169
         * Send LDAP operation to the remote host
161
170
         */
162
 
 
163
171
        rc = ldap_rename ( ld, ndn, newrdn, slapi_sdn_get_dn(newsuperior),
164
172
                           deleteoldrdn, ctrls, NULL, &msgid );
165
173
 
166
 
        if ( NULL != ctrls)
167
 
                ldap_controls_free(ctrls);
 
174
        ldap_controls_free(ctrls);
168
175
        if ( rc != LDAP_SUCCESS ) {
169
 
                cb_send_ldap_result( pb, LDAP_OPERATIONS_ERROR, NULL,
170
 
                        ldap_err2string(rc), 0, NULL);
 
176
                cb_send_ldap_result( pb, LDAP_OPERATIONS_ERROR, NULL,
 
177
                        ldap_err2string(rc), 0, NULL);
171
178
                cb_release_op_connection(cb->pool,ld,CB_LDAP_CONN_ERROR(rc));
172
 
                return -1;
 
179
                return -1;
173
180
        }
174
181
 
175
182
        while ( 1 ) {
176
 
 
177
 
                if (cb_check_forward_abandon(cb,pb,ld,msgid)) {
178
 
                        return -1;
 
183
                if (cb_check_forward_abandon(cb,pb,ld,msgid)) {
 
184
                        return -1;
179
185
                }
180
186
 
181
187
                rc = ldap_result( ld, msgid, 0, &cb->abandon_timeout, &res );
182
188
                switch ( rc ) {
183
189
                case -1:
184
 
                        cb_send_ldap_result( pb, LDAP_OPERATIONS_ERROR, NULL,
185
 
                                ldap_err2string(rc), 0, NULL);
 
190
                        cb_send_ldap_result( pb, LDAP_OPERATIONS_ERROR, NULL,
 
191
                                ldap_err2string(rc), 0, NULL);
186
192
                        cb_release_op_connection(cb->pool,ld,CB_LDAP_CONN_ERROR(rc));
187
 
                        if (res)
188
 
                                ldap_msgfree(res);
189
 
                        return -1;
 
193
                        ldap_msgfree(res);
 
194
                        return -1;
 
195
 
190
196
                case 0:
191
197
                        if ((rc=cb_ping_farm(cb,cnx,endtime)) != LDAP_SUCCESS) {
192
 
 
193
 
                                /* does not respond. give up and return a*/
194
 
                                /* error to the client.                  */
195
 
 
196
 
                                /*cb_send_ldap_result(pb,LDAP_OPERATIONS_ERROR, NULL,
 
198
                                /* does not respond. give up and return a error to the client. */
 
199
 
 
200
                                /*cb_send_ldap_result(pb,LDAP_OPERATIONS_ERROR, NULL,
197
201
                                        ldap_err2string(rc), 0, NULL);*/
198
 
                                cb_send_ldap_result(pb,LDAP_OPERATIONS_ERROR, NULL,     "FARM SERVER TEMPORARY UNAVAILABLE", 0, NULL);
 
202
                                cb_send_ldap_result(pb,LDAP_OPERATIONS_ERROR, NULL, "FARM SERVER TEMPORARY UNAVAILABLE", 0, NULL);
199
203
                                cb_release_op_connection(cb->pool,ld,CB_LDAP_CONN_ERROR(rc));
200
 
                                if (res)
201
 
                                        ldap_msgfree(res);
202
 
                                return -1;
 
204
                                ldap_msgfree(res);
 
205
                                return -1;
203
206
                        }
204
207
#ifdef CB_YIELD
205
 
                        DS_Sleep(PR_INTERVAL_NO_WAIT);
 
208
                        DS_Sleep(PR_INTERVAL_NO_WAIT);
206
209
#endif
207
210
                        break;
 
211
 
208
212
                default:
209
213
                        matched_msg=error_msg=NULL;
210
214
                        parse_rc = ldap_parse_result( ld, res, &rc, &matched_msg, 
211
 
                                                  &error_msg, &referrals, &serverctrls, 1 );
 
215
                                       &error_msg, &referrals, &serverctrls, 1 );
212
216
 
213
217
                        if ( parse_rc != LDAP_SUCCESS ) {
214
218
                                static int warned_parse_rc = 0;
223
227
                                cb_send_ldap_result( pb, LDAP_OPERATIONS_ERROR, NULL,
224
228
                                                     ENDUSERMSG, 0, NULL );
225
229
                                cb_release_op_connection(cb->pool,ld,CB_LDAP_CONN_ERROR(parse_rc));
226
 
                                slapi_ch_free((void **)&matched_msg);
227
 
                                slapi_ch_free((void **)&error_msg);
228
 
                                if (serverctrls)
229
 
                                        ldap_controls_free(serverctrls);
230
 
                                /* jarnou: free referrals */
231
 
                                if (referrals)
232
 
                                        charray_free(referrals);
 
230
                                slapi_ch_free_string(&matched_msg);
 
231
                                slapi_ch_free_string(&error_msg);
 
232
                                ldap_controls_free(serverctrls);
 
233
                                charray_free(referrals);
233
234
                                return -1;
234
235
                        }
235
236
 
246
247
                                }
247
248
                                cb_send_ldap_result( pb, rc, matched_msg, ENDUSERMSG, 0, refs);
248
249
                                cb_release_op_connection(cb->pool,ld,CB_LDAP_CONN_ERROR(rc));
249
 
                                slapi_ch_free((void **)&matched_msg);
250
 
                                slapi_ch_free((void **)&error_msg);
 
250
                                slapi_ch_free_string(&matched_msg);
 
251
                                slapi_ch_free_string(&error_msg);
251
252
                                if (refs) 
252
253
                                        ber_bvecfree(refs);
253
 
                                if (referrals) 
254
 
                                        charray_free(referrals);
255
 
                                if (serverctrls)
256
 
                                        ldap_controls_free(serverctrls);
 
254
                                charray_free(referrals);
 
255
                                ldap_controls_free(serverctrls);
257
256
                                return -1;
258
257
                        }
259
258
 
260
259
                        cb_release_op_connection(cb->pool,ld,0);
261
260
 
262
 
                        /* Add control response sent by the farm server */
263
 
 
264
 
                        for (i=0; serverctrls && serverctrls[i];i++)
265
 
                                slapi_pblock_set( pb, SLAPI_ADD_RESCONTROL, serverctrls[i]);
266
 
                        if (serverctrls)
267
 
                                ldap_controls_free(serverctrls);
268
 
                        /* jarnou: free matched_msg, error_msg, and referrals if necessary */
269
 
                        slapi_ch_free((void **)&matched_msg);
270
 
                        slapi_ch_free((void **)&error_msg);
271
 
                        if (referrals) 
272
 
                                charray_free(referrals);
273
 
                        cb_send_ldap_result( pb, LDAP_SUCCESS, NULL, NULL, 0, NULL );
 
261
                        /* Call the backend postoperation plugins */
 
262
                        if((rc = slapi_plugin_call_postop_be_plugins(pb, SLAPI_PLUGIN_MODRDN_OP))){
 
263
                                slapi_log_error( SLAPI_LOG_FATAL, CB_PLUGIN_SUBSYSTEM, "modrdn (%s): post betxn failed, error (%d)\n",ndn,rc);
 
264
                        }
 
265
 
 
266
                        /* Add control response sent by the farm server */
 
267
                        for (i=0; serverctrls && serverctrls[i]; i++)
 
268
                                slapi_pblock_set( pb, SLAPI_ADD_RESCONTROL, serverctrls[i]);
 
269
                        ldap_controls_free(serverctrls);
 
270
                        slapi_ch_free_string(&matched_msg);
 
271
                        slapi_ch_free_string(&error_msg);
 
272
                        charray_free(referrals);
 
273
                        cb_send_ldap_result( pb, LDAP_SUCCESS, NULL, NULL, 0, NULL );
 
274
 
274
275
                        return 0;
275
276
                }
276
277
        }