带负参数的 Ldap 搜索

Ldap search with negative parameter

我正尝试在我的 LDAP 基础上进行这样的搜索:

ldapsearch  -x -h localhost -p 389 -D uid=xxxadmin,ou=administrators,ou=topologymanagement,o=netscaperoot -v -w 12345 -b "ou=Usuarios,ou=Alunos,ou=XXXX,o=xxXXXxx" -f (!(objectClass=ntUser)) 1.1

基本上我想列出所有没有 objectClass ntUser 的条目并向它们添加 objectClass。

我得到这个作为答案:

-bash: !: event not found

您的搜索应该有效。但是,对于 bash,您需要引用参数。

类似于:

ldapsearch  -x -h localhost -p 389 -D uid=xxxadmin,ou=administrators,ou=topologymanagement,o=netscaperoot -v -w 12345 -b "ou=Usuarios,ou=Alunos,ou=XXXX,o=xxXXXxx" -f "(!(objectClass=ntUser))" 1.1

测试了两个 openLDAP

@(#) $OpenLDAP: ldapsearch  (Ubuntu) (Mar 17 2014 21:19:27) $buildd@aatxe:/build/buildd/openldap-2.4.31/debian/build/clients/tools
(LDAP library: OpenLDAP 20431)

ldapsearch -x -h localhost -p 389 -D "cn=admin" -W -b "dc=example,dc=com" -s sub -a always -z 1000 "(!(objectClass=inetOrgPerson))" "objectClass"

和 OpenDJ

ldapsearch --version
        OpenDJ 2.7.0-20140727
        Build 20140727000040Z

ldapsearch -h localhost -p 389 -D "cn=admin" -b "dc=example,dc=com" -s sub -a always -z 1000 "(!(objectClass=inetOrgPerson))" "objectClass"

-吉姆

它的发生是因为 bash 认为!作为特殊字符

"!" Start a history substitution, except when followed by a space, tab, the end of the line, ‘=’ or ‘(’

所以最后,您应该能够通过在术语周围加上单引号来解决您的问题,如下所示:

ldapsearch  -x -h localhost -p 389 -D uid=xxxadmin,ou=administrators,ou=topologymanagement,o=netscaperoot -v -w 12345 -b "ou=Usuarios,ou=Alunos,ou=XXXX,o=xxXXXxx" -f '(!(objectClass=ntUser))' 1.1

请参考Whosebug上的以下问题。

Which characters need to be escaped in Bash? How do we know it?

来自http://www.openldap.org/lists/openldap-software/200104/msg00196.html

This message comes from the shell (bash). It states that the command `!' didn't find the event you unintentionally asked for. This happens because the double quotes in bash do not prevent some command invocation. Use single quotes instead:

您的搜索应该是这样的:

ldapsearch  -x -h localhost -p 389 -D 'uid=xxxadmin,ou=administrators,ou=topologymanagement,o=netscaperoot' -v -w 12345 -b 'ou=Usuarios,ou=Alunos,ou=XXXX,o=xxXXXxx' -f '(!(objectClass=ntUser))' 1.1