• RSS
  • Twitter
  • FaceBook

Security Forums

Log in

FAQ | Search | Usergroups | Profile | Register | RSS | Posting Guidelines | Recent Posts

Storing binary SID in SQL Server

Users browsing this topic:0 Security Fans, 0 Stealth Security Fans
Registered Security Fans: None
Post new topic   Reply to topic   Printer-friendly version    Networking/Security Forums Index -> Programming and More

View previous topic :: View next topic  
Author Message
igregory
Just Arrived
Just Arrived


Joined: 25 May 2005
Posts: 0


Offline

PostPosted: Wed May 25, 2005 1:11 pm    Post subject: Storing binary SID in SQL Server Reply with quote

Hi,

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 http://msdn.microsoft.com/library/default.asp?url=/library/en-us/secauthz/security/convertstringsidtosid.asp).

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();
Marshal.FreeHGlobal(_sid);
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.
Back to top
View user's profile Send private message
Display posts from previous:   

Post new topic   Reply to topic   Printer-friendly version    Networking/Security Forums Index -> Programming and More All times are GMT + 2 Hours
Page 1 of 1


 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

Community Area

Log in | Register