void ssl_ds_array_kill(ssl_ds_array *a) { ap_destroy_pool(a->pSubPool); a->pSubPool = NULL; a->aData = NULL; return; }
void ssl_ds_table_kill(ssl_ds_table *t) { ap_destroy_pool(t->pSubPool); t->pSubPool = NULL; t->aKey = NULL; t->aData = NULL; return; }
CStr qEnvApacheServer::MapFullPath(const char *path) { #ifdef APACHE2 ap_pool * p; apr_pool_create_ex(&p,NULL,NULL,NULL); #else ap_pool * p = ap_make_sub_pool(NULL); #endif CStr r = ap_server_root_relative(p, (char *) path); ap_destroy_pool(p); return r; }
/** * Close all the connections cleanly when the Apache child process exits. * * @param server the Apache server object * @param p the Apache memory pool for the server. */ static void cse_close_child(server_rec *server, pool *p) { LOG(("[%d] close child\n", getpid())); cse_close_all(); if (g_pool) { ap_destroy_pool(g_pool); g_pool = 0; } g_config = 0; LOG(("[%d] close child done\n", getpid())); }
void ServerFree(TServer *srv) { /* sanity */ if (!srv) { return; } if (srv->name) { free(srv->name); srv->name = 0; } if (srv->filespath) { free(srv->filespath); srv->filespath = 0; } if (srv->rootpath) { free(srv->rootpath); srv->rootpath = 0; } if( srv->error_fname ) { free( srv->error_fname ); srv->error_fname = NULL; } if( srv->modulepath ) { free( srv->modulepath ); srv->modulepath = NULL; } if( srv->pool ) { ap_destroy_pool( srv->pool ); srv->pool = NULL; } ListInitAutoFree(&srv->defaultfilenames); SocketClose(&srv->listensock); /* remove from global srv list */ ListRemove( &srv_list,srv ); }
static table *groups_for_user(pool *p, char *user, char *grpfile) { configfile_t *f; table *grps = ap_make_table(p, 15); pool *sp; char l[MAX_STRING_LEN]; const char *group_name, *ll, *w; if (!(f = ap_pcfg_openfile(p, grpfile))) { /*add? aplog_error(APLOG_MARK, APLOG_ERR, NULL, "Could not open group file: %s", grpfile);*/ return NULL; } sp = ap_make_sub_pool(p); while (!(ap_cfg_getline(l, MAX_STRING_LEN, f))) { if ((l[0] == '#') || (!l[0])) continue; ll = l; ap_clear_pool(sp); group_name = ap_getword(sp, &ll, ':'); while (ll[0]) { w = ap_getword_conf(sp, &ll); if (!strcmp(w, user)) { ap_table_setn(grps, ap_pstrdup(p, group_name), "in"); break; } } } ap_cfg_closefile(f); ap_destroy_pool(sp); return grps; }
static int check_speling(request_rec *r) { spconfig *cfg; char *good, *bad, *postgood, *url; int filoc, dotloc, urlen, pglen; DIR *dirp; struct DIR_TYPE *dir_entry; array_header *candidates = NULL; cfg = ap_get_module_config(r->per_dir_config, &speling_module); if (!cfg->enabled) { return DECLINED; } /* We only want to worry about GETs */ if (r->method_number != M_GET) { return DECLINED; } /* We've already got a file of some kind or another */ if (r->proxyreq != NOT_PROXY || (r->finfo.st_mode != 0)) { return DECLINED; } /* This is a sub request - don't mess with it */ if (r->main) { return DECLINED; } /* * The request should end up looking like this: * r->uri: /correct-url/mispelling/more * r->filename: /correct-file/mispelling r->path_info: /more * * So we do this in steps. First break r->filename into two pieces */ filoc = ap_rind(r->filename, '/'); /* * Don't do anything if the request doesn't contain a slash, or * requests "/" */ if (filoc == -1 || strcmp(r->uri, "/") == 0) { return DECLINED; } /* good = /correct-file */ good = ap_pstrndup(r->pool, r->filename, filoc); /* bad = mispelling */ bad = ap_pstrdup(r->pool, r->filename + filoc + 1); /* postgood = mispelling/more */ postgood = ap_pstrcat(r->pool, bad, r->path_info, NULL); urlen = strlen(r->uri); pglen = strlen(postgood); /* Check to see if the URL pieces add up */ if (strcmp(postgood, r->uri + (urlen - pglen))) { return DECLINED; } /* url = /correct-url */ url = ap_pstrndup(r->pool, r->uri, (urlen - pglen)); /* Now open the directory and do ourselves a check... */ dirp = ap_popendir(r->pool, good); if (dirp == NULL) { /* Oops, not a directory... */ return DECLINED; } candidates = ap_make_array(r->pool, 2, sizeof(misspelled_file)); dotloc = ap_ind(bad, '.'); if (dotloc == -1) { dotloc = strlen(bad); } while ((dir_entry = readdir(dirp)) != NULL) { sp_reason q; /* * If we end up with a "fixed" URL which is identical to the * requested one, we must have found a broken symlink or some such. * Do _not_ try to redirect this, it causes a loop! */ if (strcmp(bad, dir_entry->d_name) == 0) { ap_pclosedir(r->pool, dirp); return OK; } /* * miscapitalization errors are checked first (like, e.g., lower case * file, upper case request) */ else if (strcasecmp(bad, dir_entry->d_name) == 0) { misspelled_file *sp_new; sp_new = (misspelled_file *) ap_push_array(candidates); sp_new->name = ap_pstrdup(r->pool, dir_entry->d_name); sp_new->quality = SP_MISCAPITALIZED; } /* * simple typing errors are checked next (like, e.g., * missing/extra/transposed char) */ else if ((q = spdist(bad, dir_entry->d_name)) != SP_VERYDIFFERENT) { misspelled_file *sp_new; sp_new = (misspelled_file *) ap_push_array(candidates); sp_new->name = ap_pstrdup(r->pool, dir_entry->d_name); sp_new->quality = q; } /* * The spdist() should have found the majority of the misspelled * requests. It is of questionable use to continue looking for * files with the same base name, but potentially of totally wrong * type (index.html <-> index.db). * I would propose to not set the WANT_BASENAME_MATCH define. * 08-Aug-1997 <*****@*****.**> * * However, Alexei replied giving some reasons to add it anyway: * > Oh, by the way, I remembered why having the * > extension-stripping-and-matching stuff is a good idea: * > * > If you're using MultiViews, and have a file named foobar.html, * > which you refer to as "foobar", and someone tried to access * > "Foobar", mod_speling won't find it, because it won't find * > anything matching that spelling. With the extension-munging, * > it would locate "foobar.html". Not perfect, but I ran into * > that problem when I first wrote the module. */ else { #ifdef WANT_BASENAME_MATCH /* * Okay... we didn't find anything. Now we take out the hard-core * power tools. There are several cases here. Someone might have * entered a wrong extension (.htm instead of .html or vice * versa) or the document could be negotiated. At any rate, now * we just compare stuff before the first dot. If it matches, we * figure we got us a match. This can result in wrong things if * there are files of different content types but the same prefix * (e.g. foo.gif and foo.html) This code will pick the first one * it finds. Better than a Not Found, though. */ int entloc = ap_ind(dir_entry->d_name, '.'); if (entloc == -1) { entloc = strlen(dir_entry->d_name); } if ((dotloc == entloc) && !strncasecmp(bad, dir_entry->d_name, dotloc)) { misspelled_file *sp_new; sp_new = (misspelled_file *) ap_push_array(candidates); sp_new->name = ap_pstrdup(r->pool, dir_entry->d_name); sp_new->quality = SP_VERYDIFFERENT; } #endif } } ap_pclosedir(r->pool, dirp); if (candidates->nelts != 0) { /* Wow... we found us a mispelling. Construct a fixed url */ char *nuri; const char *ref; misspelled_file *variant = (misspelled_file *) candidates->elts; int i; ref = ap_table_get(r->headers_in, "Referer"); qsort((void *) candidates->elts, candidates->nelts, sizeof(misspelled_file), sort_by_quality); /* * Conditions for immediate redirection: * a) the first candidate was not found by stripping the suffix * AND b) there exists only one candidate OR the best match is not * ambiguous * then return a redirection right away. */ if (variant[0].quality != SP_VERYDIFFERENT && (candidates->nelts == 1 || variant[0].quality != variant[1].quality)) { nuri = ap_escape_uri(r->pool, ap_pstrcat(r->pool, url, variant[0].name, r->path_info, NULL)); if (r->parsed_uri.query) nuri = ap_pstrcat(r->pool, nuri, "?", r->parsed_uri.query, NULL); ap_table_setn(r->headers_out, "Location", ap_construct_url(r->pool, nuri, r)); ap_log_rerror(APLOG_MARK, APLOG_NOERRNO | APLOG_INFO, r, ref ? "Fixed spelling: %s to %s from %s" : "Fixed spelling: %s to %s", r->uri, nuri, ref); return HTTP_MOVED_PERMANENTLY; } /* * Otherwise, a "[300] Multiple Choices" list with the variants is * returned. */ else { pool *p; table *notes; pool *sub_pool; array_header *t; array_header *v; if (r->main == NULL) { p = r->pool; notes = r->notes; } else { p = r->main->pool; notes = r->main->notes; } sub_pool = ap_make_sub_pool(p); t = ap_make_array(sub_pool, candidates->nelts * 8 + 8, sizeof(char *)); v = ap_make_array(sub_pool, candidates->nelts * 5, sizeof(char *)); /* Generate the response text. */ *(const char **)ap_push_array(t) = "The document name you requested (<code>"; *(const char **)ap_push_array(t) = ap_escape_html(sub_pool, r->uri); *(const char **)ap_push_array(t) = "</code>) could not be found on this server.\n" "However, we found documents with names similar " "to the one you requested.<p>" "Available documents:\n<ul>\n"; for (i = 0; i < candidates->nelts; ++i) { char *vuri; const char *reason; reason = sp_reason_str[(int) (variant[i].quality)]; /* The format isn't very neat... */ vuri = ap_pstrcat(sub_pool, url, variant[i].name, r->path_info, (r->parsed_uri.query != NULL) ? "?" : "", (r->parsed_uri.query != NULL) ? r->parsed_uri.query : "", NULL); *(const char **)ap_push_array(v) = "\""; *(const char **)ap_push_array(v) = ap_escape_uri(sub_pool, vuri); *(const char **)ap_push_array(v) = "\";\""; *(const char **)ap_push_array(v) = reason; *(const char **)ap_push_array(v) = "\""; *(const char **)ap_push_array(t) = "<li><a href=\""; *(const char **)ap_push_array(t) = ap_escape_uri(sub_pool, vuri); *(const char **)ap_push_array(t) = "\">"; *(const char **)ap_push_array(t) = ap_escape_html(sub_pool, vuri); *(const char **)ap_push_array(t) = "</a> ("; *(const char **)ap_push_array(t) = reason; *(const char **)ap_push_array(t) = ")\n"; /* * when we have printed the "close matches" and there are * more "distant matches" (matched by stripping the suffix), * then we insert an additional separator text to suggest * that the user LOOK CLOSELY whether these are really the * files she wanted. */ if (i > 0 && i < candidates->nelts - 1 && variant[i].quality != SP_VERYDIFFERENT && variant[i + 1].quality == SP_VERYDIFFERENT) { *(const char **)ap_push_array(t) = "</ul>\nFurthermore, the following related " "documents were found:\n<ul>\n"; } } *(const char **)ap_push_array(t) = "</ul>\n"; /* If we know there was a referring page, add a note: */ if (ref != NULL) { *(const char **)ap_push_array(t) = "Please consider informing the owner of the " "<a href=\""; *(const char **)ap_push_array(t) = ap_escape_uri(sub_pool, ref); *(const char **)ap_push_array(t) = "\">referring page</a> " "about the broken link.\n"; } /* Pass our table to http_protocol.c (see mod_negotiation): */ ap_table_setn(notes, "variant-list", ap_array_pstrcat(p, t, 0)); ap_table_mergen(r->subprocess_env, "VARIANTS", ap_array_pstrcat(p, v, ',')); ap_destroy_pool(sub_pool); ap_log_rerror(APLOG_MARK, APLOG_NOERRNO | APLOG_INFO, r, ref ? "Spelling fix: %s: %d candidates from %s" : "Spelling fix: %s: %d candidates", r->uri, candidates->nelts, ref); return HTTP_MULTIPLE_CHOICES; } } return OK; }
static void trace_add(server_rec *s, request_rec *r, excfg *mconfig, const char *note) { const char *sofar; char *addon; char *where; pool *p; const char *trace_copy; /* * Make sure our pools and tables are set up - we need 'em. */ setup_module_cells(); /* * Now, if we're in request-context, we use the request pool. */ if (r != NULL) { p = r->pool; if ((trace_copy = ap_table_get(r->notes, TRACE_NOTE)) == NULL) { trace_copy = ""; } } else { /* * We're not in request context, so the trace gets attached to our * module-wide pool. We do the create/destroy every time we're called * in non-request context; this avoids leaking memory in some of * the subsequent calls that allocate memory only once (such as the * key formation below). * * Make a new sub-pool and copy any existing trace to it. Point the * trace cell at the copied value. */ p = ap_make_sub_pool(example_pool); if (trace != NULL) { trace = ap_pstrdup(p, trace); } /* * Now, if we have a sub-pool from before, nuke it and replace with * the one we just allocated. */ if (example_subpool != NULL) { ap_destroy_pool(example_subpool); } example_subpool = p; trace_copy = trace; } /* * If we weren't passed a configuration record, we can't figure out to * what location this call applies. This only happens for co-routines * that don't operate in a particular directory or server context. If we * got a valid record, extract the location (directory or server) to which * it applies. */ where = (mconfig != NULL) ? mconfig->loc : "nowhere"; where = (where != NULL) ? where : ""; /* * Now, if we're not in request context, see if we've been called with * this particular combination before. The table is allocated in the * module's private pool, which doesn't get destroyed. */ if (r == NULL) { char *key; key = ap_pstrcat(p, note, ":", where, NULL); if (ap_table_get(static_calls_made, key) != NULL) { /* * Been here, done this. */ return; } else { /* * First time for this combination of routine and environment - * log it so we don't do it again. */ ap_table_set(static_calls_made, key, "been here"); } } addon = ap_pstrcat(p, " <LI>\n", " <DL>\n", " <DT><SAMP>", note, "</SAMP>\n", " </DT>\n", " <DD><SAMP>[", where, "]</SAMP>\n", " </DD>\n", " </DL>\n", " </LI>\n", NULL); sofar = (trace_copy == NULL) ? "" : trace_copy; trace_copy = ap_pstrcat(p, sofar, addon, NULL); if (r != NULL) { ap_table_set(r->notes, TRACE_NOTE, trace_copy); } else { trace = trace_copy; } /* * You *could* change the following if you wanted to see the calling * sequence reported in the server's error_log, but beware - almost all of * these co-routines are called for every single request, and the impact * on the size (and readability) of the error_log is considerable. */ #define EXAMPLE_LOG_EACH 0 #if EXAMPLE_LOG_EACH if (s != NULL) { ap_log_error(APLOG_MARK, APLOG_DEBUG, s, "mod_example: %s", note); } #endif }
void ServerFunc(TConn *c) { TRequest r; uint32 ka = 0; /* sanity */ if (!c) { return; } ka=c->server->keepalivemaxconn; c->pool = ap_make_sub_pool( c->server->pool ); c->server->stat_conns++; RequestInit(&r,c); /* tell connection handlers - new connection */ ap_conn_init_modules( c ); while (ka--) { c->start_time = ap_time(); /* Wait to read until timeout */ if (!ConnRead(c,c->server->keepalivetimeout)) { break; } /* CODE_PROBE_1("Server - Req Read Start (%x)",c); */ if (RequestRead(&r)) { /* Check if it is the last keepalive */ if (ka==1) { r.keepalive=FALSE; } r.cankeepalive=r.keepalive; if (r.status==0) { if (r.versionmajor>=2) { ResponseStatus(&r,505); } else if (!RequestValidURI(&r)) { ResponseStatus(&r,400); } else { if( ap_invoke_handler( &r ) == DECLINED ) { ((HANDLER)(c->server->defaulthandler))(&r); } } } } /* CODE_PROBE_1("Server - Req Read End (%x)",c); */ HTTPWriteEnd(&r); ConnWriteFlush( c ); if (!r.done) ResponseError(&r); RequestLog(&r); /* do flow stat update */ c->server->stat_inbytes += c->inbytes; c->server->stat_outbytes += c->outbytes; c->server->stat_data_time += ap_time() - c->start_time; if( c->server->stopped ) { break; } if (!(r.keepalive && r.cankeepalive)) { break; } RequestReset(&r,c); ConnReadInit(c); /* CODE_PROBE_1("Server - ConnReadInit - Bottom (%x)",c); */ } /* tell connection handlers session complete */ ap_conn_exit_modules( c ); ap_destroy_pool( c->pool ); RequestFree(&r); SocketClose(&(c->socket)); }
const char *fcgi_config_make_dynamic_dir(pool *p, const int wax) { const char *err; pool *tp; fcgi_dynamic_dir = ap_pstrcat(p, fcgi_socket_dir, "/dynamic", NULL); if ((err = fcgi_config_make_dir(p, fcgi_dynamic_dir))) return ap_psprintf(p, "can't create dynamic directory \"%s\": %s", fcgi_dynamic_dir, err); /* Don't step on a running server unless its OK. */ if (!wax) return NULL; #ifdef APACHE2 { apr_dir_t * dir; apr_finfo_t finfo; if (apr_pool_create(&tp, p)) return "apr_pool_create() failed"; if (apr_dir_open(&dir, fcgi_dynamic_dir, tp)) return "apr_dir_open() failed"; /* delete the contents */ while (apr_dir_read(&finfo, APR_FINFO_NAME, dir) == APR_SUCCESS) { if (strcmp(finfo.name, ".") == 0 || strcmp(finfo.name, "..") == 0) continue; apr_file_remove(finfo.name, tp); } } #else /* !APACHE2 */ { DIR *dp; struct dirent *dirp = NULL; tp = ap_make_sub_pool(p); dp = ap_popendir(tp, fcgi_dynamic_dir); if (dp == NULL) { ap_destroy_pool(tp); return ap_psprintf(p, "can't open dynamic directory \"%s\": %s", fcgi_dynamic_dir, strerror(errno)); } /* delete the contents */ while ((dirp = readdir(dp)) != NULL) { if (strcmp(dirp->d_name, ".") == 0 || strcmp(dirp->d_name, "..") == 0) continue; unlink(ap_pstrcat(tp, fcgi_dynamic_dir, "/", dirp->d_name, NULL)); } } #endif /* !APACHE2 */ ap_destroy_pool(tp); return NULL; }