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.

275 lines
7.5 KiB

  1. @echo off
  2. REM ------------------------------------------------------------------
  3. REM
  4. REM getprs.cmd
  5. REM fetch PRS signed files from the remote share.
  6. REM
  7. REM Copyright (c) Microsoft Corporation. All rights reserved.
  8. REM Version: < 1.0 > 05/02/2001 Suemiao Rossignol
  9. REM ------------------------------------------------------------------
  10. perl -x "%~f0" %*
  11. goto :EOF
  12. #!perl
  13. use strict;
  14. use lib $ENV{RAZZLETOOLPATH} . "\\PostBuildScripts";
  15. use lib $ENV{RAZZLETOOLPATH};
  16. use PbuildEnv;
  17. use Logmsg;
  18. use ParseArgs;
  19. use File::Basename;
  20. use BuildName;
  21. use GetIniSetting;
  22. use comlib;
  23. use HashText;
  24. use cksku;
  25. my $scriptname = basename( $0 );
  26. sub Usage {
  27. print<<USAGE;
  28. Fetch PRS signed files from the remote source share for the Windows build.
  29. Usage:
  30. $scriptname: -l:<language> -s:<source> [-n:<name>] [-final]
  31. -l Language.
  32. Default is "usa".
  33. -s Source Directory.
  34. Location to copy the files from.
  35. -n Build name.
  36. The name of the service pack or QFE being built.
  37. -final
  38. Copy finished binaries instead of catalogs.
  39. -? Display Usage.
  40. Example:
  41. $scriptname -l:ger -s:\\prs
  42. USAGE
  43. exit(1)
  44. }
  45. my ( $lang, $src, $name, $final );
  46. my ( @tableHash);
  47. my ( $dash, $buildName );
  48. my ( @prodSkus, %skusDirName );
  49. my ( %certPath, %certFileList, %certLog );
  50. exit(1) if( !&GetParams() );
  51. timemsg( "Start [$scriptname]" );
  52. exit(1) if( !&InitVars );
  53. exit(1) if( !&PullSignedFiles );
  54. exit(1) if( !&ErrorCheck );
  55. timemsg( "Complete [$scriptname]\n$dash" );
  56. exit(0);
  57. #-----------------------------------------------------------------------------
  58. sub GetParams
  59. {
  60. parseargs('?' => \&Usage, 's:' => \$src, 'n:' => \$name, 'final' => \$final );
  61. $lang = $ENV{lang};
  62. if( !$name )
  63. {
  64. $name = "sp1";
  65. }
  66. return 1;
  67. }
  68. #-----------------------------------------------------------------------------
  69. sub InitVars
  70. {
  71. #####Retrieve Build name
  72. if( ! ( $buildName = build_name() ))
  73. {
  74. errmsg( "[$ENV{_ntpostbld}\\build_logs\\buildname.txt] not found, exit." );
  75. return 0;
  76. }
  77. chomp( $buildName );
  78. #####Define submit log
  79. if( !$final )
  80. {
  81. %certLog =( "prs" => "$ENV{_ntpostbld}\\build_logs\\$buildName\\submit_prs.log",
  82. "fusion" => "$ENV{_ntpostbld}\\build_logs\\$buildName\\submit_fusion.log" );
  83. } else {
  84. %certLog =( "external" => "$ENV{_ntpostbld}\\build_logs\\$buildName\\submit_ext.log" );
  85. }
  86. #####Check out directories to see what requests were done.
  87. %certPath = ( );
  88. $certPath{"prs"} = "$src\\prs" if ( -e "$src\\prs" and !$final );
  89. $certPath{"fusion"} = "$src\\fusion" if ( -e "$src\\fusion" and !$final );
  90. $certPath{"external"} = "$src\\pack" if ( -e "$src\\pack" and $final );
  91. #####Misc Init
  92. $dash = '-' x 60;
  93. %certFileList =( "fusion" => "$ENV{RazzleToolPath}\\sp\\prs\\fusionlist\.txt",
  94. "prs" => "$ENV{RazzleToolPath}\\sp\\prs\\fullprslist\.txt",
  95. "external" => "$ENV{RazzleToolPath}\\sp\\prs\\finallist\.txt" );
  96. for my $theCert( keys %certFileList )
  97. {
  98. if( !(-e $certFileList{$theCert} ) )
  99. {
  100. errmsg( "$certFileList{$theCert} not found, exit." );
  101. return 0;
  102. }
  103. }
  104. #####Set Product Skus
  105. %skusDirName=( "pro" => ".", "per" => "perinf" );
  106. if ( $ENV{_BuildArch} =~ /x86/i ) {
  107. @prodSkus=("pro","per");
  108. }
  109. else {
  110. @prodSkus=("pro");
  111. }
  112. logmsg( "Language .......................[$lang]" );
  113. logmsg( "Build Name......................[$buildName]" );
  114. for my $theCert ( keys %certPath )
  115. {
  116. logmsg( "$theCert Remote Share...[$certPath{$theCert}]" );
  117. logmsg( "$theCert File List ......[$certFileList{$theCert}]" );
  118. }
  119. # logmsg( "Private Postbuild Data file.....[$privateDataFile]" );
  120. logmsg( "Temp Log file ..................[$ENV{LOGFILE}]" );
  121. logmsg( "Temp Error file ................[$ENV{ERRFILE}]" );
  122. return 1;
  123. }
  124. #-----------------------------------------------------------------------------
  125. sub PullSignedFiles
  126. {
  127. for my $theCert ( keys %certPath )
  128. {
  129. @tableHash = &comlib::ParsePrsListFile( $lang, $ENV{_buildArch}, $ENV{_buildType}, $certFileList{$theCert} );
  130. #####Verify Signed files exists and pass chktrust
  131. logmsg( $dash );
  132. logmsg( "-----Verifying $theCert signed files----------\n" );
  133. return 0 if( !&VerifySignedFiles( $certPath{$theCert} ) );
  134. #####Copy files back to %_ntpostbld%
  135. logmsg( $dash );
  136. logmsg( "-----Fetching $theCert signed files back to $ENV{_ntpostbld}-----\n" );
  137. return 0 if( !&FetchSignedFiles( $certPath{$theCert} ) );
  138. }
  139. return 1;
  140. }
  141. #-----------------------------------------------------------------------------
  142. sub FetchSignedFiles
  143. {
  144. my ( $pShareName ) = @_;
  145. my ( $src, $dest, $from, $to );
  146. my $name2 = $name;
  147. $name2 = "xp$name2" if $final and $name2 !~ /^q/i;
  148. for (my $inx=0; $inx< @tableHash; $inx++)
  149. {
  150. $src = "$pShareName\\$ENV{_buildArch}$ENV{_buildType}.$lang.$tableHash[$inx]->{ AltName }";
  151. $dest = "$ENV{_ntpostbld}\\$tableHash[$inx]->{ Filename }";
  152. $src =~ s/\%name\%/$name2/ig;
  153. $dest =~ s/\%name\%/$name2/ig;
  154. next if( !( -e $src ) );
  155. &comlib::ExecuteSystem( "move /y $src $dest" );
  156. }
  157. return 1;
  158. }
  159. #-----------------------------------------------------------------------------
  160. sub VerifySignedFiles
  161. {
  162. my ( $pShareName ) = @_;
  163. my ( $fileName );
  164. my $name2 = $name;
  165. $name2 = "xp$name2" if $final and $name2 !~ /^q/i;
  166. for (my $inx=0; $inx< @tableHash; $inx++)
  167. {
  168. $fileName = "$pShareName\\$ENV{_buildArch}$ENV{_buildType}.$lang.$tableHash[$inx]->{ AltName }";
  169. $fileName =~ s/\%name\%/$name2/ig;
  170. ###Verify exists
  171. next if( !( -e $fileName ) );
  172. ###Verify Chktrust
  173. if( !&comlib::ExecuteSystem( "chktrust -q $fileName" ) )
  174. {
  175. errmsg( "[$fileName] failed on chktrust.exit");
  176. return 0;
  177. }
  178. ###Verify if cat files are official signed
  179. #lc( $fileName );
  180. #next if( $fileName !~ /^(.+)\.cat$/ );
  181. if( !&comlib::ExecuteSystem( "findstr /ic:\"Microsoft Root Authority\" $fileName >nul 2>nul" ) )
  182. {
  183. errmsg( "Found [$fileName] contains testroot.cert, exit." );
  184. return 0;
  185. }
  186. }
  187. for my $sku ( @prodSkus )
  188. {
  189. my $chkFile = "$ENV{_ntpostbld}\\$skusDirName{ $sku}\\layout.inf";
  190. if( !system( "findstr /i /l testroot $chkFile >NUL 2>NUL" ) )
  191. {
  192. errmsg( "Found [$chkFile] contains testroot.cert, exit." );
  193. return 0;
  194. }
  195. }
  196. return 1;
  197. }
  198. #-----------------------------------------------------------------------------
  199. sub ErrorCheck
  200. {
  201. #####Check error logs
  202. if( -e $ENV{errfile} && !(-z $ENV{errfile}) )
  203. {
  204. $ENV{errfile} =~ /(.*)\.tmp$/;
  205. errmsg( $dash );
  206. errmsg("Please check error at $1");
  207. return 0;
  208. }
  209. return 1;
  210. }
  211. #-----------------------------------------------------------------------------
  212. sub build_name
  213. {
  214. return $name if $name =~ /^q/i;
  215. my $buildPath="$ENV{_ntpostbld}\\congeal_scripts";
  216. my $buildFileName="__qfenum__";
  217. if (-e "$buildPath\\$buildFileName") {
  218. open F,"$buildPath\\$buildFileName" or die "unable to ipen $buildPath\\$buildFileName ";
  219. my $buildNumber=<F>;
  220. if ( $buildNumber=~/^QFEBUILDNUMBER=(\d*)$/ ){
  221. return $1;
  222. }
  223. else{
  224. wrnmsg "$buildPath\\$buildFileName format is not correct. Defaulting to 9999";
  225. return 9999;
  226. }
  227. close F;
  228. }
  229. else {
  230. wrnmsg "$buildPath\\$buildFileName not found. Defaulting to 9999";
  231. return 9999;
  232. }
  233. }
  234. 1;