3 * Copyright 1999-2000 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 char *supportedControls[] = {
23 LDAP_CONTROL_MANAGEDSAIT,
36 BerElement *ber = op->o_ber;
37 LDAPControl ***ctrls = &op->o_ctrls;
38 int rc = LDAP_SUCCESS;
41 len = ber_pvt_ber_remaining(ber);
49 if(( tag = ber_peek_tag( ber, &len )) != LDAP_TAG_CONTROLS ) {
50 if( tag == LBER_ERROR ) {
51 rc = SLAPD_DISCONNECT;
52 errmsg = "unexpected data in PDU";
58 Debug( LDAP_DEBUG_TRACE, "=> get_ctrls\n", 0, 0, 0 );
60 if( op->o_protocol < LDAP_VERSION3 ) {
61 rc = SLAPD_DISCONNECT;
62 errmsg = "controls require LDAPv3";
66 /* set through each element */
67 *ctrls = ch_malloc( 1 * sizeof(LDAPControl *) );
70 if( *ctrls == NULL ) {
77 *ctrls[nctrls] = NULL;
79 for( tag = ber_first_element( ber, &len, &opaque );
81 tag = ber_next_element( ber, &len, opaque ) )
86 tctrl = ch_calloc( 1, sizeof(LDAPControl) );
87 tctrl->ldctl_oid = NULL;
88 tctrl->ldctl_value.bv_val = NULL;
90 /* allocate pointer space for current controls (nctrls)
91 * + this control + extra NULL
93 tctrls = (tctrl == NULL) ? NULL :
94 ch_realloc(*ctrls, (nctrls+2) * sizeof(LDAPControl *));
97 if( tctrls == NULL ) {
98 /* one of the above allocation failed */
100 if( tctrl != NULL ) {
104 ldap_controls_free(*ctrls);
108 errmsg = "no memory";
113 tctrls[nctrls++] = tctrl;
114 tctrls[nctrls] = NULL;
116 tag = ber_scanf( ber, "{a" /*}*/, &tctrl->ldctl_oid );
118 if( tag == LBER_ERROR ) {
119 Debug( LDAP_DEBUG_TRACE, "=> get_ctrls: get oid failed.\n",
122 ldap_controls_free( tctrls );
123 rc = SLAPD_DISCONNECT;
124 errmsg = "decoding controls error";
128 tag = ber_peek_tag( ber, &len );
130 if( tag == LBER_BOOLEAN ) {
132 tag = ber_scanf( ber, "b", &crit );
134 if( tag == LBER_ERROR ) {
135 Debug( LDAP_DEBUG_TRACE, "=> get_ctrls: get crit failed.\n",
138 ldap_controls_free( tctrls );
139 rc = SLAPD_DISCONNECT;
140 errmsg = "decoding controls error";
144 tctrl->ldctl_iscritical = (crit != 0);
145 tag = ber_peek_tag( ber, &len );
148 Debug( LDAP_DEBUG_TRACE, "=> get_ctrls: oid=\"%s\" (%scritical)\n",
150 tctrl->ldctl_iscritical ? "" : "non",
153 if( tag == LBER_OCTETSTRING ) {
154 tag = ber_scanf( ber, "o", &tctrl->ldctl_value );
156 if( tag == LBER_ERROR ) {
157 Debug( LDAP_DEBUG_TRACE, "=> get_ctrls: get value failed.\n",
160 ldap_controls_free( tctrls );
161 rc = SLAPD_DISCONNECT;
162 errmsg = "decoding controls error";
167 if( tctrl->ldctl_iscritical &&
168 !charray_inlist( supportedControls, tctrl->ldctl_oid ) )
170 rc = LDAP_UNAVAILABLE_CRITICAL_EXTENSION;
171 errmsg = "critical extension is unavailable ";
179 Debug( LDAP_DEBUG_TRACE, "<= get_ctrls: %d %d %s\n",
180 nctrls, rc, errmsg ? errmsg : "");
182 if( sendres && rc != LDAP_SUCCESS ) {
183 if( rc == SLAPD_DISCONNECT ) {
184 send_ldap_disconnect( conn, op, rc, errmsg );
186 send_ldap_result( conn, op, rc,
187 NULL, errmsg, NULL, NULL );
195 int get_manageDSAit( Operation *op )
198 if( op == NULL || op->o_ctrls == NULL ) {
202 for( i=0; op->o_ctrls[i] != NULL; i++ ) {
203 if( strcmp( LDAP_CONTROL_MANAGEDSAIT, op->o_ctrls[i]->ldctl_oid )