2000-05-25 09:49:21 +08:00
|
|
|
/* schema_init.c - init builtin schema */
|
|
|
|
/* $OpenLDAP$ */
|
|
|
|
/*
|
|
|
|
* Copyright 1998-2000 The OpenLDAP Foundation, All Rights Reserved.
|
|
|
|
* COPYING RESTRICTIONS APPLY, see COPYRIGHT file
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "portable.h"
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
|
|
|
#include <ac/ctype.h>
|
|
|
|
#include <ac/string.h>
|
|
|
|
#include <ac/socket.h>
|
|
|
|
|
|
|
|
#include "slap.h"
|
|
|
|
#include "ldap_pvt.h"
|
|
|
|
|
|
|
|
int schema_init_done = 0;
|
|
|
|
|
|
|
|
struct slap_internal_schema slap_schema;
|
|
|
|
|
2000-06-20 00:14:12 +08:00
|
|
|
#define objectClassIndexer NULL
|
|
|
|
#define objectClassFilter NULL
|
|
|
|
|
2000-05-25 09:49:21 +08:00
|
|
|
static int
|
|
|
|
objectClassMatch(
|
2000-06-20 00:14:12 +08:00
|
|
|
int *matchp,
|
2000-06-26 13:13:41 +08:00
|
|
|
unsigned flags,
|
2000-05-25 09:49:21 +08:00
|
|
|
Syntax *syntax,
|
|
|
|
MatchingRule *mr,
|
|
|
|
struct berval *value,
|
|
|
|
void *assertedValue )
|
|
|
|
{
|
2000-06-20 00:14:12 +08:00
|
|
|
struct berval *a = (struct berval *) assertedValue;
|
2000-05-25 09:49:21 +08:00
|
|
|
ObjectClass *oc = oc_find( value->bv_val );
|
2000-06-20 00:14:12 +08:00
|
|
|
ObjectClass *asserted = oc_find( a->bv_val );
|
|
|
|
|
2000-06-20 04:53:56 +08:00
|
|
|
if( asserted == NULL ) {
|
2000-06-26 13:13:41 +08:00
|
|
|
if( OID_LEADCHAR( *a->bv_val ) ) {
|
2000-06-20 04:53:56 +08:00
|
|
|
/* OID form, return FALSE */
|
|
|
|
*matchp = 1;
|
|
|
|
return LDAP_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* desc form, return undefined */
|
2000-06-20 11:54:50 +08:00
|
|
|
return SLAPD_COMPARE_UNDEFINED;
|
2000-06-20 04:53:56 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if ( oc == NULL ) {
|
2000-06-20 11:54:50 +08:00
|
|
|
/* unrecognized stored value */
|
|
|
|
return SLAPD_COMPARE_UNDEFINED;
|
2000-06-20 00:14:12 +08:00
|
|
|
}
|
|
|
|
|
2000-06-26 13:13:41 +08:00
|
|
|
if( flags & SLAP_MR_MODIFY_MATCHING ) {
|
|
|
|
*matchp = ( asserted != oc );
|
|
|
|
} else {
|
|
|
|
*matchp = !is_object_subclass( asserted, oc );
|
|
|
|
}
|
|
|
|
|
2000-06-20 00:14:12 +08:00
|
|
|
#if 0
|
2000-06-26 13:13:41 +08:00
|
|
|
Debug( LDAP_DEBUG_TRACE, "objectClassMatch(%s,%s) = %d\n",
|
|
|
|
value->bv_val, a->bv_val, *matchp );
|
2000-06-20 00:14:12 +08:00
|
|
|
#endif
|
|
|
|
|
2000-06-26 13:13:41 +08:00
|
|
|
return LDAP_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
#define structuralObjectClassIndexer NULL
|
|
|
|
#define structuralObjectClassFilter NULL
|
|
|
|
|
|
|
|
static int
|
|
|
|
structuralObjectClassMatch(
|
|
|
|
int *matchp,
|
|
|
|
unsigned flags,
|
|
|
|
Syntax *syntax,
|
|
|
|
MatchingRule *mr,
|
|
|
|
struct berval *value,
|
|
|
|
void *assertedValue )
|
|
|
|
{
|
|
|
|
struct berval *a = (struct berval *) assertedValue;
|
|
|
|
ObjectClass *oc = oc_find( value->bv_val );
|
|
|
|
ObjectClass *asserted = oc_find( a->bv_val );
|
|
|
|
|
|
|
|
if( asserted == NULL ) {
|
|
|
|
if( OID_LEADCHAR( *a->bv_val ) ) {
|
|
|
|
/* OID form, return FALSE */
|
|
|
|
*matchp = 1;
|
|
|
|
return LDAP_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* desc form, return undefined */
|
|
|
|
return SLAPD_COMPARE_UNDEFINED;
|
|
|
|
}
|
2000-06-20 00:14:12 +08:00
|
|
|
|
2000-06-26 13:13:41 +08:00
|
|
|
if ( oc == NULL ) {
|
|
|
|
/* unrecognized stored value */
|
|
|
|
return SLAPD_COMPARE_UNDEFINED;
|
|
|
|
}
|
|
|
|
|
|
|
|
*matchp = ( asserted != oc );
|
|
|
|
|
|
|
|
#if 0
|
|
|
|
Debug( LDAP_DEBUG_TRACE, "structuralObjectClassMatch(%s,%s) = %d\n",
|
|
|
|
value->bv_val, a->bv_val, *matchp );
|
|
|
|
#endif
|
2000-05-25 09:49:21 +08:00
|
|
|
|
|
|
|
return LDAP_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
struct slap_schema_oc_map {
|
|
|
|
char *ssom_name;
|
|
|
|
size_t ssom_offset;
|
|
|
|
} oc_map[] = {
|
2000-05-28 03:33:08 +08:00
|
|
|
{ "top", offsetof(struct slap_internal_schema, si_oc_top) },
|
2000-06-01 02:46:13 +08:00
|
|
|
{ "extensibleObject", offsetof(struct slap_internal_schema, si_oc_extensibleObject) },
|
2000-05-25 09:49:21 +08:00
|
|
|
{ "alias", offsetof(struct slap_internal_schema, si_oc_alias) },
|
|
|
|
{ "referral", offsetof(struct slap_internal_schema, si_oc_referral) },
|
2000-05-28 03:33:08 +08:00
|
|
|
{ "LDAProotDSE", offsetof(struct slap_internal_schema, si_oc_rootdse) },
|
|
|
|
{ "LDAPsubentry", offsetof(struct slap_internal_schema, si_oc_subentry) },
|
|
|
|
{ "subschema", offsetof(struct slap_internal_schema, si_oc_subschema) },
|
2000-05-25 09:49:21 +08:00
|
|
|
{ NULL, 0 }
|
|
|
|
};
|
|
|
|
|
|
|
|
struct slap_schema_ad_map {
|
|
|
|
char *ssam_name;
|
|
|
|
slap_mr_match_func *ssam_match;
|
2000-06-20 00:14:12 +08:00
|
|
|
slap_mr_indexer_func *ssam_indexer;
|
|
|
|
slap_mr_filter_func *ssam_filter;
|
2000-05-25 09:49:21 +08:00
|
|
|
size_t ssam_offset;
|
|
|
|
} ad_map[] = {
|
2000-06-20 00:14:12 +08:00
|
|
|
{ "objectClass",
|
|
|
|
objectClassMatch, objectClassIndexer, objectClassFilter,
|
2000-05-25 09:49:21 +08:00
|
|
|
offsetof(struct slap_internal_schema, si_ad_objectClass) },
|
2000-06-26 13:13:41 +08:00
|
|
|
{ "structuralObjectClass",
|
|
|
|
structuralObjectClassMatch,
|
|
|
|
structuralObjectClassIndexer, structuralObjectClassFilter,
|
|
|
|
offsetof(struct slap_internal_schema, si_ad_structuralObjectClass) },
|
2000-05-25 09:49:21 +08:00
|
|
|
|
2000-05-28 03:33:08 +08:00
|
|
|
/* user entry operational attributes */
|
2000-06-20 00:14:12 +08:00
|
|
|
{ "creatorsName", NULL, NULL, NULL,
|
2000-05-25 09:49:21 +08:00
|
|
|
offsetof(struct slap_internal_schema, si_ad_creatorsName) },
|
2000-06-20 00:14:12 +08:00
|
|
|
{ "createTimestamp", NULL, NULL, NULL,
|
2000-05-25 09:49:21 +08:00
|
|
|
offsetof(struct slap_internal_schema, si_ad_createTimestamp) },
|
2000-06-20 00:14:12 +08:00
|
|
|
{ "modifiersName", NULL, NULL, NULL,
|
2000-05-25 09:49:21 +08:00
|
|
|
offsetof(struct slap_internal_schema, si_ad_modifiersName) },
|
2000-06-20 00:14:12 +08:00
|
|
|
{ "modifyTimestamp", NULL, NULL, NULL,
|
2000-05-25 09:49:21 +08:00
|
|
|
offsetof(struct slap_internal_schema, si_ad_modifyTimestamp) },
|
2000-06-20 00:14:12 +08:00
|
|
|
{ "subschemaSubentry", NULL, NULL, NULL,
|
2000-05-25 09:49:21 +08:00
|
|
|
offsetof(struct slap_internal_schema, si_ad_subschemaSubentry) },
|
|
|
|
|
2000-05-28 03:33:08 +08:00
|
|
|
/* root DSE attributes */
|
2000-06-20 00:14:12 +08:00
|
|
|
{ "namingContexts", NULL, NULL, NULL,
|
2000-05-25 09:49:21 +08:00
|
|
|
offsetof(struct slap_internal_schema, si_ad_namingContexts) },
|
2000-06-20 00:14:12 +08:00
|
|
|
{ "supportedControl", NULL, NULL, NULL,
|
2000-05-25 09:49:21 +08:00
|
|
|
offsetof(struct slap_internal_schema, si_ad_supportedControl) },
|
2000-06-20 00:14:12 +08:00
|
|
|
{ "supportedExtension", NULL, NULL, NULL,
|
2000-05-25 09:49:21 +08:00
|
|
|
offsetof(struct slap_internal_schema, si_ad_supportedExtension) },
|
2000-06-20 00:14:12 +08:00
|
|
|
{ "supportedLDAPVersion", NULL, NULL, NULL,
|
2000-05-25 09:49:21 +08:00
|
|
|
offsetof(struct slap_internal_schema, si_ad_supportedLDAPVersion) },
|
2000-06-20 00:14:12 +08:00
|
|
|
{ "supportedSASLMechanisms", NULL, NULL, NULL,
|
2000-05-25 09:49:21 +08:00
|
|
|
offsetof(struct slap_internal_schema, si_ad_supportedSASLMechanisms) },
|
|
|
|
|
2000-05-28 03:33:08 +08:00
|
|
|
/* subschema subentry attributes */
|
2000-06-20 00:14:12 +08:00
|
|
|
{ "attributeTypes", NULL, NULL, NULL,
|
2000-05-25 09:49:21 +08:00
|
|
|
offsetof(struct slap_internal_schema, si_ad_attributeTypes) },
|
2000-06-20 00:14:12 +08:00
|
|
|
{ "ldapSyntaxes", NULL, NULL, NULL,
|
2000-05-25 09:49:21 +08:00
|
|
|
offsetof(struct slap_internal_schema, si_ad_ldapSyntaxes) },
|
2000-06-20 00:14:12 +08:00
|
|
|
{ "matchingRules", NULL, NULL, NULL,
|
2000-05-25 09:49:21 +08:00
|
|
|
offsetof(struct slap_internal_schema, si_ad_matchingRules) },
|
2000-06-20 00:14:12 +08:00
|
|
|
{ "objectClasses", NULL, NULL, NULL,
|
2000-05-25 09:49:21 +08:00
|
|
|
offsetof(struct slap_internal_schema, si_ad_objectClasses) },
|
|
|
|
|
2000-05-28 03:33:08 +08:00
|
|
|
/* knowledge information */
|
2000-06-20 00:14:12 +08:00
|
|
|
{ "aliasedObjectName", NULL, NULL, NULL,
|
2000-05-28 03:33:08 +08:00
|
|
|
offsetof(struct slap_internal_schema, si_ad_aliasedObjectName) },
|
2000-06-20 00:14:12 +08:00
|
|
|
{ "ref", NULL, NULL, NULL,
|
2000-05-25 09:49:21 +08:00
|
|
|
offsetof(struct slap_internal_schema, si_ad_ref) },
|
|
|
|
|
2000-05-29 02:58:09 +08:00
|
|
|
/* access control internals */
|
2000-06-20 00:14:12 +08:00
|
|
|
{ "entry", NULL, NULL, NULL,
|
2000-05-25 09:49:21 +08:00
|
|
|
offsetof(struct slap_internal_schema, si_ad_entry) },
|
2000-06-20 00:14:12 +08:00
|
|
|
{ "children", NULL, NULL, NULL,
|
2000-05-25 09:49:21 +08:00
|
|
|
offsetof(struct slap_internal_schema, si_ad_children) },
|
2000-05-31 05:34:55 +08:00
|
|
|
#ifdef SLAPD_ACI_ENABLED
|
2000-06-20 00:14:12 +08:00
|
|
|
{ "OpenLDAPaci", NULL, NULL, NULL,
|
2000-05-31 05:34:55 +08:00
|
|
|
offsetof(struct slap_internal_schema, si_ad_aci) },
|
|
|
|
#endif
|
2000-05-25 09:49:21 +08:00
|
|
|
|
2000-06-20 00:14:12 +08:00
|
|
|
{ "userPassword", NULL, NULL, NULL,
|
2000-05-25 09:49:21 +08:00
|
|
|
offsetof(struct slap_internal_schema, si_ad_userPassword) },
|
2000-06-20 00:14:12 +08:00
|
|
|
{ "authPassword", NULL, NULL, NULL,
|
2000-05-25 09:49:21 +08:00
|
|
|
offsetof(struct slap_internal_schema, si_ad_authPassword) },
|
|
|
|
#ifdef LDAP_API_FEATURE_X_OPENLDAP_V2_KBIND
|
2000-06-20 00:14:12 +08:00
|
|
|
{ "krbName", NULL, NULL, NULL,
|
2000-05-25 09:49:21 +08:00
|
|
|
offsetof(struct slap_internal_schema, si_ad_krbName) },
|
|
|
|
#endif
|
|
|
|
|
2000-06-20 00:14:12 +08:00
|
|
|
{ NULL, NULL, NULL, NULL, 0 }
|
2000-05-25 09:49:21 +08:00
|
|
|
};
|
|
|
|
|
2000-07-03 01:16:18 +08:00
|
|
|
static AttributeType slap_at_undefined = {
|
|
|
|
"UNDEFINED", /* cname */
|
|
|
|
{ "1.1.1", NULL, NULL, 1, NULL,
|
|
|
|
NULL, NULL, NULL, NULL,
|
|
|
|
0, 0, 0, 1, 3 },
|
|
|
|
NULL, /* sup */
|
|
|
|
NULL, /* subtypes */
|
|
|
|
NULL, NULL, NULL, NULL, /* matching rules */
|
|
|
|
NULL, /* syntax (this may need to be defined) */
|
|
|
|
NULL /* next */
|
|
|
|
};
|
2000-05-25 09:49:21 +08:00
|
|
|
|
|
|
|
int
|
|
|
|
schema_prep( void )
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
/* we should only be called once after schema_init() was called */
|
|
|
|
assert( schema_init_done == 1 );
|
|
|
|
|
|
|
|
for( i=0; oc_map[i].ssom_name; i++ ) {
|
|
|
|
ObjectClass ** ocp = (ObjectClass **)
|
|
|
|
&(((char *) &slap_schema)[oc_map[i].ssom_offset]);
|
|
|
|
|
|
|
|
*ocp = oc_find( oc_map[i].ssom_name );
|
|
|
|
|
|
|
|
if( *ocp == NULL ) {
|
|
|
|
fprintf( stderr,
|
|
|
|
"No objectClass \"%s\" defined in schema\n",
|
|
|
|
oc_map[i].ssom_name );
|
|
|
|
return LDAP_OBJECT_CLASS_VIOLATION;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for( i=0; ad_map[i].ssam_name; i++ ) {
|
|
|
|
int rc;
|
|
|
|
const char *text;
|
|
|
|
|
|
|
|
AttributeDescription ** adp = (AttributeDescription **)
|
|
|
|
&(((char *) &slap_schema)[ad_map[i].ssam_offset]);
|
|
|
|
|
|
|
|
*adp = NULL;
|
|
|
|
|
|
|
|
rc = slap_str2ad( ad_map[i].ssam_name, adp, &text );
|
|
|
|
|
|
|
|
if( rc != LDAP_SUCCESS ) {
|
|
|
|
fprintf( stderr,
|
|
|
|
"No attribute \"%s\" defined in schema\n",
|
|
|
|
ad_map[i].ssam_name );
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( ad_map[i].ssam_match ) {
|
|
|
|
/* install custom matching routine */
|
|
|
|
(*adp)->ad_type->sat_equality->smr_match = ad_map[i].ssam_match;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-07-03 01:16:18 +08:00
|
|
|
slap_schema.si_at_undefined = &slap_at_undefined;
|
|
|
|
|
2000-05-25 09:49:21 +08:00
|
|
|
++schema_init_done;
|
|
|
|
return LDAP_SUCCESS;
|
|
|
|
}
|