Home All Groups Group Topic Archive Search About

SID to dotnet SecurityIdentifier

Author
31 Dec 2005 9:00 AM
Edgars Klepers
From my research, SID's are supposed to be stored in an SQL database as a
varbinary(85).

What is the best way to translate the SID to the dotnet 2.0
SecurityIdentifier type? 

I am working in C# but can probably translate VB code over as well if that
way is easier to explain.

Thanks for your time!

-Edgars Klepers

Author
31 Dec 2005 3:35 PM
Dan Guzman
> From my research, SID's are supposed to be stored in an SQL database as a
> varbinary(85).

SecurityDescriptor.MaxBinaryLength is currently 68 in .Net framework 2.0.

> What is the best way to translate the SID to the dotnet 2.0
> SecurityIdentifier type?

If you have the byte array with SID, you can use the overloaded
SecurityIdentifier constructor:

SqlCommand command =
    new SqlCommand("SELECT SID FROM MyTable WHERE AccountName =
'MyDomain\MyAccount'", connection);

byte[] sid = (byte[]) command.ExecuteScalar();

SecurityIdentifier si = new SecurityIdentifier(sid, 0);

--
Happy Holidays

Dan Guzman
SQL Server MVP

Show quote
"Edgars Klepers" <EdgarsKlep***@discussions.microsoft.com> wrote in message
news:73E900FD-8803-48F2-B14E-23310C4192EB@microsoft.com...
> From my research, SID's are supposed to be stored in an SQL database as a
> varbinary(85).
>
> What is the best way to translate the SID to the dotnet 2.0
> SecurityIdentifier type?
>
> I am working in C# but can probably translate VB code over as well if that
> way is easier to explain.
>
> Thanks for your time!
>
> -Edgars Klepers
Author
31 Dec 2005 8:52 PM
Edgars Klepers
So from an SqlDataReader, i would just GetType(x) and typecast it to a
byte[]?  or is there a better way to get it?

Show quote
"Dan Guzman" wrote:

> > From my research, SID's are supposed to be stored in an SQL database as a
> > varbinary(85).
>
> SecurityDescriptor.MaxBinaryLength is currently 68 in .Net framework 2.0.
>
> > What is the best way to translate the SID to the dotnet 2.0
> > SecurityIdentifier type?
>
> If you have the byte array with SID, you can use the overloaded
> SecurityIdentifier constructor:
>
> SqlCommand command =
>     new SqlCommand("SELECT SID FROM MyTable WHERE AccountName =
> 'MyDomain\MyAccount'", connection);
>
> byte[] sid = (byte[]) command.ExecuteScalar();
>
> SecurityIdentifier si = new SecurityIdentifier(sid, 0);
>
> --
> Happy Holidays
>
> Dan Guzman
> SQL Server MVP
>
> "Edgars Klepers" <EdgarsKlep***@discussions.microsoft.com> wrote in message
> news:73E900FD-8803-48F2-B14E-23310C4192EB@microsoft.com...
> > From my research, SID's are supposed to be stored in an SQL database as a
> > varbinary(85).
> >
> > What is the best way to translate the SID to the dotnet 2.0
> > SecurityIdentifier type?
> >
> > I am working in C# but can probably translate VB code over as well if that
> > way is easier to explain.
> >
> > Thanks for your time!
> >
> > -Edgars Klepers
>
>
>
Author
31 Dec 2005 9:05 PM
Dan Guzman
You could use GetValue (rather than GetType) then cast.  You could also use
GetBytes.

--
Happy Holidays

Dan Guzman
SQL Server MVP

Show quote
"Edgars Klepers" <EdgarsKlep***@discussions.microsoft.com> wrote in message
news:C08A4495-D87A-4409-A6C0-F1E9915D5BBB@microsoft.com...
> So from an SqlDataReader, i would just GetType(x) and typecast it to a
> byte[]?  or is there a better way to get it?
>
> "Dan Guzman" wrote:
>
>> > From my research, SID's are supposed to be stored in an SQL database as
>> > a
>> > varbinary(85).
>>
>> SecurityDescriptor.MaxBinaryLength is currently 68 in .Net framework 2.0.
>>
>> > What is the best way to translate the SID to the dotnet 2.0
>> > SecurityIdentifier type?
>>
>> If you have the byte array with SID, you can use the overloaded
>> SecurityIdentifier constructor:
>>
>> SqlCommand command =
>>     new SqlCommand("SELECT SID FROM MyTable WHERE AccountName =
>> 'MyDomain\MyAccount'", connection);
>>
>> byte[] sid = (byte[]) command.ExecuteScalar();
>>
>> SecurityIdentifier si = new SecurityIdentifier(sid, 0);
>>
>> --
>> Happy Holidays
>>
>> Dan Guzman
>> SQL Server MVP
>>
>> "Edgars Klepers" <EdgarsKlep***@discussions.microsoft.com> wrote in
>> message
>> news:73E900FD-8803-48F2-B14E-23310C4192EB@microsoft.com...
>> > From my research, SID's are supposed to be stored in an SQL database as
>> > a
>> > varbinary(85).
>> >
>> > What is the best way to translate the SID to the dotnet 2.0
>> > SecurityIdentifier type?
>> >
>> > I am working in C# but can probably translate VB code over as well if
>> > that
>> > way is easier to explain.
>> >
>> > Thanks for your time!
>> >
>> > -Edgars Klepers
>>
>>
>>
Author
31 Dec 2005 9:22 PM
Edgars Klepers
Bah, i can't believe i didnt see the getBytes();  Thanks for your help :)

-Edgars

Show quote
"Dan Guzman" wrote:

> You could use GetValue (rather than GetType) then cast.  You could also use
> GetBytes.
>
> --
> Happy Holidays
>
> Dan Guzman
> SQL Server MVP
>
> "Edgars Klepers" <EdgarsKlep***@discussions.microsoft.com> wrote in message
> news:C08A4495-D87A-4409-A6C0-F1E9915D5BBB@microsoft.com...
> > So from an SqlDataReader, i would just GetType(x) and typecast it to a
> > byte[]?  or is there a better way to get it?
> >
> > "Dan Guzman" wrote:
> >
> >> > From my research, SID's are supposed to be stored in an SQL database as
> >> > a
> >> > varbinary(85).
> >>
> >> SecurityDescriptor.MaxBinaryLength is currently 68 in .Net framework 2.0.
> >>
> >> > What is the best way to translate the SID to the dotnet 2.0
> >> > SecurityIdentifier type?
> >>
> >> If you have the byte array with SID, you can use the overloaded
> >> SecurityIdentifier constructor:
> >>
> >> SqlCommand command =
> >>     new SqlCommand("SELECT SID FROM MyTable WHERE AccountName =
> >> 'MyDomain\MyAccount'", connection);
> >>
> >> byte[] sid = (byte[]) command.ExecuteScalar();
> >>
> >> SecurityIdentifier si = new SecurityIdentifier(sid, 0);
> >>
> >> --
> >> Happy Holidays
> >>
> >> Dan Guzman
> >> SQL Server MVP
> >>
> >> "Edgars Klepers" <EdgarsKlep***@discussions.microsoft.com> wrote in
> >> message
> >> news:73E900FD-8803-48F2-B14E-23310C4192EB@microsoft.com...
> >> > From my research, SID's are supposed to be stored in an SQL database as
> >> > a
> >> > varbinary(85).
> >> >
> >> > What is the best way to translate the SID to the dotnet 2.0
> >> > SecurityIdentifier type?
> >> >
> >> > I am working in C# but can probably translate VB code over as well if
> >> > that
> >> > way is easier to explain.
> >> >
> >> > Thanks for your time!
> >> >
> >> > -Edgars Klepers
> >>
> >>
> >>
>
>
>

AddThis Social Bookmark Button