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.

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