diff options
author | erdgeist <> | 2007-12-03 00:48:48 +0000 |
---|---|---|
committer | erdgeist <> | 2007-12-03 00:48:48 +0000 |
commit | 5d18bf211caab11f3b8ac3f921a8e338e2a9724b (patch) | |
tree | b1a49ac370deab752eaf254bd0153a4983de0f19 /ot_accesslist.c | |
parent | afea7d5ee236e73d340b79f509c090c4f40fc7e0 (diff) |
Move blessed IP handling code to accesslist objects
Diffstat (limited to 'ot_accesslist.c')
-rw-r--r-- | ot_accesslist.c | 33 |
1 files changed, 27 insertions, 6 deletions
diff --git a/ot_accesslist.c b/ot_accesslist.c index e1774fb..38b1bdf 100644 --- a/ot_accesslist.c +++ b/ot_accesslist.c | |||
@@ -12,13 +12,13 @@ | |||
12 | #include "scan.h" | 12 | #include "scan.h" |
13 | 13 | ||
14 | /* Opentracker */ | 14 | /* Opentracker */ |
15 | #include "trackerlogic.h" | ||
15 | #include "ot_accesslist.h" | 16 | #include "ot_accesslist.h" |
16 | 17 | ||
17 | /* GLOBAL VARIABLES */ | 18 | /* GLOBAL VARIABLES */ |
18 | #ifdef WANT_ACCESS_CONTROL | 19 | #ifdef WANT_ACCESS_CONTROL |
19 | static char *accesslist_filename = NULL; | 20 | static char *accesslist_filename = NULL; |
20 | static ot_vector accesslist; | 21 | static ot_vector accesslist; |
21 | static char static_inbuf[8192]; | ||
22 | 22 | ||
23 | static void accesslist_reset( void ) { | 23 | static void accesslist_reset( void ) { |
24 | free( accesslist.data ); | 24 | free( accesslist.data ); |
@@ -26,8 +26,8 @@ static void accesslist_reset( void ) { | |||
26 | } | 26 | } |
27 | 27 | ||
28 | static int accesslist_addentry( ot_hash *infohash ) { | 28 | static int accesslist_addentry( ot_hash *infohash ) { |
29 | int em; | 29 | int eger; |
30 | void *insert = vector_find_or_insert( &accesslist, infohash, OT_HASH_COMPARE_SIZE, OT_HASH_COMPARE_SIZE, &em ); | 30 | void *insert = vector_find_or_insert( &accesslist, infohash, OT_HASH_COMPARE_SIZE, OT_HASH_COMPARE_SIZE, &eger ); |
31 | 31 | ||
32 | if( !insert ) | 32 | if( !insert ) |
33 | return -1; | 33 | return -1; |
@@ -41,6 +41,7 @@ static int accesslist_addentry( ot_hash *infohash ) { | |||
41 | static void accesslist_readfile( int foo ) { | 41 | static void accesslist_readfile( int foo ) { |
42 | FILE * accesslist_filehandle; | 42 | FILE * accesslist_filehandle; |
43 | ot_hash infohash; | 43 | ot_hash infohash; |
44 | char inbuf[512]; | ||
44 | foo = foo; | 45 | foo = foo; |
45 | 46 | ||
46 | accesslist_filehandle = fopen( accesslist_filename, "r" ); | 47 | accesslist_filehandle = fopen( accesslist_filename, "r" ); |
@@ -54,15 +55,15 @@ static void accesslist_readfile( int foo ) { | |||
54 | } | 55 | } |
55 | 56 | ||
56 | /* We do ignore anything that is not of the form "^[:xdigit:]{40}[^:xdigit:].*" */ | 57 | /* We do ignore anything that is not of the form "^[:xdigit:]{40}[^:xdigit:].*" */ |
57 | while( fgets( static_inbuf, sizeof(static_inbuf), accesslist_filehandle ) ) { | 58 | while( fgets( inbuf, sizeof(inbuf), accesslist_filehandle ) ) { |
58 | int i; | 59 | int i; |
59 | for( i=0; i<20; ++i ) { | 60 | for( i=0; i<20; ++i ) { |
60 | int eger = 16 * scan_fromhex( static_inbuf[ 2*i ] ) + scan_fromhex( static_inbuf[ 1 + 2*i ] ); | 61 | int eger = 16 * scan_fromhex( inbuf[ 2*i ] ) + scan_fromhex( inbuf[ 1 + 2*i ] ); |
61 | if( eger < 0 ) | 62 | if( eger < 0 ) |
62 | continue; | 63 | continue; |
63 | infohash[i] = eger; | 64 | infohash[i] = eger; |
64 | } | 65 | } |
65 | if( scan_fromhex( static_inbuf[ 40 ] ) >= 0 ) | 66 | if( scan_fromhex( inbuf[ 40 ] ) >= 0 ) |
66 | continue; | 67 | continue; |
67 | 68 | ||
68 | /* Append accesslist to accesslist vector */ | 69 | /* Append accesslist to accesslist vector */ |
@@ -95,3 +96,23 @@ void accesslist_init( char *accesslist_filename_in ) { | |||
95 | } | 96 | } |
96 | 97 | ||
97 | #endif | 98 | #endif |
99 | |||
100 | static uint32_t g_adminip_addresses[OT_ADMINIP_MAX]; | ||
101 | static ot_permissions g_adminip_permissions[OT_ADMINIP_MAX]; | ||
102 | static unsigned int g_adminip_count = 0; | ||
103 | |||
104 | int accesslist_blessip( char *ip, ot_permissions permissions ) { | ||
105 | if( g_adminip_count >= OT_ADMINIP_MAX ) | ||
106 | return -1; | ||
107 | memmove( g_adminip_addresses + g_adminip_count, ip, 4 ); | ||
108 | g_adminip_permissions[ g_adminip_count++ ] = permissions; | ||
109 | return 0; | ||
110 | } | ||
111 | |||
112 | int accesslist_isblessed( char *ip, ot_permissions permissions ) { | ||
113 | unsigned int i; | ||
114 | for( i=0; i<g_adminip_count; ++i ) | ||
115 | if( !memcmp( g_adminip_addresses + i, ip, 4) && ( g_adminip_permissions[ i ] & permissions ) ) | ||
116 | return 1; | ||
117 | return 0; | ||
118 | } | ||