- fix LDAP schema discovery.
This commit is contained in:
parent
14c99defc6
commit
2c0907556a
@ -1,25 +1,6 @@
|
|||||||
diff --git a/include/defaults.h b/include/defaults.h
|
diff -up autofs-5.0.2/include/lookup_ldap.h.add-ldap-schema-discovery autofs-5.0.2/include/lookup_ldap.h
|
||||||
index ef58467..9aec11a 100644
|
--- autofs-5.0.2/include/lookup_ldap.h.add-ldap-schema-discovery 2007-09-05 12:52:35.000000000 +0800
|
||||||
--- a/include/defaults.h
|
+++ autofs-5.0.2/include/lookup_ldap.h 2007-09-05 12:52:35.000000000 +0800
|
||||||
+++ b/include/defaults.h
|
|
||||||
@@ -43,11 +43,8 @@ unsigned int defaults_get_timeout(void);
|
|
||||||
unsigned int defaults_get_browse_mode(void);
|
|
||||||
unsigned int defaults_get_logging(void);
|
|
||||||
const char *defaults_get_ldap_server(void);
|
|
||||||
-const char *defaults_get_map_obj_class(void);
|
|
||||||
-const char *defaults_get_entry_obj_class(void);
|
|
||||||
-const char *defaults_get_map_attr(void);
|
|
||||||
-const char *defaults_get_entry_attr(void);
|
|
||||||
-const char *defaults_get_value_attr(void);
|
|
||||||
+struct ldap_schema *defaults_get_default_schema(void);
|
|
||||||
+struct ldap_schema *defaults_get_schema(void);
|
|
||||||
unsigned int defaults_get_append_options(void);
|
|
||||||
const char *defaults_get_auth_conf_file(void);
|
|
||||||
|
|
||||||
diff --git a/include/lookup_ldap.h b/include/lookup_ldap.h
|
|
||||||
index 0a9deca..1378b9e 100644
|
|
||||||
--- a/include/lookup_ldap.h
|
|
||||||
+++ b/include/lookup_ldap.h
|
|
||||||
@@ -10,6 +10,14 @@
|
@@ -10,6 +10,14 @@
|
||||||
#include <krb5.h>
|
#include <krb5.h>
|
||||||
#endif
|
#endif
|
||||||
@ -48,10 +29,308 @@ index 0a9deca..1378b9e 100644
|
|||||||
|
|
||||||
/* TLS and SASL authentication information */
|
/* TLS and SASL authentication information */
|
||||||
char *auth_conf;
|
char *auth_conf;
|
||||||
diff --git a/lib/defaults.c b/lib/defaults.c
|
diff -up autofs-5.0.2/include/defaults.h.add-ldap-schema-discovery autofs-5.0.2/include/defaults.h
|
||||||
index 4b4acba..b146f13 100644
|
--- autofs-5.0.2/include/defaults.h.add-ldap-schema-discovery 2007-06-18 15:18:08.000000000 +0800
|
||||||
--- a/lib/defaults.c
|
+++ autofs-5.0.2/include/defaults.h 2007-09-05 12:52:35.000000000 +0800
|
||||||
+++ b/lib/defaults.c
|
@@ -43,11 +43,8 @@ unsigned int defaults_get_timeout(void);
|
||||||
|
unsigned int defaults_get_browse_mode(void);
|
||||||
|
unsigned int defaults_get_logging(void);
|
||||||
|
const char *defaults_get_ldap_server(void);
|
||||||
|
-const char *defaults_get_map_obj_class(void);
|
||||||
|
-const char *defaults_get_entry_obj_class(void);
|
||||||
|
-const char *defaults_get_map_attr(void);
|
||||||
|
-const char *defaults_get_entry_attr(void);
|
||||||
|
-const char *defaults_get_value_attr(void);
|
||||||
|
+struct ldap_schema *defaults_get_default_schema(void);
|
||||||
|
+struct ldap_schema *defaults_get_schema(void);
|
||||||
|
unsigned int defaults_get_append_options(void);
|
||||||
|
const char *defaults_get_auth_conf_file(void);
|
||||||
|
|
||||||
|
diff -up autofs-5.0.2/modules/lookup_ldap.c.add-ldap-schema-discovery autofs-5.0.2/modules/lookup_ldap.c
|
||||||
|
--- autofs-5.0.2/modules/lookup_ldap.c.add-ldap-schema-discovery 2007-09-05 12:52:35.000000000 +0800
|
||||||
|
+++ autofs-5.0.2/modules/lookup_ldap.c 2007-09-05 12:53:10.000000000 +0800
|
||||||
|
@@ -42,6 +42,13 @@
|
||||||
|
|
||||||
|
int lookup_version = AUTOFS_LOOKUP_VERSION; /* Required by protocol */
|
||||||
|
|
||||||
|
+static struct ldap_schema common_schema[] = {
|
||||||
|
+ {"nisMap", "nisMapName", "nisObject", "cn", "nisMapEntry"},
|
||||||
|
+ {"automountMap", "ou", "automount", "cn", "automountInformation"},
|
||||||
|
+ {"automountMap", "automountMapName", "automount", "automountKey", "automountInformation"},
|
||||||
|
+};
|
||||||
|
+static unsigned int common_schema_count = sizeof(common_schema)/sizeof(struct ldap_schema);
|
||||||
|
+
|
||||||
|
int bind_ldap_anonymous(LDAP *ldap, struct lookup_context *ctxt)
|
||||||
|
{
|
||||||
|
int rv;
|
||||||
|
@@ -738,54 +745,15 @@ done:
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
-static int get_default_schema(struct lookup_context *ctxt)
|
||||||
|
-{
|
||||||
|
- ctxt->map_obj_class = (char *) defaults_get_map_obj_class();
|
||||||
|
- if (!ctxt->map_obj_class)
|
||||||
|
- return 0;
|
||||||
|
-
|
||||||
|
- ctxt->entry_obj_class = (char *) defaults_get_entry_obj_class();
|
||||||
|
- if (!ctxt->entry_obj_class)
|
||||||
|
- goto free_moc;
|
||||||
|
-
|
||||||
|
- ctxt->map_attr = (char *) defaults_get_map_attr();
|
||||||
|
- if (!ctxt->map_attr)
|
||||||
|
- goto free_eoc;
|
||||||
|
-
|
||||||
|
- ctxt->entry_attr = (char *) defaults_get_entry_attr();
|
||||||
|
- if (!ctxt->entry_attr)
|
||||||
|
- goto free_ma;
|
||||||
|
-
|
||||||
|
- ctxt->value_attr = (char *) defaults_get_value_attr();
|
||||||
|
- if (!ctxt->value_attr)
|
||||||
|
- goto free_ea;
|
||||||
|
-
|
||||||
|
- return 1;
|
||||||
|
-
|
||||||
|
-free_ea:
|
||||||
|
- free(ctxt->entry_attr);
|
||||||
|
-free_ma:
|
||||||
|
- free(ctxt->map_attr);
|
||||||
|
-free_eoc:
|
||||||
|
- free(ctxt->entry_obj_class);
|
||||||
|
-free_moc:
|
||||||
|
- free(ctxt->map_obj_class);
|
||||||
|
-
|
||||||
|
- ctxt->map_obj_class = NULL;
|
||||||
|
- ctxt->entry_obj_class = NULL;
|
||||||
|
- ctxt->map_attr = NULL;
|
||||||
|
- ctxt->entry_attr = NULL;
|
||||||
|
-
|
||||||
|
- return 0;
|
||||||
|
-}
|
||||||
|
-
|
||||||
|
static void free_context(struct lookup_context *ctxt)
|
||||||
|
{
|
||||||
|
- if (ctxt->map_obj_class) {
|
||||||
|
- free(ctxt->map_obj_class);
|
||||||
|
- free(ctxt->entry_obj_class);
|
||||||
|
- free(ctxt->map_attr);
|
||||||
|
- free(ctxt->entry_attr);
|
||||||
|
+ if (ctxt->schema) {
|
||||||
|
+ free(ctxt->schema->map_class);
|
||||||
|
+ free(ctxt->schema->map_attr);
|
||||||
|
+ free(ctxt->schema->entry_class);
|
||||||
|
+ free(ctxt->schema->entry_attr);
|
||||||
|
+ free(ctxt->schema->value_attr);
|
||||||
|
+ free(ctxt->schema);
|
||||||
|
}
|
||||||
|
if (ctxt->auth_conf)
|
||||||
|
free(ctxt->auth_conf);
|
||||||
|
@@ -808,19 +776,15 @@ static void free_context(struct lookup_c
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
-static int get_query_dn(LDAP *ldap, struct lookup_context *ctxt)
|
||||||
|
+static int get_query_dn(LDAP *ldap, struct lookup_context *ctxt, const char *class, const char *key)
|
||||||
|
{
|
||||||
|
char buf[PARSE_MAX_BUF];
|
||||||
|
char *query, *dn;
|
||||||
|
LDAPMessage *result, *e;
|
||||||
|
- char *class, *key;
|
||||||
|
char *attrs[2];
|
||||||
|
int scope;
|
||||||
|
int rv, l;
|
||||||
|
|
||||||
|
- class = ctxt->map_obj_class;
|
||||||
|
- key = ctxt->map_attr;
|
||||||
|
-
|
||||||
|
attrs[0] = LDAP_NO_ATTRS;
|
||||||
|
attrs[1] = NULL;
|
||||||
|
|
||||||
|
@@ -890,6 +854,90 @@ static int get_query_dn(LDAP *ldap, stru
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
+static struct ldap_schema *alloc_common_schema(struct ldap_schema *s)
|
||||||
|
+{
|
||||||
|
+ struct ldap_schema *schema;
|
||||||
|
+ char *mc, *ma, *ec, *ea, *va;
|
||||||
|
+
|
||||||
|
+ mc = strdup(s->map_class);
|
||||||
|
+ if (!mc)
|
||||||
|
+ return NULL;
|
||||||
|
+
|
||||||
|
+ ma = strdup(s->map_attr);
|
||||||
|
+ if (!ma) {
|
||||||
|
+ free(mc);
|
||||||
|
+ return NULL;
|
||||||
|
+ }
|
||||||
|
+
|
||||||
|
+ ec = strdup(s->entry_class);
|
||||||
|
+ if (!ec) {
|
||||||
|
+ free(mc);
|
||||||
|
+ free(ma);
|
||||||
|
+ return NULL;
|
||||||
|
+ }
|
||||||
|
+
|
||||||
|
+ ea = strdup(s->entry_attr);
|
||||||
|
+ if (!ea) {
|
||||||
|
+ free(mc);
|
||||||
|
+ free(ma);
|
||||||
|
+ free(ec);
|
||||||
|
+ return NULL;
|
||||||
|
+ }
|
||||||
|
+
|
||||||
|
+ va = strdup(s->value_attr);
|
||||||
|
+ if (!va) {
|
||||||
|
+ free(mc);
|
||||||
|
+ free(ma);
|
||||||
|
+ free(ec);
|
||||||
|
+ free(ea);
|
||||||
|
+ return NULL;
|
||||||
|
+ }
|
||||||
|
+
|
||||||
|
+ schema = malloc(sizeof(struct ldap_schema));
|
||||||
|
+ if (!schema) {
|
||||||
|
+ free(mc);
|
||||||
|
+ free(ma);
|
||||||
|
+ free(ec);
|
||||||
|
+ free(ea);
|
||||||
|
+ free(va);
|
||||||
|
+ return NULL;
|
||||||
|
+ }
|
||||||
|
+
|
||||||
|
+ schema->map_class = mc;
|
||||||
|
+ schema->map_attr = ma;
|
||||||
|
+ schema->entry_class = ec;
|
||||||
|
+ schema->entry_attr = ea;
|
||||||
|
+ schema->value_attr = va;
|
||||||
|
+
|
||||||
|
+ return schema;
|
||||||
|
+}
|
||||||
|
+
|
||||||
|
+static int find_query_dn(LDAP *ldap, struct lookup_context *ctxt)
|
||||||
|
+{
|
||||||
|
+ struct ldap_schema *schema;
|
||||||
|
+ unsigned int i;
|
||||||
|
+
|
||||||
|
+ if (ctxt->schema)
|
||||||
|
+ return 0;
|
||||||
|
+
|
||||||
|
+ for (i = 0; i < common_schema_count; i++) {
|
||||||
|
+ const char *class = common_schema[i].map_class;
|
||||||
|
+ const char *key = common_schema[i].map_attr;
|
||||||
|
+ if (get_query_dn(ldap, ctxt, class, key)) {
|
||||||
|
+ schema = alloc_common_schema(&common_schema[i]);
|
||||||
|
+ if (!schema) {
|
||||||
|
+ error(LOGOPT_ANY,
|
||||||
|
+ MODPREFIX "failed to allocate schema");
|
||||||
|
+ return 0;
|
||||||
|
+ }
|
||||||
|
+ ctxt->schema = schema;
|
||||||
|
+ return 1;
|
||||||
|
+ }
|
||||||
|
+ }
|
||||||
|
+
|
||||||
|
+ return 0;
|
||||||
|
+}
|
||||||
|
+
|
||||||
|
/*
|
||||||
|
* This initializes a context (persistent non-global data) for queries to
|
||||||
|
* this module. Return zero if we succeed.
|
||||||
|
@@ -926,13 +974,6 @@ int lookup_init(const char *mapfmt, int
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
- /* Get default schema for queries */
|
||||||
|
- if (!get_default_schema(ctxt)) {
|
||||||
|
- error(LOGOPT_ANY, MODPREFIX "cannot set default schema");
|
||||||
|
- free_context(ctxt);
|
||||||
|
- return 1;
|
||||||
|
- }
|
||||||
|
-
|
||||||
|
#ifdef WITH_SASL
|
||||||
|
/*
|
||||||
|
* Determine which authentication mechanism to use. We sanity-
|
||||||
|
@@ -954,13 +995,31 @@ int lookup_init(const char *mapfmt, int
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
- ret = get_query_dn(ldap, ctxt);
|
||||||
|
- unbind_ldap_connection(ldap, ctxt);
|
||||||
|
- if (!ret) {
|
||||||
|
- error(LOGOPT_ANY, MODPREFIX "failed to get query dn");
|
||||||
|
- free_context(ctxt);
|
||||||
|
- return 1;
|
||||||
|
+ /*
|
||||||
|
+ * Get default schema for queries.
|
||||||
|
+ * If the schema isn't defined in the configuration then check for
|
||||||
|
+ * presence of a map dn in the common schemas.
|
||||||
|
+ */
|
||||||
|
+ ctxt->schema = defaults_get_schema();
|
||||||
|
+ if (!ctxt->schema) {
|
||||||
|
+ if (!find_query_dn(ldap, ctxt)) {
|
||||||
|
+ unbind_ldap_connection(ldap, ctxt);
|
||||||
|
+ error(LOGOPT_ANY,
|
||||||
|
+ MODPREFIX "failed to find valid query dn");
|
||||||
|
+ free_context(ctxt);
|
||||||
|
+ return 1;
|
||||||
|
+ }
|
||||||
|
+ } else {
|
||||||
|
+ const char *class = ctxt->schema->map_class;
|
||||||
|
+ const char *key = ctxt->schema->map_attr;
|
||||||
|
+ if (!get_query_dn(ldap, ctxt, class, key)) {
|
||||||
|
+ unbind_ldap_connection(ldap, ctxt);
|
||||||
|
+ error(LOGOPT_ANY, MODPREFIX "failed to get query dn");
|
||||||
|
+ free_context(ctxt);
|
||||||
|
+ return 1;
|
||||||
|
+ }
|
||||||
|
}
|
||||||
|
+ unbind_ldap_connection(ldap, ctxt);
|
||||||
|
|
||||||
|
/* Open the parser, if we can. */
|
||||||
|
ctxt->parse = open_parse(mapfmt, MODPREFIX, argc - 1, argv + 1);
|
||||||
|
@@ -990,9 +1049,9 @@ int lookup_read_master(struct master *ma
|
||||||
|
int scope = LDAP_SCOPE_SUBTREE;
|
||||||
|
LDAP *ldap;
|
||||||
|
|
||||||
|
- class = ctxt->entry_obj_class;
|
||||||
|
- entry = ctxt->entry_attr;
|
||||||
|
- info = ctxt->value_attr;
|
||||||
|
+ class = ctxt->schema->entry_class;
|
||||||
|
+ entry = ctxt->schema->entry_attr;
|
||||||
|
+ info = ctxt->schema->value_attr;
|
||||||
|
|
||||||
|
attrs[0] = entry;
|
||||||
|
attrs[1] = info;
|
||||||
|
@@ -1141,9 +1200,9 @@ static int read_one_map(struct autofs_po
|
||||||
|
|
||||||
|
mc = source->mc;
|
||||||
|
|
||||||
|
- class = ctxt->entry_obj_class;
|
||||||
|
- entry = ctxt->entry_attr;
|
||||||
|
- info = ctxt->value_attr;
|
||||||
|
+ class = ctxt->schema->entry_class;
|
||||||
|
+ entry = ctxt->schema->entry_attr;
|
||||||
|
+ info = ctxt->schema->value_attr;
|
||||||
|
|
||||||
|
attrs[0] = entry;
|
||||||
|
attrs[1] = info;
|
||||||
|
@@ -1438,9 +1497,9 @@ static int lookup_one(struct autofs_poin
|
||||||
|
return CHE_FAIL;
|
||||||
|
}
|
||||||
|
|
||||||
|
- class = ctxt->entry_obj_class;
|
||||||
|
- entry = ctxt->entry_attr;
|
||||||
|
- info = ctxt->value_attr;
|
||||||
|
+ class = ctxt->schema->entry_class;
|
||||||
|
+ entry = ctxt->schema->entry_attr;
|
||||||
|
+ info = ctxt->schema->value_attr;
|
||||||
|
|
||||||
|
attrs[0] = entry;
|
||||||
|
attrs[1] = info;
|
||||||
|
diff -up autofs-5.0.2/lib/defaults.c.add-ldap-schema-discovery autofs-5.0.2/lib/defaults.c
|
||||||
|
--- autofs-5.0.2/lib/defaults.c.add-ldap-schema-discovery 2007-06-18 15:18:08.000000000 +0800
|
||||||
|
+++ autofs-5.0.2/lib/defaults.c 2007-09-05 12:52:35.000000000 +0800
|
||||||
@@ -18,6 +18,7 @@
|
@@ -18,6 +18,7 @@
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
@ -79,7 +358,7 @@ index 4b4acba..b146f13 100644
|
|||||||
|
|
||||||
static char *get_env_string(const char *name)
|
static char *get_env_string(const char *name)
|
||||||
{
|
{
|
||||||
@@ -285,59 +278,120 @@ const char *defaults_get_ldap_server(void)
|
@@ -285,59 +278,120 @@ const char *defaults_get_ldap_server(voi
|
||||||
return (const char *) server;
|
return (const char *) server;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -235,10 +514,9 @@ index 4b4acba..b146f13 100644
|
|||||||
}
|
}
|
||||||
|
|
||||||
unsigned int defaults_get_append_options(void)
|
unsigned int defaults_get_append_options(void)
|
||||||
diff --git a/man/auto.master.5.in b/man/auto.master.5.in
|
diff -up autofs-5.0.2/man/auto.master.5.in.add-ldap-schema-discovery autofs-5.0.2/man/auto.master.5.in
|
||||||
index 69c796e..249c9a7 100644
|
--- autofs-5.0.2/man/auto.master.5.in.add-ldap-schema-discovery 2007-09-05 12:52:35.000000000 +0800
|
||||||
--- a/man/auto.master.5.in
|
+++ autofs-5.0.2/man/auto.master.5.in 2007-09-05 12:52:35.000000000 +0800
|
||||||
+++ b/man/auto.master.5.in
|
|
||||||
@@ -191,17 +191,25 @@ The old style
|
@@ -191,17 +191,25 @@ The old style
|
||||||
is also understood. Alternatively, the type can be obtained from the Name Service Switch
|
is also understood. Alternatively, the type can be obtained from the Name Service Switch
|
||||||
configuration, in which case the map name alone must be given.
|
configuration, in which case the map name alone must be given.
|
||||||
@ -361,11 +639,10 @@ index 69c796e..249c9a7 100644
|
|||||||
.SH LDAP AUTHENTICATION, ENCRYPTED AND CERTIFIED CONNECTIONS
|
.SH LDAP AUTHENTICATION, ENCRYPTED AND CERTIFIED CONNECTIONS
|
||||||
LDAP authenticated binds, TLS encrypted connections and certification
|
LDAP authenticated binds, TLS encrypted connections and certification
|
||||||
may be used by setting appropriate values in the autofs authentication
|
may be used by setting appropriate values in the autofs authentication
|
||||||
diff --git a/man/automount.8 b/man/automount.8
|
diff -up autofs-5.0.2/man/automount.8.add-ldap-schema-discovery autofs-5.0.2/man/automount.8
|
||||||
index fc1846a..da67a5c 100644
|
--- autofs-5.0.2/man/automount.8.add-ldap-schema-discovery 2007-09-05 12:52:35.000000000 +0800
|
||||||
--- a/man/automount.8
|
+++ autofs-5.0.2/man/automount.8 2007-09-05 12:52:35.000000000 +0800
|
||||||
+++ b/man/automount.8
|
@@ -102,6 +102,8 @@ started they will be recoverd unless the
|
||||||
@@ -102,6 +102,8 @@ started they will be recoverd unless they are no longer present in
|
|
||||||
the map in which case they need to umounted manually.
|
the map in which case they need to umounted manually.
|
||||||
.SH "SEE ALSO"
|
.SH "SEE ALSO"
|
||||||
.BR autofs (5),
|
.BR autofs (5),
|
||||||
@ -374,277 +651,3 @@ index fc1846a..da67a5c 100644
|
|||||||
.BR mount (8).
|
.BR mount (8).
|
||||||
.SH BUGS
|
.SH BUGS
|
||||||
Don't know, I've fixed everything I know about.
|
Don't know, I've fixed everything I know about.
|
||||||
diff --git a/modules/lookup_ldap.c b/modules/lookup_ldap.c
|
|
||||||
index a412797..d5e666b 100644
|
|
||||||
--- a/modules/lookup_ldap.c
|
|
||||||
+++ b/modules/lookup_ldap.c
|
|
||||||
@@ -42,6 +42,13 @@
|
|
||||||
|
|
||||||
int lookup_version = AUTOFS_LOOKUP_VERSION; /* Required by protocol */
|
|
||||||
|
|
||||||
+static struct ldap_schema common_schema[] = {
|
|
||||||
+ {"nisMap", "nisMapName", "nisObject", "cn", "nisMapEntry"},
|
|
||||||
+ {"automountMap", "ou", "automount", "cn", "automountInformation"},
|
|
||||||
+ {"automountMap", "automountMapName", "automount", "automountKey", "automountInformation"},
|
|
||||||
+};
|
|
||||||
+static unsigned int common_schema_count = sizeof(common_schema)/sizeof(struct ldap_schema);
|
|
||||||
+
|
|
||||||
int bind_ldap_anonymous(LDAP *ldap, struct lookup_context *ctxt)
|
|
||||||
{
|
|
||||||
int rv;
|
|
||||||
@@ -738,54 +745,15 @@ done:
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
-static int get_default_schema(struct lookup_context *ctxt)
|
|
||||||
-{
|
|
||||||
- ctxt->map_obj_class = (char *) defaults_get_map_obj_class();
|
|
||||||
- if (!ctxt->map_obj_class)
|
|
||||||
- return 0;
|
|
||||||
-
|
|
||||||
- ctxt->entry_obj_class = (char *) defaults_get_entry_obj_class();
|
|
||||||
- if (!ctxt->entry_obj_class)
|
|
||||||
- goto free_moc;
|
|
||||||
-
|
|
||||||
- ctxt->map_attr = (char *) defaults_get_map_attr();
|
|
||||||
- if (!ctxt->map_attr)
|
|
||||||
- goto free_eoc;
|
|
||||||
-
|
|
||||||
- ctxt->entry_attr = (char *) defaults_get_entry_attr();
|
|
||||||
- if (!ctxt->entry_attr)
|
|
||||||
- goto free_ma;
|
|
||||||
-
|
|
||||||
- ctxt->value_attr = (char *) defaults_get_value_attr();
|
|
||||||
- if (!ctxt->value_attr)
|
|
||||||
- goto free_ea;
|
|
||||||
-
|
|
||||||
- return 1;
|
|
||||||
-
|
|
||||||
-free_ea:
|
|
||||||
- free(ctxt->entry_attr);
|
|
||||||
-free_ma:
|
|
||||||
- free(ctxt->map_attr);
|
|
||||||
-free_eoc:
|
|
||||||
- free(ctxt->entry_obj_class);
|
|
||||||
-free_moc:
|
|
||||||
- free(ctxt->map_obj_class);
|
|
||||||
-
|
|
||||||
- ctxt->map_obj_class = NULL;
|
|
||||||
- ctxt->entry_obj_class = NULL;
|
|
||||||
- ctxt->map_attr = NULL;
|
|
||||||
- ctxt->entry_attr = NULL;
|
|
||||||
-
|
|
||||||
- return 0;
|
|
||||||
-}
|
|
||||||
-
|
|
||||||
static void free_context(struct lookup_context *ctxt)
|
|
||||||
{
|
|
||||||
- if (ctxt->map_obj_class) {
|
|
||||||
- free(ctxt->map_obj_class);
|
|
||||||
- free(ctxt->entry_obj_class);
|
|
||||||
- free(ctxt->map_attr);
|
|
||||||
- free(ctxt->entry_attr);
|
|
||||||
+ if (ctxt->schema) {
|
|
||||||
+ free(ctxt->schema->map_class);
|
|
||||||
+ free(ctxt->schema->map_attr);
|
|
||||||
+ free(ctxt->schema->entry_class);
|
|
||||||
+ free(ctxt->schema->entry_attr);
|
|
||||||
+ free(ctxt->schema->value_attr);
|
|
||||||
+ free(ctxt->schema);
|
|
||||||
}
|
|
||||||
if (ctxt->auth_conf)
|
|
||||||
free(ctxt->auth_conf);
|
|
||||||
@@ -808,19 +776,15 @@ static void free_context(struct lookup_context *ctxt)
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
-static int get_query_dn(LDAP *ldap, struct lookup_context *ctxt)
|
|
||||||
+static int get_query_dn(LDAP *ldap, struct lookup_context *ctxt, const char *class, const char *key)
|
|
||||||
{
|
|
||||||
char buf[PARSE_MAX_BUF];
|
|
||||||
char *query, *dn;
|
|
||||||
LDAPMessage *result, *e;
|
|
||||||
- char *class, *key;
|
|
||||||
char *attrs[2];
|
|
||||||
int scope;
|
|
||||||
int rv, l;
|
|
||||||
|
|
||||||
- class = ctxt->map_obj_class;
|
|
||||||
- key = ctxt->map_attr;
|
|
||||||
-
|
|
||||||
attrs[0] = LDAP_NO_ATTRS;
|
|
||||||
attrs[1] = NULL;
|
|
||||||
|
|
||||||
@@ -890,6 +854,90 @@ static int get_query_dn(LDAP *ldap, struct lookup_context *ctxt)
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
+static struct ldap_schema *alloc_common_schema(struct ldap_schema *s)
|
|
||||||
+{
|
|
||||||
+ struct ldap_schema *schema;
|
|
||||||
+ char *mc, *ma, *ec, *ea, *va;
|
|
||||||
+
|
|
||||||
+ mc = strdup(s->map_class);
|
|
||||||
+ if (!mc)
|
|
||||||
+ return NULL;
|
|
||||||
+
|
|
||||||
+ ma = strdup(s->map_attr);
|
|
||||||
+ if (!ma) {
|
|
||||||
+ free(mc);
|
|
||||||
+ return NULL;
|
|
||||||
+ }
|
|
||||||
+
|
|
||||||
+ ec = strdup(s->entry_class);
|
|
||||||
+ if (!ec) {
|
|
||||||
+ free(mc);
|
|
||||||
+ free(ma);
|
|
||||||
+ return NULL;
|
|
||||||
+ }
|
|
||||||
+
|
|
||||||
+ ea = strdup(s->entry_attr);
|
|
||||||
+ if (!ea) {
|
|
||||||
+ free(mc);
|
|
||||||
+ free(ma);
|
|
||||||
+ free(ec);
|
|
||||||
+ return NULL;
|
|
||||||
+ }
|
|
||||||
+
|
|
||||||
+ va = strdup(s->value_attr);
|
|
||||||
+ if (!va) {
|
|
||||||
+ free(mc);
|
|
||||||
+ free(ma);
|
|
||||||
+ free(ec);
|
|
||||||
+ free(ea);
|
|
||||||
+ return NULL;
|
|
||||||
+ }
|
|
||||||
+
|
|
||||||
+ schema = malloc(sizeof(struct ldap_schema));
|
|
||||||
+ if (!schema) {
|
|
||||||
+ free(mc);
|
|
||||||
+ free(ma);
|
|
||||||
+ free(ec);
|
|
||||||
+ free(ea);
|
|
||||||
+ free(va);
|
|
||||||
+ return NULL;
|
|
||||||
+ }
|
|
||||||
+
|
|
||||||
+ schema->map_class = mc;
|
|
||||||
+ schema->map_attr = ma;
|
|
||||||
+ schema->entry_class = ec;
|
|
||||||
+ schema->entry_attr = ea;
|
|
||||||
+ schema->value_attr = va;
|
|
||||||
+
|
|
||||||
+ return schema;
|
|
||||||
+}
|
|
||||||
+
|
|
||||||
+static int find_query_dn(LDAP *ldap, struct lookup_context *ctxt)
|
|
||||||
+{
|
|
||||||
+ struct ldap_schema *schema;
|
|
||||||
+ unsigned int i;
|
|
||||||
+
|
|
||||||
+ if (ctxt->schema)
|
|
||||||
+ return 0;
|
|
||||||
+
|
|
||||||
+ for (i = 0; i < common_schema_count; i++) {
|
|
||||||
+ const char *class = common_schema[i].map_class;
|
|
||||||
+ const char *key = common_schema[i].map_attr;
|
|
||||||
+ if (get_query_dn(ldap, ctxt, class, key)) {
|
|
||||||
+ schema = alloc_common_schema(&common_schema[i]);
|
|
||||||
+ if (!schema) {
|
|
||||||
+ error(LOGOPT_ANY,
|
|
||||||
+ MODPREFIX "failed to allocate schema");
|
|
||||||
+ return 0;
|
|
||||||
+ }
|
|
||||||
+ ctxt->schema = schema;
|
|
||||||
+ return 1;
|
|
||||||
+ }
|
|
||||||
+ }
|
|
||||||
+
|
|
||||||
+ return 0;
|
|
||||||
+}
|
|
||||||
+
|
|
||||||
/*
|
|
||||||
* This initializes a context (persistent non-global data) for queries to
|
|
||||||
* this module. Return zero if we succeed.
|
|
||||||
@@ -926,13 +974,6 @@ int lookup_init(const char *mapfmt, int argc, const char *const *argv, void **co
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
- /* Get default schema for queries */
|
|
||||||
- if (!get_default_schema(ctxt)) {
|
|
||||||
- error(LOGOPT_ANY, MODPREFIX "cannot set default schema");
|
|
||||||
- free_context(ctxt);
|
|
||||||
- return 1;
|
|
||||||
- }
|
|
||||||
-
|
|
||||||
#ifdef WITH_SASL
|
|
||||||
/*
|
|
||||||
* Determine which authentication mechanism to use. We sanity-
|
|
||||||
@@ -954,13 +995,22 @@ int lookup_init(const char *mapfmt, int argc, const char *const *argv, void **co
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
- ret = get_query_dn(ldap, ctxt);
|
|
||||||
- unbind_ldap_connection(ldap, ctxt);
|
|
||||||
- if (!ret) {
|
|
||||||
- error(LOGOPT_ANY, MODPREFIX "failed to get query dn");
|
|
||||||
- free_context(ctxt);
|
|
||||||
- return 1;
|
|
||||||
+ /*
|
|
||||||
+ * Get default schema for queries.
|
|
||||||
+ * If the schema isn't defined in the configuration then check for
|
|
||||||
+ * presence of a map dn in the common schemas.
|
|
||||||
+ */
|
|
||||||
+ ctxt->schema = defaults_get_schema();
|
|
||||||
+ if (!ctxt->schema) {
|
|
||||||
+ if (!find_query_dn(ldap, ctxt)) {
|
|
||||||
+ unbind_ldap_connection(ldap, ctxt);
|
|
||||||
+ error(LOGOPT_ANY,
|
|
||||||
+ MODPREFIX "failed to find valid query dn");
|
|
||||||
+ free_context(ctxt);
|
|
||||||
+ return 1;
|
|
||||||
+ }
|
|
||||||
}
|
|
||||||
+ unbind_ldap_connection(ldap, ctxt);
|
|
||||||
|
|
||||||
/* Open the parser, if we can. */
|
|
||||||
ctxt->parse = open_parse(mapfmt, MODPREFIX, argc - 1, argv + 1);
|
|
||||||
@@ -990,9 +1040,9 @@ int lookup_read_master(struct master *master, time_t age, void *context)
|
|
||||||
int scope = LDAP_SCOPE_SUBTREE;
|
|
||||||
LDAP *ldap;
|
|
||||||
|
|
||||||
- class = ctxt->entry_obj_class;
|
|
||||||
- entry = ctxt->entry_attr;
|
|
||||||
- info = ctxt->value_attr;
|
|
||||||
+ class = ctxt->schema->entry_class;
|
|
||||||
+ entry = ctxt->schema->entry_attr;
|
|
||||||
+ info = ctxt->schema->value_attr;
|
|
||||||
|
|
||||||
attrs[0] = entry;
|
|
||||||
attrs[1] = info;
|
|
||||||
@@ -1141,9 +1191,9 @@ static int read_one_map(struct autofs_point *ap,
|
|
||||||
|
|
||||||
mc = source->mc;
|
|
||||||
|
|
||||||
- class = ctxt->entry_obj_class;
|
|
||||||
- entry = ctxt->entry_attr;
|
|
||||||
- info = ctxt->value_attr;
|
|
||||||
+ class = ctxt->schema->entry_class;
|
|
||||||
+ entry = ctxt->schema->entry_attr;
|
|
||||||
+ info = ctxt->schema->value_attr;
|
|
||||||
|
|
||||||
attrs[0] = entry;
|
|
||||||
attrs[1] = info;
|
|
||||||
@@ -1438,9 +1488,9 @@ static int lookup_one(struct autofs_point *ap,
|
|
||||||
return CHE_FAIL;
|
|
||||||
}
|
|
||||||
|
|
||||||
- class = ctxt->entry_obj_class;
|
|
||||||
- entry = ctxt->entry_attr;
|
|
||||||
- info = ctxt->value_attr;
|
|
||||||
+ class = ctxt->schema->entry_class;
|
|
||||||
+ entry = ctxt->schema->entry_attr;
|
|
||||||
+ info = ctxt->schema->value_attr;
|
|
||||||
|
|
||||||
attrs[0] = entry;
|
|
||||||
attrs[1] = info;
|
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
Summary: A tool for automatically mounting and unmounting filesystems
|
Summary: A tool for automatically mounting and unmounting filesystems
|
||||||
Name: autofs
|
Name: autofs
|
||||||
Version: 5.0.2
|
Version: 5.0.2
|
||||||
Release: 14
|
Release: 15
|
||||||
Epoch: 1
|
Epoch: 1
|
||||||
License: GPL
|
License: GPL
|
||||||
Group: System Environment/Daemons
|
Group: System Environment/Daemons
|
||||||
@ -139,6 +139,9 @@ fi
|
|||||||
%{_libdir}/autofs/
|
%{_libdir}/autofs/
|
||||||
|
|
||||||
%changelog
|
%changelog
|
||||||
|
* Wed Sep 5 2007 Ian Kent <ikent@redhat.com> - 5.0.2-15
|
||||||
|
- fix LDAP schema discovery.
|
||||||
|
|
||||||
* Tue Aug 28 2007 Ian Kent <ikent@redhat.com> - 5.0.2-14
|
* Tue Aug 28 2007 Ian Kent <ikent@redhat.com> - 5.0.2-14
|
||||||
- update patch to prevent failure on empty master map.
|
- update patch to prevent failure on empty master map.
|
||||||
- if there's no "automount" entry in nsswitch.conf use "files" source.
|
- if there's no "automount" entry in nsswitch.conf use "files" source.
|
||||||
|
Loading…
Reference in New Issue
Block a user