From 16748b4e22c536f92850d4106cdcdcc7d7ff000c Mon Sep 17 00:00:00 2001 From: Ryan Bloom Date: Mon, 12 Jun 2000 15:29:09 +0000 Subject: [PATCH] Remove the final vestiges of stat.h from Apache 2.0. All calls are now to ap_stat. This also adds the new function ap_lstat(). This function is analogous to lstat. git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@85535 13f79535-47bb-0310-9956-ffa450edef68 --- include/ap_config.h | 4 -- modules/cache/mod_file_cache.c | 1 - modules/filters/mod_include.c | 4 +- modules/http/http_request.c | 20 ++++---- modules/mappers/mod_rewrite.c | 64 +++++++++++++------------- os/win32/os.h | 2 - os/win32/util_win32.c | 1 - server/mpm/dexter/dexter.c | 3 +- server/mpm/mpmt_beos/mpmt_beos.c | 3 +- server/mpm/mpmt_beos/poll.c | 1 - server/mpm/mpmt_pthread/mpmt_pthread.c | 3 +- server/mpm/prefork/prefork.c | 5 +- server/mpm/spmt_os2/spmt_os2.c | 3 +- server/mpm/winnt/mpm_winnt.c | 3 +- server/util.c | 6 +-- support/htpasswd.c | 12 +---- 16 files changed, 63 insertions(+), 72 deletions(-) diff --git a/include/ap_config.h b/include/ap_config.h index d9b3394483..852ede7d80 100644 --- a/include/ap_config.h +++ b/include/ap_config.h @@ -108,10 +108,6 @@ extern "C" { #include #endif -#ifdef HAVE_SYS_STAT_H -#include -#endif - #ifdef HAVE_UNISTD_H #include #endif diff --git a/modules/cache/mod_file_cache.c b/modules/cache/mod_file_cache.c index 1326e56c67..ecb15dbcf3 100644 --- a/modules/cache/mod_file_cache.c +++ b/modules/cache/mod_file_cache.c @@ -111,7 +111,6 @@ #include #include -#include #include #include #include diff --git a/modules/filters/mod_include.c b/modules/filters/mod_include.c index 38f043ba48..f87cb2c7bb 100644 --- a/modules/filters/mod_include.c +++ b/modules/filters/mod_include.c @@ -2415,7 +2415,7 @@ static int send_parsed_file(request_rec *r) if ((*state == xbithack_full) #if !defined(OS2) && !defined(WIN32) /* OS/2 dosen't support Groups. */ - && (r->finfo.protection & S_IXGRP) + && (r->finfo.protection & APR_GEXECUTE) #endif ) { ap_update_mtime(r, r->finfo.mtime); @@ -2487,7 +2487,7 @@ static int xbithack_handler(request_rec *r) #else enum xbithack *state; - if (!(r->finfo.protection & S_IXUSR)) { + if (!(r->finfo.protection & APR_UEXECUTE)) { return DECLINED; } diff --git a/modules/http/http_request.c b/modules/http/http_request.c index be609b0cc4..bc7594f4d7 100644 --- a/modules/http/http_request.c +++ b/modules/http/http_request.c @@ -76,6 +76,7 @@ #include "http_log.h" #include "http_main.h" #include "util_charset.h" +#include "apr_file_io.h" #include "apr_fnmatch.h" AP_HOOK_STRUCT( @@ -136,13 +137,13 @@ static int check_safe_file(request_rec *r) } -static int check_symlinks(char *d, int opts) +static int check_symlinks(char *d, int opts, ap_pool_t *p) { #if defined(OS2) || defined(WIN32) /* OS/2 doesn't have symlinks */ return OK; #else - struct stat lfi, fi; + ap_finfo_t lfi, fi; char *lastp; int res; @@ -168,7 +169,7 @@ static int check_symlinks(char *d, int opts) else lastp = NULL; - res = lstat(d, &lfi); + res = ap_lstat(&lfi, d, p); if (lastp) *lastp = '/'; @@ -178,7 +179,7 @@ static int check_symlinks(char *d, int opts) * the like may cons up a way to run the transaction anyway)... */ - if (!(res >= 0) || !S_ISLNK(lfi.st_mode)) + if ((res != APR_SUCCESS) || lfi.filetype != APR_LNK) return OK; /* OK, it's a symlink. May still be OK with OPT_SYM_OWNER */ @@ -186,10 +187,10 @@ static int check_symlinks(char *d, int opts) if (!(opts & OPT_SYM_OWNER)) return HTTP_FORBIDDEN; - if (stat(d, &fi) < 0) + if (ap_stat(&fi, d, p) < 0) return HTTP_FORBIDDEN; - return (fi.st_uid == lfi.st_uid) ? OK : HTTP_FORBIDDEN; + return (fi.user == lfi.user) ? OK : HTTP_FORBIDDEN; #endif } @@ -485,7 +486,7 @@ static int directory_walk(request_rec *r) * permissions appropriate to the *parent* directory... */ - if ((res = check_symlinks(test_dirname, core_dir->opts))) { + if ((res = check_symlinks(test_dirname, core_dir->opts, r->pool))) { ap_log_rerror(APLOG_MARK, APLOG_NOERRNO|APLOG_ERR, 0, r, "Symbolic link not allowed: %s", test_dirname); return res; @@ -582,7 +583,7 @@ static int directory_walk(request_rec *r) * you would *not* get the 403. */ if (r->finfo.filetype != APR_DIR - && (res = check_symlinks(r->filename, ap_allow_options(r)))) { + && (res = check_symlinks(r->filename, ap_allow_options(r), r->pool))) { ap_log_rerror(APLOG_MARK, APLOG_NOERRNO|APLOG_ERR, 0, r, "Symbolic link not allowed: %s", r->filename); return res; @@ -893,7 +894,8 @@ API_EXPORT(request_rec *) ap_sub_req_lookup_file(const char *new_file, } } else { - if ((res = check_symlinks(rnew->filename, ap_allow_options(rnew)))) { + if ((res = check_symlinks(rnew->filename, ap_allow_options(rnew), + rnew->pool))) { ap_log_rerror(APLOG_MARK, APLOG_NOERRNO|APLOG_ERR, 0, rnew, "Symbolic link not allowed: %s", rnew->filename); rnew->status = res; diff --git a/modules/mappers/mod_rewrite.c b/modules/mappers/mod_rewrite.c index 697d3f5b26..b993368319 100644 --- a/modules/mappers/mod_rewrite.c +++ b/modules/mappers/mod_rewrite.c @@ -467,7 +467,7 @@ static const char *cmd_rewritemap(cmd_parms *cmd, void *dconf, char *a1, { rewrite_server_conf *sconf; rewritemap_entry *newmap; - struct stat st; + ap_finfo_t st; sconf = (rewrite_server_conf *) ap_get_module_config(cmd->server->module_config, &rewrite_module); @@ -531,7 +531,7 @@ static const char *cmd_rewritemap(cmd_parms *cmd, void *dconf, char *a1, newmap->fpout = NULL; if (newmap->checkfile && (sconf->state == ENGINE_ENABLED) - && (stat(newmap->checkfile, &st) == -1)) { + && (ap_stat(&st, newmap->checkfile, cmd->pool) != APR_SUCCESS)) { return ap_pstrcat(cmd->pool, "RewriteMap: map file or program not found:", newmap->checkfile, NULL); @@ -2182,7 +2182,7 @@ static int apply_rewrite_cond(request_rec *r, rewritecond_entry *p, backrefinfo *briRC) { char input[MAX_STRING_LEN]; - struct stat sb; + ap_finfo_t sb; request_rec *rsub; regmatch_t regmatch[MAX_NMATCH]; int rc; @@ -2208,31 +2208,31 @@ static int apply_rewrite_cond(request_rec *r, rewritecond_entry *p, rc = 0; if (strcmp(p->pattern, "-f") == 0) { - if (stat(input, &sb) == 0) { - if (S_ISREG(sb.st_mode)) { + if (ap_stat(&sb, input, r->pool) == APR_SUCCESS) { + if (sb.filetype == APR_REG) { rc = 1; } } } else if (strcmp(p->pattern, "-s") == 0) { - if (stat(input, &sb) == 0) { - if (S_ISREG(sb.st_mode) && sb.st_size > 0) { + if (ap_stat(&sb, input, r->pool) == APR_SUCCESS) { + if ((sb.filetype == APR_REG) && sb.size > 0) { rc = 1; } } } else if (strcmp(p->pattern, "-l") == 0) { #if !defined(OS2) && !defined(WIN32) - if (lstat(input, &sb) == 0) { - if (S_ISLNK(sb.st_mode)) { + if (ap_lstat(&sb, input, r->pool) == APR_SUCCESS) { + if (sb.filetype == APR_LNK) { rc = 1; } } #endif } else if (strcmp(p->pattern, "-d") == 0) { - if (stat(input, &sb) == 0) { - if (S_ISDIR(sb.st_mode)) { + if (ap_stat(&sb, input, r->pool) == APR_SUCCESS) { + if (sb.filetype == APR_DIR) { rc = 1; } } @@ -2278,7 +2278,7 @@ static int apply_rewrite_cond(request_rec *r, rewritecond_entry *p, /* file exists for any result up to 2xx, no redirects */ if (rsub->status < 300 && /* double-check that file exists since default result is 200 */ - stat(rsub->filename, &sb) == 0) { + ap_stat(&sb, rsub->filename, r->pool) == APR_SUCCESS) { rc = 1; } @@ -2731,7 +2731,7 @@ static char *lookup_map(request_rec *r, char *name, char *key) rewritemap_entry *entries; rewritemap_entry *s; char *value; - struct stat st; + ap_finfo_t st; int i; /* get map configuration */ @@ -2745,7 +2745,7 @@ static char *lookup_map(request_rec *r, char *name, char *key) s = &entries[i]; if (strcmp(s->name, name) == 0) { if (s->type == MAPTYPE_TXT) { - if (stat(s->checkfile, &st) == -1) { + if (ap_stat(&st, s->checkfile, r->pool) != APR_SUCCESS) { ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r, "mod_rewrite: can't access text RewriteMap " "file %s", s->checkfile); @@ -2754,7 +2754,7 @@ static char *lookup_map(request_rec *r, char *name, char *key) return NULL; } value = get_cache_string(cachep, s->name, CACHEMODE_TS, - st.st_mtime, key); + st.mtime, key); if (value == NULL) { rewritelog(r, 6, "cache lookup FAILED, forcing new " "map lookup"); @@ -2763,14 +2763,14 @@ static char *lookup_map(request_rec *r, char *name, char *key) rewritelog(r, 5, "map lookup OK: map=%s key=%s[txt] " "-> val=%s", s->name, key, value); set_cache_string(cachep, s->name, CACHEMODE_TS, - st.st_mtime, key, value); + st.mtime, key, value); return value; } else { rewritelog(r, 5, "map lookup FAILED: map=%s[txt] " "key=%s", s->name, key); set_cache_string(cachep, s->name, CACHEMODE_TS, - st.st_mtime, key, ""); + st.mtime, key, ""); return NULL; } } @@ -2782,7 +2782,7 @@ static char *lookup_map(request_rec *r, char *name, char *key) } else if (s->type == MAPTYPE_DBM) { #ifndef NO_DBM_REWRITEMAP - if (stat(s->checkfile, &st) == -1) { + if (ap_stat(&st, s->checkfile, r->pool) != APR_SUCCESS) { ap_log_rerror(APLOG_MARK, APLOG_ERR, errno, r, "mod_rewrite: can't access DBM RewriteMap " "file %s", s->checkfile); @@ -2791,7 +2791,7 @@ static char *lookup_map(request_rec *r, char *name, char *key) return NULL; } value = get_cache_string(cachep, s->name, CACHEMODE_TS, - st.st_mtime, key); + st.mtime, key); if (value == NULL) { rewritelog(r, 6, "cache lookup FAILED, forcing new map lookup"); @@ -2800,14 +2800,14 @@ static char *lookup_map(request_rec *r, char *name, char *key) rewritelog(r, 5, "map lookup OK: map=%s[dbm] key=%s " "-> val=%s", s->name, key, value); set_cache_string(cachep, s->name, CACHEMODE_TS, - st.st_mtime, key, value); + st.mtime, key, value); return value; } else { rewritelog(r, 5, "map lookup FAILED: map=%s[dbm] " "key=%s", s->name, key); set_cache_string(cachep, s->name, CACHEMODE_TS, - st.st_mtime, key, ""); + st.mtime, key, ""); return NULL; } } @@ -2844,7 +2844,7 @@ static char *lookup_map(request_rec *r, char *name, char *key) } } else if (s->type == MAPTYPE_RND) { - if (stat(s->checkfile, &st) == -1) { + if (ap_stat(&st, s->checkfile, r->pool) == -1) { ap_log_rerror(APLOG_MARK, APLOG_ERR, errno, r, "mod_rewrite: can't access text RewriteMap " "file %s", s->checkfile); @@ -2853,7 +2853,7 @@ static char *lookup_map(request_rec *r, char *name, char *key) return NULL; } value = get_cache_string(cachep, s->name, CACHEMODE_TS, - st.st_mtime, key); + st.mtime, key); if (value == NULL) { rewritelog(r, 6, "cache lookup FAILED, forcing new " "map lookup"); @@ -2862,13 +2862,13 @@ static char *lookup_map(request_rec *r, char *name, char *key) rewritelog(r, 5, "map lookup OK: map=%s key=%s[txt] " "-> val=%s", s->name, key, value); set_cache_string(cachep, s->name, CACHEMODE_TS, - st.st_mtime, key, value); + st.mtime, key, value); } else { rewritelog(r, 5, "map lookup FAILED: map=%s[txt] " "key=%s", s->name, key); set_cache_string(cachep, s->name, CACHEMODE_TS, - st.st_mtime, key, ""); + st.mtime, key, ""); return NULL; } } @@ -3519,7 +3519,7 @@ static char *lookup_variable(request_rec *r, char *var) #ifndef WIN32 struct passwd *pw; struct group *gr; - struct stat finfo; + ap_finfo_t finfo; #endif result = NULL; @@ -3722,8 +3722,8 @@ static char *lookup_variable(request_rec *r, char *var) } } else { - if (stat(r->filename, &finfo) == 0) { - if ((pw = getpwuid(finfo.st_uid)) != NULL) { + if (ap_stat(&finfo, r->filename, r->pool) == APR_SUCCESS) { + if ((pw = getpwuid(finfo.user)) != NULL) { result = pw->pw_name; } } @@ -3737,8 +3737,8 @@ static char *lookup_variable(request_rec *r, char *var) } } else { - if (stat(r->filename, &finfo) == 0) { - if ((gr = getgrgid(finfo.st_gid)) != NULL) { + if (ap_stat(&finfo, r->filename, r->pool) == 0) { + if ((gr = getgrgid(finfo.group)) != NULL) { result = gr->gr_name; } } @@ -4131,7 +4131,7 @@ static void add_env_variable(request_rec *r, char *s) ** */ -static int prefix_stat(const char *path, struct stat *sb) +static int prefix_stat(const char *path, ap_finfo_t *sb) { char curpath[LONG_STRING_LEN]; char *cp; @@ -4143,7 +4143,7 @@ static int prefix_stat(const char *path, struct stat *sb) if ((cp = strchr(curpath+1, '/')) != NULL) { *cp = '\0'; } - if (stat(curpath, sb) == 0) { + if (ap_stat(sb, curpath, NULL) == 0) { return 1; } else { diff --git a/os/win32/os.h b/os/win32/os.h index 9258655c7f..d17e5accdc 100644 --- a/os/win32/os.h +++ b/os/win32/os.h @@ -116,8 +116,6 @@ typedef char * caddr_t; #define HAVE_MEMMOVE -#define HAVE_SYS_STAT_H -#define lstat(x, y) stat(x, y) #define S_ISLNK(m) (0) #define S_ISREG(m) ((m & _S_IFREG) == _S_IFREG) #ifndef S_ISDIR diff --git a/os/win32/util_win32.c b/os/win32/util_win32.c index 330a857369..b4c6d8e3c9 100644 --- a/os/win32/util_win32.c +++ b/os/win32/util_win32.c @@ -59,7 +59,6 @@ #include "httpd.h" #include "http_log.h" -#include #include #include #include diff --git a/server/mpm/dexter/dexter.c b/server/mpm/dexter/dexter.c index 9b77058676..7ccec22108 100644 --- a/server/mpm/dexter/dexter.c +++ b/server/mpm/dexter/dexter.c @@ -1434,7 +1434,8 @@ static const char *set_coredumpdir (cmd_parms *cmd, void *dummy, char *arg) } fname = ap_server_root_relative(cmd->pool, arg); - if ((stat(fname, &finfo) == -1) || !S_ISDIR(finfo.st_mode)) { + if ((ap_stat(&finfo, fname, cmd->pool) != APR_SUCCESS) || + (finfo.filetype != APR_DIR)) { return ap_pstrcat(cmd->pool, "CoreDumpDirectory ", fname, " does not exist or is not a directory", NULL); } diff --git a/server/mpm/mpmt_beos/mpmt_beos.c b/server/mpm/mpmt_beos/mpmt_beos.c index 2e8229c5a0..a32415fa1c 100644 --- a/server/mpm/mpmt_beos/mpmt_beos.c +++ b/server/mpm/mpmt_beos/mpmt_beos.c @@ -1106,7 +1106,8 @@ static const char *set_coredumpdir (cmd_parms *cmd, void *dummy, char *arg) } fname = ap_server_root_relative(cmd->pool, arg); - if ((stat(fname, &finfo) == -1) || !S_ISDIR(finfo.st_mode)) { + if ((ap_stat(&finfo, fname, cmd->pool) != APR_SUCCESS) || + (finfo.filetype != APR_DIR)) { return ap_pstrcat(cmd->pool, "CoreDumpDirectory ", fname, " does not exist or is not a directory", NULL); } diff --git a/server/mpm/mpmt_beos/poll.c b/server/mpm/mpmt_beos/poll.c index a8c471e2db..c6b6942b22 100644 --- a/server/mpm/mpmt_beos/poll.c +++ b/server/mpm/mpmt_beos/poll.c @@ -30,7 +30,6 @@ #include #include -#include #include #include #include diff --git a/server/mpm/mpmt_pthread/mpmt_pthread.c b/server/mpm/mpmt_pthread/mpmt_pthread.c index 94bbed9c2c..bc104818fe 100644 --- a/server/mpm/mpmt_pthread/mpmt_pthread.c +++ b/server/mpm/mpmt_pthread/mpmt_pthread.c @@ -1439,7 +1439,8 @@ static const char *set_coredumpdir (cmd_parms *cmd, void *dummy, char *arg) } fname = ap_server_root_relative(cmd->pool, arg); - if ((stat(fname, &finfo) == -1) || !S_ISDIR(finfo.st_mode)) { + if ((ap_stat(&finfofname, cmd->pool) != APR_SUCCESS) || + (finfo.filetype != APR_DIR)) { return ap_pstrcat(cmd->pool, "CoreDumpDirectory ", fname, " does not exist or is not a directory", NULL); } diff --git a/server/mpm/prefork/prefork.c b/server/mpm/prefork/prefork.c index 77fec0bfaf..7e21d6c42d 100644 --- a/server/mpm/prefork/prefork.c +++ b/server/mpm/prefork/prefork.c @@ -1744,7 +1744,7 @@ static const char *set_max_requests(cmd_parms *cmd, void *dummy, char *arg) static const char *set_coredumpdir (cmd_parms *cmd, void *dummy, char *arg) { - struct stat finfo; + ap_finfo_t finfo; const char *fname; const char *err = ap_check_cmd_context(cmd, GLOBAL_ONLY); if (err != NULL) { @@ -1752,7 +1752,8 @@ static const char *set_coredumpdir (cmd_parms *cmd, void *dummy, char *arg) } fname = ap_server_root_relative(cmd->pool, arg); - if ((stat(fname, &finfo) == -1) || !S_ISDIR(finfo.st_mode)) { + if ((ap_stat(&finfo, fname, cmd->pool) != APR_SUCCESS) || + (finfo.filetype != APR_DIR)) { return ap_pstrcat(cmd->pool, "CoreDumpDirectory ", fname, " does not exist or is not a directory", NULL); } diff --git a/server/mpm/spmt_os2/spmt_os2.c b/server/mpm/spmt_os2/spmt_os2.c index 36fcf60ecf..a54b146cfb 100644 --- a/server/mpm/spmt_os2/spmt_os2.c +++ b/server/mpm/spmt_os2/spmt_os2.c @@ -1608,7 +1608,8 @@ static const char *set_coredumpdir (cmd_parms *cmd, void *dummy, char *arg) } fname = ap_server_root_relative(cmd->pool, arg); - if ((stat(fname, &finfo) == -1) || !S_ISDIR(finfo.st_mode)) { + if ((ap_stat(&finfo, fname, cmd->pool) != APR_SUCCESS) || + (finfo.filetype != APR_DIR)) { return ap_pstrcat(cmd->pool, "CoreDumpDirectory ", fname, " does not exist or is not a directory", NULL); } diff --git a/server/mpm/winnt/mpm_winnt.c b/server/mpm/winnt/mpm_winnt.c index 288d29abf4..fa67a23358 100644 --- a/server/mpm/winnt/mpm_winnt.c +++ b/server/mpm/winnt/mpm_winnt.c @@ -2243,7 +2243,8 @@ static const char *set_coredumpdir (cmd_parms *cmd, void *dummy, char *arg) } fname = ap_server_root_relative(cmd->pool, arg); - if ((stat(fname, &finfo) == -1) || !S_ISDIR(finfo.st_mode)) { + if ((ap_stat(&finfo, fname, cmd->pool) != APR_SUCCESS) || + (finfo.filetype != APR_DIR)) { return ap_pstrcat(cmd->pool, "CoreDumpDirectory ", fname, " does not exist or is not a directory", NULL); } diff --git a/server/util.c b/server/util.c index 22c4f76cf7..0ae566addb 100644 --- a/server/util.c +++ b/server/util.c @@ -1648,12 +1648,12 @@ API_EXPORT(char *) ap_escape_html(ap_pool_t *p, const char *s) API_EXPORT(int) ap_is_directory(const char *path) { - struct stat finfo; + ap_finfo_t finfo; - if (stat(path, &finfo) == -1) + if (ap_stat(&finfo, path, NULL) == -1) return 0; /* in error condition, just return no */ - return (S_ISDIR(finfo.st_mode)); + return (finfo.filetype == APR_DIR); } API_EXPORT(char *) ap_make_full_path(ap_pool_t *a, const char *src1, diff --git a/support/htpasswd.c b/support/htpasswd.c index a31f6fa154..be7e95f459 100644 --- a/support/htpasswd.c +++ b/support/htpasswd.c @@ -332,18 +332,10 @@ static int writable(char *fname) */ static int exists(char *fname) { -#ifdef WIN32 - struct _stat sbuf; -#else - struct stat sbuf; -#endif + ap_finfo_t sbuf; int check; -#ifdef WIN32 - check = _stat(fname, &sbuf); -#else - check = stat(fname, &sbuf); -#endif + check = ap_stat(&sbuf, fname, NULL); return ((check == -1) && (errno == ENOENT)) ? 0 : 1; } -- 2.50.1