Commit bc4564ca authored by Howard Chu's avatar Howard Chu
Browse files

More back-config / back-ldif integration, added config_generic_wrapper,

added -F option to specify config directory
parent f682ee09
......@@ -122,7 +122,7 @@ static ConfigOCs bdbocs[] = {
static int
bdb_cf_oc(ConfigArgs *c)
{
if ( c->emit ) {
if ( c->op == SLAP_CONFIG_EMIT ) {
value_add_one( &c->rvalue_vals, &bdb_oc->soc_cname );
return 0;
}
......@@ -144,7 +144,7 @@ bdb_cf_gen(ConfigArgs *c)
struct bdb_info *bdb = c->be->be_private;
int rc;
if ( c->emit ) {
if ( c->op == SLAP_CONFIG_EMIT ) {
rc = 0;
switch( c->type ) {
case BDB_CHKPT:
......@@ -246,22 +246,3 @@ int bdb_back_init_cf( BackendInfo *bi )
rc = init_config_ocs( bdbocs );
return rc;
}
int bdb_db_config( Backend *be, const char *fname, int lineno, int argc,
char **argv )
{
ConfigArgs c = { 0 };
int rc;
c.be = be;
c.fname = fname;
c.lineno = lineno;
c.argc = argc;
c.argv = argv;
sprintf( c.log, "%s: line %lu", fname, lineno );
rc = parse_config_table( bdbcfg, &c );
if ( rc == ARG_UNKNOWN )
rc = SLAP_CONF_UNKNOWN;
return rc;
}
......@@ -536,7 +536,7 @@ bdb_back_initialize(
bi->bi_destroy = 0;
bi->bi_db_init = bdb_db_init;
bi->bi_db_config = bdb_db_config;
bi->bi_db_config = config_generic_wrapper;
bi->bi_db_open = bdb_db_open;
bi->bi_db_close = bdb_db_close;
bi->bi_db_destroy = bdb_db_destroy;
......
......@@ -29,6 +29,7 @@
#include <ac/unistd.h>
#include "slap.h"
#include "lutil.h"
#include "config.h"
struct ldif_info {
struct berval li_base_path;
......@@ -43,6 +44,43 @@ struct ldif_info {
#define ENTRY_BUFF_INCREMENT 500
static ObjectClass *ldif_oc;
static ConfigDriver ldif_cf;
static ConfigTable ldifcfg[] = {
{ "", "", 0, 0, 0, ARG_MAGIC,
ldif_cf, NULL, NULL, NULL },
{ "directory", "dir", 2, 2, 0, ARG_BERVAL|ARG_OFFSET,
(void *)offsetof(struct ldif_info, li_base_path),
"( OLcfgAt:1.1 NAME 'dbDirectory' "
"DESC 'Directory for database content' "
"EQUALITY caseIgnoreMatch "
"SYNTAX OMsDirectoryString )", NULL, NULL },
{ NULL, NULL, 0, 0, 0, ARG_IGNORED,
NULL, NULL, NULL, NULL }
};
static ConfigOCs ldifocs[] = {
{ "( OLcfgOc:2.1 "
"NAME 'ldifConfig' "
"DESC 'LDIF backend configuration' "
"AUXILIARY "
"MAY ( dbDirectory ) )",
&ldif_oc },
{ NULL, NULL }
};
static int
ldif_cf( ConfigArgs *c )
{
if ( c->op == SLAP_CONFIG_EMIT ) {
value_add_one( &c->rvalue_vals, &ldif_oc->soc_cname );
return 0;
}
return 1;
}
static char *
dn2path(struct berval * dn, struct berval * rootdn, struct berval * base_path)
{
......@@ -552,7 +590,7 @@ static int ldif_back_modify(Operation *op, SlapReply *rs) {
SLAP_FREE(path);
if(entry != NULL)
entry_free(entry);
rs->sr_text = "";
rs->sr_text = NULL;
ldap_pvt_thread_mutex_unlock(&ni->li_mutex);
ldap_pvt_thread_mutex_unlock(&entry2str_mutex);
send_ldap_result(op, rs);
......@@ -883,31 +921,6 @@ static ID ldif_tool_entry_put(BackendDB * be, Entry * e, struct berval *text) {
return NOID;
}
static int
ldif_back_db_config(
BackendDB *be,
const char *fname,
int lineno,
int argc,
char **argv )
{
struct ldif_info *ni = (struct ldif_info *) be->be_private;
if ( strcasecmp( argv[0], "directory" ) == 0 ) {
if ( argc < 2 ) {
fprintf( stderr,
"%s: line %d: missing <path> in \"directory <path>\" line\n",
fname, lineno );
return 1;
}
ber_str2bv(argv[1], 0, 1, &ni->li_base_path);
} else {
return SLAP_CONF_UNKNOWN;
}
return 0;
}
static int
ldif_back_db_init( BackendDB *be )
{
......@@ -915,6 +928,7 @@ ldif_back_db_init( BackendDB *be )
ni = ch_calloc( 1, sizeof(struct ldif_info) );
be->be_private = ni;
be->be_cf_table = be->bd_info->bi_cf_table;
ldap_pvt_thread_mutex_init(&ni->li_mutex);
return 0;
}
......@@ -948,13 +962,17 @@ ldif_back_initialize(
BackendInfo *bi
)
{
int rc;
bi->bi_cf_table = ldifcfg;
bi->bi_open = 0;
bi->bi_close = 0;
bi->bi_config = 0;
bi->bi_destroy = 0;
bi->bi_db_init = ldif_back_db_init;
bi->bi_db_config = ldif_back_db_config;
bi->bi_db_config = config_generic_wrapper;
bi->bi_db_open = ldif_back_db_open;
bi->bi_db_close = 0;
bi->bi_db_destroy = ldif_back_db_destroy;
......@@ -989,5 +1007,9 @@ ldif_back_initialize(
bi->bi_tool_id2entry_get = 0;
bi->bi_tool_entry_modify = 0;
return 0;
rc = init_config_attrs( ldifcfg );
if ( rc ) return rc;
ldifcfg[0].ad = slap_schema.si_ad_objectClass;
rc = init_config_ocs( ldifocs );
return rc;
}
This diff is collapsed.
......@@ -103,55 +103,61 @@ new_config_args( BackendDB *be, const char *fname, int lineno, int argc, char **
return(c);
}
int parse_config_table(ConfigTable *Conf, ConfigArgs *c) {
ConfigTable *config_find_keyword(ConfigTable *Conf, ConfigArgs *c) {
int i;
for(i = 0; Conf[i].name; i++)
if( (Conf[i].length && (!strncasecmp(c->argv[0], Conf[i].name, Conf[i].length))) ||
(!strcasecmp(c->argv[0], Conf[i].name)) ) break;
if ( !Conf[i].name ) return NULL;
return Conf+i;
}
int config_add_vals(ConfigTable *Conf, ConfigArgs *c) {
int i, rc, arg_user, arg_type, iarg;
long larg;
ber_len_t barg;
void *ptr;
for(i = 0; Conf[i].name; i++)
if( (Conf[i].length && (!strncasecmp(c->argv[0], Conf[i].name, Conf[i].length))) ||
(!strcasecmp(c->argv[0], Conf[i].name)) ) break;
if(!Conf[i].name) return(ARG_UNKNOWN);
arg_type = Conf[i].arg_type;
arg_type = Conf->arg_type;
if(arg_type == ARG_IGNORED) {
Debug(LDAP_DEBUG_CONFIG, "%s: keyword <%s> ignored\n",
c->log, Conf[i].name, 0);
c->log, Conf->name, 0);
return(0);
}
if(Conf[i].min_args && (c->argc < Conf[i].min_args)) {
if(Conf->min_args && (c->argc < Conf->min_args)) {
Debug(LDAP_DEBUG_CONFIG, "%s: keyword <%s> missing <%s> argument\n",
c->log, Conf[i].name, Conf[i].what);
c->log, Conf->name, Conf->what);
return(ARG_BAD_CONF);
}
if(Conf[i].max_args && (c->argc > Conf[i].max_args)) {
if(Conf->max_args && (c->argc > Conf->max_args)) {
Debug(LDAP_DEBUG_CONFIG, "%s: extra cruft after <%s> in <%s> line (ignored)\n",
c->log, Conf[i].what, Conf[i].name);
c->log, Conf->what, Conf->name);
}
if((arg_type & ARG_DB) && !c->be) {
Debug(LDAP_DEBUG_CONFIG, "%s: keyword <%s> allowed only within database declaration\n",
c->log, Conf[i].name, 0);
c->log, Conf->name, 0);
return(ARG_BAD_CONF);
}
if((arg_type & ARG_PRE_BI) && c->bi) {
Debug(LDAP_DEBUG_CONFIG, "%s: keyword <%s> must appear before any backend %sdeclaration\n",
c->log, Conf[i].name, ((arg_type & ARG_PRE_DB)
c->log, Conf->name, ((arg_type & ARG_PRE_DB)
? "or database " : "") );
return(ARG_BAD_CONF);
}
if((arg_type & ARG_PRE_DB) && c->be && c->be != frontendDB) {
Debug(LDAP_DEBUG_CONFIG, "%s: keyword <%s> must appear before any database declaration\n",
c->log, Conf[i].name, 0);
c->log, Conf->name, 0);
return(ARG_BAD_CONF);
}
if((arg_type & ARG_PAREN) && *c->argv[1] != '(' /*')'*/) {
Debug(LDAP_DEBUG_CONFIG, "%s: old <%s> format not supported\n",
c->log, Conf[i].name, 0);
c->log, Conf->name, 0);
return(ARG_BAD_CONF);
}
if((arg_type & ARGS_POINTER) && !Conf[i].arg_item) {
if((arg_type & ARGS_POINTER) && !Conf->arg_item && !(arg_type & ARG_OFFSET)) {
Debug(LDAP_DEBUG_CONFIG, "%s: null arg_item for <%s>\n",
c->log, Conf[i].name, 0);
c->log, Conf->name, 0);
return(ARG_BAD_CONF);
}
c->type = arg_user = (arg_type & ARGS_USERLAND);
......@@ -175,7 +181,7 @@ int parse_config_table(ConfigTable *Conf, ConfigArgs *c) {
} else {
Debug(LDAP_DEBUG_CONFIG, "%s: ignoring ", c->log, 0, 0);
Debug(LDAP_DEBUG_CONFIG, "invalid %s value (%s) in <%s> line\n",
Conf[i].what, c->argv[1], Conf[i].name);
Conf->what, c->argv[1], Conf->name);
return(0);
}
break;
......@@ -184,7 +190,7 @@ int parse_config_table(ConfigTable *Conf, ConfigArgs *c) {
if(iarg < j || larg < j || barg < j ) {
larg = larg ? larg : (barg ? barg : iarg);
Debug(LDAP_DEBUG_CONFIG, "%s: " , c->log, 0, 0);
Debug(LDAP_DEBUG_CONFIG, "invalid %s value (%ld) in <%s> line\n", Conf[i].what, larg, Conf[i].name);
Debug(LDAP_DEBUG_CONFIG, "invalid %s value (%ld) in <%s> line\n", Conf->what, larg, Conf->name);
return(ARG_BAD_CONF);
}
switch(arg_type & ARGS_NUMERIC) {
......@@ -194,7 +200,9 @@ int parse_config_table(ConfigTable *Conf, ConfigArgs *c) {
case ARG_BER_LEN_T: c->value_ber_t = barg; break;
}
} else if(arg_type & ARG_STRING) {
c->value_string = ch_strdup(c->argv[1]);
c->value_string = ch_strdup(c->argv[1]);
} else if(arg_type & ARG_BERVAL) {
ber_str2bv( c->argv[1], 0, 1, &c->value_bv );
} else if(arg_type & ARG_DN) {
struct berval bv;
ber_str2bv( c->argv[1], 0, 0, &bv );
......@@ -202,17 +210,17 @@ int parse_config_table(ConfigTable *Conf, ConfigArgs *c) {
if ( rc != LDAP_SUCCESS ) {
Debug(LDAP_DEBUG_CONFIG, "%s: " , c->log, 0, 0);
Debug(LDAP_DEBUG_CONFIG, "%s DN is invalid %d (%s)\n",
Conf[i].name, rc, ldap_err2string( rc ));
Conf->name, rc, ldap_err2string( rc ));
return(ARG_BAD_CONF);
}
}
if(arg_type & ARG_MAGIC) {
if(!c->be) c->be = frontendDB;
rc = (*((ConfigDriver*)Conf[i].arg_item))(c);
rc = (*((ConfigDriver*)Conf->arg_item))(c);
if(c->be == frontendDB) c->be = NULL;
if(rc) {
Debug(LDAP_DEBUG_CONFIG, "%s: handler for <%s> exited with %d!",
c->log, Conf[i].name, rc);
c->log, Conf->name, rc);
return(ARG_BAD_CONF);
}
return(0);
......@@ -224,14 +232,15 @@ int parse_config_table(ConfigTable *Conf, ConfigArgs *c) {
ptr = c->bi->bi_private;
else {
Debug(LDAP_DEBUG_CONFIG, "%s: offset for <%s> missing base pointer!",
c->log, Conf[i].name, 0);
c->log, Conf->name, 0);
return(ARG_BAD_CONF);
}
ptr = (void *)((char *)ptr + (int)Conf[i].arg_item);
ptr = (void *)((char *)ptr + (int)Conf->arg_item);
} else if (arg_type & ARGS_POINTER) {
ptr = Conf[i].arg_item;
ptr = Conf->arg_item;
}
if(arg_type & ARGS_POINTER) switch(arg_type & ARGS_POINTER) {
if(arg_type & ARGS_POINTER)
switch(arg_type & ARGS_POINTER) {
case ARG_ON_OFF:
case ARG_INT: *(int*)ptr = iarg; break;
case ARG_LONG: *(long*)ptr = larg; break;
......@@ -241,7 +250,7 @@ int parse_config_table(ConfigTable *Conf, ConfigArgs *c) {
if(cc) {
if (arg_type & ARG_UNIQUE) {
Debug(LDAP_DEBUG_CONFIG, "%s: already set %s!\n",
c->log, Conf[i].name, 0 );
c->log, Conf->name, 0 );
return(ARG_BAD_CONF);
}
ch_free(cc); /* potential memory leak */
......@@ -249,10 +258,19 @@ int parse_config_table(ConfigTable *Conf, ConfigArgs *c) {
*(char **)ptr = c->value_string;
break;
}
}
case ARG_BERVAL:
*(struct berval *)ptr = c->value_bv;
break;
}
return(arg_user);
}
int
config_del_vals(ConfigTable *cf, ConfigArgs *c)
{
int rc = 0;
}
int
config_get_vals(ConfigTable *cf, ConfigArgs *c)
{
......@@ -267,7 +285,7 @@ config_get_vals(ConfigTable *cf, ConfigArgs *c)
memset(&c->values, 0, sizeof(c->values));
c->rvalue_vals = NULL;
c->rvalue_nvals = NULL;
c->emit = 1;
c->op = SLAP_CONFIG_EMIT;
c->type = cf->arg_type & ARGS_USERLAND;
if ( cf->arg_type & ARG_MAGIC ) {
......@@ -295,14 +313,16 @@ config_get_vals(ConfigTable *cf, ConfigArgs *c)
if ( *(char **)ptr )
c->value_string = ch_strdup(*(char **)ptr);
break;
case ARG_BERVAL:
ber_dupbv( &c->value_bv, (struct berval *)ptr ); break;
}
}
if ( cf->arg_type & ARGS_POINTER) {
bv.bv_val = c->log;
switch(cf->arg_type & ARGS_POINTER) {
case ARG_INT: bv.bv_len = sprintf(bv.bv_val, "%d", c->value_int); break;
case ARG_LONG: bv.bv_len = sprintf(bv.bv_val, "%l", c->value_long); break;
case ARG_BER_LEN_T: bv.bv_len =sprintf(bv.bv_val, "%l",c->value_ber_t); break;
case ARG_LONG: bv.bv_len = sprintf(bv.bv_val, "%ld", c->value_long); break;
case ARG_BER_LEN_T: bv.bv_len = sprintf(bv.bv_val, "%ld", c->value_ber_t); break;
case ARG_ON_OFF: bv.bv_len = sprintf(bv.bv_val, "%s",
c->value_int ? "TRUE" : "FALSE"); break;
case ARG_STRING:
......@@ -312,6 +332,13 @@ config_get_vals(ConfigTable *cf, ConfigArgs *c)
return 1;
}
break;
case ARG_BERVAL:
if ( !BER_BVISEMPTY( &c->value_bv )) {
bv = c->value_bv;
} else {
return 1;
}
break;
}
if (( cf->arg_type & ARGS_POINTER ) == ARG_STRING )
ber_bvarray_add(&c->rvalue_vals, &bv);
......@@ -388,6 +415,7 @@ int
read_config_file(const char *fname, int depth, ConfigArgs *cf)
{
FILE *fp;
ConfigTable *ct;
ConfigArgs *c;
int rc;
......@@ -439,58 +467,67 @@ read_config_file(const char *fname, int depth, ConfigArgs *cf)
continue;
}
rc = parse_config_table( config_back_cf_table, c );
if ( !rc ) {
continue;
}
if ( rc & ARGS_USERLAND ) {
switch(rc) { /* XXX a usertype would be opaque here */
default:
Debug(LDAP_DEBUG_CONFIG, "%s: unknown user type <%d>\n",
c->log, *c->argv, 0);
c->op = LDAP_MOD_ADD;
ct = config_find_keyword( config_back_cf_table, c );
if ( ct ) {
rc = config_add_vals( ct, c );
if ( !rc ) continue;
if ( rc & ARGS_USERLAND ) {
/* XXX a usertype would be opaque here */
Debug(LDAP_DEBUG_CONFIG, "%s: unknown user type <%s>\n",
c->log, c->argv[0], 0);
goto badline;
}
} else if ( rc == ARG_BAD_CONF || rc != ARG_UNKNOWN ) {
goto badline;
} else if ( rc == ARG_BAD_CONF ) {
goto badline;
}
} else if ( c->bi && c->bi->bi_config ) { /* XXX to check: could both be/bi_config? oops */
rc = (*c->bi->bi_config)(c->bi, c->fname, c->lineno, c->argc, c->argv);
} else if ( c->bi ) {
rc = SLAP_CONF_UNKNOWN;
if ( c->bi->bi_cf_table ) {
ct = config_find_keyword( c->bi->bi_cf_table, c );
if ( ct ) {
rc = config_add_vals( ct, c );
}
} else if ( c->bi->bi_config ) {
rc = (*c->bi->bi_config)(c->bi, c->fname, c->lineno,
c->argc, c->argv);
}
if ( rc ) {
switch(rc) {
case SLAP_CONF_UNKNOWN:
Debug(LDAP_DEBUG_CONFIG, "%s: "
"unknown directive <%s> inside backend info definition (ignored)\n",
c->log, *c->argv, 0);
c->log, *c->argv, 0);
continue;
default:
goto badline;
}
}
} else if ( c->be ) {
rc = SLAP_CONF_UNKNOWN;
if ( c->be->be_cf_table ) {
rc = parse_config_table( c->be->be_cf_table, c );
if ( !rc ) continue;
if ( rc != ARG_UNKNOWN ) goto badline;
}
if ( c->be->be_config ) {
ct = config_find_keyword( c->be->be_cf_table, c );
if ( ct ) {
rc = config_add_vals( ct, c );
}
} else if ( c->be->be_config ) {
rc = (*c->be->be_config)(c->be, c->fname, c->lineno,
c->argc, c->argv);
if ( rc ) {
switch(rc) {
case SLAP_CONF_UNKNOWN:
Debug( LDAP_DEBUG_CONFIG, "%s: "
"unknown directive <%s> inside backend database "
"definition (ignored)\n",
c->log, *c->argv, 0);
continue;
default:
goto badline;
}
}
if ( rc ) {
switch(rc) {
case SLAP_CONF_UNKNOWN:
Debug( LDAP_DEBUG_CONFIG, "%s: "
"unknown directive <%s> inside backend database "
"definition (ignored)\n",
c->log, *c->argv, 0);
continue;
default:
goto badline;
}
}
......@@ -929,3 +966,24 @@ slap_str2clist( char ***out, char *in, const char *brkstr )
free( str );
return( *out );
}
int config_generic_wrapper( Backend *be, const char *fname, int lineno,
int argc, char **argv )
{
ConfigArgs c = { 0 };
ConfigTable *ct;
int rc;
c.be = be;
c.fname = fname;
c.lineno = lineno;
c.argc = argc;
c.argv = argv;
sprintf( c.log, "%s: line %lu", fname, lineno );
rc = SLAP_CONF_UNKNOWN;
ct = config_find_keyword( be->be_cf_table, &c );
if ( ct )
rc = config_add_vals( ct, &c );
return rc;
}
......@@ -29,15 +29,15 @@ typedef struct ConfigTable {
#define ARGS_USERLAND 0x00000fff
#define ARGS_TYPES 0x000ff000
#define ARGS_POINTER 0x0001f000
#define ARGS_POINTER 0x0003f000
#define ARGS_NUMERIC 0x0000f000
#define ARG_INT 0x00001000
#define ARG_LONG 0x00002000
#define ARG_BER_LEN_T 0x00004000
#define ARG_ON_OFF 0x00008000
#define ARG_STRING 0x00010000
#define ARG_DN 0x00020000
#define ARG_EXISTS 0x00040000 /* XXX not yet */
#define ARG_BERVAL 0x00020000
#define ARG_DN 0x00040000
#define ARG_IGNORED 0x00080000
#define ARGS_SYNTAX 0xfff00000
......@@ -77,6 +77,7 @@ typedef struct config_args_s {
long v_long;
ber_len_t v_ber_t;
char *v_string;
struct berval v_bv;
struct {
struct berval vdn_dn;
struct berval vdn_ndn;
......@@ -85,7 +86,8 @@ typedef struct config_args_s {
/* return values for emit mode */
BerVarray rvalue_vals;
BerVarray rvalue_nvals;
int emit; /* emit instead of setting */
#define SLAP_CONFIG_EMIT 0x2000 /* emit instead of set */
int op;
int type; /* ConfigTable.arg_type & ARGS_USERLAND */
BackendDB *be;
BackendInfo *bi;
......@@ -95,9 +97,12 @@ typedef struct config_args_s {
#define value_long values.v_long
#define value_ber_t values.v_ber_t
#define value_string values.v_string
#define value_bv values.v_bv
#define value_dn values.v_dn.vdn_dn
#define value_ndn values.v_dn.vdn_ndn
typedef int (ConfigDriver)(ConfigArgs *c);
int config_get_vals(ConfigTable *ct, ConfigArgs *c);
int config_add_vals(ConfigTable *ct, ConfigArgs *c);
ConfigTable * config_find_keyword(ConfigTable *ct, ConfigArgs *c);
......@@ -253,8 +253,10 @@ int main( int argc, char **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 *serverName;
int serverMode = SLAP_SERVER_MODE;
......@@ -288,6 +290,7 @@ int main( int argc, char **argv )
{
int *i;
char *newConfigFile;
char *newConfigDir;
char *newUrls;
char *regService = NULL;
......@@ -319,11 +322,17 @@ int main( int argc, char **argv )
configfile = newConfigFile;
Debug ( LDAP_DEBUG_ANY, "new config file from registry is: %s\n", configfile, 0, 0 );
}
newConfigDir = (char*)lutil_getRegParam( regService, "ConfigDir" );