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.

183 lines
4.8 KiB

  1. /*++
  2. Copyright (c) 2002 Microsoft Corporation
  3. Module Name :
  4. lockdown.cxx
  5. Abstract:
  6. Upgrade old IIS Lockdown Wizard Settings to whatever
  7. is appropriate in IIS6
  8. Author:
  9. Christopher Achille (cachille)
  10. Project:
  11. Internet Services Setup
  12. Revision History:
  13. May 2002: Created
  14. --*/
  15. #include "stdafx.h"
  16. #include "acl.hxx"
  17. #include "restrlst.hxx"
  18. #include "lockdown.hxx"
  19. #include "reg.hxx"
  20. // IsWebDavDisabled
  21. //
  22. // This checks to see if WebDav was disabled on IIS 5.0. The way
  23. // this was done, was by removing acl's on the file, so the webserver
  24. // could not load the file.
  25. // This will not only check, but it will restore the ACL's so the file
  26. // can be replaced on upgrade.
  27. //
  28. // Parameters:
  29. // pbWasDisabled - [out] Was the file disabled before or not
  30. //
  31. // Return
  32. // TRUE - Success checking
  33. // FALSE - Failed to check
  34. BOOL
  35. IsWebDavDisabled( LPBOOL pbWasDisabled )
  36. {
  37. CSecurityDescriptor SD;
  38. BOOL bAreAclsSupported;
  39. TSTR_PATH strHttpExtPath;
  40. ACCESS_MASK AccessMask;
  41. if ( !strHttpExtPath.Copy( g_pTheApp->m_csPathInetsrv ) ||
  42. !strHttpExtPath.PathAppend( g_OurExtensions[EXTENSION_WEBDAV].szFileName ) )
  43. {
  44. // Failed to construct path
  45. return FALSE;
  46. }
  47. if ( !CSecurityDescriptor::DoesFileSystemSupportACLs( strHttpExtPath.QueryStr(),
  48. &bAreAclsSupported ) )
  49. {
  50. // Failure
  51. return FALSE;
  52. }
  53. else
  54. {
  55. if ( !bAreAclsSupported )
  56. {
  57. // Since ACL's are not supported, lets just exit
  58. *pbWasDisabled = FALSE;
  59. return TRUE;
  60. }
  61. }
  62. if ( !SD.GetSecurityInfoOnFile( strHttpExtPath.QueryStr() ) ||
  63. !SD.QueryEffectiveRightsForTrustee( CSecurityDescriptor::GROUP_USERS,
  64. &AccessMask ) )
  65. {
  66. // Failed to query access
  67. // It is possible that the file is not even on the system
  68. // so just return that it is not disables
  69. *pbWasDisabled = FALSE;
  70. return TRUE;
  71. }
  72. // Was file disabled to be loaded?
  73. *pbWasDisabled = ( AccessMask & ACTRL_FILE_EXECUTE ) == 0;
  74. if ( *pbWasDisabled )
  75. {
  76. // Lets restore ACL, so we can upgrade it
  77. // Copy ACL's from that of inetsrv directory to dll, since it has been acl'd down
  78. if ( !SD.GetSecurityInfoOnFile( g_pTheApp->m_csPathInetsrv.GetBuffer(0) ) ||
  79. !SD.SetSecurityInfoOnFile( strHttpExtPath.QueryStr(), TRUE ) )
  80. {
  81. return FALSE;
  82. }
  83. }
  84. return TRUE;
  85. }
  86. // IsWebDavDisabledViaRegistry
  87. //
  88. // Is WebDav disabled in the registry?
  89. //
  90. // Parameters:
  91. // pbWasDisabled - [out] Was the file disabled before or not
  92. //
  93. // Return
  94. // TRUE - Success checking
  95. // FALSE - Failed to check
  96. BOOL
  97. IsWebDavDisabledViaRegistry( LPBOOL pbWasDisabled )
  98. {
  99. CRegValue Value;
  100. CRegistry Registry;
  101. *pbWasDisabled = FALSE;
  102. if ( !Registry.OpenRegistry( HKEY_LOCAL_MACHINE,
  103. REG_WWWPARAMETERS,
  104. KEY_READ | KEY_WRITE ) )
  105. {
  106. // Failed to open WWW Node
  107. // We will consider this success, since the node might not exist.
  108. return TRUE;
  109. }
  110. if ( Registry.ReadValue( REGISTRY_WWW_DISABLEWEBDAV_NAME,
  111. Value ) )
  112. {
  113. // Successfully read value
  114. *pbWasDisabled = *( (LPDWORD) Value.m_buffData.QueryPtr() ) != 0;
  115. }
  116. Registry.DeleteValue( REGISTRY_WWW_DISABLEWEBDAV_NAME );
  117. return TRUE;
  118. }
  119. // DisableWebDavInRestrictionList
  120. //
  121. // Lockdown access the the HttpExtension Dll. That this meands is that
  122. // we free up the ACL on the file, and deny it through the
  123. // WebSvcRestrictionList
  124. //
  125. BOOL
  126. DisableWebDavInRestrictionList()
  127. {
  128. CRestrictionList RestrictionList;
  129. CSecurityDescriptor SD;
  130. TSTR strDescription;
  131. TSTR_PATH strHttpExtPath;
  132. if ( !strHttpExtPath.Copy( g_pTheApp->m_csPathInetsrv ) ||
  133. !strHttpExtPath.PathAppend( g_OurExtensions[EXTENSION_WEBDAV].szFileName ) )
  134. {
  135. // Failed to construct path
  136. return FALSE;
  137. }
  138. // Update Metabas
  139. if ( !strDescription.LoadString( g_OurExtensions[EXTENSION_WEBDAV].dwProductName ) ||
  140. !RestrictionList.InitMetabase() ||
  141. !RestrictionList.LoadCurrentSettings() ||
  142. !RestrictionList.UpdateItem( strHttpExtPath.QueryStr(),
  143. g_OurExtensions[EXTENSION_WEBDAV].szNotLocalizedGroupName,
  144. strDescription.QueryStr(),
  145. FALSE, // DENY
  146. g_OurExtensions[EXTENSION_WEBDAV].bUIDeletable ) ||
  147. !RestrictionList.SaveSettings() )
  148. {
  149. // Failed to update metabase
  150. return FALSE;
  151. }
  152. return TRUE;
  153. }