1 diff --git a/CHANGELOG b/CHANGELOG
2 index 92013ce..c36017a 100644
6 - fix "nosymlink" option handling and add desription to man page.
7 - fix don't fail on empty master map.
8 - if there's no "automount" entry in nsswitch.conf use "files" source.
9 +- add LDAP schema discovery if no schema is configured.
11 18/06/2007 autofs-5.0.2
12 -----------------------
13 diff --git a/include/defaults.h b/include/defaults.h
14 index ef58467..9aec11a 100644
15 --- a/include/defaults.h
16 +++ b/include/defaults.h
17 @@ -43,11 +43,8 @@ unsigned int defaults_get_timeout(void);
18 unsigned int defaults_get_browse_mode(void);
19 unsigned int defaults_get_logging(void);
20 const char *defaults_get_ldap_server(void);
21 -const char *defaults_get_map_obj_class(void);
22 -const char *defaults_get_entry_obj_class(void);
23 -const char *defaults_get_map_attr(void);
24 -const char *defaults_get_entry_attr(void);
25 -const char *defaults_get_value_attr(void);
26 +struct ldap_schema *defaults_get_default_schema(void);
27 +struct ldap_schema *defaults_get_schema(void);
28 unsigned int defaults_get_append_options(void);
29 const char *defaults_get_auth_conf_file(void);
31 diff --git a/include/lookup_ldap.h b/include/lookup_ldap.h
32 index 0a9deca..1378b9e 100644
33 --- a/include/lookup_ldap.h
34 +++ b/include/lookup_ldap.h
47 struct lookup_context {
50 @@ -22,11 +30,7 @@ struct lookup_context {
53 /* LDAP lookup configuration */
54 - char *map_obj_class;
55 - char *entry_obj_class;
59 + struct ldap_schema *schema;
61 /* TLS and SASL authentication information */
63 diff --git a/lib/defaults.c b/lib/defaults.c
64 index 4b4acba..b146f13 100644
71 +#include "lookup_ldap.h"
74 #define DEFAULTS_CONFIG_FILE AUTOFS_CONF_DIR "/autofs"
76 #define ENV_AUTH_CONF_FILE "AUTH_CONF_FILE"
78 static const char *default_master_map_name = DEFAULT_MASTER_MAP_NAME;
80 -static const char *default_ldap_server = DEFAULT_LDAP_SERVER;
82 -static const char *default_map_obj_class = DEFAULT_MAP_OBJ_CLASS;
83 -static const char *default_entry_obj_class = DEFAULT_ENTRY_OBJ_CLASS;
84 -static const char *default_map_attr = DEFAULT_MAP_ATTR;
85 -static const char *default_entry_attr = DEFAULT_ENTRY_ATTR;
86 -static const char *default_value_attr = DEFAULT_VALUE_ATTR;
88 -static const char *default_auth_conf_file = DEFAULT_AUTH_CONF_FILE;
89 +static const char *default_ldap_server = DEFAULT_LDAP_SERVER;
90 +static const char *default_auth_conf_file = DEFAULT_AUTH_CONF_FILE;
92 static char *get_env_string(const char *name)
94 @@ -285,59 +278,120 @@ const char *defaults_get_ldap_server(void)
95 return (const char *) server;
98 -const char *defaults_get_map_obj_class(void)
99 +struct ldap_schema *defaults_get_default_schema(void)
102 + struct ldap_schema *schema;
103 + char *mc, *ma, *ec, *ea, *va;
105 - moc = get_env_string(ENV_NAME_MAP_OBJ_CLASS);
107 - return strdup(default_map_obj_class);
108 + mc = strdup(DEFAULT_MAP_OBJ_CLASS);
112 - return (const char *) moc;
114 + ma = strdup(DEFAULT_MAP_ATTR);
120 -const char *defaults_get_entry_obj_class(void)
123 + ec = strdup(DEFAULT_ENTRY_OBJ_CLASS);
130 - eoc = get_env_string(ENV_NAME_ENTRY_OBJ_CLASS);
132 - return strdup(default_entry_obj_class);
133 + ea = strdup(DEFAULT_ENTRY_ATTR);
141 - return (const char *) eoc;
143 + va = strdup(DEFAULT_VALUE_ATTR);
152 -const char *defaults_get_map_attr(void)
155 + schema = malloc(sizeof(struct ldap_schema));
165 - ma = get_env_string(ENV_NAME_MAP_ATTR);
167 - return strdup(default_map_attr);
168 + schema->map_class = mc;
169 + schema->map_attr = ma;
170 + schema->entry_class = ec;
171 + schema->entry_attr = ea;
172 + schema->value_attr = va;
174 - return (const char *) ma;
178 -const char *defaults_get_entry_attr(void)
179 +struct ldap_schema *defaults_get_schema(void)
182 + struct ldap_schema *schema;
183 + char *mc, *ma, *ec, *ea, *va;
185 - ea = get_env_string(ENV_NAME_ENTRY_ATTR);
187 - return strdup(default_entry_attr);
188 + mc = get_env_string(ENV_NAME_MAP_OBJ_CLASS);
192 - return (const char *) ea;
194 + ma = get_env_string(ENV_NAME_MAP_ATTR);
200 -const char *defaults_get_value_attr(void)
203 + ec = get_env_string(ENV_NAME_ENTRY_OBJ_CLASS);
210 + ea = get_env_string(ENV_NAME_ENTRY_ATTR);
218 va = get_env_string(ENV_NAME_VALUE_ATTR);
220 - return strdup(default_value_attr);
229 + schema = malloc(sizeof(struct ldap_schema));
239 + schema->map_class = mc;
240 + schema->map_attr = ma;
241 + schema->entry_class = ec;
242 + schema->entry_attr = ea;
243 + schema->value_attr = va;
245 - return (const char *) va;
249 unsigned int defaults_get_append_options(void)
250 diff --git a/man/auto.master.5.in b/man/auto.master.5.in
251 index 69c796e..249c9a7 100644
252 --- a/man/auto.master.5.in
253 +++ b/man/auto.master.5.in
254 @@ -191,17 +191,25 @@ The old style
255 is also understood. Alternatively, the type can be obtained from the Name Service Switch
256 configuration, in which case the map name alone must be given.
258 -The default LDAP schema is the NIS schema described in RFC 2307.
259 -Entries in the nisMap schema are \fBnisObject\fP objects in
260 +If no schema is set in the autofs configuration then autofs will check
261 +each of the commonly used schema for a valid entry and if one is found
262 +it will used for subsequent lookups.
264 +There are three common schemas in use:
267 +Entries in the \fBnisMap\fP schema are \fBnisObject\fP objects in
268 the specified subtree, where the \fBcn\fP attribute is the key
269 (the wildcard key is "/"), and the \fBnisMapEntry\fP attribute
270 contains the information used by the automounter.
272 -Entries in the automountMap schema are \fBautomount\fP objects in
273 -the specified subtree, where the \fBcn\fP or \fBautomountKey\fP attribute
274 -(depending on local usage) is the key (the wildcard key is "/"), and the
275 -\fBautomountInformation\fP attribute contains the information used by the
279 +The \fBautomountMap\fP schema has two variations that differ in the attribute
280 +used for the map key. Entries in the automountMap schema are \fBautomount\fP
281 +objects in the specified subtree, where the \fBcn\fP or \fBautomountKey\fP
282 +attribute (depending on local usage) is the key (the wildcard key is "/"),
283 +and the \fBautomountInformation\fP attribute contains the information used
284 +by the automounter. Note that the \fBcn\fP attribute is case insensitive.
286 The object classes and attributes used for accessing automount maps in
287 LDAP can be changed by setting entries in the autofs configuration
288 @@ -209,61 +217,44 @@ located in
290 .BR @@autofsconfdir@@/autofs .
294 +If a schema is given in the configuration then all the schema configuration
295 +values must be set, any partial schema specification will be ignored.
297 The configuration settings available are:
299 -\fBMAP_OBJECT_CLASS\fP
300 -The map object class. Its Default value is "nisMap". In the
304 -schema this corresponds to the class
309 +The map object class. In the \fBnisMap\fP schema this corresponds to the class
310 +\fBnisMap\fP and in the \fBautomountMap\fP schema it corresponds to the class
313 .B ENTRY_OBJECT_CLASS
314 -The map entry object class. Its default value is \fBnisObject\fP.
315 -In the automountMap schema this corresponds to the class
319 +The map entry object class. In the \fBnisMap\fP schema this corresponds
320 +to the class \fBnisObject\fP and in the \fBautomountMap\fP schema it
321 +corresponds to the class \fBautomount\fP.
324 The attribute used to identify the name of the map to which this
325 -entry belongs. Its default value is
333 -schema this corresponds to the attributes \fBou\fP or
335 -.BR automountMapName .
337 +entry belongs. In the \fBnisMap\fP schema this corresponds to the attribute
338 +\fBnisMapName\fP and in the \fBautomountMap\fP schema it corresponds to the
339 +attribute \fBou\fP or \fBautomountMapName\fP.
342 -The attribute used to identify a map key. Its default value is
347 -schema this corresponds to the attribute
351 +The attribute used to identify a map key. In the \fBnisMap\fP schema this
352 +corresponds to the attribute \fBcn\fP and in the \fBautomountMap\fP schema
353 +it corresponds to the attribute \fBautomountKey\fP.
356 -The attribute used to identify the value of the map entry. Its default
361 -In the automountMap schema this corresponds to the attribute
363 -.BR automountInformation .
364 +The attribute used to identify the value of the map entry. In the \fBnisMap\fP
365 +schema this corresponds to the attribute \fBnisMapEntry\fP and in the \fBautomountMap\fP
366 +schema it corresponds to the attribute \fBautomountInformation\fP.
369 +It is essential that entries use class and attribute in a consistent
370 +manner for correct operation of autofs. For example mixing \fBcn\fP and
371 +\fBautomountKey\fP attributes in \fBautomount\fP schema map entries won't
373 .SH LDAP AUTHENTICATION, ENCRYPTED AND CERTIFIED CONNECTIONS
374 LDAP authenticated binds, TLS encrypted connections and certification
375 may be used by setting appropriate values in the autofs authentication
376 diff --git a/man/automount.8 b/man/automount.8
377 index fc1846a..da67a5c 100644
378 --- a/man/automount.8
379 +++ b/man/automount.8
380 @@ -102,6 +102,8 @@ started they will be recoverd unless they are no longer present in
381 the map in which case they need to umounted manually.
385 +.BR auto.master (5),
388 Don't know, I've fixed everything I know about.
389 diff --git a/modules/lookup_ldap.c b/modules/lookup_ldap.c
390 index a412797..d5e666b 100644
391 --- a/modules/lookup_ldap.c
392 +++ b/modules/lookup_ldap.c
395 int lookup_version = AUTOFS_LOOKUP_VERSION; /* Required by protocol */
397 +static struct ldap_schema common_schema[] = {
398 + {"nisMap", "nisMapName", "nisObject", "cn", "nisMapEntry"},
399 + {"automountMap", "ou", "automount", "cn", "automountInformation"},
400 + {"automountMap", "automountMapName", "automount", "automountKey", "automountInformation"},
402 +static unsigned int common_schema_count = sizeof(common_schema)/sizeof(struct ldap_schema);
404 int bind_ldap_anonymous(LDAP *ldap, struct lookup_context *ctxt)
407 @@ -738,54 +745,15 @@ done:
411 -static int get_default_schema(struct lookup_context *ctxt)
413 - ctxt->map_obj_class = (char *) defaults_get_map_obj_class();
414 - if (!ctxt->map_obj_class)
417 - ctxt->entry_obj_class = (char *) defaults_get_entry_obj_class();
418 - if (!ctxt->entry_obj_class)
421 - ctxt->map_attr = (char *) defaults_get_map_attr();
422 - if (!ctxt->map_attr)
425 - ctxt->entry_attr = (char *) defaults_get_entry_attr();
426 - if (!ctxt->entry_attr)
429 - ctxt->value_attr = (char *) defaults_get_value_attr();
430 - if (!ctxt->value_attr)
436 - free(ctxt->entry_attr);
438 - free(ctxt->map_attr);
440 - free(ctxt->entry_obj_class);
442 - free(ctxt->map_obj_class);
444 - ctxt->map_obj_class = NULL;
445 - ctxt->entry_obj_class = NULL;
446 - ctxt->map_attr = NULL;
447 - ctxt->entry_attr = NULL;
452 static void free_context(struct lookup_context *ctxt)
454 - if (ctxt->map_obj_class) {
455 - free(ctxt->map_obj_class);
456 - free(ctxt->entry_obj_class);
457 - free(ctxt->map_attr);
458 - free(ctxt->entry_attr);
459 + if (ctxt->schema) {
460 + free(ctxt->schema->map_class);
461 + free(ctxt->schema->map_attr);
462 + free(ctxt->schema->entry_class);
463 + free(ctxt->schema->entry_attr);
464 + free(ctxt->schema->value_attr);
465 + free(ctxt->schema);
468 free(ctxt->auth_conf);
469 @@ -808,19 +776,15 @@ static void free_context(struct lookup_context *ctxt)
473 -static int get_query_dn(LDAP *ldap, struct lookup_context *ctxt)
474 +static int get_query_dn(LDAP *ldap, struct lookup_context *ctxt, const char *class, const char *key)
476 char buf[PARSE_MAX_BUF];
478 LDAPMessage *result, *e;
484 - class = ctxt->map_obj_class;
485 - key = ctxt->map_attr;
487 attrs[0] = LDAP_NO_ATTRS;
490 @@ -890,6 +854,90 @@ static int get_query_dn(LDAP *ldap, struct lookup_context *ctxt)
494 +static struct ldap_schema *alloc_common_schema(struct ldap_schema *s)
496 + struct ldap_schema *schema;
497 + char *mc, *ma, *ec, *ea, *va;
499 + mc = strdup(s->map_class);
503 + ma = strdup(s->map_attr);
509 + ec = strdup(s->entry_class);
516 + ea = strdup(s->entry_attr);
524 + va = strdup(s->value_attr);
533 + schema = malloc(sizeof(struct ldap_schema));
543 + schema->map_class = mc;
544 + schema->map_attr = ma;
545 + schema->entry_class = ec;
546 + schema->entry_attr = ea;
547 + schema->value_attr = va;
552 +static int find_query_dn(LDAP *ldap, struct lookup_context *ctxt)
554 + struct ldap_schema *schema;
560 + for (i = 0; i < common_schema_count; i++) {
561 + const char *class = common_schema[i].map_class;
562 + const char *key = common_schema[i].map_attr;
563 + if (get_query_dn(ldap, ctxt, class, key)) {
564 + schema = alloc_common_schema(&common_schema[i]);
567 + MODPREFIX "failed to allocate schema");
570 + ctxt->schema = schema;
579 * This initializes a context (persistent non-global data) for queries to
580 * this module. Return zero if we succeed.
581 @@ -926,13 +974,6 @@ int lookup_init(const char *mapfmt, int argc, const char *const *argv, void **co
585 - /* Get default schema for queries */
586 - if (!get_default_schema(ctxt)) {
587 - error(LOGOPT_ANY, MODPREFIX "cannot set default schema");
588 - free_context(ctxt);
594 * Determine which authentication mechanism to use. We sanity-
595 @@ -954,13 +995,22 @@ int lookup_init(const char *mapfmt, int argc, const char *const *argv, void **co
599 - ret = get_query_dn(ldap, ctxt);
600 - unbind_ldap_connection(ldap, ctxt);
602 - error(LOGOPT_ANY, MODPREFIX "failed to get query dn");
603 - free_context(ctxt);
606 + * Get default schema for queries.
607 + * If the schema isn't defined in the configuration then check for
608 + * presence of a map dn in the common schemas.
610 + ctxt->schema = defaults_get_schema();
611 + if (!ctxt->schema) {
612 + if (!find_query_dn(ldap, ctxt)) {
613 + unbind_ldap_connection(ldap, ctxt);
615 + MODPREFIX "failed to find valid query dn");
616 + free_context(ctxt);
620 + unbind_ldap_connection(ldap, ctxt);
622 /* Open the parser, if we can. */
623 ctxt->parse = open_parse(mapfmt, MODPREFIX, argc - 1, argv + 1);
624 @@ -990,9 +1040,9 @@ int lookup_read_master(struct master *master, time_t age, void *context)
625 int scope = LDAP_SCOPE_SUBTREE;
628 - class = ctxt->entry_obj_class;
629 - entry = ctxt->entry_attr;
630 - info = ctxt->value_attr;
631 + class = ctxt->schema->entry_class;
632 + entry = ctxt->schema->entry_attr;
633 + info = ctxt->schema->value_attr;
637 @@ -1141,9 +1191,9 @@ static int read_one_map(struct autofs_point *ap,
641 - class = ctxt->entry_obj_class;
642 - entry = ctxt->entry_attr;
643 - info = ctxt->value_attr;
644 + class = ctxt->schema->entry_class;
645 + entry = ctxt->schema->entry_attr;
646 + info = ctxt->schema->value_attr;
650 @@ -1438,9 +1488,9 @@ static int lookup_one(struct autofs_point *ap,
654 - class = ctxt->entry_obj_class;
655 - entry = ctxt->entry_attr;
656 - info = ctxt->value_attr;
657 + class = ctxt->schema->entry_class;
658 + entry = ctxt->schema->entry_attr;
659 + info = ctxt->schema->value_attr;