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.

2398 lines
69 KiB

  1. //////////////////////////////////////////////////////////////////////////////
  2. // Module : parser_dynamic.cpp
  3. //
  4. // Purpose : All parser dynamic mode functions
  5. //
  6. // Developers Name : N.Surendra Sai / Vunnam Kondal Rao
  7. //
  8. // History :
  9. //
  10. // Date Author Comments
  11. // 27 Aug 2001
  12. //
  13. //////////////////////////////////////////////////////////////////////////////
  14. #include "nshipsec.h"
  15. extern HINSTANCE g_hModule;
  16. //////////////////////////////////////////////////////////////////////////////
  17. //
  18. // Function : ParseDynamicAddSetMMPolicy()
  19. //
  20. // Date of Creation : 3rd oct 2001
  21. //
  22. // Parameters : IN LPTSTR lppwszTok[MAX_ARGS],
  23. // IN _TCHAR szListTok[MAX_STR_LEN],
  24. // IN OUT PPARSER_PKT pParser,
  25. // IN DWORD dwCurrentIndex,
  26. // IN DWORD dwMaxArgs,
  27. // IN DWORD dwTagType[MAX_ARGS],
  28. // IN BOOL flag
  29. //
  30. //
  31. // Return : DWORD
  32. //
  33. // Description : This Function called by parser function.
  34. // It will separate the List and Non-List commands
  35. //
  36. // History :
  37. //
  38. // Date Author Comments
  39. //
  40. //////////////////////////////////////////////////////////////////////////////
  41. DWORD
  42. ParseDynamicAddSetMMPolicy(
  43. IN LPTSTR lppwszTok[MAX_ARGS],
  44. IN OUT PPARSER_PKT pParser,
  45. IN DWORD dwCurrentIndex,
  46. IN DWORD dwMaxArgs,
  47. IN DWORD dwTagType[MAX_ARGS],
  48. IN BOOL bOption
  49. )
  50. {
  51. DWORD dwReturn = ERROR_SUCCESS,dwCount,dwUsed = 0;
  52. DWORD dwIndex = 0;
  53. LPTSTR szListTok = NULL;
  54. BOOL bMMSECSpecified = FALSE;
  55. szListTok = (LPTSTR)calloc(MAX_STR_LEN,sizeof(_TCHAR));
  56. if(szListTok == NULL)
  57. {
  58. PrintErrorMessage(WIN32_ERR,ERROR_OUTOFMEMORY,NULL);
  59. dwReturn = RETURN_NO_ERROR;
  60. BAIL_OUT;
  61. }
  62. for(dwCount = 0;(dwCount < dwMaxArgs) && (dwReturn == ERROR_SUCCESS);dwCount++)
  63. {
  64. switch(pParser->ValidTok[dwTagType[dwCount]].dwValue) // If one token invalid dive out from the function
  65. {
  66. case CMD_TOKEN_NAME :
  67. dwReturn = LoadParserOutput(pParser,dwCount,&dwUsed,lppwszTok[dwCount],dwTagType[dwCount],TYPE_STRING);
  68. break;
  69. case CMD_TOKEN_DEFRESPONSE :
  70. dwReturn = LoadParserOutput(pParser,dwCount,&dwUsed,lppwszTok[dwCount],dwTagType[dwCount],TYPE_BOOL);
  71. break;
  72. case CMD_TOKEN_SOFTSAEXPTIME :
  73. case CMD_TOKEN_MMLIFETIME :
  74. case CMD_TOKEN_QMPERMM :
  75. dwReturn = LoadParserOutput(pParser,dwCount,&dwUsed,lppwszTok[dwCount],dwTagType[dwCount],TYPE_DWORD);
  76. break;
  77. case CMD_TOKEN_MMSECMETHODS :
  78. bMMSECSpecified = TRUE;
  79. dwReturn = LoadParserOutput(pParser,dwCount,&dwUsed,lppwszTok[dwCount],dwTagType[dwCount],TYPE_MM_OFFER);
  80. break;
  81. default :
  82. dwReturn = ERROR_INVALID_SYNTAX;
  83. break;
  84. }
  85. }
  86. if( dwReturn == ERROR_SUCCESS )
  87. {
  88. if ( (!bMMSECSpecified) && (bOption == ADD_CMD) ) // if its an Add Cmd and no MMSec methods are specified,
  89. // ...then add defaults
  90. {
  91. _tcsncpy(szListTok,DEFAULT_MMSECMETHODS,MAX_STR_LEN-1);
  92. dwIndex = MatchEnumTagToTagIndex(CMD_TOKEN_STR_MMSECMETHODS,pParser);
  93. if(dwIndex == PARSE_ERROR)
  94. {
  95. dwReturn = ERROR_SHOW_USAGE;
  96. BAIL_OUT;
  97. }
  98. dwReturn = LoadParserOutput(pParser,dwMaxArgs,&dwUsed,szListTok,dwIndex,TYPE_MM_OFFER);
  99. }
  100. }
  101. free(szListTok);
  102. error:
  103. return dwReturn;
  104. }
  105. //////////////////////////////////////////////////////////////////////////////
  106. // Function : ParseStaticAddSetQMPolicy()
  107. //
  108. // Date of Creation : 5th oct 2001
  109. //
  110. // Parameters : IN lppwszTok[MAX_ARGS],
  111. // IN szListTok[MAX_STR_LEN],
  112. // IN OUT pParser,
  113. // IN dwCurrentIndex,
  114. // IN dwMaxArgs,
  115. // IN dwTagType[MAX_ARGS]
  116. //
  117. // Return : DWORD
  118. //
  119. // Description : Validates the arguments to the contexts DynamicQMPolicy
  120. // (Add/Set)
  121. // History :
  122. //
  123. // Date Author Comments
  124. //
  125. //////////////////////////////////////////////////////////////////////////////
  126. DWORD
  127. ParseDynamicAddSetQMPolicy(
  128. IN LPTSTR lppwszTok[MAX_ARGS],
  129. IN OUT PPARSER_PKT pParser,
  130. IN DWORD dwCurrentIndex,
  131. IN DWORD dwMaxArgs,
  132. IN DWORD dwTagType[MAX_ARGS],
  133. IN BOOL bOption
  134. )
  135. {
  136. DWORD dwReturn = ERROR_SUCCESS,dwCount,dwUsed = 0;
  137. DWORD dwIndex = 0;
  138. LPTSTR szListTok = NULL;
  139. BOOL bNegotiationSpecified = FALSE;
  140. szListTok = (LPTSTR)calloc(MAX_STR_LEN,sizeof(_TCHAR));
  141. if(szListTok == NULL)
  142. {
  143. PrintErrorMessage(WIN32_ERR,ERROR_OUTOFMEMORY,NULL);
  144. dwReturn = RETURN_NO_ERROR;
  145. BAIL_OUT;
  146. }
  147. for(dwCount = 0;(dwCount < dwMaxArgs) && (dwReturn == ERROR_SUCCESS);dwCount++)
  148. {
  149. // If one token invalid dive out from the function
  150. switch(pParser->ValidTok[dwTagType[dwCount]].dwValue)
  151. {
  152. case CMD_TOKEN_NAME :
  153. dwReturn = LoadParserOutput(pParser,dwCount,&dwUsed,lppwszTok[dwCount],dwTagType[dwCount],TYPE_STRING);
  154. break;
  155. case CMD_TOKEN_DEFRESPONSE :
  156. case CMD_TOKEN_SOFT :
  157. dwReturn = LoadParserOutput(pParser,dwCount,&dwUsed,lppwszTok[dwCount],dwTagType[dwCount],TYPE_BOOL);
  158. break;
  159. case CMD_TOKEN_PFSGROUP :
  160. dwReturn = LoadParserOutput(pParser,dwCount,&dwUsed,lppwszTok[dwCount],dwTagType[dwCount],TYPE_PFSGROUP);
  161. break;
  162. case CMD_TOKEN_NEGOTIATION :
  163. bNegotiationSpecified = TRUE;
  164. dwReturn = LoadParserOutput(pParser,dwCount,&dwUsed,lppwszTok[dwCount],dwTagType[dwCount],TYPE_QM_OFFER);
  165. break;
  166. default :
  167. dwReturn = ERROR_INVALID_SYNTAX;
  168. break;
  169. }
  170. }
  171. if( dwReturn == ERROR_SUCCESS )
  172. {
  173. if ( !bNegotiationSpecified && (bOption == ADD_CMD))
  174. {
  175. // If its an Add cmd and no QMSec methods are specified, then add defaults
  176. _tcsncpy(szListTok,DEFAULT_QMSECMETHODS,MAX_STR_LEN-1);
  177. dwIndex = MatchEnumTagToTagIndex(CMD_TOKEN_STR_NEGOTIATION,pParser);
  178. if(dwIndex == PARSE_ERROR)
  179. {
  180. dwReturn = ERROR_SHOW_USAGE;
  181. BAIL_OUT;
  182. }
  183. dwReturn = LoadParserOutput(pParser,dwMaxArgs,&dwUsed,szListTok,dwIndex,TYPE_QM_OFFER);
  184. }
  185. }
  186. free(szListTok);
  187. error:
  188. return dwReturn;
  189. }
  190. //////////////////////////////////////////////////////////////////////////////////////////
  191. //
  192. // Function : ParseDynamicDelPolicy()
  193. //
  194. // Date of Creation : 1st oct 2001
  195. //
  196. // Parameters : IN LPWSTR *ppwcArguments, // Input stream
  197. // IN OUT PPARSER_PKT pParser,
  198. // IN DWORD dwCurrentIndex,
  199. // IN DWORD dwMaxArgs
  200. //
  201. // Return : DWORD
  202. //
  203. // Description : Validates the arguments to the contexts DynamicDelelte
  204. // (QMPolicy/MMPolicy)
  205. // History :
  206. //
  207. // Date Author Comments
  208. //
  209. //////////////////////////////////////////////////////////////////////////////////////////
  210. DWORD
  211. ParseDynamicDelPolFaction(
  212. IN LPWSTR *ppwcArguments, // Input stream
  213. IN OUT PARSER_PKT *pParser,
  214. IN DWORD dwCurrentIndex,
  215. IN DWORD dwMaxArgs
  216. )
  217. {
  218. DWORD dwCount,dwNum,dwTagIndex = 0,dwIndex = 0,dwUsed = 0;
  219. DWORD dwReturn = ERROR_SUCCESS;
  220. BOOL bTagPresent= FALSE;
  221. BOOL bArg[MAX_ARGS];
  222. _TCHAR szCmd[MAX_STR_LEN] = {0};
  223. _TCHAR szTok[MAX_STR_LEN] = {0};
  224. _TCHAR szTemp[MAX_STR_LEN] = {0};
  225. const DWORD ARG_NAME = 0; // Arg Array Index ( Same Index indicates OR'd commands)
  226. const DWORD ARG_ALL = 0;
  227. const DWORD INDEX_NAME = 0; // When no tag is present the index reflects the
  228. const DWORD INDEX_ALL = 1; // Commands as in the ValidToken Structure
  229. // with the 'untagged' arg
  230. if ( (dwMaxArgs - dwCurrentIndex) >= 2 ) // Max 1 Args Allowed
  231. {
  232. PrintErrorMessage(IPSEC_ERR,0,ERRCODE_TAG_NEEDED,ERRMSG_NAMEALL);
  233. dwReturn = RETURN_NO_ERROR;
  234. BAIL_OUT;
  235. }
  236. for(dwCount = 0;dwCount < MAX_ARGS;dwCount++) // Initialize
  237. {
  238. bArg[dwCount] = FALSE;
  239. }
  240. for(dwCount = dwCurrentIndex;(dwCount < dwMaxArgs) && (dwReturn == ERROR_SUCCESS);dwCount++)
  241. {
  242. if (_tcslen(ppwcArguments[dwCount]) < MAX_STR_LEN)
  243. {
  244. _tcsncpy(szTemp,ppwcArguments[dwCount],MAX_STR_LEN-1); // temp contains arg
  245. }
  246. else
  247. {
  248. continue;
  249. }
  250. bTagPresent = SplitCmdTok(szTemp,szCmd,szTok,MAX_STR_LEN-1,MAX_STR_LEN-1);
  251. // Check for =
  252. if (bTagPresent) // Parameter With Tag Found
  253. {
  254. dwNum = 0; // Before sending to MatchEnumTag it is needed
  255. MatchEnumTag(g_hModule,szCmd,pParser->MaxTok,pParser->ValidTok,&dwNum);
  256. if (dwNum) // Convert the output of MatchEnumTag into the TagIndex
  257. {
  258. dwIndex = MatchEnumTagToTagIndex(szCmd,pParser);
  259. if(dwIndex == PARSE_ERROR)
  260. {
  261. dwReturn = ERROR_SHOW_USAGE;
  262. BAIL_OUT;
  263. }
  264. switch(pParser->ValidTok[dwIndex].dwValue)
  265. {
  266. case CMD_TOKEN_NAME :
  267. if (!bArg[ARG_NAME])
  268. {
  269. dwReturn = LoadParserOutput(pParser,dwCount-dwCurrentIndex,&dwUsed,szTok,dwIndex,TYPE_STRING);
  270. bArg[ARG_NAME] = TRUE;
  271. }else
  272. {
  273. PrintErrorMessage(IPSEC_ERR,0,ERRCODE_TAG_ALREADY_PRESENT,ERRMSG_NAMEALL);
  274. dwReturn = RETURN_NO_ERROR;
  275. }
  276. break;
  277. case CMD_TOKEN_ALL :
  278. if (!bArg[ARG_ALL])
  279. {
  280. dwReturn = LoadParserOutput(pParser,dwCount-dwCurrentIndex,&dwUsed,szTok,dwIndex,TYPE_ALL);
  281. bArg[ARG_ALL] = TRUE;
  282. }else
  283. {
  284. PrintErrorMessage(IPSEC_ERR,0,ERRCODE_TAG_ALREADY_PRESENT,ERRMSG_NAMEALL);
  285. dwReturn = RETURN_NO_ERROR;
  286. }
  287. break;
  288. default :
  289. dwReturn = ERROR_INVALID_SYNTAX;
  290. break;
  291. }
  292. }
  293. else
  294. {
  295. PrintErrorMessage(IPSEC_ERR,0,ERRCODE_INVALID_TAG,szCmd);
  296. dwReturn = RETURN_NO_ERROR;
  297. }
  298. }
  299. else // Parameter Without a Tag Found
  300. { // Find the first free slot to position the untagged arg
  301. for(dwTagIndex=0;
  302. dwTagIndex<pParser->MaxTok && (bArg[dwTagIndex] == TRUE) ;
  303. dwTagIndex++);
  304. switch (dwTagIndex)
  305. {
  306. case ARG_ALL :
  307. if (_tcsicmp(szTok,ALL_STR) == 0)
  308. {
  309. dwReturn = LoadParserOutput(pParser,dwCount-dwCurrentIndex,&dwUsed,ppwcArguments[dwCount],INDEX_ALL,TYPE_ALL);
  310. bArg[ARG_ALL] = TRUE;
  311. }else
  312. {
  313. if (!bArg[ARG_NAME])
  314. {
  315. dwReturn = LoadParserOutput(pParser,dwCount-dwCurrentIndex,&dwUsed,szTok,INDEX_NAME,TYPE_STRING);
  316. bArg[ARG_NAME] = TRUE;
  317. }else
  318. {
  319. PrintErrorMessage(IPSEC_ERR,0,ERRCODE_TAG_ALREADY_PRESENT,ERRMSG_NAMEALL);
  320. dwReturn = RETURN_NO_ERROR;
  321. }
  322. }
  323. break;
  324. default :
  325. dwReturn = ERROR_INVALID_SYNTAX;
  326. break;
  327. }
  328. }
  329. }
  330. if(dwReturn == ERR_TAG_ALREADY_PRESENT)
  331. {
  332. PrintErrorMessage(IPSEC_ERR,0,ERRCODE_TAG_ALREADY_PRESENT,pParser->ValidTok[dwIndex].pwszToken);
  333. dwReturn = RETURN_NO_ERROR;
  334. }
  335. else
  336. {
  337. if (dwReturn == ERROR_SUCCESS)
  338. {
  339. if (!bArg[ARG_NAME] )
  340. {
  341. dwReturn = RETURN_NO_ERROR;
  342. PrintErrorMessage(IPSEC_ERR,0,ERRCODE_TAG_NEEDED,ERRMSG_NAMEALL);
  343. }
  344. }
  345. }
  346. error:
  347. return dwReturn;
  348. }
  349. //////////////////////////////////////////////////////////////////////////////////////////
  350. // Function : ParseDynamicSetConfig()
  351. //
  352. // Date of Creation : 12th oct 2001
  353. //
  354. // Parameters : IN LPTSTR lppwszTok[MAX_ARGS],
  355. // IN OUT PPARSER_PKT pParser,
  356. // IN DWORD dwCurrentIndex,
  357. // IN DWORD dwMaxArgs,
  358. // IN DWORD dwTagType[MAX_ARGS]
  359. //
  360. // Return : DWORD
  361. //
  362. // Description : Validates the arguments to the contexts DynamicSetConfig
  363. //
  364. // History :
  365. //
  366. // Date Author Comments
  367. //
  368. //////////////////////////////////////////////////////////////////////////////////////////
  369. DWORD
  370. ParseDynamicSetConfig(
  371. IN LPTSTR lppwszTok[MAX_ARGS],
  372. IN OUT PPARSER_PKT pParser,
  373. IN DWORD dwCurrentIndex,
  374. IN DWORD dwMaxArgs,
  375. IN DWORD dwTagType[MAX_ARGS]
  376. )
  377. {
  378. DWORD dwReturn = ERROR_SUCCESS,dwCount,dwUsed = 0/*,dwNum = 0*/;
  379. for(dwCount = 0;(dwCount < dwMaxArgs) && (dwReturn == ERROR_SUCCESS);dwCount++)
  380. {
  381. switch(pParser->ValidTok[dwTagType[dwCount]].dwValue)
  382. {
  383. case CMD_TOKEN_PROPERTY :
  384. dwReturn = LoadParserOutput(pParser,dwCount,&dwUsed,lppwszTok[dwCount],dwTagType[dwCount],TYPE_PROPERTY);
  385. break;
  386. case CMD_TOKEN_VALUE :
  387. dwReturn = LoadParserOutput(pParser,dwCount,&dwUsed,lppwszTok[dwCount],dwTagType[dwCount],TYPE_STRING);
  388. break;
  389. default :
  390. dwReturn = ERROR_INVALID_SYNTAX;
  391. break;
  392. }
  393. }
  394. return dwReturn;
  395. }
  396. //////////////////////////////////////////////////////////////////////////////////////////
  397. //
  398. // Function : ParseDynamicAddRule()
  399. //
  400. // Date of Creation : 10th oct 2001
  401. //
  402. // Parameters : IN LPTSTR lppwszTok[MAX_ARGS],
  403. // IN LPTSTR ppwcListTok[MAX_ARGS],
  404. // IN OUT PPARSER_PKT pParser,
  405. // IN DWORD dwCurrentIndex,
  406. // IN DWORD dwMaxArgs,
  407. // IN DWORD dwTagType[MAX_ARGS],
  408. // IN DWORD dwListArgs
  409. //
  410. // Return : DWORD
  411. //
  412. // Description : Validates the arguments to the contexts DynamicAddRule
  413. //
  414. // History :
  415. //
  416. // Date Author Comments
  417. //
  418. //////////////////////////////////////////////////////////////////////////////////////////
  419. DWORD
  420. ParseDynamicAddRule(
  421. IN LPTSTR lppwszTok[MAX_ARGS],
  422. IN OUT PPARSER_PKT pParser,
  423. IN DWORD dwCurrentIndex,
  424. IN DWORD dwMaxArgs,
  425. IN DWORD dwTagType[MAX_ARGS]
  426. )
  427. {
  428. DWORD dwReturn = ERROR_SUCCESS,dwCount,dwUsed = 0;
  429. for(dwCount = 0;(dwCount < dwMaxArgs) && (dwReturn == ERROR_SUCCESS);dwCount++)
  430. {
  431. switch(pParser->ValidTok[dwTagType[dwCount]].dwValue)
  432. {
  433. case CMD_TOKEN_QMPOLICY :
  434. case CMD_TOKEN_MMPOLICY :
  435. dwReturn = LoadParserOutput(pParser,dwCount,&dwUsed,lppwszTok[dwCount],dwTagType[dwCount],TYPE_STRING);
  436. break;
  437. case CMD_TOKEN_OUTBOUND :
  438. case CMD_TOKEN_INBOUND :
  439. dwReturn = LoadParserOutput(pParser,dwCount,&dwUsed,lppwszTok[dwCount],dwTagType[dwCount],TYPE_BOUND);
  440. break;
  441. case CMD_TOKEN_MIRROR :
  442. case CMD_TOKEN_FAILMMIFEXISTS :
  443. dwReturn = LoadParserOutput(pParser,dwCount,&dwUsed,lppwszTok[dwCount],dwTagType[dwCount],TYPE_BOOL);
  444. break;
  445. case CMD_TOKEN_SRCMASK :
  446. case CMD_TOKEN_DSTMASK :
  447. dwReturn = LoadParserOutput(pParser,dwCount,&dwUsed,lppwszTok[dwCount],dwTagType[dwCount],TYPE_MASK);
  448. break;
  449. case CMD_TOKEN_SRCADDR :
  450. case CMD_TOKEN_DSTADDR :
  451. dwReturn = LoadParserOutput(pParser,dwCount,&dwUsed,lppwszTok[dwCount],dwTagType[dwCount],TYPE_IP);
  452. break;
  453. case CMD_TOKEN_SRCPORT :
  454. case CMD_TOKEN_DSTPORT :
  455. dwReturn = LoadParserOutput(pParser,dwCount,&dwUsed,lppwszTok[dwCount],dwTagType[dwCount],TYPE_PORT);
  456. break;
  457. case CMD_TOKEN_TUNNELDST :
  458. dwReturn = LoadParserOutput(pParser,dwCount,&dwUsed,lppwszTok[dwCount],dwTagType[dwCount],TYPE_IP);
  459. break;
  460. case CMD_TOKEN_PROTO :
  461. dwReturn = LoadParserOutput(pParser,dwCount,&dwUsed,lppwszTok[dwCount],dwTagType[dwCount],TYPE_PROTOCOL);
  462. break;
  463. case CMD_TOKEN_CONNTYPE :
  464. dwReturn = LoadParserOutput(pParser,dwCount,&dwUsed,lppwszTok[dwCount],dwTagType[dwCount],TYPE_CONNTYPE);
  465. break;
  466. case CMD_TOKEN_KERB :
  467. dwReturn = LoadParserOutput(pParser,dwCount,&dwUsed,lppwszTok[dwCount],dwTagType[dwCount],TYPE_KERBAUTH);
  468. break;
  469. case CMD_TOKEN_PSK :
  470. dwReturn = LoadParserOutput(pParser,dwCount,&dwUsed,lppwszTok[dwCount],dwTagType[dwCount],TYPE_PSKAUTH);
  471. break;
  472. default :
  473. dwReturn = ERROR_INVALID_SYNTAX;
  474. break;
  475. }
  476. }
  477. return dwReturn;
  478. }
  479. //////////////////////////////////////////////////////////////////////////////////////////
  480. //
  481. // Function : ParseDynamicSetRule()
  482. //
  483. // Date of Creation : 15th oct 2001
  484. //
  485. // Parameters : IN LPTSTR lppwszTok[MAX_ARGS],
  486. // IN LPTSTR ppwcListTok[MAX_ARGS],
  487. // IN OUT PPARSER_PKT pParser,
  488. // IN DWORD dwCurrentIndex,
  489. // IN DWORD dwMaxArgs,
  490. // IN DWORD dwTagType[MAX_ARGS],
  491. // IN DWORD dwListArgs
  492. //
  493. // Return : DWORD
  494. //
  495. // Description : Validates the arguments to the contexts DynamicSetRule
  496. //
  497. // History :
  498. //
  499. // Date Author Comments
  500. //
  501. //////////////////////////////////////////////////////////////////////////////////////////
  502. DWORD
  503. ParseDynamicSetRule(
  504. IN LPTSTR lppwszTok[MAX_ARGS],
  505. IN OUT PPARSER_PKT pParser,
  506. IN DWORD dwCurrentIndex,
  507. IN DWORD dwMaxArgs,
  508. IN DWORD dwTagType[MAX_ARGS]
  509. )
  510. {
  511. DWORD dwReturn = ERROR_SUCCESS,dwCount,dwUsed = 0;
  512. for(dwCount = 0;(dwCount < dwMaxArgs) && (dwReturn == ERROR_SUCCESS);dwCount++)
  513. {
  514. switch(pParser->ValidTok[dwTagType[dwCount]].dwValue)
  515. {
  516. case CMD_TOKEN_QMPOLICY :
  517. case CMD_TOKEN_MMPOLICY :
  518. dwReturn = LoadParserOutput(pParser,dwCount,&dwUsed,lppwszTok[dwCount],dwTagType[dwCount],TYPE_STRING);
  519. break;
  520. case CMD_TOKEN_OUTBOUND :
  521. case CMD_TOKEN_INBOUND :
  522. dwReturn = LoadParserOutput(pParser,dwCount,&dwUsed,lppwszTok[dwCount],dwTagType[dwCount],TYPE_BOUND);
  523. break;
  524. case CMD_TOKEN_MIRROR :
  525. dwReturn = LoadParserOutput(pParser,dwCount,&dwUsed,lppwszTok[dwCount],dwTagType[dwCount],TYPE_BOOL);
  526. break;
  527. case CMD_TOKEN_SRCADDR :
  528. case CMD_TOKEN_DSTADDR :
  529. dwReturn = LoadParserOutput(pParser,dwCount,&dwUsed,lppwszTok[dwCount],dwTagType[dwCount],TYPE_IP);
  530. break;
  531. case CMD_TOKEN_SRCMASK :
  532. case CMD_TOKEN_DSTMASK :
  533. dwReturn = LoadParserOutput(pParser,dwCount,&dwUsed,lppwszTok[dwCount],dwTagType[dwCount],TYPE_MASK);
  534. break;
  535. case CMD_TOKEN_SRCPORT :
  536. case CMD_TOKEN_DSTPORT :
  537. dwReturn = LoadParserOutput(pParser,dwCount,&dwUsed,lppwszTok[dwCount],dwTagType[dwCount],TYPE_PORT);
  538. break;
  539. case CMD_TOKEN_TUNNELDST :
  540. dwReturn = LoadParserOutput(pParser,dwCount,&dwUsed,lppwszTok[dwCount],dwTagType[dwCount],TYPE_IP);
  541. break;
  542. case CMD_TOKEN_PROTO :
  543. dwReturn = LoadParserOutput(pParser,dwCount,&dwUsed,lppwszTok[dwCount],dwTagType[dwCount],TYPE_PROTOCOL);
  544. break;
  545. case CMD_TOKEN_CONNTYPE :
  546. dwReturn = LoadParserOutput(pParser,dwCount,&dwUsed,lppwszTok[dwCount],dwTagType[dwCount],TYPE_CONNTYPE);
  547. break;
  548. case CMD_TOKEN_KERB :
  549. dwReturn = LoadParserOutput(pParser,dwCount,&dwUsed,lppwszTok[dwCount],dwTagType[dwCount],TYPE_KERBAUTH);
  550. break;
  551. case CMD_TOKEN_PSK :
  552. dwReturn = LoadParserOutput(pParser,dwCount,&dwUsed,lppwszTok[dwCount],dwTagType[dwCount],TYPE_PSKAUTH);
  553. break;
  554. default :
  555. dwReturn = ERROR_INVALID_SYNTAX;
  556. break;
  557. }
  558. }
  559. return dwReturn;
  560. }
  561. //////////////////////////////////////////////////////////////////////////////////////////
  562. //
  563. // Function : ParseDynamicDelRule()
  564. //
  565. // Date of Creation : 12th oct 2001
  566. //
  567. // Parameters : IN LPTSTR lppwszTok[MAX_ARGS],
  568. // IN OUT PPARSER_PKT pParser,
  569. // IN DWORD dwCurrentIndex,
  570. // IN DWORD dwMaxArgs,
  571. // IN DWORD dwTagType[MAX_ARGS],
  572. //
  573. // Return : DWORD
  574. //
  575. // Description : Validates the arguments to the contexts DynamicDelRule
  576. //
  577. // History :
  578. //
  579. // Date Author Comments
  580. //
  581. //////////////////////////////////////////////////////////////////////////////////////////
  582. DWORD
  583. ParseDynamicDelRule(
  584. IN LPTSTR lppwszTok[MAX_ARGS],
  585. IN OUT PPARSER_PKT pParser,
  586. IN DWORD dwCurrentIndex,
  587. IN DWORD dwMaxArgs,
  588. IN DWORD dwTagType[MAX_ARGS]
  589. )
  590. {
  591. DWORD dwReturn = ERROR_SUCCESS,dwCount,dwUsed = 0;
  592. for(dwCount = 0;(dwCount < dwMaxArgs) && (dwReturn == ERROR_SUCCESS);dwCount++)
  593. {
  594. switch(pParser->ValidTok[dwTagType[dwCount]].dwValue)
  595. {
  596. case CMD_TOKEN_MIRROR :
  597. dwReturn = LoadParserOutput(pParser,dwCount,&dwUsed,lppwszTok[dwCount],dwTagType[dwCount],TYPE_BOOL);
  598. break;
  599. case CMD_TOKEN_SRCADDR :
  600. case CMD_TOKEN_DSTADDR :
  601. dwReturn = LoadParserOutput(pParser,dwCount,&dwUsed,lppwszTok[dwCount],dwTagType[dwCount],TYPE_IP);
  602. break;
  603. case CMD_TOKEN_SRCMASK :
  604. case CMD_TOKEN_DSTMASK :
  605. dwReturn = LoadParserOutput(pParser,dwCount,&dwUsed,lppwszTok[dwCount],dwTagType[dwCount],TYPE_MASK);
  606. break;
  607. case CMD_TOKEN_SRCPORT :
  608. case CMD_TOKEN_DSTPORT :
  609. dwReturn = LoadParserOutput(pParser,dwCount,&dwUsed,lppwszTok[dwCount],dwTagType[dwCount],TYPE_PORT);
  610. break;
  611. case CMD_TOKEN_TUNNELDST :
  612. dwReturn = LoadParserOutput(pParser,dwCount,&dwUsed,lppwszTok[dwCount],dwTagType[dwCount],TYPE_IP);
  613. break;
  614. case CMD_TOKEN_PROTO :
  615. dwReturn = LoadParserOutput(pParser,dwCount,&dwUsed,lppwszTok[dwCount],dwTagType[dwCount],TYPE_PROTOCOL);
  616. break;
  617. case CMD_TOKEN_CONNTYPE :
  618. dwReturn = LoadParserOutput(pParser,dwCount,&dwUsed,lppwszTok[dwCount],dwTagType[dwCount],TYPE_CONNTYPE);
  619. break;
  620. default :
  621. dwReturn = ERROR_INVALID_SYNTAX;
  622. break;
  623. }
  624. }
  625. return dwReturn;
  626. }
  627. //////////////////////////////////////////////////////////////////////////////
  628. //
  629. // Function : ParseDynamicShowPolicy()
  630. //
  631. // Date of Creation : 29th aug 2001
  632. //
  633. // Parameters : IN LPWSTR *ppwcArguments, // Input stream
  634. // IN OUT PPARSER_PKT pParser,
  635. // IN DWORD dwCurrentIndex,
  636. // IN DWORD dwMaxArgs
  637. //
  638. // Return : DWORD
  639. //
  640. // Description : Validates the arguments to the contexts DynamicShowPolicy
  641. // (MMPolicy/QMPolicy)
  642. // History :
  643. //
  644. // Date Author Comments
  645. //
  646. //////////////////////////////////////////////////////////////////////////////
  647. DWORD
  648. ParseDynamicShowPolFaction(
  649. IN LPWSTR *ppwcArguments,
  650. IN OUT PPARSER_PKT pParser,
  651. IN DWORD dwCurrentIndex,
  652. IN DWORD dwMaxArgs
  653. )
  654. {
  655. DWORD dwCount,dwNum,dwTagIndex = 0,dwIndex = 0,dwReturn = ERROR_SUCCESS,dwUsed = 0;
  656. BOOL bTagPresent= FALSE;
  657. BOOL bArg[MAX_ARGS];
  658. _TCHAR szCmd[MAX_STR_LEN] = {0};
  659. _TCHAR szTok[MAX_STR_LEN] = {0};
  660. _TCHAR szTemp[MAX_STR_LEN] = {0};
  661. const DWORD ARG_NAME = 0; // Arg Array Index ( Same Index indicates OR'd commands)
  662. const DWORD ARG_ALL = 0;
  663. const DWORD INDEX_NAME = 0; // When no tag is present the index reflects the
  664. const DWORD INDEX_ALL = 1; // Commands as in the ValidToken Structure
  665. if ( (dwMaxArgs - dwCurrentIndex) >= 2)
  666. {
  667. dwReturn = ERROR_INVALID_SYNTAX;
  668. BAIL_OUT;
  669. }
  670. for(dwCount = 0; dwCount < MAX_ARGS;dwCount++) // Initialize
  671. {
  672. bArg[dwCount] = FALSE;
  673. }
  674. for(dwCount = dwCurrentIndex;(dwCount < dwMaxArgs) && (dwReturn == ERROR_SUCCESS);dwCount++)
  675. {
  676. if (_tcslen(ppwcArguments[dwCount]) < MAX_STR_LEN)
  677. {
  678. _tcsncpy(szTemp,ppwcArguments[dwCount],MAX_STR_LEN-1); // temp contains arg
  679. }
  680. else
  681. {
  682. continue;
  683. }
  684. bTagPresent = SplitCmdTok(szTemp,szCmd,szTok,MAX_STR_LEN-1,MAX_STR_LEN-1);
  685. // Check for =
  686. if (bTagPresent) // Parameter With Tag Found
  687. {
  688. dwNum = 0;
  689. MatchEnumTag(g_hModule,szCmd,pParser->MaxTok,pParser->ValidTok,&dwNum);
  690. if (dwNum) // Convert the output of MatchEnumTag into the TagIndex
  691. {
  692. dwIndex = MatchEnumTagToTagIndex(szCmd,pParser);
  693. if(dwIndex == PARSE_ERROR)
  694. {
  695. dwReturn = ERROR_SHOW_USAGE;
  696. BAIL_OUT;
  697. }
  698. switch(pParser->ValidTok[dwIndex].dwValue)
  699. {
  700. case CMD_TOKEN_NAME :
  701. if (!bArg[ARG_NAME])
  702. {
  703. dwReturn = LoadParserOutput(pParser,dwCount-dwCurrentIndex,&dwUsed,szTok,dwIndex,TYPE_STRING);
  704. bArg[ARG_NAME] = TRUE;
  705. }
  706. else
  707. {
  708. dwReturn = RETURN_NO_ERROR;
  709. PrintErrorMessage(IPSEC_ERR,0,ERRCODE_TAG_ALREADY_PRESENT,ERRMSG_NAMEALL);
  710. }
  711. break;
  712. case CMD_TOKEN_ALL :
  713. if (!bArg[ARG_ALL])
  714. {
  715. dwReturn = LoadParserOutput(pParser,dwCount-dwCurrentIndex,&dwUsed,szTok,dwIndex,TYPE_ALL);
  716. bArg[ARG_ALL] = TRUE;
  717. }
  718. else
  719. {
  720. dwReturn = RETURN_NO_ERROR;
  721. PrintErrorMessage(IPSEC_ERR,0,ERRCODE_TAG_ALREADY_PRESENT,ERRMSG_NAMEALL);
  722. }
  723. break;
  724. default :
  725. dwReturn = ERROR_INVALID_SYNTAX;
  726. break;
  727. }
  728. }
  729. else
  730. {
  731. PrintErrorMessage(IPSEC_ERR,0,ERRCODE_INVALID_TAG,szCmd);
  732. dwReturn = RETURN_NO_ERROR;
  733. }
  734. }
  735. else // Parameter Without a Tag Found
  736. { // Find the first free slot to position the untagged arg
  737. for(dwTagIndex=0;
  738. dwTagIndex<pParser->MaxTok && (bArg[dwTagIndex] == TRUE) ;
  739. dwTagIndex++);
  740. switch (dwTagIndex)
  741. {
  742. case ARG_ALL :
  743. if (_tcsicmp(szTok,ALL_STR) == 0)
  744. {
  745. dwReturn = LoadParserOutput(pParser,dwCount-dwCurrentIndex,&dwUsed,ppwcArguments[dwCount],INDEX_ALL,TYPE_ALL);
  746. bArg[ARG_ALL] = TRUE;
  747. }
  748. else
  749. {
  750. if (!bArg[ARG_NAME])
  751. {
  752. dwReturn = LoadParserOutput(pParser,dwCount-dwCurrentIndex,&dwUsed,szTok,INDEX_NAME,TYPE_STRING);
  753. bArg[ARG_NAME] = TRUE;
  754. }
  755. else
  756. {
  757. dwReturn = RETURN_NO_ERROR;
  758. PrintErrorMessage(IPSEC_ERR,0,ERRCODE_TAG_ALREADY_PRESENT,ERRMSG_NAMEALL);
  759. }
  760. }
  761. break;
  762. default :
  763. dwReturn = ERROR_INVALID_SYNTAX;
  764. break;
  765. }
  766. }
  767. }
  768. if(dwReturn == ERR_TAG_ALREADY_PRESENT)
  769. {
  770. PrintErrorMessage(IPSEC_ERR,0,ERRCODE_TAG_ALREADY_PRESENT,pParser->ValidTok[dwIndex].pwszToken);
  771. dwReturn = RETURN_NO_ERROR;
  772. }
  773. else if( (dwReturn == ERROR_SUCCESS) && (!bArg[ARG_NAME] ) )
  774. {
  775. dwReturn = RETURN_NO_ERROR;
  776. PrintErrorMessage(IPSEC_ERR,0,ERRCODE_TAG_NEEDED,ERRMSG_NAMEALL);
  777. }
  778. error:
  779. return dwReturn;
  780. }
  781. //////////////////////////////////////////////////////////////////////////////////////////
  782. //
  783. // Function : ParseDynamicShowQMSAS()
  784. //
  785. // Date of Creation : 19th aug 2001
  786. //
  787. // Parameters : IN LPTSTR lppwszTok[MAX_ARGS],
  788. // IN OUT PPARSER_PKT pParser,
  789. // IN DWORD dwCurrentIndex,
  790. // IN DWORD dwMaxArgs,
  791. // IN DWORD dwTagType[MAX_ARGS]
  792. //
  793. // Return : DWORD
  794. //
  795. // Description : Validates the arguments to the contexts DynamicShowQMSAS
  796. //
  797. // History :
  798. //
  799. // Date Author Comments
  800. //
  801. //////////////////////////////////////////////////////////////////////////////////////////
  802. DWORD ParseDynamicShowQMSAS(
  803. IN LPTSTR *ppwcArguments,
  804. IN OUT PPARSER_PKT pParser,
  805. IN DWORD dwCurrentIndex,
  806. IN DWORD dwMaxArgs
  807. )
  808. {
  809. DWORD dwCount, dwNum,dwTagIndex = 0,dwIndex = 0,dwReturn = ERROR_SUCCESS,dwUsed = 0;
  810. BOOL bTagPresent= FALSE;
  811. BOOL bArg[MAX_ARGS];
  812. _TCHAR szCmd[MAX_STR_LEN] = {0};
  813. _TCHAR szTok[MAX_STR_LEN] = {0};
  814. _TCHAR szTemp[MAX_STR_LEN] = {0};
  815. const DWORD ARG_ALL = 0; // Arg Array Index ( Same Index indicates OR'd commands)
  816. const DWORD ARG_SRC = 1;
  817. const DWORD ARG_DST = 2;
  818. const DWORD ARG_PROTO = 3;
  819. const DWORD ARG_FORMAT = 4;
  820. const DWORD ARG_RESOLVEDNS = 5;
  821. const DWORD INDEX_ALL = 0; // When no tag is present the index reflects the
  822. const DWORD INDEX_SRC = 1;
  823. const DWORD INDEX_DST = 2; // Commands as in the ValidToken Structure
  824. const DWORD INDEX_PROTO = 3; // Commands as in the ValidToken Structure
  825. const DWORD INDEX_FORMAT = 4; // with the 'untagged' arg
  826. const DWORD INDEX_RESOLVEDNS = 5;
  827. if ( (dwMaxArgs - dwCurrentIndex) >= 6 ) // Max 5 Args Allowed
  828. {
  829. dwReturn = ERROR_INVALID_SYNTAX;
  830. BAIL_OUT;
  831. }
  832. for(dwCount=0;dwCount < MAX_ARGS;dwCount++) // Initialize
  833. {
  834. bArg[dwCount] = FALSE;
  835. }
  836. for(dwCount = dwCurrentIndex;(dwCount < dwMaxArgs) && (dwReturn == ERROR_SUCCESS);dwCount++)
  837. {
  838. if (_tcslen(ppwcArguments[dwCount]) < MAX_STR_LEN)
  839. {
  840. _tcsncpy(szTemp,ppwcArguments[dwCount],MAX_STR_LEN-1); // temp contains arg
  841. }
  842. else
  843. {
  844. continue;
  845. }
  846. bTagPresent = SplitCmdTok(szTemp,szCmd,szTok,MAX_STR_LEN-1,MAX_STR_LEN-1);
  847. // Check for =
  848. if (bTagPresent) // Parameter With Tag Found
  849. {
  850. dwNum = 0;
  851. MatchEnumTag(g_hModule,szCmd,pParser->MaxTok,pParser->ValidTok,&dwNum);
  852. if (dwNum) // Convert the output of MatchEnumTag into the TagIndex
  853. {
  854. dwIndex = MatchEnumTagToTagIndex(szCmd,pParser);
  855. if(dwIndex == PARSE_ERROR)
  856. {
  857. dwReturn = ERROR_SHOW_USAGE;
  858. BAIL_OUT;
  859. }
  860. switch(pParser->ValidTok[dwIndex].dwValue)
  861. {
  862. case CMD_TOKEN_ALL :
  863. if (!bArg[ARG_ALL])
  864. {
  865. dwReturn = LoadParserOutput(pParser,dwCount-dwCurrentIndex,&dwUsed,szTok,dwIndex,TYPE_BOOL);
  866. bArg[ARG_ALL] = TRUE;
  867. }
  868. else
  869. {
  870. dwReturn = ERR_TAG_ALREADY_PRESENT;
  871. }
  872. break;
  873. case CMD_TOKEN_SRCADDR :
  874. if (!bArg[ARG_SRC])
  875. {
  876. dwReturn = LoadParserOutput(pParser,dwCount-dwCurrentIndex,&dwUsed,szTok,dwIndex,TYPE_IP);
  877. bArg[ARG_SRC] = TRUE;
  878. }
  879. else
  880. {
  881. dwReturn = ERR_TAG_ALREADY_PRESENT;
  882. }
  883. break;
  884. case CMD_TOKEN_DSTADDR :
  885. if (!bArg[ARG_DST])
  886. {
  887. dwReturn = LoadParserOutput(pParser,dwCount-dwCurrentIndex,&dwUsed,szTok,dwIndex,TYPE_IP);
  888. bArg[ARG_DST] = TRUE;
  889. }
  890. else
  891. {
  892. dwReturn = ERR_TAG_ALREADY_PRESENT;
  893. }
  894. break;
  895. case CMD_TOKEN_PROTO :
  896. if( !bArg[ARG_PROTO] )
  897. {
  898. dwReturn = LoadParserOutput(pParser,dwCount-dwCurrentIndex,&dwUsed,szTok,dwIndex,TYPE_PROTOCOL);
  899. bArg[ARG_PROTO] = TRUE;
  900. }
  901. else
  902. {
  903. dwReturn = ERR_TAG_ALREADY_PRESENT;
  904. }
  905. break;
  906. case CMD_TOKEN_FORMAT :
  907. if (!bArg[ARG_FORMAT])
  908. {
  909. dwReturn = LoadParserOutput(pParser,dwCount-dwCurrentIndex,&dwUsed,szTok,dwIndex,TYPE_FORMAT);
  910. bArg[ARG_FORMAT] = TRUE;
  911. }
  912. else
  913. {
  914. dwReturn = ERR_TAG_ALREADY_PRESENT;
  915. }
  916. break;
  917. case CMD_TOKEN_RESDNS :
  918. if (!bArg[ARG_RESOLVEDNS])
  919. {
  920. dwReturn = LoadParserOutput(pParser,dwCount-dwCurrentIndex,&dwUsed,szTok,dwIndex,TYPE_BOOL);
  921. bArg[ARG_RESOLVEDNS] = TRUE;
  922. }
  923. else
  924. {
  925. dwReturn = ERR_TAG_ALREADY_PRESENT;
  926. }
  927. break;
  928. default :
  929. dwReturn = ERROR_INVALID_SYNTAX;
  930. break;
  931. }
  932. }
  933. else
  934. {
  935. PrintErrorMessage(IPSEC_ERR,0,ERRCODE_INVALID_TAG,szCmd);
  936. dwReturn = RETURN_NO_ERROR;
  937. }
  938. } else // Parameter Without a Tag Found
  939. { // Find the first free slot to position the untagged arg
  940. for(dwTagIndex=0;
  941. dwTagIndex<pParser->MaxTok && (bArg[dwTagIndex] == TRUE) ;
  942. dwTagIndex++);
  943. switch (dwTagIndex)
  944. {
  945. case ARG_ALL :
  946. if (!bArg[ARG_SRC] && !bArg[ARG_ALL] && !bArg[ARG_DST] && !bArg[ARG_PROTO])
  947. {
  948. if (_tcsicmp(szTok,ALL_STR) == 0)
  949. {
  950. dwReturn = LoadParserOutput(pParser,dwCount-dwCurrentIndex,&dwUsed,ppwcArguments[dwCount],INDEX_ALL,TYPE_ALL);
  951. bArg[ARG_ALL] = TRUE;
  952. }
  953. else
  954. {
  955. dwReturn = LoadParserOutput(pParser,dwCount-dwCurrentIndex,&dwUsed,szTok,INDEX_SRC,TYPE_IP);
  956. bArg[ARG_SRC] = TRUE;
  957. }
  958. }else if (bArg[ARG_SRC] && !bArg[ARG_ALL] && !bArg[ARG_DST] )
  959. {
  960. if (_tcsicmp(szTok,ALL_STR) == 0)
  961. {
  962. dwReturn = RETURN_NO_ERROR;
  963. PrintErrorMessage(IPSEC_ERR,0,ERRCODE_TAG_ALREADY_PRESENT,pParser->ValidTok[dwIndex].pwszToken);
  964. }
  965. else
  966. {
  967. dwReturn = LoadParserOutput(pParser,dwCount-dwCurrentIndex,&dwUsed,szTok,INDEX_DST,TYPE_IP);
  968. bArg[ARG_DST] = TRUE;
  969. }
  970. }else if (bArg[ARG_SRC] && !bArg[ARG_ALL] && bArg[ARG_DST] && !bArg[ARG_PROTO])
  971. {
  972. if (_tcsicmp(szTok,ALL_STR) == 0)
  973. {
  974. dwReturn = RETURN_NO_ERROR;
  975. PrintErrorMessage(IPSEC_ERR,0,ERRCODE_ADDR_ALL_INVALID,pParser->ValidTok[dwIndex].pwszToken);
  976. }
  977. else
  978. {
  979. dwReturn = LoadParserOutput(pParser,dwCount-dwCurrentIndex,&dwUsed,szTok,INDEX_PROTO,TYPE_PROTOCOL);
  980. bArg[ARG_PROTO] = TRUE;
  981. }
  982. }else if (bArg[ARG_SRC] && !bArg[ARG_ALL] && bArg[ARG_DST] && bArg[ARG_PROTO] && !bArg[ARG_FORMAT])
  983. {
  984. if (_tcsicmp(szTok,ALL_STR) == 0)
  985. {
  986. dwReturn = RETURN_NO_ERROR;
  987. PrintErrorMessage(IPSEC_ERR,0,ERRCODE_ADDR_ALL_INVALID,pParser->ValidTok[dwIndex].pwszToken);
  988. }
  989. else
  990. {
  991. dwReturn = LoadParserOutput(pParser,dwCount-dwCurrentIndex,&dwUsed,szTok,INDEX_FORMAT,TYPE_FORMAT);
  992. bArg[ARG_FORMAT] = TRUE;
  993. }
  994. }
  995. else
  996. {
  997. if (_tcsicmp(szTok,ALL_STR) == 0)
  998. {
  999. dwReturn = LoadParserOutput(pParser,dwCount-dwCurrentIndex,&dwUsed,ppwcArguments[dwCount],INDEX_ALL,TYPE_ALL);
  1000. bArg[ARG_ALL] = TRUE;
  1001. }
  1002. else if(bArg[ARG_ALL])
  1003. {
  1004. dwReturn = LoadParserOutput(pParser,dwCount-dwCurrentIndex,&dwUsed,szTok,INDEX_FORMAT,TYPE_FORMAT);
  1005. bArg[ARG_FORMAT] = TRUE;
  1006. }
  1007. else
  1008. {
  1009. dwReturn = ERROR_SHOW_USAGE;
  1010. }
  1011. }
  1012. break;
  1013. case ARG_SRC :
  1014. if (!bArg[ARG_SRC] && !bArg[ARG_ALL])
  1015. {
  1016. dwReturn = LoadParserOutput(pParser,dwCount-dwCurrentIndex,&dwUsed,szTok,INDEX_SRC,TYPE_IP);
  1017. bArg[ARG_SRC] = TRUE;
  1018. }
  1019. else if(bArg[ARG_ALL])
  1020. {
  1021. dwReturn = LoadParserOutput(pParser,dwCount-dwCurrentIndex,&dwUsed,szTok,INDEX_FORMAT,TYPE_FORMAT);
  1022. bArg[ARG_FORMAT] = TRUE;
  1023. }
  1024. else
  1025. {
  1026. dwReturn = RETURN_NO_ERROR;
  1027. PrintErrorMessage(IPSEC_ERR,0,ERRCODE_ADDR_ALL_INVALID,pParser->ValidTok[dwIndex].pwszToken);
  1028. }
  1029. break;
  1030. case ARG_DST :
  1031. if (!bArg[ARG_DST] && !bArg[ARG_ALL])
  1032. {
  1033. dwReturn = LoadParserOutput(pParser,dwCount-dwCurrentIndex,&dwUsed,szTok,INDEX_DST,TYPE_IP);
  1034. bArg[ARG_DST] = TRUE;
  1035. }
  1036. else
  1037. {
  1038. dwReturn = RETURN_NO_ERROR;
  1039. PrintErrorMessage(IPSEC_ERR,0,ERRCODE_ADDR_ALL_INVALID,pParser->ValidTok[dwIndex].pwszToken);
  1040. }
  1041. break;
  1042. case ARG_PROTO :
  1043. if ( (!bArg[ARG_PROTO] && !bArg[ARG_ALL]) && (bArg[ARG_SRC] || bArg[ARG_DST]) )
  1044. {
  1045. dwReturn = LoadParserOutput(pParser,dwCount-dwCurrentIndex,&dwUsed,szTok,INDEX_PROTO,TYPE_PROTOCOL);
  1046. bArg[ARG_PROTO] = TRUE;
  1047. }
  1048. else
  1049. {
  1050. dwReturn = RETURN_NO_ERROR;
  1051. PrintErrorMessage(IPSEC_ERR,0,ERRCODE_ADDR_ALL_INVALID,pParser->ValidTok[dwIndex].pwszToken);
  1052. }
  1053. break;
  1054. case ARG_FORMAT :
  1055. if (!bArg[ARG_FORMAT])
  1056. {
  1057. dwReturn = LoadParserOutput(pParser,dwCount-dwCurrentIndex,&dwUsed,ppwcArguments[dwCount],INDEX_FORMAT,TYPE_FORMAT);
  1058. bArg[ARG_FORMAT] = TRUE;
  1059. }
  1060. else
  1061. {
  1062. dwReturn = ERR_TAG_ALREADY_PRESENT;
  1063. }
  1064. break;
  1065. case ARG_RESOLVEDNS :
  1066. if (!bArg[ARG_RESOLVEDNS])
  1067. {
  1068. dwReturn = LoadParserOutput(pParser,dwCount-dwCurrentIndex,&dwUsed,ppwcArguments[dwCount],INDEX_RESOLVEDNS,TYPE_BOOL);
  1069. bArg[ARG_RESOLVEDNS] = TRUE;
  1070. }
  1071. else
  1072. {
  1073. dwReturn = ERR_TAG_ALREADY_PRESENT;
  1074. }
  1075. break;
  1076. default :
  1077. dwReturn = ERROR_INVALID_SYNTAX;
  1078. break;
  1079. }
  1080. }
  1081. }
  1082. if(dwReturn == ERR_TAG_ALREADY_PRESENT)
  1083. {
  1084. PrintErrorMessage(IPSEC_ERR,0,ERRCODE_TAG_ALREADY_PRESENT,pParser->ValidTok[dwIndex].pwszToken);
  1085. dwReturn = RETURN_NO_ERROR;
  1086. }
  1087. error:
  1088. return dwReturn;
  1089. }
  1090. //////////////////////////////////////////////////////////////////////////////////////////
  1091. //
  1092. // Function : ParseDynamicShowMMFilter()
  1093. //
  1094. // Date of Creation : 19th Aug 2001
  1095. //
  1096. // Parameters : IN LPWSTR *ppwcArguments, // Input stream
  1097. // IN OUT PPARSER_PKT pParser,
  1098. // IN DWORD dwCurrentIndex,
  1099. // IN DWORD dwMaxArgs
  1100. //
  1101. //
  1102. // Return : DWORD
  1103. //
  1104. // Description : Validates the arguments to the contexts DynamicShowMMFilter
  1105. //
  1106. // History :
  1107. //
  1108. // Date Author Comments
  1109. //
  1110. //////////////////////////////////////////////////////////////////////////////////////////
  1111. DWORD
  1112. ParseDynamicShowMMFilter(
  1113. IN LPWSTR *ppwcArguments,
  1114. IN OUT PPARSER_PKT pParser,
  1115. IN DWORD dwCurrentIndex,
  1116. IN DWORD dwMaxArgs
  1117. )
  1118. {
  1119. DWORD dwCount,dwNum = 0,dwTagIndex = 0,dwIndex = 0;
  1120. DWORD dwReturn = ERROR_SUCCESS,dwUsed = 0;
  1121. BOOL bTagPresent= FALSE;
  1122. BOOL bArg[MAX_ARGS];
  1123. _TCHAR szCmd[MAX_STR_LEN] = {0};
  1124. _TCHAR szTok[MAX_STR_LEN] = {0};
  1125. _TCHAR szTemp[MAX_STR_LEN] = {0};
  1126. const DWORD ARG_NAME = 0; // Arg Array Index ( Same Index indicates OR'd commands)
  1127. const DWORD ARG_ALL = 0;
  1128. const DWORD ARG_FILTERTYPE = 1;
  1129. const DWORD ARG_SRCADDR = 2;
  1130. const DWORD ARG_DSTADDR = 3;
  1131. const DWORD ARG_SRCMASK = 4;
  1132. const DWORD ARG_DSTMASK = 5;
  1133. const DWORD ARG_RESOLVEDNS = 6;
  1134. const DWORD INDEX_NAME = 0; // When no tag is present the index reflects the
  1135. const DWORD INDEX_ALL = 1; // Commands as in the ValidToken Structure
  1136. const DWORD INDEX_FILTERTYPE = 2;
  1137. const DWORD INDEX_SRCADDR = 3;
  1138. const DWORD INDEX_DSTADDR = 4;
  1139. const DWORD INDEX_SRCMASK = 5;
  1140. const DWORD INDEX_DSTMASK = 6;
  1141. const DWORD INDEX_RESOLVEDNS = 7;
  1142. if ( (dwMaxArgs - dwCurrentIndex) >= 8 )
  1143. {
  1144. dwReturn = ERROR_INVALID_SYNTAX;
  1145. BAIL_OUT;
  1146. }
  1147. for(dwCount=0;dwCount < MAX_ARGS;dwCount++)
  1148. {
  1149. bArg[dwCount] = FALSE;
  1150. }
  1151. for(dwCount = dwCurrentIndex;(dwCount < dwMaxArgs) && (dwReturn == ERROR_SUCCESS);dwCount++)
  1152. {
  1153. if (_tcslen(ppwcArguments[dwCount]) < MAX_STR_LEN)
  1154. {
  1155. _tcsncpy(szTemp,ppwcArguments[dwCount],MAX_STR_LEN-1); // temp contains arg
  1156. }
  1157. else
  1158. {
  1159. continue;
  1160. }
  1161. bTagPresent = SplitCmdTok(szTemp,szCmd,szTok,MAX_STR_LEN-1,MAX_STR_LEN-1);
  1162. // Check for =
  1163. if (bTagPresent) // Parameter With Tag Found
  1164. {
  1165. dwNum = 0;
  1166. MatchEnumTag(g_hModule,szCmd,pParser->MaxTok,pParser->ValidTok,&dwNum);
  1167. if (dwNum) // Convert the output of MatchEnumTag into the TagIndex
  1168. {
  1169. dwIndex = MatchEnumTagToTagIndex(szCmd,pParser);
  1170. if(dwIndex == PARSE_ERROR)
  1171. {
  1172. dwReturn = ERROR_SHOW_USAGE;
  1173. BAIL_OUT;
  1174. }
  1175. switch(pParser->ValidTok[dwIndex].dwValue)
  1176. {
  1177. case CMD_TOKEN_NAME :
  1178. if (!bArg[ARG_NAME])
  1179. {
  1180. dwReturn = LoadParserOutput(pParser,dwCount-dwCurrentIndex,&dwUsed,szTok,dwIndex,TYPE_STRING);
  1181. bArg[ARG_NAME] = TRUE;
  1182. }
  1183. else
  1184. {
  1185. dwReturn = RETURN_NO_ERROR;
  1186. PrintErrorMessage(IPSEC_ERR,0,ERRCODE_TAG_ALREADY_PRESENT,ERRMSG_NAMEALL);
  1187. }
  1188. break;
  1189. case CMD_TOKEN_ALL :
  1190. if (!bArg[ARG_ALL])
  1191. {
  1192. dwReturn = LoadParserOutput(pParser,dwCount-dwCurrentIndex,&dwUsed,szTok,dwIndex,TYPE_ALL);
  1193. bArg[ARG_ALL] = TRUE;
  1194. }
  1195. else
  1196. {
  1197. dwReturn = RETURN_NO_ERROR;
  1198. PrintErrorMessage(IPSEC_ERR,0,ERRCODE_TAG_ALREADY_PRESENT,ERRMSG_NAMEALL);
  1199. }
  1200. break;
  1201. case CMD_TOKEN_TYPE :
  1202. if (!bArg[ARG_FILTERTYPE])
  1203. {
  1204. dwReturn = LoadParserOutput(pParser,dwCount-dwCurrentIndex,&dwUsed,szTok,dwIndex,TYPE_FILTER);
  1205. bArg[ARG_FILTERTYPE] = TRUE;
  1206. }
  1207. else
  1208. {
  1209. dwReturn = ERR_TAG_ALREADY_PRESENT;
  1210. }
  1211. break;
  1212. case CMD_TOKEN_SRCADDR :
  1213. if (!bArg[ARG_SRCADDR])
  1214. {
  1215. dwReturn = LoadParserOutput(pParser,dwCount-dwCurrentIndex,&dwUsed,szTok,dwIndex,TYPE_IP);
  1216. bArg[ARG_SRCADDR] = TRUE;
  1217. }
  1218. else
  1219. {
  1220. dwReturn = ERR_TAG_ALREADY_PRESENT;
  1221. }
  1222. break;
  1223. case CMD_TOKEN_DSTADDR :
  1224. if (!bArg[ARG_DSTADDR])
  1225. {
  1226. dwReturn = LoadParserOutput(pParser,dwCount-dwCurrentIndex,&dwUsed,szTok,dwIndex,TYPE_IP);
  1227. bArg[ARG_DSTADDR] = TRUE;
  1228. }
  1229. else
  1230. {
  1231. dwReturn = ERR_TAG_ALREADY_PRESENT;
  1232. }
  1233. break;
  1234. case CMD_TOKEN_SRCMASK :
  1235. if (!bArg[ARG_SRCMASK])
  1236. {
  1237. dwReturn = LoadParserOutput(pParser,dwCount-dwCurrentIndex,&dwUsed,szTok,dwIndex,TYPE_MASK);
  1238. bArg[ARG_SRCMASK] = TRUE;
  1239. }
  1240. else
  1241. {
  1242. dwReturn = ERR_TAG_ALREADY_PRESENT;
  1243. }
  1244. break;
  1245. case CMD_TOKEN_DSTMASK :
  1246. if (!bArg[ARG_SRCMASK])
  1247. {
  1248. dwReturn = LoadParserOutput(pParser,dwCount-dwCurrentIndex,&dwUsed,szTok,dwIndex,TYPE_MASK);
  1249. bArg[ARG_DSTMASK] = TRUE;
  1250. }
  1251. else
  1252. {
  1253. dwReturn = ERR_TAG_ALREADY_PRESENT;
  1254. }
  1255. break;
  1256. case CMD_TOKEN_RESDNS :
  1257. if (!bArg[ARG_RESOLVEDNS])
  1258. {
  1259. dwReturn = LoadParserOutput(pParser,dwCount-dwCurrentIndex,&dwUsed,szTok,dwIndex,TYPE_BOOL);
  1260. bArg[ARG_RESOLVEDNS] = TRUE;
  1261. }
  1262. else
  1263. {
  1264. dwReturn = ERR_TAG_ALREADY_PRESENT;
  1265. }
  1266. break;
  1267. default :
  1268. dwReturn = ERROR_INVALID_SYNTAX;
  1269. break;
  1270. }
  1271. }
  1272. else
  1273. {
  1274. PrintErrorMessage(IPSEC_ERR,0,ERRCODE_INVALID_TAG,szCmd);
  1275. dwReturn = RETURN_NO_ERROR;
  1276. }
  1277. }
  1278. else // Parameter Without a Tag Found
  1279. { // Find the first free slot to position the untagged arg
  1280. for(dwTagIndex=0;
  1281. dwTagIndex<pParser->MaxTok && (bArg[dwTagIndex] == TRUE) ;
  1282. dwTagIndex++);
  1283. switch (dwTagIndex)
  1284. {
  1285. case ARG_ALL :
  1286. if (_tcsicmp(szTok,ALL_STR) == 0)
  1287. {
  1288. dwReturn = LoadParserOutput(pParser,dwCount-dwCurrentIndex,&dwUsed,ppwcArguments[dwCount],INDEX_ALL,TYPE_ALL);
  1289. bArg[ARG_ALL] = TRUE;
  1290. }
  1291. else
  1292. {
  1293. if (!bArg[ARG_NAME])
  1294. {
  1295. dwReturn = LoadParserOutput(pParser,dwCount-dwCurrentIndex,&dwUsed,szTok,INDEX_NAME,TYPE_STRING);
  1296. bArg[ARG_NAME] = TRUE;
  1297. }
  1298. else
  1299. {
  1300. dwReturn = RETURN_NO_ERROR;
  1301. PrintErrorMessage(IPSEC_ERR,0,ERRCODE_TAG_ALREADY_PRESENT,ERRMSG_NAMEALL);
  1302. }
  1303. }
  1304. break;
  1305. case ARG_FILTERTYPE :
  1306. if (!bArg[ARG_FILTERTYPE])
  1307. {
  1308. dwReturn = LoadParserOutput(pParser,dwCount-dwCurrentIndex,&dwUsed,ppwcArguments[dwCount],INDEX_FILTERTYPE,TYPE_FILTER);
  1309. bArg[ARG_FILTERTYPE] = TRUE;
  1310. }
  1311. else
  1312. {
  1313. dwReturn = ERR_TAG_ALREADY_PRESENT;
  1314. }
  1315. break;
  1316. case ARG_SRCADDR :
  1317. if (!bArg[ARG_SRCADDR])
  1318. {
  1319. dwReturn = LoadParserOutput(pParser,dwCount-dwCurrentIndex,&dwUsed,ppwcArguments[dwCount],INDEX_SRCADDR,TYPE_IP);
  1320. bArg[ARG_SRCADDR] = TRUE;
  1321. }
  1322. else
  1323. {
  1324. dwReturn = ERR_TAG_ALREADY_PRESENT;
  1325. }
  1326. break;
  1327. case ARG_DSTADDR :
  1328. if (!bArg[ARG_DSTADDR])
  1329. {
  1330. dwReturn = LoadParserOutput(pParser,dwCount-dwCurrentIndex,&dwUsed,ppwcArguments[dwCount],INDEX_DSTADDR,TYPE_IP);
  1331. bArg[ARG_DSTADDR] = TRUE;
  1332. }
  1333. else
  1334. {
  1335. dwReturn = ERR_TAG_ALREADY_PRESENT;
  1336. }
  1337. break;
  1338. case ARG_SRCMASK :
  1339. if (!bArg[ARG_SRCMASK])
  1340. {
  1341. dwReturn = LoadParserOutput(pParser,dwCount-dwCurrentIndex,&dwUsed,ppwcArguments[dwCount],INDEX_SRCMASK,TYPE_MASK);
  1342. bArg[ARG_SRCMASK] = TRUE;
  1343. }
  1344. else
  1345. {
  1346. dwReturn = ERR_TAG_ALREADY_PRESENT;
  1347. }
  1348. break;
  1349. case ARG_DSTMASK :
  1350. if (!bArg[ARG_DSTMASK])
  1351. {
  1352. dwReturn = LoadParserOutput(pParser,dwCount-dwCurrentIndex,&dwUsed,ppwcArguments[dwCount],INDEX_DSTMASK,TYPE_MASK);
  1353. bArg[ARG_DSTMASK] = TRUE;
  1354. }
  1355. else
  1356. {
  1357. dwReturn = ERR_TAG_ALREADY_PRESENT;
  1358. }
  1359. break;
  1360. case ARG_RESOLVEDNS :
  1361. if (!bArg[ARG_RESOLVEDNS])
  1362. {
  1363. dwReturn = LoadParserOutput(pParser,dwCount-dwCurrentIndex,&dwUsed,ppwcArguments[dwCount],INDEX_RESOLVEDNS,TYPE_BOOL);
  1364. bArg[ARG_RESOLVEDNS] = TRUE;
  1365. }
  1366. else
  1367. {
  1368. dwReturn = ERR_TAG_ALREADY_PRESENT;
  1369. }
  1370. break;
  1371. default :
  1372. dwReturn = ERROR_INVALID_SYNTAX;
  1373. break;
  1374. }
  1375. }
  1376. }
  1377. if(dwReturn == ERR_TAG_ALREADY_PRESENT)
  1378. {
  1379. PrintErrorMessage(IPSEC_ERR,0,ERRCODE_TAG_ALREADY_PRESENT,pParser->ValidTok[dwIndex].pwszToken);
  1380. dwReturn = RETURN_NO_ERROR;
  1381. }
  1382. else if( (dwReturn == ERROR_SUCCESS) && (!bArg[ARG_NAME] ) )
  1383. {
  1384. dwReturn = RETURN_NO_ERROR;
  1385. PrintErrorMessage(IPSEC_ERR,0,ERRCODE_TAG_NEEDED,ERRMSG_NAMEALL);
  1386. }
  1387. error:
  1388. return dwReturn;
  1389. }
  1390. //////////////////////////////////////////////////////////////////////////////////////////
  1391. //
  1392. // Function : ParseDynamicShowQMFilter()
  1393. //
  1394. // Date of Creation : 29th Aug 2001
  1395. //
  1396. // Parameters : IN LPWSTR *ppwcArguments, // Input stream
  1397. // IN OUT PPARSER_PKT pParser,
  1398. // IN DWORD dwCurrentIndex,
  1399. // IN DWORD dwMaxArgs
  1400. //
  1401. //
  1402. // Return : DWORD
  1403. //
  1404. // Description : Validates the arguments to the contexts DynamicShowQMFilter
  1405. //
  1406. // History :
  1407. //
  1408. // Date Author Comments
  1409. //
  1410. //////////////////////////////////////////////////////////////////////////////////////////
  1411. DWORD
  1412. ParseDynamicShowQMFilter(
  1413. IN LPWSTR *ppwcArguments,
  1414. IN OUT PPARSER_PKT pParser,
  1415. IN DWORD dwCurrentIndex,
  1416. IN DWORD dwMaxArgs
  1417. )
  1418. {
  1419. DWORD dwCount,dwNum = 0,dwTagIndex = 0,dwIndex = 0;
  1420. DWORD dwReturn = ERROR_SUCCESS,dwUsed = 0;
  1421. BOOL bTagPresent= FALSE;
  1422. BOOL bArg[MAX_ARGS];
  1423. _TCHAR szCmd[MAX_STR_LEN] = {0};
  1424. _TCHAR szTok[MAX_STR_LEN] = {0};
  1425. _TCHAR szTemp[MAX_STR_LEN] = {0};
  1426. const DWORD ARG_NAME = 0; // Arg Array Index ( Same Index indicates OR'd commands)
  1427. const DWORD ARG_ALL = 0;
  1428. const DWORD ARG_FILTERTYPE = 1;
  1429. const DWORD ARG_SRCADDR = 2;
  1430. const DWORD ARG_DSTADDR = 3;
  1431. const DWORD ARG_SRCMASK = 4;
  1432. const DWORD ARG_DSTMASK = 5;
  1433. const DWORD ARG_PROTO = 6;
  1434. const DWORD ARG_SRCPORT = 7;
  1435. const DWORD ARG_DSTPORT = 8;
  1436. const DWORD ARG_ACTINBOUND = 9;
  1437. const DWORD ARG_ACTOUTBOUND = 10;
  1438. const DWORD ARG_RESOLVEDNS = 11;
  1439. const DWORD INDEX_NAME = 0; // When no tag is present the index reflects the
  1440. const DWORD INDEX_ALL = 1; // Commands as in the ValidToken Structure
  1441. const DWORD INDEX_FILTERTYPE = 2;
  1442. const DWORD INDEX_SRCADDR = 3;
  1443. const DWORD INDEX_DSTADDR = 4;
  1444. const DWORD INDEX_SRCMASK = 5;
  1445. const DWORD INDEX_DSTMASK = 6;
  1446. const DWORD INDEX_PROTO = 7;
  1447. const DWORD INDEX_SRCPORT = 8;
  1448. const DWORD INDEX_DSTPORT = 9;
  1449. const DWORD INDEX_ACTINBOUND = 10;
  1450. const DWORD INDEX_ACTOUTBOUND = 11;
  1451. const DWORD INDEX_RESOLVEDNS = 12;
  1452. if ( (dwMaxArgs - dwCurrentIndex) >= 13 )
  1453. {
  1454. dwReturn = ERROR_INVALID_SYNTAX;
  1455. BAIL_OUT;
  1456. }
  1457. for(dwCount =0;dwCount < MAX_ARGS;dwCount++)
  1458. {
  1459. bArg[dwCount] = FALSE;
  1460. }
  1461. for(dwCount = dwCurrentIndex;(dwCount < dwMaxArgs) && (dwReturn == ERROR_SUCCESS);dwCount++)
  1462. {
  1463. if (_tcslen(ppwcArguments[dwCount]) < MAX_STR_LEN)
  1464. {
  1465. _tcsncpy(szTemp,ppwcArguments[dwCount],MAX_STR_LEN-1); // temp contains arg
  1466. }
  1467. else
  1468. {
  1469. continue;
  1470. }
  1471. bTagPresent = SplitCmdTok(szTemp,szCmd,szTok,MAX_STR_LEN-1,MAX_STR_LEN-1);
  1472. // Check for =
  1473. if (bTagPresent) // Parameter With Tag Found
  1474. {
  1475. dwNum = 0;
  1476. MatchEnumTag(g_hModule,szCmd,pParser->MaxTok,pParser->ValidTok,&dwNum);
  1477. if (dwNum) // Convert the output of MatchEnumTag into the TagIndex
  1478. {
  1479. dwIndex = MatchEnumTagToTagIndex(szCmd,pParser);
  1480. if(dwIndex == PARSE_ERROR)
  1481. {
  1482. dwReturn = ERROR_SHOW_USAGE;
  1483. BAIL_OUT;
  1484. }
  1485. switch(pParser->ValidTok[dwIndex].dwValue)
  1486. {
  1487. case CMD_TOKEN_NAME :
  1488. if (!bArg[ARG_NAME])
  1489. {
  1490. dwReturn = LoadParserOutput(pParser,dwCount-dwCurrentIndex,&dwUsed,szTok,dwIndex,TYPE_STRING);
  1491. bArg[ARG_NAME] = TRUE;
  1492. }
  1493. else
  1494. {
  1495. dwReturn = RETURN_NO_ERROR;
  1496. PrintErrorMessage(IPSEC_ERR,0,ERRCODE_TAG_ALREADY_PRESENT,ERRMSG_NAMEALL);
  1497. }
  1498. break;
  1499. case CMD_TOKEN_ALL :
  1500. if (!bArg[ARG_ALL])
  1501. {
  1502. dwReturn = LoadParserOutput(pParser,dwCount-dwCurrentIndex,&dwUsed,szTok,dwIndex,TYPE_ALL);
  1503. bArg[ARG_ALL] = TRUE;
  1504. }
  1505. else
  1506. {
  1507. dwReturn = RETURN_NO_ERROR;
  1508. PrintErrorMessage(IPSEC_ERR,0,ERRCODE_TAG_ALREADY_PRESENT,ERRMSG_NAMEALL);
  1509. }
  1510. break;
  1511. case CMD_TOKEN_TYPE :
  1512. if (!bArg[ARG_FILTERTYPE])
  1513. {
  1514. dwReturn = LoadParserOutput(pParser,dwCount-dwCurrentIndex,&dwUsed,szTok,dwIndex,TYPE_FILTER);
  1515. bArg[ARG_FILTERTYPE] = TRUE;
  1516. }
  1517. else
  1518. {
  1519. dwReturn = ERR_TAG_ALREADY_PRESENT;
  1520. }
  1521. break;
  1522. case CMD_TOKEN_SRCADDR :
  1523. if (!bArg[ARG_SRCADDR])
  1524. {
  1525. dwReturn = LoadParserOutput(pParser,dwCount-dwCurrentIndex,&dwUsed,szTok,dwIndex,TYPE_IP);
  1526. bArg[ARG_SRCADDR] = TRUE;
  1527. }
  1528. else
  1529. {
  1530. dwReturn = ERR_TAG_ALREADY_PRESENT;
  1531. }
  1532. break;
  1533. case CMD_TOKEN_DSTADDR :
  1534. if (!bArg[ARG_DSTADDR])
  1535. {
  1536. dwReturn = LoadParserOutput(pParser,dwCount-dwCurrentIndex,&dwUsed,szTok,dwIndex,TYPE_IP);
  1537. bArg[ARG_DSTADDR] = TRUE;
  1538. }
  1539. else
  1540. {
  1541. dwReturn = ERR_TAG_ALREADY_PRESENT;
  1542. }
  1543. break;
  1544. case CMD_TOKEN_SRCMASK :
  1545. if (!bArg[ARG_SRCMASK])
  1546. {
  1547. dwReturn = LoadParserOutput(pParser,dwCount-dwCurrentIndex,&dwUsed,szTok,dwIndex,TYPE_MASK);
  1548. bArg[ARG_SRCMASK] = TRUE;
  1549. }
  1550. else
  1551. {
  1552. dwReturn = ERR_TAG_ALREADY_PRESENT;
  1553. }
  1554. break;
  1555. case CMD_TOKEN_DSTMASK :
  1556. if (!bArg[ARG_SRCMASK])
  1557. {
  1558. dwReturn = LoadParserOutput(pParser,dwCount-dwCurrentIndex,&dwUsed,szTok,dwIndex,TYPE_MASK);
  1559. bArg[ARG_DSTMASK] = TRUE;
  1560. }
  1561. else
  1562. {
  1563. dwReturn = ERR_TAG_ALREADY_PRESENT;
  1564. }
  1565. break;
  1566. case CMD_TOKEN_PROTO :
  1567. if (!bArg[ARG_PROTO])
  1568. {
  1569. dwReturn = LoadParserOutput(pParser,dwCount-dwCurrentIndex,&dwUsed,szTok,dwIndex,TYPE_PROTOCOL);
  1570. bArg[ARG_PROTO] = TRUE;
  1571. }
  1572. else
  1573. {
  1574. dwReturn = ERR_TAG_ALREADY_PRESENT;
  1575. }
  1576. break;
  1577. case CMD_TOKEN_SRCPORT :
  1578. if (!bArg[ARG_SRCPORT])
  1579. {
  1580. dwReturn = LoadParserOutput(pParser,dwCount-dwCurrentIndex,&dwUsed,szTok,dwIndex,TYPE_PORT);
  1581. bArg[ARG_SRCPORT] = TRUE;
  1582. }
  1583. else
  1584. {
  1585. dwReturn = ERR_TAG_ALREADY_PRESENT;
  1586. }
  1587. break;
  1588. case CMD_TOKEN_DSTPORT :
  1589. if (!bArg[ARG_DSTPORT])
  1590. {
  1591. dwReturn = LoadParserOutput(pParser,dwCount-dwCurrentIndex,&dwUsed,szTok,dwIndex,TYPE_PORT);
  1592. bArg[ARG_DSTPORT] = TRUE;
  1593. }
  1594. else
  1595. {
  1596. dwReturn = ERR_TAG_ALREADY_PRESENT;
  1597. }
  1598. break;
  1599. case CMD_TOKEN_INBOUND :
  1600. if (!bArg[ARG_ACTINBOUND])
  1601. {
  1602. dwReturn = LoadParserOutput(pParser,dwCount-dwCurrentIndex,&dwUsed,szTok,dwIndex,TYPE_BOUND);
  1603. bArg[ARG_ACTINBOUND] = TRUE;
  1604. }
  1605. else
  1606. {
  1607. dwReturn = ERR_TAG_ALREADY_PRESENT;
  1608. }
  1609. break;
  1610. case CMD_TOKEN_OUTBOUND :
  1611. if (!bArg[ARG_ACTOUTBOUND])
  1612. {
  1613. dwReturn = LoadParserOutput(pParser,dwCount-dwCurrentIndex,&dwUsed,szTok,dwIndex,TYPE_BOUND);
  1614. bArg[ARG_ACTOUTBOUND] = TRUE;
  1615. }
  1616. else
  1617. {
  1618. dwReturn = ERR_TAG_ALREADY_PRESENT;
  1619. }
  1620. break;
  1621. case CMD_TOKEN_RESDNS :
  1622. if (!bArg[ARG_RESOLVEDNS])
  1623. {
  1624. dwReturn = LoadParserOutput(pParser,dwCount-dwCurrentIndex,&dwUsed,szTok,dwIndex,TYPE_BOOL);
  1625. bArg[ARG_RESOLVEDNS] = TRUE;
  1626. }
  1627. else
  1628. {
  1629. dwReturn = ERR_TAG_ALREADY_PRESENT;
  1630. }
  1631. break;
  1632. default :
  1633. dwReturn = ERROR_INVALID_SYNTAX;
  1634. break;
  1635. }
  1636. }
  1637. else
  1638. {
  1639. PrintErrorMessage(IPSEC_ERR,0,ERRCODE_INVALID_TAG,szCmd);
  1640. dwReturn = RETURN_NO_ERROR;
  1641. }
  1642. }
  1643. else // Parameter Without a Tag Found
  1644. { // Find the first free slot to position the untagged arg
  1645. for(dwTagIndex=0;
  1646. dwTagIndex<pParser->MaxTok && (bArg[dwTagIndex] == TRUE) ;
  1647. dwTagIndex++);
  1648. switch (dwTagIndex)
  1649. {
  1650. case ARG_ALL :
  1651. if (_tcsicmp(szTok,ALL_STR) == 0)
  1652. {
  1653. dwReturn = LoadParserOutput(pParser,dwCount-dwCurrentIndex,&dwUsed,ppwcArguments[dwCount],INDEX_ALL,TYPE_ALL);
  1654. bArg[ARG_ALL] = TRUE;
  1655. }
  1656. else
  1657. {
  1658. if (!bArg[ARG_NAME])
  1659. {
  1660. dwReturn = LoadParserOutput(pParser,dwCount-dwCurrentIndex,&dwUsed,szTok,INDEX_NAME,TYPE_STRING);
  1661. bArg[ARG_NAME] = TRUE;
  1662. }
  1663. else
  1664. {
  1665. dwReturn = RETURN_NO_ERROR;
  1666. PrintErrorMessage(IPSEC_ERR,0,ERRCODE_TAG_ALREADY_PRESENT,ERRMSG_NAMEALL);
  1667. }
  1668. }
  1669. break;
  1670. case ARG_FILTERTYPE :
  1671. if (!bArg[ARG_FILTERTYPE])
  1672. {
  1673. dwReturn = LoadParserOutput(pParser,dwCount-dwCurrentIndex,&dwUsed,ppwcArguments[dwCount],INDEX_FILTERTYPE,TYPE_FILTER);
  1674. bArg[ARG_FILTERTYPE] = TRUE;
  1675. }
  1676. else
  1677. {
  1678. dwReturn = ERR_TAG_ALREADY_PRESENT;
  1679. }
  1680. break;
  1681. case ARG_SRCADDR :
  1682. if (!bArg[ARG_SRCADDR])
  1683. {
  1684. dwReturn = LoadParserOutput(pParser,dwCount-dwCurrentIndex,&dwUsed,ppwcArguments[dwCount],INDEX_SRCADDR,TYPE_IP);
  1685. bArg[ARG_SRCADDR] = TRUE;
  1686. }
  1687. else
  1688. {
  1689. dwReturn = ERR_TAG_ALREADY_PRESENT;
  1690. }
  1691. break;
  1692. case ARG_DSTADDR :
  1693. if (!bArg[ARG_DSTADDR])
  1694. {
  1695. dwReturn = LoadParserOutput(pParser,dwCount-dwCurrentIndex,&dwUsed,ppwcArguments[dwCount],INDEX_DSTADDR,TYPE_IP);
  1696. bArg[ARG_DSTADDR] = TRUE;
  1697. }
  1698. else
  1699. {
  1700. dwReturn = ERR_TAG_ALREADY_PRESENT;
  1701. }
  1702. break;
  1703. case ARG_SRCMASK :
  1704. if (!bArg[ARG_SRCMASK])
  1705. {
  1706. dwReturn = LoadParserOutput(pParser,dwCount-dwCurrentIndex,&dwUsed,ppwcArguments[dwCount],INDEX_SRCMASK,TYPE_MASK);
  1707. bArg[ARG_SRCMASK] = TRUE;
  1708. }
  1709. else
  1710. {
  1711. dwReturn = ERR_TAG_ALREADY_PRESENT;
  1712. }
  1713. break;
  1714. case ARG_DSTMASK :
  1715. if (!bArg[ARG_DSTMASK])
  1716. {
  1717. dwReturn = LoadParserOutput(pParser,dwCount-dwCurrentIndex,&dwUsed,ppwcArguments[dwCount],INDEX_DSTMASK,TYPE_MASK);
  1718. bArg[ARG_DSTMASK] = TRUE;
  1719. }
  1720. else
  1721. {
  1722. dwReturn = ERR_TAG_ALREADY_PRESENT;
  1723. }
  1724. break;
  1725. case ARG_PROTO :
  1726. if (!bArg[ARG_PROTO])
  1727. {
  1728. dwReturn = LoadParserOutput(pParser,dwCount-dwCurrentIndex,&dwUsed,ppwcArguments[dwCount],INDEX_PROTO,TYPE_PROTOCOL);
  1729. bArg[ARG_PROTO] = TRUE;
  1730. }
  1731. else
  1732. {
  1733. dwReturn = ERR_TAG_ALREADY_PRESENT;
  1734. }
  1735. break;
  1736. case ARG_SRCPORT :
  1737. if (!bArg[ARG_SRCPORT])
  1738. {
  1739. dwReturn = LoadParserOutput(pParser,dwCount-dwCurrentIndex,&dwUsed,ppwcArguments[dwCount],INDEX_SRCPORT,TYPE_PORT);
  1740. bArg[ARG_SRCPORT] = TRUE;
  1741. }
  1742. else
  1743. {
  1744. dwReturn = ERR_TAG_ALREADY_PRESENT;
  1745. }
  1746. break;
  1747. case ARG_DSTPORT :
  1748. if (!bArg[ARG_DSTPORT])
  1749. {
  1750. dwReturn = LoadParserOutput(pParser,dwCount-dwCurrentIndex,&dwUsed,ppwcArguments[dwCount],INDEX_DSTPORT,TYPE_PORT);
  1751. bArg[ARG_DSTPORT] = TRUE;
  1752. }
  1753. else
  1754. {
  1755. dwReturn = ERR_TAG_ALREADY_PRESENT;
  1756. }
  1757. break;
  1758. case ARG_ACTINBOUND :
  1759. if (!bArg[ARG_ACTINBOUND])
  1760. {
  1761. dwReturn = LoadParserOutput(pParser,dwCount-dwCurrentIndex,&dwUsed,ppwcArguments[dwCount],INDEX_ACTINBOUND,TYPE_BOUND);
  1762. bArg[ARG_ACTINBOUND] = TRUE;
  1763. }
  1764. else
  1765. {
  1766. dwReturn = ERR_TAG_ALREADY_PRESENT;
  1767. }
  1768. break;
  1769. case ARG_ACTOUTBOUND :
  1770. if (!bArg[ARG_ACTOUTBOUND])
  1771. {
  1772. dwReturn = LoadParserOutput(pParser,dwCount-dwCurrentIndex,&dwUsed,ppwcArguments[dwCount],INDEX_ACTOUTBOUND,TYPE_BOUND);
  1773. bArg[ARG_ACTOUTBOUND] = TRUE;
  1774. }
  1775. else
  1776. {
  1777. dwReturn = ERR_TAG_ALREADY_PRESENT;
  1778. }
  1779. break;
  1780. case ARG_RESOLVEDNS :
  1781. if (!bArg[ARG_RESOLVEDNS])
  1782. {
  1783. dwReturn = LoadParserOutput(pParser,dwCount-dwCurrentIndex,&dwUsed,ppwcArguments[dwCount],INDEX_RESOLVEDNS,TYPE_BOOL);
  1784. bArg[ARG_RESOLVEDNS] = TRUE;
  1785. }
  1786. else
  1787. {
  1788. dwReturn = ERR_TAG_ALREADY_PRESENT;
  1789. }
  1790. break;
  1791. default :
  1792. dwReturn = ERROR_INVALID_SYNTAX;
  1793. break;
  1794. }
  1795. }
  1796. }
  1797. if(dwReturn == ERR_TAG_ALREADY_PRESENT)
  1798. {
  1799. PrintErrorMessage(IPSEC_ERR,0,ERRCODE_TAG_ALREADY_PRESENT,pParser->ValidTok[dwIndex].pwszToken);
  1800. dwReturn = RETURN_NO_ERROR;
  1801. }
  1802. else if ( (dwReturn == ERROR_SUCCESS) && (!bArg[ARG_NAME]) )
  1803. {
  1804. dwReturn = RETURN_NO_ERROR;
  1805. PrintErrorMessage(IPSEC_ERR,0,ERRCODE_TAG_NEEDED,ERRMSG_NAMEALL);
  1806. }
  1807. error:
  1808. return dwReturn;
  1809. }
  1810. //////////////////////////////////////////////////////////////////////////////////////////
  1811. //
  1812. // Function : ParseDynamicShowRule()
  1813. //
  1814. // Date of Creation : 29th aug 2001
  1815. //
  1816. // Parameters : IN LPWSTR *ppwcArguments, // Input stream
  1817. // IN OUT PPARSER_PKT pParser,
  1818. // IN DWORD dwCurrentIndex,
  1819. // IN DWORD dwMaxArgs
  1820. //
  1821. //
  1822. // Return : DWORD
  1823. //
  1824. // Description : Validates the arguments to the context DynamicShowRule
  1825. //
  1826. // History :
  1827. //
  1828. // Date Author Comments
  1829. //
  1830. //////////////////////////////////////////////////////////////////////////////////////////
  1831. DWORD
  1832. ParseDynamicShowRule(
  1833. IN LPWSTR *ppwcArguments,
  1834. IN OUT PPARSER_PKT pParser,
  1835. IN DWORD dwCurrentIndex,
  1836. IN DWORD dwMaxArgs
  1837. )
  1838. {
  1839. DWORD dwCount,dwNum = 0,dwTagIndex = 0,dwIndex = 0;
  1840. DWORD dwReturn = ERROR_SUCCESS,dwUsed = 0;
  1841. BOOL bTagPresent= FALSE;
  1842. BOOL bArg[MAX_ARGS];
  1843. _TCHAR szCmd[MAX_STR_LEN] = {0};
  1844. _TCHAR szTok[MAX_STR_LEN] = {0};
  1845. _TCHAR szTemp[MAX_STR_LEN] = {0};
  1846. const DWORD ARG_FILTERTYPE = 0;
  1847. const DWORD ARG_SRCADDR = 1;
  1848. const DWORD ARG_DSTADDR = 2;
  1849. const DWORD ARG_SRCMASK = 3;
  1850. const DWORD ARG_DSTMASK = 4;
  1851. const DWORD ARG_PROTO = 5;
  1852. const DWORD ARG_SRCPORT = 6;
  1853. const DWORD ARG_DSTPORT = 7;
  1854. const DWORD ARG_ACTINBOUND = 8;
  1855. const DWORD ARG_ACTOUTBOUND = 9;
  1856. const DWORD ARG_RESOLVEDNS = 10;
  1857. const DWORD INDEX_FILTERTYPE = 0;
  1858. const DWORD INDEX_SRCADDR = 1;
  1859. const DWORD INDEX_DSTADDR = 2;
  1860. const DWORD INDEX_SRCMASK = 3;
  1861. const DWORD INDEX_DSTMASK = 4;
  1862. const DWORD INDEX_PROTO = 5;
  1863. const DWORD INDEX_SRCPORT = 6;
  1864. const DWORD INDEX_DSTPORT = 7;
  1865. const DWORD INDEX_ACTINBOUND = 8;
  1866. const DWORD INDEX_ACTOUTBOUND = 9;
  1867. const DWORD INDEX_RESOLVEDNS = 10;
  1868. if ( (dwMaxArgs - dwCurrentIndex) >= 12 )
  1869. {
  1870. dwReturn = ERROR_INVALID_SYNTAX;
  1871. BAIL_OUT;
  1872. }
  1873. for(dwCount = 0;dwCount < MAX_ARGS;dwCount++)
  1874. {
  1875. bArg[dwCount] = FALSE;
  1876. }
  1877. for(dwCount = dwCurrentIndex;(dwCount < dwMaxArgs) && (dwReturn == ERROR_SUCCESS);dwCount++)
  1878. {
  1879. if (_tcslen(ppwcArguments[dwCount]) < MAX_STR_LEN)
  1880. {
  1881. _tcsncpy(szTemp,ppwcArguments[dwCount],MAX_STR_LEN-1); // temp contains arg
  1882. }
  1883. else
  1884. {
  1885. continue;
  1886. }
  1887. bTagPresent = SplitCmdTok(szTemp,szCmd,szTok,MAX_STR_LEN-1,MAX_STR_LEN-1);
  1888. // Check for =
  1889. if (bTagPresent) // Parameter With Tag Found
  1890. {
  1891. dwNum = 0;
  1892. MatchEnumTag(g_hModule,szCmd,pParser->MaxTok,pParser->ValidTok,&dwNum);
  1893. if (dwNum) // Convert the output of MatchEnumTag into the TagIndex
  1894. {
  1895. dwIndex = MatchEnumTagToTagIndex(szCmd,pParser);
  1896. if(dwIndex == PARSE_ERROR)
  1897. {
  1898. dwReturn = ERROR_SHOW_USAGE;
  1899. BAIL_OUT;
  1900. }
  1901. switch(pParser->ValidTok[dwIndex].dwValue)
  1902. {
  1903. case CMD_TOKEN_TYPE :
  1904. if (!bArg[ARG_FILTERTYPE])
  1905. {
  1906. dwReturn = LoadParserOutput(pParser,dwCount-dwCurrentIndex,&dwUsed,szTok,dwIndex,TYPE_MODE);
  1907. bArg[ARG_FILTERTYPE] = TRUE;
  1908. }
  1909. else
  1910. {
  1911. dwReturn = ERR_TAG_ALREADY_PRESENT;
  1912. }
  1913. break;
  1914. case CMD_TOKEN_SRCADDR :
  1915. if (!bArg[ARG_SRCADDR])
  1916. {
  1917. dwReturn = LoadParserOutput(pParser,dwCount-dwCurrentIndex,&dwUsed,szTok,dwIndex,TYPE_IP);
  1918. bArg[ARG_SRCADDR] = TRUE;
  1919. }
  1920. else
  1921. {
  1922. dwReturn = ERR_TAG_ALREADY_PRESENT;
  1923. }
  1924. break;
  1925. case CMD_TOKEN_DSTADDR :
  1926. if (!bArg[ARG_DSTADDR])
  1927. {
  1928. dwReturn = LoadParserOutput(pParser,dwCount-dwCurrentIndex,&dwUsed,szTok,dwIndex,TYPE_IP);
  1929. bArg[ARG_DSTADDR] = TRUE;
  1930. }
  1931. else
  1932. {
  1933. dwReturn = ERR_TAG_ALREADY_PRESENT;
  1934. }
  1935. break;
  1936. case CMD_TOKEN_SRCMASK :
  1937. if (!bArg[ARG_SRCMASK])
  1938. {
  1939. dwReturn = LoadParserOutput(pParser,dwCount-dwCurrentIndex,&dwUsed,szTok,dwIndex,TYPE_MASK);
  1940. bArg[ARG_SRCMASK] = TRUE;
  1941. }
  1942. else
  1943. {
  1944. dwReturn = ERR_TAG_ALREADY_PRESENT;
  1945. }
  1946. break;
  1947. case CMD_TOKEN_DSTMASK :
  1948. if (!bArg[ARG_SRCMASK])
  1949. {
  1950. dwReturn = LoadParserOutput(pParser,dwCount-dwCurrentIndex,&dwUsed,szTok,dwIndex,TYPE_MASK);
  1951. bArg[ARG_DSTMASK] = TRUE;
  1952. }
  1953. else
  1954. {
  1955. dwReturn = ERR_TAG_ALREADY_PRESENT;
  1956. }
  1957. break;
  1958. case CMD_TOKEN_PROTO :
  1959. if (!bArg[ARG_PROTO])
  1960. {
  1961. dwReturn = LoadParserOutput(pParser,dwCount-dwCurrentIndex,&dwUsed,szTok,dwIndex,TYPE_PROTOCOL);
  1962. bArg[ARG_PROTO] = TRUE;
  1963. }
  1964. else
  1965. {
  1966. dwReturn = ERR_TAG_ALREADY_PRESENT;
  1967. }
  1968. break;
  1969. case CMD_TOKEN_SRCPORT :
  1970. if (!bArg[ARG_SRCPORT])
  1971. {
  1972. dwReturn = LoadParserOutput(pParser,dwCount-dwCurrentIndex,&dwUsed,szTok,dwIndex,TYPE_PORT);
  1973. bArg[ARG_SRCPORT] = TRUE;
  1974. }
  1975. else
  1976. {
  1977. dwReturn = ERR_TAG_ALREADY_PRESENT;
  1978. }
  1979. break;
  1980. case CMD_TOKEN_DSTPORT :
  1981. if (!bArg[ARG_DSTPORT])
  1982. {
  1983. dwReturn = LoadParserOutput(pParser,dwCount-dwCurrentIndex,&dwUsed,szTok,dwIndex,TYPE_PORT);
  1984. bArg[ARG_DSTPORT] = TRUE;
  1985. }
  1986. else
  1987. {
  1988. dwReturn = ERR_TAG_ALREADY_PRESENT;
  1989. }
  1990. break;
  1991. case CMD_TOKEN_INBOUND :
  1992. if (!bArg[ARG_ACTINBOUND])
  1993. {
  1994. dwReturn = LoadParserOutput(pParser,dwCount-dwCurrentIndex,&dwUsed,szTok,dwIndex,TYPE_BOUND);
  1995. bArg[ARG_ACTINBOUND] = TRUE;
  1996. }
  1997. else
  1998. {
  1999. dwReturn = ERR_TAG_ALREADY_PRESENT;
  2000. }
  2001. break;
  2002. case CMD_TOKEN_OUTBOUND :
  2003. if (!bArg[ARG_ACTOUTBOUND])
  2004. {
  2005. dwReturn = LoadParserOutput(pParser,dwCount-dwCurrentIndex,&dwUsed,szTok,dwIndex,TYPE_BOUND);
  2006. bArg[ARG_ACTOUTBOUND] = TRUE;
  2007. }
  2008. else
  2009. {
  2010. dwReturn = ERR_TAG_ALREADY_PRESENT;
  2011. }
  2012. break;
  2013. case CMD_TOKEN_RESDNS :
  2014. if (!bArg[ARG_RESOLVEDNS])
  2015. {
  2016. dwReturn = LoadParserOutput(pParser,dwCount-dwCurrentIndex,&dwUsed,szTok,dwIndex,TYPE_BOOL);
  2017. bArg[ARG_RESOLVEDNS] = TRUE;
  2018. }
  2019. else
  2020. {
  2021. dwReturn = ERR_TAG_ALREADY_PRESENT;
  2022. }
  2023. break;
  2024. default :
  2025. dwReturn = ERROR_INVALID_SYNTAX;
  2026. break;
  2027. }
  2028. }
  2029. else
  2030. {
  2031. PrintErrorMessage(IPSEC_ERR,0,ERRCODE_INVALID_TAG,szCmd);
  2032. dwReturn = RETURN_NO_ERROR;
  2033. }
  2034. }
  2035. else // Parameter Without a Tag Found
  2036. { // Find the first free slot to position the untagged arg
  2037. for(dwTagIndex=0;
  2038. dwTagIndex<pParser->MaxTok && (bArg[dwTagIndex] == TRUE) ;
  2039. dwTagIndex++);
  2040. switch (dwTagIndex)
  2041. {
  2042. case ARG_FILTERTYPE :
  2043. if (!bArg[ARG_FILTERTYPE])
  2044. {
  2045. dwReturn = LoadParserOutput(pParser,dwCount-dwCurrentIndex,&dwUsed,ppwcArguments[dwCount],INDEX_FILTERTYPE,TYPE_MODE);
  2046. bArg[ARG_FILTERTYPE] = TRUE;
  2047. }
  2048. else
  2049. {
  2050. dwReturn = ERR_TAG_ALREADY_PRESENT;
  2051. }
  2052. break;
  2053. case ARG_SRCADDR :
  2054. if (!bArg[ARG_SRCADDR])
  2055. {
  2056. dwReturn = LoadParserOutput(pParser,dwCount-dwCurrentIndex,&dwUsed,ppwcArguments[dwCount],INDEX_SRCADDR,TYPE_IP);
  2057. bArg[ARG_SRCADDR] = TRUE;
  2058. }
  2059. else
  2060. {
  2061. dwReturn = ERR_TAG_ALREADY_PRESENT;
  2062. }
  2063. break;
  2064. case ARG_DSTADDR :
  2065. if (!bArg[ARG_DSTADDR])
  2066. {
  2067. dwReturn = LoadParserOutput(pParser,dwCount-dwCurrentIndex,&dwUsed,ppwcArguments[dwCount],INDEX_DSTADDR,TYPE_IP);
  2068. bArg[ARG_DSTADDR] = TRUE;
  2069. }
  2070. else
  2071. {
  2072. dwReturn = ERR_TAG_ALREADY_PRESENT;
  2073. }
  2074. break;
  2075. case ARG_SRCMASK :
  2076. if (!bArg[ARG_SRCMASK])
  2077. {
  2078. dwReturn = LoadParserOutput(pParser,dwCount-dwCurrentIndex,&dwUsed,ppwcArguments[dwCount],INDEX_SRCMASK,TYPE_MASK);
  2079. bArg[ARG_SRCMASK] = TRUE;
  2080. }
  2081. else
  2082. {
  2083. dwReturn = ERR_TAG_ALREADY_PRESENT;
  2084. }
  2085. break;
  2086. case ARG_DSTMASK :
  2087. if (!bArg[ARG_DSTMASK])
  2088. {
  2089. dwReturn = LoadParserOutput(pParser,dwCount-dwCurrentIndex,&dwUsed,ppwcArguments[dwCount],INDEX_DSTMASK,TYPE_MASK);
  2090. bArg[ARG_DSTMASK] = TRUE;
  2091. }
  2092. else
  2093. {
  2094. dwReturn = ERR_TAG_ALREADY_PRESENT;
  2095. }
  2096. break;
  2097. case ARG_PROTO :
  2098. if (!bArg[ARG_PROTO])
  2099. {
  2100. dwReturn = LoadParserOutput(pParser,dwCount-dwCurrentIndex,&dwUsed,ppwcArguments[dwCount],INDEX_PROTO,TYPE_PROTOCOL);
  2101. bArg[ARG_PROTO] = TRUE;
  2102. }
  2103. else
  2104. {
  2105. dwReturn = ERR_TAG_ALREADY_PRESENT;
  2106. }
  2107. break;
  2108. case ARG_SRCPORT :
  2109. if (!bArg[ARG_SRCPORT])
  2110. {
  2111. dwReturn = LoadParserOutput(pParser,dwCount-dwCurrentIndex,&dwUsed,ppwcArguments[dwCount],INDEX_SRCPORT,TYPE_PORT);
  2112. bArg[ARG_SRCPORT] = TRUE;
  2113. }
  2114. else
  2115. {
  2116. dwReturn = ERR_TAG_ALREADY_PRESENT;
  2117. }
  2118. break;
  2119. case ARG_DSTPORT :
  2120. if (!bArg[ARG_DSTPORT])
  2121. {
  2122. dwReturn = LoadParserOutput(pParser,dwCount-dwCurrentIndex,&dwUsed,ppwcArguments[dwCount],INDEX_DSTPORT,TYPE_PORT);
  2123. bArg[ARG_DSTPORT] = TRUE;
  2124. }
  2125. else
  2126. {
  2127. dwReturn = ERR_TAG_ALREADY_PRESENT;
  2128. }
  2129. break;
  2130. case ARG_ACTINBOUND :
  2131. if (!bArg[ARG_ACTINBOUND])
  2132. {
  2133. dwReturn = LoadParserOutput(pParser,dwCount-dwCurrentIndex,&dwUsed,ppwcArguments[dwCount],INDEX_ACTINBOUND,TYPE_BOUND);
  2134. bArg[ARG_ACTINBOUND] = TRUE;
  2135. }
  2136. else
  2137. {
  2138. dwReturn = ERR_TAG_ALREADY_PRESENT;
  2139. }
  2140. break;
  2141. case ARG_ACTOUTBOUND :
  2142. if (!bArg[ARG_ACTOUTBOUND])
  2143. {
  2144. dwReturn = LoadParserOutput(pParser,dwCount-dwCurrentIndex,&dwUsed,ppwcArguments[dwCount],INDEX_ACTOUTBOUND,TYPE_BOUND);
  2145. bArg[ARG_ACTOUTBOUND] = TRUE;
  2146. }
  2147. else
  2148. {
  2149. dwReturn = ERR_TAG_ALREADY_PRESENT;
  2150. }
  2151. break;
  2152. case ARG_RESOLVEDNS :
  2153. if (!bArg[ARG_RESOLVEDNS])
  2154. {
  2155. dwReturn = LoadParserOutput(pParser,dwCount-dwCurrentIndex,&dwUsed,ppwcArguments[dwCount],INDEX_RESOLVEDNS,TYPE_BOOL);
  2156. bArg[ARG_RESOLVEDNS] = TRUE;
  2157. }
  2158. else
  2159. {
  2160. dwReturn = ERR_TAG_ALREADY_PRESENT;
  2161. }
  2162. break;
  2163. default :
  2164. dwReturn = ERROR_INVALID_SYNTAX;
  2165. break;
  2166. }
  2167. }
  2168. }
  2169. if(dwReturn == ERR_TAG_ALREADY_PRESENT)
  2170. {
  2171. PrintErrorMessage(IPSEC_ERR,0,ERRCODE_TAG_ALREADY_PRESENT,pParser->ValidTok[dwIndex].pwszToken);
  2172. dwReturn = RETURN_NO_ERROR;
  2173. }
  2174. error:
  2175. return dwReturn;
  2176. }
  2177. //////////////////////////////////////////////////////////////////////////////////////////
  2178. // Function : ParseDynamicShowStats()
  2179. //
  2180. // Date of Creation : 29th aug 2001
  2181. //
  2182. // Parameters : IN LPTSTR lppwszTok[MAX_ARGS],
  2183. // IN OUT PPARSER_PKT pParser,
  2184. // IN DWORD dwCurrentIndex,
  2185. // IN DWORD dwMaxArgs,
  2186. // IN DWORD dwTagType[MAX_ARGS]
  2187. //
  2188. // Return : DWORD
  2189. //
  2190. // Description : Validates the arguments to the context DynamicShowStats
  2191. //
  2192. // History :
  2193. //
  2194. // Date Author Comments
  2195. //
  2196. //////////////////////////////////////////////////////////////////////////////////////////
  2197. DWORD
  2198. ParseDynamicShowStats(
  2199. IN LPTSTR lppwszTok[MAX_ARGS],
  2200. IN OUT PPARSER_PKT pParser,
  2201. IN DWORD dwCurrentIndex,
  2202. IN DWORD dwMaxArgs,
  2203. IN DWORD dwTagType[MAX_ARGS]
  2204. )
  2205. {
  2206. DWORD dwReturn = ERROR_SUCCESS,dwCount,dwUsed = 0;
  2207. for(dwCount = 0;(dwCount < dwMaxArgs) && (dwReturn == ERROR_SUCCESS);dwCount++)
  2208. {
  2209. switch(pParser->ValidTok[dwTagType[dwCount]].dwValue)
  2210. {
  2211. case CMD_TOKEN_TYPE :
  2212. dwReturn = LoadParserOutput(pParser,dwCount,&dwUsed,lppwszTok[dwCount],dwTagType[dwCount],TYPE_STATS);
  2213. break;
  2214. default :
  2215. dwReturn = ERROR_INVALID_SYNTAX;
  2216. break;
  2217. }
  2218. }
  2219. return dwReturn;
  2220. }
  2221. //////////////////////////////////////////////////////////////////////////////////////////
  2222. //
  2223. // Function : ParseDynamicShowMMSAS()
  2224. //
  2225. // Date of Creation : 29th aug 2001
  2226. //
  2227. // Parameters : IN LPTSTR lppwszTok[MAX_ARGS],
  2228. // IN OUT PPARSER_PKT pParser,
  2229. // IN DWORD dwCurrentIndex,
  2230. // IN DWORD dwMaxArgs,
  2231. // IN DWORD dwTagType[MAX_ARGS]
  2232. //
  2233. // Return : DWORD
  2234. //
  2235. // Description : Validates the arguments to the context DynamicShowMMSAS
  2236. //
  2237. // History :
  2238. //
  2239. // Date Author Comments
  2240. //
  2241. //////////////////////////////////////////////////////////////////////////////////////////
  2242. DWORD
  2243. ParseDynamicShowMMSAS(
  2244. IN LPTSTR lppwszTok[MAX_ARGS],
  2245. IN OUT PPARSER_PKT pParser,
  2246. IN DWORD dwCurrentIndex,
  2247. IN DWORD dwMaxArgs,
  2248. IN DWORD dwTagType[MAX_ARGS]
  2249. )
  2250. {
  2251. DWORD dwReturn = ERROR_SUCCESS,dwCount,dwUsed = 0/*,dwNum = 0*/;
  2252. for(dwCount = 0;(dwCount < dwMaxArgs) && (dwReturn == ERROR_SUCCESS);dwCount++)
  2253. {
  2254. switch(pParser->ValidTok[dwTagType[dwCount]].dwValue)
  2255. {
  2256. case CMD_TOKEN_ALL :
  2257. break;
  2258. case CMD_TOKEN_SRCADDR :
  2259. case CMD_TOKEN_DSTADDR :
  2260. dwReturn = LoadParserOutput(pParser,dwCount,&dwUsed,lppwszTok[dwCount],dwTagType[dwCount],TYPE_IP);
  2261. break;
  2262. case CMD_TOKEN_FORMAT :
  2263. dwReturn = LoadParserOutput(pParser,dwCount,&dwUsed,lppwszTok[dwCount],dwTagType[dwCount],TYPE_FORMAT);
  2264. break;
  2265. case CMD_TOKEN_RESDNS :
  2266. dwReturn = LoadParserOutput(pParser,dwCount,&dwUsed,lppwszTok[dwCount],dwTagType[dwCount],TYPE_BOOL);
  2267. break;
  2268. default :
  2269. dwReturn = ERROR_INVALID_SYNTAX;
  2270. break;
  2271. }
  2272. }
  2273. return dwReturn;
  2274. }
  2275. //////////////////////////////////////////////////////////////////////////////
  2276. //
  2277. // Function : ParseDynamicShowAll()
  2278. //
  2279. // Date of Creation : 31st Jan 2002
  2280. //
  2281. // Parameters : IN LPTSTR lppwszTok[MAX_ARGS],
  2282. // IN OUT PPARSER_PKT pParser,
  2283. // IN DWORD dwCurrentIndex,
  2284. // IN DWORD dwMaxArgs,
  2285. // IN DWORD dwTagType[MAX_ARGS]
  2286. //
  2287. // Return : DWORD
  2288. //
  2289. // Description : It will check the valid Arguments for the ParseDynamicShowAll context.
  2290. // It loads all valid argument into pParser structure with status for each argument.
  2291. //
  2292. // History :
  2293. //
  2294. // Date Author Comments
  2295. //
  2296. //////////////////////////////////////////////////////////////////////////////
  2297. DWORD ParseDynamicShowAll(
  2298. IN LPTSTR lppwszTok[MAX_ARGS],
  2299. IN OUT PPARSER_PKT pParser,
  2300. IN DWORD dwCurrentIndex,
  2301. IN DWORD dwMaxArgs,
  2302. IN DWORD dwTagType[MAX_ARGS]
  2303. )
  2304. {
  2305. DWORD dwReturn = ERROR_SUCCESS,dwCount,dwUsed=0;
  2306. for(dwCount = 0;(dwCount < dwMaxArgs) && (dwReturn == ERROR_SUCCESS);dwCount++)
  2307. {
  2308. switch(pParser->ValidTok[dwTagType[dwCount]].dwValue)
  2309. {
  2310. case CMD_TOKEN_RESDNS :
  2311. dwReturn = LoadParserOutput(pParser,dwCount,&dwUsed,lppwszTok[dwCount],dwTagType[dwCount],TYPE_BOOL);
  2312. break;
  2313. default :
  2314. dwReturn = ERROR_SHOW_USAGE;
  2315. break;
  2316. }
  2317. }
  2318. return dwReturn;
  2319. }