 |
Forums |
Admin Discussion Forums: help Start New Thread
By: Jamey Cribbs
RE: Convert AD objectguid to hex string [ reply ] 2007-10-31 22:14
|
My situation is this:
I have a rake task that runs a stored procedure against a (non-Rails) MS SQL db, the result set is all the employees that I need to pull out of AD and create records for in my Rails app. I don't want every person in AD, just the ones that are in the stored procedure.
One of the stored procedure fields is ad_guid, which is a hex string version of the AD objectguid.
What I would like to do is to use this field to directly search AD by objectguid.
Since I can't get that to work, I'm doing something similar to what you are doing. I search AD by email address and then check the returned record's objectguid against the stored procedure's ad_guid field to make sure I have the same record.
But, it would be cleaner if I could search AD by objectguid.
|
By: James Hunt
RE: Convert AD objectguid to hex string [ reply ] 2007-10-31 21:48
|
I don't recall ever having done a lookup by Object GUID. I maintain the GUIDs in a synchronizing setup where my app database essentially pulls all of the info out of AD for local querying. The GUID allows me to determine if an entry in the local db and the AD store are identical, even if the username / first name / last name / etc. have all changed.
I'd be interested to know the circumstances of needing to look up by object guid...
|
By: Jamey Cribbs
RE: Convert AD objectguid to hex string [ reply ] 2007-10-31 21:44
|
Hey, James. Thanks for all the help. I probably should have posted sooner, cause I did find a partial solution.
I used #unpack("H*") and then did something similar to what you did with the gsub to insert the dashes at the proper spot.
The only thing I still can't figure out is how to use ldap to match on the binary string objectguid. When I set the objectguid as the filter and try to convert the hex string back to a binary string and search on that, I don't get any hits.
Maybe you just can't do an ldap lookup on objectguid using net-ldap.
Thanks again!
|
By: James Hunt
RE: Convert AD objectguid to hex string [ reply ] 2007-10-31 21:35
|
This might work out for you:
text = objectguid.split(//).collect { |d| d[0].to_s(16) }.join('').gsub(/(.{7})(.{4})(.{4})(.{4})(.*)/,'\1-\2-\3-\4-\5').upcase
=> "6A8B292-9312-E5E4-3BC4-7E66BE64D604F"
It takes the binary object guid as a string, iterates over each character and turns it into hex notation (to_s(16)), joins those strings together, and then uses gsub with positional markers to insert the hypens.
I'm sure you can find a less obfuscated way of carrying out that last part, if you were going to refactor this into a function...
|
By: Jamey Cribbs
Convert AD objectguid to hex string [ reply ] 2007-10-25 22:50
|
First of all, thanks very much for the library. Much appreciated!
When I grab a record from Active Directory using net-ldap, it returns the objectguid as a binary field. I need to match this field against a (I think) hex string that I am getting from another system. Here is an example of the string I am trying to match against:
"D48D7CAF-D0C7-1745-8D0B-91E50294EFC6"
I've been trying to figure out how to convert the binary field to something resembling this using Ruby's unpack method, but I am really just shooting in the dark. Does anyone have any ideas?
Thanks.
Jamey Cribbs
|
|
 |