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.

167 lines
3.6 KiB

  1. /*++
  2. Copyright (c) 1994-2001 Microsoft Corporation
  3. Module Name:
  4. svccntl.c
  5. Abstract:
  6. Domain Name System (DNS) API
  7. Service control routines.
  8. Author:
  9. Glenn Curtis (glennc) 05-Jul-1997
  10. Revision History:
  11. Jim Gilroy (jamesg) March 2000 -- resolver notify
  12. --*/
  13. #include "local.h"
  14. //
  15. // DCR_CLEANUP: identical ServiceControl routine is in resolver
  16. // - should either expose in dnsapi.dll or in dnslib.h
  17. //
  18. DWORD
  19. _fastcall
  20. SendServiceControl(
  21. IN LPWSTR pszServiceName,
  22. IN DWORD dwControl
  23. )
  24. {
  25. DWORD Status = NO_ERROR;
  26. SC_HANDLE scManagerHandle = NULL;
  27. SC_HANDLE scServiceHandle = NULL;
  28. SERVICE_STATUS ServiceStatus;
  29. DNSDBG( ANY, (
  30. "SendServiceControl( %S, %08x )\n",
  31. pszServiceName,
  32. dwControl ));
  33. scManagerHandle = OpenSCManagerW( NULL,
  34. NULL,
  35. SC_MANAGER_ALL_ACCESS );
  36. // SC_MANAGER_CONNECT );
  37. if ( !scManagerHandle )
  38. return GetLastError();
  39. scServiceHandle = OpenServiceW( scManagerHandle,
  40. pszServiceName,
  41. SERVICE_ALL_ACCESS );
  42. // SERVICE_CHANGE_CONFIG );
  43. if ( !scServiceHandle )
  44. {
  45. CloseServiceHandle( scManagerHandle );
  46. return GetLastError();
  47. }
  48. if ( !ControlService( scServiceHandle,
  49. dwControl,
  50. &ServiceStatus ) )
  51. {
  52. Status = GetLastError();
  53. }
  54. CloseServiceHandle( scServiceHandle );
  55. CloseServiceHandle( scManagerHandle );
  56. return Status;
  57. }
  58. VOID
  59. DnsNotifyResolver(
  60. IN DWORD Flag,
  61. IN PVOID pReserved
  62. )
  63. /*++
  64. Routine Description:
  65. Notify resolver of configuration change.
  66. This allows it to wakeup and refresh its informatio and\or dump
  67. the cache and rebuild info.
  68. Arguments:
  69. Flag -- unused
  70. pReserved -- unused
  71. Return Value:
  72. None
  73. --*/
  74. {
  75. UNREFERENCED_PARAMETER( Flag );
  76. UNREFERENCED_PARAMETER( pReserved );
  77. DNSDBG( ANY, (
  78. "\nDnsNotifyResolver()\n"
  79. "\tFlag = %08x\n"
  80. "\tpReserved = %p\n"
  81. "\tTickCount = %d\n",
  82. Flag,
  83. pReserved,
  84. GetTickCount() ));
  85. //
  86. // wake the resolver
  87. //
  88. SendServiceControl(
  89. DNS_RESOLVER_SERVICE,
  90. SERVICE_CONTROL_PARAMCHANGE );
  91. //
  92. // DCR: hack for busted resolver permissions
  93. //
  94. // DCR: network change notifications
  95. // this is a poor mechanism for handling notification
  96. // - this should happen directly through SCM
  97. // - it won't work for IPv6 or anything else
  98. // probably need to move to IPHlpApi
  99. //
  100. // notify resolver
  101. // also notify DNS server, but wait briefly to allow resolver
  102. // to handle the changes as i'm not sure that the server
  103. // doesn't call a resolver API to do it's read
  104. // note, the reason the resolver doesn't notify the DNS
  105. // server is that since Jon Schwartz moved the resolver to
  106. // NetworkService account, attempts to open the SCM to
  107. // notify the DNS server all fail
  108. //
  109. // DCR: make sure server calls directly to avoid race
  110. // DCR: make sure g_IsDnsServer is current
  111. //
  112. g_IsDnsServer = Reg_IsMicrosoftDnsServer();
  113. if ( g_IsDnsServer )
  114. {
  115. Sleep( 1000 );
  116. SendServiceControl(
  117. DNS_SERVER_SERVICE,
  118. SERVICE_CONTROL_PARAMCHANGE );
  119. }
  120. }
  121. //
  122. // End srvcntl.c
  123. //