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
This commit is contained in:
Bart Van Assche
2012-06-29 13:43:36 +00:00
parent d811c1374c
commit db5b92274a

View File

@@ -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;
}