summaryrefslogtreecommitdiffstats
path: root/bin/gen-ldif
blob: 803ece951f549713a443082fea9e933bf3665e30 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#!/bin/bash

[ ! -z "$2" ] && domain=$2 || domain="example.org"
[ ! -z "$3" ] && rootdn=$3 || rootdn="dc=example,dc=org"
[ ! -z "$4" ] && ou=$4 || ou="ou=People"

echo "dn: ${ou},${rootdn}"
echo "objectClass: top"
echo "objectClass: organizationalunit"
echo "$(echo ${ou} | cut -d'=' -f 1): $(echo ${ou} | cut -d'=' -f 2)"
echo 'aci: (targetattr ="userpassword || telephonenumber || facsimiletelephonenumber")(version 3.0; acl "Allow self entry modification"; allow (write)(userdn = "ldap:///self");)'
echo ""

i=0
while [ $i -lt 0$1 ]; do

    givenname=`head -c 200 /dev/urandom | tr -dc A-Za-z | head -c5`
    surname=`head -c 200 /dev/urandom | tr -dc A-Za-z | head -c10`

    givenname="$(echo ${givenname:0:1} | tr '[:lower:]' '[:upper:]')$(echo ${givenname:1} | tr '[:upper:]' '[:lower:]')"
    givenname_lower="$(echo ${givenname} | tr '[:upper:]' '[:lower:]')"
    surname="$(echo ${surname:0:1} | tr '[:lower:]' '[:upper:]')$(echo ${surname:1} | tr '[:upper:]' '[:lower:]')"
    surname_lower="$(echo ${surname} | tr '[:upper:]' '[:lower:]')"

    uid="$(echo ${givenname:0:1}.${surname} | tr '[:upper:]' '[:lower:]')"

    userpassword="VerySecret"

    echo "dn: uid=$uid,${ou},${rootdn}"
    echo "uid: $uid"
    echo "givenName: $givenname"
    echo "objectClass: top"
    echo "objectClass: person"
    echo "objectClass: inetOrgPerson"
    echo "objectClass: organizationalPerson"
    echo "objectClass: mailrecipient"
    echo "sn: $surname"
    echo "cn: $givenname $surname"
    echo "mail: ${givenname_lower}.${surname_lower}@${domain}"
    echo "userPassword: {SSHA}zJ3oU5kqtS3MxnLWmKpnE7+eGVbmQKmj"
    echo ""

    let i++
done