2000-02-07 05:09:44 +08:00
|
|
|
/* $OpenLDAP$ */
|
|
|
|
/*
|
2002-01-05 05:17:25 +08:00
|
|
|
* Copyright 1998-2002 The OpenLDAP Foundation, All Rights Reserved.
|
2000-02-07 05:09:44 +08:00
|
|
|
* COPYING RESTRICTIONS APPLY, see COPYRIGHT file
|
|
|
|
*/
|
|
|
|
/* ad.c - routines for dealing with attribute descriptions */
|
|
|
|
|
|
|
|
#include "portable.h"
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
|
|
|
#include <ac/ctype.h>
|
|
|
|
#include <ac/errno.h>
|
|
|
|
#include <ac/socket.h>
|
|
|
|
#include <ac/string.h>
|
|
|
|
#include <ac/time.h>
|
|
|
|
|
|
|
|
#include "ldap_pvt.h"
|
|
|
|
#include "slap.h"
|
|
|
|
|
2000-02-15 04:57:34 +08:00
|
|
|
static int ad_keystring(
|
|
|
|
struct berval *bv )
|
|
|
|
{
|
|
|
|
ber_len_t i;
|
|
|
|
|
|
|
|
if( !AD_CHAR( bv->bv_val[0] ) ) {
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
for( i=1; i<bv->bv_len; i++ ) {
|
|
|
|
if( !AD_CHAR( bv->bv_val[i] ) ) {
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2002-01-08 04:28:02 +08:00
|
|
|
void ad_destroy( AttributeDescription *ad )
|
2001-11-07 09:03:49 +08:00
|
|
|
{
|
2002-01-08 04:28:02 +08:00
|
|
|
AttributeDescription *n;
|
2001-11-07 09:03:49 +08:00
|
|
|
|
2002-01-08 04:28:02 +08:00
|
|
|
for (; ad != NULL; ad = n) {
|
2001-11-07 09:03:49 +08:00
|
|
|
n = ad->ad_next;
|
2002-01-08 04:28:02 +08:00
|
|
|
ldap_memfree( ad );
|
2001-11-07 09:03:49 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-11-16 15:39:14 +08:00
|
|
|
/* Is there an AttributeDescription for this type that uses this language? */
|
|
|
|
AttributeDescription * ad_find_lang(
|
|
|
|
AttributeType *type,
|
|
|
|
struct berval *lang )
|
|
|
|
{
|
|
|
|
AttributeDescription *ad;
|
|
|
|
|
|
|
|
ldap_pvt_thread_mutex_lock( &type->sat_ad_mutex );
|
|
|
|
for (ad = type->sat_ad; ad; ad=ad->ad_next)
|
|
|
|
{
|
|
|
|
if (ad->ad_lang.bv_len == lang->bv_len &&
|
|
|
|
!strcasecmp(ad->ad_lang.bv_val, lang->bv_val))
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
ldap_pvt_thread_mutex_unlock( &type->sat_ad_mutex );
|
|
|
|
return ad;
|
|
|
|
}
|
|
|
|
|
2000-02-15 04:57:34 +08:00
|
|
|
int slap_str2ad(
|
|
|
|
const char *str,
|
|
|
|
AttributeDescription **ad,
|
2000-05-22 11:46:57 +08:00
|
|
|
const char **text )
|
2000-02-15 04:57:34 +08:00
|
|
|
{
|
|
|
|
struct berval bv;
|
|
|
|
bv.bv_val = (char *) str;
|
|
|
|
bv.bv_len = strlen( str );
|
|
|
|
|
|
|
|
return slap_bv2ad( &bv, ad, text );
|
|
|
|
}
|
|
|
|
|
2002-01-27 07:14:51 +08:00
|
|
|
static char *strchrlen(
|
|
|
|
const char *p,
|
|
|
|
const char ch,
|
|
|
|
int *len )
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for( i=0; p[i]; i++ ) {
|
|
|
|
if( p[i] == ch ) {
|
|
|
|
*len = i;
|
|
|
|
return (char *) &p[i];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
*len = i;
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2000-02-07 05:09:44 +08:00
|
|
|
int slap_bv2ad(
|
|
|
|
struct berval *bv,
|
|
|
|
AttributeDescription **ad,
|
2000-05-22 11:46:57 +08:00
|
|
|
const char **text )
|
2000-02-07 05:09:44 +08:00
|
|
|
{
|
|
|
|
int rtn = LDAP_UNDEFINED_TYPE;
|
2001-10-22 21:23:05 +08:00
|
|
|
AttributeDescription desc, *d2;
|
|
|
|
char *name, *options;
|
2002-01-27 07:14:51 +08:00
|
|
|
char *opt, *next;
|
|
|
|
int nlang;
|
|
|
|
int langlen;
|
|
|
|
|
|
|
|
/* hardcoded limits for speed */
|
|
|
|
#define MAX_LANG_OPTIONS 128
|
|
|
|
struct berval langs[MAX_LANG_OPTIONS+1];
|
|
|
|
#define MAX_LANG_LEN 1024
|
|
|
|
char langbuf[MAX_LANG_LEN];
|
2000-02-07 05:09:44 +08:00
|
|
|
|
2000-05-16 02:46:03 +08:00
|
|
|
assert( ad != NULL );
|
2000-05-17 06:04:49 +08:00
|
|
|
assert( *ad == NULL ); /* temporary */
|
2000-02-07 05:09:44 +08:00
|
|
|
|
|
|
|
if( bv == NULL || bv->bv_len == 0 ) {
|
|
|
|
*text = "empty attribute description";
|
2000-05-16 02:46:03 +08:00
|
|
|
return rtn;
|
2000-02-07 05:09:44 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* make sure description is IA5 */
|
2000-02-15 04:57:34 +08:00
|
|
|
if( ad_keystring( bv ) ) {
|
|
|
|
*text = "attribute description contains inappropriate characters";
|
2000-05-16 02:46:03 +08:00
|
|
|
return rtn;
|
2000-02-07 05:09:44 +08:00
|
|
|
}
|
|
|
|
|
2001-10-22 21:23:05 +08:00
|
|
|
/* find valid base attribute type; parse in place */
|
2002-01-27 07:14:51 +08:00
|
|
|
memset( &desc, 0, sizeof( desc ));
|
2001-12-26 12:17:49 +08:00
|
|
|
desc.ad_cname = *bv;
|
2001-10-22 21:23:05 +08:00
|
|
|
name = bv->bv_val;
|
|
|
|
options = strchr(name, ';');
|
2002-01-27 07:14:51 +08:00
|
|
|
if( options != NULL ) {
|
2001-12-26 12:17:49 +08:00
|
|
|
desc.ad_cname.bv_len = options - name;
|
2002-01-12 04:47:24 +08:00
|
|
|
}
|
2001-12-26 12:17:49 +08:00
|
|
|
desc.ad_type = at_bvfind( &desc.ad_cname );
|
2000-02-07 05:09:44 +08:00
|
|
|
if( desc.ad_type == NULL ) {
|
|
|
|
*text = "attribute type undefined";
|
2001-10-22 21:23:05 +08:00
|
|
|
return rtn;
|
2000-02-07 05:09:44 +08:00
|
|
|
}
|
|
|
|
|
2002-01-12 04:47:24 +08:00
|
|
|
if( is_at_operational( desc.ad_type ) && options != NULL ) {
|
|
|
|
*text = "operational attribute with options undefined";
|
|
|
|
return rtn;
|
|
|
|
}
|
|
|
|
|
2002-01-27 07:14:51 +08:00
|
|
|
/*
|
|
|
|
* parse options in place
|
|
|
|
*/
|
|
|
|
nlang = 0;
|
|
|
|
memset( langs, 0, sizeof( langs ));
|
|
|
|
langlen = 0;
|
|
|
|
|
|
|
|
for( opt=options; opt != NULL; opt=next ) {
|
|
|
|
int optlen;
|
|
|
|
opt++;
|
|
|
|
next = strchrlen( opt, ';', &optlen );
|
|
|
|
|
|
|
|
if( optlen == 0 ) {
|
|
|
|
*text = "zero length option is invalid";
|
|
|
|
return rtn;
|
|
|
|
|
|
|
|
} else if ( optlen == sizeof("binary")-1 &&
|
|
|
|
strncasecmp( opt, "binary", sizeof("binary")-1 ) == 0 )
|
|
|
|
{
|
|
|
|
/* binary option */
|
2000-05-19 01:21:42 +08:00
|
|
|
if( slap_ad_is_binary( &desc ) ) {
|
2000-02-07 05:09:44 +08:00
|
|
|
*text = "option \"binary\" specified multiple times";
|
2002-01-27 07:14:51 +08:00
|
|
|
return rtn;
|
2000-02-07 05:09:44 +08:00
|
|
|
}
|
|
|
|
|
2000-05-19 01:21:42 +08:00
|
|
|
if( !slap_syntax_is_binary( desc.ad_type->sat_syntax )) {
|
2000-02-07 05:09:44 +08:00
|
|
|
/* not stored in binary, disallow option */
|
2002-02-12 12:51:23 +08:00
|
|
|
*text = "option \"binary\" not supported with type";
|
2002-01-27 07:14:51 +08:00
|
|
|
return rtn;
|
2000-02-07 05:09:44 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
desc.ad_flags |= SLAP_DESC_BINARY;
|
2002-01-27 07:14:51 +08:00
|
|
|
continue;
|
2000-02-07 05:09:44 +08:00
|
|
|
|
2002-01-27 07:14:51 +08:00
|
|
|
} else if ( optlen >= sizeof("lang-")-1 &&
|
|
|
|
strncasecmp( opt, "lang-", sizeof("lang-")-1 ) == 0 )
|
2000-02-07 05:09:44 +08:00
|
|
|
{
|
2002-01-27 07:14:51 +08:00
|
|
|
int i;
|
|
|
|
|
|
|
|
if( opt[optlen-1] == '-' ) {
|
|
|
|
desc.ad_flags |= SLAP_DESC_LANG_RANGE;
|
2000-02-07 05:09:44 +08:00
|
|
|
}
|
2000-06-05 06:59:38 +08:00
|
|
|
|
2002-01-27 07:14:51 +08:00
|
|
|
if( nlang >= MAX_LANG_OPTIONS ) {
|
|
|
|
*text = "too many language options";
|
|
|
|
return rtn;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* tags should be presented in sorted order,
|
|
|
|
* so run the array in reverse.
|
|
|
|
*/
|
|
|
|
for( i=nlang-1; i>=0; i-- ) {
|
|
|
|
int rc;
|
|
|
|
|
|
|
|
rc = strncasecmp( opt, langs[i].bv_val,
|
2002-01-29 04:25:30 +08:00
|
|
|
(unsigned) optlen < langs[i].bv_len
|
|
|
|
? optlen : langs[i].bv_len );
|
2002-01-27 07:14:51 +08:00
|
|
|
|
2002-01-29 04:25:30 +08:00
|
|
|
if( rc == 0 && (unsigned)optlen == langs[i].bv_len ) {
|
2002-01-27 07:14:51 +08:00
|
|
|
/* duplicate (ignore) */
|
|
|
|
goto done;
|
|
|
|
|
|
|
|
} else if ( rc > 0 ||
|
2002-01-29 04:25:30 +08:00
|
|
|
( rc == 0 && (unsigned)optlen > langs[i].bv_len ))
|
2002-01-27 07:14:51 +08:00
|
|
|
{
|
|
|
|
AC_MEMCPY( &langs[i+1], &langs[i],
|
|
|
|
(nlang-i)*sizeof(struct berval) );
|
|
|
|
langs[i].bv_val = opt;
|
|
|
|
langs[i].bv_len = optlen;
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if( nlang ) {
|
|
|
|
AC_MEMCPY( &langs[1], &langs[0],
|
|
|
|
nlang*sizeof(struct berval) );
|
|
|
|
}
|
|
|
|
langs[0].bv_val = opt;
|
|
|
|
langs[0].bv_len = optlen;
|
|
|
|
|
|
|
|
done:;
|
|
|
|
langlen += optlen + 1;
|
|
|
|
nlang++;
|
|
|
|
|
2000-02-07 05:09:44 +08:00
|
|
|
} else {
|
|
|
|
*text = "unrecognized option";
|
2002-01-27 07:14:51 +08:00
|
|
|
return rtn;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if( nlang > 0 ) {
|
|
|
|
int i;
|
|
|
|
|
|
|
|
if( langlen > MAX_LANG_LEN ) {
|
|
|
|
*text = "language options too long";
|
|
|
|
return rtn;
|
|
|
|
}
|
|
|
|
|
|
|
|
desc.ad_lang.bv_val = langbuf;
|
|
|
|
langlen = 0;
|
|
|
|
|
|
|
|
for( i=0; i<nlang; i++ ) {
|
|
|
|
AC_MEMCPY( &desc.ad_lang.bv_val[langlen],
|
|
|
|
langs[i].bv_val, langs[i].bv_len );
|
|
|
|
|
|
|
|
langlen += langs[i].bv_len;
|
|
|
|
desc.ad_lang.bv_val[langlen++] = ';';
|
2000-02-07 05:09:44 +08:00
|
|
|
}
|
2002-01-27 07:14:51 +08:00
|
|
|
|
|
|
|
desc.ad_lang.bv_val[--langlen] = '\0';
|
|
|
|
desc.ad_lang.bv_len = langlen;
|
2000-02-07 05:09:44 +08:00
|
|
|
}
|
|
|
|
|
2001-10-22 21:23:05 +08:00
|
|
|
/* see if a matching description is already cached */
|
|
|
|
for (d2 = desc.ad_type->sat_ad; d2; d2=d2->ad_next) {
|
2002-01-27 07:14:51 +08:00
|
|
|
if( d2->ad_flags != desc.ad_flags ) {
|
2001-10-22 21:23:05 +08:00
|
|
|
continue;
|
2002-01-27 07:14:51 +08:00
|
|
|
}
|
|
|
|
if( d2->ad_lang.bv_len != desc.ad_lang.bv_len ) {
|
2001-10-22 21:23:05 +08:00
|
|
|
continue;
|
2002-01-27 07:14:51 +08:00
|
|
|
}
|
|
|
|
if( d2->ad_lang.bv_len == 0 ) {
|
2001-10-22 21:23:05 +08:00
|
|
|
break;
|
2002-01-27 07:14:51 +08:00
|
|
|
}
|
|
|
|
if( strncasecmp( d2->ad_lang.bv_val, desc.ad_lang.bv_val,
|
|
|
|
desc.ad_lang.bv_len ) == 0 )
|
|
|
|
{
|
2001-10-22 21:23:05 +08:00
|
|
|
break;
|
2002-01-27 07:14:51 +08:00
|
|
|
}
|
2000-02-07 05:09:44 +08:00
|
|
|
}
|
|
|
|
|
2001-10-22 21:23:05 +08:00
|
|
|
/* Not found, add new one */
|
|
|
|
while (d2 == NULL) {
|
2002-02-12 08:35:29 +08:00
|
|
|
size_t dlen = 0;
|
2001-12-28 19:45:25 +08:00
|
|
|
ldap_pvt_thread_mutex_lock( &desc.ad_type->sat_ad_mutex );
|
|
|
|
/* check again now that we've locked */
|
|
|
|
for (d2 = desc.ad_type->sat_ad; d2; d2=d2->ad_next) {
|
|
|
|
if (d2->ad_flags != desc.ad_flags)
|
|
|
|
continue;
|
|
|
|
if (d2->ad_lang.bv_len != desc.ad_lang.bv_len)
|
|
|
|
continue;
|
|
|
|
if (d2->ad_lang.bv_len == 0)
|
|
|
|
break;
|
|
|
|
if (strncasecmp(d2->ad_lang.bv_val, desc.ad_lang.bv_val,
|
|
|
|
desc.ad_lang.bv_len) == 0)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (d2) {
|
|
|
|
ldap_pvt_thread_mutex_unlock( &desc.ad_type->sat_ad_mutex );
|
|
|
|
break;
|
|
|
|
}
|
2000-02-07 05:09:44 +08:00
|
|
|
|
2001-10-22 21:23:05 +08:00
|
|
|
/* Allocate a single contiguous block. If there are no
|
|
|
|
* options, we just need space for the AttrDesc structure.
|
|
|
|
* Otherwise, we need to tack on the full name length +
|
|
|
|
* options length.
|
|
|
|
*/
|
|
|
|
if (desc.ad_lang.bv_len || desc.ad_flags != SLAP_DESC_NONE) {
|
2002-02-12 08:35:29 +08:00
|
|
|
dlen = desc.ad_type->sat_cname.bv_len;
|
2002-01-27 07:14:51 +08:00
|
|
|
if (desc.ad_lang.bv_len) {
|
2002-02-12 08:35:29 +08:00
|
|
|
dlen += 1+desc.ad_lang.bv_len;
|
2002-01-27 07:14:51 +08:00
|
|
|
}
|
2001-10-22 21:23:05 +08:00
|
|
|
if( slap_ad_is_binary( &desc ) ) {
|
2002-02-12 08:35:29 +08:00
|
|
|
dlen += sizeof(";binary")-1;
|
2001-10-22 21:23:05 +08:00
|
|
|
}
|
|
|
|
}
|
2000-02-07 05:09:44 +08:00
|
|
|
|
2002-02-12 08:35:29 +08:00
|
|
|
d2 = ch_malloc(sizeof(AttributeDescription) + dlen + 1);
|
2001-10-22 21:23:05 +08:00
|
|
|
d2->ad_type = desc.ad_type;
|
|
|
|
d2->ad_flags = desc.ad_flags;
|
2002-04-18 20:21:33 +08:00
|
|
|
d2->ad_cname.bv_len = desc.ad_type->sat_cname.bv_len;
|
2001-10-22 21:23:05 +08:00
|
|
|
d2->ad_lang.bv_len = desc.ad_lang.bv_len;
|
2002-02-12 08:35:29 +08:00
|
|
|
|
2001-10-22 21:23:05 +08:00
|
|
|
if (dlen == 0) {
|
2001-11-16 15:39:14 +08:00
|
|
|
d2->ad_cname.bv_val = d2->ad_type->sat_cname.bv_val;
|
2001-10-22 21:23:05 +08:00
|
|
|
d2->ad_lang.bv_val = NULL;
|
|
|
|
} else {
|
|
|
|
d2->ad_cname.bv_val = (char *)(d2+1);
|
2001-11-16 15:39:14 +08:00
|
|
|
strcpy(d2->ad_cname.bv_val, d2->ad_type->sat_cname.bv_val);
|
2001-10-22 21:23:05 +08:00
|
|
|
if( slap_ad_is_binary( &desc ) ) {
|
|
|
|
strcpy(d2->ad_cname.bv_val+d2->ad_cname.bv_len,
|
|
|
|
";binary");
|
2002-02-12 08:35:29 +08:00
|
|
|
d2->ad_cname.bv_len += sizeof(";binary")-1;
|
2001-10-22 21:23:05 +08:00
|
|
|
}
|
|
|
|
if( d2->ad_lang.bv_len ) {
|
|
|
|
d2->ad_cname.bv_val[d2->ad_cname.bv_len++]=';';
|
|
|
|
d2->ad_lang.bv_val = d2->ad_cname.bv_val+
|
|
|
|
d2->ad_cname.bv_len;
|
|
|
|
strncpy(d2->ad_lang.bv_val,desc.ad_lang.bv_val,
|
|
|
|
d2->ad_lang.bv_len);
|
|
|
|
d2->ad_lang.bv_val[d2->ad_lang.bv_len] = '\0';
|
|
|
|
ldap_pvt_str2lower(d2->ad_lang.bv_val);
|
|
|
|
d2->ad_cname.bv_len += d2->ad_lang.bv_len;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/* Add new desc to list. We always want the bare Desc with
|
|
|
|
* no options to stay at the head of the list, assuming
|
|
|
|
* that one will be used most frequently.
|
|
|
|
*/
|
|
|
|
if (desc.ad_type->sat_ad == NULL || dlen == 0) {
|
|
|
|
d2->ad_next = desc.ad_type->sat_ad;
|
|
|
|
desc.ad_type->sat_ad = d2;
|
|
|
|
} else {
|
|
|
|
d2->ad_next = desc.ad_type->sat_ad->ad_next;
|
|
|
|
desc.ad_type->sat_ad->ad_next = d2;
|
|
|
|
}
|
2001-12-28 19:45:25 +08:00
|
|
|
ldap_pvt_thread_mutex_unlock( &desc.ad_type->sat_ad_mutex );
|
2000-02-07 05:09:44 +08:00
|
|
|
}
|
|
|
|
|
2000-02-26 03:36:07 +08:00
|
|
|
if( *ad == NULL ) {
|
2001-10-22 21:23:05 +08:00
|
|
|
*ad = d2;
|
|
|
|
} else {
|
|
|
|
**ad = *d2;
|
2000-02-26 03:36:07 +08:00
|
|
|
}
|
|
|
|
|
2002-01-27 07:14:51 +08:00
|
|
|
return LDAP_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int is_ad_sublang(
|
2002-08-21 03:08:18 +08:00
|
|
|
struct berval *sublangbv,
|
|
|
|
struct berval *suplangbv )
|
2002-01-27 07:14:51 +08:00
|
|
|
{
|
2002-08-21 03:08:18 +08:00
|
|
|
const char *suplang, *supp, *supdelimp;
|
|
|
|
const char *sublang, *subp, *subdelimp;
|
2002-01-27 07:14:51 +08:00
|
|
|
int suplen, sublen;
|
|
|
|
|
2002-08-21 03:08:18 +08:00
|
|
|
if( suplangbv->bv_len == 0 ) return 1;
|
|
|
|
if( sublangbv->bv_len == 0 ) return 0;
|
|
|
|
|
|
|
|
sublang =sublangbv->bv_val;
|
|
|
|
suplang =suplangbv->bv_val;
|
2002-01-27 07:14:51 +08:00
|
|
|
|
|
|
|
for( supp=suplang ; supp; supp=supdelimp ) {
|
|
|
|
supdelimp = strchrlen( supp, ';', &suplen );
|
|
|
|
if( supdelimp ) supdelimp++;
|
|
|
|
|
|
|
|
for( subp=sublang ; subp; subp=subdelimp ) {
|
|
|
|
subdelimp = strchrlen( subp, ';', &sublen );
|
|
|
|
if( subdelimp ) subdelimp++;
|
|
|
|
|
|
|
|
if ((( suplen < sublen && supp[suplen-1] == '-' ) ||
|
|
|
|
suplen == sublen ) && strncmp( supp, subp, suplen ) == 0 )
|
|
|
|
{
|
|
|
|
goto match;
|
|
|
|
}
|
|
|
|
}
|
2000-02-07 05:09:44 +08:00
|
|
|
|
2002-01-27 07:14:51 +08:00
|
|
|
return 0;
|
|
|
|
match:;
|
|
|
|
}
|
|
|
|
return 1;
|
2000-02-07 05:09:44 +08:00
|
|
|
}
|
|
|
|
|
2000-02-29 05:16:05 +08:00
|
|
|
int is_ad_subtype(
|
|
|
|
AttributeDescription *sub,
|
|
|
|
AttributeDescription *super
|
|
|
|
)
|
|
|
|
{
|
2002-01-27 07:14:51 +08:00
|
|
|
int lr;
|
|
|
|
|
2000-02-29 05:16:05 +08:00
|
|
|
if( !is_at_subtype( sub->ad_type, super->ad_type ) ) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2002-01-27 07:14:51 +08:00
|
|
|
/* ensure sub does support all flags of super */
|
|
|
|
lr = sub->ad_lang.bv_len ? SLAP_DESC_LANG_RANGE : 0;
|
|
|
|
if(( super->ad_flags & ( sub->ad_flags | lr )) != super->ad_flags ) {
|
2000-02-29 05:16:05 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2002-01-27 07:14:51 +08:00
|
|
|
/* check for language tags */
|
2002-08-21 03:08:18 +08:00
|
|
|
if ( !is_ad_sublang( &sub->ad_lang, &super->ad_lang )) {
|
2000-02-29 05:16:05 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2000-02-26 03:36:07 +08:00
|
|
|
int ad_inlist(
|
|
|
|
AttributeDescription *desc,
|
2001-12-31 19:35:52 +08:00
|
|
|
AttributeName *attrs )
|
2000-02-07 05:09:44 +08:00
|
|
|
{
|
2002-01-03 13:38:26 +08:00
|
|
|
if (! attrs ) return 0;
|
|
|
|
|
|
|
|
for( ; attrs->an_name.bv_val; attrs++ ) {
|
2001-12-06 09:02:11 +08:00
|
|
|
ObjectClass *oc;
|
2000-02-29 05:16:05 +08:00
|
|
|
int rc;
|
|
|
|
|
2001-12-31 19:35:52 +08:00
|
|
|
if ( attrs->an_desc ) {
|
|
|
|
if ( is_ad_subtype( desc, attrs->an_desc ))
|
|
|
|
return 1;
|
2001-12-06 09:02:11 +08:00
|
|
|
continue;
|
|
|
|
}
|
2000-02-07 05:09:44 +08:00
|
|
|
|
2001-12-06 09:02:11 +08:00
|
|
|
/*
|
|
|
|
* EXTENSION: see if requested description is an object class
|
|
|
|
* if so, return attributes which the class requires/allows
|
|
|
|
*/
|
2002-01-10 17:54:14 +08:00
|
|
|
oc = attrs->an_oc;
|
|
|
|
if( oc == NULL ) {
|
|
|
|
oc = oc_bvfind( &attrs->an_name );
|
|
|
|
attrs->an_oc = oc;
|
|
|
|
}
|
2001-12-06 09:02:11 +08:00
|
|
|
if( oc != NULL ) {
|
|
|
|
if ( oc == slap_schema.si_oc_extensibleObject ) {
|
|
|
|
/* extensibleObject allows the return of anything */
|
|
|
|
return 1;
|
|
|
|
}
|
2000-02-26 03:36:07 +08:00
|
|
|
|
2001-12-06 09:02:11 +08:00
|
|
|
if( oc->soc_required ) {
|
|
|
|
/* allow return of required attributes */
|
|
|
|
int i;
|
|
|
|
for ( i = 0; oc->soc_required[i] != NULL; i++ ) {
|
|
|
|
rc = is_at_subtype( desc->ad_type,
|
2002-02-15 22:48:01 +08:00
|
|
|
oc->soc_required[i] );
|
2001-12-06 09:02:11 +08:00
|
|
|
if( rc ) return 1;
|
|
|
|
}
|
|
|
|
}
|
2002-01-27 07:14:51 +08:00
|
|
|
|
2001-12-06 09:02:11 +08:00
|
|
|
if( oc->soc_allowed ) {
|
|
|
|
/* allow return of allowed attributes */
|
|
|
|
int i;
|
|
|
|
for ( i = 0; oc->soc_allowed[i] != NULL; i++ ) {
|
|
|
|
rc = is_at_subtype( desc->ad_type,
|
|
|
|
oc->soc_allowed[i] );
|
|
|
|
if( rc ) return 1;
|
|
|
|
}
|
|
|
|
}
|
2002-01-27 07:14:51 +08:00
|
|
|
|
2001-12-31 22:47:20 +08:00
|
|
|
} else {
|
|
|
|
/* short-circuit this search next time around */
|
|
|
|
if (!slap_schema.si_at_undefined->sat_ad) {
|
|
|
|
const char *text;
|
|
|
|
slap_bv2undef_ad(&attrs->an_name,
|
|
|
|
&attrs->an_desc, &text);
|
|
|
|
} else {
|
|
|
|
attrs->an_desc =
|
|
|
|
slap_schema.si_at_undefined->sat_ad;
|
|
|
|
}
|
2001-12-06 09:02:11 +08:00
|
|
|
}
|
2000-02-26 03:36:07 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
2000-02-07 05:09:44 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-07-03 01:16:18 +08:00
|
|
|
int slap_str2undef_ad(
|
|
|
|
const char *str,
|
|
|
|
AttributeDescription **ad,
|
|
|
|
const char **text )
|
|
|
|
{
|
|
|
|
struct berval bv;
|
|
|
|
bv.bv_val = (char *) str;
|
|
|
|
bv.bv_len = strlen( str );
|
|
|
|
|
|
|
|
return slap_bv2undef_ad( &bv, ad, text );
|
|
|
|
}
|
|
|
|
|
|
|
|
int slap_bv2undef_ad(
|
|
|
|
struct berval *bv,
|
|
|
|
AttributeDescription **ad,
|
|
|
|
const char **text )
|
|
|
|
{
|
2001-10-22 21:23:05 +08:00
|
|
|
AttributeDescription *desc;
|
2000-07-03 01:16:18 +08:00
|
|
|
|
|
|
|
assert( ad != NULL );
|
|
|
|
|
|
|
|
if( bv == NULL || bv->bv_len == 0 ) {
|
|
|
|
*text = "empty attribute description";
|
|
|
|
return LDAP_UNDEFINED_TYPE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* make sure description is IA5 */
|
|
|
|
if( ad_keystring( bv ) ) {
|
|
|
|
*text = "attribute description contains inappropriate characters";
|
|
|
|
return LDAP_UNDEFINED_TYPE;
|
|
|
|
}
|
|
|
|
|
2002-01-27 07:14:51 +08:00
|
|
|
for( desc = slap_schema.si_at_undefined->sat_ad; desc;
|
|
|
|
desc=desc->ad_next )
|
|
|
|
{
|
|
|
|
if( desc->ad_cname.bv_len == bv->bv_len &&
|
|
|
|
!strcasecmp( desc->ad_cname.bv_val, bv->bv_val ))
|
|
|
|
{
|
2001-10-22 21:23:05 +08:00
|
|
|
break;
|
2002-01-27 07:14:51 +08:00
|
|
|
}
|
|
|
|
}
|
2001-10-22 21:23:05 +08:00
|
|
|
|
2002-01-27 07:14:51 +08:00
|
|
|
if( !desc ) {
|
2002-02-12 12:51:23 +08:00
|
|
|
desc = ch_malloc(sizeof(AttributeDescription) + 1 +
|
|
|
|
bv->bv_len);
|
2001-10-22 21:23:05 +08:00
|
|
|
|
|
|
|
desc->ad_flags = SLAP_DESC_NONE;
|
|
|
|
desc->ad_lang.bv_val = NULL;
|
|
|
|
desc->ad_lang.bv_len = 0;
|
2000-07-03 01:16:18 +08:00
|
|
|
|
2001-10-22 21:23:05 +08:00
|
|
|
desc->ad_cname.bv_len = bv->bv_len;
|
|
|
|
desc->ad_cname.bv_val = (char *)(desc+1);
|
|
|
|
strcpy(desc->ad_cname.bv_val, bv->bv_val);
|
2000-07-03 01:16:18 +08:00
|
|
|
|
2001-10-22 21:23:05 +08:00
|
|
|
/* canonical to upper case */
|
|
|
|
ldap_pvt_str2upper( desc->ad_cname.bv_val );
|
2000-07-03 01:16:18 +08:00
|
|
|
|
2001-10-22 21:23:05 +08:00
|
|
|
desc->ad_type = slap_schema.si_at_undefined;
|
|
|
|
desc->ad_next = desc->ad_type->sat_ad;
|
|
|
|
desc->ad_type->sat_ad = desc;
|
2000-07-03 01:16:18 +08:00
|
|
|
}
|
|
|
|
|
2002-01-27 07:14:51 +08:00
|
|
|
if( !*ad ) {
|
2001-10-22 21:23:05 +08:00
|
|
|
*ad = desc;
|
2002-01-27 07:14:51 +08:00
|
|
|
} else {
|
2001-10-22 21:23:05 +08:00
|
|
|
**ad = *desc;
|
2002-01-27 07:14:51 +08:00
|
|
|
}
|
2000-07-03 01:16:18 +08:00
|
|
|
|
|
|
|
return LDAP_SUCCESS;
|
|
|
|
}
|
2001-12-31 19:35:52 +08:00
|
|
|
|
|
|
|
int
|
|
|
|
an_find(
|
|
|
|
AttributeName *a,
|
|
|
|
struct berval *s
|
|
|
|
)
|
|
|
|
{
|
|
|
|
if( a == NULL ) return 0;
|
|
|
|
|
2002-01-03 13:38:26 +08:00
|
|
|
for ( ; a->an_name.bv_val; a++ ) {
|
2001-12-31 19:35:52 +08:00
|
|
|
if ( a->an_name.bv_len != s->bv_len) continue;
|
|
|
|
if ( strcasecmp( s->bv_val, a->an_name.bv_val ) == 0 ) {
|
|
|
|
return( 1 );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return( 0 );
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Convert a delimited string into a list of AttributeNames; Add on
|
|
|
|
* to an existing list if it was given.
|
|
|
|
*/
|
|
|
|
AttributeName *
|
2002-01-11 04:25:23 +08:00
|
|
|
str2anlist( AttributeName *an, char *in, const char *brkstr )
|
2001-12-31 19:35:52 +08:00
|
|
|
{
|
|
|
|
char *str;
|
|
|
|
char *s;
|
|
|
|
char *lasts;
|
2002-01-03 13:38:26 +08:00
|
|
|
int i, j;
|
2001-12-31 19:35:52 +08:00
|
|
|
const char *text;
|
2002-01-03 13:38:26 +08:00
|
|
|
AttributeName *anew;
|
2001-12-31 19:35:52 +08:00
|
|
|
|
2002-01-03 13:38:26 +08:00
|
|
|
/* find last element in list */
|
|
|
|
for (i = 0; an && an[i].an_name.bv_val; i++);
|
|
|
|
|
2001-12-31 19:35:52 +08:00
|
|
|
/* protect the input string from strtok */
|
|
|
|
str = ch_strdup( in );
|
|
|
|
|
2002-01-03 13:38:26 +08:00
|
|
|
/* Count words in string */
|
|
|
|
j=1;
|
|
|
|
for ( s = str; *s; s++ ) {
|
|
|
|
if ( strchr( brkstr, *s ) != NULL ) {
|
|
|
|
j++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
an = ch_realloc( an, ( i + j + 1 ) * sizeof( AttributeName ) );
|
|
|
|
anew = an + i;
|
2001-12-31 19:35:52 +08:00
|
|
|
for ( s = ldap_pvt_strtok( str, brkstr, &lasts );
|
|
|
|
s != NULL;
|
|
|
|
s = ldap_pvt_strtok( NULL, brkstr, &lasts ) )
|
|
|
|
{
|
|
|
|
anew->an_desc = NULL;
|
2002-01-10 17:54:14 +08:00
|
|
|
anew->an_oc = NULL;
|
2001-12-31 19:35:52 +08:00
|
|
|
ber_str2bv(s, 0, 1, &anew->an_name);
|
|
|
|
slap_bv2ad(&anew->an_name, &anew->an_desc, &text);
|
2002-01-10 17:54:14 +08:00
|
|
|
if ( !anew->an_desc ) {
|
|
|
|
anew->an_oc = oc_bvfind( &anew->an_name );
|
|
|
|
if ( !anew->an_oc ) {
|
|
|
|
free( an );
|
|
|
|
/* overwrites input string on error! */
|
2002-01-11 04:25:23 +08:00
|
|
|
strcpy( in, s );
|
2002-01-10 17:54:14 +08:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
}
|
2002-01-03 13:38:26 +08:00
|
|
|
anew++;
|
2001-12-31 19:35:52 +08:00
|
|
|
}
|
2002-01-03 13:38:26 +08:00
|
|
|
anew->an_name.bv_val = NULL;
|
2001-12-31 19:35:52 +08:00
|
|
|
|
|
|
|
free( str );
|
|
|
|
return( an );
|
|
|
|
}
|
2002-01-27 07:14:51 +08:00
|
|
|
|