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.

531 lines
12 KiB

  1. /*++
  2. Copyright (c) 1994-2001 Microsoft Corporation
  3. Module Name :
  4. wfile.cpp
  5. Abstract:
  6. WWW File Properties Page
  7. Author:
  8. Sergei Antonov (sergeia)
  9. Project:
  10. Internet Services Manager
  11. Revision History:
  12. 27/02/2001 sergeia Created from wvdir.cpp
  13. --*/
  14. //
  15. // Include Files
  16. //
  17. #include "stdafx.h"
  18. #include "resource.h"
  19. #include "common.h"
  20. #include "inetprop.h"
  21. #include "InetMgrApp.h"
  22. #include "supdlgs.h"
  23. #include "shts.h"
  24. #include "w3sht.h"
  25. #include "wfile.h"
  26. #include "dirbrows.h"
  27. #include "iisobj.h"
  28. #include <lmcons.h>
  29. #ifdef _DEBUG
  30. #define new DEBUG_NEW
  31. #undef THIS_FILE
  32. static char THIS_FILE[] = __FILE__;
  33. #endif
  34. LPCTSTR CvtPathToDosStyle(CString & strPath);
  35. IMPLEMENT_DYNCREATE(CW3FilePage, CInetPropertyPage)
  36. CW3FilePage::CW3FilePage(CInetPropertySheet * pSheet)
  37. : CInetPropertyPage(CW3FilePage::IDD, pSheet, IDS_TAB_FILE),
  38. //
  39. // Assign the range of bits in m_dwAccessPermissions that
  40. // we manage. This is important, because another page
  41. // manages other bits, and we don't want to screw up
  42. // the master value bits when our changes collide (it
  43. // will mark the original bits as dirty, because we're not
  44. // notified when the change is made...
  45. //
  46. m_dwBitRangePermissions(MD_ACCESS_EXECUTE |
  47. MD_ACCESS_SCRIPT |
  48. MD_ACCESS_WRITE |
  49. MD_ACCESS_SOURCE |
  50. MD_ACCESS_READ)
  51. {
  52. VERIFY(m_strPrompt[RADIO_DIRECTORY].LoadString(IDS_PROMPT_DIR));
  53. VERIFY(m_strPrompt[RADIO_REDIRECT].LoadString(IDS_PROMPT_REDIRECT));
  54. }
  55. CW3FilePage::~CW3FilePage()
  56. {
  57. }
  58. void
  59. CW3FilePage::DoDataExchange(CDataExchange * pDX)
  60. {
  61. CInetPropertyPage::DoDataExchange(pDX);
  62. //{{AFX_DATA_MAP(CW3FilePage)
  63. // DDX_Radio(pDX, IDC_RADIO_DIR, m_nPathType);
  64. DDX_Control(pDX, IDC_RADIO_DIR, m_radio_Dir);
  65. DDX_Control(pDX, IDC_RADIO_REDIRECT, m_radio_Redirect);
  66. DDX_Check(pDX, IDC_CHECK_AUTHOR, m_fAuthor);
  67. DDX_Control(pDX, IDC_CHECK_AUTHOR, m_check_Author);
  68. DDX_Check(pDX, IDC_CHECK_READ, m_fRead);
  69. DDX_Control(pDX, IDC_CHECK_READ, m_check_Read);
  70. DDX_Check(pDX, IDC_CHECK_WRITE, m_fWrite);
  71. DDX_Control(pDX, IDC_CHECK_WRITE, m_check_Write);
  72. DDX_Check(pDX, IDC_CHECK_LOG_ACCESS, m_fLogAccess);
  73. DDX_Control(pDX, IDC_EDIT_PATH, m_edit_Path);
  74. DDX_Control(pDX, IDC_EDIT_REDIRECT, m_edit_Redirect);
  75. DDX_Control(pDX, IDC_STATIC_PATH_PROMPT, m_static_PathPrompt);
  76. // DDX_Control(pDX, IDC_CHECK_CHILD, m_check_Child);
  77. //}}AFX_DATA_MAP
  78. // DDX_Check(pDX, IDC_CHECK_CHILD, m_fChild);
  79. DDX_Check(pDX, IDC_CHECK_EXACT, m_fExact);
  80. DDX_Check(pDX, IDC_CHECK_PERMANENT, m_fPermanent);
  81. if (pDX->m_bSaveAndValidate)
  82. {
  83. if (m_nPathType == RADIO_REDIRECT)
  84. {
  85. DDX_Text(pDX, IDC_EDIT_REDIRECT, m_strRedirectPath);
  86. DDV_Url(pDX, m_strRedirectPath);
  87. // We could have only absolute URLs here
  88. // Nope, we allow relative URL's...
  89. if (IsRelURLPath(m_strRedirectPath))
  90. {
  91. }
  92. else
  93. {
  94. if (!PathIsURL(m_strRedirectPath) || m_strRedirectPath.GetLength() <= lstrlen(_T("http://")))
  95. {
  96. DDV_ShowBalloonAndFail(pDX, IDS_BAD_URL_PATH);
  97. }
  98. }
  99. if (m_strRedirectPath.Find(_T(",")) > 0)
  100. {
  101. DDV_ShowBalloonAndFail(pDX, IDS_ERR_COMMA_IN_REDIRECT);
  102. }
  103. }
  104. else // Local directory
  105. {
  106. m_strRedirectPath.Empty();
  107. }
  108. }
  109. else
  110. {
  111. DDX_Text(pDX, IDC_EDIT_REDIRECT, m_strRedirectPath);
  112. }
  113. }
  114. //
  115. // Message Map
  116. //
  117. BEGIN_MESSAGE_MAP(CW3FilePage, CInetPropertyPage)
  118. //{{AFX_MSG_MAP(CW3FilePage)
  119. ON_BN_CLICKED(IDC_CHECK_READ, OnCheckRead)
  120. ON_BN_CLICKED(IDC_CHECK_WRITE, OnCheckWrite)
  121. ON_BN_CLICKED(IDC_CHECK_AUTHOR, OnCheckAuthor)
  122. ON_BN_CLICKED(IDC_RADIO_DIR, OnRadioDir)
  123. ON_BN_CLICKED(IDC_RADIO_REDIRECT, OnRadioRedirect)
  124. //}}AFX_MSG_MAP
  125. ON_EN_CHANGE(IDC_EDIT_REDIRECT, OnItemChanged)
  126. ON_BN_CLICKED(IDC_CHECK_LOG_ACCESS, OnItemChanged)
  127. // ON_BN_CLICKED(IDC_CHECK_CHILD, OnItemChanged)
  128. ON_BN_CLICKED(IDC_CHECK_EXACT, OnItemChanged)
  129. ON_BN_CLICKED(IDC_CHECK_PERMANENT, OnItemChanged)
  130. END_MESSAGE_MAP()
  131. void
  132. CW3FilePage::ChangeTypeTo(int nNewType)
  133. {
  134. int nOldType = m_nPathType;
  135. m_nPathType = nNewType;
  136. if (nOldType == m_nPathType)
  137. {
  138. return;
  139. }
  140. OnItemChanged();
  141. SetStateByType();
  142. int nID = -1;
  143. CEdit * pPath = NULL;
  144. LPCTSTR lpKeepPath = NULL;
  145. switch(m_nPathType)
  146. {
  147. case RADIO_DIRECTORY:
  148. break;
  149. case RADIO_REDIRECT:
  150. if (!m_strRedirectPath.IsEmpty())
  151. {
  152. //
  153. // The old path info is acceptable, propose it
  154. // as a default
  155. //
  156. lpKeepPath = m_strRedirectPath;
  157. }
  158. nID = IDS_REDIRECT_MASK;
  159. pPath = &m_edit_Redirect;
  160. break;
  161. default:
  162. ASSERT(FALSE);
  163. return;
  164. }
  165. //
  166. // Load mask resource, and display
  167. // this in the directory
  168. //
  169. if (pPath != NULL)
  170. {
  171. if (lpKeepPath != NULL)
  172. {
  173. pPath->SetWindowText(lpKeepPath);
  174. }
  175. else
  176. {
  177. CString str;
  178. VERIFY(str.LoadString(nID));
  179. pPath->SetWindowText(str);
  180. }
  181. pPath->SetSel(0,-1);
  182. pPath->SetFocus();
  183. }
  184. SetAuthoringState(FALSE);
  185. }
  186. void
  187. CW3FilePage::ShowControl(CWnd * pWnd, BOOL fShow)
  188. {
  189. ASSERT(pWnd != NULL);
  190. pWnd->EnableWindow(fShow);
  191. pWnd->ShowWindow(fShow ? SW_SHOW : SW_HIDE);
  192. }
  193. void
  194. CW3FilePage::SetStateByType()
  195. /*++
  196. Routine Description:
  197. Set the state of the dialog by the path type currently selected
  198. Arguments:
  199. None
  200. Return Value:
  201. None
  202. --*/
  203. {
  204. BOOL fShowDirFlags;
  205. BOOL fShowRedirectFlags;
  206. BOOL fShowScript;
  207. switch(m_nPathType)
  208. {
  209. case RADIO_DIRECTORY:
  210. ShowControl(&m_edit_Path, fShowDirFlags = TRUE);
  211. m_edit_Path.EnableWindow(FALSE);
  212. ShowControl(&m_edit_Redirect, fShowRedirectFlags = FALSE);
  213. fShowScript = TRUE;
  214. break;
  215. case RADIO_REDIRECT:
  216. ShowControl(&m_edit_Path, fShowDirFlags = FALSE);
  217. ShowControl(&m_edit_Redirect, fShowRedirectFlags = TRUE);
  218. fShowScript = FALSE;
  219. break;
  220. default:
  221. ASSERT(FALSE && "Invalid Selection");
  222. return;
  223. }
  224. ShowControl(GetDlgItem(IDC_CHECK_READ), fShowDirFlags);
  225. ShowControl(GetDlgItem(IDC_CHECK_WRITE), fShowDirFlags);
  226. ShowControl(GetDlgItem(IDC_CHECK_LOG_ACCESS), fShowDirFlags);
  227. ShowControl(GetDlgItem(IDC_CHECK_AUTHOR), fShowDirFlags);
  228. ShowControl(GetDlgItem(IDC_STATIC_DIRFLAGS_SMALL), fShowDirFlags);
  229. ShowControl(IDC_CHECK_EXACT, fShowRedirectFlags);
  230. ShowControl(IDC_CHECK_CHILD, fShowRedirectFlags);
  231. if (fShowRedirectFlags)
  232. {
  233. GetDlgItem(IDC_CHECK_CHILD)->EnableWindow(FALSE);
  234. }
  235. ShowControl(IDC_CHECK_PERMANENT, fShowRedirectFlags);
  236. ShowControl(IDC_STATIC_REDIRECT_PROMPT, fShowRedirectFlags);
  237. ShowControl(IDC_STATIC_REDIRFLAGS, fShowRedirectFlags);
  238. ShowControl(&m_check_Author, fShowScript);
  239. //
  240. // Enable/Disable must come after the showcontrols
  241. //
  242. m_static_PathPrompt.SetWindowText(m_strPrompt[m_nPathType]);
  243. }
  244. void
  245. CW3FilePage::SaveAuthoringState()
  246. {
  247. if (m_check_Write.m_hWnd)
  248. {
  249. //
  250. // Controls initialized -- store live data
  251. //
  252. m_fOriginalWrite = m_check_Write.GetCheck() > 0;
  253. m_fOriginalRead = m_check_Read.GetCheck() > 0;
  254. }
  255. else
  256. {
  257. //
  258. // Controls not yet initialized, store original data
  259. //
  260. m_fOriginalWrite = m_fWrite;
  261. m_fOriginalRead = m_fRead;
  262. }
  263. }
  264. void
  265. CW3FilePage::RestoreAuthoringState()
  266. {
  267. m_fWrite = m_fOriginalWrite;
  268. m_fRead = m_fOriginalRead;
  269. }
  270. void
  271. CW3FilePage::SetAuthoringState(BOOL fAlterReadAndWrite)
  272. {
  273. if (fAlterReadAndWrite)
  274. {
  275. if (m_fAuthor)
  276. {
  277. //
  278. // Remember previous setting to undo
  279. // this thing.
  280. //
  281. SaveAuthoringState();
  282. m_fRead = m_fWrite = TRUE;
  283. }
  284. else
  285. {
  286. //
  287. // Restore previous defaults
  288. //
  289. RestoreAuthoringState();
  290. }
  291. m_check_Read.SetCheck(m_fRead);
  292. m_check_Write.SetCheck(m_fWrite);
  293. }
  294. m_check_Author.EnableWindow((m_fRead || m_fWrite)
  295. && HasAdminAccess()
  296. );
  297. // m_check_Read.EnableWindow(!m_fAuthor && HasAdminAccess());
  298. // m_check_Write.EnableWindow(!m_fAuthor && HasAdminAccess());
  299. }
  300. void
  301. CW3FilePage::SetPathType()
  302. {
  303. if (!m_strRedirectPath.IsEmpty())
  304. {
  305. m_nPathType = RADIO_REDIRECT;
  306. m_radio_Dir.SetCheck(0);
  307. m_radio_Redirect.SetCheck(1);
  308. }
  309. else
  310. {
  311. m_nPathType = RADIO_DIRECTORY;
  312. m_radio_Redirect.SetCheck(0);
  313. m_radio_Dir.SetCheck(1);
  314. }
  315. m_static_PathPrompt.SetWindowText(m_strPrompt[m_nPathType]);
  316. }
  317. //
  318. // Message Handlers
  319. //
  320. // <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
  321. void
  322. CW3FilePage::OnItemChanged()
  323. {
  324. SetModified(TRUE);
  325. }
  326. BOOL
  327. CW3FilePage::OnInitDialog()
  328. {
  329. CInetPropertyPage::OnInitDialog();
  330. SetPathType();
  331. SetStateByType();
  332. SetAuthoringState(FALSE);
  333. // It is enough to set file alias once -- we cannot change it here
  334. CString buf1, buf2, strAlias;
  335. CMetabasePath::GetRootPath(m_strFullMetaPath, buf1, &buf2);
  336. strAlias += _T("\\");
  337. strAlias += buf2;
  338. CvtPathToDosStyle(strAlias);
  339. m_edit_Path.SetWindowText(strAlias);
  340. #ifdef SUPPORT_SLASH_SLASH_QUESTIONMARK_SLASH_TYPE_PATHS
  341. LimitInputPath(CONTROL_HWND(IDC_EDIT_PATH),TRUE);
  342. #else
  343. LimitInputPath(CONTROL_HWND(IDC_EDIT_PATH),FALSE);
  344. #endif
  345. return TRUE;
  346. }
  347. /* virtual */
  348. HRESULT
  349. CW3FilePage::FetchLoadedValues()
  350. {
  351. CError err;
  352. BEGIN_META_DIR_READ(CW3Sheet)
  353. //
  354. // Use m_ notation because the message crackers require it
  355. //
  356. BOOL m_fDontLog;
  357. FETCH_DIR_DATA_FROM_SHEET(m_strFullMetaPath);
  358. FETCH_DIR_DATA_FROM_SHEET(m_strRedirectPath);
  359. FETCH_DIR_DATA_FROM_SHEET(m_dwAccessPerms);
  360. FETCH_DIR_DATA_FROM_SHEET(m_fDontLog);
  361. FETCH_DIR_DATA_FROM_SHEET(m_fExact);
  362. FETCH_DIR_DATA_FROM_SHEET(m_fPermanent);
  363. m_fRead = IS_FLAG_SET(m_dwAccessPerms, MD_ACCESS_READ);
  364. m_fWrite = IS_FLAG_SET(m_dwAccessPerms, MD_ACCESS_WRITE);
  365. m_fAuthor = IS_FLAG_SET(m_dwAccessPerms, MD_ACCESS_SOURCE);
  366. m_fLogAccess = !m_fDontLog;
  367. SaveAuthoringState();
  368. END_META_DIR_READ(err)
  369. return err;
  370. }
  371. /* virtual */
  372. HRESULT
  373. CW3FilePage::SaveInfo()
  374. {
  375. ASSERT(IsDirty());
  376. CError err;
  377. SET_FLAG_IF(m_fRead, m_dwAccessPerms, MD_ACCESS_READ);
  378. SET_FLAG_IF(m_fWrite, m_dwAccessPerms, MD_ACCESS_WRITE);
  379. SET_FLAG_IF(m_fAuthor, m_dwAccessPerms, MD_ACCESS_SOURCE);
  380. BOOL m_fDontLog = !m_fLogAccess;
  381. BeginWaitCursor();
  382. BEGIN_META_DIR_WRITE(CW3Sheet)
  383. INIT_DIR_DATA_MASK(m_dwAccessPerms, m_dwBitRangePermissions)
  384. STORE_DIR_DATA_ON_SHEET(m_fDontLog)
  385. STORE_DIR_DATA_ON_SHEET(m_fExact);
  386. STORE_DIR_DATA_ON_SHEET(m_fPermanent);
  387. //
  388. // CODEWORK: Not an elegant solution
  389. //
  390. // pSheet->GetDirectoryProperties().MarkRedirAsInherit(!m_fChild);
  391. STORE_DIR_DATA_ON_SHEET(m_strRedirectPath)
  392. STORE_DIR_DATA_ON_SHEET(m_dwAccessPerms)
  393. END_META_DIR_WRITE(err)
  394. if (err.Succeeded())
  395. {
  396. SaveAuthoringState();
  397. err = ((CW3Sheet *)GetSheet())->SetKeyType();
  398. NotifyMMC(PROP_CHANGE_DISPLAY_ONLY);
  399. }
  400. EndWaitCursor();
  401. return err;
  402. }
  403. void
  404. CW3FilePage::OnCheckRead()
  405. {
  406. m_fRead = !m_fRead;
  407. SetAuthoringState(FALSE);
  408. OnItemChanged();
  409. }
  410. void
  411. CW3FilePage::OnCheckWrite()
  412. {
  413. m_fWrite = !m_fWrite;
  414. SetAuthoringState(FALSE);
  415. OnItemChanged();
  416. }
  417. void
  418. CW3FilePage::OnCheckAuthor()
  419. {
  420. m_fAuthor = !m_fAuthor;
  421. SetAuthoringState(FALSE);
  422. OnItemChanged();
  423. }
  424. void
  425. CW3FilePage::OnRadioDir()
  426. {
  427. ChangeTypeTo(RADIO_DIRECTORY);
  428. }
  429. void
  430. CW3FilePage::OnRadioRedirect()
  431. {
  432. ChangeTypeTo(RADIO_REDIRECT);
  433. }