2 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
4 * Copyright 1998-2007 The OpenLDAP Foundation.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted only as authorized by the OpenLDAP
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>.
20 #include <ac/string.h>
21 #include <ac/socket.h>
26 #include "../../libraries/liblber/lber-int.h"
28 static SLAP_CTRL_PARSE_FN parseAssert;
29 static SLAP_CTRL_PARSE_FN parseDomainScope;
30 static SLAP_CTRL_PARSE_FN parseDontUseCopy;
31 static SLAP_CTRL_PARSE_FN parseManageDSAit;
32 static SLAP_CTRL_PARSE_FN parseNoOp;
33 static SLAP_CTRL_PARSE_FN parsePagedResults;
34 static SLAP_CTRL_PARSE_FN parsePermissiveModify;
35 static SLAP_CTRL_PARSE_FN parsePreRead, parsePostRead;
36 static SLAP_CTRL_PARSE_FN parseProxyAuthz;
37 static SLAP_CTRL_PARSE_FN parseRelax;
38 static SLAP_CTRL_PARSE_FN parseSearchOptions;
39 #ifdef SLAP_CONTROL_X_SORTEDRESULTS
40 static SLAP_CTRL_PARSE_FN parseSortedResults;
42 static SLAP_CTRL_PARSE_FN parseSubentries;
43 #ifdef SLAP_CONTROL_X_TREE_DELETE
44 static SLAP_CTRL_PARSE_FN parseTreeDelete;
46 static SLAP_CTRL_PARSE_FN parseValuesReturnFilter;
47 #ifdef SLAP_CONTROL_X_SESSION_TRACKING
48 static SLAP_CTRL_PARSE_FN parseSessionTracking;
51 #undef sc_mask /* avoid conflict with Irix 6.5 <sys/signal.h> */
53 const struct berval slap_pre_read_bv = BER_BVC(LDAP_CONTROL_PRE_READ);
54 const struct berval slap_post_read_bv = BER_BVC(LDAP_CONTROL_POST_READ);
56 struct slap_control_ids slap_cids;
62 /* The controlID for this control */
65 /* Operations supported by control */
68 /* Extended operations supported by control */
69 char **sc_extendedops; /* input */
70 BerVarray sc_extendedopsbv; /* run-time use */
72 /* Control parsing callback */
73 SLAP_CTRL_PARSE_FN *sc_parse;
75 LDAP_SLIST_ENTRY(slap_control) sc_next;
78 static LDAP_SLIST_HEAD(ControlsList, slap_control) controls_list
79 = LDAP_SLIST_HEAD_INITIALIZER(&controls_list);
82 * all known request control OIDs should be added to this list
85 * NOTE: initialize num_known_controls to 1 so that cid = 0 always
86 * addresses an undefined control; this allows to safely test for
87 * well known controls even if they are not registered, e.g. if
88 * they get moved to modules. An example is sc_LDAPsync, which
89 * is implemented in the syncprov overlay and thus, if configured
90 * as dynamic module, may not be registered. One side effect is that
91 * slap_known_controls[0] == NULL, so it should always be used
93 * FIXME: should we define the "undefined control" oid?
95 char *slap_known_controls[SLAP_MAX_CIDS+1];
96 static int num_known_controls = 1;
98 static char *proxy_authz_extops[] = {
99 LDAP_EXOP_MODIFY_PASSWD,
105 static char *manageDSAit_extops[] = {
110 static struct slap_control control_defs[] = {
111 { LDAP_CONTROL_ASSERT,
112 (int)offsetof(struct slap_control_ids, sc_assert),
113 SLAP_CTRL_DELETE|SLAP_CTRL_MODIFY|SLAP_CTRL_RENAME|
114 SLAP_CTRL_COMPARE|SLAP_CTRL_SEARCH,
116 parseAssert, LDAP_SLIST_ENTRY_INITIALIZER(next) },
117 { LDAP_CONTROL_PRE_READ,
118 (int)offsetof(struct slap_control_ids, sc_preRead),
119 SLAP_CTRL_DELETE|SLAP_CTRL_MODIFY|SLAP_CTRL_RENAME,
121 parsePreRead, LDAP_SLIST_ENTRY_INITIALIZER(next) },
122 { LDAP_CONTROL_POST_READ,
123 (int)offsetof(struct slap_control_ids, sc_postRead),
124 SLAP_CTRL_ADD|SLAP_CTRL_MODIFY|SLAP_CTRL_RENAME,
126 parsePostRead, LDAP_SLIST_ENTRY_INITIALIZER(next) },
127 { LDAP_CONTROL_VALUESRETURNFILTER,
128 (int)offsetof(struct slap_control_ids, sc_valuesReturnFilter),
129 SLAP_CTRL_GLOBAL|SLAP_CTRL_SEARCH,
131 parseValuesReturnFilter, LDAP_SLIST_ENTRY_INITIALIZER(next) },
132 { LDAP_CONTROL_PAGEDRESULTS,
133 (int)offsetof(struct slap_control_ids, sc_pagedResults),
136 parsePagedResults, LDAP_SLIST_ENTRY_INITIALIZER(next) },
137 #ifdef SLAP_CONTROL_X_SORTEDRESULTS
138 { LDAP_CONTROL_SORTREQUEST,
139 (int)offsetof(struct slap_control_ids, sc_sortedResults),
140 SLAP_CTRL_GLOBAL|SLAP_CTRL_SEARCH|SLAP_CTRL_HIDE,
142 parseSortedResults, LDAP_SLIST_ENTRY_INITIALIZER(next) },
144 { LDAP_CONTROL_X_DOMAIN_SCOPE,
145 (int)offsetof(struct slap_control_ids, sc_domainScope),
146 SLAP_CTRL_GLOBAL|SLAP_CTRL_SEARCH|SLAP_CTRL_HIDE,
148 parseDomainScope, LDAP_SLIST_ENTRY_INITIALIZER(next) },
149 { LDAP_CONTROL_DONTUSECOPY,
150 (int)offsetof(struct slap_control_ids, sc_dontUseCopy),
151 SLAP_CTRL_GLOBAL|SLAP_CTRL_INTROGATE|SLAP_CTRL_HIDE,
153 parseDontUseCopy, LDAP_SLIST_ENTRY_INITIALIZER(next) },
154 { LDAP_CONTROL_X_PERMISSIVE_MODIFY,
155 (int)offsetof(struct slap_control_ids, sc_permissiveModify),
156 SLAP_CTRL_MODIFY|SLAP_CTRL_HIDE,
158 parsePermissiveModify, LDAP_SLIST_ENTRY_INITIALIZER(next) },
159 #ifdef SLAP_CONTROL_X_TREE_DELETE
160 { LDAP_CONTROL_X_TREE_DELETE,
161 (int)offsetof(struct slap_control_ids, sc_treeDelete),
162 SLAP_CTRL_DELETE|SLAP_CTRL_HIDE,
164 parseTreeDelete, LDAP_SLIST_ENTRY_INITIALIZER(next) },
166 { LDAP_CONTROL_X_SEARCH_OPTIONS,
167 (int)offsetof(struct slap_control_ids, sc_searchOptions),
168 SLAP_CTRL_GLOBAL|SLAP_CTRL_SEARCH|SLAP_CTRL_HIDE,
170 parseSearchOptions, LDAP_SLIST_ENTRY_INITIALIZER(next) },
171 { LDAP_CONTROL_SUBENTRIES,
172 (int)offsetof(struct slap_control_ids, sc_subentries),
175 parseSubentries, LDAP_SLIST_ENTRY_INITIALIZER(next) },
177 (int)offsetof(struct slap_control_ids, sc_noOp),
178 SLAP_CTRL_ACCESS|SLAP_CTRL_HIDE,
180 parseNoOp, LDAP_SLIST_ENTRY_INITIALIZER(next) },
181 { LDAP_CONTROL_RELAX,
182 (int)offsetof(struct slap_control_ids, sc_relax),
183 SLAP_CTRL_GLOBAL|SLAP_CTRL_UPDATE|SLAP_CTRL_HIDE,
185 parseRelax, LDAP_SLIST_ENTRY_INITIALIZER(next) },
187 { LDAP_CONTROL_X_TXN_SPEC,
188 (int)offsetof(struct slap_control_ids, sc_txnSpec),
189 SLAP_CTRL_UPDATE|SLAP_CTRL_HIDE,
191 txn_spec_ctrl, LDAP_SLIST_ENTRY_INITIALIZER(next) },
193 { LDAP_CONTROL_MANAGEDSAIT,
194 (int)offsetof(struct slap_control_ids, sc_manageDSAit),
196 manageDSAit_extops, NULL,
197 parseManageDSAit, LDAP_SLIST_ENTRY_INITIALIZER(next) },
198 { LDAP_CONTROL_PROXY_AUTHZ,
199 (int)offsetof(struct slap_control_ids, sc_proxyAuthz),
200 SLAP_CTRL_GLOBAL|SLAP_CTRL_ACCESS,
201 proxy_authz_extops, NULL,
202 parseProxyAuthz, LDAP_SLIST_ENTRY_INITIALIZER(next) },
203 #ifdef SLAP_CONTROL_X_SESSION_TRACKING
204 { LDAP_CONTROL_X_SESSION_TRACKING,
205 (int)offsetof(struct slap_control_ids, sc_sessionTracking),
206 SLAP_CTRL_GLOBAL|SLAP_CTRL_ACCESS|SLAP_CTRL_BIND|SLAP_CTRL_HIDE,
208 parseSessionTracking, LDAP_SLIST_ENTRY_INITIALIZER(next) },
210 { NULL, 0, 0, NULL, 0, NULL, LDAP_SLIST_ENTRY_INITIALIZER(next) }
213 static struct slap_control *
214 find_ctrl( const char *oid );
217 * Register a supported control.
219 * This can be called by an OpenLDAP plugin or, indirectly, by a
220 * SLAPI plugin calling slapi_register_supported_control().
222 * NOTE: if flags == 1 the control is replaced if already registered;
223 * otherwise registering an already registered control is not allowed.
226 register_supported_control2(const char *controloid,
227 slap_mask_t controlmask,
229 SLAP_CTRL_PARSE_FN *controlparsefn,
233 struct slap_control *sc = NULL;
235 BerVarray extendedopsbv = NULL;
237 if ( num_known_controls >= SLAP_MAX_CIDS ) {
238 Debug( LDAP_DEBUG_ANY, "Too many controls registered."
239 " Recompile slapd with SLAP_MAX_CIDS defined > %d\n",
240 SLAP_MAX_CIDS, 0, 0 );
244 if ( controloid == NULL ) {
245 return LDAP_PARAM_ERROR;
248 /* check if already registered */
249 for ( i = 0; slap_known_controls[ i ]; i++ ) {
250 if ( strcmp( controloid, slap_known_controls[ i ] ) == 0 ) {
252 Debug( LDAP_DEBUG_TRACE,
253 "Control %s already registered; replacing.\n",
255 /* (find and) replace existing handler */
256 sc = find_ctrl( controloid );
257 assert( sc != NULL );
261 Debug( LDAP_DEBUG_ANY,
262 "Control %s already registered.\n",
264 return LDAP_PARAM_ERROR;
268 /* turn compatible extended operations into bervals */
269 if ( controlexops != NULL ) {
272 for ( i = 0; controlexops[ i ]; i++ );
274 extendedopsbv = ber_memcalloc( i + 1, sizeof( struct berval ) );
275 if ( extendedopsbv == NULL ) {
276 return LDAP_NO_MEMORY;
279 for ( i = 0; controlexops[ i ]; i++ ) {
280 ber_str2bv( controlexops[ i ], 0, 1, &extendedopsbv[ i ] );
285 sc = (struct slap_control *)SLAP_MALLOC( sizeof( *sc ) );
287 return LDAP_NO_MEMORY;
290 sc->sc_oid = ch_strdup( controloid );
291 sc->sc_cid = num_known_controls;
293 /* Update slap_known_controls, too. */
294 slap_known_controls[num_known_controls - 1] = sc->sc_oid;
295 slap_known_controls[num_known_controls++] = NULL;
297 LDAP_SLIST_NEXT( sc, sc_next ) = NULL;
298 LDAP_SLIST_INSERT_HEAD( &controls_list, sc, sc_next );
301 if ( sc->sc_extendedopsbv ) {
302 /* FIXME: in principle, we should rather merge
303 * existing extops with those supported by the
304 * new control handling implementation.
305 * In fact, whether a control is compatible with
306 * an extop should not be a matter of implementation.
307 * We likely also need a means for a newly
308 * registered extop to declare that it is
309 * comptible with an already registered control.
311 ber_bvarray_free( sc->sc_extendedopsbv );
312 sc->sc_extendedopsbv = NULL;
313 sc->sc_extendedops = NULL;
317 sc->sc_extendedopsbv = extendedopsbv;
318 sc->sc_mask = controlmask;
319 sc->sc_parse = controlparsefn;
321 *controlcid = sc->sc_cid;
328 * One-time initialization of internal controls.
331 slap_controls_init( void )
337 for ( i = 0; control_defs[i].sc_oid != NULL; i++ ) {
338 int *cid = (int *)(((char *)&slap_cids) + control_defs[i].sc_cid );
339 rc = register_supported_control( control_defs[i].sc_oid,
340 control_defs[i].sc_mask, control_defs[i].sc_extendedops,
341 control_defs[i].sc_parse, cid );
342 if ( rc != LDAP_SUCCESS ) break;
349 * Free memory associated with list of supported controls.
352 controls_destroy( void )
354 struct slap_control *sc;
356 while ( !LDAP_SLIST_EMPTY(&controls_list) ) {
357 sc = LDAP_SLIST_FIRST(&controls_list);
358 LDAP_SLIST_REMOVE_HEAD(&controls_list, sc_next);
360 ch_free( sc->sc_oid );
361 if ( sc->sc_extendedopsbv != NULL ) {
362 ber_bvarray_free( sc->sc_extendedopsbv );
369 * Format the supportedControl attribute of the root DSE,
370 * detailing which controls are supported by the directory
374 controls_root_dse_info( Entry *e )
376 AttributeDescription *ad_supportedControl
377 = slap_schema.si_ad_supportedControl;
378 struct berval vals[2];
379 struct slap_control *sc;
381 vals[1].bv_val = NULL;
384 LDAP_SLIST_FOREACH( sc, &controls_list, sc_next ) {
385 if( sc->sc_mask & SLAP_CTRL_HIDE ) continue;
387 vals[0].bv_val = sc->sc_oid;
388 vals[0].bv_len = strlen( sc->sc_oid );
390 if ( attr_merge( e, ad_supportedControl, vals, NULL ) ) {
399 * Return a list of OIDs and operation masks for supported
400 * controls. Used by SLAPI.
403 get_supported_controls(char ***ctrloidsp,
404 slap_mask_t **ctrlmasks)
409 struct slap_control *sc;
413 LDAP_SLIST_FOREACH( sc, &controls_list, sc_next ) {
423 oids = (char **)SLAP_MALLOC( (n + 1) * sizeof(char *) );
424 if ( oids == NULL ) {
425 return LDAP_NO_MEMORY;
427 masks = (slap_mask_t *)SLAP_MALLOC( (n + 1) * sizeof(slap_mask_t) );
428 if ( masks == NULL ) {
430 return LDAP_NO_MEMORY;
435 LDAP_SLIST_FOREACH( sc, &controls_list, sc_next ) {
436 oids[n] = ch_strdup( sc->sc_oid );
437 masks[n] = sc->sc_mask;
450 * Find a control given its OID.
452 static struct slap_control *
453 find_ctrl( const char *oid )
455 struct slap_control *sc;
457 LDAP_SLIST_FOREACH( sc, &controls_list, sc_next ) {
458 if ( strcmp( oid, sc->sc_oid ) == 0 ) {
467 slap_find_control_id(
471 struct slap_control *ctrl = find_ctrl( oid );
473 if ( cid ) *cid = ctrl->sc_cid;
476 return LDAP_CONTROL_NOT_FOUND;
480 slap_global_control( Operation *op, const char *oid, int *cid )
482 struct slap_control *ctrl = find_ctrl( oid );
484 if ( ctrl == NULL ) {
485 /* should not be reachable */
486 Debug( LDAP_DEBUG_ANY,
487 "slap_global_control: unrecognized control: %s\n",
489 return LDAP_CONTROL_NOT_FOUND;
492 if ( cid ) *cid = ctrl->sc_cid;
494 if ( ( ctrl->sc_mask & SLAP_CTRL_GLOBAL ) ||
495 ( ( op->o_tag & LDAP_REQ_SEARCH ) &&
496 ( ctrl->sc_mask & SLAP_CTRL_GLOBAL_SEARCH ) ) )
498 return LDAP_COMPARE_TRUE;
502 Debug( LDAP_DEBUG_TRACE,
503 "slap_global_control: unavailable control: %s\n",
507 return LDAP_COMPARE_FALSE;
510 void slap_free_ctrls(
512 LDAPControl **ctrls )
516 for (i=0; ctrls[i]; i++) {
517 op->o_tmpfree(ctrls[i], op->o_tmpmemctx );
519 op->o_tmpfree( ctrls, op->o_tmpmemctx );
525 LDAPControl *control,
528 struct slap_control *sc;
530 sc = find_ctrl( control->ldctl_oid );
532 /* recognized control */
534 switch( op->o_tag ) {
536 tagmask = SLAP_CTRL_ADD;
539 tagmask = SLAP_CTRL_BIND;
541 case LDAP_REQ_COMPARE:
542 tagmask = SLAP_CTRL_COMPARE;
544 case LDAP_REQ_DELETE:
545 tagmask = SLAP_CTRL_DELETE;
547 case LDAP_REQ_MODIFY:
548 tagmask = SLAP_CTRL_MODIFY;
550 case LDAP_REQ_RENAME:
551 tagmask = SLAP_CTRL_RENAME;
553 case LDAP_REQ_SEARCH:
554 tagmask = SLAP_CTRL_SEARCH;
556 case LDAP_REQ_UNBIND:
557 tagmask = SLAP_CTRL_UNBIND;
559 case LDAP_REQ_ABANDON:
560 tagmask = SLAP_CTRL_ABANDON;
562 case LDAP_REQ_EXTENDED:
564 assert( op->ore_reqoid.bv_val != NULL );
565 if( sc->sc_extendedopsbv != NULL ) {
567 for( i=0; !BER_BVISNULL( &sc->sc_extendedopsbv[i] ); i++ ) {
568 if( bvmatch( &op->ore_reqoid,
569 &sc->sc_extendedopsbv[i] ) )
578 *text = "controls internal error";
582 if (( sc->sc_mask & tagmask ) == tagmask ) {
583 /* available extension */
586 if( !sc->sc_parse ) {
587 *text = "not yet implemented";
591 rc = sc->sc_parse( op, rs, control );
593 assert( rc != LDAP_UNAVAILABLE_CRITICAL_EXTENSION );
597 } else if( control->ldctl_iscritical ) {
598 /* unavailable CRITICAL control */
599 *text = "critical extension is unavailable";
600 return LDAP_UNAVAILABLE_CRITICAL_EXTENSION;
602 } else if( control->ldctl_iscritical ) {
603 /* unrecognized CRITICAL control */
604 *text = "critical extension is not recognized";
605 return LDAP_UNAVAILABLE_CRITICAL_EXTENSION;
620 BerElement *ber = op->o_ber;
623 len = ber_pvt_ber_remaining(ber);
627 rs->sr_err = LDAP_SUCCESS;
631 if(( tag = ber_peek_tag( ber, &len )) != LDAP_TAG_CONTROLS ) {
632 if( tag == LBER_ERROR ) {
633 rs->sr_err = SLAPD_DISCONNECT;
634 rs->sr_text = "unexpected data in PDU";
640 Debug( LDAP_DEBUG_TRACE,
641 "=> get_ctrls\n", 0, 0, 0 );
643 if( op->o_protocol < LDAP_VERSION3 ) {
644 rs->sr_err = SLAPD_DISCONNECT;
645 rs->sr_text = "controls require LDAPv3";
649 /* one for first control, one for termination */
650 op->o_ctrls = op->o_tmpalloc( 2 * sizeof(LDAPControl *), op->o_tmpmemctx );
653 if( op->ctrls == NULL ) {
654 rs->sr_err = LDAP_NO_MEMORY;
655 rs->sr_text = "no memory";
660 op->o_ctrls[nctrls] = NULL;
662 /* step through each element */
663 for( tag = ber_first_element( ber, &len, &opaque );
665 tag = ber_next_element( ber, &len, opaque ) )
668 LDAPControl **tctrls;
670 c = op->o_tmpalloc( sizeof(LDAPControl), op->o_tmpmemctx );
671 memset(c, 0, sizeof(LDAPControl));
673 /* allocate pointer space for current controls (nctrls)
674 * + this control + extra NULL
676 tctrls = op->o_tmprealloc( op->o_ctrls,
677 (nctrls+2) * sizeof(LDAPControl *), op->o_tmpmemctx );
680 if( tctrls == NULL ) {
682 ldap_controls_free(op->o_ctrls);
685 rs->sr_err = LDAP_NO_MEMORY;
686 rs->sr_text = "no memory";
690 op->o_ctrls = tctrls;
692 op->o_ctrls[nctrls++] = c;
693 op->o_ctrls[nctrls] = NULL;
695 tag = ber_scanf( ber, "{m" /*}*/, &bv );
696 c->ldctl_oid = bv.bv_val;
698 if( tag == LBER_ERROR ) {
699 Debug( LDAP_DEBUG_TRACE, "=> get_ctrls: get oid failed.\n",
702 slap_free_ctrls( op, op->o_ctrls );
704 rs->sr_err = SLAPD_DISCONNECT;
705 rs->sr_text = "decoding controls error";
708 } else if( c->ldctl_oid == NULL ) {
709 Debug( LDAP_DEBUG_TRACE,
710 "get_ctrls: conn %lu got emtpy OID.\n",
711 op->o_connid, 0, 0 );
713 slap_free_ctrls( op, op->o_ctrls );
715 rs->sr_err = LDAP_PROTOCOL_ERROR;
716 rs->sr_text = "OID field is empty";
720 tag = ber_peek_tag( ber, &len );
722 if( tag == LBER_BOOLEAN ) {
724 tag = ber_scanf( ber, "b", &crit );
726 if( tag == LBER_ERROR ) {
727 Debug( LDAP_DEBUG_TRACE, "=> get_ctrls: get crit failed.\n",
729 slap_free_ctrls( op, op->o_ctrls );
731 rs->sr_err = SLAPD_DISCONNECT;
732 rs->sr_text = "decoding controls error";
736 c->ldctl_iscritical = (crit != 0);
737 tag = ber_peek_tag( ber, &len );
740 if( tag == LBER_OCTETSTRING ) {
741 tag = ber_scanf( ber, "m", &c->ldctl_value );
743 if( tag == LBER_ERROR ) {
744 Debug( LDAP_DEBUG_TRACE, "=> get_ctrls: conn %lu: "
745 "%s (%scritical): get value failed.\n",
746 op->o_connid, c->ldctl_oid,
747 c->ldctl_iscritical ? "" : "non" );
748 slap_free_ctrls( op, op->o_ctrls );
750 rs->sr_err = SLAPD_DISCONNECT;
751 rs->sr_text = "decoding controls error";
756 Debug( LDAP_DEBUG_TRACE,
757 "=> get_ctrls: oid=\"%s\" (%scritical)\n",
758 c->ldctl_oid, c->ldctl_iscritical ? "" : "non", 0 );
760 rs->sr_err = slap_parse_ctrl( op, rs, c, &rs->sr_text );
761 if ( rs->sr_err != LDAP_SUCCESS ) {
767 Debug( LDAP_DEBUG_TRACE,
768 "<= get_ctrls: n=%d rc=%d err=\"%s\"\n",
769 nctrls, rs->sr_err, rs->sr_text ? rs->sr_text : "");
771 if( sendres && rs->sr_err != LDAP_SUCCESS ) {
772 if( rs->sr_err == SLAPD_DISCONNECT ) {
773 rs->sr_err = LDAP_PROTOCOL_ERROR;
774 send_ldap_disconnect( op, rs );
775 rs->sr_err = SLAPD_DISCONNECT;
777 send_ldap_result( op, rs );
789 BI_chk_controls fnc )
793 switch ( op->o_ctrlflag[ ctrl ] ) {
794 case SLAP_CONTROL_NONCRITICAL:
795 for ( i = 0, j = -1; op->o_ctrls[ i ] != NULL; i++ ) {
796 if ( strcmp( op->o_ctrls[ i ]->ldctl_oid,
797 slap_known_controls[ ctrl - 1 ] ) == 0 )
804 rs->sr_err = LDAP_OTHER;
812 op->o_tmpfree( op->o_ctrls[ j ], op->o_tmpmemctx );
815 AC_MEMCPY( &op->o_ctrls[ j ], &op->o_ctrls[ j + 1 ],
816 ( i - j ) * sizeof( LDAPControl * ) );
819 op->o_tmpfree( op->o_ctrls, op->o_tmpmemctx );
823 op->o_ctrlflag[ ctrl ] = SLAP_CONTROL_IGNORED;
825 Debug( LDAP_DEBUG_ANY, "%s: "
826 "non-critical control \"%s\" not supported; stripped.\n",
827 op->o_log_prefix, slap_known_controls[ ctrl ], 0 );
830 case SLAP_CONTROL_IGNORED:
831 case SLAP_CONTROL_NONE:
832 rs->sr_err = SLAP_CB_CONTINUE;
835 case SLAP_CONTROL_CRITICAL:
836 rs->sr_err = LDAP_UNAVAILABLE_CRITICAL_EXTENSION;
840 Debug( LDAP_DEBUG_ANY, "%s: "
841 "critical control \"%s\" not supported.\n",
842 op->o_log_prefix, slap_known_controls[ ctrl ], 0 );
846 /* handle all cases! */
853 static int parseDontUseCopy (
858 if ( op->o_dontUseCopy != SLAP_CONTROL_NONE ) {
859 rs->sr_text = "dontUseCopy control specified multiple times";
860 return LDAP_PROTOCOL_ERROR;
863 if ( !BER_BVISNULL( &ctrl->ldctl_value )) {
864 rs->sr_text = "dontUseCopy control value not absent";
865 return LDAP_PROTOCOL_ERROR;
868 if ( !ctrl->ldctl_iscritical ) {
869 rs->sr_text = "dontUseCopy criticality of FALSE not allowed";
870 return LDAP_PROTOCOL_ERROR;
873 op->o_dontUseCopy = SLAP_CONTROL_CRITICAL;
877 static int parseRelax (
882 if ( op->o_relax != SLAP_CONTROL_NONE ) {
883 rs->sr_text = "relax control specified multiple times";
884 return LDAP_PROTOCOL_ERROR;
887 if ( !BER_BVISNULL( &ctrl->ldctl_value )) {
888 rs->sr_text = "relax control value not absent";
889 return LDAP_PROTOCOL_ERROR;
892 op->o_relax = ctrl->ldctl_iscritical
893 ? SLAP_CONTROL_CRITICAL
894 : SLAP_CONTROL_NONCRITICAL;
899 static int parseManageDSAit (
904 if ( op->o_managedsait != SLAP_CONTROL_NONE ) {
905 rs->sr_text = "manageDSAit control specified multiple times";
906 return LDAP_PROTOCOL_ERROR;
909 if ( !BER_BVISNULL( &ctrl->ldctl_value )) {
910 rs->sr_text = "manageDSAit control value not absent";
911 return LDAP_PROTOCOL_ERROR;
914 op->o_managedsait = ctrl->ldctl_iscritical
915 ? SLAP_CONTROL_CRITICAL
916 : SLAP_CONTROL_NONCRITICAL;
921 static int parseProxyAuthz (
927 struct berval dn = BER_BVNULL;
929 if ( op->o_proxy_authz != SLAP_CONTROL_NONE ) {
930 rs->sr_text = "proxy authorization control specified multiple times";
931 return LDAP_PROTOCOL_ERROR;
934 if ( BER_BVISNULL( &ctrl->ldctl_value )) {
935 rs->sr_text = "proxy authorization control value absent";
936 return LDAP_PROTOCOL_ERROR;
939 if ( !( global_allows & SLAP_ALLOW_PROXY_AUTHZ_ANON )
940 && BER_BVISEMPTY( &op->o_ndn ) )
942 rs->sr_text = "anonymous proxied authorization not allowed";
943 return LDAP_PROXIED_AUTHORIZATION_DENIED;
946 op->o_proxy_authz = ctrl->ldctl_iscritical
947 ? SLAP_CONTROL_CRITICAL
948 : SLAP_CONTROL_NONCRITICAL;
950 Debug( LDAP_DEBUG_ARGS,
951 "parseProxyAuthz: conn %lu authzid=\"%s\"\n",
953 ctrl->ldctl_value.bv_len ? ctrl->ldctl_value.bv_val : "anonymous",
956 if ( BER_BVISEMPTY( &ctrl->ldctl_value )) {
957 Debug( LDAP_DEBUG_TRACE,
958 "parseProxyAuthz: conn=%lu anonymous\n",
959 op->o_connid, 0, 0 );
962 if ( !BER_BVISNULL( &op->o_ndn ) ) {
963 op->o_ndn.bv_val[ 0 ] = '\0';
965 op->o_ndn.bv_len = 0;
967 if ( !BER_BVISNULL( &op->o_dn ) ) {
968 op->o_dn.bv_val[ 0 ] = '\0';
975 rc = slap_sasl_getdn( op->o_conn, op, &ctrl->ldctl_value,
976 NULL, &dn, SLAP_GETDN_AUTHZID );
978 /* FIXME: empty DN in proxyAuthz control should be legal... */
979 if( rc != LDAP_SUCCESS /* || !dn.bv_len */ ) {
981 ch_free( dn.bv_val );
983 rs->sr_text = "authzId mapping failed";
984 return LDAP_PROXIED_AUTHORIZATION_DENIED;
987 Debug( LDAP_DEBUG_TRACE,
988 "parseProxyAuthz: conn=%lu \"%s\"\n",
990 dn.bv_len ? dn.bv_val : "(NULL)", 0 );
992 rc = slap_sasl_authorized( op, &op->o_ndn, &dn );
995 ch_free( dn.bv_val );
996 rs->sr_text = "not authorized to assume identity";
997 return LDAP_PROXIED_AUTHORIZATION_DENIED;
1000 ch_free( op->o_ndn.bv_val );
1001 ch_free( op->o_dn.bv_val );
1004 * NOTE: since slap_sasl_getdn() returns a normalized dn,
1005 * from now on op->o_dn is normalized
1008 ber_dupbv( &op->o_dn, &dn );
1010 Statslog( LDAP_DEBUG_STATS, "%s PROXYAUTHZ dn=\"%s\"\n",
1011 op->o_log_prefix, dn.bv_val, 0, 0, 0 );
1013 return LDAP_SUCCESS;
1016 static int parseNoOp (
1021 if ( op->o_noop != SLAP_CONTROL_NONE ) {
1022 rs->sr_text = "noop control specified multiple times";
1023 return LDAP_PROTOCOL_ERROR;
1026 if ( !BER_BVISNULL( &ctrl->ldctl_value ) ) {
1027 rs->sr_text = "noop control value not empty";
1028 return LDAP_PROTOCOL_ERROR;
1031 op->o_noop = ctrl->ldctl_iscritical
1032 ? SLAP_CONTROL_CRITICAL
1033 : SLAP_CONTROL_NONCRITICAL;
1035 return LDAP_SUCCESS;
1038 static int parsePagedResults (
1043 int rc = LDAP_SUCCESS;
1047 struct berval cookie = BER_BVNULL;
1048 PagedResultsState *ps;
1050 if ( op->o_pagedresults != SLAP_CONTROL_NONE ) {
1051 rs->sr_text = "paged results control specified multiple times";
1052 return LDAP_PROTOCOL_ERROR;
1055 if ( BER_BVISNULL( &ctrl->ldctl_value ) ) {
1056 rs->sr_text = "paged results control value is absent";
1057 return LDAP_PROTOCOL_ERROR;
1060 if ( BER_BVISEMPTY( &ctrl->ldctl_value ) ) {
1061 rs->sr_text = "paged results control value is empty";
1062 return LDAP_PROTOCOL_ERROR;
1065 /* Parse the control value
1066 * realSearchControlValue ::= SEQUENCE {
1067 * size INTEGER (0..maxInt),
1068 * -- requested page size from client
1069 * -- result set size estimate from server
1070 * cookie OCTET STRING
1073 ber = ber_init( &ctrl->ldctl_value );
1074 if ( ber == NULL ) {
1075 rs->sr_text = "internal error";
1079 tag = ber_scanf( ber, "{im}", &size, &cookie );
1081 if ( tag == LBER_ERROR ) {
1082 rs->sr_text = "paged results control could not be decoded";
1083 rc = LDAP_PROTOCOL_ERROR;
1088 rs->sr_text = "paged results control size invalid";
1089 rc = LDAP_PROTOCOL_ERROR;
1093 ps = op->o_tmpalloc( sizeof(PagedResultsState), op->o_tmpmemctx );
1094 *ps = op->o_conn->c_pagedresults_state;
1096 op->o_pagedresults_state = ps;
1098 /* NOTE: according to RFC 2696 3.:
1100 If the page size is greater than or equal to the sizeLimit value, the
1101 server should ignore the control as the request can be satisfied in a
1104 * NOTE: this assumes that the op->ors_slimit be set
1105 * before the controls are parsed.
1108 if ( op->ors_slimit > 0 && size >= op->ors_slimit ) {
1109 op->o_pagedresults = SLAP_CONTROL_IGNORED;
1111 } else if ( ctrl->ldctl_iscritical ) {
1112 op->o_pagedresults = SLAP_CONTROL_CRITICAL;
1115 op->o_pagedresults = SLAP_CONTROL_NONCRITICAL;
1119 (void)ber_free( ber, 1 );
1123 #ifdef SLAP_CONTROL_X_SORTEDRESULTS
1124 static int parseSortedResults (
1129 int rc = LDAP_SUCCESS;
1131 if ( op->o_sortedresults != SLAP_CONTROL_NONE ) {
1132 rs->sr_text = "sorted results control specified multiple times";
1133 return LDAP_PROTOCOL_ERROR;
1136 if ( BER_BVISNULL( &ctrl->ldctl_value ) ) {
1137 rs->sr_text = "sorted results control value is absent";
1138 return LDAP_PROTOCOL_ERROR;
1141 if ( BER_BVISEMPTY( &ctrl->ldctl_value ) ) {
1142 rs->sr_text = "sorted results control value is empty";
1143 return LDAP_PROTOCOL_ERROR;
1146 /* blow off parsing the value */
1148 op->o_sortedresults = ctrl->ldctl_iscritical
1149 ? SLAP_CONTROL_CRITICAL
1150 : SLAP_CONTROL_NONCRITICAL;
1156 static int parseAssert (
1162 struct berval fstr = BER_BVNULL;
1164 if ( op->o_assert != SLAP_CONTROL_NONE ) {
1165 rs->sr_text = "assert control specified multiple times";
1166 return LDAP_PROTOCOL_ERROR;
1169 if ( BER_BVISNULL( &ctrl->ldctl_value )) {
1170 rs->sr_text = "assert control value is absent";
1171 return LDAP_PROTOCOL_ERROR;
1174 if ( BER_BVISEMPTY( &ctrl->ldctl_value )) {
1175 rs->sr_text = "assert control value is empty";
1176 return LDAP_PROTOCOL_ERROR;
1179 ber = ber_init( &(ctrl->ldctl_value) );
1181 rs->sr_text = "assert control: internal error";
1185 rs->sr_err = get_filter( op, ber, (Filter **)&(op->o_assertion),
1187 (void) ber_free( ber, 1 );
1188 if( rs->sr_err != LDAP_SUCCESS ) {
1189 if( rs->sr_err == SLAPD_DISCONNECT ) {
1190 rs->sr_err = LDAP_PROTOCOL_ERROR;
1191 send_ldap_disconnect( op, rs );
1192 rs->sr_err = SLAPD_DISCONNECT;
1194 send_ldap_result( op, rs );
1196 if( op->o_assertion != NULL ) {
1197 filter_free_x( op, op->o_assertion );
1203 filter2bv_x( op, op->o_assertion, &fstr );
1205 Debug( LDAP_DEBUG_ARGS, "parseAssert: conn %ld assert: %s\n",
1206 op->o_connid, fstr.bv_len ? fstr.bv_val : "empty" , 0 );
1207 op->o_tmpfree( fstr.bv_val, op->o_tmpmemctx );
1210 op->o_assert = ctrl->ldctl_iscritical
1211 ? SLAP_CONTROL_CRITICAL
1212 : SLAP_CONTROL_NONCRITICAL;
1214 rs->sr_err = LDAP_SUCCESS;
1215 return LDAP_SUCCESS;
1218 static int parsePreRead (
1223 ber_len_t siz, off, i;
1224 AttributeName *an = NULL;
1227 if ( op->o_preread != SLAP_CONTROL_NONE ) {
1228 rs->sr_text = "preread control specified multiple times";
1229 return LDAP_PROTOCOL_ERROR;
1232 if ( BER_BVISNULL( &ctrl->ldctl_value )) {
1233 rs->sr_text = "preread control value is absent";
1234 return LDAP_PROTOCOL_ERROR;
1237 if ( BER_BVISEMPTY( &ctrl->ldctl_value )) {
1238 rs->sr_text = "preread control value is empty";
1239 return LDAP_PROTOCOL_ERROR;
1243 if ( op->o_txnSpec ) { /* temporary limitation */
1244 rs->sr_text = "cannot perform pre-read in transaction";
1245 return LDAP_UNWILLING_TO_PERFORM;
1249 ber = ber_init( &(ctrl->ldctl_value) );
1251 rs->sr_text = "preread control: internal error";
1255 rs->sr_err = LDAP_SUCCESS;
1257 siz = sizeof( AttributeName );
1258 off = offsetof( AttributeName, an_name );
1259 if ( ber_scanf( ber, "{M}", &an, &siz, off ) == LBER_ERROR ) {
1260 rs->sr_text = "preread control: decoding error";
1261 rs->sr_err = LDAP_PROTOCOL_ERROR;
1265 for( i=0; i<siz; i++ ) {
1266 const char *dummy = NULL;
1268 an[i].an_desc = NULL;
1270 an[i].an_oc_exclude = 0;
1271 rs->sr_err = slap_bv2ad( &an[i].an_name, &an[i].an_desc, &dummy );
1272 if ( rs->sr_err != LDAP_SUCCESS && ctrl->ldctl_iscritical ) {
1275 : "postread control: unknown attributeType";
1280 op->o_preread = ctrl->ldctl_iscritical
1281 ? SLAP_CONTROL_CRITICAL
1282 : SLAP_CONTROL_NONCRITICAL;
1284 op->o_preread_attrs = an;
1287 (void) ber_free( ber, 1 );
1291 static int parsePostRead (
1296 ber_len_t siz, off, i;
1297 AttributeName *an = NULL;
1300 if ( op->o_postread != SLAP_CONTROL_NONE ) {
1301 rs->sr_text = "postread control specified multiple times";
1302 return LDAP_PROTOCOL_ERROR;
1305 if ( BER_BVISNULL( &ctrl->ldctl_value )) {
1306 rs->sr_text = "postread control value is absent";
1307 return LDAP_PROTOCOL_ERROR;
1310 if ( BER_BVISEMPTY( &ctrl->ldctl_value )) {
1311 rs->sr_text = "postread control value is empty";
1312 return LDAP_PROTOCOL_ERROR;
1316 if ( op->o_txnSpec ) { /* temporary limitation */
1317 rs->sr_text = "cannot perform post-read in transaction";
1318 return LDAP_UNWILLING_TO_PERFORM;
1322 ber = ber_init( &(ctrl->ldctl_value) );
1324 rs->sr_text = "postread control: internal error";
1328 rs->sr_err = LDAP_SUCCESS;
1329 siz = sizeof( AttributeName );
1330 off = offsetof( AttributeName, an_name );
1331 if ( ber_scanf( ber, "{M}", &an, &siz, off ) == LBER_ERROR ) {
1332 rs->sr_text = "postread control: decoding error";
1333 rs->sr_err = LDAP_PROTOCOL_ERROR;
1337 for ( i = 0; i < siz; i++ ) {
1338 const char *dummy = NULL;
1341 an[i].an_desc = NULL;
1343 an[i].an_oc_exclude = 0;
1344 rc = slap_bv2ad( &an[i].an_name, &an[i].an_desc, &dummy );
1345 if ( rc != LDAP_SUCCESS ) {
1347 static struct berval special_attrs[] = {
1348 BER_BVC( LDAP_NO_ATTRS ),
1349 BER_BVC( LDAP_ALL_USER_ATTRIBUTES ),
1350 BER_BVC( LDAP_ALL_OPERATIONAL_ATTRIBUTES ),
1354 /* deal with special attribute types */
1355 for ( i = 0; !BER_BVISNULL( &special_attrs[ i ] ); i++ ) {
1356 if ( bvmatch( &an[i].an_name, &special_attrs[ i ] ) ) {
1361 if ( BER_BVISNULL( &special_attrs[ i ] ) && ctrl->ldctl_iscritical ) {
1365 : "postread control: unknown attributeType";
1371 op->o_postread = ctrl->ldctl_iscritical
1372 ? SLAP_CONTROL_CRITICAL
1373 : SLAP_CONTROL_NONCRITICAL;
1375 op->o_postread_attrs = an;
1378 (void) ber_free( ber, 1 );
1382 static int parseValuesReturnFilter (
1388 struct berval fstr = BER_BVNULL;
1390 if ( op->o_valuesreturnfilter != SLAP_CONTROL_NONE ) {
1391 rs->sr_text = "valuesReturnFilter control specified multiple times";
1392 return LDAP_PROTOCOL_ERROR;
1395 if ( BER_BVISNULL( &ctrl->ldctl_value )) {
1396 rs->sr_text = "valuesReturnFilter control value is absent";
1397 return LDAP_PROTOCOL_ERROR;
1400 if ( BER_BVISEMPTY( &ctrl->ldctl_value )) {
1401 rs->sr_text = "valuesReturnFilter control value is empty";
1402 return LDAP_PROTOCOL_ERROR;
1405 ber = ber_init( &(ctrl->ldctl_value) );
1407 rs->sr_text = "internal error";
1411 rs->sr_err = get_vrFilter( op, ber,
1412 (ValuesReturnFilter **)&(op->o_vrFilter), &rs->sr_text);
1414 (void) ber_free( ber, 1 );
1416 if( rs->sr_err != LDAP_SUCCESS ) {
1417 if( rs->sr_err == SLAPD_DISCONNECT ) {
1418 rs->sr_err = LDAP_PROTOCOL_ERROR;
1419 send_ldap_disconnect( op, rs );
1420 rs->sr_err = SLAPD_DISCONNECT;
1422 send_ldap_result( op, rs );
1424 if( op->o_vrFilter != NULL) vrFilter_free( op, op->o_vrFilter );
1428 vrFilter2bv( op, op->o_vrFilter, &fstr );
1431 Debug( LDAP_DEBUG_ARGS, " vrFilter: %s\n",
1432 fstr.bv_len ? fstr.bv_val : "empty", 0, 0 );
1433 op->o_tmpfree( fstr.bv_val, op->o_tmpmemctx );
1436 op->o_valuesreturnfilter = ctrl->ldctl_iscritical
1437 ? SLAP_CONTROL_CRITICAL
1438 : SLAP_CONTROL_NONCRITICAL;
1440 rs->sr_err = LDAP_SUCCESS;
1441 return LDAP_SUCCESS;
1444 static int parseSubentries (
1449 if ( op->o_subentries != SLAP_CONTROL_NONE ) {
1450 rs->sr_text = "subentries control specified multiple times";
1451 return LDAP_PROTOCOL_ERROR;
1454 /* FIXME: should use BER library */
1455 if( ( ctrl->ldctl_value.bv_len != 3 )
1456 || ( ctrl->ldctl_value.bv_val[0] != 0x01 )
1457 || ( ctrl->ldctl_value.bv_val[1] != 0x01 ))
1459 rs->sr_text = "subentries control value encoding is bogus";
1460 return LDAP_PROTOCOL_ERROR;
1463 op->o_subentries = ctrl->ldctl_iscritical
1464 ? SLAP_CONTROL_CRITICAL
1465 : SLAP_CONTROL_NONCRITICAL;
1467 if (ctrl->ldctl_value.bv_val[2]) {
1468 set_subentries_visibility( op );
1471 return LDAP_SUCCESS;
1474 static int parsePermissiveModify (
1479 if ( op->o_permissive_modify != SLAP_CONTROL_NONE ) {
1480 rs->sr_text = "permissiveModify control specified multiple times";
1481 return LDAP_PROTOCOL_ERROR;
1484 if ( BER_BVISNULL( &ctrl->ldctl_value )) {
1485 rs->sr_text = "permissiveModify control value not absent";
1486 return LDAP_PROTOCOL_ERROR;
1489 op->o_permissive_modify = ctrl->ldctl_iscritical
1490 ? SLAP_CONTROL_CRITICAL
1491 : SLAP_CONTROL_NONCRITICAL;
1493 return LDAP_SUCCESS;
1496 static int parseDomainScope (
1501 if ( op->o_domain_scope != SLAP_CONTROL_NONE ) {
1502 rs->sr_text = "domainScope control specified multiple times";
1503 return LDAP_PROTOCOL_ERROR;
1506 if ( BER_BVISNULL( &ctrl->ldctl_value )) {
1507 rs->sr_text = "domainScope control value not empty";
1508 return LDAP_PROTOCOL_ERROR;
1511 op->o_domain_scope = ctrl->ldctl_iscritical
1512 ? SLAP_CONTROL_CRITICAL
1513 : SLAP_CONTROL_NONCRITICAL;
1515 return LDAP_SUCCESS;
1518 #ifdef SLAP_CONTROL_X_TREE_DELETE
1519 static int parseTreeDelete (
1524 if ( op->o_tree_delete != SLAP_CONTROL_NONE ) {
1525 rs->sr_text = "treeDelete control specified multiple times";
1526 return LDAP_PROTOCOL_ERROR;
1529 if ( !BER_BVISNULL( &ctrl->ldctl_value )) {
1530 rs->sr_text = "treeDelete control value not absent";
1531 return LDAP_PROTOCOL_ERROR;
1534 op->o_tree_delete = ctrl->ldctl_iscritical
1535 ? SLAP_CONTROL_CRITICAL
1536 : SLAP_CONTROL_NONCRITICAL;
1538 return LDAP_SUCCESS;
1542 static int parseSearchOptions (
1548 ber_int_t search_flags;
1551 if ( BER_BVISNULL( &ctrl->ldctl_value )) {
1552 rs->sr_text = "searchOptions control value is absent";
1553 return LDAP_PROTOCOL_ERROR;
1556 if ( BER_BVISEMPTY( &ctrl->ldctl_value )) {
1557 rs->sr_text = "searchOptions control value is empty";
1558 return LDAP_PROTOCOL_ERROR;
1561 ber = ber_init( &ctrl->ldctl_value );
1563 rs->sr_text = "internal error";
1567 tag = ber_scanf( ber, "{i}", &search_flags );
1568 (void) ber_free( ber, 1 );
1570 if ( tag == LBER_ERROR ) {
1571 rs->sr_text = "searchOptions control decoding error";
1572 return LDAP_PROTOCOL_ERROR;
1575 if ( search_flags & LDAP_SEARCH_FLAG_DOMAIN_SCOPE ) {
1576 if ( op->o_domain_scope != SLAP_CONTROL_NONE ) {
1577 rs->sr_text = "searchOptions control specified multiple times "
1578 "or with domainScope control";
1579 return LDAP_PROTOCOL_ERROR;
1582 op->o_domain_scope = ctrl->ldctl_iscritical
1583 ? SLAP_CONTROL_CRITICAL
1584 : SLAP_CONTROL_NONCRITICAL;
1587 if ( search_flags & ~(LDAP_SEARCH_FLAG_DOMAIN_SCOPE) ) {
1588 /* Other search flags not recognised so far,
1590 * LDAP_SEARCH_FLAG_PHANTOM_ROOM
1592 rs->sr_text = "searchOptions contained unrecognized flag";
1593 return LDAP_UNWILLING_TO_PERFORM;
1596 return LDAP_SUCCESS;
1599 #ifdef SLAP_CONTROL_X_SESSION_TRACKING
1600 static int parseSessionTracking(
1610 struct berval sessionSourceIp = BER_BVNULL,
1611 sessionSourceName = BER_BVNULL,
1612 formatOID = BER_BVNULL,
1613 sessionTrackingIdentifier = BER_BVNULL;
1615 size_t st_len, st_pos;
1617 if ( ctrl->ldctl_iscritical ) {
1618 rs->sr_text = "sessionTracking criticality is TRUE";
1619 return LDAP_PROTOCOL_ERROR;
1622 if ( BER_BVISNULL( &ctrl->ldctl_value ) ) {
1623 rs->sr_text = "sessionTracking control value is absent";
1624 return LDAP_PROTOCOL_ERROR;
1627 if ( BER_BVISEMPTY( &ctrl->ldctl_value ) ) {
1628 rs->sr_text = "sessionTracking control value is empty";
1629 return LDAP_PROTOCOL_ERROR;
1632 ber = ber_init( &ctrl->ldctl_value );
1633 if ( ber == NULL ) {
1634 rs->sr_text = "internal error";
1638 tag = ber_skip_tag( ber, &len );
1639 if ( tag != LBER_SEQUENCE ) {
1644 /* sessionSourceIp */
1645 tag = ber_peek_tag( ber, &len );
1646 if ( tag == LBER_DEFAULT ) {
1652 tag = ber_skip_tag( ber, &len );
1654 } else if ( len > 128 ) {
1655 rs->sr_text = "sessionTracking.sessionSourceIp too long";
1656 rs->sr_err = LDAP_PROTOCOL_ERROR;
1660 tag = ber_scanf( ber, "m", &sessionSourceIp );
1663 if ( ldif_is_not_printable( sessionSourceIp.bv_val, sessionSourceIp.bv_len ) ) {
1664 BER_BVZERO( &sessionSourceIp );
1667 /* sessionSourceName */
1668 tag = ber_peek_tag( ber, &len );
1669 if ( tag == LBER_DEFAULT ) {
1675 tag = ber_skip_tag( ber, &len );
1677 } else if ( len > 65536 ) {
1678 rs->sr_text = "sessionTracking.sessionSourceName too long";
1679 rs->sr_err = LDAP_PROTOCOL_ERROR;
1683 tag = ber_scanf( ber, "m", &sessionSourceName );
1686 if ( ldif_is_not_printable( sessionSourceName.bv_val, sessionSourceName.bv_len ) ) {
1687 BER_BVZERO( &sessionSourceName );
1691 tag = ber_peek_tag( ber, &len );
1692 if ( tag == LBER_DEFAULT ) {
1698 rs->sr_text = "sessionTracking.formatOID empty";
1699 rs->sr_err = LDAP_PROTOCOL_ERROR;
1702 } else if ( len > 1024 ) {
1703 rs->sr_text = "sessionTracking.formatOID too long";
1704 rs->sr_err = LDAP_PROTOCOL_ERROR;
1708 tag = ber_scanf( ber, "m", &formatOID );
1711 rc = numericoidValidate( NULL, &formatOID );
1712 if ( rc != LDAP_SUCCESS ) {
1713 rs->sr_text = "sessionTracking.formatOID invalid";
1717 /* sessionTrackingIdentifier */
1718 tag = ber_peek_tag( ber, &len );
1719 if ( tag == LBER_DEFAULT ) {
1725 tag = ber_skip_tag( ber, &len );
1728 /* note: should not be more than 65536... */
1729 tag = ber_scanf( ber, "m", &sessionTrackingIdentifier );
1732 if ( ldif_is_not_printable( sessionTrackingIdentifier.bv_val, sessionTrackingIdentifier.bv_len ) ) {
1733 BER_BVZERO( &sessionTrackingIdentifier );
1737 tag = ber_skip_tag( ber, &len );
1738 if ( tag == LBER_DEFAULT && len == 0 ) {
1743 if ( !BER_BVISNULL( &sessionSourceIp ) ) {
1744 st_len += STRLENOF( "IP=" ) + sessionSourceIp.bv_len;
1746 if ( !BER_BVISNULL( &sessionSourceName ) ) {
1747 if ( st_len ) st_len++;
1748 st_len += STRLENOF( "NAME=" ) + sessionSourceName.bv_len;
1750 if ( !BER_BVISNULL( &sessionTrackingIdentifier ) ) {
1751 if ( st_len ) st_len++;
1752 st_len += STRLENOF( "ID=" ) + sessionTrackingIdentifier.bv_len;
1755 if ( st_len == 0 ) {
1759 st_len += STRLENOF( " []" );
1760 st_pos = strlen( op->o_log_prefix );
1762 if ( sizeof( op->o_log_prefix ) - st_pos > st_len ) {
1763 char *ptr = &op->o_log_prefix[ st_pos ];
1765 ptr = lutil_strcopy( ptr, " [" /*]*/ );
1768 if ( !BER_BVISNULL( &sessionSourceIp ) ) {
1769 ptr = lutil_strcopy( ptr, "IP=" );
1770 ptr = lutil_strcopy( ptr, sessionSourceIp.bv_val );
1774 if ( !BER_BVISNULL( &sessionSourceName ) ) {
1775 if ( st_len ) *ptr++ = ' ';
1776 ptr = lutil_strcopy( ptr, "NAME=" );
1777 ptr = lutil_strcopy( ptr, sessionSourceName.bv_val );
1781 if ( !BER_BVISNULL( &sessionTrackingIdentifier ) ) {
1782 if ( st_len ) *ptr++ = ' ';
1783 ptr = lutil_strcopy( ptr, "ID=" );
1784 ptr = lutil_strcopy( ptr, sessionTrackingIdentifier.bv_val );
1792 (void)ber_free( ber, 1 );
1794 if ( tag == LBER_ERROR ) {
1795 rs->sr_text = "sessionTracking control decoding error";
1796 return LDAP_PROTOCOL_ERROR;