| 1 |
#!/bin/bash |
| 2 |
|
| 3 |
# SPDX-License-Identifier: GPL-2.0-only |
| 4 |
# This file is part of Scapy |
| 5 |
# See https://scapy.net/ for more information |
| 6 |
|
| 7 |
# Install an OpenLDAP test server |
| 8 |
|
| 9 |
# Pre-populate some setup questions |
| 10 |
sudo debconf-set-selections <<< 'slapd slapd/password2 password Bonjour1' |
| 11 |
sudo debconf-set-selections <<< 'slapd slapd/password1 password Bonjour1' |
| 12 |
sudo debconf-set-selections <<< 'slapd slapd/domain string scapy.net' |
| 13 |
|
| 14 |
# Run setup |
| 15 |
sudo apt-get -qy install slapd |
| 16 |
|
| 17 |
# Enable LDAPs |
| 18 |
echo "Enabling HTTPS on slapd..." |
| 19 |
sudo sed -i '/^SLAPD_SERVICES/ c\SLAPD_SERVICES="ldap:/// ldapi:/// ldaps://"' /etc/default/slapd |
| 20 |
sudo systemctl restart slapd |
| 21 |
|
| 22 |
# Calculate the paths we're going to need. |
| 23 |
CUR=$( cd "$(dirname "${BASH_SOURCE[0]}")" ; pwd -P ) |
| 24 |
PKIPATH=$(realpath "$CUR/../../../test/scapy/layers/tls/pki") |
| 25 |
OLDAPPATH=$(mktemp -d -t scapy_openldap_XXXX) |
| 26 |
|
| 27 |
# Copy certificates to temp path |
| 28 |
cp ${PKIPATH}/ca_cert.pem ${OLDAPPATH} |
| 29 |
cp ${PKIPATH}/srv_cert.pem ${OLDAPPATH} |
| 30 |
cp ${PKIPATH}/srv_key.pem ${OLDAPPATH} |
| 31 |
chmod a+rx -R ${OLDAPPATH} |
| 32 |
|
| 33 |
# Copy config template and replace variables. |
| 34 |
echo "Creating OpenLDAP config..." |
| 35 |
openldap_conf=${OLDAPPATH}/openldap_config.ldif |
| 36 |
cp $CUR/config.ldif $openldap_conf |
| 37 |
sed -i "s@{{CAFILE}}@${OLDAPPATH}/ca_cert.pem@g" $openldap_conf |
| 38 |
sed -i "s@{{CRTFILE}}@${OLDAPPATH}/srv_cert.pem@g" $openldap_conf |
| 39 |
sed -i "s@{{KEYFILE}}@${OLDAPPATH}/srv_key.pem@g" $openldap_conf |
| 40 |
|
| 41 |
echo "Applying OpenLDAP config..." |
| 42 |
sudo ldapmodify -Y EXTERNAL -H "ldapi:///" -w Bonjour1 -f $openldap_conf -c |
| 43 |
echo "Adding initial dummy data..." |
| 44 |
sudo ldapadd -D "cn=admin,dc=scapy,dc=net" -w Bonjour1 -H "ldapi:///" -f $CUR/testdata.ldif -c |