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);
19 * oc_check - check that entry e conforms to the schema required by
20 * its object class(es). returns 0 if so, non-zero otherwise.
24 oc_schema_check( Entry *e )
30 /* find the object class attribute - could error out here */
31 if ( (aoc = attr_find( e->e_attrs, "objectclass" )) == NULL ) {
32 Debug( LDAP_DEBUG_ANY, "No object class for entry (%s)\n",
37 /* check that the entry has required attrs for each oc */
38 for ( i = 0; aoc->a_vals[i] != NULL; i++ ) {
39 char *s = oc_check_required( e, aoc->a_vals[i]->bv_val );
42 Debug( LDAP_DEBUG_ANY,
43 "Entry (%s), oc \"%s\" requires attr \"%s\"\n",
44 e->e_dn, aoc->a_vals[i]->bv_val, s );
53 /* check that each attr in the entry is allowed by some oc */
54 for ( a = e->e_attrs; a != NULL; a = a->a_next ) {
55 if ( oc_check_allowed( a->a_type, aoc->a_vals ) != 0 ) {
56 Debug( LDAP_DEBUG_ANY,
57 "Entry (%s), attr \"%s\" not allowed\n",
58 e->e_dn, a->a_type, 0 );
67 oc_check_required( Entry *e, char *ocname )
75 Debug( LDAP_DEBUG_TRACE,
76 "oc_check_required entry (%s), objectclass \"%s\"\n",
79 /* find global oc defn. it we don't know about it assume it's ok */
80 if ( (oc = oc_find( ocname )) == NULL ) {
84 /* check for empty oc_required */
85 if(oc->soc_required == NULL) {
89 /* for each required attribute */
90 for ( i = 0; oc->soc_required[i] != NULL; i++ ) {
91 at = oc->soc_required[i];
92 /* see if it's in the entry */
93 for ( a = e->e_attrs; a != NULL; a = a->a_next ) {
95 strcmp( a->a_type, at->sat_oid ) == 0 ) {
100 /* Empty name list => not found */
105 if ( strcasecmp( a->a_type, *pp ) == 0 ) {
114 /* not there => schema violation */
116 if ( at->sat_names && at->sat_names[0] ) {
117 return at->sat_names[0];
127 static char *oc_usermod_attrs[] = {
129 * OpenLDAP doesn't support any user modification of
130 * operational attributes.
135 static char *oc_operational_attrs[] = {
137 * these are operational attributes that *could* be
138 * modified by users if we supported such.
149 "supportedExtension",
151 "supportedSASLMechanisms",
152 "supportedLDAPversion",
157 /* this list should be extensible */
158 static char *oc_no_usermod_attrs[] = {
160 * Operational and 'no user modification' attributes
175 * check to see if attribute is 'operational' or not.
178 oc_check_operational_attr( char *type )
180 return charray_inlist( oc_operational_attrs, type )
181 || charray_inlist( oc_usermod_attrs, type )
182 || charray_inlist( oc_no_usermod_attrs, type );
186 * check to see if attribute can be user modified or not.
189 oc_check_usermod_attr( char *type )
191 return charray_inlist( oc_usermod_attrs, type );
195 * check to see if attribute is 'no user modification' or not.
198 oc_check_no_usermod_attr( char *type )
200 return charray_inlist( oc_no_usermod_attrs, type );
205 oc_check_allowed( char *type, struct berval **ocl )
212 Debug( LDAP_DEBUG_TRACE,
213 "oc_check_allowed type \"%s\"\n", type, 0, 0 );
215 /* always allow objectclass attribute */
216 if ( strcasecmp( type, "objectclass" ) == 0 ) {
221 * All operational attributions are allowed by schema rules.
222 * However, we only check attributions which are stored in the
223 * the directory regardless if they are user or non-user modified.
225 if ( oc_check_usermod_attr( type ) || oc_check_no_usermod_attr( type ) ) {
229 /* check that the type appears as req or opt in at least one oc */
230 for ( i = 0; ocl[i] != NULL; i++ ) {
231 /* if we know about the oc */
232 if ( (oc = oc_find( ocl[i]->bv_val )) != NULL ) {
233 /* does it require the type? */
234 for ( j = 0; oc->soc_required != NULL &&
235 oc->soc_required[j] != NULL; j++ ) {
236 at = oc->soc_required[j];
238 strcmp(at->sat_oid, type ) == 0 ) {
245 if ( strcasecmp( *pp, type ) == 0 ) {
251 /* does it allow the type? */
252 for ( j = 0; oc->soc_allowed != NULL &&
253 oc->soc_allowed[j] != NULL; j++ ) {
254 at = oc->soc_allowed[j];
256 strcmp(at->sat_oid, type ) == 0 ) {
263 if ( strcasecmp( *pp, type ) == 0 ||
264 strcmp( *pp, "*" ) == 0 ) {
270 /* maybe the next oc allows it */
272 /* we don't know about the oc. assume it allows it */
278 /* not allowed by any oc */
287 static Avlnode *oc_index = NULL;
288 static ObjectClass *oc_list = NULL;
292 struct oindexrec *oir1,
293 struct oindexrec *oir2
296 return (strcasecmp( oir1->oir_name, oir2->oir_name ));
302 struct oindexrec *oir
305 return (strcasecmp( name, oir->oir_name ));
309 oc_find( const char *ocname )
311 struct oindexrec *oir = NULL;
313 if ( (oir = (struct oindexrec *) avl_find( oc_index, ocname,
314 (AVL_CMP) oc_index_name_cmp )) != NULL ) {
315 return( oir->oir_oc );
329 AttributeType **satp;
335 sat = at_find(*attrs1);
338 return SLAP_SCHERR_ATTR_NOT_FOUND;
340 if ( at_find_in_list(sat, soc->soc_required) < 0) {
341 if ( at_append_to_list(sat, &soc->soc_required) ) {
343 return SLAP_SCHERR_OUTOFMEM;
348 /* Now delete duplicates from the allowed list */
349 for ( satp = soc->soc_required; *satp; satp++ ) {
350 i = at_find_in_list(*satp,soc->soc_allowed);
352 at_delete_from_list(i, &soc->soc_allowed);
372 sat = at_find(*attrs1);
375 return SLAP_SCHERR_ATTR_NOT_FOUND;
377 if ( at_find_in_list(sat, soc->soc_required) < 0 &&
378 at_find_in_list(sat, soc->soc_allowed) < 0 ) {
379 if ( at_append_to_list(sat, &soc->soc_allowed) ) {
381 return SLAP_SCHERR_OUTOFMEM;
404 if ( !soc->soc_sups ) {
405 /* We are at the first recursive level */
414 soc->soc_sups = (ObjectClass **)ch_calloc(1,
415 nsups*sizeof(ObjectClass *));
420 soc1 = oc_find(*sups1);
423 return SLAP_SCHERR_CLASS_NOT_FOUND;
427 soc->soc_sups[nsups] = soc1;
429 code = oc_add_sups(soc,soc1->soc_sup_oids, err);
433 if ( code = oc_create_required(soc,
434 soc1->soc_at_oids_must,err) )
436 if ( code = oc_create_allowed(soc,
437 soc1->soc_at_oids_may,err) )
453 struct oindexrec *oir;
457 while ( *ocp != NULL ) {
458 ocp = &(*ocp)->soc_next;
462 if ( soc->soc_oid ) {
463 oir = (struct oindexrec *)
464 ch_calloc( 1, sizeof(struct oindexrec) );
465 oir->oir_name = soc->soc_oid;
467 if ( avl_insert( &oc_index, (caddr_t) oir,
468 (AVL_CMP) oc_index_cmp,
469 (AVL_DUP) avl_dup_error ) ) {
472 return SLAP_SCHERR_DUP_CLASS;
474 /* FIX: temporal consistency check */
475 oc_find(oir->oir_name);
477 if ( (names = soc->soc_names) ) {
479 oir = (struct oindexrec *)
480 ch_calloc( 1, sizeof(struct oindexrec) );
481 oir->oir_name = ch_strdup(*names);
483 if ( avl_insert( &oc_index, (caddr_t) oir,
484 (AVL_CMP) oc_index_cmp,
485 (AVL_DUP) avl_dup_error ) ) {
488 return SLAP_SCHERR_DUP_CLASS;
490 /* FIX: temporal consistency check */
491 oc_find(oir->oir_name);
500 LDAP_OBJECT_CLASS *oc,
507 soc = (ObjectClass *) ch_calloc( 1, sizeof(ObjectClass) );
508 memcpy( &soc->soc_oclass, oc, sizeof(LDAP_OBJECT_CLASS));
509 if ( code = oc_add_sups(soc,soc->soc_sup_oids,err) )
511 if ( code = oc_create_required(soc,soc->soc_at_oids_must,err) )
513 if ( code = oc_create_allowed(soc,soc->soc_at_oids_may,err) )
515 code = oc_insert(soc,err);
524 static Avlnode *syn_index = NULL;
525 static Syntax *syn_list = NULL;
529 struct sindexrec *sir1,
530 struct sindexrec *sir2
533 return (strcmp( sir1->sir_name, sir2->sir_name ));
539 struct sindexrec *sir
542 return (strcmp( name, sir->sir_name ));
546 syn_find( const char *synname )
548 struct sindexrec *sir = NULL;
550 if ( (sir = (struct sindexrec *) avl_find( syn_index, synname,
551 (AVL_CMP) syn_index_name_cmp )) != NULL ) {
552 return( sir->sir_syn );
564 struct sindexrec *sir;
567 while ( *synp != NULL ) {
568 synp = &(*synp)->ssyn_next;
572 if ( ssyn->ssyn_oid ) {
573 sir = (struct sindexrec *)
574 ch_calloc( 1, sizeof(struct sindexrec) );
575 sir->sir_name = ssyn->ssyn_oid;
577 if ( avl_insert( &syn_index, (caddr_t) sir,
578 (AVL_CMP) syn_index_cmp,
579 (AVL_DUP) avl_dup_error ) ) {
580 *err = ssyn->ssyn_oid;
582 return SLAP_SCHERR_DUP_SYNTAX;
584 /* FIX: temporal consistency check */
585 syn_find(sir->sir_name);
593 slap_syntax_check_func *check,
600 ssyn = (Syntax *) ch_calloc( 1, sizeof(Syntax) );
601 memcpy( &ssyn->ssyn_syn, syn, sizeof(LDAP_SYNTAX));
602 ssyn->ssyn_check = check;
603 code = syn_insert(ssyn,err);
609 MatchingRule *mir_mr;
612 static Avlnode *mr_index = NULL;
613 static MatchingRule *mr_list = NULL;
617 struct mindexrec *mir1,
618 struct mindexrec *mir2
621 return (strcmp( mir1->mir_name, mir2->mir_name ));
627 struct mindexrec *mir
630 return (strcmp( name, mir->mir_name ));
634 mr_find( const char *mrname )
636 struct mindexrec *mir = NULL;
638 if ( (mir = (struct mindexrec *) avl_find( mr_index, mrname,
639 (AVL_CMP) mr_index_name_cmp )) != NULL ) {
640 return( mir->mir_mr );
652 struct mindexrec *mir;
656 while ( *mrp != NULL ) {
657 mrp = &(*mrp)->smr_next;
661 if ( smr->smr_oid ) {
662 mir = (struct mindexrec *)
663 ch_calloc( 1, sizeof(struct mindexrec) );
664 mir->mir_name = smr->smr_oid;
666 if ( avl_insert( &mr_index, (caddr_t) mir,
667 (AVL_CMP) mr_index_cmp,
668 (AVL_DUP) avl_dup_error ) ) {
671 return SLAP_SCHERR_DUP_RULE;
673 /* FIX: temporal consistency check */
674 mr_find(mir->mir_name);
676 if ( (names = smr->smr_names) ) {
678 mir = (struct mindexrec *)
679 ch_calloc( 1, sizeof(struct mindexrec) );
680 mir->mir_name = ch_strdup(*names);
682 if ( avl_insert( &mr_index, (caddr_t) mir,
683 (AVL_CMP) mr_index_cmp,
684 (AVL_DUP) avl_dup_error ) ) {
687 return SLAP_SCHERR_DUP_RULE;
689 /* FIX: temporal consistency check */
690 mr_find(mir->mir_name);
699 LDAP_MATCHING_RULE *mr,
700 slap_mr_normalize_func *normalize,
701 slap_mr_compare_func *compare,
709 smr = (MatchingRule *) ch_calloc( 1, sizeof(MatchingRule) );
710 memcpy( &smr->smr_mrule, mr, sizeof(LDAP_MATCHING_RULE));
711 smr->smr_normalize = normalize;
712 smr->smr_compare = compare;
713 if ( smr->smr_syntax_oid ) {
714 if ( (syn = syn_find(smr->smr_syntax_oid)) ) {
715 smr->smr_syntax = syn;
717 *err = smr->smr_syntax_oid;
718 return SLAP_SCHERR_SYN_NOT_FOUND;
722 return SLAP_SCHERR_MR_INCOMPLETE;
724 code = mr_insert(smr,err);
729 case_exact_normalize(
731 struct berval **normalized
734 struct berval *newval;
737 newval = ber_bvdup( val );
738 p = q = newval->bv_val;
739 /* Ignore initial whitespace */
740 while ( isspace( *p++ ) )
743 if ( isspace( *p ) ) {
745 /* Ignore the extra whitespace */
746 while ( isspace(*p++) )
753 * If the string ended in space, backup the pointer one
754 * position. One is enough because the above loop collapsed
755 * all whitespace to a single space.
757 if ( p != newval->bv_val && isspace( *(p-1) ) ) {
760 newval->bv_len = strlen( newval->bv_val );
761 normalized = &newval;
772 return strcmp( val1->bv_val, val2->bv_val );
776 case_ignore_normalize(
778 struct berval **normalized
781 struct berval *newval;
784 newval = ber_bvdup( val );
785 p = q = newval->bv_val;
786 /* Ignore initial whitespace */
787 while ( isspace( *p++ ) )
790 if ( isspace( *p ) ) {
792 /* Ignore the extra whitespace */
793 while ( isspace(*p++) )
796 *q++ = TOUPPER( *p++ );
800 * If the string ended in space, backup the pointer one
801 * position. One is enough because the above loop collapsed
802 * all whitespace to a single space.
804 if ( p != newval->bv_val && isspace( *(p-1) ) ) {
807 newval->bv_len = strlen( newval->bv_val );
808 normalized = &newval;
819 return strcasecmp( val1->bv_val, val2->bv_val );
825 slap_syntax_check_func *check )
831 syn = ldap_str2syntax( desc, &code, &err);
833 Debug( LDAP_DEBUG_ANY, "Error in register_syntax: %s before %s in %s\n",
834 ldap_scherr2str(code), err, desc );
837 code = syn_add( syn, check, &err );
839 Debug( LDAP_DEBUG_ANY, "Error in register_syntax: %s %s in %s\n",
840 scherr2str(code), err, desc );
847 register_matching_rule(
849 slap_mr_normalize_func *normalize,
850 slap_mr_compare_func *compare )
852 LDAP_MATCHING_RULE *mr;
856 mr = ldap_str2matchingrule( desc, &code, &err);
858 Debug( LDAP_DEBUG_ANY, "Error in register_matching_rule: %s before %s in %s\n",
859 ldap_scherr2str(code), err, desc );
862 code = mr_add( mr, normalize, compare, &err );
864 Debug( LDAP_DEBUG_ANY, "Error in register_syntax: %s for %s in %s\n",
865 scherr2str(code), err, desc );
871 struct syntax_defs_rec {
873 slap_syntax_check_func *sd_check;
876 struct syntax_defs_rec syntax_defs[] = {
877 {"( 1.3.6.1.4.1.1466.115.121.1.3 DESC 'Attribute Type Description' )", NULL},
878 {"( 1.3.6.1.4.1.1466.115.121.1.4 DESC 'Audio' )", NULL},
879 {"( 1.3.6.1.4.1.1466.115.121.1.5 DESC 'Binary' )", NULL},
880 {"( 1.3.6.1.4.1.1466.115.121.1.6 DESC 'Bit String' )", NULL},
881 {"( 1.3.6.1.4.1.1466.115.121.1.8 DESC 'Certificate' )", NULL},
882 {"( 1.3.6.1.4.1.1466.115.121.1.9 DESC 'Certificate List' )", NULL},
883 {"( 1.3.6.1.4.1.1466.115.121.1.10 DESC 'Certificate Pair' )", NULL},
884 {"( 1.3.6.1.4.1.1466.115.121.1.12 DESC 'DN' )", NULL},
885 {"( 1.3.6.1.4.1.1466.115.121.1.14 DESC 'Delivery Method' )", NULL},
886 {"( 1.3.6.1.4.1.1466.115.121.1.15 DESC 'Directory String' )", NULL},
887 {"( 1.3.6.1.4.1.1466.115.121.1.16 DESC 'DIT Content Rule Description' )", NULL},
888 {"( 1.3.6.1.4.1.1466.115.121.1.17 DESC 'DIT Structure Rule Description' )", NULL},
889 {"( 1.3.6.1.4.1.1466.115.121.1.21 DESC 'Enhanced Guide' )", NULL},
890 {"( 1.3.6.1.4.1.1466.115.121.1.22 DESC 'Facsimile Telephone Number' )", NULL},
891 {"( 1.3.6.1.4.1.1466.115.121.1.24 DESC 'Generalized Time' )", NULL},
892 {"( 1.3.6.1.4.1.1466.115.121.1.25 DESC 'Guide' )", NULL},
893 {"( 1.3.6.1.4.1.1466.115.121.1.26 DESC 'IA5 String' )", NULL},
894 {"( 1.3.6.1.4.1.1466.115.121.1.27 DESC 'INTEGER' )", NULL},
895 {"( 1.3.6.1.4.1.1466.115.121.1.30 DESC 'Matching Rule Description' )", NULL},
896 {"( 1.3.6.1.4.1.1466.115.121.1.31 DESC 'Matching Rule Use Description' )", NULL},
897 {"( 1.3.6.1.4.1.1466.115.121.1.32 DESC 'Mail Preference' )", NULL},
898 {"( 1.3.6.1.4.1.1466.115.121.1.34 DESC 'Name And Optional UID' )", NULL},
899 {"( 1.3.6.1.4.1.1466.115.121.1.35 DESC 'Name Form Description' )", NULL},
900 {"( 1.3.6.1.4.1.1466.115.121.1.36 DESC 'Numeric String' )", NULL},
901 {"( 1.3.6.1.4.1.1466.115.121.1.37 DESC 'Object Class Description' )", NULL},
902 {"( 1.3.6.1.4.1.1466.115.121.1.38 DESC 'OID' )", NULL},
903 {"( 1.3.6.1.4.1.1466.115.121.1.39 DESC 'Other Mailbox' )", NULL},
904 {"( 1.3.6.1.4.1.1466.115.121.1.40 DESC 'Octet String' )", NULL},
905 {"( 1.3.6.1.4.1.1466.115.121.1.41 DESC 'Postal Address' )", NULL},
906 {"( 1.3.6.1.4.1.1466.115.121.1.42 DESC 'Protocol Information' )", NULL},
907 {"( 1.3.6.1.4.1.1466.115.121.1.43 DESC 'Presentation Address' )", NULL},
908 {"( 1.3.6.1.4.1.1466.115.121.1.44 DESC 'Printable String' )", NULL},
909 {"( 1.3.6.1.4.1.1466.115.121.1.49 DESC 'Supported Algorithm' )", NULL},
910 {"( 1.3.6.1.4.1.1466.115.121.1.50 DESC 'Telephone Number' )", NULL},
911 {"( 1.3.6.1.4.1.1466.115.121.1.51 DESC 'Teletex Terminal Identifier' )", NULL},
912 {"( 1.3.6.1.4.1.1466.115.121.1.52 DESC 'Telex Number' )", NULL},
913 {"( 1.3.6.1.4.1.1466.115.121.1.53 DESC 'UTC Time' )", NULL},
914 {"( 1.3.6.1.4.1.1466.115.121.1.54 DESC 'LDAP Syntax Description' )", NULL},
915 {"( 1.3.6.1.4.1.1466.115.121.1.58 DESC 'Substring Assertion' )", NULL},
916 {"( 1.3.6.1.1.1.0.0 DESC 'NIS netgroup triple' )", NULL},
917 {"( 1.3.6.1.1.1.0.1 DESC 'Boot parameter' )", NULL},
921 struct mrule_defs_rec {
923 slap_mr_normalize_func *mrd_normalize;
924 slap_mr_compare_func *mrd_compare;
928 * Other matching rules in X.520 that we do not use:
930 * 2.5.13.9 numericStringOrderingMatch
931 * 2.5.13.12 caseIgnoreListSubstringsMatch
932 * 2.5.13.13 booleanMatch
933 * 2.5.13.15 integerOrderingMatch
934 * 2.5.13.18 octetStringOrderingMatch
935 * 2.5.13.19 octetStringSubstringsMatch
936 * 2.5.13.25 uTCTimeMatch
937 * 2.5.13.26 uTCTimeOrderingMatch
938 * 2.5.13.31 directoryStringFirstComponentMatch
939 * 2.5.13.32 wordMatch
940 * 2.5.13.33 keywordMatch
941 * 2.5.13.34 certificateExactMatch
942 * 2.5.13.35 certificateMatch
943 * 2.5.13.36 certificatePairExactMatch
944 * 2.5.13.37 certificatePairMatch
945 * 2.5.13.38 certificateListExactMatch
946 * 2.5.13.39 certificateListMatch
947 * 2.5.13.40 algorithmIdentifierMatch
948 * 2.5.13.41 storedPrefixMatch
949 * 2.5.13.42 attributeCertificateMatch
950 * 2.5.13.43 readerAndKeyIDMatch
951 * 2.5.13.44 attributeIntegrityMatch
954 struct mrule_defs_rec mrule_defs[] = {
955 {"( 2.5.13.0 NAME 'objectIdentifierMatch' SYNTAX 1.3.6.1.4.1.1466.115.121.1.38 )", NULL, NULL},
956 {"( 2.5.13.1 NAME 'distinguishedNameMatch' SYNTAX 1.3.6.1.4.1.1466.115.121.1.12 )", NULL, NULL},
957 {"( 2.5.13.2 NAME 'caseIgnoreMatch' SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 )",
958 case_ignore_normalize, case_ignore_compare},
959 {"( 2.5.13.3 NAME 'caseIgnoreOrderingMatch' SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 )",
960 case_ignore_normalize, case_ignore_compare},
961 {"( 2.5.13.4 NAME 'caseIgnoreSubstringsMatch' SYNTAX 1.3.6.1.4.1.1466.115.121.1.58 )",
962 case_ignore_normalize, case_ignore_compare},
963 /* Next three are not in the RFC's, but are needed for compatibility */
964 {"( 2.5.13.5 NAME 'caseExactMatch' SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 )",
965 case_exact_normalize, case_exact_compare},
966 {"( 2.5.13.6 NAME 'caseExactOrderingMatch' SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 )",
967 case_exact_normalize, case_exact_compare},
968 {"( 2.5.13.7 NAME 'caseExactSubstringsMatch' SYNTAX 1.3.6.1.4.1.1466.115.121.1.58 )",
969 case_exact_normalize, case_exact_compare},
970 {"( 2.5.13.8 NAME 'numericStringMatch' SYNTAX 1.3.6.1.4.1.1466.115.121.1.36 )", NULL, NULL},
971 {"( 2.5.13.10 NAME 'numericStringSubstringsMatch' SYNTAX 1.3.6.1.4.1.1466.115.121.1.58 )", NULL, NULL},
972 {"( 2.5.13.11 NAME 'caseIgnoreListMatch' SYNTAX 1.3.6.1.4.1.1466.115.121.1.41 )", NULL, NULL},
973 {"( 2.5.13.14 NAME 'integerMatch' SYNTAX 1.3.6.1.4.1.1466.115.121.1.27 )", NULL, NULL},
974 {"( 2.5.13.16 NAME 'bitStringMatch' SYNTAX 1.3.6.1.4.1.1466.115.121.1.6 )", NULL, NULL},
975 {"( 2.5.13.17 NAME 'octetStringMatch' SYNTAX 1.3.6.1.4.1.1466.115.121.1.40 )", NULL, NULL},
976 {"( 2.5.13.20 NAME 'telephoneNumberMatch' SYNTAX 1.3.6.1.4.1.1466.115.121.1.50 )", NULL, NULL},
977 {"( 2.5.13.21 NAME 'telephoneNumberSubstringsMatch' SYNTAX 1.3.6.1.4.1.1466.115.121.1.58 )", NULL, NULL},
978 {"( 2.5.13.22 NAME 'presentationAddressMatch' SYNTAX 1.3.6.1.4.1.1466.115.121.1.43 )", NULL, NULL},
979 {"( 2.5.13.23 NAME 'uniqueMemberMatch' SYNTAX 1.3.6.1.4.1.1466.115.121.1.34 )", NULL, NULL},
980 {"( 2.5.13.24 NAME 'protocolInformationMatch' SYNTAX 1.3.6.1.4.1.1466.115.121.1.42 )", NULL, NULL},
981 {"( 2.5.13.27 NAME 'generalizedTimeMatch' SYNTAX 1.3.6.1.4.1.1466.115.121.1.24 )", NULL, NULL},
982 {"( 2.5.13.28 NAME 'generalizedTimeOrderingMatch' SYNTAX 1.3.6.1.4.1.1466.115.121.1.24 )", NULL, NULL},
983 {"( 2.5.13.29 NAME 'integerFirstComponentMatch' SYNTAX 1.3.6.1.4.1.1466.115.121.1.27 )", NULL, NULL},
984 {"( 2.5.13.30 NAME 'objectIdentifierFirstComponentMatch' SYNTAX 1.3.6.1.4.1.1466.115.121.1.38 )", NULL, NULL},
985 {"( 1.3.6.1.4.1.1466.109.114.1 NAME 'caseExactIA5Match' SYNTAX 1.3.6.1.4.1.1466.115.121.1.26 )",
986 case_exact_normalize, case_exact_compare},
987 {"( 1.3.6.1.4.1.1466.109.114.2 NAME 'caseIgnoreIA5Match' SYNTAX 1.3.6.1.4.1.1466.115.121.1.26 )",
988 case_ignore_normalize, case_ignore_compare},
997 static int schema_init_done = 0;
999 /* We are called from read_config that is recursive */
1000 if ( schema_init_done )
1002 for ( i=0; syntax_defs[i].sd_desc != NULL; i++ ) {
1003 res = register_syntax( syntax_defs[i].sd_desc,
1004 syntax_defs[i].sd_check );
1006 fprintf( stderr, "schema_init: Error registering syntax %s\n",
1007 syntax_defs[i].sd_desc );
1011 for ( i=0; mrule_defs[i].mrd_desc != NULL; i++ ) {
1012 res = register_matching_rule( mrule_defs[i].mrd_desc,
1013 ( mrule_defs[i].mrd_normalize ?
1014 mrule_defs[i].mrd_normalize : case_ignore_normalize ),
1015 ( mrule_defs[i].mrd_compare ?
1016 mrule_defs[i].mrd_compare : case_ignore_compare ) );
1018 fprintf( stderr, "schema_init: Error registering matching rule %s\n",
1019 mrule_defs[i].mrd_desc );
1023 schema_init_done = 1;
1027 #if defined( SLAPD_SCHEMA_DN )
1030 syn_schema_info( Entry *e )
1033 struct berval *vals[2];
1039 for ( syn = syn_list; syn; syn = syn->ssyn_next ) {
1040 val.bv_val = ldap_syntax2str( &syn->ssyn_syn );
1042 val.bv_len = strlen( val.bv_val );
1043 Debug( LDAP_DEBUG_TRACE, "Merging syn [%d] %s\n",
1044 val.bv_len, val.bv_val, 0 );
1045 attr_merge( e, "ldapSyntaxes", vals );
1046 ldap_memfree( val.bv_val );
1055 mr_schema_info( Entry *e )
1058 struct berval *vals[2];
1064 for ( mr = mr_list; mr; mr = mr->smr_next ) {
1065 val.bv_val = ldap_matchingrule2str( &mr->smr_mrule );
1067 val.bv_len = strlen( val.bv_val );
1068 Debug( LDAP_DEBUG_TRACE, "Merging mr [%d] %s\n",
1069 val.bv_len, val.bv_val, 0 );
1070 attr_merge( e, "matchingRules", vals );
1071 ldap_memfree( val.bv_val );
1080 oc_schema_info( Entry *e )
1083 struct berval *vals[2];
1089 for ( oc = oc_list; oc; oc = oc->soc_next ) {
1090 val.bv_val = ldap_objectclass2str( &oc->soc_oclass );
1092 val.bv_len = strlen( val.bv_val );
1093 Debug( LDAP_DEBUG_TRACE, "Merging oc [%d] %s\n",
1094 val.bv_len, val.bv_val, 0 );
1095 attr_merge( e, "objectClasses", vals );
1096 ldap_memfree( val.bv_val );
1105 schema_info( Connection *conn, Operation *op, char **attrs, int attrsonly )
1109 struct berval *vals[2];
1114 e = (Entry *) ch_calloc( 1, sizeof(Entry) );
1117 e->e_dn = ch_strdup( SLAPD_SCHEMA_DN );
1118 e->e_ndn = ch_strdup( SLAPD_SCHEMA_DN );
1119 (void) dn_normalize_case( e->e_ndn );
1120 e->e_private = NULL;
1122 val.bv_val = ch_strdup( "top" );
1123 val.bv_len = strlen( val.bv_val );
1124 attr_merge( e, "objectClass", vals );
1125 ldap_memfree( val.bv_val );
1127 val.bv_val = ch_strdup( "subschema" );
1128 val.bv_len = strlen( val.bv_val );
1129 attr_merge( e, "objectClass", vals );
1130 ldap_memfree( val.bv_val );
1132 if ( syn_schema_info( e ) ) {
1133 /* Out of memory, do something about it */
1137 if ( mr_schema_info( e ) ) {
1138 /* Out of memory, do something about it */
1142 if ( at_schema_info( e ) ) {
1143 /* Out of memory, do something about it */
1147 if ( oc_schema_info( e ) ) {
1148 /* Out of memory, do something about it */
1153 send_search_entry( &backends[0], conn, op,
1154 e, attrs, attrsonly, 0, NULL );
1155 send_search_result( conn, op, LDAP_SUCCESS,
1156 NULL, NULL, NULL, NULL, 1 );
1165 oc_print( ObjectClass *oc )
1169 if ( oc->soc_names && oc->soc_names[0] ) {
1170 printf( "objectclass %s\n", oc->soc_names[0] );
1172 printf( "objectclass %s\n", oc->soc_oid );
1174 if ( oc->soc_required != NULL ) {
1175 printf( "\trequires %s", oc->soc_required[0] );
1176 for ( i = 1; oc->soc_required[i] != NULL; i++ ) {
1177 printf( ",%s", oc->soc_required[i] );
1181 if ( oc->soc_allowed != NULL ) {
1182 printf( "\tallows %s", oc->soc_allowed[0] );
1183 for ( i = 1; oc->soc_allowed[i] != NULL; i++ ) {
1184 printf( ",%s", oc->soc_allowed[i] );
1193 int is_entry_objectclass(
1200 if( e == NULL || oc == NULL || *oc == '\0' )
1204 * find objectClass attribute
1206 attr = attr_find(e->e_attrs, "objectclass");
1208 if( attr == NULL ) {
1209 /* no objectClass attribute */
1214 bv.bv_len = strlen( bv.bv_val );
1216 if( value_find(attr->a_vals, &bv, attr->a_syntax, 1) != 0) {
1217 /* entry is not of this objectclass */