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.

391 lines
11 KiB

  1. // svcprop1.cpp : implementation file
  2. //
  3. #include "stdafx.h"
  4. #include "compdata.h"
  5. #include "resource.h"
  6. #include "shrprop.h"
  7. #include "filesvc.h"
  8. #include "dataobj.h" // CFileMgmtDataObject::m_CFMachineName
  9. #ifdef _DEBUG
  10. #define new DEBUG_NEW
  11. #undef THIS_FILE
  12. static char THIS_FILE[] = __FILE__;
  13. #endif
  14. /////////////////////////////////////////////////////////////////////////////
  15. // CSharePage property page
  16. IMPLEMENT_DYNCREATE(CSharePage, CPropertyPage)
  17. CSharePage::CSharePage(UINT nIDTemplate) :
  18. CPropertyPage(nIDTemplate ? nIDTemplate : CSharePageGeneral::IDD),
  19. m_pfnOriginalPropSheetPageProc( NULL ),
  20. m_pFileMgmtData( NULL ),
  21. m_transport( FILEMGMT_OTHER ),
  22. m_handle (0),
  23. m_pDataObject (0),
  24. m_bChanged (FALSE)
  25. {
  26. }
  27. CSharePage::~CSharePage()
  28. {
  29. if (NULL != m_pFileMgmtData)
  30. {
  31. ((IComponentData*)m_pFileMgmtData)->Release();
  32. m_pFileMgmtData = NULL;
  33. }
  34. if ( m_pDataObject )
  35. m_pDataObject->Release ();
  36. if ( m_handle )
  37. {
  38. ::MMCFreeNotifyHandle (m_handle);
  39. m_handle = NULL;
  40. }
  41. }
  42. BOOL CSharePage::Load( CFileMgmtComponentData* pFileMgmtData, LPDATAOBJECT piDataObject )
  43. {
  44. ASSERT( NULL == m_pFileMgmtData && NULL != pFileMgmtData && NULL != piDataObject );
  45. if ( !pFileMgmtData || !piDataObject )
  46. return FALSE;
  47. m_pDataObject = piDataObject;
  48. m_pDataObject->AddRef ();
  49. m_pFileMgmtData = pFileMgmtData;
  50. ((IComponentData*)m_pFileMgmtData)->AddRef();
  51. HRESULT hr = ExtractString( piDataObject, CFileMgmtDataObject::m_CFMachineName, &m_strMachineName, MAX_PATH );
  52. if ( FAILED(hr) )
  53. {
  54. ASSERT( FALSE );
  55. return FALSE;
  56. }
  57. if (m_strMachineName.IsEmpty())
  58. {
  59. // local computer
  60. TCHAR achComputerName[ MAX_COMPUTERNAME_LENGTH+1 ];
  61. DWORD dwSize = sizeof(achComputerName)/sizeof(TCHAR);
  62. GetComputerName( achComputerName, &dwSize );
  63. m_strMachineName = achComputerName;
  64. }
  65. hr = ExtractString( piDataObject, CFileMgmtDataObject::m_CFShareName, &m_strShareName, MAX_PATH );
  66. if ( FAILED(hr) )
  67. {
  68. ASSERT( FALSE );
  69. return FALSE;
  70. }
  71. hr = ExtractData( piDataObject,
  72. CFileMgmtDataObject::m_CFTransport,
  73. &m_transport,
  74. sizeof(DWORD) );
  75. if ( FAILED(hr) )
  76. {
  77. ASSERT( FALSE );
  78. return FALSE;
  79. }
  80. return TRUE;
  81. }
  82. void CSharePage::DoDataExchange(CDataExchange* pDX)
  83. {
  84. CPropertyPage::DoDataExchange(pDX);
  85. //{{AFX_DATA_MAP(CSharePage)
  86. //}}AFX_DATA_MAP
  87. } // CSharePage::DoDataExchange()
  88. BEGIN_MESSAGE_MAP(CSharePage, CPropertyPage)
  89. //{{AFX_MSG_MAP(CSharePage)
  90. //}}AFX_MSG_MAP
  91. END_MESSAGE_MAP()
  92. /////////////////////////////////////////////////////////////////////////////
  93. // CSharePage message handlers
  94. BOOL CSharePage::OnApply()
  95. {
  96. if ( IsModified () )
  97. {
  98. m_pDataObject->AddRef ();
  99. HRESULT hr = MMCPropertyChangeNotify (m_handle, reinterpret_cast <LONG_PTR>(m_pDataObject));
  100. ASSERT (SUCCEEDED (hr));
  101. if ( !SUCCEEDED (hr) )
  102. m_pDataObject->Release (); // released in OnPropertyChange () if successful
  103. }
  104. BOOL bResult = CPropertyPage::OnApply();
  105. if ( bResult )
  106. m_bChanged = FALSE;
  107. return bResult;
  108. }
  109. // This mechanism deletes the CFileMgmtGeneral when the property sheet is finished
  110. UINT CALLBACK CSharePage::PropSheetPageProc(
  111. HWND hwnd,
  112. UINT uMsg,
  113. LPPROPSHEETPAGE ppsp )
  114. {
  115. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  116. if (!ppsp || !ppsp->lParam)
  117. return 0; // unexpected
  118. CSharePage* pThis = reinterpret_cast<CSharePage*>(ppsp->lParam);
  119. LPFNPSPCALLBACK pfnOrig = pThis->m_pfnOriginalPropSheetPageProc;
  120. if (!pfnOrig)
  121. return 0; // unexpected
  122. UINT i = (pfnOrig)(hwnd,uMsg,ppsp);
  123. if (uMsg == PSPCB_RELEASE)
  124. delete pThis;
  125. return i;
  126. }
  127. void CSharePage::SetModified(BOOL bChanged)
  128. {
  129. m_bChanged = bChanged;
  130. CPropertyPage::SetModified (bChanged);
  131. }
  132. BOOL CSharePage::IsModified() const
  133. {
  134. return m_bChanged;
  135. }
  136. /////////////////////////////////////////////////////////////////////////////
  137. // CSharePageGeneral property page
  138. IMPLEMENT_DYNCREATE(CSharePageGeneral, CSharePage)
  139. CSharePageGeneral::CSharePageGeneral(UINT nIDTemplate) :
  140. CSharePage(nIDTemplate ? nIDTemplate : CSharePageGeneral::IDD),
  141. m_pvPropertyBlock( NULL ),
  142. m_fEnableDescription( TRUE ),
  143. m_fEnablePath( TRUE ),
  144. m_dwShareType(0)
  145. {
  146. //{{AFX_DATA_INIT(CSharePageGeneral)
  147. m_strShareName = _T("");
  148. m_strPath = _T("");
  149. m_strDescription = _T("");
  150. m_iMaxUsersAllowed = -1;
  151. m_dwMaxUsers = 0;
  152. //}}AFX_DATA_INIT
  153. }
  154. CSharePageGeneral::~CSharePageGeneral()
  155. {
  156. if (NULL != m_pvPropertyBlock)
  157. {
  158. ASSERT( NULL != m_pFileMgmtData && FILEMGMT_OTHER != m_transport );
  159. m_pFileMgmtData->GetFileServiceProvider(m_transport)->FreeData(m_pvPropertyBlock);
  160. }
  161. }
  162. BOOL CSharePageGeneral::Load( CFileMgmtComponentData* pFileMgmtData, LPDATAOBJECT piDataObject )
  163. {
  164. if (FALSE == CSharePage::Load(pFileMgmtData, piDataObject))
  165. return FALSE;
  166. BOOL fEditDescription = TRUE;
  167. BOOL fEditPath = TRUE;
  168. NET_API_STATUS retval =
  169. m_pFileMgmtData->GetFileServiceProvider(m_transport)->ReadShareProperties(
  170. m_strMachineName,
  171. m_strShareName,
  172. &m_pvPropertyBlock,
  173. m_strDescription,
  174. m_strPath,
  175. &m_fEnableDescription,
  176. &m_fEnablePath,
  177. &m_dwShareType);
  178. if (0L != retval)
  179. {
  180. (void) DoErrMsgBox(m_hWnd, MB_OK | MB_ICONSTOP, retval, IDS_POPUP_QUERY_SHARE, m_strShareName );
  181. return FALSE;
  182. }
  183. m_dwMaxUsers = m_pFileMgmtData->GetFileServiceProvider(
  184. m_transport)->QueryMaxUsers(m_pvPropertyBlock);
  185. if ((DWORD)-1 == m_dwMaxUsers)
  186. {
  187. m_iMaxUsersAllowed = 0;
  188. m_dwMaxUsers = 1;
  189. }
  190. else
  191. {
  192. m_iMaxUsersAllowed = 1;
  193. }
  194. return TRUE;
  195. }
  196. #define SHARE_DESCRIPTION_LIMIT MAXCOMMENTSZ
  197. #define MYUD_MAXVAL32 0x7FFFFFFF
  198. void CSharePageGeneral::DoDataExchange(CDataExchange* pDX)
  199. {
  200. CSharePage::DoDataExchange(pDX);
  201. //{{AFX_DATA_MAP(CSharePageGeneral)
  202. DDX_Control(pDX, IDC_SHRPROP_SPIN_USERS, m_spinMaxUsers);
  203. DDX_Control(pDX, IDC_EDIT_SHARE_NAME, m_editShareName);
  204. DDX_Control(pDX, IDC_EDIT_PATH_NAME, m_editPath);
  205. DDX_Control(pDX, IDC_EDIT_DESCRIPTION, m_editDescription);
  206. DDX_Control(pDX, IDC_SHRPROP_ALLOW_SPECIFIC, m_checkboxAllowSpecific);
  207. DDX_Control(pDX, IDC_SHRPROP_MAX_ALLOWED, m_checkBoxMaxAllowed);
  208. DDX_Text(pDX, IDC_EDIT_SHARE_NAME, m_strShareName);
  209. DDX_Text(pDX, IDC_EDIT_PATH_NAME, m_strPath);
  210. DDX_Text(pDX, IDC_EDIT_DESCRIPTION, m_strDescription);
  211. DDV_MaxChars(pDX, m_strDescription, SHARE_DESCRIPTION_LIMIT);
  212. DDX_Radio(pDX, IDC_SHRPROP_MAX_ALLOWED, m_iMaxUsersAllowed);
  213. DDX_Text(pDX, IDC_SHRPROP_EDIT_USERS, m_dwMaxUsers);
  214. DDV_MinMaxDWord(pDX, m_dwMaxUsers, 1, MYUD_MAXVAL32);
  215. //}}AFX_DATA_MAP
  216. if ( !pDX->m_bSaveAndValidate )
  217. {
  218. m_spinMaxUsers.SendMessage(UDM_SETRANGE32, 1, MYUD_MAXVAL32);
  219. if (0 == m_iMaxUsersAllowed)
  220. {
  221. GetDlgItem(IDC_SHRPROP_EDIT_USERS)->EnableWindow(FALSE);
  222. GetDlgItem(IDC_SHRPROP_SPIN_USERS)->EnableWindow(FALSE);
  223. }
  224. if ( !m_fEnableDescription ) {
  225. // m_staticDescription.SetWindowText(m_strDescription);
  226. // m_staticDescription.EnableWindow();
  227. // m_staticDescription.ShowWindow(SW_SHOW);
  228. m_editDescription.EnableWindow(FALSE);
  229. m_editDescription.ShowWindow(SW_HIDE);
  230. GetDlgItem(IDC_STATIC_COMMENT_STATIC)->EnableWindow(FALSE);
  231. GetDlgItem(IDC_STATIC_COMMENT_STATIC)->ShowWindow(SW_HIDE);
  232. // make read-only
  233. // m_editDescription.SetReadOnly(TRUE);
  234. }
  235. if ( m_fEnablePath ) {
  236. // m_staticPath.EnableWindow(FALSE);
  237. // m_staticPath.ShowWindow(SW_HIDE);
  238. // m_editPath.EnableWindow();
  239. // m_editPath.ShowWindow(SW_SHOW);
  240. // make read-write
  241. m_editPath.SetReadOnly(FALSE);
  242. }
  243. else {
  244. // m_staticPath.SetWindowText(m_strPath);
  245. // leave read-only
  246. }
  247. }
  248. } // CSharePageGeneral::DoDataExchange()
  249. BEGIN_MESSAGE_MAP(CSharePageGeneral, CSharePage)
  250. //{{AFX_MSG_MAP(CSharePageGeneral)
  251. ON_MESSAGE(WM_HELP, OnHelp)
  252. ON_MESSAGE(WM_CONTEXTMENU, OnContextHelp)
  253. ON_EN_CHANGE(IDC_EDIT_PATH_NAME, OnChangeEditPathName)
  254. ON_EN_CHANGE(IDC_EDIT_DESCRIPTION, OnChangeEditDescription)
  255. ON_EN_CHANGE(IDC_EDIT_SHARE_NAME, OnChangeEditShareName)
  256. ON_BN_CLICKED(IDC_SHRPROP_ALLOW_SPECIFIC, OnShrpropAllowSpecific)
  257. ON_BN_CLICKED(IDC_SHRPROP_MAX_ALLOWED, OnShrpropMaxAllowed)
  258. ON_EN_CHANGE(IDC_SHRPROP_EDIT_USERS, OnChangeShrpropEditUsers)
  259. //}}AFX_MSG_MAP
  260. END_MESSAGE_MAP()
  261. /////////////////////////////////////////////////////////////////////////////
  262. // CSharePageGeneral message handlers
  263. /////////////////////////////////////////////////////////////////////
  264. // Help
  265. BOOL CSharePageGeneral::OnHelp(WPARAM /*wParam*/, LPARAM lParam)
  266. {
  267. return DoHelp(lParam, HELP_DIALOG_TOPIC(IDD_SHAREPROP_GENERAL));
  268. }
  269. BOOL CSharePageGeneral::OnContextHelp(WPARAM wParam, LPARAM /*lParam*/)
  270. {
  271. return DoContextHelp(wParam, HELP_DIALOG_TOPIC(IDD_SHAREPROP_GENERAL));
  272. }
  273. BOOL CSharePageGeneral::OnApply()
  274. {
  275. if ( IsModified () )
  276. {
  277. ASSERT(NULL != m_pFileMgmtData);
  278. // UpdateData (TRUE) has already been called by OnKillActive () just before OnApply ()
  279. DWORD dwMaxUsers = (0 == m_iMaxUsersAllowed) ? (DWORD)-1 : m_dwMaxUsers;
  280. m_pFileMgmtData->GetFileServiceProvider(
  281. m_transport)->SetMaxUsers(m_pvPropertyBlock,dwMaxUsers);
  282. NET_API_STATUS retval =
  283. m_pFileMgmtData->GetFileServiceProvider(m_transport)->WriteShareProperties(
  284. m_strMachineName,
  285. m_strShareName,
  286. m_pvPropertyBlock,
  287. m_strDescription,
  288. m_strPath);
  289. if (0L != retval)
  290. {
  291. DoErrMsgBox(m_hWnd, MB_OK | MB_ICONEXCLAMATION, retval, IDS_POPUP_WRITE_SHARE, m_strShareName);
  292. return FALSE;
  293. }
  294. }
  295. return CSharePage::OnApply();
  296. }
  297. void CSharePageGeneral::OnChangeEditPathName()
  298. {
  299. SetModified (TRUE);
  300. }
  301. void CSharePageGeneral::OnChangeEditDescription()
  302. {
  303. SetModified (TRUE);
  304. }
  305. void CSharePageGeneral::OnChangeEditShareName()
  306. {
  307. SetModified (TRUE);
  308. }
  309. void CSharePageGeneral::OnShrpropAllowSpecific()
  310. {
  311. GetDlgItem(IDC_SHRPROP_EDIT_USERS)->EnableWindow(TRUE);
  312. GetDlgItem(IDC_SHRPROP_SPIN_USERS)->EnableWindow(TRUE);
  313. SetModified (TRUE);
  314. }
  315. void CSharePageGeneral::OnShrpropMaxAllowed()
  316. {
  317. SetDlgItemText(IDC_SHRPROP_EDIT_USERS, _T("1"));
  318. GetDlgItem(IDC_SHRPROP_EDIT_USERS)->EnableWindow(FALSE);
  319. GetDlgItem(IDC_SHRPROP_SPIN_USERS)->EnableWindow(FALSE);
  320. SetModified (TRUE);
  321. }
  322. void CSharePageGeneral::OnChangeShrpropEditUsers()
  323. {
  324. SetModified (TRUE);
  325. }