static int mod_setenv_patch_connection(server *srv, connection *con, plugin_data *p) { size_t i, j; plugin_config *s = p->config_storage[0]; PATCH(request_header); PATCH(response_header); PATCH(environment); /* skip the first, the global context */ for (i = 1; i < srv->config_context->used; i++) { data_config *dc = (data_config *)srv->config_context->data[i]; s = p->config_storage[i]; /* condition didn't match */ if (!config_check_cond(srv, con, dc)) continue; /* merge config */ for (j = 0; j < dc->value->used; j++) { data_unset *du = dc->value->data[j]; if (buffer_is_equal_string(du->key, CONST_STR_LEN("setenv.add-request-header"))) { PATCH(request_header); } else if (buffer_is_equal_string(du->key, CONST_STR_LEN("setenv.add-response-header"))) { PATCH(response_header); } else if (buffer_is_equal_string(du->key, CONST_STR_LEN("setenv.add-environment"))) { PATCH(environment); } } } return 0; }
static int mod_magnet_patch_connection(server *srv, connection *con, plugin_data *p) { size_t i, j; plugin_config *s = p->config_storage[0]; PATCH(url_raw); PATCH(physical_path); /* skip the first, the global context */ for (i = 1; i < srv->config_context->used; i++) { data_config *dc = (data_config *)srv->config_context->data[i]; s = p->config_storage[i]; /* condition didn't match */ if (!config_check_cond(srv, con, dc)) continue; /* merge config */ for (j = 0; j < dc->value->used; j++) { data_unset *du = dc->value->data[j]; if (buffer_is_equal_string(du->key, CONST_STR_LEN(MAGNET_CONFIG_RAW_URL))) { PATCH(url_raw); } else if (buffer_is_equal_string(du->key, CONST_STR_LEN(MAGNET_CONFIG_PHYSICAL_PATH))) { PATCH(physical_path); } } } return 0; }
static int mod_cgi_patch_connection(server *srv, connection *con, plugin_data *p) { size_t i, j; plugin_config *s = p->config_storage[0]; PATCH_OPTION(cgi); PATCH_OPTION(execute_all); PATCH_OPTION(execute_x_only); /* skip the first, the global context */ for (i = 1; i < srv->config_context->used; i++) { data_config *dc = (data_config *)srv->config_context->data[i]; s = p->config_storage[i]; /* condition didn't match */ if (!config_check_cond(srv, con, dc)) continue; /* merge config */ for (j = 0; j < dc->value->used; j++) { data_unset *du = dc->value->data[j]; if (buffer_is_equal_string(du->key, CONST_STR_LEN(CONFIG_ASSIGN))) { PATCH_OPTION(cgi); } else if (buffer_is_equal_string(du->key, CONST_STR_LEN(CONFIG_EXECUTE_ALL))) { PATCH_OPTION(execute_all); } else if (buffer_is_equal_string(du->key, CONST_STR_LEN(CONFIG_EXECUTE_X_ONLY))) { PATCH_OPTION(execute_x_only); } } } return 0; }
static int mod_lisp_patch_connection(server *srv, connection *con, plugin_data *p) #define PATCH(x) p->conf.x = s->x { size_t i, j; plugin_config *s = p->config_storage[0]; PATCH(LispUseHandler); PATCH(LispServerId); PATCH(LispServerPort); PATCH(LispServerIP); PATCH(loglevel); PATCH(LispSocketPoolSize); /* Skip the first, global context. */ for (i = 1; i < srv->config_context->used; i++) { data_config *dc = (data_config *)srv->config_context->data[i]; s = p->config_storage[i]; if (!config_check_cond(srv, con, dc)) continue; /* Condition did not match. */ for (j = 0; j < dc->value->used; j++) { /* Merge config. */ data_unset *du = dc->value->data[j]; if (buffer_is_equal_string(du->key, CONST_STR_LEN("lisp.use-handler"))) PATCH(LispUseHandler); else if (buffer_is_equal_string(du->key, CONST_STR_LEN("lisp.server-id"))) PATCH(LispServerId); else if (buffer_is_equal_string(du->key, CONST_STR_LEN("lisp.server-ip"))) PATCH(LispServerIP); else if (buffer_is_equal_string(du->key, CONST_STR_LEN("lisp.server-port"))) PATCH(LispServerPort); else if (buffer_is_equal_string(du->key, CONST_STR_LEN("lisp.log-level"))) PATCH(loglevel); } } return 0; }
static int mod_bitsvhd_patch_connection(server *srv, connection *con, plugin_data *p) { size_t i, j; plugin_config *s = p->config_storage[0]; PATCH(activate); PATCH(sparse); /* skip the first, the global context */ for (i = 1; i < srv->config_context->used; i++) { data_config *dc = (data_config *)srv->config_context->data[i]; s = p->config_storage[i]; /* condition didn't match */ if (!config_check_cond(srv, con, dc)) continue; /* merge config */ for (j = 0; j < dc->value->used; j++) { data_unset *du = dc->value->data[j]; if (buffer_is_equal_string(du->key, CONST_STR_LEN("bitsvhd.activate"))) { PATCH(activate); } else if (buffer_is_equal_string(du->key, CONST_STR_LEN("bitsvhd.sparse"))) { PATCH(sparse); } } } return 0; }
static int mod_cgi_patch_connection(server *srv, connection *con, plugin_data *p) { size_t i, j; plugin_config *s = p->config_storage[0]; PATCH(cgi); PATCH(execute_x_only); PATCH(xsendfile_allow); PATCH(xsendfile_docroot); /* skip the first, the global context */ for (i = 1; i < srv->config_context->used; i++) { data_config *dc = (data_config *)srv->config_context->data[i]; s = p->config_storage[i]; /* condition didn't match */ if (!config_check_cond(srv, con, dc)) continue; /* merge config */ for (j = 0; j < dc->value->used; j++) { data_unset *du = dc->value->data[j]; if (buffer_is_equal_string(du->key, CONST_STR_LEN("cgi.assign"))) { PATCH(cgi); } else if (buffer_is_equal_string(du->key, CONST_STR_LEN("cgi.execute-x-only"))) { PATCH(execute_x_only); } else if (buffer_is_equal_string(du->key, CONST_STR_LEN("cgi.x-sendfile"))) { PATCH(xsendfile_allow); } else if (buffer_is_equal_string(du->key, CONST_STR_LEN("cgi.x-sendfile-docroot"))) { PATCH(xsendfile_docroot); } } } return 0; }
static int mod_usertrack_patch_connection(server *srv, connection *con, plugin_data *p) { size_t i, j; plugin_config *s = p->config_storage[0]; PATCH(cookie_name); PATCH(cookie_domain); PATCH(cookie_max_age); /* skip the first, the global context */ for (i = 1; i < srv->config_context->used; i++) { data_config *dc = (data_config *)srv->config_context->data[i]; s = p->config_storage[i]; /* condition didn't match */ if (!config_check_cond(srv, con, dc)) continue; /* merge config */ for (j = 0; j < dc->value->used; j++) { data_unset *du = dc->value->data[j]; if (buffer_is_equal_string(du->key, CONST_STR_LEN("usertrack.cookie-name"))) { PATCH(cookie_name); } else if (buffer_is_equal_string(du->key, CONST_STR_LEN("usertrack.cookie-max-age"))) { PATCH(cookie_max_age); } else if (buffer_is_equal_string(du->key, CONST_STR_LEN("usertrack.cookie-domain"))) { PATCH(cookie_domain); } } } return 0; }
static int mod_secdownload_patch_connection(server *srv, connection *con, plugin_data *p) { size_t i, j; plugin_config *s = p->config_storage[0]; PATCH(secret); PATCH(doc_root); PATCH(uri_prefix); PATCH(timeout); /* skip the first, the global context */ for (i = 1; i < srv->config_context->used; i++) { data_config *dc = (data_config *)srv->config_context->data[i]; s = p->config_storage[i]; /* condition didn't match */ if (!config_check_cond(srv, con, dc)) continue; /* merge config */ for (j = 0; j < dc->value->used; j++) { data_unset *du = dc->value->data[j]; if (buffer_is_equal_string(du->key, CONST_STR_LEN("secdownload.secret"))) { PATCH(secret); } else if (buffer_is_equal_string(du->key, CONST_STR_LEN("secdownload.document-root"))) { PATCH(doc_root); } else if (buffer_is_equal_string(du->key, CONST_STR_LEN("secdownload.uri-prefix"))) { PATCH(uri_prefix); } else if (buffer_is_equal_string(du->key, CONST_STR_LEN("secdownload.timeout"))) { PATCH(timeout); } } } return 0; }
static int mod_staticfile_patch_connection(server *srv, connection *con, plugin_data *p) { size_t i, j; plugin_config *s = p->config_storage[0]; PATCH(exclude_ext); PATCH(etags_used); PATCH(disable_pathinfo); /* skip the first, the global context */ for (i = 1; i < srv->config_context->used; i++) { data_config *dc = (data_config *)srv->config_context->data[i]; s = p->config_storage[i]; /* condition didn't match */ if (!config_check_cond(srv, con, dc)) continue; /* merge config */ for (j = 0; j < dc->value->used; j++) { data_unset *du = dc->value->data[j]; if (buffer_is_equal_string(du->key, CONST_STR_LEN("static-file.exclude-extensions"))) { PATCH(exclude_ext); } else if (buffer_is_equal_string(du->key, CONST_STR_LEN("static-file.etags"))) { PATCH(etags_used); } else if (buffer_is_equal_string(du->key, CONST_STR_LEN("static-file.disable-pathinfo"))) { PATCH(disable_pathinfo); } } } return 0; }
static int mod_authn_gssapi_patch_connection(server *srv, connection *con, plugin_data *p) { size_t i, j; plugin_config *s = p->config_storage[0]; PATCH(auth_gssapi_keytab); PATCH(auth_gssapi_principal); /* skip the first, the global context */ for (i = 1; i < srv->config_context->used; i++) { data_config *dc = (data_config *)srv->config_context->data[i]; s = p->config_storage[i]; /* condition didn't match */ if (!config_check_cond(srv, con, dc)) continue; /* merge config */ for (j = 0; j < dc->value->used; j++) { data_unset *du = dc->value->data[j]; if (buffer_is_equal_string(du->key, CONST_STR_LEN("auth.backend.gssapi.keytab"))) { PATCH(auth_gssapi_keytab); } else if (buffer_is_equal_string(du->key, CONST_STR_LEN("auth.backend.gssapi.principal"))) { PATCH(auth_gssapi_principal); } } } return 0; }
static void run_buffer_path_simplify(buffer *psrc, buffer *pdest, const char *in, size_t in_len, const char *out, size_t out_len) { buffer_copy_string_len(psrc, in, in_len); buffer_path_simplify(pdest, psrc); if (!buffer_is_equal_string(pdest, out, out_len)) { fprintf(stderr, "%s.%d: buffer_path_simplify('%s') failed: expected '%s', got '%s'\n", __FILE__, __LINE__, in, out, pdest->ptr ? pdest->ptr : ""); fflush(stderr); abort(); } else { if (psrc != pdest) buffer_copy_buffer(psrc, pdest); buffer_path_simplify(pdest, psrc); if (!buffer_is_equal_string(pdest, out, out_len)) { fprintf(stderr, "%s.%d: buffer_path_simplify('%s') failed - not idempotent: expected '%s', got '%s'\n", __FILE__, __LINE__, in, out, pdest->ptr ? pdest->ptr : ""); fflush(stderr); abort(); } } }
static int proxy_create_env(server *srv, handler_ctx *hctx) { size_t i; connection *con = hctx->remote_conn; buffer *b; /* build header */ b = buffer_init(); /* request line */ buffer_copy_string(b, get_http_method_name(con->request.http_method)); buffer_append_string_len(b, CONST_STR_LEN(" ")); buffer_append_string_buffer(b, con->request.uri); buffer_append_string_len(b, CONST_STR_LEN(" HTTP/1.0\r\n")); proxy_append_header(con, "X-Forwarded-For", (char *)inet_ntop_cache_get_ip(srv, &(con->dst_addr))); /* http_host is NOT is just a pointer to a buffer * which is NULL if it is not set */ if (!buffer_string_is_empty(con->request.http_host)) { proxy_set_header(con, "X-Host", con->request.http_host->ptr); } proxy_set_header(con, "X-Forwarded-Proto", con->uri.scheme->ptr); /* request header */ for (i = 0; i < con->request.headers->used; i++) { data_string *ds; ds = (data_string *)con->request.headers->data[i]; if (!buffer_is_empty(ds->value) && !buffer_is_empty(ds->key)) { if (buffer_is_equal_string(ds->key, CONST_STR_LEN("Connection"))) continue; if (buffer_is_equal_string(ds->key, CONST_STR_LEN("Proxy-Connection"))) continue; buffer_append_string_buffer(b, ds->key); buffer_append_string_len(b, CONST_STR_LEN(": ")); buffer_append_string_buffer(b, ds->value); buffer_append_string_len(b, CONST_STR_LEN("\r\n")); } } buffer_append_string_len(b, CONST_STR_LEN("\r\n")); hctx->wb->bytes_in += buffer_string_length(b); chunkqueue_append_buffer(hctx->wb, b); buffer_free(b); /* body */ if (con->request.content_length) { chunkqueue *req_cq = con->request_content_queue; chunkqueue_steal(hctx->wb, req_cq, req_cq->bytes_in); } return 0; }
static void test_buffer_append_path_len(void) { buffer *b = buffer_init(); buffer_append_path_len(b, CONST_STR_LEN("a")); assert(buffer_is_equal_string(b, CONST_STR_LEN("/a"))); buffer_clear(b); buffer_append_path_len(b, CONST_STR_LEN("a")); assert(buffer_is_equal_string(b, CONST_STR_LEN("/a"))); buffer_clear(b); buffer_append_path_len(b, CONST_STR_LEN("/a")); assert(buffer_is_equal_string(b, CONST_STR_LEN("/a"))); buffer_copy_string_len(b, CONST_STR_LEN("/")); buffer_append_path_len(b, CONST_STR_LEN("a")); assert(buffer_is_equal_string(b, CONST_STR_LEN("/a"))); buffer_copy_string_len(b, CONST_STR_LEN("/")); buffer_append_path_len(b, CONST_STR_LEN("/a")); assert(buffer_is_equal_string(b, CONST_STR_LEN("/a"))); buffer_copy_string_len(b, CONST_STR_LEN("a")); buffer_append_path_len(b, CONST_STR_LEN("a")); assert(buffer_is_equal_string(b, CONST_STR_LEN("a/a"))); buffer_copy_string_len(b, CONST_STR_LEN("a/")); buffer_append_path_len(b, CONST_STR_LEN("a")); assert(buffer_is_equal_string(b, CONST_STR_LEN("a/a"))); buffer_copy_string_len(b, CONST_STR_LEN("a/")); buffer_append_path_len(b, CONST_STR_LEN("/a")); assert(buffer_is_equal_string(b, CONST_STR_LEN("a/a"))); buffer_copy_string_len(b, CONST_STR_LEN("/a/")); buffer_append_path_len(b, CONST_STR_LEN("/a")); assert(buffer_is_equal_string(b, CONST_STR_LEN("/a/a"))); buffer_free(b); }
static int mod_authn_mysql_patch_connection(server *srv, connection *con, plugin_data *p) { size_t i, j; plugin_config *s = p->config_storage[0]; PATCH(auth_mysql_host); PATCH(auth_mysql_user); PATCH(auth_mysql_pass); PATCH(auth_mysql_db); PATCH(auth_mysql_port); PATCH(auth_mysql_socket); PATCH(auth_mysql_users_table); PATCH(auth_mysql_col_user); PATCH(auth_mysql_col_pass); PATCH(auth_mysql_col_realm); /* skip the first, the global context */ for (i = 1; i < srv->config_context->used; i++) { data_config *dc = (data_config *)srv->config_context->data[i]; s = p->config_storage[i]; /* condition didn't match */ if (!config_check_cond(srv, con, dc)) continue; /* merge config */ for (j = 0; j < dc->value->used; j++) { data_unset *du = dc->value->data[j]; if (buffer_is_equal_string(du->key, CONST_STR_LEN("auth.backend.mysql.host"))) { PATCH(auth_mysql_host); } else if (buffer_is_equal_string(du->key, CONST_STR_LEN("auth.backend.mysql.user"))) { PATCH(auth_mysql_user); } else if (buffer_is_equal_string(du->key, CONST_STR_LEN("auth.backend.mysql.pass"))) { PATCH(auth_mysql_pass); } else if (buffer_is_equal_string(du->key, CONST_STR_LEN("auth.backend.mysql.db"))) { PATCH(auth_mysql_db); } else if (buffer_is_equal_string(du->key, CONST_STR_LEN("auth.backend.mysql.port"))) { PATCH(auth_mysql_port); } else if (buffer_is_equal_string(du->key, CONST_STR_LEN("auth.backend.mysql.socket"))) { PATCH(auth_mysql_socket); } else if (buffer_is_equal_string(du->key, CONST_STR_LEN("auth.backend.mysql.users_table"))) { PATCH(auth_mysql_users_table); } else if (buffer_is_equal_string(du->key, CONST_STR_LEN("auth.backend.mysql.col_user"))) { PATCH(auth_mysql_col_user); } else if (buffer_is_equal_string(du->key, CONST_STR_LEN("auth.backend.mysql.col_pass"))) { PATCH(auth_mysql_col_pass); } else if (buffer_is_equal_string(du->key, CONST_STR_LEN("auth.backend.mysql.col_realm"))) { PATCH(auth_mysql_col_realm); } } } return 0; }
static int mod_accesslog_patch_connection(server *srv, connection *con, plugin_data *p) { size_t i, j; plugin_config *s = p->config_storage[0]; PATCH(access_logfile); PATCH(format); PATCH(log_access_fd); PATCH(last_generated_accesslog_ts_ptr); PATCH(access_logbuffer); PATCH(ts_accesslog_str); PATCH(ts_accesslog_fmt_str); PATCH(append_tz_offset); PATCH(parsed_format); PATCH(use_syslog); PATCH(syslog_level); /* skip the first, the global context */ for (i = 1; i < srv->config_context->used; i++) { data_config *dc = (data_config *)srv->config_context->data[i]; s = p->config_storage[i]; /* condition didn't match */ if (!config_check_cond(srv, con, dc)) continue; /* merge config */ for (j = 0; j < dc->value->used; j++) { data_unset *du = dc->value->data[j]; if (buffer_is_equal_string(du->key, CONST_STR_LEN("accesslog.filename"))) { PATCH(access_logfile); PATCH(log_access_fd); PATCH(access_logbuffer); } else if (buffer_is_equal_string(du->key, CONST_STR_LEN("accesslog.format"))) { PATCH(format); PATCH(parsed_format); PATCH(last_generated_accesslog_ts_ptr); PATCH(ts_accesslog_str); PATCH(ts_accesslog_fmt_str); PATCH(append_tz_offset); } else if (buffer_is_equal_string(du->key, CONST_STR_LEN("accesslog.use-syslog"))) { PATCH(use_syslog); } else if (buffer_is_equal_string(du->key, CONST_STR_LEN("accesslog.syslog-level"))) { PATCH(syslog_level); } } } return 0; }
static void test_buffer_to_lower_upper(void) { buffer *psrc = buffer_init(); buffer_copy_string_len(psrc, CONST_STR_LEN("0123456789abcdefghijklmnopqrstuvwxyz")); buffer_to_lower(psrc); assert(buffer_is_equal_string(psrc, CONST_STR_LEN("0123456789abcdefghijklmnopqrstuvwxyz"))); buffer_to_upper(psrc); assert(buffer_is_equal_string(psrc, CONST_STR_LEN("0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"))); buffer_to_upper(psrc); assert(buffer_is_equal_string(psrc, CONST_STR_LEN("0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"))); buffer_to_lower(psrc); assert(buffer_is_equal_string(psrc, CONST_STR_LEN("0123456789abcdefghijklmnopqrstuvwxyz"))); buffer_free(psrc); }
static int mod_evasive_patch_connection(server *srv, connection *con, plugin_data *p) { size_t i, j; plugin_config *s = p->config_storage[0]; PATCH_OPTION(max_conns); /* skip the first, the global context */ for (i = 1; i < srv->config_context->used; i++) { data_config *dc = (data_config *)srv->config_context->data[i]; s = p->config_storage[i]; /* condition didn't match */ if (!config_check_cond(srv, con, dc)) continue; /* merge config */ for (j = 0; j < dc->value->used; j++) { data_unset *du = dc->value->data[j]; if (buffer_is_equal_string(du->key, CONST_STR_LEN("evasive.max-conns-per-ip"))) { PATCH_OPTION(max_conns); } } } return 0; }
inline static void check_base64 (char *out, const size_t out_sz, const char *in, const size_t in_len, const base64_charset enc) { force_assert(out_sz == li_to_base64_no_padding(out, out_sz, (const unsigned char *)in, in_len, enc)); buffer_reset(check); force_assert(NULL != buffer_append_base64_decode(check, out, out_sz, enc)); force_assert(buffer_is_equal_string(check, in, in_len)); }
/* (case-sensitive version of array.c:array_get_index(), * and common case expects small num of allowed tokens, * so it is reasonably performant to simply walk the array) */ static int http_auth_array_contains (const array * const a, const char * const k, const size_t klen) { for (size_t i = 0, used = a->used; i < used; ++i) { if (buffer_is_equal_string(a->data[i]->key, k, klen)) { return 1; } } return 0; }
int config_patch_connection(server *srv, connection *con, comp_key_t comp) { size_t i, j; con->conditional_is_valid[comp] = 1; /* skip the first, the global context */ for (i = 1; i < srv->config_context->used; i++) { data_config *dc = (data_config *)srv->config_context->data[i]; specific_config *s = &srv->config_storage[i]; /* not our stage */ if (comp != dc->comp) continue; /* condition didn't match */ if (!config_check_cond(srv, con, dc)) continue; /* merge config */ for (j = 0; j < dc->value->used; j++) { data_unset *du = dc->value->data[j]; if (buffer_is_equal_string(du->key, CONST_STR_LEN("server.document-root"))) { PATCH(document_root); } else if (buffer_is_equal_string(du->key, CONST_STR_LEN("ssl.pemfile"))) { PATCH(ssl_pemfile); } else if (buffer_is_equal_string(du->key, CONST_STR_LEN("ssl.ca-file"))) { PATCH(ssl_ca_file); } else if (buffer_is_equal_string(du->key, CONST_STR_LEN("ssl.cipher-list"))) { PATCH(ssl_cipher_list); } else if (buffer_is_equal_string(du->key, CONST_STR_LEN("ssl.engine"))) { PATCH(is_ssl); #ifdef HAVE_LSTAT } else if (buffer_is_equal_string(du->key, CONST_STR_LEN("server.follow-symlink"))) { PATCH(follow_symlink); #endif } else if (buffer_is_equal_string(du->key, CONST_STR_LEN("server.name"))) { buffer_copy_string_buffer(con->server_name, s->server_name); } else if (buffer_is_equal_string(du->key, CONST_STR_LEN("connection.kbytes-per-second"))) { PATCH(kbytes_per_second); } else if (buffer_is_equal_string(du->key, CONST_STR_LEN("server.kbytes-per-second"))) { PATCH(global_kbytes_per_second); PATCH(global_bytes_per_second_cnt); con->conf.global_bytes_per_second_cnt_ptr = &s->global_bytes_per_second_cnt; } } } return 0; }
static int mod_simple_vhost_patch_connection(server *srv, connection *con, plugin_data *p) { size_t i, j; plugin_config *s = p->config_storage[0]; PATCH(server_root); PATCH(default_host); PATCH(document_root); PATCH(docroot_cache_key); PATCH(docroot_cache_value); PATCH(docroot_cache_servername); PATCH(debug); /* skip the first, the global context */ for (i = 1; i < srv->config_context->used; i++) { data_config *dc = (data_config *)srv->config_context->data[i]; s = p->config_storage[i]; /* condition didn't match */ if (!config_check_cond(srv, con, dc)) continue; /* merge config */ for (j = 0; j < dc->value->used; j++) { data_unset *du = dc->value->data[j]; if (buffer_is_equal_string(du->key, CONST_STR_LEN("simple-vhost.server-root"))) { PATCH(server_root); PATCH(docroot_cache_key); PATCH(docroot_cache_value); PATCH(docroot_cache_servername); } else if (buffer_is_equal_string(du->key, CONST_STR_LEN("simple-vhost.default-host"))) { PATCH(default_host); } else if (buffer_is_equal_string(du->key, CONST_STR_LEN("simple-vhost.document-root"))) { PATCH(document_root); } else if (buffer_is_equal_string(du->key, CONST_STR_LEN("simple-vhost.debug"))) { PATCH(debug); } } } return 0; }
static int mod_sql_vhost_core_patch_connection(server *srv, connection *con, plugin_data *p) { size_t i, j; plugin_config *s = p->config_storage[0]; PATCH_OPTION(backend_data); PATCH_OPTION(get_vhost); #ifdef HAVE_GLIB_H PATCH_OPTION(vhost_table); #endif PATCH_OPTION(cache_ttl); PATCH_OPTION(debug); /* skip the first, the global context */ for (i = 1; i < srv->config_context->used; i++) { data_config *dc = (data_config *)srv->config_context->data[i]; s = p->config_storage[i]; /* condition didn't match */ if (!config_check_cond(srv, con, dc)) continue; if (s->backend_data) { PATCH_OPTION(backend_data); PATCH_OPTION(get_vhost); #ifdef HAVE_GLIB_H PATCH_OPTION(vhost_table); #endif } for (j = 0; j < dc->value->used; j++) { data_unset *du = dc->value->data[j]; if (buffer_is_equal_string(du->key, CONST_STR_LEN(CONFIG_CACHE_TTL))) { PATCH_OPTION(cache_ttl); } else if (buffer_is_equal_string(du->key, CONST_STR_LEN(CONFIG_DEBUG))) { PATCH_OPTION(debug); } } } return 0; }
static int check_aicloud_auth_url(server *srv, connection *con, plugin_data *p){ smb_info_t *c; int i, j, k; plugin_config *s; /* skip the first, the global context */ for (i = 1; i < srv->config_context->used; i++) { data_config *dc = (data_config *)srv->config_context->data[i]; s = p->config_storage[i]; /* condition didn't match */ if (!config_check_cond(srv, con, dc)) continue; /* merge config */ for (j = 0; j < dc->value->used; j++) { data_unset *du = dc->value->data[j]; if (buffer_is_equal_string(du->key, CONST_STR_LEN("url.aicloud-auth-deny"))) { PATCH(auth_deny); } } } if(p->conf.auth_deny){ for (k = 0; k < p->conf.auth_deny->used; k++) { data_string *ds = (data_string *)p->conf.auth_deny->data[k]; if (ds->value->used == 0) continue; if (strstr(con->uri.path->ptr, ds->value->ptr)) { if(p->smb_info_list==NULL) return 0; for (c = p->smb_info_list; c; c = c->next) { if( buffer_is_empty(c->server) && buffer_is_empty(c->share) && buffer_is_equal(c->src_ip, con->dst_addr_buf) ){ if(buffer_is_empty(c->username)) return 0; else return 1; } } return 0; } } } return 1; }
static int mod_rewrite_patch_connection(server *srv, connection *con, plugin_data *p) { size_t i, j; plugin_config *s = p->config_storage[0]; p->conf.rewrite = s->rewrite; p->conf.context = NULL; /* skip the first, the global context */ for (i = 1; i < srv->config_context->used; i++) { data_config *dc = (data_config *)srv->config_context->data[i]; s = p->config_storage[i]; if (COMP_HTTP_URL == dc->comp) continue; /* condition didn't match */ if (!config_check_cond(srv, con, dc)) continue; /* merge config */ for (j = 0; j < dc->value->used; j++) { data_unset *du = dc->value->data[j]; if (buffer_is_equal_string(du->key, CONST_STR_LEN("url.rewrite"))) { p->conf.rewrite = s->rewrite; p->conf.context = dc; } else if (buffer_is_equal_string(du->key, CONST_STR_LEN("url.rewrite-once"))) { p->conf.rewrite = s->rewrite; p->conf.context = dc; } else if (buffer_is_equal_string(du->key, CONST_STR_LEN("url.rewrite-repeat"))) { p->conf.rewrite = s->rewrite; p->conf.context = dc; } else if (buffer_is_equal_string(du->key, CONST_STR_LEN("url.rewrite-final"))) { p->conf.rewrite = s->rewrite; p->conf.context = dc; } } } return 0; }
static handler_t mod_status_handle_server_status(server *srv, connection *con, void *p_d) { if (buffer_is_equal_string(con->uri.query, CONST_STR_LEN("auto"))) { mod_status_handle_server_status_text(srv, con, p_d); } else { mod_status_handle_server_status_html(srv, con, p_d); } con->http_status = 200; con->file_finished = 1; return HANDLER_FINISHED; }
static int mod_cml_patch_connection(server *srv, connection *con, plugin_data *p) { size_t i, j; plugin_config *s = p->config_storage[0]; PATCH(ext); #if defined(HAVE_MEMCACHE_H) PATCH(mc); #endif PATCH(mc_namespace); PATCH(power_magnet); /* skip the first, the global context */ for (i = 1; i < srv->config_context->used; i++) { data_config *dc = (data_config *)srv->config_context->data[i]; s = p->config_storage[i]; /* condition didn't match */ if (!config_check_cond(srv, con, dc)) continue; /* merge config */ for (j = 0; j < dc->value->used; j++) { data_unset *du = dc->value->data[j]; if (buffer_is_equal_string(du->key, CONST_STR_LEN("cml.extension"))) { PATCH(ext); } else if (buffer_is_equal_string(du->key, CONST_STR_LEN("cml.memcache-hosts"))) { #if defined(HAVE_MEMCACHE_H) PATCH(mc); #endif } else if (buffer_is_equal_string(du->key, CONST_STR_LEN("cml.memcache-namespace"))) { PATCH(mc_namespace); } else if (buffer_is_equal_string(du->key, CONST_STR_LEN("cml.power-magnet"))) { PATCH(power_magnet); } } } return 0; }
static int mod_userdir_patch_connection(server *srv, connection *con, plugin_data *p) { size_t i, j; plugin_config *s = p->config_storage[0]; PATCH_OPTION(path); PATCH_OPTION(exclude_user); PATCH_OPTION(include_user); PATCH_OPTION(basepath); PATCH_OPTION(letterhomes); /* skip the first, the global context */ for (i = 1; i < srv->config_context->used; i++) { data_config *dc = (data_config *)srv->config_context->data[i]; s = p->config_storage[i]; /* condition didn't match */ if (!config_check_cond(srv, con, dc)) continue; /* merge config */ for (j = 0; j < dc->value->used; j++) { data_unset *du = dc->value->data[j]; if (buffer_is_equal_string(du->key, CONST_STR_LEN("userdir.path"))) { PATCH_OPTION(path); } else if (buffer_is_equal_string(du->key, CONST_STR_LEN("userdir.exclude-user"))) { PATCH_OPTION(exclude_user); } else if (buffer_is_equal_string(du->key, CONST_STR_LEN("userdir.include-user"))) { PATCH_OPTION(include_user); } else if (buffer_is_equal_string(du->key, CONST_STR_LEN("userdir.basepath"))) { PATCH_OPTION(basepath); } else if (buffer_is_equal_string(du->key, CONST_STR_LEN("userdir.letterhomes"))) { PATCH_OPTION(letterhomes); } } } return 0; }
static connection *connection_map_get_connection(connection_map *cm, const char *con_id, size_t idlen) { size_t i; for (i = 0; i < cm->used; i++) { connection_map_entry *cme = cm->ptr[i]; if (buffer_is_equal_string(cme->con_id, con_id, idlen)) { /* found connection */ return cme->con; } } return NULL; }
static int mod_deflate_patch_connection(server *srv, connection *con, plugin_data *p) { size_t i, j; plugin_config *s = p->config_storage[0]; PATCH(mimetypes); PATCH(allowed_encodings); PATCH(max_compress_size); PATCH(min_compress_size); PATCH(compression_level); PATCH(output_buffer_size); PATCH(work_block_size); PATCH(max_loadavg); /* skip the first, the global context */ for (i = 1; i < srv->config_context->used; i++) { data_config *dc = (data_config *)srv->config_context->data[i]; s = p->config_storage[i]; /* condition didn't match */ if (!config_check_cond(srv, con, dc)) continue; /* merge config */ for (j = 0; j < dc->value->used; j++) { data_unset *du = dc->value->data[j]; if (buffer_is_equal_string(du->key, CONST_STR_LEN("deflate.mimetypes"))) { PATCH(mimetypes); } else if (buffer_is_equal_string(du->key, CONST_STR_LEN("deflate.allowed-encodings"))) { PATCH(allowed_encodings); } else if (buffer_is_equal_string(du->key, CONST_STR_LEN("deflate.max-compress-size"))) { PATCH(max_compress_size); } else if (buffer_is_equal_string(du->key, CONST_STR_LEN("deflate.min-compress-size"))) { PATCH(min_compress_size); } else if (buffer_is_equal_string(du->key, CONST_STR_LEN("deflate.compression-level"))) { PATCH(compression_level); } else if (buffer_is_equal_string(du->key, CONST_STR_LEN("deflate.output-buffer-size"))) { PATCH(output_buffer_size); } else if (buffer_is_equal_string(du->key, CONST_STR_LEN("deflate.work-block-size"))) { PATCH(work_block_size); } else if (buffer_is_equal_string(du->key, CONST_STR_LEN("deflate.max-loadavg"))) { PATCH(max_loadavg); } } } return 0; }
static int mod_aidisk_access_patch_connection(server *srv, connection *con, plugin_data *p) { size_t i, j; plugin_config *s = p->config_storage[0]; PATCH(alias_url); #if EMBEDDED_EANBLE char *usbdiskname = nvram_get_productid(); #else char *usbdiskname = "usbdisk"; #endif /* skip the first, the global context */ for (i = 1; i < srv->config_context->used; i++) { data_config *dc = (data_config *)srv->config_context->data[i]; s = p->config_storage[i]; if( dc->comp != COMP_HTTP_URL ) continue; if(strstr(dc->string->ptr, usbdiskname)==NULL) continue; for (j = 0; j < dc->value->used; j++) { data_unset *du = dc->value->data[j]; if (buffer_is_equal_string(du->key, CONST_STR_LEN("alias.url"))) { PATCH(alias_url); } } } #if EMBEDDED_EANBLE #ifdef APP_IPKG free(usbdiskname); #endif #endif return 0; }