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.
14 #include <ac/string.h>
15 #include <ac/socket.h>
19 #include "../../libraries/liblber/lber-int.h"
21 char *supportedControls[] = {
22 LDAP_CONTROL_MANAGEDSAIT,
35 BerElement *ber = op->o_ber;
36 LDAPControl ***ctrls = &op->o_ctrls;
37 int rc = LDAP_SUCCESS;
40 len = ber_pvt_ber_remaining(ber);
48 if(( tag = ber_peek_tag( ber, &len )) != LDAP_TAG_CONTROLS ) {
49 if( tag == LBER_ERROR ) {
51 errmsg = "unexpected data in PDU";
57 Debug( LDAP_DEBUG_TRACE, "=> get_ctrls\n", 0, 0, 0 );
59 if( op->o_protocol < LDAP_VERSION3 ) {
61 errmsg = "controls require LDAPv3";
65 /* set through each element */
66 *ctrls = ch_malloc( 1 * sizeof(LDAPControl *) );
69 if( *ctrls == NULL ) {
78 for( tag = ber_first_element( ber, &len, &opaque );
80 tag = ber_next_element( ber, &len, opaque ) )
85 tctrl = ch_calloc( 1, sizeof(LDAPControl) );
86 tctrl->ldctl_oid = NULL;
87 tctrl->ldctl_value.bv_val = NULL;
89 /* allocate pointer space for current controls (nctrls)
90 * + this control + extra NULL
92 tctrls = (tctrl == NULL) ? NULL :
93 ch_realloc(*ctrls, (nctrls+2) * sizeof(LDAPControl *));
96 if( tctrls == NULL ) {
97 /* one of the above allocation failed */
103 ldap_controls_free(*ctrls);
107 errmsg = "no memory";
112 tctrls[nctrls++] = tctrl;
113 tctrls[nctrls] = NULL;
115 tag = ber_scanf( ber, "{a" /*}*/, &tctrl->ldctl_oid );
117 if( tag == LBER_ERROR ) {
118 Debug( LDAP_DEBUG_TRACE, "=> get_ctrls: get oid failed.\n",
121 ldap_controls_free( tctrls );
123 errmsg = "decoding controls error";
127 tag = ber_peek_tag( ber, &len );
129 if( tag == LBER_BOOLEAN ) {
131 tag = ber_scanf( ber, "b", &crit );
133 if( tag == LBER_ERROR ) {
134 Debug( LDAP_DEBUG_TRACE, "=> get_ctrls: get crit failed.\n",
137 ldap_controls_free( tctrls );
139 errmsg = "decoding controls error";
143 tctrl->ldctl_iscritical = (crit != 0);
144 tag = ber_peek_tag( ber, &len );
147 Debug( LDAP_DEBUG_TRACE, "=> get_ctrls: oid=\"%s\" (%scritical)\n",
149 tctrl->ldctl_iscritical ? "" : "non",
152 if( tag == LBER_OCTETSTRING ) {
153 tag = ber_scanf( ber, "o", &tctrl->ldctl_value );
155 if( tag == LBER_ERROR ) {
156 Debug( LDAP_DEBUG_TRACE, "=> get_ctrls: get value failed.\n",
159 ldap_controls_free( tctrls );
161 errmsg = "decoding controls error";
166 if( tctrl->ldctl_iscritical &&
167 !charray_inlist( supportedControls, tctrl->ldctl_oid ) )
169 rc = LDAP_UNAVAILABLE_CRITICAL_EXTENSION;
170 errmsg = "critical extension is unavailable ";
178 Debug( LDAP_DEBUG_TRACE, "<= get_ctrls: %d %d %s\n",
179 nctrls, rc, errmsg ? errmsg : "");
181 if( sendres && rc != LDAP_SUCCESS ) {
183 send_ldap_disconnect( conn, op, rc, errmsg );
185 send_ldap_result( conn, op, rc,
186 NULL, errmsg, NULL, NULL );
194 int get_manageDSAit( Operation *op )
197 if( op == NULL || op->o_ctrls == NULL ) {
201 for( i=0; op->o_ctrls[i] != NULL; i++ ) {
202 if( strcmp( LDAP_CONTROL_MANAGEDSAIT, op->o_ctrls[i]->ldctl_oid )