Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1299 lines
42 KiB

  1. /////////////////////////////////////////////////////////////
  2. // Copyright(c) 1998-2000, Microsoft Corporation
  3. //
  4. // text2pol.cpp
  5. //
  6. // Created on 4/5/98 by Randyram
  7. // Revisions:
  8. // Moved the routines to this module 8/25/98
  9. //
  10. // Split into text2pol.cpp, text2spd.h and text2spd.cpp 2/15/00 DKalin
  11. //
  12. // Implementation for the text to policy conversion routines (generic ones)
  13. // (See more in the text2spd.cpp)
  14. //
  15. /////////////////////////////////////////////////////////////
  16. #include "ipseccmd.h"
  17. // CFilter storage version
  18. DWORD ConvertFilter(IN T2P_FILTER &Filter,
  19. IN OUT IPSEC_FILTER_SPEC &PolstoreFilter)
  20. {
  21. DWORD dwReturn = T2P_OK; // return code of this function
  22. PolstoreFilter.pszSrcDNSName = PolstoreFilter.pszDestDNSName = 0;
  23. if (Filter.QMFilterType == QM_TRANSPORT_FILTER)
  24. {
  25. PolstoreFilter.FilterSpecGUID = Filter.TransportFilter.gFilterID;
  26. PolstoreFilter.pszDescription = IPSecAllocPolStr(Filter.TransportFilter.pszFilterName);
  27. PolstoreFilter.dwMirrorFlag = Filter.TransportFilter.bCreateMirror;
  28. PolstoreFilter.Filter.SrcAddr = Filter.TransportFilter.SrcAddr.uIpAddr;
  29. PolstoreFilter.Filter.SrcMask = Filter.TransportFilter.SrcAddr.uSubNetMask;
  30. PolstoreFilter.Filter.DestAddr = Filter.TransportFilter.DesAddr.uIpAddr;
  31. PolstoreFilter.Filter.DestMask = Filter.TransportFilter.DesAddr.uSubNetMask;
  32. PolstoreFilter.Filter.TunnelAddr = 0;
  33. PolstoreFilter.Filter.Protocol = Filter.TransportFilter.Protocol.dwProtocol;
  34. PolstoreFilter.Filter.SrcPort = Filter.TransportFilter.SrcPort.wPort;
  35. PolstoreFilter.Filter.DestPort = Filter.TransportFilter.DesPort.wPort;
  36. PolstoreFilter.Filter.TunnelFilter = FALSE;
  37. }
  38. else
  39. {
  40. // tunnel filter
  41. PolstoreFilter.FilterSpecGUID = Filter.TunnelFilter.gFilterID;
  42. PolstoreFilter.pszDescription = IPSecAllocPolStr(Filter.TunnelFilter.pszFilterName);
  43. PolstoreFilter.dwMirrorFlag = FALSE;
  44. PolstoreFilter.Filter.SrcAddr = Filter.TunnelFilter.SrcAddr.uIpAddr;
  45. PolstoreFilter.Filter.SrcMask = Filter.TunnelFilter.SrcAddr.uSubNetMask;
  46. PolstoreFilter.Filter.DestAddr = Filter.TunnelFilter.DesAddr.uIpAddr;
  47. PolstoreFilter.Filter.DestMask = Filter.TunnelFilter.DesAddr.uSubNetMask;
  48. PolstoreFilter.Filter.TunnelAddr = Filter.TunnelFilter.DesTunnelAddr.uIpAddr;
  49. PolstoreFilter.Filter.Protocol = Filter.TunnelFilter.Protocol.dwProtocol;
  50. PolstoreFilter.Filter.SrcPort = Filter.TunnelFilter.SrcPort.wPort;
  51. PolstoreFilter.Filter.DestPort = Filter.TunnelFilter.DesPort.wPort;
  52. PolstoreFilter.Filter.TunnelFilter = TRUE;
  53. }
  54. return dwReturn;
  55. }
  56. DWORD TextToStorageLocation(IN char *szText, OUT STORAGE_INFO & StoreInfo)
  57. {
  58. DWORD dwReturn = T2P_OK;
  59. WCHAR *pString = NULL,
  60. *pTmp = NULL;
  61. WCHAR szTmp[POTF_MAX_STRLEN];
  62. WCHAR *Info = NULL;
  63. if (szText != NULL)
  64. {
  65. // copy szText so we can muck with it
  66. _stprintf(szTmp, TEXT("%S"), szText);
  67. // parse string
  68. if ( (pString = wcschr(szTmp, POTF_STORAGE_TOKEN)) != NULL )
  69. *pString = L'\0';
  70. if (towlower(szTmp[0]) == tolower(POTF_STORAGE_DS[0]))
  71. {
  72. StoreInfo.Type = STORAGE_TYPE_DS;
  73. if ((pString != NULL) && (wcslen(pString + 1) > 0) )
  74. {
  75. ++pString; // now pointing at string
  76. wcscpy(StoreInfo.szLocationName, pString);
  77. }
  78. // else no domain provided
  79. }
  80. else if (towlower(szTmp[0]) == tolower(POTF_STORAGE_REG[0]))
  81. {
  82. StoreInfo.Type = STORAGE_TYPE_REGISTRY;
  83. }
  84. else if (towlower(szTmp[0]) == tolower(POTF_STORAGE_CACHE[0]))
  85. {
  86. StoreInfo.Type = STORAGE_TYPE_CACHE;
  87. }
  88. else // invalid option
  89. {
  90. dwReturn = T2P_INVALID_STORAGE_INFO;
  91. }
  92. }
  93. else
  94. dwReturn = T2P_NULL_STRING;
  95. return dwReturn;
  96. }
  97. // the whole reason to have this is to extract the polling interval
  98. // if specified
  99. DWORD TextToPolicyName(IN char *szText, OUT STORAGE_INFO & StoreInfo)
  100. {
  101. DWORD dwReturn = T2P_OK;
  102. WCHAR *pString = NULL,
  103. *pTmp = NULL;
  104. WCHAR szTmp[POTF_MAX_STRLEN];
  105. WCHAR *Info = NULL;
  106. if (szText != NULL)
  107. {
  108. // copy szText so we can muck with it
  109. _stprintf(szTmp, TEXT("%S"), szText);
  110. // parse string
  111. if ( (pString = wcschr(szTmp, POTF_STORAGE_TOKEN)) != NULL )
  112. *pString = '\0';
  113. wcscpy(StoreInfo.szPolicyName, szTmp);
  114. if ((pString != NULL) && (wcslen(pString + 1) > 0) )
  115. {
  116. ++pString; // now pointing at polling interval
  117. // XX could be checked more stringently
  118. // do the converstion to minutes here
  119. StoreInfo.tPollingInterval = 60 * (wcstol(pString, NULL, 10));
  120. }
  121. }
  122. else
  123. dwReturn = T2P_NULL_STRING;
  124. return dwReturn;
  125. }
  126. bool InStorageMode(IN UINT uArgCount, IN char *strArgs[])
  127. {
  128. for (UINT i = 0; i < uArgCount; ++i)
  129. if ( strArgs[i][1] == POTF_STORAGE_FLAG )
  130. return true;
  131. return false;
  132. }
  133. // CmdLineToPolicy
  134. // pStorageInfo has NULL as default
  135. // Returns False if there is any kind of failure
  136. DWORD CmdLineToPolicy(IN UINT uArgCount, IN char *strArgs[],
  137. OUT IPSEC_IKE_POLICY & IpsecIkePol,
  138. OUT bool & bConfirm
  139. ,OUT PSTORAGE_INFO pStorageInfo)
  140. {
  141. DWORD dwReturn = T2P_OK;
  142. IPSEC_QM_POLICY IpsPol;
  143. IPSEC_MM_POLICY IkePol;
  144. MM_AUTH_METHODS AuthInfos;
  145. MM_FILTER* pMMFilters;
  146. DWORD dwNumMMFilters;
  147. QM_FILTER_TYPE QMFilterType;
  148. DWORD dwNumFilters;
  149. TRANSPORT_FILTER* pTransportFilters;
  150. TUNNEL_FILTER* pTunnelFilters;
  151. memcpy(&IpsPol, &IpsecIkePol.IpsPol, sizeof(IpsPol));
  152. memcpy(&IkePol, &IpsecIkePol.IkePol, sizeof(IkePol));
  153. memcpy(&AuthInfos, &IpsecIkePol.AuthInfos, sizeof(AuthInfos));
  154. pMMFilters = IpsecIkePol.pMMFilters;
  155. dwNumMMFilters = IpsecIkePol.dwNumMMFilters;
  156. QMFilterType = IpsecIkePol.QMFilterType;
  157. dwNumFilters = IpsecIkePol.dwNumFilters;
  158. pTransportFilters = IpsecIkePol.pTransportFilters;
  159. pTunnelFilters = IpsecIkePol.pTunnelFilters;
  160. // used when finding out how much mem to alloc
  161. UINT uFiltAlloc = 0,
  162. uMMFiltAlloc = 0,
  163. uSecMetAlloc = 0,
  164. uOfferAlloc = 0,
  165. uAuthAlloc = 0;
  166. UINT i = 0; // loop cntr
  167. bool bIsMirrorFilt = false,
  168. bMirrorFiltRC = true; // since MirrorFilt is not a T2P mod
  169. T2P_FILTER Filter; // for TextToFilter calls
  170. memset(&Filter, 0, sizeof(Filter));
  171. Filter.QMFilterType = QM_TRANSPORT_FILTER; // by default it's transport
  172. bConfirm = false;
  173. // for post-processing Ike policy
  174. bool bP1RekeyUsed = false;
  175. KEY_LIFETIME OakLife;
  176. DWORD QMLimit = POTF_DEFAULT_P1REKEY_QMS;
  177. OakLife.uKeyExpirationTime = POTF_DEFAULT_P1REKEY_TIME;
  178. OakLife.uKeyExpirationKBytes = 0; // not used
  179. IF_TYPE Interface = INTERFACE_TYPE_ALL;
  180. IPAddr DesTunnelAddr = 0;
  181. IPAddr SrcTunnelAddr = 0;
  182. // We do some things differently in storage mode:
  183. // * process negotiation policy actions
  184. // * use a different filter list
  185. //
  186. // This could all be much cleaner, but until the cmd line
  187. // parsing is actually separated from the policy processing
  188. // we're pretty much stuck with this unless we want to duplicated
  189. // alot of code. eg. 2 cmdlinetopolicy, one dynamic, one storage
  190. //
  191. bool bStorageMode = InStorageMode(uArgCount, strArgs);
  192. if ( bStorageMode && !pStorageInfo )
  193. return T2P_NO_STORAGE_INFO;
  194. //
  195. // we'll allow the cmd line to specify
  196. // storage options. Use a temp structure to hold those
  197. // options-- then we'll copy it at the end if pStorageInfo != NULL
  198. //
  199. STORAGE_INFO tmpStorageInfo;
  200. memset(&tmpStorageInfo, 0, sizeof(tmpStorageInfo));
  201. tmpStorageInfo.guidNegPolAction = GUID_NEGOTIATION_ACTION_NORMAL_IPSEC;
  202. // init OUT params (free them if necessary)
  203. if (IkePol.pOffers != NULL)
  204. {
  205. free(IkePol.pOffers);
  206. }
  207. IkePol.pOffers = NULL;
  208. IkePol.dwOfferCount = 0;
  209. if (IpsPol.pOffers != NULL)
  210. {
  211. free(IpsPol.pOffers);
  212. }
  213. IpsPol.pOffers = NULL;
  214. IpsPol.dwOfferCount = 0;
  215. if (AuthInfos.pAuthenticationInfo != NULL)
  216. {
  217. for (i = 0; i < (UINT) AuthInfos.dwNumAuthInfos; i++)
  218. {
  219. if (AuthInfos.pAuthenticationInfo[i].pAuthInfo != NULL)
  220. free(AuthInfos.pAuthenticationInfo[i].pAuthInfo);
  221. }
  222. free(AuthInfos.pAuthenticationInfo);
  223. }
  224. AuthInfos.pAuthenticationInfo = NULL;
  225. AuthInfos.dwNumAuthInfos = NULL;
  226. // cleanup filters
  227. if (pTransportFilters != NULL)
  228. {
  229. for (i = 0; i < (UINT) dwNumFilters; i++)
  230. {
  231. if (pTransportFilters[i].pszFilterName != NULL)
  232. free(pTransportFilters[i].pszFilterName);
  233. }
  234. free(pTransportFilters);
  235. }
  236. pTransportFilters = NULL;
  237. if (pTunnelFilters != NULL)
  238. {
  239. for (i = 0; i < (UINT) dwNumFilters; i++)
  240. {
  241. if (pTunnelFilters[i].pszFilterName != NULL)
  242. free(pTunnelFilters[i].pszFilterName);
  243. }
  244. free(pTunnelFilters);
  245. }
  246. pTunnelFilters = NULL;
  247. QMFilterType = Filter.QMFilterType;
  248. dwNumFilters = 0;
  249. // mm filters
  250. if (pMMFilters != NULL)
  251. {
  252. for (i = 0; i < (UINT) dwNumMMFilters; i++)
  253. {
  254. if (pMMFilters[i].pszFilterName != NULL)
  255. free(pMMFilters[i].pszFilterName);
  256. }
  257. free(pMMFilters);
  258. }
  259. pMMFilters = NULL;
  260. dwNumMMFilters = 0;
  261. // we assume uArgCount and strArgs are OK
  262. // but defend against ######### here
  263. if (uArgCount > 0 && strArgs != NULL)
  264. {
  265. // find out how much memory we're going to need
  266. // we do this here because I allow multiple flags of same type
  267. for (i = 1; i < uArgCount; )
  268. {
  269. if ( strchr(POTF_FLAG_TOKENS, strArgs[i][0]) != NULL )
  270. {
  271. if (strArgs[i][1] == POTF_FILTER_FLAG)
  272. {
  273. if (strArgs[i][2] != '\0') // user omitted space
  274. {
  275. ++uFiltAlloc;
  276. }
  277. ++i;
  278. while ( (i < uArgCount) && (strchr(POTF_FLAG_TOKENS, strArgs[i][0]) == NULL) )
  279. {
  280. ++uFiltAlloc;
  281. ++i;
  282. }
  283. }
  284. else if (strArgs[i][1] == POTF_NEGPOL_FLAG)
  285. {
  286. if (strArgs[i][2] != '\0') // user omitted space
  287. ++uOfferAlloc;
  288. ++i;
  289. while ( (i < uArgCount) && (strchr(POTF_FLAG_TOKENS, strArgs[i][0]) == NULL) )
  290. {
  291. ++uOfferAlloc;
  292. ++i;
  293. }
  294. }
  295. else if (strArgs[i][1] == POTF_AUTH_FLAG)
  296. {
  297. if (strArgs[i][2] != '\0') // user omitted space
  298. ++uAuthAlloc;
  299. ++i;
  300. while ( (i < uArgCount) && (strchr(POTF_FLAG_TOKENS, strArgs[i][0]) == NULL) )
  301. {
  302. ++uAuthAlloc;
  303. ++i;
  304. }
  305. }
  306. else if ( strncmp(&strArgs[i][1], POTF_SECMETHOD_FLAG,
  307. strlen(POTF_SECMETHOD_FLAG)) == 0 )
  308. {
  309. if (strArgs[i][3] != '\0') // user omitted space
  310. ++uSecMetAlloc;
  311. ++i;
  312. while ( (i < uArgCount) && (strchr(POTF_FLAG_TOKENS, strArgs[i][0]) == NULL) )
  313. {
  314. ++uSecMetAlloc;
  315. ++i;
  316. }
  317. }
  318. else if ( strncmp(&strArgs[i][1], POTF_MMFILTER_FLAG,
  319. strlen(POTF_MMFILTER_FLAG)) == 0 )
  320. {
  321. if (strArgs[i][3] != '\0') // user omitted space
  322. ++uMMFiltAlloc;
  323. ++i;
  324. while ( (i < uArgCount) && (strchr(POTF_FLAG_TOKENS, strArgs[i][0]) == NULL) )
  325. {
  326. ++uMMFiltAlloc;
  327. ++i;
  328. }
  329. }
  330. else if (strArgs[i][1] == POTF_TUNNEL_FLAG)
  331. {
  332. // switch to tunnel mode
  333. QMFilterType = Filter.QMFilterType = QM_TUNNEL_FILTER;
  334. i++;
  335. }
  336. else
  337. ++i;
  338. }
  339. else
  340. ++i;
  341. }
  342. // now allocate the memory
  343. if (uFiltAlloc)
  344. {
  345. // we allocate both transport and tunnel filter storage because of RPC reasons
  346. pTransportFilters = new TRANSPORT_FILTER[uFiltAlloc + 1];
  347. assert(pTransportFilters != NULL);
  348. // init these
  349. for (i = 0; i <= uFiltAlloc; ++i)
  350. memset(&pTransportFilters[i], 0, sizeof(TRANSPORT_FILTER));
  351. memset(&Filter.TransportFilter, 0, sizeof(TRANSPORT_FILTER));
  352. // tunnel mode
  353. pTunnelFilters = new TUNNEL_FILTER[uFiltAlloc + 1];
  354. assert(pTunnelFilters != NULL);
  355. // init these
  356. for (i = 0; i <= uFiltAlloc; ++i)
  357. memset(&pTunnelFilters[i], 0, sizeof(TUNNEL_FILTER));
  358. memset(&Filter.TunnelFilter, 0, sizeof(TUNNEL_FILTER));
  359. if (!uMMFiltAlloc)
  360. {
  361. // allocate main mode filters for auto-generation
  362. pMMFilters = new MM_FILTER[uFiltAlloc + 1];
  363. assert(pMMFilters != NULL);
  364. // init these
  365. for (i = 0; i <= uFiltAlloc; ++i)
  366. memset(&pMMFilters[i], 0, sizeof(MM_FILTER));
  367. }
  368. }
  369. if (uMMFiltAlloc)
  370. {
  371. // allocate main mode filters
  372. pMMFilters = new MM_FILTER[uMMFiltAlloc + 1];
  373. assert(pMMFilters != NULL);
  374. // init these
  375. for (i = 0; i <= uMMFiltAlloc; ++i)
  376. memset(&pMMFilters[i], 0, sizeof(MM_FILTER));
  377. }
  378. if (uAuthAlloc)
  379. {
  380. AuthInfos.pAuthenticationInfo = new IPSEC_MM_AUTH_INFO[uAuthAlloc + 1];
  381. assert(AuthInfos.pAuthenticationInfo != NULL);
  382. // init these
  383. for (i = 0; i <= uAuthAlloc; ++i)
  384. memset(&AuthInfos.pAuthenticationInfo[i], 0, sizeof(IPSEC_MM_AUTH_INFO));
  385. }
  386. if (uOfferAlloc)
  387. {
  388. IpsPol.pOffers = new IPSEC_QM_OFFER[uOfferAlloc + 1];
  389. assert(IpsPol.pOffers != NULL);
  390. // init these
  391. for (i = 0; i <= uOfferAlloc; ++i)
  392. {
  393. memset(&IpsPol.pOffers[i], 0, sizeof(IPSEC_QM_OFFER));
  394. }
  395. }
  396. if (uSecMetAlloc)
  397. {
  398. IkePol.pOffers = new IPSEC_MM_OFFER[uSecMetAlloc + 1];
  399. assert(IkePol.pOffers != NULL);
  400. // init these
  401. for (i = 0; i <= uSecMetAlloc; ++i)
  402. {
  403. memset(&IkePol.pOffers[i], 0, sizeof(IPSEC_MM_OFFER));
  404. }
  405. }
  406. // Main processing loop ////////////////////////////////////////////////////////
  407. // invariants;
  408. // 1. use dwReturn when calling util functions, if returns false
  409. // break out of for loop and let cleanup code take over
  410. // 2. advance i each time you process a param
  411. for (i = 1; i < uArgCount && T2P_SUCCESS(dwReturn); ) // we'll advance i below
  412. {
  413. // make sure there is actually a flag, else we have parse error
  414. if ( strchr(POTF_FLAG_TOKENS, strArgs[i][0]) != NULL )
  415. {
  416. if (strArgs[i][1] == POTF_FILTER_FLAG) // filter list
  417. {
  418. // first filter is special case because user may
  419. // omit space after flag
  420. if ((strArgs[i][2] != '\0')
  421. && (strchr(POTF_FLAG_TOKENS, strArgs[i][2]) == NULL))
  422. {
  423. //
  424. // Even if we're in storage mode, we use these
  425. // filters.
  426. //
  427. dwReturn = TextToFilter(&strArgs[i][2], Filter);
  428. if (QMFilterType == QM_TRANSPORT_FILTER)
  429. {
  430. memcpy(&pTransportFilters[dwNumFilters], &Filter.TransportFilter, sizeof(TRANSPORT_FILTER));
  431. }
  432. else
  433. {
  434. // tunnel
  435. memcpy(&pTunnelFilters[dwNumFilters], &Filter.TunnelFilter, sizeof(TUNNEL_FILTER));
  436. }
  437. if (!T2P_SUCCESS(dwReturn))
  438. break;
  439. else
  440. {
  441. ++dwNumFilters;
  442. }
  443. }
  444. else if (strArgs[i][2] != '\0')
  445. {
  446. sprintf(STRLASTERR,
  447. "Unexpected flag: %s. Check usage.\n", strArgs[i]);
  448. PARSE_ERROR;
  449. dwReturn = POTF_FAILED;
  450. break;
  451. }
  452. ++i; // advance to next arg
  453. while ( (i < uArgCount) && (strchr(POTF_FLAG_TOKENS, strArgs[i][0]) == NULL) )
  454. {
  455. //
  456. // Even if we're in storage mode, we fill these in
  457. //
  458. dwReturn = TextToFilter(&strArgs[i][0], Filter);
  459. if (QMFilterType == QM_TRANSPORT_FILTER)
  460. {
  461. memcpy(&pTransportFilters[dwNumFilters], &Filter.TransportFilter, sizeof(TRANSPORT_FILTER));
  462. }
  463. else
  464. {
  465. // tunnel
  466. memcpy(&pTunnelFilters[dwNumFilters], &Filter.TunnelFilter, sizeof(TUNNEL_FILTER));
  467. }
  468. if (!T2P_SUCCESS(dwReturn))
  469. break;
  470. else
  471. {
  472. ++dwNumFilters;
  473. }
  474. ++i; // advance to next arg
  475. }
  476. }
  477. else if (strArgs[i][1] == POTF_NEGPOL_FLAG)
  478. {
  479. // first offer is special case because user may
  480. // omit space after flag
  481. if ((strArgs[i][2] != '\0')
  482. && (strchr(POTF_FLAG_TOKENS, strArgs[i][2]) == NULL))
  483. {
  484. if ( !strcmp(&strArgs[i][2], POTF_PASSTHRU) )
  485. {
  486. tmpStorageInfo.guidNegPolAction
  487. = GUID_NEGOTIATION_ACTION_NO_IPSEC;
  488. }
  489. else if ( !strcmp(&strArgs[i][2], POTF_INBOUND_PASSTHRU) )
  490. {
  491. tmpStorageInfo.guidNegPolAction =
  492. GUID_NEGOTIATION_ACTION_INBOUND_PASSTHRU;
  493. }
  494. else if ( !strcmp(&strArgs[i][2], POTF_BLOCK) )
  495. {
  496. tmpStorageInfo.guidNegPolAction =
  497. GUID_NEGOTIATION_ACTION_BLOCK;
  498. }
  499. else
  500. {
  501. dwReturn = TextToOffer(&strArgs[i][2], IpsPol.pOffers[IpsPol.dwOfferCount]);
  502. if (!T2P_SUCCESS(dwReturn)) break;
  503. else ++IpsPol.dwOfferCount;
  504. }
  505. }
  506. else if (strArgs[i][2] != '\0')
  507. {
  508. sprintf(STRLASTERR,
  509. "Unexpected flag: %s. Check usage.\n", strArgs[i]);
  510. PARSE_ERROR;
  511. dwReturn = POTF_FAILED;
  512. break;
  513. }
  514. ++i; // advance to next arg
  515. while ( (i < uArgCount) && (strchr(POTF_FLAG_TOKENS, strArgs[i][0]) == NULL) )
  516. {
  517. if ( !strcmp(&strArgs[i][0], POTF_PASSTHRU) )
  518. {
  519. tmpStorageInfo.guidNegPolAction
  520. = GUID_NEGOTIATION_ACTION_NO_IPSEC;
  521. }
  522. else if ( !strcmp(&strArgs[i][0], POTF_INBOUND_PASSTHRU) )
  523. {
  524. tmpStorageInfo.guidNegPolAction =
  525. GUID_NEGOTIATION_ACTION_INBOUND_PASSTHRU;
  526. }
  527. else if ( !strcmp(&strArgs[i][0], POTF_BLOCK) )
  528. {
  529. tmpStorageInfo.guidNegPolAction =
  530. GUID_NEGOTIATION_ACTION_BLOCK;
  531. }
  532. else
  533. {
  534. dwReturn = TextToOffer(&strArgs[i][0], IpsPol.pOffers[IpsPol.dwOfferCount]);
  535. if (!T2P_SUCCESS(dwReturn)) goto error_occured;
  536. else ++IpsPol.dwOfferCount;
  537. }
  538. ++i; // advance to next arg
  539. }
  540. }
  541. else if (strArgs[i][1] == POTF_TUNNEL_FLAG)
  542. {
  543. if (strArgs[i][2] != '\0') // no space after flag
  544. {
  545. TextToIPAddr(&strArgs[i][2], DesTunnelAddr);
  546. }
  547. else
  548. {
  549. ++i;
  550. TextToIPAddr(&strArgs[i][0], DesTunnelAddr);
  551. }
  552. ++i;
  553. // now check for second tunnel address
  554. if (i < uArgCount && strchr(POTF_FLAG_TOKENS, strArgs[i][0]) == NULL)
  555. {
  556. // not an option, tunnel address
  557. SrcTunnelAddr = DesTunnelAddr;
  558. TextToIPAddr(&strArgs[i][0], DesTunnelAddr);
  559. ++i;
  560. }
  561. }
  562. else if (strArgs[i][1] == POTF_AUTH_FLAG)
  563. {
  564. // first offer is special case because user may
  565. // omit space after flag
  566. if ((strArgs[i][2] != '\0')
  567. && (strchr(POTF_FLAG_TOKENS, strArgs[i][2]) == NULL))
  568. {
  569. dwReturn = TextToOakleyAuth(&strArgs[i][2], AuthInfos.pAuthenticationInfo[AuthInfos.dwNumAuthInfos]);
  570. if (!T2P_SUCCESS(dwReturn)) break;
  571. else ++AuthInfos.dwNumAuthInfos;
  572. }
  573. else if (strArgs[i][2] != '\0')
  574. {
  575. sprintf(STRLASTERR,
  576. "Unexpected flag: %s. Check usage.\n", strArgs[i]);
  577. PARSE_ERROR;
  578. dwReturn = POTF_FAILED;
  579. break;
  580. }
  581. ++i; // advance to next arg
  582. while ( (i < uArgCount) && (strchr(POTF_FLAG_TOKENS, strArgs[i][0]) == NULL) )
  583. {
  584. dwReturn = TextToOakleyAuth(&strArgs[i][0], AuthInfos.pAuthenticationInfo[AuthInfos.dwNumAuthInfos]);
  585. if (!T2P_SUCCESS(dwReturn)) goto error_occured;
  586. else ++AuthInfos.dwNumAuthInfos;
  587. ++i; // advance to next arg
  588. }
  589. }
  590. else if (strArgs[i][1] == POTF_STORAGE_FLAG)
  591. {
  592. if ((strArgs[i][2] != '\0')
  593. && (strchr(POTF_FLAG_TOKENS, strArgs[i][2]) == NULL))
  594. {
  595. dwReturn = TextToStorageLocation(&strArgs[i][2], tmpStorageInfo);
  596. if (!T2P_SUCCESS(dwReturn)) break;
  597. }
  598. else if (strArgs[i][2] != '\0')
  599. {
  600. sprintf(STRLASTERR,
  601. "Unexpected flag: %s. Check usage.\n", strArgs[i]);
  602. PARSE_ERROR;
  603. dwReturn = POTF_FAILED;
  604. break;
  605. }
  606. else // storage info must be in next param
  607. {
  608. ++i; // advance to next arg
  609. if ( (i < uArgCount) && (strchr(POTF_FLAG_TOKENS, strArgs[i][0]) == NULL) )
  610. {
  611. dwReturn = TextToStorageLocation(&strArgs[i][0], tmpStorageInfo);
  612. if (!T2P_SUCCESS(dwReturn)) goto error_occured;
  613. ++i; // advance to next arg
  614. }
  615. else
  616. {
  617. sprintf(STRLASTERR,
  618. "You must specify storage info: %s. Check usage.\n", strArgs[i]);
  619. PARSE_ERROR;
  620. dwReturn = POTF_FAILED;
  621. break;
  622. }
  623. }
  624. }
  625. else if (strArgs[i][1] == POTF_POLNAME_FLAG)
  626. {
  627. if ((strArgs[i][2] != '\0')
  628. && (strchr(POTF_FLAG_TOKENS, strArgs[i][2]) == NULL))
  629. {
  630. dwReturn = TextToPolicyName(&strArgs[i][2], tmpStorageInfo);
  631. if (!T2P_SUCCESS(dwReturn)) break;
  632. }
  633. else if (strArgs[i][2] != '\0')
  634. {
  635. sprintf(STRLASTERR,
  636. "Unexpected flag: %s. Check usage.\n", strArgs[i]);
  637. PARSE_ERROR;
  638. dwReturn = POTF_FAILED;
  639. break;
  640. }
  641. else // policy name must be in next param
  642. {
  643. ++i; // advance to next arg
  644. if ( (i < uArgCount) && (strchr(POTF_FLAG_TOKENS, strArgs[i][0]) == NULL) )
  645. {
  646. dwReturn = TextToPolicyName(&strArgs[i][0], tmpStorageInfo);
  647. if (!T2P_SUCCESS(dwReturn)) goto error_occured;
  648. ++i; // advance to next arg
  649. }
  650. else
  651. {
  652. sprintf(STRLASTERR,
  653. "You must specify policy name: %s. Check usage.\n", strArgs[i]);
  654. PARSE_ERROR;
  655. dwReturn = POTF_FAILED;
  656. break;
  657. }
  658. }
  659. }
  660. else if (strArgs[i][1] == POTF_RULENAME_FLAG)
  661. {
  662. // first offer is special case because user may
  663. // omit space after flag
  664. if ((strArgs[i][2] != '\0')
  665. && (strchr(POTF_FLAG_TOKENS, strArgs[i][2]) == NULL))
  666. {
  667. _stprintf(tmpStorageInfo.szRuleName, TEXT("%S"), &strArgs[i][2]);
  668. }
  669. else if (strArgs[i][2] != '\0')
  670. {
  671. sprintf(STRLASTERR,
  672. "Unexpected flag: %s. Check usage.\n", strArgs[i]);
  673. PARSE_ERROR;
  674. dwReturn = POTF_FAILED;
  675. break;
  676. }
  677. else // policy name must be in next param
  678. {
  679. ++i; // advance to next arg
  680. if ( (i < uArgCount) && (strchr(POTF_FLAG_TOKENS, strArgs[i][0]) == NULL) )
  681. {
  682. _stprintf(tmpStorageInfo.szRuleName, TEXT("%S"), &strArgs[i][0]);
  683. ++i; // advance to next arg
  684. }
  685. else
  686. {
  687. sprintf(STRLASTERR,
  688. "You must specify rule name: %s. Check usage.\n", strArgs[i]);
  689. PARSE_ERROR;
  690. dwReturn = POTF_FAILED;
  691. break;
  692. }
  693. }
  694. }
  695. else if (strArgs[i][1] == POTF_SETACTIVE_FLAG)
  696. {
  697. tmpStorageInfo.bSetActive = TRUE;
  698. ++i;
  699. }
  700. else if (strArgs[i][1] == POTF_SETINACTIVE_FLAG)
  701. {
  702. tmpStorageInfo.bSetInActive = TRUE;
  703. ++i;
  704. }
  705. else if (strArgs[i][1] == POTF_CONFIRM_FLAG)
  706. {
  707. bConfirm = true;
  708. ++i;
  709. }
  710. else if (strArgs[i][1] == POTF_DELETEPOLICY_FLAG)
  711. {
  712. tmpStorageInfo.bDeletePolicy = true;
  713. ++i;
  714. }
  715. else if ( strncmp(&strArgs[i][1], POTF_DIALUP_FLAG,
  716. strlen(POTF_DIALUP_FLAG)) == 0 )
  717. {
  718. Interface = INTERFACE_TYPE_DIALUP;
  719. ++i;
  720. }
  721. else if (strArgs[i][1] == POTF_DEACTIVATE_FLAG)
  722. {
  723. // deactivate local registry policy right here
  724. // this is left for backward compatibility with old text2pol
  725. // directory policy assignment left intact
  726. HANDLE hRegPolicyStore = NULL;
  727. PIPSEC_POLICY_DATA pipspd = NULL;
  728. DWORD dwRes = ERROR_SUCCESS;
  729. dwRes = IPSecOpenPolicyStore(NULL, IPSEC_REGISTRY_PROVIDER, NULL, &hRegPolicyStore);
  730. if (dwRes == ERROR_SUCCESS && hRegPolicyStore != NULL)
  731. {
  732. dwRes = IPSecGetAssignedPolicyData(hRegPolicyStore, &pipspd);
  733. if (dwRes == ERROR_SUCCESS && pipspd != NULL)
  734. {
  735. dwRes = IPSecUnassignPolicy(hRegPolicyStore, pipspd[0].PolicyIdentifier);
  736. IPSecFreePolicyData(pipspd);
  737. }
  738. IPSecClosePolicyStore(hRegPolicyStore);
  739. }
  740. if (dwRes != ERROR_SUCCESS)
  741. {
  742. sprintf(STRLASTERR,
  743. "Polstore operation returned 0x%x!\n", dwRes);
  744. PARSE_ERROR;
  745. dwReturn = POTF_FAILED;
  746. break;
  747. }
  748. ++i;
  749. }
  750. else if ( strncmp(&strArgs[i][1], POTF_MMFILTER_FLAG,
  751. strlen(POTF_MMFILTER_FLAG)) == 0 )
  752. {
  753. // first filter is special case because user may
  754. // omit space after flag
  755. if ((strArgs[i][3] != '\0')
  756. && (strchr(POTF_FLAG_TOKENS, strArgs[i][3]) == NULL))
  757. {
  758. dwReturn = TextToMMFilter(&strArgs[i][3], pMMFilters[dwNumMMFilters]);
  759. if (!T2P_SUCCESS(dwReturn))
  760. break;
  761. else
  762. {
  763. ++dwNumMMFilters;
  764. }
  765. }
  766. else if (strArgs[i][3] != '\0')
  767. {
  768. sprintf(STRLASTERR,
  769. "Unexpected flag: %s. Check usage.\n", strArgs[i]);
  770. PARSE_ERROR;
  771. dwReturn = POTF_FAILED;
  772. break;
  773. }
  774. ++i; // advance to next arg
  775. while ( (i < uArgCount) && (strchr(POTF_FLAG_TOKENS, strArgs[i][0]) == NULL) )
  776. {
  777. dwReturn = TextToMMFilter(&strArgs[i][0], pMMFilters[dwNumMMFilters]);
  778. if (!T2P_SUCCESS(dwReturn))
  779. break;
  780. else
  781. {
  782. ++dwNumMMFilters;
  783. }
  784. ++i; // advance to next arg
  785. }
  786. }
  787. else if ( strncmp(&strArgs[i][1], POTF_SECMETHOD_FLAG,
  788. strlen(POTF_SECMETHOD_FLAG)) == 0 )
  789. {
  790. // first method is special case because user may
  791. // omit space after flag
  792. if ((strArgs[i][3] != '\0')
  793. && (strchr(POTF_FLAG_TOKENS, strArgs[i][3]) == NULL))
  794. {
  795. dwReturn = TextToSecMethod(&strArgs[i][3], IkePol.pOffers[IkePol.dwOfferCount]);
  796. if (!T2P_SUCCESS(dwReturn)) break;
  797. else ++IkePol.dwOfferCount;
  798. }
  799. else if (strArgs[i][3] != '\0')
  800. {
  801. sprintf(STRLASTERR,
  802. "Unexpected flag: %s. Check usage.\n", strArgs[i]);
  803. PARSE_ERROR;
  804. dwReturn = false;
  805. break;
  806. }
  807. ++i; // advance to next arg
  808. while ( (i < uArgCount) && (strchr(POTF_FLAG_TOKENS, strArgs[i][0]) == NULL) )
  809. {
  810. dwReturn = TextToSecMethod(&strArgs[i][0], IkePol.pOffers[IkePol.dwOfferCount]);
  811. if (!T2P_SUCCESS(dwReturn)) goto error_occured;
  812. else ++IkePol.dwOfferCount;
  813. ++i; // advance to next arg
  814. }
  815. }
  816. else if ( strncmp(&strArgs[i][1], POTF_P1PFS_FLAG,
  817. strlen(POTF_P1PFS_FLAG)) == 0 )
  818. {
  819. QMLimit = 1;
  820. bP1RekeyUsed = true; // will fixup all the P1 offers later
  821. ++i;
  822. }
  823. else if ( strncmp(&strArgs[i][1], POTF_SOFTSA_FLAG,
  824. strlen(POTF_SOFTSA_FLAG)) == 0 )
  825. {
  826. IpsPol.dwFlags |= IPSEC_QM_POLICY_ALLOW_SOFT;
  827. if (!IkePol.uSoftSAExpirationTime)
  828. {
  829. // set this time to default
  830. IkePol.uSoftSAExpirationTime = POTF_DEF_P1SOFT_TIME;
  831. }
  832. ++i;
  833. }
  834. else if ( strncmp(&strArgs[i][1], POTF_LAN_FLAG,
  835. strlen(POTF_LAN_FLAG)) == 0 )
  836. {
  837. Interface = INTERFACE_TYPE_LAN;
  838. ++i;
  839. }
  840. else if ( strncmp(&strArgs[i][1], POTF_SOFTSAEXP_FLAG,
  841. strlen(POTF_SOFTSAEXP_FLAG)) == 0 )
  842. {
  843. if (strArgs[i][3] != '\0')
  844. {
  845. // they may have omitted a space
  846. IkePol.uSoftSAExpirationTime = atol(&strArgs[i][3]);
  847. ++i;
  848. }
  849. else
  850. {
  851. ++i;
  852. // process next arg
  853. IkePol.uSoftSAExpirationTime = atol(&strArgs[i][0]);
  854. ++i;
  855. }
  856. }
  857. else if ( strncmp(&strArgs[i][1], POTF_P1REKEY_FLAG,
  858. strlen(POTF_P1REKEY_FLAG)) == 0 )
  859. {
  860. // special case because user may
  861. // omit space after flag
  862. if (strArgs[i][3] != '\0')
  863. {
  864. dwReturn = TextToP1Rekey(&strArgs[i][3], OakLife, QMLimit);
  865. if (!T2P_SUCCESS(dwReturn)) break;
  866. ++i; // advance to next arg
  867. }
  868. else
  869. {
  870. ++i; // advance to next arg
  871. dwReturn = TextToP1Rekey(&strArgs[i][0], OakLife, QMLimit);
  872. if (!T2P_SUCCESS(dwReturn)) break;
  873. ++i; // advance to next arg
  874. }
  875. bP1RekeyUsed = true;
  876. }
  877. else
  878. {
  879. sprintf(STRLASTERR,
  880. "Unknown flag: %s\n", strArgs[i]);
  881. PARSE_ERROR;
  882. dwReturn = POTF_FAILED;
  883. }
  884. } // end if flag
  885. else
  886. {
  887. sprintf(STRLASTERR,
  888. "I don't understand:\n%s\n", strArgs[i]);
  889. PARSE_ERROR;
  890. dwReturn = POTF_FAILED;
  891. }
  892. } // end main processing loop
  893. // now do some post-processing
  894. // either cleanup for errors or fix up policy
  895. if ( bP1RekeyUsed && T2P_SUCCESS(dwReturn) && (IkePol.pOffers == NULL))
  896. {
  897. LoadIkeDefaults(IkePol);
  898. }
  899. // filter post-processing
  900. // apply interface type to transports and interface type + tunnel address to tunnels
  901. if (QMFilterType == QM_TRANSPORT_FILTER)
  902. {
  903. for (i = 0; i < dwNumFilters; i++)
  904. {
  905. RPC_STATUS RpcStat = RPC_S_OK;
  906. pTransportFilters[i].InterfaceType = Interface;
  907. // apply guidNegPolAction so that PASS INPASS and BLOCK take effect here
  908. if (UuidCompare(&(tmpStorageInfo.guidNegPolAction), (UUID *) &GUID_NEGOTIATION_ACTION_INBOUND_PASSTHRU, &RpcStat) == 0 && RpcStat == RPC_S_OK)
  909. {
  910. pTransportFilters[i].InboundFilterFlag = PASS_THRU;
  911. pTransportFilters[i].OutboundFilterFlag = NEGOTIATE_SECURITY;
  912. }
  913. else if (UuidCompare(&(tmpStorageInfo.guidNegPolAction), (UUID *) &GUID_NEGOTIATION_ACTION_BLOCK, &RpcStat) == 0 && RpcStat == RPC_S_OK)
  914. {
  915. pTransportFilters[i].InboundFilterFlag = BLOCKING;
  916. pTransportFilters[i].OutboundFilterFlag = BLOCKING;
  917. }
  918. else if (UuidCompare(&(tmpStorageInfo.guidNegPolAction), (UUID *) &GUID_NEGOTIATION_ACTION_NO_IPSEC, &RpcStat) == 0 && RpcStat == RPC_S_OK)
  919. {
  920. pTransportFilters[i].InboundFilterFlag = PASS_THRU;
  921. pTransportFilters[i].OutboundFilterFlag = PASS_THRU;
  922. }
  923. }
  924. }
  925. else
  926. {
  927. // tunnel filter
  928. for (i = 0; i < dwNumFilters; i++)
  929. {
  930. pTunnelFilters[i].InterfaceType = Interface;
  931. if (SrcTunnelAddr == 0)
  932. {
  933. // SrcTunnelAddr is set to any
  934. pTunnelFilters[i].SrcTunnelAddr.AddrType = IP_ADDR_SUBNET;
  935. pTunnelFilters[i].SrcTunnelAddr.uIpAddr = SUBNET_ADDRESS_ANY;
  936. pTunnelFilters[i].SrcTunnelAddr.uSubNetMask = SUBNET_MASK_ANY;
  937. }
  938. else
  939. {
  940. pTunnelFilters[i].SrcTunnelAddr.AddrType = IP_ADDR_UNIQUE;
  941. pTunnelFilters[i].SrcTunnelAddr.uIpAddr = SrcTunnelAddr;
  942. pTunnelFilters[i].SrcTunnelAddr.uSubNetMask = IP_ADDRESS_MASK_NONE;
  943. }
  944. // DesTunnelAddr is our tunnel address
  945. pTunnelFilters[i].DesTunnelAddr.AddrType = IP_ADDR_UNIQUE;
  946. pTunnelFilters[i].DesTunnelAddr.uIpAddr = DesTunnelAddr;
  947. pTunnelFilters[i].DesTunnelAddr.uSubNetMask = IP_ADDRESS_MASK_NONE;
  948. }
  949. }
  950. // if mainmode filters specified, apply interface type
  951. if (uMMFiltAlloc)
  952. {
  953. for (i = 0; i < dwNumMMFilters; i++)
  954. {
  955. pMMFilters[i].InterfaceType = Interface;
  956. }
  957. }
  958. if (!uMMFiltAlloc)
  959. {
  960. // generate mainmode filters - filter generation also depends on QMFilterType
  961. if (QMFilterType == QM_TRANSPORT_FILTER)
  962. {
  963. // transport
  964. Filter.QMFilterType = QM_TRANSPORT_FILTER;
  965. for (i = 0; i < dwNumFilters; i++)
  966. {
  967. bool bSuccess;
  968. bool bFound;
  969. int j;
  970. memcpy(&Filter.TransportFilter, &pTransportFilters[i], sizeof(TRANSPORT_FILTER));
  971. if (Filter.TransportFilter.OutboundFilterFlag == NEGOTIATE_SECURITY
  972. || Filter.TransportFilter.InboundFilterFlag == NEGOTIATE_SECURITY)
  973. {
  974. bSuccess = GenerateMMFilter(Filter, pMMFilters[dwNumMMFilters]);
  975. assert(bSuccess);
  976. dwNumMMFilters++;
  977. }
  978. }
  979. }
  980. else
  981. {
  982. // tunnel - generate just one filter
  983. bool bSuccess;
  984. Filter.QMFilterType = QM_TUNNEL_FILTER;
  985. memcpy(&Filter.TunnelFilter, &pTunnelFilters[0], sizeof(TUNNEL_FILTER));
  986. bSuccess = GenerateMMFilter(Filter, pMMFilters[0]);
  987. assert(bSuccess);
  988. dwNumMMFilters++;
  989. }
  990. }
  991. error_occured:
  992. if (!T2P_SUCCESS(dwReturn))
  993. {
  994. // error occured, clean up
  995. if (uFiltAlloc)
  996. {
  997. // clean up both transports and tunnels since we allocated both
  998. for (i = 0; i <= uFiltAlloc; i++)
  999. {
  1000. if (pTransportFilters[i].pszFilterName != NULL)
  1001. free(pTransportFilters[i].pszFilterName);
  1002. }
  1003. delete [] pTransportFilters;
  1004. pTransportFilters = NULL;
  1005. // tunnel filter
  1006. for (i = 0; i <= uFiltAlloc; i++)
  1007. {
  1008. if (pTunnelFilters[i].pszFilterName != NULL)
  1009. free(pTunnelFilters[i].pszFilterName);
  1010. }
  1011. delete [] pTunnelFilters;
  1012. pTunnelFilters = NULL;
  1013. dwNumFilters = 0;
  1014. if (!uMMFiltAlloc)
  1015. {
  1016. for (i = 0; i <= uMMFiltAlloc; i++)
  1017. {
  1018. if (pMMFilters[i].pszFilterName != NULL)
  1019. free(pMMFilters[i].pszFilterName);
  1020. }
  1021. delete [] pMMFilters;
  1022. pMMFilters = NULL;
  1023. dwNumMMFilters = 0;
  1024. }
  1025. }
  1026. if (uMMFiltAlloc)
  1027. {
  1028. for (i = 0; i <= uMMFiltAlloc; i++)
  1029. {
  1030. if (pMMFilters[i].pszFilterName != NULL)
  1031. free(pMMFilters[i].pszFilterName);
  1032. }
  1033. delete [] pMMFilters;
  1034. pMMFilters = NULL;
  1035. dwNumMMFilters = 0;
  1036. }
  1037. if (uOfferAlloc)
  1038. {
  1039. delete [] IpsPol.pOffers;
  1040. IpsPol.pOffers = NULL;
  1041. IpsPol.dwOfferCount = 0;
  1042. }
  1043. if (uSecMetAlloc)
  1044. {
  1045. delete [] IkePol.pOffers;
  1046. IkePol.pOffers = NULL;
  1047. IkePol.dwOfferCount = 0;
  1048. }
  1049. }
  1050. else // fix up policy as necessary
  1051. {
  1052. //
  1053. // if storage info requested, copy to caller
  1054. // only copy fields that were indicated, this gets
  1055. // passed in with caller specified items
  1056. //
  1057. if (bStorageMode)
  1058. {
  1059. T2P_FILTER tmpf;
  1060. tmpf.QMFilterType = QMFilterType;
  1061. tmpStorageInfo.FilterList = new IPSEC_FILTER_SPEC[dwNumFilters];
  1062. assert(tmpStorageInfo.FilterList != NULL);
  1063. // convert filters
  1064. for (i = 0; i < dwNumFilters; i++)
  1065. {
  1066. if (tmpf.QMFilterType == QM_TRANSPORT_FILTER)
  1067. {
  1068. memcpy(&(tmpf.TransportFilter), &(pTransportFilters[i]), sizeof(TRANSPORT_FILTER));
  1069. }
  1070. else
  1071. {
  1072. // tunnel
  1073. memcpy(&(tmpf.TunnelFilter), &(pTunnelFilters[i]), sizeof(TUNNEL_FILTER));
  1074. }
  1075. ConvertFilter(tmpf, tmpStorageInfo.FilterList[i]);
  1076. }
  1077. pStorageInfo->Type = tmpStorageInfo.Type;
  1078. if (tmpStorageInfo.szLocationName[0] != '\0')
  1079. wcscpy(pStorageInfo->szLocationName, tmpStorageInfo.szLocationName);
  1080. if (tmpStorageInfo.szPolicyName[0] != '\0')
  1081. wcscpy(pStorageInfo->szPolicyName, tmpStorageInfo.szPolicyName);
  1082. if (tmpStorageInfo.szRuleName[0] != '\0')
  1083. wcscpy(pStorageInfo->szRuleName, tmpStorageInfo.szRuleName);
  1084. if (tmpStorageInfo.tPollingInterval)
  1085. pStorageInfo->tPollingInterval = tmpStorageInfo.tPollingInterval;
  1086. pStorageInfo->guidNegPolAction = tmpStorageInfo.guidNegPolAction;
  1087. pStorageInfo->bSetActive = tmpStorageInfo.bSetActive;
  1088. pStorageInfo->bSetInActive = tmpStorageInfo.bSetInActive;
  1089. pStorageInfo->bDeleteRule = tmpStorageInfo.bDeleteRule;
  1090. pStorageInfo->bDeletePolicy = tmpStorageInfo.bDeletePolicy;
  1091. pStorageInfo->FilterList = tmpStorageInfo.FilterList;
  1092. pStorageInfo->uNumFilters = tmpStorageInfo.uNumFilters;
  1093. }
  1094. // fix up MM policy
  1095. if (bP1RekeyUsed)
  1096. {
  1097. // fix up Ike policy by filling each ike offer
  1098. // with the phase1 rekey
  1099. for (i = 0; i < IkePol.dwOfferCount; ++i)
  1100. {
  1101. IkePol.pOffers[i].Lifetime.uKeyExpirationKBytes = OakLife.uKeyExpirationKBytes;
  1102. IkePol.pOffers[i].Lifetime.uKeyExpirationTime = OakLife.uKeyExpirationTime;
  1103. IkePol.pOffers[i].dwQuickModeLimit = QMLimit;
  1104. }
  1105. }
  1106. else
  1107. {
  1108. // load defaults
  1109. for (i = 0; i < IkePol.dwOfferCount; ++i)
  1110. {
  1111. IkePol.pOffers[i].Lifetime.uKeyExpirationKBytes = 0; // not used
  1112. IkePol.pOffers[i].Lifetime.uKeyExpirationTime = POTF_DEFAULT_P1REKEY_TIME;
  1113. IkePol.pOffers[i].dwQuickModeLimit = POTF_DEFAULT_P1REKEY_QMS;
  1114. }
  1115. }
  1116. // if Kerberos is used, need to set AuthInfo string
  1117. // to dummy since RPC will choke otherwise
  1118. for (i = 0; i < AuthInfos.dwNumAuthInfos; ++i)
  1119. {
  1120. if (AuthInfos.pAuthenticationInfo[i].AuthMethod == IKE_SSPI ||
  1121. (AuthInfos.pAuthenticationInfo[i].AuthMethod == IKE_RSA_SIGNATURE &&
  1122. AuthInfos.pAuthenticationInfo[i].pAuthInfo == NULL)
  1123. )
  1124. {
  1125. AuthInfos.pAuthenticationInfo[i].dwAuthInfoSize = 0;
  1126. AuthInfos.pAuthenticationInfo[i].pAuthInfo = (LPBYTE) new wchar_t[1];
  1127. AuthInfos.pAuthenticationInfo[i].pAuthInfo[0] = UNICODE_NULL;
  1128. }
  1129. }
  1130. }
  1131. } // end if args valid
  1132. else
  1133. {
  1134. fprintf(stderr, "Fatal error occured processing cmd line at line %d\n",
  1135. __LINE__ );
  1136. dwReturn = POTF_FAILED;
  1137. }
  1138. //
  1139. // OK, copy the info to the caller
  1140. //
  1141. memcpy(&IpsecIkePol.IpsPol, &IpsPol, sizeof(IpsPol));
  1142. memcpy(&IpsecIkePol.IkePol, &IkePol, sizeof(IkePol));
  1143. memcpy(&IpsecIkePol.AuthInfos, &AuthInfos, sizeof(AuthInfos));
  1144. IpsecIkePol.pMMFilters = pMMFilters;
  1145. IpsecIkePol.dwNumMMFilters = dwNumMMFilters;
  1146. IpsecIkePol.QMFilterType = QMFilterType;
  1147. IpsecIkePol.dwNumFilters = dwNumFilters;
  1148. IpsecIkePol.pTransportFilters = pTransportFilters;
  1149. IpsecIkePol.pTunnelFilters = pTunnelFilters;
  1150. // done
  1151. return dwReturn;
  1152. }
  1153.