openldap/servers/slapd/schema_prep.c

285 lines
7.7 KiB
C
Raw Normal View History

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"
2000-09-08 07:19:10 +08:00
#include "ldap_pvt_uc.h"
2000-05-25 09:49:21 +08:00
int schema_init_done = 0;
struct slap_internal_schema slap_schema;
#define objectClassIndexer NULL
#define objectClassFilter NULL
2000-05-25 09:49:21 +08:00
static int
objectClassMatch(
int *matchp,
2000-08-29 06:20:19 +08:00
slap_mask_t flags,
2000-05-25 09:49:21 +08:00
Syntax *syntax,
MatchingRule *mr,
struct berval *value,
void *assertedValue )
{
struct berval *a = (struct berval *) assertedValue;
2000-05-25 09:49:21 +08:00
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 */
2000-06-20 11:54:50 +08:00
return SLAPD_COMPARE_UNDEFINED;
}
if ( oc == NULL ) {
2000-06-20 11:54:50 +08:00
/* unrecognized stored value */
return SLAPD_COMPARE_UNDEFINED;
}
if( flags & SLAP_MR_MODIFY_MATCHING ) {
*matchp = ( asserted != oc );
} else {
*matchp = !is_object_subclass( asserted, oc );
}
#if 0
2001-01-16 03:17:29 +08:00
#ifdef NEW_LOGGING
2001-01-18 00:35:53 +08:00
LDAP_LOG(( "schema", LDAP_LEVEL_ENTRY,
"objectClassMatch(%s, %s) = %d\n",
value->bv_val, a->bv_val, *matchp ));
2001-01-16 03:17:29 +08:00
#else
Debug( LDAP_DEBUG_TRACE, "objectClassMatch(%s,%s) = %d\n",
value->bv_val, a->bv_val, *matchp );
2001-01-16 03:17:29 +08:00
#endif
#endif
return LDAP_SUCCESS;
}
#define structuralObjectClassIndexer NULL
#define structuralObjectClassFilter NULL
static int
structuralObjectClassMatch(
int *matchp,
2000-08-29 06:20:19 +08:00
slap_mask_t 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;
}
if ( oc == NULL ) {
/* unrecognized stored value */
return SLAPD_COMPARE_UNDEFINED;
}
*matchp = ( asserted != oc );
#if 0
2001-01-16 03:17:29 +08:00
#ifdef NEW_LOGGING
2001-01-18 00:35:53 +08:00
LDAP_LOG(( "schema", LDAP_LEVEL_ENTRY,
"structuralObjectClassMatch( %s, %s ) = %d\n",
value->bv_val, a->bv_val, *matchp ));
2001-01-16 03:17:29 +08:00
#else
Debug( LDAP_DEBUG_TRACE, "structuralObjectClassMatch(%s,%s) = %d\n",
value->bv_val, a->bv_val, *matchp );
2001-01-16 03:17:29 +08:00
#endif
#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[] = {
{ "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) },
{ "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;
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[] = {
{ "objectClass",
objectClassMatch, objectClassIndexer, objectClassFilter,
2000-05-25 09:49:21 +08:00
offsetof(struct slap_internal_schema, si_ad_objectClass) },
{ "structuralObjectClass",
structuralObjectClassMatch,
structuralObjectClassIndexer, structuralObjectClassFilter,
offsetof(struct slap_internal_schema, si_ad_structuralObjectClass) },
2000-05-25 09:49:21 +08:00
/* user entry operational attributes */
{ "creatorsName", NULL, NULL, NULL,
2000-05-25 09:49:21 +08:00
offsetof(struct slap_internal_schema, si_ad_creatorsName) },
{ "createTimestamp", NULL, NULL, NULL,
2000-05-25 09:49:21 +08:00
offsetof(struct slap_internal_schema, si_ad_createTimestamp) },
{ "modifiersName", NULL, NULL, NULL,
2000-05-25 09:49:21 +08:00
offsetof(struct slap_internal_schema, si_ad_modifiersName) },
{ "modifyTimestamp", NULL, NULL, NULL,
2000-05-25 09:49:21 +08:00
offsetof(struct slap_internal_schema, si_ad_modifyTimestamp) },
{ "subschemaSubentry", NULL, NULL, NULL,
2000-05-25 09:49:21 +08:00
offsetof(struct slap_internal_schema, si_ad_subschemaSubentry) },
/* root DSE attributes */
{ "namingContexts", NULL, NULL, NULL,
2000-05-25 09:49:21 +08:00
offsetof(struct slap_internal_schema, si_ad_namingContexts) },
{ "supportedControl", NULL, NULL, NULL,
2000-05-25 09:49:21 +08:00
offsetof(struct slap_internal_schema, si_ad_supportedControl) },
{ "supportedExtension", NULL, NULL, NULL,
2000-05-25 09:49:21 +08:00
offsetof(struct slap_internal_schema, si_ad_supportedExtension) },
{ "supportedLDAPVersion", NULL, NULL, NULL,
2000-05-25 09:49:21 +08:00
offsetof(struct slap_internal_schema, si_ad_supportedLDAPVersion) },
{ "supportedSASLMechanisms", NULL, NULL, NULL,
2000-05-25 09:49:21 +08:00
offsetof(struct slap_internal_schema, si_ad_supportedSASLMechanisms) },
/* subschema subentry attributes */
{ "attributeTypes", NULL, NULL, NULL,
2000-05-25 09:49:21 +08:00
offsetof(struct slap_internal_schema, si_ad_attributeTypes) },
{ "ldapSyntaxes", NULL, NULL, NULL,
2000-05-25 09:49:21 +08:00
offsetof(struct slap_internal_schema, si_ad_ldapSyntaxes) },
{ "matchingRules", NULL, NULL, NULL,
2000-05-25 09:49:21 +08:00
offsetof(struct slap_internal_schema, si_ad_matchingRules) },
{ "objectClasses", NULL, NULL, NULL,
2000-05-25 09:49:21 +08:00
offsetof(struct slap_internal_schema, si_ad_objectClasses) },
/* knowledge information */
{ "aliasedObjectName", NULL, NULL, NULL,
offsetof(struct slap_internal_schema, si_ad_aliasedObjectName) },
{ "ref", NULL, NULL, NULL,
2000-05-25 09:49:21 +08:00
offsetof(struct slap_internal_schema, si_ad_ref) },
/* access control internals */
{ "entry", NULL, NULL, NULL,
2000-05-25 09:49:21 +08:00
offsetof(struct slap_internal_schema, si_ad_entry) },
{ "children", NULL, NULL, NULL,
2000-05-25 09:49:21 +08:00
offsetof(struct slap_internal_schema, si_ad_children) },
#ifdef SLAPD_ACI_ENABLED
{ "OpenLDAPaci", NULL, NULL, NULL,
offsetof(struct slap_internal_schema, si_ad_aci) },
#endif
2000-05-25 09:49:21 +08:00
{ "userPassword", NULL, NULL, NULL,
2000-05-25 09:49:21 +08:00
offsetof(struct slap_internal_schema, si_ad_userPassword) },
{ "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
{ "krbName", NULL, NULL, NULL,
2000-05-25 09:49:21 +08:00
offsetof(struct slap_internal_schema, si_ad_krbName) },
#endif
{ NULL, NULL, NULL, NULL, 0 }
2000-05-25 09:49:21 +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;
}
}
slap_at_undefined.sat_syntax = syn_find( SLAPD_OCTETSTRING_SYNTAX );
if( slap_at_undefined.sat_syntax == NULL ) {
fprintf( stderr,
"No octetString syntax \"" SLAPD_OCTETSTRING_SYNTAX "\"\n" );
return LDAP_INVALID_SYNTAX;
}
slap_schema.si_at_undefined = &slap_at_undefined;
2000-05-25 09:49:21 +08:00
++schema_init_done;
return LDAP_SUCCESS;
}