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.

272 lines
5.9 KiB

  1. /*++
  2. Copyright (c) 2002 Microsoft Corporation
  3. Module Name:
  4. wsroot.cpp
  5. Abstract:
  6. This module contains the functions that create a default path for web sites root.
  7. Author:
  8. Jaime Sasson (jaimes) 12-apr-2002
  9. Revision History:
  10. --*/
  11. #include "precomp.h"
  12. #pragma hdrstop
  13. #include <msi.h>
  14. //
  15. // Global strings (global to this module)
  16. //
  17. PTSTR szServerAppliancePath = TEXT("Software\\Microsoft\\ServerAppliance");
  18. PTSTR szWebSiteRoot = TEXT("WebSiteRoot");
  19. DWORD __stdcall
  20. RemoveDefaultWebSiteRoot(MSIHANDLE hInstall
  21. )
  22. /*++
  23. Routine Description:
  24. Routine to delete the default path for the web sites root from the registry, under
  25. HKLM\SOFTWARE\Microsoft\ServerAppliance.
  26. Arguments:
  27. Handle to the msi, which is not used.
  28. Return value:
  29. Win32 error indicating outcome.
  30. --*/
  31. {
  32. DWORD Error;
  33. HKEY Key;
  34. //
  35. // Open the ServerAppliance key
  36. //
  37. Error = RegOpenKeyEx( HKEY_LOCAL_MACHINE,
  38. szServerAppliancePath,
  39. 0,
  40. KEY_SET_VALUE,
  41. &Key );
  42. if( Error == ERROR_SUCCESS ) {
  43. Error = RegDeleteValue( Key,
  44. szWebSiteRoot );
  45. if( Error != ERROR_SUCCESS ) {
  46. #if 0
  47. printf("RegDeleteValue() failed. Error = %d", Error);
  48. #endif
  49. }
  50. RegCloseKey( Key );
  51. } else {
  52. #if 0
  53. printf("RegOpenKeyEx() failed. Error = %d", Error);
  54. #endif
  55. }
  56. return( Error );
  57. }
  58. DWORD
  59. SaveDefaultRoot(
  60. IN TCHAR DriveLetter
  61. )
  62. /*++
  63. Routine Description:
  64. Routine to save the default path for the web sites root in the registry, under
  65. HKLM\SOFTWARE\Microsoft\ServerAppliance.
  66. Arguments:
  67. Drive letter - Default drive where the web sites are created.
  68. Return value:
  69. Win32 error indicating outcome.
  70. --*/
  71. {
  72. DWORD Error;
  73. HKEY Key;
  74. TCHAR RootPath[] = TEXT("?:\\Websites");
  75. if( !DriveLetter ) {
  76. return( ERROR_INVALID_PARAMETER );
  77. }
  78. RootPath[0] = DriveLetter;
  79. //
  80. // Open the ServerAppliance key if it doesn't exist yet
  81. //
  82. Error = RegCreateKeyEx( HKEY_LOCAL_MACHINE,
  83. szServerAppliancePath,
  84. 0,
  85. NULL,
  86. REG_OPTION_NON_VOLATILE,
  87. KEY_SET_VALUE,
  88. NULL,
  89. &Key,
  90. NULL );
  91. if( Error == ERROR_SUCCESS ) {
  92. Error = RegSetValueEx( Key,
  93. szWebSiteRoot,
  94. 0,
  95. REG_SZ,
  96. (PBYTE)RootPath,
  97. (lstrlen( RootPath ) + 1) * sizeof(TCHAR) );
  98. if( Error != ERROR_SUCCESS ) {
  99. #if 0
  100. printf("RegSetValueEx() failed. Error = %d", Error);
  101. #endif
  102. }
  103. RegCloseKey( Key );
  104. } else {
  105. #if 0
  106. printf("RegCreateKeyEx() failed. Error = %d", Error);
  107. #endif
  108. }
  109. return( Error );
  110. }
  111. BOOL
  112. IsDriveNTFS(
  113. IN TCHAR Drive
  114. )
  115. /*++
  116. Routine Description:
  117. Determine whether a drive is formatted with the NTFS.
  118. Arguments:
  119. Drive - supplies drive letter to check.
  120. Return Value:
  121. Boolean value indicating whether the drive is NTFS.
  122. --*/
  123. {
  124. TCHAR DriveName[] = TEXT("?:\\");
  125. TCHAR Filesystem[256];
  126. TCHAR VolumeName[MAX_PATH];
  127. DWORD SerialNumber;
  128. DWORD MaxComponent;
  129. DWORD Flags;
  130. BOOL b;
  131. PTSTR szNtfs = TEXT("NTFS");
  132. DriveName[0] = Drive;
  133. b = GetVolumeInformation( DriveName,
  134. VolumeName,
  135. sizeof(VolumeName) / sizeof(TCHAR),
  136. &SerialNumber,
  137. &MaxComponent,
  138. &Flags,
  139. Filesystem,
  140. sizeof(Filesystem) / sizeof(TCHAR) );
  141. if(!b || !lstrcmpi(Filesystem,szNtfs)) {
  142. return( TRUE );
  143. }
  144. return( FALSE );
  145. }
  146. DWORD __stdcall
  147. SetupDefaultWebSiteRoot(MSIHANDLE hInstall
  148. )
  149. /*++
  150. Routine Description:
  151. This function creates a default path for websites, and saves it in the registry.
  152. Arguments:
  153. Handle to the msi, which is not used.
  154. Return Value:
  155. Win32 error indicating the outcome of the operation.
  156. --*/
  157. {
  158. DWORD Error;
  159. TCHAR i;
  160. TCHAR DriveName[] = TEXT("?:\\");
  161. TCHAR TargetDriveLetter = TEXT('\0');
  162. TCHAR WinDir[ MAX_PATH + 1 ];
  163. UINT n;
  164. //
  165. // Find out where the OS is installed.
  166. // If GetWindowsDirectory fails, the WinDir will be an empty string.
  167. //
  168. WinDir[0] = TEXT('\0');
  169. n = GetWindowsDirectory( WinDir, sizeof(WinDir)/sizeof(TCHAR) );
  170. //
  171. // Find an NTFS partition on a non-removable drive that doesn't contain the OS
  172. //
  173. for(i = TEXT('A'); i <= TEXT('Z'); i++) {
  174. DriveName[0] = i;
  175. if( (GetDriveType(DriveName) == DRIVE_FIXED) &&
  176. (WinDir[0] != i) &&
  177. IsDriveNTFS(i) ) {
  178. TargetDriveLetter = i;
  179. break;
  180. }
  181. }
  182. if( !TargetDriveLetter ) {
  183. //
  184. // If we were unable to find such a drive, then take the boot partition as the default drive.
  185. // But if we failed to retrieve where the OS is installed, then assume drive C.
  186. //
  187. TargetDriveLetter = (WinDir[0])? WinDir[0] : TEXT('C');
  188. }
  189. Error = SaveDefaultRoot(TargetDriveLetter);
  190. #if 0
  191. if( Error != ERROR_SUCCESS ) {
  192. printf("SaveDefaultDriveLetter() failed. Error = %d \n", Error);
  193. }
  194. printf("Drive selected is %lc \n", TargetDriveLetter);
  195. #endif
  196. return Error;
  197. }