Beat: -T Taintcheck OK auf Windows NOT OK auf UNIX

Beitrag lesen

OK
Ich habe jetzt mal einen wilden patch vorgenommen.

Ich habe $0 ais einer Regex gezogen.
Allerdings muss ich dabei so liberal vorgehen, dass Sicherheit nur besteht, wenn der Anwender den Scriptpfad im configfile vorgibt.

Hier der Beginn des Scripts

  
#!/usr/bin/perl -T  
  
	BEGIN {  
		use CGI::Carp qw(carpout);  
		open(LOG, ">>","error.txt")  or die "Unable to append to error.txt: $!\n";  
		carpout(*LOG);  
$1.'/EHFPlugins';  
	}  
	use warnings;  
	use strict;  
	use lib qw(.);  
	use Digest::SHA1 qw( sha1_hex );  
	use constant { NL => "\n", CRLF => "\015\012"};  
	use Storable qw(lock_store lock_retrieve);  
	use Tie::File;  
	use Encode qw(encode);  
	use URI::Escape;  
	use EHFLang;	# Sprachpaket für ehf-Formulare.  
	my $L = new EHFLang();	# Die Sprache wird nach dem ersten Aufruf von $Store gesetzt  
					# importiert die Funktion t()  translate  
  
# 1.b System Angaben aus config.ehf  
	my %System = (  
			runonce=>0,  
			debug=>0,		# Bitmaske: 1 debug; 2 input; 4 cookies; 8 user; 16 files  
			updatesite=>0,  
			version=>"0.9.6.pre"  
	);  
  
	my %Path = (  
		domain => 'localhost',  
		protokoll=>'http',  
		htmldir => 'html',  
		cgidir => 'cgi',  
		ehfdatadir => 'ehf_html',  
		scriptpath=>'',  
	);  
	$0 =~ /^(.*)$/ and ($Path{scriptpath}) = $1;  
	my $ruopen=0;  
	open( my $config, '<','config.ehf' ) or die ("Kann nicht config.ehf lesen $!");  
	while(<$config>){  
		/^#/ and next;  
		/^domain\s*=\s*([a-zA-Z0-9_.-:]+)\s*$/ and $Path{domain} = $1 and next;  
		/^protokoll\s*=\s*(https?)\s*$/ and $Path{protokoll} = $1 and next;  
		/^htmldir\s*=\s*([A-Za-z0-9_.\/-]+)\s*$/ and $Path{htmldir} = $1 and next;  
		/^cgidir\s*=\s*([A-Za-z0-9_.\/-]+)\s*$/ and $Path{cgidir} = $1 and next;  
		/^ehfdatadir\s*=\s*([A-Za-z0-9_.\/-]+)\s*$/ and $Path{ehfdatadir} = $1 and next;  
		/^ehfupdatefrom\s*=\s*(\S+)\s*$/ and $System{updatesite} = $1 and next;  
		/^ehfdebug\s*=\s*([0-9]+)\s*$/ and $System{debug} = $1 and next;  
		/^scriptpath\s*=\s*"([^"]+)"/ and $Path{scriptpath} = $1 and next;  
		/^runonce=([1-9])/ and $ruopen = 1;  
	}  
	close $config;  
	# Installations-Zugriff.  
	if($ruopen){  
		tie( my @cf , 'Tie::File', 'config.ehf') or die ("Kein Schreibrecht auf config.ehf $!");  
		foreach(@cf){  
			if( /^runonce=([1-9])/ ){  
				$System{runonce} = $1;  
				$1 gt 3  
					? ( $_ = 'runonce=0' )  
					: ( $_ = 'runonce=' . ( $1 + 1 ) );  
			}  
		}  
		untie( @cf );  
	}  
  
  
# 1.c Directory Angaben  
	$Path{scriptpath} =~ s#\\#/#g;  
	( $Path{root}, $Path{cgi}, $Path{scriptname} ) =  
		( $Path{scriptpath} =~ m!^ (.*?/) ($Path{cgidir}/\w+/) ([a-z]+\.pl)$!x );  
	# Der Pfad zum Homedirectory  
	$Path{homedir} = $Path{root} . $Path{htmldir} .'/'. $Path{ehfdatadir};  
	# Der Pfad zum CGI Verzeichnis  
	$Path{cgidir} = $Path{root} . $Path{cgi};  
  
# 1.d URL Angaben  
	# Das Schema, Domain  
	$Path{domurl} = $Path{protokoll} . '://' . $Path{domain};  
	# Die lokale URL zum HTML Verzeichnis, wo die Daten liegen  
	$Path{home} = $Path{domurl} .'/'. $Path{ehfdatadir};  
	# Die lokale URL zum CGI Verzeichnis, wo die Script und Module liegen  
	$Path{cgiurl} = $Path{domurl} . '/'. $Path{cgi};  
	$Path{scripturl} = $Path{cgiurl} . $Path{scriptname};  
  
# 1.e Ergänzung  
	$Path{__datadir} = $Path{homedir} . '/' . '__data/';  
	$Path{__layoutdir} = $Path{homedir} . '/' . '__layouts/';  
	$Path{__themedir} = $Path{homedir} . '/' . '__themes/';  
	$Path{__backupdir} = $Path{homedir} . '/' . '__backups/';  
	$Path{__static} = $Path{homedir} . '/' . '__static/';  
	$Path{userdata} = $Path{homedir} . '/' . 'userdata/';  

Das Script läuft jetzt auch auf dem UNIX mit -T.
Allerdings muss ich noch aller Routinen testen.