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.

888 lines
22 KiB

  1. //////////////////////////////////////////////////////////////////
  2. //Module: Static/Staticmisc.cpp
  3. //
  4. // Purpose: Static Module Implementation. This module implements
  5. // miscellaneous commands of Static mode.
  6. //
  7. // Developers Name: Surya
  8. //
  9. // Revision History:
  10. //
  11. // Date Author Comments
  12. // 10-8-2001 Bharat Initial Version. SCM Base line 1.0
  13. // 21-8-2001 Surya Implemented misc functions.
  14. //
  15. //////////////////////////////////////////////////////////////////
  16. #include "nshipsec.h"
  17. //
  18. //External Variables declaration
  19. //
  20. extern HINSTANCE g_hModule;
  21. extern STORAGELOCATION g_StorageLocation;
  22. extern CNshPolStore g_NshPolStoreHandle;
  23. extern CNshPolNegFilData g_NshPolNegFilData;
  24. //////////////////////////////////////////////////////////////////
  25. //
  26. //Function: HandleStaticImportPolicy()
  27. //
  28. //Date of Creation: 21st Aug 2001
  29. //
  30. //Parameters:
  31. // IN LPCWSTR pwszMachine,
  32. // IN OUT LPWSTR *ppwcArguments,
  33. // IN DWORD dwCurrentIndex,
  34. // IN DWORD dwArgCount,
  35. // IN DWORD dwFlags,
  36. // IN LPCVOID pvData,
  37. // OUT BOOL *pbDone
  38. //
  39. //Return: DWORD
  40. //
  41. //Description:
  42. // Implementation for the command " Import Policy "
  43. //
  44. // Revision History:
  45. //
  46. // Date Author Comments
  47. //
  48. //////////////////////////////////////////////////////////////////
  49. DWORD
  50. HandleStaticImportPolicy(
  51. IN LPCWSTR pwszMachine,
  52. IN OUT LPWSTR *ppwcArguments,
  53. IN DWORD dwCurrentIndex,
  54. IN DWORD dwArgCount,
  55. IN DWORD dwFlags,
  56. IN LPCVOID pvData,
  57. OUT BOOL *pbDone
  58. )
  59. {
  60. LPTSTR pszMachineName=NULL,pszFileName=NULL,pszEnhancedFileName=NULL;
  61. DWORD dwFileLocation=IPSEC_FILE_PROVIDER;
  62. DWORD dwRet = ERROR_SHOW_USAGE,dwCount=0;
  63. HANDLE hhPolicyStorage=NULL, hFileStore=NULL;
  64. DWORD dwReturnCode = ERROR_SUCCESS , dwStrLength = 0, dwLocation;
  65. const TAG_TYPE vcmdStaticImportPolicy[] =
  66. {
  67. { CMD_TOKEN_STR_FILE, NS_REQ_PRESENT, FALSE }
  68. };
  69. const TOKEN_VALUE vtokStaticImportPolicy[] =
  70. {
  71. { CMD_TOKEN_STR_FILE, CMD_TOKEN_FILE }
  72. };
  73. PARSER_PKT parser;
  74. ZeroMemory(&parser, sizeof(parser));
  75. //if the user asked for usage, delegate the responsibility to netsh
  76. if(dwArgCount <= 2)
  77. {
  78. dwRet = ERROR_SHOW_USAGE;
  79. BAIL_OUT;
  80. }
  81. parser.ValidTok = vtokStaticImportPolicy;
  82. parser.MaxTok = SIZEOF_TOKEN_VALUE(vtokStaticImportPolicy);
  83. parser.ValidCmd = vcmdStaticImportPolicy;
  84. parser.MaxCmd = SIZEOF_TAG_TYPE(vcmdStaticImportPolicy);
  85. dwRet = Parser(pwszMachine,ppwcArguments,dwCurrentIndex,dwArgCount,&parser);
  86. if(dwRet != ERROR_SUCCESS)
  87. {
  88. CleanUp();
  89. if (dwRet==RETURN_NO_ERROR)
  90. {
  91. dwRet = ERROR_SUCCESS;
  92. }
  93. BAIL_OUT;
  94. }
  95. // get the parsed user input
  96. for(dwCount=0;dwCount<parser.MaxTok;dwCount++)
  97. {
  98. switch(vtokStaticImportPolicy[parser.Cmd[dwCount].dwCmdToken].dwValue)
  99. {
  100. case CMD_TOKEN_FILE :
  101. if (parser.Cmd[dwCount].dwStatus == VALID_TOKEN && parser.Cmd[dwCount].pArg)
  102. {
  103. dwStrLength = _tcslen((LPTSTR)parser.Cmd[dwCount].pArg);
  104. pszFileName= new _TCHAR[dwStrLength+1];
  105. if(pszFileName==NULL)
  106. {
  107. PrintErrorMessage(WIN32_ERR,ERROR_OUTOFMEMORY,NULL);
  108. dwRet=ERROR_SUCCESS;
  109. BAIL_OUT;
  110. }
  111. _tcsncpy(pszFileName,(LPTSTR)parser.Cmd[dwCount].pArg,dwStrLength+1);
  112. }
  113. break;
  114. default :
  115. break;
  116. }
  117. }
  118. CleanUp();
  119. // if no file name, bail out
  120. if(!pszFileName)
  121. {
  122. PrintErrorMessage(IPSEC_ERR,0,ERRCODE_MISC_STATIC_IMPORTPOLICY_1);
  123. BAIL_OUT;
  124. }
  125. dwReturnCode = CopyStorageInfo(&pszMachineName,dwLocation);
  126. if(dwReturnCode == ERROR_OUTOFMEMORY)
  127. {
  128. PrintErrorMessage(WIN32_ERR,ERROR_OUTOFMEMORY,NULL);
  129. dwRet=ERROR_SUCCESS;
  130. BAIL_OUT;
  131. }
  132. // open pol store in normal way
  133. dwReturnCode = OpenPolicyStore(&hhPolicyStorage);
  134. if (dwReturnCode != ERROR_SUCCESS)
  135. {
  136. PrintErrorMessage(IPSEC_ERR,0,ERRCODE_FAILED_POLSTORE_OPEN);
  137. dwRet=ERROR_SUCCESS;
  138. BAIL_OUT;
  139. }
  140. // open pol store with file name
  141. dwReturnCode = IPSecOpenPolicyStore(pszMachineName, dwFileLocation, pszFileName, &hFileStore);
  142. if (dwReturnCode != ERROR_SUCCESS)
  143. {
  144. PrintErrorMessage(IPSEC_ERR,0,ERRCODE_FAILED_POLSTORE_OPEN);
  145. dwRet=ERROR_SUCCESS;
  146. BAIL_OUT;
  147. }
  148. // call the API
  149. dwReturnCode = IPSecImportPolicies(hFileStore , hhPolicyStorage );
  150. if (dwReturnCode != ERROR_SUCCESS)
  151. {
  152. if(hFileStore)
  153. {
  154. IPSecClosePolicyStore(hFileStore);
  155. hFileStore=NULL;
  156. }
  157. // if no .ipsec extension, append it and again try
  158. dwStrLength = _tcslen(pszFileName)+_tcslen(IPSEC_FILE_EXTENSION);
  159. pszEnhancedFileName=new _TCHAR[dwStrLength+1];
  160. if(pszEnhancedFileName==NULL)
  161. {
  162. PrintErrorMessage(WIN32_ERR,ERROR_OUTOFMEMORY,NULL);
  163. dwRet=ERROR_SUCCESS;
  164. BAIL_OUT;
  165. }
  166. _tcsncpy(pszEnhancedFileName,pszFileName,_tcslen(pszFileName)+1); //allocation and error checking done above
  167. _tcsncat(pszEnhancedFileName,IPSEC_FILE_EXTENSION,_tcslen(IPSEC_FILE_EXTENSION) + 1); //allocation and error checking done above
  168. dwReturnCode = IPSecOpenPolicyStore(pszMachineName, dwFileLocation, pszEnhancedFileName, &hFileStore);
  169. if (dwReturnCode != ERROR_SUCCESS)
  170. {
  171. PrintErrorMessage(IPSEC_ERR,0,ERRCODE_FAILED_POLSTORE_OPEN);
  172. dwRet=ERROR_SUCCESS;
  173. BAIL_OUT;
  174. }
  175. dwReturnCode = IPSecImportPolicies(hFileStore , hhPolicyStorage );
  176. if (dwReturnCode == ERROR_FILE_NOT_FOUND || dwReturnCode == ERROR_PATH_NOT_FOUND)
  177. {
  178. PrintErrorMessage(IPSEC_ERR,0,ERRCODE_MISC_STATIC_IMPORTPOLICY_3);
  179. }
  180. else if (dwReturnCode != ERROR_SUCCESS)
  181. {
  182. PrintErrorMessage(IPSEC_ERR,0,ERRCODE_MISC_STATIC_IMPORTPOLICY_4);
  183. }
  184. if(pszEnhancedFileName)
  185. {
  186. delete []pszEnhancedFileName;
  187. }
  188. }
  189. if(hFileStore)
  190. {
  191. IPSecClosePolicyStore(hFileStore);
  192. }
  193. dwRet=ERROR_SUCCESS;
  194. if(hhPolicyStorage)
  195. {
  196. ClosePolicyStore(hhPolicyStorage);
  197. }
  198. if(pszFileName) delete []pszFileName;
  199. error:
  200. if (pszMachineName) delete []pszMachineName;
  201. return dwRet;
  202. }
  203. //////////////////////////////////////////////////////////////////
  204. //
  205. //Function: HandleStaticExportPolicy()
  206. //
  207. //Date of Creation: 21st Aug 2001
  208. //
  209. //Parameters:
  210. // IN LPCWSTR pwszMachine,
  211. // IN OUT LPWSTR *ppwcArguments,
  212. // IN DWORD dwCurrentIndex,
  213. // IN DWORD dwArgCount,
  214. // IN DWORD dwFlags,
  215. // IN LPCVOID pvData,
  216. // OUT BOOL *pbDone
  217. //
  218. //Return: DWORD
  219. //
  220. //Description:
  221. // Implementation for the command " Export Policy "
  222. //
  223. //Revision History:
  224. //
  225. // Date Author Comments
  226. //
  227. //////////////////////////////////////////////////////////////////
  228. DWORD
  229. HandleStaticExportPolicy(
  230. IN LPCWSTR pwszMachine,
  231. IN OUT LPWSTR *ppwcArguments,
  232. IN DWORD dwCurrentIndex,
  233. IN DWORD dwArgCount,
  234. IN DWORD dwFlags,
  235. IN LPCVOID pvData,
  236. OUT BOOL *pbDone
  237. )
  238. {
  239. LPTSTR pszMachineName=NULL,pszFileName=NULL;
  240. DWORD FileLocation=IPSEC_FILE_PROVIDER;
  241. DWORD dwRet = ERROR_SHOW_USAGE,dwCount=0;
  242. HANDLE hPolicyStorage=NULL, hFileStore=NULL;
  243. DWORD dwReturnCode = ERROR_SUCCESS, dwStrLength = 0, dwLocation;
  244. const TAG_TYPE vcmdStaticExportPolicy[] =
  245. {
  246. { CMD_TOKEN_STR_FILE, NS_REQ_PRESENT, FALSE }
  247. };
  248. const TOKEN_VALUE vtokStaticExportPolicy[] =
  249. {
  250. { CMD_TOKEN_STR_FILE, CMD_TOKEN_FILE }
  251. };
  252. PARSER_PKT parser;
  253. ZeroMemory(&parser, sizeof(parser));
  254. //if the user asked for usage, delegate the responsibility to netsh
  255. if(dwArgCount <= 2)
  256. {
  257. dwRet = ERROR_SHOW_USAGE;
  258. BAIL_OUT;
  259. }
  260. parser.ValidTok = vtokStaticExportPolicy;
  261. parser.MaxTok = SIZEOF_TOKEN_VALUE(vtokStaticExportPolicy);
  262. parser.ValidCmd = vcmdStaticExportPolicy;
  263. parser.MaxCmd = SIZEOF_TAG_TYPE(vcmdStaticExportPolicy);
  264. dwRet = Parser(pwszMachine,ppwcArguments,dwCurrentIndex,dwArgCount,&parser);
  265. if(dwRet != ERROR_SUCCESS)
  266. {
  267. CleanUp();
  268. if (dwRet==RETURN_NO_ERROR)
  269. {
  270. dwRet = ERROR_SUCCESS;
  271. }
  272. BAIL_OUT;
  273. }
  274. // get the parsed user input
  275. for(dwCount=0;dwCount<parser.MaxTok;dwCount++)
  276. {
  277. switch(vtokStaticExportPolicy[parser.Cmd[dwCount].dwCmdToken].dwValue)
  278. {
  279. case CMD_TOKEN_FILE :
  280. if (parser.Cmd[dwCount].dwStatus == VALID_TOKEN)
  281. {
  282. dwStrLength = _tcslen((LPTSTR)parser.Cmd[dwCount].pArg);
  283. pszFileName= new _TCHAR[dwStrLength+1];
  284. if(pszFileName==NULL)
  285. {
  286. PrintErrorMessage(WIN32_ERR,ERROR_OUTOFMEMORY,NULL);
  287. dwRet=ERROR_SUCCESS;
  288. BAIL_OUT;
  289. }
  290. _tcsncpy(pszFileName,(LPTSTR)parser.Cmd[dwCount].pArg,dwStrLength+1);
  291. }
  292. break;
  293. default :
  294. break;
  295. }
  296. }
  297. CleanUp();
  298. // if no filename bail out
  299. if(!pszFileName)
  300. {
  301. PrintErrorMessage(IPSEC_ERR,0,ERRCODE_MISC_STATIC_IMPORTPOLICY_1);
  302. BAIL_OUT;
  303. }
  304. dwReturnCode = CopyStorageInfo(&pszMachineName,dwLocation);
  305. if(dwReturnCode == ERROR_OUTOFMEMORY)
  306. {
  307. PrintErrorMessage(WIN32_ERR,ERROR_OUTOFMEMORY,NULL);
  308. dwRet=ERROR_SUCCESS;
  309. BAIL_OUT;
  310. }
  311. //open the polstore two times one time in normal way and another time with filename
  312. dwReturnCode = IPSecOpenPolicyStore(pszMachineName, FileLocation, pszFileName, &hFileStore);
  313. if (dwReturnCode != ERROR_SUCCESS)
  314. {
  315. PrintErrorMessage(IPSEC_ERR,0,ERRCODE_FAILED_POLSTORE_OPEN);
  316. dwRet=ERROR_SUCCESS;
  317. BAIL_OUT;
  318. }
  319. dwReturnCode = OpenPolicyStore(&hPolicyStorage);
  320. if (dwReturnCode != ERROR_SUCCESS)
  321. {
  322. PrintErrorMessage(IPSEC_ERR,0,ERRCODE_FAILED_POLSTORE_OPEN);
  323. dwRet=ERROR_SUCCESS;
  324. BAIL_OUT;
  325. }
  326. dwReturnCode = IPSecExportPolicies(hPolicyStorage , hFileStore );
  327. // if something failed, throw the error messages to the user
  328. if (dwReturnCode == ERROR_INVALID_NAME)
  329. {
  330. PrintErrorMessage(IPSEC_ERR,0,ERRCODE_MISC_STATIC_IMPORTPOLICY_3);
  331. }
  332. else if (dwReturnCode != ERROR_SUCCESS)
  333. {
  334. PrintErrorMessage(IPSEC_ERR,0,ERRCODE_MISC_STATIC_EXPORTPOLICY_2);
  335. }
  336. dwRet=dwReturnCode;
  337. ClosePolicyStore(hPolicyStorage);
  338. IPSecClosePolicyStore(hFileStore);
  339. if(pszFileName) delete []pszFileName;
  340. error:
  341. if (pszMachineName) delete []pszMachineName;
  342. return dwRet;
  343. }
  344. /////////////////////////////////////////////////////////////////////
  345. //
  346. //Function: HandleStaticSetStore()
  347. //
  348. //Date of Creation: 21st Aug 2001
  349. //
  350. //Parameters:
  351. // IN LPCWSTR pwszMachine,
  352. // IN OUT LPWSTR *ppwcArguments,
  353. // IN DWORD dwCurrentIndex,
  354. // IN DWORD dwArgCount,
  355. // IN DWORD dwFlags,
  356. // IN LPCVOID pvData,
  357. // OUT BOOL *pbDone
  358. //
  359. //Return: DWORD
  360. //
  361. //Description:
  362. // Implementation for the command " Set Store "
  363. //
  364. //Revision History:
  365. //
  366. // Date Author Comments
  367. //
  368. /////////////////////////////////////////////////////////////////////
  369. DWORD WINAPI
  370. HandleStaticSetStore(
  371. IN LPCWSTR pwszMachine,
  372. IN OUT LPWSTR *ppwcArguments,
  373. IN DWORD dwCurrentIndex,
  374. IN DWORD dwArgCount,
  375. IN DWORD dwFlags,
  376. IN LPCVOID pvData,
  377. OUT BOOL *pbDone
  378. )
  379. {
  380. DWORD dwRet = ERROR_SHOW_USAGE, dwCount = 0;
  381. LPTSTR pszDomainName=NULL;
  382. HANDLE hPolicyStorage=NULL;
  383. BOOL bLocationSpecified=FALSE, bDomainSpecified=FALSE;
  384. DWORD dwReturnCode = ERROR_SUCCESS ,dwStrLength = 0;
  385. PARSER_PKT parser;
  386. ZeroMemory(&parser, sizeof(parser));
  387. DWORD dwLocation;
  388. const TAG_TYPE vcmdStaticSetStore[] =
  389. {
  390. { CMD_TOKEN_STR_LOCATION, NS_REQ_PRESENT, FALSE },
  391. { CMD_TOKEN_STR_DS, NS_REQ_ZERO, FALSE }
  392. };
  393. const TOKEN_VALUE vtokStaticSetStore[] =
  394. {
  395. { CMD_TOKEN_STR_LOCATION, CMD_TOKEN_LOCATION },
  396. { CMD_TOKEN_STR_DS, CMD_TOKEN_DS }
  397. };
  398. //if the user asked for usage, delegate the responsibility to netsh
  399. if(dwArgCount <= 3)
  400. {
  401. dwRet = ERROR_SHOW_USAGE;
  402. BAIL_OUT;
  403. }
  404. parser.ValidTok = vtokStaticSetStore;
  405. parser.MaxTok = SIZEOF_TOKEN_VALUE(vtokStaticSetStore);
  406. parser.ValidCmd = vcmdStaticSetStore;
  407. parser.MaxCmd = SIZEOF_TAG_TYPE(vcmdStaticSetStore);
  408. dwRet = Parser(pwszMachine,ppwcArguments,dwCurrentIndex,dwArgCount,&parser);
  409. if(dwRet != ERROR_SUCCESS)
  410. {
  411. CleanUp();
  412. if (dwRet==RETURN_NO_ERROR)
  413. {
  414. dwRet = ERROR_SUCCESS;
  415. }
  416. BAIL_OUT;
  417. }
  418. // get the parsed user info,
  419. for(dwCount = 0;dwCount < parser.MaxTok;dwCount++)
  420. {
  421. switch(vtokStaticSetStore[parser.Cmd[dwCount].dwCmdToken].dwValue)
  422. {
  423. case CMD_TOKEN_LOCATION:
  424. if (parser.Cmd[dwCount].dwStatus == VALID_TOKEN)
  425. {
  426. if (parser.Cmd[dwCount].pArg )
  427. {
  428. dwLocation = *((DWORD*)parser.Cmd[dwCount].pArg);
  429. bLocationSpecified=TRUE;
  430. }
  431. }
  432. break;
  433. case CMD_TOKEN_DS :
  434. if (parser.Cmd[dwCount].dwStatus == VALID_TOKEN)
  435. {
  436. dwLocation = IPSEC_DIRECTORY_PROVIDER;
  437. if(parser.Cmd[dwCount].pArg )
  438. {
  439. dwStrLength = _tcslen((LPTSTR)parser.Cmd[dwCount].pArg);
  440. pszDomainName= new _TCHAR[dwStrLength+1];
  441. if(pszDomainName==NULL)
  442. {
  443. PrintErrorMessage(WIN32_ERR,ERROR_OUTOFMEMORY,NULL);
  444. dwRet=ERROR_SUCCESS;
  445. BAIL_OUT;
  446. }
  447. _tcsncpy(pszDomainName,(LPTSTR)parser.Cmd[dwCount].pArg,dwStrLength+1);
  448. }
  449. bLocationSpecified=TRUE;
  450. }
  451. break;
  452. default :
  453. break;
  454. }
  455. }
  456. CleanUp();
  457. if(bLocationSpecified)
  458. {
  459. switch (dwLocation)
  460. {
  461. case IPSEC_DIRECTORY_PROVIDER:
  462. dwRet = ConnectStaticMachine(
  463. pszDomainName,
  464. dwLocation);
  465. if (dwRet == ERROR_INVALID_PARAMETER || dwRet == ERROR_DS_SERVER_DOWN)
  466. {
  467. if (pszDomainName)
  468. {
  469. PrintErrorMessage(
  470. IPSEC_ERR,
  471. 0,
  472. ERRCODE_MISC_STATIC_SETSTORE_DOMAIN_NA,
  473. pszDomainName);
  474. }
  475. else
  476. {
  477. PrintErrorMessage(
  478. IPSEC_ERR,
  479. 0,
  480. ERRCODE_MISC_STATIC_SETSTORE_NOT_DOMAIN_MEMBER,
  481. pszDomainName);
  482. }
  483. }
  484. else if (dwRet != ERROR_SUCCESS)
  485. {
  486. PrintErrorMessage(WIN32_ERR, dwRet, NULL);
  487. }
  488. break;
  489. case IPSEC_REGISTRY_PROVIDER:
  490. case IPSEC_PERSISTENT_PROVIDER:
  491. dwRet = ConnectStaticMachine(
  492. g_StorageLocation.pszMachineName,
  493. dwLocation
  494. );
  495. if (dwRet != ERROR_SUCCESS)
  496. {
  497. PrintErrorMessage(WIN32_ERR, dwRet, NULL);
  498. }
  499. break;
  500. default:
  501. dwRet = ERRCODE_ARG_INVALID;
  502. BAIL_OUT;
  503. break;
  504. }
  505. }
  506. error:
  507. return dwRet;
  508. }
  509. /////////////////////////////////////////////////////////////////////
  510. //
  511. //Function: HandleStaticRestoreDefaults()
  512. //
  513. //Date of Creation: 21st Aug 2001
  514. //
  515. //Parameters:
  516. // IN LPCWSTR pwszMachine,
  517. // IN OUT LPWSTR *ppwcArguments,
  518. // IN DWORD dwCurrentIndex,
  519. // IN DWORD dwArgCount,
  520. // IN DWORD dwFlags,
  521. // IN LPCVOID pvData,
  522. // OUT BOOL *pbDone
  523. //
  524. //Return: DWORD
  525. //
  526. //Description:
  527. // Implementation for the command " Restore Defaults "
  528. //
  529. //Revision History:
  530. //
  531. // Date Author Comments
  532. //
  533. /////////////////////////////////////////////////////////////////////
  534. DWORD WINAPI
  535. HandleStaticRestoreDefaults(
  536. IN LPCWSTR pwszMachine,
  537. IN OUT LPWSTR *ppwcArguments,
  538. IN DWORD dwCurrentIndex,
  539. IN DWORD dwArgCount,
  540. IN DWORD dwFlags,
  541. IN LPCVOID pvData,
  542. OUT BOOL *pbDone
  543. )
  544. {
  545. DWORD dwRet = ERROR_SHOW_USAGE,dwCount=0;
  546. HANDLE hPolicyStorage=NULL;
  547. DWORD dwReturnCode = ERROR_SUCCESS;
  548. BOOL bWin2kSpecified=FALSE;
  549. PARSER_PKT parser;
  550. ZeroMemory(&parser, sizeof(parser));
  551. const TAG_TYPE vcmdStaticRestoreDefaults[] =
  552. {
  553. { CMD_TOKEN_STR_RELEASE, NS_REQ_PRESENT, FALSE }
  554. };
  555. const TOKEN_VALUE vtokStaticRestoreDefaults[] =
  556. {
  557. { CMD_TOKEN_STR_RELEASE, CMD_TOKEN_RELEASE }
  558. };
  559. if((g_StorageLocation.dwLocation == IPSEC_DIRECTORY_PROVIDER) || (g_StorageLocation.dwLocation == IPSEC_PERSISTENT_PROVIDER))
  560. {
  561. PrintErrorMessage(IPSEC_ERR,0,ERRCODE_MISC_STATIC_RESDEFRULE_3);
  562. dwRet = ERROR_SUCCESS;
  563. BAIL_OUT;
  564. }
  565. //if the user asked for usage, delegate the responsibility to netsh
  566. if(dwArgCount <= 2)
  567. {
  568. dwRet = ERROR_SHOW_USAGE;
  569. BAIL_OUT;
  570. }
  571. parser.ValidTok = vtokStaticRestoreDefaults;
  572. parser.MaxTok = SIZEOF_TOKEN_VALUE(vtokStaticRestoreDefaults);
  573. parser.ValidCmd = vcmdStaticRestoreDefaults;
  574. parser.MaxCmd = SIZEOF_TAG_TYPE(vcmdStaticRestoreDefaults);
  575. dwRet = Parser(pwszMachine,ppwcArguments,dwCurrentIndex,dwArgCount,&parser);
  576. if(dwRet != ERROR_SUCCESS)
  577. {
  578. CleanUp();
  579. if (dwRet==RETURN_NO_ERROR)
  580. {
  581. dwRet = ERROR_SUCCESS;
  582. }
  583. BAIL_OUT;
  584. }
  585. for(dwCount=0;dwCount<parser.MaxTok;dwCount++)
  586. {
  587. switch(vtokStaticRestoreDefaults[parser.Cmd[dwCount].dwCmdToken].dwValue)
  588. {
  589. case CMD_TOKEN_RELEASE :
  590. if ((parser.Cmd[dwCount].dwStatus == VALID_TOKEN)&&(parser.Cmd[dwCount].pArg))
  591. {
  592. if (*(DWORD *)parser.Cmd[dwCount].pArg== TOKEN_RELEASE_WIN2K)
  593. {
  594. bWin2kSpecified=TRUE;
  595. }
  596. }
  597. break;
  598. default :
  599. break;
  600. }
  601. }
  602. CleanUp();
  603. // get the store location info
  604. dwReturnCode = OpenPolicyStore(&hPolicyStorage);
  605. if (dwReturnCode != ERROR_SUCCESS)
  606. {
  607. PrintErrorMessage(IPSEC_ERR,0,ERRCODE_FAILED_POLSTORE_OPEN);
  608. dwRet=ERROR_SUCCESS;
  609. BAIL_OUT;
  610. }
  611. if(bWin2kSpecified)
  612. {
  613. dwReturnCode = IPSecRestoreDefaultPolicies(hPolicyStorage);
  614. }
  615. else
  616. {
  617. //.NET case. API call is to be changed when applicable
  618. dwReturnCode = IPSecRestoreDefaultPolicies(hPolicyStorage);
  619. }
  620. if (dwReturnCode != ERROR_SUCCESS)
  621. {
  622. PrintErrorMessage(IPSEC_ERR,0,ERRCODE_MISC_STATIC_RESDEFRULE_2);
  623. }
  624. ClosePolicyStore(hPolicyStorage);
  625. dwRet=ERROR_SUCCESS;
  626. error:
  627. return dwRet;
  628. }
  629. ///////////////////////////////////////////////////////////////////////
  630. //
  631. //Function: HandleStaticSetBatch()
  632. //
  633. //Date of Creation: 21st Aug 2001
  634. //
  635. //Parameters:
  636. // IN LPCWSTR pwszMachine,
  637. // IN OUT LPWSTR *ppwcArguments,
  638. // IN DWORD dwCurrentIndex,
  639. // IN DWORD dwArgCount,
  640. // IN DWORD dwFlags,
  641. // IN LPCVOID pvData,
  642. // OUT BOOL *pbDone
  643. //
  644. //Return: DWORD
  645. //
  646. //Description:
  647. //
  648. //
  649. //Revision History:
  650. //
  651. // Date Author Comments
  652. //
  653. ///////////////////////////////////////////////////////////////////////
  654. DWORD WINAPI
  655. HandleStaticSetBatch(
  656. IN LPCWSTR pwszMachine,
  657. IN OUT LPWSTR *ppwcArguments,
  658. IN DWORD dwCurrentIndex,
  659. IN DWORD dwArgCount,
  660. IN DWORD dwFlags,
  661. IN LPCVOID pvData,
  662. OUT BOOL *pbDone
  663. )
  664. {
  665. DWORD dwRet = ERROR_SHOW_USAGE;
  666. DWORD dwCount=0;
  667. BOOL bBatchMode=FALSE;
  668. PARSER_PKT parser;
  669. ZeroMemory(&parser, sizeof(parser));
  670. const TAG_TYPE vcmdStaticSetBatch[] =
  671. {
  672. { CMD_TOKEN_STR_MODE, NS_REQ_PRESENT, FALSE }
  673. };
  674. const TOKEN_VALUE vtokStaticSetBatch[] =
  675. {
  676. { CMD_TOKEN_STR_MODE, CMD_TOKEN_MODE }
  677. };
  678. //if the user asked for usage, delegate the responsibility to netsh
  679. if(dwArgCount <= 3)
  680. {
  681. dwRet = ERROR_SHOW_USAGE;
  682. BAIL_OUT;
  683. }
  684. parser.ValidTok = vtokStaticSetBatch;
  685. parser.MaxTok = SIZEOF_TOKEN_VALUE(vtokStaticSetBatch);
  686. parser.ValidCmd = vcmdStaticSetBatch;
  687. parser.MaxCmd = SIZEOF_TAG_TYPE(vcmdStaticSetBatch);
  688. dwRet = Parser(pwszMachine,ppwcArguments,dwCurrentIndex,dwArgCount,&parser);
  689. if(dwRet != ERROR_SUCCESS)
  690. {
  691. CleanUp();
  692. if (dwRet==RETURN_NO_ERROR)
  693. {
  694. dwRet = ERROR_SUCCESS;
  695. }
  696. BAIL_OUT;
  697. }
  698. //this flag enables the cache operation
  699. for(dwCount=0;dwCount<parser.MaxTok;dwCount++)
  700. {
  701. switch(vtokStaticSetBatch[parser.Cmd[dwCount].dwCmdToken].dwValue)
  702. {
  703. case CMD_TOKEN_MODE :
  704. if ((parser.Cmd[dwCount].dwStatus == VALID_TOKEN)&&(parser.Cmd[dwCount].pArg))
  705. bBatchMode = *(BOOL *)parser.Cmd[dwCount].pArg;
  706. break;
  707. default :
  708. break;
  709. }
  710. }
  711. if (g_NshPolStoreHandle.SetBatchmodeStatus(bBatchMode) == ERROR_OUTOFMEMORY)
  712. {
  713. PrintErrorMessage(WIN32_ERR,ERROR_OUTOFMEMORY,NULL);
  714. }
  715. g_NshPolNegFilData.FlushAll();
  716. CleanUp();
  717. error:
  718. return dwRet;
  719. }
  720. ///////////////////////////////////////////////////////////////////////
  721. //
  722. //Function: CopyStorageInfo()
  723. //
  724. //Date of Creation: 21st Aug 2001
  725. //
  726. //Parameters:
  727. // OUT LPTSTR *ppszMachineName,
  728. // OUT DWORD &dwLoc
  729. //
  730. //Return: DWORD
  731. //
  732. //Description:
  733. // This function copys the Global storage info to local variables.
  734. //
  735. //Revision History:
  736. //
  737. // Date Author Comments
  738. //
  739. ///////////////////////////////////////////////////////////////////////
  740. DWORD
  741. CopyStorageInfo(
  742. OUT LPTSTR *ppszMachineName,
  743. OUT DWORD &dwLocation
  744. )
  745. {
  746. DWORD dwReturn = ERROR_SUCCESS ,dwStrLength =0;
  747. LPTSTR pszMachineName = NULL;
  748. LPTSTR pszTarget = NULL;
  749. dwLocation = g_StorageLocation.dwLocation;
  750. if (dwLocation == IPSEC_DIRECTORY_PROVIDER)
  751. {
  752. pszTarget = g_StorageLocation.pszDomainName;
  753. }
  754. else
  755. {
  756. pszTarget = g_StorageLocation.pszMachineName;
  757. }
  758. if(_tcscmp(pszTarget, _TEXT("")) !=0)
  759. {
  760. dwStrLength = _tcslen(pszTarget);
  761. pszMachineName= new _TCHAR[dwStrLength+1];
  762. if(pszMachineName)
  763. {
  764. _tcsncpy(pszMachineName,pszTarget,dwStrLength+1);
  765. }
  766. else
  767. {
  768. dwReturn = ERROR_OUTOFMEMORY;
  769. }
  770. }
  771. *ppszMachineName = pszMachineName;
  772. return dwReturn;
  773. }