From 0df3ec32ca81e7902eb44f21734dba380ab9b6ef Mon Sep 17 00:00:00 2001 From: Brian Havard Date: Mon, 10 Jan 2000 15:35:51 +0000 Subject: [PATCH] Rework ap_finfo_t to split the file type out of the protection field. I've taken a stab at the unix implementation but tested only on OS/2. git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@84416 13f79535-47bb-0310-9956-ffa450edef68 --- modules/generators/mod_autoindex.c | 6 +++--- modules/generators/mod_cgi.c | 4 ++-- modules/http/http_request.c | 29 ++++++++++++++++------------- modules/http/mod_mime.c | 2 +- modules/mappers/mod_dir.c | 2 +- modules/mappers/mod_negotiation.c | 2 +- modules/metadata/mod_cern_meta.c | 2 +- server/util.c | 6 ++---- 8 files changed, 27 insertions(+), 26 deletions(-) diff --git a/modules/generators/mod_autoindex.c b/modules/generators/mod_autoindex.c index a9bd62ad21..47ed08791a 100644 --- a/modules/generators/mod_autoindex.c +++ b/modules/generators/mod_autoindex.c @@ -953,7 +953,7 @@ static void emit_head(request_rec *r, char *header_fname, int suppress_amble, && (rr = ap_sub_req_lookup_uri(header_fname, r)) && (rr->status == HTTP_OK) && (rr->filename != NULL) - && S_ISREG(rr->finfo.protection)) { + && rr->finfo.filetype == APR_REG) { /* * Check for the two specific cases we allow: text/html and * text/anything-else. The former is allowed to be processed for @@ -1036,7 +1036,7 @@ static void emit_tail(request_rec *r, char *readme_fname, int suppress_amble) && (rr = ap_sub_req_lookup_uri(readme_fname, r)) && (rr->status == HTTP_OK) && (rr->filename != NULL) - && S_ISREG(rr->finfo.protection)) { + && rr->finfo.filetype == APR_REG) { /* * Check for the two specific cases we allow: text/html and * text/anything-else. The former is allowed to be processed for @@ -1163,7 +1163,7 @@ static struct ent *make_autoindex_entry(char *name, int autoindex_opts, if (rr->finfo.protection != 0) { p->lm = rr->finfo.mtime; - if (S_ISDIR(rr->finfo.protection)) { + if (rr->finfo.filetype == APR_DIR) { if (!(p->icon = find_icon(d, rr, 1))) { p->icon = find_default_icon(d, "^^DIRECTORY^^"); } diff --git a/modules/generators/mod_cgi.c b/modules/generators/mod_cgi.c index 8338bcd570..3017955501 100644 --- a/modules/generators/mod_cgi.c +++ b/modules/generators/mod_cgi.c @@ -482,7 +482,7 @@ static int cgi_handler(request_rec *r) #if defined(OS2) || defined(WIN32) /* Allow for cgi files without the .EXE extension on them under OS/2 */ - if (r->finfo.st_mode == 0) { + if (r->finfo.protection == 0) { struct stat statbuf; char *newfile; @@ -500,7 +500,7 @@ static int cgi_handler(request_rec *r) return log_scripterror(r, conf, NOT_FOUND, APLOG_NOERRNO, "script not found or unable to stat"); #endif - if (S_ISDIR(r->finfo.protection)) + if (r->finfo.filetype == APR_DIR) return log_scripterror(r, conf, FORBIDDEN, APLOG_NOERRNO, "attempt to invoke directory as script"); diff --git a/modules/http/http_request.c b/modules/http/http_request.c index 55adcc633f..579990333b 100644 --- a/modules/http/http_request.c +++ b/modules/http/http_request.c @@ -116,12 +116,13 @@ IMPLEMENT_HOOK_RUN_FIRST(int,auth_checker,(request_rec *r),(r),DECLINED) static int check_safe_file(request_rec *r) { - if (r->finfo.protection == 0 /* doesn't exist */ - || S_ISDIR(r->finfo.protection) - || S_ISREG(r->finfo.protection) - || S_ISLNK(r->finfo.protection)) { + if (r->finfo.protection == 0 /* doesn't exist */ + || r->finfo.filetype == APR_DIR + || r->finfo.filetype == APR_REG + || r->finfo.filetype == APR_LNK) { return OK; } + ap_log_rerror(APLOG_MARK, APLOG_NOERRNO|APLOG_ERR, 0, r, "object is not a file, directory or symlink: %s", r->filename); @@ -272,8 +273,9 @@ static int get_path_info(request_rec *r) * contents of that directory for a multi_match, so the PATH_INFO * argument starts with the component after that. */ - if (S_ISDIR(r->finfo.protection) && last_cp) { + if (r->finfo.filetype == APR_DIR && last_cp) { r->finfo.protection = 0; /* No such file... */ + r->finfo.filetype = APR_NOFILE; /* No such file... */ cp = last_cp; } @@ -286,8 +288,8 @@ static int get_path_info(request_rec *r) */ r->finfo.protection = 0; -#if defined(ENOENT) && defined(ENOTDIR) - if (errno == ENOENT || errno == ENOTDIR) { +#if defined(APR_ENOENT) && defined(APR_ENOTDIR) + if (rv == APR_ENOENT || rv == APR_ENOTDIR) { last_cp = cp; while (--cp > path && *cp != '/') @@ -297,10 +299,10 @@ static int get_path_info(request_rec *r) --cp; } else { -#if defined(EACCES) - if (errno != EACCES) +#if defined(APR_EACCES) + if (rv != APR_EACCES) #endif - ap_log_rerror(APLOG_MARK, APLOG_ERR, errno, r, + ap_log_rerror(APLOG_MARK, APLOG_ERR, rv, r, "access to %s failed", r->uri); return HTTP_FORBIDDEN; } @@ -355,6 +357,7 @@ static int directory_walk(request_rec *r) if (r->filename == NULL) { r->filename = ap_pstrdup(r->pool, r->uri); r->finfo.protection = 0; /* Not really a file... */ + r->finfo.filetype = APR_NOFILE; r->per_dir_config = per_dir_defaults; return OK; @@ -436,7 +439,7 @@ static int directory_walk(request_rec *r) if (test_filename[test_filename_len - 1] == '/') --num_dirs; - if (S_ISDIR(r->finfo.protection)) + if (r->finfo.filetype == APR_DIR) ++num_dirs; /* @@ -571,7 +574,7 @@ static int directory_walk(request_rec *r) * S_ISDIR test. But if you accessed /symlink/index.html, for example, * you would *not* get the 403. */ - if (!S_ISDIR(r->finfo.protection) + if (r->finfo.filetype != APR_DIR && (res = check_symlinks(r->filename, ap_allow_options(r)))) { ap_log_rerror(APLOG_MARK, APLOG_NOERRNO|APLOG_ERR, 0, r, "Symbolic link not allowed: %s", r->filename); @@ -875,7 +878,7 @@ API_EXPORT(request_rec *) ap_sub_req_lookup_file(const char *new_file, * no matter what, if it's a subdirectory, we need to re-run * directory_walk */ - if (S_ISDIR(rnew->finfo.protection)) { + if (rnew->finfo.filetype == APR_DIR) { res = directory_walk(rnew); if (!res) { res = file_walk(rnew); diff --git a/modules/http/mod_mime.c b/modules/http/mod_mime.c index adccd1f33c..cb31a02651 100644 --- a/modules/http/mod_mime.c +++ b/modules/http/mod_mime.c @@ -286,7 +286,7 @@ static int find_ct(request_rec *r) const char *orighandler = r->handler; const char *type; - if (S_ISDIR(r->finfo.protection)) { + if (r->finfo.filetype == APR_DIR) { r->content_type = DIR_MAGIC_TYPE; return OK; } diff --git a/modules/mappers/mod_dir.c b/modules/mappers/mod_dir.c index 8f97e6b2b1..885b7c081e 100644 --- a/modules/mappers/mod_dir.c +++ b/modules/mappers/mod_dir.c @@ -161,7 +161,7 @@ static int handle_dir(request_rec *r) char *name_ptr = *names_ptr; request_rec *rr = ap_sub_req_lookup_uri(name_ptr, r); - if (rr->status == HTTP_OK && S_ISREG(rr->finfo.protection)) { + if (rr->status == HTTP_OK && rr->finfo.filetype == APR_REG) { char *new_uri = ap_escape_uri(r->pool, rr->uri); if (rr->args != NULL) diff --git a/modules/mappers/mod_negotiation.c b/modules/mappers/mod_negotiation.c index 63b7f6e1c1..dc569776e0 100644 --- a/modules/mappers/mod_negotiation.c +++ b/modules/mappers/mod_negotiation.c @@ -2621,7 +2621,7 @@ static int handle_multi(request_rec *r) /* BLECH --- don't multi-resolve non-ordinary files */ - if (!S_ISREG(sub_req->finfo.protection)) { + if (sub_req->finfo.filetype != APR_REG) { res = NOT_FOUND; goto return_from_multi; } diff --git a/modules/metadata/mod_cern_meta.c b/modules/metadata/mod_cern_meta.c index 679d0e8af8..4e68df1e93 100644 --- a/modules/metadata/mod_cern_meta.c +++ b/modules/metadata/mod_cern_meta.c @@ -314,7 +314,7 @@ static int add_cern_meta_data(request_rec *r) }; /* is this a directory? */ - if (S_ISDIR(r->finfo.protection) || r->uri[strlen(r->uri) - 1] == '/') { + if (r->finfo.filetype == APR_DIR || r->uri[strlen(r->uri) - 1] == '/') { return DECLINED; }; diff --git a/server/util.c b/server/util.c index 0a2342beb4..c1027a3985 100644 --- a/server/util.c +++ b/server/util.c @@ -756,7 +756,6 @@ API_EXPORT(ap_status_t) ap_pcfg_openfile(configfile_t **ret_cfg, ap_context_t *p ap_file_t *file = NULL; ap_finfo_t finfo; ap_status_t stat; - ap_filetype_e type; if (name == NULL) { ap_log_error(APLOG_MARK, APLOG_ERR | APLOG_NOERRNO, 0, NULL, @@ -780,12 +779,11 @@ API_EXPORT(ap_status_t) ap_pcfg_openfile(configfile_t **ret_cfg, ap_context_t *p if (stat != APR_SUCCESS) return stat; - ap_getfileinfo(&finfo, file); - stat = ap_get_filetype(&type, finfo.protection); + stat = ap_getfileinfo(&finfo, file); if (stat != APR_SUCCESS) return stat; - if (type != APR_REG && + if (finfo.filetype != APR_REG && #if defined(WIN32) || defined(OS2) !(strcasecmp(name, "nul") == 0 || (strlen(name) >= 4 && -- 2.50.1