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.

226 lines
5.8 KiB

  1. /********************************************************************/
  2. /** Copyright(c) 1985-1997 Microsoft Corporation. **/
  3. /********************************************************************/
  4. //***
  5. //
  6. // Filename: pnphand.c
  7. //
  8. // Description: Will receive and handle pnp notifications to add/remove devices
  9. //
  10. // History: May 11,1997 NarenG Created original version.
  11. //
  12. #include "ddm.h"
  13. #include "timer.h"
  14. #include "handlers.h"
  15. #include "objects.h"
  16. #include "util.h"
  17. #include "routerif.h"
  18. #include <raserror.h>
  19. #include <rassrvr.h>
  20. #include <rasppp.h>
  21. #include <ddmif.h>
  22. #include <serial.h>
  23. #include <string.h>
  24. #include <stdlib.h>
  25. #include <memory.h>
  26. //**
  27. //
  28. // Call: DdmDevicePnpHandler
  29. //
  30. // Returns: NO_ERROR - Success
  31. // Non-zero returns - Failure
  32. //
  33. // Description: Will handle and act upon a device addition or removal.
  34. //
  35. DWORD
  36. DdmDevicePnpHandler(
  37. HANDLE pdwArg
  38. )
  39. {
  40. PNP_EVENT_NOTIF * ppnpEvent = ( PPNP_EVENT_NOTIF )pdwArg;
  41. PPP_MESSAGE PppMessage;
  42. ZeroMemory( &PppMessage, sizeof( PppMessage ) );
  43. PppMessage.dwMsgId = PPPDDMMSG_PnPNotification;
  44. PppMessage.ExtraInfo.DdmPnPNotification.PnPNotification = *ppnpEvent;
  45. SendPppMessageToDDM( &PppMessage );
  46. LocalFree( ppnpEvent );
  47. return( NO_ERROR );
  48. }
  49. //**
  50. //
  51. // Call: ChangeNotificationEventHandler
  52. //
  53. // Returns: NO_ERROR - Success
  54. // Non-zero returns - Failure
  55. //
  56. // Description:
  57. //
  58. VOID
  59. ChangeNotificationEventHandler(
  60. VOID
  61. )
  62. {
  63. DWORD dwRetCode;
  64. BOOL fIpAllowed = FALSE;
  65. DDMTRACE( "ChangeNotificationEventHandler called" );
  66. dwRetCode = LoadDDMParameters( gblDDMConfigInfo.hkeyParameters,
  67. &fIpAllowed );
  68. DeviceObjIterator( DeviceObjForceIpSec, FALSE, NULL );
  69. if ( fIpAllowed && ( !gblDDMConfigInfo.fRasSrvrInitialized ) )
  70. {
  71. dwRetCode = RasSrvrInitialize(
  72. gblDDMConfigInfo.lpfnMprAdminGetIpAddressForUser,
  73. gblDDMConfigInfo.lpfnMprAdminReleaseIpAddress );
  74. if ( dwRetCode != NO_ERROR )
  75. {
  76. DDMLogErrorString( ROUTERLOG_CANT_INITIALIZE_IP_SERVER,
  77. 0, NULL, dwRetCode, 0 );
  78. }
  79. else
  80. {
  81. gblDDMConfigInfo.fRasSrvrInitialized = TRUE;
  82. }
  83. }
  84. if ( NULL != gblDDMConfigInfo.lpfnRasAuthConfigChangeNotification )
  85. {
  86. gblDDMConfigInfo.lpfnRasAuthConfigChangeNotification(
  87. gblDDMConfigInfo.dwLoggingLevel );
  88. }
  89. if ( NULL != gblDDMConfigInfo.lpfnRasAcctConfigChangeNotification )
  90. {
  91. gblDDMConfigInfo.lpfnRasAcctConfigChangeNotification(
  92. gblDDMConfigInfo.dwLoggingLevel );
  93. }
  94. PppDdmChangeNotification( gblDDMConfigInfo.dwServerFlags,
  95. gblDDMConfigInfo.dwLoggingLevel );
  96. RegNotifyChangeKeyValue( gblDDMConfigInfo.hkeyParameters,
  97. TRUE,
  98. REG_NOTIFY_CHANGE_LAST_SET,
  99. gblSupervisorEvents[DDM_EVENT_CHANGE_NOTIFICATION],
  100. TRUE );
  101. RegNotifyChangeKeyValue( gblDDMConfigInfo.hkeyAccounting,
  102. TRUE,
  103. REG_NOTIFY_CHANGE_LAST_SET,
  104. gblSupervisorEvents[DDM_EVENT_CHANGE_NOTIFICATION1],
  105. TRUE );
  106. RegNotifyChangeKeyValue( gblDDMConfigInfo.hkeyAuthentication,
  107. TRUE,
  108. REG_NOTIFY_CHANGE_LAST_SET,
  109. gblSupervisorEvents[DDM_EVENT_CHANGE_NOTIFICATION2],
  110. TRUE );
  111. }
  112. //**
  113. //
  114. // Call: DDMTransportCreate
  115. //
  116. // Returns: NO_ERROR - Success
  117. // Non-zero returns - Failure
  118. //
  119. // Description:
  120. //
  121. DWORD
  122. DDMTransportCreate(
  123. IN DWORD dwTransportId
  124. )
  125. {
  126. static const TCHAR c_szRegKeyRemoteAccessParams[]
  127. = TEXT("SYSTEM\\CurrentControlSet\\Services\\RemoteAccess\\Parameters");
  128. DWORD dwRetCode = NO_ERROR;
  129. BOOL fEnabled = FALSE;
  130. HKEY hKey = NULL;
  131. DDMTRACE1( "DDMTransportCreate called for Transport Id = %d", dwTransportId );
  132. //
  133. // Find out if this transport is set to allow for dialin clients
  134. //
  135. dwRetCode = RegOpenKey( HKEY_LOCAL_MACHINE, c_szRegKeyRemoteAccessParams, &hKey );
  136. if ( dwRetCode != NO_ERROR )
  137. {
  138. return( dwRetCode );
  139. }
  140. dwRetCode = lProtocolEnabled( hKey, dwTransportId, TRUE, FALSE, &fEnabled );
  141. if ( dwRetCode != NO_ERROR )
  142. {
  143. return( dwRetCode );
  144. }
  145. RegCloseKey( hKey );
  146. //
  147. // Not enabled for dialin so we are done
  148. //
  149. if ( !fEnabled )
  150. {
  151. return( NO_ERROR );
  152. }
  153. if ( ( dwTransportId == PID_IP ) && ( !gblDDMConfigInfo.fRasSrvrInitialized ) )
  154. {
  155. dwRetCode = RasSrvrInitialize(
  156. gblDDMConfigInfo.lpfnMprAdminGetIpAddressForUser,
  157. gblDDMConfigInfo.lpfnMprAdminReleaseIpAddress );
  158. if ( dwRetCode != NO_ERROR )
  159. {
  160. DDMLogErrorString( ROUTERLOG_CANT_INITIALIZE_IP_SERVER,
  161. 0, NULL, dwRetCode, 0 );
  162. }
  163. else
  164. {
  165. gblDDMConfigInfo.fRasSrvrInitialized = TRUE;
  166. }
  167. }
  168. //
  169. // Insert allowed protocols in the ServerFlags which will be sent to PPP engine
  170. //
  171. switch( dwTransportId )
  172. {
  173. case PID_IP:
  174. gblDDMConfigInfo.dwServerFlags |= PPPCFG_ProjectIp;
  175. break;
  176. case PID_IPX:
  177. gblDDMConfigInfo.dwServerFlags |= PPPCFG_ProjectIpx;
  178. break;
  179. case PID_ATALK:
  180. gblDDMConfigInfo.dwServerFlags |= PPPCFG_ProjectAt;
  181. break;
  182. default:
  183. break;
  184. }
  185. PppDdmChangeNotification( gblDDMConfigInfo.dwServerFlags,
  186. gblDDMConfigInfo.dwLoggingLevel );
  187. return( dwRetCode );
  188. }