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.

1246 lines
33 KiB

  1. // maindoc.cpp : implementation of the CMainDoc class
  2. //
  3. // This is a part of the Microsoft Foundation Classes C++ library.
  4. // Copyright (C) 1992-1995 Microsoft Corporation
  5. // All rights reserved.
  6. //
  7. // This source code is only intended as a supplement to the
  8. // Microsoft Foundation Classes Reference and related
  9. // electronic documentation provided with the library.
  10. // See these sources for detailed information regarding the
  11. // Microsoft Foundation Classes product.
  12. #include "stdafx.h"
  13. #include "schclss.h"
  14. #include "viewex.h"
  15. #include "enterdlg.h"
  16. #include "fltrdlg.h"
  17. #include "qstatus.h"
  18. #include "newobj.h"
  19. #ifdef _DEBUG
  20. #undef THIS_FILE
  21. static char BASED_CODE THIS_FILE[] = __FILE__;
  22. #endif
  23. TCHAR szOpen[ MAX_PATH ];
  24. /////////////////////////////////////////////////////////////////////////////
  25. // CMainDoc
  26. IMPLEMENT_SERIAL(CMainDoc, CDocument, 0 /* schema number*/ )
  27. BEGIN_MESSAGE_MAP(CMainDoc, CDocument)
  28. //{{AFX_MSG_MAP(CMainDoc)
  29. ON_COMMAND(IDM_CHANGEDATA, OnChangeData)
  30. ON_COMMAND(IDM_FILTER, OnSetFilter)
  31. ON_COMMAND(IDM_DISABLEFILTER, OnDisableFilter)
  32. ON_UPDATE_COMMAND_UI(IDM_DISABLEFILTER, OnUpdateDisablefilter)
  33. ON_COMMAND(IDM_USEGENERIC, OnUseGeneric)
  34. ON_UPDATE_COMMAND_UI(IDM_USEGENERIC, OnUpdateUseGeneric)
  35. ON_UPDATE_COMMAND_UI(IDM_USEGETEXPUTEX, OnUpdateUseGetExPutEx)
  36. ON_COMMAND(IDM_USEGETEXPUTEX, OnUseGetExPutEx)
  37. ON_COMMAND(IDM_USEPROPERTIESLIST, OnUsepropertiesList)
  38. ON_UPDATE_COMMAND_UI(IDM_USEPROPERTIESLIST, OnUpdateUsepropertiesList)
  39. //}}AFX_MSG_MAP
  40. END_MESSAGE_MAP()
  41. /////////////////////////////////////////////////////////////////////////////
  42. // CMainDoc construction/destruction
  43. //***********************************************************
  44. // Function:
  45. // Arguments:
  46. // Return:
  47. // Purpose:
  48. // Author(s):
  49. // Revision:
  50. // Date:
  51. //***********************************************************
  52. CMainDoc::CMainDoc()
  53. {
  54. m_pClasses = new CMapStringToOb;
  55. m_pItems = new CMapStringToOb;
  56. m_bApplyFilter = FALSE;
  57. m_dwRoot = 0L;
  58. m_bUseGeneric = TRUE;
  59. m_bUseGetEx = TRUE;
  60. //m_bUseGetEx = FALSE;
  61. }
  62. //***********************************************************
  63. // Function:
  64. // Arguments:
  65. // Return:
  66. // Purpose:
  67. // Author(s):
  68. // Revision:
  69. // Date:
  70. //***********************************************************
  71. CMainDoc::~CMainDoc()
  72. {
  73. POSITION pos;
  74. CObject* pItem;
  75. CString strItem;
  76. COleDsObject* pRoot;
  77. if( NULL != m_pClasses )
  78. {
  79. for( pos = m_pClasses->GetStartPosition(); pos != NULL; )
  80. {
  81. m_pClasses->GetNextAssoc( pos, strItem, pItem );
  82. delete pItem;
  83. #ifdef _DEBUG
  84. //afxDump << strItem << "\n";
  85. #endif
  86. }
  87. m_pClasses->RemoveAll( );
  88. delete m_pClasses;
  89. }
  90. if( NULL != m_pItems )
  91. {
  92. for( pos = m_pItems->GetStartPosition(); pos != NULL; )
  93. {
  94. m_pItems->GetNextAssoc( pos, strItem, pItem );
  95. delete pItem;
  96. /*#ifdef _DEBUG
  97. afxDump << strItem << "\n";
  98. #endif*/
  99. }
  100. m_pItems->RemoveAll( );
  101. delete m_pItems;
  102. }
  103. pRoot = GetObject( &m_dwRoot );
  104. if( pRoot )
  105. delete pRoot;
  106. }
  107. //***********************************************************
  108. // Function:
  109. // Arguments:
  110. // Return:
  111. // Purpose:
  112. // Author(s):
  113. // Revision:
  114. // Date:
  115. //***********************************************************
  116. BOOL CMainDoc::CreateFakeSchema( )
  117. {
  118. CClass* pClass;
  119. CProperty* pProperty;
  120. pClass = new CClass( _T("Class"), IID_IADsClass );
  121. pProperty = new CProperty( _T("PrimaryInterface"), _T("String") );
  122. pClass->AddProperty( pProperty );
  123. pProperty = new CProperty( _T("CLSID"), _T("String") );
  124. pClass->AddProperty( pProperty );
  125. pProperty = new CProperty( _T("OID"), _T("String") );
  126. pProperty->SetMandatory( TRUE );
  127. pClass->AddProperty( pProperty );
  128. pProperty = new CProperty( _T("Abstract"), _T("Boolean") );
  129. pProperty->SetMandatory( TRUE );
  130. pClass->AddProperty( pProperty );
  131. pProperty = new CProperty( _T("Auxiliary"), _T("Boolean") );
  132. pProperty->SetMandatory( TRUE );
  133. pClass->AddProperty( pProperty );
  134. pProperty = new CProperty( _T("MandatoryProperties"), _T("String"), TRUE );
  135. pClass->AddProperty( pProperty );
  136. pProperty = new CProperty( _T("OptionalProperties"), _T("String"), TRUE );
  137. pClass->AddProperty( pProperty );
  138. pProperty = new CProperty( _T("NamingProperties"), _T("String"), TRUE );
  139. pProperty->SetMandatory( TRUE );
  140. pClass->AddProperty( pProperty );
  141. pProperty = new CProperty( _T("DerivedFrom"), _T("String"), TRUE );
  142. pProperty->SetMandatory( TRUE );
  143. pClass->AddProperty( pProperty );
  144. pProperty = new CProperty( _T("AuxDerivedFrom"), _T("String"), TRUE );
  145. pProperty->SetMandatory( TRUE );
  146. pClass->AddProperty( pProperty );
  147. pProperty = new CProperty( _T("PossibleSuperiors"), _T("String"), TRUE );
  148. pProperty->SetMandatory( TRUE );
  149. pClass->AddProperty( pProperty );
  150. pProperty = new CProperty( _T("Containment"), _T("String"), TRUE );
  151. pClass->AddProperty( pProperty );
  152. pProperty = new CProperty( _T("Container"), _T("Boolean") );
  153. pClass->AddProperty( pProperty );
  154. pProperty = new CProperty( _T("HelpFileName"), _T("String") );
  155. pClass->AddProperty( pProperty );
  156. pProperty = new CProperty( _T("HelpFileContext"), _T("Integer") );
  157. pClass->AddProperty( pProperty );
  158. m_pClasses->SetAt( _T("Class"), pClass );
  159. // Property
  160. pClass = new CClass( _T("Property"), IID_IADsProperty );
  161. pProperty = new CProperty( _T("OID"), _T("String") );
  162. pProperty->SetMandatory( TRUE );
  163. pClass->AddProperty( pProperty );
  164. pProperty = new CProperty( _T("Syntax"), _T("String") );
  165. pProperty->SetMandatory( TRUE );
  166. pClass->AddProperty( pProperty );
  167. pProperty = new CProperty( _T("MaxRange"), _T("Integer") );
  168. pClass->AddProperty( pProperty );
  169. pProperty = new CProperty( _T("MinRange"), _T("Integer") );
  170. pClass->AddProperty( pProperty );
  171. pProperty = new CProperty( _T("MultiValued"), _T("Boolean") );
  172. pProperty->SetMandatory( TRUE );
  173. pClass->AddProperty( pProperty );
  174. m_pClasses->SetAt( _T("Property"), pClass );
  175. // Syntax
  176. pClass = new CClass( _T("Syntax"), IID_IADsSyntax );
  177. pProperty = new CProperty( _T("OleAutoDataType"), _T("Integer") );
  178. pClass->AddProperty( pProperty );
  179. m_pClasses->SetAt( _T("Syntax"), pClass );
  180. // AccessControlEntry
  181. pClass = new CClass( _T("ACE"), IID_IADsAccessControlEntry );
  182. pProperty = new CProperty( _T("Trustee"), _T("String") );
  183. pClass->AddProperty( pProperty );
  184. pProperty = new CProperty( _T("AccessMask"), _T("Integer") );
  185. pClass->AddProperty( pProperty );
  186. pProperty = new CProperty( _T("AceType"), _T("Integer") );
  187. pClass->AddProperty( pProperty );
  188. pProperty = new CProperty( _T("AceFlags"), _T("Integer") );
  189. pClass->AddProperty( pProperty );
  190. pProperty = new CProperty( _T("Flags"), _T("Integer") );
  191. pClass->AddProperty( pProperty );
  192. pProperty = new CProperty( _T("ObjectType"), _T("String") );
  193. pClass->AddProperty( pProperty );
  194. pProperty = new CProperty( _T("InheritedObjectType"), _T("String") );
  195. pClass->AddProperty( pProperty );
  196. m_pClasses->SetAt( _T("ACE"), pClass );
  197. // SecurityDescriptor
  198. pClass = new CClass( _T("SecurityDescriptor"),
  199. IID_IADsSecurityDescriptor );
  200. pProperty = new CProperty( _T("Revision"), _T("Integer") );
  201. pClass->AddProperty( pProperty );
  202. pProperty = new CProperty( _T("Control"), _T("Integer") );
  203. pClass->AddProperty( pProperty );
  204. pProperty = new CProperty( _T("Owner"), _T("String") );
  205. pClass->AddProperty( pProperty );
  206. pProperty = new CProperty( _T("OwnerDefaulted"), _T("Boolean") );
  207. pClass->AddProperty( pProperty );
  208. pProperty = new CProperty( _T("Group"), _T("String") );
  209. pClass->AddProperty( pProperty );
  210. pProperty = new CProperty( _T("GroupDefaulted"), _T("Boolean") );
  211. pClass->AddProperty( pProperty );
  212. pProperty = new CProperty( _T("SaclDefaulted"), _T("Boolean") );
  213. pClass->AddProperty( pProperty );
  214. pProperty = new CProperty( _T("DaclDefaulted"), _T("Boolean") );
  215. pClass->AddProperty( pProperty );
  216. m_pClasses->SetAt( _T("SecurityDescriptor"), pClass );
  217. // ROOTDSE
  218. pClass = new CClass( _T("ROOTDSE"), IID_IADs );
  219. pProperty = new CProperty( _T("currentTime"), _T("UTCTime") );
  220. pClass->AddProperty( pProperty );
  221. pProperty = new CProperty( _T("subschemaSubentry"), _T("String") );
  222. pClass->AddProperty( pProperty );
  223. pProperty = new CProperty( _T("serverName"), _T("String") );
  224. pClass->AddProperty( pProperty );
  225. pProperty = new CProperty( _T("namingContexts"), _T("String"), TRUE );
  226. pClass->AddProperty( pProperty );
  227. pProperty = new CProperty( _T("defaultNamingContext"), _T("String") );
  228. pClass->AddProperty( pProperty );
  229. pProperty = new CProperty( _T("schemaNamingContext"), _T("String") );
  230. pClass->AddProperty( pProperty );
  231. pProperty = new CProperty( _T("configurationNamingContext"), _T("String") );
  232. pClass->AddProperty( pProperty );
  233. pProperty = new CProperty( _T("rootDomainNamingContext"), _T("String") );
  234. pClass->AddProperty( pProperty );
  235. pProperty = new CProperty( _T("supportedControl"), _T("String"), TRUE );
  236. pClass->AddProperty( pProperty );
  237. pProperty = new CProperty( _T("supportedVersion"), _T("Integer"), TRUE );
  238. pClass->AddProperty( pProperty );
  239. pProperty = new CProperty( _T("highestCommittedUsn"), _T("Integer8") );
  240. pClass->AddProperty( pProperty );
  241. m_pClasses->SetAt( _T("ROOTDSE"), pClass );
  242. return TRUE;
  243. }
  244. //***********************************************************
  245. // Function:
  246. // Arguments:
  247. // Return:
  248. // Purpose:
  249. // Author(s):
  250. // Revision:
  251. // Date:
  252. //***********************************************************
  253. DWORD CMainDoc::GetToken( void* pVoid )
  254. {
  255. DWORD dwToken;
  256. dwToken = *(DWORD*) pVoid;
  257. return dwToken;
  258. }
  259. //***********************************************************
  260. // Function:
  261. // Arguments:
  262. // Return:
  263. // Purpose:
  264. // Author(s):
  265. // Revision:
  266. // Date:
  267. //***********************************************************
  268. COleDsObject* CMainDoc::GetObject( void* pVoid )
  269. {
  270. COleDsObject* pObject;
  271. pObject = *(COleDsObject**) pVoid;
  272. return pObject;
  273. }
  274. //***********************************************************
  275. // Function:
  276. // Arguments:
  277. // Return:
  278. // Purpose:
  279. // Author(s):
  280. // Revision:
  281. // Date:
  282. //***********************************************************
  283. void CMainDoc::SetCurrentItem( DWORD dwToken )
  284. {
  285. m_dwToken = dwToken;
  286. if( NewActiveItem( ) )
  287. {
  288. UpdateAllViews( NULL );
  289. }
  290. }
  291. //***********************************************************
  292. // Function:
  293. // Arguments:
  294. // Return:
  295. // Purpose:
  296. // Author(s):
  297. // Revision:
  298. // Date:
  299. //***********************************************************
  300. DWORD CMainDoc::GetChildItemList( DWORD dwToken,
  301. DWORD* pTokens,
  302. DWORD dwMaxChildren )
  303. {
  304. CQueryStatus aQueryStatus;
  305. COleDsObject* pOleDsObject = NULL;
  306. DWORD dwFilters, dwChildrenCount=0L;
  307. pOleDsObject = GetObject( &dwToken );
  308. if( !pOleDsObject->HasChildren( ) )
  309. {
  310. return 0L;
  311. }
  312. aQueryStatus.Create( IDD_QUERYSTATUS );
  313. aQueryStatus.ShowWindow( SW_SHOW );
  314. aQueryStatus.UpdateWindow( );
  315. if( ! pOleDsObject->CreateTheObject( ) )
  316. {
  317. TRACE( _T("Warning: could not create the object\n") );
  318. }
  319. else
  320. {
  321. dwFilters = m_bApplyFilter ? LIMIT : 0;
  322. dwChildrenCount = pOleDsObject->GetChildren( pTokens,
  323. dwMaxChildren,
  324. &aQueryStatus,
  325. m_arrFilters,
  326. dwFilters );
  327. pOleDsObject->ReleaseIfNotTransient( );
  328. }
  329. aQueryStatus.DestroyWindow( );
  330. return dwChildrenCount;
  331. }
  332. //***********************************************************
  333. // Function:
  334. // Arguments:
  335. // Return:
  336. // Purpose:
  337. // Author(s):
  338. // Revision:
  339. // Date:
  340. //***********************************************************
  341. BOOL CMainDoc::OnOpenDocument( LPCTSTR lpszName )
  342. {
  343. BOOL bRez;
  344. TCHAR szString[ 1024 ];
  345. GetPrivateProfileString( _T("Open_ADsPath"),
  346. _T("Value_1"),
  347. _T(""),
  348. szString,
  349. 1023,
  350. ADSVW_INI_FILE );
  351. WritePrivateProfileString( _T("Open_ADsPath"),
  352. _T("Value_1"),
  353. lpszName,
  354. ADSVW_INI_FILE );
  355. bRez = OnNewDocument( );
  356. WritePrivateProfileString( _T("Open_ADsPath"),
  357. _T("Value_1"),
  358. szString,
  359. ADSVW_INI_FILE );
  360. return bRez;
  361. }
  362. //***********************************************************
  363. // Function:
  364. // Arguments:
  365. // Return:
  366. // Purpose:
  367. // Author(s):
  368. // Revision:
  369. // Date:
  370. //***********************************************************
  371. BOOL CMainDoc::OnNewDocument()
  372. {
  373. CNewObject aNewObject;
  374. HRESULT hResult;
  375. if (!CDocument::OnNewDocument())
  376. return FALSE;
  377. if( aNewObject.DoModal( ) != IDOK )
  378. return FALSE;
  379. m_strRoot = aNewObject.m_strPath;
  380. m_strUser = aNewObject.m_strOpenAs;
  381. m_strPassword = aNewObject.m_strPassword;
  382. m_bUseOpenObject = aNewObject.m_bUseOpen;
  383. m_bSecure = aNewObject.m_bSecure;
  384. m_bEncryption = aNewObject.m_bEncryption;
  385. m_bUseVBStyle = !(aNewObject.m_bUseExtendedSyntax);
  386. m_bUsePropertiesList = FALSE;
  387. hResult = CreateRoot( );
  388. if( FAILED( hResult ) )
  389. {
  390. CString strErrorText;
  391. strErrorText = OleDsGetErrorText ( hResult );
  392. AfxMessageBox( strErrorText );
  393. }
  394. else
  395. {
  396. SetTitle( m_strRoot );
  397. }
  398. return SUCCEEDED( hResult );
  399. }
  400. //***********************************************************
  401. // Function:
  402. // Arguments:
  403. // Return:
  404. // Purpose:
  405. // Author(s):
  406. // Revision:
  407. // Date:
  408. //***********************************************************
  409. BOOL CMainDoc::NewActiveItem( )
  410. {
  411. BOOL bRez = TRUE;
  412. /* TCHAR szQName[ 128 ];
  413. CString strName;
  414. COleDsObject* pNewObject;
  415. MakeQualifiedName( szQName, m_strItemName.GetBuffer( 128 ),
  416. m_dwItemType );
  417. strName = szQName;
  418. bRez = m_pItems->Lookup( strName, (CObject*&) pNewObject );
  419. ASSERT( bRez );
  420. m_strDisplayName = szQName;
  421. if( m_pObject != NULL )
  422. {
  423. m_pObject->ReleaseIfNotTransient( );
  424. }
  425. m_pObject = pNewObject;
  426. pNewObject->CreateTheObject( );*/
  427. return bRez;
  428. }
  429. /////////////////////////////////////////////////////////////////////////////
  430. // CMainDoc serialization
  431. //***********************************************************
  432. // Function:
  433. // Arguments:
  434. // Return:
  435. // Purpose:
  436. // Author(s):
  437. // Revision:
  438. // Date:
  439. //***********************************************************
  440. void CMainDoc::Serialize(CArchive&)
  441. {
  442. ASSERT(FALSE); // this example program does not store data
  443. }
  444. /////////////////////////////////////////////////////////////////////////////
  445. // CMainDoc commands
  446. //***********************************************************
  447. // Function:
  448. // Arguments:
  449. // Return:
  450. // Purpose:
  451. // Author(s):
  452. // Revision:
  453. // Date:
  454. //***********************************************************
  455. void CMainDoc::OnChangeData()
  456. {
  457. CEnterDlg dlg;
  458. if (dlg.DoModal() != IDOK)
  459. return;
  460. UpdateAllViews(NULL); // general update
  461. }
  462. /////////////////////////////////////////////////////////////////////////////
  463. //***********************************************************
  464. // Function:
  465. // Arguments:
  466. // Return:
  467. // Purpose:
  468. // Author(s):
  469. // Revision:
  470. // Date:
  471. //***********************************************************
  472. void CMainDoc::OnSetFilter()
  473. {
  474. // TODO: Add your command handler code here
  475. CFilterDialog aFilterDialog;
  476. aFilterDialog.SetDisplayFilter( m_arrFilters );
  477. aFilterDialog.DoModal( );
  478. }
  479. //***********************************************************
  480. // Function:
  481. // Arguments:
  482. // Return:
  483. // Purpose:
  484. // Author(s):
  485. // Revision:
  486. // Date:
  487. //***********************************************************
  488. void CMainDoc::OnDisableFilter()
  489. {
  490. // TODO: Add your command handler code here
  491. m_bApplyFilter = !m_bApplyFilter;
  492. }
  493. //***********************************************************
  494. // Function:
  495. // Arguments:
  496. // Return:
  497. // Purpose:
  498. // Author(s):
  499. // Revision:
  500. // Date:
  501. //***********************************************************
  502. COleDsObject* CMainDoc::GetCurrentObject( void )
  503. {
  504. return GetObject( &m_dwToken );
  505. }
  506. //***********************************************************
  507. // Function:
  508. // Arguments:
  509. // Return:
  510. // Purpose:
  511. // Author(s):
  512. // Revision:
  513. // Date:
  514. //***********************************************************
  515. BOOL CMainDoc::GetUseGeneric( )
  516. {
  517. return m_bUseGeneric;
  518. }
  519. //***********************************************************
  520. // Function:
  521. // Arguments:
  522. // Return:
  523. // Purpose:
  524. // Author(s):
  525. // Revision:
  526. // Date:
  527. //***********************************************************
  528. BOOL CMainDoc::UseVBStyle( )
  529. {
  530. return m_bUseVBStyle;
  531. }
  532. //***********************************************************
  533. // Function:
  534. // Arguments:
  535. // Return:
  536. // Purpose:
  537. // Author(s):
  538. // Revision:
  539. // Date:
  540. //***********************************************************
  541. BOOL CMainDoc::UsePropertiesList( )
  542. {
  543. return m_bUsePropertiesList;
  544. }
  545. //***********************************************************
  546. // Function: CMainDoc::XOleDsGetObject
  547. // Arguments:
  548. // Return:
  549. // Purpose:
  550. // Author(s):
  551. // Revision:
  552. // Date:
  553. //***********************************************************
  554. BOOL CMainDoc::GetUseGetEx( )
  555. {
  556. return m_bUseGetEx;
  557. }
  558. //***********************************************************
  559. // Function:
  560. // Arguments:
  561. // Return:
  562. // Purpose:
  563. // Author(s):
  564. // Revision:
  565. // Date:
  566. //***********************************************************
  567. CClass* CMainDoc::CreateClass( COleDsObject* pObject )
  568. {
  569. CClass* pClass;
  570. CString strSchema;
  571. CString strClass;
  572. strSchema = pObject->GetSchemaPath( );
  573. strClass = pObject->GetClass( );
  574. if( !strClass.CompareNoCase( _T("Class") ) ||
  575. !strClass.CompareNoCase( _T("Property") ) ||
  576. !strClass.CompareNoCase( _T("Syntax") ) )
  577. {
  578. if( !strSchema.IsEmpty( ) )
  579. {
  580. TRACE(_T("[OLEDS] Error, nonempty schema path for Class, Property or Syntax objects\n" ) );
  581. }
  582. strSchema.Empty( );
  583. }
  584. if( strSchema.IsEmpty( ) )
  585. {
  586. strSchema = strClass;
  587. }
  588. if( 0 == (pObject->GetItemName( ).CompareNoCase( _T("ROOTDSE") ) ) )
  589. {
  590. strSchema = _T("ROOTDSE");
  591. }
  592. if( ! m_pClasses->Lookup( strSchema, ( CObject*& )pClass ) )
  593. {
  594. // we must create a new class item
  595. HCURSOR oldCursor, newCursor;
  596. newCursor = LoadCursor( NULL, IDC_WAIT );
  597. oldCursor = SetCursor( newCursor );
  598. pClass = new CClass( strSchema, this );
  599. ASSERT( NULL != pClass );
  600. if( !strClass.CompareNoCase( _T("User") ) )
  601. {
  602. pClass->LoadMethodsInformation( _T("IADsUser") );
  603. }
  604. if( !strClass.CompareNoCase( _T("Computer") ) )
  605. {
  606. pClass->LoadMethodsInformation( _T("IADsComputerOperations") );
  607. }
  608. if( !strClass.CompareNoCase( _T("Service") ) )
  609. {
  610. pClass->LoadMethodsInformation( _T("IADsServiceOperations") );
  611. }
  612. if( !strClass.CompareNoCase( _T("FileService") ) )
  613. {
  614. pClass->LoadMethodsInformation( _T("IADsFileServiceOperations") );
  615. }
  616. if( !strClass.CompareNoCase( _T("FPNWFileService") ) )
  617. {
  618. pClass->LoadMethodsInformation( _T("IADsFileServiceOperations") );
  619. }
  620. if( !strClass.CompareNoCase( _T("PrintQueue") ) )
  621. {
  622. pClass->LoadMethodsInformation( _T("IADsPrintQueueOperations") );
  623. }
  624. if( !strClass.CompareNoCase( _T("Queue") ) )
  625. {
  626. pClass->LoadMethodsInformation( _T("IADsPrintQueueOperations") );
  627. }
  628. if( !strClass.CompareNoCase( _T("PrintJob") ) )
  629. {
  630. pClass->LoadMethodsInformation( _T("IADsPrintJobOperations") );
  631. }
  632. if( !strClass.CompareNoCase( _T("Group") ) )
  633. {
  634. pClass->LoadMethodsInformation( _T("IADsGroup") );
  635. }
  636. if( !strClass.CompareNoCase( _T("localGroup") ) )
  637. {
  638. pClass->LoadMethodsInformation( _T("IADsGroup") );
  639. }
  640. if( !strClass.CompareNoCase( _T("GlobalGroup") ) )
  641. {
  642. pClass->LoadMethodsInformation( _T("IADsGroup") );
  643. }
  644. if( !strClass.CompareNoCase( _T("GroupOfNames") ) )
  645. {
  646. pClass->LoadMethodsInformation( _T("IADsGroup") );
  647. }
  648. if( !strClass.CompareNoCase( _T("GroupOfUniqueNames") ) )
  649. {
  650. pClass->LoadMethodsInformation( _T("IADsGroup") );
  651. }
  652. if( !strClass.CompareNoCase( _T("person") ) )
  653. {
  654. pClass->LoadMethodsInformation( _T("IADsUser") );
  655. }
  656. if( !strClass.CompareNoCase( _T("organizationalPerson") ) )
  657. {
  658. pClass->LoadMethodsInformation( _T("IADsUser") );
  659. }
  660. if( !strClass.CompareNoCase( _T("residentialPerson") ) )
  661. {
  662. pClass->LoadMethodsInformation( _T("IADsUser") );
  663. }
  664. m_pClasses->SetAt( strSchema, pClass );
  665. SetCursor( oldCursor );
  666. }
  667. return pClass;
  668. }
  669. //***********************************************************
  670. // Function: CMainDoc::XOleDsGetObject
  671. // Arguments:
  672. // Return:
  673. // Purpose:
  674. // Author(s):
  675. // Revision:
  676. // Date:
  677. //***********************************************************
  678. HRESULT CMainDoc::XOleDsGetObject( WCHAR* pszwPath, REFIID refiid,
  679. void** pVoid )
  680. {
  681. // cahged to add the hack for Win95.
  682. HRESULT hResult;
  683. WCHAR szOpenAs[ MAX_PATH ];
  684. WCHAR szPassword[ MAX_PATH ];
  685. LONG lCode = 0L;
  686. Convert( szOpenAs, m_strUser.GetBuffer( MAX_PATH ) );
  687. Convert( szPassword, m_strPassword.GetBuffer( MAX_PATH ) );
  688. if( !m_bUseOpenObject )
  689. {
  690. hResult = ADsGetObject( pszwPath, refiid, pVoid );
  691. }
  692. else
  693. {
  694. if( m_bSecure )
  695. {
  696. lCode |= ADS_SECURE_AUTHENTICATION;
  697. }
  698. if( m_bEncryption )
  699. {
  700. lCode |= ADS_USE_ENCRYPTION;
  701. }
  702. // hack fo rDavid...
  703. //if( L':' == pszwPath[ 3 ] )
  704. if( FALSE )
  705. {
  706. IADsOpenDSObject* pINamespace;
  707. hResult = ADsGetObject( L"NDS:",
  708. IID_IADsOpenDSObject,
  709. (void**)&pINamespace );
  710. ASSERT( SUCCEEDED( hResult ) );
  711. if( SUCCEEDED( hResult ) )
  712. {
  713. IDispatch* pIDisp;
  714. BSTR bstrPath = NULL;
  715. bstrPath = SysAllocString(pszwPath);
  716. if (NULL == bstrPath)
  717. return E_FAIL;
  718. hResult = pINamespace->OpenDSObject( pszwPath,
  719. _wcsicmp( szOpenAs, L"NULL") ? szOpenAs : NULL,
  720. _wcsicmp( szPassword, L"NULL") ? szPassword : NULL,
  721. lCode,
  722. &pIDisp );
  723. if( SUCCEEDED( hResult ) )
  724. {
  725. hResult = pIDisp->QueryInterface( refiid, pVoid );
  726. pIDisp->Release( );
  727. }
  728. pINamespace->Release( );
  729. }
  730. }
  731. else
  732. {
  733. hResult = ADsOpenObject( pszwPath,
  734. _wcsicmp( szOpenAs, L"NULL") ? szOpenAs : NULL,
  735. _wcsicmp( szPassword, L"NULL") ? szPassword : NULL,
  736. lCode,
  737. refiid,
  738. pVoid );
  739. }
  740. }
  741. return hResult;
  742. }
  743. /*******************************************************************
  744. Function: XGetOleDsObject
  745. Arguments:
  746. Return:
  747. Purpose:
  748. Author(s):
  749. Revision:
  750. Date:
  751. *******************************************************************/
  752. HRESULT CMainDoc::PurgeObject( IUnknown* pIUnknown, LPWSTR pszPrefix )
  753. {
  754. IADs* pObject;
  755. HRESULT hResult;
  756. BSTR bstrParent = NULL;
  757. IADsContainer* pParent;
  758. while( TRUE )
  759. {
  760. hResult = pIUnknown->QueryInterface( IID_IADs, (void**)&pObject );
  761. if( FAILED( hResult ) )
  762. break;
  763. hResult = pObject->get_Parent( &bstrParent );
  764. pObject->Release( );
  765. if( NULL != bstrParent )
  766. {
  767. hResult = XOleDsGetObject( bstrParent, IID_IADsContainer, (void**)&pParent );
  768. if( SUCCEEDED( hResult ) )
  769. {
  770. hResult = ::PurgeObject( pParent, pIUnknown, pszPrefix );
  771. pParent->Release( );
  772. }
  773. }
  774. SysFreeString( bstrParent );
  775. break;
  776. }
  777. return hResult;
  778. }
  779. /*******************************************************************
  780. Function: XGetOleDsObject
  781. Arguments:
  782. Return:
  783. Purpose:
  784. Author(s):
  785. Revision:
  786. Date:
  787. *******************************************************************/
  788. HRESULT CMainDoc::XOleDsGetObject( CHAR* pszPath, REFIID refiid, void** pVoid )
  789. {
  790. int nLength;
  791. WCHAR* pszwPath;
  792. HRESULT hResult;
  793. nLength = strlen( pszPath );
  794. pszwPath = (WCHAR*) malloc( ( nLength + 1 ) * sizeof(WCHAR) );
  795. if (NULL == pszwPath)
  796. return E_FAIL;
  797. memset( pszwPath, 0, ( nLength + 1 ) * sizeof(WCHAR) );
  798. MultiByteToWideChar( CP_ACP,
  799. MB_PRECOMPOSED,
  800. pszPath,
  801. nLength,
  802. pszwPath,
  803. nLength + 1 );
  804. hResult = XOleDsGetObject( pszwPath, refiid, pVoid );
  805. free( pszwPath );
  806. return hResult;
  807. }
  808. //***********************************************************
  809. // Function:
  810. // Arguments:
  811. // Return:
  812. // Purpose:
  813. // Author(s):
  814. // Revision:
  815. // Date:
  816. //***********************************************************
  817. DWORD CMainDoc::CreateOleDsItem( COleDsObject* pParent, IADs* pIOleDs )
  818. {
  819. COleDsObject* pObject = NULL;
  820. HRESULT hResult;
  821. IUnknown* pIUnk;
  822. BSTR bstrOleDsPath = NULL;
  823. BSTR bstrClass;
  824. hResult = pIOleDs->QueryInterface( IID_IUnknown, (void**)&pIUnk );
  825. ASSERT( SUCCEEDED( hResult ) );
  826. if( FAILED( hResult ) )
  827. return 0L;
  828. hResult = pIOleDs->get_Class( &bstrClass );
  829. hResult = pIOleDs->get_ADsPath( &bstrOleDsPath );
  830. //if( FAILED( hResult ) || NULL == bstrOleDsPath );
  831. pObject = CreateOleDsObject( TypeFromString( bstrClass ), pIUnk );
  832. pIUnk->Release( );
  833. pObject->SetParent( pParent );
  834. pObject->SetDocument( this );
  835. return GetToken( &pObject );
  836. }
  837. //***********************************************************
  838. // Function:
  839. // Arguments:
  840. // Return:
  841. // Purpose:
  842. // Author(s):
  843. // Revision:
  844. // Date:
  845. //***********************************************************
  846. HRESULT CMainDoc::CreateRoot( )
  847. {
  848. IADs* pIOleDs;
  849. HRESULT hResult;
  850. HCURSOR oldCursor, newCursor;
  851. BSTR bstrPath;
  852. CreateFakeSchema( );
  853. newCursor = LoadCursor( NULL, IDC_WAIT );
  854. oldCursor = SetCursor( newCursor );
  855. bstrPath = AllocBSTR( m_strRoot.GetBuffer( 1024 ) );
  856. hResult = XOleDsGetObject( bstrPath, IID_IADs, (void**) &pIOleDs );
  857. SysFreeString( bstrPath );
  858. if( SUCCEEDED( hResult ) )
  859. {
  860. m_dwToken = CreateOleDsItem( NULL, pIOleDs );
  861. m_dwRoot = m_dwToken;
  862. pIOleDs->Release( );
  863. }
  864. SetCursor( oldCursor );
  865. return hResult;
  866. }
  867. //***********************************************************
  868. // Function:
  869. // Arguments:
  870. // Return:
  871. // Purpose:
  872. // Author(s):
  873. // Revision:
  874. // Date:
  875. //***********************************************************
  876. void CMainDoc::DeleteAllItems( )
  877. {
  878. COleDsObject* pObject;
  879. POSITION pos;
  880. CString strItem;
  881. CObject* pItem;
  882. if( NULL != m_pClasses )
  883. {
  884. for( pos = m_pClasses->GetStartPosition(); pos != NULL; )
  885. {
  886. m_pClasses->GetNextAssoc( pos, strItem, pItem );
  887. delete pItem;
  888. #ifdef _DEBUG
  889. //afxDump << strItem << "\n";
  890. #endif
  891. }
  892. m_pClasses->RemoveAll( );
  893. }
  894. pObject = GetObject( &m_dwRoot );
  895. delete pObject;
  896. CreateRoot( );
  897. }
  898. //***********************************************************
  899. // Function:
  900. // Arguments:
  901. // Return:
  902. // Purpose:
  903. // Author(s):
  904. // Revision:
  905. // Date:
  906. //***********************************************************
  907. void CMainDoc::OnUpdateDisablefilter(CCmdUI* pCmdUI)
  908. {
  909. // TODO: Add your command update UI handler code here
  910. pCmdUI->SetCheck( !m_bApplyFilter );
  911. }
  912. //***********************************************************
  913. // Function:
  914. // Arguments:
  915. // Return:
  916. // Purpose:
  917. // Author(s):
  918. // Revision:
  919. // Date:
  920. //***********************************************************
  921. void CMainDoc::OnUseGeneric()
  922. {
  923. // TODO: Add your command handler code here
  924. m_bUseGeneric = !m_bUseGeneric;
  925. }
  926. //***********************************************************
  927. // Function:
  928. // Arguments:
  929. // Return:
  930. // Purpose:
  931. // Author(s):
  932. // Revision:
  933. // Date:
  934. //***********************************************************
  935. void CMainDoc::OnUpdateUseGeneric(CCmdUI* pCmdUI)
  936. {
  937. // TODO: Add your command update UI handler code here
  938. pCmdUI->SetCheck( m_bUseGeneric );
  939. }
  940. //***********************************************************
  941. // Function:
  942. // Arguments:
  943. // Return:
  944. // Purpose:
  945. // Author(s):
  946. // Revision:
  947. // Date:
  948. //***********************************************************
  949. void CMainDoc::OnUpdateUseGetExPutEx(CCmdUI* pCmdUI)
  950. {
  951. // TODO: Add your command update UI handler code here
  952. pCmdUI->SetCheck( m_bUseGetEx );
  953. }
  954. //***********************************************************
  955. // Function:
  956. // Arguments:
  957. // Return:
  958. // Purpose:
  959. // Author(s):
  960. // Revision:
  961. // Date:
  962. //***********************************************************
  963. void CMainDoc::OnUseGetExPutEx()
  964. {
  965. // TODO: Add your command handler code here
  966. m_bUseGetEx = !m_bUseGetEx;
  967. }
  968. //***********************************************************
  969. // Function:
  970. // Arguments:
  971. // Return:
  972. // Purpose:
  973. // Author(s):
  974. // Revision:
  975. // Date:
  976. //***********************************************************
  977. void CMainDoc::OnUsepropertiesList()
  978. {
  979. // TODO: Add your command handler code here
  980. m_bUsePropertiesList = !m_bUsePropertiesList;
  981. }
  982. //***********************************************************
  983. // Function:
  984. // Arguments:
  985. // Return:
  986. // Purpose:
  987. // Author(s):
  988. // Revision:
  989. // Date:
  990. //***********************************************************
  991. void CMainDoc::OnUpdateUsepropertiesList(CCmdUI* pCmdUI)
  992. {
  993. // TODO: Add your command update UI handler code here
  994. pCmdUI->SetCheck( m_bUsePropertiesList );
  995. }
  996. //***********************************************************
  997. // Function:
  998. // Arguments:
  999. // Return:
  1000. // Purpose:
  1001. // Author(s):
  1002. // Revision:
  1003. // Date:
  1004. //***********************************************************
  1005. void CMainDoc::SetUseGeneric( BOOL bUseGeneric )
  1006. {
  1007. m_bUseGeneric = bUseGeneric;
  1008. }