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.

629 lines
26 KiB

  1. // ExportUI.cpp : Implementation of CExportUI
  2. //#include "stdafx.h"
  3. //#include "ExportUI.h"
  4. #include "stdafx.h"
  5. #include "IISUIObj.h"
  6. #include "ImportExportConfig.h"
  7. #include "ExportUI.h"
  8. #include "ImportUI.h"
  9. #include "defaults.h"
  10. #include "util.h"
  11. #include "ddxv.h"
  12. #include <strsafe.h>
  13. #define HIDD_IISUIOBJ_EXPORT 0x50402
  14. #define LAST_USED_EXPORT_PATH _T("LastExportPath")
  15. void SetControlStates(HWND hDlg, UINT msg, WPARAM wParam, PCOMMONDLGPARAM pcdParams)
  16. {
  17. BOOL bEnAbleOk = FALSE;
  18. BOOL bEnAbleBrowse = FALSE;
  19. BOOL bAllPasswordsFilled = TRUE;
  20. BOOL bFileNameFilled = FALSE;
  21. BOOL bFilePathFilled = FALSE;
  22. BOOL bUsingPassword = (BST_CHECKED == IsDlgButtonChecked(hDlg, IDC_CHECK_ENCRYPT));
  23. if (bUsingPassword)
  24. {
  25. bAllPasswordsFilled = FALSE;
  26. // check to see if we want to enable okay button
  27. if (SendMessage(GetDlgItem(hDlg,IDC_EDIT_PASSWORD1),EM_LINELENGTH,(WPARAM) -1, 0))
  28. {
  29. if (SendMessage(GetDlgItem(hDlg,IDC_EDIT_PASSWORD2),EM_LINELENGTH,(WPARAM) -1, 0))
  30. {
  31. bAllPasswordsFilled = TRUE;
  32. }
  33. }
  34. }
  35. if (SendMessage(GetDlgItem(hDlg,IDC_EDIT_FILENAME),EM_LINELENGTH,(WPARAM) -1, 0))
  36. {
  37. bFileNameFilled = TRUE;
  38. }
  39. if (SendMessage(GetDlgItem(hDlg,IDC_EDIT_PATH),EM_LINELENGTH,(WPARAM) -1, 0))
  40. {
  41. bFilePathFilled = TRUE;
  42. }
  43. if (bFileNameFilled && bFilePathFilled && bAllPasswordsFilled)
  44. {
  45. bEnAbleOk = TRUE;
  46. }
  47. // no browse button for remote case
  48. if (pcdParams)
  49. {
  50. if (pcdParams->ConnectionInfo.IsLocal)
  51. {
  52. bEnAbleBrowse = TRUE;
  53. }
  54. }
  55. EnableWindow(GetDlgItem(hDlg,IDOK), bEnAbleOk);
  56. EnableWindow(GetDlgItem(hDlg,IDC_BUTTON_BROWSE), bEnAbleBrowse);
  57. UpdateWindow(hDlg);
  58. return;
  59. }
  60. INT_PTR CALLBACK ShowExportDlgProc(HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam)
  61. {
  62. static PCOMMONDLGPARAM pcdParams;
  63. switch (msg)
  64. {
  65. case WM_INITDIALOG:
  66. {
  67. TCHAR szPathToInetsrv[_MAX_PATH];
  68. pcdParams = (PCOMMONDLGPARAM)lParam;
  69. if (!pcdParams->pszMetabasePath)
  70. {
  71. EnableWindow(GetDlgItem(hDlg,IDOK), FALSE);
  72. SetLastError(ERROR_INVALID_PARAMETER);
  73. return FALSE;
  74. }
  75. SendDlgItemMessage(hDlg, IDC_EDIT_FILENAME, EM_LIMITTEXT, _MAX_PATH, 0);
  76. SendDlgItemMessage(hDlg, IDC_EDIT_PATH, EM_LIMITTEXT, _MAX_PATH, 0);
  77. SendDlgItemMessage(hDlg, IDC_EDIT_PASSWORD1, EM_LIMITTEXT, PWLEN, 0);
  78. SendDlgItemMessage(hDlg, IDC_EDIT_PASSWORD2, EM_LIMITTEXT, PWLEN, 0);
  79. // Default it with some default values...
  80. // Fill a Default filename...
  81. SetDlgItemText(hDlg, IDC_EDIT_FILENAME, _T(""));
  82. // Fill a default filepath...
  83. SetDlgItemText(hDlg, IDC_EDIT_PATH, _T(""));
  84. if (DefaultValueSettingsLoad((LPCTSTR) pcdParams->ConnectionInfo.pszMachineName,LAST_USED_EXPORT_PATH,szPathToInetsrv))
  85. {
  86. if (0 != _tcscmp(szPathToInetsrv, _T("")))
  87. {
  88. SetDlgItemText(hDlg, IDC_EDIT_PATH, szPathToInetsrv);
  89. }
  90. else
  91. {
  92. if (GetInetsrvPath(pcdParams->ConnectionInfo.pszMachineName,szPathToInetsrv,sizeof(szPathToInetsrv)))
  93. {
  94. SetDlgItemText(hDlg, IDC_EDIT_PATH, szPathToInetsrv);
  95. }
  96. }
  97. }
  98. else
  99. {
  100. if (pcdParams->ConnectionInfo.IsLocal)
  101. {
  102. if (GetInetsrvPath(pcdParams->ConnectionInfo.pszMachineName,szPathToInetsrv,sizeof(szPathToInetsrv)))
  103. {
  104. SetDlgItemText(hDlg, IDC_EDIT_PATH, szPathToInetsrv);
  105. }
  106. }
  107. else
  108. {
  109. // forget remote case, since GetInetsrvPath may hang for this reason...
  110. }
  111. }
  112. // Set encryption using password to unchecked.
  113. SendDlgItemMessage(hDlg, IDC_CHECK_ENCRYPT, BM_SETCHECK, BST_UNCHECKED, 0L);
  114. // Set encryption password1 to blank
  115. // make sure it's disabled...
  116. SendDlgItemMessage(hDlg, IDC_EDIT_PASSWORD1, EM_SETPASSWORDCHAR, WPARAM('*'), 0);
  117. EnableWindow(GetDlgItem(hDlg,IDC_EDIT_PASSWORD1), FALSE);
  118. SetDlgItemText(hDlg, IDC_EDIT_PASSWORD1, _T(""));
  119. // Set encryption password2 to blank
  120. // make sure it's disabled...
  121. SendDlgItemMessage(hDlg, IDC_EDIT_PASSWORD2, EM_SETPASSWORDCHAR, WPARAM('*'), 0);
  122. EnableWindow(GetDlgItem(hDlg,IDC_EDIT_PASSWORD2), FALSE);
  123. SetDlgItemText(hDlg, IDC_EDIT_PASSWORD2, _T(""));
  124. EnableWindow(GetDlgItem(hDlg,IDC_STATIC_PASSWORD1), FALSE);
  125. EnableWindow(GetDlgItem(hDlg,IDC_STATIC_PASSWORD2), FALSE);
  126. CenterWindow(GetForegroundWindow(), hDlg);
  127. SetFocus(GetDlgItem(hDlg, IDC_EDIT_FILENAME));
  128. SetControlStates(hDlg,msg,wParam,pcdParams);
  129. break;
  130. }
  131. case WM_NOTIFY:
  132. break;
  133. case WM_CLOSE:
  134. EndDialog(hDlg, IDCANCEL);
  135. return FALSE;
  136. break;
  137. case WM_HELP:
  138. LaunchHelp(hDlg,HIDD_IISUIOBJ_EXPORT);
  139. return TRUE;
  140. break;
  141. case WM_COMMAND:
  142. switch(LOWORD(wParam))
  143. {
  144. case IDC_BUTTON_BROWSE:
  145. {
  146. CString strTitle;
  147. strTitle.LoadString(_Module.GetResourceInstance(), IDS_BROWSE_SELECT_FOLDER);
  148. UINT ulFlags=BIF_NEWDIALOGSTYLE |
  149. BIF_RETURNONLYFSDIRS |
  150. BIF_RETURNFSANCESTORS |
  151. //BIF_STATUSTEXT |
  152. //BIF_DONTGOBELOWDOMAIN |
  153. BIF_BROWSEFORCOMPUTER |
  154. BIF_SHAREABLE |
  155. //BIF_BROWSEINCLUDEFILES |
  156. //BIF_USENEWUI |
  157. BIF_UAHINT |
  158. BIF_VALIDATE;
  159. CFolderDialog dlg(hDlg,strTitle,ulFlags);
  160. if (IDOK == dlg.DoModal())
  161. {
  162. // update the dialog box
  163. if (0 != _tcsicmp(dlg.GetFolderPath(), _T("")))
  164. {
  165. SetDlgItemText(hDlg, IDC_EDIT_PATH, dlg.GetFolderPath());
  166. UpdateWindow(hDlg);
  167. }
  168. }
  169. return FALSE;
  170. }
  171. case IDC_EDIT_FILENAME:
  172. {
  173. switch (HIWORD(wParam))
  174. {
  175. case EN_CHANGE:
  176. EditHideBalloon();
  177. // If the contents of the edit control have changed,
  178. SetControlStates(hDlg,msg,wParam,pcdParams);
  179. break;
  180. case EN_MAXTEXT:
  181. case EN_ERRSPACE:
  182. // If the control is out of space, honk
  183. MessageBeep (0);
  184. break;
  185. default:
  186. break;
  187. }
  188. return FALSE;
  189. }
  190. case IDC_EDIT_PASSWORD1:
  191. {
  192. switch (HIWORD(wParam))
  193. {
  194. case EN_CHANGE:
  195. EditHideBalloon();
  196. SetControlStates(hDlg,msg,wParam,pcdParams);
  197. break;
  198. case EN_MAXTEXT:
  199. case EN_ERRSPACE:
  200. // If the control is out of space, honk
  201. MessageBeep (0);
  202. break;
  203. default:
  204. break;
  205. }
  206. return FALSE;
  207. }
  208. case IDC_EDIT_PASSWORD2:
  209. {
  210. switch (HIWORD(wParam))
  211. {
  212. case EN_CHANGE:
  213. EditHideBalloon();
  214. SetControlStates(hDlg,msg,wParam,pcdParams);
  215. break;
  216. case EN_MAXTEXT:
  217. case EN_ERRSPACE:
  218. // If the control is out of space, honk
  219. MessageBeep (0);
  220. break;
  221. default:
  222. break;
  223. }
  224. return FALSE;
  225. }
  226. case IDC_EDIT_PATH:
  227. {
  228. switch (HIWORD(wParam))
  229. {
  230. case EN_CHANGE:
  231. EditHideBalloon();
  232. // If the contents of the edit control have changed,
  233. SetControlStates(hDlg,msg,wParam,pcdParams);
  234. break;
  235. case EN_MAXTEXT:
  236. case EN_ERRSPACE:
  237. // If the control is out of space, honk
  238. MessageBeep (0);
  239. break;
  240. default:
  241. break;
  242. }
  243. return FALSE;
  244. }
  245. case IDHELP:
  246. LaunchHelp(hDlg,HIDD_IISUIOBJ_EXPORT);
  247. return TRUE;
  248. case IDCANCEL:
  249. {
  250. EndDialog(hDlg, (int)wParam);
  251. return FALSE;
  252. }
  253. case IDOK:
  254. {
  255. HRESULT hr = ERROR_SUCCESS;
  256. TCHAR szFullFileName[_MAX_PATH + 1];
  257. TCHAR szFileName[_MAX_PATH + 1];
  258. TCHAR szNoSpaces[_MAX_PATH + 1];
  259. ZeroMemory(szFullFileName, sizeof(szFullFileName));
  260. ZeroMemory(szFileName, sizeof(szFileName));
  261. GetDlgItemText(hDlg, IDC_EDIT_FILENAME, szFileName, _MAX_PATH);
  262. GetDlgItemText(hDlg, IDC_EDIT_PATH, szFullFileName, _MAX_PATH);
  263. CString strDefaultExt;
  264. strDefaultExt.LoadString(_Module.GetResourceInstance(), IDS_DEFAULT_SAVED_EXT);
  265. RemoveSpaces(szNoSpaces, sizeof(szNoSpaces), szFileName);
  266. StringCbCopy(szNoSpaces, sizeof(szNoSpaces), szFileName);
  267. RemoveSpaces(szNoSpaces, sizeof(szNoSpaces), szFullFileName);
  268. StringCbCopy(szFullFileName, sizeof(szFullFileName), szNoSpaces);
  269. if (IsSpaces(szFileName))
  270. {
  271. // There was no filename specified.
  272. EditShowBalloon(GetDlgItem(hDlg, IDC_EDIT_FILENAME),_Module.GetResourceInstance(),IDS_FILENAME_MISSING);
  273. }
  274. else if (0 == _tcsicmp(szFullFileName,_T("")))
  275. {
  276. // There was no filename specified.
  277. EditShowBalloon(GetDlgItem(hDlg, IDC_EDIT_FILENAME),_Module.GetResourceInstance(),IDS_FILENAME_MISSING);
  278. }
  279. else
  280. {
  281. // check for % characters
  282. // if there are any, expand them.
  283. LPTSTR pch = _tcschr( (LPTSTR) szFullFileName, _T('%'));
  284. if (pch)
  285. {
  286. if (pcdParams->ConnectionInfo.IsLocal)
  287. {
  288. if (pch)
  289. {
  290. TCHAR szValue[_MAX_PATH + 1];
  291. StringCbCopy(szValue, sizeof(szValue), szFullFileName);
  292. if (!ExpandEnvironmentStrings( (LPCTSTR)szFullFileName, szValue, sizeof(szValue)/sizeof(TCHAR)))
  293. {
  294. StringCbCopy(szValue, sizeof(szValue), szFullFileName);
  295. }
  296. StringCbCopy(szFullFileName, sizeof(szFullFileName), szValue);
  297. }
  298. }
  299. else
  300. {
  301. // we don't support % characters on remote systems.
  302. EditShowBalloon(GetDlgItem(hDlg, IDC_EDIT_PATH),_Module.GetResourceInstance(),IDS_FILENAME_NOREMOTE_EXPAND);
  303. return FALSE;
  304. }
  305. }
  306. // Check if valid folderpath
  307. if (!IsValidFolderPath(GetDlgItem(hDlg, IDC_EDIT_PATH),szFullFileName,TRUE))
  308. {
  309. return FALSE;
  310. }
  311. AddPath(szFullFileName,sizeof(szFullFileName),szFileName);
  312. // Check if file has an extension.
  313. // if there is none, then add the .xml extention.
  314. AddFileExtIfNotExist(szFullFileName,sizeof(szFullFileName),strDefaultExt);
  315. if (!IsValidName(szFileName))
  316. {
  317. EditShowBalloon(GetDlgItem(hDlg, IDC_EDIT_FILENAME),_Module.GetResourceInstance(),IDS_FILENAME_INVALID);
  318. return FALSE;
  319. }
  320. if (pcdParams->ConnectionInfo.IsLocal)
  321. {
  322. // Check if the file already exists...
  323. if (IsFileExist(szFullFileName))
  324. {
  325. // check if the filename is a directory!
  326. if (IsFileADirectory(szFullFileName))
  327. {
  328. EditShowBalloon(GetDlgItem(hDlg, IDC_EDIT_FILENAME),_Module.GetResourceInstance(),IDS_FILE_IS_A_DIR);
  329. return FALSE;
  330. }
  331. else
  332. {
  333. if (FALSE == AnswerIsYes(hDlg,IDS_REPLACE_FILE,szFullFileName))
  334. {
  335. return FALSE;
  336. }
  337. }
  338. }
  339. }
  340. else
  341. {
  342. // Check if the file already exists...
  343. // security percaution:decypt password before using it...then zero out memory that used it
  344. if (pcdParams->ConnectionInfo.pszUserPasswordEncrypted)
  345. {
  346. LPWSTR lpwstrTemp = NULL;
  347. if (FAILED(DecryptMemoryPassword((LPWSTR) pcdParams->ConnectionInfo.pszUserPasswordEncrypted,&lpwstrTemp,pcdParams->ConnectionInfo.cbUserPasswordEncrypted)))
  348. {
  349. return FALSE;
  350. }
  351. if (IsFileExistRemote(pcdParams->ConnectionInfo.pszMachineName,szFullFileName,pcdParams->ConnectionInfo.pszUserName,lpwstrTemp))
  352. {
  353. if (FALSE == AnswerIsYes(hDlg,IDS_REPLACE_FILE,szFullFileName))
  354. {
  355. return FALSE;
  356. }
  357. }
  358. if (lpwstrTemp)
  359. {
  360. // security percaution:Make sure to zero out memory that temporary password was used for.
  361. SecureZeroMemory(lpwstrTemp,pcdParams->ConnectionInfo.cbUserPasswordEncrypted);
  362. LocalFree(lpwstrTemp);
  363. lpwstrTemp = NULL;
  364. }
  365. }
  366. }
  367. // Perform the action...
  368. // and then if successfull proceed to close the dialog...
  369. // check if everything is filled in.
  370. // if not then warn user and do nothing.
  371. BOOL bUsingPassword = (BST_CHECKED == IsDlgButtonChecked(hDlg, IDC_CHECK_ENCRYPT));
  372. if (bUsingPassword)
  373. {
  374. TCHAR szPW1[PWLEN + 1];
  375. TCHAR szPW2[PWLEN + 1];
  376. SecureZeroMemory(szPW1, sizeof(szPW1));
  377. SecureZeroMemory(szPW2, sizeof(szPW2));
  378. GetDlgItemText(hDlg, IDC_EDIT_PASSWORD1, szPW1, PWLEN);
  379. GetDlgItemText(hDlg, IDC_EDIT_PASSWORD2, szPW2, PWLEN);
  380. if ( _tcscmp(szPW1, szPW2) )
  381. {
  382. // passwords do not match
  383. EditShowBalloon(GetDlgItem(hDlg, IDC_EDIT_PASSWORD1),_Module.GetResourceInstance(),IDS_PASSWORDS_NO_MATCH);
  384. return FALSE;
  385. }
  386. else
  387. {
  388. hr = DoExportConfigToFile(&pcdParams->ConnectionInfo,(BSTR) szFullFileName,(BSTR) pcdParams->pszMetabasePath,szPW1,pcdParams->dwExportFlags);
  389. }
  390. }
  391. else
  392. {
  393. hr = DoExportConfigToFile(&pcdParams->ConnectionInfo,(BSTR) szFullFileName,(BSTR) pcdParams->pszMetabasePath,NULL,pcdParams->dwExportFlags);
  394. }
  395. if (FAILED(hr))
  396. {
  397. if (hr == HRESULT_FROM_WIN32(ERROR_PATH_NOT_FOUND))
  398. {
  399. //0x80070003
  400. EditShowBalloon(GetDlgItem(hDlg, IDC_EDIT_PATH),_Module.GetResourceInstance(),IDS_FILE_NOT_FOUND);
  401. }
  402. else
  403. {
  404. // we failed.
  405. // so keep the dialog open and do nothing
  406. CError err(hr);
  407. err.MessageBox();
  408. }
  409. return FALSE;
  410. }
  411. else
  412. {
  413. TCHAR szNoSpaces2[_MAX_PATH + 1];
  414. ZeroMemory(szFullFileName, sizeof(szFullFileName));
  415. GetDlgItemText(hDlg, IDC_EDIT_PATH, szFullFileName, _MAX_PATH);
  416. RemoveSpaces(szNoSpaces2, sizeof(szNoSpaces2), szFullFileName);
  417. StringCbCopy(szFullFileName, sizeof(szFullFileName), szNoSpaces2);
  418. if (0 != _tcscmp(szFullFileName, _T("")))
  419. {
  420. DefaultValueSettingsSave((LPCTSTR) pcdParams->ConnectionInfo.pszMachineName,LAST_USED_EXPORT_PATH,szFullFileName);
  421. }
  422. EndDialog(hDlg, (int)wParam);
  423. return TRUE;
  424. }
  425. }
  426. return FALSE;
  427. }
  428. case IDC_CHECK_ENCRYPT:
  429. {
  430. // user is toggling the checkbox.
  431. BOOL bUsingPassword = (BST_CHECKED == IsDlgButtonChecked(hDlg, IDC_CHECK_ENCRYPT));
  432. // enable/disable edit label
  433. EnableWindow(GetDlgItem(hDlg,IDC_STATIC_PASSWORD1), bUsingPassword);
  434. EnableWindow(GetDlgItem(hDlg,IDC_STATIC_PASSWORD2), bUsingPassword);
  435. // enable/disable edit boxes
  436. EnableWindow(GetDlgItem(hDlg,IDC_EDIT_PASSWORD1), bUsingPassword);
  437. EnableWindow(GetDlgItem(hDlg,IDC_EDIT_PASSWORD2), bUsingPassword);
  438. SetControlStates(hDlg,msg,wParam,pcdParams);
  439. return TRUE;
  440. }
  441. }
  442. break;
  443. }
  444. return FALSE;
  445. }
  446. HRESULT DoExportConfigToFile(PCONNECTION_INFO pConnectionInfo,BSTR bstrFileNameAndPath,BSTR bstrMetabasePath,BSTR bstrPassword,DWORD dwExportFlags)
  447. {
  448. HRESULT hr = E_FAIL;
  449. IMSAdminBase *pIMSAdminBase = NULL;
  450. IMSAdminBase2 *pIMSAdminBase2 = NULL;
  451. LPWSTR lpwstrTempPassword = NULL;
  452. if (!pConnectionInfo)
  453. {
  454. return HRESULT_FROM_WIN32(ERROR_INVALID_PARAMETER);
  455. }
  456. if (pConnectionInfo->pszUserPasswordEncrypted)
  457. {
  458. if (FAILED(DecryptMemoryPassword((LPWSTR) pConnectionInfo->pszUserPasswordEncrypted,&lpwstrTempPassword,pConnectionInfo->cbUserPasswordEncrypted)))
  459. {
  460. return HRESULT_FROM_WIN32(ERROR_DECRYPTION_FAILED);
  461. }
  462. }
  463. CComAuthInfo auth(pConnectionInfo->pszMachineName,pConnectionInfo->pszUserName,lpwstrTempPassword);
  464. if (!bstrFileNameAndPath)
  465. {
  466. return HRESULT_FROM_WIN32(ERROR_INVALID_PARAMETER);
  467. }
  468. // buffer overflow paranoia, make sure it's less than 255 characters long
  469. if (wcslen(bstrFileNameAndPath) > (_MAX_PATH)){return RPC_S_STRING_TOO_LONG;}
  470. if (wcslen(bstrMetabasePath) > (_MAX_PATH)){return RPC_S_STRING_TOO_LONG;}
  471. if (bstrPassword)
  472. {
  473. if (wcslen(bstrPassword) > (_MAX_PATH)){return RPC_S_STRING_TOO_LONG;}
  474. }
  475. if(FAILED(hr = CoInitializeEx(NULL, COINIT_MULTITHREADED)))
  476. {
  477. if(FAILED(hr = CoInitializeEx(NULL, COINIT_APARTMENTTHREADED)))
  478. {
  479. return hr;
  480. }
  481. }
  482. // RPC_C_AUTHN_LEVEL_DEFAULT 0
  483. // RPC_C_AUTHN_LEVEL_NONE 1
  484. // RPC_C_AUTHN_LEVEL_CONNECT 2
  485. // RPC_C_AUTHN_LEVEL_CALL 3
  486. // RPC_C_AUTHN_LEVEL_PKT 4
  487. // RPC_C_AUTHN_LEVEL_PKT_INTEGRITY 5
  488. // RPC_C_AUTHN_LEVEL_PKT_PRIVACY 6
  489. //COSERVERINFO * pcsiName = auth.CreateServerInfoStruct(RPC_C_AUTHN_LEVEL_PKT_PRIVACY);
  490. COSERVERINFO * pcsiName = auth.CreateServerInfoStruct(RPC_C_AUTHN_LEVEL_DEFAULT);
  491. MULTI_QI res[1] =
  492. {
  493. {&IID_IMSAdminBase, NULL, 0}
  494. };
  495. if (FAILED(hr = CoCreateInstanceEx(CLSID_MSAdminBase,NULL,CLSCTX_ALL,pcsiName,1,res)))
  496. {
  497. goto DoExportConfigToFile_Exit;
  498. }
  499. pIMSAdminBase = (IMSAdminBase *)res[0].pItf;
  500. if (auth.UsesImpersonation())
  501. {
  502. if (FAILED(hr = auth.ApplyProxyBlanket(pIMSAdminBase)))
  503. {
  504. goto DoExportConfigToFile_Exit;
  505. }
  506. // There is a remote IUnknown interface that lurks behind IUnknown.
  507. // If that is not set, then the Release call can return access denied.
  508. IUnknown * pUnk = NULL;
  509. hr = pIMSAdminBase->QueryInterface(IID_IUnknown, (void **)&pUnk);
  510. if(FAILED(hr))
  511. {
  512. return hr;
  513. }
  514. if (FAILED(hr = auth.ApplyProxyBlanket(pUnk)))
  515. {
  516. goto DoExportConfigToFile_Exit;
  517. }
  518. pUnk->Release();pUnk = NULL;
  519. }
  520. if (FAILED(hr = pIMSAdminBase->QueryInterface(IID_IMSAdminBase2, (void **)&pIMSAdminBase2)))
  521. {
  522. goto DoExportConfigToFile_Exit;
  523. }
  524. if (auth.UsesImpersonation())
  525. {
  526. if (FAILED(hr = auth.ApplyProxyBlanket(pIMSAdminBase2)))
  527. {
  528. goto DoExportConfigToFile_Exit;
  529. }
  530. }
  531. else
  532. {
  533. // the local call needs min RPC_C_IMP_LEVEL_IMPERSONATE
  534. // for the pIMSAdminBase2 objects Import/Export functions!
  535. if (FAILED(hr = SetBlanket(pIMSAdminBase2)))
  536. {
  537. //goto DoExportConfigToFile_Exit;
  538. }
  539. }
  540. //IISDebugOutput(_T("Export:bstrPassword=%s,bstrFileNameAndPath=%s,bstrMetabasePath=%s,dwExportFlags=%d\r\n"),bstrPassword,bstrFileNameAndPath,bstrMetabasePath,dwExportFlags);
  541. IISDebugOutput(_T("Export:FileName=%s,MetabasePath=%s,ExportFlags=%d\r\n"),bstrFileNameAndPath,bstrMetabasePath,dwExportFlags);
  542. hr = pIMSAdminBase2->Export(bstrPassword,bstrFileNameAndPath,bstrMetabasePath,dwExportFlags);
  543. DoExportConfigToFile_Exit:
  544. IISDebugOutput(_T("Export:ret=0x%x\r\n"),hr);
  545. auth.FreeServerInfoStruct(pcsiName);
  546. if (lpwstrTempPassword)
  547. {
  548. // security percaution:Make sure to zero out memory that temporary password was used for.
  549. SecureZeroMemory(lpwstrTempPassword,pConnectionInfo->cbUserPasswordEncrypted);
  550. LocalFree(lpwstrTempPassword);
  551. lpwstrTempPassword = NULL;
  552. }
  553. if (pIMSAdminBase2)
  554. {
  555. pIMSAdminBase2->Release();
  556. pIMSAdminBase2 = NULL;
  557. }
  558. if (pIMSAdminBase)
  559. {
  560. pIMSAdminBase->Release();
  561. pIMSAdminBase = NULL;
  562. }
  563. CoUninitialize();
  564. return hr;
  565. }