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.

254 lines
6.3 KiB

  1. //+---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation 1996-2001.
  5. //
  6. // File: addobj.cpp
  7. //
  8. // Contents: implementation of CAddObject
  9. //
  10. //----------------------------------------------------------------------------
  11. #include "stdafx.h"
  12. #include "wsecmgr.h"
  13. #include "attr.h"
  14. #include "resource.h"
  15. #include "snapmgr.h"
  16. #include "util.h"
  17. #include <accctrl.h>
  18. #include "servperm.h"
  19. #include "AddObj.h"
  20. #ifdef _DEBUG
  21. #define new DEBUG_NEW
  22. #undef THIS_FILE
  23. static char THIS_FILE[] = __FILE__;
  24. #endif
  25. /////////////////////////////////////////////////////////////////////////////
  26. // CAddObject dialog
  27. CAddObject::CAddObject(SE_OBJECT_TYPE SeType, LPTSTR ObjName, BOOL bIsContainer, CWnd* pParent)
  28. : CHelpDialog(a197HelpIDs, IDD, pParent)
  29. {
  30. //{{AFX_DATA_INIT(CAddObject)
  31. m_radConfigPrevent = 0;
  32. m_radInheritOverwrite = 0;
  33. //}}AFX_DATA_INIT
  34. m_pfnCreateDsPage=NULL;
  35. m_pSI=NULL;
  36. m_pNewSD=NULL;
  37. m_NewSeInfo = 0;
  38. m_Status=0;
  39. m_SeType=SeType;
  40. m_ObjName=ObjName;
  41. m_bIsContainer = bIsContainer;
  42. m_hwndACL = NULL;
  43. }
  44. void CAddObject::DoDataExchange(CDataExchange* pDX)
  45. {
  46. CDialog::DoDataExchange(pDX);
  47. //{{AFX_DATA_MAP(CAddObject)
  48. DDX_Radio(pDX, IDC_CONFIG, m_radConfigPrevent);
  49. DDX_Radio(pDX, IDC_INHERIT, m_radInheritOverwrite);
  50. //}}AFX_DATA_MAP
  51. }
  52. BEGIN_MESSAGE_MAP(CAddObject, CHelpDialog)
  53. //{{AFX_MSG_MAP(CAddObject)
  54. ON_BN_CLICKED(IDC_SECURITY, OnTemplateSecurity)
  55. ON_BN_CLICKED(IDC_CONFIG, OnConfig)
  56. ON_BN_CLICKED(IDC_PREVENT, OnPrevent)
  57. //}}AFX_MSG_MAP
  58. END_MESSAGE_MAP()
  59. /////////////////////////////////////////////////////////////////////////////
  60. // CAddObject message handlers
  61. void CAddObject::OnTemplateSecurity()
  62. {
  63. INT_PTR nRet = 0;
  64. if( ::IsWindow( m_hwndACL ) )
  65. return;
  66. if ( SE_DS_OBJECT == m_SeType )
  67. {
  68. if ( !m_pfnCreateDsPage )
  69. {
  70. if (!g_hDsSecDll)
  71. g_hDsSecDll = LoadLibrary(TEXT("dssec.dll")); //This is safe usage.
  72. if ( g_hDsSecDll)
  73. {
  74. m_pfnCreateDsPage = (PFNDSCREATEISECINFO)GetProcAddress(g_hDsSecDll,
  75. "DSCreateISecurityInfoObject");
  76. }
  77. }
  78. if ( m_pfnCreateDsPage ) {
  79. m_hwndACL = (HWND)MyCreateDsSecurityPage(&m_pSI, m_pfnCreateDsPage,
  80. &m_pNewSD, &m_NewSeInfo,
  81. (LPCTSTR)m_ObjName,
  82. CONFIG_SECURITY_PAGE,
  83. GetSafeHwnd()
  84. );
  85. } else
  86. nRet = -1;
  87. } else {
  88. m_hwndACL = (HWND)MyCreateSecurityPage2(m_bIsContainer, &m_pNewSD, &m_NewSeInfo,
  89. (LPCTSTR)m_ObjName,
  90. m_SeType,
  91. CONFIG_SECURITY_PAGE,
  92. GetSafeHwnd(),
  93. FALSE // not modeless
  94. );
  95. }
  96. if ( (HWND)-1 == m_hwndACL ) {
  97. CString str;
  98. str.LoadString(IDS_CANT_ASSIGN_SECURITY);
  99. AfxMessageBox(str);
  100. } else if ( !m_pNewSD ) {
  101. //
  102. // if m_pNewSD is still NULL, create a new one for everyone Full control
  103. //
  104. DWORD SDSize;
  105. if (SE_REGISTRY_KEY == m_SeType) {
  106. GetDefaultRegKeySecurity(&m_pNewSD,&m_NewSeInfo);
  107. } else {
  108. GetDefaultFileSecurity(&m_pNewSD,&m_NewSeInfo);
  109. }
  110. }
  111. }
  112. BOOL CAddObject::OnInitDialog()
  113. {
  114. CDialog::OnInitDialog();
  115. SetDlgItemText(IDC_TITLE,m_ObjName);
  116. if (SE_REGISTRY_KEY == m_SeType) {
  117. CString str;
  118. str.LoadString(IDS_REGISTRY_CONFIGURE);
  119. SetDlgItemText(IDC_CONFIG,str);
  120. str.LoadString(IDS_REGISTRY_APPLY);
  121. SetDlgItemText(IDC_OVERWRITE,str);
  122. str.LoadString(IDS_REGISTRY_INHERIT);
  123. SetDlgItemText(IDC_INHERIT,str);
  124. str.LoadString(IDS_REGISTRY_PREVENT);
  125. SetDlgItemText(IDC_PREVENT,str);
  126. }
  127. if (1 == m_radConfigPrevent) {
  128. OnPrevent();
  129. } else {
  130. OnConfig();
  131. }
  132. UpdateData(FALSE);
  133. return TRUE; // return TRUE unless you set the focus to a control
  134. // EXCEPTION: OCX Property Pages should return FALSE
  135. }
  136. void CAddObject::OnOK()
  137. {
  138. UpdateData(TRUE);
  139. if ( !m_pNewSD ) {
  140. CString str;
  141. str.LoadString(IDS_SECURITY_REQUIRED);
  142. AfxMessageBox(str);
  143. return;
  144. }
  145. switch (m_radConfigPrevent) {
  146. case 0:
  147. // config
  148. switch(m_radInheritOverwrite) {
  149. case 0:
  150. // inherit
  151. m_Status = SCE_STATUS_CHECK;
  152. break;
  153. case 1:
  154. // overwrite
  155. m_Status = SCE_STATUS_OVERWRITE;
  156. break;
  157. }
  158. break;
  159. case 1:
  160. // prevent
  161. m_Status = SCE_STATUS_IGNORE;
  162. break;
  163. }
  164. if ( m_pSI ) {
  165. m_pSI->Release();
  166. m_pSI = NULL;
  167. }
  168. m_pfnCreateDsPage=NULL;
  169. CDialog::OnOK();
  170. }
  171. void CAddObject::OnCancel()
  172. {
  173. if ( m_pNewSD ) {
  174. LocalFree(m_pNewSD);
  175. m_pNewSD = NULL;
  176. }
  177. m_NewSeInfo = 0;
  178. if ( m_pSI ) {
  179. m_pSI->Release();
  180. m_pSI = NULL;
  181. }
  182. m_pfnCreateDsPage=NULL;
  183. CDialog::OnCancel();
  184. }
  185. void CAddObject::OnConfig()
  186. {
  187. CWnd *pRadio = GetDlgItem(IDC_INHERIT);
  188. if (pRadio)
  189. pRadio->EnableWindow(TRUE);
  190. pRadio = GetDlgItem(IDC_OVERWRITE);
  191. if (pRadio)
  192. pRadio->EnableWindow(TRUE);
  193. pRadio = GetDlgItem(IDC_SECURITY); //Raid #501901, #501891
  194. if (pRadio) {
  195. pRadio->EnableWindow(TRUE);
  196. }
  197. }
  198. void CAddObject::OnPrevent()
  199. {
  200. CWnd *pRadio = GetDlgItem(IDC_INHERIT);
  201. if (pRadio) {
  202. pRadio->EnableWindow(FALSE);
  203. }
  204. pRadio = GetDlgItem(IDC_OVERWRITE);
  205. if (pRadio) {
  206. pRadio->EnableWindow(FALSE);
  207. }
  208. pRadio = GetDlgItem(IDC_SECURITY); //Raid #501901, #501891
  209. if (pRadio) {
  210. pRadio->EnableWindow(FALSE);
  211. }
  212. }