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 )
36 /* find the object class attribute - could error out here */
37 if ( (aoc = attr_find( e->e_attrs, "objectclass" )) == NULL ) {
38 Debug( LDAP_DEBUG_ANY, "No object class for entry (%s)\n",
43 /* check that the entry has required attrs for each oc */
44 for ( i = 0; aoc->a_vals[i] != NULL; i++ ) {
45 if ( (oc = oc_find( aoc->a_vals[i]->bv_val )) == NULL ) {
46 Debug( LDAP_DEBUG_ANY,
47 "Objectclass \"%s\" not defined",
48 aoc->a_vals[i]->bv_val, 0, 0 );
53 char *s = oc_check_required( e, aoc->a_vals[i]->bv_val );
56 Debug( LDAP_DEBUG_ANY,
57 "Entry (%s), oc \"%s\" requires attr \"%s\"\n",
58 e->e_dn, aoc->a_vals[i]->bv_val, s );
68 /* check that each attr in the entry is allowed by some oc */
69 for ( a = e->e_attrs; a != NULL; a = a->a_next ) {
70 if ( oc_check_allowed( a->a_type, aoc->a_vals ) != 0 ) {
71 Debug( LDAP_DEBUG_ANY,
72 "Entry (%s), attr \"%s\" not allowed\n",
73 e->e_dn, a->a_type, 0 );
82 oc_check_required( Entry *e, char *ocname )
90 Debug( LDAP_DEBUG_TRACE,
91 "oc_check_required entry (%s), objectclass \"%s\"\n",
94 /* find global oc defn. it we don't know about it assume it's ok */
95 if ( (oc = oc_find( ocname )) == NULL ) {
99 /* check for empty oc_required */
100 if(oc->soc_required == NULL) {
104 /* for each required attribute */
105 for ( i = 0; oc->soc_required[i] != NULL; i++ ) {
106 at = oc->soc_required[i];
107 /* see if it's in the entry */
108 for ( a = e->e_attrs; a != NULL; a = a->a_next ) {
110 strcmp( a->a_type, at->sat_oid ) == 0 ) {
115 /* Empty name list => not found */
120 if ( strcasecmp( a->a_type, *pp ) == 0 ) {
129 /* not there => schema violation */
131 if ( at->sat_names && at->sat_names[0] ) {
132 return at->sat_names[0];
142 static char *oc_usermod_attrs[] = {
144 * OpenLDAP doesn't support any user modification of
145 * operational attributes.
150 static char *oc_operational_attrs[] = {
152 * these are operational attributes
153 * most could be user modifiable
164 "supportedExtension",
166 "supportedSASLMechanisms",
167 "supportedLDAPversion",
168 "subschemaSubentry", /* NO USER MOD */
173 /* this list should be extensible */
174 static char *oc_no_usermod_attrs[] = {
176 * Operational and 'no user modification' attributes
177 * which are STORED in the directory server.
191 * check to see if attribute is 'operational' or not.
194 oc_check_operational_attr( const char *type )
196 return charray_inlist( oc_operational_attrs, type )
197 || charray_inlist( oc_usermod_attrs, type )
198 || charray_inlist( oc_no_usermod_attrs, type );
202 * check to see if attribute can be user modified or not.
205 oc_check_usermod_attr( const char *type )
207 return charray_inlist( oc_usermod_attrs, type );
211 * check to see if attribute is 'no user modification' or not.
214 oc_check_no_usermod_attr( const char *type )
216 return charray_inlist( oc_no_usermod_attrs, type );
221 oc_check_allowed( char *type, struct berval **ocl )
228 Debug( LDAP_DEBUG_TRACE,
229 "oc_check_allowed type \"%s\"\n", type, 0, 0 );
231 /* always allow objectclass attribute */
232 if ( strcasecmp( type, "objectclass" ) == 0 ) {
237 * All operational attributions are allowed by schema rules.
238 * However, we only check attributions which are stored in the
239 * the directory regardless if they are user or non-user modified.
241 if ( oc_check_usermod_attr( type ) || oc_check_no_usermod_attr( type ) ) {
245 /* check that the type appears as req or opt in at least one oc */
246 for ( i = 0; ocl[i] != NULL; i++ ) {
247 /* if we know about the oc */
248 if ( (oc = oc_find( ocl[i]->bv_val )) != NULL ) {
249 /* does it require the type? */
250 for ( j = 0; oc->soc_required != NULL &&
251 oc->soc_required[j] != NULL; j++ ) {
252 at = oc->soc_required[j];
254 strcmp(at->sat_oid, type ) == 0 ) {
261 if ( strcasecmp( *pp, type ) == 0 ) {
267 /* does it allow the type? */
268 for ( j = 0; oc->soc_allowed != NULL &&
269 oc->soc_allowed[j] != NULL; j++ ) {
270 at = oc->soc_allowed[j];
272 strcmp(at->sat_oid, type ) == 0 ) {
279 if ( strcasecmp( *pp, type ) == 0 ||
280 strcmp( *pp, "*" ) == 0 ) {
286 /* maybe the next oc allows it */
288 /* we don't know about the oc. assume it allows it */
294 /* not allowed by any oc */
303 static Avlnode *oc_index = NULL;
304 static ObjectClass *oc_list = NULL;
308 struct oindexrec *oir1,
309 struct oindexrec *oir2
312 return (strcasecmp( oir1->oir_name, oir2->oir_name ));
318 struct oindexrec *oir
321 return (strcasecmp( name, oir->oir_name ));
325 oc_find( const char *ocname )
327 struct oindexrec *oir = NULL;
329 if ( (oir = (struct oindexrec *) avl_find( oc_index, ocname,
330 (AVL_CMP) oc_index_name_cmp )) != NULL ) {
331 return( oir->oir_oc );
345 AttributeType **satp;
351 sat = at_find(*attrs1);
354 return SLAP_SCHERR_ATTR_NOT_FOUND;
356 if ( at_find_in_list(sat, soc->soc_required) < 0) {
357 if ( at_append_to_list(sat, &soc->soc_required) ) {
359 return SLAP_SCHERR_OUTOFMEM;
364 /* Now delete duplicates from the allowed list */
365 for ( satp = soc->soc_required; *satp; satp++ ) {
366 i = at_find_in_list(*satp,soc->soc_allowed);
368 at_delete_from_list(i, &soc->soc_allowed);
388 sat = at_find(*attrs1);
391 return SLAP_SCHERR_ATTR_NOT_FOUND;
393 if ( at_find_in_list(sat, soc->soc_required) < 0 &&
394 at_find_in_list(sat, soc->soc_allowed) < 0 ) {
395 if ( at_append_to_list(sat, &soc->soc_allowed) ) {
397 return SLAP_SCHERR_OUTOFMEM;
420 if ( !soc->soc_sups ) {
421 /* We are at the first recursive level */
430 soc->soc_sups = (ObjectClass **)ch_calloc(1,
431 nsups*sizeof(ObjectClass *));
436 soc1 = oc_find(*sups1);
439 return SLAP_SCHERR_CLASS_NOT_FOUND;
443 soc->soc_sups[nsups] = soc1;
445 code = oc_add_sups(soc,soc1->soc_sup_oids, err);
449 if ( code = oc_create_required(soc,
450 soc1->soc_at_oids_must,err) )
452 if ( code = oc_create_allowed(soc,
453 soc1->soc_at_oids_may,err) )
469 struct oindexrec *oir;
473 while ( *ocp != NULL ) {
474 ocp = &(*ocp)->soc_next;
478 if ( soc->soc_oid ) {
479 oir = (struct oindexrec *)
480 ch_calloc( 1, sizeof(struct oindexrec) );
481 oir->oir_name = soc->soc_oid;
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);
493 if ( (names = soc->soc_names) ) {
495 oir = (struct oindexrec *)
496 ch_calloc( 1, sizeof(struct oindexrec) );
497 oir->oir_name = ch_strdup(*names);
499 if ( avl_insert( &oc_index, (caddr_t) oir,
500 (AVL_CMP) oc_index_cmp,
501 (AVL_DUP) avl_dup_error ) ) {
504 return SLAP_SCHERR_DUP_CLASS;
506 /* FIX: temporal consistency check */
507 oc_find(oir->oir_name);
516 LDAP_OBJECT_CLASS *oc,
523 soc = (ObjectClass *) ch_calloc( 1, sizeof(ObjectClass) );
524 memcpy( &soc->soc_oclass, oc, sizeof(LDAP_OBJECT_CLASS));
525 if ( code = oc_add_sups(soc,soc->soc_sup_oids,err) )
527 if ( code = oc_create_required(soc,soc->soc_at_oids_must,err) )
529 if ( code = oc_create_allowed(soc,soc->soc_at_oids_may,err) )
531 code = oc_insert(soc,err);
540 static Avlnode *syn_index = NULL;
541 static Syntax *syn_list = NULL;
545 struct sindexrec *sir1,
546 struct sindexrec *sir2
549 return (strcmp( sir1->sir_name, sir2->sir_name ));
555 struct sindexrec *sir
558 return (strcmp( name, sir->sir_name ));
562 syn_find( const char *synname )
564 struct sindexrec *sir = NULL;
566 if ( (sir = (struct sindexrec *) avl_find( syn_index, synname,
567 (AVL_CMP) syn_index_name_cmp )) != NULL ) {
568 return( sir->sir_syn );
574 syn_find_desc( const char *syndesc, int *len )
578 for (synp = syn_list; synp; synp = synp->ssyn_next)
579 if ((*len = dscompare( synp->ssyn_syn.syn_desc, syndesc, '{')))
591 struct sindexrec *sir;
594 while ( *synp != NULL ) {
595 synp = &(*synp)->ssyn_next;
599 if ( ssyn->ssyn_oid ) {
600 sir = (struct sindexrec *)
601 ch_calloc( 1, sizeof(struct sindexrec) );
602 sir->sir_name = ssyn->ssyn_oid;
604 if ( avl_insert( &syn_index, (caddr_t) sir,
605 (AVL_CMP) syn_index_cmp,
606 (AVL_DUP) avl_dup_error ) ) {
607 *err = ssyn->ssyn_oid;
609 return SLAP_SCHERR_DUP_SYNTAX;
611 /* FIX: temporal consistency check */
612 syn_find(sir->sir_name);
620 slap_syntax_check_func *check,
627 ssyn = (Syntax *) ch_calloc( 1, sizeof(Syntax) );
628 memcpy( &ssyn->ssyn_syn, syn, sizeof(LDAP_SYNTAX));
629 ssyn->ssyn_check = check;
630 code = syn_insert(ssyn,err);
636 MatchingRule *mir_mr;
639 static Avlnode *mr_index = NULL;
640 static MatchingRule *mr_list = NULL;
644 struct mindexrec *mir1,
645 struct mindexrec *mir2
648 return (strcmp( mir1->mir_name, mir2->mir_name ));
654 struct mindexrec *mir
657 return (strcmp( name, mir->mir_name ));
661 mr_find( const char *mrname )
663 struct mindexrec *mir = NULL;
665 if ( (mir = (struct mindexrec *) avl_find( mr_index, mrname,
666 (AVL_CMP) mr_index_name_cmp )) != NULL ) {
667 return( mir->mir_mr );
679 struct mindexrec *mir;
683 while ( *mrp != NULL ) {
684 mrp = &(*mrp)->smr_next;
688 if ( smr->smr_oid ) {
689 mir = (struct mindexrec *)
690 ch_calloc( 1, sizeof(struct mindexrec) );
691 mir->mir_name = smr->smr_oid;
693 if ( avl_insert( &mr_index, (caddr_t) mir,
694 (AVL_CMP) mr_index_cmp,
695 (AVL_DUP) avl_dup_error ) ) {
698 return SLAP_SCHERR_DUP_RULE;
700 /* FIX: temporal consistency check */
701 mr_find(mir->mir_name);
703 if ( (names = smr->smr_names) ) {
705 mir = (struct mindexrec *)
706 ch_calloc( 1, sizeof(struct mindexrec) );
707 mir->mir_name = ch_strdup(*names);
709 if ( avl_insert( &mr_index, (caddr_t) mir,
710 (AVL_CMP) mr_index_cmp,
711 (AVL_DUP) avl_dup_error ) ) {
714 return SLAP_SCHERR_DUP_RULE;
716 /* FIX: temporal consistency check */
717 mr_find(mir->mir_name);
726 LDAP_MATCHING_RULE *mr,
727 slap_mr_normalize_func *normalize,
728 slap_mr_compare_func *compare,
736 smr = (MatchingRule *) ch_calloc( 1, sizeof(MatchingRule) );
737 memcpy( &smr->smr_mrule, mr, sizeof(LDAP_MATCHING_RULE));
738 smr->smr_normalize = normalize;
739 smr->smr_compare = compare;
740 if ( smr->smr_syntax_oid ) {
741 if ( (syn = syn_find(smr->smr_syntax_oid)) ) {
742 smr->smr_syntax = syn;
744 *err = smr->smr_syntax_oid;
745 return SLAP_SCHERR_SYN_NOT_FOUND;
749 return SLAP_SCHERR_MR_INCOMPLETE;
751 code = mr_insert(smr,err);
756 case_exact_normalize(
758 struct berval **normalized
761 struct berval *newval;
764 newval = ber_bvdup( val );
765 p = q = newval->bv_val;
766 /* Ignore initial whitespace */
767 while ( isspace( *p++ ) )
770 if ( isspace( *p ) ) {
772 /* Ignore the extra whitespace */
773 while ( isspace(*p++) )
780 * If the string ended in space, backup the pointer one
781 * position. One is enough because the above loop collapsed
782 * all whitespace to a single space.
784 if ( p != newval->bv_val && isspace( *(p-1) ) ) {
787 newval->bv_len = strlen( newval->bv_val );
788 normalized = &newval;
799 return strcmp( val1->bv_val, val2->bv_val );
803 case_ignore_normalize(
805 struct berval **normalized
808 struct berval *newval;
811 newval = ber_bvdup( val );
812 p = q = newval->bv_val;
813 /* Ignore initial whitespace */
814 while ( isspace( *p++ ) )
817 if ( isspace( *p ) ) {
819 /* Ignore the extra whitespace */
820 while ( isspace(*p++) )
823 *q++ = TOUPPER( *p++ );
827 * If the string ended in space, backup the pointer one
828 * position. One is enough because the above loop collapsed
829 * all whitespace to a single space.
831 if ( p != newval->bv_val && isspace( *(p-1) ) ) {
834 newval->bv_len = strlen( newval->bv_val );
835 normalized = &newval;
846 return strcasecmp( val1->bv_val, val2->bv_val );
852 slap_syntax_check_func *check )
858 syn = ldap_str2syntax( desc, &code, &err);
860 Debug( LDAP_DEBUG_ANY, "Error in register_syntax: %s before %s in %s\n",
861 ldap_scherr2str(code), err, desc );
864 code = syn_add( syn, check, &err );
866 Debug( LDAP_DEBUG_ANY, "Error in register_syntax: %s %s in %s\n",
867 scherr2str(code), err, desc );
874 register_matching_rule(
876 slap_mr_normalize_func *normalize,
877 slap_mr_compare_func *compare )
879 LDAP_MATCHING_RULE *mr;
883 mr = ldap_str2matchingrule( desc, &code, &err);
885 Debug( LDAP_DEBUG_ANY, "Error in register_matching_rule: %s before %s in %s\n",
886 ldap_scherr2str(code), err, desc );
889 code = mr_add( mr, normalize, compare, &err );
891 Debug( LDAP_DEBUG_ANY, "Error in register_syntax: %s for %s in %s\n",
892 scherr2str(code), err, desc );
898 struct syntax_defs_rec {
900 slap_syntax_check_func *sd_check;
903 struct syntax_defs_rec syntax_defs[] = {
904 {"( 1.3.6.1.4.1.1466.115.121.1.3 DESC 'AttributeTypeDescription' )", NULL},
905 {"( 1.3.6.1.4.1.1466.115.121.1.4 DESC 'Audio' )", NULL},
906 {"( 1.3.6.1.4.1.1466.115.121.1.5 DESC 'Binary' )", NULL},
907 {"( 1.3.6.1.4.1.1466.115.121.1.6 DESC 'BitString' )", NULL},
908 {"( 1.3.6.1.4.1.1466.115.121.1.8 DESC 'Certificate' )", NULL},
909 {"( 1.3.6.1.4.1.1466.115.121.1.9 DESC 'CertificateList' )", NULL},
910 {"( 1.3.6.1.4.1.1466.115.121.1.10 DESC 'CertificatePair' )", NULL},
911 {"( 1.3.6.1.4.1.1466.115.121.1.12 DESC 'DN' )", NULL},
912 {"( 1.3.6.1.4.1.1466.115.121.1.14 DESC 'DeliveryMethod' )", NULL},
913 {"( 1.3.6.1.4.1.1466.115.121.1.15 DESC 'DirectoryString' )", NULL},
914 {"( 1.3.6.1.4.1.1466.115.121.1.16 DESC 'DITContentRuleDescription' )", NULL},
915 {"( 1.3.6.1.4.1.1466.115.121.1.17 DESC 'DITStructureRuleDescription' )", NULL},
916 {"( 1.3.6.1.4.1.1466.115.121.1.21 DESC 'EnhancedGuide' )", NULL},
917 {"( 1.3.6.1.4.1.1466.115.121.1.22 DESC 'FacsimileTelephoneNumber' )", NULL},
918 {"( 1.3.6.1.4.1.1466.115.121.1.24 DESC 'GeneralizedTime' )", NULL},
919 {"( 1.3.6.1.4.1.1466.115.121.1.25 DESC 'Guide' )", NULL},
920 {"( 1.3.6.1.4.1.1466.115.121.1.26 DESC 'IA5String' )", NULL},
921 {"( 1.3.6.1.4.1.1466.115.121.1.27 DESC 'Integer' )", NULL},
922 {"( 1.3.6.1.4.1.1466.115.121.1.30 DESC 'MatchingRuleDescription' )", NULL},
923 {"( 1.3.6.1.4.1.1466.115.121.1.31 DESC 'MatchingRuleUseDescription' )", NULL},
924 {"( 1.3.6.1.4.1.1466.115.121.1.32 DESC 'MailPreference' )", NULL},
925 {"( 1.3.6.1.4.1.1466.115.121.1.34 DESC 'NameAndOptionalUID' )", NULL},
926 {"( 1.3.6.1.4.1.1466.115.121.1.35 DESC 'NameFormDescription' )", NULL},
927 {"( 1.3.6.1.4.1.1466.115.121.1.36 DESC 'NumericString' )", NULL},
928 {"( 1.3.6.1.4.1.1466.115.121.1.37 DESC 'ObjectClassDescription' )", NULL},
929 {"( 1.3.6.1.4.1.1466.115.121.1.38 DESC 'OID' )", NULL},
930 {"( 1.3.6.1.4.1.1466.115.121.1.39 DESC 'OtherMailbox' )", NULL},
931 {"( 1.3.6.1.4.1.1466.115.121.1.40 DESC 'OctetString' )", NULL},
932 {"( 1.3.6.1.4.1.1466.115.121.1.41 DESC 'PostalAddress' )", NULL},
933 {"( 1.3.6.1.4.1.1466.115.121.1.42 DESC 'ProtocolInformation' )", NULL},
934 {"( 1.3.6.1.4.1.1466.115.121.1.43 DESC 'PresentationAddress' )", NULL},
935 {"( 1.3.6.1.4.1.1466.115.121.1.44 DESC 'PrintableString' )", NULL},
936 {"( 1.3.6.1.4.1.1466.115.121.1.49 DESC 'SupportedAlgorithm' )", NULL},
937 {"( 1.3.6.1.4.1.1466.115.121.1.50 DESC 'TelephoneNumber' )", NULL},
938 {"( 1.3.6.1.4.1.1466.115.121.1.51 DESC 'TeletexTerminalIdentifier' )", NULL},
939 {"( 1.3.6.1.4.1.1466.115.121.1.52 DESC 'TelexNumber' )", NULL},
940 {"( 1.3.6.1.4.1.1466.115.121.1.53 DESC 'UTCTime' )", NULL},
941 {"( 1.3.6.1.4.1.1466.115.121.1.54 DESC 'LDAPSyntaxDescription' )", NULL},
942 {"( 1.3.6.1.4.1.1466.115.121.1.58 DESC 'SubstringAssertion' )", NULL},
943 {"( 1.3.6.1.1.1.0.0 DESC 'NISnetgrouptriple' )", NULL},
944 {"( 1.3.6.1.1.1.0.1 DESC 'Bootparameter' )", NULL},
948 struct mrule_defs_rec {
950 slap_mr_normalize_func *mrd_normalize;
951 slap_mr_compare_func *mrd_compare;
955 * Other matching rules in X.520 that we do not use:
957 * 2.5.13.9 numericStringOrderingMatch
958 * 2.5.13.12 caseIgnoreListSubstringsMatch
959 * 2.5.13.13 booleanMatch
960 * 2.5.13.15 integerOrderingMatch
961 * 2.5.13.18 octetStringOrderingMatch
962 * 2.5.13.19 octetStringSubstringsMatch
963 * 2.5.13.25 uTCTimeMatch
964 * 2.5.13.26 uTCTimeOrderingMatch
965 * 2.5.13.31 directoryStringFirstComponentMatch
966 * 2.5.13.32 wordMatch
967 * 2.5.13.33 keywordMatch
968 * 2.5.13.34 certificateExactMatch
969 * 2.5.13.35 certificateMatch
970 * 2.5.13.36 certificatePairExactMatch
971 * 2.5.13.37 certificatePairMatch
972 * 2.5.13.38 certificateListExactMatch
973 * 2.5.13.39 certificateListMatch
974 * 2.5.13.40 algorithmIdentifierMatch
975 * 2.5.13.41 storedPrefixMatch
976 * 2.5.13.42 attributeCertificateMatch
977 * 2.5.13.43 readerAndKeyIDMatch
978 * 2.5.13.44 attributeIntegrityMatch
981 struct mrule_defs_rec mrule_defs[] = {
982 {"( 2.5.13.0 NAME 'objectIdentifierMatch' SYNTAX 1.3.6.1.4.1.1466.115.121.1.38 )", NULL, NULL},
983 {"( 2.5.13.1 NAME 'distinguishedNameMatch' SYNTAX 1.3.6.1.4.1.1466.115.121.1.12 )", NULL, NULL},
984 {"( 2.5.13.2 NAME 'caseIgnoreMatch' SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 )",
985 case_ignore_normalize, case_ignore_compare},
986 {"( 2.5.13.3 NAME 'caseIgnoreOrderingMatch' SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 )",
987 case_ignore_normalize, case_ignore_compare},
988 {"( 2.5.13.4 NAME 'caseIgnoreSubstringsMatch' SYNTAX 1.3.6.1.4.1.1466.115.121.1.58 )",
989 case_ignore_normalize, case_ignore_compare},
990 /* Next three are not in the RFC's, but are needed for compatibility */
991 {"( 2.5.13.5 NAME 'caseExactMatch' SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 )",
992 case_exact_normalize, case_exact_compare},
993 {"( 2.5.13.6 NAME 'caseExactOrderingMatch' SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 )",
994 case_exact_normalize, case_exact_compare},
995 {"( 2.5.13.7 NAME 'caseExactSubstringsMatch' SYNTAX 1.3.6.1.4.1.1466.115.121.1.58 )",
996 case_exact_normalize, case_exact_compare},
997 {"( 2.5.13.8 NAME 'numericStringMatch' SYNTAX 1.3.6.1.4.1.1466.115.121.1.36 )", NULL, NULL},
998 {"( 2.5.13.10 NAME 'numericStringSubstringsMatch' SYNTAX 1.3.6.1.4.1.1466.115.121.1.58 )", NULL, NULL},
999 {"( 2.5.13.11 NAME 'caseIgnoreListMatch' SYNTAX 1.3.6.1.4.1.1466.115.121.1.41 )", NULL, NULL},
1000 {"( 2.5.13.14 NAME 'integerMatch' SYNTAX 1.3.6.1.4.1.1466.115.121.1.27 )", NULL, NULL},
1001 {"( 2.5.13.16 NAME 'bitStringMatch' SYNTAX 1.3.6.1.4.1.1466.115.121.1.6 )", NULL, NULL},
1002 {"( 2.5.13.17 NAME 'octetStringMatch' SYNTAX 1.3.6.1.4.1.1466.115.121.1.40 )", NULL, NULL},
1003 {"( 2.5.13.20 NAME 'telephoneNumberMatch' SYNTAX 1.3.6.1.4.1.1466.115.121.1.50 )", NULL, NULL},
1004 {"( 2.5.13.21 NAME 'telephoneNumberSubstringsMatch' SYNTAX 1.3.6.1.4.1.1466.115.121.1.58 )", NULL, NULL},
1005 {"( 2.5.13.22 NAME 'presentationAddressMatch' SYNTAX 1.3.6.1.4.1.1466.115.121.1.43 )", NULL, NULL},
1006 {"( 2.5.13.23 NAME 'uniqueMemberMatch' SYNTAX 1.3.6.1.4.1.1466.115.121.1.34 )", NULL, NULL},
1007 {"( 2.5.13.24 NAME 'protocolInformationMatch' SYNTAX 1.3.6.1.4.1.1466.115.121.1.42 )", NULL, NULL},
1008 {"( 2.5.13.27 NAME 'generalizedTimeMatch' SYNTAX 1.3.6.1.4.1.1466.115.121.1.24 )", NULL, NULL},
1009 {"( 2.5.13.28 NAME 'generalizedTimeOrderingMatch' SYNTAX 1.3.6.1.4.1.1466.115.121.1.24 )", NULL, NULL},
1010 {"( 2.5.13.29 NAME 'integerFirstComponentMatch' SYNTAX 1.3.6.1.4.1.1466.115.121.1.27 )", NULL, NULL},
1011 {"( 2.5.13.30 NAME 'objectIdentifierFirstComponentMatch' SYNTAX 1.3.6.1.4.1.1466.115.121.1.38 )", NULL, NULL},
1012 {"( 1.3.6.1.4.1.1466.109.114.1 NAME 'caseExactIA5Match' SYNTAX 1.3.6.1.4.1.1466.115.121.1.26 )",
1013 case_exact_normalize, case_exact_compare},
1014 {"( 1.3.6.1.4.1.1466.109.114.2 NAME 'caseIgnoreIA5Match' SYNTAX 1.3.6.1.4.1.1466.115.121.1.26 )",
1015 case_ignore_normalize, case_ignore_compare},
1024 static int schema_init_done = 0;
1026 /* We are called from read_config that is recursive */
1027 if ( schema_init_done )
1029 for ( i=0; syntax_defs[i].sd_desc != NULL; i++ ) {
1030 res = register_syntax( syntax_defs[i].sd_desc,
1031 syntax_defs[i].sd_check );
1033 fprintf( stderr, "schema_init: Error registering syntax %s\n",
1034 syntax_defs[i].sd_desc );
1035 exit( EXIT_FAILURE );
1038 for ( i=0; mrule_defs[i].mrd_desc != NULL; i++ ) {
1039 res = register_matching_rule( mrule_defs[i].mrd_desc,
1040 ( mrule_defs[i].mrd_normalize ?
1041 mrule_defs[i].mrd_normalize : case_ignore_normalize ),
1042 ( mrule_defs[i].mrd_compare ?
1043 mrule_defs[i].mrd_compare : case_ignore_compare ) );
1045 fprintf( stderr, "schema_init: Error registering matching rule %s\n",
1046 mrule_defs[i].mrd_desc );
1047 exit( EXIT_FAILURE );
1050 schema_init_done = 1;
1054 #if defined( SLAPD_SCHEMA_DN )
1057 syn_schema_info( Entry *e )
1060 struct berval *vals[2];
1066 for ( syn = syn_list; syn; syn = syn->ssyn_next ) {
1067 val.bv_val = ldap_syntax2str( &syn->ssyn_syn );
1069 val.bv_len = strlen( val.bv_val );
1070 Debug( LDAP_DEBUG_TRACE, "Merging syn [%d] %s\n",
1071 val.bv_len, val.bv_val, 0 );
1072 attr_merge( e, "ldapSyntaxes", vals );
1073 ldap_memfree( val.bv_val );
1082 mr_schema_info( Entry *e )
1085 struct berval *vals[2];
1091 for ( mr = mr_list; mr; mr = mr->smr_next ) {
1092 val.bv_val = ldap_matchingrule2str( &mr->smr_mrule );
1094 val.bv_len = strlen( val.bv_val );
1095 Debug( LDAP_DEBUG_TRACE, "Merging mr [%d] %s\n",
1096 val.bv_len, val.bv_val, 0 );
1097 attr_merge( e, "matchingRules", vals );
1098 ldap_memfree( val.bv_val );
1107 oc_schema_info( Entry *e )
1110 struct berval *vals[2];
1116 for ( oc = oc_list; oc; oc = oc->soc_next ) {
1117 val.bv_val = ldap_objectclass2str( &oc->soc_oclass );
1119 val.bv_len = strlen( val.bv_val );
1120 Debug( LDAP_DEBUG_TRACE, "Merging oc [%d] %s\n",
1121 val.bv_len, val.bv_val, 0 );
1122 attr_merge( e, "objectClasses", vals );
1123 ldap_memfree( val.bv_val );
1132 schema_info( Connection *conn, Operation *op, char **attrs, int attrsonly )
1136 struct berval *vals[2];
1141 e = (Entry *) ch_calloc( 1, sizeof(Entry) );
1144 e->e_dn = ch_strdup( SLAPD_SCHEMA_DN );
1145 e->e_ndn = ch_strdup( SLAPD_SCHEMA_DN );
1146 (void) dn_normalize_case( e->e_ndn );
1147 e->e_private = NULL;
1150 char *rdn = ch_strdup( SLAPD_SCHEMA_DN );
1151 val.bv_val = strchr( rdn, '=' );
1153 if( val.bv_val != NULL ) {
1155 val.bv_len = strlen( ++val.bv_val );
1157 attr_merge( e, rdn, vals );
1163 if ( syn_schema_info( e ) ) {
1164 /* Out of memory, do something about it */
1168 if ( mr_schema_info( e ) ) {
1169 /* Out of memory, do something about it */
1173 if ( at_schema_info( e ) ) {
1174 /* Out of memory, do something about it */
1178 if ( oc_schema_info( e ) ) {
1179 /* Out of memory, do something about it */
1185 val.bv_len = sizeof("top")-1;
1186 attr_merge( e, "objectClass", vals );
1188 val.bv_val = "LDAPsubentry";
1189 val.bv_len = sizeof("LDAPsubentry")-1;
1190 attr_merge( e, "objectClass", vals );
1192 val.bv_val = "subschema";
1193 val.bv_len = sizeof("subschema")-1;
1194 attr_merge( e, "objectClass", vals );
1196 val.bv_val = "extensibleObject";
1197 val.bv_len = sizeof("extensibleObject")-1;
1198 attr_merge( e, "objectClass", vals );
1200 send_search_entry( &backends[0], conn, op,
1201 e, attrs, attrsonly, NULL );
1202 send_search_result( conn, op, LDAP_SUCCESS,
1203 NULL, NULL, NULL, NULL, 1 );
1212 oc_print( ObjectClass *oc )
1217 printf( "objectclass %s\n", ldap_objectclass2name( &oc->soc_oclass ) );
1218 if ( oc->soc_required != NULL ) {
1219 mid = "\trequires ";
1220 for ( i = 0; oc->soc_required[i] != NULL; i++, mid = "," )
1221 printf( "%s%s", mid,
1222 ldap_attributetype2name( &oc->soc_required[i]->sat_atype ) );
1225 if ( oc->soc_allowed != NULL ) {
1227 for ( i = 0; oc->soc_allowed[i] != NULL; i++, mid = "," )
1228 printf( "%s%s", mid,
1229 ldap_attributetype2name( &oc->soc_allowed[i]->sat_atype ) );
1237 int is_entry_objectclass(
1244 if( e == NULL || oc == NULL || *oc == '\0' )
1248 * find objectClass attribute
1250 attr = attr_find(e->e_attrs, "objectclass");
1252 if( attr == NULL ) {
1253 /* no objectClass attribute */
1257 bv.bv_val = (char *) oc;
1258 bv.bv_len = strlen( bv.bv_val );
1260 if( value_find(attr->a_vals, &bv, attr->a_syntax, 1) != 0) {
1261 /* entry is not of this objectclass */