From db5b92274a505aa29985f084a79e8562f6bc03a5 Mon Sep 17 00:00:00 2001 From: Bart Van Assche Date: Fri, 29 Jun 2012 13:43:36 +0000 Subject: [PATCH] scstadmin: Allow hash signs to be escaped Hash signs have to be specified in scst.conf when using the per_portal_acl=1 feature of iSCSI-SCST in combination with LUN masking. Make scstadmin not consider hash signs preceded by a backslash as the start of a comment. Escape backslashes and hash signs when writing out scst.conf. git-svn-id: http://svn.code.sf.net/p/scst/svn/trunk@4391 d57e44dd-8a1f-0410-8b47-8ef2f437770f --- scstadmin/scstadmin.sysfs/scstadmin | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/scstadmin/scstadmin.sysfs/scstadmin b/scstadmin/scstadmin.sysfs/scstadmin index 892d40b90..bf70d3037 100755 --- a/scstadmin/scstadmin.sysfs/scstadmin +++ b/scstadmin/scstadmin.sysfs/scstadmin @@ -1247,6 +1247,17 @@ sub readWorkingConfig { return FALSE; } +# Escape metacharacters (space, backslash and hash sign). +sub escapeMeta { + my $value = shift; + + $value =~ s/([\\\#])/\\\1/g; + if ($value =~ / /) { + $value = "\"$value\""; + } + return $value; +} + # Serialize key attributes. # $prefix: output prefix, e.g. "\t\t". # $attributes: reference to a hash with attributes and their values. @@ -1269,10 +1280,7 @@ sub serializeKeyAttr { my $value = $$attributes{$attribute}->{'keys'}->{$key}->{'value'}; if ($value ne '') { - if ($value =~ / /) { - $value = "\"$value\""; - } - $result .= "$prefix$attribute $value\n"; + $result .= "$prefix$attribute " . escapeMeta($value) . "\n"; } } } elsif ($attribute eq 'enabled' || $attribute eq 'hw_target') { @@ -1305,10 +1313,7 @@ sub serializeNkAttr { && $attribute ne 'hw_target') { my $value = $$attributes{$attribute}->{'value'}; if ($value ne '') { - if ($value =~ / /) { - $value = "\"$value\""; - } - $result .= "$prefix$attribute $value\n"; + $result .= "$prefix$attribute " . escapeMeta($value) . "\n"; } } } @@ -5056,7 +5061,8 @@ sub readConfigFile { if (!$io); while (my $line = <$io>) { - ($line, undef) = split(/\#/, $line, 2); + $line =~ s/^\#.*//; + $line =~ s/[^\\]\#.*//; if ($line =~ /\[(.*)\s+.*\]/) { my $parm = $1; @@ -5069,6 +5075,7 @@ sub readConfigFile { } } + $line =~ s/\\(.)/\1/g; $buffer .= $line; }