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.

220 lines
5.7 KiB

  1. #include "precomp.h"
  2. #pragma hdrstop
  3. // {8854ff10-d504-11d2-b1ff-00104bc54139}
  4. static const GUID g_MyGuid =
  5. { 0x8854ff10, 0xd504, 0x11d2, { 0xb1, 0xff, 0x0, 0x10, 0x4b, 0xc5, 0x41, 0x39 } };
  6. static const GUID g_IpGuid = IPMONTR_GUID;
  7. #define IPPREVIEW_HELPER_VERSION 1
  8. // shell functions
  9. HANDLE g_hModule;
  10. MIB_SERVER_HANDLE g_hMibServer;
  11. VALUE_STRING CommonBooleanStringArray[] = {
  12. TRUE, STRING_ENABLED,
  13. FALSE, STRING_DISABLED
  14. };
  15. VALUE_TOKEN CommonBooleanTokenArray[] = {
  16. TRUE, TOKEN_OPT_VALUE_ENABLE,
  17. FALSE, TOKEN_OPT_VALUE_DISABLE
  18. };
  19. VALUE_STRING CommonLoggingStringArray[] = {
  20. VRRP_LOGGING_NONE, STRING_LOGGING_NONE,
  21. VRRP_LOGGING_ERROR, STRING_LOGGING_ERROR,
  22. VRRP_LOGGING_WARN, STRING_LOGGING_WARN,
  23. VRRP_LOGGING_INFO, STRING_LOGGING_INFO
  24. };
  25. VALUE_TOKEN CommonLoggingTokenArray[] = {
  26. VRRP_LOGGING_NONE, TOKEN_OPT_VALUE_NONE,
  27. VRRP_LOGGING_ERROR, TOKEN_OPT_VALUE_ERROR,
  28. VRRP_LOGGING_WARN, TOKEN_OPT_VALUE_WARN,
  29. VRRP_LOGGING_INFO, TOKEN_OPT_VALUE_INFO
  30. };
  31. BOOL WINAPI
  32. DllMain(
  33. HINSTANCE hInstDll,
  34. DWORD fdwReason,
  35. LPVOID pReserved
  36. )
  37. {
  38. HANDLE hDll;
  39. switch (fdwReason)
  40. {
  41. case DLL_PROCESS_ATTACH:
  42. {
  43. // printf("Trying to attach\n");
  44. g_hModule = hInstDll;
  45. DisableThreadLibraryCalls(hInstDll);
  46. break;
  47. }
  48. case DLL_PROCESS_DETACH:
  49. {
  50. //
  51. // Clean up any structures used for commit
  52. //
  53. break;
  54. }
  55. default:
  56. {
  57. break;
  58. }
  59. }
  60. return TRUE;
  61. }
  62. DWORD WINAPI
  63. IpprvwmonStartHelper(
  64. IN CONST GUID *pguidParent,
  65. IN DWORD dwVersion
  66. )
  67. {
  68. DWORD dwErr;
  69. IP_CONTEXT_ATTRIBUTES attMyAttributes;
  70. ZeroMemory(&attMyAttributes, sizeof(attMyAttributes));
  71. // If you add any more contexts, then this should be converted
  72. // to use an array instead of duplicating code!
  73. attMyAttributes.pwszContext = L"vrrp";
  74. attMyAttributes.guidHelper = g_MyGuid;
  75. attMyAttributes.dwVersion = 1;
  76. attMyAttributes.dwFlags = 0;
  77. attMyAttributes.pfnDumpFn = VrrpDump;
  78. attMyAttributes.ulNumTopCmds= g_VrrpTopCmdCount;
  79. attMyAttributes.pTopCmds = (CMD_ENTRY (*)[])&g_VrrpTopCmdTable;
  80. attMyAttributes.ulNumGroups = g_VrrpCmdGroupCount;
  81. attMyAttributes.pCmdGroups = (CMD_GROUP_ENTRY (*)[])&g_VrrpCmdGroupTable;
  82. dwErr = RegisterContext( &attMyAttributes );
  83. attMyAttributes.pwszContext = L"msdp";
  84. attMyAttributes.dwVersion = 1;
  85. attMyAttributes.dwFlags = 0;
  86. attMyAttributes.pfnDumpFn = MsdpDump;
  87. attMyAttributes.ulNumTopCmds= g_MsdpTopCmdCount;
  88. attMyAttributes.pTopCmds = (CMD_ENTRY (*)[])&g_MsdpTopCmdTable;
  89. attMyAttributes.ulNumGroups = g_MsdpCmdGroupCount;
  90. attMyAttributes.pCmdGroups = (CMD_GROUP_ENTRY (*)[])&g_MsdpCmdGroupTable;
  91. dwErr = RegisterContext( &attMyAttributes );
  92. return dwErr;
  93. }
  94. DWORD WINAPI
  95. InitHelperDll(
  96. IN DWORD dwNetshVersion,
  97. OUT PNS_DLL_ATTRIBUTES pDllTable
  98. )
  99. {
  100. DWORD dwErr;
  101. NS_HELPER_ATTRIBUTES attMyAttributes;
  102. pDllTable->dwVersion = NETSH_VERSION_50;
  103. pDllTable->pfnStopFn = NULL;
  104. // Register helpers. We could either register 1 helper which
  105. // registers three contexts, or we could register 3 helpers
  106. // which each register one context. There's only a difference
  107. // if we support sub-helpers, which this DLL does not.
  108. // If we later support sub-helpers, then it's better to have
  109. // 3 helpers so that sub-helpers can register with 1 of them,
  110. // since it registers with a parent helper, not a parent context.
  111. // For now, we just use a single 3-context helper for efficiency.
  112. ZeroMemory( &attMyAttributes, sizeof(attMyAttributes) );
  113. attMyAttributes.guidHelper = g_MyGuid;
  114. attMyAttributes.dwVersion = IPPREVIEW_HELPER_VERSION;
  115. attMyAttributes.pfnStart = IpprvwmonStartHelper;
  116. attMyAttributes.pfnStop = NULL;
  117. dwErr = RegisterHelper( &g_IpGuid, &attMyAttributes );
  118. return dwErr;
  119. }
  120. BOOL
  121. IsProtocolInstalled(
  122. DWORD dwProtoId,
  123. WCHAR *pwszName
  124. )
  125. {
  126. PVOID pvStart;
  127. DWORD dwCount, dwBlkSize, dwRes;
  128. dwRes = IpmontrGetInfoBlockFromGlobalInfo(dwProtoId,
  129. (PBYTE *) NULL,
  130. &dwBlkSize,
  131. &dwCount);
  132. if (dwRes isnot NO_ERROR)
  133. {
  134. DisplayError(g_hModule, EMSG_PROTO_NOT_INSTALLED, pwszName);
  135. return FALSE;
  136. }
  137. return TRUE;
  138. }
  139. DWORD
  140. GetMIBIfIndex(
  141. IN PTCHAR *pptcArguments,
  142. IN DWORD dwCurrentIndex,
  143. OUT PDWORD pdwIndices,
  144. OUT PDWORD pdwNumParsed
  145. )
  146. /*++
  147. Routine Description:
  148. Gets the interface index.
  149. Arguments:
  150. pptcArguments - Argument array
  151. dwCurrentIndex - Index of the first argument in array
  152. pdwIndices - Indices specified in command
  153. pdwNumParsed - Number of indices in command
  154. Return Value:
  155. NO_ERROR
  156. --*/
  157. {
  158. DWORD dwErr = NO_ERROR;
  159. *pdwNumParsed = 1;
  160. // If index was specified just use it
  161. if (iswdigit(pptcArguments[dwCurrentIndex][0]))
  162. {
  163. pdwIndices[0] = _tcstoul(pptcArguments[dwCurrentIndex],NULL,10);
  164. return NO_ERROR;
  165. }
  166. // Try converting a friendly name to an ifindex
  167. return IpmontrGetIfIndexFromFriendlyName( g_hMibServer,
  168. pptcArguments[dwCurrentIndex],
  169. &pdwIndices[0] );
  170. }