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[] = {
32 BerElement *ber = op->o_ber;
33 LDAPControl ***ctrls = &op->o_ctrls;
34 int rc = LDAP_SUCCESS;
36 len = ber_pvt_ber_remaining(ber);
44 if(( tag = ber_peek_tag( ber, &len )) != LDAP_TAG_CONTROLS ) {
45 if( tag == LBER_ERROR ) {
46 rc = LDAP_PROTOCOL_ERROR;
52 if( op->o_protocol < LDAP_VERSION3 ) {
53 rc = LDAP_PROTOCOL_ERROR;
57 /* set through each element */
59 *ctrls = ch_malloc( 1 * sizeof(LDAPControl *) );
62 if( *ctrls == NULL ) {
70 for( tag = ber_first_element( ber, &len, &opaque );
72 tag = ber_next_element( ber, &len, opaque ) )
77 tctrl = ch_calloc( 1, sizeof(LDAPControl) );
79 /* allocate pointer space for current controls (nctrls)
80 * + this control + extra NULL
82 tctrls = (tctrl == NULL) ? NULL :
83 ch_realloc(*ctrls, (nctrls+2) * sizeof(LDAPControl *));
86 if( tctrls == NULL ) {
87 /* one of the above allocation failed */
93 ldap_controls_free(*ctrls);
102 tctrls[nctrls++] = tctrl;
103 tctrls[nctrls] = NULL;
105 tag = ber_scanf( ber, "{a" /*}*/, &tctrl->ldctl_oid );
107 if( tag != LBER_ERROR ) {
108 tag = ber_peek_tag( ber, &len );
111 if( tag == LBER_BOOLEAN ) {
113 tag = ber_scanf( ber, "b", &crit );
114 tctrl->ldctl_iscritical = crit ? (char) 0 : (char) ~0;
117 if( tag != LBER_ERROR ) {
118 tag = ber_peek_tag( ber, &len );
121 if( tag == LBER_OCTETSTRING ) {
122 tag = ber_scanf( ber, "o", &tctrl->ldctl_value );
125 tctrl->ldctl_value.bv_val = NULL;
128 if( tag == LBER_ERROR ) {
130 ldap_controls_free( tctrls );
131 rc = LDAP_DECODING_ERROR;
135 if( tctrl->ldctl_iscritical &&
136 !charray_inlist( supportedControls, tctrl->ldctl_oid ) )
138 rc = LDAP_UNAVAILABLE_CRITICIAL_EXTENSION;
146 if( sendres && rc != LDAP_SUCCESS ) {
147 send_ldap_result( conn, op, rc, NULL, NULL );