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.

238 lines
4.9 KiB

  1. /*++
  2. Copyright (c) 2001 Microsoft Corporation
  3. Module Name :
  4. updurls2.cpp
  5. Abstract:
  6. The main for the Project
  7. Author:
  8. Christopher Achille (cachille)
  9. Project:
  10. URLScan Update
  11. Revision History:
  12. March 2002: Created
  13. --*/
  14. // updurls2.cpp : Defines the entry point for the console application.
  15. //
  16. #include "stdafx.h"
  17. #include "windows.h"
  18. #include "urlscan.h"
  19. #include "resource.h"
  20. BOOL CheckParameters( int argc, _TCHAR* argv[], BOOL *bQuietMode, BOOL *bExpandOnly );
  21. // ShowMessage
  22. //
  23. // Show either a warning or a message to the user
  24. //
  25. // Parameters:
  26. // dwMessageId - The id of the message
  27. // bError - TRUE == error, FALSE == informative
  28. //
  29. // This does not return anything, because there would be no
  30. // point. By this time we have failed or not, and there
  31. // is not additional way to notify the user
  32. //
  33. void ShowMessage( DWORD dwMessageId, BOOL bError )
  34. {
  35. HMODULE hModule = GetModuleHandle( NULL );
  36. TCHAR szMessage[MAX_PATH];
  37. TCHAR szTitle[MAX_PATH];
  38. if ( hModule == NULL )
  39. {
  40. // Could not get handle to module
  41. return;
  42. }
  43. if ( !LoadString( hModule, dwMessageId, szMessage, MAX_PATH ) )
  44. {
  45. // Failed to Retrieve Message
  46. return;
  47. }
  48. if ( !LoadString( hModule, IDS_TITLEBAR, szTitle, MAX_PATH ) )
  49. {
  50. // Failed to Retrieve Title
  51. return;
  52. }
  53. MessageBox( NULL, szMessage, szTitle, MB_OK | ( bError ? MB_ICONEXCLAMATION : MB_ICONINFORMATION ) );
  54. }
  55. // ShowText
  56. //
  57. // Show text out to the console
  58. //
  59. // Parameters:
  60. // dwMessageId - The id of the message
  61. // szExeName - The name of this executable
  62. //
  63. // This does not return anything, because there would be no
  64. // point. By this time we have failed or not, and there
  65. // is not additional way to notify the user
  66. //
  67. void ShowText( DWORD dwMessageId, LPWSTR szExeName )
  68. {
  69. HMODULE hModule = GetModuleHandle( NULL );
  70. TCHAR szMessage[MAX_PATH];
  71. if ( hModule == NULL )
  72. {
  73. // Could not get handle to module
  74. return;
  75. }
  76. if ( !LoadString( hModule, dwMessageId, szMessage, MAX_PATH ) )
  77. {
  78. // Failed to Retrieve Message
  79. return;
  80. }
  81. wprintf(szMessage, szExeName);
  82. }
  83. // UrlScanUpdate
  84. //
  85. // Update the URLScan files
  86. DWORD
  87. UrlScanUpdate()
  88. {
  89. TCHAR szUrlScanPath[ MAX_PATH ];
  90. DWORD dwErr;
  91. if ( !IsAdministrator() )
  92. {
  93. return IDS_ERROR_ADMIN;
  94. }
  95. if ( !IsUrlScanInstalled( szUrlScanPath, MAX_PATH ) )
  96. {
  97. return IDS_ERROR_NOTINSTALLED;
  98. }
  99. dwErr = InstallURLScanFix( szUrlScanPath );
  100. if ( dwErr != ERROR_SUCCESS )
  101. {
  102. // Failure, IDS resource should be returned
  103. return dwErr;
  104. }
  105. // This is very cosmetic thing, so we do not want to
  106. // fail for this reason
  107. UpdateRegistryforAddRemove();
  108. // Success
  109. return IDS_SUCCESS_UPDATE;
  110. }
  111. // CheckParameters
  112. //
  113. // Check Parameters for command line flags
  114. //
  115. // Parameters:
  116. // argc - [in] Number of arguments
  117. // argv - [in] The list of arguments
  118. // bQuietMode - [out] Is Quiet Mode Turned On?
  119. // bExpandOnly - [out] Is Expand Only turned on?
  120. //
  121. // Return values:
  122. // TRUE - Read Parameters without a problem
  123. // FALSE - Failed to read parameters
  124. //
  125. BOOL
  126. CheckParameters( int argc, _TCHAR* argv[], BOOL *bQuietMode, BOOL *bExpandOnly )
  127. {
  128. DWORD dwCount;
  129. // SET Defaults
  130. *bQuietMode = FALSE;
  131. *bExpandOnly = FALSE;
  132. for ( dwCount = 1; dwCount < (DWORD) argc; dwCount ++ )
  133. {
  134. if ( ( argv[ dwCount ][0] != '/' ) ||
  135. ( argv[ dwCount ][1] == '\0' ) ||
  136. ( argv[ dwCount ][2] != '\0' )
  137. )
  138. {
  139. return FALSE;
  140. }
  141. // Because if previous "if", command must be in the form "/x\0" where
  142. // x is any character but '\0'
  143. switch ( argv[ dwCount ][1] )
  144. {
  145. case 'x':
  146. case 'X':
  147. *bExpandOnly = TRUE;
  148. break;
  149. case 'q':
  150. case 'Q':
  151. *bQuietMode = TRUE;
  152. break;
  153. default:
  154. return FALSE;
  155. break;
  156. }
  157. }
  158. return TRUE;
  159. }
  160. int __cdecl wmain(int argc, _TCHAR* argv[])
  161. {
  162. BOOL bExpandOnly;
  163. BOOL bQuietMode;
  164. BOOL bRet = TRUE;
  165. DWORD dwErr;
  166. if ( !CheckParameters( argc, argv, &bQuietMode, &bExpandOnly ) )
  167. {
  168. ShowText( IDS_USAGE, ( argv && argv[0] ) ? argv[0] :
  169. URLSCAN_UPDATE_DEFAULT_NAME );
  170. return 1;
  171. }
  172. if ( bExpandOnly )
  173. {
  174. // Only Expansion is wanted, so only do that.
  175. if ( ExtractUrlScanFile( URLSCAN_DEFAULT_FILENAME ) )
  176. {
  177. dwErr = IDS_SUCCESS_EXTRACT;
  178. }
  179. else
  180. {
  181. dwErr = IDS_ERROR_EXTRACT;
  182. }
  183. }
  184. else
  185. {
  186. dwErr = UrlScanUpdate();
  187. }
  188. bRet = ( dwErr == IDS_SUCCESS_EXTRACT ) ||
  189. ( dwErr == IDS_SUCCESS_UPDATE );
  190. if ( !bQuietMode )
  191. {
  192. ShowMessage( dwErr, !bRet );
  193. }
  194. // Return 0 or 1 depending on if there is an error or not
  195. return bRet ? 0 : 1;
  196. }