Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Compare Directories/Permissions across all servers

by OzzyOsbourne (Chaplain)
on Mar 23, 2001 at 22:16 UTC ( [id://66689]=sourcecode: print w/replies, xml ) Need Help??
Category: NT Admin
Author/Contact Info OzzyOsbourne
Description:

Uses File::Find and Win32::FileSecurity to dump file permissions to a text file on shares that you specify.

Usage code.pl {share} {outputlog}

Output:server(tab)share(tab)account(tab)permission1(tab)permission2(tab)...(enter)

If the account does not have a permission, the script double tabs, for easy visual inspection.

By importing the resultant tab-delimited log into a spreadsheet program, you can sort by account(colC), then share(colB), then server(colA), to very simply compare directory rights across your file and prints.

Thanks to Tyke.

use strict;
use Win32::FileSecurity qw(Get EnumerateRights);
use File::Find;

my $share=$ARGV[0];
my $out=$ARGV[1];
my ($name,$mask,@rights,%hash,$server,%rights2,@folders,$subfolder,$se
+rvsplit,$subsplit,$right,$item);
my @servers=('SERVERXX','SERVERXX','SERVERXX','SERVERXX','SERVERXX','S
+ERVERXX','SERVERXX','SERVERXX','SERVERXX','SERVERXX','SERVERXX','SERV
+ERXX','SERVERXX','SERVERXX','SERVERXX','SERVERXX','SERVERXX','SERVERX
+X');
@servers=map ("//$_/$share",@servers);
my @rightsmatch=('DELETE','READ_CONTROL','WRITE_DAC','WRITE_OWNER','SY
+NCHRONIZE','STANDARD_RIGHTS_REQUIRED','STANDARD_RIGHTS_READ','STANDAR
+D_RIGHTS_WRITE','STANDARD_RIGHTS_EXECUTE','STANDARD_RIGHTS_ALL','SPEC
+IFIC_RIGHTS_ALL','ACCESS_SYSTEM_SECURITY','MAXIMUM_ALLOWED','GENERIC_
+READ','GENERIC_WRITE','GENERIC_EXECUTE','GENERIC_ALL','FULL','READ','
+CHANGE');

open (OUT, ">$out") or die "can't open log file!";    

foreach $server( @servers ) {
print "$server\n";
@folders='';
    find(\&wanted, $server);
    foreach $subfolder (@folders){
    print "\t:$subfolder\n";
        next unless -e $subfolder ;
    if ( Get( $subfolder, \%hash ) ) {
        while( ($name, $mask) = each %hash ) {
        ($servsplit,$servsplit,$servsplit,$subsplit)=split(/\//,$subfo
+lder,4);
        print OUT "$servsplit\t$subsplit\t$name\t"; 
        EnumerateRights( $mask, \@rights ) ;#creates @rights, a list o
+f rights for the account
        %rights2=();
        foreach $right (@rights){
                $rights2{$right} = 1;
        }
        foreach $item (@rightsmatch){
        if (exists $rights2{$item}){
            print OUT "$item\t";
        }else{
            print OUT "\'\t";
        }
        }  
        print OUT "\n";
    }
        
    }
    else {
        print( "Error #", int( $! ), ": $!" ) ;
    }
    }
}

close OUT;

sub wanted {
    if (-d){
        push @folders, "$File::Find::dir/$_";
        }
}
Replies are listed 'Best First'.
Re: Compare Directories/Permissions across all servers
by Anonymous Monk on Oct 26, 2002 at 03:57 UTC
    how can this search a hidden share for example d$
      As long as you have admin privs, you can use d\$ as arg[0]. Or you can change the $share variable to d\$, as well.

      -OzzyOsbourne

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: sourcecode [id://66689]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others sharing their wisdom with the Monastery: (4)
As of 2024-03-28 22:41 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found