0

I wrote an ldap search bash script with search scope/filter that contains exclamation mark '!' and asterisk '*'. Something like this and the script is not reading the string between double quotes correctly. The same filter works just fine when I pass in the command line:

"(&(objectclass=*)(uid=*)("\!"(roles=*)))"

Here's the complete ldapsearch query that is being run in bash script:

ldapsearch -h localhost -p 389 -D "cn=ldapadm,o=proxy" -W - -b "ou=users,o=org" -s sub -LLL "(&(objectclass=*)(uid=*)("\!"(roles=*)))" | grep dn:
  • Is the ! supposed to be escaped? Are the double quotes around \! supposed to be part of the string? In that case, use single quotes around the option argument to -LLL. – Kusalananda Mar 22 '18 at 16:40
3

Use single quotes as content in double quotes is interpolated by the shell and a star or a bang has a specific meaning for it.

-LLL '(&(objectclass=*)(uid=*)("\!"(roles=*)))'

I do not know if your inside double quotes are necessary, you will probably need to remove them as well, so in fact the syntax should be:

-LLL '(&(objectclass=*)(uid=*)(!(roles=*)))'
  • Yes I tried and it didn't work: '(&(objectclass=*)(cn=*)(!(naX509UserCertificate=*)))' – Riz Mar 22 '18 at 16:48
  • I also tried these and it didn't work: '(&(objectclass=*)(cn=*)("/!"(naX509UserCertificate=*)))' '(&(objectclass=*)(cn=*)(/!(naX509UserCertificate=*)))' – Riz Mar 22 '18 at 16:49
  • 1
    Does not work as in "error by the shell" or "not giving the results I expected back from the LDAP server"? These are two different things. Please update your question with more specific details. I think that '(&(objectclass=*)(cn=*)(!(naX509UserCertificate=*)))' is fine regarding syntax. – Patrick Mevzek Mar 22 '18 at 16:52
  • There's no error by the shell... it is simply not giving expected result. If I run the same filter in a command line it works just fine – Riz Mar 22 '18 at 16:56
  • Sorry I still do not understand you on the two opposing cases you write about (shell vs command line). Without way more details about exactly what you input where, I fear not to be able to help you. Maybe someone else will better understand than me. – Patrick Mevzek Mar 22 '18 at 17:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.