71 lines
1.7 KiB
Bash
Executable File
71 lines
1.7 KiB
Bash
Executable File
#!/bin/bash
|
|
|
|
# Variablen
|
|
DOMAIN="example.com"
|
|
LDAP_CONF="/etc/samba/smb.conf"
|
|
SSL_DIR="/etc/openldap/certs"
|
|
SSL_KEY="$SSL_DIR/ldap.key"
|
|
SSL_CERT="$SSL_DIR/ldap.crt"
|
|
SSL_CA="$SSL_DIR/ca.crt"
|
|
LDAP_PORT=389
|
|
LDAPS_PORT=636
|
|
|
|
# Überprüfen, ob das Skript als Root ausgeführt wird
|
|
if [ "$EUID" -ne 0 ]; then
|
|
echo "Bitte führen Sie dieses Skript als Root aus."
|
|
exit 1
|
|
fi
|
|
|
|
# Funktion zum Erstellen von Zertifikaten und Schlüsseln
|
|
create_certificates() {
|
|
mkdir -p $SSL_DIR
|
|
openssl req -x509 -nodes -days 365 -newkey rsa:2048 \
|
|
-keyout $SSL_KEY -out $SSL_CERT -subj "/CN=$DOMAIN"
|
|
cp $SSL_CERT $SSL_CA
|
|
}
|
|
|
|
# Funktion zum Importieren des Zertifikats in Samba AD DC
|
|
import_certificate() {
|
|
echo "Importieren des Zertifikats in Samba AD DC..."
|
|
net ads tls ca import $SSL_CA
|
|
}
|
|
|
|
# Funktion zum Konfigurieren von Samba für die Verwendung von LDAPS
|
|
configure_samba_for_ldaps() {
|
|
echo "Konfigurieren von Samba für die Verwendung von LDAPS..."
|
|
cat <<EOT >> $LDAP_CONF
|
|
|
|
# LDAPS Konfiguration
|
|
tls enabled = yes
|
|
tls keyfile = $SSL_KEY
|
|
tls certfile = $SSL_CERT
|
|
tls cafile = $SSL_CA
|
|
EOT
|
|
}
|
|
|
|
# Funktion zum Aktualisieren der Firewall-Regeln
|
|
update_firewall_rules() {
|
|
echo "Aktualisieren der Firewall-Regeln..."
|
|
firewall-cmd --permanent --add-port=$LDAPS_PORT/tcp
|
|
firewall-cmd --reload
|
|
}
|
|
|
|
# Funktion zum Neustarten von Samba
|
|
restart_samba() {
|
|
echo "Neustarten von Samba..."
|
|
systemctl restart samba-ad-dc
|
|
}
|
|
|
|
# Hauptprogramm
|
|
create_certificates
|
|
import_certificate
|
|
configure_samba_for_ldaps
|
|
update_firewall_rules
|
|
restart_samba
|
|
|
|
# Überprüfen der Konfiguration
|
|
echo "Überprüfen der LDAPS-Konfiguration..."
|
|
netstat -tulpen | grep :$LDAPS_PORT
|
|
|
|
echo "Die Konfiguration ist abgeschlossen. LDAP verwendet jetzt LDAPS auf Port $LDAPS_PORT."
|