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.

1369 lines
38 KiB

  1. /**********************************************************************/
  2. /** Microsoft Windows/NT **/
  3. /** Copyright(c) Microsoft Corporation, 1997 - 1999 **/
  4. /**********************************************************************/
  5. /*
  6. AcsData.cpp
  7. Implement DataObject classes used in ACS
  8. FILE HISTORY:
  9. 11/11/97 Wei Jiang Created
  10. */
  11. #include "stdafx.h"
  12. #include "resource.h" // main symbol definition
  13. #include "helper.h"
  14. #include "acsdata.h"
  15. #include "acshand.h"
  16. ///////////////////////////////////////////////////////////////////////////////
  17. //
  18. // CDSIDataObject
  19. //
  20. //
  21. unsigned int CDSIDataObject::m_cfDsObjectNames =
  22. RegisterClipboardFormat(CFSTR_DSOBJECTNAMES);
  23. //+----------------------------------------------------------------------------
  24. //
  25. // Method: CDSIDataObject::IDataObject::GetData
  26. //
  27. // Synopsis: Returns data, in this case the Prop Page format data.
  28. //
  29. //-----------------------------------------------------------------------------
  30. STDMETHODIMP
  31. CDSIDataObject::GetData(FORMATETC * pFormatEtc, STGMEDIUM * pMedium)
  32. {
  33. HRESULT hr = S_OK;
  34. TRACE(_T("CDSIDataObject::GetData\n"));
  35. USES_CONVERSION;
  36. if (IsBadWritePtr(pMedium, sizeof(STGMEDIUM)))
  37. {
  38. return E_INVALIDARG;
  39. }
  40. if (!(pFormatEtc->tymed & TYMED_HGLOBAL))
  41. {
  42. return DV_E_TYMED;
  43. }
  44. if (pFormatEtc->cfFormat == m_cfDsObjectNames)
  45. {
  46. if(!m_bstrADsPath || !m_bstrClass)
  47. return DV_E_FORMATETC;
  48. // Return the object name and class.
  49. //
  50. LPCTSTR szPath = W2T(m_bstrADsPath);
  51. LPCTSTR szClass = W2T(m_bstrClass);
  52. int cbPath = sizeof(TCHAR) * (_tcslen(szPath) + 1);
  53. int cbClass = sizeof(TCHAR) * (_tcslen(szClass) + 1);
  54. int cbStruct = sizeof(DSOBJECTNAMES);
  55. LPDSOBJECTNAMES pDSObj;
  56. pDSObj = (LPDSOBJECTNAMES)GlobalAlloc(GMEM_FIXED | GMEM_ZEROINIT,
  57. cbStruct + cbPath + cbClass);
  58. if (pDSObj == NULL)
  59. {
  60. return STG_E_MEDIUMFULL;
  61. }
  62. pDSObj->clsidNamespace = CLSID_MicrosoftDS;
  63. pDSObj->cItems = 1;
  64. pDSObj->aObjects[0].offsetName = cbStruct;
  65. pDSObj->aObjects[0].offsetClass = cbStruct + cbPath;
  66. _tcscpy((LPTSTR)((BYTE *)pDSObj + cbStruct), szPath);
  67. _tcscpy((LPTSTR)((BYTE *)pDSObj + cbStruct + cbPath), szClass);
  68. pMedium->hGlobal = (HGLOBAL)pDSObj;
  69. hr = S_OK;
  70. }
  71. else
  72. hr = CDataObject::GetData(pFormatEtc, pMedium);
  73. return S_OK;
  74. }
  75. ///////////////////////////////////////////////////////////////////////////////
  76. //
  77. // CDSObject
  78. //
  79. //
  80. CDSObject::CDSObject(bool bNoRefCountOnContainer) :
  81. m_bstrADsPath(NULL),
  82. m_bstrClass(NULL),
  83. m_bstrName(NULL),
  84. m_bNewCreated(false),
  85. m_bOpened(false),
  86. m_pHandle(NULL),
  87. m_dwState(0),
  88. m_bNoRefCountOnContainer(bNoRefCountOnContainer)
  89. {
  90. m_dwAttributeFlags[ATTR_FLAG_LOAD] = 0;
  91. m_dwAttributeFlags[ATTR_FLAG_SAVE] = 0;
  92. }
  93. CDSObject::~CDSObject()
  94. {
  95. Close();
  96. if(m_bNoRefCountOnContainer)
  97. m_spContainer.p = NULL;
  98. else
  99. m_spContainer.Release();
  100. SysFreeString(m_bstrClass);
  101. m_bstrClass = NULL;
  102. SysFreeString(m_bstrName);
  103. m_bstrName = NULL;
  104. }
  105. //+----------------------------------------------------------------------------
  106. //
  107. // Method: CDSObject::Delete
  108. //
  109. // Synopsis: Delete the object from DS
  110. //
  111. //-----------------------------------------------------------------------------
  112. STDMETHODIMP CDSObject::Delete()
  113. {
  114. HRESULT hr = S_OK;
  115. BSTR strThisRDN = NULL;
  116. BSTR strThisCls = NULL;
  117. CComPtr<IADsContainer> spContainer;
  118. CComPtr<IADs> spContainerIADs;
  119. if(!(CDSObject*)m_spContainer) return S_FALSE;
  120. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  121. CHECK_HR(hr = Reopen());
  122. hr = m_spIADs->QueryInterface(IID_IADsContainer, (void**)&spContainer);
  123. if(hr == S_OK) // it's a container
  124. {
  125. CComPtr<IEnumVARIANT> spEnum;
  126. CComPtr<IADs> spChild;
  127. CComPtr<IDispatch> spDisp;
  128. CComObject<CDSObject>* pDSObj = NULL;
  129. CComPtr<CDSObject> spDSObj;
  130. VARIANT var;
  131. VariantInit(&var);
  132. CHECK_HR(hr = ADsBuildEnumerator(spContainer, &spEnum));
  133. while(S_OK == (hr = ADsEnumerateNext(spEnum, 1, &var, NULL)))
  134. {
  135. spDisp = var.pdispVal;
  136. spChild.Release(); // make sure spChild is NULL
  137. CHECK_HR(hr = spDisp->QueryInterface(IID_IADs, (VOID **)&spChild));
  138. // if this object is a profile object
  139. // create the object
  140. spDSObj.Release(); // make sure it's NULL
  141. CHECK_HR(hr = CComObject<CDSObject>::CreateInstance(&pDSObj)); // with 0 reference count
  142. spDSObj = pDSObj;
  143. CHECK_HR(hr = spDSObj->Attach(this, spChild));
  144. // delete
  145. spDSObj->Delete();
  146. }
  147. spContainer.Release();
  148. }
  149. CHECK_HR(hr = m_spIADs->get_Name (&strThisRDN));
  150. CHECK_HR(hr = m_spIADs->get_Class (&strThisCls));
  151. m_spIADs.Release();
  152. m_spContainer->GetIADs(&spContainerIADs);
  153. CHECK_HR(hr = spContainerIADs->QueryInterface(IID_IADsContainer, (void**)&spContainer));
  154. ASSERT((IADsContainer*)spContainer);
  155. CHECK_HR(hr = spContainer->Delete(strThisCls, strThisRDN));
  156. m_spContainer->RemoveChild(this);
  157. L_ERR:
  158. SysFreeString(strThisRDN);
  159. SysFreeString(strThisCls);
  160. return hr;
  161. }
  162. //+----------------------------------------------------------------------------
  163. //
  164. // Method: CDSObject::Rename
  165. //
  166. // Synopsis: Rename the object within the save container
  167. //
  168. //-----------------------------------------------------------------------------
  169. STDMETHODIMP CDSObject::Rename(LPCWSTR szName)
  170. {
  171. HRESULT hr = S_OK;
  172. DWORD result;
  173. CString AttrName;
  174. CString str;
  175. CComPtr<IDispatch> spDispObj;
  176. CComPtr<IADs> spADs;
  177. CComPtr<IADsContainer> spIContainer;
  178. // if we didn't create it, we don't delete it
  179. if(!(CDSObject*)m_spContainer) return S_FALSE;
  180. AttrName = L"cn=";
  181. AttrName += szName;
  182. TRACE(_T("CDSObject::Rename: Attributed name is %s.\n"), AttrName);
  183. m_spIADs.Release();
  184. // get container's IADs interface
  185. CHECK_HR(hr = m_spContainer->GetIADs(&spADs));
  186. // get containers's IADsContainer interface
  187. CHECK_HR(hr = spADs->QueryInterface(IID_IADsContainer, (void**)&spIContainer));
  188. ASSERT((IADsContainer*)spIContainer);
  189. CHECK_HR(hr = Reopen()); // make sure m_bADsPath is set
  190. str = m_bstrADsPath;
  191. CHECK_HR(hr = Close()); // close it before rename
  192. CHECK_HR(hr = spIContainer->MoveHere((LPWSTR)(LPCWSTR)str, (LPWSTR)(LPCWSTR)AttrName, &spDispObj));
  193. CHECK_HR(hr = spDispObj->QueryInterface (IID_IADs, (void **)&m_spIADs));
  194. ASSERT((IADs*)m_spIADs);
  195. SysFreeString(m_bstrName);
  196. CHECK_HR(hr = m_spIADs->get_Name(&m_bstrName));
  197. m_spIADs.Release();
  198. L_ERR:
  199. return hr;
  200. }
  201. //+----------------------------------------------------------------------------
  202. //
  203. // Method: CDSObject::Save
  204. //
  205. // Synopsis: Save the object to DS
  206. //
  207. //-----------------------------------------------------------------------------
  208. STDMETHODIMP CDSObject::Save(DWORD dwAttrFlags)
  209. {
  210. HRESULT hr;
  211. if((IADs*)m_spIADs)
  212. {
  213. CHECK_HR(hr = OnSave(dwAttrFlags)); // any additional processing before save
  214. CHECK_HR(hr = m_spIADs->SetInfo()); // save other things
  215. CHECK_HR(hr = SaveAttributes(dwAttrFlags)); // save attributes
  216. }
  217. else
  218. hr = S_FALSE;
  219. L_ERR:
  220. return hr;
  221. }
  222. //+----------------------------------------------------------------------------
  223. //
  224. // Method: CDSObject::SetInfo
  225. //
  226. // Synopsis: Set necessary information for Reopen
  227. //
  228. //-----------------------------------------------------------------------------
  229. //??
  230. STDMETHODIMP CDSObject::SetInfo
  231. (
  232. CDSObject* pContainer, // container, when NULL, objName is fullpath
  233. LPCWSTR clsName, // class name
  234. LPCWSTR objName // object name, ignored when container == NULL
  235. )
  236. {
  237. HRESULT hr = S_OK;
  238. if(m_bNoRefCountOnContainer)
  239. m_spContainer.p = pContainer;
  240. else
  241. m_spContainer = pContainer;
  242. try{
  243. SysFreeString(m_bstrClass);
  244. m_bstrClass = NULL;
  245. m_bstrClass = SysAllocString(clsName);
  246. CString cnName = L"cn=";
  247. cnName += objName;
  248. SysFreeString(m_bstrName);
  249. m_bstrName = NULL;
  250. m_bstrName = SysAllocString(cnName);
  251. }catch(CMemoryException&){
  252. CHECK_HR(hr = E_OUTOFMEMORY);
  253. }
  254. L_ERR:
  255. return hr;
  256. }
  257. //+----------------------------------------------------------------------------
  258. //
  259. // Method: CDSObject::Open
  260. //
  261. // Synopsis: Open an object in DS, create one when necessary
  262. //
  263. //-----------------------------------------------------------------------------
  264. //??
  265. STDMETHODIMP CDSObject::Open
  266. (
  267. CDSObject* pContainer, // container, when NULL, objName is fullpath
  268. LPCWSTR clsName, // class name
  269. LPCWSTR objName, // object name, ignored when container == NULL
  270. bool bCreateIfNonExist, // [in, out] if create
  271. bool bPersistWhenCreate
  272. )
  273. {
  274. HRESULT hr = S_OK;
  275. CComPtr<IADs> spIADs;
  276. CComPtr<IDispatch> spIDisp;
  277. CComPtr<IADsContainer> spIContainer;
  278. bool bCallSave = false;
  279. DWORD dwAttrFlags = 0;
  280. if(!pContainer) // if container is not specified
  281. {
  282. CHECK_HR(hr = ADsOpenObject((LPWSTR)objName, NULL, NULL, ADS_SECURE_AUTHENTICATION | ADS_USE_SIGNING | ADS_USE_SEALING, IID_IADs, (void**)&spIADs));
  283. ASSERT((IADs*)spIADs);
  284. }
  285. else // open/create within container
  286. {
  287. // get container's ADSI
  288. CHECK_HR(hr = pContainer->GetIADs(&spIADs));
  289. ASSERT((IADs*)spIADs);
  290. CHECK_HR(spIADs->QueryInterface(IID_IADsContainer, (void**)&spIContainer));
  291. ASSERT((IADsContainer*)spIContainer);
  292. CString cnName = objName;
  293. cnName.TrimLeft();
  294. // if cn= is already in the string
  295. if(cnName.GetLength() < 4 || cnName[2] != _T('=')
  296. || (cnName[0] != _T('c') && cnName[0] != _T('C'))
  297. || (cnName[1] != _T('n') && cnName[1] != _T('N')))
  298. {
  299. cnName = _T("cn=");
  300. cnName += objName;
  301. }
  302. // if it cannot open
  303. hr = spIContainer->GetObject((LPWSTR)clsName, (LPWSTR)(LPCWSTR)cnName, &spIDisp);
  304. spIADs.Release();
  305. if(S_OK == hr)
  306. {
  307. ASSERT((IDispatch*)spIDisp);
  308. spIDisp->QueryInterface(IID_IADs, (void**)&spIADs);
  309. ASSERT((IADs*)spIADs);
  310. }
  311. else // the object cannot be open
  312. {
  313. if(!bCreateIfNonExist) goto L_ERR;
  314. // create one if not exist
  315. CHECK_HR(spIContainer->Create((LPWSTR)clsName,(LPWSTR)(LPCWSTR)cnName, &spIDisp));
  316. ASSERT((IDispatch*)spIDisp);
  317. spIDisp->QueryInterface(IID_IADs, (void**)&spIADs);
  318. ASSERT((IADs*)spIADs);
  319. CHECK_HR(hr = OnCreate(&dwAttrFlags)); // callback function to do something for open
  320. // persist the object
  321. if(bPersistWhenCreate)
  322. bCallSave = true;
  323. m_bNewCreated = true;
  324. }
  325. }
  326. if(m_bNoRefCountOnContainer)
  327. m_spContainer.p = pContainer;
  328. else
  329. m_spContainer = pContainer;
  330. m_spIADs = (IADs*)spIADs;
  331. SysFreeString(m_bstrADsPath);
  332. m_bstrADsPath = NULL;
  333. CHECK_HR(hr = m_spIADs->get_ADsPath(&m_bstrADsPath));
  334. SysFreeString(m_bstrClass);
  335. m_bstrClass = NULL;
  336. CHECK_HR(hr = m_spIADs->get_Class(&m_bstrClass));
  337. SysFreeString(m_bstrName);
  338. m_bstrName = NULL;
  339. CHECK_HR(hr = m_spIADs->get_Name(&m_bstrName));
  340. // if new created and need to save
  341. if(bCallSave)
  342. CHECK_HR(hr = Save(dwAttrFlags));
  343. CHECK_HR(hr = OnOpen()); // callback function to do something for open
  344. CHECK_HR(hr = LoadAttributes()); // loadin attributes
  345. m_bOpened = true;
  346. L_ERR:
  347. return hr;
  348. }
  349. //+----------------------------------------------------------------------------
  350. //
  351. // Method: CDSObject::Reopen
  352. //
  353. // Synopsis: Reopen an object in DS
  354. //
  355. //-----------------------------------------------------------------------------
  356. STDMETHODIMP CDSObject::Reopen()
  357. {
  358. HRESULT hr = S_OK;
  359. CComPtr<IDispatch> spIDisp;
  360. CComPtr<IADs> spIADs;
  361. CComPtr<IADsContainer> spIContainer;
  362. // this must be pre opened, or created
  363. ASSERT((CDSObject*)m_spContainer);
  364. ASSERT(m_bstrName);
  365. ASSERT(m_bstrClass);
  366. // close it, if the object was representing another DS object
  367. Close();
  368. // get container's ADSI
  369. CHECK_HR(hr = m_spContainer->GetIADs(&spIADs));
  370. ASSERT((IADs*)spIADs);
  371. CHECK_HR(spIADs->QueryInterface(IID_IADsContainer, (void**)&spIContainer));
  372. ASSERT((IADsContainer*)spIContainer);
  373. // if it cannot open
  374. CHECK_HR(hr = spIContainer->GetObject((LPWSTR)m_bstrClass, m_bstrName, &spIDisp));
  375. ASSERT((IDispatch*)spIDisp);
  376. if(!(IADs*)m_spIADs)
  377. spIDisp->QueryInterface(IID_IADs, (void**)&m_spIADs);
  378. ASSERT((IADs*)m_spIADs);
  379. CHECK_HR(hr = m_spIADs->get_ADsPath(&m_bstrADsPath));
  380. CHECK_HR(hr = OnOpen()); // callback function to do something for open
  381. CHECK_HR(hr = LoadAttributes()); // loadin attributes
  382. m_bOpened = true;
  383. L_ERR:
  384. return hr;
  385. }
  386. //+----------------------------------------------------------------------------
  387. //
  388. // Method: CDSObject::Attach
  389. //
  390. // Synopsis: Open an object in DS, create one when necessary
  391. //
  392. //-----------------------------------------------------------------------------
  393. STDMETHODIMP CDSObject::Attach
  394. (
  395. CDSObject* pContainer, // container, when NULL, objName is fullpath
  396. IADs* pIObject // adsi interface for this object
  397. )
  398. {
  399. ASSERT(pIObject); // no joke
  400. HRESULT hr = S_OK;
  401. ASSERT(!m_bstrName); // the object should never be opened before
  402. if(m_bNoRefCountOnContainer)
  403. m_spContainer.p = pContainer;
  404. else
  405. m_spContainer = pContainer;
  406. m_spIADs = pIObject;
  407. CHECK_HR(hr = OnOpen()); // callback function to do something for open
  408. CHECK_HR(hr = LoadAttributes()); // loadin attributes
  409. CHECK_HR(hr = m_spIADs->get_ADsPath(&m_bstrADsPath));
  410. CHECK_HR(hr = m_spIADs->get_Class(&m_bstrClass));
  411. CHECK_HR(hr = m_spIADs->get_Name(&m_bstrName));
  412. m_bOpened = true;
  413. L_ERR:
  414. return hr;
  415. }
  416. //+----------------------------------------------------------------------------
  417. //
  418. // Method: CDSObject::Close
  419. //
  420. // Synopsis: Release pointers, free space
  421. //
  422. //-----------------------------------------------------------------------------
  423. STDMETHODIMP CDSObject::Close()
  424. {
  425. m_spIADs.Release();
  426. SysFreeString(m_bstrADsPath);
  427. m_bstrADsPath = NULL;
  428. m_bOpened = false;
  429. return S_OK;
  430. }
  431. //+----------------------------------------------------------------------------
  432. //
  433. // Method: CDSObject::GetString
  434. //
  435. // Synopsis: GetIADs of the object, reference is increased by 1
  436. //
  437. //-----------------------------------------------------------------------------
  438. STDMETHODIMP CDSObject::GetString(CString& str, int nCol)
  439. {
  440. USES_CONVERSION;
  441. switch(nCol)
  442. {
  443. case 0: // name field
  444. str = GetName();
  445. return S_OK;
  446. default:
  447. str = _T(" ");
  448. return S_OK;
  449. }
  450. }
  451. //+----------------------------------------------------------------------------
  452. //
  453. // Method: CDSObject::GetIADs
  454. //
  455. // Synopsis: GetIADs of the object, reference is increased by 1
  456. //
  457. //-----------------------------------------------------------------------------
  458. STDMETHODIMP CDSObject::GetIADs(IADs** ppIADs)
  459. {
  460. HRESULT hr = S_OK;
  461. bool bNeedClose = false;
  462. if(!(IADs*)m_spIADs)
  463. {
  464. CHECK_HR(hr = Reopen());
  465. bNeedClose = true;
  466. ASSERT((IADs*)m_spIADs);
  467. }
  468. *ppIADs = (IADs*)m_spIADs;
  469. if(*ppIADs)
  470. (*ppIADs)->AddRef();
  471. if(bNeedClose)
  472. CHECK_HR(hr = Close());
  473. L_ERR:
  474. return hr;
  475. }
  476. //+----------------------------------------------------------------------------
  477. //
  478. // Method: CDSObject::SaveAttributes
  479. //
  480. // Synopsis: Save attributes to DS according to the flags
  481. //
  482. //-----------------------------------------------------------------------------
  483. STDMETHODIMP CDSObject::SaveAttributes(DWORD dwAttrFlags)
  484. {
  485. CDSAttribute* pAttr = GetAttributes();
  486. if(!pAttr) return S_OK; // when no attribute to save
  487. HRESULT hr = S_OK;
  488. CDSAttributeInfo* pInfo;
  489. CComPtr<IDirectoryObject> spDirObj;
  490. ADS_ATTR_INFO aADsAttrInfos[MAX_ATTRIBUTES];
  491. ADSVALUE aADsValues[MAX_ATTRIBUTES];
  492. ZeroMemory(aADsAttrInfos, sizeof(aADsAttrInfos));
  493. ZeroMemory(aADsValues, sizeof(aADsValues));
  494. DWORD count = 0;
  495. while(pAttr->pInfo)
  496. {
  497. ASSERT(count < MAX_ATTRIBUTES); // make sure it's in the range
  498. if(dwAttrFlags & pAttr->pInfo->flag) // if the attribute should be saved
  499. {
  500. pInfo = pAttr->pInfo;
  501. // clear this attribute -- remove it
  502. if(GetFlags(ATTR_FLAG_SAVE, pInfo->flag) == 0)
  503. {
  504. // when need to delete
  505. if(GetFlags(ATTR_FLAG_LOAD, pInfo->flag) != 0)
  506. {
  507. SetFlags(ATTR_FLAG_LOAD, pInfo->flag, false);
  508. aADsAttrInfos[count].pszAttrName = pInfo->name;
  509. aADsAttrInfos[count].dwADsType = pInfo->type;
  510. aADsAttrInfos[count].dwNumValues = 0;
  511. aADsAttrInfos[count].dwControlCode = ADS_ATTR_CLEAR;
  512. aADsAttrInfos[count].pADsValues = NULL;
  513. count++;
  514. }
  515. // else doesn't exist in DS, need to do nothing
  516. }
  517. else // need to save it
  518. {
  519. SetFlags(ATTR_FLAG_LOAD, pInfo->flag, true);
  520. aADsAttrInfos[count].pszAttrName = pInfo->name;
  521. aADsAttrInfos[count].dwADsType = pInfo->type;
  522. aADsAttrInfos[count].dwNumValues = 1;
  523. aADsAttrInfos[count].dwControlCode = ADS_ATTR_UPDATE;
  524. aADsAttrInfos[count].pADsValues = aADsValues + count;
  525. aADsValues[count].dwType = pInfo->type;
  526. switch(pInfo->type)
  527. {
  528. case ADSTYPE_BOOLEAN:
  529. aADsValues[count].Boolean = *(ADS_BOOLEAN*)pAttr->pBuffer;
  530. break;
  531. case ADSTYPE_INTEGER:
  532. aADsValues[count].Integer = *(ADS_INTEGER*)pAttr->pBuffer;
  533. break;
  534. case ADSTYPE_LARGE_INTEGER:
  535. aADsValues[count].LargeInteger = *(ADS_LARGE_INTEGER*)pAttr->pBuffer;
  536. break;
  537. case ADSTYPE_CASE_IGNORE_STRING:
  538. case ADSTYPE_CASE_EXACT_STRING:
  539. case ADSTYPE_PRINTABLE_STRING:
  540. if(pInfo->ifMultiValued) // expect the buffer to be a StrArray pointer
  541. {
  542. // with current set of attributes, only one is possible
  543. CStrArray* pArray = (CStrArray*)(pAttr->pBuffer);
  544. ASSERT(pArray); // must be some mistake in code, types don't match
  545. ADSVALUE* pValue;
  546. aADsAttrInfos[count].dwNumValues = pArray->GetSize();
  547. ASSERT(aADsAttrInfos[count].dwNumValues);
  548. if(aADsAttrInfos[count].dwNumValues > 1)
  549. {
  550. try{
  551. aADsAttrInfos[count].pADsValues = (ADSVALUE*)_alloca(sizeof(ADSVALUE) * aADsAttrInfos[count].dwNumValues);
  552. }
  553. catch(...)
  554. {
  555. CHECK_HR(hr = E_OUTOFMEMORY);
  556. }
  557. }
  558. pValue = aADsAttrInfos[count].pADsValues;
  559. // when need to support REAL multi-valued attribute, the way how aADsAttrInfos is allocated needs to change
  560. for(int i = 0; i < pArray->GetSize(); i++, pValue++)
  561. {
  562. pValue->CaseIgnoreString = T2W((LPTSTR)(LPCTSTR)*(pArray->GetAt(i)));
  563. pValue->dwType = pInfo->type;
  564. }
  565. }
  566. else // NOT multivalued CString pointer
  567. {
  568. CString* pStr = NULL;
  569. pStr = (CString*)(pAttr->pBuffer);
  570. ASSERT(pStr);
  571. if(pStr && pStr->GetLength())
  572. aADsValues[count].CaseIgnoreString = T2W((LPTSTR)(LPCTSTR)*pStr);
  573. else
  574. aADsValues[count].CaseIgnoreString = NULL;
  575. }
  576. break;
  577. default:
  578. // other types are not supported
  579. // need to make some changes when adding new types
  580. ASSERT(0);
  581. break;
  582. }
  583. count++;
  584. }
  585. }
  586. pAttr++;
  587. };
  588. if (!count) // there is no attribute to load
  589. return hr;
  590. // load the attributes
  591. ASSERT((IADs*)m_spIADs);
  592. CHECK_HR( hr = m_spIADs->QueryInterface(IID_IDirectoryObject, (void**)&spDirObj));
  593. ASSERT((IDirectoryObject*)spDirObj);
  594. CHECK_HR(hr = spDirObj->SetObjectAttributes(aADsAttrInfos, count, &count));
  595. L_ERR:
  596. return hr;
  597. }
  598. HRESULT CDSObject::SetState(DWORD state)
  599. {
  600. if(state == m_dwState)
  601. return S_OK;
  602. m_dwState = state;
  603. if(m_pHandle)
  604. return m_pHandle->ShowState(state);
  605. else
  606. return S_OK;
  607. };
  608. //+----------------------------------------------------------------------------
  609. //
  610. // Method: CDSObject::LoadAttributes
  611. //
  612. // Synopsis: Load attributes from DS and set flags to indicate the presence
  613. //
  614. //-----------------------------------------------------------------------------
  615. STDMETHODIMP CDSObject::LoadAttributes()
  616. {
  617. CDSAttribute* pAttr = GetAttributes();
  618. if(!pAttr) return S_OK; // when no attribute to read
  619. HRESULT hr = S_OK;
  620. CDSAttributeInfo* pInfo;
  621. CComPtr<IDirectoryObject> spDirObj;
  622. LPWSTR aAttriNames[MAX_ATTRIBUTES];
  623. ADS_ATTR_INFO* pADsAttrInfo = NULL;
  624. DWORD count = 0;
  625. while(pAttr->pInfo)
  626. {
  627. pInfo = pAttr->pInfo;
  628. // clear the flag of this attribute
  629. SetFlags(ATTR_FLAG_LOAD, pInfo->flag, false);
  630. ASSERT(count < MAX_ATTRIBUTES); // make sure it's in the range
  631. aAttriNames[count++] = pInfo->name;
  632. pAttr++;
  633. }
  634. if (!count) // there is no attribute to load
  635. return hr;
  636. // load the attributes
  637. ASSERT((IADs*)m_spIADs);
  638. CHECK_HR( hr = m_spIADs->QueryInterface(IID_IDirectoryObject, (void**)&spDirObj));
  639. ASSERT((IDirectoryObject*)spDirObj);
  640. CHECK_HR(hr = spDirObj->GetObjectAttributes(aAttriNames, count, &pADsAttrInfo, &count));
  641. while(count--)
  642. {
  643. pAttr = GetAttributes();
  644. ASSERT(pAttr); // since we got it last time, we should get the same this time
  645. while(pAttr->pInfo)
  646. {
  647. pInfo = pAttr->pInfo;
  648. if(_wcsicmp(pADsAttrInfo[count].pszAttrName, pInfo->name) == 0)
  649. break;
  650. else
  651. pAttr++;
  652. };
  653. ASSERT(pAttr->pInfo); // muse be found
  654. ASSERT(pInfo->type == pADsAttrInfo[count].dwADsType); // type must match
  655. SetFlags(ATTR_FLAG_LOAD, pInfo->flag, true);
  656. switch(pInfo->type)
  657. {
  658. case ADSTYPE_BOOLEAN:
  659. *(ADS_BOOLEAN*)pAttr->pBuffer = pADsAttrInfo[count].pADsValues[0].Boolean;
  660. break;
  661. case ADSTYPE_INTEGER:
  662. *(ADS_INTEGER*)pAttr->pBuffer = pADsAttrInfo[count].pADsValues[0].Integer;
  663. break;
  664. case ADSTYPE_LARGE_INTEGER:
  665. *(ADS_LARGE_INTEGER*)pAttr->pBuffer = pADsAttrInfo[count].pADsValues[0].LargeInteger;
  666. break;
  667. case ADSTYPE_CASE_IGNORE_STRING:
  668. case ADSTYPE_CASE_EXACT_STRING:
  669. case ADSTYPE_PRINTABLE_STRING:
  670. if(!pInfo->ifMultiValued) // CString is used
  671. {
  672. *(CString*)(pAttr->pBuffer) = pADsAttrInfo[count].pADsValues[0].CaseIgnoreString;
  673. }
  674. else // for multi-valued, CStrArray is used
  675. {
  676. CString* pStr = NULL;
  677. CStrArray* pArray = (CStrArray*)(pAttr->pBuffer);
  678. // clear the existing content of the array
  679. pArray->DeleteAll();
  680. for(int i = 0; i< pADsAttrInfo[count].dwNumValues; i++)
  681. {
  682. try{
  683. pStr = new CString(pADsAttrInfo[count].pADsValues[i].CaseIgnoreString);
  684. }
  685. catch(...)
  686. {
  687. CHECK_HR(hr = E_OUTOFMEMORY);
  688. }
  689. pArray->Add(pStr);
  690. }
  691. }
  692. break;
  693. default:
  694. // other types are not supported
  695. // need to make some changes when adding new types
  696. ASSERT(0);
  697. break;
  698. }
  699. }
  700. L_ERR:
  701. FreeADsMem(pADsAttrInfo);
  702. // This is to deal with a bug related to GetAttribute function of ADS , which returns error when no attribute is found
  703. // code to be cleaned, once the bug is fixed, this should be removed
  704. if(hr == 0x80005210)
  705. hr = S_OK;
  706. return hr;
  707. }
  708. ///////////////////////////////////////////////////////////////////////////////
  709. //
  710. // CACSGlobalObject
  711. //
  712. //
  713. //+----------------------------------------------------------------------------
  714. //
  715. // Method: CACSGlobalObject::Open
  716. //
  717. // Synopsis:
  718. //
  719. //-----------------------------------------------------------------------------
  720. STDMETHODIMP CACSGlobalObject::Open()
  721. {
  722. HRESULT hr = S_OK;
  723. CString adsPath;
  724. int i, j;
  725. // try to get the object to see if the object is already there
  726. // profile container pointer
  727. IADs* pIADs = NULL;
  728. VARIANT var;
  729. BSTR bstrConfigPath = NULL;
  730. if(IfOpened())
  731. return S_OK;
  732. m_nOpenErrorId = 0;
  733. VariantInit(&var);
  734. // get ROOTDSE
  735. CHECK_HR(hr = ADsOpenObject(ACS_DSP_ROOTDSE, NULL, NULL, ADS_SECURE_AUTHENTICATION | ADS_USE_SIGNING | ADS_USE_SEALING,IID_IADs, (void**)&pIADs));
  736. ASSERT(pIADs);
  737. // the name of the domain
  738. CHECK_HR(hr = pIADs->Get(ACS_DSA_DEFAULTCONTEXT, &var));
  739. m_strDomainName = V_BSTR(&var);
  740. i = m_strDomainName.Find(_T('='));
  741. if(i != -1) i++;
  742. j = m_strDomainName.Find(_T(','));
  743. m_strDomainName = m_strDomainName.Mid(i, j - i);
  744. VariantClear(&var);
  745. CHECK_HR(hr = pIADs->Get(ACS_DSA_CONFIGCONTEXT, &var));
  746. bstrConfigPath = V_BSTR(&var);
  747. pIADs->Release();
  748. pIADs = NULL;
  749. try{
  750. adsPath = LDAP_LEADING;
  751. adsPath += ACS_RPATH_ACS_INCONFIG;
  752. adsPath += bstrConfigPath;
  753. }catch(CMemoryException&){
  754. hr = E_OUTOFMEMORY;
  755. }
  756. CHECK_HR(hr);
  757. if FAILED(hr = CDSObject::Open(NULL, NULL, T2W((LPTSTR)(LPCTSTR)adsPath), false, false))
  758. // assume because of it doesn't exist
  759. {
  760. adsPath = LDAP_LEADING;
  761. adsPath += ACS_RPATH_ACS_PARENT_INCOFIG;
  762. adsPath += bstrConfigPath;
  763. CComObject<CDSObject>* pParentObj = NULL;
  764. CHECK_HR(hr = CComObject<CDSObject>::CreateInstance(&pParentObj)); // with 0 reference count
  765. // open it's parent -- this must be exist in DS
  766. CHECK_HR(hr = pParentObj->Open(NULL, NULL, T2W((LPTSTR)(LPCTSTR)adsPath), false, false));
  767. // create it within it's parent
  768. hr = CDSObject::Open(pParentObj, ACS_CLS_CONTAINER, ACS_NAME_ACS, true, true);
  769. if(FAILED(hr))
  770. m_nOpenErrorId = IDS_ERR_ROOTNODE;
  771. }
  772. L_ERR:
  773. VariantClear(&var);
  774. return hr;
  775. }
  776. STDMETHODIMP CACSGlobalObject::OnOpen()
  777. {
  778. if (!IfNewCreated())
  779. return S_OK;
  780. HRESULT hr = S_OK;
  781. // create default and unknown policies
  782. CComObject<CACSPolicyElement>* pDSObj = NULL;
  783. CComPtr<CACSPolicyElement> spObj;
  784. // create the object in DS
  785. CHECK_HR(hr = CComObject<CACSPolicyElement>::CreateInstance(&pDSObj)); // ref == 0
  786. spObj = pDSObj; // ref == 1
  787. if((CACSPolicyElement*)spObj)
  788. {
  789. // set default attributes and set the flags to save it
  790. spObj->SetFlags(ATTR_FLAG_SAVE, spObj->SetGlobalDefault(), true);
  791. }
  792. CHECK_HR(hr = spObj->Open(this, ACS_CLS_POLICY, ACSPOLICY_DEFAULT, true, true));
  793. spObj->ClearFlags(ATTR_FLAG_SAVE); // clear the saving flags
  794. CHECK_HR(hr = spObj->Close());
  795. // unknown_User -- make sure it exists
  796. spObj.Release();
  797. // create the object in DS
  798. CHECK_HR(hr = CComObject<CACSPolicyElement>::CreateInstance(&pDSObj)); // ref == 0
  799. spObj = pDSObj; // ref == 1
  800. if((CACSPolicyElement*)spObj)
  801. {
  802. // set attribute and flag for global unknown
  803. spObj->SetFlags(ATTR_FLAG_SAVE, spObj->SetGlobalUnknown(), true);
  804. }
  805. CHECK_HR(hr = spObj->Open(this, ACS_CLS_POLICY, ACSPOLICY_UNKNOWN, true, true));
  806. spObj->ClearFlags(ATTR_FLAG_SAVE); // clear the saving flags
  807. CHECK_HR(hr = spObj->Close());
  808. L_ERR:
  809. return hr;
  810. }
  811. ///////////////////////////////////////////////////////////////////////////////
  812. //
  813. // CACSSubnetsObject
  814. //
  815. //
  816. //+----------------------------------------------------------------------------
  817. //
  818. // Method: CACSSubnetsObject::Open
  819. //
  820. // Synopsis:
  821. //
  822. //-----------------------------------------------------------------------------
  823. STDMETHODIMP CACSSubnetsObject::Open()
  824. {
  825. HRESULT hr = S_OK;
  826. CString adsPath;
  827. int i, j;
  828. // try to get the object to see if the object is already there
  829. // profile container pointer
  830. IADs* pIADs = NULL;
  831. VARIANT var;
  832. BSTR bstrConfigPath = NULL;
  833. if(IfOpened())
  834. return S_OK;
  835. VariantInit(&var);
  836. // get ROOTDSE
  837. CHECK_HR(hr = ADsOpenObject(ACS_DSP_ROOTDSE, NULL, NULL, ADS_SECURE_AUTHENTICATION | ADS_USE_SIGNING | ADS_USE_SEALING, IID_IADs, (void**)&pIADs));
  838. ASSERT(pIADs);
  839. // configuration folder
  840. VariantClear(&var);
  841. CHECK_HR(hr = pIADs->Get(ACS_DSA_CONFIGCONTEXT, &var));
  842. bstrConfigPath = V_BSTR(&var);
  843. pIADs->Release();
  844. pIADs = NULL;
  845. try{
  846. adsPath = LDAP_LEADING;
  847. adsPath += ACS_RPATH_SUBNETS_INCONFIG;
  848. adsPath += bstrConfigPath;
  849. }catch(CMemoryException&){
  850. hr = E_OUTOFMEMORY;
  851. }
  852. CHECK_HR(hr);
  853. hr = CDSObject::Open(NULL, NULL, T2W((LPTSTR)(LPCTSTR)adsPath), false, false);
  854. L_ERR:
  855. VariantClear(&var);
  856. return hr;
  857. }
  858. //============================================
  859. // attribute info of policy element
  860. CDSAttributeInfo CACSPolicyElement::m_aPolicyAttributeInfo[] = {
  861. {ACS_PAI_TIMEOFDAY , ACS_PAN_TIMEOFDAY , ACS_PAT_TIMEOFDAY , ACS_PAM_TIMEOFDAY , ACS_PAF_TIMEOFDAY },
  862. {ACS_PAI_DIRECTION , ACS_PAN_DIRECTION , ACS_PAT_DIRECTION , ACS_PAM_DIRECTION , ACS_PAF_DIRECTION },
  863. {ACS_PAI_PF_TOKENRATE , ACS_PAN_PF_TOKENRATE , ACS_PAT_PF_TOKENRATE , ACS_PAM_PF_TOKENRATE , ACS_PAF_PF_TOKENRATE },
  864. {ACS_PAI_PF_PEAKBANDWIDTH , ACS_PAN_PF_PEAKBANDWIDTH , ACS_PAT_PF_PEAKBANDWIDTH , ACS_PAM_PF_PEAKBANDWIDTH , ACS_PAF_PF_PEAKBANDWIDTH },
  865. {ACS_PAI_PF_DURATION , ACS_PAN_PF_DURATION , ACS_PAT_PF_DURATION , ACS_PAM_PF_DURATION , ACS_PAF_PF_DURATION },
  866. {ACS_PAI_SERVICETYPE , ACS_PAN_SERVICETYPE , ACS_PAT_SERVICETYPE , ACS_PAM_SERVICETYPE , ACS_PAF_SERVICETYPE },
  867. {ACS_PAI_PRIORITY , ACS_PAN_PRIORITY , ACS_PAT_PRIORITY , ACS_PAM_PRIORITY , ACS_PAF_PRIORITY },
  868. {ACS_PAI_PERMISSIONBITS , ACS_PAN_PERMISSIONBITS , ACS_PAT_PERMISSIONBITS , ACS_PAM_PERMISSIONBITS , ACS_PAF_PERMISSIONBITS },
  869. {ACS_PAI_TT_FLOWS , ACS_PAN_TT_FLOWS , ACS_PAT_TT_FLOWS , ACS_PAM_TT_FLOWS , ACS_PAF_TT_FLOWS },
  870. {ACS_PAI_TT_TOKENRATE , ACS_PAN_TT_TOKENRATE , ACS_PAT_TT_TOKENRATE , ACS_PAM_TT_TOKENRATE , ACS_PAF_TT_TOKENRATE },
  871. {ACS_PAI_TT_PEAKBANDWIDTH , ACS_PAN_TT_PEAKBANDWIDTH , ACS_PAT_TT_PEAKBANDWIDTH , ACS_PAM_TT_PEAKBANDWIDTH , ACS_PAF_TT_PEAKBANDWIDTH },
  872. {ACS_PAI_IDENTITYNAME , ACS_PAN_IDENTITYNAME , ACS_PAT_IDENTITYNAME , ACS_PAM_IDENTITYNAME , ACS_PAF_IDENTITYNAME },
  873. {ACS_PAI_INVALID, NULL, ADSTYPE_INVALID, false, 0}
  874. };
  875. //============================================
  876. // attribute info of subnet config object
  877. CDSAttributeInfo CACSSubnetConfig::m_aSubnetAttributeInfo[] = {
  878. {ACS_SCAI_ALLOCABLERSVPBW, ACS_SCAN_ALLOCABLERSVPBW ,ACS_SCAT_ALLOCABLERSVPBW ,ACS_SCAM_ALLOCABLERSVPBW ,ACS_SCAF_ALLOCABLERSVPBW },
  879. {ACS_SCAI_MAXPEAKBW, ACS_SCAN_MAXPEAKBW ,ACS_SCAT_MAXPEAKBW ,ACS_SCAM_MAXPEAKBW ,ACS_SCAF_MAXPEAKBW },
  880. {ACS_SCAI_ENABLERSVPMESSAGELOGGING, ACS_SCAN_ENABLERSVPMESSAGELOGGING ,ACS_SCAT_ENABLERSVPMESSAGELOGGING ,ACS_SCAM_ENABLERSVPMESSAGELOGGING ,ACS_SCAF_ENABLERSVPMESSAGELOGGING },
  881. {ACS_SCAI_EVENTLOGLEVEL, ACS_SCAN_EVENTLOGLEVEL ,ACS_SCAT_EVENTLOGLEVEL ,ACS_SCAM_EVENTLOGLEVEL ,ACS_SCAF_EVENTLOGLEVEL },
  882. {ACS_SCAI_ENABLEACSSERVICE, ACS_SCAN_ENABLEACSSERVICE ,ACS_SCAT_ENABLEACSSERVICE ,ACS_SCAM_ENABLEACSSERVICE ,ACS_SCAF_ENABLEACSSERVICE },
  883. {ACS_SCAI_MAX_PF_TOKENRATE, ACS_SCAN_MAX_PF_TOKENRATE ,ACS_SCAT_MAX_PF_TOKENRATE ,ACS_SCAM_MAX_PF_TOKENRATE ,ACS_SCAF_MAX_PF_TOKENRATE },
  884. {ACS_SCAI_MAX_PF_PEAKBW, ACS_SCAN_MAX_PF_PEAKBW ,ACS_SCAT_MAX_PF_PEAKBW ,ACS_SCAM_MAX_PF_PEAKBW ,ACS_SCAF_MAX_PF_PEAKBW },
  885. {ACS_SCAI_MAX_PF_DURATION, ACS_SCAN_MAX_PF_DURATION ,ACS_SCAT_MAX_PF_DURATION ,ACS_SCAM_MAX_PF_DURATION ,ACS_SCAF_MAX_PF_DURATION },
  886. {ACS_SCAI_RSVPLOGFILESLOCATION, ACS_SCAN_RSVPLOGFILESLOCATION ,ACS_SCAT_RSVPLOGFILESLOCATION ,ACS_SCAM_RSVPLOGFILESLOCATION ,ACS_SCAF_RSVPLOGFILESLOCATION },
  887. {ACS_SCAI_DESCRIPTION, ACS_SCAN_DESCRIPTION ,ACS_SCAT_DESCRIPTION ,ACS_SCAM_DESCRIPTION ,ACS_SCAF_DESCRIPTION },
  888. {ACS_SCAI_MAXNOOFLOGFILES, ACS_SCAN_MAXNOOFLOGFILES ,ACS_SCAT_MAXNOOFLOGFILES ,ACS_SCAM_MAXNOOFLOGFILES ,ACS_SCAF_MAXNOOFLOGFILES },
  889. {ACS_SCAI_MAXSIZEOFRSVPLOGFILE, ACS_SCAN_MAXSIZEOFRSVPLOGFILE ,ACS_SCAT_MAXSIZEOFRSVPLOGFILE ,ACS_SCAM_MAXSIZEOFRSVPLOGFILE ,ACS_SCAF_MAXSIZEOFRSVPLOGFILE },
  890. {ACS_SCAI_DSBMPRIORITY, ACS_SCAN_DSBMPRIORITY ,ACS_SCAT_DSBMPRIORITY ,ACS_SCAM_DSBMPRIORITY ,ACS_SCAF_DSBMPRIORITY },
  891. {ACS_SCAI_DSBMREFRESH, ACS_SCAN_DSBMREFRESH ,ACS_SCAT_DSBMREFRESH ,ACS_SCAM_DSBMREFRESH ,ACS_SCAF_DSBMREFRESH },
  892. {ACS_SCAI_DSBMDEADTIME, ACS_SCAN_DSBMDEADTIME ,ACS_SCAT_DSBMDEADTIME ,ACS_SCAM_DSBMDEADTIME ,ACS_SCAF_DSBMDEADTIME },
  893. {ACS_SCAI_CACHETIMEOUT, ACS_SCAN_CACHETIMEOUT ,ACS_SCAT_CACHETIMEOUT ,ACS_SCAM_CACHETIMEOUT ,ACS_SCAF_CACHETIMEOUT },
  894. {ACS_SCAI_NONRESERVEDTXLIMIT, ACS_SCAN_NONRESERVEDTXLIMIT ,ACS_SCAT_NONRESERVEDTXLIMIT ,ACS_SCAM_NONRESERVEDTXLIMIT ,ACS_SCAF_NONRESERVEDTXLIMIT },
  895. // accounting
  896. {ACS_SCAI_ENABLERSVPMESSAGEACCOUNTING, ACS_SCAN_ENABLERSVPMESSAGEACCOUNTING ,ACS_SCAT_ENABLERSVPMESSAGELOGGING ,ACS_SCAM_ENABLERSVPMESSAGEACCOUNTING ,ACS_SCAF_ENABLERSVPMESSAGEACCOUNTING },
  897. {ACS_SCAI_RSVPACCOUNTINGFILESLOCATION, ACS_SCAN_RSVPACCOUNTINGFILESLOCATION ,ACS_SCAT_RSVPLOGFILESLOCATION ,ACS_SCAM_RSVPACCOUNTINGFILESLOCATION ,ACS_SCAF_RSVPACCOUNTINGFILESLOCATION },
  898. {ACS_SCAI_MAXNOOFACCOUNTINGFILES, ACS_SCAN_MAXNOOFACCOUNTINGFILES ,ACS_SCAT_MAXNOOFLOGFILES ,ACS_SCAM_MAXNOOFACCOUNTINGFILES ,ACS_SCAF_MAXNOOFACCOUNTINGFILES },
  899. {ACS_SCAI_MAXSIZEOFRSVPACCOUNTINGFILE, ACS_SCAN_MAXSIZEOFRSVPACCOUNTINGFILE ,ACS_SCAT_MAXSIZEOFRSVPLOGFILE ,ACS_SCAM_MAXSIZEOFRSVPACCOUNTINGFILE ,ACS_SCAF_MAXSIZEOFRSVPACCOUNTINGFILE },
  900. // server list
  901. {ACS_SCAI_SERVERLIST, ACS_SCAN_SERVERLIST ,ACS_SCAT_SERVERLIST ,ACS_SCAM_SERVERLIST ,ACS_SCAF_SERVERLIST },
  902. {ACS_PAI_INVALID, NULL, ADSTYPE_INVALID, false, 0}
  903. };
  904. //============================================
  905. // attribute info of subnet service limit object
  906. CDSAttributeInfo CACSSubnetServiceLimits::m_aSubnetServiceLimitsAttributeInfo[] = {
  907. {ACS_SSLAI_ALLOCABLERSVPBW, ACS_SSLAN_ALLOCABLERSVPBW ,ACS_SSLAT_ALLOCABLERSVPBW ,ACS_SSLAM_ALLOCABLERSVPBW ,ACS_SSLAF_ALLOCABLERSVPBW },
  908. {ACS_SSLAI_MAXPEAKBW, ACS_SSLAN_MAXPEAKBW ,ACS_SSLAT_MAXPEAKBW ,ACS_SSLAM_MAXPEAKBW ,ACS_SSLAF_MAXPEAKBW },
  909. {ACS_SSLAI_MAX_PF_TOKENRATE,ACS_SSLAN_MAX_PF_TOKENRATE ,ACS_SSLAT_MAX_PF_TOKENRATE ,ACS_SSLAM_MAX_PF_TOKENRATE ,ACS_SSLAF_MAX_PF_TOKENRATE },
  910. {ACS_SSLAI_MAX_PF_PEAKBW, ACS_SSLAN_MAX_PF_PEAKBW ,ACS_SSLAT_MAX_PF_PEAKBW ,ACS_SSLAM_MAX_PF_PEAKBW ,ACS_SSLAF_MAX_PF_PEAKBW },
  911. {ACS_SSLAI_SERVICETYPE, ACS_SSLAN_SERVICETYPE ,ACS_SSLAT_SERVICETYPE ,ACS_SSLAM_SERVICETYPE ,ACS_SSLAF_SERVICETYPE },
  912. {ACS_PAI_INVALID, NULL, ADSTYPE_INVALID, false, 0}
  913. };
  914. bool CACSPolicyElement::IsConflictInContainer()
  915. {
  916. CACSPolicyContainer* pCont = dynamic_cast<CACSPolicyContainer*>((CDSObject*)m_spContainer);
  917. return pCont->IsConflictWithExisting(this);
  918. }
  919. void CACSPolicyElement::InvalidateConflictState()
  920. {
  921. CACSPolicyContainer* pCont = dynamic_cast<CACSPolicyContainer*>((CDSObject*)m_spContainer);
  922. pCont->SetChildrenConflictState();
  923. }
  924. STDMETHODIMP CACSPolicyElement::GetString(CString& str, int nCol)
  925. {
  926. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  927. USES_CONVERSION;
  928. Reopen();
  929. str.Empty();
  930. switch(nCol)
  931. {
  932. case 0: // name field
  933. if(m_bUseName_NewPolicy)
  934. {
  935. str.LoadString(IDS_NEWACSPOLICY);
  936. }
  937. else if(m_strArrayIdentityName.GetSize())
  938. {
  939. int offset;
  940. int id = GetIdentityType(&offset);
  941. switch(id){
  942. case 0:
  943. if(m_strDefaultUser.IsEmpty())
  944. str.LoadString(IDS_ANYAUTHENTICATEDUSER);
  945. break;
  946. case 1:
  947. if(m_strUnknownUser.IsEmpty())
  948. str.LoadString(IDS_NONAUTHENTICATEDUSER);
  949. break;
  950. default:
  951. str = m_strArrayIdentityName[(INT_PTR)0]->Mid(offset);
  952. break;
  953. }
  954. }
  955. break;
  956. case 1: // direction
  957. if(GetFlags(ATTR_FLAG_LOAD, ACS_PAF_DIRECTION))
  958. {
  959. switch(m_dwDirection)
  960. {
  961. case ACS_DIRECTION_SEND:
  962. if(m_strDirectionSend.IsEmpty())
  963. m_strDirectionSend.LoadString(IDS_SEND);
  964. str = m_strDirectionSend;
  965. break;
  966. case ACS_DIRECTION_RECEIVE:
  967. if(m_strDirectionReceive.IsEmpty())
  968. m_strDirectionReceive.LoadString(IDS_RECEIVE);
  969. str = m_strDirectionReceive;
  970. break;
  971. case ACS_DIRECTION_BOTH:
  972. if(m_strDirectionBoth.IsEmpty())
  973. m_strDirectionBoth.LoadString(IDS_SENDRECEIVE);
  974. str = m_strDirectionBoth;
  975. break;
  976. default:
  977. ASSERT(0);
  978. }
  979. }
  980. break;
  981. case 2: // Service Level
  982. if(GetFlags(ATTR_FLAG_LOAD, ACS_PAF_SERVICETYPE))
  983. {
  984. switch(m_dwServiceType)
  985. {
  986. case ACS_SERVICETYPE_BESTEFFORT:
  987. if(m_strServiceTypeBestEffort.IsEmpty())
  988. m_strServiceTypeBestEffort.LoadString(IDS_BESTEFFORT);
  989. str = m_strServiceTypeBestEffort;
  990. break;
  991. case ACS_SERVICETYPE_CONTROLLEDLOAD:
  992. if(m_strServiceTypeControlledLoad.IsEmpty())
  993. m_strServiceTypeControlledLoad.LoadString(IDS_CONTROLLEDLOAD);
  994. str = m_strServiceTypeControlledLoad;
  995. break;
  996. case ACS_SERVICETYPE_GUARANTEEDSERVICE:
  997. if(m_strServiceTypeGuaranteedService.IsEmpty())
  998. m_strServiceTypeGuaranteedService.LoadString(IDS_GUARANTEEDSERVICE);
  999. str = m_strServiceTypeGuaranteedService;
  1000. break;
  1001. case ACS_SERVICETYPE_ALL:
  1002. if(m_strServiceTypeAll.IsEmpty())
  1003. m_strServiceTypeAll.LoadString(IDS_ALL);
  1004. str = m_strServiceTypeAll;
  1005. break;
  1006. case ACS_SERVICETYPE_DISABLED:
  1007. if(m_strServiceTypeDisabled.IsEmpty())
  1008. m_strServiceTypeDisabled.LoadString(IDS_SERVICETYPE_DISABLED);
  1009. str = m_strServiceTypeDisabled;
  1010. break;
  1011. default:
  1012. // invalid value
  1013. ASSERT(0);
  1014. // message box
  1015. }
  1016. }
  1017. break;
  1018. case 3: // date rate
  1019. if(GetFlags(ATTR_FLAG_LOAD, ACS_PAF_PF_TOKENRATE))
  1020. {
  1021. if (IS_LARGE_UNLIMIT(m_ddPFTokenRate))
  1022. {
  1023. str.LoadString(IDS_RESOURCELIMITED);
  1024. }
  1025. else
  1026. {
  1027. str.Format(_T("%d"), TOKBS(m_ddPFTokenRate.LowPart));
  1028. }
  1029. }
  1030. break;
  1031. case 4: // peak rate
  1032. if(GetFlags(ATTR_FLAG_LOAD, ACS_PAF_PF_PEAKBANDWIDTH))
  1033. {
  1034. if (IS_LARGE_UNLIMIT(m_ddPFPeakBandWidth))
  1035. {
  1036. str.LoadString(IDS_RESOURCELIMITED);
  1037. }
  1038. else
  1039. {
  1040. str.Format(_T("%d"), TOKBS(m_ddPFPeakBandWidth.LowPart));
  1041. }
  1042. }
  1043. break;
  1044. default:
  1045. break;
  1046. }
  1047. if(str.IsEmpty())
  1048. str = _T("-");
  1049. return S_OK;
  1050. }
  1051. // string for direction
  1052. CString CACSPolicyElement::m_strDirectionSend;
  1053. CString CACSPolicyElement::m_strDirectionReceive;
  1054. CString CACSPolicyElement::m_strDirectionBoth;
  1055. // string for service type
  1056. CString CACSPolicyElement::m_strServiceTypeAll;
  1057. CString CACSPolicyElement::m_strServiceTypeBestEffort;
  1058. CString CACSPolicyElement::m_strServiceTypeControlledLoad;
  1059. CString CACSPolicyElement::m_strServiceTypeGuaranteedService;
  1060. CString CACSPolicyElement::m_strServiceTypeDisabled;
  1061. // identity display name
  1062. CString CACSPolicyElement::m_strDefaultUser;
  1063. CString CACSPolicyElement::m_strUnknownUser;
  1064. HRESULT CACSSubnetObject::GetString(CString& str, int nCol)
  1065. {
  1066. USES_CONVERSION;
  1067. switch(nCol)
  1068. {
  1069. case 0: // name field
  1070. ASSERT((CDSObject*)m_spContainer);
  1071. str = m_spContainer->GetName();
  1072. break;
  1073. default:
  1074. if(!m_spConfigObject.p) // the ACS object is not created
  1075. {
  1076. Reopen();
  1077. if(!m_spConfigObject.p)
  1078. {
  1079. str = _T("-");
  1080. return S_OK;
  1081. }
  1082. }
  1083. return m_spConfigObject->GetString(str, nCol);
  1084. break;
  1085. }
  1086. return S_OK;
  1087. }
  1088. HRESULT CACSSubnetConfig::GetString(CString& str, int nCol)
  1089. {
  1090. USES_CONVERSION;
  1091. if(!m_bOpened) Reopen();
  1092. str.Empty();
  1093. switch(nCol)
  1094. {
  1095. case 0:
  1096. ASSERT(0); // should not come here, it should be covered by its
  1097. case 1: // name field
  1098. str = m_strDESCRIPTION;
  1099. break;
  1100. case 2: // date rate
  1101. if(GetFlags(ATTR_FLAG_LOAD, ACS_SCAF_MAX_PF_TOKENRATE))
  1102. str.Format(_T("%d"), TOKBS(m_ddMAX_PF_TOKENRATE.LowPart));
  1103. break;
  1104. case 3: // peak rate
  1105. if(GetFlags(ATTR_FLAG_LOAD, ACS_SCAF_MAX_PF_PEAKBW))
  1106. str.Format(_T("%d"), TOKBS(m_ddMAX_PF_PEAKBW.LowPart));
  1107. break;
  1108. default:
  1109. ASSERT(0);
  1110. }
  1111. if(str.IsEmpty())
  1112. str = _T("-");
  1113. return S_OK;
  1114. }
  1115. /////////////////////