More verbmasks cleanup, added index unparsing

This commit is contained in:
Howard Chu 2005-03-02 16:35:59 +00:00
parent 530e93f96e
commit 74e38c0ad4
8 changed files with 189 additions and 114 deletions

View File

@ -23,6 +23,7 @@
#include "slap.h"
#include "back-bdb.h"
#include "lutil.h"
/* for the cache of attribute information (which are indexed, etc.) */
typedef struct bdb_attrinfo {
@ -296,6 +297,39 @@ bdb_attr_index_config(
return LDAP_SUCCESS;
}
static int
bdb_attr_index_unparser( void *v1, void *v2 )
{
AttrInfo *ai = v1;
BerVarray *bva = v2;
struct berval bv;
char *ptr;
slap_index2bvlen( ai->ai_indexmask, &bv );
if ( bv.bv_len ) {
bv.bv_len += ai->ai_desc->ad_cname.bv_len + 1;
ptr = ch_malloc( bv.bv_len+1 );
bv.bv_val = lutil_strcopy( ptr, ai->ai_desc->ad_cname.bv_val );
*bv.bv_val++ = ' ';
slap_index2bv( ai->ai_indexmask, &bv );
bv.bv_val = ptr;
ber_bvarray_add( bva, &bv );
}
}
static AttributeDescription addef = { NULL, NULL, BER_BVC("default") };
static AttrInfo aidef = { &addef };
void
bdb_attr_index_unparse( struct bdb_info *bdb, BerVarray *bva )
{
if ( bdb->bi_defaultmask ) {
aidef.ai_indexmask = bdb->bi_defaultmask;
bdb_attr_index_unparser( &aidef, bva );
}
avl_apply( bdb->bi_attrs, bdb_attr_index_unparser, bva, -1, AVL_INORDER );
}
void
bdb_attr_index_destroy( Avlnode *tree )
{

View File

@ -130,12 +130,12 @@ bdb_cf_oc(ConfigArgs *c)
}
static slap_verbmasks bdb_lockd[] = {
{ "default", DB_LOCK_DEFAULT },
{ "oldest", DB_LOCK_OLDEST },
{ "random", DB_LOCK_RANDOM },
{ "youngest", DB_LOCK_YOUNGEST },
{ "fewest", DB_LOCK_MINLOCKS },
{ NULL, 0 }
{ BER_BVC("default"), DB_LOCK_DEFAULT },
{ BER_BVC("oldest"), DB_LOCK_OLDEST },
{ BER_BVC("random"), DB_LOCK_RANDOM },
{ BER_BVC("youngest"), DB_LOCK_YOUNGEST },
{ BER_BVC("fewest"), DB_LOCK_MINLOCKS },
{ BER_BVNULL, 0 }
};
static int
@ -166,18 +166,17 @@ bdb_cf_gen(ConfigArgs *c)
break;
case BDB_INDEX:
rc = 1;
bdb_attr_index_unparse( bdb, &c->rvalue_vals );
if ( !c->rvalue_vals ) rc = 1;
break;
case BDB_LOCKD:
rc = 1;
if ( bdb->bi_lock_detect != DB_LOCK_DEFAULT ) {
int i;
for (i=0; bdb_lockd[i].word; i++) {
for (i=0; !BER_BVISNULL(&bdb_lockd[i].word); i++) {
if ( bdb->bi_lock_detect == bdb_lockd[i].mask ) {
struct berval bv;
ber_str2bv( bdb_lockd[i].word, 0, 1, &bv );
ber_bvarray_add( &c->rvalue_vals, &bv );
value_add_one( &c->rvalue_vals, &bdb_lockd[i].word );
rc = 0;
break;
}
@ -214,7 +213,7 @@ bdb_cf_gen(ConfigArgs *c)
case BDB_LOCKD:
rc = verb_to_mask( c->argv[1], bdb_lockd );
if ( !bdb_lockd[rc].word ) {
if ( BER_BVISNULL(&bdb_lockd[rc].word) ) {
fprintf( stderr, "%s: "
"bad policy (%s) in \"lockDetect <policy>\" line\n",
c->log, c->argv[1] );

View File

@ -33,6 +33,7 @@ LDAP_BEGIN_DECL
#define bdb_attr_mask BDB_SYMBOL(attr_mask)
#define bdb_attr_index_config BDB_SYMBOL(attr_index_config)
#define bdb_attr_index_destroy BDB_SYMBOL(attr_index_destroy)
#define bdb_attr_index_unparse BDB_SYMBOL(attr_index_unparse)
#ifdef LDAP_COMP_MATCH
#define bdb_attr_comp_ref BDB_SYMBOL(attr_comp_ref)
@ -54,6 +55,7 @@ int bdb_attr_index_config LDAP_P(( struct bdb_info *bdb,
const char *fname, int lineno,
int argc, char **argv ));
void bdb_attr_index_unparse LDAP_P(( struct bdb_info *bdb, BerVarray *bva ));
void bdb_attr_index_destroy LDAP_P(( Avlnode *tree ));
/*

View File

@ -1324,22 +1324,22 @@ config_restrict(ConfigArgs *c) {
slap_mask_t restrictops = 0;
int i;
slap_verbmasks 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 }
{ 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) {
@ -1364,11 +1364,11 @@ config_allows(ConfigArgs *c) {
slap_mask_t allows = 0;
int i;
slap_verbmasks 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 }
{ 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( allowable_ops, global_allows, &c->rvalue_vals );
@ -1389,12 +1389,12 @@ config_disallows(ConfigArgs *c) {
slap_mask_t disallows = 0;
int i;
slap_verbmasks 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 }
{ 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( disallowable_ops, global_disallows, &c->rvalue_vals );
@ -1415,12 +1415,12 @@ config_requires(ConfigArgs *c) {
slap_mask_t requires = 0;
int i;
slap_verbmasks 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 }
{ 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( requires_ops, c->be->be_requires, &c->rvalue_vals );
@ -1441,22 +1441,22 @@ config_loglevel(ConfigArgs *c) {
int i;
char *next;
slap_verbmasks 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 }
{ 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) {
@ -1479,7 +1479,7 @@ config_loglevel(ConfigArgs *c) {
}
} else {
int j = verb_to_mask(c->argv[i], loglevel_ops);
if(!loglevel_ops[j].word) {
if(BER_BVISNULL(&loglevel_ops[j].word)) {
Debug( LDAP_DEBUG_ANY,
"%s: unknown level \"%s\" "
"in \"loglevel <level> [...]\" line.\n",
@ -1906,17 +1906,17 @@ static int
config_tls_config(ConfigArgs *c) {
int i, flag;
slap_verbmasks crlkeys[] = {
{ "none", LDAP_OPT_X_TLS_CRL_NONE },
{ "peer", LDAP_OPT_X_TLS_CRL_PEER },
{ "all", LDAP_OPT_X_TLS_CRL_ALL },
{ NULL, 0 }
{ 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 }
};
slap_verbmasks 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 }
{ 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
@ -1931,9 +1931,9 @@ config_tls_config(ConfigArgs *c) {
}
if (c->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;
}
}

View File

@ -551,8 +551,8 @@ badline:
int
verb_to_mask(const char *word, slap_verbmasks *v) {
int i;
for(i = 0; v[i].word; i++)
if(!strcasecmp(word, v[i].word))
for(i = 0; !BER_BVISNULL(&v[i].word); i++)
if(!strcasecmp(word, v[i].word.bv_val))
break;
return(i);
}
@ -562,7 +562,7 @@ verbs_to_mask(int argc, char *argv[], slap_verbmasks *v, slap_mask_t *m) {
int i, j;
for(i = 1; i < argc; i++) {
j = verb_to_mask(argv[i], v);
if(!v[j].word) return(1);
if(BER_BVISNULL(&v[j].word)) return(1);
while (!v[j].mask) j--;
*m |= v[j].mask;
}
@ -575,28 +575,28 @@ mask_to_verbs(slap_verbmasks *v, slap_mask_t m, BerVarray *bva) {
struct berval bv;
if (!m) return 1;
for (i=0; v[i].word; i++) {
for (i=0; !BER_BVISNULL(&v[i].word); i++) {
if (!v[i].mask) continue;
if (( m & v[i].mask ) == v[i].mask ) {
ber_str2bv( v[i].word, 0, 0, &bv );
value_add_one( bva, &bv );
value_add_one( bva, &v[i].word );
}
}
return 0;
}
static slap_verbmasks tlskey[] = {
{ "no", SB_TLS_OFF },
{ "yes", SB_TLS_ON },
{ "critical", SB_TLS_CRITICAL }
{ BER_BVC("no"), SB_TLS_OFF },
{ BER_BVC("yes"), SB_TLS_ON },
{ BER_BVC("critical"), SB_TLS_CRITICAL },
{ BER_BVNULL, 0 }
};
static slap_verbmasks methkey[] = {
{ "simple", LDAP_AUTH_SIMPLE },
{ BER_BVC("simple"), LDAP_AUTH_SIMPLE },
#ifdef HAVE_CYRUS_SASL
{ "sasl", LDAP_AUTH_SASL },
{ BER_BVC("sasl"), LDAP_AUTH_SASL },
#endif
{ NULL, 0 }
{ BER_BVNULL, 0 }
};
typedef struct cf_aux_table {
@ -630,8 +630,8 @@ int bindconf_parse( const char *word, slap_bindconf *bc ) {
if ( tab->aux ) {
int j;
rc = 1;
for (j=0; tab->aux[j].word; j++) {
if (!strcasecmp(word+tab->key.bv_len, tab->aux[j].word)) {
for (j=0; !BER_BVISNULL(&tab->aux[j].word); j++) {
if (!strcasecmp(word+tab->key.bv_len, tab->aux[j].word.bv_val)) {
int *ptr = (int *)cptr;
*ptr = tab->aux[j].mask;
rc = 0;
@ -661,11 +661,11 @@ int bindconf_unparse( slap_bindconf *bc, struct berval *bv ) {
cptr = (char **)((char *)bc + tab->off);
if ( tab->aux ) {
int *ip = (int *)cptr, i;
for ( i=0; tab->aux[i].word; i++ ) {
for ( i=0; !BER_BVISNULL(&tab->aux[i].word); i++ ) {
if ( *ip == tab->aux[i].mask ) {
*ptr++ = ' ';
ptr = lutil_strcopy( ptr, tab->key.bv_val );
ptr = lutil_strcopy( ptr, tab->aux[i].word );
ptr = lutil_strcopy( ptr, tab->aux[i].word.bv_val );
break;
}
}

View File

@ -21,32 +21,70 @@
#include "slap.h"
static slap_verbmasks idxstr[] = {
{ BER_BVC("pres"), SLAP_INDEX_PRESENT },
{ BER_BVC("eq"), SLAP_INDEX_EQUALITY },
{ BER_BVC("approx"), SLAP_INDEX_APPROX },
{ BER_BVC("subinitial"), SLAP_INDEX_SUBSTR_INITIAL },
{ BER_BVC("subany"), SLAP_INDEX_SUBSTR_ANY },
{ BER_BVC("subfinal"), SLAP_INDEX_SUBSTR_FINAL },
{ BER_BVC("sub"), SLAP_INDEX_SUBSTR_DEFAULT },
{ BER_BVC("substr"), 0 },
{ BER_BVC("notags"), SLAP_INDEX_NOTAGS },
{ BER_BVC("nolang"), 0 }, /* backwards compat */
{ BER_BVC("nosubtypes"), SLAP_INDEX_NOSUBTYPES },
{ BER_BVNULL, 0 }
};
int slap_str2index( const char *str, slap_mask_t *idx )
{
if ( strcasecmp( str, "pres" ) == 0 ) {
*idx = SLAP_INDEX_PRESENT;
} else if ( strcasecmp( str, "eq" ) == 0 ) {
*idx = SLAP_INDEX_EQUALITY;
} else if ( strcasecmp( str, "approx" ) == 0 ) {
*idx = SLAP_INDEX_APPROX;
} else if ( strcasecmp( str, "subinitial" ) == 0 ) {
*idx = SLAP_INDEX_SUBSTR_INITIAL;
} else if ( strcasecmp( str, "subany" ) == 0 ) {
*idx = SLAP_INDEX_SUBSTR_ANY;
} else if ( strcasecmp( str, "subfinal" ) == 0 ) {
*idx = SLAP_INDEX_SUBSTR_FINAL;
} else if ( strcasecmp( str, "substr" ) == 0 ||
strcasecmp( str, "sub" ) == 0 )
{
*idx = SLAP_INDEX_SUBSTR_DEFAULT;
} else if ( strcasecmp( str, "nolang" ) == 0 || /* backwards compat */
strcasecmp( str, "notags" ) == 0 ) {
*idx = SLAP_INDEX_NOTAGS;
} else if ( strcasecmp( str, "nosubtypes" ) == 0 ) {
*idx = SLAP_INDEX_NOSUBTYPES;
} else {
return LDAP_OTHER;
}
int i;
i = verb_to_mask( str, idxstr );
if ( BER_BVISNULL(&idxstr[i].word) ) return LDAP_OTHER;
while ( !idxstr[i].mask ) i--;
*idx = idxstr[i].mask;
return LDAP_SUCCESS;
}
void slap_index2bvlen( slap_mask_t idx, struct berval *bv )
{
int i;
bv->bv_len = 0;
for ( i=0; !BER_BVISNULL( &idxstr[i].word ); i++ ) {
if ( !idxstr[i].mask ) continue;
if ( IS_SLAP_INDEX( idx, idxstr[i].mask )) {
if ( (idxstr[i].mask & SLAP_INDEX_SUBSTR) &&
((idx & SLAP_INDEX_SUBSTR_DEFAULT) != idxstr[i].mask))
continue;
if ( bv->bv_len ) bv->bv_len++;
bv->bv_len += idxstr[i].word.bv_len;
}
}
}
/* caller must provide buffer space, after calling index2bvlen */
void slap_index2bv( slap_mask_t idx, struct berval *bv )
{
int i;
char *ptr;
if ( !bv->bv_len ) return;
ptr = bv->bv_val;
for ( i=0; !BER_BVISNULL( &idxstr[i].word ); i++ ) {
if ( !idxstr[i].mask ) continue;
if ( IS_SLAP_INDEX( idx, idxstr[i].mask )) {
if ( (idxstr[i].mask & SLAP_INDEX_SUBSTR) &&
((idx & SLAP_INDEX_SUBSTR_DEFAULT) != idxstr[i].mask))
continue;
if ( ptr != bv->bv_val ) *ptr++ = ',';
ptr = lutil_strcopy( ptr, idxstr[i].word.bv_val );
}
}
}

View File

@ -762,6 +762,8 @@ LDAP_SLAPD_V( void * ) slap_tls_ctx;
* index.c
*/
LDAP_SLAPD_F (int) slap_str2index LDAP_P(( const char *str, slap_mask_t *idx ));
LDAP_SLAPD_F (void) slap_index2bvlen LDAP_P(( slap_mask_t idx, struct berval *bv ));
LDAP_SLAPD_F (void) slap_index2bv LDAP_P(( slap_mask_t idx, struct berval *bv ));
/*
* init.c

View File

@ -1419,7 +1419,7 @@ struct slap_replica_info {
};
typedef struct slap_verbmasks {
const char *word;
struct berval word;
const int mask;
} slap_verbmasks;