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.

3960 lines
108 KiB

  1. #ifndef _WIN32_WINNT
  2. #define _WIN32_WINNT 0x0500
  3. #endif
  4. #include <stdio.h>
  5. #include <windows.h>
  6. #include "uddisitenode.h"
  7. #include "webservernode.h"
  8. #include "comp.h"
  9. #include "compdata.h"
  10. #include "dataobj.h"
  11. #include "globals.h"
  12. #include "resource.h"
  13. #include "objectpicker.h"
  14. #include <htmlhelp.h>
  15. #include <windowsx.h>
  16. #include <commctrl.h>
  17. #include <atldbcli.h>
  18. #include <oledberr.h>
  19. #include <sddl.h>
  20. #include "net_config_get.h"
  21. #include "net_config_save.h"
  22. #include "ADM_execResetKeyImmediate.h"
  23. #include "ADM_setAdminAccount.h"
  24. #include <algorithm>
  25. #include "uddi.h"
  26. #include "scppublisher.h"
  27. BOOL RefreshInstances( HWND hwndList, PTCHAR szComputerName = _T("") );
  28. BOOL GetInstances( PTCHAR szComputer, StringVector& instances );
  29. // {53186FE3-F178-460c-8F3B-352549292B91}
  30. const GUID CUDDISiteNode::thisGuid = { 0x53186fe3, 0xf178, 0x460c, { 0x8f, 0x3b, 0x35, 0x25, 0x49, 0x29, 0x2b, 0x91 } };
  31. UINT CUDDISiteNode::m_nNextChildID = 0;
  32. //==============================================================
  33. //
  34. // CDBSchemaVersion implementation
  35. //
  36. //
  37. CDBSchemaVersion::CDBSchemaVersion() :
  38. m_major( -1 ),
  39. m_minor( -1 ),
  40. m_build( -1 ),
  41. m_rev( -1 )
  42. {}
  43. BOOL
  44. CDBSchemaVersion::IsCompatible( const CDBSchemaVersion& version )
  45. {
  46. //
  47. // The major and minor versions MUST be equal in order for the versions to be
  48. // compatible. Other values are ignored.
  49. //
  50. return ( m_major == version.m_major ) &&
  51. ( m_minor == version.m_minor );
  52. }
  53. BOOL
  54. CDBSchemaVersion::Parse( const tstring& versionString )
  55. {
  56. szVersion = versionString;
  57. int length = versionString.length();
  58. _TCHAR *buffer = new _TCHAR[ length + 1];
  59. if( NULL == buffer )
  60. {
  61. throw E_OUTOFMEMORY;
  62. return FALSE;
  63. }
  64. _tcscpy( buffer, versionString.c_str() );
  65. m_major = GetPart( _tcstok( buffer, _T(".") ) );
  66. m_minor = GetPart( _tcstok( NULL, _T(".") ) );
  67. m_build = GetPart( _tcstok( NULL, _T(".") ) );
  68. m_rev = GetPart( _tcstok( NULL, _T(".") ) );
  69. delete[] buffer;
  70. buffer = NULL;
  71. return ( m_major != -1 &&
  72. m_minor != -1 &&
  73. m_build != -1 &&
  74. m_rev != -1 );
  75. }
  76. int
  77. CDBSchemaVersion::GetPart( const _TCHAR* token )
  78. {
  79. if( NULL == token )
  80. {
  81. return -1;
  82. }
  83. int part = _tstoi( token );
  84. if( 0 == part && 0 != _tcscmp( token, _T( "0" ) ) )
  85. {
  86. return -1;
  87. }
  88. return part;
  89. }
  90. //==============================================================
  91. //
  92. // CUDDISiteNode implementation
  93. //
  94. //
  95. CUDDISiteNode::CUDDISiteNode( _TCHAR *szName, _TCHAR *szInstanceName, int id, CUDDIServicesNode *parent, BOOL bExtension )
  96. : m_szName(NULL)
  97. , m_szInstanceName(NULL)
  98. , m_ppHandle( 0 )
  99. , m_isDeleted( FALSE )
  100. , m_pParent( parent )
  101. , m_bIsDirty( FALSE )
  102. , m_bStdSvr( TRUE )
  103. {
  104. OutputDebugString( _T("Site Information Follows:\n" ) );
  105. OutputDebugString( _T("Computer: ") );
  106. OutputDebugString( szName );
  107. OutputDebugString( _T("\nInstance: " ) );
  108. OutputDebugString( szInstanceName );
  109. OutputDebugString( _T("\n") );
  110. m_szName = new _TCHAR[ ( _tcslen( szName ) + 1 ) ];
  111. _tcscpy( m_szName, szName );
  112. tstring strFullyQualifiedInstanceName;
  113. CUDDISiteNode::GetFullyQualifiedInstanceName( szName, strFullyQualifiedInstanceName );
  114. m_szInstanceName = new _TCHAR[ strFullyQualifiedInstanceName.length() + 1 ];
  115. _tcscpy( m_szInstanceName, strFullyQualifiedInstanceName.c_str() );
  116. m_bIsExtension = bExtension;
  117. }
  118. CUDDISiteNode::~CUDDISiteNode()
  119. {
  120. ClearChildMap();
  121. if( m_szName )
  122. delete [] m_szName;
  123. if( m_szInstanceName )
  124. delete [] m_szInstanceName;
  125. }
  126. BOOL
  127. CUDDISiteNode::ChildExists( const WCHAR *pwszName )
  128. {
  129. if( NULL == pwszName )
  130. {
  131. return FALSE;
  132. }
  133. return ( NULL == FindChild( pwszName ) ) ? FALSE : TRUE;
  134. }
  135. BOOL
  136. CUDDISiteNode::HasChildren()
  137. {
  138. if( 0 == m_mapConfig.size() && !CUDDIWebServerNode::IsWebServer( m_szName ) )
  139. return FALSE;
  140. return TRUE;
  141. }
  142. CUDDIServicesNode *
  143. CUDDISiteNode::GetStaticNode()
  144. {
  145. return m_pParent;
  146. }
  147. HRESULT
  148. CUDDISiteNode::GetData()
  149. {
  150. HRESULT hr = E_FAIL;
  151. try
  152. {
  153. m_mapConfig.clear();
  154. //
  155. // Determine if the OS that this site node is running on is Windows Server 2003 Standard or not.
  156. //
  157. hr = IsStandardServer( m_szName, &m_bStdSvr );
  158. if( FAILED(hr) )
  159. {
  160. THROW_UDDIEXCEPTION_ST( hr, IDS_DOT_NET_SERVER, g_hinst );
  161. }
  162. //
  163. // Initialize the map to the default settings
  164. //
  165. m_mapConfig[ UDDI_AUTHENTICATION_MODE ] = _T( "3" );
  166. m_mapConfig[ UDDI_REQUIRE_SSL ] = _T( "1" );
  167. m_mapConfig[ UDDI_ADMIN_GROUP ] = _T( "S-1-5-32-544" );
  168. m_mapConfig[ UDDI_COORDINATOR_GROUP ] = _T( "S-1-5-32-544" );
  169. m_mapConfig[ UDDI_PUBLISHER_GROUP ] = _T( "S-1-5-32-544" );
  170. m_mapConfig[ UDDI_USER_GROUP ] = _T( "S-1-5-32-545" );
  171. m_mapConfig[ UDDI_TICKET_TIMEOUT ] = _T( "60" );
  172. m_mapConfig[ UDDI_KEY_TIMEOUT ] = _T( "7" );
  173. m_mapConfig[ UDDI_KEY_RESET_DATE ] = _T( "" );
  174. m_mapConfig[ UDDI_KEY_AUTORESET ] = _T( "0" );
  175. m_mapConfig[ UDDI_DISCOVERY_URL ] = _T( "" );
  176. m_mapConfig[ UDDI_FIND_MAXROWS ] = _T( "1000" );
  177. //
  178. // Build up the default Site Name in case Site.Name is not specified
  179. //
  180. _TCHAR szBuffer[ 256 ];
  181. LoadString( g_hinst, IDS_DATABASE_SERVER_DEFAULT_SITE_NAME_PREFIX, szBuffer, ARRAYLEN( szBuffer ) - 1 );
  182. m_mapConfig[ UDDI_SITE_NAME ] = szBuffer;
  183. m_mapConfig[ UDDI_SITE_NAME ] += m_szName;
  184. //
  185. // Get the setup information
  186. //
  187. CUDDIRegistryKey rootkey( _T( "SOFTWARE\\Microsoft\\UDDI"), KEY_READ, m_szName );
  188. m_mapConfig[ UDDI_SETUP_LOCATION ] = rootkey.GetString( _T("InstallRoot"), _T("") );
  189. rootkey.Close();
  190. _TCHAR szValue[ 256 ];
  191. CUDDIRegistryKey setupkey( _T( "SOFTWARE\\Microsoft\\UDDI\\Setup"), KEY_READ, m_szName );
  192. m_mapConfig[ UDDI_SETUP_DB ] = _itot( setupkey.GetDWORD( _T("DBServer"), 0 ), szValue, 10 );
  193. m_mapConfig[ UDDI_SETUP_WEB ] = _itot( setupkey.GetDWORD( _T("WebServer"), 0 ), szValue, 10 );
  194. m_mapConfig[ UDDI_SETUP_ADMIN ] = _itot( setupkey.GetDWORD( _T("Admin"), 0 ), szValue, 10 );
  195. setupkey.Close();
  196. CUDDIRegistryKey dbkey( _T( "SOFTWARE\\Microsoft\\UDDI\\Setup\\DBServer"), KEY_READ, m_szName );
  197. m_mapConfig[ UDDI_SETUP_DATE ] = dbkey.GetString( _T("InstallDate"), _T("") );
  198. m_mapConfig[ UDDI_SETUP_LANGUAGE ] = dbkey.GetString( _T("ProductLanguage"), _T("") );
  199. m_mapConfig[ UDDI_SETUP_NAME ] = dbkey.GetString( _T("ProductName"), _T("") );
  200. m_mapConfig[ UDDI_SETUP_FRAMEWORK_VERSION ] = dbkey.GetString( _T("FrameworkVersion"), _T("") );
  201. m_mapConfig[ UDDI_SETUP_MANUFACTURER ] = dbkey.GetString( _T("Manufacturer"), _T("") );
  202. m_mapConfig[ UDDI_SETUP_VERSION ] = dbkey.GetString( _T("ProductVersion"), _T("") );
  203. dbkey.Close();
  204. //
  205. // Populate the configuration map from the database
  206. //
  207. hr = GetConfig( m_mapConfig, GetConnectionStringOLEDB() );
  208. if( FAILED(hr) )
  209. {
  210. THROW_UDDIEXCEPTION_ST( E_FAIL, IDS_DATABASE_SERVER_OLEDB_READ_FAILED, g_hinst );
  211. }
  212. else
  213. {
  214. //
  215. // Get our version information
  216. //
  217. if( FALSE == m_siteVersion.Parse( m_mapConfig[ UDDI_DBSCHEMA_VERSION ] ) )
  218. {
  219. _TCHAR szMessage[ 512 ];
  220. _TCHAR szMessageFormat[ 512 ];
  221. memset( szMessage, 0, 512 * sizeof( _TCHAR ) );
  222. memset( szMessageFormat, 0, 512 * sizeof( _TCHAR ) );
  223. LoadString( g_hinst, IDS_DATABASE_SERVER_DBSCHEMA_VERSION_READ_FAILED, szMessageFormat, ARRAYLEN( szMessageFormat ) );
  224. _sntprintf( szMessage, ARRAYLEN( szMessage ) - 1, szMessageFormat, m_szName );
  225. THROW_UDDIEXCEPTION( E_FAIL, szMessage );
  226. }
  227. WCHAR wszBuf[ 256 ];
  228. wszBuf[ 0 ] = 0x00;
  229. LoadString( g_hinst, IDS_UDDIMMC_UNSPECIFIED, wszBuf, ARRAYLEN( wszBuf ) );
  230. if( _T( "unspecified" ) == m_mapConfig[ UDDI_SITE_DESCRIPTION ] )
  231. {
  232. m_mapConfig[ UDDI_SITE_DESCRIPTION ] = wszBuf;
  233. }
  234. if( _T( "unspecified" ) == m_mapConfig[ UDDI_SITE_NAME ] )
  235. {
  236. m_mapConfig[ UDDI_SITE_NAME ] = wszBuf;
  237. }
  238. }
  239. }
  240. catch( CUDDIException &e )
  241. {
  242. // re-throw.
  243. throw e;
  244. }
  245. catch( ... )
  246. {
  247. if( FALSE == FAILED( hr ) )
  248. {
  249. hr = E_FAIL;
  250. }
  251. }
  252. return hr;
  253. }
  254. const _TCHAR *CUDDISiteNode::GetDisplayName( int nCol )
  255. {
  256. switch( nCol )
  257. {
  258. case 0:
  259. {
  260. m_strDisplayName = m_mapConfig[ UDDI_SITE_NAME ];
  261. break;
  262. }
  263. case 1:
  264. {
  265. m_strDisplayName = m_szName;
  266. break;
  267. }
  268. case 2:
  269. {
  270. if( 0 == _tcslen( m_szInstanceName ) )
  271. m_strDisplayName = DefaultInstanceDisplayName();
  272. else
  273. m_strDisplayName = m_szInstanceName;
  274. break;
  275. }
  276. case 3:
  277. {
  278. m_strDisplayName = m_mapConfig[ UDDI_SITE_DESCRIPTION ];
  279. break;
  280. }
  281. default:
  282. {
  283. m_strDisplayName = _T("");
  284. break;
  285. }
  286. }
  287. return m_strDisplayName.c_str();
  288. }
  289. HRESULT CUDDISiteNode::OnShow( IConsole *pConsole, BOOL bShow, HSCOPEITEM scopeitem )
  290. {
  291. HRESULT hr = S_OK;
  292. IHeaderCtrl *pHeaderCtrl = NULL;
  293. IResultData *pResultData = NULL;
  294. if( bShow )
  295. {
  296. hr = pConsole->QueryInterface( IID_IHeaderCtrl, (void **)&pHeaderCtrl );
  297. _ASSERT( SUCCEEDED(hr) );
  298. hr = pConsole->QueryInterface( IID_IResultData, (void **)&pResultData );
  299. _ASSERT( SUCCEEDED(hr) );
  300. //
  301. // Set the column headers in the results pane
  302. //
  303. WCHAR szColumnName[ 256 ];
  304. LoadStringW( g_hinst, IDS_WEBSERVER_COLUMN_NAME, szColumnName, ARRAYLEN( szColumnName ) );
  305. hr = pHeaderCtrl->InsertColumn( 0, szColumnName, 0, 150 );
  306. _ASSERT( S_OK == hr );
  307. LoadStringW( g_hinst, IDS_WEBSERVER_COLUMN_STATUS, szColumnName, ARRAYLEN( szColumnName ) );
  308. hr = pHeaderCtrl->InsertColumn( 1, szColumnName, 0, 100 );
  309. _ASSERT( S_OK == hr );
  310. pHeaderCtrl->Release();
  311. pResultData->Release();
  312. }
  313. return hr;
  314. }
  315. HRESULT CUDDISiteNode::OnExpand( IConsoleNameSpace *pConsoleNameSpace, IConsole *pConsole, HSCOPEITEM parent )
  316. {
  317. //
  318. // Cache static node's HSCOPEITEM for future use
  319. //
  320. // m_hParentHScopeItem = parent;
  321. if( !m_bExpanded )
  322. {
  323. // Load up the child nodes.
  324. LoadChildMap( m_mapConfig[ UDDI_SITE_WEBSERVERS ] );
  325. return AddChildrenToScopePane( pConsoleNameSpace, GetScopeItemValue() );
  326. }
  327. return S_OK;
  328. }
  329. HRESULT
  330. CUDDISiteNode::RemoveChildren( IConsoleNameSpace *pNS )
  331. {
  332. if( NULL == pNS )
  333. {
  334. return E_INVALIDARG;
  335. }
  336. for( CUDDIWebServerNodeMap::iterator iter = m_mapChildren.begin();
  337. iter != m_mapChildren.end(); iter++ )
  338. {
  339. CUDDIWebServerNode *pWSNode = (CUDDIWebServerNode *)iter->second;
  340. HSCOPEITEM hsi = pWSNode->GetScopeItemValue();
  341. pNS->DeleteItem( hsi, TRUE );
  342. }
  343. ClearChildMap();
  344. return S_OK;
  345. }
  346. HRESULT
  347. CUDDISiteNode::OnPropertyChange( IConsole *pConsole, CComponent *pComponent )
  348. {
  349. HRESULT hr = S_FALSE;
  350. try
  351. {
  352. hr = SaveData();
  353. if( S_OK != hr )
  354. return hr;
  355. hr = GetData();
  356. if( S_OK != hr )
  357. return hr;
  358. }
  359. catch( CUDDIException& e )
  360. {
  361. TCHAR szTitle[ 256 ];
  362. LoadString( g_hinst, IDS_DATABASE_SERVER_SELECT_ERROR_TITLE, szTitle, ARRAYLEN( szTitle ) );
  363. HWND hwnd;
  364. pConsole->GetMainWindow( &hwnd );
  365. MessageBox( hwnd, e.GetEntireError().c_str(), szTitle, MB_ICONERROR | MB_OK | MB_APPLMODAL );
  366. return E_FAIL;
  367. }
  368. catch(...)
  369. {
  370. return E_FAIL;
  371. }
  372. //
  373. // Call IConsole::UpdateAllViews to redraw the item
  374. // in all views. We need a data object because of the
  375. // way UpdateAllViews is implemented, and because
  376. // MMCN_PROPERTY_CHANGE doesn't give us one
  377. //
  378. hr = pConsole->UpdateAllViews( NULL, GetScopeItemValue(), 0 );
  379. return hr;
  380. }
  381. HRESULT CUDDISiteNode::OnShowContextHelp(IDisplayHelp *pDisplayHelp, LPOLESTR helpFile)
  382. {
  383. if( ( NULL == pDisplayHelp ) || ( NULL == helpFile ) )
  384. {
  385. return E_INVALIDARG;
  386. }
  387. wstring wstrHelpInfo = helpFile;
  388. wstrHelpInfo += g_wszUddiSiteNodeHelp;
  389. LPOLESTR pszTopic = static_cast<LPOLESTR>(CoTaskMemAlloc((wstrHelpInfo.length() + 1) * sizeof(WCHAR)));
  390. if( NULL == pszTopic )
  391. {
  392. return E_OUTOFMEMORY;
  393. }
  394. wcsncpy( pszTopic, wstrHelpInfo.c_str(), wstrHelpInfo.length() );
  395. pszTopic[ wstrHelpInfo.length() ] = NULL;
  396. return pDisplayHelp->ShowTopic( pszTopic );
  397. }
  398. HRESULT CUDDISiteNode::OnSelect( CComponent *pComponent, IConsole *pConsole, BOOL bScope, BOOL bSelect )
  399. {
  400. if( ( NULL == pComponent ) ||( NULL == pConsole ) )
  401. {
  402. return E_INVALIDARG;
  403. }
  404. HRESULT hr = E_FAIL;
  405. if( bSelect )
  406. {
  407. //
  408. // Enable refresh, and delete verbs
  409. //
  410. IConsoleVerb *pConsoleVerb = NULL;
  411. hr = pConsole->QueryConsoleVerb( &pConsoleVerb );
  412. if( FAILED(hr) )
  413. {
  414. return hr;
  415. }
  416. hr = pConsoleVerb->SetVerbState( MMC_VERB_REFRESH, ENABLED, TRUE );
  417. if( !IsExtension() )
  418. {
  419. hr = pConsoleVerb->SetVerbState( MMC_VERB_DELETE, ENABLED, TRUE );
  420. _ASSERT( S_OK == hr );
  421. }
  422. hr = pConsoleVerb->SetVerbState( MMC_VERB_OPEN, ENABLED, TRUE );
  423. if( FAILED(hr) )
  424. {
  425. pConsoleVerb->Release();
  426. return hr;
  427. }
  428. //
  429. // Can't get to properties (via the standard methods) unless
  430. // we tell MMC to display the Properties menu item and
  431. // toolbar button, this will give the user a visual cue that
  432. // there's "something" to do
  433. //
  434. hr = pConsoleVerb->SetVerbState( MMC_VERB_PROPERTIES, ENABLED, TRUE );
  435. //
  436. // Also set MMC_VERB_PROPERTIES as the default verb
  437. //
  438. hr = pConsoleVerb->SetDefaultVerb( MMC_VERB_PROPERTIES );
  439. pConsoleVerb->Release();
  440. }
  441. return S_FALSE;
  442. }
  443. BOOL CALLBACK CUDDISiteNode::GeneralDialogProc( HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam )
  444. {
  445. static CUDDISiteNode *pDatabaseServer = NULL;
  446. switch( uMsg )
  447. {
  448. case WM_INITDIALOG:
  449. {
  450. //
  451. // Catch the "this" pointer so we can actually operate on the object
  452. //
  453. pDatabaseServer = reinterpret_cast<CUDDISiteNode *>(reinterpret_cast<PROPSHEETPAGE *>(lParam)->lParam);
  454. CConfigMap& m_mapProperties = pDatabaseServer->m_mapConfig;
  455. SetDlgItemText( hwndDlg, IDC_GENERAL_SITE_TXT_INSTALL_DATE, LocalizedDate( m_mapProperties[ UDDI_SETUP_DATE ] ).c_str() );
  456. SetDlgItemText( hwndDlg, IDC_GENERAL_SITE_TXT_UDDI_LANGUAGE, m_mapProperties[ UDDI_SETUP_LANGUAGE ].c_str() );
  457. SetDlgItemText( hwndDlg, IDC_GENERAL_SITE_TXT_DISPLAYNAME, m_mapProperties[ UDDI_SITE_NAME ].c_str() );
  458. SetDlgItemText( hwndDlg, IDC_GENERAL_SITE_TXT_DESCRIPTION, m_mapProperties[ UDDI_SITE_DESCRIPTION ].c_str() );
  459. SetDlgItemText( hwndDlg, IDC_GENERAL_SITE_TXT_PROVIDER_KEY, m_mapProperties[ UDDI_SITE_KEY ].c_str() );
  460. SetDlgItemText( hwndDlg, IDC_GENERAL_SITE_TXT_FRAMEWORK_VERSION, m_mapProperties[ UDDI_SETUP_FRAMEWORK_VERSION ].c_str() );
  461. SetDlgItemText( hwndDlg, IDC_GENERAL_SITE_TXT_UDDI_VERSION, m_mapProperties[ UDDI_SETUP_VERSION ].c_str() );
  462. SetDlgItemText( hwndDlg, IDC_GENERAL_SITE_TXT_INSTALL_LOCATION, m_mapProperties[ UDDI_SETUP_LOCATION ].c_str() );
  463. _TCHAR szServiceName[ 256 ];
  464. if( _T("1") == m_mapProperties[ UDDI_SETUP_WEB ] )
  465. {
  466. ::LoadString( g_hinst, IDS_WEBSERVER_COMPONENT_DESCRIPTION, szServiceName, ARRAYLEN( szServiceName ) );
  467. ListBox_AddString( GetDlgItem( hwndDlg, IDC_GENERAL_SITE_LIST_SERVICES ), szServiceName );
  468. }
  469. if( _T("1") == m_mapProperties[ UDDI_SETUP_DB ] )
  470. {
  471. ::LoadString( g_hinst, IDS_DATABASE_SERVER_COMPONENT_DESCRIPTION, szServiceName, ARRAYLEN( szServiceName ) );
  472. ListBox_AddString( GetDlgItem( hwndDlg, IDC_GENERAL_SITE_LIST_SERVICES ), szServiceName );
  473. }
  474. if( _T("1") == m_mapProperties[ UDDI_SETUP_ADMIN ] )
  475. {
  476. ::LoadString( g_hinst, IDS_UDDIMMC_COMPONENT_DESCRIPTION, szServiceName, ARRAYLEN( szServiceName ) );
  477. ListBox_AddString( GetDlgItem( hwndDlg, IDC_GENERAL_SITE_LIST_SERVICES ), szServiceName );
  478. }
  479. }
  480. break;
  481. case WM_NOTIFY:
  482. if( PSN_HELP == ((NMHDR *) lParam)->code )
  483. {
  484. wstring strHelp( pDatabaseServer->GetHelpFile() );
  485. strHelp += g_wszUddiSiteGeneralPageHelp;
  486. ::HtmlHelp( hwndDlg, strHelp.c_str(), HH_DISPLAY_TOPIC, NULL );
  487. }
  488. break;
  489. case WM_HELP:
  490. {
  491. wstring strHelp( pDatabaseServer->GetHelpFile() );
  492. strHelp += g_wszUddiSiteGeneralPageHelp;
  493. ::HtmlHelp( hwndDlg, strHelp.c_str(), HH_DISPLAY_TOPIC, NULL );
  494. }
  495. break;
  496. }
  497. return FALSE;
  498. }
  499. void SplitGroupName( const PTCHAR szGroupName, StringVector& names )
  500. {
  501. //
  502. // Example: CREEVES\\Administrators
  503. //
  504. PTCHAR begin = szGroupName;
  505. PTCHAR end = begin;
  506. while( *end )
  507. {
  508. if( _T('\\') == *end )
  509. {
  510. TCHAR szNameTemp[ 256 ];
  511. _tcsncpy( szNameTemp, begin, end - begin );
  512. szNameTemp[ end - begin ] = NULL;
  513. names.push_back( szNameTemp );
  514. begin = end + 1;
  515. }
  516. end++;
  517. }
  518. //
  519. // Get the last one
  520. //
  521. if( begin != end )
  522. {
  523. names.push_back( begin );
  524. }
  525. }
  526. struct RolesData
  527. {
  528. RolesData( CUDDISiteNode* pServer )
  529. : pDBServer( pServer )
  530. , bAdminChanged( false )
  531. , bCoordinatorChanged( false )
  532. , bPublishChanged( false )
  533. , bUserChanged( false )
  534. , bInitialized( false ){}
  535. CUDDISiteNode* pDBServer;
  536. bool bAdminChanged;
  537. bool bCoordinatorChanged;
  538. bool bPublishChanged;
  539. bool bUserChanged;
  540. bool bInitialized;
  541. //
  542. // These members get updated when the user picks a new role/group
  543. //
  544. tstring tsNewAdminSID;
  545. tstring tsNewCoordinatorSID;
  546. tstring tsNewPublisherSID;
  547. tstring tsNewUserSID;
  548. };
  549. tstring SidFromGroupName( const tstring& strGroupName, const LPCTSTR szTargetComputer )
  550. {
  551. BYTE sid[ 1024 ];
  552. TCHAR domain[ 1024 ];
  553. LPTSTR szSidBuf = NULL;
  554. DWORD cbSID = ARRAYLEN( sid );
  555. DWORD cbDomain = ARRAYLEN( domain );
  556. SID_NAME_USE puse;
  557. tstring strSid = _T("");
  558. try
  559. {
  560. BOOL bRet = LookupAccountName(
  561. NULL,
  562. strGroupName.c_str(),
  563. sid,
  564. &cbSID,
  565. domain,
  566. &cbDomain,
  567. &puse );
  568. if( !bRet )
  569. UDDIVERIFYAPI();// bRet, _T("The attempt to lookup the security identifer failed" ) );
  570. bRet = ConvertSidToStringSid( sid, &szSidBuf );
  571. UDDIASSERT( bRet );
  572. strSid = szSidBuf;
  573. if( szSidBuf )
  574. LocalFree( szSidBuf );
  575. }
  576. catch( CUDDIException& e )
  577. {
  578. MessageBox( NULL, e.GetEntireError().c_str(), _T("Security name conversion failed" ), MB_OK );
  579. }
  580. return strSid;
  581. }
  582. tstring GroupNameFromSid( const tstring& strGroupSid, const tstring& strTargetComputer )
  583. {
  584. PSID lpSid = NULL;
  585. TCHAR domain[ 1024 ];
  586. TCHAR name[ 1024 ];
  587. DWORD cbDomain = ( sizeof domain / sizeof domain[0] );
  588. DWORD cbName = ( sizeof name / sizeof name[0] );
  589. SID_NAME_USE puse;
  590. tstring strGroupName = _T("");
  591. BOOL bRet = ConvertStringSidToSid( strGroupSid.c_str(), &lpSid );
  592. UDDIVERIFY( bRet, _T("Unable to convert the group security identifer into a textual name." ) );
  593. bRet = LookupAccountSid( strTargetComputer.c_str(), lpSid, name, &cbName, domain, &cbDomain, &puse );
  594. if( !bRet )
  595. {
  596. if( lpSid )
  597. LocalFree( lpSid );
  598. //
  599. // If we can't look up the account, we can't continue.
  600. //
  601. THROW_UDDIEXCEPTION_ST( GetLastError(), IDS_ACCOUNT_GROUP_ERROR, g_hinst );
  602. }
  603. strGroupName = domain;
  604. strGroupName += _T("\\");
  605. strGroupName += name;
  606. if( lpSid )
  607. LocalFree( lpSid );
  608. return strGroupName;
  609. }
  610. BOOL CALLBACK CUDDISiteNode::RolesDialogProc( HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam )
  611. {
  612. switch( uMsg )
  613. {
  614. case WM_INITDIALOG:
  615. {
  616. //
  617. // Save the window data into the user data reference
  618. //
  619. CUDDISiteNode* pDBServer = reinterpret_cast<CUDDISiteNode *>(reinterpret_cast<PROPSHEETPAGE *>(lParam)->lParam);
  620. RolesData* pdata = new RolesData( pDBServer );
  621. SetWindowLongPtr( hwndDlg, GWLP_USERDATA, reinterpret_cast<LONG_PTR>( pdata ) );
  622. //
  623. // Admin group.
  624. //
  625. try
  626. {
  627. tstring strAdminGroup = GroupNameFromSid( pDBServer->m_mapConfig[ UDDI_ADMIN_GROUP ], pDBServer->m_szName );
  628. SetDlgItemText( hwndDlg, IDC_ROLES_EDIT_ADMIN_GROUP_NAME, strAdminGroup.c_str() );
  629. }
  630. catch( ... )
  631. {
  632. SetDlgItemText( hwndDlg, IDC_ROLES_EDIT_ADMIN_GROUP_NAME, pDBServer->m_mapConfig[ UDDI_ADMIN_GROUP ].c_str() );
  633. }
  634. //
  635. // Coordinator Group.
  636. //
  637. try
  638. {
  639. tstring strCoordinatorGroup = GroupNameFromSid( pDBServer->m_mapConfig[ UDDI_COORDINATOR_GROUP ], pDBServer->m_szName );
  640. SetDlgItemText( hwndDlg, IDC_ROLES_EDIT_COORDINATOR_GROUP_NAME, strCoordinatorGroup.c_str() );
  641. }
  642. catch( ... )
  643. {
  644. SetDlgItemText( hwndDlg, IDC_ROLES_EDIT_COORDINATOR_GROUP_NAME, pDBServer->m_mapConfig[ UDDI_ADMIN_GROUP ].c_str() );
  645. }
  646. //
  647. // Publisher Group.
  648. //
  649. try
  650. {
  651. tstring strPublisherGroup = GroupNameFromSid( pDBServer->m_mapConfig[ UDDI_PUBLISHER_GROUP ], pDBServer->m_szName );
  652. SetDlgItemText( hwndDlg, IDC_ROLES_EDIT_PUBLISHER_GROUP_NAME, strPublisherGroup.c_str() );
  653. }
  654. catch( ... )
  655. {
  656. SetDlgItemText( hwndDlg, IDC_ROLES_EDIT_PUBLISHER_GROUP_NAME, pDBServer->m_mapConfig[ UDDI_ADMIN_GROUP ].c_str() );
  657. }
  658. //
  659. // User Group.
  660. //
  661. try
  662. {
  663. tstring strUserGroup = GroupNameFromSid( pDBServer->m_mapConfig[ UDDI_USER_GROUP ], pDBServer->m_szName );
  664. SetDlgItemText( hwndDlg, IDC_ROLES_EDIT_USER_GROUP_NAME, strUserGroup.c_str() );
  665. }
  666. catch( ... )
  667. {
  668. SetDlgItemText( hwndDlg, IDC_ROLES_EDIT_USER_GROUP_NAME, pDBServer->m_mapConfig[ UDDI_USER_GROUP ].c_str() );
  669. }
  670. pdata->bInitialized = true;
  671. }
  672. case WM_COMMAND:
  673. {
  674. RolesData* pdata = reinterpret_cast<RolesData*>( GetWindowLongPtr( hwndDlg, GWLP_USERDATA ) );
  675. if( BN_CLICKED == HIWORD(wParam) )
  676. {
  677. try
  678. {
  679. TCHAR szGroupSID[ 1024 ];
  680. if( IDC_ROLES_BTN_ADMINISTRATOR_SELECT == LOWORD(wParam) )
  681. {
  682. if( ObjectPicker( hwndDlg, OT_GroupSID, szGroupSID, ARRAYLEN( szGroupSID ), pdata->pDBServer->m_szName ) )
  683. {
  684. try
  685. {
  686. tstring tstr = GroupNameFromSid( szGroupSID, pdata->pDBServer->m_szName );
  687. SetDlgItemText( hwndDlg, IDC_ROLES_EDIT_ADMIN_GROUP_NAME, tstr.c_str() );
  688. }
  689. catch( ... )
  690. {
  691. SetDlgItemText( hwndDlg, IDC_ROLES_EDIT_ADMIN_GROUP_NAME, szGroupSID );
  692. }
  693. pdata->bAdminChanged = true;
  694. pdata->tsNewAdminSID = szGroupSID;
  695. SendMessage( GetParent(hwndDlg), PSM_CHANGED, (WPARAM) hwndDlg, 0 );
  696. }
  697. }
  698. else if( IDC_ROLES_BTN_COORDINATOR_SELECT == LOWORD(wParam) )
  699. {
  700. if( ObjectPicker( hwndDlg, OT_GroupSID, szGroupSID, ARRAYLEN( szGroupSID ), pdata->pDBServer->m_szName ) )
  701. {
  702. try
  703. {
  704. tstring tstr = GroupNameFromSid( szGroupSID, pdata->pDBServer->m_szName );
  705. SetDlgItemText( hwndDlg, IDC_ROLES_EDIT_COORDINATOR_GROUP_NAME, tstr.c_str() );
  706. }
  707. catch( ... )
  708. {
  709. SetDlgItemText( hwndDlg, IDC_ROLES_EDIT_COORDINATOR_GROUP_NAME, szGroupSID );
  710. }
  711. pdata->bCoordinatorChanged = true;
  712. pdata->tsNewCoordinatorSID = szGroupSID;
  713. SendMessage( GetParent(hwndDlg), PSM_CHANGED, (WPARAM) hwndDlg, 0 );
  714. }
  715. }
  716. else if( IDC_ROLES_BTN_PUBLISHER_SELECT == LOWORD(wParam) )
  717. {
  718. if( ObjectPicker( hwndDlg, OT_GroupSID, szGroupSID, ARRAYLEN( szGroupSID ), pdata->pDBServer->m_szName ) )
  719. {
  720. try
  721. {
  722. tstring tstr = GroupNameFromSid( szGroupSID, pdata->pDBServer->m_szName );
  723. SetDlgItemText( hwndDlg, IDC_ROLES_EDIT_PUBLISHER_GROUP_NAME, tstr.c_str() );
  724. }
  725. catch( ... )
  726. {
  727. SetDlgItemText( hwndDlg, IDC_ROLES_EDIT_PUBLISHER_GROUP_NAME, szGroupSID );
  728. }
  729. pdata->bPublishChanged = true;
  730. pdata->tsNewPublisherSID = szGroupSID;
  731. SendMessage( GetParent(hwndDlg), PSM_CHANGED, (WPARAM) hwndDlg, 0 );
  732. }
  733. }
  734. else if( IDC_ROLES_BTN_USER_SELECT == LOWORD(wParam) )
  735. {
  736. if( ObjectPicker( hwndDlg, OT_GroupSID, szGroupSID, ARRAYLEN( szGroupSID ), pdata->pDBServer->m_szName ) )
  737. {
  738. try
  739. {
  740. tstring tstr = GroupNameFromSid( szGroupSID, pdata->pDBServer->m_szName );
  741. SetDlgItemText( hwndDlg, IDC_ROLES_EDIT_USER_GROUP_NAME, tstr.c_str() );
  742. }
  743. catch( ... )
  744. {
  745. SetDlgItemText( hwndDlg, IDC_ROLES_EDIT_USER_GROUP_NAME, szGroupSID );
  746. }
  747. pdata->bUserChanged = true;
  748. pdata->tsNewUserSID = szGroupSID;
  749. SendMessage( GetParent(hwndDlg), PSM_CHANGED, (WPARAM) hwndDlg, 0 );
  750. }
  751. }
  752. break;
  753. }
  754. catch( CUDDIException& exception )
  755. {
  756. _TCHAR szTitle[256];
  757. ::LoadString( g_hinst, IDS_UDDIMMC_SNAPINNAME, szTitle, ARRAYLEN( szTitle ) - 1 );
  758. MessageBox( hwndDlg, (LPCTSTR) exception, szTitle, MB_ICONERROR | MB_OK | MB_APPLMODAL );
  759. break;
  760. }
  761. catch( ... )
  762. {
  763. TCHAR wszTitle[ 128 ];
  764. TCHAR wszMsg[ 256 ];
  765. LoadString( g_hinst, IDS_GENERAL_EXCEPTION_TITLE, wszTitle, 128 );
  766. LoadString( g_hinst, IDS_GENERAL_EXCEPTION, wszMsg, 256 );
  767. MessageBox( hwndDlg, wszMsg, wszTitle, MB_OK );
  768. break;
  769. }
  770. }
  771. else if( EN_CHANGE == HIWORD(wParam) )
  772. {
  773. if( pdata->bInitialized )
  774. {
  775. switch( LOWORD(wParam) )
  776. {
  777. case IDC_ROLES_EDIT_USER_GROUP_NAME:
  778. pdata->bUserChanged = true;
  779. SendMessage( GetParent(hwndDlg), PSM_CHANGED, (WPARAM) hwndDlg, 0 );
  780. break;
  781. case IDC_ROLES_EDIT_PUBLISHER_GROUP_NAME:
  782. pdata->bPublishChanged = true;
  783. SendMessage( GetParent(hwndDlg), PSM_CHANGED, (WPARAM) hwndDlg, 0 );
  784. break;
  785. case IDC_ROLES_EDIT_COORDINATOR_GROUP_NAME:
  786. pdata->bCoordinatorChanged = true;
  787. SendMessage( GetParent(hwndDlg), PSM_CHANGED, (WPARAM) hwndDlg, 0 );
  788. break;
  789. case IDC_ROLES_EDIT_ADMIN_GROUP_NAME:
  790. pdata->bAdminChanged = true;
  791. SendMessage( GetParent(hwndDlg), PSM_CHANGED, (WPARAM) hwndDlg, 0 );
  792. break;
  793. }
  794. }
  795. }
  796. break;
  797. }
  798. case WM_DESTROY:
  799. {
  800. delete reinterpret_cast<RolesData*>( GetWindowLongPtr( hwndDlg, GWLP_USERDATA ) );
  801. break;
  802. }
  803. case WM_HELP:
  804. {
  805. RolesData* pdata = reinterpret_cast<RolesData*>( GetWindowLongPtr( hwndDlg, GWLP_USERDATA ) );
  806. wstring strHelp( pdata->pDBServer->GetHelpFile() );
  807. strHelp += g_wszUddiRolesPageHelp;
  808. ::HtmlHelp( hwndDlg, strHelp.c_str(), HH_DISPLAY_TOPIC, NULL );
  809. break;
  810. }
  811. case WM_NOTIFY:
  812. switch( ((NMHDR *) lParam)->code )
  813. {
  814. case PSN_APPLY:
  815. {
  816. RolesData* pdata = reinterpret_cast<RolesData*>( GetWindowLongPtr( hwndDlg, GWLP_USERDATA ) );
  817. CUDDISiteNode* pDBServer = pdata->pDBServer;
  818. if( pdata->bAdminChanged )
  819. {
  820. pDBServer->m_mapChanges[ UDDI_ADMIN_GROUP ] = pdata->tsNewAdminSID;
  821. pdata->bAdminChanged = false;
  822. }
  823. if( pdata->bCoordinatorChanged )
  824. {
  825. pDBServer->m_mapChanges[ UDDI_COORDINATOR_GROUP ] = pdata->tsNewCoordinatorSID;
  826. pdata->bCoordinatorChanged = false;
  827. }
  828. if( pdata->bPublishChanged )
  829. {
  830. pDBServer->m_mapChanges[ UDDI_PUBLISHER_GROUP ] = pdata->tsNewPublisherSID;
  831. pdata->bPublishChanged = false;
  832. }
  833. if( pdata->bUserChanged )
  834. {
  835. pDBServer->m_mapChanges[ UDDI_USER_GROUP ] = pdata->tsNewUserSID;
  836. pdata->bUserChanged = false;
  837. }
  838. //
  839. // Ask MMC to send us a message (on the main thread) so
  840. // we know the Apply button was clicked.
  841. //
  842. HRESULT hr = MMCPropertyChangeNotify( pDBServer->m_ppHandle, reinterpret_cast<LONG_PTR>(pDBServer) );
  843. _ASSERT( SUCCEEDED(hr) );
  844. return PSNRET_NOERROR;
  845. }
  846. case PSN_HELP:
  847. {
  848. RolesData* pdata = reinterpret_cast<RolesData*>( GetWindowLongPtr( hwndDlg, GWLP_USERDATA ) );
  849. wstring strHelp( pdata->pDBServer->GetHelpFile() );
  850. strHelp += g_wszUddiRolesPageHelp;
  851. ::HtmlHelp( hwndDlg, strHelp.c_str(), HH_DISPLAY_TOPIC, NULL );
  852. break;
  853. }
  854. break;
  855. }
  856. }
  857. return FALSE;
  858. }
  859. struct SecurityData
  860. {
  861. SecurityData( CUDDISiteNode* pDBServer )
  862. : pServer( pDBServer )
  863. , bModeChanged( false )
  864. , bSSLChanged( false )
  865. , bKeyTimeoutChanged( false )
  866. , bTicketTimeoutChanged( false )
  867. , bAutoKeyResetChanged( false )
  868. , bAutoKeyReset( false )
  869. , nKeyTimeout( 0 )
  870. , nTicketTimeout( 0 )
  871. {
  872. if( NULL != pServer )
  873. {
  874. bAutoKeyReset = ( 0 != _tcscmp( _T("0"), pServer->GetConfigMap()[ UDDI_KEY_AUTORESET ].c_str() ) );
  875. nKeyTimeout = _tstoi( pDBServer->GetConfigMap()[ UDDI_KEY_TIMEOUT ].c_str() );
  876. nTicketTimeout = _tstoi( pDBServer->GetConfigMap()[ UDDI_TICKET_TIMEOUT ].c_str() );
  877. }
  878. }
  879. bool bModeChanged;
  880. bool bSSLChanged;
  881. bool bKeyTimeoutChanged;
  882. bool bTicketTimeoutChanged;
  883. bool bAutoKeyResetChanged;
  884. bool bAutoKeyReset;
  885. int nKeyTimeout;
  886. int nTicketTimeout;
  887. CUDDISiteNode* pServer;
  888. };
  889. BOOL CALLBACK CUDDISiteNode::SecurityDialogProc( HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam )
  890. {
  891. switch( uMsg )
  892. {
  893. case WM_INITDIALOG:
  894. {
  895. //
  896. // Catch the "this" pointer so we can actually operate on the object
  897. //
  898. CUDDISiteNode* pDBServer = reinterpret_cast<CUDDISiteNode *>(reinterpret_cast<PROPSHEETPAGE *>(lParam)->lParam);
  899. SecurityData* pdata = new SecurityData( pDBServer );
  900. SetWindowLongPtr( hwndDlg, GWLP_USERDATA, reinterpret_cast<LONG_PTR>( pdata ) );
  901. _TCHAR* pszMode = (_TCHAR*) pDBServer->m_mapConfig[ UDDI_AUTHENTICATION_MODE ].c_str();
  902. int nAuthenticationMode = _ttoi( pszMode );
  903. switch( nAuthenticationMode )
  904. {
  905. case 1:
  906. SendDlgItemMessage( hwndDlg, IDC_SECURITY_RADIO_AUTHENTICATION_UDDI, BM_SETCHECK, BST_CHECKED, NULL );
  907. break;
  908. case 2:
  909. case 6:
  910. SendDlgItemMessage( hwndDlg, IDC_SECURITY_RADIO_AUTHENTICATION_WINDOWS, BM_SETCHECK, BST_CHECKED, NULL );
  911. EnableWindow( GetDlgItem( hwndDlg, IDC_SECURITY_CHECK_AUTHENTICATED_READS ), TRUE );
  912. break;
  913. case 3:
  914. default:
  915. SendDlgItemMessage( hwndDlg, IDC_SECURITY_RADIO_AUTHENTICATION_BOTH, BM_SETCHECK, BST_CHECKED, NULL );
  916. break;
  917. }
  918. if( 4 & nAuthenticationMode )
  919. {
  920. SendDlgItemMessage( hwndDlg, IDC_SECURITY_CHECK_AUTHENTICATED_READS, BM_SETCHECK, BST_CHECKED, NULL );
  921. }
  922. //
  923. // Setup the HTTPS requirement setting
  924. //
  925. _TCHAR* pszHttps = (_TCHAR*) pDBServer->m_mapConfig[ UDDI_REQUIRE_SSL ].c_str();
  926. int nhttps = _ttoi( pszHttps );
  927. if( 0 == nhttps )
  928. {
  929. SendDlgItemMessage( hwndDlg, IDC_SECURITY_CHECK_REQUIRE_SSL, BM_SETCHECK, BST_UNCHECKED, NULL );
  930. }
  931. else
  932. {
  933. SendDlgItemMessage( hwndDlg, IDC_SECURITY_CHECK_REQUIRE_SSL, BM_SETCHECK, BST_CHECKED, NULL );
  934. }
  935. }
  936. break;
  937. case WM_HELP:
  938. {
  939. SecurityData* pdata = reinterpret_cast<SecurityData*>( GetWindowLongPtr( hwndDlg, GWLP_USERDATA ) ) ;
  940. wstring strHelp( pdata->pServer->GetHelpFile() );
  941. strHelp += g_wszUddiSecurityPageHelp;
  942. ::HtmlHelp( hwndDlg, strHelp.c_str(), HH_DISPLAY_TOPIC, NULL );
  943. }
  944. break;
  945. case WM_COMMAND:
  946. {
  947. SecurityData* pdata = reinterpret_cast<SecurityData*>( GetWindowLongPtr( hwndDlg, GWLP_USERDATA ) );
  948. CUDDISiteNode* pDBServer = pdata->pServer;
  949. //
  950. // Set the state of the Authenticated Reads check box
  951. //
  952. LRESULT nChecked = SendDlgItemMessage( hwndDlg, IDC_SECURITY_RADIO_AUTHENTICATION_WINDOWS, BM_GETCHECK, NULL, NULL );
  953. EnableWindow( GetDlgItem( hwndDlg, IDC_SECURITY_CHECK_AUTHENTICATED_READS ), BST_CHECKED == nChecked ? TRUE : FALSE );
  954. if( !nChecked )
  955. {
  956. SendDlgItemMessage( hwndDlg, IDC_SECURITY_CHECK_AUTHENTICATED_READS, BM_SETCHECK, FALSE, NULL );
  957. }
  958. if( IDC_CRYPTOGRAPHY_BTN_CHANGE == LOWORD(wParam) )
  959. {
  960. INT_PTR nResult = DialogBoxParam( g_hinst, MAKEINTRESOURCE( IDD_CRYPTOGRAPHY ), GetParent(hwndDlg), CryptographyDialogProc, (LPARAM) pdata );
  961. if( nResult )
  962. {
  963. SendMessage( GetParent(hwndDlg), PSM_CHANGED, (WPARAM)hwndDlg, 0 );
  964. }
  965. }
  966. else if( BN_CLICKED == HIWORD(wParam) &&
  967. ( IDC_SECURITY_RADIO_AUTHENTICATION_BOTH == LOWORD(wParam) ||
  968. IDC_SECURITY_RADIO_AUTHENTICATION_UDDI == LOWORD(wParam) ||
  969. IDC_SECURITY_RADIO_AUTHENTICATION_WINDOWS == LOWORD(wParam) ||
  970. IDC_SECURITY_CHECK_AUTHENTICATED_READS == LOWORD(wParam) ) )
  971. {
  972. pdata->bModeChanged = true;
  973. SendMessage( GetParent(hwndDlg), PSM_CHANGED, (WPARAM)hwndDlg, 0 );
  974. }
  975. else if( BN_CLICKED == HIWORD(wParam) && IDC_SECURITY_CHECK_REQUIRE_SSL == LOWORD(wParam) )
  976. {
  977. pdata->bSSLChanged = true;
  978. SendMessage( GetParent(hwndDlg), PSM_CHANGED, (WPARAM)hwndDlg, 0 );
  979. }
  980. }
  981. break;
  982. case WM_DESTROY:
  983. {
  984. SecurityData* pdata = reinterpret_cast<SecurityData*>( GetWindowLongPtr( hwndDlg, GWLP_USERDATA ) );
  985. CUDDISiteNode* pDBServer = pdata->pServer;
  986. delete pdata;
  987. //
  988. // Tell MMC that we're done with the property sheet (we got this
  989. // handle in CreatePropertyPages
  990. //
  991. MMCFreeNotifyHandle( pDBServer->m_ppHandle );
  992. }
  993. break;
  994. case WM_NOTIFY:
  995. {
  996. switch( ((NMHDR *) lParam)->code )
  997. {
  998. case PSN_APPLY:
  999. {
  1000. SecurityData* pdata = reinterpret_cast<SecurityData*>( GetWindowLongPtr( hwndDlg, GWLP_USERDATA ) );
  1001. CUDDISiteNode* pDBServer = pdata->pServer;
  1002. if( pdata->bAutoKeyResetChanged )
  1003. {
  1004. pDBServer->m_mapChanges[ UDDI_KEY_AUTORESET ] = pdata->bAutoKeyReset ? _T("1") : _T("0");
  1005. }
  1006. if( pdata->bKeyTimeoutChanged )
  1007. {
  1008. _TCHAR szValue[ 10 ];
  1009. pDBServer->m_mapChanges[ UDDI_KEY_TIMEOUT ] = _itot( pdata->nKeyTimeout, szValue, 10 );
  1010. }
  1011. if( pdata->bTicketTimeoutChanged )
  1012. {
  1013. _TCHAR szValue[ 10 ];
  1014. pDBServer->m_mapChanges[ UDDI_TICKET_TIMEOUT ] = _itot( pdata->nTicketTimeout, szValue, 10 );
  1015. }
  1016. if( pdata->bModeChanged )
  1017. {
  1018. if( BST_CHECKED == SendDlgItemMessage( hwndDlg, IDC_SECURITY_RADIO_AUTHENTICATION_BOTH, BM_GETCHECK, 0, 0 ) )
  1019. {
  1020. pDBServer->m_mapChanges[ UDDI_AUTHENTICATION_MODE ] = _T("3");
  1021. }
  1022. else if( BST_CHECKED == SendDlgItemMessage( hwndDlg, IDC_SECURITY_RADIO_AUTHENTICATION_UDDI, BM_GETCHECK, 0, 0 ) )
  1023. {
  1024. pDBServer->m_mapChanges[ UDDI_AUTHENTICATION_MODE ] = _T("1");
  1025. }
  1026. else if( BST_CHECKED == SendDlgItemMessage( hwndDlg, IDC_SECURITY_RADIO_AUTHENTICATION_WINDOWS, BM_GETCHECK, 0, 0 ) )
  1027. {
  1028. if( BST_CHECKED == SendDlgItemMessage( hwndDlg, IDC_SECURITY_CHECK_AUTHENTICATED_READS, BM_GETCHECK, 0, 0 ) )
  1029. pDBServer->m_mapChanges[ UDDI_AUTHENTICATION_MODE ] = _T("6");
  1030. else
  1031. pDBServer->m_mapChanges[ UDDI_AUTHENTICATION_MODE ] = _T("2");
  1032. }
  1033. }
  1034. if( pdata->bSSLChanged )
  1035. {
  1036. LRESULT nChecked = SendDlgItemMessage( hwndDlg, IDC_SECURITY_CHECK_REQUIRE_SSL, BM_GETCHECK, NULL, NULL );
  1037. pDBServer->m_mapChanges[ UDDI_REQUIRE_SSL ] = ( BST_CHECKED == nChecked ? _T("1") : _T("0") );
  1038. }
  1039. pdata->bAutoKeyResetChanged = false;
  1040. pdata->bKeyTimeoutChanged = false;
  1041. pdata->bModeChanged = false;
  1042. pdata->bSSLChanged = false;
  1043. pdata->bTicketTimeoutChanged = false;
  1044. HRESULT hr = MMCPropertyChangeNotify( pDBServer->m_ppHandle, reinterpret_cast<LONG_PTR>(pDBServer) );
  1045. _ASSERT( SUCCEEDED(hr) );
  1046. }
  1047. return PSNRET_NOERROR;
  1048. case PSN_HELP:
  1049. {
  1050. SecurityData* pdata = reinterpret_cast<SecurityData*>( GetWindowLongPtr( hwndDlg, GWLP_USERDATA ) );
  1051. wstring strHelp( pdata->pServer->GetHelpFile() );
  1052. strHelp += g_wszUddiSecurityPageHelp;
  1053. ::HtmlHelp( hwndDlg, strHelp.c_str(), HH_DISPLAY_TOPIC, NULL );
  1054. }
  1055. break;
  1056. }
  1057. }
  1058. break;
  1059. }
  1060. return FALSE;
  1061. }
  1062. size_t CUDDISiteNode::PublishToActiveDirectory()
  1063. {
  1064. //
  1065. // Build up the list of ServiceConnectionPoint classes
  1066. //
  1067. CUDDIServiceCxnPtPublisher publisher(
  1068. GetConnectionStringOLEDB(),
  1069. m_mapConfig[ UDDI_SITE_KEY ],
  1070. m_mapConfig[ UDDI_SITE_NAME ],
  1071. m_mapConfig[ UDDI_DISCOVERY_URL ] );
  1072. //
  1073. // Process the binding information for the default
  1074. // provider for the site
  1075. //
  1076. publisher.ProcessSite();
  1077. //
  1078. // If there are no bindings don't publish anything
  1079. //
  1080. if( 0 == publisher.size() )
  1081. return 0;
  1082. //
  1083. // Delete the Site container
  1084. //
  1085. try
  1086. {
  1087. publisher.DeleteSiteContainer();
  1088. }
  1089. catch(...)
  1090. {
  1091. }
  1092. //
  1093. // Publish the Site Container
  1094. //
  1095. publisher.CreateSiteContainer();
  1096. //
  1097. // Publish the Service Connection Points
  1098. //
  1099. publisher.PublishServiceCxnPts();
  1100. return publisher.size();
  1101. }
  1102. void CUDDISiteNode::RemoveFromActiveDirectory()
  1103. {
  1104. //
  1105. // Build up the list of ServiceConnectionPoint classes
  1106. //
  1107. CUDDIServiceCxnPtPublisher publisher(
  1108. GetConnectionStringOLEDB(),
  1109. m_mapConfig[ UDDI_SITE_KEY ],
  1110. m_mapConfig[ UDDI_SITE_NAME ],
  1111. m_mapConfig[ UDDI_DISCOVERY_URL ] );
  1112. publisher.DeleteSiteContainer();
  1113. }
  1114. BOOL CUDDISiteNode::CanPublishToActiveDirectory()
  1115. {
  1116. return TRUE;
  1117. }
  1118. BOOL CALLBACK CUDDISiteNode::ActiveDirectoryDialogProc( HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam )
  1119. {
  1120. static CUDDISiteNode *pDatabaseServer = NULL;
  1121. switch( uMsg )
  1122. {
  1123. case WM_INITDIALOG:
  1124. //
  1125. // Catch the "this" pointer so we can actually operate on the object
  1126. //
  1127. pDatabaseServer = reinterpret_cast<CUDDISiteNode *>(reinterpret_cast<PROPSHEETPAGE *>(lParam)->lParam);
  1128. break;
  1129. case WM_HELP:
  1130. {
  1131. wstring strHelp( pDatabaseServer->GetHelpFile() );
  1132. strHelp += g_wszUddiActiveDirectoryPageHelp;
  1133. ::HtmlHelp( hwndDlg, strHelp.c_str(), HH_DISPLAY_TOPIC, NULL );
  1134. }
  1135. break;
  1136. case WM_COMMAND:
  1137. if( IDC_ACTIVEDIRECTORY_BTN_ADD == LOWORD(wParam) )
  1138. {
  1139. try
  1140. {
  1141. size_t nCount = pDatabaseServer->PublishToActiveDirectory();
  1142. //
  1143. // Tell the user the publication job succeeded
  1144. //
  1145. _TCHAR szMessage[ 256 ];
  1146. _TCHAR szTitle[ 256 ];
  1147. if( nCount )
  1148. {
  1149. LoadString( g_hinst, IDS_ACTIVEDIRECTORY_PUBLISH_SUCCEEDED, szMessage, ARRAYLEN( szMessage ) );
  1150. LoadString( g_hinst, IDS_UDDIMMC_NAME, szTitle, ARRAYLEN( szTitle ) );
  1151. }
  1152. else
  1153. {
  1154. LoadString( g_hinst, IDS_ACTIVEDIRECTORY_NO_BINDINGS, szMessage, ARRAYLEN( szMessage ) );
  1155. LoadString( g_hinst, IDS_UDDIMMC_NAME, szTitle, ARRAYLEN( szTitle ) );
  1156. }
  1157. MessageBox( hwndDlg, szMessage, szTitle, MB_OK );
  1158. }
  1159. catch( CUDDIException& e )
  1160. {
  1161. UDDIMsgBox( hwndDlg, IDS_ACTIVEDIRECTORY_PUBLISH_FAILED, IDS_UDDIMMC_SNAPINNAME, MB_ICONERROR, e.GetEntireError().c_str() );
  1162. }
  1163. }
  1164. if( IDC_ACTIVEDIRECTORY_BTN_REMOVE == LOWORD(wParam) )
  1165. {
  1166. try
  1167. {
  1168. pDatabaseServer->RemoveFromActiveDirectory();
  1169. //
  1170. // Tell the user the publication job succeeded
  1171. //
  1172. _TCHAR szMessage[ 256 ];
  1173. _TCHAR szTitle[ 256 ];
  1174. LoadString( g_hinst, IDS_ACTIVEDIRECTORY_DELETE_SUCCEDED, szMessage, ARRAYLEN( szMessage ) );
  1175. LoadString( g_hinst, IDS_UDDIMMC_NAME, szTitle, ARRAYLEN( szTitle ) );
  1176. MessageBox( hwndDlg, szMessage, szTitle, MB_OK );
  1177. }
  1178. catch( CUDDIException& e )
  1179. {
  1180. UDDIMsgBox( hwndDlg, IDS_ACTIVEDIRECTORY_DELETE_FAILED, IDS_UDDIMMC_SNAPINNAME, MB_ICONERROR, e.GetEntireError().c_str() );
  1181. }
  1182. }
  1183. break;
  1184. case WM_NOTIFY:
  1185. switch( ((NMHDR *) lParam)->code )
  1186. {
  1187. case PSN_APPLY:
  1188. return PSNRET_NOERROR;
  1189. case PSN_HELP:
  1190. {
  1191. wstring strHelp( pDatabaseServer->GetHelpFile() );
  1192. strHelp += g_wszUddiActiveDirectoryPageHelp;
  1193. ::HtmlHelp( hwndDlg, strHelp.c_str(), HH_DISPLAY_TOPIC, NULL );
  1194. }
  1195. break;
  1196. }
  1197. break;
  1198. }
  1199. return FALSE;
  1200. }
  1201. HRESULT CUDDISiteNode::HasPropertySheets()
  1202. {
  1203. //
  1204. // Say "yes" when MMC asks if we have pages
  1205. //
  1206. return S_OK;
  1207. }
  1208. HRESULT
  1209. CUDDISiteNode::CreatePropertyPages( IPropertySheetCallback *lpProvider, LONG_PTR handle )
  1210. {
  1211. if( ( NULL == lpProvider ) || ( 0 == handle ) )
  1212. {
  1213. return E_INVALIDARG;
  1214. }
  1215. HRESULT hr = S_OK;
  1216. try
  1217. {
  1218. hr = GetData();
  1219. }
  1220. catch( CUDDIException& e )
  1221. {
  1222. IConsole *pConsole = NULL;
  1223. HWND hwndConsole = NULL;
  1224. //
  1225. // This *should* always work. If it does work, then we use
  1226. // pConsole to get the main window handle for the mmc, and use
  1227. // this main window handle to display a modal dialog.
  1228. //
  1229. // If this fails (which it never should), we then display dialog,
  1230. // but with a NULL HWND.
  1231. //
  1232. hr = lpProvider->QueryInterface( IID_IConsole, (void **)&pConsole );
  1233. if( NULL != pConsole )
  1234. {
  1235. pConsole->GetMainWindow( &hwndConsole );
  1236. }
  1237. TCHAR szTitle[ 256 ];
  1238. LoadString( g_hinst, IDS_DATABASE_SERVER_GETDATA_ERROR_TITLE, szTitle, ARRAYLEN( szTitle ) );
  1239. MessageBox( hwndConsole, e.GetEntireError().c_str(), szTitle, MB_ICONERROR | MB_OK | MB_APPLMODAL );
  1240. if( NULL != pConsole )
  1241. {
  1242. pConsole->Release();
  1243. }
  1244. return E_FAIL;
  1245. }
  1246. catch(...)
  1247. {
  1248. return E_FAIL;
  1249. }
  1250. PropertyPages pps[] = {
  1251. { IDD_GENERAL_SITE_PROPPAGE, GeneralDialogProc },
  1252. { IDD_ROLES_PROPPAGE, RolesDialogProc },
  1253. { IDD_SECURITY_PROPPAGE, SecurityDialogProc },
  1254. { IDD_ACTIVEDIRECTORY_PROPPAGE, ActiveDirectoryDialogProc },
  1255. { IDD_ADVANCED_PROPPAGE, AdvancedDialogProc } };
  1256. PROPSHEETPAGE psp;
  1257. HPROPSHEETPAGE hPage = NULL;
  1258. //
  1259. // Cache this handle so we can call MMCPropertyChangeNotify
  1260. //
  1261. m_ppHandle = handle;
  1262. //
  1263. // Create the property page for this node.
  1264. // NOTE: if your node has multiple pages, put the following
  1265. // in a loop and create multiple pages calling
  1266. // lpProvider->AddPage() for each page.
  1267. //
  1268. psp.dwSize = sizeof(PROPSHEETPAGE);
  1269. psp.dwFlags = PSP_DEFAULT | PSP_HASHELP;
  1270. psp.hInstance = g_hinst;
  1271. psp.lParam = reinterpret_cast<LPARAM>(this);
  1272. for( int i=0; i < ARRAYLEN( pps ); i++ )
  1273. {
  1274. psp.pszTemplate = MAKEINTRESOURCE( pps[ i ].id );
  1275. psp.pfnDlgProc = pps[ i ].dlgproc;
  1276. hPage = CreatePropertySheetPage( &psp );
  1277. _ASSERT( hPage );
  1278. hr = lpProvider->AddPage( hPage );
  1279. if( FAILED(hr) )
  1280. break;
  1281. }
  1282. return hr;
  1283. }
  1284. HRESULT CUDDISiteNode::GetWatermarks(
  1285. HBITMAP *lphWatermark,
  1286. HBITMAP *lphHeader,
  1287. HPALETTE *lphPalette,
  1288. BOOL *bStretch )
  1289. {
  1290. return S_FALSE;
  1291. }
  1292. HRESULT CUDDISiteNode::OnUpdateItem( IConsole *pConsole, long item, ITEM_TYPE itemtype )
  1293. {
  1294. HRESULT hr = S_FALSE;
  1295. _ASSERT( NULL != this || m_isDeleted || RESULT == itemtype );
  1296. //
  1297. // Redraw the item
  1298. //
  1299. IResultData *pResultData = NULL;
  1300. hr = pConsole->QueryInterface( IID_IResultData, (void **)&pResultData );
  1301. _ASSERT( SUCCEEDED(hr) );
  1302. HRESULTITEM myhresultitem;
  1303. _ASSERT( NULL != &myhresultitem );
  1304. //
  1305. // lparam == this. See CSpaceStation::OnShow
  1306. //
  1307. hr = pResultData->FindItemByLParam( (LPARAM)this, &myhresultitem );
  1308. if( FAILED(hr) )
  1309. {
  1310. //
  1311. // Failed : Reason may be that current view does not have this item.
  1312. // So exit gracefully.
  1313. //
  1314. hr = S_FALSE;
  1315. }
  1316. else
  1317. {
  1318. hr = pResultData->UpdateItem( myhresultitem );
  1319. _ASSERT( SUCCEEDED(hr) );
  1320. }
  1321. pResultData->Release();
  1322. return hr;
  1323. }
  1324. HRESULT CUDDISiteNode::OnRefresh( IConsole *pConsole )
  1325. {
  1326. //
  1327. // Call IConsole::UpdateAllViews to redraw all views
  1328. // owned by the parent scope item
  1329. //
  1330. HRESULT hr = pConsole->UpdateAllViews( NULL, m_pParent->GetParentScopeItem(), UPDATE_SCOPEITEM );
  1331. _ASSERT( S_OK == hr);
  1332. if( TRUE == SUCCEEDED( hr ) )
  1333. {
  1334. CUDDIWebServerNodeMap::iterator it = m_mapChildren.begin();
  1335. for ( it = m_mapChildren.begin(); it != m_mapChildren.end(); it++ )
  1336. {
  1337. CUDDIWebServerNode *pWSNode = it->second;
  1338. if( NULL != pWSNode )
  1339. {
  1340. pWSNode->OnRefresh( pConsole );
  1341. }
  1342. }
  1343. }
  1344. return hr;
  1345. }
  1346. HRESULT CUDDISiteNode::OnAddMenuItems( IContextMenuCallback *pContextMenuCallback, long *pInsertionsAllowed )
  1347. {
  1348. HRESULT hr = S_OK;
  1349. if( !IsExtension() )
  1350. {
  1351. WCHAR szWebServerMenuText[ MAX_PATH ];
  1352. WCHAR szWebServerMenuDescription[ MAX_PATH ];
  1353. LoadStringW( g_hinst, IDS_WEBSERVER_ADD, szWebServerMenuText, ARRAYLEN( szWebServerMenuText ) );
  1354. LoadStringW( g_hinst, IDS_WEBSERVER_DESCRIPTION, szWebServerMenuDescription, ARRAYLEN( szWebServerMenuDescription ) );
  1355. CONTEXTMENUITEM menuItemsNew[] =
  1356. {
  1357. {
  1358. szWebServerMenuText,
  1359. szWebServerMenuDescription,
  1360. IDM_NEW_WEBSERVER,
  1361. CCM_INSERTIONPOINTID_PRIMARY_TOP,
  1362. m_bStdSvr ? MF_GRAYED : 0, // this menu option is disabled iff site node is on a Windows Server 2003 standard machine.
  1363. 0
  1364. },
  1365. { NULL, NULL, 0, 0, 0 }
  1366. };
  1367. //
  1368. // Loop through and add each of the menu items, we
  1369. // want to add to new menu, so see if it is allowed.
  1370. //
  1371. if( *pInsertionsAllowed & CCM_INSERTIONALLOWED_TOP )
  1372. {
  1373. for( LPCONTEXTMENUITEM m = menuItemsNew; m->strName; m++ )
  1374. {
  1375. hr = pContextMenuCallback->AddItem( m );
  1376. if( FAILED(hr) )
  1377. break;
  1378. }
  1379. }
  1380. }
  1381. #if defined( _DEBUG ) || defined( DBG )
  1382. CONTEXTMENUITEM menuItemsNew[] =
  1383. {
  1384. {
  1385. _T("Debug"), _T("Dump all the configuration data"),
  1386. IDM_DEBUG, CCM_INSERTIONPOINTID_PRIMARY_TOP, 0, 0
  1387. },
  1388. { NULL, NULL, 0, 0, 0 }
  1389. };
  1390. //
  1391. // Loop through and add each of the menu items, we
  1392. // want to add to new menu, so see if it is allowed.
  1393. //
  1394. if( *pInsertionsAllowed & CCM_INSERTIONALLOWED_TOP )
  1395. {
  1396. for( LPCONTEXTMENUITEM m = menuItemsNew; m->strName; m++ )
  1397. {
  1398. hr = pContextMenuCallback->AddItem( m );
  1399. if( FAILED(hr) )
  1400. break;
  1401. }
  1402. }
  1403. #endif
  1404. return hr;
  1405. }
  1406. CUDDIWebServerNode* CUDDISiteNode::FindChild( LPCTSTR szName )
  1407. {
  1408. CUDDIWebServerNodeMap::iterator it;
  1409. for( it = m_mapChildren.begin(); it != m_mapChildren.end(); it++ )
  1410. {
  1411. CUDDIWebServerNode* pNode = it->second;
  1412. if( ( NULL != pNode ) && ( !pNode->IsDeleted() ) && ( 0 == _tcsicmp( szName, pNode->GetName() ) ) )
  1413. {
  1414. return pNode;
  1415. }
  1416. }
  1417. return NULL;
  1418. }
  1419. HRESULT CUDDISiteNode::OnMenuCommand( IConsole *pConsole, IConsoleNameSpace *pConsoleNameSpace, long lCommandID, IDataObject *pDataObject )
  1420. {
  1421. switch( lCommandID )
  1422. {
  1423. case IDM_NEW_WEBSERVER:
  1424. {
  1425. //
  1426. // Use these for some message boxes.
  1427. //
  1428. _TCHAR szMessage[ 512 ];
  1429. _TCHAR szTitle[ 128 ];
  1430. WebServerData wsData;
  1431. wsData.pBase = this;
  1432. HWND hwndConsole = NULL;
  1433. HRESULT hr = pConsole->GetMainWindow( &hwndConsole );
  1434. _ASSERT( S_OK == hr);
  1435. INT_PTR nResult = DialogBoxParam( g_hinst, MAKEINTRESOURCE( IDD_WEBSERVER_NEW ), hwndConsole, CUDDIWebServerNode::NewWebServerDialogProc, (LPARAM)&wsData );
  1436. if( nResult )
  1437. {
  1438. try
  1439. {
  1440. wstring strOldConnStr;
  1441. CUDDIWebServerNode::GetWriterConnectionString( wsData.szName, strOldConnStr );
  1442. if( !CUDDISiteNode::AddWebServerToSite( m_szName, wsData.szName, hwndConsole ) )
  1443. {
  1444. return E_FAIL;
  1445. }
  1446. if( 0 != strOldConnStr.length() )
  1447. {
  1448. wstring strDomain, strServer, strInstance;
  1449. CUDDIWebServerNode::CrackConnectionString( strOldConnStr, strDomain, strServer, strInstance );
  1450. CUDDISiteNode *pOldSite = static_cast<CUDDISiteNode *>( m_pParent->FindChild( strServer.c_str() ) );
  1451. if( NULL != pOldSite )
  1452. {
  1453. CUDDIWebServerNode *pOldWS = pOldSite->FindChild( wsData.szName.c_str() );
  1454. if( NULL != pOldSite )
  1455. {
  1456. pOldWS->DeleteFromScopePane( pConsoleNameSpace );
  1457. }
  1458. }
  1459. }
  1460. //
  1461. // Make sure the version of the web server is compatible with the version on the site.
  1462. //
  1463. UINT n = m_nNextChildID;
  1464. CUDDIWebServerNode *pNode = new CUDDIWebServerNode( wsData.szName.c_str(), n, this, m_bIsExtension );
  1465. if( TRUE == AddChildEntry( pNode, n ) )
  1466. {
  1467. //
  1468. // Set the connection strings registry keys on the web server machine to point to this UDDI site.
  1469. //
  1470. tstring szConnStr = CUDDIWebServerNode::BuildConnectionString( m_szName );
  1471. CUDDIWebServerNode::SetReaderConnectionString( wsData.szName.c_str(), szConnStr );
  1472. CUDDIWebServerNode::SetWriterConnectionString( wsData.szName.c_str(), szConnStr );
  1473. //
  1474. // Add this new web server node to the list of web servers for this site.
  1475. //
  1476. m_nNextChildID++;
  1477. m_bIsDirty = TRUE;
  1478. SCOPEDATAITEM sdi;
  1479. ZeroMemory( &sdi, sizeof(SCOPEDATAITEM) );
  1480. sdi.mask = SDI_STR | // Displayname is valid
  1481. SDI_PARAM | // lParam is valid
  1482. SDI_IMAGE | // nImage is valid
  1483. SDI_OPENIMAGE | // nOpenImage is valid
  1484. SDI_PARENT |
  1485. SDI_CHILDREN;
  1486. sdi.relativeID = GetScopeItemValue();
  1487. sdi.nImage = m_mapChildren[ n ]->GetBitmapIndex();
  1488. sdi.nOpenImage = MMC_IMAGECALLBACK;
  1489. sdi.displayname = MMC_CALLBACK;
  1490. sdi.lParam = (LPARAM) m_mapChildren[ n ];
  1491. sdi.cChildren = m_mapChildren[ n ]->HasChildren();
  1492. hr = pConsoleNameSpace->InsertItem( &sdi );
  1493. _ASSERT( SUCCEEDED(hr) );
  1494. m_mapChildren[ n ]->SetScopeItemValue( sdi.ID );
  1495. m_mapChildren[ n ]->SetParentScopeItem( sdi.relativeID );
  1496. //
  1497. // We created a new object in result pane. We need to insert this object
  1498. // in all the views, call UpdateAllViews for this.
  1499. // Pass pointer to data object passed into OnMenuCommand.
  1500. //
  1501. hr = pConsole->UpdateAllViews( pDataObject, GetScopeItemValue(), UPDATE_SCOPEITEM );
  1502. _ASSERT( S_OK == hr);
  1503. //
  1504. // Prompt the user with a warning to tell them that they might have to alter their
  1505. // machine.config settings if this web server is part of a web farm.
  1506. //
  1507. memset( szMessage, 0, 512 * sizeof( _TCHAR ) );
  1508. memset( szTitle, 0, 128 * sizeof( _TCHAR ) );
  1509. LoadString( g_hinst, IDS_WEBSERVER_WEBFARM_DETAIL, szMessage, ARRAYLEN( szMessage ) );
  1510. LoadString( g_hinst, IDS_WEBSERVER_WEBFARM, szTitle, ARRAYLEN( szTitle ) );
  1511. MessageBox( hwndConsole, szMessage, szTitle, MB_OK );
  1512. }
  1513. }
  1514. catch( CUDDIException &e )
  1515. {
  1516. UDDIMsgBox( hwndConsole, (LPCTSTR) e, IDS_ERROR_TITLE, MB_ICONEXCLAMATION | MB_OK );
  1517. return E_FAIL;
  1518. }
  1519. catch( ... )
  1520. {
  1521. UDDIMsgBox( hwndConsole, IDS_ERROR_ADDWEBSITE, IDS_ERROR_TITLE, MB_ICONEXCLAMATION | MB_OK );
  1522. return E_UNEXPECTED;
  1523. }
  1524. }
  1525. }
  1526. break;
  1527. #if defined( _DEBUG ) || defined( DBG )
  1528. case IDM_DEBUG:
  1529. {
  1530. try
  1531. {
  1532. GetData();
  1533. }
  1534. catch( CUDDIException& e )
  1535. {
  1536. TCHAR szTitle[ 256 ];
  1537. LoadString( g_hinst, IDS_DATABASE_SERVER_GETDATA_ERROR_TITLE, szTitle, ARRAYLEN( szTitle ) );
  1538. HWND hwnd;
  1539. pConsole->GetMainWindow( &hwnd );
  1540. MessageBox( hwnd, e.GetEntireError().c_str(), szTitle, MB_ICONERROR | MB_OK | MB_APPLMODAL );
  1541. return E_FAIL;
  1542. }
  1543. for( CConfigMap::iterator iter = m_mapConfig.begin();
  1544. iter != m_mapConfig.end(); iter++ )
  1545. {
  1546. OutputDebugString( (*iter).first.c_str() );
  1547. OutputDebugString( _T(" = ") );
  1548. OutputDebugString( (*iter).second.c_str() );
  1549. OutputDebugString( _T("\n") );
  1550. }
  1551. }
  1552. break;
  1553. #endif
  1554. }
  1555. return S_OK;
  1556. }
  1557. HRESULT
  1558. CUDDISiteNode::OnDelete( IConsoleNameSpace *pConsoleNameSpace, IConsole *pConsoleComp )
  1559. {
  1560. if( ( NULL == pConsoleNameSpace ) || ( NULL == pConsoleComp ) )
  1561. {
  1562. return E_INVALIDARG;
  1563. }
  1564. HRESULT hr;
  1565. hr = pConsoleNameSpace->DeleteItem( GetScopeItemValue(), TRUE );
  1566. //
  1567. // Now set isDeleted member so that the parent doesn't try to
  1568. // to insert it again in CUDDIServicesNode::OnShow. Admittedly, a hack...
  1569. //
  1570. m_isDeleted = TRUE;
  1571. return hr;
  1572. }
  1573. const LPCTSTR CUDDISiteNode::GetName()
  1574. {
  1575. return m_szName;
  1576. }
  1577. BOOL
  1578. CUDDISiteNode::GetFullyQualifiedInstanceName( LPCTSTR szName, tstring& strInstanceName )
  1579. {
  1580. try
  1581. {
  1582. strInstanceName = _T( "" );
  1583. CUDDIRegistryKey dbkey( _T( "SOFTWARE\\Microsoft\\UDDI" ), KEY_READ, szName );
  1584. strInstanceName = dbkey.GetString( _T( "InstanceName" ) );
  1585. dbkey.Close();
  1586. return TRUE;
  1587. }
  1588. catch( ... )
  1589. {
  1590. strInstanceName = _T( "" );
  1591. return FALSE;
  1592. }
  1593. }
  1594. const _TCHAR *
  1595. CUDDISiteNode::GetInstanceName()
  1596. {
  1597. return m_szInstanceName;
  1598. }
  1599. CUDDISiteNode* CUDDISiteNode::Create( _TCHAR *szName, _TCHAR *szInstanceName, int id, CUDDIServicesNode* parent, BOOL bExtension )
  1600. {
  1601. CUDDISiteNode* pNode = new CUDDISiteNode( szName, szInstanceName, id, parent, bExtension );
  1602. try
  1603. {
  1604. if( pNode )
  1605. pNode->GetData();
  1606. }
  1607. catch( CUDDIException &e )
  1608. {
  1609. delete pNode;
  1610. pNode = NULL;
  1611. throw e;
  1612. }
  1613. catch(...)
  1614. {
  1615. }
  1616. return pNode;
  1617. }
  1618. CConfigMap& CUDDISiteNode::GetConfigMap()
  1619. {
  1620. return m_mapConfig;
  1621. }
  1622. tstring
  1623. CUDDISiteNode::GetConnectionStringOLEDB()
  1624. {
  1625. try
  1626. {
  1627. tstring strConn = GetConnectionString();
  1628. if( tstring::npos == strConn.find( _T( "Provider=SQLOLEDB.1" ) ) )
  1629. {
  1630. strConn += _T( ";Provider=SQLOLEDB.1" );
  1631. }
  1632. return strConn;
  1633. }
  1634. catch( ... )
  1635. {
  1636. return _T( "" );
  1637. }
  1638. }
  1639. tstring
  1640. CUDDISiteNode::GetConnectionString()
  1641. {
  1642. try
  1643. {
  1644. tstring strConn = _T( "Data Source=" );
  1645. tstring strInstanceName = _T( "" );
  1646. BOOL b = GetFullyQualifiedInstanceName( m_szName, strInstanceName );
  1647. if( FALSE == b )
  1648. {
  1649. return _T( "" );
  1650. }
  1651. strConn += strInstanceName;
  1652. strConn += _T(";Initial Catalog=uddi;Integrated Security=SSPI;");
  1653. return strConn;
  1654. }
  1655. catch( ... )
  1656. {
  1657. return _T( "" );
  1658. }
  1659. }
  1660. BOOL CALLBACK CUDDISiteNode::CryptographyDialogProc( HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam )
  1661. {
  1662. CUDDISiteNode *pDatabaseServer = NULL;
  1663. switch( uMsg )
  1664. {
  1665. case WM_INITDIALOG:
  1666. {
  1667. SecurityData* pdata = reinterpret_cast<SecurityData*>(lParam);
  1668. CUDDISiteNode* pDBServer = pdata->pServer;
  1669. SetWindowLongPtr( hwndDlg, GWLP_USERDATA, lParam );
  1670. SetDlgItemText( hwndDlg, IDC_CRYPTOGRAPHY_TXT_RESET_DATE, LocalizedDateTime( pdata->pServer->GetConfigMap()[ UDDI_KEY_RESET_DATE ] ).c_str() );
  1671. SendDlgItemMessage( hwndDlg, IDC_CRYPTOGRAPHY_SPIN_TICKET_TIMEOUT, UDM_SETRANGE32, (WPARAM) 1, (LPARAM) 1000 );
  1672. SendDlgItemMessage( hwndDlg, IDC_CRYPTOGRAPHY_SPIN_TIMEOUT, UDM_SETRANGE32, (WPARAM) 1, (LPARAM) 365 );
  1673. SendDlgItemMessage( hwndDlg, IDC_CRYPTOGRAPHY_SPIN_TICKET_TIMEOUT, UDM_SETPOS32, NULL, (LPARAM) pdata->nTicketTimeout );
  1674. SendDlgItemMessage( hwndDlg, IDC_CRYPTOGRAPHY_SPIN_TIMEOUT, UDM_SETPOS32, NULL, (LPARAM) pdata->nKeyTimeout );
  1675. SendDlgItemMessage( hwndDlg, IDC_CRYPTOGRAPHY_CHECK_AUTO_RESET, BM_SETCHECK, pdata->bAutoKeyReset ? BST_CHECKED : BST_UNCHECKED, NULL );
  1676. EnableWindow( GetDlgItem( hwndDlg, IDC_CRYPTOGRAPHY_EDIT_TIMEOUT ), pdata->bAutoKeyReset );
  1677. EnableWindow( GetDlgItem( hwndDlg, IDC_CRYPTOGRAPHY_SPIN_TIMEOUT ), pdata->bAutoKeyReset );
  1678. }
  1679. break;
  1680. case WM_HELP:
  1681. {
  1682. SecurityData* pdata = reinterpret_cast<SecurityData*>( GetWindowLongPtr( hwndDlg, GWLP_USERDATA ) ) ;
  1683. wstring strHelp( pdata->pServer->GetHelpFile() );
  1684. strHelp += g_wszUddiCryptographyHelp;
  1685. ::HtmlHelp( hwndDlg, strHelp.c_str(), HH_DISPLAY_TOPIC, NULL );
  1686. }
  1687. break;
  1688. case WM_COMMAND:
  1689. {
  1690. SecurityData* pdata = reinterpret_cast<SecurityData*>( GetWindowLongPtr( hwndDlg, GWLP_USERDATA ) ) ;
  1691. _TCHAR szMessage[ 512 ];
  1692. _TCHAR szTitle[ 256 ];
  1693. switch( LOWORD(wParam) )
  1694. {
  1695. case IDC_CRYPTOGRAPHY_BTN_RESET_NOW:
  1696. ::LoadString( g_hinst, IDS_CRYPTOGRAPHY_RESET_NOW_CONFIRM, szMessage, ARRAYLEN( szMessage ) );
  1697. ::LoadString( g_hinst, IDS_CRYPTOGRAPHY_RESET_NOW_TITLE, szTitle, ARRAYLEN( szTitle ) );
  1698. if( IDYES == MessageBox( hwndDlg, szMessage, szTitle, MB_YESNO | MB_ICONQUESTION ) )
  1699. {
  1700. if( TRUE == pdata->pServer->ResetCryptography() )
  1701. {
  1702. ::LoadString( g_hinst, IDS_CRYPTOGRAPHY_RESET_NOW_SUCCESS, szMessage, ARRAYLEN( szMessage ) );
  1703. ::LoadString( g_hinst, IDS_CRYPTOGRAPHY_RESET_NOW_SUCCESS_TITLE, szTitle, ARRAYLEN( szTitle ) );
  1704. SetDlgItemText( hwndDlg, IDC_CRYPTOGRAPHY_TXT_RESET_DATE, LocalizedDateTime( pdata->pServer->m_mapConfig[ UDDI_KEY_RESET_DATE ] ).c_str() );
  1705. MessageBox( hwndDlg, szMessage, szTitle, MB_OK );
  1706. }
  1707. else
  1708. {
  1709. ::LoadString( g_hinst, IDS_CRYPTOGRAPHY_RESET_NOW_FAILED, szMessage, ARRAYLEN( szMessage ) );
  1710. ::LoadString( g_hinst, IDS_CRYPTOGRAPHY_RESET_NOW_FAILED_TITLE, szTitle, ARRAYLEN( szTitle ) );
  1711. MessageBox( hwndDlg, szMessage, szTitle, MB_OK );
  1712. }
  1713. }
  1714. break;
  1715. case IDC_CRYPTOGRAPHY_CHECK_AUTO_RESET:
  1716. {
  1717. LRESULT nChecked = SendDlgItemMessage( hwndDlg, IDC_CRYPTOGRAPHY_CHECK_AUTO_RESET, BM_GETCHECK, NULL, NULL );
  1718. EnableWindow( GetDlgItem( hwndDlg, IDC_CRYPTOGRAPHY_EDIT_TIMEOUT ), BST_CHECKED == nChecked ? TRUE : FALSE );
  1719. EnableWindow( GetDlgItem( hwndDlg, IDC_CRYPTOGRAPHY_SPIN_TIMEOUT ), BST_CHECKED == nChecked ? TRUE : FALSE );
  1720. pdata->bAutoKeyResetChanged = true;
  1721. }
  1722. break;
  1723. case IDC_CRYPTOGRAPHY_EDIT_TIMEOUT:
  1724. {
  1725. if( ( EN_CHANGE == HIWORD( wParam ) ) && ( NULL != pdata ) )
  1726. {
  1727. pdata->bKeyTimeoutChanged = true;
  1728. }
  1729. }
  1730. break;
  1731. case IDC_CRYPTOGRAPHY_EDIT_TICKET_TIMEOUT:
  1732. {
  1733. if( ( EN_CHANGE == HIWORD( wParam ) ) && ( NULL != pdata ) )
  1734. {
  1735. pdata->bTicketTimeoutChanged = true;
  1736. }
  1737. }
  1738. break;
  1739. case IDHELP:
  1740. {
  1741. wstring strHelp( pdata->pServer->GetHelpFile() );
  1742. strHelp += g_wszUddiCryptographyHelp;
  1743. ::HtmlHelp( hwndDlg, strHelp.c_str(), HH_DISPLAY_TOPIC, NULL );
  1744. }
  1745. break;
  1746. case IDOK:
  1747. {
  1748. //
  1749. // Check that the ticket timeout is in proper range.
  1750. //
  1751. BOOL bError = FALSE;
  1752. LRESULT lValue = SendDlgItemMessage( hwndDlg, IDC_CRYPTOGRAPHY_SPIN_TICKET_TIMEOUT, UDM_GETPOS32, NULL, (LPARAM) &bError );
  1753. if( bError )
  1754. {
  1755. //
  1756. // Value out of range
  1757. //
  1758. LoadString( g_hinst, IDS_CRYPTOGRAPHY_TICKET_TIMEOUT_ERROR, szMessage, ARRAYLEN( szMessage ) );
  1759. LoadString( g_hinst, IDS_CRYPTOGRAPHY_TICKET_TIMEOUT_ERROR_TITLE, szTitle, ARRAYLEN( szTitle ) );
  1760. MessageBox( hwndDlg, szMessage, szTitle, MB_ICONERROR );
  1761. SendDlgItemMessage( hwndDlg, IDC_CRYPTOGRAPHY_SPIN_TICKET_TIMEOUT, UDM_SETPOS32, NULL, (LPARAM) 1000 );
  1762. SetFocus( GetDlgItem( hwndDlg, IDC_CRYPTOGRAPHY_EDIT_TICKET_TIMEOUT ) );
  1763. return FALSE;
  1764. }
  1765. if( pdata->bTicketTimeoutChanged )
  1766. {
  1767. pdata->nTicketTimeout = lValue;
  1768. }
  1769. if( IsWindowEnabled( GetDlgItem( hwndDlg, IDC_CRYPTOGRAPHY_EDIT_TIMEOUT ) ) )
  1770. {
  1771. //
  1772. // Check that the cryptography expiration is within specs
  1773. //
  1774. lValue = SendDlgItemMessage( hwndDlg, IDC_CRYPTOGRAPHY_SPIN_TIMEOUT, UDM_GETPOS32, NULL, (LPARAM) &bError );
  1775. if( bError )
  1776. {
  1777. //
  1778. // Value out of range
  1779. //
  1780. LoadString( g_hinst, IDS_CRYPTOGRAPHY_TIMEOUT_ERROR, szMessage, ARRAYLEN( szMessage ) );
  1781. LoadString( g_hinst, IDS_CRYPTOGRAPHY_TICKET_TIMEOUT_ERROR_TITLE, szTitle, ARRAYLEN( szTitle ) );
  1782. MessageBox( hwndDlg, szMessage, szTitle, MB_ICONERROR );
  1783. SendDlgItemMessage( hwndDlg, IDC_CRYPTOGRAPHY_SPIN_TIMEOUT, UDM_SETPOS32, NULL, (LPARAM) 365 );
  1784. SetFocus( GetDlgItem( hwndDlg, IDC_CRYPTOGRAPHY_EDIT_TIMEOUT ) );
  1785. return FALSE;
  1786. }
  1787. //
  1788. // We won't update the key timeout unless auto
  1789. // reset is enabled
  1790. //
  1791. if( pdata->bKeyTimeoutChanged )
  1792. {
  1793. pdata->nKeyTimeout = lValue;
  1794. }
  1795. }
  1796. if( pdata->bAutoKeyResetChanged )
  1797. {
  1798. LRESULT nChecked = SendDlgItemMessage( hwndDlg, IDC_CRYPTOGRAPHY_CHECK_AUTO_RESET, BM_GETCHECK, NULL, NULL );
  1799. pdata->bAutoKeyReset = BST_CHECKED == nChecked;
  1800. }
  1801. EndDialog( hwndDlg, TRUE );
  1802. }
  1803. break;
  1804. case IDCANCEL:
  1805. {
  1806. //
  1807. // Reset the change flags if the dialog is cancelled
  1808. //
  1809. pdata->bAutoKeyResetChanged = false;
  1810. pdata->bKeyTimeoutChanged = false;
  1811. pdata->bTicketTimeoutChanged = false;
  1812. EndDialog( hwndDlg, FALSE );
  1813. }
  1814. break;
  1815. } /* End switch(...)*/
  1816. } /* End case WM_COMMAND */
  1817. break;
  1818. case WM_NOTIFY:
  1819. {
  1820. SecurityData* pdata = reinterpret_cast<SecurityData*>( GetWindowLongPtr( hwndDlg, GWLP_USERDATA ) ) ;
  1821. LPNMHDR phdr = (LPNMHDR) lParam;
  1822. if( UDN_DELTAPOS == phdr->code && IDC_CRYPTOGRAPHY_SPIN_TIMEOUT == phdr->idFrom )
  1823. {
  1824. pdata->bKeyTimeoutChanged = true;
  1825. }
  1826. else if( UDN_DELTAPOS == phdr->code && IDC_CRYPTOGRAPHY_SPIN_TICKET_TIMEOUT == phdr->idFrom )
  1827. {
  1828. pdata->bTicketTimeoutChanged = true;
  1829. }
  1830. }
  1831. break;
  1832. case WM_DESTROY:
  1833. break;
  1834. } /* End switch(nMsg) */
  1835. return FALSE;
  1836. }
  1837. BOOL
  1838. CUDDISiteNode::IsDatabaseServer( PTCHAR szName )
  1839. {
  1840. try
  1841. {
  1842. CUDDIRegistryKey key( _T( "SOFTWARE\\Microsoft\\UDDI\\Setup" ), KEY_READ, szName );
  1843. DWORD dwDB = key.GetDWORD( _T( "DBServer" ), 0 );
  1844. key.Close();
  1845. return ( 0 == dwDB ) ? FALSE : TRUE;
  1846. }
  1847. catch( ... )
  1848. {
  1849. return FALSE;
  1850. }
  1851. }
  1852. BOOL
  1853. CUDDISiteNode::IsDatabaseServer( PTCHAR szName, PTCHAR szInstance )
  1854. {
  1855. try
  1856. {
  1857. CUDDIRegistryKey key( _T( "SOFTWARE\\Microsoft\\UDDI\\Setup" ), KEY_READ, szName );
  1858. DWORD dwDB = key.GetDWORD( _T( "DBServer" ), 0 );
  1859. key.Close();
  1860. if( 0 == dwDB )
  1861. return FALSE;
  1862. CUDDIRegistryKey dbkey( _T( "SOFTWARE\\Microsoft\\UDDI" ), KEY_READ, szName );
  1863. tstring strInstance = dbkey.GetString( _T( "InstanceName" ), _T("") );
  1864. dbkey.Close();
  1865. if( 0 != _tcsicmp( szInstance, InstanceRealName( strInstance.c_str() ) ) )
  1866. return FALSE;
  1867. return TRUE;
  1868. }
  1869. catch( ... )
  1870. {
  1871. return FALSE;
  1872. }
  1873. }
  1874. BOOL CUDDISiteNode::ResetCryptography()
  1875. {
  1876. BOOL fRet = FALSE;
  1877. try
  1878. {
  1879. HRESULT hr = E_FAIL;
  1880. ADM_execResetKeyImmediate resetkey;
  1881. resetkey.m_connectionString = GetConnectionStringOLEDB().c_str();
  1882. hr = resetkey.Open();
  1883. if( FAILED(hr) || 0 != resetkey.m_RETURNVALUE )
  1884. {
  1885. CUDDISiteNode::HandleOLEDBError( hr );
  1886. }
  1887. m_mapConfig[ UDDI_KEY_RESET_DATE ] = resetkey.m_keyLastResetDate;
  1888. fRet = TRUE;
  1889. }
  1890. catch( CUDDIException &e )
  1891. {
  1892. OutputDebugString( e );
  1893. fRet = FALSE;
  1894. }
  1895. catch( ... )
  1896. {
  1897. fRet = FALSE;
  1898. }
  1899. return fRet;
  1900. }
  1901. HRESULT CUDDISiteNode::SaveData()
  1902. {
  1903. HRESULT hr = S_OK;
  1904. //
  1905. // Save each modifed configuration value into the configuration table
  1906. // using net_config_save
  1907. //
  1908. OutputDebugString( _T("Updating Values...\n") );
  1909. for( CConfigMap::iterator iter = m_mapChanges.begin();
  1910. iter != m_mapChanges.end(); iter++ )
  1911. {
  1912. if( 0 == _tcsicmp( (*iter).first.c_str(), UDDI_ADMIN_GROUP ) )
  1913. {
  1914. OutputDebugString( _T("The Administrator Group Name was modified\n") );
  1915. //
  1916. // The admin group has been changed. We need to update this independently because the
  1917. // translation of the "S-1..." format to SID is very difficult in T-SQL
  1918. //
  1919. // TODO: This call should be bound inside a transaction. with net_config_save
  1920. //
  1921. ADM_setAdminAccount updateadmin;
  1922. updateadmin.m_connectionString = GetConnectionStringOLEDB().c_str();
  1923. _tcsncpy( updateadmin.m_accountName, GroupNameFromSid( (*iter).second, m_szName ).c_str(), ARRAYLEN( updateadmin.m_accountName ) );
  1924. updateadmin.m_accountName[ ARRAYLEN( updateadmin.m_accountName ) - 1 ] = NULL;
  1925. hr = updateadmin.Open();
  1926. if( FAILED(hr) || 0 != updateadmin.m_RETURNVALUE )
  1927. {
  1928. try
  1929. {
  1930. CUDDISiteNode::HandleOLEDBError( hr );
  1931. }
  1932. catch( CUDDIException &e )
  1933. {
  1934. // leave 'hr' the same.
  1935. OutputDebugString( e );
  1936. }
  1937. catch( ... )
  1938. {
  1939. // leave 'hr' the same.
  1940. }
  1941. break;
  1942. }
  1943. }
  1944. OutputDebugString( (*iter).first.c_str() );
  1945. OutputDebugString( _T(" = ") );
  1946. OutputDebugString( (*iter).second.c_str() );
  1947. OutputDebugString( _T("\n") );
  1948. net_config_save rs;
  1949. rs.m_connectionString = GetConnectionStringOLEDB().c_str();
  1950. _tcsncpy( rs.m_configName, (*iter).first.c_str(), ARRAYLEN( rs.m_configName ) - 1 );
  1951. rs.m_configName[ ARRAYLEN( rs.m_configName ) - 1 ] = 0x00;
  1952. _tcsncpy( rs.m_configValue, (*iter).second.c_str(), ARRAYLEN( rs.m_configValue ) - 1 );
  1953. rs.m_configValue[ ARRAYLEN( rs.m_configValue ) - 1 ] = 0x00;
  1954. hr = rs.Open();
  1955. if( FAILED(hr) || 0 != rs.m_RETURNVALUE )
  1956. {
  1957. try
  1958. {
  1959. CUDDISiteNode::HandleOLEDBError( hr );
  1960. }
  1961. catch( CUDDIException &e )
  1962. {
  1963. // leave 'hr' the same.
  1964. OutputDebugString( e );
  1965. }
  1966. catch( ... )
  1967. {
  1968. // leave 'hr' the same.
  1969. }
  1970. break;
  1971. }
  1972. }
  1973. //
  1974. // Regardless of the outcome clear the change collection
  1975. //
  1976. m_mapChanges.clear();
  1977. return hr;
  1978. }
  1979. struct PropertyData
  1980. {
  1981. CUDDISiteNode* pServer;
  1982. _TCHAR szName[ 512 ];
  1983. _TCHAR szValue[ 512 ];
  1984. _TCHAR szDefault[ 512 ];
  1985. _TCHAR szHelpText[ 512 ];
  1986. };
  1987. BOOL CALLBACK CUDDISiteNode::AdvancedDialogProc( HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam )
  1988. {
  1989. switch( uMsg )
  1990. {
  1991. case WM_INITDIALOG:
  1992. {
  1993. CUDDISiteNode* pDatabaseServer = reinterpret_cast<CUDDISiteNode *>(reinterpret_cast<PROPSHEETPAGE *>(lParam)->lParam);
  1994. SetWindowLongPtr( hwndDlg, GWLP_USERDATA, reinterpret_cast<LONG_PTR>(pDatabaseServer) );
  1995. CConfigMap& m_mapConfig = pDatabaseServer->m_mapConfig;
  1996. HWND hwndList = GetDlgItem( hwndDlg, IDC_ACTIVEDIRECTORY_LIST_ADVANCED );
  1997. ListView_SetExtendedListViewStyleEx( hwndList, 0, LVS_EX_BORDERSELECT | LVS_EX_FULLROWSELECT | LVS_EX_GRIDLINES );
  1998. TCHAR szName[ 256 ];
  1999. LVCOLUMN lvcol;
  2000. LoadString( g_hinst, IDS_ADVANCED_NAME_COLUMN_NAME, szName, ARRAYLEN( szName ) );
  2001. ZeroMemory( &lvcol, sizeof( lvcol ) );
  2002. lvcol.mask = LVCF_TEXT | LVCF_WIDTH | LVCF_FMT;
  2003. lvcol.fmt = LVCFMT_LEFT;
  2004. lvcol.cx = 150;
  2005. lvcol.pszText = szName;
  2006. ListView_InsertColumn( hwndList, 0, &lvcol );
  2007. LoadString( g_hinst, IDS_ADVANCED_VALUE_COLUMN_NAME, szName, ARRAYLEN( szName ) );
  2008. ZeroMemory( &lvcol, sizeof( lvcol ) );
  2009. lvcol.mask = LVCF_TEXT | LVCF_WIDTH | LVCF_FMT;
  2010. lvcol.fmt = LVCFMT_LEFT;
  2011. lvcol.cx = 215;
  2012. lvcol.pszText = szName;
  2013. ListView_InsertColumn( hwndList, 1, &lvcol );
  2014. LPCTSTR ppszValues[] = {
  2015. UDDI_DISCOVERY_URL,
  2016. UDDI_FIND_MAXROWS,
  2017. UDDI_OPERATOR_NAME };
  2018. for( int i=0; i< ARRAYLEN( ppszValues ); i++ )
  2019. {
  2020. LVITEM item;
  2021. ZeroMemory( &item, sizeof( item ) );
  2022. item.mask = LVIF_TEXT;
  2023. item.pszText = _T("");
  2024. int nIndex = ListView_InsertItem( hwndList, &item );
  2025. ListView_SetItemText( hwndList, nIndex, 0, (PTCHAR) ppszValues[ i ] );
  2026. ListView_SetItemText( hwndList, nIndex, 1, (_TCHAR*) m_mapConfig[ ppszValues[ i ] ].c_str() );
  2027. }
  2028. break;
  2029. }
  2030. case WM_COMMAND:
  2031. if( IDC_ADVANCED_BTN_EDIT == LOWORD( wParam ) )
  2032. {
  2033. CUDDISiteNode* pDatabaseServer = reinterpret_cast<CUDDISiteNode*>( GetWindowLongPtr( hwndDlg, GWLP_USERDATA ) );
  2034. HWND hwndList = GetDlgItem( hwndDlg, IDC_ACTIVEDIRECTORY_LIST_ADVANCED );
  2035. int n = ListView_GetNextItem( hwndList, -1, LVNI_SELECTED );
  2036. if( -1 != n )
  2037. {
  2038. PropertyData data;
  2039. data.pServer = pDatabaseServer;
  2040. ListView_GetItemText( hwndList, n, 0, data.szName, 256 );
  2041. ListView_GetItemText( hwndList, n, 1, data.szValue, 256 );
  2042. INT_PTR nResult = DialogBoxParam( g_hinst, MAKEINTRESOURCE( IDD_ADVANCED_EDIT ), hwndDlg, PropertyEditDialogProc, (LPARAM) &data );
  2043. if( nResult )
  2044. {
  2045. ListView_SetItemText( hwndList, n, 1, data.szValue );
  2046. SendMessage( GetParent(hwndDlg), PSM_CHANGED, (WPARAM) hwndDlg, 0 );
  2047. }
  2048. }
  2049. }
  2050. break;
  2051. case WM_NOTIFY:
  2052. if( IDC_ACTIVEDIRECTORY_LIST_ADVANCED == wParam && NM_DBLCLK == ((LPNMHDR)lParam)->code )
  2053. {
  2054. CUDDISiteNode* pDatabaseServer = reinterpret_cast<CUDDISiteNode*>( GetWindowLongPtr( hwndDlg, GWLP_USERDATA ) );
  2055. HWND hwndList = GetDlgItem( hwndDlg, IDC_ACTIVEDIRECTORY_LIST_ADVANCED );
  2056. //
  2057. // The list was double-clicked
  2058. // use hit test to determine the item index
  2059. //
  2060. LPNMITEMACTIVATE pitem = (LPNMITEMACTIVATE) lParam;
  2061. LVHITTESTINFO htinfo;
  2062. ZeroMemory( &htinfo, sizeof( LVHITTESTINFO ) );
  2063. htinfo.pt = pitem->ptAction;
  2064. int n = ListView_SubItemHitTest( GetDlgItem( hwndDlg, IDC_ACTIVEDIRECTORY_LIST_ADVANCED ),&htinfo );
  2065. if( -1 != n )
  2066. {
  2067. PropertyData data;
  2068. data.pServer = pDatabaseServer;
  2069. ListView_GetItemText( hwndList, n, 0, data.szName, ARRAYLEN( data.szName ) );
  2070. ListView_GetItemText( hwndList, n, 1, data.szValue, ARRAYLEN( data.szValue ) );
  2071. INT_PTR nResult = DialogBoxParam( g_hinst, MAKEINTRESOURCE( IDD_ADVANCED_EDIT ), hwndDlg, PropertyEditDialogProc, (LPARAM) &data );
  2072. if( nResult )
  2073. {
  2074. ListView_SetItemText( hwndList, n, 1, data.szValue );
  2075. SendMessage( GetParent(hwndDlg), PSM_CHANGED, (WPARAM) hwndDlg, 0 );
  2076. }
  2077. }
  2078. }
  2079. else if( IDC_ACTIVEDIRECTORY_LIST_ADVANCED == wParam &&
  2080. LVN_ITEMCHANGED == ((LPNMHDR)lParam)->code )
  2081. {
  2082. HWND hwndList = GetDlgItem( hwndDlg, IDC_ACTIVEDIRECTORY_LIST_ADVANCED );
  2083. EnableWindow( GetDlgItem( hwndDlg, IDC_ADVANCED_BTN_EDIT ), ( ListView_GetSelectedCount( hwndList ) > 0 ) );
  2084. }
  2085. else if( PSN_APPLY == ((NMHDR *) lParam)->code )
  2086. {
  2087. CUDDISiteNode* pDatabaseServer = reinterpret_cast<CUDDISiteNode*>( GetWindowLongPtr( hwndDlg, GWLP_USERDATA ) );
  2088. //
  2089. // Loop through the items and add modified items to the change collection
  2090. //
  2091. HWND hwndList = GetDlgItem( hwndDlg, IDC_ACTIVEDIRECTORY_LIST_ADVANCED );
  2092. int n = ListView_GetNextItem( hwndList, -1, LVNI_ALL );
  2093. while( -1 != n )
  2094. {
  2095. _TCHAR szModified[ 2 ];
  2096. ListView_GetItemText( hwndList, n, 0, szModified, 2 );
  2097. if( NULL != szModified[ 0 ] )
  2098. {
  2099. _TCHAR szName[ 256 ];
  2100. _TCHAR szValue[ 256 ];
  2101. ListView_GetItemText( hwndList, n, 0, szName, ARRAYLEN( szName ) );
  2102. ListView_GetItemText( hwndList, n, 1, szValue, ARRAYLEN( szValue ) );
  2103. pDatabaseServer->m_mapChanges[ szName ] = szValue;
  2104. }
  2105. n = ListView_GetNextItem( hwndList, n, LVNI_ALL );
  2106. }
  2107. //
  2108. // Ask MMC to send us a message (on the main thread) so
  2109. // we know the Apply button was clicked.
  2110. //
  2111. HRESULT hr = MMCPropertyChangeNotify( pDatabaseServer->m_ppHandle, reinterpret_cast<LONG_PTR>( pDatabaseServer ) );
  2112. _ASSERT( SUCCEEDED(hr) );
  2113. return PSNRET_NOERROR;
  2114. }
  2115. else if( PSN_HELP == ((NMHDR *) lParam)->code )
  2116. {
  2117. CUDDISiteNode* pDatabaseServer = reinterpret_cast<CUDDISiteNode*>( GetWindowLongPtr( hwndDlg, GWLP_USERDATA ) );
  2118. wstring strHelp( pDatabaseServer->GetHelpFile() );
  2119. strHelp += g_wszUddiAdvancedPageHelp;
  2120. ::HtmlHelp( hwndDlg, strHelp.c_str(), HH_DISPLAY_TOPIC, NULL );
  2121. }
  2122. break;
  2123. case WM_HELP:
  2124. {
  2125. CUDDISiteNode* pDatabaseServer = reinterpret_cast<CUDDISiteNode*>( GetWindowLongPtr( hwndDlg, GWLP_USERDATA ) );
  2126. wstring strHelp( pDatabaseServer->GetHelpFile() );
  2127. strHelp += g_wszUddiAdvancedPageHelp;
  2128. ::HtmlHelp( hwndDlg, strHelp.c_str(), HH_DISPLAY_TOPIC, NULL );
  2129. }
  2130. }
  2131. return FALSE;
  2132. }
  2133. BOOL CALLBACK CUDDISiteNode::PropertyEditDialogProc( HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam )
  2134. {
  2135. switch( uMsg )
  2136. {
  2137. case WM_INITDIALOG:
  2138. {
  2139. PropertyData* pdata = (PropertyData*) lParam;
  2140. SetWindowLongPtr( hwndDlg, GWLP_USERDATA, reinterpret_cast<LONG_PTR>( pdata ) );
  2141. SetDlgItemText( hwndDlg, IDC_ADVANCED_EDIT_TXT_NAME, pdata->szName );
  2142. SetDlgItemText( hwndDlg, IDC_ADVANCED_EDIT_VALUE, pdata->szValue );
  2143. break;
  2144. }
  2145. case WM_HELP:
  2146. {
  2147. PropertyData* pdata = reinterpret_cast<PropertyData*>( GetWindowLongPtrA( hwndDlg, GWLP_USERDATA ) );
  2148. wstring strHelp( pdata->pServer->GetHelpFile() );
  2149. strHelp += g_wszUddiEditPropertyHelp;
  2150. ::HtmlHelp( hwndDlg, strHelp.c_str(), HH_DISPLAY_TOPIC, NULL );
  2151. break;
  2152. }
  2153. case WM_COMMAND:
  2154. if( IDOK == LOWORD( wParam ) )
  2155. {
  2156. PropertyData* pdata = reinterpret_cast<PropertyData*>( GetWindowLongPtrA( hwndDlg, GWLP_USERDATA ) );
  2157. GetDlgItemText( hwndDlg, IDC_ADVANCED_EDIT_VALUE, pdata->szValue, sizeof( pdata->szValue ) / sizeof( _TCHAR ) );
  2158. EndDialog( hwndDlg, TRUE );
  2159. return FALSE;
  2160. }
  2161. else if( IDCANCEL == LOWORD( wParam ) )
  2162. {
  2163. EndDialog( hwndDlg, FALSE );
  2164. return FALSE;
  2165. }
  2166. else if( IDHELP == LOWORD( wParam ) )
  2167. {
  2168. PropertyData* pdata = reinterpret_cast<PropertyData*>( GetWindowLongPtrA( hwndDlg, GWLP_USERDATA ) );
  2169. wstring strHelp( pdata->pServer->GetHelpFile() );
  2170. strHelp += g_wszUddiEditPropertyHelp;
  2171. ::HtmlHelp( hwndDlg, strHelp.c_str(), HH_DISPLAY_TOPIC, NULL );
  2172. }
  2173. break;
  2174. }
  2175. return FALSE;
  2176. }
  2177. BOOL CALLBACK CUDDISiteNode::NewDatabaseServerDialogProc( HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam )
  2178. {
  2179. static DatabaseData* pData = NULL;
  2180. switch( uMsg )
  2181. {
  2182. case WM_INITDIALOG:
  2183. {
  2184. WCHAR wszBuf[ 256 ];
  2185. wszBuf[ 0 ] = 0x00;
  2186. DWORD dwBufSize = 256;
  2187. GetComputerName( wszBuf, &dwBufSize );
  2188. pData = reinterpret_cast<DatabaseData*>(lParam);
  2189. BOOL fChildExists = FALSE;
  2190. if( pData && pData->pBase )
  2191. {
  2192. if( pData->pBase->ChildExists( wszBuf ) )
  2193. {
  2194. fChildExists = TRUE;
  2195. }
  2196. }
  2197. if( IsDatabaseServer( _T("") ) && !fChildExists )
  2198. {
  2199. SendDlgItemMessage( hwndDlg, IDC_SITE_CONNECT_RADIO_LOCALCOMPUTER, BM_SETCHECK, TRUE, NULL );
  2200. EnableWindow( GetDlgItem( hwndDlg, IDOK ), TRUE );
  2201. RefreshInstances( GetDlgItem( hwndDlg, IDC_SITE_CONNECT_TXT_DATABASE_INSTANCE ) );
  2202. }
  2203. else
  2204. {
  2205. EnableWindow( GetDlgItem( hwndDlg, IDC_SITE_CONNECT_RADIO_LOCALCOMPUTER ), FALSE );
  2206. EnableWindow( GetDlgItem( hwndDlg, IDC_SITE_CONNECT_BTN_BROWSE ), TRUE );
  2207. EnableWindow( GetDlgItem( hwndDlg, IDC_SITE_CONNECT_EDIT_ANOTHERCOMPUTER ), TRUE );
  2208. EnableWindow( GetDlgItem( hwndDlg, IDOK ), FALSE );
  2209. SetDlgItemText( hwndDlg, IDC_SITE_CONNECT_TXT_DATABASE_INSTANCE, _T("") );
  2210. SendDlgItemMessage( hwndDlg, IDC_SITE_CONNECT_RADIO_ANOTHERCOMPUTER, BM_SETCHECK, TRUE, NULL );
  2211. SetFocus( GetDlgItem( hwndDlg, IDC_SITE_CONNECT_EDIT_ANOTHERCOMPUTER ) );
  2212. }
  2213. break;
  2214. }
  2215. case WM_HELP:
  2216. {
  2217. wstring strHelp( pData->pBase->GetHelpFile() );
  2218. strHelp += g_wszUddiAddSiteHelp;
  2219. ::HtmlHelp( hwndDlg, strHelp.c_str(), HH_DISPLAY_TOPIC, NULL );
  2220. break;
  2221. }
  2222. case WM_COMMAND:
  2223. {
  2224. switch( LOWORD(wParam) )
  2225. {
  2226. case IDC_SITE_CONNECT_RADIO_LOCALCOMPUTER:
  2227. {
  2228. EnableWindow( GetDlgItem( hwndDlg, IDC_SITE_CONNECT_BTN_BROWSE ), FALSE );
  2229. EnableWindow( GetDlgItem( hwndDlg, IDC_SITE_CONNECT_EDIT_ANOTHERCOMPUTER ), FALSE );
  2230. EnableWindow( GetDlgItem( hwndDlg, IDOK ), TRUE );
  2231. RefreshInstances( GetDlgItem( hwndDlg, IDC_SITE_CONNECT_TXT_DATABASE_INSTANCE ) );
  2232. break;
  2233. }
  2234. case IDC_SITE_CONNECT_RADIO_ANOTHERCOMPUTER:
  2235. {
  2236. EnableWindow( GetDlgItem( hwndDlg, IDC_SITE_CONNECT_BTN_BROWSE ), TRUE );
  2237. EnableWindow( GetDlgItem( hwndDlg, IDC_SITE_CONNECT_EDIT_ANOTHERCOMPUTER ), TRUE );
  2238. WCHAR wszComputerName[ 256 ];
  2239. wszComputerName[ 0 ] = 0x00;
  2240. GetDlgItemText( hwndDlg, IDC_SITE_CONNECT_EDIT_ANOTHERCOMPUTER, wszComputerName, ARRAYLEN( wszComputerName ) );
  2241. //
  2242. // Enable the OK button only if there is some sort of text
  2243. // in the edit control where the computer name is supposed
  2244. // to be typed in.
  2245. //
  2246. EnableWindow( GetDlgItem( hwndDlg, IDOK ), 0 == wcslen( wszComputerName ) ? FALSE : TRUE );
  2247. if( 0 == _tcslen( wszComputerName ) )
  2248. SetDlgItemText( hwndDlg, IDC_SITE_CONNECT_TXT_DATABASE_INSTANCE, _T("") );
  2249. else
  2250. RefreshInstances( GetDlgItem( hwndDlg, IDC_SITE_CONNECT_TXT_DATABASE_INSTANCE ), wszComputerName );
  2251. break;
  2252. }
  2253. case IDC_SITE_CONNECT_EDIT_ANOTHERCOMPUTER:
  2254. {
  2255. if( EN_CHANGE == HIWORD(wParam) )
  2256. {
  2257. SetDlgItemText( hwndDlg, IDC_SITE_CONNECT_TXT_DATABASE_INSTANCE, _T("") );
  2258. WCHAR wszComputerName[ 256 ];
  2259. wszComputerName[ 0 ] = 0x00;
  2260. GetDlgItemText( hwndDlg, IDC_SITE_CONNECT_EDIT_ANOTHERCOMPUTER, wszComputerName, ARRAYLEN( wszComputerName ) );
  2261. //
  2262. // Enable the OK button only if there is some sort of text
  2263. // in the edit control where the computer name is supposed
  2264. // to be typed in.
  2265. //
  2266. EnableWindow( GetDlgItem( hwndDlg, IDOK ), 0 == wcslen( wszComputerName ) ? FALSE : TRUE );
  2267. }
  2268. break;
  2269. }
  2270. case IDC_SITE_CONNECT_BTN_BROWSE:
  2271. {
  2272. _TCHAR szComputerName[ 256 ];
  2273. if( ObjectPicker( hwndDlg, OT_Computer, szComputerName, ARRAYLEN( szComputerName ) ) )
  2274. {
  2275. SetDlgItemText( hwndDlg, IDC_SITE_CONNECT_EDIT_ANOTHERCOMPUTER, szComputerName );
  2276. RefreshInstances( GetDlgItem( hwndDlg, IDC_SITE_CONNECT_TXT_DATABASE_INSTANCE ), szComputerName );
  2277. }
  2278. break;
  2279. }
  2280. case IDHELP:
  2281. {
  2282. wstring strHelp( pData->pBase->GetHelpFile() );
  2283. strHelp += g_wszUddiAddSiteHelp;
  2284. ::HtmlHelp( hwndDlg, strHelp.c_str(), HH_DISPLAY_TOPIC, NULL );
  2285. break;
  2286. }
  2287. case IDOK:
  2288. {
  2289. DWORD dwSize = 256;
  2290. if( SendDlgItemMessage( hwndDlg, IDC_SITE_CONNECT_RADIO_LOCALCOMPUTER, BM_GETCHECK, NULL, NULL ) )
  2291. {
  2292. //
  2293. // The user chose to use the database on the local computer.
  2294. //
  2295. pData->szServerName[ 0 ] = 0;
  2296. GetComputerName( pData->szServerName, &dwSize );
  2297. }
  2298. else
  2299. {
  2300. //
  2301. // The user chose to go with whatever they typed in for a computer name.
  2302. //
  2303. GetDlgItemText( hwndDlg, IDC_SITE_CONNECT_EDIT_ANOTHERCOMPUTER, pData->szServerName, dwSize );
  2304. static const tstring szLocalhost = _T("localhost");
  2305. //
  2306. // If the user typed in 'localhost', we have to switch it. Must be
  2307. // careful though... 'localhostabc' is a 100% legal computer name.
  2308. //
  2309. if( ( szLocalhost.length() == _tcslen( pData->szServerName ) ) && ( 0 == _tcsncicmp( szLocalhost.c_str(), pData->szServerName, szLocalhost.length() ) ) )
  2310. {
  2311. dwSize = 256;
  2312. pData->szServerName[ 0 ] = 0;
  2313. GetComputerName( pData->szServerName, &dwSize );
  2314. //
  2315. // If there is no UDDI database installed on the local computer,
  2316. // tell the user & force them to re-select.
  2317. //
  2318. if( !CUDDISiteNode::IsDatabaseServer( pData->szServerName ) )
  2319. {
  2320. _TCHAR szTitle[ 256 ];
  2321. _TCHAR szMessage[ 1024 ];
  2322. LoadString( g_hinst, IDS_DATABASE_SERVER_SELECT_ERROR, szMessage, ARRAYLEN( szMessage ) );
  2323. LoadString( g_hinst, IDS_DATABASE_SERVER_SELECT_ERROR_TITLE, szTitle, ARRAYLEN( szTitle ) );
  2324. MessageBox( hwndDlg, szMessage, szTitle, MB_ICONERROR );
  2325. return FALSE;
  2326. }
  2327. }
  2328. }
  2329. if( 0 == _tcslen( pData->szServerName ) || !CUDDISiteNode::IsDatabaseServer( pData->szServerName ) )
  2330. {
  2331. _TCHAR szTitle[ 256 ];
  2332. _TCHAR szMessage[ 1024 ];
  2333. LoadString( g_hinst, IDS_DATABASE_SERVER_SELECT_ERROR, szMessage, ARRAYLEN( szMessage ) );
  2334. LoadString( g_hinst, IDS_DATABASE_SERVER_SELECT_ERROR_TITLE, szTitle, ARRAYLEN( szTitle ) );
  2335. MessageBox( hwndDlg, szMessage, szTitle, MB_ICONERROR );
  2336. return FALSE;
  2337. }
  2338. //
  2339. // Copy the instance name into the structure
  2340. //
  2341. tstring strLocalInstanceName;
  2342. BOOL bSuccess = CUDDISiteNode::GetFullyQualifiedInstanceName( pData->szServerName, strLocalInstanceName );
  2343. _tcsncpy( pData->szInstanceName, strLocalInstanceName.c_str(), ARRAYLEN( pData->szInstanceName ) );
  2344. pData->szInstanceName[ ARRAYLEN( pData->szInstanceName ) - 1 ] = NULL;
  2345. ToUpper( pData->szServerName );
  2346. EndDialog( hwndDlg, TRUE );
  2347. return TRUE;
  2348. }
  2349. case IDCANCEL:
  2350. {
  2351. EndDialog( hwndDlg, FALSE );
  2352. return TRUE;
  2353. }
  2354. }
  2355. }
  2356. case WM_DESTROY:
  2357. {
  2358. break;
  2359. }
  2360. }
  2361. return FALSE;
  2362. }
  2363. BOOL GetInstances( PTCHAR szComputer, StringVector& instances )
  2364. {
  2365. try
  2366. {
  2367. CUDDIRegistryKey key( _T("SOFTWARE\\Microsoft\\Microsoft SQL Server" ), KEY_READ, szComputer );
  2368. key.GetMultiString( _T("InstalledInstances"), instances );
  2369. }
  2370. catch(...)
  2371. {
  2372. }
  2373. return ( 0 != instances.size() );
  2374. }
  2375. //
  2376. // This function will look at the registry of the specifed
  2377. // computer and determine it hosts a UDDI Services Database
  2378. // Component. If it does it will set the text of the specified
  2379. // control and return TRUE.
  2380. //
  2381. BOOL RefreshInstances( HWND hwnd, PTCHAR szComputerName )
  2382. {
  2383. try
  2384. {
  2385. _TCHAR szText[ 512 ];
  2386. _TCHAR szComputer[ 256 ];
  2387. DWORD dwSize = ARRAYLEN( szComputer );
  2388. if( 0 == _tcslen( szComputerName ) )
  2389. {
  2390. szComputer[ 0 ] = 0;
  2391. ::GetComputerName( szComputer, &dwSize );
  2392. }
  2393. else
  2394. {
  2395. _tcsncpy( szComputer, szComputerName, ARRAYLEN( szComputer ) - 1 );
  2396. szComputer[ ARRAYLEN( szComputer ) - 1 ] = NULL;
  2397. }
  2398. BOOL bFound = FALSE;
  2399. StringVector instances;
  2400. if( GetInstances( szComputer, instances ) )
  2401. {
  2402. CUDDIRegistryKey dbkey( _T( "SOFTWARE\\Microsoft\\UDDI\\Setup\\DBServer" ), KEY_READ, szComputer );
  2403. tstring strInstance = dbkey.GetString( _T( "InstanceNameOnly" ), _T("----") );
  2404. dbkey.Close();
  2405. if( _T("----") != strInstance )
  2406. {
  2407. for( StringVector::iterator iter = instances.begin();
  2408. iter != instances.end() && !bFound; iter++ )
  2409. {
  2410. if( 0 == _tcsicmp( strInstance.c_str(), InstanceDisplayName( (*iter).c_str() ) ) )
  2411. {
  2412. _TCHAR szTemplate[ 512 ];
  2413. LoadString( g_hinst, IDS_SITE_CONNECT_INSTANCE_FOUND_TEMPLATE, szTemplate, ARRAYLEN( szTemplate ) );
  2414. _sntprintf( szText, ARRAYLEN( szText ), szTemplate, strInstance.c_str() );
  2415. szText[ ARRAYLEN( szText ) - 1 ] = NULL;
  2416. bFound = TRUE;
  2417. }
  2418. }
  2419. }
  2420. }
  2421. if( !bFound )
  2422. {
  2423. LoadString( g_hinst, IDS_SITE_CONNECT_NO_INSTANCES_FOUND, szText, ARRAYLEN( szText ) );
  2424. }
  2425. SetWindowText( hwnd, szText );
  2426. return TRUE;
  2427. }
  2428. catch( ... )
  2429. {
  2430. return FALSE;
  2431. }
  2432. }
  2433. _TCHAR szDefaultInstance[ 256 ] = _T("");
  2434. _TCHAR* DefaultInstanceDisplayName()
  2435. {
  2436. if( !szDefaultInstance[ 0 ] )
  2437. {
  2438. ::LoadString( g_hinst, IDS_DATABASE_SERVER_DEFAULT_INSTANCE, szDefaultInstance, ARRAYLEN( szDefaultInstance ) );
  2439. }
  2440. return (_TCHAR*) szDefaultInstance;
  2441. }
  2442. const _TCHAR szDefaultRealName[] = _T("");
  2443. LPCTSTR InstanceDisplayName( LPCTSTR szName )
  2444. {
  2445. if( tstring( szName ) == tstring( _T("MSSQLSERVER") ) ||
  2446. 0 == _tcslen( szName ) )
  2447. {
  2448. return DefaultInstanceDisplayName();
  2449. }
  2450. else
  2451. return szName;
  2452. }
  2453. LPCTSTR InstanceRealName( LPCTSTR szName )
  2454. {
  2455. if( tstring( szName ) == tstring( DefaultInstanceDisplayName() ) )
  2456. {
  2457. return szDefaultRealName;
  2458. }
  2459. else
  2460. return szName;
  2461. }
  2462. void
  2463. CUDDISiteNode::HandleOLEDBError( HRESULT hrErr )
  2464. {
  2465. CDBErrorInfo ErrorInfo;
  2466. ULONG cRecords = 0;
  2467. HRESULT hr;
  2468. ULONG i;
  2469. CComBSTR bstrDesc, bstrHelpFile, bstrSource, bstrMsg;
  2470. GUID guid;
  2471. DWORD dwHelpContext;
  2472. WCHAR wszGuid[40];
  2473. USES_CONVERSION;
  2474. // If the user passed in an HRESULT then trace it
  2475. if( hrErr != S_OK )
  2476. {
  2477. TCHAR sz[ 256 ];
  2478. _sntprintf( sz, 256, _T("OLE DB Error Record dump for hr = 0x%x\n"), hrErr );
  2479. sz[ 255 ] = 0x00;
  2480. bstrMsg += sz;
  2481. }
  2482. LCID lcLocale = GetSystemDefaultLCID();
  2483. hr = ErrorInfo.GetErrorRecords(&cRecords);
  2484. if( FAILED(hr) && ( ErrorInfo.m_spErrorInfo == NULL ) )
  2485. {
  2486. TCHAR sz[ 256 ];
  2487. _sntprintf( sz, 256, _T("No OLE DB Error Information found: hr = 0x%x\n"), hr );
  2488. sz[ 255 ] = 0x00;
  2489. bstrMsg += sz;
  2490. }
  2491. else
  2492. {
  2493. for( i = 0; i < cRecords; i++ )
  2494. {
  2495. hr = ErrorInfo.GetAllErrorInfo(i, lcLocale, &bstrDesc, &bstrSource, &guid,
  2496. &dwHelpContext, &bstrHelpFile);
  2497. if( FAILED(hr) )
  2498. {
  2499. TCHAR sz[ 256 ];
  2500. _sntprintf( sz, 256, _T("OLE DB Error Record dump retrieval failed: hr = 0x%x\n"), hr );
  2501. sz[ 255 ] = 0x00;
  2502. bstrMsg += sz;
  2503. break;
  2504. }
  2505. StringFromGUID2( guid, wszGuid, sizeof(wszGuid) / sizeof(WCHAR) );
  2506. TCHAR sz[ 256 ];
  2507. _sntprintf(
  2508. sz, 256,
  2509. _T("Row #: %4d Source: \"%s\" Description: \"%s\" Help File: \"%s\" Help Context: %4d GUID: %s\n"),
  2510. i, OLE2T(bstrSource), OLE2T(bstrDesc), OLE2T(bstrHelpFile), dwHelpContext, OLE2T(wszGuid) );
  2511. sz[ 255 ] = 0x00;
  2512. bstrMsg += sz;
  2513. bstrSource.Empty();
  2514. bstrDesc.Empty();
  2515. bstrHelpFile.Empty();
  2516. }
  2517. bstrMsg += _T("OLE DB Error Record dump end\n");
  2518. throw CUDDIException( hrErr, wstring( bstrMsg.m_str ) );
  2519. }
  2520. }
  2521. void
  2522. CUDDISiteNode::ClearChildMap()
  2523. {
  2524. for( CUDDIWebServerNodeMap::iterator iter = m_mapChildren.begin();
  2525. iter != m_mapChildren.end(); iter++ )
  2526. {
  2527. delete iter->second;
  2528. iter->second = NULL;
  2529. }
  2530. m_mapChildren.clear();
  2531. }
  2532. BOOL
  2533. CUDDISiteNode::LoadChildMap( const tstring& szWebServers )
  2534. {
  2535. BOOL fRet = FALSE;
  2536. //
  2537. // Blow away any current children.
  2538. //
  2539. ClearChildMap();
  2540. if( IsExtension() )
  2541. {
  2542. if( CUDDIWebServerNode::IsWebServer( m_szName ) )
  2543. {
  2544. tstring strDomain, strServer, strInstance, strWriter;
  2545. CUDDIWebServerNode::GetWriterConnectionString( m_szName, strWriter );
  2546. if( !strWriter.empty() )
  2547. {
  2548. CUDDIWebServerNode::CrackConnectionString( strWriter, strDomain, strServer, strInstance );
  2549. if( 0 == _tcsicmp( strServer.c_str(), m_szName ) )
  2550. {
  2551. UINT n = m_nNextChildID;
  2552. m_nNextChildID++;
  2553. CUDDIWebServerNode *pNode = new CUDDIWebServerNode( strServer.c_str(), n, this, m_bIsExtension );
  2554. AddChildEntry( pNode, n );
  2555. }
  2556. }
  2557. }
  2558. }
  2559. else
  2560. {
  2561. CStringCollection webServers( szWebServers );
  2562. int iWebServerCnt = webServers.Size();
  2563. for( int i = 0; i < iWebServerCnt; i++ )
  2564. {
  2565. const wstring& webServer = webServers[ i ];
  2566. //
  2567. // If the machine is hosting the UDDI Web Server, and if that Web Server is not already
  2568. // a part of this UDDI site, then add it.
  2569. //
  2570. if( CUDDIWebServerNode::IsWebServer( webServer.c_str() ) && ( NULL == FindChild( webServer.c_str() ) ) )
  2571. {
  2572. UINT n = m_nNextChildID;
  2573. m_nNextChildID++;
  2574. CUDDIWebServerNode *pNode = new CUDDIWebServerNode( webServer.c_str(), n, this, m_bIsExtension );
  2575. AddChildEntry( pNode, n );
  2576. }
  2577. }
  2578. fRet = TRUE;
  2579. if( 0 == m_mapChildren.size() )
  2580. {
  2581. if( CUDDIWebServerNode::IsWebServer( m_szName ) )
  2582. {
  2583. tstring szWriter, szDomain, szServer, szInstance;
  2584. CUDDIWebServerNode::GetWriterConnectionString( m_szName, szWriter );
  2585. if( !szWriter.empty() )
  2586. {
  2587. CUDDIWebServerNode::CrackConnectionString( szWriter, szDomain, szServer, szInstance );
  2588. if( 0 == _tcsicmp( szServer.c_str(), m_szName ) )
  2589. {
  2590. // add a node in our child map, change our list of writers
  2591. UINT n = m_mapChildren.size();
  2592. CUDDIWebServerNode *pNode = new CUDDIWebServerNode( m_szName, n, this, m_bIsExtension );
  2593. if( TRUE == AddChildEntry( pNode, n ) )
  2594. {
  2595. tstring szWriters;
  2596. SaveChildMap( szWriters );
  2597. m_mapChanges[ UDDI_SITE_WEBSERVERS ] = szWriters;
  2598. }
  2599. }
  2600. }
  2601. }
  2602. }
  2603. }
  2604. return fRet;
  2605. }
  2606. int
  2607. CUDDISiteNode::SaveChildMap( tstring& szWebServers )
  2608. {
  2609. szWebServers = _T("");
  2610. BOOL fFirst = TRUE;
  2611. CUDDIWebServerNodeMap::iterator it;
  2612. int cnt = 0;
  2613. for( it = m_mapChildren.begin(); it != m_mapChildren.end(); it++ )
  2614. {
  2615. CUDDIWebServerNode *pWS = it->second;
  2616. if( !pWS->IsDeleted() )
  2617. {
  2618. if( fFirst )
  2619. {
  2620. fFirst = FALSE;
  2621. }
  2622. else
  2623. {
  2624. szWebServers.append( _T("%") );
  2625. }
  2626. szWebServers.append( pWS->GetName() );
  2627. cnt++;
  2628. }
  2629. }
  2630. return cnt;
  2631. }
  2632. void
  2633. CUDDISiteNode::OnDeleteChild( const tstring& szName )
  2634. {
  2635. //
  2636. // The child node has already removed itself from the scope pane.
  2637. // We use this function to update our change map to reflect the
  2638. // fact that we now have 1 less Web Server writing to this DB.
  2639. //
  2640. tstring szWebServers;
  2641. SaveChildMap( szWebServers );
  2642. m_mapChanges[ UDDI_SITE_WEBSERVERS ] = szWebServers;
  2643. SaveData();
  2644. m_mapConfig[ UDDI_SITE_WEBSERVERS ] = szWebServers;
  2645. }
  2646. HRESULT
  2647. CUDDISiteNode::AddChildrenToScopePane( IConsoleNameSpace *pConsoleNameSpace, HSCOPEITEM parent )
  2648. {
  2649. HRESULT hr = E_FAIL;
  2650. if( ( NULL == pConsoleNameSpace ) || ( NULL == parent ) )
  2651. {
  2652. return E_INVALIDARG;
  2653. }
  2654. //
  2655. // Create the child nodes, then expand them
  2656. //
  2657. SCOPEDATAITEM sdi;
  2658. CUDDIWebServerNodeMap::iterator it;
  2659. for( it = m_mapChildren.begin(); it != m_mapChildren.end(); it++ )
  2660. {
  2661. CUDDIWebServerNode *pWSNode = it->second;
  2662. if( NULL == pWSNode )
  2663. {
  2664. hr = E_FAIL;
  2665. return hr;
  2666. }
  2667. if( !( pWSNode->IsDeleted() ) )
  2668. {
  2669. ZeroMemory( &sdi, sizeof(SCOPEDATAITEM) );
  2670. sdi.mask = SDI_STR | // Displayname is valid
  2671. SDI_PARAM | // lParam is valid
  2672. SDI_IMAGE | // nImage is valid
  2673. SDI_OPENIMAGE | // nOpenImage is valid
  2674. SDI_PARENT |
  2675. SDI_CHILDREN;
  2676. sdi.relativeID = parent;
  2677. sdi.nImage = pWSNode->GetBitmapIndex();
  2678. sdi.nOpenImage = MMC_IMAGECALLBACK; //INDEX_OPENFOLDER;
  2679. sdi.displayname = MMC_CALLBACK;
  2680. sdi.lParam = (LPARAM)pWSNode; // The cookie
  2681. sdi.cChildren = 0;
  2682. hr = pConsoleNameSpace->InsertItem( &sdi );
  2683. _ASSERT( SUCCEEDED(hr) );
  2684. pWSNode->SetScopeItemValue( sdi.ID );
  2685. pWSNode->SetParentScopeItem( sdi.relativeID );
  2686. }
  2687. }
  2688. hr = S_OK;
  2689. return hr;
  2690. }
  2691. HRESULT
  2692. CUDDISiteNode::GetConfig( CConfigMap& configMap, const tstring& connectionString )
  2693. {
  2694. tstring tempConnectionString( connectionString );
  2695. if( connectionString.find( _T("Provider=SQLOLEDB.1") ) == std::wstring::npos )
  2696. {
  2697. tempConnectionString.append( _T(";Provider=SQLOLEDB.1") );
  2698. }
  2699. net_config_get configGet;
  2700. configGet.m_connectionString = tempConnectionString.c_str();
  2701. DBROWCOUNT rowCount;
  2702. HRESULT hr = configGet.Open();
  2703. while( SUCCEEDED(hr) && hr != DB_S_NORESULT )
  2704. {
  2705. if( NULL != configGet.GetInterface() )
  2706. {
  2707. HRESULT hr2 = configGet.Bind();
  2708. if( SUCCEEDED( hr2 ) )
  2709. {
  2710. while( S_OK == configGet.MoveNext() )
  2711. {
  2712. _ASSERT( !configGet.m_dwconfigNameStatus );
  2713. _ASSERT( !configGet.m_dwconfigValueStatus );
  2714. configMap[ configGet.m_configName ] = configGet.m_configValue;
  2715. }
  2716. }
  2717. }
  2718. hr = configGet.GetNextResult( &rowCount );
  2719. }
  2720. return hr;
  2721. }
  2722. HRESULT
  2723. CUDDISiteNode::SaveConfig( CConfigMap& configMap, const tstring& connectionString )
  2724. {
  2725. tstring tempConnectionString( connectionString );
  2726. if( connectionString.find( _T("Provider=SQLOLEDB.1") ) == std::wstring::npos )
  2727. {
  2728. tempConnectionString.append( _T(";Provider=SQLOLEDB.1") );
  2729. }
  2730. HRESULT hr = E_FAIL;
  2731. for( CConfigMap::iterator iterator = configMap.begin(); iterator != configMap.end(); iterator++ )
  2732. {
  2733. net_config_save configSave;
  2734. configSave.m_connectionString = tempConnectionString.c_str();
  2735. OutputDebugString( (*iterator).first.c_str() );
  2736. OutputDebugString( _T(" = ") );
  2737. OutputDebugString( (*iterator).second.c_str() );
  2738. OutputDebugString( _T("\n") );
  2739. _tcsncpy( configSave.m_configName, (*iterator).first.c_str(), ARRAYLEN( configSave.m_configName ) - 1 );
  2740. configSave.m_configName[ ARRAYLEN( configSave.m_configName ) - 1 ] = 0x00;
  2741. _tcsncpy( configSave.m_configValue, (*iterator).second.c_str(), ARRAYLEN( configSave.m_configValue ) - 1 );
  2742. configSave.m_configValue[ ARRAYLEN( configSave.m_configValue ) - 1 ] = 0x00;
  2743. hr = configSave.Open();
  2744. if( FAILED(hr) || 0 != configSave.m_RETURNVALUE )
  2745. {
  2746. break;
  2747. }
  2748. }
  2749. return hr;
  2750. }
  2751. const _TCHAR *
  2752. CUDDISiteNode::GetNextWebServer( tstring& webServerList, int& position )
  2753. {
  2754. int length = webServerList.length();
  2755. int nextPosition = position;
  2756. const _TCHAR* webServer = NULL;
  2757. //
  2758. // No point if there no string.
  2759. //
  2760. if( 0 == length)
  2761. {
  2762. return NULL;
  2763. }
  2764. while( nextPosition < length && webServerList[nextPosition] != WEBSERVER_LIST_DELIM )
  2765. {
  2766. nextPosition++;
  2767. }
  2768. if( nextPosition < length )
  2769. {
  2770. webServerList[ nextPosition ] = NULL_TERMINATOR;
  2771. webServer = webServerList.c_str() + position;
  2772. }
  2773. else
  2774. {
  2775. webServer = ( 0 == position ) ? webServerList.c_str() : NULL;
  2776. }
  2777. position = nextPosition;
  2778. return webServer;
  2779. }
  2780. void
  2781. CUDDISiteNode::AddWebServer( tstring& webServerList, const tstring& webServer )
  2782. {
  2783. if( webServerList.length() > 0 )
  2784. {
  2785. webServerList += WEBSERVER_LIST_DELIM;
  2786. }
  2787. webServerList.append( webServer );
  2788. }
  2789. BOOL
  2790. CUDDISiteNode::AddChildEntry( CUDDIWebServerNode *pNode, UINT position )
  2791. {
  2792. CUDDIWebServerNodeMapEntry entry( position, pNode );
  2793. m_mapChildren.insert( entry );
  2794. return TRUE;
  2795. }
  2796. void
  2797. CUDDISiteNode::AddChild( const wstring& strName, IConsole *pConsole )
  2798. {
  2799. if( FindChild( strName.c_str() ) || ( NULL == pConsole ) )
  2800. {
  2801. return;
  2802. }
  2803. IConsoleNameSpace *pConsoleNameSpace = NULL;
  2804. pConsole->QueryInterface( IID_IConsoleNameSpace, reinterpret_cast<void **>( &pConsoleNameSpace ) );
  2805. if( NULL == pConsoleNameSpace )
  2806. {
  2807. return;
  2808. }
  2809. HRESULT hr;
  2810. CUDDIWebServerNode *pNewWS = new CUDDIWebServerNode( strName.c_str(), m_nNextChildID, this, m_bIsExtension );
  2811. m_nNextChildID++;
  2812. AddChildEntry( pNewWS );
  2813. SCOPEDATAITEM sdi;
  2814. ZeroMemory( &sdi, sizeof( SCOPEDATAITEM ) );
  2815. sdi.mask = SDI_STR | // Displayname is valid
  2816. SDI_PARAM | // lParam is valid
  2817. SDI_IMAGE | // nImage is valid
  2818. SDI_OPENIMAGE | // nOpenImage is valid
  2819. SDI_PARENT |
  2820. SDI_CHILDREN;
  2821. sdi.relativeID = GetScopeItemValue();
  2822. sdi.nImage = pNewWS->GetBitmapIndex();
  2823. sdi.nOpenImage = MMC_IMAGECALLBACK;
  2824. sdi.displayname = MMC_CALLBACK;
  2825. sdi.lParam = (LPARAM)pNewWS;
  2826. sdi.cChildren = pNewWS->HasChildren();
  2827. hr = pConsoleNameSpace->InsertItem( &sdi );
  2828. _ASSERT( SUCCEEDED(hr) );
  2829. pNewWS->SetScopeItemValue( sdi.ID );
  2830. pNewWS->SetParentScopeItem( sdi.relativeID );
  2831. //
  2832. // We created a new object in result pane. We need to insert this object
  2833. // in all the views, call UpdateAllViews for this.
  2834. // Pass pointer to data object passed into OnMenuCommand.
  2835. //
  2836. //hr = pConsole->UpdateAllViews( pDataObject, m_hParentHScopeItem, UPDATE_SCOPEITEM );
  2837. //_ASSERT( S_OK == hr);
  2838. //
  2839. // Prompt the user with a warning to tell them that they might have to alter their
  2840. // machine.config settings if this web server is part of a web farm.
  2841. //
  2842. WCHAR wszMessage[ 512 ];
  2843. WCHAR wszTitle[ 512 ];
  2844. memset( wszMessage, 0, 512 * sizeof( _TCHAR ) );
  2845. memset( wszTitle, 0, 128 * sizeof( _TCHAR ) );
  2846. LoadString( g_hinst, IDS_WEBSERVER_WEBFARM_DETAIL, wszMessage, ARRAYLEN( wszMessage ) );
  2847. LoadString( g_hinst, IDS_WEBSERVER_WEBFARM, wszTitle, ARRAYLEN( wszTitle ) );
  2848. HWND hwndConsole = NULL;
  2849. pConsole->GetMainWindow( &hwndConsole );
  2850. MessageBox( hwndConsole, wszMessage, wszTitle, MB_OK );
  2851. pConsoleNameSpace->Release();
  2852. }
  2853. BOOL
  2854. CUDDISiteNode::AddWebServerToSite( const wstring& strSite,
  2855. const wstring& strWebServer,
  2856. HWND hwndParent )
  2857. {
  2858. try
  2859. {
  2860. //
  2861. // Make sure our params at least have some sort of content!
  2862. //
  2863. if( ( 0 == strSite.length() ) || ( 0 == strWebServer.length() ) )
  2864. {
  2865. return FALSE;
  2866. }
  2867. //
  2868. // If strSite does not contain the name of a machine/cluster
  2869. // resource which hosts a UDDI Site, barf @ the user & exit
  2870. // immediately.
  2871. //
  2872. if( !CUDDISiteNode::IsDatabaseServer( (PTCHAR)strSite.c_str() ) )
  2873. {
  2874. UDDIMsgBox( hwndParent,
  2875. IDS_DATABASE_SERVER_SELECT_ERROR,
  2876. IDS_DATABASE_SERVER_SELECT_ERROR_TITLE,
  2877. MB_ICONEXCLAMATION | MB_OK );
  2878. return FALSE;
  2879. }
  2880. //
  2881. // If strWebServer does not contain the name of a machine
  2882. // which hosts a UDDI Web Server, barf @ the user & exit
  2883. // immediately.
  2884. //
  2885. if( !CUDDIWebServerNode::IsWebServer( strWebServer.c_str() ) )
  2886. {
  2887. UDDIMsgBox( hwndParent,
  2888. IDS_WEBSERVER_SELECT_ERROR,
  2889. IDS_WEBSERVER_SELECT_ERROR_TITLE,
  2890. MB_ICONEXCLAMATION | MB_OK );
  2891. return FALSE;
  2892. }
  2893. if( strSite != strWebServer )
  2894. {
  2895. //
  2896. // In this particular case the user is attempting to add to the UDDI Site a
  2897. // UDDI Web Server which is running on a Windows Server 2003 Standard machine. This cannot
  2898. // happen.
  2899. //
  2900. BOOL bWSRunsOnStdSvr = TRUE;
  2901. HRESULT hr = E_FAIL;
  2902. hr = ::IsStandardServer( strWebServer.c_str(), &bWSRunsOnStdSvr );
  2903. if( FAILED(hr) )
  2904. {
  2905. UDDIMsgBox( hwndParent,
  2906. IDS_DOT_NET_SERVER,
  2907. IDS_ERROR_TITLE,
  2908. MB_ICONEXCLAMATION | MB_OK );
  2909. return FALSE;
  2910. }
  2911. if( TRUE == bWSRunsOnStdSvr )
  2912. {
  2913. UDDIMsgBox( hwndParent,
  2914. IDS_WEBSERVER_NOT_ASSIGNABLE_DETAIL,
  2915. IDS_WEBSERVER_NOT_ASSIGNABLE,
  2916. MB_ICONEXCLAMATION | MB_OK );
  2917. return FALSE;
  2918. }
  2919. //
  2920. // In this particular case the user is attempting to add a UDDI Web Server
  2921. // to a UDDI Site which is running on a Windows Server 2003 Standard machine. This cannot
  2922. // happen.
  2923. //
  2924. BOOL bDBRunsOnStdSvr = TRUE;
  2925. hr = ::IsStandardServer( strSite.c_str(), &bDBRunsOnStdSvr );
  2926. if( FAILED(hr) )
  2927. {
  2928. UDDIMsgBox( hwndParent,
  2929. IDS_DOT_NET_SERVER,
  2930. IDS_ERROR_TITLE,
  2931. MB_ICONEXCLAMATION | MB_OK );
  2932. return FALSE;
  2933. }
  2934. if( TRUE == bDBRunsOnStdSvr )
  2935. {
  2936. UDDIMsgBox( hwndParent,
  2937. IDS_DATABASE_STANDARD_SERVER_DETAIL,
  2938. IDS_DATABASE_STANDARD_SERVER,
  2939. MB_ICONEXCLAMATION | MB_OK );
  2940. return FALSE;
  2941. }
  2942. }
  2943. //
  2944. // Do a check here to make sure the db schema on the new site
  2945. // is legit.
  2946. //
  2947. wstring strWSCurrentSite = _T( "" );
  2948. BOOL fWSCurrentSiteIsValid = FALSE;
  2949. BOOL fSameSite = FALSE;
  2950. BOOL fOKToMoveWebServer = FALSE;
  2951. //
  2952. // 1. Determine if the web server is: currently assigned to a site, if that
  2953. // site is valid, and if that site is the same as the new site.
  2954. //
  2955. if( CUDDIWebServerNode::IsAssignedToSite( strWebServer, CM_Writer, strWSCurrentSite ) )
  2956. {
  2957. //
  2958. // The web server thinks that it is currently assigned to a site. However we
  2959. // must take into consideration the following 2 cases:
  2960. //
  2961. // 1. The web server's connection string contains garbage.
  2962. // 2. The web server's connection string is valid, but the site that it
  2963. // refers to does not exist anymore.
  2964. //
  2965. if( ( 0 == strWSCurrentSite.length() ) ||
  2966. !CUDDISiteNode::IsDatabaseServer( (PTCHAR)strWSCurrentSite.c_str() ) )
  2967. {
  2968. fWSCurrentSiteIsValid = FALSE;
  2969. }
  2970. else
  2971. {
  2972. fWSCurrentSiteIsValid = TRUE;
  2973. }
  2974. //
  2975. // The user is trying to add the web server back to the same site that the
  2976. // web server thinks it belongs to. This can happen when the user un-installs
  2977. // and then re-installs the database.
  2978. //
  2979. fSameSite = ( 0 == _wcsicmp( strWSCurrentSite.c_str(), strSite.c_str() ) ) ? TRUE : FALSE;
  2980. //
  2981. // If the old site is valid, and if the site that the user wants isn't the
  2982. // old site, ask them if they are really sure.
  2983. //
  2984. if( fWSCurrentSiteIsValid && !fSameSite )
  2985. {
  2986. //
  2987. // First prompt the user to see if they really want to remove the web server from its current site.
  2988. //
  2989. WCHAR wszMessage[ 512 ];
  2990. WCHAR wszMessageFormat[ 512 ];
  2991. WCHAR wszTitle[ 128 ];
  2992. wszMessage[ 0 ] = 0x00;
  2993. wszTitle[ 0 ] = 0x00;
  2994. wszMessageFormat[ 0 ] = 0x00;
  2995. LoadString( g_hinst, IDS_WEBSERVER_ASSIGNED_DETAIL, wszMessageFormat, ARRAYLEN( wszMessageFormat ) );
  2996. _sntprintf( wszMessage,
  2997. ARRAYLEN(wszMessage) - 1,
  2998. wszMessageFormat,
  2999. strWebServer.c_str(),
  3000. strWSCurrentSite.c_str(),
  3001. strWebServer.c_str(),
  3002. strSite.c_str() );
  3003. LoadString( g_hinst, IDS_WEBSERVER_ASSIGNED, wszTitle, ARRAYLEN( wszTitle ) );
  3004. int iYesNo = MessageBox( hwndParent, wszMessage, wszTitle, MB_YESNO );
  3005. if( IDNO == iYesNo )
  3006. {
  3007. return FALSE;
  3008. }
  3009. else
  3010. {
  3011. fOKToMoveWebServer = TRUE;
  3012. }
  3013. }
  3014. //
  3015. // If we're in here, either the old site is bogus, or it's the same site.
  3016. // In either case, it's ok to move the web server.
  3017. //
  3018. else
  3019. {
  3020. fOKToMoveWebServer = TRUE;
  3021. }
  3022. }
  3023. else
  3024. {
  3025. fOKToMoveWebServer = TRUE;
  3026. }
  3027. //
  3028. // 2. Get the list of Web Servers that the old Site contains.
  3029. //
  3030. if( ( FALSE == fSameSite ) && fWSCurrentSiteIsValid )
  3031. {
  3032. HRESULT hr = E_FAIL;
  3033. CConfigMap configOldSite;
  3034. wstring strOldConnStr;
  3035. BOOL b = CUDDIWebServerNode::GetWriterConnectionString( strWebServer, strOldConnStr );
  3036. CUDDIWebServerNode::SetWriterConnectionString( strWebServer, L"" );
  3037. CUDDIWebServerNode::SetReaderConnectionString( strWebServer, L"" );
  3038. hr = GetConfig( configOldSite, strOldConnStr );
  3039. if( FAILED(hr) )
  3040. {
  3041. UDDIMsgBox( hwndParent,
  3042. IDS_DATABASE_SERVER_OLEDB_READ_FAILED,
  3043. IDS_DATABASE_SERVER_GETDATA_ERROR_TITLE,
  3044. MB_OK );
  3045. return FALSE;
  3046. }
  3047. CStringCollection oldSiteWebServers( configOldSite[ UDDI_SITE_WEBSERVERS ] );
  3048. oldSiteWebServers.DeleteString( strWebServer );
  3049. configOldSite[ UDDI_SITE_WEBSERVERS ] = oldSiteWebServers.GetDelimitedString();
  3050. hr = SaveConfig( configOldSite, strOldConnStr );
  3051. if( FAILED(hr) )
  3052. {
  3053. WCHAR wszMessageFormat[ 512 ];
  3054. WCHAR wszTitle[ 128 ];
  3055. memset( wszMessageFormat, 0, 512 * sizeof( WCHAR ) );
  3056. memset( wszTitle, 0, 128 * sizeof( WCHAR ) );
  3057. LoadString( g_hinst,
  3058. IDS_WEBSERVER_REMOVE_FAILED_DETAIL,
  3059. wszMessageFormat,
  3060. ARRAYLEN( wszMessageFormat ) );
  3061. TCHAR pwszFormatted[ 512 ];
  3062. pwszFormatted[ 0 ] = 0x00;
  3063. LPCTSTR pwszArgs[ 3 ] = { strWebServer.c_str(), strWSCurrentSite.c_str(), strSite.c_str() };
  3064. DWORD dwBytesWritten = FormatMessage( FORMAT_MESSAGE_FROM_STRING | FORMAT_MESSAGE_ARGUMENT_ARRAY,
  3065. (LPCVOID)wszMessageFormat,
  3066. 0,
  3067. 0,
  3068. pwszFormatted,
  3069. 512,
  3070. (va_list *)pwszArgs
  3071. );
  3072. LoadString( g_hinst,
  3073. IDS_WEBSERVER_REMOVE_FAILED,
  3074. wszTitle,
  3075. ARRAYLEN( wszTitle ) );
  3076. int iYesNo = MessageBox( hwndParent,
  3077. pwszFormatted,
  3078. wszTitle,
  3079. MB_ICONEXCLAMATION | MB_YESNO );
  3080. //
  3081. // User does not want to continue.
  3082. //
  3083. if( IDNO == iYesNo )
  3084. {
  3085. CUDDIWebServerNode::SetReaderConnectionString( strWebServer, strOldConnStr );
  3086. CUDDIWebServerNode::SetWriterConnectionString( strWebServer, strOldConnStr );
  3087. return FALSE;
  3088. }
  3089. }
  3090. }
  3091. //
  3092. // 3. Get the list of Web Servers that the new Site contains.
  3093. //
  3094. if( fOKToMoveWebServer )
  3095. {
  3096. HRESULT hr = E_FAIL;
  3097. CConfigMap configNewSite;
  3098. wstring strNewConnStr;
  3099. strNewConnStr = CUDDIWebServerNode::BuildConnectionString( strSite );
  3100. hr = GetConfig( configNewSite, strNewConnStr );
  3101. if( FAILED(hr) )
  3102. {
  3103. UDDIMsgBox( hwndParent,
  3104. IDS_DATABASE_SERVER_OLEDB_READ_FAILED,
  3105. IDS_DATABASE_SERVER_GETDATA_ERROR_TITLE,
  3106. MB_OK );
  3107. return FALSE;
  3108. }
  3109. wstring strWSSchemaVersion;
  3110. if( !CUDDIWebServerNode::GetDBSchemaVersion( strWebServer, strWSSchemaVersion ) )
  3111. {
  3112. WCHAR wszTitle[ 256 ];
  3113. WCHAR wszMessageFormat[ 512 ];
  3114. WCHAR wszMessage[ 512 ];
  3115. memset( wszMessage, 0, 512 * sizeof( WCHAR ) );
  3116. memset( wszMessageFormat, 0, 512 * sizeof( WCHAR ) );
  3117. LoadString( g_hinst, IDS_ERROR_TITLE, wszTitle, ARRAYLEN( wszTitle ) );
  3118. LoadString( g_hinst, IDS_WEBSERVER_SERVER_DBSCHEMA_VERSION_READ_FAILED, wszMessageFormat, ARRAYLEN( wszMessageFormat ) );
  3119. _sntprintf( wszMessage, ARRAYLEN( wszMessage ) - 1, wszMessageFormat, strWebServer.c_str() );
  3120. MessageBox( hwndParent, wszMessage, wszTitle, MB_ICONERROR );
  3121. return FALSE;
  3122. }
  3123. CDBSchemaVersion schemaVersionWS;
  3124. if( !schemaVersionWS.Parse( strWSSchemaVersion ) )
  3125. {
  3126. _TCHAR szTitle[ 256 ];
  3127. _TCHAR szMessageFormat[ 512 ];
  3128. _TCHAR szMessage[ 512 ];
  3129. memset( szMessage, 0, 512 * sizeof( _TCHAR ) );
  3130. memset( szMessageFormat, 0, 512 * sizeof( _TCHAR ) );
  3131. LoadString( g_hinst, IDS_ERROR_TITLE, szTitle, ARRAYLEN( szTitle ) );
  3132. LoadString( g_hinst, IDS_INVALID_VERSION_FORMAT, szMessageFormat, ARRAYLEN( szMessageFormat ) );
  3133. _sntprintf( szMessage, ARRAYLEN( szMessage ) - 1, szMessageFormat, strWebServer );
  3134. MessageBox( hwndParent, szMessage, szTitle, MB_ICONERROR );
  3135. return FALSE;
  3136. }
  3137. CDBSchemaVersion schemaVersionNewSite;
  3138. if( !schemaVersionNewSite.Parse( configNewSite[ UDDI_DBSCHEMA_VERSION ] ) )
  3139. {
  3140. _TCHAR szTitle[ 256 ];
  3141. _TCHAR szMessageFormat[ 512 ];
  3142. _TCHAR szMessage[ 512 ];
  3143. memset( szMessage, 0, 512 * sizeof( _TCHAR ) );
  3144. memset( szMessageFormat, 0, 512 * sizeof( _TCHAR ) );
  3145. LoadString( g_hinst, IDS_ERROR_TITLE, szTitle, ARRAYLEN( szTitle ) );
  3146. LoadString( g_hinst, IDS_DATABASE_SERVER_DBSCHEMA_VERSION_READ_FAILED, szMessageFormat, ARRAYLEN( szMessageFormat ) );
  3147. _sntprintf( szMessage, ARRAYLEN( szMessage ) - 1, szMessageFormat, strSite );
  3148. MessageBox( hwndParent, szMessage, szTitle, MB_ICONERROR );
  3149. return FALSE;
  3150. }
  3151. //
  3152. // Make sure the web server version is compatible.
  3153. //
  3154. if( FALSE == schemaVersionNewSite.IsCompatible( schemaVersionWS ) )
  3155. {
  3156. _TCHAR szTitle[ 256 ];
  3157. _TCHAR szMessage[ 1024 ];
  3158. _TCHAR szMessageFormat[ 512 ];
  3159. memset( szTitle, 0, 256 * sizeof( _TCHAR ) );
  3160. memset( szMessage, 0, 1024 * sizeof( _TCHAR ) );
  3161. memset( szMessageFormat, 0, 512 * sizeof( _TCHAR ) );
  3162. LoadString( g_hinst, IDS_ERROR_TITLE, szTitle, ARRAYLEN( szTitle ) );
  3163. LoadString( g_hinst, IDS_WEBSERVER_SERVER_INVALID_DBSCHEMA_VERSION, szMessageFormat, ARRAYLEN( szMessageFormat ) );
  3164. _sntprintf( szMessage,
  3165. ARRAYLEN( szMessage ) - 1,
  3166. szMessageFormat,
  3167. strWebServer.c_str(),
  3168. schemaVersionWS.szVersion.c_str(),
  3169. strSite.c_str(),
  3170. schemaVersionNewSite.szVersion.c_str() );
  3171. MessageBox( hwndParent, szMessage, szTitle, MB_ICONERROR );
  3172. return FALSE;
  3173. }
  3174. CStringCollection newSiteWebServers( configNewSite[ UDDI_SITE_WEBSERVERS ] );
  3175. if( newSiteWebServers.Exists( strWebServer ) && fSameSite )
  3176. {
  3177. WCHAR wszMessage[ 256 ];
  3178. WCHAR wszTitle[ 256 ];
  3179. wszMessage[ 0 ] = 0x00;
  3180. wszTitle[ 0 ] = 0x00;
  3181. LoadString( g_hinst, IDS_WEBSERVER_ALREADY_EXISTS, wszMessage, ARRAYLEN( wszMessage ) );
  3182. LoadString( g_hinst, IDS_WEBSERVER_SELECT_ERROR_TITLE, wszTitle, ARRAYLEN( wszTitle ) );
  3183. MessageBox( hwndParent, wszMessage, wszTitle, MB_OK );
  3184. return FALSE;
  3185. }
  3186. newSiteWebServers.AddString( strWebServer );
  3187. configNewSite[ UDDI_SITE_WEBSERVERS ] = newSiteWebServers.GetDelimitedString();
  3188. hr = SaveConfig( configNewSite, strNewConnStr );
  3189. if( FAILED(hr) )
  3190. {
  3191. WCHAR wszMessage[ 512 ];
  3192. WCHAR wszMessageFormat[ 512 ];
  3193. WCHAR wszTitle[ 128 ];
  3194. memset( wszMessage, 0, 512 * sizeof( WCHAR ) );
  3195. memset( wszMessageFormat, 0, 512 * sizeof( WCHAR ) );
  3196. memset( wszTitle, 0, 128 * sizeof( WCHAR ) );
  3197. LoadString( g_hinst,
  3198. IDS_WEBSERVER_ADD_FAILED_DETAIL,
  3199. wszMessageFormat,
  3200. ARRAYLEN( wszMessageFormat ) );
  3201. _sntprintf( wszMessage,
  3202. ARRAYLEN(wszMessage) - 1,
  3203. wszMessageFormat,
  3204. strWebServer.c_str(),
  3205. strSite.c_str() );
  3206. LoadString( g_hinst,
  3207. IDS_WEBSERVER_ADD_FAILED,
  3208. wszTitle,
  3209. ARRAYLEN( wszTitle ) );
  3210. MessageBox( hwndParent,
  3211. wszMessage,
  3212. wszTitle,
  3213. MB_ICONEXCLAMATION | MB_YESNO );
  3214. CUDDIWebServerNode::SetReaderConnectionString( strWebServer, L"" );
  3215. CUDDIWebServerNode::SetWriterConnectionString( strWebServer, L"" );
  3216. return FALSE;
  3217. }
  3218. CUDDIWebServerNode::SetReaderConnectionString( strWebServer, strNewConnStr );
  3219. CUDDIWebServerNode::SetWriterConnectionString( strWebServer, strNewConnStr );
  3220. }
  3221. return TRUE;
  3222. }
  3223. catch( CUDDIException &e )
  3224. {
  3225. UDDIMsgBox( hwndParent, (LPCTSTR) e, IDS_ERROR_TITLE, MB_ICONEXCLAMATION | MB_OK );
  3226. return FALSE;
  3227. }
  3228. catch( ... )
  3229. {
  3230. UDDIMsgBox( hwndParent, IDS_ERROR_ADDWEBSITE, IDS_ERROR_TITLE, MB_ICONEXCLAMATION | MB_OK );
  3231. return FALSE;
  3232. }
  3233. }
  3234. CStringCollection::CStringCollection( const wstring& strDelimitedStrings,
  3235. const wstring& strDelim )
  3236. {
  3237. _coll.clear();
  3238. if( 0 == strDelimitedStrings.length() )
  3239. {
  3240. return;
  3241. }
  3242. _strDelim = strDelim;
  3243. WCHAR *pwsz = new WCHAR[ strDelimitedStrings.length() + 1 ];
  3244. if( NULL == pwsz )
  3245. {
  3246. return;
  3247. }
  3248. wcsncpy( pwsz, strDelimitedStrings.c_str(), strDelimitedStrings.length() );
  3249. pwsz[ strDelimitedStrings.length() ] = 0x00;
  3250. //
  3251. // Convert to upper case.
  3252. //
  3253. pwsz = _wcsupr( pwsz );
  3254. WCHAR *pwszToken = wcstok( pwsz, _strDelim.c_str() );
  3255. while( NULL != pwszToken )
  3256. {
  3257. _coll.push_back( pwszToken );
  3258. pwszToken = wcstok( NULL, _strDelim.c_str() );
  3259. }
  3260. delete [] pwsz;
  3261. }
  3262. CStringCollection::~CStringCollection()
  3263. {
  3264. _coll.clear();
  3265. }
  3266. void
  3267. CStringCollection::DeleteString( const wstring& str )
  3268. {
  3269. if( 0 == str.length() )
  3270. {
  3271. return;
  3272. }
  3273. vector< wstring >::iterator it = _coll.begin();
  3274. for( ; it != _coll.end(); it++ )
  3275. {
  3276. if( 0 == _wcsicmp( str.c_str(), it->c_str() ) )
  3277. {
  3278. _coll.erase( it );
  3279. break;
  3280. }
  3281. }
  3282. }
  3283. void
  3284. CStringCollection::AddString( const wstring& str )
  3285. {
  3286. if( 0 == str.length() )
  3287. {
  3288. return;
  3289. }
  3290. WCHAR *pwsz = new WCHAR[ str.length() + 1 ];
  3291. if( NULL == pwsz )
  3292. {
  3293. return;
  3294. }
  3295. wcsncpy( pwsz, str.c_str(), str.length() );
  3296. pwsz[ str.length() ] = 0x00;
  3297. pwsz = _wcsupr( pwsz );
  3298. vector< wstring >::const_iterator cit;
  3299. cit = find( _coll.begin(), _coll.end(), str );
  3300. if( _coll.end() == cit )
  3301. {
  3302. _coll.push_back( str );
  3303. }
  3304. delete [] pwsz;
  3305. }
  3306. wstring
  3307. CStringCollection::GetDelimitedString() const
  3308. {
  3309. wstring str;
  3310. vector< wstring >::const_iterator cit;
  3311. bool first = true;
  3312. for( cit = _coll.begin(); cit != _coll.end(); cit++ )
  3313. {
  3314. first = ( _coll.begin() == cit ) ? true : false;
  3315. if( !first )
  3316. {
  3317. str += _strDelim;
  3318. }
  3319. str += *cit;
  3320. }
  3321. return str;
  3322. }
  3323. BOOL
  3324. CStringCollection::Exists( const wstring& str ) const
  3325. {
  3326. BOOL fRet = FALSE;
  3327. if( 0 == str.length() )
  3328. {
  3329. return fRet;
  3330. }
  3331. vector< wstring >::const_iterator cit = _coll.begin();
  3332. for( ; cit != _coll.end(); cit++ )
  3333. {
  3334. if( 0 == _wcsicmp( str.c_str(), cit->c_str() ) )
  3335. {
  3336. fRet = TRUE;
  3337. break;
  3338. }
  3339. }
  3340. return fRet;
  3341. }