Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I formulate an ldap query looking for the absence of an attribute

I want to query my directory for all User objects that don't contain a value for a given attribute... I have kind of hacked it up looking for things without a specific value (the potential assigned values are small, so this mostly worked) - but I would really like to know if there is a way to actually query for the absence of an attribute... kind of analogous to a relational database null.

Here is the query I ended up using:

(&(objectClass=User)(!extensionAttribute1=A))

Any ideas how to write an LDAP query looking for objects where an attribute has not been defined? Is this even possible?

like image 919
Goyuix Avatar asked Jul 15 '09 23:07

Goyuix


People also ask

How do you create a query in LDAP?

To create an LDAP queryBrowse the Directory manager tree and select an object in the LDAP directory. The query that you're creating will return results from this point in the tree down. Click the New LDAP query toolbar button. Type a descriptive name for the query.

How do I find the LDAP attribute name?

You can see the LDAP attribute name in the attribute editor. When working with scripts or creating a program you will need to use the LDAP attribute name. This page provides a visual reference of the LDAP field mappings in Active Directory.

What are LDAP attributes?

LDAP# Attribute has an attributeTypes, which contains the name of that attribute (which links it to an Attribute Type) and an optional set of Attribute Options, and a collection of one or more values. A LDAP Entry contains a collection of Attributes.


1 Answers

We need a few more parens when doing this:

(&(objectClass=User)(!(extensionAttribute1=*)))

If you want to look for a particular attribute you need to remove some parens (removing the ! is not enough)

(&(objectClass=User)(extensionAttribute1=*))

like image 187
JeffJak Avatar answered Oct 19 '22 20:10

JeffJak