Retriving the SID from a Relative Distinguished Name (RDN)

I have a RDN (like "DC=local, DC=smart, CN=Users, CN=User One") that is returned from a certificate
(CertGetNameString( pCertContext, CERT_NAME_RDN_TYPE,  0, &dwStrType, szNameString, 128))

I would like to have the SID for this RDN name. I guess there must be some kind of Active Directory (ADSI) function for this (preferably that doesn't require binding to a certain domain or server), but my knowledge to ADSI is limited?
OleSetnesAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

grayeCommented:
You'll have to use LDAP to connect to the domain to retrieve the user object.   Yes, that means you'll have to bind to any one of the domain controllers (usually by just using the domain name, not a server name).   Yes, that also means that you'll have to provide credentials to do so (unless you're domain is setup as a WinNT compatible domain which allows anonomous enumerations)

http://www.microsoft.com/windows2000/techinfo/howitworks/activedirectory/adinterface.asp

Once you've got the user object, you can obtain the the LoginName property.   Using the DomainName and LoginName you then use the LookupAccountName API to return the SID

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/secauthz/security/lookupaccountname.asp



Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Programming

From novice to tech pro — start learning today.