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.

403 lines
14 KiB

  1. /*
  2. ** d e m a n d . h
  3. **
  4. ** Purpose: create an intelligent method of defer loading functions
  5. **
  6. ** Creators: jimsch, brimo, t-erikne
  7. ** Created: 5/15/97
  8. **
  9. ** Copyright (C) Microsoft Corp. 1997
  10. */
  11. //
  12. // IF YOU #INCLUDE A FILE HERE YOU PROBABLY CONFUSED.
  13. // THIS FILE IS INCLUDED BY LOTS OF PEOPLE. THINK THRICE
  14. // BEFORE #INCLUDING *ANYTHING* HERE. MAKE GOOD USE
  15. // OF FORWARD REFS, THIS IS C++.
  16. //
  17. #define USE_CRITSEC
  18. #ifdef IMPLEMENT_LOADER_FUNCTIONS
  19. #define LOADER_FUNCTION(ret, name, args1, args2, err, dll) \
  20. typedef ret (WINAPI * TYP_##name) args1; \
  21. extern TYP_##name VAR_##name; \
  22. ret WINAPI LOADER_##name args1 \
  23. { \
  24. ESS_DemandLoad##dll(); \
  25. if (VAR_##name == LOADER_##name) return err; \
  26. return VAR_##name args2; \
  27. } \
  28. TYP_##name VAR_##name = LOADER_##name;
  29. #define LOADER_FUNCTION_VOID(ret, name, args1, args2, dll) \
  30. typedef ret (WINAPI * TYP_##name) args1; \
  31. extern TYP_##name VAR_##name; \
  32. ret WINAPI LOADER_##name args1 \
  33. { \
  34. ESS_DemandLoad##dll(); \
  35. if (VAR_##name == LOADER_##name) return; \
  36. VAR_##name args2; \
  37. return; \
  38. } \
  39. TYP_##name VAR_##name = LOADER_##name;
  40. #else // !IMPLEMENT_LOADER_FUNCTIONS
  41. #define LOADER_FUNCTION(ret, name, args1, args2, err, dll) \
  42. typedef ret (WINAPI * TYP_##name) args1; \
  43. extern TYP_##name VAR_##name; \
  44. #define LOADER_FUNCTION_VOID(ret, name, args1, args2, dll) \
  45. typedef ret (WINAPI * TYP_##name) args1; \
  46. extern TYP_##name VAR_##name;
  47. #endif // IMPLEMENT_LOADER_FUNCTIONS
  48. extern HINSTANCE g_hInst;
  49. void ESS_InitDemandLoadLibs();
  50. void ESS_FreeDemandLoadLibs();
  51. /////////////////////////////////////
  52. // CRYPT32.DLL
  53. #define _CRYPT32_
  54. BOOL ESS_DemandLoadCrypt32(void);
  55. typedef void *HCERTSTORE;
  56. typedef const struct _CERT_CONTEXT *PCCERT_CONTEXT;
  57. typedef struct _CERT_INFO *PCERT_INFO;
  58. typedef struct _CERT_RDN_ATTR *PCERT_RDN_ATTR;
  59. typedef struct _CERT_NAME_INFO *PCERT_NAME_INFO;
  60. typedef void *HCRYPTMSG;
  61. typedef struct _CMSG_STREAM_INFO *PCMSG_STREAM_INFO;
  62. typedef struct _CERT_RDN_ATTR *PCERT_RDN_ATTR;
  63. typedef struct _CERT_NAME_INFO *PCCERT_NAME_INFO;
  64. LOADER_FUNCTION( BOOL, CryptRegisterOIDFunction,
  65. (DWORD dwEncodingType, LPCSTR pszFuncName, LPCSTR pszOID, LPCWSTR pwszDll,
  66. LPCSTR pszOverrideFuncName),
  67. (dwEncodingType, pszFuncName, pszOID, pwszDll, pszOverrideFuncName),
  68. NULL, Crypt32)
  69. #define CryptRegisterOIDFunction VAR_CryptRegisterOIDFunction
  70. LOADER_FUNCTION( BOOL, I_CryptUninstallAsn1Module,
  71. (HCRYPTASN1MODULE hAsn1Module),
  72. (hAsn1Module),
  73. NULL, Crypt32)
  74. #define I_CryptUninstallAsn1Module VAR_I_CryptUninstallAsn1Module
  75. LOADER_FUNCTION( BOOL, I_CryptInstallAsn1Module,
  76. (ASN1module_t pMod, DWORD dwFlags, void *pvReserved),
  77. (pMod, dwFlags, pvReserved),
  78. NULL, Crypt32)
  79. #define I_CryptInstallAsn1Module VAR_I_CryptInstallAsn1Module
  80. LOADER_FUNCTION( ASN1encoding_t, I_CryptGetAsn1Encoder,
  81. (HCRYPTASN1MODULE hAsn1Module),
  82. (hAsn1Module),
  83. NULL, Crypt32)
  84. #define I_CryptGetAsn1Encoder VAR_I_CryptGetAsn1Encoder
  85. LOADER_FUNCTION( ASN1decoding_t, I_CryptGetAsn1Decoder,
  86. (HCRYPTASN1MODULE hAsn1Module),
  87. (hAsn1Module),
  88. NULL, Crypt32)
  89. #define I_CryptGetAsn1Decoder VAR_I_CryptGetAsn1Decoder
  90. ////////////////////////////////
  91. // nmasn1.dll
  92. BOOL ESS_DemandLoadNmasn1(void);
  93. LOADER_FUNCTION( ASN1module_t, ASN1_CreateModule,
  94. ( ASN1uint32_t nVersion, ASN1encodingrule_e eRule, ASN1uint32_t dwFlags,ASN1uint32_t cPDU, const ASN1GenericFun_t apfnEncoder[], const ASN1GenericFun_t apfnDecoder[], const ASN1FreeFun_t apfnFreeMemory[], const ASN1uint32_t acbStructSize[], ASN1magic_t nModuleName),
  95. ( nVersion, eRule, dwFlags,cPDU, apfnEncoder, apfnDecoder, apfnFreeMemory, acbStructSize, nModuleName),
  96. NULL, Nmasn1)
  97. #define ASN1_CreateModule VAR_ASN1_CreateModule
  98. LOADER_FUNCTION_VOID( void, ASN1_CloseModule,
  99. (ASN1module_t pModule),
  100. (pModule),
  101. Nmasn1)
  102. #define ASN1_CloseModule VAR_ASN1_CloseModule
  103. LOADER_FUNCTION( int, ASN1BEREncObjectIdentifier2,
  104. (ASN1encoding_t enc, ASN1uint32_t tag, ASN1objectidentifier2_t *val),
  105. (enc, tag, val),
  106. NULL, Nmasn1)
  107. #define ASN1BEREncObjectIdentifier2 VAR_ASN1BEREncObjectIdentifier2
  108. LOADER_FUNCTION( int, ASN1BERDecObjectIdentifier2,
  109. (ASN1decoding_t dec, ASN1uint32_t tag, ASN1objectidentifier2_t * a),
  110. (dec, tag, a),
  111. NULL, Nmasn1)
  112. #define ASN1BERDecObjectIdentifier2 VAR_ASN1BERDecObjectIdentifier2
  113. LOADER_FUNCTION( int, ASN1BEREncEndOfContents,
  114. (ASN1encoding_t enc, ASN1uint32_t LengthOffset),
  115. (enc, LengthOffset),
  116. NULL, Nmasn1)
  117. #define ASN1BEREncEndOfContents VAR_ASN1BEREncEndOfContents
  118. LOADER_FUNCTION( int, ASN1BEREncS32,
  119. (ASN1encoding_t enc, ASN1uint32_t tag, ASN1int32_t b),
  120. (enc, tag, b),
  121. NULL, Nmasn1)
  122. #define ASN1BEREncS32 VAR_ASN1BEREncS32
  123. LOADER_FUNCTION( int, ASN1BEREncOpenType,
  124. (ASN1encoding_t enc, ASN1open_t * a),
  125. (enc, a),
  126. NULL, Nmasn1)
  127. #define ASN1BEREncOpenType VAR_ASN1BEREncOpenType
  128. LOADER_FUNCTION( int, ASN1BEREncExplicitTag,
  129. (ASN1encoding_t enc, ASN1uint32_t tag, ASN1uint32_t *pLengthOffset),
  130. (enc, tag, pLengthOffset),
  131. NULL, Nmasn1)
  132. #define ASN1BEREncExplicitTag VAR_ASN1BEREncExplicitTag
  133. LOADER_FUNCTION( int, ASN1BERDecEndOfContents,
  134. (ASN1decoding_t dec, ASN1decoding_t dd, ASN1octet_t *di),
  135. (dec, dd, di),
  136. NULL, Nmasn1)
  137. #define ASN1BERDecEndOfContents VAR_ASN1BERDecEndOfContents
  138. LOADER_FUNCTION( int, ASN1BERDecS32Val,
  139. (ASN1decoding_t dec, ASN1uint32_t tag, ASN1int32_t * a),
  140. (dec, tag, a),
  141. NULL, Nmasn1)
  142. #define ASN1BERDecS32Val VAR_ASN1BERDecS32Val
  143. LOADER_FUNCTION( int, ASN1BERDecOpenType2,
  144. (ASN1decoding_t dec, ASN1open_t * a),
  145. (dec, a),
  146. NULL, Nmasn1)
  147. #define ASN1BERDecOpenType2 VAR_ASN1BERDecOpenType2
  148. LOADER_FUNCTION( int, ASN1BERDecExplicitTag,
  149. (ASN1decoding_t dec, ASN1uint32_t tag, ASN1decoding_t *dd, ASN1octet_t **di),
  150. (dec, tag, dd,di),
  151. NULL, Nmasn1)
  152. #define ASN1BERDecExplicitTag VAR_ASN1BERDecExplicitTag
  153. LOADER_FUNCTION( int, ASN1CEREncOctetString,
  154. (ASN1encoding_t enc, ASN1uint32_t a, ASN1uint32_t b, ASN1octet_t * c),
  155. (enc, a, b, c),
  156. NULL, Nmasn1)
  157. #define ASN1CEREncOctetString VAR_ASN1CEREncOctetString
  158. LOADER_FUNCTION( int, ASN1BERDecOctetString2,
  159. (ASN1decoding_t dec, ASN1uint32_t tag, ASN1octetstring_t *val),
  160. (dec, tag, val),
  161. NULL, Nmasn1)
  162. #define ASN1BERDecOctetString2 VAR_ASN1BERDecOctetString2
  163. LOADER_FUNCTION( int, ASN1BERDecOctetString,
  164. (ASN1decoding_t dec, ASN1uint32_t tag, ASN1octetstring_t *val),
  165. (dec, tag, val),
  166. NULL, Nmasn1)
  167. #define ASN1BERDecOctetString VAR_ASN1BERDecOctetString
  168. LOADER_FUNCTION_VOID( void, ASN1octetstring_free,
  169. (ASN1octetstring_t * a),
  170. (a),
  171. Nmasn1)
  172. #define ASN1octetstring_free VAR_ASN1octetstring_free
  173. LOADER_FUNCTION( int, ASN1BEREncUTF8String,
  174. (ASN1encoding_t enc, ASN1uint32_t tag, ASN1uint32_t length, WCHAR *value),
  175. (enc, tag, length, value),
  176. NULL, Nmasn1)
  177. #define ASN1BEREncUTF8String VAR_ASN1BEREncUTF8String
  178. LOADER_FUNCTION( int, ASN1BERDecUTF8String,
  179. (ASN1decoding_t dec, ASN1uint32_t tag, ASN1wstring_t *val),
  180. (dec, tag, val),
  181. NULL, Nmasn1)
  182. #define ASN1BERDecUTF8String VAR_ASN1BERDecUTF8String
  183. LOADER_FUNCTION( int, ASN1BERDecPeekTag,
  184. (ASN1decoding_t dec, ASN1uint32_t *tag),
  185. (dec, tag),
  186. NULL, Nmasn1)
  187. #define ASN1BERDecPeekTag VAR_ASN1BERDecPeekTag
  188. LOADER_FUNCTION_VOID( void, ASN1utf8string_free,
  189. (ASN1wstring_t * a),
  190. (a),
  191. Nmasn1)
  192. #define ASN1utf8string_free VAR_ASN1utf8string_free
  193. LOADER_FUNCTION( void *, ASN1DecRealloc,
  194. (ASN1decoding_t dec, void *ptr, ASN1uint32_t size),
  195. (dec, ptr, size),
  196. NULL, Nmasn1)
  197. #define ASN1DecRealloc VAR_ASN1DecRealloc
  198. LOADER_FUNCTION( int, ASN1BERDecNotEndOfContents,
  199. (ASN1decoding_t dec, ASN1octet_t *di),
  200. (dec, di),
  201. NULL, Nmasn1)
  202. #define ASN1BERDecNotEndOfContents VAR_ASN1BERDecNotEndOfContents
  203. LOADER_FUNCTION_VOID( void, ASN1Free,
  204. (void *ptr),
  205. (ptr),
  206. Nmasn1)
  207. #define ASN1Free VAR_ASN1Free
  208. LOADER_FUNCTION( ASN1error_e, ASN1DecSetError,
  209. (ASN1decoding_t dec, ASN1error_e err),
  210. (dec, err),
  211. ASN1_ERR_INTERNAL, Nmasn1)
  212. #define ASN1DecSetError VAR_ASN1DecSetError
  213. LOADER_FUNCTION( int, ASN1BEREncU32,
  214. (ASN1encoding_t enc, ASN1uint32_t tag, ASN1uint32_t a),
  215. (enc, tag, a),
  216. NULL, Nmasn1)
  217. #define ASN1BEREncU32 VAR_ASN1BEREncU32
  218. LOADER_FUNCTION( int, ASN1CEREncCharString,
  219. (ASN1encoding_t enc, ASN1uint32_t a, ASN1uint32_t b, ASN1char_t * c),
  220. (enc, a, b, c),
  221. NULL, Nmasn1)
  222. #define ASN1CEREncCharString VAR_ASN1CEREncCharString
  223. LOADER_FUNCTION( int, ASN1CEREncBeginBlk,
  224. (ASN1encoding_t enc, ASN1blocktype_e eBlkType, void **ppBlk),
  225. (enc, eBlkType, ppBlk),
  226. NULL, Nmasn1)
  227. #define ASN1CEREncBeginBlk VAR_ASN1CEREncBeginBlk
  228. LOADER_FUNCTION( int, ASN1CEREncNewBlkElement,
  229. (void *pBlk, ASN1encoding_t *enc2),
  230. (pBlk, enc2),
  231. NULL, Nmasn1)
  232. #define ASN1CEREncNewBlkElement VAR_ASN1CEREncNewBlkElement
  233. LOADER_FUNCTION( int, ASN1CEREncFlushBlkElement,
  234. (void *pBlk),
  235. (pBlk),
  236. NULL, Nmasn1)
  237. #define ASN1CEREncFlushBlkElement VAR_ASN1CEREncFlushBlkElement
  238. LOADER_FUNCTION( int, ASN1CEREncEndBlk,
  239. (void *pBlk),
  240. (pBlk),
  241. NULL, Nmasn1)
  242. #define ASN1CEREncEndBlk VAR_ASN1CEREncEndBlk
  243. LOADER_FUNCTION( int, ASN1BERDecU16Val,
  244. (ASN1decoding_t dec, ASN1uint32_t tag, ASN1uint16_t *a),
  245. (dec, tag, a),
  246. NULL, Nmasn1)
  247. #define ASN1BERDecU16Val VAR_ASN1BERDecU16Val
  248. LOADER_FUNCTION( int, ASN1BERDecZeroCharString,
  249. (ASN1decoding_t dec, ASN1uint32_t tag, ASN1ztcharstring_t * a),
  250. (dec, tag, a),
  251. NULL, Nmasn1)
  252. #define ASN1BERDecZeroCharString VAR_ASN1BERDecZeroCharString
  253. LOADER_FUNCTION_VOID( void, ASN1ztcharstring_free,
  254. (ASN1ztcharstring_t a),
  255. (a),
  256. Nmasn1)
  257. #define ASN1ztcharstring_free VAR_ASN1ztcharstring_free
  258. LOADER_FUNCTION( int, ASN1CEREncGeneralizedTime,
  259. (ASN1encoding_t enc, ASN1uint32_t a, ASN1generalizedtime_t * b),
  260. (enc, a, b),
  261. NULL, Nmasn1)
  262. #define ASN1CEREncGeneralizedTime VAR_ASN1CEREncGeneralizedTime
  263. LOADER_FUNCTION( int, ASN1BEREncNull,
  264. (ASN1encoding_t enc, ASN1uint32_t tag),
  265. (enc, tag),
  266. NULL, Nmasn1)
  267. #define ASN1BEREncNull VAR_ASN1BEREncNull
  268. LOADER_FUNCTION( int, ASN1BERDecGeneralizedTime,
  269. (ASN1decoding_t dec, ASN1uint32_t tag, ASN1generalizedtime_t * a),
  270. (dec, tag, a),
  271. NULL, Nmasn1)
  272. #define ASN1BERDecGeneralizedTime VAR_ASN1BERDecGeneralizedTime
  273. LOADER_FUNCTION( int, ASN1BERDecNull,
  274. (ASN1decoding_t dec, ASN1uint32_t tag),
  275. (dec, tag),
  276. NULL, Nmasn1)
  277. #define ASN1BERDecNull VAR_ASN1BERDecNull
  278. LOADER_FUNCTION( ASN1error_e, ASN1_Encode,
  279. ( ASN1encoding_t pEncoderInfo, void *pDataStruct, ASN1uint32_t nPduNum, ASN1uint32_t dwFlags, ASN1octet_t *pbBuf, ASN1uint32_t cbBufSize),
  280. ( pEncoderInfo, pDataStruct, nPduNum, dwFlags, pbBuf, cbBufSize),
  281. ASN1_ERR_INTERNAL, Nmasn1)
  282. #define ASN1_Encode VAR_ASN1_Encode
  283. LOADER_FUNCTION_VOID( void, ASN1_FreeEncoded,
  284. ( ASN1encoding_t pEncoderInfo, void *pBuf),
  285. ( pEncoderInfo, pBuf),
  286. Nmasn1)
  287. #define ASN1_FreeEncoded VAR_ASN1_FreeEncoded
  288. LOADER_FUNCTION( ASN1error_e, ASN1_Decode,
  289. ( ASN1decoding_t pDecoderInfo, void **ppDataStruct, ASN1uint32_t nPduNum, ASN1uint32_t dwFlags, ASN1octet_t *pbBuf, ASN1uint32_t cbBufSize),
  290. ( pDecoderInfo, ppDataStruct, nPduNum, dwFlags, pbBuf, cbBufSize),
  291. ASN1_ERR_INTERNAL, Nmasn1)
  292. #define ASN1_Decode VAR_ASN1_Decode
  293. LOADER_FUNCTION( ASN1error_e, ASN1_SetEncoderOption,
  294. ( ASN1encoding_t pEncoderInfo, ASN1optionparam_t *pOptParam),
  295. ( pEncoderInfo, pOptParam),
  296. ASN1_ERR_INTERNAL, Nmasn1)
  297. #define ASN1_SetEncoderOption VAR_ASN1_SetEncoderOption
  298. LOADER_FUNCTION( ASN1error_e, ASN1_GetEncoderOption,
  299. ( ASN1encoding_t pEncoderInfo, ASN1optionparam_t *pOptParam),
  300. ( pEncoderInfo, pOptParam),
  301. ASN1_ERR_INTERNAL, Nmasn1)
  302. #define ASN1_GetEncoderOption VAR_ASN1_GetEncoderOption
  303. LOADER_FUNCTION_VOID( void, ASN1_FreeDecoded,
  304. ( ASN1decoding_t pDecoderInfo, void *pDataStruct, ASN1uint32_t nPduNum),
  305. ( pDecoderInfo, pDataStruct, nPduNum),
  306. Nmasn1)
  307. #define ASN1_FreeDecoded VAR_ASN1_FreeDecoded
  308. LOADER_FUNCTION( int, ASN1BEREncOctetString,
  309. (ASN1encoding_t enc, ASN1uint32_t tag, ASN1uint32_t len, ASN1octet_t *val),
  310. (enc, tag, len, val),
  311. 0, Nmasn1)
  312. #define ASN1BEREncOctetString VAR_ASN1BEREncOctetString
  313. LOADER_FUNCTION( int, ASN1BEREncCharString,
  314. (ASN1encoding_t enc, ASN1uint32_t tag, ASN1uint32_t a, ASN1char_t * b),
  315. (enc, tag, a, b),
  316. 0, Nmasn1)
  317. #define ASN1BEREncCharString VAR_ASN1BEREncCharString
  318. LOADER_FUNCTION( int, ASN1BEREncSX,
  319. (ASN1encoding_t enc, ASN1uint32_t tag, ASN1intx_t * a),
  320. (enc, tag, a),
  321. 0, Nmasn1)
  322. #define ASN1BEREncSX VAR_ASN1BEREncSX
  323. LOADER_FUNCTION( int, ASN1BERDecSXVal,
  324. (ASN1decoding_t dec, ASN1uint32_t tag, ASN1intx_t *a),
  325. (dec, tag, a),
  326. 0, Nmasn1)
  327. #define ASN1BERDecSXVal VAR_ASN1BERDecSXVal
  328. LOADER_FUNCTION_VOID( void, ASN1intx_free,
  329. (ASN1intx_t * a),
  330. (a),
  331. Nmasn1)
  332. #define ASN1intx_free VAR_ASN1intx_free