Problem with GUID verification in LDAP (ActiveDirectory) database.

GAMMIS

New member
Joined
Sep 3, 2020
Messages
1
Programming Experience
Beginner
As in the topic, I struggle with verifying my guid if it exists in LDAP. Guid was previously downloaded from AD and saved in SQL database. Now, for the needs of my application, I want to verify my GUID in AD if it exists. I wrote a piece of code that connects to AD and checks for the given object (adSearch.Filter = "(& (Name = John Smith 1))";). In this case I am looking for Jan Kowalski 1 in the Name attribute and it works fine and many other attributes, eg userPrincipalName etc. As soon as I check the GUID I get adResults was null. adSearch.Filter = "(& (objectGUID = 5c9a13b7-288d-4fdf-856f-e9ccddb5631e))";
C#:
       public static string GetGuid(string objectGuid, string objectClass)
        {
            DirectoryEntry adRoot = new DirectoryEntry(ConfigurationManager.AppSettings["LDAPConnection"], ConfigurationManager.AppSettings["LDAPUser"], ConfigurationManager.AppSettings["LDAPPass"]);
            Object adsiObj = adRoot.NativeObject;

            DirectorySearcher adSearch = new DirectorySearcher(adRoot);
            //adSearch.Filter = "(&(objectGUID=" + queryGuid + "))";
            adSearch.Filter = "(&(objectGUID=5c9a13b7-288d-4fdf-856f-e9ccddb5631e))";
            //adSearch.Filter = "(&(Name=Jan Kowalski 1))";

            SearchResult adResults = adSearch.FindOne();
            var adObject = adResults.GetDirectoryEntry();

            return adObject.Guid;
        }
 
Last edited by a moderator:
Welcome to the forums! In the future please post your code in code tags to make it easier for everyone to read.
 
I had to refresh some repressed memories, but as per RFC 2254, you'll need to encode that guid as a hex string. Something like
C#:
\b7\13\9a\5c\8d\28\df\47\6f\85\ ...
 
Back
Top Bottom