Changeset 72
- Timestamp:
- 04/15/04 17:22:58 (9 years ago)
- Location:
- trunk/wifidog
- Files:
-
- 4 modified
-
ChangeLog (modified) (1 diff)
-
src/auth.c (modified) (6 diffs)
-
src/firewall.c (modified) (12 diffs)
-
src/http.c (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/wifidog/ChangeLog
r71 r72 1 1 # $Header$ 2 2004-04-15 Alexandre Carmel-Veilleux <acv@acv.ca> 3 * Changed the locking mechanism, now all access to t_node * structs 4 are properly protected. 5 2 6 2004-04-15 Alexandre Carmel-Veilleux <acv@acv.ca> 3 7 * Connection now closed if counter hasn't change for one full -
trunk/wifidog/src/auth.c
r67 r72 27 27 28 28 #include "common.h" 29 30 pthread_mutex_t nodes_mutex = PTHREAD_MUTEX_INITIALIZER; 29 31 30 32 s_config config; … … 57 59 UserClasses *tmp_uc; 58 60 UserRights *tmp_ur; 61 char *ip, 62 *mac, 63 *token; 59 64 60 node = (t_node*)ptr;65 ip = (char *)ptr; 61 66 62 if (node == NULL) 67 pthread_mutex_lock(&nodes_mutex); 68 69 node = node_find_by_ip(ip); 70 71 if (node == NULL) { 72 pthread_mutex_unlock(&nodes_mutex); 63 73 return; /* Implicit pthread_exit() */ 64 65 profile = authenticate(node->ip, node->mac, node->token, 0); 74 } 75 76 mac = strdup(node->mac); 77 token = strdup(node->token); 78 79 pthread_mutex_unlock(&nodes_mutex); 80 81 profile = authenticate(ip, mac, token, 0); 82 83 pthread_mutex_lock(&nodes_mutex); 84 85 /* can't trust the node to still exist */ 86 node = node_find_by_ip(ip); 87 88 /* don't need any of them anymore */ 89 free(ip); 90 free(token); 91 free(mac); 92 93 if (node == NULL) { 94 pthread_mutex_unlock(&nodes_mutex); 95 return; 96 } 66 97 67 98 if (profile == -1) { … … 73 104 "answer from the central server"); 74 105 node->fd = 0; 106 pthread_mutex_unlock(&nodes_mutex); 75 107 return; 76 108 } else if (profile == 0) { … … 79 111 "timed-out. Please re-login"); 80 112 node->fd = 0; 113 pthread_mutex_unlock(&nodes_mutex); 81 114 return; 82 115 } … … 93 126 _http_output(node->fd, "User Class not defined"); 94 127 node->fd = 0; 128 pthread_mutex_unlock(&nodes_mutex); 95 129 return; 96 130 } else { … … 119 153 node->fd = 0; 120 154 155 pthread_mutex_unlock(&nodes_mutex); 121 156 return; 122 157 } -
trunk/wifidog/src/firewall.c
r71 r72 28 28 #include "common.h" 29 29 30 pthread_mutex_t nodes_mutex = PTHREAD_MUTEX_INITIALIZER;31 32 30 extern s_config config; 31 32 pthread_mutex_t nodes_mutex; 33 33 34 34 t_node *firstnode = NULL; … … 182 182 fw_counter(void) 183 183 { 184 FILE *output; 185 long int counter; 186 int profile, rc; 187 char ip[255], mac[255]; 188 char script[MAX_BUF]; 184 FILE *output; 185 long int counter; 186 int profile, 187 rc; 188 char ip[255], 189 mac[255], 190 script[MAX_BUF], 191 *token; 189 192 t_node *p1; 190 193 … … 204 207 * Maybe this should be done on the auth 205 208 * server */ 209 210 pthread_mutex_lock(&nodes_mutex); 206 211 207 212 p1 = node_find_by_ip(ip); … … 220 225 p1->rights->last_checked = time(NULL); 221 226 p1->counter = counter; 222 223 profile = authenticate(p1->ip,224 p1->mac,225 p1->token,226 p1->counter);227 227 228 if (profile <= 0) { 228 token = strdup(p1->token); 229 230 pthread_mutex_unlock(&nodes_mutex); 231 232 profile = authenticate(ip, mac, token, 233 counter); 234 235 pthread_mutex_lock(&nodes_mutex); 236 237 free(token); 238 239 /* may have changed while we held the 240 * mutex */ 241 p1 = node_find_by_ip(ip); 242 243 if (p1 == NULL) { 244 debug(D_LOG_DEBUG, "Node was " 245 "freed while being " 246 "re-validated!"); 247 } else if (profile <= 0) { 229 248 /* failed */ 230 249 debug(D_LOG_DEBUG, "Auth " … … 248 267 } 249 268 } 269 pthread_mutex_unlock(&nodes_mutex); 250 270 } 251 271 } … … 258 278 { 259 279 260 pthread_mutex_lock(&nodes_mutex);261 280 firstnode = NULL; 262 pthread_mutex_unlock(&nodes_mutex);263 281 } 264 282 … … 269 287 *prevnode; 270 288 271 pthread_mutex_lock(&nodes_mutex);272 273 289 prevnode = NULL; 274 290 curnode = firstnode; … … 303 319 ip, token); 304 320 305 pthread_mutex_unlock(&nodes_mutex);306 307 321 return curnode; 308 322 } … … 313 327 t_node *ptr; 314 328 315 pthread_mutex_lock(&nodes_mutex);316 317 329 ptr = firstnode; 318 330 while (NULL != ptr) { 319 if (0 == strcmp(ptr->ip, ip)) { 320 pthread_mutex_unlock(&nodes_mutex); 331 if (0 == strcmp(ptr->ip, ip)) 321 332 return ptr; 322 }323 333 ptr = ptr->next; 324 334 } 325 326 pthread_mutex_unlock(&nodes_mutex);327 335 328 336 return NULL; … … 334 342 t_node *ptr; 335 343 336 pthread_mutex_lock(&nodes_mutex);337 338 344 ptr = firstnode; 339 345 while (NULL != ptr) { 340 if (0 == strcmp(ptr->token, token)) { 341 pthread_mutex_unlock(&nodes_mutex); 346 if (0 == strcmp(ptr->token, token)) 342 347 return ptr; 343 }344 348 ptr = ptr->next; 345 349 } 346 350 347 pthread_mutex_unlock(&nodes_mutex);348 349 351 return NULL; 350 352 } … … 374 376 t_node *ptr; 375 377 376 pthread_mutex_lock(&nodes_mutex);377 378 378 ptr = firstnode; 379 379 … … 389 389 } 390 390 } 391 392 pthread_mutex_unlock(&nodes_mutex);393 391 } 394 392 -
trunk/wifidog/src/http.c
r68 r72 29 29 30 30 extern s_config config; 31 32 pthread_mutex_t nodes_mutex; 31 33 32 34 void … … 74 76 t_node *node; 75 77 httpVar * token; 76 char * mac; 78 char *mac, 79 *ip; 77 80 int profile; 78 81 int temp; … … 90 93 // We have their MAC address 91 94 95 pthread_mutex_lock(&nodes_mutex); 96 92 97 if ((node = node_find_by_ip(webserver->clientAddr)) 93 98 == NULL) { … … 114 119 webserver->clientSock = -1; 115 120 121 pthread_mutex_unlock(&nodes_mutex); 122 123 /* That clientAddr may be freed prior to the thread 124 * finishing. */ 125 ip = strdup(webserver->clientAddr); 126 116 127 /* start sub process */ 117 128 pthread_create(&tid, NULL, (void *)auth_thread, 118 (void *) node);129 (void *)ip); 119 130 pthread_detach(tid); 120 131
