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.

93 lines
2.7 KiB

  1. /*++
  2. Copyright (c) 2001 Microsoft Corporation
  3. Module Name:
  4. FixServiceStartupCircularDependency.cpp
  5. Abstract:
  6. Hooks the call to CreateServiceA and changes the start parameter for
  7. only the service passed in COMMAND_LINE from SERVICE_AUTO_START to
  8. SERVICE_SYSTEM_START. This eliminates a circular dependency during
  9. boot up which results in XP taking 15 to 20 minutes to boot.
  10. Notes:
  11. This is a general purpose shim. Pass the service name in the command
  12. line. It tests if the startup type for that service is SERVICE_AUTO_START
  13. and if so changes it to SERVICE_SYSTEM_START.
  14. History:
  15. 02/19/2001 a-brienw Created
  16. 02/20/2001 a-brienw Changed it to a general purpose shim using the command
  17. line to pass in the service name.
  18. 02/14/2002 astritz Security Review
  19. --*/
  20. #include "precomp.h"
  21. IMPLEMENT_SHIM_BEGIN(FixServiceStartupCircularDependency)
  22. #include "ShimHookMacro.h"
  23. APIHOOK_ENUM_BEGIN
  24. APIHOOK_ENUM_ENTRY(CreateServiceA)
  25. APIHOOK_ENUM_END
  26. /*++
  27. Hook CreateServiceA to change the start parameter for the required service.
  28. --*/
  29. SC_HANDLE
  30. APIHook_CreateServiceA(
  31. SC_HANDLE hSCManager, // handle to SCM database
  32. LPCSTR lpServiceName, // name of service to start
  33. LPCSTR lpDisplayName, // display name
  34. DWORD dwDesiredAccess, // type of access to service
  35. DWORD dwServiceType, // type of service
  36. DWORD dwStartType, // when to start service
  37. DWORD dwErrorControl, // severity of service failure
  38. LPCSTR lpBinaryPathName, // name of binary file
  39. LPCSTR lpLoadOrderGroup, // name of load ordering group
  40. LPDWORD lpdwTagId, // tag identifier
  41. LPCSTR lpDependencies, // array of dependency names
  42. LPCSTR lpServiceStartName, // account name
  43. LPCSTR lpPassword // account password
  44. )
  45. {
  46. /*
  47. Only change it if it is currently SERVICE_AUTO_START. Do not change
  48. the IF statement to read != as there are other startup types which do
  49. not result in a circular dependency.
  50. */
  51. if (dwStartType == SERVICE_AUTO_START &&
  52. !_stricmp(lpServiceName,COMMAND_LINE))
  53. {
  54. LOGN( eDbgLevelInfo,
  55. "[CreateServiceA] Fixed startup type: %s.", lpServiceName);
  56. dwStartType = SERVICE_SYSTEM_START;
  57. }
  58. return ORIGINAL_API(CreateServiceA)(hSCManager, lpServiceName,
  59. lpDisplayName, dwDesiredAccess, dwServiceType, dwStartType,
  60. dwErrorControl, lpBinaryPathName, lpLoadOrderGroup, lpdwTagId,
  61. lpDependencies, lpServiceStartName, lpPassword);
  62. }
  63. /*++
  64. Register hooked functions
  65. --*/
  66. HOOK_BEGIN
  67. APIHOOK_ENTRY(ADVAPI32.DLL, CreateServiceA)
  68. HOOK_END
  69. IMPLEMENT_SHIM_END