2 * Copyright 1999 The OpenLDAP Foundation.
5 * Redistribution and use in source and binary forms are permitted only
6 * as authorized by the OpenLDAP Public License. A copy of this
7 * license is available at http://www.OpenLDAP.org/license.html or
8 * in file LICENSE in the top-level directory of the distribution.
13 #include <ac/socket.h>
17 #include "../../libraries/liblber/lber-int.h"
19 char *supportedControls[] = {
20 LDAP_CONTROL_MANAGEDSAIT,
33 BerElement *ber = op->o_ber;
34 LDAPControl ***ctrls = &op->o_ctrls;
35 int rc = LDAP_SUCCESS;
38 len = ber_pvt_ber_remaining(ber);
46 if(( tag = ber_peek_tag( ber, &len )) != LDAP_TAG_CONTROLS ) {
47 if( tag == LBER_ERROR ) {
49 errmsg = "unexpected data in PDU";
55 if( op->o_protocol < LDAP_VERSION3 ) {
57 errmsg = "controls require LDAPv3";
61 /* set through each element */
63 *ctrls = ch_malloc( 1 * sizeof(LDAPControl *) );
66 if( *ctrls == NULL ) {
75 for( tag = ber_first_element( ber, &len, &opaque );
77 tag = ber_next_element( ber, &len, opaque ) )
82 tctrl = ch_calloc( 1, sizeof(LDAPControl) );
84 /* allocate pointer space for current controls (nctrls)
85 * + this control + extra NULL
87 tctrls = (tctrl == NULL) ? NULL :
88 ch_realloc(*ctrls, (nctrls+2) * sizeof(LDAPControl *));
91 if( tctrls == NULL ) {
92 /* one of the above allocation failed */
98 ldap_controls_free(*ctrls);
102 errmsg = "no memory";
108 tctrls[nctrls++] = tctrl;
109 tctrls[nctrls] = NULL;
111 tag = ber_scanf( ber, "{a" /*}*/, &tctrl->ldctl_oid );
113 if( tag != LBER_ERROR ) {
114 tag = ber_peek_tag( ber, &len );
117 if( tag == LBER_BOOLEAN ) {
119 tag = ber_scanf( ber, "b", &crit );
120 tctrl->ldctl_iscritical = crit ? (char) 0 : (char) ~0;
123 if( tag != LBER_ERROR ) {
124 tag = ber_peek_tag( ber, &len );
127 if( tag == LBER_OCTETSTRING ) {
128 tag = ber_scanf( ber, "o", &tctrl->ldctl_value );
131 tctrl->ldctl_value.bv_val = NULL;
134 if( tag == LBER_ERROR ) {
136 ldap_controls_free( tctrls );
138 errmsg = "decoding controls error";
142 if( tctrl->ldctl_iscritical &&
143 !charray_inlist( supportedControls, tctrl->ldctl_oid ) )
145 rc = LDAP_UNAVAILABLE_CRITICAL_EXTENSION;
146 errmsg = "critical extension is unavailable ";
154 if( sendres && rc != LDAP_SUCCESS ) {
156 send_ldap_disconnect( conn, op, rc, errmsg );
158 send_ldap_result( conn, op, rc,
159 NULL, errmsg, NULL, NULL );
167 int get_manageDSAit( Operation *op )
170 if( op == NULL || op->o_ctrls == NULL ) {
174 for( i=0; op->o_ctrls[i] != NULL; i++ ) {
175 if( strcmp( LDAP_CONTROL_MANAGEDSAIT, op->o_ctrls[i]->ldctl_oid )