r21707: Finally merge my (long-living) perlselftest branch.
[ab/samba.git/.git] / source / script / tests / mk-openldap.sh
1 SLAPD_CONF=$LDAPDIR/slapd.conf
2 export SLAPD_CONF
3
4 cat >$SLAPD_CONF <<EOF
5 loglevel 0
6
7 include $LDAPDIR/ad.schema
8
9 pidfile         $PIDDIR/slapd.pid
10 argsfile        $LDAPDIR/slapd.args
11 sasl-realm $DNSNAME
12 access to * by * write
13
14 allow update_anon
15
16 authz-regexp
17           uid=([^,]*),cn=$DNSNAME,cn=digest-md5,cn=auth
18           ldap:///$BASEDN??sub?(samAccountName=\$1)
19
20 authz-regexp
21           uid=([^,]*),cn=([^,]*),cn=digest-md5,cn=auth
22           ldap:///$BASEDN??sub?(samAccountName=\$1)
23
24 include $LDAPDIR/modules.conf
25
26 defaultsearchbase "$BASEDN"
27
28 backend         bdb
29 database        bdb
30 suffix          "$BASEDN"
31 rootdn          "cn=Manager,$BASEDN"
32 rootpw          $PASSWORD
33 directory       $LDAPDIR/db
34 index           objectClass eq
35 index           samAccountName eq
36 index name eq
37 index objectSid eq
38 index objectCategory eq
39 index member eq
40 index uidNumber eq
41 index gidNumber eq
42 index unixName eq
43 index privilege eq
44 index nCName eq pres
45 index lDAPDisplayName eq
46 index subClassOf eq
47 index dnsRoot eq
48 index nETBIOSName eq pres
49
50 overlay syncprov
51 syncprov-checkpoint 100 10
52 syncprov-sessionlog 100
53
54 EOF
55
56 cat > $LDAPDIR/db/DB_CONFIG <<EOF
57 #
58         # Set the database in memory cache size.
59         #
60         set_cachesize   0       524288        0
61         
62         
63         #
64         # Set database flags (this is a test environment, we don't need to fsync()).
65         #               
66         set_flags       DB_TXN_NOSYNC
67         
68         #
69         # Set log values.
70         #
71         set_lg_regionmax        104857
72         set_lg_max              1048576
73         set_lg_bsize            209715
74         set_lg_dir              $LDAPDIR/db/bdb-logs
75         
76         
77         #
78         # Set temporary file creation directory.
79         #                       
80         set_tmp_dir             $LDAPDIR/db/tmp
81 EOF
82
83 LDAP_URI="ldapi://$LDAPDIR/ldapi"
84 LDAP_URI_ESCAPE="ldapi://"`echo $LDAPDIR/ldapi | sed 's|/|%2F|g'`
85 export LDAP_URI
86 export LDAP_URI_ESCAPE
87
88 #This uses the provision we just did, to read out the schema
89 $srcdir/bin/ad2oLschema $CONFIGURATION -H $PRIVATEDIR/sam.ldb -I $srcdir/setup/schema-map-openldap-2.3 -O $LDAPDIR/ad.schema >&2
90
91 #Now create an LDAP baseDN
92 $srcdir/bin/smbscript $srcdir/setup/provision $PROVISION_OPTIONS --ldap-base >&2
93
94 OLDPATH=$PATH
95 PATH=/usr/local/sbin:/usr/sbin:/sbin:$PATH
96 export PATH
97
98 MODCONF=$LDAPDIR/modules.conf
99 rm -f $MODCONF
100 touch $MODCONF
101
102 slaptest -u -f $SLAPD_CONF >&2 || {
103     echo "enabling slapd modules" >&2
104     cat > $MODCONF <<EOF 
105 modulepath      /usr/lib/ldap
106 moduleload      back_bdb
107 EOF
108 }
109
110 if slaptest -u -f $SLAPD_CONF; then
111     slapadd -f $SLAPD_CONF < $PRIVATEDIR/$DNSNAME.ldif >/dev/null || {
112         echo "slapadd failed" >&2
113     }
114
115     slaptest -f $SLAPD_CONF >/dev/null || {
116         echo "slaptest after database load failed" >&2
117     }
118 fi
119     
120 PATH=$OLDPATH
121 export PATH
122