turn.c 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. /* $OpenLDAP$ */
  2. /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
  3. *
  4. * Copyright 2005-2022 The OpenLDAP Foundation.
  5. * All rights reserved.
  6. *
  7. * Redistribution and use in source and binary forms, with or without
  8. * modification, are permitted only as authorized by the OpenLDAP
  9. * Public License.
  10. *
  11. * A copy of this license is available in the file LICENSE in the
  12. * top-level directory of the distribution or, alternatively, at
  13. * <http://www.OpenLDAP.org/license.html>.
  14. */
  15. /* ACKNOWLEDGEMENTS:
  16. * This program was originally developed by Kurt D. Zeilenga for inclusion in
  17. * OpenLDAP Software.
  18. */
  19. /*
  20. * LDAPv3 Turn Operation Request
  21. */
  22. #include "portable.h"
  23. #include <stdio.h>
  24. #include <ac/stdlib.h>
  25. #include <ac/socket.h>
  26. #include <ac/string.h>
  27. #include <ac/time.h>
  28. #include "ldap-int.h"
  29. #include "ldap_log.h"
  30. int
  31. ldap_turn(
  32. LDAP *ld,
  33. int mutual,
  34. LDAP_CONST char* identifier,
  35. LDAPControl **sctrls,
  36. LDAPControl **cctrls,
  37. int *msgidp )
  38. {
  39. #ifdef LDAP_EXOP_X_TURN
  40. BerElement *turnvalber = NULL;
  41. struct berval turnval;
  42. int rc;
  43. turnvalber = ber_alloc_t( LBER_USE_DER );
  44. if( mutual ) {
  45. ber_printf( turnvalber, "{bs}", mutual, identifier );
  46. } else {
  47. ber_printf( turnvalber, "{s}", identifier );
  48. }
  49. ber_flatten2( turnvalber, &turnval, 0 );
  50. rc = ldap_extended_operation( ld, LDAP_EXOP_X_TURN,
  51. &turnval, sctrls, cctrls, msgidp );
  52. ber_free( turnvalber, 1 );
  53. return rc;
  54. #else
  55. return LDAP_CONTROL_NOT_FOUND;
  56. #endif
  57. }
  58. int
  59. ldap_turn_s(
  60. LDAP *ld,
  61. int mutual,
  62. LDAP_CONST char* identifier,
  63. LDAPControl **sctrls,
  64. LDAPControl **cctrls )
  65. {
  66. #ifdef LDAP_EXOP_X_TURN
  67. BerElement *turnvalber = NULL;
  68. struct berval turnval;
  69. int rc;
  70. turnvalber = ber_alloc_t( LBER_USE_DER );
  71. if( mutual ) {
  72. ber_printf( turnvalber, "{bs}", 0xFF, identifier );
  73. } else {
  74. ber_printf( turnvalber, "{s}", identifier );
  75. }
  76. ber_flatten2( turnvalber, &turnval, 0 );
  77. rc = ldap_extended_operation_s( ld, LDAP_EXOP_X_TURN,
  78. &turnval, sctrls, cctrls, NULL, NULL );
  79. ber_free( turnvalber, 1 );
  80. return rc;
  81. #else
  82. return LDAP_CONTROL_NOT_FOUND;
  83. #endif
  84. }