Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Learning Perl Chap 2 Win32::FileSecurity Help

by punklrokk (Scribe)
on May 09, 2006 at 01:14 UTC ( [id://548114]=perlquestion: print w/replies, xml ) Need Help??

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

I keep getting the following error and can't figure out why:

C:\scripts>perl everyone.pl Error handling error: 32, GetFileSecurity at everyone.pl line 23.
use File::Find; use Win32::FileSecurity; #determine the DACL mask for Full Access $fullmask = Win32::FileSecurity::MakeMask(FULL); &find(\&wanted,"\\"); sub wanted { # Win32::FileSecurity::Get does not like the paging file, skip it next if ($_ eq "pagefile.sys"); (-f $_) && #Line 23 Win32::FileSecurity::Get($_, \%users) && (defined $users{"Everyone"}) && ($users{"Everyone"} == $fullmask) && print "$File::Find::name\n"; }

Replies are listed 'Best First'.
Re: Learning Perl Chap 2 Win32::FileSecurity Help
by BrowserUk (Patriarch) on May 09, 2006 at 03:12 UTC

    Error 32 in ERROR_SHARING_VIOLATION which is probably a "valid error" in as much as it's something you might expect to encounter and either attemptto recover from or ignore.

    It shoudl be being reported to you via a null return from Win32::FileSecurity::Get() and by the error text in $! per the documentation. Unfortunately, there appears to be a deliberate error in XS code that is causing it to croak instead of just reporting it back to the caller. When an error return is received from an OS API call, the XS code calls this routine to handle it.

    void ErrorHandler( const char *ErrName ) { dTHX; SV* sv = NULL ; /* sv = perl_get_sv( "!", TRUE ) ; */ if ( sv == NULL ) { croak( "Error handling error: %u, %s", GetLastError(), ErrName + ) ; } else { sv_setpv( sv, (char *) ErrName ) ; sv_setiv( sv, GetLastError() ) ; SvPOK_on(sv) ; } }

    It is meant to get access to $!, fill in the error text, and then return to the caller for recovery; but as you can see, the attempt to get access to $! has been commented out, so sv will always be null, and all error returns will croak. You should raise a perlbug.


    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    Lingua non convalesco, consenesco et abolesco. -- Rule 1 has a caveat! -- Who broke the cabal?
    "Science is about questioning the status quo. Questioning authority".
    In the absence of evidence, opinion is indistinguishable from prejudice.

      The code is probably commented out because it would't work. $! is magical and so setting its value in that way would have no effect (similar to how the data stored in a scalar is ignored while the scalar is tied).

      The proper approach would be to just call SetLastError(...) which makes the error information available in $^E (which might not have been the case when this module was written).

      - tye        

        Fair enough. Though inserting return would make more sense than always croaking.


        Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
        Lingua non convalesco, consenesco et abolesco. -- Rule 1 has a caveat! -- Who broke the cabal?
        "Science is about questioning the status quo. Questioning authority".
        In the absence of evidence, opinion is indistinguishable from prejudice.
      Woah,

      Little over my head there, but I think what you are saying is the Error Handler should grab Error $!, but because this is commented out, it just gives this generic error?

      JP Bourget (punklrokk) MS Information and Security Rochester Institute of Technology Rochester, NY

        Kind of. The line commented out is meant to get access to the perl variable $! so that it can assign the error code and text into it (the else branch of the if statement), so that these will be available to the calling application.

        If it successfully obtains access to $! and takes the else branch, then the sub returns to it's immediate caller (other XS routines within the module), where those subs would then return undef or whatever to the calling application. The calling application (ie. your code), can then decide whether the error is something that it can saftely ignore and continue or abort as fits the purpose of the application.

        As it currently stands (on CPAN), any API error passed into ErrorHandler() is always fatal which is a nonsense. It's hard to guess why that would have been commented out or by whom--it looks like it was a quick check that got forgotten to me. Whatever, it should be corrected which means someone should raise a perlbug against it.

        As a workaround, though not a particularly satisfactory one because it means you will effectively be ignoring all api errors, you can use an eval block to trap the croak some thing like this:

        use File::Find; use Win32::FileSecurity; #determine the DACL mask for Full Access my $fullmask = Win32::FileSecurity::MakeMask('FULL'); &find(\&wanted,"\\"); my %users; ## Note: use return not next from a subroutine ## with warnings enabled perl will remind you of this sub wanted { # Win32::FileSecurity::Get does not like the paging file, skip it return if ($_ eq "pagefile.sys"); return unless -f $_; ## Do the get in an eval block and return 1 if it succeeds. ## Otherwise ignore the problem and go onto the next file. return unless eval{ Win32::FileSecurity::Get($_, \%users); 1 }; return unless defined $users{"Everyone"}; return unless $users{"Everyone"} == $fullmask; print "$File::Find::name\n"; }

        Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
        Lingua non convalesco, consenesco et abolesco. -- Rule 1 has a caveat! -- Who broke the cabal?
        "Science is about questioning the status quo. Questioning authority".
        In the absence of evidence, opinion is indistinguishable from prejudice.
Re: Learning Perl Chap 2 Win32::FileSecurity Help
by davidj (Priest) on May 09, 2006 at 02:31 UTC
    You need to provide more information; specifically, the content of line 23. Without it, there is really no way to help you.
    You might want to take a look here: Understanding and Using PerlMonks to get an idea about how to aske questions and get the help you need.

    davidj

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others lurking in the Monastery: (5)
As of 2024-04-25 14:50 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found