Browse Source

[multiple] more forgiving config str to boolean (fixes #3036)

more consistent use of shared code config_plugin_value_tobool()

(thx tow-conf)

x-ref:
  "The on/off keywords in boolean configuration options is inconsistent, which might be misleading and error-prone."
  https://redmine.lighttpd.net/issues/3036
master
Glenn Strauss 2 months ago
parent
commit
730c932e3c
6 changed files with 28 additions and 67 deletions
  1. +3
    -8
      src/configfile.c
  2. +5
    -18
      src/mod_extforward.c
  3. +14
    -32
      src/mod_proxy.c
  4. +1
    -2
      src/mod_vhostdb_ldap.c
  5. +3
    -6
      src/mod_webdav.c
  6. +2
    -1
      src/stat_cache.c

+ 3
- 8
src/configfile.c View File

@ -476,17 +476,12 @@ static int config_http_parseopts (server *srv, const array *a) {
for (size_t i = 0; i < a->used; ++i) {
const data_string * const ds = (const data_string *)a->data[i];
const buffer *k = &ds->key;
const buffer *v = &ds->value;
unsigned short int opt;
int val = 0;
if (buffer_eq_slen(v, CONST_STR_LEN("enable")))
val = 1;
else if (buffer_eq_slen(v, CONST_STR_LEN("disable")))
val = 0;
else {
int val = config_plugin_value_tobool((data_unset *)ds, 2);
if (2 == val) {
log_error(srv->errh, __FILE__, __LINE__,
"unrecognized value for server.http-parseopts: "
"%s => %s (expect \"[enable|disable]\")", k->ptr, v->ptr);
"%s => %s (expect \"[enable|disable]\")", k->ptr, ds->value.ptr);
rc = 0;
}
if (buffer_eq_slen(k, CONST_STR_LEN("url-normalize")))


+ 5
- 18
src/mod_extforward.c View File

@ -302,31 +302,18 @@ static unsigned int mod_extforward_parse_opts(server *srv, const array *opts_par
log_error(srv->errh, __FILE__, __LINE__,
"extforward.params keys must be one of: "
"host, remote_user, but not: %s", du->key.ptr);
return HANDLER_ERROR;
return UINT_MAX;
}
if (du->type == TYPE_STRING) {
data_string *ds = (data_string *)du;
if (buffer_eq_slen(&ds->value, CONST_STR_LEN("enable"))) {
opts |= param;
}
else if (!buffer_eq_slen(&ds->value, CONST_STR_LEN("disable"))) {
log_error(srv->errh, __FILE__, __LINE__,
"extforward.params values must be one of: "
"0, 1, enable, disable; error for key: %s", du->key.ptr);
return UINT_MAX;
}
}
else if (du->type == TYPE_INTEGER) {
data_integer *di = (data_integer *)du;
if (di->value) opts |= param;
}
else {
int val = config_plugin_value_tobool(du, 2);
if (2 == val) {
log_error(srv->errh, __FILE__, __LINE__,
"extforward.params values must be one of: "
"0, 1, enable, disable; error for key: %s", du->key.ptr);
return UINT_MAX;
}
if (val)
opts |= param;
}
return opts;
}


+ 14
- 32
src/mod_proxy.c View File

@ -177,27 +177,15 @@ static unsigned int mod_proxy_parse_forwarded(server *srv, const array *a)
"by, for, host, proto, remote_user, but not: %s", du->key.ptr);
return UINT_MAX;
}
if (du->type == TYPE_STRING) {
data_string *ds = (data_string *)du;
if (buffer_eq_slen(&ds->value, CONST_STR_LEN("enable")))
forwarded |= param;
else if (!buffer_eq_slen(&ds->value, CONST_STR_LEN("disable"))) {
log_error(srv->errh, __FILE__, __LINE__,
"proxy.forwarded values must be one of: "
"0, 1, enable, disable; error for key: %s", du->key.ptr);
return UINT_MAX;
}
}
else if (du->type == TYPE_INTEGER) {
data_integer *di = (data_integer *)du;
if (di->value) forwarded |= param;
}
else {
int val = config_plugin_value_tobool(du, 2);
if (2 == val) {
log_error(srv->errh, __FILE__, __LINE__,
"proxy.forwarded values must be one of: "
"0, 1, enable, disable; error for key: %s", du->key.ptr);
return UINT_MAX;
}
if (val)
forwarded |= param;
}
return forwarded;
}
@ -210,42 +198,36 @@ static http_header_remap_opts * mod_proxy_parse_header_opts(server *srv, const a
for (uint32_t j = 0, used = a->used; j < used; ++j) {
data_array *da = (data_array *)a->data[j];
if (buffer_eq_slen(&da->key, CONST_STR_LEN("https-remap"))) {
data_string *ds = (data_string *)da;
if (ds->type != TYPE_STRING) {
int val = config_plugin_value_tobool((data_unset *)da, 2);
if (2 == val) {
log_error(srv->errh, __FILE__, __LINE__,
"unexpected value for proxy.header; "
"expected \"enable\" or \"disable\" for https-remap");
"expected \"https-remap\" => \"enable\" or \"disable\"");
return NULL;
}
header.https_remap =
!buffer_eq_slen(&ds->value, CONST_STR_LEN("disable"))
&& !buffer_eq_slen(&ds->value, CONST_STR_LEN("0"));
header.https_remap = val;
continue;
}
else if (buffer_eq_slen(&da->key, CONST_STR_LEN("upgrade"))) {
data_string *ds = (data_string *)da;
if (ds->type != TYPE_STRING) {
int val = config_plugin_value_tobool((data_unset *)da, 2);
if (2 == val) {
log_error(srv->errh, __FILE__, __LINE__,
"unexpected value for proxy.header; "
"expected \"upgrade\" => \"enable\" or \"disable\"");
return NULL;
}
header.upgrade =
!buffer_eq_slen(&ds->value, CONST_STR_LEN("disable"))
&& !buffer_eq_slen(&ds->value, CONST_STR_LEN("0"));
header.upgrade = val;
continue;
}
else if (buffer_eq_slen(&da->key, CONST_STR_LEN("connect"))) {
data_string *ds = (data_string *)da;
if (ds->type != TYPE_STRING) {
int val = config_plugin_value_tobool((data_unset *)da, 2);
if (2 == val) {
log_error(srv->errh, __FILE__, __LINE__,
"unexpected value for proxy.header; "
"expected \"connect\" => \"enable\" or \"disable\"");
return NULL;
}
header.connect_method =
!buffer_eq_slen(&ds->value, CONST_STR_LEN("disable"))
&& !buffer_eq_slen(&ds->value, CONST_STR_LEN("0"));
header.connect_method = val;
continue;
}
if (da->type != TYPE_ARRAY || !array_is_kvstring(&da->value)) {


+ 1
- 2
src/mod_vhostdb_ldap.c View File

@ -113,8 +113,7 @@ static int mod_vhostdb_dbconf_setup (server *srv, const array *opts, void **vdat
} else if (buffer_is_equal_caseless_string(&ds->key, CONST_STR_LEN("ca-file"))) {
if (!buffer_string_is_empty(&ds->value)) cafile = ds->value.ptr;
} else if (buffer_is_equal_caseless_string(&ds->key, CONST_STR_LEN("starttls"))) {
starttls = !buffer_is_equal_string(&ds->value, CONST_STR_LEN("disable"))
&& !buffer_is_equal_string(&ds->value, CONST_STR_LEN("0"));
starttls = config_plugin_value_tobool((data_unset *)ds, 1);
} else if (buffer_is_equal_caseless_string(&ds->key, CONST_STR_LEN("timeout"))) {
timeout = strtol(ds->value.ptr, NULL, 10);
}


+ 3
- 6
src/mod_webdav.c View File

@ -503,22 +503,19 @@ SETDEFAULTS_FUNC(mod_webdav_set_defaults) {
data_string *ds = (data_string *)cpv->v.a->data[j];
if (buffer_is_equal_string(&ds->key,
CONST_STR_LEN("deprecated-unsafe-partial-put"))
&& buffer_eq_slen(&ds->value,
CONST_STR_LEN("enable"))) {
&& config_plugin_value_tobool((data_unset *)ds,0)) {
opts |= MOD_WEBDAV_UNSAFE_PARTIAL_PUT_COMPAT;
continue;
}
if (buffer_is_equal_string(&ds->key,
CONST_STR_LEN("propfind-depth-infinity"))
&& buffer_eq_slen(&ds->value,
CONST_STR_LEN("enable"))) {
&& config_plugin_value_tobool((data_unset *)ds,0)) {
opts |= MOD_WEBDAV_PROPFIND_DEPTH_INFINITY;
continue;
}
if (buffer_is_equal_string(&ds->key,
CONST_STR_LEN("unsafe-propfind-follow-symlink"))
&& buffer_eq_slen(&ds->value,
CONST_STR_LEN("enable"))) {
&& config_plugin_value_tobool((data_unset *)ds,0)) {
opts |= MOD_WEBDAV_UNSAFE_PROPFIND_FOLLOW_SYMLINK;
continue;
}


+ 2
- 1
src/stat_cache.c View File

@ -910,7 +910,8 @@ int stat_cache_choose_engine (const buffer *stat_cache_string, log_error_st *err
else if (buffer_eq_slen(stat_cache_string, CONST_STR_LEN("fam")))
sc.stat_cache_engine = STAT_CACHE_ENGINE_FAM;
#endif
else if (buffer_eq_slen(stat_cache_string, CONST_STR_LEN("disable")))
else if (buffer_eq_slen(stat_cache_string, CONST_STR_LEN("disable"))
|| buffer_eq_slen(stat_cache_string, CONST_STR_LEN("none")))
sc.stat_cache_engine = STAT_CACHE_ENGINE_NONE;
else {
log_error(errh, __FILE__, __LINE__,


Loading…
Cancel
Save