1 /* ad.c - routines for dealing with attribute descriptions */
3 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
5 * Copyright 1998-2004 The OpenLDAP Foundation.
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted only as authorized by the OpenLDAP
12 * A copy of this license is available in the file LICENSE in the
13 * top-level directory of the distribution or, alternatively, at
14 * <http://www.OpenLDAP.org/license.html>.
23 #include <ac/socket.h>
24 #include <ac/string.h>
30 static AttributeName anlist_no_attrs[] = {
31 { BER_BVC( LDAP_NO_ATTRS ), NULL, 0, NULL },
32 { BER_BVNULL, NULL, 0, NULL }
35 static AttributeName anlist_all_user_attributes[] = {
36 { BER_BVC( LDAP_ALL_USER_ATTRIBUTES ), NULL, 0, NULL },
37 { BER_BVNULL, NULL, 0, NULL }
40 static AttributeName anlist_all_operational_attributes[] = {
41 { BER_BVC( LDAP_ALL_OPERATIONAL_ATTRIBUTES ), NULL, 0, NULL },
42 { BER_BVNULL, NULL, 0, NULL }
45 static AttributeName anlist_all_attributes[] = {
46 { BER_BVC( LDAP_ALL_USER_ATTRIBUTES ), NULL, 0, NULL },
47 { BER_BVC( LDAP_ALL_OPERATIONAL_ATTRIBUTES ), NULL, 0, NULL },
48 { BER_BVNULL, NULL, 0, NULL }
51 AttributeName *slap_anlist_no_attrs = anlist_no_attrs;
52 AttributeName *slap_anlist_all_user_attributes = anlist_all_user_attributes;
53 AttributeName *slap_anlist_all_operational_attributes = anlist_all_operational_attributes;
54 AttributeName *slap_anlist_all_attributes = anlist_all_attributes;
56 typedef struct Attr_option {
57 struct berval name; /* option name or prefix */
58 int prefix; /* NAME is a tag and range prefix */
61 static Attr_option lang_option = { { sizeof("lang-")-1, "lang-" }, 1 };
63 /* Options sorted by name, and number of options */
64 static Attr_option *options = &lang_option;
65 static int option_count = 1;
67 static Attr_option *ad_find_option_definition( const char *opt, int optlen );
69 static int ad_keystring(
74 if( !AD_LEADCHAR( bv->bv_val[0] ) ) {
78 for( i=1; i<bv->bv_len; i++ ) {
79 if( !AD_CHAR( bv->bv_val[i] ) ) {
86 void ad_destroy( AttributeDescription *ad )
88 AttributeDescription *n;
90 for (; ad != NULL; ad = n) {
96 /* Is there an AttributeDescription for this type that uses these tags? */
97 AttributeDescription * ad_find_tags(
101 AttributeDescription *ad;
103 ldap_pvt_thread_mutex_lock( &type->sat_ad_mutex );
104 for (ad = type->sat_ad; ad; ad=ad->ad_next)
106 if (ad->ad_tags.bv_len == tags->bv_len &&
107 !strcasecmp(ad->ad_tags.bv_val, tags->bv_val))
110 ldap_pvt_thread_mutex_unlock( &type->sat_ad_mutex );
116 AttributeDescription **ad,
120 bv.bv_val = (char *) str;
121 bv.bv_len = strlen( str );
123 return slap_bv2ad( &bv, ad, text );
126 static char *strchrlen(
133 for( i=0; p[i]; i++ ) {
136 return (char *) &p[i];
146 AttributeDescription **ad,
149 int rtn = LDAP_UNDEFINED_TYPE;
150 AttributeDescription desc, *d2;
151 char *name, *options;
156 /* hardcoded limits for speed */
157 #define MAX_TAGGING_OPTIONS 128
158 struct berval tags[MAX_TAGGING_OPTIONS+1];
159 #define MAX_TAGS_LEN 1024
160 char tagbuf[MAX_TAGS_LEN];
162 assert( ad != NULL );
163 assert( *ad == NULL ); /* temporary */
165 if( bv == NULL || BER_BVISNULL( bv ) || BER_BVISEMPTY( bv ) ) {
166 *text = "empty AttributeDescription";
170 /* make sure description is IA5 */
171 if( ad_keystring( bv ) ) {
172 *text = "AttributeDescription contains inappropriate characters";
176 /* find valid base attribute type; parse in place */
177 memset( &desc, 0, sizeof( desc ));
180 options = strchr(name, ';');
181 if( options != NULL ) {
182 desc.ad_cname.bv_len = options - name;
184 desc.ad_type = at_bvfind( &desc.ad_cname );
185 if( desc.ad_type == NULL ) {
186 *text = "attribute type undefined";
190 if( is_at_operational( desc.ad_type ) && options != NULL ) {
191 *text = "operational attribute with options undefined";
196 * parse options in place
199 memset( tags, 0, sizeof( tags ));
202 for( opt=options; opt != NULL; opt=next ) {
205 next = strchrlen( opt, ';', &optlen );
208 *text = "zero length option is invalid";
211 } else if ( optlen == sizeof("binary")-1 &&
212 strncasecmp( opt, "binary", sizeof("binary")-1 ) == 0 )
215 if( slap_ad_is_binary( &desc ) ) {
216 *text = "option \"binary\" specified multiple times";
220 if( !slap_syntax_is_binary( desc.ad_type->sat_syntax )) {
221 /* not stored in binary, disallow option */
222 *text = "option \"binary\" not supported with type";
226 desc.ad_flags |= SLAP_DESC_BINARY;
229 } else if ( ad_find_option_definition( opt, optlen ) ) {
232 if( opt[optlen-1] == '-' ) {
233 desc.ad_flags |= SLAP_DESC_TAG_RANGE;
236 if( ntags >= MAX_TAGGING_OPTIONS ) {
237 *text = "too many tagging options";
242 * tags should be presented in sorted order,
243 * so run the array in reverse.
245 for( i=ntags-1; i>=0; i-- ) {
248 rc = strncasecmp( opt, tags[i].bv_val,
249 (unsigned) optlen < tags[i].bv_len
250 ? optlen : tags[i].bv_len );
252 if( rc == 0 && (unsigned)optlen == tags[i].bv_len ) {
253 /* duplicate (ignore) */
256 } else if ( rc > 0 ||
257 ( rc == 0 && (unsigned)optlen > tags[i].bv_len ))
259 AC_MEMCPY( &tags[i+2], &tags[i+1],
260 (ntags-i-1)*sizeof(struct berval) );
261 tags[i+1].bv_val = opt;
262 tags[i+1].bv_len = optlen;
268 AC_MEMCPY( &tags[1], &tags[0],
269 ntags*sizeof(struct berval) );
271 tags[0].bv_val = opt;
272 tags[0].bv_len = optlen;
275 tagslen += optlen + 1;
279 *text = "unrecognized option";
287 if( tagslen > MAX_TAGS_LEN ) {
288 *text = "tagging options too long";
292 desc.ad_tags.bv_val = tagbuf;
295 for( i=0; i<ntags; i++ ) {
296 AC_MEMCPY( &desc.ad_tags.bv_val[tagslen],
297 tags[i].bv_val, tags[i].bv_len );
299 tagslen += tags[i].bv_len;
300 desc.ad_tags.bv_val[tagslen++] = ';';
303 desc.ad_tags.bv_val[--tagslen] = '\0';
304 desc.ad_tags.bv_len = tagslen;
307 /* see if a matching description is already cached */
308 for (d2 = desc.ad_type->sat_ad; d2; d2=d2->ad_next) {
309 if( d2->ad_flags != desc.ad_flags ) {
312 if( d2->ad_tags.bv_len != desc.ad_tags.bv_len ) {
315 if( d2->ad_tags.bv_len == 0 ) {
318 if( strncasecmp( d2->ad_tags.bv_val, desc.ad_tags.bv_val,
319 desc.ad_tags.bv_len ) == 0 )
325 /* Not found, add new one */
328 ldap_pvt_thread_mutex_lock( &desc.ad_type->sat_ad_mutex );
329 /* check again now that we've locked */
330 for (d2 = desc.ad_type->sat_ad; d2; d2=d2->ad_next) {
331 if (d2->ad_flags != desc.ad_flags)
333 if (d2->ad_tags.bv_len != desc.ad_tags.bv_len)
335 if (d2->ad_tags.bv_len == 0)
337 if (strncasecmp(d2->ad_tags.bv_val, desc.ad_tags.bv_val,
338 desc.ad_tags.bv_len) == 0)
342 ldap_pvt_thread_mutex_unlock( &desc.ad_type->sat_ad_mutex );
346 /* Allocate a single contiguous block. If there are no
347 * options, we just need space for the AttrDesc structure.
348 * Otherwise, we need to tack on the full name length +
349 * options length, + maybe tagging options length again.
351 if (desc.ad_tags.bv_len || desc.ad_flags != SLAP_DESC_NONE) {
352 dlen = desc.ad_type->sat_cname.bv_len + 1;
353 if (desc.ad_tags.bv_len) {
354 dlen += 1+desc.ad_tags.bv_len;
356 if( slap_ad_is_binary( &desc ) ) {
357 dlen += sizeof(";binary")+desc.ad_tags.bv_len;
361 d2 = ch_malloc(sizeof(AttributeDescription) + dlen);
363 d2->ad_type = desc.ad_type;
364 d2->ad_flags = desc.ad_flags;
365 d2->ad_cname.bv_len = desc.ad_type->sat_cname.bv_len;
366 d2->ad_tags.bv_len = desc.ad_tags.bv_len;
369 d2->ad_cname.bv_val = d2->ad_type->sat_cname.bv_val;
370 d2->ad_tags.bv_val = NULL;
374 d2->ad_cname.bv_val = (char *)(d2+1);
375 strcpy(d2->ad_cname.bv_val, d2->ad_type->sat_cname.bv_val);
376 cp = d2->ad_cname.bv_val + d2->ad_cname.bv_len;
377 if( slap_ad_is_binary( &desc ) ) {
380 if( desc.ad_tags.bv_len ) {
381 lp = desc.ad_tags.bv_val;
382 while( strncasecmp(lp, "binary", sizeof("binary")-1) < 0
383 && (lp = strchr( lp, ';' )) != NULL )
385 if( lp != desc.ad_tags.bv_val ) {
388 ? lp - desc.ad_tags.bv_val - 1
389 : strlen( desc.ad_tags.bv_val ));
390 cp = lutil_strncopy(cp, desc.ad_tags.bv_val, j);
393 cp = lutil_strcopy(cp, ";binary");
396 cp = lutil_strcopy(cp, lp);
398 d2->ad_cname.bv_len = cp - d2->ad_cname.bv_val;
399 if( desc.ad_tags.bv_len )
400 ldap_pvt_str2lower(op);
405 if( desc.ad_tags.bv_len ) {
406 lp = d2->ad_cname.bv_val + d2->ad_cname.bv_len + j;
409 d2->ad_tags.bv_val = lp;
410 strcpy(lp, desc.ad_tags.bv_val);
411 ldap_pvt_str2lower(lp);
413 d2->ad_cname.bv_len += 1 + desc.ad_tags.bv_len;
416 /* Add new desc to list. We always want the bare Desc with
417 * no options to stay at the head of the list, assuming
418 * that one will be used most frequently.
420 if (desc.ad_type->sat_ad == NULL || dlen == 0) {
421 d2->ad_next = desc.ad_type->sat_ad;
422 desc.ad_type->sat_ad = d2;
424 d2->ad_next = desc.ad_type->sat_ad->ad_next;
425 desc.ad_type->sat_ad->ad_next = d2;
427 ldap_pvt_thread_mutex_unlock( &desc.ad_type->sat_ad_mutex );
439 static int is_ad_subtags(
440 struct berval *subtagsbv,
441 struct berval *suptagsbv )
443 const char *suptags, *supp, *supdelimp;
444 const char *subtags, *subp, *subdelimp;
447 subtags =subtagsbv->bv_val;
448 suptags =suptagsbv->bv_val;
450 for( supp=suptags ; supp; supp=supdelimp ) {
451 supdelimp = strchrlen( supp, ';', &suplen );
452 if( supdelimp ) supdelimp++;
454 for( subp=subtags ; subp; subp=subdelimp ) {
455 subdelimp = strchrlen( subp, ';', &sublen );
456 if( subdelimp ) subdelimp++;
459 ? ( suplen-1 == sublen && supp[suplen-1] == '-'
460 && strncmp( supp, subp, sublen ) == 0 )
461 : ( ( suplen == sublen || supp[suplen-1] == '-' )
462 && strncmp( supp, subp, suplen ) == 0 ) )
475 AttributeDescription *sub,
476 AttributeDescription *super
482 for ( a = sub->ad_type; a; a=a->sat_sup ) {
483 if ( a == super->ad_type ) break;
489 /* ensure sub does support all flags of super */
490 lr = sub->ad_tags.bv_len ? SLAP_DESC_TAG_RANGE : 0;
491 if(( super->ad_flags & ( sub->ad_flags | lr )) != super->ad_flags ) {
495 /* check for tagging options */
496 if ( super->ad_tags.bv_len == 0 )
498 if ( sub->ad_tags.bv_len == 0 )
501 return is_ad_subtags( &sub->ad_tags, &super->ad_tags );
505 AttributeDescription *desc,
506 AttributeName *attrs )
508 if (! attrs ) return 0;
510 for( ; attrs->an_name.bv_val; attrs++ ) {
515 if ( attrs->an_desc ) {
518 if ( desc == attrs->an_desc ) {
523 * EXTENSION: if requested description is preceeded by
524 * a '-' character, do not match on subtypes.
526 if ( attrs->an_name.bv_val[0] == '-' ) {
530 /* Is this a subtype of the requested attr? */
531 for (a = desc->ad_type; a; a=a->sat_sup) {
532 if ( a == attrs->an_desc->ad_type )
538 /* Does desc support all the requested flags? */
539 lr = desc->ad_tags.bv_len ? SLAP_DESC_TAG_RANGE : 0;
540 if(( attrs->an_desc->ad_flags & (desc->ad_flags | lr))
541 != attrs->an_desc->ad_flags ) {
544 /* Do the descs have compatible tags? */
545 if ( attrs->an_desc->ad_tags.bv_len == 0 ) {
548 if ( desc->ad_tags.bv_len == 0) {
551 if ( is_ad_subtags( &desc->ad_tags,
552 &attrs->an_desc->ad_tags ) ) {
559 * EXTENSION: see if requested description is @objectClass
560 * if so, return attributes which the class requires/allows
561 * else if requested description is !objectClass, return
562 * attributes which the class does not require/allow
565 if( oc == NULL && attrs->an_name.bv_val ) {
566 switch( attrs->an_name.bv_val[0] ) {
567 case '@': /* @objectClass */
568 case '+': /* +objectClass (deprecated) */
569 case '!': { /* exclude */
570 struct berval ocname;
571 ocname.bv_len = attrs->an_name.bv_len - 1;
572 ocname.bv_val = &attrs->an_name.bv_val[1];
573 oc = oc_bvfind( &ocname );
574 attrs->an_oc_exclude = 0;
575 if ( oc && attrs->an_name.bv_val[0] == '!' ) {
576 attrs->an_oc_exclude = 1;
580 default: /* old (deprecated) way */
581 oc = oc_bvfind( &attrs->an_name );
586 if ( attrs->an_oc_exclude ) {
589 if ( oc == slap_schema.si_oc_extensibleObject ) {
590 /* extensibleObject allows the return of anything */
594 if( oc->soc_required ) {
595 /* allow return of required attributes */
598 for ( i = 0; oc->soc_required[i] != NULL; i++ ) {
599 for (a = desc->ad_type; a; a=a->sat_sup) {
600 if ( a == oc->soc_required[i] ) {
607 if( oc->soc_allowed ) {
608 /* allow return of allowed attributes */
610 for ( i = 0; oc->soc_allowed[i] != NULL; i++ ) {
611 for (a = desc->ad_type; a; a=a->sat_sup) {
612 if ( a == oc->soc_allowed[i] ) {
622 if ( oc == slap_schema.si_oc_extensibleObject ) {
623 /* extensibleObject allows the return of anything */
627 if( oc->soc_required ) {
628 /* allow return of required attributes */
631 for ( i = 0; oc->soc_required[i] != NULL; i++ ) {
632 for (a = desc->ad_type; a; a=a->sat_sup) {
633 if ( a == oc->soc_required[i] ) {
640 if( oc->soc_allowed ) {
641 /* allow return of allowed attributes */
643 for ( i = 0; oc->soc_allowed[i] != NULL; i++ ) {
644 for (a = desc->ad_type; a; a=a->sat_sup) {
645 if ( a == oc->soc_allowed[i] ) {
653 /* short-circuit this search next time around */
654 if (!slap_schema.si_at_undefined->sat_ad) {
656 slap_bv2undef_ad(&attrs->an_name,
657 &attrs->an_desc, &text);
660 slap_schema.si_at_undefined->sat_ad;
669 int slap_str2undef_ad(
671 AttributeDescription **ad,
675 bv.bv_val = (char *) str;
676 bv.bv_len = strlen( str );
678 return slap_bv2undef_ad( &bv, ad, text );
681 int slap_bv2undef_ad(
683 AttributeDescription **ad,
686 AttributeDescription *desc;
688 assert( ad != NULL );
690 if( bv == NULL || bv->bv_len == 0 ) {
691 *text = "empty AttributeDescription";
692 return LDAP_UNDEFINED_TYPE;
695 /* make sure description is IA5 */
696 if( ad_keystring( bv ) ) {
697 *text = "AttributeDescription contains inappropriate characters";
698 return LDAP_UNDEFINED_TYPE;
701 for( desc = slap_schema.si_at_undefined->sat_ad; desc;
704 if( desc->ad_cname.bv_len == bv->bv_len &&
705 !strcasecmp( desc->ad_cname.bv_val, bv->bv_val ))
712 desc = ch_malloc(sizeof(AttributeDescription) + 1 +
715 desc->ad_flags = SLAP_DESC_NONE;
716 desc->ad_tags.bv_val = NULL;
717 desc->ad_tags.bv_len = 0;
719 desc->ad_cname.bv_len = bv->bv_len;
720 desc->ad_cname.bv_val = (char *)(desc+1);
721 strcpy(desc->ad_cname.bv_val, bv->bv_val);
723 /* canonical to upper case */
724 ldap_pvt_str2upper( desc->ad_cname.bv_val );
726 desc->ad_type = slap_schema.si_at_undefined;
727 desc->ad_next = desc->ad_type->sat_ad;
728 desc->ad_type->sat_ad = desc;
746 if( a == NULL ) return 0;
748 for ( ; a->an_name.bv_val; a++ ) {
749 if ( a->an_name.bv_len != s->bv_len) continue;
750 if ( strcasecmp( s->bv_val, a->an_name.bv_val ) == 0 ) {
759 * Convert a delimited string into a list of AttributeNames; add
760 * on to an existing list if it was given. If the string is not
761 * a valid attribute name, if a '-' is prepended it is skipped
762 * and the remaining name is tried again; if a '@' (or '+') is
763 * prepended, an objectclass name is searched instead; if a '!'
764 * is prepended, the objectclass name is negated.
766 * NOTE: currently, if a valid attribute name is not found, the
767 * same string is also checked as valid objectclass name; however,
768 * this behavior is deprecated.
771 str2anlist( AttributeName *an, char *in, const char *brkstr )
780 /* find last element in list */
781 for (i = 0; an && an[i].an_name.bv_val; i++);
783 /* protect the input string from strtok */
784 str = ch_strdup( in );
786 /* Count words in string */
788 for ( s = str; *s; s++ ) {
789 if ( strchr( brkstr, *s ) != NULL ) {
794 an = ch_realloc( an, ( i + j + 1 ) * sizeof( AttributeName ) );
795 BER_BVZERO( &an[i + j].an_name );
797 for ( s = ldap_pvt_strtok( str, brkstr, &lasts );
799 s = ldap_pvt_strtok( NULL, brkstr, &lasts ) )
801 anew->an_desc = NULL;
803 anew->an_oc_exclude = 0;
804 ber_str2bv(s, 0, 1, &anew->an_name);
805 slap_bv2ad(&anew->an_name, &anew->an_desc, &text);
806 if ( !anew->an_desc ) {
807 switch( anew->an_name.bv_val[0] ) {
809 struct berval adname;
810 adname.bv_len = anew->an_name.bv_len - 1;
811 adname.bv_val = &anew->an_name.bv_val[1];
812 slap_bv2ad(&adname, &anew->an_desc, &text);
813 if ( !anew->an_desc ) {
819 case '+': /* (deprecated) */
821 struct berval ocname;
822 ocname.bv_len = anew->an_name.bv_len - 1;
823 ocname.bv_val = &anew->an_name.bv_val[1];
824 anew->an_oc = oc_bvfind( &ocname );
825 if ( !anew->an_oc ) {
829 if ( anew->an_name.bv_val[0] == '!' ) {
830 anew->an_oc_exclude = 1;
835 /* old (deprecated) way */
836 anew->an_oc = oc_bvfind( &anew->an_name );
837 if ( !anew->an_oc ) {
845 anew->an_name.bv_val = NULL;
850 for ( i = 0; an[i].an_name.bv_val; i++ ) {
851 free( an[i].an_name.bv_val );
855 * overwrites input string
863 char **anlist2charray_x( AttributeName *an, int dup, void *ctx )
869 for ( i = 0; !BER_BVISNULL( &an[i].an_name ); i++ )
871 attrs = (char **) slap_sl_malloc( (i + 1) * sizeof(char *), ctx );
872 for ( i = 0; !BER_BVISNULL( &an[i].an_name ); i++ ) {
874 attrs[i] = ch_strdup( an[i].an_name.bv_val );
876 attrs[i] = an[i].an_name.bv_val;
886 char **anlist2charray( AttributeName *an, int dup )
888 return anlist2charray_x( an, dup, NULL );
892 anlist2attrs( AttributeName * anlist )
899 attrs = anlist2charray( anlist, 1 );
901 for ( i = 0; anlist[i].an_name.bv_val; i++ ) {
902 if ( ( oc = anlist[i].an_oc ) ) {
903 for ( j = 0; oc->soc_required && oc->soc_required[j]; j++ ) ;
905 for ( j = 0; oc->soc_allowed && oc->soc_allowed[j]; j++ ) ;
916 attrs = (char **) ch_realloc( attrs, (i + k + 1) * sizeof( char * ));
918 for ( i = 0; anlist[i].an_name.bv_val; i++ ) {
919 if ( ( oc = anlist[i].an_oc ) ) {
920 for ( j = 0; oc->soc_required && oc->soc_required[j]; j++ ) {
921 attrs[n++] = ch_strdup(
922 oc->soc_required[j]->sat_cname.bv_val );
924 for ( j = 0; oc->soc_allowed && oc->soc_allowed[j]; j++ ) {
925 attrs[n++] = ch_strdup(
926 oc->soc_allowed[j]->sat_cname.bv_val );
935 while ( attrs && attrs[i] ) {
936 if ( *attrs[i] == '@' ) {
937 for ( j = i; attrs[j]; j++ ) {
940 attrs[j] = attrs[j+1];
947 for ( i = 0; attrs && attrs[i]; i++ ) {
949 while ( attrs && attrs[j] ) {
950 if ( !strcmp( attrs[i], attrs[j] )) {
951 for ( k = j; attrs && attrs[k]; k++ ) {
954 attrs[k] = attrs[k+1];
963 attrs = (char **) ch_realloc( attrs, (i+1) * sizeof( char * ));
970 file2anlist( AttributeName *an, const char *fname, const char *brkstr )
976 size_t lmax = LBUFSIZ;
978 fp = fopen( fname, "r" );
980 Debug( LDAP_DEBUG_ANY,
981 "get_attrs_from_file: failed to open attribute list file "
982 "\"%s\": %s\n", fname, strerror(errno), 0 );
986 lcur = line = (char *) ch_malloc( lmax );
988 Debug( LDAP_DEBUG_ANY,
989 "get_attrs_from_file: could not allocate memory\n",
995 while ( fgets( lcur, LBUFSIZ, fp ) != NULL ) {
996 char *str, *s, *next;
997 const char *delimstr = brkstr;
998 if ( ( c = strchr( lcur, '\n' ) ) ) {
1001 } else if ( *(c-1) == '\r' ) {
1008 line = (char *) ch_realloc( line, lmax );
1010 Debug( LDAP_DEBUG_ANY,
1011 "get_attrs_from_file: could not allocate memory\n",
1016 lcur = line + strlen( line );
1019 an = str2anlist( an, line, brkstr );
1030 /* Define an attribute option. */
1032 ad_define_option( const char *name, const char *fname, int lineno )
1035 unsigned int optlen;
1037 if ( options == &lang_option ) {
1046 if ( !DESC_CHAR( name[optlen] ) ) {
1047 Debug( LDAP_DEBUG_ANY,
1048 "%s: line %d: illegal option name \"%s\"\n",
1049 fname, lineno, name );
1052 } while ( name[++optlen] );
1054 options = ch_realloc( options,
1055 (option_count+1) * sizeof(Attr_option) );
1057 if ( strcasecmp( name, "binary" ) == 0
1058 || ad_find_option_definition( name, optlen ) ) {
1059 Debug( LDAP_DEBUG_ANY,
1060 "%s: line %d: option \"%s\" is already defined\n",
1061 fname, lineno, name );
1065 for ( i = option_count; i; --i ) {
1066 if ( strcasecmp( name, options[i-1].name.bv_val ) >= 0 )
1068 options[i] = options[i-1];
1071 options[i].name.bv_val = ch_strdup( name );
1072 options[i].name.bv_len = optlen;
1073 options[i].prefix = (name[optlen-1] == '-');
1075 if ( i != option_count &&
1076 options[i].prefix &&
1077 optlen < options[i+1].name.bv_len &&
1078 strncasecmp( name, options[i+1].name.bv_val, optlen ) == 0 ) {
1079 Debug( LDAP_DEBUG_ANY,
1080 "%s: line %d: option \"%s\" overrides previous option\n",
1081 fname, lineno, name );
1089 /* Find the definition of the option name or prefix matching the arguments */
1090 static Attr_option *
1091 ad_find_option_definition( const char *opt, int optlen )
1093 int top = 0, bot = option_count;
1094 while ( top < bot ) {
1095 int mid = (top + bot) / 2;
1096 int mlen = options[mid].name.bv_len;
1097 char *mname = options[mid].name.bv_val;
1099 if ( optlen < mlen ) {
1100 j = strncasecmp( opt, mname, optlen ) - 1;
1102 j = strncasecmp( opt, mname, mlen );
1103 if ( j==0 && (optlen==mlen || options[mid].prefix) )
1104 return &options[mid];
1114 MatchingRule *ad_mr(
1115 AttributeDescription *ad,
1118 switch( usage & SLAP_MR_TYPE_MASK ) {
1120 case SLAP_MR_EQUALITY:
1121 return ad->ad_type->sat_equality;
1123 case SLAP_MR_ORDERING:
1124 return ad->ad_type->sat_ordering;
1126 case SLAP_MR_SUBSTR:
1127 return ad->ad_type->sat_substr;
1131 assert( 0 /* ad_mr: bad usage */);