Use register_at / register_oc

This commit is contained in:
Howard Chu 2006-09-13 13:26:56 +00:00
parent ef271979a8
commit e04275ca04
7 changed files with 40 additions and 187 deletions

View file

@ -894,11 +894,12 @@ at_schema_info( Entry *e )
}
int
register_at( char *def, AttributeDescription **ad, int dupok )
register_at( char *def, AttributeDescription **rad, int dupok )
{
LDAPAttributeType *at;
int code, freeit = 0;
const char *err;
AttributeDescription *ad = NULL;
at = ldap_str2attributetype( def, &code, &err, LDAP_SCHEMA_ALLOW_ALL );
if ( !at ) {
@ -921,7 +922,7 @@ register_at( char *def, AttributeDescription **ad, int dupok )
return code;
}
}
code = slap_str2ad( at->at_names[0], ad, &err );
code = slap_str2ad( at->at_names[0], &ad, &err );
if ( freeit || code ) {
ldap_attributetype_free( at );
} else {
@ -931,5 +932,6 @@ register_at( char *def, AttributeDescription **ad, int dupok )
Debug( LDAP_DEBUG_ANY, "register_at: AttributeType \"%s\": %s\n",
def, err, 0 );
}
if ( rad ) *rad = ad;
return code;
}

View file

