sort.c 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. /** BEGIN COPYRIGHT BLOCK
  2. * This Program is free software; you can redistribute it and/or modify it under
  3. * the terms of the GNU General Public License as published by the Free Software
  4. * Foundation; version 2 of the License.
  5. *
  6. * This Program is distributed in the hope that it will be useful, but WITHOUT
  7. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  8. * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
  9. *
  10. * You should have received a copy of the GNU General Public License along with
  11. * this Program; if not, write to the Free Software Foundation, Inc., 59 Temple
  12. * Place, Suite 330, Boston, MA 02111-1307 USA.
  13. *
  14. * In addition, as a special exception, Red Hat, Inc. gives You the additional
  15. * right to link the code of this Program with code not covered under the GNU
  16. * General Public License ("Non-GPL Code") and to distribute linked combinations
  17. * including the two, subject to the limitations in this paragraph. Non-GPL Code
  18. * permitted under this exception must only link to the code of this Program
  19. * through those well defined interfaces identified in the file named EXCEPTION
  20. * found in the source code files (the "Approved Interfaces"). The files of
  21. * Non-GPL Code may instantiate templates or use macros or inline functions from
  22. * the Approved Interfaces without causing the resulting work to be covered by
  23. * the GNU General Public License. Only Red Hat, Inc. may make changes or
  24. * additions to the list of Approved Interfaces. You must obey the GNU General
  25. * Public License in all respects for all of the Program code and other code used
  26. * in conjunction with the Program except the Non-GPL Code covered by this
  27. * exception. If you modify this file, you may extend this exception to your
  28. * version of the file, but you are not obligated to do so. If you do not wish to
  29. * provide this exception without modification, you must delete this exception
  30. * statement from your version and license this file solely under the GPL without
  31. * exception.
  32. *
  33. *
  34. * Copyright (C) 2009 Red Hat, Inc.
  35. * All rights reserved.
  36. * END COPYRIGHT BLOCK **/
  37. #ifdef HAVE_CONFIG_H
  38. # include <config.h>
  39. #endif
  40. #include "slap.h"
  41. /* Fix for bug # 394184, SD, 20 Jul 00 */
  42. /* fix and cleanup (switch(code) {} removed) */
  43. /* arg 'code' has now the correct sortResult value */
  44. int
  45. sort_make_sort_response_control ( Slapi_PBlock *pb, int code, char *error_type)
  46. {
  47. LDAPControl new_ctrl = {0};
  48. BerElement *ber= NULL;
  49. struct berval *bvp = NULL;
  50. int rc = -1;
  51. ber_int_t control_code;
  52. if (code == CONN_GET_SORT_RESULT_CODE) {
  53. code = pagedresults_get_sort_result_code(pb->pb_conn);
  54. } else {
  55. Slapi_Operation *operation;
  56. slapi_pblock_get (pb, SLAPI_OPERATION, &operation);
  57. if (operation->o_flags & OP_FLAG_PAGED_RESULTS) {
  58. pagedresults_set_sort_result_code(pb->pb_conn, code);
  59. }
  60. }
  61. control_code = code;
  62. /*
  63. SortResult ::= SEQUENCE {
  64. sortResult ENUMERATED {
  65. success (0), -- results are sorted
  66. operationsError (1), -- server internal failure
  67. timeLimitExceeded (3), -- timelimit reached before
  68. -- sorting was completed
  69. strongAuthRequired (8), -- refused to return sorted
  70. -- results via insecure
  71. -- protocol
  72. adminLimitExceeded (11), -- too many matching entries
  73. -- for the server to sort
  74. noSuchAttribute (16), -- unrecognized attribute
  75. -- type in sort key
  76. inappropriateMatching (18), -- unrecognized or inappro-
  77. -- priate matching rule in
  78. -- sort key
  79. insufficientAccessRights (50), -- refused to return sorted
  80. -- results to this client
  81. busy (51), -- too busy to process
  82. unwillingToPerform (53), -- unable to sort
  83. other (80)
  84. },
  85. attributeType [0] AttributeType OPTIONAL
  86. }
  87. */
  88. if ( ( ber = ber_alloc()) == NULL ) {
  89. return -1;
  90. }
  91. if (( rc = ber_printf( ber, "{e", control_code )) != -1 ) {
  92. if ( rc != -1 && NULL != error_type ) {
  93. rc = ber_printf( ber, "s", error_type );
  94. }
  95. if ( rc != -1 ) {
  96. rc = ber_printf( ber, "}" );
  97. }
  98. }
  99. if ( rc != -1 ) {
  100. rc = ber_flatten( ber, &bvp );
  101. }
  102. ber_free( ber, 1 );
  103. if ( rc == -1 ) {
  104. return rc;
  105. }
  106. new_ctrl.ldctl_oid = LDAP_CONTROL_SORTRESPONSE;
  107. new_ctrl.ldctl_value = *bvp;
  108. new_ctrl.ldctl_iscritical = 1;
  109. if ( slapi_pblock_set( pb, SLAPI_ADD_RESCONTROL, &new_ctrl ) != 0 ) {
  110. ber_bvfree(bvp);
  111. return( -1 );
  112. }
  113. ber_bvfree(bvp);
  114. return( LDAP_SUCCESS );
  115. }
  116. /* End fix for bug #394184 */