]> git.sur5r.net Git - openldap/commitdiff
Add register_at / register_oc helpers.
authorHoward Chu <hyc@openldap.org>
Wed, 13 Sep 2006 12:48:45 +0000 (12:48 +0000)
committerHoward Chu <hyc@openldap.org>
Wed, 13 Sep 2006 12:48:45 +0000 (12:48 +0000)
servers/slapd/aci.c
servers/slapd/at.c
servers/slapd/back-bdb/monitor.c
servers/slapd/config.c
servers/slapd/oc.c
servers/slapd/proto-slap.h

index 28b99388ea2381f791e423411a116c095f774b8f..75642b6fd404bfc21b60bc3015b8589b9d78cc87 100644 (file)
@@ -702,37 +702,15 @@ aci_init( void )
        }
 
        /* 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;
 }
index 9453cabf02383cb3fb9acc1738a5ec89c69972b8..813f52226e03a8bb16f51389707dcd76eaae34f5 100644 (file)
@@ -892,3 +892,44 @@ at_schema_info( Entry *e )
        }
        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;
+}
index fac8ce307bf0e458fa52efdb54db739b4f3f9705..7607618f615ef4b3e40eb9695a41908ed296966f 100644 (file)
@@ -57,11 +57,10 @@ static struct {
 };
 
 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 "
@@ -69,7 +68,7 @@ static struct {
                "USAGE directoryOperation )",
                &ad_olmBDBEntryCache },
 
-       { "olmBDBEntryInfo", "( olmBDBAttributes:2 "
+       { "( olmBDBAttributes:2 "
                "NAME ( 'olmBDBEntryInfo' ) "
                "DESC 'Number of items in EntryInfo Cache' "
                "SUP monitorCounter "
@@ -77,7 +76,7 @@ static struct {
                "USAGE directoryOperation )",
                &ad_olmBDBEntryInfo },
 
-       { "olmBDBIDLCache", "( olmBDBAttributes:3 "
+       { "( olmBDBAttributes:3 "
                "NAME ( 'olmBDBIDLCache' ) "
                "DESC 'Number of items in IDL Cache' "
                "SUP monitorCounter "
@@ -85,7 +84,7 @@ static struct {
                "USAGE directoryOperation )",
                &ad_olmBDBIDLCache },
 
-       { "olmDbDirectory", "( olmBDBAttributes:4 "
+       { "( olmBDBAttributes:4 "
                "NAME ( 'olmDbDirectory' ) "
                "DESC 'Path name of the directory "
                        "where the database environment resides' "
@@ -98,13 +97,12 @@ static struct {
 };
 
 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 ( "
@@ -187,7 +185,7 @@ bdb_monitor_free(
        /* 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,
@@ -205,7 +203,6 @@ int
 bdb_monitor_initialize( void )
 {
        int             i, code;
-       const char      *err;
        BackendInfo *bi;
 
        static int      bdb_monitor_initialized = 0;
@@ -236,90 +233,22 @@ bdb_monitor_initialize( void )
                }
        }
 
-       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;
index 70a5a6375fd80a2ec5e1f84b364f30289ff7b293..dbc62367e15e59e385484fc19affbd80d19ddadd 100644 (file)
@@ -471,49 +471,18 @@ config_get_vals(ConfigTable *cf, ConfigArgs *c)
 
 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;
@@ -521,36 +490,17 @@ init_config_attrs(ConfigTable *ct) {
 
 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;
 }
index 4847c9cc07c4f7155373ca6e37b517ecb8e0f929..d4e970d394acf2ef94e25f8e463b4e1d58c63ab8 100644 (file)
@@ -755,3 +755,34 @@ oc_schema_info( Entry *e )
        }
        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;
+}
index 91b84b741dd2c6375368754cfc977e7878b5ab41..0d48e5118bfd495cd512a18d0a4da9edadcb9c94 100644 (file)
@@ -234,6 +234,11 @@ LDAP_SLAPD_F (int) at_next LDAP_P(( AttributeType **at ));
 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
  */
@@ -1236,6 +1241,11 @@ LDAP_SLAPD_F (int) oc_schema_info( Entry *e );
 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
  */