#!/bin/sh
# Throwaway LDAP server + nslcd client on one host, with one LDAP-only user "ldapuser".
set -e
export DEBIAN_FRONTEND=noninteractive
debconf-set-selections <<D
slapd slapd/domain string example.org
slapd shared/organization string Example
slapd slapd/password1 password adminpw
slapd slapd/password2 password adminpw
nslcd nslcd/ldap-uris string ldap://127.0.0.1/
nslcd nslcd/ldap-base string dc=example,dc=org
libnss-ldapd libnss-ldapd/nsswitch multiselect passwd, group, shadow
D
apt-get -q update >/dev/null
apt-get -q -y install slapd ldap-utils nslcd libnss-ldapd libpam-ldapd sshpass >/dev/null
H=$(slappasswd -s userpw)
ldapadd -x -D cn=admin,dc=example,dc=org -w adminpw <<L
dn: ou=people,dc=example,dc=org
objectClass: organizationalUnit
ou: people

dn: uid=ldapuser,ou=people,dc=example,dc=org
objectClass: inetOrgPerson
objectClass: posixAccount
objectClass: shadowAccount
cn: LDAP User
sn: User
uid: ldapuser
uidNumber: 20001
gidNumber: 100
homeDirectory: /home/ldapuser
loginShell: /bin/bash
userPassword: $H
L
pam-auth-update --enable mkhomedir
mkdir -p /etc/ssh/sshd_config.d
printf 'PasswordAuthentication yes\nKbdInteractiveAuthentication no\n' > /etc/ssh/sshd_config.d/00-test.conf
systemctl restart ssh nslcd
getent passwd ldapuser
