pastebin - collaborative debugging tool
kpaste.net RSS


Script to auto config openldap on lucid
Posted by Anonymous on Sun 2nd May 2010 19:19
raw | new post

  1. #!/bin/bash
  2. # Script to auto install/configure OpenLDAP on Ubuntu 10.04
  3. #
  4. #    Author: TorrentialStorm
  5.  
  6. if [ "$(id -ru)" != "0" ]; then
  7.         echo "This script must be run as root."
  8.         exit
  9. fi
  10.  
  11. apt-get install slapd
  12. rm -rf /var/lib/ldap/* /etc/slapd.d
  13. dpkg-reconfigure slapd
  14.  
  15.  
  16. TMPFILE=$(tempfile)
  17.  
  18. DOMAIN=
  19. while [ -z "$DOMAIN" ]; do
  20.         whiptail --nocancel --inputbox "Domain Name:" 10 50 "example.org" 2> "${TMPFILE}"
  21.         DOMAIN=$(cat ${TMPFILE})
  22.         TOPDOM=$(echo "${DOMAIN}" | cut -d. -f1)
  23.         DOM=${DOMAIN}
  24.         DOMAIN=$(echo "${DOMAIN}" | sed 's/\./,dc=/g')
  25. done
  26.  
  27. PASSWORD=
  28. while [ -z "$PASSWORD" ]; do
  29.         whiptail --nocancel --passwordbox "Admin Password:" 10 50 2> "${TMPFILE}"      
  30.         PASSWORD=$(cat ${TMPFILE})
  31. done
  32.  
  33.  
  34. ldapadd -Y EXTERNAL -H ldapi:/// -f /etc/ldap/schema/cosine.ldif
  35. ldapadd -Y EXTERNAL -H ldapi:/// -f /etc/ldap/schema/nis.ldif
  36. ldapadd -Y EXTERNAL -H ldapi:/// -f /etc/ldap/schema/inetorgperson.ldif
  37. ldapadd -Y EXTERNAL -H ldapi:/// -f /etc/ldap/schema/misc.ldif
  38.  
  39.  
  40. ldapadd -Y EXTERNAL -H ldapi:/// <<EOF
  41. # Load hdb backend module
  42. dn: cn=module{0},cn=config
  43. objectClass: olcModuleList
  44. cn: module
  45. olcModulepath: /usr/lib/ldap
  46. olcModuleload: {0}back_hdb
  47.  
  48. # Create the hdb database and place the files under /var/lib/ldap
  49. dn: olcDatabase={1}hdb,cn=config
  50. objectClass: olcDatabaseConfig
  51. objectClass: olcHdbConfig
  52. olcDatabase: {1}hdb
  53. olcDbDirectory: /var/lib/ldap
  54. olcSuffix: dc=${DOMAIN}
  55. olcRootDN: cn=admin,dc=${DOMAIN}
  56. olcRootPW: ${PASSWORD}
  57. olcDbConfig: {0}set_cachesize 0 2097152 0
  58. olcDbConfig: {1}set_lk_max_objects 1500
  59. olcDbConfig: {2}set_lk_max_locks 1500
  60. olcDbConfig: {3}set_lk_max_lockers 1500
  61. olcLastMod: TRUE
  62. olcDbCheckpoint: 512 30
  63. olcDbIndex: uid pres,eq
  64. olcDbIndex: cn,sn,mail pres,eq,approx,sub
  65. olcDbIndex: objectClass eq
  66. EOF
  67.  
  68.  
  69. ldapadd -Y EXTERNAL -H ldapi:/// <<EOF
  70. dn: dc=$DOMAIN
  71. objectClass: dcObject
  72. objectclass: organization
  73. o: $DOM
  74. dc: $TOPDOM
  75. description: LDAP root
  76.  
  77. dn: ou=People, dc=$DOMAIN
  78. ou: People
  79. objectclass: organizationalUnit
  80.  
  81. dn: ou=Group, dc=$DOMAIN
  82. ou: Group
  83. objectclass: organizationalUnit
  84. EOF
  85.  
  86. ldapmodify -Y EXTERNAL -H ldapi:/// <<EOF
  87. dn: olcDatabase={1}hdb,cn=config
  88. add: olcAccess
  89. olcAccess: {0}to attrs=userPassword,shadowLastChange by dn="cn=admin,dc=$DOMAIN" write by anonymous auth by self write by * none
  90. olcAccess: {1}to dn.subtree="" by * read
  91. olcAccess: {2}to * by dn="cn=admin,dc=$DOMAIN" write by * read
  92. EOF
  93.  
  94. rm ${TMPFILE}

Submit a correction or amendment below (click here to make a fresh posting)
After submitting an amendment, you'll be able to view the differences between the old and new posts easily.

Syntax highlighting:

To highlight particular lines, prefix each line with {%HIGHLIGHT}




All content is user-submitted.
The administrators of this site (kpaste.net) are not responsible for their content.
Abuse reports should be emailed to us at