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.

487 lines
14 KiB

  1. // WizPerm.cpp : implementation file
  2. //
  3. #include "stdafx.h"
  4. #include "WizPerm.h"
  5. #include "aclpage.h"
  6. #include <htmlhelp.h>
  7. #ifdef _DEBUG
  8. #define new DEBUG_NEW
  9. #undef THIS_FILE
  10. static char THIS_FILE[] = __FILE__;
  11. #endif
  12. /////////////////////////////////////////////////////////////////////////////
  13. // CWizPerm property page
  14. IMPLEMENT_DYNCREATE(CWizPerm, CPropertyPageEx)
  15. CWizPerm::CWizPerm() : CPropertyPageEx(CWizPerm::IDD, 0, IDS_HEADERTITLE_PERM, IDS_HEADERSUBTITLE_PERM)
  16. {
  17. //{{AFX_DATA_INIT(CWizPerm)
  18. // NOTE: the ClassWizard will add member initialization here
  19. //}}AFX_DATA_INIT
  20. m_psp.dwFlags |= PSP_USEHEADERTITLE | PSP_USEHEADERSUBTITLE;
  21. }
  22. CWizPerm::~CWizPerm()
  23. {
  24. }
  25. void CWizPerm::DoDataExchange(CDataExchange* pDX)
  26. {
  27. CPropertyPageEx::DoDataExchange(pDX);
  28. //{{AFX_DATA_MAP(CWizPerm)
  29. // NOTE: the ClassWizard will add DDX and DDV calls here
  30. //}}AFX_DATA_MAP
  31. }
  32. BEGIN_MESSAGE_MAP(CWizPerm, CPropertyPageEx)
  33. //{{AFX_MSG_MAP(CWizPerm)
  34. ON_BN_CLICKED(IDC_RADIO_PERM1, OnRadioPerm1)
  35. ON_BN_CLICKED(IDC_RADIO_PERM2, OnRadioPerm2)
  36. ON_BN_CLICKED(IDC_RADIO_PERM3, OnRadioPerm3)
  37. ON_BN_CLICKED(IDC_RADIO_PERM4, OnRadioPerm4)
  38. ON_BN_CLICKED(IDC_PERM_CUSTOM, OnPermCustom)
  39. ON_NOTIFY(NM_CLICK, IDC_PERM_HELPLINK, OnHelpLink)
  40. ON_NOTIFY(NM_RETURN, IDC_PERM_HELPLINK, OnHelpLink)
  41. //}}AFX_MSG_MAP
  42. END_MESSAGE_MAP()
  43. /////////////////////////////////////////////////////////////////////////////
  44. // CWizPerm message handlers
  45. BOOL CWizPerm::OnInitDialog()
  46. {
  47. CPropertyPageEx::OnInitDialog();
  48. CShrwizApp *pApp = (CShrwizApp *)AfxGetApp();
  49. if (pApp->m_bServerSBS)
  50. {
  51. CString cstrPerm2, cstrPerm3;
  52. cstrPerm2.LoadString(IDS_SBS_PERM2);
  53. cstrPerm3.LoadString(IDS_SBS_PERM3);
  54. SetDlgItemText(IDC_RADIO_PERM2, cstrPerm2);
  55. SetDlgItemText(IDC_RADIO_PERM3, cstrPerm3);
  56. }
  57. return TRUE; // return TRUE unless you set the focus to a control
  58. // EXCEPTION: OCX Property Pages should return FALSE
  59. }
  60. void CWizPerm::OnRadioPerm1()
  61. {
  62. Reset();
  63. GetDlgItem(IDC_PERM_CUSTOM)->EnableWindow(FALSE);
  64. }
  65. void CWizPerm::OnRadioPerm2()
  66. {
  67. Reset();
  68. GetDlgItem(IDC_PERM_CUSTOM)->EnableWindow(FALSE);
  69. }
  70. void CWizPerm::OnRadioPerm3()
  71. {
  72. Reset();
  73. GetDlgItem(IDC_PERM_CUSTOM)->EnableWindow(FALSE);
  74. }
  75. void CWizPerm::OnRadioPerm4()
  76. {
  77. // do not call Reset, in order to keep the pSD that the user has customized
  78. GetDlgItem(IDC_PERM_CUSTOM)->EnableWindow(TRUE);
  79. }
  80. void CWizPerm::OnPermCustom()
  81. {
  82. CWaitCursor wait;
  83. HRESULT hr = CoInitializeEx(NULL, COINIT_APARTMENTTHREADED);
  84. if (FAILED(hr))
  85. {
  86. TRACE(_T("CoInitializeEx failed hr=%x"), hr);
  87. return;
  88. }
  89. CShrwizApp *pApp = (CShrwizApp *)AfxGetApp();
  90. CShareSecurityInformation *pssInfo = NULL;
  91. HPROPSHEETPAGE phPages[2];
  92. int cPages = 1;
  93. CString cstrSheetTitle, cstrSharePageTitle;
  94. cstrSheetTitle.LoadString(IDS_CUSTOM_PERM);
  95. cstrSharePageTitle.LoadString(IDS_SHARE_PERMISSIONS);
  96. // create "Share Permissions" property page
  97. BOOL bSFMOnly = (!pApp->m_bSMB && pApp->m_bSFM);
  98. if (bSFMOnly)
  99. {
  100. PROPSHEETPAGE psp;
  101. ZeroMemory(&psp, sizeof(psp));
  102. psp.dwSize = sizeof(psp);
  103. psp.dwFlags = PSP_USETITLE;
  104. psp.hInstance = AfxGetResourceHandle();
  105. psp.pszTemplate = MAKEINTRESOURCE(IDD_NO_SHARE_PERMISSIONS);
  106. psp.pszTitle = cstrSharePageTitle;
  107. phPages[0] = CreatePropertySheetPage(&psp);
  108. if ( !(phPages[0]) )
  109. {
  110. hr = GetLastError();
  111. DisplayMessageBox(m_hWnd, MB_OK|MB_ICONWARNING, hr, IDS_FAILED_TO_CREATE_ACLUI);
  112. }
  113. } else
  114. {
  115. pssInfo = new CShareSecurityInformation(pApp->m_pSD);
  116. if (!pssInfo)
  117. {
  118. hr = E_OUTOFMEMORY;
  119. DisplayMessageBox(m_hWnd, MB_OK|MB_ICONWARNING, hr, IDS_FAILED_TO_CREATE_ACLUI);
  120. } else
  121. {
  122. pssInfo->Initialize(pApp->m_cstrTargetComputer, pApp->m_cstrShareName, cstrSharePageTitle);
  123. phPages[0] = CreateSecurityPage(pssInfo);
  124. if ( !(phPages[0]) )
  125. {
  126. hr = HRESULT_FROM_WIN32(GetLastError());
  127. DisplayMessageBox(m_hWnd, MB_OK|MB_ICONWARNING, hr, IDS_FAILED_TO_CREATE_ACLUI);
  128. }
  129. }
  130. }
  131. if (SUCCEEDED(hr))
  132. {
  133. // create "File Security" property page
  134. CFileSecurityDataObject *pfsDataObject = new CFileSecurityDataObject;
  135. if (!pfsDataObject)
  136. {
  137. hr = E_OUTOFMEMORY;
  138. DisplayMessageBox(m_hWnd, MB_OK|MB_ICONWARNING, hr, IDS_FAILED_TO_CREATE_ACLUI);
  139. // destroy pages that have not been passed to the PropertySheet function
  140. DestroyPropertySheetPage(phPages[0]);
  141. } else
  142. {
  143. pfsDataObject->Initialize(pApp->m_cstrTargetComputer, pApp->m_cstrFolder);
  144. hr = CreateFileSecurityPropPage(&(phPages[1]), pfsDataObject);
  145. if (SUCCEEDED(hr))
  146. cPages = 2;
  147. PROPSHEETHEADER psh;
  148. ZeroMemory(&psh, sizeof(psh));
  149. psh.dwSize = sizeof(psh);
  150. psh.dwFlags = PSH_DEFAULT | PSH_NOAPPLYNOW;
  151. psh.hwndParent = m_hWnd;
  152. psh.hInstance = AfxGetResourceHandle();
  153. psh.pszCaption = cstrSheetTitle;
  154. psh.nPages = cPages;
  155. psh.phpage = phPages;
  156. // create the property sheet
  157. PropertySheet(&psh);
  158. pfsDataObject->Release();
  159. }
  160. }
  161. if (!bSFMOnly)
  162. {
  163. if (pssInfo)
  164. pssInfo->Release();
  165. }
  166. CoUninitialize();
  167. }
  168. void CWizPerm::OnHelpLink(NMHDR* pNMHDR, LRESULT* pResult)
  169. {
  170. CWaitCursor wait;
  171. ::HtmlHelp(0, _T("file_srv.chm"), HH_DISPLAY_TOPIC, (DWORD_PTR)(_T("file_srv_set_permissions.htm")));
  172. *pResult = 0;
  173. }
  174. LRESULT CWizPerm::OnWizardNext()
  175. {
  176. CWaitCursor wait;
  177. HRESULT hr = S_OK;
  178. BOOL bCustom = FALSE;
  179. CShrwizApp *pApp = (CShrwizApp *)AfxGetApp();
  180. switch (GetCheckedRadioButton(IDC_RADIO_PERM1, IDC_RADIO_PERM4))
  181. {
  182. case IDC_RADIO_PERM1:
  183. {
  184. CPermEntry permEntry;
  185. hr = permEntry.Initialize(pApp->m_cstrTargetComputer, ACCOUNT_EVERYONE, SHARE_PERM_READ_ONLY);
  186. if (SUCCEEDED(hr))
  187. hr = BuildSecurityDescriptor(&permEntry, 1, &(pApp->m_pSD));
  188. }
  189. break;
  190. case IDC_RADIO_PERM2:
  191. {
  192. CPermEntry permEntry[3];
  193. UINT i = 0;
  194. hr = permEntry[i++].Initialize(pApp->m_cstrTargetComputer, ACCOUNT_EVERYONE, SHARE_PERM_READ_ONLY);
  195. if (SUCCEEDED(hr))
  196. {
  197. hr = permEntry[i++].Initialize(pApp->m_cstrTargetComputer, ACCOUNT_ADMINISTRATORS, SHARE_PERM_FULL_CONTROL);
  198. if (SUCCEEDED(hr))
  199. {
  200. if (pApp->m_bServerSBS)
  201. hr = permEntry[i++].Initialize(pApp->m_cstrTargetComputer, ACCOUNT_SBSFOLDEROPERATORS, SHARE_PERM_FULL_CONTROL);
  202. if (SUCCEEDED(hr))
  203. hr = BuildSecurityDescriptor(permEntry, i, &(pApp->m_pSD));
  204. }
  205. }
  206. }
  207. break;
  208. case IDC_RADIO_PERM3:
  209. {
  210. CPermEntry permEntry[3];
  211. UINT i = 0;
  212. hr = permEntry[i++].Initialize(pApp->m_cstrTargetComputer, ACCOUNT_EVERYONE, SHARE_PERM_READ_WRITE);
  213. if (SUCCEEDED(hr))
  214. {
  215. hr = permEntry[i++].Initialize(pApp->m_cstrTargetComputer, ACCOUNT_ADMINISTRATORS, SHARE_PERM_FULL_CONTROL);
  216. if (SUCCEEDED(hr))
  217. {
  218. if (pApp->m_bServerSBS)
  219. hr = permEntry[i++].Initialize(pApp->m_cstrTargetComputer, ACCOUNT_SBSFOLDEROPERATORS, SHARE_PERM_FULL_CONTROL);
  220. if (SUCCEEDED(hr))
  221. hr = BuildSecurityDescriptor(permEntry, i, &(pApp->m_pSD));
  222. }
  223. }
  224. }
  225. break;
  226. case IDC_RADIO_PERM4:
  227. {
  228. bCustom = TRUE;
  229. if (NULL == pApp->m_pSD)
  230. {
  231. CPermEntry permEntry;
  232. hr = permEntry.Initialize(pApp->m_cstrTargetComputer, ACCOUNT_EVERYONE, SHARE_PERM_READ_ONLY);
  233. if (SUCCEEDED(hr))
  234. hr = BuildSecurityDescriptor(&permEntry, 1, &(pApp->m_pSD));
  235. }
  236. }
  237. break;
  238. default:
  239. ASSERT(FALSE);
  240. return FALSE; // prevent the property sheet from being destroyed
  241. }
  242. if (!bCustom && FAILED(hr))
  243. {
  244. DisplayMessageBox(m_hWnd, MB_OK|MB_ICONERROR, hr, IDS_FAILED_TO_GET_SD);
  245. return FALSE; // prevent the property sheet from being destroyed
  246. }
  247. CreateShare();
  248. return CPropertyPageEx::OnWizardNext();
  249. }
  250. BOOL CWizPerm::OnSetActive()
  251. {
  252. CShrwizApp *pApp = (CShrwizApp *)AfxGetApp();
  253. GetParent()->SetDlgItemText(ID_WIZNEXT, pApp->m_cstrFinishButtonText);
  254. BOOL bSFMOnly = (!pApp->m_bSMB && pApp->m_bSFM);
  255. GetDlgItem(IDC_RADIO_PERM1)->EnableWindow(!bSFMOnly);
  256. GetDlgItem(IDC_RADIO_PERM2)->EnableWindow(!bSFMOnly);
  257. GetDlgItem(IDC_RADIO_PERM3)->EnableWindow(!bSFMOnly);
  258. if (bSFMOnly)
  259. {
  260. CheckRadioButton(IDC_RADIO_PERM1, IDC_RADIO_PERM4, IDC_RADIO_PERM4);
  261. OnRadioPerm4();
  262. }
  263. if (!pApp->m_bPermissionsPageInitialized)
  264. {
  265. if (!bSFMOnly)
  266. {
  267. CheckRadioButton(IDC_RADIO_PERM1, IDC_RADIO_PERM4, IDC_RADIO_PERM1);
  268. OnRadioPerm1();
  269. }
  270. pApp->m_bPermissionsPageInitialized = TRUE;
  271. }
  272. return CPropertyPageEx::OnSetActive();
  273. }
  274. void CWizPerm::Reset()
  275. {
  276. CShrwizApp *pApp = (CShrwizApp *)AfxGetApp();
  277. if (pApp->m_pSD)
  278. {
  279. LocalFree((HLOCAL)(pApp->m_pSD));
  280. pApp->m_pSD = NULL;
  281. }
  282. }
  283. int
  284. CWizPerm::CreateShare()
  285. {
  286. DWORD dwRet = NERR_Success;
  287. CShrwizApp *pApp = (CShrwizApp *)AfxGetApp();
  288. UINT iSuccess = 0;
  289. CString cstrSMBError;
  290. CString cstrSFMError;
  291. do {
  292. if (pApp->m_bSMB)
  293. {
  294. CString cstrSMB;
  295. cstrSMB.LoadString(IDS_SMB_CLIENTS);
  296. dwRet = SMBCreateShare(
  297. pApp->m_cstrTargetComputer,
  298. pApp->m_cstrShareName,
  299. pApp->m_cstrShareDescription,
  300. pApp->m_cstrFolder,
  301. pApp->m_pSD
  302. );
  303. if (NERR_Success != dwRet)
  304. {
  305. GetErrorMessage(dwRet, cstrSMBError);
  306. } else
  307. {
  308. iSuccess++;
  309. if (pApp->m_bIsLocal) // refresh shell
  310. SHChangeNotify(SHCNE_NETSHARE, SHCNF_PATH | SHCNF_FLUSH, pApp->m_cstrFolder, 0);
  311. // set client side caching setting, ignore error
  312. if (pApp->m_bCSC)
  313. {
  314. (void)SMBSetCSC(
  315. pApp->m_cstrTargetComputer,
  316. pApp->m_cstrShareName,
  317. pApp->m_dwCSCFlag
  318. );
  319. }
  320. }
  321. }
  322. if (pApp->m_bSFM)
  323. {
  324. dwRet = SFMCreateShare(
  325. pApp->m_cstrTargetComputer,
  326. pApp->m_cstrMACShareName,
  327. pApp->m_cstrFolder,
  328. pApp->m_hLibSFM
  329. );
  330. if (NERR_Success != dwRet)
  331. {
  332. GetErrorMessage(dwRet, cstrSFMError);
  333. } else
  334. {
  335. iSuccess++;
  336. }
  337. }
  338. } while (0);
  339. enum {noMac, onlySMB, onlySFM, both} eClientSelection = noMac;
  340. if (!pApp->m_bServerSFM)
  341. {
  342. eClientSelection = noMac;
  343. } else if (pApp->m_bSMB)
  344. {
  345. if (pApp->m_bSFM)
  346. eClientSelection = both;
  347. else
  348. eClientSelection = onlySMB;
  349. } else
  350. {
  351. eClientSelection = onlySFM;
  352. }
  353. // summary text
  354. switch (eClientSelection)
  355. {
  356. case noMac:
  357. pApp->m_cstrFinishSummary.FormatMessage(IDS_SUMMARY_NOMAC,
  358. pApp->m_cstrTargetComputer,
  359. pApp->m_cstrFolder,
  360. pApp->m_cstrShareName,
  361. pApp->m_cstrUNCPrefix + pApp->m_cstrShareName);
  362. break;
  363. case onlySMB:
  364. pApp->m_cstrFinishSummary.FormatMessage(IDS_SUMMARY_ONLYSMB,
  365. pApp->m_cstrTargetComputer,
  366. pApp->m_cstrFolder,
  367. pApp->m_cstrShareName,
  368. pApp->m_cstrUNCPrefix + pApp->m_cstrShareName);
  369. break;
  370. case onlySFM:
  371. pApp->m_cstrFinishSummary.FormatMessage(IDS_SUMMARY_ONLYSFM,
  372. pApp->m_cstrTargetComputer,
  373. pApp->m_cstrFolder,
  374. pApp->m_cstrMACShareName);
  375. break;
  376. case both:
  377. pApp->m_cstrFinishSummary.FormatMessage(IDS_SUMMARY_BOTH,
  378. pApp->m_cstrTargetComputer,
  379. pApp->m_cstrFolder,
  380. pApp->m_cstrShareName,
  381. pApp->m_cstrUNCPrefix + pApp->m_cstrShareName,
  382. pApp->m_cstrMACShareName);
  383. break;
  384. default:
  385. break;
  386. }
  387. // title & status
  388. if (0 == iSuccess)
  389. { // total failure
  390. pApp->m_cstrFinishTitle.LoadString(IDS_TITLE_FAILURE);
  391. switch (eClientSelection)
  392. {
  393. case noMac:
  394. pApp->m_cstrFinishStatus.FormatMessage(IDS_STATUS_FAILURE_NOMAC, cstrSMBError);
  395. break;
  396. case onlySMB:
  397. pApp->m_cstrFinishStatus.FormatMessage(IDS_STATUS_FAILURE_ONLYSMB, cstrSMBError);
  398. break;
  399. case onlySFM:
  400. pApp->m_cstrFinishStatus.FormatMessage(IDS_STATUS_FAILURE_ONLYSFM, cstrSFMError);
  401. break;
  402. case both:
  403. pApp->m_cstrFinishStatus.FormatMessage(IDS_STATUS_FAILURE_BOTH, cstrSMBError, cstrSFMError);
  404. break;
  405. default:
  406. break;
  407. }
  408. } else if (both == eClientSelection && 1 == iSuccess)
  409. { // partial failure
  410. pApp->m_cstrFinishTitle.LoadString(IDS_TITLE_PARTIAL_FAILURE);
  411. if (cstrSMBError.IsEmpty())
  412. pApp->m_cstrFinishStatus.FormatMessage(IDS_STATUS_PARTIAL_FAILURE_SFM, cstrSFMError);
  413. else
  414. pApp->m_cstrFinishStatus.FormatMessage(IDS_STATUS_PARTIAL_FAILURE_SMB, cstrSMBError);
  415. } else
  416. { // success
  417. pApp->m_cstrFinishTitle.LoadString(IDS_TITLE_SUCCESS);
  418. pApp->m_cstrFinishStatus.LoadString(IDS_STATUS_SUCCESS);
  419. }
  420. return 0;
  421. }