3 * Copyright 1999-2003 The OpenLDAP Foundation.
6 * Redistribution and use in source and binary forms are permitted only
7 * as authorized by the OpenLDAP Public License. A copy of this
8 * license is available at http://www.OpenLDAP.org/license.html or
9 * in file LICENSE in the top-level directory of the distribution.
15 #include <ac/string.h>
16 #include <ac/socket.h>
20 #include "../../libraries/liblber/lber-int.h"
22 static SLAP_CTRL_PARSE_FN parseProxyAuthz;
23 static SLAP_CTRL_PARSE_FN parseManageDSAit;
24 static SLAP_CTRL_PARSE_FN parseNoOp;
25 static SLAP_CTRL_PARSE_FN parsePagedResults;
26 static SLAP_CTRL_PARSE_FN parseValuesReturnFilter;
27 static SLAP_CTRL_PARSE_FN parsePermissiveModify;
28 static SLAP_CTRL_PARSE_FN parseDomainScope;
30 #ifdef LDAP_CONTROL_SUBENTRIES
31 static SLAP_CTRL_PARSE_FN parseSubentries;
33 #ifdef LDAP_CLIENT_UPDATE
34 static SLAP_CTRL_PARSE_FN parseClientUpdate;
37 static SLAP_CTRL_PARSE_FN parseLdupSync;
40 #undef sc_mask /* avoid conflict with Irix 6.5 <sys/signal.h> */
42 static char *proxy_authz_extops[] = {
43 LDAP_EXOP_MODIFY_PASSWD,
55 * Operations supported by control
60 * Extended operations supported by control
62 char **sc_extendedops;
65 * Control parsing callback
67 SLAP_CTRL_PARSE_FN *sc_parse;
69 LDAP_SLIST_ENTRY(slap_control) sc_next;
72 static LDAP_SLIST_HEAD(ControlsList, slap_control) controls_list
73 = LDAP_SLIST_HEAD_INITIALIZER(&controls_list);
76 * all known request control OIDs should be added to this list
78 char **slap_known_controls = NULL;
80 static struct slap_control control_defs[] = {
81 { LDAP_CONTROL_VALUESRETURNFILTER,
82 SLAP_CTRL_SEARCH, NULL,
83 parseValuesReturnFilter, LDAP_SLIST_ENTRY_INITIALIZER(next) },
84 #ifdef LDAP_CONTROL_PAGEDRESULTS
85 { LDAP_CONTROL_PAGEDRESULTS,
86 SLAP_CTRL_SEARCH, NULL,
87 parsePagedResults, LDAP_SLIST_ENTRY_INITIALIZER(next) },
89 #ifdef LDAP_CONTROL_X_DOMAIN_SCOPE
90 { LDAP_CONTROL_X_DOMAIN_SCOPE,
91 SLAP_CTRL_FRONTEND|SLAP_CTRL_SEARCH, NULL,
92 parseDomainScope, LDAP_SLIST_ENTRY_INITIALIZER(next) },
94 #ifdef LDAP_CONTROL_X_PERMISSIVE_MODIFY
95 { LDAP_CONTROL_X_PERMISSIVE_MODIFY,
96 SLAP_CTRL_MODIFY, NULL,
97 parsePermissiveModify, LDAP_SLIST_ENTRY_INITIALIZER(next) },
99 #ifdef LDAP_CONTROL_SUBENTRIES
100 { LDAP_CONTROL_SUBENTRIES,
101 SLAP_CTRL_SEARCH, NULL,
102 parseSubentries, LDAP_SLIST_ENTRY_INITIALIZER(next) },
105 SLAP_CTRL_ACCESS, NULL,
106 parseNoOp, LDAP_SLIST_ENTRY_INITIALIZER(next) },
107 #ifdef LDAP_CLIENT_UPDATE
108 { LDAP_CONTROL_CLIENT_UPDATE,
109 SLAP_CTRL_SEARCH, NULL,
110 parseClientUpdate, LDAP_SLIST_ENTRY_INITIALIZER(next) },
114 SLAP_CTRL_SEARCH, NULL,
115 parseLdupSync, LDAP_SLIST_ENTRY_INITIALIZER(next) },
117 { LDAP_CONTROL_MANAGEDSAIT,
118 SLAP_CTRL_ACCESS, NULL,
119 parseManageDSAit, LDAP_SLIST_ENTRY_INITIALIZER(next) },
120 { LDAP_CONTROL_PROXY_AUTHZ,
121 SLAP_CTRL_FRONTEND|SLAP_CTRL_ACCESS, proxy_authz_extops,
122 parseProxyAuthz, LDAP_SLIST_ENTRY_INITIALIZER(next) },
123 { NULL, 0, NULL, 0, LDAP_SLIST_ENTRY_INITIALIZER(next) }
127 * Register a supported control.
129 * This can be called by an OpenLDAP plugin or, indirectly, by a
130 * SLAPI plugin calling slapi_register_supported_control().
133 register_supported_control(const char *controloid,
134 slap_mask_t controlmask,
136 SLAP_CTRL_PARSE_FN *controlparsefn)
138 struct slap_control *sc;
141 if ( controloid == NULL ) {
142 return LDAP_PARAM_ERROR;
145 sc = (struct slap_control *)SLAP_MALLOC( sizeof( *sc ) );
147 return LDAP_NO_MEMORY;
149 sc->sc_oid = ch_strdup( controloid );
150 sc->sc_mask = controlmask;
151 if ( controlexops != NULL ) {
152 sc->sc_extendedops = ldap_charray_dup( controlexops );
153 if ( sc->sc_extendedops == NULL ) {
155 return LDAP_NO_MEMORY;
158 sc->sc_extendedops = NULL;
160 sc->sc_parse = controlparsefn;
162 /* Update slap_known_controls, too. */
163 if ( slap_known_controls == NULL ) {
164 slap_known_controls = (char **)SLAP_MALLOC( 2 * sizeof(char *) );
165 if ( slap_known_controls == NULL ) {
166 if ( sc->sc_extendedops != NULL ) ldap_charray_free( sc->sc_extendedops );
168 return LDAP_NO_MEMORY;
170 slap_known_controls[0] = ch_strdup( sc->sc_oid );
171 slap_known_controls[1] = NULL;
173 for ( i = 0; slap_known_controls[i] != NULL; i++ )
175 slap_known_controls = (char **)SLAP_REALLOC( slap_known_controls, (i + 2) * sizeof(char *) );
176 if ( slap_known_controls == NULL ) {
177 if ( sc->sc_extendedops != NULL ) ldap_charray_free( sc->sc_extendedops );
179 return LDAP_NO_MEMORY;
181 slap_known_controls[i++] = ch_strdup( sc->sc_oid );
182 slap_known_controls[i] = NULL;
185 LDAP_SLIST_NEXT( sc, sc_next ) = NULL;
186 LDAP_SLIST_INSERT_HEAD( &controls_list, sc, sc_next );
192 * One-time initialization of internal controls.
195 slap_controls_init( void )
198 struct slap_control *sc;
202 for ( i = 0; control_defs[i].sc_oid != NULL; i++ ) {
203 rc = register_supported_control( control_defs[i].sc_oid,
204 control_defs[i].sc_mask, control_defs[i].sc_extendedops,
205 control_defs[i].sc_parse );
206 if ( rc != LDAP_SUCCESS )
214 * Free memory associated with list of supported controls.
217 controls_destroy( void )
219 struct slap_control *sc;
221 while ( !LDAP_SLIST_EMPTY(&controls_list) ) {
222 sc = LDAP_SLIST_FIRST(&controls_list);
223 LDAP_SLIST_REMOVE_HEAD(&controls_list, sc_next);
225 ch_free( sc->sc_oid );
226 if ( sc->sc_extendedops != NULL ) {
227 ldap_charray_free( sc->sc_extendedops );
231 ldap_charray_free( slap_known_controls );
235 * Format the supportedControl attribute of the root DSE,
236 * detailing which controls are supported by the directory
240 controls_root_dse_info( Entry *e )
242 AttributeDescription *ad_supportedControl
243 = slap_schema.si_ad_supportedControl;
244 struct berval vals[2];
245 struct slap_control *sc;
247 vals[1].bv_val = NULL;
250 LDAP_SLIST_FOREACH( sc, &controls_list, sc_next ) {
251 vals[0].bv_val = sc->sc_oid;
252 vals[0].bv_len = strlen( sc->sc_oid );
254 if ( attr_merge( e, ad_supportedControl, vals, NULL ) )
256 if ( attr_merge( e, ad_supportedControl, vals ) )
257 #endif /* SLAP_NVALUES */
265 * Return a list of OIDs and operation masks for supported
266 * controls. Used by SLAPI.
269 get_supported_controls(char ***ctrloidsp,
270 slap_mask_t **ctrlmasks)
276 struct slap_control *sc;
280 LDAP_SLIST_FOREACH( sc, &controls_list, sc_next ) {
290 oids = (char **)SLAP_MALLOC( (n + 1) * sizeof(char *) );
291 if ( oids == NULL ) {
292 return LDAP_NO_MEMORY;
294 masks = (slap_mask_t *)SLAP_MALLOC( (n + 1) * sizeof(slap_mask_t) );
295 if ( masks == NULL ) {
297 return LDAP_NO_MEMORY;
302 LDAP_SLIST_FOREACH( sc, &controls_list, sc_next ) {
303 oids[n] = ch_strdup( sc->sc_oid );
304 masks[n] = sc->sc_mask;
317 * Find a control given its OID.
319 static struct slap_control *
320 find_ctrl( const char *oid )
322 struct slap_control *sc;
324 LDAP_SLIST_FOREACH( sc, &controls_list, sc_next ) {
325 if ( strcmp( oid, sc->sc_oid ) == 0 ) {
342 BerElement *ber = op->o_ber;
343 struct slap_control *sc;
344 int rc = LDAP_SUCCESS;
345 const char *errmsg = NULL;
347 len = ber_pvt_ber_remaining(ber);
355 if(( tag = ber_peek_tag( ber, &len )) != LDAP_TAG_CONTROLS ) {
356 if( tag == LBER_ERROR ) {
357 rc = SLAPD_DISCONNECT;
358 errmsg = "unexpected data in PDU";
365 LDAP_LOG( OPERATION, ENTRY,
366 "get_ctrls: conn %lu\n", conn->c_connid, 0, 0 );
368 Debug( LDAP_DEBUG_TRACE,
369 "=> get_ctrls\n", 0, 0, 0 );
372 if( op->o_protocol < LDAP_VERSION3 ) {
373 rc = SLAPD_DISCONNECT;
374 errmsg = "controls require LDAPv3";
378 /* one for first control, one for termination */
379 op->o_ctrls = ch_malloc( 2 * sizeof(LDAPControl *) );
382 if( op->ctrls == NULL ) {
384 errmsg = "no memory";
389 op->o_ctrls[nctrls] = NULL;
391 /* step through each element */
392 for( tag = ber_first_element( ber, &len, &opaque );
394 tag = ber_next_element( ber, &len, opaque ) )
397 LDAPControl **tctrls;
399 c = ch_calloc( 1, sizeof(LDAPControl) );
403 ldap_controls_free(op->o_ctrls);
407 errmsg = "no memory";
412 /* allocate pointer space for current controls (nctrls)
413 * + this control + extra NULL
415 tctrls = ch_realloc( op->o_ctrls,
416 (nctrls+2) * sizeof(LDAPControl *));
419 if( tctrls == NULL ) {
421 ldap_controls_free(op->o_ctrls);
425 errmsg = "no memory";
429 op->o_ctrls = tctrls;
431 op->o_ctrls[nctrls++] = c;
432 op->o_ctrls[nctrls] = NULL;
434 tag = ber_scanf( ber, "{a" /*}*/, &c->ldctl_oid );
436 if( tag == LBER_ERROR ) {
438 LDAP_LOG( OPERATION, INFO, "get_ctrls: conn %lu get OID failed.\n",
439 conn->c_connid, 0, 0 );
441 Debug( LDAP_DEBUG_TRACE, "=> get_ctrls: get oid failed.\n",
445 ldap_controls_free( op->o_ctrls );
447 rc = SLAPD_DISCONNECT;
448 errmsg = "decoding controls error";
451 } else if( c->ldctl_oid == NULL ) {
453 LDAP_LOG( OPERATION, INFO,
454 "get_ctrls: conn %lu got emtpy OID.\n",
455 conn->c_connid, 0, 0 );
457 Debug( LDAP_DEBUG_TRACE,
458 "get_ctrls: conn %lu got emtpy OID.\n",
459 conn->c_connid, 0, 0 );
462 ldap_controls_free( op->o_ctrls );
464 rc = LDAP_PROTOCOL_ERROR;
465 errmsg = "OID field is empty";
469 tag = ber_peek_tag( ber, &len );
471 if( tag == LBER_BOOLEAN ) {
473 tag = ber_scanf( ber, "b", &crit );
475 if( tag == LBER_ERROR ) {
477 LDAP_LOG( OPERATION, INFO,
478 "get_ctrls: conn %lu get crit failed.\n",
479 conn->c_connid, 0, 0 );
481 Debug( LDAP_DEBUG_TRACE, "=> get_ctrls: get crit failed.\n",
484 ldap_controls_free( op->o_ctrls );
486 rc = SLAPD_DISCONNECT;
487 errmsg = "decoding controls error";
491 c->ldctl_iscritical = (crit != 0);
492 tag = ber_peek_tag( ber, &len );
495 if( tag == LBER_OCTETSTRING ) {
496 tag = ber_scanf( ber, "o", &c->ldctl_value );
498 if( tag == LBER_ERROR ) {
500 LDAP_LOG( OPERATION, INFO, "get_ctrls: conn %lu: "
501 "%s (%scritical): get value failed.\n",
502 conn->c_connid, c->ldctl_oid,
503 c->ldctl_iscritical ? "" : "non" );
505 Debug( LDAP_DEBUG_TRACE, "=> get_ctrls: conn %lu: "
506 "%s (%scritical): get value failed.\n",
507 conn->c_connid, c->ldctl_oid,
508 c->ldctl_iscritical ? "" : "non" );
510 ldap_controls_free( op->o_ctrls );
512 rc = SLAPD_DISCONNECT;
513 errmsg = "decoding controls error";
519 LDAP_LOG( OPERATION, INFO,
520 "get_ctrls: conn %lu oid=\"%s\" (%scritical)\n",
521 conn->c_connid, c->ldctl_oid, c->ldctl_iscritical ? "" : "non" );
523 Debug( LDAP_DEBUG_TRACE,
524 "=> get_ctrls: oid=\"%s\" (%scritical)\n",
525 c->ldctl_oid, c->ldctl_iscritical ? "" : "non", 0 );
528 sc = find_ctrl( c->ldctl_oid );
530 /* recognized control */
532 switch( op->o_tag ) {
534 tagmask = SLAP_CTRL_ADD;
537 tagmask = SLAP_CTRL_BIND;
539 case LDAP_REQ_COMPARE:
540 tagmask = SLAP_CTRL_COMPARE;
542 case LDAP_REQ_DELETE:
543 tagmask = SLAP_CTRL_DELETE;
545 case LDAP_REQ_MODIFY:
546 tagmask = SLAP_CTRL_MODIFY;
548 case LDAP_REQ_RENAME:
549 tagmask = SLAP_CTRL_RENAME;
551 case LDAP_REQ_SEARCH:
552 tagmask = SLAP_CTRL_SEARCH;
554 case LDAP_REQ_UNBIND:
555 tagmask = SLAP_CTRL_UNBIND;
557 case LDAP_REQ_ABANDON:
558 tagmask = SLAP_CTRL_ABANDON;
560 case LDAP_REQ_EXTENDED:
562 assert( op->o_extendedop != NULL );
563 if( sc->sc_extendedops != NULL ) {
565 for( i=0; sc->sc_extendedops[i] != NULL; i++ ) {
566 if( strcmp( op->o_extendedop, sc->sc_extendedops[i] )
577 errmsg = "controls internal error";
581 if (( sc->sc_mask & tagmask ) == tagmask ) {
582 /* available extension */
584 if( !sc->sc_parse ) {
586 errmsg = "not yet implemented";
590 rc = sc->sc_parse( conn, op, c, &errmsg );
592 if( rc != LDAP_SUCCESS ) goto return_results;
594 if ( sc->sc_mask & SLAP_CTRL_FRONTEND ) {
595 /* kludge to disable backend_control() check */
596 c->ldctl_iscritical = 0;
598 } else if ( tagmask == SLAP_CTRL_SEARCH &&
599 sc->sc_mask & SLAP_CTRL_FRONTEND_SEARCH )
601 /* kludge to disable backend_control() check */
602 c->ldctl_iscritical = 0;
605 } else if( c->ldctl_iscritical ) {
606 /* unavailable CRITICAL control */
607 rc = LDAP_UNAVAILABLE_CRITICAL_EXTENSION;
608 errmsg = "critical extension is unavailable";
612 } else if( c->ldctl_iscritical ) {
613 /* unrecognized CRITICAL control */
614 rc = LDAP_UNAVAILABLE_CRITICAL_EXTENSION;
615 errmsg = "critical extension is not recognized";
622 LDAP_LOG( OPERATION, RESULTS,
623 "get_ctrls: n=%d rc=%d err=\"%s\"\n",
624 nctrls, rc, errmsg ? errmsg : "" );
626 Debug( LDAP_DEBUG_TRACE,
627 "<= get_ctrls: n=%d rc=%d err=\"%s\"\n",
628 nctrls, rc, errmsg ? errmsg : "");
631 if( sendres && rc != LDAP_SUCCESS ) {
632 if( rc == SLAPD_DISCONNECT ) {
633 send_ldap_disconnect( conn, op, LDAP_PROTOCOL_ERROR, errmsg );
635 send_ldap_result( conn, op, rc,
636 NULL, errmsg, NULL, NULL );
643 static int parseManageDSAit (
649 if ( op->o_managedsait != SLAP_NO_CONTROL ) {
650 *text = "manageDSAit control specified multiple times";
651 return LDAP_PROTOCOL_ERROR;
654 if ( ctrl->ldctl_value.bv_len ) {
655 *text = "manageDSAit control value not empty";
656 return LDAP_PROTOCOL_ERROR;
659 op->o_managedsait = ctrl->ldctl_iscritical
660 ? SLAP_CRITICAL_CONTROL
661 : SLAP_NONCRITICAL_CONTROL;
666 static int parseProxyAuthz (
673 struct berval dn = { 0, NULL };
675 if ( op->o_proxy_authz != SLAP_NO_CONTROL ) {
676 *text = "proxy authorization control specified multiple times";
677 return LDAP_PROTOCOL_ERROR;
680 op->o_proxy_authz = ctrl->ldctl_iscritical
681 ? SLAP_CRITICAL_CONTROL
682 : SLAP_NONCRITICAL_CONTROL;
685 LDAP_LOG( OPERATION, ARGS,
686 "parseProxyAuthz: conn %lu authzid=\"%s\"\n",
688 ctrl->ldctl_value.bv_len ? ctrl->ldctl_value.bv_val : "anonymous",
691 Debug( LDAP_DEBUG_ARGS,
692 "parseProxyAuthz: conn %lu authzid=\"%s\"\n",
694 ctrl->ldctl_value.bv_len ? ctrl->ldctl_value.bv_val : "anonymous",
698 if( ctrl->ldctl_value.bv_len == 0 ) {
700 LDAP_LOG( OPERATION, RESULTS,
701 "parseProxyAuthz: conn=%lu anonymous\n",
702 conn->c_connid, 0, 0 );
704 Debug( LDAP_DEBUG_TRACE,
705 "parseProxyAuthz: conn=%lu anonymous\n",
706 conn->c_connid, 0, 0 );
710 free( op->o_dn.bv_val );
712 op->o_dn.bv_val = ch_strdup( "" );
714 free( op->o_ndn.bv_val );
715 op->o_ndn.bv_len = 0;
716 op->o_ndn.bv_val = ch_strdup( "" );
721 rc = slap_sasl_getdn( conn,
722 ctrl->ldctl_value.bv_val, ctrl->ldctl_value.bv_len,
723 NULL, &dn, SLAP_GETDN_AUTHZID );
725 if( rc != LDAP_SUCCESS || !dn.bv_len ) {
727 ch_free( dn.bv_val );
729 *text = "authzId mapping failed";
730 return LDAP_PROXY_AUTHZ_FAILURE;
734 LDAP_LOG( OPERATION, RESULTS,
735 "parseProxyAuthz: conn=%lu \"%s\"\n",
737 dn.bv_len ? dn.bv_val : "(NULL)", 0 );
739 Debug( LDAP_DEBUG_TRACE,
740 "parseProxyAuthz: conn=%lu \"%s\"\n",
742 dn.bv_len ? dn.bv_val : "(NULL)", 0 );
745 rc = slap_sasl_authorized( conn, &op->o_ndn, &dn );
748 ch_free( dn.bv_val );
749 *text = "not authorized to assume identity";
750 return LDAP_PROXY_AUTHZ_FAILURE;
753 ch_free( op->o_dn.bv_val );
754 ch_free( op->o_ndn.bv_val );
756 op->o_dn.bv_val = NULL;
760 * NOTE: since slap_sasl_getdn() returns a normalized dn,
761 * from now on op->o_dn is normalized
763 ber_dupbv( &op->o_dn, &dn );
768 static int parseNoOp (
774 if ( op->o_noop != SLAP_NO_CONTROL ) {
775 *text = "noop control specified multiple times";
776 return LDAP_PROTOCOL_ERROR;
779 if ( ctrl->ldctl_value.bv_len ) {
780 *text = "noop control value not empty";
781 return LDAP_PROTOCOL_ERROR;
784 op->o_noop = ctrl->ldctl_iscritical
785 ? SLAP_CRITICAL_CONTROL
786 : SLAP_NONCRITICAL_CONTROL;
791 #ifdef LDAP_CONTROL_PAGEDRESULTS
792 static int parsePagedResults (
801 struct berval cookie = { 0, NULL };
803 if ( op->o_pagedresults != SLAP_NO_CONTROL ) {
804 *text = "paged results control specified multiple times";
805 return LDAP_PROTOCOL_ERROR;
808 if ( ctrl->ldctl_value.bv_len == 0 ) {
809 *text = "paged results control value is empty (or absent)";
810 return LDAP_PROTOCOL_ERROR;
813 /* Parse the control value
814 * realSearchControlValue ::= SEQUENCE {
815 * size INTEGER (0..maxInt),
816 * -- requested page size from client
817 * -- result set size estimate from server
818 * cookie OCTET STRING
821 ber = ber_init( &ctrl->ldctl_value );
823 *text = "internal error";
827 tag = ber_scanf( ber, "{im}", &size, &cookie );
828 (void) ber_free( ber, 1 );
830 if( tag == LBER_ERROR ) {
831 *text = "paged results control could not be decoded";
832 return LDAP_PROTOCOL_ERROR;
836 *text = "paged results control size invalid";
837 return LDAP_PROTOCOL_ERROR;
840 if( cookie.bv_len ) {
841 PagedResultsCookie reqcookie;
842 if( cookie.bv_len != sizeof( reqcookie ) ) {
844 *text = "paged results cookie is invalid";
845 return LDAP_PROTOCOL_ERROR;
848 AC_MEMCPY( &reqcookie, cookie.bv_val, sizeof( reqcookie ));
850 if( reqcookie > op->o_pagedresults_state.ps_cookie ) {
852 *text = "paged results cookie is invalid";
853 return LDAP_PROTOCOL_ERROR;
855 } else if( reqcookie < op->o_pagedresults_state.ps_cookie ) {
856 *text = "paged results cookie is invalid or old";
857 return LDAP_UNWILLING_TO_PERFORM;
860 /* Initial request. Initialize state. */
861 op->o_pagedresults_state.ps_cookie = 0;
862 op->o_pagedresults_state.ps_id = NOID;
865 op->o_pagedresults_size = size;
867 op->o_pagedresults = ctrl->ldctl_iscritical
868 ? SLAP_CRITICAL_CONTROL
869 : SLAP_NONCRITICAL_CONTROL;
875 int parseValuesReturnFilter (
883 struct berval fstr = { 0, NULL };
884 const char *err_msg = "";
886 if ( op->o_valuesreturnfilter != SLAP_NO_CONTROL ) {
887 *text = "valuesReturnFilter control specified multiple times";
888 return LDAP_PROTOCOL_ERROR;
891 if ( ctrl->ldctl_value.bv_len == 0 ) {
892 *text = "valuesReturnFilter control value is empty (or absent)";
893 return LDAP_PROTOCOL_ERROR;
896 ber = ber_init( &(ctrl->ldctl_value) );
898 *text = "internal error";
902 rc = get_vrFilter( conn, ber, &(op->vrFilter), &err_msg);
904 if( rc != LDAP_SUCCESS ) {
906 if( rc == SLAPD_DISCONNECT ) {
907 send_ldap_disconnect( conn, op,
908 LDAP_PROTOCOL_ERROR, *text );
910 send_ldap_result( conn, op, rc,
911 NULL, *text, NULL, NULL );
913 if( fstr.bv_val != NULL) free( fstr.bv_val );
914 if( op->vrFilter != NULL) vrFilter_free( op->vrFilter );
917 vrFilter2bv( op->vrFilter, &fstr );
921 LDAP_LOG( OPERATION, ARGS,
922 "parseValuesReturnFilter: conn %d vrFilter: %s\n",
923 conn->c_connid, fstr.bv_len ? fstr.bv_val : "empty" , 0 );
925 Debug( LDAP_DEBUG_ARGS, " vrFilter: %s\n",
926 fstr.bv_len ? fstr.bv_val : "empty", 0, 0 );
929 op->o_valuesreturnfilter = ctrl->ldctl_iscritical
930 ? SLAP_CRITICAL_CONTROL
931 : SLAP_NONCRITICAL_CONTROL;
936 #ifdef LDAP_CONTROL_SUBENTRIES
937 static int parseSubentries (
943 if ( op->o_subentries != SLAP_NO_CONTROL ) {
944 *text = "subentries control specified multiple times";
945 return LDAP_PROTOCOL_ERROR;
948 /* FIXME: should use BER library */
949 if( ( ctrl->ldctl_value.bv_len != 3 )
950 && ( ctrl->ldctl_value.bv_val[0] != 0x01 )
951 && ( ctrl->ldctl_value.bv_val[1] != 0x01 ))
953 *text = "subentries control value encoding is bogus";
954 return LDAP_PROTOCOL_ERROR;
957 op->o_subentries = ctrl->ldctl_iscritical
958 ? SLAP_CRITICAL_CONTROL
959 : SLAP_NONCRITICAL_CONTROL;
961 op->o_subentries_visibility = (ctrl->ldctl_value.bv_val[2] != 0x00);
967 #ifdef LDAP_CONTROL_X_PERMISSIVE_MODIFY
968 static int parsePermissiveModify (
974 if ( op->o_permissive_modify != SLAP_NO_CONTROL ) {
975 *text = "permissiveModify control specified multiple times";
976 return LDAP_PROTOCOL_ERROR;
979 if ( ctrl->ldctl_value.bv_len ) {
980 *text = "permissiveModify control value not empty";
981 return LDAP_PROTOCOL_ERROR;
984 op->o_permissive_modify = ctrl->ldctl_iscritical
985 ? SLAP_CRITICAL_CONTROL
986 : SLAP_NONCRITICAL_CONTROL;
992 #ifdef LDAP_CONTROL_X_DOMAIN_SCOPE
993 static int parseDomainScope (
999 if ( op->o_domain_scope != SLAP_NO_CONTROL ) {
1000 *text = "domainScope control specified multiple times";
1001 return LDAP_PROTOCOL_ERROR;
1004 if ( ctrl->ldctl_value.bv_len ) {
1005 *text = "domainScope control value not empty";
1006 return LDAP_PROTOCOL_ERROR;
1009 op->o_domain_scope = ctrl->ldctl_iscritical
1010 ? SLAP_CRITICAL_CONTROL
1011 : SLAP_NONCRITICAL_CONTROL;
1013 return LDAP_SUCCESS;
1017 #ifdef LDAP_CLIENT_UPDATE
1018 static int parseClientUpdate (
1029 struct berval scheme = { 0, NULL };
1030 struct berval cookie = { 0, NULL };
1032 if ( op->o_clientupdate != SLAP_NO_CONTROL ) {
1033 *text = "LCUP client update control specified multiple times";
1034 return LDAP_PROTOCOL_ERROR;
1038 if ( op->o_sync != SLAP_NO_CONTROL ) {
1039 *text = "LDAP Client Update and Sync controls used together";
1040 return LDAP_PROTOCOL_ERROR;
1044 if ( ctrl->ldctl_value.bv_len == 0 ) {
1045 *text = "LCUP client update control value is empty (or absent)";
1046 return LDAP_PROTOCOL_ERROR;
1049 /* Parse the control value
1050 * ClientUpdateControlValue ::= SEQUENCE {
1051 * updateType ENUMERATED {
1052 * synchronizeOnly {0},
1053 * synchronizeAndPersist {1},
1054 * persistOnly {2} },
1055 * sendCookieInterval INTEGER OPTIONAL,
1056 * cookie LCUPCookie OPTIONAL
1060 ber = ber_init( &ctrl->ldctl_value );
1062 *text = "internal error";
1066 if ( (tag = ber_scanf( ber, "{i" /*}*/, &type )) == LBER_ERROR ) {
1067 *text = "LCUP client update control : decoding error";
1068 return LDAP_PROTOCOL_ERROR;
1072 case LDAP_CUP_SYNC_ONLY:
1073 type = SLAP_LCUP_SYNC;
1075 case LDAP_CUP_SYNC_AND_PERSIST:
1076 type = SLAP_LCUP_SYNC_AND_PERSIST;
1078 case LDAP_CUP_PERSIST_ONLY:
1079 type = SLAP_LCUP_PERSIST;
1082 *text = "LCUP client update control : unknown update type";
1083 return LDAP_PROTOCOL_ERROR;
1086 if ( (tag = ber_peek_tag( ber, &len )) == LBER_DEFAULT ) {
1087 *text = "LCUP client update control : decoding error";
1088 return LDAP_PROTOCOL_ERROR;
1091 if ( tag == LDAP_CUP_TAG_INTERVAL ) {
1092 if ( (tag = ber_scanf( ber, "i", &interval )) == LBER_ERROR ) {
1093 *text = "LCUP client update control : decoding error";
1094 return LDAP_PROTOCOL_ERROR;
1097 if ( interval <= 0 ) {
1098 /* server chooses interval */
1099 interval = LDAP_CUP_DEFAULT_SEND_COOKIE_INTERVAL;
1103 /* server chooses interval */
1104 interval = LDAP_CUP_DEFAULT_SEND_COOKIE_INTERVAL;
1107 if ( (tag = ber_peek_tag( ber, &len )) == LBER_DEFAULT ) {
1108 *text = "LCUP client update control : decoding error";
1109 return LDAP_PROTOCOL_ERROR;
1112 if ( tag == LDAP_CUP_TAG_COOKIE ) {
1113 if ( (tag = ber_scanf( ber, /*{*/ "{mm}}",
1114 &scheme, &cookie )) == LBER_ERROR )
1116 *text = "LCUP client update control : decoding error";
1117 return LDAP_PROTOCOL_ERROR;
1121 /* TODO : Cookie Scheme Validation */
1123 if ( lcup_cookie_scheme_validate(scheme) != LDAP_SUCCESS ) {
1124 *text = "Unsupported LCUP cookie scheme";
1125 return LCUP_UNSUPPORTED_SCHEME;
1128 if ( lcup_cookie_validate(scheme, cookie) != LDAP_SUCCESS ) {
1129 *text = "Invalid LCUP cookie";
1130 return LCUP_INVALID_COOKIE;
1134 ber_dupbv( &op->o_clientupdate_state, &cookie );
1136 (void) ber_free( ber, 1 );
1138 op->o_clientupdate_type = (char) type;
1139 op->o_clientupdate_interval = interval;
1141 op->o_clientupdate = ctrl->ldctl_iscritical
1142 ? SLAP_CRITICAL_CONTROL
1143 : SLAP_NONCRITICAL_CONTROL;
1145 return LDAP_SUCCESS;
1150 static int parseLdupSync (
1160 struct berval cookie = { 0, NULL };
1162 if ( op->o_sync != SLAP_NO_CONTROL ) {
1163 *text = "LDAP Sync control specified multiple times";
1164 return LDAP_PROTOCOL_ERROR;
1167 #ifdef LDAP_CLIENT_UPDATE
1168 if ( op->o_clientupdate != SLAP_NO_CONTROL ) {
1169 *text = "LDAP Sync and LDAP Client Update controls used together";
1170 return LDAP_PROTOCOL_ERROR;
1174 if ( ctrl->ldctl_value.bv_len == 0 ) {
1175 *text = "LDAP Sync control value is empty (or absent)";
1176 return LDAP_PROTOCOL_ERROR;
1179 /* Parse the control value
1180 * syncRequestValue ::= SEQUENCE {
1185 * refreshAndPersist (3)
1187 * cookie syncCookie OPTIONAL
1191 ber = ber_init( &ctrl->ldctl_value );
1193 *text = "internal error";
1197 if ( (tag = ber_scanf( ber, "{i" /*}*/, &mode )) == LBER_ERROR ) {
1198 *text = "LDAP Sync control : mode decoding error";
1199 return LDAP_PROTOCOL_ERROR;
1203 case LDAP_SYNC_REFRESH_ONLY:
1204 mode = SLAP_SYNC_REFRESH;
1206 case LDAP_SYNC_REFRESH_AND_PERSIST:
1207 mode = SLAP_SYNC_REFRESH_AND_PERSIST;
1210 *text = "LDAP Sync control : unknown update mode";
1211 return LDAP_PROTOCOL_ERROR;
1214 tag = ber_peek_tag( ber, &len );
1216 if ( tag == LDAP_SYNC_TAG_COOKIE ) {
1217 if (( ber_scanf( ber, /*{*/ "m}",
1218 &cookie )) == LBER_ERROR ) {
1219 *text = "LDAP Sync control : cookie decoding error";
1220 return LDAP_PROTOCOL_ERROR;
1223 if (( ber_scanf( ber, /*{*/ "}")) == LBER_ERROR ) {
1224 *text = "LDAP Sync control : decoding error";
1225 return LDAP_PROTOCOL_ERROR;
1228 cookie.bv_val = NULL;
1231 /* TODO : Cookie Scheme Validation */
1233 if ( lcup_cookie_scheme_validate(scheme) != LDAP_SUCCESS ) {
1234 *text = "Unsupported LCUP cookie scheme";
1235 return LCUP_UNSUPPORTED_SCHEME;
1238 if ( lcup_cookie_validate(scheme, cookie) != LDAP_SUCCESS ) {
1239 *text = "Invalid LCUP cookie";
1240 return LCUP_INVALID_COOKIE;
1244 ber_dupbv( &op->o_sync_state, &cookie );
1246 (void) ber_free( ber, 1 );
1248 op->o_sync_mode = (char) mode;
1250 op->o_sync = ctrl->ldctl_iscritical
1251 ? SLAP_CRITICAL_CONTROL
1252 : SLAP_NONCRITICAL_CONTROL;
1254 return LDAP_SUCCESS;