ldbm_compare.c 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. /** BEGIN COPYRIGHT BLOCK
  2. * Copyright (C) 2001 Sun Microsystems, Inc. Used by permission.
  3. * Copyright (C) 2005 Red Hat, Inc.
  4. * All rights reserved.
  5. *
  6. * License: GPL (version 3 or any later version).
  7. * See LICENSE for details.
  8. * END COPYRIGHT BLOCK **/
  9. #ifdef HAVE_CONFIG_H
  10. # include <config.h>
  11. #endif
  12. /* compare.c - ldbm backend compare routine */
  13. #include "back-ldbm.h"
  14. int
  15. ldbm_back_compare( Slapi_PBlock *pb )
  16. {
  17. backend *be;
  18. ldbm_instance *inst;
  19. struct ldbminfo *li;
  20. struct backentry *e;
  21. int err;
  22. char *type;
  23. struct berval *bval;
  24. entry_address *addr;
  25. Slapi_Value compare_value;
  26. int result;
  27. int ret = 0;
  28. Slapi_DN *namespace_dn;
  29. back_txn txn = {NULL};
  30. slapi_pblock_get( pb, SLAPI_BACKEND, &be );
  31. slapi_pblock_get( pb, SLAPI_PLUGIN_PRIVATE, &li );
  32. slapi_pblock_get( pb, SLAPI_TARGET_ADDRESS, &addr);
  33. slapi_pblock_get( pb, SLAPI_COMPARE_TYPE, &type );
  34. slapi_pblock_get( pb, SLAPI_COMPARE_VALUE, &bval );
  35. slapi_pblock_get( pb, SLAPI_TXN, &txn.back_txn_txn );
  36. if ( !txn.back_txn_txn ) {
  37. dblayer_txn_init( li, &txn );
  38. slapi_pblock_set( pb, SLAPI_TXN, txn.back_txn_txn );
  39. }
  40. inst = (ldbm_instance *) be->be_instance_info;
  41. if (inst && inst->inst_ref_count) {
  42. slapi_counter_increment(inst->inst_ref_count);
  43. } else {
  44. slapi_log_err(SLAPI_LOG_ERR, "ldbm_back_compare",
  45. "Instance \"%s\" does not exist.\n",
  46. inst ? inst->inst_name : "null instance");
  47. return -1;
  48. }
  49. /* get the namespace dn */
  50. namespace_dn = (Slapi_DN*)slapi_be_getsuffix(be, 0);
  51. if ((e = find_entry(pb, be, addr, &txn, NULL)) == NULL) {
  52. ret = -1; /* error result sent by find_entry() */
  53. goto bail;
  54. }
  55. err = slapi_access_allowed (pb, e->ep_entry, type, bval, SLAPI_ACL_COMPARE);
  56. if ( err != LDAP_SUCCESS ) {
  57. slapi_send_ldap_result( pb, err, NULL, NULL, 0, NULL );
  58. ret = 1;
  59. } else {
  60. slapi_value_init_berval(&compare_value,bval);
  61. err = slapi_vattr_namespace_value_compare(e->ep_entry,namespace_dn,type,&compare_value,&result,0);
  62. if (0 != err) {
  63. /* Was the attribute not found ? */
  64. if (SLAPI_VIRTUALATTRS_NOT_FOUND == err) {
  65. slapi_send_ldap_result( pb, LDAP_NO_SUCH_ATTRIBUTE, NULL, NULL,0, NULL );
  66. ret = 1;
  67. } else {
  68. /* Some other problem, call it an operations error */
  69. slapi_send_ldap_result( pb, LDAP_OPERATIONS_ERROR, NULL, NULL,0, NULL );
  70. ret = -1;
  71. }
  72. } else {
  73. /* Interpret the result */
  74. if (result) {
  75. /* Compare true */
  76. slapi_send_ldap_result( pb, LDAP_COMPARE_TRUE, NULL, NULL, 0, NULL );
  77. } else {
  78. /* Compare false */
  79. slapi_send_ldap_result( pb, LDAP_COMPARE_FALSE, NULL, NULL, 0, NULL );
  80. }
  81. ret = 0;
  82. }
  83. value_done(&compare_value);
  84. }
  85. CACHE_RETURN( &inst->inst_cache, &e );
  86. bail:
  87. if (inst->inst_ref_count) {
  88. slapi_counter_decrement(inst->inst_ref_count);
  89. }
  90. return( ret );
  91. }