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.

1024 lines
30 KiB

  1. /////////////////////////////////////////////////////////////////////////////
  2. //
  3. // Copyright (c) 1996-2002 Microsoft Corporation
  4. //
  5. // Module Name:
  6. // SmbShare.cpp
  7. //
  8. // Abstract:
  9. // Implementation of the CFileShareParamsPage classes.
  10. //
  11. // Author:
  12. // David Potter (davidp) June 28, 1996
  13. //
  14. // Revision History:
  15. //
  16. // Notes:
  17. //
  18. /////////////////////////////////////////////////////////////////////////////
  19. #include "stdafx.h"
  20. #include <lmcons.h>
  21. #include <lmaccess.h>
  22. #include <clusudef.h>
  23. #include "CluAdmX.h"
  24. #include "ExtObj.h"
  25. #include "SmbShare.h"
  26. #include "DDxDDv.h"
  27. #include "PropList.h"
  28. #include "HelpData.h"
  29. #include "FSAdv.h"
  30. #include "FSCache.h"
  31. #include "ExcOper.h"
  32. #include <sddl.h>
  33. #include "SmbSSht.h"
  34. #include "AclUtils.h"
  35. #ifdef _DEBUG
  36. #define new DEBUG_NEW
  37. #undef THIS_FILE
  38. static char THIS_FILE[] = __FILE__;
  39. #endif
  40. /////////////////////////////////////////////////////////////////////////////
  41. // CFileShareParamsPage property page
  42. /////////////////////////////////////////////////////////////////////////////
  43. IMPLEMENT_DYNCREATE(CFileShareParamsPage, CBasePropertyPage)
  44. /////////////////////////////////////////////////////////////////////////////
  45. // Message Maps
  46. BEGIN_MESSAGE_MAP(CFileShareParamsPage, CBasePropertyPage)
  47. //{{AFX_MSG_MAP(CFileShareParamsPage)
  48. ON_EN_CHANGE(IDC_PP_FILESHR_PARAMS_SHARE_NAME, OnChangeRequiredField)
  49. ON_EN_CHANGE(IDC_PP_FILESHR_PARAMS_PATH, OnChangeRequiredField)
  50. ON_BN_CLICKED(IDC_PP_FILESHR_PARAMS_MAX_USERS_ALLOWED_RB, OnBnClickedMaxUsers)
  51. ON_BN_CLICKED(IDC_PP_FILESHR_PARAMS_MAX_USERS_RB, OnBnClickedMaxUsers)
  52. ON_EN_CHANGE(IDC_PP_FILESHR_PARAMS_MAX_USERS, OnEnChangeMaxUsers)
  53. ON_BN_CLICKED(IDC_PP_FILESHR_PARAMS_PERMISSIONS, OnBnClickedPermissions)
  54. ON_BN_CLICKED(IDC_PP_FILESHR_PARAMS_ADVANCED, OnBnClickedAdvanced)
  55. ON_BN_CLICKED(IDC_PP_FILESHR_PARAMS_CACHING, OnBnClickedCaching)
  56. //}}AFX_MSG_MAP
  57. // TODO: Modify the following lines to represent the data displayed on this page.
  58. ON_EN_CHANGE(IDC_PP_FILESHR_PARAMS_REMARK, CBasePropertyPage::OnChangeCtrl)
  59. END_MESSAGE_MAP()
  60. /////////////////////////////////////////////////////////////////////////////
  61. //++
  62. //
  63. // CFileShareParamsPage::CFileShareParamsPage
  64. //
  65. // Routine Description:
  66. // Default constructor.
  67. //
  68. // Arguments:
  69. // None.
  70. //
  71. // Return Value:
  72. // None.
  73. //
  74. //--
  75. /////////////////////////////////////////////////////////////////////////////
  76. CFileShareParamsPage::CFileShareParamsPage( void )
  77. : CBasePropertyPage(g_aHelpIDs_IDD_PP_FILESHR_PARAMETERS, g_aHelpIDs_IDD_WIZ_FILESHR_PARAMETERS)
  78. {
  79. // TODO: Modify the following lines to represent the data displayed on this page.
  80. //{{AFX_DATA_INIT(CFileShareParamsPage)
  81. m_strShareName = _T("");
  82. m_strPath = _T("");
  83. m_strRemark = _T("");
  84. //}}AFX_DATA_INIT
  85. m_psec = NULL;
  86. m_psecNT4 = NULL;
  87. m_psecNT5 = NULL;
  88. m_psecPrev = NULL;
  89. m_dwMaxUsers = (DWORD) -1;
  90. m_bShareSubDirs = FALSE;
  91. m_bPrevShareSubDirs = FALSE;
  92. m_bHideSubDirShares = FALSE;
  93. m_bPrevHideSubDirShares = FALSE;
  94. m_bIsDfsRoot = FALSE;
  95. m_bPrevIsDfsRoot = FALSE;
  96. // Setup the property array.
  97. {
  98. m_rgProps[epropShareName].Set(REGPARAM_FILESHR_SHARE_NAME, m_strShareName, m_strPrevShareName);
  99. m_rgProps[epropPath].Set(REGPARAM_FILESHR_PATH, m_strPath, m_strPrevPath);
  100. m_rgProps[epropRemark].Set(REGPARAM_FILESHR_REMARK, m_strRemark, m_strPrevRemark);
  101. m_rgProps[epropMaxUsers].Set(REGPARAM_FILESHR_MAX_USERS, m_dwMaxUsers, m_dwPrevMaxUsers);
  102. m_rgProps[epropShareSubDirs].Set(REGPARAM_FILESHR_SHARE_SUBDIRS, m_bShareSubDirs, m_bPrevShareSubDirs, CObjectProperty::opfNew);
  103. m_rgProps[epropHideSubDirShares].Set(REGPARAM_FILESHR_HIDE_SUBDIR_SHARES, m_bHideSubDirShares, m_bPrevHideSubDirShares, CObjectProperty::opfNew);
  104. m_rgProps[epropIsDfsRoot].Set(REGPARAM_FILESHR_IS_DFS_ROOT, m_bIsDfsRoot, m_bPrevIsDfsRoot, CObjectProperty::opfNew);
  105. m_rgProps[epropCSCCache].Set(REGPARAM_FILESHR_CSC_CACHE, m_dwCSCCache, m_dwPrevCSCCache, CObjectProperty::opfNew);
  106. } // Setup the property array
  107. m_iddPropertyPage = IDD_PP_FILESHR_PARAMETERS;
  108. m_iddWizardPage = IDD_WIZ_FILESHR_PARAMETERS;
  109. } //*** CFileShareParamsPage::CFileShareParamsPage()
  110. /////////////////////////////////////////////////////////////////////////////
  111. //++
  112. //
  113. // CFileShareParamsPage::~CFileShareParamsPage
  114. //
  115. // Routine Description:
  116. // Destructor.
  117. //
  118. // Arguments:
  119. // None.
  120. //
  121. // Return Value:
  122. // None.
  123. //
  124. //--
  125. /////////////////////////////////////////////////////////////////////////////
  126. CFileShareParamsPage::~CFileShareParamsPage(
  127. void
  128. )
  129. {
  130. ::LocalFree(m_psec);
  131. ::LocalFree(m_psecNT4);
  132. ::LocalFree(m_psecNT5);
  133. ::LocalFree(m_psecPrev);
  134. } //*** CFileShareParamsPage::~CFileShareParamsPage()
  135. /////////////////////////////////////////////////////////////////////////////
  136. //++
  137. //
  138. // CFileShareParamsPage::ScParseUnknownProperty
  139. //
  140. // Routine Description:
  141. // Parse a property that is not in the array of automatically-parsed
  142. // properties.
  143. //
  144. // Arguments:
  145. // pwszName [IN] Name of the property.
  146. // rvalue [IN] CLUSPROP property value.
  147. // cbBuf [IN] Total size of the value buffer.
  148. //
  149. // Return Value:
  150. // ERROR_SUCCESS Properties were parsed successfully.
  151. //
  152. // Exceptions Thrown:
  153. //
  154. //--
  155. /////////////////////////////////////////////////////////////////////////////
  156. DWORD
  157. CFileShareParamsPage::ScParseUnknownProperty(
  158. IN LPCWSTR pwszName,
  159. IN const CLUSPROP_BUFFER_HELPER & rvalue,
  160. IN DWORD cbBuf
  161. )
  162. {
  163. ASSERT(pwszName != NULL);
  164. ASSERT(rvalue.pb != NULL);
  165. DWORD sc = ERROR_SUCCESS;
  166. if ( ClRtlStrNICmp( pwszName, REGPARAM_FILESHR_SD, RTL_NUMBER_OF( REGPARAM_FILESHR_SD ) ) == 0 )
  167. {
  168. sc = ScConvertPropertyToSD(rvalue, cbBuf, &m_psecNT5);
  169. } // if: new security descriptor
  170. if (sc == ERROR_SUCCESS)
  171. {
  172. if ( ClRtlStrNICmp( pwszName, REGPARAM_FILESHR_SECURITY, RTL_NUMBER_OF( REGPARAM_FILESHR_SECURITY ) ) == 0 )
  173. {
  174. sc = ScConvertPropertyToSD(rvalue, cbBuf, &m_psecNT4);
  175. } // if: old security descriptor
  176. } // if:
  177. return sc;
  178. } //*** CFileShareParamsPage::ScParseUnknownProperty()
  179. /////////////////////////////////////////////////////////////////////////////
  180. //++
  181. //
  182. // CFileShareParamsPage::DoDataExchange
  183. //
  184. // Routine Description:
  185. // Do data exchange between the dialog and the class.
  186. //
  187. // Arguments:
  188. // pDX [IN OUT] Data exchange object
  189. //
  190. // Return Value:
  191. // None.
  192. //
  193. //--
  194. /////////////////////////////////////////////////////////////////////////////
  195. void
  196. CFileShareParamsPage::DoDataExchange(
  197. CDataExchange * pDX
  198. )
  199. {
  200. if (!pDX->m_bSaveAndValidate || !BSaved())
  201. {
  202. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  203. // TODO: Modify the following lines to represent the data displayed on this page.
  204. //{{AFX_DATA_MAP(CFileShareParamsPage)
  205. DDX_Control(pDX, IDC_PP_FILESHR_PARAMS_PERMISSIONS, m_pbPermissions);
  206. DDX_Control(pDX, IDC_PP_FILESHR_PARAMS_MAX_USERS_SPIN, m_spinMaxUsers);
  207. DDX_Control(pDX, IDC_PP_FILESHR_PARAMS_MAX_USERS_RB, m_rbMaxUsers);
  208. DDX_Control(pDX, IDC_PP_FILESHR_PARAMS_MAX_USERS_ALLOWED_RB, m_rbMaxUsersAllowed);
  209. DDX_Control(pDX, IDC_PP_FILESHR_PARAMS_MAX_USERS, m_editMaxUsers);
  210. DDX_Control(pDX, IDC_PP_FILESHR_PARAMS_REMARK, m_editRemark);
  211. DDX_Control(pDX, IDC_PP_FILESHR_PARAMS_PATH, m_editPath);
  212. DDX_Control(pDX, IDC_PP_FILESHR_PARAMS_SHARE_NAME, m_editShareName);
  213. DDX_Text(pDX, IDC_PP_FILESHR_PARAMS_SHARE_NAME, m_strShareName);
  214. DDX_Text(pDX, IDC_PP_FILESHR_PARAMS_PATH, m_strPath);
  215. DDX_Text(pDX, IDC_PP_FILESHR_PARAMS_REMARK, m_strRemark);
  216. //}}AFX_DATA_MAP
  217. #ifndef UDM_SETRANGE32
  218. #define UDM_SETRANGE32 (WM_USER+111)
  219. #endif
  220. #ifndef UD_MAXVAL32
  221. #define UD_MAXVAL32 0x7fffffff
  222. #endif
  223. if (pDX->m_bSaveAndValidate)
  224. {
  225. if (!BBackPressed())
  226. {
  227. DDV_MaxChars(pDX, m_strShareName, NNLEN);
  228. DDV_MaxChars(pDX, m_strPath, MAX_PATH);
  229. DDV_MaxChars(pDX, m_strRemark, MAXCOMMENTSZ);
  230. DDV_RequiredText(pDX, IDC_PP_FILESHR_PARAMS_SHARE_NAME, IDC_PP_FILESHR_PARAMS_SHARE_NAME_LABEL, m_strShareName);
  231. DDV_RequiredText(pDX, IDC_PP_FILESHR_PARAMS_PATH, IDC_PP_FILESHR_PARAMS_PATH_LABEL, m_strPath);
  232. } // if: Back button not pressed
  233. // Get the max # users.
  234. if (m_rbMaxUsersAllowed.GetCheck() == BST_CHECKED)
  235. m_dwMaxUsers = (DWORD) -1;
  236. else if (BBackPressed())
  237. DDX_Text(pDX, IDC_PP_FILESHR_PARAMS_MAX_USERS, m_dwMaxUsers);
  238. else
  239. #ifdef UD32
  240. DDX_Number(pDX, IDC_PP_FILESHR_PARAMS_MAX_USERS, m_dwMaxUsers, 1, UD_MAXVAL32, FALSE /*bSigned*/);
  241. #else
  242. DDX_Number(pDX, IDC_PP_FILESHR_PARAMS_MAX_USERS, m_dwMaxUsers, 1, UD_MAXVAL, FALSE /*bSigned*/);
  243. #endif
  244. } // if: saving data from dialog
  245. else
  246. {
  247. #ifdef UD32
  248. DDX_Number(pDX, IDC_PP_FILESHR_PARAMS_MAX_USERS, m_dwMaxUsers, 1, UD_MAXVAL32, FALSE /*bSigned*/);
  249. #else
  250. DDX_Number(pDX, IDC_PP_FILESHR_PARAMS_MAX_USERS, m_dwMaxUsers, 1, UD_MAXVAL, FALSE /*bSigned*/);
  251. #endif
  252. if (m_dwMaxUsers == (DWORD) -1)
  253. {
  254. m_rbMaxUsersAllowed.SetCheck(BST_CHECKED);
  255. m_rbMaxUsers.SetCheck(BST_UNCHECKED);
  256. m_editMaxUsers.SetWindowText(_T(""));
  257. } // if: unlimited specified
  258. else
  259. {
  260. m_rbMaxUsersAllowed.SetCheck(BST_UNCHECKED);
  261. m_rbMaxUsers.SetCheck(BST_CHECKED);
  262. } // else: a maximum was specified
  263. } // else: setting data to dialog
  264. } // if: not saving or haven't saved yet
  265. CBasePropertyPage::DoDataExchange(pDX);
  266. } //*** CFileShareParamsPage::DoDataExchange()
  267. /////////////////////////////////////////////////////////////////////////////
  268. //++
  269. //
  270. // CFileShareParamsPage::OnInitDialog
  271. //
  272. // Routine Description:
  273. // Handler for the WM_INITDIALOG message.
  274. //
  275. // Arguments:
  276. // None.
  277. //
  278. // Return Value:
  279. // TRUE We need the focus to be set for us.
  280. // FALSE We already set the focus to the proper control.
  281. //
  282. //--
  283. /////////////////////////////////////////////////////////////////////////////
  284. BOOL
  285. CFileShareParamsPage::OnInitDialog(
  286. void
  287. )
  288. {
  289. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  290. CBasePropertyPage::OnInitDialog();
  291. // Set limits on the edit controls.
  292. m_editShareName.SetLimitText(NNLEN);
  293. m_editPath.SetLimitText(MAX_PATH);
  294. m_editRemark.SetLimitText(MAXCOMMENTSZ);
  295. // Set the spin control limits.
  296. #ifdef UD32
  297. m_spinMaxUsers.SendMessage(UDM_SETRANGE32, 1, UD_MAXVAL32);
  298. #else
  299. m_spinMaxUsers.SetRange(1, UD_MAXVAL);
  300. #endif
  301. m_pbPermissions.EnableWindow(TRUE);
  302. return TRUE; // return TRUE unless you set the focus to a control
  303. // EXCEPTION: OCX Property Pages should return FALSE
  304. } //*** CFileShareParamsPage::OnInitDialog()
  305. /////////////////////////////////////////////////////////////////////////////
  306. //++
  307. //
  308. // CFileShareParamsPage::OnSetActive
  309. //
  310. // Routine Description:
  311. // Handler for the PSN_SETACTIVE message.
  312. //
  313. // Arguments:
  314. // None.
  315. //
  316. // Return Value:
  317. // TRUE Page successfully initialized.
  318. // FALSE Page not initialized.
  319. //
  320. //--
  321. /////////////////////////////////////////////////////////////////////////////
  322. BOOL
  323. CFileShareParamsPage::OnSetActive(
  324. void
  325. )
  326. {
  327. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  328. // Enable/disable the Next/Finish button.
  329. if (BWizard())
  330. {
  331. if ((m_strShareName.GetLength() == 0) || (m_strPath.GetLength() == 0))
  332. EnableNext(FALSE);
  333. else
  334. EnableNext(TRUE);
  335. } // if: enable/disable the Next button
  336. return CBasePropertyPage::OnSetActive();
  337. } //*** CFileShareParamsPage::OnSetActive()
  338. /////////////////////////////////////////////////////////////////////////////
  339. //++
  340. //
  341. // CFileShareParamsPage::BApplyChanges
  342. //
  343. // Routine Description:
  344. // Apply changes made on the page.
  345. //
  346. // Arguments:
  347. // None.
  348. //
  349. // Return Value:
  350. // TRUE Page successfully applied.
  351. // FALSE Error applying page.
  352. //
  353. //--
  354. /////////////////////////////////////////////////////////////////////////////
  355. BOOL
  356. CFileShareParamsPage::BApplyChanges(
  357. void
  358. )
  359. {
  360. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  361. CWaitCursor wc;
  362. return CBasePropertyPage::BApplyChanges();
  363. } //*** CFileShareParamsPage::BApplyChanges()
  364. /////////////////////////////////////////////////////////////////////////////
  365. //++
  366. //
  367. // CFileShareParamsPage::BBuildPropList
  368. //
  369. // Routine Description:
  370. // Build the property list.
  371. //
  372. // Arguments:
  373. // rcpl [IN OUT] Cluster property list.
  374. // bNoNewProps [IN] TRUE = exclude properties marked with opfNew.
  375. //
  376. // Return Value:
  377. // None.
  378. //
  379. // Exceptions Thrown:
  380. // Any exceptions thrown by CClusPropList::ScAddProp().
  381. //
  382. //--
  383. /////////////////////////////////////////////////////////////////////////////
  384. BOOL CFileShareParamsPage::BBuildPropList(
  385. IN OUT CClusPropList & rcpl,
  386. IN BOOL bNoNewProps // = FALSE
  387. )
  388. {
  389. BOOL bSuccess = FALSE;
  390. DWORD sc = ERROR_SUCCESS;
  391. //
  392. // Call the base class method.
  393. //
  394. bSuccess = CBasePropertyPage::BBuildPropList(rcpl, bNoNewProps);
  395. if (bSuccess)
  396. {
  397. //
  398. // We are creating the file share resource when we are a wizard page. So when we
  399. // are creating a file share resource and the security descriptor is NULL then
  400. // we need to create an SD that has everyone read only.
  401. //
  402. if ((Peo()->BWizard()) && (m_psec == NULL))
  403. {
  404. sc = ScCreateDefaultSD(&m_psec);
  405. } // if:
  406. if (sc == ERROR_SUCCESS)
  407. {
  408. if (!bNoNewProps)
  409. {
  410. rcpl.ScAddProp(
  411. REGPARAM_FILESHR_SD,
  412. (LPBYTE) m_psec,
  413. (m_psec == NULL ? 0 : ::GetSecurityDescriptorLength(m_psec)),
  414. (LPBYTE) m_psecPrev,
  415. (m_psecPrev == NULL ? 0 : ::GetSecurityDescriptorLength(m_psecPrev))
  416. );
  417. }
  418. PSECURITY_DESCRIPTOR psd = ::ClRtlConvertFileShareSDToNT4Format(m_psec);
  419. rcpl.ScAddProp(
  420. REGPARAM_FILESHR_SECURITY,
  421. (LPBYTE) psd,
  422. (psd == NULL ? 0 : ::GetSecurityDescriptorLength(psd)),
  423. (LPBYTE) m_psecPrev,
  424. (m_psecPrev == NULL ? 0 : ::GetSecurityDescriptorLength(m_psecPrev))
  425. );
  426. ::LocalFree(psd);
  427. } // if:
  428. else
  429. {
  430. bSuccess = FALSE;
  431. } // else:
  432. } // if: rest of property list build successfully
  433. return bSuccess;
  434. } //*** CFileShareParamsPage::BBuildPropList()
  435. /////////////////////////////////////////////////////////////////////////////
  436. //++
  437. //
  438. // CFileShareParamsPage::OnChangeRequiredField
  439. //
  440. // Routine Description:
  441. // Handler for the EN_CHANGE message on the Share name or Path edit
  442. // controls.
  443. //
  444. // Arguments:
  445. // None.
  446. //
  447. // Return Value:
  448. // None.
  449. //
  450. //--
  451. /////////////////////////////////////////////////////////////////////////////
  452. void CFileShareParamsPage::OnChangeRequiredField(void)
  453. {
  454. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  455. OnChangeCtrl();
  456. if (BWizard())
  457. {
  458. if ((m_editShareName.GetWindowTextLength() == 0)
  459. || (m_editPath.GetWindowTextLength() == 0))
  460. {
  461. EnableNext(FALSE);
  462. }
  463. else
  464. {
  465. EnableNext(TRUE);
  466. }
  467. } // if: in a wizard
  468. } //*** CFileShareParamsPage::OnChangeRequiredField()
  469. /////////////////////////////////////////////////////////////////////////////
  470. //++
  471. //
  472. // CFileShareParamsPage::OnBnClickedMaxUsers
  473. //
  474. // Routine Description:
  475. // Handler for the BN_CLICKED message on the Max Users radio buttons.
  476. //
  477. // Arguments:
  478. // None.
  479. //
  480. // Return Value:
  481. // None.
  482. //
  483. //--
  484. /////////////////////////////////////////////////////////////////////////////
  485. void CFileShareParamsPage::OnBnClickedMaxUsers(void)
  486. {
  487. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  488. SetModified(TRUE);
  489. if (m_rbMaxUsersAllowed.GetCheck() == BST_CHECKED)
  490. {
  491. m_editMaxUsers.SetWindowText(_T(""));
  492. }
  493. else
  494. {
  495. m_editMaxUsers.SetFocus();
  496. }
  497. } //*** CFileShareParamsPage::OnBnClickedMaxUsers()
  498. /////////////////////////////////////////////////////////////////////////////
  499. //++
  500. //
  501. // CFileShareParamsPage::OnEnChangeMaxUsers
  502. //
  503. // Routine Description:
  504. // Handler for the EN_CHANGE message on the Max Users edit control.
  505. //
  506. // Arguments:
  507. // None.
  508. //
  509. // Return Value:
  510. // None.
  511. //
  512. //--
  513. /////////////////////////////////////////////////////////////////////////////
  514. void CFileShareParamsPage::OnEnChangeMaxUsers(void)
  515. {
  516. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  517. OnChangeCtrl();
  518. if (m_editMaxUsers.m_hWnd != NULL)
  519. {
  520. if (m_editMaxUsers.GetWindowTextLength() == 0)
  521. {
  522. m_rbMaxUsersAllowed.SetCheck(BST_CHECKED);
  523. m_rbMaxUsers.SetCheck(BST_UNCHECKED);
  524. } // if: maximum # users has not been specified
  525. else
  526. {
  527. m_rbMaxUsersAllowed.SetCheck(BST_UNCHECKED);
  528. m_rbMaxUsers.SetCheck(BST_CHECKED);
  529. } // if: maximum # users has been specified
  530. } // if: control variables have been initialized
  531. } //*** CFileShareParamsPage::OnEnChangeMaxUsers()
  532. /////////////////////////////////////////////////////////////////////////////
  533. //++
  534. //
  535. // CFileShareParamsPage::OnBnClickedPermissions
  536. //
  537. // Routine Description:
  538. // Handler for the BN_CLICKED message on the Permissions push button.
  539. //
  540. // Arguments:
  541. // None.
  542. //
  543. // Return Value:
  544. // None.
  545. //
  546. //--
  547. /////////////////////////////////////////////////////////////////////////////
  548. void CFileShareParamsPage::OnBnClickedPermissions(void)
  549. {
  550. AFX_MANAGE_STATE( AfxGetStaticModuleState() );
  551. HRESULT hr = S_OK;
  552. INT_PTR nRet = 0;
  553. CString strNode;
  554. CString strShareName;
  555. //
  556. // Get the node on which the Cluster Name resource is online.
  557. //
  558. if ( BGetClusterNetworkNameNode( strNode ) == FALSE )
  559. {
  560. return;
  561. } // if:
  562. CWaitCursor wc;
  563. try
  564. {
  565. m_editShareName.GetWindowText( strShareName );
  566. m_strCaption.Format(
  567. IDS_ACLEDIT_PERMISSIONS,
  568. (LPCTSTR) strShareName,
  569. (LPCTSTR) Peo()->RrdResData().m_strName
  570. );
  571. CFileShareSecuritySheet fsSecurity( this, m_strCaption );
  572. hr = fsSecurity.HrInit( this, Peo(), strNode, strShareName );
  573. if ( SUCCEEDED( hr ) )
  574. {
  575. nRet = fsSecurity.DoModal();
  576. m_strCaption.Empty();
  577. } // if:
  578. } // try:
  579. catch ( CMemoryException * pme )
  580. {
  581. pme->Delete();
  582. } // catch: MFC memory exception...
  583. } //*** CFileShareParamsPage::OnBnClickedPermissions()
  584. /////////////////////////////////////////////////////////////////////////////
  585. //++
  586. //
  587. // CFileShareParamsPage::OnBnClickedAdvanced
  588. //
  589. // Routine Description:
  590. // Handler for the BN_CLICKED message on the Advanced push button.
  591. //
  592. // Arguments:
  593. // None.
  594. //
  595. // Return Value:
  596. // None.
  597. //
  598. //--
  599. /////////////////////////////////////////////////////////////////////////////
  600. void CFileShareParamsPage::OnBnClickedAdvanced(void)
  601. {
  602. CFileShareAdvancedDlg dlg(m_bShareSubDirs, m_bHideSubDirShares, m_bIsDfsRoot, this);
  603. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  604. if (dlg.DoModal() == IDOK)
  605. {
  606. if ( (m_bHideSubDirShares != dlg.m_bHideSubDirShares)
  607. || (m_bShareSubDirs != dlg.m_bShareSubDirs)
  608. || (m_bIsDfsRoot != dlg.m_bIsDfsRoot))
  609. {
  610. m_bHideSubDirShares = dlg.m_bHideSubDirShares;
  611. m_bShareSubDirs = dlg.m_bShareSubDirs;
  612. m_bIsDfsRoot = dlg.m_bIsDfsRoot;
  613. SetModified(TRUE);
  614. } // if: data changed
  615. } // if: user accepted the dialog
  616. } //*** CFileShareParamsPage::OnBnClickedAdvanced()
  617. /////////////////////////////////////////////////////////////////////////////
  618. //++
  619. //
  620. // CFileShareParamsPage::OnBnClickedCaching
  621. //
  622. // Routine Description:
  623. // Handler for the BN_CLICKED message on the Caching push button.
  624. //
  625. // Arguments:
  626. // None.
  627. //
  628. // Return Value:
  629. // None.
  630. //
  631. //--
  632. /////////////////////////////////////////////////////////////////////////////
  633. void CFileShareParamsPage::OnBnClickedCaching(void)
  634. {
  635. CFileShareCachingDlg dlg(m_dwCSCCache, this);
  636. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  637. if (dlg.DoModal() == IDOK)
  638. {
  639. if (m_dwCSCCache != dlg.m_dwFlags)
  640. {
  641. m_dwCSCCache = dlg.m_dwFlags;
  642. SetModified(TRUE);
  643. } // if: data changed
  644. } // if: user accepted the dialog
  645. } //*** CFileShareParamsPage::OnBnClickedCaching()
  646. /////////////////////////////////////////////////////////////////////////////
  647. //++
  648. //
  649. // CFileShareParamsPage::SetSecurityDescriptor
  650. //
  651. // Routine Description:
  652. // Save the passed in descriptor into m_psec.
  653. //
  654. // Arguments:
  655. // psec [IN] new security descriptor
  656. //
  657. // Return Value:
  658. //
  659. //
  660. //--
  661. /////////////////////////////////////////////////////////////////////////////
  662. HRESULT CFileShareParamsPage::SetSecurityDescriptor(
  663. IN PSECURITY_DESCRIPTOR psec
  664. )
  665. {
  666. ASSERT( psec != NULL );
  667. AFX_MANAGE_STATE( AfxGetStaticModuleState() );
  668. HRESULT hr = S_OK;
  669. DWORD sc = ERROR_SUCCESS;
  670. try
  671. {
  672. if ( psec != NULL )
  673. {
  674. ASSERT( IsValidSecurityDescriptor( psec ) );
  675. if ( IsValidSecurityDescriptor( psec ) )
  676. {
  677. LocalFree( m_psecPrev );
  678. m_psecPrev = NULL;
  679. if ( m_psec == NULL )
  680. {
  681. m_psecPrev = NULL;
  682. } // if: no previous value
  683. else
  684. {
  685. m_psecPrev = ::ClRtlCopySecurityDescriptor( m_psec );
  686. if ( m_psecPrev == NULL )
  687. {
  688. sc = GetLastError(); // Get the last error
  689. hr = HRESULT_FROM_WIN32( sc ); // Convert to HRESULT
  690. goto Cleanup;
  691. } // if: error copying the security descriptor
  692. } // else: previous value exists
  693. LocalFree( m_psec );
  694. m_psec = NULL;
  695. m_psec = ::ClRtlCopySecurityDescriptor( psec );
  696. if ( m_psec == NULL )
  697. {
  698. sc = GetLastError(); // Get the last error
  699. hr = HRESULT_FROM_WIN32( sc ); // Convert to HRESULT
  700. goto Cleanup;
  701. } // if: error copying the security descriptor
  702. SetModified( TRUE );
  703. hr = S_OK;
  704. } // if: security descriptor is valid
  705. } // if: non-NULL security descriptor specified
  706. else
  707. {
  708. TRACE( _T("CFileShareParamsPage::SetSecurityDescriptor() - ACLUI handed us back a NULL SD!\r") );
  709. hr = E_UNEXPECTED;
  710. }
  711. } // try:
  712. catch ( ... )
  713. {
  714. hr = E_FAIL;
  715. } // catch: everything...
  716. Cleanup:
  717. return hr;
  718. } //*** CFileShareParamsPage::SetSecurityDescriptor()
  719. /////////////////////////////////////////////////////////////////////////////
  720. //++
  721. //
  722. // CFileShareParamsPage::ScConvertPropertyToSD
  723. //
  724. // Routine Description:
  725. // Convert the property into an SD.
  726. //
  727. // Arguments:
  728. // rvalue [IN] CLUSPROP property value.
  729. // cbBuf [IN] Total size of the value buffer.
  730. // ppsec [IN] SD to save the property to.
  731. //
  732. // Return Value:
  733. // none.
  734. //
  735. // Exceptions Thrown:
  736. // Any exceptions from CString::operator=().
  737. //
  738. //--
  739. /////////////////////////////////////////////////////////////////////////////
  740. DWORD CFileShareParamsPage::ScConvertPropertyToSD(
  741. IN const CLUSPROP_BUFFER_HELPER & rvalue,
  742. IN DWORD cbBuf,
  743. IN PSECURITY_DESCRIPTOR *ppsec
  744. )
  745. {
  746. ASSERT(rvalue.pSyntax->wFormat == CLUSPROP_FORMAT_BINARY);
  747. ASSERT(cbBuf >= sizeof(*rvalue.pBinaryValue) + ALIGN_CLUSPROP(rvalue.pValue->cbLength));
  748. ASSERT(ppsec);
  749. DWORD sc = ERROR_SUCCESS;
  750. if ((ppsec != NULL) && (rvalue.pBinaryValue->cbLength != 0))
  751. {
  752. *ppsec = ::LocalAlloc(LMEM_ZEROINIT, rvalue.pBinaryValue->cbLength);
  753. if (*ppsec == NULL)
  754. {
  755. return ERROR_NOT_ENOUGH_MEMORY;
  756. }
  757. ::CopyMemory(*ppsec, rvalue.pBinaryValue->rgb, rvalue.pBinaryValue->cbLength);
  758. ASSERT(::IsValidSecurityDescriptor(*ppsec));
  759. if (!::IsValidSecurityDescriptor(*ppsec))
  760. {
  761. ::LocalFree(*ppsec);
  762. *ppsec = NULL;
  763. } // if: invalid security descriptor
  764. } // if: security descriptor specified
  765. else
  766. {
  767. if ( ppsec != NULL )
  768. {
  769. ::LocalFree(*ppsec);
  770. *ppsec = NULL;
  771. }
  772. } // else: no security descriptor specified
  773. return sc;
  774. } //*** CFileShareParamsPage::ScConvertPropertyToSD()
  775. /////////////////////////////////////////////////////////////////////////////
  776. //++
  777. //
  778. // CFileShareParamsPage::Psec
  779. //
  780. // Routine Description:
  781. // Return the SD for the FileShare. Since we may have two different
  782. // SDs we have to choose one and go with it... Since AclUi can use
  783. // the NT4 one without change it's OK to use it as is if the NT5 one
  784. // is not present...
  785. //
  786. // Arguments:
  787. // none.
  788. //
  789. // Return Value:
  790. // The SD...
  791. //
  792. // Exceptions Thrown:
  793. //
  794. //--
  795. /////////////////////////////////////////////////////////////////////////////
  796. const PSECURITY_DESCRIPTOR CFileShareParamsPage::Psec(
  797. void
  798. )
  799. {
  800. //
  801. // If we are in the wizard and m_psec is still NULL then the permissions
  802. // button was clicked and we need a proper default SD to hand to ACLUI...
  803. //
  804. if ((Peo()->BWizard()) && (m_psec == NULL))
  805. {
  806. DWORD sc;
  807. sc = ScCreateDefaultSD(&m_psec);
  808. if (sc == ERROR_SUCCESS)
  809. {
  810. ASSERT(m_psec != NULL);
  811. ASSERT(m_psecPre == NULL);
  812. } // if:
  813. else
  814. {
  815. //
  816. // If this fails then there really isn't anything much to do...
  817. // ACLUI will show everyone FULL control...
  818. //
  819. ASSERT(m_psec == NULL);
  820. ASSERT(m_psecPre == NULL);
  821. } // else:
  822. } // if:
  823. else
  824. {
  825. if (m_psec == NULL)
  826. {
  827. //
  828. // try the NT5 one first...
  829. //
  830. if (m_psecNT5 != NULL)
  831. {
  832. m_psec = ::ClRtlCopySecurityDescriptor(m_psecNT5);
  833. if ( m_psec == NULL )
  834. {
  835. goto Cleanup;
  836. } // if: error copying the security descriptor
  837. } // if: we have an NT5 SD...
  838. else
  839. {
  840. if (m_psecNT4 != NULL)
  841. {
  842. m_psec = ::ClRtlCopySecurityDescriptor(m_psecNT4);
  843. if ( m_psec == NULL )
  844. {
  845. goto Cleanup;
  846. } // if: error copying the security descriptor
  847. } // if: we have an NT4 SD...
  848. } // else: we don't have an NT5 SD...
  849. //
  850. // Set current values as the previous values to track changes.
  851. //
  852. m_psecPrev = ::ClRtlCopySecurityDescriptor(m_psec);
  853. } // if: we have an SD...
  854. } // else:
  855. Cleanup:
  856. return m_psec;
  857. } //*** CFileShareParamsPage::Psec()
  858. /////////////////////////////////////////////////////////////////////////////
  859. //++
  860. //
  861. // CFileShareParamsPage::ScCreateDefaultSD
  862. //
  863. // Routine Description:
  864. // When we are creating a new file share resource we need to create a
  865. // default SD that has everyone read only in its ACL.
  866. //
  867. // Arguments:
  868. // ppSecOut
  869. //
  870. // Return Value:
  871. // ERROR_SUCCESS
  872. //
  873. // Exceptions Thrown:
  874. // None.
  875. //
  876. //--
  877. /////////////////////////////////////////////////////////////////////////////
  878. DWORD
  879. CFileShareParamsPage::ScCreateDefaultSD(
  880. PSECURITY_DESCRIPTOR * ppSecOut
  881. )
  882. {
  883. ASSERT( ppSecOut != NULL );
  884. BOOL fRet = TRUE;
  885. DWORD sc = ERROR_SUCCESS;
  886. PSECURITY_DESCRIPTOR pSec = NULL;
  887. //
  888. // Create a default SD and hand it out...
  889. //
  890. fRet = ConvertStringSecurityDescriptorToSecurityDescriptorW(
  891. L"D:(A;;GRGX;;;WD)"
  892. , SDDL_REVISION_1
  893. , &pSec
  894. , NULL
  895. );
  896. if ( fRet )
  897. {
  898. sc = ERROR_SUCCESS;
  899. *ppSecOut = pSec;
  900. } // if:
  901. else
  902. {
  903. sc = GetLastError();
  904. TRACE( _T( "CFileShareParamsPage::ScCreateDefaultSD() - ConvertStringSecurityDescriptorToSecurityDescriptorW() failed. (sc = %#08x)\r" ), sc );
  905. } // else:
  906. return sc;
  907. } //*** CFileShareParamsPage::ScCreateDefaultSD()