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.

460 lines
18 KiB

  1. //+-------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. //
  5. // Copyright (C) Microsoft Corporation, 1997 - 1999
  6. //
  7. // File: demand.h
  8. //
  9. //--------------------------------------------------------------------------
  10. /*
  11. ** d e m a n d . h
  12. **
  13. ** Purpose: create an intelligent method of defer loading functions
  14. **
  15. ** Creators: jimsch, brimo, t-erikne
  16. ** Created: 5/15/97
  17. **
  18. ** Copyright (C) Microsoft Corp. 1997
  19. */
  20. #if _MSC_VER > 1000
  21. #pragma once
  22. #endif
  23. #ifndef __DEMAND_H
  24. #define __DEMAND_H
  25. #ifndef MAC
  26. //
  27. // IF YOU #INCLUDE A FILE HERE YOU PROBABLY ARE MAKING A MISTAKE.
  28. // THIS FILE IS INCLUDED BY LOTS OF PEOPLE. THINK THRICE
  29. // BEFORE #INCLUDING *ANYTHING* HERE. MAKE GOOD USE
  30. // OF FORWARD REFS INSTEAD.
  31. //
  32. #ifdef IMPLEMENT_LOADER_FUNCTIONS
  33. #define USE_CRITSEC
  34. #define LOADER_FUNCTION(ret, name, args1, args2, err, dll) \
  35. typedef ret (WINAPI * TYP_##name) args1; \
  36. extern TYP_##name VAR_##name; \
  37. ret WINAPI LOADER_##name args1 \
  38. { \
  39. if (!DemandLoad##dll()) return err; \
  40. return VAR_##name args2; \
  41. } \
  42. TYP_##name VAR_##name = LOADER_##name;
  43. #define LOADER_FUNCTION_VOID(ret, name, args1, args2, dll) \
  44. typedef ret (WINAPI * TYP_##name) args1; \
  45. extern TYP_##name VAR_##name; \
  46. ret WINAPI LOADER_##name args1 \
  47. { \
  48. if (!DemandLoad##dll()) return; \
  49. VAR_##name args2; \
  50. return; \
  51. } \
  52. TYP_##name VAR_##name = LOADER_##name;
  53. #if 0
  54. // my 1st attempt
  55. #define DemandLoadDLL_GENERATOR(fnsuffix, dllname, handle, procaddrlist) \
  56. BOOL DemandLoad##fnsuffix() \
  57. { \
  58. BOOL fRet = TRUE; \
  59. \
  60. Assert(fInit); \
  61. EnterCriticalSection(&cs); \
  62. \
  63. if (0 == handle) \
  64. { \
  65. handle = LoadLibrary(#dllname); \
  66. \
  67. if (0 == handle) \
  68. fRet = FALSE; \
  69. else \
  70. { \
  71. procaddrlist \
  72. } \
  73. } \
  74. \
  75. LeaveCriticalSection(&cs); \
  76. return fRet; \
  77. }
  78. #endif
  79. #else // !IMPLEMENT_LOADER_FUNCTIONS
  80. #define LOADER_FUNCTION(ret, name, args1, args2, err, dll) \
  81. typedef ret (WINAPI * TYP_##name) args1; \
  82. extern TYP_##name VAR_##name;
  83. #define LOADER_FUNCTION_VOID(ret, name, args1, args2, dll) \
  84. typedef ret (WINAPI * TYP_##name) args1; \
  85. extern TYP_##name VAR_##name;
  86. #if 0
  87. #define DemandLoadDLL_GENERATOR(fnsuffix, dllname, handle, procaddrlist) \
  88. BOOL DemandLoad##fnsuffix(void);
  89. #endif
  90. #endif // IMPLEMENT_LOADER_FUNCTIONS
  91. void InitDemandLoadedLibs();
  92. void FreeDemandLoadedLibs();
  93. /////////////////////////////////////
  94. // CRYPT32.DLL
  95. BOOL DemandLoadCrypt32(void);
  96. LOADER_FUNCTION( BOOL, CertFreeCertificateContext,
  97. (PCCERT_CONTEXT pCertContext),
  98. (pCertContext),
  99. FALSE, Crypt32)
  100. #define CertFreeCertificateContext VAR_CertFreeCertificateContext
  101. LOADER_FUNCTION( PCCERT_CONTEXT, CertDuplicateCertificateContext,
  102. (PCCERT_CONTEXT pCertContext),
  103. (pCertContext), NULL, Crypt32)
  104. #define CertDuplicateCertificateContext VAR_CertDuplicateCertificateContext
  105. LOADER_FUNCTION( PCCERT_CONTEXT, CertFindCertificateInStore,
  106. (HCERTSTORE hCertStore, DWORD dwCertEncodingType, DWORD dwFindFlags, DWORD dwFindType, const void *pvFindPara, PCCERT_CONTEXT pPrevCertContext),
  107. (hCertStore, dwCertEncodingType, dwFindFlags, dwFindType, pvFindPara, pPrevCertContext),
  108. NULL, Crypt32)
  109. #define CertFindCertificateInStore VAR_CertFindCertificateInStore
  110. LOADER_FUNCTION( BOOL, CertCloseStore,
  111. (HCERTSTORE hCertStore, DWORD dwFlags),
  112. (hCertStore, dwFlags),
  113. FALSE, Crypt32)
  114. #define CertCloseStore VAR_CertCloseStore
  115. LOADER_FUNCTION( HCERTSTORE, CertOpenStore,
  116. (LPCSTR lpszStoreProvider, DWORD dwEncodingType, HCRYPTPROV hCryptProv,
  117. DWORD dwFlags, const void *pvPara),
  118. (lpszStoreProvider, dwEncodingType, hCryptProv, dwFlags, pvPara),
  119. NULL, Crypt32)
  120. #define CertOpenStore VAR_CertOpenStore
  121. LOADER_FUNCTION( BOOL, CertGetCertificateContextProperty,
  122. (PCCERT_CONTEXT pCertContext, DWORD dwPropId, void *pvData, DWORD *pcbData),
  123. (pCertContext, dwPropId, pvData, pcbData),
  124. FALSE, Crypt32)
  125. #define CertGetCertificateContextProperty VAR_CertGetCertificateContextProperty
  126. LOADER_FUNCTION( BOOL, CertCompareCertificate,
  127. (DWORD dwCertEncodingType, PCERT_INFO pCertId1, PCERT_INFO pCertId2),
  128. (dwCertEncodingType, pCertId1, pCertId2),
  129. FALSE, Crypt32)
  130. #define CertCompareCertificate VAR_CertCompareCertificate
  131. LOADER_FUNCTION( PCCERT_CONTEXT, CertEnumCertificatesInStore,
  132. (HCERTSTORE hCertStore, PCCERT_CONTEXT pPrevCertContext),
  133. (hCertStore, pPrevCertContext),
  134. NULL, Crypt32)
  135. #define CertEnumCertificatesInStore VAR_CertEnumCertificatesInStore
  136. LOADER_FUNCTION( BOOL, CryptDecodeObject,
  137. (DWORD dwCertEncodingType, LPCSTR lpszStructType, const BYTE * pbEncoded,
  138. DWORD cbEncoded, DWORD dwFlags, void * pvStructInfo, DWORD * pcbStructInfo),
  139. (dwCertEncodingType, lpszStructType, pbEncoded, cbEncoded, dwFlags,
  140. pvStructInfo, pcbStructInfo),
  141. FALSE, Crypt32)
  142. #define CryptDecodeObject VAR_CryptDecodeObject
  143. LOADER_FUNCTION( PCERT_EXTENSION, CertFindExtension,
  144. (LPCSTR pszObjId, DWORD cExtensions, CERT_EXTENSION rgExtensions[]),
  145. (pszObjId, cExtensions, rgExtensions),
  146. NULL, Crypt32)
  147. #define CertFindExtension VAR_CertFindExtension
  148. LOADER_FUNCTION( BOOL, CryptFormatObject,
  149. (DWORD dwCertEncodingType, DWORD dwFormatType, DWORD dwFormatStrType,
  150. void * pFormatStruct, LPCSTR lpszStructType, const BYTE * pbEncoded,
  151. DWORD cbEncoded, void * pbFormat, DWORD * pcbFormat),
  152. (dwCertEncodingType, dwFormatType, dwFormatStrType, pFormatStruct,
  153. lpszStructType, pbEncoded, cbEncoded, pbFormat, pcbFormat),
  154. FALSE, Crypt32)
  155. #define CryptFormatObject VAR_CryptFormatObject
  156. LOADER_FUNCTION( DWORD, CertNameToStrW,
  157. (DWORD dwCertEncodingType, PCERT_NAME_BLOB pName, DWORD dwStrType,
  158. LPWSTR psz, DWORD csz),
  159. (dwCertEncodingType, pName, dwStrType, psz, csz),
  160. 0, Crypt32)
  161. #define CertNameToStrW VAR_CertNameToStrW
  162. LOADER_FUNCTION( DWORD, CertNameToStrA,
  163. (DWORD dwCertEncodingType, PCERT_NAME_BLOB pName, DWORD dwStrType,
  164. LPSTR psz, DWORD csz),
  165. (dwCertEncodingType, pName, dwStrType, psz, csz),
  166. 0, Crypt32)
  167. #define CertNameToStrA VAR_CertNameToStrA
  168. LOADER_FUNCTION( BOOL, CertStrToNameA,
  169. (DWORD dwCertEncodingType, LPCSTR pszX500, DWORD dwStrType, void *pvReserved,
  170. BYTE *pbEncoded, DWORD *pcbEncoded, LPCSTR *ppszError),
  171. (dwCertEncodingType, pszX500, dwStrType, pvReserved,
  172. pbEncoded, pcbEncoded, ppszError),
  173. FALSE, Crypt32)
  174. #define CertStrToNameA VAR_CertStrToNameA
  175. LOADER_FUNCTION( DWORD, CertRDNValueToStrW,
  176. (DWORD dwValueType, PCERT_RDN_VALUE_BLOB pValue, LPWSTR psz, DWORD csz),
  177. (dwValueType, pValue, psz, csz),
  178. 0, Crypt32)
  179. #define CertRDNValueToStrW VAR_CertRDNValueToStrW
  180. LOADER_FUNCTION( PCERT_RDN_ATTR, CertFindRDNAttr,
  181. (LPCSTR pszObjId, PCERT_NAME_INFO pName),
  182. (pszObjId, pName),
  183. NULL, Crypt32)
  184. #define CertFindRDNAttr VAR_CertFindRDNAttr
  185. LOADER_FUNCTION( BOOL, CryptRegisterOIDFunction,
  186. (DWORD dwEncodingType, LPCSTR pszFuncName, LPCSTR pszOID, LPCWSTR pwszDll,
  187. LPCSTR pszOverrideFuncName),
  188. (dwEncodingType, pszFuncName, pszOID, pwszDll, pszOverrideFuncName),
  189. FALSE, Crypt32)
  190. #define CryptRegisterOIDFunction VAR_CryptRegisterOIDFunction
  191. LOADER_FUNCTION( BOOL, CryptUnregisterOIDFunction,
  192. (DWORD dwEncodingType, LPCSTR pszFuncName, LPCSTR pszOID),
  193. (dwEncodingType, pszFuncName, pszOID),
  194. FALSE, Crypt32)
  195. #define CryptUnregisterOIDFunction VAR_CryptUnregisterOIDFunction
  196. LOADER_FUNCTION( BOOL, CertSetCertificateContextProperty,
  197. (PCCERT_CONTEXT pCertContext, DWORD dwPropId, DWORD dwFlags, const void * pvData),
  198. (pCertContext, dwPropId, dwFlags, pvData),
  199. FALSE, Crypt32)
  200. #define CertSetCertificateContextProperty VAR_CertSetCertificateContextProperty
  201. LOADER_FUNCTION( BOOL, CertVerifyCTLUsage,
  202. (DWORD dwEncodingType, DWORD dwSubjectType, void *pvSubject,
  203. PCTL_USAGE pSubjectUsage, DWORD dwFlags,
  204. PCTL_VERIFY_USAGE_PARA pVerifyUsagePara,
  205. PCTL_VERIFY_USAGE_STATUS pVerifyUsageStatus),
  206. (dwEncodingType, dwSubjectType, pvSubject, pSubjectUsage, dwFlags,
  207. pVerifyUsagePara, pVerifyUsageStatus),
  208. 0, Crypt32)
  209. #define CertVerifyCTLUsage VAR_CertVerifyCTLUsage
  210. LOADER_FUNCTION( PCCERT_CONTEXT, CertGetIssuerCertificateFromStore,
  211. (HCERTSTORE hCertStore, PCCERT_CONTEXT pSubjectContext,
  212. PCCERT_CONTEXT pPrevIssuerContext, DWORD *pdwFlags),
  213. (hCertStore, pSubjectContext, pPrevIssuerContext, pdwFlags),
  214. NULL, Crypt32)
  215. #define CertGetIssuerCertificateFromStore VAR_CertGetIssuerCertificateFromStore
  216. LOADER_FUNCTION( BOOL, CertFreeCTLContext,
  217. (PCCTL_CONTEXT pCtlContext),
  218. (pCtlContext),
  219. FALSE, Crypt32)
  220. #define CertFreeCTLContext VAR_CertFreeCTLContext
  221. LOADER_FUNCTION( BOOL, CertAddEncodedCTLToStore,
  222. (HCERTSTORE hCertStore, DWORD dwMsgAndCertEncodingType, const BYTE *pbCtlEncoded,
  223. DWORD cbCtlEncoded, DWORD dwAddDisposition, PCCTL_CONTEXT *ppCtlContext),
  224. (hCertStore, dwMsgAndCertEncodingType, pbCtlEncoded, cbCtlEncoded,
  225. dwAddDisposition, ppCtlContext),
  226. FALSE, Crypt32)
  227. #define CertAddEncodedCTLToStore VAR_CertAddEncodedCTLToStore
  228. LOADER_FUNCTION( BOOL, CryptMsgEncodeAndSignCTL,
  229. (DWORD dwMsgEncodingType, PCTL_INFO pCtlInfo, PCMSG_SIGNED_ENCODE_INFO pSignInfo,
  230. DWORD dwFlags, BYTE *pbEncoded, DWORD *pcbEncoded),
  231. (dwMsgEncodingType, pCtlInfo, pSignInfo, dwFlags, pbEncoded, pcbEncoded),
  232. FALSE, Crypt32)
  233. #define CryptMsgEncodeAndSignCTL VAR_CryptMsgEncodeAndSignCTL
  234. LOADER_FUNCTION( PCCTL_CONTEXT, CertFindCTLInStore,
  235. (HCERTSTORE hCertStore, DWORD dwMsgAndCertEncodingType, DWORD dwFindFlags,
  236. DWORD dwFindType, const void *pvFindPara, PCCTL_CONTEXT pPrevCtlContext),
  237. (hCertStore, dwMsgAndCertEncodingType, dwFindFlags,
  238. dwFindType, pvFindPara, pPrevCtlContext),
  239. NULL, Crypt32)
  240. #define CertFindCTLInStore VAR_CertFindCTLInStore
  241. LOADER_FUNCTION( PCCTL_CONTEXT, CryptSignAndEncodeCertificate,
  242. (HCRYPTPROV hCryptProv, DWORD dwKeySpec, DWORD dwCertEncodingType,
  243. LPCSTR lpszStructType, const void *pvStructInfo,
  244. PCRYPT_ALGORITHM_IDENTIFIER pSignatureAlgorithm,
  245. const void *pvHashAuxInfo, PBYTE pbEncoded, DWORD *pcbEncoded),
  246. (hCryptProv, dwKeySpec, dwCertEncodingType, lpszStructType,
  247. pvStructInfo, pSignatureAlgorithm, pvHashAuxInfo, pbEncoded,
  248. pcbEncoded),
  249. NULL, Crypt32)
  250. #define CryptSignAndEncodeCertificate VAR_CryptSignAndEncodeCertificate
  251. LOADER_FUNCTION( BOOL, CryptEncodeObject,
  252. (DWORD dwCertEncodingType, LPCSTR lpszStructType, const void *pvStructInfo,
  253. BYTE *pbEncoded, DWORD *pcbEncoded),
  254. (dwCertEncodingType, lpszStructType, pvStructInfo, pbEncoded,pcbEncoded),
  255. FALSE, Crypt32)
  256. #define CryptEncodeObject VAR_CryptEncodeObject
  257. LOADER_FUNCTION( BOOL, CryptExportPublicKeyInfo,
  258. (HCRYPTPROV hCryptProv, DWORD dwKeySpec, DWORD dwCertEncodingType,
  259. PCERT_PUBLIC_KEY_INFO pInfo, DWORD *pcbInfo),
  260. (hCryptProv, dwKeySpec, dwCertEncodingType, pInfo, pcbInfo),
  261. FALSE, Crypt32)
  262. #define CryptExportPublicKeyInfo VAR_CryptExportPublicKeyInfo
  263. LOADER_FUNCTION( HCERTSTORE, CertDuplicateStore,
  264. (HCERTSTORE hCertStore),
  265. (hCertStore),
  266. NULL, Crypt32)
  267. #define CertDuplicateStore VAR_CertDuplicateStore
  268. LOADER_FUNCTION( BOOL, CertAddEncodedCertificateToStore,
  269. (HCERTSTORE hCertStore, DWORD dwCertEncodingType, const BYTE *pbCertEncoded,
  270. DWORD cbCertEncoded, DWORD dwAddDisposition, PCCERT_CONTEXT *ppCertContext),
  271. (hCertStore, dwCertEncodingType, pbCertEncoded,
  272. cbCertEncoded, dwAddDisposition, ppCertContext),
  273. FALSE, Crypt32)
  274. #define CertAddEncodedCertificateToStore VAR_CertAddEncodedCertificateToStore
  275. LOADER_FUNCTION( LONG, CertVerifyTimeValidity,
  276. (LPFILETIME pTimeToVerify, PCERT_INFO pCertInfo),
  277. (pTimeToVerify, pCertInfo),
  278. +1, Crypt32) // Return AFTER by default
  279. #define CertVerifyTimeValidity VAR_CertVerifyTimeValidity
  280. LOADER_FUNCTION( PCTL_ENTRY, CertFindSubjectInCTL,
  281. (DWORD dwEncodingType, DWORD dwSubjectType, void *pvSubject,
  282. PCCTL_CONTEXT pCtlContext, DWORD dwFlags),
  283. (dwEncodingType, dwSubjectType, pvSubject, pCtlContext, dwFlags),
  284. NULL, Crypt32)
  285. #define CertFindSubjectInCTL VAR_CertFindSubjectInCTL
  286. LOADER_FUNCTION( BOOL, CertVerifySubjectCertificateContext,
  287. (PCCERT_CONTEXT pSubject, PCCERT_CONTEXT pIssuer, DWORD *pdwFlags),
  288. (pSubject, pIssuer, pdwFlags),
  289. FALSE, Crypt32)
  290. #define CertVerifySubjectCertificateContext VAR_CertVerifySubjectCertificateContext
  291. LOADER_FUNCTION( BOOL, CertGetEnhancedKeyUsage,
  292. (PCCERT_CONTEXT pCertContext, DWORD dwFlags, PCERT_ENHKEY_USAGE pUsage,
  293. DWORD *pcbUsage),
  294. (pCertContext, dwFlags, pUsage, pcbUsage),
  295. FALSE, Crypt32)
  296. #define CertGetEnhancedKeyUsage VAR_CertGetEnhancedKeyUsage
  297. #if 0
  298. LOADER_FUNCTION( BOOL, ,
  299. (),
  300. (),
  301. FALSE, Crypt32)
  302. #define X VAR_
  303. #endif // 0
  304. /////////////////////////////////////
  305. // ADVAPI32.DLL
  306. #ifndef ALGIDDEF
  307. #define ALGIDDEF
  308. typedef unsigned int ALG_ID;
  309. #endif
  310. BOOL DemandLoadAdvApi32(void);
  311. LOADER_FUNCTION( BOOL, CryptAcquireContextW,
  312. (HCRYPTPROV *phProv, LPCWSTR pszContainer, LPCWSTR pszProvider, DWORD dwProvType, DWORD dwFlags),
  313. (phProv, pszContainer, pszProvider, dwProvType, dwFlags),
  314. FALSE, AdvApi32)
  315. #define CryptAcquireContextW VAR_CryptAcquireContextW
  316. #if 0
  317. LOADER_FUNCTION( BOOL, CryptGetProvParam,
  318. (HCRYPTPROV hProv, DWORD dwParam, BYTE *pbData, DWORD *pdwDataLen, DWORD dwFlags),
  319. (hProv, dwParam, pbData, pdwDataLen, dwFlags),
  320. FALSE, AdvApi32)
  321. #define CryptGetProvParam VAR_CryptGetProvParam
  322. LOADER_FUNCTION( BOOL, CryptReleaseContext,
  323. (HCRYPTPROV hProv, DWORD dwFlags),
  324. (hProv, dwFlags),
  325. FALSE, AdvApi32)
  326. #define CryptReleaseContext VAR_CryptReleaseContext
  327. LOADER_FUNCTION( BOOL, CryptGenKey,
  328. (HCRYPTPROV hProv, ALG_ID Algid, DWORD dwFlags, HCRYPTKEY *phKey),
  329. (hProv, Algid, dwFlags, phKey),
  330. FALSE, AdvApi32)
  331. #define CryptGenKey VAR_CryptGenKey
  332. LOADER_FUNCTION( BOOL, CryptDestroyKey,
  333. (HCRYPTKEY hKey),
  334. (hKey),
  335. FALSE, AdvApi32)
  336. #define CryptDestroyKey VAR_CryptDestroyKey
  337. #endif // 0
  338. #ifndef WIN16
  339. /////////////////////////////////////
  340. // USER32.DLL
  341. BOOL DemandLoadUser32();
  342. LOADER_FUNCTION( LRESULT, SendDlgItemMessageW,
  343. (HWND hwnd, int idCtl, UINT msg, WPARAM wparam, LPARAM lparam),
  344. (hwnd, idCtl, msg, wparam, lparam),
  345. -1, User32)
  346. #define SendDlgItemMessageW VAR_SendDlgItemMessageW
  347. LOADER_FUNCTION( BOOL, SetDlgItemTextW,
  348. (HWND hwnd, int idCtl, LPCWSTR psz),
  349. (hwnd, idCtl, psz),
  350. FALSE, User32)
  351. #define SetDlgItemTextW VAR_SetDlgItemTextW
  352. LOADER_FUNCTION( UINT, GetDlgItemTextW,
  353. (HWND hwnd, int idCtl, LPWSTR psz, int nMax),
  354. (hwnd, idCtl, psz, nMax),
  355. FALSE, User32)
  356. #define GetDlgItemTextW VAR_GetDlgItemTextW
  357. LOADER_FUNCTION( int, LoadStringW,
  358. (HINSTANCE hinst, UINT idStr, LPWSTR rgwch, int cwch),
  359. (hinst, idStr, rgwch, cwch),
  360. 0, User32)
  361. #define LoadStringW VAR_LoadStringW
  362. LOADER_FUNCTION( DWORD, FormatMessageW,
  363. (DWORD dwFlags, LPCVOID pbSource, DWORD dwMessageId,
  364. DWORD dwLangId, LPWSTR lpBuffer, DWORD nSize, va_list * args),
  365. (dwFlags, pbSource, dwMessageId, dwLangId, lpBuffer, nSize, args),
  366. 0, User32)
  367. #define FormatMessageW VAR_FormatMessageW
  368. LOADER_FUNCTION( BOOL, WinHelpW,
  369. (HWND hWndMain, LPCWSTR szHelp, UINT uCommand, ULONG_PTR dwData),
  370. (hWndMain, szHelp, uCommand, dwData),
  371. FALSE, User32)
  372. #define WinHelpW VAR_WinHelpW
  373. #endif // !WIN16
  374. #else // MAC
  375. #define SendDlgItemMessageW MySendDlgItemMessageW
  376. #define SetDlgItemTextW MySetDlgItemTextW
  377. #define GetDlgItemTextW MyGetDlgItemTextW
  378. #define LoadStringW MyLoadStringW
  379. #define FormatMessageW MyFormatMessageW
  380. #define WinHelpW MyWinHelpW
  381. #define SendMessageW SendMessageA
  382. #undef CertOpenStore
  383. EXTERN_C WINCRYPT32API HCERTSTORE WINAPI MacCertOpenStore(LPCSTR lpszStoreProvider,
  384. DWORD dwEncodingType,
  385. HCRYPTPROV hCryptProv,
  386. DWORD dwFlags,
  387. const void *pvPara);
  388. #define CertOpenStore MacCertOpenStore
  389. #endif // !MAC
  390. #endif // include once