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.

862 lines
21 KiB

  1. //+--------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1996 - 1999
  5. //
  6. // File: cs.h
  7. //
  8. // Contents: Cert Server common definitions
  9. //
  10. // History: 25-Jul-96 vich created
  11. //
  12. //---------------------------------------------------------------------------
  13. #ifndef __CS_H__
  14. #define __CS_H__
  15. #ifndef __CERTLIB_H__
  16. # error -- cs.h should only be included from certlib.h!
  17. #endif
  18. #include <ntverp.h>
  19. #ifndef DBG
  20. # if defined _DEBUG
  21. # define DBG 1
  22. # else
  23. # define DBG 0
  24. # endif
  25. #endif
  26. #ifndef DBG_CERTSRV
  27. # define DBG_CERTSRV DBG
  28. #endif
  29. // _tcslen of a static string:
  30. #define _TSZARRAYSIZE(a) ((DWORD) ((sizeof(a)/sizeof((a)[0])) - 1))
  31. #if !defined(DBG_CERTSRV_DEBUG_PRINT) && !defined(DBG_CERTSRV_DEBUG_PRINT_LINEFILE)
  32. # if DBG_CERTSRV
  33. # define DBG_CERTSRV_DEBUG_PRINT // checked build logging
  34. # else
  35. //# define DBG_CERTSRV_DEBUG_PRINT_LINEFILE 1 // basic file#, line# logging
  36. //# define DBG_CERTSRV_DEBUG_PRINT_LINEFILE 2 // add Error2, etc. logging
  37. # define DBG_CERTSRV_DEBUG_PRINT_LINEFILE 3 // also add dynamic strings
  38. # endif
  39. #endif //DBG_CERTSRV
  40. #define DBG_SS_ERROR 0x00000001
  41. #define DBG_SS_ASSERT 0x00000002
  42. #define DBG_SS_INFO 0x00000004 // or in with any of the below
  43. #define DBG_SS_MODLOAD 0x00000008
  44. #define DBG_SS_NOQUIET 0x00000010
  45. #define DBG_SS_CERTHIER 0x00000100
  46. #define DBG_SS_CERTREQ 0x00000200
  47. #define DBG_SS_CERTUTIL 0x00000400
  48. #define DBG_SS_CERTSRV 0x00000800
  49. #define DBG_SS_CERTADM 0x00001000
  50. #define DBG_SS_CERTCLI 0x00002000
  51. #define DBG_SS_CERTDB 0x00004000
  52. #define DBG_SS_CERTENC 0x00008000
  53. #define DBG_SS_CERTEXIT 0x00010000
  54. #define DBG_SS_CERTIF 0x00020000
  55. #define DBG_SS_CERTMMC 0x00040000
  56. #define DBG_SS_CERTOCM 0x00080000
  57. #define DBG_SS_CERTPOL 0x00100000
  58. #define DBG_SS_CERTVIEW 0x00200000
  59. #define DBG_SS_CERTBCLI 0x00400000
  60. #define DBG_SS_CERTJET 0x00800000
  61. #define DBG_SS_CERTLIBXE 0x10000000 // same as dbgdef.h's DBG_SS_APP
  62. #define DBG_SS_AUDIT 0x20000000
  63. #define DBG_SS_CERTLIB 0x40000000
  64. #define DBG_SS_OPENLOG 0x80000000
  65. #define DBG_SS_CERTHIERI (DBG_SS_CERTHIER | DBG_SS_INFO)
  66. #define DBG_SS_CERTREQI (DBG_SS_CERTREQ | DBG_SS_INFO)
  67. #define DBG_SS_CERTUTILI (DBG_SS_CERTUTIL | DBG_SS_INFO)
  68. #define DBG_SS_CERTSRVI (DBG_SS_CERTSRV | DBG_SS_INFO)
  69. #define DBG_SS_CERTADMI (DBG_SS_CERTADM | DBG_SS_INFO)
  70. #define DBG_SS_CERTCLII (DBG_SS_CERTCLI | DBG_SS_INFO)
  71. #define DBG_SS_CERTDBI (DBG_SS_CERTDB | DBG_SS_INFO)
  72. #define DBG_SS_CERTENCI (DBG_SS_CERTENC | DBG_SS_INFO)
  73. #define DBG_SS_CERTEXITI (DBG_SS_CERTEXIT | DBG_SS_INFO)
  74. #define DBG_SS_CERTIFI (DBG_SS_CERTIF | DBG_SS_INFO)
  75. #define DBG_SS_CERTMMCI (DBG_SS_CERTMMC | DBG_SS_INFO)
  76. #define DBG_SS_CERTOCMI (DBG_SS_CERTOCM | DBG_SS_INFO)
  77. #define DBG_SS_CERTPOLI (DBG_SS_CERTPOL | DBG_SS_INFO)
  78. #define DBG_SS_CERTVIEWI (DBG_SS_CERTVIEW | DBG_SS_INFO)
  79. #define DBG_SS_CERTBCLII (DBG_SS_CERTBCLI | DBG_SS_INFO)
  80. #define DBG_SS_CERTJETI (DBG_SS_CERTJET | DBG_SS_INFO)
  81. #define DBG_SS_CERTLIBI (DBG_SS_CERTLIB | DBG_SS_INFO)
  82. // begin_certsrv
  83. // VerifyRequest() return values
  84. #define VR_PENDING 0 // request will be accepted or denied later
  85. #define VR_INSTANT_OK 1 // request was accepted
  86. #define VR_INSTANT_BAD 2 // request was rejected
  87. // end_certsrv
  88. // Certificate types:
  89. #define CERT_TYPE_NONE 0 // cannot create certificates
  90. #define CERT_TYPE_X509 1 // CCITT x509 certificates
  91. #define CERT_TYPE_SDSI 2 // SDSI certificates
  92. #define CERT_TYPE_PGP 3 // PGP certificates
  93. #if DBG_CERTSRV
  94. # define DBGCODE(a) a
  95. # define DBGPARM0(parm) parm
  96. # define DBGPARM(parm) , parm
  97. #else // DBG_CERTSRV
  98. # define DBGCODE(a)
  99. # define DBGPARM0(parm)
  100. # define DBGPARM(parm)
  101. #endif // DBG_CERTSRV
  102. #define wprintf myConsolePrintf
  103. #define printf Use_wprintf_Instead_Of_printf
  104. #define LdapMapErrorToWin32 Use_myHLdapError_Instead_Of_LdapMapErrorToWin32
  105. #if 0 == i386
  106. # define IOBUNALIGNED(pf) ((sizeof(WCHAR) - 1) & (DWORD) (ULONG_PTR) (pf)->_ptr)
  107. # define ALIGNIOB(pf) \
  108. { \
  109. if (IOBUNALIGNED(pf)) \
  110. { \
  111. fflush(pf); /* fails when running as a service */ \
  112. } \
  113. if (IOBUNALIGNED(pf)) \
  114. { \
  115. fprintf(pf, " "); \
  116. fflush(pf); \
  117. } \
  118. }
  119. #else
  120. # define IOBUNALIGNED(pf) FALSE
  121. # define ALIGNIOB(pf)
  122. #endif
  123. HRESULT myHExceptionCode(IN EXCEPTION_POINTERS const *pep);
  124. typedef VOID (WINAPI FNPRINTERROR)(
  125. IN char const *pszMessage,
  126. OPTIONAL IN WCHAR const *pwszData,
  127. IN char const *pszFile,
  128. IN DWORD dwLine,
  129. IN HRESULT hr,
  130. IN HRESULT hrquiet);
  131. FNPRINTERROR CSPrintError;
  132. typedef VOID (WINAPI FNPRINTASSERT)(
  133. IN char const *pszFailedAssertion,
  134. IN char const *pszFileName,
  135. IN DWORD dwLine,
  136. IN char const *pszMessage);
  137. FNPRINTASSERT CSPrintAssert;
  138. typedef VOID (WINAPI FNPRINTERRORLINEFILE)(
  139. IN DWORD dwLineFile,
  140. IN HRESULT hr);
  141. FNPRINTERRORLINEFILE CSPrintErrorLineFile;
  142. typedef VOID (WINAPI FNPRINTERRORLINEFILE2)(
  143. IN DWORD dwLineFile,
  144. IN HRESULT hr,
  145. IN HRESULT hrquiet);
  146. FNPRINTERRORLINEFILE2 CSPrintErrorLineFile2;
  147. typedef VOID (WINAPI FNPRINTERRORLINEFILE2)(
  148. IN DWORD dwLineFile,
  149. IN HRESULT hr,
  150. IN HRESULT hrquiet);
  151. FNPRINTERRORLINEFILE2 CSPrintErrorLineFile2;
  152. typedef VOID (WINAPI FNPRINTERRORLINEFILEDATA)(
  153. OPTIONAL IN WCHAR const *pwszData,
  154. IN DWORD dwLineFile,
  155. IN HRESULT hr);
  156. FNPRINTERRORLINEFILEDATA CSPrintErrorLineFileData;
  157. typedef VOID (WINAPI FNPRINTERRORLINEFILEDATA2)(
  158. OPTIONAL IN WCHAR const *pwszData,
  159. IN DWORD dwLineFile,
  160. IN HRESULT hr,
  161. IN HRESULT hrquiet);
  162. FNPRINTERRORLINEFILEDATA2 CSPrintErrorLineFileData2;
  163. #define __LINEFILE__ __MAKELINEFILE__(__dwFILE__, __LINE__)
  164. #define __MAKELINEFILE__(file, line) ((file) | ((line) << 16))
  165. #define __LINEFILETOFILE__(dwLineFile) ((DWORD) (USHORT) (dwLineFile))
  166. #define __LINEFILETOLINE__(dwLineFile) ((dwLineFile) >> 16)
  167. #ifdef DBG_CERTSRV_DEBUG_PRINT
  168. #define __FILEDIR__ __DIR__ "\\" __FILE__
  169. __inline BOOL CSExpr(IN BOOL expr) { return(expr); }
  170. __inline BOOL CSExprA(IN char const *pszexpr) { return(NULL != pszexpr); }
  171. __inline BOOL CSExprW(IN WCHAR const *pwszexpr) { return(NULL != pwszexpr); }
  172. # define CSASSERT(exp) CSASSERTMSG(NULL, exp)
  173. # define CSASSERTMSG(pszmsg, exp) \
  174. if (!(exp)) \
  175. CSPrintAssert(#exp, __FILEDIR__, __LINE__, (pszmsg))
  176. # define DBGERRORPRINT(pszMessage, pwszData, dwLine, hr, hrquiet) \
  177. CSPrintError((pszMessage), (pwszData), __FILEDIR__, (dwLine), (hr), (hrquiet))
  178. # define myHEXCEPTIONCODE() myHExceptionCodePrint(GetExceptionInformation(), __FILEDIR__, __dwFILE__, __LINE__)
  179. #else // DBG_CERTSRV_DEBUG_PRINT
  180. # ifdef DBG_CERTSRV_DEBUG_PRINT_LINEFILE // free build tracing
  181. # define myHEXCEPTIONCODE() myHExceptionCodePrintLineFile(GetExceptionInformation(), __LINEFILE__)
  182. # else // DBG_CERTSRV_DEBUG_PRINT_LINEFILE
  183. # define DBGERRORPRINT(pszMessage, pwszData, dwLine, hr, hrquiet)
  184. # define myHEXCEPTIONCODE() myHExceptionCodePrint(GetExceptionInformation(), NULL, __dwFILE__, __LINE__)
  185. # endif // DBG_CERTSRV_DEBUG_PRINT_LINEFILE
  186. # define CSASSERT(exp)
  187. # define CSASSERTMSG(msg, exp)
  188. #endif // DBG_CERTSRV_DEBUG_PRINT
  189. #ifdef DBG_CERTSRV_DEBUG_PRINT_LINEFILE
  190. #define DBGERRORPRINTLINE(pszMessage, hr) \
  191. CSPrintErrorLineFile(__LINEFILE__, (hr))
  192. # if (2 <= DBG_CERTSRV_DEBUG_PRINT_LINEFILE)
  193. # define DBGERRORPRINTLINE2(pszMessage, hr, hrquiet) \
  194. CSPrintErrorLineFile2(__LINEFILE__, (hr), (hrquiet))
  195. # else
  196. # define DBGERRORPRINTLINE2(pszMessage, hr, hrquiet)
  197. # endif
  198. #if (3 <= DBG_CERTSRV_DEBUG_PRINT_LINEFILE)
  199. # define DBGERRORPRINTLINESTR(pszMessage, pwszData, hr) \
  200. CSPrintErrorLineFileData((pwszData), __LINEFILE__, (hr))
  201. # define DBGERRORPRINTLINESTR2(pszMessage, pwszData, hr, hrquiet) \
  202. CSPrintErrorLineFileData2((pwszData), __LINEFILE__, (hr), (hrquiet))
  203. #else
  204. # define DBGERRORPRINTLINESTR(pszMessage, pwszData, hr) \
  205. CSPrintErrorLineFile(__LINEFILE__, (hr))
  206. # if (2 <= DBG_CERTSRV_DEBUG_PRINT_LINEFILE)
  207. # define DBGERRORPRINTLINESTR2(pszMessage, pwszData, hr, hrquiet) \
  208. CSPrintErrorLineFile2(__LINEFILE__, (hr), (hrquiet))
  209. # else
  210. # define DBGERRORPRINTLINESTR2(pszMessage, pwszData, hr, hrquiet)
  211. # endif
  212. #endif
  213. #else // DBG_CERTSRV_DEBUG_PRINT_LINEFILE
  214. #define DBGERRORPRINTLINE(pszMessage, hr) \
  215. DBGERRORPRINTLINESTR2((pszMessage), NULL, (hr), 0)
  216. #define DBGERRORPRINTLINE2(pszMessage, hr, hrquiet) \
  217. DBGERRORPRINTLINESTR2((pszMessage), NULL, (hr), (hrquiet))
  218. #define DBGERRORPRINTLINESTR(pszMessage, pwszData, hr) \
  219. DBGERRORPRINTLINESTR2((pszMessage), (pwszData), (hr), 0)
  220. #define DBGERRORPRINTLINESTR2(pszMessage, pwszData, hr, hrquiet) \
  221. { \
  222. DBGERRORPRINT((pszMessage), (pwszData), __LINE__, (hr), (hrquiet)); \
  223. }
  224. #endif // DBG_CERTSRV_DEBUG_PRINT_LINEFILE
  225. typedef VOID (FNLOGSTRING)(
  226. IN char const *pszString);
  227. typedef VOID (FNLOGEXCEPTION)(
  228. IN HRESULT hrExcept,
  229. IN EXCEPTION_POINTERS const *pep,
  230. OPTIONAL IN char const *pszFileName,
  231. IN DWORD dwFile,
  232. IN DWORD dwLine);
  233. HRESULT myHExceptionCodePrint(
  234. IN EXCEPTION_POINTERS const *pep,
  235. OPTIONAL IN char const *pszFile,
  236. IN DWORD dwFile,
  237. IN DWORD dwLine);
  238. HRESULT myHExceptionCodePrintLineFile(
  239. IN EXCEPTION_POINTERS const *pep,
  240. IN DWORD dwLineFile);
  241. VOID myLogExceptionInit(
  242. IN FNLOGEXCEPTION *pfnLogException);
  243. int WINAPIV DbgPrintf(DWORD dwSubSysId, char const *pszfmt, ...);
  244. int WINAPIV DbgPrintfW(DWORD dwSubSysId, WCHAR const *pwszfmt, ...);
  245. VOID DbgPrintfInit(OPTIONAL IN CHAR const *pszFile);
  246. BOOL DbgIsSSActive(DWORD dwSSIn);
  247. VOID DbgLogStringInit(FNLOGSTRING *pfnLog);
  248. VOID DbgTerminate(VOID);
  249. #if (VER_FILEFLAGS & VS_FF_DEBUG)
  250. #define szCSVER_DEBUG_STR " debug"
  251. #else
  252. #define szCSVER_DEBUG_STR " retail"
  253. #endif
  254. #if (VER_FILEFLAGS & VS_FF_PRIVATEBUILD)
  255. #define szCSVER_PRIVATE_STR " private"
  256. #else
  257. #define szCSVER_PRIVATE_STR
  258. #endif
  259. #define szCSVER_STR \
  260. VER_FILEVERSION_STR szCSVER_DEBUG_STR szCSVER_PRIVATE_STR BUILD_MACHINE_TAG
  261. __inline VOID
  262. DbgLogFileVersion(
  263. IN char const *pszFile,
  264. IN char const *pszVersion)
  265. {
  266. DbgPrintf(MAXDWORD, "%hs: %hs\n", pszFile, pszVersion);
  267. }
  268. #define CBLOGMAXAPPEND (512 * 1024)
  269. #ifdef DBG_CERTSRV_DEBUG_PRINT
  270. # define DBGPRINT(a) DbgPrintf a
  271. # define DBGPRINTW(a) DbgPrintfW a
  272. # define DBGDUMPHEX(a) mydbgDumpHex a
  273. # define DBGPARMREFERENCED(parm) parm
  274. #else
  275. # define DBGPRINT(a)
  276. # define DBGPRINTW(a)
  277. # define DBGDUMPHEX(a)
  278. # define DBGPARMREFERENCED(parm)
  279. #endif
  280. #define CONSOLEPRINT0(a) DbgPrintf a
  281. #define CONSOLEPRINT1(a) DbgPrintf a
  282. #define CONSOLEPRINT2(a) DbgPrintf a
  283. #define CONSOLEPRINT3(a) DbgPrintf a
  284. #define CONSOLEPRINT4(a) DbgPrintf a
  285. #define CONSOLEPRINT5(a) DbgPrintf a
  286. #define CONSOLEPRINT6(a) DbgPrintf a
  287. #define CONSOLEPRINT7(a) DbgPrintf a
  288. #define CONSOLEPRINT8(a) DbgPrintf a
  289. #if 1 < DBG_CERTSRV
  290. # define DBGTRACE(a) DbgPrintf a
  291. #else
  292. # define DBGTRACE(a)
  293. #endif
  294. #define _LeaveError(hr, pszMessage) \
  295. { \
  296. DBGERRORPRINTLINE((pszMessage), (hr)); \
  297. __leave; \
  298. }
  299. #define _LeaveError2(hr, pszMessage, hrquiet) \
  300. { \
  301. DBGERRORPRINTLINE2((pszMessage), (hr), (hrquiet)); \
  302. __leave; \
  303. }
  304. #define _LeaveErrorStr(hr, pszMessage, pwszData) \
  305. { \
  306. DBGERRORPRINTLINESTR((pszMessage), (pwszData), (hr)); \
  307. __leave; \
  308. }
  309. #define _LeaveError3(hr, pszMessage, hrquiet, hrquiet2) \
  310. _LeaveErrorStr3((hr), (pszMessage), NULL, (hrquiet), (hrquiet2))
  311. #define _LeaveErrorStr2(hr, pszMessage, pwszData, hrquiet) \
  312. { \
  313. DBGERRORPRINTLINESTR2((pszMessage), (pwszData), (hr), (hrquiet)); \
  314. __leave; \
  315. }
  316. #define _LeaveErrorStr3(hr, pszMessage, pwszData, hrquiet, hrquiet2) \
  317. { \
  318. if ((hrquiet2) != (hr)) \
  319. { \
  320. DBGERRORPRINTLINESTR2((pszMessage), (pwszData), (hr), (hrquiet)); \
  321. } \
  322. __leave; \
  323. }
  324. #define _LeaveIfError(hr, pszMessage) \
  325. { \
  326. if (S_OK != (hr)) \
  327. { \
  328. DBGERRORPRINTLINE((pszMessage), (hr)); \
  329. __leave; \
  330. } \
  331. }
  332. #define _LeaveIfError2(hr, pszMessage, hrquiet) \
  333. { \
  334. if (S_OK != (hr)) \
  335. { \
  336. DBGERRORPRINTLINE2((pszMessage), (hr), (hrquiet)); \
  337. __leave; \
  338. } \
  339. }
  340. #define _LeaveIfErrorStr(hr, pszMessage, pwszData) \
  341. { \
  342. if (S_OK != (hr)) \
  343. { \
  344. DBGERRORPRINTLINESTR((pszMessage), (pwszData), (hr)); \
  345. __leave; \
  346. } \
  347. }
  348. #define _LeaveIfError3(hr, pszMessage, hrquiet, hrquiet2) \
  349. { \
  350. if (S_OK != (hr)) \
  351. { \
  352. if ((hrquiet2) != (hr)) \
  353. { \
  354. DBGERRORPRINTLINE2((pszMessage), (hr), (hrquiet)); \
  355. } \
  356. __leave; \
  357. } \
  358. }
  359. #define _LeaveIfErrorStr2(hr, pszMessage, pwszData, hrquiet) \
  360. { \
  361. if (S_OK != (hr)) \
  362. { \
  363. DBGERRORPRINTLINESTR2((pszMessage), (pwszData), (hr), (hrquiet)); \
  364. __leave; \
  365. } \
  366. }
  367. #define _LeaveIfErrorStr3(hr, pszMessage, pwszData, hrquiet, hrquiet2) \
  368. { \
  369. if (S_OK != (hr)) \
  370. { \
  371. if ((hrquiet2) != (hr)) \
  372. { \
  373. DBGERRORPRINTLINESTR2((pszMessage), (pwszData), (hr), (hrquiet)); \
  374. } \
  375. __leave; \
  376. } \
  377. }
  378. #define _PrintError(hr, pszMessage) \
  379. { \
  380. DBGERRORPRINTLINE((pszMessage), (hr)); \
  381. }
  382. #define _PrintError2(hr, pszMessage, hrquiet) \
  383. { \
  384. DBGERRORPRINTLINE2((pszMessage), (hr), (hrquiet)); \
  385. }
  386. #define _PrintErrorStr(hr, pszMessage, pwszData) \
  387. { \
  388. DBGERRORPRINTLINESTR((pszMessage), (pwszData), (hr)); \
  389. }
  390. #define _PrintError3(hr, pszMessage, hrquiet, hrquiet2) \
  391. { \
  392. if ((hrquiet2) != (hr)) \
  393. { \
  394. DBGERRORPRINTLINE2((pszMessage), (hr), (hrquiet)); \
  395. } \
  396. }
  397. #define _PrintErrorStr2(hr, pszMessage, pwszData, hrquiet) \
  398. { \
  399. DBGERRORPRINTLINESTR2((pszMessage), (pwszData), (hr), (hrquiet)); \
  400. }
  401. #define _PrintErrorStr3(hr, pszMessage, pwszData, hrquiet, hrquiet2) \
  402. { \
  403. if ((hrquiet2) != (hr)) \
  404. { \
  405. DBGERRORPRINTLINESTR2((pszMessage), (pwszData), (hr), (hrquiet)); \
  406. } \
  407. }
  408. #define _PrintIfError(hr, pszMessage) \
  409. { \
  410. if (S_OK != (hr)) \
  411. { \
  412. DBGERRORPRINTLINE((pszMessage), (hr)); \
  413. } \
  414. }
  415. #define _PrintIfError2(hr, pszMessage, hrquiet) \
  416. { \
  417. if (S_OK != (hr)) \
  418. { \
  419. DBGERRORPRINTLINE2((pszMessage), (hr), (hrquiet)); \
  420. } \
  421. }
  422. #define _PrintIfError3(hr, pszMessage, hrquiet, hrquiet2) \
  423. { \
  424. if (S_OK != (hr)) \
  425. { \
  426. if ((hrquiet2) != (hr)) \
  427. { \
  428. DBGERRORPRINTLINE2((pszMessage), (hr), (hrquiet)); \
  429. } \
  430. } \
  431. }
  432. #define _PrintIfError4(hr, pszMessage, hrquiet, hrquiet2, hrquiet3) \
  433. { \
  434. if (S_OK != (hr)) \
  435. { \
  436. if ((hrquiet2) != (hr) && (hrquiet3) != (hr)) \
  437. { \
  438. DBGERRORPRINTLINE2((pszMessage), (hr), (hrquiet)); \
  439. } \
  440. } \
  441. }
  442. #define _PrintIfErrorStr(hr, pszMessage, pwszData) \
  443. { \
  444. if (S_OK != (hr)) \
  445. { \
  446. DBGERRORPRINTLINESTR((pszMessage), (pwszData), (hr)); \
  447. } \
  448. }
  449. #define _PrintIfErrorStr2(hr, pszMessage, pwszData, hrquiet) \
  450. { \
  451. if (S_OK != (hr)) \
  452. { \
  453. DBGERRORPRINTLINESTR2((pszMessage), (pwszData), (hr), (hrquiet)); \
  454. } \
  455. }
  456. #define _PrintIfErrorStr3(hr, pszMessage, pwszData, hrquiet, hrquiet2) \
  457. { \
  458. if (S_OK != (hr)) \
  459. { \
  460. if ((hrquiet2) != (hr)) \
  461. { \
  462. DBGERRORPRINTLINESTR2((pszMessage), (pwszData), (hr), (hrquiet)); \
  463. } \
  464. } \
  465. }
  466. #define _PrintIfErrorStr4(hr, pszMessage, pwszData, hrquiet, hrquiet2, hrquiet3) \
  467. { \
  468. if (S_OK != (hr)) \
  469. { \
  470. if ((hrquiet2) != (hr) && (hrquiet3) != (hr)) \
  471. { \
  472. DBGERRORPRINTLINESTR2((pszMessage), (pwszData), (hr), (hrquiet)); \
  473. } \
  474. } \
  475. }
  476. #define _PrintExpectedError(hr, pszMessage) \
  477. { \
  478. if (S_OK != (hr)) \
  479. { \
  480. DBGERRORPRINTLINESTR(("Expected error "), (pszMessage), (hr)); \
  481. } \
  482. }
  483. #define _JumpError(hr, label, pszMessage) \
  484. { \
  485. DBGERRORPRINTLINE((pszMessage), (hr)); \
  486. goto label; \
  487. }
  488. #define _JumpError2(hr, label, pszMessage, hrquiet) \
  489. { \
  490. DBGERRORPRINTLINE2((pszMessage), (hr), (hrquiet)); \
  491. goto label; \
  492. }
  493. #define _JumpErrorStr(hr, label, pszMessage, pwszData) \
  494. { \
  495. DBGERRORPRINTLINESTR((pszMessage), (pwszData), (hr)); \
  496. goto label; \
  497. }
  498. #define _JumpErrorStr2(hr, label, pszMessage, pwszData, hrquiet) \
  499. { \
  500. DBGERRORPRINTLINESTR2((pszMessage), (pwszData), (hr), (hrquiet)); \
  501. goto label; \
  502. }
  503. #define _JumpErrorStr3(hr, label, pszMessage, pwszData, hrquiet, hrquiet2) \
  504. { \
  505. if ((hrquiet2) != (hr)) \
  506. { \
  507. DBGERRORPRINTLINESTR2((pszMessage), (pwszData), (hr), (hrquiet)); \
  508. } \
  509. goto label; \
  510. }
  511. #define _JumpIfError(hr, label, pszMessage) \
  512. { \
  513. if (S_OK != (hr)) \
  514. { \
  515. DBGERRORPRINTLINE((pszMessage), (hr)); \
  516. goto label; \
  517. } \
  518. }
  519. #define _JumpIfError2(hr, label, pszMessage, hrquiet) \
  520. { \
  521. if (S_OK != (hr)) \
  522. { \
  523. DBGERRORPRINTLINE2((pszMessage), (hr), (hrquiet)); \
  524. goto label; \
  525. } \
  526. }
  527. #define _JumpIfErrorStr(hr, label, pszMessage, pwszData) \
  528. { \
  529. if (S_OK != (hr)) \
  530. { \
  531. DBGERRORPRINTLINESTR((pszMessage), (pwszData), (hr)); \
  532. goto label; \
  533. } \
  534. }
  535. #define _JumpIfError3(hr, label, pszMessage, hrquiet, hrquiet2) \
  536. { \
  537. if (S_OK != (hr)) \
  538. { \
  539. if ((hrquiet2) != (hr)) \
  540. { \
  541. DBGERRORPRINTLINE2((pszMessage), (hr), (hrquiet)); \
  542. } \
  543. goto label; \
  544. } \
  545. }
  546. #define _JumpIfError4(hr, label, pszMessage, hrquiet, hrquiet2, hrquiet3) \
  547. { \
  548. if (S_OK != (hr)) \
  549. { \
  550. if ((hrquiet2) != (hr) && (hrquiet3) != (hr)) \
  551. { \
  552. DBGERRORPRINTLINE2((pszMessage), (hr), (hrquiet)); \
  553. } \
  554. goto label; \
  555. } \
  556. }
  557. #define _JumpIfErrorStr2(hr, label, pszMessage, pwszData, hrquiet) \
  558. { \
  559. if (S_OK != (hr)) \
  560. { \
  561. DBGERRORPRINTLINESTR2((pszMessage), (pwszData), (hr), (hrquiet)); \
  562. goto label; \
  563. } \
  564. }
  565. #define _JumpIfErrorStr3(hr, label, pszMessage, pwszData, hrquiet, hrquiet2) \
  566. { \
  567. if (S_OK != (hr)) \
  568. { \
  569. if ((hrquiet2) != (hr)) \
  570. { \
  571. DBGERRORPRINTLINESTR2((pszMessage), (pwszData), (hr), (hrquiet)); \
  572. } \
  573. goto label; \
  574. } \
  575. }
  576. #define _JumpIfErrorStr4(hr, label, pszMessage, pwszData, hrquiet, hrquiet2, hrquiet3) \
  577. { \
  578. if (S_OK != (hr)) \
  579. { \
  580. if ((hrquiet2) != (hr) && (hrquiet3) != (hr)) \
  581. { \
  582. DBGERRORPRINTLINESTR2((pszMessage), (pwszData), (hr), (hrquiet)); \
  583. } \
  584. goto label; \
  585. } \
  586. }
  587. #define _JumpIfWin32Error(err, label, pszMessage) \
  588. { \
  589. if (ERROR_SUCCESS != (err)) \
  590. { \
  591. hr = HRESULT_FROM_WIN32((err)); \
  592. DBGERRORPRINTLINE((pszMessage), hr); \
  593. goto label; \
  594. } \
  595. }
  596. #define _JumpIfErrorNotSpecific(hr, label, pszMessage, hrquiet) \
  597. { \
  598. if (S_OK != (hr)) \
  599. { \
  600. DBGERRORPRINTLINE2((pszMessage), (hr), (hrquiet)); \
  601. if ((hrquiet) != (hr)) \
  602. { \
  603. goto label; \
  604. } \
  605. } \
  606. }
  607. #define _JumpIfAllocFailed(ptr, label) \
  608. { \
  609. if ((ptr) == NULL) \
  610. { \
  611. hr = E_OUTOFMEMORY; \
  612. DBGERRORPRINTLINE("allocation error", (hr)); \
  613. goto label; \
  614. } \
  615. }
  616. #define Add2Ptr(pb, cb) ((VOID *) ((BYTE *) (pb) + (ULONG_PTR) (cb)))
  617. #define Add2ConstPtr(pb, cb) \
  618. ((VOID const *) ((BYTE const *) (pb) + (ULONG_PTR) (cb)))
  619. #define WSZARRAYSIZE(a) csWSZARRAYSIZE(a, _TSZARRAYSIZE(a))
  620. #define SZARRAYSIZE(a) csSZARRAYSIZE(a, _TSZARRAYSIZE(a))
  621. #ifdef UNICODE
  622. #define TSZARRAYSIZE(a) WSZARRAYSIZE(a)
  623. #else
  624. #define TSZARRAYSIZE(a) SZARRAYSIZE(a)
  625. #endif
  626. #if DBG_CERTSRV
  627. __inline DWORD
  628. csWSZARRAYSIZE(
  629. IN WCHAR const *pwsz,
  630. IN DWORD cwc)
  631. {
  632. CSASSERT(wcslen(pwsz) == cwc);
  633. return(cwc);
  634. }
  635. __inline DWORD
  636. csSZARRAYSIZE(
  637. IN CHAR const *psz,
  638. IN DWORD cch)
  639. {
  640. CSASSERT(strlen(psz) == cch);
  641. return(cch);
  642. }
  643. #else
  644. #define csWSZARRAYSIZE(pwsz, cwc) (cwc)
  645. #define csSZARRAYSIZE(psz, cch) (cch)
  646. #endif // DBG_CERTSRV
  647. //
  648. // VOID
  649. // InitializeListHead(
  650. // PLIST_ENTRY ListHead
  651. // );
  652. //
  653. #define InitializeListHead(ListHead) (\
  654. (ListHead)->Flink = (ListHead)->Blink = (ListHead))
  655. //
  656. // VOID
  657. // InsertTailList(
  658. // PLIST_ENTRY ListHead,
  659. // PLIST_ENTRY Entry
  660. // );
  661. //
  662. #define InsertTailList(ListHead,Entry) {\
  663. PLIST_ENTRY _EX_Blink;\
  664. PLIST_ENTRY _EX_ListHead;\
  665. _EX_ListHead = (ListHead);\
  666. _EX_Blink = _EX_ListHead->Blink;\
  667. (Entry)->Flink = _EX_ListHead;\
  668. (Entry)->Blink = _EX_Blink;\
  669. _EX_Blink->Flink = (Entry);\
  670. _EX_ListHead->Blink = (Entry);\
  671. }
  672. //
  673. // VOID
  674. // RemoveEntryList(
  675. // PLIST_ENTRY Entry
  676. // );
  677. //
  678. #define RemoveEntryList(Entry) {\
  679. PLIST_ENTRY _EX_Blink;\
  680. PLIST_ENTRY _EX_Flink;\
  681. _EX_Flink = (Entry)->Flink;\
  682. _EX_Blink = (Entry)->Blink;\
  683. _EX_Blink->Flink = _EX_Flink;\
  684. _EX_Flink->Blink = _EX_Blink;\
  685. }
  686. #endif // __CS_H__