Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

397 lines
9.9 KiB

  1. /*++
  2. Copyright (c) 2001 Microsoft Corporation
  3. Module Name :
  4. comncomp.cxx
  5. Abstract:
  6. Class used to install the Common Components
  7. Author:
  8. Christopher Achille (cachille)
  9. Project:
  10. Internet Services Setup
  11. Revision History:
  12. June 2002: Created
  13. --*/
  14. #include "stdafx.h"
  15. #include "comncomp.hxx"
  16. #include "reg.hxx"
  17. #include "iadmw.h"
  18. #include "iiscnfg.h"
  19. #include "mdkey.h"
  20. #include "acl.hxx"
  21. // Define extinct properties, so we can remove them
  22. #define MD_MAX_GLOBAL_CONNECTIONS (IIS_MD_GLOBAL_BASE+2)
  23. sExtinctProperties g_ExtinctProps[] =
  24. { { MD_MAX_GLOBAL_CONNECTIONS,
  25. ALL_METADATA }
  26. };
  27. // SetInstallStateInRegistry
  28. //
  29. // Set the Install state in the registry. This is so that other
  30. // components can know that we are in install mode. Such as the
  31. // metabase, which only wants to create an new metabase.xml
  32. // during setup
  33. //
  34. BOOL
  35. SetInstallStateInRegistry( DWORD dwState )
  36. {
  37. CRegistry Reg;
  38. if ( !Reg.OpenRegistry( HKEY_LOCAL_MACHINE,
  39. REG_INETSTP,
  40. KEY_ALL_ACCESS,
  41. dwState != INSTALLSTATE_DONE ) )
  42. {
  43. if ( dwState == INSTALLSTATE_DONE )
  44. {
  45. // This is fine, since we were only going to remove
  46. // it anyways
  47. return TRUE;
  48. }
  49. return FALSE;
  50. }
  51. if ( dwState == INSTALLSTATE_DONE )
  52. {
  53. // We are done, so remove registry entry
  54. if ( !Reg.DeleteValue( REG_INSTALLSTATE ) )
  55. {
  56. return FALSE;
  57. }
  58. }
  59. else
  60. {
  61. CRegValue Value;
  62. if ( !Value.SetDword( dwState ) ||
  63. !Reg.SetValue( REG_INSTALLSTATE, Value ) )
  64. {
  65. return FALSE;
  66. }
  67. }
  68. return TRUE;
  69. }
  70. // DeleteHistoryFiles
  71. //
  72. // Remove all the metabase History Files.
  73. // This is because the history files were created during the setup
  74. // process, and are only partially complete
  75. //
  76. BOOL
  77. CCommonInstallComponent::DeleteHistoryFiles()
  78. {
  79. TSTR_PATH strHistoryLocation;
  80. BOOL bRet = TRUE;
  81. if ( !strHistoryLocation.Copy( g_pTheApp->m_csPathInetsrv.GetBuffer(0) ) ||
  82. !strHistoryLocation.PathAppend( PATH_HISTORYFILES ) )
  83. {
  84. // Could not construct Path
  85. bRet = FALSE;
  86. }
  87. if ( bRet &&
  88. !RecRemoveDir( strHistoryLocation.QueryStr(), FALSE ) )
  89. {
  90. bRet = FALSE;
  91. }
  92. if ( !bRet )
  93. {
  94. // This is really a very minor issue, so we will just issue a warning
  95. iisDebugOut((LOG_TYPE_WARN, _T("Could not delete history files after install, some of them will be incomplete") ));
  96. }
  97. return TRUE;
  98. }
  99. // DeleteOldBackups
  100. //
  101. // Remove all the backups that we had from previous versions
  102. // This is because they are not valid on the current version, and
  103. // can not be used
  104. //
  105. BOOL
  106. CCommonInstallComponent::DeleteOldBackups()
  107. {
  108. TSTR_PATH strBackupLocation;
  109. BOOL bRet = TRUE;
  110. if ( !strBackupLocation.Copy( g_pTheApp->m_csPathInetsrv.GetBuffer(0) ) ||
  111. !strBackupLocation.PathAppend( PATH_METABASEBACKUPS ) )
  112. {
  113. // Could not construct Path
  114. bRet = FALSE;
  115. }
  116. if ( bRet &&
  117. !RecRemoveDir( strBackupLocation.QueryStr(), FALSE ) )
  118. {
  119. bRet = FALSE;
  120. }
  121. if ( !bRet )
  122. {
  123. // This is really a very minor issue, so we will just issue a warning
  124. iisDebugOut((LOG_TYPE_WARN, _T("Could not delete the old backup's from the previous version") ));
  125. }
  126. return TRUE;
  127. }
  128. // PreInstall
  129. //
  130. // PreInstall the Common Component
  131. //
  132. BOOL
  133. CCommonInstallComponent::PreInstall()
  134. {
  135. BOOL bRet = TRUE;
  136. bRet = bRet && SetInstallStateInRegistry( INSTALLSTATE_CURRENTLYINSTALLING );
  137. return bRet;
  138. }
  139. // Install
  140. //
  141. // Install the Common Component
  142. //
  143. BOOL
  144. CCommonInstallComponent::Install()
  145. {
  146. BOOL bRet = TRUE;
  147. if ( IsUpgrade() )
  148. {
  149. bRet = bRet && DeleteOldBackups();
  150. bRet = bRet && RemoveExtinctMbProperties();
  151. }
  152. return bRet;
  153. }
  154. // PostInstall
  155. //
  156. // All work that is necessary after instalation
  157. //
  158. BOOL
  159. CCommonInstallComponent::PostInstall()
  160. {
  161. BOOL bRet = TRUE;
  162. bRet = bRet && SetInstallStateInRegistry( INSTALLSTATE_DONE );
  163. bRet = bRet && DeleteHistoryFiles();
  164. return bRet;
  165. }
  166. // PreUnInstall
  167. //
  168. // PreUnInstall the Common Component
  169. //
  170. BOOL
  171. CCommonInstallComponent::PreUnInstall()
  172. {
  173. BOOL bRet = TRUE;
  174. bRet = bRet && SetInstallStateInRegistry( INSTALLSTATE_CURRENTLYUNINSTALLING );
  175. return bRet;
  176. }
  177. // PostUnInstall
  178. //
  179. // All work that is necessary after removal
  180. //
  181. BOOL
  182. CCommonInstallComponent::PostUnInstall()
  183. {
  184. BOOL bRet = TRUE;
  185. bRet = bRet && SetInstallStateInRegistry( INSTALLSTATE_DONE );
  186. return bRet;
  187. }
  188. // GetFriendlyName
  189. //
  190. // Retireve the Friendly Name for the Component
  191. //
  192. BOOL
  193. CCommonInstallComponent::GetFriendlyName( TSTR *pstrFriendlyName )
  194. {
  195. return pstrFriendlyName->LoadString( IDS_IIS_COMPONENTNAME );
  196. }
  197. // GetName
  198. //
  199. // Retrieve the OCM component name
  200. //
  201. LPTSTR
  202. CCommonInstallComponent::GetName()
  203. {
  204. return g_ComponentList[COMPONENT_IIS_COMMON].szComponentName;
  205. }
  206. // RemoveExtinctMbProperties
  207. //
  208. // Remove Metabase properties that were used in old version, but no longer
  209. // get used
  210. //
  211. BOOL
  212. CCommonInstallComponent::RemoveExtinctMbProperties()
  213. {
  214. DWORD i;
  215. CMDKey cmdKey;
  216. CStringList cslpathList;
  217. CString csPath;
  218. POSITION pos;
  219. if ( FAILED( cmdKey.OpenNode( _T("/LM") ) ) )
  220. {
  221. // Failed to open MB
  222. return FALSE;
  223. }
  224. for ( i = 0;
  225. i < ( (DWORD) ( sizeof( g_ExtinctProps ) / sizeof( sExtinctProperties ) ) );
  226. i++ )
  227. {
  228. if (FAILED( cmdKey.GetDataPaths( g_ExtinctProps[i].dwPropertyId,
  229. g_ExtinctProps[i].dwUserType,
  230. cslpathList) ))
  231. {
  232. // Ignore errors, since this is cosmetic, just continue
  233. // with next item
  234. continue;
  235. }
  236. pos = cslpathList.GetHeadPosition();
  237. while ( NULL != pos )
  238. {
  239. csPath = cslpathList.GetNext( pos );
  240. // Ignore errors, since what we are doing is cosmetic
  241. cmdKey.DeleteData( g_ExtinctProps[i].dwPropertyId,
  242. g_ExtinctProps[i].dwUserType,
  243. csPath.GetBuffer(0) );
  244. }
  245. }
  246. cmdKey.Close();
  247. return TRUE;
  248. }
  249. // SetMetabaseFileAcls
  250. //
  251. // Set the ACL's on all the Metabase Specific Files, these are going to be
  252. // the following:
  253. // %windir%\system32\inetsrv\History
  254. // %windir%\system32\inetsrv\History\*
  255. // %windir%\system32\inetsrv\Metaback\*
  256. // %windir%\system32\inetsrv\Metabase.xml
  257. // %windir%\system32\inetsrv\mbschema.xml
  258. // %windir%\system32\inetsrv\mbschema.bin.*
  259. // %windir%\system32\inetsrv\metabase.bak
  260. // %windir%\system32\inetsrv\metabase.xml.tmp
  261. //
  262. BOOL
  263. CCommonInstallComponent::SetMetabaseFileAcls()
  264. {
  265. TSTR_PATH strHistory;
  266. TSTR_PATH strHistoryAll;
  267. TSTR_PATH strMetabackAll;
  268. TSTR_PATH strMetabase;
  269. TSTR_PATH strMBSchema;
  270. TSTR_PATH strMBSchemaAll;
  271. TSTR_PATH strMetabaseBackup;
  272. TSTR_PATH strMetabaseTemp;
  273. CSecurityDescriptor AdminSD;
  274. BOOL bDriveIsAclable;
  275. if ( !strHistory.Copy( PATH_FULL_HISTORY_DIR ) ||
  276. !strHistoryAll.Copy( PATH_FULL_HISTORY_ALLFILES ) ||
  277. !strMetabackAll.Copy( PATH_FULL_METABACK_ALLFILES ) ||
  278. !strMetabase.Copy( PATH_FULL_METABASE_FILE ) ||
  279. !strMBSchema.Copy( PATH_FULL_MBSCHEMA_FILE ) ||
  280. !strMBSchemaAll.Copy( PATH_FULL_MBSCHEMA_BINFILES ) ||
  281. !strMetabaseBackup.Copy( PATH_FULL_METABASE_BACKUPFILE ) ||
  282. !strMetabaseTemp.Copy( PATH_FULL_METABASE_TEMPFILE ) ||
  283. !strHistory.ExpandEnvironmentVariables() ||
  284. !strHistoryAll.ExpandEnvironmentVariables() ||
  285. !strMetabackAll.ExpandEnvironmentVariables() ||
  286. !strMetabase.ExpandEnvironmentVariables() ||
  287. !strMBSchema.ExpandEnvironmentVariables() ||
  288. !strMBSchemaAll.ExpandEnvironmentVariables() ||
  289. !strMetabaseBackup.ExpandEnvironmentVariables() ||
  290. !strMetabaseTemp.ExpandEnvironmentVariables()
  291. )
  292. {
  293. // Failed to construct Path
  294. return FALSE;
  295. }
  296. if ( !CSecurityDescriptor::DoesFileSystemSupportACLs( // All of these are on the same drive
  297. strHistory.QueryStr(), // so just use one to test
  298. &bDriveIsAclable ) )
  299. {
  300. // Failed to check if ACL is valid for this filesystem
  301. return FALSE;
  302. }
  303. if ( !bDriveIsAclable )
  304. {
  305. // This drive is not aclable, so skip it
  306. return TRUE;
  307. }
  308. if ( !AdminSD.AddAccessAcebyWellKnownID( CSecurityDescriptor::GROUP_ADMINISTRATORS,
  309. CSecurityDescriptor::ACCESS_FULL,
  310. TRUE,
  311. TRUE ) ||
  312. !AdminSD.AddAccessAcebyWellKnownID( CSecurityDescriptor::USER_LOCALSYSTEM,
  313. CSecurityDescriptor::ACCESS_FULL,
  314. TRUE,
  315. TRUE ) )
  316. {
  317. // Failed to create Admin SD
  318. return FALSE;
  319. }
  320. if ( !AdminSD.SetSecurityInfoOnFiles( strHistory.QueryStr(), FALSE ) ||
  321. !AdminSD.SetSecurityInfoOnFiles( strHistoryAll.QueryStr(), FALSE ) ||
  322. !AdminSD.SetSecurityInfoOnFiles( strMetabackAll.QueryStr(), FALSE ) ||
  323. !AdminSD.SetSecurityInfoOnFiles( strMetabase.QueryStr(), FALSE ) ||
  324. !AdminSD.SetSecurityInfoOnFiles( strMBSchema.QueryStr(), FALSE ) ||
  325. !AdminSD.SetSecurityInfoOnFiles( strMBSchemaAll.QueryStr(), FALSE ) ||
  326. !AdminSD.SetSecurityInfoOnFiles( strMetabaseBackup.QueryStr(), FALSE ) ||
  327. !AdminSD.SetSecurityInfoOnFiles( strMetabaseTemp.QueryStr(), FALSE ) )
  328. {
  329. // Failed to set ACL on one of these nodes
  330. return FALSE;
  331. }
  332. return TRUE;
  333. }