1 /* schema.c - routines to enforce schema definitions */
11 #include "ldap_defaults.h"
14 static char * oc_check_required(Entry *e, char *ocname);
15 static int oc_check_allowed(char *type, struct berval **ocl);
18 * oc_check - check that entry e conforms to the schema required by
19 * its object class(es). returns 0 if so, non-zero otherwise.
23 oc_schema_check( Entry *e )
29 /* find the object class attribute - could error out here */
30 if ( (aoc = attr_find( e->e_attrs, "objectclass" )) == NULL ) {
31 Debug( LDAP_DEBUG_ANY, "No object class for entry (%s)\n",
36 /* check that the entry has required attrs for each oc */
37 for ( i = 0; aoc->a_vals[i] != NULL; i++ ) {
38 char *s = oc_check_required( e, aoc->a_vals[i]->bv_val );
41 Debug( LDAP_DEBUG_ANY,
42 "Entry (%s), oc \"%s\" requires attr \"%s\"\n",
43 e->e_dn, aoc->a_vals[i]->bv_val, s );
52 /* check that each attr in the entry is allowed by some oc */
53 for ( a = e->e_attrs; a != NULL; a = a->a_next ) {
54 if ( oc_check_allowed( a->a_type, aoc->a_vals ) != 0 ) {
55 Debug( LDAP_DEBUG_ANY,
56 "Entry (%s), attr \"%s\" not allowed\n",
57 e->e_dn, a->a_type, 0 );
66 oc_check_required( Entry *e, char *ocname )
74 Debug( LDAP_DEBUG_TRACE,
75 "oc_check_required entry (%s), objectclass \"%s\"\n",
78 /* find global oc defn. it we don't know about it assume it's ok */
79 if ( (oc = oc_find( ocname )) == NULL ) {
83 /* check for empty oc_required */
84 if(oc->soc_required == NULL) {
88 /* for each required attribute */
89 for ( i = 0; oc->soc_required[i] != NULL; i++ ) {
90 at = oc->soc_required[i];
91 /* see if it's in the entry */
92 for ( a = e->e_attrs; a != NULL; a = a->a_next ) {
94 strcmp( a->a_type, at->sat_oid ) == 0 ) {
99 /* Empty name list => not found */
104 if ( strcasecmp( a->a_type, *pp ) == 0 ) {
113 /* not there => schema violation */
115 if ( at->sat_names && at->sat_names[0] ) {
116 return at->sat_names[0];
126 static char *oc_usermod_attrs[] = {
128 * OpenLDAP doesn't support any user modification of
129 * operational attributes.
134 static char *oc_operational_attrs[] = {
136 * these are operational attributes that *could* be
137 * modified by users if we supported such.
151 /* this list should be extensible */
152 static char *oc_no_usermod_attrs[] = {
154 * Operational and 'no user modification' attributes
169 * check to see if attribute is 'operational' or not.
172 oc_check_operational_attr( char *type )
174 return charray_inlist( oc_operational_attrs, type )
175 || charray_inlist( oc_usermod_attrs, type )
176 || charray_inlist( oc_no_usermod_attrs, type );
180 * check to see if attribute can be user modified or not.
183 oc_check_usermod_attr( char *type )
185 return charray_inlist( oc_usermod_attrs, type );
189 * check to see if attribute is 'no user modification' or not.
192 oc_check_no_usermod_attr( char *type )
194 return charray_inlist( oc_no_usermod_attrs, type );
199 oc_check_allowed( char *type, struct berval **ocl )
206 Debug( LDAP_DEBUG_TRACE,
207 "oc_check_allowed type \"%s\"\n", type, 0, 0 );
209 /* always allow objectclass attribute */
210 if ( strcasecmp( type, "objectclass" ) == 0 ) {
215 * All operational attributions are allowed by schema rules.
216 * However, we only check attributions which are stored in the
217 * the directory regardless if they are user or non-user modified.
219 if ( oc_check_usermod_attr( type ) || oc_check_no_usermod_attr( type ) ) {
223 /* check that the type appears as req or opt in at least one oc */
224 for ( i = 0; ocl[i] != NULL; i++ ) {
225 /* if we know about the oc */
226 if ( (oc = oc_find( ocl[i]->bv_val )) != NULL ) {
227 /* does it require the type? */
228 for ( j = 0; oc->soc_required != NULL &&
229 oc->soc_required[j] != NULL; j++ ) {
230 at = oc->soc_required[j];
232 strcmp(at->sat_oid, type ) == 0 ) {
239 if ( strcasecmp( *pp, type ) == 0 ) {
245 /* does it allow the type? */
246 for ( j = 0; oc->soc_allowed != NULL &&
247 oc->soc_allowed[j] != NULL; j++ ) {
248 at = oc->soc_allowed[j];
250 strcmp(at->sat_oid, type ) == 0 ) {
257 if ( strcasecmp( *pp, type ) == 0 ||
258 strcmp( *pp, "*" ) == 0 ) {
264 /* maybe the next oc allows it */
266 /* we don't know about the oc. assume it allows it */
272 /* not allowed by any oc */
281 static Avlnode *oc_index = NULL;
282 static ObjectClass *oc_list = NULL;
286 struct oindexrec *oir1,
287 struct oindexrec *oir2
290 return (strcasecmp( oir1->oir_name, oir2->oir_name ));
296 struct oindexrec *oir
299 return (strcasecmp( name, oir->oir_name ));
303 oc_find( const char *ocname )
305 struct oindexrec *oir = NULL;
307 if ( (oir = (struct oindexrec *) avl_find( oc_index, ocname,
308 (AVL_CMP) oc_index_name_cmp )) != NULL ) {
309 return( oir->oir_oc );
323 AttributeType **satp;
329 sat = at_find(*attrs1);
332 return SLAP_SCHERR_ATTR_NOT_FOUND;
334 if ( at_find_in_list(sat, soc->soc_required) < 0) {
335 if ( at_append_to_list(sat, &soc->soc_required) ) {
337 return SLAP_SCHERR_OUTOFMEM;
342 /* Now delete duplicates from the allowed list */
343 for ( satp = soc->soc_required; *satp; satp++ ) {
344 i = at_find_in_list(*satp,soc->soc_allowed);
346 at_delete_from_list(i, &soc->soc_allowed);
366 sat = at_find(*attrs1);
369 return SLAP_SCHERR_ATTR_NOT_FOUND;
371 if ( at_find_in_list(sat, soc->soc_required) < 0 &&
372 at_find_in_list(sat, soc->soc_allowed) < 0 ) {
373 if ( at_append_to_list(sat, &soc->soc_allowed) ) {
375 return SLAP_SCHERR_OUTOFMEM;
398 if ( !soc->soc_sups ) {
399 /* We are at the first recursive level */
408 soc->soc_sups = (ObjectClass **)ch_calloc(1,
409 nsups*sizeof(ObjectClass *));
414 soc1 = oc_find(*sups1);
417 return SLAP_SCHERR_CLASS_NOT_FOUND;
421 soc->soc_sups[nsups] = soc1;
423 code = oc_add_sups(soc,soc1->soc_sup_oids, err);
427 if ( code = oc_create_required(soc,
428 soc1->soc_at_oids_must,err) )
430 if ( code = oc_create_allowed(soc,
431 soc1->soc_at_oids_may,err) )
447 struct oindexrec *oir;
451 while ( *ocp != NULL ) {
452 ocp = &(*ocp)->soc_next;
456 if ( soc->soc_oid ) {
457 oir = (struct oindexrec *)
458 ch_calloc( 1, sizeof(struct oindexrec) );
459 oir->oir_name = soc->soc_oid;
461 if ( avl_insert( &oc_index, (caddr_t) oir,
462 (AVL_CMP) oc_index_cmp,
463 (AVL_DUP) avl_dup_error ) ) {
466 return SLAP_SCHERR_DUP_CLASS;
468 /* FIX: temporal consistency check */
469 oc_find(oir->oir_name);
471 if ( (names = soc->soc_names) ) {
473 oir = (struct oindexrec *)
474 ch_calloc( 1, sizeof(struct oindexrec) );
475 oir->oir_name = ch_strdup(*names);
477 if ( avl_insert( &oc_index, (caddr_t) oir,
478 (AVL_CMP) oc_index_cmp,
479 (AVL_DUP) avl_dup_error ) ) {
482 return SLAP_SCHERR_DUP_CLASS;
484 /* FIX: temporal consistency check */
485 oc_find(oir->oir_name);
494 LDAP_OBJECT_CLASS *oc,
501 soc = (ObjectClass *) ch_calloc( 1, sizeof(ObjectClass) );
502 memcpy( &soc->soc_oclass, oc, sizeof(LDAP_OBJECT_CLASS));
503 if ( code = oc_add_sups(soc,soc->soc_sup_oids,err) )
505 if ( code = oc_create_required(soc,soc->soc_at_oids_must,err) )
507 if ( code = oc_create_allowed(soc,soc->soc_at_oids_may,err) )
509 code = oc_insert(soc,err);
518 static Avlnode *syn_index = NULL;
519 static Syntax *syn_list = NULL;
523 struct sindexrec *sir1,
524 struct sindexrec *sir2
527 return (strcmp( sir1->sir_name, sir2->sir_name ));
533 struct sindexrec *sir
536 return (strcmp( name, sir->sir_name ));
540 syn_find( const char *synname )
542 struct sindexrec *sir = NULL;
544 if ( (sir = (struct sindexrec *) avl_find( syn_index, synname,
545 (AVL_CMP) syn_index_name_cmp )) != NULL ) {
546 return( sir->sir_syn );
558 struct sindexrec *sir;
561 while ( *synp != NULL ) {
562 synp = &(*synp)->ssyn_next;
566 if ( ssyn->ssyn_oid ) {
567 sir = (struct sindexrec *)
568 ch_calloc( 1, sizeof(struct sindexrec) );
569 sir->sir_name = ssyn->ssyn_oid;
571 if ( avl_insert( &syn_index, (caddr_t) sir,
572 (AVL_CMP) syn_index_cmp,
573 (AVL_DUP) avl_dup_error ) ) {
574 *err = ssyn->ssyn_oid;
576 return SLAP_SCHERR_DUP_SYNTAX;
578 /* FIX: temporal consistency check */
579 syn_find(sir->sir_name);
587 slap_syntax_check_func *check,
594 ssyn = (Syntax *) ch_calloc( 1, sizeof(Syntax) );
595 memcpy( &ssyn->ssyn_syn, syn, sizeof(LDAP_SYNTAX));
596 ssyn->ssyn_check = check;
597 code = syn_insert(ssyn,err);
603 MatchingRule *mir_mr;
606 static Avlnode *mr_index = NULL;
607 static MatchingRule *mr_list = NULL;
611 struct mindexrec *mir1,
612 struct mindexrec *mir2
615 return (strcmp( mir1->mir_name, mir2->mir_name ));
621 struct mindexrec *mir
624 return (strcmp( name, mir->mir_name ));
628 mr_find( const char *mrname )
630 struct mindexrec *mir = NULL;
632 if ( (mir = (struct mindexrec *) avl_find( mr_index, mrname,
633 (AVL_CMP) mr_index_name_cmp )) != NULL ) {
634 return( mir->mir_mr );
646 struct mindexrec *mir;
650 while ( *mrp != NULL ) {
651 mrp = &(*mrp)->smr_next;
655 if ( smr->smr_oid ) {
656 mir = (struct mindexrec *)
657 ch_calloc( 1, sizeof(struct mindexrec) );
658 mir->mir_name = smr->smr_oid;
660 if ( avl_insert( &mr_index, (caddr_t) mir,
661 (AVL_CMP) mr_index_cmp,
662 (AVL_DUP) avl_dup_error ) ) {
665 return SLAP_SCHERR_DUP_RULE;
667 /* FIX: temporal consistency check */
668 mr_find(mir->mir_name);
670 if ( (names = smr->smr_names) ) {
672 mir = (struct mindexrec *)
673 ch_calloc( 1, sizeof(struct mindexrec) );
674 mir->mir_name = ch_strdup(*names);
676 if ( avl_insert( &mr_index, (caddr_t) mir,
677 (AVL_CMP) mr_index_cmp,
678 (AVL_DUP) avl_dup_error ) ) {
681 return SLAP_SCHERR_DUP_RULE;
683 /* FIX: temporal consistency check */
684 mr_find(mir->mir_name);
693 LDAP_MATCHING_RULE *mr,
694 slap_mr_normalize_func *normalize,
695 slap_mr_compare_func *compare,
703 smr = (MatchingRule *) ch_calloc( 1, sizeof(MatchingRule) );
704 memcpy( &smr->smr_mrule, mr, sizeof(LDAP_MATCHING_RULE));
705 smr->smr_normalize = normalize;
706 smr->smr_compare = compare;
707 if ( smr->smr_syntax_oid ) {
708 if ( (syn = syn_find(smr->smr_syntax_oid)) ) {
709 smr->smr_syntax = syn;
711 *err = smr->smr_syntax_oid;
712 return SLAP_SCHERR_SYN_NOT_FOUND;
716 return SLAP_SCHERR_MR_INCOMPLETE;
718 code = mr_insert(smr,err);
723 case_exact_normalize(
725 struct berval **normalized
728 struct berval *newval;
731 newval = ber_bvdup( val );
732 p = q = newval->bv_val;
733 /* Ignore initial whitespace */
734 while ( isspace( *p++ ) )
737 if ( isspace( *p ) ) {
739 /* Ignore the extra whitespace */
740 while ( isspace(*p++) )
747 * If the string ended in space, backup the pointer one
748 * position. One is enough because the above loop collapsed
749 * all whitespace to a single space.
751 if ( p != newval->bv_val && isspace( *(p-1) ) ) {
754 newval->bv_len = strlen( newval->bv_val );
755 normalized = &newval;
766 return strcmp( val1->bv_val, val2->bv_val );
770 case_ignore_normalize(
772 struct berval **normalized
775 struct berval *newval;
778 newval = ber_bvdup( val );
779 p = q = newval->bv_val;
780 /* Ignore initial whitespace */
781 while ( isspace( *p++ ) )
784 if ( isspace( *p ) ) {
786 /* Ignore the extra whitespace */
787 while ( isspace(*p++) )
790 *q++ = TOUPPER( *p++ );
794 * If the string ended in space, backup the pointer one
795 * position. One is enough because the above loop collapsed
796 * all whitespace to a single space.
798 if ( p != newval->bv_val && isspace( *(p-1) ) ) {
801 newval->bv_len = strlen( newval->bv_val );
802 normalized = &newval;
813 return strcasecmp( val1->bv_val, val2->bv_val );
819 slap_syntax_check_func *check )
825 syn = ldap_str2syntax( desc, &code, &err);
827 Debug( LDAP_DEBUG_ANY, "Error in register_syntax: %s before %s in %s\n",
828 ldap_scherr2str(code), err, desc );
831 code = syn_add( syn, check, &err );
833 Debug( LDAP_DEBUG_ANY, "Error in register_syntax: %s %s in %s\n",
834 scherr2str(code), err, desc );
841 register_matching_rule(
843 slap_mr_normalize_func *normalize,
844 slap_mr_compare_func *compare )
846 LDAP_MATCHING_RULE *mr;
850 mr = ldap_str2matchingrule( desc, &code, &err);
852 Debug( LDAP_DEBUG_ANY, "Error in register_matching_rule: %s before %s in %s\n",
853 ldap_scherr2str(code), err, desc );
856 code = mr_add( mr, normalize, compare, &err );
858 Debug( LDAP_DEBUG_ANY, "Error in register_syntax: %s for %s in %s\n",
859 scherr2str(code), err, desc );
865 struct syntax_defs_rec {
867 slap_syntax_check_func *sd_check;
870 struct syntax_defs_rec syntax_defs[] = {
871 {"( 1.3.6.1.4.1.1466.115.121.1.3 DESC 'Attribute Type Description' )", NULL},
872 {"( 1.3.6.1.4.1.1466.115.121.1.4 DESC 'Audio' )", NULL},
873 {"( 1.3.6.1.4.1.1466.115.121.1.5 DESC 'Binary' )", NULL},
874 {"( 1.3.6.1.4.1.1466.115.121.1.6 DESC 'Bit String' )", NULL},
875 {"( 1.3.6.1.4.1.1466.115.121.1.8 DESC 'Certificate' )", NULL},
876 {"( 1.3.6.1.4.1.1466.115.121.1.9 DESC 'Certificate List' )", NULL},
877 {"( 1.3.6.1.4.1.1466.115.121.1.10 DESC 'Certificate Pair' )", NULL},
878 {"( 1.3.6.1.4.1.1466.115.121.1.12 DESC 'DN' )", NULL},
879 {"( 1.3.6.1.4.1.1466.115.121.1.14 DESC 'Delivery Method' )", NULL},
880 {"( 1.3.6.1.4.1.1466.115.121.1.15 DESC 'Directory String' )", NULL},
881 {"( 1.3.6.1.4.1.1466.115.121.1.16 DESC 'DIT Content Rule Description' )", NULL},
882 {"( 1.3.6.1.4.1.1466.115.121.1.17 DESC 'DIT Structure Rule Description' )", NULL},
883 {"( 1.3.6.1.4.1.1466.115.121.1.21 DESC 'Enhanced Guide' )", NULL},
884 {"( 1.3.6.1.4.1.1466.115.121.1.22 DESC 'Facsimile Telephone Number' )", NULL},
885 {"( 1.3.6.1.4.1.1466.115.121.1.24 DESC 'Generalized Time' )", NULL},
886 {"( 1.3.6.1.4.1.1466.115.121.1.25 DESC 'Guide' )", NULL},
887 {"( 1.3.6.1.4.1.1466.115.121.1.26 DESC 'IA5 String' )", NULL},
888 {"( 1.3.6.1.4.1.1466.115.121.1.27 DESC 'INTEGER' )", NULL},
889 {"( 1.3.6.1.4.1.1466.115.121.1.30 DESC 'Matching Rule Description' )", NULL},
890 {"( 1.3.6.1.4.1.1466.115.121.1.31 DESC 'Matching Rule Use Description' )", NULL},
891 {"( 1.3.6.1.4.1.1466.115.121.1.32 DESC 'Mail Preference' )", NULL},
892 {"( 1.3.6.1.4.1.1466.115.121.1.34 DESC 'Name And Optional UID' )", NULL},
893 {"( 1.3.6.1.4.1.1466.115.121.1.35 DESC 'Name Form Description' )", NULL},
894 {"( 1.3.6.1.4.1.1466.115.121.1.36 DESC 'Numeric String' )", NULL},
895 {"( 1.3.6.1.4.1.1466.115.121.1.37 DESC 'Object Class Description' )", NULL},
896 {"( 1.3.6.1.4.1.1466.115.121.1.38 DESC 'OID' )", NULL},
897 {"( 1.3.6.1.4.1.1466.115.121.1.39 DESC 'Other Mailbox' )", NULL},
898 {"( 1.3.6.1.4.1.1466.115.121.1.40 DESC 'Octet String' )", NULL},
899 {"( 1.3.6.1.4.1.1466.115.121.1.41 DESC 'Postal Address' )", NULL},
900 {"( 1.3.6.1.4.1.1466.115.121.1.42 DESC 'Protocol Information' )", NULL},
901 {"( 1.3.6.1.4.1.1466.115.121.1.43 DESC 'Presentation Address' )", NULL},
902 {"( 1.3.6.1.4.1.1466.115.121.1.44 DESC 'Printable String' )", NULL},
903 {"( 1.3.6.1.4.1.1466.115.121.1.49 DESC 'Supported Algorithm' )", NULL},
904 {"( 1.3.6.1.4.1.1466.115.121.1.50 DESC 'Telephone Number' )", NULL},
905 {"( 1.3.6.1.4.1.1466.115.121.1.51 DESC 'Teletex Terminal Identifier' )", NULL},
906 {"( 1.3.6.1.4.1.1466.115.121.1.52 DESC 'Telex Number' )", NULL},
907 {"( 1.3.6.1.4.1.1466.115.121.1.53 DESC 'UTC Time' )", NULL},
908 {"( 1.3.6.1.4.1.1466.115.121.1.54 DESC 'LDAP Syntax Description' )", NULL},
909 {"( 1.3.6.1.4.1.1466.115.121.1.58 DESC 'Substring Assertion' )", NULL},
910 {"( 1.3.6.1.1.1.0.0 DESC 'NIS netgroup triple' )", NULL},
911 {"( 1.3.6.1.1.1.0.1 DESC 'Boot parameter' )", NULL},
915 struct mrule_defs_rec {
917 slap_mr_normalize_func *mrd_normalize;
918 slap_mr_compare_func *mrd_compare;
922 * Other matching rules in X.520 that we do not use:
924 * 2.5.13.9 numericStringOrderingMatch
925 * 2.5.13.12 caseIgnoreListSubstringsMatch
926 * 2.5.13.13 booleanMatch
927 * 2.5.13.15 integerOrderingMatch
928 * 2.5.13.18 octetStringOrderingMatch
929 * 2.5.13.19 octetStringSubstringsMatch
930 * 2.5.13.25 uTCTimeMatch
931 * 2.5.13.26 uTCTimeOrderingMatch
932 * 2.5.13.31 directoryStringFirstComponentMatch
933 * 2.5.13.32 wordMatch
934 * 2.5.13.33 keywordMatch
935 * 2.5.13.34 certificateExactMatch
936 * 2.5.13.35 certificateMatch
937 * 2.5.13.36 certificatePairExactMatch
938 * 2.5.13.37 certificatePairMatch
939 * 2.5.13.38 certificateListExactMatch
940 * 2.5.13.39 certificateListMatch
941 * 2.5.13.40 algorithmIdentifierMatch
942 * 2.5.13.41 storedPrefixMatch
943 * 2.5.13.42 attributeCertificateMatch
944 * 2.5.13.43 readerAndKeyIDMatch
945 * 2.5.13.44 attributeIntegrityMatch
948 struct mrule_defs_rec mrule_defs[] = {
949 {"( 2.5.13.0 NAME 'objectIdentifierMatch' SYNTAX 1.3.6.1.4.1.1466.115.121.1.38 )", NULL, NULL},
950 {"( 2.5.13.1 NAME 'distinguishedNameMatch' SYNTAX 1.3.6.1.4.1.1466.115.121.1.12 )", NULL, NULL},
951 {"( 2.5.13.2 NAME 'caseIgnoreMatch' SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 )",
952 case_ignore_normalize, case_ignore_compare},
953 {"( 2.5.13.3 NAME 'caseIgnoreOrderingMatch' SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 )",
954 case_ignore_normalize, case_ignore_compare},
955 {"( 2.5.13.4 NAME 'caseIgnoreSubstringsMatch' SYNTAX 1.3.6.1.4.1.1466.115.121.1.58 )",
956 case_ignore_normalize, case_ignore_compare},
957 /* Next three are not in the RFC's, but are needed for compatibility */
958 {"( 2.5.13.5 NAME 'caseExactMatch' SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 )",
959 case_exact_normalize, case_exact_compare},
960 {"( 2.5.13.6 NAME 'caseExactOrderingMatch' SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 )",
961 case_exact_normalize, case_exact_compare},
962 {"( 2.5.13.7 NAME 'caseExactSubstringsMatch' SYNTAX 1.3.6.1.4.1.1466.115.121.1.58 )",
963 case_exact_normalize, case_exact_compare},
964 {"( 2.5.13.8 NAME 'numericStringMatch' SYNTAX 1.3.6.1.4.1.1466.115.121.1.36 )", NULL, NULL},
965 {"( 2.5.13.10 NAME 'numericStringSubstringsMatch' SYNTAX 1.3.6.1.4.1.1466.115.121.1.58 )", NULL, NULL},
966 {"( 2.5.13.11 NAME 'caseIgnoreListMatch' SYNTAX 1.3.6.1.4.1.1466.115.121.1.41 )", NULL, NULL},
967 {"( 2.5.13.14 NAME 'integerMatch' SYNTAX 1.3.6.1.4.1.1466.115.121.1.27 )", NULL, NULL},
968 {"( 2.5.13.16 NAME 'bitStringMatch' SYNTAX 1.3.6.1.4.1.1466.115.121.1.6 )", NULL, NULL},
969 {"( 2.5.13.17 NAME 'octetStringMatch' SYNTAX 1.3.6.1.4.1.1466.115.121.1.40 )", NULL, NULL},
970 {"( 2.5.13.20 NAME 'telephoneNumberMatch' SYNTAX 1.3.6.1.4.1.1466.115.121.1.50 )", NULL, NULL},
971 {"( 2.5.13.21 NAME 'telephoneNumberSubstringsMatch' SYNTAX 1.3.6.1.4.1.1466.115.121.1.58 )", NULL, NULL},
972 {"( 2.5.13.22 NAME 'presentationAddressMatch' SYNTAX 1.3.6.1.4.1.1466.115.121.1.43 )", NULL, NULL},
973 {"( 2.5.13.23 NAME 'uniqueMemberMatch' SYNTAX 1.3.6.1.4.1.1466.115.121.1.34 )", NULL, NULL},
974 {"( 2.5.13.24 NAME 'protocolInformationMatch' SYNTAX 1.3.6.1.4.1.1466.115.121.1.42 )", NULL, NULL},
975 {"( 2.5.13.27 NAME 'generalizedTimeMatch' SYNTAX 1.3.6.1.4.1.1466.115.121.1.24 )", NULL, NULL},
976 {"( 2.5.13.28 NAME 'generalizedTimeOrderingMatch' SYNTAX 1.3.6.1.4.1.1466.115.121.1.24 )", NULL, NULL},
977 {"( 2.5.13.29 NAME 'integerFirstComponentMatch' SYNTAX 1.3.6.1.4.1.1466.115.121.1.27 )", NULL, NULL},
978 {"( 2.5.13.30 NAME 'objectIdentifierFirstComponentMatch' SYNTAX 1.3.6.1.4.1.1466.115.121.1.38 )", NULL, NULL},
979 {"( 1.3.6.1.4.1.1466.109.114.1 NAME 'caseExactIA5Match' SYNTAX 1.3.6.1.4.1.1466.115.121.1.26 )",
980 case_exact_normalize, case_exact_compare},
981 {"( 1.3.6.1.4.1.1466.109.114.2 NAME 'caseIgnoreIA5Match' SYNTAX 1.3.6.1.4.1.1466.115.121.1.26 )",
982 case_ignore_normalize, case_ignore_compare},
991 static int schema_init_done = 0;
993 /* We are called from read_config that is recursive */
994 if ( schema_init_done )
996 for ( i=0; syntax_defs[i].sd_desc != NULL; i++ ) {
997 res = register_syntax( syntax_defs[i].sd_desc,
998 syntax_defs[i].sd_check );
1000 fprintf( stderr, "schema_init: Error registering syntax %s\n",
1001 syntax_defs[i].sd_desc );
1005 for ( i=0; mrule_defs[i].mrd_desc != NULL; i++ ) {
1006 res = register_matching_rule( mrule_defs[i].mrd_desc,
1007 ( mrule_defs[i].mrd_normalize ?
1008 mrule_defs[i].mrd_normalize : case_ignore_normalize ),
1009 ( mrule_defs[i].mrd_compare ?
1010 mrule_defs[i].mrd_compare : case_ignore_compare ) );
1012 fprintf( stderr, "schema_init: Error registering matching rule %s\n",
1013 mrule_defs[i].mrd_desc );
1017 schema_init_done = 1;
1021 #if defined( SLAPD_SCHEMA_DN )
1024 syn_schema_info( Entry *e )
1027 struct berval *vals[2];
1033 for ( syn = syn_list; syn; syn = syn->ssyn_next ) {
1034 val.bv_val = ldap_syntax2str( &syn->ssyn_syn );
1036 val.bv_len = strlen( val.bv_val );
1037 Debug( LDAP_DEBUG_TRACE, "Merging syn [%d] %s\n",
1038 val.bv_len, val.bv_val, 0 );
1039 attr_merge( e, "ldapSyntaxes", vals );
1040 ldap_memfree( val.bv_val );
1049 mr_schema_info( Entry *e )
1052 struct berval *vals[2];
1058 for ( mr = mr_list; mr; mr = mr->smr_next ) {
1059 val.bv_val = ldap_matchingrule2str( &mr->smr_mrule );
1061 val.bv_len = strlen( val.bv_val );
1062 Debug( LDAP_DEBUG_TRACE, "Merging mr [%d] %s\n",
1063 val.bv_len, val.bv_val, 0 );
1064 attr_merge( e, "matchingRules", vals );
1065 ldap_memfree( val.bv_val );
1074 oc_schema_info( Entry *e )
1077 struct berval *vals[2];
1083 for ( oc = oc_list; oc; oc = oc->soc_next ) {
1084 val.bv_val = ldap_objectclass2str( &oc->soc_oclass );
1086 val.bv_len = strlen( val.bv_val );
1087 Debug( LDAP_DEBUG_TRACE, "Merging oc [%d] %s\n",
1088 val.bv_len, val.bv_val, 0 );
1089 attr_merge( e, "objectClasses", vals );
1090 ldap_memfree( val.bv_val );
1099 schema_info( Connection *conn, Operation *op, char **attrs, int attrsonly )
1103 struct berval *vals[2];
1108 e = (Entry *) ch_calloc( 1, sizeof(Entry) );
1111 e->e_dn = ch_strdup( SLAPD_SCHEMA_DN );
1112 e->e_ndn = dn_normalize_case( ch_strdup( SLAPD_SCHEMA_DN ));
1113 e->e_private = NULL;
1115 val.bv_val = ch_strdup( "top" );
1116 val.bv_len = strlen( val.bv_val );
1117 attr_merge( e, "objectClass", vals );
1118 ldap_memfree( val.bv_val );
1120 val.bv_val = ch_strdup( "subschema" );
1121 val.bv_len = strlen( val.bv_val );
1122 attr_merge( e, "objectClass", vals );
1123 ldap_memfree( val.bv_val );
1125 if ( syn_schema_info( e ) ) {
1126 /* Out of memory, do something about it */
1130 if ( mr_schema_info( e ) ) {
1131 /* Out of memory, do something about it */
1135 if ( at_schema_info( e ) ) {
1136 /* Out of memory, do something about it */
1140 if ( oc_schema_info( e ) ) {
1141 /* Out of memory, do something about it */
1146 send_search_entry( &backends[0], conn, op,
1147 e, attrs, attrsonly, 0, NULL );
1148 send_search_result( conn, op, LDAP_SUCCESS,
1149 NULL, NULL, NULL, NULL, 1 );
1158 oc_print( ObjectClass *oc )
1162 if ( oc->soc_names && oc->soc_names[0] ) {
1163 printf( "objectclass %s\n", oc->soc_names[0] );
1165 printf( "objectclass %s\n", oc->soc_oid );
1167 if ( oc->soc_required != NULL ) {
1168 printf( "\trequires %s", oc->soc_required[0] );
1169 for ( i = 1; oc->soc_required[i] != NULL; i++ ) {
1170 printf( ",%s", oc->soc_required[i] );
1174 if ( oc->soc_allowed != NULL ) {
1175 printf( "\tallows %s", oc->soc_allowed[0] );
1176 for ( i = 1; oc->soc_allowed[i] != NULL; i++ ) {
1177 printf( ",%s", oc->soc_allowed[i] );
1186 int is_entry_objectclass(
1193 if( e == NULL || oc == NULL || *oc == '\0' )
1197 * find objectClass attribute
1199 attr = attr_find(e->e_attrs, "objectclass");
1201 if( attr == NULL ) {
1202 /* no objectClass attribute */
1207 bv.bv_len = strlen( bv.bv_val );
1209 if( value_find(attr->a_vals, &bv, attr->a_syntax, 1) != 0) {
1210 /* entry is not of this objectclass */