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.

Blacklist.h 2.5KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. /* Copyright (C) 2002-2005 RealVNC Ltd. All Rights Reserved.
  2. *
  3. * This is free software; you can redistribute it and/or modify
  4. * it under the terms of the GNU General Public License as published by
  5. * the Free Software Foundation; either version 2 of the License, or
  6. * (at your option) any later version.
  7. *
  8. * This software is distributed in the hope that it will be useful,
  9. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. * GNU General Public License for more details.
  12. *
  13. * You should have received a copy of the GNU General Public License
  14. * along with this software; if not, write to the Free Software
  15. * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
  16. * USA.
  17. */
  18. //
  19. // Blacklist.h - Handling of black-listed entities.
  20. // Just keeps a table mapping strings to timing information, including
  21. // how many times the entry has been black-listed and when to next
  22. // put it on probation (e.g. allow a connection in from the host, and
  23. // re-blacklist it if that fails).
  24. //
  25. #ifndef __RFB_BLACKLIST_H__
  26. #define __RFB_BLACKLIST_H__
  27. #include <string.h>
  28. #include <time.h>
  29. #include <map>
  30. #include <string>
  31. #include <rfb/Configuration.h>
  32. namespace rfb {
  33. //
  34. // -=- Blacklist handler
  35. //
  36. // Parameters include a threshold after which to blacklist the named
  37. // host, and a timeout after which to re-consider them.
  38. //
  39. // Threshold means that isBlackmarked can be called that number of times
  40. // before it will return true.
  41. //
  42. // Timeout means that after that many seconds, the next call to isBlackmarked
  43. // will return false. At the same time, the timeout is doubled, so that the
  44. // next calls will fail, until the timeout expires again or clearBlackmark is
  45. // called.
  46. //
  47. // When clearBlackMark is called, the corresponding entry is completely
  48. // removed, causing the next isBlackmarked call to return false.
  49. // KNOWN BUG: Client can keep making rejected requests, thus increasing
  50. // their timeout. If client does this for 30 years, timeout may wrap round
  51. // to a very small value again.
  52. // THIS CLASS IS NOT THREAD-SAFE!
  53. class Blacklist {
  54. public:
  55. Blacklist();
  56. ~Blacklist();
  57. bool isBlackmarked(const char* name);
  58. void clearBlackmark(const char* name);
  59. protected:
  60. struct BlacklistInfo {
  61. int marks;
  62. time_t blockUntil;
  63. unsigned int blockTimeout;
  64. };
  65. typedef std::map<std::string,BlacklistInfo> BlacklistMap;
  66. BlacklistMap blm;
  67. };
  68. }
  69. #endif