(Answer) (Category) OpenLDAP Faq-O-Matic : (Category) OpenLDAP Software FAQ : (Category) Integration : (Answer) How to use AutoFS with OpenLDAP?
Current versions of autofs does not use the schema defined in RFC2307
(patches exist at http://people.redhat.com/nalin/autofs/), but the
schema defined below.

# Depends upon core.schema and cosine.schema

# OID Base is
# Attribute types are under
# Object classes are under
# Syntaxes are under

# Attribute Type Definitions

attributetype ( NAME 'automountInformation'
        DESC 'Information used by the autofs automounter'
        EQUALITY caseExactIA5Match

objectclass ( NAME 'automount' SUP top STRUCTURAL
        DESC 'An entry in an automounter map'
        MUST ( cn $ automountInformation $ objectclass )
        MAY ( description ) )

objectclass ( NAME 'automountMap' SUP top STRUCTURAL
        DESC 'An group of related automount objects'
        MUST ( ou ) )

The following example has been tested with autofs 4.0:

dn: ou=auto.master, dc=example, dc=com
objectClass: top
objectClass: automountMap
ou: auto.master

dn: cn=/home, ou=auto.master, dc=example, dc=com
objectClass: automount
cn: /home
automountInformation: ldap ldapserver.example.com:ou=auto.home,dc=example,dc=com

dn: ou=auto.home, dc=example, dc=com
objectClass: top
objectClass: automountMap
ou: auto.home

dn: cn=user1, ou=auto.home, dc=example, dc=com
objectClass: automount
cn: user1
automountInformation: -fstype=nfs,hard,intr,nodev,nosuid nfsserver.example.com:/home/user1

dn: cn=user2, ou=auto.home, dc=example, dc=com
objectClass: automount
cn: user2
automountInformation: -fstype=nfs,hard,intr,nodev,nosuid nfsserver.example.com:/home/user2

You will probably have to edit the init script if you wan't auto.master in LDAP.
Add something like (to the function getmounts):

# check for LDAP maps to be loaded
if [ -x /usr/bin/ldapsearch ]
        ldapsearch -x "(&(ou=auto.master)(objectclass=automountmap))" "dn" | \
        grep "dn:.*ou=auto.master" > /dev/null 2>&1;
        ldapbase=`ldapsearch -x "(&(ou=auto.master)(objectclass=automountmap))" "ou" \
                | grep "^dn:" | sed 's/^dn: ou=auto.master,\(.*\)/\1/' \
                | sed 's/ //g'`
        ldapsearch -u -x -b "ou=auto.master,$ldapbase"  \
                "(&(objectclass=automount)(cn=*))" -s one \
                | grep "^cn" \
                | sed 's/cn: \(.*\)/\1/' | (
                while read dir ; do
                        echo "/usr/sbin/automount $dir ldap $ldapbase"
The previous information doesn't work with the new 'nisObject' schema objects; 

You can check if your are using the new objects running the following (to get the contents of ytour auto.master map directly from LDAP):

ldapsearch -x -LLL -b "nisMapName=auto.master,dc=XXX,dc=com" "cn" "nisMapEntry" -s sub|grep -v dn 

This returns:

cn: /home
nisMapEntry: auto.home

cn: /nb_apps
nisMapEntry: auto.nb_apps

cn: /data
nisMapEntry: auto.data

Then, the idea is to make the autofs script to generate the proper auto.master entry without needing to edit this file on every single machine. The required format is something like:

[josevnz@linux0037 bash]$ /etc/init.d/autofs status
Configured Mount Points:
/usr/sbin/automount /home ldap SERVER.dev01.XXX.com:nisMapName=auto.home,dc=XXX,dc=com  rsize=8192,wsize=8192
/usr/sbin/automount /nb_apps ldap SERVER.dev01.XXX.com:nisMapName=auto.nb_apps,dc=XXX,dc=com  rsize=8192,wsize=8192
/usr/sbin/automount /data ldap SERVER.dev01.XXX.com:nisMapName=auto.data,dc=XXX,dc=com  rsize=8192,wsize=8192

One way of doing it is to modify the /etc/init.d/autofs script (Redhat 7.xx, 8.xx) like this:

# Construct the LDAP mount points properly
# josevnz at newbreak dot com
function getldapmounts()
    #/usr/lib/autofs/autofs-ldap-auto-master 2> /dev/null

    # Get the LDAP server from the 'ldap.conf'.
    LDAP_SERVER=`cat /etc/openldap/ldap.conf | grep -v '#'| grep HOST| sed -e's/HOST //'`
    # Get the default base
    LDAP_BASE=` cat /etc/openldap/ldap.conf | grep -v '#'| grep BASE| sed -e's/BASE //'`

    #/usr/lib/autofs/autofs-ldap-auto-master 2> /dev/null
    /usr/lib/autofs/autofs-ldap-auto-master|sed -e"s/[a-zA-Z0-9]*\..*/ ldap\:$LDAP_SERVER\:nisMapName=&,$LDAP_BASE/"

By the time of this writting, this is a known bug and has the following Redhat bugzilla case numbers:

#65212 (https://bugzilla.redhat.com/bugzilla/show_bug.cgi?id=65212)
#73123 (https://bugzilla.redhat.com/bugzilla/show_bug.cgi?id=73123)

You can check all the autofs bugs for Redhat here:
For Rehdat Linux 9 I changed in /etc/init.d/autofs file, readhat() funcation like this.

 getmounts | sed 's/yp//' | tee $TMP | sh

Now it started working.

my /etc/nsswitch.conf file looks like this.

#grep automount /etc/nsswitch.conf
automount:   ldap
[Append to This Answer]
Previous: (Answer) How to use LDAP authentication with Squid?
Next: (Answer) How do I use LDAP in/with Linux?
This document is: http://www.openldap.org/faq/index.cgi?file=599
[Search] [Appearance]
This is a Faq-O-Matic 2.721.test.
© Copyright 1998-2013, OpenLDAP Foundation, info@OpenLDAP.org