Browse Source

Ticket 153 - use openldap's schema parser

        Bug Description:  After running ol-schema-migrate.pl(which converts openldap schema to
                          389 DS schema format), 389 still doesn't parse the schema correctly as
                          it expects the syntax to be in a certain order.

        Fix Description:  First, instead of only recording the "X-ORIGIN" values, I have created a
                          linked list for all the schema extensions, not just "X-ORIGIN".  Then on
                          systems that have openldap, we use the openldap schema parser.  On
                          systems that only have mozldap, we use the old parser.

                          Also did some code cleanup.

        https://fedorahosted.org/389/ticket/153

        Reviewed by: richm(Thanks!)
Mark Reynolds 12 years ago
parent
commit
305dac5202

+ 26 - 24
ldap/servers/slapd/attrsyntax.c

@@ -208,7 +208,7 @@ attr_syntax_free( struct asyntaxinfo *a )
 	slapi_ch_free( (void **)&a->asi_mr_equality );
 	slapi_ch_free( (void **)&a->asi_mr_ordering );
 	slapi_ch_free( (void **)&a->asi_mr_substring );
-	cool_charray_free( a->asi_origin );
+	schema_free_extensions(a->asi_extensions);
 	slapi_ch_free( (void **) &a );
 }
 
@@ -584,7 +584,7 @@ attr_syntax_dup( struct asyntaxinfo *a )
 	newas->asi_mr_equality = slapi_ch_strdup( a->asi_mr_equality );
 	newas->asi_mr_ordering = slapi_ch_strdup( a->asi_mr_ordering );
 	newas->asi_mr_substring = slapi_ch_strdup( a->asi_mr_substring );
-	newas->asi_origin = cool_charray_dup( a->asi_origin );
+	newas->asi_extensions = schema_copy_extensions( a->asi_extensions );
 	newas->asi_plugin = a->asi_plugin;
 	newas->asi_flags = a->asi_flags;
 	newas->asi_oid = slapi_ch_strdup( a->asi_oid);
@@ -622,9 +622,9 @@ attr_syntax_add( struct asyntaxinfo *asip )
 			goto cleanup_and_return;
 		}
 	}
