END_TEST void core_setup(void) { const unsigned int kIdx = 0; const unsigned int kEls = kIdx + 1; cas_cfg *cfg = NULL; cas_dir_cfg *d_cfg = NULL; apr_uri_t login; request = (request_rec *) malloc(sizeof(request_rec)); apr_pool_create(&pool, NULL); request->pool = pool; /* set up the request */ request->headers_in = apr_table_make(request->pool, 0); request->headers_out = apr_table_make(request->pool, 0); request->err_headers_out = apr_table_make(request->pool, 0); apr_table_set(request->headers_in, "Host", "foo.example.com"); apr_table_set(request->headers_in, "CAS_foo", "foo-value"); apr_table_set(request->headers_in, "Cookie", "foo=bar; " CAS_DEFAULT_COOKIE "=0123456789abcdef; baz=zot"); request->server = apr_pcalloc(request->pool, sizeof(struct server_rec)); request->connection = apr_pcalloc(request->pool, sizeof(struct conn_rec)); request->connection->local_addr = apr_pcalloc(request->pool, sizeof(apr_sockaddr_t)); apr_pool_userdata_set("https", "scheme", NULL, request->pool); request->server->server_hostname = "foo.example.com"; request->connection->local_addr->port = 80; request->unparsed_uri = "/foo?bar=baz&zot=qux"; request->uri = "/foo"; request->args = "bar=baz&zot=qux"; apr_uri_parse(request->pool, "http://foo.example.com/foo?bar=baz&zot=qux", &request->parsed_uri); /* set up the per server, and per directory configs */ auth_cas_module.module_index = kIdx; cfg = cas_create_server_config(request->pool, request->server); cfg->CASDebug = TRUE; memset(&login, 0, sizeof(login)); login.scheme = "https"; login.hostname = "login.example.com"; login.path = "/cas/login"; login.port = 0; memcpy(&cfg->CASLoginURL, &login, sizeof(apr_uri_t)); d_cfg = cas_create_dir_config(request->pool, NULL); request->request_config = apr_pcalloc(request->pool, sizeof(ap_conf_vector_t *)*kEls); request->server->module_config = apr_pcalloc(request->pool, sizeof(ap_conf_vector_t *)*kEls); request->per_dir_config = apr_pcalloc(request->pool, sizeof(ap_conf_vector_t *)*kEls); ap_set_module_config(request->server->module_config, &auth_cas_module, cfg); ap_set_module_config(request->per_dir_config, &auth_cas_module, d_cfg); }
static ib_status_t ib_error_callback(ib_tx_t *tx, int status, void *cbdata) { #if 0 /* We're being called from a connection filter here. * So on input we have to anticipate the Request * while on output we're too late to do anything very interesting. */ ap_filter_t *f = vf; mod_ib_conn_ctx *ctx = ap_get_module_config(f->c->conn_config, &ironbee_module); if (ctx == NULL) { ctx = apr_pcalloc(f->c->pool, sizeof(mod_ib_conn_ctx)); ap_set_module_config(f->c->conn_config, &ironbee_module, ctx); } if (ap_is_HTTP_VALID_RESPONSE(status)) { /* Ironbee wants us to return an HTTP error */ ctx->status = status; } else if (status == DONE) { /* Ironbee wants us to return an HTTP error */ ctx->status = status; } else { ap_log_cerror(APLOG_MARK, APLOG_DEBUG, 0, f->c, IB_PRODUCT_NAME ": requested unsupported action %d", status); return IB_ENOTIMPL; } #endif return IB_ENOTIMPL; }
static void filter_insert(request_rec *r) { mod_filter_chain *p; ap_filter_rec_t *filter; mod_filter_cfg *cfg = ap_get_module_config(r->per_dir_config, &filter_module); #ifndef NO_PROTOCOL int ranges = 1; mod_filter_ctx *ctx = apr_pcalloc(r->pool, sizeof(mod_filter_ctx)); ap_set_module_config(r->request_config, &filter_module, ctx); #endif for (p = cfg->chain; p; p = p->next) { filter = apr_hash_get(cfg->live_filters, p->fname, APR_HASH_KEY_STRING); if (filter == NULL) { ap_log_rerror(APLOG_MARK, APLOG_WARNING, 0, r, "Unknown filter %s not added", p->fname); continue; } ap_add_output_filter_handle(filter, NULL, r, r->connection); #ifndef NO_PROTOCOL if (ranges && (filter->proto_flags & (AP_FILTER_PROTO_NO_BYTERANGE | AP_FILTER_PROTO_CHANGE_LENGTH))) { ctx->range = apr_table_get(r->headers_in, "Range"); apr_table_unset(r->headers_in, "Range"); ranges = 0; } #endif } return; }
static apr_status_t upload_filter_init(ap_filter_t* f) { upload_conf* conf = ap_get_module_config(f->r->per_dir_config,&upload_module); upload_ctx* ctx = apr_palloc(f->r->pool, sizeof(upload_ctx)) ; // check content-type, get boundary or error const char* ctype = apr_table_get(f->r->headers_in, "Content-Type") ; if ( ! ctype || ! conf->file_field || strncmp ( ctype , "multipart/form-data", 19 ) ) { ap_remove_input_filter(f) ; return APR_SUCCESS ; } ctx->pool = f->r->pool ; ctx->form = apr_table_make(ctx->pool, conf->form_size) ; ctx->boundary = get_boundary(f->r->pool, ctype) ; ctx->parse_state = p_none ; ctx->key = ctx->val = 0 ; ctx->file_field = conf->file_field ; ctx->is_file = 0 ; ctx->leftover = 0 ; // ctx->bbin = apr_brigade_create(f->r->pool, f->r->connection->bucket_alloc) ; /* save the table in request_config */ ap_set_module_config(f->r->request_config, &upload_module, ctx->form) ; f->ctx = ctx ; return APR_SUCCESS ; }
static mbox_req_cfg_t *get_req_conf(request_rec *r) { mbox_req_cfg_t *conf = ap_get_module_config(r->request_config, &mbox_module); const char *temp; if (conf) return conf; conf = apr_pcalloc(r->pool, sizeof(*conf)); temp = ap_strstr_c(r->uri, r->path_info); if (temp) conf->base_uri = apr_pstrmemdup(r->pool, r->uri, temp - r->uri); else conf->base_uri = r->uri; temp = ap_strstr_c(conf->base_uri, ".mbox"); /* 7 is length of "/yyyymm" */ if (temp && temp >= conf->base_uri + 7) { conf->base_path = apr_pstrmemdup(r->pool, conf->base_uri, temp - 7 - conf->base_uri); conf->base_name = ap_strrchr_c(conf->base_path, '/') + 1; } ap_set_module_config(r->request_config, &mbox_module, conf); return conf; }
static h2_ctx *h2_ctx_create(conn_rec *c) { h2_ctx *ctx = apr_pcalloc(c->pool, sizeof(h2_ctx)); assert(ctx); ap_set_module_config(c->conn_config, &h2_module, ctx); return ctx; }
/* If it's one of ours, fill in r->finfo now to avoid extra stat()... this is a * bit of a kludge, because we really want to run after core_translate runs. */ static int file_cache_xlat(request_rec *r) { a_server_config *sconf; a_file *match; int res; sconf = ap_get_module_config(r->server->module_config, &file_cache_module); /* we only operate when at least one cachefile directive was used */ if (!apr_hash_count(sconf->fileht)) { return DECLINED; } res = ap_core_translate(r); if (res != OK || !r->filename) { return res; } /* search the cache */ match = (a_file *) apr_hash_get(sconf->fileht, r->filename, APR_HASH_KEY_STRING); if (match == NULL) return DECLINED; /* pass search results to handler */ ap_set_module_config(r->request_config, &file_cache_module, match); /* shortcircuit the get_path_info() stat() calls and stuff */ r->finfo = match->finfo; return OK; }
/** * Attach our filter to every incoming connection. */ static int mod_sslhaf_pre_conn(conn_rec *c, void *csd) { sslhaf_cfg_t *cfg = NULL; // TODO Can we determine if SSL is enabled on this connection // and don't bother if it isn't? It is actually possible that // someone speaks SSL on a non-SSL connection, but we won't // be able to detect that. It wouldn't matter, though, because // Apache will not process such a request. cfg = sslhaf_cfg_create( c, &mod_sslhaf_alloc, &mod_sslhaf_free, &mod_sslhaf_snprintf, &mod_sslhaf_log); if (cfg == NULL) return OK; sslhaf_cfg_set_create_strings(cfg, true); ap_set_module_config(c->conn_config, &sslhaf_module, cfg); ap_add_input_filter(mod_sslhaf_in_filter_name, NULL, NULL, c); ap_add_output_filter(mod_sslhaf_out_filter_name, NULL, NULL, c); #ifdef ENABLE_DEBUG ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, c->base_server, "mod_sslhaf: Connection from %s", SSLHAF_AP_CONN_REMOTE_IP(c)); #endif return OK; }
static h2_ctx *h2_ctx_create(const conn_rec *c) { h2_ctx *ctx = apr_pcalloc(c->pool, sizeof(h2_ctx)); AP_DEBUG_ASSERT(ctx); ap_set_module_config(c->conn_config, &http2_module, ctx); return ctx; }
static int firstbyte_pre_conn(conn_rec *c, void *csd) { firstbyte_config_t *cf = apr_pcalloc(c->pool, sizeof(*cf)); ap_set_module_config(c->conn_config, &log_firstbyte_module, cf); ap_add_output_filter(firstbyte_filter_name, NULL, NULL, c); return OK; }
static int logio_pre_conn(conn_rec *c, void *csd) { logio_config_t *cf = apr_pcalloc(c->pool, sizeof(*cf)); ap_set_module_config(c->conn_config, &logio_module, cf); ap_add_input_filter(logio_filter_name, NULL, NULL, c); return OK; }
static int mag_pre_connection(conn_rec *c, void *csd) { struct mag_conn *mc; mc = mag_new_conn_ctx(c->pool); mc->is_preserved = true; ap_set_module_config(c->conn_config, &auth_gssapi_module, (void*)mc); return OK; }
static ap_dbd_t *log_sql_dbd_getconnection(request_rec *r) { request_config_t *rconf = ap_get_module_config(r->request_config, &LOGSQL_MODULE(dbd)); if (!rconf) { rconf = apr_pcalloc(r->pool, sizeof(request_config_t)); ap_set_module_config(r->request_config, &LOGSQL_MODULE(dbd), (void *)rconf); rconf->dbd = dbd_acquire_fn(r); } return rconf->dbd; }
static int pre_connection(conn_rec *c, void *csd) { req_start_config_t *cf = apr_pcalloc(c->pool, sizeof(*cf)); cf->time = apr_time_now(); cf->count = 0; ap_set_module_config(c->conn_config, &conn_start_module, cf); // ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, NULL, "Pre Connection: %hu", cf->count); return OK; }
static int mag_pre_connection(conn_rec *c, void *csd) { struct mag_conn *mc; mc = apr_pcalloc(c->pool, sizeof(struct mag_conn)); if (!mc) return DECLINED; mc->parent = c->pool; ap_set_module_config(c->conn_config, &auth_gssapi_module, (void*)mc); return OK; }
static qEnvApache *get_psx_req_env(request_rec *r, bool create = true) { if (!gEnv) { smx_log_str(SMXLOGLEVEL_DEBUG,"server environment created during get_psx_req_env"); ap_set_module_config(r->server->module_config, &smx_module, create_psx_config(r->pool, r->server)); } if (!gEnv) return NULL; qEnvApache *renv = (qEnvApache *) ap_get_module_config(r->request_config, &smx_module); if (!renv) { if (create) { renv = new qEnvApache(r); ap_set_module_config(r->request_config, &smx_module, renv); } } else if (create) renv->AddRef(); return renv; }
static apr_status_t logio_ttfb_filter(ap_filter_t *f, apr_bucket_brigade *b) { request_rec *r = f->r; logio_dirconf_t *conf = ap_get_module_config(r->per_dir_config, &logio_module); if (conf && conf->track_ttfb) { logio_req_t *rconf = ap_get_module_config(r->request_config, &logio_module); if (rconf == NULL) { rconf = apr_pcalloc(r->pool, sizeof(logio_req_t)); rconf->ttfb = apr_time_now() - r->request_time; ap_set_module_config(r->request_config, &logio_module, rconf); } } ap_remove_output_filter(f); return ap_pass_brigade(f->next, b); }
qEnvApache::~qEnvApache() { #ifdef _DBUGMEM InterlockedDecrement(&gApCnt); #endif if (myCtxFree) { #ifdef _DBUGMEM InterlockedDecrement(&gCxCnt); #endif myCtx->Free(); } if (PrevEnv()) PrevEnv()->Free(); ap_set_module_config(myReq->request_config, &smx_module, NULL); }
static void fix_event_conn(conn_rec *c, conn_rec *master) { event_conn_state_t *master_cs = ap_get_module_config(master->conn_config, h2_conn_mpm_module()); event_conn_state_t *cs = apr_pcalloc(c->pool, sizeof(event_conn_state_t)); cs->bucket_alloc = apr_bucket_alloc_create(c->pool); ap_set_module_config(c->conn_config, h2_conn_mpm_module(), cs); cs->c = c; cs->r = NULL; cs->p = master_cs->p; cs->pfd = master_cs->pfd; cs->pub = master_cs->pub; cs->pub.state = CONN_STATE_READ_REQUEST_LINE; c->cs = &(cs->pub); }
static ap_inline qEnvApacheServer *get_psx_srv_env(request_rec *r) { if (!gEnv) { smx_log_str(SMXLOGLEVEL_DEBUG,"server environment created during get_psx_srv_env"); ap_set_module_config(r->server->module_config, &smx_module, create_psx_config(r->pool, r->server)); } if (!gEnv) return NULL; qEnvApacheServer *ps = ((qEnvApacheServer *) ap_get_module_config(r->server->module_config, &smx_module)); if (!ps->IsReady()) ps->Initialize(r); return ps; }
static void filter_insert(request_rec *r) { mod_filter_chain *p; ap_filter_rec_t *filter; mod_filter_cfg *cfg = ap_get_module_config(r->per_dir_config, &filter_module); #ifndef NO_PROTOCOL int ranges = 1; mod_filter_ctx *ctx = apr_pcalloc(r->pool, sizeof(mod_filter_ctx)); ap_set_module_config(r->request_config, &filter_module, ctx); #endif /** IG: Now that we've merged to the final config, go one last time * through the chain, and prune out the NULL filters */ for (p = cfg->chain; p; p = p->next) { if (p->fname == NULL) cfg->chain = p->next; } for (p = cfg->chain; p; p = p->next) { filter = apr_hash_get(cfg->live_filters, p->fname, APR_HASH_KEY_STRING); if (filter == NULL) { ap_log_rerror(APLOG_MARK, APLOG_WARNING, 0, r, APLOGNO(01380) "Unknown filter %s not added", p->fname); continue; } ap_add_output_filter_handle(filter, NULL, r, r->connection); #ifndef NO_PROTOCOL if (ranges && (filter->proto_flags & (AP_FILTER_PROTO_NO_BYTERANGE | AP_FILTER_PROTO_CHANGE_LENGTH))) { ctx->range = apr_table_get(r->headers_in, "Range"); apr_table_unset(r->headers_in, "Range"); ranges = 0; } #endif } }
// Replace the incoming token from the cookies to the data set from driver // database. If the token is not set or doesn't exist, it will generate a new // one and set it in request variables for the output filter. // // TODO: It should be useful to put the token into a special header or cookie. void psm_map_cookies(request_rec *r, psm_driver *driver) { const char *header; char *token; psm_request_vars *vars; unsigned int found = 0; // Fetch configuration of the server vars = (psm_request_vars *) apr_palloc(r->pool, sizeof(psm_request_vars)); // Look at `Cookie` header to get private state cookie header = apr_table_get(r->headers_in, HEADER_COOKIE); if (header != NULL) { int i; apr_array_header_t *cookies; // Parse incoming cookies cookies = parse_cookie(r->pool, header); // Test if the private state cookie is set and contains a token for (i = 0; i < cookies->nelts && ! found; i++) { psm_cookie *cookie = ((psm_cookie **)cookies->elts)[i]; if (! strcasecmp(cookie->name, PSM_TOKEN_NAME) && strlen(cookie->value)) { ap_log_rerror(APLOG_MARK, APLOG_NOTICE, 0, r, "Private token detected: %s", cookie->value); vars->token = apr_pstrdup(r->pool, cookie->value); found = 1; } } } // Try to retrieve cookies from the driver if we found the private state cookie token if (found) { apr_array_header_t *cookies; // Initialize Apache array with the good size cookies = apr_array_make(r->pool, PSM_ARRAY_INIT_SZ, sizeof(psm_cookie *)); // Fetch "data" cookies from the driver (aka db) and write them if (driver->fetch_cookies(r->pool, *driver->data, cookies, vars->token) == OK) { psm_write_cookie(r->headers_in, cookies); } // If we didn't find it, trigger the token generation else { found = 0; } } // Re-check in case of fetch_cookies function failed if (! found) { // Generate a random token vars->token = generate_token(r->pool, PSM_TOKEN_LENGTH); // Unset incoming cookies apr_table_unset(r->headers_in, HEADER_COOKIE); ap_log_rerror(APLOG_MARK, APLOG_NOTICE, 0, r, "Not any private token found. New token set: %s", vars->token); } // Set variables of this request for the output filter // TODO is it mandatory to set when `vars` is a pointer ? ap_set_module_config(r->request_config, &psm_module, vars); }
// ----------------------------------------------------------------------------- int trell_job_rpc_handle( trell_sconf_t* sconf, request_rec*r, xmlSchemaPtr schema, const char* job, trell_dispatch_info_t* dispatch_info ) { // set up request config req_cfg_t* req_cfg = apr_palloc( r->pool, sizeof(*req_cfg) ); req_cfg->m_schema = schema; ap_set_module_config( r->request_config, tinia_get_module(), req_cfg ); // add validation filter ap_add_input_filter( "tinia_validate_xml", NULL, r, r->connection ); if( r->method_number != M_POST ) { // should be checked earlier ap_log_rerror( APLOG_MARK, APLOG_ERR, 0, r, "mod_trell: method != POST" ); return HTTP_METHOD_NOT_ALLOWED; } // check if content type is correct const char* content_type = apr_table_get( r->headers_in, "Content-Type" ); if( content_type == NULL ) { ap_log_rerror( APLOG_MARK, APLOG_ERR, 0, r, "mod_trell: No content type" ); return HTTP_BAD_REQUEST; } // In case we get Content-Type: text/xml; encoding=foo. char* semicolon = strchr( content_type, ';' ); if( semicolon != NULL ) { // Chop line at semicolon. *semicolon = '\0'; } if( ! ( ( strcasecmp( "application/xml", content_type) == 0 ) || ( strcasecmp( "text/xml", content_type ) == 0 ) ) ) { ap_log_rerror( APLOG_MARK, APLOG_ERR, 0, r, "mod_trell: Unsupported content-type '%s'", content_type ); return HTTP_BAD_REQUEST; } tinia_msg_xml_t query; query.msg.type = TRELL_MESSAGE_XML; trell_pass_query_msg_post_data_t pass_query_data; pass_query_data.sconf = sconf; pass_query_data.r = r; pass_query_data.dispatch_info = dispatch_info; pass_query_data.message = &query; pass_query_data.message_offset = 0; pass_query_data.message_size = sizeof(query); pass_query_data.pass_post = 1; tinia_pass_reply_data_t pass_reply_data; pass_reply_data.sconf = sconf; pass_reply_data.r = r; pass_reply_data.dispatch_info = dispatch_info; pass_reply_data.longpolling = 0; pass_reply_data.brigade = NULL; int rv = tinia_ipc_msg_client_sendrecv_by_name( job, trell_messenger_log_wrapper, r, trell_pass_query_msg_post, &pass_query_data, trell_pass_reply, &pass_reply_data, 0 ); if( rv == 0 ) { return OK; } else if( rv == -1 ) { return HTTP_REQUEST_TIME_OUT; } else { ap_log_rerror( APLOG_MARK, APLOG_NOTICE, 0, r, "%s: failed.", r->path_info ); return HTTP_INTERNAL_SERVER_ERROR; } }
/* * this routine gives our module another chance to examine the request * headers and to take special action. This is the first phase whose * hooks' configuration directives can appear inside the <Directory> * and similar sections, because at this stage the URI has been mapped * to the filename. For example this phase can be used to block evil * clients, while little resources were wasted on these. * * This is a RUN_ALL hook. */ static int header_parser(request_rec *r) { // Get the module configuration dir_config_t *dcfg = (dir_config_t *) ap_get_module_config(r->per_dir_config, &defender_module); // Stop if Defender not enabled if (!dcfg->defender) return DECLINED; RuntimeScanner *scanner = new RuntimeScanner(*dcfg->parser); // Register a C function to delete scanner at the end of the request cycle apr_pool_cleanup_register(r->pool, (void *) scanner, defender_delete_runtimescanner_object, apr_pool_cleanup_null); // Reserve a temporary memory block from the request pool to store data between hooks defender_config_t *pDefenderConfig = (defender_config_t *) apr_palloc(r->pool, sizeof(defender_config_t)); // Remember our application pointer for future calls pDefenderConfig->vpRuntimeScanner = scanner; // Register our config data structure for our module for retrieval later as required ap_set_module_config(r->request_config, &defender_module, (void *) pDefenderConfig); // Set method if (r->method_number == M_GET) scanner->method = METHOD_GET; else if (r->method_number == M_POST) scanner->method = METHOD_POST; else if (r->method_number == M_PUT) scanner->method = METHOD_PUT; // Set logger info scanner->pid = getpid(); apr_os_thread_t tid = apr_os_thread_current(); unsigned int pid_buffer_len = 16; char pid_buffer[pid_buffer_len]; apr_snprintf(pid_buffer, pid_buffer_len, "%pT", &tid); scanner->threadId = std::string(pid_buffer); scanner->connectionId = r->connection->id; scanner->clientIp = r->useragent_ip; scanner->requestedHost = r->hostname; scanner->serverHostname = r->server->server_hostname; scanner->fullUri = r->unparsed_uri; scanner->protocol = r->protocol; ap_version_t vers; ap_get_server_revision(&vers); scanner->softwareVersion = std::to_string(vers.major) + "." + std::to_string(vers.minor) + "." + std::to_string(vers.patch); scanner->logLevel = static_cast<LOG_LVL>(r->log->level); if (scanner->logLevel >= APLOG_DEBUG) scanner->logLevel = LOG_LVL_DEBUG; scanner->writeLogFn = write_log; scanner->errorLogFile = r->server->error_log; scanner->learningLogFile = dcfg->matchlog_file; scanner->learningJSONLogFile = dcfg->jsonmatchlog_file; scanner->learning = dcfg->learning; scanner->extensiveLearning = dcfg->extensive; // Set runtime modifiers scanner->libinjSQL = dcfg->libinjection_sql; scanner->libinjXSS = dcfg->libinjection_xss; scanner->bodyLimit = dcfg->requestBodyLimit; // Set the uri path scanner->setUri(r->parsed_uri.path); // Pass every HTTP header received const apr_array_header_t *headerFields = apr_table_elts(r->headers_in); apr_table_entry_t *headerEntry = (apr_table_entry_t *) headerFields->elts; for (int i = 0; i < headerFields->nelts; i++) scanner->addHeader(headerEntry[i].key, headerEntry[i].val); // Pass GET parameters apr_table_t *getTable = NULL; ap_args_to_table(r, &getTable); const apr_array_header_t *getParams = apr_table_elts(getTable); apr_table_entry_t *getParam = (apr_table_entry_t *) getParams->elts; for (int i = 0; i < getParams->nelts; i++) scanner->addGETParameter(getParam[i].key, getParam[i].val); // Run scanner int ret = scanner->processHeaders(); if (dcfg->useenv) ret = pass_in_env(r, scanner); return ret; }
conn_rec *h2_slave_create(conn_rec *master, int slave_id, apr_pool_t *parent) { apr_allocator_t *allocator; apr_status_t status; apr_pool_t *pool; conn_rec *c; void *cfg; module *mpm; ap_assert(master); ap_log_cerror(APLOG_MARK, APLOG_TRACE3, 0, master, "h2_stream(%ld-%d): create slave", master->id, slave_id); /* We create a pool with its own allocator to be used for * processing a request. This is the only way to have the processing * independant of its parent pool in the sense that it can work in * another thread. Also, the new allocator needs its own mutex to * synchronize sub-pools. */ apr_allocator_create(&allocator); apr_allocator_max_free_set(allocator, ap_max_mem_free); status = apr_pool_create_ex(&pool, parent, NULL, allocator); if (status != APR_SUCCESS) { ap_log_cerror(APLOG_MARK, APLOG_ERR, status, master, APLOGNO(10004) "h2_session(%ld-%d): create slave pool", master->id, slave_id); return NULL; } apr_allocator_owner_set(allocator, pool); apr_pool_abort_set(abort_on_oom, pool); apr_pool_tag(pool, "h2_slave_conn"); c = (conn_rec *) apr_palloc(pool, sizeof(conn_rec)); if (c == NULL) { ap_log_cerror(APLOG_MARK, APLOG_ERR, APR_ENOMEM, master, APLOGNO(02913) "h2_session(%ld-%d): create slave", master->id, slave_id); apr_pool_destroy(pool); return NULL; } memcpy(c, master, sizeof(conn_rec)); c->master = master; c->pool = pool; c->conn_config = ap_create_conn_config(pool); c->notes = apr_table_make(pool, 5); c->input_filters = NULL; c->output_filters = NULL; c->keepalives = 0; #if AP_MODULE_MAGIC_AT_LEAST(20180903, 1) c->filter_conn_ctx = NULL; #endif c->bucket_alloc = apr_bucket_alloc_create(pool); #if !AP_MODULE_MAGIC_AT_LEAST(20180720, 1) c->data_in_input_filters = 0; c->data_in_output_filters = 0; #endif /* prevent mpm_event from making wrong assumptions about this connection, * like e.g. using its socket for an async read check. */ c->clogging_input_filters = 1; c->log = NULL; c->log_id = apr_psprintf(pool, "%ld-%d", master->id, slave_id); c->aborted = 0; /* We cannot install the master connection socket on the slaves, as * modules mess with timeouts/blocking of the socket, with * unwanted side effects to the master connection processing. * Fortunately, since we never use the slave socket, we can just install * a single, process-wide dummy and everyone is happy. */ ap_set_module_config(c->conn_config, &core_module, dummy_socket); /* TODO: these should be unique to this thread */ c->sbh = master->sbh; /* TODO: not all mpm modules have learned about slave connections yet. * copy their config from master to slave. */ if ((mpm = h2_conn_mpm_module()) != NULL) { cfg = ap_get_module_config(master->conn_config, mpm); ap_set_module_config(c->conn_config, mpm, cfg); } ap_log_cerror(APLOG_MARK, APLOG_TRACE3, 0, c, "h2_slave(%s): created", c->log_id); return c; }
Config(conn_rec *c) { ap_set_module_config(c->conn_config, &serenity_module, this); }
static request_rec * test_setup(apr_pool_t *pool) { const unsigned int kIdx = 0; const unsigned int kEls = kIdx + 1; request_rec *request = (request_rec *) apr_pcalloc(pool, sizeof(request_rec)); request->pool = pool; request->headers_in = apr_table_make(request->pool, 0); request->headers_out = apr_table_make(request->pool, 0); request->err_headers_out = apr_table_make(request->pool, 0); apr_table_set(request->headers_in, "Host", "www.example.com"); apr_table_set(request->headers_in, "OIDC_foo", "some-value"); apr_table_set(request->headers_in, "Cookie", "foo=bar; " "mod_auth_openidc_session" "=0123456789abcdef; baz=zot"); request->server = apr_pcalloc(request->pool, sizeof(struct server_rec)); request->server->process = apr_pcalloc(request->pool, sizeof(struct process_rec)); request->server->process->pool = request->pool; request->connection = apr_pcalloc(request->pool, sizeof(struct conn_rec)); request->connection->local_addr = apr_pcalloc(request->pool, sizeof(apr_sockaddr_t)); apr_pool_userdata_set("https", "scheme", NULL, request->pool); request->server->server_hostname = "www.example.com"; request->connection->local_addr->port = 80; request->unparsed_uri = "/bla?foo=bar¶m1=value1"; request->args = "foo=bar¶m1=value1"; apr_uri_parse(request->pool, "http://www.example.com/bla?foo=bar¶m1=value1", &request->parsed_uri); auth_openidc_module.module_index = kIdx; oidc_cfg *cfg = oidc_create_server_config(request->pool, request->server); cfg->provider.issuer = "https://idp.example.com"; cfg->provider.authorization_endpoint_url = "https://idp.example.com/authorize"; cfg->provider.scope = "openid"; cfg->provider.client_id = "client_id"; cfg->redirect_uri = "https://www.example.com/protected/"; oidc_dir_cfg *d_cfg = oidc_create_dir_config(request->pool, NULL); request->server->module_config = apr_pcalloc(request->pool, sizeof(ap_conf_vector_t *) * kEls); request->per_dir_config = apr_pcalloc(request->pool, sizeof(ap_conf_vector_t *) * kEls); ap_set_module_config(request->server->module_config, &auth_openidc_module, cfg); ap_set_module_config(request->per_dir_config, &auth_openidc_module, d_cfg); cfg->cache = &oidc_cache_shm; cfg->cache_cfg = NULL; cfg->cache_shm_size_max = 500; cfg->cache_shm_entry_size_max = 16384 + 255 + 17; cfg->cache->post_config(request->server); return request; }
/* * This function will configure MPM-ITK */ static int vhx_itk_post_read(request_rec *r) { uid_t libhome_uid; gid_t libhome_gid; int vhost_found_by_request = DECLINED; vhx_config_rec *vhr = (vhx_config_rec *) ap_get_module_config(r->server->module_config, &vhostx_module); VH_AP_LOG_RERROR(APLOG_MARK, APLOG_DEBUG, 0, r, "vhx_itk_post_read: BEGIN ***,pid=%d",getpid()); vhx_request_t *reqc; reqc = ap_get_module_config(r->request_config, &vhostx_module); if (!reqc) { reqc = (vhx_request_t *)apr_pcalloc(r->pool, sizeof(vhx_request_t)); reqc->vhost_found = VH_VHOST_INFOS_NOT_YET_REQUESTED; ap_set_module_config(r->request_config, &vhostx_module, reqc); } vhx_conn_cfg_t *conn_cfg = (vhx_conn_cfg_t*) ap_get_module_config(r->connection->conn_config, &vhostx_module); if (!conn_cfg) { conn_cfg = apr_pcalloc(r->connection->pool, sizeof(vhx_conn_cfg_t)); conn_cfg->last_vhost = NULL; conn_cfg->last_vhost_status = VH_VHOST_INFOS_NOT_YET_REQUESTED; ap_set_module_config(r->connection->conn_config, &vhostx_module, conn_cfg); } if(r->hostname != NULL) { conn_cfg->last_vhost = apr_pstrdup(r->pool, r->hostname); vhost_found_by_request = getldaphome(r, vhr, r->hostname, reqc); if (vhost_found_by_request == OK) { libhome_uid = atoi(reqc->uid); libhome_gid = atoi(reqc->gid); } else { if (vhr->lamer_mode) { if ((strncasecmp(r->hostname, "www.",4) == 0) && (strlen(r->hostname) > 4)) { VH_AP_LOG_RERROR(APLOG_MARK, APLOG_DEBUG, 0, r, "vhx_itk_post_read: Lamer friendly mode engaged"); char *lhost; lhost = apr_pstrdup(r->pool, r->hostname + 4); VH_AP_LOG_RERROR(APLOG_MARK, APLOG_DEBUG, 0, r, "vhx_itk_post_read: Found a lamer for %s -> %s", r->hostname, lhost); vhost_found_by_request = getldaphome(r, vhr, lhost, reqc); if (vhost_found_by_request == OK) { libhome_uid = atoi(reqc->uid); libhome_gid = atoi(reqc->gid); VH_AP_LOG_RERROR(APLOG_MARK, APLOG_DEBUG, 0, r, "vhx_itk_post_read: lamer for %s -> %s has itk uid='%d' itk gid='%d'", r->hostname, lhost, libhome_uid, libhome_gid); } else { libhome_uid = vhr->itk_defuid; libhome_gid = vhr->itk_defgid; VH_AP_LOG_RERROR(APLOG_MARK, APLOG_DEBUG, 0, r, "vhx_itk_post_read: no lamer found for %s set default itk uid='%d' itk gid='%d'", r->hostname, libhome_uid, libhome_gid); } } else { libhome_uid = vhr->itk_defuid; libhome_gid = vhr->itk_defgid; } } else { libhome_uid = vhr->itk_defuid; libhome_gid = vhr->itk_defgid; } } if (vhost_found_by_request == OK) { conn_cfg->last_vhost_status = VH_VHOST_INFOS_FOUND; /* If ITK support is not enabled, then don't process request */ if (vhr->itk_enable) { module *mpm_itk_module = ap_find_linked_module("itk.c"); if (mpm_itk_module == NULL) { VH_AP_LOG_RERROR(APLOG_MARK, APLOG_ERR, 0, r, "%s: (vhx_itk_post_read) itk.c is not loaded",VH_NAME); return HTTP_INTERNAL_SERVER_ERROR; } itk_conf *cfg = (itk_conf *) ap_get_module_config(r->per_dir_config, mpm_itk_module); VH_AP_LOG_RERROR(APLOG_MARK, APLOG_DEBUG, 0, r, "vhx_itk_post_read: itk uid='%d' itk gid='%d' itk username='******' before change", cfg->uid, cfg->gid, cfg->username); char *itk_username = NULL; struct passwd *pw = getpwuid(libhome_uid); if(pw != NULL) { cfg->uid = libhome_uid; cfg->gid = libhome_gid; /* set the username - otherwise MPM-ITK will not work */ itk_username = apr_pstrdup(r->pool, pw->pw_name); cfg->username = itk_username; //chroot if(vhr->chroot_enable != 0 && reqc->chroot_dir != NULL) { if (ap_is_directory(r->pool, reqc->chroot_dir)) { if(chroot(reqc->chroot_dir)<0) { VH_AP_LOG_RERROR(APLOG_MARK, APLOG_WARNING, 0, r, "%s: (vhx_itk_post_read) couldn't chroot to %s", VH_NAME, reqc->chroot_dir); if(chdir("/")<0) { VH_AP_LOG_RERROR(APLOG_MARK, APLOG_WARNING, 0, r, "vhx_itk_post_read: couldn't chdir to / after chroot to '%s'",reqc->chroot_dir); } } else { VH_AP_LOG_RERROR(APLOG_MARK, APLOG_DEBUG, 0, r, "vhx_itk_post_read: chroot to %s",reqc->chroot_dir); } } else { VH_AP_LOG_RERROR(APLOG_MARK, APLOG_WARNING, 0, r, "%s: (vhx_itk_post_read) chroot directory '%s' does not exist. Skipping chroot", VH_NAME, reqc->chroot_dir); } } else { VH_AP_LOG_RERROR(APLOG_MARK, APLOG_WARNING, 0, r, "vhx_itk_post_read: chroot not enabled or chroot_dir empty. Skipping chroot."); } } VH_AP_LOG_RERROR(APLOG_MARK, APLOG_DEBUG, 0, r, "vhx_itk_post_read: itk uid='%d' itk gid='%d' itk username='******' after change", cfg->uid, cfg->gid, cfg->username); } } else { VH_AP_LOG_RERROR(APLOG_MARK, APLOG_DEBUG, 0, r, "vhx_itk_post_read: set VH_VHOST_INFOS_NOT_FOUND"); reqc->vhost_found = VH_VHOST_INFOS_NOT_FOUND; conn_cfg->last_vhost_status = VH_VHOST_INFOS_NOT_FOUND; } } VH_AP_LOG_RERROR(APLOG_MARK, APLOG_DEBUG, 0, r, "vhx_itk_post_read: END ***"); return OK; }
static int mod_vhost_ldap_translate_name(request_rec *r) { mod_vhost_ldap_request_t *reqc = NULL; mod_vhost_ldap_config_t *conf = (mod_vhost_ldap_config_t *)ap_get_module_config(r->server->module_config, &vhost_ldap_ng_module); #if (AP_SERVER_MAJORVERSION_NUMBER == 2) && (AP_SERVER_MINORVERSION_NUMBER <= 2) core_server_config *core = (core_server_config *)ap_get_module_config(r->server->module_config, &core_module); #endif LDAP *ld = NULL; char *realfile = NULL; char *myfilter = NULL; alias_t *alias = NULL, *cursor = NULL; int i = 0, ret = 0; apr_table_t *e; LDAPMessage *ldapmsg = NULL, *vhostentry = NULL; if (conf->enabled != MVL_ENABLED || !conf->url || !r->hostname){ ap_log_rerror(APLOG_MARK, APLOG_INFO|APLOG_NOERRNO, 0, r, "[mod_vhost_ldap_ng.c] Module disabled"); return DECLINED; } //Search in cache reqc = (mod_vhost_ldap_request_t *)get_from_requestscache(r); if(!reqc){ ap_log_rerror(APLOG_MARK, APLOG_INFO|APLOG_NOERRNO, 0, r, "[mod_vhost_ldap_ng.c] Cannot resolve data from cache"); reqc = apr_pcalloc(vhost_ldap_pool, sizeof(mod_vhost_ldap_request_t)); } if (reqc->expires < apr_time_now()){ //Search ldap //TODO: Create a function while((ret = ldapconnect(&ld, conf)) != 0 && i<2){ i++; ap_log_rerror(APLOG_MARK, APLOG_ERR|APLOG_NOERRNO, 0, r, "[mod_vhost_ldap_ng.c] ldapconnect: %s", ldap_err2string(ret)); } if(i == 2){ conf->enabled = MVL_DISABLED; return HTTP_GATEWAY_TIME_OUT; } myfilter = apr_psprintf(r->pool,"(&(%s)(|(apacheServerName=%s)(apacheServerAlias=%s)))", conf->filter, r->hostname, r->hostname); ret = ldap_search_s (ld, conf->basedn, conf->scope, myfilter, (char **)attributes, 0, &ldapmsg); if(ret != LDAP_SUCCESS){//SIGPIPE? return DECLINED; } if(ldap_count_entries(ld, ldapmsg)!=1){ if(!conf->fallback_name || !conf->fallback_docroot){ reqc->name = apr_pstrdup(vhost_ldap_pool, r->hostname); reqc->decline = 1; reqc->admin = apr_pstrdup(vhost_ldap_pool, r->server->server_admin); add_to_requestscache(reqc, r); if(ldapmsg) ldap_msgfree(ldapmsg); ldapdestroy(&ld); return DECLINED; }else{ reqc->name = conf->fallback_name; reqc->docroot = conf->fallback_docroot; } }else{ reqc->aliases = (apr_array_header_t *)apr_array_make(vhost_ldap_pool, 2, sizeof(alias_t)); reqc->redirects = (apr_array_header_t *)apr_array_make(vhost_ldap_pool, 2, sizeof(alias_t)); reqc->env = apr_table_make(vhost_ldap_pool, 2); vhostentry = ldap_first_entry(ld, ldapmsg); reqc->dn = ldap_get_dn(ld, vhostentry); i=0; while(attributes[i]){ int k = 0, j; char **eValues = ldap_get_values(ld, vhostentry, attributes[i]), *str[3]; if (eValues){ k = ldap_count_values (eValues); if (strcasecmp(attributes[i], "apacheServerName") == 0){ reqc->name = apr_pstrdup(vhost_ldap_pool, eValues[0]); }else if(strcasecmp(attributes[i], "apacheServerAdmin") == 0){ reqc->admin = apr_pstrdup(vhost_ldap_pool, eValues[0]); }else if(strcasecmp(attributes[i], "apacheDocumentRoot") == 0){ reqc->docroot = apr_pstrdup(vhost_ldap_pool, eValues[0]); /* Make it absolute, relative to ServerRoot */ if(conf->rootdir && (strncmp(reqc->docroot, "/", 1) != 0)) reqc->docroot = apr_pstrcat(vhost_ldap_pool, conf->rootdir, reqc->docroot, NULL); reqc->docroot = ap_server_root_relative(vhost_ldap_pool, reqc->docroot); }else if(strcasecmp(attributes[i], "apacheAlias") == 0){ while(k){ k--; for(j = 0; j < 2; j++) str[j] = ap_getword_conf(r->pool, (const char **)&eValues[k]); if(str[--j] == '\0') ap_log_rerror(APLOG_MARK, APLOG_WARNING|APLOG_NOERRNO, 0, r, "[mod_vhost_ldap_ng.c]: Wrong apacheAlias parameter: %s", eValues[k]); else{ alias = apr_array_push(reqc->aliases); alias->src = apr_pstrdup(vhost_ldap_pool, str[0]); alias->dst = apr_pstrdup(vhost_ldap_pool, str[1]); } } }else if(strcasecmp(attributes[i], "apacheScriptAlias") == 0){ while(k){ k--; for(j = 0; j < 2; j++) str[j] = ap_getword_conf(r->pool, (const char **)&eValues[k]); if(str[--j] == '\0') ap_log_rerror(APLOG_MARK, APLOG_DEBUG|APLOG_NOERRNO, 0, r, "[mod_vhost_ldap_ng.c]: Wrong apacheScriptAlias parameter: %s", eValues[k]); else{ alias = apr_array_push(reqc->aliases); alias->src = apr_pstrdup(vhost_ldap_pool, str[0]); alias->dst = apr_pstrdup(vhost_ldap_pool, str[1]); } } }else if(strcasecmp (attributes[i], "apacheRedirect") == 0){ while(k){ k--; for(j = 0; j < 3; j++) str[j] = ap_getword_conf(r->pool, (const char **)&eValues[k]); if(str[1] == '\0') ap_log_rerror(APLOG_MARK, APLOG_WARNING|APLOG_NOERRNO, 0, r, "[mod_vhost_ldap_ng.c]: Missing apacheRedirect parameter: %s", eValues[k]); else{ alias = apr_array_push(reqc->redirects); alias->src = apr_pstrdup(vhost_ldap_pool, str[0]); if(str[2] != '\0'){ if(strcasecmp(str[1], "gone") == 0) alias->flags |= REDIR_GONE; else if (strcasecmp(str[1], "permanent") == 0) alias->flags |= REDIR_PERMANENT; else if (strcasecmp(str[1], "temp") == 0) alias->flags |= REDIR_TEMP; else if (strcasecmp(str[1], "seeother") == 0) alias->flags |= REDIR_SEEOTHER; else{ alias->flags |= REDIR_PERMANENT; ap_log_rerror(APLOG_MARK, APLOG_WARNING|APLOG_NOERRNO, 0, r, "[mod_vhost_ldap_ng.c]: Wrong apacheRedirect type: %s", str[2]); } alias->dst = apr_pstrdup(vhost_ldap_pool, str[2]); }else alias->dst = apr_pstrdup(vhost_ldap_pool, str[1]); } } }else if(strcasecmp(attributes[i], "apacheSuexecUid") == 0){ reqc->uid = apr_pstrdup(vhost_ldap_pool, eValues[0]); }else if(strcasecmp(attributes[i], "apacheSuexecGid") == 0){ reqc->gid = apr_pstrdup(vhost_ldap_pool, eValues[0]); }else if(strcasecmp (attributes[i], "apacheErrorLog") == 0){ if(conf->rootdir && (strncmp(eValues[0], "/", 1) != 0)) r->server->error_fname = apr_pstrcat(vhost_ldap_pool, conf->rootdir, eValues[0], NULL); else r->server->error_fname = apr_pstrdup(vhost_ldap_pool, eValues[0]);; apr_file_open(&r->server->error_log, r->server->error_fname, APR_APPEND | APR_WRITE | APR_CREATE | APR_LARGEFILE, APR_OS_DEFAULT, r->pool); } #ifdef HAVEPHP else if(strcasecmp(attributes[i], "phpIncludePath") == 0){ if(conf->php_includepath) reqc->php_includepath = apr_pstrcat(vhost_ldap_pool, conf->php_includepath, ":", eValues[0], NULL); else reqc->php_includepath = apr_pstrdup(vhost_ldap_pool, eValues[0]); }else if(strcasecmp(attributes[i], "phpOpenBasedir") == 0){ if(conf->rootdir && (strncmp(eValues[0], "/", 1) != 0)) reqc->php_openbasedir = apr_pstrcat(vhost_ldap_pool, conf->rootdir, eValues[0], NULL); else reqc->php_openbasedir = apr_pstrdup(vhost_ldap_pool, eValues[0]); } else if(strcasecmp(attributes[i], "php_admin_value") == 0){ } #endif else if(strcasecmp(attributes[i], "SetEnv") == 0){ for(j = 0; j < 2; j++) str[j] = ap_getword_conf(r->pool, (const char **)&eValues[0]); if(str[--j] == '\0') ap_log_rerror(APLOG_MARK, APLOG_DEBUG|APLOG_NOERRNO, 0, r, "[mod_vhost_ldap_ng.c]: Wrong apacheScriptAlias parameter: %s", eValues[0]); else{ apr_table_set(reqc->env, str[0], str[1]); } }else if(strcasecmp(attributes[i], "PassEnv") == 0){ } } i++; } } if(ldapmsg) ldap_msgfree(ldapmsg); ldapdestroy(&ld); add_to_requestscache(reqc, r); } if(reqc->decline) return DECLINED; ap_set_module_config(r->request_config, &vhost_ldap_ng_module, reqc); e = r->subprocess_env; if(apr_table_elts(reqc->env)->nelts) r->subprocess_env = apr_table_overlay(r->pool, e, reqc->env); #ifdef HAVEPHP char *openbasedir, *include; if(!reqc->php_includepath) include = apr_pstrcat(r->pool, conf->php_includepath, ":", reqc->docroot, NULL); else include = apr_pstrcat(r->pool, reqc->php_includepath, ":", conf->php_includepath, ":", reqc->docroot, NULL); zend_alter_ini_entry("include_path", strlen("include_path") + 1, (void *)include, strlen(include), PHP_INI_SYSTEM, PHP_INI_STAGE_RUNTIME); if(reqc->php_openbasedir){ openbasedir = apr_pstrcat(r->pool, reqc->php_openbasedir, ":", include, NULL); zend_alter_ini_entry("open_basedir", strlen("open_basedir") + 1, (void *)openbasedir, strlen(openbasedir), PHP_INI_SYSTEM, PHP_INI_STAGE_RUNTIME); } #endif if ((reqc->name == NULL)||(reqc->docroot == NULL)) { ap_log_rerror(APLOG_MARK, APLOG_ERR|APLOG_NOERRNO, 0, r, "[mod_vhost_ldap_ng.c] translate: " "translate failed; ServerName %s or DocumentRoot %s not defined", reqc->name, reqc->docroot); return HTTP_INTERNAL_SERVER_ERROR; } cursor = NULL; //From mod_alias: checking for redirects if(reqc->redirects){ cursor = (alias_t *)reqc->redirects->elts; if (r->uri[0] != '/' && r->uri[0] != '\0') return DECLINED; for(i = 0; i < reqc->redirects->nelts; i++){ alias = (alias_t *) &cursor[i]; if(alias_matches(r->uri, alias->src)){ apr_table_setn(r->headers_out, "Location", alias->dst); /* OLD STUFF if(alias->redir_status){ if (strcasecmp(alias->redir_status, "gone") == 0) return HTTP_GONE; else if (strcasecmp(alias->redir_status, "permanent") == 0) return HTTP_MOVED_PERMANENTLY; else if (strcasecmp(alias->redir_status, "temp") == 0) return HTTP_MOVED_TEMPORARILY; else if (strcasecmp(alias->redir_status, "seeother") == 0) return HTTP_SEE_OTHER; } */ if(alias->flags & REDIR_GONE) return HTTP_GONE; else if(alias->flags & REDIR_TEMP) return HTTP_MOVED_TEMPORARILY; else if(alias->flags & REDIR_SEEOTHER) return HTTP_SEE_OTHER; else return HTTP_MOVED_PERMANENTLY; } } } /* Checking for aliases */ if(reqc->aliases){ cursor = (alias_t *)reqc->aliases->elts; for(i = 0; reqc->aliases && i < reqc->aliases->nelts; i++){ alias = (alias_t *) &cursor[i]; if (alias_matches(r->uri, alias->src)) { /* Set exact filename for CGI script */ realfile = apr_pstrcat(r->pool, alias->dst, r->uri + strlen(alias->src), NULL); /* Add apacheRootDir config param IF realfile is a realative path*/ if(conf->rootdir && (strncmp(realfile, "/", 1) != 0)) realfile = apr_pstrcat(r->pool, conf->rootdir, "/", realfile, NULL); /* Let apache normalize the path */ if((realfile = ap_server_root_relative(r->pool, realfile))) { ap_log_rerror(APLOG_MARK, APLOG_DEBUG|APLOG_NOERRNO, 0, r, "[mod_vhost_ldap_ng.c]: ap_document_root is: %s", ap_document_root(r)); r->filename = realfile; if(alias->flags & ISCGI){ //r->handler = "cgi-script"; r->handler = "Script"; apr_table_setn(r->notes, "alias-forced-type", r->handler); } return OK; } return OK; } else if (r->uri[0] == '/') { /* we don't set r->filename here, and let other modules do it * this allows other modules (mod_rewrite.c) to work as usual */ /* r->filename = apr_pstrcat (r->pool, reqc->docroot, r->uri, NULL); */ } else { /* We don't handle non-file requests here */ return DECLINED; } } } if ((r->server = apr_pmemdup(r->pool, r->server, sizeof(*r->server))) == NULL) { ap_log_rerror(APLOG_MARK, APLOG_ERR|APLOG_NOERRNO, 0, r, "[mod_vhost_ldap_ng.c] translate: " "translate failed; Unable to copy r->server structure"); return HTTP_INTERNAL_SERVER_ERROR; } r->server->server_hostname = apr_pstrdup(r->pool,reqc->name); if (reqc->admin) r->server->server_admin = apr_pstrdup(r->pool, reqc->admin); #if (AP_SERVER_MAJORVERSION_NUMBER == 2) && (AP_SERVER_MINORVERSION_NUMBER <= 2) core->ap_document_root = apr_pstrdup(r->pool, reqc->docroot); if (!ap_is_directory(r->pool, reqc->docroot)) ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r, "[mod_vhost_ldap_ng.c] set_document_root: Warning: DocumentRoot [%s] does not exist", core->ap_document_root); #else ap_set_document_root(r, reqc->docroot); #endif //ap_set_module_config(r->server->module_config, &core_module, core); /* Hack to allow post-processing by other modules (mod_rewrite, mod_alias) */ return DECLINED; }
/* * Send the right path to the end user upon a request. */ static int vhx_translate_name(request_rec * r) { vhx_config_rec *vhr = (vhx_config_rec *) ap_get_module_config(r->server->module_config, &vhostx_module); core_server_config *conf = (core_server_config *) ap_get_module_config(r->server->module_config, &core_module); vhx_request_t *reqc; int vhost_found_by_request = DECLINED; VH_AP_LOG_RERROR(APLOG_MARK, APLOG_DEBUG, 0, r, "vhx_translate_name: BEGIN ***,pid=%d",getpid()); VH_AP_LOG_RERROR(APLOG_MARK, APLOG_DEBUG|APLOG_NOERRNO, 0, r, "vhx_translate_name: request URI '%s'", r->unparsed_uri); /* If VHS is not enabled, then don't process request */ if (!vhr->enable) { VH_AP_LOG_RERROR(APLOG_MARK, APLOG_DEBUG, 0, r, "vhx_translate_name: VHS Disabled "); return DECLINED; } if(r->hostname == NULL) { VH_AP_LOG_RERROR(APLOG_MARK, APLOG_DEBUG, 0, r, "vhx_translate_name: no 'Host:' header found"); return vhx_redirect_stuff(r, vhr); } vhx_conn_cfg_t *conn_cfg = (vhx_conn_cfg_t*) ap_get_module_config(r->connection->conn_config, &vhostx_module); if (conn_cfg != NULL) { if(conn_cfg->last_vhost != NULL) { if ((apr_strnatcasecmp(r->hostname, conn_cfg->last_vhost) == 0) && (conn_cfg->last_vhost_status == VH_VHOST_INFOS_NOT_FOUND)) { VH_AP_LOG_RERROR(APLOG_MARK, APLOG_DEBUG, 0, r, "vhx_translate_name: VH_VHOST_INFOS_NOT_FOUND already set"); return DECLINED; } } } reqc = ap_get_module_config(r->request_config, &vhostx_module); if (!reqc) { reqc = (vhx_request_t *)apr_pcalloc(r->pool, sizeof(vhx_request_t)); reqc->vhost_found = VH_VHOST_INFOS_NOT_YET_REQUESTED; VH_AP_LOG_RERROR(APLOG_MARK, APLOG_DEBUG, 0, r, "vhx_translate_name: set VH_VHOST_INFOS_NOT_YET_REQUESTED"); ap_set_module_config(r->request_config, &vhostx_module, reqc); } /* If we don't have LDAP Url module is disabled */ if (!vhr->ldap_have_url) { VH_AP_LOG_RERROR(APLOG_MARK, APLOG_ERR, 0, r, "vhx_translate_name: VHS Disabled - No LDAP URL "); return DECLINED; } VH_AP_LOG_RERROR(APLOG_MARK, APLOG_DEBUG, 0, r, "vhx_translate_name: VHS Enabled."); /* Avoid handling request that don't start with '/' */ if (r->uri[0] != '/' && r->uri[0] != '\0') { VH_AP_LOG_RERROR(APLOG_MARK, APLOG_WARNING, 0, r, "%s: (vhx_translate_name) declined URI '%s' no leading `/'", VH_NAME, r->uri); return DECLINED; } //if ((ptr = ap_strchr(host, ':'))) { // *ptr = '\0'; //} if (reqc->vhost_found == VH_VHOST_INFOS_NOT_YET_REQUESTED) { VH_AP_LOG_RERROR(APLOG_MARK, APLOG_DEBUG, 0, r, "vhx_translate_name: looking for %s", r->hostname); /* * Trying to get vhost information */ vhost_found_by_request = getldaphome(r, vhr, (char *) r->hostname, reqc); if (vhost_found_by_request != OK) { /* * The vhost has not been found * Trying to get lamer mode or not */ if (vhr->lamer_mode) { if ((strncasecmp(r->hostname, "www.",4) == 0) && (strlen(r->hostname) > 4)) { VH_AP_LOG_RERROR(APLOG_MARK, APLOG_DEBUG, 0, r, "vhx_translate_name: Lamer friendly mode engaged"); char *lhost; lhost = apr_pstrdup(r->pool, r->hostname + 4); VH_AP_LOG_RERROR(APLOG_MARK, APLOG_DEBUG, 0, r, "vhx_translate_name: Found a lamer for %s -> %s", r->hostname, lhost); vhost_found_by_request = getldaphome(r, vhr, lhost, reqc); if (vhost_found_by_request != OK) { if (vhr->log_notfound) { VH_AP_LOG_RERROR(APLOG_MARK, APLOG_NOTICE, 0, r, "%s: (vhx_translate_name) no host found in database for %s or %s", VH_NAME, r->hostname, lhost); } return vhx_redirect_stuff(r, vhr); } } } else { if (vhr->log_notfound) { VH_AP_LOG_RERROR(APLOG_MARK, APLOG_NOTICE, 0, r, "%s: (vhx_translate_name) no host found in database for %s (WWW mode not enabled)", VH_NAME, r->hostname); } return vhx_redirect_stuff(r, vhr); } } } else { VH_AP_LOG_RERROR(APLOG_MARK, APLOG_DEBUG, 0, r, "vhx_translate_name: Request to backend has already been done (vhx_itk_post_read()) !"); if (reqc->vhost_found == VH_VHOST_INFOS_NOT_FOUND) vhost_found_by_request = DECLINED; /* the request has already be done and vhost was not found */ else vhost_found_by_request = OK; /* the request has already be done and vhost was found */ } if (vhost_found_by_request == OK) VH_AP_LOG_RERROR(APLOG_MARK, APLOG_DEBUG, 0, r, "vhx_translate_name: path found in database for %s is %s", r->hostname, reqc->docroot); else { if (vhr->log_notfound) { VH_AP_LOG_RERROR(APLOG_MARK, APLOG_NOTICE|APLOG_NOERRNO, 0, r, "%s: (vhx_translate_name) no path found found in database for %s", VH_NAME, r->hostname); } return vhx_redirect_stuff(r, vhr); } // Set VH_GECOS env variable - used for logging apr_table_set(r->subprocess_env, "VH_GECOS", reqc->name ? reqc->name : ""); /* Do we have handle vhr_Path_Prefix here ? */ if (vhr->path_prefix) { apr_table_set(r->subprocess_env, "VH_PATH", apr_pstrcat(r->pool, vhr->path_prefix, reqc->docroot, NULL)); apr_table_set(r->subprocess_env, "SERVER_ROOT", apr_pstrcat(r->pool, vhr->path_prefix, reqc->docroot, NULL)); } else { apr_table_set(r->subprocess_env, "VH_PATH", reqc->docroot); apr_table_set(r->subprocess_env, "SERVER_ROOT", reqc->docroot); } if (reqc->admin) { r->server->server_admin = apr_pstrcat(r->pool, reqc->admin, NULL); } else { r->server->server_admin = apr_pstrcat(r->pool, "webmaster@", r->hostname, NULL); } r->server->server_hostname = apr_pstrcat(r->connection->pool, r->hostname, NULL); r->parsed_uri.path = apr_pstrcat(r->pool, vhr->path_prefix ? vhr->path_prefix : "", reqc->docroot, r->parsed_uri.path, NULL); r->parsed_uri.hostname = r->server->server_hostname; r->parsed_uri.hostinfo = r->server->server_hostname; /* document_root */ if (vhr->path_prefix) { conf->ap_document_root = apr_pstrcat(r->pool, vhr->path_prefix, reqc->docroot, NULL); } else { conf->ap_document_root = apr_pstrcat(r->pool, reqc->docroot, NULL); } /* if directory exist */ if (!ap_is_directory(r->pool, reqc->docroot)) { VH_AP_LOG_RERROR(APLOG_MARK, APLOG_ERR, 0, r, "%s: (vhx_translate_name) homedir '%s' is not dir at all", VH_NAME, reqc->docroot); return DECLINED; } r->filename = apr_psprintf(r->pool, "%s%s%s", vhr->path_prefix ? vhr->path_prefix : "", reqc->docroot, r->uri); /* Avoid getting // in filename */ ap_no2slash(r->filename); VH_AP_LOG_RERROR(APLOG_MARK, APLOG_DEBUG, 0, r, "vhx_translate_name: translated http[s]://%s%s to file %s", r->hostname, r->uri, r->filename); #ifdef HAVE_MOD_PHP_SUPPORT if(reqc->homedirectory != NULL) vhx_php_config(r, vhr, reqc->homedirectory, reqc->phpoptions); else vhx_php_config(r, vhr, reqc->docroot, reqc->phpoptions); #endif /* HAVE_MOD_PHP_SUPPORT */ VH_AP_LOG_RERROR(APLOG_MARK, APLOG_DEBUG, 0, r, "vhx_translate_name: END ***, pid=%d",getpid()); return OK; }