From c8f62b12d3539afa6036e330e209c84ae34a31f9 Mon Sep 17 00:00:00 2001 From: Luke Howard Date: Tue, 16 Dec 2003 11:17:54 +0000 Subject: [PATCH] Honour any controls that are sent by a SLAPI plugin --- servers/slapd/result.c | 78 ++++++++++++++++++++++++++++++++---------- 1 file changed, 59 insertions(+), 19 deletions(-) diff --git a/servers/slapd/result.c b/servers/slapd/result.c index b134b9918d..ad379390e5 100644 --- a/servers/slapd/result.c +++ b/servers/slapd/result.c @@ -211,31 +211,71 @@ static long send_ldap_ber( } static int -send_ldap_controls( BerElement *ber, LDAPControl **c ) +send_ldap_control( BerElement *ber, LDAPControl *c ) { int rc; + + assert( c != NULL ); + + rc = ber_printf( ber, "{s" /*}*/, c->ldctl_oid ); + + if( c->ldctl_iscritical ) { + rc = ber_printf( ber, "b", + (ber_int_t) c->ldctl_iscritical ) ; + if( rc == -1 ) return rc; + } + + if( c->ldctl_value.bv_val != NULL ) { + rc = ber_printf( ber, "O", &c->ldctl_value ); + if( rc == -1 ) return rc; + } + + rc = ber_printf( ber, /*{*/"N}" ); + if( rc == -1 ) return rc; + + return 0; +} + +static int +send_ldap_controls( Operation *o, BerElement *ber, LDAPControl **c ) +{ + int rc; +#ifdef LDAP_SLAPI + LDAPControl **sctrls = NULL; + + /* + * Retrieve any additional controls that may be set by the + * plugin. + */ + + if ( slapi_pblock_get( o->o_pb, SLAPI_RESCONTROLS, &sctrls ) != 0 ) { + sctrls = NULL; + } + + if ( c == NULL && sctrls == NULL ) return 0; +#else if( c == NULL ) return 0; +#endif /* LDAP_SLAPI */ rc = ber_printf( ber, "t{"/*}*/, LDAP_TAG_CONTROLS ); if( rc == -1 ) return rc; +#ifdef LDAP_SLAPI + if ( c != NULL ) +#endif /* LDAP_SLAPI */ for( ; *c != NULL; c++) { - rc = ber_printf( ber, "{s" /*}*/, (*c)->ldctl_oid ); - - if( (*c)->ldctl_iscritical ) { - rc = ber_printf( ber, "b", - (ber_int_t) (*c)->ldctl_iscritical ) ; - if( rc == -1 ) return rc; - } + rc = send_ldap_control( ber, *c ); + if( rc == -1 ) return rc; + } - if( (*c)->ldctl_value.bv_val != NULL ) { - rc = ber_printf( ber, "O", &((*c)->ldctl_value)); +#ifdef LDAP_SLAPI + if ( sctrls != NULL ) { + for ( c = sctrls; *c != NULL; c++ ) { + rc = send_ldap_control( ber, *c ); if( rc == -1 ) return rc; } - - rc = ber_printf( ber, /*{*/"N}" ); - if( rc == -1 ) return rc; } +#endif /* LDAP_SLAPI */ rc = ber_printf( ber, /*{*/"N}" ); @@ -351,8 +391,8 @@ send_ldap_response( rc = ber_printf( ber, /*"{"*/ "N}" ); } - if( rc != -1 && rs->sr_ctrls != NULL ) { - rc = send_ldap_controls( ber, rs->sr_ctrls ); + if( rc != -1 ) { + rc = send_ldap_controls( op, ber, rs->sr_ctrls ); } if( rc != -1 ) { @@ -1172,8 +1212,8 @@ slap_send_search_entry( Operation *op, SlapReply *rs ) attrs_free( aa ); rc = ber_printf( ber, /*{{*/ "}N}" ); - if( rc != -1 && rs->sr_ctrls != NULL ) { - rc = send_ldap_controls( ber, rs->sr_ctrls ); + if( rc != -1 ) { + rc = send_ldap_controls( op, ber, rs->sr_ctrls ); } if( rc != -1 ) { @@ -1396,8 +1436,8 @@ slap_send_search_reference( Operation *op, SlapReply *rs ) rc = ber_printf( ber, "{it{W}" /*"}"*/ , op->o_msgid, LDAP_RES_SEARCH_REFERENCE, rs->sr_ref ); - if( rc != -1 && rs->sr_ctrls != NULL ) { - rc = send_ldap_controls( ber, rs->sr_ctrls ); + if( rc != -1 ) { + rc = send_ldap_controls( op, ber, rs->sr_ctrls ); } if( rc != -1 ) { -- 2.39.5