10139N/A--- servers/slapd/schema_check.c 2003/06/26 13:12:39 1.1
10139N/A+++ servers/slapd/schema_check.c 2003/06/26 14:56:05
10139N/A@@ -21,6 +21,11 @@
10139N/A ObjectClass *oc,
10139N/A struct berval *ocname );
10139N/A
10139N/A+static int entry_naming_check(
10139N/A+ Entry *e,
10139N/A+ const char** text,
10139N/A+ char *textbuf, size_t textlen );
10139N/A+
10139N/A /*
10139N/A * entry_schema_check - check that entry e conforms to the schema required
10139N/A * by its object class(es).
10139N/A@@ -198,6 +203,12 @@
10139N/A return LDAP_NO_OBJECT_CLASS_MODS;
10139N/A }
10139N/A
10139N/A+ /* naming check */
10139N/A+ rc = entry_naming_check( e, text, textbuf, textlen );
10139N/A+ if( rc != LDAP_SUCCESS ) {
10139N/A+ return rc;
10139N/A+ }
10139N/A+
10139N/A /* check that the entry has required attrs for each oc */
10139N/A for ( i = 0; aoc->a_vals[i].bv_val != NULL; i++ ) {
10139N/A if ( (oc = oc_bvfind( &aoc->a_vals[i] )) == NULL ) {
10139N/A@@ -589,3 +600,70 @@
10139N/A return structural_class( ocmod->sml_bvalues, sc, NULL,
10139N/A text, textbuf, textlen );
10139N/A }
10139N/A+
10139N/A+static int
10139N/A+entry_naming_check(
10139N/A+ Entry *e,
10139N/A+ const char** text,
10139N/A+ char *textbuf, size_t textlen )
10139N/A+{
10139N/A+ /* naming check */
10139N/A+ LDAPRDN *rdn = NULL;
10139N/A+ const char *p = NULL;
10139N/A+ ber_len_t cnt;
10139N/A+ int rc = LDAP_SUCCESS;
10139N/A+
10139N/A+ /*
10139N/A+ * Get attribute type(s) and attribute value(s) of our RDN
10139N/A+ */
10139N/A+ if ( ldap_bv2rdn( &e->e_name, &rdn, (char **)&p,
10139N/A+ LDAP_DN_FORMAT_LDAP ) )
10139N/A+ {
10139N/A+ *text = "unrecongized attribute type(s) in RDN";
10139N/A+ return LDAP_INVALID_DN_SYNTAX;
10139N/A+ }
10139N/A+
10139N/A+ /* Check that each AVA of the RDN is present in the entry */
10139N/A+ /* FIXME: Should also check that each AVA lists a distinct type */
10139N/A+ for ( cnt = 0; (*rdn)[cnt]; cnt++ ) {
10139N/A+ LDAPAVA *ava = (*rdn)[cnt];
10139N/A+ AttributeDescription *desc = NULL;
10139N/A+ Attribute *attr;
10139N/A+ const char *errtext;
10139N/A+
10139N/A+ rc = slap_bv2ad( &ava->la_attr, &desc, &errtext );
10139N/A+ if ( rc != LDAP_SUCCESS ) {
10139N/A+ snprintf( textbuf, textlen, "%s (in RDN)", errtext );
10139N/A+ break;
10139N/A+ }
10139N/A+
10139N/A+ /* find the naming attribute */
10139N/A+ attr = attr_find( e->e_attrs, desc );
10139N/A+ if ( attr == NULL ) {
10139N/A+ snprintf( textbuf, textlen,
10139N/A+ "naming attribute '%s' is not present in entry",
10139N/A+ ava->la_attr.bv_val );
10139N/A+ rc = LDAP_NAMING_VIOLATION;
10139N/A+ break;
10139N/A+ }
10139N/A+
10139N/A+ if( ava->la_flags & LDAP_AVA_BINARY ) {
10139N/A+ snprintf( textbuf, textlen,
10139N/A+ "value of naming attribute '%s' in unsupported BER form",
10139N/A+ ava->la_attr.bv_val );
10139N/A+ rc = LDAP_NAMING_VIOLATION;
10139N/A+ }
10139N/A+
10139N/A+ if ( value_find( desc, attr->a_vals, &ava->la_value ) != 0 ) {
10139N/A+ snprintf( textbuf, textlen,
10139N/A+ "value of naming attribute '%s' is not present in entry",
10139N/A+ ava->la_attr.bv_val );
10139N/A+ rc = LDAP_NAMING_VIOLATION;
10139N/A+ break;
10139N/A+ }
10139N/A+ }
10139N/A+
10139N/A+ ldap_rdnfree( rdn );
10139N/A+ return rc;
10139N/A+}
10139N/A+