]> git.sur5r.net Git - openldap/blob - servers/slapd/controls.c
#ifdef for slap_auxprop_store
[openldap] / servers / slapd / controls.c
1 /* $OpenLDAP$ */
2 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
3  *
4  * Copyright 1998-2003 The OpenLDAP Foundation.
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted only as authorized by the OpenLDAP
9  * Public License.
10  *
11  * A copy of this license is available in the file LICENSE in the
12  * top-level directory of the distribution or, alternatively, at
13  * <http://www.OpenLDAP.org/license.html>.
14  */
15
16 #include "portable.h"
17
18 #include <stdio.h>
19
20 #include <ac/string.h>
21 #include <ac/socket.h>
22
23 #include "slap.h"
24
25 #include "../../libraries/liblber/lber-int.h"
26
27 static SLAP_CTRL_PARSE_FN parseAssert;
28 static SLAP_CTRL_PARSE_FN parsePreRead;
29 static SLAP_CTRL_PARSE_FN parsePostRead;
30 static SLAP_CTRL_PARSE_FN parseProxyAuthz;
31 static SLAP_CTRL_PARSE_FN parseManageDSAit;
32 static SLAP_CTRL_PARSE_FN parseModifyIncrement;
33 static SLAP_CTRL_PARSE_FN parseNoOp;
34 static SLAP_CTRL_PARSE_FN parsePagedResults;
35 static SLAP_CTRL_PARSE_FN parseValuesReturnFilter;
36 static SLAP_CTRL_PARSE_FN parsePermissiveModify;
37 static SLAP_CTRL_PARSE_FN parseDomainScope;
38
39 #ifdef LDAP_CONTROL_SUBENTRIES
40 static SLAP_CTRL_PARSE_FN parseSubentries;
41 #endif
42 static SLAP_CTRL_PARSE_FN parseLDAPsync;
43
44 #undef sc_mask /* avoid conflict with Irix 6.5 <sys/signal.h> */
45
46 const struct berval slap_pre_read_bv = BER_BVC(LDAP_CONTROL_PRE_READ);
47 const struct berval slap_post_read_bv = BER_BVC(LDAP_CONTROL_POST_READ);
48
49 struct slap_control {
50         /* Control OID */
51         char *sc_oid;
52
53         /* Operations supported by control */
54         slap_mask_t sc_mask;
55
56         /* Extended operations supported by control */
57         char **sc_extendedops;
58
59         /* Control parsing callback */
60         SLAP_CTRL_PARSE_FN *sc_parse;
61
62         LDAP_SLIST_ENTRY(slap_control) sc_next;
63 };
64
65 static LDAP_SLIST_HEAD(ControlsList, slap_control) controls_list
66         = LDAP_SLIST_HEAD_INITIALIZER(&controls_list);
67
68 /*
69  * all known request control OIDs should be added to this list
70  */
71 char **slap_known_controls = NULL;
72
73 static char *proxy_authz_extops[] = {
74         LDAP_EXOP_MODIFY_PASSWD,
75         LDAP_EXOP_X_WHO_AM_I,
76         NULL
77 };
78
79 static struct slap_control control_defs[] = {
80         { LDAP_CONTROL_ASSERT,
81                 SLAP_CTRL_HIDE|SLAP_CTRL_ACCESS, NULL,
82                 parseAssert, LDAP_SLIST_ENTRY_INITIALIZER(next) },
83         { LDAP_CONTROL_PRE_READ,
84                 SLAP_CTRL_HIDE|SLAP_CTRL_DELETE|SLAP_CTRL_MODIFY|SLAP_CTRL_RENAME, NULL,
85                 parsePreRead, LDAP_SLIST_ENTRY_INITIALIZER(next) },
86         { LDAP_CONTROL_POST_READ,
87                 SLAP_CTRL_HIDE|SLAP_CTRL_ADD|SLAP_CTRL_MODIFY|SLAP_CTRL_RENAME, NULL,
88                 parsePostRead, LDAP_SLIST_ENTRY_INITIALIZER(next) },
89         { LDAP_CONTROL_VALUESRETURNFILTER,
90                 SLAP_CTRL_SEARCH, NULL,
91                 parseValuesReturnFilter, LDAP_SLIST_ENTRY_INITIALIZER(next) },
92 #ifdef LDAP_CONTROL_PAGEDRESULTS
93         { LDAP_CONTROL_PAGEDRESULTS,
94                 SLAP_CTRL_SEARCH, NULL,
95                 parsePagedResults, LDAP_SLIST_ENTRY_INITIALIZER(next) },
96 #endif
97 #ifdef LDAP_CONTROL_X_DOMAIN_SCOPE
98         { LDAP_CONTROL_X_DOMAIN_SCOPE,
99                 SLAP_CTRL_FRONTEND|SLAP_CTRL_SEARCH, NULL,
100                 parseDomainScope, LDAP_SLIST_ENTRY_INITIALIZER(next) },
101 #endif
102 #ifdef LDAP_CONTROL_X_PERMISSIVE_MODIFY
103         { LDAP_CONTROL_X_PERMISSIVE_MODIFY,
104                 SLAP_CTRL_MODIFY, NULL,
105                 parsePermissiveModify, LDAP_SLIST_ENTRY_INITIALIZER(next) },
106 #endif
107 #ifdef LDAP_CONTROL_SUBENTRIES
108         { LDAP_CONTROL_SUBENTRIES,
109                 SLAP_CTRL_SEARCH, NULL,
110                 parseSubentries, LDAP_SLIST_ENTRY_INITIALIZER(next) },
111 #endif
112         { LDAP_CONTROL_NOOP,
113                 SLAP_CTRL_ACCESS, NULL,
114                 parseNoOp, LDAP_SLIST_ENTRY_INITIALIZER(next) },
115         { LDAP_CONTROL_SYNC,
116                 SLAP_CTRL_HIDE|SLAP_CTRL_SEARCH, NULL,
117                 parseLDAPsync, LDAP_SLIST_ENTRY_INITIALIZER(next) },
118         { LDAP_CONTROL_MODIFY_INCREMENT,
119                 SLAP_CTRL_HIDE|SLAP_CTRL_MODIFY, NULL,
120                 parseModifyIncrement, LDAP_SLIST_ENTRY_INITIALIZER(next) },
121         { LDAP_CONTROL_MANAGEDSAIT,
122                 SLAP_CTRL_ACCESS, NULL,
123                 parseManageDSAit, LDAP_SLIST_ENTRY_INITIALIZER(next) },
124         { LDAP_CONTROL_PROXY_AUTHZ,
125                 SLAP_CTRL_FRONTEND|SLAP_CTRL_ACCESS, proxy_authz_extops,
126                 parseProxyAuthz, LDAP_SLIST_ENTRY_INITIALIZER(next) },
127         { NULL, 0, NULL, 0, LDAP_SLIST_ENTRY_INITIALIZER(next) }
128 };
129
130 /*
131  * Register a supported control.
132  *
133  * This can be called by an OpenLDAP plugin or, indirectly, by a
134  * SLAPI plugin calling slapi_register_supported_control().
135  */
136 int
137 register_supported_control(const char *controloid,
138         slap_mask_t controlmask,
139         char **controlexops,
140         SLAP_CTRL_PARSE_FN *controlparsefn)
141 {
142         struct slap_control *sc;
143         int i;
144
145         if ( controloid == NULL ) {
146                 return LDAP_PARAM_ERROR;
147         }
148
149         sc = (struct slap_control *)SLAP_MALLOC( sizeof( *sc ) );
150         if ( sc == NULL ) {
151                 return LDAP_NO_MEMORY;
152         }
153         sc->sc_oid = ch_strdup( controloid );
154         sc->sc_mask = controlmask;
155         if ( controlexops != NULL ) {
156                 sc->sc_extendedops = ldap_charray_dup( controlexops );
157                 if ( sc->sc_extendedops == NULL ) {
158                         ch_free( sc );
159                         return LDAP_NO_MEMORY;
160                 }
161         } else {
162                 sc->sc_extendedops = NULL;
163         }
164         sc->sc_parse = controlparsefn;
165
166         /* Update slap_known_controls, too. */
167         if ( slap_known_controls == NULL ) {
168                 slap_known_controls = (char **)SLAP_MALLOC( 2 * sizeof(char *) );
169                 if ( slap_known_controls == NULL ) {
170                         if ( sc->sc_extendedops != NULL ) ldap_charray_free( sc->sc_extendedops );
171                         ch_free( sc );
172                         return LDAP_NO_MEMORY;
173                 }
174                 slap_known_controls[0] = ch_strdup( sc->sc_oid );
175                 slap_known_controls[1] = NULL;
176         } else {
177                 for ( i = 0; slap_known_controls[i] != NULL; i++ )
178                         ;
179                 slap_known_controls = (char **)SLAP_REALLOC( slap_known_controls, (i + 2) * sizeof(char *) );
180                 if ( slap_known_controls == NULL ) {
181                         if ( sc->sc_extendedops != NULL ) ldap_charray_free( sc->sc_extendedops );
182                         ch_free( sc );
183                         return LDAP_NO_MEMORY;
184                 }
185                 slap_known_controls[i++] = ch_strdup( sc->sc_oid );
186                 slap_known_controls[i] = NULL;
187         }
188
189         LDAP_SLIST_NEXT( sc, sc_next ) = NULL;
190         LDAP_SLIST_INSERT_HEAD( &controls_list, sc, sc_next );
191
192         return LDAP_SUCCESS;
193 }
194
195 /*
196  * One-time initialization of internal controls.
197  */
198 int
199 slap_controls_init( void )
200 {
201         int i, rc;
202         struct slap_control *sc;
203
204         rc = LDAP_SUCCESS;
205
206         for ( i = 0; control_defs[i].sc_oid != NULL; i++ ) {
207                 rc = register_supported_control( control_defs[i].sc_oid,
208                         control_defs[i].sc_mask, control_defs[i].sc_extendedops,
209                         control_defs[i].sc_parse );
210                 if ( rc != LDAP_SUCCESS )
211                         break;
212         }
213
214         return rc;
215 }
216
217 /*
218  * Free memory associated with list of supported controls.
219  */
220 void
221 controls_destroy( void )
222 {
223         struct slap_control *sc;
224
225         while ( !LDAP_SLIST_EMPTY(&controls_list) ) {
226                 sc = LDAP_SLIST_FIRST(&controls_list);
227                 LDAP_SLIST_REMOVE_HEAD(&controls_list, sc_next);
228
229                 ch_free( sc->sc_oid );
230                 if ( sc->sc_extendedops != NULL ) {
231                         ldap_charray_free( sc->sc_extendedops );
232                 }
233                 ch_free( sc );
234         }
235         ldap_charray_free( slap_known_controls );
236 }
237
238 /*
239  * Format the supportedControl attribute of the root DSE,
240  * detailing which controls are supported by the directory
241  * server.
242  */
243 int
244 controls_root_dse_info( Entry *e )
245 {
246         AttributeDescription *ad_supportedControl
247                 = slap_schema.si_ad_supportedControl;
248         struct berval vals[2];
249         struct slap_control *sc;
250
251         vals[1].bv_val = NULL;
252         vals[1].bv_len = 0;
253
254         LDAP_SLIST_FOREACH( sc, &controls_list, sc_next ) {
255                 if( sc->sc_mask & SLAP_CTRL_HIDE ) continue;
256
257                 vals[0].bv_val = sc->sc_oid;
258                 vals[0].bv_len = strlen( sc->sc_oid );
259
260                 if ( attr_merge( e, ad_supportedControl, vals, NULL ) ) {
261                         return -1;
262                 }
263         }
264
265         return 0;
266 }
267
268 /*
269  * Return a list of OIDs and operation masks for supported
270  * controls. Used by SLAPI.
271  */
272 int
273 get_supported_controls(char ***ctrloidsp,
274         slap_mask_t **ctrlmasks)
275 {
276         int i, n;
277         char **oids;
278         slap_mask_t *masks;
279         int rc;
280         struct slap_control *sc;
281
282         n = 0;
283
284         LDAP_SLIST_FOREACH( sc, &controls_list, sc_next ) {
285                 n++;
286         }
287
288         if ( n == 0 ) {
289                 *ctrloidsp = NULL;
290                 *ctrlmasks = NULL;
291                 return LDAP_SUCCESS;
292         }
293
294         oids = (char **)SLAP_MALLOC( (n + 1) * sizeof(char *) );
295         if ( oids == NULL ) {
296                 return LDAP_NO_MEMORY;
297         }
298         masks = (slap_mask_t *)SLAP_MALLOC( (n + 1) * sizeof(slap_mask_t) );
299         if  ( masks == NULL ) {
300                 ch_free( oids );
301                 return LDAP_NO_MEMORY;
302         }
303
304         n = 0;
305
306         LDAP_SLIST_FOREACH( sc, &controls_list, sc_next ) {
307                 oids[n] = ch_strdup( sc->sc_oid );
308                 masks[n] = sc->sc_mask;
309                 n++;
310         }
311         oids[n] = NULL;
312         masks[n] = 0;
313
314         *ctrloidsp = oids;
315         *ctrlmasks = masks;
316
317         return LDAP_SUCCESS;
318 }
319
320 /*
321  * Find a control given its OID.
322  */
323 static struct slap_control *
324 find_ctrl( const char *oid )
325 {
326         struct slap_control *sc;
327
328         LDAP_SLIST_FOREACH( sc, &controls_list, sc_next ) {
329                 if ( strcmp( oid, sc->sc_oid ) == 0 ) {
330                         return sc;
331                 }
332         }
333
334         return NULL;
335 }
336
337 void slap_free_ctrls(
338         Operation *op,
339         LDAPControl **ctrls
340 )
341 {
342         int i;
343
344         for (i=0; ctrls[i]; i++) {
345                 op->o_tmpfree(ctrls[i], op->o_tmpmemctx );
346         }
347         op->o_tmpfree( ctrls, op->o_tmpmemctx );
348 }
349
350 int get_ctrls(
351         Operation *op,
352         SlapReply *rs,
353         int sendres )
354 {
355         int nctrls = 0;
356         ber_tag_t tag;
357         ber_len_t len;
358         char *opaque;
359         BerElement *ber = op->o_ber;
360         struct slap_control *sc;
361         struct berval bv;
362
363         len = ber_pvt_ber_remaining(ber);
364
365         if( len == 0) {
366                 /* no controls */
367                 rs->sr_err = LDAP_SUCCESS;
368                 return rs->sr_err;
369         }
370
371         if(( tag = ber_peek_tag( ber, &len )) != LDAP_TAG_CONTROLS ) {
372                 if( tag == LBER_ERROR ) {
373                         rs->sr_err = SLAPD_DISCONNECT;
374                         rs->sr_text = "unexpected data in PDU";
375                 }
376
377                 goto return_results;
378         }
379
380 #ifdef NEW_LOGGING
381         LDAP_LOG( OPERATION, ENTRY,
382                 "get_ctrls: conn %lu\n", op->o_connid, 0, 0 );
383 #else
384         Debug( LDAP_DEBUG_TRACE,
385                 "=> get_ctrls\n", 0, 0, 0 );
386 #endif
387
388         if( op->o_protocol < LDAP_VERSION3 ) {
389                 rs->sr_err = SLAPD_DISCONNECT;
390                 rs->sr_text = "controls require LDAPv3";
391                 goto return_results;
392         }
393
394         /* one for first control, one for termination */
395         op->o_ctrls = op->o_tmpalloc( 2 * sizeof(LDAPControl *), op->o_tmpmemctx );
396
397 #if 0
398         if( op->ctrls == NULL ) {
399                 rs->sr_err = LDAP_NO_MEMORY;
400                 rs->sr_text = "no memory";
401                 goto return_results;
402         }
403 #endif
404
405         op->o_ctrls[nctrls] = NULL;
406
407         /* step through each element */
408         for( tag = ber_first_element( ber, &len, &opaque );
409                 tag != LBER_ERROR;
410                 tag = ber_next_element( ber, &len, opaque ) )
411         {
412                 LDAPControl *c;
413                 LDAPControl **tctrls;
414
415                 c = op->o_tmpalloc( sizeof(LDAPControl), op->o_tmpmemctx );
416                 memset(c, 0, sizeof(LDAPControl));
417
418                 /* allocate pointer space for current controls (nctrls)
419                  * + this control + extra NULL
420                  */
421                 tctrls = op->o_tmprealloc( op->o_ctrls,
422                         (nctrls+2) * sizeof(LDAPControl *), op->o_tmpmemctx );
423
424 #if 0
425                 if( tctrls == NULL ) {
426                         ch_free( c );
427                         ldap_controls_free(op->o_ctrls);
428                         op->o_ctrls = NULL;
429
430                         rs->sr_err = LDAP_NO_MEMORY;
431                         rs->sr_text = "no memory";
432                         goto return_results;
433                 }
434 #endif
435                 op->o_ctrls = tctrls;
436
437                 op->o_ctrls[nctrls++] = c;
438                 op->o_ctrls[nctrls] = NULL;
439
440                 tag = ber_scanf( ber, "{m" /*}*/, &bv );
441                 c->ldctl_oid = bv.bv_val;
442
443                 if( tag == LBER_ERROR ) {
444 #ifdef NEW_LOGGING
445                         LDAP_LOG( OPERATION, INFO, "get_ctrls: conn %lu get OID failed.\n",
446                                 op->o_connid, 0, 0 );
447 #else
448                         Debug( LDAP_DEBUG_TRACE, "=> get_ctrls: get oid failed.\n",
449                                 0, 0, 0 );
450 #endif
451
452                         slap_free_ctrls( op, op->o_ctrls );
453                         op->o_ctrls = NULL;
454                         rs->sr_err = SLAPD_DISCONNECT;
455                         rs->sr_text = "decoding controls error";
456                         goto return_results;
457
458                 } else if( c->ldctl_oid == NULL ) {
459 #ifdef NEW_LOGGING
460                         LDAP_LOG( OPERATION, INFO,
461                                 "get_ctrls: conn %lu got emtpy OID.\n",
462                                 op->o_connid, 0, 0 );
463 #else
464                         Debug( LDAP_DEBUG_TRACE,
465                                 "get_ctrls: conn %lu got emtpy OID.\n",
466                                 op->o_connid, 0, 0 );
467 #endif
468
469                         slap_free_ctrls( op, op->o_ctrls );
470                         op->o_ctrls = NULL;
471                         rs->sr_err = LDAP_PROTOCOL_ERROR;
472                         rs->sr_text = "OID field is empty";
473                         goto return_results;
474                 }
475
476                 tag = ber_peek_tag( ber, &len );
477
478                 if( tag == LBER_BOOLEAN ) {
479                         ber_int_t crit;
480                         tag = ber_scanf( ber, "b", &crit );
481
482                         if( tag == LBER_ERROR ) {
483 #ifdef NEW_LOGGING
484                                 LDAP_LOG( OPERATION, INFO, 
485                                         "get_ctrls: conn %lu get crit failed.\n", 
486                                         op->o_connid, 0, 0 );
487 #else
488                                 Debug( LDAP_DEBUG_TRACE, "=> get_ctrls: get crit failed.\n",
489                                         0, 0, 0 );
490 #endif
491                                 slap_free_ctrls( op, op->o_ctrls );
492                                 op->o_ctrls = NULL;
493                                 rs->sr_err = SLAPD_DISCONNECT;
494                                 rs->sr_text = "decoding controls error";
495                                 goto return_results;
496                         }
497
498                         c->ldctl_iscritical = (crit != 0);
499                         tag = ber_peek_tag( ber, &len );
500                 }
501
502                 if( tag == LBER_OCTETSTRING ) {
503                         tag = ber_scanf( ber, "m", &c->ldctl_value );
504
505                         if( tag == LBER_ERROR ) {
506 #ifdef NEW_LOGGING
507                                 LDAP_LOG( OPERATION, INFO, "get_ctrls: conn %lu: "
508                                         "%s (%scritical): get value failed.\n",
509                                         op->o_connid, c->ldctl_oid,
510                                         c->ldctl_iscritical ? "" : "non" );
511 #else
512                                 Debug( LDAP_DEBUG_TRACE, "=> get_ctrls: conn %lu: "
513                                         "%s (%scritical): get value failed.\n",
514                                         op->o_connid, c->ldctl_oid,
515                                         c->ldctl_iscritical ? "" : "non" );
516 #endif
517                                 slap_free_ctrls( op, op->o_ctrls );
518                                 op->o_ctrls = NULL;
519                                 rs->sr_err = SLAPD_DISCONNECT;
520                                 rs->sr_text = "decoding controls error";
521                                 goto return_results;
522                         }
523                 }
524
525 #ifdef NEW_LOGGING
526                 LDAP_LOG( OPERATION, INFO, 
527                         "get_ctrls: conn %lu oid=\"%s\" (%scritical)\n",
528                         op->o_connid, c->ldctl_oid, c->ldctl_iscritical ? "" : "non" );
529 #else
530                 Debug( LDAP_DEBUG_TRACE,
531                         "=> get_ctrls: oid=\"%s\" (%scritical)\n",
532                         c->ldctl_oid, c->ldctl_iscritical ? "" : "non", 0 );
533 #endif
534
535                 sc = find_ctrl( c->ldctl_oid );
536                 if( sc != NULL ) {
537                         /* recognized control */
538                         slap_mask_t tagmask;
539                         switch( op->o_tag ) {
540                         case LDAP_REQ_ADD:
541                                 tagmask = SLAP_CTRL_ADD;
542                                 break;
543                         case LDAP_REQ_BIND:
544                                 tagmask = SLAP_CTRL_BIND;
545                                 break;
546                         case LDAP_REQ_COMPARE:
547                                 tagmask = SLAP_CTRL_COMPARE;
548                                 break;
549                         case LDAP_REQ_DELETE:
550                                 tagmask = SLAP_CTRL_DELETE;
551                                 break;
552                         case LDAP_REQ_MODIFY:
553                                 tagmask = SLAP_CTRL_MODIFY;
554                                 break;
555                         case LDAP_REQ_RENAME:
556                                 tagmask = SLAP_CTRL_RENAME;
557                                 break;
558                         case LDAP_REQ_SEARCH:
559                                 tagmask = SLAP_CTRL_SEARCH;
560                                 break;
561                         case LDAP_REQ_UNBIND:
562                                 tagmask = SLAP_CTRL_UNBIND;
563                                 break;
564                         case LDAP_REQ_ABANDON:
565                                 tagmask = SLAP_CTRL_ABANDON;
566                                 break;
567                         case LDAP_REQ_EXTENDED:
568                                 tagmask=~0L;
569                                 assert( op->ore_reqoid.bv_val != NULL );
570                                 if( sc->sc_extendedops != NULL ) {
571                                         int i;
572                                         for( i=0; sc->sc_extendedops[i] != NULL; i++ ) {
573                                                 if( strcmp( op->ore_reqoid.bv_val, sc->sc_extendedops[i] )
574                                                         == 0 )
575                                                 {
576                                                         tagmask=0L;
577                                                         break;
578                                                 }
579                                         }
580                                 }
581                                 break;
582                         default:
583                                 rs->sr_err = LDAP_OTHER;
584                                 rs->sr_text = "controls internal error";
585                                 goto return_results;
586                         }
587
588                         if (( sc->sc_mask & tagmask ) == tagmask ) {
589                                 /* available extension */
590
591                                 if( !sc->sc_parse ) {
592                                         rs->sr_err = LDAP_OTHER;
593                                         rs->sr_text = "not yet implemented";
594                                         goto return_results;
595                                 }
596
597                                 rs->sr_err = sc->sc_parse( op, rs, c );
598
599                                 if( rs->sr_err != LDAP_SUCCESS ) goto return_results;
600
601                                 if ( sc->sc_mask & SLAP_CTRL_FRONTEND ) {
602                                         /* kludge to disable backend_control() check */
603                                         c->ldctl_iscritical = 0;
604
605                                 } else if ( tagmask == SLAP_CTRL_SEARCH &&
606                                         sc->sc_mask & SLAP_CTRL_FRONTEND_SEARCH )
607                                 {
608                                         /* kludge to disable backend_control() check */
609                                         c->ldctl_iscritical = 0;
610                                 }
611
612                         } else if( c->ldctl_iscritical ) {
613                                 /* unavailable CRITICAL control */
614                                 rs->sr_err = LDAP_UNAVAILABLE_CRITICAL_EXTENSION;
615                                 rs->sr_text = "critical extension is unavailable";
616                                 goto return_results;
617                         }
618
619                 } else if( c->ldctl_iscritical ) {
620                         /* unrecognized CRITICAL control */
621                         rs->sr_err = LDAP_UNAVAILABLE_CRITICAL_EXTENSION;
622                         rs->sr_text = "critical extension is not recognized";
623                         goto return_results;
624                 }
625         }
626
627 return_results:
628 #ifdef NEW_LOGGING
629         LDAP_LOG( OPERATION, RESULTS, 
630                 "get_ctrls: n=%d rc=%d err=\"%s\"\n",
631                 nctrls, rs->sr_err, rs->sr_text ? rs->sr_text : "" );
632 #else
633         Debug( LDAP_DEBUG_TRACE,
634                 "<= get_ctrls: n=%d rc=%d err=\"%s\"\n",
635                 nctrls, rs->sr_err, rs->sr_text ? rs->sr_text : "");
636 #endif
637
638         if( sendres && rs->sr_err != LDAP_SUCCESS ) {
639                 if( rs->sr_err == SLAPD_DISCONNECT ) {
640                         rs->sr_err = LDAP_PROTOCOL_ERROR;
641                         send_ldap_disconnect( op, rs );
642                         rs->sr_err = SLAPD_DISCONNECT;
643                 } else {
644                         send_ldap_result( op, rs );
645                 }
646         }
647
648         return rs->sr_err;
649 }
650
651 static int parseModifyIncrement (
652         Operation *op,
653         SlapReply *rs,
654         LDAPControl *ctrl )
655 {
656 #if 0
657         if ( op->o_parseModifyIncrement != SLAP_NO_CONTROL ) {
658                 rs->sr_text = "modifyIncrement control specified multiple times";
659                 return LDAP_PROTOCOL_ERROR;
660         }
661 #endif
662
663         if ( ctrl->ldctl_value.bv_len ) {
664                 rs->sr_text = "modifyIncrement control value not empty";
665                 return LDAP_PROTOCOL_ERROR;
666         }
667
668 #if 0
669         op->o_parseModifyIncrement = ctrl->ldctl_iscritical
670                 ? SLAP_CRITICAL_CONTROL
671                 : SLAP_NONCRITICAL_CONTROL;
672 #endif
673
674         return LDAP_SUCCESS;
675 }
676
677 static int parseManageDSAit (
678         Operation *op,
679         SlapReply *rs,
680         LDAPControl *ctrl )
681 {
682         if ( op->o_managedsait != SLAP_NO_CONTROL ) {
683                 rs->sr_text = "manageDSAit control specified multiple times";
684                 return LDAP_PROTOCOL_ERROR;
685         }
686
687         if ( ctrl->ldctl_value.bv_len ) {
688                 rs->sr_text = "manageDSAit control value not empty";
689                 return LDAP_PROTOCOL_ERROR;
690         }
691
692         op->o_managedsait = ctrl->ldctl_iscritical
693                 ? SLAP_CRITICAL_CONTROL
694                 : SLAP_NONCRITICAL_CONTROL;
695
696         return LDAP_SUCCESS;
697 }
698
699 static int parseProxyAuthz (
700         Operation *op,
701         SlapReply *rs,
702         LDAPControl *ctrl )
703 {
704         int rc;
705         struct berval dn = { 0, NULL };
706
707         if ( op->o_proxy_authz != SLAP_NO_CONTROL ) {
708                 rs->sr_text = "proxy authorization control specified multiple times";
709                 return LDAP_PROTOCOL_ERROR;
710         }
711
712         op->o_proxy_authz = ctrl->ldctl_iscritical
713                 ? SLAP_CRITICAL_CONTROL
714                 : SLAP_NONCRITICAL_CONTROL;
715
716 #ifdef NEW_LOGGING
717         LDAP_LOG( OPERATION, ARGS, 
718                 "parseProxyAuthz: conn %lu authzid=\"%s\"\n", 
719                 op->o_connid,
720                 ctrl->ldctl_value.bv_len ?  ctrl->ldctl_value.bv_val : "anonymous",
721                 0 );
722 #else
723         Debug( LDAP_DEBUG_ARGS,
724                 "parseProxyAuthz: conn %lu authzid=\"%s\"\n", 
725                 op->o_connid,
726                 ctrl->ldctl_value.bv_len ?  ctrl->ldctl_value.bv_val : "anonymous",
727                 0 );
728 #endif
729
730         if( ctrl->ldctl_value.bv_len == 0 ) {
731 #ifdef NEW_LOGGING
732                 LDAP_LOG( OPERATION, RESULTS, 
733                         "parseProxyAuthz: conn=%lu anonymous\n", 
734                         op->o_connid, 0, 0 );
735 #else
736                 Debug( LDAP_DEBUG_TRACE,
737                         "parseProxyAuthz: conn=%lu anonymous\n", 
738                         op->o_connid, 0, 0 );
739 #endif
740
741                 /* anonymous */
742                 free( op->o_dn.bv_val );
743                 op->o_dn.bv_len = 0;
744                 op->o_dn.bv_val = ch_strdup( "" );
745
746                 free( op->o_ndn.bv_val );
747                 op->o_ndn.bv_len = 0;
748                 op->o_ndn.bv_val = ch_strdup( "" );
749
750                 return LDAP_SUCCESS;
751         }
752
753         rc = slap_sasl_getdn( op->o_conn, op,
754                 ctrl->ldctl_value.bv_val, ctrl->ldctl_value.bv_len,
755                 NULL, &dn, SLAP_GETDN_AUTHZID );
756
757         if( rc != LDAP_SUCCESS || !dn.bv_len ) {
758                 if ( dn.bv_val ) {
759                         ch_free( dn.bv_val );
760                 }
761                 rs->sr_text = "authzId mapping failed";
762                 return LDAP_PROXY_AUTHZ_FAILURE;
763         }
764
765 #ifdef NEW_LOGGING
766         LDAP_LOG( OPERATION, RESULTS, 
767                 "parseProxyAuthz: conn=%lu \"%s\"\n", 
768                 op->o_connid,
769                 dn.bv_len ? dn.bv_val : "(NULL)", 0 );
770 #else
771         Debug( LDAP_DEBUG_TRACE,
772                 "parseProxyAuthz: conn=%lu \"%s\"\n", 
773                 op->o_connid,
774                 dn.bv_len ? dn.bv_val : "(NULL)", 0 );
775 #endif
776
777         rc = slap_sasl_authorized( op, &op->o_ndn, &dn );
778
779         if( rc ) {
780                 ch_free( dn.bv_val );
781                 rs->sr_text = "not authorized to assume identity";
782                 return LDAP_PROXY_AUTHZ_FAILURE;
783         }
784
785         ch_free( op->o_dn.bv_val );
786         ch_free( op->o_ndn.bv_val );
787
788         op->o_dn.bv_val = NULL;
789         op->o_ndn = dn;
790
791         /*
792          * NOTE: since slap_sasl_getdn() returns a normalized dn,
793          * from now on op->o_dn is normalized
794          */
795         ber_dupbv( &op->o_dn, &dn );
796
797         return LDAP_SUCCESS;
798 }
799
800 static int parseNoOp (
801         Operation *op,
802         SlapReply *rs,
803         LDAPControl *ctrl )
804 {
805         if ( op->o_noop != SLAP_NO_CONTROL ) {
806                 rs->sr_text = "noop control specified multiple times";
807                 return LDAP_PROTOCOL_ERROR;
808         }
809
810         if ( ctrl->ldctl_value.bv_len ) {
811                 rs->sr_text = "noop control value not empty";
812                 return LDAP_PROTOCOL_ERROR;
813         }
814
815         op->o_noop = ctrl->ldctl_iscritical
816                 ? SLAP_CRITICAL_CONTROL
817                 : SLAP_NONCRITICAL_CONTROL;
818
819         return LDAP_SUCCESS;
820 }
821
822 #ifdef LDAP_CONTROL_PAGEDRESULTS
823 static int parsePagedResults (
824         Operation *op,
825         SlapReply *rs,
826         LDAPControl *ctrl )
827 {
828         ber_tag_t tag;
829         ber_int_t size;
830         BerElement *ber;
831         struct berval cookie = { 0, NULL };
832
833         if ( op->o_pagedresults != SLAP_NO_CONTROL ) {
834                 rs->sr_text = "paged results control specified multiple times";
835                 return LDAP_PROTOCOL_ERROR;
836         }
837
838         if ( ctrl->ldctl_value.bv_len == 0 ) {
839                 rs->sr_text = "paged results control value is empty (or absent)";
840                 return LDAP_PROTOCOL_ERROR;
841         }
842
843         /* Parse the control value
844          *      realSearchControlValue ::= SEQUENCE {
845          *              size    INTEGER (0..maxInt),
846          *                              -- requested page size from client
847          *                              -- result set size estimate from server
848          *              cookie  OCTET STRING
849          * }
850          */
851         ber = ber_init( &ctrl->ldctl_value );
852         if( ber == NULL ) {
853                 rs->sr_text = "internal error";
854                 return LDAP_OTHER;
855         }
856
857         tag = ber_scanf( ber, "{im}", &size, &cookie );
858         (void) ber_free( ber, 1 );
859
860         if( tag == LBER_ERROR ) {
861                 rs->sr_text = "paged results control could not be decoded";
862                 return LDAP_PROTOCOL_ERROR;
863         }
864
865         if( size < 0 ) {
866                 rs->sr_text = "paged results control size invalid";
867                 return LDAP_PROTOCOL_ERROR;
868         }
869
870         if( cookie.bv_len ) {
871                 PagedResultsCookie reqcookie;
872                 if( cookie.bv_len != sizeof( reqcookie ) ) {
873                         /* bad cookie */
874                         rs->sr_text = "paged results cookie is invalid";
875                         return LDAP_PROTOCOL_ERROR;
876                 }
877
878                 AC_MEMCPY( &reqcookie, cookie.bv_val, sizeof( reqcookie ));
879
880                 if( reqcookie > op->o_pagedresults_state.ps_cookie ) {
881                         /* bad cookie */
882                         rs->sr_text = "paged results cookie is invalid";
883                         return LDAP_PROTOCOL_ERROR;
884
885                 } else if( reqcookie < op->o_pagedresults_state.ps_cookie ) {
886                         rs->sr_text = "paged results cookie is invalid or old";
887                         return LDAP_UNWILLING_TO_PERFORM;
888                 }
889         } else {
890                 /* Initial request.  Initialize state. */
891                 op->o_pagedresults_state.ps_cookie = 0;
892                 op->o_pagedresults_state.ps_id = NOID;
893         }
894
895         op->o_pagedresults_size = size;
896
897         op->o_pagedresults = ctrl->ldctl_iscritical
898                 ? SLAP_CRITICAL_CONTROL
899                 : SLAP_NONCRITICAL_CONTROL;
900
901         return LDAP_SUCCESS;
902 }
903 #endif
904
905 static int parseAssert (
906         Operation *op,
907         SlapReply *rs,
908         LDAPControl *ctrl )
909 {
910         BerElement      *ber;
911         struct berval   fstr = { 0, NULL };
912         const char *err_msg = "";
913
914         if ( op->o_assert != SLAP_NO_CONTROL ) {
915                 rs->sr_text = "assert control specified multiple times";
916                 return LDAP_PROTOCOL_ERROR;
917         }
918
919         if ( ctrl->ldctl_value.bv_len == 0 ) {
920                 rs->sr_text = "assert control value is empty (or absent)";
921                 return LDAP_PROTOCOL_ERROR;
922         }
923
924         ber = ber_init( &(ctrl->ldctl_value) );
925         if (ber == NULL) {
926                 rs->sr_text = "assert control: internal error";
927                 return LDAP_OTHER;
928         }
929         
930         rs->sr_err = get_filter( op, ber, &(op->o_assertion), &rs->sr_text);
931
932         if( rs->sr_err != LDAP_SUCCESS ) {
933                 if( rs->sr_err == SLAPD_DISCONNECT ) {
934                         rs->sr_err = LDAP_PROTOCOL_ERROR;
935                         send_ldap_disconnect( op, rs );
936                         rs->sr_err = SLAPD_DISCONNECT;
937                 } else {
938                         send_ldap_result( op, rs );
939                 }
940                 if( op->o_assertion != NULL ) {
941                         filter_free_x( op, op->o_assertion );
942                 }
943                 return rs->sr_err;
944         }
945
946 #ifdef LDAP_DEBUG
947         filter2bv_x( op, op->o_assertion, &fstr );
948
949 #ifdef NEW_LOGGING
950         LDAP_LOG( OPERATION, ARGS, 
951                 "parseAssert: conn %ld assert: %s\n", 
952                 op->o_connid, fstr.bv_len ? fstr.bv_val : "empty" , 0 );
953 #else
954         Debug( LDAP_DEBUG_ARGS, "parseAssert: conn %ld assert: %s\n",
955                 op->o_connid, fstr.bv_len ? fstr.bv_val : "empty" , 0 );
956 #endif
957         op->o_tmpfree( fstr.bv_val, op->o_tmpmemctx );
958 #endif
959
960         op->o_assert = ctrl->ldctl_iscritical
961                 ? SLAP_CRITICAL_CONTROL
962                 : SLAP_NONCRITICAL_CONTROL;
963
964         rs->sr_err = LDAP_SUCCESS;
965         return LDAP_SUCCESS;
966 }
967
968 static int parsePreRead (
969         Operation *op,
970         SlapReply *rs,
971         LDAPControl *ctrl )
972 {
973         ber_len_t siz, off, i;
974         AttributeName *an = NULL;
975         BerElement      *ber;
976
977         if ( op->o_preread != SLAP_NO_CONTROL ) {
978                 rs->sr_text = "preread control specified multiple times";
979                 return LDAP_PROTOCOL_ERROR;
980         }
981
982         if ( ctrl->ldctl_value.bv_len == 0 ) {
983                 rs->sr_text = "preread control value is empty (or absent)";
984                 return LDAP_PROTOCOL_ERROR;
985         }
986
987         ber = ber_init( &(ctrl->ldctl_value) );
988         if (ber == NULL) {
989                 rs->sr_text = "preread control: internal error";
990                 return LDAP_OTHER;
991         }
992
993         siz = sizeof( AttributeName );
994         off = offsetof( AttributeName, an_name );
995         if ( ber_scanf( ber, "{M}", &an, &siz, off ) == LBER_ERROR ) {
996                 rs->sr_text = "preread control: decoding error";
997                 return LDAP_PROTOCOL_ERROR;
998         }
999
1000         for( i=0; i<siz; i++ ) {
1001                 const char *dummy;
1002                 an[i].an_desc = NULL;
1003                 an[i].an_oc = NULL;
1004                 slap_bv2ad( &an[i].an_name, &an[i].an_desc, &dummy );
1005         }
1006
1007         op->o_preread = ctrl->ldctl_iscritical
1008                 ? SLAP_CRITICAL_CONTROL
1009                 : SLAP_NONCRITICAL_CONTROL;
1010
1011         op->o_preread_attrs = an;
1012
1013         rs->sr_err = LDAP_SUCCESS;
1014         return LDAP_SUCCESS;
1015 }
1016
1017 static int parsePostRead (
1018         Operation *op,
1019         SlapReply *rs,
1020         LDAPControl *ctrl )
1021 {
1022         ber_len_t siz, off, i;
1023         AttributeName *an = NULL;
1024         BerElement      *ber;
1025
1026         if ( op->o_postread != SLAP_NO_CONTROL ) {
1027                 rs->sr_text = "postread control specified multiple times";
1028                 return LDAP_PROTOCOL_ERROR;
1029         }
1030
1031         if ( ctrl->ldctl_value.bv_len == 0 ) {
1032                 rs->sr_text = "postread control value is empty (or absent)";
1033                 return LDAP_PROTOCOL_ERROR;
1034         }
1035
1036         ber = ber_init( &(ctrl->ldctl_value) );
1037         if (ber == NULL) {
1038                 rs->sr_text = "postread control: internal error";
1039                 return LDAP_OTHER;
1040         }
1041
1042         siz = sizeof( AttributeName );
1043         off = offsetof( AttributeName, an_name );
1044         if ( ber_scanf( ber, "{M}", &an, &siz, off ) == LBER_ERROR ) {
1045                 rs->sr_text = "postread control: decoding error";
1046                 return LDAP_PROTOCOL_ERROR;
1047         }
1048
1049         for( i=0; i<siz; i++ ) {
1050                 const char *dummy;
1051                 an[i].an_desc = NULL;
1052                 an[i].an_oc = NULL;
1053                 slap_bv2ad( &an[i].an_name, &an[i].an_desc, &dummy );
1054         }
1055
1056         op->o_postread = ctrl->ldctl_iscritical
1057                 ? SLAP_CRITICAL_CONTROL
1058                 : SLAP_NONCRITICAL_CONTROL;
1059
1060         op->o_postread_attrs = an;
1061
1062         rs->sr_err = LDAP_SUCCESS;
1063         return LDAP_SUCCESS;
1064 }
1065
1066 int parseValuesReturnFilter (
1067         Operation *op,
1068         SlapReply *rs,
1069         LDAPControl *ctrl )
1070 {
1071         BerElement      *ber;
1072         struct berval   fstr = { 0, NULL };
1073         const char *err_msg = "";
1074
1075         if ( op->o_valuesreturnfilter != SLAP_NO_CONTROL ) {
1076                 rs->sr_text = "valuesReturnFilter control specified multiple times";
1077                 return LDAP_PROTOCOL_ERROR;
1078         }
1079
1080         if ( ctrl->ldctl_value.bv_len == 0 ) {
1081                 rs->sr_text = "valuesReturnFilter control value is empty (or absent)";
1082                 return LDAP_PROTOCOL_ERROR;
1083         }
1084
1085         ber = ber_init( &(ctrl->ldctl_value) );
1086         if (ber == NULL) {
1087                 rs->sr_text = "internal error";
1088                 return LDAP_OTHER;
1089         }
1090         
1091         rs->sr_err = get_vrFilter( op, ber, &(op->o_vrFilter), &rs->sr_text);
1092
1093         if( rs->sr_err != LDAP_SUCCESS ) {
1094                 if( rs->sr_err == SLAPD_DISCONNECT ) {
1095                         rs->sr_err = LDAP_PROTOCOL_ERROR;
1096                         send_ldap_disconnect( op, rs );
1097                         rs->sr_err = SLAPD_DISCONNECT;
1098                 } else {
1099                         send_ldap_result( op, rs );
1100                 }
1101                 if( op->o_vrFilter != NULL) vrFilter_free( op, op->o_vrFilter ); 
1102         }
1103 #ifdef LDAP_DEBUG
1104         else {
1105                 vrFilter2bv( op, op->o_vrFilter, &fstr );
1106         }
1107
1108 #ifdef NEW_LOGGING
1109         LDAP_LOG( OPERATION, ARGS, 
1110                 "parseValuesReturnFilter: conn %d       vrFilter: %s\n", 
1111                 op->o_connid, fstr.bv_len ? fstr.bv_val : "empty" , 0 );
1112 #else
1113         Debug( LDAP_DEBUG_ARGS, "       vrFilter: %s\n",
1114                 fstr.bv_len ? fstr.bv_val : "empty", 0, 0 );
1115 #endif
1116         op->o_tmpfree( fstr.bv_val, op->o_tmpmemctx );
1117 #endif
1118
1119         op->o_valuesreturnfilter = ctrl->ldctl_iscritical
1120                 ? SLAP_CRITICAL_CONTROL
1121                 : SLAP_NONCRITICAL_CONTROL;
1122
1123         rs->sr_err = LDAP_SUCCESS;
1124         return LDAP_SUCCESS;
1125 }
1126
1127 #ifdef LDAP_CONTROL_SUBENTRIES
1128 static int parseSubentries (
1129         Operation *op,
1130         SlapReply *rs,
1131         LDAPControl *ctrl )
1132 {
1133         if ( op->o_subentries != SLAP_NO_CONTROL ) {
1134                 rs->sr_text = "subentries control specified multiple times";
1135                 return LDAP_PROTOCOL_ERROR;
1136         }
1137
1138         /* FIXME: should use BER library */
1139         if( ( ctrl->ldctl_value.bv_len != 3 )
1140                 && ( ctrl->ldctl_value.bv_val[0] != 0x01 )
1141                 && ( ctrl->ldctl_value.bv_val[1] != 0x01 ))
1142         {
1143                 rs->sr_text = "subentries control value encoding is bogus";
1144                 return LDAP_PROTOCOL_ERROR;
1145         }
1146
1147         op->o_subentries = ctrl->ldctl_iscritical
1148                 ? SLAP_CRITICAL_CONTROL
1149                 : SLAP_NONCRITICAL_CONTROL;
1150
1151         op->o_subentries_visibility = (ctrl->ldctl_value.bv_val[2] != 0x00);
1152
1153         return LDAP_SUCCESS;
1154 }
1155 #endif
1156
1157 #ifdef LDAP_CONTROL_X_PERMISSIVE_MODIFY
1158 static int parsePermissiveModify (
1159         Operation *op,
1160         SlapReply *rs,
1161         LDAPControl *ctrl )
1162 {
1163         if ( op->o_permissive_modify != SLAP_NO_CONTROL ) {
1164                 rs->sr_text = "permissiveModify control specified multiple times";
1165                 return LDAP_PROTOCOL_ERROR;
1166         }
1167
1168         if ( ctrl->ldctl_value.bv_len ) {
1169                 rs->sr_text = "permissiveModify control value not empty";
1170                 return LDAP_PROTOCOL_ERROR;
1171         }
1172
1173         op->o_permissive_modify = ctrl->ldctl_iscritical
1174                 ? SLAP_CRITICAL_CONTROL
1175                 : SLAP_NONCRITICAL_CONTROL;
1176
1177         return LDAP_SUCCESS;
1178 }
1179 #endif
1180
1181 #ifdef LDAP_CONTROL_X_DOMAIN_SCOPE
1182 static int parseDomainScope (
1183         Operation *op,
1184         SlapReply *rs,
1185         LDAPControl *ctrl )
1186 {
1187         if ( op->o_domain_scope != SLAP_NO_CONTROL ) {
1188                 rs->sr_text = "domainScope control specified multiple times";
1189                 return LDAP_PROTOCOL_ERROR;
1190         }
1191
1192         if ( ctrl->ldctl_value.bv_len ) {
1193                 rs->sr_text = "domainScope control value not empty";
1194                 return LDAP_PROTOCOL_ERROR;
1195         }
1196
1197         op->o_domain_scope = ctrl->ldctl_iscritical
1198                 ? SLAP_CRITICAL_CONTROL
1199                 : SLAP_NONCRITICAL_CONTROL;
1200
1201         return LDAP_SUCCESS;
1202 }
1203 #endif
1204
1205 static int parseLDAPsync (
1206         Operation *op,
1207         SlapReply *rs,
1208         LDAPControl *ctrl )
1209 {
1210         ber_tag_t tag;
1211         BerElement *ber;
1212         ber_int_t mode;
1213         ber_len_t len;
1214         struct slap_session_entry *se;
1215
1216         if ( op->o_sync != SLAP_NO_CONTROL ) {
1217                 rs->sr_text = "LDAP Sync control specified multiple times";
1218                 return LDAP_PROTOCOL_ERROR;
1219         }
1220
1221         if ( ctrl->ldctl_value.bv_len == 0 ) {
1222                 rs->sr_text = "LDAP Sync control value is empty (or absent)";
1223                 return LDAP_PROTOCOL_ERROR;
1224         }
1225
1226         /* Parse the control value
1227          *      syncRequestValue ::= SEQUENCE {
1228          *              mode   ENUMERATED {
1229          *                      -- 0 unused
1230          *                      refreshOnly             (1),
1231          *                      -- 2 reserved
1232          *                      refreshAndPersist       (3)
1233          *              },
1234          *              cookie  syncCookie OPTIONAL
1235          *      }
1236          */
1237
1238         ber = ber_init( &ctrl->ldctl_value );
1239         if( ber == NULL ) {
1240                 rs->sr_text = "internal error";
1241                 return LDAP_OTHER;
1242         }
1243
1244         if ( (tag = ber_scanf( ber, "{i" /*}*/, &mode )) == LBER_ERROR ) {
1245                 rs->sr_text = "LDAP Sync control : mode decoding error";
1246                 return LDAP_PROTOCOL_ERROR;
1247         }
1248
1249         switch( mode ) {
1250         case LDAP_SYNC_REFRESH_ONLY:
1251                 mode = SLAP_SYNC_REFRESH;
1252                 break;
1253         case LDAP_SYNC_REFRESH_AND_PERSIST:
1254                 mode = SLAP_SYNC_REFRESH_AND_PERSIST;
1255                 break;
1256         default:
1257                 rs->sr_text = "LDAP Sync control : unknown update mode";
1258                 return LDAP_PROTOCOL_ERROR;
1259         }
1260
1261         tag = ber_peek_tag( ber, &len );
1262
1263         if ( tag == LDAP_TAG_SYNC_COOKIE ) {
1264                 struct berval tmp_bv;   
1265                 if (( ber_scanf( ber, /*{*/ "o", &tmp_bv )) == LBER_ERROR ) {
1266                         rs->sr_text = "LDAP Sync control : cookie decoding error";
1267                         return LDAP_PROTOCOL_ERROR;
1268                 }
1269                 ber_bvarray_add( &op->o_sync_state.octet_str, &tmp_bv );
1270                 slap_parse_sync_cookie( &op->o_sync_state );
1271         }
1272         if ( tag == LDAP_TAG_RELOAD_HINT ) {
1273                 if (( ber_scanf( ber, /*{*/ "b", &op->o_sync_rhint )) == LBER_ERROR ) {
1274                         rs->sr_text = "LDAP Sync control : rhint decoding error";
1275                         return LDAP_PROTOCOL_ERROR;
1276                 }
1277         }
1278         if (( ber_scanf( ber, /*{*/ "}")) == LBER_ERROR ) {
1279                         rs->sr_text = "LDAP Sync control : decoding error";
1280                         return LDAP_PROTOCOL_ERROR;
1281         }
1282
1283         (void) ber_free( ber, 1 );
1284
1285         op->o_sync_mode = (char) mode;
1286
1287         op->o_sync = ctrl->ldctl_iscritical
1288                 ? SLAP_CRITICAL_CONTROL
1289                 : SLAP_NONCRITICAL_CONTROL;
1290
1291         return LDAP_SUCCESS;
1292 }