-
-	/* make sure the primary name is unique OR, if override is allowed, that
-     * the primary name and OID point to the same schema definition.
+	/*
+	 * Make sure the primary name is unique OR, if override is allowed, that
+	 * the primary name and OID point to the same schema definition.
 	 */
 	if ( NULL != ( oldas_from_name = attr_syntax_get_by_name_locking_optional(
 					asip->asi_name, !nolock))) {
@@ -687,23 +687,22 @@ cleanup_and_return:
  */
 int
 attr_syntax_create(
-	const char			*attr_oid,
-	char *const			*attr_names,
-	int					num_names,
-	const char			*attr_desc,
-	const char			*attr_superior,
-	const char			*mr_equality,
-	const char			*mr_ordering,
-	const char			*mr_substring,
-	char *const			*attr_origins,
-	const char			*attr_syntax,
-	int					syntaxlength,
+	const char		*attr_oid,
+	char *const		*attr_names,
+	const char		*attr_desc,
+	const char		*attr_superior,
+	const char		*mr_equality,
+	const char		*mr_ordering,
+	const char		*mr_substring,
+	schemaext		*extensions,
+	const char		*attr_syntax,
+	int			syntaxlength,
 	unsigned long		flags,
 	struct asyntaxinfo	**asip
 )
 {
-	char					*s;
-	struct asyntaxinfo		a;
+	char			*s;
+	struct asyntaxinfo	a;
 	int rc = LDAP_SUCCESS;
 
 	/* XXXmcs: had to cast away const in many places below */
@@ -719,7 +718,7 @@ attr_syntax_create(
 	a.asi_mr_equality = (char*)mr_equality;
 	a.asi_mr_ordering = (char*)mr_ordering;
 	a.asi_mr_substring = (char*)mr_substring;
-	a.asi_origin = (char **)attr_origins;
+	a.asi_extensions = extensions;
 	a.asi_plugin = plugin_syntax_find( attr_syntax );
 	a.asi_syntaxlength = syntaxlength;
 	/* ideally, we would report an error and fail to start if there was some problem
@@ -905,6 +904,8 @@ attr_syntax_printnode(PLHashEntry *he, PRIntn i, void *arg)
 {
 	char *alias = (char *)he->key;
 	struct asyntaxinfo *a = (struct asyntaxinfo *)he->value;
+	schemaext *ext = a->asi_extensions;
+
 	printf( "  name: %s\n", a->asi_name );
 	printf( "\t flags       : 0x%x\n", a->asi_flags );
 	printf( "\t alias       : %s\n", alias );
@@ -914,10 +915,11 @@ attr_syntax_printnode(PLHashEntry *he, PRIntn i, void *arg)
 	printf( "\t mr_equality : %s\n", a->asi_mr_equality );
 	printf( "\t mr_ordering : %s\n", a->asi_mr_ordering );
 	printf( "\t mr_substring: %s\n", a->asi_mr_substring );
-	if ( NULL != a->asi_origin ) {
-		for ( i = 0; NULL != a->asi_origin[i]; ++i ) {
-			printf( "\t origin      : %s\n", a->asi_origin[i] );
+	while( ext ) {
+		for ( i = 0; ext->values && ext->values[i]; i++ ) {
+			printf( "\t %s      : %s\n", ext->term, ext->values[i]);
 		}
+		ext = ext->next;
 	}
 	printf( "\tplugin: %p\n", a->asi_plugin );
 	printf( "--------------\n" );
@@ -1236,11 +1238,11 @@ slapi_add_internal_attr_syntax( const char *name, const char *oid,
 	origins[0] = SLAPD_VERSION_STR;
 	origins[1] = NULL;
 
-	rc = attr_syntax_create( oid, names, 1,
+	rc = attr_syntax_create( oid, names,
 			"internal server defined attribute type",
 			 NULL,						/* superior */
 			 mr_equality, NULL, NULL,	/* matching rules */
-			 origins, syntax,
+			 NULL, syntax,
 			 SLAPI_SYNTAXLENGTH_NONE,
 			 std_flags | extraflags,
 			 &asip );

+ 8 - 1
ldap/servers/slapd/charray.c

@@ -55,6 +55,13 @@ charray_add(
     char    ***a,
     char    *s
 )
+{
+    slapi_ch_array_add_ext(a, s);
+}
+
+/* return the total number of elements that are now in the array */
+int
+slapi_ch_array_add_ext(char ***a, char *s)
 {
     int    n;
 
@@ -81,10 +88,10 @@ charray_add(
 #endif
 
     /* Putting code back so that thread conflict can be made visible */
-
     (*a)[n++] = s;
     (*a)[n] = NULL;
 
+    return n;
 }
 
 void

+ 5 - 5
ldap/servers/slapd/proto-slap.h

@@ -121,11 +121,10 @@ int attr_syntax_exists (const char *attr_name);
 void attr_syntax_delete ( struct asyntaxinfo *asip );
 #define SLAPI_SYNTAXLENGTH_NONE		(-1)	/* for syntaxlength parameter */
 int attr_syntax_create( const char *attr_oid, char *const*attr_names,
-		int num_names, const char *attr_desc, const char *attr_superior,
+		const char *attr_desc, const char *attr_superior,
 		const char *mr_equality, const char *mr_ordering,
-		const char *mr_substring, char *const *attr_origins,
-		const char *attr_syntax, int syntaxlength, unsigned long flags,
-		struct asyntaxinfo **asip );
+		const char *mr_substring, schemaext *extensions, const char *attr_syntax,
+		int syntaxlength, unsigned long flags, struct asyntaxinfo **asip );
 void attr_syntax_free( struct asyntaxinfo *a );
 int attr_syntax_add( struct asyntaxinfo *asip );
 char *attr_syntax_normalize_no_lookup( const char *s );
@@ -1000,7 +999,8 @@ void slapi_schema_expand_objectclasses( Slapi_Entry *e );
 int slapi_validate_schema_files(char *schemadir);
 /* API to reload the schema files */
 int slapi_reload_schema_files(char *schemadir);
-
+void schema_free_extensions(schemaext *extensions);
+schemaext *schema_copy_extensions(schemaext *extensions);
 /*
  * schemaparse.c
  */

File diff suppressed because it is too large
+ 448 - 278
ldap/servers/slapd/schema.c


+ 24 - 16
ldap/servers/slapd/slap.h

@@ -491,6 +491,14 @@ typedef struct oid_item {
     struct oid_item	*oi_next;
 } oid_item_t;
 
+/* schema extension item: X-ORIGIN, X-CSN, etc */
+typedef struct schemaext {
+    char *term;
+    char **values;
+    int value_count;
+    struct schemaext *next;
+} schemaext;
+
 /* attribute description (represents an attribute, but not the value) */
 typedef struct asyntaxinfo {
     char    			*asi_oid;			/* OID */
@@ -501,7 +509,7 @@ typedef struct asyntaxinfo {
 	char				*asi_mr_equality;	/* equality matching rule */
 	char				*asi_mr_ordering;	/* ordering matching rule */
 	char				*asi_mr_substring;	/* substring matching rule */
-	char				**asi_origin;		/* X-ORIGIN extension */
+	schemaext			*asi_extensions;	/* schema extensions (X-ORIGIN, X-?????, ...) */
 	struct slapdplugin	*asi_plugin;		/* syntax */
 	unsigned long		asi_flags;			/* SLAPI_ATTR_FLAG_... */
 	int					asi_syntaxlength;	/* length associated w/syntax */
@@ -676,25 +684,25 @@ extern struct attrs_in_extension attrs_in_extension[];
 #define OC_FLAG_OBSOLETE		8
 
 /* values for oc_kind */
-#define OC_KIND_STRUCTURAL		0
-#define OC_KIND_AUXILIARY		1
-#define OC_KIND_ABSTRACT		2
+#define OC_KIND_ABSTRACT		0
+#define OC_KIND_STRUCTURAL		1
+#define OC_KIND_AUXILIARY		2
 
 
 /* XXXmcs: ../plugins/cos/cos_cache.c has its own copy of this definition! */
 struct objclass {
-	char				*oc_name;		/* NAME */
-	char				*oc_desc;		/* DESC */
-    char        		*oc_oid;		/* object identifier */
-    char        		*oc_superior;	/* SUP -- XXXmcs: should be an array */
-	PRUint8				oc_kind;		/* ABSTRACT/STRUCTURAL/AUXILIARY */
-    PRUint8				oc_flags;		/* misc. flags, e.g., OBSOLETE */
-	char				**oc_required;
-	char				**oc_allowed;
-    char        		**oc_orig_required;	/* MUST */
-    char        		**oc_orig_allowed;	/* MAY */
-	char				**oc_origin;	/* X-ORIGIN extension */
-	struct objclass		*oc_next;
+    char                *oc_name;       /* NAME */
+    char                *oc_desc;       /* DESC */
+    char                *oc_oid;        /* object identifier */
+    char                *oc_superior;   /* SUP -- XXXmcs: should be an array */
+    PRUint8             oc_kind;        /* ABSTRACT/STRUCTURAL/AUXILIARY */
+    PRUint8             oc_flags;       /* misc. flags, e.g., OBSOLETE */
+    char                **oc_required;
+    char                **oc_allowed;
+    char                **oc_orig_required; /* MUST */
+    char                **oc_orig_allowed;  /* MAY */
+    schemaext           *oc_extensions; /* schema extensions (X-ORIGIN, X-?????, ...) */
+    struct objclass     *oc_next;
 };
 
 struct matchingRuleList {

+ 15 - 0
ldap/servers/slapd/slapi-plugin.h

@@ -5439,6 +5439,21 @@ char ** slapi_ch_array_dup( char **array );
  */
 void slapi_ch_array_add( char ***array, char *string );
 
+/**
+ * Add a string to an array of strings
+ *
+ * \param array The array to add the string to
+ * \param string The string to add to the array
+ * \warning The \c string parameter is not copied.  If you do not
+ *          want to hand the memory used by \c string over to the
+ *          array, you should duplicate it first by calling the
+ *          slapi_ch_strdup() function.
+ * \warning If \c *a is \c NULL, a new array will be allocated.
+ * \see slapi_ch_array_free()
+ * \return the total number of elements in the array.
+ */
+int slapi_ch_array_add_ext(char ***array, char *string);
+
 /**
  * Find a string in an array of strings
  *

Some files were not shown because too many files changed in this diff