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.

337 lines
10 KiB

  1. @echo off
  2. REM ------------------------------------------------------------------
  3. REM
  4. REM submit.cmd
  5. REM Submit files for PRS signing
  6. REM
  7. REM Copyright (c) Microsoft Corporation. All rights reserved.
  8. REM
  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 ParseArgs;
  18. use Logmsg;
  19. use Win32::OLE qw(in);
  20. use comlib;
  21. use File::Basename;
  22. #
  23. # UPDATE DATA: Default values for various things...
  24. #
  25. my $JobDescriptionFormat = "%s (%s)";
  26. my $SignedFileUrlDefault = "http://www.microsoft.com/windows";
  27. my $SignersDefault = "aesquiv surajp jeremyd jfeltis jtolman miker mlekas wadela dmiura sergueik suemiaor tsanders tokuroy piperpg jorgeba";
  28. $ENV{script_name} = basename( $0 );
  29. sub Usage {
  30. print<<USAGE;
  31. $ENV{script_name} <path_to_files> [-cert:<id>][-signer:<alias>][-url:<url>] [-wait]
  32. <path_to_files> submit all files in this directory. Required parameter.
  33. -signer:<alias> Indicate who can approve this request. Repeat option once
  34. for each person who can approve the request.
  35. Default is '$SignersDefault'.
  36. -cert:<id> Certificate to use. Can be a decimal value or the name
  37. of a known certs - "buildlab", "fusion", or "external".
  38. Default is buildlab cert, ID #15.
  39. -url:<url> URL to use on the signed files. This shows up in the
  40. final certificate.
  41. Default is currently '$SignedFileUrlDefault'.
  42. -wait wait for request to be signed.
  43. USAGE
  44. exit(1)
  45. }
  46. my ( $filePath, $cert, @signers,$signedFileUrl, $wait );
  47. my ( $certName, $displayName );
  48. my ( %jobInfo, $request, $certName );
  49. timemsg( "Start $ENV{script_name}" );
  50. exit(1) if( !&GetParams() );
  51. exit(1) if( !&InitVars() );
  52. exit(1) if( !&SubmitRequest() );
  53. exit(1) if( $wait && !&LookupStatus() );
  54. timemsg( "Complete successfully" );
  55. exit(0);
  56. #-----------------------------------------------------------------------------
  57. sub GetParams
  58. {
  59. # Validate params and build of the data we need to do the submit
  60. parseargs('?' => \&Usage,
  61. 'signer:' => \@signers,
  62. 'cert:' => \$cert,
  63. 'url:' => \$signedFileUrl,
  64. 'certname:' => \$certName,
  65. 'displayname:' => \$displayName,
  66. 'wait' => \$wait,
  67. \$filePath );
  68. # Verify file path
  69. if ( !defined $filePath )
  70. {
  71. errmsg( "Invalid arguments -- must specify path to files!" );
  72. print "@ARGV\n";
  73. return 0;
  74. }
  75. if ( ! -e $filePath )
  76. {
  77. errmsg( "Invalid arguments -- path [$filePath] does not exist!" );
  78. print "@ARGV\n";
  79. return 0;
  80. }
  81. # Figure out the Cert ID and Name...
  82. if ( $cert )
  83. {
  84. # Make the srting all lowercase...
  85. my $CertLower;
  86. $CertLower = lc $cert;
  87. #Compare against known certs...
  88. if ( $CertLower eq "buildlab" || $CertLower eq "27" )
  89. {
  90. $jobInfo{CertificateID} = "27";
  91. $certName = "Microsoft Windows XP Publisher" if( !$certName );
  92. }
  93. elsif ( $CertLower eq "fusion" || $CertLower eq "26" )
  94. {
  95. $jobInfo{CertificateID} = "26";
  96. $certName = "Microsoft Fusion Verification" if( !$certName );
  97. }
  98. elsif ( $CertLower eq "external" || $CertLower eq "23" )
  99. {
  100. $jobInfo{CertificateID} = "23" if( !$certName );
  101. $certName = "External Cert";
  102. }
  103. elsif ( $CertLower =~ /^[0-9]+$/ )
  104. {
  105. $jobInfo{CertificateID} = $cert;
  106. $certName = "Cert #$cert" if( !$certName );
  107. }
  108. else
  109. {
  110. errmsg( "Invalid arguments -- -cert:<id> must be a known name or a decimal ID value!" );
  111. print "@ARGV\n";
  112. return 0;
  113. }
  114. }
  115. else
  116. {
  117. # Nothing given - assume buildlab cert...
  118. $jobInfo{CertificateID} = '27';
  119. $certName = "Microsoft Windows XP Publisher" if( !$certName );
  120. }
  121. # Figure out request name format string and build the real req name...
  122. $jobInfo{JobDescription} = sprintf( $JobDescriptionFormat, $certName, $ENV{LANG} );
  123. # Figure out the right URL to use...
  124. $signedFileUrl = $SignedFileUrlDefault if ( ! $signedFileUrl );
  125. # Figure out the proper list of people to sign for this!
  126. @signers = split( / /, $SignersDefault ) if ( !@signers );
  127. $displayName = "Windows XP PRS Catalogs" if( !$displayName );
  128. logmsg( "Source Directory ..[$filePath]" );
  129. logmsg( "Cert ID ...........[$jobInfo{CertificateID}]" );
  130. logmsg( "Signing URL .......[$signedFileUrl]" );
  131. logmsg( "Job Description ...[$jobInfo{JobDescription}]" );
  132. logmsg( "Signers ...........[@signers]" );
  133. logmsg( "Certificate Name ..[$certName]" );
  134. logmsg( "Display Name ......[$displayName]" );
  135. logmsg( "Log file ..........[$ENV{logfile}]" );
  136. logmsg( "Error file ........[$ENV{errfile}]" );
  137. return 1;
  138. }
  139. #-----------------------------------------------------------------------------
  140. sub InitVars
  141. {
  142. my $dash='-' x 60;
  143. logmsg( $dash );
  144. # Instantiate the sign-request object
  145. logmsg( "Creating request using [$certName]..." );
  146. if( ! ($request = Win32::OLE->new('SecureCodeSign.CodeSign')) )
  147. {
  148. errmsg( "Failed to instantiate request object ". Win32::OLE->LastError() );
  149. return 0;
  150. }
  151. if( !$request->Init( "production" ) )
  152. {
  153. errmsg( "Failed to Connect to server and validate permission" );
  154. return 0;
  155. }
  156. foreach ( keys %jobInfo )
  157. {
  158. if ( !( $request->{$_} = $jobInfo{$_} ) )
  159. {
  160. errmsg( "Failed setting $_: ". Win32::OLE->LastError() );
  161. return 0;
  162. }
  163. }
  164. # Gather the files for the submit
  165. my @signFiles = glob "$filePath\\*";
  166. if ( !@signFiles )
  167. {
  168. errmsg( "No files found at [$filePath]" );
  169. return 0;
  170. }
  171. # Get the files object
  172. my $files = $request->SignFiles;
  173. if ( !defined $files )
  174. {
  175. errmsg( "Failed to instantiate file object: ". Win32::OLE->LastError() );
  176. return 0;
  177. }
  178. # Add files to the request
  179. my $dispnamefile = "$ENV{temp}\\displayname.$ENV{_BUILDARCH}$ENV{_BUILDTYPE}.txt";
  180. my @altDisplayNameInfo = ();
  181. push @altDisplayNameInfo, &comlib::ReadFile( $dispnamefile ) if -f $dispnamefile;
  182. foreach my $curFile ( @signFiles )
  183. {
  184. next if( -d $curFile );
  185. my $altName = $displayName;
  186. &ReplaceDisplayName( basename($curFile), \$altName, \@altDisplayNameInfo );
  187. logmsg( "Adding $curFile ($altName)..." );
  188. if ( !$files->add( $curFile, $altName, $signedFileUrl ) )
  189. {
  190. errmsg( "Failed to add file $curFile: ". Win32::OLE->LastError() );
  191. return 0;
  192. }
  193. }
  194. # Get sign-off object
  195. my $signers = $request->Signers;
  196. if ( !defined $signers )
  197. {
  198. errmsg( "Failed to instantiate signers object: ". Win32::OLE->LastError() );
  199. return 0;
  200. }
  201. # Add signers to the request
  202. foreach( @signers )
  203. {
  204. logmsg( "Sign-off from: $_" );
  205. if ( !$signers->add( $_ ) )
  206. {
  207. errmsg( "Failed adding signer $_: ". OLE::Win32->LastError() );
  208. return 0;
  209. }
  210. }
  211. return 1;
  212. }
  213. #-----------------------------------------------------------------------------
  214. sub ReplaceDisplayName
  215. {
  216. my ( $pFileName, $pDisplayName, $pAltDisplayNameInfo ) = @_;
  217. for my $line ( @$pAltDisplayNameInfo )
  218. {
  219. my @mFields = split( /\s+/, $line );
  220. my $name = lc $mFields[0];
  221. if( lc $pFileName =~ /\.\Q$name\E$/ )
  222. {
  223. $mFields[1] =~ s/\;/ /g;
  224. $$pDisplayName = $mFields[1];
  225. last;
  226. }
  227. }
  228. }
  229. #-----------------------------------------------------------------------------
  230. sub SubmitRequest
  231. {
  232. my $dash='-' x 60;
  233. logmsg( $dash );
  234. if ( !$request->Submit() )
  235. {
  236. foreach my $error ( in $request->RequestErrors )
  237. {
  238. errmsg( "Failed to submit: " . $error->ErrorNumber." - ". $error->ErrorDescription );
  239. }
  240. return 0;
  241. }
  242. logmsg( "Request was successfully submitted. ID #". $request->JobID );
  243. return 1;
  244. }
  245. #-----------------------------------------------------------------------------
  246. sub LookupStatus
  247. {
  248. my %status = ( 1 => 'Pre-Activation',
  249. 2 => 'Waiting for Sign-Off',
  250. 3 => 'Waiting for Virus Check',
  251. 5 => 'Waiting for Digital Signature',
  252. 6 => 'Waiting for Time Stamp',
  253. 7 => 'Waiting to be posted to signed server',
  254. 8 => 'Complete. Posted to Signed Server',
  255. 30 => 'Problem Occurred (contact signhelp to reactivate request)',
  256. 60 => 'Failed: Signer Rejected Job',
  257. 64 => 'Could not strong name sign one or more files',
  258. 65 => 'Failed: Automatic Handoff Failed',
  259. 66 => 'Failed: Virus Found',
  260. 67 => 'Failed: Couldn�t Digitally Sign One or More Files',
  261. 68 => 'Failed: Couldn�t Time Stamp One or More Files',
  262. 69 => 'Failed: Job Inactive Too Long',
  263. 70 => 'Administratively Failed',
  264. 71 => 'Waiting for manual review',
  265. 72 => 'On Hold For Phone Verification' );
  266. logmsg( "Waiting for request to complete ..." );
  267. while (1)
  268. {
  269. if ( !$request->UpdateStatus($request->JobID) )
  270. {
  271. errmsg( "Failed determining request status: ". Win32::OLE->LastError() );
  272. return 0;
  273. }
  274. timemsg( "Status = $status{$request->Status}" );
  275. last if( $request->status == 8 );
  276. #return ( &MailSignhelp() ) if( $request->status == 30 );
  277. return 0 if( $request->status >= 30 );
  278. sleep 60;
  279. }
  280. logmsg( "Signing request complete, pickup at " . $request->SignedPath );
  281. return 1;
  282. }
  283. #-----------------------------------------------------------------------------
  284. 1;
  285. __END__
  286. :endperl
  287. @echo off
  288. if not defined seterror (
  289. set seterror=
  290. for %%a in ( seterror.exe ) do set seterror=%%~$PATH:a
  291. )
  292. @%seterror% %RETURNVALUE%