#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 */
int cb_use_ldif;
} CfBackInfo;
+static CfBackInfo cfBackInfo;
+
static char *passwd_salt;
static char *logfileName;
#ifdef SLAP_AUTH_REWRITE
/* 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;
"EQUALITY caseIgnoreMatch "
"SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )",
NULL, NULL },
- { "objectidentifier", NULL, 0, 0, 0, ARG_MAGIC|CFG_OID,
+ { "objectidentifier", "name> <oid", 3, 3, 0, ARG_MAGIC|CFG_OID,
&config_generic, "( OLcfgGlAt:33 NAME 'olcObjectIdentifier' "
"EQUALITY caseIgnoreMatch "
"SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )", NULL, NULL },
static int
config_generic(ConfigArgs *c) {
- char *p;
int i;
if ( c->op == SLAP_CONFIG_EMIT ) {
return rc;
}
- p = strchr(c->line,'(' /*')'*/);
-
switch(c->type) {
case CFG_BACKEND:
if(!(c->bi = backend_info(c->argv[1]))) {
if ( c->op == LDAP_MOD_ADD && c->private && cfn != c->private )
cfn = c->private;
- if(parse_oidm(c->fname, c->lineno, c->argc, c->argv, 1, &om))
+ if(parse_oidm(c, 1, &om))
return(1);
if (!cfn->c_om_head) cfn->c_om_head = om;
cfn->c_om_tail = om;
}
/* else prev is NULL, append to end of global list */
}
- if(parse_oc(c->fname, c->lineno, p, c->argv, &oc, prev)) return(1);
+ if(parse_oc(c, &oc, prev)) return(1);
if (!cfn->c_oc_head) cfn->c_oc_head = oc;
if (cfn->c_oc_tail == prev) cfn->c_oc_tail = oc;
}
}
/* else prev is NULL, append to end of global list */
}
- if(parse_at(c->fname, c->lineno, p, c->argv, &at, prev)) return(1);
+ 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;
}
if ( c->op == LDAP_MOD_ADD && c->private && cfn != c->private )
cfn = c->private;
- if(parse_cr(c->fname, c->lineno, p, c->argv, &cr)) return(1);
+ if(parse_cr(c, &cr)) return(1);
if (!cfn->c_cr_head) cfn->c_cr_head = cr;
cfn->c_cr_tail = cr;
}
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:
typedef struct setup_cookie {
CfBackInfo *cfb;
ConfigArgs *ca;
+ Entry *frontend;
+ Entry *config;
+ int got_frontend;
+ int got_config;
} setup_cookie;
static int
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",
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;
/* 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 );
}
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;
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 ) {
ca->line = ptr+1;
}
}
- rc = config_parse_add( ct, ca );
+ rc = config_parse_add( ct, ca, i );
if ( rc ) {
rc = LDAP_OTHER;
goto out;
}
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 )
}
#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
};
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 */
}
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 ) {
backend_destroy_one( &cfb->cb_db, 0 );
}
- free( be->be_private );
-
loglevel_destroy();
return 0;
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;
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 }
};
config_back_initialize( BackendInfo *bi )
{
ConfigTable *ct = config_back_cf_table;
+ ConfigArgs ca;
char *argv[4];
int i;
AttributeDescription *ad = NULL;
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;