[multiple] use stat_cache_path_isdir()

master
Glenn Strauss 3 years ago
parent 7d368cd7a5
commit f846a392d5

@ -10,6 +10,7 @@
#include "stat_cache.h"
#include <errno.h>
#include <stdlib.h>
#include <string.h>
#include <dirent.h>
@ -1025,7 +1026,6 @@ static int http_list_directory(request_st * const r, plugin_data * const p, buff
URIHANDLER_FUNC(mod_dirlisting_subrequest) {
plugin_data *p = p_d;
stat_cache_entry *sce = NULL;
if (NULL != r->handler_module) return HANDLER_GO_ON;
if (buffer_string_is_empty(&r->uri.path)) return HANDLER_GO_ON;
@ -1044,16 +1044,14 @@ URIHANDLER_FUNC(mod_dirlisting_subrequest) {
"URI : %s", r->uri.path.ptr);
}
sce = stat_cache_get_entry(&r->physical.path);
if (NULL == sce) {
log_error(r->conf.errh, __FILE__, __LINE__,
"stat_cache_get_entry failed: %s", r->physical.path.ptr);
if (!stat_cache_path_isdir(&r->physical.path)) {
if (errno == ENOTDIR)
return HANDLER_GO_ON;
log_perror(r->conf.errh,__FILE__,__LINE__,"%s",r->physical.path.ptr);
r->http_status = 500;
return HANDLER_FINISHED;
}
if (!S_ISDIR(sce->st.st_mode)) return HANDLER_GO_ON;
if (http_list_directory(r, p, &r->physical.path)) {
/* dirlisting failed */
r->http_status = 403;

@ -326,7 +326,6 @@ static void mod_evhost_build_doc_root_path(buffer *b, array *parsed_host, buffer
static handler_t mod_evhost_uri_handler(request_st * const r, void *p_d) {
plugin_data *p = p_d;
stat_cache_entry *sce = NULL;
/* not authority set */
if (buffer_string_is_empty(&r->uri.authority)) return HANDLER_GO_ON;
@ -339,11 +338,8 @@ static handler_t mod_evhost_uri_handler(request_st * const r, void *p_d) {
buffer * const b = &p->tmp_buf;
mod_evhost_build_doc_root_path(b, &p->split_vals, &r->uri.authority, p->conf.path_pieces);
sce = stat_cache_get_entry(b);
if (NULL == sce) {
if (!stat_cache_path_isdir(b)) {
log_perror(r->conf.errh, __FILE__, __LINE__, "%s", b->ptr);
} else if(!S_ISDIR(sce->st.st_mode)) {
log_error(r->conf.errh, __FILE__, __LINE__, "not a directory: %s", b->ptr);
} else {
buffer_copy_buffer(&r->physical.doc_root, b);
}

@ -269,7 +269,6 @@ SETDEFAULTS_FUNC(mod_mysql_vhost_set_defaults) {
REQUEST_FUNC(mod_mysql_vhost_handle_docroot) {
plugin_data *p = p_d;
plugin_connection_data *c;
stat_cache_entry *sce;
unsigned cols;
MYSQL_ROW row;
@ -329,15 +328,10 @@ REQUEST_FUNC(mod_mysql_vhost_handle_docroot) {
buffer_copy_string(b, row[0]);
buffer_append_slash(b);
sce = stat_cache_get_entry(b);
if (NULL == sce) {
if (!stat_cache_path_isdir(b)) {
log_perror(r->conf.errh, __FILE__, __LINE__, "%s", b->ptr);
goto ERR500;
}
if (!S_ISDIR(sce->st.st_mode)) {
log_error(r->conf.errh, __FILE__, __LINE__, "Not a directory %s", b->ptr);
goto ERR500;
}
/* cache the data */
buffer_copy_buffer(c->server_name, &r->uri.authority);

@ -152,21 +152,17 @@ static void build_doc_root_path(buffer *out, const buffer *sroot, const buffer *
}
static int build_doc_root(request_st * const r, plugin_data *p, buffer *out, const buffer *host) {
stat_cache_entry *sce = NULL;
build_doc_root_path(out, p->conf.server_root, host, p->conf.document_root);
/* one-element cache (positive cache, not negative cache) */
if (buffer_is_equal(out, &p->last_root)) return 1;
sce = stat_cache_get_entry(out);
if (NULL == sce) {
if (!stat_cache_path_isdir(out)) {
if (p->conf.debug) {
log_perror(r->conf.errh, __FILE__, __LINE__, "%s", out->ptr);
}
return 0;
} else if (!S_ISDIR(sce->st.st_mode)) {
return 0;
}
buffer_copy_buffer(&p->last_root, out);

@ -273,7 +273,6 @@ REQUEST_FUNC(mod_vhostdb_handle_docroot) {
vhostdb_cache_entry *ve;
const http_vhostdb_backend_t *backend;
buffer *b;
stat_cache_entry *sce;
/* no host specified? */
if (buffer_string_is_empty(&r->uri.authority)) return HANDLER_GO_ON;
@ -303,16 +302,10 @@ REQUEST_FUNC(mod_vhostdb_handle_docroot) {
/* sanity check that really is a directory */
buffer_append_slash(b);
sce = stat_cache_get_entry(b);
if (NULL == sce) {
if (!stat_cache_path_isdir(b)) {
log_perror(r->conf.errh, __FILE__, __LINE__, "%s", b->ptr);
return mod_vhostdb_error_500(r); /* HANDLER_FINISHED */
}
if (!S_ISDIR(sce->st.st_mode)) {
log_error(r->conf.errh, __FILE__, __LINE__,
"Not a directory: %s", b->ptr);
return mod_vhostdb_error_500(r); /* HANDLER_FINISHED */
}
if (ve && !p->conf.vhostdb_cache)
vhostdb_cache_entry_free(ve);

@ -75,9 +75,9 @@ int main (void) {
* stub functions
*/
stat_cache_entry * stat_cache_get_entry(const buffer *name) {
int stat_cache_path_isdir(const buffer *name) {
UNUSED(name);
return NULL;
return 1;
}
int config_plugin_values_init(server *srv, void *p_d, const config_plugin_keys_t *cpk, const char *mname) {

@ -43,9 +43,9 @@ int main (void) {
* stub functions
*/
stat_cache_entry * stat_cache_get_entry(const buffer *name) {
int stat_cache_path_isdir(const buffer *name) {
UNUSED(name);
return NULL;
return 1;
}
int config_plugin_values_init(server *srv, void *p_d, const config_plugin_keys_t *cpk, const char *mname) {

Loading…
Cancel
Save