Gmail Calendar Documents Reader Web more »
Recently Visited Groups | Help | Sign in
Google Groups Home
Convert objectSID to string
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  8 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Seagull Ng  
View profile  
 More options Jul 8 2006, 12:38 am
Newsgroups: microsoft.public.windows.server.active_directory
From: Seagull Ng <Seagul...@discussions.microsoft.com>
Date: Fri, 7 Jul 2006 07:38:02 -0700
Local: Sat, Jul 8 2006 12:38 am
Subject: Convert objectSID to string
Is there a script to convert objectSID to readable string during user account
extract process from AD to CSV file?

I have read this one:
http://blogs.msdn.com/alextch/archive/2006/03/04/convertObjectSIDtoSt... but it's not quite what I want.

Thanks.


    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Joe Kaplan (MVP - ADSI)  
View profile  
 More options Jul 8 2006, 1:06 am
Newsgroups: microsoft.public.windows.server.active_directory
From: "Joe Kaplan \(MVP - ADSI\)" <joseph.e.kap...@removethis.accenture.com>
Date: Fri, 7 Jul 2006 10:06:14 -0500
Local: Sat, Jul 8 2006 1:06 am
Subject: Re: Convert objectSID to string
If you want a script, Richard Mueller has one at his website that will work:

www.rlmueller.net

If you want .NET code, then that blog posting is good for showing how to get
SDDL.  If you want an octet string, then we have a handy function in our
book that does that which you can download from the book's code samples.

What type of "readable string" do you really want?

Joe K.

--
Joe Kaplan-MS MVP Directory Services Programming
Co-author of "The .NET Developer's Guide to Directory Services Programming"
http://www.directoryprogramming.net
--

"Seagull Ng" <Seagul...@discussions.microsoft.com> wrote in message

news:BB8FA464-3C12-4326-AFD1-8ED7DE26FE2E@microsoft.com...


    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Seagull Ng  
View profile  
 More options Jul 8 2006, 1:16 am
Newsgroups: microsoft.public.windows.server.active_directory
From: Seagull Ng <Seagul...@discussions.microsoft.com>
Date: Fri, 7 Jul 2006 08:16:02 -0700
Local: Sat, Jul 8 2006 1:16 am
Subject: Re: Convert objectSID to string
To convert from this format
X'0105000000000005150000006b50545832786a116a7cf24ee8030000' to
S-1-5-21-1481920619-292190258-1324514410-134914

Thanks Joe.

"Joe Kaplan (MVP - ADSI)" wrote:


    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Richard Mueller  
View profile  
 More options Jul 8 2006, 1:50 am
Newsgroups: microsoft.public.windows.server.active_directory
From: "Richard Mueller" <rlmueller-NOS...@ameritech.NOSPAM.net>
Date: Fri, 7 Jul 2006 10:50:05 -0500
Local: Sat, Jul 8 2006 1:50 am
Subject: Re: Convert objectSID to string

Seagull Ng wrote:
> To convert from this format
> X'0105000000000005150000006b50545832786a116a7cf24ee8030000' to
> S-1-5-21-1481920619-292190258-1324514410-134914

> Thanks Joe.

Hi,

A function to convert SID values is not easy in VBScript. After recent
correspondence with someone in the newsgroups I've come up with this code
(watch line wrapping):

Option Explicit
Dim objUser

Set objUser = GetObject("LDAP://cn=Joe User,ou=Sales,dc=MyDomain,dc=com")
Wscript.Echo ObjSidToStrSid(objUser.objectSid)

Function ObjSidToStrSid(arrSid)
    ' Function to convert OctetString (byte array) to Decimal string (SDDL)
Sid.
    Dim strHex, strDec

    strHex = OctetStrToHexStr(arrSid)
    strDec = HexStrToDecStr(strHex)
    ObjSidToStrSid = strDec
End Function ' ObjSidToStrSid

Function OctetStrToHexStr(arrbytOctet)
    ' Function to convert OctetString (byte array) to Hex string.
    Dim k

    OctetStrToHexStr = ""
    For k = 1 To Lenb(arrbytOctet)
        OctetStrToHexStr = OctetStrToHexStr _
            & Right("0" & Hex(Ascb(Midb(arrbytOctet, k, 1))), 2)
    Next
End Function ' OctetStrToHexStr

Function HexStrToDecStr(strSid)
    ' Function to convert Hex string Sid to Decimal string (SDDL) Sid.

    ' SID anatomy:
    ' Byte Position
    ' 0   : SID Structure Revision Level (SRL)
    ' 1   : Number of Subauthority/Relative Identifier
    ' 2-7 : Identifier Authority Value (IAV) [48 bits]
    ' 8-x : Variable number of Subauthority or Relative Identifier (RID) [32
bits]
    '
    ' Example:
    '
    '   <Domain/Machine>\Administrator
    ' Pos  :    0 |  1 |  2  3  4  5  6  7 |  8  9 10 11 | 12 13 14 15 | 16
17 18 19 | 20 21 22 23 | 24 25 26 27
    ' Value:   01 | 05 | 00 00 00 00 00 05 | 15 00 00 00 | 06 4E 7D 7F | 11
57 56 7A | 04 11 C5 20 | F4 01 00 00
    ' str  : S- 1 |    |                -5 | -21         | -2138918406
