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

1737 lines
53 KiB

  1. // compdata.cpp : Implementation of CFileMgmtComponentData
  2. /*
  3. History:
  4. 8/20/97 EricDav
  5. Added Configure File Server for Macintosh menu item to the
  6. root node. Only shows up if SFM is installed and the user
  7. has admin access to that machine.
  8. */
  9. #include "stdafx.h"
  10. #include "cookie.h"
  11. #include "safetemp.h"
  12. #include "macros.h"
  13. USE_HANDLE_MACROS("FILEMGMT(compdata.cpp)")
  14. #include "dataobj.h"
  15. #include "compdata.h"
  16. #include "cmponent.h"
  17. #include "DynamLnk.h" // DynamicDLL
  18. #include "FileSvc.h" // FileServiceProvider
  19. #include "smb.h"
  20. #include "fpnw.h"
  21. #include "sfm.h"
  22. #include "SnapMgr.h" // CFileMgtGeneral: Snapin Manager property page
  23. #include "chooser2.h" // CHOOSER2_PickTargetComputer
  24. #include <compuuid.h> // UUIDs for Computer Management
  25. #include <safeboot.h> // for SAFEBOOT_MINIMAL
  26. #include <shlwapi.h> // for IsOS
  27. #include <shlwapip.h> // for IsOS
  28. #ifdef _DEBUG
  29. #define new DEBUG_NEW
  30. #undef THIS_FILE
  31. static char THIS_FILE[] = __FILE__;
  32. #endif
  33. #include "stdcdata.cpp" // CComponentData implementation
  34. #include "chooser2.cpp" // CHOOSER2_PickTargetComputer implementation
  35. //
  36. // CFileMgmtComponentData
  37. //
  38. CString g_strTransportSMB;
  39. CString g_strTransportSFM;
  40. CString g_strTransportFPNW;
  41. BOOL g_fTransportStringsLoaded = FALSE;
  42. CFileMgmtComponentData::CFileMgmtComponentData()
  43. : m_fLoadedFileMgmtToolbarBitmap(FALSE),
  44. m_fLoadedSvcMgmtToolbarBitmap(FALSE),
  45. m_pRootCookie( NULL ),
  46. m_hScManager( NULL ),
  47. m_SchemaSupportSharePublishing(SHAREPUBLISH_SCHEMA_UNASSIGNED),
  48. m_bIsSimpleUI(FALSE),
  49. m_fQueryServiceConfig2( TRUE ) // Pretend the target machine does support QueryServiceConfig2() API
  50. {
  51. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  52. //
  53. // We must refcount the root cookie, since a dataobject for it
  54. // might outlive the IComponentData. JonN 9/2/97
  55. //
  56. m_pRootCookie = new CFileMgmtScopeCookie();
  57. ASSERT(NULL != m_pRootCookie);
  58. // JonN 10/27/98 All CRefcountedObject's start with refcount==1
  59. // m_pRootCookie->AddRef();
  60. m_apFileServiceProviders[FILEMGMT_SMB] = new SmbFileServiceProvider(this);
  61. m_apFileServiceProviders[FILEMGMT_FPNW] = new FpnwFileServiceProvider(this);
  62. m_apFileServiceProviders[FILEMGMT_SFM] = new SfmFileServiceProvider(this);
  63. m_dwFlagsPersist = 0;
  64. m_fAllowOverrideMachineName = TRUE;
  65. ASSERT( 3 == FILEMGMT_NUM_TRANSPORTS );
  66. #ifdef SNAPIN_PROTOTYPER
  67. m_RegistryParsedYet = FALSE;
  68. #endif
  69. if (!g_fTransportStringsLoaded)
  70. {
  71. g_fTransportStringsLoaded = TRUE;
  72. VERIFY( g_strTransportSMB.LoadString(IDS_TRANSPORT_SMB) );
  73. VERIFY( g_strTransportSFM.LoadString(IDS_TRANSPORT_SFM) );
  74. VERIFY( g_strTransportFPNW.LoadString(IDS_TRANSPORT_FPNW) );
  75. }
  76. }
  77. CFileMgmtComponentData::~CFileMgmtComponentData()
  78. {
  79. AFX_MANAGE_STATE(AfxGetStaticModuleState()); // required for CWaitCursor
  80. for (INT i = 0; i < FILEMGMT_NUM_TRANSPORTS; i++)
  81. {
  82. delete m_apFileServiceProviders[i];
  83. m_apFileServiceProviders[i] = NULL;
  84. }
  85. // Close the service control manager
  86. Service_CloseScManager();
  87. m_pRootCookie->Release();
  88. m_pRootCookie = NULL;
  89. }
  90. DEFINE_FORWARDS_MACHINE_NAME( CFileMgmtComponentData, m_pRootCookie )
  91. CFileSvcMgmtSnapin::CFileSvcMgmtSnapin()
  92. {
  93. // The identity of the default root node is the only difference
  94. // between the File Management snapin and the Service Management snapins
  95. QueryRootCookie().SetObjectType( FILEMGMT_ROOT );
  96. SetHtmlHelpFileName (L"file_srv.chm");
  97. }
  98. CFileSvcMgmtSnapin::~CFileSvcMgmtSnapin()
  99. {
  100. }
  101. CServiceMgmtSnapin::CServiceMgmtSnapin()
  102. {
  103. // The identity of the default root node is the only difference
  104. // between the File Management snapin and the Service Management snapins
  105. #ifdef SNAPIN_PROTOTYPER
  106. QueryRootCookie().SetObjectType( FILEMGMT_PROTOTYPER );
  107. #else
  108. QueryRootCookie().SetObjectType( FILEMGMT_SERVICES );
  109. #endif
  110. SetHtmlHelpFileName (L"sys_srv.chm");
  111. }
  112. CServiceMgmtSnapin::~CServiceMgmtSnapin()
  113. {
  114. }
  115. CFileSvcMgmtExtension::CFileSvcMgmtExtension()
  116. {
  117. // The root cookie is not used
  118. SetHtmlHelpFileName (L"file_srv.chm");
  119. }
  120. CFileSvcMgmtExtension::~CFileSvcMgmtExtension()
  121. {
  122. }
  123. CServiceMgmtExtension::CServiceMgmtExtension()
  124. {
  125. // The root cookie is not used
  126. SetHtmlHelpFileName (L"sys_srv.chm");
  127. }
  128. CServiceMgmtExtension::~CServiceMgmtExtension()
  129. {
  130. }
  131. CCookie& CFileMgmtComponentData::QueryBaseRootCookie()
  132. {
  133. ASSERT(NULL != m_pRootCookie);
  134. return (CCookie&)(*m_pRootCookie);
  135. }
  136. STDMETHODIMP CFileMgmtComponentData::CreateComponent(LPCOMPONENT* ppComponent)
  137. {
  138. MFC_TRY;
  139. ASSERT(ppComponent != NULL);
  140. CComObject<CFileMgmtComponent>* pObject;
  141. CComObject<CFileMgmtComponent>::CreateInstance(&pObject);
  142. ASSERT(pObject != NULL);
  143. pObject->SetComponentDataPtr( (CFileMgmtComponentData*)this );
  144. return pObject->QueryInterface(IID_IComponent,
  145. reinterpret_cast<void**>(ppComponent));
  146. MFC_CATCH;
  147. }
  148. HRESULT CFileMgmtComponentData::LoadIcons(LPIMAGELIST pImageList, BOOL fLoadLargeIcons)
  149. {
  150. HBITMAP hBMSm = NULL;
  151. HBITMAP hBMLg = NULL;
  152. HRESULT hr = S_OK;
  153. hBMSm = ::LoadBitmap(AfxGetInstanceHandle(),MAKEINTRESOURCE(IDB_FILEMGMT_ICONS_16));
  154. if (!hBMSm)
  155. return HRESULT_FROM_WIN32(GetLastError());
  156. if (fLoadLargeIcons)
  157. {
  158. hBMLg = ::LoadBitmap(AfxGetInstanceHandle(),MAKEINTRESOURCE(IDB_FILEMGMT_ICONS_32));
  159. if (!hBMLg)
  160. {
  161. hr = HRESULT_FROM_WIN32(GetLastError());
  162. DeleteObject(hBMSm);
  163. return hr;
  164. }
  165. }
  166. hr = pImageList->ImageListSetStrip((LONG_PTR *)hBMSm, (LONG_PTR *)hBMLg, iIconSharesFolder, RGB(255,0,255));
  167. DeleteObject(hBMSm);
  168. if (fLoadLargeIcons)
  169. DeleteObject(hBMLg);
  170. if (FAILED(hr))
  171. return hr;
  172. hBMSm = ::LoadBitmap(AfxGetInstanceHandle(),MAKEINTRESOURCE(IDB_SVCMGMT_ICONS_16));
  173. if (!hBMSm)
  174. return HRESULT_FROM_WIN32(GetLastError());
  175. if (fLoadLargeIcons)
  176. {
  177. hBMLg = ::LoadBitmap(AfxGetInstanceHandle(),MAKEINTRESOURCE(IDB_SVCMGMT_ICONS_32));
  178. if (!hBMLg)
  179. {
  180. hr = HRESULT_FROM_WIN32(GetLastError());
  181. DeleteObject(hBMSm);
  182. return hr;
  183. }
  184. }
  185. hr = pImageList->ImageListSetStrip((LONG_PTR *)hBMSm, (LONG_PTR *)hBMLg, iIconService, RGB(255,0,255));
  186. DeleteObject(hBMSm);
  187. if (fLoadLargeIcons)
  188. DeleteObject(hBMLg);
  189. return hr;
  190. }
  191. GUID g_guidSystemTools = structuuidNodetypeSystemTools;
  192. GUID g_guidServerApps = structuuidNodetypeServerApps;
  193. BOOL CFileMgmtComponentData::IsExtendedNodetype( GUID& refguid )
  194. {
  195. return (refguid == g_guidSystemTools || refguid == g_guidServerApps);
  196. }
  197. HRESULT CFileMgmtComponentData::AddScopeCookie( HSCOPEITEM hParent,
  198. LPCTSTR lpcszTargetServer,
  199. FileMgmtObjectType objecttype,
  200. CFileMgmtCookie* pParentCookie )
  201. {
  202. SCOPEDATAITEM tSDItem;
  203. ::ZeroMemory(&tSDItem,sizeof(tSDItem));
  204. tSDItem.mask = SDI_STR | SDI_IMAGE | SDI_OPENIMAGE | SDI_STATE | SDI_PARAM | SDI_PARENT;
  205. tSDItem.displayname = MMC_CALLBACK;
  206. // CODEWORK should use MMC_ICON_CALLBACK here
  207. tSDItem.relativeID = hParent;
  208. tSDItem.nState = 0;
  209. if (FILEMGMT_ROOT != objecttype)
  210. {
  211. // no children
  212. tSDItem.mask |= SDI_CHILDREN; // note that cChildren is still 0
  213. }
  214. CFileMgmtScopeCookie* pCookie = new CFileMgmtScopeCookie(
  215. lpcszTargetServer,
  216. objecttype);
  217. if (NULL != pParentCookie)
  218. pParentCookie->m_listScopeCookieBlocks.AddHead( pCookie );
  219. // WARNING cookie cast
  220. tSDItem.lParam = reinterpret_cast<LPARAM>((CCookie*)pCookie);
  221. tSDItem.nImage = QueryImage( *pCookie, FALSE );
  222. tSDItem.nOpenImage = QueryImage( *pCookie, TRUE );
  223. return m_pConsoleNameSpace->InsertItem(&tSDItem);
  224. }
  225. BOOL IsSimpleUI(PCTSTR pszMachineName);
  226. HRESULT CFileMgmtComponentData::OnNotifyExpand(
  227. LPDATAOBJECT lpDataObject,
  228. BOOL bExpanding,
  229. HSCOPEITEM hParent)
  230. {
  231. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  232. CWaitCursor wait;
  233. if (!bExpanding)
  234. return S_OK;
  235. GUID guidObjectType;
  236. HRESULT hr = ExtractObjectTypeGUID( lpDataObject, &guidObjectType );
  237. ASSERT( SUCCEEDED(hr) );
  238. if ( IsExtendedNodetype(guidObjectType) )
  239. {
  240. CString strServerName;
  241. hr = ExtractString( lpDataObject, CFileMgmtDataObject::m_CFMachineName, &strServerName, MAX_PATH );
  242. if ( FAILED(hr) )
  243. {
  244. ASSERT( FALSE );
  245. return hr;
  246. }
  247. // JonN 10/27/98: We add these nodes under the root cookie
  248. return AddScopeNodes( strServerName, hParent, &QueryRootCookie() );
  249. }
  250. CCookie* pbasecookie = NULL;
  251. FileMgmtObjectType objecttype =
  252. (FileMgmtObjectType)CheckObjectTypeGUID( &guidObjectType );
  253. hr = ExtractBaseCookie( lpDataObject, &pbasecookie );
  254. ASSERT( SUCCEEDED(hr) );
  255. CFileMgmtCookie* pParentCookie = (CFileMgmtCookie*)pbasecookie;
  256. if (NULL == pParentCookie) // JonN 05/30/00 PREFIX 110945
  257. {
  258. ASSERT(FALSE);
  259. return S_OK;
  260. }
  261. #ifdef SNAPIN_PROTOTYPER
  262. //(void)Prototyper_HrEnumerateScopeChildren(pParentCookie, hParent);
  263. return S_OK;
  264. #endif
  265. switch ( objecttype )
  266. {
  267. // This node type has a child
  268. case FILEMGMT_ROOT:
  269. if ( !IsExtensionSnapin() )
  270. {
  271. // Ensure that node is formatted correctly
  272. CString machineName = pParentCookie->QueryNonNULLMachineName ();
  273. if ( !pParentCookie->m_hScopeItem )
  274. pParentCookie->m_hScopeItem = hParent;
  275. m_strMachineNamePersist = machineName; // init m_strMachineNamePersist
  276. hr = ChangeRootNodeName (machineName);
  277. ASSERT( SUCCEEDED(hr) );
  278. }
  279. break;
  280. // These node types have no children
  281. case FILEMGMT_SHARES:
  282. case FILEMGMT_SESSIONS:
  283. case FILEMGMT_RESOURCES:
  284. case FILEMGMT_SERVICES:
  285. return S_OK;
  286. case FILEMGMT_SHARE:
  287. case FILEMGMT_SESSION:
  288. case FILEMGMT_RESOURCE:
  289. case FILEMGMT_SERVICE:
  290. TRACE( "CFileMgmtComponentData::EnumerateScopeChildren node type should not be in scope pane\n" );
  291. // fall through
  292. default:
  293. TRACE( "CFileMgmtComponentData::EnumerateScopeChildren bad parent type\n" );
  294. ASSERT( FALSE );
  295. return S_OK;
  296. }
  297. if ( NULL == hParent || !(pParentCookie->m_listScopeCookieBlocks).IsEmpty() )
  298. {
  299. ASSERT(FALSE);
  300. return E_UNEXPECTED;
  301. }
  302. return AddScopeNodes( pParentCookie->QueryTargetServer(), hParent, pParentCookie );
  303. }
  304. //
  305. // 7/11/2001 LinanT
  306. // Determine if the schema supports share publishing or not. This information is used
  307. // to decide whether to show the Publish tab on a share's property sheet.
  308. // We only need to do this once on current-retargeted computer. The ReInit() process
  309. // will reset this member variable if computer has been retargeted.
  310. //
  311. BOOL CFileMgmtComponentData::GetSchemaSupportSharePublishing()
  312. {
  313. if (SHAREPUBLISH_SCHEMA_UNASSIGNED == m_SchemaSupportSharePublishing)
  314. {
  315. if (S_OK == CheckSchemaVersion(QueryRootCookie().QueryNonNULLMachineName()))
  316. m_SchemaSupportSharePublishing = SHAREPUBLISH_SCHEMA_SUPPORTED;
  317. else
  318. m_SchemaSupportSharePublishing = SHAREPUBLISH_SCHEMA_UNSUPPORTED;
  319. }
  320. return (SHAREPUBLISH_SCHEMA_SUPPORTED == m_SchemaSupportSharePublishing);
  321. }
  322. //
  323. // 7/11/2001 LinanT
  324. // Cache the interface pointer to the computer object in AD. This information is
  325. // used to speed up the multiple-shares-deletion process.
  326. // We only need to do this once on current-retargeted computer. The ReInit() process
  327. // will reset this member variable if computer has been retargeted.
  328. //
  329. IADsContainer *CFileMgmtComponentData::GetIADsContainer()
  330. {
  331. if (!m_spiADsContainer)
  332. {
  333. if (GetSchemaSupportSharePublishing())
  334. {
  335. CString strADsPath, strDCName;
  336. HRESULT hr = GetADsPathOfComputerObject(QueryRootCookie().QueryNonNULLMachineName(), strADsPath, strDCName);
  337. if (SUCCEEDED(hr))
  338. ADsGetObject(strADsPath, IID_IADsContainer, (void**)&m_spiADsContainer);
  339. }
  340. }
  341. return (IADsContainer *)m_spiADsContainer;
  342. }
  343. //
  344. // 7/11/2001 LinanT
  345. // Re-initialize several "global" member variables based on the current-targeted computer.
  346. // These variables are all related to share operations.
  347. //
  348. HRESULT CFileMgmtComponentData::ReInit(LPCTSTR lpcszTargetServer)
  349. {
  350. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  351. CWaitCursor wait;
  352. //
  353. // re-initialize several global variables based on the targeted server
  354. //
  355. SetIsSimpleUI(IsSimpleUI(lpcszTargetServer));
  356. //
  357. // reset schema version of the domain the targeted machine belongs to
  358. //
  359. m_SchemaSupportSharePublishing = SHAREPUBLISH_SCHEMA_UNASSIGNED;
  360. //
  361. // reset the interface pointer to the AD container
  362. //
  363. if ((IADsContainer *)m_spiADsContainer)
  364. m_spiADsContainer.Release();
  365. return S_OK;
  366. }
  367. HRESULT CFileMgmtComponentData::AddScopeNodes( LPCTSTR lpcszTargetServer,
  368. HSCOPEITEM hParent,
  369. CFileMgmtCookie* pParentCookie )
  370. {
  371. ASSERT( NULL != pParentCookie );
  372. //
  373. // Create new cookies
  374. //
  375. LoadGlobalStrings();
  376. if (IsExtensionSnapin())
  377. {
  378. ASSERT( pParentCookie->m_listScopeCookieBlocks.IsEmpty() );
  379. }
  380. HRESULT hr = S_OK;
  381. if (IsServiceSnapin())
  382. {
  383. if ( IsExtensionSnapin() )
  384. {
  385. hr = AddScopeCookie( hParent, lpcszTargetServer, FILEMGMT_SERVICES, pParentCookie );
  386. ASSERT( SUCCEEDED(hr) );
  387. }
  388. return hr;
  389. }
  390. if (IsExtensionSnapin() && (pParentCookie == m_pRootCookie)) // called as extension
  391. {
  392. QueryRootCookie().SetMachineName(lpcszTargetServer);
  393. hr = AddScopeCookie( hParent, lpcszTargetServer, FILEMGMT_ROOT, pParentCookie );
  394. ASSERT( SUCCEEDED(hr) );
  395. return hr;
  396. }
  397. //
  398. // 7/11/2001 LinanT bug#433102
  399. // Before we insert the "Shares" scope node, we need to
  400. // re-initialize related global variables on currently targeted computer.
  401. //
  402. ReInit(lpcszTargetServer);
  403. hr = AddScopeCookie( hParent, lpcszTargetServer, FILEMGMT_SHARES, pParentCookie );
  404. ASSERT( SUCCEEDED(hr) );
  405. hr = AddScopeCookie( hParent, lpcszTargetServer, FILEMGMT_SESSIONS, pParentCookie );
  406. ASSERT( SUCCEEDED(hr) );
  407. hr = AddScopeCookie( hParent, lpcszTargetServer, FILEMGMT_RESOURCES, pParentCookie );
  408. ASSERT( SUCCEEDED(hr) );
  409. return S_OK;
  410. }
  411. HRESULT CFileMgmtComponentData::OnNotifyDelete(LPDATAOBJECT /*lpDataObject*/)
  412. {
  413. // CODEWORK The user hit the Delete key, I should deal with this
  414. return S_OK;
  415. }
  416. // JonN 10/27/98: We must release the children of the root cookie
  417. // JonN 10/27/98: We must release the cached Service Controller handle
  418. HRESULT CFileMgmtComponentData::OnNotifyRelease(LPDATAOBJECT lpDataObject, HSCOPEITEM /*hItem*/)
  419. {
  420. GUID guidObjectType;
  421. HRESULT hr = ExtractObjectTypeGUID( lpDataObject, &guidObjectType );
  422. ASSERT( SUCCEEDED(hr) );
  423. if ( IsExtendedNodetype(guidObjectType) )
  424. {
  425. // EricDav 3/19/99: We need to close the SCManager for both the service
  426. // snapin and the file mgmt snapin as the SFM config part uses this as well.
  427. Service_CloseScManager();
  428. QueryRootCookie().ReleaseScopeChildren();
  429. }
  430. // CODEWORK This will release all top-level extension scopenodes, not just those
  431. // under this particular external scopenode. I depend on the fact that COMPMGMT
  432. // will only create one instance of System Tools. JonN 10/27/98
  433. return S_OK;
  434. }
  435. STDMETHODIMP CFileMgmtComponentData::AddMenuItems(
  436. IDataObject* piDataObject,
  437. IContextMenuCallback* piCallback,
  438. long* pInsertionAllowed)
  439. {
  440. MFC_TRY;
  441. TRACE_METHOD(CFileMgmtComponentData,AddMenuItems);
  442. TEST_NONNULL_PTR_PARAM(piDataObject);
  443. TEST_NONNULL_PTR_PARAM(piCallback);
  444. TEST_NONNULL_PTR_PARAM(pInsertionAllowed);
  445. TRACE( "FileMgmt snapin: extending menu\n" );
  446. DATA_OBJECT_TYPES dataobjecttype = CCT_SCOPE;
  447. HRESULT hr = ExtractData( piDataObject,
  448. CFileMgmtDataObject::m_CFDataObjectType,
  449. &dataobjecttype,
  450. sizeof(dataobjecttype) );
  451. ASSERT( SUCCEEDED(hr) );
  452. GUID guidObjectType = GUID_NULL; // JonN 11/21/00 PREFIX 226044
  453. hr = ExtractObjectTypeGUID( piDataObject, &guidObjectType );
  454. ASSERT( SUCCEEDED(hr) );
  455. int objecttype = FilemgmtCheckObjectTypeGUID(IN &guidObjectType);
  456. if (objecttype == -1)
  457. {
  458. // We don't recognize the GUID, therefore we assume
  459. // the node wants to be extended by the service snapin.
  460. (void)Service_FAddMenuItems(piCallback, piDataObject, TRUE);
  461. return S_OK;
  462. }
  463. return DoAddMenuItems( piCallback, (FileMgmtObjectType)objecttype, dataobjecttype, pInsertionAllowed, piDataObject );
  464. MFC_CATCH;
  465. } // CFileMgmtComponentData::AddMenuItems()
  466. HRESULT CFileMgmtComponentData::DoAddMenuItems( IContextMenuCallback* piCallback,
  467. FileMgmtObjectType objecttype,
  468. DATA_OBJECT_TYPES /*dataobjecttype*/,
  469. long* pInsertionAllowed,
  470. IDataObject* piDataObject)
  471. {
  472. HRESULT hr = S_OK;
  473. if ( !IsExtensionSnapin()
  474. && (objecttype == m_pRootCookie->QueryObjectType()) )
  475. {
  476. if (CCM_INSERTIONALLOWED_TOP & (*pInsertionAllowed) )
  477. {
  478. hr = LoadAndAddMenuItem(
  479. piCallback,
  480. IDS_CHANGE_COMPUTER_TOP,
  481. IDS_CHANGE_COMPUTER_TOP,
  482. CCM_INSERTIONPOINTID_PRIMARY_TOP,
  483. 0,
  484. AfxGetInstanceHandle() );
  485. ASSERT( SUCCEEDED(hr) );
  486. }
  487. if ( CCM_INSERTIONALLOWED_TASK & (*pInsertionAllowed) )
  488. {
  489. hr = LoadAndAddMenuItem(
  490. piCallback,
  491. IDS_CHANGE_COMPUTER_TASK,
  492. IDS_CHANGE_COMPUTER_TASK,
  493. CCM_INSERTIONPOINTID_PRIMARY_TASK,
  494. 0,
  495. AfxGetInstanceHandle() );
  496. ASSERT( SUCCEEDED(hr) );
  497. }
  498. }
  499. switch (objecttype)
  500. {
  501. case FILEMGMT_ROOT:
  502. {
  503. // check to see if this machine has SFM installed
  504. // if so, display the menu item.
  505. SfmFileServiceProvider* pProvider =
  506. (SfmFileServiceProvider*) GetFileServiceProvider(FILEMGMT_SFM);
  507. CString strServerName;
  508. HRESULT hr = ExtractString( piDataObject, CFileMgmtDataObject::m_CFMachineName, &strServerName, MAX_PATH );
  509. if ( FAILED(hr) )
  510. {
  511. ASSERT( FALSE );
  512. break;
  513. }
  514. if (m_hScManager == NULL)
  515. {
  516. Service_EOpenScManager(strServerName);
  517. }
  518. if ( pProvider->FSFMInstalled(strServerName) )
  519. {
  520. if ( CCM_INSERTIONALLOWED_TASK & (*pInsertionAllowed) )
  521. {
  522. hr = LoadAndAddMenuItem(
  523. piCallback,
  524. IDS_CONFIG_SFM_TASK,
  525. IDS_CONFIG_SFM_TASK,
  526. CCM_INSERTIONPOINTID_PRIMARY_TASK,
  527. 0,
  528. AfxGetInstanceHandle() );
  529. ASSERT( SUCCEEDED(hr) );
  530. }
  531. if ( CCM_INSERTIONALLOWED_TOP & (*pInsertionAllowed) )
  532. {
  533. hr = LoadAndAddMenuItem(
  534. piCallback,
  535. IDS_CONFIG_SFM_TOP,
  536. IDS_CONFIG_SFM_TOP,
  537. CCM_INSERTIONPOINTID_PRIMARY_TOP,
  538. 0,
  539. AfxGetInstanceHandle() );
  540. ASSERT( SUCCEEDED(hr) );
  541. }
  542. }
  543. }
  544. break;
  545. case FILEMGMT_SHARES:
  546. //
  547. // don't add New Share Wizard to the menu whenever SimpleSharingUI appears in NT Explorer
  548. //
  549. if (GetIsSimpleUI())
  550. break;
  551. if ( CCM_INSERTIONALLOWED_TOP & (*pInsertionAllowed) )
  552. {
  553. hr = LoadAndAddMenuItem(
  554. piCallback,
  555. IDS_NEW_SHARE_TOP,
  556. IDS_NEW_SHARE_TOP,
  557. CCM_INSERTIONPOINTID_PRIMARY_TOP,
  558. 0,
  559. AfxGetInstanceHandle() );
  560. ASSERT( SUCCEEDED(hr) );
  561. }
  562. if ( CCM_INSERTIONALLOWED_NEW & (*pInsertionAllowed) )
  563. {
  564. hr = LoadAndAddMenuItem(
  565. piCallback,
  566. IDS_NEW_SHARE_NEW,
  567. IDS_NEW_SHARE_NEW,
  568. CCM_INSERTIONPOINTID_PRIMARY_NEW,
  569. 0,
  570. AfxGetInstanceHandle() );
  571. ASSERT( SUCCEEDED(hr) );
  572. }
  573. break;
  574. case FILEMGMT_SESSIONS:
  575. if ( CCM_INSERTIONALLOWED_TOP & (*pInsertionAllowed) )
  576. {
  577. hr = LoadAndAddMenuItem(
  578. piCallback,
  579. IDS_DISCONNECT_ALL_SESSIONS_TOP,
  580. IDS_DISCONNECT_ALL_SESSIONS_TOP,
  581. CCM_INSERTIONPOINTID_PRIMARY_TOP,
  582. 0,
  583. AfxGetInstanceHandle() );
  584. ASSERT( SUCCEEDED(hr) );
  585. }
  586. if ( CCM_INSERTIONALLOWED_TASK & (*pInsertionAllowed) )
  587. {
  588. hr = LoadAndAddMenuItem(
  589. piCallback,
  590. IDS_DISCONNECT_ALL_SESSIONS_TASK,
  591. IDS_DISCONNECT_ALL_SESSIONS_TASK,
  592. CCM_INSERTIONPOINTID_PRIMARY_TASK,
  593. 0,
  594. AfxGetInstanceHandle() );
  595. ASSERT( SUCCEEDED(hr) );
  596. }
  597. break;
  598. case FILEMGMT_RESOURCES:
  599. if ( CCM_INSERTIONALLOWED_TOP & (*pInsertionAllowed) )
  600. {
  601. hr = LoadAndAddMenuItem(
  602. piCallback,
  603. IDS_DISCONNECT_ALL_RESOURCES_TOP,
  604. IDS_DISCONNECT_ALL_RESOURCES_TOP,
  605. CCM_INSERTIONPOINTID_PRIMARY_TOP,
  606. 0,
  607. AfxGetInstanceHandle() );
  608. ASSERT( SUCCEEDED(hr) );
  609. }
  610. if ( CCM_INSERTIONALLOWED_TASK & (*pInsertionAllowed) )
  611. {
  612. hr = LoadAndAddMenuItem(
  613. piCallback,
  614. IDS_DISCONNECT_ALL_RESOURCES_TASK,
  615. IDS_DISCONNECT_ALL_RESOURCES_TASK,
  616. CCM_INSERTIONPOINTID_PRIMARY_TASK,
  617. 0,
  618. AfxGetInstanceHandle() );
  619. ASSERT( SUCCEEDED(hr) );
  620. }
  621. break;
  622. case FILEMGMT_SERVICES:
  623. #ifdef SNAPIN_PROTOTYPER
  624. // (void)Prototyper_FAddMenuItemsFromHKey(piCallback, m_regkeySnapinDemoRoot);
  625. #endif
  626. break;
  627. default:
  628. ASSERT( FALSE );
  629. break;
  630. } // switch
  631. return hr;
  632. } // CFileMgmtComponentData::DoAddMenuItems()
  633. STDMETHODIMP CFileMgmtComponentData::Command(
  634. LONG lCommandID,
  635. IDataObject* piDataObject )
  636. {
  637. MFC_TRY;
  638. TRACE_METHOD(CFileMgmtComponentData,Command);
  639. TEST_NONNULL_PTR_PARAM(piDataObject);
  640. TRACE( "CFileMgmtComponentData::Command: command %ld selected\n", lCommandID );
  641. #ifdef SNAPIN_PROTOTYPER
  642. Prototyper_ContextMenuCommand(lCommandID, piDataObject);
  643. return S_OK;
  644. #endif
  645. BOOL fRefresh = FALSE;
  646. switch (lCommandID)
  647. {
  648. case IDS_CHANGE_COMPUTER_TASK:
  649. case IDS_CHANGE_COMPUTER_TOP:
  650. {
  651. HRESULT hr = OnChangeComputer(piDataObject);
  652. fRefresh = ( SUCCEEDED(hr) && S_FALSE != hr );
  653. }
  654. break;
  655. case IDS_NEW_SHARE_NEW:
  656. case IDS_NEW_SHARE_TOP:
  657. fRefresh = NewShare( piDataObject );
  658. break;
  659. case IDS_DISCONNECT_ALL_SESSIONS_TASK:
  660. case IDS_DISCONNECT_ALL_SESSIONS_TOP:
  661. fRefresh = DisconnectAllSessions( piDataObject );
  662. break;
  663. case IDS_DISCONNECT_ALL_RESOURCES_TASK:
  664. case IDS_DISCONNECT_ALL_RESOURCES_TOP:
  665. fRefresh = DisconnectAllResources( piDataObject );
  666. break;
  667. case IDS_CONFIG_SFM_TASK:
  668. case IDS_CONFIG_SFM_TOP:
  669. fRefresh = ConfigSfm( piDataObject );
  670. break;
  671. case cmServiceStart:
  672. case cmServiceStop:
  673. case cmServicePause:
  674. case cmServiceResume:
  675. case cmServiceRestart:
  676. case cmServiceStartTask:
  677. case cmServiceStopTask:
  678. case cmServicePauseTask:
  679. case cmServiceResumeTask:
  680. case cmServiceRestartTask:
  681. // Context menu extension
  682. (void)Service_FDispatchMenuCommand(lCommandID, piDataObject);
  683. Assert(FALSE == fRefresh && "Context menu extension not allowed to refresh result pane");
  684. break;
  685. case -1: // Received when back arrow pushed in console.
  686. break;
  687. default:
  688. ASSERT(FALSE && "CFileMgmtComponentData::Command() - Invalid command ID");
  689. break;
  690. } // switch
  691. if (fRefresh)
  692. {
  693. // clear all views of this data
  694. m_pConsole->UpdateAllViews(piDataObject, 0L, 0L);
  695. // reread all views of this data
  696. m_pConsole->UpdateAllViews(piDataObject, 1L, 0L);
  697. }
  698. return S_OK;
  699. MFC_CATCH;
  700. } // CFileMgmtComponentData::Command()
  701. ///////////////////////////////////////////////////////////////////////////////
  702. //
  703. // OnChangeComputer ()
  704. //
  705. // Purpose: Change the machine managed by the snapin
  706. //
  707. // Input: piDataObject - the selected node. This should be the root node
  708. // of the snapin.
  709. // Output: Returns S_OK on success
  710. //
  711. // JonN 12/10/99 Copied from MYCOMPUT
  712. //
  713. ///////////////////////////////////////////////////////////////////////////////
  714. // 1. Launch object picker and get new computer name
  715. // 2. Change root node text
  716. // 3. Save new computer name to persistent name
  717. // 4. Delete subordinate nodes
  718. // 5. Re-add subordinate nodes
  719. HRESULT CFileMgmtComponentData::OnChangeComputer( IDataObject * /*piDataObject*/ )
  720. {
  721. if ( IsExtensionSnapin() )
  722. {
  723. ASSERT(FALSE);
  724. return S_FALSE;
  725. }
  726. HRESULT hr = S_OK;
  727. do { // false loop
  728. HWND hWndParent = NULL;
  729. hr = m_pConsole->GetMainWindow (&hWndParent);
  730. ASSERT(SUCCEEDED(hr));
  731. CComBSTR sbstrTargetComputer;
  732. if ( !CHOOSER2_PickTargetComputer( AfxGetInstanceHandle(),
  733. hWndParent,
  734. &sbstrTargetComputer ) )
  735. {
  736. hr = S_FALSE;
  737. break;
  738. }
  739. CString strTargetComputer = sbstrTargetComputer;
  740. strTargetComputer.MakeUpper ();
  741. // If the user chooses the local computer, treat that as if they had chosen
  742. // "Local Computer" in Snapin Manager. This means that there is no way to
  743. // reset the snapin to target explicitly at this computer without either
  744. // reloading the snapin from Snapin Manager, or going to a different computer.
  745. // When the Choose Target Computer UI is revised, we can make this more
  746. // consistent with Snapin Manager.
  747. if ( IsLocalComputername( strTargetComputer ) )
  748. strTargetComputer = L"";
  749. // If this is the same machine then don't do anything
  750. if (m_strMachineNamePersist == strTargetComputer)
  751. break;
  752. if (strTargetComputer.Left(2) == _T("\\\\"))
  753. QueryRootCookie().SetMachineName ((LPCTSTR)strTargetComputer + 2);
  754. else
  755. QueryRootCookie().SetMachineName (strTargetComputer);
  756. // Set the persistent name. If we are managing the local computer
  757. // this name should be empty.
  758. m_strMachineNamePersist = strTargetComputer;
  759. // This requires the MMCN_PRELOAD change so that we have the
  760. // HSCOPEITEM for the root node
  761. hr = ChangeRootNodeName (strTargetComputer);
  762. if ( !SUCCEEDED(hr) )
  763. break;
  764. Service_CloseScManager();
  765. // If the node hasn't already been expanded, or if it was previously
  766. // expanded and there weren't any children, then there is no need
  767. // to remove and replace and child nodes.
  768. if ( QueryRootCookie().m_listScopeCookieBlocks.IsEmpty() )
  769. {
  770. //
  771. // 7/11/2001 LinanT bug#433102
  772. // When "Shares" is added to scope pane by itself as the root node, we need to
  773. // re-initialize related global variables after computer retargeted.
  774. //
  775. FileMgmtObjectType objecttype = QueryRootCookie().QueryObjectType();
  776. if (FILEMGMT_SHARES == objecttype)
  777. ReInit(strTargetComputer); // these global variables are only needed by the share-related operations
  778. break;
  779. }
  780. // Delete subordinates
  781. HSCOPEITEM hRootScopeItem = QueryRootCookie().m_hScopeItem;
  782. MMC_COOKIE lCookie = 0;
  783. HSCOPEITEM hChild = 0;
  784. do {
  785. hr = m_pConsoleNameSpace->GetChildItem (hRootScopeItem,
  786. &hChild, &lCookie);
  787. if ( S_OK != hr )
  788. break;
  789. hr = m_pConsoleNameSpace->DeleteItem (hChild, TRUE);
  790. ASSERT (SUCCEEDED (hr));
  791. if ( !SUCCEEDED(hr) )
  792. break;
  793. } while (S_OK == hr);
  794. QueryRootCookie().ReleaseScopeChildren();
  795. hr = AddScopeNodes( strTargetComputer, hRootScopeItem, &QueryRootCookie() );
  796. } while (false); // false loop
  797. return hr;
  798. } // CFileMgmtComponentData::OnChangeComputer
  799. typedef enum _Shell32ApiIndex
  800. {
  801. SHELL_EXECUTE_ENUM = 0
  802. };
  803. // not subject to localization
  804. static LPCSTR g_COMPDATA_apchShell32FunctionNames[] = {
  805. "ShellExecuteW",
  806. NULL
  807. };
  808. // not subject to localization
  809. DynamicDLL g_COMPDATA_Shell32DLL( _T("SHELL32.DLL"), g_COMPDATA_apchShell32FunctionNames );
  810. typedef HINSTANCE (*SHELLEXECUTEPROC)(HWND, LPCWSTR, LPCWSTR, LPCWSTR, LPCWSTR, INT);
  811. BOOL CFileMgmtComponentData::NewShare( LPDATAOBJECT piDataObject )
  812. {
  813. TCHAR szWinDir[MAX_PATH];
  814. if (GetSystemWindowsDirectory(szWinDir, MAX_PATH) == 0)
  815. {
  816. ASSERT(FALSE);
  817. return FALSE;
  818. }
  819. CString strServerName;
  820. HRESULT hr = ExtractString( piDataObject, CFileMgmtDataObject::m_CFMachineName, &strServerName, MAX_PATH );
  821. if ( FAILED(hr) )
  822. {
  823. ASSERT( FALSE );
  824. return FALSE;
  825. }
  826. CString csAppName = szWinDir;
  827. if (csAppName.Right(1) != _T('\\'))
  828. csAppName += _T("\\");
  829. csAppName += _T("System32\\shrpubw.exe");
  830. CString strParameters;
  831. if (strServerName.IsEmpty())
  832. strParameters = _T(" /s");
  833. else
  834. strParameters.Format( _T(" /s %s"), strServerName );
  835. HWND hWnd;
  836. m_pConsole->GetMainWindow(&hWnd);
  837. DWORD dwExitCode =0;
  838. hr = SynchronousCreateProcess(hWnd, csAppName, strParameters, &dwExitCode);
  839. if ( FAILED(hr) )
  840. {
  841. (void) DoErrMsgBox(GetActiveWindow(), MB_OK | MB_ICONSTOP, hr, IDS_POPUP_NEWSHARE);
  842. return FALSE;
  843. }
  844. return TRUE;
  845. }
  846. BOOL CFileMgmtComponentData::DisconnectAllSessions( LPDATAOBJECT pDataObject )
  847. {
  848. CCookie* pbasecookie = NULL;
  849. FileMgmtObjectType objecttype;
  850. HRESULT hr = ExtractBaseCookie( pDataObject, &pbasecookie, &objecttype );
  851. ASSERT( SUCCEEDED(hr) && NULL != pbasecookie && FILEMGMT_SESSIONS == objecttype );
  852. CFileMgmtCookie* pcookie = (CFileMgmtCookie*)pbasecookie;
  853. if ( IDYES != DoErrMsgBox(GetActiveWindow(), MB_YESNO, 0, IDS_POPUP_CLOSE_ALL_SESSIONS) )
  854. {
  855. return FALSE;
  856. }
  857. INT iTransport;
  858. for ( iTransport = FILEMGMT_NUM_TRANSPORTS - 1; // bug#163500: follow this order: SFM/FPNW/SMB
  859. iTransport >= FILEMGMT_FIRST_TRANSPORT;
  860. iTransport-- )
  861. {
  862. // NULL == pResultData means disconnect all sessions
  863. // bug#210110: ignore error to attempt on all sessions
  864. (void) GetFileServiceProvider(iTransport)->EnumerateSessions(
  865. NULL, pcookie, true);
  866. }
  867. return TRUE; // always assume that something might have changed
  868. }
  869. BOOL CFileMgmtComponentData::DisconnectAllResources( LPDATAOBJECT pDataObject )
  870. {
  871. CCookie* pbasecookie = NULL;
  872. FileMgmtObjectType objecttype;
  873. HRESULT hr = ExtractBaseCookie( pDataObject, &pbasecookie, &objecttype );
  874. ASSERT( SUCCEEDED(hr) && NULL != pbasecookie && FILEMGMT_RESOURCES == objecttype );
  875. CFileMgmtCookie* pcookie = (CFileMgmtCookie*)pbasecookie;
  876. if ( IDYES != DoErrMsgBox(GetActiveWindow(), MB_YESNO, 0, IDS_POPUP_CLOSE_ALL_RESOURCES) )
  877. {
  878. return FALSE;
  879. }
  880. INT iTransport;
  881. for ( iTransport = FILEMGMT_NUM_TRANSPORTS - 1; // bug#163494: follow this order: SFM/FPNW/SMB
  882. iTransport >= FILEMGMT_FIRST_TRANSPORT;
  883. iTransport-- )
  884. {
  885. // NULL == pResultData means disconnect all resources
  886. // bug#210110: ignore error to attempt on all open files
  887. (void) GetFileServiceProvider(iTransport)->EnumerateResources(
  888. NULL,pcookie);
  889. }
  890. return TRUE; // always assume that something might have changed
  891. }
  892. BOOL CFileMgmtComponentData::ConfigSfm( LPDATAOBJECT pDataObject )
  893. {
  894. CString strServerName;
  895. HRESULT hr = ExtractString( pDataObject, CFileMgmtDataObject::m_CFMachineName, &strServerName, MAX_PATH );
  896. if ( FAILED(hr) )
  897. {
  898. ASSERT( FALSE );
  899. return FALSE;
  900. }
  901. SfmFileServiceProvider* pProvider =
  902. (SfmFileServiceProvider*) GetFileServiceProvider(FILEMGMT_SFM);
  903. // make sure the service is running
  904. if ( pProvider->StartSFM(::GetActiveWindow(), m_hScManager, strServerName) )
  905. {
  906. // does the user have access?
  907. DWORD dwErr = pProvider->UserHasAccess(strServerName);
  908. if ( dwErr == NO_ERROR )
  909. {
  910. pProvider->DisplaySfmProperties(pDataObject, (CFileMgmtCookie*) &QueryRootCookie());
  911. }
  912. else
  913. {
  914. // need to tell the user something here
  915. DoErrMsgBox(::GetActiveWindow(), MB_OK | MB_ICONEXCLAMATION, dwErr);
  916. }
  917. }
  918. return FALSE; // nothing to update in the UI
  919. }
  920. ///////////////////////////////////////////////////////////////////////////////
  921. /// IExtendPropertySheet
  922. STDMETHODIMP CFileMgmtComponentData::QueryPagesFor(LPDATAOBJECT pDataObject)
  923. {
  924. MFC_TRY;
  925. if (NULL == pDataObject)
  926. {
  927. ASSERT(FALSE);
  928. return E_POINTER;
  929. }
  930. HRESULT hr;
  931. DATA_OBJECT_TYPES dataobjecttype = CCT_SCOPE;
  932. FileMgmtObjectType objecttype = FileMgmtObjectTypeFromIDataObject(pDataObject);
  933. hr = ExtractData( pDataObject, CFileMgmtDataObject::m_CFDataObjectType, &dataobjecttype, sizeof(dataobjecttype) );
  934. ASSERT( SUCCEEDED(hr) );
  935. ASSERT( CCT_SCOPE == dataobjecttype ||
  936. CCT_RESULT == dataobjecttype ||
  937. CCT_SNAPIN_MANAGER == dataobjecttype );
  938. // determine if it needs property pages
  939. switch (objecttype)
  940. {
  941. #ifdef SNAPIN_PROTOTYPER
  942. case FILEMGMT_PROTOTYPER:
  943. // return S_OK;
  944. #endif
  945. case FILEMGMT_ROOT:
  946. case FILEMGMT_SHARES:
  947. case FILEMGMT_SESSIONS:
  948. case FILEMGMT_RESOURCES:
  949. case FILEMGMT_SERVICES:
  950. return (CCT_SNAPIN_MANAGER == dataobjecttype) ? S_OK : S_FALSE;
  951. default:
  952. break;
  953. }
  954. ASSERT(FALSE);
  955. return S_FALSE;
  956. MFC_CATCH;
  957. } // CFileMgmtComponentData::QueryPagesFor()
  958. STDMETHODIMP CFileMgmtComponentData::CreatePropertyPages(
  959. LPPROPERTYSHEETCALLBACK pCallBack,
  960. LONG_PTR /*handle*/, // This handle must be saved in the property page object to notify the parent when modified
  961. LPDATAOBJECT pDataObject)
  962. {
  963. MFC_TRY;
  964. if (NULL == pCallBack || NULL == pDataObject)
  965. {
  966. ASSERT(FALSE);
  967. return E_POINTER;
  968. }
  969. HRESULT hr;
  970. // extract data from data object
  971. FileMgmtObjectType objecttype = FileMgmtObjectTypeFromIDataObject(pDataObject);
  972. DATA_OBJECT_TYPES dataobjecttype = CCT_SCOPE;
  973. hr = ExtractData( pDataObject, CFileMgmtDataObject::m_CFDataObjectType, &dataobjecttype, sizeof(dataobjecttype) );
  974. ASSERT( SUCCEEDED(hr) );
  975. ASSERT( CCT_SCOPE == dataobjecttype ||
  976. CCT_RESULT == dataobjecttype ||
  977. CCT_SNAPIN_MANAGER == dataobjecttype );
  978. // determine if it needs property pages
  979. switch (objecttype)
  980. {
  981. case FILEMGMT_ROOT:
  982. case FILEMGMT_SHARES:
  983. case FILEMGMT_SESSIONS:
  984. case FILEMGMT_RESOURCES:
  985. #ifdef SNAPIN_PROTOTYPER
  986. case FILEMGMT_PROTOTYPER:
  987. #endif
  988. case FILEMGMT_SERVICES:
  989. {
  990. if (CCT_SNAPIN_MANAGER != dataobjecttype)
  991. {
  992. ASSERT(FALSE);
  993. return E_UNEXPECTED;
  994. }
  995. //
  996. // Note that once we have established that this is a CCT_SNAPIN_MANAGER cookie,
  997. // we don't care about its other properties. A CCT_SNAPIN_MANAGER cookie is
  998. // equivalent to a BOOL flag asking for the Node Properties page instead of a
  999. // managed object property page. JonN 10/9/96
  1000. //
  1001. CChooseMachinePropPage * pPage;
  1002. if (IsServiceSnapin())
  1003. {
  1004. pPage = new CChooseMachinePropPage();
  1005. pPage->SetCaption(IDS_CAPTION_SERVICES);
  1006. pPage->SetHelp(g_szHelpFileFilemgmt, g_a970HelpIDs);
  1007. }
  1008. else
  1009. {
  1010. CFileMgmtGeneral * pPageT = new CFileMgmtGeneral;
  1011. pPageT->SetFileMgmtComponentData(this);
  1012. pPage = pPageT;
  1013. pPage->SetHelp(g_szHelpFileFilemgmt, HELP_DIALOG_TOPIC(IDD_FILE_FILEMANAGEMENT_GENERAL));
  1014. }
  1015. // Initialize state of object
  1016. ASSERT(NULL != m_pRootCookie);
  1017. pPage->InitMachineName( QueryRootCookie().QueryTargetServer() );
  1018. pPage->SetOutputBuffers(
  1019. OUT &m_strMachineNamePersist,
  1020. OUT &m_fAllowOverrideMachineName,
  1021. OUT &m_pRootCookie->m_strMachineName); // Effective machine name
  1022. HPROPSHEETPAGE hPage=MyCreatePropertySheetPage(&pPage->m_psp);
  1023. pCallBack->AddPage(hPage);
  1024. return S_OK;
  1025. }
  1026. default:
  1027. break;
  1028. }
  1029. ASSERT(FALSE);
  1030. return S_FALSE;
  1031. MFC_CATCH;
  1032. } // CFileMgmtComponentData::CreatePropertyPages()
  1033. CString g_strShares;
  1034. CString g_strSessions;
  1035. CString g_strResources;
  1036. CString g_strServices;
  1037. BOOL g_fScopeStringsLoaded = FALSE;
  1038. void CFileMgmtComponentData::LoadGlobalStrings()
  1039. {
  1040. if (!g_fScopeStringsLoaded )
  1041. {
  1042. g_fScopeStringsLoaded = TRUE;
  1043. VERIFY( g_strShares.LoadString( IDS_SCOPE_SHARES ) );
  1044. VERIFY( g_strSessions.LoadString( IDS_SCOPE_SESSIONS ) );
  1045. VERIFY( g_strResources.LoadString( IDS_SCOPE_RESOURCES ) );
  1046. VERIFY( g_strServices.LoadString( IDS_SCOPE_SERVICES ) );
  1047. }
  1048. }
  1049. // global space to store the string haded back to GetDisplayInfo()
  1050. // CODEWORK should use "bstr" for ANSI-ization
  1051. CString g_strResultColumnText;
  1052. BSTR CFileMgmtScopeCookie::QueryResultColumnText( int nCol, CFileMgmtComponentData& refcdata )
  1053. {
  1054. FileMgmtObjectType objtype = QueryObjectType();
  1055. BOOL fStaticNode = ( !refcdata.IsExtensionSnapin()
  1056. && refcdata.QueryRootCookie().QueryObjectType() == objtype);
  1057. switch (objtype)
  1058. {
  1059. //
  1060. // These are scope items which can appear in the result pane.
  1061. // We only need to deal with column 0, others are blank
  1062. //
  1063. case FILEMGMT_ROOT:
  1064. switch (nCol)
  1065. {
  1066. case 0:
  1067. GetDisplayName( g_strResultColumnText, fStaticNode );
  1068. return const_cast<BSTR>(((LPCTSTR)g_strResultColumnText));
  1069. case 1: // Type - blank
  1070. break;
  1071. case 2: // Description
  1072. g_strResultColumnText.LoadString(IDS_SNAPINABOUT_DESCR_FILESVC);
  1073. return const_cast<BSTR>(((LPCTSTR)g_strResultColumnText));
  1074. default:
  1075. break;
  1076. }
  1077. break;
  1078. case FILEMGMT_SHARES:
  1079. case FILEMGMT_SESSIONS:
  1080. case FILEMGMT_RESOURCES:
  1081. if (0 == nCol)
  1082. {
  1083. GetDisplayName( g_strResultColumnText, fStaticNode );
  1084. return const_cast<BSTR>(((LPCTSTR)g_strResultColumnText));
  1085. }
  1086. break;
  1087. case FILEMGMT_SERVICES:
  1088. switch (nCol)
  1089. {
  1090. case 0:
  1091. GetDisplayName( g_strResultColumnText, fStaticNode );
  1092. return const_cast<BSTR>(((LPCTSTR)g_strResultColumnText));
  1093. case 1: // Type - blank
  1094. break;
  1095. case 2: // Description
  1096. g_strResultColumnText.LoadString(IDS_SNAPINABOUT_DESCR_SERVICES);
  1097. return const_cast<BSTR>(((LPCTSTR)g_strResultColumnText));
  1098. default:
  1099. break;
  1100. }
  1101. break;
  1102. default:
  1103. ASSERT(FALSE);
  1104. break;
  1105. }
  1106. return L"";
  1107. }
  1108. BSTR MakeDwordResult(DWORD dw)
  1109. {
  1110. g_strResultColumnText.Format( _T("%d"), dw );
  1111. return const_cast<BSTR>((LPCTSTR)g_strResultColumnText);
  1112. }
  1113. BSTR MakeElapsedTimeResult(DWORD dwTime)
  1114. {
  1115. if ( -1L == dwTime )
  1116. return L""; // not known
  1117. DWORD dwSeconds = dwTime % 60;
  1118. dwTime /= 60;
  1119. DWORD dwMinutes = dwTime % 60;
  1120. dwTime /= 60;
  1121. DWORD dwHours = dwTime % 24;
  1122. dwTime /= 24;
  1123. DWORD dwDays = dwTime;
  1124. LoadStringPrintf(
  1125. (dwDays == 0) ? IDS_TIME_HOURPLUS :
  1126. ((dwDays > 1) ? IDS_TIME_DAYPLUS : IDS_TIME_ONEDAY),
  1127. &g_strResultColumnText,
  1128. dwDays, dwHours, dwMinutes, dwSeconds );
  1129. return const_cast<BSTR>((LPCTSTR)g_strResultColumnText);
  1130. }
  1131. BSTR CFileMgmtComponentData::MakeTransportResult(FILEMGMT_TRANSPORT transport)
  1132. {
  1133. return const_cast<BSTR>(GetFileServiceProvider(transport)->QueryTransportString());
  1134. }
  1135. CString g_strPermissionNone;
  1136. CString g_strPermissionCreate;
  1137. CString g_strPermissionReadWrite;
  1138. CString g_strPermissionRead;
  1139. CString g_strPermissionWrite;
  1140. BOOL g_fPermissionStringsLoaded = FALSE;
  1141. BSTR MakePermissionsResult( DWORD dwPermissions )
  1142. {
  1143. if (!g_fPermissionStringsLoaded)
  1144. {
  1145. g_fPermissionStringsLoaded = TRUE;
  1146. VERIFY( g_strPermissionNone.LoadString(IDS_FILEPERM_NONE) );
  1147. VERIFY( g_strPermissionCreate.LoadString(IDS_FILEPERM_CREATE) );
  1148. VERIFY( g_strPermissionReadWrite.LoadString(IDS_FILEPERM_READWRITE) );
  1149. VERIFY( g_strPermissionRead.LoadString(IDS_FILEPERM_READ) );
  1150. VERIFY( g_strPermissionWrite.LoadString(IDS_FILEPERM_WRITE) );
  1151. }
  1152. if (PERM_FILE_CREATE & dwPermissions)
  1153. return const_cast<BSTR>((LPCTSTR)g_strPermissionCreate);
  1154. else if (PERM_FILE_WRITE & dwPermissions)
  1155. return ( (PERM_FILE_READ & dwPermissions)
  1156. ? const_cast<BSTR>((LPCTSTR)g_strPermissionReadWrite)
  1157. : const_cast<BSTR>((LPCTSTR)g_strPermissionWrite) );
  1158. else if (PERM_FILE_READ & dwPermissions)
  1159. return const_cast<BSTR>((LPCTSTR)g_strPermissionRead);
  1160. return const_cast<BSTR>((LPCTSTR)g_strPermissionNone);
  1161. }
  1162. CString& CFileMgmtComponentData::ResultStorageString()
  1163. {
  1164. return g_strResultColumnText;
  1165. }
  1166. BSTR CFileMgmtComponentData::QueryResultColumnText(
  1167. CCookie& basecookieref,
  1168. int nCol )
  1169. {
  1170. CFileMgmtCookie& cookieref = (CFileMgmtCookie&)basecookieref;
  1171. return cookieref.QueryResultColumnText( nCol, *this );
  1172. /*
  1173. #ifndef UNICODE
  1174. #error not ANSI-enabled
  1175. #endif
  1176. HRESULT hr = S_OK;
  1177. switch (cookieref.QueryObjectType())
  1178. {
  1179. //
  1180. // These are scope items which can appear in the result pane.
  1181. // We only need to deal with column 0, others are blank
  1182. //
  1183. case FILEMGMT_SHARES:
  1184. if (0 == nCol)
  1185. return const_cast<BSTR>(((LPCTSTR)g_strShares));
  1186. break;
  1187. case FILEMGMT_SESSIONS:
  1188. if (0 == nCol)
  1189. return const_cast<BSTR>(((LPCTSTR)g_strSessions));
  1190. break;
  1191. case FILEMGMT_RESOURCES:
  1192. if (0 == nCol)
  1193. return const_cast<BSTR>(((LPCTSTR)g_strResources));
  1194. break;
  1195. //
  1196. // These are result items. We need to deal with all columns.
  1197. // It is no longer permitted to set this text at insert time.
  1198. //
  1199. case FILEMGMT_SHARE:
  1200. case FILEMGMT_SESSION:
  1201. case FILEMGMT_RESOURCE:
  1202. case FILEMGMT_SERVICE:
  1203. return cookieref.QueryResultColumnText( nCol, *this );
  1204. // CODEWORK do we need to deal with these? They never appear
  1205. // in the result pane.
  1206. case FILEMGMT_ROOT:
  1207. case FILEMGMT_SERVICES:
  1208. // fall through
  1209. default:
  1210. ASSERT(FALSE);
  1211. break;
  1212. }
  1213. return L"";
  1214. */
  1215. }
  1216. int CFileMgmtComponentData::QueryImage(CCookie& basecookieref, BOOL fOpenImage)
  1217. {
  1218. CFileMgmtCookie& cookieref = (CFileMgmtCookie&)basecookieref;
  1219. // CODEWORK we need new icons for Resource, Open File and possibly also
  1220. // differentiating by transport
  1221. int iIconReturn = iIconSharesFolder;
  1222. switch (cookieref.QueryObjectType())
  1223. {
  1224. case FILEMGMT_ROOT:
  1225. case FILEMGMT_SHARES:
  1226. case FILEMGMT_SESSIONS:
  1227. case FILEMGMT_RESOURCES:
  1228. if (fOpenImage)
  1229. return iIconSharesFolderOpen;
  1230. return iIconSharesFolder;
  1231. case FILEMGMT_SERVICE:
  1232. case FILEMGMT_SERVICES:
  1233. return iIconService;
  1234. case FILEMGMT_SHARE:
  1235. iIconReturn = iIconSMBShare;
  1236. break;
  1237. case FILEMGMT_SESSION:
  1238. iIconReturn = iIconSMBSession;
  1239. break;
  1240. case FILEMGMT_RESOURCE:
  1241. iIconReturn = iIconSMBResource;
  1242. break;
  1243. default:
  1244. ASSERT(FALSE);
  1245. return iIconSharesFolder;
  1246. }
  1247. FILEMGMT_TRANSPORT transport = FILEMGMT_SMB;
  1248. VERIFY( SUCCEEDED(cookieref.GetTransport( &transport ) ) );
  1249. switch (transport)
  1250. {
  1251. case FILEMGMT_SMB:
  1252. break;
  1253. case FILEMGMT_SFM:
  1254. return iIconReturn+1;
  1255. case FILEMGMT_FPNW:
  1256. return iIconReturn+2;
  1257. #ifdef SNAPIN_PROTOTYPER
  1258. case FILEMGMT_PROTOTYPER:
  1259. if (((CPrototyperScopeCookie &)cookieref).m_ScopeType == HTML)
  1260. return iIconPrototyperHTML;
  1261. else return iIconPrototyperContainerClosed;
  1262. case FILEMGMT_PROTOTYPER_LEAF:
  1263. return iIconPrototyperLeaf;
  1264. #endif // FILEMGMT_PROTOTYPER
  1265. default:
  1266. ASSERT(FALSE);
  1267. break;
  1268. }
  1269. return iIconReturn;
  1270. }
  1271. ///////////////////////////////////////////////////////////////////////////////
  1272. //
  1273. // ChangeRootNodeName ()
  1274. //
  1275. // Purpose: Change the text of the root node
  1276. //
  1277. // Input: newName - the new machine name that the snapin manages
  1278. // Output: Returns S_OK on success
  1279. //
  1280. ///////////////////////////////////////////////////////////////////////////////
  1281. HRESULT CFileMgmtComponentData::ChangeRootNodeName(const CString & newName)
  1282. {
  1283. MFC_TRY;
  1284. ASSERT (m_pRootCookie);
  1285. if ( !m_pRootCookie )
  1286. return E_FAIL;
  1287. // This should only happen per bug 453635/453636, when the snapin
  1288. // was just added to the console and we still don't have the
  1289. // root node's HSCOPEITEM. Ignore this for now.
  1290. if ( !QueryBaseRootCookie().m_hScopeItem )
  1291. return S_OK;
  1292. CString machineName (newName);
  1293. CString formattedName;
  1294. // If machineName is empty, then this manages the local machine. Get
  1295. // the local machine name. Then format the computer name with the snapin
  1296. // name
  1297. FileMgmtObjectType objecttype = QueryRootCookie().QueryObjectType();
  1298. // JonN 11/14/00 164998 set to SERVICES where appropriate
  1299. if (machineName.IsEmpty())
  1300. {
  1301. if (IsServiceSnapin())
  1302. formattedName.LoadString(IDS_DISPLAYNAME_SERVICES_LOCAL);
  1303. else
  1304. {
  1305. switch (objecttype)
  1306. {
  1307. case FILEMGMT_SHARES:
  1308. formattedName.LoadString(IDS_DISPLAYNAME_SHARES_LOCAL);
  1309. break;
  1310. case FILEMGMT_SESSIONS:
  1311. formattedName.LoadString(IDS_DISPLAYNAME_SESSIONS_LOCAL);
  1312. break;
  1313. case FILEMGMT_RESOURCES:
  1314. formattedName.LoadString(IDS_DISPLAYNAME_FILES_LOCAL);
  1315. break;
  1316. default:
  1317. formattedName.LoadString(IDS_DISPLAYNAME_ROOT_LOCAL);
  1318. break;
  1319. }
  1320. }
  1321. }
  1322. else
  1323. {
  1324. machineName.MakeUpper ();
  1325. if (IsServiceSnapin())
  1326. formattedName.FormatMessage(IDS_DISPLAYNAME_s_SERVICES, machineName);
  1327. else
  1328. {
  1329. switch (objecttype)
  1330. {
  1331. case FILEMGMT_SHARES:
  1332. formattedName.FormatMessage(IDS_DISPLAYNAME_s_SHARES, machineName);
  1333. break;
  1334. case FILEMGMT_SESSIONS:
  1335. formattedName.FormatMessage(IDS_DISPLAYNAME_s_SESSIONS, machineName);
  1336. break;
  1337. case FILEMGMT_RESOURCES:
  1338. formattedName.FormatMessage(IDS_DISPLAYNAME_s_FILES, machineName);
  1339. break;
  1340. default:
  1341. formattedName.FormatMessage(IDS_DISPLAYNAME_s_ROOT, machineName);
  1342. break;
  1343. }
  1344. }
  1345. }
  1346. SCOPEDATAITEM item;
  1347. ::ZeroMemory (&item, sizeof (SCOPEDATAITEM));
  1348. item.mask = SDI_STR;
  1349. item.displayname = (LPTSTR) (LPCTSTR) formattedName;
  1350. item.ID = QueryBaseRootCookie ().m_hScopeItem;
  1351. return m_pConsoleNameSpace->SetItem (&item);
  1352. MFC_CATCH;
  1353. }
  1354. ///////////////////////////////////////////////////////////////////////////////
  1355. //
  1356. // OnNotifyPreload ()
  1357. //
  1358. // Purpose: Remember the HSCOPEITEM of the root node
  1359. //
  1360. // Note: Requires that CCF_SNAPIN_PRELOADS be set
  1361. //
  1362. ///////////////////////////////////////////////////////////////////////////////
  1363. HRESULT CFileMgmtComponentData::OnNotifyPreload(
  1364. LPDATAOBJECT /*lpDataObject*/,
  1365. HSCOPEITEM hRootScopeItem)
  1366. {
  1367. QueryRootCookie().m_hScopeItem = hRootScopeItem;
  1368. //
  1369. // 7/11/2001 LinanT bug#433102
  1370. // Before "Shares" is added to scope pane by itself as the root node, we need to
  1371. // initialize related global variables.
  1372. //
  1373. PCWSTR lpwcszMachineName = QueryRootCookie().QueryNonNULLMachineName();
  1374. FileMgmtObjectType objecttype = QueryRootCookie().QueryObjectType();
  1375. if (FILEMGMT_SHARES == objecttype)
  1376. {
  1377. ReInit(lpwcszMachineName);
  1378. }
  1379. // JonN 3/13/01 342366
  1380. // Services: No credential defaults to local from command line
  1381. VERIFY( SUCCEEDED( ChangeRootNodeName(
  1382. QueryRootCookie().QueryNonNULLMachineName())));
  1383. return S_OK;
  1384. }
  1385. //////////////////////////////////////////////////////////////////////////////
  1386. // The following 3 functions are cut & pasted from shell\osshell\lmui\ntshrui\util.cxx
  1387. //////////////////////////////////////////////////////////////////////////////
  1388. //+---------------------------------------------------------------------------
  1389. //
  1390. // Function: IsSafeMode
  1391. //
  1392. // Synopsis: Checks the registry to see if the system is in safe mode.
  1393. //
  1394. // History: 06-Oct-00 JeffreyS Created
  1395. //
  1396. //----------------------------------------------------------------------------
  1397. BOOL
  1398. IsSafeMode(
  1399. VOID
  1400. )
  1401. {
  1402. BOOL fIsSafeMode = FALSE;
  1403. HKEY hkey = NULL;
  1404. LONG ec = RegOpenKeyEx(
  1405. HKEY_LOCAL_MACHINE,
  1406. TEXT("SYSTEM\\CurrentControlSet\\Control\\SafeBoot\\Option"),
  1407. 0,
  1408. KEY_QUERY_VALUE,
  1409. &hkey
  1410. );
  1411. if (ec == NO_ERROR)
  1412. {
  1413. DWORD dwValue = 0;
  1414. DWORD dwValueSize = sizeof(dwValue);
  1415. ec = RegQueryValueEx(hkey,
  1416. TEXT("OptionValue"),
  1417. NULL,
  1418. NULL,
  1419. (LPBYTE)&dwValue,
  1420. &dwValueSize);
  1421. if (ec == NO_ERROR)
  1422. {
  1423. fIsSafeMode = (dwValue == SAFEBOOT_MINIMAL || dwValue == SAFEBOOT_NETWORK);
  1424. }
  1425. RegCloseKey(hkey);
  1426. }
  1427. return fIsSafeMode;
  1428. }
  1429. //+---------------------------------------------------------------------------
  1430. //
  1431. // Function: IsForcedGuestModeOn
  1432. //
  1433. // Synopsis: Checks the registry to see if the system is using the
  1434. // Guest-only network access mode.
  1435. //
  1436. // History: 06-Oct-00 JeffreyS Created
  1437. // 19-Apr-00 GPease Modified and changed name
  1438. //
  1439. //----------------------------------------------------------------------------
  1440. BOOL
  1441. IsForcedGuestModeOn(
  1442. VOID
  1443. )
  1444. {
  1445. BOOL fIsForcedGuestModeOn = FALSE;
  1446. if (IsOS(OS_PERSONAL))
  1447. {
  1448. // Guest mode is always on for Personal
  1449. fIsForcedGuestModeOn = TRUE;
  1450. }
  1451. else if (IsOS(OS_PROFESSIONAL) && !IsOS(OS_DOMAINMEMBER))
  1452. {
  1453. // Professional, not in a domain. Check the ForceGuest value.
  1454. HKEY hkey = NULL;
  1455. LONG ec = RegOpenKeyEx(
  1456. HKEY_LOCAL_MACHINE,
  1457. TEXT("SYSTEM\\CurrentControlSet\\Control\\LSA"),
  1458. 0,
  1459. KEY_QUERY_VALUE,
  1460. &hkey
  1461. );
  1462. if (ec == NO_ERROR)
  1463. {
  1464. DWORD dwValue = 0;
  1465. DWORD dwValueSize = sizeof(dwValue);
  1466. ec = RegQueryValueEx(hkey,
  1467. TEXT("ForceGuest"),
  1468. NULL,
  1469. NULL,
  1470. (LPBYTE)&dwValue,
  1471. &dwValueSize);
  1472. if (ec == NO_ERROR && 0 != dwValue)
  1473. {
  1474. fIsForcedGuestModeOn = TRUE;
  1475. }
  1476. RegCloseKey(hkey);
  1477. }
  1478. }
  1479. return fIsForcedGuestModeOn;
  1480. }
  1481. //+---------------------------------------------------------------------------
  1482. //
  1483. // Function: IsSimpleUI
  1484. //
  1485. // Synopsis: Checks whether to show the simple version of the UI.
  1486. //
  1487. // History: 06-Oct-00 JeffreyS Created
  1488. // 19-Apr-00 GPease Removed CTRL key check
  1489. //
  1490. //----------------------------------------------------------------------------
  1491. BOOL IsSimpleUI(PCTSTR pszMachineName)
  1492. {
  1493. //
  1494. // no need to disable acl-related context menu items if targeted at a remote machine
  1495. //
  1496. if (!IsLocalComputername(pszMachineName))
  1497. return FALSE;
  1498. // Show old UI in safe mode and anytime network access involves
  1499. // true user identity (server, pro with GuestMode off).
  1500. // Show simple UI anytime network access is done using the Guest
  1501. // account (personal, pro with GuestMode on) except in safe mode.
  1502. return (!IsSafeMode() && IsForcedGuestModeOn());
  1503. }