File main.c changed (mode: 100644) (index 7f9380f..5a5c82b) |
... |
... |
int handle_request_tunnel_frame(protocol_frame *rcvd_frame) |
407 |
407 |
log_printf(L_INFO, "Got a request to forward data from %s:%d\n", hostname, port); |
log_printf(L_INFO, "Got a request to forward data from %s:%d\n", hostname, port); |
408 |
408 |
|
|
409 |
409 |
// check rules |
// check rules |
410 |
|
if (rules_policy == ENFORCE && nrules > 0) { |
|
411 |
|
// selects a random service |
|
412 |
|
int r = rand() % nrules; |
|
413 |
|
int i; |
|
414 |
|
rule * rtmp = rules; |
|
415 |
|
|
|
416 |
|
for (i = 0; i < r; i++) |
|
417 |
|
{ |
|
418 |
|
if (rtmp != NULL) |
|
419 |
|
rtmp = rtmp->next; |
|
420 |
|
} |
|
421 |
|
|
|
422 |
|
if (rtmp != NULL) { |
|
423 |
|
port = rtmp->port; |
|
424 |
|
hostname = strdup(rtmp->host); |
|
425 |
|
} else { |
|
426 |
|
log_printf(L_ERROR, "Could not find valid hostname/port. Dropping request.\n"); |
|
427 |
|
return -1; |
|
428 |
|
} |
|
429 |
|
|
|
430 |
|
log_printf(L_INFO, "ENFORCE policy enabled, using %s:%d\n", hostname, port); |
|
431 |
|
|
|
432 |
|
} else if (rules_policy == VALIDATE && nrules > 0 ) { |
|
433 |
|
|
|
434 |
|
|
|
435 |
|
// new implementatio |
|
|
410 |
|
if (rules_policy == VALIDATE && nrules > 0 ) { |
436 |
411 |
|
|
437 |
412 |
rule rtmp, *found = NULL; |
rule rtmp, *found = NULL; |
438 |
413 |
rtmp.host = hostname; |
rtmp.host = hostname; |
|
... |
... |
int handle_request_tunnel_frame(protocol_frame *rcvd_frame) |
444 |
419 |
log_printf(L_WARNING, "Rejected, request not in rules\n"); |
log_printf(L_WARNING, "Rejected, request not in rules\n"); |
445 |
420 |
return -1; |
return -1; |
446 |
421 |
} |
} |
447 |
|
|
|
448 |
422 |
} else if (rules_policy != NONE) { |
} else if (rules_policy != NONE) { |
449 |
423 |
log_printf(L_WARNING, "Filter option active but no allowed host/port. All requests will be dropped.\n"); |
log_printf(L_WARNING, "Filter option active but no allowed host/port. All requests will be dropped.\n"); |
450 |
424 |
return -1; |
return -1; |
|
... |
... |
void load_rules() |
808 |
782 |
rule_obj->host = strdup(ahost); |
rule_obj->host = strdup(ahost); |
809 |
783 |
|
|
810 |
784 |
LL_APPEND(rules, rule_obj); |
LL_APPEND(rules, rule_obj); |
811 |
|
|
|
812 |
785 |
linen++; |
linen++; |
813 |
786 |
} else { |
} else { |
814 |
787 |
log_printf(L_WARNING, "Invalid port in line: %s\n", line); |
log_printf(L_WARNING, "Invalid port in line: %s\n", line); |
|
... |
... |
void load_rules() |
824 |
797 |
nrules = linen; |
nrules = linen; |
825 |
798 |
|
|
826 |
799 |
log_printf(L_INFO, "Loaded %d rules\n", nrules); |
log_printf(L_INFO, "Loaded %d rules\n", nrules); |
827 |
|
if (nrules==0 && |
|
828 |
|
(rules_policy == ENFORCE || rules_policy == VALIDATE)){ |
|
|
800 |
|
if (nrules==0 && rules_policy == VALIDATE){ |
829 |
801 |
log_printf(L_WARNING, "No rules loaded! NO CONNECTIONS WILL BE ALLOWED!\n"); |
log_printf(L_WARNING, "No rules loaded! NO CONNECTIONS WILL BE ALLOWED!\n"); |
830 |
802 |
} |
} |
831 |
803 |
} |
} |
|
... |
... |
void help() |
1196 |
1168 |
fprintf(stderr, "-C <dir> - save private key in <dir> instead of /etc/tuntox in server mode\n"); |
fprintf(stderr, "-C <dir> - save private key in <dir> instead of /etc/tuntox in server mode\n"); |
1197 |
1169 |
fprintf(stderr, "-s <secret> - shared secret used for connection authentication (max %u characters)\n", TOX_MAX_FRIEND_REQUEST_LENGTH-1); |
fprintf(stderr, "-s <secret> - shared secret used for connection authentication (max %u characters)\n", TOX_MAX_FRIEND_REQUEST_LENGTH-1); |
1198 |
1170 |
fprintf(stderr, "-f <file> - allows only connections to hostname/port combinations contained in <file>. Rules must by entered one per line with the <hostname>:<port> format\n"); |
fprintf(stderr, "-f <file> - allows only connections to hostname/port combinations contained in <file>. Rules must by entered one per line with the <hostname>:<port> format\n"); |
1199 |
|
fprintf(stderr, "-e <file> - same as -f, but force the connection to a randomly selected hostname/port combination of <file>, ignoring the client's request\n"); |
|
1200 |
1171 |
fprintf(stderr, "-d - debug mode\n"); |
fprintf(stderr, "-d - debug mode\n"); |
1201 |
1172 |
fprintf(stderr, "-q - quiet mode\n"); |
fprintf(stderr, "-q - quiet mode\n"); |
1202 |
1173 |
fprintf(stderr, "-S - send output to syslog instead of stderr\n"); |
fprintf(stderr, "-S - send output to syslog instead of stderr\n"); |
|
... |
... |
int main(int argc, char *argv[]) |
1218 |
1189 |
|
|
1219 |
1190 |
log_init(); |
log_init(); |
1220 |
1191 |
|
|
1221 |
|
while ((oc = getopt(argc, argv, "L:pi:C:s:f:e:P:dqhSF:DU:")) != -1) |
|
|
1192 |
|
while ((oc = getopt(argc, argv, "L:pi:C:s:f:P:dqhSF:DU:")) != -1) |
1222 |
1193 |
{ |
{ |
1223 |
1194 |
switch(oc) |
switch(oc) |
1224 |
1195 |
{ |
{ |
|
... |
... |
int main(int argc, char *argv[]) |
1296 |
1267 |
rules_policy = VALIDATE; |
rules_policy = VALIDATE; |
1297 |
1268 |
log_printf(L_INFO, "Filter policy set to VALIDATE\n"); |
log_printf(L_INFO, "Filter policy set to VALIDATE\n"); |
1298 |
1269 |
break; |
break; |
1299 |
|
case 'e': |
|
1300 |
|
strncpy(rules_file, optarg, sizeof(rules_file) - 1); |
|
1301 |
|
rules_policy = ENFORCE; |
|
1302 |
|
log_printf(L_INFO, "Filter policy set to ENFORCE\n"); |
|
1303 |
|
break; |
|
1304 |
1270 |
case 's': |
case 's': |
1305 |
1271 |
/* Shared secret */ |
/* Shared secret */ |
1306 |
1272 |
use_shared_secret = 1; |
use_shared_secret = 1; |