setpk11provider.pl revision 247bf378605811d695e968dbe930a7fc45c0038e
1e369379766496d6088982a8e29679efa98d7df9Danny Mayer#!/usr/bin/perl
0c27b3fe77ac1d5094ba3521e8142d9e7973133fMark Andrews#
1e369379766496d6088982a8e29679efa98d7df9Danny Mayer * Copyright (C) 2009, 2012 Internet Systems Consortium, Inc. ("ISC")
0c27b3fe77ac1d5094ba3521e8142d9e7973133fMark Andrews *
0c27b3fe77ac1d5094ba3521e8142d9e7973133fMark Andrews * Permission to use, copy, modify, and/or distribute this software for any
0c27b3fe77ac1d5094ba3521e8142d9e7973133fMark Andrews * purpose with or without fee is hereby granted, provided that the above
1e369379766496d6088982a8e29679efa98d7df9Danny Mayer * copyright notice and this permission notice appear in all copies.
1e369379766496d6088982a8e29679efa98d7df9Danny Mayer *
ec5347e2c775f027573ce5648b910361aa926c01Automatic Updater * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
1e369379766496d6088982a8e29679efa98d7df9Danny Mayer * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
1e369379766496d6088982a8e29679efa98d7df9Danny Mayer * AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
1e369379766496d6088982a8e29679efa98d7df9Danny Mayer * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
1e369379766496d6088982a8e29679efa98d7df9Danny Mayer * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
1e369379766496d6088982a8e29679efa98d7df9Danny Mayer * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
1e369379766496d6088982a8e29679efa98d7df9Danny Mayer * PERFORMANCE OF THIS SOFTWARE.
1e369379766496d6088982a8e29679efa98d7df9Danny Mayer
68c2ccc953059f389cefc0f8a5ce0f83be7458c9Danny Mayer# $Id$
68c2ccc953059f389cefc0f8a5ce0f83be7458c9Danny Mayer
1e369379766496d6088982a8e29679efa98d7df9Danny Mayer# setpk11provider.pl
0c27b3fe77ac1d5094ba3521e8142d9e7973133fMark Andrews# This script sets the PKCS#11 provider name in the build scripts.
0c27b3fe77ac1d5094ba3521e8142d9e7973133fMark Andrews#
68c2ccc953059f389cefc0f8a5ce0f83be7458c9Danny Mayer# for instance: setpk11provider.pl bp201w32HSM
0c27b3fe77ac1d5094ba3521e8142d9e7973133fMark Andrews#
0c27b3fe77ac1d5094ba3521e8142d9e7973133fMark Andrews
68c2ccc953059f389cefc0f8a5ce0f83be7458c9Danny Mayerif ($#ARGV != 0) {
0c27b3fe77ac1d5094ba3521e8142d9e7973133fMark Andrews die "Usage: perl setpk11provider.pl <pkcs11_provider_dll_name>\n"
0c27b3fe77ac1d5094ba3521e8142d9e7973133fMark Andrews}
0c27b3fe77ac1d5094ba3521e8142d9e7973133fMark Andrews
68c2ccc953059f389cefc0f8a5ce0f83be7458c9Danny Mayermy $provider=$ARGV[0];
0c27b3fe77ac1d5094ba3521e8142d9e7973133fMark Andrews
0c27b3fe77ac1d5094ba3521e8142d9e7973133fMark Andrews$provider =~ s|\.[dD][lL][lL]$||;
0c27b3fe77ac1d5094ba3521e8142d9e7973133fMark Andrews
68c2ccc953059f389cefc0f8a5ce0f83be7458c9Danny Mayer# List of files that need to be updated
0c27b3fe77ac1d5094ba3521e8142d9e7973133fMark Andrews@filelist = ("../bin/pkcs11/win32//pk11keygen.mak",
0c27b3fe77ac1d5094ba3521e8142d9e7973133fMark Andrews "../bin/pkcs11/win32//pk11keygen.dsp",
0c27b3fe77ac1d5094ba3521e8142d9e7973133fMark Andrews "../bin/pkcs11/win32//pk11list.mak",
68c2ccc953059f389cefc0f8a5ce0f83be7458c9Danny Mayer "../bin/pkcs11/win32//pk11list.dsp",
0c27b3fe77ac1d5094ba3521e8142d9e7973133fMark Andrews "../bin/pkcs11/win32//pk11destroy.mak",
0c27b3fe77ac1d5094ba3521e8142d9e7973133fMark Andrews "../bin/pkcs11/win32//pk11destroy.dsp");
68c2ccc953059f389cefc0f8a5ce0f83be7458c9Danny Mayer
0c27b3fe77ac1d5094ba3521e8142d9e7973133fMark Andrews# function to replace the provider define
0c27b3fe77ac1d5094ba3521e8142d9e7973133fMark Andrewssub updatefile {
1e369379766496d6088982a8e29679efa98d7df9Danny Mayer my($filename, $substr, $line);
0c27b3fe77ac1d5094ba3521e8142d9e7973133fMark Andrews my(@Lines);
0c27b3fe77ac1d5094ba3521e8142d9e7973133fMark Andrews
0c27b3fe77ac1d5094ba3521e8142d9e7973133fMark Andrews $filename = $_[0];
49549455317f93903b060405d087e33d0c65c2d9Andreas Gustafsson $substr = $_[1];
1e369379766496d6088982a8e29679efa98d7df9Danny Mayer
1e369379766496d6088982a8e29679efa98d7df9Danny Mayer open (RFILE, $filename) || die "Can't open file $filename: $!";
@Lines = <RFILE>;
close (RFILE);
# Replace the string
foreach $line (@Lines) {
$line =~ s/unknown_provider/$substr/gi;
}
#update the file
open (RFILE, ">$filename") || die "Can't open file $filename: $!";
foreach $line (@Lines) {
print RFILE $line;
}
close(RFILE);
}
# update config.h to define or undefine USE_PKCS11
sub updateconfig {
my($havexml, $substr, $line);
my(@Lines);
$havexml = $_[0];
open (RFILE, "../config.h") || die "Can't open config.h";
@Lines = <RFILE>;
close (RFILE);
foreach $line (@Lines) {
if ($havexml) {
$line =~ s/^.*#undef USE_PKCS11.*$/define USE_PKCS11 1/;
} else {
$line =~ s/^#define USE_PKCS11 .*$/\/\* #undef USE_PKCS11 \*\//;
}
}
open (RFILE, ">../config.h") || die "Can't open config.h";
print "Updating file ../config.h\n";
foreach $line (@Lines) {
print RFILE $line;
}
close(RFILE);
}
#Update the list of files
if ($provider ne 0) {
$ind = 0;
print "Provider is $provider\n";
foreach $file (@filelist) {
print "Updating file $file\n";
updatefile($file, $provider);
$ind++;
}
updateconfig(1);
} else {
updateconfig(0);
}