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";
59 LDAP_LOG(( "operation", LDAP_LEVEL_ENTRY,
60 "get_ctrls: conn %d\n", conn->c_connid ));
62 Debug( LDAP_DEBUG_TRACE, "=> get_ctrls\n", 0, 0, 0 );
64 if( op->o_protocol < LDAP_VERSION3 ) {
65 rc = SLAPD_DISCONNECT;
66 errmsg = "controls require LDAPv3";
70 /* set through each element */
71 *ctrls = ch_malloc( 1 * sizeof(LDAPControl *) );
74 if( *ctrls == NULL ) {
81 *ctrls[nctrls] = NULL;
83 for( tag = ber_first_element( ber, &len, &opaque );
85 tag = ber_next_element( ber, &len, opaque ) )
90 tctrl = ch_calloc( 1, sizeof(LDAPControl) );
91 tctrl->ldctl_oid = NULL;
92 tctrl->ldctl_value.bv_val = NULL;
94 /* allocate pointer space for current controls (nctrls)
95 * + this control + extra NULL
97 tctrls = (tctrl == NULL) ? NULL :
98 ch_realloc(*ctrls, (nctrls+2) * sizeof(LDAPControl *));
101 if( tctrls == NULL ) {
102 /* one of the above allocation failed */
104 if( tctrl != NULL ) {
108 ldap_controls_free(*ctrls);
112 errmsg = "no memory";
117 tctrls[nctrls++] = tctrl;
118 tctrls[nctrls] = NULL;
120 tag = ber_scanf( ber, "{a" /*}*/, &tctrl->ldctl_oid );
122 if( tag == LBER_ERROR ) {
124 LDAP_LOG(( "operation", LDAP_LEVEL_INFO,
125 "get_ctrls: conn %d get OID failed.\n",
128 Debug( LDAP_DEBUG_TRACE, "=> get_ctrls: get oid failed.\n",
132 ldap_controls_free( tctrls );
133 rc = SLAPD_DISCONNECT;
134 errmsg = "decoding controls error";
138 tag = ber_peek_tag( ber, &len );
140 if( tag == LBER_BOOLEAN ) {
142 tag = ber_scanf( ber, "b", &crit );
144 if( tag == LBER_ERROR ) {
146 LDAP_LOG(( "operation", LDAP_LEVEL_INFO,
147 "get_ctrls: conn %d get crit failed.\n",
150 Debug( LDAP_DEBUG_TRACE, "=> get_ctrls: get crit failed.\n",
154 ldap_controls_free( tctrls );
155 rc = SLAPD_DISCONNECT;
156 errmsg = "decoding controls error";
160 tctrl->ldctl_iscritical = (crit != 0);
161 tag = ber_peek_tag( ber, &len );
165 LDAP_LOG(( "operation", LDAP_LEVEL_INFO,
166 "get_ctrls: conn %d oid=\"%s\" (%scritical)\n",
167 conn->c_connid, tctrl->ldctl_oid,
168 tctrl->ldctl_iscritical ? "" : "non" ));
170 Debug( LDAP_DEBUG_TRACE, "=> get_ctrls: oid=\"%s\" (%scritical)\n",
172 tctrl->ldctl_iscritical ? "" : "non",
175 if( tag == LBER_OCTETSTRING ) {
176 tag = ber_scanf( ber, "o", &tctrl->ldctl_value );
178 if( tag == LBER_ERROR ) {
180 LDAP_LOG(( "operation", LDAP_LEVEL_INFO,
181 "get_ctrls: conn %d get value failed.\n", conn->c_connid ));
183 Debug( LDAP_DEBUG_TRACE, "=> get_ctrls: get value failed.\n",
187 ldap_controls_free( tctrls );
188 rc = SLAPD_DISCONNECT;
189 errmsg = "decoding controls error";
194 if( tctrl->ldctl_iscritical &&
195 !charray_inlist( supportedControls, tctrl->ldctl_oid ) )
197 rc = LDAP_UNAVAILABLE_CRITICAL_EXTENSION;
198 errmsg = "critical extension is unavailable ";
207 LDAP_LOG(( "operation", LDAP_LEVEL_RESULTS,
208 "get_ctrls: conn %d %d %d %s\n",
209 conn->c_connid, nctrls, rc, errmsg ? errmsg : "" ));
211 Debug( LDAP_DEBUG_TRACE, "<= get_ctrls: %d %d %s\n",
212 nctrls, rc, errmsg ? errmsg : "");
214 if( sendres && rc != LDAP_SUCCESS ) {
215 if( rc == SLAPD_DISCONNECT ) {
216 send_ldap_disconnect( conn, op, rc, errmsg );
218 send_ldap_result( conn, op, rc,
219 NULL, errmsg, NULL, NULL );
227 int get_manageDSAit( Operation *op )
230 if( op == NULL || op->o_ctrls == NULL ) {
234 for( i=0; op->o_ctrls[i] != NULL; i++ ) {
235 if( strcmp( LDAP_CONTROL_MANAGEDSAIT, op->o_ctrls[i]->ldctl_oid )