#pragma ident "%Z%%M% %I% %E% SMI"
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
/* control.c - routines to handle ldapv3 controls */
#include "ldap-int.h"
LDAPControl *ctrl_src );
/*
* Append a list of LDAPv3 controls to ber. If ctrls is NULL, use default
* set of controls from ld.
* Return an LDAP error code (LDAP_SUCCESS if all goes well).
* If closeseq is non-zero, we do an extra ber_put_seq() as well.
*/
int
BerElement *ber )
{
LDAPControl *c;
int rc, i;
/* if no controls were passed in, use global list from LDAP * */
}
/* if there are no controls then we are done */
goto clean_exit;
}
/*
* If we're using LDAPv2 or earlier we can't send any controls, so
* we just ignore them unless one is marked critical, in which case
* we return an error.
*/
if ( ctrls[i]->ldctl_iscritical ) {
goto error_exit;
}
}
goto clean_exit;
}
/*
* encode the controls as a Sequence of Sequence
*/
goto error_exit;
}
c = ctrls[i];
goto error_exit;
}
/* criticality is "BOOLEAN DEFAULT FALSE" */
/* therefore, it should only be encoded if it exists AND is TRUE */
if ( c->ldctl_iscritical ) {
== -1 ) {
goto error_exit;
}
}
== -1 ) {
goto error_exit;
}
}
goto error_exit;
}
}
goto error_exit;
}
goto error_exit;
}
return( LDAP_SUCCESS );
return( rc );
}
/*
* Pull controls out of "ber" (if any present) and return them in "controlsp."
* Returns an LDAP error code.
*/
int
{
char *last;
/*
* Each LDAPMessage can have a set of controls appended
* to it. Controls are used to extend the functionality
* of an LDAP operation (e.g., add an attribute size limit
* to the search operation). These controls look like this:
*
* Controls ::= SEQUENCE OF Control
*
* Control ::= SEQUENCE {
* controlType LDAPOID,
* criticality BOOLEAN DEFAULT FALSE,
* controlValue OCTET STRING
* }
*/
/*
* check to see if controls were included
*/
return( LDAP_DECODING_ERROR ); /* unexpected error */
}
if ( len == 0 ) {
"<= nsldapi_get_controls no controls\n", 0, 0, 0 );
return( LDAP_SUCCESS ); /* no controls */
}
if ( tag == LBER_ERROR ) {
"<= nsldapi_get_controls LDAP_PROTOCOL_ERROR\n",
0, 0, 0 );
return( LDAP_DECODING_ERROR ); /* decoding error */
}
/*
* We found something other than controls. This should never
* happen in LDAPv3, but we don't treat this is a hard error --
* we just ignore the extra stuff.
*/
"<= nsldapi_get_controls ignoring unrecognized data in message (tag 0x%x)\n",
tag, 0, 0 );
return( LDAP_SUCCESS );
}
maxcontrols = curcontrols = 0;
(char *)*controlsp, maxcontrols *
sizeof(struct ldapcontrol *) );
rc = LDAP_NO_MEMORY;
goto free_and_return;
}
}
sizeof(LDAPControl))) == NULL ) {
rc = LDAP_NO_MEMORY;
goto free_and_return;
}
== LBER_ERROR ) {
goto free_and_return;
}
/* the criticality is optional */
int aint;
goto free_and_return;
}
} else {
/* absent is synonomous with FALSE */
newctrl->ldctl_iscritical = 0;
}
/* the control value is optional */
== LBER_ERROR ) {
goto free_and_return;
}
} else {
}
}
if ( tag == LBER_ERROR ) {
goto free_and_return;
}
"<= nsldapi_get_controls found %d controls\n", curcontrols, 0, 0 );
return( LDAP_SUCCESS );
"<= nsldapi_get_controls error 0x%x\n", rc, 0, 0 );
return( rc );
}
void
{
}
}
NSLDAPI_FREE( (char *)ctrl );
}
}
void
{
int i;
ldap_control_free( ctrls[i] );
}
NSLDAPI_FREE( (char *)ctrls );
}
}
#if 0
LDAPControl **
{
int nctrls = 0;
LDAPControl **ctrlp;
int i;
return ( NULL );
/* Count the existing controls */
nctrls++;
}
}
/* allocate the new control structure */
return( NULL );
}
for( i = 0; i < (nctrls + 1); i++ ) {
if ( i < nctrls ) {
} else {
}
return( NULL );
}
}
return ctrlp;
}
#endif /* 0 */
/*
* Replace *ldctrls with a copy of newctrls.
* returns 0 if successful.
* return -1 if not and set error code inside LDAP *ld.
*/
int
{
int count;
}
return( 0 );
}
;
}
sizeof( LDAPControl *))) == NULL ) {
return( -1 );
}
return( -1 );
}
}
return( 0 );
}
/*
* return a malloc'd copy of "ctrl" (NULL if memory allocation fails)
*/
static LDAPControl *
/* LDAP_CALL */ /* keep this routine internal for now */
{
== NULL ) {
return( NULL );
}
NSLDAPI_FREE( rctrl );
return( NULL );
}
return( rctrl );
}
/*
* duplicate the contents of "ctrl_src" and place in "ctrl_dst"
*/
static int
/* LDAP_CALL */ /* keep this routine internal for now */
{
return( LDAP_PARAM_ERROR );
}
/* fill in the fields of this new control */
== NULL ) {
return( LDAP_NO_MEMORY );
}
} else {
== NULL ) {
return( LDAP_NO_MEMORY );
}
}
return ( LDAP_SUCCESS );
}
/*
* build an allocated LDAPv3 control. Returns an LDAP error code.
*/
int
LDAPControl **ctrlp )
{
int rc;
} else {
/* allocate struct berval with contents of the BER encoding */
if ( freeber ) {
}
if ( rc == -1 ) {
return( LDAP_NO_MEMORY );
}
}
/* allocate the new control structure */
== NULL ) {
ber_bvfree( bvp );
}
return( LDAP_NO_MEMORY );
}
/* fill in the fields of this new control */
NSLDAPI_FREE( *ctrlp );
ber_bvfree( bvp );
}
return( LDAP_NO_MEMORY );
}
} else {
}
return( LDAP_SUCCESS );
}