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.

429 lines
9.5 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(SPECIAL_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(DS_UI_NODE, 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* pComponentData, BOOL* pbHide)
  174. {
  175. int iSystemFlags = 0;
  176. CDSCookie* pCookie = NULL;
  177. ASSERT(typeid(*m_pNodeData) == typeid(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 pComponentData->CanEnableVerb(this);
  197. }
  198. BOOL CDSUINode::IsRenameAllowed(CDSComponentData* pComponentData, BOOL* pbHide)
  199. {
  200. int iSystemFlags = 0;
  201. CDSCookie* pCookie = NULL;
  202. ASSERT(typeid(*m_pNodeData) == typeid(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. bool enable = false;
  253. if (IsContainer())
  254. {
  255. if (GetFolderInfo()->IsExpanded())
  256. {
  257. enable = true;
  258. }
  259. }
  260. return pComponentData->CanEnableVerb(this) && enable;
  261. }
  262. BOOL CDSUINode::ArePropertiesAllowed(CDSComponentData* pComponentData, BOOL* pbHide)
  263. {
  264. CDSCookie* pCookie = NULL;
  265. ASSERT(typeid(*m_pNodeData) == typeid(CDSCookie));
  266. pCookie = dynamic_cast<CDSCookie*>(m_pNodeData);
  267. if (pCookie == NULL)
  268. {
  269. ASSERT(FALSE);
  270. *pbHide = TRUE;
  271. return FALSE;
  272. }
  273. if (wcscmp(pCookie->GetClass(), L"domainDNS") == 0)
  274. {
  275. //
  276. // domain node, just show properties
  277. //
  278. *pbHide = FALSE;
  279. return pComponentData->CanEnableVerb(this);
  280. }
  281. *pbHide = FALSE;
  282. return TRUE;
  283. }
  284. BOOL CDSUINode::IsCutAllowed(CDSComponentData* pComponentData, BOOL* pbHide)
  285. {
  286. //
  287. // For Sites and Services we only allow cut on server nodes
  288. //
  289. if (pComponentData->QuerySnapinType() == SNAPINTYPE_SITE)
  290. {
  291. CDSCookie* pCookie = dynamic_cast<CDSCookie*>(GetNodeData());
  292. if (pCookie)
  293. {
  294. if (_wcsicmp(pCookie->GetClass(), L"server") == 0)
  295. {
  296. *pbHide = FALSE;
  297. return TRUE;
  298. }
  299. *pbHide = TRUE;
  300. return FALSE;
  301. }
  302. }
  303. return IsDeleteAllowed(pComponentData, pbHide);
  304. }
  305. BOOL CDSUINode::IsCopyAllowed(CDSComponentData*, BOOL* pbHide)
  306. {
  307. *pbHide = TRUE;
  308. return FALSE;
  309. }
  310. BOOL CDSUINode::IsPasteAllowed(CDSComponentData* pComponentData, BOOL* pbHide)
  311. {
  312. //
  313. // For Sites and Services we only allow paste on serversContainers
  314. //
  315. if (pComponentData->QuerySnapinType() == SNAPINTYPE_SITE)
  316. {
  317. CDSCookie* pCookie = dynamic_cast<CDSCookie*>(GetNodeData());
  318. if (pCookie)
  319. {
  320. CString szClass;
  321. szClass = pCookie->GetClass();
  322. if (_wcsicmp(pCookie->GetClass(), L"serversContainer") == 0)
  323. {
  324. *pbHide = FALSE;
  325. return TRUE;
  326. }
  327. *pbHide = TRUE;
  328. return FALSE;
  329. }
  330. }
  331. *pbHide = FALSE;
  332. return TRUE;
  333. }
  334. CContextMenuVerbs* CDSUINode::GetContextMenuVerbsObject(CDSComponentData* pComponentData)
  335. {
  336. TRACE(L"Entering CDSUINode::GetContextMenuVerbsObject\n");
  337. if (m_pMenuVerbs == NULL)
  338. {
  339. if (pComponentData->QuerySnapinType() == SNAPINTYPE_SITE)
  340. {
  341. TRACE(L"Creating new CSARContextMenuVerbs object\n");
  342. m_pMenuVerbs = new CSARContextMenuVerbs(pComponentData);
  343. }
  344. else
  345. {
  346. TRACE(L"Creating new CDSAdminContextMenuVerbs object\n");
  347. m_pMenuVerbs = new CDSAdminContextMenuVerbs(pComponentData);
  348. }
  349. }
  350. return m_pMenuVerbs;
  351. }
  352. BOOL CDSUINode::HasPropertyPages(LPDATAOBJECT)
  353. {
  354. BOOL bRet = TRUE;
  355. if (dynamic_cast<CDSCookie*>(GetNodeData()) == NULL)
  356. {
  357. bRet = FALSE;
  358. }
  359. return bRet;
  360. }