UnauthorizedAccessException when calling SetSecurityDescriptor

D

Doug Taylor

Hi,

I originally posted this in dotnet.security, but have moved it here by request:



Hi,

I am trying to programmatically add a user with read permissions to
the DACL of a registry key. All appears to go well until I try to
save the security descriptor back into the registry. I then get the
UnauthorizedAccessException thrown.

I'm doing this with an account that is in the Administrators group.
Any ideas what I am missing?


Code follows:

using System;
using System.Security.Permissions;
using Microsoft.Win32;
using System.Diagnostics;
using ActiveDs;

namespace TRISClientPreSetup
{
class cMain
{
[STAThread]
static void Main(string[] args)
{
RegistryKey oRootKey = Registry.LocalMachine;
AccessControlEntryClass oACE;
ADsSecurityUtilityClass oADSUC = new ADsSecurityUtilityClass();
SecurityDescriptor oSD;
AccessControlList oACL;

try
{
// Set the SecurtityMask of the Security Utility Class object
oADSUC.SecurityMask =
(int)ADS_SECURITY_INFO_ENUM.ADS_SECURITY_INFO_DACL;
// Get the SecurityDescriptor of the of the registry key
oSD = (SecurityDescriptor)oADSUC.GetSecurityDescriptor(
@"HKEY_LOCAL_MACHINE\System\CurrentControlSet\Services\EventLog",
(int)ADS_PATHTYPE_ENUM.ADS_PATH_REGISTRY,
(int)ADS_SD_FORMAT_ENUM.ADS_SD_FORMAT_IID);
// Get the DACL of the SecurityDescriptor of the registry key
oACL = (AccessControlList)oSD.DiscretionaryAcl;

// Set up a new AccessControlEntry to add to the DACL
oACE = new AccessControlEntryClass();
// Set the trustee to the new user
oACE.Trustee = @"KA2G2P51\tris";
// I empirically derrived the AccessMask by manually adding
// this user through regedt32 then examining the value of
// the resulting entry
oACE.AccessMask = (int)(ADS_RIGHTS_ENUM.ADS_RIGHT_READ_CONTROL
| ADS_RIGHTS_ENUM.ADS_RIGHT_DS_CREATE_CHILD
| ADS_RIGHTS_ENUM.ADS_RIGHT_DS_READ_PROP
| ADS_RIGHTS_ENUM.ADS_RIGHT_DS_SELF);
// I derrived the AceFlags the same way
oACE.AceFlags = (int)ADS_ACEFLAG_ENUM.ADS_ACEFLAG_INHERIT_ACE;

// Add the AccessControlEntry to the DACL
oACL.AddAce( oACE );
// Save the DACL back into the SecurityDescriptor
oSD.DiscretionaryAcl = oACL;
// Save the SecurityDescriptor back into the registry
oADSUC.SetSecurityDescriptor(
@"HKEY_LOCAL_MACHINE\System\CurrentControlSet\Services\EventLog",
(int)ADS_PATHTYPE_ENUM.ADS_PATH_REGISTRY,
oSD,
(int)ADS_SD_FORMAT_ENUM.ADS_SD_FORMAT_IID);

// This last line is the line that errors with:
// System.UnauthorizedAccessException: Access is denied.

}
catch ( Exception ex )
{
Console.WriteLine( ex.ToString() );
Console.Read();
}
}
}
}
 
D

doug.h.taylor.accipitersoftware.com

Hi,

This is to keep this thread alive.

Is this an MSDN managed group?

Thanks,
Doug
 
M

MSFT

hi Taylor,

This group is managed by us. Please let me know if there is an MSFT replied
your original post and his email. I will help to follow up with him.

Thanks,

Luke
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
 
D

doug.h.taylor.accipitersoftware.com

Luke,

Thanks for your reply. In truth, your's is the first reply. Is there
anything that I need to do that will help? Are there any more details
I can supply?

Thanks again,
Doug
 
M

MSFT

Hi Doug,

If you have a issue which need assistance, you may post a message on this
group and include all detaill information about the problem. For example,
the exact error message you get, and part of your code which can help to
reproduce the problem.

