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 Debug( LDAP_DEBUG_TRACE, "=> get_ctrls\n", 0, 0, 0 );
57 if( op->o_protocol < LDAP_VERSION3 ) {
59 errmsg = "controls require LDAPv3";
63 /* set through each element */
64 *ctrls = ch_malloc( 1 * sizeof(LDAPControl *) );
67 if( *ctrls == NULL ) {
76 for( tag = ber_first_element( ber, &len, &opaque );
78 tag = ber_next_element( ber, &len, opaque ) )
83 tctrl = ch_calloc( 1, sizeof(LDAPControl) );
84 tctrl->ldctl_oid = NULL;
85 tctrl->ldctl_value.bv_val = NULL;
87 /* allocate pointer space for current controls (nctrls)
88 * + this control + extra NULL
90 tctrls = (tctrl == NULL) ? NULL :
91 ch_realloc(*ctrls, (nctrls+2) * sizeof(LDAPControl *));
94 if( tctrls == NULL ) {
95 /* one of the above allocation failed */
101 ldap_controls_free(*ctrls);
105 errmsg = "no memory";
110 tctrls[nctrls++] = tctrl;
111 tctrls[nctrls] = NULL;
113 tag = ber_scanf( ber, "{a" /*}*/, &tctrl->ldctl_oid );
115 if( tag == LBER_ERROR ) {
116 Debug( LDAP_DEBUG_TRACE, "=> get_ctrls: get oid failed.\n",
119 ldap_controls_free( tctrls );
121 errmsg = "decoding controls error";
125 tag = ber_peek_tag( ber, &len );
127 if( tag == LBER_BOOLEAN ) {
129 tag = ber_scanf( ber, "b", &crit );
131 if( tag == LBER_ERROR ) {
132 Debug( LDAP_DEBUG_TRACE, "=> get_ctrls: get crit failed.\n",
135 ldap_controls_free( tctrls );
137 errmsg = "decoding controls error";
141 tctrl->ldctl_iscritical = (crit != 0);
142 tag = ber_peek_tag( ber, &len );
145 Debug( LDAP_DEBUG_TRACE, "=> get_ctrls: oid=\"%s\" (%scritical)\n",
147 tctrl->ldctl_iscritical ? "" : "non",
150 if( tag == LBER_OCTETSTRING ) {
151 tag = ber_scanf( ber, "o", &tctrl->ldctl_value );
153 if( tag == LBER_ERROR ) {
154 Debug( LDAP_DEBUG_TRACE, "=> get_ctrls: get value failed.\n",
157 ldap_controls_free( tctrls );
159 errmsg = "decoding controls error";
164 if( tctrl->ldctl_iscritical &&
165 !charray_inlist( supportedControls, tctrl->ldctl_oid ) )
167 rc = LDAP_UNAVAILABLE_CRITICAL_EXTENSION;
168 errmsg = "critical extension is unavailable ";
176 Debug( LDAP_DEBUG_TRACE, "<= get_ctrls: %d %d %s\n",
177 nctrls, rc, errmsg ? errmsg : "");
179 if( sendres && rc != LDAP_SUCCESS ) {
181 send_ldap_disconnect( conn, op, rc, errmsg );
183 send_ldap_result( conn, op, rc,
184 NULL, errmsg, NULL, NULL );
192 int get_manageDSAit( Operation *op )
195 if( op == NULL || op->o_ctrls == NULL ) {
199 for( i=0; op->o_ctrls[i] != NULL; i++ ) {
200 if( strcmp( LDAP_CONTROL_MANAGEDSAIT, op->o_ctrls[i]->ldctl_oid )