ETOOBUSY 🚀 minimal blogging for the impatient
I know this is supposed to be a blog and that there exist services to keep bookmarks (e.g. Pinboard), but I’ve found myself looking for this lately and it’s just useful.
With this in mind, I was sincerely afraid when I discovered that attribute userAccountControl is a bit field and I wanted to look for records matching a particular value in a particular bit. Oh my.
Then it occurred to me that, well, I can not be the only one to have this need, or to ever need this at all. So… search engines to the rescue! Which landed me to Filtering for Bit Fields.
So it appears that Active Directory is one of the few to use bit fields extensively, which led people at Microsoft to implement a syntax that targets specific bits.
It’s possible to test multiple bits in a single filter rule, allowing for AND-ing them or OR-ing them:
# looking for disabled records, AND style (userAccountControl:1.2.840.1135188.8.131.523:=2) # ditto, OR style (804 instead of 803) (userAccountControl:1.2.840.1135184.108.40.2064:=2)
Well, of course the two styles collapse when we’re only looking for one bit, but you get the idea.
Just to ease copy-and-paste, it’s worth to add the negated condition for enabled records:
# looking for enabled records, AND style (!(userAccountControl:1.2.840.1135220.127.116.113:=2))
The general rule for bit fields (from the linked page) is the following:
# AND --> 803 <---------------------. <Attribute name>:1.2.840.113518.104.22.1683:=<decimal comparative value> # OR --> 804 <---------------------. <Attribute name>:1.2.840.113522.214.171.1244:=<decimal comparative value>
comparative value on the right hand side has to be a
decimal apparently and cannot be, say, a binary or a hexadecimal
value. I think this is pretty lame, but there’s worse.
Stay safe folks!