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.

234 lines
6.0 KiB

  1. //+---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1998 - 2001
  5. //
  6. // File : hnetmon.cpp
  7. //
  8. // Contents : helper initialization code
  9. //
  10. // Notes :
  11. //
  12. // Author : Raghu Gatta (rgatta) 11 May 2001
  13. //
  14. //----------------------------------------------------------------------------
  15. #include "precomp.h"
  16. #pragma hdrstop
  17. //
  18. // Global variables.
  19. //
  20. HANDLE g_hModule = 0;
  21. BOOL
  22. WINAPI
  23. DllMain(
  24. HINSTANCE hInstDll,
  25. DWORD fdwReason,
  26. LPVOID pReserved
  27. )
  28. {
  29. HANDLE hDll;
  30. switch (fdwReason)
  31. {
  32. case DLL_PROCESS_ATTACH:
  33. {
  34. g_hModule = hInstDll;
  35. //DisableThreadLibraryCalls(hInstDll);
  36. break;
  37. }
  38. case DLL_PROCESS_DETACH:
  39. {
  40. //
  41. // Clean up any structures used for commit
  42. //
  43. break;
  44. }
  45. default:
  46. {
  47. break;
  48. }
  49. }
  50. return TRUE;
  51. }
  52. DWORD
  53. WINAPI
  54. InitHelperDll(
  55. IN DWORD dwNetshVersion,
  56. OUT PVOID pReserved
  57. )
  58. {
  59. DWORD dwRet;
  60. NS_HELPER_ATTRIBUTES attMyAttributes;
  61. //
  62. // Register helpers
  63. // We have a single helper only (BRIDGE)
  64. //
  65. ZeroMemory(&attMyAttributes, sizeof(attMyAttributes));
  66. attMyAttributes.dwVersion = BRIDGEMON_HELPER_VERSION;
  67. attMyAttributes.pfnStart = BridgeStartHelper;
  68. attMyAttributes.pfnStop = BridgeStopHelper;
  69. attMyAttributes.guidHelper = g_BridgeGuid;
  70. //
  71. // Specify g_RootGuid as the parent helper to indicate
  72. // that any contexts registered by this helper will be top
  73. // level contexts.
  74. //
  75. dwRet = RegisterHelper(
  76. &g_RootGuid,
  77. &attMyAttributes
  78. );
  79. return dwRet;
  80. }
  81. DWORD
  82. WINAPI
  83. BridgeStartHelper(
  84. IN CONST GUID * pguidParent,
  85. IN DWORD dwVersion
  86. )
  87. {
  88. DWORD dwRet = ERROR_INVALID_PARAMETER;
  89. NS_CONTEXT_ATTRIBUTES attMyContextAttributes;
  90. ZeroMemory(&attMyContextAttributes, sizeof(attMyContextAttributes));
  91. attMyContextAttributes.dwVersion = BRIDGEMON_HELPER_VERSION;
  92. attMyContextAttributes.dwFlags = 0;
  93. attMyContextAttributes.ulPriority = DEFAULT_CONTEXT_PRIORITY;
  94. attMyContextAttributes.pwszContext = TOKEN_BRIDGE;
  95. attMyContextAttributes.guidHelper = g_BridgeGuid;
  96. attMyContextAttributes.ulNumTopCmds = g_ulBridgeNumTopCmds;
  97. attMyContextAttributes.pTopCmds = (CMD_ENTRY (*)[])g_BridgeCmds;
  98. attMyContextAttributes.ulNumGroups = g_ulBridgeNumGroups;
  99. attMyContextAttributes.pCmdGroups = (CMD_GROUP_ENTRY (*)[])g_BridgeCmdGroups;
  100. attMyContextAttributes.pfnCommitFn = BridgeCommit;
  101. attMyContextAttributes.pfnConnectFn = BridgeConnect;
  102. attMyContextAttributes.pfnDumpFn = BridgeDump;
  103. dwRet = RegisterContext(&attMyContextAttributes);
  104. return dwRet;
  105. }
  106. DWORD
  107. WINAPI
  108. BridgeStopHelper(
  109. IN DWORD dwReserved
  110. )
  111. {
  112. return NO_ERROR;
  113. }
  114. DWORD
  115. WINAPI
  116. BridgeCommit(
  117. IN DWORD dwAction
  118. )
  119. {
  120. //
  121. // The handling of this action is admittedly simple in this example.
  122. // We simply have two copies of the data that we persist and consider
  123. // one the "online" set of data and one the "offline" set of data.
  124. // However, since neither the offline nor online sets of data need to
  125. // be "applied" to anything, it makes the distinction between them
  126. // somewhat meaningless. The scheme used to support online/offline modes
  127. // is generally left up to the developer.
  128. //
  129. switch (dwAction)
  130. {
  131. case NETSH_COMMIT:
  132. //
  133. // Change to commit mode, otherwise known as online.
  134. //
  135. break;
  136. case NETSH_UNCOMMIT:
  137. //
  138. // Change to uncommit mode, otherwise known as offline.
  139. //
  140. break;
  141. case NETSH_FLUSH:
  142. //
  143. // Flush all uncommitted changes.
  144. //
  145. break;
  146. case NETSH_SAVE:
  147. //
  148. // Save all uncommitted changes.
  149. //
  150. break;
  151. default:
  152. //
  153. // Not supported.
  154. //
  155. break;
  156. }
  157. return NO_ERROR;
  158. }
  159. DWORD
  160. WINAPI
  161. BridgeConnect(
  162. IN LPCWSTR pwszMachine
  163. )
  164. {
  165. //
  166. // This function is called whenever the machine name changes.
  167. // If the context this was called for (you can specify a connect
  168. // function on a per context basis, see RegisterContext) is
  169. // supposed to be remotable, then the helper should verify
  170. // connectivity to the machine specified by pwszMachine and
  171. // return an error if unable to reach the machine.
  172. //
  173. //
  174. // This is also where the helper might want to call RegisterContext
  175. // again on a context to remove or add commands at will. This allows
  176. // the commands in your context to be dynamic, that is, commands
  177. // may be added and removed at will. However, the versioning
  178. // functions tend to make a dynamic context unnecessary, as most
  179. // dynamic command changes are needed because of differing OS's the
  180. // commands are used on. Note that NULL for pwszMachine indicates
  181. // that the machine to be connected to is the local machine. When
  182. // and if the connect function returns an error code, the command
  183. // that was going to be executed (whether a context command or
  184. // entering a context) will fail.
  185. //
  186. //
  187. // Uncomment this line to see how often the Connect function is called
  188. // and what gets passed to it.
  189. //
  190. //PrintMessageFromModule(g_hModule, GEN_CONNECT_SHOWSTRING, pwszMachine);
  191. return NO_ERROR;
  192. }