From af866c3b44ba37577671f2bffd482499f4b8bc00 Mon Sep 17 00:00:00 2001 From: Kurt Zeilenga Date: Fri, 1 Apr 2005 02:40:29 +0000 Subject: [PATCH] Added a conformant sortedResults support which is unable to sort anything. --- servers/slapd/controls.c | 37 +++++++++++++++++++++++++++++++++ servers/slapd/result.c | 44 +++++++++++++++++++++++++++++++++------- servers/slapd/slap.h | 10 +++++++-- 3 files changed, 82 insertions(+), 9 deletions(-) diff --git a/servers/slapd/controls.c b/servers/slapd/controls.c index 7b16044683..78199b1d2e 100644 --- a/servers/slapd/controls.c +++ b/servers/slapd/controls.c @@ -32,6 +32,9 @@ static SLAP_CTRL_PARSE_FN parseManageDSAit; static SLAP_CTRL_PARSE_FN parseModifyIncrement; static SLAP_CTRL_PARSE_FN parseNoOp; static SLAP_CTRL_PARSE_FN parsePagedResults; +#ifdef LDAP_DEVEL +static SLAP_CTRL_PARSE_FN parseSortedResults; +#endif static SLAP_CTRL_PARSE_FN parseValuesReturnFilter; static SLAP_CTRL_PARSE_FN parsePermissiveModify; static SLAP_CTRL_PARSE_FN parseDomainScope; @@ -112,6 +115,12 @@ static struct slap_control control_defs[] = { (int)offsetof(struct slap_control_ids, sc_pagedResults), SLAP_CTRL_SEARCH, NULL, parsePagedResults, LDAP_SLIST_ENTRY_INITIALIZER(next) }, +#ifdef LDAP_DEVEL + { LDAP_CONTROL_SORTREQUEST, + (int)offsetof(struct slap_control_ids, sc_sortedResults), + SLAP_CTRL_GLOBAL|SLAP_CTRL_SEARCH|SLAP_CTRL_HIDE, NULL, + parseSortedResults, LDAP_SLIST_ENTRY_INITIALIZER(next) }, +#endif #ifdef LDAP_CONTROL_X_DOMAIN_SCOPE { LDAP_CONTROL_X_DOMAIN_SCOPE, (int)offsetof(struct slap_control_ids, sc_domainScope), @@ -950,6 +959,34 @@ done:; return rc; } +#ifdef LDAP_DEVEL +static int parseSortedResults ( + Operation *op, + SlapReply *rs, + LDAPControl *ctrl ) +{ + int rc = LDAP_SUCCESS; + + if ( op->o_sortedresults != SLAP_CONTROL_NONE ) { + rs->sr_text = "sorted results control specified multiple times"; + return LDAP_PROTOCOL_ERROR; + } + + if ( BER_BVISEMPTY( &ctrl->ldctl_value ) ) { + rs->sr_text = "sorted results control value is empty (or absent)"; + return LDAP_PROTOCOL_ERROR; + } + + /* blow off parsing the value */ + + op->o_sortedresults = ctrl->ldctl_iscritical + ? SLAP_CONTROL_CRITICAL + : SLAP_CONTROL_NONCRITICAL; + + return rc; +} +#endif + static int parseAssert ( Operation *op, SlapReply *rs, diff --git a/servers/slapd/result.c b/servers/slapd/result.c index f1abb5110b..38bad417eb 100644 --- a/servers/slapd/result.c +++ b/servers/slapd/result.c @@ -254,7 +254,9 @@ send_ldap_controls( Operation *o, BerElement *ber, LDAPControl **c ) * plugin. */ - if ( o->o_pb && slapi_pblock_get( o->o_pb, SLAPI_RESCONTROLS, &sctrls ) != 0 ) { + if ( o->o_pb && + slapi_pblock_get( o->o_pb, SLAPI_RESCONTROLS, &sctrls ) != 0 ) + { sctrls = NULL; } @@ -269,10 +271,37 @@ send_ldap_controls( Operation *o, BerElement *ber, LDAPControl **c ) #ifdef LDAP_SLAPI if ( c != NULL ) #endif /* LDAP_SLAPI */ - for( ; *c != NULL; c++) { - rc = send_ldap_control( ber, *c ); + { + for( ; *c != NULL; c++) { + rc = send_ldap_control( ber, *c ); + if( rc == -1 ) return rc; + } + } + +#ifdef LDAP_DEVEL + /* this is a hack to avoid having to modify op->s_ctrls */ + if( o->o_sortedresults ) { + BerElementBuffer berbuf; + BerElement *sber = (BerElement *) &berbuf; + LDAPControl sorted; + BER_BVZERO( &sorted.ldctl_value ); + sorted.ldctl_oid = LDAP_CONTROL_SORTRESPONSE; + sorted.ldctl_iscritical = 0; + + ber_init2( sber, NULL, LBER_USE_DER ); + + ber_printf( sber, "{i}", LDAP_UNWILLING_TO_PERFORM ); + + if( ber_flatten2( ber, &sorted.ldctl_value, 0 ) == -1 ) { + return LBER_ERROR; + } + + (void) ber_free_buf( ber ); + + rc = send_ldap_control( ber, &sorted ); if( rc == -1 ) return rc; } +#endif #ifdef LDAP_SLAPI if ( sctrls != NULL ) { @@ -1405,8 +1434,7 @@ str2result( char *s, int *code, char **matched, - char **info -) + char **info ) { int rc; char *c; @@ -1567,8 +1595,10 @@ slap_attr_flags( AttributeName *an ) flags |= ( SLAP_OPATTRS_NO | SLAP_USERATTRS_YES ); } else { - flags |= an_find( an, &AllOper ) ? SLAP_OPATTRS_YES : SLAP_OPATTRS_NO; - flags |= an_find( an, &AllUser ) ? SLAP_USERATTRS_YES : SLAP_USERATTRS_NO; + flags |= an_find( an, &AllOper ) + ? SLAP_OPATTRS_YES : SLAP_OPATTRS_NO; + flags |= an_find( an, &AllUser ) + ? SLAP_USERATTRS_YES : SLAP_USERATTRS_NO; } return flags; diff --git a/servers/slapd/slap.h b/servers/slapd/slap.h index 2768a8face..29755901fe 100644 --- a/servers/slapd/slap.h +++ b/servers/slapd/slap.h @@ -2166,6 +2166,9 @@ struct slap_control_ids { int sc_modifyIncrement; int sc_noOp; int sc_pagedResults; +#ifdef LDAP_DEVEL + int sc_sortedResults; +#endif int sc_valuesReturnFilter; int sc_permissiveModify; int sc_domainScope; @@ -2370,10 +2373,13 @@ typedef struct slap_op { #define o_pagedresults o_ctrlflag[slap_cids.sc_pagedResults] #define o_pagedresults_state o_controls[slap_cids.sc_pagedResults] +#define get_pagedresults(op) ((int)(op)->o_pagedresults) -#define o_sync o_ctrlflag[slap_cids.sc_LDAPsync] +#ifdef LDAP_DEVEL +#define o_sortedresults o_ctrlflag[slap_cids.sc_sortedResults] +#endif -#define get_pagedresults(op) ((int)(op)->o_pagedresults) +#define o_sync o_ctrlflag[slap_cids.sc_LDAPsync] AuthorizationInformation o_authz; -- 2.39.5