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.

301 lines
7.3 KiB

  1. /*++
  2. Copyright (c) 1995 Microsoft Corporation
  3. Module Name:
  4. common.c
  5. Abstract:
  6. Common initialization functions for IPXPROMN.DLL
  7. Author:
  8. V Raman 1/5/1998
  9. --*/
  10. #include "precomp.h"
  11. #pragma hdrstop
  12. //
  13. // GUID for IPXPROMN.DLL
  14. //
  15. // {d3fcba3a-a4e9-11d2-b944-00c04fc2ab1c}
  16. //
  17. static const GUID g_MyGuid =
  18. {
  19. 0xd3fcba3a, 0xa4e9, 0x11d2,
  20. {
  21. 0xb9, 0x44, 0x0, 0xc0, 0x4f, 0xc2, 0xab, 0x1c
  22. }
  23. };
  24. static const GUID g_IpxGuid = IPXMONTR_GUID;
  25. #define IPXPROMON_HELPER_VERSION 1
  26. //
  27. // ipxmon functions
  28. //
  29. PIM_DEL_INFO_BLK_IF DeleteInfoBlockFromInterfaceInfo ;
  30. PIM_DEL_INFO_BLK_GLOBAL DeleteInfoBlockFromGlobalInfo ;
  31. PIM_DEL_PROTO DeleteProtocol ;
  32. PIM_GET_INFO_BLK_GLOBAL GetInfoBlockFromGlobalInfo ;
  33. PIM_GET_INFO_BLK_IF GetInfoBlockFromInterfaceInfo ;
  34. PIM_SET_INFO_BLK_GLOBAL SetInfoBlockInGlobalInfo ;
  35. PIM_SET_INFO_BLK_IF SetInfoBlockInInterfaceInfo ;
  36. PIM_IF_ENUM InterfaceEnum ;
  37. PIM_GET_IF_TYPE GetInterfaceType ;
  38. PIM_PROTO_LIST GetProtocolList ;
  39. PIM_ROUTER_STATUS IsRouterRunning ;
  40. PIM_MATCH_ROUT_PROTO MatchRoutingProtoTag ;
  41. ULONG StartedCommonInitialization, CompletedCommonInitialization ;
  42. HANDLE g_hModule;
  43. //
  44. // Handle to router being administered
  45. //
  46. HANDLE g_hMprConfig;
  47. HANDLE g_hMprAdmin;
  48. HANDLE g_hMIBServer;
  49. BOOL
  50. WINAPI
  51. DllMain(
  52. HINSTANCE hInstDll,
  53. DWORD fdwReason,
  54. LPVOID pReserved
  55. )
  56. {
  57. HANDLE hDll;
  58. switch (fdwReason)
  59. {
  60. case DLL_PROCESS_ATTACH:
  61. {
  62. // printf("Trying to attach\n");
  63. g_hModule = hInstDll;
  64. DisableThreadLibraryCalls(hInstDll);
  65. break;
  66. }
  67. case DLL_PROCESS_DETACH:
  68. {
  69. //
  70. // Clean up any structures used for commit
  71. //
  72. break;
  73. }
  74. default:
  75. {
  76. break;
  77. }
  78. }
  79. return TRUE;
  80. }
  81. BOOL
  82. IA64VersionCheck
  83. (
  84. IN UINT CIMOSType,
  85. IN UINT CIMOSProductSuite,
  86. IN LPCWSTR CIMOSVersion,
  87. IN LPCWSTR CIMOSBuildNumber,
  88. IN LPCWSTR CIMServicePackMajorVersion,
  89. IN LPCWSTR CIMServicePackMinorVersion,
  90. IN UINT CIMProcessorArchitecture,
  91. IN DWORD dwReserved
  92. )
  93. {
  94. if (CIMProcessorArchitecture == PROCESSOR_ARCHITECTURE_INTEL)// IA64=6 (x86 == 0)
  95. return TRUE;
  96. else
  97. return FALSE;
  98. }
  99. DWORD
  100. WINAPI
  101. IpxpromonStartHelper(
  102. IN CONST GUID *pguidParent,
  103. IN DWORD dwVersion
  104. )
  105. {
  106. DWORD dwErr;
  107. NS_CONTEXT_ATTRIBUTES attMyAttributes;
  108. //
  109. // If you add any more contexts, then this should be converted
  110. // to use an array instead of duplicating code!
  111. //
  112. //
  113. // Register the RIP context
  114. //
  115. ZeroMemory(&attMyAttributes, sizeof(attMyAttributes));
  116. attMyAttributes.pwszContext = L"rip";
  117. attMyAttributes.guidHelper = g_MyGuid;
  118. attMyAttributes.dwVersion = 1;
  119. attMyAttributes.dwFlags = 0;
  120. attMyAttributes.ulNumTopCmds= 0;
  121. attMyAttributes.pTopCmds = NULL;
  122. attMyAttributes.ulNumGroups = g_ulIpxRipNumGroups;
  123. attMyAttributes.pCmdGroups = (CMD_GROUP_ENTRY (*)[])&g_IpxRipCmdGroups;
  124. attMyAttributes.pfnDumpFn = IpxRipDump;
  125. attMyAttributes.pfnConnectFn= ConnectToRouter;
  126. attMyAttributes.pfnOsVersionCheck = IA64VersionCheck;
  127. dwErr = RegisterContext( &attMyAttributes );
  128. //
  129. // Register the SAP context
  130. //
  131. ZeroMemory(&attMyAttributes, sizeof(attMyAttributes));
  132. attMyAttributes.pwszContext = L"sap";
  133. attMyAttributes.guidHelper = g_MyGuid;
  134. attMyAttributes.dwVersion = 1;
  135. attMyAttributes.dwFlags = 0;
  136. attMyAttributes.ulNumTopCmds= 0;
  137. attMyAttributes.pTopCmds = NULL;
  138. attMyAttributes.ulNumGroups = g_ulIpxSapNumGroups;
  139. attMyAttributes.pCmdGroups = (CMD_GROUP_ENTRY (*)[])&g_IpxSapCmdGroups;
  140. attMyAttributes.pfnDumpFn = IpxSapDump;
  141. attMyAttributes.pfnConnectFn= ConnectToRouter;
  142. attMyAttributes.pfnOsVersionCheck = IA64VersionCheck;
  143. dwErr = RegisterContext( &attMyAttributes );
  144. //
  145. // Register the NB context
  146. //
  147. ZeroMemory(&attMyAttributes, sizeof(attMyAttributes));
  148. attMyAttributes.pwszContext = L"netbios";
  149. attMyAttributes.guidHelper = g_MyGuid;
  150. attMyAttributes.dwVersion = 1;
  151. attMyAttributes.dwFlags = 0;
  152. attMyAttributes.ulNumTopCmds= 0;
  153. attMyAttributes.pTopCmds = NULL;
  154. attMyAttributes.ulNumGroups = g_ulIpxNbNumGroups;
  155. attMyAttributes.pCmdGroups = (CMD_GROUP_ENTRY (*)[])&g_IpxNbCmdGroups;
  156. attMyAttributes.pfnDumpFn = IpxNbDump;
  157. attMyAttributes.pfnConnectFn= ConnectToRouter;
  158. attMyAttributes.pfnOsVersionCheck = IA64VersionCheck;
  159. dwErr = RegisterContext( &attMyAttributes );
  160. return dwErr;
  161. }
  162. DWORD WINAPI
  163. InitHelperDll(
  164. IN DWORD dwNetshVersion,
  165. OUT PNS_DLL_ATTRIBUTES pDllTable
  166. )
  167. {
  168. DWORD dwErr;
  169. NS_HELPER_ATTRIBUTES attMyAttributes;
  170. pDllTable->dwVersion = NETSH_VERSION_50;
  171. pDllTable->pfnStopFn = NULL;
  172. //
  173. // Register helpers. We could either register 1 helper which
  174. // registers three contexts, or we could register 3 helpers
  175. // which each register one context. There's only a difference
  176. // if we support sub-helpers, which this DLL does not.
  177. // If we later support sub-helpers, then it's better to have
  178. // 3 helpers so that sub-helpers can register with 1 of them,
  179. // since it registers with a parent helper, not a parent context.
  180. // For now, we just use a single 3-context helper for efficiency.
  181. //
  182. ZeroMemory( &attMyAttributes, sizeof(attMyAttributes) );
  183. attMyAttributes.guidHelper = g_MyGuid;
  184. attMyAttributes.dwVersion = IPXPROMON_HELPER_VERSION;
  185. attMyAttributes.pfnStart = IpxpromonStartHelper;
  186. attMyAttributes.pfnStop = NULL;
  187. dwErr = RegisterHelper( &g_IpxGuid, &attMyAttributes );
  188. return dwErr;
  189. }
  190. DWORD WINAPI
  191. ConnectToRouter(
  192. IN LPCWSTR pwszRouter
  193. )
  194. {
  195. DWORD dwErr;
  196. //
  197. // Connect to router config if required
  198. // (when is this ever required)
  199. //
  200. if ( !g_hMprConfig )
  201. {
  202. dwErr = MprConfigServerConnect( (LPWSTR)pwszRouter, &g_hMprConfig );
  203. if ( dwErr isnot NO_ERROR )
  204. {
  205. return ERROR_CONNECT_REMOTE_CONFIG;
  206. }
  207. }
  208. //
  209. // Check to see if router is running. If so, get the handles
  210. //
  211. do
  212. {
  213. if ( MprAdminIsServiceRunning( (LPWSTR)pwszRouter ) )
  214. {
  215. if ( MprAdminServerConnect( (LPWSTR)pwszRouter, &g_hMprAdmin ) ==
  216. NO_ERROR )
  217. {
  218. if ( MprAdminMIBServerConnect( (LPWSTR)pwszRouter, &g_hMIBServer ) ==
  219. NO_ERROR )
  220. {
  221. // DEBUG("Got server handle");
  222. break;
  223. }
  224. else
  225. {
  226. MprAdminServerDisconnect( g_hMprAdmin );
  227. }
  228. }
  229. }
  230. g_hMprAdmin = g_hMIBServer = NULL;
  231. } while (FALSE);
  232. return NO_ERROR;
  233. }
  234.