summaryrefslogtreecommitdiff
path: root/ot_accesslist.c
diff options
context:
space:
mode:
Diffstat (limited to 'ot_accesslist.c')
-rw-r--r--ot_accesslist.c43
1 files changed, 27 insertions, 16 deletions
diff --git a/ot_accesslist.c b/ot_accesslist.c
index 0cb6fe7..304b3f1 100644
--- a/ot_accesslist.c
+++ b/ot_accesslist.c
@@ -8,10 +8,12 @@
8#include <string.h> 8#include <string.h>
9#include <stdio.h> 9#include <stdio.h>
10#include <signal.h> 10#include <signal.h>
11#include <unistd.h>
11 12
12/* Libowfat */ 13/* Libowfat */
13#include "byte.h" 14#include "byte.h"
14#include "scan.h" 15#include "scan.h"
16#include "ip6.h"
15 17
16/* Opentracker */ 18/* Opentracker */
17#include "trackerlogic.h" 19#include "trackerlogic.h"
@@ -32,14 +34,14 @@ void accesslist_deinit( void ) {
32 accesslist_reset( ); 34 accesslist_reset( );
33} 35}
34 36
35static int accesslist_addentry( ot_hash *infohash ) { 37static int accesslist_addentry( ot_hash infohash ) {
36 int eger; 38 int eger;
37 void *insert = vector_find_or_insert( &accesslist, infohash, OT_HASH_COMPARE_SIZE, OT_HASH_COMPARE_SIZE, &eger ); 39 void *insert = vector_find_or_insert( &accesslist, infohash, OT_HASH_COMPARE_SIZE, OT_HASH_COMPARE_SIZE, &eger );
38 40
39 if( !insert ) 41 if( !insert )
40 return -1; 42 return -1;
41 43
42 memmove( insert, infohash, OT_HASH_COMPARE_SIZE ); 44 memcpy( insert, infohash, OT_HASH_COMPARE_SIZE );
43 45
44 return 0; 46 return 0;
45} 47}
@@ -64,7 +66,7 @@ static void accesslist_readfile( int foo ) {
64 /* We do ignore anything that is not of the form "^[:xdigit:]{40}[^:xdigit:].*" */ 66 /* We do ignore anything that is not of the form "^[:xdigit:]{40}[^:xdigit:].*" */
65 while( fgets( inbuf, sizeof(inbuf), accesslist_filehandle ) ) { 67 while( fgets( inbuf, sizeof(inbuf), accesslist_filehandle ) ) {
66 int i; 68 int i;
67 for( i=0; i<20; ++i ) { 69 for( i=0; i<(int)sizeof(ot_hash); ++i ) {
68 int eger = 16 * scan_fromhex( inbuf[ 2*i ] ) + scan_fromhex( inbuf[ 1 + 2*i ] ); 70 int eger = 16 * scan_fromhex( inbuf[ 2*i ] ) + scan_fromhex( inbuf[ 1 + 2*i ] );
69 if( eger < 0 ) 71 if( eger < 0 )
70 continue; 72 continue;
@@ -74,13 +76,13 @@ static void accesslist_readfile( int foo ) {
74 continue; 76 continue;
75 77
76 /* Append accesslist to accesslist vector */ 78 /* Append accesslist to accesslist vector */
77 accesslist_addentry( &infohash ); 79 accesslist_addentry( infohash );
78 } 80 }
79 81
80 fclose( accesslist_filehandle ); 82 fclose( accesslist_filehandle );
81} 83}
82 84
83int accesslist_hashisvalid( ot_hash *hash ) { 85int accesslist_hashisvalid( ot_hash hash ) {
84 int exactmatch; 86 int exactmatch;
85 binary_search( hash, accesslist.data, accesslist.size, OT_HASH_COMPARE_SIZE, OT_HASH_COMPARE_SIZE, &exactmatch ); 87 binary_search( hash, accesslist.data, accesslist.size, OT_HASH_COMPARE_SIZE, OT_HASH_COMPARE_SIZE, &exactmatch );
86 88
@@ -102,30 +104,39 @@ void accesslist_init( ) {
102} 104}
103#endif 105#endif
104 106
105static uint32_t g_adminip_addresses[OT_ADMINIP_MAX]; 107static ot_ip6 g_adminip_addresses[OT_ADMINIP_MAX];
106static ot_permissions g_adminip_permissions[OT_ADMINIP_MAX]; 108static ot_permissions g_adminip_permissions[OT_ADMINIP_MAX];
107static unsigned int g_adminip_count = 0; 109static unsigned int g_adminip_count = 0;
108 110
109int accesslist_blessip( char *ip, ot_permissions permissions ) { 111int accesslist_blessip( ot_ip6 ip, ot_permissions permissions ) {
110 if( g_adminip_count >= OT_ADMINIP_MAX ) 112 if( g_adminip_count >= OT_ADMINIP_MAX )
111 return -1; 113 return -1;
112 WRITE32(g_adminip_addresses + g_adminip_count,0,READ32(ip,0)); 114
115 memcpy(g_adminip_addresses + g_adminip_count,ip,sizeof(ot_ip6));
113 g_adminip_permissions[ g_adminip_count++ ] = permissions; 116 g_adminip_permissions[ g_adminip_count++ ] = permissions;
117
114#ifdef _DEBUG 118#ifdef _DEBUG
115 uint8_t *_ip = (uint8_t*)ip; 119 {
116 fprintf( stderr, "Blessing ip address %d.%d.%d.%d with:", _ip[0], _ip[1], _ip[2], _ip[3]); 120 char _debug[512];
117 if( permissions & OT_PERMISSION_MAY_STAT ) fputs( " may_fetch_stats", stderr ); 121 int off = snprintf( _debug, sizeof(_debug), "Blessing ip address " );
118 if( permissions & OT_PERMISSION_MAY_LIVESYNC ) fputs( " may_sync_live", stderr ); 122 off += fmt_ip6(_debug+off, ip );
119 if( permissions & OT_PERMISSION_MAY_FULLSCRAPE ) fputs( " may_fetch_fullscrapes", stderr ); 123
120 if( !permissions ) fputs(" nothing.\n", stderr); else fputs(".\n", stderr ); 124 if( permissions & OT_PERMISSION_MAY_STAT ) off += snprintf( _debug+off, 512-off, " may_fetch_stats" );
125 if( permissions & OT_PERMISSION_MAY_LIVESYNC ) off += snprintf( _debug+off, 512-off, " may_sync_live" );
126 if( permissions & OT_PERMISSION_MAY_FULLSCRAPE ) off += snprintf( _debug+off, 512-off, " may_fetch_fullscrapes" );
127 if( !permissions ) off += snprintf( _debug+off, sizeof(_debug)-off, " nothing\n" );
128 _debug[off++] = '.';
129 write( 2, _debug, off );
130 }
121#endif 131#endif
132
122 return 0; 133 return 0;
123} 134}
124 135
125int accesslist_isblessed( char *ip, ot_permissions permissions ) { 136int accesslist_isblessed( ot_ip6 ip, ot_permissions permissions ) {
126 unsigned int i; 137 unsigned int i;
127 for( i=0; i<g_adminip_count; ++i ) 138 for( i=0; i<g_adminip_count; ++i )
128 if( !memcmp( g_adminip_addresses + i, ip, 4) && ( g_adminip_permissions[ i ] & permissions ) ) 139 if( !memcmp( g_adminip_addresses + i, ip, sizeof(ot_ip6)) && ( g_adminip_permissions[ i ] & permissions ) )
129 return 1; 140 return 1;
130 return 0; 141 return 0;
131} 142}