Implemented variable support in directory type package acl keyword.

This commit is contained in:
László Valkó 2018-08-27 03:34:28 +02:00
parent 220baf72f9
commit b13781541b

View file

@ -602,10 +602,17 @@ sub get_default_dnsdomain ()
return $found; return $found;
} }
sub is_part_of_domain () sub is_part_of_domain (;$)
{ {
my ($vars) = @_;
my $wbem = get_wbem_info(); 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 ($) sub get_registry_value ($)
@ -2217,9 +2224,9 @@ sub patchdef_check_availability ($$$$)
return ($condition); return ($condition);
} }
sub pkg_check_condition ($$$) sub pkg_check_condition ($$$$)
{ {
my ($pkg, $name, $config) = @_; my ($pkg, $name, $config, $pvars) = @_;
my $condition = $$pkg{condition}; my $condition = $$pkg{condition};
return (undef, undef) unless defined $condition; return (undef, undef) unless defined $condition;
@ -2231,6 +2238,7 @@ sub pkg_check_condition ($$$)
my $error; my $error;
($condition, $error) = check_condition('global', $vars, $condition); ($condition, $error) = check_condition('global', $vars, $condition);
return (undef, $error) unless defined $condition; return (undef, $error) unless defined $condition;
$$pvars = $vars;
return ($condition); return ($condition);
} }
@ -3208,13 +3216,16 @@ sub handle_mbr ($$$$)
return 1; return 1;
} }
sub do_acls ($$$) sub do_acls ($$$$)
{ {
my ($pkg, $directory, $acls) = @_; my ($pkg, $vars, $directory, $acls) = @_;
foreach my $acl (@$acls) { foreach my $acl (@$acls) {
my $sourcefile = $ENV{systemroot}.'\\System32\\icacls.exe'; 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]; my $paramlist = [$directory, @$acl];
print_log('global', INFO, 'param list: %s', join(',', @$paramlist));
my $result = []; my $result = [];
my ($error, $exitcode) = run_exe('global', undef, undef, undef, $sourcefile, $paramlist, 0, $result); my ($error, $exitcode) = run_exe('global', undef, undef, undef, $sourcefile, $paramlist, 0, $result);
if (defined $error) { if (defined $error) {
@ -3225,9 +3236,9 @@ sub do_acls ($$$)
return 1; return 1;
} }
sub do_directory ($$) sub do_directory ($$$)
{ {
my ($pkg, $directory) = @_; my ($pkg, $vars, $directory) = @_;
if (! -d $directory) { if (! -d $directory) {
print_log('global', DEBUG1, 'Creating directory %s', $directory); print_log('global', DEBUG1, 'Creating directory %s', $directory);
@ -3237,7 +3248,7 @@ sub do_directory ($$)
} }
my $acls = $$pkg{acls}; my $acls = $$pkg{acls};
if (defined $acls) { if (defined $acls) {
my $rc = do_acls($pkg, $directory, $acls); my $rc = do_acls($pkg, $vars, $directory, $acls);
if (! $rc) { if (! $rc) {
print_log('global', DEBUG1, 'Removing directory %s', $directory); print_log('global', DEBUG1, 'Removing directory %s', $directory);
if (! rmdir($directory)) { if (! rmdir($directory)) {
@ -3250,13 +3261,11 @@ sub do_directory ($$)
return 1; 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 $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 $directory = substitute_variables($vars, $$pkg{'directory'}, 1, $base_directory, 'global');
my $found = -d $directory; my $found = -d $directory;
@ -3269,7 +3278,7 @@ sub handle_directory ($$$$$)
print_log('global', WARNING, 'Directory %s to create: %s does not exist - %s', print_log('global', WARNING, 'Directory %s to create: %s does not exist - %s',
$name, $directory, $update? 'creating' : 'CREATE'); $name, $directory, $update? 'creating' : 'CREATE');
if ($update) { if ($update) {
my $rc = do_directory($pkg, $directory); my $rc = do_directory($pkg, $vars, $directory);
if (! $rc) { if (! $rc) {
push @{$$counters{FailList}}, $name; push @{$$counters{FailList}}, $name;
$$counters{FailCount}++; $$counters{FailCount}++;
@ -3422,8 +3431,10 @@ sub handle_pkg ($$$$$$)
{ {
my ($config, $base_directory, $db, $pkg, $counters, $update) = @_; my ($config, $base_directory, $db, $pkg, $counters, $update) = @_;
my $vars;
my $pvars = \$vars;
my $name = $$pkg{name}; 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) { if (defined $error) {
print_log('global', INFO, 'Ignoring package/patch %s: %s', $name, $error); print_log('global', INFO, 'Ignoring package/patch %s: %s', $name, $error);
push @{$$counters{FailList}}, $name; push @{$$counters{FailList}}, $name;
@ -3444,7 +3455,7 @@ sub handle_pkg ($$$$$$)
return handle_user($pkg, $counters, $update); return handle_user($pkg, $counters, $update);
} }
if (defined $$pkg{'directory'}) { 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'}) { if (defined $$pkg{'mbr-source-file'}) {
return handle_mbr($config, $pkg, $counters, $update); return handle_mbr($config, $pkg, $counters, $update);