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.

438 lines
9.8 KiB

  1. //+-------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. //
  5. // Copyright (C) Microsoft Corporation, 1995 - 1999
  6. //
  7. // File: celib.h
  8. //
  9. // Contents: helper functions
  10. //
  11. //--------------------------------------------------------------------------
  12. #ifndef __CELIB_H__
  13. #define __CELIB_H__
  14. #include <stdio.h>
  15. #define CENCODEMAX (64 * 1024)
  16. // Bitmap manipulation routines. Fetch or set a bit, given a base and index.
  17. #define GETBIT(pb, i) ((pb)[(i) / 8] & (1 << ((i) % 8)))
  18. #define SETBIT(pb, i) ((pb)[(i) / 8] |= (1 << ((i) % 8)))
  19. #define CLEARBIT(pb, i) ((pb)[(i) / 8] &= ~(1 << ((i) % 8)))
  20. #define BITSTOBYTES(b) ((int)(((b) + 7) / 8))
  21. #define ceCASIGN_KEY_USAGE \
  22. (CERT_KEY_CERT_SIGN_KEY_USAGE | CERT_DIGITAL_SIGNATURE_KEY_USAGE | \
  23. CERT_CRL_SIGN_KEY_USAGE)
  24. // Size of a fixed array:
  25. #define ARRAYSIZE(a) (sizeof(a)/sizeof((a)[0]))
  26. // wcslen of a static string:
  27. #define WSZARRAYSIZE(a) ((sizeof(a)/sizeof((a)[0])) - 1)
  28. #define wszCERTENROLLSHAREPATH L"CertSrv\\CertEnroll"
  29. #define cwcHRESULTSTRING 40
  30. #define cwcDWORDSPRINTF (1 + 10 + 1) // DWORD "%d" w/sign & '\0'
  31. #define SAFE_SUBTRACT_POINTERS(p1, p2) \
  32. (assert(sizeof((*p1)) == sizeof(*(p2))), (DWORD)((p1) - (p2)))
  33. #define printf Use_wprintf_Instead_Of_printf
  34. #define _LeaveError(hr, pszMessage) \
  35. _LeaveErrorStr2((hr), (pszMessage), NULL, S_OK)
  36. #define _LeaveError2(hr, pszMessage, hr2) \
  37. _LeaveErrorStr2((hr), (pszMessage), NULL, (hr2))
  38. #define _LeaveErrorStr(hr, pszMessage, pwszData) \
  39. _LeaveErrorStr2((hr), (pszMessage), (pwszData), S_OK)
  40. #define _LeaveErrorStr2(hr, pszMessage, pwszData, hr2) \
  41. { \
  42. ceERRORPRINTLINESTR((pszMessage), (pwszData), (hr)); \
  43. __leave; \
  44. }
  45. #define _LeaveIfError(hr, pszMessage) \
  46. _LeaveIfErrorStr2((hr), (pszMessage), NULL, S_OK)
  47. #define _LeaveIfError2(hr, pszMessage, hr2) \
  48. _LeaveIfErrorStr2((hr), (pszMessage), NULL, (hr2))
  49. #define _LeaveIfErrorStr(hr, pszMessage, pwszData) \
  50. _LeaveIfErrorStr2((hr), (pszMessage), (pwszData), S_OK)
  51. #define _LeaveIfErrorStr2(hr, pszMessage, pwszData, hr2) \
  52. { \
  53. if (S_OK != (hr)) \
  54. { \
  55. ceERRORPRINTLINESTR((pszMessage), (pwszData), (hr)); \
  56. __leave; \
  57. } \
  58. }
  59. #define _PrintErrorStr(hr, pszMessage, pwsz) \
  60. ceERRORPRINTLINESTR((pszMessage), (pwsz), (hr))
  61. #define _PrintErrorStr2(hr, pszMessage, pwsz, hr2) \
  62. _PrintErrorStr((hr), (pszMessage), (pwsz))
  63. #define _PrintError2(hr, pszMessage, hr2) \
  64. _PrintErrorStr((hr), (pszMessage), NULL)
  65. #define _PrintError(hr, pszMessage) \
  66. _PrintErrorStr((hr), (pszMessage), NULL)
  67. #define _PrintIfErrorStr(hr, pszMessage, pwsz) \
  68. { \
  69. if (S_OK != (hr)) \
  70. { \
  71. ceERRORPRINTLINESTR((pszMessage), (pwsz), (hr)); \
  72. } \
  73. }
  74. #define _PrintIfErrorStr2(hr, pszMessage, pwsz, hr2) \
  75. _PrintIfErrorStr((hr), (pszMessage), (pwsz))
  76. #define _PrintIfError2(hr, pszMessage, hr2) \
  77. _PrintIfErrorStr((hr), (pszMessage), NULL)
  78. #define _PrintIfError(hr, pszMessage) \
  79. _PrintIfErrorStr((hr), (pszMessage), NULL)
  80. #define _JumpErrorStr(hr, label, pszMessage, pwsz) \
  81. _JumpError((hr), label, (pszMessage))
  82. #define _JumpError(hr, label, pszMessage) \
  83. { \
  84. ceERRORPRINTLINESTR((pszMessage), NULL, (hr)); \
  85. goto label; \
  86. }
  87. #define _JumpIfErrorStr(hr, label, pszMessage, pwsz) \
  88. { \
  89. if (S_OK != (hr)) \
  90. { \
  91. ceERRORPRINTLINESTR((pszMessage), (pwsz), (hr)); \
  92. goto label; \
  93. } \
  94. }
  95. #define _JumpIfErrorStr2(hr, label, pszMessage, pwsz, hr2) \
  96. _JumpIfErrorStr((hr), label, (pszMessage), NULL)
  97. #define _JumpIfError2(hr, label, pszMessage, hr2) \
  98. _JumpIfErrorStr((hr), label, (pszMessage), NULL)
  99. #define _JumpIfError(hr, label, pszMessage) \
  100. _JumpIfErrorStr((hr), label, (pszMessage), NULL)
  101. #define ceERRORPRINTLINE(pszMessage, hr) \
  102. ceErrorPrintLine(__FILE__, __LINE__, (pszMessage), NULL, (hr))
  103. #define ceERRORPRINTLINESTR(pszMessage, pwszData, hr) \
  104. ceErrorPrintLine(__FILE__, __LINE__, (pszMessage), (pwszData), (hr))
  105. #define DBGPRINT(a) ceDbgPrintf a
  106. int WINAPIV ceDbgPrintf(BOOL fDebug, char const *pszfmt, ...);
  107. VOID
  108. ceErrorPrintLine(
  109. IN char const *pszFile,
  110. IN DWORD line,
  111. IN char const *pszMessage,
  112. IN WCHAR const *pwszData,
  113. IN HRESULT hr);
  114. HRESULT
  115. ceHLastError(VOID);
  116. HRESULT
  117. ceHError(
  118. IN HRESULT hr);
  119. #define chLBRACE '{'
  120. #define chRBRACE '}'
  121. #define szLBRACE "{"
  122. #define szRBRACE "}"
  123. #define wcLBRACE L'{'
  124. #define wcRBRACE L'}'
  125. #define wszLBRACE L"{"
  126. #define wszRBRACE L"}"
  127. #define chLPAREN '('
  128. #define chRPAREN ')'
  129. #define szLPAREN "("
  130. #define szRPAREN ")"
  131. #define wcLPAREN L'('
  132. #define wcRPAREN L')'
  133. #define wszLPAREN L"("
  134. #define wszRPAREN L")"
  135. // Constants chosen to avoid DWORD overflow:
  136. #define CVT_WEEKS (7 * CVT_DAYS)
  137. #define CVT_DAYS (24 * CVT_HOURS)
  138. #define CVT_HOURS (60 * CVT_MINUTES)
  139. #define CVT_MINUTES (60 * CVT_SECONDS)
  140. #define CVT_SECONDS (1)
  141. #define CVT_BASE (1000 * 1000 * 10)
  142. enum ENUM_PERIOD
  143. {
  144. ENUM_PERIOD_INVALID = -1,
  145. ENUM_PERIOD_SECONDS = 0,
  146. ENUM_PERIOD_MINUTES,
  147. ENUM_PERIOD_HOURS,
  148. ENUM_PERIOD_DAYS,
  149. ENUM_PERIOD_WEEKS,
  150. ENUM_PERIOD_MONTHS,
  151. ENUM_PERIOD_YEARS
  152. };
  153. typedef struct _LLFILETIME
  154. {
  155. union {
  156. LONGLONG ll;
  157. FILETIME ft;
  158. };
  159. } LLFILETIME;
  160. __inline VOID
  161. ceAddToFileTime(
  162. IN OUT FILETIME *pft,
  163. IN LONGLONG ll)
  164. {
  165. LLFILETIME llft;
  166. llft.ft = *pft;
  167. llft.ll += ll;
  168. *pft = llft.ft;
  169. }
  170. __inline LONGLONG
  171. ceSubtractFileTimes(
  172. IN FILETIME const *pft1,
  173. IN FILETIME const *pft2)
  174. {
  175. LLFILETIME llft1;
  176. LLFILETIME llft2;
  177. llft1.ft = *pft1;
  178. llft2.ft = *pft2;
  179. return(llft1.ll - llft2.ll);
  180. }
  181. HRESULT
  182. ceMakeExprDate(
  183. IN OUT DATE *pDate,
  184. IN LONG lDelta,
  185. IN enum ENUM_PERIOD enumPeriod);
  186. HRESULT
  187. ceTranslatePeriodUnits(
  188. IN WCHAR const *pwszPeriod,
  189. IN LONG lCount,
  190. OUT enum ENUM_PERIOD *penumPeriod,
  191. OUT LONG *plCount);
  192. WCHAR const *
  193. ceGetOIDNameA(
  194. IN char const *pszObjId);
  195. WCHAR const *
  196. ceGetOIDName(
  197. IN WCHAR const *pwszObjId);
  198. BOOL
  199. ceDecodeObject(
  200. IN DWORD dwEncodingType,
  201. IN LPCSTR lpszStructType,
  202. IN BYTE const *pbEncoded,
  203. IN DWORD cbEncoded,
  204. IN BOOL fCoTaskMemAlloc,
  205. OUT VOID **ppvStructInfo,
  206. OUT DWORD *pcbStructInfo);
  207. BOOL
  208. ceEncodeObject(
  209. DWORD dwEncodingType,
  210. IN LPCSTR lpszStructType,
  211. IN VOID const *pvStructInfo,
  212. IN DWORD dwFlags,
  213. IN BOOL fCoTaskMemAlloc,
  214. OUT BYTE **ppbEncoded,
  215. OUT DWORD *pcbEncoded);
  216. WCHAR *
  217. ceDuplicateString(
  218. IN WCHAR const *pwsz);
  219. HRESULT
  220. ceDupString(
  221. IN WCHAR const *pwszIn,
  222. OUT WCHAR **ppwszOut);
  223. BOOL
  224. ceConvertWszToSz(
  225. OUT char **ppsz,
  226. IN WCHAR const *pwc,
  227. IN LONG cb);
  228. BOOL
  229. ceConvertWszToBstr(
  230. OUT BSTR *pbstr,
  231. IN WCHAR const *pwc,
  232. IN LONG cb);
  233. BOOL
  234. ceConvertSzToWsz(
  235. OUT WCHAR **ppwsz,
  236. IN char const *pch,
  237. IN LONG cch);
  238. BOOL
  239. ceConvertSzToBstr(
  240. OUT BSTR *pbstr,
  241. IN CHAR const *pch,
  242. IN LONG cch);
  243. VOID
  244. ceFreeBstr(
  245. IN OUT BSTR *pstr);
  246. HRESULT
  247. ceDateToFileTime(
  248. IN DATE const *pDate,
  249. OUT FILETIME *pft);
  250. HRESULT
  251. ceFileTimeToDate(
  252. IN FILETIME const *pft,
  253. OUT DATE *pDate);
  254. HRESULT
  255. ceVerifyObjIdA(
  256. IN char const *pszObjId);
  257. HRESULT
  258. ceVerifyObjId(
  259. IN WCHAR const *pwszObjId);
  260. HRESULT
  261. ceVerifyAltNameString(
  262. IN LONG NameChoice,
  263. IN BSTR strName);
  264. HRESULT
  265. ceDispatchSetErrorInfo(
  266. IN HRESULT hrError,
  267. IN WCHAR const *pwszDescription,
  268. OPTIONAL IN WCHAR const *pwszProgId,
  269. OPTIONAL IN IID const *piid);
  270. VOID
  271. ceInitErrorMessageText(
  272. IN HMODULE hMod,
  273. IN DWORD idsUnexpected,
  274. IN DWORD idsUnknownErrorCode); // L"Error %ws %ws"
  275. WCHAR const *
  276. ceGetErrorMessageText(
  277. IN HRESULT hr,
  278. IN BOOL fHResultString);
  279. WCHAR const *
  280. ceGetErrorMessageTextEx(
  281. IN HRESULT hr,
  282. IN BOOL fHResultString,
  283. IN OPTIONAL WCHAR const * const *papwszInsertionText);
  284. WCHAR const *
  285. ceHResultToString(
  286. IN OUT WCHAR *awchr,
  287. IN HRESULT hr);
  288. #define cwcFILENAMESUFFIXMAX 20
  289. #define cwcSUFFIXMAX (1 + 5 + 1) // five decimal digits plus parentheses
  290. #define wszFCSAPARM_SERVERDNSNAME L"%1"
  291. #define wszFCSAPARM_SERVERSHORTNAME L"%2"
  292. #define wszFCSAPARM_SANITIZEDCANAME L"%3"
  293. #define wszFCSAPARM_CERTFILENAMESUFFIX L"%4"
  294. #define wszFCSAPARM_DOMAINDN L"%5"
  295. #define wszFCSAPARM_CONFIGDN L"%6"
  296. #define wszFCSAPARM_SANITIZEDCANAMEHASH L"%7"
  297. #define wszFCSAPARM_CRLFILENAMESUFFIX L"%8"
  298. #define wszFCSAPARM_CRLDELTAFILENAMESUFFIX L"%9"
  299. #define wszFCSAPARM_DSCRLATTRIBUTE L"%10"
  300. #define wszFCSAPARM_DSCACERTATTRIBUTE L"%11"
  301. #define wszFCSAPARM_DSUSERCERTATTRIBUTE L"%12"
  302. #define wszFCSAPARM_DSKRACERTATTRIBUTE L"%13"
  303. #define wszFCSAPARM_DSCROSSCERTPAIRATTRIBUTE L"%14"
  304. HRESULT
  305. ceFormatCertsrvStringArray(
  306. IN BOOL fURL,
  307. IN LPCWSTR pwszServerName_p1_2,
  308. IN LPCWSTR pwszSanitizedName_p3_7,
  309. IN DWORD iCert_p4,
  310. IN DWORD iCertTarget_p4,
  311. IN LPCWSTR pwszDomainDN_p5,
  312. IN LPCWSTR pwszConfigDN_p6,
  313. IN DWORD iCRL_p8,
  314. IN BOOL fDeltaCRL_p9,
  315. IN BOOL fDSAttrib_p10_11,
  316. IN DWORD cStrings,
  317. IN LPCWSTR *apwszStringsIn,
  318. OUT LPWSTR *apwszStringsOut);
  319. HRESULT
  320. ceBuildPathAndExt(
  321. IN WCHAR const *pwszDir,
  322. IN WCHAR const *pwszFile,
  323. OPTIONAL IN WCHAR const *pwszExt,
  324. OUT WCHAR **ppwszPath);
  325. HRESULT
  326. ceInternetCanonicalizeUrl(
  327. IN WCHAR const *pwszIn,
  328. OUT WCHAR **ppwszOut);
  329. int
  330. ceWtoI(
  331. IN WCHAR const *pwszDigitString,
  332. OUT BOOL *pfValid);
  333. int
  334. celstrcmpiL(
  335. IN WCHAR const *pwsz1,
  336. IN WCHAR const *pwsz2);
  337. HRESULT
  338. ceIsConfigLocal(
  339. IN WCHAR const *pwszConfig,
  340. OPTIONAL OUT WCHAR **ppwszMachine,
  341. OUT BOOL *pfLocal);
  342. #endif // __CELIB_H__