sort.c 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. /** BEGIN COPYRIGHT BLOCK
  2. * Copyright (C) 2009 Red Hat, Inc.
  3. * All rights reserved.
  4. *
  5. * License: GPL (version 3 or any later version).
  6. * See LICENSE for details.
  7. * END COPYRIGHT BLOCK **/
  8. #ifdef HAVE_CONFIG_H
  9. # include <config.h>
  10. #endif
  11. #include "slap.h"
  12. /* Fix for bug # 394184, SD, 20 Jul 00 */
  13. /* fix and cleanup (switch(code) {} removed) */
  14. /* arg 'code' has now the correct sortResult value */
  15. int
  16. sort_make_sort_response_control ( Slapi_PBlock *pb, int code, char *error_type)
  17. {
  18. LDAPControl new_ctrl = {0};
  19. BerElement *ber= NULL;
  20. struct berval *bvp = NULL;
  21. int rc = -1;
  22. ber_int_t control_code;
  23. int pr_idx = -1;
  24. slapi_pblock_get(pb, SLAPI_PAGED_RESULTS_INDEX, &pr_idx);
  25. if (code == CONN_GET_SORT_RESULT_CODE) {
  26. code = pagedresults_get_sort_result_code(pb->pb_conn,
  27. pb->pb_op, pr_idx);
  28. } else {
  29. Slapi_Operation *operation;
  30. slapi_pblock_get (pb, SLAPI_OPERATION, &operation);
  31. if (op_is_pagedresults(operation)) {
  32. pagedresults_set_sort_result_code(pb->pb_conn,
  33. pb->pb_op, code, pr_idx);
  34. }
  35. }
  36. control_code = code;
  37. /*
  38. SortResult ::= SEQUENCE {
  39. sortResult ENUMERATED {
  40. success (0), -- results are sorted
  41. operationsError (1), -- server internal failure
  42. timeLimitExceeded (3), -- timelimit reached before
  43. -- sorting was completed
  44. strongAuthRequired (8), -- refused to return sorted
  45. -- results via insecure
  46. -- protocol
  47. adminLimitExceeded (11), -- too many matching entries
  48. -- for the server to sort
  49. noSuchAttribute (16), -- unrecognized attribute
  50. -- type in sort key
  51. inappropriateMatching (18), -- unrecognized or inappro-
  52. -- priate matching rule in
  53. -- sort key
  54. insufficientAccessRights (50), -- refused to return sorted
  55. -- results to this client
  56. busy (51), -- too busy to process
  57. unwillingToPerform (53), -- unable to sort
  58. other (80)
  59. },
  60. attributeType [0] AttributeType OPTIONAL
  61. }
  62. */
  63. if ( ( ber = ber_alloc()) == NULL ) {
  64. return -1;
  65. }
  66. if (( rc = ber_printf( ber, "{e", control_code )) != -1 ) {
  67. if ( rc != -1 && NULL != error_type ) {
  68. rc = ber_printf( ber, "s", error_type );
  69. }
  70. if ( rc != -1 ) {
  71. rc = ber_printf( ber, "}" );
  72. }
  73. }
  74. if ( rc != -1 ) {
  75. rc = ber_flatten( ber, &bvp );
  76. }
  77. ber_free( ber, 1 );
  78. if ( rc == -1 ) {
  79. return rc;
  80. }
  81. new_ctrl.ldctl_oid = LDAP_CONTROL_SORTRESPONSE;
  82. new_ctrl.ldctl_value = *bvp;
  83. new_ctrl.ldctl_iscritical = 1;
  84. if ( slapi_pblock_set( pb, SLAPI_ADD_RESCONTROL, &new_ctrl ) != 0 ) {
  85. ber_bvfree(bvp);
  86. return( -1 );
  87. }
  88. ber_bvfree(bvp);
  89. return( LDAP_SUCCESS );
  90. }
  91. /* End fix for bug #394184 */