Simple values retrievable

This commit is contained in:
Howard Chu 2005-02-21 02:21:29 +00:00
parent c6f373bce1
commit 1895da7f52
3 changed files with 105 additions and 21 deletions

View File

@ -201,10 +201,12 @@ config_back_db_open( BackendDB *be )
struct berval rdn; struct berval rdn;
Entry *e, *parent; Entry *e, *parent;
CfEntryInfo *ce, *ceparent, *ceprev; CfEntryInfo *ce, *ceparent, *ceprev;
int i, buflen = 0; int i, rc, buflen = 0;
char *buf = NULL; char *buf = NULL;
BackendInfo *bi; BackendInfo *bi;
BackendDB *bptr; BackendDB *bptr;
ConfigArgs c;
ConfigTable *ct;
/* create root of tree */ /* create root of tree */
ber_str2bv( CONFIG_DN, STRLENOF( CONFIG_DN ), 0, &rdn ); ber_str2bv( CONFIG_DN, STRLENOF( CONFIG_DN ), 0, &rdn );
@ -214,6 +216,17 @@ config_back_db_open( BackendDB *be )
cfb->cb_root = ce; cfb->cb_root = ce;
config_build_entry( e, be->be_private, "olcGlobal", &rdn ); config_build_entry( e, be->be_private, "olcGlobal", &rdn );
c.be = be;
c.bi = be->bd_info;
ct = ce->ce_table;
for (ct=ce->ce_table; ct->name; ct++) {
if (!ct->ad) continue;
if (ct->arg_type & ARG_DB) continue;
rc = config_get_vals(ct, &c);
if (rc == LDAP_SUCCESS) {
attr_merge(e, ct->ad, c.rvalue_vals, c.rvalue_nvals);
}
}
parent = e; parent = e;
ceparent = ce; ceparent = ce;
@ -264,6 +277,18 @@ config_back_db_open( BackendDB *be )
ce->ce_table = bptr->be_cf_table; ce->ce_table = bptr->be_cf_table;
config_build_entry( e, bptr->be_private, "olcDatabaseConfig", config_build_entry( e, bptr->be_private, "olcDatabaseConfig",
&rdn ); &rdn );
c.be = bptr;
c.bi = bi;
ct = be->bd_info->bi_cf_table;
for (; ct->name; ct++) {
if (!ct->ad) continue;
if (!(ct->arg_type & (ARG_DB|ARG_MAY_DB))) continue;
rc = config_get_vals(ct, &c);
if (rc == LDAP_SUCCESS) {
attr_merge(e, ct->ad, c.rvalue_vals, c.rvalue_nvals);
}
}
if ( !ceparent->ce_kids ) { if ( !ceparent->ce_kids ) {
ceparent->ce_kids = ce; ceparent->ce_kids = ce;
} else { } else {

View File

@ -526,8 +526,9 @@ int parse_config_table(ConfigTable *Conf, ConfigArgs *c) {
return(ARG_BAD_CONF); return(ARG_BAD_CONF);
} }
if((arg_type & ARG_PRE_BI) && c->bi) { if((arg_type & ARG_PRE_BI) && c->bi) {
Debug(LDAP_DEBUG_CONFIG, "%s: keyword <%s> must appear before any backend declaration\n", Debug(LDAP_DEBUG_CONFIG, "%s: keyword <%s> must appear before any backend %sdeclaration\n",
c->log, Conf[i].name, 0); c->log, Conf[i].name, ((arg_type & ARG_PRE_DB)
? "or database " : "") );
return(ARG_BAD_CONF); return(ARG_BAD_CONF);
} }
if((arg_type & ARG_PRE_DB) && c->be && c->be != frontendDB) { if((arg_type & ARG_PRE_DB) && c->be && c->be != frontendDB) {
@ -546,10 +547,7 @@ int parse_config_table(ConfigTable *Conf, ConfigArgs *c) {
return(ARG_BAD_CONF); return(ARG_BAD_CONF);
} }
c->type = arg_user = (arg_type & ARGS_USERLAND); c->type = arg_user = (arg_type & ARGS_USERLAND);
c->value_int = c->value_long = c->value_ber_t = 0; memset(&c->values, 0, sizeof(c->values));
c->value_string = NULL;
BER_BVZERO( &c->value_dn );
BER_BVZERO( &c->value_ndn );
if(arg_type & ARGS_NUMERIC) { if(arg_type & ARGS_NUMERIC) {
int j; int j;
iarg = 0; larg = 0; barg = 0; iarg = 0; larg = 0; barg = 0;
@ -558,9 +556,11 @@ int parse_config_table(ConfigTable *Conf, ConfigArgs *c) {
case ARG_LONG: larg = atol(c->argv[1]); break; case ARG_LONG: larg = atol(c->argv[1]); break;
case ARG_BER_LEN_T: barg = (ber_len_t)atol(c->argv[1]); break; case ARG_BER_LEN_T: barg = (ber_len_t)atol(c->argv[1]); break;
case ARG_ON_OFF: case ARG_ON_OFF:
if(!strcasecmp(c->argv[1], "on")) { if(!strcasecmp(c->argv[1], "on") ||
!strcasecmp(c->argv[1], "true")) {
iarg = 1; iarg = 1;
} else if(!strcasecmp(c->argv[1], "off")) { } else if(!strcasecmp(c->argv[1], "off") ||
!strcasecmp(c->argv[1], "false")) {
iarg = 0; iarg = 0;
} else { } else {
Debug(LDAP_DEBUG_CONFIG, "%s: ignoring ", c->log, 0, 0); Debug(LDAP_DEBUG_CONFIG, "%s: ignoring ", c->log, 0, 0);
@ -578,12 +578,15 @@ int parse_config_table(ConfigTable *Conf, ConfigArgs *c) {
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[i].what, larg, Conf[i].name);
return(ARG_BAD_CONF); return(ARG_BAD_CONF);
} }
c->value_int = iarg; switch(arg_type & ARGS_NUMERIC) {
c->value_long = larg; case ARG_ON_OFF:
c->value_ber_t = barg; case ARG_INT: c->value_int = iarg; break;
} case ARG_LONG: c->value_long = larg; break;
if(arg_type & ARG_STRING) c->value_string = ch_strdup(c->argv[1]); case ARG_BER_LEN_T: c->value_ber_t = barg; break;
if(arg_type & ARG_DN) { }
} else if(arg_type & ARG_STRING) {
c->value_string = ch_strdup(c->argv[1]);
} else if(arg_type & ARG_DN) {
struct berval bv; struct berval bv;
ber_str2bv( c->argv[1], 0, 0, &bv ); ber_str2bv( c->argv[1], 0, 0, &bv );
rc = dnPrettyNormal( NULL, &bv, &c->value_dn, &c->value_ndn, NULL ); rc = dnPrettyNormal( NULL, &bv, &c->value_dn, &c->value_ndn, NULL );
@ -627,6 +630,46 @@ int parse_config_table(ConfigTable *Conf, ConfigArgs *c) {
return(arg_user); return(arg_user);
} }
int
config_get_vals(ConfigTable *cf, ConfigArgs *c)
{
int rc = 0;
struct berval bv;
memset(&c->values, 0, sizeof(c->values));
c->rvalue_vals = ch_calloc(2,sizeof(struct berval));
c->rvalue_nvals = NULL;
c->emit = 1;
if ( cf->arg_type & ARG_MAGIC ) {
#if 0
rc = (*((ConfigDriver*)cf->arg_item))(c);
if ( rc ) return rc;
#else
rc = 1;
#endif
} else {
switch(cf->arg_type & ARGS_POINTER) {
case ARG_ON_OFF:
case ARG_INT: c->value_int = *(int *)cf->arg_item; break;
case ARG_LONG: c->value_long = *(long *)cf->arg_item; break;
case ARG_BER_LEN_T: c->value_ber_t = *(ber_len_t *)cf->arg_item; break;
case ARG_STRING: c->value_string = *(char **)cf->arg_item; 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_ON_OFF: bv.bv_len = sprintf(bv.bv_val, "%s",
c->value_int ? "TRUE" : "FALSE"); break;
case ARG_STRING: ber_str2bv( c->value_string, 0, 0, &bv); break;
}
ber_bvarray_add(&c->rvalue_vals, &bv);
}
return rc;
}
int int
init_config_attrs(ConfigTable *ct) { init_config_attrs(ConfigTable *ct) {
LDAPAttributeType *at; LDAPAttributeType *at;

View File

@ -65,18 +65,33 @@ typedef struct config_args_s {
unsigned long lineno; unsigned long lineno;
char log[PATH_MAX + STRLENOF(": line 18446744073709551615") + 1]; char log[PATH_MAX + STRLENOF(": line 18446744073709551615") + 1];
int depth; int depth;
int value_int; /* parsed first val */ /* parsed first val for simple cases */
long value_long; /* for simple cases */ union {
ber_len_t value_ber_t; int v_int;
char *value_string; long v_long;
struct berval value_dn; ber_len_t v_ber_t;
struct berval value_ndn; char *v_string;
struct {
struct berval vdn_dn;
struct berval vdn_ndn;
} v_dn;
} values;
/* return values for emit mode */
BerVarray rvalue_vals;
BerVarray rvalue_nvals;
int emit; /* emit instead of setting */ int emit; /* emit instead of setting */
int type; /* ConfigTable.arg_type & ARGS_USERLAND */ int type; /* ConfigTable.arg_type & ARGS_USERLAND */
BackendDB *be; BackendDB *be;
BackendInfo *bi; BackendInfo *bi;
} ConfigArgs; } ConfigArgs;
#define value_int values.v_int
#define value_long values.v_long
#define value_ber_t values.v_ber_t
#define value_string values.v_string
#define value_dn values.v_dn.vdn_dn
#define value_ndn values.v_dn.vdn_ndn
typedef int (ConfigDriver)(ConfigArgs *c); typedef int (ConfigDriver)(ConfigArgs *c);
#ifdef SLAPD_MODULES #ifdef SLAPD_MODULES
@ -99,3 +114,4 @@ typedef struct ConfigFile {
} ConfigFile; } ConfigFile;
void config_back_init( ConfigFile *cfp, ConfigTable *ct ); void config_back_init( ConfigFile *cfp, ConfigTable *ct );
int config_get_vals(ConfigTable *ct, ConfigArgs *c);