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.

298 lines
6.9 KiB

  1. //////////////////////////////////////////////////////////////////////////////
  2. //
  3. // Copyright (c) 1998 Microsoft Corporation
  4. //
  5. // Module Name:
  6. //
  7. // aaaamon.c
  8. //
  9. // Abstract:
  10. //
  11. // Main aaaamon file.
  12. //
  13. // Revision History:
  14. //
  15. // pmay
  16. // Thierry Perraut 04/02/1999
  17. //
  18. //////////////////////////////////////////////////////////////////////////////
  19. #define AAAA_HELPER_VERSION 1
  20. #include <windows.h>
  21. #include "strdefs.h"
  22. #include "rmstring.h"
  23. #include <netsh.h>
  24. #include "aaaamontr.h"
  25. #include "context.h"
  26. #include "aaaahndl.h"
  27. #include "aaaaconfig.h"
  28. #include "aaaaversion.h"
  29. GUID g_AaaamontrGuid = AAAAMONTR_GUID;
  30. GUID g_NetshGuid = NETSH_ROOT_GUID;
  31. //
  32. // Reminder
  33. //
  34. // #define CREATE_CMD_ENTRY(t,f) {CMD_##t, f, HLP_##t, HLP_##t##_EX, CMD_FLAG_PRIVATE}
  35. // #define CREATE_CMD_ENTRY_EX(t,f,i) {CMD_##t, f, HLP_##t, HLP_##t##_EX, i}
  36. // #define CMD_FLAG_PRIVATE 0x01 // not valid in sub-contexts
  37. // #define CMD_FLAG_INTERACTIVE 0x02 // not valid from outside netsh
  38. // #define CMD_FLAG_IMMEDIATE 0x04 // not valid from ancestor contexts
  39. // #define CMD_FLAG_LOCAL 0x08 // not valid from a remote machine
  40. // #define CMD_FLAG_ONLINE 0x10 // not valid in offline/non-commit mode
  41. CMD_ENTRY g_AaaaSetCmdTable[] =
  42. {
  43. CREATE_CMD_ENTRY_EX(AAAACONFIG_SET, HandleAaaaConfigSet,(CMD_FLAG_PRIVATE | CMD_FLAG_ONLINE)),
  44. };
  45. CMD_ENTRY g_AaaaShowCmdTable[] =
  46. {
  47. CREATE_CMD_ENTRY_EX(AAAACONFIG_SHOW, HandleAaaaConfigShow,(CMD_FLAG_PRIVATE | CMD_FLAG_ONLINE)),
  48. CREATE_CMD_ENTRY_EX(AAAAVERSION_SHOW, HandleAaaaVersionShow,(CMD_FLAG_PRIVATE | CMD_FLAG_ONLINE)),
  49. };
  50. CMD_GROUP_ENTRY g_AaaaCmdGroups[] =
  51. {
  52. CREATE_CMD_GROUP_ENTRY(GROUP_SET, g_AaaaSetCmdTable),
  53. CREATE_CMD_GROUP_ENTRY(GROUP_SHOW, g_AaaaShowCmdTable),
  54. };
  55. ULONG g_ulNumGroups = sizeof(g_AaaaCmdGroups)/sizeof(CMD_GROUP_ENTRY);
  56. HANDLE g_hModule;
  57. BOOL g_bCommit;
  58. DWORD g_dwNumTableEntries;
  59. DWORD ParentVersion;
  60. BOOL g_bAaaaDirty = FALSE;
  61. NS_CONTEXT_CONNECT_FN AaaaConnect;
  62. ULONG g_ulInitCount;
  63. //////////////////////////////////////////////////////////////////////////////
  64. // AaaaCommit
  65. //////////////////////////////////////////////////////////////////////////////
  66. DWORD
  67. WINAPI
  68. AaaaCommit(
  69. IN DWORD dwAction
  70. )
  71. {
  72. switch(dwAction)
  73. {
  74. case NETSH_COMMIT:
  75. {
  76. if(g_bCommit)
  77. {
  78. return NO_ERROR;
  79. }
  80. g_bCommit = TRUE;
  81. break;
  82. }
  83. case NETSH_UNCOMMIT:
  84. {
  85. g_bCommit = FALSE;
  86. return NO_ERROR;
  87. }
  88. case NETSH_SAVE:
  89. {
  90. if(g_bCommit)
  91. {
  92. return NO_ERROR;
  93. }
  94. break;
  95. }
  96. case NETSH_FLUSH:
  97. {
  98. //
  99. // Action is a flush. If current state is commit, then
  100. // nothing to be done.
  101. //
  102. if(g_bCommit)
  103. {
  104. return NO_ERROR;
  105. }
  106. // bFlush = TRUE;
  107. break;
  108. }
  109. default:
  110. {
  111. return NO_ERROR;
  112. }
  113. }
  114. //
  115. // Switched to commit mode. So set all valid info in the
  116. // strutures. Free memory and invalidate the info.
  117. //
  118. return NO_ERROR;
  119. }
  120. //////////////////////////////////////////////////////////////////////////////
  121. // AaaaStartHelper
  122. //////////////////////////////////////////////////////////////////////////////
  123. DWORD
  124. WINAPI
  125. AaaaStartHelper(
  126. IN CONST GUID *pguidParent,
  127. IN DWORD dwVersion
  128. )
  129. {
  130. DWORD dwErr;
  131. NS_CONTEXT_ATTRIBUTES attMyAttributes;
  132. ParentVersion = dwVersion;
  133. ZeroMemory( &attMyAttributes, sizeof(attMyAttributes) );
  134. attMyAttributes.pwszContext = L"aaaa";
  135. attMyAttributes.guidHelper = g_AaaamontrGuid;
  136. attMyAttributes.dwVersion = 1;
  137. attMyAttributes.dwFlags = CMD_FLAG_LOCAL;
  138. attMyAttributes.ulNumTopCmds = 0;
  139. attMyAttributes.pTopCmds = NULL;
  140. attMyAttributes.ulNumGroups = g_ulNumGroups;
  141. attMyAttributes.pCmdGroups = (CMD_GROUP_ENTRY (*)[])&g_AaaaCmdGroups;
  142. attMyAttributes.pfnCommitFn = AaaaCommit;
  143. attMyAttributes.pfnDumpFn = AaaaDump;
  144. attMyAttributes.pfnConnectFn= AaaaConnect;
  145. dwErr = RegisterContext( &attMyAttributes );
  146. return dwErr;
  147. }
  148. //////////////////////////////////////////////////////////////////////////////
  149. // AaaaUnInit
  150. //////////////////////////////////////////////////////////////////////////////
  151. DWORD
  152. WINAPI
  153. AaaaUnInit(
  154. IN DWORD dwReserved
  155. )
  156. {
  157. if(InterlockedDecrement(&g_ulInitCount) != 0)
  158. {
  159. return NO_ERROR;
  160. }
  161. return NO_ERROR;
  162. }
  163. //////////////////////////////////////////////////////////////////////////////
  164. // AaaaDllEntry
  165. //////////////////////////////////////////////////////////////////////////////
  166. BOOL
  167. WINAPI
  168. AaaaDllEntry(
  169. HINSTANCE hInstDll,
  170. DWORD fdwReason,
  171. LPVOID pReserved
  172. )
  173. {
  174. switch (fdwReason)
  175. {
  176. case DLL_PROCESS_ATTACH:
  177. {
  178. g_hModule = hInstDll;
  179. DisableThreadLibraryCalls(hInstDll);
  180. break;
  181. }
  182. case DLL_PROCESS_DETACH:
  183. {
  184. g_hModule = NULL;
  185. break;
  186. }
  187. default:
  188. {
  189. break;
  190. }
  191. }
  192. return TRUE;
  193. }
  194. //////////////////////////////////////////////////////////////////////////////
  195. // InitHelperDll
  196. //////////////////////////////////////////////////////////////////////////////
  197. DWORD WINAPI
  198. InitHelperDll(
  199. IN DWORD dwNetshVersion,
  200. OUT PVOID pReserved
  201. )
  202. {
  203. DWORD dwErr;
  204. NS_HELPER_ATTRIBUTES attMyAttributes;
  205. //
  206. // See if this is the first time we are being called
  207. //
  208. if(InterlockedIncrement(&g_ulInitCount) != 1)
  209. {
  210. return NO_ERROR;
  211. }
  212. g_bCommit = TRUE;
  213. // Register this module as a helper to the netsh root
  214. // context.
  215. //
  216. ZeroMemory( &attMyAttributes, sizeof(attMyAttributes) );
  217. attMyAttributes.guidHelper = g_AaaamontrGuid;
  218. attMyAttributes.dwVersion = AAAA_HELPER_VERSION;
  219. attMyAttributes.pfnStart = AaaaStartHelper;
  220. attMyAttributes.pfnStop = NULL;
  221. RegisterHelper( &g_NetshGuid, &attMyAttributes );
  222. // Register any sub contexts implemented in this dll
  223. //
  224. dwErr = AaaaContextInstallSubContexts();
  225. if (dwErr != NO_ERROR)
  226. {
  227. AaaaUnInit(0);
  228. return dwErr;
  229. }
  230. return NO_ERROR;
  231. }
  232. //////////////////////////////////////////////////////////////////////////////
  233. // AaaaConnect
  234. //////////////////////////////////////////////////////////////////////////////
  235. DWORD WINAPI
  236. AaaaConnect(
  237. IN LPCWSTR pwszRouter
  238. )
  239. {
  240. // If context info is dirty, reregister it
  241. if (g_bAaaaDirty)
  242. {
  243. AaaaStartHelper(NULL, ParentVersion);
  244. }
  245. return NO_ERROR;
  246. }