Regards,

Luke
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
 
D

doug.h.taylor.accipitersoftware.com

Luke,

Thanks for your response.

As far as the exact error message and the code which can help to
reproduce the problem... I refer you to my original post.

However, I have had to move on and we have found a 3rd party solution,
so I guess we can let it drop.

I do wish Microsoft would look into making this task easier within the
Framework. I feel it is an overlooked area.

Thanks again,
Doug
 
J

John Eikanger [MSFT]

Hi, Doug

When you changed the newsgroup of your post, we lost any link to your
original post. Luke was unable to locate it. I did some digging and found
it in microsoft.public.dotnet.security, which is not a managed newsgroup.
This explains why we did respond to your original post. If you wish to
pursue yoru original issue further, please respond here and we will get
someone on it.

Thank you for choosing the MSDN Managed Newsgroups,

John Eikanger
Microsoft Developer Support

This posting is provided “AS IS” with no warranties, and confers no rights.
"Microsoft highly recommends to all of our customers that they visit the
http://www.microsoft.com/protect site and perform the three straightforward
steps listed to improve your computer’s security."
--------------------
| From: (e-mail address removed)
(doug.h.taylor.accipitersoftware.com)
| Newsgroups: microsoft.public.dotnet.general
| Subject: Re: UnauthorizedAccessException when calling
SetSecurityDescriptor
| Date: 30 Sep 2003 12:14:49 -0700
| Organization: http://groups.google.com
| Lines: 33
| Message-ID: <[email protected]>
| References: <[email protected]>
<[email protected]>
<[email protected]>
<[email protected]>
<[email protected]>
| NNTP-Posting-Host: 148.134.37.3
| Content-Type: text/plain; charset=ISO-8859-1
| Content-Transfer-Encoding: 8bit
| X-Trace: posting.google.com 1064949289 3840 127.0.0.1 (30 Sep 2003
19:14:49 GMT)
| X-Complaints-To: (e-mail address removed)
| NNTP-Posting-Date: Tue, 30 Sep 2003 19:14:49 +0000 (UTC)
| Path:
cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!newsfeed00.sul.t-online.de!t-onlin
e.de!news-spur1.maxwell.syr.edu!news.maxwell.syr.edu!sn-xit-03!sn-xit-04!sn-
xit-01!sn-xit-09!supernews.com!postnews1.google.com!not-for-mail
| Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.general:110385
| X-Tomcat-NG: microsoft.public.dotnet.general
|
| Luke,
|
| Thanks for your response.
|
| As far as the exact error message and the code which can help to
| reproduce the problem... I refer you to my original post.
|
| However, I have had to move on and we have found a 3rd party solution,
| so I guess we can let it drop.
|
| I do wish Microsoft would look into making this task easier within the
| Framework. I feel it is an overlooked area.
|
| Thanks again,
| Doug
 
D

doug.h.taylor.accipitersoftware.com

John,

Thanks for your attention. I am sorry for the confusion. When I
switched newsgroups I simply copied the text of the first message in
the security newsgroup and pasted it in a new thread in this
newsgroup. There should be no links between the two newsgroups. When
I view this thread I can see my original posting as message 1 in this
thread. I have no idea why you cannot see it. Perhaps it is because
I am viewing these with Google and it looks different to me.

At any rate, I have moved on. I never got a resolution, but I ran out
of time. Thanks again for your assistance and I'm sorry for all the
confusion.

Doug


Hi, Doug

When you changed the newsgroup of your post, we lost any link to your
original post. Luke was unable to locate it. I did some digging and found
it in microsoft.public.dotnet.security, which is not a managed newsgroup.
This explains why we did respond to your original post. If you wish to
pursue yoru original issue further, please respond here and we will get
someone on it.

Thank you for choosing the MSDN Managed Newsgroups,

John Eikanger
Microsoft Developer Support

This posting is provided ?AS IS? with no warranties, and confers no rights.
"Microsoft highly recommends to all of our customers that they visit the
http://www.microsoft.com/protect site and perform the three straightforward
steps listed to improve your computer?s security."
truncated.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

Writing ACL dont work 1

Top