#include "http_log.h"
#include "http_main.h"
#include "util_charset.h"
+#include "apr_file_io.h"
#include "apr_fnmatch.h"
AP_HOOK_STRUCT(
}
-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;
else
lastp = NULL;
- res = lstat(d, &lfi);
+ res = ap_lstat(&lfi, d, p);
if (lastp)
*lastp = '/';
* 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 */
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
}
* 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;
* 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;
}
}
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;
{
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);
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);
backrefinfo *briRC)
{
char input[MAX_STRING_LEN];
- struct stat sb;
+ ap_finfo_t sb;
request_rec *rsub;
regmatch_t regmatch[MAX_NMATCH];
int rc;
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;
}
}
/* 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;
}
rewritemap_entry *entries;
rewritemap_entry *s;
char *value;
- struct stat st;
+ ap_finfo_t st;
int i;
/* get map configuration */
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);
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");
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;
}
}
}
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);
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");
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;
}
}
}
}
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);
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");
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;
}
}
#ifndef WIN32
struct passwd *pw;
struct group *gr;
- struct stat finfo;
+ ap_finfo_t finfo;
#endif
result = NULL;
}
}
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;
}
}
}
}
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;
}
}
**
*/
-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;
if ((cp = strchr(curpath+1, '/')) != NULL) {
*cp = '\0';
}
- if (stat(curpath, sb) == 0) {
+ if (ap_stat(sb, curpath, NULL) == 0) {
return 1;
}
else {