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.

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