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.

413 lines
8.7 KiB

  1. //+-------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1992 - 1999
  5. //
  6. // File: DSCookie.cpp
  7. //
  8. //--------------------------------------------------------------------------
  9. #include "stdafx.h"
  10. #include "dscookie.h"
  11. #include "dssnap.h"
  12. #include "ContextMenu.h"
  13. #include <notify.h>
  14. #ifdef _DEBUG
  15. #define new DEBUG_NEW
  16. #undef THIS_FILE
  17. static char THIS_FILE[] = __FILE__;
  18. #endif
  19. /////////////////////////////////////////////////////////////////////////////
  20. // CDSCookie
  21. CDSCookie::CDSCookie()
  22. {
  23. m_ppChildList = NULL;
  24. m_bDisabled = FALSE;
  25. m_bNonExpiringPassword = FALSE;
  26. m_iSystemFlags = 0;
  27. m_pCacheItem = NULL;
  28. m_pExtraInfo = NULL;
  29. m_pModifiedTime = NULL;
  30. }
  31. CDSCookie::~CDSCookie()
  32. {
  33. if (m_ppChildList)
  34. LocalFree (m_ppChildList);
  35. if (m_pExtraInfo != NULL)
  36. {
  37. delete m_pExtraInfo;
  38. m_pExtraInfo = NULL;
  39. }
  40. if (m_pModifiedTime != NULL)
  41. free(m_pModifiedTime);
  42. //TRACE(_T("CDSCookie::Deleted (%s)\n"), m_strName);
  43. }
  44. CDSColumnSet* CDSUINode::GetColumnSet(CDSComponentData* pComponentData)
  45. {
  46. CDSColumnSet* pColumnSet = NULL;
  47. if (IsContainer())
  48. {
  49. CDSCookie* pCookie = GetDSCookieFromUINode(this);
  50. if (pCookie != NULL)
  51. {
  52. PCWSTR pszClass = pCookie->GetClass();
  53. if (pszClass != NULL)
  54. {
  55. pColumnSet = GetFolderInfo()->GetColumnSet(pszClass, pComponentData);
  56. }
  57. }
  58. if (pColumnSet == NULL)
  59. {
  60. pColumnSet = GetFolderInfo()->GetColumnSet(DEFAULT_COLUMN_SET, pComponentData);
  61. }
  62. }
  63. return pColumnSet;
  64. }
  65. int CDSCookie::GetImage(BOOL bOpen)
  66. {
  67. ASSERT(m_pCacheItem != NULL);
  68. return m_pCacheItem->GetIconIndex(this, bOpen);
  69. }
  70. GUID* CDSCookie::GetGUID()
  71. {
  72. if(m_pCacheItem != NULL)
  73. return m_pCacheItem->GetGUID();
  74. return (GUID*)&GUID_NULL;
  75. }
  76. LPCWSTR CDSCookie::GetClass()
  77. {
  78. if (m_pCacheItem == NULL)
  79. return L"";
  80. return m_pCacheItem->GetClassName();
  81. }
  82. LPCWSTR CDSCookie::GetLocalizedClassName()
  83. {
  84. // try to see if we have extra info to use
  85. if (m_pExtraInfo != NULL)
  86. {
  87. LPCWSTR lpsz = m_pExtraInfo->GetFriendlyClassName();
  88. if ((lpsz != NULL) && (lpsz[0] != NULL))
  89. return lpsz;
  90. }
  91. // try the class cache
  92. if (m_pCacheItem != NULL)
  93. {
  94. return m_pCacheItem->GetFriendlyClassName();
  95. }
  96. return L"";
  97. }
  98. //+-------------------------------------------------------------------------
  99. // Value Management functions
  100. //+-------------------------------------------------------------------------
  101. void
  102. CDSCookie::SetChildList (WCHAR **ppList)
  103. {
  104. if (m_ppChildList) {
  105. LocalFree (m_ppChildList);
  106. }
  107. m_ppChildList=ppList;
  108. }
  109. /////////////////////////////////////////////////////////////////////////////
  110. // CDSUINode : UI node corresponding to a DS object (result of an ADSI query)
  111. CDSUINode::CDSUINode(CUINode* pParentNode) : CUINode(pParentNode)
  112. {
  113. }
  114. LPCWSTR CDSUINode::GetDisplayString(int nCol, CDSColumnSet* pColumnSet)
  115. {
  116. // if we are out of range for the column set, just return
  117. if ( (nCol < 0) || pColumnSet == NULL || (nCol >= pColumnSet->GetNumCols()) )
  118. {
  119. return L"";
  120. }
  121. // we have a valid range
  122. LPCWSTR lpszDisplayString = NULL;
  123. CDSColumn* pCol = (CDSColumn*)pColumnSet->GetColumnAt(nCol);
  124. ASSERT(pCol != NULL);
  125. switch ( pCol->GetColumnType())
  126. {
  127. case ATTR_COLTYPE_NAME:
  128. lpszDisplayString = const_cast<LPTSTR>(GetName());
  129. break;
  130. case ATTR_COLTYPE_CLASS:
  131. lpszDisplayString = const_cast<LPTSTR>(GetCookie()->GetLocalizedClassName());
  132. break;
  133. case ATTR_COLTYPE_DESC:
  134. lpszDisplayString = const_cast<LPTSTR>(GetDesc());
  135. break;
  136. default:
  137. ASSERT(FALSE);
  138. // fall through
  139. case ATTR_COLTYPE_SPECIAL:
  140. case ATTR_COLTYPE_MODIFIED_TIME:
  141. {
  142. // determine how many SPECIAL columns came before this one
  143. int nSpecialCol = 0;
  144. int idx = 0;
  145. POSITION pos = pColumnSet->GetHeadPosition();
  146. while (idx < nCol && pos != NULL)
  147. {
  148. CDSColumn* pColumn = (CDSColumn*)pColumnSet->GetNext(pos);
  149. ASSERT(pColumn != NULL);
  150. if ((pColumn->GetColumnType() == ATTR_COLTYPE_SPECIAL || pColumn->GetColumnType() == ATTR_COLTYPE_MODIFIED_TIME) &&
  151. pColumn->IsVisible())
  152. {
  153. nSpecialCol++;
  154. }
  155. idx++;
  156. }
  157. CStringList& strlist = GetCookie()->GetParentClassSpecificStrings();
  158. POSITION pos2 = strlist.FindIndex( nSpecialCol );
  159. if ( NULL != pos2 )
  160. {
  161. CString& strref = strlist.GetAt( pos2 );
  162. lpszDisplayString = const_cast<LPTSTR>((LPCTSTR)strref);
  163. }
  164. else
  165. {
  166. lpszDisplayString = L"";
  167. }
  168. }
  169. } // switch
  170. ASSERT(lpszDisplayString != NULL);
  171. return lpszDisplayString;
  172. }
  173. BOOL CDSUINode::IsDeleteAllowed(CDSComponentData*, BOOL* pbHide)
  174. {
  175. int iSystemFlags = 0;
  176. CDSCookie* pCookie = NULL;
  177. ASSERT(IS_CLASS(*m_pNodeData, CDSCookie));
  178. pCookie = dynamic_cast<CDSCookie*>(m_pNodeData);
  179. if (pCookie == NULL)
  180. {
  181. ASSERT(FALSE);
  182. *pbHide = TRUE;
  183. return FALSE;
  184. }
  185. if (wcscmp(pCookie->GetClass(), L"domainDNS") == 0)
  186. {
  187. *pbHide = TRUE;
  188. return FALSE;
  189. }
  190. *pbHide = FALSE;
  191. iSystemFlags = pCookie->GetSystemFlags();
  192. if (iSystemFlags & FLAG_DISALLOW_DELETE)
  193. {
  194. return FALSE;
  195. }
  196. return TRUE;
  197. }
  198. BOOL CDSUINode::IsRenameAllowed(CDSComponentData* pComponentData, BOOL* pbHide)
  199. {
  200. int iSystemFlags = 0;
  201. CDSCookie* pCookie = NULL;
  202. ASSERT(IS_CLASS(*m_pNodeData, CDSCookie));
  203. pCookie = dynamic_cast<CDSCookie*>(m_pNodeData);
  204. if (pCookie == NULL)
  205. {
  206. ASSERT(FALSE);
  207. *pbHide = TRUE;
  208. return FALSE;
  209. }
  210. //
  211. // Disable rename for domainDNS and computer objects
  212. //
  213. if (wcscmp(pCookie->GetClass(), L"domainDNS") == 0 ||
  214. wcscmp(pCookie->GetClass(), L"computer") == 0)
  215. {
  216. *pbHide = TRUE;
  217. return FALSE;
  218. }
  219. BOOL bEnable = pComponentData->CanEnableVerb(this);
  220. SnapinType iSnapinType = pComponentData->QuerySnapinType();
  221. *pbHide = FALSE;
  222. iSystemFlags = pCookie->GetSystemFlags();
  223. switch (iSnapinType)
  224. {
  225. case SNAPINTYPE_DS:
  226. case SNAPINTYPE_DSEX:
  227. if (iSystemFlags & FLAG_DOMAIN_DISALLOW_RENAME)
  228. {
  229. return FALSE;
  230. }
  231. else
  232. {
  233. return bEnable;
  234. }
  235. case SNAPINTYPE_SITE:
  236. if (iSystemFlags & FLAG_CONFIG_ALLOW_RENAME)
  237. {
  238. return bEnable;
  239. }
  240. else
  241. {
  242. return FALSE;
  243. }
  244. default:
  245. break;
  246. }
  247. return TRUE;
  248. }
  249. BOOL CDSUINode::IsRefreshAllowed(CDSComponentData* pComponentData, BOOL* pbHide)
  250. {
  251. *pbHide = FALSE;
  252. return pComponentData->CanEnableVerb(this);
  253. }
  254. BOOL CDSUINode::ArePropertiesAllowed(CDSComponentData* pComponentData, BOOL* pbHide)
  255. {
  256. CDSCookie* pCookie = NULL;
  257. ASSERT(IS_CLASS(*m_pNodeData, CDSCookie));
  258. pCookie = dynamic_cast<CDSCookie*>(m_pNodeData);
  259. if (pCookie == NULL)
  260. {
  261. ASSERT(FALSE);
  262. *pbHide = TRUE;
  263. return FALSE;
  264. }
  265. if (wcscmp(pCookie->GetClass(), L"domainDNS") == 0)
  266. {
  267. //
  268. // domain node, just show properties
  269. //
  270. *pbHide = FALSE;
  271. return pComponentData->CanEnableVerb(this);
  272. }
  273. *pbHide = FALSE;
  274. return TRUE;
  275. }
  276. BOOL CDSUINode::IsCutAllowed(CDSComponentData* pComponentData, BOOL* pbHide)
  277. {
  278. //
  279. // For Sites and Services we only allow cut on server nodes
  280. //
  281. if (pComponentData->QuerySnapinType() == SNAPINTYPE_SITE)
  282. {
  283. CDSCookie* pCookie = dynamic_cast<CDSCookie*>(GetNodeData());
  284. if (pCookie)
  285. {
  286. if (_wcsicmp(pCookie->GetClass(), L"server") == 0)
  287. {
  288. *pbHide = FALSE;
  289. return TRUE;
  290. }
  291. *pbHide = TRUE;
  292. return FALSE;
  293. }
  294. }
  295. return IsDeleteAllowed(pComponentData, pbHide);
  296. }
  297. BOOL CDSUINode::IsCopyAllowed(CDSComponentData*, BOOL* pbHide)
  298. {
  299. *pbHide = TRUE;
  300. return FALSE;
  301. }
  302. BOOL CDSUINode::IsPasteAllowed(CDSComponentData* pComponentData, BOOL* pbHide)
  303. {
  304. //
  305. // For Sites and Services we only allow paste on serversContainers
  306. //
  307. if (pComponentData->QuerySnapinType() == SNAPINTYPE_SITE)
  308. {
  309. CDSCookie* pCookie = dynamic_cast<CDSCookie*>(GetNodeData());
  310. if (pCookie)
  311. {
  312. CString szClass;
  313. szClass = pCookie->GetClass();
  314. if (_wcsicmp(pCookie->GetClass(), L"serversContainer") == 0)
  315. {
  316. *pbHide = FALSE;
  317. return TRUE;
  318. }
  319. *pbHide = TRUE;
  320. return FALSE;
  321. }
  322. }
  323. *pbHide = FALSE;
  324. return TRUE;
  325. }
  326. CContextMenuVerbs* CDSUINode::GetContextMenuVerbsObject(CDSComponentData* pComponentData)
  327. {
  328. if (m_pMenuVerbs == NULL)
  329. {
  330. if (pComponentData->QuerySnapinType() == SNAPINTYPE_SITE)
  331. {
  332. m_pMenuVerbs = new CSARContextMenuVerbs(pComponentData);
  333. }
  334. else
  335. {
  336. m_pMenuVerbs = new CDSAdminContextMenuVerbs(pComponentData);
  337. }
  338. }
  339. return m_pMenuVerbs;
  340. }
  341. BOOL CDSUINode::HasPropertyPages(LPDATAOBJECT)
  342. {
  343. BOOL bRet = TRUE;
  344. if (dynamic_cast<CDSCookie*>(GetNodeData()) == NULL)
  345. {
  346. bRet = FALSE;
  347. }
  348. return bRet;
  349. }