1 /* schema.c - routines to enforce schema definitions */
4 * Copyright 1998-1999 The OpenLDAP Foundation, All Rights Reserved.
5 * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
13 #include <ac/string.h>
14 #include <ac/socket.h>
19 static char * oc_check_required(Entry *e, char *ocname);
20 static int oc_check_allowed(char *type, struct berval **ocl);
23 * oc_check - check that entry e conforms to the schema required by
24 * its object class(es). returns 0 if so, non-zero otherwise.
28 oc_schema_check( Entry *e )
36 /* find the object class attribute - could error out here */
37 if ( (aoc = attr_find( e->e_attrs, "objectclass" )) == NULL ) {
38 Debug( LDAP_DEBUG_ANY, "No object class for entry (%s)\n",
43 /* check that the entry has required attrs for each oc */
44 for ( i = 0; aoc->a_vals[i] != NULL; i++ ) {
45 if ( (oc = oc_find( aoc->a_vals[i]->bv_val )) == NULL ) {
46 Debug( LDAP_DEBUG_ANY,
47 "Objectclass \"%s\" not defined\n",
48 aoc->a_vals[i]->bv_val, 0, 0 );
52 char *s = oc_check_required( e, aoc->a_vals[i]->bv_val );
55 Debug( LDAP_DEBUG_ANY,
56 "Entry (%s), oc \"%s\" requires attr \"%s\"\n",
57 e->e_dn, aoc->a_vals[i]->bv_val, s );
67 /* check that each attr in the entry is allowed by some oc */
68 for ( a = e->e_attrs; a != NULL; a = a->a_next ) {
69 if ( oc_check_allowed( a->a_type, aoc->a_vals ) != 0 ) {
70 Debug( LDAP_DEBUG_ANY,
71 "Entry (%s), attr \"%s\" not allowed\n",
72 e->e_dn, a->a_type, 0 );
81 oc_check_required( Entry *e, char *ocname )
89 Debug( LDAP_DEBUG_TRACE,
90 "oc_check_required entry (%s), objectclass \"%s\"\n",
93 /* find global oc defn. it we don't know about it assume it's ok */
94 if ( (oc = oc_find( ocname )) == NULL ) {
98 /* check for empty oc_required */
99 if(oc->soc_required == NULL) {
103 /* for each required attribute */
104 for ( i = 0; oc->soc_required[i] != NULL; i++ ) {
105 at = oc->soc_required[i];
106 /* see if it's in the entry */
107 for ( a = e->e_attrs; a != NULL; a = a->a_next ) {
109 strcmp( a->a_type, at->sat_oid ) == 0 ) {
114 /* Empty name list => not found */
119 if ( strcasecmp( a->a_type, *pp ) == 0 ) {
128 /* not there => schema violation */
130 if ( at->sat_names && at->sat_names[0] ) {
131 return at->sat_names[0];
141 #ifdef SLAPD_SCHEMA_COMPAT
142 /* these shouldn't be hardcoded */
144 static char *oc_op_usermod_attrs[] = {
146 * these are operational attributes which are
147 * not defined as NO-USER_MODIFICATION and
148 * which slapd supports modification of.
151 * Likely candidate, "aci"
156 static char *oc_op_attrs[] = {
158 * these are operational attributes
159 * most could be user modifiable
170 "supportedExtension",
172 "supportedSASLMechanisms",
173 "supportedLDAPversion",
174 "supportedACIMechanisms",
175 "subschemaSubentry", /* NO USER MOD */
180 /* this list should be extensible */
181 static char *oc_op_no_usermod_attrs[] = {
183 * Operational and 'no user modification' attributes
184 * which are STORED in the directory server.
199 * check to see if attribute is 'operational' or not.
202 oc_check_op_attr( const char *type )
204 #ifdef SLAPD_SCHEMA_COMPAT
205 return charray_inlist( oc_op_attrs, type )
206 || charray_inlist( oc_op_usermod_attrs, type )
207 || charray_inlist( oc_op_no_usermod_attrs, type );
209 AttributeType *at = at_find( type );
211 if( at == NULL ) return 0;
213 return at->sat_usage != 0;
218 * check to see if attribute can be user modified or not.
221 oc_check_op_usermod_attr( const char *type )
223 #ifdef SLAPD_SCHEMA_COMPAT
224 return charray_inlist( oc_op_usermod_attrs, type );
226 /* not (yet) in schema */
232 * check to see if attribute is 'no user modification' or not.
235 oc_check_op_no_usermod_attr( const char *type )
237 #ifdef SLAPD_SCHEMA_COMPAT
238 return charray_inlist( oc_op_no_usermod_attrs, type );
240 AttributeType *at = at_find( type );
242 if( at == NULL ) return 0;
244 return at->sat_no_user_mod;
250 oc_check_allowed( char *type, struct berval **ocl )
258 Debug( LDAP_DEBUG_TRACE,
259 "oc_check_allowed type \"%s\"\n", type, 0, 0 );
261 /* always allow objectclass attribute */
262 if ( strcasecmp( type, "objectclass" ) == 0 ) {
267 * The "type" we have received is actually an AttributeDescription.
268 * Let's find out the corresponding type.
270 p = strchr( type, ';' );
272 t = ch_malloc( p-type+1 );
273 strncpy( t, type, p-type );
275 Debug( LDAP_DEBUG_TRACE,
276 "oc_check_allowed type \"%s\" from \"%s\"\n",
284 * All operational attributions are allowed by schema rules.
286 if ( oc_check_op_attr( t ) ) {
290 /* check that the type appears as req or opt in at least one oc */
291 for ( i = 0; ocl[i] != NULL; i++ ) {
292 /* if we know about the oc */
293 if ( (oc = oc_find( ocl[i]->bv_val )) != NULL ) {
294 /* does it require the type? */
295 for ( j = 0; oc->soc_required != NULL &&
296 oc->soc_required[j] != NULL; j++ ) {
297 at = oc->soc_required[j];
299 strcmp(at->sat_oid, t ) == 0 ) {
308 if ( strcasecmp( *pp, t ) == 0 ) {
316 /* does it allow the type? */
317 for ( j = 0; oc->soc_allowed != NULL &&
318 oc->soc_allowed[j] != NULL; j++ ) {
319 at = oc->soc_allowed[j];
321 strcmp( at->sat_oid, t ) == 0 ) {
330 if ( strcasecmp( *pp, t ) == 0 ||
331 strcmp( *pp, "*" ) == 0 ) {
339 /* maybe the next oc allows it */
341 #ifdef OC_UNDEFINED_IMPLES_EXTENSIBLE
342 /* we don't know about the oc. assume it allows it */
353 /* not allowed by any oc */
362 static Avlnode *oc_index = NULL;
363 static ObjectClass *oc_list = NULL;
367 struct oindexrec *oir1,
368 struct oindexrec *oir2
371 return (strcasecmp( oir1->oir_name, oir2->oir_name ));
377 struct oindexrec *oir
380 return (strcasecmp( name, oir->oir_name ));
384 oc_find( const char *ocname )
386 struct oindexrec *oir = NULL;
388 if ( (oir = (struct oindexrec *) avl_find( oc_index, ocname,
389 (AVL_CMP) oc_index_name_cmp )) != NULL ) {
390 return( oir->oir_oc );
404 AttributeType **satp;
410 sat = at_find(*attrs1);
413 return SLAP_SCHERR_ATTR_NOT_FOUND;
415 if ( at_find_in_list(sat, soc->soc_required) < 0) {
416 if ( at_append_to_list(sat, &soc->soc_required) ) {
418 return SLAP_SCHERR_OUTOFMEM;
423 /* Now delete duplicates from the allowed list */
424 for ( satp = soc->soc_required; *satp; satp++ ) {
425 i = at_find_in_list(*satp,soc->soc_allowed);
427 at_delete_from_list(i, &soc->soc_allowed);
447 sat = at_find(*attrs1);
450 return SLAP_SCHERR_ATTR_NOT_FOUND;
452 if ( at_find_in_list(sat, soc->soc_required) < 0 &&
453 at_find_in_list(sat, soc->soc_allowed) < 0 ) {
454 if ( at_append_to_list(sat, &soc->soc_allowed) ) {
456 return SLAP_SCHERR_OUTOFMEM;
479 if ( !soc->soc_sups ) {
480 /* We are at the first recursive level */
489 soc->soc_sups = (ObjectClass **)ch_calloc(1,
490 nsups*sizeof(ObjectClass *));
495 soc1 = oc_find(*sups1);
498 return SLAP_SCHERR_CLASS_NOT_FOUND;
502 soc->soc_sups[nsups] = soc1;
504 code = oc_add_sups(soc,soc1->soc_sup_oids, err);
508 code = oc_create_required(soc,soc1->soc_at_oids_must,err);
511 code = oc_create_allowed(soc,soc1->soc_at_oids_may,err);
529 struct oindexrec *oir;
533 while ( *ocp != NULL ) {
534 ocp = &(*ocp)->soc_next;
538 if ( soc->soc_oid ) {
539 oir = (struct oindexrec *)
540 ch_calloc( 1, sizeof(struct oindexrec) );
541 oir->oir_name = soc->soc_oid;
543 if ( avl_insert( &oc_index, (caddr_t) oir,
544 (AVL_CMP) oc_index_cmp,
545 (AVL_DUP) avl_dup_error ) ) {
548 return SLAP_SCHERR_DUP_CLASS;
550 /* FIX: temporal consistency check */
551 oc_find(oir->oir_name);
553 if ( (names = soc->soc_names) ) {
555 oir = (struct oindexrec *)
556 ch_calloc( 1, sizeof(struct oindexrec) );
557 oir->oir_name = ch_strdup(*names);
559 if ( avl_insert( &oc_index, (caddr_t) oir,
560 (AVL_CMP) oc_index_cmp,
561 (AVL_DUP) avl_dup_error ) ) {
564 return SLAP_SCHERR_DUP_CLASS;
566 /* FIX: temporal consistency check */
567 oc_find(oir->oir_name);
576 LDAP_OBJECT_CLASS *oc,
583 soc = (ObjectClass *) ch_calloc( 1, sizeof(ObjectClass) );
584 memcpy( &soc->soc_oclass, oc, sizeof(LDAP_OBJECT_CLASS));
585 if ( (code = oc_add_sups(soc,soc->soc_sup_oids,err)) != 0 )
587 if ( (code = oc_create_required(soc,soc->soc_at_oids_must,err)) != 0 )
589 if ( (code = oc_create_allowed(soc,soc->soc_at_oids_may,err)) != 0 )
591 code = oc_insert(soc,err);
600 static Avlnode *syn_index = NULL;
601 static Syntax *syn_list = NULL;
605 struct sindexrec *sir1,
606 struct sindexrec *sir2
609 return (strcmp( sir1->sir_name, sir2->sir_name ));
615 struct sindexrec *sir
618 return (strcmp( name, sir->sir_name ));
622 syn_find( const char *synname )
624 struct sindexrec *sir = NULL;
626 if ( (sir = (struct sindexrec *) avl_find( syn_index, synname,
627 (AVL_CMP) syn_index_name_cmp )) != NULL ) {
628 return( sir->sir_syn );
634 syn_find_desc( const char *syndesc, int *len )
638 for (synp = syn_list; synp; synp = synp->ssyn_next)
639 if ((*len = dscompare( synp->ssyn_syn.syn_desc, syndesc, '{')))
651 struct sindexrec *sir;
654 while ( *synp != NULL ) {
655 synp = &(*synp)->ssyn_next;
659 if ( ssyn->ssyn_oid ) {
660 sir = (struct sindexrec *)
661 ch_calloc( 1, sizeof(struct sindexrec) );
662 sir->sir_name = ssyn->ssyn_oid;
664 if ( avl_insert( &syn_index, (caddr_t) sir,
665 (AVL_CMP) syn_index_cmp,
666 (AVL_DUP) avl_dup_error ) ) {
667 *err = ssyn->ssyn_oid;
669 return SLAP_SCHERR_DUP_SYNTAX;
671 /* FIX: temporal consistency check */
672 syn_find(sir->sir_name);
680 slap_syntax_validate_func *validate,
681 slap_syntax_transform_func *ber2str,
682 slap_syntax_transform_func *str2ber,
689 ssyn = (Syntax *) ch_calloc( 1, sizeof(Syntax) );
690 memcpy( &ssyn->ssyn_syn, syn, sizeof(LDAP_SYNTAX));
692 ssyn->ssyn_validate = validate;
693 ssyn->ssyn_ber2str = ber2str;
694 ssyn->ssyn_str2ber = str2ber;
696 code = syn_insert(ssyn,err);
702 MatchingRule *mir_mr;
705 static Avlnode *mr_index = NULL;
706 static MatchingRule *mr_list = NULL;
710 struct mindexrec *mir1,
711 struct mindexrec *mir2
714 return (strcmp( mir1->mir_name, mir2->mir_name ));
720 struct mindexrec *mir
723 return (strcmp( name, mir->mir_name ));
727 mr_find( const char *mrname )
729 struct mindexrec *mir = NULL;
731 if ( (mir = (struct mindexrec *) avl_find( mr_index, mrname,
732 (AVL_CMP) mr_index_name_cmp )) != NULL ) {
733 return( mir->mir_mr );
745 struct mindexrec *mir;
749 while ( *mrp != NULL ) {
750 mrp = &(*mrp)->smr_next;
754 if ( smr->smr_oid ) {
755 mir = (struct mindexrec *)
756 ch_calloc( 1, sizeof(struct mindexrec) );
757 mir->mir_name = smr->smr_oid;
759 if ( avl_insert( &mr_index, (caddr_t) mir,
760 (AVL_CMP) mr_index_cmp,
761 (AVL_DUP) avl_dup_error ) ) {
764 return SLAP_SCHERR_DUP_RULE;
766 /* FIX: temporal consistency check */
767 mr_find(mir->mir_name);
769 if ( (names = smr->smr_names) ) {
771 mir = (struct mindexrec *)
772 ch_calloc( 1, sizeof(struct mindexrec) );
773 mir->mir_name = ch_strdup(*names);
775 if ( avl_insert( &mr_index, (caddr_t) mir,
776 (AVL_CMP) mr_index_cmp,
777 (AVL_DUP) avl_dup_error ) ) {
780 return SLAP_SCHERR_DUP_RULE;
782 /* FIX: temporal consistency check */
783 mr_find(mir->mir_name);
792 LDAP_MATCHING_RULE *mr,
793 slap_mr_convert_func *convert,
794 slap_mr_normalize_func *normalize,
795 slap_mr_match_func *match,
803 smr = (MatchingRule *) ch_calloc( 1, sizeof(MatchingRule) );
804 memcpy( &smr->smr_mrule, mr, sizeof(LDAP_MATCHING_RULE));
806 smr->smr_convert = convert;
807 smr->smr_normalize = normalize;
808 smr->smr_match = match;
810 if ( smr->smr_syntax_oid ) {
811 if ( (syn = syn_find(smr->smr_syntax_oid)) ) {
812 smr->smr_syntax = syn;
814 *err = smr->smr_syntax_oid;
815 return SLAP_SCHERR_SYN_NOT_FOUND;
819 return SLAP_SCHERR_MR_INCOMPLETE;
821 code = mr_insert(smr,err);
830 /* any value allowed */
841 unsigned char *u = in->bv_val;
843 for( count = in->bv_len; count > 0; count+=len, u+=len ) {
844 /* get the length indicated by the first byte */
845 len = LDAP_UTF8_CHARLEN( u );
847 /* should not be zero */
848 if( len == 0 ) return -1;
850 /* make sure len corresponds with the offset
851 to the next character */
852 if( LDAP_UTF8_OFFSET( u ) != len ) return -1;
855 if( count != 0 ) return -1;
865 struct berval **normalized )
867 struct berval *newval;
870 newval = ch_malloc( sizeof( struct berval ) );
874 /* Ignore initial whitespace */
875 while ( ldap_utf8_isspace( p ) ) {
884 newval->bv_val = ch_strdup( p );
885 p = q = newval->bv_val;
891 if ( ldap_utf8_isspace( p ) ) {
892 len = LDAP_UTF8_COPY(q,p);
897 /* Ignore the extra whitespace */
898 while ( ldap_utf8_isspace( p ) ) {
902 len = LDAP_UTF8_COPY(q,p);
909 assert( *newval->bv_val );
910 assert( newval->bv_val < p );
913 /* cannot start with a space */
914 assert( !ldap_utf8_isspace(newval->bv_val) );
917 * If the string ended in space, backup the pointer one
918 * position. One is enough because the above loop collapsed
919 * all whitespace to a single space.
926 /* cannot end with a space */
927 assert( !ldap_utf8_isspace( LDAP_UTF8_PREV(q) ) );
932 newval->bv_len = q - newval->bv_val;
933 normalized = &newval;
945 for(i=0; i < val->bv_len; i++) {
946 if( !isascii(val->bv_val[i]) ) return -1;
956 struct berval **out )
959 struct berval *bv = ch_malloc( sizeof(struct berval) );
960 bv->bv_len = (in->bv_len+1) * sizeof( ldap_unicode_t );
961 bv->bv_val = ch_malloc( bv->bv_len );
963 for(i=0; i < in->bv_len; i++ ) {
965 * IA5StringValidate should have been called to ensure
966 * input is limited to IA5.
968 bv->bv_val[i] = in->bv_val[i];
980 struct berval **normalized )
982 struct berval *newval;
985 newval = ch_malloc( sizeof( struct berval ) );
989 /* Ignore initial whitespace */
990 while ( isspace( *p++ ) ) {
999 newval->bv_val = ch_strdup( p );
1000 p = q = newval->bv_val;
1003 if ( isspace( *p ) ) {
1006 /* Ignore the extra whitespace */
1007 while ( isspace( *p++ ) ) {
1015 assert( *newval->bv_val );
1016 assert( newval->bv_val < p );
1019 /* cannot start with a space */
1020 assert( !isspace(*newval->bv_val) );
1023 * If the string ended in space, backup the pointer one
1024 * position. One is enough because the above loop collapsed
1025 * all whitespace to a single space.
1028 if ( isspace( q[-1] ) ) {
1032 /* cannot end with a space */
1033 assert( !isspace( q[-1] ) );
1035 /* null terminate */
1038 newval->bv_len = q - newval->bv_val;
1039 normalized = &newval;
1048 struct berval *value,
1049 struct berval *assertedValue )
1051 return strcmp( value->bv_val, assertedValue->bv_val );
1058 struct berval *value,
1059 struct berval *assertedValue )
1061 return strcasecmp( value->bv_val, assertedValue->bv_val );
1067 slap_syntax_validate_func *validate,
1068 slap_syntax_transform_func *ber2str,
1069 slap_syntax_transform_func *str2ber )
1075 syn = ldap_str2syntax( desc, &code, &err);
1077 Debug( LDAP_DEBUG_ANY, "Error in register_syntax: %s before %s in %s\n",
1078 ldap_scherr2str(code), err, desc );
1082 code = syn_add( syn, validate, ber2str, str2ber, &err );
1084 Debug( LDAP_DEBUG_ANY, "Error in register_syntax: %s %s in %s\n",
1085 scherr2str(code), err, desc );
1093 register_matching_rule(
1095 slap_mr_convert_func *convert,
1096 slap_mr_normalize_func *normalize,
1097 slap_mr_match_func *match )
1099 LDAP_MATCHING_RULE *mr;
1103 mr = ldap_str2matchingrule( desc, &code, &err);
1105 Debug( LDAP_DEBUG_ANY, "Error in register_matching_rule: %s before %s in %s\n",
1106 ldap_scherr2str(code), err, desc );
1110 code = mr_add( mr, convert, normalize, match, &err );
1112 Debug( LDAP_DEBUG_ANY, "Error in register_syntax: %s for %s in %s\n",
1113 scherr2str(code), err, desc );
1119 struct syntax_defs_rec {
1121 slap_syntax_validate_func *sd_validate;
1122 slap_syntax_transform_func *sd_ber2str;
1123 slap_syntax_transform_func *sd_str2ber;
1126 struct syntax_defs_rec syntax_defs[] = {
1127 {"( 1.3.6.1.4.1.1466.115.121.1.3 DESC 'AttributeTypeDescription' )",
1129 {"( 1.3.6.1.4.1.1466.115.121.1.4 DESC 'Audio' )",
1131 {"( 1.3.6.1.4.1.1466.115.121.1.5 DESC 'Binary' )",
1133 {"( 1.3.6.1.4.1.1466.115.121.1.6 DESC 'BitString' )",
1135 {"( 1.3.6.1.4.1.1466.115.121.1.7 DESC 'Boolean' )",
1137 {"( 1.3.6.1.4.1.1466.115.121.1.8 DESC 'Certificate' )",
1139 {"( 1.3.6.1.4.1.1466.115.121.1.9 DESC 'CertificateList' )",
1141 {"( 1.3.6.1.4.1.1466.115.121.1.10 DESC 'CertificatePair' )",
1143 {"( 1.3.6.1.4.1.1466.115.121.1.12 DESC 'DN' )",
1145 {"( 1.3.6.1.4.1.1466.115.121.1.14 DESC 'DeliveryMethod' )",
1147 {"( 1.3.6.1.4.1.1466.115.121.1.15 DESC 'DirectoryString' )",
1148 UTF8StringValidate, NULL, NULL},
1149 {"( 1.3.6.1.4.1.1466.115.121.1.16 DESC 'DITContentRuleDescription' )",
1151 {"( 1.3.6.1.4.1.1466.115.121.1.17 DESC 'DITStructureRuleDescription' )",
1153 {"( 1.3.6.1.4.1.1466.115.121.1.21 DESC 'EnhancedGuide' )",
1155 {"( 1.3.6.1.4.1.1466.115.121.1.22 DESC 'FacsimileTelephoneNumber' )",
1157 {"( 1.3.6.1.4.1.1466.115.121.1.24 DESC 'GeneralizedTime' )",
1159 {"( 1.3.6.1.4.1.1466.115.121.1.25 DESC 'Guide' )",
1161 {"( 1.3.6.1.4.1.1466.115.121.1.26 DESC 'IA5String' )",
1162 IA5StringValidate, NULL, NULL},
1163 {"( 1.3.6.1.4.1.1466.115.121.1.27 DESC 'Integer' )",
1165 {"( 1.3.6.1.4.1.1466.115.121.1.28 DESC 'JPEG' )",
1167 {"( 1.3.6.1.4.1.1466.115.121.1.30 DESC 'MatchingRuleDescription' )",
1169 {"( 1.3.6.1.4.1.1466.115.121.1.31 DESC 'MatchingRuleUseDescription' )",
1171 {"( 1.3.6.1.4.1.1466.115.121.1.32 DESC 'MailPreference' )",
1173 {"( 1.3.6.1.4.1.1466.115.121.1.34 DESC 'NameAndOptionalUID' )",
1175 {"( 1.3.6.1.4.1.1466.115.121.1.35 DESC 'NameFormDescription' )",
1177 {"( 1.3.6.1.4.1.1466.115.121.1.36 DESC 'NumericString' )",
1179 {"( 1.3.6.1.4.1.1466.115.121.1.37 DESC 'ObjectClassDescription' )",
1181 {"( 1.3.6.1.4.1.1466.115.121.1.38 DESC 'OID' )",
1183 {"( 1.3.6.1.4.1.1466.115.121.1.39 DESC 'OtherMailbox' )",
1185 {"( 1.3.6.1.4.1.1466.115.121.1.40 DESC 'OctetString' )",
1186 octetStringValidate, NULL, NULL},
1187 {"( 1.3.6.1.4.1.1466.115.121.1.41 DESC 'PostalAddress' )",
1189 {"( 1.3.6.1.4.1.1466.115.121.1.42 DESC 'ProtocolInformation' )",
1191 {"( 1.3.6.1.4.1.1466.115.121.1.43 DESC 'PresentationAddress' )",
1193 {"( 1.3.6.1.4.1.1466.115.121.1.44 DESC 'PrintableString' )",
1195 {"( 1.3.6.1.4.1.1466.115.121.1.49 DESC 'SupportedAlgorithm' )",
1197 {"( 1.3.6.1.4.1.1466.115.121.1.50 DESC 'TelephoneNumber' )",
1199 {"( 1.3.6.1.4.1.1466.115.121.1.51 DESC 'TeletexTerminalIdentifier' )",
1201 {"( 1.3.6.1.4.1.1466.115.121.1.52 DESC 'TelexNumber' )",
1203 {"( 1.3.6.1.4.1.1466.115.121.1.53 DESC 'UTCTime' )",
1205 {"( 1.3.6.1.4.1.1466.115.121.1.54 DESC 'LDAPSyntaxDescription' )",
1207 {"( 1.3.6.1.4.1.1466.115.121.1.58 DESC 'SubstringAssertion' )",
1213 struct mrule_defs_rec {
1215 slap_mr_convert_func *mrd_convert;
1216 slap_mr_normalize_func *mrd_normalize;
1217 slap_mr_match_func *mrd_match;
1221 * Other matching rules in X.520 that we do not use:
1223 * 2.5.13.9 numericStringOrderingMatch
1224 * 2.5.13.12 caseIgnoreListSubstringsMatch
1225 * 2.5.13.13 booleanMatch
1226 * 2.5.13.15 integerOrderingMatch
1227 * 2.5.13.18 octetStringOrderingMatch
1228 * 2.5.13.19 octetStringSubstringsMatch
1229 * 2.5.13.25 uTCTimeMatch
1230 * 2.5.13.26 uTCTimeOrderingMatch
1231 * 2.5.13.31 directoryStringFirstComponentMatch
1232 * 2.5.13.32 wordMatch
1233 * 2.5.13.33 keywordMatch
1234 * 2.5.13.34 certificateExactMatch
1235 * 2.5.13.35 certificateMatch
1236 * 2.5.13.36 certificatePairExactMatch
1237 * 2.5.13.37 certificatePairMatch
1238 * 2.5.13.38 certificateListExactMatch
1239 * 2.5.13.39 certificateListMatch
1240 * 2.5.13.40 algorithmIdentifierMatch
1241 * 2.5.13.41 storedPrefixMatch
1242 * 2.5.13.42 attributeCertificateMatch
1243 * 2.5.13.43 readerAndKeyIDMatch
1244 * 2.5.13.44 attributeIntegrityMatch
1247 /* recycled matching functions */
1248 #define caseIgnoreMatch caseIgnoreIA5Match
1249 #define caseExactMatch caseExactIA5Match
1251 /* unimplemented matching functions */
1252 #define objectIdentifierMatch NULL
1253 #define distinguishedNameMatch NULL
1254 #define caseIgnoreOrderingMatch NULL
1255 #define caseIgnoreSubstringsMatch NULL
1256 #define caseExactOrderingMatch NULL
1257 #define caseExactSubstringsMatch NULL
1258 #define numericStringMatch NULL
1259 #define numericStringSubstringsMatch NULL
1260 #define caseIgnoreListMatch NULL
1261 #define integerMatch NULL
1262 #define bitStringMatch NULL
1263 #define octetStringMatch NULL
1264 #define telephoneNumberMatch NULL
1265 #define telephoneNumberSubstringsMatch NULL
1266 #define presentationAddressMatch NULL
1267 #define uniqueMemberMatch NULL
1268 #define protocolInformationMatch NULL
1269 #define generalizedTimeMatch NULL
1270 #define generalizedTimeOrderingMatch NULL
1271 #define integerFirstComponentMatch NULL
1272 #define objectIdentifierFirstComponentMatch NULL
1273 #define caseIgnoreIA5SubstringsMatch NULL
1275 struct mrule_defs_rec mrule_defs[] = {
1276 {"( 2.5.13.0 NAME 'objectIdentifierMatch' "
1277 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.38 )",
1278 NULL, NULL, objectIdentifierMatch},
1280 {"( 2.5.13.1 NAME 'distinguishedNameMatch' "
1281 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.12 )",
1282 NULL, NULL, distinguishedNameMatch},
1284 {"( 2.5.13.2 NAME 'caseIgnoreMatch' "
1285 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 )",
1286 NULL, UTF8StringNormalize, caseIgnoreMatch},
1288 {"( 2.5.13.3 NAME 'caseIgnoreOrderingMatch' "
1289 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 )",
1290 NULL, UTF8StringNormalize, caseIgnoreOrderingMatch},
1292 {"( 2.5.13.4 NAME 'caseIgnoreSubstringsMatch' "
1293 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.58 )",
1294 NULL, UTF8StringNormalize, caseIgnoreSubstringsMatch},
1296 /* Next three are not in the RFC's, but are needed for compatibility */
1297 {"( 2.5.13.5 NAME 'caseExactMatch' "
1298 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 )",
1299 NULL, UTF8StringNormalize, caseExactMatch},
1301 {"( 2.5.13.6 NAME 'caseExactOrderingMatch' "
1302 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 )",
1303 NULL, UTF8StringNormalize, caseExactOrderingMatch},
1305 {"( 2.5.13.7 NAME 'caseExactSubstringsMatch' "
1306 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.58 )",
1307 NULL, UTF8StringNormalize, caseExactSubstringsMatch},
1309 {"( 2.5.13.8 NAME 'numericStringMatch' "
1310 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.36 )",
1311 NULL, NULL, numericStringMatch},
1313 {"( 2.5.13.10 NAME 'numericStringSubstringsMatch' "
1314 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.58 )",
1315 NULL, NULL, numericStringSubstringsMatch},
1317 {"( 2.5.13.11 NAME 'caseIgnoreListMatch' "
1318 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.41 )",
1319 NULL, NULL, caseIgnoreListMatch},
1321 {"( 2.5.13.14 NAME 'integerMatch' "
1322 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.27 )",
1323 NULL, NULL, integerMatch},
1325 {"( 2.5.13.16 NAME 'bitStringMatch' "
1326 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.6 )",
1327 NULL, NULL, bitStringMatch},
1329 {"( 2.5.13.17 NAME 'octetStringMatch' "
1330 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.40 )",
1331 NULL, NULL, octetStringMatch},
1333 {"( 2.5.13.20 NAME 'telephoneNumberMatch' "
1334 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.50 )",
1335 NULL, NULL, telephoneNumberMatch},
1337 {"( 2.5.13.21 NAME 'telephoneNumberSubstringsMatch' "
1338 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.58 )",
1339 NULL, NULL, telephoneNumberSubstringsMatch},
1341 {"( 2.5.13.22 NAME 'presentationAddressMatch' "
1342 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.43 )",
1343 NULL, NULL, presentationAddressMatch},
1345 {"( 2.5.13.23 NAME 'uniqueMemberMatch' "
1346 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.34 )",
1347 NULL, NULL, uniqueMemberMatch},
1349 {"( 2.5.13.24 NAME 'protocolInformationMatch' "
1350 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.42 )",
1351 NULL, NULL, protocolInformationMatch},
1353 {"( 2.5.13.27 NAME 'generalizedTimeMatch' "
1354 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.24 )",
1355 NULL, NULL, generalizedTimeMatch},
1357 {"( 2.5.13.28 NAME 'generalizedTimeOrderingMatch' "
1358 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.24 )",
1359 NULL, NULL, generalizedTimeOrderingMatch},
1361 {"( 2.5.13.29 NAME 'integerFirstComponentMatch' "
1362 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.27 )",
1363 NULL, NULL, integerFirstComponentMatch},
1365 {"( 2.5.13.30 NAME 'objectIdentifierFirstComponentMatch' "
1366 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.38 )",
1367 NULL, NULL, objectIdentifierFirstComponentMatch},
1369 {"( 1.3.6.1.4.1.1466.109.114.1 NAME 'caseExactIA5Match' "
1370 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.26 )",
1371 NULL, IA5StringNormalize, caseExactIA5Match},
1373 {"( 1.3.6.1.4.1.1466.109.114.2 NAME 'caseIgnoreIA5Match' "
1374 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.26 )",
1375 NULL, IA5StringNormalize, caseIgnoreIA5Match},
1377 {"( 1.3.6.1.4.1.1466.109.114.3 NAME 'caseIgnoreIA5SubstringsMatch' "
1378 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.26 )",
1379 NULL, IA5StringNormalize, caseIgnoreIA5SubstringsMatch},
1381 {NULL, NULL, NULL, NULL}
1389 static int schema_init_done = 0;
1391 /* We are called from read_config that is recursive */
1392 if ( schema_init_done )
1395 for ( i=0; syntax_defs[i].sd_desc != NULL; i++ ) {
1396 res = register_syntax( syntax_defs[i].sd_desc,
1397 syntax_defs[i].sd_validate,
1398 syntax_defs[i].sd_ber2str,
1399 syntax_defs[i].sd_str2ber );
1402 fprintf( stderr, "schema_init: Error registering syntax %s\n",
1403 syntax_defs[i].sd_desc );
1404 exit( EXIT_FAILURE );
1408 for ( i=0; mrule_defs[i].mrd_desc != NULL; i++ ) {
1409 res = register_matching_rule(
1410 mrule_defs[i].mrd_desc,
1411 mrule_defs[i].mrd_convert,
1412 mrule_defs[i].mrd_normalize,
1413 mrule_defs[i].mrd_match );
1417 "schema_init: Error registering matching rule %s\n",
1418 mrule_defs[i].mrd_desc );
1419 exit( EXIT_FAILURE );
1422 schema_init_done = 1;
1426 #if defined( SLAPD_SCHEMA_DN )
1429 syn_schema_info( Entry *e )
1432 struct berval *vals[2];
1438 for ( syn = syn_list; syn; syn = syn->ssyn_next ) {
1439 val.bv_val = ldap_syntax2str( &syn->ssyn_syn );
1441 val.bv_len = strlen( val.bv_val );
1442 Debug( LDAP_DEBUG_TRACE, "Merging syn [%ld] %s\n",
1443 (long) val.bv_len, val.bv_val, 0 );
1444 attr_merge( e, "ldapSyntaxes", vals );
1445 ldap_memfree( val.bv_val );
1454 mr_schema_info( Entry *e )
1457 struct berval *vals[2];
1463 for ( mr = mr_list; mr; mr = mr->smr_next ) {
1464 val.bv_val = ldap_matchingrule2str( &mr->smr_mrule );
1466 val.bv_len = strlen( val.bv_val );
1467 Debug( LDAP_DEBUG_TRACE, "Merging mr [%ld] %s\n",
1468 (long) val.bv_len, val.bv_val, 0 );
1469 attr_merge( e, "matchingRules", vals );
1470 ldap_memfree( val.bv_val );
1479 oc_schema_info( Entry *e )
1482 struct berval *vals[2];
1488 for ( oc = oc_list; oc; oc = oc->soc_next ) {
1489 val.bv_val = ldap_objectclass2str( &oc->soc_oclass );
1491 val.bv_len = strlen( val.bv_val );
1492 Debug( LDAP_DEBUG_TRACE, "Merging oc [%ld] %s\n",
1493 (long) val.bv_len, val.bv_val, 0 );
1494 attr_merge( e, "objectClasses", vals );
1495 ldap_memfree( val.bv_val );
1504 schema_info( Connection *conn, Operation *op, char **attrs, int attrsonly )
1508 struct berval *vals[2];
1513 e = (Entry *) ch_calloc( 1, sizeof(Entry) );
1516 e->e_dn = ch_strdup( SLAPD_SCHEMA_DN );
1517 e->e_ndn = ch_strdup( SLAPD_SCHEMA_DN );
1518 (void) dn_normalize( e->e_ndn );
1519 e->e_private = NULL;
1522 char *rdn = ch_strdup( SLAPD_SCHEMA_DN );
1523 val.bv_val = strchr( rdn, '=' );
1525 if( val.bv_val != NULL ) {
1527 val.bv_len = strlen( ++val.bv_val );
1529 attr_merge( e, rdn, vals );
1535 if ( syn_schema_info( e ) ) {
1536 /* Out of memory, do something about it */
1540 if ( mr_schema_info( e ) ) {
1541 /* Out of memory, do something about it */
1545 if ( at_schema_info( e ) ) {
1546 /* Out of memory, do something about it */
1550 if ( oc_schema_info( e ) ) {
1551 /* Out of memory, do something about it */
1557 val.bv_len = sizeof("top")-1;
1558 attr_merge( e, "objectClass", vals );
1560 val.bv_val = "LDAPsubentry";
1561 val.bv_len = sizeof("LDAPsubentry")-1;
1562 attr_merge( e, "objectClass", vals );
1564 val.bv_val = "subschema";
1565 val.bv_len = sizeof("subschema")-1;
1566 attr_merge( e, "objectClass", vals );
1568 val.bv_val = "extensibleObject";
1569 val.bv_len = sizeof("extensibleObject")-1;
1570 attr_merge( e, "objectClass", vals );
1572 send_search_entry( &backends[0], conn, op,
1573 e, attrs, attrsonly, NULL );
1574 send_search_result( conn, op, LDAP_SUCCESS,
1575 NULL, NULL, NULL, NULL, 1 );
1584 oc_print( ObjectClass *oc )
1589 printf( "objectclass %s\n", ldap_objectclass2name( &oc->soc_oclass ) );
1590 if ( oc->soc_required != NULL ) {
1591 mid = "\trequires ";
1592 for ( i = 0; oc->soc_required[i] != NULL; i++, mid = "," )
1593 printf( "%s%s", mid,
1594 ldap_attributetype2name( &oc->soc_required[i]->sat_atype ) );
1597 if ( oc->soc_allowed != NULL ) {
1599 for ( i = 0; oc->soc_allowed[i] != NULL; i++, mid = "," )
1600 printf( "%s%s", mid,
1601 ldap_attributetype2name( &oc->soc_allowed[i]->sat_atype ) );
1609 int is_entry_objectclass(
1616 if( e == NULL || oc == NULL || *oc == '\0' )
1620 * find objectClass attribute
1622 attr = attr_find(e->e_attrs, "objectclass");
1624 if( attr == NULL ) {
1625 /* no objectClass attribute */
1629 bv.bv_val = (char *) oc;
1630 bv.bv_len = strlen( bv.bv_val );
1632 #ifdef SLAPD_SCHEMA_COMPAT
1633 if( value_find(attr->a_vals, &bv, attr->a_syntax, 1) != 0) {
1634 /* entry is not of this objectclass */