X-Git-Url: https://git.sur5r.net/?a=blobdiff_plain;f=servers%2Fslapd%2Fbconfig.c;h=6efd2d2df6aeacb80cdbee6ba6c32f8ddfa3cd7f;hb=7684514535dbe9f407b420bab76f06861ad7587d;hp=254f6be7ba6e098b08506fb9379e3b74f9d7dcc7;hpb=d2b27b156e7f07daf7af5b74d9235e7d7f62e86d;p=openldap diff --git a/servers/slapd/bconfig.c b/servers/slapd/bconfig.c index 254f6be7ba..6efd2d2df6 100644 --- a/servers/slapd/bconfig.c +++ b/servers/slapd/bconfig.c @@ -37,8 +37,11 @@ #include "config.h" -static struct berval config_rdn = BER_BVC("cn=config"); -static struct berval schema_rdn = BER_BVC("cn=schema"); +#define CONFIG_RDN "cn=config" +#define SCHEMA_RDN "cn=schema" + +static struct berval config_rdn = BER_BVC(CONFIG_RDN); +static struct berval schema_rdn = BER_BVC(SCHEMA_RDN); extern int slap_DN_strict; /* dn.c */ @@ -71,6 +74,8 @@ typedef struct { int cb_use_ldif; } CfBackInfo; +static CfBackInfo cfBackInfo; + static char *passwd_salt; static char *logfileName; #ifdef SLAP_AUTH_REWRITE @@ -81,15 +86,25 @@ static struct berval cfdir; /* Private state */ static AttributeDescription *cfAd_backend, *cfAd_database, *cfAd_overlay, - *cfAd_include; + *cfAd_include, *cfAd_attr, *cfAd_oc, *cfAd_om; static ConfigFile *cfn; static Avlnode *CfOcTree; +/* System schema state */ +extern AttributeType *at_sys_tail; /* at.c */ +extern ObjectClass *oc_sys_tail; /* oc.c */ +extern OidMacro *om_sys_tail; /* oidm.c */ +static AttributeType *cf_at_tail; +static ObjectClass *cf_oc_tail; +static OidMacro *cf_om_tail; + static int config_add_internal( CfBackInfo *cfb, Entry *e, ConfigArgs *ca, SlapReply *rs, int *renumber, Operation *op ); +static int config_check_schema( CfBackInfo *cfb ); + static ConfigDriver config_fname; static ConfigDriver config_cfdir; static ConfigDriver config_generic; @@ -163,6 +178,7 @@ enum { CFG_TTHREADS, CFG_MIRRORMODE, CFG_HIDDEN, + CFG_MONITORING, CFG_LAST }; @@ -221,6 +237,7 @@ static OidRec OidMacros[] = { * OLcfgOv{Oc|At}:12 -> ppolicy * OLcfgOv{Oc|At}:13 -> constraint * OLcfgOv{Oc|At}:14 -> translucent + * OLcfgOv{Oc|At}:15 -> auditlog */ /* alphabetical ordering */ @@ -257,7 +274,7 @@ static ConfigTable config_back_cf_table[] = { "EQUALITY caseIgnoreMatch " "SYNTAX OMsDirectoryString )", NULL, NULL }, { "attribute", "attribute", 2, 0, STRLENOF( "attribute" ), - ARG_PAREN|ARG_MAGIC|CFG_ATTR|ARG_NO_DELETE|ARG_NO_INSERT, + ARG_PAREN|ARG_MAGIC|CFG_ATTR, &config_generic, "( OLcfgGlAt:4 NAME 'olcAttributeTypes' " "DESC 'OpenLDAP attributeTypes' " "EQUALITY caseIgnoreMatch " @@ -381,13 +398,17 @@ static ConfigTable config_back_cf_table[] = { #endif "( OLcfgGlAt:31 NAME 'olcModulePath' " "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL }, - { "objectclass", "objectclass", 2, 0, 0, ARG_PAREN|ARG_MAGIC|CFG_OC|ARG_NO_DELETE|ARG_NO_INSERT, + { "monitoring", "TRUE|FALSE", 2, 2, 0, + ARG_MAGIC|CFG_MONITORING|ARG_DB|ARG_ON_OFF, &config_generic, + "( OLcfgDbAt:0.18 NAME 'olcMonitoring' " + "SYNTAX OMsBoolean SINGLE-VALUE )", NULL, NULL }, + { "objectclass", "objectclass", 2, 0, 0, ARG_PAREN|ARG_MAGIC|CFG_OC, &config_generic, "( OLcfgGlAt:32 NAME 'olcObjectClasses' " "DESC 'OpenLDAP object classes' " "EQUALITY caseIgnoreMatch " "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )", NULL, NULL }, - { "objectidentifier", NULL, 0, 0, 0, ARG_MAGIC|CFG_OID, + { "objectidentifier", "name> op == SLAP_CONFIG_EMIT ) { @@ -940,6 +961,9 @@ config_generic(ConfigArgs *c) { else rc = 1; break; + case CFG_MONITORING: + c->value_int = (SLAP_DBMONITORING(c->be) != 0); + break; case CFG_SSTR_IF_MAX: c->value_int = index_substr_if_maxlen; break; @@ -1027,6 +1051,7 @@ config_generic(ConfigArgs *c) { case CFG_DEPTH: case CFG_LASTMOD: case CFG_MIRRORMODE: + case CFG_MONITORING: case CFG_SASLSECP: case CFG_SSTR_IF_MAX: case CFG_SSTR_IF_MIN: @@ -1097,6 +1122,76 @@ config_generic(ConfigArgs *c) { } break; + case CFG_OC: { + CfEntryInfo *ce = c->ca_entry->e_private; + /* can't modify the hardcoded schema */ + if ( ce->ce_parent->ce_type == Cft_Global ) + return 1; + } + cfn = c->private; + if ( c->valx < 0 ) { + ObjectClass *oc; + + for( oc = cfn->c_oc_head; oc; oc_next( &oc )) { + oc_delete( oc ); + if ( oc == cfn->c_oc_tail ) + break; + } + cfn->c_oc_head = cfn->c_oc_tail = NULL; + } else { + ObjectClass *oc, *prev = NULL; + int i; + + for ( i=0, oc=cfn->c_oc_head; ivalx; i++) { + prev = oc; + oc_next( &oc ); + } + oc_delete( oc ); + if ( cfn->c_oc_tail == oc ) { + cfn->c_oc_tail = prev; + } + if ( cfn->c_oc_head == oc ) { + oc_next( &oc ); + cfn->c_oc_head = oc; + } + } + break; + + case CFG_ATTR: { + CfEntryInfo *ce = c->ca_entry->e_private; + /* can't modify the hardcoded schema */ + if ( ce->ce_parent->ce_type == Cft_Global ) + return 1; + } + cfn = c->private; + if ( c->valx < 0 ) { + AttributeType *at; + + for( at = cfn->c_at_head; at; at_next( &at )) { + at_delete( at ); + if ( at == cfn->c_at_tail ) + break; + } + cfn->c_at_head = cfn->c_at_tail = NULL; + } else { + AttributeType *at, *prev = NULL; + int i; + + for ( i=0, at=cfn->c_at_head; ivalx; i++) { + prev = at; + at_next( &at ); + } + at_delete( at ); + if ( cfn->c_at_tail == at ) { + cfn->c_at_tail = prev; + } + if ( cfn->c_at_head == at ) { + at_next( &at ); + cfn->c_at_head = at; + } + } + break; + case CFG_LIMITS: /* FIXME: there is no limits_free function */ case CFG_ATOPT: @@ -1105,9 +1200,7 @@ config_generic(ConfigArgs *c) { /* FIXME: there is no way to remove attributes added by a DSE file */ case CFG_OID: - case CFG_OC: case CFG_DIT: - case CFG_ATTR: case CFG_MODPATH: default: rc = 1; @@ -1116,8 +1209,6 @@ config_generic(ConfigArgs *c) { return rc; } - p = strchr(c->line,'(' /*')'*/); - switch(c->type) { case CFG_BACKEND: if(!(c->bi = backend_info(c->argv[1]))) { @@ -1232,7 +1323,9 @@ config_generic(ConfigArgs *c) { case CFG_OID: { OidMacro *om; - if(parse_oidm(c->fname, c->lineno, c->argc, c->argv, 1, &om)) + if ( c->op == LDAP_MOD_ADD && c->private && cfn != c->private ) + cfn = c->private; + if(parse_oidm(c, 1, &om)) return(1); if (!cfn->c_om_head) cfn->c_om_head = om; cfn->c_om_tail = om; @@ -1240,29 +1333,77 @@ config_generic(ConfigArgs *c) { break; case CFG_OC: { - ObjectClass *oc; + ObjectClass *oc, *prev; - if(parse_oc(c->fname, c->lineno, p, c->argv, &oc)) return(1); + if ( c->op == LDAP_MOD_ADD && c->private && cfn != c->private ) + cfn = c->private; + if ( c->valx < 0 ) { + prev = cfn->c_oc_tail; + } else { + prev = NULL; + /* If adding anything after the first, prev is easy */ + if ( c->valx ) { + int i; + for (i=0, oc = cfn->c_oc_head; ivalx; i++) { + prev = oc; + oc_next( &oc ); + } + } else + /* If adding the first, and head exists, find its prev */ + if (cfn->c_oc_head) { + for ( oc_start( &oc ); oc != cfn->c_oc_head; ) { + prev = oc; + oc_next( &oc ); + } + } + /* else prev is NULL, append to end of global list */ + } + if(parse_oc(c, &oc, prev)) return(1); if (!cfn->c_oc_head) cfn->c_oc_head = oc; - cfn->c_oc_tail = oc; + if (cfn->c_oc_tail == prev) cfn->c_oc_tail = oc; } break; - case CFG_DIT: { - ContentRule *cr; + case CFG_ATTR: { + AttributeType *at, *prev; - if(parse_cr(c->fname, c->lineno, p, c->argv, &cr)) return(1); - if (!cfn->c_cr_head) cfn->c_cr_head = cr; - cfn->c_cr_tail = cr; + if ( c->op == LDAP_MOD_ADD && c->private && cfn != c->private ) + cfn = c->private; + if ( c->valx < 0 ) { + prev = cfn->c_at_tail; + } else { + prev = NULL; + /* If adding anything after the first, prev is easy */ + if ( c->valx ) { + int i; + for (i=0, at = cfn->c_at_head; ivalx; i++) { + prev = at; + at_next( &at ); + } + } else + /* If adding the first, and head exists, find its prev */ + if (cfn->c_at_head) { + for ( at_start( &at ); at != cfn->c_at_head; ) { + prev = at; + at_next( &at ); + } + } + /* else prev is NULL, append to end of global list */ + } + if(parse_at(c, &at, prev)) return(1); + if (!cfn->c_at_head) cfn->c_at_head = at; + if (cfn->c_at_tail == prev) cfn->c_at_tail = at; } break; - case CFG_ATTR: { - AttributeType *at; + case CFG_DIT: { + ContentRule *cr; - if(parse_at(c->fname, c->lineno, p, c->argv, &at)) return(1); - if (!cfn->c_at_head) cfn->c_at_head = at; - cfn->c_at_tail = at; + if ( c->op == LDAP_MOD_ADD && c->private && cfn != c->private ) + cfn = c->private; + if(parse_cr(c, &cr)) return(1); + if (!cfn->c_cr_head) cfn->c_cr_head = cr; + cfn->c_cr_tail = cr; } break; @@ -1377,6 +1518,8 @@ config_generic(ConfigArgs *c) { { struct berval bv; ber_str2bv( c->argv[1], 0, 1, &bv ); + if ( c->op == LDAP_MOD_ADD && c->private && cfn != c->private ) + cfn = c->private; ber_bvarray_add( &cfn->c_dseFiles, &bv ); } break; @@ -1417,6 +1560,13 @@ config_generic(ConfigArgs *c) { SLAP_DBFLAGS(c->be) |= SLAP_DBFLAG_SINGLE_SHADOW; break; + case CFG_MONITORING: + if(c->value_int) + SLAP_DBFLAGS(c->be) |= SLAP_DBFLAG_MONITORING; + else + SLAP_DBFLAGS(c->be) &= ~SLAP_DBFLAG_MONITORING; + break; + case CFG_HIDDEN: if (c->value_int) SLAP_DBFLAGS(c->be) |= SLAP_DBFLAG_HIDDEN; @@ -1476,6 +1626,10 @@ config_generic(ConfigArgs *c) { ber_str2bv(ptr, 0, 1, &bv); ber_bvarray_add( &modcur->mp_loads, &bv ); } + /* Check for any new hardcoded schema */ + if ( c->op == LDAP_MOD_ADD && CONFIG_ONLINE_ADD( c )) { + config_check_schema( &cfBackInfo ); + } break; case CFG_MODPATH: @@ -2040,7 +2194,7 @@ config_restrict(ConfigArgs *c) { { BER_BVC("compare"), SLAP_RESTRICT_OP_COMPARE }, { BER_BVC("read"), SLAP_RESTRICT_OP_READS }, { BER_BVC("write"), SLAP_RESTRICT_OP_WRITES }, - { BER_BVC("extended"), SLAP_RESTRICT_OP_EXTENDED }, + { BER_BVC("extended"), SLAP_RESTRICT_OP_EXTENDED }, { BER_BVC("extended=" LDAP_EXOP_START_TLS ), SLAP_RESTRICT_EXOP_START_TLS }, { BER_BVC("extended=" LDAP_EXOP_MODIFY_PASSWD ), SLAP_RESTRICT_EXOP_MODIFY_PASSWD }, { BER_BVC("extended=" LDAP_EXOP_X_WHO_AM_I ), SLAP_RESTRICT_EXOP_WHOAMI }, @@ -2144,8 +2298,10 @@ config_disallows(ConfigArgs *c) { static int config_requires(ConfigArgs *c) { - slap_mask_t requires = 0; - int i; + slap_mask_t requires = frontendDB->be_requires; + int i, argc = c->argc; + char **argv = c->argv; + slap_verbmasks requires_ops[] = { { BER_BVC("bind"), SLAP_REQUIRE_BIND }, { BER_BVC("LDAPv3"), SLAP_REQUIRE_LDAP_V3 }, @@ -2165,11 +2321,23 @@ config_requires(ConfigArgs *c) { } return 0; } - i = verbs_to_mask(c->argc, c->argv, requires_ops, &requires); + /* "none" can only be first, to wipe out default/global values */ + if ( strcasecmp( c->argv[ 1 ], "none" ) == 0 ) { + argv++; + argc--; + requires = 0; + } + i = verbs_to_mask(argc, argv, requires_ops, &requires); if ( i ) { - snprintf( c->msg, sizeof( c->msg ), "<%s> unknown feature", c->argv[0] ); - Debug(LDAP_DEBUG_ANY, "%s: %s %s\n", - c->log, c->msg, c->argv[i]); + if (strcasecmp( c->argv[ i ], "none" ) == 0 ) { + snprintf( c->msg, sizeof( c->msg ), "<%s> \"none\" (#%d) must be listed first", c->argv[0], i - 1 ); + Debug(LDAP_DEBUG_ANY, "%s: %s\n", + c->log, c->msg, 0); + } else { + snprintf( c->msg, sizeof( c->msg ), "<%s> unknown feature #%d", c->argv[0], i - 1 ); + Debug(LDAP_DEBUG_ANY, "%s: %s \"%s\"\n", + c->log, c->msg, c->argv[i]); + } return(1); } c->be->be_requires = requires; @@ -2326,6 +2494,28 @@ loglevel2bvarray( int l, BerVarray *bva ) return mask_to_verbs( loglevel_ops, l, bva ); } +int +loglevel_print( FILE *out ) +{ + int i; + + if ( loglevel_ops == NULL ) { + loglevel_init(); + } + + fprintf( out, "Installed log subsystems:\n\n" ); + for ( i = 0; !BER_BVISNULL( &loglevel_ops[ i ].word ); i++ ) { + fprintf( out, "\t%-30s (%lu)\n", + loglevel_ops[ i ].word.bv_val, + loglevel_ops[ i ].mask ); + } + + fprintf( out, "\nNOTE: custom log subsystems may be later installed " + "by specific code\n\n" ); + + return 0; +} + static int config_syslog; static int @@ -2466,7 +2656,7 @@ config_security(ConfigArgs *c) { } for(i = 1; i < c->argc; i++) { slap_ssf_t *tgt = NULL; - char *src; + char *src = NULL; for ( j=0; !BER_BVISNULL( &sec_keys[j].key ); j++ ) { if(!strncasecmp(c->argv[i], sec_keys[j].key.bv_val, sec_keys[j].key.bv_len)) { @@ -2615,6 +2805,8 @@ config_replica(ConfigArgs *c) { nr = add_replica_info(c->be, replicauri, replicahost); break; } else if(!strncasecmp(c->argv[i], "uri=", STRLENOF("uri="))) { + ber_len_t len; + if ( replicauri ) { snprintf( c->msg, sizeof( c->msg ), "<%s> replica host/URI already specified", c->argv[0] ); Debug(LDAP_DEBUG_ANY, "%s: %s \"%s\"\n", c->log, c->msg, replicauri ); @@ -2633,11 +2825,28 @@ config_replica(ConfigArgs *c) { Debug(LDAP_DEBUG_ANY, "%s: %s\n", c->log, c->msg, 0 ); return(1); } + + len = strlen(ludp->lud_scheme) + strlen(ludp->lud_host) + + STRLENOF("://") + 1; + if (ludp->lud_port != LDAP_PORT) { + if (ludp->lud_port < 1 || ludp->lud_port > 65535) { + ldap_free_urldesc(ludp); + snprintf( c->msg, sizeof( c->msg ), "<%s> invalid port", + c->argv[0] ); + Debug(LDAP_DEBUG_ANY, "%s: %s\n", c->log, c->msg, 0 ); + return(1); + } + len += STRLENOF(":65535"); + } + replicauri = ch_malloc( len ); + replicahost = lutil_strcopy( replicauri, ludp->lud_scheme ); + replicahost = lutil_strcopy( replicahost, "://" ); + if (ludp->lud_port == LDAP_PORT) { + strcpy( replicahost, ludp->lud_host ); + } else { + sprintf( replicahost, "%s:%d",ludp->lud_host,ludp->lud_port ); + } ldap_free_urldesc(ludp); - replicauri = c->argv[i] + STRLENOF("uri="); - replicauri = ch_strdup( replicauri ); - replicahost = strchr( replicauri, '/' ); - replicahost += 2; nr = add_replica_info(c->be, replicauri, replicahost); break; } @@ -2974,6 +3183,10 @@ config_find_base( CfEntryInfo *root, struct berval *dn, CfEntryInfo **last ) typedef struct setup_cookie { CfBackInfo *cfb; ConfigArgs *ca; + Entry *frontend; + Entry *config; + int got_frontend; + int got_config; } setup_cookie; static int @@ -2983,6 +3196,56 @@ config_ldif_resp( Operation *op, SlapReply *rs ) setup_cookie *sc = op->o_callback->sc_private; sc->cfb->cb_got_ldif = 1; + /* Does the frontend exist? */ + if ( !sc->got_frontend ) { + if ( !strncmp( rs->sr_entry->e_nname.bv_val, + "olcDatabase", STRLENOF( "olcDatabase" ))) { + if ( strncmp( rs->sr_entry->e_nname.bv_val + + STRLENOF( "olcDatabase" ), "={-1}frontend", + STRLENOF( "={-1}frontend" ))) { + struct berval rdn; + int i = op->o_noop; + sc->ca->be = frontendDB; + sc->ca->bi = frontendDB->bd_info; + frontendDB->be_cf_ocs = &CFOC_FRONTEND; + rdn.bv_val = sc->ca->log; + rdn.bv_len = snprintf(rdn.bv_val, sizeof( sc->ca->log ), + "%s=" SLAP_X_ORDERED_FMT "%s", + cfAd_database->ad_cname.bv_val, -1, + sc->ca->bi->bi_type); + op->o_noop = 1; + sc->frontend = config_build_entry( op, rs, + sc->cfb->cb_root, sc->ca, &rdn, &CFOC_DATABASE, + sc->ca->be->be_cf_ocs ); + op->o_noop = i; + } + sc->got_frontend++; + } + } + /* Does the configDB exist? */ + if ( sc->got_frontend && !sc->got_config && + !strncmp( rs->sr_entry->e_nname.bv_val, + "olcDatabase", STRLENOF( "olcDatabase" ))) { + if ( strncmp( rs->sr_entry->e_nname.bv_val + + STRLENOF( "olcDatabase" ), "={0}config", + STRLENOF( "={0}config" ))) { + struct berval rdn; + int i = op->o_noop; + sc->ca->be = LDAP_STAILQ_FIRST( &backendDB ); + sc->ca->bi = sc->ca->be->bd_info; + rdn.bv_val = sc->ca->log; + rdn.bv_len = snprintf(rdn.bv_val, sizeof( sc->ca->log ), + "%s=" SLAP_X_ORDERED_FMT "%s", + cfAd_database->ad_cname.bv_val, 0, + sc->ca->bi->bi_type); + op->o_noop = 1; + sc->config = config_build_entry( op, rs, sc->cfb->cb_root, + sc->ca, &rdn, &CFOC_DATABASE, sc->ca->be->be_cf_ocs ); + op->o_noop = i; + } + sc->got_config++; + } + rs->sr_err = config_add_internal( sc->cfb, rs->sr_entry, sc->ca, NULL, NULL, NULL ); if ( rs->sr_err != LDAP_SUCCESS ) { Debug( LDAP_DEBUG_ANY, "config error processing %s: %s\n", @@ -3085,6 +3348,10 @@ config_setup_ldif( BackendDB *be, const char *dir, int readit ) { sc.cfb = cfb; sc.ca = &c; cb.sc_private = ≻ + sc.got_frontend = 0; + sc.got_config = 0; + sc.frontend = NULL; + sc.config = NULL; op->o_bd = &cfb->cb_db; @@ -3097,6 +3364,15 @@ config_setup_ldif( BackendDB *be, const char *dir, int readit ) { /* Restore normal DN validation */ slap_DN_strict = prev_DN_strict; + op->o_tag = LDAP_REQ_ADD; + if ( rc == LDAP_SUCCESS && sc.frontend ) { + op->ora_e = sc.frontend; + rc = op->o_bd->be_add( op, &rs ); + } + if ( rc == LDAP_SUCCESS && sc.config ) { + op->ora_e = sc.config; + rc = op->o_bd->be_add( op, &rs ); + } ldap_pvt_thread_pool_context_reset( thrctx ); } @@ -3343,7 +3619,7 @@ check_vals( ConfigTable *ct, ConfigArgs *ca, void *ptr, int isAttr ) AttributeDescription *ad; BerVarray vals; - int i, rc = 0, sort = 0; + int i, rc = 0; if ( isAttr ) { a = ptr; @@ -3356,7 +3632,6 @@ check_vals( ConfigTable *ct, ConfigArgs *ca, void *ptr, int isAttr ) } if ( a && ( ad->ad_type->sat_flags & SLAP_AT_ORDERED_VAL )) { - sort = 1; rc = ordered_value_sort( a, 1 ); if ( rc ) { snprintf(ca->msg, sizeof( ca->msg ), "ordered_value_sort failed on attr %s\n", @@ -3366,7 +3641,8 @@ check_vals( ConfigTable *ct, ConfigArgs *ca, void *ptr, int isAttr ) } for ( i=0; vals[i].bv_val; i++ ) { ca->line = vals[i].bv_val; - if ( sort ) { + if (( ad->ad_type->sat_flags & SLAP_AT_ORDERED_VAL ) && + ca->line[0] == '{' ) { char *idx = strchr( ca->line, '}' ); if ( idx ) ca->line = idx+1; } @@ -3757,7 +4033,7 @@ config_add_internal( CfBackInfo *cfb, Entry *e, ConfigArgs *ca, SlapReply *rs, if ( ptr ) ca->line = ptr+1; } ca->valx = i; - rc = config_parse_add( ct, ca ); + rc = config_parse_add( ct, ca, i ); if ( rc ) { rc = LDAP_OTHER; goto done; @@ -4034,7 +4310,7 @@ config_modify_internal( CfEntryInfo *ce, Operation *op, SlapReply *rs, if(rc == LDAP_SUCCESS) { /* check that the entry still obeys the schema */ - rc = entry_schema_check(op, e, NULL, 0, + rc = entry_schema_check(op, e, NULL, 0, 0, &rs->sr_text, ca->msg, sizeof(ca->msg) ); } if ( rc == LDAP_SUCCESS ) { @@ -4096,8 +4372,9 @@ config_modify_internal( CfEntryInfo *ce, Operation *op, SlapReply *rs, if ( rc ) rc = LDAP_OTHER; } if ( ml->sml_values ) { + d = d->next; ch_free( dels ); - dels = d->next; + dels = d; } if ( ml->sml_op == LDAP_MOD_REPLACE ) { ml->sml_values = vals; @@ -4127,7 +4404,7 @@ config_modify_internal( CfEntryInfo *ce, Operation *op, SlapReply *rs, ca->line = ptr+1; } } - rc = config_parse_add( ct, ca ); + rc = config_parse_add( ct, ca, i ); if ( rc ) { rc = LDAP_OTHER; goto out; @@ -4369,7 +4646,7 @@ Entry * config_build_entry( Operation *op, SlapReply *rs, CfEntryInfo *parent, ConfigArgs *c, struct berval *rdn, ConfigOCs *main, ConfigOCs *extra ) { - Entry *e = ch_calloc( 1, sizeof(Entry) ); + Entry *e = entry_alloc(); CfEntryInfo *ce = ch_calloc( 1, sizeof(CfEntryInfo) ); struct berval val; struct berval ad_name; @@ -4436,10 +4713,10 @@ config_build_entry( Operation *op, SlapReply *rs, CfEntryInfo *parent, } oc_at = attr_find( e->e_attrs, slap_schema.si_ad_objectClass ); - rc = structural_class(oc_at->a_vals, &val, NULL, &text, c->msg, - sizeof(c->msg)); - attr_merge_normalize_one(e, slap_schema.si_ad_structuralObjectClass, &val, NULL ); - if ( op ) { + rc = structural_class(oc_at->a_vals, &oc, NULL, &text, c->msg, + sizeof(c->msg), op->o_tmpmemctx ); + attr_merge_normalize_one(e, slap_schema.si_ad_structuralObjectClass, &oc->soc_cname, NULL ); + if ( !op->o_noop ) { op->ora_e = e; op->o_bd->be_add( op, rs ); if ( ( rs->sr_err != LDAP_SUCCESS ) @@ -4555,6 +4832,87 @@ config_build_modules( ConfigArgs *c, CfEntryInfo *ceparent, } #endif +static int +config_check_schema(CfBackInfo *cfb) +{ + struct berval schema_dn = BER_BVC(SCHEMA_RDN "," CONFIG_RDN); + ConfigArgs c = {0}; + ConfigFile *cf = cfb->cb_config; + CfEntryInfo *ce, *last; + Entry *e; + + /* If there's no root entry, we must be in the midst of converting */ + if ( !cfb->cb_root ) + return 0; + + /* Make sure the main schema entry exists */ + ce = config_find_base( cfb->cb_root, &schema_dn, &last ); + if ( ce ) { + Attribute *a; + struct berval *bv; + + e = ce->ce_entry; + + /* Make sure it's up to date */ + if ( cf_om_tail != om_sys_tail ) { + a = attr_find( e->e_attrs, cfAd_om ); + if ( a ) { + if ( a->a_nvals != a->a_vals ) + ber_bvarray_free( a->a_nvals ); + ber_bvarray_free( a->a_vals ); + a->a_vals = NULL; + a->a_nvals = NULL; + } + oidm_unparse( &bv, NULL, NULL, 1 ); + attr_merge_normalize( e, cfAd_om, bv, NULL ); + ber_bvarray_free( bv ); + cf_om_tail = om_sys_tail; + } + if ( cf_at_tail != at_sys_tail ) { + a = attr_find( e->e_attrs, cfAd_attr ); + if ( a ) { + if ( a->a_nvals != a->a_vals ) + ber_bvarray_free( a->a_nvals ); + ber_bvarray_free( a->a_vals ); + a->a_vals = NULL; + a->a_nvals = NULL; + } + at_unparse( &bv, NULL, NULL, 1 ); + attr_merge_normalize( e, cfAd_attr, bv, NULL ); + ber_bvarray_free( bv ); + cf_at_tail = at_sys_tail; + } + if ( cf_oc_tail != oc_sys_tail ) { + a = attr_find( e->e_attrs, cfAd_oc ); + if ( a ) { + if ( a->a_nvals != a->a_vals ) + ber_bvarray_free( a->a_nvals ); + ber_bvarray_free( a->a_vals ); + a->a_vals = NULL; + a->a_nvals = NULL; + } + oc_unparse( &bv, NULL, NULL, 1 ); + attr_merge_normalize( e, cfAd_oc, bv, NULL ); + ber_bvarray_free( bv ); + cf_oc_tail = oc_sys_tail; + } + } else { + SlapReply rs = {REP_RESULT}; + c.private = NULL; + e = config_build_entry( NULL, &rs, cfb->cb_root, &c, &schema_rdn, + &CFOC_SCHEMA, NULL ); + if ( !e ) { + return -1; + } + ce = e->e_private; + ce->ce_private = cfb->cb_config; + cf_at_tail = at_sys_tail; + cf_oc_tail = oc_sys_tail; + cf_om_tail = om_sys_tail; + } + return 0; +} + static const char *defacl[] = { NULL, "to", "*", "by", "*", "none", NULL }; @@ -4585,22 +4943,23 @@ config_back_db_open( BackendDB *be ) parse_acl(be, "config_back_db_open", 0, 6, (char **)defacl, 0 ); } - /* If we read the config from back-ldif, nothing to do here */ - if ( cfb->cb_got_ldif ) - return 0; + /* If we read the config from back-ldif, do some quick sanity checks */ + if ( cfb->cb_got_ldif ) { + return config_check_schema( cfb ); + } - if ( cfb->cb_use_ldif ) { - thrctx = ldap_pvt_thread_pool_context(); - op = (Operation *) &opbuf; - connection_fake_init( &conn, op, thrctx ); + thrctx = ldap_pvt_thread_pool_context(); + op = (Operation *) &opbuf; + connection_fake_init( &conn, op, thrctx ); - op->o_tag = LDAP_REQ_ADD; - op->o_callback = &cb; - op->o_bd = &cfb->cb_db; - op->o_dn = op->o_bd->be_rootdn; - op->o_ndn = op->o_bd->be_rootndn; - } else { - op = NULL; + op->o_tag = LDAP_REQ_ADD; + op->o_callback = &cb; + op->o_bd = &cfb->cb_db; + op->o_dn = op->o_bd->be_rootdn; + op->o_ndn = op->o_bd->be_rootndn; + + if ( !cfb->cb_use_ldif ) { + op->o_noop = 1; } /* create root of tree */ @@ -4646,6 +5005,10 @@ config_back_db_open( BackendDB *be ) return -1; } ce = e->e_private; + ce->ce_private = cfb->cb_config; + cf_at_tail = at_sys_tail; + cf_oc_tail = oc_sys_tail; + cf_om_tail = om_sys_tail; /* Create schema nodes for included schema... */ if ( cfb->cb_config->c_kids ) { @@ -4836,8 +5199,6 @@ config_back_db_destroy( BackendDB *be ) backend_destroy_one( &cfb->cb_db, 0 ); } - free( be->be_private ); - loglevel_destroy(); return 0; @@ -4849,7 +5210,7 @@ config_back_db_init( BackendDB *be ) struct berval dn; CfBackInfo *cfb; - cfb = ch_calloc( 1, sizeof(CfBackInfo)); + cfb = &cfBackInfo; cfb->cb_config = ch_calloc( 1, sizeof(ConfigFile)); cfn = cfb->cb_config; be->be_private = cfb; @@ -4953,9 +5314,12 @@ static struct { char *name; AttributeDescription **desc; } ads[] = { + { "attribute", &cfAd_attr }, { "backend", &cfAd_backend }, { "database", &cfAd_database }, { "include", &cfAd_include }, + { "objectclass", &cfAd_oc }, + { "objectidentifier", &cfAd_om }, { "overlay", &cfAd_overlay }, { NULL, NULL } }; @@ -4987,6 +5351,7 @@ int config_back_initialize( BackendInfo *bi ) { ConfigTable *ct = config_back_cf_table; + ConfigArgs ca; char *argv[4]; int i; AttributeDescription *ad = NULL; @@ -5038,11 +5403,17 @@ config_back_initialize( BackendInfo *bi ) bi->bi_tool_entry_get = config_tool_entry_get; bi->bi_tool_entry_put = config_tool_entry_put; + ca.argv = argv; + argv[ 0 ] = "slapd"; + ca.argv = argv; + ca.argc = 3; + ca.fname = argv[0]; + argv[3] = NULL; for (i=0; OidMacros[i].name; i++ ) { argv[1] = OidMacros[i].name; argv[2] = OidMacros[i].oid; - parse_oidm( "slapd", i, 3, argv, 0, NULL ); + parse_oidm( &ca, 0, NULL ); } bi->bi_cf_ocs = cf_ocs;