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.

500 lines
15 KiB

  1. /*++
  2. Module Name:
  3. pubProp.cpp
  4. Abstract:
  5. --*/
  6. #include "stdafx.h"
  7. #include "resource.h"
  8. #include "utils.h"
  9. #include "pubProp.h"
  10. #include "mvEdit.h"
  11. #include "dfshelp.h"
  12. #include "ldaputils.h"
  13. CPublishPropPage::CPublishPropPage() :
  14. m_lNotifyHandle(0),
  15. m_lNotifyParam(0),
  16. CQWizardPageImpl<CPublishPropPage>(false)
  17. {
  18. m_bPublish = FALSE;
  19. }
  20. CPublishPropPage::~CPublishPropPage()
  21. {
  22. // do not call MMCFreeNotifyHandle(m_lNotifyHandle);
  23. //
  24. // It should only be called once, and is already called
  25. // by the main property page
  26. }
  27. void CPublishPropPage::_Load()
  28. {
  29. HRESULT hr = S_OK;
  30. CComBSTR bstrUNCPath;
  31. do {
  32. if (!m_piDfsRoot)
  33. {
  34. hr = E_INVALIDARG;
  35. break;
  36. }
  37. DFS_TYPE lDfsType = DFS_TYPE_UNASSIGNED;
  38. hr = m_piDfsRoot->get_DfsType((long *)&lDfsType);
  39. BREAK_IF_FAILED(hr);
  40. if (lDfsType != DFS_TYPE_FTDFS)
  41. {
  42. CComBSTR bstrServerName, bstrShareName;
  43. hr = m_piDfsRoot->GetOneDfsHost(&bstrServerName, &bstrShareName);
  44. BREAK_IF_FAILED(hr);
  45. if (lstrlen(bstrShareName) > MAX_RDN_KEY_SIZE)
  46. {
  47. LoadStringFromResource(IDS_PUBPAGE_ERRMSG_64, &m_bstrError);
  48. return;
  49. }
  50. bstrUNCPath = _T("\\\\");
  51. BREAK_OUTOFMEMORY_IF_NULL((BSTR)bstrUNCPath, &hr);
  52. bstrUNCPath += bstrServerName;
  53. BREAK_OUTOFMEMORY_IF_NULL((BSTR)bstrUNCPath, &hr);
  54. bstrUNCPath += _T("\\");
  55. BREAK_OUTOFMEMORY_IF_NULL((BSTR)bstrUNCPath, &hr);
  56. bstrUNCPath += bstrShareName;
  57. BREAK_OUTOFMEMORY_IF_NULL((BSTR)bstrUNCPath, &hr);
  58. hr = ReadSharePublishInfoOnSARoot(
  59. bstrServerName,
  60. bstrShareName,
  61. &m_bPublish,
  62. &m_bstrUNCPath,
  63. &m_bstrDescription,
  64. &m_bstrKeywords,
  65. &m_bstrManagedBy
  66. );
  67. BREAK_IF_FAILED(hr);
  68. } else
  69. {
  70. CComBSTR bstrDomainName;
  71. hr = m_piDfsRoot->get_DomainName(&bstrDomainName);
  72. BREAK_IF_FAILED(hr);
  73. CComBSTR bstrDfsName;
  74. hr = m_piDfsRoot->get_DfsName(&bstrDfsName);
  75. BREAK_IF_FAILED(hr);
  76. bstrUNCPath = _T("\\\\");
  77. BREAK_OUTOFMEMORY_IF_NULL((BSTR)bstrUNCPath, &hr);
  78. bstrUNCPath += bstrDomainName;
  79. BREAK_OUTOFMEMORY_IF_NULL((BSTR)bstrUNCPath, &hr);
  80. bstrUNCPath += _T("\\");
  81. BREAK_OUTOFMEMORY_IF_NULL((BSTR)bstrUNCPath, &hr);
  82. bstrUNCPath += bstrDfsName;
  83. BREAK_OUTOFMEMORY_IF_NULL((BSTR)bstrUNCPath, &hr);
  84. hr = ReadSharePublishInfoOnFTRoot(
  85. bstrDomainName,
  86. bstrDfsName,
  87. &m_bPublish,
  88. &m_bstrUNCPath,
  89. &m_bstrDescription,
  90. &m_bstrKeywords,
  91. &m_bstrManagedBy
  92. );
  93. BREAK_IF_FAILED(hr);
  94. }
  95. } while (0);
  96. if (FAILED(hr))
  97. {
  98. _Reset();
  99. GetMessage(&m_bstrError, hr, IDS_PUBPAGE_ERRMSG);
  100. }
  101. if (!m_bstrUNCPath || !*m_bstrUNCPath)
  102. m_bstrUNCPath = bstrUNCPath;
  103. }
  104. HRESULT CPublishPropPage::_Save(
  105. IN BOOL i_bPublish,
  106. IN BSTR i_bstrDescription,
  107. IN BSTR i_bstrKeywords,
  108. IN BSTR i_bstrManagedBy
  109. )
  110. {
  111. RETURN_INVALIDARG_IF_NULL((IDfsRoot *)m_piDfsRoot);
  112. HRESULT hr = S_OK;
  113. do {
  114. if (m_bPublish == i_bPublish &&
  115. PROPSTRNOCHNG((BSTR)m_bstrDescription, i_bstrDescription) &&
  116. PROPSTRNOCHNG((BSTR)m_bstrKeywords, i_bstrKeywords) &&
  117. PROPSTRNOCHNG((BSTR)m_bstrManagedBy, i_bstrManagedBy) )
  118. break; // no change
  119. DFS_TYPE lDfsType = DFS_TYPE_UNASSIGNED;
  120. hr = m_piDfsRoot->get_DfsType((long *)&lDfsType);
  121. BREAK_IF_FAILED(hr);
  122. if (lDfsType != DFS_TYPE_FTDFS)
  123. {
  124. CComBSTR bstrServerName, bstrShareName;
  125. hr = m_piDfsRoot->GetOneDfsHost(&bstrServerName, &bstrShareName);
  126. BREAK_IF_FAILED(hr);
  127. hr = ModifySharePublishInfoOnSARoot(
  128. bstrServerName,
  129. bstrShareName,
  130. i_bPublish,
  131. m_bstrUNCPath,
  132. i_bstrDescription,
  133. i_bstrKeywords,
  134. i_bstrManagedBy
  135. );
  136. if (S_OK == hr)
  137. {
  138. m_bPublish = i_bPublish;
  139. m_bstrDescription = i_bstrDescription;
  140. m_bstrKeywords = i_bstrKeywords;
  141. m_bstrManagedBy = i_bstrManagedBy;
  142. } else if (S_FALSE == hr)
  143. hr = S_OK; // ignore non-existing object
  144. BREAK_IF_FAILED(hr);
  145. } else
  146. {
  147. CComBSTR bstrDomainName;
  148. hr = m_piDfsRoot->get_DomainName(&bstrDomainName);
  149. BREAK_IF_FAILED(hr);
  150. CComBSTR bstrDfsName;
  151. hr = m_piDfsRoot->get_DfsName(&bstrDfsName);
  152. BREAK_IF_FAILED(hr);
  153. hr = ModifySharePublishInfoOnFTRoot(
  154. bstrDomainName,
  155. bstrDfsName,
  156. i_bPublish,
  157. m_bstrUNCPath,
  158. i_bstrDescription,
  159. i_bstrKeywords,
  160. i_bstrManagedBy
  161. );
  162. if (S_OK == hr)
  163. {
  164. m_bPublish = i_bPublish;
  165. m_bstrDescription = i_bstrDescription;
  166. m_bstrKeywords = i_bstrKeywords;
  167. m_bstrManagedBy = i_bstrManagedBy;
  168. }
  169. BREAK_IF_FAILED(hr);
  170. }
  171. } while (0);
  172. return hr;
  173. }
  174. LRESULT
  175. CPublishPropPage::OnInitDialog(
  176. IN UINT i_uMsg,
  177. IN WPARAM i_wParam,
  178. LPARAM i_lParam,
  179. IN OUT BOOL& io_bHandled
  180. )
  181. {
  182. CWaitCursor wait;
  183. _Load();
  184. CheckDlgButton(IDC_PUBPROP_PUBLISH, (m_bPublish ? BST_CHECKED : BST_UNCHECKED));
  185. ::EnableWindow(GetDlgItem(IDC_PUBPROP_UNCPATH_LABEL), m_bPublish);
  186. ::EnableWindow(GetDlgItem(IDC_PUBPROP_UNCPATH), m_bPublish);
  187. ::EnableWindow(GetDlgItem(IDC_PUBPROP_DESCRIPTION_LABEL), m_bPublish);
  188. ::EnableWindow(GetDlgItem(IDC_PUBPROP_DESCRIPTION), m_bPublish);
  189. ::EnableWindow(GetDlgItem(IDC_PUBPROP_KEYWORDS_LABEL), m_bPublish);
  190. ::EnableWindow(GetDlgItem(IDC_PUBPROP_KEYWORDS), m_bPublish);
  191. ::EnableWindow(GetDlgItem(IDC_PUBPROP_KEYWORDS_EDIT), m_bPublish);
  192. ::EnableWindow(GetDlgItem(IDC_PUBPROP_MANAGEDBY_LABEL), m_bPublish);
  193. ::EnableWindow(GetDlgItem(IDC_PUBPROP_MANAGEDBY), m_bPublish);
  194. SetDlgItemText(IDC_PUBPROP_ERROR, ((BSTR)m_bstrError) ? m_bstrError : _T(""));
  195. SetDlgItemText(IDC_PUBPROP_UNCPATH, ((BSTR)m_bstrUNCPath) ? m_bstrUNCPath : _T(""));
  196. SetDlgItemText(IDC_PUBPROP_DESCRIPTION, ((BSTR)m_bstrDescription) ? m_bstrDescription : _T(""));
  197. SetDlgItemText(IDC_PUBPROP_KEYWORDS, ((BSTR)m_bstrKeywords) ? m_bstrKeywords : _T(""));
  198. SetDlgItemText(IDC_PUBPROP_MANAGEDBY, ((BSTR)m_bstrManagedBy) ? m_bstrManagedBy : _T(""));
  199. if (!m_bstrError)
  200. {
  201. ::SendMessage(GetDlgItem(IDC_PUBPROP_DESCRIPTION), EM_LIMITTEXT, 1024, 0); // AD schema defines its upper to be 1024
  202. MyShowWindow(GetDlgItem(IDC_PUBPROP_ERROR), FALSE);
  203. } else
  204. {
  205. MyShowWindow(GetDlgItem(IDC_PUBPROP_PUBLISH), FALSE);
  206. MyShowWindow(GetDlgItem(IDC_PUBPROP_UNCPATH), FALSE);
  207. MyShowWindow(GetDlgItem(IDC_PUBPROP_UNCPATH_LABEL), FALSE);
  208. MyShowWindow(GetDlgItem(IDC_PUBPROP_DESCRIPTION), FALSE);
  209. MyShowWindow(GetDlgItem(IDC_PUBPROP_DESCRIPTION_LABEL), FALSE);
  210. MyShowWindow(GetDlgItem(IDC_PUBPROP_KEYWORDS), FALSE);
  211. MyShowWindow(GetDlgItem(IDC_PUBPROP_KEYWORDS_LABEL), FALSE);
  212. MyShowWindow(GetDlgItem(IDC_PUBPROP_KEYWORDS_EDIT), FALSE);
  213. MyShowWindow(GetDlgItem(IDC_PUBPROP_MANAGEDBY), FALSE);
  214. MyShowWindow(GetDlgItem(IDC_PUBPROP_MANAGEDBY_LABEL), FALSE);
  215. }
  216. return TRUE; // To let the dialg set the control
  217. }
  218. /*++
  219. This function is called when a user clicks the ? in the top right of a property sheet
  220. and then clciks a control, or when they hit F1 in a control.
  221. --*/
  222. LRESULT CPublishPropPage::OnCtxHelp(
  223. IN UINT i_uMsg,
  224. IN WPARAM i_wParam,
  225. IN LPARAM i_lParam,
  226. IN OUT BOOL& io_bHandled
  227. )
  228. {
  229. LPHELPINFO lphi = (LPHELPINFO) i_lParam;
  230. if (!lphi || lphi->iContextType != HELPINFO_WINDOW || lphi->iCtrlId < 0)
  231. return FALSE;
  232. ::WinHelp((HWND)(lphi->hItemHandle),
  233. DFS_CTX_HELP_FILE,
  234. HELP_WM_HELP,
  235. (DWORD_PTR)(PVOID)g_aHelpIDs_IDD_PUBLISH_PROP);
  236. return TRUE;
  237. }
  238. /*++
  239. This function handles "What's This" help when a user right clicks the control
  240. --*/
  241. LRESULT CPublishPropPage::OnCtxMenuHelp(
  242. IN UINT i_uMsg,
  243. IN WPARAM i_wParam,
  244. IN LPARAM i_lParam,
  245. IN OUT BOOL& io_bHandled
  246. )
  247. {
  248. ::WinHelp((HWND)i_wParam,
  249. DFS_CTX_HELP_FILE,
  250. HELP_CONTEXTMENU,
  251. (DWORD_PTR)(PVOID)g_aHelpIDs_IDD_PUBLISH_PROP);
  252. return TRUE;
  253. }
  254. void CPublishPropPage::_Reset()
  255. {
  256. m_bPublish = FALSE;
  257. m_bstrUNCPath.Empty();
  258. m_bstrDescription.Empty();
  259. m_bstrKeywords.Empty();
  260. m_bstrManagedBy.Empty();
  261. }
  262. HRESULT CPublishPropPage::Initialize(
  263. IN IDfsRoot* i_piDfsRoot
  264. )
  265. {
  266. RETURN_INVALIDARG_IF_NULL(i_piDfsRoot);
  267. if ((IDfsRoot *)m_piDfsRoot)
  268. m_piDfsRoot.Release();
  269. m_piDfsRoot = i_piDfsRoot;
  270. _Reset();
  271. return S_OK;
  272. }
  273. LRESULT
  274. CPublishPropPage::OnApply()
  275. {
  276. CWaitCursor wait;
  277. HRESULT hr = S_OK;
  278. DWORD dwTextLength = 0;
  279. int idControl = 0;
  280. int idString = 0;
  281. BOOL bValidInput = FALSE;
  282. BOOL bPublish = IsDlgButtonChecked(IDC_PUBPROP_PUBLISH);
  283. CComBSTR bstrDescription;
  284. CComBSTR bstrKeywords;
  285. CComBSTR bstrManagedBy;
  286. do {
  287. idControl = IDC_PUBPROP_DESCRIPTION;
  288. hr = GetInputText(GetDlgItem(idControl), &bstrDescription, &dwTextLength);
  289. BREAK_IF_FAILED(hr);
  290. idControl = IDC_PUBPROP_KEYWORDS;
  291. hr = GetInputText(GetDlgItem(idControl), &bstrKeywords, &dwTextLength);
  292. BREAK_IF_FAILED(hr);
  293. idControl = IDC_PUBPROP_MANAGEDBY;
  294. hr = GetInputText(GetDlgItem(idControl), &bstrManagedBy, &dwTextLength);
  295. BREAK_IF_FAILED(hr);
  296. bValidInput = TRUE;
  297. } while (0);
  298. if (FAILED(hr))
  299. {
  300. SetActivePropertyPage(GetParent(), m_hWnd);
  301. DisplayMessageBoxForHR(hr);
  302. ::SetFocus(GetDlgItem(idControl));
  303. return FALSE;
  304. } else if (bValidInput)
  305. {
  306. hr = _Save(bPublish, bstrDescription, bstrKeywords, bstrManagedBy);
  307. if (FAILED(hr))
  308. {
  309. SetActivePropertyPage(GetParent(), m_hWnd);
  310. if (HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND) == hr)
  311. DisplayMessageBox(::GetActiveWindow(), MB_OK, 0, IDS_FAILED_TO_PUBLISH_DFSROOT_BADUSER);
  312. else
  313. DisplayMessageBox(::GetActiveWindow(), MB_OK, hr, IDS_FAILED_TO_PUBLISH_DFSROOT, m_bstrUNCPath);
  314. return FALSE;
  315. } else if (S_FALSE == hr) // no dfs root object in the DS
  316. {
  317. SetActivePropertyPage(GetParent(), m_hWnd);
  318. DisplayMessageBox(::GetActiveWindow(), MB_OK, 0, IDS_FAILED_TO_PUBLISH_NOROOTOBJ);
  319. return FALSE;
  320. }
  321. ::SendMessage(GetParent(), PSM_UNCHANGED, (WPARAM)m_hWnd, 0);
  322. if (m_lNotifyHandle && m_lNotifyParam)
  323. MMCPropertyChangeNotify(m_lNotifyHandle, m_lNotifyParam);
  324. return TRUE;
  325. } else
  326. {
  327. SetActivePropertyPage(GetParent(), m_hWnd);
  328. if (idString)
  329. DisplayMessageBoxWithOK(idString);
  330. ::SetFocus(GetDlgItem(idControl));
  331. return FALSE;
  332. }
  333. }
  334. LRESULT
  335. CPublishPropPage::OnPublish(
  336. IN WORD i_wNotifyCode,
  337. IN WORD i_wID,
  338. IN HWND i_hWndCtl,
  339. IN OUT BOOL& io_bHandled
  340. )
  341. {
  342. if (BN_CLICKED == i_wNotifyCode)
  343. {
  344. ::SendMessage(GetParent(), PSM_CHANGED, (WPARAM)m_hWnd, 0);
  345. BOOL bEnable = (BST_CHECKED == IsDlgButtonChecked(i_wID));
  346. ::EnableWindow(GetDlgItem(IDC_PUBPROP_UNCPATH_LABEL), bEnable);
  347. ::EnableWindow(GetDlgItem(IDC_PUBPROP_UNCPATH), bEnable);
  348. ::EnableWindow(GetDlgItem(IDC_PUBPROP_DESCRIPTION_LABEL), bEnable);
  349. ::EnableWindow(GetDlgItem(IDC_PUBPROP_DESCRIPTION), bEnable);
  350. ::EnableWindow(GetDlgItem(IDC_PUBPROP_KEYWORDS_LABEL), bEnable);
  351. ::EnableWindow(GetDlgItem(IDC_PUBPROP_KEYWORDS), bEnable);
  352. ::EnableWindow(GetDlgItem(IDC_PUBPROP_KEYWORDS_EDIT), bEnable);
  353. ::EnableWindow(GetDlgItem(IDC_PUBPROP_MANAGEDBY_LABEL), bEnable);
  354. ::EnableWindow(GetDlgItem(IDC_PUBPROP_MANAGEDBY), bEnable);
  355. }
  356. return TRUE;
  357. }
  358. LRESULT
  359. CPublishPropPage::OnDescription(
  360. IN WORD i_wNotifyCode,
  361. IN WORD i_wID,
  362. IN HWND i_hWndCtl,
  363. IN OUT BOOL& io_bHandled
  364. )
  365. {
  366. if (EN_CHANGE == i_wNotifyCode)
  367. {
  368. ::SendMessage(GetParent(), PSM_CHANGED, (WPARAM)m_hWnd, 0);
  369. }
  370. return TRUE;
  371. }
  372. LRESULT
  373. CPublishPropPage::OnEditKeywords(
  374. IN WORD i_wNotifyCode,
  375. IN WORD i_wID,
  376. IN HWND i_hWndCtl,
  377. IN OUT BOOL& io_bHandled
  378. )
  379. {
  380. DWORD dwTextLength = 0;
  381. CComBSTR bstrKeywords;
  382. GetInputText(GetDlgItem(IDC_PUBPROP_KEYWORDS), &bstrKeywords, &dwTextLength);
  383. if (S_OK == InvokeMultiValuedStringEditDlg(
  384. &bstrKeywords,
  385. _T(";"),
  386. IDS_MVSTRINGEDIT_TITLE_KEYWORDS,
  387. IDS_MVSTRINGEDIT_TEXT_KEYWORDS,
  388. KEYTWORDS_UPPER_RANGER))
  389. {
  390. SetDlgItemText(IDC_PUBPROP_KEYWORDS, bstrKeywords);
  391. ::SendMessage(GetParent(), PSM_CHANGED, (WPARAM)m_hWnd, 0);
  392. }
  393. return TRUE;
  394. }
  395. LRESULT
  396. CPublishPropPage::OnManagedBy(
  397. IN WORD i_wNotifyCode,
  398. IN WORD i_wID,
  399. IN HWND i_hWndCtl,
  400. IN OUT BOOL& io_bHandled
  401. )
  402. {
  403. if (EN_CHANGE == i_wNotifyCode)
  404. {
  405. ::SendMessage(GetParent(), PSM_CHANGED, (WPARAM)m_hWnd, 0);
  406. }
  407. return TRUE;
  408. }
  409. LRESULT
  410. CPublishPropPage::OnParentClosing(
  411. IN UINT i_uMsg,
  412. IN WPARAM i_wParam,
  413. LPARAM i_lParam,
  414. IN OUT BOOL& io_bHandled
  415. )
  416. {
  417. ::SendMessage(GetParent(), PSM_PRESSBUTTON, PSBTN_CANCEL, 0);
  418. return TRUE;
  419. }
  420. HRESULT
  421. CPublishPropPage::SetNotifyData(
  422. IN LONG_PTR i_lNotifyHandle,
  423. IN LPARAM i_lParam
  424. )
  425. {
  426. m_lNotifyHandle = i_lNotifyHandle;
  427. m_lNotifyParam = i_lParam;
  428. return S_OK;
  429. }