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.

458 lines
16 KiB

  1. /////////////////////////////////////////////////////////////////////////////
  2. //
  3. // Copyright (c) 1999-2002 Microsoft Corporation
  4. //
  5. // Module Name:
  6. // Dhcp.cpp
  7. //
  8. // Description:
  9. // Implementation of the DHCP Service resource extension property page classes.
  10. //
  11. // Author:
  12. // David Potter (DavidP) March 24, 1999
  13. //
  14. // Revision History:
  15. //
  16. // Notes:
  17. //
  18. /////////////////////////////////////////////////////////////////////////////
  19. #include "stdafx.h"
  20. #include "ClNetResEx.h"
  21. #include "Dhcp.h"
  22. #include "BasePage.inl"
  23. #include "ExtObj.h"
  24. #include "DDxDDv.h"
  25. #include "HelpData.h"
  26. #ifdef _DEBUG
  27. #define new DEBUG_NEW
  28. #undef THIS_FILE
  29. static char THIS_FILE[] = __FILE__;
  30. #endif
  31. /////////////////////////////////////////////////////////////////////////////
  32. // CDhcpParamsPage property page
  33. /////////////////////////////////////////////////////////////////////////////
  34. IMPLEMENT_DYNCREATE( CDhcpParamsPage, CBasePropertyPage )
  35. /////////////////////////////////////////////////////////////////////////////
  36. // Message Maps
  37. BEGIN_MESSAGE_MAP( CDhcpParamsPage, CBasePropertyPage )
  38. //{{AFX_MSG_MAP(CDhcpParamsPage)
  39. ON_EN_CHANGE( IDC_PP_DHCP_DATABASEPATH, OnChangeRequiredField )
  40. ON_EN_CHANGE( IDC_PP_DHCP_LOGFILEPATH, OnChangeRequiredField )
  41. ON_EN_CHANGE( IDC_PP_DHCP_BACKUPPATH, OnChangeRequiredField )
  42. //}}AFX_MSG_MAP
  43. // TODO: Modify the following lines to represent the data displayed on this page.
  44. END_MESSAGE_MAP()
  45. /////////////////////////////////////////////////////////////////////////////
  46. //++
  47. //
  48. // CDhcpParamsPage::CDhcpParamsPage
  49. //
  50. // Description:
  51. // Default constructor.
  52. //
  53. // Arguments:
  54. // None.
  55. //
  56. // Return Value:
  57. // None.
  58. //
  59. //--
  60. /////////////////////////////////////////////////////////////////////////////
  61. CDhcpParamsPage::CDhcpParamsPage( void )
  62. : CBasePropertyPage(
  63. CDhcpParamsPage::IDD,
  64. g_aHelpIDs_IDD_PP_DHCP_PARAMETERS,
  65. g_aHelpIDs_IDD_WIZ_DHCP_PARAMETERS
  66. )
  67. {
  68. // TODO: Modify the following lines to represent the data displayed on this page.
  69. //{{AFX_DATA_INIT(CDhcpParamsPage)
  70. m_strDatabasePath = _T("");
  71. m_strLogFilePath = _T("");
  72. m_strBackupPath = _T("");
  73. //}}AFX_DATA_INIT
  74. // Setup the property array.
  75. {
  76. m_rgProps[ epropDatabasePath ].Set( REGPARAM_DHCP_DATABASEPATH, m_strDatabasePath, m_strPrevDatabasePath, m_strDatabaseExpandedPath );
  77. m_rgProps[ epropLogFilePath ].Set( REGPARAM_DHCP_LOGFILEPATH, m_strLogFilePath, m_strPrevLogFilePath, m_strLogFileExpandedPath );
  78. m_rgProps[ epropBackupPath ].Set( REGPARAM_DHCP_BACKUPPATH, m_strBackupPath, m_strPrevBackupPath, m_strBackupExpandedPath );
  79. } // Setup the property array
  80. m_iddPropertyPage = IDD_PP_DHCP_PARAMETERS;
  81. m_iddWizardPage = IDD_WIZ_DHCP_PARAMETERS;
  82. } //*** CDhcpParamsPage::CDhcpParamsPage()
  83. /////////////////////////////////////////////////////////////////////////////
  84. //++
  85. //
  86. // CDhcpParamsPage::DoDataExchange
  87. //
  88. // Description:
  89. // Do data exchange between the dialog and the class.
  90. //
  91. // Arguments:
  92. // pDX [IN OUT] Data exchange object
  93. //
  94. // Return Value:
  95. // None.
  96. //
  97. //--
  98. /////////////////////////////////////////////////////////////////////////////
  99. void CDhcpParamsPage::DoDataExchange( CDataExchange * pDX )
  100. {
  101. if ( ! pDX->m_bSaveAndValidate || ! BSaved() )
  102. {
  103. AFX_MANAGE_STATE( AfxGetStaticModuleState() );
  104. // TODO: Modify the following lines to represent the data displayed on this page.
  105. //{{AFX_DATA_MAP(CDhcpParamsPage)
  106. DDX_Control( pDX, IDC_PP_DHCP_DATABASEPATH, m_editDatabasePath );
  107. DDX_Control( pDX, IDC_PP_DHCP_LOGFILEPATH, m_editLogFilePath );
  108. DDX_Control( pDX, IDC_PP_DHCP_BACKUPPATH, m_editBackupPath );
  109. DDX_Text( pDX, IDC_PP_DHCP_DATABASEPATH, m_strDatabasePath );
  110. DDX_Text( pDX, IDC_PP_DHCP_LOGFILEPATH, m_strLogFilePath );
  111. DDX_Text( pDX, IDC_PP_DHCP_BACKUPPATH, m_strBackupPath );
  112. //}}AFX_DATA_MAP
  113. // Handle numeric parameters.
  114. if ( ! BBackPressed() )
  115. {
  116. } // if: back button not pressed
  117. if ( pDX->m_bSaveAndValidate )
  118. {
  119. // Make sure all required fields are present.
  120. if ( ! BBackPressed() )
  121. {
  122. DDV_RequiredText( pDX, IDC_PP_DHCP_DATABASEPATH, IDC_PP_DHCP_DATABASEPATH_LABEL, m_strDatabasePath );
  123. DDV_RequiredText( pDX, IDC_PP_DHCP_LOGFILEPATH, IDC_PP_DHCP_LOGFILEPATH_LABEL, m_strLogFilePath );
  124. DDV_RequiredText( pDX, IDC_PP_DHCP_BACKUPPATH, IDC_PP_DHCP_BACKUPPATH_LABEL, m_strBackupPath );
  125. } // if: back button not pressed
  126. } // if: saving data from dialog
  127. } // if: not saving or haven't saved yet
  128. CBasePropertyPage::DoDataExchange( pDX );
  129. } //*** CDhcpParamsPage::DoDataExchange()
  130. /////////////////////////////////////////////////////////////////////////////
  131. //++
  132. //
  133. // CDhcpParamsPage::OnInitDialog
  134. //
  135. // Description:
  136. // Handler for the WM_INITDIALOG message.
  137. //
  138. // Arguments:
  139. // None.
  140. //
  141. // Return Value:
  142. // TRUE We need the focus to be set for us.
  143. // FALSE We already set the focus to the proper control.
  144. //
  145. //--
  146. /////////////////////////////////////////////////////////////////////////////
  147. BOOL CDhcpParamsPage::OnInitDialog( void )
  148. {
  149. HRESULT hr;
  150. AFX_MANAGE_STATE( AfxGetStaticModuleState() );
  151. CBasePropertyPage::OnInitDialog();
  152. // Limit the size of the text that can be entered in edit controls.
  153. m_editDatabasePath.SetLimitText( _MAX_PATH );
  154. m_editLogFilePath.SetLimitText( _MAX_PATH );
  155. m_editBackupPath.SetLimitText( _MAX_PATH );
  156. // If this is a wizard, make sure the default values are something legal.
  157. if ( BWizard( ) )
  158. {
  159. DWORD status;
  160. WCHAR szValidDevice[ 3 ]; // "X:" + NULL
  161. DWORD dwSize = RTL_NUMBER_OF( szValidDevice );
  162. szValidDevice[ 0 ] = L'\0';
  163. status = ResUtilFindDependentDiskResourceDriveLetter( Peo( )->Hcluster( ),
  164. Peo( )->PrdResData( )->m_hresource,
  165. szValidDevice,
  166. &dwSize
  167. );
  168. szValidDevice[ 2 ] = L'\0'; // Make sure it's valid.
  169. // Did we find a disk resource in the the dependency list?
  170. if ( status == ERROR_SUCCESS
  171. && szValidDevice[ 0 ] != L'\0' )
  172. {
  173. WCHAR szFilePath[ MAX_PATH ];
  174. // If the default is "%SystemRoot%\<something>" then change it to match the
  175. // dependent resource
  176. if ( m_editDatabasePath.GetWindowText( szFilePath, MAX_PATH ) >= sizeof(L"%SystemRoot%")/sizeof(WCHAR) - 1
  177. && ClRtlStrNICmp( szFilePath, L"%SystemRoot%", sizeof(L"%SystemRoot%")/sizeof(WCHAR) - 1 ) == 0 )
  178. {
  179. // Start with the new drive letter
  180. hr = StringCchCopyNW( szFilePath, RTL_NUMBER_OF( szFilePath ), szValidDevice, 3 );
  181. if ( FAILED( hr ) )
  182. {
  183. goto Cleanup;
  184. }
  185. // Is the expanded string really expanded?
  186. if ( m_strDatabaseExpandedPath[0] != L'%' )
  187. { // yes, then just copy the expanded string minus the drive letter.
  188. LPCWSTR psz = m_strDatabaseExpandedPath;
  189. psz = wcschr( psz, L':' );
  190. if ( psz )
  191. {
  192. psz++; // move to next character
  193. }
  194. else // if: psz
  195. {
  196. psz = m_strDatabaseExpandedPath;
  197. } // else: just cat the whole thing, let the user figure it out.
  198. hr = StringCchCatW( szFilePath, RTL_NUMBER_OF( szFilePath ), psz );
  199. if ( FAILED( hr ) )
  200. {
  201. goto Cleanup;
  202. }
  203. }
  204. else
  205. { // no, then strip the %SystemRoot%
  206. // find the ending '%'... this must be there because of the strcmp above!
  207. LPCWSTR psz = m_strDatabaseExpandedPath;
  208. psz = wcschr( psz + 1, L'%' );
  209. ASSERT( psz );
  210. psz++; // move past the '%'
  211. hr = StringCchCatW( szFilePath, RTL_NUMBER_OF( szFilePath ), psz );
  212. if ( FAILED( hr ) )
  213. {
  214. goto Cleanup;
  215. }
  216. }
  217. m_editDatabasePath.SetWindowText( szFilePath );
  218. } // if: m_editDatabasePath == %SystemRoot%
  219. // If the default is "%SystemRoot%\<something>" then change it to match the
  220. // dependent resource
  221. if ( m_editLogFilePath.GetWindowText( szFilePath, MAX_PATH ) >= sizeof(L"%SystemRoot%")/sizeof(WCHAR) - 1
  222. && ClRtlStrNICmp( szFilePath, L"%SystemRoot%", sizeof(L"%SystemRoot%")/sizeof(WCHAR) - 1 ) == 0 )
  223. {
  224. // Start with the new drive letter
  225. hr = StringCchCopyNW( szFilePath, RTL_NUMBER_OF( szFilePath ), szValidDevice, 3 );
  226. if ( FAILED( hr ) )
  227. {
  228. goto Cleanup;
  229. }
  230. // Is the expanded string really expanded?
  231. if ( m_strLogFileExpandedPath[0] != L'%' )
  232. { // yes, then just copy the expanded string minus the drive letter.
  233. LPCWSTR psz = m_strLogFileExpandedPath;
  234. psz = wcschr( psz, L':' );
  235. if ( psz )
  236. {
  237. psz++; // move to next character
  238. }
  239. else // if: psz
  240. {
  241. psz = m_strLogFileExpandedPath;
  242. } // else: just cat the whole thing, let the user figure it out.
  243. hr = StringCchCatW( szFilePath, RTL_NUMBER_OF( szFilePath ), psz );
  244. if ( FAILED( hr ) )
  245. {
  246. goto Cleanup;
  247. }
  248. }
  249. else
  250. { // no, then strip the %SystemRoot%
  251. // find the ending '%'... this must be there because of the strcmp above!
  252. LPCWSTR psz = m_strLogFileExpandedPath;
  253. psz = wcschr( psz + 1, L'%' );
  254. ASSERT( psz );
  255. psz++; // move past the '%'
  256. hr = StringCchCatW( szFilePath, RTL_NUMBER_OF( szFilePath ), psz );
  257. if ( FAILED( hr ) )
  258. {
  259. goto Cleanup;
  260. }
  261. }
  262. m_editLogFilePath.SetWindowText( szFilePath );
  263. } // if: m_editLogFilePath == %SystemRoot%
  264. else if ( szFilePath[0] == L'\0' )
  265. { // no path found - default to the same as the database path
  266. m_editDatabasePath.GetWindowText( szFilePath, MAX_PATH );
  267. m_editLogFilePath.SetWindowText( szFilePath );
  268. } // else: no log path found
  269. // If the default is "%SystemRoot%\<something>" then change it to match the
  270. // dependent resource
  271. if ( m_editBackupPath.GetWindowText( szFilePath, MAX_PATH ) >= sizeof(L"%SystemRoot%")/sizeof(WCHAR) - 1
  272. && ClRtlStrNICmp( szFilePath, L"%SystemRoot%", sizeof(L"%SystemRoot%")/sizeof(WCHAR) - 1 ) == 0 )
  273. {
  274. // Start with the new drive letter
  275. hr = StringCchCopyNW( szFilePath, RTL_NUMBER_OF( szFilePath ), szValidDevice, 3 );
  276. if ( FAILED( hr ) )
  277. {
  278. goto Cleanup;
  279. }
  280. // Is the expanded string really expanded?
  281. if ( m_strBackupExpandedPath[0] != L'%' )
  282. { // yes, then just copy the expanded string minus the drive letter.
  283. LPCWSTR psz = m_strBackupExpandedPath;
  284. psz = wcschr( psz, L':' );
  285. if ( psz )
  286. {
  287. psz++; // move to next character
  288. }
  289. else // if: psz
  290. {
  291. psz = m_strBackupExpandedPath;
  292. } // else: just cat the whole thing, let the user figure it out.
  293. hr = StringCchCatW( szFilePath, RTL_NUMBER_OF( szFilePath ), psz );
  294. if ( FAILED( hr ) )
  295. {
  296. goto Cleanup;
  297. }
  298. }
  299. else
  300. { // no, then strip the %SystemRoot%
  301. // find the ending '%'... this must be there because of the strcmp above!
  302. LPCWSTR psz = m_strBackupExpandedPath;
  303. psz = wcschr( psz + 1, L'%' );
  304. ASSERT( psz );
  305. psz++; // move past the '%'
  306. hr = StringCchCatW( szFilePath, RTL_NUMBER_OF( szFilePath ), psz );
  307. if ( FAILED( hr ) )
  308. {
  309. goto Cleanup;
  310. }
  311. }
  312. m_editBackupPath.SetWindowText( szFilePath );
  313. } // if: m_editBackupPath == %SystemRoot%
  314. } // if: found a disk resource
  315. } // if: in a wizard
  316. Cleanup:
  317. return TRUE; // return TRUE unless you set the focus to a control
  318. // EXCEPTION: OCX Property Pages should return FALSE
  319. } //*** CDhcpParamsPage::OnInitDialog()
  320. /////////////////////////////////////////////////////////////////////////////
  321. //++
  322. //
  323. // CDhcpParamsPage::OnSetActive
  324. //
  325. // Description:
  326. // Handler for the PSN_SETACTIVE message.
  327. //
  328. // Arguments:
  329. // None.
  330. //
  331. // Return Value:
  332. // TRUE Page successfully initialized.
  333. // FALSE Page not initialized.
  334. //
  335. //--
  336. /////////////////////////////////////////////////////////////////////////////
  337. BOOL CDhcpParamsPage::OnSetActive( void )
  338. {
  339. AFX_MANAGE_STATE( AfxGetStaticModuleState() );
  340. // Enable/disable the Next/Finish button.
  341. if ( BWizard() )
  342. {
  343. EnableNext( BAllRequiredFieldsPresent() );
  344. } // if: displaying a wizard
  345. return CBasePropertyPage::OnSetActive();
  346. } //*** CDhcpParamsPage::OnSetActive()
  347. /////////////////////////////////////////////////////////////////////////////
  348. //++
  349. //
  350. // CDhcpParamsPage::OnChangeRequiredField
  351. //
  352. // Description:
  353. // Handler for the EN_CHANGE message on the Share name or Path edit
  354. // controls.
  355. //
  356. // Arguments:
  357. // None.
  358. //
  359. // Return Value:
  360. // None.
  361. //
  362. //--
  363. /////////////////////////////////////////////////////////////////////////////
  364. void CDhcpParamsPage::OnChangeRequiredField( void )
  365. {
  366. AFX_MANAGE_STATE( AfxGetStaticModuleState() );
  367. OnChangeCtrl();
  368. if ( BWizard() )
  369. {
  370. EnableNext( BAllRequiredFieldsPresent() );
  371. } // if: displaying a wizard
  372. } //*** CDhcpParamsPage::OnChangeRequiredField()
  373. /////////////////////////////////////////////////////////////////////////////
  374. //++
  375. //
  376. // CDhcpParamsPage::BAllRequiredFieldsPresent
  377. //
  378. // Description:
  379. // Handler for the EN_CHANGE message on the Share name or Path edit
  380. // controls.
  381. //
  382. // Arguments:
  383. // None.
  384. //
  385. // Return Value:
  386. // None.
  387. //
  388. //--
  389. /////////////////////////////////////////////////////////////////////////////
  390. BOOL CDhcpParamsPage::BAllRequiredFieldsPresent( void ) const
  391. {
  392. BOOL _bPresent;
  393. if ( 0
  394. || (m_editDatabasePath.GetWindowTextLength() == 0)
  395. || (m_editLogFilePath.GetWindowTextLength() == 0)
  396. || (m_editBackupPath.GetWindowTextLength() == 0)
  397. )
  398. {
  399. _bPresent = FALSE;
  400. } // if: required field not present
  401. else
  402. {
  403. _bPresent = TRUE;
  404. } // else: all required fields are present
  405. return _bPresent;
  406. } //*** CDhcpParamsPage::BAllRequiredFieldsPresent()