celib.h 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. /**
  2. * This file has no copyright assigned and is placed in the Public Domain.
  3. * This file is part of the mingw-w64 runtime package.
  4. * No warranty is given; refer to the file DISCLAIMER.PD within this package.
  5. */
  6. #ifndef __CELIB_H__
  7. #define __CELIB_H__
  8. #include <stdio.h>
  9. #define CENCODEMAX (64 *1024)
  10. #define GETBIT(pb,i) ((pb)[(i) / 8] & (1 << ((i) % 8)))
  11. #define SETBIT(pb,i) ((pb)[(i) / 8] |= (1 << ((i) % 8)))
  12. #define CLEARBIT(pb,i) ((pb)[(i) / 8] &= ~(1 << ((i) % 8)))
  13. #define BITSTOBYTES(b) ((int)(((b) + 7) / 8))
  14. #define ceCASIGN_KEY_USAGE (CERT_KEY_CERT_SIGN_KEY_USAGE | CERT_DIGITAL_SIGNATURE_KEY_USAGE | CERT_CRL_SIGN_KEY_USAGE)
  15. #define ARRAYSIZE(a) (sizeof(a)/sizeof((a)[0]))
  16. #define WSZARRAYSIZE(a) ((sizeof(a)/sizeof((a)[0])) - 1)
  17. #define wszCERTENROLLSHAREPATH L"CertSrv\\CertEnroll"
  18. #define cwcHRESULTSTRING 40
  19. #define cwcDWORDSPRINTF (1 + 10 + 1)
  20. #define SAFE_SUBTRACT_POINTERS(p1,p2) (assert(sizeof((*p1))==sizeof(*(p2))),(DWORD)((p1) - (p2)))
  21. #define printf Use_wprintf_Instead_Of_printf
  22. #define _LeaveError(hr,pszMessage) _LeaveErrorStr2((hr),(pszMessage),NULL,S_OK)
  23. #define _LeaveError2(hr,pszMessage,hr2) _LeaveErrorStr2((hr),(pszMessage),NULL,(hr2))
  24. #define _LeaveErrorStr(hr,pszMessage,pwszData) _LeaveErrorStr2((hr),(pszMessage),(pwszData),S_OK)
  25. #define _LeaveErrorStr2(hr,pszMessage,pwszData,hr2) { ceERRORPRINTLINESTR((pszMessage),(pwszData),(hr)); __leave; }
  26. #define _LeaveIfError(hr,pszMessage) _LeaveIfErrorStr2((hr),(pszMessage),NULL,S_OK)
  27. #define _LeaveIfError2(hr,pszMessage,hr2) _LeaveIfErrorStr2((hr),(pszMessage),NULL,(hr2))
  28. #define _LeaveIfErrorStr(hr,pszMessage,pwszData) _LeaveIfErrorStr2((hr),(pszMessage),(pwszData),S_OK)
  29. #define _LeaveIfErrorStr2(hr,pszMessage,pwszData,hr2) { if (S_OK!=(hr)) { ceERRORPRINTLINESTR((pszMessage),(pwszData),(hr)); __leave; } }
  30. #define _PrintErrorStr(hr,pszMessage,pwsz) ceERRORPRINTLINESTR((pszMessage),(pwsz),(hr))
  31. #define _PrintErrorStr2(hr,pszMessage,pwsz,hr2) _PrintErrorStr((hr),(pszMessage),(pwsz))
  32. #define _PrintError2(hr,pszMessage,hr2) _PrintErrorStr((hr),(pszMessage),NULL)
  33. #define _PrintError(hr,pszMessage) _PrintErrorStr((hr),(pszMessage),NULL)
  34. #define _PrintIfErrorStr(hr,pszMessage,pwsz) { if (S_OK!=(hr)) { ceERRORPRINTLINESTR((pszMessage),(pwsz),(hr)); } }
  35. #define _PrintIfErrorStr2(hr,pszMessage,pwsz,hr2) _PrintIfErrorStr((hr),(pszMessage),(pwsz))
  36. #define _PrintIfError2(hr,pszMessage,hr2) _PrintIfErrorStr((hr),(pszMessage),NULL)
  37. #define _PrintIfError(hr,pszMessage) _PrintIfErrorStr((hr),(pszMessage),NULL)
  38. #define _JumpErrorStr(hr,label,pszMessage,pwsz) _JumpError((hr),label,(pszMessage))
  39. #define _JumpError(hr,label,pszMessage) { ceERRORPRINTLINESTR((pszMessage),NULL,(hr)); goto label; }
  40. #define _JumpIfErrorStr(hr,label,pszMessage,pwsz) { if (S_OK!=(hr)) { ceERRORPRINTLINESTR((pszMessage),(pwsz),(hr)); goto label; } }
  41. #define _JumpIfErrorStr2(hr,label,pszMessage,pwsz,hr2) _JumpIfErrorStr((hr),label,(pszMessage),NULL)
  42. #define _JumpIfError2(hr,label,pszMessage,hr2) _JumpIfErrorStr((hr),label,(pszMessage),NULL)
  43. #define _JumpIfError(hr,label,pszMessage) _JumpIfErrorStr((hr),label,(pszMessage),NULL)
  44. #define ceERRORPRINTLINE(pszMessage,hr) ceErrorPrintLine(__FILE__,__LINE__,(pszMessage),NULL,(hr))
  45. #define ceERRORPRINTLINESTR(pszMessage,pwszData,hr) ceErrorPrintLine(__FILE__,__LINE__,(pszMessage),(pwszData),(hr))
  46. #define DBGPRINT(a) ceDbgPrintf a
  47. int WINAPIV ceDbgPrintf(WINBOOL fDebug,char const *pszfmt,...);
  48. VOID ceErrorPrintLine(char const *pszFile,DWORD line,char const *pszMessage,WCHAR const *pwszData,HRESULT hr);
  49. HRESULT ceHLastError(VOID);
  50. HRESULT ceHError(HRESULT hr);
  51. #define chLBRACE '{'
  52. #define chRBRACE '}'
  53. #define szLBRACE "{"
  54. #define szRBRACE "}"
  55. #define wcLBRACE L'{'
  56. #define wcRBRACE L'}'
  57. #define wszLBRACE L"{"
  58. #define wszRBRACE L"}"
  59. #define chLPAREN '('
  60. #define chRPAREN ')'
  61. #define szLPAREN "("
  62. #define szRPAREN ")"
  63. #define wcLPAREN L'('
  64. #define wcRPAREN L')'
  65. #define wszLPAREN L"("
  66. #define wszRPAREN L")"
  67. #define CVT_WEEKS (7 *CVT_DAYS)
  68. #define CVT_DAYS (24 *CVT_HOURS)
  69. #define CVT_HOURS (60 *CVT_MINUTES)
  70. #define CVT_MINUTES (60 *CVT_SECONDS)
  71. #define CVT_SECONDS (1)
  72. #define CVT_BASE (1000 *1000 *10)
  73. enum ENUM_PERIOD {
  74. ENUM_PERIOD_INVALID = -1,ENUM_PERIOD_SECONDS = 0,ENUM_PERIOD_MINUTES,ENUM_PERIOD_HOURS,ENUM_PERIOD_DAYS,ENUM_PERIOD_WEEKS,
  75. ENUM_PERIOD_MONTHS,ENUM_PERIOD_YEARS
  76. };
  77. typedef struct _LLFILETIME {
  78. __C89_NAMELESS union {
  79. LONGLONG ll;
  80. FILETIME ft;
  81. };
  82. } LLFILETIME;
  83. static __inline VOID ceAddToFileTime(FILETIME *pft,LONGLONG ll) {
  84. LLFILETIME llft;
  85. llft.ft = *pft;
  86. llft.ll += ll;
  87. *pft = llft.ft;
  88. }
  89. static __inline LONGLONG ceSubtractFileTimes(FILETIME const *pft1,FILETIME const *pft2) {
  90. LLFILETIME llft1;
  91. LLFILETIME llft2;
  92. llft1.ft = *pft1;
  93. llft2.ft = *pft2;
  94. return(llft1.ll - llft2.ll);
  95. }
  96. HRESULT ceMakeExprDate(DATE *pDate,LONG lDelta,enum ENUM_PERIOD enumPeriod);
  97. HRESULT ceTranslatePeriodUnits(WCHAR const *pwszPeriod,LONG lCount,enum ENUM_PERIOD *penumPeriod,LONG *plCount);
  98. WCHAR const *ceGetOIDNameA(char const *pszObjId);
  99. WCHAR const *ceGetOIDName(WCHAR const *pwszObjId);
  100. WINBOOL ceDecodeObject(DWORD dwEncodingType,LPCSTR lpszStructType,BYTE const *pbEncoded,DWORD cbEncoded,WINBOOL fCoTaskMemAlloc,VOID **ppvStructInfo,DWORD *pcbStructInfo);
  101. WINBOOL ceEncodeObject(DWORD dwEncodingType,LPCSTR lpszStructType,VOID const *pvStructInfo,DWORD dwFlags,WINBOOL fCoTaskMemAlloc,BYTE **ppbEncoded,DWORD *pcbEncoded);
  102. WCHAR *ceDuplicateString(WCHAR const *pwsz);
  103. HRESULT ceDupString(WCHAR const *pwszIn,WCHAR **ppwszOut);
  104. WINBOOL ceConvertWszToSz(char **ppsz,WCHAR const *pwc,LONG cb);
  105. WINBOOL ceConvertWszToBstr(BSTR *pbstr,WCHAR const *pwc,LONG cb);
  106. WINBOOL ceConvertSzToWsz(WCHAR **ppwsz,char const *pch,LONG cch);
  107. WINBOOL ceConvertSzToBstr(BSTR *pbstr,CHAR const *pch,LONG cch);
  108. VOID ceFreeBstr(BSTR *pstr);
  109. HRESULT ceDateToFileTime(DATE const *pDate,FILETIME *pft);
  110. HRESULT ceFileTimeToDate(FILETIME const *pft,DATE *pDate);
  111. HRESULT ceVerifyObjIdA(char const *pszObjId);
  112. HRESULT ceVerifyObjId(WCHAR const *pwszObjId);
  113. HRESULT ceVerifyAltNameString(LONG NameChoice,BSTR strName);
  114. HRESULT ceDispatchSetErrorInfo(HRESULT hrError,WCHAR const *pwszDescription,WCHAR const *pwszProgId,IID const *piid);
  115. VOID ceInitErrorMessageText(HMODULE hMod,DWORD idsUnexpected,DWORD idsUnknownErrorCode);
  116. WCHAR const *ceGetErrorMessageText(HRESULT hr,WINBOOL fHResultString);
  117. WCHAR const *ceGetErrorMessageTextEx(HRESULT hr,WINBOOL fHResultString,WCHAR const *const *papwszInsertionText);
  118. WCHAR const *ceHResultToString(WCHAR *awchr,HRESULT hr);
  119. #define cwcFILENAMESUFFIXMAX 20
  120. #define cwcSUFFIXMAX (1 + 5 + 1)
  121. #define wszFCSAPARM_SERVERDNSNAME L"%1"
  122. #define wszFCSAPARM_SERVERSHORTNAME L"%2"
  123. #define wszFCSAPARM_SANITIZEDCANAME L"%3"
  124. #define wszFCSAPARM_CERTFILENAMESUFFIX L"%4"
  125. #define wszFCSAPARM_DOMAINDN L"%5"
  126. #define wszFCSAPARM_CONFIGDN L"%6"
  127. #define wszFCSAPARM_SANITIZEDCANAMEHASH L"%7"
  128. #define wszFCSAPARM_CRLFILENAMESUFFIX L"%8"
  129. #define wszFCSAPARM_CRLDELTAFILENAMESUFFIX L"%9"
  130. #define wszFCSAPARM_DSCRLATTRIBUTE L"%10"
  131. #define wszFCSAPARM_DSCACERTATTRIBUTE L"%11"
  132. #define wszFCSAPARM_DSUSERCERTATTRIBUTE L"%12"
  133. #define wszFCSAPARM_DSKRACERTATTRIBUTE L"%13"
  134. #define wszFCSAPARM_DSCROSSCERTPAIRATTRIBUTE L"%14"
  135. HRESULT ceFormatCertsrvStringArray(WINBOOL fURL,LPCWSTR pwszServerName_p1_2,LPCWSTR pwszSanitizedName_p3_7,DWORD iCert_p4,DWORD iCertTarget_p4,LPCWSTR pwszDomainDN_p5,LPCWSTR pwszConfigDN_p6,DWORD iCRL_p8,WINBOOL fDeltaCRL_p9,WINBOOL fDSAttrib_p10_11,DWORD cStrings,LPCWSTR *apwszStringsIn,LPWSTR *apwszStringsOut);
  136. HRESULT ceBuildPathAndExt(WCHAR const *pwszDir,WCHAR const *pwszFile,WCHAR const *pwszExt,WCHAR **ppwszPath);
  137. HRESULT ceInternetCanonicalizeUrl(WCHAR const *pwszIn,WCHAR **ppwszOut);
  138. int ceWtoI(WCHAR const *pwszDigitString,WINBOOL *pfValid);
  139. int celstrcmpiL(WCHAR const *pwsz1,WCHAR const *pwsz2);
  140. HRESULT ceIsConfigLocal(WCHAR const *pwszConfig,WCHAR **ppwszMachine,WINBOOL *pfLocal);
  141. #endif