1 /* schema.c - routines to enforce schema definitions */
4 * Copyright 1998-1999 The OpenLDAP Foundation, All Rights Reserved.
5 * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
13 #include <ac/string.h>
14 #include <ac/socket.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 );
52 char *s = oc_check_required( e, aoc->a_vals[i]->bv_val );
55 Debug( LDAP_DEBUG_ANY,
56 "Entry (%s), oc \"%s\" requires attr \"%s\"\n",
57 e->e_dn, aoc->a_vals[i]->bv_val, s );
67 /* check that each attr in the entry is allowed by some oc */
68 for ( a = e->e_attrs; a != NULL; a = a->a_next ) {
69 if ( oc_check_allowed( a->a_type, aoc->a_vals ) != 0 ) {
70 Debug( LDAP_DEBUG_ANY,
71 "Entry (%s), attr \"%s\" not allowed\n",
72 e->e_dn, a->a_type, 0 );
81 oc_check_required( Entry *e, char *ocname )
89 Debug( LDAP_DEBUG_TRACE,
90 "oc_check_required entry (%s), objectclass \"%s\"\n",
93 /* find global oc defn. it we don't know about it assume it's ok */
94 if ( (oc = oc_find( ocname )) == NULL ) {
98 /* check for empty oc_required */
99 if(oc->soc_required == NULL) {
103 /* for each required attribute */
104 for ( i = 0; oc->soc_required[i] != NULL; i++ ) {
105 at = oc->soc_required[i];
106 /* see if it's in the entry */
107 for ( a = e->e_attrs; a != NULL; a = a->a_next ) {
109 strcmp( a->a_type, at->sat_oid ) == 0 ) {
114 /* Empty name list => not found */
119 if ( strcasecmp( a->a_type, *pp ) == 0 ) {
128 /* not there => schema violation */
130 if ( at->sat_names && at->sat_names[0] ) {
131 return at->sat_names[0];
141 static char *oc_usermod_attrs[] = {
143 * OpenLDAP doesn't support any user modification of
144 * operational attributes.
149 static char *oc_operational_attrs[] = {
151 * these are operational attributes
152 * most could be user modifiable
163 "supportedExtension",
165 "supportedSASLMechanisms",
166 "supportedLDAPversion",
167 "subschemaSubentry", /* NO USER MOD */
172 /* this list should be extensible */
173 static char *oc_no_usermod_attrs[] = {
175 * Operational and 'no user modification' attributes
176 * which are STORED in the directory server.
190 * check to see if attribute is 'operational' or not.
193 oc_check_operational_attr( const char *type )
195 return charray_inlist( oc_operational_attrs, type )
196 || charray_inlist( oc_usermod_attrs, type )
197 || charray_inlist( oc_no_usermod_attrs, type );
201 * check to see if attribute can be user modified or not.
204 oc_check_usermod_attr( const char *type )
206 return charray_inlist( oc_usermod_attrs, type );
210 * check to see if attribute is 'no user modification' or not.
213 oc_check_no_usermod_attr( const char *type )
215 return charray_inlist( oc_no_usermod_attrs, type );
220 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 ) ) {
246 * The "type" we have received is actually an AttributeDescription.
247 * Let's find out the corresponding type.
249 p = strchr( type, ';' );
251 t = ch_malloc( p-type+1 );
252 strncpy( t, type, p-type );
254 Debug( LDAP_DEBUG_TRACE,
255 "oc_check_allowed type \"%s\" from \"%s\"\n",
262 /* check that the type appears as req or opt in at least one oc */
263 for ( i = 0; ocl[i] != NULL; i++ ) {
264 /* if we know about the oc */
265 if ( (oc = oc_find( ocl[i]->bv_val )) != NULL ) {
266 /* does it require the type? */
267 for ( j = 0; oc->soc_required != NULL &&
268 oc->soc_required[j] != NULL; j++ ) {
269 at = oc->soc_required[j];
271 strcmp(at->sat_oid, t ) == 0 ) {
280 if ( strcasecmp( *pp, t ) == 0 ) {
288 /* does it allow the type? */
289 for ( j = 0; oc->soc_allowed != NULL &&
290 oc->soc_allowed[j] != NULL; j++ ) {
291 at = oc->soc_allowed[j];
293 strcmp( at->sat_oid, t ) == 0 ) {
302 if ( strcasecmp( *pp, t ) == 0 ||
303 strcmp( *pp, "*" ) == 0 ) {
311 /* maybe the next oc allows it */
313 /* we don't know about the oc. assume it allows it */
323 /* not allowed by any oc */
332 static Avlnode *oc_index = NULL;
333 static ObjectClass *oc_list = NULL;
337 struct oindexrec *oir1,
338 struct oindexrec *oir2
341 return (strcasecmp( oir1->oir_name, oir2->oir_name ));
347 struct oindexrec *oir
350 return (strcasecmp( name, oir->oir_name ));
354 oc_find( const char *ocname )
356 struct oindexrec *oir = NULL;
358 if ( (oir = (struct oindexrec *) avl_find( oc_index, ocname,
359 (AVL_CMP) oc_index_name_cmp )) != NULL ) {
360 return( oir->oir_oc );
374 AttributeType **satp;
380 sat = at_find(*attrs1);
383 return SLAP_SCHERR_ATTR_NOT_FOUND;
385 if ( at_find_in_list(sat, soc->soc_required) < 0) {
386 if ( at_append_to_list(sat, &soc->soc_required) ) {
388 return SLAP_SCHERR_OUTOFMEM;
393 /* Now delete duplicates from the allowed list */
394 for ( satp = soc->soc_required; *satp; satp++ ) {
395 i = at_find_in_list(*satp,soc->soc_allowed);
397 at_delete_from_list(i, &soc->soc_allowed);
417 sat = at_find(*attrs1);
420 return SLAP_SCHERR_ATTR_NOT_FOUND;
422 if ( at_find_in_list(sat, soc->soc_required) < 0 &&
423 at_find_in_list(sat, soc->soc_allowed) < 0 ) {
424 if ( at_append_to_list(sat, &soc->soc_allowed) ) {
426 return SLAP_SCHERR_OUTOFMEM;
449 if ( !soc->soc_sups ) {
450 /* We are at the first recursive level */
459 soc->soc_sups = (ObjectClass **)ch_calloc(1,
460 nsups*sizeof(ObjectClass *));
465 soc1 = oc_find(*sups1);
468 return SLAP_SCHERR_CLASS_NOT_FOUND;
472 soc->soc_sups[nsups] = soc1;
474 code = oc_add_sups(soc,soc1->soc_sup_oids, err);
478 code = oc_create_required(soc,soc1->soc_at_oids_must,err);
481 code = oc_create_allowed(soc,soc1->soc_at_oids_may,err);
499 struct oindexrec *oir;
503 while ( *ocp != NULL ) {
504 ocp = &(*ocp)->soc_next;
508 if ( soc->soc_oid ) {
509 oir = (struct oindexrec *)
510 ch_calloc( 1, sizeof(struct oindexrec) );
511 oir->oir_name = soc->soc_oid;
513 if ( avl_insert( &oc_index, (caddr_t) oir,
514 (AVL_CMP) oc_index_cmp,
515 (AVL_DUP) avl_dup_error ) ) {
518 return SLAP_SCHERR_DUP_CLASS;
520 /* FIX: temporal consistency check */
521 oc_find(oir->oir_name);
523 if ( (names = soc->soc_names) ) {
525 oir = (struct oindexrec *)
526 ch_calloc( 1, sizeof(struct oindexrec) );
527 oir->oir_name = ch_strdup(*names);
529 if ( avl_insert( &oc_index, (caddr_t) oir,
530 (AVL_CMP) oc_index_cmp,
531 (AVL_DUP) avl_dup_error ) ) {
534 return SLAP_SCHERR_DUP_CLASS;
536 /* FIX: temporal consistency check */
537 oc_find(oir->oir_name);
546 LDAP_OBJECT_CLASS *oc,
553 soc = (ObjectClass *) ch_calloc( 1, sizeof(ObjectClass) );
554 memcpy( &soc->soc_oclass, oc, sizeof(LDAP_OBJECT_CLASS));
555 if ( (code = oc_add_sups(soc,soc->soc_sup_oids,err)) != 0 )
557 if ( (code = oc_create_required(soc,soc->soc_at_oids_must,err)) != 0 )
559 if ( (code = oc_create_allowed(soc,soc->soc_at_oids_may,err)) != 0 )
561 code = oc_insert(soc,err);
570 static Avlnode *syn_index = NULL;
571 static Syntax *syn_list = NULL;
575 struct sindexrec *sir1,
576 struct sindexrec *sir2
579 return (strcmp( sir1->sir_name, sir2->sir_name ));
585 struct sindexrec *sir
588 return (strcmp( name, sir->sir_name ));
592 syn_find( const char *synname )
594 struct sindexrec *sir = NULL;
596 if ( (sir = (struct sindexrec *) avl_find( syn_index, synname,
597 (AVL_CMP) syn_index_name_cmp )) != NULL ) {
598 return( sir->sir_syn );
604 syn_find_desc( const char *syndesc, int *len )
608 for (synp = syn_list; synp; synp = synp->ssyn_next)
609 if ((*len = dscompare( synp->ssyn_syn.syn_desc, syndesc, '{')))
621 struct sindexrec *sir;
624 while ( *synp != NULL ) {
625 synp = &(*synp)->ssyn_next;
629 if ( ssyn->ssyn_oid ) {
630 sir = (struct sindexrec *)
631 ch_calloc( 1, sizeof(struct sindexrec) );
632 sir->sir_name = ssyn->ssyn_oid;
634 if ( avl_insert( &syn_index, (caddr_t) sir,
635 (AVL_CMP) syn_index_cmp,
636 (AVL_DUP) avl_dup_error ) ) {
637 *err = ssyn->ssyn_oid;
639 return SLAP_SCHERR_DUP_SYNTAX;
641 /* FIX: temporal consistency check */
642 syn_find(sir->sir_name);
650 slap_syntax_check_func *check,
657 ssyn = (Syntax *) ch_calloc( 1, sizeof(Syntax) );
658 memcpy( &ssyn->ssyn_syn, syn, sizeof(LDAP_SYNTAX));
659 ssyn->ssyn_check = check;
660 code = syn_insert(ssyn,err);
666 MatchingRule *mir_mr;
669 static Avlnode *mr_index = NULL;
670 static MatchingRule *mr_list = NULL;
674 struct mindexrec *mir1,
675 struct mindexrec *mir2
678 return (strcmp( mir1->mir_name, mir2->mir_name ));
684 struct mindexrec *mir
687 return (strcmp( name, mir->mir_name ));
691 mr_find( const char *mrname )
693 struct mindexrec *mir = NULL;
695 if ( (mir = (struct mindexrec *) avl_find( mr_index, mrname,
696 (AVL_CMP) mr_index_name_cmp )) != NULL ) {
697 return( mir->mir_mr );
709 struct mindexrec *mir;
713 while ( *mrp != NULL ) {
714 mrp = &(*mrp)->smr_next;
718 if ( smr->smr_oid ) {
719 mir = (struct mindexrec *)
720 ch_calloc( 1, sizeof(struct mindexrec) );
721 mir->mir_name = smr->smr_oid;
723 if ( avl_insert( &mr_index, (caddr_t) mir,
724 (AVL_CMP) mr_index_cmp,
725 (AVL_DUP) avl_dup_error ) ) {
728 return SLAP_SCHERR_DUP_RULE;
730 /* FIX: temporal consistency check */
731 mr_find(mir->mir_name);
733 if ( (names = smr->smr_names) ) {
735 mir = (struct mindexrec *)
736 ch_calloc( 1, sizeof(struct mindexrec) );
737 mir->mir_name = ch_strdup(*names);
739 if ( avl_insert( &mr_index, (caddr_t) mir,
740 (AVL_CMP) mr_index_cmp,
741 (AVL_DUP) avl_dup_error ) ) {
744 return SLAP_SCHERR_DUP_RULE;
746 /* FIX: temporal consistency check */
747 mr_find(mir->mir_name);
756 LDAP_MATCHING_RULE *mr,
757 slap_mr_normalize_func *normalize,
758 slap_mr_compare_func *compare,
766 smr = (MatchingRule *) ch_calloc( 1, sizeof(MatchingRule) );
767 memcpy( &smr->smr_mrule, mr, sizeof(LDAP_MATCHING_RULE));
768 smr->smr_normalize = normalize;
769 smr->smr_compare = compare;
770 if ( smr->smr_syntax_oid ) {
771 if ( (syn = syn_find(smr->smr_syntax_oid)) ) {
772 smr->smr_syntax = syn;
774 *err = smr->smr_syntax_oid;
775 return SLAP_SCHERR_SYN_NOT_FOUND;
779 return SLAP_SCHERR_MR_INCOMPLETE;
781 code = mr_insert(smr,err);
786 case_exact_normalize(
788 struct berval **normalized
791 struct berval *newval;
794 newval = ber_bvdup( val );
795 p = q = newval->bv_val;
796 /* Ignore initial whitespace */
797 while ( isspace( *p++ ) )
800 if ( isspace( *p ) ) {
802 /* Ignore the extra whitespace */
803 while ( isspace(*p++) )
810 * If the string ended in space, backup the pointer one
811 * position. One is enough because the above loop collapsed
812 * all whitespace to a single space.
814 if ( p != newval->bv_val && isspace( *(p-1) ) ) {
817 newval->bv_len = strlen( newval->bv_val );
818 normalized = &newval;
829 return strcmp( val1->bv_val, val2->bv_val );
833 case_ignore_normalize(
835 struct berval **normalized
838 struct berval *newval;
841 newval = ber_bvdup( val );
842 p = q = newval->bv_val;
843 /* Ignore initial whitespace */
844 while ( isspace( *p++ ) )
847 if ( isspace( *p ) ) {
849 /* Ignore the extra whitespace */
850 while ( isspace(*p++) )
853 *q++ = TOUPPER( *p++ );
857 * If the string ended in space, backup the pointer one
858 * position. One is enough because the above loop collapsed
859 * all whitespace to a single space.
861 if ( p != newval->bv_val && isspace( *(p-1) ) ) {
864 newval->bv_len = strlen( newval->bv_val );
865 normalized = &newval;
876 return strcasecmp( val1->bv_val, val2->bv_val );
882 slap_syntax_check_func *check )
888 syn = ldap_str2syntax( desc, &code, &err);
890 Debug( LDAP_DEBUG_ANY, "Error in register_syntax: %s before %s in %s\n",
891 ldap_scherr2str(code), err, desc );
894 code = syn_add( syn, check, &err );
896 Debug( LDAP_DEBUG_ANY, "Error in register_syntax: %s %s in %s\n",
897 scherr2str(code), err, desc );
904 register_matching_rule(
906 slap_mr_normalize_func *normalize,
907 slap_mr_compare_func *compare )
909 LDAP_MATCHING_RULE *mr;
913 mr = ldap_str2matchingrule( desc, &code, &err);
915 Debug( LDAP_DEBUG_ANY, "Error in register_matching_rule: %s before %s in %s\n",
916 ldap_scherr2str(code), err, desc );
919 code = mr_add( mr, normalize, compare, &err );
921 Debug( LDAP_DEBUG_ANY, "Error in register_syntax: %s for %s in %s\n",
922 scherr2str(code), err, desc );
928 struct syntax_defs_rec {
930 slap_syntax_check_func *sd_check;
933 struct syntax_defs_rec syntax_defs[] = {
934 {"( 1.3.6.1.4.1.1466.115.121.1.3 DESC 'AttributeTypeDescription' )", NULL},
935 {"( 1.3.6.1.4.1.1466.115.121.1.4 DESC 'Audio' )", NULL},
936 {"( 1.3.6.1.4.1.1466.115.121.1.5 DESC 'Binary' )", NULL},
937 {"( 1.3.6.1.4.1.1466.115.121.1.6 DESC 'BitString' )", NULL},
938 {"( 1.3.6.1.4.1.1466.115.121.1.8 DESC 'Certificate' )", NULL},
939 {"( 1.3.6.1.4.1.1466.115.121.1.9 DESC 'CertificateList' )", NULL},
940 {"( 1.3.6.1.4.1.1466.115.121.1.10 DESC 'CertificatePair' )", NULL},
941 {"( 1.3.6.1.4.1.1466.115.121.1.12 DESC 'DN' )", NULL},
942 {"( 1.3.6.1.4.1.1466.115.121.1.14 DESC 'DeliveryMethod' )", NULL},
943 {"( 1.3.6.1.4.1.1466.115.121.1.15 DESC 'DirectoryString' )", NULL},
944 {"( 1.3.6.1.4.1.1466.115.121.1.16 DESC 'DITContentRuleDescription' )", NULL},
945 {"( 1.3.6.1.4.1.1466.115.121.1.17 DESC 'DITStructureRuleDescription' )", NULL},
946 {"( 1.3.6.1.4.1.1466.115.121.1.21 DESC 'EnhancedGuide' )", NULL},
947 {"( 1.3.6.1.4.1.1466.115.121.1.22 DESC 'FacsimileTelephoneNumber' )", NULL},
948 {"( 1.3.6.1.4.1.1466.115.121.1.24 DESC 'GeneralizedTime' )", NULL},
949 {"( 1.3.6.1.4.1.1466.115.121.1.25 DESC 'Guide' )", NULL},
950 {"( 1.3.6.1.4.1.1466.115.121.1.26 DESC 'IA5String' )", NULL},
951 {"( 1.3.6.1.4.1.1466.115.121.1.27 DESC 'Integer' )", NULL},
952 {"( 1.3.6.1.4.1.1466.115.121.1.28 DESC 'JPEG' )", NULL},
953 {"( 1.3.6.1.4.1.1466.115.121.1.30 DESC 'MatchingRuleDescription' )", NULL},
954 {"( 1.3.6.1.4.1.1466.115.121.1.31 DESC 'MatchingRuleUseDescription' )", NULL},
955 {"( 1.3.6.1.4.1.1466.115.121.1.32 DESC 'MailPreference' )", NULL},
956 {"( 1.3.6.1.4.1.1466.115.121.1.34 DESC 'NameAndOptionalUID' )", NULL},
957 {"( 1.3.6.1.4.1.1466.115.121.1.35 DESC 'NameFormDescription' )", NULL},
958 {"( 1.3.6.1.4.1.1466.115.121.1.36 DESC 'NumericString' )", NULL},
959 {"( 1.3.6.1.4.1.1466.115.121.1.37 DESC 'ObjectClassDescription' )", NULL},
960 {"( 1.3.6.1.4.1.1466.115.121.1.38 DESC 'OID' )", NULL},
961 {"( 1.3.6.1.4.1.1466.115.121.1.39 DESC 'OtherMailbox' )", NULL},
962 {"( 1.3.6.1.4.1.1466.115.121.1.40 DESC 'OctetString' )", NULL},
963 {"( 1.3.6.1.4.1.1466.115.121.1.41 DESC 'PostalAddress' )", NULL},
964 {"( 1.3.6.1.4.1.1466.115.121.1.42 DESC 'ProtocolInformation' )", NULL},
965 {"( 1.3.6.1.4.1.1466.115.121.1.43 DESC 'PresentationAddress' )", NULL},
966 {"( 1.3.6.1.4.1.1466.115.121.1.44 DESC 'PrintableString' )", NULL},
967 {"( 1.3.6.1.4.1.1466.115.121.1.49 DESC 'SupportedAlgorithm' )", NULL},
968 {"( 1.3.6.1.4.1.1466.115.121.1.50 DESC 'TelephoneNumber' )", NULL},
969 {"( 1.3.6.1.4.1.1466.115.121.1.51 DESC 'TeletexTerminalIdentifier' )", NULL},
970 {"( 1.3.6.1.4.1.1466.115.121.1.52 DESC 'TelexNumber' )", NULL},
971 {"( 1.3.6.1.4.1.1466.115.121.1.53 DESC 'UTCTime' )", NULL},
972 {"( 1.3.6.1.4.1.1466.115.121.1.54 DESC 'LDAPSyntaxDescription' )", NULL},
973 {"( 1.3.6.1.4.1.1466.115.121.1.58 DESC 'SubstringAssertion' )", NULL},
974 {"( 1.3.6.1.1.1.0.0 DESC 'NISnetgrouptriple' )", NULL},
975 {"( 1.3.6.1.1.1.0.1 DESC 'Bootparameter' )", NULL},
979 struct mrule_defs_rec {
981 slap_mr_normalize_func *mrd_normalize;
982 slap_mr_compare_func *mrd_compare;
986 * Other matching rules in X.520 that we do not use:
988 * 2.5.13.9 numericStringOrderingMatch
989 * 2.5.13.12 caseIgnoreListSubstringsMatch
990 * 2.5.13.13 booleanMatch
991 * 2.5.13.15 integerOrderingMatch
992 * 2.5.13.18 octetStringOrderingMatch
993 * 2.5.13.19 octetStringSubstringsMatch
994 * 2.5.13.25 uTCTimeMatch
995 * 2.5.13.26 uTCTimeOrderingMatch
996 * 2.5.13.31 directoryStringFirstComponentMatch
997 * 2.5.13.32 wordMatch
998 * 2.5.13.33 keywordMatch
999 * 2.5.13.34 certificateExactMatch
1000 * 2.5.13.35 certificateMatch
1001 * 2.5.13.36 certificatePairExactMatch
1002 * 2.5.13.37 certificatePairMatch
1003 * 2.5.13.38 certificateListExactMatch
1004 * 2.5.13.39 certificateListMatch
1005 * 2.5.13.40 algorithmIdentifierMatch
1006 * 2.5.13.41 storedPrefixMatch
1007 * 2.5.13.42 attributeCertificateMatch
1008 * 2.5.13.43 readerAndKeyIDMatch
1009 * 2.5.13.44 attributeIntegrityMatch
1012 struct mrule_defs_rec mrule_defs[] = {
1013 {"( 2.5.13.0 NAME 'objectIdentifierMatch' SYNTAX 1.3.6.1.4.1.1466.115.121.1.38 )", NULL, NULL},
1014 {"( 2.5.13.1 NAME 'distinguishedNameMatch' SYNTAX 1.3.6.1.4.1.1466.115.121.1.12 )", NULL, NULL},
1015 {"( 2.5.13.2 NAME 'caseIgnoreMatch' SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 )",
1016 case_ignore_normalize, case_ignore_compare},
1017 {"( 2.5.13.3 NAME 'caseIgnoreOrderingMatch' SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 )",
1018 case_ignore_normalize, case_ignore_compare},
1019 {"( 2.5.13.4 NAME 'caseIgnoreSubstringsMatch' SYNTAX 1.3.6.1.4.1.1466.115.121.1.58 )",
1020 case_ignore_normalize, case_ignore_compare},
1021 /* Next three are not in the RFC's, but are needed for compatibility */
1022 {"( 2.5.13.5 NAME 'caseExactMatch' SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 )",
1023 case_exact_normalize, case_exact_compare},
1024 {"( 2.5.13.6 NAME 'caseExactOrderingMatch' SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 )",
1025 case_exact_normalize, case_exact_compare},
1026 {"( 2.5.13.7 NAME 'caseExactSubstringsMatch' SYNTAX 1.3.6.1.4.1.1466.115.121.1.58 )",
1027 case_exact_normalize, case_exact_compare},
1028 {"( 2.5.13.8 NAME 'numericStringMatch' SYNTAX 1.3.6.1.4.1.1466.115.121.1.36 )", NULL, NULL},
1029 {"( 2.5.13.10 NAME 'numericStringSubstringsMatch' SYNTAX 1.3.6.1.4.1.1466.115.121.1.58 )", NULL, NULL},
1030 {"( 2.5.13.11 NAME 'caseIgnoreListMatch' SYNTAX 1.3.6.1.4.1.1466.115.121.1.41 )", NULL, NULL},
1031 {"( 2.5.13.14 NAME 'integerMatch' SYNTAX 1.3.6.1.4.1.1466.115.121.1.27 )", NULL, NULL},
1032 {"( 2.5.13.16 NAME 'bitStringMatch' SYNTAX 1.3.6.1.4.1.1466.115.121.1.6 )", NULL, NULL},
1033 {"( 2.5.13.17 NAME 'octetStringMatch' SYNTAX 1.3.6.1.4.1.1466.115.121.1.40 )", NULL, NULL},
1034 {"( 2.5.13.20 NAME 'telephoneNumberMatch' SYNTAX 1.3.6.1.4.1.1466.115.121.1.50 )", NULL, NULL},
1035 {"( 2.5.13.21 NAME 'telephoneNumberSubstringsMatch' SYNTAX 1.3.6.1.4.1.1466.115.121.1.58 )", NULL, NULL},
1036 {"( 2.5.13.22 NAME 'presentationAddressMatch' SYNTAX 1.3.6.1.4.1.1466.115.121.1.43 )", NULL, NULL},
1037 {"( 2.5.13.23 NAME 'uniqueMemberMatch' SYNTAX 1.3.6.1.4.1.1466.115.121.1.34 )", NULL, NULL},
1038 {"( 2.5.13.24 NAME 'protocolInformationMatch' SYNTAX 1.3.6.1.4.1.1466.115.121.1.42 )", NULL, NULL},
1039 {"( 2.5.13.27 NAME 'generalizedTimeMatch' SYNTAX 1.3.6.1.4.1.1466.115.121.1.24 )", NULL, NULL},
1040 {"( 2.5.13.28 NAME 'generalizedTimeOrderingMatch' SYNTAX 1.3.6.1.4.1.1466.115.121.1.24 )", NULL, NULL},
1041 {"( 2.5.13.29 NAME 'integerFirstComponentMatch' SYNTAX 1.3.6.1.4.1.1466.115.121.1.27 )", NULL, NULL},
1042 {"( 2.5.13.30 NAME 'objectIdentifierFirstComponentMatch' SYNTAX 1.3.6.1.4.1.1466.115.121.1.38 )", NULL, NULL},
1043 {"( 1.3.6.1.4.1.1466.109.114.1 NAME 'caseExactIA5Match' SYNTAX 1.3.6.1.4.1.1466.115.121.1.26 )",
1044 case_exact_normalize, case_exact_compare},
1045 {"( 1.3.6.1.4.1.1466.109.114.2 NAME 'caseIgnoreIA5Match' SYNTAX 1.3.6.1.4.1.1466.115.121.1.26 )",
1046 case_ignore_normalize, case_ignore_compare},
1055 static int schema_init_done = 0;
1057 /* We are called from read_config that is recursive */
1058 if ( schema_init_done )
1060 for ( i=0; syntax_defs[i].sd_desc != NULL; i++ ) {
1061 res = register_syntax( syntax_defs[i].sd_desc,
1062 syntax_defs[i].sd_check );
1064 fprintf( stderr, "schema_init: Error registering syntax %s\n",
1065 syntax_defs[i].sd_desc );
1066 exit( EXIT_FAILURE );
1069 for ( i=0; mrule_defs[i].mrd_desc != NULL; i++ ) {
1070 res = register_matching_rule( mrule_defs[i].mrd_desc,
1071 ( mrule_defs[i].mrd_normalize ?
1072 mrule_defs[i].mrd_normalize : case_ignore_normalize ),
1073 ( mrule_defs[i].mrd_compare ?
1074 mrule_defs[i].mrd_compare : case_ignore_compare ) );
1076 fprintf( stderr, "schema_init: Error registering matching rule %s\n",
1077 mrule_defs[i].mrd_desc );
1078 exit( EXIT_FAILURE );
1081 schema_init_done = 1;
1085 #if defined( SLAPD_SCHEMA_DN )
1088 syn_schema_info( Entry *e )
1091 struct berval *vals[2];
1097 for ( syn = syn_list; syn; syn = syn->ssyn_next ) {
1098 val.bv_val = ldap_syntax2str( &syn->ssyn_syn );
1100 val.bv_len = strlen( val.bv_val );
1101 Debug( LDAP_DEBUG_TRACE, "Merging syn [%ld] %s\n",
1102 (long) val.bv_len, val.bv_val, 0 );
1103 attr_merge( e, "ldapSyntaxes", vals );
1104 ldap_memfree( val.bv_val );
1113 mr_schema_info( Entry *e )
1116 struct berval *vals[2];
1122 for ( mr = mr_list; mr; mr = mr->smr_next ) {
1123 val.bv_val = ldap_matchingrule2str( &mr->smr_mrule );
1125 val.bv_len = strlen( val.bv_val );
1126 Debug( LDAP_DEBUG_TRACE, "Merging mr [%ld] %s\n",
1127 (long) val.bv_len, val.bv_val, 0 );
1128 attr_merge( e, "matchingRules", vals );
1129 ldap_memfree( val.bv_val );
1138 oc_schema_info( Entry *e )
1141 struct berval *vals[2];
1147 for ( oc = oc_list; oc; oc = oc->soc_next ) {
1148 val.bv_val = ldap_objectclass2str( &oc->soc_oclass );
1150 val.bv_len = strlen( val.bv_val );
1151 Debug( LDAP_DEBUG_TRACE, "Merging oc [%ld] %s\n",
1152 (long) val.bv_len, val.bv_val, 0 );
1153 attr_merge( e, "objectClasses", vals );
1154 ldap_memfree( val.bv_val );
1163 schema_info( Connection *conn, Operation *op, char **attrs, int attrsonly )
1167 struct berval *vals[2];
1172 e = (Entry *) ch_calloc( 1, sizeof(Entry) );
1175 e->e_dn = ch_strdup( SLAPD_SCHEMA_DN );
1176 e->e_ndn = ch_strdup( SLAPD_SCHEMA_DN );
1177 (void) dn_normalize_case( e->e_ndn );
1178 e->e_private = NULL;
1181 char *rdn = ch_strdup( SLAPD_SCHEMA_DN );
1182 val.bv_val = strchr( rdn, '=' );
1184 if( val.bv_val != NULL ) {
1186 val.bv_len = strlen( ++val.bv_val );
1188 attr_merge( e, rdn, vals );
1194 if ( syn_schema_info( e ) ) {
1195 /* Out of memory, do something about it */
1199 if ( mr_schema_info( e ) ) {
1200 /* Out of memory, do something about it */
1204 if ( at_schema_info( e ) ) {
1205 /* Out of memory, do something about it */
1209 if ( oc_schema_info( e ) ) {
1210 /* Out of memory, do something about it */
1216 val.bv_len = sizeof("top")-1;
1217 attr_merge( e, "objectClass", vals );
1219 val.bv_val = "LDAPsubentry";
1220 val.bv_len = sizeof("LDAPsubentry")-1;
1221 attr_merge( e, "objectClass", vals );
1223 val.bv_val = "subschema";
1224 val.bv_len = sizeof("subschema")-1;
1225 attr_merge( e, "objectClass", vals );
1227 val.bv_val = "extensibleObject";
1228 val.bv_len = sizeof("extensibleObject")-1;
1229 attr_merge( e, "objectClass", vals );
1231 send_search_entry( &backends[0], conn, op,
1232 e, attrs, attrsonly, NULL );
1233 send_search_result( conn, op, LDAP_SUCCESS,
1234 NULL, NULL, NULL, NULL, 1 );
1243 oc_print( ObjectClass *oc )
1248 printf( "objectclass %s\n", ldap_objectclass2name( &oc->soc_oclass ) );
1249 if ( oc->soc_required != NULL ) {
1250 mid = "\trequires ";
1251 for ( i = 0; oc->soc_required[i] != NULL; i++, mid = "," )
1252 printf( "%s%s", mid,
1253 ldap_attributetype2name( &oc->soc_required[i]->sat_atype ) );
1256 if ( oc->soc_allowed != NULL ) {
1258 for ( i = 0; oc->soc_allowed[i] != NULL; i++, mid = "," )
1259 printf( "%s%s", mid,
1260 ldap_attributetype2name( &oc->soc_allowed[i]->sat_atype ) );
1268 int is_entry_objectclass(
1275 if( e == NULL || oc == NULL || *oc == '\0' )
1279 * find objectClass attribute
1281 attr = attr_find(e->e_attrs, "objectclass");
1283 if( attr == NULL ) {
1284 /* no objectClass attribute */
1288 bv.bv_val = (char *) oc;
1289 bv.bv_len = strlen( bv.bv_val );
1291 if( value_find(attr->a_vals, &bv, attr->a_syntax, 1) != 0) {
1292 /* entry is not of this objectclass */