apr_ldap_init.h 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. /* Licensed to the Apache Software Foundation (ASF) under one or more
  2. * contributor license agreements. See the NOTICE file distributed with
  3. * this work for additional information regarding copyright ownership.
  4. * The ASF licenses this file to You under the Apache License, Version 2.0
  5. * (the "License"); you may not use this file except in compliance with
  6. * the License. You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. /**
  17. * @file apr_ldap_init.h
  18. * @brief APR-UTIL LDAP ldap_init() functions
  19. */
  20. #ifndef APR_LDAP_INIT_H
  21. #define APR_LDAP_INIT_H
  22. /**
  23. * @addtogroup APR_Util_LDAP
  24. * @{
  25. */
  26. #include "apr_ldap.h"
  27. #if APR_HAS_LDAP
  28. #ifdef __cplusplus
  29. extern "C" {
  30. #endif /* __cplusplus */
  31. /**
  32. * Macro to detect security related return values.
  33. */
  34. #if defined(LDAP_INSUFFICIENT_ACCESS)
  35. #define APU_LDAP_INSUFFICIENT_ACCESS LDAP_INSUFFICIENT_ACCESS
  36. #elif defined(LDAP_INSUFFICIENT_RIGHTS)
  37. #define APU_LDAP_INSUFFICIENT_ACCESS LDAP_INSUFFICIENT_RIGHTS
  38. #elif defined(APR_HAS_MICROSOFT_LDAPSDK)
  39. /* The macros above fail to contemplate that LDAP_RETCODE values
  40. * may be represented by an enum. autoconf tests would be much
  41. * more robust.
  42. */
  43. #define APU_LDAP_INSUFFICIENT_ACCESS LDAP_INSUFFICIENT_RIGHTS
  44. #else
  45. #error The security return codes must be added to support this LDAP toolkit.
  46. #endif
  47. #if defined(LDAP_SECURITY_ERROR)
  48. #define APU_LDAP_SECURITY_ERROR LDAP_SECURITY_ERROR
  49. #else
  50. #define APU_LDAP_SECURITY_ERROR(n) \
  51. (LDAP_INAPPROPRIATE_AUTH == n) ? 1 \
  52. : (LDAP_INVALID_CREDENTIALS == n) ? 1 \
  53. : (APU_LDAP_INSUFFICIENT_ACCESS == n) ? 1 \
  54. : 0
  55. #endif
  56. /**
  57. * APR LDAP SSL Initialise function
  58. *
  59. * This function initialises SSL on the underlying LDAP toolkit
  60. * if this is necessary.
  61. *
  62. * If a CA certificate is provided, this is set, however the setting
  63. * of certificates via this method has been deprecated and will be removed in
  64. * APR v2.0.
  65. *
  66. * The apr_ldap_set_option() function with the APR_LDAP_OPT_TLS_CERT option
  67. * should be used instead to set certificates.
  68. *
  69. * If SSL support is not available on this platform, or a problem
  70. * was encountered while trying to set the certificate, the function
  71. * will return APR_EGENERAL. Further LDAP specific error information
  72. * can be found in result_err.
  73. * @param pool The pool to use
  74. * @param cert_auth_file The name of the certificate to use, can be NULL
  75. * @param cert_file_type The type of certificate specified. See the
  76. * apr_ldap_set_option() APR_LDAP_OPT_TLS_CERT option for details.
  77. * @param result_err The returned result
  78. */
  79. APU_DECLARE_LDAP(int) apr_ldap_ssl_init(apr_pool_t *pool,
  80. const char *cert_auth_file,
  81. int cert_file_type,
  82. apr_ldap_err_t **result_err);
  83. /**
  84. * APR LDAP SSL De-Initialise function
  85. *
  86. * This function tears down any SSL certificate setup previously
  87. * set using apr_ldap_ssl_init(). It should be called to clean
  88. * up if a graceful restart of a service is attempted.
  89. * @todo currently we do not check whether apr_ldap_ssl_init()
  90. * has been called first - we probably should.
  91. */
  92. APU_DECLARE_LDAP(int) apr_ldap_ssl_deinit(void);
  93. /**
  94. * APR LDAP initialise function
  95. *
  96. * This function is responsible for initialising an LDAP
  97. * connection in a toolkit independant way. It does the
  98. * job of ldap_init() from the C api.
  99. *
  100. * It handles both the SSL and non-SSL case, and attempts
  101. * to hide the complexity setup from the user. This function
  102. * assumes that any certificate setup necessary has already
  103. * been done.
  104. *
  105. * If SSL or STARTTLS needs to be enabled, and the underlying
  106. * toolkit supports it, the following values are accepted for
  107. * secure:
  108. *
  109. * APR_LDAP_NONE: No encryption
  110. * APR_LDAP_SSL: SSL encryption (ldaps://)
  111. * APR_LDAP_STARTTLS: Force STARTTLS on ldap://
  112. * @remark The Novell toolkit is only able to set the SSL mode via this
  113. * function. To work around this limitation, set the SSL mode here if no
  114. * per connection client certificates are present, otherwise set secure
  115. * APR_LDAP_NONE here, then set the per connection client certificates,
  116. * followed by setting the SSL mode via apr_ldap_set_option(). As Novell
  117. * does not support per connection client certificates, this problem is
  118. * worked around while still being compatible with other LDAP toolkits.
  119. * @param pool The pool to use
  120. * @param ldap The LDAP handle
  121. * @param hostname The name of the host to connect to. This can be either a
  122. * DNS name, or an IP address.
  123. * @param portno The port to connect to
  124. * @param secure The security mode to set
  125. * @param result_err The returned result
  126. */
  127. APU_DECLARE_LDAP(int) apr_ldap_init(apr_pool_t *pool,
  128. LDAP **ldap,
  129. const char *hostname,
  130. int portno,
  131. int secure,
  132. apr_ldap_err_t **result_err);
  133. /**
  134. * APR LDAP info function
  135. *
  136. * This function returns a string describing the LDAP toolkit
  137. * currently in use. The string is placed inside result_err->reason.
  138. * @param pool The pool to use
  139. * @param result_err The returned result
  140. */
  141. APU_DECLARE_LDAP(int) apr_ldap_info(apr_pool_t *pool,
  142. apr_ldap_err_t **result_err);
  143. #ifdef __cplusplus
  144. }
  145. #endif
  146. #endif /* APR_HAS_LDAP */
  147. /** @} */
  148. #endif /* APR_LDAP_URL_H */