Advanced-Config
view release on metacpan or search on metacpan
lib/Advanced/Config/Reader.pm view on Meta::CPAN
# Doing some accounting to make sure any sensitive data doesn't
# show up in the fish logs from now on.
if ( $mask && ! $mask_flag ) {
$mask_flag = 1;
DBUG_PAUSE ();
DBUG_MASK ( 0 );
}
if ( $do_mod_lookup ) {
my $m;
($val, $m) = apply_modifier ( $config, $val, $mod_tag, $mod_opt, $mod_val, $file );
if ( $m == -2 ) {
# The name of the variable changed & points to an encrypted value.
$val = $opts->{variable_left} . ${val} . $opts->{variable_right};
} elsif ( $m && ! $mask_flag ) {
$mask_flag = 1;
DBUG_PAUSE ();
DBUG_MASK ( 0 );
}
}
# Rebuild the output string so we can look for more variables ...
if ( defined $val ) {
$output = $left . $val . $right;
} else {
$output = $left . $right;
}
# Get the next variable to evaluate ...
($left, $tag, $right, $cmt_flag, $mod_tag, $mod_opt, $mod_val, $ot) =
parse_for_variables ( $output, 0, $opts );
} # End while ( defined $tag ) loop ...
# Restore all place holders back into the output string with the
# proper variable name. Have to assume still sensitive even if
# all the placeholders drop out. Since can't tell what else may
# have triggered it.
if ( $mask_flag == -1 ) {
$mask_flag = 1; # Mark sensitive ...
foreach ( keys %encrypt_vars ) {
my $val = $opts->{variable_left} . $encrypt_vars{$_} . $opts->{variable_right};
$mask_flag = -1 if ( $output =~ s/$_/$val/ );
}
}
# Did the variable substitution result in the need to trim things?
if ( $trim_flag ) {
$output =~ s/^\s+//;
$output =~ s/\s+$//;
}
DBUG_RETURN ( $output, $mask_flag );
}
# ==============================================================
=item ($v[, $s]) = apply_modifier ( $config, $value, $tag, $rule, $sub_rule, $file )
This is a helper method to F<expand_variables>. Not for public use.
This function takes the rule specified by I<$rule> and applies it against
the I<$value> with assistance from the I<$sub_rule>.
It returns the edited I<value> and whether applying the modifier made it
I<sensitive>. (-1 means it's an encrypted value. -2 means it's the variable
name that resolves to an encrypted value. 0 - Non-sensitive, 1 - Sensitive.)
See L<https://web.archive.org/web/20200309072646/https://wiki.bash-hackers.org/syntax/pe>
for information on how this can work. This module supports most of the
parameter expansions listed there except for those dealing with arrays. Other
modifier rules may be added upon request.
=cut
# NOTE1: Fish has already been paused if $tag is sensitive. Since this method
# has no idea if the current tag is sensitive or not.
# NOTE2: But still need to mask the return value if referencing sensitive data
# in case the original $tag wasn't sensitive. So in most cases it will
# return not-sensitive even if fish has already been paused!
#
# NOTE3: If sensitive/mask is -1, it's sensitive and not decrypted. In this
# case the returned value is the tag's name, not it's value!
sub apply_modifier
{
DBUG_ENTER_FUNC ( @_ );
my $cfg = shift;
my $value = shift; # The value for ${mod_tag} ...
my $mod_tag = shift; # The tag to apply the rule against!
my $mod_opt = shift; # The rule ...
my $mod_val = shift; # The sub-rule ...
my $file = shift; # The file the tag's from.
my $alt_val = (defined $value) ? $value : "";
# The values to return ...
my $output;
# Values: 0 - Normal non-sensitive return value (99.9% of the time)
# 1 - Sensitive return value.
# -1 - Return value is encrypted.
# -2 - Return value is variable name of encrypted value.
my $mask = 0;
# If looking for a default value ...
if ( ( $mod_opt eq ":+" && $alt_val ne "" ) ||
( $mod_opt =~ m/^:[-=?]$/ && $alt_val eq "" ) ||
( $mod_opt eq "+" && defined $value ) ||
( $mod_opt =~ m/^[-=?]$/ && ! defined $value ) ) {
$output = $mod_val; # Now uses this value as it's default!
if ( $mod_opt eq ":=" || $mod_opt eq "=" ) {
# The variable either doesn't exist or it resolved to "".
# This variant rule says to also set the variable to this value!
$cfg->_base_set ( $mod_tag, $output, $file );
} elsif ( $mod_opt eq ":?" || $mod_opt eq "?" ) {
# In shell scripts, ":?" would cause your script to die with the
( run in 0.713 second using v1.01-cache-2.11-cpan-39bf76dae61 )