1 /* schema.c - routines to enforce schema definitions */
3 * Copyright 1998-1999 The OpenLDAP Foundation, All Rights Reserved.
4 * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
12 #include <ac/string.h>
13 #include <ac/socket.h>
15 #include "ldap_defaults.h"
18 static char * oc_check_required(Entry *e, char *ocname);
19 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 )
34 /* find the object class attribute - could error out here */
35 if ( (aoc = attr_find( e->e_attrs, "objectclass" )) == NULL ) {
36 Debug( LDAP_DEBUG_ANY, "No object class for entry (%s)\n",
41 /* check that the entry has required attrs for each oc */
42 for ( i = 0; aoc->a_vals[i] != NULL; i++ ) {
43 char *s = oc_check_required( e, aoc->a_vals[i]->bv_val );
46 Debug( LDAP_DEBUG_ANY,
47 "Entry (%s), oc \"%s\" requires attr \"%s\"\n",
48 e->e_dn, aoc->a_vals[i]->bv_val, s );
57 /* check that each attr in the entry is allowed by some oc */
58 for ( a = e->e_attrs; a != NULL; a = a->a_next ) {
59 if ( oc_check_allowed( a->a_type, aoc->a_vals ) != 0 ) {
60 Debug( LDAP_DEBUG_ANY,
61 "Entry (%s), attr \"%s\" not allowed\n",
62 e->e_dn, a->a_type, 0 );
71 oc_check_required( Entry *e, char *ocname )
79 Debug( LDAP_DEBUG_TRACE,
80 "oc_check_required entry (%s), objectclass \"%s\"\n",
83 /* find global oc defn. it we don't know about it assume it's ok */
84 if ( (oc = oc_find( ocname )) == NULL ) {
88 /* check for empty oc_required */
89 if(oc->soc_required == NULL) {
93 /* for each required attribute */
94 for ( i = 0; oc->soc_required[i] != NULL; i++ ) {
95 at = oc->soc_required[i];
96 /* see if it's in the entry */
97 for ( a = e->e_attrs; a != NULL; a = a->a_next ) {
99 strcmp( a->a_type, at->sat_oid ) == 0 ) {
104 /* Empty name list => not found */
109 if ( strcasecmp( a->a_type, *pp ) == 0 ) {
118 /* not there => schema violation */
120 if ( at->sat_names && at->sat_names[0] ) {
121 return at->sat_names[0];
131 static char *oc_usermod_attrs[] = {
133 * OpenLDAP doesn't support any user modification of
134 * operational attributes.
139 static char *oc_operational_attrs[] = {
141 * these are operational attributes
142 * most could be user modifiable
153 "supportedExtension",
155 "supportedSASLMechanisms",
156 "supportedLDAPversion",
157 "subschemaSubentry", /* NO USER MOD */
162 /* this list should be extensible */
163 static char *oc_no_usermod_attrs[] = {
165 * Operational and 'no user modification' attributes
166 * which are STORED in the directory server.
180 * check to see if attribute is 'operational' or not.
183 oc_check_operational_attr( char *type )
185 return charray_inlist( oc_operational_attrs, type )
186 || charray_inlist( oc_usermod_attrs, type )
187 || charray_inlist( oc_no_usermod_attrs, type );
191 * check to see if attribute can be user modified or not.
194 oc_check_usermod_attr( char *type )
196 return charray_inlist( oc_usermod_attrs, type );
200 * check to see if attribute is 'no user modification' or not.
203 oc_check_no_usermod_attr( char *type )
205 return charray_inlist( oc_no_usermod_attrs, type );
210 oc_check_allowed( char *type, struct berval **ocl )
217 Debug( LDAP_DEBUG_TRACE,
218 "oc_check_allowed type \"%s\"\n", type, 0, 0 );
220 /* always allow objectclass attribute */
221 if ( strcasecmp( type, "objectclass" ) == 0 ) {
226 * All operational attributions are allowed by schema rules.
227 * However, we only check attributions which are stored in the
228 * the directory regardless if they are user or non-user modified.
230 if ( oc_check_usermod_attr( type ) || oc_check_no_usermod_attr( type ) ) {
234 /* check that the type appears as req or opt in at least one oc */
235 for ( i = 0; ocl[i] != NULL; i++ ) {
236 /* if we know about the oc */
237 if ( (oc = oc_find( ocl[i]->bv_val )) != NULL ) {
238 /* does it require the type? */
239 for ( j = 0; oc->soc_required != NULL &&
240 oc->soc_required[j] != NULL; j++ ) {
241 at = oc->soc_required[j];
243 strcmp(at->sat_oid, type ) == 0 ) {
250 if ( strcasecmp( *pp, type ) == 0 ) {
256 /* does it allow the type? */
257 for ( j = 0; oc->soc_allowed != NULL &&
258 oc->soc_allowed[j] != NULL; j++ ) {
259 at = oc->soc_allowed[j];
261 strcmp(at->sat_oid, type ) == 0 ) {
268 if ( strcasecmp( *pp, type ) == 0 ||
269 strcmp( *pp, "*" ) == 0 ) {
275 /* maybe the next oc allows it */
277 /* we don't know about the oc. assume it allows it */
283 /* not allowed by any oc */
292 static Avlnode *oc_index = NULL;
293 static ObjectClass *oc_list = NULL;
297 struct oindexrec *oir1,
298 struct oindexrec *oir2
301 return (strcasecmp( oir1->oir_name, oir2->oir_name ));
307 struct oindexrec *oir
310 return (strcasecmp( name, oir->oir_name ));
314 oc_find( const char *ocname )
316 struct oindexrec *oir = NULL;
318 if ( (oir = (struct oindexrec *) avl_find( oc_index, ocname,
319 (AVL_CMP) oc_index_name_cmp )) != NULL ) {
320 return( oir->oir_oc );
334 AttributeType **satp;
340 sat = at_find(*attrs1);
343 return SLAP_SCHERR_ATTR_NOT_FOUND;
345 if ( at_find_in_list(sat, soc->soc_required) < 0) {
346 if ( at_append_to_list(sat, &soc->soc_required) ) {
348 return SLAP_SCHERR_OUTOFMEM;
353 /* Now delete duplicates from the allowed list */
354 for ( satp = soc->soc_required; *satp; satp++ ) {
355 i = at_find_in_list(*satp,soc->soc_allowed);
357 at_delete_from_list(i, &soc->soc_allowed);
377 sat = at_find(*attrs1);
380 return SLAP_SCHERR_ATTR_NOT_FOUND;
382 if ( at_find_in_list(sat, soc->soc_required) < 0 &&
383 at_find_in_list(sat, soc->soc_allowed) < 0 ) {
384 if ( at_append_to_list(sat, &soc->soc_allowed) ) {
386 return SLAP_SCHERR_OUTOFMEM;
409 if ( !soc->soc_sups ) {
410 /* We are at the first recursive level */
419 soc->soc_sups = (ObjectClass **)ch_calloc(1,
420 nsups*sizeof(ObjectClass *));
425 soc1 = oc_find(*sups1);
428 return SLAP_SCHERR_CLASS_NOT_FOUND;
432 soc->soc_sups[nsups] = soc1;
434 code = oc_add_sups(soc,soc1->soc_sup_oids, err);
438 if ( code = oc_create_required(soc,
439 soc1->soc_at_oids_must,err) )
441 if ( code = oc_create_allowed(soc,
442 soc1->soc_at_oids_may,err) )
458 struct oindexrec *oir;
462 while ( *ocp != NULL ) {
463 ocp = &(*ocp)->soc_next;
467 if ( soc->soc_oid ) {
468 oir = (struct oindexrec *)
469 ch_calloc( 1, sizeof(struct oindexrec) );
470 oir->oir_name = soc->soc_oid;
472 if ( avl_insert( &oc_index, (caddr_t) oir,
473 (AVL_CMP) oc_index_cmp,
474 (AVL_DUP) avl_dup_error ) ) {
477 return SLAP_SCHERR_DUP_CLASS;
479 /* FIX: temporal consistency check */
480 oc_find(oir->oir_name);
482 if ( (names = soc->soc_names) ) {
484 oir = (struct oindexrec *)
485 ch_calloc( 1, sizeof(struct oindexrec) );
486 oir->oir_name = ch_strdup(*names);
488 if ( avl_insert( &oc_index, (caddr_t) oir,
489 (AVL_CMP) oc_index_cmp,
490 (AVL_DUP) avl_dup_error ) ) {
493 return SLAP_SCHERR_DUP_CLASS;
495 /* FIX: temporal consistency check */
496 oc_find(oir->oir_name);
505 LDAP_OBJECT_CLASS *oc,
512 soc = (ObjectClass *) ch_calloc( 1, sizeof(ObjectClass) );
513 memcpy( &soc->soc_oclass, oc, sizeof(LDAP_OBJECT_CLASS));
514 if ( code = oc_add_sups(soc,soc->soc_sup_oids,err) )
516 if ( code = oc_create_required(soc,soc->soc_at_oids_must,err) )
518 if ( code = oc_create_allowed(soc,soc->soc_at_oids_may,err) )
520 code = oc_insert(soc,err);
529 static Avlnode *syn_index = NULL;
530 static Syntax *syn_list = NULL;
534 struct sindexrec *sir1,
535 struct sindexrec *sir2
538 return (strcmp( sir1->sir_name, sir2->sir_name ));
544 struct sindexrec *sir
547 return (strcmp( name, sir->sir_name ));
551 syn_find( const char *synname )
553 struct sindexrec *sir = NULL;
555 if ( (sir = (struct sindexrec *) avl_find( syn_index, synname,
556 (AVL_CMP) syn_index_name_cmp )) != NULL ) {
557 return( sir->sir_syn );
569 struct sindexrec *sir;
572 while ( *synp != NULL ) {
573 synp = &(*synp)->ssyn_next;
577 if ( ssyn->ssyn_oid ) {
578 sir = (struct sindexrec *)
579 ch_calloc( 1, sizeof(struct sindexrec) );
580 sir->sir_name = ssyn->ssyn_oid;
582 if ( avl_insert( &syn_index, (caddr_t) sir,
583 (AVL_CMP) syn_index_cmp,
584 (AVL_DUP) avl_dup_error ) ) {
585 *err = ssyn->ssyn_oid;
587 return SLAP_SCHERR_DUP_SYNTAX;
589 /* FIX: temporal consistency check */
590 syn_find(sir->sir_name);
598 slap_syntax_check_func *check,
605 ssyn = (Syntax *) ch_calloc( 1, sizeof(Syntax) );
606 memcpy( &ssyn->ssyn_syn, syn, sizeof(LDAP_SYNTAX));
607 ssyn->ssyn_check = check;
608 code = syn_insert(ssyn,err);
614 MatchingRule *mir_mr;
617 static Avlnode *mr_index = NULL;
618 static MatchingRule *mr_list = NULL;
622 struct mindexrec *mir1,
623 struct mindexrec *mir2
626 return (strcmp( mir1->mir_name, mir2->mir_name ));
632 struct mindexrec *mir
635 return (strcmp( name, mir->mir_name ));
639 mr_find( const char *mrname )
641 struct mindexrec *mir = NULL;
643 if ( (mir = (struct mindexrec *) avl_find( mr_index, mrname,
644 (AVL_CMP) mr_index_name_cmp )) != NULL ) {
645 return( mir->mir_mr );
657 struct mindexrec *mir;
661 while ( *mrp != NULL ) {
662 mrp = &(*mrp)->smr_next;
666 if ( smr->smr_oid ) {
667 mir = (struct mindexrec *)
668 ch_calloc( 1, sizeof(struct mindexrec) );
669 mir->mir_name = smr->smr_oid;
671 if ( avl_insert( &mr_index, (caddr_t) mir,
672 (AVL_CMP) mr_index_cmp,
673 (AVL_DUP) avl_dup_error ) ) {
676 return SLAP_SCHERR_DUP_RULE;
678 /* FIX: temporal consistency check */
679 mr_find(mir->mir_name);
681 if ( (names = smr->smr_names) ) {
683 mir = (struct mindexrec *)
684 ch_calloc( 1, sizeof(struct mindexrec) );
685 mir->mir_name = ch_strdup(*names);
687 if ( avl_insert( &mr_index, (caddr_t) mir,
688 (AVL_CMP) mr_index_cmp,
689 (AVL_DUP) avl_dup_error ) ) {
692 return SLAP_SCHERR_DUP_RULE;
694 /* FIX: temporal consistency check */
695 mr_find(mir->mir_name);
704 LDAP_MATCHING_RULE *mr,
705 slap_mr_normalize_func *normalize,
706 slap_mr_compare_func *compare,
714 smr = (MatchingRule *) ch_calloc( 1, sizeof(MatchingRule) );
715 memcpy( &smr->smr_mrule, mr, sizeof(LDAP_MATCHING_RULE));
716 smr->smr_normalize = normalize;
717 smr->smr_compare = compare;
718 if ( smr->smr_syntax_oid ) {
719 if ( (syn = syn_find(smr->smr_syntax_oid)) ) {
720 smr->smr_syntax = syn;
722 *err = smr->smr_syntax_oid;
723 return SLAP_SCHERR_SYN_NOT_FOUND;
727 return SLAP_SCHERR_MR_INCOMPLETE;
729 code = mr_insert(smr,err);
734 case_exact_normalize(
736 struct berval **normalized
739 struct berval *newval;
742 newval = ber_bvdup( val );
743 p = q = newval->bv_val;
744 /* Ignore initial whitespace */
745 while ( isspace( *p++ ) )
748 if ( isspace( *p ) ) {
750 /* Ignore the extra whitespace */
751 while ( isspace(*p++) )
758 * If the string ended in space, backup the pointer one
759 * position. One is enough because the above loop collapsed
760 * all whitespace to a single space.
762 if ( p != newval->bv_val && isspace( *(p-1) ) ) {
765 newval->bv_len = strlen( newval->bv_val );
766 normalized = &newval;
777 return strcmp( val1->bv_val, val2->bv_val );
781 case_ignore_normalize(
783 struct berval **normalized
786 struct berval *newval;
789 newval = ber_bvdup( val );
790 p = q = newval->bv_val;
791 /* Ignore initial whitespace */
792 while ( isspace( *p++ ) )
795 if ( isspace( *p ) ) {
797 /* Ignore the extra whitespace */
798 while ( isspace(*p++) )
801 *q++ = TOUPPER( *p++ );
805 * If the string ended in space, backup the pointer one
806 * position. One is enough because the above loop collapsed
807 * all whitespace to a single space.
809 if ( p != newval->bv_val && isspace( *(p-1) ) ) {
812 newval->bv_len = strlen( newval->bv_val );
813 normalized = &newval;
824 return strcasecmp( val1->bv_val, val2->bv_val );
830 slap_syntax_check_func *check )
836 syn = ldap_str2syntax( desc, &code, &err);
838 Debug( LDAP_DEBUG_ANY, "Error in register_syntax: %s before %s in %s\n",
839 ldap_scherr2str(code), err, desc );
842 code = syn_add( syn, check, &err );
844 Debug( LDAP_DEBUG_ANY, "Error in register_syntax: %s %s in %s\n",
845 scherr2str(code), err, desc );
852 register_matching_rule(
854 slap_mr_normalize_func *normalize,
855 slap_mr_compare_func *compare )
857 LDAP_MATCHING_RULE *mr;
861 mr = ldap_str2matchingrule( desc, &code, &err);
863 Debug( LDAP_DEBUG_ANY, "Error in register_matching_rule: %s before %s in %s\n",
864 ldap_scherr2str(code), err, desc );
867 code = mr_add( mr, normalize, compare, &err );
869 Debug( LDAP_DEBUG_ANY, "Error in register_syntax: %s for %s in %s\n",
870 scherr2str(code), err, desc );
876 struct syntax_defs_rec {
878 slap_syntax_check_func *sd_check;
881 struct syntax_defs_rec syntax_defs[] = {
882 {"( 1.3.6.1.4.1.1466.115.121.1.3 DESC 'Attribute Type Description' )", NULL},
883 {"( 1.3.6.1.4.1.1466.115.121.1.4 DESC 'Audio' )", NULL},
884 {"( 1.3.6.1.4.1.1466.115.121.1.5 DESC 'Binary' )", NULL},
885 {"( 1.3.6.1.4.1.1466.115.121.1.6 DESC 'Bit String' )", NULL},
886 {"( 1.3.6.1.4.1.1466.115.121.1.8 DESC 'Certificate' )", NULL},
887 {"( 1.3.6.1.4.1.1466.115.121.1.9 DESC 'Certificate List' )", NULL},
888 {"( 1.3.6.1.4.1.1466.115.121.1.10 DESC 'Certificate Pair' )", NULL},
889 {"( 1.3.6.1.4.1.1466.115.121.1.12 DESC 'DN' )", NULL},
890 {"( 1.3.6.1.4.1.1466.115.121.1.14 DESC 'Delivery Method' )", NULL},
891 {"( 1.3.6.1.4.1.1466.115.121.1.15 DESC 'Directory String' )", NULL},
892 {"( 1.3.6.1.4.1.1466.115.121.1.16 DESC 'DIT Content Rule Description' )", NULL},
893 {"( 1.3.6.1.4.1.1466.115.121.1.17 DESC 'DIT Structure Rule Description' )", NULL},
894 {"( 1.3.6.1.4.1.1466.115.121.1.21 DESC 'Enhanced Guide' )", NULL},
895 {"( 1.3.6.1.4.1.1466.115.121.1.22 DESC 'Facsimile Telephone Number' )", NULL},
896 {"( 1.3.6.1.4.1.1466.115.121.1.24 DESC 'Generalized Time' )", NULL},
897 {"( 1.3.6.1.4.1.1466.115.121.1.25 DESC 'Guide' )", NULL},
898 {"( 1.3.6.1.4.1.1466.115.121.1.26 DESC 'IA5 String' )", NULL},
899 {"( 1.3.6.1.4.1.1466.115.121.1.27 DESC 'INTEGER' )", NULL},
900 {"( 1.3.6.1.4.1.1466.115.121.1.30 DESC 'Matching Rule Description' )", NULL},
901 {"( 1.3.6.1.4.1.1466.115.121.1.31 DESC 'Matching Rule Use Description' )", NULL},
902 {"( 1.3.6.1.4.1.1466.115.121.1.32 DESC 'Mail Preference' )", NULL},
903 {"( 1.3.6.1.4.1.1466.115.121.1.34 DESC 'Name And Optional UID' )", NULL},
904 {"( 1.3.6.1.4.1.1466.115.121.1.35 DESC 'Name Form Description' )", NULL},
905 {"( 1.3.6.1.4.1.1466.115.121.1.36 DESC 'Numeric String' )", NULL},
906 {"( 1.3.6.1.4.1.1466.115.121.1.37 DESC 'Object Class Description' )", NULL},
907 {"( 1.3.6.1.4.1.1466.115.121.1.38 DESC 'OID' )", NULL},
908 {"( 1.3.6.1.4.1.1466.115.121.1.39 DESC 'Other Mailbox' )", NULL},
909 {"( 1.3.6.1.4.1.1466.115.121.1.40 DESC 'Octet String' )", NULL},
910 {"( 1.3.6.1.4.1.1466.115.121.1.41 DESC 'Postal Address' )", NULL},
911 {"( 1.3.6.1.4.1.1466.115.121.1.42 DESC 'Protocol Information' )", NULL},
912 {"( 1.3.6.1.4.1.1466.115.121.1.43 DESC 'Presentation Address' )", NULL},
913 {"( 1.3.6.1.4.1.1466.115.121.1.44 DESC 'Printable String' )", NULL},
914 {"( 1.3.6.1.4.1.1466.115.121.1.49 DESC 'Supported Algorithm' )", NULL},
915 {"( 1.3.6.1.4.1.1466.115.121.1.50 DESC 'Telephone Number' )", NULL},
916 {"( 1.3.6.1.4.1.1466.115.121.1.51 DESC 'Teletex Terminal Identifier' )", NULL},
917 {"( 1.3.6.1.4.1.1466.115.121.1.52 DESC 'Telex Number' )", NULL},
918 {"( 1.3.6.1.4.1.1466.115.121.1.53 DESC 'UTC Time' )", NULL},
919 {"( 1.3.6.1.4.1.1466.115.121.1.54 DESC 'LDAP Syntax Description' )", NULL},
920 {"( 1.3.6.1.4.1.1466.115.121.1.58 DESC 'Substring Assertion' )", NULL},
921 {"( 1.3.6.1.1.1.0.0 DESC 'NIS netgroup triple' )", NULL},
922 {"( 1.3.6.1.1.1.0.1 DESC 'Boot parameter' )", NULL},
926 struct mrule_defs_rec {
928 slap_mr_normalize_func *mrd_normalize;
929 slap_mr_compare_func *mrd_compare;
933 * Other matching rules in X.520 that we do not use:
935 * 2.5.13.9 numericStringOrderingMatch
936 * 2.5.13.12 caseIgnoreListSubstringsMatch
937 * 2.5.13.13 booleanMatch
938 * 2.5.13.15 integerOrderingMatch
939 * 2.5.13.18 octetStringOrderingMatch
940 * 2.5.13.19 octetStringSubstringsMatch
941 * 2.5.13.25 uTCTimeMatch
942 * 2.5.13.26 uTCTimeOrderingMatch
943 * 2.5.13.31 directoryStringFirstComponentMatch
944 * 2.5.13.32 wordMatch
945 * 2.5.13.33 keywordMatch
946 * 2.5.13.34 certificateExactMatch
947 * 2.5.13.35 certificateMatch
948 * 2.5.13.36 certificatePairExactMatch
949 * 2.5.13.37 certificatePairMatch
950 * 2.5.13.38 certificateListExactMatch
951 * 2.5.13.39 certificateListMatch
952 * 2.5.13.40 algorithmIdentifierMatch
953 * 2.5.13.41 storedPrefixMatch
954 * 2.5.13.42 attributeCertificateMatch
955 * 2.5.13.43 readerAndKeyIDMatch
956 * 2.5.13.44 attributeIntegrityMatch
959 struct mrule_defs_rec mrule_defs[] = {
960 {"( 2.5.13.0 NAME 'objectIdentifierMatch' SYNTAX 1.3.6.1.4.1.1466.115.121.1.38 )", NULL, NULL},
961 {"( 2.5.13.1 NAME 'distinguishedNameMatch' SYNTAX 1.3.6.1.4.1.1466.115.121.1.12 )", NULL, NULL},
962 {"( 2.5.13.2 NAME 'caseIgnoreMatch' SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 )",
963 case_ignore_normalize, case_ignore_compare},
964 {"( 2.5.13.3 NAME 'caseIgnoreOrderingMatch' SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 )",
965 case_ignore_normalize, case_ignore_compare},
966 {"( 2.5.13.4 NAME 'caseIgnoreSubstringsMatch' SYNTAX 1.3.6.1.4.1.1466.115.121.1.58 )",
967 case_ignore_normalize, case_ignore_compare},
968 /* Next three are not in the RFC's, but are needed for compatibility */
969 {"( 2.5.13.5 NAME 'caseExactMatch' SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 )",
970 case_exact_normalize, case_exact_compare},
971 {"( 2.5.13.6 NAME 'caseExactOrderingMatch' SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 )",
972 case_exact_normalize, case_exact_compare},
973 {"( 2.5.13.7 NAME 'caseExactSubstringsMatch' SYNTAX 1.3.6.1.4.1.1466.115.121.1.58 )",
974 case_exact_normalize, case_exact_compare},
975 {"( 2.5.13.8 NAME 'numericStringMatch' SYNTAX 1.3.6.1.4.1.1466.115.121.1.36 )", NULL, NULL},
976 {"( 2.5.13.10 NAME 'numericStringSubstringsMatch' SYNTAX 1.3.6.1.4.1.1466.115.121.1.58 )", NULL, NULL},
977 {"( 2.5.13.11 NAME 'caseIgnoreListMatch' SYNTAX 1.3.6.1.4.1.1466.115.121.1.41 )", NULL, NULL},
978 {"( 2.5.13.14 NAME 'integerMatch' SYNTAX 1.3.6.1.4.1.1466.115.121.1.27 )", NULL, NULL},
979 {"( 2.5.13.16 NAME 'bitStringMatch' SYNTAX 1.3.6.1.4.1.1466.115.121.1.6 )", NULL, NULL},
980 {"( 2.5.13.17 NAME 'octetStringMatch' SYNTAX 1.3.6.1.4.1.1466.115.121.1.40 )", NULL, NULL},
981 {"( 2.5.13.20 NAME 'telephoneNumberMatch' SYNTAX 1.3.6.1.4.1.1466.115.121.1.50 )", NULL, NULL},
982 {"( 2.5.13.21 NAME 'telephoneNumberSubstringsMatch' SYNTAX 1.3.6.1.4.1.1466.115.121.1.58 )", NULL, NULL},
983 {"( 2.5.13.22 NAME 'presentationAddressMatch' SYNTAX 1.3.6.1.4.1.1466.115.121.1.43 )", NULL, NULL},
984 {"( 2.5.13.23 NAME 'uniqueMemberMatch' SYNTAX 1.3.6.1.4.1.1466.115.121.1.34 )", NULL, NULL},
985 {"( 2.5.13.24 NAME 'protocolInformationMatch' SYNTAX 1.3.6.1.4.1.1466.115.121.1.42 )", NULL, NULL},
986 {"( 2.5.13.27 NAME 'generalizedTimeMatch' SYNTAX 1.3.6.1.4.1.1466.115.121.1.24 )", NULL, NULL},
987 {"( 2.5.13.28 NAME 'generalizedTimeOrderingMatch' SYNTAX 1.3.6.1.4.1.1466.115.121.1.24 )", NULL, NULL},
988 {"( 2.5.13.29 NAME 'integerFirstComponentMatch' SYNTAX 1.3.6.1.4.1.1466.115.121.1.27 )", NULL, NULL},
989 {"( 2.5.13.30 NAME 'objectIdentifierFirstComponentMatch' SYNTAX 1.3.6.1.4.1.1466.115.121.1.38 )", NULL, NULL},
990 {"( 1.3.6.1.4.1.1466.109.114.1 NAME 'caseExactIA5Match' SYNTAX 1.3.6.1.4.1.1466.115.121.1.26 )",
991 case_exact_normalize, case_exact_compare},
992 {"( 1.3.6.1.4.1.1466.109.114.2 NAME 'caseIgnoreIA5Match' SYNTAX 1.3.6.1.4.1.1466.115.121.1.26 )",
993 case_ignore_normalize, case_ignore_compare},
1002 static int schema_init_done = 0;
1004 /* We are called from read_config that is recursive */
1005 if ( schema_init_done )
1007 for ( i=0; syntax_defs[i].sd_desc != NULL; i++ ) {
1008 res = register_syntax( syntax_defs[i].sd_desc,
1009 syntax_defs[i].sd_check );
1011 fprintf( stderr, "schema_init: Error registering syntax %s\n",
1012 syntax_defs[i].sd_desc );
1013 exit( EXIT_FAILURE );
1016 for ( i=0; mrule_defs[i].mrd_desc != NULL; i++ ) {
1017 res = register_matching_rule( mrule_defs[i].mrd_desc,
1018 ( mrule_defs[i].mrd_normalize ?
1019 mrule_defs[i].mrd_normalize : case_ignore_normalize ),
1020 ( mrule_defs[i].mrd_compare ?
1021 mrule_defs[i].mrd_compare : case_ignore_compare ) );
1023 fprintf( stderr, "schema_init: Error registering matching rule %s\n",
1024 mrule_defs[i].mrd_desc );
1025 exit( EXIT_FAILURE );
1028 schema_init_done = 1;
1032 #if defined( SLAPD_SCHEMA_DN )
1035 syn_schema_info( Entry *e )
1038 struct berval *vals[2];
1044 for ( syn = syn_list; syn; syn = syn->ssyn_next ) {
1045 val.bv_val = ldap_syntax2str( &syn->ssyn_syn );
1047 val.bv_len = strlen( val.bv_val );
1048 Debug( LDAP_DEBUG_TRACE, "Merging syn [%d] %s\n",
1049 val.bv_len, val.bv_val, 0 );
1050 attr_merge( e, "ldapSyntaxes", vals );
1051 ldap_memfree( val.bv_val );
1060 mr_schema_info( Entry *e )
1063 struct berval *vals[2];
1069 for ( mr = mr_list; mr; mr = mr->smr_next ) {
1070 val.bv_val = ldap_matchingrule2str( &mr->smr_mrule );
1072 val.bv_len = strlen( val.bv_val );
1073 Debug( LDAP_DEBUG_TRACE, "Merging mr [%d] %s\n",
1074 val.bv_len, val.bv_val, 0 );
1075 attr_merge( e, "matchingRules", vals );
1076 ldap_memfree( val.bv_val );
1085 oc_schema_info( Entry *e )
1088 struct berval *vals[2];
1094 for ( oc = oc_list; oc; oc = oc->soc_next ) {
1095 val.bv_val = ldap_objectclass2str( &oc->soc_oclass );
1097 val.bv_len = strlen( val.bv_val );
1098 Debug( LDAP_DEBUG_TRACE, "Merging oc [%d] %s\n",
1099 val.bv_len, val.bv_val, 0 );
1100 attr_merge( e, "objectClasses", vals );
1101 ldap_memfree( val.bv_val );
1110 schema_info( Connection *conn, Operation *op, char **attrs, int attrsonly )
1114 struct berval *vals[2];
1119 e = (Entry *) ch_calloc( 1, sizeof(Entry) );
1122 e->e_dn = ch_strdup( SLAPD_SCHEMA_DN );
1123 e->e_ndn = ch_strdup( SLAPD_SCHEMA_DN );
1124 (void) dn_normalize_case( e->e_ndn );
1125 e->e_private = NULL;
1128 char *rdn = ch_strdup( SLAPD_SCHEMA_DN );
1129 val.bv_val = strchr( rdn, '=' );
1131 if( val.bv_val != NULL ) {
1133 val.bv_len = strlen( ++val.bv_val );
1135 attr_merge( e, rdn, vals );
1141 if ( syn_schema_info( e ) ) {
1142 /* Out of memory, do something about it */
1146 if ( mr_schema_info( e ) ) {
1147 /* Out of memory, do something about it */
1151 if ( at_schema_info( e ) ) {
1152 /* Out of memory, do something about it */
1156 if ( oc_schema_info( e ) ) {
1157 /* Out of memory, do something about it */
1163 val.bv_len = sizeof("top")-1;
1164 attr_merge( e, "objectClass", vals );
1166 val.bv_val = "subschema";
1167 val.bv_len = sizeof("subschema")-1;
1168 attr_merge( e, "objectClass", vals );
1170 val.bv_val = "extensibleObject";
1171 val.bv_len = sizeof("extensibleObject")-1;
1172 attr_merge( e, "objectClass", vals );
1174 send_search_entry( &backends[0], conn, op,
1175 e, attrs, attrsonly, NULL );
1176 send_search_result( conn, op, LDAP_SUCCESS,
1177 NULL, NULL, NULL, NULL, 1 );
1186 oc_print( ObjectClass *oc )
1190 if ( oc->soc_names && oc->soc_names[0] ) {
1191 printf( "objectclass %s\n", oc->soc_names[0] );
1193 printf( "objectclass %s\n", oc->soc_oid );
1195 if ( oc->soc_required != NULL ) {
1196 printf( "\trequires %s", oc->soc_required[0] );
1197 for ( i = 1; oc->soc_required[i] != NULL; i++ ) {
1198 printf( ",%s", oc->soc_required[i] );
1202 if ( oc->soc_allowed != NULL ) {
1203 printf( "\tallows %s", oc->soc_allowed[0] );
1204 for ( i = 1; oc->soc_allowed[i] != NULL; i++ ) {
1205 printf( ",%s", oc->soc_allowed[i] );
1214 int is_entry_objectclass(
1221 if( e == NULL || oc == NULL || *oc == '\0' )
1225 * find objectClass attribute
1227 attr = attr_find(e->e_attrs, "objectclass");
1229 if( attr == NULL ) {
1230 /* no objectClass attribute */
1235 bv.bv_len = strlen( bv.bv_val );
1237 if( value_find(attr->a_vals, &bv, attr->a_syntax, 1) != 0) {
1238 /* entry is not of this objectclass */