Search
Module:
Directory

   Desktop Functions:

   Smart Device Functions:


Show Recent Changes
Subscribe (RSS)
Misc. Pages
Comments
FAQ
Helpful Tools
Playground
Suggested Reading
Website TODO List
Download Visual Studio Add-In

RtlInitializeSid (ntdll)
 
.
Summary
The RtlInitializeSid routine initializes a security identifier (SID) structure.

C# Signature:

[DllImport("ntdll", CharSet = CharSet.Auto, ExactSpelling = true, SetLastError = true)]
private static extern Int32 RtlInitializeSid([In, Out] ref SID Sid, [In] ref SID_IDENTIFIER_AUTHORITY IdentifierAuthority, byte SubAuthorityCount);

VB Signature:

Declare Function RtlInitializeSid Lib "ntdll.dll" (TODO) As TODO

User-Defined Types:

[StructLayout(LayoutKind.Sequential, Size = 6)]
struct SID_IDENTIFIER_AUTHORITY
{
   [MarshalAs(UnmanagedType.ByValArray, SizeConst = 6)]
   public byte[] Value;

   public SID_IDENTIFIER_AUTHORITY(byte[] value)
   {
     if (value.Length != 6)
       throw new ArgumentOutOfRangeException("value", "Value must be an array of 6 bytes.");
     this.Value = value;
   }
}

[StructLayout(LayoutKind.Sequential)]
struct SID
{
   public byte Revision;
   public byte SubAuthorityCount;
   public SID_IDENTIFIER_AUTHORITY IdentifierAuthority;
   public UInt32[] SubAuthority;

   public SID(int subAuthorityCount)
   {
     this.Revision = 0;
     this.SubAuthorityCount = 0;
     this.IdentifierAuthority = default(SID_IDENTIFIER_AUTHORITY);
     this.SubAuthority = new UInt32[subAuthorityCount];
   }
}

Alternative Managed API:

Do you know one? Please contribute it!

Notes:

Tested on Win8.1 x64 by @gsuberland, but not thoroughly.

Tips & Tricks:

Please add some!

Sample Code:

// just using a null identifier here
SID_IDENTIFIER_AUTHORITY id = new SID_IDENTIFIER_AUTHORITY(new byte[] { 0, 0, 0, 0, 0, 0 });
// new SID with an allocated SubAuthority count of 1
SID sid = new SID(1);

// make the call, passing the correct SubAuthority count
var status = RtlInitializeSid(ref sid, ref id, (byte)sid.SubAuthority.Length);

if (status < 0)
   Console.WriteLine("Failed.");
else
   Console.WriteLine("Success.");

Documentation

Please edit this page!

Do you have...

  • helpful tips or sample code to share for using this API in managed code?
  • corrections to the existing content?
  • variations of the signature you want to share?
  • additional languages you want to include?

Select "Edit This Page" on the right hand toolbar and edit it! Or add new pages containing supporting types needed for this API (structures, delegates, and more).

 
Access PInvoke.net directly from VS:
Terms of Use
Edit This Page
Find References
Show Printable Version
Revisions