OzzyOsbourne has asked for the wisdom of the Perl Monks concerning the following question:

MPH, tired of aimlessly wading through seas documentation, seeks descreet, elegant module to retrieve a list of users that have permission to a particular share on win32.

Full features welcome, and long term commitment a plus.

-OzzyOsbourne

Replies are listed 'Best First'.
Re: Getting share permissions in win32
by Tyke (Pilgrim) on Mar 19, 2001 at 19:14 UTC
Re: Getting share permissions in win32
by clemburg (Curate) on Mar 19, 2001 at 19:34 UTC

    Depending on what you need, this may help, too (from the NT Resource Kit, GUI based):

    NETWATCH.EXE: Net Watcher - Windows-based tool, shows who is connected to shared directories.

    Christian Lemburg
    Brainbench MVP for Perl
    http://www.brainbench.com

      The real goal is to audit permissions across 40 file and print servers. Given the directory sizes and complexities, I really don't want to do it manually. I will if I have to, but I don't wanna.

      -OzzyOsbourne

        Try a modification of the below with File::Find (I think it will do UNC paths ... anyone?) or DosGlob. You could foreach ( @ARGV ) to parse through specific shares. Win32::NetResource has a discovery capability (not for hidden shares, though).
        #!/usr/bin/perl -w use strict; use Win32::Perms; use vars qw ( @List @Mask ); my $Dir = new Win32::Perms( $ARGV[0] ); $Dir->Dump( \@List ); foreach my $shareRef ( @List ) { print "\n" , $shareRef->{'Domain'} , '/' , $shareRef->{'Account'} +, "\n\n"; Win32::Perms::DecodeMask ( $shareRef, \@Mask ); foreach ( @Mask ) { print "\t" , $_ , "\n"; } }
        BTW, the URL to Win32::Perms is:
        http://www.roth.net/perl/perms/

        Dave's main page does seem like a wonderful rendition of a cow in a snowstorm.

Re: Getting share permissions in win32
by orbital (Scribe) on Mar 19, 2001 at 21:12 UTC
    I would recommend checking out David Roth's Book Win32 Perl Scripting: Administrator's Handbook. This book has covers a wide spectrum of issues, including the ones your running into.

    I know on the link I posted above he has all the example code in a zip file from his book. I still recommend getting the book as he goes indepth to explain the concepts that he is using.

    Dave Roth wrote the Win32::Perms module

Re: Getting share permissions in win32
by OzzyOsbourne (Chaplain) on Mar 20, 2001 at 01:36 UTC

    This is what I ended up doing as a gapstop measure. It will become more complex (using file::find), but this is the basic structure I used. Notice that it is rather close to the sample code in the docs. :)

    The most difficult part of this process was actually picking the module. Some modules were so complex in that they were way beyond me, and others had such bad documentation that I sat there scratching my head on how to get them going.

    This just seemed like the simplest way to get this done.

    Thanks for all the suggestions!

    use strict; use Win32::FileSecurity qw(Get EnumerateRights); my $share=$ARGV[0]; my $out=$ARGV[1]; my ($name,$mask,@rights,%hash,$server); my @servers=('SERVERX','SERVERX','SERVERX','SERVERX','SERVERX','SERVER +X','SERVERX','SERVERX','SERVERX','SERVERX','SERVERX','SERVERX','SERVE +RX','SERVERX','SERVERX','SERVERX','SERVERX','SERVERX','SERVERX','SERV +ERX','SERVERX','SERVERX','SERVERX','SERVERX','SERVERX'); @servers=map ("//$_/$share",@servers); open (OUT, ">$out") or die "can't open log file!"; foreach $server( @servers ) { next unless -e $server ; if ( Get( $server, \%hash ) ) { print OUT "$server\n"; print "$server\n"; while( ($name, $mask) = each %hash ) { print OUT "\t$name:\n\t\t"; EnumerateRights( $mask, \@rights ) ; print OUT join( "\n\t\t", @rights ), "\n"; } } else { print( "Error #", int( $! ), ": $!" ) ; } } close OUT;

    -OzzyOsbourne