/lsass/server/auth-providers/ad-open-provider/lsasqlite.h

https://github.com/BeyondTrust/pbis-open · C Header · 207 lines · 136 code · 27 blank · 44 comment · 6 complexity · ce52dba036112d122c304d3536bf723d MD5 · raw file

  1. /* Editor Settings: expandtabs and use 4 spaces for indentation
  2. * ex: set softtabstop=4 tabstop=8 expandtab shiftwidth=4: *
  3. * -*- mode: c, c-basic-offset: 4 -*- */
  4. /*
  5. * Copyright © BeyondTrust Software 2004 - 2019
  6. * All rights reserved.
  7. *
  8. * Licensed under the Apache License, Version 2.0 (the "License");
  9. * you may not use this file except in compliance with the License.
  10. * You may obtain a copy of the License at
  11. *
  12. * http://www.apache.org/licenses/LICENSE-2.0
  13. *
  14. * Unless required by applicable law or agreed to in writing, software
  15. * distributed under the License is distributed on an "AS IS" BASIS,
  16. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  17. * See the License for the specific language governing permissions and
  18. * limitations under the License.
  19. *
  20. * BEYONDTRUST MAKES THIS SOFTWARE AVAILABLE UNDER OTHER LICENSING TERMS AS
  21. * WELL. IF YOU HAVE ENTERED INTO A SEPARATE LICENSE AGREEMENT WITH
  22. * BEYONDTRUST, THEN YOU MAY ELECT TO USE THE SOFTWARE UNDER THE TERMS OF THAT
  23. * SOFTWARE LICENSE AGREEMENT INSTEAD OF THE TERMS OF THE APACHE LICENSE,
  24. * NOTWITHSTANDING THE ABOVE NOTICE. IF YOU HAVE QUESTIONS, OR WISH TO REQUEST
  25. * A COPY OF THE ALTERNATE LICENSING TERMS OFFERED BY BEYONDTRUST, PLEASE CONTACT
  26. * BEYONDTRUST AT beyondtrust.com/contact
  27. */
  28. /*
  29. * Copyright (C) BeyondTrust Software. All rights reserved.
  30. *
  31. * Module Name:
  32. *
  33. * lsasqlite.h
  34. *
  35. * Abstract:
  36. *
  37. * BeyondTrust Security and Authentication Subsystem (LSASS)
  38. *
  39. * Sqlite wrapper methods used by the cache API
  40. *
  41. * Authors: Kyle Stemen (kstemen@likewisesoftware.com)
  42. *
  43. */
  44. #ifndef __LSASQLITE_H__
  45. #define __LSASQLITE_H__
  46. #include <lw/security-types.h>
  47. #define SQLITE3_SAFE_FREE_STRING(x) \
  48. if ((x) != NULL) \
  49. { \
  50. sqlite3_free(x); \
  51. (x) = NULL; \
  52. }
  53. #define BAIL_ON_SQLITE3_ERROR(dwError, pszError) \
  54. do { \
  55. if (dwError) \
  56. { \
  57. LSA_LOG_DEBUG("Sqlite3 error '%s' (code = %u)", \
  58. LSA_SAFE_LOG_STRING(pszError), dwError); \
  59. goto error; \
  60. } \
  61. } while (0)
  62. #define BAIL_ON_SQLITE3_ERROR_DB(dwError, pDb) \
  63. BAIL_ON_SQLITE3_ERROR(dwError, sqlite3_errmsg(pDb))
  64. #define BAIL_ON_SQLITE3_ERROR_STMT(dwError, pStatement) \
  65. BAIL_ON_SQLITE3_ERROR_DB(dwError, sqlite3_db_handle(pStatement))
  66. #define ENTER_SQLITE_LOCK(pLock, bInLock) \
  67. if (!bInLock) { \
  68. pthread_rwlock_wrlock(pLock); \
  69. bInLock = TRUE; \
  70. }
  71. #define LEAVE_SQLITE_LOCK(pLock, bInLock) \
  72. if (bInLock) { \
  73. pthread_rwlock_unlock(pLock); \
  74. bInLock = FALSE; \
  75. }
  76. typedef DWORD (*PFN_LSA_SQLITE_EXEC_CALLBACK)(
  77. IN sqlite3 *pDb,
  78. IN PVOID pContext,
  79. OUT PSTR* ppszError
  80. );
  81. DWORD
  82. LsaSqliteReadUInt64(
  83. sqlite3_stmt *pstQuery,
  84. int *piColumnPos,
  85. PCSTR name,
  86. uint64_t *pqwResult);
  87. DWORD
  88. LsaSqliteReadInt64(
  89. sqlite3_stmt *pstQuery,
  90. int *piColumnPos,
  91. PCSTR name,
  92. int64_t *pqwResult);
  93. DWORD
  94. LsaSqliteReadUInt32(
  95. sqlite3_stmt *pstQuery,
  96. int *piColumnPos,
  97. PCSTR name,
  98. DWORD *pdwResult);
  99. DWORD
  100. LsaSqliteReadBoolean(
  101. sqlite3_stmt *pstQuery,
  102. int *piColumnPos,
  103. PCSTR name,
  104. BOOLEAN *pbResult);
  105. DWORD
  106. LsaSqliteReadString(
  107. sqlite3_stmt *pstQuery,
  108. int *piColumnPos,
  109. PCSTR name,
  110. PSTR *ppszResult);
  111. DWORD
  112. LsaSqliteReadStringInPlace(
  113. IN sqlite3_stmt *pstQuery,
  114. IN OUT int *piColumnPos,
  115. IN PCSTR name,
  116. OUT PSTR pszResult,
  117. //Includes NULL
  118. IN size_t sMaxSize);
  119. DWORD
  120. LsaSqliteReadSid(
  121. IN sqlite3_stmt *pstQuery,
  122. IN OUT int *piColumnPos,
  123. IN PCSTR name,
  124. OUT PSID* ppSid);
  125. DWORD
  126. LsaSqliteReadGuid(
  127. IN sqlite3_stmt *pstQuery,
  128. IN OUT int *piColumnPos,
  129. IN PCSTR name,
  130. OUT uuid_t** ppGuid);
  131. DWORD
  132. LsaSqliteBindInt64(
  133. IN OUT sqlite3_stmt* pstQuery,
  134. IN int Index,
  135. IN int64_t Value
  136. );
  137. DWORD
  138. LsaSqliteReadTimeT(
  139. sqlite3_stmt *pstQuery,
  140. int *piColumnPos,
  141. PCSTR name,
  142. time_t *pResult);
  143. DWORD
  144. LsaSqliteBindString(
  145. IN OUT sqlite3_stmt* pstQuery,
  146. IN int Index,
  147. IN PCSTR pszValue
  148. );
  149. DWORD
  150. LsaSqliteBindBoolean(
  151. IN OUT sqlite3_stmt* pstQuery,
  152. IN int Index,
  153. IN BOOLEAN bValue
  154. );
  155. DWORD
  156. LsaSqliteAllocPrintf(
  157. OUT PSTR* ppszSqlCommand,
  158. IN PCSTR pszSqlFormat,
  159. IN ...
  160. );
  161. DWORD
  162. LsaSqliteExec(
  163. IN sqlite3* pSqlDatabase,
  164. IN PCSTR pszSqlCommand,
  165. OUT PSTR* ppszSqlError
  166. );
  167. DWORD
  168. LsaSqliteExecCallbackWithRetry(
  169. IN sqlite3* pDb,
  170. IN pthread_rwlock_t* pLock,
  171. IN PFN_LSA_SQLITE_EXEC_CALLBACK pfnCallback,
  172. IN PVOID pContext
  173. );
  174. DWORD
  175. LsaSqliteExecWithRetry(
  176. IN sqlite3* pDb,
  177. IN pthread_rwlock_t* pLock,
  178. IN PCSTR pszTransaction
  179. );
  180. #endif /* __LSASQLITE_H__ */