httpd-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From n.@apache.org
Subject cvs commit: apache-1.3/src/modules/standard mod_rewrite.c mod_rewrite.h
Date Wed, 02 Apr 2003 21:01:09 GMT
nd          2003/04/02 13:01:09

  Modified:    src/modules/standard mod_rewrite.c mod_rewrite.h
  Log:
  Fix the prefix_stat function. (which does a stat call on the first
  path segment). This function was still tailored for unix systems only.
  It should work on other systems as well now.
  
  Note that in 2.x we use the apr_filepath_root function that doesn't
  exist in 1.3. It is replaced by some simple workaround stuff which
  behaves similar.
  
  Obtained from: 2.1 (r1.143)
  Reviewed by: Brad Nicholes, Will Rowe
  
  Revision  Changes    Path
  1.185     +55 -12    apache-1.3/src/modules/standard/mod_rewrite.c
  
  Index: mod_rewrite.c
  ===================================================================
  RCS file: /home/cvs/apache-1.3/src/modules/standard/mod_rewrite.c,v
  retrieving revision 1.184
  retrieving revision 1.185
  diff -u -r1.184 -r1.185
  --- mod_rewrite.c	2 Apr 2003 20:54:09 -0000	1.184
  +++ mod_rewrite.c	2 Apr 2003 21:01:09 -0000	1.185
  @@ -1039,7 +1039,6 @@
       char docroot[512];
       char *cp, *cp2;
       const char *ccp;
  -    struct stat finfo;
       unsigned int port;
       int rulestatus;
       int n;
  @@ -1271,7 +1270,7 @@
                * because we only do stat() on the first directory
                * and this gets cached by the kernel for along time!
                */
  -            n = prefix_stat(r->filename, &finfo);
  +            n = prefix_stat(r->filename, r->pool);
               if (n == 0) {
                   if ((ccp = ap_document_root(r)) != NULL) {
                       l = ap_cpystrn(docroot, ccp, sizeof(docroot)) - docroot;
  @@ -4164,24 +4163,68 @@
   **
   */
   
  -static int prefix_stat(const char *path, struct stat *sb)
  +static int prefix_stat(const char *path, ap_pool *pool)
   {
  -    char curpath[LONG_STRING_LEN];
  -    char *cp;
  +    const char *curpath = path;
  +    char *root;
  +    char *slash;
  +    char *statpath;
  +    struct stat sb;
   
  -    ap_cpystrn(curpath, path, sizeof(curpath));
  -    if (curpath[0] != '/') {
  +    if (!ap_os_is_path_absolute(curpath)) {
           return 0;
       }
  -    if ((cp = strchr(curpath+1, '/')) != NULL) {
  -        *cp = '\0';
  +
  +    /* need to be a bit tricky here.
  +     * Actually we're looking for the first path segment ...
  +     */
  +    if (*curpath != '/') {
  +        /* be safe: +1 = '\0'; +1 = possible additional '\0'
  +         * from ap_make_dirstr_prefix
  +         */
  +        root = ap_palloc(pool, strlen(curpath) + 2);
  +        slash = ap_make_dirstr_prefix(root, curpath, 1);
  +        curpath += strlen(root);
       }
  -    if (stat(curpath, sb) == 0) {
  -        return 1;
  +    else {
  +#if defined(HAVE_UNC_PATHS)
  +    /* Check for UNC names. */
  +        if (curpath[1] == '/') {
  +            slash = strchr(curpath + 2, '/');
  +
  +            /* XXX not sure here. Be safe for now */
  +            if (!slash) {
  +                return 0;
  +            }
  +            root = ap_pstrndup(pool, curpath, slash - curpath + 1);
  +            curpath += strlen(root);
  +        }
  +        else {
  +#endif /* UNC */
  +            root = "/";
  +            ++curpath;
  +#if defined(HAVE_UNC_PATHS)
  +        }
  +#endif
  +    }
  +
  +    /* let's recognize slashes only, the mod_rewrite semantics are opaque
  +     * enough.
  +     */
  +    if ((slash = strchr(curpath, '/')) != NULL) {
  +        statpath = ap_pstrcat(pool, root,
  +                              ap_pstrndup(pool, curpath, slash - curpath),
  +                              NULL);
       }
       else {
  -        return 0;
  +        statpath = ap_pstrcat(pool, root, curpath, NULL);
       }
  +
  +    if (stat(statpath, &sb) == 0) {
  +        return 1;
  +    }
  +
  +    return 0;
   }
   
   
  
  
  
  1.85      +1 -1      apache-1.3/src/modules/standard/mod_rewrite.h
  
  Index: mod_rewrite.h
  ===================================================================
  RCS file: /home/cvs/apache-1.3/src/modules/standard/mod_rewrite.h,v
  retrieving revision 1.84
  retrieving revision 1.85
  diff -u -r1.84 -r1.85
  --- mod_rewrite.h	19 Mar 2003 14:01:08 -0000	1.84
  +++ mod_rewrite.h	2 Apr 2003 21:01:09 -0000	1.85
  @@ -496,7 +496,7 @@
   static char  *subst_prefix_path(request_rec *r, char *input, char *match,
                                   char *subst);
   static int    parseargline(char *str, char **a1, char **a2, char **a3);
  -static int    prefix_stat(const char *path, struct stat *sb);
  +static int    prefix_stat(const char *path, ap_pool *pool);
   static void   add_env_variable(request_rec *r, char *s);
   static int    subreq_ok(request_rec *r);
   static int    is_redirect_limit_exceeded(request_rec *r);
  
  
  

Mime
View raw message