Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Win32::Perms Remove method

by Discipulus (Abbot)
on Jun 11, 2004 at 09:35 UTC ( #363341=perlquestion: print w/replies, xml ) Need Help??

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

hi all !!

I'm investigating about the gordian knot (not the rip pack!) of ntfs permissions. The core module in activeperl Win32::FileSecurity not cover all the 'features' of the filesystem. The API::File module is too complex so I'm trying to use Win32::Perms.

The task is to substitute one account with another one.
The Remove method ran correctly in a test script but when I put it in recursive sub the scripts hung with CPU at 100%.
Here the code:
###globals my $vecchio = 'DOMAIN\old_user'; my $vec_usr = 'old_user'; my $vec_dom='DOMAIN'; my $nuovo= '\\MACHINE\new_user'; my $nuo_usr= 'new_user'; my $new_dom= 'MACHINE'; ########## # take the root &substitute_dacl($root) ################### sub substitute_dacl { my $path = shift; print"\n-------------\n$path\n"; $perm = new Win32::Perms($path)|| die "$!"; $perm->Dump(\@list); my $owner=$perm->Owner(); if ($owner eq $vecchio) {$perm->Owner($nuovo); print "owner: $owner\t";print "Change owner\n"} foreach $elem(@list) { if (${$elem}{'Account'} eq $vec_usr) { print"-------> $vec_usr in $path\n"; my %hash=( 'Account' =>$nuo_usr, 'Domain' =>$nuo_dom, 'Mask' =>${$elem}{'Mask'}, #take the old 'Type' =>${$elem}{'Type'}, #options 'Flag' =>${$elem}{'Flag'}, # as is ); $perm->Add(\%hash)||warn "No add..\n"; $perm->Remove($vec_usr)||warn "$^E $!";# FAILS & HUNG if ($perm->Set()){print "Set ok\n"}else{warn "$^E $!"} #system "cacls \"$path\" /E /R ${$elem}{'Domain'}\\${$elem}{'Acc +ount'}";#THIS WORK BUT TERRIBLE last; } } }
What is happening ? any suggestion welcome

greetings from sunny hot roma
Lor*363341

Replies are listed 'Best First'.
Re: Win32::Perms Remove method
by dfaure (Chaplain) on Jun 14, 2004 at 09:26 UTC
    The Remove method ran correctly in a test script but when I put it in recursive sub the scripts hung with CPU at 100%.

    I'm not a Win32::Perms specialist, but I suppose you recursively walk a directory tree. Then, are you sure you create AND delete your Win32::Perms object on each path specification?

    $perm = new Win32::Perms($path)|| die "$!"; ... $perm = undef;
    HTH, Dominique
Re: Win32::Perms Remove method
by bibo (Pilgrim) on Jun 14, 2004 at 16:14 UTC
    I hate to be a total dork, but do you know you can do this using the windows(file) explorer? You can pick a folder, right click and choose properties, and recurse thru the folder and all files with the changes. Why beat yourself up writing a script when you can do it with a couple mouse manuevers?

    And the same thing goes for the CACLS.EXE command which you commented out. It can recurse, and do everything you want, so why? you never explain to us this little point...

    TMTOWTDI

      with cacls.exe u cannot substitute account.. with Xcopy u cannot copy between server local user's acl.. I need to take dirA on srvA and substitute usrLocal-A with usrDOMAINB, then copy dirA su servB and substitute in the acl usrDOMAINB with usrLOCAL-C ... this with some giga of file... greetings Lor*
      you can do this using the windows(file) explorer

      You're right, but you may not have direct access to the computer handling the files. Eg., the code is extracted from a web-shared data storage app.

      (Then we may ask ourself about the viability of such a service on Win32 :-), but this is not the purpose here)

      HTH, Dominique
Re: Win32::Perms Remove method
by BrowserUk (Patriarch) on Jun 15, 2004 at 08:38 UTC

    I think that instead of trying to do the recursion yourself, you ought to be looking at using the SetRecurse() method. This is a sample supplied with the package (see ..\perl\site\lib\win32\perms\recurse.pl)

    use Win32::Perms; $Dir = 'd:\temp' unless( $Dir = $ARGV[0] ); $P = new Win32::Perms( $Dir ); # Set the all of the files called *.tmp in the specified directory $P->SetRecurse( "$Dir/*.tmp" ); print "Finished\n";


    Examine what is said, not who speaks.
    "Efficiency is intelligent laziness." -David Dunham
    "Think for yourself!" - Abigail
      thanks perlyfull BrowserUK,

      I use the tachyon recurse that I love a lot:
      my $root = 'c:/prova/'; my @dirs = ($root); my @files; for my $path (@dirs){ opendir ( DIR, $path ) or next; # skip dirs we can't read while (my $file = readdir DIR) { next if $file eq '.' or $file eq '..';# skip dot files next if -l $path.$file; # skip sym links if ( -d $path.$file ) { push @dirs, $path.$file.'/'; # add dir to list } else { push @files, $path.$file; # add file to list } } closedir DIR; }
      I never noticed this SetRecurse method. But the core of the problem remain. loves Lor*
        But the core of the problem remain.

        What does this mean?

        If you mean that you are still getting hangs when using a single Win32::Perms object recursively, then I would suggest that that is the source of your problem.


        Examine what is said, not who speaks.
        "Efficiency is intelligent laziness." -David Dunham
        "Think for yourself!" - Abigail

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (3)
As of 2022-07-03 23:28 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?