From cb686a5eb7de3d9bcb357c186f7f95b2d8119414 Mon Sep 17 00:00:00 2001 From: Howard Chu Date: Sun, 1 May 2005 20:55:15 +0000 Subject: [PATCH] Fix config selection: if -f but no -F, just read config file if -f and -F, convert config file to config dir else, try reading config dir if no config dir, try config filE --- servers/slapd/bconfig.c | 79 +++++++++++++++++++++++--------------- servers/slapd/main.c | 12 ++---- servers/slapd/slapcommon.c | 4 +- 3 files changed, 55 insertions(+), 40 deletions(-) diff --git a/servers/slapd/bconfig.c b/servers/slapd/bconfig.c index 50e1b8214e..f32f8e9812 100644 --- a/servers/slapd/bconfig.c +++ b/servers/slapd/bconfig.c @@ -2369,7 +2369,7 @@ config_ldif_resp( Operation *op, SlapReply *rs ) /* Configure and read the underlying back-ldif store */ static int -config_setup_ldif( BackendDB *be, const char *dir ) { +config_setup_ldif( BackendDB *be, const char *dir, int readit ) { CfBackInfo *cfb = be->be_private; ConfigArgs c = {0}; ConfigTable *ct; @@ -2426,35 +2426,37 @@ config_setup_ldif( BackendDB *be, const char *dir ) { if ( backend_startup_one( &cfb->cb_db )) return 1; - op = (Operation *)opbuf; - connection_fake_init( &conn, op, cfb ); + if ( readit ) { + op = (Operation *)opbuf; + connection_fake_init( &conn, op, cfb ); - filter.f_desc = slap_schema.si_ad_objectClass; - - op->o_tag = LDAP_REQ_SEARCH; + filter.f_desc = slap_schema.si_ad_objectClass; - op->ors_filter = &filter; - op->ors_filterstr = filterstr; - op->ors_scope = LDAP_SCOPE_SUBTREE; + op->o_tag = LDAP_REQ_SEARCH; - op->o_dn = be->be_rootdn; - op->o_ndn = be->be_rootndn; + op->ors_filter = &filter; + op->ors_filterstr = filterstr; + op->ors_scope = LDAP_SCOPE_SUBTREE; - op->o_req_dn = be->be_suffix[0]; - op->o_req_ndn = be->be_nsuffix[0]; + op->o_dn = be->be_rootdn; + op->o_ndn = be->be_rootndn; - op->ors_tlimit = SLAP_NO_LIMIT; - op->ors_slimit = SLAP_NO_LIMIT; + op->o_req_dn = be->be_suffix[0]; + op->o_req_ndn = be->be_nsuffix[0]; - op->ors_attrs = slap_anlist_all_attributes; - op->ors_attrsonly = 0; + op->ors_tlimit = SLAP_NO_LIMIT; + op->ors_slimit = SLAP_NO_LIMIT; - op->o_callback = &cb; - cb.sc_private = cfb; + 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 ); + } - op->o_bd = &cfb->cb_db; - op->o_bd->be_search( op, &rs ); - cfb->cb_use_ldif = 1; return 0; @@ -2505,15 +2507,32 @@ read_config(const char *fname, const char *dir) { cfb = be->be_private; - /* Setup the underlying back-ldif backend */ - if ( config_setup_ldif( be, dir )) - return 1; + /* If no .conf, or a dir was specified, setup the dir */ + if ( !fname || dir ) { + if ( dir ) { + /* If explicitly given, check for existence */ + struct stat st; + + if ( stat( dir, &st ) < 0 ) { + Debug( LDAP_DEBUG_ANY, + "invalid config directory %s, error %d\n", + dir, errno, 0 ); + return 1; + } + } else { + dir = SLAPD_DEFAULT_CONFIGDIR; + } + /* if fname is defaulted, try reading .d */ + if ( config_setup_ldif( be, dir, !fname )) + 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 + /* If we read the config from back-ldif, nothing to do here */ + if ( cfb->cb_got_ldif ) + return 0; + } + + if ( !fname ) + fname = SLAPD_DEFAULT_CONFIGFILE; ber_str2bv( fname, 0, 1, &cf_prv.c_file ); return read_config_file(fname, 0, NULL); diff --git a/servers/slapd/main.c b/servers/slapd/main.c index 8ba7f78291..98857b275d 100644 --- a/servers/slapd/main.c +++ b/servers/slapd/main.c @@ -252,13 +252,8 @@ int main( int argc, char **argv ) int g_argc = argc; char **g_argv = argv; -#ifdef HAVE_NT_SERVICE_MANAGER - char *configfile = ".\\slapd.conf"; - char *configdir = ".\\slapd.d"; -#else - char *configfile = SLAPD_DEFAULT_CONFIGFILE; - char *configdir = SLAPD_DEFAULT_CONFIGDIR; -#endif + char *configfile = NULL; + char *configdir = NULL; char *serverName; int serverMode = SLAP_SERVER_MODE; @@ -778,7 +773,8 @@ unhandled_option:; #ifdef HAVE_NT_EVENT_LOG if (is_NT_Service) - lutil_LogStartedEvent( serverName, slap_debug, configfile, urls ); + lutil_LogStartedEvent( serverName, slap_debug, configfile ? + configfile : SLAPD_DEFAULT_CONFIGFILE , urls ); #endif rc = slapd_daemon(); diff --git a/servers/slapd/slapcommon.c b/servers/slapd/slapcommon.c index 10a1548ec6..48122b53d1 100644 --- a/servers/slapd/slapcommon.c +++ b/servers/slapd/slapcommon.c @@ -166,8 +166,8 @@ slap_tool_init( int argc, char **argv ) { char *options; - char *conffile = SLAPD_DEFAULT_CONFIGFILE; - char *confdir = SLAPD_DEFAULT_CONFIGDIR; + char *conffile = NULL; + char *confdir = NULL; struct berval base = BER_BVNULL; char *filterstr = NULL; char *subtree = NULL; -- 2.39.5