1#!/usr/bin/perl 2# 3# Copyright (C) 2009, 2012 Internet Systems Consortium, Inc. ("ISC") 4# 5# Permission to use, copy, modify, and/or distribute this software for any 6# purpose with or without fee is hereby granted, provided that the above 7# copyright notice and this permission notice appear in all copies. 8# 9# THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH 10# REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY 11# AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT, 12# INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM 13# LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE 14# OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR 15# PERFORMANCE OF THIS SOFTWARE. 16 17# Id 18 19# setpk11provider.pl 20# This script sets the PKCS#11 provider name in the build scripts. 21# 22# for instance: setpk11provider.pl bp201w32HSM 23# 24 25if ($#ARGV != 0) { 26 die "Usage: perl setpk11provider.pl <pkcs11_provider_dll_name>\n" 27} 28 29my $provider=$ARGV[0]; 30 31$provider =~ s|\.[dD][lL][lL]$||; 32 33# List of files that need to be updated 34@filelist = ("../bin/pkcs11/win32//pk11keygen.mak", 35 "../bin/pkcs11/win32//pk11keygen.dsp", 36 "../bin/pkcs11/win32//pk11list.mak", 37 "../bin/pkcs11/win32//pk11list.dsp", 38 "../bin/pkcs11/win32//pk11destroy.mak", 39 "../bin/pkcs11/win32//pk11destroy.dsp"); 40 41# function to replace the provider define 42sub updatefile { 43 my($filename, $substr, $line); 44 my(@Lines); 45 46 $filename = $_[0]; 47 $substr = $_[1]; 48 49 open (RFILE, $filename) || die "Can't open file $filename: $!"; 50 @Lines = <RFILE>; 51 close (RFILE); 52 53 # Replace the string 54 foreach $line (@Lines) { 55 $line =~ s/unknown_provider/$substr/gi; 56 } 57 #update the file 58 open (RFILE, ">$filename") || die "Can't open file $filename: $!"; 59 foreach $line (@Lines) { 60 print RFILE $line; 61 } 62 close(RFILE); 63} 64 65# update config.h to define or undefine USE_PKCS11 66sub updateconfig { 67 my($havexml, $substr, $line); 68 my(@Lines); 69 70 $havexml = $_[0]; 71 72 open (RFILE, "../config.h") || die "Can't open config.h"; 73 @Lines = <RFILE>; 74 close (RFILE); 75 76 foreach $line (@Lines) { 77 if ($havexml) { 78 $line =~ s/^.*#undef USE_PKCS11.*$/define USE_PKCS11 1/; 79 } else { 80 $line =~ s/^#define USE_PKCS11 .*$/\/\* #undef USE_PKCS11 \*\//; 81 } 82 } 83 84 open (RFILE, ">../config.h") || die "Can't open config.h"; 85 print "Updating file ../config.h\n"; 86 foreach $line (@Lines) { 87 print RFILE $line; 88 } 89 close(RFILE); 90} 91 92#Update the list of files 93if ($provider ne 0) { 94 $ind = 0; 95 print "Provider is $provider\n"; 96 foreach $file (@filelist) { 97 print "Updating file $file\n"; 98 updatefile($file, $provider); 99 $ind++; 100 } 101 updateconfig(1); 102} else { 103 updateconfig(0); 104} 105 106