Changeset 64
- Timestamp:
- 04/14/04 17:14:10 (9 years ago)
- Location:
- trunk/wifidog
- Files:
-
- 2 added
- 2 removed
- 9 modified
-
ChangeLog (modified) (1 diff)
-
configure.in (modified) (1 diff)
-
src/Makefile.am (modified) (2 diffs)
-
src/auth.c (added)
-
src/auth.h (added)
-
src/child.c (deleted)
-
src/child.h (deleted)
-
src/common.h (modified) (2 diffs)
-
src/firewall.c (modified) (9 diffs)
-
src/firewall.h (modified) (2 diffs)
-
src/gateway.c (modified) (4 diffs)
-
src/gateway.h (modified) (1 diff)
-
src/http.c (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/wifidog/ChangeLog
r62 r64 1 1 # $Header$ 2 2004-04-14 Alexandre Carmel-Veilleux <acv@acv.ca> 3 * Switched to threads. Alpha quality build, at best 4 2 5 2004-04-12 Alexandre Carmel-Veilleux <acv@acv.ca> 3 6 * Changed child return value handling, again. Now it's actually -
trunk/wifidog/configure.in
r30 r64 84 84 BB_ENABLE_DOXYGEN 85 85 86 # check for pthread 87 AC_CHECK_HEADER(pthread.h, , AC_MSG_ERROR(You need the pthread headers) ) 88 AC_CHECK_LIB(pthread, pthread_create, , AC_MSG_ERROR(You need the pthread library) ) 89 86 90 # check for libhttpd 87 91 AC_CHECK_HEADER(httpd.h, , AC_MSG_ERROR(You do not seem to have the libhttpd headers - please obtain libhttpd from http://www.hughes.com.au/products/libhttpd/ , patch it with http://www.topfx.com/dist/libhttpd.custom404.patch and install it) ) -
trunk/wifidog/src/Makefile.am
r43 r64 16 16 centralserver.c \ 17 17 http.c \ 18 child.c \18 auth.c \ 19 19 userclasses.c 20 20 … … 27 27 centralserver.h \ 28 28 http.h \ 29 child.h \29 auth.h \ 30 30 userclasses.h 31 31 -
trunk/wifidog/src/common.h
r46 r64 44 44 #include <errno.h> 45 45 46 #include <pthread.h> 47 46 48 #include "httpd.h" 47 49 … … 54 56 #include "http.h" 55 57 #include "centralserver.h" 56 #include " child.h"58 #include "auth.h" 57 59 58 60 #define MAX_BUF 4096 -
trunk/wifidog/src/firewall.c
r59 r64 28 28 #include "common.h" 29 29 30 pthread_mutex_t nodes_mutex = PTHREAD_MUTEX_INITIALIZER; 31 30 32 extern s_config config; 31 33 … … 186 188 char script[MAX_BUF]; 187 189 t_node *p1; 188 ChildInfo *ci;189 pid_t pid;190 190 191 191 sprintf(script, "%s/%s/%s", config.fwscripts_path, config.fwtype, … … 212 212 p1->counter = counter; 213 213 214 ci = new_childinfo(); 215 ci->ip = strdup(p1->ip); 216 ci->mac = strdup(p1->mac); 217 register_child(ci); 218 219 if ((pid = fork()) == 0) { 220 profile = authenticate(p1->ip, 214 profile = authenticate(p1->ip, 221 215 p1->mac, 222 216 p1->token, 223 217 p1->counter); 224 225 /* no negatives */ 226 if (profile <= 0) 227 profile = 0; 228 229 /* SIGCHLD handler will 230 * clean up the mess 231 * afterwards */ 232 exit(profile); 218 219 if (profile <= 0) { 220 /* failed */ 221 debug(D_LOG_DEBUG, "Auth " 222 "failed for client %s", 223 ip); 224 fw_deny(p1->ip, p1->mac, 225 p1->rights->profile); 226 node_delete(p1); 227 } else { 228 /* successful */ 229 debug(D_LOG_DEBUG, "Updated " 230 "client %s counter to " 231 "%ld bytes", ip, 232 counter); 233 234 if (!check_userrights(p1)) { 235 fw_deny(p1->ip, p1->mac, 236 p1->rights->profile); 237 node_delete(p1); 238 } 233 239 } 234 debug(D_LOG_DEBUG, "Forked sub-process"235 " with pid %d", (int)pid);236 debug(D_LOG_DEBUG, "Updated client %s "237 "counter to %ld bytes", ip,238 counter);239 free_childinfo(ci);240 240 } 241 241 } … … 248 248 node_init(void) 249 249 { 250 251 pthread_mutex_lock(&nodes_mutex); 250 252 firstnode = NULL; 253 pthread_mutex_unlock(&nodes_mutex); 251 254 } 252 255 … … 254 257 node_add(char *ip, char *mac, char *token, long int counter, int active) 255 258 { 256 t_node *curnode, 257 *prevnode; 258 259 t_node *curnode, 260 *prevnode; 261 262 pthread_mutex_lock(&nodes_mutex); 263 259 264 prevnode = NULL; 260 265 curnode = firstnode; … … 288 293 debug(D_LOG_DEBUG, "Added a new node to linked list: IP: %s Token: %s", 289 294 ip, token); 295 296 pthread_mutex_unlock(&nodes_mutex); 290 297 291 298 return curnode; … … 296 303 { 297 304 t_node *ptr; 305 306 pthread_mutex_lock(&nodes_mutex); 298 307 299 308 ptr = firstnode; 300 309 while (NULL != ptr) { 301 if (0 == strcmp(ptr->ip, ip)) 310 if (0 == strcmp(ptr->ip, ip)) { 311 pthread_mutex_unlock(&nodes_mutex); 302 312 return ptr; 313 } 314 ptr = ptr->next; 315 } 316 317 pthread_mutex_unlock(&nodes_mutex); 318 319 return NULL; 320 } 321 322 t_node * 323 node_find_by_token(char *token) 324 { 325 t_node *ptr; 326 327 pthread_mutex_lock(&nodes_mutex); 328 329 ptr = firstnode; 330 while (NULL != ptr) { 331 if (0 == strcmp(ptr->token, token)) { 332 pthread_mutex_unlock(&nodes_mutex); 333 return ptr; 334 } 303 335 ptr = ptr->next; 304 336 } 305 337 306 return NULL; 307 } 308 309 t_node * 310 node_find_by_token(char *token) 311 { 312 t_node *ptr; 313 314 ptr = firstnode; 315 while (NULL != ptr) { 316 if (0 == strcmp(ptr->token, token)) 317 return ptr; 318 ptr = ptr->next; 319 } 320 338 pthread_mutex_unlock(&nodes_mutex); 339 321 340 return NULL; 322 341 } … … 345 364 { 346 365 t_node *ptr; 366 367 pthread_mutex_lock(&nodes_mutex); 347 368 348 369 ptr = firstnode; … … 359 380 } 360 381 } 361 } 382 383 pthread_mutex_unlock(&nodes_mutex); 384 } 385 386 int 387 check_userrights(t_node *node) 388 { 389 if (node->rights->end_time <= time(NULL)) { 390 debug(D_LOG_DEBUG, "Connection %s has expired", node->ip); 391 return 0; 392 } 393 394 return 1; 395 } 396 -
trunk/wifidog/src/firewall.h
r45 r64 29 29 30 30 typedef struct _t_node { 31 void*next;31 struct _t_node *next; 32 32 char *ip, 33 33 *mac, 34 34 *token; 35 int active; /* boolean */ 35 int active, /* boolean */ 36 fd; /* socket */ 36 37 long int counter; 37 38 UserRights *rights; … … 54 55 void free_node(t_node *node); 55 56 57 int check_userrights(t_node *node); 58 56 59 #endif /* _FIREWALL_H_ */ -
trunk/wifidog/src/gateway.c
r58 r64 37 37 httpd * webserver; 38 38 int result; 39 pthread_t tid; 39 40 40 41 /* Initialize the linked list */ … … 62 63 fw_init(); 63 64 64 last_checked = time(NULL); 65 65 /* start clean up thread */ 66 pthread_create(&tid, NULL, (void *)cleanup_thread, NULL); 67 pthread_detach(tid); 68 66 69 debug(D_LOG_DEBUG, "Waiting for connections"); 67 70 while(1) { … … 104 107 httpdEndRequest(webserver); 105 108 } 106 107 if (time(NULL) - last_checked > config.checkinterval) {108 fw_counter();109 last_checked = time(NULL);110 }111 109 } 112 110 … … 153 151 154 152 void 153 sigchld_handler(int s) 154 { 155 int status; 156 157 wait(&status); 158 } 159 160 void 155 161 termination_handler(int s) 156 162 { -
trunk/wifidog/src/gateway.h
r57 r64 29 29 30 30 void termination_handler(int s); 31 void sigchld_handler(int s); 31 32 void init_signals(void); 32 33 void check_counters(void); -
trunk/wifidog/src/http.c
r62 r64 72 72 http_callback_auth(httpd * webserver) 73 73 { 74 ChildInfo * ci;74 t_node *node; 75 75 httpVar * token; 76 76 char * mac; 77 77 int profile; 78 78 int temp; 79 p id_t pid;79 pthread_t tid; 80 80 81 81 if (token = httpdGetVariableByName(webserver, "token")) { … … 91 91 // We have their MAC address 92 92 93 /* register child info */94 ci = new_childinfo();95 ci->ip = strdup(webserver->clientAddr);96 ci->mac = strdup(mac);97 register_child(ci);98 99 93 if (!node_find_by_ip(webserver->clientAddr)) { 100 94 node_add(webserver->clientAddr, mac, … … 102 96 } 103 97 104 if ((pid = fork()) == 0) { 105 profile = authenticate(webserver->clientAddr, 106 mac, token->value, 0); 107 if (profile == -1) { 108 // Error talking to central server 109 debug(D_LOG_ERR, "Got %d from central " 110 "server authenticating token " 111 "%s from %s at %s", profile, 112 token->value, 113 webserver->clientAddr, mac); 114 httpdOutput(webserver, "Access denied:" 115 "We did not get a valid " 116 "answer from the central " 117 "server"); 118 httpdEndRequest(webserver); 119 exit(0); 120 } 121 else if (profile == 0) { 122 // Central server said invalid token 123 httpdOutput(webserver, "Your " 124 "authentication has failed or " 125 "timed-out. Please re-login"); 126 httpdEndRequest(webserver); 127 exit(0); 128 } 129 else { 130 // Successfull, what do we do here? 131 httpdEndRequest(webserver); 132 exit(profile); 133 } 134 } else { 135 debug(D_LOG_DEBUG, "Forked sub process with " 136 "pid %d", (int)pid); 137 free(mac); 138 free_childinfo(ci); 139 webserver->clientSock = -1; 140 /* So we don't get shutdown, 141 * there's no error handling in 142 * httpdEndRequest */ 143 } 98 node = node_find_by_ip(webserver->clientAddr); 99 100 node->fd = webserver->clientSock; 101 webserver->clientSock = -1; 102 103 /* start sub process */ 104 pthread_create(&tid, NULL, (void *)auth_thread, 105 (void *)node); 106 pthread_detach(tid); 107 108 free(mac); 144 109 } 145 110 } else { … … 148 113 } 149 114 } 150
