keymon has asked for the wisdom of the Perl Monks concerning the following question:
The script is pasted below. Here's the weird thing. The hash %dhash contains key-value pairs, like these:
BUILTIN\Administrators => 270467583
NT AUTHORITY\SYSTEM => 270467583
Everyone => 1245631
I copy these values into a separate hash, called %hash (sorry about the naming). After the call to Set, the keys in all of my hashes get changed from something like this "BUILTIN\Administrators" to "BUILTIN Administrators". Naturally, the Set() fails in the next iteration.
But I am really confused as to why strings that are not even a part of the manipulation (keys in %dhash and %fhash) are being modified?
-- confused in win32land
#! C:\Perl\bin\perl.exe -w use strict; use File::Find (); use vars qw/*name *dir *prune/; *name = *File::Find::name; *dir = *File::Find::dir; *prune = *File::Find::prune; use Win32::FileSecurity qw(Get Set MakeMask); sub wanted; my %dhash; my %fhash; die "Usage: $0 <path>\n" unless (@ARGV); die "Need dmask.txt file\n" unless (-r "C:\\dmask.txt"); die "Need fmask.txt file\n" unless (-r "C:\\fmask.txt"); open(IN,"<", 'c:\dmask.txt') || die "dmask.txt: $!\n"; while (<IN>) { chomp; my ($id,@mask) = split(/\t/); $dhash{$id} = MakeMask(@mask); } close(IN); open(IN,"<", 'c:\fmask.txt') || die "fmask.txt: $!\n"; while (<IN>) { chomp; my ($id,@mask) = split(/\t/); $fhash{$id} = MakeMask(@mask); } close(IN); # Traverse desired filesystems File::Find::find({wanted => \&wanted}, $ARGV[0]); exit; sub wanted { my %hash; if (-d $name) { if ( Get( $name, \%hash ) ) { my $fix = 0; foreach my $id (keys %dhash) { if ((! exists($hash{$id})) or ($hash{$ +id} != $dh ash{$id})) { $hash{$id} = $dhash{$id}; $fix = 1; } } if ($fix != 0) { Set( $name, \%hash); } } else { print( "Error #", int( $! ), ": $!" ) ; } } elsif (-f $name) { if ( Get( $name, \%hash ) ) { my $fix = 0; foreach my $id (keys %fhash) { if ((! exists($hash{$id})) or ($hash{$ +id} != $fh ash{$id})) { $hash{$id} = $fhash{$id}; $fix = 1; } } if ($fix != 0) { Set( $name, \%hash); } } else { print( "Error #", int( $! ), ": $!" ) ; } } }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Win32::FileSecurity weirdness
by Thelonius (Priest) on Oct 03, 2005 at 09:39 UTC | |
by Anonymous Monk on Oct 03, 2005 at 15:00 UTC | |
|
Re: Win32::FileSecurity weirdness
by keymon (Beadle) on Oct 03, 2005 at 15:12 UTC |