unbind.c 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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. /* unbind.c - decode an ldap unbind operation and pass it to a backend db */
  13. /*
  14. * Copyright (c) 1995 Regents of the University of Michigan.
  15. * All rights reserved.
  16. *
  17. * Redistribution and use in source and binary forms are permitted
  18. * provided that this notice is preserved and that due credit is given
  19. * to the University of Michigan at Ann Arbor. The name of the University
  20. * may not be used to endorse or promote products derived from this
  21. * software without specific prior written permission. This software
  22. * is provided ``as is'' without express or implied warranty.
  23. *
  24. */
  25. #include <stdio.h>
  26. #include <sys/types.h>
  27. #include <sys/socket.h>
  28. #include "slap.h"
  29. void
  30. do_unbind( Slapi_PBlock *pb )
  31. {
  32. Slapi_Operation *operation;
  33. BerElement *ber;
  34. int err;
  35. int ignore_criticality = 1;
  36. LDAPDebug( LDAP_DEBUG_TRACE, "do_unbind\n", 0, 0, 0 );
  37. slapi_pblock_get( pb, SLAPI_OPERATION, &operation);
  38. ber = operation->o_ber;
  39. /*
  40. * Parse the unbind request. It looks like this:
  41. *
  42. * UnBindRequest ::= NULL
  43. */
  44. if ( ber_get_null( ber ) == LBER_ERROR ) {
  45. slapi_log_access( LDAP_DEBUG_STATS, "conn=%" NSPRIu64 " op=%d UNBIND,"
  46. " decoding error: UnBindRequest not null\n",
  47. pb->pb_conn->c_connid, operation->o_opid );
  48. /* LDAPv3 does not allow a response to an unbind... so just return. */
  49. goto free_and_return;
  50. }
  51. /*
  52. * in LDAPv3 there can be optional control extensions on
  53. * the end of an LDAPMessage. we need to read them in and
  54. * pass them to the backend.
  55. * RFC 4511 section 4.1.11. Controls says that the UnbindRequest
  56. * MUST ignore the criticality field of controls
  57. */
  58. if ( (err = get_ldapmessage_controls_ext( pb, ber, NULL, ignore_criticality )) != 0 ) {
  59. slapi_log_access( LDAP_DEBUG_STATS, "conn=%" NSPRIu64 " op=%d UNBIND,"
  60. " error processing controls - error %d (%s)\n",
  61. pb->pb_conn->c_connid, operation->o_opid,
  62. err, ldap_err2string( err ));
  63. /* LDAPv3 does not allow a response to an unbind... so just return. */
  64. goto free_and_return;
  65. }
  66. /* target spec is used to decide which plugins are applicable for the operation */
  67. PR_EnterMonitor(pb->pb_conn->c_mutex);
  68. operation_set_target_spec_str (operation, pb->pb_conn->c_dn);
  69. PR_ExitMonitor(pb->pb_conn->c_mutex);
  70. /* ONREPL - plugins should be called and passed bind dn and, possibly, other data */
  71. slapi_log_access( LDAP_DEBUG_STATS, "conn=%" NSPRIu64 " op=%d UNBIND\n",
  72. pb->pb_conn->c_connid, operation->o_opid );
  73. /* pass the unbind to all backends */
  74. be_unbindall( pb->pb_conn, operation );
  75. /* close the connection to the client */
  76. disconnect_server( pb->pb_conn, operation->o_connid, operation->o_opid, SLAPD_DISCONNECT_UNBIND, 0);
  77. free_and_return:;
  78. }