This is the mail archive of the
cluster-cvs@sourceware.org
mailing list for the cluster.
cluster: STABLE3 - config: Add 'cn' to LDIF when needed
- From: Lon Hohberger <lon at fedoraproject dot org>
- To: cluster-cvs-relay at redhat dot com
- Date: Thu, 10 Sep 2009 17:49:17 +0000 (UTC)
- Subject: cluster: STABLE3 - config: Add 'cn' to LDIF when needed
Gitweb: http://git.fedorahosted.org/git/cluster.git?p=cluster.git;a=commitdiff;h=85bc3dd69ce5dfac07bc90e85619fa3123813f29
Commit: 85bc3dd69ce5dfac07bc90e85619fa3123813f29
Parent: 631ec23c7baf7fc4ff6cad16fba7f8a02ebe0dcc
Author: Lon Hohberger <lhh@redhat.com>
AuthorDate: Thu Sep 10 13:29:56 2009 -0400
Committer: Lon Hohberger <lhh@redhat.com>
CommitterDate: Thu Sep 10 13:29:56 2009 -0400
config: Add 'cn' to LDIF when needed
Adds 'MUST ( cn )' to LDIF output when no 'name'
or 'cn' attribute is present already.
Signed-off-by: Lon Hohberger <lhh@redhat.com>
---
config/tools/ldap/rng2ldif/rng2ldif.c | 10 ++++++++
config/tools/ldap/rng2ldif/tree.c | 39 ++++++++++++++++++++++++++++----
config/tools/ldap/rng2ldif/tree.h | 2 +
3 files changed, 46 insertions(+), 5 deletions(-)
diff --git a/config/tools/ldap/rng2ldif/rng2ldif.c b/config/tools/ldap/rng2ldif/rng2ldif.c
index ea99e8b..33e795c 100644
--- a/config/tools/ldap/rng2ldif/rng2ldif.c
+++ b/config/tools/ldap/rng2ldif/rng2ldif.c
@@ -81,10 +81,20 @@ print_obj_node(FILE *fp, struct ldap_object_node *node)
if (node->required_attrs) {
fprintf(fp, "%s MUST ( ", cmt);
+
+ if (node->need_cn) {
+ fprintf(fp, "cn $ ");
+ }
+
for (n = node->required_attrs; n->next != NULL; n = n->next)
fprintf(fp, "%s $ ", n->node->name);
fprintf(fp, "%s )\n", n->node->name);
+ } else {
+ if (node->need_cn) {
+ fprintf(fp, "%s MUST ( cn )\n", cmt);
+ }
}
+
if (node->optional_attrs) {
fprintf(fp, "%s MAY ( ", cmt);
for (n = node->optional_attrs; n->next != NULL; n = n->next)
diff --git a/config/tools/ldap/rng2ldif/tree.c b/config/tools/ldap/rng2ldif/tree.c
index a6e0b46..61acc5b 100644
--- a/config/tools/ldap/rng2ldif/tree.c
+++ b/config/tools/ldap/rng2ldif/tree.c
@@ -13,7 +13,7 @@
static struct ldap_attr_node *
-find_attr(struct ldap_attr_node *attrs, const char *name)
+find_attr_byname(struct ldap_attr_node *attrs, const char *name)
{
struct ldap_attr_node *n;
@@ -38,6 +38,19 @@ find_meta_attr(struct ldap_attr_meta_node *metas, struct ldap_attr_node *attr)
}
+static struct ldap_attr_meta_node *
+find_meta_attr_byname(struct ldap_attr_meta_node *metas, const char *name)
+{
+ struct ldap_attr_meta_node *n;
+
+ for (n = metas; n; n = n->next) {
+ if (!strcmp(n->node->name, name))
+ return n;
+ }
+ return NULL;
+}
+
+
static int
find_data_match_fn(xmlNodePtr curr_node, char **match_fn, char **ldap_syntax)
{
@@ -82,7 +95,7 @@ get_attr(xmlNodePtr curr_node, struct ldap_attr_node **attrs,
name = (char *)xmlGetProp(curr_node, (xmlChar *)"name");
normalized = normalize_name((const char *)name);
- n = find_attr(*attrs, normalized);
+ n = find_attr_byname(*attrs, normalized);
if (n) {
free(normalized);
return n;
@@ -249,8 +262,10 @@ parse_element_tag(xmlNodePtr curr_node,
struct idinfo *ids)
{
struct ldap_object_node *obj;
+ struct ldap_attr_meta_node *attrm;
char *n, *normalized;
struct idval *v;
+ int need_cn = 1;
dbg_printf("Trying to parse element tag\n");
n = (char *)xmlGetProp(curr_node, (xmlChar *)"name");
@@ -273,13 +288,29 @@ parse_element_tag(xmlNodePtr curr_node,
obj->idval = v;
obj->next = *objs;
*objs = obj;
- dbg_printf("New object class %s \n",obj->name);
+ printf("New object class %s \n",obj->name);
}
find_optional_attributes(curr_node->xmlChildrenNode, 0,
obj, attrs, ids);
find_required_attributes(curr_node->xmlChildrenNode,
obj, attrs, ids);
+
+ if (find_meta_attr_byname(obj->required_attrs, "name") ||
+ find_meta_attr_byname(obj->required_attrs, "cn")) {
+ need_cn = 0;
+ }
+
+ if (need_cn &&
+ (find_meta_attr_byname(obj->optional_attrs, "name") ||
+ find_meta_attr_byname(obj->optional_attrs, "cn"))) {
+ need_cn = 0;
+ }
+
+ if (need_cn) {
+ dbg_printf("Object class might %s need 'MUST ( cn )' for proper LDIF\n", obj->name);
+ obj->need_cn = 1;
+ }
}
@@ -289,8 +320,6 @@ find_objects(xmlNodePtr curr_node,
struct ldap_attr_node **attrs,
struct idinfo *ids)
{
- //xmlNodePtr node;
-
if (!curr_node)
return 0;
diff --git a/config/tools/ldap/rng2ldif/tree.h b/config/tools/ldap/rng2ldif/tree.h
index 098f4b6..f55c556 100644
--- a/config/tools/ldap/rng2ldif/tree.h
+++ b/config/tools/ldap/rng2ldif/tree.h
@@ -26,6 +26,8 @@ struct ldap_object_node {
struct idval *idval;
struct ldap_attr_meta_node *optional_attrs;
struct ldap_attr_meta_node *required_attrs;
+ int need_cn; /* If we don't have a 'name' or a 'cn' attribute,
+ add one when we output the LDIF */
};
int