Browse Source

+ f2b_jail_set_param()

master
Alex 'AdUser' Z 8 years ago
parent
commit
58a4de2e72
  1. 86
      src/jail.c
  2. 9
      src/jail.h

86
src/jail.c

@ -45,6 +45,52 @@ f2b_jail_parse_compound_value(const char *value, char *name, char *init) {
return;
}
bool
f2b_jail_set_param(f2b_jail_t *jail, const char *param, const char *value) {
assert(jail != NULL);
assert(param != NULL);
assert(value != NULL);
if (strcmp(param, "enabled") == 0) {
if (strcmp(value, "yes") == 0)
jail->enabled = true;
return true;
}
if (strcmp(param, "bantime") == 0) {
jail->bantime = atoi(value);
if (jail->bantime <= 0)
jail->bantime = DEFAULT_BANTIME;
return true;
}
if (strcmp(param, "findtime") == 0) {
jail->findtime = atoi(value);
if (jail->findtime <= 0)
jail->findtime = DEFAULT_FINDTIME;
return true;
}
if (strcmp(param, "expiretime") == 0) {
jail->expiretime = atoi(value);
if (jail->expiretime <= 0)
jail->expiretime = DEFAULT_EXPIRETIME;
return true;
}
if (strcmp(param, "maxretry") == 0) {
jail->maxretry = atoi(value);
if (jail->maxretry == 0)
jail->maxretry = DEFAULT_MAXRETRY;
return true;
}
if (strcmp(param, "incr_bantime") == 0) {
jail->incr_bantime = atof(value);
return true;
}
if (strcmp(param, "incr_findtime") == 0) {
jail->incr_findtime = atof(value);
return true;
}
return false;
}
void
f2b_jail_apply_config(f2b_jail_t *jail, f2b_config_section_t *section) {
f2b_config_param_t *param = NULL;
@ -54,43 +100,6 @@ f2b_jail_apply_config(f2b_jail_t *jail, f2b_config_section_t *section) {
assert(section->type == t_jail || section->type == t_defaults);
for (param = section->param; param != NULL; param = param->next) {
if (strcmp(param->name, "enabled") == 0) {
if (strcmp(param->value, "yes") == 0)
jail->enabled = true;
continue;
}
if (strcmp(param->name, "bantime") == 0) {
jail->bantime = atoi(param->value);
if (jail->bantime <= 0)
jail->bantime = DEFAULT_BANTIME;
continue;
}
if (strcmp(param->name, "findtime") == 0) {
jail->findtime = atoi(param->value);
if (jail->findtime <= 0)
jail->findtime = DEFAULT_FINDTIME;
continue;
}
if (strcmp(param->name, "expiretime") == 0) {
jail->expiretime = atoi(param->value);
if (jail->expiretime <= 0)
jail->expiretime = DEFAULT_EXPIRETIME;
continue;
}
if (strcmp(param->name, "maxretry") == 0) {
jail->maxretry = atoi(param->value);
if (jail->maxretry == 0)
jail->maxretry = DEFAULT_MAXRETRY;
continue;
}
if (strcmp(param->name, "incr_bantime") == 0) {
jail->incr_bantime = atof(param->value);
continue;
}
if (strcmp(param->name, "incr_findtime") == 0) {
jail->incr_findtime = atof(param->value);
continue;
}
if (strcmp(param->name, "source") == 0) {
f2b_jail_parse_compound_value(param->value, jail->source_name, jail->source_init);
continue;
@ -103,6 +112,9 @@ f2b_jail_apply_config(f2b_jail_t *jail, f2b_config_section_t *section) {
f2b_jail_parse_compound_value(param->value, jail->backend_name, jail->backend_init);
continue;
}
if (f2b_jail_set_param(jail, param->name, param->value))
continue;
f2b_log_msg(log_warn, "jail '%s': unrecognized parameter: %s", jail->name, param->name);
}
return;

9
src/jail.h

@ -68,7 +68,14 @@ f2b_jail_t *f2b_jail_create (f2b_config_section_t *section);
* @returns Pointer to wanted jail or NULL if not found
*/
f2b_jail_t *f2b_jail_find (f2b_jail_t *list, const char *name);
/**
* @brief Set tunable parameter of jail
* @param jail Jail pointer
* @param param Parameter name
* @param value Parameter value
* @return true if parameter set, false if not found
*/
bool f2b_jail_set_param(f2b_jail_t *jail, const char *param, const char *value);
/**
* @brief Setup source, filter and backend in jail
* @param jail Jail pointer

Loading…
Cancel
Save