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.

259 lines
5.8 KiB

  1. /*++
  2. Copyright (c) 2001 Microsoft Corporation
  3. Module Name:
  4. ISA.cpp
  5. Abstract:
  6. The ISA setup needs to successfully open the SharedAccess service and get the
  7. its status in order to succeed. But on whistler we remove this from advanced
  8. server since it's a consumer feature so the ISA setup bails out.
  9. We fake the service API call return values to make the ISA setup happy.
  10. History:
  11. 04/24/2001 maonis Created
  12. --*/
  13. #include "precomp.h"
  14. IMPLEMENT_SHIM_BEGIN(ISA)
  15. #include "ShimHookMacro.h"
  16. APIHOOK_ENUM_BEGIN
  17. APIHOOK_ENUM_ENTRY(OpenServiceA)
  18. APIHOOK_ENUM_ENTRY(OpenServiceW)
  19. APIHOOK_ENUM_ENTRY(QueryServiceStatus)
  20. APIHOOK_ENUM_ENTRY(QueryServiceConfigA)
  21. APIHOOK_ENUM_ENTRY(ChangeServiceConfigA)
  22. APIHOOK_ENUM_ENTRY(CloseServiceHandle)
  23. APIHOOK_ENUM_END
  24. /*++
  25. Abstract:
  26. This checks to see if the service is being opened is SharedAccess.
  27. If so we simply return a fake handle.
  28. History:
  29. 04/24/2001 maonis Created
  30. --*/
  31. SC_HANDLE
  32. APIHOOK(OpenServiceA)(
  33. SC_HANDLE hSCManager, // handle to SCM database
  34. LPCSTR lpServiceName, // service name
  35. DWORD dwDesiredAccess // access
  36. )
  37. {
  38. DPF("ISA", eDbgLevelInfo, "Calling OpenServiceA on %s", lpServiceName);
  39. SC_HANDLE hService;
  40. if (!(hService = ORIGINAL_API(OpenServiceA)(hSCManager, lpServiceName, dwDesiredAccess)))
  41. {
  42. if (lpServiceName && !lstrcmpiA(lpServiceName, "SharedAccess"))
  43. {
  44. DPF("ISA", eDbgLevelError, "it's trying to open SharedAccess!!!");
  45. return (SC_HANDLE)0xBAADF00D;
  46. }
  47. }
  48. return hService;
  49. }
  50. SC_HANDLE
  51. APIHOOK(OpenServiceW)(
  52. SC_HANDLE hSCManager, // handle to SCM database
  53. LPCWSTR lpServiceName, // service name
  54. DWORD dwDesiredAccess // access
  55. )
  56. {
  57. DPF("ISA", eDbgLevelInfo, "Calling OpenServiceW on %S", lpServiceName);
  58. SC_HANDLE hService;
  59. if (!(hService = ORIGINAL_API(OpenServiceW)(hSCManager, lpServiceName, dwDesiredAccess)))
  60. {
  61. if (lpServiceName && !lstrcmpiW(lpServiceName, L"SharedAccess"))
  62. {
  63. DPF("ISA", eDbgLevelError, "it's trying to open SharedAccess!!!");
  64. return (SC_HANDLE)0xBAADF00D;
  65. }
  66. }
  67. return hService;
  68. }
  69. /*++
  70. Abstract:
  71. This checks to see if the service handle is 0xBAADF00D, if so just sets
  72. the service status to SERVICE_STOPPED.
  73. History:
  74. 04/24/2001 maonis Created
  75. --*/
  76. BOOL
  77. APIHOOK(QueryServiceStatus)(
  78. SC_HANDLE hService, // handle to service
  79. LPSERVICE_STATUS lpServiceStatus // service status
  80. )
  81. {
  82. if (hService == (SC_HANDLE)0xBAADF00D)
  83. {
  84. lpServiceStatus->dwCurrentState = SERVICE_STOPPED;
  85. return TRUE;
  86. }
  87. else
  88. {
  89. return ORIGINAL_API(QueryServiceStatus)(hService, lpServiceStatus);
  90. }
  91. }
  92. /*++
  93. Abstract:
  94. ISA calls this API first with a NULL lpServiceConfig to get the size
  95. of the buffer needs to be allocated for the structure; then it calls
  96. the API again with the pointer to the structure.
  97. History:
  98. 05/07/2001 maonis Created
  99. --*/
  100. BOOL
  101. APIHOOK(QueryServiceConfigA)(
  102. SC_HANDLE hService, // handle to service
  103. LPQUERY_SERVICE_CONFIGA lpServiceConfig, // buffer
  104. DWORD cbBufSize, // size of buffer
  105. LPDWORD pcbBytesNeeded // bytes needed
  106. )
  107. {
  108. if (hService == (SC_HANDLE)0xBAADF00D)
  109. {
  110. if (lpServiceConfig)
  111. {
  112. lpServiceConfig->lpDependencies = NULL;
  113. return TRUE;
  114. }
  115. else
  116. {
  117. *pcbBytesNeeded = sizeof(QUERY_SERVICE_CONFIGA);
  118. SetLastError(ERROR_INSUFFICIENT_BUFFER);
  119. return TRUE;
  120. }
  121. }
  122. else
  123. {
  124. return ORIGINAL_API(QueryServiceConfigA)(hService, lpServiceConfig, cbBufSize, pcbBytesNeeded);
  125. }
  126. }
  127. /*++
  128. Abstract:
  129. We simply make this API succeed when hService is 0xBAADF00D.
  130. History:
  131. 05/07/2001 maonis Created
  132. --*/
  133. BOOL
  134. APIHOOK(ChangeServiceConfigA)(
  135. SC_HANDLE hService, // handle to service
  136. DWORD dwServiceType, // type of service
  137. DWORD dwStartType, // when to start service
  138. DWORD dwErrorControl, // severity of start failure
  139. LPCSTR lpBinaryPathName, // service binary file name
  140. LPCSTR lpLoadOrderGroup, // load ordering group name
  141. LPDWORD lpdwTagId, // tag identifier
  142. LPCSTR lpDependencies, // array of dependency names
  143. LPCSTR lpServiceStartName, // account name
  144. LPCSTR lpPassword, // account password
  145. LPCSTR lpDisplayName // display name
  146. )
  147. {
  148. if (hService == (SC_HANDLE)0xBAADF00D)
  149. {
  150. return TRUE;
  151. }
  152. else
  153. {
  154. return ORIGINAL_API(ChangeServiceConfigA)(
  155. hService,
  156. dwServiceType,
  157. dwStartType,
  158. dwErrorControl,
  159. lpBinaryPathName,
  160. lpLoadOrderGroup,
  161. lpdwTagId,
  162. lpDependencies,
  163. lpServiceStartName,
  164. lpPassword,
  165. lpDisplayName);
  166. }
  167. }
  168. /*++
  169. Abstract:
  170. This checks to see if the service handle is 0xBAADF00D, if so simply return
  171. History:
  172. 04/24/2001 maonis Created
  173. --*/
  174. BOOL
  175. APIHOOK(CloseServiceHandle)(
  176. SC_HANDLE hSCObject // handle to service or SCM object
  177. )
  178. {
  179. if (hSCObject == (SC_HANDLE)0xBAADF00D)
  180. {
  181. return TRUE;
  182. }
  183. else
  184. {
  185. return ORIGINAL_API(CloseServiceHandle)(hSCObject);
  186. }
  187. }
  188. /*++
  189. Register hooked functions
  190. --*/
  191. HOOK_BEGIN
  192. APIHOOK_ENTRY(Advapi32.DLL, OpenServiceA)
  193. APIHOOK_ENTRY(Advapi32.DLL, OpenServiceW)
  194. APIHOOK_ENTRY(Advapi32.DLL, QueryServiceStatus)
  195. APIHOOK_ENTRY(Advapi32.DLL, QueryServiceConfigA)
  196. APIHOOK_ENTRY(Advapi32.DLL, ChangeServiceConfigA)
  197. APIHOOK_ENTRY(Advapi32.DLL, CloseServiceHandle)
  198. HOOK_END
  199. IMPLEMENT_SHIM_END