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.

289 lines
7.6 KiB

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