ldbm_bind.c 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  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. /* bind.c - ldbm backend bind and unbind routines */
  13. #include "back-ldbm.h"
  14. int
  15. ldbm_back_bind( Slapi_PBlock *pb )
  16. {
  17. backend *be;
  18. ldbm_instance *inst;
  19. ber_tag_t method;
  20. struct berval *cred;
  21. struct ldbminfo *li;
  22. struct backentry *e;
  23. Slapi_Attr *attr;
  24. Slapi_Value **bvals;
  25. entry_address *addr;
  26. back_txn txn = {NULL};
  27. int rc = SLAPI_BIND_SUCCESS;
  28. int result_sent = 0;
  29. /* get parameters */
  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_BIND_METHOD, &method );
  34. slapi_pblock_get( pb, SLAPI_BIND_CREDENTIALS, &cred );
  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_ref_count) {
  42. slapi_counter_increment(inst->inst_ref_count);
  43. } else {
  44. slapi_log_err(SLAPI_LOG_ERR, "ldbm_back_bind",
  45. "instance %s does not exist.\n", inst->inst_name);
  46. return( SLAPI_BIND_FAIL );
  47. }
  48. /* always allow noauth simple binds (front end will send the result) */
  49. if ( method == LDAP_AUTH_SIMPLE && cred->bv_len == 0 ) {
  50. rc = SLAPI_BIND_ANONYMOUS;
  51. goto bail;
  52. }
  53. /*
  54. * find the target entry. find_entry() takes care of referrals
  55. * and sending errors if the entry does not exist.
  56. */
  57. if ((e = find_entry( pb, be, addr, &txn, &result_sent)) == NULL) {
  58. rc = SLAPI_BIND_FAIL;
  59. /* In the failure case, the result is supposed to be sent in the backend. */
  60. if (!result_sent) {
  61. slapi_send_ldap_result(pb, LDAP_INAPPROPRIATE_AUTH, NULL, NULL, 0, NULL);
  62. }
  63. goto bail;
  64. }
  65. switch ( method ) {
  66. case LDAP_AUTH_SIMPLE:
  67. {
  68. Slapi_Value cv;
  69. if ( slapi_entry_attr_find( e->ep_entry, "userpassword", &attr ) != 0 ) {
  70. slapi_send_ldap_result( pb, LDAP_INAPPROPRIATE_AUTH, NULL,
  71. NULL, 0, NULL );
  72. CACHE_RETURN( &inst->inst_cache, &e );
  73. rc = SLAPI_BIND_FAIL;
  74. goto bail;
  75. }
  76. bvals= attr_get_present_values(attr);
  77. slapi_value_init_berval(&cv,cred);
  78. if ( slapi_pw_find_sv( bvals, &cv ) != 0 ) {
  79. slapi_pblock_set(pb, SLAPI_PB_RESULT_TEXT, "Invalid credentials");
  80. slapi_send_ldap_result( pb, LDAP_INVALID_CREDENTIALS, NULL, NULL, 0, NULL );
  81. CACHE_RETURN( &inst->inst_cache, &e );
  82. value_done(&cv);
  83. rc = SLAPI_BIND_FAIL;
  84. goto bail;
  85. }
  86. value_done(&cv);
  87. }
  88. break;
  89. default:
  90. slapi_send_ldap_result( pb, LDAP_STRONG_AUTH_NOT_SUPPORTED, NULL,
  91. "auth method not supported", 0, NULL );
  92. CACHE_RETURN( &inst->inst_cache, &e );
  93. rc = SLAPI_BIND_FAIL;
  94. goto bail;
  95. }
  96. CACHE_RETURN( &inst->inst_cache, &e );
  97. bail:
  98. if (inst->inst_ref_count) {
  99. slapi_counter_decrement(inst->inst_ref_count);
  100. }
  101. /* success: front end will send result */
  102. return rc;
  103. }