mirror of
https://github.com/clearlinux/uwsgi.git
synced 2026-09-07 06:06:08 +00:00
added blacklist/whitelist support for options
This commit is contained in:
@@ -37,6 +37,9 @@ event = auto
|
||||
timer = auto
|
||||
filemonitor = auto
|
||||
|
||||
blacklist =
|
||||
whitelist =
|
||||
|
||||
embed_files =
|
||||
|
||||
embed_config =
|
||||
|
||||
@@ -1859,6 +1859,32 @@ int uwsgi_logic_opt_for(char *key, char *value) {
|
||||
|
||||
void add_exported_option(char *key, char *value, int configured) {
|
||||
|
||||
struct uwsgi_string_list *blacklist = uwsgi.blacklist;
|
||||
struct uwsgi_string_list *whitelist = uwsgi.whitelist;
|
||||
|
||||
while(blacklist) {
|
||||
if (!strcmp(key, blacklist->value)) {
|
||||
uwsgi_log("uWSGI error: forbidden option \"%s\"\n", key);
|
||||
exit(1);
|
||||
}
|
||||
blacklist = blacklist->next;
|
||||
}
|
||||
|
||||
if (whitelist) {
|
||||
int allowed = 0;
|
||||
while(whitelist) {
|
||||
if (!strcmp(key, whitelist->value)) {
|
||||
allowed = 1;
|
||||
break;
|
||||
}
|
||||
whitelist = whitelist->next;
|
||||
}
|
||||
if (!allowed) {
|
||||
uwsgi_log("uWSGI error: forbidden option \"%s\"\n", key);
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
if (uwsgi.logic_opt_running) goto add;
|
||||
|
||||
if (!strcmp(key, "end") || !strcmp(key, "endfor") || !strcmp(key, "endif")) {
|
||||
@@ -3938,6 +3964,17 @@ char *uwsgi_check_touches(struct uwsgi_string_list *touch_list) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
char *uwsgi_chomp(char *str) {
|
||||
size_t i;
|
||||
for(i=0;i<strlen(str);i++) {
|
||||
if (str[i] == '\r' || str[i] == '\n') {
|
||||
str[i] = 0;
|
||||
return str;
|
||||
}
|
||||
}
|
||||
|
||||
return str;
|
||||
}
|
||||
|
||||
char *uwsgi_tmpname(char *base, char *id) {
|
||||
char *template = uwsgi_concat3(base, "/", id);
|
||||
@@ -3948,3 +3985,19 @@ char *uwsgi_tmpname(char *base, char *id) {
|
||||
|
||||
return template;
|
||||
}
|
||||
|
||||
int uwsgi_file_to_string_list(char *filename, struct uwsgi_string_list **list) {
|
||||
|
||||
char line[1024];
|
||||
|
||||
FILE *fh = fopen(filename, "r");
|
||||
if (fh) {
|
||||
while(fgets(line, 1024, fh)) {
|
||||
uwsgi_string_new_list(list, uwsgi_chomp(uwsgi_str(line)));
|
||||
}
|
||||
fclose(fh);
|
||||
return 1;
|
||||
}
|
||||
uwsgi_error_open(filename);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -1231,6 +1231,20 @@ int main(int argc, char *argv[], char *envp[]) {
|
||||
|
||||
uwsgi.mime_file = "/etc/mime.types";
|
||||
|
||||
#ifdef UWSGI_BLACKLIST
|
||||
if (!uwsgi_file_to_string_list(UWSGI_BLACKLIST, &uwsgi.blacklist)) {
|
||||
uwsgi_log("you cannot run this build of uWSGI without a blacklist file\n");
|
||||
exit(1);
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef UWSGI_WHITELIST
|
||||
if (!uwsgi_file_to_string_list(UWSGI_WHITELIST, &uwsgi.whitelist)) {
|
||||
uwsgi_log("you cannot run this build of uWSGI without a whitelist file\n");
|
||||
exit(1);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
gettimeofday(&uwsgi.start_tv, NULL);
|
||||
|
||||
|
||||
@@ -975,6 +975,8 @@ struct uwsgi_server {
|
||||
// autoload plugins
|
||||
int autoload;
|
||||
struct uwsgi_string_list *plugins_dir;
|
||||
struct uwsgi_string_list *blacklist;
|
||||
struct uwsgi_string_list *whitelist;
|
||||
|
||||
int snapshot;
|
||||
|
||||
@@ -2607,6 +2609,8 @@ int uwsgi_apply_routes(struct wsgi_request *);
|
||||
int uwsgi_apply_routes_fast(struct wsgi_request *, char *, int);
|
||||
#endif
|
||||
|
||||
char *uwsgi_chomp(char *);
|
||||
int uwsgi_file_to_string_list(char *, struct uwsgi_string_list **);
|
||||
void uwsgi_backtrace(int);
|
||||
void uwsgi_check_logrotate(void);
|
||||
char *uwsgi_check_touches(struct uwsgi_string_list *);
|
||||
|
||||
@@ -535,6 +535,12 @@ class uConf(object):
|
||||
if self.get('udp'):
|
||||
self.cflags.append("-DUWSGI_UDP")
|
||||
|
||||
if self.get('blacklist'):
|
||||
self.cflags.append('-DUWSGI_BLACKLIST="\\"%s\\""' % self.get('blacklist'))
|
||||
|
||||
if self.get('whitelist'):
|
||||
self.cflags.append('-DUWSGI_WHITELIST="\\"%s\\""' % self.get('whitelist'))
|
||||
|
||||
has_pcre = False
|
||||
|
||||
# re-enable after pcre fix
|
||||
|
||||
Reference in New Issue
Block a user