| 
						
						
							
								
							
						
						
					 | 
					 | 
					@ -24,6 +24,8 @@
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					#include <errno.h>
 | 
					 | 
					 | 
					 | 
					#include <errno.h>
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					#include <netinet/tcp.h>
 | 
					 | 
					 | 
					 | 
					#include <netinet/tcp.h>
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					#include <netdb.h>
 | 
					 | 
					 | 
					 | 
					#include <netdb.h>
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					#include <pthread.h>
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					#include <stdlib.h>
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					#include <time.h>
 | 
					 | 
					 | 
					 | 
					#include <time.h>
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					
 | 
					 | 
					 | 
					 | 
					
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					#include <map>
 | 
					 | 
					 | 
					 | 
					#include <map>
 | 
				
			
			
		
	
	
		
		
			
				
					| 
						
						
						
							
								
							
						
					 | 
					 | 
					@ -35,6 +37,9 @@
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					static std::map<std::string, unsigned> hits;
 | 
					 | 
					 | 
					 | 
					static std::map<std::string, unsigned> hits;
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					static std::map<std::string, time_t> blacklist;
 | 
					 | 
					 | 
					 | 
					static std::map<std::string, time_t> blacklist;
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					
 | 
					 | 
					 | 
					 | 
					
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					static pthread_mutex_t hitmutex = PTHREAD_MUTEX_INITIALIZER;
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					static pthread_mutex_t blmutex = PTHREAD_MUTEX_INITIALIZER;
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					unsigned char bl_isBlacklisted(const char *addr) {
 | 
					 | 
					 | 
					 | 
					unsigned char bl_isBlacklisted(const char *addr) {
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
						const unsigned char count = blacklist.count(addr);
 | 
					 | 
					 | 
					 | 
						const unsigned char count = blacklist.count(addr);
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
						if (!count)
 | 
					 | 
					 | 
					 | 
						if (!count)
 | 
				
			
			
		
	
	
		
		
			
				
					| 
						
						
						
							
								
							
						
					 | 
					 | 
					@ -43,19 +48,35 @@ unsigned char bl_isBlacklisted(const char *addr) {
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
						const time_t now = time(NULL);
 | 
					 | 
					 | 
					 | 
						const time_t now = time(NULL);
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
						const unsigned timeout = rfb::Blacklist::initialTimeout;
 | 
					 | 
					 | 
					 | 
						const unsigned timeout = rfb::Blacklist::initialTimeout;
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					
 | 
					 | 
					 | 
					 | 
					
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
						if (pthread_mutex_lock(&blmutex))
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
							abort();
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
						if (now - timeout > blacklist[addr]) {
 | 
					 | 
					 | 
					 | 
						if (now - timeout > blacklist[addr]) {
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
							blacklist.erase(addr);
 | 
					 | 
					 | 
					 | 
							blacklist.erase(addr);
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
							pthread_mutex_unlock(&blmutex);
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
							if (pthread_mutex_lock(&hitmutex))
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
								abort();
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
							hits.erase(addr);
 | 
					 | 
					 | 
					 | 
							hits.erase(addr);
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
							pthread_mutex_unlock(&hitmutex);
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
							return 0;
 | 
					 | 
					 | 
					 | 
							return 0;
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
						} else {
 | 
					 | 
					 | 
					 | 
						} else {
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
							blacklist[addr] = now;
 | 
					 | 
					 | 
					 | 
							blacklist[addr] = now;
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
							pthread_mutex_unlock(&blmutex);
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
							return 1;
 | 
					 | 
					 | 
					 | 
							return 1;
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
						}
 | 
					 | 
					 | 
					 | 
						}
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					}
 | 
					 | 
					 | 
					 | 
					}
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					
 | 
					 | 
					 | 
					 | 
					
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					void bl_addFailure(const char *addr) {
 | 
					 | 
					 | 
					 | 
					void bl_addFailure(const char *addr) {
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
						if (pthread_mutex_lock(&hitmutex))
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
							abort();
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
						const unsigned num = ++hits[addr];
 | 
					 | 
					 | 
					 | 
						const unsigned num = ++hits[addr];
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
						pthread_mutex_unlock(&hitmutex);
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
						if (num >= (unsigned) rfb::Blacklist::threshold) {
 | 
					 | 
					 | 
					 | 
						if (num >= (unsigned) rfb::Blacklist::threshold) {
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
							if (pthread_mutex_lock(&blmutex))
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
								abort();
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
							blacklist[addr] = time(NULL);
 | 
					 | 
					 | 
					 | 
							blacklist[addr] = time(NULL);
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
							pthread_mutex_unlock(&blmutex);
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
						}
 | 
					 | 
					 | 
					 | 
						}
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					}
 | 
					 | 
					 | 
					 | 
					}
 | 
				
			
			
		
	
	
		
		
			
				
					| 
						
						
						
					 | 
					 | 
					
 
 |