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.

1946 lines
61 KiB

  1. #include "pch.hxx"
  2. #include <prsht.h>
  3. #include <prshtp.h>
  4. #include <imnact.h>
  5. #include <acctman.h>
  6. #include <icwacct.h>
  7. #include "dllmain.h"
  8. #include <acctimp.h>
  9. #include "icwwiz.h"
  10. #include "acctui.h"
  11. #include "server.h"
  12. #include <resource.h>
  13. #include <demand.h>
  14. #include "strconst.h"
  15. #include <msident.h>
  16. #include <shlwapi.h>
  17. #include <autodiscovery.h>
  18. ASSERTDATA
  19. BOOL FGetSystemShutdownPrivledge(void);
  20. typedef struct tagACCTWIZINIT
  21. {
  22. ACCTTYPE type;
  23. ULONG iFirstPage;
  24. ULONG iLastPage;
  25. } ACCTWIZINIT;
  26. const static ACCTWIZINIT c_rgAcctInit[ACCT_LAST] =
  27. {
  28. {
  29. ACCT_NEWS,
  30. ORD_PAGE_NEWSNAME,
  31. ORD_PAGE_NEWSCOMPLETE
  32. },
  33. {
  34. ACCT_MAIL,
  35. ORD_PAGE_MAILNAME,
  36. ORD_PAGE_MAILCOMPLETE
  37. },
  38. {
  39. ACCT_DIR_SERV,
  40. ORD_PAGE_LDAPINFO,
  41. ORD_PAGE_LDAPCOMPLETE
  42. },
  43. };
  44. const static ACCTWIZINIT c_rgAutoDiscoveryAcctInit =
  45. {
  46. ACCT_MAIL,
  47. ORD_PAGE_AD_MAILADDRESS,
  48. ORD_PAGE_AD_MAILCOMPLETE
  49. };
  50. const static int c_rgidsNewAcct[ACCT_LAST] = {idsNewNewsAccount, idsNewMailAccount, idsNewLdapAccount};
  51. //If you change this table please verify that the #defines and enumerations are correct in ids.h
  52. const static PAGEINFO g_pRequestedPageInfo[NUM_WIZARD_PAGES] =
  53. {
  54. { IDD_PAGE_MAILPROMPT, idsMailPromptHeader, MailPromptInitProc, MailPromptOKProc, NULL, NULL, NULL, 0}, // exit
  55. { IDD_PAGE_MAILACCT, idsMailAcctHeader, AcctInitProc, AcctOKProc, AcctCmdProc, NULL, NULL, 0},
  56. { IDD_PAGE_MIGRATE, idsMailMigrateHeader, MigrateInitProc, MigrateOKProc, AcctCmdProc, NULL, NULL, 0},
  57. { IDD_PAGE_MAILACCTIMPORT, idsMailImportHeader, MigrateInitProc, MigrateOKProc, AcctCmdProc, NULL, NULL, 0},
  58. { IDD_PAGE_MIGRATESELECT, idsMailSelectHeader, SelectInitProc, SelectOKProc, NULL, NULL, NULL, 0},
  59. { IDD_PAGE_MAILCONFIRM, idsConfirmHeader, ConfirmInitProc, ConfirmOKProc, NULL, NULL, NULL, 0}, // exit
  60. { IDD_PAGE_MAILNAME, idsYourNameHeader, NameInitProc, NameOKProc, NameCmdProc, NULL, NULL, 0},
  61. { IDD_PAGE_MAILADDRESS, idsMailAddressHeader, AddressInitProc, AddressOKProc, AddressCmdProc, NULL, NULL, 0},
  62. { IDD_PAGE_MAILSERVER, idsMailServerHeader, ServerInitProc, ServerOKProc, ServerCmdProc, NULL, NULL, 0}, // exit
  63. { IDD_PAGE_MAILLOGON, idsMailLogonHeader, LogonInitProc, LogonOKProc, LogonCmdProc, NULL, NULL, 0}, // exit
  64. { IDD_PAGE_CONNECT, 0, ConnectInitProc, ConnectOKProc, ConnectCmdProc, NULL, NULL, 0},
  65. { IDD_PAGE_COMPLETE, idsCompleteHeader, CompleteInitProc, CompleteOKProc, NULL, NULL, NULL, 0},
  66. { IDD_PAGE_NEWSMIGRATE, idsNewsMigrateHeader, MigrateInitProc, MigrateOKProc, AcctCmdProc, NULL, NULL, 0},
  67. { IDD_PAGE_NEWSACCTIMPORT, idsNewsImportHeader, MigrateInitProc, MigrateOKProc, AcctCmdProc, NULL, NULL, 0},
  68. { IDD_PAGE_NEWSACCTSELECT, idsNewsSelectHeader, SelectInitProc, SelectOKProc, NULL, NULL, NULL, 0},
  69. { IDD_PAGE_NEWSCONFIRM, idsConfirmHeader, ConfirmInitProc, ConfirmOKProc, NULL, NULL, NULL, 0}, // exit
  70. { IDD_PAGE_NEWSNAME, idsYourNameHeader, NameInitProc, NameOKProc, NameCmdProc, NULL, NULL, 0},
  71. { IDD_PAGE_NEWSADDRESS, idsNewsAddressHeader, AddressInitProc, AddressOKProc, AddressCmdProc, NULL, NULL, 0},
  72. { IDD_PAGE_NEWSINFO, idsNewsServerHeader, ServerInitProc, ServerOKProc, ServerCmdProc, NULL, NULL, 0}, // exit
  73. { IDD_PAGE_MAILLOGON, idsNewsLogonHeader, LogonInitProc, LogonOKProc, LogonCmdProc, NULL, NULL, 0}, // exit
  74. { IDD_PAGE_CONNECT, 0, ConnectInitProc, ConnectOKProc, ConnectCmdProc, NULL, NULL, 0},
  75. { IDD_PAGE_COMPLETE, idsCompleteHeader, CompleteInitProc, CompleteOKProc, NULL, NULL, NULL, 0},
  76. { IDD_PAGE_LDAPINFO, idsLdapServerHeader, ServerInitProc, ServerOKProc, ServerCmdProc, NULL, NULL, 0},
  77. { IDD_PAGE_LDAPLOGON, idsLdapLogonHeader, LogonInitProc, LogonOKProc, LogonCmdProc, NULL, NULL, 0},
  78. { IDD_PAGE_LDAPRESOLVE, idsLdapResolveHeader, ResolveInitProc, ResolveOKProc, NULL, NULL, NULL, 0}, // exit
  79. { IDD_PAGE_COMPLETE, idsCompleteHeader, CompleteInitProc, CompleteOKProc, NULL, NULL, NULL, 0},
  80. { IDD_PAGE_MAILADDRESS, idsMailAddressHeader, AddressInitProc, AddressOKProc, AddressCmdProc, NULL, NULL, 0},
  81. { IDD_PAGE_PASSIFIER, idsAutoDiscoveryDescTitle, PassifierInitProc, PassifierOKProc, PassifierCmdProc, NULL, NULL, 0},
  82. { IDD_PAGE_AUTODISCOVERY, idsAutoDiscoveryDescTitle, AutoDiscoveryInitProc, AutoDiscoveryOKProc, AutoDiscoveryCmdProc, AutoDiscoveryWMUserProc, AutoDiscoveryCancelProc, 0},
  83. { IDD_PAGE_USEWEBMAIL, idsAutoDiscoveryDescTitle, UseWebMailInitProc, UseWebMailOKProc, UseWebMailCmdProc, NULL, NULL, 0},
  84. { IDD_PAGE_GOTOSERVERINFO, idsAutoDiscoveryDescTitle, GotoServerInfoInitProc, GotoServerInfoOKProc, GotoServerInfoCmdProc, NULL, NULL, 0},
  85. { IDD_PAGE_MAILSERVER, idsMailServerHeader, ServerInitProc, ServerOKProc, ServerCmdProc, NULL, NULL, 0}, // exit
  86. { IDD_PAGE_MAILNAME, idsYourNameHeader, NameInitProc, NameOKProc, NameCmdProc, NULL, NULL, 0},
  87. { IDD_PAGE_MAILLOGON, idsMailLogonHeader, LogonInitProc, LogonOKProc, LogonCmdProc, NULL, NULL, 0}, // exit
  88. { IDD_PAGE_CONNECT, 0, ConnectInitProc, ConnectOKProc, ConnectCmdProc, NULL, NULL, 0},
  89. { IDD_PAGE_COMPLETE, idsCompleteHeader, CompleteInitProc, CompleteOKProc, NULL, NULL, NULL, 0},
  90. };
  91. const static UINT c_rgOrdNewAcct[ACCT_LAST] =
  92. {
  93. ORD_PAGE_NEWSCONNECT,
  94. ORD_PAGE_MAILCONNECT,
  95. ORD_PAGE_LDAPCOMPLETE
  96. };
  97. const static UINT c_rgOEOrdNewAcct[ACCT_LAST] =
  98. {
  99. ORD_PAGE_NEWSCOMPLETE,
  100. ORD_PAGE_MAILCOMPLETE,
  101. ORD_PAGE_LDAPCOMPLETE
  102. };
  103. BOOL _InitComCtl32()
  104. {
  105. static BOOL fInitialized = FALSE;
  106. if (!fInitialized)
  107. {
  108. INITCOMMONCONTROLSEX icc;
  109. icc.dwSize = sizeof(INITCOMMONCONTROLSEX);
  110. icc.dwICC = (ICC_ANIMATE_CLASS | ICC_USEREX_CLASSES | ICC_COOL_CLASSES | ICC_INTERNET_CLASSES | ICC_PAGESCROLLER_CLASS | ICC_NATIVEFNTCTL_CLASS | ICC_LISTVIEW_CLASSES);
  111. fInitialized = InitCommonControlsEx(&icc);
  112. }
  113. return fInitialized;
  114. }
  115. HRESULT GetAcctConnectInfo(CAccount *pAcct, ACCTDATA *pData)
  116. {
  117. HRESULT hr;
  118. DWORD dw;
  119. hr = pAcct->GetPropDw(AP_RAS_CONNECTION_TYPE, &dw);
  120. if (SUCCEEDED(hr))
  121. {
  122. pData->dwConnect = dw;
  123. // if (dw == CONNECTION_TYPE_RAS || dw == CONNECTION_TYPE_INETSETTINGS)
  124. if (dw == CONNECTION_TYPE_RAS)
  125. hr = pAcct->GetPropSz(AP_RAS_CONNECTOID, pData->szConnectoid, ARRAYSIZE(pData->szConnectoid));
  126. }
  127. return(hr);
  128. }
  129. BOOL GetRequiredAccountProp(CAccount *pAcct, DWORD dwProp, char *psz, ULONG cch)
  130. {
  131. HRESULT hr;
  132. Assert(pAcct != NULL);
  133. Assert(psz != NULL);
  134. hr = pAcct->GetPropSz(dwProp, psz, cch);
  135. return(SUCCEEDED(hr) && !FIsEmpty(psz));
  136. }
  137. CICWApprentice::CICWApprentice(void)
  138. {
  139. DllAddRef();
  140. m_cRef = 1;
  141. m_fInit = FALSE;
  142. m_fReboot = FALSE;
  143. m_pExt = NULL;
  144. m_pPageInfo = NULL;
  145. m_pInitInfo = NULL;
  146. m_cPages = 0;
  147. m_idPrevPage = 0;
  148. m_idNextPage = 0;
  149. m_iCurrentPage = 0;
  150. ZeroMemory(m_iPageHistory, sizeof(m_iPageHistory));
  151. m_cPagesCompleted = 0;
  152. m_hDlg = NULL;
  153. m_rgPage = NULL;
  154. m_extFirstPage = 0;
  155. m_extLastPage = 0;
  156. m_pAcctMgr = NULL;
  157. m_pAcct = NULL;
  158. m_dwFlags = 0;
  159. m_pICW = 0;
  160. m_acctType = (ACCTTYPE)-1;
  161. m_fSave = FALSE;
  162. m_fSkipICW = FALSE;
  163. m_dwReload = 0;
  164. m_iSel = 0;
  165. m_fMigrate = FALSE;
  166. m_fComplete = FALSE;
  167. // The user can turn the feature on and off with the SZ_REGVALUE_AUTODISCOVERY regkey.
  168. // The admin can turn the policy blocking the feature on and off with SZ_REGVALUE_AUTODISCOVERY_POLICY.
  169. m_fUseAutoDiscovery = (SHRegGetBoolUSValue(SZ_REGKEY_AUTODISCOVERY, SZ_REGVALUE_AUTODISCOVERY, FALSE, FALSE) &&
  170. SHRegGetBoolUSValue(SZ_REGKEY_AUTODISCOVERY_POLICY, SZ_REGVALUE_AUTODISCOVERY_POLICY, FALSE, TRUE));
  171. if (m_fUseAutoDiscovery)
  172. {
  173. IMailAutoDiscovery * pMailAutoDiscovery;
  174. // Let's make sure our API is installed and available. I'm being robust because it's better safe than sorry.
  175. if (SUCCEEDED(CoCreateInstance(CLSID_MailAutoDiscovery, NULL, CLSCTX_INPROC_SERVER, IID_IMailAutoDiscovery, (void **)&pMailAutoDiscovery)))
  176. {
  177. pMailAutoDiscovery->Release();
  178. }
  179. else
  180. {
  181. m_fUseAutoDiscovery = FALSE; // We can't use it.
  182. }
  183. }
  184. m_pData = NULL;
  185. m_pMigInfo = NULL;
  186. m_cMigInfo = 0;
  187. m_iMigInfo = -1;
  188. m_pHttpServices = NULL;
  189. m_cHttpServices = 0;
  190. m_pServices = NULL;
  191. m_cServices = 0;
  192. }
  193. CICWApprentice::~CICWApprentice()
  194. {
  195. int i;
  196. if (m_pAcctMgr != NULL)
  197. m_pAcctMgr->Release();
  198. if (m_pAcct != NULL)
  199. m_pAcct->Release();
  200. if (m_pExt != NULL)
  201. m_pExt->Release();
  202. if (m_pData != NULL)
  203. {
  204. if (m_pData->pAcct != NULL)
  205. m_pData->pAcct->Release();
  206. MemFree(m_pData);
  207. }
  208. if (m_pInitInfo != NULL)
  209. MemFree(m_pInitInfo);
  210. if (m_pICW != NULL)
  211. m_pICW->Release();
  212. if (m_pMigInfo != NULL)
  213. {
  214. for (i = 0; i < m_cMigInfo; i++)
  215. {
  216. Assert(m_pMigInfo[i].pImp != NULL);
  217. m_pMigInfo[i].pImp->Release();
  218. if (m_pMigInfo[i].pImp2 != NULL)
  219. m_pMigInfo[i].pImp2->Release();
  220. }
  221. MemFree(m_pMigInfo);
  222. }
  223. if (m_pServices != NULL)
  224. MemFree(m_pServices);
  225. if (m_pHttpServices != NULL)
  226. MemFree(m_pHttpServices);
  227. DllRelease();
  228. }
  229. STDMETHODIMP CICWApprentice::QueryInterface(REFIID riid, LPVOID *ppv)
  230. {
  231. if (ppv == NULL)
  232. return(E_INVALIDARG);
  233. *ppv = NULL;
  234. // IID_IICWApprentice
  235. if (IID_IICWApprentice == riid)
  236. *ppv = (void *)(IICWApprentice *)this;
  237. // IID_IICWExtension
  238. else if (IID_IICWExtension == riid)
  239. *ppv = (void *)(IICWExtension *)this;
  240. // IID_IUnknown
  241. else if (IID_IUnknown == riid)
  242. *ppv = (void *)this;
  243. else
  244. return(E_NOINTERFACE);
  245. ((LPUNKNOWN)*ppv)->AddRef();
  246. return(S_OK);
  247. }
  248. STDMETHODIMP_(ULONG) CICWApprentice::AddRef(VOID)
  249. {
  250. return(++m_cRef);
  251. }
  252. STDMETHODIMP_(ULONG) CICWApprentice::Release(VOID)
  253. {
  254. if (--m_cRef == 0)
  255. {
  256. delete this;
  257. return(0);
  258. }
  259. return(m_cRef);
  260. }
  261. // this Initialize is called only by the ICW (in apprentice mode)
  262. HRESULT CICWApprentice::Initialize(IICWExtension *pExt)
  263. {
  264. DWORD cb, dwUserID;
  265. HRESULT hr;
  266. IUserIdentityManager *pIdMan = NULL;
  267. IUserIdentity *pUser = NULL;
  268. GUID *pguid;
  269. if (pExt == NULL)
  270. return(E_INVALIDARG);
  271. if (m_fInit)
  272. return E_UNEXPECTED;
  273. Assert(m_pExt == NULL);
  274. Assert(!m_pData);
  275. Assert(!m_pInitInfo);
  276. Assert(m_pAcctMgr == NULL);
  277. cb = sizeof(ACCTDATA) * ACCT_LAST;
  278. if (!MemAlloc((void **)&m_pData, cb))
  279. {
  280. TrapError(hr = E_OUTOFMEMORY);
  281. goto exit;
  282. }
  283. ZeroMemory(m_pData, cb);
  284. cb = sizeof(DLGINITINFO) * NUM_WIZARD_PAGES;
  285. if (!MemAlloc((void **)&m_pInitInfo, cb))
  286. {
  287. TrapError(hr = E_OUTOFMEMORY);
  288. goto exit;
  289. }
  290. ZeroMemory(m_pInitInfo, cb);
  291. hr = HrCreateAccountManager((IImnAccountManager **)&m_pAcctMgr);
  292. if (FAILED(hr))
  293. goto exit;
  294. Assert(m_pAcctMgr != NULL);
  295. if (m_pAcctMgr->FNoModifyAccts())
  296. {
  297. hr = E_FAIL;
  298. goto exit;
  299. }
  300. if (SUCCEEDED(CoCreateInstance(CLSID_UserIdentityManager, NULL, CLSCTX_INPROC_SERVER, IID_IUserIdentityManager, (LPVOID *)&pIdMan)))
  301. {
  302. Assert(pIdMan != NULL);
  303. pguid = (GUID*)&UID_GIBC_CURRENT_USER;
  304. // Avoid showing UI so try current, if no current, use default
  305. if (SUCCEEDED(pIdMan->GetIdentityByCookie(pguid, &pUser)))
  306. pUser->Release();
  307. else
  308. pguid = (GUID*)&UID_GIBC_DEFAULT_USER;
  309. pIdMan->Release();
  310. hr = m_pAcctMgr->InitUser(NULL, *pguid, 0);
  311. }
  312. else
  313. hr = m_pAcctMgr->Init(NULL);
  314. if (FAILED(hr))
  315. goto exit;
  316. m_pExt = pExt;
  317. m_pExt->AddRef();
  318. m_pPageInfo = g_pRequestedPageInfo;
  319. Assert(m_dwFlags == 0);
  320. m_dwFlags = (ACCT_WIZ_IN_ICW | ACCT_WIZ_HTTPMAIL);
  321. m_acctType = ACCT_MAIL;
  322. m_fInit = TRUE;
  323. InitHTTPMailServices();
  324. return(S_OK);
  325. // Only go here if something has gone wrong and function will fail
  326. exit:
  327. Assert(FAILED(hr));
  328. SafeMemFree(m_pData);
  329. SafeMemFree(m_pInitInfo);
  330. SafeRelease(m_pAcctMgr);
  331. return hr;
  332. }
  333. HRESULT CICWApprentice::AddWizardPages(DWORD dwFlags)
  334. {
  335. BOOL fRet;
  336. char sz[CCHMAX_STRINGRES];
  337. DWORD type;
  338. UINT rgid[NUM_WIZARD_PAGES];
  339. UINT idFirstPage, idLastPage;
  340. HPROPSHEETPAGE hWizPage[NUM_WIZARD_PAGES];
  341. PROPSHEETPAGE psPage;
  342. ULONG nPageIndex, dlgID;
  343. HRESULT hr;
  344. _InitComCtl32(); // So we can use the ICC_ANIMATE_CLASS common controls.
  345. if (m_pAcctMgr->FNoModifyAccts())
  346. return(E_FAIL);
  347. hr = m_pAcctMgr->GetAccountCount(ACCT_MAIL, &type);
  348. if (FAILED(hr))
  349. return(hr);
  350. else if (type == 0)
  351. {
  352. hr = InitializeMigration(0);
  353. if (FAILED(hr))
  354. return(hr);
  355. }
  356. hr = S_OK;
  357. ZeroMemory(hWizPage, sizeof(hWizPage)); // hWizPage is an array
  358. ZeroMemory(rgid, sizeof(rgid));
  359. ZeroMemory(&psPage, sizeof(PROPSHEETPAGE));
  360. psPage.dwSize = sizeof(psPage);
  361. psPage.dwFlags = PSP_DEFAULT | PSP_USEHEADERTITLE;
  362. psPage.hInstance = g_hInstRes;
  363. psPage.pfnDlgProc = GenDlgProc;
  364. idFirstPage = g_pRequestedPageInfo[ICW_FIRST_PAGE].uDlgID;
  365. idLastPage = g_pRequestedPageInfo[ICW_LAST_PAGE].uDlgID;
  366. // create a property sheet page for each page in the wizard
  367. for (nPageIndex = ICW_FIRST_PAGE; nPageIndex <= ICW_LAST_PAGE; nPageIndex++)
  368. {
  369. dlgID = g_pRequestedPageInfo[nPageIndex].uDlgID;
  370. Assert(dlgID >= EXTERNAL_DIALOGID_MINIMUM);
  371. Assert(dlgID <= EXTERNAL_DIALOGID_MAXIMUM);
  372. m_pInitInfo[m_cPages].pApp = this;
  373. m_pInitInfo[m_cPages].ord = nPageIndex;
  374. psPage.lParam = (LPARAM)&m_pInitInfo[m_cPages];
  375. psPage.pszTemplate = MAKEINTRESOURCE(dlgID);
  376. LoadString(g_hInstRes, g_pRequestedPageInfo[nPageIndex].uHdrID, sz, ARRAYSIZE(sz));
  377. psPage.pszHeaderTitle = sz;
  378. hWizPage[m_cPages] = CreatePropertySheetPage(&psPage);
  379. if (hWizPage[m_cPages] == NULL ||
  380. !m_pExt->AddExternalPage(hWizPage[m_cPages], dlgID))
  381. {
  382. hr = E_FAIL;
  383. break;
  384. }
  385. rgid[m_cPages] = dlgID;
  386. m_cPages++;
  387. }
  388. if (SUCCEEDED(hr))
  389. {
  390. m_pExt->SetFirstLastPage(idFirstPage, idLastPage);
  391. }
  392. else
  393. {
  394. for (nPageIndex = 0; nPageIndex <= m_cPages; nPageIndex++)
  395. {
  396. if (hWizPage[nPageIndex] != NULL)
  397. {
  398. DestroyPropertySheetPage(hWizPage[nPageIndex]);
  399. if (rgid[nPageIndex] != 0)
  400. m_pExt->RemoveExternalPage(hWizPage[nPageIndex], rgid[nPageIndex]);
  401. }
  402. }
  403. }
  404. return(hr);
  405. }
  406. HRESULT CICWApprentice::SetPrevNextPage(UINT uPrevPage, UINT uNextPage)
  407. {
  408. if (uPrevPage != 0)
  409. m_idPrevPage = uPrevPage;
  410. if (uNextPage != 0)
  411. m_idNextPage = uNextPage;
  412. Assert(m_idPrevPage != 0);
  413. Assert(m_idNextPage != 0);
  414. return(S_OK);
  415. }
  416. HRESULT CICWApprentice::GetConnectionInformation(CONNECTINFO *pInfo)
  417. {
  418. return(E_NOTIMPL);
  419. }
  420. HRESULT CICWApprentice::SetConnectionInformation(CONNECTINFO *pInfo)
  421. {
  422. ACCTDATA *pData;
  423. DWORD type;
  424. Assert(CONNECT_LAN == CONNECTION_TYPE_LAN);
  425. Assert(CONNECT_MANUAL == CONNECTION_TYPE_MANUAL);
  426. Assert(CONNECT_RAS == CONNECTION_TYPE_RAS);
  427. if (pInfo == NULL || pInfo->type > CONNECT_RAS)
  428. return(E_INVALIDARG);
  429. pData = m_pData;
  430. for (type = ACCT_NEWS; type < ACCT_LAST; type++)
  431. {
  432. pData->dwConnect = pInfo->type;
  433. // if (pData->dwConnect == CONNECTION_TYPE_RAS || pData->dwConnect == CONNECTION_TYPE_INETSETTINGS)
  434. if (pData->dwConnect == CONNECTION_TYPE_RAS)
  435. StrCpyN(pData->szConnectoid, pInfo->szConnectoid, ARRAYSIZE(pData->szConnectoid));
  436. pData++;
  437. }
  438. return(S_OK);
  439. }
  440. const static c_rgError[ACCT_LAST] =
  441. {
  442. ERR_NEWS_ACCT,
  443. ERR_MAIL_ACCT,
  444. ERR_DIRSERV_ACCT
  445. };
  446. HRESULT CICWApprentice::Save(HWND hwnd, DWORD *pdwError)
  447. {
  448. HRESULT hr;
  449. CAccount *pAcct;
  450. if (pdwError == NULL)
  451. return(E_INVALIDARG);
  452. hr = S_OK;
  453. *pdwError = 0;
  454. if (m_fSave)
  455. {
  456. if (m_fMigrate || m_pData->szAcctOrig[0] == 0)
  457. hr = m_pAcctMgr->CreateAccountObject(m_acctType, (IImnAccount **)&pAcct);
  458. else
  459. hr = m_pAcctMgr->FindAccount(AP_ACCOUNT_NAME, m_pData->szAcctOrig, (IImnAccount **)&pAcct);
  460. if (FAILED(hr))
  461. {
  462. *pdwError = c_rgError[m_acctType];
  463. }
  464. else
  465. {
  466. hr = SaveAccountData(pAcct, m_acctType != ACCT_DIR_SERV);
  467. if (FAILED(hr))
  468. *pdwError = c_rgError[m_acctType];
  469. pAcct->Release();
  470. }
  471. m_fSave = FALSE;
  472. }
  473. return(hr);
  474. }
  475. HRESULT CICWApprentice::InitHTTPMailServices()
  476. {
  477. HKEY hkey = NULL, hkeyT = NULL;
  478. LONG lResult;
  479. HRESULT hr = S_OK;
  480. DWORD cServices, cb, i, type, dwFlagsT;
  481. BOOL fHideHotmail;
  482. m_cServices = 0;
  483. if (!AcctUtil_IsHTTPMailEnabled() || ((ACCT_WIZ_HTTPMAIL & m_dwFlags) == 0))
  484. return S_OK;
  485. fHideHotmail = AcctUtil_HideHotmail();
  486. if (ERROR_SUCCESS == RegOpenKeyEx(HKEY_LOCAL_MACHINE, c_szHTTPMailServiceRoot, 0, KEY_READ, &hkey))
  487. {
  488. if (ERROR_SUCCESS == RegQueryInfoKey(hkey, NULL, NULL, 0, &cServices, NULL, NULL, NULL, NULL, NULL, NULL, NULL) &&
  489. cServices > 0)
  490. {
  491. HTTPMAILSERVICE hmsNew;
  492. cb = sizeof(HTTPMAILSERVICE) * cServices;
  493. if (!MemAlloc((void **)&m_pServices, cb))
  494. {
  495. hr = E_OUTOFMEMORY;
  496. goto out;
  497. }
  498. if (!MemAlloc((void **)&m_pHttpServices, cb))
  499. {
  500. MemFree(m_pServices);
  501. hr = E_OUTOFMEMORY;
  502. goto out;
  503. }
  504. ZeroMemory(m_pServices, cb);
  505. ZeroMemory(m_pHttpServices, cb);
  506. // Start Enumerating the keys
  507. for (i = 0; i < cServices; i++)
  508. {
  509. BOOL fHttp, fSignup;
  510. ZeroMemory(&hmsNew, sizeof(hmsNew));
  511. fHttp = fSignup = false;
  512. // Enumerate Friendly Names
  513. cb = sizeof(hmsNew.szDomain);
  514. lResult = RegEnumKeyEx(hkey, i, hmsNew.szDomain, &cb, 0, NULL, NULL, NULL);
  515. // No more items
  516. if (lResult == ERROR_NO_MORE_ITEMS)
  517. break;
  518. // Error, lets move onto the next account
  519. if (lResult != ERROR_SUCCESS)
  520. {
  521. Assert(FALSE);
  522. continue;
  523. }
  524. if (ERROR_SUCCESS == RegOpenKeyEx(hkey, hmsNew.szDomain, 0, KEY_QUERY_VALUE, &hkeyT))
  525. {
  526. cb = sizeof(DWORD);
  527. dwFlagsT = 0;
  528. RegQueryValueEx(hkeyT, c_szHTTPMailDomainMSN, NULL, &type, (LPBYTE)&dwFlagsT, &cb);
  529. hmsNew.fDomainMSN = (dwFlagsT == 1);
  530. if (!fHideHotmail || !hmsNew.fDomainMSN)
  531. {
  532. cb = sizeof(DWORD);
  533. dwFlagsT = 0;
  534. RegQueryValueEx(hkeyT, c_szHTTPMailEnabled, NULL, &type, (LPBYTE)&dwFlagsT, &cb);
  535. fHttp = (dwFlagsT == 1);
  536. cb = CCHMAX_SERVICENAME;
  537. if (ERROR_SUCCESS != RegQueryValueEx(hkeyT, c_szHTTPMailServiceName, NULL, &type, (LPBYTE)&hmsNew.szFriendlyName, &cb) || hmsNew.szFriendlyName[0] == 0)
  538. goto next;
  539. fSignup = true;
  540. cb = MAX_PATH;
  541. if (ERROR_SUCCESS != RegQueryValueEx(hkeyT, c_szHTTPMailSignUp, NULL, &type, (LPBYTE)&hmsNew.szSignupUrl, &cb) || hmsNew.szSignupUrl[0] == 0)
  542. fSignup = false;
  543. cb = MAX_PATH;
  544. RegQueryValueEx(hkeyT, c_szHTTPMailServer, NULL, &type, (LPBYTE)&hmsNew.szRootUrl, &cb);
  545. if (hmsNew.szRootUrl[0] == 0)
  546. fHttp = false;
  547. hmsNew.fHTTPEnabled = fHttp;
  548. cb = sizeof(DWORD);
  549. dwFlagsT = 0;
  550. RegQueryValueEx(hkeyT, c_szHTTPMailUseWizard, NULL, &type, (LPBYTE)&dwFlagsT, &cb);
  551. hmsNew.fUseWizard = (dwFlagsT == 1);
  552. if (fHttp)
  553. m_pHttpServices[m_cHttpServices++] = hmsNew;
  554. if (fSignup)
  555. m_pServices[m_cServices++] = hmsNew;
  556. }
  557. next:
  558. RegCloseKey(hkeyT);
  559. }
  560. }
  561. }
  562. }
  563. out:
  564. if (NULL != hkey)
  565. RegCloseKey(hkey);
  566. return hr;
  567. }
  568. HRESULT CICWApprentice::Initialize(CAccountManager *pAcctMgr, CAccount *pAcct)
  569. {
  570. Assert(pAcctMgr != NULL);
  571. Assert(pAcct != NULL);
  572. Assert(!m_fInit);
  573. Assert(m_pExt == NULL);
  574. Assert(m_pAcctMgr == NULL);
  575. Assert(m_pAcct == NULL);
  576. if (!MemAlloc((void **)&m_pData, sizeof(ACCTDATA)))
  577. return(E_OUTOFMEMORY);
  578. ZeroMemory(m_pData, sizeof(ACCTDATA));
  579. if (!MemAlloc((void **)&m_pInitInfo, sizeof(DLGINITINFO) * NUM_WIZARD_PAGES))
  580. return(E_OUTOFMEMORY);
  581. ZeroMemory(m_pInitInfo, sizeof(DLGINITINFO) * NUM_WIZARD_PAGES);
  582. m_pAcctMgr = pAcctMgr;
  583. m_pAcctMgr->AddRef();
  584. m_pAcct = pAcct;
  585. m_pAcct->AddRef();
  586. m_pAcct->GetAccountType(&m_acctType);
  587. m_pPageInfo = g_pRequestedPageInfo;
  588. m_fInit = TRUE;
  589. return(S_OK);
  590. }
  591. int CALLBACK AcctPropSheetProc(HWND hwndDlg, UINT uMsg, LPARAM lParam)
  592. {
  593. DLGTEMPLATE *pDlg;
  594. if (uMsg == PSCB_PRECREATE)
  595. {
  596. pDlg = (DLGTEMPLATE *)lParam;
  597. if (!!(pDlg->style & DS_CONTEXTHELP))
  598. pDlg->style &= ~DS_CONTEXTHELP;
  599. }
  600. return(0);
  601. }
  602. HRESULT CICWApprentice::DoWizard(HWND hwnd, CLSID *pclsid, DWORD dwFlags)
  603. {
  604. TCHAR sz[CCHMAX_STRINGRES];
  605. int iRet;
  606. const ACCTWIZINIT *pinit;
  607. PROPSHEETPAGE psPage;
  608. PROPSHEETHEADER psHeader;
  609. UINT nPageIndex, cAccts, dlgID, szID;
  610. HRESULT hr;
  611. INITCOMMONCONTROLSEX icex = { sizeof(icex), ICC_FLAGS };
  612. Assert(m_pAcct != NULL);
  613. if (m_acctType == ACCT_MAIL || m_acctType == ACCT_NEWS)
  614. {
  615. if (pclsid != NULL)
  616. {
  617. hr = InitializeImport(*pclsid, dwFlags);
  618. if (FAILED(hr))
  619. return(hr);
  620. Assert(m_cMigInfo == 1);
  621. }
  622. else if (!!(dwFlags & (ACCT_WIZ_MIGRATE | ACCT_WIZ_MAILIMPORT | ACCT_WIZ_NEWSIMPORT)))
  623. {
  624. hr = InitializeMigration(dwFlags);
  625. if (FAILED(hr))
  626. return(hr);
  627. if (!!(dwFlags & (ACCT_WIZ_MAILIMPORT | ACCT_WIZ_NEWSIMPORT)))
  628. {
  629. if (m_cMigInfo == 0)
  630. return(E_NoAccounts);
  631. }
  632. }
  633. }
  634. if (!MemAlloc((void **)&m_rgPage, NUM_WIZARD_PAGES * sizeof(HPROPSHEETPAGE)))
  635. return(E_OUTOFMEMORY);
  636. m_cPageBuf = NUM_WIZARD_PAGES;
  637. InitCommonControlsEx(&icex);
  638. hr = InitAccountData(m_pAcct, NULL, FALSE);
  639. Assert(!FAILED(hr));
  640. ZeroMemory(&psPage, sizeof(PROPSHEETPAGE));
  641. ZeroMemory(&psHeader, sizeof(PROPSHEETHEADER));
  642. psPage.dwSize = sizeof(psPage);
  643. psPage.dwFlags = PSP_DEFAULT | PSP_USEHEADERTITLE;
  644. psPage.hInstance = g_hInstRes;
  645. psPage.pfnDlgProc = GenDlgProc;
  646. pinit = &c_rgAcctInit[m_acctType];
  647. Assert(pinit->type == m_acctType);
  648. if (m_cMigInfo > 0)
  649. {
  650. if (pclsid != NULL)
  651. {
  652. hr = HandleMigrationSelection(0, &nPageIndex, hwnd);
  653. if (FAILED(hr))
  654. goto exit;
  655. m_dwFlags |= ACCT_WIZ_IMPORT_CLIENT;
  656. }
  657. else if (!!(dwFlags & ACCT_WIZ_MAILIMPORT))
  658. {
  659. nPageIndex = ORD_PAGE_MAILACCTIMPORT;
  660. }
  661. else if (!!(dwFlags & ACCT_WIZ_NEWSIMPORT))
  662. {
  663. nPageIndex = ORD_PAGE_NEWSACCTIMPORT;
  664. }
  665. else
  666. {
  667. Assert(m_acctType == ACCT_MAIL || m_acctType == ACCT_NEWS);
  668. nPageIndex = (m_acctType == ACCT_MAIL) ? ORD_PAGE_MIGRATE : ORD_PAGE_NEWSMIGRATE;
  669. }
  670. m_dwFlags |= ACCT_WIZ_MIGRATE;
  671. }
  672. else
  673. {
  674. if ((ACCT_MAIL == m_acctType) && m_fUseAutoDiscovery)
  675. {
  676. // In this case, we want to change the range to
  677. // ORD_PAGE_AD_MAILNAME to ORD_PAGE_AD_MAILCOMPLETE;
  678. pinit = &c_rgAutoDiscoveryAcctInit;
  679. }
  680. nPageIndex = pinit->iFirstPage;
  681. m_dwFlags |= (dwFlags & ACCT_WIZ_NO_NEW_POP);
  682. }
  683. m_dwFlags |= (dwFlags & ACCT_WIZ_INTERNETCONNECTION);
  684. m_dwFlags |= (dwFlags & ACCT_WIZ_HTTPMAIL);
  685. m_dwFlags |= (dwFlags & ACCT_WIZ_OE);
  686. if (m_acctType == ACCT_MAIL)
  687. InitHTTPMailServices();
  688. // create a property sheet page for each page in the wizard
  689. for ( ; nPageIndex <= pinit->iLastPage; nPageIndex++)
  690. {
  691. dlgID = g_pRequestedPageInfo[nPageIndex].uDlgID;
  692. Assert(dlgID >= EXTERNAL_DIALOGID_MINIMUM);
  693. Assert(dlgID <= EXTERNAL_DIALOGID_MAXIMUM);
  694. m_pInitInfo[m_cPages].pApp = this;
  695. m_pInitInfo[m_cPages].ord = nPageIndex;
  696. psPage.lParam = (LPARAM)&m_pInitInfo[m_cPages];
  697. psPage.pszTemplate = MAKEINTRESOURCE(dlgID);
  698. if (dlgID == IDD_PAGE_CONNECT)
  699. {
  700. if (m_dwFlags & ACCT_WIZ_INTERNETCONNECTION)
  701. continue;
  702. else
  703. szID = ((m_acctType == ACCT_MAIL) ? idsMailConnectHeader : idsNewsConnectHeader);
  704. }
  705. else
  706. szID = g_pRequestedPageInfo[nPageIndex].uHdrID;
  707. LoadString(g_hInstRes, szID, sz, ARRAYSIZE(sz));
  708. psPage.pszHeaderTitle = sz;
  709. m_rgPage[m_cPages] = CreatePropertySheetPage(&psPage);
  710. if (m_rgPage[m_cPages] == NULL)
  711. {
  712. hr = E_FAIL;
  713. break;
  714. }
  715. m_cPages++;
  716. }
  717. exit:
  718. if (!FAILED(hr))
  719. {
  720. DWORD dwMajor = CommctrlMajor();
  721. if (m_acctType != ACCT_DIR_SERV)
  722. InitializeICW(m_acctType, m_acctType == ACCT_MAIL ? IDD_PAGE_MAILLOGON : IDD_PAGE_NEWSINFO, IDD_PAGE_COMPLETE);
  723. m_idPrevPage = -1;
  724. m_idNextPage = -1;
  725. psHeader.dwSize = sizeof(PROPSHEETHEADER);
  726. // OE Bug 71023
  727. // Wiz97 app compat related
  728. if (dwMajor >= 4)
  729. {
  730. if (dwMajor >= 5)
  731. psHeader.dwFlags = PSH_WIZARD97IE5 | PSH_STRETCHWATERMARK | PSH_WATERMARK;
  732. else
  733. psHeader.dwFlags = PSH_WIZARD97IE4;
  734. psHeader.dwFlags |= PSH_USEPAGELANG | PSH_HEADER;
  735. }
  736. else
  737. {
  738. // Something has gone wrong
  739. AssertSz(FALSE, "Commctrl has a major ver of less than 4!");
  740. hr = E_FAIL;
  741. }
  742. if (SUCCEEDED(hr))
  743. {
  744. // As long as commctrl was okay
  745. psHeader.hwndParent = hwnd;
  746. psHeader.hInstance = g_hInstRes;
  747. psHeader.nPages = m_cPages;
  748. psHeader.phpage = m_rgPage;
  749. psHeader.pszbmWatermark = MAKEINTRESOURCE(idbICW);
  750. psHeader.pszbmHeader = 0;
  751. psHeader.pfnCallback = AcctPropSheetProc;
  752. iRet = (int) PropertySheet(&psHeader);
  753. if (iRet == -1)
  754. {
  755. hr = E_FAIL;
  756. }
  757. else if (m_fReboot)
  758. {
  759. if (FGetSystemShutdownPrivledge() && ExitWindowsEx(EWX_REBOOT,0))
  760. hr = S_FALSE;
  761. else
  762. hr = E_FAIL;
  763. }
  764. else if (iRet == 0)
  765. {
  766. hr = S_FALSE;
  767. }
  768. else
  769. {
  770. hr = S_OK;
  771. }
  772. }
  773. if (m_pICW != NULL)
  774. {
  775. m_pICW->Release();
  776. m_pICW = NULL;
  777. }
  778. }
  779. else
  780. {
  781. for (nPageIndex = 0; nPageIndex < m_cPages; nPageIndex++)
  782. {
  783. if (m_rgPage[nPageIndex] != NULL)
  784. DestroyPropertySheetPage(m_rgPage[nPageIndex]);
  785. }
  786. }
  787. MemFree(m_rgPage);
  788. return(hr);
  789. }
  790. BOOL STDMETHODCALLTYPE CICWApprentice::AddExternalPage(HPROPSHEETPAGE hPage, UINT uDlgID)
  791. {
  792. UINT cPages;
  793. Assert(m_hDlg == NULL);
  794. Assert(m_rgPage != NULL);
  795. Assert(m_cPages > 0);
  796. Assert(m_cPages <= m_cPageBuf);
  797. if (hPage == NULL || uDlgID == 0)
  798. return(FALSE);
  799. if (m_cPages == m_cPageBuf)
  800. {
  801. cPages = m_cPageBuf + NUM_WIZARD_PAGES;
  802. if (!MemRealloc((void **)&m_rgPage, cPages * sizeof(HPROPSHEETPAGE)))
  803. return(FALSE);
  804. m_cPageBuf = cPages;
  805. }
  806. m_rgPage[m_cPages] = hPage;
  807. m_cPages++;
  808. return(TRUE);
  809. }
  810. BOOL STDMETHODCALLTYPE CICWApprentice::RemoveExternalPage(HPROPSHEETPAGE hPage, UINT uDlgID)
  811. {
  812. Assert(m_hDlg == NULL);
  813. // TODO: implement this
  814. return(FALSE);
  815. }
  816. BOOL STDMETHODCALLTYPE CICWApprentice::ExternalCancel(CANCELTYPE type)
  817. {
  818. BOOL fCancel;
  819. if (m_hDlg == NULL)
  820. {
  821. AssertSz(FALSE, "i don't think that this should be called yet");
  822. return(FALSE);
  823. }
  824. switch (type)
  825. {
  826. case CANCEL_PROMPT:
  827. fCancel = (IDYES == AcctMessageBox(m_hDlg, MAKEINTRESOURCE(idsConnectionWizard), MAKEINTRESOURCE(idsCancelWizard), NULL, MB_YESNO|MB_ICONEXCLAMATION |MB_DEFBUTTON2));
  828. break;
  829. case CANCEL_SILENT:
  830. PropSheet_PressButton(m_hDlg, PSBTN_CANCEL);
  831. fCancel = TRUE;
  832. break;
  833. case CANCEL_REBOOT:
  834. PropSheet_PressButton(m_hDlg, PSBTN_CANCEL);
  835. m_fReboot = TRUE;
  836. fCancel = TRUE;
  837. break;
  838. default:
  839. AssertSz(FALSE, "unexpected value");
  840. fCancel = FALSE;
  841. break;
  842. }
  843. return(fCancel);
  844. }
  845. BOOL STDMETHODCALLTYPE CICWApprentice::SetFirstLastPage(UINT uFirstPageDlgID, UINT uLastPageDlgID)
  846. {
  847. if (uFirstPageDlgID != 0)
  848. m_extFirstPage = uFirstPageDlgID;
  849. if (uLastPageDlgID != 0)
  850. m_extLastPage = uLastPageDlgID;
  851. Assert(m_extFirstPage != 0);
  852. Assert(m_extLastPage != 0);
  853. return(TRUE);
  854. }
  855. void CICWApprentice::InitializeICW(ACCTTYPE type, UINT uPrev, UINT uNext)
  856. {
  857. HRESULT hr;
  858. CONNECTINFO info;
  859. IImnAccount *pAcct;
  860. Assert(m_pAcct != NULL);
  861. ZeroMemory(&info, sizeof(CONNECTINFO));
  862. info.cbSize = sizeof(CONNECTINFO);
  863. if (SUCCEEDED(m_pAcct->GetPropDw(AP_RAS_CONNECTION_TYPE, &info.type)))
  864. {
  865. if (info.type == CONNECT_RAS)
  866. m_pAcct->GetPropSz(AP_RAS_CONNECTOID, info.szConnectoid, ARRAYSIZE(info.szConnectoid));
  867. }
  868. else
  869. {
  870. info.type = CONNECT_RAS;
  871. if (SUCCEEDED(m_pAcctMgr->GetDefaultAccount(type, &pAcct)))
  872. {
  873. if (SUCCEEDED(pAcct->GetPropDw(AP_RAS_CONNECTION_TYPE, &info.type)))
  874. {
  875. if (info.type == CONNECT_RAS)
  876. pAcct->GetPropSz(AP_RAS_CONNECTOID, info.szConnectoid, ARRAYSIZE(info.szConnectoid));
  877. }
  878. pAcct->Release();
  879. }
  880. }
  881. if ((m_dwFlags & ACCT_WIZ_INTERNETCONNECTION) == 0)
  882. {
  883. // get the ICW connection apprentice
  884. hr = CoCreateInstance(CLSID_ApprenticeICW, NULL, CLSCTX_INPROC_SERVER, IID_IICWApprentice, (void **)&m_pICW);
  885. if (SUCCEEDED(hr))
  886. {
  887. Assert(m_pICW != NULL);
  888. if (FAILED(m_pICW->Initialize((IICWExtension *)this)) ||
  889. FAILED(m_pICW->AddWizardPages(WIZ_USE_WIZARD97)))
  890. {
  891. m_pICW->Release();
  892. m_pICW = NULL;
  893. }
  894. hr = m_pICW->SetConnectionInformation(&info);
  895. Assert(!FAILED(hr));
  896. hr = m_pICW->SetPrevNextPage(uPrev, uNext);
  897. Assert(!FAILED(hr));
  898. }
  899. }
  900. }
  901. const static TCHAR c_szRegAcctImport[] = TEXT("Software\\Microsoft\\Internet Account Manager\\Import");
  902. const static TCHAR c_szRegFlags[] = TEXT("Flags");
  903. #define IMPORT_ONLY_OUTLOOK 0x0001
  904. #define IMPORT_NO_OUTLOOK 0x0002
  905. #define IMPORT_NEWS 0x0004
  906. HRESULT CICWApprentice::InitializeMigration(DWORD dwFlags)
  907. {
  908. HRESULT hr = S_OK;
  909. LONG lResult;
  910. BOOL fOutlook,
  911. fMailAcct;
  912. DWORD cImp,
  913. cb,
  914. i,
  915. cAcct,
  916. type,
  917. dwFlagsT;
  918. TCHAR szCLSID[MAX_PATH];
  919. HKEY hkey,
  920. hkeyT;
  921. LPWSTR pwszCLSID = NULL;
  922. CLSID clsid;
  923. IAccountImport *pImp = NULL;
  924. IAccountImport2 *pImp2 = NULL;
  925. Assert(m_pMigInfo == NULL);
  926. Assert(m_cMigInfo == 0);
  927. Assert(m_pAcctMgr != NULL);
  928. hr = S_OK;
  929. fOutlook = !!(dwFlags & ACCT_WIZ_OUTLOOK);
  930. fMailAcct = (m_acctType == ACCT_MAIL);
  931. if (ERROR_SUCCESS == RegOpenKeyEx(HKEY_LOCAL_MACHINE, c_szRegAcctImport, 0, KEY_READ, &hkey))
  932. {
  933. if (ERROR_SUCCESS == RegQueryInfoKey(hkey, NULL, NULL, 0, &cImp, NULL, NULL, NULL, NULL, NULL, NULL, NULL) &&
  934. cImp > 0)
  935. {
  936. cb = sizeof(MIGRATEINFO) * cImp;
  937. IF_NULLEXIT(MemAlloc((void **)&m_pMigInfo, cb));
  938. ZeroMemory(m_pMigInfo, cb);
  939. // Start Enumerating the keys
  940. for (i = 0; i < cImp; i++)
  941. {
  942. // Enumerate Friendly Names
  943. cb = sizeof(szCLSID);
  944. lResult = RegEnumKeyEx(hkey, i, szCLSID, &cb, 0, NULL, NULL, NULL);
  945. // No more items
  946. if (lResult == ERROR_NO_MORE_ITEMS)
  947. break;
  948. // Error, lets move onto the next account
  949. if (lResult != ERROR_SUCCESS)
  950. {
  951. Assert(FALSE);
  952. continue;
  953. }
  954. if (ERROR_SUCCESS == RegOpenKeyEx(hkey, szCLSID, 0, KEY_QUERY_VALUE, &hkeyT))
  955. {
  956. cb = sizeof(DWORD);
  957. dwFlagsT = 0;
  958. if (ERROR_SUCCESS == RegQueryValueEx(hkeyT, c_szRegFlags, NULL, &type, (LPBYTE)&dwFlagsT, &cb))
  959. {
  960. if ((fOutlook && !!(dwFlagsT & IMPORT_NO_OUTLOOK)) ||
  961. (!fOutlook && !!(dwFlagsT & IMPORT_ONLY_OUTLOOK)) ||
  962. (fMailAcct && (dwFlagsT & IMPORT_NEWS)) ||
  963. (!fMailAcct && !(dwFlagsT & IMPORT_NEWS)))
  964. {
  965. RegCloseKey(hkeyT);
  966. continue;
  967. }
  968. }
  969. else
  970. {
  971. if (!fMailAcct)
  972. {
  973. RegCloseKey(hkeyT);
  974. continue;
  975. }
  976. }
  977. IF_NULLEXIT(pwszCLSID = PszToUnicode(CP_ACP, szCLSID));
  978. IF_FAILEXIT(hr = CLSIDFromString(pwszCLSID, &clsid));
  979. SafeMemFree(pwszCLSID);
  980. if (SUCCEEDED(CoCreateInstance(clsid, NULL, CLSCTX_INPROC_SERVER, IID_IAccountImport, (void **)&pImp)))
  981. {
  982. hr = pImp->AutoDetect(&cAcct, dwFlags);
  983. if (dwFlags && (hr == E_INVALIDARG))
  984. hr = pImp->AutoDetect(&cAcct, 0);
  985. if (S_OK == hr && cAcct > 0)
  986. {
  987. cb = sizeof(m_pMigInfo[m_cMigInfo].szDisplay);
  988. RegQueryValueEx(hkeyT, NULL, NULL, &type, (LPBYTE)m_pMigInfo[m_cMigInfo].szDisplay, &cb);
  989. m_pMigInfo[m_cMigInfo].pImp = pImp;
  990. pImp = NULL;
  991. m_pMigInfo[m_cMigInfo].cAccts = cAcct;
  992. if (SUCCEEDED(m_pMigInfo[m_cMigInfo].pImp->QueryInterface(IID_IAccountImport2, (void **)&pImp2)))
  993. {
  994. m_pMigInfo[m_cMigInfo].pImp2 = pImp2;
  995. pImp2 = NULL;
  996. }
  997. m_cMigInfo++;
  998. }
  999. else
  1000. {
  1001. SafeRelease(pImp);
  1002. }
  1003. }
  1004. RegCloseKey(hkeyT);
  1005. }
  1006. }
  1007. }
  1008. }
  1009. hkeyT = 0;
  1010. exit:
  1011. if (hkeyT)
  1012. RegCloseKey(hkeyT);
  1013. if (hkey)
  1014. RegCloseKey(hkey);
  1015. MemFree(pwszCLSID);
  1016. return(hr);
  1017. }
  1018. HRESULT CICWApprentice::InitializeImport(CLSID clsid, DWORD dwFlags)
  1019. {
  1020. HRESULT hr;
  1021. DWORD cb, cAcct;
  1022. IAccountImport *pImp;
  1023. Assert(m_pMigInfo == NULL);
  1024. Assert(m_cMigInfo == 0);
  1025. Assert(m_pAcctMgr != NULL);
  1026. hr = E_FAIL;
  1027. cb = sizeof(MIGRATEINFO);
  1028. if (!MemAlloc((void **)&m_pMigInfo, cb))
  1029. return(E_OUTOFMEMORY);
  1030. ZeroMemory(m_pMigInfo, cb);
  1031. if (SUCCEEDED(CoCreateInstance(clsid, NULL, CLSCTX_INPROC_SERVER, IID_IAccountImport, (void **)&pImp)))
  1032. {
  1033. hr = pImp->AutoDetect(&cAcct, dwFlags);
  1034. if (dwFlags && (E_INVALIDARG == hr))
  1035. // 72961 - OL98's OE importer will return E_INVALIDARG with non-zero flags
  1036. hr = pImp->AutoDetect(&cAcct, 0);
  1037. if (S_OK == hr && cAcct > 0)
  1038. {
  1039. m_pMigInfo[m_cMigInfo].pImp = pImp;
  1040. m_pMigInfo[m_cMigInfo].cAccts = cAcct;
  1041. m_cMigInfo++;
  1042. }
  1043. else
  1044. {
  1045. pImp->Release();
  1046. hr = E_NoAccounts;
  1047. }
  1048. }
  1049. return(hr);
  1050. }
  1051. UINT CICWApprentice::GetNextWizSection()
  1052. {
  1053. ACCTTYPE type;
  1054. if (0 == (m_dwFlags & ACCT_WIZ_IN_ICW))
  1055. {
  1056. if (0 == (m_dwFlags & ACCT_WIZ_INTERNETCONNECTION))
  1057. {
  1058. if (m_pICW != NULL)
  1059. return(CONNECT_DLG);
  1060. return(c_rgOrdNewAcct[m_acctType]);
  1061. }
  1062. else
  1063. {
  1064. return (c_rgOEOrdNewAcct[m_acctType]);
  1065. }
  1066. }
  1067. return(EXTERN_DLG);
  1068. }
  1069. HRESULT CICWApprentice::InitAccountData(CAccount *pAcct, IMPCONNINFO *pConnInfo, BOOL fMigrate)
  1070. {
  1071. DWORD dw;
  1072. HRESULT hr;
  1073. CAccount *pAcctDef = NULL;
  1074. Assert(m_pAcctMgr != NULL);
  1075. Assert((!fMigrate) ^ (pConnInfo != NULL));
  1076. #ifdef DEBUG
  1077. if (fMigrate)
  1078. Assert((m_acctType == ACCT_MAIL) || (m_acctType == ACCT_NEWS));
  1079. #endif // DEBUG
  1080. m_fMigrate = fMigrate;
  1081. m_dwReload |= ALL_PAGE;
  1082. m_fComplete = TRUE;
  1083. m_pData->fCreateNewAccount = false;
  1084. m_pData->iServiceIndex = -1;
  1085. m_pData->iNewServiceIndex = 0;
  1086. m_pData->fDomainMSN = FALSE;
  1087. if (m_pData->pAcct != NULL)
  1088. m_pData->pAcct->Release();
  1089. ZeroMemory(m_pData, sizeof(ACCTDATA));
  1090. if (fMigrate)
  1091. {
  1092. Assert(pAcct != NULL);
  1093. m_pData->pAcct = pAcct;
  1094. m_pData->pAcct->AddRef();
  1095. }
  1096. if (pAcct == NULL)
  1097. {
  1098. Assert(!fMigrate);
  1099. if (m_acctType == ACCT_DIR_SERV)
  1100. return(S_OK);
  1101. if (FAILED(m_pAcctMgr->GetDefaultAccount(m_acctType, (IImnAccount **)&pAcctDef)))
  1102. return(S_OK);
  1103. pAcct = pAcctDef;
  1104. }
  1105. else
  1106. {
  1107. hr = pAcct->GetPropSz(AP_ACCOUNT_NAME, m_pData->szAcctOrig, ARRAYSIZE(m_pData->szAcctOrig));
  1108. if (fMigrate && *m_pData->szAcctOrig != 0)
  1109. {
  1110. hr = m_pAcctMgr->GetUniqueAccountName(m_pData->szAcctOrig, ARRAYSIZE(m_pData->szAcctOrig));
  1111. Assert(SUCCEEDED(hr));
  1112. }
  1113. StrCpyN(m_pData->szAcct, m_pData->szAcctOrig, ARRAYSIZE(m_pData->szAcct));
  1114. }
  1115. if (m_acctType != ACCT_DIR_SERV)
  1116. {
  1117. if (fMigrate)
  1118. {
  1119. switch (pConnInfo->dwConnect)
  1120. {
  1121. case CONN_USE_DEFAULT:
  1122. if (!!(m_dwFlags & ACCT_WIZ_INTERNETCONNECTION))
  1123. {
  1124. hr = GetConnectInfoForOE(pAcct);
  1125. }
  1126. else
  1127. {
  1128. hr = GetIEConnectInfo(pAcct);
  1129. }
  1130. if (SUCCEEDED(hr))
  1131. hr = GetAcctConnectInfo(pAcct, m_pData);
  1132. break;
  1133. case CONN_USE_SETTINGS:
  1134. m_pData->dwConnect = pConnInfo->dwConnectType;
  1135. if (m_pData->dwConnect == CONNECTION_TYPE_RAS)
  1136. StrCpyN(m_pData->szConnectoid, pConnInfo->szConnectoid, ARRAYSIZE(m_pData->szConnectoid));
  1137. hr = S_OK;
  1138. break;
  1139. case CONN_NO_INFO:
  1140. // TODO: should we use IE connection in this case???
  1141. case CONN_CREATE_ENTRY:
  1142. // TODO: handle this case
  1143. default:
  1144. hr = E_FAIL;
  1145. break;
  1146. }
  1147. }
  1148. else
  1149. {
  1150. hr = GetAcctConnectInfo(pAcct, m_pData);
  1151. if (FAILED(hr))
  1152. {
  1153. if (!!(m_dwFlags & ACCT_WIZ_INTERNETCONNECTION))
  1154. {
  1155. hr = GetConnectInfoForOE(pAcct);
  1156. }
  1157. else
  1158. {
  1159. hr = GetIEConnectInfo(pAcct);
  1160. }
  1161. if (SUCCEEDED(hr))
  1162. hr = GetAcctConnectInfo(pAcct, m_pData);
  1163. }
  1164. }
  1165. if (FAILED(hr))
  1166. m_fComplete = FALSE;
  1167. }
  1168. switch (m_acctType)
  1169. {
  1170. case ACCT_NEWS:
  1171. if (!GetRequiredAccountProp(pAcct, AP_NNTP_DISPLAY_NAME, m_pData->szName, ARRAYSIZE(m_pData->szName)))
  1172. m_fComplete = FALSE;
  1173. if (!GetRequiredAccountProp(pAcct, AP_NNTP_EMAIL_ADDRESS, m_pData->szEmail, ARRAYSIZE(m_pData->szEmail)))
  1174. m_fComplete = FALSE;
  1175. if (pAcctDef != NULL)
  1176. break;
  1177. if (!GetRequiredAccountProp(pAcct, AP_NNTP_SERVER, m_pData->szSvr1, ARRAYSIZE(m_pData->szSvr1)))
  1178. m_fComplete = FALSE;
  1179. hr = pAcct->GetPropSz(AP_NNTP_USERNAME, m_pData->szUsername, ARRAYSIZE(m_pData->szUsername));
  1180. if (SUCCEEDED(hr))
  1181. m_pData->fLogon = TRUE;
  1182. hr = pAcct->GetPropDw(AP_NNTP_PROMPT_PASSWORD, &m_pData->fAlwaysPromptPassword);
  1183. if (FAILED(hr) || !m_pData->fAlwaysPromptPassword)
  1184. pAcct->GetPropSz(AP_NNTP_PASSWORD, m_pData->szPassword, ARRAYSIZE(m_pData->szPassword));
  1185. hr = pAcct->GetPropDw(AP_NNTP_USE_SICILY, &dw);
  1186. if (SUCCEEDED(hr) && dw != 0)
  1187. {
  1188. m_pData->fSPA = TRUE;
  1189. m_pData->fLogon = TRUE;
  1190. }
  1191. break;
  1192. case ACCT_MAIL:
  1193. if (!GetRequiredAccountProp(pAcct, AP_SMTP_DISPLAY_NAME, m_pData->szName, ARRAYSIZE(m_pData->szName)))
  1194. m_fComplete = FALSE;
  1195. if (!GetRequiredAccountProp(pAcct, AP_SMTP_EMAIL_ADDRESS, m_pData->szEmail, ARRAYSIZE(m_pData->szEmail)))
  1196. m_fComplete = FALSE;
  1197. if (pAcctDef != NULL)
  1198. break;
  1199. hr = pAcct->GetServerTypes(&dw);
  1200. if (SUCCEEDED(hr))
  1201. m_pData->fServerTypes = dw;
  1202. if (!GetRequiredAccountProp(pAcct, (m_pData->fServerTypes & SRV_IMAP) ? AP_IMAP_SERVER : AP_POP3_SERVER,
  1203. m_pData->szSvr1, ARRAYSIZE(m_pData->szSvr1)))
  1204. m_fComplete = FALSE;
  1205. if (!GetRequiredAccountProp(pAcct, AP_SMTP_SERVER, m_pData->szSvr2, ARRAYSIZE(m_pData->szSvr2)))
  1206. m_fComplete = FALSE;
  1207. hr = pAcct->GetPropSz((m_pData->fServerTypes & SRV_IMAP) ? AP_IMAP_USERNAME : AP_POP3_USERNAME,
  1208. m_pData->szUsername, ARRAYSIZE(m_pData->szUsername));
  1209. if (SUCCEEDED(hr))
  1210. m_pData->fLogon = TRUE;
  1211. hr = pAcct->GetPropDw((m_pData->fServerTypes & SRV_IMAP) ? AP_IMAP_PROMPT_PASSWORD : AP_POP3_PROMPT_PASSWORD,
  1212. &m_pData->fAlwaysPromptPassword);
  1213. if (FAILED(hr) || !m_pData->fAlwaysPromptPassword)
  1214. pAcct->GetPropSz((m_pData->fServerTypes & SRV_IMAP) ? AP_IMAP_PASSWORD : AP_POP3_PASSWORD,
  1215. m_pData->szPassword, ARRAYSIZE(m_pData->szPassword));
  1216. hr = pAcct->GetPropDw((m_pData->fServerTypes & SRV_IMAP) ? AP_IMAP_USE_SICILY : AP_POP3_USE_SICILY, &dw);
  1217. if (SUCCEEDED(hr) && dw != 0)
  1218. {
  1219. m_pData->fSPA = TRUE;
  1220. m_pData->fLogon = TRUE;
  1221. }
  1222. if (!m_pData->fLogon)
  1223. {
  1224. // for mail we have to have logon
  1225. m_fComplete = FALSE;
  1226. }
  1227. break;
  1228. case ACCT_DIR_SERV:
  1229. if (!GetRequiredAccountProp(pAcct, AP_LDAP_SERVER, m_pData->szSvr1, ARRAYSIZE(m_pData->szSvr1)))
  1230. m_fComplete = FALSE;
  1231. hr = pAcct->GetPropDw(AP_LDAP_AUTHENTICATION, &dw);
  1232. if (SUCCEEDED(hr))
  1233. {
  1234. if (dw == LDAP_AUTH_PASSWORD)
  1235. {
  1236. m_pData->fLogon = TRUE;
  1237. hr = pAcct->GetPropSz(AP_LDAP_USERNAME, m_pData->szUsername, ARRAYSIZE(m_pData->szUsername));
  1238. if (SUCCEEDED(hr))
  1239. pAcct->GetPropSz(AP_LDAP_PASSWORD, m_pData->szPassword, ARRAYSIZE(m_pData->szPassword));
  1240. }
  1241. else if (dw == LDAP_AUTH_MEMBER_SYSTEM)
  1242. {
  1243. m_pData->fLogon = TRUE;
  1244. m_pData->fSPA = TRUE;
  1245. hr = pAcct->GetPropSz(AP_LDAP_USERNAME, m_pData->szUsername, ARRAYSIZE(m_pData->szUsername));
  1246. if (SUCCEEDED(hr))
  1247. pAcct->GetPropSz(AP_LDAP_PASSWORD, m_pData->szPassword, ARRAYSIZE(m_pData->szPassword));
  1248. }
  1249. }
  1250. hr = pAcct->GetPropDw(AP_LDAP_RESOLVE_FLAG, &dw);
  1251. if (SUCCEEDED(hr))
  1252. m_pData->fResolve = (dw != 0);
  1253. break;
  1254. }
  1255. if (pAcctDef != NULL)
  1256. pAcctDef->Release();
  1257. return(S_OK);
  1258. }
  1259. // TODO: how about some error handling???
  1260. HRESULT CICWApprentice::SaveAccountData(CAccount *pAcct, BOOL fSetAsDefault)
  1261. {
  1262. HRESULT hr;
  1263. DWORD dw;
  1264. LPMAILSERVERPROPSINFO pProps = NULL;
  1265. if (pAcct == NULL)
  1266. pAcct = m_pAcct;
  1267. if (m_pData->pAcct != NULL)
  1268. {
  1269. Assert(m_fMigrate);
  1270. pAcct = m_pData->pAcct;
  1271. }
  1272. pAcct->SetPropSz(AP_ACCOUNT_NAME, m_pData->szAcct);
  1273. pAcct->SetPropDw(AP_RAS_CONNECTION_TYPE, m_pData->dwConnect);
  1274. // if (m_pData->dwConnect == CONNECTION_TYPE_RAS || m_pData->dwConnect == CONNECTION_TYPE_INETSETTINGS)
  1275. if (m_pData->dwConnect == CONNECTION_TYPE_RAS)
  1276. pAcct->SetPropSz(AP_RAS_CONNECTOID, m_pData->szConnectoid);
  1277. else
  1278. pAcct->SetProp(AP_RAS_CONNECTOID, NULL, 0);
  1279. switch (m_acctType)
  1280. {
  1281. case ACCT_NEWS:
  1282. pAcct->SetPropSz(AP_NNTP_DISPLAY_NAME, m_pData->szName);
  1283. pAcct->SetPropSz(AP_NNTP_EMAIL_ADDRESS, m_pData->szEmail);
  1284. pAcct->SetPropSz(AP_NNTP_SERVER, m_pData->szSvr1);
  1285. pAcct->SetProp(AP_NNTP_USERNAME, NULL, 0);
  1286. pAcct->SetProp(AP_NNTP_PASSWORD, NULL, 0);
  1287. pAcct->SetProp(AP_NNTP_USE_SICILY, NULL, 0);
  1288. if (m_pData->fLogon)
  1289. {
  1290. pAcct->SetPropDw(AP_NNTP_USE_SICILY, m_pData->fSPA);
  1291. pAcct->SetPropSz(AP_NNTP_USERNAME, m_pData->szUsername);
  1292. pAcct->SetPropDw(AP_NNTP_PROMPT_PASSWORD, m_pData->fAlwaysPromptPassword);
  1293. if (!m_pData->fAlwaysPromptPassword)
  1294. pAcct->SetPropSz(AP_NNTP_PASSWORD, m_pData->szPassword);
  1295. }
  1296. break;
  1297. case ACCT_MAIL:
  1298. pAcct->SetPropSz(AP_SMTP_DISPLAY_NAME, m_pData->szName);
  1299. pAcct->SetPropSz(AP_SMTP_EMAIL_ADDRESS, m_pData->szEmail);
  1300. if (0 == (m_pData->fServerTypes & SRV_HTTPMAIL))
  1301. pAcct->SetProp(AP_HTTPMAIL_SERVER, NULL, 0);
  1302. if (0 == (m_pData->fServerTypes & SRV_IMAP))
  1303. pAcct->SetProp(AP_IMAP_SERVER, NULL, 0);
  1304. if (0 == (m_pData->fServerTypes & SRV_POP3))
  1305. pAcct->SetProp(AP_POP3_SERVER, NULL, 0);
  1306. if (m_pData->fServerTypes & SRV_SMTP)
  1307. pAcct->SetPropSz(AP_SMTP_SERVER, m_pData->szSvr2);
  1308. else
  1309. pAcct->SetProp(AP_SMTP_SERVER, NULL, 0);
  1310. if (m_pData->fServerTypes & SRV_HTTPMAIL)
  1311. {
  1312. GetServerProps(SERVER_HTTPMAIL, &pProps);
  1313. pAcct->SetPropSz(AP_HTTPMAIL_FRIENDLY_NAME, m_pData->szFriendlyServiceName);
  1314. if (m_pData->fDomainMSN)
  1315. pAcct->SetPropDw(AP_HTTPMAIL_DOMAIN_MSN, m_pData->fDomainMSN);
  1316. }
  1317. else if (m_pData->fServerTypes & SRV_IMAP)
  1318. GetServerProps(SERVER_IMAP, &pProps);
  1319. else
  1320. GetServerProps(SERVER_MAIL, &pProps);
  1321. Assert(pProps);
  1322. pAcct->SetPropSz(pProps->server, m_pData->szSvr1);
  1323. pAcct->SetPropDw(pProps->useSicily, m_pData->fSPA);
  1324. pAcct->SetPropSz(pProps->userName, m_pData->szUsername);
  1325. pAcct->SetPropDw(pProps->promptPassword, m_pData->fAlwaysPromptPassword);
  1326. if (m_pData->fAlwaysPromptPassword)
  1327. pAcct->SetProp(pProps->password, NULL, 0);
  1328. else
  1329. pAcct->SetPropSz(pProps->password, m_pData->szPassword);
  1330. break;
  1331. case ACCT_DIR_SERV:
  1332. pAcct->SetPropSz(AP_LDAP_SERVER, m_pData->szSvr1);
  1333. pAcct->SetProp(AP_LDAP_USERNAME, NULL, 0);
  1334. pAcct->SetProp(AP_LDAP_PASSWORD, NULL, 0);
  1335. if (m_pData->fLogon)
  1336. {
  1337. pAcct->SetPropSz(AP_LDAP_USERNAME, m_pData->szUsername);
  1338. pAcct->SetPropSz(AP_LDAP_PASSWORD, m_pData->szPassword);
  1339. if (m_pData->fSPA)
  1340. {
  1341. dw = LDAP_AUTH_MEMBER_SYSTEM;
  1342. }
  1343. else
  1344. {
  1345. dw = LDAP_AUTH_PASSWORD;
  1346. }
  1347. }
  1348. else
  1349. {
  1350. dw = LDAP_AUTH_ANONYMOUS;
  1351. }
  1352. pAcct->SetPropDw(AP_LDAP_AUTHENTICATION, dw);
  1353. pAcct->SetPropDw(AP_LDAP_RESOLVE_FLAG, m_pData->fResolve);
  1354. break;
  1355. }
  1356. hr = pAcct->SaveChanges();
  1357. if (SUCCEEDED(hr) && fSetAsDefault)
  1358. pAcct->SetAsDefault();
  1359. // OE Bug 67399
  1360. // Make sure this account does not remain marked as Incomplete
  1361. // We currently only mark mail and news account as incomplete
  1362. if ((ACCT_MAIL == m_acctType) || (ACCT_NEWS == m_acctType))
  1363. {
  1364. char szIncomplete[CCHMAX_ACCOUNT_NAME];
  1365. char szCurrID [CCHMAX_ACCOUNT_NAME];
  1366. // Need to exclusively check for S_OK...
  1367. if (S_OK == m_pAcctMgr->GetIncompleteAccount(m_acctType, szIncomplete, ARRAYSIZE(szIncomplete)))
  1368. {
  1369. // Is the incomplete account, this account?
  1370. if (SUCCEEDED(pAcct->GetPropSz(AP_ACCOUNT_ID, szCurrID, ARRAYSIZE(szCurrID))))
  1371. {
  1372. if (!lstrcmpi(szIncomplete, szCurrID))
  1373. {
  1374. m_pAcctMgr->SetIncompleteAccount(m_acctType, NULL);
  1375. }
  1376. }
  1377. else
  1378. AssertSz(0, "Account with no ID?!");
  1379. }
  1380. }
  1381. return(hr);
  1382. }
  1383. HRESULT CICWApprentice::InitializeImportAccount(HWND hwnd, DWORD_PTR dwCookie)
  1384. {
  1385. HRESULT hr;
  1386. IAccountImport *pImp;
  1387. IAccountImport2 *pImp2;
  1388. IMPCONNINFO conninfo;
  1389. CAccount *pAcct;
  1390. pImp = m_pMigInfo[m_iMigInfo].pImp;
  1391. Assert(pImp != NULL);
  1392. pImp2 = m_pMigInfo[m_iMigInfo].pImp2;
  1393. // TODO: verify that the user profile selection works properly
  1394. if (m_acctType == ACCT_NEWS && pImp2 != NULL)
  1395. {
  1396. // This is where we handle the possibility of a news account having subscribed to multiple servers.
  1397. if (FAILED(hr = pImp2->InitializeImport(hwnd, dwCookie)))
  1398. return(hr);
  1399. }
  1400. if (SUCCEEDED(hr = m_pAcctMgr->CreateAccountObject(m_acctType, (IImnAccount **)&pAcct)))
  1401. {
  1402. ZeroMemory(&conninfo, sizeof(IMPCONNINFO));
  1403. conninfo.cbSize = sizeof(IMPCONNINFO);
  1404. if (pImp2 != NULL)
  1405. hr = pImp2->GetSettings2(dwCookie, pAcct, &conninfo);
  1406. else
  1407. hr = pImp->GetSettings(dwCookie, pAcct);
  1408. if (SUCCEEDED(hr))
  1409. {
  1410. hr = InitAccountData(pAcct, &conninfo, TRUE);
  1411. Assert(!FAILED(hr));
  1412. }
  1413. pAcct->Release();
  1414. }
  1415. return(hr);
  1416. }
  1417. HRESULT CICWApprentice::HandleMigrationSelection(int index, UINT *puNextPage, HWND hDlg)
  1418. {
  1419. HRESULT hr;
  1420. IAccountImport *pImp;
  1421. IEnumIMPACCOUNTS *pEnum;
  1422. IMPACCOUNTINFO impinfo;
  1423. Assert(m_cMigInfo > 0);
  1424. if (m_iMigInfo != index)
  1425. {
  1426. m_iMigInfo = index;
  1427. if (m_pMigInfo[index].cAccts > 1)
  1428. {
  1429. m_dwReload |= SELECT_PAGE;
  1430. }
  1431. else
  1432. {
  1433. pImp = m_pMigInfo[index].pImp;
  1434. Assert(pImp != NULL);
  1435. if (S_OK == (hr = pImp->EnumerateAccounts(&pEnum)))
  1436. {
  1437. Assert(pEnum != NULL);
  1438. if (SUCCEEDED(hr = pEnum->Next(&impinfo)))
  1439. hr = InitializeImportAccount(hDlg, impinfo.dwCookie);
  1440. pEnum->Release();
  1441. }
  1442. if (FAILED(hr))
  1443. return(hr);
  1444. }
  1445. }
  1446. if (m_pMigInfo[index].cAccts > 1)
  1447. {
  1448. if (m_acctType == ACCT_MAIL)
  1449. *puNextPage = ORD_PAGE_MIGRATESELECT;
  1450. else
  1451. *puNextPage = ORD_PAGE_NEWSACCTSELECT;
  1452. }
  1453. else
  1454. {
  1455. if (m_acctType == ACCT_MAIL)
  1456. {
  1457. if (m_fComplete)
  1458. *puNextPage = ORD_PAGE_MAILCONFIRM;
  1459. else
  1460. *puNextPage = ORD_PAGE_MAILNAME;
  1461. }
  1462. else
  1463. {
  1464. if (m_fComplete)
  1465. *puNextPage = ORD_PAGE_NEWSCONFIRM;
  1466. else
  1467. *puNextPage = ORD_PAGE_NEWSNAME;
  1468. }
  1469. }
  1470. return(S_OK);
  1471. }
  1472. BOOL FGetSystemShutdownPrivledge()
  1473. {
  1474. OSVERSIONINFO osinfo;
  1475. TOKEN_PRIVILEGES tkp;
  1476. HANDLE hToken = NULL;
  1477. BOOL bRC = FALSE;
  1478. osinfo.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
  1479. GetVersionEx(&osinfo);
  1480. if (osinfo.dwPlatformId == VER_PLATFORM_WIN32_NT)
  1481. {
  1482. if (OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, &hToken))
  1483. {
  1484. Assert(hToken != NULL);
  1485. ZeroMemory(&tkp, sizeof(tkp));
  1486. LookupPrivilegeValue(NULL, SE_SHUTDOWN_NAME, &tkp.Privileges[0].Luid);
  1487. tkp.PrivilegeCount = 1; /* one privilege to set */
  1488. tkp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
  1489. AdjustTokenPrivileges(hToken, FALSE, &tkp, 0, (PTOKEN_PRIVILEGES) NULL, 0);
  1490. if (ERROR_SUCCESS == GetLastError())
  1491. bRC = TRUE;
  1492. CloseHandle(hToken);
  1493. }
  1494. }
  1495. else
  1496. {
  1497. bRC = TRUE;
  1498. }
  1499. return(bRC);
  1500. }
  1501. CNewsGroupImport::CNewsGroupImport()
  1502. {
  1503. m_cRef = 1;
  1504. m_pAcct = NULL;
  1505. }
  1506. CNewsGroupImport::~CNewsGroupImport()
  1507. {
  1508. if (m_pAcct != NULL)
  1509. m_pAcct->Release();
  1510. }
  1511. STDMETHODIMP CNewsGroupImport::QueryInterface(REFIID riid, LPVOID *pNews)
  1512. {
  1513. if (pNews == NULL)
  1514. return(E_INVALIDARG);
  1515. *pNews = NULL;
  1516. if (riid == IID_INewsGroupImport || riid == IID_IUnknown)
  1517. *pNews = (void*)(INewsGroupImport*)this;
  1518. else
  1519. return(E_NOINTERFACE);
  1520. ((LPUNKNOWN)*pNews)->AddRef();
  1521. return(S_OK);
  1522. }
  1523. ULONG CNewsGroupImport::AddRef(void)
  1524. {
  1525. return ++m_cRef;
  1526. }
  1527. ULONG CNewsGroupImport::Release(void)
  1528. {
  1529. if(--m_cRef == 0)
  1530. {
  1531. delete this;
  1532. return 0;
  1533. }
  1534. return m_cRef;
  1535. }
  1536. HRESULT CNewsGroupImport::Initialize(IImnAccount *pAcct)
  1537. {
  1538. m_pAcct = pAcct;
  1539. m_pAcct->AddRef();
  1540. return S_OK;
  1541. }
  1542. HRESULT CNewsGroupImport::ImportSubList(LPCSTR pListGroups)
  1543. {
  1544. PFNSUBNEWSGROUP lpfnNewsGroup = NULL;
  1545. HINSTANCE hInstance;
  1546. HRESULT hr = S_FALSE;
  1547. hInstance = LoadLibrary(c_szMainDll);
  1548. if (hInstance != NULL)
  1549. {
  1550. if ((lpfnNewsGroup = (PFNSUBNEWSGROUP)GetProcAddress(hInstance, MAKEINTRESOURCE(17))) != NULL)
  1551. {
  1552. if (!SUCCEEDED(lpfnNewsGroup(NULL, m_pAcct, pListGroups)))
  1553. hr = S_FALSE;
  1554. else
  1555. hr = S_OK;
  1556. }
  1557. FreeLibrary(hInstance);
  1558. }
  1559. return hr;
  1560. }
  1561. static const char c_szComctl32Dll[] = "comctl32.dll";
  1562. static const char c_szDllGetVersion[] = "DllGetVersion";
  1563. DWORD CommctrlMajor()
  1564. {
  1565. HINSTANCE hinst;
  1566. DLLGETVERSIONPROC pfnVersion;
  1567. DLLVERSIONINFO info;
  1568. static BOOL s_fInit = FALSE;
  1569. static DWORD s_dwMajor = 0;
  1570. if (!s_fInit)
  1571. {
  1572. s_fInit = TRUE;
  1573. hinst = LoadLibrary(c_szComctl32Dll);
  1574. if (hinst != NULL)
  1575. {
  1576. pfnVersion = (DLLGETVERSIONPROC)GetProcAddress(hinst, c_szDllGetVersion);
  1577. if (pfnVersion != NULL)
  1578. {
  1579. info.cbSize = sizeof(DLLVERSIONINFO);
  1580. if (SUCCEEDED(pfnVersion(&info)))
  1581. {
  1582. s_dwMajor = info.dwMajorVersion;
  1583. }
  1584. }
  1585. FreeLibrary(hinst);
  1586. }
  1587. }
  1588. return(s_dwMajor);
  1589. }