From b13781541b95c407d9f60583227c4790fa1d9b43 Mon Sep 17 00:00:00 2001 From: Valko Laszlo Date: Mon, 27 Aug 2018 03:34:28 +0200 Subject: [PATCH] Implemented variable support in directory type package acl keyword. --- pkgtool.pm | 43 +++++++++++++++++++++++++++---------------- 1 file changed, 27 insertions(+), 16 deletions(-) diff --git a/pkgtool.pm b/pkgtool.pm index 16893d3..8501ce3 100644 --- a/pkgtool.pm +++ b/pkgtool.pm @@ -602,10 +602,17 @@ sub get_default_dnsdomain () return $found; } -sub is_part_of_domain () +sub is_part_of_domain (;$) { + my ($vars) = @_; + my $wbem = get_wbem_info(); - return defined $wbem && $$wbem{'PartOfDomain'}; + if (defined $wbem && $$wbem{'PartOfDomain'}) { + $$vars{'current_domain'} = $$wbem{Domain}; + return 1; + } + $$vars{'current_domain'} = ''; + return 0; } sub get_registry_value ($) @@ -2217,9 +2224,9 @@ sub patchdef_check_availability ($$$$) return ($condition); } -sub pkg_check_condition ($$$) +sub pkg_check_condition ($$$$) { - my ($pkg, $name, $config) = @_; + my ($pkg, $name, $config, $pvars) = @_; my $condition = $$pkg{condition}; return (undef, undef) unless defined $condition; @@ -2231,6 +2238,7 @@ sub pkg_check_condition ($$$) my $error; ($condition, $error) = check_condition('global', $vars, $condition); return (undef, $error) unless defined $condition; + $$pvars = $vars; return ($condition); } @@ -3208,13 +3216,16 @@ sub handle_mbr ($$$$) return 1; } -sub do_acls ($$$) +sub do_acls ($$$$) { - my ($pkg, $directory, $acls) = @_; + my ($pkg, $vars, $directory, $acls) = @_; foreach my $acl (@$acls) { my $sourcefile = $ENV{systemroot}.'\\System32\\icacls.exe'; + print_log('global', INFO, 'acl list: %s', join(',', @$acl)); + $acl = [map { substitute_variables($vars, $_, 0, undef, 'global') } @$acl]; my $paramlist = [$directory, @$acl]; + print_log('global', INFO, 'param list: %s', join(',', @$paramlist)); my $result = []; my ($error, $exitcode) = run_exe('global', undef, undef, undef, $sourcefile, $paramlist, 0, $result); if (defined $error) { @@ -3225,9 +3236,9 @@ sub do_acls ($$$) return 1; } -sub do_directory ($$) +sub do_directory ($$$) { - my ($pkg, $directory) = @_; + my ($pkg, $vars, $directory) = @_; if (! -d $directory) { print_log('global', DEBUG1, 'Creating directory %s', $directory); @@ -3237,7 +3248,7 @@ sub do_directory ($$) } my $acls = $$pkg{acls}; if (defined $acls) { - my $rc = do_acls($pkg, $directory, $acls); + my $rc = do_acls($pkg, $vars, $directory, $acls); if (! $rc) { print_log('global', DEBUG1, 'Removing directory %s', $directory); if (! rmdir($directory)) { @@ -3250,13 +3261,11 @@ sub do_directory ($$) return 1; } -sub handle_directory ($$$$$) +sub handle_directory ($$$$$$) { - my ($config, $pkg, $base_directory, $counters, $update) = @_; + my ($config, $pkg, $vars, $base_directory, $counters, $update) = @_; my $name = $$pkg{name}; - my $vars = get_default_vars($config); - set_datetime_vars($vars); my $directory = substitute_variables($vars, $$pkg{'directory'}, 1, $base_directory, 'global'); my $found = -d $directory; @@ -3269,7 +3278,7 @@ sub handle_directory ($$$$$) print_log('global', WARNING, 'Directory %s to create: %s does not exist - %s', $name, $directory, $update? 'creating' : 'CREATE'); if ($update) { - my $rc = do_directory($pkg, $directory); + my $rc = do_directory($pkg, $vars, $directory); if (! $rc) { push @{$$counters{FailList}}, $name; $$counters{FailCount}++; @@ -3422,8 +3431,10 @@ sub handle_pkg ($$$$$$) { my ($config, $base_directory, $db, $pkg, $counters, $update) = @_; + my $vars; + my $pvars = \$vars; my $name = $$pkg{name}; - my ($condcheck, $error) = pkg_check_condition($pkg, $name, $config); + my ($condcheck, $error) = pkg_check_condition($pkg, $name, $config, $pvars); if (defined $error) { print_log('global', INFO, 'Ignoring package/patch %s: %s', $name, $error); push @{$$counters{FailList}}, $name; @@ -3444,7 +3455,7 @@ sub handle_pkg ($$$$$$) return handle_user($pkg, $counters, $update); } if (defined $$pkg{'directory'}) { - return handle_directory($config, $pkg, $base_directory, $counters, $update); + return handle_directory($config, $pkg, $vars, $base_directory, $counters, $update); } if (defined $$pkg{'mbr-source-file'}) { return handle_mbr($config, $pkg, $counters, $update);