os/security/cryptoservices/certificateandkeymgmt/twtlscert/scripts/batchfiles/certstorePlugins
author sl@SLION-WIN7.fritz.box
Fri, 15 Jun 2012 03:10:57 +0200
changeset 0 bde4ae8d615e
permissions -rw-r--r--
First public contribution.
sl@0
     1
#!/usr/bin/perl -w
sl@0
     2
sl@0
     3
# pluginScript.pl
sl@0
     4
#
sl@0
     5
# Controls the availability of cert store plugins on the emulator, for testing
sl@0
     6
# purposes.  
sl@0
     7
sl@0
     8
$UsageMessage = <<"EOF";
sl@0
     9
usage:
sl@0
    10
  pluginScript disable PLUGIN
sl@0
    11
    Disable the specified plugin by moving it to a backup location
sl@0
    12
  pluginScript disable_all
sl@0
    13
    Disable all plugins
sl@0
    14
  pluginScript enable PLUGIN
sl@0
    15
    Enable the specified plugin by copying the backup to its original location
sl@0
    16
  pluginScript list PLATFORM BUILD
sl@0
    17
    List the currently enabled plugins for the specified platform and build
sl@0
    18
    (default is winscw udeb)
sl@0
    19
EOF
sl@0
    20
sl@0
    21
@plugins = ('filecertstore.dll',
sl@0
    22
			'tadditionalstores.dll',
sl@0
    23
			'tadditionalstoressoftware.dll',
sl@0
    24
			'wapcertstore.dll',
sl@0
    25
 			'swicertstoreplugin.dll',
sl@0
    26
 			'thwsimstores.dll',
sl@0
    27
 			'thwuiccstores.dll',
sl@0
    28
 			'thwwimstores.dll',
sl@0
    29
			'tDeviceImmutablestores.dll',
sl@0
    30
 			'MIDP2CertStore.dll');
sl@0
    31
sl@0
    32
@platforms = ('wins', 'winscw');
sl@0
    33
sl@0
    34
@builds = ('udeb', 'urel');
sl@0
    35
sl@0
    36
$EpocRoot = $ENV{'EPOCROOT'} . "epoc32";
sl@0
    37
sl@0
    38
sub usage()
sl@0
    39
{
sl@0
    40
	die $UsageMessage;
sl@0
    41
}
sl@0
    42
sl@0
    43
sub copyFile($$)
sl@0
    44
{
sl@0
    45
	my ($from, $to) = @_;
sl@0
    46
	print "Copying $from -> $to\n";
sl@0
    47
	die "Can't copy: $!" unless system("cmd", "/c", "copy", $from, $to) == 0;
sl@0
    48
}
sl@0
    49
sl@0
    50
sub deleteFile($)
sl@0
    51
{
sl@0
    52
	my ($file) = @_;
sl@0
    53
	print "Deleting $file\n";
sl@0
    54
	die "Can't delete '$file': $!" unless unlink $file;
sl@0
    55
}
sl@0
    56
sl@0
    57
sub ensureDir($)
sl@0
    58
{
sl@0
    59
	my ($dir) = @_;
sl@0
    60
	if (! -d $dir)
sl@0
    61
	{
sl@0
    62
		print "Creating $dir\n";
sl@0
    63
		die "Can't create dir '$dir': $!" unless mkdir $dir;
sl@0
    64
	}
sl@0
    65
}
sl@0
    66
sl@0
    67
sub isSecure($)
sl@0
    68
{
sl@0
    69
	my ($plugin) = @_;
sl@0
    70
	$plugin =~ s/\.dll/.rsc/i;
sl@0
    71
	return -f "$EpocRoot\\data\\z\\resource\\plugins\\$plugin"
sl@0
    72
}
sl@0
    73
sl@0
    74
sub pluginDir($$)
sl@0
    75
{
sl@0
    76
	my ($plugin, $path) = @_;
sl@0
    77
sl@0
    78
	if (isSecure($plugin))
sl@0
    79
	{
sl@0
    80
		return "$path";
sl@0
    81
	}
sl@0
    82
	else
sl@0
    83
	{
sl@0
    84
		return "$path\\z\\system\\libs\\plugins";
sl@0
    85
	}
sl@0
    86
}
sl@0
    87
sl@0
    88
sub backupDir($$)
sl@0
    89
{
sl@0
    90
	my ($plugin, $path) = @_;
sl@0
    91
sl@0
    92
	if (isSecure($plugin))
sl@0
    93
	{
sl@0
    94
		return "$path\\plugins_backup";
sl@0
    95
	}
sl@0
    96
	else
sl@0
    97
	{
sl@0
    98
		return "$path\\z\\system\\libs\\plugins_backup";
sl@0
    99
	}
sl@0
   100
}
sl@0
   101
sl@0
   102
