/vmidentity/interop/idm/ad/defines.h

https://github.com/vmware/lightwave · C Header · 154 lines · 107 code · 19 blank · 28 comment · 34 complexity · 560290997c00a3de5a7506fdae420cc9 MD5 · raw file

  1. /*
  2. * Copyright © 2012-2015 VMware, Inc. All Rights Reserved.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the “License”); you may not
  5. * use this file except in compliance with the License. You may obtain a copy
  6. * of the License at http://www.apache.org/licenses/LICENSE-2.0
  7. *
  8. * Unless required by applicable law or agreed to in writing, software
  9. * distributed under the License is distributed on an “AS IS” BASIS, without
  10. * warranties or conditions of any kind, EITHER EXPRESS OR IMPLIED. See the
  11. * License for the specific language governing permissions and limitations
  12. * under the License.
  13. */
  14. /*
  15. * Module Name:
  16. *
  17. * defines.h
  18. *
  19. * Abstract:
  20. *
  21. * Identity Manager - Active Directory Integration
  22. *
  23. * Definitions
  24. *
  25. * Authors: Sriram Nambakam (snambakam@vmware.com)
  26. * Adam Bernstein (abernstein@vmware.com)
  27. *
  28. */
  29. #ifndef _WIN32
  30. typedef SIZE_T size_t;
  31. #ifndef IDM_ERROR_USER_INVALID_CREDENTIAL
  32. #define IDM_ERROR_USER_INVALID_CREDENTIAL 9234
  33. #endif
  34. #else
  35. #define pthread_mutex_lock(pCriticalSection) EnterCriticalSection(pCriticalSection)
  36. #define pthread_mutex_unlock(pCriticalSection) LeaveCriticalSection(pCriticalSection)
  37. #define pthread_mutex_init(mutex, defaults) InitializeCriticalSection((mutex))
  38. #define pthread_mutex_destroy(mutex) DeleteCriticalSection((mutex))
  39. #endif
  40. #define BAIL_ON_ERROR(dwError) \
  41. if (dwError) goto error;
  42. #define BAIL_ON_SECURITY_ERROR(secError, dwError) \
  43. do { \
  44. if ((secError) < 0) \
  45. { \
  46. dwError = (DWORD) (secError); \
  47. goto error; \
  48. } \
  49. } while (0)
  50. #define BAIL_ON_GSSAPI_ERROR(err, maj, min) \
  51. do { \
  52. if (err) { maj = GSS_S_FAILURE; min = err; goto error; } \
  53. } while (0)
  54. #ifndef _WIN32
  55. #define BAIL_ON_KERBEROS_ERROR(pCtx, krbErr, dwError) \
  56. do { \
  57. if (krbErr) { \
  58. (dwError) = LwTranslateKrb5Error( \
  59. pCtx, \
  60. krbErr, \
  61. __FUNCTION__, \
  62. __FILE__, \
  63. __LINE__); \
  64. goto error; \
  65. } \
  66. } while (0)
  67. #define IDM_RWMUTEX_LOCK_SHARED(mutex, locked, dwError) \
  68. do { \
  69. if ((mutex) && !(locked)) { \
  70. DWORD dwErrorLock = pthread_rwlock_rdlock(mutex); \
  71. if (dwErrorLock) { \
  72. (dwError) = LwErrnoToWin32Error(dwErrorLock); \
  73. } else { \
  74. (locked) = TRUE; \
  75. (dwError) = 0; \
  76. } \
  77. } \
  78. } while(0)
  79. #define IDM_RWMUTEX_LOCK_EXCLUSIVE(mutex, locked, dwError) \
  80. do { \
  81. if ((mutex) && !(locked)) { \
  82. DWORD dwErrorLock = pthread_rwlock_wrlock(mutex); \
  83. if (dwErrorLock) { \
  84. (dwError) = LwErrnoToWin32Error(dwErrorLock); \
  85. } else { \
  86. (locked) = TRUE; \
  87. (dwError) = 0; \
  88. } \
  89. } \
  90. } while(0)
  91. #define IDM_RWMUTEX_UNLOCK(mutex, locked, dwError) \
  92. do { \
  93. if ((mutex) && locked) { \
  94. DWORD dwErrorLock = pthread_rwlock_unlock(mutex); \
  95. if (dwErrorLock) { \
  96. (dwError) = LwErrnoToWin32Error(dwErrorLock); \
  97. } else { \
  98. (locked) = FALSE; \
  99. (dwError) = 0; \
  100. } \
  101. } \
  102. } while(0)
  103. #define IDM_MUTEX_LOCK(mutex, locked, dwError) \
  104. do { \
  105. if ((mutex) && !(locked)) { \
  106. DWORD dwErrorLock = pthread_mutex_lock(mutex); \
  107. if (dwErrorLock) { \
  108. (dwError) = LwErrnoToWin32Error(dwErrorLock); \
  109. } else { \
  110. (locked) = TRUE; \
  111. (dwError) = 0; \
  112. } \
  113. } \
  114. } while(0)
  115. #define IDM_MUTEX_UNLOCK(mutex, locked, dwError) \
  116. do { \
  117. if ((mutex) && locked) { \
  118. DWORD dwErrorLock = pthread_mutex_unlock(mutex); \
  119. if (dwErrorLock) { \
  120. (dwError) = LwErrnoToWin32Error(dwErrorLock); \
  121. } else { \
  122. (locked) = FALSE; \
  123. (dwError) = 0; \
  124. } \
  125. } \
  126. } while(0)
  127. #endif /* !_WIN32 */
  128. #define SEC_SUCCESS(Status) ((Status) >= 0)
  129. #define IDM_SAFE_FREE_MEMORY(PTR) \
  130. do { \
  131. if ((PTR)) { \
  132. IDMFreeMemory(PTR); \
  133. (PTR) = NULL; \
  134. } \
  135. } while(0)