469,927 Members | 1,735 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,927 developers. It's quick & easy.

UnauthorizedAccessException when calling SetSecurityDescriptor

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\Serv ices\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\Serv ices\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();
}
}
}
}
Jul 21 '05 #1
7 2912
Hi,

This is to keep this thread alive.

Is this an MSDN managed group?

Thanks,
Doug
Jul 21 '05 #2
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.)

Jul 21 '05 #3
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
lu******@online.microsoft.com (MSFT) wrote in message news:<zw**************@cpmsftngxa06.phx.gbl>...
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.)

Jul 21 '05 #4
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.)

Jul 21 '05 #5
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
lu******@online.microsoft.com (MSFT) wrote in message news:<Yo**************@cpmsftngxa06.phx.gbl>...
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.)

Jul 21 '05 #6
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: do*********@accipitersoftware.com
(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: <e1**************************@posting.google.com >
| References: <e1**************************@posting.google.com >
<e1*************************@posting.google.com>
<zw**************@cpmsftngxa06.phx.gbl>
<e1**************************@posting.google.com >
<Yo**************@cpmsftngxa06.phx.gbl>
| 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: gr**********@google.com
| NNTP-Posting-Date: Tue, 30 Sep 2003 19:14:49 +0000 (UTC)
| Path:
cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!newsfeed 00.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

Jul 21 '05 #7
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
jo****@online.microsoft.com (John Eikanger [MSFT]) wrote in message news:<Ea**************@cpmsftngxa06.phx.gbl>...
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.
Jul 21 '05 #8

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

5 posts views Thread by Kristoffer Persson | last post: by
reply views Thread by =?Utf-8?B?cGxlYXNlIGhlbHAgU3lzdGVtLlVuYXV0aG9yaXpl | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.