1 diff -uNr autofs-3.1.4/Makefile.conf.in autofs-3.1.4-ldap/Makefile.conf.in
2 --- autofs-3.1.4/Makefile.conf.in Tue Apr 11 14:18:08 2000
3 +++ autofs-3.1.4-ldap/Makefile.conf.in Tue Apr 11 14:17:49 2000
5 LIBHESIOD = @LIBHESIOD@
6 HESIOD_FLAGS = @HESIOD_FLAGS@
8 +# LDAP support: yes (1) no (0)
10 +LDAP_FLAGS = @LDAP_FLAGS@
11 +LDAP_LIBS= @LDAP_LIBS@
13 # NIS+ support: yes (1) no (0)
14 NISPLUS = @HAVE_NISPLUS@
16 diff -uNr autofs-3.1.4/configure.in autofs-3.1.4-ldap/configure.in
17 --- autofs-3.1.4/configure.in Tue Apr 11 14:18:08 2000
18 +++ autofs-3.1.4-ldap/configure.in Tue Apr 11 14:17:49 2000
20 AC_CHECK_HEADER(rpcsvc/nis.h, HAVE_NISPLUS=1)
21 AC_SUBST(HAVE_NISPLUS)
23 +AC_ARG_WITH(openldap,
24 +--with-openldap=DIR enable LDAP map support (OpenLDAP libs and includes in DIR),
25 + CFLAGS="$CFLAGS -I$withval/include"
26 + CPPLAGS="$CPPFLAGS -I$withval/include"
27 + AC_CHECK_HEADER(ldap.h)
28 + AC_CHECK_LIB(ldap, ldap_init,
30 + LDAP_LIBS="-L$withval/lib -lldap -llber",,
31 + -L$withval/lib -llber)
38 # Location of init.d directory?
40 diff -uNr autofs-3.1.4/man/auto.master.5 autofs-3.1.4-ldap/man/auto.master.5
41 --- autofs-3.1.4/man/auto.master.5 Tue Apr 11 14:18:08 2000
42 +++ autofs-3.1.4-ldap/man/auto.master.5 Tue Apr 11 14:21:11 2000
46 -.TH AUTO.MASTER 5 "9 Sep 1997"
47 +.TH AUTO.MASTER 5 "11 Apr 2000"
49 /etc/auto.master \- Master Map for automounter
55 +/auto ldap:ldapserver:ou=automount,ou=services,dc=example,dc=com
59 -This will generate three mountpoints
60 +This will generate four mountpoints
69 will lead to the consultation of the map in
72 will consult the map in
77 will consult the NIS map
82 +will access the \fIautomount\fP objects in \fIldapserver\fP's subtree under
83 +.IR ou=automount,ou=services,dc=example,dc=com .
87 diff -uNr autofs-3.1.4/man/automount.8 autofs-3.1.4-ldap/man/automount.8
88 --- autofs-3.1.4/man/automount.8 Fri Jan 21 14:08:09 2000
89 +++ autofs-3.1.4-ldap/man/automount.8 Tue Apr 11 14:17:50 2000
91 The map is a hesiod database whose
93 entries are used for maps.
96 +map names are of the form \fB[servername:]basedn\fP, where the optional
97 +\fBservername\fP is the name of the LDAP server to query, and \fBbasedn\fP is
98 +the DN to do a subtree search under. Entries are \fBautomount\fP objects in
99 +the specified subtree, where the \fBcn\fP attribute is the key (the wildcard
100 +key is "/"), and the \fBautomounterInformation\fP attribute contains the
101 +information used by the automounter. Documentation on the schema
102 +used by this module is available online at
103 +http://docs.iplanet.com/docs/manuals/directory/411ext/nis/mapping.htm
106 \fBformat\fP Format of the map data; currently the only formats
107 diff -uNr autofs-3.1.4/modules/Makefile autofs-3.1.4-ldap/modules/Makefile
108 --- autofs-3.1.4/modules/Makefile Tue Apr 11 14:18:08 2000
109 +++ autofs-3.1.4-ldap/modules/Makefile Tue Apr 11 14:17:50 2000
111 MODS += lookup_nisplus.so
115 + SRCS += lookup_ldap.c
116 + MODS += lookup_ldap.so
119 CFLAGS += -I../include -fpic -DAUTOFS_LIB_DIR=\"$(autofslibdir)\" -DPATH_AUTOMOUNT=\"$(sbindir)/automount\"
123 $(CC) $(SOLDFLAGS) $(CFLAGS) $(HESIOD_FLAGS) -o lookup_hesiod.so \
124 lookup_hesiod.c $(LIBHESIOD) $(LIBRESOLV)
125 $(STRIP) lookup_hesiod.so
127 +lookup_ldap.so: lookup_ldap.c
128 + $(CC) $(SOLDFLAGS) $(CFLAGS) $(LDAP_FLAGS) -o lookup_ldap.so \
129 + lookup_ldap.c $(LDAP_LIBS)
130 + $(STRIP) lookup_ldap.so
131 diff -uNr autofs-3.1.4/modules/lookup_ldap.c autofs-3.1.4-ldap/modules/lookup_ldap.c
132 --- autofs-3.1.4/modules/lookup_ldap.c Wed Dec 31 19:00:00 1969
133 +++ autofs-3.1.4-ldap/modules/lookup_ldap.c Tue Apr 11 14:28:51 2000
138 + * Module for Linux automountd to access automount maps in LDAP directories.
142 +#include <sys/types.h>
148 +#include <netinet/in.h>
149 +#include <arpa/nameser.h>
154 +#define MODULE_LOOKUP
155 +#include "automount.h"
157 +#define MAPFMT_DEFAULT "sun"
159 +#define MODPREFIX "lookup(ldap): "
161 +#define OBJECTCLASS "automount"
162 +#define ATTRIBUTE "automountInformation"
163 +#define WILDCARD "/"
165 +struct lookup_context {
166 + char *server, *base;
167 + struct parse_mod *parser;
170 +int lookup_version = AUTOFS_LOOKUP_VERSION; /* Required by protocol */
173 + * This initializes a context (persistent non-global data) for queries to
174 + * this module. Return zero if we succeed.
176 +int lookup_init(const char *mapfmt, int argc, const char * const *argv,
179 + struct lookup_context *ctxt = NULL;
183 + /* If we can't build a context, bail. */
184 + ctxt = (struct lookup_context*) malloc(sizeof(struct lookup_context));
186 + if( ctxt == NULL ) {
187 + syslog(LOG_INFO, MODPREFIX "malloc: %m");
190 + memset(ctxt, 0, sizeof(struct lookup_context));
192 + /* If a map type isn't explicitly given, parse it like sun entries. */
193 + if( mapfmt == NULL ) {
194 + mapfmt = MAPFMT_DEFAULT;
197 + /* Now we sanity-check by binding to the server temporarily. We have to be
198 + * a little strange in here, because we want to provide for use of the
199 + * "default" server, which is set in an ldap.conf file somewhere. */
200 + if(strchr(argv[0], ':') != NULL) {
201 + l = strchr(argv[0], ':') - argv[0];
202 + /* Isolate the server's name. */
203 + ctxt->server = malloc(l + 1);
204 + memset(ctxt->server, 0, l + 1);
205 + memcpy(ctxt->server, argv[0], l);
206 + /* Isolate the base DN. */
207 + ctxt->base = malloc(strlen(argv[0]) - l);
208 + memset(ctxt->base, 0, strlen(argv[0]) - l);
209 + memcpy(ctxt->base, argv[0] + l + 1, strlen(argv[0]) - l - 1);
211 + /* Use the default server; isolate the base DN's name. */
212 + l = strlen(argv[0]);
213 + ctxt->server = NULL;
214 + ctxt->base = malloc(l + 1);
215 + memset(ctxt->base, 0, l + 1);
216 + memcpy(ctxt->base, argv[0], l);
219 + syslog(LOG_DEBUG, MODPREFIX "server = \"%s\", base dn = \"%s\"",
220 + ctxt->server ? ctxt->server : "(default)", ctxt->base);
222 + /* Initialize the LDAP context. */
223 + if( ( ldap = ldap_init(ctxt->server, LDAP_PORT)) == NULL ) {
224 + syslog(LOG_CRIT, MODPREFIX "couldn't initialize LDAP");
228 + /* Connect to the server as an anonymous user. */
229 + rv = ldap_simple_bind_s(ldap, ctxt->base, NULL);
230 + if( rv != LDAP_SUCCESS ) {
231 + syslog(LOG_CRIT, MODPREFIX "couldn't connect to %s", ctxt->server);
235 + /* Okay, we're done here. */
238 + /* Open the parser, if we can. */
239 + return !(ctxt->parser = open_parse(mapfmt, MODPREFIX, argc - 1, argv + 1));
242 +/* Lookup by key and pass a filesystem to a parser. */
243 +int lookup_mount(const char *root, const char *name, int name_len, void *context)
245 + struct lookup_context *ctxt = (struct lookup_context *) context;
248 + LDAPMessage *result, *e;
250 + char *attrs[] = {ATTRIBUTE, NULL};
253 + chdir("/"); /* If this is not here the filesystem stays
254 + busy, for some reason... */
256 + if( ctxt == NULL ) {
257 + syslog(LOG_CRIT, MODPREFIX "context was NULL");
261 + /* Build a query string. */
262 + l = name_len + strlen("(&(objectclass=" OBJECTCLASS ")(cn=))") + 2;
265 + if( query == NULL ) {
266 + syslog(LOG_INFO, MODPREFIX "malloc: %m");
270 + memset(query, '\0', l);
271 + if( sprintf(query, "(&(objectclass=" OBJECTCLASS ")(cn=%s))", name) >= l ) {
272 + syslog(LOG_DEBUG, MODPREFIX "error forming query string");
274 + query[l - 1] = '\0';
276 + /* Initialize the LDAP context. */
277 + if( (ldap = ldap_init(ctxt->server, LDAP_PORT) ) == NULL ) {
278 + syslog(LOG_CRIT, MODPREFIX "couldn't initialize LDAP connection"
279 + " to %s", ctxt->server ? ctxt->server : "default server");
284 + /* Connect to the server as an anonymous user. */
285 + rv = ldap_simple_bind_s(ldap, ctxt->base, NULL);
286 + if ( rv != LDAP_SUCCESS ) {
287 + syslog(LOG_CRIT, MODPREFIX "couldn't bind to %s",
288 + ctxt->server ? ctxt->server : "default server");
294 + syslog(LOG_DEBUG, MODPREFIX "searching for \"%s\"", query);
295 + rv = ldap_search_s(ldap, ctxt->base, LDAP_SCOPE_SUBTREE,
296 + query, attrs, 0, &result);
298 + if( ( rv != LDAP_SUCCESS) || ( result == NULL ) ) {
299 + syslog(LOG_INFO, MODPREFIX "query failed for %s", query);
304 + e = ldap_first_entry(ldap, result);
306 + /* If we got no answers, try it with "/" instead, which makes a better
307 + * wildcard thatn "*" for LDAP, and also happens to be illegal for actual
308 + * directory names. */
310 + syslog(LOG_DEBUG, MODPREFIX "no entry for \"%s\" found, trying cn=\"/\"",
313 + sprintf(query, "(&(objectclass=" OBJECTCLASS ")(cn=" WILDCARD "))");
315 + syslog(LOG_DEBUG, MODPREFIX "searching for \"%s\"", query);
316 + rv = ldap_search_s(ldap, ctxt->base, LDAP_SCOPE_SUBTREE,
317 + query, attrs, 0, &result);
318 + if( ( rv != LDAP_SUCCESS) || ( result == NULL ) ) {
319 + syslog(LOG_INFO, MODPREFIX "query failed for %s", query);
324 + syslog(LOG_DEBUG, MODPREFIX "getting first entry for cn=\"/\"");
326 + e = ldap_first_entry(ldap, result);
330 + syslog(LOG_INFO, MODPREFIX "got answer, but no first entry for %s", query);
334 + syslog(LOG_DEBUG, MODPREFIX "examining first entry");
337 + values = ldap_get_values(ldap, e, ATTRIBUTE);
338 + if( values == NULL ) {
339 + syslog(LOG_INFO, MODPREFIX "no " ATTRIBUTE " defined for %s", query);
344 + /* Try each of the answers in sucession. */
346 + for( i = 0 ; ( values[i] != NULL ) && ( rv != 0 ) ; i++ ) {
347 + rv = ctxt->parser->parse_mount(root, name, name_len, values[0],
348 + ctxt->parser->context);
352 + ldap_value_free(values);
353 + ldap_msgfree(result);
361 + * This destroys a context for queries to this module. It releases the parser
362 + * structure (unloading the module) and frees the memory used by the context.
364 +int lookup_done(void *context)
366 + struct lookup_context *ctxt = (struct lookup_context *) context;
367 + int rv = close_parse(ctxt->parser);
368 + free(ctxt->server);