For the life of me, I cannot figure out why I cannot reproduce this error outside of my main project. This is with Perl 5.20 and I am trying to get the security information for a registry key. Here is the code as written in my main project followed by a code snippet that I have tried running outside of the project to reproduce the error.
sub getEffectiveRights
{
my $object = $_[1];
my $objectType = $_[2];
my $binarySid = $_[3];
my $error = undef;
my $result = undef;
# Establish variables.
my $psidOwner;
my $psidGroup;
my $pDacl;
my $pSacl;
my $pSecurityDescriptor;
try
{
$logger->debug("Object: $object");
# Call GetNamedSecurityInfo. This is to get the DACL.
($psidOwner, $psidGroup, $pDacl, $pSacl, $pSecurityDescriptor)
+ = Win32::Security::Raw::GetNamedSecurityInfo(
$object, $objectType, 'DACL_SECURITY_INFORMATION');
print "returned from Win32::Security::Raw::GetNamedSecurityInf
+o\n";
unless (defined($pDacl))
{
throw Error::Simple("An error occurred trying to access th
+e discretionary access control entries for security object '" . $obje
+ct . "'.");
}
# Build the trustee structure.
my $trustee = System_Functions->buildTrusteeWithSid($binarySid
+);
# Get the access mask.
$result = System_Functions->getEffectiveRightsFromAcl($pDacl,
+$trustee);
}
catch Error::Simple with {
$error = shift;
print "error = $error\n";
}
finally
{
# Clear memory.
if (defined($pSecurityDescriptor))
{
Win32::Security::Raw::LocalFree($pSecurityDescriptor);
}
};
if (defined($error))
{
throw Error::Simple("Could not access '$object'. Verify that i
+t exists and that you have permission to access it. $error");
}
return $result;
}
And the script that works outside of the main project:
use warnings;
use strict;
use Win32::Security::Raw;
#my $object = "MACHINE\\SYSTEM\\CurrentControlSet\\Services";
my @objects = ("MACHINE\\SYSTEM\\CurrentControlSet\\services","MACHINE
+\\SYSTEM\\CurrentControlSet\\Services","MACHINE\\SYSTEM\\CurrentContr
+olSet\\services\\.NET CLR Data", "MACHINE\\SYSTEM\\CurrentControlSet\
+\services\\Lsa\\Performance");
my $ObjectType = 'SE_REGISTRY_KEY';
my $SecurityInfo = 'DACL_SECURITY_INFORMATION';
# Establish variables.
my $psidOwner;
my $psidGroup;
my $pDacl;
my $pSacl;
my $pSecurityDescriptor;
foreach my $object (@objects) {
print "object = $object\n";
# Call GetNamedSecurityInfo. This is to get the DACL.
($psidOwner, $psidGroup, $pDacl, $pSacl, $pSecurityDescriptor) = W
+in32::Security::Raw::GetNamedSecurityInfo($object, $ObjectType, 'DACL
+_SECURITY_INFORMATION');
print "$psidOwner, $psidGroup, $pDacl, $pSacl, $pSecurityDescripto
+r.\n";
if (defined($pSecurityDescriptor))
{
Win32::Security::Raw::LocalFree($pSecurityDescriptor);
}
print "\n\n";
}
I noticed that Win32::API, which is called by Win32::Security::Raw, changed significantly since Perl 5.12 and now has buffer overflow protection built-in but I'm unsure why it would be complaining about "parameter 1". Any help would be greatly appreciative as this is preventing us from upgrading to Perl 5.20.
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.