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.

7169 lines
242 KiB

  1. #include "stdafx.h"
  2. #include <ole2.h>
  3. #include "iadm.h"
  4. #include "iiscnfgp.h"
  5. #include "mdkey.h"
  6. #include "lsaKeys.h"
  7. #undef MAX_SERVICE_NAME_LEN
  8. #include "elem.h"
  9. #include "mdentry.h"
  10. #include "mdacl.h"
  11. #include "inetinfo.h"
  12. #include <iis64.h>
  13. #include "inetcom.h"
  14. #include "logtype.h"
  15. #include "ilogobj.hxx"
  16. #include "log.h"
  17. #include "sslkeys.h"
  18. #include "massupdt.h"
  19. #include "strfn.h"
  20. #include "svc.h"
  21. #include "setpass.h"
  22. #include "dcomperm.h"
  23. #include "wolfpack.h"
  24. #include "parse.hxx"
  25. #define MAX_FIELDS 12
  26. #define FIELD_SEPERATOR _T("\t")
  27. #define MDENTRY_FROMINFFILE_FAILED 0
  28. #define MDENTRY_FROMINFFILE_DO_ADD 1
  29. #define MDENTRY_FROMINFFILE_DO_DEL 2
  30. #define MDENTRY_FROMINFFILE_DO_NOTHING 3
  31. MDEntry s_gMetabaseTypes[] = {
  32. // Path Type Identifies Attributes User Type Data Type Len Default Value
  33. { NULL, MD_KEY_TYPE, 0, IIS_MD_UT_SERVER, STRING_METADATA, 0, NULL }
  34. };
  35. // These must be global because that's how they passed around
  36. LPTSTR g_field[MAX_FIELDS];
  37. LPBYTE g_pbData = NULL;
  38. int g_CheckIfMetabaseValueWasWritten = FALSE;
  39. // function: GetDefaultAttributes
  40. //
  41. // Get the default attributes for a given property. This is so that
  42. // we do not have to set the usertype, and attributes everytime we
  43. // want to create a property
  44. //
  45. // Parameters:
  46. // dwID [in] - The id of the property
  47. // sMDEntry [out] - The structure filled with the right parameters
  48. //
  49. // Return:
  50. // TRUE - Succeeded
  51. // FALSE - Failed to find defaults
  52. BOOL
  53. GetDefaultAttributes(DWORD dwId, MDEntry *pMdEntry)
  54. {
  55. DWORD dwCurrent = 0;
  56. DWORD dwMax = sizeof(s_gMetabaseTypes)/sizeof(s_gMetabaseTypes[0]);
  57. BOOL bFound = FALSE;
  58. MDEntry *pCurrentEntry;
  59. // Initialize it to start
  60. pMdEntry->szMDPath = NULL;
  61. pMdEntry->dwMDIdentifier = dwId;
  62. pMdEntry->dwMDAttributes = METABASE_USE_DEFAULT;
  63. pMdEntry->dwMDUserType = METABASE_USE_DEFAULT;
  64. pMdEntry->dwMDDataType = METABASE_USE_DEFAULT;
  65. pMdEntry->dwMDDataLen = 0;
  66. pMdEntry->pbMDData = NULL;
  67. while ( dwCurrent < dwMax )
  68. {
  69. pCurrentEntry = &( s_gMetabaseTypes[dwCurrent] );
  70. if ( pCurrentEntry->dwMDIdentifier == dwId )
  71. {
  72. pMdEntry->szMDPath = pCurrentEntry->szMDPath;
  73. pMdEntry->dwMDAttributes = pCurrentEntry->dwMDAttributes;
  74. pMdEntry->dwMDUserType = pCurrentEntry->dwMDUserType;
  75. pMdEntry->dwMDDataType = pCurrentEntry->dwMDDataType;
  76. pMdEntry->dwMDDataLen = pCurrentEntry->dwMDDataLen;
  77. pMdEntry->pbMDData = pCurrentEntry->pbMDData;
  78. break;
  79. }
  80. dwCurrent++;
  81. }
  82. ASSERT(bFound);
  83. return bFound;
  84. }
  85. // function: WriteDefaultValue
  86. //
  87. // Write a default value to the metabase. This means that if it already exists
  88. // we will NOT overite it.
  89. //
  90. // Parameters:
  91. // szPath - The path where it will be set
  92. // dwID - The ID of the property
  93. // szValue - The value
  94. // dwAttributes - The attributes, if not specified, the default is taken
  95. // dwUserType - The user type, if not specified, the default is taken
  96. // dwDataType - The data type, if not specified, the default is taken
  97. //
  98. // Return Value
  99. // TRUE - Successfully set
  100. // FALSE - Failed to set value
  101. //
  102. BOOL
  103. WriteDefaultValue(LPTSTR szPath,
  104. DWORD dwId,
  105. LPTSTR szValue,
  106. DWORD dwAttributes = METABASE_USE_DEFAULT,
  107. DWORD dwUserType = METABASE_USE_DEFAULT,
  108. DWORD dwDataType = METABASE_USE_DEFAULT)
  109. {
  110. CMDKey cmdKey;
  111. MDEntry mdEntry;
  112. // Load defaults from table
  113. if ( !GetDefaultAttributes( dwId, &mdEntry ) )
  114. {
  115. return FALSE;
  116. }
  117. mdEntry.szMDPath = szPath;
  118. if ( szValue != NULL )
  119. {
  120. mdEntry.dwMDDataLen = ( _tcslen( szValue ) + 1 ) * sizeof(TCHAR);
  121. mdEntry.pbMDData = (LPBYTE) szValue;
  122. }
  123. if ( dwAttributes != METABASE_USE_DEFAULT )
  124. {
  125. mdEntry.dwMDAttributes = dwAttributes;
  126. }
  127. if ( dwUserType != METABASE_USE_DEFAULT )
  128. {
  129. mdEntry.dwMDUserType = dwUserType;
  130. }
  131. if ( dwDataType != METABASE_USE_DEFAULT )
  132. {
  133. mdEntry.dwMDUserType = dwDataType;
  134. }
  135. // Check and make sure all the fields are valid
  136. ASSERT( mdEntry.szMDPath != NULL);
  137. ASSERT( mdEntry.dwMDDataLen != 0 );
  138. ASSERT( mdEntry.pbMDData != NULL );
  139. ASSERT( mdEntry.dwMDAttributes != METABASE_USE_DEFAULT );
  140. ASSERT( mdEntry.dwMDUserType != METABASE_USE_DEFAULT );
  141. ASSERT( mdEntry .dwMDUserType != METABASE_USE_DEFAULT );
  142. return SetMDEntry_Wrap( &mdEntry );
  143. }
  144. HRESULT WINAPI Add_WWW_VDirA(CHAR * pszMetabasePath, CHAR * pszVDirName, CHAR * pszPhysicalPath, DWORD dwPermissions, DWORD iApplicationType)
  145. {
  146. HRESULT hr = ERROR_BAD_PATHNAME;
  147. WCHAR wszMetabasePath[_MAX_PATH];
  148. WCHAR wszVDirName[_MAX_PATH];
  149. WCHAR wszPhysicalPath[_MAX_PATH];
  150. INT i = 0;
  151. // check to make sure it's not larger than max_length!
  152. if (strlen(pszMetabasePath) > _MAX_PATH){goto Add_WWW_VDirA_Exit;}
  153. if (strlen(pszVDirName) > _MAX_PATH){goto Add_WWW_VDirA_Exit;}
  154. if (strlen(pszPhysicalPath) > _MAX_PATH){goto Add_WWW_VDirA_Exit;}
  155. // convert it to unicode then call the wide function
  156. memset( (PVOID)wszMetabasePath, 0, sizeof(wszMetabasePath));
  157. memset( (PVOID)wszVDirName, 0, sizeof(wszVDirName));
  158. memset( (PVOID)wszPhysicalPath, 0, sizeof(wszPhysicalPath));
  159. i = MultiByteToWideChar(CP_ACP, 0, (LPCSTR) wszMetabasePath, -1, (LPWSTR)wszMetabasePath, _MAX_PATH);
  160. if (i <= 0) {goto Add_WWW_VDirA_Exit;}
  161. i = MultiByteToWideChar(CP_ACP, 0, (LPCSTR) wszVDirName, -1, (LPWSTR)wszVDirName, _MAX_PATH);
  162. if (i <= 0) {goto Add_WWW_VDirA_Exit;}
  163. i = MultiByteToWideChar(CP_ACP, 0, (LPCSTR) wszPhysicalPath, -1, (LPWSTR)wszPhysicalPath, _MAX_PATH);
  164. if (i <= 0) {goto Add_WWW_VDirA_Exit;}
  165. hr = Add_WWW_VDirW(wszMetabasePath, wszVDirName, wszPhysicalPath,dwPermissions, iApplicationType);
  166. Add_WWW_VDirA_Exit:
  167. return hr;
  168. }
  169. HRESULT WINAPI Remove_WWW_VDirA(CHAR * pszMetabasePath, CHAR * pszVDirName)
  170. {
  171. HRESULT hr = ERROR_BAD_PATHNAME;
  172. WCHAR wszMetabasePath[_MAX_PATH];
  173. WCHAR wszVDirName[_MAX_PATH];
  174. INT i = 0;
  175. // check to make sure it's not larger than max_length!
  176. if (strlen(pszMetabasePath) > _MAX_PATH){goto Remove_WWW_VDirA_Exit;}
  177. if (strlen(pszVDirName) > _MAX_PATH){goto Remove_WWW_VDirA_Exit;}
  178. // convert it to unicode then call the wide function
  179. memset( (PVOID)wszMetabasePath, 0, sizeof(wszMetabasePath));
  180. memset( (PVOID)wszVDirName, 0, sizeof(wszVDirName));
  181. i = MultiByteToWideChar(CP_ACP, 0, (LPCSTR) wszMetabasePath, -1, (LPWSTR)wszMetabasePath, _MAX_PATH);
  182. if (i <= 0) {goto Remove_WWW_VDirA_Exit;}
  183. i = MultiByteToWideChar(CP_ACP, 0, (LPCSTR) wszVDirName, -1, (LPWSTR)wszVDirName, _MAX_PATH);
  184. if (i <= 0) {goto Remove_WWW_VDirA_Exit;}
  185. hr = Remove_WWW_VDirW(wszMetabasePath, wszVDirName);
  186. Remove_WWW_VDirA_Exit:
  187. return hr;
  188. }
  189. HRESULT WINAPI Add_WWW_VDirW(WCHAR * pwszMetabasePath, WCHAR * pwszVDirName, WCHAR * pwszPhysicalPath, DWORD dwPermissions, DWORD iApplicationType)
  190. {
  191. HRESULT hr = ERROR_BAD_PATHNAME;
  192. IMSAdminBase *pIMSAdminBase = NULL;
  193. // check to make sure it's not larger than max_length!
  194. if ((wcslen(pwszMetabasePath) * sizeof(WCHAR)) > _MAX_PATH){goto Add_WWW_VDirW_Exit2;}
  195. if ((wcslen(pwszVDirName) * sizeof(WCHAR)) > _MAX_PATH){goto Add_WWW_VDirW_Exit2;}
  196. if ((wcslen(pwszPhysicalPath) * sizeof(WCHAR)) > _MAX_PATH){goto Add_WWW_VDirW_Exit2;}
  197. // only allow this if they are running as admin.
  198. hr = ERROR_ACCESS_DENIED;
  199. if (!RunningAsAdministrator())
  200. {
  201. goto Add_WWW_VDirW_Exit;
  202. }
  203. // if the service doesn't exist, then
  204. // we don't have to do anyting
  205. if (CheckifServiceExist(_T("IISADMIN")) != 0 )
  206. {
  207. hr = ERROR_SERVICE_DOES_NOT_EXIST;
  208. goto Add_WWW_VDirW_Exit;
  209. }
  210. hr = E_FAIL;
  211. #ifndef _CHICAGO_
  212. hr = CoInitializeEx( NULL, COINIT_MULTITHREADED );
  213. #else
  214. hr = CoInitialize(NULL);
  215. #endif
  216. // no need to call uninit
  217. if( FAILED (hr)) {goto Add_WWW_VDirW_Exit2;}
  218. hr = ::CoCreateInstance(CLSID_MSAdminBase,NULL,CLSCTX_ALL,IID_IMSAdminBase,(void **) & pIMSAdminBase);
  219. if(FAILED (hr))
  220. {goto Add_WWW_VDirW_Exit;}
  221. hr = AddVirtualDir( pIMSAdminBase, pwszMetabasePath, pwszVDirName, pwszPhysicalPath, dwPermissions, iApplicationType);
  222. if(SUCCEEDED(hr))
  223. {hr = pIMSAdminBase->SaveData();}
  224. if (pIMSAdminBase)
  225. {
  226. pIMSAdminBase->Release();
  227. pIMSAdminBase = NULL;
  228. }
  229. Add_WWW_VDirW_Exit:
  230. CoUninitialize();
  231. Add_WWW_VDirW_Exit2:
  232. return hr;
  233. }
  234. HRESULT WINAPI Remove_WWW_VDirW(WCHAR * pwszMetabasePath, WCHAR * pwszVDirName)
  235. {
  236. HRESULT hr = ERROR_BAD_PATHNAME;
  237. IMSAdminBase *pIMSAdminBase = NULL;
  238. // check to make sure it's not larger than max_length!
  239. if ((wcslen(pwszMetabasePath) * sizeof(WCHAR)) > _MAX_PATH){goto Remove_WWW_VDirW_Exit2;}
  240. if ((wcslen(pwszVDirName) * sizeof(WCHAR)) > _MAX_PATH){goto Remove_WWW_VDirW_Exit2;}
  241. // only allow this if they are running as admin.
  242. hr = ERROR_ACCESS_DENIED;
  243. if (!RunningAsAdministrator())
  244. {
  245. goto Remove_WWW_VDirW_Exit;
  246. }
  247. // if the service doesn't exist, then
  248. // we don't have to do anyting
  249. if (CheckifServiceExist(_T("IISADMIN")) != 0 )
  250. {
  251. hr = ERROR_SUCCESS;
  252. goto Remove_WWW_VDirW_Exit2;
  253. }
  254. hr = E_FAIL;
  255. #ifndef _CHICAGO_
  256. hr = CoInitializeEx( NULL, COINIT_MULTITHREADED );
  257. #else
  258. hr = CoInitialize(NULL);
  259. #endif
  260. // no need to call uninit
  261. if( FAILED (hr)) {goto Remove_WWW_VDirW_Exit2;}
  262. hr = ::CoCreateInstance(CLSID_MSAdminBase,NULL,CLSCTX_ALL,IID_IMSAdminBase,(void **) & pIMSAdminBase);
  263. if( FAILED (hr))
  264. {goto Remove_WWW_VDirW_Exit;}
  265. hr = RemoveVirtualDir(pIMSAdminBase, pwszMetabasePath, pwszVDirName);
  266. if(SUCCEEDED(hr))
  267. {hr = pIMSAdminBase->SaveData();}
  268. if (pIMSAdminBase)
  269. {
  270. pIMSAdminBase->Release();
  271. pIMSAdminBase = NULL;
  272. }
  273. Remove_WWW_VDirW_Exit:
  274. CoUninitialize();
  275. Remove_WWW_VDirW_Exit2:
  276. return hr;
  277. }
  278. // Split a line of entry into iExpectedNumOfFields g_fields for MDEntry datatype
  279. BOOL SplitLine(LPTSTR szLine, INT iExpectedNumOfFields)
  280. {
  281. int i = 0;
  282. TCHAR *token = NULL;
  283. token = _tcstok(szLine, FIELD_SEPERATOR);
  284. while (token && i < iExpectedNumOfFields)
  285. {
  286. g_field[i++] = token;
  287. token = _tcstok(NULL, FIELD_SEPERATOR);
  288. }
  289. if (i == iExpectedNumOfFields)
  290. return TRUE;
  291. else
  292. return FALSE;
  293. }
  294. // Split a line of entry into iExpectedNumOfFields g_fields for MDEntry datatype
  295. BOOL SplitLineCommaDelimited(LPTSTR szLine, INT iExpectedNumOfFields)
  296. {
  297. int i = 0;
  298. TCHAR *token;
  299. token = _tcstok(szLine, _T(","));
  300. while (token && i < iExpectedNumOfFields)
  301. {
  302. g_field[i++] = token;
  303. token = _tcstok(NULL, _T(","));
  304. }
  305. if (i == iExpectedNumOfFields)
  306. return TRUE;
  307. else
  308. return FALSE;
  309. }
  310. DWORD GetSizeBasedOnMetaType(DWORD dwDataType,LPTSTR szString)
  311. {
  312. DWORD dwRet = 0;
  313. switch (dwDataType)
  314. {
  315. case DWORD_METADATA:
  316. dwRet = 4;
  317. break;
  318. case STRING_METADATA:
  319. case EXPANDSZ_METADATA:
  320. if (szString == NULL)
  321. {
  322. dwRet = 0;
  323. }
  324. else
  325. {
  326. dwRet = (_tcslen((LPTSTR)szString) + 1) * sizeof(TCHAR);
  327. }
  328. break;
  329. case MULTISZ_METADATA:
  330. if (szString == NULL)
  331. {
  332. dwRet = 0;
  333. }
  334. else
  335. {
  336. dwRet = GetMultiStrSize((LPTSTR)szString) * sizeof(TCHAR);
  337. }
  338. break;
  339. case BINARY_METADATA:
  340. break;
  341. }
  342. return dwRet;
  343. }
  344. // function: MDEntry_Process
  345. //
  346. // The prupose of this function, is to read in a location and value from
  347. // the inf file, if the location in the metabase equals that value, then
  348. // change it to the new value.
  349. // The main use of this function is to change values that we might of set
  350. // incorrectly before.
  351. //
  352. // Format:
  353. // g_field[0] = "2"
  354. // g_field[1] = Location
  355. // g_field[2] = ID
  356. // g_field[3] = DataType
  357. // g_field[4] = DataSize
  358. // g_field[5] = Old Value (if this matches the metabase, we will replace with new value)
  359. // g_field[6] = Inheritable
  360. // g_field[7] = UserType
  361. // g_field[8] = DataType
  362. // g_field[9] = Length
  363. // g_field[10] = Value
  364. //
  365. // Return:
  366. // TRUE - Processed line fine
  367. // FALSE - Error Occurred
  368. BOOL MDEntry_Process(LPTSTR szLine)
  369. {
  370. CMDKey cmdKey;
  371. CMDValue cmdMetaValue;
  372. DWORD dwSize;
  373. DWORD dwDataType;
  374. // Split the line into the difference fields
  375. if (!SplitLine(szLine, 11))
  376. {
  377. return FALSE;
  378. }
  379. // Open the Node
  380. if ( FAILED(cmdKey.OpenNode(g_field[1]) ) )
  381. {
  382. return FALSE;
  383. }
  384. // Retrieve Value
  385. if ( !cmdKey.GetData(cmdMetaValue, _ttoi(g_field[2])) )
  386. {
  387. return FALSE;
  388. }
  389. dwDataType = _ttoi(g_field[3]);
  390. dwSize = _ttoi(g_field[4]);
  391. if (dwSize == 0)
  392. {
  393. dwSize = GetSizeBasedOnMetaType(dwDataType, g_field[5]);
  394. }
  395. if ( dwDataType == DWORD_METADATA )
  396. {
  397. if ( !cmdMetaValue.IsEqual(dwDataType,dwSize, _ttoi(g_field[5])) )
  398. {
  399. // The values did not match
  400. return TRUE;
  401. }
  402. }
  403. else
  404. {
  405. if ( !cmdMetaValue.IsEqual(dwDataType,dwSize,g_field[5]) )
  406. {
  407. // The values did not match
  408. return TRUE;
  409. }
  410. }
  411. dwSize = _ttoi(g_field[9]);
  412. if (dwSize == 0)
  413. {
  414. dwSize = GetSizeBasedOnMetaType(dwDataType, g_field[10]);
  415. }
  416. // At this point, we know that the values matched, so lets replace with the new value.
  417. if ( dwDataType == DWORD_METADATA )
  418. {
  419. DWORD dwValue = _ttoi(g_field[10]);
  420. cmdKey.SetData(_ttoi(g_field[2]),atodw(g_field[6]),_ttoi(g_field[7]),_ttoi(g_field[8]),dwSize,(LPBYTE) &dwValue);
  421. }
  422. else
  423. {
  424. cmdKey.SetData(_ttoi(g_field[2]),atodw(g_field[6]),_ttoi(g_field[7]),_ttoi(g_field[8]),dwSize,(LPBYTE) g_field[10]);
  425. }
  426. cmdKey.Close();
  427. return TRUE;
  428. }
  429. // function: MDEntry_MoveValue
  430. //
  431. // The prupose of this function, is to move a value set in the metabase from one location
  432. // to another. If that value does not exist, then we set a new value for it.
  433. //
  434. // Format:
  435. // g_field[0] = "3"
  436. // g_field[1] = Old Location
  437. // g_field[2] = Old ID
  438. // g_field[3] = New Location
  439. // g_field[4] = New ID
  440. // g_field[5] = Inheritable (Hex)
  441. // g_field[6] = UserType
  442. // g_field[7] = DataType
  443. // g_field[8] = Length
  444. // g_field[9] = Value (if none was detected before)
  445. //
  446. // Return:
  447. // TRUE - Processed line fine
  448. // FALSE - Error Occurred
  449. BOOL MDEntry_MoveValue(LPTSTR szLine)
  450. {
  451. CMDKey cmdKey;
  452. CMDValue cmdMetaValue;
  453. CMDValue cmdDummyValue;
  454. DWORD dwSize;
  455. BOOL fRet = TRUE;
  456. // Split the line into the difference fields
  457. if (!SplitLine(szLine, 10))
  458. {
  459. return FALSE;
  460. }
  461. dwSize = _ttoi(g_field[8]);
  462. if (dwSize == 0)
  463. {
  464. dwSize = GetSizeBasedOnMetaType(_ttoi(g_field[7]), g_field[9]);
  465. }
  466. // First set the value that we are changing the data to
  467. cmdMetaValue.SetValue(_ttoi(g_field[4]),atodw(g_field[5]),_ttoi(g_field[6]),_ttoi(g_field[7]),dwSize,(LPTSTR) g_field[9]);
  468. // Open the Retrieve from Node
  469. if ( SUCCEEDED(cmdKey.OpenNode(g_field[1]) ) )
  470. {
  471. // Retrieve the old Value
  472. if ( cmdKey.GetData(cmdMetaValue, _ttoi(g_field[2])) )
  473. {
  474. // Delete Old Value if it exists
  475. if (FAILED(cmdKey.DeleteData(_ttoi(g_field[2]), ALL_METADATA)))
  476. {
  477. fRet = FALSE;
  478. }
  479. }
  480. cmdKey.Close();
  481. }
  482. // Open the node to Set
  483. if ( FAILED(cmdKey.OpenNode(g_field[3]) ) )
  484. {
  485. return FALSE;
  486. }
  487. // Set New Value (at this point cmdMetaValue, is either the value we orinally set, or
  488. // the value that was retrieved from the old location)
  489. if ( !cmdKey.GetData(cmdDummyValue, _ttoi(g_field[4])) )
  490. {
  491. if (!cmdKey.SetData(cmdMetaValue, _ttoi(g_field[4])))
  492. {
  493. fRet = FALSE;
  494. }
  495. }
  496. cmdKey.Close();
  497. return fRet;
  498. }
  499. INT GetMDEntryFromInfLineEx(LPTSTR szLine, MDEntry *pMDEntry)
  500. {
  501. INT iTemp = MDENTRY_FROMINFFILE_DO_ADD;
  502. INT iReturn = MDENTRY_FROMINFFILE_FAILED;
  503. if (!SplitLine(szLine, 8)){goto GetMDEntryFromInfLineEx_Exit;}
  504. if ( _tcscmp(g_field[0], _T("-1")) != 0)
  505. {
  506. if ( _tcscmp(g_field[0], _T("-0")) != 0)
  507. {
  508. goto GetMDEntryFromInfLineEx_Exit;
  509. }
  510. else
  511. {
  512. iTemp = MDENTRY_FROMINFFILE_DO_DEL;
  513. }
  514. }
  515. pMDEntry->szMDPath = g_field[1];
  516. pMDEntry->dwMDIdentifier = _ttoi(g_field[2]);
  517. pMDEntry->dwMDAttributes = atodw(g_field[3]);
  518. pMDEntry->dwMDUserType = _ttoi(g_field[4]);
  519. pMDEntry->dwMDDataType = _ttoi(g_field[5]);
  520. pMDEntry->dwMDDataLen = _ttoi(g_field[6]);
  521. switch ( pMDEntry->dwMDDataType )
  522. {
  523. case DWORD_METADATA:
  524. {
  525. *(DWORD *)g_pbData = atodw(g_field[7]);
  526. pMDEntry->pbMDData = g_pbData;
  527. break;
  528. }
  529. case MULTISZ_METADATA:
  530. {
  531. CString csMultiSZ;
  532. int nLen = 0;
  533. ReadMultiSZFromInfSection(&csMultiSZ, g_pTheApp->m_hInfHandle, g_field[7]);
  534. nLen = csMultiSZ.GetLength();
  535. HGLOBAL hBlock = NULL;
  536. hBlock = GlobalAlloc(GPTR, (nLen+1)*sizeof(TCHAR));
  537. if (hBlock)
  538. {
  539. TCHAR *p = (LPTSTR)hBlock;
  540. memcpy((LPVOID)hBlock, (LPVOID)(LPCTSTR)csMultiSZ, (nLen+1)*sizeof(TCHAR));
  541. while (*p)
  542. {
  543. if (*p == _T('|'))
  544. *p = _T('\0');
  545. p = _tcsinc(p);
  546. }
  547. pMDEntry->pbMDData = (LPBYTE)hBlock;
  548. }
  549. else
  550. {
  551. iisDebugOut((LOG_TYPE_ERROR, _T("GetMDEntryFromInfLine.1.Failed to allocate memory.\n")));
  552. pMDEntry->dwMDDataLen = 0;
  553. pMDEntry->pbMDData = NULL;
  554. goto GetMDEntryFromInfLineEx_Exit;
  555. }
  556. break;
  557. }
  558. default:
  559. {
  560. // treat the whole thing as string
  561. pMDEntry->pbMDData = (LPBYTE)g_field[7];
  562. break;
  563. }
  564. }
  565. switch (pMDEntry->dwMDDataType)
  566. {
  567. case DWORD_METADATA:
  568. pMDEntry->dwMDDataLen = 4;
  569. break;
  570. case STRING_METADATA:
  571. case EXPANDSZ_METADATA:
  572. pMDEntry->dwMDDataLen = (_tcslen((LPTSTR)pMDEntry->pbMDData) + 1) * sizeof(TCHAR);
  573. break;
  574. case MULTISZ_METADATA:
  575. pMDEntry->dwMDDataLen = GetMultiStrSize((LPTSTR)pMDEntry->pbMDData) * sizeof(TCHAR);
  576. break;
  577. case BINARY_METADATA:
  578. break;
  579. }
  580. iReturn = iTemp;
  581. GetMDEntryFromInfLineEx_Exit:
  582. return iReturn;
  583. }
  584. // Fill in the structure of MDEntry
  585. INT GetMDEntryFromInfLine(LPTSTR szLine, MDEntry *pMDEntry)
  586. {
  587. INT iReturn = MDENTRY_FROMINFFILE_FAILED;
  588. BOOL fMigrate;
  589. BOOL fKeepOldReg;
  590. HKEY hRegRootKey;
  591. LPTSTR szRegSubKey;
  592. LPTSTR szRegValueName;
  593. // Check if the first character is = "-1"
  594. // if it is then do the special metabase slam deal none of this
  595. // upgrade and look up registry junk, just slam the data into the metabase.
  596. if (szLine[0] == _T('-') && szLine[1] == _T('1'))
  597. {
  598. iReturn = GetMDEntryFromInfLineEx(szLine, pMDEntry);
  599. goto GetMDEntryFromInfLine_Exit;
  600. }
  601. if (szLine[0] == _T('-') && szLine[1] == _T('0'))
  602. {
  603. iReturn = GetMDEntryFromInfLineEx(szLine, pMDEntry);
  604. goto GetMDEntryFromInfLine_Exit;
  605. }
  606. if (szLine[0] == _T('2') )
  607. {
  608. MDEntry_Process(szLine);
  609. return MDENTRY_FROMINFFILE_DO_NOTHING;
  610. }
  611. if (szLine[0] == _T('3') )
  612. {
  613. MDEntry_MoveValue(szLine);
  614. return MDENTRY_FROMINFFILE_DO_NOTHING;
  615. }
  616. if (!SplitLine(szLine, 12))
  617. return FALSE;
  618. if ( _tcscmp(g_field[0], _T("1")) == 0)
  619. fMigrate = (g_pTheApp->m_eUpgradeType == UT_10_W95 || g_pTheApp->m_eUpgradeType == UT_351 || g_pTheApp->m_eUpgradeType == UT_10 || g_pTheApp->m_eUpgradeType == UT_20 || g_pTheApp->m_eUpgradeType == UT_30);
  620. else
  621. fMigrate = FALSE;
  622. if ( _tcscmp(g_field[1], _T("1")) == 0)
  623. fKeepOldReg = TRUE;
  624. else
  625. fKeepOldReg = FALSE;
  626. if (_tcsicmp(g_field[2], _T("HKLM")) == 0) {hRegRootKey = HKEY_LOCAL_MACHINE;}
  627. else if (_tcsicmp(g_field[2], _T("HKCR")) == 0) {hRegRootKey = HKEY_CLASSES_ROOT;}
  628. else if (_tcsicmp(g_field[2], _T("HKCU")) == 0) {hRegRootKey = HKEY_CURRENT_USER;}
  629. else if (_tcsicmp(g_field[2], _T("HKU")) == 0) {hRegRootKey = HKEY_USERS;}
  630. else {hRegRootKey = HKEY_LOCAL_MACHINE;}
  631. szRegSubKey = g_field[3];
  632. szRegValueName = g_field[4];
  633. pMDEntry->szMDPath = g_field[5];
  634. pMDEntry->dwMDIdentifier = _ttoi(g_field[6]);
  635. pMDEntry->dwMDAttributes = atodw(g_field[7]);
  636. pMDEntry->dwMDUserType = _ttoi(g_field[8]);
  637. pMDEntry->dwMDDataType = _ttoi(g_field[9]);
  638. pMDEntry->dwMDDataLen = _ttoi(g_field[10]);
  639. switch ( pMDEntry->dwMDDataType )
  640. {
  641. case DWORD_METADATA:
  642. {
  643. *(DWORD *)g_pbData = atodw(g_field[11]);
  644. pMDEntry->pbMDData = g_pbData;
  645. break;
  646. }
  647. case MULTISZ_METADATA:
  648. {
  649. CString csMultiSZ;
  650. int nLen = 0;
  651. ReadMultiSZFromInfSection(&csMultiSZ, g_pTheApp->m_hInfHandle, g_field[11]);
  652. nLen = csMultiSZ.GetLength();
  653. HGLOBAL hBlock = NULL;
  654. hBlock = GlobalAlloc(GPTR, (nLen+1)*sizeof(TCHAR));
  655. if (hBlock)
  656. {
  657. TCHAR *p = (LPTSTR)hBlock;
  658. memcpy((LPVOID)hBlock, (LPVOID)(LPCTSTR)csMultiSZ, (nLen+1)*sizeof(TCHAR));
  659. while (*p)
  660. {
  661. if (*p == _T('|'))
  662. *p = _T('\0');
  663. p = _tcsinc(p);
  664. }
  665. pMDEntry->pbMDData = (LPBYTE)hBlock;
  666. }
  667. else
  668. {
  669. iisDebugOut((LOG_TYPE_ERROR, _T("GetMDEntryFromInfLine.1.Failed to allocate memory.\n")));
  670. pMDEntry->dwMDDataLen = 0;
  671. pMDEntry->pbMDData = NULL;
  672. goto GetMDEntryFromInfLine_Exit;
  673. }
  674. break;
  675. }
  676. default:
  677. {
  678. // treat the whole thing as string
  679. pMDEntry->pbMDData = (LPBYTE)g_field[11];
  680. break;
  681. }
  682. }
  683. // migrate if necessary
  684. if (fMigrate)
  685. {
  686. HKEY hKey = NULL;
  687. LONG err = ERROR_SUCCESS;
  688. DWORD dwType = 0;
  689. DWORD cbData = sizeof(g_pbData);
  690. err = RegOpenKeyEx(hRegRootKey, szRegSubKey, 0, KEY_ALL_ACCESS, &hKey);
  691. if ( err == ERROR_SUCCESS )
  692. {
  693. err = RegQueryValueEx(hKey, szRegValueName, NULL, &dwType, g_pbData, &cbData);
  694. if (err == ERROR_MORE_DATA)
  695. {
  696. free(g_pbData);
  697. g_pbData = NULL;
  698. g_pbData = (LPBYTE)malloc(cbData);
  699. if (!g_pbData)
  700. {
  701. iisDebugOut((LOG_TYPE_ERROR, _T("GetMDEntryFromInfLine.2.Failed to allocate memory.\n")));
  702. err = E_FAIL;
  703. }
  704. else
  705. {
  706. err = RegQueryValueEx(hKey, szRegValueName, NULL, &dwType, g_pbData, &cbData);
  707. }
  708. }
  709. if ( err == ERROR_SUCCESS)
  710. {
  711. if (_tcsicmp(szRegValueName, _T("MaxConnections")) == 0)
  712. {
  713. if (*(DWORD *)g_pbData == 0x186a0) {*(DWORD *)g_pbData = 0x77359400;}
  714. }
  715. pMDEntry->pbMDData = g_pbData;
  716. pMDEntry->dwMDDataLen = cbData;
  717. }
  718. if (fKeepOldReg == FALSE) {err = RegDeleteValue(hKey, szRegValueName);}
  719. RegCloseKey(hKey);
  720. }
  721. }
  722. else if (fKeepOldReg == FALSE)
  723. {
  724. HKEY hKey = NULL;
  725. LONG err = ERROR_SUCCESS;
  726. DWORD dwType = 0;
  727. DWORD cbData = sizeof(g_pbData);
  728. err = RegOpenKeyEx(hRegRootKey, szRegSubKey, 0, KEY_ALL_ACCESS, &hKey);
  729. if ( err == ERROR_SUCCESS )
  730. {
  731. err = RegDeleteValue(hKey, szRegValueName);
  732. RegCloseKey(hKey);
  733. }
  734. }
  735. switch (pMDEntry->dwMDDataType)
  736. {
  737. case DWORD_METADATA:
  738. pMDEntry->dwMDDataLen = 4;
  739. break;
  740. case STRING_METADATA:
  741. case EXPANDSZ_METADATA:
  742. pMDEntry->dwMDDataLen = (_tcslen((LPTSTR)pMDEntry->pbMDData) + 1) * sizeof(TCHAR);
  743. break;
  744. case MULTISZ_METADATA:
  745. pMDEntry->dwMDDataLen = GetMultiStrSize((LPTSTR)pMDEntry->pbMDData) * sizeof(TCHAR);
  746. break;
  747. case BINARY_METADATA:
  748. break;
  749. }
  750. iReturn = MDENTRY_FROMINFFILE_DO_ADD;
  751. GetMDEntryFromInfLine_Exit:
  752. return iReturn;
  753. }
  754. DWORD WriteToMD_AdminInstance(CString csKeyPath,CString& csInstNumber)
  755. {
  756. DWORD dwReturn = ERROR_SUCCESS;
  757. MDEntry stMDEntry;
  758. stMDEntry.szMDPath = (LPTSTR)(LPCTSTR)csKeyPath;
  759. stMDEntry.dwMDIdentifier = MD_ADMIN_INSTANCE;
  760. stMDEntry.dwMDAttributes = METADATA_INHERIT;
  761. stMDEntry.dwMDUserType = IIS_MD_UT_SERVER;
  762. stMDEntry.dwMDDataType = STRING_METADATA;
  763. stMDEntry.dwMDDataLen = (csInstNumber.GetLength() + 1) * sizeof(TCHAR);
  764. stMDEntry.pbMDData = (LPBYTE)(LPCTSTR)csInstNumber;
  765. dwReturn = SetMDEntry(&stMDEntry);
  766. return dwReturn;
  767. }
  768. DWORD WriteToMD_VRootPath(CString csKeyPath, CString csPath, int iOverWriteAlways)
  769. {
  770. DWORD dwReturn = ERROR_SUCCESS;
  771. MDEntry stMDEntry;
  772. // LM/W3SVC/1/ROOT/something
  773. stMDEntry.szMDPath = (LPTSTR)(LPCTSTR)csKeyPath;
  774. stMDEntry.dwMDIdentifier = MD_VR_PATH;
  775. stMDEntry.dwMDAttributes = METADATA_INHERIT;
  776. stMDEntry.dwMDUserType = IIS_MD_UT_FILE;
  777. stMDEntry.dwMDDataType = STRING_METADATA;
  778. stMDEntry.dwMDDataLen = (csPath.GetLength() + 1) * sizeof(TCHAR);
  779. stMDEntry.pbMDData = (LPBYTE)(LPCTSTR)csPath;
  780. //dwReturn = SetMDEntry_Wrap(&stMDEntry);
  781. if (iOverWriteAlways)
  782. {
  783. dwReturn = SetMDEntry(&stMDEntry);
  784. }
  785. else
  786. {
  787. dwReturn = SetMDEntry_NoOverWrite(&stMDEntry);
  788. }
  789. return dwReturn;
  790. }
  791. DWORD WriteToMD_AccessPerm(CString csKeyPath, DWORD dwRegularPerm, int iOverWriteAlways)
  792. {
  793. DWORD dwReturn = ERROR_SUCCESS;
  794. MDEntry stMDEntry;
  795. // LM/W3SVC/1/ROOT/something
  796. stMDEntry.szMDPath = (LPTSTR)(LPCTSTR)csKeyPath;
  797. stMDEntry.dwMDIdentifier = MD_ACCESS_PERM;
  798. stMDEntry.dwMDAttributes = METADATA_INHERIT;
  799. stMDEntry.dwMDUserType = IIS_MD_UT_FILE;
  800. stMDEntry.dwMDDataType = DWORD_METADATA;
  801. stMDEntry.dwMDDataLen = sizeof(DWORD);
  802. stMDEntry.pbMDData = (LPBYTE)&dwRegularPerm;
  803. if (iOverWriteAlways)
  804. {
  805. dwReturn = SetMDEntry(&stMDEntry);
  806. }
  807. else
  808. {
  809. dwReturn = SetMDEntry_NoOverWrite(&stMDEntry);
  810. }
  811. return dwReturn;
  812. }
  813. DWORD WriteToMD_SSLPerm(CString csKeyPath, DWORD dwSSLPerm, int iOverWriteAlways)
  814. {
  815. DWORD dwReturn = ERROR_SUCCESS;
  816. MDEntry stMDEntry;
  817. // LM/W3SVC/1/ROOT/
  818. stMDEntry.szMDPath = (LPTSTR)(LPCTSTR)csKeyPath;
  819. stMDEntry.dwMDIdentifier = MD_SSL_ACCESS_PERM;
  820. stMDEntry.dwMDAttributes = METADATA_INHERIT;
  821. stMDEntry.dwMDUserType = IIS_MD_UT_FILE;
  822. stMDEntry.dwMDDataType = DWORD_METADATA;
  823. stMDEntry.dwMDDataLen = sizeof(DWORD);
  824. stMDEntry.pbMDData = (LPBYTE)&dwSSLPerm;
  825. if (iOverWriteAlways)
  826. {
  827. dwReturn = SetMDEntry(&stMDEntry);
  828. }
  829. else
  830. {
  831. dwReturn = SetMDEntry_NoOverWrite(&stMDEntry);
  832. }
  833. return dwReturn;
  834. }
  835. DWORD WriteToMD_Authorization(CString csKeyPath, DWORD dwValue)
  836. {
  837. DWORD dwReturn = ERROR_SUCCESS;
  838. MDEntry stMDEntry;
  839. // MD_AUTH_ANONYMOUS
  840. // MD_AUTH_BASIC
  841. // MD_AUTH_NT
  842. // LM/W3SVC/1/ROOT/
  843. stMDEntry.szMDPath = (LPTSTR)(LPCTSTR)csKeyPath;
  844. stMDEntry.dwMDIdentifier = MD_AUTHORIZATION;
  845. stMDEntry.dwMDAttributes = METADATA_INHERIT;
  846. stMDEntry.dwMDUserType = IIS_MD_UT_FILE;
  847. stMDEntry.dwMDDataType = DWORD_METADATA;
  848. stMDEntry.dwMDDataLen = sizeof(DWORD);
  849. stMDEntry.pbMDData = (LPBYTE)&dwValue;
  850. dwReturn = SetMDEntry_Wrap(&stMDEntry);
  851. return dwReturn;
  852. }
  853. DWORD WriteToMD_DirBrowsing_WWW(CString csKeyPath)
  854. {
  855. DWORD dwReturn = ERROR_SUCCESS;
  856. MDEntry stMDEntry;
  857. DWORD dwData = 0;
  858. stMDEntry.szMDPath = (LPTSTR)(LPCTSTR)csKeyPath;
  859. stMDEntry.dwMDIdentifier = MD_DIRECTORY_BROWSING;
  860. stMDEntry.dwMDAttributes = METADATA_INHERIT;
  861. stMDEntry.dwMDUserType = IIS_MD_UT_FILE;
  862. stMDEntry.dwMDDataType = DWORD_METADATA;
  863. stMDEntry.dwMDDataLen = sizeof(DWORD);
  864. // default
  865. dwData = MD_DIRBROW_SHOW_DATE |
  866. MD_DIRBROW_SHOW_TIME |
  867. MD_DIRBROW_SHOW_SIZE |
  868. MD_DIRBROW_SHOW_EXTENSION |
  869. MD_DIRBROW_LONG_DATE |
  870. MD_DIRBROW_LOADDEFAULT |
  871. MD_DIRBROW_ENABLED;
  872. stMDEntry.pbMDData = (LPBYTE)&dwData;
  873. dwReturn = SetMDEntry(&stMDEntry);
  874. return dwReturn;
  875. }
  876. DWORD WriteToMD_VRUserName(CString csKeyPath, CString csUserName)
  877. {
  878. DWORD dwReturn = ERROR_SUCCESS;
  879. MDEntry stMDEntry;
  880. // LM/W3SVC/1/ROOT/
  881. stMDEntry.szMDPath = (LPTSTR)(LPCTSTR)csKeyPath;
  882. stMDEntry.dwMDIdentifier = MD_VR_USERNAME;
  883. stMDEntry.dwMDAttributes = METADATA_INHERIT;
  884. stMDEntry.dwMDUserType = IIS_MD_UT_FILE;
  885. stMDEntry.dwMDDataType = STRING_METADATA;
  886. stMDEntry.dwMDDataLen = (csUserName.GetLength() + 1) * sizeof(TCHAR);
  887. stMDEntry.pbMDData = (LPBYTE)(LPCTSTR)csUserName;
  888. dwReturn = SetMDEntry_Wrap(&stMDEntry);
  889. return dwReturn;
  890. }
  891. DWORD WriteToMD_VRPassword(CString csKeyPath, CString csPassword)
  892. {
  893. DWORD dwReturn = ERROR_SUCCESS;
  894. MDEntry stMDEntry;
  895. // LM/W3SVC/1/ROOT/
  896. stMDEntry.szMDPath = (LPTSTR)(LPCTSTR)csKeyPath;
  897. stMDEntry.dwMDIdentifier = MD_VR_PASSWORD;
  898. stMDEntry.dwMDAttributes = METADATA_INHERIT | METADATA_SECURE;
  899. stMDEntry.dwMDUserType = IIS_MD_UT_FILE;
  900. stMDEntry.dwMDDataType = STRING_METADATA;
  901. stMDEntry.dwMDDataLen = (csPassword.GetLength() + 1) * sizeof(TCHAR);
  902. stMDEntry.pbMDData = (LPBYTE)(LPCTSTR)csPassword;
  903. dwReturn = SetMDEntry_Wrap(&stMDEntry);
  904. return dwReturn;
  905. }
  906. DWORD WriteToMD_IIsWebVirtualDir(CString csKeyPath)
  907. {
  908. DWORD dwReturn = ERROR_SUCCESS;
  909. MDEntry stMDEntry;
  910. CString csKeyType;
  911. csKeyType = _T("IIsWebVirtualDir");
  912. stMDEntry.szMDPath = (LPTSTR)(LPCTSTR)csKeyPath;
  913. stMDEntry.dwMDIdentifier = MD_KEY_TYPE;
  914. stMDEntry.dwMDAttributes = METADATA_NO_ATTRIBUTES;
  915. stMDEntry.dwMDUserType = IIS_MD_UT_SERVER;
  916. stMDEntry.dwMDDataType = STRING_METADATA;
  917. stMDEntry.dwMDDataLen = (csKeyType.GetLength() + 1) * sizeof(TCHAR);
  918. stMDEntry.pbMDData = (LPBYTE)(LPCTSTR)csKeyType;
  919. dwReturn = SetMDEntry(&stMDEntry);
  920. return dwReturn;
  921. }
  922. DWORD WriteToMD_IIsFtpVirtualDir(CString csKeyPath)
  923. {
  924. DWORD dwReturn = ERROR_SUCCESS;
  925. MDEntry stMDEntry;
  926. CString csKeyType;
  927. csKeyType = _T("IIsFtpVirtualDir");
  928. stMDEntry.szMDPath = (LPTSTR)(LPCTSTR)csKeyPath;
  929. stMDEntry.dwMDIdentifier = MD_KEY_TYPE;
  930. stMDEntry.dwMDAttributes = METADATA_NO_ATTRIBUTES;
  931. stMDEntry.dwMDUserType = IIS_MD_UT_SERVER;
  932. stMDEntry.dwMDDataType = STRING_METADATA;
  933. stMDEntry.dwMDDataLen = (csKeyType.GetLength() + 1) * sizeof(TCHAR);
  934. stMDEntry.pbMDData = (LPBYTE)(LPCTSTR)csKeyType;
  935. dwReturn = SetMDEntry(&stMDEntry);
  936. return dwReturn;
  937. }
  938. DWORD WriteToMD_IIsWebServerInstance_WWW(CString csKeyPath)
  939. {
  940. DWORD dwReturn = ERROR_SUCCESS;
  941. MDEntry stMDEntry;
  942. CString csKeyType;
  943. csKeyType = _T("IIsWebServer");
  944. // LM/W3SVC/N
  945. stMDEntry.szMDPath = (LPTSTR)(LPCTSTR)csKeyPath;
  946. stMDEntry.dwMDIdentifier = MD_KEY_TYPE;
  947. stMDEntry.dwMDAttributes = METADATA_NO_ATTRIBUTES;
  948. stMDEntry.dwMDUserType = IIS_MD_UT_SERVER;
  949. stMDEntry.dwMDDataType = STRING_METADATA;
  950. stMDEntry.dwMDDataLen = (csKeyType.GetLength() + 1) * sizeof(TCHAR);
  951. stMDEntry.pbMDData = (LPBYTE)(LPCTSTR)csKeyType;
  952. SetMDEntry(&stMDEntry);
  953. return dwReturn;
  954. }
  955. DWORD WriteToMD_IIsFtpServerInstance_FTP(CString csKeyPath)
  956. {
  957. DWORD dwReturn = ERROR_SUCCESS;
  958. MDEntry stMDEntry;
  959. CString csKeyType;
  960. csKeyType = _T("IIsFtpServer");
  961. // LM/FTP/N
  962. stMDEntry.szMDPath = (LPTSTR)(LPCTSTR)csKeyPath;
  963. stMDEntry.dwMDIdentifier = MD_KEY_TYPE;
  964. stMDEntry.dwMDAttributes = METADATA_NO_ATTRIBUTES;
  965. stMDEntry.dwMDUserType = IIS_MD_UT_SERVER;
  966. stMDEntry.dwMDDataType = STRING_METADATA;
  967. stMDEntry.dwMDDataLen = (csKeyType.GetLength() + 1) * sizeof(TCHAR);
  968. stMDEntry.pbMDData = (LPBYTE)(LPCTSTR)csKeyType;
  969. SetMDEntry(&stMDEntry);
  970. return dwReturn;
  971. }
  972. DWORD WriteToMD_AnonymousUserName_FTP(int iUpgradeScenarioSoOnlyOverWriteIfAlreadyThere)
  973. {
  974. DWORD dwReturnTemp = ERROR_SUCCESS;
  975. DWORD dwReturn = ERROR_SUCCESS;
  976. int iOverWriteName = TRUE;
  977. int iOverWritePass = TRUE;
  978. CMDKey cmdKey;
  979. MDEntry stMDEntry;
  980. MDEntry stMDEntry_Pass;
  981. // Add the anonymous user name
  982. stMDEntry.szMDPath = _T("LM/MSFTPSVC");
  983. stMDEntry.dwMDIdentifier = MD_ANONYMOUS_USER_NAME;
  984. stMDEntry.dwMDAttributes = METADATA_INHERIT;
  985. stMDEntry.dwMDUserType = IIS_MD_UT_FILE;
  986. stMDEntry.dwMDDataType = STRING_METADATA;
  987. stMDEntry.dwMDDataLen = (g_pTheApp->m_csFTPAnonyName.GetLength() + 1) * sizeof(TCHAR);
  988. stMDEntry.pbMDData = (LPBYTE)(LPCTSTR)g_pTheApp->m_csFTPAnonyName;
  989. iisDebugOut((LOG_TYPE_PROGRAM_FLOW, _T("FTP Anonymous usrname=%s.\n"), g_pTheApp->m_csFTPAnonyName));
  990. // add anonymous password
  991. stMDEntry_Pass.szMDPath = _T("LM/MSFTPSVC");
  992. stMDEntry_Pass.dwMDIdentifier = MD_ANONYMOUS_PWD;
  993. stMDEntry_Pass.dwMDAttributes = METADATA_INHERIT | METADATA_SECURE;
  994. stMDEntry_Pass.dwMDUserType = IIS_MD_UT_FILE;
  995. stMDEntry_Pass.dwMDDataType = STRING_METADATA;
  996. stMDEntry_Pass.dwMDDataLen = (g_pTheApp->m_csFTPAnonyPassword.GetLength() + 1) * sizeof(TCHAR);
  997. stMDEntry_Pass.pbMDData = (LPBYTE)(LPCTSTR)g_pTheApp->m_csFTPAnonyPassword;
  998. // make sure and delete it first
  999. // DeleteMDEntry(&stMDEntry_Pass);
  1000. if (iUpgradeScenarioSoOnlyOverWriteIfAlreadyThere)
  1001. {
  1002. iOverWriteName = FALSE;
  1003. iOverWritePass = FALSE;
  1004. if (ChkMdEntry_Exist(&stMDEntry))
  1005. {
  1006. iOverWriteName = TRUE;
  1007. }
  1008. if (ChkMdEntry_Exist(&stMDEntry_Pass))
  1009. {
  1010. iOverWritePass = TRUE;
  1011. }
  1012. }
  1013. // --------------------------------------------------
  1014. // always overwrite, we may have changed the password
  1015. // important: Set the username and the password on a single open and close!
  1016. // --------------------------------------------------
  1017. cmdKey.CreateNode(METADATA_MASTER_ROOT_HANDLE, (LPCTSTR)stMDEntry.szMDPath);
  1018. if ( (METADATA_HANDLE) cmdKey )
  1019. {
  1020. if (iOverWriteName)
  1021. {
  1022. dwReturnTemp = ERROR_SUCCESS;
  1023. dwReturnTemp = cmdKey.SetData(stMDEntry.dwMDIdentifier,stMDEntry.dwMDAttributes,stMDEntry.dwMDUserType,stMDEntry.dwMDDataType,stMDEntry.dwMDDataLen,stMDEntry.pbMDData);
  1024. if (FAILED(dwReturnTemp))
  1025. {
  1026. SetErrorFlag(__FILE__, __LINE__);
  1027. iisDebugOut((LOG_TYPE_ERROR, _T("SetMDEntry:SetData(%d), FAILED. Code=0x%x.End.\n"), stMDEntry.dwMDIdentifier, dwReturnTemp));
  1028. dwReturn = dwReturnTemp;
  1029. }
  1030. }
  1031. if (iOverWritePass)
  1032. {
  1033. dwReturnTemp = ERROR_SUCCESS;
  1034. dwReturnTemp = cmdKey.SetData(stMDEntry_Pass.dwMDIdentifier,stMDEntry_Pass.dwMDAttributes,stMDEntry_Pass.dwMDUserType,stMDEntry_Pass.dwMDDataType,stMDEntry_Pass.dwMDDataLen,stMDEntry_Pass.pbMDData);
  1035. if (FAILED(dwReturnTemp))
  1036. {
  1037. SetErrorFlag(__FILE__, __LINE__);
  1038. iisDebugOut((LOG_TYPE_ERROR, _T("SetMDEntry:SetData(%d), FAILED. Code=0x%x.End.\n"), stMDEntry_Pass.dwMDIdentifier, dwReturnTemp));
  1039. dwReturn = dwReturnTemp;
  1040. }
  1041. }
  1042. cmdKey.Close();
  1043. }
  1044. return dwReturn;
  1045. }
  1046. DWORD WriteToMD_AnonymousUserName_WWW(int iUpgradeScenarioSoOnlyOverWriteIfAlreadyThere)
  1047. {
  1048. DWORD dwReturnTemp = ERROR_SUCCESS;
  1049. DWORD dwReturn = ERROR_SUCCESS;
  1050. CMDKey cmdKey;
  1051. MDEntry stMDEntry;
  1052. MDEntry stMDEntry_Pass;
  1053. int iOverWriteName = TRUE;
  1054. int iOverWritePass = TRUE;
  1055. // add anonymous username
  1056. stMDEntry.szMDPath = _T("LM/W3SVC");
  1057. stMDEntry.dwMDIdentifier = MD_ANONYMOUS_USER_NAME;
  1058. stMDEntry.dwMDAttributes = METADATA_INHERIT;
  1059. stMDEntry.dwMDUserType = IIS_MD_UT_FILE;
  1060. stMDEntry.dwMDDataType = STRING_METADATA;
  1061. stMDEntry.dwMDDataLen = (g_pTheApp->m_csWWWAnonyName.GetLength() + 1) * sizeof(TCHAR);
  1062. stMDEntry.pbMDData = (LPBYTE)(LPCTSTR)g_pTheApp->m_csWWWAnonyName;
  1063. iisDebugOut((LOG_TYPE_PROGRAM_FLOW, _T("WWW Anonymous usrname=%s.\n"), g_pTheApp->m_csWWWAnonyName));
  1064. // add anonymous password
  1065. stMDEntry_Pass.szMDPath = _T("LM/W3SVC");
  1066. stMDEntry_Pass.dwMDIdentifier = MD_ANONYMOUS_PWD;
  1067. stMDEntry_Pass.dwMDAttributes = METADATA_INHERIT | METADATA_SECURE;
  1068. stMDEntry_Pass.dwMDUserType = IIS_MD_UT_FILE;
  1069. stMDEntry_Pass.dwMDDataType = STRING_METADATA;
  1070. stMDEntry_Pass.dwMDDataLen = (g_pTheApp->m_csWWWAnonyPassword.GetLength() + 1) * sizeof(TCHAR);
  1071. stMDEntry_Pass.pbMDData = (LPBYTE)(LPCTSTR)g_pTheApp->m_csWWWAnonyPassword;
  1072. // make sure and delete it first
  1073. // DeleteMDEntry(&stMDEntry_Pass);
  1074. if (iUpgradeScenarioSoOnlyOverWriteIfAlreadyThere)
  1075. {
  1076. iOverWriteName = FALSE;
  1077. iOverWritePass = FALSE;
  1078. if (ChkMdEntry_Exist(&stMDEntry))
  1079. {
  1080. iOverWriteName = TRUE;
  1081. }
  1082. if (ChkMdEntry_Exist(&stMDEntry_Pass))
  1083. {
  1084. iOverWritePass = TRUE;
  1085. }
  1086. }
  1087. // --------------------------------------------------
  1088. // always overwrite, we may have changed the password
  1089. // important: Set the username and the password on a single open and close!
  1090. // --------------------------------------------------
  1091. cmdKey.CreateNode(METADATA_MASTER_ROOT_HANDLE, (LPCTSTR)stMDEntry.szMDPath);
  1092. if ( (METADATA_HANDLE) cmdKey )
  1093. {
  1094. if (iOverWriteName)
  1095. {
  1096. dwReturnTemp = ERROR_SUCCESS;
  1097. dwReturnTemp = cmdKey.SetData(stMDEntry.dwMDIdentifier,stMDEntry.dwMDAttributes,stMDEntry.dwMDUserType,stMDEntry.dwMDDataType,stMDEntry.dwMDDataLen,stMDEntry.pbMDData);
  1098. if (FAILED(dwReturnTemp))
  1099. {
  1100. SetErrorFlag(__FILE__, __LINE__);
  1101. iisDebugOut((LOG_TYPE_ERROR, _T("SetMDEntry:SetData(%d), FAILED. Code=0x%x.End.\n"), stMDEntry.dwMDIdentifier, dwReturnTemp));
  1102. dwReturn = dwReturnTemp;
  1103. }
  1104. }
  1105. if (iOverWritePass)
  1106. {
  1107. dwReturnTemp = ERROR_SUCCESS;
  1108. dwReturnTemp = cmdKey.SetData(stMDEntry_Pass.dwMDIdentifier,stMDEntry_Pass.dwMDAttributes,stMDEntry_Pass.dwMDUserType,stMDEntry_Pass.dwMDDataType,stMDEntry_Pass.dwMDDataLen,stMDEntry_Pass.pbMDData);
  1109. if (FAILED(dwReturnTemp))
  1110. {
  1111. SetErrorFlag(__FILE__, __LINE__);
  1112. iisDebugOut((LOG_TYPE_ERROR, _T("SetMDEntry:SetData(%d), FAILED. Code=0x%x.End.\n"), stMDEntry_Pass.dwMDIdentifier, dwReturnTemp));
  1113. dwReturn = dwReturnTemp;
  1114. }
  1115. }
  1116. cmdKey.Close();
  1117. }
  1118. return dwReturn;
  1119. }
  1120. DWORD WriteToMD_AnonymousUseSubAuth_FTP(void)
  1121. {
  1122. DWORD dwReturn = ERROR_SUCCESS;
  1123. MDEntry stMDEntry;
  1124. DWORD dwData = 0;
  1125. // if not PDC, BDC, SamNT, Win95
  1126. stMDEntry.szMDPath = _T("LM/MSFTPSVC");
  1127. stMDEntry.dwMDIdentifier = MD_ANONYMOUS_USE_SUBAUTH;
  1128. stMDEntry.dwMDAttributes = METADATA_INHERIT;
  1129. stMDEntry.dwMDUserType = IIS_MD_UT_FILE;
  1130. stMDEntry.dwMDDataType = DWORD_METADATA;
  1131. stMDEntry.dwMDDataLen = sizeof(DWORD);
  1132. if ((g_pTheApp->m_csFTPAnonyName).CompareNoCase(g_pTheApp->m_csGuestName) == 0)
  1133. dwData = 0x1;
  1134. else
  1135. dwData = 0x0;
  1136. stMDEntry.pbMDData = (LPBYTE)&dwData;
  1137. dwReturn = SetMDEntry_Wrap(&stMDEntry);
  1138. return dwReturn;
  1139. }
  1140. // This is the same as
  1141. // enable password synchronization
  1142. DWORD WriteToMD_AnonymousUseSubAuth_WWW(void)
  1143. {
  1144. DWORD dwReturn = ERROR_SUCCESS;
  1145. MDEntry stMDEntry;
  1146. DWORD dwData = 0;
  1147. // if not PDC, BDC, SamNT, Win95
  1148. stMDEntry.szMDPath = _T("LM/W3SVC");
  1149. stMDEntry.dwMDIdentifier = MD_ANONYMOUS_USE_SUBAUTH;
  1150. stMDEntry.dwMDAttributes = METADATA_INHERIT;
  1151. stMDEntry.dwMDUserType = IIS_MD_UT_FILE;
  1152. stMDEntry.dwMDDataType = DWORD_METADATA;
  1153. stMDEntry.dwMDDataLen = sizeof(DWORD);
  1154. // set the sub authority bit on whether or not the anonymous name is an account
  1155. // on this local machine, or whether it is a domain account somewhere.
  1156. // if ((g_pTheApp->m_csWWWAnonyName).CompareNoCase(g_pTheApp->m_csGuestName) == 0)
  1157. DWORD dwErr;
  1158. if ( IsLocalAccount(g_pTheApp->m_csWWWAnonyName, &dwErr) )
  1159. {
  1160. dwData = 0x1;
  1161. }
  1162. else
  1163. {
  1164. dwData = 0x0;
  1165. }
  1166. stMDEntry.pbMDData = (LPBYTE)&dwData;
  1167. dwReturn = SetMDEntry_Wrap(&stMDEntry);
  1168. return dwReturn;
  1169. }
  1170. DWORD WriteToMD_GreetingMessage_FTP(void)
  1171. {
  1172. DWORD dwReturnTemp = ERROR_SUCCESS;
  1173. DWORD dwReturn = ERROR_SUCCESS;
  1174. MDEntry stMDEntry;
  1175. CRegKey regFTPParam(HKEY_LOCAL_MACHINE, _T("System\\CurrentControlSet\\Services\\MSFTPSVC\\Parameters"), KEY_READ);
  1176. CStringList csGreetingsList;
  1177. int nLen = 0;
  1178. HGLOBAL hBlock = NULL;
  1179. regFTPParam.QueryValue(_T("GreetingMessage"), csGreetingsList);
  1180. if (csGreetingsList.IsEmpty() == FALSE)
  1181. {
  1182. POSITION pos = NULL;
  1183. CString csGreetings;
  1184. LPTSTR p;
  1185. pos = csGreetingsList.GetHeadPosition();
  1186. while (pos)
  1187. {
  1188. csGreetings = csGreetingsList.GetAt(pos);
  1189. if ( !csGreetings.IsEmpty() )
  1190. {
  1191. nLen += csGreetings.GetLength() + 1;
  1192. iisDebugOut((LOG_TYPE_TRACE, _T("pos=%x, greeting=%s, nLen=%d\n"), pos, csGreetings, nLen));
  1193. }
  1194. csGreetingsList.GetNext(pos);
  1195. }
  1196. nLen++;
  1197. hBlock = GlobalAlloc(GPTR, nLen * sizeof(TCHAR));
  1198. if (!hBlock)
  1199. {
  1200. iisDebugOut((LOG_TYPE_ERROR, _T("WriteToMD_GreetingMessage_FTP.1.Failed to allocate memory.\n")));
  1201. return ERROR_OUTOFMEMORY;
  1202. }
  1203. p = (LPTSTR)hBlock;
  1204. pos = csGreetingsList.GetHeadPosition();
  1205. while (pos)
  1206. {
  1207. csGreetings = csGreetingsList.GetAt(pos);
  1208. if ( !csGreetings.IsEmpty() )
  1209. {
  1210. _tcscpy(p, csGreetings);
  1211. p = _tcsninc(p, csGreetings.GetLength())+1;
  1212. iisDebugOut((LOG_TYPE_TRACE, _T("pos=%x, greeting=%s\n"), pos, csGreetings));
  1213. }
  1214. csGreetingsList.GetNext(pos);
  1215. }
  1216. *p = _T('\0');
  1217. p = _tcsinc(p);
  1218. stMDEntry.szMDPath = _T("LM/MSFTPSVC");
  1219. stMDEntry.dwMDIdentifier = MD_GREETING_MESSAGE;
  1220. stMDEntry.dwMDAttributes = METADATA_INHERIT;
  1221. stMDEntry.dwMDUserType = IIS_MD_UT_SERVER;
  1222. stMDEntry.dwMDDataType = MULTISZ_METADATA;
  1223. stMDEntry.dwMDDataLen = nLen * sizeof(TCHAR);
  1224. stMDEntry.pbMDData = (LPBYTE)hBlock;
  1225. dwReturn = SetMDEntry_Wrap(&stMDEntry);
  1226. }
  1227. if (stMDEntry.pbMDData)
  1228. {
  1229. GlobalFree(stMDEntry.pbMDData);
  1230. stMDEntry.pbMDData = NULL;
  1231. }
  1232. return dwReturn;
  1233. }
  1234. DWORD WriteToMD_ServerBindings_HTMLA(CString csKeyPath, UINT iPort)
  1235. {
  1236. DWORD dwReturn = ERROR_SUCCESS;
  1237. MDEntry stMDEntry;
  1238. TCHAR szData[_MAX_PATH];
  1239. memset( (PVOID)szData, 0, sizeof(szData));
  1240. _stprintf(szData, _T(":%d:"), iPort);
  1241. stMDEntry.szMDPath = (LPTSTR)(LPCTSTR)csKeyPath;
  1242. stMDEntry.dwMDIdentifier = MD_SERVER_BINDINGS;
  1243. stMDEntry.dwMDAttributes = 0;
  1244. stMDEntry.dwMDUserType = IIS_MD_UT_SERVER;
  1245. stMDEntry.dwMDDataType = MULTISZ_METADATA;
  1246. stMDEntry.dwMDDataLen = GetMultiStrSize(szData) * sizeof(TCHAR);
  1247. stMDEntry.pbMDData = (LPBYTE)szData;
  1248. dwReturn = SetMDEntry_Wrap(&stMDEntry);
  1249. return dwReturn;
  1250. }
  1251. DWORD WriteToMD_ServerBindings(LPCTSTR szSvcName, CString csKeyPath, CString csIP)
  1252. {
  1253. DWORD dwReturnTemp = ERROR_SUCCESS;
  1254. DWORD dwReturn = ERROR_SUCCESS;
  1255. MDEntry stMDEntry;
  1256. int nPort = 0;
  1257. HGLOBAL hBlock = NULL;
  1258. hBlock = GlobalAlloc(GPTR, _MAX_PATH * sizeof(TCHAR));
  1259. if (!hBlock)
  1260. {
  1261. iisDebugOut((LOG_TYPE_ERROR, _T("WriteToMD_ServerBindings.Failed to allocate memory.\n")));
  1262. return ERROR_OUTOFMEMORY;
  1263. }
  1264. // LM/W3SVC/N
  1265. stMDEntry.szMDPath = (LPTSTR)(LPCTSTR)csKeyPath;
  1266. stMDEntry.dwMDIdentifier = MD_SERVER_BINDINGS;
  1267. stMDEntry.dwMDAttributes = 0;
  1268. stMDEntry.dwMDUserType = IIS_MD_UT_SERVER;
  1269. stMDEntry.dwMDDataType = MULTISZ_METADATA;
  1270. nPort = GetPortNum(szSvcName);
  1271. if (csIP.Compare(_T("null")) == 0)
  1272. _stprintf((LPTSTR)hBlock, _T(":%d:"), nPort);
  1273. else
  1274. _stprintf((LPTSTR)hBlock, _T("%s:%d:"), csIP, nPort);
  1275. stMDEntry.dwMDDataLen = GetMultiStrSize((LPTSTR)hBlock) * sizeof(TCHAR);
  1276. stMDEntry.pbMDData = (LPBYTE)hBlock;
  1277. dwReturnTemp = SetMDEntry_Wrap(&stMDEntry);
  1278. if (stMDEntry.pbMDData)
  1279. {
  1280. GlobalFree(stMDEntry.pbMDData);
  1281. stMDEntry.pbMDData = NULL;
  1282. }
  1283. if (dwReturnTemp != ERROR_SUCCESS){dwReturn = dwReturnTemp;}
  1284. return dwReturn;
  1285. }
  1286. DWORD WriteToMD_SecureBindings(CString csKeyPath, CString csIP)
  1287. {
  1288. DWORD dwReturnTemp = ERROR_SUCCESS;
  1289. DWORD dwReturn = ERROR_SUCCESS;
  1290. MDEntry stMDEntry;
  1291. HGLOBAL hBlock = NULL;
  1292. hBlock = GlobalAlloc(GPTR, _MAX_PATH * sizeof(TCHAR));
  1293. if (!hBlock)
  1294. {
  1295. iisDebugOut((LOG_TYPE_ERROR, _T("WriteToMD_SecureBindings.Failed to allocate memory.\n")));
  1296. return ERROR_OUTOFMEMORY;
  1297. }
  1298. // LM/W3SVC/N
  1299. stMDEntry.szMDPath = (LPTSTR)(LPCTSTR)csKeyPath;
  1300. stMDEntry.dwMDIdentifier = MD_SECURE_BINDINGS;
  1301. stMDEntry.dwMDAttributes = 0;
  1302. stMDEntry.dwMDUserType = IIS_MD_UT_SERVER;
  1303. stMDEntry.dwMDDataType = MULTISZ_METADATA;
  1304. if (csIP.Compare(_T("null"))==0)
  1305. _tcscpy((LPTSTR)hBlock, _T(":443:"));
  1306. else
  1307. _stprintf((LPTSTR)hBlock, _T("%s:443:"), csIP);
  1308. stMDEntry.dwMDDataLen = GetMultiStrSize((LPTSTR)hBlock) * sizeof(TCHAR);
  1309. stMDEntry.pbMDData = (LPBYTE)hBlock;
  1310. dwReturnTemp = SetMDEntry_Wrap(&stMDEntry);
  1311. if (stMDEntry.pbMDData)
  1312. {
  1313. GlobalFree(stMDEntry.pbMDData);
  1314. stMDEntry.pbMDData = NULL;
  1315. }
  1316. if (dwReturnTemp != ERROR_SUCCESS){dwReturn = dwReturnTemp;}
  1317. return dwReturn;
  1318. }
  1319. DWORD WriteToMD_ServerSize(CString csKeyPath)
  1320. {
  1321. DWORD dwReturn = ERROR_SUCCESS;
  1322. MDEntry stMDEntry;
  1323. DWORD dwServerSize = 0x1;
  1324. // LM/W3SVC/N
  1325. // LM/MSFTPSVC/N
  1326. stMDEntry.szMDPath = (LPTSTR)(LPCTSTR)csKeyPath;
  1327. stMDEntry.dwMDIdentifier = MD_SERVER_SIZE;
  1328. stMDEntry.dwMDAttributes = METADATA_INHERIT;
  1329. stMDEntry.dwMDUserType = IIS_MD_UT_SERVER;
  1330. stMDEntry.dwMDDataType = DWORD_METADATA;
  1331. stMDEntry.dwMDDataLen = sizeof(DWORD);
  1332. stMDEntry.pbMDData = (LPBYTE)&dwServerSize;
  1333. dwReturn = SetMDEntry_Wrap(&stMDEntry);
  1334. return dwReturn;
  1335. }
  1336. DWORD WriteToMD_NotDeleteAble(CString csKeyPath)
  1337. {
  1338. DWORD dwReturn = ERROR_SUCCESS;
  1339. return dwReturn;
  1340. }
  1341. DWORD WriteToMD_ServerComment(CString csKeyPath, UINT iCommentID)
  1342. {
  1343. DWORD dwReturn = ERROR_SUCCESS;
  1344. MDEntry stMDEntry;
  1345. CString csDefaultSite;
  1346. MyLoadString(IDS_DEFAULT_WEB_SITE, csDefaultSite);
  1347. if (iCommentID)
  1348. {
  1349. MyLoadString(iCommentID, csDefaultSite);
  1350. }
  1351. // LM/W3SVC/N
  1352. // LM/MSFTPSVC/N
  1353. stMDEntry.szMDPath = (LPTSTR)(LPCTSTR)csKeyPath;
  1354. stMDEntry.dwMDIdentifier = MD_SERVER_COMMENT;
  1355. stMDEntry.dwMDAttributes = METADATA_INHERIT;
  1356. stMDEntry.dwMDUserType = IIS_MD_UT_SERVER;
  1357. stMDEntry.dwMDDataType = STRING_METADATA;
  1358. stMDEntry.dwMDDataLen = (csDefaultSite.GetLength() + 1) * sizeof(TCHAR);
  1359. stMDEntry.pbMDData = (LPBYTE)(LPCTSTR)csDefaultSite;
  1360. dwReturn = SetMDEntry_NoOverWrite(&stMDEntry);
  1361. return dwReturn;
  1362. }
  1363. DWORD WriteToMD_DefaultSiteAndSize(CString csKeyPath)
  1364. {
  1365. DWORD dwReturnTemp = ERROR_SUCCESS;
  1366. DWORD dwReturn = ERROR_SUCCESS;
  1367. UINT iCommentID = IDS_DEFAULT_WEB_SITE;
  1368. // Get Resource ID
  1369. if (csKeyPath.Find(_T("W3SVC")) != -1)
  1370. iCommentID = IDS_DEFAULT_WEB_SITE;
  1371. else
  1372. iCommentID = IDS_DEFAULT_FTP_SITE;
  1373. dwReturnTemp = WriteToMD_ServerComment(csKeyPath, iCommentID);
  1374. if (dwReturnTemp != ERROR_SUCCESS){dwReturn = dwReturnTemp;}
  1375. dwReturnTemp = WriteToMD_ServerSize(csKeyPath);
  1376. if (dwReturnTemp != ERROR_SUCCESS){dwReturn = dwReturnTemp;}
  1377. if (g_pTheApp->m_eNTOSType == OT_NTW)
  1378. {
  1379. dwReturnTemp = WriteToMD_NotDeleteAble(csKeyPath);
  1380. if (dwReturnTemp != ERROR_SUCCESS){dwReturn = dwReturnTemp;}
  1381. }
  1382. return dwReturn;
  1383. }
  1384. DWORD WriteToMD_CertMapper(CString csKeyPath)
  1385. {
  1386. DWORD dwReturnTemp = ERROR_SUCCESS;
  1387. DWORD dwReturn = ERROR_SUCCESS;
  1388. MDEntry stMDEntry;
  1389. CString csKeyType;
  1390. CString csKeyPath2;
  1391. csKeyPath2 = csKeyPath;
  1392. csKeyPath2 += _T("/IIsCertMapper");
  1393. // LM/W3SVC/N/IIsCertMapper
  1394. csKeyType = _T("IIsCertMapper");
  1395. stMDEntry.szMDPath = (LPTSTR)(LPCTSTR)csKeyPath2;
  1396. stMDEntry.dwMDIdentifier = MD_KEY_TYPE;
  1397. stMDEntry.dwMDAttributes = METADATA_NO_ATTRIBUTES;
  1398. stMDEntry.dwMDUserType = IIS_MD_UT_SERVER;
  1399. stMDEntry.dwMDDataType = STRING_METADATA;
  1400. stMDEntry.dwMDDataLen = (csKeyType.GetLength() + 1) * sizeof(TCHAR);
  1401. stMDEntry.pbMDData = (LPBYTE)(LPCTSTR)csKeyType;
  1402. dwReturnTemp = SetMDEntry(&stMDEntry);
  1403. if (dwReturnTemp != ERROR_SUCCESS){dwReturn = dwReturnTemp;}
  1404. return dwReturn;
  1405. }
  1406. //
  1407. // Returns the amount of filters that iis5 needs
  1408. //
  1409. int AddRequiredFilters(TSTR &strTheSection, CStringArray& arrayName,CStringArray& arrayPath)
  1410. {
  1411. iisDebugOut_Start(_T("AddRequiredFilters"),LOG_TYPE_TRACE);
  1412. int c = 0;
  1413. CString csName = _T("");
  1414. CString csPath = _T("");
  1415. TSTR strTheTempSection;
  1416. CStringList strList;
  1417. iisDebugOut((LOG_TYPE_TRACE, _T("ProcessFilters:%s\n"),strTheSection.QueryStr() ));
  1418. if ( strTheTempSection.Copy( strTheSection ) &&
  1419. GetSectionNameToDo(g_pTheApp->m_hInfHandle, &strTheTempSection )
  1420. )
  1421. {
  1422. if (ERROR_SUCCESS == FillStrListWithListOfSections(g_pTheApp->m_hInfHandle, strList, strTheTempSection.QueryStr() ))
  1423. {
  1424. // loop thru the list returned back
  1425. if (strList.IsEmpty() == FALSE)
  1426. {
  1427. POSITION pos = NULL;
  1428. CString csEntry;
  1429. pos = strList.GetHeadPosition();
  1430. while (pos)
  1431. {
  1432. csEntry = _T("");
  1433. csEntry = strList.GetAt(pos);
  1434. // Split into name, and value. look for ","
  1435. int i;
  1436. i = csEntry.ReverseFind(_T(','));
  1437. if (i != -1)
  1438. {
  1439. int len =0;
  1440. len = csEntry.GetLength();
  1441. csPath = csEntry.Right(len - i - 1);
  1442. csName = csEntry.Left(i);
  1443. // only add the filter if the file exists..
  1444. // Check if exists..
  1445. if (IsFileExist(csPath))
  1446. {
  1447. // Add it to our array...
  1448. iisDebugOut((LOG_TYPE_TRACE, _T("Add filter Entry:%s:%s\n"),csName, csPath));
  1449. arrayName.Add(csName);
  1450. arrayPath.Add(csPath);
  1451. c++;
  1452. }
  1453. else
  1454. {
  1455. iisDebugOut((LOG_TYPE_TRACE, _T("Missing Filter:Cannot Find:%s:%s\n"),csName, csPath));
  1456. }
  1457. }
  1458. strList.GetNext(pos);
  1459. }
  1460. }
  1461. }
  1462. }
  1463. iisDebugOut_End(_T("AddRequiredFilters"),LOG_TYPE_TRACE);
  1464. return c;
  1465. }
  1466. DWORD WriteToMD_Filters_WWW(TSTR &strTheSection)
  1467. {
  1468. DWORD dwReturnTemp = ERROR_SUCCESS;
  1469. DWORD dwReturn = ERROR_SUCCESS;
  1470. CString csKeyType;
  1471. CString csPath = _T("");
  1472. int c = 0;
  1473. int j = 0, k=0;
  1474. CStringArray arrayName, arrayPath;
  1475. CString csName, csFilterDlls;
  1476. CRegKey regWWWParam(HKEY_LOCAL_MACHINE, _T("System\\CurrentControlSet\\Services\\W3SVC\\Parameters"), KEY_READ);
  1477. // Add Required Filters to the arrayName
  1478. c = AddRequiredFilters( strTheSection, arrayName, arrayPath);
  1479. // Look thru the registry and
  1480. // find the users filters -- grab then and stick them into our
  1481. // big array of filters...
  1482. if ( (g_pTheApp->m_eUpgradeType == UT_351 || g_pTheApp->m_eUpgradeType == UT_10 || g_pTheApp->m_eUpgradeType == UT_20 || g_pTheApp->m_eUpgradeType == UT_30) && (HKEY)regWWWParam )
  1483. {
  1484. if ( regWWWParam.QueryValue(_T("Filter Dlls"), csFilterDlls) == ERROR_SUCCESS )
  1485. {
  1486. csFilterDlls.TrimLeft();
  1487. csFilterDlls.TrimRight();
  1488. csFilterDlls.MakeLower();
  1489. if (!(csFilterDlls.IsEmpty()))
  1490. {
  1491. CString csTemp;
  1492. while (csFilterDlls.IsEmpty() == FALSE)
  1493. {
  1494. j = csFilterDlls.Find(_T(','));
  1495. if ( j != -1 )
  1496. {
  1497. // means more than 1 item
  1498. csTemp = csFilterDlls.Mid(0, j); // retrieve the first one
  1499. csFilterDlls = csFilterDlls.Mid(j+1);
  1500. csFilterDlls.TrimLeft();
  1501. }
  1502. else
  1503. { // has only one item
  1504. csTemp = csFilterDlls.Mid(0);
  1505. csFilterDlls.Empty();
  1506. }
  1507. csPath = csTemp;
  1508. // get the filename of this dll, i.e., <path>\f1.dll ==> f1
  1509. j = csTemp.ReverseFind(_T('\\'));
  1510. j = (j==-1) ? 0 : j+1; // move j to the first char of the pure filename
  1511. // change csTemp = f1.dll
  1512. csTemp = csTemp.Mid(j);
  1513. j = csTemp.Find(_T('.'));
  1514. csName = (j==-1) ? csTemp : csTemp.Mid(0, j);
  1515. // add to arrary, avoid redundency
  1516. for (k=0; k<c; k++)
  1517. {
  1518. if (csName.Compare((CString)arrayName[k]) == 0)
  1519. break;
  1520. }
  1521. if (k==c)
  1522. {
  1523. arrayName.Add(csName);
  1524. arrayPath.Add(csPath);
  1525. c++;
  1526. }
  1527. }
  1528. }
  1529. }
  1530. }
  1531. // make sure there are entries to write out...
  1532. if (arrayName.GetSize() > 0)
  1533. {
  1534. // if we are upgrading from Beta3 we need to take care to add the new filters to
  1535. // the existing ones that are in the metabase. - boydm
  1536. CString csOrder; // cstrings initialize to empty
  1537. // now the array is ready to use, and it has at least 2 items
  1538. csOrder = (CString)arrayName[0];
  1539. for (k=1; k<c; k++)
  1540. {
  1541. csOrder += _T(",");
  1542. csOrder += arrayName[k];
  1543. }
  1544. // now we have csOrder=f1,f2,f3,sspifilt
  1545. // About KeyType
  1546. dwReturnTemp = WriteToMD_Filters_List_Entry(csOrder);
  1547. if (dwReturnTemp != ERROR_SUCCESS){dwReturn = dwReturnTemp;}
  1548. CString csMDPath;
  1549. for (k=0; k<c; k++)
  1550. {
  1551. dwReturnTemp = WriteToMD_Filter_Entry((CString) arrayName[k], (CString) arrayPath[k]);
  1552. if (dwReturnTemp != ERROR_SUCCESS){dwReturn = dwReturnTemp;}
  1553. }
  1554. }
  1555. return dwReturn;
  1556. }
  1557. #ifndef _CHICAGO_
  1558. // UNDONE: WE NEED TO DO ERROR CHECKING HERE!!!!!!!!!!!!!
  1559. DWORD UpgradeCryptoKeys_WWW(void)
  1560. {
  1561. DWORD dwReturn = ERROR_PATH_NOT_FOUND;
  1562. if ( g_pTheApp->m_eOS != OS_W95 )
  1563. {
  1564. // if upgrading iis 2 or 3, then the keys are stored in the LSA/Registry.
  1565. if (g_pTheApp->m_eUpgradeType == UT_351 || g_pTheApp->m_eUpgradeType == UT_10 || g_pTheApp->m_eUpgradeType == UT_20 || g_pTheApp->m_eUpgradeType == UT_30 )
  1566. {
  1567. // prepare the machine name
  1568. WCHAR wchMachineName[UNLEN + 1];
  1569. memset( (PVOID)wchMachineName, 0, sizeof(wchMachineName));
  1570. #if defined(UNICODE) || defined(_UNICODE)
  1571. wcsncpy(wchMachineName, g_pTheApp->m_csMachineName, UNLEN);
  1572. #else
  1573. MultiByteToWideChar(CP_ACP, 0, (LPCSTR)g_pTheApp->m_csMachineName, -1, (LPWSTR)wchMachineName, UNLEN);
  1574. #endif
  1575. // upgrade the keys
  1576. UpgradeLSAKeys( wchMachineName );
  1577. dwReturn = ERROR_SUCCESS;
  1578. }
  1579. // if upgrading iis 4, then the keys are stored in the metabase
  1580. if (!g_pTheApp->m_bWin95Migration)
  1581. {
  1582. if (g_pTheApp->m_bUpgradeTypeHasMetabaseFlag)
  1583. {
  1584. Upgradeiis4Toiis5MetabaseSSLKeys();
  1585. dwReturn = ERROR_SUCCESS;
  1586. }
  1587. }
  1588. }
  1589. return dwReturn;
  1590. }
  1591. #endif //_CHICAGO_
  1592. // add pSrc on top of pDest
  1593. void Merge2IPNodes(CMapStringToString *pSrc, CMapStringToString *pDest)
  1594. {
  1595. CString csName, csSrcValue, csDestValue;
  1596. POSITION pos = pSrc->GetStartPosition();
  1597. while (pos)
  1598. {
  1599. pSrc->GetNextAssoc(pos, csName, csSrcValue);
  1600. if (pDest->Lookup(csName, csDestValue) == FALSE)
  1601. {
  1602. // add this new value to pDest
  1603. pDest->SetAt(csName, csSrcValue);
  1604. }
  1605. }
  1606. return;
  1607. }
  1608. /*
  1609. Logic:
  1610. 1. Create pNew, which contains new vroots except the home root
  1611. 2. Get pMap from registry in Upgrade case, or pMap is empty in Fresh case.
  1612. 3. If pMap is empty, add home root into pNews, set pMap to contain null==>pNew. goto 8.
  1613. 4. If pMap is not empty and nullNode exists, Merge nullNode into pNew. goto 6.
  1614. 5. If pMap is not empty and nullNode does not exist, goto 6.
  1615. 6. Merge pNew onto each ipNodes in the pMap
  1616. 7. For nullNode in pMap, if there is no / (home root) exists, delete this nullNode from the pMap.
  1617. 8. Done.
  1618. */
  1619. void CreateWWWVRMap(CMapStringToOb *pMap)
  1620. {
  1621. CString name, value;
  1622. CMapStringToString *pNew;
  1623. {
  1624. pNew = new CMapStringToString;
  1625. // only create new scripts directories if this is either new or maintenance. If we were to
  1626. // create it here on an upgrade, it replaces the user's old scripts directory. - Actually
  1627. // this is only true if the user's old script directory has different capitalization than
  1628. // what is listed below. This is because the merge routine that mushes together the pNew
  1629. // and pMap lists is case sensitive. The old ones are usually "Scripts" with a capital S.
  1630. /*
  1631. if ( (g_pTheApp->m_eInstallMode == IM_FRESH)||(g_pTheApp->m_eInstallMode == IM_MAINTENANCE) )
  1632. {
  1633. name = _T("/scripts");
  1634. value.Format(_T("%s,,%x"), g_pTheApp->m_csPathScripts, MD_ACCESS_EXECUTE);
  1635. value.MakeLower();
  1636. pNew->SetAt(name, value);
  1637. }
  1638. */
  1639. // Create the scripts dir always.
  1640. // HANDLED in the inf file in iis6
  1641. /*
  1642. name = _T("/scripts");
  1643. value.Format(_T("%s,,%x"), g_pTheApp->m_csPathScripts, MD_ACCESS_EXECUTE);
  1644. value.MakeLower();
  1645. pNew->SetAt(name, value);
  1646. */
  1647. /*
  1648. name = _T("/iishelp");
  1649. value.Format(_T("%s\\Help\\iishelp,,%x"), g_pTheApp->m_csWinDir, MD_ACCESS_SCRIPT | MD_ACCESS_READ);
  1650. value.MakeLower();
  1651. pNew->SetAt(name, value);
  1652. */
  1653. // bug # 123133 iis5.1 Remove samples from install
  1654. // name = _T("/iissamples");
  1655. // value.Format(_T("%s,,%x"), g_pTheApp->m_csPathIISSamples, MD_ACCESS_SCRIPT | MD_ACCESS_READ);
  1656. // value.MakeLower();
  1657. // pNew->SetAt(name, value);
  1658. /*
  1659. removed per bug#197982 8/11/98
  1660. The decision was made NOT to setup the IISADMPWD vdir.
  1661. can you pls still copy the files but not set up the vdir?
  1662. if (g_pTheApp->m_eOS != OS_W95)
  1663. {
  1664. name = _T("/iisadmpwd");
  1665. value.Format(_T("%s\\iisadmpwd,,%x"), g_pTheApp->m_csPathInetsrv, MD_ACCESS_EXECUTE);
  1666. value.MakeLower();
  1667. pNew->SetAt(name, value);
  1668. }
  1669. */
  1670. /*
  1671. // actually this was removed per bug318938
  1672. // --------------------------------
  1673. // handled in the inf file for iis6
  1674. // --------------------------------
  1675. // Add the msadc virtual root
  1676. // Get the path for msadc...
  1677. // C:\Program Files\Common Files\system\msadc
  1678. CString csCommonFilesPath;
  1679. csCommonFilesPath = g_pTheApp->m_csSysDrive + _T("\\Program Files\\Common Files");
  1680. CRegKey regCurrentVersion(HKEY_LOCAL_MACHINE, _T("Software\\Microsoft\\Windows\\CurrentVersion"), KEY_READ);
  1681. if ( (HKEY)regCurrentVersion )
  1682. {
  1683. if (regCurrentVersion.QueryValue(_T("CommonFilesDir"), csCommonFilesPath) != 0)
  1684. {
  1685. csCommonFilesPath = g_pTheApp->m_csSysDrive + _T("\\Program Files\\Common Files");
  1686. }
  1687. else
  1688. {
  1689. if (-1 != csCommonFilesPath.Find(_T('%')) )
  1690. {
  1691. // there is a '%' in the string
  1692. TCHAR szTempDir[_MAX_PATH];
  1693. _tcscpy(szTempDir, csCommonFilesPath);
  1694. if (ExpandEnvironmentStrings( (LPCTSTR)csCommonFilesPath, szTempDir, sizeof(szTempDir)/sizeof(TCHAR)))
  1695. {
  1696. csCommonFilesPath = szTempDir;
  1697. }
  1698. }
  1699. }
  1700. }
  1701. SetupSetDirectoryId_Wrapper(g_pTheApp->m_hInfHandle, 32777, g_pTheApp->m_csPathProgramFiles);
  1702. CString csCommonFilesPath2;
  1703. csCommonFilesPath2 = AddPath(csCommonFilesPath, _T("System\\msadc"));
  1704. name = _T("/msadc");
  1705. value.Format(_T("%s,,%x"), csCommonFilesPath2, MD_ACCESS_READ | MD_ACCESS_EXECUTE | MD_ACCESS_SCRIPT);
  1706. value.MakeLower();
  1707. pNew->SetAt(name, value);
  1708. */
  1709. }
  1710. if (g_pTheApp->m_eUpgradeType == UT_10_W95 || g_pTheApp->m_eUpgradeType == UT_351 || g_pTheApp->m_eUpgradeType == UT_10 || g_pTheApp->m_eUpgradeType == UT_20 || g_pTheApp->m_eUpgradeType == UT_30)
  1711. {
  1712. CElem elem;
  1713. elem.ReadRegVRoots(REG_WWWVROOTS, pMap);
  1714. // check to see if pMap contains a null node (default website). If there is no default
  1715. // node, then add one with nothing in it. This will later be merged with the pNew map - boydm
  1716. CMapStringToString *pNullNode;
  1717. if ( !pMap->Lookup(_T("null"),(CObject*&)pNullNode) )
  1718. {
  1719. // there is no node in the map that corresponds to the default website. We must create
  1720. // one at this point and add it to the list
  1721. pNullNode = new CMapStringToString;
  1722. if (pNullNode)
  1723. {
  1724. // add the home root to the new null node
  1725. name = _T("/");
  1726. value.Format(_T("%s,,%x"), g_pTheApp->m_csPathWWWRoot, MD_ACCESS_SCRIPT | MD_ACCESS_READ);
  1727. value.MakeLower();
  1728. pNullNode->SetAt(name, value);
  1729. // add it to the pMap
  1730. pMap->SetAt(_T("null"), pNullNode);
  1731. }
  1732. }
  1733. if (pMap->IsEmpty())
  1734. {iisDebugOut((LOG_TYPE_TRACE, _T("UpgradeVDirs:No VDirs To Upgrade\n")));}
  1735. }
  1736. if ( pMap->IsEmpty() )
  1737. {
  1738. // we don't need to add a default website when
  1739. // add home root to pNew, set pMap to contain null==>pNew. Done.
  1740. name = _T("/");
  1741. value.Format(_T("%s,,%x"), g_pTheApp->m_csPathWWWRoot, MD_ACCESS_SCRIPT | MD_ACCESS_READ);
  1742. value.MakeLower();
  1743. pNew->SetAt(name, value);
  1744. pMap->SetAt(_T("null"), pNew);
  1745. }
  1746. else
  1747. {
  1748. CMapStringToString *pNullObj;
  1749. CString csIP;
  1750. CMapStringToString *pObj;
  1751. POSITION pos = NULL;
  1752. // if there is a default website in the map, add all the "standard" new virtual
  1753. // directories to it.
  1754. if (pMap->Lookup(_T("null"), (CObject*&)pNullObj))
  1755. {
  1756. // add nullNode contents into pNew
  1757. Merge2IPNodes(pNullObj, pNew);
  1758. }
  1759. // add pNew to each ipNodes in the pMap
  1760. pos = pMap->GetStartPosition();
  1761. while (pos)
  1762. {
  1763. pMap->GetNextAssoc(pos, csIP, (CObject*&)pObj);
  1764. Merge2IPNodes(pNew, pObj);
  1765. pMap->SetAt(csIP, pObj);
  1766. }
  1767. /*
  1768. #ifdef 0 // boydm - we don't know why it would do this.
  1769. // delete the nullNode if it doesn't contain home root
  1770. if (pMap->Lookup(_T("null"), (CObject*&)pNullObj)) {
  1771. if (pNullObj->Lookup(_T("/"), value) == FALSE) {
  1772. // delete this nullNode from pMap
  1773. delete pNullObj;
  1774. pMap->RemoveKey(_T("null"));
  1775. }
  1776. }
  1777. #endif
  1778. */
  1779. }
  1780. return;
  1781. }
  1782. void CreateFTPVRMap(CMapStringToOb *pMap)
  1783. {
  1784. CString name, value;
  1785. CMapStringToString *pNew;
  1786. pNew = new CMapStringToString;
  1787. if (g_pTheApp->m_eUpgradeType == UT_10_W95 || g_pTheApp->m_eUpgradeType == UT_351 || g_pTheApp->m_eUpgradeType == UT_10 || g_pTheApp->m_eUpgradeType == UT_20 || g_pTheApp->m_eUpgradeType == UT_30)
  1788. {
  1789. CElem elem;
  1790. elem.ReadRegVRoots(REG_FTPVROOTS, pMap);
  1791. }
  1792. if ( pMap->IsEmpty() )
  1793. {
  1794. // add home root to pNew, set pMap to contain null==>pNew. Done.
  1795. name = _T("/");
  1796. value.Format(_T("%s,,%x"), g_pTheApp->m_csPathFTPRoot, MD_ACCESS_READ);
  1797. value.MakeLower();
  1798. pNew->SetAt(name, value);
  1799. pMap->SetAt(_T("null"), pNew);
  1800. }
  1801. else
  1802. {
  1803. CMapStringToString *pNullObj;
  1804. CString csIP;
  1805. CMapStringToString *pObj;
  1806. POSITION pos = NULL;
  1807. if (pMap->Lookup(_T("null"), (CObject*&)pNullObj))
  1808. {
  1809. // add nullNode contents into pNew
  1810. Merge2IPNodes(pNullObj, pNew);
  1811. }
  1812. // add pNew to each ipNodes in the pMap
  1813. pos = pMap->GetStartPosition();
  1814. while (pos)
  1815. {
  1816. pMap->GetNextAssoc(pos, csIP, (CObject*&)pObj);
  1817. Merge2IPNodes(pNew, pObj);
  1818. pMap->SetAt(csIP, pObj);
  1819. }
  1820. // delete the nullNode if it doesn't contain home root
  1821. if (pMap->Lookup(_T("null"), (CObject*&)pNullObj))
  1822. {
  1823. if (pNullObj->Lookup(_T("/"), value) == FALSE)
  1824. {
  1825. // delete this nullNode from pMap
  1826. delete pNullObj;
  1827. pMap->RemoveKey(_T("null"));
  1828. }
  1829. }
  1830. }
  1831. return;
  1832. }
  1833. void EmptyMap(CMapStringToOb *pMap)
  1834. {
  1835. POSITION pos = pMap->GetStartPosition();
  1836. while (pos)
  1837. {
  1838. CString csKey;
  1839. CMapStringToString *pObj;
  1840. pMap->GetNextAssoc(pos, csKey, (CObject*&)pObj);
  1841. delete pObj;
  1842. }
  1843. pMap->RemoveAll();
  1844. }
  1845. void DumpVRootList(CMapStringToOb *pMap)
  1846. {
  1847. /*
  1848. CMapStringToString *pGlobalObj;
  1849. if (pMap->Lookup(_T("null"), (CObject*&)pGlobalObj))
  1850. {
  1851. POSITION pos = pGlobalObj->GetStartPosition();
  1852. while (pos)
  1853. {
  1854. CString csValue;
  1855. CString csName;
  1856. pGlobalObj->GetNextAssoc(pos, csName, csValue);
  1857. // dump out the vroots...
  1858. iisDebugOut((LOG_TYPE_TRACE, _T("DumpVRootList: Virtual Root to create():%s=%s\n")));
  1859. }
  1860. }
  1861. */
  1862. CString csIP;
  1863. CMapStringToString *pObj;
  1864. //
  1865. // loop though the virtual servers...
  1866. //
  1867. POSITION pos0 = pMap->GetStartPosition();
  1868. while (pos0)
  1869. {
  1870. csIP.Empty();
  1871. pMap->GetNextAssoc(pos0, csIP, (CObject*&)pObj);
  1872. POSITION pos1 = pObj->GetStartPosition();
  1873. while (pos1)
  1874. {
  1875. CString csValue;
  1876. CString csName;
  1877. pObj->GetNextAssoc(pos1, csName, csValue);
  1878. // dump out the vroots...
  1879. iisDebugOut((LOG_TYPE_PROGRAM_FLOW, _T("DumpVRootList: ip=%s:VRoot to create:%s=%s\n"), csIP, csName, csValue));
  1880. }
  1881. }
  1882. return;
  1883. }
  1884. void SsyncVRoots(LPCTSTR szSvcName, CMapStringToOb *pMap)
  1885. {
  1886. CString csParam = _T("System\\CurrentControlSet\\Services\\");
  1887. csParam += szSvcName;
  1888. csParam += _T("\\Parameters");
  1889. CRegKey regParam(HKEY_LOCAL_MACHINE, csParam);
  1890. if ((HKEY)regParam)
  1891. {
  1892. // remove the old virtual roots key
  1893. regParam.DeleteTree(_T("Virtual Roots"));
  1894. /*
  1895. CMapStringToString *pGlobalObj;
  1896. if (pMap->Lookup(_T("null"), (CObject*&)pGlobalObj)) {
  1897. // recreate the key
  1898. CRegKey regVRoots(_T("Virtual Roots"), (HKEY)regParam);
  1899. if ((HKEY)regVRoots) {
  1900. POSITION pos = pGlobalObj->GetStartPosition();
  1901. while (pos) {
  1902. CString csValue;
  1903. CString csName;
  1904. pGlobalObj->GetNextAssoc(pos, csName, csValue);
  1905. regVRoots.SetValue(csName, csValue);
  1906. }
  1907. }
  1908. }
  1909. */
  1910. }
  1911. }
  1912. void AddVRootsToMD(LPCTSTR szSvcName)
  1913. {
  1914. iisDebugOut_Start(_T("AddVRootsToMD"),LOG_TYPE_TRACE);
  1915. CMapStringToOb Map;
  1916. if (_tcsicmp(szSvcName, _T("W3SVC")) == 0)
  1917. {
  1918. CreateWWWVRMap(&Map);
  1919. }
  1920. if (_tcsicmp(szSvcName, _T("MSFTPSVC")) == 0)
  1921. {
  1922. CreateFTPVRMap(&Map);
  1923. }
  1924. //Display Virtuall roots which we should create!!!
  1925. DumpVRootList(&Map);
  1926. // all ssyncvroots seems to do is delete the old vroots from the registry, if there are any
  1927. SsyncVRoots(szSvcName, &Map);
  1928. // This actually takes the virtual website and root map
  1929. // built in CreateWWWVRMap and applies it to the metabase
  1930. AddVRMapToMD(szSvcName, &Map);
  1931. EmptyMap(&Map);
  1932. iisDebugOut_End(_T("AddVRootsToMD"),LOG_TYPE_TRACE);
  1933. return;
  1934. }
  1935. // This routine scans through the virtual web sites and adds them to the metabase
  1936. // boydm - I removed much of the guts of this routine and put it into AddVirtualServer above.
  1937. // This allows me to treat the null node specially in order to guarantee it goes on site 1
  1938. void AddVRMapToMD(LPCTSTR szSvcName, CMapStringToOb *pMap)
  1939. {
  1940. UINT i = 1; // instance number is in range of 1 - 4 billion
  1941. CString csRoot = _T("LM/");
  1942. csRoot += szSvcName; // "LM/W3SVC"
  1943. csRoot.MakeUpper();
  1944. CMapStringToString *pObj = NULL;
  1945. CString csIP;
  1946. // look for the null node. If it is there, then that is the default server.
  1947. // we must add that one first so that it is virtual server number 1
  1948. if ( pMap->Lookup(_T("null"),(CObject*&)pObj) )
  1949. {
  1950. // set the ip string to null
  1951. csIP = _T("null");
  1952. // add the virtual server
  1953. // make sure to specify site #1 !!!
  1954. i = AddVirtualServer( szSvcName, 1, pObj, csRoot, csIP) + 1;
  1955. // remove the null mapping list from the main mapping object
  1956. if ( pMap->RemoveKey( _T("null") ) )
  1957. {
  1958. // clean it up from memory too
  1959. delete pObj;
  1960. pObj = NULL;
  1961. }
  1962. }
  1963. // loop though the rest of the virtual servers and add them as well
  1964. POSITION pos0 = pMap->GetStartPosition();
  1965. while (pos0)
  1966. {
  1967. csIP.Empty();
  1968. pMap->GetNextAssoc(pos0, csIP, (CObject*&)pObj);
  1969. // get the next unused instance number and add from there...
  1970. i = GetInstNumber(csRoot, i);
  1971. // add the virtual server
  1972. i = AddVirtualServer( szSvcName, i, pObj, csRoot, csIP) + 1;
  1973. }
  1974. }
  1975. int GetPortNum(LPCTSTR szSvcName)
  1976. {
  1977. CString csPath = _T("SYSTEM\\CurrentControlSet\\Control\\ServiceProvider\\ServiceTypes\\");
  1978. csPath += szSvcName;
  1979. DWORD dwPort = 0;
  1980. if (_tcsicmp(szSvcName, _T("W3SVC")) == 0) {dwPort = 80;}
  1981. if (_tcsicmp(szSvcName, _T("MSFTPSVC")) == 0) {dwPort = 21;}
  1982. CRegKey regKey(HKEY_LOCAL_MACHINE, csPath, KEY_READ);
  1983. if ( (HKEY)regKey )
  1984. {
  1985. regKey.QueryValue(_T("TcpPort"), dwPort);
  1986. }
  1987. return (int)dwPort;
  1988. }
  1989. // if not exist, create it; else, return immediately
  1990. void AddMDVRootTree(CString csKeyPath, CString csName, CString csValue, LPCTSTR pszIP, UINT nProgressBarTextWebInstance)
  1991. {
  1992. CString csPath = csKeyPath;
  1993. CMDKey cmdKey;
  1994. csPath += _T("/Root");
  1995. if (csName.Compare(_T("/")) != 0)
  1996. csPath += csName; // LM/W3SVC/N//iisadmin
  1997. cmdKey.OpenNode(csPath);
  1998. if ( (METADATA_HANDLE)cmdKey )
  1999. {
  2000. cmdKey.Close();
  2001. }
  2002. else
  2003. {
  2004. CreateMDVRootTree(csKeyPath, csName, csValue, pszIP, nProgressBarTextWebInstance);
  2005. }
  2006. return;
  2007. }
  2008. int SetVRootPermissions_w3svc(CString csKeyPath, LPTSTR szPath, DWORD *pdwPerm)
  2009. {
  2010. int iReturn = TRUE;
  2011. DWORD dwPerm;
  2012. dwPerm = *pdwPerm;
  2013. if (csKeyPath.Find(_T("W3SVC")) != -1)
  2014. {
  2015. iisDebugOut_Start1(_T("SetVRootPermissions_w3svc"), csKeyPath, LOG_TYPE_TRACE);
  2016. // if this is www, and it is because of the above test, then we always
  2017. // turn on the MD_ACCESS_SCRIPT flag if MD_ACCESS_EXECUTE is on. This
  2018. // fixes a Upgrade from IIS3 problem - boydm
  2019. if ( dwPerm & MD_ACCESS_EXECUTE )
  2020. {
  2021. dwPerm |= MD_ACCESS_SCRIPT;
  2022. }
  2023. // add MD_ACCESS_SCRIPT to wwwroot
  2024. if (csKeyPath.Right(4) == _T("ROOT"))
  2025. {
  2026. dwPerm |= MD_ACCESS_SCRIPT;
  2027. }
  2028. // reset /iisadmin path, add more Permission
  2029. if (csKeyPath.Right(8) == _T("IISADMIN"))
  2030. {
  2031. CString csPath = g_pTheApp->m_csPathInetsrv;
  2032. csPath += _T("\\iisadmin");
  2033. _tcscpy(szPath, csPath);
  2034. if (g_pTheApp->m_eOS == OS_NT && g_pTheApp->m_eNTOSType != OT_NTW)
  2035. {
  2036. dwPerm |= MD_ACCESS_SCRIPT | MD_ACCESS_READ;
  2037. }
  2038. else
  2039. {
  2040. dwPerm |= MD_ACCESS_SCRIPT | MD_ACCESS_READ | MD_ACCESS_NO_REMOTE_READ | MD_ACCESS_NO_REMOTE_SCRIPT;
  2041. }
  2042. }
  2043. *pdwPerm = dwPerm;
  2044. }
  2045. iisDebugOut((LOG_TYPE_TRACE, _T("SetVRootPermissions_w3svc:(%s),return=0x%x.\n"), csKeyPath, dwPerm));
  2046. return iReturn;
  2047. }
  2048. /*
  2049. [/W3SVC/1/ROOT]
  2050. AccessPerm : [IF] (DWORD) 0x201={Read Script}
  2051. 6039 : [IF] (DWORD) 0x1={1}
  2052. VrPath : [IF] (STRING) "c:\inetpub\wwwroot"
  2053. KeyType : [S] (STRING) "IIsWebVirtualDir"
  2054. [/W3SVC/1/ROOT/IISADMIN]
  2055. AccessPerm : [IF] (DWORD) 0x201={Read Script}
  2056. Authorization : [IF] (DWORD) 0x4={NT}
  2057. VrPath : [IF] (STRING) "C:\WINNT\System32\inetsrv\iisadmin"
  2058. KeyType : [S] (STRING) "IIsWebVirtualDir"
  2059. IpSec : [IRF] (BINARY) 0x18 00 00 80 20 00 00 80 3c 00 00 80 44 00 00 80 01 00 00 00 4c 00 00 00 00 00 00 00 00 00 00 00 01 00 00 00 01 00 00 00 02 00 00 00 02 00 00 00 04 00 00 00 00 00 00 00 4c 00 00 80 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ff ff ff ff 7f 00 00 01
  2060. CustomError : [IF] (MULTISZ) "400,*,FILE,C:\WINNT\help\iisHelp\common\400.htm" "401,1,FILE,C:\WINNT\help\iisHelp\common\401-1.htm" "401,2,FILE,C:\WINNT\help\iisHelp\common\401-2.htm" "401,3,FILE,C:\WINNT\help\iisHelp\common\401-3.htm" "401,4,FILE,C:\WINNT\help\iisHelp\common\401-4.htm" "401,5,FILE,C:\WINNT\help\iisHelp\common\401-5.htm" "403,1,FILE,C:\WINNT\help\iisHelp\common\403-1.htm" "403,2,FILE,C:\WINNT\help\iisHelp\common\403-2.htm" "403,3,FILE,C:\WINNT\help\iisHelp\common\403-3.htm" "403,4,FILE,C:\WINNT\help\iisHelp\common\403-4.htm" "403,5,FILE,C:\WINNT\help\iisHelp\common\403-5.htm" "403,7,FILE,C:\WINNT\help\iisHelp\common\403-7.htm" "403,8,FILE,C:\WINNT\help\iisHelp\common\403-8.htm" "403,9,FILE,C:\WINNT\help\iisHelp\common\403-9.htm" "403,10,FILE,C:\WINNT\help\iisHelp\common\403-10.htm" "403,11,FILE,C:\WINNT\help\iisHelp\common\403-11.htm" "403,12,FILE,C:\WINNT\help\iisHelp\common\403-12.htm" "404,*,FILE,C:\WINNT\help\iisHelp\common\404b.htm" "405,*,FILE,C:\WINNT\help\iisHelp\common\405.htm" "406,*,FILE,C:\WINNT\help\iisHelp\common\406.htm" "407,*,FILE,C:\WINNT\help\iisHelp\common\407.htm" "412,*,FILE,C:\WINNT\help\iisHelp\common\412.htm" "414,*,FILE,C:\WINNT\help\iisHelp\common\414.htm" "500,12,FILE,C:\WINNT\help\iisHelp\common\500-12.htm" "500,13,FILE,C:\WINNT\help\iisHelp\common\500-13.htm" "500,15,FILE,C:\WINNT\help\iisHelp\common\500-15.htm" "500,100,URL,/help/common/500-100.asp" "403,6,FILE,C:\WINNT\help\iishelp\common\htmla.htm"
  2061. [/W3SVC/1/ROOT/IISSAMPLES]
  2062. AccessPerm : [IF] (DWORD) 0x201={Read Script}
  2063. VrPath : [IF] (STRING) "c:\inetpub\iissamples"
  2064. KeyType : [S] (STRING) "IIsWebVirtualDir"
  2065. [/W3SVC/1/ROOT/IISHELP]
  2066. AccessPerm : [IF] (DWORD) 0x201={Read Script}
  2067. VrPath : [IF] (STRING) "c:\winnt\help\iishelp"
  2068. KeyType : [S] (STRING) "IIsWebVirtualDir"
  2069. CustomError : [IF] (MULTISZ) "400,*,FILE,C:\WINNT\help\iisHelp\common\400.htm" "401,1,FILE,C:\WINNT\help\iisHelp\common\401-1.htm" "401,2,FILE,C:\WINNT\help\iisHelp\common\401-2.htm" "401,3,FILE,C:\WINNT\help\iisHelp\common\401-3.htm" "401,4,FILE,C:\WINNT\help\iisHelp\common\401-4.htm" "401,5,FILE,C:\WINNT\help\iisHelp\common\401-5.htm" "403,1,FILE,C:\WINNT\help\iisHelp\common\403-1.htm" "403,2,FILE,C:\WINNT\help\iisHelp\common\403-2.htm" "403,3,FILE,C:\WINNT\help\iisHelp\common\403-3.htm" "403,4,FILE,C:\WINNT\help\iisHelp\common\403-4.htm" "403,5,FILE,C:\WINNT\help\iisHelp\common\403-5.htm" "403,6,FILE,C:\WINNT\help\iisHelp\common\403-6.htm" "403,7,FILE,C:\WINNT\help\iisHelp\common\403-7.htm" "403,8,FILE,C:\WINNT\help\iisHelp\common\403-8.htm" "403,9,FILE,C:\WINNT\help\iisHelp\common\403-9.htm" "403,10,FILE,C:\WINNT\help\iisHelp\common\403-10.htm" "403,11,FILE,C:\WINNT\help\iisHelp\common\403-11.htm" "403,12,FILE,C:\WINNT\help\iisHelp\common\403-12.htm" "405,*,FILE,C:\WINNT\help\iisHelp\common\405.htm" "406,*,FILE,C:\WINNT\help\iisHelp\common\406.htm" "407,*,FILE,C:\WINNT\help\iisHelp\common\407.htm" "412,*,FILE,C:\WINNT\help\iisHelp\common\412.htm" "414,*,FILE,C:\WINNT\help\iisHelp\common\414.htm" "500,12,FILE,C:\WINNT\help\iisHelp\common\500-12.htm" "500,13,FILE,C:\WINNT\help\iisHelp\common\500-13.htm" "500,15,FILE,C:\WINNT\help\iisHelp\common\500-15.htm" "500,100,URL,/help/common/500-100.asp" "404,*,FILE,C:\WINNT\help\iishelp\common\404.htm"
  2070. [/W3SVC/1/ROOT/SCRIPTS]
  2071. AccessPerm : [IF] (DWORD) 0x204={Execute Script}
  2072. VrPath : [IF] (STRING) "c:\inetpub\scripts"
  2073. KeyType : [S] (STRING) "IIsWebVirtualDir"
  2074. */
  2075. void CreateMDVRootTree(CString csKeyPath, CString csName, CString csValue, LPCTSTR pszIP, UINT nProgressBarTextWebInstance)
  2076. {
  2077. iisDebugOut((LOG_TYPE_TRACE, _T("CreateMDVRootTree():Start.%s.%s.%s.%s.\n"),csKeyPath,csName,csValue,pszIP));
  2078. int iOverwriteAlways = TRUE;
  2079. int iThisIsAnIISDefaultApp = FALSE;
  2080. int iCreateAnApplicationForThis = FALSE;
  2081. CMDKey cmdKey;
  2082. CString csKeyPath_Copy;
  2083. TCHAR szPath[_MAX_PATH], szUserName[_MAX_PATH];
  2084. DWORD dwPerm, dwRegularPerm, dwSSLPerm;
  2085. csKeyPath += _T("/Root");
  2086. if (csName.Compare(_T("/")) != 0)
  2087. {
  2088. csKeyPath += csName; // LM/W3SVC/N/Root/iisadmin
  2089. }
  2090. csKeyPath.MakeUpper();
  2091. // let the user know what is going on which this vroot!
  2092. UINT SvcId;
  2093. SvcId = IDS_ADD_SETTINGS_FOR_WEB_2;
  2094. if ( csKeyPath.Find(_T("MSFTPSVC")) != -1 ) {SvcId = IDS_ADD_SETTINGS_FOR_FTP_2;}
  2095. //
  2096. // see if we can create the node. if we can't then return!
  2097. //
  2098. csKeyPath_Copy = csKeyPath;
  2099. // Make it look good.
  2100. if (csKeyPath.Right(8) == _T("IISADMIN"))
  2101. {
  2102. csKeyPath_Copy = csKeyPath.Left(csKeyPath.GetLength() - 8);
  2103. csKeyPath_Copy += _T("IISAdmin");
  2104. }
  2105. if (csKeyPath.Right(6) == _T("WEBPUB"))
  2106. {
  2107. csKeyPath_Copy = csKeyPath.Left(csKeyPath.GetLength() - 6);
  2108. csKeyPath_Copy += _T("Webpub");
  2109. }
  2110. if (csKeyPath.Right(10) == _T("IISSAMPLES"))
  2111. {
  2112. csKeyPath_Copy = csKeyPath.Left(csKeyPath.GetLength() - 10);
  2113. csKeyPath_Copy += _T("IISSamples");
  2114. }
  2115. if (csKeyPath.Right(7) == _T("IISHELP"))
  2116. {
  2117. csKeyPath_Copy = csKeyPath.Left(csKeyPath.GetLength() - 7);
  2118. csKeyPath_Copy += _T("IISHelp");
  2119. }
  2120. if (csKeyPath.Right(7) == _T("SCRIPTS"))
  2121. {
  2122. csKeyPath_Copy = csKeyPath.Left(csKeyPath.GetLength() - 7);
  2123. csKeyPath_Copy += _T("Scripts");
  2124. }
  2125. cmdKey.CreateNode(METADATA_MASTER_ROOT_HANDLE, csKeyPath_Copy);
  2126. if ( !(METADATA_HANDLE)cmdKey )
  2127. {
  2128. iisDebugOut((LOG_TYPE_TRACE, _T("CreateMDVRootTree():CreateNode %s.FAILED.\n"),csKeyPath_Copy));
  2129. return;
  2130. }
  2131. cmdKey.Close();
  2132. //
  2133. // Get the virtual root data
  2134. //
  2135. memset( (PVOID)szPath, 0, sizeof(szPath));
  2136. memset( (PVOID)szUserName, 0, sizeof(szUserName));
  2137. SplitVRString(csValue, szPath, szUserName, &dwPerm);
  2138. //
  2139. // Set KeyType
  2140. //
  2141. if ( csKeyPath.Find(_T("W3SVC")) != -1 )
  2142. WriteToMD_IIsWebVirtualDir(csKeyPath);
  2143. else
  2144. WriteToMD_IIsFtpVirtualDir(csKeyPath);
  2145. //
  2146. // Will return szPath and dwPerm.
  2147. // Get the permissions
  2148. //
  2149. SetVRootPermissions_w3svc(csKeyPath, szPath, &dwPerm);
  2150. //
  2151. // Set The path of the virtual root.
  2152. //
  2153. // if this is the Default VRoot then, don't overwrite it if already there!!!
  2154. //
  2155. iOverwriteAlways = TRUE;
  2156. if (csName.Compare(_T("/")) == 0) {iOverwriteAlways = FALSE;}
  2157. WriteToMD_VRootPath(csKeyPath, szPath, iOverwriteAlways);
  2158. //
  2159. // Set regular permissions
  2160. //
  2161. dwRegularPerm = dwPerm & MD_NONSSL_ACCESS_MASK;
  2162. dwSSLPerm = dwPerm & MD_SSL_ACCESS_MASK;
  2163. // do not overwrite if the value is already there!
  2164. WriteToMD_AccessPerm(csKeyPath, dwRegularPerm, FALSE);
  2165. //
  2166. // Set ssl permissions
  2167. //
  2168. // Do, not overwrite if the value is already there!
  2169. //
  2170. if (dwSSLPerm && (csKeyPath.Find(_T("W3SVC")) != -1))
  2171. {
  2172. WriteToMD_SSLPerm(csKeyPath, dwSSLPerm, FALSE);
  2173. }
  2174. //
  2175. // iif iisadmin then set Authorization
  2176. //
  2177. if (csKeyPath.Right(8) == _T("IISADMIN"))
  2178. {
  2179. if (g_pTheApp->m_eOS == OS_NT && g_pTheApp->m_eNTOSType != OT_NTW)
  2180. {
  2181. WriteToMD_Authorization(csKeyPath, MD_AUTH_NT);
  2182. }
  2183. // bug#340576
  2184. // removed per bug#340576
  2185. // should look like this: LM/W3SVC/N/Root/iisadmin
  2186. //WriteToMD_AspCodepage(csKeyPath, 65001, FALSE);
  2187. // bug#356345
  2188. WriteToMD_EnableParentPaths_WWW(csKeyPath, TRUE);
  2189. }
  2190. //
  2191. // if /IISHELP then make sure this is off bug356345
  2192. //
  2193. if (csKeyPath.Right(7) == _T("IISHELP"))
  2194. {
  2195. WriteToMD_EnableParentPaths_WWW(csKeyPath, FALSE);
  2196. }
  2197. //
  2198. // if /IISSAMPLES then set dirbrowsing on.
  2199. //
  2200. if (csKeyPath.Right(10) == _T("IISSAMPLES"))
  2201. {
  2202. WriteToMD_DirBrowsing_WWW(csKeyPath);
  2203. }
  2204. // If username is something,
  2205. // then let's get the password and save it to the metabase
  2206. if (szUserName[0] != _T('\0'))
  2207. {
  2208. // do have username and path is UNC
  2209. WriteToMD_VRUserName(csKeyPath, szUserName);
  2210. #ifndef _CHICAGO_
  2211. CString csRoot;
  2212. TCHAR szRootPassword[_MAX_PATH] = _T("");
  2213. BOOL b;
  2214. // if this is for the w3svc server...
  2215. if (csKeyPath.Find(_T("W3SVC")) != -1)
  2216. {
  2217. if (!pszIP || !(*pszIP) || !(_tcsicmp(pszIP, _T("null"))))
  2218. {
  2219. // first, try <vroot>
  2220. csRoot = csName;
  2221. b = GetRootSecret(csRoot, _T("W3_ROOT_DATA"), szRootPassword);
  2222. if (!b || !(*szRootPassword))
  2223. {
  2224. // second, try <vroot>,
  2225. csRoot = csName + _T(",");
  2226. b = GetRootSecret(csRoot, _T("W3_ROOT_DATA"), szRootPassword);
  2227. if (!b)
  2228. *szRootPassword = _T('\0');
  2229. }
  2230. }
  2231. else
  2232. {
  2233. csRoot = csName + _T(",");
  2234. csRoot += pszIP;
  2235. b = GetRootSecret(csRoot, _T("W3_ROOT_DATA"), szRootPassword);
  2236. if (!b)
  2237. *szRootPassword = _T('\0');
  2238. }
  2239. }
  2240. // if this is for the ftp server...
  2241. if (csKeyPath.Find(_T("MSFTPSVC")) != -1)
  2242. {
  2243. if (!pszIP || !(*pszIP) || !(_tcsicmp(pszIP, _T("null"))))
  2244. {
  2245. // first, try <vroot>
  2246. csRoot = csName;
  2247. b = GetRootSecret(csRoot, _T("FTPD_ROOT_DATA"), szRootPassword);
  2248. if (!b || !(*szRootPassword))
  2249. {
  2250. // second, try <vroot>,
  2251. csRoot = csName + _T(",");
  2252. b = GetRootSecret(csRoot, _T("FTPD_ROOT_DATA"), szRootPassword);
  2253. if (!b)
  2254. *szRootPassword = _T('\0');
  2255. }
  2256. }
  2257. else
  2258. {
  2259. csRoot = csName + _T(",");
  2260. csRoot += pszIP;
  2261. b = GetRootSecret(csRoot, _T("FTPD_ROOT_DATA"), szRootPassword);
  2262. if (!b)
  2263. *szRootPassword = _T('\0');
  2264. }
  2265. }
  2266. // if we have a password, then write it out
  2267. if (*szRootPassword)
  2268. {
  2269. WriteToMD_VRPassword(csKeyPath, szRootPassword);
  2270. }
  2271. #endif
  2272. }
  2273. //
  2274. // If this is the W3svc service then
  2275. // Create an Inprocess application for Certain Virtual Roots.
  2276. //
  2277. if (csKeyPath.Find(_T("W3SVC")) != -1)
  2278. {
  2279. CString csVirtualRootName;
  2280. csVirtualRootName = csKeyPath;
  2281. iCreateAnApplicationForThis = FALSE;
  2282. iThisIsAnIISDefaultApp = FALSE;
  2283. // maintain backward compatibility
  2284. // Any vroot with execute permissions is an application
  2285. if ((g_pTheApp->m_eInstallMode == IM_UPGRADE) && (dwPerm & MD_ACCESS_EXECUTE))
  2286. {
  2287. // Set this to true so that this previous iis application will
  2288. // be created as an com+ applicaton
  2289. iCreateAnApplicationForThis = TRUE;
  2290. // but if this is the msadc vroot then don't set as an application
  2291. // removed per bug 340993 make RDS vroot run oop
  2292. //if (csKeyPath.Right(5) == _T("MSADC")) {iCreateAnApplicationForThis = FALSE;}
  2293. }
  2294. // on a fresh install MSADC needs to be it's owned pooled application
  2295. // on an upgrade just leave it alone.
  2296. if (csKeyPath.Right(5) == _T("MSADC")) {csVirtualRootName = csKeyPath.Right(5); iCreateAnApplicationForThis = TRUE; iThisIsAnIISDefaultApp = TRUE;}
  2297. // if these are our paths then createinproc them
  2298. if (csKeyPath.Right(4) == _T("ROOT")) {csVirtualRootName = csKeyPath.Right(4); iCreateAnApplicationForThis = TRUE; iThisIsAnIISDefaultApp = TRUE;}
  2299. if (csKeyPath.Right(8) == _T("IISADMIN")) {csVirtualRootName = csKeyPath.Right(8);iCreateAnApplicationForThis = TRUE; iThisIsAnIISDefaultApp = TRUE;}
  2300. if (csKeyPath.Right(6) == _T("WEBPUB")) {csVirtualRootName = csKeyPath.Right(6);iCreateAnApplicationForThis = TRUE; iThisIsAnIISDefaultApp = TRUE;}
  2301. if (csKeyPath.Right(10) == _T("IISSAMPLES")) {csVirtualRootName = csKeyPath.Right(10);iCreateAnApplicationForThis = TRUE; iThisIsAnIISDefaultApp = TRUE;}
  2302. if (csKeyPath.Right(7) == _T("IISHELP")) {csVirtualRootName = csKeyPath.Right(7);iCreateAnApplicationForThis = TRUE; iThisIsAnIISDefaultApp = TRUE;}
  2303. if (TRUE == iCreateAnApplicationForThis)
  2304. {
  2305. // If this is an upgrade from a previous iis which has a metabase, then
  2306. // Upgrades should leave in-process apps, in-process.
  2307. // Including default sites because they might be running ISAPIs.
  2308. if (g_pTheApp->m_bUpgradeTypeHasMetabaseFlag)
  2309. {
  2310. // Since this upgrade already has a metabase,
  2311. // Leave the default applications and other user
  2312. // applications the way they already are
  2313. // check to see if the appID property exists...
  2314. // if it doesn't then set the property
  2315. if (FALSE == DoesAppIsolatedExist(csKeyPath))
  2316. {
  2317. // there is no app isolated on this node.
  2318. iisDebugOut((LOG_TYPE_WARN, _T("No AppIsolated specified for (%s)\n"),csKeyPath));
  2319. }
  2320. else
  2321. {
  2322. iisDebugOut((LOG_TYPE_TRACE, _T("AppIsolated exists for (%s)\n"),csKeyPath));
  2323. }
  2324. }
  2325. else
  2326. {
  2327. if (iThisIsAnIISDefaultApp)
  2328. {
  2329. // create an inprocess application which uses the OOP Pool
  2330. // Use The pool since these are "our" vdirs
  2331. CreateInProc_Wrap(csKeyPath, TRUE);
  2332. }
  2333. else
  2334. {
  2335. // create an in process application
  2336. // upgraded iis 2.0/3.0 asp vdirs should
  2337. // be using this since they were all in-proc in iis 2.0/3.0
  2338. CreateInProc_Wrap(csKeyPath, FALSE);
  2339. }
  2340. }
  2341. }
  2342. /* Bug114531: no need to add scriptmap under /iisHelp
  2343. if (csKeyPath.Right(7) == _T("IISHELP")) {
  2344. // add script map
  2345. ScriptMapNode ScriptMapList = {0};
  2346. // make it a sentinel
  2347. ScriptMapList.next = &ScriptMapList;
  2348. ScriptMapList.prev = &ScriptMapList;
  2349. GetScriptMapListFromMetabase(&ScriptMapList);
  2350. WriteScriptMapListToMetabase(&ScriptMapList, (LPTSTR)(LPCTSTR)csKeyPath, MD_SCRIPTMAPFLAG_SCRIPT | MD_SCRIPTMAPFLAG_CHECK_PATH_INFO);
  2351. FreeScriptMapList(&ScriptMapList);
  2352. }
  2353. */
  2354. }
  2355. iisDebugOut((LOG_TYPE_TRACE, _T("CreateMDVRootTree():End.%s.%s.%s.%s.\n"),csKeyPath,csName,csValue,pszIP));
  2356. }
  2357. void SplitVRString(CString csValue, LPTSTR szPath, LPTSTR szUserName, DWORD *pdwPerm)
  2358. {
  2359. // csValue should be in format of "<path>,<username>,<perm>"
  2360. // with one exception: IISv1.0 has format of "<Path>"
  2361. CString csPath, csUserName, csPerm;
  2362. int len, i;
  2363. csValue.TrimLeft();
  2364. csValue.TrimRight();
  2365. csPath = _T("");
  2366. csUserName = _T("");
  2367. csPerm = _T("");
  2368. *pdwPerm = 0;
  2369. i = csValue.ReverseFind(_T(','));
  2370. if (i != -1)
  2371. {
  2372. len = csValue.GetLength();
  2373. csPerm = csValue.Right(len - i - 1);
  2374. csValue = csValue.Left(i);
  2375. *pdwPerm = atodw((LPCTSTR)csPerm);
  2376. i = csValue.ReverseFind(_T(','));
  2377. if (i != -1)
  2378. {
  2379. len = csValue.GetLength();
  2380. csUserName = csValue.Right(len - i - 1);
  2381. csPath = csValue.Left(i);
  2382. }
  2383. }
  2384. else
  2385. {
  2386. // assume it is the format of "<Path>"
  2387. csPath = csValue;
  2388. }
  2389. _tcscpy(szPath, (LPCTSTR)csPath);
  2390. _tcscpy(szUserName, (LPCTSTR)csUserName);
  2391. return;
  2392. }
  2393. // loop thru the metabase
  2394. // and look for the next instance number which is not used!
  2395. // return that. "i" is at least = 1.
  2396. UINT GetInstNumber(LPCTSTR szMDPath, UINT i)
  2397. {
  2398. TCHAR Buf[10];
  2399. CString csInstRoot, csMDPath;
  2400. CMDKey cmdKey;
  2401. csInstRoot = szMDPath;
  2402. csInstRoot += _T("/");
  2403. _itot(i, Buf, 10);
  2404. csMDPath = csInstRoot + Buf;
  2405. cmdKey.OpenNode(csMDPath);
  2406. while ( (METADATA_HANDLE)cmdKey )
  2407. {
  2408. cmdKey.Close();
  2409. _itot(++i, Buf, 10);
  2410. csMDPath = csInstRoot + Buf;
  2411. cmdKey.OpenNode(csMDPath);
  2412. }
  2413. return (i);
  2414. }
  2415. BOOL ChkMdEntry_Exist(MDEntry *pMDEntry)
  2416. {
  2417. BOOL bReturn = FALSE;
  2418. CMDKey cmdKey;
  2419. PVOID pData = NULL;
  2420. MDEntry MDEntryTemp;
  2421. MDEntryTemp.szMDPath = pMDEntry->szMDPath;
  2422. //_tcscpy(MDEntryTemp.szMDPath,pMDEntry->szMDPath);
  2423. MDEntryTemp.dwMDIdentifier = pMDEntry->dwMDIdentifier;
  2424. MDEntryTemp.dwMDAttributes = pMDEntry->dwMDAttributes;
  2425. MDEntryTemp.dwMDUserType = pMDEntry->dwMDUserType;
  2426. MDEntryTemp.dwMDDataType = pMDEntry->dwMDDataType;
  2427. MDEntryTemp.dwMDDataLen = pMDEntry->dwMDDataLen;
  2428. MDEntryTemp.pbMDData = NULL;
  2429. // if the attributes = METADATA_INHERIT
  2430. // then let's just make sure that we check using the METADATA_NO_ATTRIBUTES deal.
  2431. if (MDEntryTemp.dwMDAttributes == METADATA_INHERIT)
  2432. {
  2433. MDEntryTemp.dwMDAttributes = METADATA_NO_ATTRIBUTES;
  2434. }
  2435. // Check if this is for the binary type
  2436. if (MDEntryTemp.dwMDDataType == BINARY_METADATA)
  2437. {
  2438. BOOL bFound = FALSE;
  2439. DWORD attr, uType, dType, cbLen;
  2440. CMDKey cmdKey;
  2441. BUFFER bufData;
  2442. PBYTE pData;
  2443. int BufSize;
  2444. cmdKey.OpenNode((LPCTSTR) MDEntryTemp.szMDPath);
  2445. if ( (METADATA_HANDLE) cmdKey )
  2446. {
  2447. pData = (PBYTE)(bufData.QueryPtr());
  2448. BufSize = bufData.QuerySize();
  2449. cbLen = 0;
  2450. bFound = cmdKey.GetData(MDEntryTemp.dwMDIdentifier, &attr, &uType, &dType, &cbLen, pData, BufSize);
  2451. if (bFound)
  2452. {
  2453. bReturn = TRUE;
  2454. }
  2455. else
  2456. {
  2457. if (cbLen > 0)
  2458. {
  2459. if ( ! (bufData.Resize(cbLen)) )
  2460. {
  2461. iisDebugOut((LOG_TYPE_ERROR, _T("ChkMdEntry_Exist(): cmdKey.GetData. failed to resize to %d.!\n"), cbLen));
  2462. }
  2463. else
  2464. {
  2465. pData = (PBYTE)(bufData.QueryPtr());
  2466. BufSize = cbLen;
  2467. cbLen = 0;
  2468. //bFound = cmdKey.GetData(MD_ADMIN_ACL, &attr, &uType, &dType, &cbLen, pData, BufSize);
  2469. bFound = cmdKey.GetData(MDEntryTemp.dwMDIdentifier, &attr, &uType, &dType, &cbLen, pData, BufSize);
  2470. if (bFound)
  2471. {
  2472. bReturn = TRUE;
  2473. }
  2474. else
  2475. {
  2476. // No the acl Does not exist!
  2477. }
  2478. }
  2479. }
  2480. else
  2481. {
  2482. // No the acl Does not exist!
  2483. }
  2484. }
  2485. cmdKey.Close();
  2486. }
  2487. }
  2488. else
  2489. {
  2490. // Check the metabase and see if the big Key /LM/W3SVC is there
  2491. cmdKey.OpenNode((LPCTSTR) MDEntryTemp.szMDPath);
  2492. if ( (METADATA_HANDLE)cmdKey )
  2493. {
  2494. // Check to see if our little Identifier is there.
  2495. //DWORD dwAttr = METADATA_INHERIT;
  2496. //DWORD dwUType = IIS_MD_UT_SERVER;
  2497. //DWORD dwDType = MULTISZ_METADATA;
  2498. //DWORD dwLength = 0;
  2499. DWORD dwAttr = MDEntryTemp.dwMDAttributes;
  2500. DWORD dwUType = MDEntryTemp.dwMDUserType;
  2501. DWORD dwDType = MDEntryTemp.dwMDDataType;
  2502. DWORD dwLength = 0;
  2503. // we need to start this process by getting the existing multisz data from the metabase
  2504. // first, figure out how much memory we will need to do this
  2505. cmdKey.GetData( MDEntryTemp.dwMDIdentifier,&dwAttr,&dwUType,&dwDType,&dwLength,NULL,0,MDEntryTemp.dwMDAttributes,MDEntryTemp.dwMDUserType,MDEntryTemp.dwMDDataType);
  2506. // unfortunatly, the above routine only returns TRUE or FALSE. And since we are purposefully
  2507. // passing in a null ponter of 0 size in order to get the length of the data, it will always
  2508. // return 0 whether it was because the metabase is inacessable, or there pointer was NULL,
  2509. // which it is. So - I guess we assume it worked, allocate the buffer and attempt to read it
  2510. // in again.
  2511. TCHAR* pOurBuffer;
  2512. DWORD cbBuffer = dwLength;
  2513. // This GetData call is supposed to return back the size of the string we're supposed to alloc.
  2514. // if the string is "Test", then since it's unicode the return would be ((4+1)*2) = 10.
  2515. // if the string is " ", then it would be (1+1)*2=4
  2516. // it should never be something as small as 2.
  2517. /*
  2518. if (cbBuffer <= 2)
  2519. {
  2520. if (dwDType == STRING_METADATA || dwDType == EXPANDSZ_METADATA)
  2521. {
  2522. iisDebugOut((LOG_TYPE_ERROR, _T("ChkMdEntry_Exist[%s:%d].requested size of this property reported back=%2. which is too small for a string.\n"), MDEntryTemp.szMDPath, MDEntryTemp.dwMDIdentifier, cbBuffer));
  2523. }
  2524. }
  2525. */
  2526. // allocate the space, if it fails, we fail
  2527. // note that GPTR causes it to be initialized to zero
  2528. pData = GlobalAlloc( GPTR, cbBuffer );
  2529. if ( !pData )
  2530. {
  2531. iisDebugOut((LOG_TYPE_ERROR, _T("ChkMdEntry_Exist(%d). Failed to allocate memory.\n"), MDEntryTemp.dwMDIdentifier));
  2532. // We Failed to allocate memory
  2533. cmdKey.Close();
  2534. goto ChkMdEntry_Exist_Exit;
  2535. }
  2536. pOurBuffer = (TCHAR*)pData;
  2537. // now get the data from the metabase
  2538. int iTemp = FALSE;
  2539. iTemp = cmdKey.GetData( MDEntryTemp.dwMDIdentifier,&dwAttr,&dwUType,&dwDType,&dwLength,(PUCHAR)pData,cbBuffer,MDEntryTemp.dwMDAttributes,MDEntryTemp.dwMDUserType,MDEntryTemp.dwMDDataType);
  2540. if (iTemp)
  2541. {
  2542. // if we have successfully retrieved the data, then we don't need to overwrite it!
  2543. bReturn = TRUE;
  2544. }
  2545. cmdKey.Close();
  2546. }
  2547. }
  2548. ChkMdEntry_Exist_Exit:
  2549. if (pData){GlobalFree(pData);pData=NULL;}
  2550. TCHAR lpReturnString[50];
  2551. ReturnStringForMetabaseID(MDEntryTemp.dwMDIdentifier, lpReturnString);
  2552. if (bReturn)
  2553. {
  2554. iisDebugOut((LOG_TYPE_TRACE, _T("ChkMdEntry_Exist[%s:%d:%s]. Exists.\n"), MDEntryTemp.szMDPath, MDEntryTemp.dwMDIdentifier, lpReturnString));
  2555. }
  2556. else
  2557. {
  2558. iisDebugOut((LOG_TYPE_TRACE, _T("ChkMdEntry_Exist[%s:%d:%s]. Not Exists.\n"), MDEntryTemp.szMDPath, MDEntryTemp.dwMDIdentifier, lpReturnString));
  2559. }
  2560. return bReturn;
  2561. }
  2562. DWORD SetMDEntry_Wrap(MDEntry *pMDEntry)
  2563. {
  2564. DWORD dwReturn = ERROR_SUCCESS;
  2565. int iFoundFlag = FALSE;
  2566. CString csKeyPath = pMDEntry->szMDPath;
  2567. ACTION_TYPE atWWWorFTPorCORE;
  2568. if (csKeyPath.Find(_T("W3SVC")) == -1)
  2569. {
  2570. iFoundFlag = TRUE;
  2571. atWWWorFTPorCORE = GetSubcompAction(_T("iis_www"), FALSE);
  2572. }
  2573. if (iFoundFlag != TRUE)
  2574. {
  2575. if (csKeyPath.Find(_T("MSFTPSVC")) == -1)
  2576. {
  2577. iFoundFlag = TRUE;
  2578. atWWWorFTPorCORE = GetSubcompAction(_T("iis_ftp"), FALSE);
  2579. }
  2580. }
  2581. if (iFoundFlag != TRUE)
  2582. {
  2583. iFoundFlag = TRUE;
  2584. atWWWorFTPorCORE = GetSubcompAction(_T("iis_core"), FALSE);
  2585. }
  2586. if (g_pTheApp->m_bUpgradeTypeHasMetabaseFlag)
  2587. {
  2588. dwReturn = SetMDEntry_NoOverWrite(pMDEntry);
  2589. }
  2590. else
  2591. {
  2592. dwReturn = SetMDEntry(pMDEntry);
  2593. }
  2594. return dwReturn;
  2595. }
  2596. DWORD DeleteMDEntry(MDEntry *pMDEntry)
  2597. {
  2598. CMDKey cmdKey;
  2599. DWORD dwReturn = ERROR_SUCCESS;
  2600. // Check if it exists first...
  2601. if (ChkMdEntry_Exist(pMDEntry))
  2602. {
  2603. cmdKey.OpenNode((LPCTSTR) pMDEntry->szMDPath);
  2604. if ( (METADATA_HANDLE)cmdKey )
  2605. {
  2606. // Delete the data
  2607. dwReturn = cmdKey.DeleteData(pMDEntry->dwMDIdentifier, pMDEntry->dwMDDataType);
  2608. cmdKey.Close();
  2609. }
  2610. }
  2611. if (FAILED(dwReturn))
  2612. {
  2613. iisDebugOut((LOG_TYPE_ERROR, _T("DeleteMDEntry(%d).FAILED.\n"), pMDEntry->dwMDIdentifier));
  2614. }
  2615. return dwReturn;
  2616. }
  2617. DWORD SetMDEntry(MDEntry *pMDEntry)
  2618. {
  2619. CMDKey cmdKey;
  2620. DWORD dwReturn = ERROR_SUCCESS;
  2621. cmdKey.CreateNode(METADATA_MASTER_ROOT_HANDLE, (LPCTSTR)pMDEntry->szMDPath);
  2622. if ( (METADATA_HANDLE)cmdKey )
  2623. {
  2624. dwReturn = ERROR_SUCCESS;
  2625. dwReturn = cmdKey.SetData(pMDEntry->dwMDIdentifier,pMDEntry->dwMDAttributes,pMDEntry->dwMDUserType,pMDEntry->dwMDDataType,pMDEntry->dwMDDataLen,pMDEntry->pbMDData);
  2626. // output what we set to the log file...
  2627. if (FAILED(dwReturn))
  2628. {
  2629. SetErrorFlag(__FILE__, __LINE__);
  2630. iisDebugOut((LOG_TYPE_ERROR, _T("SetMDEntry:SetData(%d), FAILED. Code=0x%x.End.\n"), pMDEntry->dwMDIdentifier, dwReturn));
  2631. }
  2632. cmdKey.Close();
  2633. }
  2634. if (g_CheckIfMetabaseValueWasWritten == TRUE)
  2635. {
  2636. // Check if the entry now exists....
  2637. if (!ChkMdEntry_Exist(pMDEntry))
  2638. {
  2639. iisDebugOut((LOG_TYPE_ERROR, _T("SetMDEntry(%d). Entry which we were supposed to write, does not exist! FAILURE.\n"), pMDEntry->dwMDIdentifier));
  2640. }
  2641. }
  2642. return dwReturn;
  2643. }
  2644. // -------------------------------------------
  2645. // MDEntry look something like this:
  2646. //
  2647. // stMDEntry.szMDPath = _T("LM/W3SVC");
  2648. // stMDEntry.dwMDIdentifier = MD_NTAUTHENTICATION_PROVIDERS;
  2649. // stMDEntry.dwMDAttributes = METADATA_INHERIT;
  2650. // stMDEntry.dwMDUserType = IIS_MD_UT_FILE;
  2651. // stMDEntry.dwMDDataType = STRING_METADATA;
  2652. // stMDEntry.dwMDDataLen = (csData.GetLength() + 1) * sizeof(TCHAR);
  2653. // stMDEntry.pbMDData = (LPBYTE)(LPCTSTR)csData;
  2654. // -------------------------------------------
  2655. DWORD SetMDEntry_NoOverWrite(MDEntry *pMDEntry)
  2656. {
  2657. DWORD dwReturn = ERROR_SUCCESS;
  2658. if (ChkMdEntry_Exist(pMDEntry))
  2659. {
  2660. iisDebugOut((LOG_TYPE_TRACE, _T("SetMDEntry_NoOverWrite:SetData(%d). Do not overwrite entry.\n"), pMDEntry->dwMDIdentifier));
  2661. }
  2662. else
  2663. {
  2664. dwReturn = SetMDEntry(pMDEntry);
  2665. }
  2666. return dwReturn;
  2667. }
  2668. int MigrateInfSectionToMD(HINF hFile, LPCTSTR szSection)
  2669. {
  2670. iisDebugOut_Start1(_T("MigrateInfSectionToMD"),(LPTSTR) szSection, LOG_TYPE_TRACE);
  2671. int iReturn = FALSE;
  2672. MDEntry stMDEntry;
  2673. LPTSTR szLine = NULL;
  2674. DWORD dwLineLen = 0, dwRequiredSize;
  2675. INT iType = 0;
  2676. BOOL b = FALSE;
  2677. INFCONTEXT Context;
  2678. if ((g_pbData = (LPBYTE)malloc(1024)) == NULL)
  2679. {
  2680. iisDebugOut((LOG_TYPE_ERROR, _T("MigrateInfSectionToMD:%s.1.Failed to allocate memory.\n"), szSection));
  2681. // failed to malloc
  2682. goto MigrateInfSectionToMD_Exit;
  2683. }
  2684. b = SetupFindFirstLine_Wrapped(hFile, szSection, NULL, &Context);
  2685. if (!b)
  2686. {
  2687. iisDebugOut((LOG_TYPE_ERROR, _T("MigrateInfSectionToMD:%s.FailedSetupFindFirstLine call.\n"), szSection));
  2688. // failed the SetupFindFirstLine call
  2689. goto MigrateInfSectionToMD_Exit;
  2690. }
  2691. if ( ( szLine = (LPTSTR)calloc(1024, sizeof(TCHAR)) ) != NULL )
  2692. {
  2693. dwLineLen = 1024;
  2694. }
  2695. else
  2696. {
  2697. iisDebugOut((LOG_TYPE_ERROR, _T("MigrateInfSectionToMD:%s.2.Failed to allocate memory.\n"), szSection));
  2698. // failed something
  2699. goto MigrateInfSectionToMD_Exit;
  2700. }
  2701. while (b)
  2702. {
  2703. b = SetupGetLineText(&Context, NULL, NULL, NULL, NULL, 0, &dwRequiredSize);
  2704. if (dwRequiredSize > dwLineLen)
  2705. {
  2706. free(szLine);
  2707. szLine = NULL;
  2708. if ( ( szLine = (LPTSTR)calloc(dwRequiredSize, sizeof(TCHAR)) ) != NULL )
  2709. {
  2710. dwLineLen = dwRequiredSize;
  2711. }
  2712. else
  2713. {
  2714. // failed something
  2715. iisDebugOut((LOG_TYPE_ERROR, _T("MigrateInfSectionToMD:%s.3.Failed to allocate memory.\n"), szSection));
  2716. goto MigrateInfSectionToMD_Exit;
  2717. }
  2718. }
  2719. if (SetupGetLineText(&Context, NULL, NULL, NULL, szLine, dwRequiredSize, NULL) == FALSE)
  2720. {
  2721. iisDebugOut((LOG_TYPE_ERROR, _T("MigrateInfSectionToMD:%s.3.Failed SetupGetLineText call.\n"), szSection));
  2722. // failed SetupGetLineText call
  2723. goto MigrateInfSectionToMD_Exit;
  2724. }
  2725. if ( ( ( *szLine >= 'a' ) && ( *szLine <= 'z') ) ||
  2726. ( ( *szLine >= 'A' ) && ( *szLine <= 'Z') )
  2727. )
  2728. {
  2729. CParse ParseLine;
  2730. ParseLine.ParseLine(&(g_pTheApp->FuncDict),szLine);
  2731. }
  2732. else
  2733. {
  2734. iType = GetMDEntryFromInfLine(szLine, &stMDEntry);
  2735. if ( MDENTRY_FROMINFFILE_FAILED != iType )
  2736. {
  2737. if (MDENTRY_FROMINFFILE_DO_DEL == iType)
  2738. {
  2739. DeleteMDEntry(&stMDEntry);
  2740. }
  2741. else
  2742. if (MDENTRY_FROMINFFILE_DO_ADD == iType)
  2743. {
  2744. SetMDEntry_Wrap(&stMDEntry);
  2745. }
  2746. // We had success in setting the key
  2747. iReturn = TRUE;
  2748. }
  2749. else
  2750. {
  2751. iisDebugOut((LOG_TYPE_ERROR, _T("MigrateInfSectionToMD:%s.3.Failed GetMDEntryFromInfLine call.\n"), szSection));
  2752. }
  2753. }
  2754. b = SetupFindNextLine(&Context, &Context);
  2755. }
  2756. MigrateInfSectionToMD_Exit:
  2757. if (szLine) {free(szLine);szLine=NULL;}
  2758. if (g_pbData){free(g_pbData);g_pbData=NULL;}
  2759. iisDebugOut_End1(_T("MigrateInfSectionToMD"),(LPTSTR) szSection,LOG_TYPE_TRACE);
  2760. return iReturn;
  2761. }
  2762. /*
  2763. #define METADATA_INHERIT 0x00000001
  2764. IIS_MD_UT_SERVER 1
  2765. DWORD_METADATA 1
  2766. 1 0 HKLM System\CurrentControlSet\Services\W3SVC\Parameters MaxConnections
  2767. LM/W3SVC 1014 1 1 1 4 20
  2768. */
  2769. void DumpMimeMap(CMapStringToString *mimeMap)
  2770. {
  2771. POSITION pos = NULL;
  2772. CString csName;
  2773. CString csValue;
  2774. pos = mimeMap->GetStartPosition();
  2775. while (pos)
  2776. {
  2777. mimeMap->GetNextAssoc(pos, csName, csValue);
  2778. // output
  2779. iisDebugOut((LOG_TYPE_WARN, _T("DumpMimeMap:%s=%s\n"), csName, csValue));
  2780. }
  2781. }
  2782. void InstallMimeMap()
  2783. {
  2784. CMapStringToString mimeMap;
  2785. TSTR strTheSection;
  2786. if ( g_pTheApp->m_eUpgradeType == UT_351 || g_pTheApp->m_eUpgradeType == UT_10 || g_pTheApp->m_eUpgradeType == UT_20 || g_pTheApp->m_eUpgradeType == UT_30)
  2787. {
  2788. CreateMimeMapFromRegistry(&mimeMap);
  2789. }
  2790. else
  2791. {
  2792. if (g_pTheApp->m_bUpgradeTypeHasMetabaseFlag)
  2793. {
  2794. ReadMimeMapFromMetabase(&mimeMap);
  2795. }
  2796. }
  2797. if ( strTheSection.Copy( _T("MIMEMAP") ) &&
  2798. GetSectionNameToDo(g_pTheApp->m_hInfHandle, &strTheSection )
  2799. )
  2800. {
  2801. ReadMimeMapFromInfSection(&mimeMap, g_pTheApp->m_hInfHandle, strTheSection.QueryStr() , TRUE);
  2802. }
  2803. // DumpMimeMap(&mimeMap);
  2804. if (mimeMap.IsEmpty() == FALSE)
  2805. {
  2806. // install it into the metabase
  2807. // first construct the MULTISZ string
  2808. BUFFER bufData;
  2809. DWORD cbBufLen;
  2810. BYTE *pData;
  2811. cbBufLen = bufData.QuerySize();
  2812. pData = (BYTE *) (bufData.QueryPtr());
  2813. ZeroMemory( pData, cbBufLen );
  2814. LPTSTR p = (LPTSTR)pData;
  2815. CString csName, csValue, csString;
  2816. DWORD cbRequiredLen, cbIncreasedLen;
  2817. DWORD cbDataLen = 0;
  2818. POSITION pos = NULL;
  2819. pos = mimeMap.GetStartPosition();
  2820. while (pos)
  2821. {
  2822. mimeMap.GetNextAssoc(pos, csName, csValue);
  2823. csString.Format(_T(".%s,%s"), csName, csValue);
  2824. cbIncreasedLen = csString.GetLength()*sizeof(TCHAR) + 1*sizeof(TCHAR);
  2825. cbRequiredLen = cbDataLen + cbIncreasedLen + 1 * sizeof(TCHAR);
  2826. if (cbRequiredLen > cbBufLen)
  2827. {
  2828. if (bufData.Resize(cbRequiredLen))
  2829. {
  2830. cbBufLen = bufData.QuerySize();
  2831. // move the pointer to the end
  2832. pData = (BYTE *)(bufData.QueryPtr());
  2833. p = (LPTSTR)(pData + cbDataLen);
  2834. // p = _tcsninc(p, cbDataLen / sizeof(TCHAR));
  2835. }
  2836. else
  2837. {
  2838. // insufficient buffer
  2839. return;
  2840. }
  2841. }
  2842. _tcscpy(p, csString);
  2843. p += csString.GetLength() + 1;
  2844. cbDataLen += cbIncreasedLen;
  2845. }
  2846. *p = _T('\0');
  2847. p = _tcsinc(p);
  2848. cbDataLen += sizeof(TCHAR);
  2849. CMDKey cmdKey;
  2850. cmdKey.CreateNode(METADATA_MASTER_ROOT_HANDLE, _T("LM/MimeMap"));
  2851. if ( (METADATA_HANDLE)cmdKey )
  2852. {
  2853. cmdKey.SetData(MD_MIME_MAP,METADATA_INHERIT,IIS_MD_UT_FILE,MULTISZ_METADATA,cbDataLen,(LPBYTE)pData );
  2854. CString csKeyType = _T("IIsMimeMap");
  2855. cmdKey.SetData(MD_KEY_TYPE,METADATA_NO_ATTRIBUTES,IIS_MD_UT_SERVER,STRING_METADATA,(csKeyType.GetLength() + 1) * sizeof(TCHAR),(LPBYTE)(LPCTSTR)csKeyType );
  2856. cmdKey.Close();
  2857. }
  2858. }
  2859. CRegKey regInetinfoParam(HKEY_LOCAL_MACHINE, REG_INETINFOPARAMETERS);
  2860. if ( (HKEY)regInetinfoParam )
  2861. {
  2862. regInetinfoParam.DeleteTree(_T("MimeMap"));
  2863. }
  2864. return;
  2865. }
  2866. void ReadMimeMapFromMetabase(CMapStringToString *pMap)
  2867. {
  2868. BOOL bFound = FALSE;
  2869. DWORD attr, uType, dType, cbLen;
  2870. CMDKey cmdKey;
  2871. BUFFER bufData;
  2872. LPTSTR p, rest, token;
  2873. CString csName, csValue;
  2874. PBYTE pData;
  2875. int BufSize;
  2876. cmdKey.OpenNode(_T("LM/MimeMap"));
  2877. if ( (METADATA_HANDLE)cmdKey )
  2878. {
  2879. pData = (PBYTE)(bufData.QueryPtr());
  2880. BufSize = bufData.QuerySize();
  2881. cbLen = 0;
  2882. bFound = cmdKey.GetData(MD_MIME_MAP, &attr, &uType, &dType, &cbLen, pData, BufSize);
  2883. if (!bFound && (cbLen > 0))
  2884. {
  2885. if ( ! (bufData.Resize(cbLen)) )
  2886. {
  2887. cmdKey.Close();
  2888. return; // insufficient memory
  2889. }
  2890. else
  2891. {
  2892. pData = (PBYTE)(bufData.QueryPtr());
  2893. BufSize = cbLen;
  2894. cbLen = 0;
  2895. bFound = cmdKey.GetData(MD_MIME_MAP, &attr, &uType, &dType, &cbLen, pData, BufSize);
  2896. }
  2897. }
  2898. cmdKey.Close();
  2899. if (bFound && (dType == MULTISZ_METADATA))
  2900. {
  2901. p = (LPTSTR)pData;
  2902. while (*p)
  2903. {
  2904. rest = _tcsninc(p, _tcslen(p))+1;
  2905. p = _tcsinc(p); // bypass the first dot
  2906. token = _tcstok(p, _T(","));
  2907. if (token)
  2908. {
  2909. csName = token;
  2910. token = _tcstok(NULL, _T(","));
  2911. csValue = token;
  2912. pMap->SetAt(csName, csValue);
  2913. }
  2914. p = rest; // points to the next string
  2915. }
  2916. }
  2917. }
  2918. return;
  2919. }
  2920. BOOL CreateMimeMapFromRegistry(CMapStringToString *pMap)
  2921. {
  2922. // make sure we start from an empty Map
  2923. pMap->RemoveAll();
  2924. CRegKey regMimeMap(HKEY_LOCAL_MACHINE, REG_MIMEMAP, KEY_READ);
  2925. if ( (HKEY)regMimeMap )
  2926. {
  2927. CRegValueIter regEnum( regMimeMap );
  2928. CString csName, csValue;
  2929. while ( regEnum.Next( &csName, &csValue ) == ERROR_SUCCESS )
  2930. {
  2931. TCHAR szLine[_MAX_PATH];
  2932. LPTSTR token;
  2933. _tcscpy(szLine, csName);
  2934. token = _tcstok(szLine, _T(","));
  2935. if (token)
  2936. {
  2937. csValue = token;
  2938. csValue.TrimLeft();
  2939. csValue.TrimRight();
  2940. // get rid of the leftside double-quotes
  2941. if (csValue.Left(1) == _T("\""))
  2942. {
  2943. csValue = csValue.Mid(1);
  2944. }
  2945. token = _tcstok(NULL, _T(","));
  2946. if (token)
  2947. csName = token;
  2948. else
  2949. csName = _T("");
  2950. // get rid of the surrounding double-quotes
  2951. csName.TrimLeft();
  2952. csName.TrimRight();
  2953. if (csName.IsEmpty() == FALSE)
  2954. {
  2955. pMap->SetAt(csName, csValue);
  2956. }
  2957. }
  2958. }
  2959. }
  2960. return (!(pMap->IsEmpty()));
  2961. }
  2962. BOOL CreateMimeMapFromInfSection(CMapStringToString *pMap, HINF hFile, LPCTSTR szSection)
  2963. {
  2964. // make sure we start from an empty Map
  2965. pMap->RemoveAll();
  2966. ReadMimeMapFromInfSection(pMap, hFile, szSection, TRUE);
  2967. return (!(pMap->IsEmpty()));
  2968. }
  2969. // mime map in inf file should look something like this:
  2970. //
  2971. // [MIMEMAP]
  2972. // "text/html,htm,,h"
  2973. // "image/gif,gif,,g"
  2974. // "image/jpeg,jpg,,:"
  2975. // "text/plain,txt,,0"
  2976. // "text/html,html,,h"
  2977. // "image/jpeg,jpeg,,:"
  2978. // "image/jpeg,jpe,,:"
  2979. // "image/bmp,bmp,,:"
  2980. // "application/octet-stream,*,,5"
  2981. // "application/pdf,pdf,,5"
  2982. // "application/octet-stream,bin,,5"
  2983. //
  2984. void ReadMimeMapFromInfSection(CMapStringToString *pMap, HINF hFile, LPCTSTR szSection, BOOL fAction)
  2985. {
  2986. LPTSTR szLine;
  2987. BOOL b = FALSE;
  2988. DWORD dwLineLen = 0, dwRequiredSize;
  2989. CString csTempString;
  2990. INFCONTEXT Context;
  2991. b = SetupFindFirstLine_Wrapped(hFile, szSection, NULL, &Context);
  2992. if ( ( szLine = (LPTSTR)calloc(1024, sizeof(TCHAR)) ) != NULL )
  2993. dwLineLen = 1024;
  2994. else
  2995. {
  2996. iisDebugOut((LOG_TYPE_ERROR, _T("ReadMimeMapFromInfSection.1.Failed to allocate memory.\n")));
  2997. return;
  2998. }
  2999. while (b)
  3000. {
  3001. b = SetupGetLineText(&Context, NULL, NULL, NULL, NULL, 0, &dwRequiredSize);
  3002. if (dwRequiredSize > dwLineLen)
  3003. {
  3004. free(szLine);
  3005. szLine = NULL;
  3006. if ( ( szLine = (LPTSTR)calloc(dwRequiredSize, sizeof(TCHAR)) ) != NULL )
  3007. dwLineLen = dwRequiredSize;
  3008. else
  3009. {
  3010. iisDebugOut((LOG_TYPE_ERROR, _T("ReadMimeMapFromInfSection.2.Failed to allocate memory.\n")));
  3011. return;
  3012. }
  3013. }
  3014. if (SetupGetLineText(&Context, NULL, NULL, NULL, szLine, dwRequiredSize, NULL))
  3015. {
  3016. CString csName, csValue;
  3017. LPTSTR token;
  3018. token = _tcstok(szLine, _T(","));
  3019. if (token)
  3020. {
  3021. // "text/html,htm,,h"
  3022. // csValue=text/html
  3023. // ===========
  3024. csValue = token;
  3025. csValue.TrimLeft();
  3026. csValue.TrimRight();
  3027. // get rid of the leftside double-quotes
  3028. if (csValue.Left(1) == _T("\""))
  3029. csValue = csValue.Mid(1);
  3030. /*
  3031. if (csName.Right(1) == _T("\""))
  3032. csName = csName.Left(csName.GetLength() - 1);
  3033. */
  3034. // "text/html,htm,,h"
  3035. // name=htm
  3036. // ===========
  3037. token = _tcstok(NULL, _T(","));
  3038. if (token)
  3039. csName = token;
  3040. else
  3041. csName = _T("");
  3042. // get rid of the surrounding double-quotes
  3043. csName.TrimLeft();
  3044. csName.TrimRight();
  3045. /*
  3046. if (csName.Left(1) == _T("\""))
  3047. csName = csName.Mid(1);
  3048. if (csName.Right(1) == _T("\""))
  3049. csName = csName.Left(csName.GetLength() - 1);
  3050. */
  3051. if (csName.IsEmpty() == FALSE)
  3052. {
  3053. if (fAction)
  3054. {
  3055. // Check if this extension already exists in the list.
  3056. // if it does then don't overwrite it.
  3057. if (0 == pMap->Lookup( csName, csTempString) )
  3058. {
  3059. // otherwise add new extensions
  3060. pMap->SetAt(csName, csValue);
  3061. }
  3062. }
  3063. else
  3064. {
  3065. // remove old extensions
  3066. pMap->RemoveKey(csName);
  3067. }
  3068. }
  3069. }
  3070. }
  3071. b = SetupFindNextLine(&Context, &Context);
  3072. }
  3073. if (szLine) {free(szLine);szLine=NULL;}
  3074. return;
  3075. }
  3076. void ReadMultiSZFromInfSection(CString *pcsMultiSZ, HINF hFile, LPCTSTR szSection)
  3077. {
  3078. LPTSTR szLine;
  3079. BOOL b = FALSE;
  3080. DWORD dwLineLen = 0, dwRequiredSize;
  3081. INFCONTEXT Context;
  3082. b = SetupFindFirstLine_Wrapped(hFile, szSection, NULL, &Context);
  3083. if ( ( szLine = (LPTSTR)calloc(1024, sizeof(TCHAR)) ) != NULL )
  3084. dwLineLen = 1024;
  3085. else
  3086. {
  3087. iisDebugOut((LOG_TYPE_ERROR, _T("ReadMultiSZFromInfSection.1.Failed to allocate memory.\n")));
  3088. return;
  3089. }
  3090. while (b)
  3091. {
  3092. b = SetupGetLineText(&Context, NULL, NULL, NULL, NULL, 0, &dwRequiredSize);
  3093. if (dwRequiredSize > dwLineLen)
  3094. {
  3095. free(szLine);
  3096. szLine=NULL;
  3097. if ( ( szLine = (LPTSTR)calloc(dwRequiredSize, sizeof(TCHAR)) ) != NULL )
  3098. dwLineLen = dwRequiredSize;
  3099. else
  3100. {
  3101. iisDebugOut((LOG_TYPE_ERROR, _T("ReadMultiSZFromInfSection.2.Failed to allocate memory.\n")));
  3102. return;
  3103. }
  3104. }
  3105. if (SetupGetLineText(&Context, NULL, NULL, NULL, szLine, dwRequiredSize, NULL))
  3106. {
  3107. _tcscat(szLine, _T("|"));
  3108. (*pcsMultiSZ) += szLine;
  3109. }
  3110. b = SetupFindNextLine(&Context, &Context);
  3111. }
  3112. if (szLine) {free(szLine);szLine=NULL;}
  3113. if (pcsMultiSZ->IsEmpty()) {(*pcsMultiSZ) = _T("|");}
  3114. return;
  3115. }
  3116. void SetLogPlugInOrder(LPCTSTR lpszSvc)
  3117. {
  3118. DWORD dwReturn = ERROR_SUCCESS;
  3119. DWORD dwReturnTemp = ERROR_SUCCESS;
  3120. DWORD dwLogType;
  3121. DWORD dwLogFileTruncateSize = 0x1400000;
  3122. CString csLogPlugInOrder;
  3123. DWORD dwLogFilePeriod;
  3124. DWORD extField = 0;
  3125. #ifndef _CHICAGO_
  3126. dwLogType = MD_LOG_TYPE_ENABLED;
  3127. csLogPlugInOrder = EXTLOG_CLSID;
  3128. dwLogFilePeriod = MD_LOGFILE_PERIOD_DAILY;
  3129. extField = DEFAULT_EXTLOG_FIELDS | EXTLOG_WIN32_STATUS;
  3130. #else // CHICAGO
  3131. //
  3132. // win95
  3133. //
  3134. dwLogType = MD_LOG_TYPE_DISABLED;
  3135. csLogPlugInOrder = NCSALOG_CLSID;
  3136. dwLogFilePeriod = MD_LOGFILE_PERIOD_MONTHLY;
  3137. #endif // _CHICAGO_
  3138. if (g_pTheApp->m_eUpgradeType == UT_351 || g_pTheApp->m_eUpgradeType == UT_10 || g_pTheApp->m_eUpgradeType == UT_20 || g_pTheApp->m_eUpgradeType == UT_30)
  3139. {
  3140. CString csParam = _T("System\\CurrentControlSet\\Services");
  3141. csParam += _T("\\");
  3142. csParam += lpszSvc;
  3143. csParam += _T("\\Parameters");
  3144. CRegKey regParam(csParam, HKEY_LOCAL_MACHINE);
  3145. if ((HKEY)regParam)
  3146. {
  3147. DWORD dwType, dwFormat;
  3148. regParam.QueryValue(_T("LogFilePeriod"), dwLogFilePeriod);
  3149. regParam.QueryValue(_T("LogFileTruncateSize"), dwLogFileTruncateSize);
  3150. if (regParam.QueryValue(_T("LogType"), dwType) == ERROR_SUCCESS)
  3151. {
  3152. switch (dwType)
  3153. {
  3154. case INET_LOG_TO_SQL:
  3155. csLogPlugInOrder = ODBCLOG_CLSID;
  3156. break;
  3157. case INET_LOG_TO_FILE:
  3158. if (regParam.QueryValue(_T("LogFileFormat"), dwFormat) == ERROR_SUCCESS)
  3159. {
  3160. switch (dwFormat)
  3161. {
  3162. case INET_LOG_FORMAT_NCSA:
  3163. csLogPlugInOrder = NCSALOG_CLSID;
  3164. break;
  3165. case INET_LOG_FORMAT_INTERNET_STD:
  3166. csLogPlugInOrder = ASCLOG_CLSID;
  3167. break;
  3168. default:
  3169. break;
  3170. }
  3171. }
  3172. break;
  3173. case INET_LOG_DISABLED:
  3174. dwLogType = MD_LOG_TYPE_DISABLED;
  3175. break;
  3176. default:
  3177. break;
  3178. }
  3179. }
  3180. //delete LogFilePeriod, LogFileFormat, LogType
  3181. regParam.DeleteValue(_T("LogFilePeriod"));
  3182. regParam.DeleteValue(_T("LogFileTruncateSize"));
  3183. regParam.DeleteValue(_T("LogFileFormat"));
  3184. regParam.DeleteValue(_T("LogType"));
  3185. }
  3186. }
  3187. if ((dwLogFilePeriod >= MD_LOGFILE_PERIOD_DAILY) && (dwLogFileTruncateSize > 0x1400000) ) {dwLogFileTruncateSize = 0x1400000;}
  3188. MDEntry stMDEntry;
  3189. //
  3190. // set LogType, LogPluginOrder, LogFilePeriod in the metabase
  3191. //
  3192. CString csKeyPath = _T("LM/");
  3193. csKeyPath += lpszSvc;
  3194. stMDEntry.szMDPath = (LPTSTR)(LPCTSTR)csKeyPath;
  3195. stMDEntry.dwMDIdentifier = MD_LOG_TYPE;
  3196. stMDEntry.dwMDAttributes = METADATA_INHERIT;
  3197. stMDEntry.dwMDUserType = IIS_MD_UT_SERVER;
  3198. stMDEntry.dwMDDataType = DWORD_METADATA;
  3199. stMDEntry.dwMDDataLen = sizeof(DWORD);
  3200. stMDEntry.pbMDData = (LPBYTE)&dwLogType;
  3201. dwReturnTemp = SetMDEntry(&stMDEntry);
  3202. if (dwReturnTemp != ERROR_SUCCESS){dwReturn = dwReturnTemp;}
  3203. stMDEntry.szMDPath = (LPTSTR)(LPCTSTR)csKeyPath;
  3204. stMDEntry.dwMDIdentifier = MD_LOG_PLUGIN_ORDER;
  3205. stMDEntry.dwMDAttributes = METADATA_INHERIT;
  3206. stMDEntry.dwMDUserType = IIS_MD_UT_SERVER;
  3207. stMDEntry.dwMDDataType = STRING_METADATA;
  3208. stMDEntry.dwMDDataLen = (csLogPlugInOrder.GetLength() + 1) * sizeof(TCHAR);
  3209. stMDEntry.pbMDData = (LPBYTE)(LPCTSTR)csLogPlugInOrder;
  3210. dwReturnTemp = SetMDEntry(&stMDEntry);
  3211. if (dwReturnTemp != ERROR_SUCCESS){dwReturn = dwReturnTemp;}
  3212. stMDEntry.szMDPath = (LPTSTR)(LPCTSTR)csKeyPath;
  3213. stMDEntry.dwMDIdentifier = MD_LOGFILE_PERIOD;
  3214. stMDEntry.dwMDAttributes = METADATA_INHERIT;
  3215. stMDEntry.dwMDUserType = IIS_MD_UT_SERVER;
  3216. stMDEntry.dwMDDataType = DWORD_METADATA;
  3217. stMDEntry.dwMDDataLen = sizeof(DWORD);
  3218. stMDEntry.pbMDData = (LPBYTE)&dwLogFilePeriod;
  3219. dwReturnTemp = SetMDEntry(&stMDEntry);
  3220. if (dwReturnTemp != ERROR_SUCCESS){dwReturn = dwReturnTemp;}
  3221. stMDEntry.szMDPath = (LPTSTR)(LPCTSTR)csKeyPath;
  3222. stMDEntry.dwMDIdentifier = MD_LOGFILE_TRUNCATE_SIZE;
  3223. stMDEntry.dwMDAttributes = METADATA_INHERIT;
  3224. stMDEntry.dwMDUserType = IIS_MD_UT_SERVER;
  3225. stMDEntry.dwMDDataType = DWORD_METADATA;
  3226. stMDEntry.dwMDDataLen = sizeof(DWORD);
  3227. stMDEntry.pbMDData = (LPBYTE)&dwLogFileTruncateSize;
  3228. dwReturnTemp = SetMDEntry(&stMDEntry);
  3229. if (dwReturnTemp != ERROR_SUCCESS){dwReturn = dwReturnTemp;}
  3230. if ( extField != 0 )
  3231. {
  3232. stMDEntry.szMDPath = (LPTSTR)(LPCTSTR)csKeyPath;
  3233. stMDEntry.dwMDIdentifier = MD_LOGEXT_FIELD_MASK;
  3234. stMDEntry.dwMDAttributes = METADATA_INHERIT;
  3235. stMDEntry.dwMDUserType = IIS_MD_UT_SERVER;
  3236. stMDEntry.dwMDDataType = DWORD_METADATA;
  3237. stMDEntry.dwMDDataLen = sizeof(DWORD);
  3238. stMDEntry.pbMDData = (LPBYTE)&extField;
  3239. dwReturnTemp = SetMDEntry_Wrap(&stMDEntry);
  3240. if (dwReturnTemp != ERROR_SUCCESS){dwReturn = dwReturnTemp;}
  3241. }
  3242. return;
  3243. }
  3244. //------------------------------------------------------------------------------------
  3245. // make sure that virtual server 1 can be accessed by local host. This involves reading in
  3246. // the existing bindings. Then, if it is all unassigned we are OK. If 127.0.0.1 is there
  3247. // we are OK. Otherwise, we need to add 127.0.0.1:80
  3248. BOOL ConfirmLocalHost(LPCTSTR lpszVirtServer)
  3249. {
  3250. CMDKey cmdKey;
  3251. PVOID pData = NULL;
  3252. TCHAR* pNext;
  3253. BOOL bReturn;
  3254. CString csBinding;
  3255. CString cs;
  3256. CString csLocalHost = _T("127.0.0.1:80:");
  3257. // open the key to the virtual server, which is what is passed in as a parameter
  3258. cmdKey.OpenNode( lpszVirtServer );
  3259. // test for success.
  3260. if ( (METADATA_HANDLE)cmdKey == NULL ){return FALSE;}
  3261. DWORD dwAttr = METADATA_INHERIT;
  3262. DWORD dwUType = IIS_MD_UT_SERVER;
  3263. DWORD dwDType = MULTISZ_METADATA;
  3264. DWORD dwLength = 0;
  3265. // we need to start this process by getting the existing multisz data from the metabase
  3266. // first, figure out how much memory we will need to do this
  3267. cmdKey.GetData( MD_SERVER_BINDINGS,&dwAttr,&dwUType,&dwDType,&dwLength,NULL,0,METADATA_INHERIT,IIS_MD_UT_SERVER,MULTISZ_METADATA);
  3268. // unfortunatly, the above routine only returns TRUE or FALSE. And since we are purposefully
  3269. // passing in a null ponter of 0 size in order to get the length of the data, it will always
  3270. // return 0 whether it was because the metabase is inacessable, or there pointer was NULL,
  3271. // which it is. So - I guess we assume it worked, allocate the buffer and attempt to read it
  3272. // in again.
  3273. TCHAR* pBindings;
  3274. DWORD cbBuffer = dwLength;
  3275. // add enough space to the allocated space that we can just append the string
  3276. cbBuffer += (csLocalHost.GetLength() + 4) * sizeof(WCHAR);
  3277. dwLength = cbBuffer;
  3278. // allocate the space, if it fails, we fail
  3279. // note that GPTR causes it to be initialized to zero
  3280. pData = GlobalAlloc( GPTR, cbBuffer );
  3281. if ( !pData )
  3282. {
  3283. iisDebugOut((LOG_TYPE_ERROR, _T("ConfirmLocalHost.Failed to allocate memory.\n")));
  3284. cmdKey.Close();
  3285. goto cleanup;
  3286. }
  3287. pBindings = (TCHAR*)pData;
  3288. // now get the data from the metabase
  3289. bReturn = cmdKey.GetData( MD_SERVER_BINDINGS,&dwAttr,&dwUType,&dwDType,&dwLength,(PUCHAR)pData,cbBuffer,METADATA_INHERIT,IIS_MD_UT_SERVER,MULTISZ_METADATA );
  3290. // if we have successfully retrieved the existing bindings, then we need to scan them
  3291. // to see if we are already covered
  3292. if (bReturn)
  3293. {
  3294. // got the existing bindings, scan them now - pBindings will be pointing at the second end \0
  3295. // when it is time to exit the loop.
  3296. while ( *pBindings )
  3297. {
  3298. csBinding = pBindings;
  3299. // if the first character of the binding is a ':' then we are all done because it is "All Unassigned"
  3300. if ( csBinding[0] == _T(':') )
  3301. goto cleanup;
  3302. // if the binding is for localhost, then we are done
  3303. if ( csBinding.Left(9) == _T("127.0.0.1") )
  3304. goto cleanup;
  3305. // increment pBindings to the next string
  3306. pBindings = _tcsninc( pBindings, _tcslen(pBindings))+1;
  3307. }
  3308. }
  3309. // append our new error to the end of the list. The value pErrors should be pointing
  3310. // to the correct location to copy it in to
  3311. _tcscpy( pBindings, csLocalHost );
  3312. // calculate the correct data length for this thing
  3313. // get the location of the end of the multisz
  3314. pNext = _tcsninc( pBindings, _tcslen(pBindings))+2;
  3315. // Get the length of the data to copy
  3316. cbBuffer = DIFF((PBYTE)pNext - (PBYTE)pData);
  3317. // write the new errors list back out to the metabase
  3318. cmdKey.SetData(MD_SERVER_BINDINGS,0,IIS_MD_UT_SERVER,MULTISZ_METADATA,cbBuffer,(PUCHAR)pData);
  3319. // close the key
  3320. cleanup:
  3321. cmdKey.Close();
  3322. // clean up
  3323. if (pData){GlobalFree(pData);pData=NULL;}
  3324. // the only time it should return FALSE is if it can't open the key
  3325. return TRUE;
  3326. }
  3327. //------------------------------------------------------------------------------------
  3328. // Beta 3 server set the MD_NOT_DELETABLE property on the default website and the administration website.
  3329. // remove it. It should only be set now on the default website for the NTW platform. This routine scans
  3330. // all the virtual websites and attempts to delete the MD_NOT_DELETABLE property. This should only be
  3331. // called on the NTS platform during an upgrade
  3332. // pszService string representing the service being operated on. ex: "W3SVC"
  3333. //
  3334. // Actually, now I'm only going to bother checking instances 1 and 2. These are the only ones that would
  3335. // have this value set on them anyway and we can save a lot of time by not checking them all. - boydm
  3336. void RemoveCannotDeleteVR( LPCTSTR )
  3337. {
  3338. }
  3339. //------------------------------------------------------------------------------------
  3340. // IntegrateNewErrorsOnUpgrade_WWW
  3341. // This routine finds the new custom errors and error messages that are being integrated
  3342. // into an upgrade and adds them to the existing errors. This code should not be called
  3343. // for a fresh install. The plan is to read each new error from the appropriate INF section
  3344. // then call a helper routine to add it only if it does not already exist. The use can always
  3345. // add these things by hand, and if they have done so, we don't want to override their good work.
  3346. // Note: the "g_field" variable is a global declared at the top of this file.
  3347. //
  3348. // hFile Handle to the INF file
  3349. // szSection name of section containing the error to integrate - usually "UPGRADE_ERRORS"
  3350. //
  3351. void IntegrateNewErrorsOnUpgrade_WWW( IN HINF hFile, IN LPCTSTR szSection )
  3352. {
  3353. iisDebugOut_Start(_T("IntegrateNewErrorsOnUpgrade_WWW"),LOG_TYPE_TRACE);
  3354. DWORD dwReturn = ERROR_SUCCESS;
  3355. LPTSTR szLine = NULL;
  3356. DWORD dwRequiredSize;
  3357. BOOL b = FALSE;
  3358. INFCONTEXT Context;
  3359. if( g_pTheApp->m_eInstallMode != IM_UPGRADE )
  3360. {
  3361. iisDebugOut((LOG_TYPE_WARN, _T("WARNING: IntegrateNewErrorsOnUpgrade_WWW called on FRESH install")));
  3362. dwReturn = ERROR_SUCCESS;
  3363. goto IntegrateNewErrorsOnUpgrade_WWW_Exit;
  3364. }
  3365. // go to the beginning of the section in the INF file
  3366. b = SetupFindFirstLine_Wrapped(hFile, szSection, NULL, &Context);
  3367. if (!b)
  3368. {
  3369. iisDebugOut((LOG_TYPE_ERROR, _T("FAILED: Unable to find INF section %s for upgrading errors"), szSection));
  3370. dwReturn = ERROR_PATH_NOT_FOUND;
  3371. goto IntegrateNewErrorsOnUpgrade_WWW_Exit;
  3372. }
  3373. // loop through the items in the section.
  3374. while (b)
  3375. {
  3376. // get the size of the memory we need for this
  3377. b = SetupGetLineText(&Context, NULL, NULL, NULL, NULL, 0, &dwRequiredSize);
  3378. // prepare the buffer to receive the line
  3379. szLine = (LPTSTR)GlobalAlloc( GPTR, dwRequiredSize * sizeof(TCHAR) );
  3380. if ( !szLine )
  3381. {
  3382. SetErrorFlag(__FILE__, __LINE__);
  3383. iisDebugOut((LOG_TYPE_ERROR, _T("FAILED: Unable to allocate buffer of %u bytes - upgrade errors"), dwRequiredSize));
  3384. dwReturn = ERROR_OUTOFMEMORY;
  3385. goto IntegrateNewErrorsOnUpgrade_WWW_Exit;
  3386. }
  3387. // get the line from the inf file1
  3388. if (SetupGetLineText(&Context, NULL, NULL, NULL, szLine, dwRequiredSize, NULL) == FALSE)
  3389. {
  3390. SetErrorFlag(__FILE__, __LINE__);
  3391. iisDebugOut((LOG_TYPE_ERROR, _T("FAILED: Unable to get the next INF line - upgrade errors")));
  3392. dwReturn = ERROR_PATH_NOT_FOUND;
  3393. goto IntegrateNewErrorsOnUpgrade_WWW_Exit;
  3394. }
  3395. // split the line into its component parts
  3396. if ( SplitLine(szLine, 5) )
  3397. {
  3398. // the first two g_fields are dwords. Must convert them before using them
  3399. DWORD dwError = _ttoi(g_field[0]);
  3400. DWORD dwSubCode = _ttoi(g_field[1]);
  3401. // the last g_field is a flag for overwriting existing errors
  3402. BOOL fOverwrite = _ttoi(g_field[4]);
  3403. // call the helper function that integrates the custom error
  3404. AddCustomError(dwError, dwSubCode, g_field[2], g_field[3], fOverwrite );
  3405. }
  3406. else
  3407. {
  3408. // failed to split the line
  3409. SetErrorFlag(__FILE__, __LINE__);
  3410. iisDebugOut((LOG_TYPE_ERROR, _T("FAILED: Unable to split upgrade error INF line - %s"), szLine));
  3411. dwReturn = ERROR_INVALID_DATA;
  3412. }
  3413. // find the next line in the section. If there is no next line it should return false
  3414. b = SetupFindNextLine(&Context, &Context);
  3415. // free the temporary buffer
  3416. if (szLine)
  3417. {
  3418. GlobalFree(szLine);
  3419. szLine = NULL;
  3420. }
  3421. }
  3422. IntegrateNewErrorsOnUpgrade_WWW_Exit:
  3423. if (szLine){GlobalFree(szLine);szLine=NULL;}
  3424. // let someone watching the debug out put window know it is done
  3425. iisDebugOut_End(_T("IntegrateNewErrorsOnUpgrade_WWW"),LOG_TYPE_TRACE);
  3426. return;
  3427. }
  3428. int WWW_Upgrade_RegToMetabase(HINF hInf)
  3429. {
  3430. iisDebugOut_Start(_T("WWW_Upgrade_RegToMetabase"),LOG_TYPE_TRACE);
  3431. int iReturn = FALSE;
  3432. ACTION_TYPE atCORE = GetIISCoreAction(FALSE);
  3433. // upgrade the script map
  3434. Register_iis_www_handleScriptMap();
  3435. // ================
  3436. //
  3437. // LM/W3SVC/InProcessIsapiApps
  3438. //
  3439. // fresh = ok.
  3440. // reinstall = ok.
  3441. // upgrade 1,2,3 = ok. no isapi apps are listed in the registry, so there is nothing to upgrade.
  3442. // upgrade 4 = User may have added other isapi apps.
  3443. // We need to make sure that
  3444. // a. the ones we are installing get put there
  3445. // b. that we keep the other isapi apps which the user has already installed
  3446. // ================
  3447. // for now, let's just ignore if iis40 upgrade
  3448. if (g_pTheApp->m_bUpgradeTypeHasMetabaseFlag)
  3449. {
  3450. // Added for nt5
  3451. TSTR strTheSection;
  3452. if ( strTheSection.Copy( _T("InProc_ISAPI_Apps") ) &&
  3453. GetSectionNameToDo(g_pTheApp->m_hInfHandle, &strTheSection)
  3454. )
  3455. {
  3456. VerifyMD_InProcessISAPIApps_WWW( strTheSection.QueryStr() );
  3457. }
  3458. }
  3459. else
  3460. {
  3461. TSTR strTheSection;
  3462. if ( strTheSection.Copy( _T("InProc_ISAPI_Apps") ) &&
  3463. GetSectionNameToDo(g_pTheApp->m_hInfHandle, &strTheSection)
  3464. )
  3465. {
  3466. WriteToMD_InProcessISAPIApps_WWW( strTheSection.QueryStr() );
  3467. }
  3468. }
  3469. AdvanceProgressBarTickGauge();
  3470. // ================
  3471. //
  3472. // LM/W3SVC/NTAuthenticationProviders
  3473. //
  3474. // fresh = ok, do not need to write
  3475. // reinstall = ok, do not need to write
  3476. // upgrade 1,2,3 = ok, do not need to write
  3477. // upgrade 4 = user may have other authentication protocols. if they have ntlm, then we need
  3478. // to change that to Negotiate,NTLM because that is the new "NTLM" after IIS 4
  3479. // ================
  3480. if ( g_pTheApp->GetUpgradeVersion() == 4 )
  3481. {
  3482. // For IIS4 users, make sure that they have NTLM and Netgotiate
  3483. VerifyMD_NTAuthenticationProviders_WWW();
  3484. }
  3485. // ================
  3486. //
  3487. // LM/W3SVC/IpSec
  3488. //
  3489. // fresh = ok.
  3490. // reinstall = ok.
  3491. // upgrade 1,2,3 = ok, handles upgrades.
  3492. // upgrade 4 = ok. does nothing and leaves whatever the user already had!
  3493. // ================
  3494. #ifndef _CHICAGO_
  3495. if (g_pTheApp->m_eUpgradeType == UT_351 || g_pTheApp->m_eUpgradeType == UT_10 || g_pTheApp->m_eUpgradeType == UT_20 || g_pTheApp->m_eUpgradeType == UT_30)
  3496. {
  3497. MigrateServiceIpSec(L"SYSTEM\\CurrentControlSet\\Services\\W3SVC\\Parameters",L"LM/W3SVC" );
  3498. CRegKey regWWWParam(HKEY_LOCAL_MACHINE, _T("System\\CurrentControlSet\\Services\\W3SVC\\Parameters"));
  3499. if (regWWWParam)
  3500. {
  3501. regWWWParam.DeleteTree(_T("Deny IP List"));
  3502. regWWWParam.DeleteTree(_T("Grant IP List"));
  3503. }
  3504. }
  3505. #endif //_CHICAGO_
  3506. if ( (g_pTheApp->m_eUpgradeType == UT_351 || g_pTheApp->m_eUpgradeType == UT_10 || g_pTheApp->m_eUpgradeType == UT_20 || g_pTheApp->m_eUpgradeType == UT_30))
  3507. {
  3508. CRegKey regWWWParam(HKEY_LOCAL_MACHINE, _T("System\\CurrentControlSet\\Services\\W3SVC\\Parameters"));
  3509. if (regWWWParam)
  3510. {
  3511. regWWWParam.DeleteValue(_T("AnonymousUserName"));
  3512. regWWWParam.DeleteValue(_T("NTAuthenticationProviders"));
  3513. regWWWParam.DeleteValue(_T("Filter Dlls"));
  3514. regWWWParam.DeleteValue(_T("SecurePort"));
  3515. }
  3516. }
  3517. AdvanceProgressBarTickGauge();
  3518. // If we are upgrading from a K2 beta, then we do not want to mess around with the virtual roots. Just
  3519. // use the existing ones. The only exception is that we need to make sure local host can reach on the
  3520. // default website so that the index server documentation works.
  3521. // ================
  3522. //
  3523. // LM/W3SVC/LogType
  3524. // LM/W3SVC/LogPluginOrder
  3525. // LM/W3SVC/LogFilePeriod
  3526. // LM/W3SVC/LogFileTruncateSize
  3527. //
  3528. // fresh = ok.
  3529. // reinstall = ok.
  3530. // upgrade 1,2,3 = ok, handles upgrades.
  3531. // upgrade 4 = ok. if exists, should leave what the user had.
  3532. // otherwise write in the default stuff.
  3533. // ================
  3534. SetLogPlugInOrder(_T("W3SVC"));
  3535. AdvanceProgressBarTickGauge();
  3536. // ================
  3537. // This needs to be done before the virtual roots get moved into the metabase.
  3538. // ================
  3539. if (!g_pTheApp->m_bUpgradeTypeHasMetabaseFlag)
  3540. {
  3541. #ifndef _CHICAGO_
  3542. Upgrade_WolfPack();
  3543. #endif //_CHICAGO_
  3544. }
  3545. AdvanceProgressBarTickGauge();
  3546. // ================
  3547. // LM/W3SVC/CustomError
  3548. // LM/W3SVC/Info/CustomErrorDesc
  3549. // LM/W3SVC/n/Root/iisamples/exair/CustomError
  3550. // LM/W3SVC/n/Root/iisamples/iisadmin/CustomError
  3551. // LM/W3SVC/n/Root/iisamples/iishelp/CustomError
  3552. //
  3553. // fresh = ok.
  3554. // reinstall = ok
  3555. // upgrade 1,2,3 = ok, handles upgrades.
  3556. // upgrade 4 = ok. if exists, should leave what the user had.
  3557. // otherwise write in the default stuff. in otherwords -- SetDataNoOverwrite!
  3558. // ================
  3559. if ( g_pTheApp->m_eInstallMode == IM_UPGRADE )
  3560. {
  3561. // go back again and integrate and final new custom errors into the upgraded errors.
  3562. // Only do this on an upgrade.
  3563. TSTR strTheSection;
  3564. if ( strTheSection.Copy( _T("UPGRADE_ERRORS") ) &&
  3565. GetSectionNameToDo(hInf, &strTheSection)
  3566. )
  3567. {
  3568. IntegrateNewErrorsOnUpgrade_WWW( hInf, strTheSection.QueryStr() );
  3569. }
  3570. // This moves error pages (ie 404.htm) from \help\common to \help\iishelp\common, and updates metabase paths for IIS4
  3571. if ( g_pTheApp->GetUpgradeVersion() == 4 )
  3572. {
  3573. MoveOldHelpFilesToNewLocation();
  3574. HRESULT hRes;
  3575. CFixCustomErrors CustomErrFix;
  3576. hRes = CustomErrFix.Update(_T("LM/W3SVC"));
  3577. if (FAILED(hRes))
  3578. {iisDebugOut((LOG_TYPE_WARN, _T("CustomErrFix.Update():FAILED= %x.\n"),hRes));}
  3579. }
  3580. }
  3581. AdvanceProgressBarTickGauge();
  3582. #ifndef _CHICAGO_
  3583. //
  3584. // upgrade the cryptographic server keys.
  3585. // either from the registry or metabase to the pstores.
  3586. //
  3587. UpgradeCryptoKeys_WWW();
  3588. AdvanceProgressBarTickGauge();
  3589. #endif //_CHICAGO_
  3590. iisDebugOut_End(_T("WWW_Upgrade_RegToMetabase"),LOG_TYPE_TRACE);
  3591. return iReturn;
  3592. }
  3593. int FTP_Upgrade_RegToMetabase(HINF hInf)
  3594. {
  3595. int iReturn = FALSE;
  3596. iisDebugOut_Start(_T("FTP_Upgrade_RegToMetabase"),LOG_TYPE_TRACE);
  3597. ACTION_TYPE atCORE = GetIISCoreAction(TRUE);
  3598. AdvanceProgressBarTickGauge();
  3599. #ifndef _CHICAGO_
  3600. // ================
  3601. //
  3602. // LM/MSFTPSVC/IpSec
  3603. //
  3604. // fresh = ok.
  3605. // reinstall = ok.
  3606. // upgrade 1,2,3 = ok, handles upgrades.
  3607. // upgrade 4 = ok. does nothing and leaves whatever the user already had!
  3608. // ================
  3609. if (g_pTheApp->m_eUpgradeType == UT_351 || g_pTheApp->m_eUpgradeType == UT_10 || g_pTheApp->m_eUpgradeType == UT_20 || g_pTheApp->m_eUpgradeType == UT_30)
  3610. {
  3611. MigrateServiceIpSec(L"SYSTEM\\CurrentControlSet\\Services\\MSFTPSVC\\Parameters",L"LM/MSFTPSVC" );
  3612. CRegKey regFTPParam(HKEY_LOCAL_MACHINE, _T("System\\CurrentControlSet\\Services\\MSFTPSVC\\Parameters"));
  3613. regFTPParam.DeleteTree(_T("Deny IP List"));
  3614. regFTPParam.DeleteTree(_T("Grant IP List"));
  3615. }
  3616. #endif //_CHICAGO_
  3617. // ================
  3618. //
  3619. // LM/MSFTPSVC/MD_GREETING_MESSAGE
  3620. //
  3621. // fresh = ok. do nothing.
  3622. // reinstall = ok. do nothing.
  3623. // upgrade 1,2,3 = ok, handles upgrades.
  3624. // upgrade 4 = do nothing
  3625. // ================
  3626. if ( (g_pTheApp->m_eUpgradeType == UT_10_W95 || g_pTheApp->m_eUpgradeType == UT_351 || g_pTheApp->m_eUpgradeType == UT_10 || g_pTheApp->m_eUpgradeType == UT_20 || g_pTheApp->m_eUpgradeType == UT_30) )
  3627. {
  3628. CRegKey regFTPParam(HKEY_LOCAL_MACHINE, _T("System\\CurrentControlSet\\Services\\MSFTPSVC\\Parameters"));
  3629. if (regFTPParam)
  3630. {
  3631. WriteToMD_GreetingMessage_FTP();
  3632. regFTPParam.DeleteValue(_T("GreetingMessage"));
  3633. regFTPParam.DeleteValue(_T("AnonymousUserName"));
  3634. }
  3635. }
  3636. AdvanceProgressBarTickGauge();
  3637. // ================
  3638. //
  3639. // LM/MSFTPSVC/LogType
  3640. // LM/MSFTPSVC/LogPluginOrder
  3641. // LM/MSFTPSVC/LogFilePeriod
  3642. // LM/MSFTPSVC/LogFileTruncateSize
  3643. //
  3644. // LM/MSFTPSVC/Capabilities
  3645. //
  3646. // fresh = ok.
  3647. // reinstall = ok.
  3648. // upgrade 1,2,3 = ok, handles upgrades.
  3649. // upgrade 4 = ok. if exists, should leave what the user had.
  3650. // otherwise write in the default stuff. in otherwords -- SetDataNoOverwrite!
  3651. // ================
  3652. SetLogPlugInOrder(_T("MSFTPSVC"));
  3653. AdvanceProgressBarTickGauge();
  3654. iisDebugOut_End(_T("FTP_Upgrade_RegToMetabase"),LOG_TYPE_TRACE);
  3655. iReturn = TRUE;
  3656. return iReturn;
  3657. }
  3658. // Open the metabase and loop thru all the filters which are in there,
  3659. // make sure they contain the filters we require for nt5
  3660. DWORD VerifyMD_Filters_WWW(TSTR &strTheSection)
  3661. {
  3662. iisDebugOut_Start(_T("VerifyMD_Filters_WWW"),LOG_TYPE_TRACE);
  3663. DWORD dwReturnTemp = ERROR_SUCCESS;
  3664. DWORD dwReturn = ERROR_SUCCESS;
  3665. CString csKeyType;
  3666. CString csOrder;
  3667. int bFound = FALSE;
  3668. int c = 0;
  3669. int k = 0;
  3670. INT i, nArrayItems;
  3671. BOOL fAddComma = FALSE;
  3672. CMDKey cmdKey;
  3673. BOOL bReturn;
  3674. CStringArray arrayName, arrayPath;
  3675. CStringArray arrayName_New, arrayPath_New;
  3676. // Add Required Filters to the arrayName
  3677. c = AddRequiredFilters(strTheSection, arrayName, arrayPath);
  3678. // set aside the number of array items
  3679. nArrayItems = (INT)arrayName.GetSize();
  3680. // leave if it is empty
  3681. if ( nArrayItems == 0 ) {goto VerifyMD_Filters_WWW_Exit;}
  3682. // zero out the order string
  3683. csOrder.Empty();
  3684. // open the key to the virtual server, which is what is passed in as a parameter
  3685. cmdKey.OpenNode( _T("LM/W3SVC/Filters") );
  3686. // test for success.
  3687. if ( (METADATA_HANDLE)cmdKey )
  3688. {
  3689. DWORD dwAttr = METADATA_NO_ATTRIBUTES;
  3690. DWORD dwUType = IIS_MD_UT_SERVER;
  3691. DWORD dwDType = STRING_METADATA;
  3692. DWORD dwLength = 0;
  3693. // we need to start this process by getting the existing multisz data from the metabase
  3694. // first, figure out how much memory we will need to do this
  3695. cmdKey.GetData( MD_FILTER_LOAD_ORDER,&dwAttr,&dwUType,&dwDType,&dwLength,NULL,0,METADATA_NO_ATTRIBUTES,IIS_MD_UT_SERVER,STRING_METADATA);
  3696. // give the buffer some head space
  3697. // dwLength += 2;
  3698. bReturn = FALSE;
  3699. if (dwLength > 0)
  3700. {
  3701. // now get the real data from the metabase
  3702. bReturn = cmdKey.GetData( MD_FILTER_LOAD_ORDER,&dwAttr,&dwUType,&dwDType,&dwLength,(PUCHAR)csOrder.GetBuffer( dwLength ),dwLength,METADATA_NO_ATTRIBUTES,IIS_MD_UT_SERVER,STRING_METADATA );
  3703. csOrder.ReleaseBuffer();
  3704. }
  3705. // the data doesn't get written out here, so close the metabase key
  3706. cmdKey.Close();
  3707. // if reading the value from the metabase didn't work, zero out the string
  3708. if ( !bReturn )
  3709. {csOrder.Empty();}
  3710. }
  3711. // if there is something in the order string from the upgrade, then we need to start adding commas
  3712. if ( !csOrder.IsEmpty() )
  3713. {
  3714. iisDebugOut((LOG_TYPE_TRACE, _T("VerifyMD_Filters_WWW():Start. %s.\n"),csOrder));
  3715. fAddComma = TRUE;
  3716. }
  3717. // Do special re-arranging for
  3718. // sspifilt and compression filter
  3719. ReOrderFiltersSpecial(nArrayItems, arrayName, csOrder);
  3720. for ( i = 0; i < nArrayItems; i++ )
  3721. {
  3722. // if the name in the array is already in the filter order list,
  3723. // then continue to the next one
  3724. CString csOrderUpper;
  3725. CString csUpperValue;
  3726. csOrderUpper = csOrder;
  3727. csOrderUpper.MakeUpper();
  3728. csOrderUpper.TrimLeft();
  3729. csOrderUpper.TrimRight();
  3730. csUpperValue = arrayName[i];
  3731. csUpperValue.MakeUpper();
  3732. csUpperValue.TrimLeft();
  3733. csUpperValue.TrimRight();
  3734. // Always, Add this entry to the list of new filters to add!!
  3735. // This is because ReOrderFiltersSpecial() may add Compress or sspifilt to the csOrder
  3736. arrayName_New.Add(arrayName[i]);
  3737. arrayPath_New.Add(arrayPath[i]);
  3738. if ( csOrderUpper.Find( csUpperValue ) >= 0 )
  3739. {
  3740. // this entry is already in the csOrderlist so lets not add it again.
  3741. continue;
  3742. }
  3743. // the name is not alreay in the list. Unless this is the first one to be added, insert
  3744. // a comma to seperate the list, then add the file name
  3745. if ( fAddComma )
  3746. {
  3747. csOrder += _T(',');
  3748. }
  3749. // Add this entry to our list!
  3750. csOrder +=arrayName[i];
  3751. // once we've added one, we know we always need to adde a comma from now on
  3752. fAddComma = TRUE;
  3753. }
  3754. nArrayItems = (INT)arrayName_New.GetSize();
  3755. // always write out the loadorder list.
  3756. WriteToMD_Filters_List_Entry(csOrder);
  3757. // leave if it is empty
  3758. if ( nArrayItems == 0 ) {goto VerifyMD_Filters_WWW_Exit;}
  3759. for (k=0; k<nArrayItems; k++)
  3760. {
  3761. WriteToMD_Filter_Entry(arrayName_New[k], arrayPath_New[k]);
  3762. }
  3763. VerifyMD_Filters_WWW_Exit:
  3764. iisDebugOut_End1(_T("VerifyMD_Filters_WWW"),csOrder,LOG_TYPE_TRACE);
  3765. return dwReturn;
  3766. }
  3767. DWORD WriteToMD_Filters_List_Entry(CString csOrder)
  3768. {
  3769. DWORD dwReturn = ERROR_SUCCESS;
  3770. DWORD dwReturnTemp = ERROR_SUCCESS;
  3771. MDEntry stMDEntry;
  3772. CString csKeyType;
  3773. // Add this entry to the metabase!
  3774. csKeyType = _T("IIsFilters");
  3775. stMDEntry.szMDPath = _T("LM/W3SVC/Filters");
  3776. stMDEntry.dwMDIdentifier = MD_KEY_TYPE;
  3777. stMDEntry.dwMDAttributes = METADATA_NO_ATTRIBUTES;
  3778. stMDEntry.dwMDUserType = IIS_MD_UT_SERVER;
  3779. stMDEntry.dwMDDataType = STRING_METADATA;
  3780. stMDEntry.dwMDDataLen = (csKeyType.GetLength() + 1) * sizeof(TCHAR);
  3781. stMDEntry.pbMDData = (LPBYTE)(LPCTSTR)csKeyType;
  3782. dwReturnTemp = SetMDEntry(&stMDEntry);
  3783. if (dwReturnTemp != ERROR_SUCCESS){dwReturn = dwReturnTemp;}
  3784. // now we have csOrder=f1,f2,f3,sspifilt
  3785. stMDEntry.szMDPath = _T("LM/W3SVC/Filters");
  3786. stMDEntry.dwMDIdentifier = MD_FILTER_LOAD_ORDER;
  3787. stMDEntry.dwMDAttributes = METADATA_NO_ATTRIBUTES;
  3788. stMDEntry.dwMDUserType = IIS_MD_UT_SERVER;
  3789. stMDEntry.dwMDDataType = STRING_METADATA;
  3790. stMDEntry.dwMDDataLen = (csOrder.GetLength() + 1) * sizeof(TCHAR);
  3791. stMDEntry.pbMDData = (LPBYTE)(LPCTSTR)csOrder;
  3792. // always overwrite, we may have added new filters
  3793. dwReturnTemp = SetMDEntry(&stMDEntry);
  3794. if (dwReturnTemp != ERROR_SUCCESS){dwReturn = dwReturnTemp;}
  3795. return dwReturn;
  3796. }
  3797. DWORD WriteToMD_Filter_Entry(CString csFilter_Name, CString csFilter_Path)
  3798. {
  3799. DWORD dwReturn = ERROR_SUCCESS;
  3800. DWORD dwReturnTemp = ERROR_SUCCESS;
  3801. MDEntry stMDEntry;
  3802. CString csMDPath;
  3803. CString csKeyType;
  3804. csMDPath = _T("LM/W3SVC/Filters/") + (CString)csFilter_Name;
  3805. // Set Entry for the Filter
  3806. stMDEntry.szMDPath = (LPTSTR)(LPCTSTR)csMDPath;
  3807. stMDEntry.dwMDIdentifier = MD_FILTER_IMAGE_PATH;
  3808. stMDEntry.dwMDAttributes = METADATA_NO_ATTRIBUTES;
  3809. stMDEntry.dwMDUserType = IIS_MD_UT_SERVER;
  3810. stMDEntry.dwMDDataType = STRING_METADATA;
  3811. stMDEntry.dwMDDataLen = ((csFilter_Path).GetLength() + 1) * sizeof(TCHAR);
  3812. stMDEntry.pbMDData = (LPBYTE)(LPCTSTR)(csFilter_Path);
  3813. // always overwrite, we may have added new filters
  3814. dwReturnTemp = SetMDEntry_Wrap(&stMDEntry);
  3815. if (dwReturnTemp != ERROR_SUCCESS){dwReturn = dwReturnTemp;}
  3816. // Set KeyType
  3817. csKeyType = _T("IIsFilter");
  3818. stMDEntry.szMDPath = (LPTSTR)(LPCTSTR)csMDPath;
  3819. stMDEntry.dwMDIdentifier = MD_KEY_TYPE;
  3820. stMDEntry.dwMDAttributes = METADATA_NO_ATTRIBUTES;
  3821. stMDEntry.dwMDUserType = IIS_MD_UT_SERVER;
  3822. stMDEntry.dwMDDataType = STRING_METADATA;
  3823. stMDEntry.dwMDDataLen = (csKeyType.GetLength() + 1) * sizeof(TCHAR);
  3824. stMDEntry.pbMDData = (LPBYTE)(LPCTSTR)csKeyType;
  3825. // always overwrite, we may have added new filters
  3826. dwReturnTemp = SetMDEntry_Wrap(&stMDEntry);
  3827. if (dwReturnTemp != ERROR_SUCCESS){dwReturn = dwReturnTemp;}
  3828. return dwReturn;
  3829. }
  3830. DWORD WriteToMD_InProcessISAPIApps_WWW(IN LPCTSTR szSection)
  3831. {
  3832. DWORD dwReturnTemp = ERROR_SUCCESS;
  3833. DWORD dwReturn = ERROR_SUCCESS;
  3834. CStringArray arrayName, arrayPath;
  3835. int nArrayItems = 0;
  3836. int i;
  3837. TSTR_MSZ mstrInProcList;
  3838. // Add Required Filters to the arrayName
  3839. AddRequiredISAPI(arrayName, arrayPath, szSection);
  3840. // set aside the number of array items
  3841. nArrayItems = (int)arrayName.GetSize();
  3842. // leave if it is empty
  3843. if ( nArrayItems == 0 ) {goto WriteToMD_InProcessISAPIApps_WWW_Exit;}
  3844. for ( i = 0; i < nArrayItems; i++ )
  3845. {
  3846. if ( !mstrInProcList.Add( arrayPath[i].GetBuffer(0) ) )
  3847. {
  3848. goto WriteToMD_InProcessISAPIApps_WWW_Exit;
  3849. }
  3850. }
  3851. // write it to the metabase
  3852. WriteToMD_ISAPI_Entry( mstrInProcList );
  3853. WriteToMD_InProcessISAPIApps_WWW_Exit:
  3854. return dwReturn;
  3855. }
  3856. //
  3857. // Returns the amount of entries that we added.
  3858. //
  3859. int AddRequiredISAPI(CStringArray& arrayName,CStringArray& arrayPath, IN LPCTSTR szSection)
  3860. {
  3861. iisDebugOut_Start(_T("AddRequiredISAPI"),LOG_TYPE_TRACE);
  3862. int c = 0;
  3863. CString csName = _T("");
  3864. CString csPath = _T("");
  3865. CStringList strList;
  3866. TSTR strTheSection;
  3867. if ( strTheSection.Copy( szSection ) &&
  3868. GetSectionNameToDo(g_pTheApp->m_hInfHandle, &strTheSection)
  3869. )
  3870. {
  3871. if (ERROR_SUCCESS == FillStrListWithListOfSections(g_pTheApp->m_hInfHandle, strList, strTheSection.QueryStr() ))
  3872. {
  3873. // loop thru the list returned back
  3874. if (strList.IsEmpty() == FALSE)
  3875. {
  3876. POSITION pos = NULL;
  3877. CString csEntry;
  3878. pos = strList.GetHeadPosition();
  3879. while (pos)
  3880. {
  3881. csEntry = _T("");
  3882. csEntry = strList.GetAt(pos);
  3883. // Split into name, and value. look for ","
  3884. int i;
  3885. i = csEntry.ReverseFind(_T(','));
  3886. if (i != -1)
  3887. {
  3888. int len =0;
  3889. len = csEntry.GetLength();
  3890. csPath = csEntry.Right(len - i - 1);
  3891. csName = csEntry.Left(i);
  3892. // Add it to our array...
  3893. iisDebugOut((LOG_TYPE_TRACE, _T("Add isapi Entry:%s:%s\n"),csName, csPath));
  3894. arrayName.Add(csName);
  3895. arrayPath.Add(csPath);
  3896. c++;
  3897. }
  3898. strList.GetNext(pos);
  3899. }
  3900. }
  3901. }
  3902. }
  3903. iisDebugOut((LOG_TYPE_TRACE, _T("AddRequiredISAPI:End.Return=%d\n"),c));
  3904. return c;
  3905. }
  3906. DWORD WriteToMD_ISAPI_Entry( TSTR_MSZ &mstrInprocIsapiList )
  3907. {
  3908. MDEntry stMDEntry;
  3909. // write the new errors list back out to the metabase
  3910. stMDEntry.szMDPath = _T("LM/W3SVC");
  3911. stMDEntry.dwMDIdentifier = MD_IN_PROCESS_ISAPI_APPS;
  3912. stMDEntry.dwMDAttributes = METADATA_INHERIT;
  3913. stMDEntry.dwMDUserType = IIS_MD_UT_SERVER;
  3914. stMDEntry.dwMDDataType = MULTISZ_METADATA;
  3915. stMDEntry.dwMDDataLen = mstrInprocIsapiList.QueryLen() * sizeof(WCHAR);
  3916. stMDEntry.pbMDData = (LPBYTE) mstrInprocIsapiList.QueryMultiSz();
  3917. return SetMDEntry(&stMDEntry);
  3918. }
  3919. // loop thru the isapi apps and make sure the required ones are there.
  3920. BOOL VerifyMD_InProcessISAPIApps_WWW(IN LPCTSTR szSection)
  3921. {
  3922. CMDKey cmdKey;
  3923. PVOID pData = NULL;
  3924. BOOL bReturn = FALSE;
  3925. CString csOneBlobEntry;
  3926. CString cs;
  3927. int c = 0;
  3928. TSTR_MSZ mstrInProcList;
  3929. CMDValue cmdInProcList;
  3930. int iISAPIPath_NewlyAdded_Count = 0;
  3931. int i, nArrayItems;
  3932. int iPleaseCloseTheMetabase = FALSE;
  3933. TCHAR* pBlobEntry = NULL;
  3934. DWORD cbBuffer = 0;
  3935. CStringArray arrayName, arrayPath;
  3936. // open the key
  3937. cmdKey.OpenNode(_T("LM/W3SVC"));
  3938. // test for success.
  3939. if ( (METADATA_HANDLE)cmdKey == NULL )
  3940. {
  3941. // i could not open the key
  3942. // maybe there is nothing there.
  3943. // this must be a fresh install.
  3944. WriteToMD_InProcessISAPIApps_WWW(szSection);
  3945. goto VerifyMD_InProcessISAPIApps_WWW_Exit;
  3946. }
  3947. iPleaseCloseTheMetabase = TRUE;
  3948. // Add Required Filters to the arrayName
  3949. c = AddRequiredISAPI(arrayName, arrayPath, szSection);
  3950. // set aside the number of array items
  3951. nArrayItems = (int)arrayName.GetSize();
  3952. // leave if it is empty
  3953. if ( nArrayItems == 0 ) {goto VerifyMD_InProcessISAPIApps_WWW_Exit;}
  3954. // Initialize Value
  3955. if ( !cmdInProcList.SetValue( MD_IN_PROCESS_ISAPI_APPS,
  3956. METADATA_INHERIT,
  3957. IIS_MD_UT_SERVER,
  3958. MULTISZ_METADATA,
  3959. sizeof( _T("\0\0") ),
  3960. _T("\0\0") ) )
  3961. {
  3962. iisDebugOut((LOG_TYPE_ERROR, _T("VerifyMD_InProcessISAPIApps_WWW.1.Failed to allocate memory.\n")));
  3963. goto VerifyMD_InProcessISAPIApps_WWW_Exit;
  3964. }
  3965. // Retrieve Value from metabase
  3966. if ( cmdKey.GetData( cmdInProcList, MD_IN_PROCESS_ISAPI_APPS ) )
  3967. {
  3968. if ( ( cmdInProcList.GetDataType() != MULTISZ_METADATA ) ||
  3969. ( !mstrInProcList.Copy( (LPTSTR) cmdInProcList.GetData() ) )
  3970. )
  3971. {
  3972. iisDebugOut((LOG_TYPE_ERROR, _T("VerifyMD_InProcessISAPIApps_WWW.2.Failed to allocate memory.\n")));
  3973. goto VerifyMD_InProcessISAPIApps_WWW_Exit;
  3974. }
  3975. }
  3976. // close the handle to the metabase so that we can
  3977. // open it to write the stuff out later!
  3978. cmdKey.Close();
  3979. iPleaseCloseTheMetabase = FALSE;
  3980. // now loop thru this list
  3981. // and check if our isapi dll's are in this list.
  3982. // if they are not, then we add them to the end.
  3983. iISAPIPath_NewlyAdded_Count = 0;
  3984. for ( i = 0; i < nArrayItems; i++ )
  3985. {
  3986. // if the name in the array is already in the filter order list,
  3987. // then continue to the next one
  3988. if ( mstrInProcList.IsPresent( arrayPath[i].GetBuffer(0) ) )
  3989. {
  3990. // Skip this one
  3991. continue;
  3992. }
  3993. if ( !mstrInProcList.Add( arrayPath[i].GetBuffer(0) ) )
  3994. {
  3995. iisDebugOut((LOG_TYPE_ERROR, _T("VerifyMD_InProcessISAPIApps_WWW.3.Failed to add item to list.\n")));
  3996. goto VerifyMD_InProcessISAPIApps_WWW_Exit;
  3997. }
  3998. iISAPIPath_NewlyAdded_Count++;
  3999. }
  4000. // If we added any new entries to the metabase
  4001. // the let's write out the new block of data, otherwise let's get out.
  4002. if (iISAPIPath_NewlyAdded_Count > 0)
  4003. {
  4004. WriteToMD_ISAPI_Entry( mstrInProcList );
  4005. }
  4006. VerifyMD_InProcessISAPIApps_WWW_Exit:
  4007. // close the key
  4008. if (TRUE == iPleaseCloseTheMetabase){cmdKey.Close();}
  4009. if (pData){GlobalFree(pData);pData=NULL;}
  4010. // the only time it should return FALSE is if it can't open the key
  4011. return TRUE;
  4012. }
  4013. DWORD WriteToMD_NTAuthenticationProviders_WWW(CString csData)
  4014. {
  4015. DWORD dwReturnTemp = ERROR_SUCCESS;
  4016. DWORD dwReturn = ERROR_SUCCESS;
  4017. MDEntry stMDEntry;
  4018. // Upgrade 4.0 comment --> Replace any NTLM with Negotiate,NTLM
  4019. stMDEntry.szMDPath = _T("LM/W3SVC");
  4020. //stMDEntry.szMDPath = (LPTSTR)(LPCTSTR)csKeyPath;
  4021. stMDEntry.dwMDIdentifier = MD_NTAUTHENTICATION_PROVIDERS;
  4022. stMDEntry.dwMDAttributes = METADATA_INHERIT;
  4023. stMDEntry.dwMDUserType = IIS_MD_UT_FILE;
  4024. stMDEntry.dwMDDataType = STRING_METADATA;
  4025. stMDEntry.dwMDDataLen = (csData.GetLength() + 1) * sizeof(TCHAR);
  4026. stMDEntry.pbMDData = (LPBYTE)(LPCTSTR)csData;
  4027. dwReturnTemp = SetMDEntry(&stMDEntry);
  4028. if (dwReturnTemp != ERROR_SUCCESS){dwReturn = dwReturnTemp;}
  4029. return dwReturn;
  4030. }
  4031. // Open the metabase and loop thru all the entries which are in there,
  4032. // make sure they contain the entries we require for nt5
  4033. DWORD VerifyMD_NTAuthenticationProviders_WWW(void)
  4034. {
  4035. iisDebugOut_Start(_T("VerifyMD_NTAuthenticationProviders_WWW"),LOG_TYPE_TRACE);
  4036. DWORD dwReturnTemp = ERROR_SUCCESS;
  4037. DWORD dwReturn = ERROR_SUCCESS;
  4038. CString csKeyType;
  4039. CString csOrder;
  4040. int c = 0;
  4041. int k = 0;
  4042. BOOL fAddComma = FALSE;
  4043. CMDKey cmdKey;
  4044. BOOL bReturn;
  4045. int bFound_Negotiate = FALSE;
  4046. int bFound_NTLM = FALSE;
  4047. int j = 0;
  4048. int iPleaseWriteOutTheEntry = FALSE;
  4049. cmdKey.OpenNode( _T("LM/W3SVC") );
  4050. // test for success.
  4051. if ( (METADATA_HANDLE)cmdKey )
  4052. {
  4053. DWORD dwAttr = METADATA_INHERIT;
  4054. DWORD dwUType = IIS_MD_UT_FILE;
  4055. DWORD dwDType = STRING_METADATA;
  4056. DWORD dwLength = 0;
  4057. // we need to start this process by getting the existing multisz data from the metabase
  4058. // first, figure out how much memory we will need to do this
  4059. cmdKey.GetData( MD_NTAUTHENTICATION_PROVIDERS,&dwAttr,&dwUType,&dwDType,&dwLength,NULL,0,METADATA_INHERIT,IIS_MD_UT_FILE,STRING_METADATA);
  4060. // give the buffer some head space
  4061. // dwLength += 2;
  4062. bReturn = FALSE;
  4063. if (dwLength > 0)
  4064. {
  4065. // now get the real data from the metabase
  4066. bReturn = cmdKey.GetData( MD_NTAUTHENTICATION_PROVIDERS,&dwAttr,&dwUType,&dwDType,&dwLength,(PUCHAR)csOrder.GetBuffer( dwLength ),dwLength,METADATA_INHERIT,IIS_MD_UT_FILE,STRING_METADATA );
  4067. csOrder.ReleaseBuffer();
  4068. }
  4069. // the data doesn't get written out here, so close the metabase key
  4070. cmdKey.Close();
  4071. // if reading the value from the metabase didn't work, zero out the string
  4072. if ( !bReturn ){csOrder.Empty();}
  4073. }
  4074. // if there is something in the order string from the upgrade, then we need to start adding commas
  4075. if ( !csOrder.IsEmpty() ){fAddComma = TRUE;}
  4076. // search for negotiate.
  4077. // if it is there then set flag.
  4078. if ( csOrder.Find( _T("Negotiate") ) >= 0 ) {bFound_Negotiate = TRUE;}
  4079. if ( csOrder.Find( _T("NTLM") ) >= 0 ) {bFound_NTLM = TRUE;}
  4080. if (bFound_Negotiate && bFound_NTLM)
  4081. {
  4082. // The entries already exist. so exit
  4083. goto VerifyMD_NTAuthenticationProviders_WWW_Exit;
  4084. }
  4085. if (bFound_NTLM)
  4086. {
  4087. // we found NTLM
  4088. // check if Negotiate is in there.
  4089. // So let's add it to the end
  4090. if (!bFound_Negotiate)
  4091. {
  4092. // no Negotiate entry, add both NTLM and Negotiate in place of NTLM!
  4093. // Find where NTLM exists and stick Negotiate in front of it!
  4094. // testing,NTLM,somethingelse
  4095. j = csOrder.Find(_T(','));
  4096. if ( j != -1 )
  4097. {
  4098. CString csLeftSide;
  4099. CString csRightSide;
  4100. j = csOrder.Find(_T("NTLM"));
  4101. // means more than 1 item
  4102. csLeftSide = csOrder.Mid(0, j);
  4103. csRightSide = csOrder.Mid(j+4);
  4104. csOrder = csLeftSide;
  4105. csOrder += _T("Negotiate,NTLM");
  4106. csOrder += csRightSide;
  4107. }
  4108. else
  4109. {
  4110. csOrder = _T("Negotiate,NTLM");
  4111. }
  4112. iPleaseWriteOutTheEntry = TRUE;
  4113. }
  4114. }
  4115. else
  4116. {
  4117. // That means we didn't find NTLM
  4118. // So let's add it to the end
  4119. if (fAddComma) {csOrder += _T(',');}
  4120. if (bFound_Negotiate)
  4121. {
  4122. iPleaseWriteOutTheEntry = TRUE;
  4123. // negotiate already exists, so just add NTLM entry to the end of the list.
  4124. csOrder += _T("NTLM");
  4125. }
  4126. else
  4127. {
  4128. // No NTLM and No Negotiate, add them both.
  4129. iPleaseWriteOutTheEntry = TRUE;
  4130. csOrder += _T("Negotiate,NTLM");
  4131. }
  4132. }
  4133. if (TRUE == iPleaseWriteOutTheEntry)
  4134. {
  4135. dwReturn = WriteToMD_NTAuthenticationProviders_WWW(csOrder);
  4136. }
  4137. goto VerifyMD_NTAuthenticationProviders_WWW_Exit;
  4138. VerifyMD_NTAuthenticationProviders_WWW_Exit:
  4139. iisDebugOut_End(_T("VerifyMD_NTAuthenticationProviders_WWW"),LOG_TYPE_TRACE);
  4140. return dwReturn;
  4141. }
  4142. void AddSpecialCustomErrors(IN HINF hFile,IN LPCTSTR szSection,IN CString csKeyPath,IN BOOL fOverwrite)
  4143. {
  4144. iisDebugOut((LOG_TYPE_TRACE, _T("AddSpecialCustomErrors():Start.%s:%s.\n"),szSection,csKeyPath));
  4145. // open the .inf file and get the infsection
  4146. // read that section and add it to the custom errors at the csKeypath.
  4147. CStringList strList;
  4148. CString csTheSection = szSection;
  4149. CString csTemp;
  4150. DWORD dwErrorCode;
  4151. INT iErrorSubCode;
  4152. if (ERROR_SUCCESS == FillStrListWithListOfSections(hFile, strList, csTheSection))
  4153. {
  4154. // loop thru the list returned back
  4155. if (strList.IsEmpty() == FALSE)
  4156. {
  4157. POSITION pos = NULL;
  4158. CString csEntry;
  4159. pos = strList.GetHeadPosition();
  4160. while (pos)
  4161. {
  4162. csEntry = strList.GetAt(pos);
  4163. // at this point csEntry should look like this:
  4164. // 500,100,URL,/iisHelp/common/500-100.asp
  4165. // parse the line.
  4166. // get the first error ID code
  4167. csTemp = csEntry.Left( csEntry.Find(_T(',')) );
  4168. csEntry = csEntry.Right( csEntry.GetLength() - (csTemp.GetLength() +1) );
  4169. _stscanf( csTemp, _T("%d"), &dwErrorCode );
  4170. // get the second code
  4171. csTemp = csEntry.Left( csEntry.Find(_T(',')) );
  4172. csEntry = csEntry.Right( csEntry.GetLength() - (csTemp.GetLength() +1) );
  4173. if ( csTemp == _T('*') )
  4174. iErrorSubCode = -1;
  4175. else
  4176. _stscanf( csTemp, _T("%d"), &iErrorSubCode );
  4177. // Get the next whole string
  4178. csTemp = csEntry;
  4179. // Addthe new error code.
  4180. AddCustomError(dwErrorCode, iErrorSubCode, csTemp, csKeyPath, fOverwrite);
  4181. // get the next error
  4182. strList.GetNext(pos);
  4183. }
  4184. }
  4185. }
  4186. iisDebugOut_End1(_T("AddSpecialCustomErrors"),csKeyPath,LOG_TYPE_TRACE);
  4187. return;
  4188. }
  4189. // given a pointer to a map for a single virtual website, this routine creates its vitual directories - BOYDM
  4190. // szSvcName the name of the server - W3SVC or MSFTPSVC
  4191. // i the virtual server number
  4192. // pObj the map for the virtual server's directories
  4193. // szVirtServerPath the path to the node we are creating. example: LM/W3SVC/1
  4194. //
  4195. // returns the value of n, which is used to then increment i
  4196. // ****** warning ****** This does not necessarily start from #1 !!! ******
  4197. // will get the next open virtual server number and add from there.
  4198. UINT AddVirtualServer(LPCTSTR szSvcName, UINT i, CMapStringToString *pObj, CString& csRoot, CString& csIP)
  4199. {
  4200. iisDebugOut((LOG_TYPE_TRACE, _T("AddVirtualServer():Start.%s.%d.%s.%s.\n"),szSvcName,i,csRoot,csIP));
  4201. CMDKey cmdKey;
  4202. TCHAR Buf[10];
  4203. UINT SvcId;
  4204. // convert the virtual server number to a string
  4205. _itot(i, Buf, 10);
  4206. // Default the progress text to the web server
  4207. SvcId = IDS_ADD_SETTINGS_FOR_WEB_1;
  4208. if (_tcsicmp(szSvcName, _T("MSFTPSVC")) == 0) {SvcId = IDS_ADD_SETTINGS_FOR_FTP_1;}
  4209. // Display the Current Site number so the user knows what we are doing
  4210. CString csKeyPath = csRoot;
  4211. csKeyPath += _T("/");
  4212. csKeyPath += Buf; // "LM/W3SVC/n"
  4213. cmdKey.CreateNode(METADATA_MASTER_ROOT_HANDLE, csKeyPath);
  4214. if ( (METADATA_HANDLE)cmdKey ) {cmdKey.Close();}
  4215. else
  4216. {
  4217. iisDebugOut((LOG_TYPE_ERROR, _T("AddVirtualServer():CreateNode %s. FAILED.\n"),csKeyPath));
  4218. return i;
  4219. }
  4220. //
  4221. // /W3SVC/1/IIsWebServer
  4222. //
  4223. if (csRoot.Find(_T("W3SVC")) != -1)
  4224. {
  4225. WriteToMD_IIsWebServerInstance_WWW(csKeyPath);
  4226. }
  4227. else
  4228. {
  4229. WriteToMD_IIsFtpServerInstance_FTP(csKeyPath);
  4230. }
  4231. // for W3SVC or MSFTPSVC
  4232. //
  4233. // /W3SVC/1/ServerBindings
  4234. // /MSFTPSVC/1/ServerBindings
  4235. //
  4236. WriteToMD_ServerBindings(szSvcName, csKeyPath, csIP);
  4237. // About Default Site and Server Size
  4238. if (csIP.Compare(_T("null"))==0)
  4239. {
  4240. // for W3SVC or MSFTPSVC
  4241. //"LM/W3SVC/N/ServerSize"
  4242. //"LM/W3SVC/N/ServerComment"
  4243. //
  4244. //"LM/MSFTPSVC/N/ServerSize"
  4245. //"LM/MSFTPSVC/N/ServerComment"
  4246. WriteToMD_DefaultSiteAndSize(csKeyPath);
  4247. if (csRoot.Find(_T("W3SVC")) != -1)
  4248. {
  4249. // Do only for wwww server!
  4250. TSTR strTheSection;
  4251. if ( strTheSection.Copy( _T("DefaultLoadFile") ) &&
  4252. GetSectionNameToDo(g_pTheApp->m_hInfHandle, &strTheSection)
  4253. )
  4254. {
  4255. VerifyMD_DefaultLoadFile_WWW(strTheSection.QueryStr() , csKeyPath);
  4256. }
  4257. // Check if the defaultload.asp file exists...
  4258. // Add the auth for a certain file...
  4259. CString csVrootPlusFileName;
  4260. csVrootPlusFileName.Format(_T("%s\\%s"), g_pTheApp->m_csPathWWWRoot, _T("localstart.asp"));
  4261. if (IsFileExist(csVrootPlusFileName))
  4262. {
  4263. csVrootPlusFileName = csKeyPath;
  4264. csVrootPlusFileName += _T("/ROOT/localstart.asp");
  4265. WriteToMD_Authorization(csVrootPlusFileName, MD_AUTH_NT | MD_AUTH_BASIC);
  4266. }
  4267. }
  4268. }
  4269. //
  4270. // Loop thru the Virtual Dirs
  4271. //
  4272. POSITION pos1 = pObj->GetStartPosition();
  4273. TCHAR szSpecialSection[200];
  4274. CString csFullKeyPath;
  4275. while (pos1)
  4276. {
  4277. CString csValue;
  4278. CString csName;
  4279. pObj->GetNextAssoc(pos1, csName, csValue);
  4280. //
  4281. // Create Virtual Root Tree
  4282. //
  4283. // CreateMDVRootTree(LM/W3SVC/1, /, "<path>,<username>,<perm>", "null", nProgressBarTextWebInstance)
  4284. // CreateMDVRootTree(LM/W3SVC/1, /IISADMIN, "<path>,<username>,<perm>", "122.255.255.255", nProgressBarTextWebInstance)
  4285. // CreateMDVRootTree(LM/W3SVC/1, /IISSAMPLES, "<path>,<username>,<perm>", "122.255.255.255", nProgressBarTextWebInstance)
  4286. // CreateMDVRootTree(LM/W3SVC/1, /IISHELP, "%s\\Help\\iishelp,,%x", "122.255.255.255", nProgressBarTextWebInstance)
  4287. // CreateMDVRootTree(LM/W3SVC/1, /SCRIPTS, "<path>,<username>,<perm>", "122.255.255.255", nProgressBarTextWebInstance)
  4288. // CreateMDVRootTree(LM/W3SVC/1, /IISADMPWD, "<path>,<username>,<perm>", "122.255.255.255", nProgressBarTextWebInstance)
  4289. //
  4290. // Will create:
  4291. // /= /W3SVC/1/ROOT
  4292. // IISADMIN= /W3SVC/1/ROOT/IISADMIN
  4293. // IISSAMPLES= /W3SVC/1/ROOT/IISSAMPLES
  4294. // IISHELP= /W3SVC/1/ROOT/IISHELP
  4295. // SCRIPTS= /W3SVC/1/ROOT/SCRIPTS
  4296. // IISADMPWD= /W3SVC/1/ROOT/IISADMPWD
  4297. CreateMDVRootTree(csKeyPath, csName, csValue, csIP, i);
  4298. if (csRoot.Find(_T("W3SVC")) != -1)
  4299. {
  4300. if (csName == _T("/"))
  4301. {csFullKeyPath = csKeyPath + _T("/ROOT");}
  4302. else
  4303. {csFullKeyPath = csKeyPath + _T("/ROOT") + csName;}
  4304. // Add Special Custom errors for this vroot
  4305. // AddSpecialCustomErrors(g_pTheApp->m_hInfHandle, _T("CUSTOMERROR_ALL_DEFAULT_VDIRS"), csFullKeyPath, TRUE);
  4306. // Add Special Custom errors for this certain vroot
  4307. _stprintf(szSpecialSection, _T("CUSTOMERROR_%s"), csName);
  4308. AddSpecialCustomErrors(g_pTheApp->m_hInfHandle, szSpecialSection, csFullKeyPath, TRUE);
  4309. }
  4310. AdvanceProgressBarTickGauge();
  4311. }
  4312. if (csRoot.Find(_T("W3SVC")) != -1)
  4313. {
  4314. // if this is for the web server
  4315. WriteToMD_CertMapper(csKeyPath);
  4316. }
  4317. //AdvanceProgressBarTickGauge();
  4318. // return the value of i so that it can be incremented
  4319. iisDebugOut((LOG_TYPE_TRACE, _T("AddVirtualServer():End.%s.%d.%s.%s.\n"),szSvcName,i,csRoot,csIP));
  4320. return i;
  4321. }
  4322. // The list will be filled with every instance we care to look at:
  4323. // We should now loop thru the list and make sure that we have all the required fields.
  4324. // csMDPath = like LM/W3SVC/N
  4325. int VerifyVRoots_W3SVC_n(CString csMDPath)
  4326. {
  4327. int iReturn = FALSE;
  4328. iisDebugOut_Start(_T("VerifyVRoots_W3SVC_n"), LOG_TYPE_TRACE);
  4329. /*
  4330. [/W3SVC/1]
  4331. ServerSize : [IS] (DWORD) 0x1={Medium}
  4332. ServerComment : [IS] (STRING) "Default Web Site"
  4333. KeyType : [S] (STRING) "IIsWebServer"
  4334. ServerBindings : [IS] (MULTISZ) ":80:"
  4335. SecureBindings : [IS] (MULTISZ) ":443:"
  4336. */
  4337. WriteToMD_IIsWebServerInstance_WWW(csMDPath);
  4338. WriteToMD_DefaultSiteAndSize(csMDPath);
  4339. if (csMDPath.CompareNoCase(_T("LM/W3SVC/1")) == 0)
  4340. {
  4341. // if this is the default web site then it's get's special consideration
  4342. WriteToMD_ServerBindings(_T("W3SVC"), csMDPath, _T("null"));
  4343. }
  4344. else
  4345. {
  4346. // how do i get the csIP???
  4347. // for other W3SVC/2 sites???
  4348. }
  4349. iisDebugOut_End(_T("VerifyVRoots_W3SVC_n"),LOG_TYPE_TRACE);
  4350. return iReturn;
  4351. }
  4352. DWORD WriteToMD_Capabilities(LPCTSTR lpszSvc)
  4353. {
  4354. DWORD dwReturn = ERROR_SUCCESS;
  4355. MDEntry stMDEntry;
  4356. DWORD dwCapabilities = 0;
  4357. // Set the capability type - default to win95
  4358. // Set odbc on if server...
  4359. dwCapabilities = IIS_CAP1_W95;
  4360. if (g_pTheApp->m_eNTOSType == OT_PDC_OR_BDC){dwCapabilities = IIS_CAP1_NTS; dwCapabilities |= IIS_CAP1_ODBC_LOGGING;}
  4361. if (g_pTheApp->m_eNTOSType == OT_NTW){dwCapabilities = IIS_CAP1_NTW;}
  4362. if (g_pTheApp->m_eNTOSType == OT_NTS){dwCapabilities = IIS_CAP1_NTS; dwCapabilities |= IIS_CAP1_ODBC_LOGGING;}
  4363. // LM/MSFTPSVC
  4364. // LM/W3SVC
  4365. CString csKeyPath = _T("LM/");
  4366. csKeyPath += lpszSvc;
  4367. csKeyPath += _T("/Info");
  4368. stMDEntry.szMDPath = (LPTSTR)(LPCTSTR)csKeyPath;
  4369. stMDEntry.dwMDIdentifier = MD_SERVER_CAPABILITIES;
  4370. stMDEntry.dwMDAttributes = METADATA_INHERIT;
  4371. stMDEntry.dwMDUserType = IIS_MD_UT_SERVER;
  4372. stMDEntry.dwMDDataType = DWORD_METADATA;
  4373. stMDEntry.dwMDDataLen = sizeof(DWORD);
  4374. stMDEntry.pbMDData = (LPBYTE)&dwCapabilities;
  4375. dwReturn = SetMDEntry(&stMDEntry);
  4376. return dwReturn;
  4377. }
  4378. // loop thru the metabase
  4379. // and look for the next instance number which is not used!
  4380. // return that. "i" is at least = 1.
  4381. int VerifyVRoots(LPCTSTR szSvcName)
  4382. {
  4383. iisDebugOut_Start(_T("VerifyVRoots"), LOG_TYPE_TRACE);
  4384. CString csRoot = _T("LM/");
  4385. csRoot += szSvcName; // "LM/W3SVC"
  4386. TCHAR Buf[10];
  4387. CString csInstRoot, csMDPath;
  4388. CMDKey cmdKey;
  4389. CStringList strListInstance;
  4390. int i = 1;
  4391. // Loop thru every instance of
  4392. // the servers "LM/W3SVC/N"
  4393. csInstRoot = csRoot;
  4394. csInstRoot += _T("/");
  4395. _itot(i, Buf, 10);
  4396. csMDPath = csInstRoot + Buf;
  4397. cmdKey.OpenNode(csMDPath);
  4398. while ( (METADATA_HANDLE)cmdKey )
  4399. {
  4400. cmdKey.Close();
  4401. _itot(++i, Buf, 10);
  4402. csMDPath = csInstRoot + Buf;
  4403. cmdKey.OpenNode(csMDPath);
  4404. if ((METADATA_HANDLE) cmdKey)
  4405. {
  4406. // Add it to our list of our nodes!
  4407. strListInstance.AddTail(csMDPath);
  4408. }
  4409. }
  4410. if (strListInstance.IsEmpty() == FALSE)
  4411. {
  4412. iisDebugOut((LOG_TYPE_TRACE, _T("************** Loop START **************")));
  4413. POSITION pos = NULL;
  4414. CString csEntry;
  4415. pos = strListInstance.GetHeadPosition();
  4416. while (pos)
  4417. {
  4418. csEntry = strListInstance.GetAt(pos);
  4419. iisDebugOutSafeParams((LOG_TYPE_TRACE, _T("%1!s!\n"), csEntry));
  4420. if (_tcsicmp(szSvcName, _T("W3SVC")) == 0)
  4421. {
  4422. VerifyVRoots_W3SVC_n(csEntry);
  4423. }
  4424. strListInstance.GetNext(pos);
  4425. }
  4426. iisDebugOut((LOG_TYPE_TRACE, _T("************** Loop END **************")));
  4427. }
  4428. iisDebugOut_End(_T("VerifyVRoots"),LOG_TYPE_TRACE);
  4429. return TRUE;
  4430. }
  4431. DWORD HandleSecurityTemplates(LPCTSTR szSvcName)
  4432. {
  4433. DWORD dwReturn = ERROR_SUCCESS;
  4434. DWORD dwReturnTemp = ERROR_SUCCESS;
  4435. CString csKeyType;
  4436. CString csKeyPath;
  4437. UINT iComment = IDS_TEMPLATE_PUBLIC_WEB_SITE;
  4438. DWORD dwRegularPerm;
  4439. if (_tcsicmp(szSvcName, _T("W3SVC")) == 0)
  4440. {
  4441. //
  4442. // do www regular
  4443. //
  4444. dwRegularPerm = MD_ACCESS_SCRIPT | MD_ACCESS_READ;
  4445. csKeyPath = _T("LM/W3SVC/Info/Templates/Public Web Site");
  4446. iComment = IDS_TEMPLATE_PUBLIC_WEB_SITE;
  4447. dwReturn = WriteToMD_ServerComment(csKeyPath, iComment);
  4448. dwReturnTemp = WriteToMD_IIsWebServerInstance_WWW(csKeyPath);
  4449. if (dwReturnTemp != ERROR_SUCCESS){dwReturn = dwReturnTemp;}
  4450. csKeyPath = _T("LM/W3SVC/Info/Templates/Public Web Site/Root");
  4451. dwReturnTemp = WriteToMD_IIsWebVirtualDir(csKeyPath);
  4452. if (dwReturnTemp != ERROR_SUCCESS){dwReturn = dwReturnTemp;}
  4453. dwReturnTemp = WriteToMD_AccessPerm(csKeyPath, dwRegularPerm, TRUE);
  4454. if (dwReturnTemp != ERROR_SUCCESS){dwReturn = dwReturnTemp;}
  4455. dwReturnTemp = WriteToMD_Authorization(csKeyPath, MD_AUTH_ANONYMOUS);
  4456. if (dwReturnTemp != ERROR_SUCCESS){dwReturn = dwReturnTemp;}
  4457. WriteToMD_IPsec_GrantByDefault(csKeyPath);
  4458. //
  4459. // do www secure site
  4460. //
  4461. dwRegularPerm = MD_ACCESS_SCRIPT | MD_ACCESS_READ;
  4462. csKeyPath = _T("LM/W3SVC/Info/Templates/Secure Web Site");
  4463. iComment = IDS_TEMPLATE_PUBLIC_SECURE_SITE;
  4464. dwReturn = WriteToMD_ServerComment(csKeyPath, iComment);
  4465. dwReturnTemp = WriteToMD_IIsWebServerInstance_WWW(csKeyPath);
  4466. if (dwReturnTemp != ERROR_SUCCESS){dwReturn = dwReturnTemp;}
  4467. csKeyPath = _T("LM/W3SVC/Info/Templates/Secure Web Site/Root");
  4468. dwReturnTemp = WriteToMD_IIsWebVirtualDir(csKeyPath);
  4469. if (dwReturnTemp != ERROR_SUCCESS){dwReturn = dwReturnTemp;}
  4470. dwReturnTemp = WriteToMD_AccessPerm(csKeyPath, dwRegularPerm, TRUE);
  4471. if (dwReturnTemp != ERROR_SUCCESS){dwReturn = dwReturnTemp;}
  4472. dwReturnTemp = WriteToMD_Authorization(csKeyPath, MD_AUTH_MD5 | MD_AUTH_NT | MD_AUTH_BASIC);
  4473. if (dwReturnTemp != ERROR_SUCCESS){dwReturn = dwReturnTemp;}
  4474. WriteToMD_IPsec_GrantByDefault(csKeyPath);
  4475. }
  4476. else
  4477. {
  4478. //
  4479. // do ftp site
  4480. //
  4481. dwRegularPerm = MD_ACCESS_READ;
  4482. csKeyPath = _T("LM/MSFTPSVC/Info/Templates/Public FTP Site");
  4483. iComment = IDS_TEMPLATE_PUBLIC_FTP_SITE;
  4484. dwReturn = WriteToMD_ServerComment(csKeyPath, iComment);
  4485. dwReturnTemp = WriteToMD_IIsFtpServerInstance_FTP(csKeyPath);
  4486. if (dwReturnTemp != ERROR_SUCCESS){dwReturn = dwReturnTemp;}
  4487. csKeyPath = _T("LM/MSFTPSVC/Info/Templates/Public FTP Site/Root");
  4488. dwReturnTemp = WriteToMD_IIsFtpServerInstance_FTP(csKeyPath);
  4489. if (dwReturnTemp != ERROR_SUCCESS){dwReturn = dwReturnTemp;}
  4490. dwReturnTemp = WriteToMD_AccessPerm(csKeyPath, dwRegularPerm, TRUE);
  4491. if (dwReturnTemp != ERROR_SUCCESS){dwReturn = dwReturnTemp;}
  4492. csKeyPath = _T("LM/MSFTPSVC/Info/Templates/Public FTP Site");
  4493. dwReturnTemp = WriteToMD_AllowAnonymous_FTP(csKeyPath);
  4494. if (dwReturnTemp != ERROR_SUCCESS){dwReturn = dwReturnTemp;}
  4495. dwReturnTemp = WriteToMD_AnonymousOnly_FTP(csKeyPath);
  4496. if (dwReturnTemp != ERROR_SUCCESS){dwReturn = dwReturnTemp;}
  4497. WriteToMD_IPsec_GrantByDefault(csKeyPath);
  4498. }
  4499. iisDebugOut_End(_T("HandleSecurityTemplates"),LOG_TYPE_TRACE);
  4500. return dwReturn;
  4501. }
  4502. DWORD WriteToMD_IPsec_GrantByDefault(CString csKeyPath)
  4503. {
  4504. DWORD dwReturn = ERROR_SUCCESS;
  4505. MDEntry stMDEntry;
  4506. // LM/MSFTPSVC
  4507. // LM/W3SVC
  4508. // cmdKey.SetData(MD_IP_SEC,METADATA_INHERIT | METADATA_REFERENCE,IIS_MD_UT_FILE,BINARY_METADATA,acCheck.GetStorage()->GetUsed(),(acCheck.GetStorage()->GetAlloc()? acCheck.GetStorage()->GetAlloc() : (LPBYTE)""));
  4509. stMDEntry.szMDPath = (LPTSTR)(LPCTSTR)csKeyPath;
  4510. stMDEntry.dwMDIdentifier = MD_IP_SEC;
  4511. stMDEntry.dwMDAttributes = METADATA_INHERIT | METADATA_REFERENCE;
  4512. stMDEntry.dwMDUserType = IIS_MD_UT_FILE;
  4513. stMDEntry.dwMDDataType = BINARY_METADATA;
  4514. stMDEntry.dwMDDataLen = 0;
  4515. stMDEntry.pbMDData = (LPBYTE)"";
  4516. // we know we are tryint to write nothing, so make sure
  4517. // we don't try to retrieve nothing from it.
  4518. //int iBeforeValue = FALSE;
  4519. //iBeforeValue = g_CheckIfMetabaseValueWasWritten;
  4520. //g_CheckIfMetabaseValueWasWritten = FALSE;
  4521. dwReturn = SetMDEntry(&stMDEntry);
  4522. // Set the flag back after calling the function
  4523. //g_CheckIfMetabaseValueWasWritten = iBeforeValue;
  4524. return dwReturn;
  4525. }
  4526. DWORD WriteToMD_HttpExpires(CString csData)
  4527. {
  4528. DWORD dwReturnTemp = ERROR_SUCCESS;
  4529. DWORD dwReturn = ERROR_SUCCESS;
  4530. MDEntry stMDEntry;
  4531. stMDEntry.szMDPath = _T("LM/W3SVC");
  4532. stMDEntry.dwMDIdentifier = MD_HTTP_EXPIRES;
  4533. stMDEntry.dwMDAttributes = METADATA_INHERIT;
  4534. stMDEntry.dwMDUserType = IIS_MD_UT_FILE;
  4535. stMDEntry.dwMDDataType = STRING_METADATA;
  4536. stMDEntry.dwMDDataLen = (csData.GetLength() + 1) * sizeof(TCHAR);
  4537. stMDEntry.pbMDData = (LPBYTE)(LPCTSTR)csData;
  4538. dwReturnTemp = SetMDEntry_Wrap(&stMDEntry);
  4539. if (dwReturnTemp != ERROR_SUCCESS){dwReturn = dwReturnTemp;}
  4540. return dwReturn;
  4541. }
  4542. DWORD WriteToMD_AllowAnonymous_FTP(CString csKeyPath)
  4543. {
  4544. DWORD dwReturn = ERROR_SUCCESS;
  4545. MDEntry stMDEntry;
  4546. DWORD dwData = 0;
  4547. stMDEntry.szMDPath = (LPTSTR)(LPCTSTR)csKeyPath;
  4548. stMDEntry.dwMDIdentifier = MD_ALLOW_ANONYMOUS;
  4549. stMDEntry.dwMDAttributes = METADATA_INHERIT;
  4550. stMDEntry.dwMDUserType = IIS_MD_UT_SERVER;
  4551. stMDEntry.dwMDDataType = DWORD_METADATA;
  4552. stMDEntry.dwMDDataLen = sizeof(DWORD);
  4553. dwData = 0x1;
  4554. stMDEntry.pbMDData = (LPBYTE)&dwData;
  4555. dwReturn = SetMDEntry(&stMDEntry);
  4556. return dwReturn;
  4557. }
  4558. DWORD WriteToMD_AnonymousOnly_FTP(CString csKeyPath)
  4559. {
  4560. DWORD dwReturn = ERROR_SUCCESS;
  4561. MDEntry stMDEntry;
  4562. DWORD dwData = 0;
  4563. stMDEntry.szMDPath = (LPTSTR)(LPCTSTR)csKeyPath;
  4564. stMDEntry.dwMDIdentifier = MD_ANONYMOUS_ONLY;
  4565. stMDEntry.dwMDAttributes = METADATA_INHERIT;
  4566. stMDEntry.dwMDUserType = IIS_MD_UT_SERVER;
  4567. stMDEntry.dwMDDataType = DWORD_METADATA;
  4568. stMDEntry.dwMDDataLen = sizeof(DWORD);
  4569. dwData = 0x1;
  4570. stMDEntry.pbMDData = (LPBYTE)&dwData;
  4571. dwReturn = SetMDEntry(&stMDEntry);
  4572. return dwReturn;
  4573. }
  4574. DWORD WriteToMD_IWamUserName_WWW(void)
  4575. {
  4576. DWORD dwReturnTemp = ERROR_SUCCESS;
  4577. DWORD dwReturn = ERROR_SUCCESS;
  4578. CMDKey cmdKey;
  4579. MDEntry stMDEntry;
  4580. MDEntry stMDEntry_Pass;
  4581. // the username
  4582. stMDEntry.szMDPath = _T("LM/W3SVC");
  4583. stMDEntry.dwMDIdentifier = MD_WAM_USER_NAME;
  4584. stMDEntry.dwMDAttributes = METADATA_INHERIT;
  4585. stMDEntry.dwMDUserType = IIS_MD_UT_FILE;
  4586. stMDEntry.dwMDDataType = STRING_METADATA;
  4587. stMDEntry.dwMDDataLen = (g_pTheApp->m_csWAMAccountName.GetLength() + 1) * sizeof(TCHAR);
  4588. stMDEntry.pbMDData = (LPBYTE)(LPCTSTR) g_pTheApp->m_csWAMAccountName;
  4589. // the password
  4590. stMDEntry_Pass.szMDPath = _T("LM/W3SVC");
  4591. stMDEntry_Pass.dwMDIdentifier = MD_WAM_PWD;
  4592. stMDEntry_Pass.dwMDAttributes = METADATA_INHERIT | METADATA_SECURE;
  4593. stMDEntry_Pass.dwMDUserType = IIS_MD_UT_FILE;
  4594. stMDEntry_Pass.dwMDDataType = STRING_METADATA;
  4595. stMDEntry_Pass.dwMDDataLen = (g_pTheApp->m_csWAMAccountPassword.GetLength() + 1) * sizeof(TCHAR);
  4596. stMDEntry_Pass.pbMDData = (LPBYTE)(LPCTSTR) g_pTheApp->m_csWAMAccountPassword;
  4597. // make sure and delete it first
  4598. // DeleteMDEntry(&stMDEntry_Pass);
  4599. // --------------------------------------------------
  4600. // always overwrite, we may have changed the password
  4601. // important: Set the username and the password on a single open and close!
  4602. // --------------------------------------------------
  4603. cmdKey.CreateNode(METADATA_MASTER_ROOT_HANDLE, (LPCTSTR)stMDEntry.szMDPath);
  4604. if ( (METADATA_HANDLE) cmdKey )
  4605. {
  4606. dwReturnTemp = ERROR_SUCCESS;
  4607. dwReturnTemp = cmdKey.SetData(stMDEntry.dwMDIdentifier,stMDEntry.dwMDAttributes,stMDEntry.dwMDUserType,stMDEntry.dwMDDataType,stMDEntry.dwMDDataLen,stMDEntry.pbMDData);
  4608. if (FAILED(dwReturnTemp))
  4609. {
  4610. SetErrorFlag(__FILE__, __LINE__);
  4611. iisDebugOut((LOG_TYPE_ERROR, _T("SetMDEntry:SetData(%d), FAILED. Code=0x%x.End.\n"), stMDEntry.dwMDIdentifier, dwReturnTemp));
  4612. dwReturn = dwReturnTemp;
  4613. }
  4614. dwReturnTemp = ERROR_SUCCESS;
  4615. dwReturnTemp = cmdKey.SetData(stMDEntry_Pass.dwMDIdentifier,stMDEntry_Pass.dwMDAttributes,stMDEntry_Pass.dwMDUserType,stMDEntry_Pass.dwMDDataType,stMDEntry_Pass.dwMDDataLen,stMDEntry_Pass.pbMDData);
  4616. if (FAILED(dwReturnTemp))
  4617. {
  4618. SetErrorFlag(__FILE__, __LINE__);
  4619. iisDebugOut((LOG_TYPE_ERROR, _T("SetMDEntry:SetData(%d), FAILED. Code=0x%x.End.\n"), stMDEntry_Pass.dwMDIdentifier, dwReturnTemp));
  4620. dwReturn = dwReturnTemp;
  4621. }
  4622. cmdKey.Close();
  4623. }
  4624. return dwReturn;
  4625. }
  4626. // loop thru the custom errors and make sure they point to the right place
  4627. BOOL VerifyCustomErrors_WWW(CString csKeyPath)
  4628. {
  4629. CMDKey cmdKey;
  4630. PVOID pData = NULL;
  4631. BOOL bReturn = FALSE;
  4632. CString csOneBlobEntry;
  4633. TCHAR szOneBlobEntry2[_MAX_PATH + 20];
  4634. CString csCustomErrorEntry;
  4635. int c = 0;
  4636. int iCustomErrorEntryCount = 0;
  4637. int iCustomErrorUpdatedCount = 0;
  4638. int iPleaseCloseTheMetabase = FALSE;
  4639. TCHAR szDrive_only[_MAX_DRIVE];
  4640. TCHAR szPath_only[_MAX_PATH];
  4641. TCHAR szPath_only2[_MAX_PATH];
  4642. TCHAR szFilename_only[_MAX_PATH];
  4643. TCHAR szFilename_ext_only[_MAX_EXT];
  4644. DWORD dwAttr;
  4645. DWORD dwUType;
  4646. DWORD dwDType;
  4647. DWORD dwLength;
  4648. TCHAR* pBlobEntry = NULL;
  4649. DWORD cbBuffer = 0;
  4650. // open the key
  4651. cmdKey.OpenNode(csKeyPath);
  4652. // test for success.
  4653. if ( (METADATA_HANDLE)cmdKey == NULL )
  4654. {
  4655. // if could not open the key maybe there is nothing there.
  4656. goto VerifyCustomErrors_WWW_Exit;
  4657. }
  4658. iPleaseCloseTheMetabase = TRUE;
  4659. dwAttr = METADATA_INHERIT;
  4660. dwUType = IIS_MD_UT_FILE;
  4661. dwDType = MULTISZ_METADATA;
  4662. dwLength = 0;
  4663. // we need to start this process by getting the existing multisz data from the metabase
  4664. // first, figure out how much memory we will need to do this
  4665. // make sure METADATA_INHERIT is NOT set!
  4666. // otherwise becaues the entry exists at the root, we'll always get it.
  4667. cmdKey.GetData(MD_CUSTOM_ERROR,&dwAttr,&dwUType,&dwDType,&dwLength,NULL,0,METADATA_NO_ATTRIBUTES,IIS_MD_UT_FILE,MULTISZ_METADATA);
  4668. // unfortunatly, the above routine only returns TRUE or FALSE. And since we are purposefully
  4669. // passing in a null ponter of 0 size in order to get the length of the data, it will always
  4670. // return 0 whether it was because the metabase is inacessable, or there pointer was NULL,
  4671. // which it is. So - I guess we assume it worked, allocate the buffer and attempt to read it
  4672. // in again.
  4673. cbBuffer = dwLength;
  4674. // allocate the space, if it fails, we fail
  4675. // note that GPTR causes it to be initialized to zero
  4676. pData = GlobalAlloc( GPTR, cbBuffer );
  4677. if ( !pData )
  4678. {
  4679. iisDebugOut((LOG_TYPE_ERROR, _T("VerifyCustomErrors_WWW.1.Failed to allocate memory.\n")));
  4680. goto VerifyCustomErrors_WWW_Exit;
  4681. }
  4682. pBlobEntry = (TCHAR*)pData;
  4683. // now get the data from the metabase
  4684. iCustomErrorEntryCount = 0;
  4685. bReturn = cmdKey.GetData(MD_CUSTOM_ERROR,&dwAttr,&dwUType,&dwDType,&dwLength,(PUCHAR)pData,cbBuffer,METADATA_NO_ATTRIBUTES,IIS_MD_UT_FILE,MULTISZ_METADATA );
  4686. // loop thru this list and add it to our array of entries.
  4687. if (bReturn)
  4688. {
  4689. // got the entry, scan them now - pBlobEntry will be pointing at the second end \0
  4690. // when it is time to exit the loop.
  4691. csCustomErrorEntry = _T("");
  4692. while ( *pBlobEntry )
  4693. {
  4694. csOneBlobEntry = pBlobEntry;
  4695. _tcscpy(szOneBlobEntry2, csOneBlobEntry);
  4696. // Grab the blob entry and make sure that it points to the new location.
  4697. //"500,15,FILE,D:\WINNT\help\iisHelp\common\500-15.htm"
  4698. //"500,100,URL,/iisHelp/common/500-100.asp"
  4699. if ( SplitLineCommaDelimited(szOneBlobEntry2, 4) )
  4700. {
  4701. // Check if this is for a file type:
  4702. if (_tcsicmp(g_field[2], _T("FILE")) == 0)
  4703. {
  4704. // Get the filename
  4705. // Trim off the filename and return only the path
  4706. _tsplitpath( g_field[3], szDrive_only, szPath_only, szFilename_only, szFilename_ext_only);
  4707. // Check if the path points to the old place...
  4708. CString csFilePath;
  4709. csFilePath.Format(_T("%s\\help\\common\\file"), g_pTheApp->m_csWinDir);
  4710. _tsplitpath( csFilePath, NULL, szPath_only2, NULL, NULL);
  4711. if (_tcsicmp(szPath_only, szPath_only2) == 0)
  4712. {
  4713. // yes, it points to the old place.
  4714. // let's see if it exists in the new place first....
  4715. CString csFilePathNew;
  4716. csFilePathNew.Format(_T("%s\\help\\iishelp\\common"), g_pTheApp->m_csWinDir);
  4717. csFilePath.Format(_T("%s\\%s%s"), csFilePathNew, szFilename_only, szFilename_ext_only);
  4718. if (IsFileExist(csFilePath))
  4719. {
  4720. // yes, it does, then let's replace it.
  4721. csOneBlobEntry.Format(_T("%s,%s,%s,%s\\%s%s"), g_field[0], g_field[1], g_field[2], csFilePathNew, szFilename_only, szFilename_ext_only);
  4722. iCustomErrorUpdatedCount++;
  4723. }
  4724. else
  4725. {
  4726. // no it does not exist...
  4727. // see if there is a *.bak file with that name...
  4728. CString csFilePath2;
  4729. csFilePath2 = csFilePath;
  4730. csFilePath2 += _T(".bak");
  4731. if (IsFileExist(csFilePath2))
  4732. {
  4733. // yes, it does, then let's replace it.
  4734. csOneBlobEntry.Format(_T("%s,%s,%s,%s\\%s%s.bak"), g_field[0], g_field[1], g_field[2], csFilePathNew, szFilename_only, szFilename_ext_only);
  4735. iCustomErrorUpdatedCount++;
  4736. }
  4737. else
  4738. {
  4739. // They must be pointing to some other file which we don't have.
  4740. // let's try to copy the old file from the old directory...
  4741. TCHAR szNewFileName[_MAX_PATH];
  4742. // rename file to *.bak and move it to the new location..
  4743. _stprintf(szNewFileName, _T("%s\\%s%s"), csFilePathNew, szFilename_only, szFilename_ext_only);
  4744. // move it
  4745. if (IsFileExist(csFilePath))
  4746. {
  4747. if (MoveFileEx( g_field[3], szNewFileName, MOVEFILE_COPY_ALLOWED|MOVEFILE_WRITE_THROUGH|MOVEFILE_REPLACE_EXISTING))
  4748. {
  4749. // yes, it does, then let's replace it.
  4750. csOneBlobEntry.Format(_T("%s,%s,%s,%s"), g_field[0], g_field[1], g_field[2], szNewFileName);
  4751. iCustomErrorUpdatedCount++;
  4752. }
  4753. }
  4754. else
  4755. {
  4756. // Check if the file was renamed...
  4757. TCHAR szNewFileName[_MAX_PATH];
  4758. // rename file to *.bak and move it to the new location..
  4759. _stprintf(szNewFileName, _T("%s\\%s%s.bak"), csFilePathNew, szFilename_only, szFilename_ext_only);
  4760. // yes, it does, then let's replace it.
  4761. if (IsFileExist(szNewFileName))
  4762. {
  4763. csOneBlobEntry.Format(_T("%s,%s,%s,%s"), g_field[0], g_field[1], g_field[2], szNewFileName);
  4764. iCustomErrorUpdatedCount++;
  4765. }
  4766. else
  4767. {
  4768. // they must be pointing to some other file which we don't install.
  4769. // so don't change this entry...
  4770. }
  4771. }
  4772. }
  4773. }
  4774. }
  4775. }
  4776. }
  4777. else
  4778. {
  4779. // failed to split the line
  4780. SetErrorFlag(__FILE__, __LINE__);
  4781. iisDebugOut((LOG_TYPE_ERROR, _T("FAILED: Unable to split upgrade error INF line - %s"), szOneBlobEntry2));
  4782. }
  4783. // append on the "|" which we'll convert to a null later
  4784. csCustomErrorEntry += csOneBlobEntry + _T("|");
  4785. iCustomErrorEntryCount++;
  4786. // increment pBlobEntry to the next string
  4787. pBlobEntry = _tcsninc( pBlobEntry, _tcslen(pBlobEntry))+1;
  4788. }
  4789. // add the terminating second "|" character
  4790. csCustomErrorEntry +=_T("|");
  4791. }
  4792. // close the handle to the metabase so that we can
  4793. // open it to write the stuff out later!
  4794. cmdKey.Close();
  4795. iPleaseCloseTheMetabase = FALSE;
  4796. // If we added any new entries to the metabase
  4797. // the let's write out the new block of data, otherwise let's get out.
  4798. if (iCustomErrorUpdatedCount > 0)
  4799. {
  4800. WriteToMD_CustomError_Entry(csKeyPath,csCustomErrorEntry);
  4801. }
  4802. VerifyCustomErrors_WWW_Exit:
  4803. // close the key
  4804. if (TRUE == iPleaseCloseTheMetabase){cmdKey.Close();}
  4805. if (pData){GlobalFree(pData);pData=NULL;}
  4806. // the only time it should return FALSE is if it can't open the key
  4807. return TRUE;
  4808. }
  4809. /*
  4810. "400,*,FILE,D:\WINNT\help\common\400.htm"
  4811. "401,1,FILE,D:\WINNT\help\common\401-1.htm"
  4812. "401,2,FILE,D:\WINNT\help\common\401-2.htm"
  4813. "401,3,FILE,D:\WINNT\help\common\401-3.htm"
  4814. "401,4,FILE,D:\WINNT\help\common\401-4.htm"
  4815. "401,5,FILE,D:\WINNT\help\common\401-5.htm"
  4816. "403,1,FILE,D:\WINNT\help\common\403-1.htm"
  4817. "403,2,FILE,D:\WINNT\help\common\403-2.htm"
  4818. "403,3,FILE,D:\WINNT\help\common\403-3.htm"
  4819. "403,4,FILE,D:\WINNT\help\common\403-4.htm"
  4820. "403,5,FILE,D:\WINNT\help\common\403-5.htm"
  4821. "403,6,FILE,D:\WINNT\help\common\403-6.htm"
  4822. "403,7,FILE,D:\WINNT\help\common\403-7.htm"
  4823. "403,8,FILE,D:\WINNT\help\common\403-8.htm"
  4824. "403,9,FILE,D:\WINNT\help\common\403-9.htm"
  4825. "403,10,FILE,D:\WINNT\help\common\403-10.htm"
  4826. "403,11,FILE,D:\WINNT\help\common\403-11.htm"
  4827. "403,12,FILE,D:\WINNT\help\common\403-12.htm"
  4828. "404,*,FILE,D:\WINNT\help\common\404b.htm"
  4829. "405,*,FILE,D:\WINNT\help\common\405.htm"
  4830. "406,*,FILE,D:\WINNT\help\common\406.htm"
  4831. "407,*,FILE,D:\WINNT\help\common\407.htm"
  4832. "412,*,FILE,D:\WINNT\help\common\412.htm"
  4833. "414,*,FILE,D:\WINNT\help\common\414.htm"
  4834. "403,13,FILE,D:\WINNT\help\iisHelp\common\403-13.htm"
  4835. "403,15,FILE,D:\WINNT\help\iisHelp\common\403-15.htm"
  4836. "403,16,FILE,D:\WINNT\help\iisHelp\common\403-16.htm"
  4837. "403,17,FILE,D:\WINNT\help\iisHelp\common\403-17.htm"
  4838. "500,12,FILE,D:\WINNT\help\iisHelp\common\500-12.htm"
  4839. "500,13,FILE,D:\WINNT\help\iisHelp\common\500-13.htm"
  4840. "500,15,FILE,D:\WINNT\help\iisHelp\common\500-15.htm"
  4841. "500,100,URL,/iisHelp/common/500-100.asp"
  4842. */
  4843. DWORD WriteToMD_CustomError_Entry(CString csKeyPath, CString csCustomErrorDelimitedList)
  4844. {
  4845. DWORD dwReturn = ERROR_SUCCESS;
  4846. DWORD dwReturnTemp = ERROR_SUCCESS;
  4847. MDEntry stMDEntry;
  4848. HGLOBAL hBlock = NULL;
  4849. int nCustomErrorLength;
  4850. nCustomErrorLength = csCustomErrorDelimitedList.GetLength() * sizeof(TCHAR);
  4851. hBlock = GlobalAlloc(GPTR, nCustomErrorLength + sizeof(TCHAR));
  4852. if (!hBlock)
  4853. {
  4854. iisDebugOut((LOG_TYPE_ERROR, _T("WriteToMD_CustomError_Entry.Failed to allocate memory.\n")));
  4855. return ERROR_OUTOFMEMORY;
  4856. }
  4857. TCHAR *p = (LPTSTR)hBlock;
  4858. memcpy((LPVOID)hBlock, (LPVOID)(LPCTSTR)csCustomErrorDelimitedList, nCustomErrorLength + sizeof(TCHAR));
  4859. // replace all '|' which a null
  4860. while (*p)
  4861. {
  4862. if (*p == _T('|'))
  4863. {
  4864. *p = _T('\0');
  4865. }
  4866. p = _tcsinc(p);
  4867. }
  4868. // write the new errors list back out to the metabase
  4869. stMDEntry.szMDPath = (LPTSTR)(LPCTSTR)csKeyPath;
  4870. stMDEntry.dwMDIdentifier = MD_CUSTOM_ERROR;
  4871. stMDEntry.dwMDAttributes = METADATA_INHERIT;
  4872. stMDEntry.dwMDUserType = IIS_MD_UT_FILE;
  4873. stMDEntry.dwMDDataType = MULTISZ_METADATA;
  4874. stMDEntry.dwMDDataLen = nCustomErrorLength;
  4875. stMDEntry.pbMDData = (LPBYTE)hBlock;
  4876. dwReturnTemp = SetMDEntry(&stMDEntry);
  4877. if (dwReturnTemp != ERROR_SUCCESS){dwReturn = dwReturnTemp;}
  4878. if (hBlock){GlobalFree(hBlock);hBlock=NULL;}
  4879. return dwReturn;
  4880. }
  4881. void MoveOldHelpFilesToNewLocation(void)
  4882. {
  4883. HANDLE hFile = INVALID_HANDLE_VALUE;
  4884. WIN32_FIND_DATA FindFileData;
  4885. TCHAR szDirNameTemp[_MAX_PATH];
  4886. TSTR_PATH strTempHelpHTMFilesDir1;
  4887. TSTR_PATH strTempHelpHTMFilesDir2;
  4888. if ( !strTempHelpHTMFilesDir1.RetrieveWindowsDir() ||
  4889. !strTempHelpHTMFilesDir1.PathAppend( _T("help\\common") ) ||
  4890. !strTempHelpHTMFilesDir2.RetrieveWindowsDir() ||
  4891. !strTempHelpHTMFilesDir2.PathAppend( _T("help\\iishelp\\common") ) )
  4892. {
  4893. return;
  4894. }
  4895. // Check if the old directory exists...
  4896. if (!IsFileExist( strTempHelpHTMFilesDir1.QueryStr() ))
  4897. {
  4898. return;
  4899. }
  4900. // The old directory does exist..
  4901. // let's rename all the files to *.bak, then move them over.
  4902. // *.htm to *.htm.bak
  4903. // *.asp to *.asp.bak
  4904. // *.asa to *.asa.bak
  4905. // *.inc to *.inc.bak
  4906. //
  4907. // 1st let's delete any *.bak files they may already have...
  4908. //DeleteFilesWildcard(szTempHelpHTMFilesDir1, _T("*.bak"));
  4909. // ok, this is a directory,
  4910. // so tack on the *.* deal
  4911. _stprintf(szDirNameTemp, _T("%s\\*.*"), strTempHelpHTMFilesDir1.QueryStr() );
  4912. hFile = FindFirstFile(szDirNameTemp, &FindFileData);
  4913. if (hFile != INVALID_HANDLE_VALUE)
  4914. {
  4915. do {
  4916. if ( _tcsicmp(FindFileData.cFileName, _T(".")) != 0 && _tcsicmp(FindFileData.cFileName, _T("..")) != 0 )
  4917. {
  4918. if (FindFileData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
  4919. {
  4920. // this is a directory, so let's skip it
  4921. }
  4922. else
  4923. {
  4924. // this is a file, let's check if it's one of the ones we care about.
  4925. TCHAR szFilename_ext_only[_MAX_EXT];
  4926. _tsplitpath( FindFileData.cFileName, NULL, NULL, NULL, szFilename_ext_only);
  4927. int iYesFlag = FALSE;
  4928. if (szFilename_ext_only)
  4929. {
  4930. if ( _tcsicmp(szFilename_ext_only, _T(".htm")) == 0) {iYesFlag = TRUE;}
  4931. if ( _tcsicmp(szFilename_ext_only, _T(".html")) == 0) {iYesFlag = TRUE;}
  4932. if ( _tcsicmp(szFilename_ext_only, _T(".asp")) == 0) {iYesFlag = TRUE;}
  4933. if ( _tcsicmp(szFilename_ext_only, _T(".asa")) == 0) {iYesFlag = TRUE;}
  4934. if ( _tcsicmp(szFilename_ext_only, _T(".inc")) == 0) {iYesFlag = TRUE;}
  4935. if (TRUE == iYesFlag)
  4936. {
  4937. TCHAR szOldFileName[_MAX_PATH];
  4938. TCHAR szNewFileName[_MAX_PATH];
  4939. // rename to filename.*.bak
  4940. _stprintf(szOldFileName, _T("%s\\%s"), strTempHelpHTMFilesDir1.QueryStr(), FindFileData.cFileName);
  4941. // rename file to *.bak and move it to the new location..
  4942. _stprintf(szNewFileName, _T("%s\\%s.bak"), strTempHelpHTMFilesDir2.QueryStr() , FindFileData.cFileName);
  4943. // move it
  4944. MoveFileEx( szOldFileName, szNewFileName, MOVEFILE_COPY_ALLOWED|MOVEFILE_WRITE_THROUGH|MOVEFILE_REPLACE_EXISTING);
  4945. }
  4946. }
  4947. }
  4948. }
  4949. // get the next file
  4950. if ( !FindNextFile(hFile, &FindFileData) )
  4951. {
  4952. FindClose(hFile);
  4953. break;
  4954. }
  4955. } while (TRUE);
  4956. }
  4957. return;
  4958. }
  4959. void WriteToMD_ForceMetabaseToWriteToDisk(void)
  4960. {
  4961. if (CheckifServiceExist(_T("IISADMIN")) == 0 )
  4962. {
  4963. CMDKey cmdKey;
  4964. cmdKey.ForceWriteMetabaseToDisk();
  4965. //cmdKey.OpenNode(_T("/"));
  4966. //if ( (METADATA_HANDLE)cmdKey )
  4967. //{
  4968. // cmdKey.ForceWriteMetabaseToDisk();
  4969. // cmdKey.Close();
  4970. //}
  4971. }
  4972. return;
  4973. }
  4974. DWORD WriteToMD_DefaultLoadFile(CString csKeyPath,CString csData)
  4975. {
  4976. DWORD dwReturnTemp = ERROR_SUCCESS;
  4977. DWORD dwReturn = ERROR_SUCCESS;
  4978. MDEntry stMDEntry;
  4979. //stMDEntry.szMDPath = _T("LM/W3SVC");
  4980. stMDEntry.szMDPath = (LPTSTR)(LPCTSTR) csKeyPath;
  4981. stMDEntry.dwMDIdentifier = MD_DEFAULT_LOAD_FILE;
  4982. stMDEntry.dwMDAttributes = METADATA_INHERIT;
  4983. stMDEntry.dwMDUserType = IIS_MD_UT_FILE;
  4984. stMDEntry.dwMDDataType = STRING_METADATA;
  4985. stMDEntry.dwMDDataLen = (csData.GetLength() + 1) * sizeof(TCHAR);
  4986. stMDEntry.pbMDData = (LPBYTE)(LPCTSTR)csData;
  4987. dwReturnTemp = SetMDEntry(&stMDEntry);
  4988. if (dwReturnTemp != ERROR_SUCCESS){dwReturn = dwReturnTemp;}
  4989. return dwReturn;
  4990. }
  4991. //
  4992. // Returns the amount of entries that we added.
  4993. //
  4994. int AddRequiredDefaultLoad(CStringArray& arrayName,IN LPCTSTR szSection)
  4995. {
  4996. int c = 0;
  4997. CStringList strList;
  4998. TSTR strTheSection;
  4999. if ( strTheSection.Copy( szSection ) &&
  5000. GetSectionNameToDo(g_pTheApp->m_hInfHandle, &strTheSection)
  5001. )
  5002. {
  5003. if (ERROR_SUCCESS == FillStrListWithListOfSections(g_pTheApp->m_hInfHandle, strList, strTheSection.QueryStr() ))
  5004. {
  5005. // loop thru the list returned back
  5006. if (strList.IsEmpty() == FALSE)
  5007. {
  5008. POSITION pos = NULL;
  5009. CString csEntry;
  5010. pos = strList.GetHeadPosition();
  5011. while (pos)
  5012. {
  5013. csEntry = _T("");
  5014. csEntry = strList.GetAt(pos);
  5015. // Add it to our array...
  5016. // iisDebugOut((LOG_TYPE_TRACE, _T("Add default load Entry:%s:%s\n"),csName, csPath));
  5017. arrayName.Add(csEntry);
  5018. c++;
  5019. strList.GetNext(pos);
  5020. }
  5021. }
  5022. }
  5023. }
  5024. return c;
  5025. }
  5026. void VerifyMD_DefaultLoadFile_WWW(IN LPCTSTR szSection, CString csKeyPath)
  5027. {
  5028. iisDebugOut_Start(_T("VerifyMD_DefaultLoadFile_WWW"), LOG_TYPE_TRACE);
  5029. CMDKey cmdKey;
  5030. BOOL bReturn = FALSE;
  5031. BOOL fAddComma = FALSE;
  5032. int i = 0;
  5033. CStringArray arrayDefaultValues;
  5034. int nArrayItems = 0;
  5035. CString csFinalEntryToWrite;
  5036. int iNewlyAdded_Count = 0;
  5037. // open the key
  5038. // cmdKey.OpenNode(_T("LM/W3SVC"));
  5039. cmdKey.OpenNode(csKeyPath);
  5040. // test for success.
  5041. if ( (METADATA_HANDLE)cmdKey )
  5042. {
  5043. DWORD dwAttr = METADATA_INHERIT;
  5044. DWORD dwUType = IIS_MD_UT_FILE;
  5045. DWORD dwDType = STRING_METADATA;
  5046. DWORD dwLength = 0;
  5047. // we need to start this process by getting the existing multisz data from the metabase
  5048. // first, figure out how much memory we will need to do this
  5049. cmdKey.GetData( MD_DEFAULT_LOAD_FILE,&dwAttr,&dwUType,&dwDType,&dwLength,NULL,0,METADATA_INHERIT,IIS_MD_UT_FILE,STRING_METADATA);
  5050. if (dwLength > 0)
  5051. {
  5052. // now get the real data from the metabase
  5053. bReturn = cmdKey.GetData( MD_DEFAULT_LOAD_FILE,&dwAttr,&dwUType,&dwDType,&dwLength,(PUCHAR)csFinalEntryToWrite.GetBuffer( dwLength ),dwLength,METADATA_INHERIT,IIS_MD_UT_FILE,STRING_METADATA );
  5054. csFinalEntryToWrite.ReleaseBuffer();
  5055. }
  5056. // the data doesn't get written out here, so close the metabase key
  5057. cmdKey.Close();
  5058. // if reading the value from the metabase didn't work, zero out the string
  5059. if ( !bReturn ){csFinalEntryToWrite.Empty();}
  5060. }
  5061. // if there is something in the order string from the upgrade, then we need to start adding commas
  5062. if ( !csFinalEntryToWrite.IsEmpty() )
  5063. {
  5064. fAddComma = TRUE;
  5065. iisDebugOut((LOG_TYPE_TRACE, _T("VerifyMD_DefaultLoadFile_WWW:InitialEntry=%s.\n"),csFinalEntryToWrite));
  5066. }
  5067. else
  5068. {
  5069. iisDebugOut((LOG_TYPE_TRACE, _T("VerifyMD_DefaultLoadFile_WWW:InitialEntry=None.\n")));
  5070. }
  5071. // Add Required Filters to the arrayDefaultValues
  5072. AddRequiredDefaultLoad(arrayDefaultValues, szSection);
  5073. nArrayItems = (int)arrayDefaultValues.GetSize();
  5074. if ( nArrayItems == 0 ) {goto VerifyMD_DefaultLoadFile_WWW_Exit;}
  5075. // now loop thru this list
  5076. // and check if our isapi dll's are in this list.
  5077. // if they are not, then we add them to the end.
  5078. iNewlyAdded_Count = 0;
  5079. for ( i = 0; i < nArrayItems; i++ )
  5080. {
  5081. // if the name in the array is already in the filter order list,
  5082. // then continue to the next one
  5083. if ( csFinalEntryToWrite.Find( arrayDefaultValues[i] ) >= 0 )
  5084. {continue;}
  5085. if (fAddComma == TRUE){csFinalEntryToWrite += _T(",");}
  5086. else{fAddComma = TRUE;}
  5087. // Add this entry to our list!
  5088. csFinalEntryToWrite += arrayDefaultValues[i];
  5089. iNewlyAdded_Count++;
  5090. }
  5091. // If we added any new entries to the metabase
  5092. // the let's write out the new block of data, otherwise let's get out.
  5093. if (iNewlyAdded_Count > 0)
  5094. {
  5095. WriteToMD_DefaultLoadFile(csKeyPath,csFinalEntryToWrite);
  5096. iisDebugOut((LOG_TYPE_TRACE, _T("VerifyMD_DefaultLoadFile_WWW:NewEntry=%s.\n"),csFinalEntryToWrite));
  5097. }
  5098. VerifyMD_DefaultLoadFile_WWW_Exit:
  5099. iisDebugOut_End(_T("VerifyMD_DefaultLoadFile_WWW"),LOG_TYPE_TRACE);
  5100. return;
  5101. }
  5102. INT Register_iis_www_handleScriptMap()
  5103. {
  5104. int iReturn = TRUE;
  5105. HRESULT hRes;
  5106. ACTION_TYPE atWWW = GetSubcompAction(_T("iis_www"),FALSE);
  5107. ScriptMapNode ScriptMapList = {0};
  5108. // make it a sentinel
  5109. ScriptMapList.next = &ScriptMapList;
  5110. ScriptMapList.prev = &ScriptMapList;
  5111. if (atWWW == AT_INSTALL_FRESH || atWWW == AT_INSTALL_REINSTALL)
  5112. {
  5113. GetScriptMapListFromClean(&ScriptMapList, _T("ScriptMaps_CleanList"));
  5114. }
  5115. if (atWWW == AT_INSTALL_UPGRADE)
  5116. {
  5117. switch (g_pTheApp->m_eUpgradeType)
  5118. {
  5119. case UT_50:
  5120. case UT_51:
  5121. case UT_60:
  5122. //GetScriptMapListFromClean(&ScriptMapList, _T("ScriptMaps_CleanList"));
  5123. GetScriptMapListFromMetabase(&ScriptMapList, g_pTheApp->m_eUpgradeType);
  5124. break;
  5125. case UT_40:
  5126. GetScriptMapListFromMetabase(&ScriptMapList, g_pTheApp->m_eUpgradeType);
  5127. break;
  5128. case UT_10_W95:
  5129. case UT_351:
  5130. case UT_10:
  5131. case UT_20:
  5132. case UT_30:
  5133. default:
  5134. GetScriptMapListFromRegistry(&ScriptMapList);
  5135. break;
  5136. }
  5137. }
  5138. WriteScriptMapListToMetabase(&ScriptMapList, _T("LM/W3SVC"), MD_SCRIPTMAPFLAG_SCRIPT);
  5139. if (atWWW == AT_INSTALL_UPGRADE)
  5140. {
  5141. //DumpScriptMapList();
  5142. if ( g_pTheApp->GetUpgradeVersion() <= 4 )
  5143. {
  5144. // only invert the script map verbs if it is from 4.0 or before.
  5145. // The reason is because 4.0 had an exclusion list, NOT inclusion list like 5 and 6
  5146. // invert the script map verbs
  5147. CInvertScriptMaps inverter;
  5148. hRes = inverter.Update( _T("LM/W3SVC") );
  5149. if ( FAILED(hRes) )
  5150. {
  5151. iisDebugOut((LOG_TYPE_ERROR, _T("inverter.Update():FAILED Invert script map verbs =%x.\n"),hRes));
  5152. }
  5153. }
  5154. // fix the IPSec reference bit flags
  5155. CIPSecRefBitAdder refFixer;
  5156. hRes = refFixer.Update( _T("LM/W3SVC") );
  5157. if ( FAILED(hRes) )
  5158. {
  5159. iisDebugOut((LOG_TYPE_ERROR, _T("refFixer.Update(): FAILED Fix IPSEC ref flag =%x.\n"),hRes));
  5160. }
  5161. //DumpScriptMapList();
  5162. }
  5163. //
  5164. // Whack the old Script Map RegKey
  5165. //
  5166. CRegKey regMachine = HKEY_LOCAL_MACHINE;
  5167. CRegKey regWWWParam( REG_WWWPARAMETERS, regMachine );
  5168. if ((HKEY) regWWWParam ) {regWWWParam.DeleteTree(_T("Script Map"));}
  5169. FreeScriptMapList(&ScriptMapList);
  5170. return iReturn;
  5171. }
  5172. int ReOrderFiltersSpecial(int nArrayItems,CStringArray& arrayName,CString& csOrder)
  5173. {
  5174. int bFound = FALSE;
  5175. int i = 0;
  5176. CString csOrderTemp;
  5177. CString csOrderTemp2;
  5178. CStringList cslStringListTemp;
  5179. CString csOneEntry;
  5180. POSITION pos;
  5181. int numInList;
  5182. // make a copy of string we'll be working with
  5183. csOrderTemp = csOrder;
  5184. // scan through the list of filters we want to add/makesureisthere.
  5185. //
  5186. // SPECIAL HANDLING FOR SSPIFILT
  5187. //
  5188. // if we want to add the sspifilt then apply these rules:
  5189. // if sspifilt is on the list then just leave it there.
  5190. // if sspifilt is not on the list then stick it in first position.
  5191. //
  5192. bFound = FALSE;
  5193. for ( i = 0; i < nArrayItems; i++ )
  5194. {
  5195. if (_tcsicmp(arrayName[i], _T("SSPIFILT")) == 0)
  5196. {bFound = TRUE;}
  5197. }
  5198. // we found sspifilt in the value's list that we want to add
  5199. if (bFound)
  5200. {
  5201. csOrderTemp2 = csOrderTemp;
  5202. csOrderTemp2.MakeUpper();
  5203. csOrderTemp2.TrimLeft();
  5204. csOrderTemp2.TrimRight();
  5205. // now check if it's in the existing users list.
  5206. if ( csOrderTemp2.Find( _T("SSPIFILT") ) >= 0 )
  5207. {
  5208. // yes, it's already there. just leave it there.
  5209. }
  5210. else
  5211. {
  5212. // changes csOrderTemp
  5213. AddFilter1ToFirstPosition(csOrderTemp, _T("sspifilt"));
  5214. }
  5215. }
  5216. // SPECIAL HANDLING FOR Compression FILTER
  5217. //
  5218. // if we want to add the Compression filter then apply these rules:
  5219. // if compression is on the list, then just make sure it's after sspifilt. (re-order they're existing loadorder)
  5220. // if compression is not on the list then stick it after sspifilt. (insert it in the existing list)
  5221. //
  5222. bFound = FALSE;
  5223. for ( i = 0; i < nArrayItems; i++ )
  5224. {
  5225. if (_tcsicmp(arrayName[i], _T("COMPRESSION")) == 0)
  5226. {bFound = TRUE;}
  5227. }
  5228. // we found compression in the value's list that we want to add
  5229. if (bFound)
  5230. {
  5231. // now check if it's in the existing users list.
  5232. csOrderTemp2 = csOrderTemp;
  5233. csOrderTemp2.MakeUpper();
  5234. csOrderTemp2.TrimLeft();
  5235. csOrderTemp2.TrimRight();
  5236. if ( csOrderTemp2.Find( _T("COMPRESSION") ) >= 0 )
  5237. {
  5238. // Make sure it's after sspifilt!
  5239. // yucky!
  5240. // 1. check if it's already after sspifilt.
  5241. // a. if it is cool, get out.
  5242. // b. if not then reorder it so that it is
  5243. CString csOrderTemp2 = csOrderTemp;
  5244. csOrderTemp2.MakeUpper();
  5245. csOrderTemp2.TrimLeft();
  5246. csOrderTemp2.TrimRight();
  5247. int numInList1 = csOrderTemp2.Find(_T("COMPRESSION"));
  5248. int numInList2 = csOrderTemp2.Find(_T("SSPIFILT"));
  5249. if (numInList2 != -1)
  5250. {
  5251. if (numInList1 < numInList2)
  5252. {
  5253. // if compression is before sspifilt, then we'll have to remove it
  5254. numInList = ConvertSepLineToStringList(csOrderTemp,cslStringListTemp,_T(","));
  5255. bFound = FALSE;
  5256. pos = cslStringListTemp.GetHeadPosition();
  5257. while (pos)
  5258. {
  5259. csOneEntry = cslStringListTemp.GetAt(pos);
  5260. csOneEntry.TrimLeft();
  5261. csOneEntry.TrimRight();
  5262. // Does this contain sspifilt?
  5263. if (_tcsicmp(csOneEntry, _T("COMPRESSION")) == 0)
  5264. {
  5265. // Here it is, let's delete it.
  5266. if ( NULL != pos )
  5267. {cslStringListTemp.RemoveAt(pos);}
  5268. // break out of the loop
  5269. bFound = TRUE;
  5270. break;
  5271. }
  5272. // get the next one
  5273. cslStringListTemp.GetNext(pos);
  5274. }
  5275. if (bFound)
  5276. {
  5277. // convert the stringlist back into the comma delimited cstring.
  5278. ConvertStringListToSepLine(cslStringListTemp,csOrderTemp,_T(","));
  5279. }
  5280. // loop thru and add Compression after sspifilt
  5281. //it is not in the users list, let's stick it after sspifilt.
  5282. AddFilter1AfterFilter2(csOrderTemp, _T("Compression"), _T("sspifilt"));
  5283. }
  5284. }
  5285. else
  5286. {
  5287. // sspifilt was not found.
  5288. //it is not in the users list, let's stick it in the first position.
  5289. // changes csOrderTemp
  5290. AddFilter1ToFirstPosition(csOrderTemp, _T("sspifilt"));
  5291. }
  5292. }
  5293. else
  5294. {
  5295. // it is not in the users list, let's stick it after sspifilt.
  5296. // check if sspifilt already exists..
  5297. AddFilter1AfterFilter2(csOrderTemp, _T("Compression"), _T("sspifilt"));
  5298. }
  5299. }
  5300. csOrder = csOrderTemp;
  5301. return TRUE;
  5302. }
  5303. void AddFilter1ToFirstPosition(CString& csOrder,LPTSTR szFilter1)
  5304. {
  5305. CString csNewOrder;
  5306. //it is not in the users list, let's stick it in the first position.
  5307. csNewOrder = szFilter1;
  5308. if (!csOrder.IsEmpty())
  5309. {
  5310. csNewOrder += _T(",");
  5311. csNewOrder += csOrder;
  5312. }
  5313. // set it back to csOrderTemp
  5314. csOrder = csNewOrder;
  5315. }
  5316. void AddFilter1AfterFilter2(CString& csOrder,LPTSTR szFilter1,LPTSTR szFilter2)
  5317. {
  5318. int bFound = FALSE;
  5319. CStringList cslStringListTemp;
  5320. CString csOneEntry;
  5321. POSITION pos;
  5322. int numInList;
  5323. CString csOrderTemp;
  5324. CString csNewOrder;
  5325. csOrderTemp = csOrder;
  5326. // we have already determined that filter1 is not in the list
  5327. // add filter1 after filter2.
  5328. // split up the comma delimited csOrder entry into string list.
  5329. numInList = ConvertSepLineToStringList(csOrderTemp,cslStringListTemp,_T(","));
  5330. bFound = FALSE;
  5331. pos = cslStringListTemp.GetHeadPosition();
  5332. while (pos)
  5333. {
  5334. csOneEntry = cslStringListTemp.GetAt(pos);
  5335. csOneEntry.TrimLeft();
  5336. csOneEntry.TrimRight();
  5337. // Does this contain filter#2?
  5338. if (_tcsicmp(csOneEntry, szFilter2) == 0)
  5339. {
  5340. // Here it is, so insert compression after this one...
  5341. cslStringListTemp.InsertAfter(pos, (CString) szFilter1);
  5342. // break out of the loop
  5343. bFound = TRUE;
  5344. break;
  5345. }
  5346. // get the next one
  5347. cslStringListTemp.GetNext(pos);
  5348. }
  5349. if (bFound)
  5350. {
  5351. // convert the stringlist back into the comma delimited cstring.
  5352. ConvertStringListToSepLine(cslStringListTemp,csOrderTemp,_T(","));
  5353. }
  5354. else
  5355. {
  5356. // we didn't find sspifilt,
  5357. //it is not in the users list, let's stick it in the first position.
  5358. csNewOrder = szFilter2;
  5359. csNewOrder += _T(",");
  5360. csNewOrder += szFilter1;
  5361. if (!csOrderTemp.IsEmpty())
  5362. {
  5363. csNewOrder += _T(",");
  5364. csNewOrder += csOrderTemp;
  5365. }
  5366. // set it back to csOrderTemp
  5367. csOrderTemp = csNewOrder;
  5368. }
  5369. csOrder = csOrderTemp;
  5370. return;
  5371. }
  5372. int GetScriptMapAllInclusionVerbs(CString &csTheVerbList)
  5373. {
  5374. int iReturn = FALSE;
  5375. int c = 0;
  5376. CStringArray arrayName;
  5377. CStringList strList;
  5378. TSTR strTheSection;
  5379. if ( strTheSection.Copy( _T("ScriptMaps_All_Included_Verbs") ) &&
  5380. GetSectionNameToDo(g_pTheApp->m_hInfHandle, &strTheSection)
  5381. )
  5382. {
  5383. if (ERROR_SUCCESS == FillStrListWithListOfSections(g_pTheApp->m_hInfHandle, strList, strTheSection.QueryStr() ))
  5384. {
  5385. // loop thru the list returned back
  5386. if (strList.IsEmpty() == FALSE)
  5387. {
  5388. POSITION pos = NULL;
  5389. pos = strList.GetHeadPosition();
  5390. if (pos)
  5391. {
  5392. // Set it to the 1st value in the list and that's all
  5393. csTheVerbList = strList.GetAt(pos);
  5394. iReturn = TRUE;
  5395. }
  5396. }
  5397. }
  5398. }
  5399. return iReturn;
  5400. }
  5401. void GetScriptMapListFromClean(ScriptMapNode *pList, IN LPCTSTR szSection)
  5402. {
  5403. iisDebugOut_Start1(_T("GetScriptMapListFromClean"), (LPTSTR) szSection, LOG_TYPE_TRACE);
  5404. CString csExtention = _T("");
  5405. CString csBinaryPath = _T("");
  5406. CString csVerbs = _T("");
  5407. CStringList strList;
  5408. TSTR strTheSection;
  5409. ScriptMapNode *pNode;
  5410. if ( strTheSection.Copy( szSection ) &&
  5411. GetSectionNameToDo(g_pTheApp->m_hInfHandle, &strTheSection)
  5412. )
  5413. {
  5414. if (ERROR_SUCCESS == FillStrListWithListOfSections(g_pTheApp->m_hInfHandle, strList, strTheSection.QueryStr() ))
  5415. {
  5416. // loop thru the list returned back
  5417. if (strList.IsEmpty() == FALSE)
  5418. {
  5419. int numParts;
  5420. CString csEntry;
  5421. CStringList cslEntryList;
  5422. CString szDelimiter = _T("|");
  5423. CString csTemp;
  5424. DWORD dwFlags;
  5425. POSITION posEntryList;
  5426. POSITION pos = NULL;
  5427. pos = strList.GetHeadPosition();
  5428. while (pos)
  5429. {
  5430. csEntry = _T("");
  5431. csEntry = strList.GetAt(pos);
  5432. // entry should look something like this.
  5433. //.asp|c:\winnt\system32\inetsrv\asp.dll|GET,HEAD,POST,TRACE
  5434. // break into a string list
  5435. numParts = ConvertSepLineToStringList(csEntry,cslEntryList,szDelimiter);
  5436. posEntryList = cslEntryList.FindIndex(0);
  5437. if (NULL != posEntryList)
  5438. {
  5439. csExtention = cslEntryList.GetNext( posEntryList );
  5440. // no whitespace before or after
  5441. csExtention.TrimLeft();
  5442. csExtention.TrimRight();
  5443. }
  5444. if (NULL != posEntryList)
  5445. {
  5446. csBinaryPath = cslEntryList.GetNext( posEntryList );
  5447. // no whitespace before or after
  5448. csBinaryPath.TrimLeft();
  5449. csBinaryPath.TrimRight();
  5450. }
  5451. if (NULL != posEntryList)
  5452. {
  5453. csVerbs = cslEntryList.GetNext( posEntryList );
  5454. // make sure the verb is normalized to capitals and
  5455. // no whitespace before or after
  5456. csVerbs.MakeUpper();
  5457. csVerbs.TrimLeft();
  5458. csVerbs.TrimRight();
  5459. }
  5460. dwFlags = 0;
  5461. // Check to see if there is a additional flag that will be used for the script map.
  5462. if (NULL != posEntryList)
  5463. {
  5464. csTemp = cslEntryList.GetNext( posEntryList );
  5465. // make sure there are no whitespaces before or after
  5466. csTemp.TrimLeft();
  5467. csTemp.TrimRight();
  5468. if (!csTemp.IsEmpty())
  5469. {
  5470. dwFlags = atodw(csTemp.GetBuffer(1));
  5471. }
  5472. }
  5473. // Add this script map to our list.
  5474. if (csExtention && csBinaryPath)
  5475. {
  5476. iisDebugOut((LOG_TYPE_TRACE, _T("GetScriptMapListFromClean(%s).entry=%s|%s|%s.\n"),szSection, csExtention,csBinaryPath,csVerbs));
  5477. pNode = AllocNewScriptMapNode((LPTSTR)(LPCTSTR) csExtention, (LPTSTR)(LPCTSTR) csBinaryPath, MD_SCRIPTMAPFLAG_SCRIPT | dwFlags, (LPTSTR)(LPCTSTR) csVerbs);
  5478. InsertScriptMapList(pList, pNode, TRUE);
  5479. }
  5480. strList.GetNext(pos);
  5481. }
  5482. }
  5483. }
  5484. }
  5485. iisDebugOut_End1(_T("GetScriptMapListFromClean"),szSection,LOG_TYPE_TRACE);
  5486. return;
  5487. }
  5488. DWORD WriteToMD_IDRegistration(CString csKeyPath)
  5489. {
  5490. iisDebugOut_Start1(_T("WriteToMD_IDRegistration"), csKeyPath, LOG_TYPE_TRACE);
  5491. DWORD dwReturn = ERROR_SUCCESS;
  5492. MDEntry stMDEntry;
  5493. TSTR strTheSection;
  5494. CStringList strList;
  5495. TCHAR szData[_MAX_PATH];
  5496. memset( (PVOID)szData, 0, sizeof(szData));
  5497. //_tcscpy(szData, _T("0-65535;Microsoft Reserved|65536-524288;Microsoft IIS Admin Objects Reserved"));
  5498. if ( strTheSection.Copy( _T("IIS_Metabase_IDRegistration") ) &&
  5499. GetSectionNameToDo(g_pTheApp->m_hInfHandle, &strTheSection)
  5500. )
  5501. {
  5502. if (ERROR_SUCCESS == FillStrListWithListOfSections(g_pTheApp->m_hInfHandle, strList, strTheSection.QueryStr() ))
  5503. {
  5504. _tcscpy(szData, _T(""));
  5505. // loop thru the list returned back
  5506. if (strList.IsEmpty() == FALSE)
  5507. {
  5508. int c = 0;
  5509. POSITION pos = NULL;
  5510. CString csEntry;
  5511. pos = strList.GetHeadPosition();
  5512. while (pos)
  5513. {
  5514. csEntry = _T("");
  5515. csEntry = strList.GetAt(pos);
  5516. iisDebugOut((LOG_TYPE_TRACE, _T("WriteToMD_IDRegistration().csEntry=%s.\n"),csEntry));
  5517. // concatenate to our big string
  5518. if (c > 0){_tcscat(szData, _T("|"));}
  5519. _tcscat(szData, csEntry);
  5520. // increment the counter
  5521. c++;
  5522. strList.GetNext(pos);
  5523. }
  5524. }
  5525. }
  5526. }
  5527. if (szData)
  5528. {
  5529. iisDebugOut((LOG_TYPE_TRACE, _T("WriteToMD_IDRegistration().Data=%s.\n"),szData));
  5530. TCHAR *p = (LPTSTR) szData;
  5531. while (*p)
  5532. {
  5533. // replace all '|' with a null
  5534. if (*p == _T('|'))
  5535. {
  5536. iisDebugOut((LOG_TYPE_TRACE, _T("WriteToMD_IDRegistration().Data[...]=%c.\n"),*p));
  5537. *p = _T('\0');
  5538. }
  5539. p = _tcsinc(p);
  5540. }
  5541. stMDEntry.szMDPath = (LPTSTR)(LPCTSTR)csKeyPath;
  5542. stMDEntry.dwMDIdentifier = MD_METADATA_ID_REGISTRATION;
  5543. stMDEntry.dwMDAttributes = METADATA_INHERIT;
  5544. stMDEntry.dwMDUserType = IIS_MD_UT_SERVER;
  5545. stMDEntry.dwMDDataType = MULTISZ_METADATA;
  5546. stMDEntry.dwMDDataLen = GetMultiStrSize(szData) * sizeof(TCHAR);
  5547. stMDEntry.pbMDData = (LPBYTE)szData;
  5548. dwReturn = SetMDEntry_Wrap(&stMDEntry);
  5549. }
  5550. iisDebugOut_End1(_T("WriteToMD_IDRegistration"),csKeyPath,LOG_TYPE_TRACE);
  5551. return dwReturn;
  5552. }
  5553. DWORD WriteToMD_AspCodepage(CString csKeyPath, DWORD dwValue, int iOverWriteAlways)
  5554. {
  5555. DWORD dwReturn = ERROR_SUCCESS;
  5556. MDEntry stMDEntry;
  5557. // LM/W3SVC/2/ROOT
  5558. stMDEntry.szMDPath = (LPTSTR)(LPCTSTR)csKeyPath;
  5559. stMDEntry.dwMDIdentifier = MD_ASP_CODEPAGE;
  5560. stMDEntry.dwMDAttributes = METADATA_INHERIT;
  5561. stMDEntry.dwMDUserType = ASP_MD_UT_APP;
  5562. stMDEntry.dwMDDataType = DWORD_METADATA;
  5563. stMDEntry.dwMDDataLen = sizeof(DWORD);
  5564. stMDEntry.pbMDData = (LPBYTE)&dwValue;
  5565. if (iOverWriteAlways)
  5566. {
  5567. dwReturn = SetMDEntry(&stMDEntry);
  5568. }
  5569. else
  5570. {
  5571. dwReturn = SetMDEntry_NoOverWrite(&stMDEntry);
  5572. }
  5573. iisDebugOut((LOG_TYPE_TRACE, _T("WriteToMD_AspCodepage:%s:%d:%d.\n"),csKeyPath, dwValue, iOverWriteAlways));
  5574. return dwReturn;
  5575. }
  5576. // HttpCustom : [IF] (MULTISZ) "Content-Type: Text/html; Charset=UTF-8"
  5577. DWORD WriteToMD_HttpCustom(CString csKeyPath, CString csData, int iOverWriteAlways)
  5578. {
  5579. DWORD dwReturn = ERROR_SUCCESS;
  5580. MDEntry stMDEntry;
  5581. TCHAR szData[_MAX_PATH];
  5582. memset( (PVOID)szData, 0, sizeof(szData));
  5583. _stprintf(szData, _T("%s"), csData);
  5584. // LM/W3SVC/2/ROOT
  5585. stMDEntry.szMDPath = (LPTSTR)(LPCTSTR)csKeyPath;
  5586. stMDEntry.dwMDIdentifier = MD_HTTP_CUSTOM;
  5587. stMDEntry.dwMDAttributes = METADATA_INHERIT;
  5588. stMDEntry.dwMDUserType = IIS_MD_UT_FILE;
  5589. stMDEntry.dwMDDataType = MULTISZ_METADATA;
  5590. stMDEntry.dwMDDataLen = GetMultiStrSize(szData) * sizeof(TCHAR);
  5591. stMDEntry.pbMDData = (LPBYTE)szData;
  5592. if (iOverWriteAlways)
  5593. {
  5594. dwReturn = SetMDEntry(&stMDEntry);
  5595. }
  5596. else
  5597. {
  5598. dwReturn = SetMDEntry_NoOverWrite(&stMDEntry);
  5599. }
  5600. iisDebugOut((LOG_TYPE_TRACE, _T("WriteToMD_HttpCustom:%s:%s:%d.\n"),csKeyPath, csData, iOverWriteAlways));
  5601. return dwReturn;
  5602. }
  5603. DWORD WriteToMD_EnableParentPaths_WWW(CString csKeyPath, BOOL bEnableFlag)
  5604. {
  5605. DWORD dwReturn = ERROR_SUCCESS;
  5606. MDEntry stMDEntry;
  5607. DWORD dwData = 0;
  5608. stMDEntry.szMDPath = (LPTSTR)(LPCTSTR)csKeyPath;
  5609. stMDEntry.dwMDIdentifier = MD_ASP_ENABLEPARENTPATHS;
  5610. stMDEntry.dwMDAttributes = METADATA_INHERIT;
  5611. stMDEntry.dwMDUserType = ASP_MD_UT_APP;
  5612. stMDEntry.dwMDDataType = DWORD_METADATA;
  5613. stMDEntry.dwMDDataLen = sizeof(DWORD);
  5614. // turn it on
  5615. if (bEnableFlag)
  5616. {
  5617. dwData = 0x1;
  5618. }
  5619. else
  5620. {
  5621. dwData = 0x0;
  5622. }
  5623. stMDEntry.pbMDData = (LPBYTE)&dwData;
  5624. dwReturn = SetMDEntry(&stMDEntry);
  5625. return dwReturn;
  5626. }
  5627. void EnforceMaxConnections(void)
  5628. {
  5629. // if this is not workstation then get out.
  5630. if (g_pTheApp->m_eNTOSType == OT_NTW)
  5631. {
  5632. //iisDebugOut((LOG_TYPE_TRACE, _T("EnforceMaxConnections: Start.\n")));
  5633. HRESULT hRes;
  5634. CEnforceMaxConnection MaxConnectionEnforcer;
  5635. // loop thru the metabase and get all places where MaxConnections is found.
  5636. // if these are larger than 10 then set it to 10.
  5637. iisDebugOut((LOG_TYPE_TRACE, _T("EnforceMaxConnections: Before.\n")));
  5638. hRes = MaxConnectionEnforcer.Update(_T("LM/W3SVC"));
  5639. if (FAILED(hRes))
  5640. {iisDebugOut((LOG_TYPE_WARN, _T("EnforceMaxConnections.Update(LM/W3SVC):FAILED= %x.\n"),hRes));}
  5641. hRes = MaxConnectionEnforcer.Update(_T("LM/MSFTPSVC"));
  5642. if (FAILED(hRes))
  5643. {iisDebugOut((LOG_TYPE_WARN, _T("EnforceMaxConnections.Update(LM/MSFTPSVC):FAILED= %x.\n"),hRes));}
  5644. //iisDebugOut((LOG_TYPE_TRACE, _T("EnforceMaxConnections: End.\n")));
  5645. }
  5646. return;
  5647. }
  5648. DWORD WriteToMD_DwordEntry(CString csKeyPath,DWORD dwID,DWORD dwAttrib,DWORD dwUserType,DWORD dwTheData,INT iOverwriteFlag)
  5649. {
  5650. DWORD dwReturn = ERROR_SUCCESS;
  5651. MDEntry stMDEntry;
  5652. DWORD dwCopyOfTheData = dwTheData;
  5653. stMDEntry.szMDPath = (LPTSTR)(LPCTSTR)csKeyPath;
  5654. stMDEntry.dwMDIdentifier = dwID;
  5655. stMDEntry.dwMDAttributes = dwAttrib;
  5656. stMDEntry.dwMDUserType = dwUserType;
  5657. stMDEntry.dwMDDataType = DWORD_METADATA;
  5658. stMDEntry.dwMDDataLen = sizeof(DWORD);
  5659. stMDEntry.pbMDData = (LPBYTE)&dwCopyOfTheData;
  5660. if (iOverwriteFlag)
  5661. {
  5662. dwReturn = SetMDEntry(&stMDEntry);
  5663. }
  5664. else
  5665. {
  5666. dwReturn = SetMDEntry_NoOverWrite(&stMDEntry);
  5667. }
  5668. return dwReturn;
  5669. }
  5670. #define REASONABLE_TIMEOUT 1000
  5671. HRESULT
  5672. RemoveVirtualDir(
  5673. IMSAdminBase *pIMSAdminBase,
  5674. WCHAR * pwszMetabasePath,
  5675. WCHAR * pwszVDir
  5676. )
  5677. {
  5678. METADATA_HANDLE hMetabase = NULL;
  5679. HRESULT hr = E_FAIL;
  5680. // Attempt to open the virtual dir set on Web server #1 (default server)
  5681. hr = pIMSAdminBase->OpenKey( METADATA_MASTER_ROOT_HANDLE,
  5682. pwszMetabasePath,
  5683. METADATA_PERMISSION_READ | METADATA_PERMISSION_WRITE,
  5684. REASONABLE_TIMEOUT,
  5685. &hMetabase );
  5686. if( FAILED( hr )) {
  5687. iisDebugOut((LOG_TYPE_ERROR, _T("RemoveVirtualDir:FAILED 0x%x\n"),hr));
  5688. return hr;
  5689. }
  5690. // We don't check the return value since the key may already
  5691. // not exist and we could get an error for that reason.
  5692. pIMSAdminBase->DeleteKey( hMetabase, pwszVDir );
  5693. pIMSAdminBase->CloseKey( hMetabase );
  5694. return hr;
  5695. }
  5696. HRESULT
  5697. AddVirtualDir(
  5698. IMSAdminBase *pIMSAdminBase,
  5699. WCHAR * pwszMetabasePath,
  5700. WCHAR * pwszVDir,
  5701. WCHAR * pwszPhysicalPath,
  5702. DWORD dwPermissions,
  5703. INT iApplicationType
  5704. )
  5705. {
  5706. HRESULT hr;
  5707. METADATA_HANDLE hMetabase = NULL; // handle to metabase
  5708. WCHAR szTempPath[MAX_PATH];
  5709. DWORD dwMDRequiredDataLen = 0;
  5710. DWORD dwAccessPerm = 0;
  5711. METADATA_RECORD mr;
  5712. // Attempt to open the virtual dir set on Web server #1 (default server)
  5713. hr = pIMSAdminBase->OpenKey( METADATA_MASTER_ROOT_HANDLE,
  5714. pwszMetabasePath,
  5715. METADATA_PERMISSION_READ | METADATA_PERMISSION_WRITE,
  5716. REASONABLE_TIMEOUT,
  5717. &hMetabase );
  5718. // Create the key if it does not exist.
  5719. if( FAILED( hr )) {goto AddVirtualDir_Exit;}
  5720. mr.dwMDIdentifier = MD_VR_PATH;
  5721. mr.dwMDAttributes = 0;
  5722. mr.dwMDUserType = IIS_MD_UT_FILE;
  5723. mr.dwMDDataType = STRING_METADATA;
  5724. mr.dwMDDataLen = sizeof( szTempPath );
  5725. mr.pbMDData = reinterpret_cast<unsigned char *>(szTempPath);
  5726. // see if MD_VR_PATH exists.
  5727. hr = pIMSAdminBase->GetData( hMetabase, pwszVDir, &mr, &dwMDRequiredDataLen );
  5728. if( FAILED( hr ))
  5729. {
  5730. if( hr == MD_ERROR_DATA_NOT_FOUND || HRESULT_CODE(hr) == ERROR_PATH_NOT_FOUND )
  5731. {
  5732. // Write both the key and the values if GetData() failed with any of the two errors.
  5733. pIMSAdminBase->AddKey( hMetabase, pwszVDir );
  5734. mr.dwMDIdentifier = MD_VR_PATH;
  5735. mr.dwMDAttributes = METADATA_INHERIT;
  5736. mr.dwMDUserType = IIS_MD_UT_FILE;
  5737. mr.dwMDDataType = STRING_METADATA;
  5738. mr.dwMDDataLen = (wcslen(pwszPhysicalPath) + 1) * sizeof(WCHAR);
  5739. mr.pbMDData = reinterpret_cast<unsigned char *>(pwszPhysicalPath);
  5740. // Write MD_VR_PATH value
  5741. hr = pIMSAdminBase->SetData( hMetabase, pwszVDir, &mr );
  5742. }
  5743. }
  5744. // set the key type to say this is a www vdir!
  5745. if(SUCCEEDED(hr))
  5746. {
  5747. PWCHAR szKeyType = IIS_CLASS_WEB_VDIR_W;
  5748. mr.dwMDIdentifier = MD_KEY_TYPE;
  5749. mr.dwMDAttributes = 0; // no need for inheritence
  5750. mr.dwMDUserType = IIS_MD_UT_FILE;
  5751. mr.dwMDDataType = STRING_METADATA;
  5752. mr.dwMDDataLen = (wcslen(szKeyType) + 1) * sizeof(WCHAR);
  5753. mr.pbMDData = reinterpret_cast<unsigned char *>(szKeyType);
  5754. // Write value
  5755. hr = pIMSAdminBase->SetData( hMetabase, pwszVDir, &mr );
  5756. }
  5757. // set access permissions
  5758. if (dwPermissions != -1)
  5759. {
  5760. if(SUCCEEDED(hr))
  5761. {
  5762. dwAccessPerm = dwPermissions;
  5763. mr.dwMDIdentifier = MD_ACCESS_PERM;
  5764. mr.dwMDAttributes = METADATA_INHERIT; // Make it inheritable so all subdirectories will have the same rights.
  5765. mr.dwMDUserType = IIS_MD_UT_FILE;
  5766. mr.dwMDDataType = DWORD_METADATA;
  5767. mr.dwMDDataLen = sizeof(DWORD);
  5768. mr.pbMDData = reinterpret_cast<unsigned char *>(&dwAccessPerm);
  5769. // Write MD_ACCESS_PERM value
  5770. hr = pIMSAdminBase->SetData( hMetabase, pwszVDir, &mr );
  5771. }
  5772. }
  5773. // if all that succeeded, then try to create the application, if they wanted one
  5774. if (iApplicationType != -1)
  5775. {
  5776. if(SUCCEEDED(hr))
  5777. {
  5778. // Create the path
  5779. // create an in process application
  5780. CString csThePath;
  5781. csThePath = pwszMetabasePath;
  5782. csThePath += _T('/');
  5783. csThePath += pwszVDir;
  5784. if (iApplicationType == 1)
  5785. {
  5786. CreateInProc(csThePath, FALSE);
  5787. }
  5788. else
  5789. {
  5790. // create a pooled application
  5791. CreateInProc(csThePath, TRUE);
  5792. }
  5793. }
  5794. }
  5795. pIMSAdminBase->CloseKey( hMetabase );
  5796. AddVirtualDir_Exit:
  5797. if FAILED(hr)
  5798. {iisDebugOut((LOG_TYPE_ERROR, _T("AddVirtualDir:FAILED 0x%x\n"),hr));}
  5799. return hr;
  5800. }
  5801. int RemoveMetabaseFilter(TCHAR * szFilterName, int iRemoveMetabaseNodes)
  5802. {
  5803. iisDebugOut_Start(_T("RemoveMetabaseFilter"),LOG_TYPE_TRACE);
  5804. int iReturn = FALSE;
  5805. CString csOrder;
  5806. CString csLookingFor;
  5807. CMDKey cmdKey;
  5808. // zero out the order string
  5809. csOrder.Empty();
  5810. // open the key to the virtual server, which is what is passed in as a parameter
  5811. cmdKey.OpenNode( _T("LM/W3SVC/Filters") );
  5812. if ( (METADATA_HANDLE)cmdKey )
  5813. {
  5814. BOOL bReturn;
  5815. DWORD dwAttr = METADATA_NO_ATTRIBUTES;
  5816. DWORD dwUType = IIS_MD_UT_SERVER;
  5817. DWORD dwDType = STRING_METADATA;
  5818. DWORD dwLength = 0;
  5819. // we need to start this process by getting the existing multisz data from the metabase
  5820. // first, figure out how much memory we will need to do this
  5821. cmdKey.GetData( MD_FILTER_LOAD_ORDER,&dwAttr,&dwUType,&dwDType,&dwLength,NULL,0,METADATA_NO_ATTRIBUTES,IIS_MD_UT_SERVER,STRING_METADATA);
  5822. // give the buffer some head space
  5823. // dwLength += 2;
  5824. bReturn = FALSE;
  5825. if (dwLength > 0)
  5826. {
  5827. // now get the real data from the metabase
  5828. bReturn = cmdKey.GetData( MD_FILTER_LOAD_ORDER,&dwAttr,&dwUType,&dwDType,&dwLength,(PUCHAR)csOrder.GetBuffer( dwLength ),dwLength,METADATA_NO_ATTRIBUTES,IIS_MD_UT_SERVER,STRING_METADATA );
  5829. csOrder.ReleaseBuffer();
  5830. }
  5831. // the data doesn't get written out here, so close the metabase key
  5832. cmdKey.Close();
  5833. // if reading the value from the metabase didn't work, zero out the string
  5834. if ( !bReturn )
  5835. {csOrder.Empty();}
  5836. }
  5837. // if there is something in the order string from the upgrade
  5838. // then we need to look thru it
  5839. if ( !csOrder.IsEmpty() )
  5840. {
  5841. csOrder.MakeLower();
  5842. csLookingFor = szFilterName;
  5843. csLookingFor.MakeLower();
  5844. if (csOrder.Find(csLookingFor) != -1)
  5845. {
  5846. CStringList cslStringListTemp;
  5847. CString csOneEntry;
  5848. POSITION pos;
  5849. int numInList;
  5850. int bFound;
  5851. numInList = ConvertSepLineToStringList(csOrder,cslStringListTemp,_T(","));
  5852. bFound = FALSE;
  5853. pos = cslStringListTemp.GetHeadPosition();
  5854. while (pos)
  5855. {
  5856. csOneEntry = cslStringListTemp.GetAt(pos);
  5857. csOneEntry.TrimLeft();
  5858. csOneEntry.TrimRight();
  5859. // Does this contain our filter?
  5860. if (_tcsicmp(csOneEntry, szFilterName) == 0)
  5861. {
  5862. // Here it is, let's delete it.
  5863. if ( NULL != pos )
  5864. {
  5865. cslStringListTemp.RemoveAt(pos);
  5866. }
  5867. // break out of the loop
  5868. bFound = TRUE;
  5869. break;
  5870. }
  5871. // get the next one
  5872. cslStringListTemp.GetNext(pos);
  5873. }
  5874. // if we found and deleted it then
  5875. // go and write out the new string!
  5876. if (bFound)
  5877. {
  5878. // convert the stringlist back into the comma delimited cstring.
  5879. ConvertStringListToSepLine(cslStringListTemp,csOrder,_T(","));
  5880. // write it out
  5881. WriteToMD_Filters_List_Entry(csOrder);
  5882. }
  5883. }
  5884. }
  5885. if (iRemoveMetabaseNodes)
  5886. {
  5887. // let's remove the metabase node as well!
  5888. // delete the metabase node.
  5889. if (CheckifServiceExist(_T("IISADMIN")) == 0 )
  5890. {
  5891. cmdKey.OpenNode(_T("LM/W3SVC/Filters"));
  5892. if ( (METADATA_HANDLE)cmdKey )
  5893. {
  5894. cmdKey.DeleteNode(szFilterName);
  5895. cmdKey.Close();
  5896. }
  5897. }
  5898. }
  5899. //RemoveMetabaseFilter_Exit:
  5900. iisDebugOut_End1(_T("RemoveMetabaseFilter"),csOrder,LOG_TYPE_TRACE);
  5901. return iReturn;
  5902. }
  5903. int GetIncompatibleFilters(LPTSTR szTheSection, CStringArray& arrayName,CStringArray& arrayPath)
  5904. {
  5905. int c = 0;
  5906. CString csName = _T("");
  5907. CString csPath = _T("");
  5908. TSTR strTheSection;
  5909. CStringList strList;
  5910. iisDebugOut((LOG_TYPE_TRACE, _T("ProcessFilters:%s\n"),szTheSection));
  5911. if ( strTheSection.Copy( szTheSection ) &&
  5912. GetSectionNameToDo(g_pTheApp->m_hInfHandle, &strTheSection)
  5913. )
  5914. {
  5915. if (ERROR_SUCCESS == FillStrListWithListOfSections(g_pTheApp->m_hInfHandle, strList, strTheSection.QueryStr() ))
  5916. {
  5917. // loop thru the list returned back
  5918. if (strList.IsEmpty() == FALSE)
  5919. {
  5920. POSITION pos = NULL;
  5921. CString csEntry;
  5922. pos = strList.GetHeadPosition();
  5923. while (pos)
  5924. {
  5925. csEntry = _T("");
  5926. csEntry = strList.GetAt(pos);
  5927. // Split into name, and value. look for ","
  5928. int i;
  5929. i = csEntry.ReverseFind(_T(','));
  5930. if (i != -1)
  5931. {
  5932. int len =0;
  5933. len = csEntry.GetLength();
  5934. csPath = csEntry.Right(len - i - 1);
  5935. csName = csEntry.Left(i);
  5936. // Add it to our array...
  5937. arrayName.Add(csName);
  5938. arrayPath.Add(csPath);
  5939. c++;
  5940. }
  5941. else
  5942. {
  5943. // Add it to our array...
  5944. arrayName.Add(csEntry);
  5945. arrayPath.Add(csEntry);
  5946. c++;
  5947. }
  5948. strList.GetNext(pos);
  5949. }
  5950. }
  5951. }
  5952. }
  5953. return c;
  5954. }
  5955. BOOL IsStringInArray(CString csItem, CStringArray &arrayInput)
  5956. {
  5957. BOOL bReturn = FALSE;
  5958. int nArrayItems = (int) arrayInput.GetSize();
  5959. if (nArrayItems <= 0)
  5960. {
  5961. goto IsCStringInArray_Exit;
  5962. }
  5963. // Does this contain our filtername?
  5964. for (int iCount=0; iCount<nArrayItems; iCount++)
  5965. {
  5966. if (_tcsicmp(csItem, arrayInput[iCount]) == 0)
  5967. {
  5968. // we found the entry
  5969. bReturn = TRUE;
  5970. goto IsCStringInArray_Exit;
  5971. }
  5972. }
  5973. bReturn = FALSE;
  5974. IsCStringInArray_Exit:
  5975. return bReturn;
  5976. }
  5977. int RemoveIncompatibleMetabaseFilters(LPTSTR szSectionName,int iRemoveMetabaseNodes)
  5978. {
  5979. DWORD dwReturn = ERROR_SUCCESS;
  5980. CMDKey cmdKey;
  5981. int iBadFiltersCount=0,iCount=0;
  5982. CString csOrder;
  5983. CString csOneEntry;
  5984. CString csRemovedFilters;
  5985. CStringList cslStringListTemp;
  5986. CStringArray arrayName, arrayPath;
  5987. BOOL bFound = FALSE;
  5988. POSITION pos1,pos2 = NULL;
  5989. INT nArrayItems;
  5990. BOOL bReturn = FALSE;
  5991. DWORD dwAttr = METADATA_NO_ATTRIBUTES;
  5992. DWORD dwUType = IIS_MD_UT_SERVER;
  5993. DWORD dwDType = STRING_METADATA;
  5994. DWORD dwLength = 0;
  5995. iisDebugOut_Start(_T("RemoveIncompatibleMetabaseFilters"),LOG_TYPE_TRACE);
  5996. // Add Required Filters to the arrayName
  5997. csOrder.Empty();
  5998. iBadFiltersCount = GetIncompatibleFilters( szSectionName, arrayName, arrayPath);
  5999. nArrayItems = (INT)arrayName.GetSize();
  6000. if (nArrayItems <= 0)
  6001. {
  6002. goto RemoveIncompatibleMetabaseFilters_Exit;
  6003. }
  6004. // open the existing key in the metabase and get that value
  6005. cmdKey.OpenNode( _T("LM/W3SVC/Filters") );
  6006. if ( !(METADATA_HANDLE)cmdKey )
  6007. {
  6008. goto RemoveIncompatibleMetabaseFilters_Exit;
  6009. }
  6010. // we need to start this process by getting the existing multisz data from the metabase
  6011. // first, figure out how much memory we will need to do this
  6012. cmdKey.GetData( MD_FILTER_LOAD_ORDER,&dwAttr,&dwUType,&dwDType,&dwLength,NULL,0,METADATA_NO_ATTRIBUTES,IIS_MD_UT_SERVER,STRING_METADATA);
  6013. bReturn = FALSE;
  6014. if (dwLength > 0)
  6015. {
  6016. // now get the real data from the metabase
  6017. bReturn = cmdKey.GetData( MD_FILTER_LOAD_ORDER,&dwAttr,&dwUType,&dwDType,&dwLength,(PUCHAR)csOrder.GetBuffer( dwLength ),dwLength,METADATA_NO_ATTRIBUTES,IIS_MD_UT_SERVER,STRING_METADATA );
  6018. csOrder.ReleaseBuffer();
  6019. }
  6020. cmdKey.Close();
  6021. if ( !bReturn )
  6022. {
  6023. csOrder.Empty();
  6024. goto RemoveIncompatibleMetabaseFilters_Exit;
  6025. }
  6026. // if there is nothing in order then get out
  6027. if ( csOrder.IsEmpty() )
  6028. {
  6029. goto RemoveIncompatibleMetabaseFilters_Exit;
  6030. }
  6031. // split up the comma delimited csOrder entry into string list.
  6032. bFound = FALSE;
  6033. ConvertSepLineToStringList(csOrder,cslStringListTemp,_T(","));
  6034. for( pos1 = cslStringListTemp.GetHeadPosition(); ( pos2 = pos1 ) != NULL; )
  6035. {
  6036. csOneEntry = cslStringListTemp.GetNext(pos1);
  6037. csOneEntry.TrimLeft();
  6038. csOneEntry.TrimRight();
  6039. // Does this contain our filtername?
  6040. if (TRUE == IsStringInArray(csOneEntry,arrayName))
  6041. {
  6042. csRemovedFilters += _T(',') + csOneEntry;
  6043. cslStringListTemp.RemoveAt(pos2);
  6044. bFound = TRUE;
  6045. }
  6046. }
  6047. // now we have csOrder=f1,f2,f3,sspifilt
  6048. if (bFound)
  6049. {
  6050. if (cslStringListTemp.IsEmpty())
  6051. {
  6052. // hardcode this entry in
  6053. csOrder = _T(" ");
  6054. dwReturn = WriteToMD_Filters_List_Entry(csOrder);
  6055. }
  6056. else
  6057. {
  6058. // convert the stringlist back into the comma delimited cstring.
  6059. ConvertStringListToSepLine(cslStringListTemp,csOrder,_T(","));
  6060. dwReturn = WriteToMD_Filters_List_Entry(csOrder);
  6061. }
  6062. if (iRemoveMetabaseNodes)
  6063. {
  6064. if (ERROR_SUCCESS == dwReturn)
  6065. {
  6066. // let's remove the metabase node as well!
  6067. // delete the metabase node.
  6068. if (CheckifServiceExist(_T("IISADMIN")) == 0 )
  6069. {
  6070. int i = 0;
  6071. // loop thru the list of bad filters to remove and remove them.
  6072. i = csRemovedFilters.ReverseFind(_T(','));
  6073. while (i != -1)
  6074. {
  6075. int len = csRemovedFilters.GetLength();
  6076. csOneEntry = csRemovedFilters.Right(len - i - 1);
  6077. if (_tcsicmp(csOneEntry, _T("")) != 0)
  6078. {
  6079. cmdKey.OpenNode(_T("LM/W3SVC/Filters"));
  6080. if ( (METADATA_HANDLE)cmdKey )
  6081. {
  6082. cmdKey.DeleteNode(csOneEntry);
  6083. cmdKey.Close();
  6084. }
  6085. }
  6086. csRemovedFilters = csRemovedFilters.Left(i);
  6087. i = csRemovedFilters.ReverseFind(_T(','));
  6088. }
  6089. }
  6090. }
  6091. }
  6092. }
  6093. RemoveIncompatibleMetabaseFilters_Exit:
  6094. iisDebugOut_End(_T("RemoveIncompatibleMetabaseFilters"),LOG_TYPE_TRACE);
  6095. return dwReturn;
  6096. }
  6097. int DoesAppIsolatedExist(CString csKeyPath)
  6098. {
  6099. int iReturn = false;
  6100. MDEntry stMDEntry;
  6101. DWORD dwValue = 0;
  6102. // LM/W3SVC/1/ROOT/something
  6103. stMDEntry.szMDPath = (LPTSTR)(LPCTSTR)csKeyPath;
  6104. stMDEntry.dwMDIdentifier = MD_APP_ISOLATED;
  6105. stMDEntry.dwMDAttributes = METADATA_INHERIT;
  6106. stMDEntry.dwMDUserType = IIS_MD_UT_WAM;
  6107. stMDEntry.dwMDDataType = DWORD_METADATA;
  6108. stMDEntry.dwMDDataLen = sizeof(DWORD);
  6109. stMDEntry.pbMDData = (LPBYTE)&dwValue;
  6110. if (ChkMdEntry_Exist(&stMDEntry))
  6111. {
  6112. iReturn = TRUE;
  6113. }
  6114. return iReturn;
  6115. }
  6116. DWORD WriteToMD_RootKeyType(void)
  6117. {
  6118. DWORD dwReturn = ERROR_SUCCESS;
  6119. MDEntry stMDEntry;
  6120. CString csKeyType;
  6121. CString csKeyPath = _T("/");
  6122. csKeyType = _T("IIS_ROOT");
  6123. stMDEntry.szMDPath = (LPTSTR)(LPCTSTR)csKeyPath;
  6124. stMDEntry.dwMDIdentifier = MD_KEY_TYPE;
  6125. stMDEntry.dwMDAttributes = METADATA_NO_ATTRIBUTES;
  6126. stMDEntry.dwMDUserType = IIS_MD_UT_SERVER;
  6127. stMDEntry.dwMDDataType = STRING_METADATA;
  6128. stMDEntry.dwMDDataLen = (csKeyType.GetLength() + 1) * sizeof(TCHAR);
  6129. stMDEntry.pbMDData = (LPBYTE)(LPCTSTR)csKeyType;
  6130. dwReturn = SetMDEntry(&stMDEntry);
  6131. return dwReturn;
  6132. }
  6133. void UpgradeFilters(CString csTheSection)
  6134. {
  6135. TSTR strTheSection;
  6136. if ( g_pTheApp->m_bUpgradeTypeHasMetabaseFlag &&
  6137. strTheSection.Copy( csTheSection )
  6138. )
  6139. {
  6140. VerifyMD_Filters_WWW( strTheSection );
  6141. }
  6142. else
  6143. {
  6144. WriteToMD_Filters_WWW( strTheSection );
  6145. }
  6146. return;
  6147. }