Source code of Windows XP (NT5)
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.

290 lines
5.2 KiB

  1. /*++
  2. Copyright (c) 2001 Microsoft Corporation
  3. Module Name:
  4. dload.cpp
  5. Abstract:
  6. This file implement dload error handling
  7. --*/
  8. #include "precomp.h"
  9. #include <delayimp.h>
  10. BOOL
  11. BITSFailureHookWinHttpAddRequestHeaders(
  12. IN HINTERNET hRequest,
  13. IN LPCWSTR lpszHeaders,
  14. IN DWORD dwHeadersLength,
  15. IN DWORD dwModifiers
  16. )
  17. {
  18. SetLastError( ERROR_MOD_NOT_FOUND );
  19. return FALSE;
  20. }
  21. BOOL
  22. BITSFailureHookWinHttpCloseHandle(
  23. IN HINTERNET hInternet
  24. )
  25. {
  26. SetLastError( ERROR_MOD_NOT_FOUND );
  27. return FALSE;
  28. }
  29. HINTERNET
  30. BITSFailureHookWinHttpConnect(
  31. IN HINTERNET hInternetSession,
  32. IN LPCWSTR pszServerNameW,
  33. IN INTERNET_PORT nServerPort,
  34. IN DWORD dwReserved
  35. )
  36. {
  37. SetLastError( ERROR_MOD_NOT_FOUND );
  38. return NULL;
  39. }
  40. BOOL
  41. BITSFailureHookWinHttpCrackUrl(
  42. IN LPCWSTR pszUrlW,
  43. IN DWORD dwUrlLengthW,
  44. IN DWORD dwFlags,
  45. IN OUT LPURL_COMPONENTS pUCW
  46. )
  47. {
  48. SetLastError( ERROR_MOD_NOT_FOUND );
  49. return FALSE;
  50. }
  51. HINTERNET
  52. BITSFailureHookWinHttpOpen(
  53. IN LPCWSTR pszAgentW,
  54. IN DWORD dwAccessType,
  55. IN LPCWSTR pszProxyW OPTIONAL,
  56. IN LPCWSTR pszProxyBypassW OPTIONAL,
  57. IN DWORD dwFlags
  58. )
  59. {
  60. SetLastError( ERROR_MOD_NOT_FOUND );
  61. return NULL;
  62. }
  63. HINTERNET
  64. BITSFailureHookWinHttpOpenRequest(
  65. IN HINTERNET hConnect,
  66. IN LPCWSTR lpszVerb,
  67. IN LPCWSTR lpszObjectName,
  68. IN LPCWSTR lpszVersion,
  69. IN LPCWSTR lpszReferrer OPTIONAL,
  70. IN LPCWSTR FAR * lplpszAcceptTypes OPTIONAL,
  71. IN DWORD dwFlags
  72. )
  73. {
  74. SetLastError( ERROR_MOD_NOT_FOUND );
  75. return NULL;
  76. }
  77. BOOL
  78. BITSFailureHookWinHttpQueryHeaders(
  79. IN HINTERNET hRequest,
  80. IN DWORD dwInfoLevel,
  81. IN LPCWSTR lpszName OPTIONAL,
  82. OUT LPVOID lpBuffer OPTIONAL,
  83. IN OUT LPDWORD lpdwBufferLength,
  84. IN OUT LPDWORD lpdwIndex OPTIONAL
  85. )
  86. {
  87. SetLastError( ERROR_MOD_NOT_FOUND );
  88. return FALSE;
  89. }
  90. BOOL
  91. BITSFailureHookWinHttpReadData(
  92. IN HINTERNET hFile,
  93. IN LPVOID lpBuffer,
  94. IN DWORD dwNumberOfBytesToRead,
  95. OUT LPDWORD lpdwNumberOfBytesRead
  96. )
  97. {
  98. SetLastError( ERROR_MOD_NOT_FOUND );
  99. return FALSE;
  100. }
  101. BOOL
  102. BITSFailureHookWinHttpReceiveResponse(
  103. IN HINTERNET hRequest,
  104. IN LPVOID lpBuffersOut OPTIONAL
  105. )
  106. {
  107. SetLastError( ERROR_MOD_NOT_FOUND );
  108. return FALSE;
  109. }
  110. BOOL
  111. BITSFailureHookWinHttpSendRequest(
  112. IN HINTERNET hRequest,
  113. IN LPCWSTR lpszHeaders OPTIONAL,
  114. IN DWORD dwHeadersLength,
  115. IN LPVOID lpOptional OPTIONAL,
  116. IN DWORD dwOptionalLength,
  117. IN DWORD dwTotalLength,
  118. IN DWORD_PTR dwContext
  119. )
  120. {
  121. SetLastError( ERROR_MOD_NOT_FOUND );
  122. return FALSE;
  123. }
  124. BOOL
  125. BITSFailureHookWinHttpWriteData(
  126. IN HINTERNET hFile,
  127. IN LPCVOID lpBuffer,
  128. IN DWORD dwNumberOfBytesToWrite,
  129. OUT LPDWORD lpdwNumberOfBytesWritten
  130. )
  131. {
  132. SetLastError( ERROR_MOD_NOT_FOUND );
  133. return FALSE;
  134. }
  135. struct FailureHookTableEntry
  136. {
  137. LPCSTR pszDllName;
  138. LPCSTR pszProcName;
  139. FARPROC pfnHandler;
  140. };
  141. FailureHookTableEntry FailureHookTable[] =
  142. {
  143. {
  144. "winhttp.dll",
  145. "WinHttpAddRequestHeaders",
  146. (FARPROC)BITSFailureHookWinHttpAddRequestHeaders
  147. },
  148. {
  149. "winhttp.dll",
  150. "WinHttpCloseHandle",
  151. (FARPROC)BITSFailureHookWinHttpCloseHandle
  152. },
  153. {
  154. "winhttp.dll",
  155. "WinHttpConnect",
  156. (FARPROC)BITSFailureHookWinHttpConnect
  157. },
  158. {
  159. "winhttp.dll",
  160. "WinHttpCrackUrl",
  161. (FARPROC)BITSFailureHookWinHttpCrackUrl
  162. },
  163. {
  164. "winhttp.dll",
  165. "WinHttpOpen",
  166. (FARPROC)BITSFailureHookWinHttpOpen
  167. },
  168. {
  169. "winhttp.dll",
  170. "WinHttpOpenRequest",
  171. (FARPROC)BITSFailureHookWinHttpOpenRequest
  172. },
  173. {
  174. "winhttp.dll",
  175. "WinHttpQueryHeaders",
  176. (FARPROC)BITSFailureHookWinHttpQueryHeaders
  177. },
  178. {
  179. "winhttp.dll",
  180. "WinHttpReadData",
  181. (FARPROC)BITSFailureHookWinHttpReadData
  182. },
  183. {
  184. "winhttp.dll",
  185. "WinHttpReceiveResponse",
  186. (FARPROC)BITSFailureHookWinHttpReceiveResponse
  187. },
  188. {
  189. "winhttp.dll",
  190. "WinHttpSendRequest",
  191. (FARPROC)BITSFailureHookWinHttpSendRequest
  192. },
  193. {
  194. "winhttp.dll",
  195. "WinHttpWriteData",
  196. (FARPROC)BITSFailureHookWinHttpWriteData
  197. },
  198. {
  199. NULL,
  200. NULL,
  201. NULL
  202. }
  203. };
  204. FARPROC
  205. LookupFailureHook(
  206. LPCSTR pszDllName,
  207. LPCSTR pszProcName
  208. )
  209. {
  210. for ( FailureHookTableEntry *p = FailureHookTable;
  211. p->pszDllName; p++ )
  212. {
  213. if ( ( lstrcmpiA( pszDllName, p->pszDllName ) == 0 ) &&
  214. ( lstrcmpiA( pszProcName, p->pszProcName ) == 0 ) )
  215. {
  216. return p->pfnHandler;
  217. }
  218. }
  219. ASSERT( 0 );
  220. return NULL;
  221. }
  222. FARPROC
  223. WINAPI
  224. BITSSERVER_DelayLoadFailureHook(
  225. UINT unReason,
  226. PDelayLoadInfo pDelayInfo
  227. )
  228. {
  229. // For a failed LoadLibrary, we return a bogus HMODULE of -1 to force
  230. // DLOAD call again with dliFailGetProc
  231. if (dliFailLoadLib == unReason)
  232. {
  233. return (FARPROC)-1;
  234. }
  235. if (dliFailGetProc == unReason)
  236. {
  237. // The loader is asking us to return a pointer to a procedure.
  238. // Lookup the handler for this DLL/procedure and, if found, return it.
  239. return LookupFailureHook(pDelayInfo->szDll, pDelayInfo->dlp.szProcName);
  240. }
  241. return NULL;
  242. }