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.

536 lines
16 KiB

  1. //+-------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. //
  5. // Copyright (C) Microsoft Corporation, 1998 - 1999
  6. //
  7. // File: editor.h
  8. //
  9. //--------------------------------------------------------------------------
  10. #ifndef _ADSIEDIT_EDIT_H
  11. #define _ADSIEDIT_EDIT_H
  12. class CADSIEditConnectionNode;
  13. class CADSIFilterObject;
  14. #include "common.h"
  15. #include "snapdata.h"
  16. #include "filterui.h"
  17. #include "query.h"
  18. typedef enum
  19. {
  20. QUERY_OK = 0,
  21. ERROR_TOO_MANY_NODES
  22. } QUERY_STATE;
  23. extern LPCWSTR g_lpszGC;
  24. class CADSIEditContainerNode;
  25. ///////////////////////////////////////////////////////////////////////////////
  26. // CADSIEditBackgroundThread
  27. class CADSIEditBackgroundThread : public CBackgroundThread
  28. {
  29. public:
  30. CADSIEditBackgroundThread() : CBackgroundThread(){};
  31. virtual BOOL InitInstance()
  32. {
  33. HRESULT hr = ::OleInitialize(NULL);
  34. if (FAILED(hr))
  35. {
  36. return FALSE;
  37. }
  38. return TRUE;
  39. } // MFC override
  40. virtual int ExitInstance()
  41. {
  42. ::OleUninitialize();
  43. return CWinThread::ExitInstance();
  44. }
  45. };
  46. /////////////////////////////////////////////////////////////////////////////////
  47. // CADsObject :
  48. class CADsObject : public CObject
  49. {
  50. public:
  51. CADsObject(CADSIEditConnectionNode* cConnectNode);
  52. CADsObject(CADsObject* pADsObject);
  53. CADsObject();
  54. CADSIEditConnectionNode* GetConnectionNode() { return m_pConnectionNode; }
  55. void SetConnectionNode(CADSIEditConnectionNode* pConnectionNode) { m_pConnectionNode = pConnectionNode; }
  56. void GetName(CString& sName) { sName = m_sName; }
  57. void SetName(LPCWSTR lpszName);
  58. void GetDN(CString& sDN) { sDN = m_sDN; }
  59. PCWSTR GetDNString() { return m_sDN; }
  60. void SetDN(LPCWSTR lpszDN) { m_sDN = lpszDN; }
  61. void GetPath(CString& sPath) { sPath = m_sPath; }
  62. void SetPath(LPCWSTR sPath) { m_sPath = sPath; }
  63. void GetClass(CString& sClass ) { sClass = m_sClass; }
  64. void SetClass(LPCWSTR lpszClass) { m_sClass = lpszClass; }
  65. BOOL GetContainer() { return m_bContainer; }
  66. void SetContainer(const BOOL bContainer) { m_bContainer = bContainer; }
  67. BOOL IsIntermediateNode() { return m_bIntermediate; }
  68. void SetIntermediateNode(BOOL bIntermediate) { m_bIntermediate = bIntermediate; }
  69. BOOL IsComplete() { return m_bComplete; }
  70. void SetComplete(const BOOL bComplete) { m_bComplete = bComplete; }
  71. PCWSTR GetNCName() { return m_szNCName; }
  72. void SetNCName(PCWSTR pszNCName) { m_szNCName = pszNCName; }
  73. private:
  74. CADSIEditConnectionNode* m_pConnectionNode;
  75. CString m_sName;
  76. CString m_sDN;
  77. CString m_sClass;
  78. CString m_sPath;
  79. CString m_szNCName;
  80. BOOL m_bContainer;
  81. BOOL m_bIntermediate;
  82. BOOL m_bComplete;
  83. };
  84. ///////////////////////////////////////////////////////////////////////////////
  85. // CADSIFilterObject
  86. class CADSIFilterObject
  87. {
  88. public :
  89. CADSIFilterObject();
  90. CADSIFilterObject(CADSIFilterObject* pFilterObject);
  91. ~CADSIFilterObject() {}
  92. void GetFilterString(CString& sFilter);
  93. void GetUserDefinedFilter(CString& sUserFilter) { sUserFilter = m_sUserFilter; }
  94. void SetUserDefinedFilter(LPCWSTR lpszUserFilter) { m_sUserFilter = lpszUserFilter; }
  95. void GetContainerList(CStringList* pContainerList) { CopyStringList(pContainerList, &m_ContainerList); }
  96. void SetContainerList(CStringList* pContainerList) { CopyStringList(&m_ContainerList, pContainerList); }
  97. BOOL InUse() { return m_bInUse; }
  98. void SetInUse(BOOL bInUse) { m_bInUse = bInUse; }
  99. void Save(IStream* pStm);
  100. static HRESULT CreateFilterFromStream(IStream* pStm, CADSIFilterObject** ppFilterObject);
  101. private :
  102. CString m_sFilterString;
  103. CString m_sUserFilter;
  104. CStringList m_ContainerList;
  105. BOOL m_bInUse;
  106. };
  107. ////////////////////////////////////////////////////////////////////////////////
  108. // CCredentialObject
  109. class CCredentialObject
  110. {
  111. public :
  112. CCredentialObject()
  113. {
  114. m_sUsername = _T("");
  115. m_lpszPassword = NULL;
  116. m_bUseCredentials = FALSE;
  117. }
  118. CCredentialObject(CCredentialObject* pCredObject);
  119. ~CCredentialObject()
  120. {
  121. free(m_lpszPassword);
  122. }
  123. void GetUsername(CString& sUsername) { sUsername = m_sUsername; }
  124. void SetUsername(LPCWSTR lpszUsername) { m_sUsername = lpszUsername; }
  125. HRESULT GetPassword(LPWSTR lpszPassword);
  126. HRESULT SetPasswordFromHwnd(HWND hWnd);
  127. BOOL UseCredentials() { return m_bUseCredentials; }
  128. void SetUseCredentials(const BOOL bUseCred) { m_bUseCredentials = bUseCred; }
  129. private :
  130. CString m_sUsername;
  131. LPWSTR m_lpszPassword;
  132. BOOL m_bUseCredentials;
  133. };
  134. /////////////////////////////////////////////////////////////////////////////////
  135. // CConnectionData
  136. class CConnectionData : public CADsObject
  137. {
  138. public:
  139. CConnectionData();
  140. CConnectionData(CADSIEditConnectionNode* pConnectNode);
  141. CConnectionData(CConnectionData* pConnectData);
  142. ~CConnectionData();
  143. void ConstructorHelper();
  144. void GetDomainServer(CString& sServer) { sServer = m_sDomainServer; }
  145. void SetDomainServer(LPCWSTR lpszDomainServer) { m_sDomainServer = lpszDomainServer; }
  146. void GetPort(CString& sPort) { sPort = m_sPort; }
  147. void SetPort(LPCWSTR lpszPort) { m_sPort = lpszPort; }
  148. void GetDistinguishedName(CString& sDistinguished) { sDistinguished = m_sDistinguishedName; }
  149. void SetDistinguishedName(LPCWSTR lpszDistName) { m_sDistinguishedName = lpszDistName; }
  150. void GetNamingContext(CString& sNamingContext) { sNamingContext = m_sNamingContext; }
  151. void SetNamingContext(LPCWSTR lpszNamingContext) { m_sNamingContext = lpszNamingContext; }
  152. void GetBasePath(CString& sBasePath) { sBasePath = m_sBasePath; }
  153. void SetBasePath(LPCWSTR lpszPath) { m_sBasePath = lpszPath; }
  154. void GetBaseLDAPPath(CString& sBasePath);
  155. void GetLDAP(CString& sLDAP) { sLDAP = m_sLDAP; }
  156. void SetLDAP(LPCWSTR lpszLDAP) { m_sLDAP = lpszLDAP; }
  157. BOOL GetUserDefinedServer() { return m_bUserDefinedServer; }
  158. void SetUserDefinedServer(BOOL bUserDefinedServer) { m_bUserDefinedServer = bUserDefinedServer; }
  159. void SetPath(LPCWSTR lpszPath) { CADsObject::SetPath(lpszPath); }
  160. // Schema paths
  161. //
  162. void SetSchemaPath(LPCWSTR lpszPath) { m_sSchemaPath = lpszPath; }
  163. HRESULT GetSchemaPath(CString& sPath);
  164. void SetAbstractSchemaPath(LPCWSTR lpszPath) { m_sAbstractSchemaPath = lpszPath; }
  165. void GetAbstractSchemaPath(CString& sPath);
  166. // Filter Options
  167. //
  168. void SetFilter(CADSIFilterObject* pFilter) { m_pFilterObject = pFilter; }
  169. CADSIFilterObject* GetFilter() { return m_pFilterObject; }
  170. CCredentialObject* GetCredentialObject() { return m_pCredentialsObject; }
  171. ULONG GetMaxObjectCount() { return m_nMaxObjectCount; }
  172. void SetMaxObjectCount(ULONG nMaxCount) { m_nMaxObjectCount = nMaxCount; }
  173. BOOL IsGC() { return (_wcsicmp(LPCWSTR(m_sLDAP), g_lpszGC) == 0); }
  174. BOOL IsRootDSE() { return m_bRootDSE; }
  175. void SetRootDSE(const BOOL bRootDSE) { m_bRootDSE = bRootDSE; }
  176. void SetIDirectoryInterface(IDirectoryObject* pDirObject);
  177. void Save(IStream* pStm);
  178. static CConnectionData* Load(IStream* pStm);
  179. static HRESULT LoadBasePathFromContext(CConnectionData* pConnectData, const CString sContext);
  180. static HRESULT GetServerNameFromDefault(CConnectionData* pConnectData);
  181. void BuildPath();
  182. HRESULT GetADSIServerName(OUT CString& szServer, IN IUnknown* pUnk);
  183. private:
  184. CString m_sBasePath;
  185. CString m_sDomainServer;
  186. CString m_sPort;
  187. CString m_sDistinguishedName;
  188. CString m_sNamingContext;
  189. CString m_sLDAP;
  190. CString m_sSchemaPath;
  191. CString m_sAbstractSchemaPath;
  192. // Filter Options
  193. //
  194. CADSIFilterObject* m_pFilterObject;
  195. CCredentialObject* m_pCredentialsObject;
  196. IDirectoryObject* m_pDirObject;
  197. BOOL m_bCredentials;
  198. BOOL m_bRootDSE;
  199. BOOL m_bUserDefinedServer;
  200. ULONG m_nMaxObjectCount; // Maximum Number of objects per container
  201. };
  202. //////////////////////////////////////////////////////////////////////////////////
  203. // CADSIEditLeafNode :
  204. class CADSIEditLeafNode : public CLeafNode
  205. {
  206. typedef enum
  207. {
  208. notLoaded = 0, // initial state, valid only if server never contacted
  209. loading,
  210. loaded,
  211. unableToLoad,
  212. accessDenied
  213. } nodeStateType;
  214. protected:
  215. CADsObject* m_pADsObject;
  216. public:
  217. CADSIEditLeafNode(CADsObject* pADsObject)
  218. {
  219. m_pADsObject = pADsObject;
  220. }
  221. ~CADSIEditLeafNode()
  222. {
  223. delete m_pADsObject;
  224. }
  225. // node info
  226. DECLARE_NODE_GUID()
  227. CADSIEditLeafNode(CADSIEditLeafNode* pLeafNode);
  228. virtual BOOL OnAddMenuItem(LPCONTEXTMENUITEM2 pContextMenuItem,
  229. long *pInsertionAllowed);
  230. virtual HRESULT OnCommand(long nCommandID,
  231. DATA_OBJECT_TYPES type,
  232. CComponentDataObject* pComponentData,
  233. CNodeList* pNodeList);
  234. virtual void OnConnectToNCFromHere(CComponentDataObject* pComponentData);
  235. virtual BOOL OnSetRenameVerbState(DATA_OBJECT_TYPES type,
  236. BOOL* pbHide,
  237. CNodeList* pNodeList);
  238. virtual BOOL OnSetDeleteVerbState(DATA_OBJECT_TYPES type,
  239. BOOL* pbHide,
  240. CNodeList* pNodeList);
  241. virtual void OnDelete(CComponentDataObject* pComponentData,
  242. CNodeList* pNodeList);
  243. virtual HRESULT OnRename(CComponentDataObject* pComponentData, LPWSTR lpszNewName);
  244. virtual void OnMove(CComponentDataObject* pComponentData);
  245. virtual LPCWSTR GetString(int nCol);
  246. virtual int GetImageIndex(BOOL bOpenImage);
  247. virtual BOOL FindNode(LPCWSTR lpszPath, CList<CTreeNode*, CTreeNode*>& foundNodeList);
  248. virtual void RefreshOverlappedTrees(CString& szPath, CComponentDataObject* pComponentData);
  249. virtual BOOL HasPropertyPages(DATA_OBJECT_TYPES type,
  250. BOOL* pbHideVerb,
  251. CNodeList* pNodeList);
  252. virtual HRESULT CreatePropertyPages(LPPROPERTYSHEETCALLBACK lpProvider,
  253. LONG_PTR handle,
  254. CNodeList* pNodeList);
  255. virtual BOOL CanCloseSheets();
  256. virtual void SetContainer(BOOL container) { m_pADsObject->SetContainer(container); }
  257. BOOL BuildSchemaPath(CString& sPath);
  258. virtual LPCONTEXTMENUITEM2 OnGetContextMenuItemTable()
  259. { return CADSIEditLeafMenuHolder::GetContextMenuItem(); }
  260. virtual CADsObject* GetADsObject() { return m_pADsObject; }
  261. CContainerNode* GetRootContainer()
  262. { return (m_pContainer != NULL) ? m_pContainer->GetRootContainer() : NULL; }
  263. };
  264. //////////////////////////////////////////////////////////////////////////////////
  265. // CADSIEditContainerNode :
  266. class CADSIEditContainerNode : public CMTContainerNode
  267. {
  268. public:
  269. // enumeration for node states, to handle icon changes
  270. typedef enum
  271. {
  272. notLoaded = 0, // initial state, valid only if server never contacted
  273. loading,
  274. loaded,
  275. unableToLoad,
  276. accessDenied
  277. } nodeStateType;
  278. public:
  279. CADSIEditContainerNode() : m_pPartitionsColumnSet(NULL)
  280. {
  281. m_pADsObject = new CADsObject();
  282. m_nState = notLoaded;
  283. m_szDescriptionText = L"";
  284. }
  285. CADSIEditContainerNode(CADsObject* pADsObject);
  286. CADSIEditContainerNode(CADSIEditContainerNode* pContNode);
  287. ~CADSIEditContainerNode()
  288. {
  289. delete m_pADsObject;
  290. if (m_pPartitionsColumnSet)
  291. {
  292. delete m_pPartitionsColumnSet;
  293. m_pPartitionsColumnSet = NULL;
  294. }
  295. }
  296. // node info
  297. DECLARE_NODE_GUID()
  298. virtual BOOL OnAddMenuItem(LPCONTEXTMENUITEM2 pContextMenuItem,
  299. long *pInsertionAllowed);
  300. virtual HRESULT OnCommand(long nCommandID,
  301. DATA_OBJECT_TYPES type,
  302. CComponentDataObject* pComponentData,
  303. CNodeList* pNodeList);
  304. virtual BOOL OnSetRenameVerbState(DATA_OBJECT_TYPES type,
  305. BOOL* pbHide,
  306. CNodeList* pNodeList);
  307. virtual BOOL OnSetDeleteVerbState(DATA_OBJECT_TYPES type,
  308. BOOL* pbHide,
  309. CNodeList* pNodeList);
  310. virtual void OnDelete(CComponentDataObject* pComponentData,
  311. CNodeList* pNodeList);
  312. virtual HRESULT OnRename(CComponentDataObject* pComponentData, LPWSTR lpszNewName);
  313. virtual void OnMove(CComponentDataObject* pComponentData);
  314. virtual void OnCreate(CComponentDataObject* pComponentData);
  315. virtual void OnConnectFromHere(CComponentDataObject* pComponentData);
  316. virtual void OnConnectToNCFromHere(CComponentDataObject* pComponentData);
  317. virtual CQueryObj* OnCreateQuery();
  318. virtual LPCWSTR GetString(int nCol);
  319. virtual BOOL HasPropertyPages(DATA_OBJECT_TYPES type,
  320. BOOL* pbHideVerb,
  321. CNodeList* pNodeList);
  322. virtual HRESULT CreatePropertyPages(LPPROPERTYSHEETCALLBACK lpProvider,
  323. LONG_PTR handle,
  324. CNodeList* pNodeList);
  325. virtual BOOL OnSetRefreshVerbState(DATA_OBJECT_TYPES type,
  326. BOOL* pbHide,
  327. CNodeList* pNodeList);
  328. virtual void SetContainer(BOOL container) { m_pADsObject->SetContainer(container); }
  329. virtual LPCONTEXTMENUITEM2 OnGetContextMenuItemTable()
  330. { return CADSIEditContainerMenuHolder::GetContextMenuItem(); }
  331. virtual int GetImageIndex(BOOL bOpenImage);
  332. virtual CBackgroundThread* CreateThreadObject()
  333. {
  334. return new CADSIEditBackgroundThread(); // override if need derived tipe of object
  335. }
  336. BOOL GetNamingAttribute(LPCWSTR lpszClass, CStringList* sNamingAttr);
  337. BOOL BuildSchemaPath(CString& sPath);
  338. virtual void OnDeleteMultiple(CComponentDataObject* pComponentData,
  339. CNodeList* pNodeList);
  340. virtual HRESULT DeleteChild(LPCWSTR lpszClass, LPCWSTR lpszPath);
  341. virtual HRESULT DeleteSubtree(LPCWSTR lpszPath);
  342. virtual BOOL FindNode(LPCWSTR lpszPath, CList<CTreeNode*, CTreeNode*>& foundNodeList);
  343. void RefreshOverlappedTrees(CString& sPath, CComponentDataObject* pComponentData);
  344. virtual CADsObject* GetADsObject() { return m_pADsObject; }
  345. virtual CColumnSet* GetColumnSet();
  346. virtual LPCWSTR GetColumnID()
  347. {
  348. return GetColumnSet()->GetColumnID();
  349. }
  350. virtual LPWSTR GetDescriptionBarText()
  351. {
  352. LPWSTR lpszFormat = L"%d Object(s)";
  353. int iCount = m_containerChildList.GetCount() + m_leafChildList.GetCount();
  354. m_szDescriptionText.Format(lpszFormat, iCount);
  355. return (LPWSTR)(LPCWSTR)m_szDescriptionText;
  356. }
  357. //
  358. // Allow multiple selection
  359. //
  360. virtual HRESULT GetResultViewType(LPOLESTR* ppViewType, long* pViewOptions)
  361. {
  362. *pViewOptions = MMC_VIEW_OPTIONS_MULTISELECT;
  363. *ppViewType = NULL;
  364. return S_FALSE;
  365. }
  366. protected:
  367. virtual BOOL CanCloseSheets();
  368. virtual void OnChangeState(CComponentDataObject* pComponentDataObject);
  369. virtual void OnHaveData(CObjBase* pObj, CComponentDataObject* pComponentDataObject);
  370. virtual void OnError(DWORD dwErr);
  371. CADsObject* m_pADsObject;
  372. CADSIEditColumnSet* m_pPartitionsColumnSet;
  373. CString m_szDescriptionText;
  374. };
  375. //////////////////////////////////////////////////////////////////////
  376. class CADSIEditQueryObject : public CQueryObj
  377. {
  378. public:
  379. CADSIEditQueryObject(LPCWSTR lpszPath,
  380. LPCWSTR lpszFilter,
  381. ADS_SCOPEENUM scope,
  382. ULONG ulMaxObjectCount,
  383. CCredentialObject* pCredObject,
  384. BOOL bIsGC,
  385. CADSIEditConnectionNode* pConnectNode)
  386. : m_credentialObject(pCredObject)
  387. {
  388. m_sPath = lpszPath;
  389. m_sFilter = lpszFilter;
  390. m_ulMaxObjectCount = ulMaxObjectCount;
  391. m_Scope = scope;
  392. m_bIsGC = bIsGC;
  393. m_pPathCracker = NULL;
  394. // NOTE : this holds a pointer across threads but is not
  395. // being used. We should be sure not to use it or
  396. // find another way to put the pointer in the data
  397. // structures for any new nodes created
  398. //
  399. m_pConnectNode = pConnectNode;
  400. }
  401. virtual ~CADSIEditQueryObject()
  402. {
  403. /* if (m_pPathCracker != NULL)
  404. {
  405. m_pPathCracker->Release();
  406. }
  407. */ }
  408. virtual BOOL Enumerate();
  409. virtual bool IsContainer(PCWSTR pszClass, PCWSTR pszPath);
  410. BOOL IsGC() { return m_bIsGC; }
  411. void GetResults(CADSIQueryObject& enumSearch);
  412. void CreateNewObject(CString& sPath,
  413. ADS_OBJECT_INFO* pInfo,
  414. PCWSTR pszNCName);
  415. void CrackPath(const CString sName, CString& sPath, CString& sDN);
  416. IADsPathname* PathCracker();
  417. void SetFilter(LPCWSTR lpszFilter) { m_sFilter = lpszFilter; }
  418. void GetFilter(CString& sFilter) { sFilter = m_sFilter; }
  419. protected:
  420. // CADsObject *m_pADsObject;
  421. CString m_sPath;
  422. CString m_sFilter;
  423. ADS_SCOPEENUM m_Scope;
  424. BOOL m_bIsGC;
  425. ULONG m_ulMaxObjectCount;
  426. CCredentialObject m_credentialObject;
  427. CADSIEditConnectionNode* m_pConnectNode;
  428. CComPtr<IADsPathname> m_pPathCracker;
  429. };
  430. #endif _ADSIEDIT_EDIT_H