}
/* ACI attribute */
- at = ldap_str2attributetype( aci_at.desc,
- &rc, &text, LDAP_SCHEMA_ALLOW_ALL );
- if ( !at ) {
- Debug( LDAP_DEBUG_ANY,
- "aci_init: AttributeType \"%s\" parse failed: %s %s\n",
- aci_at.name, ldap_scherr2str( rc ), text );
- return rc;
- }
-
- rc = at_add( at, 0, &sat, &text );
+ rc = register_at( aci_at.desc, aci_at.ad, 0 );
if ( rc != LDAP_SUCCESS ) {
- ldap_attributetype_free( at );
Debug( LDAP_DEBUG_ANY,
- "aci_init: AttributeType \"%s\" load failed: %s %s\n",
- aci_at.name, scherr2str( rc ), text );
+ "aci_init: at_register failed\n", 0, 0, 0 );
return rc;
}
- ldap_memfree( at );
-
- rc = slap_str2ad( aci_at.name,
- aci_at.ad, &text );
- if ( rc != LDAP_SUCCESS ) {
- Debug( LDAP_DEBUG_ANY,
- "aci_init: unable to find AttributeDescription "
- "\"%s\": %d (%s)\n",
- aci_at.name, rc, text );
- return 1;
- }
/* install flags */
- sat->sat_flags |= aci_at.flags;
+ (*aci_at.ad)->ad_type->sat_flags |= aci_at.flags;
return rc;
}
}
return 0;
}
+
+int
+register_at( char *def, AttributeDescription **ad, int dupok )
+{
+ LDAPAttributeType *at;
+ int code, freeit = 0;
+ const char *err;
+
+ at = ldap_str2attributetype( def, &code, &err, LDAP_SCHEMA_ALLOW_ALL );
+ if ( !at ) {
+ Debug( LDAP_DEBUG_ANY,
+ "register_at: AttributeType \"%s\": %s, %s\n",
+ def, ldap_scherr2str(code), err );
+ return code;
+ }
+
+ code = at_add( at, 0, NULL, &err );
+ if ( code ) {
+ if ( code == SLAP_SCHERR_ATTR_DUP && dupok ) {
+ freeit = 1;
+
+ } else {
+ ldap_attributetype_free( at );
+ Debug( LDAP_DEBUG_ANY,
+ "register_at: AttributeType \"%s\": %s, %s\n",
+ def, scherr2str(code), err );
+ return code;
+ }
+ }
+ code = slap_str2ad( at->at_names[0], ad, &err );
+ if ( freeit || code ) {
+ ldap_attributetype_free( at );
+ } else {
+ ldap_memfree( at );
+ }
+ if ( code ) {
+ Debug( LDAP_DEBUG_ANY, "register_at: AttributeType \"%s\": %s\n",
+ def, err, 0 );
+ }
+ return code;
+}
};
static struct {
- char *name;
char *desc;
AttributeDescription **ad;
} s_at[] = {
- { "olmBDBEntryCache", "( olmBDBAttributes:1 "
+ { "( olmBDBAttributes:1 "
"NAME ( 'olmBDBEntryCache' ) "
"DESC 'Number of items in Entry Cache' "
"SUP monitorCounter "
"USAGE directoryOperation )",
&ad_olmBDBEntryCache },
- { "olmBDBEntryInfo", "( olmBDBAttributes:2 "
+ { "( olmBDBAttributes:2 "
"NAME ( 'olmBDBEntryInfo' ) "
"DESC 'Number of items in EntryInfo Cache' "
"SUP monitorCounter "
"USAGE directoryOperation )",
&ad_olmBDBEntryInfo },
- { "olmBDBIDLCache", "( olmBDBAttributes:3 "
+ { "( olmBDBAttributes:3 "
"NAME ( 'olmBDBIDLCache' ) "
"DESC 'Number of items in IDL Cache' "
"SUP monitorCounter "
"USAGE directoryOperation )",
&ad_olmBDBIDLCache },
- { "olmDbDirectory", "( olmBDBAttributes:4 "
+ { "( olmBDBAttributes:4 "
"NAME ( 'olmDbDirectory' ) "
"DESC 'Path name of the directory "
"where the database environment resides' "
};
static struct {
- char *name;
char *desc;
ObjectClass **oc;
} s_oc[] = {
/* augments an existing object, so it must be AUXILIARY
* FIXME: derive from some ABSTRACT "monitoredEntity"? */
- { "olmBDBDatabase", "( olmBDBObjectClasses:1 "
+ { "( olmBDBObjectClasses:1 "
"NAME ( 'olmBDBDatabase' ) "
"SUP top AUXILIARY "
"MAY ( "
/* don't care too much about return code... */
/* remove attrs */
- for ( i = 0; s_at[ i ].name != NULL; i++ ) {
+ for ( i = 0; s_at[ i ].desc != NULL; i++ ) {
mod.sm_desc = *s_at[ i ].ad;
mod.sm_values = NULL;
rc = modify_delete_values( e, &mod, 1, &text,
bdb_monitor_initialize( void )
{
int i, code;
- const char *err;
BackendInfo *bi;
static int bdb_monitor_initialized = 0;
}
}
- 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 ) {
- Debug( LDAP_DEBUG_ANY,
- "bdb_monitor_initialize: "
- "AttributeType load failed: %s %s\n",
- ldap_scherr2str( code ), err, 0 );
- return LDAP_INVALID_SYNTAX;
- }
-
- code = at_add( at, 0, NULL, &err );
+ for ( i = 0; s_at[ i ].desc != NULL; i++ ) {
+ code = register_at( s_at[ i ].desc, s_at[ i ].ad, 1 );
if ( code != LDAP_SUCCESS ) {
Debug( LDAP_DEBUG_ANY,
- "bdb_monitor_initialize: "
- "AttributeType load failed: %s %s\n",
- scherr2str( code ), err, 0 );
- code = LDAP_INVALID_SYNTAX;
- goto done_at;
- }
-
- code = slap_str2ad( s_at[ i ].name,
- s_at[ i ].ad, &err );
- if ( code != LDAP_SUCCESS ) {
- Debug( LDAP_DEBUG_ANY,
- "bdb_monitor_initialize: "
- "unable to find AttributeDescription "
- "\"%s\": %d (%s)\n",
- s_at[ i ].name, code, err );
- code = LDAP_UNDEFINED_TYPE;
- goto done_at;
- }
-
-done_at:;
- if ( code ) {
- ldap_attributetype_free( at );
- return code;
+ "bdb_monitor_initialize: register_at failed\n",
+ 0, 0, 0 );
}
-
- ldap_memfree( at );
}
- for ( i = 0; s_oc[ i ].name != NULL; i++ ) {
- LDAPObjectClass *oc;
-
- oc = ldap_str2objectclass( s_oc[ i ].desc,
- &code, &err, LDAP_SCHEMA_ALLOW_ALL );
- if ( !oc ) {
- Debug( LDAP_DEBUG_ANY,
- "bdb_monitor_initialize: "
- "ObjectClass load failed: %s %s\n",
- ldap_scherr2str( code ), err, 0 );
- return LDAP_INVALID_SYNTAX;
- }
-
- code = oc_add( oc, 0, NULL, &err );
+ for ( i = 0; s_oc[ i ].desc != NULL; i++ ) {
+ code = register_oc( s_oc[ i ].desc, s_oc[ i ].oc, 1 );
if ( code != LDAP_SUCCESS ) {
Debug( LDAP_DEBUG_ANY,
- "bdb_monitor_initialize: "
- "ObjectClass load failed: %s %s\n",
- scherr2str( code ), err, 0 );
- code = LDAP_INVALID_SYNTAX;
- goto done_oc;
- }
-
- *s_oc[ i ].oc = oc_find( s_oc[ i ].name );
- if ( *s_oc[ i ].oc == NULL ) {
- code = LDAP_UNDEFINED_TYPE;
- Debug( LDAP_DEBUG_ANY,
- "bdb_monitor_initialize: "
- "unable to find objectClass \"%s\"\n",
- s_oc[ i ].name, 0, 0 );
- goto done_oc;
- }
-
-done_oc:;
- if ( code != LDAP_SUCCESS ) {
- ldap_objectclass_free( oc );
- return code;
+ "bdb_monitor_initialize: register_oc failed\n",
+ 0, 0, 0 );
}
-
- ldap_memfree( oc );
}
return 0;
int
init_config_attrs(ConfigTable *ct) {
- LDAPAttributeType *at;
int i, code;
- const char *err;
for (i=0; ct[i].name; i++ ) {
- int freeit = 0;
-
if ( !ct[i].attribute ) continue;
- at = ldap_str2attributetype( ct[i].attribute,
- &code, &err, LDAP_SCHEMA_ALLOW_ALL );
- if ( !at ) {
- fprintf( stderr, "init_config_attrs: AttributeType \"%s\": %s, %s\n",
- ct[i].attribute, ldap_scherr2str(code), err );
- return code;
- }
-
- code = at_add( at, 0, NULL, &err );
- if ( code ) {
- if ( code == SLAP_SCHERR_ATTR_DUP ) {
- freeit = 1;
-
- } else {
- ldap_attributetype_free( at );
- fprintf( stderr, "init_config_attrs: AttributeType \"%s\": %s, %s\n",
- ct[i].attribute, scherr2str(code), err );
- return code;
- }
- }
- code = slap_str2ad( at->at_names[0], &ct[i].ad, &err );
- if ( freeit || code ) {
- ldap_attributetype_free( at );
- } else {
- ldap_memfree( at );
- }
+ code = register_at( ct[i].attribute, &ct[i].ad, 1 );
if ( code ) {
- fprintf( stderr, "init_config_attrs: AttributeType \"%s\": %s\n",
- ct[i].attribute, err );
+ fprintf( stderr, "init_config_attrs: register_at failed\n" );
return code;
- } else {
+ }
#ifndef LDAP_DEVEL
- ct[i].ad->ad_type->sat_flags |= SLAP_AT_HIDE;
+ ct[i].ad->ad_type->sat_flags |= SLAP_AT_HIDE;
#endif
- }
}
return 0;
int
init_config_ocs( ConfigOCs *ocs ) {
- int i;
+ int i, code;
for (i=0;ocs[i].co_def;i++) {
- LDAPObjectClass *oc;
- int code;
- const char *err;
-
- oc = ldap_str2objectclass( ocs[i].co_def, &code, &err,
- LDAP_SCHEMA_ALLOW_ALL );
- if ( !oc ) {
- fprintf( stderr, "init_config_ocs: objectclass \"%s\": %s, %s\n",
- ocs[i].co_def, ldap_scherr2str(code), err );
- return code;
- }
- code = oc_add(oc,0,NULL,&err);
- if ( code && code != SLAP_SCHERR_CLASS_DUP ) {
- fprintf( stderr, "init_config_ocs: objectclass \"%s\": %s, %s\n",
- ocs[i].co_def, scherr2str(code), err );
- ldap_objectclass_free(oc);
+ code = register_oc( ocs[i].co_def, &ocs[i].co_oc, 1 );
+ if ( code ) {
+ fprintf( stderr, "init_config_ocs: register_oc failed\n" );
return code;
}
- ocs[i].co_oc = oc_find(oc->oc_names[0]);
- if ( code ) {
- ldap_objectclass_free(oc);
- } else {
- ldap_memfree(oc);
#ifndef LDAP_DEVEL
- ocs[i].co_oc->soc_flags |= SLAP_OC_HIDE;
+ ocs[i].co_oc->soc_flags |= SLAP_OC_HIDE;
#endif
- }
}
return 0;
}
}
return 0;
}
+
+int
+register_oc( char *def, ObjectClass **soc, int dupok )
+{
+ LDAPObjectClass *oc;
+ int code;
+ const char *err;
+
+ oc = ldap_str2objectclass( def, &code, &err, LDAP_SCHEMA_ALLOW_ALL );
+ if ( !oc ) {
+ Debug( LDAP_DEBUG_ANY,
+ "register_oc: objectclass \"%s\": %s, %s\n",
+ def, ldap_scherr2str(code), err );
+ return code;
+ }
+ code = oc_add(oc,0,NULL,&err);
+ if ( code && ( code != SLAP_SCHERR_CLASS_DUP || !dupok )) {
+ Debug( LDAP_DEBUG_ANY,
+ "register_oc: objectclass \"%s\": %s, %s\n",
+ def, scherr2str(code), err );
+ ldap_objectclass_free(oc);
+ return code;
+ }
+ *soc = oc_find(oc->oc_names[0]);
+ if ( code ) {
+ ldap_objectclass_free(oc);
+ } else {
+ ldap_memfree(oc);
+ }
+ return 0;
+}
LDAP_SLAPD_F (void) at_unparse LDAP_P((
BerVarray *bva, AttributeType *start, AttributeType *end, int system ));
+LDAP_SLAPD_F (int) register_at LDAP_P((
+ char *at,
+ AttributeDescription **ad,
+ int dupok ));
+
/*
* attr.c
*/
LDAP_SLAPD_F (void) oc_unparse LDAP_P((
BerVarray *bva, ObjectClass *start, ObjectClass *end, int system ));
+LDAP_SLAPD_F (int) register_oc LDAP_P((
+ char *desc,
+ ObjectClass **oc,
+ int dupok ));
+
/*
* oidm.c
*/