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.

381 lines
9.1 KiB

  1. /**********************************************************************/
  2. /** Microsoft Windows/NT **/
  3. /** Copyright(c) Microsoft Corporation, 1997 - 1998 **/
  4. /**********************************************************************/
  5. /*
  6. AcsUser.cpp
  7. Implements the ACS User object extension
  8. FILE HISTORY:
  9. 11/03/97 Wei Jiang Created
  10. */
  11. // ACSUser.cpp : Implementation of CACSUser
  12. #include "stdafx.h"
  13. #include "acs.h"
  14. #include "acsadmin.h"
  15. #include "ACSUser.h"
  16. #include <dsgetdc.h>
  17. #include <mmc.h>
  18. #if 0 // user page is removed
  19. /////////////////////////////////////////////////////////////////////////////
  20. // CACSUser
  21. CACSUser::CACSUser()
  22. {
  23. m_pPage = NULL;
  24. m_pwszObjName = NULL;
  25. m_pwszClass = NULL;
  26. m_ObjMedium.tymed =TYMED_HGLOBAL;
  27. m_ObjMedium.hGlobal = NULL;
  28. m_bShowPage = TRUE;
  29. }
  30. CACSUser::~CACSUser()
  31. {
  32. // stgmedia
  33. delete m_pPage;
  34. ReleaseStgMedium(&m_ObjMedium);
  35. }
  36. //===============================================================================
  37. // IShellExtInit::Initialize
  38. //
  39. // information of the user object is passed in via parameter pDataObject
  40. // further processing will be based on the DN of the user object
  41. STDMETHODIMP CACSUser::Initialize
  42. (
  43. LPCITEMIDLIST pIDFolder,
  44. LPDATAOBJECT pDataObj,
  45. HKEY hRegKey
  46. )
  47. {
  48. TRACE(_T("CACSUser::Initialize()\r\n"));
  49. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  50. ASSERT (pDataObj != NULL);
  51. LPDSOBJECTNAMES pDsObjectNames;
  52. // get the object name out of the pDataObj
  53. UINT cfDsObjectNames = RegisterClipboardFormat(CFSTR_DSOBJECTNAMES);
  54. FORMATETC fmte = {cfDsObjectNames, NULL, DVASPECT_CONTENT, -1, TYMED_HGLOBAL};
  55. // Get the path to the DS object from the data object.
  56. // Note: This call runs on the caller's main thread. The pages' window
  57. // procs run on a different thread, so don't reference the data object
  58. // from a winproc unless it is first marshalled on this thread.
  59. HRESULT hr = pDataObj->GetData(&fmte, &m_ObjMedium);
  60. if (!SUCCEEDED (hr))
  61. {
  62. ASSERT (0);
  63. return hr;
  64. }
  65. pDsObjectNames = (LPDSOBJECTNAMES)m_ObjMedium.hGlobal;
  66. if (pDsObjectNames->cItems < 1)
  67. {
  68. ASSERT (0);
  69. return E_FAIL;
  70. }
  71. m_bShowPage = (pDsObjectNames->aObjects[0].dwProviderFlags & DSPROVIDER_ADVANCED);
  72. // if not to show the page, then nothing need to be done after this
  73. if(!m_bShowPage)
  74. return hr;
  75. // get the name of the object
  76. m_pwszObjName = (LPWSTR)ByteOffset(pDsObjectNames, pDsObjectNames->aObjects[0].offsetName);
  77. // get the class name of the object
  78. m_pwszClass = (LPWSTR)ByteOffset(pDsObjectNames, pDsObjectNames->aObjects[0].offsetClass);
  79. // if the user object is exist, change the user name, and load the property
  80. ASSERT(!m_pPage); // it should have been consumed or new
  81. try{
  82. m_pPage = new CACSUserPg();
  83. }catch(CMemoryException&)
  84. {
  85. delete m_pPage;
  86. m_pPage = NULL;
  87. }
  88. if(!m_pPage)
  89. return E_OUTOFMEMORY;
  90. return m_pPage->Load(m_pwszObjName);
  91. }
  92. //
  93. // FUNCTION: IShellPropSheetExt::AddPages(LPFNADDPROPSHEETPAGE, LPARAM)
  94. //
  95. // PURPOSE: Called by the shell just before the property sheet is displayed.
  96. //
  97. // PARAMETERS:
  98. // lpfnAddPage - Pointer to the Shell's AddPage function
  99. // lParam - Passed as second parameter to lpfnAddPage
  100. //
  101. // RETURN VALUE:
  102. //
  103. // NOERROR in all cases. If for some reason our pages don't get added,
  104. // the Shell still needs to bring up the Properties... sheet.
  105. //
  106. // COMMENTS:
  107. //
  108. STDMETHODIMP CACSUser::AddPages(LPFNADDPROPSHEETPAGE lpfnAddPage, LPARAM lParam)
  109. {
  110. TRACE(_T("CACSUser::AddPages()\r\n"));
  111. // if not to show the page, then nothing need to be done after this
  112. if(!m_bShowPage)
  113. return S_OK;
  114. // param validation
  115. ASSERT (lpfnAddPage);
  116. if (lpfnAddPage == NULL)
  117. return E_UNEXPECTED;
  118. // make sure our state is fixed up (cause we don't know what context we were called in)
  119. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  120. ASSERT(m_pPage); // the page object must have been created in initialize
  121. VERIFY(SUCCEEDED(MMCPropPageCallback(&m_pPage->m_psp)));
  122. HPROPSHEETPAGE hPage = CreatePropertySheetPage(&(m_pPage->m_psp));
  123. ASSERT (hPage);
  124. if (hPage == NULL)
  125. return E_UNEXPECTED;
  126. // add the page
  127. lpfnAddPage (hPage, lParam);
  128. m_pPage = NULL; // since it's just consumed by the dialog, cannot added again
  129. return S_OK;
  130. }
  131. //
  132. // FUNCTION: IShellPropSheetExt::ReplacePage(UINT, LPFNADDPROPSHEETPAGE, LPARAM)
  133. //
  134. // PURPOSE: Called by the shell only for Control Panel property sheet
  135. // extensions
  136. //
  137. // PARAMETERS:
  138. // uPageID - ID of page to be replaced
  139. // lpfnReplaceWith - Pointer to the Shell's Replace function
  140. // lParam - Passed as second parameter to lpfnReplaceWith
  141. //
  142. // RETURN VALUE:
  143. //
  144. // E_FAIL, since we don't support this function. It should never be
  145. // called.
  146. // COMMENTS:
  147. //
  148. STDMETHODIMP CACSUser::ReplacePage
  149. (
  150. UINT uPageID,
  151. LPFNADDPROPSHEETPAGE lpfnReplaceWith,
  152. LPARAM lParam
  153. )
  154. {
  155. TRACE(_T("CACSUser::ReplacePage()\r\n"));
  156. return E_FAIL;
  157. }
  158. /////////////////////////////////////////////////////////////////////////////
  159. // CACSUserPg property page
  160. IMPLEMENT_DYNCREATE(CACSUserPg, CACSPage)
  161. BEGIN_MESSAGE_MAP(CACSUserPg, CACSPage)
  162. //{{AFX_MSG_MAP(CACSUserPg)
  163. ON_CBN_EDITCHANGE(IDC_COMBOUSERPROFILENAME, OnEditchangeCombouserprofilename)
  164. ON_CBN_SELCHANGE(IDC_COMBOUSERPROFILENAME, OnSelchangeCombouserprofilename)
  165. //}}AFX_MSG_MAP
  166. END_MESSAGE_MAP()
  167. CACSUserPg::CACSUserPg() : CACSPage(CACSUserPg::IDD)
  168. {
  169. //{{AFX_DATA_INIT(CACSUserPg)
  170. m_strProfileName = _T("");
  171. //}}AFX_DATA_INIT
  172. m_pBox = NULL;
  173. }
  174. CACSUserPg::~CACSUserPg()
  175. {
  176. delete m_pBox;
  177. }
  178. void CACSUserPg::DoDataExchange(CDataExchange* pDX)
  179. {
  180. CPropertyPage::DoDataExchange(pDX);
  181. //{{AFX_DATA_MAP(CACSUserPg)
  182. DDX_CBString(pDX, IDC_COMBOUSERPROFILENAME, m_strProfileName);
  183. DDV_MaxChars(pDX, m_strProfileName, 128);
  184. //}}AFX_DATA_MAP
  185. }
  186. BOOL CACSUserPg::OnApply()
  187. {
  188. if(!GetModified()) return TRUE;
  189. m_strArrayPolicyNames.DeleteAll();
  190. if(!m_strProfileName.IsEmpty())
  191. {
  192. CString* pStr = NULL;
  193. try
  194. {
  195. pStr = new CString();
  196. *pStr = m_strProfileName;
  197. m_strArrayPolicyNames.Add(pStr);
  198. pStr = NULL;
  199. }
  200. catch(CMemoryException&)
  201. {
  202. delete pStr;
  203. }
  204. }
  205. Save();
  206. // TODO: Add your specialized code here and/or call the base class
  207. return CACSPage::OnApply();
  208. }
  209. HRESULT CACSUserPg::Load(LPCWSTR userPath)
  210. {
  211. HRESULT hr;
  212. // get the DS user attributes for PolicyName
  213. // IADsContainer interface for the user object
  214. if(FAILED(hr = ADsOpenObject((LPWSTR)userPath, NULL, NULL, ADS_SECURE_AUTHENTICATION | ADS_USE_SIGNING | ADS_USE_SEALING, IID_IADs, (void**)&m_spIADs)))
  215. return hr;
  216. ASSERT((IADs*)m_spIADs);
  217. VARIANT var;
  218. VariantInit(&var);
  219. // framed route
  220. m_strArrayPolicyNames.DeleteAll();
  221. if SUCCEEDED(hr = m_spIADs->GetEx(ACS_UAN_POLICYNAME, &var))
  222. {
  223. m_strArrayPolicyNames = (SAFEARRAY*)V_ARRAY(&var);
  224. }
  225. else if (!NOTINCACHE(hr))
  226. goto L_ERR;
  227. VariantClear(&var);
  228. L_SUCC:
  229. hr = S_OK;
  230. goto L_CLEANUP;
  231. L_ERR:
  232. goto L_CLEANUP;
  233. L_CLEANUP:
  234. VariantClear(&var);
  235. return hr;
  236. }
  237. HRESULT CACSUserPg::Save()
  238. {
  239. HRESULT hr;
  240. if(!(IADs*)m_spIADs)
  241. return E_FAIL;
  242. VARIANT var;
  243. VariantInit(&var);
  244. // Policy names
  245. if(m_strArrayPolicyNames.GetSize())
  246. {
  247. V_VT(&var) = VT_VARIANT | VT_ARRAY;
  248. V_ARRAY(&var) = (SAFEARRAY*)m_strArrayPolicyNames;
  249. CHECK_HR(hr = m_spIADs->PutEx(ADS_PROPERTY_UPDATE,ACS_UAN_POLICYNAME, var));
  250. }
  251. else
  252. {
  253. if(S_OK == m_spIADs->GetEx(ACS_UAN_POLICYNAME, &var))
  254. CHECK_HR(hr = m_spIADs->PutEx(ADS_PROPERTY_CLEAR, ACS_UAN_POLICYNAME, var));
  255. }
  256. VariantClear(&var);
  257. CHECK_HR( hr = m_spIADs->SetInfo() );
  258. L_ERR:
  259. // message box to display error message -- FAILED to SAVE
  260. return hr;
  261. }
  262. BOOL CACSUserPg::OnInitDialog()
  263. {
  264. HRESULT hr = S_OK;
  265. CStrArray* pStrArray;
  266. CComObject<CACSGlobalProfiles>* pObj;
  267. int currentIndex = -1;
  268. CHECK_HR( hr = CComObject<CACSGlobalProfiles>::CreateInstance(&pObj));
  269. ASSERT(pObj);
  270. m_spGlobalProfiles = (CACSGlobalProfiles*)pObj;
  271. CHECK_HR( hr = m_spGlobalProfiles->Open());
  272. pStrArray = m_spGlobalProfiles->GetChildrenNameList();
  273. if(pStrArray)
  274. m_GlobalProfileNames = *pStrArray;
  275. // Initialize profile name
  276. if(m_strArrayPolicyNames.GetSize())
  277. m_strProfileName = *(m_strArrayPolicyNames[0]);
  278. if(m_strProfileName.GetLength() && (currentIndex = m_GlobalProfileNames.Find(m_strProfileName)) == -1)
  279. {
  280. try
  281. {
  282. CString* pStr = new CString(m_strProfileName);
  283. currentIndex = m_GlobalProfileNames.Add(pStr);
  284. }
  285. catch(CMemoryException&){} // it's ok even if the string is not added to the array
  286. }
  287. CACSPage::OnInitDialog();
  288. // Initialize combo box list
  289. // fillin the list box
  290. try{
  291. m_pBox = new CStrBox<CComboBox>(this, IDC_COMBOUSERPROFILENAME, m_GlobalProfileNames);
  292. m_pBox->Fill();
  293. if(currentIndex != -1)
  294. m_pBox->Select(currentIndex);
  295. }
  296. catch(CMemoryException&)
  297. {
  298. CHECK_HR(hr = E_OUTOFMEMORY);
  299. };
  300. L_ERR:
  301. return TRUE; // return TRUE unless you set the focus to a control
  302. // EXCEPTION: OCX Property Pages should return FALSE
  303. }
  304. void CACSUserPg::OnEditchangeCombouserprofilename()
  305. {
  306. SetModified(TRUE);
  307. }
  308. void CACSUserPg::OnSelchangeCombouserprofilename()
  309. {
  310. SetModified(TRUE);
  311. }
  312. #endif // #if 0