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 */
65 *ctrls = ch_malloc( 1 * sizeof(LDAPControl *) );
68 if( *ctrls == NULL ) {
77 for( tag = ber_first_element( ber, &len, &opaque );
79 tag = ber_next_element( ber, &len, opaque ) )
84 tctrl = ch_calloc( 1, sizeof(LDAPControl) );
85 tctrl->ldctl_oid = NULL;
86 tctrl->ldctl_value.bv_val = NULL;
88 /* allocate pointer space for current controls (nctrls)
89 * + this control + extra NULL
91 tctrls = (tctrl == NULL) ? NULL :
92 ch_realloc(*ctrls, (nctrls+2) * sizeof(LDAPControl *));
95 if( tctrls == NULL ) {
96 /* one of the above allocation failed */
102 ldap_controls_free(*ctrls);
106 errmsg = "no memory";
111 tctrls[nctrls++] = tctrl;
112 tctrls[nctrls] = NULL;
114 tag = ber_scanf( ber, "{a" /*}*/, &tctrl->ldctl_oid );
116 if( tag == LBER_ERROR ) {
117 Debug( LDAP_DEBUG_TRACE, "=> get_ctrls: get oid failed.\n",
120 ldap_controls_free( tctrls );
122 errmsg = "decoding controls error";
126 Debug( LDAP_DEBUG_TRACE, "=> get_ctrls: %s\n",
127 tctrl->ldctl_oid, 0, 0 );
129 tag = ber_peek_tag( ber, &len );
131 if( tag == LBER_BOOLEAN ) {
133 tag = ber_scanf( ber, "b", &crit );
135 if( tag == LBER_ERROR ) {
136 Debug( LDAP_DEBUG_TRACE, "=> get_ctrls: get crit failed.\n",
139 ldap_controls_free( tctrls );
141 errmsg = "decoding controls error";
145 tctrl->ldctl_iscritical = crit ? (char) 0 : (char) ~0;
146 tag = ber_peek_tag( ber, &len );
149 if( tag == LBER_OCTETSTRING ) {
150 tag = ber_scanf( ber, "o", &tctrl->ldctl_value );
152 if( tag == LBER_ERROR ) {
153 Debug( LDAP_DEBUG_TRACE, "=> get_ctrls: get value failed.\n",
156 ldap_controls_free( tctrls );
158 errmsg = "decoding controls error";
163 if( tctrl->ldctl_iscritical &&
164 !charray_inlist( supportedControls, tctrl->ldctl_oid ) )
166 rc = LDAP_UNAVAILABLE_CRITICAL_EXTENSION;
167 errmsg = "critical extension is unavailable ";
175 Debug( LDAP_DEBUG_TRACE, "<= get_ctrls: %d %d %s\n",
176 nctrls, rc, errmsg ? errmsg : "");
178 if( sendres && rc != LDAP_SUCCESS ) {
180 send_ldap_disconnect( conn, op, rc, errmsg );
182 send_ldap_result( conn, op, rc,
183 NULL, errmsg, NULL, NULL );
191 int get_manageDSAit( Operation *op )
194 if( op == NULL || op->o_ctrls == NULL ) {
198 for( i=0; op->o_ctrls[i] != NULL; i++ ) {
199 if( strcmp( LDAP_CONTROL_MANAGEDSAIT, op->o_ctrls[i]->ldctl_oid )