Reworked things to get rid of several pointer errors.

Implemented svcname paramater for hosts access mode to set daemon name in hosts.allow,hosts.deny.
New router config syntax:

svcname defaults to uwsgi

uwsgi.ini:
router access:hosts
router access:hosts=svcname
router access:allow=addr
router access:deny=addr

hosts.deny:
svcname:ALL
This commit is contained in:
colinlbc
2012-10-25 14:10:37 -07:00
parent 99f584cff0
commit e8bfa12372
+57 -27
View File
@@ -9,54 +9,85 @@ int deny_severity = LOG_WARNING;
int uwsgi_routing_func_access(struct wsgi_request *wsgi_req, struct uwsgi_route *ur){
int pass = 0;
char *action;
char *host;
char *access_data = malloc(0xff);
char *access_action = malloc(0xff);
char *access_param = malloc(0xff);
char *access_addr = malloc(0xff);
if (strchr((char *)ur->data, ',')){
action = strtok((char *)ur->data, ",");
host = strtok(NULL, "");
}
else {
action = "access:hosts";
}
bzero(access_data, 0xff);
bzero(access_action, 0xff);
bzero(access_param, 0xff);
bzero(access_addr, 0xff);
if (uwsgi_parse_vars(wsgi_req)) {
return -1;
return UWSGI_ROUTE_BREAK;
}
if (!strcmp(action, "access:hosts")){
// syntax access:hosts to use hosts.allow, hosts.deny
char *remote_addr = uwsgi_concat2n(wsgi_req->remote_addr, wsgi_req->remote_addr_len, "", 0);
#ifdef UWSGI_DEBUG
uwsgi_log("Access: Parsing router: %s\n", ur->data);
strncpy(access_data, ur->data, 0xff);
#endif
pass = hosts_ctl("uwsgi", STRING_UNKNOWN, remote_addr, STRING_UNKNOWN);
if (strchr(access_data, '=')){
// parse router config: action=param
access_action = strtok(access_data, "=");
access_param = strtok(NULL, "");
uwsgi_log("Access: access_param = %d\n", access_param);
if (!access_param){
// config syntax error if no access_param
uwsgi_log("Access: syntax error - no paramater specified after action\n");
return UWSGI_ROUTE_BREAK;
}
} else {
// set default access_action, access_param if no colon found
access_action = "hosts";
access_param = "uwsgi";
#ifdef UWSGI_DEBUG
uwsgi_log("Access: Using defaults: access_action = %s, access_param = %s\n", access_action, access_param);
#endif
free(remote_addr);
}
else if (!strcmp(action, "access:allow")){
// implement hosts allow check on syntax access:allow,addr
if (!strncmp(access_action, "hosts", 4)){
// syntax access:hosts=svcname to use hosts.allow, hosts.deny with svcname as daemon name
access_addr = uwsgi_concat2n(wsgi_req->remote_addr, wsgi_req->remote_addr_len, "", 0);
pass = hosts_ctl(access_param, STRING_UNKNOWN, access_addr, STRING_UNKNOWN);
} else if (!strncmp(access_action, "allow", 4)){
// implement hosts allow check on syntax access:allow=addr
} else if (!strncmp(access_action, "deny", 3)){
// implement hosts deny check on syntax access:deny=addr
}
free(access_data);
else if (!strcmp(host, "access:deny")){
// implement hosts deny check on syntax access:deny,addr
}
if (pass == 1){
if (pass){
#ifdef UWSGI_DEBUG
uwsgi_log("Access: allowing access from %s\n", wsgi_req->remote_addr);
uwsgi_log("Access: allowing access from %s\n", access_addr);
#endif
free(access_addr);
return UWSGI_ROUTE_NEXT;
}
else {
} else if (pass == 0){
#ifdef UWSGI_DEBUG
uwsgi_log("Access: denying access from %s\n", wsgi_req->remote_addr);
uwsgi_log("Access: denying access from %s\n", access_addr);
#endif
wsgi_req->status = 403;
wsgi_req->headers_size += wsgi_req->socket->proto_write_header(wsgi_req, "HTTP/1.0 403 Forbidden\r\nContent-Type: text/html\r\n\r\n", 51);
wsgi_req->response_size += wsgi_req->socket->proto_write(wsgi_req,"<h1>403 Forbidden</h1>", 23);
free(access_addr);
return UWSGI_ROUTE_BREAK;
}
#ifdef UWSGI_DEBUG
uwsgi_log("Access: Something went wrong: %d\n", pass);
#endif
free(access_addr);
return UWSGI_ROUTE_BREAK;
}
@@ -75,4 +106,3 @@ struct uwsgi_plugin router_access_plugin = {
.name = "router_access",
.on_load = router_access_register,
};