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

PLEASE HELP
I have a remote server (say srv1) in there I have 3 folders (directories). Number of users and groups has been granted access to all or some off the directories/sub-directories (I have full rights to the server). I need to write a script that removes the ‘Everyone’ account access wherever was found in any dir/sub-dir on that remote server without remove any other account.
The following is the code I have written.
$dir-> Remove (-1) ie resetting all perms works but when I try to remove the Everyone group it failes (no errors given) just hangs, cna some please pleasaee tell whats iam doing wrong?
And can extract the information of the SAM and modify the permission for Everyone account access instead of using Wine32::Perms?
use warnings 'all'; use Win32::Perms; use Win32::NetAdmin; my $srv = shift @ARGV; my $drv = pop @ARGV; my $unc_path = "\\\\" . $srv . "\\" . $drv . "\\"; print "\nServer\t: $srv\nDrive\t: $drv\nUnc\t:$unc_path\n"; my $file_counter = 1; &proccess_dir ("$unc_path"); sub proccess_dir { my ($dir_name) = @_; my ($file, $sub_dir, $file_var); $file_var = "CONST" . $file_counter++; opendir ( $file_var,"$unc_path") || warn "\n$! : $unc_path\n"; print "$dir_name\n"; $dir = new Win32::Perms ($dir_name) || return 0; $dir -> Dump; print "\n\n\n***********************************\n\n\n"; $dir -> Remove ('everyone');# it hangs here forever $dir -> Set ( ); $dir -> Dump; while ( $file = readdir ( $file_var ) ) { next if ( $file eq "." || $file eq ".." ); } rewinddir ( $file_var ); while ( $sub_dir = readdir ( $file_var ) ) { next unless (-d ( $dir_name . "/" . $sub_dir ) ); next if ( $sub_dir eq "." || $sub_dir eq ".." ); &proccess_dir ($dir_name . "/" . $sub_dir ); } closedir ( $file_var ); }

Replies are listed 'Best First'.
Re: Removing Permissions
by particle (Vicar) on Jun 17, 2002 at 11:29 UTC
    use the system command 'cacls'. this will remove 'Everyone' rights recursively from the directory specified.

    my $result = system( 'cacls', $dir_name, '/t', '/e', '/r', 'Everyone' +);
    i don't know why your script is hanging, because i'm not familiar with that module. in any case, it seems like overkill if this is all you're doing.

    ~Particle *accelerates*

      Great, It worked,…Thanks ;-) Any idea how to do the same thing but through the SAM instead?
      XCacls vs Cacls Any Advantages/Disadvantages in using Xcacls?
        xcacls is little known, i guess that's a disadvantage. it's freeware, so it's not supported by microsoft like cacls is. in some companies, you may have policies in place that forbid running software like this. it's part of the resource kit, but is freely downloadable from Microsoft. here is a brief syntax comparison between cacls and xcacls.

        for this simple application, cacls is a good choice. for more powerful uses, specifically when combining access rights, xcacls adds value.

        ~Particle *accelerates*

Re: Removing Permissions
by caedes (Pilgrim) on Jun 17, 2002 at 13:01 UTC
    I once had a similar problem with the ActiveState port of Perl on Windows 2000. It would just hang with no errors at seemingly random times while the same code on Linux was just fine (no unportable code mind you). My solution was to switch the server to Linux, and I haven't looked back yet. ;-)
      Linux, music to my ears ;-)
      Glad to say that Cacls has worked it removed the ‘Everyone’ account without any problems -for the time being :-|