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.

117 lines
3.3 KiB

  1. #include "precomp.h"
  2. #include "nlasvc.h"
  3. #include "nlanotif.h"
  4. CRITICAL_SECTION gNLA_LPC_CS;
  5. HANDLE ghNLA_LPC_Port = NULL;
  6. HANDLE
  7. NLAConnectLPC()
  8. {
  9. // Connect via LPC to the Winsock Mobility system service.
  10. HANDLE h = NULL;
  11. SECURITY_QUALITY_OF_SERVICE DynamicQoS =
  12. {
  13. sizeof(SECURITY_QUALITY_OF_SERVICE),
  14. SecurityAnonymous,
  15. SECURITY_DYNAMIC_TRACKING,
  16. FALSE
  17. };
  18. WSM_LPC_DATA data;
  19. ULONG dataLength = sizeof(data);
  20. UNICODE_STRING portName;
  21. DWORD retCode;
  22. DhcpPrint((DEBUG_TRACK, "Entering NLAConnectLPC.\n"));
  23. RtlZeroMemory(&data, sizeof(data));
  24. data.signature = WSM_SIGNATURE;
  25. data.connect.version.major = WSM_VERSION_MAJOR;
  26. data.connect.version.minor = WSM_VERSION_MINOR;
  27. RtlInitUnicodeString(&portName, WSM_PRIVATE_PORT_NAME);
  28. retCode = NtConnectPort(
  29. &h,
  30. &portName,
  31. &DynamicQoS,
  32. NULL,
  33. NULL,
  34. NULL,
  35. &data, &dataLength);
  36. if ( retCode != STATUS_SUCCESS)
  37. {
  38. DhcpPrint((DEBUG_TRACK, "NtConnectPort failed with errCode 0x%08x.\n", retCode));
  39. if (h != NULL)
  40. {
  41. CloseHandle(h);
  42. h = NULL;
  43. }
  44. }
  45. DhcpPrint((DEBUG_TRACK, "Exiting NLAConnectLPC.\n"));
  46. return (h);
  47. } // NLAConnectLPC
  48. void
  49. NLANotifyDHCPChange()
  50. {
  51. WSM_LPC_MESSAGE message;
  52. DWORD retCode;
  53. DhcpPrint((DEBUG_TRACK, "Entering NLANotifyDHCPChange.\n"));
  54. EnterCriticalSection(&gNLA_LPC_CS);
  55. // Connect to the NLA service if necessary.
  56. if (ghNLA_LPC_Port == NULL)
  57. {
  58. if ((ghNLA_LPC_Port = NLAConnectLPC()) == NULL)
  59. {
  60. LeaveCriticalSection(&gNLA_LPC_CS);
  61. DhcpPrint((DEBUG_TRACK, "Exiting NLANotifyDHCPChange as 1st call to NLAConnectLPC() failed.\n"));
  62. return;
  63. }
  64. }
  65. // Send change notification to the NLA service.
  66. RtlZeroMemory(&message, sizeof(message));
  67. message.portMsg.u1.s1.TotalLength = sizeof(message);
  68. message.portMsg.u1.s1.DataLength = sizeof(message.data);
  69. message.data.signature = WSM_SIGNATURE;
  70. message.data.request.type = DHCP_NOTIFY_CHANGE; //WSM_LPC_REQUEST::DHCP_NOTIFY_CHANGE;
  71. retCode = NtRequestPort(ghNLA_LPC_Port, (PPORT_MESSAGE)&message);
  72. if (retCode != STATUS_SUCCESS)
  73. {
  74. DhcpPrint((DEBUG_TRACK, "NLANotifyDHCPChange: NtRequestPort failed with errCode 0x%08x.\n", retCode));
  75. // It's possible the service was stopped and restarted.
  76. // Ditch the old LPC connection.
  77. CloseHandle(ghNLA_LPC_Port);
  78. // Create a new LPC connection.
  79. if ((ghNLA_LPC_Port = NLAConnectLPC()) == NULL)
  80. {
  81. LeaveCriticalSection(&gNLA_LPC_CS);
  82. DhcpPrint((DEBUG_TRACK, "Exiting NLANotifyDHCPChange as 2nd call to NLAConnectLPC() failed.\n"));
  83. return;
  84. }
  85. // Try the notification one last time.
  86. NtRequestPort(ghNLA_LPC_Port, (PPORT_MESSAGE)&message);
  87. }
  88. LeaveCriticalSection(&gNLA_LPC_CS);
  89. DhcpPrint((DEBUG_TRACK, "Exiting NLANotifyDHCPChange.\n"));
  90. } // NLANotifyDHCPChange