Subversion Repositories ALCASAR

Rev

Rev 2715 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log

Rev 2715 Rev 2731
Line 1... Line 1...
1
#!/bin/bash
1
#!/bin/bash
2
 
2
 
3
# $Id: alcasar-ldap.sh 2715 2019-03-10 23:53:44Z tom.houdayer $
3
# $Id: alcasar-ldap.sh 2731 2019-05-26 21:09:18Z tom.houdayer $
4
 
4
 
5
# alcasar-ldap.sh
5
# alcasar-ldap.sh
6
# by Rexy
6
# by Rexy
7
# This script is distributed under the Gnu General Public License (GPL)
7
# This script is distributed under the Gnu General Public License (GPL)
8
 
8
 
Line 58... Line 58...
58
		if [ "$LDAP_SSL" == 'on' ]; then
58
		if [ "$LDAP_SSL" == 'on' ]; then
59
			$SED "s/^\tserver =.*/\tserver = \"ldaps:\/\/${LDAP_SERVER//\"/\\\\\\\"}\"/g" $LDAP_MODULE
59
			$SED "s/^\tserver =.*/\tserver = \"ldaps:\/\/${LDAP_SERVER//\"/\\\\\\\"}\"/g" $LDAP_MODULE
60
			$SED "s/^\tport =.*/\tport = 636/g" $LDAP_MODULE
60
			$SED "s/^\tport =.*/\tport = 636/g" $LDAP_MODULE
61
			[ "$LDAP_CERT_REQUIRED" == 'on' ] && require_cert='demand' || require_cert='never'
61
			[ "$LDAP_CERT_REQUIRED" == 'on' ] && require_cert='demand' || require_cert='never'
62
			$SED "s/^\t\t#?require_cert =.*/\t\trequire_cert = '$require_cert'/g" $LDAP_MODULE
62
			$SED "s/^\t\t#?require_cert =.*/\t\trequire_cert = '$require_cert'/g" $LDAP_MODULE
63
			echo -e "TLS_CACERT $LDAPS_CERT_LOC\nTLS_REQCERT $require_cert" > $OPENLDAP_CONF
63
			echo "TLS_REQCERT $require_cert" > $OPENLDAP_CONF
-
 
64
			[ -f "$LDAPS_CERT_LOC" ] && echo "TLS_CACERT $LDAPS_CERT_LOC" >> $OPENLDAP_CONF
64
		else
65
		else
65
			$SED "s/^\tserver =.*/\tserver = \"ldap:\/\/${LDAP_SERVER//\"/\\\\\\\"}\"/g" $LDAP_MODULE
66
			$SED "s/^\tserver =.*/\tserver = \"ldap:\/\/${LDAP_SERVER//\"/\\\\\\\"}\"/g" $LDAP_MODULE
66
			$SED "s/^\tport =.*/\tport = 389/g" $LDAP_MODULE
67
			$SED "s/^\tport =.*/\tport = 389/g" $LDAP_MODULE
67
			echo  '' > $OPENLDAP_CONF
68
			echo  '' > $OPENLDAP_CONF
68
		fi
69
		fi
69
		$SED "s/^\tidentity =.*/\tidentity = \"${LDAP_USER//\"/\\\\\\\"}\"/g" $LDAP_MODULE
70
		$SED "s/^\tidentity =.*/\tidentity = \"${LDAP_USER//\"/\\\\\\\"}\"/g" $LDAP_MODULE
70
		$SED "s/^\tpassword =.*/\tpassword = \"${LDAP_PASSWORD//\"/\\\\\\\"}\"/g" $LDAP_MODULE
71
		$SED "s/^\tpassword =.*/\tpassword = \"${LDAP_PASSWORD//\"/\\\\\\\"}\"/g" $LDAP_MODULE
71
		$SED "s/^\tbase_dn =.*/\tbase_dn = \"${LDAP_BASE//\"/\\\\\\\"}\"/g" $LDAP_MODULE
72
		$SED "s/^\tbase_dn =.*/\tbase_dn = \"${LDAP_BASE//\"/\\\\\\\"}\"/g" $LDAP_MODULE
72
		[ -n "$LDAP_FILTER" ] && filter="$LDAP_FILTER" || filter='&'
73
		[ -n "$LDAP_FILTER" ] && filter="$LDAP_FILTER" || filter='&'
73
		$SED "s/^\t\tfilter =.*/\t\tfilter = \"(\&(${LDAP_UID//\"/\\\\\\\"}=%{%{Stripped-User-Name}:-%{User-Name}})($filter))\"/g" $LDAP_MODULE
