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 );
233 * Format the supportedControl attribute of the root DSE,
234 * detailing which controls are supported by the directory
238 controls_root_dse_info( Entry *e )
240 AttributeDescription *ad_supportedControl
241 = slap_schema.si_ad_supportedControl;
242 struct berval vals[2];
243 struct slap_control *sc;
245 vals[1].bv_val = NULL;
248 LDAP_SLIST_FOREACH( sc, &controls_list, sc_next ) {
249 vals[0].bv_val = sc->sc_oid;
250 vals[0].bv_len = strlen( sc->sc_oid );
252 if ( attr_merge( e, ad_supportedControl, vals, NULL ) )
254 if ( attr_merge( e, ad_supportedControl, vals ) )
255 #endif /* SLAP_NVALUES */
263 * Return a list of OIDs and operation masks for supported
264 * controls. Used by SLAPI.
267 get_supported_controls(char ***ctrloidsp,
268 slap_mask_t **ctrlmasks)
274 struct slap_control *sc;
278 LDAP_SLIST_FOREACH( sc, &controls_list, sc_next ) {
288 oids = (char **)SLAP_MALLOC( (n + 1) * sizeof(char *) );
289 if ( oids == NULL ) {
290 return LDAP_NO_MEMORY;
292 masks = (slap_mask_t *)SLAP_MALLOC( (n + 1) * sizeof(slap_mask_t) );
293 if ( masks == NULL ) {
295 return LDAP_NO_MEMORY;
300 LDAP_SLIST_FOREACH( sc, &controls_list, sc_next ) {
301 oids[n] = ch_strdup( sc->sc_oid );
302 masks[n] = sc->sc_mask;
315 * Find a control given its OID.
317 static struct slap_control *
318 find_ctrl( const char *oid )
320 struct slap_control *sc;
322 LDAP_SLIST_FOREACH( sc, &controls_list, sc_next ) {
323 if ( strcmp( oid, sc->sc_oid ) == 0 ) {
340 BerElement *ber = op->o_ber;
341 struct slap_control *sc;
342 int rc = LDAP_SUCCESS;
343 const char *errmsg = NULL;
345 len = ber_pvt_ber_remaining(ber);
353 if(( tag = ber_peek_tag( ber, &len )) != LDAP_TAG_CONTROLS ) {
354 if( tag == LBER_ERROR ) {
355 rc = SLAPD_DISCONNECT;
356 errmsg = "unexpected data in PDU";
363 LDAP_LOG( OPERATION, ENTRY,
364 "get_ctrls: conn %lu\n", conn->c_connid, 0, 0 );
366 Debug( LDAP_DEBUG_TRACE,
367 "=> get_ctrls\n", 0, 0, 0 );
370 if( op->o_protocol < LDAP_VERSION3 ) {
371 rc = SLAPD_DISCONNECT;
372 errmsg = "controls require LDAPv3";
376 /* one for first control, one for termination */
377 op->o_ctrls = ch_malloc( 2 * sizeof(LDAPControl *) );
380 if( op->ctrls == NULL ) {
382 errmsg = "no memory";
387 op->o_ctrls[nctrls] = NULL;
389 /* step through each element */
390 for( tag = ber_first_element( ber, &len, &opaque );
392 tag = ber_next_element( ber, &len, opaque ) )
395 LDAPControl **tctrls;
397 c = ch_calloc( 1, sizeof(LDAPControl) );
401 ldap_controls_free(op->o_ctrls);
405 errmsg = "no memory";
410 /* allocate pointer space for current controls (nctrls)
411 * + this control + extra NULL
413 tctrls = ch_realloc( op->o_ctrls,
414 (nctrls+2) * sizeof(LDAPControl *));
417 if( tctrls == NULL ) {
419 ldap_controls_free(op->o_ctrls);
423 errmsg = "no memory";
427 op->o_ctrls = tctrls;
429 op->o_ctrls[nctrls++] = c;
430 op->o_ctrls[nctrls] = NULL;
432 tag = ber_scanf( ber, "{a" /*}*/, &c->ldctl_oid );
434 if( tag == LBER_ERROR ) {
436 LDAP_LOG( OPERATION, INFO, "get_ctrls: conn %lu get OID failed.\n",
437 conn->c_connid, 0, 0 );
439 Debug( LDAP_DEBUG_TRACE, "=> get_ctrls: get oid failed.\n",
443 ldap_controls_free( op->o_ctrls );
445 rc = SLAPD_DISCONNECT;
446 errmsg = "decoding controls error";
449 } else if( c->ldctl_oid == NULL ) {
451 LDAP_LOG( OPERATION, INFO,
452 "get_ctrls: conn %lu got emtpy OID.\n",
453 conn->c_connid, 0, 0 );
455 Debug( LDAP_DEBUG_TRACE,
456 "get_ctrls: conn %lu got emtpy OID.\n",
457 conn->c_connid, 0, 0 );
460 ldap_controls_free( op->o_ctrls );
462 rc = LDAP_PROTOCOL_ERROR;
463 errmsg = "OID field is empty";
467 tag = ber_peek_tag( ber, &len );
469 if( tag == LBER_BOOLEAN ) {
471 tag = ber_scanf( ber, "b", &crit );
473 if( tag == LBER_ERROR ) {
475 LDAP_LOG( OPERATION, INFO,
476 "get_ctrls: conn %lu get crit failed.\n",
477 conn->c_connid, 0, 0 );
479 Debug( LDAP_DEBUG_TRACE, "=> get_ctrls: get crit failed.\n",
482 ldap_controls_free( op->o_ctrls );
484 rc = SLAPD_DISCONNECT;
485 errmsg = "decoding controls error";
489 c->ldctl_iscritical = (crit != 0);
490 tag = ber_peek_tag( ber, &len );
493 if( tag == LBER_OCTETSTRING ) {
494 tag = ber_scanf( ber, "o", &c->ldctl_value );
496 if( tag == LBER_ERROR ) {
498 LDAP_LOG( OPERATION, INFO, "get_ctrls: conn %lu: "
499 "%s (%scritical): get value failed.\n",
500 conn->c_connid, c->ldctl_oid,
501 c->ldctl_iscritical ? "" : "non" );
503 Debug( LDAP_DEBUG_TRACE, "=> get_ctrls: conn %lu: "
504 "%s (%scritical): get value failed.\n",
505 conn->c_connid, c->ldctl_oid,
506 c->ldctl_iscritical ? "" : "non" );
508 ldap_controls_free( op->o_ctrls );
510 rc = SLAPD_DISCONNECT;
511 errmsg = "decoding controls error";
517 LDAP_LOG( OPERATION, INFO,
518 "get_ctrls: conn %lu oid=\"%s\" (%scritical)\n",
519 conn->c_connid, c->ldctl_oid, c->ldctl_iscritical ? "" : "non" );
521 Debug( LDAP_DEBUG_TRACE,
522 "=> get_ctrls: oid=\"%s\" (%scritical)\n",
523 c->ldctl_oid, c->ldctl_iscritical ? "" : "non", 0 );
526 sc = find_ctrl( c->ldctl_oid );
528 /* recognized control */
530 switch( op->o_tag ) {
532 tagmask = SLAP_CTRL_ADD;
535 tagmask = SLAP_CTRL_BIND;
537 case LDAP_REQ_COMPARE:
538 tagmask = SLAP_CTRL_COMPARE;
540 case LDAP_REQ_DELETE:
541 tagmask = SLAP_CTRL_DELETE;
543 case LDAP_REQ_MODIFY:
544 tagmask = SLAP_CTRL_MODIFY;
546 case LDAP_REQ_RENAME:
547 tagmask = SLAP_CTRL_RENAME;
549 case LDAP_REQ_SEARCH:
550 tagmask = SLAP_CTRL_SEARCH;
552 case LDAP_REQ_UNBIND:
553 tagmask = SLAP_CTRL_UNBIND;
555 case LDAP_REQ_ABANDON:
556 tagmask = SLAP_CTRL_ABANDON;
558 case LDAP_REQ_EXTENDED:
560 assert( op->o_extendedop != NULL );
561 if( sc->sc_extendedops != NULL ) {
563 for( i=0; sc->sc_extendedops[i] != NULL; i++ ) {
564 if( strcmp( op->o_extendedop, sc->sc_extendedops[i] )
575 errmsg = "controls internal error";
579 if (( sc->sc_mask & tagmask ) == tagmask ) {
580 /* available extension */
582 if( !sc->sc_parse ) {
584 errmsg = "not yet implemented";
588 rc = sc->sc_parse( conn, op, c, &errmsg );
590 if( rc != LDAP_SUCCESS ) goto return_results;
592 if ( sc->sc_mask & SLAP_CTRL_FRONTEND ) {
593 /* kludge to disable backend_control() check */
594 c->ldctl_iscritical = 0;
596 } else if ( tagmask == SLAP_CTRL_SEARCH &&
597 sc->sc_mask & SLAP_CTRL_FRONTEND_SEARCH )
599 /* kludge to disable backend_control() check */
600 c->ldctl_iscritical = 0;
603 } else if( c->ldctl_iscritical ) {
604 /* unavailable CRITICAL control */
605 rc = LDAP_UNAVAILABLE_CRITICAL_EXTENSION;
606 errmsg = "critical extension is unavailable";
610 } else if( c->ldctl_iscritical ) {
611 /* unrecognized CRITICAL control */
612 rc = LDAP_UNAVAILABLE_CRITICAL_EXTENSION;
613 errmsg = "critical extension is not recognized";
620 LDAP_LOG( OPERATION, RESULTS,
621 "get_ctrls: n=%d rc=%d err=\"%s\"\n",
622 nctrls, rc, errmsg ? errmsg : "" );
624 Debug( LDAP_DEBUG_TRACE,
625 "<= get_ctrls: n=%d rc=%d err=\"%s\"\n",
626 nctrls, rc, errmsg ? errmsg : "");
629 if( sendres && rc != LDAP_SUCCESS ) {
630 if( rc == SLAPD_DISCONNECT ) {
631 send_ldap_disconnect( conn, op, LDAP_PROTOCOL_ERROR, errmsg );
633 send_ldap_result( conn, op, rc,
634 NULL, errmsg, NULL, NULL );
641 static int parseManageDSAit (
647 if ( op->o_managedsait != SLAP_NO_CONTROL ) {
648 *text = "manageDSAit control specified multiple times";
649 return LDAP_PROTOCOL_ERROR;
652 if ( ctrl->ldctl_value.bv_len ) {
653 *text = "manageDSAit control value not empty";
654 return LDAP_PROTOCOL_ERROR;
657 op->o_managedsait = ctrl->ldctl_iscritical
658 ? SLAP_CRITICAL_CONTROL
659 : SLAP_NONCRITICAL_CONTROL;
664 static int parseProxyAuthz (
671 struct berval dn = { 0, NULL };
673 if ( op->o_proxy_authz != SLAP_NO_CONTROL ) {
674 *text = "proxy authorization control specified multiple times";
675 return LDAP_PROTOCOL_ERROR;
678 op->o_proxy_authz = ctrl->ldctl_iscritical
679 ? SLAP_CRITICAL_CONTROL
680 : SLAP_NONCRITICAL_CONTROL;
683 LDAP_LOG( OPERATION, ARGS,
684 "parseProxyAuthz: conn %lu authzid=\"%s\"\n",
686 ctrl->ldctl_value.bv_len ? ctrl->ldctl_value.bv_val : "anonymous",
689 Debug( LDAP_DEBUG_ARGS,
690 "parseProxyAuthz: conn %lu authzid=\"%s\"\n",
692 ctrl->ldctl_value.bv_len ? ctrl->ldctl_value.bv_val : "anonymous",
696 if( ctrl->ldctl_value.bv_len == 0 ) {
698 LDAP_LOG( OPERATION, RESULTS,
699 "parseProxyAuthz: conn=%lu anonymous\n",
700 conn->c_connid, 0, 0 );
702 Debug( LDAP_DEBUG_TRACE,
703 "parseProxyAuthz: conn=%lu anonymous\n",
704 conn->c_connid, 0, 0 );
708 free( op->o_dn.bv_val );
710 op->o_dn.bv_val = ch_strdup( "" );
712 free( op->o_ndn.bv_val );
713 op->o_ndn.bv_len = 0;
714 op->o_ndn.bv_val = ch_strdup( "" );
719 rc = slap_sasl_getdn( conn,
720 ctrl->ldctl_value.bv_val, ctrl->ldctl_value.bv_len,
721 NULL, &dn, SLAP_GETDN_AUTHZID );
723 if( rc != LDAP_SUCCESS || !dn.bv_len ) {
725 ch_free( dn.bv_val );
727 *text = "authzId mapping failed";
728 return LDAP_PROXY_AUTHZ_FAILURE;
732 LDAP_LOG( OPERATION, RESULTS,
733 "parseProxyAuthz: conn=%lu \"%s\"\n",
735 dn.bv_len ? dn.bv_val : "(NULL)", 0 );
737 Debug( LDAP_DEBUG_TRACE,
738 "parseProxyAuthz: conn=%lu \"%s\"\n",
740 dn.bv_len ? dn.bv_val : "(NULL)", 0 );
743 rc = slap_sasl_authorized( conn, &op->o_ndn, &dn );
746 ch_free( dn.bv_val );
747 *text = "not authorized to assume identity";
748 return LDAP_PROXY_AUTHZ_FAILURE;
751 ch_free( op->o_dn.bv_val );
752 ch_free( op->o_ndn.bv_val );
754 op->o_dn.bv_val = NULL;
758 * NOTE: since slap_sasl_getdn() returns a normalized dn,
759 * from now on op->o_dn is normalized
761 ber_dupbv( &op->o_dn, &dn );
766 static int parseNoOp (
772 if ( op->o_noop != SLAP_NO_CONTROL ) {
773 *text = "noop control specified multiple times";
774 return LDAP_PROTOCOL_ERROR;
777 if ( ctrl->ldctl_value.bv_len ) {
778 *text = "noop control value not empty";
779 return LDAP_PROTOCOL_ERROR;
782 op->o_noop = ctrl->ldctl_iscritical
783 ? SLAP_CRITICAL_CONTROL
784 : SLAP_NONCRITICAL_CONTROL;
789 #ifdef LDAP_CONTROL_PAGEDRESULTS
790 static int parsePagedResults (
799 struct berval cookie = { 0, NULL };
801 if ( op->o_pagedresults != SLAP_NO_CONTROL ) {
802 *text = "paged results control specified multiple times";
803 return LDAP_PROTOCOL_ERROR;
806 if ( ctrl->ldctl_value.bv_len == 0 ) {
807 *text = "paged results control value is empty (or absent)";
808 return LDAP_PROTOCOL_ERROR;
811 /* Parse the control value
812 * realSearchControlValue ::= SEQUENCE {
813 * size INTEGER (0..maxInt),
814 * -- requested page size from client
815 * -- result set size estimate from server
816 * cookie OCTET STRING
819 ber = ber_init( &ctrl->ldctl_value );
821 *text = "internal error";
825 tag = ber_scanf( ber, "{im}", &size, &cookie );
826 (void) ber_free( ber, 1 );
828 if( tag == LBER_ERROR ) {
829 *text = "paged results control could not be decoded";
830 return LDAP_PROTOCOL_ERROR;
834 *text = "paged results control size invalid";
835 return LDAP_PROTOCOL_ERROR;
838 if( cookie.bv_len ) {
839 PagedResultsCookie reqcookie;
840 if( cookie.bv_len != sizeof( reqcookie ) ) {
842 *text = "paged results cookie is invalid";
843 return LDAP_PROTOCOL_ERROR;
846 AC_MEMCPY( &reqcookie, cookie.bv_val, sizeof( reqcookie ));
848 if( reqcookie > op->o_pagedresults_state.ps_cookie ) {
850 *text = "paged results cookie is invalid";
851 return LDAP_PROTOCOL_ERROR;
853 } else if( reqcookie < op->o_pagedresults_state.ps_cookie ) {
854 *text = "paged results cookie is invalid or old";
855 return LDAP_UNWILLING_TO_PERFORM;
858 /* Initial request. Initialize state. */
859 op->o_pagedresults_state.ps_cookie = 0;
860 op->o_pagedresults_state.ps_id = NOID;
863 op->o_pagedresults_size = size;
865 op->o_pagedresults = ctrl->ldctl_iscritical
866 ? SLAP_CRITICAL_CONTROL
867 : SLAP_NONCRITICAL_CONTROL;
873 int parseValuesReturnFilter (
881 struct berval fstr = { 0, NULL };
882 const char *err_msg = "";
884 if ( op->o_valuesreturnfilter != SLAP_NO_CONTROL ) {
885 *text = "valuesReturnFilter control specified multiple times";
886 return LDAP_PROTOCOL_ERROR;
889 if ( ctrl->ldctl_value.bv_len == 0 ) {
890 *text = "valuesReturnFilter control value is empty (or absent)";
891 return LDAP_PROTOCOL_ERROR;
894 ber = ber_init( &(ctrl->ldctl_value) );
896 *text = "internal error";
900 rc = get_vrFilter( conn, ber, &(op->vrFilter), &err_msg);
902 if( rc != LDAP_SUCCESS ) {
904 if( rc == SLAPD_DISCONNECT ) {
905 send_ldap_disconnect( conn, op,
906 LDAP_PROTOCOL_ERROR, *text );
908 send_ldap_result( conn, op, rc,
909 NULL, *text, NULL, NULL );
911 if( fstr.bv_val != NULL) free( fstr.bv_val );
912 if( op->vrFilter != NULL) vrFilter_free( op->vrFilter );
915 vrFilter2bv( op->vrFilter, &fstr );
919 LDAP_LOG( OPERATION, ARGS,
920 "parseValuesReturnFilter: conn %d vrFilter: %s\n",
921 conn->c_connid, fstr.bv_len ? fstr.bv_val : "empty" , 0 );
923 Debug( LDAP_DEBUG_ARGS, " vrFilter: %s\n",
924 fstr.bv_len ? fstr.bv_val : "empty", 0, 0 );
927 op->o_valuesreturnfilter = ctrl->ldctl_iscritical
928 ? SLAP_CRITICAL_CONTROL
929 : SLAP_NONCRITICAL_CONTROL;
934 #ifdef LDAP_CONTROL_SUBENTRIES
935 static int parseSubentries (
941 if ( op->o_subentries != SLAP_NO_CONTROL ) {
942 *text = "subentries control specified multiple times";
943 return LDAP_PROTOCOL_ERROR;
946 /* FIXME: should use BER library */
947 if( ( ctrl->ldctl_value.bv_len != 3 )
948 && ( ctrl->ldctl_value.bv_val[0] != 0x01 )
949 && ( ctrl->ldctl_value.bv_val[1] != 0x01 ))
951 *text = "subentries control value encoding is bogus";
952 return LDAP_PROTOCOL_ERROR;
955 op->o_subentries = ctrl->ldctl_iscritical
956 ? SLAP_CRITICAL_CONTROL
957 : SLAP_NONCRITICAL_CONTROL;
959 op->o_subentries_visibility = (ctrl->ldctl_value.bv_val[2] != 0x00);
965 #ifdef LDAP_CONTROL_X_PERMISSIVE_MODIFY
966 static int parsePermissiveModify (
972 if ( op->o_permissive_modify != SLAP_NO_CONTROL ) {
973 *text = "permissiveModify control specified multiple times";
974 return LDAP_PROTOCOL_ERROR;
977 if ( ctrl->ldctl_value.bv_len ) {
978 *text = "permissiveModify control value not empty";
979 return LDAP_PROTOCOL_ERROR;
982 op->o_permissive_modify = ctrl->ldctl_iscritical
983 ? SLAP_CRITICAL_CONTROL
984 : SLAP_NONCRITICAL_CONTROL;
990 #ifdef LDAP_CONTROL_X_DOMAIN_SCOPE
991 static int parseDomainScope (
997 if ( op->o_domain_scope != SLAP_NO_CONTROL ) {
998 *text = "domainScope control specified multiple times";
999 return LDAP_PROTOCOL_ERROR;
1002 if ( ctrl->ldctl_value.bv_len ) {
1003 *text = "domainScope control value not empty";
1004 return LDAP_PROTOCOL_ERROR;
1007 op->o_domain_scope = ctrl->ldctl_iscritical
1008 ? SLAP_CRITICAL_CONTROL
1009 : SLAP_NONCRITICAL_CONTROL;
1011 return LDAP_SUCCESS;
1015 #ifdef LDAP_CLIENT_UPDATE
1016 static int parseClientUpdate (
1027 struct berval scheme = { 0, NULL };
1028 struct berval cookie = { 0, NULL };
1030 if ( op->o_clientupdate != SLAP_NO_CONTROL ) {
1031 *text = "LCUP client update control specified multiple times";
1032 return LDAP_PROTOCOL_ERROR;
1036 if ( op->o_sync != SLAP_NO_CONTROL ) {
1037 *text = "LDAP Client Update and Sync controls used together";
1038 return LDAP_PROTOCOL_ERROR;
1042 if ( ctrl->ldctl_value.bv_len == 0 ) {
1043 *text = "LCUP client update control value is empty (or absent)";
1044 return LDAP_PROTOCOL_ERROR;
1047 /* Parse the control value
1048 * ClientUpdateControlValue ::= SEQUENCE {
1049 * updateType ENUMERATED {
1050 * synchronizeOnly {0},
1051 * synchronizeAndPersist {1},
1052 * persistOnly {2} },
1053 * sendCookieInterval INTEGER OPTIONAL,
1054 * cookie LCUPCookie OPTIONAL
1058 ber = ber_init( &ctrl->ldctl_value );
1060 *text = "internal error";
1064 if ( (tag = ber_scanf( ber, "{i" /*}*/, &type )) == LBER_ERROR ) {
1065 *text = "LCUP client update control : decoding error";
1066 return LDAP_PROTOCOL_ERROR;
1070 case LDAP_CUP_SYNC_ONLY:
1071 type = SLAP_LCUP_SYNC;
1073 case LDAP_CUP_SYNC_AND_PERSIST:
1074 type = SLAP_LCUP_SYNC_AND_PERSIST;
1076 case LDAP_CUP_PERSIST_ONLY:
1077 type = SLAP_LCUP_PERSIST;
1080 *text = "LCUP client update control : unknown update type";
1081 return LDAP_PROTOCOL_ERROR;
1084 if ( (tag = ber_peek_tag( ber, &len )) == LBER_DEFAULT ) {
1085 *text = "LCUP client update control : decoding error";
1086 return LDAP_PROTOCOL_ERROR;
1089 if ( tag == LDAP_CUP_TAG_INTERVAL ) {
1090 if ( (tag = ber_scanf( ber, "i", &interval )) == LBER_ERROR ) {
1091 *text = "LCUP client update control : decoding error";
1092 return LDAP_PROTOCOL_ERROR;
1095 if ( interval <= 0 ) {
1096 /* server chooses interval */
1097 interval = LDAP_CUP_DEFAULT_SEND_COOKIE_INTERVAL;
1101 /* server chooses interval */
1102 interval = LDAP_CUP_DEFAULT_SEND_COOKIE_INTERVAL;
1105 if ( (tag = ber_peek_tag( ber, &len )) == LBER_DEFAULT ) {
1106 *text = "LCUP client update control : decoding error";
1107 return LDAP_PROTOCOL_ERROR;
1110 if ( tag == LDAP_CUP_TAG_COOKIE ) {
1111 if ( (tag = ber_scanf( ber, /*{*/ "{mm}}",
1112 &scheme, &cookie )) == LBER_ERROR )
1114 *text = "LCUP client update control : decoding error";
1115 return LDAP_PROTOCOL_ERROR;
1119 /* TODO : Cookie Scheme Validation */
1121 if ( lcup_cookie_scheme_validate(scheme) != LDAP_SUCCESS ) {
1122 *text = "Unsupported LCUP cookie scheme";
1123 return LCUP_UNSUPPORTED_SCHEME;
1126 if ( lcup_cookie_validate(scheme, cookie) != LDAP_SUCCESS ) {
1127 *text = "Invalid LCUP cookie";
1128 return LCUP_INVALID_COOKIE;
1132 ber_dupbv( &op->o_clientupdate_state, &cookie );
1134 (void) ber_free( ber, 1 );
1136 op->o_clientupdate_type = (char) type;
1137 op->o_clientupdate_interval = interval;
1139 op->o_clientupdate = ctrl->ldctl_iscritical
1140 ? SLAP_CRITICAL_CONTROL
1141 : SLAP_NONCRITICAL_CONTROL;
1143 return LDAP_SUCCESS;
1148 static int parseLdupSync (
1158 struct berval cookie = { 0, NULL };
1160 if ( op->o_sync != SLAP_NO_CONTROL ) {
1161 *text = "LDAP Sync control specified multiple times";
1162 return LDAP_PROTOCOL_ERROR;
1165 #ifdef LDAP_CLIENT_UPDATE
1166 if ( op->o_clientupdate != SLAP_NO_CONTROL ) {
1167 *text = "LDAP Sync and LDAP Client Update controls used together";
1168 return LDAP_PROTOCOL_ERROR;
1172 if ( ctrl->ldctl_value.bv_len == 0 ) {
1173 *text = "LDAP Sync control value is empty (or absent)";
1174 return LDAP_PROTOCOL_ERROR;
1177 /* Parse the control value
1178 * syncRequestValue ::= SEQUENCE {
1183 * refreshAndPersist (3)
1185 * cookie syncCookie OPTIONAL
1189 ber = ber_init( &ctrl->ldctl_value );
1191 *text = "internal error";
1195 if ( (tag = ber_scanf( ber, "{i" /*}*/, &mode )) == LBER_ERROR ) {
1196 *text = "LDAP Sync control : mode decoding error";
1197 return LDAP_PROTOCOL_ERROR;
1201 case LDAP_SYNC_REFRESH_ONLY:
1202 mode = SLAP_SYNC_REFRESH;
1204 case LDAP_SYNC_REFRESH_AND_PERSIST:
1205 mode = SLAP_SYNC_REFRESH_AND_PERSIST;
1208 *text = "LDAP Sync control : unknown update mode";
1209 return LDAP_PROTOCOL_ERROR;
1212 tag = ber_peek_tag( ber, &len );
1214 if ( tag == LDAP_SYNC_TAG_COOKIE ) {
1215 if (( ber_scanf( ber, /*{*/ "m}",
1216 &cookie )) == LBER_ERROR ) {
1217 *text = "LDAP Sync control : cookie decoding error";
1218 return LDAP_PROTOCOL_ERROR;
1221 if (( ber_scanf( ber, /*{*/ "}")) == LBER_ERROR ) {
1222 *text = "LDAP Sync control : decoding error";
1223 return LDAP_PROTOCOL_ERROR;
1226 cookie.bv_val = NULL;
1229 /* TODO : Cookie Scheme Validation */
1231 if ( lcup_cookie_scheme_validate(scheme) != LDAP_SUCCESS ) {
1232 *text = "Unsupported LCUP cookie scheme";
1233 return LCUP_UNSUPPORTED_SCHEME;
1236 if ( lcup_cookie_validate(scheme, cookie) != LDAP_SUCCESS ) {
1237 *text = "Invalid LCUP cookie";
1238 return LCUP_INVALID_COOKIE;
1242 ber_dupbv( &op->o_sync_state, &cookie );
1244 (void) ber_free( ber, 1 );
1246 op->o_sync_mode = (char) mode;
1248 op->o_sync = ctrl->ldctl_iscritical
1249 ? SLAP_CRITICAL_CONTROL
1250 : SLAP_NONCRITICAL_CONTROL;
1252 return LDAP_SUCCESS;