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.
152 /* this list should be extensible */
153 static char *oc_no_usermod_attrs[] = {
155 * Operational and 'no user modification' attributes
170 * check to see if attribute is 'operational' or not.
173 oc_check_operational_attr( char *type )
175 return charray_inlist( oc_operational_attrs, type )
176 || charray_inlist( oc_usermod_attrs, type )
177 || charray_inlist( oc_no_usermod_attrs, type );
181 * check to see if attribute can be user modified or not.
184 oc_check_usermod_attr( char *type )
186 return charray_inlist( oc_usermod_attrs, type );
190 * check to see if attribute is 'no user modification' or not.
193 oc_check_no_usermod_attr( char *type )
195 return charray_inlist( oc_no_usermod_attrs, type );
200 oc_check_allowed( char *type, struct berval **ocl )
207 Debug( LDAP_DEBUG_TRACE,
208 "oc_check_allowed type \"%s\"\n", type, 0, 0 );
210 /* always allow objectclass attribute */
211 if ( strcasecmp( type, "objectclass" ) == 0 ) {
216 * All operational attributions are allowed by schema rules.
217 * However, we only check attributions which are stored in the
218 * the directory regardless if they are user or non-user modified.
220 if ( oc_check_usermod_attr( type ) || oc_check_no_usermod_attr( type ) ) {
224 /* check that the type appears as req or opt in at least one oc */
225 for ( i = 0; ocl[i] != NULL; i++ ) {
226 /* if we know about the oc */
227 if ( (oc = oc_find( ocl[i]->bv_val )) != NULL ) {
228 /* does it require the type? */
229 for ( j = 0; oc->soc_required != NULL &&
230 oc->soc_required[j] != NULL; j++ ) {
231 at = oc->soc_required[j];
233 strcmp(at->sat_oid, type ) == 0 ) {
240 if ( strcasecmp( *pp, type ) == 0 ) {
246 /* does it allow the type? */
247 for ( j = 0; oc->soc_allowed != NULL &&
248 oc->soc_allowed[j] != NULL; j++ ) {
249 at = oc->soc_allowed[j];
251 strcmp(at->sat_oid, type ) == 0 ) {
258 if ( strcasecmp( *pp, type ) == 0 ||
259 strcmp( *pp, "*" ) == 0 ) {
265 /* maybe the next oc allows it */
267 /* we don't know about the oc. assume it allows it */
273 /* not allowed by any oc */
282 static Avlnode *oc_index = NULL;
283 static ObjectClass *oc_list = NULL;
287 struct oindexrec *oir1,
288 struct oindexrec *oir2
291 return (strcasecmp( oir1->oir_name, oir2->oir_name ));
297 struct oindexrec *oir
300 return (strcasecmp( name, oir->oir_name ));
304 oc_find( const char *ocname )
306 struct oindexrec *oir = NULL;
308 if ( (oir = (struct oindexrec *) avl_find( oc_index, ocname,
309 (AVL_CMP) oc_index_name_cmp )) != NULL ) {
310 return( oir->oir_oc );
324 AttributeType **satp;
330 sat = at_find(*attrs1);
333 return SLAP_SCHERR_ATTR_NOT_FOUND;
335 if ( at_find_in_list(sat, soc->soc_required) < 0) {
336 if ( at_append_to_list(sat, &soc->soc_required) ) {
338 return SLAP_SCHERR_OUTOFMEM;
343 /* Now delete duplicates from the allowed list */
344 for ( satp = soc->soc_required; *satp; satp++ ) {
345 i = at_find_in_list(*satp,soc->soc_allowed);
347 at_delete_from_list(i, &soc->soc_allowed);
367 sat = at_find(*attrs1);
370 return SLAP_SCHERR_ATTR_NOT_FOUND;
372 if ( at_find_in_list(sat, soc->soc_required) < 0 &&
373 at_find_in_list(sat, soc->soc_allowed) < 0 ) {
374 if ( at_append_to_list(sat, &soc->soc_allowed) ) {
376 return SLAP_SCHERR_OUTOFMEM;
399 if ( !soc->soc_sups ) {
400 /* We are at the first recursive level */
409 soc->soc_sups = (ObjectClass **)ch_calloc(1,
410 nsups*sizeof(ObjectClass *));
415 soc1 = oc_find(*sups1);
418 return SLAP_SCHERR_CLASS_NOT_FOUND;
422 soc->soc_sups[nsups] = soc1;
424 code = oc_add_sups(soc,soc1->soc_sup_oids, err);
428 if ( code = oc_create_required(soc,
429 soc1->soc_at_oids_must,err) )
431 if ( code = oc_create_allowed(soc,
432 soc1->soc_at_oids_may,err) )
448 struct oindexrec *oir;
452 while ( *ocp != NULL ) {
453 ocp = &(*ocp)->soc_next;
457 if ( soc->soc_oid ) {
458 oir = (struct oindexrec *)
459 ch_calloc( 1, sizeof(struct oindexrec) );
460 oir->oir_name = soc->soc_oid;
462 if ( avl_insert( &oc_index, (caddr_t) oir,
463 (AVL_CMP) oc_index_cmp,
464 (AVL_DUP) avl_dup_error ) ) {
467 return SLAP_SCHERR_DUP_CLASS;
469 /* FIX: temporal consistency check */
470 oc_find(oir->oir_name);
472 if ( (names = soc->soc_names) ) {
474 oir = (struct oindexrec *)
475 ch_calloc( 1, sizeof(struct oindexrec) );
476 oir->oir_name = ch_strdup(*names);
478 if ( avl_insert( &oc_index, (caddr_t) oir,
479 (AVL_CMP) oc_index_cmp,
480 (AVL_DUP) avl_dup_error ) ) {
483 return SLAP_SCHERR_DUP_CLASS;
485 /* FIX: temporal consistency check */
486 oc_find(oir->oir_name);
495 LDAP_OBJECT_CLASS *oc,
502 soc = (ObjectClass *) ch_calloc( 1, sizeof(ObjectClass) );
503 memcpy( &soc->soc_oclass, oc, sizeof(LDAP_OBJECT_CLASS));
504 if ( code = oc_add_sups(soc,soc->soc_sup_oids,err) )
506 if ( code = oc_create_required(soc,soc->soc_at_oids_must,err) )
508 if ( code = oc_create_allowed(soc,soc->soc_at_oids_may,err) )
510 code = oc_insert(soc,err);
519 static Avlnode *syn_index = NULL;
520 static Syntax *syn_list = NULL;
524 struct sindexrec *sir1,
525 struct sindexrec *sir2
528 return (strcmp( sir1->sir_name, sir2->sir_name ));
534 struct sindexrec *sir
537 return (strcmp( name, sir->sir_name ));
541 syn_find( const char *synname )
543 struct sindexrec *sir = NULL;
545 if ( (sir = (struct sindexrec *) avl_find( syn_index, synname,
546 (AVL_CMP) syn_index_name_cmp )) != NULL ) {
547 return( sir->sir_syn );
559 struct sindexrec *sir;
562 while ( *synp != NULL ) {
563 synp = &(*synp)->ssyn_next;
567 if ( ssyn->ssyn_oid ) {
568 sir = (struct sindexrec *)
569 ch_calloc( 1, sizeof(struct sindexrec) );
570 sir->sir_name = ssyn->ssyn_oid;
572 if ( avl_insert( &syn_index, (caddr_t) sir,
573 (AVL_CMP) syn_index_cmp,
574 (AVL_DUP) avl_dup_error ) ) {
575 *err = ssyn->ssyn_oid;
577 return SLAP_SCHERR_DUP_SYNTAX;
579 /* FIX: temporal consistency check */
580 syn_find(sir->sir_name);
588 slap_syntax_check_func *check,
595 ssyn = (Syntax *) ch_calloc( 1, sizeof(Syntax) );
596 memcpy( &ssyn->ssyn_syn, syn, sizeof(LDAP_SYNTAX));
597 ssyn->ssyn_check = check;
598 code = syn_insert(ssyn,err);
604 MatchingRule *mir_mr;
607 static Avlnode *mr_index = NULL;
608 static MatchingRule *mr_list = NULL;
612 struct mindexrec *mir1,
613 struct mindexrec *mir2
616 return (strcmp( mir1->mir_name, mir2->mir_name ));
622 struct mindexrec *mir
625 return (strcmp( name, mir->mir_name ));
629 mr_find( const char *mrname )
631 struct mindexrec *mir = NULL;
633 if ( (mir = (struct mindexrec *) avl_find( mr_index, mrname,
634 (AVL_CMP) mr_index_name_cmp )) != NULL ) {
635 return( mir->mir_mr );
647 struct mindexrec *mir;
651 while ( *mrp != NULL ) {
652 mrp = &(*mrp)->smr_next;
656 if ( smr->smr_oid ) {
657 mir = (struct mindexrec *)
658 ch_calloc( 1, sizeof(struct mindexrec) );
659 mir->mir_name = smr->smr_oid;
661 if ( avl_insert( &mr_index, (caddr_t) mir,
662 (AVL_CMP) mr_index_cmp,
663 (AVL_DUP) avl_dup_error ) ) {
666 return SLAP_SCHERR_DUP_RULE;
668 /* FIX: temporal consistency check */
669 mr_find(mir->mir_name);
671 if ( (names = smr->smr_names) ) {
673 mir = (struct mindexrec *)
674 ch_calloc( 1, sizeof(struct mindexrec) );
675 mir->mir_name = ch_strdup(*names);
677 if ( avl_insert( &mr_index, (caddr_t) mir,
678 (AVL_CMP) mr_index_cmp,
679 (AVL_DUP) avl_dup_error ) ) {
682 return SLAP_SCHERR_DUP_RULE;
684 /* FIX: temporal consistency check */
685 mr_find(mir->mir_name);
694 LDAP_MATCHING_RULE *mr,
695 slap_mr_normalize_func *normalize,
696 slap_mr_compare_func *compare,
704 smr = (MatchingRule *) ch_calloc( 1, sizeof(MatchingRule) );
705 memcpy( &smr->smr_mrule, mr, sizeof(LDAP_MATCHING_RULE));
706 smr->smr_normalize = normalize;
707 smr->smr_compare = compare;
708 if ( smr->smr_syntax_oid ) {
709 if ( (syn = syn_find(smr->smr_syntax_oid)) ) {
710 smr->smr_syntax = syn;
712 *err = smr->smr_syntax_oid;
713 return SLAP_SCHERR_SYN_NOT_FOUND;
717 return SLAP_SCHERR_MR_INCOMPLETE;
719 code = mr_insert(smr,err);
724 case_exact_normalize(
726 struct berval **normalized
729 struct berval *newval;
732 newval = ber_bvdup( val );
733 p = q = newval->bv_val;
734 /* Ignore initial whitespace */
735 while ( isspace( *p++ ) )
738 if ( isspace( *p ) ) {
740 /* Ignore the extra whitespace */
741 while ( isspace(*p++) )
748 * If the string ended in space, backup the pointer one
749 * position. One is enough because the above loop collapsed
750 * all whitespace to a single space.
752 if ( p != newval->bv_val && isspace( *(p-1) ) ) {
755 newval->bv_len = strlen( newval->bv_val );
756 normalized = &newval;
767 return strcmp( val1->bv_val, val2->bv_val );
771 case_ignore_normalize(
773 struct berval **normalized
776 struct berval *newval;
779 newval = ber_bvdup( val );
780 p = q = newval->bv_val;
781 /* Ignore initial whitespace */
782 while ( isspace( *p++ ) )
785 if ( isspace( *p ) ) {
787 /* Ignore the extra whitespace */
788 while ( isspace(*p++) )
791 *q++ = TOUPPER( *p++ );
795 * If the string ended in space, backup the pointer one
796 * position. One is enough because the above loop collapsed
797 * all whitespace to a single space.
799 if ( p != newval->bv_val && isspace( *(p-1) ) ) {
802 newval->bv_len = strlen( newval->bv_val );
803 normalized = &newval;
814 return strcasecmp( val1->bv_val, val2->bv_val );
820 slap_syntax_check_func *check )
826 syn = ldap_str2syntax( desc, &code, &err);
828 Debug( LDAP_DEBUG_ANY, "Error in register_syntax: %s before %s in %s\n",
829 ldap_scherr2str(code), err, desc );
832 code = syn_add( syn, check, &err );
834 Debug( LDAP_DEBUG_ANY, "Error in register_syntax: %s %s in %s\n",
835 scherr2str(code), err, desc );
842 register_matching_rule(
844 slap_mr_normalize_func *normalize,
845 slap_mr_compare_func *compare )
847 LDAP_MATCHING_RULE *mr;
851 mr = ldap_str2matchingrule( desc, &code, &err);
853 Debug( LDAP_DEBUG_ANY, "Error in register_matching_rule: %s before %s in %s\n",
854 ldap_scherr2str(code), err, desc );
857 code = mr_add( mr, normalize, compare, &err );
859 Debug( LDAP_DEBUG_ANY, "Error in register_syntax: %s for %s in %s\n",
860 scherr2str(code), err, desc );
866 struct syntax_defs_rec {
868 slap_syntax_check_func *sd_check;
871 struct syntax_defs_rec syntax_defs[] = {
872 {"( 1.3.6.1.4.1.1466.115.121.1.3 DESC 'Attribute Type Description' )", NULL},
873 {"( 1.3.6.1.4.1.1466.115.121.1.4 DESC 'Audio' )", NULL},
874 {"( 1.3.6.1.4.1.1466.115.121.1.5 DESC 'Binary' )", NULL},
875 {"( 1.3.6.1.4.1.1466.115.121.1.6 DESC 'Bit String' )", NULL},
876 {"( 1.3.6.1.4.1.1466.115.121.1.8 DESC 'Certificate' )", NULL},
877 {"( 1.3.6.1.4.1.1466.115.121.1.9 DESC 'Certificate List' )", NULL},
878 {"( 1.3.6.1.4.1.1466.115.121.1.10 DESC 'Certificate Pair' )", NULL},
879 {"( 1.3.6.1.4.1.1466.115.121.1.12 DESC 'DN' )", NULL},
880 {"( 1.3.6.1.4.1.1466.115.121.1.14 DESC 'Delivery Method' )", NULL},
881 {"( 1.3.6.1.4.1.1466.115.121.1.15 DESC 'Directory String' )", NULL},
882 {"( 1.3.6.1.4.1.1466.115.121.1.16 DESC 'DIT Content Rule Description' )", NULL},
883 {"( 1.3.6.1.4.1.1466.115.121.1.17 DESC 'DIT Structure Rule Description' )", NULL},
884 {"( 1.3.6.1.4.1.1466.115.121.1.21 DESC 'Enhanced Guide' )", NULL},
885 {"( 1.3.6.1.4.1.1466.115.121.1.22 DESC 'Facsimile Telephone Number' )", NULL},
886 {"( 1.3.6.1.4.1.1466.115.121.1.24 DESC 'Generalized Time' )", NULL},
887 {"( 1.3.6.1.4.1.1466.115.121.1.25 DESC 'Guide' )", NULL},
888 {"( 1.3.6.1.4.1.1466.115.121.1.26 DESC 'IA5 String' )", NULL},
889 {"( 1.3.6.1.4.1.1466.115.121.1.27 DESC 'INTEGER' )", NULL},
890 {"( 1.3.6.1.4.1.1466.115.121.1.30 DESC 'Matching Rule Description' )", NULL},
891 {"( 1.3.6.1.4.1.1466.115.121.1.31 DESC 'Matching Rule Use Description' )", NULL},
892 {"( 1.3.6.1.4.1.1466.115.121.1.32 DESC 'Mail Preference' )", NULL},
893 {"( 1.3.6.1.4.1.1466.115.121.1.34 DESC 'Name And Optional UID' )", NULL},
894 {"( 1.3.6.1.4.1.1466.115.121.1.35 DESC 'Name Form Description' )", NULL},
895 {"( 1.3.6.1.4.1.1466.115.121.1.36 DESC 'Numeric String' )", NULL},
896 {"( 1.3.6.1.4.1.1466.115.121.1.37 DESC 'Object Class Description' )", NULL},
897 {"( 1.3.6.1.4.1.1466.115.121.1.38 DESC 'OID' )", NULL},
898 {"( 1.3.6.1.4.1.1466.115.121.1.39 DESC 'Other Mailbox' )", NULL},
899 {"( 1.3.6.1.4.1.1466.115.121.1.40 DESC 'Octet String' )", NULL},
900 {"( 1.3.6.1.4.1.1466.115.121.1.41 DESC 'Postal Address' )", NULL},
901 {"( 1.3.6.1.4.1.1466.115.121.1.42 DESC 'Protocol Information' )", NULL},
902 {"( 1.3.6.1.4.1.1466.115.121.1.43 DESC 'Presentation Address' )", NULL},
903 {"( 1.3.6.1.4.1.1466.115.121.1.44 DESC 'Printable String' )", NULL},
904 {"( 1.3.6.1.4.1.1466.115.121.1.49 DESC 'Supported Algorithm' )", NULL},
905 {"( 1.3.6.1.4.1.1466.115.121.1.50 DESC 'Telephone Number' )", NULL},
906 {"( 1.3.6.1.4.1.1466.115.121.1.51 DESC 'Teletex Terminal Identifier' )", NULL},
907 {"( 1.3.6.1.4.1.1466.115.121.1.52 DESC 'Telex Number' )", NULL},
908 {"( 1.3.6.1.4.1.1466.115.121.1.53 DESC 'UTC Time' )", NULL},
909 {"( 1.3.6.1.4.1.1466.115.121.1.54 DESC 'LDAP Syntax Description' )", NULL},
910 {"( 1.3.6.1.4.1.1466.115.121.1.58 DESC 'Substring Assertion' )", NULL},
911 {"( 1.3.6.1.1.1.0.0 DESC 'NIS netgroup triple' )", NULL},
912 {"( 1.3.6.1.1.1.0.1 DESC 'Boot parameter' )", NULL},
916 struct mrule_defs_rec {
918 slap_mr_normalize_func *mrd_normalize;
919 slap_mr_compare_func *mrd_compare;
923 * Other matching rules in X.520 that we do not use:
925 * 2.5.13.9 numericStringOrderingMatch
926 * 2.5.13.12 caseIgnoreListSubstringsMatch
927 * 2.5.13.13 booleanMatch
928 * 2.5.13.15 integerOrderingMatch
929 * 2.5.13.18 octetStringOrderingMatch
930 * 2.5.13.19 octetStringSubstringsMatch
931 * 2.5.13.25 uTCTimeMatch
932 * 2.5.13.26 uTCTimeOrderingMatch
933 * 2.5.13.31 directoryStringFirstComponentMatch
934 * 2.5.13.32 wordMatch
935 * 2.5.13.33 keywordMatch
936 * 2.5.13.34 certificateExactMatch
937 * 2.5.13.35 certificateMatch
938 * 2.5.13.36 certificatePairExactMatch
939 * 2.5.13.37 certificatePairMatch
940 * 2.5.13.38 certificateListExactMatch
941 * 2.5.13.39 certificateListMatch
942 * 2.5.13.40 algorithmIdentifierMatch
943 * 2.5.13.41 storedPrefixMatch
944 * 2.5.13.42 attributeCertificateMatch
945 * 2.5.13.43 readerAndKeyIDMatch
946 * 2.5.13.44 attributeIntegrityMatch
949 struct mrule_defs_rec mrule_defs[] = {
950 {"( 2.5.13.0 NAME 'objectIdentifierMatch' SYNTAX 1.3.6.1.4.1.1466.115.121.1.38 )", NULL, NULL},
951 {"( 2.5.13.1 NAME 'distinguishedNameMatch' SYNTAX 1.3.6.1.4.1.1466.115.121.1.12 )", NULL, NULL},
952 {"( 2.5.13.2 NAME 'caseIgnoreMatch' SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 )",
953 case_ignore_normalize, case_ignore_compare},
954 {"( 2.5.13.3 NAME 'caseIgnoreOrderingMatch' SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 )",
955 case_ignore_normalize, case_ignore_compare},
956 {"( 2.5.13.4 NAME 'caseIgnoreSubstringsMatch' SYNTAX 1.3.6.1.4.1.1466.115.121.1.58 )",
957 case_ignore_normalize, case_ignore_compare},
958 /* Next three are not in the RFC's, but are needed for compatibility */
959 {"( 2.5.13.5 NAME 'caseExactMatch' SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 )",
960 case_exact_normalize, case_exact_compare},
961 {"( 2.5.13.6 NAME 'caseExactOrderingMatch' SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 )",
962 case_exact_normalize, case_exact_compare},
963 {"( 2.5.13.7 NAME 'caseExactSubstringsMatch' SYNTAX 1.3.6.1.4.1.1466.115.121.1.58 )",
964 case_exact_normalize, case_exact_compare},
965 {"( 2.5.13.8 NAME 'numericStringMatch' SYNTAX 1.3.6.1.4.1.1466.115.121.1.36 )", NULL, NULL},
966 {"( 2.5.13.10 NAME 'numericStringSubstringsMatch' SYNTAX 1.3.6.1.4.1.1466.115.121.1.58 )", NULL, NULL},
967 {"( 2.5.13.11 NAME 'caseIgnoreListMatch' SYNTAX 1.3.6.1.4.1.1466.115.121.1.41 )", NULL, NULL},
968 {"( 2.5.13.14 NAME 'integerMatch' SYNTAX 1.3.6.1.4.1.1466.115.121.1.27 )", NULL, NULL},
969 {"( 2.5.13.16 NAME 'bitStringMatch' SYNTAX 1.3.6.1.4.1.1466.115.121.1.6 )", NULL, NULL},
970 {"( 2.5.13.17 NAME 'octetStringMatch' SYNTAX 1.3.6.1.4.1.1466.115.121.1.40 )", NULL, NULL},
971 {"( 2.5.13.20 NAME 'telephoneNumberMatch' SYNTAX 1.3.6.1.4.1.1466.115.121.1.50 )", NULL, NULL},
972 {"( 2.5.13.21 NAME 'telephoneNumberSubstringsMatch' SYNTAX 1.3.6.1.4.1.1466.115.121.1.58 )", NULL, NULL},
973 {"( 2.5.13.22 NAME 'presentationAddressMatch' SYNTAX 1.3.6.1.4.1.1466.115.121.1.43 )", NULL, NULL},
974 {"( 2.5.13.23 NAME 'uniqueMemberMatch' SYNTAX 1.3.6.1.4.1.1466.115.121.1.34 )", NULL, NULL},
975 {"( 2.5.13.24 NAME 'protocolInformationMatch' SYNTAX 1.3.6.1.4.1.1466.115.121.1.42 )", NULL, NULL},
976 {"( 2.5.13.27 NAME 'generalizedTimeMatch' SYNTAX 1.3.6.1.4.1.1466.115.121.1.24 )", NULL, NULL},
977 {"( 2.5.13.28 NAME 'generalizedTimeOrderingMatch' SYNTAX 1.3.6.1.4.1.1466.115.121.1.24 )", NULL, NULL},
978 {"( 2.5.13.29 NAME 'integerFirstComponentMatch' SYNTAX 1.3.6.1.4.1.1466.115.121.1.27 )", NULL, NULL},
979 {"( 2.5.13.30 NAME 'objectIdentifierFirstComponentMatch' SYNTAX 1.3.6.1.4.1.1466.115.121.1.38 )", NULL, NULL},
980 {"( 1.3.6.1.4.1.1466.109.114.1 NAME 'caseExactIA5Match' SYNTAX 1.3.6.1.4.1.1466.115.121.1.26 )",
981 case_exact_normalize, case_exact_compare},
982 {"( 1.3.6.1.4.1.1466.109.114.2 NAME 'caseIgnoreIA5Match' SYNTAX 1.3.6.1.4.1.1466.115.121.1.26 )",
983 case_ignore_normalize, case_ignore_compare},
992 static int schema_init_done = 0;
994 /* We are called from read_config that is recursive */
995 if ( schema_init_done )
997 for ( i=0; syntax_defs[i].sd_desc != NULL; i++ ) {
998 res = register_syntax( syntax_defs[i].sd_desc,
999 syntax_defs[i].sd_check );
1001 fprintf( stderr, "schema_init: Error registering syntax %s\n",
1002 syntax_defs[i].sd_desc );
1006 for ( i=0; mrule_defs[i].mrd_desc != NULL; i++ ) {
1007 res = register_matching_rule( mrule_defs[i].mrd_desc,
1008 ( mrule_defs[i].mrd_normalize ?
1009 mrule_defs[i].mrd_normalize : case_ignore_normalize ),
1010 ( mrule_defs[i].mrd_compare ?
1011 mrule_defs[i].mrd_compare : case_ignore_compare ) );
1013 fprintf( stderr, "schema_init: Error registering matching rule %s\n",
1014 mrule_defs[i].mrd_desc );
1018 schema_init_done = 1;
1022 #if defined( SLAPD_SCHEMA_DN )
1025 syn_schema_info( Entry *e )
1028 struct berval *vals[2];
1034 for ( syn = syn_list; syn; syn = syn->ssyn_next ) {
1035 val.bv_val = ldap_syntax2str( &syn->ssyn_syn );
1037 val.bv_len = strlen( val.bv_val );
1038 Debug( LDAP_DEBUG_TRACE, "Merging syn [%d] %s\n",
1039 val.bv_len, val.bv_val, 0 );
1040 attr_merge( e, "ldapSyntaxes", vals );
1041 ldap_memfree( val.bv_val );
1050 mr_schema_info( Entry *e )
1053 struct berval *vals[2];
1059 for ( mr = mr_list; mr; mr = mr->smr_next ) {
1060 val.bv_val = ldap_matchingrule2str( &mr->smr_mrule );
1062 val.bv_len = strlen( val.bv_val );
1063 Debug( LDAP_DEBUG_TRACE, "Merging mr [%d] %s\n",
1064 val.bv_len, val.bv_val, 0 );
1065 attr_merge( e, "matchingRules", vals );
1066 ldap_memfree( val.bv_val );
1075 oc_schema_info( Entry *e )
1078 struct berval *vals[2];
1084 for ( oc = oc_list; oc; oc = oc->soc_next ) {
1085 val.bv_val = ldap_objectclass2str( &oc->soc_oclass );
1087 val.bv_len = strlen( val.bv_val );
1088 Debug( LDAP_DEBUG_TRACE, "Merging oc [%d] %s\n",
1089 val.bv_len, val.bv_val, 0 );
1090 attr_merge( e, "objectClasses", vals );
1091 ldap_memfree( val.bv_val );
1100 schema_info( Connection *conn, Operation *op, char **attrs, int attrsonly )
1104 struct berval *vals[2];
1109 e = (Entry *) ch_calloc( 1, sizeof(Entry) );
1112 e->e_dn = ch_strdup( SLAPD_SCHEMA_DN );
1113 e->e_ndn = ch_strdup( SLAPD_SCHEMA_DN );
1114 (void) dn_normalize_case( e->e_ndn );
1115 e->e_private = NULL;
1117 val.bv_val = ch_strdup( "top" );
1118 val.bv_len = strlen( val.bv_val );
1119 attr_merge( e, "objectClass", vals );
1120 ldap_memfree( val.bv_val );
1122 val.bv_val = ch_strdup( "subschema" );
1123 val.bv_len = strlen( val.bv_val );
1124 attr_merge( e, "objectClass", vals );
1125 ldap_memfree( val.bv_val );
1127 if ( syn_schema_info( e ) ) {
1128 /* Out of memory, do something about it */
1132 if ( mr_schema_info( e ) ) {
1133 /* Out of memory, do something about it */
1137 if ( at_schema_info( e ) ) {
1138 /* Out of memory, do something about it */
1142 if ( oc_schema_info( e ) ) {
1143 /* Out of memory, do something about it */
1148 send_search_entry( &backends[0], conn, op,
1149 e, attrs, attrsonly, 0, NULL );
1150 send_search_result( conn, op, LDAP_SUCCESS,
1151 NULL, NULL, NULL, NULL, 1 );
1160 oc_print( ObjectClass *oc )
1164 if ( oc->soc_names && oc->soc_names[0] ) {
1165 printf( "objectclass %s\n", oc->soc_names[0] );
1167 printf( "objectclass %s\n", oc->soc_oid );
1169 if ( oc->soc_required != NULL ) {
1170 printf( "\trequires %s", oc->soc_required[0] );
1171 for ( i = 1; oc->soc_required[i] != NULL; i++ ) {
1172 printf( ",%s", oc->soc_required[i] );
1176 if ( oc->soc_allowed != NULL ) {
1177 printf( "\tallows %s", oc->soc_allowed[0] );
1178 for ( i = 1; oc->soc_allowed[i] != NULL; i++ ) {
1179 printf( ",%s", oc->soc_allowed[i] );
1188 int is_entry_objectclass(
1195 if( e == NULL || oc == NULL || *oc == '\0' )
1199 * find objectClass attribute
1201 attr = attr_find(e->e_attrs, "objectclass");
1203 if( attr == NULL ) {
1204 /* no objectClass attribute */
1209 bv.bv_len = strlen( bv.bv_val );
1211 if( value_find(attr->a_vals, &bv, attr->a_syntax, 1) != 0) {
1212 /* entry is not of this objectclass */