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.

924 lines
26 KiB

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