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.

973 lines
34 KiB

  1. #ifndef INITGUID
  2. #define INITGUID
  3. #endif
  4. #ifndef WIN32_LEAN_AND_MEAN
  5. #define WIN32_LEAN_AND_MEAN
  6. #endif
  7. #ifndef _WIN32_WINNT
  8. #define _WIN32_WINNT 0x0500
  9. #endif
  10. #include <windows.h>
  11. #include <tchar.h>
  12. #include <stdio.h>
  13. #include <iadmw.h> // Interface header
  14. #include <iiscnfg.h> // MD_ & IIS_MD_ defines
  15. #include <objbase.h>
  16. #include "..\..\shared\common.h" // needed for GetUDDIInstallPath
  17. #include "webcaum.h"
  18. #include "resource.h"
  19. #include <string>
  20. #include <vector>
  21. using namespace std;
  22. #define tstring basic_string <TCHAR>
  23. typedef std::vector<tstring> cStrList;
  24. #define APPPOOLNAME TEXT( "MSUDDIAppPool" )
  25. #define DEFAULTLOADFILE TEXT( "default.aspx" )
  26. #define UDDIAPPLICATIONNAME TEXT( "uddi" )
  27. #define UDDIAPPLICATIONDEPENDENCY TEXT( "UDDI;ASP.NET v1.1.4322" )
  28. #define UDDINTAUTHPROVIDERS TEXT( "NTLM" )
  29. #define APIAPPLICATIONNAME TEXT( "uddipublic" )
  30. #ifndef MD_APPPOOL_IDENTITY_TYPE_LOCALSYSTEM
  31. #define MD_APPPOOL_IDENTITY_TYPE_LOCALSYSTEM 0
  32. #define MD_APPPOOL_IDENTITY_TYPE_LOCALSERVICE 1
  33. #define MD_APPPOOL_IDENTITY_TYPE_NETWORKSERVICE 2
  34. #define MD_APPPOOL_IDENTITY_TYPE_SPECIFICUSER 3
  35. #endif
  36. #define REASONABLE_TIMEOUT 1000
  37. BOOL IsInList( LPCTSTR szStrToFind, cStrList *pList, BOOL bIgnoreCase )
  38. {
  39. if( IsBadReadPtr( pList, sizeof cStrList ) )
  40. return FALSE;
  41. BOOL bFound = FALSE;
  42. for( cStrList::size_type i = 0; ( i < pList->size() ) && !bFound ; i++ )
  43. {
  44. LPCTSTR szEntry = (*pList)[i].c_str();
  45. if ( bIgnoreCase )
  46. bFound = !_tcsicmp( szEntry, szStrToFind );
  47. else
  48. bFound = !_tcscmp( szEntry, szStrToFind );
  49. }
  50. return bFound;
  51. }
  52. BOOL RemoveFromList( LPCTSTR szStrToFind, cStrList *pList, BOOL bIgnoreCase )
  53. {
  54. if( IsBadReadPtr( pList, sizeof cStrList ) )
  55. return FALSE;
  56. BOOL bFound = FALSE;
  57. for( cStrList::size_type i = 0; ( i < pList->size() ) && !bFound ; i++ )
  58. {
  59. LPCTSTR szEntry = (*pList)[i].c_str();
  60. if ( bIgnoreCase )
  61. bFound = !_tcsicmp( szEntry, szStrToFind );
  62. else
  63. bFound = !_tcscmp( szEntry, szStrToFind );
  64. if( bFound )
  65. {
  66. pList->erase(pList->begin() + i);
  67. }
  68. }
  69. return bFound;
  70. }
  71. //--------------------------------------------------------------------------
  72. class CIISObjectBase
  73. {
  74. protected:
  75. static IMSAdminBase* pIMSAdminBase;
  76. METADATA_HANDLE m_hMetabase;
  77. PTCHAR m_szKeyName;
  78. PTCHAR m_szRoot;
  79. public:
  80. CIISObjectBase() : m_hMetabase( NULL ), m_szKeyName( NULL ), m_szRoot( NULL )
  81. {
  82. }
  83. virtual ~CIISObjectBase()
  84. {
  85. Release();
  86. }
  87. static void Initialize()
  88. {
  89. HRESULT hr = CoCreateInstance(
  90. CLSID_MSAdminBase,
  91. NULL,
  92. CLSCTX_ALL,
  93. IID_IMSAdminBase,
  94. (void**)&pIMSAdminBase );
  95. if( FAILED( hr ) )
  96. {
  97. LogError( TEXT( "CIISObjectBase::Initialize::CoCreateInstance() failed..." ), HRESULT_CODE(hr) );
  98. throw hr;
  99. }
  100. }
  101. static void Uninitialize()
  102. {
  103. if( pIMSAdminBase )
  104. {
  105. pIMSAdminBase->Release();
  106. pIMSAdminBase = NULL;
  107. }
  108. }
  109. void SetData( DWORD dwIdentifier, DWORD dwValue, DWORD dwAttributes, DWORD dwUserType )
  110. {
  111. HRESULT hr;
  112. METADATA_RECORD mr;
  113. mr.dwMDIdentifier = dwIdentifier;
  114. mr.dwMDAttributes = dwAttributes;
  115. mr.dwMDUserType = dwUserType;
  116. mr.dwMDDataType = DWORD_METADATA;
  117. mr.dwMDDataLen = sizeof( DWORD );
  118. mr.pbMDData = reinterpret_cast<unsigned char *>(&dwValue);
  119. hr = pIMSAdminBase->SetData( m_hMetabase, m_szKeyName, &mr );
  120. if( FAILED( hr ) )
  121. {
  122. LogError( TEXT( "CIISObjectBase::SetData::pIMSAdminBase->SetData() failed..." ), HRESULT_CODE(hr) );
  123. throw hr;
  124. }
  125. }
  126. void SetData( DWORD dwIdentifier, PTCHAR szValue, DWORD dwAttributes, DWORD dwUserType )
  127. {
  128. HRESULT hr;
  129. METADATA_RECORD mr;
  130. mr.dwMDIdentifier = dwIdentifier;
  131. mr.dwMDAttributes = dwAttributes;
  132. mr.dwMDUserType = dwUserType;
  133. mr.dwMDDataType = STRING_METADATA;
  134. mr.dwMDDataLen = (DWORD) ( _tcslen( szValue ) + 1) * sizeof( TCHAR );
  135. mr.pbMDData = reinterpret_cast<unsigned char *>(szValue);
  136. hr = pIMSAdminBase->SetData( m_hMetabase, m_szKeyName, &mr );
  137. if( FAILED( hr ) )
  138. {
  139. LogError( TEXT( "CIISObjectBase::SetData::pIMSAdminBase->SetData() failed..." ), HRESULT_CODE(hr) );
  140. throw hr;
  141. }
  142. }
  143. void GetData( DWORD dwIdentifier, PTCHAR szValue, DWORD dwBufferLen, DWORD dwAttributes, DWORD dwUserType )
  144. {
  145. HRESULT hr;
  146. METADATA_RECORD mr;
  147. DWORD dwMDRequiredDataLen = 0;
  148. mr.dwMDIdentifier = dwIdentifier;
  149. mr.dwMDAttributes = dwAttributes;
  150. mr.dwMDUserType = dwUserType;
  151. mr.dwMDDataType = STRING_METADATA;
  152. mr.dwMDDataLen = 0;
  153. mr.pbMDData = NULL;
  154. mr.dwMDDataLen = dwBufferLen;
  155. mr.pbMDData = reinterpret_cast<unsigned char *>(szValue);
  156. hr = pIMSAdminBase->GetData( m_hMetabase, m_szKeyName, &mr, &dwMDRequiredDataLen );
  157. if( FAILED( hr ) )
  158. {
  159. Log( TEXT( "CIISObjectBase::GetData::pIMSAdminBase->GetData() failed with HRESULT 0x%x." ), hr );
  160. throw hr;
  161. }
  162. }
  163. void GetMultiSzData( DWORD dwIdentifier, cStrList* pList, DWORD dwAttributes, DWORD dwUserType )
  164. {
  165. HRESULT hr;
  166. METADATA_RECORD mr;
  167. DWORD dwMDRequiredDataLen = 0;
  168. PTCHAR szValue = NULL;
  169. mr.dwMDIdentifier = dwIdentifier;
  170. mr.dwMDAttributes = dwAttributes;
  171. mr.dwMDUserType = dwUserType;
  172. mr.dwMDDataType = MULTISZ_METADATA;
  173. mr.dwMDDataLen = 0;
  174. mr.pbMDData = NULL;
  175. hr = pIMSAdminBase->GetData( m_hMetabase, m_szKeyName, &mr, &dwMDRequiredDataLen );
  176. DWORD dwMDDataLen = dwMDRequiredDataLen / sizeof(TCHAR);
  177. //
  178. // Let API calculate needed buffer size, then allocate
  179. //
  180. if( ERROR_INSUFFICIENT_BUFFER == HRESULT_CODE(hr) )
  181. {
  182. szValue = new TCHAR[ dwMDDataLen ];
  183. if( NULL == szValue )
  184. {
  185. hr = E_OUTOFMEMORY;
  186. LogError( TEXT( "CIISObjectBase::GetMultiSzData::new TCHAR[] failed..." ), HRESULT_CODE(hr) );
  187. throw hr;
  188. }
  189. mr.dwMDDataLen = dwMDRequiredDataLen;
  190. mr.pbMDData = reinterpret_cast<unsigned char *>(szValue);
  191. hr = pIMSAdminBase->GetData( m_hMetabase, m_szKeyName, &mr, &dwMDRequiredDataLen );
  192. }
  193. else
  194. {
  195. //
  196. // Should never get here, should always fail with insufficient buffer
  197. //
  198. hr = E_FAIL;
  199. LogError( TEXT( "CIISObjectBase::GetMultiSzData::pIMSAdminBase->GetData() failed..." ), HRESULT_CODE(hr) );
  200. throw hr;
  201. }
  202. if( FAILED( hr ) )
  203. {
  204. //
  205. // Don't forget to free buffer before throwing exception
  206. //
  207. if( NULL != szValue )
  208. {
  209. delete [] szValue;
  210. }
  211. LogError( TEXT( "CIISObjectBase::GetMultiSzData::pIMSAdminBase->GetData() failed..." ), HRESULT_CODE(hr) );
  212. throw hr;
  213. }
  214. if( NULL != szValue )
  215. {
  216. while( *szValue )
  217. {
  218. //
  219. // Add value at front to cStrList
  220. //
  221. pList->push_back( szValue );
  222. //
  223. // Walk past null-delimited string
  224. //
  225. while( *szValue )
  226. szValue++;
  227. //
  228. // Walk past null character
  229. //
  230. szValue++;
  231. }
  232. //
  233. // Free allocated buffer
  234. //
  235. delete [] szValue;
  236. }
  237. }
  238. void SetMultiSzData( DWORD dwIdentifier, cStrList* pList, DWORD dwAttributes, DWORD dwUserType )
  239. {
  240. HRESULT hr;
  241. METADATA_RECORD mr;
  242. DWORD dwMDDataLen = 0;
  243. tstring szValue;
  244. //
  245. // Convert cStrList to multisz string
  246. //
  247. for( cStrList::size_type i = 0; ( i < pList->size() ); i++ )
  248. {
  249. LPCTSTR szEntry = (*pList)[i].c_str();
  250. szValue += szEntry;
  251. szValue += TEXT( '\t' );
  252. }
  253. //
  254. // Add trailing tab (which will become null) character
  255. //
  256. szValue += TEXT( '\t' );
  257. //
  258. // Calculate string data length
  259. //
  260. dwMDDataLen = (DWORD)szValue.length() * sizeof(TCHAR);
  261. //
  262. // Replace /t with /0, to properly create multisz string
  263. //
  264. PTCHAR szTemp = (PTCHAR)szValue.c_str();
  265. while( *szTemp )
  266. {
  267. if( TEXT( '\t' ) == *szTemp )
  268. *szTemp = TEXT( '\0' );
  269. szTemp++;
  270. }
  271. mr.dwMDIdentifier = dwIdentifier;
  272. mr.dwMDAttributes = dwAttributes;
  273. mr.dwMDUserType = dwUserType;
  274. mr.dwMDDataType = MULTISZ_METADATA;
  275. mr.dwMDDataLen = dwMDDataLen;
  276. mr.pbMDData = reinterpret_cast<unsigned char *>( (PTCHAR)szValue.c_str() );
  277. hr = pIMSAdminBase->SetData( m_hMetabase, m_szKeyName, &mr );
  278. if( FAILED( hr ) )
  279. {
  280. LogError( TEXT( "CIISObjectBase::SetMultiSzData::pIMSAdminBase->SetData() failed..." ), HRESULT_CODE(hr) );
  281. throw hr;
  282. }
  283. }
  284. void Delete()
  285. {
  286. HRESULT hr;
  287. //
  288. // Attempt to open the virtual dir set on Web server #1 (default server)
  289. //
  290. hr = pIMSAdminBase->OpenKey( METADATA_MASTER_ROOT_HANDLE,
  291. m_szRoot,
  292. METADATA_PERMISSION_READ | METADATA_PERMISSION_WRITE,
  293. REASONABLE_TIMEOUT,
  294. &m_hMetabase );
  295. if( FAILED( hr ))
  296. {
  297. LogError( TEXT( "CIISObjectBase::Delete::pIMSAdminBase->OpenKey() failed..." ), HRESULT_CODE(hr) );
  298. throw hr;
  299. }
  300. //
  301. // We don't check the return value since the key may already
  302. // not exist and we could get an error for that reason.
  303. //
  304. pIMSAdminBase->DeleteKey( m_hMetabase, m_szKeyName );
  305. pIMSAdminBase->CloseKey( m_hMetabase );
  306. m_hMetabase = NULL;
  307. }
  308. void Release()
  309. {
  310. if( m_hMetabase && pIMSAdminBase )
  311. {
  312. pIMSAdminBase->CloseKey( m_hMetabase );
  313. m_hMetabase = NULL;
  314. }
  315. }
  316. };
  317. //--------------------------------------------------------------------------
  318. IMSAdminBase* CIISObjectBase::pIMSAdminBase = NULL;
  319. class CIISApplicationPool : public CIISObjectBase
  320. {
  321. public:
  322. CIISApplicationPool( PTCHAR szName )
  323. {
  324. m_szKeyName = szName;
  325. m_szRoot = TEXT( "/LM/W3SVC/AppPools" );
  326. }
  327. void Create()
  328. {
  329. HRESULT hr;
  330. METADATA_RECORD mr = {0};
  331. DWORD dwMDRequiredDataLen = 0;
  332. TCHAR achBuffer[ 256 ];
  333. //
  334. // Attempt to open the UDDI Application Pool
  335. //
  336. hr = pIMSAdminBase->OpenKey( METADATA_MASTER_ROOT_HANDLE,
  337. m_szRoot,
  338. METADATA_PERMISSION_READ | METADATA_PERMISSION_WRITE,
  339. REASONABLE_TIMEOUT,
  340. &m_hMetabase );
  341. //
  342. // Create the key if it does not exist.
  343. //
  344. if( FAILED( hr ))
  345. {
  346. LogError( TEXT( "CIISApplicationPool::pIMSAdminBase->OpenKey() failed..." ), HRESULT_CODE(hr) );
  347. throw hr;
  348. }
  349. mr.dwMDIdentifier = MD_KEY_TYPE;
  350. mr.dwMDAttributes = 0;
  351. mr.dwMDUserType = IIS_MD_UT_SERVER;
  352. mr.dwMDDataType = STRING_METADATA;
  353. mr.dwMDDataLen = sizeof(achBuffer);
  354. mr.pbMDData = reinterpret_cast<unsigned char *>(achBuffer);
  355. //
  356. // See if MD_KEY_TYPE exists
  357. //
  358. hr = pIMSAdminBase->GetData( m_hMetabase, m_szKeyName, &mr, &dwMDRequiredDataLen );
  359. if( FAILED( hr ))
  360. {
  361. if( MD_ERROR_DATA_NOT_FOUND == hr || ERROR_PATH_NOT_FOUND == HRESULT_CODE(hr) )
  362. {
  363. //
  364. // Write both the key and the values if GetData() failed with any of the two errors.
  365. //
  366. hr = pIMSAdminBase->AddKey( m_hMetabase, m_szKeyName );
  367. if( FAILED( hr ) )
  368. {
  369. LogError( TEXT( "CIISApplicationPool::pIMSAdminBase->AddKey() failed..." ), HRESULT_CODE(hr) );
  370. throw hr;
  371. }
  372. }
  373. else
  374. {
  375. LogError( TEXT( "CIISApplicationPool::pIMSAdminBase->GetData() failed..." ), HRESULT_CODE(hr));
  376. throw hr;
  377. }
  378. //
  379. // Setup default properties
  380. //
  381. // TODO: Need to use #define for IIsApplicationPool
  382. //
  383. SetData( MD_KEY_TYPE, TEXT( "IIsApplicationPool" ), 0, IIS_MD_UT_SERVER );
  384. }
  385. }
  386. };
  387. //--------------------------------------------------------------------------
  388. class CIISWebService : public CIISObjectBase
  389. {
  390. public:
  391. CIISWebService()
  392. {
  393. m_szKeyName = TEXT( "/W3SVC" );
  394. m_szRoot = TEXT( "/LM" );
  395. }
  396. void Create()
  397. {
  398. HRESULT hr;
  399. METADATA_RECORD mr = {0};
  400. DWORD dwMDRequiredDataLen = 0;
  401. TCHAR achBuffer[ 256 ];
  402. //
  403. // Attempt to open the IIS Web Service
  404. //
  405. hr = pIMSAdminBase->OpenKey( METADATA_MASTER_ROOT_HANDLE,
  406. m_szRoot,
  407. METADATA_PERMISSION_READ | METADATA_PERMISSION_WRITE,
  408. REASONABLE_TIMEOUT,
  409. &m_hMetabase );
  410. //
  411. // Create the key if it does not exist.
  412. //
  413. if( FAILED( hr ))
  414. {
  415. LogError( TEXT( "CIISWebService::pIMSAdminBase->OpenKey() failed..." ), HRESULT_CODE(hr) );
  416. throw hr;
  417. }
  418. mr.dwMDIdentifier = MD_KEY_TYPE;
  419. mr.dwMDAttributes = 0;
  420. mr.dwMDUserType = IIS_MD_UT_SERVER;
  421. mr.dwMDDataType = STRING_METADATA;
  422. mr.dwMDDataLen = sizeof(achBuffer);
  423. mr.pbMDData = reinterpret_cast<unsigned char *>(achBuffer);
  424. //
  425. // See if MD_KEY_TYPE exists
  426. //
  427. hr = pIMSAdminBase->GetData( m_hMetabase, m_szKeyName, &mr, &dwMDRequiredDataLen );
  428. if( FAILED( hr ))
  429. {
  430. LogError( TEXT( "CIISWebService::pIMSAdminBase->GetData() failed..." ), HRESULT_CODE(hr));
  431. throw hr;
  432. }
  433. }
  434. };
  435. class CIISApplication : public CIISObjectBase
  436. {
  437. private:
  438. PTCHAR m_szPath;
  439. public:
  440. CIISApplication( PTCHAR szVDir, PTCHAR szPath )
  441. {
  442. m_szKeyName = szVDir;
  443. m_szPath = szPath;
  444. m_szRoot = TEXT( "/LM/W3SVC/1/ROOT" );
  445. }
  446. void Create()
  447. {
  448. HRESULT hr;
  449. METADATA_RECORD mr;
  450. DWORD dwMDRequiredDataLen = 0;
  451. TCHAR szTempPath[ MAX_PATH ];
  452. //
  453. // Attempt to open the virtual dir set on Web server #1 (default server)
  454. //
  455. hr = pIMSAdminBase->OpenKey( METADATA_MASTER_ROOT_HANDLE,
  456. m_szRoot,
  457. METADATA_PERMISSION_READ | METADATA_PERMISSION_WRITE,
  458. REASONABLE_TIMEOUT,
  459. &m_hMetabase );
  460. //
  461. // Create the key if it does not exist.
  462. //
  463. if( FAILED( hr ))
  464. {
  465. LogError( TEXT( "CIISApplication::pIMSAdminBase->OpenKey() failed..." ), HRESULT_CODE( hr ) );
  466. throw hr;
  467. }
  468. mr.dwMDIdentifier = MD_VR_PATH;
  469. mr.dwMDAttributes = METADATA_INHERIT;
  470. mr.dwMDUserType = IIS_MD_UT_FILE;
  471. mr.dwMDDataType = STRING_METADATA;
  472. mr.dwMDDataLen = sizeof( szTempPath );
  473. mr.pbMDData = reinterpret_cast<unsigned char *>(szTempPath);
  474. //
  475. // See if MD_VR_PATH exists.
  476. //
  477. hr = pIMSAdminBase->GetData( m_hMetabase, m_szKeyName, &mr, &dwMDRequiredDataLen );
  478. if( FAILED( hr ))
  479. {
  480. if( MD_ERROR_DATA_NOT_FOUND == hr ||
  481. ERROR_PATH_NOT_FOUND == HRESULT_CODE(hr) )
  482. {
  483. //
  484. // Write both the key and the values if GetData() failed with any of the two errors.
  485. //
  486. hr = pIMSAdminBase->AddKey( m_hMetabase, m_szKeyName );
  487. if( FAILED( hr ) )
  488. {
  489. LogError( TEXT( "CIISApplication::pIMSAdminBase->AddKey() failed..." ), HRESULT_CODE(hr) );
  490. throw hr;
  491. }
  492. }
  493. else
  494. {
  495. LogError( TEXT( "CIISApplication::pIMSAdminBase->GetData() failed..." ), HRESULT_CODE(hr) );
  496. throw hr;
  497. }
  498. }
  499. //
  500. // Set default property information
  501. //
  502. SetData( MD_VR_PATH, m_szPath, METADATA_INHERIT, IIS_MD_UT_FILE );
  503. SetData( MD_KEY_TYPE, IIS_CLASS_WEB_VDIR_W, 0, IIS_MD_UT_SERVER );
  504. //
  505. // Setup the path to the application root
  506. //
  507. TCHAR szAppRoot [ MAX_PATH + 1 ];
  508. _sntprintf( szAppRoot, MAX_PATH, TEXT( "%s/%s" ), m_szRoot, m_szKeyName );
  509. SetData( MD_APP_ROOT, szAppRoot, METADATA_INHERIT, IIS_MD_UT_FILE );
  510. }
  511. };
  512. //--------------------------------------------------------------------------
  513. UINT SetupIISUDDIMetabase( int AppPoolIdentityType, LPCTSTR szUserName, LPCTSTR szPwd )
  514. {
  515. ENTER();
  516. UINT errCode = ERROR_SUCCESS;
  517. // ::MessageBox( NULL, TEXT( "Attach Debugger" ), TEXT( "SetupIISUDDIMetabase" ), MB_OK );
  518. if( FAILED( CoInitializeEx( NULL, COINIT_MULTITHREADED ) ) )
  519. {
  520. Log( TEXT( "SetupIISUDDIMetabase() failed: CoInitializeEx() failed" ) );
  521. return ERROR_INSTALL_FAILURE;
  522. }
  523. //
  524. // Get the root UDDI application path from the registry
  525. //
  526. //
  527. TCHAR szUddiApplicationFilePath[ MAX_PATH ];
  528. if( !GetUDDIInstallPath( szUddiApplicationFilePath , MAX_PATH ) )
  529. {
  530. return ERROR_INSTALL_FAILURE;
  531. }
  532. _tcscat( szUddiApplicationFilePath, TEXT( "webroot" ) );
  533. //
  534. // Set the api application path to the root UDDI path also
  535. //
  536. TCHAR szApiApplicationFilePath[ MAX_PATH ];
  537. _tcscpy( szApiApplicationFilePath, szUddiApplicationFilePath );
  538. try
  539. {
  540. //
  541. // Initialize the connection the the IIS metabase
  542. //
  543. try
  544. {
  545. CIISObjectBase::Initialize();
  546. }
  547. catch( HRESULT hr )
  548. {
  549. LogError( TEXT( "CIISObjectBase::Initialize() failed" ), HRESULT_CODE( hr ) );
  550. throw hr;
  551. }
  552. //
  553. // Create the application pool for the SOAP API and the User Interface
  554. //
  555. try
  556. {
  557. CIISApplicationPool pool( APPPOOLNAME );
  558. pool.Create();
  559. //
  560. // These values are set by the user on an OCM property page
  561. //
  562. pool.SetData( MD_APPPOOL_IDENTITY_TYPE, AppPoolIdentityType, METADATA_INHERIT, IIS_MD_UT_SERVER );
  563. //
  564. // If the user type is "Specific User," then set the user name and password
  565. //
  566. if( MD_APPPOOL_IDENTITY_TYPE_SPECIFICUSER == AppPoolIdentityType )
  567. {
  568. pool.SetData( MD_WAM_USER_NAME, ( PTCHAR ) szUserName, METADATA_INHERIT, IIS_MD_UT_FILE );
  569. pool.SetData( MD_WAM_PWD, ( PTCHAR ) szPwd, METADATA_INHERIT | METADATA_SECURE, IIS_MD_UT_FILE );
  570. }
  571. pool.SetData( MD_APPPOOL_MAX_PROCESS_COUNT, 1, METADATA_INHERIT, IIS_MD_UT_SERVER );
  572. pool.Release();
  573. }
  574. catch( HRESULT hr )
  575. {
  576. LogError( TEXT( "Error creating application pool" ), HRESULT_CODE( hr ) );
  577. throw hr;
  578. }
  579. //
  580. // Create the uddi application for access to the user interface
  581. //
  582. try
  583. {
  584. TCHAR wszBuf[ 512 ];
  585. wszBuf[ 0 ] = 0x00;
  586. LoadString( g_hinst, IDS_UDDI_APPLICATION_FRIENDLY_NAME, wszBuf, 512 );
  587. CIISApplication uddi( UDDIAPPLICATIONNAME, szUddiApplicationFilePath );
  588. uddi.Create();
  589. uddi.SetData( MD_AUTHORIZATION, MD_AUTH_BASIC | MD_AUTH_NT, METADATA_INHERIT, IIS_MD_UT_FILE );
  590. uddi.SetData( MD_ACCESS_PERM, MD_ACCESS_READ | MD_ACCESS_SCRIPT, METADATA_INHERIT, IIS_MD_UT_FILE );
  591. uddi.SetData( MD_DEFAULT_LOAD_FILE, DEFAULTLOADFILE, 0, IIS_MD_UT_FILE );
  592. uddi.SetData( MD_APP_ISOLATED, 2, 0, IIS_MD_UT_WAM );
  593. uddi.SetData( MD_APP_FRIENDLY_NAME, wszBuf, 0, IIS_MD_UT_WAM );
  594. uddi.SetData( MD_APP_APPPOOL_ID, APPPOOLNAME, METADATA_INHERIT, IIS_MD_UT_SERVER );
  595. uddi.Release();
  596. }
  597. catch( HRESULT hr )
  598. {
  599. LogError( TEXT( "Error creating uddi application for access to the user interface" ), HRESULT_CODE( hr ) );
  600. throw hr;
  601. }
  602. //
  603. // Create the api application for access to the SOAP interface
  604. //
  605. try
  606. {
  607. TCHAR wszBuf[ 512 ];
  608. wszBuf[ 0 ] = 0x00;
  609. LoadString( g_hinst, IDS_API_APPLICATION_FRIENDLY_NAME, wszBuf, 512 );
  610. CIISApplication api( APIAPPLICATIONNAME, szApiApplicationFilePath );
  611. api.Create();
  612. api.SetData( MD_AUTHORIZATION, MD_AUTH_ANONYMOUS /* todo remove by Mark Patton | MD_AUTH_NT*/, METADATA_INHERIT, IIS_MD_UT_FILE );
  613. api.SetData( MD_ACCESS_PERM, MD_ACCESS_READ | MD_ACCESS_SCRIPT, METADATA_INHERIT, IIS_MD_UT_FILE );
  614. // api.SetData( MD_DEFAULT_LOAD_FILE, DEFAULTLOADFILE, 0, IIS_MD_UT_FILE );
  615. api.SetData( MD_APP_ISOLATED, 2, 0, IIS_MD_UT_WAM );
  616. api.SetData( MD_APP_FRIENDLY_NAME, wszBuf, 0, IIS_MD_UT_WAM );
  617. api.SetData( MD_APP_APPPOOL_ID, APPPOOLNAME, METADATA_INHERIT, IIS_MD_UT_SERVER );
  618. //
  619. // Use the default account.
  620. //
  621. #if 0
  622. //
  623. // Set the anonymous user name and password
  624. //
  625. if ( MD_APPPOOL_IDENTITY_TYPE_SPECIFICUSER == AppPoolIdentityType )
  626. {
  627. //
  628. // Domain account:
  629. //
  630. api.SetData( MD_ANONYMOUS_USER_NAME, (PTCHAR) szUserName, METADATA_INHERIT, IIS_MD_UT_FILE );
  631. if( szPwd && _tcslen( szPwd ) )
  632. {
  633. api.SetData( MD_ANONYMOUS_PWD, (PTCHAR) szPwd, METADATA_INHERIT | METADATA_SECURE, IIS_MD_UT_FILE );
  634. }
  635. }
  636. else
  637. {
  638. //
  639. // Network service account:
  640. //
  641. api.SetData( MD_ANONYMOUS_USER_NAME, (PTCHAR) szUserName, METADATA_NO_ATTRIBUTES, IIS_MD_UT_WAM );
  642. }
  643. #endif
  644. api.Release();
  645. }
  646. catch( HRESULT hr )
  647. {
  648. LogError( TEXT( "Error creating the api application for access to the SOAP interface" ), HRESULT_CODE( hr ) );
  649. throw hr;
  650. }
  651. //
  652. // Create the UDDI application dependency
  653. //
  654. try
  655. {
  656. cStrList cAppDep;
  657. CIISWebService ws;
  658. ws.Create();
  659. ws.GetMultiSzData( MD_APP_DEPENDENCIES, &cAppDep, 0, IIS_MD_UT_SERVER );
  660. if( !IsInList( UDDIAPPLICATIONDEPENDENCY, &cAppDep, FALSE ) )
  661. {
  662. //
  663. // Append UDDI app dependency string
  664. //
  665. cAppDep.push_back( UDDIAPPLICATIONDEPENDENCY );
  666. //
  667. // Set new app dependency string into record
  668. //
  669. ws.SetMultiSzData( MD_APP_DEPENDENCIES, &cAppDep, 0, IIS_MD_UT_SERVER );
  670. }
  671. TCHAR szAuthProv[ 256 ];
  672. Log( TEXT( "Attempting to get string value for MD_NTAUTHENTICATION_PROVIDERS." ) );
  673. try
  674. {
  675. ws.GetData( MD_NTAUTHENTICATION_PROVIDERS, szAuthProv, sizeof(szAuthProv), 0, IIS_MD_UT_FILE );
  676. Log( TEXT( "Found NT Authentication Providers: %s" ), szAuthProv );
  677. }
  678. catch( HRESULT hr )
  679. {
  680. //
  681. // Not an error if it doesn't exist already.
  682. //
  683. Log( TEXT( "Failed to get MD_NTAUTHENTICATION_PROVIDERS as IIS_MD_UT_FILE, HRESULT 0x%x." ), hr );
  684. }
  685. try
  686. {
  687. ws.SetData( MD_NTAUTHENTICATION_PROVIDERS, UDDINTAUTHPROVIDERS, METADATA_INHERIT, IIS_MD_UT_FILE );
  688. Log( TEXT( "Set NT Authentication Providers: %s" ), UDDINTAUTHPROVIDERS );
  689. }
  690. catch( HRESULT hr )
  691. {
  692. Log( TEXT( "Failed to set MD_NTAUTHENTICATION_PROVIDERS as IIS_MD_UT_FILE, HRESULT 0x%x." ), hr );
  693. throw hr;
  694. }
  695. ws.Release();
  696. }
  697. catch( HRESULT hr )
  698. {
  699. LogError( TEXT( "Error creating application dependency" ), HRESULT_CODE( hr ) );
  700. throw hr;
  701. }
  702. }
  703. catch( ... )
  704. {
  705. errCode = ERROR_INSTALL_FAILURE;
  706. }
  707. CIISObjectBase::Uninitialize();
  708. CoUninitialize();
  709. return errCode;
  710. }
  711. //--------------------------------------------------------------------------
  712. UINT RemoveIISUDDIMetabase(void)
  713. {
  714. ENTER();
  715. UINT errCode = ERROR_INSTALL_FAILURE;
  716. // ::MessageBox( NULL, TEXT( "Attach Debugger" ), TEXT( "RemoveIISUDDIMetabase" ), MB_OK );
  717. //
  718. // Get the root UDDI application path from the registry
  719. //
  720. TCHAR szUddiApplicationFilePath[ MAX_PATH + 1 ];
  721. if( !GetUDDIInstallPath( szUddiApplicationFilePath , MAX_PATH ) )
  722. {
  723. return ERROR_INSTALL_FAILURE;
  724. }
  725. if( FAILED( CoInitializeEx( NULL, COINIT_MULTITHREADED ) ) )
  726. {
  727. Log( TEXT( "RemoveIISUDDIMetabase() failed: CoInitializeEx() failed" ) );
  728. return ERROR_INSTALL_FAILURE;
  729. }
  730. _tcsncat( szUddiApplicationFilePath, TEXT( "webroot" ), MAX_PATH - _tcslen( szUddiApplicationFilePath ) );
  731. szUddiApplicationFilePath[ MAX_PATH ] = NULL;
  732. //
  733. // Set the api application path to the root UDDI path also
  734. //
  735. TCHAR szApiApplicationFilePath[ MAX_PATH+1 ];
  736. memset( szApiApplicationFilePath, 0, sizeof szApiApplicationFilePath );
  737. _tcsncpy( szApiApplicationFilePath, szUddiApplicationFilePath, MAX_PATH );
  738. try
  739. {
  740. try
  741. {
  742. CIISObjectBase::Initialize();
  743. }
  744. catch( HRESULT hr )
  745. {
  746. LogError( TEXT( "CIISObjectBase::Initialize() failed" ), HRESULT_CODE( hr ) );
  747. throw hr;
  748. }
  749. //
  750. // Delete the api application for access to the SOAP interface
  751. //
  752. try
  753. {
  754. CIISApplication api( APIAPPLICATIONNAME, szApiApplicationFilePath );
  755. api.Delete();
  756. api.Release();
  757. }
  758. catch( HRESULT hr )
  759. {
  760. LogError( TEXT( "Error deleting the api application for access to the SOAP interface" ), HRESULT_CODE( hr ) );
  761. throw hr;
  762. }
  763. //
  764. // Delete the uddi application for access to the user interface
  765. //
  766. try
  767. {
  768. CIISApplication uddi( UDDIAPPLICATIONNAME, szUddiApplicationFilePath );
  769. uddi.Delete();
  770. uddi.Release();
  771. }
  772. catch( HRESULT hr )
  773. {
  774. LogError( TEXT( "Error deleting uddi application for access to the user interface" ), HRESULT_CODE( hr ) );
  775. throw hr;
  776. }
  777. //
  778. // Delete the application pool entry
  779. //
  780. try
  781. {
  782. CIISApplicationPool pool( APPPOOLNAME );
  783. pool.Delete();
  784. pool.Release();
  785. }
  786. catch( HRESULT hr )
  787. {
  788. LogError( TEXT( "Error deleting application pool" ), HRESULT_CODE( hr ) );
  789. throw hr;
  790. }
  791. //
  792. // Remove the UDDI application dependency
  793. //
  794. try
  795. {
  796. cStrList cAppDep;
  797. CIISWebService ws;
  798. ws.Create();
  799. ws.GetMultiSzData( MD_APP_DEPENDENCIES, &cAppDep, 0, IIS_MD_UT_SERVER );
  800. if( RemoveFromList( UDDIAPPLICATIONDEPENDENCY, &cAppDep, FALSE ) )
  801. {
  802. //
  803. // Set new app dependency string into record
  804. //
  805. ws.SetMultiSzData( MD_APP_DEPENDENCIES, &cAppDep, 0, IIS_MD_UT_SERVER );
  806. }
  807. ws.Release();
  808. }
  809. catch( HRESULT hr )
  810. {
  811. LogError( TEXT( "Error deleting application dependency" ), HRESULT_CODE( hr ) );
  812. throw hr;
  813. }
  814. }
  815. catch( ... )
  816. {
  817. errCode = ERROR_INSTALL_FAILURE;
  818. }
  819. CIISObjectBase::Uninitialize();
  820. CoUninitialize();
  821. return errCode;
  822. }