mirror of
https://git.openldap.org/openldap/openldap.git
synced 2025-12-21 15:19:34 -05:00
Add server side sorting control
This commit is contained in:
parent
1dc90fba78
commit
689b51fe48
2 changed files with 75 additions and 0 deletions
|
|
@ -134,6 +134,7 @@ static int print_paged_results( LDAP *ld, LDAPControl *ctrl );
|
|||
#ifdef LDAP_CONTROL_PASSWORDPOLICYREQUEST
|
||||
static int print_ppolicy( LDAP *ld, LDAPControl *ctrl );
|
||||
#endif
|
||||
static int print_sss( LDAP *ld, LDAPControl *ctrl );
|
||||
|
||||
static struct tool_ctrls_t {
|
||||
const char *oid;
|
||||
|
|
@ -146,6 +147,7 @@ static struct tool_ctrls_t {
|
|||
#ifdef LDAP_CONTROL_PASSWORDPOLICYREQUEST
|
||||
{ LDAP_CONTROL_PASSWORDPOLICYRESPONSE, TOOL_ALL, print_ppolicy },
|
||||
#endif
|
||||
{ LDAP_CONTROL_SORTRESPONSE, TOOL_SEARCH, print_sss },
|
||||
{ NULL, 0, NULL }
|
||||
};
|
||||
|
||||
|
|
@ -1864,6 +1866,26 @@ print_paged_results( LDAP *ld, LDAPControl *ctrl )
|
|||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
print_sss( LDAP *ld, LDAPControl *ctrl )
|
||||
{
|
||||
int rc;
|
||||
ber_int_t err;
|
||||
char *attr;
|
||||
|
||||
rc = ldap_parse_sortresponse_control( ld, ctrl, &err, &attr );
|
||||
if ( rc == LDAP_SUCCESS ) {
|
||||
char buf[ BUFSIZ ];
|
||||
rc = snprintf( buf, sizeof(buf), "(%d) %s %s",
|
||||
err, ldap_err2string(err), attr ? attr : "" );
|
||||
|
||||
tool_write_ldif( ldif ? LDIF_PUT_COMMENT : LDIF_PUT_VALUE,
|
||||
"sortResult", buf, rc );
|
||||
}
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
#ifdef LDAP_CONTROL_PASSWORDPOLICYREQUEST
|
||||
static int
|
||||
print_ppolicy( LDAP *ld, LDAPControl *ctrl )
|
||||
|
|
|
|||
|
|
@ -128,6 +128,7 @@ usage( void )
|
|||
fprintf( stderr, _(" !dontUseCopy (Don't Use Copy)\n"));
|
||||
fprintf( stderr, _(" [!]mv=<filter> (matched values filter)\n"));
|
||||
fprintf( stderr, _(" [!]pr=<size>[/prompt|noprompt] (paged results/prompt)\n"));
|
||||
fprintf( stderr, _(" [!]sss=[-]<attr[:OID]>[/[-]<attr[:OID]>...] (server side sorting)\n"));
|
||||
fprintf( stderr, _(" [!]subentries[=true|false] (subentries)\n"));
|
||||
fprintf( stderr, _(" [!]sync=ro[/<cookie>] (LDAP Sync refreshOnly)\n"));
|
||||
fprintf( stderr, _(" rp[/<cookie>][/<slimit>] (LDAP Sync refreshAndPersist)\n"));
|
||||
|
|
@ -199,6 +200,9 @@ static int dontUseCopy = 0;
|
|||
|
||||
static int domainScope = 0;
|
||||
|
||||
static int sss = 0;
|
||||
static LDAPSortKey **sss_keys = NULL;
|
||||
|
||||
static int ldapsync = 0;
|
||||
static struct berval sync_cookie = { 0, NULL };
|
||||
static int sync_slimit = -1;
|
||||
|
|
@ -395,6 +399,31 @@ handle_private_option( int i )
|
|||
|
||||
domainScope = 1 + crit;
|
||||
|
||||
} else if ( strcasecmp( control, "sss" ) == 0 ) {
|
||||
char *keyp;
|
||||
if( sss ) {
|
||||
fprintf( stderr,
|
||||
_("server side sorting control previously specified\n"));
|
||||
exit( EXIT_FAILURE );
|
||||
}
|
||||
if( cvalue == NULL ) {
|
||||
fprintf( stderr,
|
||||
_("missing specification of sss control\n") );
|
||||
exit( EXIT_FAILURE );
|
||||
}
|
||||
keyp = cvalue;
|
||||
while (keyp = strchr(keyp, '/')) {
|
||||
*keyp++ = ' ';
|
||||
}
|
||||
if ( ldap_create_sort_keylist( &sss_keys, cvalue )) {
|
||||
fprintf( stderr,
|
||||
_("server side sorting control value \"%s\" invalid\n"),
|
||||
cvalue );
|
||||
exit( EXIT_FAILURE );
|
||||
}
|
||||
|
||||
sss = 1 + crit;
|
||||
|
||||
} else if ( strcasecmp( control, "subentries" ) == 0 ) {
|
||||
if( subentries ) {
|
||||
fprintf( stderr,
|
||||
|
|
@ -754,6 +783,7 @@ getNextPage:
|
|||
|| domainScope
|
||||
|| pagedResults
|
||||
|| ldapsync
|
||||
|| sss
|
||||
|| subentries
|
||||
|| valuesReturnFilter )
|
||||
{
|
||||
|
|
@ -886,6 +916,22 @@ getNextPage:
|
|||
c[i].ldctl_iscritical = pagedResults > 1;
|
||||
i++;
|
||||
}
|
||||
|
||||
if ( sss ) {
|
||||
if ( ctrl_add() ) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
if ( ldap_create_sort_control_value( ld,
|
||||
sss_keys, &c[i].ldctl_value ) )
|
||||
{
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
c[i].ldctl_oid = LDAP_CONTROL_SORTREQUEST;
|
||||
c[i].ldctl_iscritical = sss > 1;
|
||||
i++;
|
||||
}
|
||||
}
|
||||
|
||||
tool_server_controls( ld, c, i );
|
||||
|
|
@ -968,6 +1014,10 @@ getNextPage:
|
|||
(pagedResults > 1) ? _("critical ") : "",
|
||||
pageSize );
|
||||
}
|
||||
if ( sss ) {
|
||||
printf(_("\n# with server side sorting %scontrol"),
|
||||
sss > 1 ? _("critical ") : "" );
|
||||
}
|
||||
|
||||
printf( _("\n#\n\n") );
|
||||
|
||||
|
|
@ -1051,6 +1101,9 @@ getNextPage:
|
|||
if ( control != NULL ) {
|
||||
ber_memfree( control );
|
||||
}
|
||||
if ( sss_keys != NULL ) {
|
||||
ldap_free_sort_keylist( sss_keys );
|
||||
}
|
||||
|
||||
if ( c ) {
|
||||
for ( ; save_nctrls-- > 0; ) {
|
||||
|
|
|
|||
Loading…
Reference in a new issue