Hi,
I've combined the ShowPerms.pl from Win32::Perms, with traverse.pl,
attempting to turn the showperms section into another subroutine to be
called.
When I specify a file, I expect it to only dump the perms of that file,
however it comes back with three copies of the perms from '.' and then dumps
the perms of all the files in the current directory.
Any Suggestions?
8<---------------------Begin recperms.pl------------>8
#!/usr/bin/perl
#record Perms.
&traverse('.');
sub traverse {
local($dir) = shift;
local($path);
unless (opendir(DIR, $dir)) {
warn "Can't open $dir\n";
closedir(DIR);
return;
}
foreach (readdir(DIR)) {
next if $_ eq '.' || $_ eq '..';
$path = "$dir/$_";
if (-d $path) { # a directory
ShowPerm($path);
&traverse($path);
} elsif (-f _) { # a plain file
ShowPerm($path);
# or do something you want to
}
}
closedir(DIR);
}
sub ShowPerm {
use Win32::Perms;
%PERM = (
R => 0,
W => 1,
X => 2,
D => 3,
P => 4,
O => 5,
A => 6,
);
%MAP = (
'FILE_READ_DATA' => 'R',
'GENERIC_READ' => 'R',
'KEY_READ' => 'R',
'FILE_WRITE_DATA' => 'W',
'KEY_WRITE' => 'W',
'GENERIC_WRITE' => 'W',
'DELETE' => 'D',
'FILE_DELETE_CHILD' => 'D',
'FILE_EXECUTE' => 'X',
'FILE_TRAVERSE' => 'X',
'GENERIC_EXECUTE' => 'X',
'CHANGE_PERMISSION' => 'P',
'TAKE_OWNERSHIP' => 'O',
'FILE_ALL_ACCESS' => 'A',
'GENERIC_ALL' => 'A',
'STANDARD_RIGHTS_ALL' => 'A',
);
$Path = "$path";
print "\nDumping permissions for '$Path':\n";
GetPerms( $Path );
print "\n\n";
} #End of SUB ShowPerms.
sub GetPerms
{
my( $Path ) = @_;
my( $Acct, @List );
my( $Perm ) = new Win32::Perms( $Path );
if( ! $Perm )
{
print "Can not obtain permissions for '$Path'\n";
return;
};
$Perm->Dump( \@List );
foreach $Acct ( @List )
{
my( $Perm );
my( @String ) = split( //, "-" x scalar( keys( %PERM ) ) );
my( $Mask, @M, @F );
my( $DaclType );
next if( $Acct->{Entry} ne "DACL" );
$iTotal++;
DecodeMask( $Acct, \@M, \@F );
foreach $Mask ( @M )
{
$Perm |= 2**$PERM{ $MAP{$Mask} };
}
foreach $Mask ( keys( %PERM ) )
{
$String[$PERM{$Mask}] = $Mask if( $Perm & 2**$PERM{$Mask} )
;
}
$DaclType = $Acct->{ObjectName};
if( 2 == $Acct->{ObjectType} )
{
# We have either a file or directory. Therefore we need to
# figure out if this DACL represents an object (file) or
# a container (dir)...
if( $Acct->{Flag} & DIR )
{
$DaclType = "Directory";
}
else
{
$DaclType = "File";
}
}
printf( " % 20s % -11s %s\n", $Acct->{Account}, "($DaclType)",
join( '', @String ) );
}
if( ! $iTotal )
{
print "\t Everyone has full permissions.\n";
}
}
_______________________________________________
Perl-Win32-Admin mailing list
[EMAIL PROTECTED]
http://listserv.ActiveState.com/mailman/listinfo/perl-win32-admin