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.

2519 lines
89 KiB

  1. // ImportUI.cpp : Implementation of CImportUI
  2. #include "stdafx.h"
  3. #include "IISUIObj.h"
  4. #include "ImportExportConfig.h"
  5. #include "ExportUI.h"
  6. #include "ImportUI.h"
  7. #include "Defaults.h"
  8. #include "util.h"
  9. #include "ddxv.h"
  10. #include <strsafe.h>
  11. #define HIDD_IISUIOBJ_IMPORT 0x50401
  12. #define LAST_USED_IMPORT_FILE _T("LastImportFile")
  13. LPTSTR GimmiePointerToLastPart(LPCTSTR lpszMDPath)
  14. {
  15. LPTSTR lpszReturn = NULL;
  16. ASSERT_PTR(lpszMDPath);
  17. if (!lpszMDPath || !*lpszMDPath)
  18. {
  19. return NULL;
  20. }
  21. LPCTSTR lp = lpszMDPath + _tcslen(lpszMDPath) - 1;
  22. //
  23. // Skip trailing separator
  24. //
  25. if (*lp == SZ_MBN_SEP_CHAR)
  26. {
  27. --lp;
  28. }
  29. while (*lp && *lp != SZ_MBN_SEP_CHAR)
  30. {
  31. lpszReturn = (LPTSTR) (lp--);
  32. }
  33. return lpszReturn;
  34. }
  35. void InitListView(HWND hList)
  36. {
  37. LV_COLUMN lvCol;
  38. RECT rect;
  39. LONG width;
  40. ZeroMemory(&rect, sizeof(rect));
  41. GetWindowRect(hList, &rect);
  42. width = rect.right - rect.left - 4; // -4 to prevent the horizontal scrollbar from appearing
  43. ZeroMemory(&lvCol, sizeof(lvCol));
  44. lvCol.mask = LVCF_TEXT | LVCF_WIDTH;
  45. lvCol.fmt = LVCFMT_LEFT;
  46. lvCol.cx = width;
  47. ListView_InsertColumn(hList, 0, &lvCol);
  48. return;
  49. }
  50. HRESULT DoImportConfigFromFile(PCONNECTION_INFO pConnectionInfo,BSTR bstrFileNameAndPath,BSTR bstrMetabaseSourcePath,BSTR bstrMetabaseDestinationPath,BSTR bstrPassword,DWORD dwImportFlags)
  51. {
  52. HRESULT hr = E_FAIL;
  53. IMSAdminBase *pIMSAdminBase = NULL;
  54. IMSAdminBase2 *pIMSAdminBase2 = NULL;
  55. LPWSTR lpwstrTempPassword = NULL;
  56. if (!pConnectionInfo)
  57. {
  58. return HRESULT_FROM_WIN32(ERROR_INVALID_PARAMETER);
  59. }
  60. if (pConnectionInfo->pszUserPasswordEncrypted)
  61. {
  62. if (FAILED(DecryptMemoryPassword((LPWSTR) pConnectionInfo->pszUserPasswordEncrypted,&lpwstrTempPassword,pConnectionInfo->cbUserPasswordEncrypted)))
  63. {
  64. return HRESULT_FROM_WIN32(ERROR_DECRYPTION_FAILED);
  65. }
  66. }
  67. CComAuthInfo auth(pConnectionInfo->pszMachineName,pConnectionInfo->pszUserName,lpwstrTempPassword);
  68. if (!bstrFileNameAndPath)
  69. {
  70. return HRESULT_FROM_WIN32(ERROR_INVALID_PARAMETER);
  71. }
  72. // Bufferfer overflow paranoia, make sure it's less than 255 characters long
  73. if (wcslen(bstrFileNameAndPath) > (_MAX_PATH)){return RPC_S_STRING_TOO_LONG;}
  74. if (wcslen(bstrMetabaseSourcePath) > (_MAX_PATH * 3)){return RPC_S_STRING_TOO_LONG;}
  75. if (wcslen(bstrMetabaseDestinationPath) > (_MAX_PATH * 3)){return RPC_S_STRING_TOO_LONG;}
  76. if (bstrPassword)
  77. {
  78. if (wcslen(bstrPassword) > (_MAX_PATH)){return RPC_S_STRING_TOO_LONG;}
  79. }
  80. if(FAILED(hr = CoInitializeEx(NULL, COINIT_MULTITHREADED)))
  81. {
  82. if(FAILED(hr = CoInitializeEx(NULL, COINIT_APARTMENTTHREADED)))
  83. {
  84. return hr;
  85. }
  86. }
  87. // RPC_C_AUTHN_LEVEL_DEFAULT 0
  88. // RPC_C_AUTHN_LEVEL_NONE 1
  89. // RPC_C_AUTHN_LEVEL_CONNECT 2
  90. // RPC_C_AUTHN_LEVEL_CALL 3
  91. // RPC_C_AUTHN_LEVEL_PKT 4
  92. // RPC_C_AUTHN_LEVEL_PKT_INTEGRITY 5
  93. // RPC_C_AUTHN_LEVEL_PKT_PRIVACY 6
  94. COSERVERINFO * pcsiName = auth.CreateServerInfoStruct(RPC_C_AUTHN_LEVEL_DEFAULT);
  95. MULTI_QI res[1] =
  96. {
  97. {&IID_IMSAdminBase, NULL, 0}
  98. };
  99. if (FAILED(hr = CoCreateInstanceEx(CLSID_MSAdminBase,NULL,CLSCTX_ALL,pcsiName,1,res)))
  100. {
  101. goto DoImportConfigFromFile_Exit;
  102. }
  103. pIMSAdminBase = (IMSAdminBase *)res[0].pItf;
  104. if (auth.UsesImpersonation())
  105. {
  106. if (FAILED(hr = auth.ApplyProxyBlanket(pIMSAdminBase)))
  107. {
  108. goto DoImportConfigFromFile_Exit;
  109. }
  110. // There is a remote IUnknown interface that lurks behind IUnknown.
  111. // If that is not set, then the Release call can return access denied.
  112. IUnknown * pUnk = NULL;
  113. hr = pIMSAdminBase->QueryInterface(IID_IUnknown, (void **)&pUnk);
  114. if(FAILED(hr))
  115. {
  116. return hr;
  117. }
  118. if (FAILED(hr = auth.ApplyProxyBlanket(pUnk)))
  119. {
  120. goto DoImportConfigFromFile_Exit;
  121. }
  122. pUnk->Release();pUnk = NULL;
  123. }
  124. if (FAILED(hr = pIMSAdminBase->QueryInterface(IID_IMSAdminBase2, (void **)&pIMSAdminBase2)))
  125. {
  126. goto DoImportConfigFromFile_Exit;
  127. }
  128. if (auth.UsesImpersonation())
  129. {
  130. if (FAILED(hr = auth.ApplyProxyBlanket(pIMSAdminBase2)))
  131. {
  132. goto DoImportConfigFromFile_Exit;
  133. }
  134. }
  135. else
  136. {
  137. // the local call needs min RPC_C_IMP_LEVEL_IMPERSONATE
  138. // for the pIMSAdminBase2 objects Import/Export functions!
  139. if (FAILED(hr = SetBlanket(pIMSAdminBase2)))
  140. {
  141. //goto DoImportConfigFromFile_Exit;
  142. }
  143. }
  144. //#define MD_IMPORT_INHERITED 0x00000001
  145. //#define MD_IMPORT_NODE_ONLY 0x00000002
  146. //#define MD_IMPORT_MERGE 0x00000004
  147. IISDebugOutput(_T("Import:MetabasePathSource=%s,MetabasePathDestination=%s\r\n"),bstrMetabaseSourcePath,bstrMetabaseDestinationPath);
  148. hr = pIMSAdminBase2->Import(bstrPassword,bstrFileNameAndPath,bstrMetabaseSourcePath,bstrMetabaseDestinationPath,dwImportFlags);
  149. DoImportConfigFromFile_Exit:
  150. IISDebugOutput(_T("Import:ret=0x%x\r\n"),hr);
  151. if (lpwstrTempPassword)
  152. {
  153. // security percaution:Make sure to zero out memory that temporary password was used for.
  154. SecureZeroMemory(lpwstrTempPassword,pConnectionInfo->cbUserPasswordEncrypted);
  155. LocalFree(lpwstrTempPassword);
  156. lpwstrTempPassword = NULL;
  157. }
  158. if (pIMSAdminBase2)
  159. {
  160. pIMSAdminBase2->Release();
  161. pIMSAdminBase2 = NULL;
  162. }
  163. if (pIMSAdminBase)
  164. {
  165. pIMSAdminBase->Release();
  166. pIMSAdminBase = NULL;
  167. }
  168. CoUninitialize();
  169. return hr;
  170. }
  171. INT_PTR CALLBACK ShowSiteExistsDlgProc(HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam)
  172. {
  173. switch (msg)
  174. {
  175. case WM_INITDIALOG:
  176. EnableWindow(GetDlgItem(hDlg, IDC_RADIO1), TRUE);
  177. EnableWindow(GetDlgItem(hDlg, IDC_RADIO2), TRUE);
  178. CheckDlgButton(hDlg,IDC_RADIO1,BST_CHECKED);
  179. CheckDlgButton(hDlg,IDC_RADIO2,BST_UNCHECKED);
  180. CenterWindow(GetParent(hDlg), hDlg);
  181. UpdateWindow(hDlg);
  182. break;
  183. case WM_CLOSE:
  184. EndDialog(hDlg, IDCANCEL);
  185. return FALSE;
  186. break;
  187. case WM_COMMAND:
  188. switch (wParam)
  189. {
  190. case IDCANCEL:
  191. EndDialog(hDlg, (int) wParam);
  192. return FALSE;
  193. case IDOK:
  194. if (BST_CHECKED == IsDlgButtonChecked(hDlg,IDC_RADIO1))
  195. {
  196. EndDialog(hDlg, (int) IDC_RADIO1);
  197. }
  198. else if (BST_CHECKED == IsDlgButtonChecked(hDlg,IDC_RADIO2))
  199. {
  200. EndDialog(hDlg, (int) IDC_RADIO2);
  201. }
  202. return TRUE;
  203. }
  204. break;
  205. }
  206. return FALSE;
  207. }
  208. INT_PTR CALLBACK ShowVDirExistsDlgProc(HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam)
  209. {
  210. static LPTSTR szReturnString = NULL;
  211. switch (msg)
  212. {
  213. case WM_INITDIALOG:
  214. szReturnString = (LPTSTR) lParam;
  215. EnableWindow(GetDlgItem(hDlg, IDC_RADIO1), TRUE);
  216. EnableWindow(GetDlgItem(hDlg, IDC_RADIO2), TRUE);
  217. CheckDlgButton(hDlg,IDC_RADIO1,BST_CHECKED);
  218. CheckDlgButton(hDlg,IDC_RADIO2,BST_UNCHECKED);
  219. SendDlgItemMessage(hDlg, IDC_EDIT_NEW_NAME, EM_LIMITTEXT, _MAX_PATH, 0);
  220. EnableWindow(GetDlgItem(hDlg,IDC_EDIT_NEW_NAME), TRUE);
  221. SetDlgItemText(hDlg, IDC_EDIT_NEW_NAME, _T(""));
  222. CenterWindow(GetParent(hDlg), hDlg);
  223. UpdateWindow(hDlg);
  224. break;
  225. case WM_CLOSE:
  226. EndDialog(hDlg, IDCANCEL);
  227. return FALSE;
  228. break;
  229. case WM_COMMAND:
  230. switch(LOWORD(wParam))
  231. {
  232. case IDC_EDIT_NEW_NAME:
  233. {
  234. switch (HIWORD(wParam))
  235. {
  236. case EN_CHANGE:
  237. EditHideBalloon();
  238. // If the contents of the edit control have changed,
  239. if (BST_CHECKED == IsDlgButtonChecked(hDlg,IDC_RADIO1))
  240. {
  241. EnableWindow(GetDlgItem(hDlg, IDOK),(SendMessage(GetDlgItem(hDlg,LOWORD(wParam)),EM_LINELENGTH,(WPARAM) -1, 0) != 0));
  242. }
  243. break;
  244. case EN_MAXTEXT:
  245. case EN_ERRSPACE:
  246. // If the control is out of space, honk
  247. MessageBeep (0);
  248. break;
  249. default:
  250. break;
  251. }
  252. return TRUE;
  253. }
  254. case IDC_RADIO1:
  255. EnableWindow(GetDlgItem(hDlg, IDC_EDIT_NEW_NAME), TRUE);
  256. EnableWindow(GetDlgItem(hDlg, IDOK),(SendMessage(GetDlgItem(hDlg,IDC_EDIT_NEW_NAME),EM_LINELENGTH,(WPARAM) -1, 0) != 0));
  257. SetFocus(GetDlgItem(hDlg, IDC_EDIT_NEW_NAME));
  258. return TRUE;
  259. case IDC_RADIO2:
  260. EnableWindow(GetDlgItem(hDlg, IDC_EDIT_NEW_NAME), FALSE);
  261. EnableWindow(GetDlgItem(hDlg, IDOK),TRUE);
  262. return TRUE;
  263. case IDCANCEL:
  264. EndDialog(hDlg, (int) wParam);
  265. return FALSE;
  266. case IDOK:
  267. TCHAR szEditString[_MAX_PATH + 1];
  268. ZeroMemory(szEditString, sizeof(szEditString));
  269. GetDlgItemText(hDlg, IDC_EDIT_NEW_NAME, szEditString, _MAX_PATH);
  270. // sizeof szReturnString = _MAX_PATH + 1
  271. StringCbCopy(szReturnString,_MAX_PATH + 1, szEditString);
  272. if (BST_CHECKED == IsDlgButtonChecked(hDlg,IDC_RADIO1))
  273. {
  274. EndDialog(hDlg, (int) IDC_RADIO1);
  275. }
  276. else if (BST_CHECKED == IsDlgButtonChecked(hDlg,IDC_RADIO2))
  277. {
  278. EndDialog(hDlg, (int) IDC_RADIO2);
  279. }
  280. return TRUE;
  281. }
  282. break;
  283. }
  284. return FALSE;
  285. }
  286. INT_PTR CALLBACK
  287. ShowAppPoolExistsDlgProc(HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam)
  288. {
  289. static LPTSTR szReturnString = NULL;
  290. switch (msg)
  291. {
  292. case WM_INITDIALOG:
  293. szReturnString = (LPTSTR) lParam;
  294. EnableWindow(GetDlgItem(hDlg, IDC_RADIO1), TRUE);
  295. EnableWindow(GetDlgItem(hDlg, IDC_RADIO2), TRUE);
  296. CheckDlgButton(hDlg,IDC_RADIO1,BST_CHECKED);
  297. CheckDlgButton(hDlg,IDC_RADIO2,BST_UNCHECKED);
  298. SendDlgItemMessage(hDlg, IDC_EDIT_NEW_NAME, EM_LIMITTEXT, _MAX_PATH, 0);
  299. EnableWindow(GetDlgItem(hDlg,IDC_EDIT_NEW_NAME), TRUE);
  300. SetDlgItemText(hDlg, IDC_EDIT_NEW_NAME, _T(""));
  301. CenterWindow(GetParent(hDlg), hDlg);
  302. UpdateWindow(hDlg);
  303. break;
  304. case WM_CLOSE:
  305. EndDialog(hDlg, IDCANCEL);
  306. return FALSE;
  307. break;
  308. case WM_COMMAND:
  309. switch(LOWORD(wParam))
  310. {
  311. case IDC_EDIT_NEW_NAME:
  312. {
  313. switch (HIWORD(wParam))
  314. {
  315. case EN_CHANGE:
  316. EditHideBalloon();
  317. // If the contents of the edit control have changed,
  318. if (BST_CHECKED == IsDlgButtonChecked(hDlg,IDC_RADIO1))
  319. {
  320. EnableWindow(GetDlgItem(hDlg, IDOK),(SendMessage(GetDlgItem(hDlg,LOWORD(wParam)),EM_LINELENGTH,(WPARAM) -1, 0) != 0));
  321. }
  322. break;
  323. case EN_MAXTEXT:
  324. case EN_ERRSPACE:
  325. // If the control is out of space, honk
  326. MessageBeep (0);
  327. break;
  328. default:
  329. break;
  330. }
  331. return TRUE;
  332. }
  333. case IDC_RADIO1:
  334. EnableWindow(GetDlgItem(hDlg, IDC_EDIT_NEW_NAME), TRUE);
  335. EnableWindow(GetDlgItem(hDlg, IDOK),(SendMessage(GetDlgItem(hDlg,IDC_EDIT_NEW_NAME),EM_LINELENGTH,(WPARAM) -1, 0) != 0));
  336. SetFocus(GetDlgItem(hDlg, IDC_EDIT_NEW_NAME));
  337. return TRUE;
  338. case IDC_RADIO2:
  339. EnableWindow(GetDlgItem(hDlg, IDC_EDIT_NEW_NAME), FALSE);
  340. EnableWindow(GetDlgItem(hDlg, IDOK),TRUE);
  341. return TRUE;
  342. case IDCANCEL:
  343. EndDialog(hDlg, (int) wParam);
  344. return FALSE;
  345. case IDOK:
  346. TCHAR szEditString[_MAX_PATH + 1];
  347. ZeroMemory(szEditString, sizeof(szEditString));
  348. if (BST_CHECKED == IsDlgButtonChecked(hDlg,IDC_RADIO1))
  349. {
  350. GetDlgItemText(hDlg, IDC_EDIT_NEW_NAME, szEditString, _MAX_PATH);
  351. // check for invalid entry
  352. TCHAR bad_chars[] = _T("\\/");
  353. if (_tcslen(szEditString) != _tcscspn(szEditString, bad_chars))
  354. {
  355. CString strCaption;
  356. CString strMsg;
  357. strCaption.LoadString(_Module.GetResourceInstance(), IDS_MSGBOX_CAPTION);
  358. strMsg.LoadString(_Module.GetResourceInstance(), IDS_INVALID_ENTRY);
  359. MessageBox(hDlg,strMsg,strCaption,MB_ICONEXCLAMATION | MB_OK);
  360. *szReturnString = 0;
  361. }
  362. else
  363. {
  364. // sizeof szReturnString = _MAX_PATH + 1
  365. StringCbCopy(szReturnString,_MAX_PATH + 1, szEditString);
  366. EndDialog(hDlg, (int) IDC_RADIO1);
  367. }
  368. }
  369. else if (BST_CHECKED == IsDlgButtonChecked(hDlg,IDC_RADIO2))
  370. {
  371. *szReturnString = 0;
  372. EndDialog(hDlg, (int) IDC_RADIO2);
  373. }
  374. }
  375. break;
  376. }
  377. return FALSE;
  378. }
  379. INT_PTR CALLBACK ShowPasswordDlgProc(HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam)
  380. {
  381. static LPTSTR szReturnString = NULL;
  382. switch (msg)
  383. {
  384. case WM_INITDIALOG:
  385. szReturnString = (LPTSTR) lParam;
  386. SendDlgItemMessage(hDlg, IDC_EDIT_GET_PASSWORD, EM_LIMITTEXT, PWLEN, 0);
  387. SendDlgItemMessage(hDlg, IDC_EDIT_GET_PASSWORD, EM_SETPASSWORDCHAR, WPARAM('*'), 0);
  388. EnableWindow(GetDlgItem(hDlg,IDC_EDIT_GET_PASSWORD), TRUE);
  389. SetDlgItemText(hDlg, IDC_EDIT_GET_PASSWORD, _T(""));
  390. UpdateWindow(hDlg);
  391. break;
  392. case WM_CLOSE:
  393. EndDialog(hDlg, IDCANCEL);
  394. return FALSE;
  395. break;
  396. case WM_COMMAND:
  397. switch (wParam)
  398. {
  399. case IDCANCEL:
  400. EndDialog(hDlg,(int)wParam);
  401. return FALSE;
  402. case IDOK:
  403. {
  404. TCHAR szPassword[PWLEN + 1];
  405. SecureZeroMemory(szPassword, sizeof(szPassword));
  406. GetDlgItemText(hDlg, IDC_EDIT_GET_PASSWORD, szPassword, PWLEN);
  407. // sizeof szReturnString = _MAX_PATH + 1
  408. StringCbCopy(szReturnString,_MAX_PATH + 1, szPassword);
  409. // security percaution:Make sure to zero out memory that temporary password was used for.
  410. SecureZeroMemory(szPassword, sizeof(szPassword));
  411. EndDialog(hDlg,(int)wParam);
  412. return TRUE;
  413. }
  414. }
  415. break;
  416. }
  417. return FALSE;
  418. }
  419. HRESULT FillListBoxWithMultiSzData(HWND hList,LPCTSTR szKeyType,WCHAR * pszBuffer)
  420. {
  421. HRESULT hr = E_FAIL;
  422. WCHAR szBuffer[_MAX_PATH + 1];
  423. WCHAR * pszBufferTemp1 = NULL;
  424. WCHAR * pszBufferTemp2 = NULL;
  425. LVITEM ItemIndex;
  426. LV_COLUMN lvcol;
  427. INT iIndex = 0;
  428. DWORD dwCount = 0;
  429. BOOL bMultiSzIsPaired = FALSE;
  430. BOOL bPleaseAddItem = TRUE;
  431. BOOL bPleaseFilterThisSitesList = FALSE;
  432. if (0 == _tcscmp(szKeyType,IIS_CLASS_WEB_SERVER_W) || 0 == _tcscmp(szKeyType,IIS_CLASS_FTP_SERVER_W) )
  433. {
  434. bPleaseFilterThisSitesList = TRUE;
  435. }
  436. pszBufferTemp1 = pszBuffer;
  437. // forget this, it's always paired.
  438. //bMultiSzIsPaired = IsMultiSzPaired(pszBufferTemp1);
  439. bMultiSzIsPaired = TRUE;
  440. // Erase existing data in list box...
  441. ListView_DeleteAllItems(hList);
  442. // Delete all of the columns.
  443. for (int i=0;i <= ListView_GetItemCount(hList);i++)
  444. {ListView_DeleteColumn(hList,i);}
  445. //
  446. // Decide on the column widths
  447. //
  448. RECT rect;
  449. GetClientRect(hList, &rect);
  450. LONG lWidth;
  451. if (dwCount > (DWORD)ListView_GetCountPerPage(hList))
  452. {
  453. lWidth = (rect.right - rect.left) - GetSystemMetrics(SM_CYHSCROLL);
  454. }
  455. else
  456. {
  457. lWidth = rect.right - rect.left;
  458. }
  459. //
  460. // Insert the component name column
  461. //
  462. memset(&lvcol, 0, sizeof(lvcol));
  463. // zero memory
  464. ZeroMemory(szBuffer, sizeof(szBuffer));
  465. lvcol.mask = LVCF_FMT | LVCF_TEXT | LVCF_WIDTH;
  466. lvcol.fmt = LVCFMT_LEFT;
  467. lvcol.pszText = szBuffer;
  468. lvcol.cx = lWidth;
  469. LoadString(_Module.m_hInst, IDS_COL_LOCATION, szBuffer, ARRAYSIZE(szBuffer));
  470. ListView_InsertColumn(hList, 0, &lvcol);
  471. SendMessage(hList, LVM_SETEXTENDEDLISTVIEWSTYLE,(WPARAM) 0, LVS_EX_FULLROWSELECT | LVS_EX_LABELTIP);
  472. if (!pszBufferTemp1)
  473. {
  474. return ERROR_SUCCESS;
  475. }
  476. while (1)
  477. {
  478. if (pszBufferTemp1)
  479. {
  480. hr = ERROR_SUCCESS;
  481. ZeroMemory (&ItemIndex, sizeof(ItemIndex));
  482. if (bMultiSzIsPaired)
  483. {
  484. bPleaseAddItem = TRUE;
  485. // -----------
  486. // paired list
  487. // value1a value1b
  488. // value2a value2b
  489. // ...
  490. // -----------
  491. // make a copy of this baby
  492. pszBufferTemp2 = pszBufferTemp1;
  493. // then increment until we hit another null.
  494. // to get value #2 -- which is the description
  495. while (*pszBufferTemp1)
  496. {
  497. pszBufferTemp1++;
  498. }
  499. // check for the ending \0\0
  500. if ( *(pszBufferTemp1+1) == NULL)
  501. {
  502. break;
  503. }
  504. else
  505. {
  506. pszBufferTemp1++;
  507. }
  508. // Check if pszBufferTemp1 is an empty string
  509. // if it is then display something else.
  510. //IISDebugOutput(_T("key=%s,friendly=%s\r\n"),pszBufferTemp2,pszBufferTemp1);
  511. if (IsSpaces(pszBufferTemp1))
  512. {
  513. ItemIndex.pszText = pszBufferTemp2;
  514. ItemIndex.pszText = GimmiePointerToLastPart(pszBufferTemp2);
  515. }
  516. else
  517. {
  518. ItemIndex.pszText = pszBufferTemp1;
  519. }
  520. if (bPleaseFilterThisSitesList)
  521. {
  522. // Check if it is a true site node -- like
  523. // /LM/W3SVC/1
  524. // /LM/MSFTPSVC/1
  525. // and not /LM/W3SVC/SOMETHINGELSE
  526. //
  527. DWORD dwInstanceNum = CMetabasePath::GetInstanceNumber(pszBufferTemp2);
  528. if (dwInstanceNum == 0 || dwInstanceNum == 0xffffffff)
  529. {
  530. // this is not a valid site path
  531. bPleaseAddItem = FALSE;
  532. }
  533. }
  534. if (bPleaseAddItem)
  535. {
  536. ItemIndex.mask = LVIF_TEXT | LVIF_PARAM;
  537. ItemIndex.iItem = iIndex;
  538. ItemIndex.lParam = (LPARAM) pszBufferTemp2;
  539. iIndex = ListView_InsertItem (hList, &ItemIndex);
  540. }
  541. // then increment until we hit another null.
  542. // to get value #2
  543. while (*pszBufferTemp1)
  544. {
  545. pszBufferTemp1++;
  546. }
  547. // check for the ending \0\0
  548. if ( *(pszBufferTemp1+1) == NULL)
  549. {
  550. break;
  551. }
  552. else
  553. {
  554. pszBufferTemp1++;
  555. }
  556. }
  557. else
  558. {
  559. // -----------
  560. // single list
  561. // value1a
  562. // value2a
  563. // ...
  564. // -----------
  565. ItemIndex.mask = LVIF_TEXT | LVIF_PARAM;
  566. ItemIndex.iItem = iIndex;
  567. ItemIndex.pszText = pszBufferTemp1;
  568. ItemIndex.lParam = (LPARAM) pszBufferTemp1;
  569. iIndex = ListView_InsertItem (hList, &ItemIndex);
  570. // then increment until we hit another null.
  571. // to get value #2
  572. while (*pszBufferTemp1)
  573. {
  574. pszBufferTemp1++;
  575. }
  576. }
  577. // check for the ending \0\0
  578. if ( *(pszBufferTemp1+1) == NULL)
  579. {
  580. break;
  581. }
  582. else
  583. {
  584. pszBufferTemp1++;
  585. }
  586. iIndex++;
  587. }
  588. }
  589. return hr;
  590. }
  591. HRESULT DoEnumDataFromFile(PCONNECTION_INFO pConnectionInfo,BSTR bstrFileNameAndPath,BSTR bstrPathType,WCHAR ** pszMetabaseMultiszList)
  592. {
  593. HRESULT hr = E_FAIL;
  594. IMSAdminBase *pIMSAdminBase = NULL;
  595. IMSImpExpHelp * pIMSImpExpHelp = NULL;
  596. WCHAR * pszBuffer = NULL;
  597. DWORD dwBufferSize = 1;
  598. LPWSTR lpwstrTempPassword = NULL;
  599. if (!pConnectionInfo)
  600. {
  601. return HRESULT_FROM_WIN32(ERROR_INVALID_PARAMETER);
  602. }
  603. if (pConnectionInfo->pszUserPasswordEncrypted)
  604. {
  605. if (FAILED(DecryptMemoryPassword((LPWSTR) pConnectionInfo->pszUserPasswordEncrypted,&lpwstrTempPassword,pConnectionInfo->cbUserPasswordEncrypted)))
  606. {
  607. return HRESULT_FROM_WIN32(ERROR_DECRYPTION_FAILED);
  608. }
  609. }
  610. CComAuthInfo auth(pConnectionInfo->pszMachineName,pConnectionInfo->pszUserName,lpwstrTempPassword);
  611. if (!bstrFileNameAndPath)
  612. {
  613. return HRESULT_FROM_WIN32(ERROR_INVALID_PARAMETER);
  614. }
  615. if (!bstrPathType)
  616. {
  617. return HRESULT_FROM_WIN32(ERROR_INVALID_PARAMETER);
  618. }
  619. // Buffer overflow paranoia, make sure it's less than 255 characters long
  620. if (wcslen(bstrFileNameAndPath) > (_MAX_PATH)){return RPC_S_STRING_TOO_LONG;}
  621. if (wcslen(bstrPathType) > (_MAX_PATH)){return RPC_S_STRING_TOO_LONG;}
  622. if(FAILED(hr = CoInitializeEx(NULL, COINIT_MULTITHREADED)))
  623. {
  624. if(FAILED(hr = CoInitializeEx(NULL, COINIT_APARTMENTTHREADED)))
  625. {
  626. return hr;
  627. }
  628. }
  629. // RPC_C_AUTHN_LEVEL_DEFAULT 0
  630. // RPC_C_AUTHN_LEVEL_NONE 1
  631. // RPC_C_AUTHN_LEVEL_CONNECT 2
  632. // RPC_C_AUTHN_LEVEL_CALL 3
  633. // RPC_C_AUTHN_LEVEL_PKT 4
  634. // RPC_C_AUTHN_LEVEL_PKT_INTEGRITY 5
  635. // RPC_C_AUTHN_LEVEL_PKT_PRIVACY 6
  636. COSERVERINFO * pcsiName = auth.CreateServerInfoStruct(RPC_C_AUTHN_LEVEL_DEFAULT);
  637. MULTI_QI res[1] =
  638. {
  639. {&IID_IMSAdminBase, NULL, 0}
  640. };
  641. if (FAILED(hr = CoCreateInstanceEx(CLSID_MSAdminBase,NULL,CLSCTX_ALL,pcsiName,1,res)))
  642. {
  643. goto DoEnumDataFromFile_Exit;
  644. }
  645. pIMSAdminBase = (IMSAdminBase *)res[0].pItf;
  646. if (auth.UsesImpersonation())
  647. {
  648. if (FAILED(hr = auth.ApplyProxyBlanket(pIMSAdminBase)))
  649. {
  650. goto DoEnumDataFromFile_Exit;
  651. }
  652. // There is a remote IUnknown interface that lurks behind IUnknown.
  653. // If that is not set, then the Release call can return access denied.
  654. IUnknown * pUnk = NULL;
  655. hr = pIMSAdminBase->QueryInterface(IID_IUnknown, (void **)&pUnk);
  656. if(FAILED(hr))
  657. {
  658. return hr;
  659. }
  660. if (FAILED(hr = auth.ApplyProxyBlanket(pUnk)))
  661. {
  662. goto DoEnumDataFromFile_Exit;
  663. }
  664. pUnk->Release();pUnk = NULL;
  665. }
  666. if (FAILED(hr = pIMSAdminBase->QueryInterface(IID_IMSImpExpHelp, (void **)&pIMSImpExpHelp)))
  667. {
  668. goto DoEnumDataFromFile_Exit;
  669. }
  670. if (auth.UsesImpersonation())
  671. {
  672. if (FAILED(hr = auth.ApplyProxyBlanket(pIMSImpExpHelp)))
  673. {
  674. goto DoEnumDataFromFile_Exit;
  675. }
  676. }
  677. else
  678. {
  679. // the local call needs min RPC_C_IMP_LEVEL_IMPERSONATE
  680. // for the pIMSAdminBase2 objects Import/Export functions!
  681. if (FAILED(hr = SetBlanket(pIMSImpExpHelp)))
  682. {
  683. //goto DoEnumDataFromFile_Exit;
  684. }
  685. }
  686. IISDebugOutput(_T("EnumeratePathsInFile:FileName=%s,PathType=%s\r\n"),bstrFileNameAndPath,bstrPathType);
  687. if (FAILED(hr = pIMSImpExpHelp->EnumeratePathsInFile(bstrFileNameAndPath, bstrPathType, dwBufferSize, pszBuffer, &dwBufferSize)))
  688. {
  689. goto DoEnumDataFromFile_Exit;
  690. }
  691. pszBuffer = (WCHAR *) ::CoTaskMemAlloc(dwBufferSize * sizeof(WCHAR));
  692. if (NULL == pszBuffer)
  693. {
  694. hr = E_OUTOFMEMORY;
  695. goto DoEnumDataFromFile_Exit;
  696. }
  697. if (FAILED(hr = pIMSImpExpHelp->EnumeratePathsInFile(bstrFileNameAndPath, bstrPathType, dwBufferSize, pszBuffer, &dwBufferSize)))
  698. {
  699. // free existing amount of space we asked for
  700. if (pszBuffer)
  701. {
  702. ::CoTaskMemFree(pszBuffer);
  703. pszBuffer = NULL;
  704. }
  705. goto DoEnumDataFromFile_Exit;
  706. }
  707. if (!pszBuffer || dwBufferSize <= 0)
  708. {
  709. goto DoEnumDataFromFile_Exit;
  710. }
  711. // see if returned an empty list...
  712. if (0 == _tcscmp(pszBuffer,_T("")))
  713. {
  714. goto DoEnumDataFromFile_Exit;
  715. }
  716. *pszMetabaseMultiszList = pszBuffer;
  717. DoEnumDataFromFile_Exit:
  718. IISDebugOutput(_T("EnumeratePathsInFile:ret=0x%x\r\n"),hr);
  719. if (lpwstrTempPassword)
  720. {
  721. // security percaution:Make sure to zero out memory that temporary password was used for.
  722. SecureZeroMemory(lpwstrTempPassword,pConnectionInfo->cbUserPasswordEncrypted);
  723. LocalFree(lpwstrTempPassword);
  724. lpwstrTempPassword = NULL;
  725. }
  726. if (pIMSImpExpHelp)
  727. {
  728. pIMSImpExpHelp->Release();
  729. pIMSImpExpHelp = NULL;
  730. }
  731. if (pIMSAdminBase)
  732. {
  733. pIMSAdminBase->Release();
  734. pIMSAdminBase = NULL;
  735. }
  736. CoUninitialize();
  737. return hr;
  738. }
  739. void ImportDlgEnableButtons(HWND hDlg,PCOMMONDLGPARAM pcdParams,LPCTSTR lpszCurrentEnumedFileName)
  740. {
  741. BOOL fEnableListControl = FALSE;
  742. BOOL fEnableOK = FALSE;
  743. BOOL fEnableBrowse = FALSE;
  744. BOOL fEnableEnum = FALSE;
  745. TCHAR szFullFileName[_MAX_PATH + 1];
  746. ZeroMemory(szFullFileName, sizeof(szFullFileName));
  747. GetDlgItemText(hDlg, IDC_EDIT_FILE, szFullFileName, _MAX_PATH);
  748. HWND hList = GetDlgItem(hDlg, IDC_LIST_OBJECT);
  749. int ItemIndex = ListView_GetNextItem(hList, -1, LVNI_ALL);
  750. if (ItemIndex < 0)
  751. {
  752. // no items in listview,disable what we need to
  753. fEnableListControl = FALSE;
  754. fEnableOK = FALSE;
  755. }
  756. else
  757. {
  758. fEnableListControl = TRUE;
  759. // Check if something is selected
  760. ItemIndex = ListView_GetNextItem(hList, -1, LVNI_SELECTED);
  761. if (ItemIndex < 0)
  762. {
  763. fEnableOK = FALSE;
  764. }
  765. else
  766. {
  767. fEnableOK = TRUE;
  768. }
  769. }
  770. // Check if we should enable the listcontrol at all...
  771. // see if the filename is the same
  772. if (0 != _tcsicmp(_T(""),lpszCurrentEnumedFileName))
  773. {
  774. // check for % characters
  775. // if there are any, expand them.
  776. LPTSTR pch = _tcschr( (LPTSTR) szFullFileName, _T('%'));
  777. if (pch && pcdParams->ConnectionInfo.IsLocal)
  778. {
  779. TCHAR szValue[_MAX_PATH + 1];
  780. TCHAR szValue2[_MAX_PATH + 1];
  781. StringCbCopy(szValue, sizeof(szValue), szFullFileName);
  782. StringCbCopy(szValue2, sizeof(szValue2), lpszCurrentEnumedFileName);
  783. if (!ExpandEnvironmentStrings( (LPCTSTR)szFullFileName, szValue, sizeof(szValue)/sizeof(TCHAR)))
  784. {StringCbCopy(szValue, sizeof(szValue), szFullFileName);}
  785. if (!ExpandEnvironmentStrings( (LPCTSTR)lpszCurrentEnumedFileName, szValue2, sizeof(szValue2)/sizeof(TCHAR)))
  786. {StringCbCopy(szValue2, sizeof(szValue2), lpszCurrentEnumedFileName);}
  787. if (0 != _tcsicmp(szValue,szValue2))
  788. {
  789. // it's not the same file
  790. // so let's erase and disable the info in the list box.
  791. fEnableListControl = FALSE;
  792. }
  793. }
  794. else
  795. {
  796. if (0 != _tcsicmp(szFullFileName,lpszCurrentEnumedFileName))
  797. {
  798. // it's not the same file
  799. // so let's erase and disable the info in the list box.
  800. fEnableListControl = FALSE;
  801. }
  802. }
  803. }
  804. EnableWindow(hList, fEnableListControl);
  805. if (FALSE == IsWindowEnabled(hList))
  806. {
  807. fEnableOK = FALSE;
  808. }
  809. // Set focus on listbox
  810. //if (fEnableListControl){SetFocus(GetDlgItem(hDlg, IDC_LIST_OBJECT));}
  811. fEnableEnum = (SendMessage(GetDlgItem(hDlg,IDC_EDIT_FILE),EM_LINELENGTH,(WPARAM) -1, 0) != 0);
  812. // no browse button for remote case
  813. if (pcdParams)
  814. {
  815. if (pcdParams->ConnectionInfo.IsLocal)
  816. {fEnableBrowse = TRUE;}
  817. }
  818. // enable enum button
  819. EnableWindow(GetDlgItem(hDlg, IDC_BUTTON_ENUM_FILE),fEnableEnum);
  820. // enable browse button
  821. EnableWindow(GetDlgItem(hDlg,IDC_BUTTON_BROWSE), fEnableBrowse);
  822. // enable OK button
  823. EnableWindow(GetDlgItem(hDlg, IDOK), fEnableOK);
  824. UpdateWindow(hDlg);
  825. }
  826. INT_PTR CALLBACK ShowImportDlgProc(HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam)
  827. {
  828. static PCOMMONDLGPARAM pcdParams;
  829. static TCHAR * pszMetabaseMultiszList = NULL;
  830. static CString strCurrentFileNameEnum;
  831. switch (msg)
  832. {
  833. case WM_INITDIALOG:
  834. pcdParams = (PCOMMONDLGPARAM)lParam;
  835. pszMetabaseMultiszList = NULL;
  836. TCHAR szFullFileName1[_MAX_PATH + 1];
  837. ZeroMemory(szFullFileName1, sizeof(szFullFileName1));
  838. if (DefaultValueSettingsLoad(pcdParams->ConnectionInfo.pszMachineName,LAST_USED_IMPORT_FILE,szFullFileName1))
  839. {
  840. if (0 != _tcscmp(szFullFileName1, _T("")))
  841. {
  842. SetDlgItemText(hDlg, IDC_EDIT_FILE, szFullFileName1);
  843. }
  844. }
  845. strCurrentFileNameEnum = _T("");
  846. InitListView(GetDlgItem(hDlg, IDC_LIST_OBJECT));
  847. CenterWindow(GetParent(hDlg), hDlg);
  848. SetFocus(GetDlgItem(hDlg, IDC_EDIT_FILE));
  849. ImportDlgEnableButtons(hDlg,pcdParams,strCurrentFileNameEnum);
  850. EnableWindow(GetDlgItem(hDlg, IDC_LIST_OBJECT), FALSE);
  851. break;
  852. /*
  853. case WM_ACTIVATE:
  854. if (wParam == 0)
  855. {
  856. }
  857. break;
  858. */
  859. case WM_NOTIFY:
  860. {
  861. if((int)((LPNMHDR)lParam)->idFrom == IDC_LIST_OBJECT)
  862. {
  863. switch (((LPNMHDR)lParam)->code)
  864. {
  865. case LVN_ITEMCHANGED:
  866. ImportDlgEnableButtons(hDlg,pcdParams,strCurrentFileNameEnum);
  867. break;
  868. case NM_CLICK:
  869. ImportDlgEnableButtons(hDlg,pcdParams,strCurrentFileNameEnum);
  870. break;
  871. case NM_DBLCLK:
  872. if((int)((LPNMHDR)lParam)->idFrom == IDC_LIST_OBJECT)
  873. {
  874. PostMessage(hDlg,WM_COMMAND,IDOK,NULL);
  875. }
  876. break;
  877. default:
  878. break;
  879. }
  880. }
  881. return FALSE;
  882. break;
  883. }
  884. case WM_CLOSE:
  885. ListView_DeleteAllItems(GetDlgItem(hDlg, IDC_LIST_OBJECT));
  886. EndDialog(hDlg, IDCANCEL);
  887. return FALSE;
  888. break;
  889. case WM_HELP:
  890. LaunchHelp(hDlg,HIDD_IISUIOBJ_IMPORT);
  891. return TRUE;
  892. break;
  893. case WM_COMMAND:
  894. switch(LOWORD(wParam))
  895. {
  896. case IDC_EDIT_FILE:
  897. {
  898. switch (HIWORD(wParam))
  899. {
  900. case EN_CHANGE:
  901. EditHideBalloon();
  902. {
  903. // If the contents of the edit control have changed,
  904. // check if it's the same as the file that is currently enumed...
  905. HWND hList = GetDlgItem(hDlg, IDC_LIST_OBJECT);
  906. if (ListView_GetItemCount(hList) > 0)
  907. {
  908. TCHAR szFullFileName3[_MAX_PATH + 1];
  909. ZeroMemory(szFullFileName3, sizeof(szFullFileName3));
  910. GetDlgItemText(hDlg, IDC_EDIT_FILE, szFullFileName3, _MAX_PATH);
  911. // see if the filename is the same as this one!
  912. if (!strCurrentFileNameEnum.IsEmpty())
  913. {
  914. if (0 != _tcsicmp(szFullFileName3,strCurrentFileNameEnum))
  915. {
  916. // it's not the same file
  917. // so let's erase and disable the info in the list box.
  918. EnableWindow(hList, FALSE);
  919. }
  920. }
  921. }
  922. ImportDlgEnableButtons(hDlg,pcdParams,strCurrentFileNameEnum);
  923. break;
  924. }
  925. case EN_MAXTEXT:
  926. case EN_ERRSPACE:
  927. // If the control is out of space, honk
  928. MessageBeep (0);
  929. break;
  930. default:
  931. break;
  932. }
  933. return TRUE;
  934. break;
  935. }
  936. case IDC_BUTTON_BROWSE:
  937. {
  938. TCHAR szOldFilePath[_MAX_PATH + 1];
  939. GetDlgItemText(hDlg, IDC_EDIT_FILE, szOldFilePath, _MAX_PATH);
  940. TCHAR szNewFilePath[_MAX_PATH + 1];
  941. ZeroMemory(szNewFilePath, sizeof(szNewFilePath));
  942. if (BrowseForFile(szOldFilePath,szNewFilePath,sizeof(szNewFilePath)))
  943. {
  944. if (0 != _tcsicmp(szNewFilePath, _T("")))
  945. {
  946. SetDlgItemText(hDlg, IDC_EDIT_FILE, szNewFilePath);
  947. UpdateWindow(hDlg);
  948. }
  949. }
  950. ImportDlgEnableButtons(hDlg,pcdParams,strCurrentFileNameEnum);
  951. return FALSE;
  952. break;
  953. }
  954. case IDC_BUTTON_ENUM_FILE:
  955. {
  956. BOOL bThingsAreKool = TRUE;
  957. TCHAR szFullFileName2[_MAX_PATH + 1];
  958. ZeroMemory(szFullFileName2, sizeof(szFullFileName2));
  959. GetDlgItemText(hDlg, IDC_EDIT_FILE, szFullFileName2, _MAX_PATH);
  960. // check for % characters
  961. // if there are any, expand them.
  962. LPTSTR pch = _tcschr( (LPTSTR) szFullFileName2, _T('%'));
  963. if (pch)
  964. {
  965. if (pcdParams->ConnectionInfo.IsLocal)
  966. {
  967. TCHAR szValue[_MAX_PATH + 1];
  968. StringCbCopy(szValue, sizeof(szValue), szFullFileName2);
  969. if (!ExpandEnvironmentStrings( (LPCTSTR)szFullFileName2, szValue, sizeof(szValue)/sizeof(TCHAR)))
  970. {
  971. StringCbCopy(szValue, sizeof(szValue), szFullFileName2);
  972. }
  973. StringCbCopy(szFullFileName2, sizeof(szFullFileName2), szValue);
  974. bThingsAreKool = TRUE;
  975. }
  976. else
  977. {
  978. // we don't support % characters on remote systems.
  979. EditShowBalloon(GetDlgItem(hDlg, IDC_EDIT_FILE),_Module.GetResourceInstance(),IDS_FILENAME_NOREMOTE_EXPAND);
  980. bThingsAreKool = FALSE;
  981. }
  982. }
  983. if (bThingsAreKool)
  984. {
  985. if (pcdParams->ConnectionInfo.IsLocal)
  986. {
  987. if (!IsFileExist(szFullFileName2))
  988. {
  989. bThingsAreKool = FALSE;
  990. EditShowBalloon(GetDlgItem(hDlg, IDC_EDIT_FILE),_Module.GetResourceInstance(),IDS_FILE_NOT_FOUND);
  991. }
  992. }
  993. }
  994. if (bThingsAreKool)
  995. {
  996. TCHAR szNodeType[50];
  997. ZeroMemory(szNodeType, sizeof(szNodeType));
  998. if (pcdParams->pszKeyType)
  999. {
  1000. HRESULT hr = ERROR_SUCCESS;
  1001. StringCbCopy(szNodeType, sizeof(szNodeType), pcdParams->pszKeyType);
  1002. if (0 != _tcsicmp(szNodeType,_T("")))
  1003. {
  1004. HWND hList = GetDlgItem(hDlg, IDC_LIST_OBJECT);
  1005. // Erase existing data in list box...
  1006. ListView_DeleteAllItems(hList);
  1007. // free up the preiously used pointer if we already have memory freed
  1008. if (pszMetabaseMultiszList)
  1009. {
  1010. ::CoTaskMemFree(pszMetabaseMultiszList);
  1011. pszMetabaseMultiszList = NULL;
  1012. }
  1013. if (SUCCEEDED(hr = DoEnumDataFromFile(&pcdParams->ConnectionInfo,szFullFileName2,szNodeType,&pszMetabaseMultiszList)))
  1014. {
  1015. strCurrentFileNameEnum = szFullFileName2;
  1016. if (pszMetabaseMultiszList)
  1017. {
  1018. // filter out stuff we don't want the user to see...
  1019. hr = FillListBoxWithMultiSzData(hList,szNodeType,pszMetabaseMultiszList);
  1020. //DumpStrInMultiStr(pszMetabaseMultiszList);
  1021. if (SUCCEEDED(hr))
  1022. {
  1023. if (0 != _tcscmp(szFullFileName2, _T("")))
  1024. {
  1025. DefaultValueSettingsSave(pcdParams->ConnectionInfo.pszMachineName,LAST_USED_IMPORT_FILE,szFullFileName2);
  1026. }
  1027. }
  1028. }
  1029. else
  1030. {
  1031. // check if there was anything returned...
  1032. // if there was then we got something back
  1033. // which doesn't have the objects we asked for
  1034. CString strMsg;
  1035. CString strFormat;
  1036. CString strObjectType;
  1037. BOOL bFound = FALSE;
  1038. //IIS_CLASS_WEB_SERVER_W
  1039. //IIS_CLASS_FTP_SERVER_W
  1040. //IIS_CLASS_WEB_VDIR_W
  1041. //IIS_CLASS_FTP_VDIR_W
  1042. //IIsApplicationPool
  1043. if (0 == _tcscmp(szNodeType,IIS_CLASS_WEB_SERVER_W))
  1044. {
  1045. strObjectType = IIS_CLASS_WEB_SERVER_W;
  1046. strObjectType.LoadString(_Module.GetResourceInstance(), IDS_STRING_WEB_SERVER);
  1047. bFound = TRUE;
  1048. }
  1049. else if (0 == _tcscmp(szNodeType,IIS_CLASS_FTP_SERVER_W))
  1050. {
  1051. strObjectType = IIS_CLASS_FTP_SERVER_W;
  1052. strObjectType.LoadString(_Module.GetResourceInstance(), IDS_STRING_FTP_SERVER);
  1053. bFound = TRUE;
  1054. }
  1055. else if (0 == _tcscmp(szNodeType,IIS_CLASS_WEB_VDIR_W))
  1056. {
  1057. strObjectType = IIS_CLASS_WEB_VDIR_W;
  1058. strObjectType.LoadString(_Module.GetResourceInstance(), IDS_STRING_WEB_VDIR);
  1059. bFound = TRUE;
  1060. }
  1061. else if (0 == _tcscmp(szNodeType,IIS_CLASS_FTP_VDIR_W))
  1062. {
  1063. strObjectType = IIS_CLASS_FTP_VDIR_W;
  1064. strObjectType.LoadString(_Module.GetResourceInstance(), IDS_STRING_FTP_VDIR);
  1065. bFound = TRUE;
  1066. }
  1067. else if (0 == _tcscmp(szNodeType,_T("IIsApplicationPool")))
  1068. {
  1069. strObjectType = _T("IIsApplicationPool");
  1070. strObjectType.LoadString(_Module.GetResourceInstance(), IDS_STRING_APP_POOL);
  1071. bFound = TRUE;
  1072. }
  1073. if (bFound)
  1074. {
  1075. strFormat.LoadString(_Module.GetResourceInstance(), IDS_IMPORT_MISMATCH);
  1076. strMsg.FormatMessage((LPCTSTR) strFormat,(LPCTSTR) strObjectType,(LPCTSTR) strObjectType,(LPCTSTR) strObjectType);
  1077. EditShowBalloon(GetDlgItem(hDlg, IDC_EDIT_FILE),(LPCTSTR) strMsg);
  1078. }
  1079. }
  1080. }
  1081. else
  1082. {
  1083. if (HRESULTTOWIN32(hr) == ERROR_FILE_NOT_FOUND)
  1084. {
  1085. EditShowBalloon(
  1086. GetDlgItem(hDlg, IDC_EDIT_FILE),
  1087. _Module.GetResourceInstance(),IDS_FILE_NOT_FOUND);
  1088. }
  1089. }
  1090. }
  1091. }
  1092. }
  1093. ImportDlgEnableButtons(hDlg,pcdParams,strCurrentFileNameEnum);
  1094. return FALSE;
  1095. break;
  1096. }
  1097. case IDC_LIST_OBJECT:
  1098. {
  1099. ImportDlgEnableButtons(hDlg,pcdParams,strCurrentFileNameEnum);
  1100. return FALSE;
  1101. break;
  1102. }
  1103. case IDHELP:
  1104. LaunchHelp(hDlg,HIDD_IISUIOBJ_IMPORT);
  1105. return TRUE;
  1106. case IDCANCEL:
  1107. {
  1108. ListView_DeleteAllItems(GetDlgItem(hDlg, IDC_LIST_OBJECT));
  1109. // free up memory we may have allocated...
  1110. if (pszMetabaseMultiszList)
  1111. {
  1112. ::CoTaskMemFree(pszMetabaseMultiszList);
  1113. pszMetabaseMultiszList = NULL;
  1114. }
  1115. EndDialog(hDlg,(int)wParam);
  1116. return FALSE;
  1117. break;
  1118. }
  1119. case IDOK:
  1120. if (TRUE == OnImportOK(hDlg,&pcdParams->ConnectionInfo,pcdParams->pszKeyType,pcdParams->pszMetabasePath,pcdParams->dwImportFlags))
  1121. {
  1122. TCHAR szFullFileName3[_MAX_PATH + 1];
  1123. ZeroMemory(szFullFileName3, sizeof(szFullFileName3));
  1124. GetDlgItemText(hDlg, IDC_EDIT_FILE, szFullFileName3, _MAX_PATH);
  1125. ListView_DeleteAllItems(GetDlgItem(hDlg, IDC_LIST_OBJECT));
  1126. // free up memory we may have allocated...
  1127. if (pszMetabaseMultiszList)
  1128. {
  1129. ::CoTaskMemFree(pszMetabaseMultiszList);
  1130. pszMetabaseMultiszList = NULL;
  1131. }
  1132. return TRUE;
  1133. }
  1134. else
  1135. {
  1136. return FALSE;
  1137. }
  1138. break;
  1139. }
  1140. break;
  1141. }
  1142. return FALSE;
  1143. }
  1144. BOOL OnImportOK(HWND hDlg,PCONNECTION_INFO pConnectionInfo,LPCTSTR szKeyType,LPCTSTR szCurrentMetabasePath,DWORD dwImportFlags)
  1145. {
  1146. BOOL bPleaseProceed = FALSE;
  1147. HRESULT hr = ERROR_SUCCESS;
  1148. INT iReturnedFlag = 0;
  1149. TCHAR szFullFileName[_MAX_PATH + 1];
  1150. TCHAR szNewPassword[PWLEN + 1];
  1151. LPTSTR pszSourcePath = NULL;
  1152. LPTSTR pszDestinationPathMungeAble = NULL;
  1153. DWORD dwDestinationPathMungeAble = 0;
  1154. LPTSTR pszSaveSafeCopy = NULL;
  1155. int ItemIndex = 0;
  1156. LVITEM lviGet;
  1157. memset(&lviGet, 0, sizeof(lviGet));
  1158. // Get the filepath which this tree was created from.
  1159. // could have changed since user edited edit box...
  1160. // so get the one that the tree was created from...
  1161. GetDlgItemText(hDlg, IDC_EDIT_FILE, szFullFileName, _MAX_PATH);
  1162. SecureZeroMemory(szNewPassword, sizeof(szNewPassword));
  1163. if (ListView_GetSelectedCount(GetDlgItem(hDlg, IDC_LIST_OBJECT)) <= 0)
  1164. {
  1165. goto OnImportOK_Exit;
  1166. }
  1167. // Get the metabase path the user selected..
  1168. ItemIndex = ListView_GetNextItem(GetDlgItem(hDlg, IDC_LIST_OBJECT), -1, LVNI_SELECTED);
  1169. if (-1 == ItemIndex)
  1170. {
  1171. goto OnImportOK_Exit;
  1172. }
  1173. ZeroMemory(&lviGet, sizeof(LVITEM));
  1174. lviGet.iItem = ItemIndex;
  1175. lviGet.iSubItem = 0;
  1176. lviGet.mask = LVIF_PARAM;
  1177. lviGet.lParam = NULL;
  1178. if (FALSE == ListView_GetItem(GetDlgItem(hDlg, IDC_LIST_OBJECT), &lviGet))
  1179. {
  1180. goto OnImportOK_Exit;
  1181. }
  1182. if (lviGet.lParam)
  1183. {
  1184. // figure out how big of a buffer do we need...
  1185. int iLen = _tcslen((LPTSTR) lviGet.lParam) + 1;
  1186. pszSourcePath = (LPTSTR) LocalAlloc(LPTR, iLen * sizeof(TCHAR));
  1187. if (!pszSourcePath)
  1188. {
  1189. goto OnImportOK_Exit;
  1190. }
  1191. StringCbCopy(pszSourcePath,(iLen * sizeof(TCHAR)), (WCHAR *) lviGet.lParam);
  1192. dwDestinationPathMungeAble = iLen * sizeof(TCHAR);
  1193. pszDestinationPathMungeAble = (LPTSTR) LocalAlloc(LPTR, dwDestinationPathMungeAble);
  1194. if (!pszDestinationPathMungeAble)
  1195. {
  1196. goto OnImportOK_Exit;
  1197. }
  1198. // make the destination path the same as what we got from the file!
  1199. StringCbCopy(pszDestinationPathMungeAble,dwDestinationPathMungeAble,pszSourcePath);
  1200. }
  1201. // Clean the metabase to work with Import...
  1202. // we have something like this in the list
  1203. // LM/W3SVC/1/ROOT/MyDir
  1204. // -----------------------------------
  1205. // Check to see if the destination path already exists!!!!
  1206. // if it already does, then popup a msg box to get another from the user!
  1207. // -----------------------------------
  1208. do
  1209. {
  1210. iReturnedFlag = 0;
  1211. IISDebugOutput(_T("CleanDestinationPathForVdirs:before:KeyType=%s,CurPath=%s,MetabasePathDestination=%s\r\n"),szKeyType,szCurrentMetabasePath,pszDestinationPathMungeAble);
  1212. if (FAILED(hr = CleanDestinationPathForVdirs(szKeyType,szCurrentMetabasePath,&pszDestinationPathMungeAble,&dwDestinationPathMungeAble)))
  1213. {
  1214. // something failed, let's just stay on this dialog
  1215. bPleaseProceed = FALSE;
  1216. goto OnImportOK_Exit;
  1217. }
  1218. IISDebugOutput(_T("CleanDestinationPathForVdirs:after :KeyType=%s,CurPath=%s,MetabasePathDestination=%s\r\n"),szKeyType,szCurrentMetabasePath,pszDestinationPathMungeAble);
  1219. // allocate the new space
  1220. int cbSafeCopy = (_tcslen(pszDestinationPathMungeAble)+ 1) * sizeof(TCHAR);
  1221. if (pszSaveSafeCopy)
  1222. {LocalFree(pszSaveSafeCopy);pszSaveSafeCopy=NULL;}
  1223. pszSaveSafeCopy = (LPTSTR) LocalAlloc(LPTR, cbSafeCopy);
  1224. if (!pszSaveSafeCopy)
  1225. {
  1226. bPleaseProceed = FALSE;
  1227. goto OnImportOK_Exit;
  1228. }
  1229. // copy the data to the new buffer
  1230. StringCbCopy(pszSaveSafeCopy,cbSafeCopy,pszDestinationPathMungeAble);
  1231. if (FALSE == GetNewDestinationPathIfEntryExists(hDlg,pConnectionInfo,szKeyType,&pszDestinationPathMungeAble,&dwDestinationPathMungeAble,&iReturnedFlag))
  1232. {
  1233. // cancelled, so let's just stay on this dialog
  1234. bPleaseProceed = FALSE;
  1235. goto OnImportOK_Exit;
  1236. }
  1237. else
  1238. {
  1239. if (1 == iReturnedFlag)
  1240. {
  1241. // The destination path already exists and we should overwrite
  1242. // we should overwrite
  1243. // Get the original destination path
  1244. // since it could already have been munged...
  1245. StringCbCopy(pszDestinationPathMungeAble,dwDestinationPathMungeAble,pszSaveSafeCopy);
  1246. break;
  1247. }
  1248. else if (2 == iReturnedFlag)
  1249. {
  1250. // the path didn't already exists so we can write it out now...
  1251. break;
  1252. }
  1253. else
  1254. {
  1255. // we got a new pszDestinationPathMungeAble
  1256. // go thru the loop again.
  1257. }
  1258. }
  1259. } while (TRUE);
  1260. // if we get down here
  1261. // it's because we have a pszDestinationPathMungeAble that we
  1262. // can write to or overwrite...
  1263. // we will never get here is the user cancelled...
  1264. do
  1265. {
  1266. // Perform the action...
  1267. // if it fails then ask for a password...
  1268. if (FAILED(hr = DoImportConfigFromFile(pConnectionInfo,szFullFileName,pszSourcePath,pszDestinationPathMungeAble,szNewPassword,dwImportFlags)))
  1269. {
  1270. // Check if it failed because the site/vdir/app pool already exists...
  1271. // if that's the error, then ask the user for a new path...
  1272. // If it failed because of bad password, then say so
  1273. if (0x8007052B == hr)
  1274. {
  1275. // See if the user wants to try again.
  1276. // if they do, then try it with the new password...
  1277. if (IDCANCEL == DialogBoxParam((HINSTANCE) _Module.m_hInst, MAKEINTRESOURCE(IDD_DIALOG_GET_PASSWORD), hDlg, ShowPasswordDlgProc, (LPARAM) szNewPassword))
  1278. {
  1279. // the user cancelled...
  1280. // so we should just stay on this page...
  1281. // cancelled, so let's just stay on this dialog
  1282. bPleaseProceed = FALSE;
  1283. break;
  1284. }
  1285. else
  1286. {
  1287. // try it again with the new password...
  1288. }
  1289. }
  1290. else if (HRESULTTOWIN32(hr) == ERROR_NO_MATCH)
  1291. {
  1292. bPleaseProceed = FALSE;
  1293. break;
  1294. }
  1295. else
  1296. {
  1297. // if it failed or some reason
  1298. // then get out of loop
  1299. // hr holds the error
  1300. CError err(hr);
  1301. err.MessageBox();
  1302. bPleaseProceed = FALSE;
  1303. break;
  1304. }
  1305. }
  1306. else
  1307. {
  1308. // Succeeded to import the config from the file
  1309. // let's get out
  1310. bPleaseProceed = TRUE;
  1311. ListView_DeleteAllItems(GetDlgItem(hDlg, IDC_LIST_OBJECT));
  1312. //
  1313. // If we imported then, we need to do some fixup....
  1314. //
  1315. // make sure to append on the "root" stuff...
  1316. if (0 == _tcscmp(szKeyType,IIS_CLASS_WEB_SERVER_W))
  1317. {
  1318. // figure out how big of a buffer do we need...
  1319. int iLen = _tcslen((LPTSTR) pszSourcePath) + _tcslen(_T("/ROOT")) + 1;
  1320. LPTSTR pszNewPath = (LPTSTR) LocalAlloc(LPTR, iLen * sizeof(TCHAR));
  1321. if (pszNewPath)
  1322. {
  1323. StringCbCopy(pszNewPath,(iLen * sizeof(TCHAR)), (TCHAR *) pszSourcePath);
  1324. StringCbCat(pszNewPath,(iLen * sizeof(TCHAR)), (TCHAR *) _T("/ROOT"));
  1325. // figure out how big of a buffer do we need...
  1326. iLen = _tcslen((LPTSTR) pszDestinationPathMungeAble) + _tcslen(_T("/ROOT")) + 1;
  1327. LPTSTR pszNewPath2 = (LPTSTR) LocalAlloc(LPTR, iLen * sizeof(TCHAR));
  1328. if (pszNewPath2)
  1329. {
  1330. StringCbCopy(pszNewPath2,(iLen * sizeof(TCHAR)), (TCHAR *) pszDestinationPathMungeAble);
  1331. StringCbCat(pszNewPath2,(iLen * sizeof(TCHAR)), (TCHAR *) _T("/ROOT"));
  1332. hr = FixupImportAppRoot(pConnectionInfo,pszNewPath,pszNewPath2);
  1333. }
  1334. }
  1335. }
  1336. else if (0 == _tcscmp(szKeyType,IIS_CLASS_WEB_VDIR_W))
  1337. {
  1338. hr = FixupImportAppRoot(pConnectionInfo,pszSourcePath,pszDestinationPathMungeAble);
  1339. }
  1340. EndDialog(hDlg, IDOK);
  1341. break;
  1342. }
  1343. } while (FAILED(hr));
  1344. OnImportOK_Exit:
  1345. if (pszSourcePath)
  1346. {
  1347. LocalFree(pszSourcePath);pszSourcePath=NULL;
  1348. }
  1349. if (pszDestinationPathMungeAble)
  1350. {
  1351. LocalFree(pszDestinationPathMungeAble);pszDestinationPathMungeAble=NULL;
  1352. }
  1353. if (pszSaveSafeCopy)
  1354. {
  1355. LocalFree(pszSaveSafeCopy);pszSaveSafeCopy=NULL;
  1356. }
  1357. // make sure this doesn't hang around in memory
  1358. SecureZeroMemory(szNewPassword, sizeof(szNewPassword));
  1359. return bPleaseProceed;
  1360. }
  1361. // IIsWebServer
  1362. // IIsWebVirtualDir
  1363. // IIsFtpServer
  1364. // IIsFtpVirtualDir
  1365. // IIsApplicationPool
  1366. BOOL GetNewDestinationPathIfEntryExists(HWND hDlg,PCONNECTION_INFO pConnectionInfo,LPCTSTR szKeyType,LPTSTR * pszDestinationPathMungeAble,DWORD * pcbDestinationPathMungeAble,INT * iReturnedFlag)
  1367. {
  1368. BOOL bPleaseProceed = FALSE;
  1369. // IF iReturnedFlag = 0 then don't overwrite and don't use the new path
  1370. // IF iReturnedFlag = 1 then overwrite the existing entry
  1371. // IF iReturnedFlag = 2 then use the newly created path
  1372. *iReturnedFlag = 0;
  1373. if (!pConnectionInfo)
  1374. {
  1375. goto GetNewDestinationPathIfEntryExists_Exit;
  1376. }
  1377. BOOL bEntryAlreadyThere = IsMetabaseWebSiteKeyExistAuth(pConnectionInfo,*pszDestinationPathMungeAble);
  1378. if (FALSE == bEntryAlreadyThere)
  1379. {
  1380. bPleaseProceed = TRUE;
  1381. *iReturnedFlag = 2;
  1382. goto GetNewDestinationPathIfEntryExists_Exit;
  1383. }
  1384. // at this point
  1385. // the destination path already exists in the metabase
  1386. // Popup a dialog to get the user to pick a different DestinationPath
  1387. // figure out which one of the dialogs we need to display and get another path from the user...
  1388. if (0 == _tcscmp(szKeyType,IIS_CLASS_WEB_SERVER_W) || 0 == _tcscmp(szKeyType,IIS_CLASS_FTP_SERVER_W) )
  1389. {
  1390. INT_PTR iRet = DialogBox((HINSTANCE) _Module.m_hInst, MAKEINTRESOURCE(IDD_DIALOG_EXISTS_SITE), hDlg, ShowSiteExistsDlgProc);
  1391. switch(iRet)
  1392. {
  1393. case IDCANCEL:
  1394. bPleaseProceed = FALSE;
  1395. *iReturnedFlag = 0;
  1396. break;
  1397. case IDC_RADIO1: // create new site...
  1398. {
  1399. bPleaseProceed = TRUE;
  1400. *iReturnedFlag = 0;
  1401. // Get the new size that we're going to need...
  1402. LPTSTR pNewPointer = NULL;
  1403. INT iNewSize = 0;
  1404. if (0 == _tcscmp(szKeyType,IIS_CLASS_WEB_SERVER_W))
  1405. {
  1406. iNewSize = _tcslen(SZ_MBN_MACHINE SZ_MBN_SEP_STR SZ_MBN_WEB SZ_MBN_SEP_STR) + 10 + 1;
  1407. }
  1408. else
  1409. {
  1410. iNewSize = _tcslen(SZ_MBN_MACHINE SZ_MBN_SEP_STR SZ_MBN_FTP SZ_MBN_SEP_STR) + 10 + 1;
  1411. }
  1412. pNewPointer = (LPTSTR) LocalAlloc(LPTR, iNewSize * sizeof(TCHAR));
  1413. if (!pNewPointer)
  1414. {
  1415. bPleaseProceed = FALSE;
  1416. *iReturnedFlag = 0;
  1417. goto GetNewDestinationPathIfEntryExists_Exit;
  1418. }
  1419. // Generate a new site ID
  1420. if (0 == _tcscmp(szKeyType,IIS_CLASS_WEB_SERVER_W))
  1421. {
  1422. StringCbPrintf(pNewPointer,(iNewSize * sizeof(TCHAR)),SZ_MBN_MACHINE SZ_MBN_SEP_STR SZ_MBN_WEB SZ_MBN_SEP_STR _T("%d"), GetUniqueSite(SZ_MBN_MACHINE SZ_MBN_SEP_STR SZ_MBN_WEB));
  1423. }
  1424. else
  1425. {
  1426. StringCbPrintf(pNewPointer,(iNewSize * sizeof(TCHAR)),SZ_MBN_MACHINE SZ_MBN_SEP_STR SZ_MBN_FTP SZ_MBN_SEP_STR _T("%d"), GetUniqueSite(SZ_MBN_MACHINE SZ_MBN_SEP_STR SZ_MBN_FTP));
  1427. }
  1428. LocalFree((LPTSTR) *pszDestinationPathMungeAble);*pszDestinationPathMungeAble=NULL;
  1429. *pszDestinationPathMungeAble = pNewPointer;
  1430. *pcbDestinationPathMungeAble = (iNewSize * sizeof(TCHAR));
  1431. //IISDebugOutput(_T("Create new site:[%s]\r\n"),*pszDestinationPathMungeAble);
  1432. break;
  1433. }
  1434. case IDC_RADIO2: // replace existing..
  1435. bPleaseProceed = TRUE;
  1436. *iReturnedFlag = 1;
  1437. break;
  1438. default:
  1439. bPleaseProceed = FALSE;
  1440. *iReturnedFlag = 0;
  1441. break;
  1442. }
  1443. }
  1444. else if (0 == _tcscmp(szKeyType,IIS_CLASS_WEB_VDIR_W) || 0 == _tcscmp(szKeyType,IIS_CLASS_FTP_VDIR_W))
  1445. {
  1446. TCHAR szMetabaseVDir[_MAX_PATH + 1];
  1447. ZeroMemory(szMetabaseVDir, sizeof(szMetabaseVDir));
  1448. INT_PTR iRet = DialogBoxParam((HINSTANCE) _Module.m_hInst, MAKEINTRESOURCE(IDD_DIALOG_EXISTS_VDIR), hDlg, ShowVDirExistsDlgProc, (LPARAM) szMetabaseVDir);
  1449. switch(iRet)
  1450. {
  1451. case IDCANCEL:
  1452. bPleaseProceed = FALSE;
  1453. *iReturnedFlag = 0;
  1454. break;
  1455. case IDC_RADIO1: // create new site...
  1456. {
  1457. bPleaseProceed = TRUE;
  1458. *iReturnedFlag = 0;
  1459. // Get VDir Name that the user input on that screeen...
  1460. // Generate a VDir Name
  1461. CString strOriginalDestPath = *pszDestinationPathMungeAble;
  1462. CString strNewPath, strRemainder;
  1463. // Is this the root??
  1464. LPCTSTR lpPath1 = CMetabasePath::GetRootPath(strOriginalDestPath, strNewPath, &strRemainder);
  1465. if (lpPath1)
  1466. {
  1467. // Allocate enough space for the new path...
  1468. LPTSTR pNewPointer = NULL;
  1469. DWORD iNewSize = 0;
  1470. iNewSize = _tcslen(lpPath1) + _tcslen(szMetabaseVDir) + 2;
  1471. pNewPointer = (LPTSTR) LocalAlloc(LPTR, iNewSize * sizeof(TCHAR));
  1472. if (!pNewPointer)
  1473. {
  1474. bPleaseProceed = FALSE;
  1475. *iReturnedFlag = 0;
  1476. goto GetNewDestinationPathIfEntryExists_Exit;
  1477. }
  1478. // if this is the root dir...
  1479. StringCbCopy(pNewPointer,iNewSize * sizeof(TCHAR),lpPath1);
  1480. AddEndingMetabaseSlashIfNeedTo(pNewPointer,iNewSize * sizeof(TCHAR));
  1481. StringCbCat(pNewPointer,iNewSize * sizeof(TCHAR),szMetabaseVDir);
  1482. LocalFree((LPTSTR) *pszDestinationPathMungeAble);*pszDestinationPathMungeAble=NULL;
  1483. *pszDestinationPathMungeAble = pNewPointer;
  1484. *pcbDestinationPathMungeAble = (iNewSize * sizeof(TCHAR));
  1485. //IISDebugOutput(_T("Create new vdir:[%s]\r\n"),*pszDestinationPathMungeAble);
  1486. }
  1487. break;
  1488. }
  1489. case IDC_RADIO2: // replace existing...
  1490. bPleaseProceed = TRUE;
  1491. *iReturnedFlag = 1;
  1492. break;
  1493. default:
  1494. bPleaseProceed = FALSE;
  1495. *iReturnedFlag = 0;
  1496. break;
  1497. }
  1498. }
  1499. else if (0 == _tcscmp(szKeyType,L"IIsApplicationPool"))
  1500. {
  1501. TCHAR szMetabaseAppPool[_MAX_PATH + 1];
  1502. ZeroMemory(szMetabaseAppPool,sizeof(szMetabaseAppPool));
  1503. INT_PTR iRet = DialogBoxParam((HINSTANCE) _Module.m_hInst, MAKEINTRESOURCE(IDD_DIALOG_EXISTS_APP_POOL), hDlg, ShowAppPoolExistsDlgProc, (LPARAM) szMetabaseAppPool);
  1504. switch(iRet)
  1505. {
  1506. case IDCANCEL:
  1507. bPleaseProceed = FALSE;
  1508. *iReturnedFlag = 0;
  1509. break;
  1510. case IDC_RADIO1: // create new site...
  1511. {
  1512. bPleaseProceed = TRUE;
  1513. *iReturnedFlag = 0;
  1514. // Allocate enough space for the new path...
  1515. LPTSTR pNewPointer = NULL;
  1516. INT iNewSize = 0;
  1517. iNewSize = _tcslen(SZ_MBN_MACHINE SZ_MBN_SEP_STR SZ_MBN_WEB SZ_MBN_SEP_STR SZ_MBN_APP_POOLS SZ_MBN_SEP_STR) +
  1518. _tcslen(szMetabaseAppPool) + 1;
  1519. pNewPointer = (LPTSTR) LocalAlloc(LPTR, iNewSize * sizeof(TCHAR));
  1520. if (!pNewPointer)
  1521. {
  1522. bPleaseProceed = FALSE;
  1523. *iReturnedFlag = 0;
  1524. goto GetNewDestinationPathIfEntryExists_Exit;
  1525. }
  1526. // Get The New AppPool Name that the user input on that screeen...
  1527. StringCbPrintf(pNewPointer,(iNewSize * sizeof(TCHAR)),SZ_MBN_MACHINE SZ_MBN_SEP_STR SZ_MBN_WEB SZ_MBN_SEP_STR SZ_MBN_APP_POOLS SZ_MBN_SEP_STR _T("%s"),szMetabaseAppPool);
  1528. LocalFree((LPTSTR) *pszDestinationPathMungeAble);*pszDestinationPathMungeAble=NULL;
  1529. *pszDestinationPathMungeAble = pNewPointer;
  1530. *pcbDestinationPathMungeAble = (iNewSize * sizeof(TCHAR));
  1531. //IISDebugOutput(_T("Create new AppPool:[%s]\r\n"),*pszDestinationPathMungeAble);
  1532. break;
  1533. }
  1534. case IDC_RADIO2: // replace existing...
  1535. bPleaseProceed = TRUE;
  1536. *iReturnedFlag = 1;
  1537. break;
  1538. default:
  1539. bPleaseProceed = FALSE;
  1540. *iReturnedFlag = 0;
  1541. break;
  1542. }
  1543. }
  1544. else
  1545. {
  1546. // nothing matches, get out
  1547. bPleaseProceed = FALSE;
  1548. }
  1549. GetNewDestinationPathIfEntryExists_Exit:
  1550. return bPleaseProceed;
  1551. }
  1552. HRESULT CleanDestinationPathForVdirs(LPCTSTR szKeyType,LPCTSTR szCurrentMetabasePath,LPTSTR * pszDestinationPathMungeMe,DWORD * pcbDestinationPathMungeMe)
  1553. {
  1554. HRESULT hReturn = E_FAIL;
  1555. BOOL bCreateAFirstLevelVdir = FALSE;
  1556. LPTSTR pszLastPart = NULL;
  1557. LPTSTR pszLastPartNew = NULL;
  1558. int iLastPartNewSize = 0;
  1559. INT iChars = 0;
  1560. DWORD cbNewPointer = 0;
  1561. LPTSTR pNewPointer = NULL;
  1562. if (!CleanMetaPath(pszDestinationPathMungeMe,pcbDestinationPathMungeMe))
  1563. {
  1564. hReturn = E_POINTER;
  1565. }
  1566. if (0 == _tcscmp(szKeyType,IIS_CLASS_WEB_SERVER_W) || 0 == _tcscmp(szKeyType,IIS_CLASS_FTP_SERVER_W) )
  1567. {
  1568. hReturn = S_OK;
  1569. }
  1570. else if (0 == _tcscmp(szKeyType,IIS_CLASS_WEB_VDIR_W) || 0 == _tcscmp(szKeyType,IIS_CLASS_FTP_VDIR_W))
  1571. {
  1572. hReturn = E_FAIL;
  1573. // szCurrentMetabasePath probably looks like:
  1574. // lm/w3svc/500/ROOT/CurrentSite
  1575. // lm/w3svc/500/ROOT
  1576. // lm/w3svc/500
  1577. // *pszDestinationPathMungeMe probably looks like:
  1578. // lm/w3svc/23/ROOT/MyOldSite
  1579. // lm/w3svc/23/ROOT
  1580. //
  1581. // make *pszDestinationPathMungeMe look like lm/w3svc/500/ROOT/MyOldSite
  1582. //
  1583. // Get the lm/w3svc/sitenum part of szCurrentMetabasePath
  1584. //
  1585. if (0 == _tcscmp(szKeyType,IIS_CLASS_WEB_VDIR_W))
  1586. {
  1587. //IISDebugOutput(_T("CleanDestinationPathForVdirs:KeyType=%s,CurPath=%s,MetabasePathDestination=%s\r\n"),szKeyType,szCurrentMetabasePath,*pszDestinationPathMungeMe);
  1588. // Get Vdir we want to append...
  1589. // should look like "ROOT/MyVdir"
  1590. CString strSiteNode, strRemainder_WithRoot;
  1591. LPCTSTR lpPath1 = CMetabasePath::TruncatePath(3, *pszDestinationPathMungeMe, strSiteNode, &strRemainder_WithRoot);
  1592. if (lpPath1){}
  1593. if (strRemainder_WithRoot.IsEmpty())
  1594. {
  1595. hReturn = E_INVALIDARG;
  1596. goto CleanDestinationPathForVdirs_Exit;
  1597. }
  1598. if (IsWebSitePath(szCurrentMetabasePath))
  1599. {
  1600. // if our current metabase path is already a site node, then add them together
  1601. // /LM/W3SVC/1 + / + ROOT/MyVdir
  1602. // figure out how much space we need.
  1603. iChars = _tcslen(szCurrentMetabasePath) + _tcslen(strRemainder_WithRoot) + 2; // includes extra slash
  1604. cbNewPointer = iChars * sizeof(TCHAR);
  1605. // allocate the new space
  1606. pNewPointer = NULL;
  1607. pNewPointer = (LPTSTR) LocalAlloc(LPTR, cbNewPointer);
  1608. if (!pNewPointer)
  1609. {
  1610. hReturn = E_OUTOFMEMORY;
  1611. goto CleanDestinationPathForVdirs_Exit;
  1612. }
  1613. // copy the data to the new buffer
  1614. StringCbCopy(pNewPointer,cbNewPointer,szCurrentMetabasePath);
  1615. AddEndingMetabaseSlashIfNeedTo(pNewPointer,cbNewPointer);
  1616. StringCbCat(pNewPointer,cbNewPointer,(LPCTSTR) strRemainder_WithRoot);
  1617. // Free the old one.
  1618. LocalFree(*pszDestinationPathMungeMe);*pszDestinationPathMungeMe=NULL;
  1619. // point to the new buffer
  1620. *pszDestinationPathMungeMe = pNewPointer;
  1621. *pcbDestinationPathMungeMe = cbNewPointer;
  1622. hReturn = S_OK;
  1623. }
  1624. else if (IsWebSiteVDirPath(szCurrentMetabasePath,FALSE))
  1625. {
  1626. // we failed to get farther, just treat it as a new vdir
  1627. bCreateAFirstLevelVdir = TRUE;
  1628. // if our current metabase path is already a vdir/physical path dir...then do some funky magic
  1629. pszLastPart = NULL;
  1630. pszLastPartNew = NULL;
  1631. iLastPartNewSize = 0;
  1632. BOOL bIsRootVdir = IsRootVDir(*pszDestinationPathMungeMe);
  1633. pszLastPart = GimmiePointerToLastPart(*pszDestinationPathMungeMe);
  1634. if (pszLastPart)
  1635. {
  1636. bCreateAFirstLevelVdir = FALSE;
  1637. iLastPartNewSize = _tcslen(pszLastPart) + 1;
  1638. pszLastPartNew = (LPTSTR) LocalAlloc(LPTR, iLastPartNewSize * sizeof(TCHAR));
  1639. if (!pszLastPartNew)
  1640. {
  1641. hReturn = E_OUTOFMEMORY;
  1642. goto CleanDestinationPathForVdirs_Exit;
  1643. }
  1644. StringCbCopy(pszLastPartNew, iLastPartNewSize * sizeof(TCHAR),pszLastPart);
  1645. }
  1646. // check if the site that the user is currently on, is a vdir or physical dir...
  1647. if (bCreateAFirstLevelVdir)
  1648. {
  1649. // /LM/W3SVC/1 + / + ROOT/MyNewVdir
  1650. CString strRemainder_Temp;
  1651. LPCTSTR lpPath2 = CMetabasePath::TruncatePath(3, szCurrentMetabasePath, strSiteNode, &strRemainder_Temp);
  1652. if (lpPath2){}
  1653. if (strSiteNode.IsEmpty())
  1654. {
  1655. hReturn = E_INVALIDARG;
  1656. goto CleanDestinationPathForVdirs_Exit;
  1657. }
  1658. // figure out how much space we need.
  1659. iChars = _tcslen(strSiteNode) + _tcslen(strRemainder_WithRoot) + 2; // includes extra slash
  1660. cbNewPointer = iChars * sizeof(TCHAR);
  1661. // allocate it
  1662. pNewPointer = NULL;
  1663. pNewPointer = (LPTSTR) LocalAlloc(LPTR, cbNewPointer);
  1664. if (!pNewPointer)
  1665. {
  1666. hReturn = E_OUTOFMEMORY;
  1667. goto CleanDestinationPathForVdirs_Exit;
  1668. }
  1669. // Copy to new buffer
  1670. StringCbCopy(pNewPointer,cbNewPointer,strSiteNode);
  1671. AddEndingMetabaseSlashIfNeedTo(pNewPointer,cbNewPointer);
  1672. StringCbCat(pNewPointer,cbNewPointer,(LPCTSTR) strRemainder_WithRoot);
  1673. // Free the old one.
  1674. LocalFree(*pszDestinationPathMungeMe);*pszDestinationPathMungeMe=NULL;
  1675. // point to the new buffer
  1676. *pszDestinationPathMungeMe = pNewPointer;
  1677. *pcbDestinationPathMungeMe = cbNewPointer;
  1678. }
  1679. else
  1680. {
  1681. // /LM/W3SVC/1/ROOT/MyOldVdirThatIwantToKeep + / + MyNewVdir
  1682. // figure out how much space we need.
  1683. iChars = _tcslen(szCurrentMetabasePath) + 2; // includes extra slash
  1684. if (pszLastPartNew)
  1685. {
  1686. iChars = iChars + _tcslen(pszLastPartNew);
  1687. }
  1688. cbNewPointer = iChars * sizeof(TCHAR);
  1689. // allocate the new amt of space
  1690. pNewPointer = NULL;
  1691. pNewPointer = (LPTSTR) LocalAlloc(LPTR, cbNewPointer);
  1692. if (!pNewPointer)
  1693. {
  1694. hReturn = E_OUTOFMEMORY;
  1695. goto CleanDestinationPathForVdirs_Exit;
  1696. }
  1697. // Copy to new buffer
  1698. StringCbCopy(pNewPointer,cbNewPointer,szCurrentMetabasePath);
  1699. if (pszLastPartNew)
  1700. {
  1701. // Don't copy over if the end of this part is root
  1702. // and the part we want to copy over is "root"
  1703. if (!bIsRootVdir)
  1704. {
  1705. AddEndingMetabaseSlashIfNeedTo(pNewPointer,cbNewPointer);
  1706. StringCbCat(pNewPointer,cbNewPointer,pszLastPartNew);
  1707. }
  1708. }
  1709. // Free the old one.
  1710. LocalFree(*pszDestinationPathMungeMe);*pszDestinationPathMungeMe=NULL;
  1711. // point to the new buffer
  1712. *pszDestinationPathMungeMe = pNewPointer;
  1713. *pcbDestinationPathMungeMe = cbNewPointer;
  1714. }
  1715. hReturn = S_OK;
  1716. }
  1717. else
  1718. {
  1719. hReturn = E_INVALIDARG;
  1720. goto CleanDestinationPathForVdirs_Exit;
  1721. }
  1722. }
  1723. else
  1724. {
  1725. // Get Vdir we want to append...
  1726. CString strSiteNode, strRemainder_WithRoot;
  1727. LPCTSTR lpPath3 = CMetabasePath::TruncatePath(3, *pszDestinationPathMungeMe, strSiteNode, &strRemainder_WithRoot);
  1728. if (lpPath3){}
  1729. if (strRemainder_WithRoot.IsEmpty())
  1730. {
  1731. hReturn = E_INVALIDARG;
  1732. goto CleanDestinationPathForVdirs_Exit;
  1733. }
  1734. if (IsFTPSitePath(szCurrentMetabasePath))
  1735. {
  1736. // if our current metabase path is already a site node, then add them together
  1737. // /LM/MSFTPSVC/1 + / + ROOT/MyVdir
  1738. // figure out how much space we need.
  1739. iChars = _tcslen(szCurrentMetabasePath) + _tcslen(strRemainder_WithRoot) + 2;
  1740. cbNewPointer = iChars * sizeof(TCHAR);
  1741. // allocate the new amt of space
  1742. pNewPointer = NULL;
  1743. pNewPointer = (LPTSTR) LocalAlloc(LPTR, cbNewPointer);
  1744. if (!pNewPointer)
  1745. {
  1746. hReturn = E_OUTOFMEMORY;
  1747. goto CleanDestinationPathForVdirs_Exit;
  1748. }
  1749. // Copy to new buffer
  1750. StringCbCopy(pNewPointer,cbNewPointer,szCurrentMetabasePath);
  1751. AddEndingMetabaseSlashIfNeedTo(pNewPointer,cbNewPointer);
  1752. StringCbCat(pNewPointer,cbNewPointer,(LPCTSTR) strRemainder_WithRoot);
  1753. // Free the old one.
  1754. LocalFree(*pszDestinationPathMungeMe);*pszDestinationPathMungeMe=NULL;
  1755. // point to the new buffer
  1756. *pszDestinationPathMungeMe = pNewPointer;
  1757. *pcbDestinationPathMungeMe = cbNewPointer;
  1758. hReturn = S_OK;
  1759. }
  1760. else if (IsFTPSiteVDirPath(szCurrentMetabasePath,FALSE))
  1761. {
  1762. // we failed to get farther, just treat it as a new vdir
  1763. bCreateAFirstLevelVdir = TRUE;
  1764. // if our current metabase path is already a vdir/physical path dir...then do some funky magic
  1765. pszLastPart = NULL;
  1766. pszLastPartNew = NULL;
  1767. iLastPartNewSize = 0;
  1768. BOOL bIsRootVdir = IsRootVDir(*pszDestinationPathMungeMe);
  1769. pszLastPart = GimmiePointerToLastPart(*pszDestinationPathMungeMe);
  1770. if (pszLastPart)
  1771. {
  1772. bCreateAFirstLevelVdir = FALSE;
  1773. iLastPartNewSize = _tcslen(pszLastPart) + 1;
  1774. pszLastPartNew = (LPTSTR) LocalAlloc(LPTR, iLastPartNewSize * sizeof(TCHAR));
  1775. if (!pszLastPartNew)
  1776. {
  1777. hReturn = E_OUTOFMEMORY;
  1778. goto CleanDestinationPathForVdirs_Exit;
  1779. }
  1780. StringCbCopy(pszLastPartNew, iLastPartNewSize * sizeof(TCHAR),pszLastPart);
  1781. }
  1782. // check if the site that the user is currently on, is a vdir or physical dir...
  1783. if (bCreateAFirstLevelVdir)
  1784. {
  1785. CString strRemainder_Temp;
  1786. LPCTSTR lpPath4 = CMetabasePath::TruncatePath(3, szCurrentMetabasePath, strSiteNode, &strRemainder_Temp);
  1787. if (lpPath4){}
  1788. if (strSiteNode.IsEmpty())
  1789. {
  1790. hReturn = E_INVALIDARG;
  1791. goto CleanDestinationPathForVdirs_Exit;
  1792. }
  1793. // figure out how much space we need.
  1794. iChars = _tcslen(szCurrentMetabasePath) + _tcslen(strRemainder_WithRoot) + 2;
  1795. cbNewPointer = iChars * sizeof(TCHAR);
  1796. // allocate the new amt of space
  1797. pNewPointer = NULL;
  1798. pNewPointer = (LPTSTR) LocalAlloc(LPTR, cbNewPointer);
  1799. if (!pNewPointer)
  1800. {
  1801. hReturn = E_OUTOFMEMORY;
  1802. goto CleanDestinationPathForVdirs_Exit;
  1803. }
  1804. // Copy to new buffer
  1805. StringCbCopy(pNewPointer,cbNewPointer,strSiteNode);
  1806. AddEndingMetabaseSlashIfNeedTo(pNewPointer,cbNewPointer);
  1807. StringCbCat(pNewPointer,cbNewPointer,(LPCTSTR) strRemainder_WithRoot);
  1808. // Free the old one.
  1809. LocalFree(*pszDestinationPathMungeMe);*pszDestinationPathMungeMe=NULL;
  1810. // point to the new buffer
  1811. *pszDestinationPathMungeMe = pNewPointer;
  1812. *pcbDestinationPathMungeMe = cbNewPointer;
  1813. }
  1814. else
  1815. {
  1816. // /LM/MSFTPSVC/1/ROOT/MyOldVdirThatIwantToKeep + / + MyNewVdir
  1817. // figure out how much space we need.
  1818. iChars = _tcslen(szCurrentMetabasePath) + 2;
  1819. if (pszLastPartNew)
  1820. {
  1821. iChars = iChars + _tcslen(pszLastPartNew);
  1822. }
  1823. cbNewPointer = iChars * sizeof(TCHAR);
  1824. // allocate the new amt of space
  1825. pNewPointer = NULL;
  1826. pNewPointer = (LPTSTR) LocalAlloc(LPTR, cbNewPointer);
  1827. if (!pNewPointer)
  1828. {
  1829. hReturn = E_OUTOFMEMORY;
  1830. goto CleanDestinationPathForVdirs_Exit;
  1831. }
  1832. // Copy to new buffer
  1833. StringCbCopy(pNewPointer,cbNewPointer,szCurrentMetabasePath);
  1834. if (pszLastPartNew)
  1835. {
  1836. // Don't copy over if the end of this part is root
  1837. // and the part we want to copy over is "root"
  1838. if (!bIsRootVdir)
  1839. {
  1840. AddEndingMetabaseSlashIfNeedTo(pNewPointer,cbNewPointer);
  1841. StringCbCat(pNewPointer,cbNewPointer,pszLastPartNew);
  1842. }
  1843. }
  1844. // Free the old one.
  1845. LocalFree(*pszDestinationPathMungeMe);*pszDestinationPathMungeMe=NULL;
  1846. // point to the new buffer
  1847. *pszDestinationPathMungeMe = pNewPointer;
  1848. *pcbDestinationPathMungeMe = cbNewPointer;
  1849. }
  1850. hReturn = S_OK;
  1851. }
  1852. else
  1853. {
  1854. hReturn = E_INVALIDARG;
  1855. goto CleanDestinationPathForVdirs_Exit;
  1856. }
  1857. }
  1858. }
  1859. else if (0 == _tcscmp(szKeyType,L"IIsApplicationPool"))
  1860. {
  1861. hReturn = S_OK;
  1862. }
  1863. else
  1864. {
  1865. // nothing matches, get out
  1866. hReturn = E_INVALIDARG;
  1867. }
  1868. CleanDestinationPathForVdirs_Exit:
  1869. if (pszLastPartNew)
  1870. {
  1871. LocalFree(pszLastPartNew);pszLastPartNew=NULL;
  1872. }
  1873. return hReturn;
  1874. }
  1875. #define DEFAULT_TIMEOUT_VALUE 30000
  1876. HRESULT FixupImportAppRoot(PCONNECTION_INFO pConnectionInfo,LPCWSTR pszSourcePath,LPCWSTR pszDestPath)
  1877. {
  1878. HRESULT hr = S_OK;
  1879. IMSAdminBase *pIMSAdminBase = NULL;
  1880. IMSAdminBase2 *pIMSAdminBase2 = NULL;
  1881. METADATA_HANDLE hObjHandle = NULL;
  1882. DWORD dwMDMetaID = MD_APP_ROOT;
  1883. DWORD dwBufferSize = 0;
  1884. DWORD dwReqdBufferSize = 0;
  1885. WCHAR *pBuffer = NULL;
  1886. DWORD dwRecBufSize = 0;
  1887. WCHAR *pRecBuf = NULL;
  1888. METADATA_RECORD mdrMDData;
  1889. const WCHAR c_slash = L'/';
  1890. WCHAR *pSourcePath = NULL;
  1891. DWORD dwSLen = 0;
  1892. WCHAR *pFoundStr = NULL;
  1893. WCHAR *pOrigBuffer = NULL;
  1894. WCHAR *pNewAppRoot = NULL;
  1895. BOOL bCoInitCalled = FALSE;
  1896. LPWSTR lpwstrTempPassword = NULL;
  1897. if ((!pszSourcePath)||(!pszDestPath))
  1898. {
  1899. return RETURNCODETOHRESULT(ERROR_INVALID_PARAMETER);
  1900. }
  1901. if (!pConnectionInfo)
  1902. {
  1903. return HRESULT_FROM_WIN32(ERROR_INVALID_PARAMETER);
  1904. }
  1905. if (pConnectionInfo->pszUserPasswordEncrypted)
  1906. {
  1907. if (FAILED(DecryptMemoryPassword((LPWSTR) pConnectionInfo->pszUserPasswordEncrypted,&lpwstrTempPassword,pConnectionInfo->cbUserPasswordEncrypted)))
  1908. {
  1909. return HRESULT_FROM_WIN32(ERROR_DECRYPTION_FAILED);
  1910. }
  1911. }
  1912. CComAuthInfo auth(pConnectionInfo->pszMachineName,pConnectionInfo->pszUserName,lpwstrTempPassword);
  1913. _wcsupr((WCHAR*)pszSourcePath);
  1914. _wcsupr((WCHAR*)pszDestPath);
  1915. // Make sure that pSourcePath has a trailing slash.
  1916. dwSLen = (DWORD)wcslen(pszSourcePath);
  1917. if (c_slash == pszSourcePath[dwSLen - 1])
  1918. {
  1919. pSourcePath = new WCHAR[dwSLen+ 1];
  1920. if (!pSourcePath)
  1921. {
  1922. hr = E_OUTOFMEMORY;
  1923. goto done;
  1924. }
  1925. StringCbCopyW(pSourcePath,((dwSLen+1) * sizeof(WCHAR)), pszSourcePath);
  1926. }
  1927. else
  1928. {
  1929. pSourcePath = new WCHAR[dwSLen + 2];
  1930. if (!pSourcePath)
  1931. {
  1932. hr = E_OUTOFMEMORY;
  1933. goto done;
  1934. }
  1935. StringCbCopyW(pSourcePath,((dwSLen+2) * sizeof(WCHAR)), pszSourcePath);
  1936. pSourcePath[dwSLen] = c_slash;
  1937. pSourcePath[dwSLen+1] = 0;
  1938. }
  1939. if(FAILED(hr = CoInitializeEx(NULL, COINIT_MULTITHREADED)))
  1940. {
  1941. if(FAILED(hr = CoInitializeEx(NULL, COINIT_APARTMENTTHREADED)))
  1942. {
  1943. goto done;
  1944. }
  1945. }
  1946. bCoInitCalled = TRUE;
  1947. // RPC_C_AUTHN_LEVEL_DEFAULT 0
  1948. // RPC_C_AUTHN_LEVEL_NONE 1
  1949. // RPC_C_AUTHN_LEVEL_CONNECT 2
  1950. // RPC_C_AUTHN_LEVEL_CALL 3
  1951. // RPC_C_AUTHN_LEVEL_PKT 4
  1952. // RPC_C_AUTHN_LEVEL_PKT_INTEGRITY 5
  1953. // RPC_C_AUTHN_LEVEL_PKT_PRIVACY 6
  1954. COSERVERINFO * pcsiName = auth.CreateServerInfoStruct(RPC_C_AUTHN_LEVEL_DEFAULT);
  1955. MULTI_QI res[1] =
  1956. {
  1957. {&IID_IMSAdminBase, NULL, 0}
  1958. };
  1959. if (FAILED(hr = CoCreateInstanceEx(CLSID_MSAdminBase,NULL,CLSCTX_ALL,pcsiName,1,res)))
  1960. {
  1961. goto done;
  1962. }
  1963. pIMSAdminBase = (IMSAdminBase *)res[0].pItf;
  1964. if (auth.UsesImpersonation())
  1965. {
  1966. if (FAILED(hr = auth.ApplyProxyBlanket(pIMSAdminBase)))
  1967. {
  1968. goto done;
  1969. }
  1970. // There is a remote IUnknown interface that lurks behind IUnknown.
  1971. // If that is not set, then the Release call can return access denied.
  1972. IUnknown * pUnk = NULL;
  1973. hr = pIMSAdminBase->QueryInterface(IID_IUnknown, (void **)&pUnk);
  1974. if(FAILED(hr))
  1975. {
  1976. goto done;
  1977. }
  1978. if (FAILED(hr = auth.ApplyProxyBlanket(pUnk)))
  1979. {
  1980. goto done;
  1981. }
  1982. pUnk->Release();pUnk = NULL;
  1983. }
  1984. if (FAILED(hr = pIMSAdminBase->QueryInterface(IID_IMSAdminBase2, (void **)&pIMSAdminBase2)))
  1985. {
  1986. goto done;
  1987. }
  1988. if (auth.UsesImpersonation())
  1989. {
  1990. if (FAILED(hr = auth.ApplyProxyBlanket(pIMSAdminBase2)))
  1991. {
  1992. goto done;
  1993. }
  1994. }
  1995. else
  1996. {
  1997. // the local call needs min RPC_C_IMP_LEVEL_IMPERSONATE
  1998. // for the pIMSAdminBase2 objects Import/Export functions!
  1999. if (FAILED(hr = SetBlanket(pIMSAdminBase2)))
  2000. {
  2001. //goto done;
  2002. }
  2003. }
  2004. hr = pIMSAdminBase2->OpenKey( METADATA_MASTER_ROOT_HANDLE,
  2005. (LPWSTR)L"",
  2006. METADATA_PERMISSION_READ | METADATA_PERMISSION_WRITE,
  2007. DEFAULT_TIMEOUT_VALUE,
  2008. &hObjHandle
  2009. );
  2010. if (FAILED(hr))
  2011. {
  2012. goto done;
  2013. }
  2014. hr = pIMSAdminBase2->GetDataPaths(
  2015. hObjHandle,
  2016. pszDestPath,
  2017. dwMDMetaID,
  2018. ALL_METADATA,
  2019. dwBufferSize,
  2020. (LPWSTR)L"",
  2021. &dwReqdBufferSize
  2022. );
  2023. if (FAILED(hr))
  2024. {
  2025. if (hr != HRESULT_FROM_WIN32(ERROR_INSUFFICIENT_BUFFER))
  2026. {
  2027. goto done;
  2028. }
  2029. }
  2030. pBuffer = new WCHAR[dwReqdBufferSize];
  2031. if (!pBuffer)
  2032. {
  2033. hr = E_OUTOFMEMORY;
  2034. goto done;
  2035. }
  2036. dwBufferSize = dwReqdBufferSize;
  2037. hr = pIMSAdminBase2->GetDataPaths(
  2038. hObjHandle,
  2039. pszDestPath,
  2040. dwMDMetaID,
  2041. ALL_METADATA,
  2042. dwBufferSize,
  2043. (LPWSTR)pBuffer,
  2044. &dwReqdBufferSize
  2045. );
  2046. pOrigBuffer = pBuffer;
  2047. if (FAILED(hr))
  2048. {
  2049. goto done;
  2050. }
  2051. // look at AppRoot at each path
  2052. while (*pBuffer)
  2053. {
  2054. // Create the new AppRoot for this record...
  2055. int iNewAppRootLen = wcslen(pBuffer) + 1;
  2056. pNewAppRoot = new WCHAR[iNewAppRootLen];
  2057. if (!pNewAppRoot)
  2058. {
  2059. hr = E_OUTOFMEMORY;
  2060. goto done;
  2061. }
  2062. StringCbCopy(pNewAppRoot,iNewAppRootLen * sizeof(WCHAR),pBuffer);
  2063. _wcsupr((WCHAR*)pNewAppRoot);
  2064. // make sure it doesn't end with a slash...
  2065. if (_T('/') == pNewAppRoot[iNewAppRootLen - 2])
  2066. {
  2067. // cut if off if it's there
  2068. pNewAppRoot[iNewAppRootLen - 2] = '\0';
  2069. }
  2070. MD_SET_DATA_RECORD(&mdrMDData,
  2071. dwMDMetaID,
  2072. METADATA_INHERIT,
  2073. IIS_MD_UT_FILE,
  2074. STRING_METADATA,
  2075. dwRecBufSize,
  2076. pRecBuf);
  2077. hr = pIMSAdminBase2->GetData(
  2078. hObjHandle,
  2079. pBuffer,
  2080. &mdrMDData,
  2081. &dwRecBufSize
  2082. );
  2083. if (FAILED(hr))
  2084. {
  2085. if (hr != HRESULT_FROM_WIN32(ERROR_INSUFFICIENT_BUFFER))
  2086. {
  2087. goto done;
  2088. }
  2089. }
  2090. pRecBuf = new WCHAR[dwRecBufSize + 1]; // for extra slash if we need it
  2091. if (!pRecBuf)
  2092. {
  2093. hr = E_OUTOFMEMORY;
  2094. goto done;
  2095. }
  2096. MD_SET_DATA_RECORD(&mdrMDData,
  2097. dwMDMetaID,
  2098. METADATA_INHERIT,
  2099. IIS_MD_UT_FILE,
  2100. STRING_METADATA,
  2101. dwRecBufSize,
  2102. pRecBuf);
  2103. hr = pIMSAdminBase2->GetData(
  2104. hObjHandle,
  2105. pBuffer,
  2106. &mdrMDData,
  2107. &dwRecBufSize
  2108. );
  2109. if (FAILED(hr))
  2110. {
  2111. goto done;
  2112. }
  2113. _wcsupr(pRecBuf);
  2114. // Make sure that pRecBuf has a trailing slash.
  2115. dwSLen = (DWORD)wcslen(pRecBuf);
  2116. if (c_slash != pRecBuf[dwSLen - 1])
  2117. {
  2118. pRecBuf[dwSLen] = c_slash;
  2119. pRecBuf[dwSLen+1] = 0;
  2120. }
  2121. pFoundStr = wcsstr(pRecBuf,pSourcePath);
  2122. if (pFoundStr)
  2123. {
  2124. if (pNewAppRoot)
  2125. {
  2126. // now set the new AppRoot
  2127. MD_SET_DATA_RECORD(&mdrMDData,
  2128. dwMDMetaID,
  2129. METADATA_INHERIT,
  2130. IIS_MD_UT_FILE,
  2131. STRING_METADATA,
  2132. (DWORD)((wcslen(pNewAppRoot)+1)*sizeof(WCHAR)),
  2133. (PBYTE)pNewAppRoot);
  2134. hr = pIMSAdminBase2->SetData(
  2135. hObjHandle,
  2136. pBuffer,
  2137. &mdrMDData
  2138. );
  2139. IISDebugOutput(_T("FixupImportAppRoot:NewAppRoot=%s\r\n"),(LPCTSTR) pNewAppRoot);
  2140. }
  2141. else
  2142. {
  2143. hr = E_OUTOFMEMORY;
  2144. }
  2145. if (FAILED(hr))
  2146. {
  2147. goto done;
  2148. }
  2149. if (pNewAppRoot)
  2150. {
  2151. delete[] pNewAppRoot;
  2152. pNewAppRoot = NULL;
  2153. }
  2154. }
  2155. if (pRecBuf)
  2156. {
  2157. delete [] pRecBuf;
  2158. pRecBuf = NULL;
  2159. }
  2160. pBuffer += wcslen(pBuffer) + 1;
  2161. }
  2162. done:
  2163. if (lpwstrTempPassword)
  2164. {
  2165. // security percaution:Make sure to zero out memory that temporary password was used for.
  2166. SecureZeroMemory(lpwstrTempPassword,pConnectionInfo->cbUserPasswordEncrypted);
  2167. LocalFree(lpwstrTempPassword);
  2168. lpwstrTempPassword = NULL;
  2169. }
  2170. if (hObjHandle)
  2171. {
  2172. pIMSAdminBase2->CloseKey(hObjHandle);
  2173. }
  2174. if (pIMSAdminBase2)
  2175. {
  2176. pIMSAdminBase2->Release();
  2177. pIMSAdminBase2 = NULL;
  2178. }
  2179. if (pIMSAdminBase)
  2180. {
  2181. pIMSAdminBase->Release();
  2182. pIMSAdminBase = NULL;
  2183. }
  2184. if (pRecBuf)
  2185. {
  2186. delete[] pRecBuf;
  2187. pRecBuf = NULL;
  2188. }
  2189. if (pNewAppRoot)
  2190. {
  2191. delete[] pNewAppRoot;
  2192. pNewAppRoot = NULL;
  2193. }
  2194. if (pOrigBuffer)
  2195. {
  2196. // pOrigBuffer is pBuffer before we moved through it.
  2197. delete pOrigBuffer;
  2198. pOrigBuffer = NULL;
  2199. pBuffer = NULL;
  2200. }
  2201. if (pSourcePath)
  2202. {
  2203. delete[] pSourcePath;
  2204. pSourcePath = NULL;
  2205. }
  2206. if (bCoInitCalled)
  2207. {
  2208. CoUninitialize();
  2209. }
  2210. return hr;
  2211. }