sub disable($)
sl@0
   103
{
sl@0
   104
	my ($plugin) = @_;
sl@0
   105
sl@0
   106
	for my $platform (@platforms)
sl@0
   107
	{
sl@0
   108
		for my $build (@builds)
sl@0
   109
		{
sl@0
   110
			my $path = "$EpocRoot\\release\\$platform\\$build";
sl@0
   111
sl@0
   112
			my $backupDir = backupDir($plugin, $path);
sl@0
   113
			my $pluginDir = pluginDir($plugin, $path);
sl@0
   114
			my $pluginFile = "$pluginDir\\$plugin";
sl@0
   115
			my $backupFile = "$backupDir\\$plugin";
sl@0
   116
sl@0
   117
			if (-f $pluginFile)
sl@0
   118
			{
sl@0
   119
				# Always copy, in case plugin has been rebuilt
sl@0
   120
				ensureDir($backupDir);
sl@0
   121
				copyFile($pluginFile, $backupDir);
sl@0
   122
sl@0
   123
				deleteFile($pluginFile);
sl@0
   124
			}
sl@0
   125
		}
sl@0
   126
	}
sl@0
   127
}
sl@0
   128
sl@0
   129
sub disableAll()
sl@0
   130
{
sl@0
   131
	for my $plugin (@plugins)
sl@0
   132
	{
sl@0
   133
		disable($plugin)
sl@0
   134
	}
sl@0
   135
}
sl@0
   136
sl@0
   137
sub enable($)
sl@0
   138
{
sl@0
   139
	my ($plugin) = @_;
sl@0
   140
sl@0
   141
	for my $platform (@platforms)
sl@0
   142
	{
sl@0
   143
		for my $build (@builds)
sl@0
   144
		{
sl@0
   145
			my $path = "$EpocRoot\\release\\$platform\\$build";
sl@0
   146
sl@0
   147
			my $backupDir = backupDir($plugin, $path);
sl@0
   148
			my $pluginDir = pluginDir($plugin, $path);
sl@0
   149
			my $pluginFile = "$pluginDir\\$plugin";
sl@0
   150
			my $backupFile = "$backupDir\\$plugin";
sl@0
   151
sl@0
   152
			if (! -f $pluginFile && -f $backupFile)
sl@0
   153
			{
sl@0
   154
				copyFile($backupFile, $pluginDir);					
sl@0
   155
			}
sl@0
   156
		}
sl@0
   157
	}
sl@0
   158
}
sl@0
   159
sl@0
   160
sub list($$)
sl@0
   161
{
sl@0
   162
	my ($platform, $build) = @_;	
sl@0
   163
	my $path = "$EpocRoot\\release\\$platform\\$build";
sl@0
   164
sl@0
   165
	printf "%-32s %-12s %s\n",  "Plugin:", "Type:", "Status:";
sl@0
   166
sl@0
   167
	for my $plugin (@plugins)
sl@0
   168
	{
sl@0
   169
		my $secure = isSecure($plugin);
sl@0
   170
		my $enabled = 0;
sl@0
   171
sl@0
   172
		if ($secure)
sl@0
   173
		{
sl@0
   174
			$enabled = -f "$path\\$plugin";
sl@0
   175
		}
sl@0
   176
		else
sl@0
   177
		{
sl@0
   178
			$enabled = -f "$path\\z\\system\\libs\\plugins\\$plugin";
sl@0
   179
		}
sl@0
   180
sl@0
   181
		my $secureMess = $secure ? 'secure' : 'old-style';
sl@0
   182
		my $enabledMess = $enabled ? 'enabled' : 'disabled';
sl@0
   183
sl@0
   184
		printf "%-32s %-12s %s\n",  $plugin, $secureMess, $enabledMess;
sl@0
   185
	}
sl@0
   186
}
sl@0
   187
sl@0
   188
sub main(@)
sl@0
   189
{
sl@0
   190
	my $action = shift || usage();
sl@0
   191
	if ($action eq 'backup_all')
sl@0
   192
	{
sl@0
   193
		backupAll();
sl@0
   194
	}
sl@0
   195
	elsif ($action eq 'disable')
sl@0
   196
	{
sl@0
   197
		my $plugin = shift || usage();
sl@0
   198
		usage() unless grep { $_ eq $plugin } @plugins;
sl@0
   199
		disable($plugin);
sl@0
   200
	}
sl@0
   201
	elsif ($action eq 'disable_all')
sl@0
   202
	{
sl@0
   203
		disableAll();
sl@0
   204
	}
sl@0
   205
	elsif ($action eq 'enable')
sl@0
   206
	{
sl@0
   207
		my $plugin = shift || usage();
sl@0
   208
		usage() unless grep { $_ eq $plugin } @plugins;
sl@0
   209
		enable($plugin);
sl@0
   210
	}
sl@0
   211
	elsif ($action eq 'list')
sl@0
   212
	{
sl@0
   213
		my $platform = shift || 'winscw';
sl@0
   214
		my $build = shift || 'udeb';
sl@0
   215
		usage() unless grep { $_ eq $platform } @platforms;
sl@0
   216
		usage() unless grep { $_ eq $build } @builds;
sl@0
   217
		list($platform, $build);
sl@0
   218
	}
sl@0
   219
	else
sl@0
   220
	{
sl@0
   221
		usage();
sl@0
   222
	}
sl@0
   223
}
sl@0
   224
sl@0
   225
main(@ARGV);