Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

363 lines
7.6 KiB

  1. #include "precomp.h"
  2. const ULONG guFatalExceptions[] =
  3. {
  4. STATUS_ACCESS_VIOLATION,
  5. STATUS_POSSIBLE_DEADLOCK,
  6. STATUS_INSTRUCTION_MISALIGNMENT,
  7. STATUS_DATATYPE_MISALIGNMENT,
  8. STATUS_PRIVILEGED_INSTRUCTION,
  9. STATUS_ILLEGAL_INSTRUCTION,
  10. STATUS_BREAKPOINT,
  11. STATUS_STACK_OVERFLOW
  12. };
  13. const int FATAL_EXCEPTIONS_ARRAY_SIZE =
  14. sizeof(guFatalExceptions) / sizeof(guFatalExceptions[0]);
  15. #define BAIL_ON_WIN32_ERROR(dwError) \
  16. if (dwError) { \
  17. goto error; \
  18. }
  19. DWORD
  20. TranslateExceptionCode(
  21. DWORD dwExceptionCode
  22. )
  23. {
  24. return (dwExceptionCode);
  25. }
  26. int
  27. RPC_ENTRY
  28. I_RpcExceptionFilter(
  29. unsigned long uExceptionCode
  30. )
  31. {
  32. int i = 0;
  33. for (i = 0; i < FATAL_EXCEPTIONS_ARRAY_SIZE; i ++) {
  34. if (uExceptionCode == guFatalExceptions[i]) {
  35. return EXCEPTION_CONTINUE_SEARCH;
  36. }
  37. }
  38. return EXCEPTION_EXECUTE_HANDLER;
  39. }
  40. DWORD
  41. WZCDestroyClientContextHandle(
  42. DWORD dwStatus,
  43. HANDLE hFilter
  44. )
  45. {
  46. DWORD dwError = 0;
  47. switch (dwStatus) {
  48. case RPC_S_SERVER_UNAVAILABLE:
  49. case RPC_S_CALL_FAILED:
  50. case RPC_S_CALL_FAILED_DNE:
  51. case RPC_S_UNKNOWN_IF:
  52. RpcTryExcept {
  53. RpcSsDestroyClientContext(&hFilter);
  54. } RpcExcept(I_RpcExceptionFilter(RpcExceptionCode())) {
  55. dwError = TranslateExceptionCode(RpcExceptionCode());
  56. BAIL_ON_WIN32_ERROR(dwError);
  57. } RpcEndExcept
  58. break;
  59. default:
  60. dwError = dwStatus;
  61. break;
  62. }
  63. error:
  64. return (dwError);
  65. }
  66. DWORD
  67. OpenWZCDbLogSession(
  68. LPWSTR pServerName,
  69. DWORD dwVersion,
  70. PHANDLE phSession
  71. )
  72. {
  73. DWORD dwError = 0;
  74. if (dwVersion) {
  75. return (ERROR_INVALID_LEVEL);
  76. }
  77. if (!phSession) {
  78. return (ERROR_INVALID_PARAMETER);
  79. }
  80. RpcTryExcept {
  81. dwError = RpcOpenWZCDbLogSession(
  82. pServerName,
  83. phSession
  84. );
  85. BAIL_ON_WIN32_ERROR(dwError);
  86. } RpcExcept(I_RpcExceptionFilter(RpcExceptionCode())) {
  87. dwError = TranslateExceptionCode(RpcExceptionCode());
  88. BAIL_ON_WIN32_ERROR(dwError);
  89. } RpcEndExcept
  90. error:
  91. return (dwError);
  92. }
  93. DWORD
  94. CloseWZCDbLogSession(
  95. HANDLE hSession
  96. )
  97. {
  98. DWORD dwError = 0;
  99. if (!hSession) {
  100. return (ERROR_INVALID_PARAMETER);
  101. }
  102. RpcTryExcept {
  103. dwError = RpcCloseWZCDbLogSession(
  104. &hSession
  105. );
  106. BAIL_ON_WIN32_ERROR(dwError);
  107. } RpcExcept(I_RpcExceptionFilter(RpcExceptionCode())) {
  108. dwError = TranslateExceptionCode(RpcExceptionCode());
  109. BAIL_ON_WIN32_ERROR(dwError);
  110. } RpcEndExcept
  111. error:
  112. if (dwError) {
  113. dwError = WZCDestroyClientContextHandle(
  114. dwError,
  115. hSession
  116. );
  117. }
  118. return (dwError);
  119. }
  120. DWORD
  121. EnumWZCDbLogRecords(
  122. HANDLE hSession,
  123. PWZC_DB_RECORD pTemplateRecord,
  124. PBOOL pbEnumFromStart,
  125. DWORD dwPreferredNumEntries,
  126. PWZC_DB_RECORD * ppWZCRecords,
  127. LPDWORD pdwNumRecords,
  128. LPVOID pvReserved
  129. )
  130. {
  131. DWORD dwError = 0;
  132. WZC_DB_RECORD_CONTAINER RecordContainer;
  133. PWZC_DB_RECORD_CONTAINER pRecordContainer = &RecordContainer;
  134. WZC_DB_RECORD_CONTAINER TemplateRecordContainer;
  135. PWZC_DB_RECORD_CONTAINER pTemplateRecordContainer = &TemplateRecordContainer;
  136. if (pvReserved != NULL) {
  137. return (ERROR_INVALID_LEVEL);
  138. }
  139. memset(pRecordContainer, 0, sizeof(WZC_DB_RECORD_CONTAINER));
  140. memset(pTemplateRecordContainer, 0, sizeof(WZC_DB_RECORD_CONTAINER));
  141. if (!hSession || !pbEnumFromStart) {
  142. return (ERROR_INVALID_PARAMETER);
  143. }
  144. if (!ppWZCRecords || !pdwNumRecords) {
  145. return (ERROR_INVALID_PARAMETER);
  146. }
  147. if (pTemplateRecord) {
  148. pTemplateRecordContainer->dwNumRecords = 1;
  149. pTemplateRecordContainer->pWZCRecords = pTemplateRecord;
  150. }
  151. RpcTryExcept {
  152. dwError = RpcEnumWZCDbLogRecords(
  153. hSession,
  154. pTemplateRecordContainer,
  155. pbEnumFromStart,
  156. dwPreferredNumEntries,
  157. &pRecordContainer
  158. );
  159. if (dwError != ERROR_NO_MORE_ITEMS) {
  160. BAIL_ON_WIN32_ERROR(dwError);
  161. }
  162. } RpcExcept(I_RpcExceptionFilter(RpcExceptionCode())) {
  163. dwError = TranslateExceptionCode(RpcExceptionCode());
  164. BAIL_ON_WIN32_ERROR(dwError);
  165. } RpcEndExcept
  166. *ppWZCRecords = pRecordContainer->pWZCRecords;
  167. *pdwNumRecords = pRecordContainer->dwNumRecords;
  168. return (dwError);
  169. error:
  170. *ppWZCRecords = NULL;
  171. *pdwNumRecords = 0;
  172. return (dwError);
  173. }
  174. DWORD
  175. FlushWZCDbLog(
  176. HANDLE hSession
  177. )
  178. {
  179. DWORD dwError = 0;
  180. if (!hSession) {
  181. return (ERROR_INVALID_PARAMETER);
  182. }
  183. RpcTryExcept {
  184. dwError = RpcFlushWZCDbLog(
  185. hSession
  186. );
  187. BAIL_ON_WIN32_ERROR(dwError);
  188. } RpcExcept(I_RpcExceptionFilter(RpcExceptionCode())) {
  189. dwError = TranslateExceptionCode(RpcExceptionCode());
  190. BAIL_ON_WIN32_ERROR(dwError);
  191. } RpcEndExcept
  192. error:
  193. return (dwError);
  194. }
  195. /*
  196. GetSpecificLogRecord: Wrapper for the RPC call to get a specific record
  197. Arguments:
  198. [in] hSession - Handle to the database session
  199. [in] pwzcTemplate - Type of record to locate
  200. [out] ppWZCRecords - List of records retrieved
  201. pvReserved - Reserved
  202. Returns:
  203. ERROR_SUCCESS on success
  204. */
  205. DWORD GetSpecificLogRecord(HANDLE hSession,
  206. PWZC_DB_RECORD pTemplateRecord,
  207. PWZC_DB_RECORD *ppWZCRecords,
  208. LPDWORD pdwNumRecords,
  209. LPVOID pvReserved)
  210. {
  211. DWORD dwError = 0;
  212. WZC_DB_RECORD_CONTAINER RecordContainer;
  213. PWZC_DB_RECORD_CONTAINER pRecordContainer = &RecordContainer;
  214. WZC_DB_RECORD_CONTAINER TemplateRecordContainer;
  215. PWZC_DB_RECORD_CONTAINER pTemplateRecordContainer=&TemplateRecordContainer;
  216. if (pvReserved != NULL)
  217. {
  218. return (ERROR_INVALID_LEVEL);
  219. }
  220. memset(pRecordContainer, 0, sizeof(WZC_DB_RECORD_CONTAINER));
  221. memset(pTemplateRecordContainer, 0, sizeof(WZC_DB_RECORD_CONTAINER));
  222. if (!hSession)
  223. {
  224. return (ERROR_INVALID_PARAMETER);
  225. }
  226. if (!ppWZCRecords || !pdwNumRecords)
  227. {
  228. return (ERROR_INVALID_PARAMETER);
  229. }
  230. if (pTemplateRecord)
  231. {
  232. pTemplateRecordContainer->dwNumRecords = 1;
  233. pTemplateRecordContainer->pWZCRecords = pTemplateRecord;
  234. }
  235. RpcTryExcept
  236. {
  237. dwError = RpcGetWZCDbLogRecord(hSession,
  238. pTemplateRecordContainer,
  239. &pRecordContainer);
  240. if (dwError != ERROR_NO_MORE_ITEMS)
  241. {
  242. BAIL_ON_WIN32_ERROR(dwError);
  243. }
  244. }
  245. RpcExcept(I_RpcExceptionFilter(RpcExceptionCode()))
  246. {
  247. dwError = TranslateExceptionCode(RpcExceptionCode());
  248. BAIL_ON_WIN32_ERROR(dwError);
  249. } RpcEndExcept
  250. *ppWZCRecords = pRecordContainer->pWZCRecords;
  251. *pdwNumRecords = pRecordContainer->dwNumRecords;
  252. return (dwError);
  253. error:
  254. *ppWZCRecords = NULL;
  255. *pdwNumRecords = 0;
  256. return (dwError);
  257. }