Browse Source

* f2b_jail_cmd_ip_ban()

master
Alex 'AdUser' Z 8 years ago
parent
commit
48accbd188
  1. 14
      src/daemon.c
  2. 28
      src/jail.c
  3. 1
      src/jail.h

14
src/daemon.c

@ -132,19 +132,7 @@ f2b_cmsg_process(const f2b_cmsg_t *msg, char *res, size_t ressize) {
} else if (msg->type == CMD_JAIL_IP_STATUS) {
f2b_jail_cmd_ip_status(res, ressize, args[0], args[1]);
} else if (msg->type == CMD_JAIL_IP_BAN) {
if ((addr = f2b_addrlist_lookup(jail->ipaddrs, args[1])) == NULL) {
/* TODO: this is copy-paste from f2b_jail_process */
time_t now = time(NULL);
addr = f2b_ipaddr_create(args[1], jail->maxretry);
if (!addr) {
snprintf(res, ressize, "can't parse ip address: %s", args[1]);
return;
}
addr->lastseen = now;
f2b_matches_append(&addr->matches, now);
jail->ipaddrs = f2b_addrlist_append(jail->ipaddrs, addr);
}
f2b_jail_ban(jail, addr);
f2b_jail_cmd_ip_ban(res, ressize, args[0], args[1]);
} else if (msg->type == CMD_JAIL_IP_RELEASE) {
if ((addr = f2b_addrlist_lookup(jail->ipaddrs, args[1])) == NULL) {
snprintf(res, ressize, "can't find ip '%s' in jail '%s'\n", args[1], args[0]);

28
src/jail.c

@ -465,3 +465,31 @@ f2b_jail_cmd_ip_status(char *res, size_t ressize, const char *name, const char *
}
f2b_ipaddr_status(addr, res, ressize);
}
void
f2b_jail_cmd_ip_ban(char *res, size_t ressize, const char *name, const char *ip) {
f2b_jail_t *jail = NULL;
f2b_ipaddr_t *addr = NULL;
assert(res != NULL);
assert(name != NULL);
assert(ip != NULL);
if ((jail = f2b_jail_find(jails, name)) == NULL) {
snprintf(res, ressize, "can't find jail '%s'", name);
return;
}
if ((addr = f2b_addrlist_lookup(jail->ipaddrs, ip)) == NULL) {
time_t now = time(NULL);
addr = f2b_ipaddr_create(ip, jail->maxretry);
if (!addr) {
snprintf(res, ressize, "can't parse ip address: %s", ip);
return;
}
addr->lastseen = now;
f2b_matches_append(&addr->matches, now);
jail->ipaddrs = f2b_addrlist_append(jail->ipaddrs, addr);
}
f2b_jail_unban(jail, addr);
}

1
src/jail.h

@ -56,4 +56,5 @@ bool f2b_jail_stop (f2b_jail_t *jail);
void f2b_jail_cmd_status (char *res, size_t ressize, const char *name);
void f2b_jail_cmd_ip_status (char *res, size_t ressize, const char *name, const char *ip);
void f2b_jail_cmd_ip_ban (char *res, size_t ressize, const char *name, const char *ip);
#endif /* F2B_JAIL_H_ */

Loading…
Cancel
Save