| -2052478737 | -549785860  | -500

    Const BYTES_IN_32BITS = 4
    Const SRL_BYTE = 0
    Const IAV_START_BYTE = 2
    Const IAV_END_BYTE = 7
    Const RID_START_BYTE = 8
    Const MSB = 3 'Most significant byte
    Const LSB = 0 'Least significant byte

    Dim arrbytSid, lngTemp, base, offset, i

    ReDim arrbytSid(Len(strSid)/2 - 1)

    ' Convert hex string into integer array
    For i = 0 To UBound(arrbytSid)
        arrbytSid(i) = CInt("&H" & Mid(strSid, 2 * i + 1, 2))
    Next

    ' Add SRL number
    HexStrToDecStr = "S-" & arrbytSid(SRL_BYTE)

    ' Add Identifier Authority Value
    lngTemp = 0
    For i = IAV_START_BYTE To IAV_END_BYTE
        lngTemp = lngTemp * 256 + arrbytSid(i)
    Next
    HexStrToDecStr = HexStrToDecStr & "-" & CStr(lngTemp)

    ' Add a variable number of 32-bit subauthority or
    ' relative identifier (RID) values.
    ' Bytes are in reverse significant order.
    ' i.e. HEX 01 02 03 04 => HEX 04 03 02 01
    ' = (((0 * 256 + 04) * 256 + 03) * 256 + 02) * 256 + 01
    ' = DEC 67305985
    For base = RID_START_BYTE To UBound(arrbytSid) Step BYTES_IN_32BITS
        lngTemp = 0
        For offset = MSB to LSB Step -1
            lngTemp = lngTemp * 256 + arrbytSid(base + offset)
        Next
        HexStrToDecStr = HexStrToDecStr & "-" & CStr(lngTemp)
    Next
End Function ' HexStrToDecStr

--
Richard
Microsoft MVP Scripting and ADSI
Hilltop Lab - http://www.rlmueller.net


    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Joe Kaplan (MVP - ADSI)  
View profile  
 More options Jul 8 2006, 3:00 am
Newsgroups: microsoft.public.windows.server.active_directory
From: "Joe Kaplan \(MVP - ADSI\)" <joseph.e.kap...@removethis.accenture.com>
Date: Fri, 7 Jul 2006 12:00:08 -0500
Local: Sat, Jul 8 2006 3:00 am
Subject: Re: Convert objectSID to string
Like Richard said, getting SDDL is not easy in script.  This is one of the
reasons I tend to avoid programming in script.  There is probably a cool way
to do this with WMI, but I'm not sure what that might be.

Best of luck!

Joe K.

--
Joe Kaplan-MS MVP Directory Services Programming
Co-author of "The .NET Developer's Guide to Directory Services Programming"
http://www.directoryprogramming.net
--

"Richard Mueller" <rlmueller-NOS...@ameritech.NOSPAM.net> wrote in message

news:%23RIjF0doGHA.196@TK2MSFTNGP05.phx.gbl...


    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Seagull Ng  
View profile  
 More options Jul 8 2006, 6:31 am
Newsgroups: microsoft.public.windows.server.active_directory
From: Seagull Ng <Seagul...@discussions.microsoft.com>
Date: Fri, 7 Jul 2006 13:31:02 -0700
Local: Sat, Jul 8 2006 6:31 am
Subject: Re: Convert objectSID to string
Thanks for your effort.
I modified a bit of your script to my convenience (to allow user input for a
common name). It works flawlessly.

Thanks again.


    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Joe Richards [MVP]  
View profile  
 More options Jul 8 2006, 6:45 am
Newsgroups: microsoft.public.windows.server.active_directory
From: "Joe Richards [MVP]" <humorexpr...@hotmail.com>
Date: Fri, 07 Jul 2006 16:45:30 -0400
Local: Sat, Jul 8 2006 6:45 am
Subject: Re: Convert objectSID to string
Richard does this handle ADAM SIDs as well as AD SIDs? The format is a
little different and many of the scripts I have seen to do the
conversion tend to break. I didn't look very close at this one I admit.

Around last september or so I worked with someone on one of the
newsgroups on how to do this properly so it works for any SID and not
just on SIDs with the assumption they have the same number of
subauthorities that a domain SID has.

I should dig that out and blog it.

--
Joe Richards Microsoft MVP Windows Server Directory Services
Author of O'Reilly Active Directory Third Edition
www.joeware.net

---O'Reilly Active Directory Third Edition now available---

         http://www.joeware.net/win/ad3e.htm


    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Richard Mueller  
View profile  
 More options Jul 8 2006, 7:51 am
Newsgroups: microsoft.public.windows.server.active_directory
From: "Richard Mueller" <rlmueller-NOS...@ameritech.NOSPAM.net>
Date: Fri, 7 Jul 2006 16:51:47 -0500
Local: Sat, Jul 8 2006 7:51 am
Subject: Re: Convert objectSID to string
Joe,

My original functions worked for most AD objects, but failed on well known
and local object Sids. I think these functions work on all. I tested on
local objects and the builtin administrators group. It's kind of a mess, but
at least it can be done. Somebody name Wilfred Wong wrote the final code and
I should put his name in a comment. I did not test ADAM SID's.

Richard

"Joe Richards [MVP]" <humorexpr...@hotmail.com> wrote in message
news:ee1UKZgoGHA.4960@TK2MSFTNGP04.phx.gbl...


    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »

Create a group - Google Groups - Google Home - Terms of Service - Privacy Policy
©2010 Google