diff options
Diffstat (limited to 'main')
-rw-r--r-- | main/http.c | 22 | ||||
-rw-r--r-- | main/manager.c | 37 |
2 files changed, 40 insertions, 19 deletions
diff --git a/main/http.c b/main/http.c index 1c4a9ca60..cc32b9422 100644 --- a/main/http.c +++ b/main/http.c @@ -57,12 +57,16 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$") #define MAX_PREFIX 80 #define DEFAULT_PORT 8088 #define DEFAULT_TLS_PORT 8089 +#define DEFAULT_SESSION_LIMIT 100 /* See http.h for more information about the SSL implementation */ #if defined(HAVE_OPENSSL) && (defined(HAVE_FUNOPEN) || defined(HAVE_FOPENCOOKIE)) #define DO_SSL /* comment in/out if you want to support ssl */ #endif +static int session_limit = DEFAULT_SESSION_LIMIT; +static int session_count = 0; + static struct ast_tls_config http_tls_cfg; static void *httpd_helper_thread(void *arg); @@ -829,6 +833,10 @@ static void *httpd_helper_thread(void *data) char *uri, *method; enum ast_http_method http_method = AST_HTTP_UNKNOWN; + if (ast_atomic_fetchadd_int(&session_count, +1) >= session_limit) { + goto done; + } + if (!fgets(buf, sizeof(buf), ser->f)) { goto done; } @@ -894,17 +902,19 @@ static void *httpd_helper_thread(void *data) if (!*uri) { ast_http_error(ser, 400, "Bad Request", "Invalid Request"); - return NULL; + goto done; } handle_uri(ser, uri, http_method, headers); - /* Clean up all the header information pulled as well */ +done: + ast_atomic_fetchadd_int(&session_count, -1); + + /* clean up all the header information */ if (headers) { ast_variables_destroy(headers); } -done: if (ser->f) { fclose(ser->f); } @@ -1044,6 +1054,12 @@ static int __ast_http_load(int reload) } } else if (!strcasecmp(v->name, "redirect")) { add_redirect(v->value); + } else if (!strcasecmp(v->name, "sessionlimit")) { + if (ast_parse_arg(v->value, PARSE_INT32|PARSE_DEFAULT|PARSE_IN_RANGE, + &session_limit, DEFAULT_SESSION_LIMIT, 1, INT_MAX)) { + ast_log(LOG_WARNING, "Invalid %s '%s' at line %d of http.conf\n", + v->name, v->value, v->lineno); + } } else { ast_log(LOG_WARNING, "Ignoring unknown option '%s' in http.conf\n", v->name); } diff --git a/main/manager.c b/main/manager.c index da0523be9..784b3799c 100644 --- a/main/manager.c +++ b/main/manager.c @@ -3891,6 +3891,27 @@ static int action_originate(struct mansession *s, const struct message *m) ast_format_cap_remove_all(cap); ast_parse_allow_disallow(NULL, cap, codecs, 1); } + + if (!ast_strlen_zero(app)) { + /* To run the System application (or anything else that goes to + * shell), you must have the additional System privilege */ + if (!(s->session->writeperm & EVENT_FLAG_SYSTEM) + && ( + strcasestr(app, "system") || /* System(rm -rf /) + TrySystem(rm -rf /) */ + strcasestr(app, "exec") || /* Exec(System(rm -rf /)) + TryExec(System(rm -rf /)) */ + strcasestr(app, "agi") || /* AGI(/bin/rm,-rf /) + EAGI(/bin/rm,-rf /) */ + strstr(appdata, "SHELL") || /* NoOp(${SHELL(rm -rf /)}) */ + strstr(appdata, "EVAL") /* NoOp(${EVAL(${some_var_containing_SHELL})}) */ + )) { + astman_send_error(s, m, "Originate with certain 'Application' arguments requires the additional System privilege, which you do not have."); + res = 0; + goto fast_orig_cleanup; + } + } + /* Allocate requested channel variables */ vars = astman_get_variables(m); @@ -3928,22 +3949,6 @@ static int action_originate(struct mansession *s, const struct message *m) } } } else if (!ast_strlen_zero(app)) { - /* To run the System application (or anything else that goes to shell), you must have the additional System privilege */ - if (!(s->session->writeperm & EVENT_FLAG_SYSTEM) - && ( - strcasestr(app, "system") || /* System(rm -rf /) - TrySystem(rm -rf /) */ - strcasestr(app, "exec") || /* Exec(System(rm -rf /)) - TryExec(System(rm -rf /)) */ - strcasestr(app, "agi") || /* AGI(/bin/rm,-rf /) - EAGI(/bin/rm,-rf /) */ - strstr(appdata, "SHELL") || /* NoOp(${SHELL(rm -rf /)}) */ - strstr(appdata, "EVAL") /* NoOp(${EVAL(${some_var_containing_SHELL})}) */ - )) { - astman_send_error(s, m, "Originate with certain 'Application' arguments requires the additional System privilege, which you do not have."); - res = 0; - goto fast_orig_cleanup; - } res = ast_pbx_outgoing_app(tech, cap, data, to, app, appdata, &reason, 1, l, n, vars, account, NULL); } else { if (exten && context && pi) { |