cheatsheet ldapmodify | zuhdi.org

Cheat Sheet ldapmodify

Environment

  • Debian 10.0 x64
  • slapd 2.4.44 (Jan 29 2019 17:42:45)
  • ldapmodify (Aug 10 2019 18:58:18)

Excerpt

Log 2019 / 11

1. Install ldap-utils

root@chimera:~# apt-get -y install ldap-utils

root@chimera:~# ldapmodify -VV
ldapmodify: @(#) $OpenLDAP: ldapmodify  (Aug 10 2019 18:58:18) $
        Debian OpenLDAP Maintainers <pkg-openldap-devel@lists.alioth.debian.org>
        (LDAP library: OpenLDAP 20447)

2. ldapmodify replace:

root@athos:~# ldapsearch -H ldapi:// -LLL -b 'cn=config' -s base 'olcLogLevel'
SASL/EXTERNAL authentication started
SASL username: gidNumber=0+uidNumber=0,cn=peercred,cn=external,cn=auth
SASL SSF: 0
dn: cn=config
olcLogLevel: any

2.1. Inline

root@athos:~# ldapmodify -Y EXTERNAL -H ldapi:// <<EOF
dn: cn=config
changetype: modify
replace: olcLogLevel
olcLogLevel: stats
EOF

root@athos:~# ldapmodify -Y EXTERNAL -H ldapi:// <<EOF
> dn: cn=config
> changetype: modify
> replace: olcLogLevel
> olcLogLevel: stats
> EOF
SASL/EXTERNAL authentication started
SASL username: gidNumber=0+uidNumber=0,cn=peercred,cn=external,cn=auth
SASL SSF: 0
modifying entry "cn=config"

2.2. Using LDIF File

cat <<EOF > input.ldif
dn: cn=config
changetype: modify
replace: olcLogLevel
olcLogLevel: stats
EOF

2.2.1. Show Trailing Whitespace

root@athos:~# (export GREP_COLOR='0;41'; grep --col -Enm5 '\s+$' input.ldif)
1:dn: cn=config
2:changetype: modify
3:replace: olcLogLevel
4:olcLogLevel: stats

2.2.2. Remove Trailing Whitespace

root@athos:~# sed -ri 's,\s+$,,g' input.ldif

2.2.3. ldapmodify

root@athos:~# ldapmodify -Y EXTERNAL -H ldapi:// -f input.ldif
SASL/EXTERNAL authentication started
SASL username: gidNumber=0+uidNumber=0,cn=peercred,cn=external,cn=auth
SASL SSF: 0
modifying entry "cn=config"

3. ldapmodify delete:

ldapmodify -Y EXTERNAL -H ldapi:// <<EOF
dn: cn=config
changetype: modify
delete: olcLogLevel
EOF

root@athos:~# ldapmodify -Y EXTERNAL -H ldapi:// <<EOF
> dn: cn=config
> changetype: modify
> delete: olcLogLevel
> EOF
SASL/EXTERNAL authentication started
SASL username: gidNumber=0+uidNumber=0,cn=peercred,cn=external,cn=auth
SASL SSF: 0
modifying entry "cn=config"

Hugo. Malte Kiefer & Zuhdi Najib.