Taken from http://www.ccm.ece.vt.edu/~lscharf/samd/?topic=Linux&title=Linux+autofs+with+LDAP : Linux autofs with LDAP Keywords: Date Created: 2002-05-17 Author: Luke Scharf Problem: The Linux automounter (autofs) will not bind to an LDAP server that requires the client to authenticate. Autofs is only able to get automount information from an LDAP server that will allow anyone-in-the-world to bind to it. I verified this by reading lookup_ldap.c from the autofs-3.1.7 source code. Solution: Autofs conveniently allows you to generate your mapping with an external program. This program takes a username as a command-line parameter and writes the location to standard output. There is also the ldapsearch command line tool, which will authenticate (properly) to an ldap server and search for arbitrary information. I put these pieces together with a perl script. In addition to actually authenticating with the LDAP server before attempting a query, this script reads the settings from the global LDAP settings. Here's the script: #!/usr/bin/perl -w # # Name: auto.home_ldap # # Purpose: To retrieve automount information from an LDAP server that # refuses anonymous binding. The existing Linux automount client (as of # RedHat 7.3) can only retrieve automount information if anonymous # binding is allowed. Since I don't want to hand out user information # to just anyone, a password is required to connect to the server. # # Author: Luke Scharf (luke@vt.edu) May, 2002 # # License: GNU General Public License (http://www.gnu.org) # ##### Includes ##### use strict; ##### Constants ##### my $scope = "subtree"; my $fields = "automountInformation"; ##### Variables ##### my $host; my $binddn; my $bindpw; my $base; my $ssl; my $username; my $query; ##### Get Parameters ##### # Parse command line my $ARGC = @ARGV; if ($ARGC < 1) { exit 0; } # Abort if no commands were given $username = $ARGV[0]; # What user's home directory are we looking for? # Read system-wide ldap configuration file(s) open(CONFIG, "< /etc/ldap.conf"); while() { # Tokenize the line @_ = split(); # Do not process blank or bogus lines if ( not $_[0] ) { next; } # Store parameters from the config file if ( $_[0] =~ /^host$/ ) { $host = $_[1]; } if ( $_[0] =~ /^binddn$/ ) { $binddn= $_[1]; } if ( $_[0] =~ /^bindpw$/ ) { $bindpw= $_[1]; } if ( $_[0] =~ /^base$/ ) { $base= $_[1]; } if ( $_[0] =~ /^ssl$/ ) { $ssl = $_[1]; } } ##### Communicate With LDAP Server ##### # Compose the query $query = "(&(objectClass=automount)(cn=$username))"; # Glob together a command line with all of the search parameters my $ldapcommand; $ldapcommand = "ldapsearch -LLL"; $ldapcommand .= " -h $host"; $ldapcommand .= " -D $binddn"; if ($ssl=~/no/) { $ldapcommand .= " -x"; } $ldapcommand .= " -w \"$bindpw\""; $ldapcommand .= " -b $base"; $ldapcommand .= " -s $scope"; $ldapcommand .= " \'$query\'"; $ldapcommand .= " $fields"; # Open a pipe to ldapsearch open(LDAP, "$ldapcommand |"); # Output in an automounter-friendly manner my $user; my $home; while( my $line = ) { chomp $line; if ($line =~ /^automountInformation\:/) { $home = $line; $home =~ s|^automountInformation\: ||g; print "$home\n"; } } This script is then referenced by an entry in /etc/auto.master that looks like this: /home program:/etc/auto.home_ldap.pl Despite the fact that this script necessitates two forks for every search, the speed is quite good. My guestimate is that the NFS-mount takes most of the time when you reference a file in an unmounted home directory.