X-Git-Url: https://git.sur5r.net/?a=blobdiff_plain;f=servers%2Fslapd%2Fbconfig.c;h=d3f28a9d663af4f43c42b01b745d9500bd6e0abc;hb=3eb87b2faae4b9f59f1270936f70a1781c2abd7a;hp=04ce1a60d038c4fc04034f63d427f8f98c5e5784;hpb=1bc59be16d8abe5e430d386d89ee175e77bb4664;p=openldap diff --git a/servers/slapd/bconfig.c b/servers/slapd/bconfig.c index 04ce1a60d0..d3f28a9d66 100644 --- a/servers/slapd/bconfig.c +++ b/servers/slapd/bconfig.c @@ -35,7 +35,10 @@ #include "config.h" -#define CONFIG_DN "cn=config" +static struct berval config_rdn = BER_BVC("cn=config"); +static struct berval schema_rdn = BER_BVC("cn=schema"); + +#define IFMT "{%d}" #ifdef SLAPD_MODULES typedef struct modpath_s { @@ -43,23 +46,33 @@ typedef struct modpath_s { struct berval mp_path; BerVarray mp_loads; } ModPaths; + +static ModPaths modpaths, *modlast = &modpaths, *modcur = &modpaths; #endif typedef struct ConfigFile { struct ConfigFile *c_sibs; struct ConfigFile *c_kids; struct berval c_file; -#ifdef SLAPD_MODULES - ModPaths c_modpaths; - ModPaths *c_modlast; -#endif + AttributeType *c_at_head, *c_at_tail; + ContentRule *c_cr_head, *c_cr_tail; + ObjectClass *c_oc_head, *c_oc_tail; + OidMacro *c_om_head, *c_om_tail; BerVarray c_dseFiles; } ConfigFile; +typedef struct CfOcInfo { + struct berval *co_name; + ConfigTable *co_table; + ConfigType co_type; +} CfOcInfo; + typedef struct CfEntryInfo { + struct CfEntryInfo *ce_parent; struct CfEntryInfo *ce_sibs; struct CfEntryInfo *ce_kids; Entry *ce_entry; + ConfigType ce_type; BackendInfo *ce_bi; BackendDB *ce_be; } CfEntryInfo; @@ -67,6 +80,8 @@ typedef struct CfEntryInfo { typedef struct { ConfigFile *cb_config; CfEntryInfo *cb_root; + BackendDB cb_db; /* underlying database */ + int cb_got_ldif; } CfBackInfo; /* These do nothing in slapd, they're kept only to make them @@ -79,19 +94,27 @@ static char *passwd_salt; static char *logfileName; static BerVarray authz_rewrites; +static struct berval cfdir; + +/* Private state */ static AttributeDescription *cfAd_backend, *cfAd_database, *cfAd_overlay, *cfAd_include; -static ObjectClass *cfOc_global, *cfOc_backend, *cfOc_database, - *cfOc_include, *cfOc_overlay; +static ObjectClass *cfOc_schema, *cfOc_global, *cfOc_backend, *cfOc_database, + *cfOc_include, *cfOc_overlay, *cfOc_module; static ConfigFile cf_prv, *cfn = &cf_prv; +static Avlnode *CfOcTree; + static int add_syncrepl LDAP_P(( Backend *, char **, int )); static int parse_syncrepl_line LDAP_P(( char **, int, syncinfo_t *)); static void syncrepl_unparse LDAP_P (( syncinfo_t *, struct berval *)); +static int config_add_internal( CfBackInfo *cfb, Entry *e, SlapReply *rs, + int *renumber ); static ConfigDriver config_fname; +static ConfigDriver config_cfdir; static ConfigDriver config_generic; static ConfigDriver config_search_base; static ConfigDriver config_passwd_hash; @@ -189,7 +212,12 @@ ConfigTable config_back_cf_table[] = { &config_fname, "( OLcfgAt:78 NAME 'olcConfigFile' " "DESC 'File for slapd configuration directives' " "EQUALITY caseIgnoreMatch " - "SYNTAX OMsDirectoryString )", NULL, NULL }, + "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL }, + { "", "", 0, 0, 0, ARG_MAGIC, + &config_cfdir, "( OLcfgAt:79 NAME 'olcConfigDir' " + "DESC 'Directory for slapd configuration backend' " + "EQUALITY caseIgnoreMatch " + "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL }, { "access", NULL, 0, 0, 0, ARG_MAY_DB|ARG_MAGIC|CFG_ACL, &config_generic, "( OLcfgAt:1 NAME 'olcAccess' " "DESC 'Access Control List' " @@ -204,10 +232,13 @@ ConfigTable config_back_cf_table[] = { &slapd_args_file, "( OLcfgAt:3 NAME 'olcArgsFile' " "DESC 'File for slapd command line options' " "EQUALITY caseIgnoreMatch " - "SYNTAX OMsDirectoryString )", NULL, NULL }, - /* Use standard 'attributeTypes' attr */ + "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL }, { "attribute", "attribute", 2, 0, 9, ARG_PAREN|ARG_MAGIC|CFG_ATTR, - &config_generic, NULL, NULL, NULL }, + &config_generic, "( OLcfgAt:4 NAME 'olcAttributeTypes' " + "DESC 'OpenLDAP attributeTypes' " + "EQUALITY caseIgnoreMatch " + "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )", + NULL, NULL }, { "attributeoptions", NULL, 0, 0, 0, ARG_MAGIC|CFG_ATOPT, &config_generic, "( OLcfgAt:5 NAME 'olcAttributeOptions' " "EQUALITY caseIgnoreMatch " @@ -220,11 +251,11 @@ ConfigTable config_back_cf_table[] = { #endif "( OLcfgAt:6 NAME 'olcAuthIDRewrite' " "EQUALITY caseIgnoreMatch " - "SYNTAX OMsDirectoryString )", NULL, NULL }, + "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )", NULL, NULL }, { "authz-policy", "policy", 2, 2, 0, ARG_STRING|ARG_MAGIC|CFG_AZPOLICY, &config_generic, "( OLcfgAt:7 NAME 'olcAuthzPolicy' " "EQUALITY caseIgnoreMatch " - "SYNTAX OMsDirectoryString )", NULL, NULL }, + "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL }, { "authz-regexp", NULL, 3, 3, 0, ARG_MAGIC|CFG_AZREGEXP, &config_generic, "( OLcfgAt:8 NAME 'olcAuthzRegexp' " "EQUALITY caseIgnoreMatch " @@ -233,30 +264,33 @@ ConfigTable config_back_cf_table[] = { &config_generic, "( OLcfgAt:9 NAME 'olcBackend' " "DESC 'A type of backend' " "EQUALITY caseIgnoreMatch " - "SYNTAX OMsDirectoryString )", NULL, NULL }, - { "concurrency", "level", 2, 2, 0, ARG_INT|ARG_NONZERO|ARG_MAGIC|CFG_CONCUR, + "SYNTAX OMsDirectoryString X-ORDERED 'SIBLINGS' )", NULL, NULL }, + { "concurrency", "level", 2, 2, 0, ARG_INT|ARG_MAGIC|CFG_CONCUR, &config_generic, "( OLcfgAt:10 NAME 'olcConcurrency' " - "SYNTAX OMsInteger )", NULL, NULL }, - { "conn_max_pending", "max", 2, 2, 0, ARG_LONG, + "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL }, + { "conn_max_pending", "max", 2, 2, 0, ARG_INT, &slap_conn_max_pending, "( OLcfgAt:11 NAME 'olcConnMaxPending' " - "SYNTAX OMsInteger )", NULL, NULL }, - { "conn_max_pending_auth", "max", 2, 2, 0, ARG_LONG, + "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL }, + { "conn_max_pending_auth", "max", 2, 2, 0, ARG_INT, &slap_conn_max_pending_auth, "( OLcfgAt:12 NAME 'olcConnMaxPendingAuth' " - "SYNTAX OMsInteger )", NULL, NULL }, + "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL }, { "database", "type", 2, 2, 0, ARG_MAGIC|CFG_DATABASE, &config_generic, "( OLcfgAt:13 NAME 'olcDatabase' " "DESC 'The backend type for a database instance' " - "SUP olcBackend )", NULL, NULL }, + "SUP olcBackend X-ORDERED 'SIBLINGS' )", NULL, NULL }, { "defaultSearchBase", "dn", 2, 2, 0, ARG_PRE_BI|ARG_PRE_DB|ARG_DN|ARG_MAGIC, &config_search_base, "( OLcfgAt:14 NAME 'olcDefaultSearchBase' " - "SYNTAX OMsDN )", NULL, NULL }, + "SYNTAX OMsDN SINGLE-VALUE )", NULL, NULL }, { "disallows", "features", 2, 0, 8, ARG_PRE_DB|ARG_MAGIC, &config_disallows, "( OLcfgAt:15 NAME 'olcDisallows' " "EQUALITY caseIgnoreMatch " "SYNTAX OMsDirectoryString )", NULL, NULL }, - /* use standard schema */ { "ditcontentrule", NULL, 0, 0, 0, ARG_MAGIC|CFG_DIT, - &config_generic, NULL, NULL, NULL }, + &config_generic, "( OLcfgAt:16 NAME 'olcDitContentRules' " + "DESC 'OpenLDAP DIT content rules' " + "EQUALITY caseIgnoreMatch " + "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )", + NULL, NULL }, { "gentlehup", "on|off", 2, 2, 0, #ifdef SIGHUP ARG_ON_OFF, &global_gentlehup, @@ -264,44 +298,44 @@ ConfigTable config_back_cf_table[] = { ARG_IGNORED, NULL, #endif "( OLcfgAt:17 NAME 'olcGentleHUP' " - "SYNTAX OMsBoolean )", NULL, NULL }, + "SYNTAX OMsBoolean SINGLE-VALUE )", NULL, NULL }, { "idletimeout", "timeout", 2, 2, 0, ARG_INT, &global_idletimeout, "( OLcfgAt:18 NAME 'olcIdleTimeout' " - "SYNTAX OMsInteger )", NULL, NULL }, + "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL }, /* XXX -- special case? */ { "include", "file", 2, 2, 0, ARG_MAGIC, &config_include, "( OLcfgAt:19 NAME 'olcInclude' " "SUP labeledURI )", NULL, NULL }, { "index_substr_if_minlen", "min", 2, 2, 0, ARG_INT|ARG_NONZERO|ARG_MAGIC|CFG_SSTR_IF_MIN, &config_generic, "( OLcfgAt:20 NAME 'olcIndexSubstrIfMinLen' " - "SYNTAX OMsInteger )", NULL, NULL }, + "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL }, { "index_substr_if_maxlen", "max", 2, 2, 0, ARG_INT|ARG_NONZERO|ARG_MAGIC|CFG_SSTR_IF_MAX, &config_generic, "( OLcfgAt:21 NAME 'olcIndexSubstrIfMaxLen' " - "SYNTAX OMsInteger )", NULL, NULL }, + "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL }, { "index_substr_any_len", "len", 2, 2, 0, ARG_INT|ARG_NONZERO, &index_substr_any_len, "( OLcfgAt:22 NAME 'olcIndexSubstrAnyLen' " - "SYNTAX OMsInteger )", NULL, NULL }, + "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL }, { "index_substr_step", "step", 2, 2, 0, ARG_INT|ARG_NONZERO, &index_substr_any_step, "( OLcfgAt:23 NAME 'olcIndexSubstrAnyStep' " - "SYNTAX OMsInteger )", NULL, NULL }, + "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL }, { "lastmod", "on|off", 2, 2, 0, ARG_DB|ARG_ON_OFF|ARG_MAGIC|CFG_LASTMOD, &config_generic, "( OLcfgAt:24 NAME 'olcLastMod' " - "SYNTAX OMsBoolean )", NULL, NULL }, + "SYNTAX OMsBoolean SINGLE-VALUE )", NULL, NULL }, { "limits", "limits", 2, 0, 0, ARG_DB|ARG_MAGIC|CFG_LIMITS, &config_generic, "( OLcfgAt:25 NAME 'olcLimits' " "SYNTAX OMsDirectoryString )", NULL, NULL }, - { "localSSF", "ssf", 2, 2, 0, ARG_LONG, + { "localSSF", "ssf", 2, 2, 0, ARG_INT, &local_ssf, "( OLcfgAt:26 NAME 'olcLocalSSF' " - "SYNTAX OMsInteger )", NULL, NULL }, + "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL }, { "logfile", "file", 2, 2, 0, ARG_STRING|ARG_MAGIC|CFG_LOGFILE, &config_generic, "( OLcfgAt:27 NAME 'olcLogFile' " - "SYNTAX OMsDirectoryString )", NULL, NULL }, + "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL }, { "loglevel", "level", 2, 0, 0, ARG_MAGIC, &config_loglevel, "( OLcfgAt:28 NAME 'olcLogLevel' " "SYNTAX OMsDirectoryString )", NULL, NULL }, { "maxDerefDepth", "depth", 2, 2, 0, ARG_DB|ARG_INT|ARG_MAGIC|CFG_DEPTH, &config_generic, "( OLcfgAt:29 NAME 'olcMaxDerefDepth' " - "SYNTAX OMsInteger )", NULL, NULL }, + "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL }, { "moduleload", "file", 2, 0, 0, #ifdef SLAPD_MODULES ARG_MAGIC|CFG_MODLOAD, &config_generic, @@ -309,7 +343,7 @@ ConfigTable config_back_cf_table[] = { ARG_IGNORED, NULL, #endif "( OLcfgAt:30 NAME 'olcModuleLoad' " - "SYNTAX OMsDirectoryString )", NULL, NULL }, + "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )", NULL, NULL }, { "modulepath", "path", 2, 2, 0, #ifdef SLAPD_MODULES ARG_MAGIC|CFG_MODPATH, &config_generic, @@ -317,25 +351,28 @@ ConfigTable config_back_cf_table[] = { ARG_IGNORED, NULL, #endif "( OLcfgAt:31 NAME 'olcModulePath' " - "SYNTAX OMsDirectoryString )", NULL, NULL }, - /* use standard schema */ + "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )", NULL, NULL }, { "objectclass", "objectclass", 2, 0, 0, ARG_PAREN|ARG_MAGIC|CFG_OC, - &config_generic, NULL, NULL, NULL }, + &config_generic, "( OLcfgAt: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, &config_generic, "( OLcfgAt:33 NAME 'olcObjectIdentifier' " - "SYNTAX OMsDirectoryString )", NULL, NULL }, + "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )", NULL, NULL }, { "overlay", "overlay", 2, 2, 0, ARG_MAGIC, &config_overlay, "( OLcfgAt:34 NAME 'olcOverlay' " - "SUP olcDatabase )", NULL, NULL }, + "SUP olcDatabase X-ORDERED 'SIBLINGS' )", NULL, NULL }, { "password-crypt-salt-format", "salt", 2, 2, 0, ARG_STRING|ARG_MAGIC|CFG_SALT, &config_generic, "( OLcfgAt:35 NAME 'olcPasswordCryptSaltFormat' " - "SYNTAX OMsDirectoryString )", NULL, NULL }, + "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL }, { "password-hash", "hash", 2, 2, 0, ARG_MAGIC, &config_passwd_hash, "( OLcfgAt:36 NAME 'olcPasswordHash' " "SYNTAX OMsDirectoryString )", NULL, NULL }, { "pidfile", "file", 2, 2, 0, ARG_STRING, &slapd_pid_file, "( OLcfgAt:37 NAME 'olcPidFile' " - "SYNTAX OMsDirectoryString )", NULL, NULL }, + "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL }, { "plugin", NULL, 0, 0, 0, #ifdef LDAP_SLAPI ARG_MAGIC|CFG_PLUGIN, &config_generic, @@ -351,28 +388,28 @@ ConfigTable config_back_cf_table[] = { ARG_IGNORED, NULL, #endif "( OLcfgAt:39 NAME 'olcPluginLogFile' " - "SYNTAX OMsDirectoryString )", NULL, NULL }, + "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL }, { "readonly", "on|off", 2, 2, 0, ARG_MAY_DB|ARG_ON_OFF|ARG_MAGIC|CFG_RO, &config_generic, "( OLcfgAt:40 NAME 'olcReadOnly' " - "SYNTAX OMsBoolean )", NULL, NULL }, + "SYNTAX OMsBoolean SINGLE-VALUE )", NULL, NULL }, { "referral", "url", 2, 2, 0, ARG_MAGIC, &config_referral, "( OLcfgAt:41 NAME 'olcReferral' " - "SUP labeledURI )", NULL, NULL }, + "SUP labeledURI SINGLE-VALUE )", NULL, NULL }, { "replica", "host or uri", 2, 0, 0, ARG_DB|ARG_MAGIC, &config_replica, "( OLcfgAt:42 NAME 'olcReplica' " "SUP labeledURI )", NULL, NULL }, { "replica-argsfile", NULL, 0, 0, 0, ARG_STRING, &replica_argsFile, "( OLcfgAt:43 NAME 'olcReplicaArgsFile' " - "SYNTAX OMsDirectoryString )", NULL, NULL }, + "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL }, { "replica-pidfile", NULL, 0, 0, 0, ARG_STRING, &replica_pidFile, "( OLcfgAt:44 NAME 'olcReplicaPidFile' " - "SYNTAX OMsDirectoryString )", NULL, NULL }, + "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL }, { "replicationInterval", NULL, 0, 0, 0, ARG_INT, &replicationInterval, "( OLcfgAt:45 NAME 'olcReplicationInterval' " - "SYNTAX OMsInteger )", NULL, NULL }, + "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL }, { "replogfile", "filename", 2, 2, 0, ARG_MAY_DB|ARG_MAGIC|ARG_STRING|CFG_REPLOG, &config_generic, "( OLcfgAt:46 NAME 'olcReplogFile' " - "SYNTAX OMsDirectoryString )", NULL, NULL }, + "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL }, { "require", "features", 2, 0, 7, ARG_MAY_DB|ARG_MAGIC, &config_requires, "( OLcfgAt:47 NAME 'olcRequires' " "SYNTAX OMsDirectoryString )", NULL, NULL }, @@ -386,16 +423,16 @@ ConfigTable config_back_cf_table[] = { ARG_IGNORED, NULL, #endif "( OLcfgAt:49 NAME 'olcReverseLookup' " - "SYNTAX OMsBoolean )", NULL, NULL }, + "SYNTAX OMsBoolean SINGLE-VALUE )", NULL, NULL }, { "rootdn", "dn", 2, 2, 0, ARG_DB|ARG_DN|ARG_MAGIC, &config_rootdn, "( OLcfgAt:50 NAME 'olcRootDN' " - "SYNTAX OMsDN )", NULL, NULL }, + "SYNTAX OMsDN SINGLE-VALUE )", NULL, NULL }, { "rootDSE", "file", 2, 2, 0, ARG_MAGIC|CFG_ROOTDSE, &config_generic, "( OLcfgAt:51 NAME 'olcRootDSE' " "SYNTAX OMsDirectoryString )", NULL, NULL }, - { "rootpw", "password", 2, 2, 0, ARG_STRING|ARG_DB|ARG_MAGIC, + { "rootpw", "password", 2, 2, 0, ARG_BERVAL|ARG_DB|ARG_MAGIC, &config_rootpw, "( OLcfgAt:52 NAME 'olcRootPW' " - "SYNTAX OMsOctetString )", NULL, NULL }, + "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL }, { "sasl-authz-policy", NULL, 2, 2, 0, ARG_MAGIC|CFG_AZPOLICY, &config_generic, NULL, NULL, NULL }, { "sasl-host", "host", 2, 2, 0, @@ -405,7 +442,7 @@ ConfigTable config_back_cf_table[] = { ARG_IGNORED, NULL, #endif "( OLcfgAt:53 NAME 'olcSaslHost' " - "SYNTAX OMsDirectoryString )", NULL, NULL }, + "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL }, { "sasl-realm", "realm", 2, 2, 0, #ifdef HAVE_CYRUS_SASL ARG_STRING|ARG_UNIQUE, &global_realm, @@ -413,7 +450,7 @@ ConfigTable config_back_cf_table[] = { ARG_IGNORED, NULL, #endif "( OLcfgAt:54 NAME 'olcSaslRealm' " - "SYNTAX OMsDirectoryString )", NULL, NULL }, + "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL }, { "sasl-regexp", NULL, 3, 3, 0, ARG_MAGIC|CFG_AZREGEXP, &config_generic, NULL, NULL, NULL }, { "sasl-secprops", "properties", 2, 2, 0, @@ -423,27 +460,27 @@ ConfigTable config_back_cf_table[] = { ARG_IGNORED, NULL, #endif "( OLcfgAt:56 NAME 'olcSaslSecProps' " - "SYNTAX OMsDirectoryString )", NULL, NULL }, + "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL }, { "saslRegexp", NULL, 3, 3, 0, ARG_MAGIC|CFG_AZREGEXP, &config_generic, NULL, NULL, NULL }, { "schemacheck", "on|off", 2, 2, 0, ARG_ON_OFF|ARG_MAGIC|CFG_CHECK, &config_generic, "( OLcfgAt:57 NAME 'olcSchemaCheck' " - "SYNTAX OMsBoolean )", NULL, NULL }, + "SYNTAX OMsBoolean SINGLE-VALUE )", NULL, NULL }, { "schemadn", "dn", 2, 2, 0, ARG_MAY_DB|ARG_DN|ARG_MAGIC, &config_schema_dn, "( OLcfgAt:58 NAME 'olcSchemaDN' " - "SYNTAX OMsDN )", NULL, NULL }, + "SYNTAX OMsDN SINGLE-VALUE )", NULL, NULL }, { "security", "factors", 2, 0, 0, ARG_MAY_DB|ARG_MAGIC, &config_security, "( OLcfgAt:59 NAME 'olcSecurity' " "SYNTAX OMsDirectoryString )", NULL, NULL }, { "sizelimit", "limit", 2, 0, 0, ARG_MAY_DB|ARG_MAGIC|CFG_SIZE, &config_sizelimit, "( OLcfgAt:60 NAME 'olcSizeLimit' " "SYNTAX OMsInteger )", NULL, NULL }, - { "sockbuf_max_incoming", "max", 2, 2, 0, ARG_LONG, + { "sockbuf_max_incoming", "max", 2, 2, 0, ARG_BER_LEN_T, &sockbuf_max_incoming, "( OLcfgAt:61 NAME 'olcSockbufMaxIncoming' " - "SYNTAX OMsInteger )", NULL, NULL }, - { "sockbuf_max_incoming_auth", "max", 2, 2, 0, ARG_LONG, + "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL }, + { "sockbuf_max_incoming_auth", "max", 2, 2, 0, ARG_BER_LEN_T, &sockbuf_max_incoming_auth, "( OLcfgAt:62 NAME 'olcSockbufMaxIncomingAuth' " - "SYNTAX OMsInteger )", NULL, NULL }, + "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL }, { "srvtab", "file", 2, 2, 0, #ifdef LDAP_API_FEATURE_X_OPENLDAP_V2_KBIND ARG_STRING, &ldap_srvtab, @@ -451,16 +488,16 @@ ConfigTable config_back_cf_table[] = { ARG_IGNORED, NULL, #endif "( OLcfgAt:63 NAME 'olcSrvtab' " - "SYNTAX OMsDirectoryString )", NULL, NULL }, + "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL }, { "suffix", "suffix", 2, 2, 0, ARG_DB|ARG_DN|ARG_MAGIC, &config_suffix, "( OLcfgAt:64 NAME 'olcSuffix' " "SYNTAX OMsDN )", NULL, NULL }, { "syncrepl", NULL, 0, 0, 0, ARG_DB|ARG_MAGIC, &config_syncrepl, "( OLcfgAt:65 NAME 'olcSyncrepl' " - "SYNTAX OMsDirectoryString )", NULL, NULL }, + "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL }, { "threads", "count", 2, 2, 0, ARG_INT|ARG_MAGIC|CFG_THREADS, &config_generic, "( OLcfgAt:66 NAME 'olcThreads' " - "SYNTAX OMsInteger )", NULL, NULL }, + "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL }, { "timelimit", "limit", 2, 0, 0, ARG_MAY_DB|ARG_MAGIC|CFG_TIME, &config_timelimit, "( OLcfgAt:67 NAME 'olcTimeLimit' " "SYNTAX OMsInteger )", NULL, NULL }, @@ -471,7 +508,7 @@ ConfigTable config_back_cf_table[] = { ARG_IGNORED, NULL, #endif "( OLcfgAt:68 NAME 'olcTLSCACertificateFile' " - "SYNTAX OMsDirectoryString )", NULL, NULL }, + "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL }, { "TLSCACertificatePath", NULL, 0, 0, 0, #ifdef HAVE_TLS CFG_TLS_CA_PATH|ARG_STRING|ARG_MAGIC, &config_tls_option, @@ -479,7 +516,7 @@ ConfigTable config_back_cf_table[] = { ARG_IGNORED, NULL, #endif "( OLcfgAt:69 NAME 'olcTLSCACertificatePath' " - "SYNTAX OMsDirectoryString )", NULL, NULL }, + "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL }, { "TLSCertificateFile", NULL, 0, 0, 0, #ifdef HAVE_TLS CFG_TLS_CERT_FILE|ARG_STRING|ARG_MAGIC, &config_tls_option, @@ -487,7 +524,7 @@ ConfigTable config_back_cf_table[] = { ARG_IGNORED, NULL, #endif "( OLcfgAt:70 NAME 'olcTLSCertificateFile' " - "SYNTAX OMsDirectoryString )", NULL, NULL }, + "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL }, { "TLSCertificateKeyFile", NULL, 0, 0, 0, #ifdef HAVE_TLS CFG_TLS_CERT_KEY|ARG_STRING|ARG_MAGIC, &config_tls_option, @@ -495,7 +532,7 @@ ConfigTable config_back_cf_table[] = { ARG_IGNORED, NULL, #endif "( OLcfgAt:71 NAME 'olcTLSCertificateKeyFile' " - "SYNTAX OMsDirectoryString )", NULL, NULL }, + "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL }, { "TLSCipherSuite", NULL, 0, 0, 0, #ifdef HAVE_TLS CFG_TLS_CIPHER|ARG_STRING|ARG_MAGIC, &config_tls_option, @@ -503,15 +540,15 @@ ConfigTable config_back_cf_table[] = { ARG_IGNORED, NULL, #endif "( OLcfgAt:72 NAME 'olcTLSCipherSuite' " - "SYNTAX OMsDirectoryString )", NULL, NULL }, + "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL }, { "TLSCRLCheck", NULL, 0, 0, 0, -#ifdef HAVE_TLS +#if defined(HAVE_TLS) && defined(HAVE_OPENSSL_CRL) CFG_TLS_CRLCHECK|ARG_STRING|ARG_MAGIC, &config_tls_config, #else ARG_IGNORED, NULL, #endif "( OLcfgAt:73 NAME 'olcTLSCRLCheck' " - "SYNTAX OMsDirectoryString )", NULL, NULL }, + "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL }, { "TLSRandFile", NULL, 0, 0, 0, #ifdef HAVE_TLS CFG_TLS_RAND|ARG_STRING|ARG_MAGIC, &config_tls_option, @@ -519,7 +556,7 @@ ConfigTable config_back_cf_table[] = { ARG_IGNORED, NULL, #endif "( OLcfgAt:74 NAME 'olcTLSRandFile' " - "SYNTAX OMsDirectoryString )", NULL, NULL }, + "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL }, { "TLSVerifyClient", NULL, 0, 0, 0, #ifdef HAVE_TLS CFG_TLS_VERIFY|ARG_STRING|ARG_MAGIC, &config_tls_config, @@ -527,12 +564,12 @@ ConfigTable config_back_cf_table[] = { ARG_IGNORED, NULL, #endif "( OLcfgAt:75 NAME 'olcTLSVerifyClient' " - "SYNTAX OMsDirectoryString )", NULL, NULL }, + "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL }, { "ucdata-path", "path", 2, 2, 0, ARG_IGNORED, NULL, NULL, NULL, NULL }, { "updatedn", "dn", 2, 2, 0, ARG_DB|ARG_MAGIC, &config_updatedn, "( OLcfgAt:76 NAME 'olcUpdateDN' " - "SYNTAX OMsDN )", NULL, NULL }, + "SYNTAX OMsDN SINGLE-VALUE )", NULL, NULL }, { "updateref", "url", 2, 2, 0, ARG_DB|ARG_MAGIC, &config_updateref, "( OLcfgAt:77 NAME 'olcUpdateRef' " "SUP labeledURI )", NULL, NULL }, @@ -544,56 +581,76 @@ static ConfigOCs cf_ocs[] = { { "( OLcfgOc:1 " "NAME 'olcConfig' " "DESC 'OpenLDAP configuration object' " - "ABSTRACT SUP top " - "MAY ( cn $ olcConfigFile ) )", NULL }, - { "( OLcfgOc:3 " + "ABSTRACT SUP top )", Cft_Abstract, NULL }, + { "( OLcfgOc:2 " "NAME 'olcGlobal' " "DESC 'OpenLDAP Global configuration options' " "SUP olcConfig STRUCTURAL " - "MAY ( olcAccess $ olcAllows $ olcArgsFile $ olcAttributeOptions $ " - "olcAuthIDRewrite $ olcAuthzPolicy $ olcAuthzRegexp $ " - "olcConcurrency $ olcConnMaxPending $ olcConnMaxPendingAuth $ " - "olcDefaultSearchBase $ olcDisallows $ olcGentleHUP $ " - "olcIdleTimeout $ olcIndexSubstrIfMaxLen $ olcIndexSubstrIfMinLen $ " + "MAY ( cn $ olcConfigFile $ olcConfigDir $ olcAllows $ olcArgsFile $ " + "olcAttributeOptions $ olcAttributeTypes $ olcAuthIDRewrite $ " + "olcAuthzPolicy $ olcAuthzRegexp $ olcConcurrency $ " + "olcConnMaxPending $ olcConnMaxPendingAuth $ olcDefaultSearchBase $ " + "olcDisallows $ olcDitContentRules $ olcGentleHUP $ olcIdleTimeout $ " + "olcIndexSubstrIfMaxLen $ olcIndexSubstrIfMinLen $ " "olcIndexSubstrAnyLen $ olcIndexSubstrAnyStep $ olcLocalSSF $ " - "olcLogLevel $ olcModuleLoad $ olcModulePath $ olcObjectIdentifier $ " + "olcLogLevel $ olcModulePath $ olcObjectClasses $ " + "olcObjectIdentifier $ " "olcPasswordCryptSaltFormat $ olcPasswordHash $ olcPidFile $ " "olcPlugin $ olcPluginLogFile $ olcReadOnly $ olcReferral $ " "olcReplicaPidFile $ olcReplicaArgsFile $ olcReplicationInterval $ " "olcReplogFile $ olcRequires $ olcRestrict $ olcReverseLookup $ " - "olcRootDSE $ olcSaslHost $ olcSaslRealm $ olcSaslSecProps $ " + "olcRootDSE $ olcRootPW $ " + "olcSaslHost $ olcSaslRealm $ olcSaslSecProps $ " "olcSchemaCheck $ olcSchemaDN $ olcSecurity $ olcSizeLimit $ " "olcSockbufMaxIncoming $ olcSockbufMaxIncomingAuth $ olcSrvtab $ " "olcThreads $ olcTimeLimit $ olcTLSCACertificateFile $ " "olcTLSCACertificatePath $ olcTLSCertificateFile $ " "olcTLSCertificateKeyFile $ olcTLSCipherSuite $ olcTLSCRLCheck $ " - "olcTLSRandFile $ olcTLSVerifyClient ) )", &cfOc_global }, + "olcTLSRandFile $ olcTLSVerifyClient ) )", Cft_Global, &cfOc_global }, + { "( OLcfgOc:3 " + "NAME 'olcSchemaConfig' " + "DESC 'OpenLDAP schema object' " + "SUP olcConfig STRUCTURAL " + "MAY ( cn $ olcObjectIdentifier $ olcAttributeTypes $ " + "olcObjectClasses $ olcDitContentRules ) )", + Cft_Schema, &cfOc_schema }, { "( OLcfgOc:4 " "NAME 'olcBackendConfig' " "DESC 'OpenLDAP Backend-specific options' " "SUP olcConfig STRUCTURAL " - "MAY ( olcBackend ) )", &cfOc_backend }, + "MUST olcBackend )", Cft_Backend, &cfOc_backend }, { "( OLcfgOc:5 " "NAME 'olcDatabaseConfig' " "DESC 'OpenLDAP Database-specific options' " "SUP olcConfig STRUCTURAL " - "MAY ( olcAccess $ olcDatabase $ olcLastMod $ olcLimits $ " + "MUST olcDatabase " + "MAY ( olcSuffix $ olcAccess $ olcLastMod $ olcLimits $ " "olcMaxDerefDepth $ olcPlugin $ olcReadOnly $ olcReplica $ " "olcReplogFile $ olcRequires $ olcRestrict $ olcRootDN $ olcRootPW $ " - "olcSchemaDN $ olcSecurity $ olcSizeLimit $ olcSuffix $ olcSyncrepl $ " - "olcTimeLimit $ olcUpdateDN $ olcUpdateRef ) )", &cfOc_database }, + "olcSchemaDN $ olcSecurity $ olcSizeLimit $ olcSyncrepl $ " + "olcTimeLimit $ olcUpdateDN $ olcUpdateRef ) )", + Cft_Database, &cfOc_database }, { "( OLcfgOc:6 " + "NAME 'olcOverlayConfig' " + "DESC 'OpenLDAP Overlay-specific options' " + "SUP olcConfig STRUCTURAL " + "MUST olcOverlay )", Cft_Overlay, &cfOc_overlay }, + { "( OLcfgOc:7 " "NAME 'olcIncludeFile' " "DESC 'OpenLDAP configuration include file' " "SUP olcConfig STRUCTURAL " - "MAY ( olcInclude $ olcModuleLoad $ olcModulePath $ olcRootDSE ) )", - &cfOc_include }, - { "( OLcfgOc:7 " - "NAME 'olcOverlayConfig' " - "DESC 'OpenLDAP Overlay-specific options' " + "MUST olcInclude " + "MAY ( cn $ olcRootDSE ) )", + Cft_Include, &cfOc_include }, +#ifdef SLAPD_MODULES + { "( OLcfgOc:8 " + "NAME 'olcModuleList' " + "DESC 'OpenLDAP dynamic module info' " "SUP olcConfig STRUCTURAL " - "MAY ( olcOverlay ) )", &cfOc_overlay }, - { NULL, NULL } + "MUST olcModuleLoad " + "MAY cn )", Cft_Module, &cfOc_module }, +#endif + { NULL, 0, NULL } }; static int @@ -601,7 +658,7 @@ config_generic(ConfigArgs *c) { char *p; int i; - if ( c->emit ) { + if ( c->op == SLAP_CONFIG_EMIT ) { int rc = 0; switch(c->type) { case CFG_CONCUR: @@ -623,7 +680,7 @@ config_generic(ConfigArgs *c) { int i; for ( i=0; c->be->be_limits[i]; i++ ) { - bv.bv_len = sprintf( buf, "{%d}", i ); + bv.bv_len = sprintf( buf, IFMT, i ); bv.bv_val = buf+bv.bv_len; limits_unparse( c->be->be_limits[i], &bv ); bv.bv_len += bv.bv_val - buf; @@ -658,11 +715,51 @@ config_generic(ConfigArgs *c) { case CFG_DEPTH: c->value_int = c->be->be_max_deref_depth; break; - case CFG_OID: - oidm_unparse( &c->rvalue_vals ); + case CFG_OID: { + ConfigFile *cf = c->private; + if ( !cf ) + oidm_unparse( &c->rvalue_vals, NULL, NULL, 1 ); + else if ( cf->c_om_head ) + oidm_unparse( &c->rvalue_vals, cf->c_om_head, + cf->c_om_tail, 0 ); + if ( !c->rvalue_vals ) + rc = 1; + } + break; + case CFG_OC: { + ConfigFile *cf = c->private; + if ( !cf ) + oc_unparse( &c->rvalue_vals, NULL, NULL, 1 ); + else if ( cf->c_oc_head ) + oc_unparse( &c->rvalue_vals, cf->c_oc_head, + cf->c_oc_tail, 0 ); + if ( !c->rvalue_vals ) + rc = 1; + } + break; + case CFG_ATTR: { + ConfigFile *cf = c->private; + if ( !cf ) + at_unparse( &c->rvalue_vals, NULL, NULL, 1 ); + else if ( cf->c_at_head ) + at_unparse( &c->rvalue_vals, cf->c_at_head, + cf->c_at_tail, 0 ); + if ( !c->rvalue_vals ) + rc = 1; + } + break; + case CFG_DIT: { + ConfigFile *cf = c->private; + if ( !cf ) + cr_unparse( &c->rvalue_vals, NULL, NULL, 1 ); + else if ( cf->c_cr_head ) + cr_unparse( &c->rvalue_vals, cf->c_cr_head, + cf->c_cr_tail, 0 ); if ( !c->rvalue_vals ) rc = 1; + } break; + case CFG_CHECK: c->value_int = global_schemacheck; break; @@ -671,7 +768,7 @@ config_generic(ConfigArgs *c) { char *src, *dst, ibuf[11]; struct berval bv, abv; for (i=0, a=c->be->be_acl; a; i++,a=a->acl_next) { - abv.bv_len = sprintf( ibuf, "{%x}", i ); + abv.bv_len = sprintf( ibuf, IFMT, i ); acl_unparse( a, &bv ); abv.bv_val = ch_malloc( abv.bv_len + bv.bv_len + 1 ); AC_MEMCPY( abv.bv_val, ibuf, abv.bv_len ); @@ -696,7 +793,7 @@ config_generic(ConfigArgs *c) { c->value_string = ch_strdup( c->be->be_replogfile ); break; case CFG_ROOTDSE: { - ConfigFile *cf = (ConfigFile *)c->line; + ConfigFile *cf = c->private; if ( cf->c_dseFiles ) { value_add( &c->rvalue_vals, cf->c_dseFiles ); } else { @@ -721,31 +818,29 @@ config_generic(ConfigArgs *c) { break; #ifdef SLAPD_MODULES case CFG_MODLOAD: { - ConfigFile *cf = (ConfigFile *)c->line; - ModPaths *mp; - for (i=0, mp=&cf->c_modpaths; mp; mp=mp->mp_next, i++) { - int j; - if (!mp->mp_loads) continue; - for (j=0; !BER_BVISNULL(&mp->mp_loads[j]); j++) { + ModPaths *mp = c->private; + if (mp->mp_loads) { + int i; + for (i=0; !BER_BVISNULL(&mp->mp_loads[i]); i++) { struct berval bv; bv.bv_val = c->log; - bv.bv_len = sprintf( bv.bv_val, "{%d}{%d}%s", i, j, - mp->mp_loads[j].bv_val ); + bv.bv_len = sprintf( bv.bv_val, IFMT "%s", i, + mp->mp_loads[i].bv_val ); value_add_one( &c->rvalue_vals, &bv ); } } + rc = c->rvalue_vals ? 0 : 1; } break; case CFG_MODPATH: { - ConfigFile *cf = (ConfigFile *)c->line; ModPaths *mp; - for (i=0, mp=&cf->c_modpaths; mp; mp=mp->mp_next, i++) { + for (i=0, mp=&modpaths; mp; mp=mp->mp_next, i++) { struct berval bv; if ( BER_BVISNULL( &mp->mp_path ) && !mp->mp_loads ) continue; bv.bv_val = c->log; - bv.bv_len = sprintf( bv.bv_val, "{%d}%s", i, + bv.bv_len = sprintf( bv.bv_val, IFMT "%s", i, mp->mp_path.bv_val ); value_add_one( &c->rvalue_vals, &bv ); } @@ -768,7 +863,7 @@ config_generic(ConfigArgs *c) { idx.bv_val = ibuf; for ( i=0; !BER_BVISNULL( &authz_rewrites[i] ); i++ ) { - idx.bv_len = sprintf( idx.bv_val, "{%d}", i ); + idx.bv_len = sprintf( idx.bv_val, IFMT, i ); bv.bv_len = idx.bv_len + authz_rewrites[i].bv_len; bv.bv_val = ch_malloc( bv.bv_len + 1 ); strcpy( bv.bv_val, idx.bv_val ); @@ -786,6 +881,19 @@ config_generic(ConfigArgs *c) { } p = strchr(c->line,'(' /*')'*/); + if ( c->op == LDAP_MOD_DELETE ) { + int rc = 0; + switch(c->type) { + case CFG_BACKEND: + case CFG_DATABASE: + rc = 1; + break; + case CFG_CONCUR: + ldap_pvt_thread_set_concurrency(c); + break; + + } + } switch(c->type) { case CFG_BACKEND: if(!(c->bi = backend_info(c->argv[1]))) { @@ -800,7 +908,9 @@ config_generic(ConfigArgs *c) { /* NOTE: config is always the first backend! */ if ( !strcasecmp( c->argv[1], "config" )) { - c->be = backendDB; + c->be = LDAP_STAILQ_FIRST(&backendDB); + } else if ( !strcasecmp( c->argv[1], "frontend" )) { + c->be = frontendDB; } else if(!(c->be = backend_db_init(c->argv[1]))) { Debug(LDAP_DEBUG_ANY, "%s: " "database %s failed init!\n", c->log, c->argv[1], 0); @@ -867,20 +977,41 @@ config_generic(ConfigArgs *c) { c->be->be_max_deref_depth = c->value_int; break; - case CFG_OID: - if(parse_oidm(c->fname, c->lineno, c->argc, c->argv)) return(1); + case CFG_OID: { + OidMacro *om; + + if(parse_oidm(c->fname, c->lineno, c->argc, c->argv, 1, &om)) + return(1); + if (!cfn->c_om_head) cfn->c_om_head = om; + cfn->c_om_tail = om; + } break; - case CFG_OC: - if(parse_oc(c->fname, c->lineno, p, c->argv)) return(1); + case CFG_OC: { + ObjectClass *oc; + + if(parse_oc(c->fname, c->lineno, p, c->argv, &oc)) return(1); + if (!cfn->c_oc_head) cfn->c_oc_head = oc; + cfn->c_oc_tail = oc; + } break; - case CFG_DIT: - if(parse_cr(c->fname, c->lineno, p, c->argv)) return(1); + case CFG_DIT: { + ContentRule *cr; + + 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; + } break; - case CFG_ATTR: - if(parse_at(c->fname, c->lineno, p, c->argv)) return(1); + case CFG_ATTR: { + AttributeType *at; + + 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; + } break; case CFG_ATOPT: @@ -975,8 +1106,11 @@ config_generic(ConfigArgs *c) { /* Record this load on the current path */ { struct berval bv; - ber_str2bv(c->line, 0, 1, &bv); - ber_bvarray_add( &cfn->c_modlast->mp_loads, &bv ); + char *ptr = c->line + STRLENOF("moduleload"); + while (!isspace(*ptr)) ptr++; + while (isspace(*ptr)) ptr++; + ber_str2bv(ptr, 0, 1, &bv); + ber_bvarray_add( &modcur->mp_loads, &bv ); } break; @@ -986,16 +1120,18 @@ config_generic(ConfigArgs *c) { { ModPaths *mp; - if (!cfn->c_modpaths.mp_loads) { - mp = &cfn->c_modpaths; + if (!modpaths.mp_loads) { + mp = &modpaths; } else { mp = ch_malloc( sizeof( ModPaths )); - cfn->c_modlast->mp_next = mp; + modlast->mp_next = mp; } ber_str2bv(c->argv[1], 0, 1, &mp->mp_path); mp->mp_next = NULL; mp->mp_loads = NULL; - cfn->c_modlast = mp; + modlast = mp; + if ( c->op == SLAP_CONFIG_ADD ) + modcur = mp; } break; @@ -1032,19 +1168,31 @@ config_generic(ConfigArgs *c) { static int config_fname(ConfigArgs *c) { - if(c->emit && c->line) { - ConfigFile *cf = (ConfigFile *)c->line; - value_add_one( &c->rvalue_vals, &cf->c_file ); + if(c->op == SLAP_CONFIG_EMIT) { + if (c->private) { + ConfigFile *cf = c->private; + value_add_one( &c->rvalue_vals, &cf->c_file ); + return 0; + } + return 1; + } + return(0); +} + +static int +config_cfdir(ConfigArgs *c) { + if(c->op == SLAP_CONFIG_EMIT) { + value_add_one( &c->rvalue_vals, &cfdir ); return 0; } - return(1); + return(0); } static int config_search_base(ConfigArgs *c) { struct berval dn; - if(c->emit) { + if(c->op == SLAP_CONFIG_EMIT) { int rc = 1; if (!BER_BVISEMPTY(&default_search_base)) { value_add_one(&c->rvalue_vals, &default_search_base); @@ -1078,7 +1226,7 @@ config_search_base(ConfigArgs *c) { static int config_passwd_hash(ConfigArgs *c) { int i; - if (c->emit) { + if (c->op == SLAP_CONFIG_EMIT) { struct berval bv; for (i=0; default_passwd_hash && default_passwd_hash[i]; i++) { ber_str2bv(default_passwd_hash[i], 0, 0, &bv); @@ -1111,12 +1259,14 @@ config_passwd_hash(ConfigArgs *c) { static int config_schema_dn(ConfigArgs *c) { - struct berval dn; - int rc; - if ( c->emit ) { - value_add_one(&c->rvalue_vals, &c->be->be_schemadn); - value_add_one(&c->rvalue_nvals, &c->be->be_schemandn); - return 0; + if ( c->op == SLAP_CONFIG_EMIT ) { + int rc = 1; + if ( !BER_BVISEMPTY( &c->be->be_schemadn )) { + value_add_one(&c->rvalue_vals, &c->be->be_schemadn); + value_add_one(&c->rvalue_nvals, &c->be->be_schemandn); + rc = 0; + } + return rc; } c->be->be_schemadn = c->value_dn; c->be->be_schemandn = c->value_ndn; @@ -1128,7 +1278,7 @@ config_sizelimit(ConfigArgs *c) { int i, rc = 0; char *next; struct slap_limits_set *lim = &c->be->be_def_limit; - if (c->emit) { + if (c->op == SLAP_CONFIG_EMIT) { char buf[8192]; struct berval bv; bv.bv_val = buf; @@ -1176,7 +1326,7 @@ config_timelimit(ConfigArgs *c) { int i, rc = 0; char *next; struct slap_limits_set *lim = &c->be->be_def_limit; - if (c->emit) { + if (c->op == SLAP_CONFIG_EMIT) { char buf[8192]; struct berval bv; bv.bv_val = buf; @@ -1221,7 +1371,7 @@ config_timelimit(ConfigArgs *c) { static int config_overlay(ConfigArgs *c) { - if (c->emit) { + if (c->op == SLAP_CONFIG_EMIT) { return 1; } if(c->argv[1][0] == '-' && overlay_config(c->be, &c->argv[1][1])) { @@ -1239,8 +1389,12 @@ config_suffix(ConfigArgs *c) { Backend *tbe; struct berval pdn, ndn; int rc; - if (c->emit) { - if ( !BER_BVISNULL( &c->be->be_suffix[0] )) { + + if (c->be == frontendDB || SLAP_MONITOR(c->be) || + SLAP_CONFIG(c->be)) return 1; + + if (c->op == SLAP_CONFIG_EMIT) { + if (!BER_BVISNULL( &c->be->be_suffix[0] )) { value_add( &c->rvalue_vals, c->be->be_suffix ); value_add( &c->rvalue_nvals, c->be->be_nsuffix ); return 0; @@ -1283,7 +1437,7 @@ config_suffix(ConfigArgs *c) { static int config_rootdn(ConfigArgs *c) { - if (c->emit) { + if (c->op == SLAP_CONFIG_EMIT) { if ( !BER_BVISNULL( &c->be->be_rootdn )) { value_add_one(&c->rvalue_vals, &c->be->be_rootdn); value_add_one(&c->rvalue_nvals, &c->be->be_rootndn); @@ -1300,9 +1454,9 @@ config_rootdn(ConfigArgs *c) { static int config_rootpw(ConfigArgs *c) { Backend *tbe; - if (c->emit) { + if (c->op == SLAP_CONFIG_EMIT) { if (!BER_BVISEMPTY(&c->be->be_rootpw)) { - c->value_string=ch_strdup("*"); + ber_dupbv( &c->value_bv, &c->be->be_rootpw); return 0; } return 1; @@ -1315,7 +1469,7 @@ config_rootpw(ConfigArgs *c) { c->log, 0, 0); return(1); } - ber_str2bv(c->value_string, 0, 0, &c->be->be_rootpw); + c->be->be_rootpw = c->value_bv; return(0); } @@ -1323,29 +1477,30 @@ static int config_restrict(ConfigArgs *c) { slap_mask_t restrictops = 0; int i; - struct verb_mask_list restrictable_ops[] = { - { "bind", SLAP_RESTRICT_OP_BIND }, - { "add", SLAP_RESTRICT_OP_ADD }, - { "modify", SLAP_RESTRICT_OP_MODIFY }, - { "rename", SLAP_RESTRICT_OP_RENAME }, - { "modrdn", 0 }, - { "delete", SLAP_RESTRICT_OP_DELETE }, - { "search", SLAP_RESTRICT_OP_SEARCH }, - { "compare", SLAP_RESTRICT_OP_COMPARE }, - { "read", SLAP_RESTRICT_OP_READS }, - { "write", SLAP_RESTRICT_OP_WRITES }, - { "extended", SLAP_RESTRICT_OP_EXTENDED }, - { "extended=" LDAP_EXOP_START_TLS, SLAP_RESTRICT_EXOP_START_TLS }, - { "extended=" LDAP_EXOP_MODIFY_PASSWD, SLAP_RESTRICT_EXOP_MODIFY_PASSWD }, - { "extended=" LDAP_EXOP_X_WHO_AM_I, SLAP_RESTRICT_EXOP_WHOAMI }, - { "extended=" LDAP_EXOP_X_CANCEL, SLAP_RESTRICT_EXOP_CANCEL }, - { NULL, 0 } + slap_verbmasks restrictable_ops[] = { + { BER_BVC("bind"), SLAP_RESTRICT_OP_BIND }, + { BER_BVC("add"), SLAP_RESTRICT_OP_ADD }, + { BER_BVC("modify"), SLAP_RESTRICT_OP_MODIFY }, + { BER_BVC("rename"), SLAP_RESTRICT_OP_RENAME }, + { BER_BVC("modrdn"), 0 }, + { BER_BVC("delete"), SLAP_RESTRICT_OP_DELETE }, + { BER_BVC("search"), SLAP_RESTRICT_OP_SEARCH }, + { 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=" 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 }, + { BER_BVC("extended=" LDAP_EXOP_X_CANCEL ), SLAP_RESTRICT_EXOP_CANCEL }, + { BER_BVNULL, 0 } }; - if (c->emit) { - return mask_to_verbs( c, restrictable_ops, c->be->be_restrictops ); + if (c->op == SLAP_CONFIG_EMIT) { + return mask_to_verbs( restrictable_ops, c->be->be_restrictops, + &c->rvalue_vals ); } - i = verbs_to_mask( c, restrictable_ops, &restrictops ); + i = verbs_to_mask( c->argc, c->argv, restrictable_ops, &restrictops ); if ( i ) { Debug(LDAP_DEBUG_ANY, "%s: " "unknown operation %s in \"restrict \" line\n", @@ -1362,17 +1517,17 @@ static int config_allows(ConfigArgs *c) { slap_mask_t allows = 0; int i; - struct verb_mask_list allowable_ops[] = { - { "bind_v2", SLAP_ALLOW_BIND_V2 }, - { "bind_anon_cred", SLAP_ALLOW_BIND_ANON_CRED }, - { "bind_anon_dn", SLAP_ALLOW_BIND_ANON_DN }, - { "update_anon", SLAP_ALLOW_UPDATE_ANON }, - { NULL, 0 } + slap_verbmasks allowable_ops[] = { + { BER_BVC("bind_v2"), SLAP_ALLOW_BIND_V2 }, + { BER_BVC("bind_anon_cred"), SLAP_ALLOW_BIND_ANON_CRED }, + { BER_BVC("bind_anon_dn"), SLAP_ALLOW_BIND_ANON_DN }, + { BER_BVC("update_anon"), SLAP_ALLOW_UPDATE_ANON }, + { BER_BVNULL, 0 } }; - if (c->emit) { - return mask_to_verbs( c, allowable_ops, global_allows ); + if (c->op == SLAP_CONFIG_EMIT) { + return mask_to_verbs( allowable_ops, global_allows, &c->rvalue_vals ); } - i = verbs_to_mask(c, allowable_ops, &allows); + i = verbs_to_mask(c->argc, c->argv, allowable_ops, &allows); if ( i ) { Debug(LDAP_DEBUG_ANY, "%s: " "unknown feature %s in \"allow \" line\n", @@ -1387,18 +1542,18 @@ static int config_disallows(ConfigArgs *c) { slap_mask_t disallows = 0; int i; - struct verb_mask_list disallowable_ops[] = { - { "bind_anon", SLAP_DISALLOW_BIND_ANON }, - { "bind_simple", SLAP_DISALLOW_BIND_SIMPLE }, - { "bind_krb4", SLAP_DISALLOW_BIND_KRBV4 }, - { "tls_2_anon", SLAP_DISALLOW_TLS_2_ANON }, - { "tls_authc", SLAP_DISALLOW_TLS_AUTHC }, - { NULL, 0 } + slap_verbmasks disallowable_ops[] = { + { BER_BVC("bind_anon"), SLAP_DISALLOW_BIND_ANON }, + { BER_BVC("bind_simple"), SLAP_DISALLOW_BIND_SIMPLE }, + { BER_BVC("bind_krb4"), SLAP_DISALLOW_BIND_KRBV4 }, + { BER_BVC("tls_2_anon"), SLAP_DISALLOW_TLS_2_ANON }, + { BER_BVC("tls_authc"), SLAP_DISALLOW_TLS_AUTHC }, + { BER_BVNULL, 0 } }; - if (c->emit) { - return mask_to_verbs( c, disallowable_ops, global_disallows ); + if (c->op == SLAP_CONFIG_EMIT) { + return mask_to_verbs( disallowable_ops, global_disallows, &c->rvalue_vals ); } - i = verbs_to_mask(c, disallowable_ops, &disallows); + i = verbs_to_mask(c->argc, c->argv, disallowable_ops, &disallows); if ( i ) { Debug(LDAP_DEBUG_ANY, "%s: " "unknown feature %s in \"disallow \" line\n", @@ -1413,18 +1568,18 @@ static int config_requires(ConfigArgs *c) { slap_mask_t requires = 0; int i; - struct verb_mask_list requires_ops[] = { - { "bind", SLAP_REQUIRE_BIND }, - { "LDAPv3", SLAP_REQUIRE_LDAP_V3 }, - { "authc", SLAP_REQUIRE_AUTHC }, - { "sasl", SLAP_REQUIRE_SASL }, - { "strong", SLAP_REQUIRE_STRONG }, - { NULL, 0 } + slap_verbmasks requires_ops[] = { + { BER_BVC("bind"), SLAP_REQUIRE_BIND }, + { BER_BVC("LDAPv3"), SLAP_REQUIRE_LDAP_V3 }, + { BER_BVC("authc"), SLAP_REQUIRE_AUTHC }, + { BER_BVC("sasl"), SLAP_REQUIRE_SASL }, + { BER_BVC("strong"), SLAP_REQUIRE_STRONG }, + { BER_BVNULL, 0 } }; - if (c->emit) { - return mask_to_verbs( c, requires_ops, c->be->be_requires ); + if (c->op == SLAP_CONFIG_EMIT) { + return mask_to_verbs( requires_ops, c->be->be_requires, &c->rvalue_vals ); } - i = verbs_to_mask(c, requires_ops, &requires); + i = verbs_to_mask(c->argc, c->argv, requires_ops, &requires); if ( i ) { Debug(LDAP_DEBUG_ANY, "%s: " "unknown feature %s in \"require \" line\n", @@ -1439,27 +1594,27 @@ static int config_loglevel(ConfigArgs *c) { int i; char *next; - struct verb_mask_list loglevel_ops[] = { - { "Trace", LDAP_DEBUG_TRACE }, - { "Packets", LDAP_DEBUG_PACKETS }, - { "Args", LDAP_DEBUG_ARGS }, - { "Conns", LDAP_DEBUG_CONNS }, - { "BER", LDAP_DEBUG_BER }, - { "Filter", LDAP_DEBUG_FILTER }, - { "Config", LDAP_DEBUG_CONFIG }, - { "ACL", LDAP_DEBUG_ACL }, - { "Stats", LDAP_DEBUG_STATS }, - { "Stats2", LDAP_DEBUG_STATS2 }, - { "Shell", LDAP_DEBUG_SHELL }, - { "Parse", LDAP_DEBUG_PARSE }, - { "Cache", LDAP_DEBUG_CACHE }, - { "Index", LDAP_DEBUG_INDEX }, - { "Any", -1 }, - { NULL, 0 } + slap_verbmasks loglevel_ops[] = { + { BER_BVC("Trace"), LDAP_DEBUG_TRACE }, + { BER_BVC("Packets"), LDAP_DEBUG_PACKETS }, + { BER_BVC("Args"), LDAP_DEBUG_ARGS }, + { BER_BVC("Conns"), LDAP_DEBUG_CONNS }, + { BER_BVC("BER"), LDAP_DEBUG_BER }, + { BER_BVC("Filter"), LDAP_DEBUG_FILTER }, + { BER_BVC("Config"), LDAP_DEBUG_CONFIG }, + { BER_BVC("ACL"), LDAP_DEBUG_ACL }, + { BER_BVC("Stats"), LDAP_DEBUG_STATS }, + { BER_BVC("Stats2"), LDAP_DEBUG_STATS2 }, + { BER_BVC("Shell"), LDAP_DEBUG_SHELL }, + { BER_BVC("Parse"), LDAP_DEBUG_PARSE }, + { BER_BVC("Cache"), LDAP_DEBUG_CACHE }, + { BER_BVC("Index"), LDAP_DEBUG_INDEX }, + { BER_BVC("Any"), -1 }, + { BER_BVNULL, 0 } }; - if (c->emit) { - return mask_to_verbs( c, loglevel_ops, ldap_syslog ); + if (c->op == SLAP_CONFIG_EMIT) { + return mask_to_verbs( loglevel_ops, ldap_syslog, &c->rvalue_vals ); } ldap_syslog = 0; @@ -1477,8 +1632,8 @@ config_loglevel(ConfigArgs *c) { return( 1 ); } } else { - int j = verb_to_mask(c, loglevel_ops, c->argv[i][0]); - if(!loglevel_ops[j].word) { + int j = verb_to_mask(c->argv[i], loglevel_ops); + if(BER_BVISNULL(&loglevel_ops[j].word)) { Debug( LDAP_DEBUG_ANY, "%s: unknown level \"%s\" " "in \"loglevel [...]\" line.\n", @@ -1494,7 +1649,7 @@ config_loglevel(ConfigArgs *c) { static int config_syncrepl(ConfigArgs *c) { - if (c->emit) { + if (c->op == SLAP_CONFIG_EMIT) { if ( c->be->be_syncinfo ) { struct berval bv; syncrepl_unparse( c->be->be_syncinfo, &bv ); @@ -1518,7 +1673,7 @@ config_syncrepl(ConfigArgs *c) { static int config_referral(ConfigArgs *c) { struct berval vals[2]; - if (c->emit) { + if (c->op == SLAP_CONFIG_EMIT) { if ( default_referral ) { value_add( &c->rvalue_vals, default_referral ); return 0; @@ -1560,7 +1715,7 @@ config_security(ConfigArgs *c) { slap_ssf_set_t *set = &c->be->be_ssf_set; char *next; int i, j; - if (c->emit) { + if (c->op == SLAP_CONFIG_EMIT) { char numbuf[32]; struct berval bv; slap_ssf_t *tgt; @@ -1629,7 +1784,7 @@ replica_unparse( struct slap_replica_info *ri, int i, struct berval *bv ) struct berval bc = {0}; char numbuf[32]; - len = sprintf(numbuf, "{%d}", i ); + len = sprintf(numbuf, IFMT, i ); len += strlen( ri->ri_uri ) + STRLENOF("uri="); if ( ri->ri_nsuffix ) { @@ -1679,7 +1834,7 @@ config_replica(ConfigArgs *c) { char *replicahost, *replicauri; LDAPURLDesc *ludp; - if (c->emit) { + if (c->op == SLAP_CONFIG_EMIT) { if (c->be->be_replica) { struct berval bv; for (i=0;c->be->be_replica[i]; i++) { @@ -1784,7 +1939,7 @@ static int config_updatedn(ConfigArgs *c) { struct berval dn; int rc; - if (c->emit) { + if (c->op == SLAP_CONFIG_EMIT) { if (!BER_BVISEMPTY(&c->be->be_update_ndn)) { value_add_one(&c->rvalue_vals, &c->be->be_update_ndn); value_add_one(&c->rvalue_nvals, &c->be->be_update_ndn); @@ -1817,7 +1972,7 @@ config_updatedn(ConfigArgs *c) { static int config_updateref(ConfigArgs *c) { struct berval vals[2]; - if (c->emit) { + if (c->op == SLAP_CONFIG_EMIT) { if ( c->be->be_update_refs ) { value_add( &c->rvalue_vals, c->be->be_update_refs ); return 0; @@ -1851,13 +2006,15 @@ config_include(ConfigArgs *c) { ConfigFile *cf; ConfigFile *cfsave = cfn; ConfigFile *cf2 = NULL; - if (c->emit) { + if (c->op == SLAP_CONFIG_EMIT) { + if (c->private) { + ConfigFile *cf = c->private; + value_add_one( &c->rvalue_vals, &cf->c_file ); + return 0; + } return 1; } cf = ch_calloc( 1, sizeof(ConfigFile)); -#ifdef SLAPD_MODULES - cf->c_modlast = &cf->c_modpaths; -#endif if ( cfn->c_kids ) { for (cf2=cfn->c_kids; cf2 && cf2->c_sibs; cf2=cf2->c_sibs) ; cf2->c_sibs = cf; @@ -1865,15 +2022,15 @@ config_include(ConfigArgs *c) { cfn->c_kids = cf; } cfn = cf; + ber_str2bv( c->argv[1], 0, 1, &cf->c_file ); rc = read_config_file(c->argv[1], c->depth + 1, c); c->lineno = savelineno - 1; cfn = cfsave; if ( rc ) { if ( cf2 ) cf2->c_sibs = NULL; else cfn->c_kids = NULL; + ch_free( cf->c_file.bv_val ); ch_free( cf ); - } else { - ber_str2bv( c->argv[1], 0, 1, &cf->c_file ); } return(rc); } @@ -1883,17 +2040,17 @@ static int config_tls_option(ConfigArgs *c) { int flag; switch(c->type) { - case CFG_TLS_RAND: flag = LDAP_OPT_X_TLS_RANDOM_FILE; break; + case CFG_TLS_RAND: flag = LDAP_OPT_X_TLS_RANDOM_FILE; break; case CFG_TLS_CIPHER: flag = LDAP_OPT_X_TLS_CIPHER_SUITE; break; case CFG_TLS_CERT_FILE: flag = LDAP_OPT_X_TLS_CERTFILE; break; case CFG_TLS_CERT_KEY: flag = LDAP_OPT_X_TLS_KEYFILE; break; case CFG_TLS_CA_PATH: flag = LDAP_OPT_X_TLS_CACERTDIR; break; case CFG_TLS_CA_FILE: flag = LDAP_OPT_X_TLS_CACERTFILE; break; default: Debug(LDAP_DEBUG_ANY, "%s: " - "unknown tls_option <%x>\n", + "unknown tls_option <0x%x>\n", c->log, c->type, 0); } - if (c->emit) { + if (c->op == SLAP_CONFIG_EMIT) { return ldap_pvt_tls_get_option( NULL, flag, &c->value_string ); } ch_free(c->value_string); @@ -1904,35 +2061,32 @@ config_tls_option(ConfigArgs *c) { static int config_tls_config(ConfigArgs *c) { int i, flag; - struct verb_mask_list crlkeys[] = { - { "none", LDAP_OPT_X_TLS_CRL_NONE }, - { "peer", LDAP_OPT_X_TLS_CRL_PEER }, - { "all", LDAP_OPT_X_TLS_CRL_ALL }, - { NULL, 0 } + slap_verbmasks crlkeys[] = { + { BER_BVC("none"), LDAP_OPT_X_TLS_CRL_NONE }, + { BER_BVC("peer"), LDAP_OPT_X_TLS_CRL_PEER }, + { BER_BVC("all"), LDAP_OPT_X_TLS_CRL_ALL }, + { BER_BVNULL, 0 } }; - struct verb_mask_list vfykeys[] = { - { "never", LDAP_OPT_X_TLS_NEVER }, - { "demand", LDAP_OPT_X_TLS_DEMAND }, - { "try", LDAP_OPT_X_TLS_TRY }, - { "hard", LDAP_OPT_X_TLS_HARD }, - { NULL, 0 } + slap_verbmasks vfykeys[] = { + { BER_BVC("never"), LDAP_OPT_X_TLS_NEVER }, + { BER_BVC("demand"), LDAP_OPT_X_TLS_DEMAND }, + { BER_BVC("try"), LDAP_OPT_X_TLS_TRY }, + { BER_BVC("hard"), LDAP_OPT_X_TLS_HARD }, + { BER_BVNULL, 0 } }, *keys; switch(c->type) { -#ifdef HAVE_OPENSSL_CRL - case CFG_TLS_CRLCHECK: flag = LDAP_OPT_X_TLS_CRLCHECK; keys = crlkeys; - break; -#endif - case CFG_TLS_VERIFY: flag = LDAP_OPT_X_TLS_REQUIRE_CERT; keys = vfykeys; - break; - default: Debug(LDAP_DEBUG_ANY, "%s: " - "unknown tls_option <%x>\n", - c->log, c->type, 0); + case CFG_TLS_CRLCHECK: flag = LDAP_OPT_X_TLS_CRLCHECK; keys = crlkeys; break; + case CFG_TLS_VERIFY: flag = LDAP_OPT_X_TLS_REQUIRE_CERT; keys = vfykeys; break; + default: + Debug(LDAP_DEBUG_ANY, "%s: " + "unknown tls_option <0x%x>\n", + c->log, c->type, 0); } - if (c->emit) { + if (c->op == SLAP_CONFIG_EMIT) { ldap_pvt_tls_get_option( NULL, flag, &c->value_int ); - for (i=0; keys[i].word; i++) { + for (i=0; !BER_BVISNULL(&keys[i].word); i++) { if (keys[i].mask == c->value_int) { - c->value_string = ch_strdup( keys[i].word ); + c->value_string = ch_strdup( keys[i].word.bv_val ); return 0; } } @@ -2464,38 +2618,17 @@ syncrepl_unparse( syncinfo_t *si, struct berval *bv ) ber_dupbv( bv, &bc ); } - -int -read_config(const char *fname, int depth) { - - if ( !backend_db_init( "config" )) - return 1; - - ber_str2bv( fname, 0, 1, &cf_prv.c_file ); - return read_config_file(fname, depth, NULL); -} - -static int -config_back_bind( Operation *op, SlapReply *rs ) -{ - if ( op->orb_method == LDAP_AUTH_SIMPLE && be_isroot_pw( op )) { - ber_dupbv( &op->orb_edn, be_root_dn( op->o_bd )); - /* frontend sends result */ - return LDAP_SUCCESS; - } - - rs->sr_err = LDAP_INVALID_CREDENTIALS; - send_ldap_result( op, rs ); - - return rs->sr_err; -} - static CfEntryInfo * config_find_base( CfEntryInfo *root, struct berval *dn, CfEntryInfo **last ) { struct berval cdn; char *c; + if ( !root ) { + *last = NULL; + return NULL; + } + if ( dn_match( &root->ce_entry->e_nname, dn )) return root; @@ -2505,10 +2638,10 @@ config_find_base( CfEntryInfo *root, struct berval *dn, CfEntryInfo **last ) while(root) { *last = root; for (--c;c>dn->bv_val && *c != ',';c--); - if ( *c == ',' ) - c++; cdn.bv_val = c; - cdn.bv_len = dn->bv_len - (c-dn->bv_val); + if ( *c == ',' ) + cdn.bv_val++; + cdn.bv_len = dn->bv_len - (cdn.bv_val - dn->bv_val); root = root->ce_kids; @@ -2524,6 +2657,173 @@ config_find_base( CfEntryInfo *root, struct berval *dn, CfEntryInfo **last ) return root; } +static int +config_ldif_resp( Operation *op, SlapReply *rs ) +{ + if ( rs->sr_type == REP_SEARCH ) { + CfBackInfo *cfb = op->o_callback->sc_private; + + cfb->cb_got_ldif = 1; + rs->sr_err = config_add_internal( cfb, rs->sr_entry, NULL, NULL ); + } + return rs->sr_err; +} + +/* Configure and read the underlying back-ldif store */ +static int +config_setup_ldif( BackendDB *be, const char *dir ) { + CfBackInfo *cfb = be->be_private; + ConfigArgs c = {0}; + ConfigTable *ct; + char *argv[3]; + int rc; + slap_callback cb = { NULL, config_ldif_resp, NULL, NULL }; + Connection conn = {0}; + char opbuf[OPERATION_BUFFER_SIZE]; + Operation *op; + SlapReply rs = {REP_RESULT}; + Filter filter = { LDAP_FILTER_PRESENT }; + struct berval filterstr = BER_BVC("(objectclass=*)"); + + cfb->cb_db.bd_info = backend_info( "ldif" ); + if ( !cfb->cb_db.bd_info ) + return 0; /* FIXME: eventually this will be a fatal error */ + + if ( cfb->cb_db.bd_info->bi_db_init( &cfb->cb_db )) return 1; + + /* Mark that back-ldif type is in use */ + cfb->cb_db.bd_info->bi_nDB++; + + cfb->cb_db.be_suffix = be->be_suffix; + cfb->cb_db.be_nsuffix = be->be_nsuffix; + cfb->cb_db.be_rootdn = be->be_rootdn; + cfb->cb_db.be_rootndn = be->be_rootndn; + + ber_str2bv( dir, 0, 1, &cfdir ); + + c.be = &cfb->cb_db; + c.fname = "slapd"; + c.argc = 2; + argv[0] = "directory"; + argv[1] = (char *)dir; + argv[2] = NULL; + c.argv = argv; + + ct = config_find_keyword( c.be->be_cf_table, &c ); + if ( !ct ) + return 1; + + if ( config_add_vals( ct, &c )) + return 1; + + if ( backend_startup_one( &cfb->cb_db )) + return 1; + + op = (Operation *)opbuf; + connection_fake_init( &conn, op, cfb ); + + filter.f_desc = slap_schema.si_ad_objectClass; + + op->o_tag = LDAP_REQ_SEARCH; + + op->ors_filter = &filter; + op->ors_filterstr = filterstr; + op->ors_scope = LDAP_SCOPE_SUBTREE; + + op->o_dn = be->be_rootdn; + op->o_ndn = be->be_rootndn; + + op->o_req_dn = be->be_suffix[0]; + op->o_req_ndn = be->be_nsuffix[0]; + + op->ors_tlimit = SLAP_NO_LIMIT; + op->ors_slimit = SLAP_NO_LIMIT; + + op->ors_attrs = slap_anlist_all_attributes; + op->ors_attrsonly = 0; + + op->o_callback = &cb; + cb.sc_private = cfb; + + op->o_bd = &cfb->cb_db; + op->o_bd->be_search( op, &rs ); + + return 0; +} + +static int +CfOcInfo_cmp( const void *c1, const void *c2 ) { + const CfOcInfo *co1 = c1; + const CfOcInfo *co2 = c2; + + return ber_bvcmp( co1->co_name, co2->co_name ); +} + +int +config_register_schema(ConfigTable *ct, ConfigOCs *ocs) { + int i; + CfOcInfo *co; + + i = init_config_attrs( ct ); + if ( i ) return i; + + /* set up the objectclasses */ + i = init_config_ocs( ocs ); + if ( i ) return i; + + for (i=0; ocs[i].def; i++) { + if ( ocs[i].oc ) { + co = ch_malloc( sizeof(CfOcInfo) ); + co->co_name = &(*ocs[i].oc)->soc_cname; + co->co_table = ct; + co->co_type = ocs[i].cft; + avl_insert( &CfOcTree, co, CfOcInfo_cmp, avl_dup_error ); + } + } + return 0; +} + +int +read_config(const char *fname, const char *dir) { + BackendDB *be; + CfBackInfo *cfb; + + /* Setup the config backend */ + be = backend_db_init( "config" ); + if ( !be ) + return 1; + + cfb = be->be_private; + + /* Setup the underlying back-ldif backend */ + if ( config_setup_ldif( be, dir )) + return 1; + +#ifdef SLAP_USE_CONFDIR + /* If we read the config from back-ldif, nothing to do here */ + if ( cfb->cb_got_ldif ) + return 0; +#endif + ber_str2bv( fname, 0, 1, &cf_prv.c_file ); + + return read_config_file(fname, 0, NULL); +} + +static int +config_back_bind( Operation *op, SlapReply *rs ) +{ + if ( op->orb_method == LDAP_AUTH_SIMPLE && be_isroot_pw( op )) { + ber_dupbv( &op->orb_edn, be_root_dn( op->o_bd )); + /* frontend sends result */ + return LDAP_SUCCESS; + } + + rs->sr_err = LDAP_INVALID_CREDENTIALS; + send_ldap_result( op, rs ); + + return rs->sr_err; +} + static int config_send( Operation *op, SlapReply *rs, CfEntryInfo *ce, int depth ) { @@ -2550,14 +2850,630 @@ config_send( Operation *op, SlapReply *rs, CfEntryInfo *ce, int depth ) return rc; } -static int -config_back_search( Operation *op, SlapReply *rs ) +static ConfigTable * +config_find_table( CfOcInfo *co, AttributeDescription *ad ) { - CfBackInfo *cfb; - CfEntryInfo *ce, *last; - int rc; + int i; - if ( !be_isroot( op ) ) { + for (i=0; co->co_table[i].name; i++) + if ( co->co_table[i].ad == ad ) + return &co->co_table[i]; + return NULL; +} + +/* Sort the values in an X-ORDERED VALUES attribute. + * If the values have no index, leave them in their given order. + * If the values have indexes, sort them. + * If some are indexed and some are not, return Error. + * + * FIXME: This function probably belongs in the frontend somewhere, + * like slap_mods_check. + */ +static int +sort_vals( Attribute *a ) +{ + int i; + int index = 0, noindex = 0; + + /* count attrs, look for index */ + for (i=0; a->a_vals[i].bv_val; i++) { + if ( a->a_vals[i].bv_val[0] == '{' ) { + char *ptr; + index = 1; + ptr = strchr( a->a_vals[i].bv_val, '}' ); + if ( !ptr || !ptr[1] ) + return LDAP_INVALID_SYNTAX; + if ( noindex ) + return LDAP_INVALID_SYNTAX; + } else { + noindex = 1; + if ( index ) + return LDAP_INVALID_SYNTAX; + } + } + + if ( index ) { + int vals = i, *indexes, j, idx; + struct berval tmp, ntmp; + char *ptr; + +#if 0 + /* Strip index from normalized values */ + if ( !a->a_nvals || a->a_vals == a->a_nvals ) { + a->a_nvals = ch_malloc( (vals+1)*sizeof(struct berval)); + BER_BVZERO(a->a_nvals+vals); + for ( i=0; ia_vals[i].bv_val, '}') + 1; + a->a_nvals[i].bv_len = a->a_vals[i].bv_len - + (ptr - a->a_vals[i].bv_val); + a->a_nvals[i].bv_val = ch_malloc( a->a_nvals[i].bv_len + 1); + strcpy(a->a_nvals[i].bv_val, ptr ); + } + } else { + for ( i=0; ia_nvals[i].bv_val, '}') + 1; + a->a_nvals[i].bv_len -= ptr - a->a_nvals[i].bv_val; + strcpy(a->a_nvals[i].bv_val, ptr); + } + } +#endif + + indexes = ch_malloc( vals * sizeof(int) ); + for ( i=0; ia_vals[i].bv_val+1); + + /* Insertion sort */ + for ( i=1; ia_vals[i]; + ntmp = a->a_nvals[i]; + j = i; + while ((j > 0) && (indexes[j-1] > idx)) { + indexes[j] = indexes[j-1]; + a->a_vals[j] = a->a_vals[j-1]; + a->a_nvals[j] = a->a_nvals[j-1]; + j--; + } + indexes[j] = idx; + a->a_vals[j] = tmp; + a->a_nvals[j] = ntmp; + } + } + return 0; +} + +static int +check_attr( ConfigTable *ct, ConfigArgs *ca, Attribute *a ) +{ + int i, rc = 0, sort = 0; + + if ( a->a_desc->ad_type->sat_flags & SLAP_AT_ORDERED ) { + sort = 1; + rc = sort_vals( a ); + if ( rc ) + return rc; + } + for ( i=0; a->a_nvals[i].bv_val; i++ ) { + ca->line = a->a_nvals[i].bv_val; + if ( sort ) ca->line = strchr( ca->line, '}' ) + 1; + rc = config_parse_vals( ct, ca, i ); + if ( rc ) + break; + } + return rc; +} + +static int +check_name_index( CfEntryInfo *parent, ConfigType ce_type, Entry *e, + SlapReply *rs, int *renum ) +{ + CfEntryInfo *ce; + int index = -1, gotindex = 0, nsibs; + int renumber = 0, tailindex = 0; + char *ptr1, *ptr2; + struct berval rdn; + + if ( renum ) *renum = 0; + + /* These entries don't get indexed/renumbered */ + if ( ce_type == Cft_Global ) return 0; + if ( ce_type == Cft_Schema && parent->ce_type == Cft_Global ) return 0; + + if ( ce_type == Cft_Include || ce_type == Cft_Module ) + tailindex = 1; + + /* See if the rdn has an index already */ + dnRdn( &e->e_name, &rdn ); + ptr1 = strchr( e->e_name.bv_val, '{' ); + if ( ptr1 && ptr1 - e->e_name.bv_val < rdn.bv_len ) { + ptr2 = strchr( ptr1, '}' ); + if (!ptr2 || ptr2 - e->e_name.bv_val > rdn.bv_len) + return LDAP_NAMING_VIOLATION; + if ( ptr2-ptr1 == 1) + return LDAP_NAMING_VIOLATION; + gotindex = 1; + index = atoi(ptr1+1); + if ( index < 0 ) + return LDAP_NAMING_VIOLATION; + } + + /* count related kids */ + for (nsibs=0, ce=parent->ce_kids; ce; ce=ce->ce_sibs) { + if ( ce->ce_type == ce_type ) nsibs++; + } + + if ( index != nsibs ) { + if ( gotindex ) { + if ( index < nsibs ) { + if ( tailindex ) return LDAP_NAMING_VIOLATION; + /* Siblings need to be renumbered */ + renumber = 1; + } + } + if ( !renumber ) { + struct berval ival, newrdn, nnewrdn; + struct berval rtype, rval; + Attribute *a; + AttributeDescription *ad = NULL; + char ibuf[32]; + const char *text; + + rval.bv_val = strchr(rdn.bv_val, '=' ) + 1; + rval.bv_len = rdn.bv_len - (rval.bv_val - rdn.bv_val); + rtype.bv_val = rdn.bv_val; + rtype.bv_len = rval.bv_val - rtype.bv_val - 1; + + /* Find attr */ + slap_bv2ad( &rtype, &ad, &text ); + a = attr_find( e->e_attrs, ad ); + if (!a ) return LDAP_NAMING_VIOLATION; + + ival.bv_val = ibuf; + ival.bv_len = sprintf( ibuf, IFMT, nsibs ); + + newrdn.bv_len = rdn.bv_len + ival.bv_len; + newrdn.bv_val = ch_malloc( newrdn.bv_len+1 ); + + if ( tailindex ) { + ptr1 = lutil_strncopy( newrdn.bv_val, rdn.bv_val, rdn.bv_len ); + ptr1 = lutil_strcopy( ptr1, ival.bv_val ); + } else { + int xlen; + if ( !gotindex ) { + ptr2 = rval.bv_val; + xlen = rval.bv_len; + } else { + xlen = rdn.bv_len - (ptr2 - rdn.bv_val); + } + ptr1 = lutil_strncopy( newrdn.bv_val, rtype.bv_val, + rtype.bv_len ); + *ptr1++ = '='; + ptr1 = lutil_strcopy( ptr1, ival.bv_val ); + ptr1 = lutil_strncopy( ptr1, ptr2, xlen ); + *ptr1 = '\0'; + } + + /* Do the equivalent of ModRDN */ + /* Replace DN / NDN */ + newrdn.bv_len = ptr1 - newrdn.bv_val; + rdnNormalize( 0, NULL, NULL, &newrdn, &nnewrdn, NULL ); + free( e->e_name.bv_val ); + build_new_dn( &e->e_name, &parent->ce_entry->e_name, + &newrdn, NULL ); + free( e->e_nname.bv_val ); + build_new_dn( &e->e_nname, &parent->ce_entry->e_nname, + &nnewrdn, NULL ); + + /* Replace attr */ + free( a->a_vals[0].bv_val ); + ptr1 = strchr( newrdn.bv_val, '=' ) + 1; + a->a_vals[0].bv_len = newrdn.bv_len - (ptr1 - newrdn.bv_val); + a->a_vals[0].bv_val = ch_malloc( a->a_vals[0].bv_len + 1 ); + strcpy( a->a_vals[0].bv_val, ptr1 ); + + if ( a->a_nvals != a->a_vals ) { + free( a->a_nvals[0].bv_val ); + ptr1 = strchr( nnewrdn.bv_val, '=' ) + 1; + a->a_nvals[0].bv_len = nnewrdn.bv_len - (ptr1 - nnewrdn.bv_val); + a->a_nvals[0].bv_val = ch_malloc( a->a_nvals[0].bv_len + 1 ); + strcpy( a->a_nvals[0].bv_val, ptr1 ); + } + free( nnewrdn.bv_val ); + free( newrdn.bv_val ); + } + } + if ( renum ) *renum = renumber; + return 0; +} + +/* Parse an LDAP entry into config directives */ +static int +config_add_internal( CfBackInfo *cfb, Entry *e, SlapReply *rs, int *renum ) +{ + CfEntryInfo *ce, *last; + CfOcInfo co, *coptr, **colst = NULL; + Attribute *a, *oc_at, *type_attr; + AttributeDescription *type_ad = NULL; + int i, j, nocs, rc; + ConfigArgs ca = {0}; + struct berval pdn; + Entry *xe = NULL; + ConfigTable *ct, *type_ct = NULL; + + /* Make sure parent exists and entry does not */ + ce = config_find_base( cfb->cb_root, &e->e_nname, &last ); + if ( ce ) + return LDAP_ALREADY_EXISTS; + + dnParent( &e->e_nname, &pdn ); + + /* If last is NULL, the new entry is the root/suffix entry, + * otherwise last should be the parent. + */ + if ( last && !dn_match( &last->ce_entry->e_nname, &pdn )) { + if ( rs ) + rs->sr_matched = last->ce_entry->e_name.bv_val; + return LDAP_NO_SUCH_OBJECT; + } + + oc_at = attr_find( e->e_attrs, slap_schema.si_ad_objectClass ); + if ( !oc_at ) return LDAP_OBJECT_CLASS_VIOLATION; + + /* count the objectclasses */ + for ( i=0; oc_at->a_nvals[i].bv_val; i++ ); + nocs = i; + colst = (CfOcInfo **)ch_malloc( nocs * sizeof(CfOcInfo *)); + + for ( i=0, j=0; ia_nvals[i]; + coptr = avl_find( CfOcTree, &co, CfOcInfo_cmp ); + + /* ignore non-config objectclasses. probably should be + * an error, general data doesn't belong here. + */ + if ( !coptr ) continue; + + /* Ignore the root objectclass, it has no implementation. + */ + if ( coptr->co_type == Cft_Abstract ) continue; + colst[j++] = coptr; + } + nocs = j; + + /* Only the root can be Cft_Global, everything else must + * have a parent. Only limited nesting arrangements are allowed. + */ + switch( colst[0]->co_type ) { + case Cft_Global: + if ( last ) { + rc = LDAP_CONSTRAINT_VIOLATION; + goto leave; + } + break; + case Cft_Schema: + case Cft_Backend: + case Cft_Database: + case Cft_Include: + if ( !last || ( last->ce_type != Cft_Global && + last->ce_type != colst[0]->co_type )) { + rc = LDAP_CONSTRAINT_VIOLATION; + goto leave; + } + break; + case Cft_Overlay: + if ( !last || ( last->ce_type != Cft_Global && + last->ce_type != Cft_Database && + last->ce_type != colst[0]->co_type )) { + rc = LDAP_CONSTRAINT_VIOLATION; + goto leave; + } + break; +#ifdef SLAPD_MODULES + case Cft_Module: + if ( !last || last->ce_type != Cft_Global ) { + rc = LDAP_CONSTRAINT_VIOLATION; + goto leave; + } +#endif + break; + } + + /* Parse all the values and check for simple syntax errors before + * performing any set actions. + */ + switch (colst[0]->co_type) { + case Cft_Schema: + /* The cn=schema entry is all hardcoded, so never reparse it */ + if (last->ce_type == Cft_Global ) + goto ok; + /* FALLTHRU */ + case Cft_Global: + ca.be = LDAP_STAILQ_FIRST(&backendDB); + break; + + case Cft_Backend: + if ( last->ce_type == Cft_Backend ) + ca.bi = last->ce_bi; + else + type_ad = cfAd_backend; + break; + case Cft_Database: + if ( last->ce_type == Cft_Database ) { + ca.be = last->ce_be; + } else { + type_ad = cfAd_database; + /* dummy, just to get past check_attr */ + ca.be = frontendDB; + } + break; + + case Cft_Overlay: + ca.be = last->ce_be; + type_ad = cfAd_overlay; + break; + + case Cft_Include: + if ( !rs ) /* ignored */ + break; + type_ad = cfAd_include; + break; +#ifdef SLAPD_MODULES + case Cft_Module: { + ModPaths *mp; + char *ptr; + ptr = strchr( e->e_name.bv_val, '{' ); + if ( !ptr ) { + rc = LDAP_NAMING_VIOLATION; + goto leave; + } + j = atoi(ptr+1); + for (i=0, mp=&modpaths; mp && imp_next); + /* There is no corresponding modpath for this load? */ + if ( i != j ) { + rc = LDAP_NAMING_VIOLATION; + goto leave; + } + module_path( mp->mp_path.bv_val ); + ca.private = mp; + } + break; +#endif + } + + /* If doing an LDAPadd, check for indexed names and any necessary + * renaming/renumbering. Entries that don't need indexed names are + * ignored. Entries that need an indexed name and arrive without one + * are assigned to the end. Entries that arrive with an index may + * cause the following entries to be renumbered/bumped down. + * + * Note that "pseudo-indexed" entries (cn=Include{xx}, cn=Module{xx}) + * don't allow Adding an entry with an index that's already in use. + * This is flagged as an error (LDAP_ALREADY_EXISTS) up above. + * + * These entries can have auto-assigned indexes (appended to the end) + * but only the other types support auto-renumbering of siblings. + */ + rc = check_name_index( last, colst[0]->co_type, e, rs, renum ); + if ( rc ) + goto leave; + + init_config_argv( &ca ); + if ( type_ad ) { + type_attr = attr_find( e->e_attrs, type_ad ); + if ( !type_attr ) { + rc = LDAP_OBJECT_CLASS_VIOLATION; + goto leave; + } + for ( i=0; ie_attrs; a; a=a->a_next ) { + if ( a == type_attr || a == oc_at ) continue; + ct = NULL; + for ( i=0; ia_desc ); + if ( ct ) break; + } + if ( !ct ) continue; /* user data? */ + rc = check_attr( ct, &ca, a ); + if ( rc ) goto leave; + } + + /* Basic syntax checks are OK. Do the actual settings. */ + if ( type_ct ) { + ca.line = type_attr->a_vals[0].bv_val; + if ( type_ad->ad_type->sat_flags & SLAP_AT_ORDERED ) + ca.line = strchr( ca.line, '}' ) + 1; + rc = config_parse_add( type_ct, &ca, 0 ); + if ( rc ) { + rc = LDAP_OTHER; + goto leave; + } + } + for ( a=e->e_attrs; a; a=a->a_next ) { + if ( a == type_attr || a == oc_at ) continue; + ct = NULL; + for ( i=0; ia_desc ); + if ( ct ) break; + } + if ( !ct ) continue; /* user data? */ + for (i=0; a->a_vals[i].bv_val; i++) { + ca.line = a->a_vals[i].bv_val; + if ( a->a_desc->ad_type->sat_flags & SLAP_AT_ORDERED ) + ca.line = strchr( ca.line, '}' ) + 1; + rc = config_parse_add( ct, &ca, i ); + if ( rc ) { + rc = LDAP_OTHER; + goto leave; + } + } + } +ok: + ce = ch_calloc( 1, sizeof(CfEntryInfo) ); + ce->ce_parent = last; + ce->ce_entry = entry_dup( e ); + ce->ce_entry->e_private = ce; + ce->ce_type = colst[0]->co_type; + if ( !last ) { + cfb->cb_root = ce; + } else if ( last->ce_kids ) { + CfEntryInfo *c2; + + for (c2=last->ce_kids; c2 && c2->ce_sibs; c2 = c2->ce_sibs); + + c2->ce_sibs = ce; + } else { + last->ce_kids = ce; + } + +leave: + ch_free( ca.argv ); + if ( colst ) ch_free( colst ); + return rc; +} + +/* Parse an LDAP entry into config directives, then store in underlying + * database. + */ +static int +config_back_add( Operation *op, SlapReply *rs ) +{ + CfBackInfo *cfb; + CfEntryInfo *ce, *last; + int renumber; + + if ( !be_isroot( op ) ) { + rs->sr_err = LDAP_INSUFFICIENT_ACCESS; + send_ldap_result( op, rs ); + } + + cfb = (CfBackInfo *)op->o_bd->be_private; + + ldap_pvt_thread_pool_pause( &connection_pool ); + + /* Strategy: + * 1) check for existence of entry + * 2) check for sibling renumbering + * 3) perform internal add + * 4) store entry in underlying database + * 5) perform any necessary renumbering + */ + rs->sr_err = config_add_internal( cfb, op->ora_e, rs, &renumber ); + if ( rs->sr_err == LDAP_SUCCESS ) { + BackendDB *be = op->o_bd; + slap_callback sc = { NULL, slap_null_cb, NULL, NULL }; + op->o_bd = &cfb->cb_db; + sc.sc_next = op->o_callback; + op->o_callback = ≻ + op->o_bd->be_add( op, rs ); + op->o_bd = be; + op->o_callback = sc.sc_next; + } + if ( renumber ) { + } + + ldap_pvt_thread_pool_resume( &connection_pool ); + +out: + send_ldap_result( op, rs ); + return rs->sr_err; +} + +/* Modify rules: + * for single-valued attributes, should just use REPLACE. + * any received DELETE/ADD on a single-valued attr will + * be checked (if a DEL value is provided) and then + * rewritten as a REPLACE. + * any DELETE received without a corresponding ADD will be + * rejected with LDAP_CONSTRAINT_VIOLATION. + */ +static int +config_back_modify( Operation *op, SlapReply *rs ) +{ + CfBackInfo *cfb; + CfEntryInfo *ce, *last; + + if ( !be_isroot( op ) ) { + rs->sr_err = LDAP_INSUFFICIENT_ACCESS; + send_ldap_result( op, rs ); + } + + cfb = (CfBackInfo *)op->o_bd->be_private; + + ce = config_find_base( cfb->cb_root, &op->o_req_ndn, &last ); + if ( !ce ) { + if ( last ) + rs->sr_matched = last->ce_entry->e_name.bv_val; + rs->sr_err = LDAP_NO_SUCH_OBJECT; + goto out; + } + ldap_pvt_thread_pool_pause( &connection_pool ); + + /* Strategy: + * 1) perform the Modify on the cached Entry. + * 2) verify that the Entry still satisfies the schema. + * 3) perform the individual config operations. + * 4) store Modified entry in underlying LDIF backend. + */ + ldap_pvt_thread_pool_resume( &connection_pool ); +out: + send_ldap_result( op, rs ); + return rs->sr_err; +} + +static int +config_back_modrdn( Operation *op, SlapReply *rs ) +{ + CfBackInfo *cfb; + CfEntryInfo *ce, *last; + + if ( !be_isroot( op ) ) { + rs->sr_err = LDAP_INSUFFICIENT_ACCESS; + send_ldap_result( op, rs ); + } + + cfb = (CfBackInfo *)op->o_bd->be_private; + + ce = config_find_base( cfb->cb_root, &op->o_req_ndn, &last ); + if ( !ce ) { + if ( last ) + rs->sr_matched = last->ce_entry->e_name.bv_val; + rs->sr_err = LDAP_NO_SUCH_OBJECT; + goto out; + } + + /* We don't allow moving objects to new parents. + * Generally we only allow reordering a set of ordered entries. + */ + if ( op->orr_newSup ) { + rs->sr_err = LDAP_UNWILLING_TO_PERFORM; + goto out; + } + ldap_pvt_thread_pool_pause( &connection_pool ); + + ldap_pvt_thread_pool_resume( &connection_pool ); +out: + send_ldap_result( op, rs ); + return rs->sr_err; +} + +static int +config_back_search( Operation *op, SlapReply *rs ) +{ + CfBackInfo *cfb; + CfEntryInfo *ce, *last; + int rc; + + if ( !be_isroot( op ) ) { rs->sr_err = LDAP_INSUFFICIENT_ACCESS; send_ldap_result( op, rs ); } @@ -2591,13 +3507,22 @@ out: } static Entry * -config_alloc_entry( struct berval *pdn, struct berval *rdn ) +config_alloc_entry( CfEntryInfo *parent, struct berval *rdn ) { Entry *e = ch_calloc( 1, sizeof(Entry) ); CfEntryInfo *ce = ch_calloc( 1, sizeof(CfEntryInfo) ); + struct berval pdn; + e->e_private = ce; ce->ce_entry = e; - build_new_dn( &e->e_name, pdn, rdn, NULL ); + ce->ce_parent = parent; + if ( parent ) { + pdn = parent->ce_entry->e_nname; + } else { + BER_BVZERO( &pdn ); + } + + build_new_dn( &e->e_name, &pdn, rdn, NULL ); ber_dupbv( &e->e_nname, &e->e_name ); return e; } @@ -2616,7 +3541,10 @@ config_build_entry( ConfigArgs *c, Entry *e, ObjectClass *oc, int rc, i; char *ptr; const char *text; + char textbuf[SLAP_TEXT_BUFLEN]; + size_t textlen = sizeof(textbuf); AttributeType **at; + Attribute *oc_at; BER_BVZERO( &vals[1] ); @@ -2633,19 +3561,37 @@ config_build_entry( ConfigArgs *c, Entry *e, ObjectClass *oc, vals[0].bv_len = rdn->bv_len - (vals[0].bv_val - rdn->bv_val); attr_merge(e, ad, vals, NULL ); - for (at=oc->soc_allowed;*at;at++) { + for (at=oc->soc_required; at && *at; at++) { /* Skip the naming attr */ if ((*at)->sat_ad == ad || (*at)->sat_ad == slap_schema.si_ad_cn ) continue; for (i=0;ct[i].name;i++) { - if (ct[i].ad == (*at)->sat_ad) + if (ct[i].ad == (*at)->sat_ad) { + rc = config_get_vals(&ct[i], c); + if (rc == LDAP_SUCCESS) { + attr_merge(e, ct[i].ad, c->rvalue_vals, c->rvalue_nvals); + ber_bvarray_free( c->rvalue_nvals ); + ber_bvarray_free( c->rvalue_vals ); + } break; + } } - rc = config_get_vals(&ct[i], c); - if (rc == LDAP_SUCCESS) { - attr_merge(e, ct[i].ad, c->rvalue_vals, c->rvalue_nvals); - ber_bvarray_free( c->rvalue_nvals ); - ber_bvarray_free( c->rvalue_vals ); + } + + for (at=oc->soc_allowed; at && *at; at++) { + /* Skip the naming attr */ + if ((*at)->sat_ad == ad || (*at)->sat_ad == slap_schema.si_ad_cn ) + continue; + for (i=0;ct[i].name;i++) { + if (ct[i].ad == (*at)->sat_ad) { + rc = config_get_vals(&ct[i], c); + if (rc == LDAP_SUCCESS) { + attr_merge(e, ct[i].ad, c->rvalue_vals, c->rvalue_nvals); + ber_bvarray_free( c->rvalue_nvals ); + ber_bvarray_free( c->rvalue_vals ); + } + break; + } } } @@ -2662,28 +3608,95 @@ config_build_entry( ConfigArgs *c, Entry *e, ObjectClass *oc, } } } + oc_at = attr_find( e->e_attrs, slap_schema.si_ad_objectClass ); + rc = structural_class(oc_at->a_vals, vals, NULL, &text, textbuf, textlen); + BER_BVZERO( &vals[1] ); + attr_merge(e, slap_schema.si_ad_structuralObjectClass, vals, NULL ); return 0; } +static void +config_build_schema_inc( ConfigArgs *c, CfEntryInfo *ceparent, + Operation *op, SlapReply *rs ) +{ + Entry *e; + ConfigFile *cf = c->private; + CfEntryInfo *ce, *ceprev; + char *ptr; + struct berval bv; + + if ( ceparent->ce_kids ) { + for ( ceprev = ceparent->ce_kids; ceprev->ce_sibs; + ceprev = ceprev->ce_sibs ); + } + + for (; cf; cf=cf->c_sibs, c->depth++) { + c->value_dn.bv_val = c->log; + bv.bv_val = strrchr(cf->c_file.bv_val, LDAP_DIRSEP[0]); + if ( !bv.bv_val ) { + bv = cf->c_file; + } else { + bv.bv_val++; + bv.bv_len = cf->c_file.bv_len - (bv.bv_val - cf->c_file.bv_val); + } + ptr = strchr( bv.bv_val, '.' ); + if ( ptr ) + bv.bv_len = ptr - bv.bv_val; + c->value_dn.bv_len = sprintf(c->value_dn.bv_val, "cn=" IFMT, c->depth); + strncpy( c->value_dn.bv_val + c->value_dn.bv_len, bv.bv_val, + bv.bv_len ); + c->value_dn.bv_len += bv.bv_len; + c->value_dn.bv_val[c->value_dn.bv_len] ='\0'; + + e = config_alloc_entry( ceparent, &c->value_dn ); + c->private = cf; + config_build_entry( c, e, cfOc_schema, &c->value_dn, + c->bi->bi_cf_table, NO_TABLE ); + ce = e->e_private; + ce->ce_type = Cft_Schema; + op->ora_e = e; + op->o_bd->be_add( op, rs ); + ce->ce_bi = c->bi; + if ( !ceparent->ce_kids ) { + ceparent->ce_kids = ce; + } else { + ceprev->ce_sibs = ce; + } + ceprev = ce; + if ( cf->c_kids ) { + c->private = cf->c_kids; + config_build_schema_inc( c, ceparent, op, rs ); + } + } +} + static CfEntryInfo * -config_build_includes( ConfigArgs *c, Entry *parent ) +config_build_includes( ConfigArgs *c, CfEntryInfo *ceparent, + Operation *op, SlapReply *rs ) { Entry *e; int i; - ConfigFile *cf = (ConfigFile *)c->line; - CfEntryInfo *ce, *ceparent, *ceprev; + ConfigFile *cf = c->private; + CfEntryInfo *ce, *ceprev; - ceparent = parent->e_private; + if ( ceparent->ce_kids ) { + for ( ceprev = ceparent->ce_kids; ceprev->ce_sibs; + ceprev = ceprev->ce_sibs ); + } for (i=0; cf; cf=cf->c_sibs, i++) { c->value_dn.bv_val = c->log; - c->value_dn.bv_len = sprintf(c->value_dn.bv_val, "cn=include{%d}", i); - e = config_alloc_entry( &parent->e_nname, &c->value_dn ); - c->line = (char *)cf; + c->value_dn.bv_len = sprintf(c->value_dn.bv_val, "cn=include" IFMT, i); + e = config_alloc_entry( ceparent, &c->value_dn ); + c->private = cf; config_build_entry( c, e, cfOc_include, &c->value_dn, c->bi->bi_cf_table, NO_TABLE ); + op->ora_e = e; + op->o_bd->be_add( op, rs ); ce = e->e_private; + ce->ce_type = Cft_Include; + ce->ce_bi = c->bi; if ( !ceparent->ce_kids ) { ceparent->ce_kids = ce; } else { @@ -2691,13 +3704,54 @@ config_build_includes( ConfigArgs *c, Entry *parent ) } ceprev = ce; if ( cf->c_kids ) { - c->line = (char *)cf->c_kids; - config_build_includes( c, e ); + c->private = cf->c_kids; + config_build_includes( c, ce, op, rs ); } } return ce; } +#ifdef SLAPD_MODULES + +static CfEntryInfo * +config_build_modules( ConfigArgs *c, CfEntryInfo *ceparent, + Operation *op, SlapReply *rs ) +{ + Entry *e; + int i; + CfEntryInfo *ce, *ceprev; + ModPaths *mp; + + if ( ceparent->ce_kids ) { + for ( ceprev = ceparent->ce_kids; ceprev->ce_sibs; + ceprev = ceprev->ce_sibs ); + } + + for (i=0, mp=&modpaths; mp; mp=mp->mp_next, i++) { + if ( BER_BVISNULL( &mp->mp_path ) && !mp->mp_loads ) + continue; + c->value_dn.bv_val = c->log; + c->value_dn.bv_len = sprintf(c->value_dn.bv_val, "cn=module" IFMT, i); + e = config_alloc_entry( ceparent, &c->value_dn ); + ce = e->e_private; + ce->ce_type = Cft_Include; + c->private = mp; + config_build_entry( c, e, cfOc_module, &c->value_dn, + c->bi->bi_cf_table, NO_TABLE ); + op->ora_e = e; + op->o_bd->be_add( op, rs ); + ce->ce_bi = c->bi; + if ( !ceparent->ce_kids ) { + ceparent->ce_kids = ce; + } else { + ceprev->ce_sibs = ce; + } + ceprev = ce; + } + return ce; +} +#endif + static int config_back_db_open( BackendDB *be ) { @@ -2710,44 +3764,98 @@ config_back_db_open( BackendDB *be ) BackendDB *bptr; ConfigArgs c; ConfigTable *ct; + Connection conn = {0}; + char opbuf[OPERATION_BUFFER_SIZE]; + Operation *op; + slap_callback cb = { NULL, slap_null_cb, NULL, NULL }; + SlapReply rs = {REP_RESULT}; + + /* If we read the config from back-ldif, nothing to do here */ + if ( cfb->cb_got_ldif ) + return 0; + + op = (Operation *)opbuf; + connection_fake_init( &conn, op, cfb ); + + op->o_dn = be->be_rootdn; + op->o_ndn = be->be_rootndn; + + op->o_tag = LDAP_REQ_ADD; + op->o_callback = &cb; + op->o_bd = &cfb->cb_db; /* create root of tree */ - ber_str2bv( CONFIG_DN, STRLENOF( CONFIG_DN ), 0, &rdn ); + rdn = config_rdn; e = config_alloc_entry( NULL, &rdn ); ce = e->e_private; + ce->ce_type = Cft_Global; cfb->cb_root = ce; c.be = be; c.bi = be->bd_info; - c.line = (char *)cfb->cb_config; + c.private = cfb->cb_config; ct = c.bi->bi_cf_table; config_build_entry( &c, e, cfOc_global, &rdn, ct, NO_TABLE ); + op->ora_e = e; + op->o_bd->be_add( op, &rs ); + ce->ce_bi = c.bi; parent = e; ceparent = ce; - /* Create includeFile nodes... */ + /* Create schema nodes... cn=schema will contain the hardcoded core + * schema, read-only. Child objects will contain runtime loaded schema + * files. + */ + rdn = schema_rdn; + e = config_alloc_entry( ceparent, &rdn ); + ce = e->e_private; + ce->ce_type = Cft_Schema; + c.private = NULL; + config_build_entry( &c, e, cfOc_schema, &rdn, ct, NO_TABLE ); + op->ora_e = e; + op->o_bd->be_add( op, &rs ); + if ( !ceparent->ce_kids ) { + ceparent->ce_kids = ce; + } else { + ceprev->ce_sibs = ce; + } + ceprev = ce; + + /* Create includeFile nodes and schema nodes for included schema... */ if ( cfb->cb_config->c_kids ) { - c.line = (char *)cfb->cb_config->c_kids; - ceprev = config_build_includes( &c, parent ); + c.depth = 0; + c.private = cfb->cb_config->c_kids; + config_build_schema_inc( &c, ce, op, &rs ); + c.private = cfb->cb_config->c_kids; + ceprev = config_build_includes( &c, ceparent, op, &rs ); } +#ifdef SLAPD_MODULES + /* Create Module nodes... */ + if ( modpaths.mp_loads ) { + ceprev = config_build_modules( &c, ceparent, op, &rs ); + } +#endif + /* Create backend nodes. Skip if they don't provide a cf_table. * There usually aren't any of these. */ c.line = 0; - bi = backendInfo; - for (i=0; ibi_cf_table) continue; if (!bi->bi_private) continue; rdn.bv_val = c.log; rdn.bv_len = sprintf(rdn.bv_val, "%s=%s", cfAd_backend->ad_cname.bv_val, bi->bi_type); - e = config_alloc_entry( &parent->e_nname, &rdn ); + e = config_alloc_entry( ceparent, &rdn ); ce = e->e_private; + ce->ce_type = Cft_Backend; ce->ce_bi = bi; c.bi = bi; config_build_entry( &c, e, cfOc_backend, &rdn, ct, BI_TABLE ); + op->ora_e = e; + op->o_bd->be_add( op, &rs ); if ( !ceparent->ce_kids ) { ceparent->ce_kids = ce; } else { @@ -2757,12 +3865,14 @@ config_back_db_open( BackendDB *be ) } /* Create database nodes... */ - for (i=0; ibd_info->bi_private; @@ -2771,15 +3881,18 @@ config_back_db_open( BackendDB *be ) bi = bptr->bd_info; } rdn.bv_val = c.log; - rdn.bv_len = sprintf(rdn.bv_val, "%s={%0x}%s", cfAd_database->ad_cname.bv_val, + rdn.bv_len = sprintf(rdn.bv_val, "%s=" IFMT "%s", cfAd_database->ad_cname.bv_val, i, bi->bi_type); - e = config_alloc_entry( &parent->e_nname, &rdn ); + e = config_alloc_entry( ceparent, &rdn ); ce = e->e_private; c.be = bptr; c.bi = bi; + ce->ce_type = Cft_Database; ce->ce_be = c.be; ce->ce_bi = c.bi; config_build_entry( &c, e, cfOc_database, &rdn, ct, BE_TABLE ); + op->ora_e = e; + op->o_bd->be_add( op, &rs ); if ( !ceparent->ce_kids ) { ceparent->ce_kids = ce; } else { @@ -2795,15 +3908,18 @@ config_back_db_open( BackendDB *be ) for (j=0,on=oi->oi_list; on; j++,on=on->on_next) { rdn.bv_val = c.log; - rdn.bv_len = sprintf(rdn.bv_val, "%s={%0x}%s", + rdn.bv_len = sprintf(rdn.bv_val, "%s=" IFMT "%s", cfAd_overlay->ad_cname.bv_val, j, on->on_bi.bi_type ); - oe = config_alloc_entry( &e->e_nname, &rdn ); + oe = config_alloc_entry( opar, &rdn ); ce = oe->e_private; c.be = bptr; c.bi = &on->on_bi; + ce->ce_type = Cft_Overlay; ce->ce_be = c.be; ce->ce_bi = c.bi; config_build_entry( &c, oe, cfOc_overlay, &rdn, ct, BI_TABLE ); + op->ora_e = oe; + op->o_bd->be_add( op, &rs ); if ( !opar->ce_kids ) { opar->ce_kids = ce; } else { @@ -2834,37 +3950,65 @@ config_back_db_init( Backend *be ) cfb->cb_config = &cf_prv; be->be_private = cfb; - ber_str2bv( CONFIG_DN, 0, 1, &be->be_rootdn ); + ber_dupbv( &be->be_rootdn, &config_rdn ); ber_dupbv( &be->be_rootndn, &be->be_rootdn ); ber_dupbv( &dn, &be->be_rootdn ); ber_bvarray_add( &be->be_suffix, &dn ); ber_dupbv( &dn, &be->be_rootdn ); ber_bvarray_add( &be->be_nsuffix, &dn ); + /* Hide from namingContexts */ + SLAP_BFLAGS(be) |= SLAP_BFLAG_CONFIG; + return 0; } static struct { char *name; AttributeDescription **desc; - AttributeDescription *sub; } ads[] = { - { "attribute", NULL, NULL }, - { "backend", &cfAd_backend, NULL }, - { "database", &cfAd_database, NULL }, - { "ditcontentrule", NULL, NULL }, - { "include", &cfAd_include, NULL }, - { "objectclass", NULL, NULL }, - { "overlay", &cfAd_overlay, NULL }, - { NULL, NULL, NULL } + { "backend", &cfAd_backend }, + { "database", &cfAd_database }, + { "include", &cfAd_include }, + { "overlay", &cfAd_overlay }, + { NULL, NULL } }; +/* Notes: + * add / delete: all types that may be added or deleted must use an + * X-ORDERED attributeType for their RDN. Adding and deleting entries + * should automatically renumber the index of any siblings as needed, + * so that no gaps in the numbering sequence exist after the add/delete + * is completed. + * What can be added: + * schema objects + * backend objects for backend-specific config directives + * database objects + * overlay objects + * + * delete: probably no support this time around. + * + * modrdn: generally not done. Will be invoked automatically by add/ + * delete to update numbering sequence. Perform as an explicit operation + * so that the renumbering effect may be replicated. Subtree rename must + * be supported, since renumbering a database will affect all its child + * overlays. + * + * modify: must be fully supported. + */ + int config_back_initialize( BackendInfo *bi ) { ConfigTable *ct = config_back_cf_table; char *argv[4]; int i; + static char *controls[] = { + LDAP_CONTROL_MANAGEDSAIT, + NULL + }; + + bi->bi_controls = controls; bi->bi_open = 0; bi->bi_close = 0; @@ -2881,9 +4025,9 @@ config_back_initialize( BackendInfo *bi ) bi->bi_op_unbind = 0; bi->bi_op_search = config_back_search; bi->bi_op_compare = 0; - bi->bi_op_modify = 0; - bi->bi_op_modrdn = 0; - bi->bi_op_add = 0; + bi->bi_op_modify = config_back_modify; + bi->bi_op_modrdn = config_back_modrdn; + bi->bi_op_add = config_back_add; bi->bi_op_delete = 0; bi->bi_op_abandon = 0; @@ -2898,34 +4042,23 @@ config_back_initialize( BackendInfo *bi ) for (i=0; OidMacros[i].name; i++ ) { argv[1] = OidMacros[i].name; argv[2] = OidMacros[i].oid; - parse_oidm( "slapd", i, 3, argv ); + parse_oidm( "slapd", i, 3, argv, 0, NULL ); } - i = init_config_attrs( ct ); + bi->bi_cf_table = ct; + + i = config_register_schema( ct, cf_ocs ); if ( i ) return i; /* set up the notable AttributeDescriptions */ - ads[0].sub = slap_schema.si_ad_attributeTypes; - ads[3].sub = slap_schema.si_ad_ditContentRules; - ads[5].sub = slap_schema.si_ad_objectClasses; - - bi->bi_cf_table = ct; - i = 0; for (;ct->name;ct++) { if (strcmp(ct->name, ads[i].name)) continue; - if (ads[i].sub) { - ct->ad = ads[i].sub; - } else { - *ads[i].desc = ct->ad; - } + *ads[i].desc = ct->ad; i++; if (!ads[i].name) break; } - /* set up the objectclasses */ - i = init_config_ocs( cf_ocs ); - - return i; + return 0; }