74
		$SED "s/^\t\tfilter =.*/\t\tfilter = \"(\&(${LDAP_UID//\"/\\\\\\\"}=%{%{Stripped-User-Name}:-%{User-Name}})(${filter//&/\\&}))\"/g" $LDAP_MODULE
74
		if [ ! -e /etc/raddb/mods-enabled/ldap ]; then
75
		if [ ! -e /etc/raddb/mods-enabled/ldap ]; then
75
			ln -s $LDAP_MODULE /etc/raddb/mods-enabled/ldap
76
			ln -s $LDAP_MODULE /etc/raddb/mods-enabled/ldap
76
		fi
77
		fi
77
		[ -e /etc/raddb/sites-enabled/alcasar ] && rm /etc/raddb/sites-enabled/alcasar
78
		[ -e /etc/raddb/sites-enabled/alcasar ] && rm /etc/raddb/sites-enabled/alcasar
78
		ln -s /etc/raddb/sites-available/alcasar-with-ldap /etc/raddb/sites-enabled/alcasar
79
		ln -s /etc/raddb/sites-available/alcasar-with-ldap /etc/raddb/sites-enabled/alcasar
Line 88... Line 89...
88
		;;
89
		;;
89
	--import-cert)
90
	--import-cert)
90
		cert=$2
91
		cert=$2
91
		[ -z "$cert" ] && echo "$usage" && exit 1
92
		[ -z "$cert" ] && echo "$usage" && exit 1
92
 
93
 
-
 
94
		[ ! -f "$cert" ] && { echo >&2 "ERR: certificate file \"$cert\" not found" ; exit 1; }
-
 
95
 
-
 
96
		# TODO : convert DER format to PEM ?
-
 
97
		cp -f "$cert" $LDAPS_CERT_LOC
-
 
98
		chown root:radius $LDAPS_CERT_LOC
-
 
99
		chmod 644 $LDAPS_CERT_LOC
-
 
100
 
93
		if [ "$LDAP_CERT_REQUIRED" == 'on' ]; then
101
		if [ "$LDAP_CERT_REQUIRED" == 'on' ]; then
94
			domainName=$(openssl x509 -noout -subject -in $LDAPS_CERT_LOC | cut -d' ' -f2- | sed 's@/[A-Za-z]\+=@\n@g' | tac | tr '\n' '.' | sed  's@\.\+$@@')
102
			domainName=$(openssl x509 -noout -subject -in $LDAPS_CERT_LOC | cut -d' ' -f2- | sed 's@/[A-Za-z]\+=@\n@g' | tac | tr '\n' '.' | sed  's@\.\+$@@')
95
			if [ "$domainName" != "$LDAP_SERVER" ]; then
103
			if [ "$domainName" != "$LDAP_SERVER" ]; then
96
				echo 'WARN: the common name of the certificate is different from the server domain name'
104
				echo 'WARN: the common name of the certificate is different from the server domain name'
97
			fi
105
			fi
98
		fi
106
		fi
99
		# TODO : convert DER format to PEM ?
-
 
100
		cp -f "$cert" $LDAPS_CERT_LOC
-
 
101
		chown root:radius $LDAPS_CERT_LOC
-
 
102
		chmod 644 $LDAPS_CERT_LOC
-
 
103
 
107
 
104
		$SED "s/^LDAP_SSL=.*/LDAP_SSL=on/g" $CONF_FILE
108
		$SED "s/^LDAP_SSL=.*/LDAP_SSL=on/g" $CONF_FILE
105
		$SED "s/^\tserver =.*/\tserver = \"ldaps:\/\/${LDAP_SERVER//\"/\\\\\\\"}\"/g" $LDAP_MODULE
109
		$SED "s/^\tserver =.*/\tserver = \"ldaps:\/\/${LDAP_SERVER//\"/\\\\\\\"}\"/g" $LDAP_MODULE
106
		$SED "s/^\tport =.*/\tport = 636/g" $LDAP_MODULE
110
		$SED "s/^\tport =.*/\tport = 636/g" $LDAP_MODULE
107
		$SED "s@^#\?\t\tca_file =.*@\t\tca_file = $LDAPS_CERT_LOC@g" $LDAP_MODULE
111
		$SED "s@^#\?\t\tca_file =.*@\t\tca_file = $LDAPS_CERT_LOC@g" $LDAP_MODULE