Storing binary SID in SQL Server

Networking/Security Forums -> Programming and More

Author: igregory PostPosted: Wed May 25, 2005 1:11 pm    Post subject: Storing binary SID in SQL Server

I've a problem I'm struggling with related to SIDs. I'm adding a user interface to an xisting application which stores a Microsoft SID as a varbinary128 field in SQL server 2000. The application is running in a Sharepoint context on Server 2003 with active directory on a second server.

I've been able to extract the SID from Sharepoint and convert it using ConvertStringSidtoSid. Hence I have a binary SID struct pointed to by my IntPtr (see

I need to get that binary SID into the SQL server table varbinary 128 field.

What I'm struggling with is how to get the binary in a format to get it into a parameter for a stored procedure. The only comparable issue I can find is saving BLOB fields which I understand can be passed using an array of data type byte which can then be passed to a binary field in the database. However I have no idea how to a) get my binary data from memory as defined by IntPtr into a byte array, b) pass a byte array to the stored procedure.

My code is:

In the class declarations

public string sid;
IntPtr _sid = IntPtr.Zero; //pointer to binary form of SID string.
int _error=0;

[DllImport("advapi32.dll", CharSet=CharSet.Auto, SetLastError=true)]
internal static extern bool ConvertStringSidToSid(
[In, MarshalAs(UnmanagedType.LPTStr)] string pStringSid,
ref IntPtr sid);

and in the pageload method

sid = user.Sid;
//converts SID string into the binary form
bool _rc0 = ConvertStringSidToSid(sid, ref _sid);

if (_rc0 == false)
_error = Marshal.GetLastWin32Error();
throw(new Exception(new Win32Exception(_error).Message));

Then I have to pass _sid it to my database

Thank you for any pointers you can give me.

Networking/Security Forums -> Programming and More

output generated using printer-friendly topic mod, All times are GMT + 2 Hours

Page 1 of 1

Powered by phpBB 2.0.x © 2001 phpBB Group