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.

205 lines
4.4 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. DNS_STATUS
  19. Dns_SendServiceControl(
  20. IN PWSTR pwsServiceName,
  21. IN DWORD Access,
  22. IN DWORD Control
  23. )
  24. {
  25. DWORD status = ERROR_INVALID_PARAMETER;
  26. SC_HANDLE hmanager = NULL;
  27. SC_HANDLE hservice = NULL;
  28. SERVICE_STATUS serviceStatus;
  29. DNSDBG( ANY, (
  30. "Dns_SendServiceControl( %S, %08x, %08x )\n",
  31. pwsServiceName,
  32. Access,
  33. Control ));
  34. hmanager = OpenSCManagerW(
  35. NULL,
  36. NULL,
  37. SC_MANAGER_CONNECT );
  38. if ( !hmanager )
  39. {
  40. DNSDBG( ANY, (
  41. "ERROR: OpenSCManager( SC_MANAGER_CONNECT ) failed %d\n",
  42. GetLastError() ));
  43. goto Cleanup;
  44. }
  45. hservice = OpenServiceW(
  46. hmanager,
  47. pwsServiceName,
  48. Access );
  49. if ( !hservice )
  50. {
  51. DNSDBG( ANY, (
  52. "ERROR: OpenService( %S, %08x ) failed %d\n",
  53. pwsServiceName,
  54. Access,
  55. GetLastError() ));
  56. goto Cleanup;
  57. }
  58. if ( !ControlService(
  59. hservice,
  60. Control,
  61. &serviceStatus ) )
  62. {
  63. DNSDBG( ANY, (
  64. "ERROR: ControlService( %08x ) failed %d\n",
  65. Control,
  66. GetLastError() ));
  67. goto Cleanup;
  68. }
  69. status = NO_ERROR;
  70. Cleanup:
  71. if ( status != NO_ERROR )
  72. {
  73. status = GetLastError();
  74. }
  75. if ( hservice )
  76. {
  77. CloseServiceHandle( hservice );
  78. }
  79. if ( hmanager )
  80. {
  81. CloseServiceHandle( hmanager );
  82. }
  83. DNSDBG( ANY, (
  84. "Leave Dns_SendServiceControl( %S, %08x, %08x ) => %d\n",
  85. pwsServiceName,
  86. Access,
  87. Control,
  88. status ));
  89. return status;
  90. }
  91. VOID
  92. DnsNotifyResolver(
  93. IN DWORD Flag,
  94. IN PVOID pReserved
  95. )
  96. /*++
  97. Routine Description:
  98. Notify resolver of configuration change.
  99. This allows it to wakeup and refresh its informatio and\or dump
  100. the cache and rebuild info.
  101. Arguments:
  102. Flag -- unused
  103. pReserved -- unused
  104. Return Value:
  105. None
  106. --*/
  107. {
  108. UNREFERENCED_PARAMETER( Flag );
  109. UNREFERENCED_PARAMETER( pReserved );
  110. DNSDBG( ANY, (
  111. "\nDnsNotifyResolver()\n"
  112. "\tFlag = %08x\n"
  113. "\tpReserved = %p\n"
  114. "\tTickCount = %d\n",
  115. Flag,
  116. pReserved,
  117. GetTickCount() ));
  118. //
  119. // wake the resolver
  120. //
  121. Dns_SendServiceControl(
  122. DNS_RESOLVER_SERVICE,
  123. SERVICE_USER_DEFINED_CONTROL,
  124. SERVICE_CONTROL_PARAMCHANGE );
  125. //
  126. // DCR: hack for busted resolver permissions
  127. //
  128. // DCR: network change notifications
  129. // this is a poor mechanism for handling notification
  130. // - this should happen directly through SCM
  131. // - it won't work for IPv6 or anything else
  132. // probably need to move to IPHlpApi
  133. //
  134. // notify resolver
  135. // also notify DNS server, but wait briefly to allow resolver
  136. // to handle the changes as i'm not sure that the server
  137. // doesn't call a resolver API to do it's read
  138. // note, the reason the resolver doesn't notify the DNS
  139. // server is that since Jon Schwartz moved the resolver to
  140. // NetworkService account, attempts to open the SCM to
  141. // notify the DNS server all fail
  142. //
  143. // DCR: make sure server calls directly to avoid race
  144. // DCR: make sure g_IsDnsServer is current
  145. //
  146. g_IsDnsServer = Reg_IsMicrosoftDnsServer();
  147. if ( g_IsDnsServer )
  148. {
  149. Sleep( 1000 );
  150. Dns_SendServiceControl(
  151. DNS_SERVER_SERVICE,
  152. SERVICE_USER_DEFINED_CONTROL,
  153. SERVICE_CONTROL_PARAMCHANGE );
  154. }
  155. }
  156. //
  157. // End srvcntl.c
  158. //