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.

412 lines
10 KiB

  1. //+-------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. //
  5. // Copyright (C) Microsoft Corporation, 1998 - 1999
  6. //
  7. // File: aclpag_.cpp
  8. //
  9. //--------------------------------------------------------------------------
  10. #include <aclpage.h>
  11. #include <dssec.h>
  12. ///////////////////////////////////////////////////////////////////////
  13. // CDynamicLibraryBase
  14. class CDynamicLibraryBase
  15. {
  16. public:
  17. CDynamicLibraryBase()
  18. {
  19. m_lpszLibraryName = NULL;
  20. m_lpszFunctionName = NULL;
  21. m_lpszFunctionNameEx = NULL;
  22. m_hLibrary = NULL;
  23. m_pfFunction = NULL;
  24. m_pfFunctionEx = NULL;
  25. }
  26. virtual ~CDynamicLibraryBase()
  27. {
  28. if (m_hLibrary != NULL)
  29. {
  30. ::FreeLibrary(m_hLibrary);
  31. m_hLibrary = NULL;
  32. }
  33. }
  34. BOOL Load()
  35. {
  36. if (m_hLibrary != NULL)
  37. return TRUE; // already loaded
  38. ASSERT(m_lpszLibraryName != NULL);
  39. m_hLibrary = ::LoadLibrary(m_lpszLibraryName);
  40. if (NULL == m_hLibrary)
  41. {
  42. // The library is not present
  43. return FALSE;
  44. }
  45. ASSERT(m_lpszFunctionName != NULL);
  46. ASSERT(m_pfFunction == NULL);
  47. m_pfFunction = ::GetProcAddress(m_hLibrary, m_lpszFunctionName );
  48. if ( NULL == m_pfFunction )
  49. {
  50. // The library is present but does not have the entry point
  51. ::FreeLibrary( m_hLibrary );
  52. m_hLibrary = NULL;
  53. return FALSE;
  54. }
  55. if (m_lpszFunctionNameEx != NULL)
  56. {
  57. ASSERT(m_pfFunctionEx == NULL);
  58. m_pfFunctionEx = ::GetProcAddress(m_hLibrary, m_lpszFunctionNameEx);
  59. if ( NULL == m_pfFunctionEx)
  60. {
  61. ::FreeLibrary( m_hLibrary );
  62. m_hLibrary = NULL;
  63. return FALSE;
  64. }
  65. }
  66. ASSERT(m_hLibrary != NULL);
  67. ASSERT(m_pfFunction != NULL);
  68. return TRUE;
  69. }
  70. protected:
  71. LPCSTR m_lpszFunctionName;
  72. LPCSTR m_lpszFunctionNameEx;
  73. LPCTSTR m_lpszLibraryName;
  74. FARPROC m_pfFunction;
  75. FARPROC m_pfFunctionEx;
  76. HMODULE m_hLibrary;
  77. };
  78. ///////////////////////////////////////////////////////////////////////
  79. // CDsSecDLL
  80. class CDsSecDLL : public CDynamicLibraryBase
  81. {
  82. public:
  83. CDsSecDLL()
  84. {
  85. m_lpszLibraryName = _T("dssec.dll");
  86. m_lpszFunctionName = "DSCreateISecurityInfoObject";
  87. m_lpszFunctionNameEx = "DSCreateISecurityInfoObjectEx";
  88. }
  89. HRESULT DSCreateISecurityInfoObject(LPCWSTR pwszObjectPath, // in
  90. LPCWSTR pwszObjectClass, // in
  91. LPSECURITYINFO* ppISecurityInfo // out
  92. );
  93. HRESULT DSCreateISecurityInfoObjectEx(LPCWSTR pwszObjectPath, // in
  94. LPCWSTR pwszObjectClass, // in
  95. LPCWSTR pwszServer, // in
  96. LPCWSTR pwszUsername, // in
  97. LPCWSTR pwszPassword, // in
  98. DWORD dwFlags,
  99. LPSECURITYINFO* ppISecurityInfo // out
  100. );
  101. };
  102. HRESULT CDsSecDLL::DSCreateISecurityInfoObject(LPCWSTR pwszObjectPath, // in
  103. LPCWSTR pwszObjectClass, // in
  104. LPSECURITYINFO* ppISecurityInfo // out
  105. )
  106. {
  107. ASSERT(m_hLibrary != NULL);
  108. ASSERT(m_pfFunction != NULL);
  109. return ((PFNDSCREATEISECINFO)m_pfFunction)
  110. (pwszObjectPath,pwszObjectClass, 0, ppISecurityInfo, NULL, NULL, 0);
  111. }
  112. HRESULT CDsSecDLL::DSCreateISecurityInfoObjectEx(LPCWSTR pwszObjectPath, // in
  113. LPCWSTR pwszObjectClass, // in
  114. LPCWSTR pwszServer, // in
  115. LPCWSTR pwszUsername, // in
  116. LPCWSTR pwszPassword, // in
  117. DWORD dwFlags,
  118. LPSECURITYINFO* ppISecurityInfo // out
  119. )
  120. {
  121. ASSERT(m_hLibrary != NULL);
  122. ASSERT(m_pfFunctionEx != NULL);
  123. return ((PFNDSCREATEISECINFOEX)m_pfFunctionEx)
  124. (pwszObjectPath,pwszObjectClass, pwszServer,
  125. pwszUsername, pwszPassword, dwFlags, ppISecurityInfo, NULL, NULL, 0);
  126. }
  127. ///////////////////////////////////////////////////////////////////////
  128. // CAclUiDLL
  129. class CAclUiDLL : public CDynamicLibraryBase
  130. {
  131. public:
  132. CAclUiDLL()
  133. {
  134. m_lpszLibraryName = _T("aclui.dll");
  135. m_lpszFunctionName = "CreateSecurityPage";
  136. m_pfFunction = NULL;
  137. m_lpszFunctionNameEx = NULL;
  138. m_pfFunctionEx = NULL;
  139. }
  140. HPROPSHEETPAGE CreateSecurityPage( LPSECURITYINFO psi );
  141. };
  142. typedef HPROPSHEETPAGE (*ACLUICREATESECURITYPAGEPROC) (LPSECURITYINFO);
  143. HPROPSHEETPAGE CAclUiDLL::CreateSecurityPage( LPSECURITYINFO psi )
  144. {
  145. ASSERT(m_hLibrary != NULL);
  146. ASSERT(m_pfFunction != NULL);
  147. return ((ACLUICREATESECURITYPAGEPROC)m_pfFunction) (psi);
  148. }
  149. //////////////////////////////////////////////////////////////////////////
  150. // CISecurityInformationWrapper
  151. class CISecurityInformationWrapper : public ISecurityInformation
  152. {
  153. public:
  154. CISecurityInformationWrapper(CAclEditorPage* pAclEditorPage)
  155. {
  156. m_dwRefCount = 0;
  157. ASSERT(pAclEditorPage != NULL);
  158. m_pAclEditorPage = pAclEditorPage;
  159. m_pISecInfo = NULL;
  160. }
  161. ~CISecurityInformationWrapper()
  162. {
  163. ASSERT(m_dwRefCount == 0);
  164. ISecurityInformation* pSecInfo = GetSecInfoPtr();
  165. if (pSecInfo != NULL)
  166. pSecInfo->Release();
  167. }
  168. void SetSecInfoPtr(ISecurityInformation* pSecInfo)
  169. {
  170. ASSERT(pSecInfo != NULL);
  171. m_pISecInfo = pSecInfo;
  172. }
  173. ISecurityInformation* GetSecInfoPtr()
  174. {
  175. return m_pISecInfo;
  176. }
  177. public:
  178. // *** IUnknown methods ***
  179. STDMETHOD(QueryInterface) (REFIID riid, LPVOID * ppvObj)
  180. {
  181. return GetSecInfoPtr()->QueryInterface(riid, ppvObj);
  182. }
  183. STDMETHOD_(ULONG,AddRef) ()
  184. {
  185. // trap the first addref to increment count on page holder
  186. if (m_dwRefCount == 0)
  187. {
  188. m_pAclEditorPage->m_pPageHolder->AddRef();
  189. }
  190. m_dwRefCount++;
  191. return GetSecInfoPtr()->AddRef();
  192. }
  193. STDMETHOD_(ULONG,Release) ()
  194. {
  195. m_dwRefCount--;
  196. // this might be the last release on the page holder
  197. // which would cause the holder to delete itself and
  198. // "this" in the process (i.e. "this" no more valid when
  199. // returning from the m_pPageHolder->Release() call
  200. ISecurityInformation* pISecInfo = GetSecInfoPtr();
  201. // trap the last release to decrement count on page holder
  202. if (m_dwRefCount == 0)
  203. {
  204. m_pAclEditorPage->m_pPageHolder->Release();
  205. }
  206. return pISecInfo->Release();
  207. }
  208. // *** ISecurityInformation methods ***
  209. STDMETHOD(GetObjectInformation) (PSI_OBJECT_INFO pObjectInfo )
  210. {
  211. return GetSecInfoPtr()->GetObjectInformation(pObjectInfo);
  212. }
  213. STDMETHOD(GetSecurity) (SECURITY_INFORMATION RequestedInformation,
  214. PSECURITY_DESCRIPTOR *ppSecurityDescriptor,
  215. BOOL fDefault)
  216. {
  217. return GetSecInfoPtr()->GetSecurity(RequestedInformation,
  218. ppSecurityDescriptor,
  219. fDefault);
  220. }
  221. STDMETHOD(SetSecurity) (SECURITY_INFORMATION SecurityInformation,
  222. PSECURITY_DESCRIPTOR pSecurityDescriptor )
  223. {
  224. return GetSecInfoPtr()->SetSecurity(SecurityInformation,
  225. pSecurityDescriptor);
  226. }
  227. STDMETHOD(GetAccessRights) (const GUID* pguidObjectType,
  228. DWORD dwFlags, // SI_EDIT_AUDITS, SI_EDIT_PROPERTIES
  229. PSI_ACCESS *ppAccess,
  230. ULONG *pcAccesses,
  231. ULONG *piDefaultAccess )
  232. {
  233. return GetSecInfoPtr()->GetAccessRights(pguidObjectType,
  234. dwFlags,
  235. ppAccess,
  236. pcAccesses,
  237. piDefaultAccess);
  238. }
  239. STDMETHOD(MapGeneric) (const GUID *pguidObjectType,
  240. UCHAR *pAceFlags,
  241. ACCESS_MASK *pMask)
  242. {
  243. return GetSecInfoPtr()->MapGeneric(pguidObjectType,
  244. pAceFlags,
  245. pMask);
  246. }
  247. STDMETHOD(GetInheritTypes) (PSI_INHERIT_TYPE *ppInheritTypes,
  248. ULONG *pcInheritTypes )
  249. {
  250. return GetSecInfoPtr()->GetInheritTypes(ppInheritTypes,
  251. pcInheritTypes);
  252. }
  253. STDMETHOD(PropertySheetPageCallback)(HWND hwnd, UINT uMsg, SI_PAGE_TYPE uPage )
  254. {
  255. return GetSecInfoPtr()->PropertySheetPageCallback(hwnd, uMsg, uPage);
  256. }
  257. private:
  258. DWORD m_dwRefCount;
  259. ISecurityInformation* m_pISecInfo; // interface pointer to the wrapped interface
  260. CAclEditorPage* m_pAclEditorPage; // back pointer
  261. //friend class CAclEditorPage;
  262. };
  263. //////////////////////////////////////////////////////////////////////////
  264. // static instances of the dynamically loaded DLL's
  265. CDsSecDLL g_DsSecDLL;
  266. CAclUiDLL g_AclUiDLL;
  267. //////////////////////////////////////////////////////////////////////////
  268. // CAclEditorPage
  269. CAclEditorPage* CAclEditorPage::CreateInstance(LPCTSTR lpszLDAPPath,
  270. CPropertyPageHolderBase* pPageHolder)
  271. {
  272. CAclEditorPage* pAclEditorPage = new CAclEditorPage;
  273. if (pAclEditorPage != NULL)
  274. {
  275. pAclEditorPage->SetHolder(pPageHolder);
  276. if (FAILED(pAclEditorPage->Initialize(lpszLDAPPath)))
  277. {
  278. delete pAclEditorPage;
  279. pAclEditorPage = NULL;
  280. }
  281. }
  282. return pAclEditorPage;
  283. }
  284. CAclEditorPage* CAclEditorPage::CreateInstanceEx(LPCTSTR lpszLDAPPath,
  285. LPCTSTR lpszServer,
  286. LPCTSTR lpszUsername,
  287. LPCTSTR lpszPassword,
  288. DWORD dwFlags,
  289. CPropertyPageHolderBase* pPageHolder)
  290. {
  291. CAclEditorPage* pAclEditorPage = new CAclEditorPage;
  292. if (pAclEditorPage != NULL)
  293. {
  294. pAclEditorPage->SetHolder(pPageHolder);
  295. if (FAILED(pAclEditorPage->InitializeEx(lpszLDAPPath,
  296. lpszServer,
  297. lpszUsername,
  298. lpszPassword,
  299. dwFlags)))
  300. {
  301. delete pAclEditorPage;
  302. pAclEditorPage = NULL;
  303. }
  304. }
  305. return pAclEditorPage;
  306. }
  307. CAclEditorPage::CAclEditorPage()
  308. {
  309. m_pPageHolder = NULL;
  310. m_pISecInfoWrap = new CISecurityInformationWrapper(this);
  311. }
  312. CAclEditorPage::~CAclEditorPage()
  313. {
  314. delete m_pISecInfoWrap;
  315. }
  316. HRESULT CAclEditorPage::Initialize(LPCTSTR lpszLDAPPath)
  317. {
  318. // get ISecurityInfo* from DSSECL.DLL
  319. if (!g_DsSecDLL.Load())
  320. return E_INVALIDARG;
  321. ISecurityInformation* pSecInfo = NULL;
  322. HRESULT hr = g_DsSecDLL.DSCreateISecurityInfoObject(
  323. lpszLDAPPath,
  324. NULL, // pwszObjectClass
  325. &pSecInfo);
  326. if (SUCCEEDED(hr))
  327. m_pISecInfoWrap->SetSecInfoPtr(pSecInfo);
  328. return hr;
  329. }
  330. HRESULT CAclEditorPage::InitializeEx(LPCTSTR lpszLDAPPath,
  331. LPCTSTR lpszServer,
  332. LPCTSTR lpszUsername,
  333. LPCTSTR lpszPassword,
  334. DWORD dwFlags)
  335. {
  336. // get ISecurityInfo* from DSSECL.DLL
  337. if (!g_DsSecDLL.Load())
  338. return E_INVALIDARG;
  339. ISecurityInformation* pSecInfo = NULL;
  340. HRESULT hr = g_DsSecDLL.DSCreateISecurityInfoObjectEx(
  341. lpszLDAPPath,
  342. NULL, // pwszObjectClass
  343. lpszServer,
  344. lpszUsername,
  345. lpszPassword,
  346. dwFlags,
  347. &pSecInfo);
  348. if (SUCCEEDED(hr))
  349. m_pISecInfoWrap->SetSecInfoPtr(pSecInfo);
  350. return hr;
  351. }
  352. HPROPSHEETPAGE CAclEditorPage::CreatePage()
  353. {
  354. if (!g_AclUiDLL.Load())
  355. return NULL;
  356. // call into ACLUI.DLL to create the page
  357. // passing the wrapper interface
  358. return g_AclUiDLL.CreateSecurityPage(m_pISecInfoWrap);
  359. }