summaryrefslogtreecommitdiff
path: root/ot_accesslist.c
diff options
context:
space:
mode:
Diffstat (limited to 'ot_accesslist.c')
-rw-r--r--ot_accesslist.c22
1 files changed, 12 insertions, 10 deletions
diff --git a/ot_accesslist.c b/ot_accesslist.c
index ef845d6..4bf1701 100644
--- a/ot_accesslist.c
+++ b/ot_accesslist.c
@@ -21,8 +21,6 @@
21#include <errno.h> 21#include <errno.h>
22#endif 22#endif
23 23
24/* Libowfat */
25
26/* Opentracker */ 24/* Opentracker */
27#include "ot_accesslist.h" 25#include "ot_accesslist.h"
28#include "ot_hex.h" 26#include "ot_hex.h"
@@ -110,7 +108,7 @@ size_t accesslist_parse_hashes(ot_hash *dest, size_t capacity, const char *buf,
110 size_t count = 0; 108 size_t count = 0;
111 109
112 while (count < capacity && end - offs >= 40) { 110 while (count < capacity && end - offs >= 40) {
113 if (hex_tohash(dest[count], offs)) { 111 if (hex_to_hash(dest[count], offs)) {
114 offs += 40; 112 offs += 40;
115 113
116 if (offs == end || !hex_isdigit((unsigned char)*offs)) 114 if (offs == end || !hex_isdigit((unsigned char)*offs))
@@ -162,6 +160,9 @@ static void accesslist_readfile(void) {
162 const char *map; 160 const char *map;
163 size_t maplen, capacity, found; 161 size_t maplen, capacity, found;
164 162
163 if (!g_accesslist_filename)
164 return;
165
165 if (accesslist_map(g_accesslist_filename, &map, &maplen) < 0) { 166 if (accesslist_map(g_accesslist_filename, &map, &maplen) < 0) {
166 char *wd = getcwd(NULL, 0); 167 char *wd = getcwd(NULL, 0);
167 fprintf(stderr, "Warning: Can't open accesslist file: %s (but will try to create it later, if necessary and possible).\nPWD: %s\n", g_accesslist_filename, wd); 168 fprintf(stderr, "Warning: Can't open accesslist file: %s (but will try to create it later, if necessary and possible).\nPWD: %s\n", g_accesslist_filename, wd);
@@ -187,7 +188,8 @@ static void accesslist_readfile(void) {
187 if (map) 188 if (map)
188 munmap((void *)map, maplen); 189 munmap((void *)map, maplen);
189 190
190 qsort(accesslist_new->list, found, sizeof(ot_hash), vector_compare_hash); 191 if (found)
192 qsort(accesslist_new->list, found, sizeof(ot_hash), vector_compare_hash);
191 accesslist_new->size = found; 193 accesslist_new->size = found;
192 194
193 /* Now exchange the accesslist vector in the least race condition prone way */ 195 /* Now exchange the accesslist vector in the least race condition prone way */
@@ -225,18 +227,18 @@ int accesslist_hashisvalid(const ot_hash hash) {
225#endif 227#endif
226 void *exactmatch = NULL; 228 void *exactmatch = NULL;
227 229
228 if (accesslist) 230 if (accesslist && accesslist->size)
229 exactmatch = bsearch(hash, accesslist->list, accesslist->size, OT_HASH_COMPARE_SIZE, vector_compare_hash); 231 exactmatch = bsearch(hash, accesslist->list, accesslist->size, OT_HASH_COMPARE_SIZE, vector_compare_hash);
230 232
231#ifdef WANT_DYNAMIC_ACCESSLIST 233#ifdef WANT_DYNAMIC_ACCESSLIST
232 /* If we had no match on the main list, scan the list of dynamically added hashes */ 234 /* If we had no match on the main list, scan the list of dynamically added hashes */
233 accesslist_add = g_accesslist_add; 235 accesslist_add = g_accesslist_add;
234 if ((exactmatch == NULL) && accesslist_add) 236 if ((exactmatch == NULL) && accesslist_add && accesslist_add->size)
235 exactmatch = bsearch(hash, accesslist_add->list, accesslist_add->size, OT_HASH_COMPARE_SIZE, vector_compare_hash); 237 exactmatch = bsearch(hash, accesslist_add->list, accesslist_add->size, OT_HASH_COMPARE_SIZE, vector_compare_hash);
236 238
237 /* If we found a matching hash on the main list, scan the list of dynamically deleted hashes */ 239 /* If we found a matching hash on the main list, scan the list of dynamically deleted hashes */
238 accesslist_delete = g_accesslist_delete; 240 accesslist_delete = g_accesslist_delete;
239 if ((exactmatch != NULL) && accesslist_delete && bsearch(hash, accesslist_delete->list, accesslist_delete->size, OT_HASH_COMPARE_SIZE, vector_compare_hash)) 241 if ((exactmatch != NULL) && accesslist_delete && accesslist_delete->size && bsearch(hash, accesslist_delete->list, accesslist_delete->size, OT_HASH_COMPARE_SIZE, vector_compare_hash))
240 exactmatch = NULL; 242 exactmatch = NULL;
241#endif 243#endif
242 244
@@ -308,7 +310,7 @@ static void *accesslist_adddel_worker(const char *fifoname, ot_accesslist *_
308 if (linelen < 41) 310 if (linelen < 41)
309 continue; 311 continue;
310 312
311 if (!hex_tohash(info_hash, line)) 313 if (!hex_to_hash(info_hash, line))
312 continue; 314 continue;
313 315
314 /* From now on we modify g_accesslist_add and g_accesslist_delete, so prevent the 316 /* From now on we modify g_accesslist_add and g_accesslist_delete, so prevent the
@@ -386,8 +388,9 @@ void accesslist_init(void) {
386} 388}
387 389
388void accesslist_deinit(void) { 390void accesslist_deinit(void) {
389 /* Wake up sleeping worker */ 391 /* Wake the worker and wait for it to notice that the tracker is stopping. */
390 pthread_kill(thread_id, SIGHUP); 392 pthread_kill(thread_id, SIGHUP);
393 pthread_join(thread_id, NULL);
391 394
392 pthread_mutex_lock(&g_accesslist_mutex); 395 pthread_mutex_lock(&g_accesslist_mutex);
393 396
@@ -399,7 +402,6 @@ void accesslist_deinit(void) {
399#endif 402#endif
400 403
401 pthread_mutex_unlock(&g_accesslist_mutex); 404 pthread_mutex_unlock(&g_accesslist_mutex);
402 pthread_cancel(thread_id);
403 pthread_mutex_destroy(&g_accesslist_mutex); 405 pthread_mutex_destroy(&g_accesslist_mutex);
404} 406}
405 407