From: Howard Chu Date: Wed, 2 Mar 2005 14:49:54 +0000 (+0000) Subject: Cleanup verb/mask processing X-Git-Tag: OPENLDAP_REL_ENG_2_3_BP~105 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=530e93f96e407f608a0875e8965eba2822c25f44;p=openldap Cleanup verb/mask processing --- diff --git a/servers/slapd/back-bdb/config.c b/servers/slapd/back-bdb/config.c index 7c46c99ccd..db98d7a6d5 100644 --- a/servers/slapd/back-bdb/config.c +++ b/servers/slapd/back-bdb/config.c @@ -129,7 +129,7 @@ bdb_cf_oc(ConfigArgs *c) return 1; } -static struct verb_mask_list bdb_lockd[] = { +static slap_verbmasks bdb_lockd[] = { { "default", DB_LOCK_DEFAULT }, { "oldest", DB_LOCK_OLDEST }, { "random", DB_LOCK_RANDOM }, @@ -213,7 +213,7 @@ bdb_cf_gen(ConfigArgs *c) break; case BDB_LOCKD: - rc = verb_to_mask( c, bdb_lockd, 1 ); + rc = verb_to_mask( c->argv[1], bdb_lockd ); if ( !bdb_lockd[rc].word ) { fprintf( stderr, "%s: " "bad policy (%s) in \"lockDetect \" line\n", diff --git a/servers/slapd/bconfig.c b/servers/slapd/bconfig.c index 04ce1a60d0..1a1ffd7e21 100644 --- a/servers/slapd/bconfig.c +++ b/servers/slapd/bconfig.c @@ -1323,7 +1323,7 @@ static int config_restrict(ConfigArgs *c) { slap_mask_t restrictops = 0; int i; - struct verb_mask_list restrictable_ops[] = { + slap_verbmasks restrictable_ops[] = { { "bind", SLAP_RESTRICT_OP_BIND }, { "add", SLAP_RESTRICT_OP_ADD }, { "modify", SLAP_RESTRICT_OP_MODIFY }, @@ -1343,9 +1343,10 @@ config_restrict(ConfigArgs *c) { }; if (c->emit) { - return mask_to_verbs( c, restrictable_ops, c->be->be_restrictops ); + 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,7 +1363,7 @@ static int config_allows(ConfigArgs *c) { slap_mask_t allows = 0; int i; - struct verb_mask_list allowable_ops[] = { + 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 }, @@ -1370,9 +1371,9 @@ config_allows(ConfigArgs *c) { { NULL, 0 } }; if (c->emit) { - return mask_to_verbs( c, allowable_ops, global_allows ); + 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,7 +1388,7 @@ static int config_disallows(ConfigArgs *c) { slap_mask_t disallows = 0; int i; - struct verb_mask_list disallowable_ops[] = { + slap_verbmasks disallowable_ops[] = { { "bind_anon", SLAP_DISALLOW_BIND_ANON }, { "bind_simple", SLAP_DISALLOW_BIND_SIMPLE }, { "bind_krb4", SLAP_DISALLOW_BIND_KRBV4 }, @@ -1396,9 +1397,9 @@ config_disallows(ConfigArgs *c) { { NULL, 0 } }; if (c->emit) { - return mask_to_verbs( c, disallowable_ops, global_disallows ); + 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,7 +1414,7 @@ static int config_requires(ConfigArgs *c) { slap_mask_t requires = 0; int i; - struct verb_mask_list requires_ops[] = { + slap_verbmasks requires_ops[] = { { "bind", SLAP_REQUIRE_BIND }, { "LDAPv3", SLAP_REQUIRE_LDAP_V3 }, { "authc", SLAP_REQUIRE_AUTHC }, @@ -1422,9 +1423,9 @@ config_requires(ConfigArgs *c) { { NULL, 0 } }; if (c->emit) { - return mask_to_verbs( c, requires_ops, c->be->be_requires ); + 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,7 +1440,7 @@ static int config_loglevel(ConfigArgs *c) { int i; char *next; - struct verb_mask_list loglevel_ops[] = { + slap_verbmasks loglevel_ops[] = { { "Trace", LDAP_DEBUG_TRACE }, { "Packets", LDAP_DEBUG_PACKETS }, { "Args", LDAP_DEBUG_ARGS }, @@ -1459,7 +1460,7 @@ config_loglevel(ConfigArgs *c) { }; if (c->emit) { - return mask_to_verbs( c, loglevel_ops, ldap_syslog ); + return mask_to_verbs( loglevel_ops, ldap_syslog, &c->rvalue_vals ); } ldap_syslog = 0; @@ -1477,7 +1478,7 @@ config_loglevel(ConfigArgs *c) { return( 1 ); } } else { - int j = verb_to_mask(c, loglevel_ops, c->argv[i][0]); + int j = verb_to_mask(c->argv[i], loglevel_ops); if(!loglevel_ops[j].word) { Debug( LDAP_DEBUG_ANY, "%s: unknown level \"%s\" " @@ -1904,13 +1905,13 @@ config_tls_option(ConfigArgs *c) { static int config_tls_config(ConfigArgs *c) { int i, flag; - struct verb_mask_list crlkeys[] = { + 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 } }; - struct verb_mask_list vfykeys[] = { + slap_verbmasks vfykeys[] = { { "never", LDAP_OPT_X_TLS_NEVER }, { "demand", LDAP_OPT_X_TLS_DEMAND }, { "try", LDAP_OPT_X_TLS_TRY }, diff --git a/servers/slapd/config.c b/servers/slapd/config.c index 84b6e2635d..673c4d43dc 100644 --- a/servers/slapd/config.c +++ b/servers/slapd/config.c @@ -549,19 +549,19 @@ badline: /* restrictops, allows, disallows, requires, loglevel */ int -verb_to_mask(ConfigArgs *c, struct verb_mask_list *v, int word) { - int j; - for(j = 0; v[j].word; j++) - if(!strcasecmp(c->argv[word], v[j].word)) +verb_to_mask(const char *word, slap_verbmasks *v) { + int i; + for(i = 0; v[i].word; i++) + if(!strcasecmp(word, v[i].word)) break; - return(j); + return(i); } int -verbs_to_mask(ConfigArgs *c, struct verb_mask_list *v, slap_mask_t *m) { +verbs_to_mask(int argc, char *argv[], slap_verbmasks *v, slap_mask_t *m) { int i, j; - for(i = 1; i < c->argc; i++) { - j = verb_to_mask(c, v, i); + for(i = 1; i < argc; i++) { + j = verb_to_mask(argv[i], v); if(!v[j].word) return(1); while (!v[j].mask) j--; *m |= v[j].mask; @@ -570,7 +570,7 @@ verbs_to_mask(ConfigArgs *c, struct verb_mask_list *v, slap_mask_t *m) { } int -mask_to_verbs(ConfigArgs *c, struct verb_mask_list *v, slap_mask_t m) { +mask_to_verbs(slap_verbmasks *v, slap_mask_t m, BerVarray *bva) { int i, j; struct berval bv; @@ -579,19 +579,19 @@ mask_to_verbs(ConfigArgs *c, struct verb_mask_list *v, slap_mask_t m) { if (!v[i].mask) continue; if (( m & v[i].mask ) == v[i].mask ) { ber_str2bv( v[i].word, 0, 0, &bv ); - value_add_one( &c->rvalue_vals, &bv ); + value_add_one( bva, &bv ); } } return 0; } -static struct verb_mask_list tlskey[] = { +static slap_verbmasks tlskey[] = { { "no", SB_TLS_OFF }, { "yes", SB_TLS_ON }, { "critical", SB_TLS_CRITICAL } }; -static struct verb_mask_list methkey[] = { +static slap_verbmasks methkey[] = { { "simple", LDAP_AUTH_SIMPLE }, #ifdef HAVE_CYRUS_SASL { "sasl", LDAP_AUTH_SASL }, @@ -603,7 +603,7 @@ typedef struct cf_aux_table { struct berval key; int off; int quote; - struct verb_mask_list *aux; + slap_verbmasks *aux; } cf_aux_table; static cf_aux_table bindkey[] = { @@ -619,7 +619,7 @@ static cf_aux_table bindkey[] = { { BER_BVNULL, 0, 0, NULL } }; -int bindconf_parse( char *word, slap_bindconf *bc ) { +int bindconf_parse( const char *word, slap_bindconf *bc ) { int i, rc = 0; char **cptr; cf_aux_table *tab; diff --git a/servers/slapd/config.h b/servers/slapd/config.h index c63d315670..cf9e1ad78a 100644 --- a/servers/slapd/config.h +++ b/servers/slapd/config.h @@ -101,6 +101,4 @@ typedef struct config_args_s { typedef int (ConfigDriver)(ConfigArgs *c); -struct verb_mask_list { char *word; int mask; }; - int config_get_vals(ConfigTable *ct, ConfigArgs *c); diff --git a/servers/slapd/proto-slap.h b/servers/slapd/proto-slap.h index 314bb933fa..cdc4e6a5fe 100644 --- a/servers/slapd/proto-slap.h +++ b/servers/slapd/proto-slap.h @@ -443,6 +443,18 @@ LDAP_SLAPD_F (int) read_config LDAP_P(( const char *fname, int depth )); LDAP_SLAPD_F (void) config_destroy LDAP_P ((void)); LDAP_SLAPD_F (char **) slap_str2clist LDAP_P(( char ***, char *, const char * )); +LDAP_SLAPD_F (int) verb_to_mask LDAP_P(( + const char *word, slap_verbmasks *v )); +LDAP_SLAPD_F (int) verbs_to_mask LDAP_P(( + int argc, char *argv[], slap_verbmasks *v, slap_mask_t *m )); +LDAP_SLAPD_F (int) mask_to_verbs LDAP_P(( + slap_verbmasks *v, slap_mask_t m, BerVarray *bva )); +LDAP_SLAPD_F (int) bindconf_parse LDAP_P(( + const char *word, slap_bindconf *bc )); +LDAP_SLAPD_F (int) bindconf_unparse LDAP_P(( + slap_bindconf *bc, struct berval *bv )); +LDAP_SLAPD_F (void) bindconf_free LDAP_P(( slap_bindconf *bc )); + #ifdef LDAP_SLAPI LDAP_SLAPD_V (int) slapi_plugins_used; #endif diff --git a/servers/slapd/slap.h b/servers/slapd/slap.h index 4192e4423e..2913d4cdb8 100644 --- a/servers/slapd/slap.h +++ b/servers/slapd/slap.h @@ -1418,6 +1418,11 @@ struct slap_replica_info { slap_bindconf ri_bindconf; /* for back-config */ }; +typedef struct slap_verbmasks { + const char *word; + const int mask; +} slap_verbmasks; + #define SLAP_LIMIT_TIME 1 #define SLAP_LIMIT_SIZE 2