You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

76 lines
1.9KB

  1. /**
  2. * @PROJECT ForbidHosts
  3. * @COPYRIGHT See COPYING in the top level directory
  4. * @FILE forbidhosts.h
  5. * @PURPOSE Tool for checking IPv4 & IPv6 failed connections
  6. * @DEVELOPERS Pierre Schweitzer <pierre@reactos.org>
  7. * Rafal Kupiec <belliash@asiotec.eu.org>
  8. */
  9. #define MAXATTEMPTS 5
  10. #define HOSTEXPIRE 10
  11. #define FAILUREPENALTY 1
  12. #define DENYFILE "/etc/hosts.deny"
  13. #define LOGFILE "/var/log/auth.log"
  14. #define PIDFILE "/var/run/forbidhosts.pid"
  15. #define FHVERSION "1.6"
  16. #define assertHard(e) if (!(e)) assertException(__FILE__, __LINE__, #e, true)
  17. #define assertSoft(e) if (!(e)) assertException(__FILE__, __LINE__, #e, false)
  18. using namespace std;
  19. struct hf_t {
  20. unsigned int max_attempts;
  21. unsigned int host_expire;
  22. unsigned int failure_penalty;
  23. string banned_names;
  24. string debug;
  25. string deny_file;
  26. string log_file;
  27. string pid_file;
  28. string protocol;
  29. };
  30. hf_t global;
  31. struct banned_t {
  32. string ipaddr;
  33. time_t expires;
  34. banned_t(time_t date, const string &address) {
  35. ipaddr = address;
  36. expires = date + 12 * 60 * 60;
  37. }
  38. };
  39. struct host_t {
  40. string ipaddr;
  41. unsigned int attempts;
  42. time_t first_seen;
  43. time_t expires;
  44. host_t(time_t date, const string &address) {
  45. attempts = 1;
  46. ipaddr = address;
  47. first_seen = date;
  48. expires = date + global.host_expire * 60;
  49. }
  50. };
  51. int logfile;
  52. void assertException(const char *file, unsigned int line, const char *assert, bool critical);
  53. void assignGlobalVars();
  54. bool compare(const host_t &lhs, const host_t &rhs);
  55. void daemonize(string workdir);
  56. void debug(const char *msg, ...);
  57. void denyHost(string host);
  58. void printVersion();
  59. unsigned int readLine(int file, vector<host_t> &hosts, vector<banned_t> &banned);
  60. void shutdown(int code);
  61. void signalHandler(int signal);
  62. bool updateHost(const string &host, vector<host_t> &hosts, vector<banned_t> &banned, unsigned int repeated, bool loggedin);
  63. bool validateEntry(char *entry, char **address, unsigned int *length, bool *loggedin);
  64. unsigned int validateRepeated(char *line);