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.

269 lines
9.6 KiB

  1. // svcprop1.cpp : implementation file
  2. //
  3. #include "stdafx.h"
  4. #include "compdata.h"
  5. #include "resource.h"
  6. #include "shrpub.h"
  7. #include "mvedit.h"
  8. #include "filesvc.h"
  9. #include "dataobj.h" // CFileMgmtDataObject::m_CFMachineName
  10. #ifdef _DEBUG
  11. #define new DEBUG_NEW
  12. #undef THIS_FILE
  13. static char THIS_FILE[] = __FILE__;
  14. #endif
  15. /////////////////////////////////////////////////////////////////////////////
  16. // CSharePagePublish property page
  17. IMPLEMENT_DYNCREATE(CSharePagePublish, CSharePage)
  18. CSharePagePublish::CSharePagePublish() :
  19. CSharePage(CSharePagePublish::IDD)
  20. {
  21. m_bExposeKeywords = TRUE;
  22. m_bExposeManagedBy = TRUE;
  23. //{{AFX_DATA_INIT(CSharePagePublish)
  24. m_iPublish = BST_UNCHECKED;
  25. //}}AFX_DATA_INIT
  26. }
  27. CSharePagePublish::~CSharePagePublish()
  28. {
  29. m_handle = NULL; // let General page call MMCFreeNotifyHandle
  30. }
  31. BOOL CSharePagePublish::Load( CFileMgmtComponentData* pFileMgmtData, LPDATAOBJECT piDataObject )
  32. {
  33. if ( FALSE == CSharePage::Load (pFileMgmtData, piDataObject) )
  34. return FALSE;
  35. if (FILEMGMT_SMB != m_transport)
  36. return FALSE;
  37. return TRUE;
  38. }
  39. void CSharePagePublish::DoDataExchange(CDataExchange* pDX)
  40. {
  41. CSharePage::DoDataExchange(pDX);
  42. //{{AFX_DATA_MAP(CSharePagePublish)
  43. DDX_Check(pDX, IDC_CHECK_SHRPUB_PUBLISH, m_iPublish);
  44. DDX_Text(pDX, IDC_STATIC_SHRPUB_ERRORMSG, m_strError);
  45. DDX_Text(pDX, IDC_EDIT_SHRPUB_UNCPATH, m_strUNCPath);
  46. DDX_Text(pDX, IDC_EDIT_SHRPUB_DESCRIPTION, m_strDescription);
  47. DDX_Text(pDX, IDC_EDIT_SHRPUB_KEYWORDS, m_strKeywords);
  48. DDX_Text(pDX, IDC_EDIT_SHRPUB_MANAGEDBY, m_strManagedBy);
  49. DDV_MaxChars(pDX, m_strDescription, 1024); // AD schema defines its upper to be 1024
  50. //}}AFX_DATA_MAP
  51. if ( !pDX->m_bSaveAndValidate )
  52. {
  53. if (BST_CHECKED != m_iPublish)
  54. {
  55. GetDlgItem(IDC_LABEL_SHRPUB_UNCPATH)->EnableWindow(FALSE);
  56. GetDlgItem(IDC_EDIT_SHRPUB_UNCPATH)->EnableWindow(FALSE);
  57. GetDlgItem(IDC_LABEL_SHRPUB_DESCRIPTION)->EnableWindow(FALSE);
  58. GetDlgItem(IDC_EDIT_SHRPUB_DESCRIPTION)->EnableWindow(FALSE);
  59. GetDlgItem(IDC_LABEL_SHRPUB_KEYWORDS)->EnableWindow(FALSE);
  60. GetDlgItem(IDC_EDIT_SHRPUB_KEYWORDS)->EnableWindow(FALSE);
  61. GetDlgItem(IDC_LABEL_SHRPUB_MANAGEDBY)->EnableWindow(FALSE);
  62. GetDlgItem(IDC_EDIT_SHRPUB_MANAGEDBY)->EnableWindow(FALSE);
  63. GetDlgItem(IDC_BUTTON_SHRPUB_CHANGE)->EnableWindow(FALSE);
  64. }
  65. }
  66. } // CSharePagePublish::DoDataExchange()
  67. BEGIN_MESSAGE_MAP(CSharePagePublish, CSharePage)
  68. //{{AFX_MSG_MAP(CSharePagePublish)
  69. ON_MESSAGE(WM_HELP, OnHelp)
  70. ON_MESSAGE(WM_CONTEXTMENU, OnContextHelp)
  71. ON_EN_CHANGE(IDC_EDIT_SHRPUB_DESCRIPTION, OnChangeEditDescription)
  72. ON_BN_CLICKED(IDC_BUTTON_SHRPUB_CHANGE, OnChangeKeywords)
  73. ON_EN_CHANGE(IDC_EDIT_SHRPUB_MANAGEDBY, OnChangeEditManagedBy)
  74. ON_BN_CLICKED(IDC_CHECK_SHRPUB_PUBLISH, OnShrpubPublish)
  75. //}}AFX_MSG_MAP
  76. END_MESSAGE_MAP()
  77. /////////////////////////////////////////////////////////////////////////////
  78. // CSharePagePublish message handlers
  79. #define MAX_RDN_KEY_SIZE 64 // ds\src\inc\ntdsa.h
  80. BOOL CSharePagePublish::OnInitDialog()
  81. {
  82. BOOL bPublish = FALSE;
  83. HRESULT hr = S_OK;
  84. BOOL bLongShareName = (lstrlen(m_strShareName) > MAX_RDN_KEY_SIZE);
  85. if (!bLongShareName)
  86. m_pFileMgmtData->GetFileServiceProvider(FILEMGMT_SMB)->ReadSharePublishInfo(
  87. m_strMachineName,
  88. m_strShareName,
  89. &bPublish,
  90. m_strUNCPath,
  91. m_strDescription,
  92. m_strKeywords,
  93. m_strManagedBy
  94. );
  95. if (bLongShareName || FAILED(hr))
  96. {
  97. if (bLongShareName)
  98. {
  99. (void) GetMsg(m_strError, 0, IDS_MSG_SHRPUB_ERRMSG_64);
  100. } else
  101. {
  102. (void) GetMsg(m_strError, hr, IDS_MSG_READ_SHRPUB, m_strShareName);
  103. }
  104. //
  105. // show errmsg, hide all the other controls
  106. //
  107. GetDlgItem(IDC_CHECK_SHRPUB_PUBLISH)->ShowWindow(SW_HIDE);
  108. GetDlgItem(IDC_CHECK_SHRPUB_PUBLISH)->EnableWindow(FALSE);
  109. GetDlgItem(IDC_LABEL_SHRPUB_UNCPATH)->ShowWindow(SW_HIDE);
  110. GetDlgItem(IDC_LABEL_SHRPUB_UNCPATH)->EnableWindow(FALSE);
  111. GetDlgItem(IDC_EDIT_SHRPUB_UNCPATH)->ShowWindow(SW_HIDE);
  112. GetDlgItem(IDC_EDIT_SHRPUB_UNCPATH)->EnableWindow(FALSE);
  113. GetDlgItem(IDC_LABEL_SHRPUB_DESCRIPTION)->ShowWindow(SW_HIDE);
  114. GetDlgItem(IDC_LABEL_SHRPUB_DESCRIPTION)->EnableWindow(FALSE);
  115. GetDlgItem(IDC_EDIT_SHRPUB_DESCRIPTION)->ShowWindow(SW_HIDE);
  116. GetDlgItem(IDC_EDIT_SHRPUB_DESCRIPTION)->EnableWindow(FALSE);
  117. GetDlgItem(IDC_LABEL_SHRPUB_KEYWORDS)->ShowWindow(SW_HIDE);
  118. GetDlgItem(IDC_LABEL_SHRPUB_KEYWORDS)->EnableWindow(FALSE);
  119. GetDlgItem(IDC_EDIT_SHRPUB_KEYWORDS)->ShowWindow(SW_HIDE);
  120. GetDlgItem(IDC_EDIT_SHRPUB_KEYWORDS)->EnableWindow(FALSE);
  121. GetDlgItem(IDC_BUTTON_SHRPUB_CHANGE)->ShowWindow(SW_HIDE);
  122. GetDlgItem(IDC_BUTTON_SHRPUB_CHANGE)->EnableWindow(FALSE);
  123. GetDlgItem(IDC_LABEL_SHRPUB_MANAGEDBY)->ShowWindow(SW_HIDE);
  124. GetDlgItem(IDC_LABEL_SHRPUB_MANAGEDBY)->EnableWindow(FALSE);
  125. GetDlgItem(IDC_EDIT_SHRPUB_MANAGEDBY)->ShowWindow(SW_HIDE);
  126. GetDlgItem(IDC_EDIT_SHRPUB_MANAGEDBY)->EnableWindow(FALSE);
  127. } else
  128. {
  129. GetDlgItem(IDC_STATIC_SHRPUB_ERRORMSG)->ShowWindow(SW_HIDE);
  130. GetDlgItem(IDC_STATIC_SHRPUB_ERRORMSG)->EnableWindow(FALSE);
  131. if (!m_bExposeKeywords)
  132. {
  133. GetDlgItem(IDC_LABEL_SHRPUB_KEYWORDS)->ShowWindow(SW_HIDE);
  134. GetDlgItem(IDC_LABEL_SHRPUB_KEYWORDS)->EnableWindow(FALSE);
  135. GetDlgItem(IDC_EDIT_SHRPUB_KEYWORDS)->ShowWindow(SW_HIDE);
  136. GetDlgItem(IDC_EDIT_SHRPUB_KEYWORDS)->EnableWindow(FALSE);
  137. GetDlgItem(IDC_BUTTON_SHRPUB_CHANGE)->ShowWindow(SW_HIDE);
  138. GetDlgItem(IDC_BUTTON_SHRPUB_CHANGE)->EnableWindow(FALSE);
  139. }
  140. if (!m_bExposeManagedBy)
  141. {
  142. GetDlgItem(IDC_LABEL_SHRPUB_MANAGEDBY)->ShowWindow(SW_HIDE);
  143. GetDlgItem(IDC_LABEL_SHRPUB_MANAGEDBY)->EnableWindow(FALSE);
  144. GetDlgItem(IDC_EDIT_SHRPUB_MANAGEDBY)->ShowWindow(SW_HIDE);
  145. GetDlgItem(IDC_EDIT_SHRPUB_MANAGEDBY)->EnableWindow(FALSE);
  146. }
  147. if (!bPublish)
  148. {
  149. if (m_strMachineName.Left(2) == _T("\\\\"))
  150. {
  151. m_strUNCPath = m_strMachineName;
  152. } else
  153. {
  154. m_strUNCPath = _T("\\\\");
  155. m_strUNCPath += m_strMachineName;
  156. }
  157. m_strUNCPath += _T("\\");
  158. m_strUNCPath += m_strShareName;
  159. }
  160. m_iPublish = (bPublish ? BST_CHECKED : BST_UNCHECKED);
  161. }
  162. return CSharePage::OnInitDialog();
  163. }
  164. /////////////////////////////////////////////////////////////////////
  165. // Help
  166. BOOL CSharePagePublish::OnHelp(WPARAM /*wParam*/, LPARAM lParam)
  167. {
  168. return DoHelp(lParam, HELP_DIALOG_TOPIC(IDD_SHAREPROP_PUBLISH));
  169. }
  170. BOOL CSharePagePublish::OnContextHelp(WPARAM wParam, LPARAM /*lParam*/)
  171. {
  172. return DoContextHelp(wParam, HELP_DIALOG_TOPIC(IDD_SHAREPROP_PUBLISH));
  173. }
  174. BOOL CSharePagePublish::OnApply()
  175. {
  176. if ( IsModified () )
  177. {
  178. ASSERT(NULL != m_pFileMgmtData);
  179. // UpdateData (TRUE) has already been called by OnKillActive () just before OnApply ()
  180. HRESULT hr =
  181. m_pFileMgmtData->GetFileServiceProvider(FILEMGMT_SMB)->WriteSharePublishInfo(
  182. m_strMachineName,
  183. m_strShareName,
  184. (BST_CHECKED==m_iPublish),
  185. m_strDescription,
  186. m_strKeywords,
  187. m_strManagedBy);
  188. if (FAILED(hr))
  189. {
  190. DoErrMsgBox(m_hWnd, MB_OK | MB_ICONEXCLAMATION, hr, IDS_POPUP_WRITE_SHRPUB, m_strShareName);
  191. return FALSE;
  192. }
  193. }
  194. return CSharePage::OnApply();
  195. }
  196. void CSharePagePublish::OnChangeEditDescription()
  197. {
  198. SetModified (TRUE);
  199. }
  200. #define KEYTWORDS_UPPER_RANGER 256
  201. void CSharePagePublish::OnChangeKeywords()
  202. {
  203. if (S_OK == InvokeMultiValuedStringEditDlg(
  204. this,
  205. m_strKeywords,
  206. _T(";"),
  207. IDS_MVSTRINGEDIT_TITLE_KEYWORDS,
  208. IDS_MVSTRINGEDIT_TEXT_KEYWORDS,
  209. KEYTWORDS_UPPER_RANGER))
  210. {
  211. SetDlgItemText(IDC_EDIT_SHRPUB_KEYWORDS, m_strKeywords);
  212. SetModified (TRUE);
  213. }
  214. }
  215. void CSharePagePublish::OnChangeEditManagedBy()
  216. {
  217. SetModified (TRUE);
  218. }
  219. void CSharePagePublish::OnShrpubPublish()
  220. {
  221. BOOL bPublish = (BST_CHECKED == IsDlgButtonChecked(IDC_CHECK_SHRPUB_PUBLISH));
  222. GetDlgItem(IDC_LABEL_SHRPUB_UNCPATH)->EnableWindow(bPublish);
  223. GetDlgItem(IDC_EDIT_SHRPUB_UNCPATH)->EnableWindow(bPublish);
  224. GetDlgItem(IDC_LABEL_SHRPUB_DESCRIPTION)->EnableWindow(bPublish);
  225. GetDlgItem(IDC_EDIT_SHRPUB_DESCRIPTION)->EnableWindow(bPublish);
  226. GetDlgItem(IDC_LABEL_SHRPUB_KEYWORDS)->EnableWindow(bPublish);
  227. GetDlgItem(IDC_EDIT_SHRPUB_KEYWORDS)->EnableWindow(bPublish);
  228. GetDlgItem(IDC_LABEL_SHRPUB_MANAGEDBY)->EnableWindow(bPublish);
  229. GetDlgItem(IDC_EDIT_SHRPUB_MANAGEDBY)->EnableWindow(bPublish);
  230. GetDlgItem(IDC_BUTTON_SHRPUB_CHANGE)->EnableWindow(bPublish);
  231. SetModified (TRUE);
  232. }