Source code of Windows XP (NT5)
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.

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