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.

165 lines
4.5 KiB

  1. #include "pch.h"
  2. #include "common.h"
  3. #include <snapbase.h>
  4. #include "editimpl.h"
  5. HRESULT CAttributeEditor::Initialize(
  6. IADs* pADsObj,
  7. LPDS_ATTREDITOR_BINDINGINFO pBindingInfo,
  8. CADSIEditPropertyPageHolder* pHolder)
  9. {
  10. TRACE(_T("CAttributeEditor::Initialize()\n"));
  11. m_spIADs = pADsObj;
  12. // NTRAID#NTBUG9-562277-2002/03/04-artm There should be release code backing up ASSERT's.
  13. ASSERT(pBindingInfo != NULL);
  14. ASSERT(pBindingInfo->lpfnBind != NULL);
  15. ASSERT(pBindingInfo->lpszProviderServer != NULL);
  16. m_BindingInfo.lParam = pBindingInfo->lParam;
  17. m_BindingInfo.lpfnBind = pBindingInfo->lpfnBind;
  18. m_BindingInfo.dwFlags = pBindingInfo->dwFlags;
  19. // NTRAID#NTBUG9-562468-2002/03/04-artm Can the info in binding struct be trusted?
  20. // In this case, are we guaranteed that lpszProviderServer is null terminated?
  21. int nCount = wcslen(pBindingInfo->lpszProviderServer);
  22. // NTRAID#NTBUG9-562222-2002/03/04-artm Need to check that mem. allocation succeeded.
  23. m_BindingInfo.lpszProviderServer = new WCHAR[nCount + 1];
  24. // NOTICE-2002/03/04-artm wcscpy() fine as long as mem. allocation succeeded
  25. wcscpy(m_BindingInfo.lpszProviderServer, pBindingInfo->lpszProviderServer);
  26. m_BindingInfo.dwSize = sizeof(DS_ATTREDITOR_BINDINGINFO);
  27. m_pHolder = pHolder;
  28. ASSERT(m_pHolder);
  29. //
  30. // Retrieve the class name
  31. //
  32. CComBSTR bstrClass;
  33. HRESULT hr = S_OK;
  34. hr = m_spIADs->get_Class(&bstrClass);
  35. if (SUCCEEDED(hr))
  36. {
  37. m_szClass = bstrClass;
  38. }
  39. return hr;
  40. }
  41. HRESULT CAttributeEditor::CreateModal()
  42. {
  43. TRACE(_T("CAttributeEditor::CreateModal()\n"));
  44. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  45. CThemeContextActivator activator;
  46. //
  47. // Build the abstract schema path
  48. //
  49. CString szSchemaClass(m_BindingInfo.lpszProviderServer);
  50. szSchemaClass = szSchemaClass + _T("schema/") + m_szClass;
  51. //
  52. // Bind to the class object in the abstract schema
  53. //
  54. HRESULT hr = S_OK;
  55. CComPtr<IADsClass> spIADsClass;
  56. if (m_BindingInfo.dwFlags & DSATTR_EDITOR_ROOTDSE)
  57. {
  58. //
  59. // Trying to bind to the schema class of the RootDSE will fail.
  60. // Just pass NULL instead
  61. //
  62. spIADsClass = NULL;
  63. }
  64. else
  65. {
  66. hr = m_BindingInfo.lpfnBind((LPWSTR)(LPCWSTR)szSchemaClass,
  67. ADS_SECURE_AUTHENTICATION,
  68. IID_IADsClass,
  69. (PVOID*)&spIADsClass,
  70. m_BindingInfo.lParam);
  71. }
  72. if (SUCCEEDED(hr))
  73. {
  74. //
  75. // Invoke the editor
  76. //
  77. m_pEditor = new CAttributeEditorPropertyPage(m_spIADs, spIADsClass, &m_BindingInfo, m_pHolder);
  78. if (m_pEditor)
  79. {
  80. CPropertySheet* m_pDummySheet = new CPropertySheet();
  81. if (m_pDummySheet)
  82. {
  83. m_pDummySheet->m_psh.dwFlags |= PSH_NOAPPLYNOW;
  84. CString szCaption;
  85. VERIFY(szCaption.LoadString(IDS_ATTREDITOR_CAPTION));
  86. m_pDummySheet->m_psh.pszCaption = szCaption;
  87. m_pDummySheet->AddPage(m_pEditor);
  88. hr = (m_pDummySheet->DoModal() == IDOK) ? S_OK : S_FALSE;
  89. }
  90. delete m_pEditor;
  91. m_pEditor = NULL;
  92. }
  93. }
  94. return hr;
  95. }
  96. HRESULT CAttributeEditor::GetPage(HPROPSHEETPAGE* phPropSheetPage)
  97. {
  98. TRACE(_T("CAttributeEditor::GetPage()\n"));
  99. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  100. //
  101. // Build the abstract schema path
  102. //
  103. CString szSchemaClass(m_BindingInfo.lpszProviderServer);
  104. szSchemaClass = szSchemaClass + _T("schema/") + m_szClass;
  105. //
  106. // Bind to the class object in the abstract schema
  107. //
  108. HRESULT hr = S_OK;
  109. CComPtr<IADsClass> spIADsClass;
  110. if (m_BindingInfo.dwFlags & DSATTR_EDITOR_ROOTDSE)
  111. {
  112. //
  113. // Trying to bind to the schema class of the RootDSE will fail.
  114. // Just pass NULL instead
  115. //
  116. spIADsClass = NULL;
  117. }
  118. else
  119. {
  120. hr = m_BindingInfo.lpfnBind((LPWSTR)(LPCWSTR)szSchemaClass,
  121. ADS_SECURE_AUTHENTICATION,
  122. IID_IADsClass,
  123. (PVOID*)&spIADsClass,
  124. m_BindingInfo.lParam);
  125. }
  126. if (SUCCEEDED(hr))
  127. {
  128. //
  129. // Invoke the editor
  130. //
  131. m_pEditor = new CAttributeEditorPropertyPage(m_spIADs, spIADsClass, &m_BindingInfo, m_pHolder);
  132. *phPropSheetPage = MyCreatePropertySheetPage(&(m_pEditor->m_psp));
  133. if (*phPropSheetPage == NULL)
  134. {
  135. hr = E_FAIL;
  136. }
  137. }
  138. else
  139. {
  140. ADSIEditErrorMessage(hr);
  141. }
  142. return hr;
  143. }