retcode.c revision 1.1.1.2 1 1.1.1.2 lukem /* $NetBSD: retcode.c,v 1.1.1.2 2010/03/08 02:14:20 lukem Exp $ */
2 1.1.1.2 lukem
3 1.1 lukem /* retcode.c - customizable response for client testing purposes */
4 1.1.1.2 lukem /* OpenLDAP: pkg/ldap/servers/slapd/overlays/retcode.c,v 1.18.2.11 2009/11/22 19:39:43 quanah Exp */
5 1.1 lukem /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
6 1.1 lukem *
7 1.1.1.2 lukem * Copyright 2005-2009 The OpenLDAP Foundation.
8 1.1 lukem * Portions Copyright 2005 Pierangelo Masarati <ando (at) sys-net.it>
9 1.1 lukem * All rights reserved.
10 1.1 lukem *
11 1.1 lukem * Redistribution and use in source and binary forms, with or without
12 1.1 lukem * modification, are permitted only as authorized by the OpenLDAP
13 1.1 lukem * Public License.
14 1.1 lukem *
15 1.1 lukem * A copy of this license is available in the file LICENSE in the
16 1.1 lukem * top-level directory of the distribution or, alternatively, at
17 1.1 lukem * <http://www.OpenLDAP.org/license.html>.
18 1.1 lukem */
19 1.1 lukem /* ACKNOWLEDGEMENTS:
20 1.1 lukem * This work was initially developed by Pierangelo Masarati for inclusion
21 1.1 lukem * in OpenLDAP Software.
22 1.1 lukem */
23 1.1 lukem
24 1.1 lukem #include "portable.h"
25 1.1 lukem
26 1.1 lukem #ifdef SLAPD_OVER_RETCODE
27 1.1 lukem
28 1.1 lukem #include <stdio.h>
29 1.1 lukem
30 1.1 lukem #include <ac/unistd.h>
31 1.1 lukem #include <ac/string.h>
32 1.1 lukem #include <ac/ctype.h>
33 1.1 lukem #include <ac/socket.h>
34 1.1 lukem
35 1.1 lukem #include "slap.h"
36 1.1 lukem #include "config.h"
37 1.1 lukem #include "lutil.h"
38 1.1 lukem #include "ldif.h"
39 1.1 lukem
40 1.1 lukem static slap_overinst retcode;
41 1.1 lukem
42 1.1 lukem static AttributeDescription *ad_errCode;
43 1.1 lukem static AttributeDescription *ad_errText;
44 1.1 lukem static AttributeDescription *ad_errOp;
45 1.1 lukem static AttributeDescription *ad_errSleepTime;
46 1.1 lukem static AttributeDescription *ad_errMatchedDN;
47 1.1 lukem static AttributeDescription *ad_errUnsolicitedOID;
48 1.1 lukem static AttributeDescription *ad_errUnsolicitedData;
49 1.1 lukem static AttributeDescription *ad_errDisconnect;
50 1.1 lukem
51 1.1 lukem static ObjectClass *oc_errAbsObject;
52 1.1 lukem static ObjectClass *oc_errObject;
53 1.1 lukem static ObjectClass *oc_errAuxObject;
54 1.1 lukem
55 1.1 lukem typedef enum retcode_op_e {
56 1.1 lukem SN_DG_OP_NONE = 0x0000,
57 1.1 lukem SN_DG_OP_ADD = 0x0001,
58 1.1 lukem SN_DG_OP_BIND = 0x0002,
59 1.1 lukem SN_DG_OP_COMPARE = 0x0004,
60 1.1 lukem SN_DG_OP_DELETE = 0x0008,
61 1.1 lukem SN_DG_OP_MODIFY = 0x0010,
62 1.1 lukem SN_DG_OP_RENAME = 0x0020,
63 1.1 lukem SN_DG_OP_SEARCH = 0x0040,
64 1.1 lukem SN_DG_EXTENDED = 0x0080,
65 1.1 lukem SN_DG_OP_AUTH = SN_DG_OP_BIND,
66 1.1 lukem SN_DG_OP_READ = (SN_DG_OP_COMPARE|SN_DG_OP_SEARCH),
67 1.1 lukem SN_DG_OP_WRITE = (SN_DG_OP_ADD|SN_DG_OP_DELETE|SN_DG_OP_MODIFY|SN_DG_OP_RENAME),
68 1.1 lukem SN_DG_OP_ALL = (SN_DG_OP_AUTH|SN_DG_OP_READ|SN_DG_OP_WRITE|SN_DG_EXTENDED)
69 1.1 lukem } retcode_op_e;
70 1.1 lukem
71 1.1 lukem typedef struct retcode_item_t {
72 1.1.1.2 lukem struct berval rdi_line;
73 1.1 lukem struct berval rdi_dn;
74 1.1 lukem struct berval rdi_ndn;
75 1.1 lukem struct berval rdi_text;
76 1.1 lukem struct berval rdi_matched;
77 1.1 lukem int rdi_err;
78 1.1 lukem BerVarray rdi_ref;
79 1.1 lukem int rdi_sleeptime;
80 1.1 lukem Entry rdi_e;
81 1.1 lukem slap_mask_t rdi_mask;
82 1.1 lukem struct berval rdi_unsolicited_oid;
83 1.1 lukem struct berval rdi_unsolicited_data;
84 1.1 lukem
85 1.1 lukem unsigned rdi_flags;
86 1.1 lukem #define RDI_PRE_DISCONNECT (0x1U)
87 1.1 lukem #define RDI_POST_DISCONNECT (0x2U)
88 1.1 lukem
89 1.1 lukem struct retcode_item_t *rdi_next;
90 1.1 lukem } retcode_item_t;
91 1.1 lukem
92 1.1 lukem typedef struct retcode_t {
93 1.1 lukem struct berval rd_pdn;
94 1.1 lukem struct berval rd_npdn;
95 1.1 lukem
96 1.1 lukem int rd_sleep;
97 1.1 lukem
98 1.1 lukem retcode_item_t *rd_item;
99 1.1 lukem
100 1.1.1.2 lukem int rd_indir;
101 1.1 lukem #define RETCODE_FINDIR 0x01
102 1.1.1.2 lukem #define RETCODE_INDIR( rd ) ( (rd)->rd_indir )
103 1.1 lukem } retcode_t;
104 1.1 lukem
105 1.1 lukem static int
106 1.1 lukem retcode_entry_response( Operation *op, SlapReply *rs, BackendInfo *bi, Entry *e );
107 1.1 lukem
108 1.1 lukem static unsigned int
109 1.1 lukem retcode_sleep( int s )
110 1.1 lukem {
111 1.1 lukem unsigned int r = 0;
112 1.1 lukem
113 1.1 lukem /* sleep as required */
114 1.1 lukem if ( s < 0 ) {
115 1.1 lukem #if 0 /* use high-order bits for better randomness (Numerical Recipes in "C") */
116 1.1 lukem r = rand() % (-s);
117 1.1 lukem #endif
118 1.1 lukem r = ((double)(-s))*rand()/(RAND_MAX + 1.0);
119 1.1 lukem } else if ( s > 0 ) {
120 1.1 lukem r = (unsigned int)s;
121 1.1 lukem }
122 1.1 lukem if ( r ) {
123 1.1 lukem sleep( r );
124 1.1 lukem }
125 1.1 lukem
126 1.1 lukem return r;
127 1.1 lukem }
128 1.1 lukem
129 1.1 lukem static int
130 1.1 lukem retcode_cleanup_cb( Operation *op, SlapReply *rs )
131 1.1 lukem {
132 1.1 lukem rs->sr_matched = NULL;
133 1.1 lukem rs->sr_text = NULL;
134 1.1 lukem
135 1.1 lukem if ( rs->sr_ref != NULL ) {
136 1.1 lukem ber_bvarray_free( rs->sr_ref );
137 1.1 lukem rs->sr_ref = NULL;
138 1.1 lukem }
139 1.1 lukem
140 1.1 lukem ch_free( op->o_callback );
141 1.1 lukem op->o_callback = NULL;
142 1.1 lukem
143 1.1 lukem return SLAP_CB_CONTINUE;
144 1.1 lukem }
145 1.1 lukem
146 1.1 lukem static int
147 1.1 lukem retcode_send_onelevel( Operation *op, SlapReply *rs )
148 1.1 lukem {
149 1.1 lukem slap_overinst *on = (slap_overinst *)op->o_bd->bd_info;
150 1.1 lukem retcode_t *rd = (retcode_t *)on->on_bi.bi_private;
151 1.1 lukem
152 1.1 lukem retcode_item_t *rdi;
153 1.1 lukem
154 1.1 lukem for ( rdi = rd->rd_item; rdi != NULL; rdi = rdi->rdi_next ) {
155 1.1 lukem if ( op->o_abandon ) {
156 1.1 lukem return rs->sr_err = SLAPD_ABANDON;
157 1.1 lukem }
158 1.1 lukem
159 1.1 lukem rs->sr_err = test_filter( op, &rdi->rdi_e, op->ors_filter );
160 1.1 lukem if ( rs->sr_err == LDAP_COMPARE_TRUE ) {
161 1.1 lukem /* safe default */
162 1.1 lukem rs->sr_attrs = op->ors_attrs;
163 1.1 lukem rs->sr_operational_attrs = NULL;
164 1.1 lukem rs->sr_ctrls = NULL;
165 1.1 lukem rs->sr_flags = 0;
166 1.1 lukem rs->sr_err = LDAP_SUCCESS;
167 1.1 lukem rs->sr_entry = &rdi->rdi_e;
168 1.1 lukem
169 1.1 lukem rs->sr_err = send_search_entry( op, rs );
170 1.1 lukem rs->sr_entry = NULL;
171 1.1 lukem
172 1.1 lukem switch ( rs->sr_err ) {
173 1.1 lukem case LDAP_UNAVAILABLE: /* connection closed */
174 1.1 lukem rs->sr_err = LDAP_OTHER;
175 1.1 lukem /* fallthru */
176 1.1 lukem case LDAP_SIZELIMIT_EXCEEDED:
177 1.1 lukem goto done;
178 1.1 lukem }
179 1.1 lukem }
180 1.1 lukem rs->sr_err = LDAP_SUCCESS;
181 1.1 lukem }
182 1.1 lukem
183 1.1 lukem done:;
184 1.1 lukem
185 1.1 lukem send_ldap_result( op, rs );
186 1.1 lukem
187 1.1 lukem return rs->sr_err;
188 1.1 lukem }
189 1.1 lukem
190 1.1 lukem static int
191 1.1 lukem retcode_op_add( Operation *op, SlapReply *rs )
192 1.1 lukem {
193 1.1 lukem return retcode_entry_response( op, rs, NULL, op->ora_e );
194 1.1 lukem }
195 1.1 lukem
196 1.1 lukem typedef struct retcode_cb_t {
197 1.1 lukem BackendInfo *rdc_info;
198 1.1 lukem unsigned rdc_flags;
199 1.1 lukem ber_tag_t rdc_tag;
200 1.1 lukem AttributeName *rdc_attrs;
201 1.1 lukem } retcode_cb_t;
202 1.1 lukem
203 1.1 lukem static int
204 1.1 lukem retcode_cb_response( Operation *op, SlapReply *rs )
205 1.1 lukem {
206 1.1 lukem retcode_cb_t *rdc = (retcode_cb_t *)op->o_callback->sc_private;
207 1.1 lukem
208 1.1 lukem op->o_tag = rdc->rdc_tag;
209 1.1 lukem if ( rs->sr_type == REP_SEARCH ) {
210 1.1 lukem ber_tag_t o_tag = op->o_tag;
211 1.1 lukem int rc;
212 1.1 lukem
213 1.1 lukem if ( op->o_tag == LDAP_REQ_SEARCH ) {
214 1.1 lukem rs->sr_attrs = rdc->rdc_attrs;
215 1.1 lukem }
216 1.1 lukem rc = retcode_entry_response( op, rs, rdc->rdc_info, rs->sr_entry );
217 1.1 lukem op->o_tag = o_tag;
218 1.1 lukem
219 1.1 lukem return rc;
220 1.1 lukem }
221 1.1 lukem
222 1.1 lukem switch ( rs->sr_err ) {
223 1.1 lukem case LDAP_SUCCESS:
224 1.1 lukem case LDAP_NO_SUCH_OBJECT:
225 1.1 lukem /* in case of noSuchObject, stop the internal search
226 1.1 lukem * for in-directory error stuff */
227 1.1 lukem if ( !op->o_abandon ) {
228 1.1 lukem rdc->rdc_flags = SLAP_CB_CONTINUE;
229 1.1 lukem }
230 1.1 lukem return 0;
231 1.1 lukem }
232 1.1 lukem
233 1.1 lukem return SLAP_CB_CONTINUE;
234 1.1 lukem }
235 1.1 lukem
236 1.1 lukem static int
237 1.1 lukem retcode_op_internal( Operation *op, SlapReply *rs )
238 1.1 lukem {
239 1.1 lukem slap_overinst *on = (slap_overinst *)op->o_bd->bd_info;
240 1.1 lukem
241 1.1 lukem Operation op2 = *op;
242 1.1 lukem BackendDB db = *op->o_bd;
243 1.1 lukem slap_callback sc = { 0 };
244 1.1 lukem retcode_cb_t rdc;
245 1.1 lukem
246 1.1 lukem int rc;
247 1.1 lukem
248 1.1 lukem op2.o_tag = LDAP_REQ_SEARCH;
249 1.1 lukem op2.ors_scope = LDAP_SCOPE_BASE;
250 1.1 lukem op2.ors_deref = LDAP_DEREF_NEVER;
251 1.1 lukem op2.ors_tlimit = SLAP_NO_LIMIT;
252 1.1 lukem op2.ors_slimit = SLAP_NO_LIMIT;
253 1.1 lukem op2.ors_limit = NULL;
254 1.1 lukem op2.ors_attrsonly = 0;
255 1.1 lukem op2.ors_attrs = slap_anlist_all_attributes;
256 1.1 lukem
257 1.1 lukem ber_str2bv_x( "(objectClass=errAbsObject)",
258 1.1 lukem STRLENOF( "(objectClass=errAbsObject)" ),
259 1.1 lukem 1, &op2.ors_filterstr, op2.o_tmpmemctx );
260 1.1 lukem op2.ors_filter = str2filter_x( &op2, op2.ors_filterstr.bv_val );
261 1.1 lukem
262 1.1.1.2 lukem /* errAbsObject is defined by this overlay! */
263 1.1.1.2 lukem assert( op2.ors_filter != NULL );
264 1.1.1.2 lukem
265 1.1 lukem db.bd_info = on->on_info->oi_orig;
266 1.1 lukem op2.o_bd = &db;
267 1.1 lukem
268 1.1 lukem rdc.rdc_info = on->on_info->oi_orig;
269 1.1 lukem rdc.rdc_flags = RETCODE_FINDIR;
270 1.1 lukem if ( op->o_tag == LDAP_REQ_SEARCH ) {
271 1.1 lukem rdc.rdc_attrs = op->ors_attrs;
272 1.1 lukem }
273 1.1 lukem rdc.rdc_tag = op->o_tag;
274 1.1 lukem sc.sc_response = retcode_cb_response;
275 1.1 lukem sc.sc_private = &rdc;
276 1.1 lukem op2.o_callback = ≻
277 1.1 lukem
278 1.1 lukem rc = op2.o_bd->be_search( &op2, rs );
279 1.1 lukem op->o_abandon = op2.o_abandon;
280 1.1 lukem
281 1.1.1.2 lukem filter_free_x( &op2, op2.ors_filter, 1 );
282 1.1 lukem ber_memfree_x( op2.ors_filterstr.bv_val, op2.o_tmpmemctx );
283 1.1 lukem
284 1.1 lukem if ( rdc.rdc_flags == SLAP_CB_CONTINUE ) {
285 1.1 lukem return SLAP_CB_CONTINUE;
286 1.1 lukem }
287 1.1 lukem
288 1.1 lukem return rc;
289 1.1 lukem }
290 1.1 lukem
291 1.1 lukem static int
292 1.1 lukem retcode_op_func( Operation *op, SlapReply *rs )
293 1.1 lukem {
294 1.1 lukem slap_overinst *on = (slap_overinst *)op->o_bd->bd_info;
295 1.1 lukem retcode_t *rd = (retcode_t *)on->on_bi.bi_private;
296 1.1 lukem
297 1.1 lukem retcode_item_t *rdi;
298 1.1 lukem struct berval nrdn, npdn;
299 1.1 lukem
300 1.1 lukem slap_callback *cb = NULL;
301 1.1 lukem
302 1.1 lukem /* sleep as required */
303 1.1 lukem retcode_sleep( rd->rd_sleep );
304 1.1 lukem
305 1.1 lukem if ( !dnIsSuffix( &op->o_req_ndn, &rd->rd_npdn ) ) {
306 1.1 lukem if ( RETCODE_INDIR( rd ) ) {
307 1.1 lukem switch ( op->o_tag ) {
308 1.1 lukem case LDAP_REQ_ADD:
309 1.1 lukem return retcode_op_add( op, rs );
310 1.1 lukem
311 1.1 lukem case LDAP_REQ_BIND:
312 1.1 lukem /* skip if rootdn */
313 1.1 lukem /* FIXME: better give the db a chance? */
314 1.1 lukem if ( be_isroot_pw( op ) ) {
315 1.1 lukem return LDAP_SUCCESS;
316 1.1 lukem }
317 1.1 lukem return retcode_op_internal( op, rs );
318 1.1 lukem
319 1.1 lukem case LDAP_REQ_SEARCH:
320 1.1 lukem if ( op->ors_scope == LDAP_SCOPE_BASE ) {
321 1.1 lukem rs->sr_err = retcode_op_internal( op, rs );
322 1.1 lukem switch ( rs->sr_err ) {
323 1.1 lukem case SLAP_CB_CONTINUE:
324 1.1 lukem if ( rs->sr_nentries == 0 ) {
325 1.1 lukem break;
326 1.1 lukem }
327 1.1 lukem rs->sr_err = LDAP_SUCCESS;
328 1.1 lukem /* fallthru */
329 1.1 lukem
330 1.1 lukem default:
331 1.1 lukem send_ldap_result( op, rs );
332 1.1 lukem break;
333 1.1 lukem }
334 1.1 lukem return rs->sr_err;
335 1.1 lukem }
336 1.1 lukem break;
337 1.1 lukem
338 1.1 lukem case LDAP_REQ_MODIFY:
339 1.1 lukem case LDAP_REQ_DELETE:
340 1.1 lukem case LDAP_REQ_MODRDN:
341 1.1 lukem case LDAP_REQ_COMPARE:
342 1.1 lukem return retcode_op_internal( op, rs );
343 1.1 lukem }
344 1.1 lukem }
345 1.1 lukem
346 1.1 lukem return SLAP_CB_CONTINUE;
347 1.1 lukem }
348 1.1 lukem
349 1.1 lukem if ( op->o_tag == LDAP_REQ_SEARCH
350 1.1 lukem && op->ors_scope != LDAP_SCOPE_BASE
351 1.1 lukem && op->o_req_ndn.bv_len == rd->rd_npdn.bv_len )
352 1.1 lukem {
353 1.1 lukem return retcode_send_onelevel( op, rs );
354 1.1 lukem }
355 1.1 lukem
356 1.1 lukem dnParent( &op->o_req_ndn, &npdn );
357 1.1 lukem if ( npdn.bv_len != rd->rd_npdn.bv_len ) {
358 1.1 lukem rs->sr_err = LDAP_NO_SUCH_OBJECT;
359 1.1 lukem rs->sr_matched = rd->rd_pdn.bv_val;
360 1.1 lukem send_ldap_result( op, rs );
361 1.1 lukem rs->sr_matched = NULL;
362 1.1 lukem return rs->sr_err;
363 1.1 lukem }
364 1.1 lukem
365 1.1 lukem dnRdn( &op->o_req_ndn, &nrdn );
366 1.1 lukem
367 1.1 lukem for ( rdi = rd->rd_item; rdi != NULL; rdi = rdi->rdi_next ) {
368 1.1 lukem struct berval rdi_nrdn;
369 1.1 lukem
370 1.1 lukem dnRdn( &rdi->rdi_ndn, &rdi_nrdn );
371 1.1 lukem if ( dn_match( &nrdn, &rdi_nrdn ) ) {
372 1.1 lukem break;
373 1.1 lukem }
374 1.1 lukem }
375 1.1 lukem
376 1.1 lukem if ( rdi != NULL && rdi->rdi_mask != SN_DG_OP_ALL ) {
377 1.1 lukem retcode_op_e o_tag = SN_DG_OP_NONE;
378 1.1 lukem
379 1.1 lukem switch ( op->o_tag ) {
380 1.1 lukem case LDAP_REQ_ADD:
381 1.1 lukem o_tag = SN_DG_OP_ADD;
382 1.1 lukem break;
383 1.1 lukem
384 1.1 lukem case LDAP_REQ_BIND:
385 1.1 lukem o_tag = SN_DG_OP_BIND;
386 1.1 lukem break;
387 1.1 lukem
388 1.1 lukem case LDAP_REQ_COMPARE:
389 1.1 lukem o_tag = SN_DG_OP_COMPARE;
390 1.1 lukem break;
391 1.1 lukem
392 1.1 lukem case LDAP_REQ_DELETE:
393 1.1 lukem o_tag = SN_DG_OP_DELETE;
394 1.1 lukem break;
395 1.1 lukem
396 1.1 lukem case LDAP_REQ_MODIFY:
397 1.1 lukem o_tag = SN_DG_OP_MODIFY;
398 1.1 lukem break;
399 1.1 lukem
400 1.1 lukem case LDAP_REQ_MODRDN:
401 1.1 lukem o_tag = SN_DG_OP_RENAME;
402 1.1 lukem break;
403 1.1 lukem
404 1.1 lukem case LDAP_REQ_SEARCH:
405 1.1 lukem o_tag = SN_DG_OP_SEARCH;
406 1.1 lukem break;
407 1.1 lukem
408 1.1 lukem case LDAP_REQ_EXTENDED:
409 1.1 lukem o_tag = SN_DG_EXTENDED;
410 1.1 lukem break;
411 1.1 lukem
412 1.1 lukem default:
413 1.1 lukem /* Should not happen */
414 1.1 lukem break;
415 1.1 lukem }
416 1.1 lukem
417 1.1 lukem if ( !( o_tag & rdi->rdi_mask ) ) {
418 1.1 lukem return SLAP_CB_CONTINUE;
419 1.1 lukem }
420 1.1 lukem }
421 1.1 lukem
422 1.1 lukem if ( rdi == NULL ) {
423 1.1 lukem rs->sr_matched = rd->rd_pdn.bv_val;
424 1.1 lukem rs->sr_err = LDAP_NO_SUCH_OBJECT;
425 1.1 lukem rs->sr_text = "retcode not found";
426 1.1 lukem
427 1.1 lukem } else {
428 1.1 lukem if ( rdi->rdi_flags & RDI_PRE_DISCONNECT ) {
429 1.1 lukem return rs->sr_err = SLAPD_DISCONNECT;
430 1.1 lukem }
431 1.1 lukem
432 1.1 lukem rs->sr_err = rdi->rdi_err;
433 1.1 lukem rs->sr_text = rdi->rdi_text.bv_val;
434 1.1 lukem rs->sr_matched = rdi->rdi_matched.bv_val;
435 1.1 lukem
436 1.1 lukem /* FIXME: we only honor the rdi_ref field in case rdi_err
437 1.1 lukem * is LDAP_REFERRAL otherwise send_ldap_result() bails out */
438 1.1 lukem if ( rs->sr_err == LDAP_REFERRAL ) {
439 1.1 lukem BerVarray ref;
440 1.1 lukem
441 1.1 lukem if ( rdi->rdi_ref != NULL ) {
442 1.1 lukem ref = rdi->rdi_ref;
443 1.1 lukem } else {
444 1.1 lukem ref = default_referral;
445 1.1 lukem }
446 1.1 lukem
447 1.1 lukem if ( ref != NULL ) {
448 1.1 lukem rs->sr_ref = referral_rewrite( ref,
449 1.1 lukem NULL, &op->o_req_dn, LDAP_SCOPE_DEFAULT );
450 1.1 lukem
451 1.1 lukem } else {
452 1.1 lukem rs->sr_err = LDAP_OTHER;
453 1.1 lukem rs->sr_text = "bad referral object";
454 1.1 lukem }
455 1.1 lukem }
456 1.1 lukem
457 1.1 lukem retcode_sleep( rdi->rdi_sleeptime );
458 1.1 lukem }
459 1.1 lukem
460 1.1 lukem switch ( op->o_tag ) {
461 1.1 lukem case LDAP_REQ_EXTENDED:
462 1.1 lukem if ( rdi == NULL ) {
463 1.1 lukem break;
464 1.1 lukem }
465 1.1 lukem cb = ( slap_callback * )ch_malloc( sizeof( slap_callback ) );
466 1.1 lukem memset( cb, 0, sizeof( slap_callback ) );
467 1.1 lukem cb->sc_cleanup = retcode_cleanup_cb;
468 1.1 lukem op->o_callback = cb;
469 1.1 lukem break;
470 1.1 lukem
471 1.1 lukem default:
472 1.1 lukem if ( rdi && !BER_BVISNULL( &rdi->rdi_unsolicited_oid ) ) {
473 1.1 lukem ber_int_t msgid = op->o_msgid;
474 1.1 lukem
475 1.1 lukem /* RFC 4511 unsolicited response */
476 1.1 lukem
477 1.1 lukem op->o_msgid = 0;
478 1.1 lukem if ( strcmp( rdi->rdi_unsolicited_oid.bv_val, "0" ) == 0 ) {
479 1.1 lukem send_ldap_result( op, rs );
480 1.1 lukem
481 1.1 lukem } else {
482 1.1 lukem ber_tag_t tag = op->o_tag;
483 1.1 lukem
484 1.1 lukem op->o_tag = LDAP_REQ_EXTENDED;
485 1.1 lukem rs->sr_rspoid = rdi->rdi_unsolicited_oid.bv_val;
486 1.1 lukem if ( !BER_BVISNULL( &rdi->rdi_unsolicited_data ) ) {
487 1.1 lukem rs->sr_rspdata = &rdi->rdi_unsolicited_data;
488 1.1 lukem }
489 1.1 lukem send_ldap_extended( op, rs );
490 1.1 lukem rs->sr_rspoid = NULL;
491 1.1 lukem rs->sr_rspdata = NULL;
492 1.1 lukem op->o_tag = tag;
493 1.1 lukem
494 1.1 lukem }
495 1.1 lukem op->o_msgid = msgid;
496 1.1 lukem
497 1.1 lukem } else {
498 1.1 lukem send_ldap_result( op, rs );
499 1.1 lukem }
500 1.1 lukem
501 1.1 lukem if ( rs->sr_ref != NULL ) {
502 1.1 lukem ber_bvarray_free( rs->sr_ref );
503 1.1 lukem rs->sr_ref = NULL;
504 1.1 lukem }
505 1.1 lukem rs->sr_matched = NULL;
506 1.1 lukem rs->sr_text = NULL;
507 1.1 lukem
508 1.1 lukem if ( rdi && rdi->rdi_flags & RDI_POST_DISCONNECT ) {
509 1.1 lukem return rs->sr_err = SLAPD_DISCONNECT;
510 1.1 lukem }
511 1.1 lukem break;
512 1.1 lukem }
513 1.1 lukem
514 1.1 lukem return rs->sr_err;
515 1.1 lukem }
516 1.1 lukem
517 1.1 lukem static int
518 1.1 lukem retcode_op2str( ber_tag_t op, struct berval *bv )
519 1.1 lukem {
520 1.1 lukem switch ( op ) {
521 1.1 lukem case LDAP_REQ_BIND:
522 1.1 lukem BER_BVSTR( bv, "bind" );
523 1.1 lukem return 0;
524 1.1 lukem case LDAP_REQ_ADD:
525 1.1 lukem BER_BVSTR( bv, "add" );
526 1.1 lukem return 0;
527 1.1 lukem case LDAP_REQ_DELETE:
528 1.1 lukem BER_BVSTR( bv, "delete" );
529 1.1 lukem return 0;
530 1.1 lukem case LDAP_REQ_MODRDN:
531 1.1 lukem BER_BVSTR( bv, "modrdn" );
532 1.1 lukem return 0;
533 1.1 lukem case LDAP_REQ_MODIFY:
534 1.1 lukem BER_BVSTR( bv, "modify" );
535 1.1 lukem return 0;
536 1.1 lukem case LDAP_REQ_COMPARE:
537 1.1 lukem BER_BVSTR( bv, "compare" );
538 1.1 lukem return 0;
539 1.1 lukem case LDAP_REQ_SEARCH:
540 1.1 lukem BER_BVSTR( bv, "search" );
541 1.1 lukem return 0;
542 1.1 lukem case LDAP_REQ_EXTENDED:
543 1.1 lukem BER_BVSTR( bv, "extended" );
544 1.1 lukem return 0;
545 1.1 lukem }
546 1.1 lukem return -1;
547 1.1 lukem }
548 1.1 lukem
549 1.1 lukem static int
550 1.1 lukem retcode_entry_response( Operation *op, SlapReply *rs, BackendInfo *bi, Entry *e )
551 1.1 lukem {
552 1.1 lukem Attribute *a;
553 1.1 lukem int err;
554 1.1 lukem char *next;
555 1.1 lukem int disconnect = 0;
556 1.1 lukem
557 1.1 lukem if ( get_manageDSAit( op ) ) {
558 1.1 lukem return SLAP_CB_CONTINUE;
559 1.1 lukem }
560 1.1 lukem
561 1.1 lukem if ( !is_entry_objectclass_or_sub( e, oc_errAbsObject ) ) {
562 1.1 lukem return SLAP_CB_CONTINUE;
563 1.1 lukem }
564 1.1 lukem
565 1.1 lukem /* operation */
566 1.1 lukem a = attr_find( e->e_attrs, ad_errOp );
567 1.1 lukem if ( a != NULL ) {
568 1.1 lukem int i,
569 1.1 lukem gotit = 0;
570 1.1 lukem struct berval bv = BER_BVNULL;
571 1.1 lukem
572 1.1 lukem (void)retcode_op2str( op->o_tag, &bv );
573 1.1 lukem
574 1.1 lukem if ( BER_BVISNULL( &bv ) ) {
575 1.1 lukem return SLAP_CB_CONTINUE;
576 1.1 lukem }
577 1.1 lukem
578 1.1 lukem for ( i = 0; !BER_BVISNULL( &a->a_nvals[ i ] ); i++ ) {
579 1.1 lukem if ( bvmatch( &a->a_nvals[ i ], &bv ) ) {
580 1.1 lukem gotit = 1;
581 1.1 lukem break;
582 1.1 lukem }
583 1.1 lukem }
584 1.1 lukem
585 1.1 lukem if ( !gotit ) {
586 1.1 lukem return SLAP_CB_CONTINUE;
587 1.1 lukem }
588 1.1 lukem }
589 1.1 lukem
590 1.1 lukem /* disconnect */
591 1.1 lukem a = attr_find( e->e_attrs, ad_errDisconnect );
592 1.1 lukem if ( a != NULL ) {
593 1.1 lukem if ( bvmatch( &a->a_nvals[ 0 ], &slap_true_bv ) ) {
594 1.1 lukem return rs->sr_err = SLAPD_DISCONNECT;
595 1.1 lukem }
596 1.1 lukem disconnect = 1;
597 1.1 lukem }
598 1.1 lukem
599 1.1 lukem /* error code */
600 1.1 lukem a = attr_find( e->e_attrs, ad_errCode );
601 1.1 lukem if ( a == NULL ) {
602 1.1 lukem return SLAP_CB_CONTINUE;
603 1.1 lukem }
604 1.1 lukem err = strtol( a->a_nvals[ 0 ].bv_val, &next, 0 );
605 1.1 lukem if ( next == a->a_nvals[ 0 ].bv_val || next[ 0 ] != '\0' ) {
606 1.1 lukem return SLAP_CB_CONTINUE;
607 1.1 lukem }
608 1.1 lukem rs->sr_err = err;
609 1.1 lukem
610 1.1 lukem /* sleep time */
611 1.1 lukem a = attr_find( e->e_attrs, ad_errSleepTime );
612 1.1 lukem if ( a != NULL && a->a_nvals[ 0 ].bv_val[ 0 ] != '-' ) {
613 1.1 lukem int sleepTime;
614 1.1 lukem
615 1.1 lukem if ( lutil_atoi( &sleepTime, a->a_nvals[ 0 ].bv_val ) == 0 ) {
616 1.1 lukem retcode_sleep( sleepTime );
617 1.1 lukem }
618 1.1 lukem }
619 1.1 lukem
620 1.1 lukem if ( rs->sr_err != LDAP_SUCCESS && !LDAP_API_ERROR( rs->sr_err )) {
621 1.1 lukem BackendDB db = *op->o_bd,
622 1.1 lukem *o_bd = op->o_bd;
623 1.1 lukem void *o_callback = op->o_callback;
624 1.1 lukem
625 1.1 lukem /* message text */
626 1.1 lukem a = attr_find( e->e_attrs, ad_errText );
627 1.1 lukem if ( a != NULL ) {
628 1.1 lukem rs->sr_text = a->a_vals[ 0 ].bv_val;
629 1.1 lukem }
630 1.1 lukem
631 1.1 lukem /* matched DN */
632 1.1 lukem a = attr_find( e->e_attrs, ad_errMatchedDN );
633 1.1 lukem if ( a != NULL ) {
634 1.1 lukem rs->sr_matched = a->a_vals[ 0 ].bv_val;
635 1.1 lukem }
636 1.1 lukem
637 1.1 lukem if ( bi == NULL ) {
638 1.1 lukem slap_overinst *on = (slap_overinst *)op->o_bd->bd_info;
639 1.1 lukem
640 1.1 lukem bi = on->on_info->oi_orig;
641 1.1 lukem }
642 1.1 lukem
643 1.1 lukem db.bd_info = bi;
644 1.1 lukem op->o_bd = &db;
645 1.1 lukem op->o_callback = NULL;
646 1.1 lukem
647 1.1 lukem /* referral */
648 1.1 lukem if ( rs->sr_err == LDAP_REFERRAL ) {
649 1.1 lukem BerVarray refs = default_referral;
650 1.1 lukem
651 1.1 lukem a = attr_find( e->e_attrs, slap_schema.si_ad_ref );
652 1.1 lukem if ( a != NULL ) {
653 1.1 lukem refs = a->a_vals;
654 1.1 lukem }
655 1.1 lukem rs->sr_ref = referral_rewrite( refs,
656 1.1 lukem NULL, &op->o_req_dn, op->oq_search.rs_scope );
657 1.1 lukem
658 1.1 lukem send_search_reference( op, rs );
659 1.1 lukem ber_bvarray_free( rs->sr_ref );
660 1.1 lukem rs->sr_ref = NULL;
661 1.1 lukem
662 1.1 lukem } else {
663 1.1 lukem a = attr_find( e->e_attrs, ad_errUnsolicitedOID );
664 1.1 lukem if ( a != NULL ) {
665 1.1 lukem struct berval oid = BER_BVNULL,
666 1.1 lukem data = BER_BVNULL;
667 1.1 lukem ber_int_t msgid = op->o_msgid;
668 1.1 lukem
669 1.1 lukem /* RFC 4511 unsolicited response */
670 1.1 lukem
671 1.1 lukem op->o_msgid = 0;
672 1.1 lukem
673 1.1 lukem oid = a->a_nvals[ 0 ];
674 1.1 lukem
675 1.1 lukem a = attr_find( e->e_attrs, ad_errUnsolicitedData );
676 1.1 lukem if ( a != NULL ) {
677 1.1 lukem data = a->a_nvals[ 0 ];
678 1.1 lukem }
679 1.1 lukem
680 1.1 lukem if ( strcmp( oid.bv_val, "0" ) == 0 ) {
681 1.1 lukem send_ldap_result( op, rs );
682 1.1 lukem
683 1.1 lukem } else {
684 1.1 lukem ber_tag_t tag = op->o_tag;
685 1.1 lukem
686 1.1 lukem op->o_tag = LDAP_REQ_EXTENDED;
687 1.1 lukem rs->sr_rspoid = oid.bv_val;
688 1.1 lukem if ( !BER_BVISNULL( &data ) ) {
689 1.1 lukem rs->sr_rspdata = &data;
690 1.1 lukem }
691 1.1 lukem send_ldap_extended( op, rs );
692 1.1 lukem rs->sr_rspoid = NULL;
693 1.1 lukem rs->sr_rspdata = NULL;
694 1.1 lukem op->o_tag = tag;
695 1.1 lukem }
696 1.1 lukem op->o_msgid = msgid;
697 1.1 lukem
698 1.1 lukem } else {
699 1.1 lukem send_ldap_result( op, rs );
700 1.1 lukem }
701 1.1 lukem }
702 1.1 lukem
703 1.1 lukem rs->sr_text = NULL;
704 1.1 lukem rs->sr_matched = NULL;
705 1.1 lukem op->o_bd = o_bd;
706 1.1 lukem op->o_callback = o_callback;
707 1.1 lukem }
708 1.1 lukem
709 1.1 lukem if ( rs->sr_err != LDAP_SUCCESS ) {
710 1.1 lukem if ( disconnect ) {
711 1.1 lukem return rs->sr_err = SLAPD_DISCONNECT;
712 1.1 lukem }
713 1.1 lukem
714 1.1 lukem op->o_abandon = 1;
715 1.1 lukem return rs->sr_err;
716 1.1 lukem }
717 1.1 lukem
718 1.1 lukem return SLAP_CB_CONTINUE;
719 1.1 lukem }
720 1.1 lukem
721 1.1 lukem static int
722 1.1 lukem retcode_response( Operation *op, SlapReply *rs )
723 1.1 lukem {
724 1.1 lukem slap_overinst *on = (slap_overinst *)op->o_bd->bd_info;
725 1.1 lukem retcode_t *rd = (retcode_t *)on->on_bi.bi_private;
726 1.1 lukem
727 1.1 lukem if ( rs->sr_type != REP_SEARCH || !RETCODE_INDIR( rd ) ) {
728 1.1 lukem return SLAP_CB_CONTINUE;
729 1.1 lukem }
730 1.1 lukem
731 1.1 lukem return retcode_entry_response( op, rs, NULL, rs->sr_entry );
732 1.1 lukem }
733 1.1 lukem
734 1.1 lukem static int
735 1.1 lukem retcode_db_init( BackendDB *be, ConfigReply *cr )
736 1.1 lukem {
737 1.1 lukem slap_overinst *on = (slap_overinst *)be->bd_info;
738 1.1 lukem retcode_t *rd;
739 1.1 lukem
740 1.1 lukem srand( getpid() );
741 1.1 lukem
742 1.1 lukem rd = (retcode_t *)ch_malloc( sizeof( retcode_t ) );
743 1.1 lukem memset( rd, 0, sizeof( retcode_t ) );
744 1.1 lukem
745 1.1 lukem on->on_bi.bi_private = (void *)rd;
746 1.1 lukem
747 1.1 lukem return 0;
748 1.1 lukem }
749 1.1 lukem
750 1.1.1.2 lukem static void
751 1.1.1.2 lukem retcode_item_destroy( retcode_item_t *rdi )
752 1.1 lukem {
753 1.1.1.2 lukem ber_memfree( rdi->rdi_line.bv_val );
754 1.1 lukem
755 1.1.1.2 lukem ber_memfree( rdi->rdi_dn.bv_val );
756 1.1.1.2 lukem ber_memfree( rdi->rdi_ndn.bv_val );
757 1.1 lukem
758 1.1.1.2 lukem if ( !BER_BVISNULL( &rdi->rdi_text ) ) {
759 1.1.1.2 lukem ber_memfree( rdi->rdi_text.bv_val );
760 1.1 lukem }
761 1.1 lukem
762 1.1.1.2 lukem if ( !BER_BVISNULL( &rdi->rdi_matched ) ) {
763 1.1.1.2 lukem ber_memfree( rdi->rdi_matched.bv_val );
764 1.1.1.2 lukem }
765 1.1 lukem
766 1.1.1.2 lukem if ( rdi->rdi_ref ) {
767 1.1.1.2 lukem ber_bvarray_free( rdi->rdi_ref );
768 1.1.1.2 lukem }
769 1.1 lukem
770 1.1.1.2 lukem BER_BVZERO( &rdi->rdi_e.e_name );
771 1.1.1.2 lukem BER_BVZERO( &rdi->rdi_e.e_nname );
772 1.1.1.2 lukem
773 1.1.1.2 lukem entry_clean( &rdi->rdi_e );
774 1.1.1.2 lukem
775 1.1.1.2 lukem ch_free( rdi );
776 1.1.1.2 lukem }
777 1.1.1.2 lukem
778 1.1.1.2 lukem enum {
779 1.1.1.2 lukem RC_PARENT = 1,
780 1.1.1.2 lukem RC_ITEM
781 1.1.1.2 lukem };
782 1.1.1.2 lukem
783 1.1.1.2 lukem static ConfigDriver rc_cf_gen;
784 1.1.1.2 lukem
785 1.1.1.2 lukem static ConfigTable rccfg[] = {
786 1.1.1.2 lukem { "retcode-parent", "dn",
787 1.1.1.2 lukem 2, 2, 0, ARG_MAGIC|ARG_DN|RC_PARENT, rc_cf_gen,
788 1.1.1.2 lukem "( OLcfgOvAt:20.1 NAME 'olcRetcodeParent' "
789 1.1.1.2 lukem "DESC '' "
790 1.1.1.2 lukem "SYNTAX OMsDN SINGLE-VALUE )", NULL, NULL },
791 1.1.1.2 lukem { "retcode-item", "rdn> <retcode> <...",
792 1.1.1.2 lukem 3, 0, 0, ARG_MAGIC|RC_ITEM, rc_cf_gen,
793 1.1.1.2 lukem "( OLcfgOvAt:20.2 NAME 'olcRetcodeItem' "
794 1.1.1.2 lukem "DESC '' "
795 1.1.1.2 lukem "EQUALITY caseIgnoreMatch "
796 1.1.1.2 lukem "SYNTAX OMsDirectoryString "
797 1.1.1.2 lukem "X-ORDERED 'VALUES' )", NULL, NULL },
798 1.1.1.2 lukem { "retcode-indir", "on|off",
799 1.1.1.2 lukem 1, 2, 0, ARG_OFFSET|ARG_ON_OFF,
800 1.1.1.2 lukem (void *)offsetof(retcode_t, rd_indir),
801 1.1.1.2 lukem "( OLcfgOvAt:20.3 NAME 'olcRetcodeInDir' "
802 1.1.1.2 lukem "DESC '' "
803 1.1.1.2 lukem "SYNTAX OMsBoolean SINGLE-VALUE )", NULL, NULL },
804 1.1.1.2 lukem
805 1.1.1.2 lukem { "retcode-sleep", "sleeptime",
806 1.1.1.2 lukem 2, 2, 0, ARG_OFFSET|ARG_INT,
807 1.1.1.2 lukem (void *)offsetof(retcode_t, rd_sleep),
808 1.1.1.2 lukem "( OLcfgOvAt:20.4 NAME 'olcRetcodeSleep' "
809 1.1.1.2 lukem "DESC '' "
810 1.1.1.2 lukem "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
811 1.1.1.2 lukem
812 1.1.1.2 lukem { NULL, NULL, 0, 0, 0, ARG_IGNORED }
813 1.1.1.2 lukem };
814 1.1.1.2 lukem
815 1.1.1.2 lukem static ConfigOCs rcocs[] = {
816 1.1.1.2 lukem { "( OLcfgOvOc:20.1 "
817 1.1.1.2 lukem "NAME 'olcRetcodeConfig' "
818 1.1.1.2 lukem "DESC 'Retcode configuration' "
819 1.1.1.2 lukem "SUP olcOverlayConfig "
820 1.1.1.2 lukem "MAY ( olcRetcodeParent "
821 1.1.1.2 lukem "$ olcRetcodeItem "
822 1.1.1.2 lukem "$ olcRetcodeInDir "
823 1.1.1.2 lukem "$ olcRetcodeSleep "
824 1.1.1.2 lukem ") )",
825 1.1.1.2 lukem Cft_Overlay, rccfg, NULL, NULL },
826 1.1.1.2 lukem { NULL, 0, NULL }
827 1.1.1.2 lukem };
828 1.1.1.2 lukem
829 1.1.1.2 lukem static int
830 1.1.1.2 lukem rc_cf_gen( ConfigArgs *c )
831 1.1.1.2 lukem {
832 1.1.1.2 lukem slap_overinst *on = (slap_overinst *)c->bi;
833 1.1.1.2 lukem retcode_t *rd = (retcode_t *)on->on_bi.bi_private;
834 1.1.1.2 lukem int rc = ARG_BAD_CONF;
835 1.1.1.2 lukem
836 1.1.1.2 lukem if ( c->op == SLAP_CONFIG_EMIT ) {
837 1.1.1.2 lukem switch( c->type ) {
838 1.1.1.2 lukem case RC_PARENT:
839 1.1.1.2 lukem if ( !BER_BVISEMPTY( &rd->rd_pdn )) {
840 1.1.1.2 lukem rc = value_add_one( &c->rvalue_vals,
841 1.1.1.2 lukem &rd->rd_pdn );
842 1.1.1.2 lukem if ( rc == 0 ) {
843 1.1.1.2 lukem rc = value_add_one( &c->rvalue_nvals,
844 1.1.1.2 lukem &rd->rd_npdn );
845 1.1.1.2 lukem }
846 1.1.1.2 lukem return rc;
847 1.1.1.2 lukem }
848 1.1.1.2 lukem rc = 0;
849 1.1.1.2 lukem break;
850 1.1.1.2 lukem
851 1.1.1.2 lukem case RC_ITEM: {
852 1.1.1.2 lukem retcode_item_t *rdi;
853 1.1.1.2 lukem int i;
854 1.1.1.2 lukem
855 1.1.1.2 lukem for ( rdi = rd->rd_item, i = 0; rdi; rdi = rdi->rdi_next, i++ ) {
856 1.1.1.2 lukem char buf[4096];
857 1.1.1.2 lukem struct berval bv;
858 1.1.1.2 lukem char *ptr;
859 1.1.1.2 lukem
860 1.1.1.2 lukem bv.bv_len = snprintf( buf, sizeof( buf ), SLAP_X_ORDERED_FMT, i );
861 1.1.1.2 lukem bv.bv_len += rdi->rdi_line.bv_len;
862 1.1.1.2 lukem ptr = bv.bv_val = ch_malloc( bv.bv_len + 1 );
863 1.1.1.2 lukem ptr = lutil_strcopy( ptr, buf );
864 1.1.1.2 lukem ptr = lutil_strncopy( ptr, rdi->rdi_line.bv_val, rdi->rdi_line.bv_len );
865 1.1.1.2 lukem ber_bvarray_add( &c->rvalue_vals, &bv );
866 1.1.1.2 lukem }
867 1.1.1.2 lukem rc = 0;
868 1.1.1.2 lukem } break;
869 1.1.1.2 lukem
870 1.1.1.2 lukem default:
871 1.1.1.2 lukem assert( 0 );
872 1.1.1.2 lukem break;
873 1.1 lukem }
874 1.1 lukem
875 1.1.1.2 lukem return rc;
876 1.1 lukem
877 1.1.1.2 lukem } else if ( c->op == LDAP_MOD_DELETE ) {
878 1.1.1.2 lukem switch( c->type ) {
879 1.1.1.2 lukem case RC_PARENT:
880 1.1.1.2 lukem if ( rd->rd_pdn.bv_val ) {
881 1.1.1.2 lukem ber_memfree ( rd->rd_pdn.bv_val );
882 1.1.1.2 lukem rc = 0;
883 1.1.1.2 lukem }
884 1.1.1.2 lukem if ( rd->rd_npdn.bv_val ) {
885 1.1.1.2 lukem ber_memfree ( rd->rd_npdn.bv_val );
886 1.1.1.2 lukem }
887 1.1.1.2 lukem break;
888 1.1.1.2 lukem
889 1.1.1.2 lukem case RC_ITEM:
890 1.1.1.2 lukem if ( c->valx == -1 ) {
891 1.1.1.2 lukem retcode_item_t *rdi, *next;
892 1.1.1.2 lukem
893 1.1.1.2 lukem for ( rdi = rd->rd_item; rdi != NULL; rdi = next ) {
894 1.1.1.2 lukem next = rdi->rdi_next;
895 1.1.1.2 lukem retcode_item_destroy( rdi );
896 1.1.1.2 lukem }
897 1.1.1.2 lukem
898 1.1.1.2 lukem } else {
899 1.1.1.2 lukem retcode_item_t **rdip, *rdi;
900 1.1.1.2 lukem int i;
901 1.1.1.2 lukem
902 1.1.1.2 lukem for ( rdip = &rd->rd_item, i = 0; i <= c->valx && *rdip; i++, rdip = &(*rdip)->rdi_next )
903 1.1.1.2 lukem ;
904 1.1.1.2 lukem if ( *rdip == NULL ) {
905 1.1.1.2 lukem return 1;
906 1.1.1.2 lukem }
907 1.1.1.2 lukem rdi = *rdip;
908 1.1.1.2 lukem *rdip = rdi->rdi_next;
909 1.1.1.2 lukem
910 1.1.1.2 lukem retcode_item_destroy( rdi );
911 1.1.1.2 lukem }
912 1.1.1.2 lukem rc = 0;
913 1.1.1.2 lukem break;
914 1.1.1.2 lukem
915 1.1.1.2 lukem default:
916 1.1.1.2 lukem assert( 0 );
917 1.1.1.2 lukem break;
918 1.1 lukem }
919 1.1.1.2 lukem return rc; /* FIXME */
920 1.1.1.2 lukem }
921 1.1.1.2 lukem
922 1.1.1.2 lukem switch( c->type ) {
923 1.1.1.2 lukem case RC_PARENT:
924 1.1.1.2 lukem if ( rd->rd_pdn.bv_val ) {
925 1.1.1.2 lukem ber_memfree ( rd->rd_pdn.bv_val );
926 1.1.1.2 lukem }
927 1.1.1.2 lukem if ( rd->rd_npdn.bv_val ) {
928 1.1.1.2 lukem ber_memfree ( rd->rd_npdn.bv_val );
929 1.1.1.2 lukem }
930 1.1.1.2 lukem rd->rd_pdn = c->value_dn;
931 1.1.1.2 lukem rd->rd_npdn = c->value_ndn;
932 1.1.1.2 lukem rc = 0;
933 1.1.1.2 lukem break;
934 1.1 lukem
935 1.1.1.2 lukem case RC_ITEM: {
936 1.1 lukem retcode_item_t rdi = { BER_BVNULL }, **rdip;
937 1.1 lukem struct berval bv, rdn, nrdn;
938 1.1 lukem char *next = NULL;
939 1.1.1.2 lukem int i;
940 1.1 lukem
941 1.1.1.2 lukem if ( c->argc < 3 ) {
942 1.1.1.2 lukem snprintf( c->cr_msg, sizeof(c->cr_msg),
943 1.1 lukem "\"retcode-item <RDN> <retcode> [<text>]\": "
944 1.1.1.2 lukem "missing args" );
945 1.1.1.2 lukem Debug( LDAP_DEBUG_CONFIG, "%s: retcode: %s\n",
946 1.1.1.2 lukem c->log, c->cr_msg, 0 );
947 1.1.1.2 lukem return ARG_BAD_CONF;
948 1.1 lukem }
949 1.1 lukem
950 1.1.1.2 lukem ber_str2bv( c->argv[ 1 ], 0, 0, &bv );
951 1.1 lukem
952 1.1 lukem rc = dnPrettyNormal( NULL, &bv, &rdn, &nrdn, NULL );
953 1.1 lukem if ( rc != LDAP_SUCCESS ) {
954 1.1.1.2 lukem snprintf( c->cr_msg, sizeof(c->cr_msg),
955 1.1.1.2 lukem "unable to normalize RDN \"%s\": %d",
956 1.1.1.2 lukem c->argv[ 1 ], rc );
957 1.1.1.2 lukem Debug( LDAP_DEBUG_CONFIG, "%s: retcode: %s\n",
958 1.1.1.2 lukem c->log, c->cr_msg, 0 );
959 1.1.1.2 lukem return ARG_BAD_CONF;
960 1.1 lukem }
961 1.1 lukem
962 1.1 lukem if ( !dnIsOneLevelRDN( &nrdn ) ) {
963 1.1.1.2 lukem snprintf( c->cr_msg, sizeof(c->cr_msg),
964 1.1.1.2 lukem "value \"%s\" is not a RDN",
965 1.1.1.2 lukem c->argv[ 1 ] );
966 1.1.1.2 lukem Debug( LDAP_DEBUG_CONFIG, "%s: retcode: %s\n",
967 1.1.1.2 lukem c->log, c->cr_msg, 0 );
968 1.1.1.2 lukem return ARG_BAD_CONF;
969 1.1 lukem }
970 1.1 lukem
971 1.1 lukem if ( BER_BVISNULL( &rd->rd_npdn ) ) {
972 1.1 lukem /* FIXME: we use the database suffix */
973 1.1.1.2 lukem if ( c->be->be_nsuffix == NULL ) {
974 1.1.1.2 lukem snprintf( c->cr_msg, sizeof(c->cr_msg),
975 1.1 lukem "either \"retcode-parent\" "
976 1.1.1.2 lukem "or \"suffix\" must be defined" );
977 1.1.1.2 lukem Debug( LDAP_DEBUG_CONFIG, "%s: retcode: %s\n",
978 1.1.1.2 lukem c->log, c->cr_msg, 0 );
979 1.1.1.2 lukem return ARG_BAD_CONF;
980 1.1 lukem }
981 1.1 lukem
982 1.1.1.2 lukem ber_dupbv( &rd->rd_pdn, &c->be->be_suffix[ 0 ] );
983 1.1.1.2 lukem ber_dupbv( &rd->rd_npdn, &c->be->be_nsuffix[ 0 ] );
984 1.1 lukem }
985 1.1 lukem
986 1.1 lukem build_new_dn( &rdi.rdi_dn, &rd->rd_pdn, &rdn, NULL );
987 1.1 lukem build_new_dn( &rdi.rdi_ndn, &rd->rd_npdn, &nrdn, NULL );
988 1.1 lukem
989 1.1 lukem ch_free( rdn.bv_val );
990 1.1 lukem ch_free( nrdn.bv_val );
991 1.1 lukem
992 1.1.1.2 lukem rdi.rdi_err = strtol( c->argv[ 2 ], &next, 0 );
993 1.1.1.2 lukem if ( next == c->argv[ 2 ] || next[ 0 ] != '\0' ) {
994 1.1.1.2 lukem snprintf( c->cr_msg, sizeof(c->cr_msg),
995 1.1.1.2 lukem "unable to parse return code \"%s\"",
996 1.1.1.2 lukem c->argv[ 2 ] );
997 1.1.1.2 lukem Debug( LDAP_DEBUG_CONFIG, "%s: retcode: %s\n",
998 1.1.1.2 lukem c->log, c->cr_msg, 0 );
999 1.1.1.2 lukem return ARG_BAD_CONF;
1000 1.1 lukem }
1001 1.1 lukem
1002 1.1 lukem rdi.rdi_mask = SN_DG_OP_ALL;
1003 1.1 lukem
1004 1.1.1.2 lukem if ( c->argc > 3 ) {
1005 1.1.1.2 lukem for ( i = 3; i < c->argc; i++ ) {
1006 1.1.1.2 lukem if ( strncasecmp( c->argv[ i ], "op=", STRLENOF( "op=" ) ) == 0 )
1007 1.1 lukem {
1008 1.1 lukem char **ops;
1009 1.1 lukem int j;
1010 1.1 lukem
1011 1.1.1.2 lukem ops = ldap_str2charray( &c->argv[ i ][ STRLENOF( "op=" ) ], "," );
1012 1.1 lukem assert( ops != NULL );
1013 1.1 lukem
1014 1.1 lukem rdi.rdi_mask = SN_DG_OP_NONE;
1015 1.1 lukem
1016 1.1 lukem for ( j = 0; ops[ j ] != NULL; j++ ) {
1017 1.1 lukem if ( strcasecmp( ops[ j ], "add" ) == 0 ) {
1018 1.1 lukem rdi.rdi_mask |= SN_DG_OP_ADD;
1019 1.1 lukem
1020 1.1 lukem } else if ( strcasecmp( ops[ j ], "bind" ) == 0 ) {
1021 1.1 lukem rdi.rdi_mask |= SN_DG_OP_BIND;
1022 1.1 lukem
1023 1.1 lukem } else if ( strcasecmp( ops[ j ], "compare" ) == 0 ) {
1024 1.1 lukem rdi.rdi_mask |= SN_DG_OP_COMPARE;
1025 1.1 lukem
1026 1.1 lukem } else if ( strcasecmp( ops[ j ], "delete" ) == 0 ) {
1027 1.1 lukem rdi.rdi_mask |= SN_DG_OP_DELETE;
1028 1.1 lukem
1029 1.1 lukem } else if ( strcasecmp( ops[ j ], "modify" ) == 0 ) {
1030 1.1 lukem rdi.rdi_mask |= SN_DG_OP_MODIFY;
1031 1.1 lukem
1032 1.1 lukem } else if ( strcasecmp( ops[ j ], "rename" ) == 0
1033 1.1 lukem || strcasecmp( ops[ j ], "modrdn" ) == 0 )
1034 1.1 lukem {
1035 1.1 lukem rdi.rdi_mask |= SN_DG_OP_RENAME;
1036 1.1 lukem
1037 1.1 lukem } else if ( strcasecmp( ops[ j ], "search" ) == 0 ) {
1038 1.1 lukem rdi.rdi_mask |= SN_DG_OP_SEARCH;
1039 1.1 lukem
1040 1.1 lukem } else if ( strcasecmp( ops[ j ], "extended" ) == 0 ) {
1041 1.1 lukem rdi.rdi_mask |= SN_DG_EXTENDED;
1042 1.1 lukem
1043 1.1 lukem } else if ( strcasecmp( ops[ j ], "auth" ) == 0 ) {
1044 1.1 lukem rdi.rdi_mask |= SN_DG_OP_AUTH;
1045 1.1 lukem
1046 1.1 lukem } else if ( strcasecmp( ops[ j ], "read" ) == 0 ) {
1047 1.1 lukem rdi.rdi_mask |= SN_DG_OP_READ;
1048 1.1 lukem
1049 1.1 lukem } else if ( strcasecmp( ops[ j ], "write" ) == 0 ) {
1050 1.1 lukem rdi.rdi_mask |= SN_DG_OP_WRITE;
1051 1.1 lukem
1052 1.1 lukem } else if ( strcasecmp( ops[ j ], "all" ) == 0 ) {
1053 1.1 lukem rdi.rdi_mask |= SN_DG_OP_ALL;
1054 1.1 lukem
1055 1.1 lukem } else {
1056 1.1.1.2 lukem snprintf( c->cr_msg, sizeof(c->cr_msg),
1057 1.1.1.2 lukem "unknown op \"%s\"",
1058 1.1 lukem ops[ j ] );
1059 1.1 lukem ldap_charray_free( ops );
1060 1.1.1.2 lukem Debug( LDAP_DEBUG_CONFIG, "%s: retcode: %s\n",
1061 1.1.1.2 lukem c->log, c->cr_msg, 0 );
1062 1.1.1.2 lukem return ARG_BAD_CONF;
1063 1.1 lukem }
1064 1.1 lukem }
1065 1.1 lukem
1066 1.1 lukem ldap_charray_free( ops );
1067 1.1 lukem
1068 1.1.1.2 lukem } else if ( strncasecmp( c->argv[ i ], "text=", STRLENOF( "text=" ) ) == 0 )
1069 1.1 lukem {
1070 1.1 lukem if ( !BER_BVISNULL( &rdi.rdi_text ) ) {
1071 1.1.1.2 lukem snprintf( c->cr_msg, sizeof(c->cr_msg),
1072 1.1.1.2 lukem "\"text\" already provided" );
1073 1.1.1.2 lukem Debug( LDAP_DEBUG_CONFIG, "%s: retcode: %s\n",
1074 1.1.1.2 lukem c->log, c->cr_msg, 0 );
1075 1.1.1.2 lukem return ARG_BAD_CONF;
1076 1.1 lukem }
1077 1.1.1.2 lukem ber_str2bv( &c->argv[ i ][ STRLENOF( "text=" ) ], 0, 1, &rdi.rdi_text );
1078 1.1 lukem
1079 1.1.1.2 lukem } else if ( strncasecmp( c->argv[ i ], "matched=", STRLENOF( "matched=" ) ) == 0 )
1080 1.1 lukem {
1081 1.1 lukem struct berval dn;
1082 1.1 lukem
1083 1.1 lukem if ( !BER_BVISNULL( &rdi.rdi_matched ) ) {
1084 1.1.1.2 lukem snprintf( c->cr_msg, sizeof(c->cr_msg),
1085 1.1.1.2 lukem "\"matched\" already provided" );
1086 1.1.1.2 lukem Debug( LDAP_DEBUG_CONFIG, "%s: retcode: %s\n",
1087 1.1.1.2 lukem c->log, c->cr_msg, 0 );
1088 1.1.1.2 lukem return ARG_BAD_CONF;
1089 1.1 lukem }
1090 1.1.1.2 lukem ber_str2bv( &c->argv[ i ][ STRLENOF( "matched=" ) ], 0, 0, &dn );
1091 1.1 lukem if ( dnPretty( NULL, &dn, &rdi.rdi_matched, NULL ) != LDAP_SUCCESS ) {
1092 1.1.1.2 lukem snprintf( c->cr_msg, sizeof(c->cr_msg),
1093 1.1.1.2 lukem "unable to prettify matched DN \"%s\"",
1094 1.1.1.2 lukem &c->argv[ i ][ STRLENOF( "matched=" ) ] );
1095 1.1.1.2 lukem Debug( LDAP_DEBUG_CONFIG, "%s: retcode: %s\n",
1096 1.1.1.2 lukem c->log, c->cr_msg, 0 );
1097 1.1.1.2 lukem return ARG_BAD_CONF;
1098 1.1 lukem }
1099 1.1 lukem
1100 1.1.1.2 lukem } else if ( strncasecmp( c->argv[ i ], "ref=", STRLENOF( "ref=" ) ) == 0 )
1101 1.1 lukem {
1102 1.1 lukem char **refs;
1103 1.1 lukem int j;
1104 1.1 lukem
1105 1.1 lukem if ( rdi.rdi_ref != NULL ) {
1106 1.1.1.2 lukem snprintf( c->cr_msg, sizeof(c->cr_msg),
1107 1.1.1.2 lukem "\"ref\" already provided" );
1108 1.1.1.2 lukem Debug( LDAP_DEBUG_CONFIG, "%s: retcode: %s\n",
1109 1.1.1.2 lukem c->log, c->cr_msg, 0 );
1110 1.1.1.2 lukem return ARG_BAD_CONF;
1111 1.1 lukem }
1112 1.1 lukem
1113 1.1 lukem if ( rdi.rdi_err != LDAP_REFERRAL ) {
1114 1.1.1.2 lukem snprintf( c->cr_msg, sizeof(c->cr_msg),
1115 1.1.1.2 lukem "providing \"ref\" "
1116 1.1.1.2 lukem "along with a non-referral "
1117 1.1.1.2 lukem "resultCode may cause slapd failures "
1118 1.1.1.2 lukem "related to internal checks" );
1119 1.1.1.2 lukem Debug( LDAP_DEBUG_CONFIG, "%s: retcode: %s\n",
1120 1.1.1.2 lukem c->log, c->cr_msg, 0 );
1121 1.1 lukem }
1122 1.1 lukem
1123 1.1.1.2 lukem refs = ldap_str2charray( &c->argv[ i ][ STRLENOF( "ref=" ) ], " " );
1124 1.1 lukem assert( refs != NULL );
1125 1.1 lukem
1126 1.1 lukem for ( j = 0; refs[ j ] != NULL; j++ ) {
1127 1.1 lukem struct berval bv;
1128 1.1 lukem
1129 1.1 lukem ber_str2bv( refs[ j ], 0, 1, &bv );
1130 1.1 lukem ber_bvarray_add( &rdi.rdi_ref, &bv );
1131 1.1 lukem }
1132 1.1 lukem
1133 1.1 lukem ldap_charray_free( refs );
1134 1.1 lukem
1135 1.1.1.2 lukem } else if ( strncasecmp( c->argv[ i ], "sleeptime=", STRLENOF( "sleeptime=" ) ) == 0 )
1136 1.1 lukem {
1137 1.1 lukem if ( rdi.rdi_sleeptime != 0 ) {
1138 1.1.1.2 lukem snprintf( c->cr_msg, sizeof(c->cr_msg),
1139 1.1.1.2 lukem "\"sleeptime\" already provided" );
1140 1.1.1.2 lukem Debug( LDAP_DEBUG_CONFIG, "%s: retcode: %s\n",
1141 1.1.1.2 lukem c->log, c->cr_msg, 0 );
1142 1.1.1.2 lukem return ARG_BAD_CONF;
1143 1.1 lukem }
1144 1.1 lukem
1145 1.1.1.2 lukem if ( lutil_atoi( &rdi.rdi_sleeptime, &c->argv[ i ][ STRLENOF( "sleeptime=" ) ] ) ) {
1146 1.1.1.2 lukem snprintf( c->cr_msg, sizeof(c->cr_msg),
1147 1.1.1.2 lukem "unable to parse \"sleeptime=%s\"",
1148 1.1.1.2 lukem &c->argv[ i ][ STRLENOF( "sleeptime=" ) ] );
1149 1.1.1.2 lukem Debug( LDAP_DEBUG_CONFIG, "%s: retcode: %s\n",
1150 1.1.1.2 lukem c->log, c->cr_msg, 0 );
1151 1.1.1.2 lukem return ARG_BAD_CONF;
1152 1.1 lukem }
1153 1.1 lukem
1154 1.1.1.2 lukem } else if ( strncasecmp( c->argv[ i ], "unsolicited=", STRLENOF( "unsolicited=" ) ) == 0 )
1155 1.1 lukem {
1156 1.1 lukem char *data;
1157 1.1 lukem
1158 1.1 lukem if ( !BER_BVISNULL( &rdi.rdi_unsolicited_oid ) ) {
1159 1.1.1.2 lukem snprintf( c->cr_msg, sizeof(c->cr_msg),
1160 1.1.1.2 lukem "\"unsolicited\" already provided" );
1161 1.1.1.2 lukem Debug( LDAP_DEBUG_CONFIG, "%s: retcode: %s\n",
1162 1.1.1.2 lukem c->log, c->cr_msg, 0 );
1163 1.1.1.2 lukem return ARG_BAD_CONF;
1164 1.1 lukem }
1165 1.1 lukem
1166 1.1.1.2 lukem data = strchr( &c->argv[ i ][ STRLENOF( "unsolicited=" ) ], ':' );
1167 1.1 lukem if ( data != NULL ) {
1168 1.1 lukem struct berval oid;
1169 1.1 lukem
1170 1.1.1.2 lukem if ( ldif_parse_line2( &c->argv[ i ][ STRLENOF( "unsolicited=" ) ],
1171 1.1 lukem &oid, &rdi.rdi_unsolicited_data, NULL ) )
1172 1.1 lukem {
1173 1.1.1.2 lukem snprintf( c->cr_msg, sizeof(c->cr_msg),
1174 1.1.1.2 lukem "unable to parse \"unsolicited\"" );
1175 1.1.1.2 lukem Debug( LDAP_DEBUG_CONFIG, "%s: retcode: %s\n",
1176 1.1.1.2 lukem c->log, c->cr_msg, 0 );
1177 1.1.1.2 lukem return ARG_BAD_CONF;
1178 1.1 lukem }
1179 1.1 lukem
1180 1.1 lukem ber_dupbv( &rdi.rdi_unsolicited_oid, &oid );
1181 1.1 lukem
1182 1.1 lukem } else {
1183 1.1.1.2 lukem ber_str2bv( &c->argv[ i ][ STRLENOF( "unsolicited=" ) ], 0, 1,
1184 1.1 lukem &rdi.rdi_unsolicited_oid );
1185 1.1 lukem }
1186 1.1 lukem
1187 1.1.1.2 lukem } else if ( strncasecmp( c->argv[ i ], "flags=", STRLENOF( "flags=" ) ) == 0 )
1188 1.1 lukem {
1189 1.1.1.2 lukem char *arg = &c->argv[ i ][ STRLENOF( "flags=" ) ];
1190 1.1 lukem if ( strcasecmp( arg, "disconnect" ) == 0 ) {
1191 1.1 lukem rdi.rdi_flags |= RDI_PRE_DISCONNECT;
1192 1.1 lukem
1193 1.1 lukem } else if ( strcasecmp( arg, "pre-disconnect" ) == 0 ) {
1194 1.1 lukem rdi.rdi_flags |= RDI_PRE_DISCONNECT;
1195 1.1 lukem
1196 1.1 lukem } else if ( strcasecmp( arg, "post-disconnect" ) == 0 ) {
1197 1.1 lukem rdi.rdi_flags |= RDI_POST_DISCONNECT;
1198 1.1 lukem
1199 1.1 lukem } else {
1200 1.1.1.2 lukem snprintf( c->cr_msg, sizeof(c->cr_msg),
1201 1.1.1.2 lukem "unknown flag \"%s\"", arg );
1202 1.1.1.2 lukem Debug( LDAP_DEBUG_CONFIG, "%s: retcode: %s\n",
1203 1.1.1.2 lukem c->log, c->cr_msg, 0 );
1204 1.1.1.2 lukem return ARG_BAD_CONF;
1205 1.1 lukem }
1206 1.1 lukem
1207 1.1 lukem } else {
1208 1.1.1.2 lukem snprintf( c->cr_msg, sizeof(c->cr_msg),
1209 1.1.1.2 lukem "unknown option \"%s\"",
1210 1.1.1.2 lukem c->argv[ i ] );
1211 1.1.1.2 lukem Debug( LDAP_DEBUG_CONFIG, "%s: retcode: %s\n",
1212 1.1.1.2 lukem c->log, c->cr_msg, 0 );
1213 1.1.1.2 lukem return ARG_BAD_CONF;
1214 1.1 lukem }
1215 1.1 lukem }
1216 1.1 lukem }
1217 1.1 lukem
1218 1.1.1.2 lukem rdi.rdi_line.bv_len = 2*(c->argc - 1) + c->argc - 2;
1219 1.1.1.2 lukem for ( i = 1; i < c->argc; i++ ) {
1220 1.1.1.2 lukem rdi.rdi_line.bv_len += strlen( c->argv[ i ] );
1221 1.1.1.2 lukem }
1222 1.1.1.2 lukem next = rdi.rdi_line.bv_val = ch_malloc( rdi.rdi_line.bv_len + 1 );
1223 1.1.1.2 lukem
1224 1.1.1.2 lukem for ( i = 1; i < c->argc; i++ ) {
1225 1.1.1.2 lukem *next++ = '"';
1226 1.1.1.2 lukem next = lutil_strcopy( next, c->argv[ i ] );
1227 1.1.1.2 lukem *next++ = '"';
1228 1.1.1.2 lukem *next++ = ' ';
1229 1.1.1.2 lukem }
1230 1.1.1.2 lukem *--next = '\0';
1231 1.1.1.2 lukem
1232 1.1 lukem for ( rdip = &rd->rd_item; *rdip; rdip = &(*rdip)->rdi_next )
1233 1.1 lukem /* go to last */ ;
1234 1.1 lukem
1235 1.1 lukem
1236 1.1 lukem *rdip = ( retcode_item_t * )ch_malloc( sizeof( retcode_item_t ) );
1237 1.1 lukem *(*rdip) = rdi;
1238 1.1 lukem
1239 1.1.1.2 lukem rc = 0;
1240 1.1.1.2 lukem } break;
1241 1.1 lukem
1242 1.1.1.2 lukem default:
1243 1.1.1.2 lukem rc = SLAP_CONF_UNKNOWN;
1244 1.1.1.2 lukem break;
1245 1.1 lukem }
1246 1.1 lukem
1247 1.1.1.2 lukem return rc;
1248 1.1 lukem }
1249 1.1 lukem
1250 1.1 lukem static int
1251 1.1 lukem retcode_db_open( BackendDB *be, ConfigReply *cr)
1252 1.1 lukem {
1253 1.1 lukem slap_overinst *on = (slap_overinst *)be->bd_info;
1254 1.1 lukem retcode_t *rd = (retcode_t *)on->on_bi.bi_private;
1255 1.1 lukem
1256 1.1 lukem retcode_item_t *rdi;
1257 1.1 lukem
1258 1.1 lukem for ( rdi = rd->rd_item; rdi; rdi = rdi->rdi_next ) {
1259 1.1 lukem LDAPRDN rdn = NULL;
1260 1.1 lukem int rc, j;
1261 1.1 lukem char* p;
1262 1.1 lukem struct berval val[ 3 ];
1263 1.1 lukem char buf[ SLAP_TEXT_BUFLEN ];
1264 1.1 lukem
1265 1.1 lukem /* DN */
1266 1.1 lukem rdi->rdi_e.e_name = rdi->rdi_dn;
1267 1.1 lukem rdi->rdi_e.e_nname = rdi->rdi_ndn;
1268 1.1 lukem
1269 1.1 lukem /* objectClass */
1270 1.1 lukem val[ 0 ] = oc_errObject->soc_cname;
1271 1.1 lukem val[ 1 ] = slap_schema.si_oc_extensibleObject->soc_cname;
1272 1.1 lukem BER_BVZERO( &val[ 2 ] );
1273 1.1 lukem
1274 1.1 lukem attr_merge( &rdi->rdi_e, slap_schema.si_ad_objectClass, val, NULL );
1275 1.1 lukem
1276 1.1 lukem /* RDN avas */
1277 1.1 lukem rc = ldap_bv2rdn( &rdi->rdi_dn, &rdn, (char **) &p,
1278 1.1 lukem LDAP_DN_FORMAT_LDAP );
1279 1.1 lukem
1280 1.1 lukem assert( rc == LDAP_SUCCESS );
1281 1.1 lukem
1282 1.1 lukem for ( j = 0; rdn[ j ]; j++ ) {
1283 1.1 lukem LDAPAVA *ava = rdn[ j ];
1284 1.1 lukem AttributeDescription *ad = NULL;
1285 1.1 lukem const char *text;
1286 1.1 lukem
1287 1.1 lukem rc = slap_bv2ad( &ava->la_attr, &ad, &text );
1288 1.1 lukem assert( rc == LDAP_SUCCESS );
1289 1.1 lukem
1290 1.1 lukem attr_merge_normalize_one( &rdi->rdi_e, ad,
1291 1.1 lukem &ava->la_value, NULL );
1292 1.1 lukem }
1293 1.1 lukem
1294 1.1 lukem ldap_rdnfree( rdn );
1295 1.1 lukem
1296 1.1 lukem /* error code */
1297 1.1 lukem snprintf( buf, sizeof( buf ), "%d", rdi->rdi_err );
1298 1.1 lukem ber_str2bv( buf, 0, 0, &val[ 0 ] );
1299 1.1 lukem
1300 1.1 lukem attr_merge_one( &rdi->rdi_e, ad_errCode, &val[ 0 ], NULL );
1301 1.1 lukem
1302 1.1 lukem if ( rdi->rdi_ref != NULL ) {
1303 1.1 lukem attr_merge_normalize( &rdi->rdi_e, slap_schema.si_ad_ref,
1304 1.1 lukem rdi->rdi_ref, NULL );
1305 1.1 lukem }
1306 1.1 lukem
1307 1.1 lukem /* text */
1308 1.1 lukem if ( !BER_BVISNULL( &rdi->rdi_text ) ) {
1309 1.1 lukem val[ 0 ] = rdi->rdi_text;
1310 1.1 lukem
1311 1.1 lukem attr_merge_normalize_one( &rdi->rdi_e, ad_errText, &val[ 0 ], NULL );
1312 1.1 lukem }
1313 1.1 lukem
1314 1.1 lukem /* matched */
1315 1.1 lukem if ( !BER_BVISNULL( &rdi->rdi_matched ) ) {
1316 1.1 lukem val[ 0 ] = rdi->rdi_matched;
1317 1.1 lukem
1318 1.1 lukem attr_merge_normalize_one( &rdi->rdi_e, ad_errMatchedDN, &val[ 0 ], NULL );
1319 1.1 lukem }
1320 1.1 lukem
1321 1.1 lukem /* sleep time */
1322 1.1 lukem if ( rdi->rdi_sleeptime ) {
1323 1.1 lukem snprintf( buf, sizeof( buf ), "%d", rdi->rdi_sleeptime );
1324 1.1 lukem ber_str2bv( buf, 0, 0, &val[ 0 ] );
1325 1.1 lukem
1326 1.1 lukem attr_merge_one( &rdi->rdi_e, ad_errSleepTime, &val[ 0 ], NULL );
1327 1.1 lukem }
1328 1.1 lukem
1329 1.1 lukem /* operations */
1330 1.1 lukem if ( rdi->rdi_mask & SN_DG_OP_ADD ) {
1331 1.1 lukem BER_BVSTR( &val[ 0 ], "add" );
1332 1.1 lukem attr_merge_normalize_one( &rdi->rdi_e, ad_errOp, &val[ 0 ], NULL );
1333 1.1 lukem }
1334 1.1 lukem
1335 1.1 lukem if ( rdi->rdi_mask & SN_DG_OP_BIND ) {
1336 1.1 lukem BER_BVSTR( &val[ 0 ], "bind" );
1337 1.1 lukem attr_merge_normalize_one( &rdi->rdi_e, ad_errOp, &val[ 0 ], NULL );
1338 1.1 lukem }
1339 1.1 lukem
1340 1.1 lukem if ( rdi->rdi_mask & SN_DG_OP_COMPARE ) {
1341 1.1 lukem BER_BVSTR( &val[ 0 ], "compare" );
1342 1.1 lukem attr_merge_normalize_one( &rdi->rdi_e, ad_errOp, &val[ 0 ], NULL );
1343 1.1 lukem }
1344 1.1 lukem
1345 1.1 lukem if ( rdi->rdi_mask & SN_DG_OP_DELETE ) {
1346 1.1 lukem BER_BVSTR( &val[ 0 ], "delete" );
1347 1.1 lukem attr_merge_normalize_one( &rdi->rdi_e, ad_errOp, &val[ 0 ], NULL );
1348 1.1 lukem }
1349 1.1 lukem
1350 1.1 lukem if ( rdi->rdi_mask & SN_DG_EXTENDED ) {
1351 1.1 lukem BER_BVSTR( &val[ 0 ], "extended" );
1352 1.1 lukem attr_merge_normalize_one( &rdi->rdi_e, ad_errOp, &val[ 0 ], NULL );
1353 1.1 lukem }
1354 1.1 lukem
1355 1.1 lukem if ( rdi->rdi_mask & SN_DG_OP_MODIFY ) {
1356 1.1 lukem BER_BVSTR( &val[ 0 ], "modify" );
1357 1.1 lukem attr_merge_normalize_one( &rdi->rdi_e, ad_errOp, &val[ 0 ], NULL );
1358 1.1 lukem }
1359 1.1 lukem
1360 1.1 lukem if ( rdi->rdi_mask & SN_DG_OP_RENAME ) {
1361 1.1 lukem BER_BVSTR( &val[ 0 ], "rename" );
1362 1.1 lukem attr_merge_normalize_one( &rdi->rdi_e, ad_errOp, &val[ 0 ], NULL );
1363 1.1 lukem }
1364 1.1 lukem
1365 1.1 lukem if ( rdi->rdi_mask & SN_DG_OP_SEARCH ) {
1366 1.1 lukem BER_BVSTR( &val[ 0 ], "search" );
1367 1.1 lukem attr_merge_normalize_one( &rdi->rdi_e, ad_errOp, &val[ 0 ], NULL );
1368 1.1 lukem }
1369 1.1 lukem }
1370 1.1 lukem
1371 1.1 lukem return 0;
1372 1.1 lukem }
1373 1.1 lukem
1374 1.1 lukem static int
1375 1.1 lukem retcode_db_destroy( BackendDB *be, ConfigReply *cr )
1376 1.1 lukem {
1377 1.1 lukem slap_overinst *on = (slap_overinst *)be->bd_info;
1378 1.1 lukem retcode_t *rd = (retcode_t *)on->on_bi.bi_private;
1379 1.1 lukem
1380 1.1 lukem if ( rd ) {
1381 1.1 lukem retcode_item_t *rdi, *next;
1382 1.1 lukem
1383 1.1 lukem for ( rdi = rd->rd_item; rdi != NULL; rdi = next ) {
1384 1.1 lukem next = rdi->rdi_next;
1385 1.1.1.2 lukem retcode_item_destroy( rdi );
1386 1.1 lukem }
1387 1.1 lukem
1388 1.1 lukem if ( !BER_BVISNULL( &rd->rd_pdn ) ) {
1389 1.1 lukem ber_memfree( rd->rd_pdn.bv_val );
1390 1.1 lukem }
1391 1.1 lukem
1392 1.1 lukem if ( !BER_BVISNULL( &rd->rd_npdn ) ) {
1393 1.1 lukem ber_memfree( rd->rd_npdn.bv_val );
1394 1.1 lukem }
1395 1.1 lukem
1396 1.1 lukem ber_memfree( rd );
1397 1.1 lukem }
1398 1.1 lukem
1399 1.1 lukem return 0;
1400 1.1 lukem }
1401 1.1 lukem
1402 1.1 lukem #if SLAPD_OVER_RETCODE == SLAPD_MOD_DYNAMIC
1403 1.1 lukem static
1404 1.1 lukem #endif /* SLAPD_OVER_RETCODE == SLAPD_MOD_DYNAMIC */
1405 1.1 lukem int
1406 1.1 lukem retcode_initialize( void )
1407 1.1 lukem {
1408 1.1 lukem int i, code;
1409 1.1 lukem
1410 1.1 lukem static struct {
1411 1.1 lukem char *desc;
1412 1.1 lukem AttributeDescription **ad;
1413 1.1 lukem } retcode_at[] = {
1414 1.1 lukem { "( 1.3.6.1.4.1.4203.666.11.4.1.1 "
1415 1.1 lukem "NAME ( 'errCode' ) "
1416 1.1 lukem "DESC 'LDAP error code' "
1417 1.1 lukem "EQUALITY integerMatch "
1418 1.1 lukem "ORDERING integerOrderingMatch "
1419 1.1 lukem "SYNTAX 1.3.6.1.4.1.1466.115.121.1.27 "
1420 1.1 lukem "SINGLE-VALUE )",
1421 1.1 lukem &ad_errCode },
1422 1.1 lukem { "( 1.3.6.1.4.1.4203.666.11.4.1.2 "
1423 1.1 lukem "NAME ( 'errOp' ) "
1424 1.1 lukem "DESC 'Operations the errObject applies to' "
1425 1.1 lukem "EQUALITY caseIgnoreMatch "
1426 1.1 lukem "SUBSTR caseIgnoreSubstringsMatch "
1427 1.1 lukem "SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 )",
1428 1.1 lukem &ad_errOp},
1429 1.1 lukem { "( 1.3.6.1.4.1.4203.666.11.4.1.3 "
1430 1.1 lukem "NAME ( 'errText' ) "
1431 1.1 lukem "DESC 'LDAP error textual description' "
1432 1.1 lukem "EQUALITY caseIgnoreMatch "
1433 1.1 lukem "SUBSTR caseIgnoreSubstringsMatch "
1434 1.1 lukem "SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 "
1435 1.1 lukem "SINGLE-VALUE )",
1436 1.1 lukem &ad_errText },
1437 1.1 lukem { "( 1.3.6.1.4.1.4203.666.11.4.1.4 "
1438 1.1 lukem "NAME ( 'errSleepTime' ) "
1439 1.1 lukem "DESC 'Time to wait before returning the error' "
1440 1.1 lukem "EQUALITY integerMatch "
1441 1.1 lukem "SYNTAX 1.3.6.1.4.1.1466.115.121.1.27 "
1442 1.1 lukem "SINGLE-VALUE )",
1443 1.1 lukem &ad_errSleepTime },
1444 1.1 lukem { "( 1.3.6.1.4.1.4203.666.11.4.1.5 "
1445 1.1 lukem "NAME ( 'errMatchedDN' ) "
1446 1.1 lukem "DESC 'Value to be returned as matched DN' "
1447 1.1 lukem "EQUALITY distinguishedNameMatch "
1448 1.1 lukem "SYNTAX 1.3.6.1.4.1.1466.115.121.1.12 "
1449 1.1 lukem "SINGLE-VALUE )",
1450 1.1 lukem &ad_errMatchedDN },
1451 1.1 lukem { "( 1.3.6.1.4.1.4203.666.11.4.1.6 "
1452 1.1 lukem "NAME ( 'errUnsolicitedOID' ) "
1453 1.1 lukem "DESC 'OID to be returned within unsolicited response' "
1454 1.1 lukem "EQUALITY objectIdentifierMatch "
1455 1.1 lukem "SYNTAX 1.3.6.1.4.1.1466.115.121.1.38 "
1456 1.1 lukem "SINGLE-VALUE )",
1457 1.1 lukem &ad_errUnsolicitedOID },
1458 1.1 lukem { "( 1.3.6.1.4.1.4203.666.11.4.1.7 "
1459 1.1 lukem "NAME ( 'errUnsolicitedData' ) "
1460 1.1 lukem "DESC 'Data to be returned within unsolicited response' "
1461 1.1 lukem "SYNTAX 1.3.6.1.4.1.1466.115.121.1.40 "
1462 1.1 lukem "SINGLE-VALUE )",
1463 1.1 lukem &ad_errUnsolicitedData },
1464 1.1 lukem { "( 1.3.6.1.4.1.4203.666.11.4.1.8 "
1465 1.1 lukem "NAME ( 'errDisconnect' ) "
1466 1.1 lukem "DESC 'Disconnect without notice' "
1467 1.1 lukem "SYNTAX 1.3.6.1.4.1.1466.115.121.1.7 "
1468 1.1 lukem "SINGLE-VALUE )",
1469 1.1 lukem &ad_errDisconnect },
1470 1.1 lukem { NULL }
1471 1.1 lukem };
1472 1.1 lukem
1473 1.1 lukem static struct {
1474 1.1 lukem char *desc;
1475 1.1 lukem ObjectClass **oc;
1476 1.1 lukem } retcode_oc[] = {
1477 1.1 lukem { "( 1.3.6.1.4.1.4203.666.11.4.3.0 "
1478 1.1 lukem "NAME ( 'errAbsObject' ) "
1479 1.1 lukem "SUP top ABSTRACT "
1480 1.1 lukem "MUST ( errCode ) "
1481 1.1 lukem "MAY ( "
1482 1.1 lukem "cn "
1483 1.1 lukem "$ description "
1484 1.1 lukem "$ errOp "
1485 1.1 lukem "$ errText "
1486 1.1 lukem "$ errSleepTime "
1487 1.1 lukem "$ errMatchedDN "
1488 1.1 lukem "$ errUnsolicitedOID "
1489 1.1 lukem "$ errUnsolicitedData "
1490 1.1 lukem "$ errDisconnect "
1491 1.1 lukem ") )",
1492 1.1 lukem &oc_errAbsObject },
1493 1.1 lukem { "( 1.3.6.1.4.1.4203.666.11.4.3.1 "
1494 1.1 lukem "NAME ( 'errObject' ) "
1495 1.1 lukem "SUP errAbsObject STRUCTURAL "
1496 1.1 lukem ")",
1497 1.1 lukem &oc_errObject },
1498 1.1 lukem { "( 1.3.6.1.4.1.4203.666.11.4.3.2 "
1499 1.1 lukem "NAME ( 'errAuxObject' ) "
1500 1.1 lukem "SUP errAbsObject AUXILIARY "
1501 1.1 lukem ")",
1502 1.1 lukem &oc_errAuxObject },
1503 1.1 lukem { NULL }
1504 1.1 lukem };
1505 1.1 lukem
1506 1.1 lukem
1507 1.1 lukem for ( i = 0; retcode_at[ i ].desc != NULL; i++ ) {
1508 1.1 lukem code = register_at( retcode_at[ i ].desc, retcode_at[ i ].ad, 0 );
1509 1.1 lukem if ( code ) {
1510 1.1 lukem Debug( LDAP_DEBUG_ANY,
1511 1.1 lukem "retcode: register_at failed\n", 0, 0, 0 );
1512 1.1 lukem return code;
1513 1.1 lukem }
1514 1.1 lukem
1515 1.1 lukem (*retcode_at[ i ].ad)->ad_type->sat_flags |= SLAP_AT_HIDE;
1516 1.1 lukem }
1517 1.1 lukem
1518 1.1 lukem for ( i = 0; retcode_oc[ i ].desc != NULL; i++ ) {
1519 1.1 lukem code = register_oc( retcode_oc[ i ].desc, retcode_oc[ i ].oc, 0 );
1520 1.1 lukem if ( code ) {
1521 1.1 lukem Debug( LDAP_DEBUG_ANY,
1522 1.1 lukem "retcode: register_oc failed\n", 0, 0, 0 );
1523 1.1 lukem return code;
1524 1.1 lukem }
1525 1.1 lukem
1526 1.1 lukem (*retcode_oc[ i ].oc)->soc_flags |= SLAP_OC_HIDE;
1527 1.1 lukem }
1528 1.1 lukem
1529 1.1 lukem retcode.on_bi.bi_type = "retcode";
1530 1.1 lukem
1531 1.1 lukem retcode.on_bi.bi_db_init = retcode_db_init;
1532 1.1 lukem retcode.on_bi.bi_db_open = retcode_db_open;
1533 1.1 lukem retcode.on_bi.bi_db_destroy = retcode_db_destroy;
1534 1.1 lukem
1535 1.1 lukem retcode.on_bi.bi_op_add = retcode_op_func;
1536 1.1 lukem retcode.on_bi.bi_op_bind = retcode_op_func;
1537 1.1 lukem retcode.on_bi.bi_op_compare = retcode_op_func;
1538 1.1 lukem retcode.on_bi.bi_op_delete = retcode_op_func;
1539 1.1 lukem retcode.on_bi.bi_op_modify = retcode_op_func;
1540 1.1 lukem retcode.on_bi.bi_op_modrdn = retcode_op_func;
1541 1.1 lukem retcode.on_bi.bi_op_search = retcode_op_func;
1542 1.1 lukem
1543 1.1 lukem retcode.on_bi.bi_extended = retcode_op_func;
1544 1.1 lukem
1545 1.1 lukem retcode.on_response = retcode_response;
1546 1.1 lukem
1547 1.1.1.2 lukem retcode.on_bi.bi_cf_ocs = rcocs;
1548 1.1.1.2 lukem
1549 1.1.1.2 lukem code = config_register_schema( rccfg, rcocs );
1550 1.1.1.2 lukem if ( code ) {
1551 1.1.1.2 lukem return code;
1552 1.1.1.2 lukem }
1553 1.1.1.2 lukem
1554 1.1 lukem return overlay_register( &retcode );
1555 1.1 lukem }
1556 1.1 lukem
1557 1.1 lukem #if SLAPD_OVER_RETCODE == SLAPD_MOD_DYNAMIC
1558 1.1 lukem int
1559 1.1 lukem init_module( int argc, char *argv[] )
1560 1.1 lukem {
1561 1.1 lukem return retcode_initialize();
1562 1.1 lukem }
1563 1.1 lukem #endif /* SLAPD_OVER_RETCODE == SLAPD_MOD_DYNAMIC */
1564 1.1 lukem
1565 1.1 lukem #endif /* SLAPD_OVER_RETCODE */
1566