1
|
#!/bin/sh
|
2
|
# Do initial configuration of slapd
|
3
|
|
4
|
set -e
|
5
|
|
6
|
LDIFDIR=/usr/share/u-auth
|
7
|
|
8
|
BACKUPDIR="/var/backup/reset-ldap-`date +%Y%m%dT%H:%M:%S`"
|
9
|
mkdir -p "$BACKUPDIR"
|
10
|
echo Old configuration saved in $BACKUPDIR
|
11
|
cp -R /var/lib/ldap /etc/ldap/slapd.d/ "$BACKUPDIR"
|
12
|
rm -rf /var/lib/ldap/*
|
13
|
mkdir /var/lib/ldap/config-accesslog/
|
14
|
|
15
|
echo Load overlay modules, configure auditlog for cn=config
|
16
|
slapadd -n0 -F/etc/ldap/slapd.d -l${LDIFDIR}/radius.ldif
|
17
|
|
18
|
echo "Suffixe de la base à créer (exemple : dc=univ-psl,dc=fr) :"
|
19
|
echo -n "-> "
|
20
|
read SUFFIX
|
21
|
echo
|
22
|
|
23
|
if [ -d "/var/lib/ldap/$SUFFIX" ]; then
|
24
|
echo "ERR: le répertoire '/var/lib/ldap/$SUFFIX' existe déjà" >&2
|
25
|
exit 1
|
26
|
fi
|
27
|
|
28
|
if ldapsearch -H ldapi:// -Y EXTERNAL -b cn=config olcSuffix=$SUFFIX 2>/dev/null | grep -q '^result: [1-9]'; then
|
29
|
echo "ERR: le suffixe $SUFFIX existe déjà" >&2
|
30
|
exit 2
|
31
|
fi
|
32
|
|
33
|
echo "Choisir un mot de passe administrateur (uid=admin,ou=people,$SUFFIX) :"
|
34
|
echo -n "-> "
|
35
|
stty -echo
|
36
|
read PASSWORD
|
37
|
stty echo
|
38
|
echo
|
39
|
echo "Une nouvelle fois :"
|
40
|
echo -n "-> "
|
41
|
stty -echo
|
42
|
read PASSWORD2
|
43
|
stty echo
|
44
|
echo
|
45
|
if [ x"$PASSWORD" != x"$PASSWORD2" ]; then
|
46
|
echo "ERR: mots de passe différents" >&2
|
47
|
exit 3
|
48
|
fi
|
49
|
echo
|
50
|
|
51
|
echo "Nom de l'organisation (ou=...) :"
|
52
|
echo "uniquement des majuscules, sans accent"
|
53
|
echo "Exemple: ENS"
|
54
|
echo -n "-> "
|
55
|
read ORGANIZATION
|
56
|
echo
|
57
|
|
58
|
|
59
|
echo "Récapitulatif :"
|
60
|
echo " Suffixe : $SUFFIX"
|
61
|
echo " Nom : $ORGANIZATION"
|
62
|
echo "DN établissement : ou=$ORGANIZATION,$SUFFIX"
|
63
|
echo
|
64
|
echo "Créer cette base ? (taper oui)"
|
65
|
echo -n "-> "
|
66
|
read OK
|
67
|
echo
|
68
|
|
69
|
if [ "x$OK" != "xoui" ]; then
|
70
|
exit 4
|
71
|
fi
|
72
|
|
73
|
DC=`echo $SUFFIX | sed 's/dc=\([^,]*\).*/\1/'`
|
74
|
|
75
|
DBDIR=/var/lib/ldap/$SUFFIX
|
76
|
DBACCESSLOGDIR=/var/lib/ldap/$SUFFIX/accesslog/
|
77
|
|
78
|
mkdir -p "$DBDIR" "$DBACCESSLOGDIR"
|
79
|
|
80
|
chown -R openldap:openldap /etc/ldap/slapd.d /var/lib/ldap
|
81
|
|
82
|
LDIF=`tempfile --prefix=newdb --suffix=.ldif`
|
83
|
cat << EOF > $LDIF
|
84
|
# LDAPVI syntax
|
85
|
add olcDatabase={1}mdb,cn=config
|
86
|
objectClass: olcDatabaseConfig
|
87
|
objectClass: olcMdbConfig
|
88
|
olcDatabase: {1}mdb
|
89
|
olcSuffix: $SUFFIX
|
90
|
olcDbDirectory: /var/lib/ldap/$SUFFIX/
|
91
|
olcRootDN: uid=admin,ou=people,$SUFFIX
|
92
|
olcRootPW: $PASSWORD
|
93
|
olcLastMod: TRUE
|
94
|
olcAddContentACL: FALSE
|
95
|
olcMonitoring: TRUE
|
96
|
olcSyncUseSubentry: FALSE
|
97
|
olcMaxDerefDepth: 0
|
98
|
olcLimits: {0}dn.exact="uid=admin,ou=people,$SUFFIX" size.soft=unlimited size.hard=unlimited time.soft=unlimited time.hard=unlimited
|
99
|
olcLimits: {1}dn.exact="gidNumber=0+uidNumber=0,cn=peercred,cn=external,cn=auth" size.soft=unlimited size.hard=unlimited time.soft=unlimited time.hard=unlimited
|
100
|
olcReadOnly: FALSE
|
101
|
# Index
|
102
|
olcDbIndex: objectClass,member,owner eq
|
103
|
olcDbIndex: mail,givenName,uid,cn,sn,displayName pres,eq,approx,sub
|
104
|
# Accès super-utilisateur
|
105
|
olcAccess: {0}to *
|
106
|
by dn.exact="gidNumber=0+uidNumber=0,cn=peercred,cn=external,cn=auth" manage
|
107
|
by group.exact="cn=admin,ou=groups,$SUFFIX" manage
|
108
|
by * break
|
109
|
# Branche people
|
110
|
olcAccess: {1}to dn.regex="uid=[^,]+,ou=people,$SUFFIX" attrs=userPassword,labeledURI
|
111
|
by self write
|
112
|
by * break
|
113
|
# Les accès aux autres attributs utilisateurs
|
114
|
olcAccess: {2}to dn.one="ou=people,$SUFFIX"
|
115
|
by users read
|
116
|
by anonymous auth
|
117
|
by * none
|
118
|
# Branche groups
|
119
|
# Le propriétaire du groupe
|
120
|
olcAccess: {3}to dn.one="ou=groups,$SUFFIX"
|
121
|
by set="this/owner & user" manage
|
122
|
by * break
|
123
|
# Les utilisateurs en général sur les attributs descriptifs
|
124
|
olcAccess: {4}to dn.one="ou=groups,$SUFFIX" attrs=cn,description,owner
|
125
|
by users read
|
126
|
by * break
|
127
|
|
128
|
# Create accesslog DIT
|
129
|
add olcDatabase={1}mdb,cn=config
|
130
|
objectClass: olcDatabaseConfig
|
131
|
objectClass: olcMdbConfig
|
132
|
olcSuffix: cn=accesslog,$SUFFIX
|
133
|
olcDbDirectory: /var/lib/ldap/$SUFFIX/accesslog/
|
134
|
olcAccess: {0}to *
|
135
|
by dn.exact=gidNumber=0+uidNumber=0,cn=peercred,cn=external,cn=auth manage
|
136
|
by group=cn=admin,ou=groupes,$SUFFIX manage
|
137
|
by * break
|
138
|
|
139
|
add olcOverlay={0}syncprov,olcDatabase={1}mdb,cn=config
|
140
|
objectClass: olcOverlayConfig
|
141
|
objectClass: olcSyncProvConfig
|
142
|
olcOverlay: {0}syncprov
|
143
|
olcSpCheckpoint: 100 10
|
144
|
olcSpSessionlog: 100
|
145
|
|
146
|
# Log all writes to the db
|
147
|
add olcOverlay={1}accesslog,olcDatabase={2}mdb,cn=config
|
148
|
objectClass: olcAccesslogConfig
|
149
|
objectClass: olcOverlayConfig
|
150
|
objectClass: olcConfig
|
151
|
objectClass: top
|
152
|
olcOverlay: {1}accesslog
|
153
|
olcAccessLogDB: cn=accesslog,$SUFFIX
|
154
|
olcAccessLogOps: writes
|
155
|
# log are conserved one year and purged every day
|
156
|
olcAccessLogPurge: 365+00:00 1+00:00
|
157
|
# Keep a copy of everything
|
158
|
olcAccessLogOld: objectClass=*
|
159
|
|
160
|
add olcOverlay={2}refint,olcDatabase={2}mdb,cn=config
|
161
|
objectClass: olcOverlayConfig
|
162
|
objectClass: olcRefintConfig
|
163
|
olcOverlay: {2}refint
|
164
|
olcRefintAttribute: member
|
165
|
olcRefintNothing: $SUFFIX
|
166
|
|
167
|
add olcOverlay={3}constraint,olcDatabase={2}mdb,cn=config
|
168
|
objectClass: olcOverlayConfig
|
169
|
objectClass: olcConstraintConfig
|
170
|
olcOverlay: {3}constraint
|
171
|
# un seul cn pour les utilisateurs
|
172
|
olcConstraintAttribute: cn count 1 restrict="ldap:///ou=people,$SUFFIX??sub?(objectClass=*)"
|
173
|
#olcConstraintAttribute: cn regex "^[-A-Z' ]*$" restrict="ldap:///ou=people,$SUFFIX??sub?(objectClass=*)"
|
174
|
olcConstraintAttribute: cn regex "^[-A-Za-z0-9 ]*$" restrict="ldap:///ou=groups,$SUFFIX??sub?(objectClass=*)"
|
175
|
olcConstraintAttribute: cn regex "^[-A-Za-z0-9 ]*$" restrict="ldap:///$SUFFIX??base?(objectClass=*)"
|
176
|
olcConstraintAttribute: dc regex "^[a-z0-9-]*$"
|
177
|
olcConstraintAttribute: mail count 1
|
178
|
olcConstraintAttribute: mail
|
179
|
regex "^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$"
|
180
|
# olcConstraintAttribute: mailForwardingAddress
|
181
|
regex "^([a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}|[a-zA-Z0-9]+)$" # mail ou uid
|
182
|
|
183
|
add $SUFFIX
|
184
|
objectClass: organization
|
185
|
objectClass: dcObject
|
186
|
dc: $DC
|
187
|
o: $ORGANIZATION
|
188
|
|
189
|
add ou=people,$SUFFIX
|
190
|
objectClass: organizationalUnit
|
191
|
ou: people
|
192
|
|
193
|
add uid=admin,ou=people,$SUFFIX
|
194
|
objectClass: inetOrgPerson
|
195
|
uid: admin
|
196
|
cn: Administrateur annuaire
|
197
|
displayName: Administrateur annuaire
|
198
|
givenName: Administrateur
|
199
|
sn: annuaire
|
200
|
userPassword: $PASSWORD
|
201
|
|
202
|
add ou=$ORGANIZATION,$SUFFIX
|
203
|
objectClass: organizationalUnit
|
204
|
ou: $ORGANIZATION
|
205
|
|
206
|
EOF
|
207
|
|
208
|
|
209
|
echo "Chargement de la définition de la nouvelle base annuaire ($LDIF) :"
|
210
|
ldapvi --verbose --profile config --ldapmodify --ldapvi --add $LDIF
|
211
|
# slapadd -n0 -F/etc/ldap/slapd.d -l${LDIF}
|
212
|
echo "OK"
|
213
|
|
214
|
chown -R openldap.openldap /etc/ldap/slapd.d /var/lib/ldap
|
215
|
|
216
|
LDAP_SETUP=`tempfile --prefix=ldap --suffix=.conf`
|
217
|
cat << EOF > $LDAP_SETUP
|
218
|
ldap {
|
219
|
#
|
220
|
# Note that this needs to match the name in the LDAP
|
221
|
# server certificate, if you're using ldaps.
|
222
|
server = "localhost"
|
223
|
identity = "uid=admin,ou=people,$SUFFIX"
|
224
|
password = "$PASSWORD"
|
225
|
basedn = "$ORGANIZATION,$SUFFIX"
|
226
|
filter = "(uid=%{%{Stripped-User-Name}:-%{User-Name}})"
|
227
|
#base_filter = "(objectclass=radiusprofile)"
|
228
|
|
229
|
ldap_connections_number = 5
|
230
|
|
231
|
# How many times the connection can be used before
|
232
|
# being re-established. This is useful for things
|
233
|
# like load balancers, which may exhibit sticky
|
234
|
# behaviour without it. (0) is unlimited.
|
235
|
max_uses = 0
|
236
|
|
237
|
# Port to connect on, defaults to 389. Setting this to
|
238
|
# 636 will enable LDAPS if start_tls (see below) is not
|
239
|
# able to be used.
|
240
|
#port = 389
|
241
|
|
242
|
# seconds to wait for LDAP query to finish. default: 20
|
243
|
timeout = 4
|
244
|
|
245
|
# seconds LDAP server has to process the query (server-side
|
246
|
# time limit). default: 20
|
247
|
#
|
248
|
# LDAP_OPT_TIMELIMIT is set to this value.
|
249
|
timelimit = 3
|
250
|
|
251
|
#
|
252
|
# seconds to wait for response of the server. (network
|
253
|
# failures) default: 10
|
254
|
#
|
255
|
# LDAP_OPT_NETWORK_TIMEOUT is set to this value.
|
256
|
net_timeout = 1
|
257
|
|
258
|
# Mapping of RADIUS dictionary attributes to LDAP
|
259
|
# directory attributes.
|
260
|
dictionary_mapping = ${confdir}/ldap.attrmap
|
261
|
|
262
|
# Un-comment the following to disable Novell
|
263
|
# eDirectory account policy check and intruder
|
264
|
# detection. This will work *only if* FreeRADIUS is
|
265
|
# configured to build with --with-edir option.
|
266
|
#
|
267
|
edir_account_policy_check = no
|
268
|
|
269
|
# By default, if the packet contains a User-Password,
|
270
|
# and no other module is configured to handle the
|
271
|
# authentication, the LDAP module sets itself to do
|
272
|
# LDAP bind for authentication.
|
273
|
#
|
274
|
# THIS WILL ONLY WORK FOR PAP AUTHENTICATION.
|
275
|
#
|
276
|
# THIS WILL NOT WORK FOR CHAP, MS-CHAP, or 802.1x (EAP).
|
277
|
#
|
278
|
# You can disable this behavior by setting the following
|
279
|
# configuration entry to "no".
|
280
|
#
|
281
|
# allowed values: {no, yes}
|
282
|
# set_auth_type = yes
|
283
|
|
284
|
|
285
|
# Keepalive configuration. This MAY NOT be supported by your
|
286
|
# LDAP library. If these configuration entries appear in the
|
287
|
# output of "radiusd -X", then they are supported. Otherwise,
|
288
|
# they are unsupported, and changing them will do nothing.
|
289
|
#
|
290
|
keepalive {
|
291
|
# LDAP_OPT_X_KEEPALIVE_IDLE
|
292
|
idle = 60
|
293
|
|
294
|
# LDAP_OPT_X_KEEPALIVE_PROBES
|
295
|
probes = 3
|
296
|
|
297
|
# LDAP_OPT_X_KEEPALIVE_INTERVAL
|
298
|
interval = 3
|
299
|
}
|
300
|
}
|
301
|
EOF
|
302
|
|
303
|
|
304
|
service freeradius stop
|
305
|
|
306
|
cp /etc/freeradius/modules/ldap /etc/freeradius/modules/ldap.backup
|
307
|
mv $LDAP_SETUP /etc/freeradius/modules/ldap
|
308
|
|
309
|
service freeradius start
|