Don't allow enabling encryption when it's not compiled in

This commit is contained in:
Ari Koivula 2016-06-07 13:13:33 +03:00
parent 8eb087120e
commit 182038c743

View file

@ -861,28 +861,38 @@ int kvz_config_parse(kvz_config *cfg, const char *name, const char *value)
if (toggle == 1) { if (toggle == 1) {
cfg->crypto_features = KVZ_CRYPTO_ON; cfg->crypto_features = KVZ_CRYPTO_ON;
} }
return 1; } else {
// Try and parse "feature1+feature2" type list.
for (;;) {
if (*cur == '+' || *cur == '\0') {
int8_t feature = 0;
int num_chars = cur - token_begin;
if (parse_enum_n(token_begin, num_chars, crypto_feature_names, &feature)) {
cfg->crypto_features |= (1 << feature);
} else {
cfg->crypto_features = KVZ_CRYPTO_OFF;
return 0;
}
token_begin = cur + 1;
}
if (*cur == '\0') {
break;
} else {
++cur;
}
}
} }
// Try and parse "feature1+feature2" type list. // Disallow turning on the encryption when it's not compiled in.
for (;;) { bool encryption_compiled_in = false;
if (*cur == '+' || *cur == '\0') { #ifdef KVZ_SEL_ENCRYPTION
int8_t feature = 0; encryption_compiled_in = true;
int num_chars = cur - token_begin; #endif
if (parse_enum_n(token_begin, num_chars, crypto_feature_names, &feature)) { if (!encryption_compiled_in && cfg->crypto_features) {
cfg->crypto_features |= (1 << feature); fprintf(stderr, "--crypto cannot be enabled because it's not compiled in.\n");
} else { cfg->crypto_features = KVZ_CRYPTO_OFF;
cfg->crypto_features = KVZ_CRYPTO_OFF; return 0;
return 0;
}
token_begin = cur + 1;
}
if (*cur == '\0') {
break;
} else {
++cur;
}
} }
return 1; return 1;