static const char *configure_redirect(cmd_parms *cmd, void *d_, const char *arg1) { dir_config_rec *d = d_; int status; if (!strcasecmp(arg1, "ON")) status = HTTP_MOVED_TEMPORARILY; else if (!strcasecmp(arg1, "OFF")) status = REDIRECT_OFF; else if (!strcasecmp(arg1, "permanent")) status = HTTP_MOVED_PERMANENTLY; else if (!strcasecmp(arg1, "temp")) status = HTTP_MOVED_TEMPORARILY; else if (!strcasecmp(arg1, "seeother")) status = HTTP_SEE_OTHER; else if (apr_isdigit(*arg1)) { status = atoi(arg1); if (!ap_is_HTTP_REDIRECT(status)) { return "DirectoryIndexRedirect only accepts values between 300 and 399"; } } else { return "DirectoryIndexRedirect ON|OFF|permanent|temp|seeother|3xx"; } d->redirect_index = status; return NULL; }
/*============================================================================ *============================================================================ * This is the beginning of the cgi filter code moved from mod_include. This * is the code required to handle the "exec" SSI directive. *============================================================================ *============================================================================*/ static apr_status_t include_cgi(include_ctx_t *ctx, ap_filter_t *f, apr_bucket_brigade *bb, char *s) { request_rec *r = f->r; request_rec *rr = ap_sub_req_lookup_uri(s, r, f->next); int rr_status; if (rr->status != HTTP_OK) { ap_destroy_sub_req(rr); return APR_EGENERAL; } /* No hardwired path info or query allowed */ if ((rr->path_info && rr->path_info[0]) || rr->args) { ap_destroy_sub_req(rr); return APR_EGENERAL; } if (rr->finfo.filetype != APR_REG) { ap_destroy_sub_req(rr); return APR_EGENERAL; } /* Script gets parameters of the *document*, for back compatibility */ rr->path_info = r->path_info; /* hard to get right; see mod_cgi.c */ rr->args = r->args; /* Force sub_req to be treated as a CGI request, even if ordinary * typing rules would have called it something else. */ ap_set_content_type(rr, CGI_MAGIC_TYPE); /* Run it. */ rr_status = ap_run_sub_req(rr); if (ap_is_HTTP_REDIRECT(rr_status)) { const char *location = apr_table_get(rr->headers_out, "Location"); if (location) { char *buffer; location = ap_escape_html(rr->pool, location); buffer = apr_pstrcat(ctx->pool, "<a href=\"", location, "\">", location, "</a>", NULL); APR_BRIGADE_INSERT_TAIL(bb, apr_bucket_pool_create(buffer, strlen(buffer), ctx->pool, f->c->bucket_alloc)); } } ap_destroy_sub_req(rr); return APR_SUCCESS; }
static int asis_handler(request_rec *r) { FILE *f; const char *location; r->allowed |= (1 << M_GET); if (r->method_number != M_GET) return DECLINED; if (r->finfo.st_mode == 0) { ap_log_rerror(APLOG_MARK, APLOG_NOERRNO|APLOG_ERR, r, "File does not exist: %s", r->filename); return NOT_FOUND; } f = ap_pfopen(r->pool, r->filename, "r"); if (f == NULL) { ap_log_rerror(APLOG_MARK, APLOG_ERR, r, "file permissions deny server access: %s", r->filename); return FORBIDDEN; } ap_scan_script_header_err(r, f, NULL); location = ap_table_get(r->headers_out, "Location"); if (location && location[0] == '/' && ((r->status == HTTP_OK) || ap_is_HTTP_REDIRECT(r->status))) { ap_pfclose(r->pool, f); /* Internal redirect -- fake-up a pseudo-request */ r->status = HTTP_OK; /* This redirect needs to be a GET no matter what the original * method was. */ r->method = ap_pstrdup(r->pool, "GET"); r->method_number = M_GET; ap_internal_redirect_handler(location, r); return OK; } ap_send_http_header(r); if (!r->header_only) ap_send_fd(f, r); ap_pfclose(r->pool, f); return OK; }
static int asis_handler(request_rec *r) { conn_rec *c = r->connection; apr_file_t *f = NULL; apr_status_t rv; const char *location; if(strcmp(r->handler,ASIS_MAGIC_TYPE) && strcmp(r->handler,"send-as-is")) return DECLINED; r->allowed |= (AP_METHOD_BIT << M_GET); if (r->method_number != M_GET) return DECLINED; if (r->finfo.filetype == 0) { ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r, "File does not exist: %s", r->filename); return HTTP_NOT_FOUND; } if ((rv = apr_file_open(&f, r->filename, APR_READ, APR_OS_DEFAULT, r->pool)) != APR_SUCCESS) { ap_log_rerror(APLOG_MARK, APLOG_ERR, rv, r, "file permissions deny server access: %s", r->filename); return HTTP_FORBIDDEN; } ap_scan_script_header_err(r, f, NULL); location = apr_table_get(r->headers_out, "Location"); if (location && location[0] == '/' && ((r->status == HTTP_OK) || ap_is_HTTP_REDIRECT(r->status))) { apr_file_close(f); /* Internal redirect -- fake-up a pseudo-request */ r->status = HTTP_OK; /* This redirect needs to be a GET no matter what the original * method was. */ r->method = apr_pstrdup(r->pool, "GET"); r->method_number = M_GET; ap_internal_redirect_handler(location, r); return OK; } if (!r->header_only) { apr_bucket_brigade *bb; apr_bucket *b; apr_off_t pos = 0; rv = apr_file_seek(f, APR_CUR, &pos); if (rv != APR_SUCCESS) { ap_log_rerror(APLOG_MARK, APLOG_ERR, rv, r, "mod_asis: failed to find end-of-headers position " "for %s", r->filename); apr_file_close(f); return HTTP_INTERNAL_SERVER_ERROR; } bb = apr_brigade_create(r->pool, c->bucket_alloc); #if APR_HAS_LARGE_FILES if (r->finfo.size - pos > AP_MAX_SENDFILE) { /* APR_HAS_LARGE_FILES issue; must split into mutiple buckets, * no greater than MAX(apr_size_t), and more granular than that * in case the brigade code/filters attempt to read it directly. */ apr_off_t fsize = r->finfo.size - pos; b = apr_bucket_file_create(f, pos, AP_MAX_SENDFILE, r->pool, c->bucket_alloc); while (fsize > AP_MAX_SENDFILE) { APR_BRIGADE_INSERT_TAIL(bb, b); apr_bucket_copy(b, &b); b->start += AP_MAX_SENDFILE; fsize -= AP_MAX_SENDFILE; } b->length = (apr_size_t)fsize; /* Resize just the last bucket */ } else #endif b = apr_bucket_file_create(f, pos, (apr_size_t) (r->finfo.size - pos), r->pool, c->bucket_alloc); APR_BRIGADE_INSERT_TAIL(bb, b); b = apr_bucket_eos_create(c->bucket_alloc); APR_BRIGADE_INSERT_TAIL(bb, b); rv = ap_pass_brigade(r->output_filters, bb); if (rv != APR_SUCCESS) { ap_log_rerror(APLOG_MARK, APLOG_ERR, rv, r, "mod_asis: ap_pass_brigade failed for file %s", r->filename); return HTTP_INTERNAL_SERVER_ERROR; } } else { apr_file_close(f); } return OK; }
static int sqlalias_redir(request_rec *r) { MYSQL *dblink = NULL; server_rec *s = r->server; sqlalias_conf_t *s_cfg = (sqlalias_conf_t *) ap_get_module_config(s->module_config, &sqlalias_module); if (r->uri[0] != '/' && r->uri[0] != '\0') { return DECLINED; } else if(!s_cfg->enable || sqlalias_filter(r, s_cfg->filters) == FILTERED_URI || !(dblink = sqlalias_dbconnect(r->server, s_cfg))) { return DECLINED; } else { MYSQL_RES *result = NULL; MYSQL_ROW row; char *query = NULL; int found = 0; int response = 0; const char *ccp; int uri_length = strlen(r->uri); char *uri = (char *) malloc(sizeof(char) * (uri_length * 2 + 1)); strcpy(uri, r->uri); #ifndef SQLALIAS_PERFECT_MATCH if (uri_length > 1 && uri[uri_length-1] == '/') { uri[uri_length-1] = '\0'; uri_length--; } #endif /* SQLALIAS_PERFECT_MATCH */ mysql_real_escape_string(dblink, uri, uri, uri_length); query = apr_psprintf(r->pool, s_cfg->db_query, uri); free(uri); if(mysql_real_query(dblink, query, strlen(query))) { ap_log_error(APLOG_MARK, APLOG_ERR|APLOG_NOERRNO, 0, r->server, "sqlalias: %s.", mysql_error(dblink)); #ifdef SQLALIAS_USE_PCONNECT apr_thread_mutex_unlock(sqlalias_mutex); #else DEBUG_MSG(r->server, "sqlalias: Database connection closed. (pid:%d)", getpid()); mysql_close(dblink); #endif /* SQLALIAS_USE_PCONNECT */ return DECLINED; } if (!(result = mysql_store_result(dblink))) { ap_log_error(APLOG_MARK, APLOG_ERR|APLOG_NOERRNO, 0, r->server, "sqlalias: %s.", mysql_error(dblink)); #ifdef SQLALIAS_USE_PCONNECT apr_thread_mutex_unlock(sqlalias_mutex); #else DEBUG_MSG(r->server, "sqlalias: Database connection closed. (pid:%d)", getpid()); mysql_close(dblink); #endif /* SQLALIAS_USE_PCONNECT */ return DECLINED; } if((row = mysql_fetch_row(result))) { found = 1; response = (mysql_num_fields(result) > 1) ? atoi(row[1]) : DECLINED ; if(ap_is_HTTP_REDIRECT(response) || (is_absolute_uri(row[0]) && (response = HTTP_MOVED_TEMPORARILY))) { char *destination = apr_pstrdup(r->pool, row[0]); DEBUG_MSG(r->server, "sqlalias: %s redirect to %s (R=%d)", r->uri, destination, response?response:HTTP_OK); apr_table_setn(r->headers_out, "Location", destination); } else { DEBUG_MSG(r->server, "sqlalias: rewrite %s -> %s", r->uri, row[0]); /* the filename must be either an absolute local path or an * absolute local URL. */ if (*row[0] != '/' && !ap_os_is_path_absolute(r->pool, row[0])) { ap_log_error(APLOG_MARK, APLOG_ERR, 0, r->server, "sqlalias: Bad redirection for %s (%s)", r->uri, row[0]); response = HTTP_BAD_REQUEST; } else if ((ccp = ap_document_root(r)) != NULL) { char *q = NULL; r->uri = apr_pstrdup(r->pool, row[0]); q = strchr(r->uri, '?'); if (q != NULL) { char *olduri = NULL; olduri = apr_pstrdup(r->pool, r->uri); *q++ = '\0'; if(r->args) r->args = apr_pstrcat(r->pool, q, "&", r->args, NULL); else r->args = apr_pstrdup(r->pool, q); if(strlen(r->args) == 0) r->args = NULL; } } } #ifdef SQLALIAS_DEBUG } else { DEBUG_MSG(r->server, "sqlalias: No entry for %s", r->uri); #endif /* SQLALIAS_DEBUG */ } mysql_free_result(result); #ifdef SQLALIAS_USE_PCONNECT apr_thread_mutex_unlock(sqlalias_mutex); #else DEBUG_MSG(r->server, "sqlalias: Database connection closed. (pid:%d)", getpid()); mysql_close(dblink); #endif /* SQLALIAS_USE_PCONNECT */ if(found && response != 200) return response; } return DECLINED; }