472,342 Members | 1,830 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,342 software developers and data experts.

SetSecurityDescriptor error 1307

I have a .Net console application. It creates a user's folder, sets
permissions using WMI, then fails to give the ownership of that folder
to the user (for quotas).

This all executes on a single 2003 server, within a larger domain. My
admin account, from which I run the app, and the user's account, are
both AD domain accounts.

Seems simple enough, and it works fine with a VB script from the
console. However, when I run my C# .Net app, it fails with 1307.

I've read the other posts regarding this, in ASP, and I've tried both
WMI and ADSI methods to set owner - both give the same error 1307.

The only case when this app does work properly, is when I change
ownership of the folder to my own admin account.

I'm obviously missing the point here. Am I right in thinking this has
to do with impersonation? Do I need to use COM+? Can anyone please put
me on the right track - thanks very much.

Nov 17 '05 #1
2 5198
Nigel,

Can you show the script, as well as the code from the console app?
There might be a discrepancy between the two that is missed (or rather,
something is out of order, since what you would call in VB Script is
different than what you would call in C#).

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Nigel Frost" <N.*******@soton.ac.uk> wrote in message
news:11********************@g47g2000cwa.googlegrou ps.com...
I have a .Net console application. It creates a user's folder, sets
permissions using WMI, then fails to give the ownership of that folder
to the user (for quotas).

This all executes on a single 2003 server, within a larger domain. My
admin account, from which I run the app, and the user's account, are
both AD domain accounts.

Seems simple enough, and it works fine with a VB script from the
console. However, when I run my C# .Net app, it fails with 1307.

I've read the other posts regarding this, in ASP, and I've tried both
WMI and ADSI methods to set owner - both give the same error 1307.

The only case when this app does work properly, is when I change
ownership of the folder to my own admin account.

I'm obviously missing the point here. Am I right in thinking this has
to do with impersonation? Do I need to use COM+? Can anyone please put
me on the right track - thanks very much.

Nov 17 '05 #2
Nicholas,
Thanks for taking an interest in my problem.
As a further test, I used WMI in my app to create a Win32_Process to
run my VB script in a command window. It also failed with error 1307.
So I have two command windows - the original one with permission to
change the ownership, and the spawned one that does not!

Here are some (edited) code extracts:

The VB script
-------------
set refWMI =
GetObject("winMgmts:{impersonationLevel=impersonat e,(Security,Restore)}!\\"
& strMachine & "\root\cimv2")

'find the user's Win32_Account and Win32_SID
set col = refWMI.ExecQuery("SELECT * FROM Win32_ACCOUNT " & "WHERE
Name='" & strUser & "' AND Domain='testdomain'" )
For Each ref in col
set refAccount = ref
set refSID = refWMI.Get("Win32_SID='" & refAccount.SID & "'")
exit for
Next

'get the Win32_LogicalFileSecuritySetting for the user's home folder
set refSecSetting = refWMI.Get("Win32_LogicalFileSecuritySetting='" &
strUserDirPath & "'")

'get Win32_SecurityDescriptor
ret = refSecSetting.GetSecurityDescriptor(refSecDescript or)

'create Win32_Trustee
Set refNewTrustee = refWMI.Get("Win32_Trustee").spawnInstance_()
With refNewTrustee
.Domain = refAccount.Domain
.Name = refAccount.Name
.SID = refSID.BinaryRepresentation
.SidLength = refSID.SidLength
.SIDString = refSID.SID
End With

'set the new owner
refSecDescriptor.Owner = refNewTrustee

'Commit changes
ret = refSecSetting.SetSecurityDescriptor(refSecDescript or)

C# WMI code
-----------
ConnectionOptions options = new ConnectionOptions();
options.Impersonation = ImpersonationLevel.Impersonate;
options.Authentication = AuthenticationLevel.Unchanged;
scope = new ManagementScope(strScope,options);
scope.Connect();

// Win32_LogicalFileSecuritySetting
string wql = string.Format(
@"SELECT * FROM Win32_LogicalFileSecuritySetting WHERE

Path='e:\\share\\{0}'",user);
ManagementObjectCollection queryCol = execQuery(scope, wql); // my fn
foreach (ManagementObject moSetting in queryCol)
{
securitySetting = moSetting;
break;
}

// Win32_SecurityDescriptor
Object[] oArgs = new Object[1];
result = securitySetting.InvokeMethod("GetSecurityDescripto r", oArgs);
securityDescriptor = (ManagementBaseObject)oArgs[0];

securityDescriptor["ControlFlags"] = 32771;

// Win32_Account for user
userAccount = getUserAccount(scope, domain, user); // my fn

// Win32_SID for user
userSid = getUserSID(scope, user, userAccount); my fn

// The current owner
ManagementBaseObject currentOwner =
(ManagementBaseObject)securityDescriptor["Owner"];

// new owner - Win32_Trustee for user
ManagementBaseObject newOwner =
(ManagementBaseObject)currentOwner.Clone();

newOwner["Domain"] = (string)userAccount["Domain"];
newOwner["Name"] = (string)userAccount["Name"];
newOwner["SID"] = (Byte[])userSid["BinaryRepresentation"];
newOwner["SidLength"] = (UInt32)userSid["SidLength"];
newOwner["SIDString"] = (string)userSid["SID"];
securityDescriptor["Owner"] = newOwner;

// Commit the changes
Object[] oSetArgs = new Object[1] { securityDescriptor };

// Here is where I get the error 1307
result = securitySetting.InvokeMethod("SetSecurityDescripto r",
oSetArgs);

================================================== ===========

C# ADSI code
------------
string path = string.Format(@"e:\\share\\{0}",user);

ADsSecurityUtilityClass asu = new ADsSecurityUtilityClass();

// Get DACL and OWNER info
asu.SecurityMask = (int)(ADS_SECURITY_INFO_ENUM.ADS_SECURITY_INFO_OWN ER

| ADS_SECURITY_INFO_ENUM.ADS_SECURITY_INFO_DACL);

SecurityDescriptor sd = asu.GetSecurityDescriptor(
path,
(int)ADS_PATHTYPE_ENUM.ADS_PATH_FILE,
(int)ADS_SD_FORMAT_ENUM.ADS_SD_FORMAT_IID) as SecurityDescriptor;
}

sd.Owner = string.Format(@"testdomain\{0}",user);

// Here is where I get the error 1307
asu.SetSecurityDescriptor(
path,
(int)ADS_PATHTYPE_ENUM.ADS_PATH_FILE,
sd,
(int)ADS_SD_FORMAT_ENUM.ADS_SD_FORMAT_IID);

================================================== ===========

C# running VB Script
--------------------
ConnectionOptions options = new ConnectionOptions();
options.Impersonation = ImpersonationLevel.Impersonate;
options.Authentication = AuthenticationLevel.Unchanged;
scope = new ManagementScope(strScope,options);
scope.Connect();

// Create a process in which to run the script
ManagementClass process = createManagementClass(scope,"WIN32_Process");

UInt32 pid = 0;
object[] methodArgs =
{
@"cmd.exe /k cscript owner.vbs njf1", // keep the cmd window open
@"C:\projects\xyz\vb",
null,
pid
};

// Run the cmd window - the script fails with error 1307
Object result = process.InvokeMethod ("Create", methodArgs);

================================================== ===========
Nicholas Paldino [.NET/C# MVP] wrote:
Nigel,

Can you show the script, as well as the code from the console app?
There might be a discrepancy between the two that is missed (or rather,
something is out of order, since what you would call in VB Script is
different than what you would call in C#).

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Nigel Frost" <N.*******@soton.ac.uk> wrote in message
news:11********************@g47g2000cwa.googlegrou ps.com...
I have a .Net console application. It creates a user's folder, sets
permissions using WMI, then fails to give the ownership of that folder
to the user (for quotas).

This all executes on a single 2003 server, within a larger domain. My
admin account, from which I run the app, and the user's account, are
both AD domain accounts.

Seems simple enough, and it works fine with a VB script from the
console. However, when I run my C# .Net app, it fails with 1307.

I've read the other posts regarding this, in ASP, and I've tried both
WMI and ADSI methods to set owner - both give the same error 1307.

The only case when this app does work properly, is when I change
ownership of the folder to my own admin account.

I'm obviously missing the point here. Am I right in thinking this has
to do with impersonation? Do I need to use COM+? Can anyone please put
me on the right track - thanks very much.


Nov 17 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: AIM | last post by:
Error in msvc in building inheritance.obj to build hello.pyd Hello, I am trying to build the boost 1.31.0 sample extension hello.cpp. I can...
7
by: Doug Taylor | last post by:
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...
1
by: DiskMan | last post by:
System: Redhat 7.2 Kernel-2.6.11.8 GCC-3.4.3 CCC-6.5.9 Binutils-2.15 Make-3.80 GTK/GLIB-2.6.7 For some reason my Linux box is suddenly...
2
by: Gregory | last post by:
Hi, One of the disadvantages of using error handling with error codes instead of exception handling is that error codes retuned from a function...
5
by: NG | last post by:
Hi, We are having DB2-V7.2 DB on AIX 5.2 machine. Recently we upgraded our system to fixpack 13 and activated activate AIX asynchronous IO...
13
by: deko | last post by:
I use this convention frequently: Exit_Here: Exit Sub HandleErr: Select Case Err.Number Case 3163 Resume Next Case 3376 Resume Next
7
by: p | last post by:
WE had a Crystal 8 WebApp using vs 2002 which we upgraded to VS2003. I also have Crystal 9 pro on my development machine. The web app runs fine on...
3
by: Manuel | last post by:
I'm trying to compile glut 3.7.6 (dowbloaded from official site)using devc++. So I've imported the glut32.dsp into devc++, included manually some...
0
by: bazzer | last post by:
hey, im trying to access a microsoft access database from an ASP.NET web application in visual basic 2003.NET. i get the following error when i...
0
by: teenabhardwaj | last post by:
How would one discover a valid source for learning news, comfort, and help for engineering designs? Covering through piles of books takes a lot of...
0
by: Kemmylinns12 | last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and...
0
by: CD Tom | last post by:
This only shows up in access runtime. When a user select a report from my report menu when they close the report they get a menu I've called Add-ins...
0
by: Naresh1 | last post by:
What is WebLogic Admin Training? WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge...
0
jalbright99669
by: jalbright99669 | last post by:
Am having a bit of a time with URL Rewrite. I need to incorporate http to https redirect with a reverse proxy. I have the URL Rewrite rules made...
0
by: Matthew3360 | last post by:
Hi there. I have been struggling to find out how to use a variable as my location in my header redirect function. Here is my code. ...
2
by: Matthew3360 | last post by:
Hi, I have a python app that i want to be able to get variables from a php page on my webserver. My python app is on my computer. How would I make it...
0
by: Arjunsri | last post by:
I have a Redshift database that I need to use as an import data source. I have configured the DSN connection using the server, port, database, and...
0
by: Matthew3360 | last post by:
Hi, I have been trying to connect to a local host using php curl. But I am finding it hard to do this. I am doing the curl get request from my web...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.