Source code of Windows XP (NT5)
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.

408 lines
8.2 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. AddWZCDbLogRecord(
  122. LPWSTR pServerName,
  123. DWORD dwVersion,
  124. PWZC_DB_RECORD pWZCRecord,
  125. LPVOID pvReserved
  126. )
  127. {
  128. DWORD dwError = 0;
  129. WZC_DB_RECORD_CONTAINER RecordContainer;
  130. PWZC_DB_RECORD_CONTAINER pRecordContainer = &RecordContainer;
  131. if (dwVersion || pvReserved != NULL) {
  132. return (ERROR_INVALID_LEVEL);
  133. }
  134. if (!pWZCRecord) {
  135. return (ERROR_INVALID_PARAMETER);
  136. }
  137. pRecordContainer->dwNumRecords = 1;
  138. pRecordContainer->pWZCRecords = pWZCRecord;
  139. RpcTryExcept {
  140. dwError = RpcAddWZCDbLogRecord(
  141. pServerName,
  142. pRecordContainer
  143. );
  144. BAIL_ON_WIN32_ERROR(dwError);
  145. } RpcExcept(I_RpcExceptionFilter(RpcExceptionCode())) {
  146. dwError = TranslateExceptionCode(RpcExceptionCode());
  147. BAIL_ON_WIN32_ERROR(dwError);
  148. } RpcEndExcept
  149. error:
  150. return (dwError);
  151. }
  152. DWORD
  153. EnumWZCDbLogRecords(
  154. HANDLE hSession,
  155. PWZC_DB_RECORD pTemplateRecord,
  156. PBOOL pbEnumFromStart,
  157. DWORD dwPreferredNumEntries,
  158. PWZC_DB_RECORD * ppWZCRecords,
  159. LPDWORD pdwNumRecords,
  160. LPVOID pvReserved
  161. )
  162. {
  163. DWORD dwError = 0;
  164. WZC_DB_RECORD_CONTAINER RecordContainer;
  165. PWZC_DB_RECORD_CONTAINER pRecordContainer = &RecordContainer;
  166. WZC_DB_RECORD_CONTAINER TemplateRecordContainer;
  167. PWZC_DB_RECORD_CONTAINER pTemplateRecordContainer = &TemplateRecordContainer;
  168. if (pvReserved != NULL) {
  169. return (ERROR_INVALID_LEVEL);
  170. }
  171. memset(pRecordContainer, 0, sizeof(WZC_DB_RECORD_CONTAINER));
  172. memset(pTemplateRecordContainer, 0, sizeof(WZC_DB_RECORD_CONTAINER));
  173. if (!hSession || !pbEnumFromStart) {
  174. return (ERROR_INVALID_PARAMETER);
  175. }
  176. if (!ppWZCRecords || !pdwNumRecords) {
  177. return (ERROR_INVALID_PARAMETER);
  178. }
  179. if (pTemplateRecord) {
  180. pTemplateRecordContainer->dwNumRecords = 1;
  181. pTemplateRecordContainer->pWZCRecords = pTemplateRecord;
  182. }
  183. RpcTryExcept {
  184. dwError = RpcEnumWZCDbLogRecords(
  185. hSession,
  186. pTemplateRecordContainer,
  187. pbEnumFromStart,
  188. dwPreferredNumEntries,
  189. &pRecordContainer
  190. );
  191. if (dwError != ERROR_NO_MORE_ITEMS) {
  192. BAIL_ON_WIN32_ERROR(dwError);
  193. }
  194. } RpcExcept(I_RpcExceptionFilter(RpcExceptionCode())) {
  195. dwError = TranslateExceptionCode(RpcExceptionCode());
  196. BAIL_ON_WIN32_ERROR(dwError);
  197. } RpcEndExcept
  198. *ppWZCRecords = pRecordContainer->pWZCRecords;
  199. *pdwNumRecords = pRecordContainer->dwNumRecords;
  200. return (dwError);
  201. error:
  202. *ppWZCRecords = NULL;
  203. *pdwNumRecords = 0;
  204. return (dwError);
  205. }
  206. DWORD
  207. FlushWZCDbLog(
  208. HANDLE hSession
  209. )
  210. {
  211. DWORD dwError = 0;
  212. if (!hSession) {
  213. return (ERROR_INVALID_PARAMETER);
  214. }
  215. RpcTryExcept {
  216. dwError = RpcFlushWZCDbLog(
  217. hSession
  218. );
  219. BAIL_ON_WIN32_ERROR(dwError);
  220. } RpcExcept(I_RpcExceptionFilter(RpcExceptionCode())) {
  221. dwError = TranslateExceptionCode(RpcExceptionCode());
  222. BAIL_ON_WIN32_ERROR(dwError);
  223. } RpcEndExcept
  224. error:
  225. return (dwError);
  226. }
  227. /*
  228. GetSpecificLogRecord: Wrapper for the RPC call to get a specific record
  229. Arguments:
  230. [in] hSession - Handle to the database session
  231. [in] pwzcTemplate - Type of record to locate
  232. [out] ppWZCRecords - List of records retrieved
  233. pvReserved - Reserved
  234. Returns:
  235. ERROR_SUCCESS on success
  236. */
  237. DWORD GetSpecificLogRecord(HANDLE hSession,
  238. PWZC_DB_RECORD pTemplateRecord,
  239. PWZC_DB_RECORD *ppWZCRecords,
  240. LPDWORD pdwNumRecords,
  241. LPVOID pvReserved)
  242. {
  243. DWORD dwError = 0;
  244. WZC_DB_RECORD_CONTAINER RecordContainer;
  245. PWZC_DB_RECORD_CONTAINER pRecordContainer = &RecordContainer;
  246. WZC_DB_RECORD_CONTAINER TemplateRecordContainer;
  247. PWZC_DB_RECORD_CONTAINER pTemplateRecordContainer=&TemplateRecordContainer;
  248. if (pvReserved != NULL)
  249. {
  250. return (ERROR_INVALID_LEVEL);
  251. }
  252. memset(pRecordContainer, 0, sizeof(WZC_DB_RECORD_CONTAINER));
  253. memset(pTemplateRecordContainer, 0, sizeof(WZC_DB_RECORD_CONTAINER));
  254. if (!hSession)
  255. {
  256. return (ERROR_INVALID_PARAMETER);
  257. }
  258. if (!ppWZCRecords || !pdwNumRecords)
  259. {
  260. return (ERROR_INVALID_PARAMETER);
  261. }
  262. if (pTemplateRecord)
  263. {
  264. pTemplateRecordContainer->dwNumRecords = 1;
  265. pTemplateRecordContainer->pWZCRecords = pTemplateRecord;
  266. }
  267. RpcTryExcept
  268. {
  269. dwError = RpcGetWZCDbLogRecord(hSession,
  270. pTemplateRecordContainer,
  271. &pRecordContainer);
  272. if (dwError != ERROR_NO_MORE_ITEMS)
  273. {
  274. BAIL_ON_WIN32_ERROR(dwError);
  275. }
  276. }
  277. RpcExcept(I_RpcExceptionFilter(RpcExceptionCode()))
  278. {
  279. dwError = TranslateExceptionCode(RpcExceptionCode());
  280. BAIL_ON_WIN32_ERROR(dwError);
  281. } RpcEndExcept
  282. *ppWZCRecords = pRecordContainer->pWZCRecords;
  283. *pdwNumRecords = pRecordContainer->dwNumRecords;
  284. return (dwError);
  285. error:
  286. *ppWZCRecords = NULL;
  287. *pdwNumRecords = 0;
  288. return (dwError);
  289. }