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.

487 lines
13 KiB

  1. //////////////////////////////////////////////////////////////////////////////
  2. //
  3. // Copyright Microsoft Corporation
  4. //
  5. // Module Name:
  6. //
  7. // aaaaConfig.cpp
  8. //
  9. // Abstract:
  10. //
  11. // Handlers for aaaa config commands
  12. //
  13. //////////////////////////////////////////////////////////////////////////////
  14. #include "stdafx.h"
  15. #include "strdefs.h"
  16. #include "rmstring.h"
  17. #include "aaaamon.h"
  18. #include "aaaaversion.h"
  19. #include "aaaaconfig.h"
  20. #include "utils.h"
  21. #include "iasdefs.h"
  22. #include "ias.h"
  23. namespace
  24. {
  25. const wchar_t* const tokenArray[] =
  26. {
  27. {TOKEN_VERSION},
  28. {TOKEN_CONFIG},
  29. {TOKEN_SERVER_SETTINGS},
  30. {TOKEN_CLIENTS},
  31. {TOKEN_CONNECTION_REQUEST_POLICIES},
  32. {TOKEN_LOGGING},
  33. {TOKEN_REMOTE_ACCESS_POLICIES},
  34. };
  35. };
  36. //
  37. // NOTE since WIN32 errors are assumed to fall in the range -32k to 32k
  38. // (see comment in winerror.h near HRESULT_FROM_WIN32 definition), we can
  39. // re-create original Win32 error from low-order 16 bits of HRESULT.
  40. //
  41. #define WIN32_FROM_HRESULT(x) \
  42. ( (HRESULT_FACILITY(x) == FACILITY_WIN32) ? ((DWORD)((x) & 0x0000FFFF)) : (x) )
  43. //////////////////////////////////////////////////////////////////////////////
  44. //
  45. // Parses the Aaaa set config from the command line
  46. //
  47. //////////////////////////////////////////////////////////////////////////////
  48. DWORD
  49. AaaaConfigParseSetCommandLine(
  50. IN PWCHAR *ppwcArguments,
  51. IN DWORD dwCurrentIndex,
  52. IN DWORD dwArgCount,
  53. IN DWORD dwCmdFlags
  54. )
  55. {
  56. const WCHAR IAS_MDB[] = L"%SystemRoot%\\System32\\ias\\ias.mdb";
  57. DWORD dwErr = NO_ERROR;
  58. static TOKEN_VALUE rgEnumType[] =
  59. {
  60. {TOKEN_SERVER_SETTINGS, SERVER_SETTINGS},
  61. {TOKEN_CLIENTS, CLIENTS},
  62. {TOKEN_CONNECTION_REQUEST_POLICIES, CONNECTION_REQUEST_POLICIES},
  63. {TOKEN_LOGGING, LOGGING},
  64. {TOKEN_REMOTE_ACCESS_POLICIES, REMOTE_ACCESS_POLICIES},
  65. };
  66. static AAAAMON_CMD_ARG pArgs[] =
  67. {
  68. {
  69. AAAAMONTR_CMD_TYPE_ENUM,
  70. {TOKEN_TYPE, FALSE, FALSE},
  71. rgEnumType,
  72. sizeof(rgEnumType) / sizeof(*rgEnumType),
  73. NULL
  74. },
  75. {
  76. AAAAMONTR_CMD_TYPE_STRING,
  77. // tag string, required or not, present or not
  78. {TOKEN_BLOB, NS_REQ_PRESENT, FALSE}, //tag_type
  79. NULL,
  80. 0,
  81. NULL ,
  82. },
  83. };
  84. wchar_t* blobString = 0;
  85. do
  86. {
  87. // Parse
  88. //
  89. dwErr = RutlParse(
  90. ppwcArguments,
  91. dwCurrentIndex,
  92. dwArgCount,
  93. NULL,
  94. pArgs,
  95. sizeof(pArgs) / sizeof(*pArgs));
  96. if ( dwErr != NO_ERROR )
  97. {
  98. break;
  99. }
  100. _ASSERT(pBlobString != 0);
  101. blobString = AAAAMON_CMD_ARG_GetPsz(&pArgs[1]);
  102. if (!blobString)
  103. {
  104. dwErr = ERROR_INVALID_SYNTAX;
  105. break;
  106. }
  107. IAS_SHOW_TOKEN_LIST restoreType;
  108. DWORD dwordType = (AAAAMON_CMD_ARG_GetDword(&pArgs[0]));
  109. if (dwordType == -1)
  110. {
  111. // optional parameter not set
  112. restoreType = CONFIG;
  113. }
  114. else
  115. {
  116. restoreType = (IAS_SHOW_TOKEN_LIST)dwordType;
  117. }
  118. // Config
  119. //
  120. if ( !pArgs[1].rgTag.bPresent )
  121. {
  122. // tag blob not found
  123. DisplayMessage(g_hModule, MSG_AAAACONFIG_SET_FAIL);
  124. dwErr = ERROR_INVALID_SYNTAX;
  125. break;
  126. }
  127. // tag blob found
  128. // Now try to restore the database from the script
  129. HRESULT hres = IASRestoreConfig(blobString, restoreType);
  130. if ( FAILED(hres) )
  131. {
  132. if (hres != IAS_E_LICENSE_VIOLATION)
  133. {
  134. DisplayMessage(g_hModule, MSG_AAAACONFIG_SET_FAIL);
  135. dwErr = WIN32_FROM_HRESULT(hres);
  136. }
  137. else
  138. {
  139. DisplayMessage(g_hModule, MSG_AAAACONFIG_LICENSE_VIOLATION);
  140. dwErr = NO_ERROR;
  141. }
  142. break;
  143. }
  144. // set config successfull: refresh the service
  145. hres = RefreshIASService();
  146. if ( FAILED(hres) )
  147. {
  148. ///////////////////////////
  149. // Refresh should not fail.
  150. ///////////////////////////
  151. DisplayMessage(g_hModule, MSG_AAAACONFIG_SET_REFRESH_FAIL);
  152. dwErr = NO_ERROR;
  153. }
  154. else
  155. {
  156. DisplayMessage(g_hModule, MSG_AAAACONFIG_SET_SUCCESS);
  157. dwErr = NO_ERROR;
  158. }
  159. } while ( FALSE );
  160. RutlFree(blobString);
  161. return dwErr;
  162. }
  163. //////////////////////////////////////////////////////////////////////////////
  164. // Function Name:AaaConfigDumpConfig
  165. //
  166. // Parameters: none
  167. //
  168. // Description: writes the current config (header, content...) to the output
  169. //
  170. // Returns: NO_ERROR or ERROR_SUPPRESS_OUTPUT
  171. //
  172. //////////////////////////////////////////////////////////////////////////////
  173. DWORD AaaaConfigDumpConfig(IAS_SHOW_TOKEN_LIST showType)
  174. {
  175. const int MAX_SIZE_DISPLAY_LINE = 80;
  176. const int SIZE_MAX_STRING = 512;
  177. DisplayMessage(g_hModule, MSG_AAAACONFIG_SHOW_HEADER);
  178. bool bCoInitialized = false;
  179. do
  180. {
  181. HRESULT hr = CoInitializeEx(NULL, COINIT_MULTITHREADED);
  182. if ( FAILED(hr) )
  183. {
  184. if ( hr != RPC_E_CHANGED_MODE )
  185. {
  186. break;
  187. }
  188. }
  189. else
  190. {
  191. bCoInitialized = true;
  192. }
  193. LONG lVersion;
  194. hr = AaaaVersionGetVersion(&lVersion);
  195. if ( FAILED(hr) )
  196. {
  197. DisplayMessage(g_hModule, MSG_AAAACONFIG_SHOW_FAIL);
  198. break;
  199. }
  200. // Sanity check to make sure that the actual database is a Whistler DB
  201. if ( lVersion != IAS_CURRENT_VERSION )
  202. {
  203. DisplayMessage(g_hModule, MSG_AAAACONFIG_SHOW_FAIL);
  204. break;
  205. }
  206. wchar_t sDisplayString[SIZE_MAX_STRING] = L"";
  207. // This will not create a buffer overrun
  208. swprintf(
  209. sDisplayString,
  210. L"# IAS.MDB Version = %d\n",
  211. lVersion
  212. );
  213. DisplayMessageT(sDisplayString);
  214. ULONG ulSize;
  215. wchar_t* pDumpString;
  216. hr = IASDumpConfig(&pDumpString, &ulSize);
  217. if ( SUCCEEDED(hr) )
  218. {
  219. ULONG RelativePos = 0;
  220. ULONG CurrentPos = 0;
  221. wchar_t DisplayLine [MAX_SIZE_DISPLAY_LINE];
  222. DisplayMessageT(MSG_AAAACONFIG_BLOBBEGIN_A);
  223. switch (showType)
  224. {
  225. case SERVER_SETTINGS:
  226. {
  227. DisplayMessageT(MSG_AAAACONFIG_BLOBBEGIN_B);
  228. DisplayMessageT(TOKEN_SERVER_SETTINGS);
  229. break;
  230. }
  231. case CLIENTS:
  232. {
  233. DisplayMessageT(MSG_AAAACONFIG_BLOBBEGIN_B);
  234. DisplayMessageT(TOKEN_CLIENTS);
  235. break;
  236. }
  237. case CONNECTION_REQUEST_POLICIES:
  238. {
  239. DisplayMessageT(MSG_AAAACONFIG_BLOBBEGIN_B);
  240. DisplayMessageT(TOKEN_CONNECTION_REQUEST_POLICIES);
  241. break;
  242. }
  243. case LOGGING:
  244. {
  245. DisplayMessageT(MSG_AAAACONFIG_BLOBBEGIN_B);
  246. DisplayMessageT(TOKEN_LOGGING);
  247. break;
  248. }
  249. case REMOTE_ACCESS_POLICIES:
  250. {
  251. DisplayMessageT(MSG_AAAACONFIG_BLOBBEGIN_B);
  252. DisplayMessageT(TOKEN_REMOTE_ACCESS_POLICIES);
  253. break;
  254. }
  255. case CONFIG:
  256. default:
  257. {
  258. break;
  259. }
  260. }
  261. DisplayMessageT(MSG_AAAACONFIG_BLOBBEGIN_C);
  262. while ( CurrentPos <= ulSize )
  263. {
  264. wchar_t TempChar = pDumpString[CurrentPos++];
  265. DisplayLine[RelativePos++] = TempChar;
  266. if ( TempChar == L'\r' )
  267. {
  268. DisplayLine[RelativePos] = L'\0';
  269. DisplayMessageT(DisplayLine);
  270. RelativePos = 0;
  271. }
  272. }
  273. DisplayMessageT(L"*");
  274. free(pDumpString); // was allocated by malloc
  275. DisplayMessageT(MSG_AAAACONFIG_BLOBEND);
  276. DisplayMessage(
  277. g_hModule,
  278. MSG_AAAACONFIG_SHOW_FOOTER
  279. );
  280. }
  281. else
  282. {
  283. DisplayMessage(g_hModule, MSG_AAAACONFIG_SHOW_INVALID_SYNTAX);
  284. DisplayMessage(g_hModule, HLP_AAAACONFIG_SHOW);
  285. }
  286. }
  287. while (false);
  288. if (bCoInitialized)
  289. {
  290. CoUninitialize();
  291. }
  292. return NO_ERROR;
  293. }
  294. //////////////////////////////////////////////////////////////////////////////
  295. //
  296. // Handles the aaaa config set command
  297. //
  298. //////////////////////////////////////////////////////////////////////////////
  299. DWORD
  300. HandleAaaaConfigSet(
  301. IN LPCWSTR pwszMachine,
  302. IN OUT LPWSTR *ppwcArguments,
  303. IN DWORD dwCurrentIndex,
  304. IN DWORD dwArgCount,
  305. IN DWORD dwFlags,
  306. IN LPCVOID pvData,
  307. OUT BOOL *pbDone
  308. )
  309. {
  310. return AaaaConfigParseSetCommandLine(
  311. ppwcArguments,
  312. dwCurrentIndex,
  313. dwArgCount,
  314. dwFlags
  315. );
  316. }
  317. //////////////////////////////////////////////////////////////////////////////
  318. //
  319. // Parses the Aaaa set config from the command line
  320. //
  321. //////////////////////////////////////////////////////////////////////////////
  322. DWORD
  323. AaaaConfigParseShowCommandLine(
  324. IN PWCHAR *ppwcArguments,
  325. IN DWORD dwCurrentIndex,
  326. IN DWORD dwArgCount,
  327. IN DWORD dwCmdFlags
  328. )
  329. {
  330. const size_t arraySize = sizeof(tokenArray)/sizeof(*tokenArray);
  331. BOOL bFound = FALSE;
  332. for (DWORD index = 0; index < arraySize; ++index)
  333. {
  334. if (MatchToken(ppwcArguments[dwCurrentIndex-1], tokenArray[index]))
  335. {
  336. bFound = TRUE;
  337. break;
  338. }
  339. }
  340. const size_t SIZE_MAX_STRING = 512;
  341. DWORD dwErr = NO_ERROR;
  342. if (bFound == TRUE)
  343. {
  344. switch (index)
  345. {
  346. case VERSION:
  347. {
  348. LONG lVersion;
  349. HRESULT hr = AaaaVersionGetVersion(&lVersion);
  350. if (SUCCEEDED(hr))
  351. {
  352. wchar_t sDisplayString[SIZE_MAX_STRING];
  353. // This will not create a buffer overrun
  354. swprintf(
  355. sDisplayString,
  356. L"Version = %d\n",
  357. lVersion
  358. );
  359. DisplayMessageT(sDisplayString);
  360. }
  361. else
  362. {
  363. DisplayMessage(g_hModule, MSG_AAAAVERSION_GET_FAIL);
  364. dwErr = ERROR;
  365. }
  366. break;
  367. }
  368. case CONFIG:
  369. {
  370. AaaaConfigDumpConfig(CONFIG);
  371. break;
  372. }
  373. case SERVER_SETTINGS:
  374. {
  375. AaaaConfigDumpConfig(SERVER_SETTINGS);
  376. break;
  377. }
  378. case CLIENTS:
  379. {
  380. AaaaConfigDumpConfig(CLIENTS);
  381. break;
  382. }
  383. case CONNECTION_REQUEST_POLICIES:
  384. {
  385. AaaaConfigDumpConfig(CONNECTION_REQUEST_POLICIES);
  386. break;
  387. }
  388. case LOGGING:
  389. {
  390. AaaaConfigDumpConfig(LOGGING);
  391. break;
  392. }
  393. case REMOTE_ACCESS_POLICIES:
  394. {
  395. AaaaConfigDumpConfig(REMOTE_ACCESS_POLICIES);
  396. break;
  397. }
  398. default:
  399. {
  400. DisplayMessage(g_hModule, MSG_AAAACONFIG_SHOW_INVALID_SYNTAX);
  401. }
  402. }
  403. }
  404. return dwErr;
  405. }
  406. //////////////////////////////////////////////////////////////////////////////
  407. //
  408. // Handles the aaaa config show command
  409. //
  410. //////////////////////////////////////////////////////////////////////////////
  411. DWORD
  412. HandleAaaaConfigShow(
  413. IN LPCWSTR pwszMachine,
  414. IN OUT LPWSTR *ppwcArguments,
  415. IN DWORD dwCurrentIndex,
  416. IN DWORD dwArgCount,
  417. IN DWORD dwFlags,
  418. IN LPCVOID pvData,
  419. OUT BOOL *pbDone
  420. )
  421. {
  422. if (dwCurrentIndex < dwArgCount)
  423. {
  424. DisplayMessage(g_hModule, MSG_AAAACONFIG_SHOW_FAIL);
  425. DisplayMessage(g_hModule, HLP_AAAACONFIG_SHOW);
  426. }
  427. else
  428. {
  429. return AaaaConfigParseShowCommandLine(
  430. ppwcArguments,
  431. dwCurrentIndex,
  432. dwArgCount,
  433. dwFlags
  434. );
  435. }
  436. return NO_ERROR;
  437. }