blob: 0eb3846093d3d4fb990c4ac008e3eb4a56539e29 [file] [log] [blame]
Constantin Kaplinskyde179d42006-04-16 06:53:44 +00001/* Copyright (C) 2002-2005 RealVNC Ltd. All Rights Reserved.
2 *
Constantin Kaplinsky47ed8d32004-10-08 09:43:57 +00003 * 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//
20// Blacklist.h - Handling of black-listed entities.
21// Just keeps a table mapping strings to timing information, including
22// how many times the entry has been black-listed and when to next
23// put it on probation (e.g. allow a connection in from the host, and
24// re-blacklist it if that fails).
25//
26
27#ifndef __RFB_BLACKLIST_H__
28#define __RFB_BLACKLIST_H__
29
30#include <string.h>
31#include <time.h>
32#include <map>
33
34#include <rfb/Configuration.h>
35#include <rfb/util.h>
36
37namespace rfb {
38
39 //
40 // -=- Blacklist handler
41 //
42 // Parameters include a threshold after which to blacklist the named
43 // host, and a timeout after which to re-consider them.
44 //
45 // Threshold means that isBlackmarked can be called that number of times
46 // before it will return true.
47 //
48 // Timeout means that after that many seconds, the next call to isBlackmarked
49 // will return false. At the same time, the timeout is doubled, so that the
50 // next calls will fail, until the timeout expires again or clearBlackmark is
51 // called.
52 //
53 // When clearBlackMark is called, the corresponding entry is completely
54 // removed, causing the next isBlackmarked call to return false.
55
56 // KNOWN BUG: Client can keep making rejected requests, thus increasing
57 // their timeout. If client does this for 30 years, timeout may wrap round
58 // to a very small value again.
59
60 // THIS CLASS IS NOT THREAD-SAFE!
61
62 class Blacklist {
63 public:
64 Blacklist();
65 ~Blacklist();
66
67 bool isBlackmarked(const char* name);
68 void clearBlackmark(const char* name);
69
70 static IntParameter threshold;
71 static IntParameter initialTimeout;
72
73 protected:
74 struct ltStr {
75 bool operator()(const char* s1, const char* s2) const {
76 return strcmp(s1, s2) < 0;
77 };
78 };
79 struct BlacklistInfo {
80 int marks;
81 time_t blockUntil;
82 unsigned int blockTimeout;
83 };
84 typedef std::map<const char*,BlacklistInfo,ltStr> BlacklistMap;
85 BlacklistMap blm;
86 };
87
88}
89
90#endif
91