3 * Copyright 1998-2000 The OpenLDAP Foundation, All Rights Reserved.
4 * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
6 /* at.c - routines for dealing with attribute types */
14 #include <ac/socket.h>
15 #include <ac/string.h>
21 #ifndef SLAPD_SCHEMA_NOT_COMPAT
23 at_canonical_name( const char * a_type )
30 return (char *) a_type;
32 } else if ( atp->sat_names
33 && atp->sat_names[0] && (*(atp->sat_names[0]) != '\0') )
35 return atp->sat_names[0];
37 } else if (atp->sat_oid && (*atp->sat_oid != '\0')) {
41 return (char *) a_type;
44 #define DEFAULT_SYNTAX SYNTAX_CIS
47 * attr_syntax - return the syntax of attribute type
51 attr_syntax( const char *type )
57 return( sat->sat_syntax_compat );
60 return( DEFAULT_SYNTAX );
64 * attr_syntax_config - process an attribute syntax config line
76 LDAP_ATTRIBUTE_TYPE *at;
82 Debug( LDAP_DEBUG_ANY,
83 "%s: line %d: missing name in \"attribute <name>+ <syntax>\" (ignored)\n",
88 at = (LDAP_ATTRIBUTE_TYPE *)
89 ch_calloc( 1, sizeof(LDAP_ATTRIBUTE_TYPE) );
91 #define SYNTAX_DS_OID "1.3.6.1.4.1.1466.115.121.1.15"
92 #define SYNTAX_DSCE_OID "2.5.13.5"
93 #define SYNTAX_IA5_OID "1.3.6.1.4.1.1466.115.121.1.26"
94 #define SYNTAX_IA5CE_OID "1.3.6.1.4.1.1466.109.114.1"
95 #define SYNTAX_DN_OID SLAPD_OID_DN_SYNTAX
96 #define SYNTAX_TEL_OID "1.3.6.1.4.1.1466.115.121.1.50"
97 #define SYNTAX_BIN_OID "1.3.6.1.4.1.1466.115.121.1.40" /* octetString */
100 if ( strcasecmp( argv[lasti], "caseignorestring" ) == 0 ||
101 strcasecmp( argv[lasti], "cis" ) == 0 ) {
102 at->at_syntax_oid = SYNTAX_DS_OID;
103 at->at_equality_oid = "2.5.13.2";
104 at->at_ordering_oid = "2.5.13.3";
105 at->at_substr_oid = "2.5.13.4";
107 } else if ( strcasecmp( argv[lasti], "telephone" ) == 0 ||
108 strcasecmp( argv[lasti], "tel" ) == 0 ) {
109 at->at_syntax_oid = SYNTAX_TEL_OID;
110 at->at_equality_oid = "2.5.13.20";
111 at->at_substr_oid = "2.5.13.21";
113 } else if ( strcasecmp( argv[lasti], "dn" ) == 0 ) {
114 at->at_syntax_oid = SYNTAX_DN_OID;
115 at->at_equality_oid = "2.5.13.1";
117 } else if ( strcasecmp( argv[lasti], "caseexactstring" ) == 0 ||
118 strcasecmp( argv[lasti], "ces" ) == 0 ) {
119 at->at_syntax_oid = SYNTAX_DS_OID;
120 at->at_equality_oid = SYNTAX_DSCE_OID;
121 at->at_ordering_oid = "2.5.13.6";
122 at->at_substr_oid = "2.5.13.7";
124 } else if ( strcasecmp( argv[lasti], "binary" ) == 0 ||
125 strcasecmp( argv[lasti], "bin" ) == 0 ) {
126 /* bin -> octetString, not binary! */
127 at->at_syntax_oid = SYNTAX_BIN_OID;
128 at->at_equality_oid = "2.5.13.17";
131 Debug( LDAP_DEBUG_ANY,
132 "%s: line %d: unknown syntax \"%s\" in attribute line (ignored)\n",
133 fname, lineno, argv[lasti] );
134 Debug( LDAP_DEBUG_ANY,
135 "possible syntaxes are \"cis\", \"ces\", \"tel\", \"dn\", or \"bin\"\n",
137 free( (AttributeType *) at );
143 at->at_names = charray_dup( argv );
146 code = at_add( at, &err );
148 fprintf( stderr, "%s: line %d: %s %s\n",
149 fname, lineno, scherr2str(code), err);
150 exit( EXIT_FAILURE );
163 if ( at_find( name ) ) {
166 argv[0] = (char*) name;
169 at_config( "implicit", 0, 2, argv );
180 for( ; sub != NULL; sub = sub->sat_sup ) {
181 if( sub == sup ) return 1;
189 AttributeType *air_at;
192 static Avlnode *attr_index = NULL;
193 static AttributeType *attr_list = NULL;
197 struct aindexrec *air1,
198 struct aindexrec *air2
201 return (strcasecmp( air1->air_name, air2->air_name ));
207 struct aindexrec *air
210 return (strcasecmp( type, air->air_name ));
218 struct aindexrec *air;
221 #ifndef SLAPD_SCHEMA_NOT_COMPAT
223 * The name may actually be an AttributeDescription, i.e. it may
226 /* Treat any attribute type with option as an unknown attribute type */
227 char *p = strchr( name, ';' );
229 tmpname = ch_malloc( p-name+1 );
230 strncpy( tmpname, name, p-name );
231 tmpname[p-name] = '\0';
235 tmpname = (char *)name;
238 if ( (air = (struct aindexrec *) avl_find( attr_index, tmpname,
239 (AVL_CMP) attr_index_name_cmp )) != NULL ) {
240 if ( tmpname != name )
241 ldap_memfree( tmpname );
242 return( air->air_at );
245 if ( tmpname != name )
246 ldap_memfree( tmpname );
253 AttributeType ***listp
256 AttributeType **list;
257 AttributeType **list1;
263 list = calloc(size, sizeof(AttributeType *));
275 list1 = realloc(list, size*sizeof(AttributeType *));
290 AttributeType ***listp
293 AttributeType **list;
294 AttributeType **list1;
302 for ( i=0; list[i]; i++ )
307 for ( i=pos, j=pos+1; list[j]; i++, j++ ) {
311 /* Tell the runtime this can be shrinked */
312 list1 = realloc(list, (i+1)*sizeof(AttributeType **));
331 for ( i=0; list[i]; i++ ) {
332 if ( sat == list[i] ) {
346 struct aindexrec *air;
350 while ( *atp != NULL ) {
351 atp = &(*atp)->sat_next;
355 if ( sat->sat_oid ) {
356 air = (struct aindexrec *)
357 ch_calloc( 1, sizeof(struct aindexrec) );
358 air->air_name = sat->sat_oid;
360 if ( avl_insert( &attr_index, (caddr_t) air,
361 (AVL_CMP) attr_index_cmp,
362 (AVL_DUP) avl_dup_error ) ) {
365 return SLAP_SCHERR_DUP_ATTR;
367 /* FIX: temporal consistency check */
368 at_find(air->air_name);
371 if ( (names = sat->sat_names) ) {
373 air = (struct aindexrec *)
374 ch_calloc( 1, sizeof(struct aindexrec) );
375 air->air_name = ch_strdup(*names);
377 if ( avl_insert( &attr_index, (caddr_t) air,
378 (AVL_CMP) attr_index_cmp,
379 (AVL_DUP) avl_dup_error ) ) {
381 ldap_memfree(air->air_name);
383 return SLAP_SCHERR_DUP_ATTR;
385 /* FIX: temporal consistency check */
386 at_find(air->air_name);
396 LDAP_ATTRIBUTE_TYPE *at,
405 LDAP_SCHEMA_EXTENSION_ITEM **ext;
407 if ( at->at_names && at->at_names[0] ) {
408 cname = at->at_names[0];
409 } else if ( at->at_oid ) {
413 return SLAP_SCHERR_ATTR_INCOMPLETE;
415 sat = (AttributeType *) ch_calloc( 1, sizeof(AttributeType) );
416 memcpy( &sat->sat_atype, at, sizeof(LDAP_ATTRIBUTE_TYPE));
418 #ifdef SLAPD_SCHEMA_NOT_COMPAT
419 sat->sat_cname = cname;
422 if ( at->at_sup_oid ) {
423 AttributeType *supsat = at_find(at->at_sup_oid);
425 if ( (supsat == NULL ) ) {
426 *err = at->at_sup_oid;
427 return SLAP_SCHERR_ATTR_NOT_FOUND;
430 sat->sat_sup = supsat;
432 if ( at_append_to_list(sat, &supsat->sat_subtypes) ) {
434 return SLAP_SCHERR_OUTOFMEM;
439 * Inherit definitions from superiors. We only check the
440 * direct superior since that one has already inherited from
443 if ( sat->sat_sup ) {
444 sat->sat_syntax = sat->sat_sup->sat_syntax;
445 #ifndef SLAPD_SCHEMA_NOT_COMPAT
446 sat->sat_syntax_compat = sat->sat_sup->sat_syntax_compat;
448 sat->sat_equality = sat->sat_sup->sat_equality;
449 sat->sat_ordering = sat->sat_sup->sat_ordering;
450 sat->sat_substr = sat->sat_sup->sat_substr;
451 sat->sat_binary = sat->sat_sup->sat_binary;
452 sat->sat_not_h_r = sat->sat_sup->sat_not_h_r;
455 if ( at->at_syntax_oid ) {
456 if ( (syn = syn_find(sat->sat_syntax_oid)) ) {
457 sat->sat_syntax = syn;
459 *err = sat->sat_syntax_oid;
460 return SLAP_SCHERR_SYN_NOT_FOUND;
463 #ifndef SLAPD_SCHEMA_NOT_COMPAT
464 if ( !strcmp(at->at_syntax_oid, SYNTAX_DS_OID) ) {
465 if ( at->at_equality_oid && (
466 !strcmp(at->at_equality_oid, SYNTAX_DSCE_OID) ) )
468 sat->sat_syntax_compat = SYNTAX_CES;
470 sat->sat_syntax_compat = SYNTAX_CIS;
473 } else if ( !strcmp(at->at_syntax_oid, SYNTAX_IA5_OID) ) {
474 if ( at->at_equality_oid && (
475 !strcmp(at->at_equality_oid, SYNTAX_IA5CE_OID) ) )
477 sat->sat_syntax_compat = SYNTAX_CES;
479 sat->sat_syntax_compat = SYNTAX_CIS;
482 } else if ( !strcmp(at->at_syntax_oid, SYNTAX_DN_OID ) ) {
483 sat->sat_syntax_compat = SYNTAX_CIS | SYNTAX_DN;
485 } else if ( !strcmp(at->at_syntax_oid, SYNTAX_TEL_OID ) ) {
486 sat->sat_syntax_compat = SYNTAX_CIS | SYNTAX_TEL;
488 } else if ( !strcmp(at->at_syntax_oid, SYNTAX_BIN_OID ) ) {
489 sat->sat_syntax_compat = SYNTAX_BIN;
492 sat->sat_syntax_compat = DEFAULT_SYNTAX;
496 } else if ( sat->sat_syntax == NULL ) {
497 return SLAP_SCHERR_ATTR_INCOMPLETE;
500 if ( sat->sat_equality_oid ) {
501 if ( (mr = mr_find(sat->sat_equality_oid)) ) {
502 sat->sat_equality = mr;
504 *err = sat->sat_equality_oid;
505 return SLAP_SCHERR_MR_NOT_FOUND;
510 if ( sat->sat_ordering_oid ) {
511 if ( (mr = mr_find(sat->sat_ordering_oid)) ) {
512 sat->sat_ordering = mr;
514 *err = sat->sat_ordering_oid;
515 return SLAP_SCHERR_MR_NOT_FOUND;
519 if ( sat->sat_substr_oid ) {
520 if ( (mr = mr_find(sat->sat_substr_oid)) ) {
521 sat->sat_substr = mr;
523 *err = sat->sat_substr_oid;
524 return SLAP_SCHERR_MR_NOT_FOUND;
528 if ( sat->sat_extensions ) {
529 for ( ext = sat->sat_extensions; *ext; ext++ ) {
530 if ( strcmp((*ext)->lsei_name, "X-BINARY-TRANSFER-REQUIRED") == 0 &&
531 (*ext)->lsei_values &&
532 (*ext)->lsei_values[0] &&
533 strcasecmp((*ext)->lsei_values[0], "true") == 0 ) {
535 } else if ( strcmp((*ext)->lsei_name, "X-NOT-HUMAN-READABLE") == 0 &&
536 (*ext)->lsei_values &&
537 (*ext)->lsei_values[0] &&
538 strcasecmp((*ext)->lsei_values[0], "true") == 0 ) {
539 sat->sat_not_h_r = 1;
544 code = at_insert(sat,err);
550 at_index_printnode( struct aindexrec *air )
555 ldap_attributetype2str(&air->air_at->sat_atype) );
560 at_index_print( void )
562 printf("Printing attribute type index:\n");
563 (void) avl_apply( attr_index, (AVL_APPLY) at_index_printnode,
564 0, -1, AVL_INORDER );
568 #if defined( SLAPD_SCHEMA_DN )
570 at_schema_info( Entry *e )
573 struct berval *vals[2];
576 #ifdef SLAPD_SCHEMA_NOT_COMPAT
577 AttributeDescription *ad_attributeTypes = slap_schema.si_ad_attributeTypes;
579 char *ad_attributeTypes = "attributeTypes";
585 for ( at = attr_list; at; at = at->sat_next ) {
586 val.bv_val = ldap_attributetype2str( &at->sat_atype );
587 if ( val.bv_val == NULL ) {
590 val.bv_len = strlen( val.bv_val );
592 Debug( LDAP_DEBUG_TRACE, "Merging at [%ld] %s\n",
593 (long) val.bv_len, val.bv_val, 0 );
595 attr_merge( e, ad_attributeTypes, vals );
596 ldap_memfree( val.bv_val );