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.

295 lines
7.9 KiB

  1. //////////////////////////////////////////////////////////////////////////////
  2. //
  3. // Copyright (c) 1998-2000 Microsoft Corporation
  4. //
  5. // Module Name:
  6. //
  7. // aaaaConfig.cpp
  8. //
  9. // Abstract:
  10. //
  11. // Handlers for aaaa config commands
  12. //
  13. // Revision History:
  14. //
  15. // pmay
  16. // tperraut 04/02/1999
  17. // tperraut 04/03/2000 Version# test, use of upgrade code for version <
  18. // Whistler Proxy (2)
  19. //
  20. //////////////////////////////////////////////////////////////////////////////
  21. #include "stdafx.h"
  22. #include "strdefs.h"
  23. #include "rmstring.h"
  24. #include "aaaamon.h"
  25. #include "aaaaversion.h"
  26. #include "aaaaconfig.h"
  27. //
  28. // NOTE since WIN32 errors are assumed to fall in the range -32k to 32k
  29. // (see comment in winerror.h near HRESULT_FROM_WIN32 definition), we can
  30. // re-create original Win32 error from low-order 16 bits of HRESULT.
  31. //
  32. #define WIN32_FROM_HRESULT(x) \
  33. ( (HRESULT_FACILITY(x) == FACILITY_WIN32) ? ((DWORD)((x) & 0x0000FFFF)) : (x) )
  34. //////////////////////////////////////////////////////////////////////////////
  35. //
  36. // Parses the Aaaa set config from the command line
  37. //
  38. //////////////////////////////////////////////////////////////////////////////
  39. DWORD
  40. AaaaConfigParseCommandLine(
  41. IN PWCHAR *ppwcArguments,
  42. IN DWORD dwCurrentIndex,
  43. IN DWORD dwArgCount,
  44. IN DWORD dwCmdFlags
  45. )
  46. {
  47. const WCHAR IAS_MDB[] = L"%SystemRoot%\\System32\\ias\\ias.mdb";
  48. DWORD dwErr = NO_ERROR;
  49. TOKEN_VALUE rgEnumState[] =
  50. {
  51. {TOKEN_SET, HLP_AAAACONFIG_SET},
  52. {TOKEN_SHOW, HLP_AAAACONFIG_SHOW}
  53. };
  54. AAAAMON_CMD_ARG pArgs[] =
  55. {
  56. {
  57. AAAAMONTR_CMD_TYPE_STRING,
  58. // tag string, required or not, present or not
  59. {TOKEN_BLOB, NS_REQ_PRESENT, FALSE}, //tag_type
  60. rgEnumState,
  61. sizeof(rgEnumState)/sizeof(*rgEnumState),
  62. NULL
  63. }
  64. };
  65. do
  66. {
  67. // Parse
  68. //
  69. dwErr = RutlParse(
  70. ppwcArguments,
  71. dwCurrentIndex,
  72. dwArgCount,
  73. NULL,
  74. pArgs,
  75. sizeof(pArgs) / sizeof(*pArgs));
  76. if ( dwErr != NO_ERROR )
  77. {
  78. break;
  79. }
  80. // Config
  81. //
  82. if ( !pArgs[0].rgTag.bPresent )
  83. {
  84. // tag blob not found
  85. DisplayMessage(g_hModule, MSG_AAAACONFIG_SET_FAIL);
  86. dwErr = ERROR_INVALID_SYNTAX;
  87. break;
  88. }
  89. // tag blob found
  90. // Now try to restore the database from the script
  91. HRESULT hres = IASRestoreConfig(ppwcArguments[dwCurrentIndex]);
  92. if ( FAILED(hres) )
  93. {
  94. DisplayMessage(g_hModule, MSG_AAAACONFIG_SET_FAIL);
  95. dwErr = WIN32_FROM_HRESULT(hres);
  96. break;
  97. }
  98. // set config successfull: refresh the service
  99. hres = RefreshIASService();
  100. if ( FAILED(hres) )
  101. {
  102. ///////////////////////////
  103. // Refresh should not fail.
  104. ///////////////////////////
  105. DisplayMessage(g_hModule, MSG_AAAACONFIG_SET_REFRESH_FAIL);
  106. dwErr = NO_ERROR;
  107. }
  108. else
  109. {
  110. DisplayMessage(g_hModule, MSG_AAAACONFIG_SET_SUCCESS);
  111. dwErr = NO_ERROR;
  112. }
  113. } while ( FALSE );
  114. return dwErr;
  115. }
  116. //////////////////////////////////////////////////////////////////////////////
  117. // Function Name:AaaConfigDumpConfig
  118. //
  119. // Parameters: none
  120. //
  121. // Description: writes the current config (header, content...) to the output
  122. //
  123. // Returns: NO_ERROR or ERROR_SUPPRESS_OUTPUT
  124. //
  125. //////////////////////////////////////////////////////////////////////////////
  126. DWORD AaaaConfigDumpConfig()
  127. {
  128. const int MAX_SIZE_DISPLAY_LINE = 80;
  129. const int SIZE_MAX_STRING = 512;
  130. const int WHISTLER_PROXY_VERSION = 3;
  131. DisplayMessage(g_hModule, MSG_AAAACONFIG_SHOW_HEADER);
  132. bool bCoInitialized = false;
  133. do
  134. {
  135. HRESULT hr = CoInitializeEx(NULL, COINIT_MULTITHREADED);
  136. if ( FAILED(hr) )
  137. {
  138. if ( hr != RPC_E_CHANGED_MODE )
  139. {
  140. break;
  141. }
  142. }
  143. else
  144. {
  145. bCoInitialized = true;
  146. }
  147. LONG lVersion;
  148. hr = AaaaVersionGetVersion(&lVersion);
  149. if ( FAILED(hr) )
  150. {
  151. DisplayMessage(g_hModule, MSG_AAAACONFIG_SHOW_FAIL);
  152. break;
  153. }
  154. // Sanity check to make sure that the actual database is a Whistler DB
  155. if ( lVersion != WHISTLER_PROXY_VERSION )
  156. {
  157. DisplayMessage(g_hModule, MSG_AAAACONFIG_SHOW_FAIL);
  158. break;
  159. }
  160. WCHAR sDisplayString[SIZE_MAX_STRING] = L"";
  161. _snwprintf(
  162. sDisplayString,
  163. SIZE_MAX_STRING,
  164. L"# IAS.MDB Version = %d\n",
  165. lVersion
  166. );
  167. DisplayMessageT(sDisplayString);
  168. ULONG ulSize;
  169. WCHAR* pDumpString;
  170. hr = IASDumpConfig(&pDumpString, &ulSize);
  171. if ( SUCCEEDED(hr) )
  172. {
  173. ULONG RelativePos = 0;
  174. ULONG CurrentPos = 0;
  175. WCHAR DisplayLine [MAX_SIZE_DISPLAY_LINE];
  176. DisplayMessageT(MSG_AAAACONFIG_BLOBBEGIN);
  177. while ( CurrentPos <= ulSize )
  178. {
  179. WCHAR TempChar = pDumpString[CurrentPos++];
  180. DisplayLine[RelativePos++] = TempChar;
  181. if ( TempChar == L'\r' )
  182. {
  183. DisplayLine[RelativePos] = L'\0';
  184. DisplayMessageT(DisplayLine);
  185. RelativePos = 0;
  186. }
  187. }
  188. DisplayMessageT(L"*");
  189. free (pDumpString); // was allocated by malloc
  190. DisplayMessageT(MSG_AAAACONFIG_BLOBEND);
  191. DisplayMessage(
  192. g_hModule,
  193. MSG_AAAACONFIG_SHOW_FOOTER
  194. );
  195. }
  196. else
  197. {
  198. DisplayMessage(g_hModule, MSG_AAAACONFIG_SHOW_INVALID_SYNTAX);
  199. DisplayMessage(g_hModule, HLP_AAAACONFIG_SHOW);
  200. }
  201. }
  202. while (false);
  203. if (bCoInitialized)
  204. {
  205. CoUninitialize();
  206. }
  207. return NO_ERROR;
  208. }
  209. //////////////////////////////////////////////////////////////////////////////
  210. //
  211. // Handles the aaaa config set command
  212. //
  213. //////////////////////////////////////////////////////////////////////////////
  214. DWORD
  215. HandleAaaaConfigSet(
  216. IN LPCWSTR pwszMachine,
  217. IN OUT LPWSTR *ppwcArguments,
  218. IN DWORD dwCurrentIndex,
  219. IN DWORD dwArgCount,
  220. IN DWORD dwFlags,
  221. IN LPCVOID pvData,
  222. OUT BOOL *pbDone
  223. )
  224. {
  225. return AaaaConfigParseCommandLine(
  226. ppwcArguments,
  227. dwCurrentIndex,
  228. dwArgCount,
  229. dwFlags
  230. );
  231. }
  232. //////////////////////////////////////////////////////////////////////////////
  233. //
  234. // Handles the aaaa config show command
  235. //
  236. //////////////////////////////////////////////////////////////////////////////
  237. DWORD
  238. HandleAaaaConfigShow(
  239. IN LPCWSTR pwszMachine,
  240. IN OUT LPWSTR *ppwcArguments,
  241. IN DWORD dwCurrentIndex,
  242. IN DWORD dwArgCount,
  243. IN DWORD dwFlags,
  244. IN LPCVOID pvData,
  245. OUT BOOL *pbDone
  246. )
  247. {
  248. if (dwCurrentIndex < dwArgCount)
  249. {
  250. DisplayMessage(g_hModule, MSG_AAAACONFIG_SHOW_FAIL);
  251. DisplayMessage(g_hModule, HLP_AAAACONFIG_SHOW);
  252. }
  253. else
  254. {
  255. AaaaConfigDumpConfig();
  256. }
  257. return NO_ERROR;
  258. }