@ -778,7 +778,8 @@ register_oc( char *def, ObjectClass **soc, int dupok )
ldap_objectclass_free(oc);
return code;
}
*soc = oc_find(oc->oc_names[0]);
if ( soc )
*soc = oc_find(oc->oc_names[0]);
if ( code ) {
ldap_objectclass_free(oc);
} else {

View file

@ -1571,59 +1571,24 @@ int accesslog_initialize()
/* log schema integration */
for ( i=0; lattrs[i].at; i++ ) {
LDAPAttributeType *lat;
AttributeType *at;
int code;
const char *err;
lat = ldap_str2attributetype( lattrs[i].at, &code, &err,
LDAP_SCHEMA_ALLOW_ALL );
if ( !lat ) {
Debug( LDAP_DEBUG_ANY, "accesslog_init: "
"ldap_str2attributetype failed on %d: %s, %s\n",
i, ldap_scherr2str(code), err );
return -1;
}
code = at_add( lat, 0, &at, &err );
ldap_memfree( lat );
code = register_at( lattrs[i].at, lattrs[i].ad, 0 );
if ( code ) {
Debug( LDAP_DEBUG_ANY, "log_back_initialize: "
"at_add failed on %d: %s\n",
i, scherr2str(code), 0 );
return -1;
}
if ( slap_bv2ad( &at->sat_cname, lattrs[i].ad, &err )) {
Debug( LDAP_DEBUG_ANY, "accesslog_init: "
"slap_bv2ad failed on %d: %s\n",
i, err, 0 );
Debug( LDAP_DEBUG_ANY,
"accesslog_init: register_at failed\n", 0, 0, 0 );
return -1;
}
}
for ( i=0; locs[i].ot; i++ ) {
LDAPObjectClass *loc;
ObjectClass *oc;
int code;
const char *err;
loc = ldap_str2objectclass( locs[i].ot, &code, &err,
LDAP_SCHEMA_ALLOW_ALL );
if ( !loc ) {
Debug( LDAP_DEBUG_ANY, "accesslog_init: "
"ldap_str2objectclass failed on %d: %s, %s\n",
i, ldap_scherr2str(code), err );
return -1;
}
code = oc_add( loc, 0, &oc, &err );
ldap_memfree( loc );
code = register_oc( locs[i].ot, locs[i].oc, 0 );
if ( code ) {
Debug( LDAP_DEBUG_ANY, "accesslog_init: "
"oc_add failed on %d: %s\n",
i, scherr2str(code), 0 );
Debug( LDAP_DEBUG_ANY,
"accesslog_init: register_oc failed\n", 0, 0, 0 );
return -1;
}
if ( locs[i].oc )
*locs[i].oc = oc;
}
return overlay_register(&accesslog);

View file

@ -1844,11 +1844,10 @@ dds_initialize()
if ( !do_not_load_schema ) {
static struct {
char *name;
char *desc;
AttributeDescription **ad;
} s_at[] = {
{ "entryExpireTimestamp", "( 1.3.6.1.4.1.4203.666.1.57 "
{ "( 1.3.6.1.4.1.4203.666.1.57 "
"NAME ( 'entryExpireTimestamp' ) "
"DESC 'RFC2589 OpenLDAP extension: expire time of a dynamic object, "
"computed as now + entryTtl' "
@ -1862,35 +1861,13 @@ dds_initialize()
{ NULL }
};
for ( i = 0; s_at[ i ].name != NULL; i++ ) {
LDAPAttributeType *at;
at = ldap_str2attributetype( s_at[ i ].desc,
&code, &err, LDAP_SCHEMA_ALLOW_ALL );
if ( !at ) {
fprintf( stderr, "dds_initialize: "
"AttributeType load failed: %s %s\n",
ldap_scherr2str( code ), err );
for ( i = 0; s_at[ i ].desc != NULL; i++ ) {
code = register_at( s_at[ i ].desc, s_at[ i ].ad, 0 );
if ( code ) {
Debug( LDAP_DEBUG_ANY,
"dds_initialize: register_at failed\n", 0, 0, 0 );
return code;
}
code = at_add( at, 0, NULL, &err );
ldap_memfree( at );
if ( code != LDAP_SUCCESS ) {
fprintf( stderr, "dds_initialize: "
"AttributeType load failed: %s %s\n",
scherr2str( code ), err );
return code;
}
code = slap_str2ad( s_at[ i ].name, s_at[ i ].ad, &err );
if ( code != LDAP_SUCCESS ) {
fprintf( stderr, "dds_initialize: "
"unable to find AttributeDescription "
"\"%s\": %d (%s)\n",
s_at[ i ].name, code, err );
return 1;
}
}
}

View file

@ -63,12 +63,11 @@ struct berval lastmodType[] = {
};
static struct m_s {
char *name;
char *schema;
slap_mask_t flags;
int offset;
} moc[] = {
{ "lastmod", "( 1.3.6.1.4.1.4203.666.3.13"
{ "( 1.3.6.1.4.1.4203.666.3.13"
"NAME 'lastmod' "
"DESC 'OpenLDAP per-database last modification monitoring' "
"STRUCTURAL "
@ -83,7 +82,7 @@ static struct m_s {
offsetof( struct lastmod_schema_t, lms_oc_lastmod ) },
{ NULL }
}, mat[] = {
{ "lastmodDN", "( 1.3.6.1.4.1.4203.666.1.28"
{ "( 1.3.6.1.4.1.4203.666.1.28"
"NAME 'lastmodDN' "
"DESC 'DN of last modification' "
"EQUALITY distinguishedNameMatch "
@ -91,7 +90,7 @@ static struct m_s {
"NO-USER-MODIFICATION "
"USAGE directoryOperation )", SLAP_AT_HIDE,
offsetof( struct lastmod_schema_t, lms_ad_lastmodDN ) },
{ "lastmodType", "( 1.3.6.1.4.1.4203.666.1.29"
{ "( 1.3.6.1.4.1.4203.666.1.29"
"NAME 'lastmodType' "
"DESC 'Type of last modification' "
"SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 "
@ -100,7 +99,7 @@ static struct m_s {
"NO-USER-MODIFICATION "
"USAGE directoryOperation )", SLAP_AT_HIDE,
offsetof( struct lastmod_schema_t, lms_ad_lastmodType ) },
{ "lastmodEnabled", "( 1.3.6.1.4.1.4203.666.1.30"
{ "( 1.3.6.1.4.1.4203.666.1.30"
"NAME 'lastmodEnabled' "
"DESC 'Lastmod overlay state' "
"SYNTAX 1.3.6.1.4.1.1466.115.121.1.7 "
@ -748,96 +747,33 @@ lastmod_db_init(
const char *text;
/* schema integration */
for ( i = 0; mat[i].name; i++ ) {
LDAPAttributeType *at;
for ( i = 0; mat[i].schema; i++ ) {
int code;
const char *err;
AttributeDescription **ad;
at = ldap_str2attributetype( mat[i].schema, &code,
&err, LDAP_SCHEMA_ALLOW_ALL );
if ( !at ) {
Debug( LDAP_DEBUG_ANY, "lastmod_init: "
"in AttributeType '%s' %s before %s\n",
mat[i].name, ldap_scherr2str(code), err );
return -1;
}
if ( at->at_oid == NULL ) {
Debug( LDAP_DEBUG_ANY, "lastmod_init: "
"null OID for attributeType '%s'\n",
mat[i].name, 0, 0 );
ldap_attributetype_free( at );
return -1;
}
code = at_add(at, 0, NULL, &err);
if ( code ) {
Debug( LDAP_DEBUG_ANY, "lastmod_init: "
"%s in attributeType '%s'\n",
scherr2str(code), mat[i].name, 0 );
ldap_attributetype_free( at );
return -1;
}
ldap_memfree(at);
ad = ((AttributeDescription **)&(((char *)&lastmod_schema)[mat[i].offset]));
AttributeDescription **ad =
((AttributeDescription **)&(((char *)&lastmod_schema)[mat[i].offset]));
ad[0] = NULL;
if ( slap_str2ad( mat[i].name, ad, &text ) ) {
code = register_at( mat[i].schema, ad, 0 );
if ( code ) {
Debug( LDAP_DEBUG_ANY,
"lastmod_init: %s\n", text, 0, 0 );
"lastmod_init: register_at failed\n", 0, 0, 0 );
return -1;
}
(*ad)->ad_type->sat_flags |= mat[i].flags;
}
for ( i = 0; moc[i].name; i++ ) {
LDAPObjectClass *oc;
for ( i = 0; moc[i].schema; i++ ) {
int code;
const char *err;
ObjectClass *Oc;
ObjectClass **Oc =
((ObjectClass **)&(((char *)&lastmod_schema)[moc[i].offset]));
oc = ldap_str2objectclass(moc[i].schema, &code, &err,
LDAP_SCHEMA_ALLOW_ALL );
if ( !oc ) {
Debug( LDAP_DEBUG_ANY,
"unable to parse lastmod objectClass '%s': "
"%s before %s\n" , moc[i].name,
ldap_scherr2str(code), err );
return -1;
}
if ( oc->oc_oid == NULL ) {
Debug( LDAP_DEBUG_ANY,
"objectClass '%s' has no OID\n" ,
moc[i].name, 0, 0 );
ldap_objectclass_free( oc );
return -1;
}
code = oc_add(oc, 0, NULL, &err);
code = register_oc( moc[i].schema, Oc, 0 );
if ( code ) {
Debug( LDAP_DEBUG_ANY,
"objectClass '%s': %s \"%s\"\n" ,
moc[i].name, scherr2str(code), err );
ldap_objectclass_free( oc );
"lastmod_init: register_oc failed\n", 0, 0, 0 );
return -1;
}
ldap_memfree(oc);
Oc = oc_find( moc[i].name );
if ( Oc == NULL ) {
Debug( LDAP_DEBUG_ANY, "lastmod_init: "
"unable to find objectClass %s "
"(just added)\n", moc[i].name, 0, 0 );
return -1;
}
Oc->soc_flags |= moc[i].flags;
((ObjectClass **)&(((char *)&lastmod_schema)[moc[i].offset]))[0] = Oc;
(*Oc)->soc_flags |= moc[i].flags;
}
}

View file

@ -2330,31 +2330,16 @@ static char *obsolete_names[] = {
int pcache_initialize()
{
LDAPAttributeType *at;
int code;
const char *err;
struct berval debugbv = BER_BVC("pcache");
if (( code = slap_loglevel_get( &debugbv, &pcache_debug )))
return code;
at = ldap_str2attributetype( queryid_schema, &code, &err,
LDAP_SCHEMA_ALLOW_ALL );
if ( !at ) {
Debug( LDAP_DEBUG_ANY,
"pcache_initialize: ldap_str2attributetype failed %s %s\n",
ldap_scherr2str(code), err, 0 );
return code;
}
code = at_add( at, 0, NULL, &err );
if ( !code ) {
slap_str2ad( at->at_names[0], &ad_queryid, &err );
}
ldap_memfree( at );
code = register_at( queryid_schema, &ad_queryid, 0 );
if ( code ) {
Debug( LDAP_DEBUG_ANY,
"pcache_initialize: at_add failed %s %s\n",
scherr2str(code), err, 0 );
"pcache_initialize: register_at failed\n", 0, 0, 0 );
return code;
}

View file

@ -2157,26 +2157,13 @@ static slap_overinst ppolicy;
int ppolicy_initialize()
{
LDAPAttributeType *at;
const char *err;
int i, code;
for (i=0; pwd_OpSchema[i].def; i++) {
at = ldap_str2attributetype( pwd_OpSchema[i].def, &code, &err,
LDAP_SCHEMA_ALLOW_ALL );
if ( !at ) {
fprintf( stderr, "AttributeType Load failed %s %s\n",
ldap_scherr2str(code), err );
return code;
}
code = at_add( at, 0, NULL, &err );
if ( !code ) {
slap_str2ad( at->at_names[0], pwd_OpSchema[i].ad, &err );
}
ldap_memfree( at );
code = register_at( pwd_OpSchema[i].def, pwd_OpSchema[i].ad, 0 );
if ( code ) {
fprintf( stderr, "AttributeType Load failed %s %s\n",
scherr2str(code), err );
Debug( LDAP_DEBUG_ANY,
"ppolicy_initialize: register_at failed\n", 0, 0, 0 );
return code;
}
/* Allow Manager to set these as needed */