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>
22 #include "../../libraries/liblber/lber-int.h"
24 char *supportedControls[] = {
25 LDAP_CONTROL_MANAGEDSAIT,
38 BerElement *ber = op->o_ber;
39 LDAPControl ***ctrls = &op->o_ctrls;
40 int rc = LDAP_SUCCESS;
43 len = ber_pvt_ber_remaining(ber);
51 if(( tag = ber_peek_tag( ber, &len )) != LDAP_TAG_CONTROLS ) {
52 if( tag == LBER_ERROR ) {
53 rc = SLAPD_DISCONNECT;
54 errmsg = "unexpected data in PDU";
61 LDAP_LOG(( "operation", LDAP_LEVEL_ENTRY,
62 "get_ctrls: conn %d\n", conn->c_connid ));
64 Debug( LDAP_DEBUG_TRACE, "=> get_ctrls\n", 0, 0, 0 );
66 if( op->o_protocol < LDAP_VERSION3 ) {
67 rc = SLAPD_DISCONNECT;
68 errmsg = "controls require LDAPv3";
72 /* set through each element */
73 *ctrls = ch_malloc( 1 * sizeof(LDAPControl *) );
76 if( *ctrls == NULL ) {
83 *ctrls[nctrls] = NULL;
85 for( tag = ber_first_element( ber, &len, &opaque );
87 tag = ber_next_element( ber, &len, opaque ) )
92 tctrl = ch_calloc( 1, sizeof(LDAPControl) );
93 tctrl->ldctl_oid = NULL;
94 tctrl->ldctl_value.bv_val = NULL;
96 /* allocate pointer space for current controls (nctrls)
97 * + this control + extra NULL
99 tctrls = (tctrl == NULL) ? NULL :
100 ch_realloc(*ctrls, (nctrls+2) * sizeof(LDAPControl *));
103 if( tctrls == NULL ) {
104 /* one of the above allocation failed */
106 if( tctrl != NULL ) {
110 ldap_controls_free(*ctrls);
114 errmsg = "no memory";
119 tctrls[nctrls++] = tctrl;
120 tctrls[nctrls] = NULL;
122 tag = ber_scanf( ber, "{a" /*}*/, &tctrl->ldctl_oid );
124 if( tag == LBER_ERROR ) {
126 LDAP_LOG(( "operation", LDAP_LEVEL_INFO,
127 "get_ctrls: conn %d get OID failed.\n",
130 Debug( LDAP_DEBUG_TRACE, "=> get_ctrls: get oid failed.\n",
134 ldap_controls_free( tctrls );
135 rc = SLAPD_DISCONNECT;
136 errmsg = "decoding controls error";
140 tag = ber_peek_tag( ber, &len );
142 if( tag == LBER_BOOLEAN ) {
144 tag = ber_scanf( ber, "b", &crit );
146 if( tag == LBER_ERROR ) {
148 LDAP_LOG(( "operation", LDAP_LEVEL_INFO,
149 "get_ctrls: conn %d get crit failed.\n",
152 Debug( LDAP_DEBUG_TRACE, "=> get_ctrls: get crit failed.\n",
156 ldap_controls_free( tctrls );
157 rc = SLAPD_DISCONNECT;
158 errmsg = "decoding controls error";
162 tctrl->ldctl_iscritical = (crit != 0);
163 tag = ber_peek_tag( ber, &len );
167 LDAP_LOG(( "operation", LDAP_LEVEL_INFO,
168 "get_ctrls: conn %d oid=\"%s\" (%scritical)\n",
169 conn->c_connid, tctrl->ldctl_oid,
170 tctrl->ldctl_iscritical ? "" : "non" ));
172 Debug( LDAP_DEBUG_TRACE, "=> get_ctrls: oid=\"%s\" (%scritical)\n",
174 tctrl->ldctl_iscritical ? "" : "non",
177 if( tag == LBER_OCTETSTRING ) {
178 tag = ber_scanf( ber, "o", &tctrl->ldctl_value );
180 if( tag == LBER_ERROR ) {
182 LDAP_LOG(( "operation", LDAP_LEVEL_INFO,
183 "get_ctrls: conn %d get value failed.\n", conn->c_connid ));
185 Debug( LDAP_DEBUG_TRACE, "=> get_ctrls: get value failed.\n",
189 ldap_controls_free( tctrls );
190 rc = SLAPD_DISCONNECT;
191 errmsg = "decoding controls error";
196 if( tctrl->ldctl_iscritical &&
197 !charray_inlist( supportedControls, tctrl->ldctl_oid ) )
199 rc = LDAP_UNAVAILABLE_CRITICAL_EXTENSION;
200 errmsg = "critical extension is unavailable ";
209 LDAP_LOG(( "operation", LDAP_LEVEL_RESULTS,
210 "get_ctrls: conn %d %d %d %s\n",
211 conn->c_connid, nctrls, rc, errmsg ? errmsg : "" ));
213 Debug( LDAP_DEBUG_TRACE, "<= get_ctrls: %d %d %s\n",
214 nctrls, rc, errmsg ? errmsg : "");
217 if( sendres && rc != LDAP_SUCCESS ) {
218 if( rc == SLAPD_DISCONNECT ) {
219 send_ldap_disconnect( conn, op, LDAP_PROTOCOL_ERROR, errmsg );
221 send_ldap_result( conn, op, rc,
222 NULL, errmsg, NULL, NULL );
230 int get_manageDSAit( Operation *op )
233 if( op == NULL || op->o_ctrls == NULL ) {
237 for( i=0; op->o_ctrls[i] != NULL; i++ ) {
238 if( strcmp( LDAP_CONTROL_MANAGEDSAIT, op->o_ctrls[i]->ldctl_oid )