httpd-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From wr...@locus.apache.org
Subject cvs commit: apache-2.0/src/lib/apr/misc/win32 names.c
Date Mon, 23 Oct 2000 17:21:15 GMT
wrowe       00/10/23 10:21:15

  Modified:    src/lib/apr aprlib.def
               src/lib/apr/file_io/unix fileio.h
               src/lib/apr/file_io/win32 dir.c filedup.c fileio.h open.c
               src/lib/apr/include apr_file_io.h
               src/lib/apr/misc/win32 names.c
  Log:
    The start of the canonical name stuff.
  
       * removed cruft that did nothing (yet)
       * add prototypes for the apr_canon... fn's
       * Consider:  apr_compare_canonical (need to count matching elements)
       * Consider:  Manoj's suggestion to handle symlinks within here.
       * Consider:  fanf's concept to use dev/inode for comparison w/o strs.
  
  Revision  Changes    Path
  1.36      +2 -2      apache-2.0/src/lib/apr/aprlib.def
  
  Index: aprlib.def
  ===================================================================
  RCS file: /home/cvs/apache-2.0/src/lib/apr/aprlib.def,v
  retrieving revision 1.35
  retrieving revision 1.36
  diff -u -r1.35 -r1.36
  --- aprlib.def	2000/10/11 07:54:31	1.35
  +++ aprlib.def	2000/10/23 17:21:10	1.36
  @@ -117,8 +117,8 @@
   ;
   	apr_get_os_thread   @110
   	apr_get_os_threadkey   @111
  -	apr_os_systemcase_filename   @112
  -	canonical_filename   @113
  +
  +
   	apr_create_pool   @114
   ;
   ;
  
  
  
  1.27      +17 -0     apache-2.0/src/lib/apr/file_io/unix/fileio.h
  
  Index: fileio.h
  ===================================================================
  RCS file: /home/cvs/apache-2.0/src/lib/apr/file_io/unix/fileio.h,v
  retrieving revision 1.26
  retrieving revision 1.27
  diff -u -r1.26 -r1.27
  --- fileio.h	2000/08/02 05:25:51	1.26
  +++ fileio.h	2000/10/23 17:21:11	1.27
  @@ -58,6 +58,7 @@
   #include "apr.h"
   #include "apr_private.h"
   #include "apr_general.h"
  +#include "apr_tables.h"
   #include "apr_file_io.h"
   #include "apr_errno.h"
   #include "apr_lib.h"
  @@ -111,6 +112,22 @@
   /* End System headers */
   
   #define APR_FILE_BUFSIZE 4096
  +
  +typedef struct apr_canon_elem_t {
  +/* A possible comparison mechanism to play with once we start
  + * implementing case insensitive mount poinbt semantices
  + *  int dev;
  + *  int inode;
  + *  apr_time_t cached;  --for timeout?
  + */
  +    int pathlen;
  +    char *element;
  +} apr_canon_elem_t;
  +
  +struct apr_canon_t {
  +    apr_pool_t *cntxt;
  +    apr_array_header_t *elems;
  +};
   
   struct apr_file_t {
       apr_pool_t *cntxt;
  
  
  
  1.28      +2 -5      apache-2.0/src/lib/apr/file_io/win32/dir.c
  
  Index: dir.c
  ===================================================================
  RCS file: /home/cvs/apache-2.0/src/lib/apr/file_io/win32/dir.c,v
  retrieving revision 1.27
  retrieving revision 1.28
  diff -u -r1.27 -r1.28
  --- dir.c	2000/10/06 17:24:38	1.27
  +++ dir.c	2000/10/23 17:21:11	1.28
  @@ -83,12 +83,10 @@
   
   apr_status_t apr_opendir(apr_dir_t **new, const char *dirname, apr_pool_t *cont)
   {
  -    char * temp;
       (*new) = apr_pcalloc(cont, sizeof(apr_dir_t));
       (*new)->cntxt = cont;
       (*new)->entry = NULL;
  -    temp = canonical_filename((*new)->cntxt, dirname);
  -    if (temp[strlen(temp)] == '/') {
  +    if (dirname[strlen(dirname)] == '/') {
       	(*new)->dirname = apr_pstrcat(cont, dirname, "*", NULL);
       }
       else {
  @@ -153,8 +151,7 @@
   
   apr_status_t apr_remove_dir(const char *path, apr_pool_t *cont)
   {
  -    char *temp = canonical_filename(cont, path);
  -    if (!RemoveDirectory(temp)) {
  +    if (!RemoveDirectory(path)) {
           return apr_get_os_error();
       }
       return APR_SUCCESS;
  
  
  
  1.22      +7 -5      apache-2.0/src/lib/apr/file_io/win32/filedup.c
  
  Index: filedup.c
  ===================================================================
  RCS file: /home/cvs/apache-2.0/src/lib/apr/file_io/win32/filedup.c,v
  retrieving revision 1.21
  retrieving revision 1.22
  diff -u -r1.21 -r1.22
  --- filedup.c	2000/10/06 17:24:38	1.21
  +++ filedup.c	2000/10/23 17:21:11	1.22
  @@ -105,12 +105,14 @@
   
       (*new_file)->cntxt = old_file->cntxt;
       (*new_file)->fname = apr_pstrdup(old_file->cntxt, old_file->fname);
  -    (*new_file)->demonfname = apr_pstrdup(old_file->cntxt, old_file->demonfname);
  -    (*new_file)->lowerdemonfname = apr_pstrdup(old_file->cntxt, old_file->lowerdemonfname);
  +/*    (*new_file)->demonfname = apr_pstrdup(old_file->cntxt, old_file->demonfname);
  + *    (*new_file)->lowerdemonfname = apr_pstrdup(old_file->cntxt, old_file->lowerdemonfname);
  + */
       (*new_file)->append = old_file->append;
  -/*   (*new_file)->protection = old_file->protection;
  -    (*new_file)->user = old_file->user;
  -    (*new_file)->group = old_file->group;*/
  +/*    (*new_file)->protection = old_file->protection;
  + *    (*new_file)->user = old_file->user;
  + *    (*new_file)->group = old_file->group;
  + */
       (*new_file)->size = old_file->size;
       (*new_file)->atime = old_file->atime;    
       (*new_file)->mtime = old_file->mtime;
  
  
  
  1.32      +35 -7     apache-2.0/src/lib/apr/file_io/win32/fileio.h
  
  Index: fileio.h
  ===================================================================
  RCS file: /home/cvs/apache-2.0/src/lib/apr/file_io/win32/fileio.h,v
  retrieving revision 1.31
  retrieving revision 1.32
  diff -u -r1.31 -r1.32
  --- fileio.h	2000/10/16 06:04:40	1.31
  +++ fileio.h	2000/10/23 17:21:11	1.32
  @@ -59,6 +59,7 @@
   #include "apr_private.h"
   #include "apr_pools.h"
   #include "apr_general.h"
  +#include "apr_tables.h"
   #include "apr_lock.h"
   #include "apr_file_io.h"
   #include "apr_errno.h"
  @@ -88,6 +89,34 @@
   
   #define APR_FILE_BUFSIZE 4096
   
  +typedef enum apr_canon_case_e {
  +    APR_CANON_CASE_GIVEN,
  +    APR_CANON_CASE_LOWER,
  +    APR_CANON_CASE_TRUE
  +} apr_canon_case_e;
  +
  +/*
  + * Internal canonical filename elements for the apr_canon_t elems
  + *  ccase   tracks the mechanism used to resolve this element
  + *  pathlen is the full path length to the end of this element
  + *  name    slash is prefix, as appropriate 
  +               
  + */
  +typedef struct apr_canon_elem_t {
  +    apr_canon_case_e ccase;
  +    int pathlen;
  +    char *name;
  +} apr_canon_elem_t;
  +
  +/* warning: win32 canonical path "/" resolves to a
  + * zero'th element of the empty string for testing the
  + * psudo-root for the system
  + */
  +struct apr_canon_t {
  +    apr_pool_t *cntxt;
  +    apr_array_header_t *elems;
  +};
  +
   /* quick run-down of fields in windows' apr_file_t structure that may have 
    * obvious uses.
    * fname --  the filename as passed to the open call.
  @@ -110,8 +139,8 @@
   
       /* File specific info */
       char *fname;
  -    char *demonfname; 
  -    char *lowerdemonfname; 
  +    apr_canon_t *canonname;
  +    
       DWORD dwFileAttributes;
       int eof_hit;
       BOOLEAN buffered;          // Use buffered I/O?
  @@ -142,12 +171,11 @@
   };
   
   apr_status_t file_cleanup(void *);
  -/*mode_t get_fileperms(apr_fileperms_t);
  -*/
  -APR_DECLARE(char *) apr_os_systemcase_filename(struct apr_pool_t *pCont, 
  -                                              const char *szFile);
  -char * canonical_filename(struct apr_pool_t *pCont, const char *szFile);
   
  +/**
  + * Internal function to create a Win32/NT pipe that respects some async
  + * timeout options.
  + */
   apr_status_t apr_create_nt_pipe(apr_file_t **in, apr_file_t **out, 
                                   BOOLEAN bAsyncRead, BOOLEAN bAsyncWrite, 
                                   apr_pool_t *p);
  
  
  
  1.51      +5 -30     apache-2.0/src/lib/apr/file_io/win32/open.c
  
  Index: open.c
  ===================================================================
  RCS file: /home/cvs/apache-2.0/src/lib/apr/file_io/win32/open.c,v
  retrieving revision 1.50
  retrieving revision 1.51
  diff -u -r1.50 -r1.51
  --- open.c	2000/10/06 22:50:54	1.50
  +++ open.c	2000/10/23 17:21:11	1.51
  @@ -111,9 +111,6 @@
   
       (*new)->fname = apr_pstrdup(cont, fname);
   
  -    (*new)->demonfname = canonical_filename((*new)->cntxt, fname);
  -    (*new)->lowerdemonfname = strlwr((*new)->demonfname);
  - 
       if (apr_get_oslevel(cont, &level) == APR_SUCCESS && level >= APR_WIN_NT)
{
           sharemode |= FILE_SHARE_DELETE;
       }
  @@ -196,40 +193,18 @@
   
   apr_status_t apr_remove_file(const char *path, apr_pool_t *cont)
   {
  -    char *temp = canonical_filename(cont, path);
  -
  -    if (DeleteFile(temp)) {
  +    if (DeleteFile(path))
           return APR_SUCCESS;
  -    }
  -    else {
  -        return apr_get_os_error();
  -    }
  +    return apr_get_os_error();
   }
   
   apr_status_t apr_rename_file(const char *from_path, const char *to_path,
                              apr_pool_t *p)
   {
  -    const char *from_canon = canonical_filename(p, from_path);
  -    const char *to_canon = canonical_filename(p, to_path);
  -    DWORD err;
  -
  -    /* TODO: would be nice to use MoveFileEx() here, but it isn't available
  -     * on Win95/98. MoveFileEx could theoretically help prevent the
  -     * case where we delete the target but don't move the file(!).
  -     * it can also copy across devices...
  -     */
  -
  -    if (MoveFile(from_canon, to_canon)) {
  +    if (MoveFileEx(from_path, to_path, MOVEFILE_REPLACE_EXISTING |
  +                                        MOVEFILE_COPY_ALLOWED))
           return APR_SUCCESS;
  -    }
  -    err = apr_get_os_error();
  -    if (APR_STATUS_IS_EEXIST(err)) {
  -        (void) DeleteFile(to_canon);
  -        if (MoveFile(from_canon, to_canon))
  -            return APR_SUCCESS;
  -        err = apr_get_os_error();
  -    }
  -    return err;
  +    return apr_get_os_error();
   }
   
   apr_status_t apr_get_os_file(apr_os_file_t *thefile, apr_file_t *file)
  
  
  
  1.68      +113 -2    apache-2.0/src/lib/apr/include/apr_file_io.h
  
  Index: apr_file_io.h
  ===================================================================
  RCS file: /home/cvs/apache-2.0/src/lib/apr/include/apr_file_io.h,v
  retrieving revision 1.67
  retrieving revision 1.68
  diff -u -r1.67 -r1.68
  --- apr_file_io.h	2000/10/18 02:44:50	1.67
  +++ apr_file_io.h	2000/10/23 17:21:13	1.68
  @@ -119,6 +119,7 @@
   typedef struct apr_file_t         apr_file_t;
   typedef struct apr_finfo_t        apr_finfo_t;
   typedef struct apr_dir_t          apr_dir_t;
  +typedef struct apr_canon_t        apr_canon_t;
   typedef apr_int32_t               apr_fileperms_t;
   typedef uid_t                    apr_uid_t;
   typedef gid_t                    apr_gid_t;
  @@ -156,9 +157,119 @@
       apr_time_t ctime;
   };
   
  -/*   Function definitions */
  +/*   Make and Merge Canonical Name Options */
   
   /**
  + * Require the trusted_name+child_name result is an absolute product 
  + * or fail with error for the make and merge canonical name functions.
  + */
  +#define APR_CANON_ONLY_ABSOLUTE   0
  +/**
  + * Allow that the trusted_name+child_name result may be a relative result
  + * for the make and merge canonical name functions.
  + */
  +#define APR_CANON_ALLOW_RELATIVE  2
  +
  +/**
  + * Require the trusted_name+child_name result is not an absolute path
  + * or fail with error for the make and merge canonical name functions.
  + */
  +#define APR_CANON_ONLY_RELATIVE   3
  +
  +/**
  + * Require the trusted_name+child_name result is a child of trusted_name 
  + * or fail with error for the make and merge canonical name functions.
  + */
  +#define APR_CANON_CHILD_OF_TRUSTED  4
  +
  +/**
  + * If file path elements exist (can stat) then fold the element's name 
  + * to lowercase for the make and merge canonical name functions.
  + */
  +#define APR_CANON_LOWERCASE 
  +
  +/**
  + * If file path elements exist (can readdir) then fold the element's name 
  + * to the true case lowercase for the make and merge canonical name functions.
  + */
  +#define APR_CANON_TRUECASE 
  +
  +/**
  + * Canonicalize the path and name.
  + *
  + * @param new_name The newly allocated canonicalized trusted+child name
  + * @param trusted_name Already canonical parent path; may be NULL.
  + * @param child_name An absolute path or path relative to trusted_name.
  + * @param options See the APR_CANON_ bit flags documentation for options
  + * @param pool The context in which to allocate the new_name apr_canon_t
  + *
  + * @tip A canonical name is a name stipped of embedded backrefs "../", 
  + * thisrefs "./", successive slashes (//), or any other ambigious file
  + * name element.  Absolute canonical names referencing the same file must 
  + * strcmp() identically, excluding symlinks or inconsistent use of the
  + * APR_CANON_LOWERCASE or APR_CANON_TRUECASE options.
  + * 
  + * If the name does not exist, or resolves to a relative name the given case
  + * is preserved.  Insignificant elements are eliminated.  For example, on Win32 this 
  + * function removes trailing dots (which are allowed, but not stored in 
  + * the file system), and "/../" under Unix is resolved to "/".  The relative 
  + * canonical name may contain leading backrefs "../", but will never contain 
  + * any other prohibited element.
  + */
  +
  +/*
  + * @param trusted_name May be null
  + * @param child_name May be absolute, in which case trusted_name is ignored
  + * unless APR_CHILD_RELATIVE is tested.
  + */
  +
  +apr_status_t apr_make_canonical_name(apr_canon_t **new_name, 
  +                                     const apr_canon_t *trusted_name, 
  +                                     const char *child_name, 
  +                                     int options,
  +                                     apr_pool_t *pool);
  +
  +apr_status_t apr_merge_canonical_name(apr_canon_t **new_name,
  +                                      const apr_canon_t *trusted_name,
  +                                      const apr_canon_t *child_name,
  +                                      int options,
  +                                      apr_pool_t *pool);
  +
  +apr_status_t apr_get_canonical_name(char **path, 
  +                                    const apr_canon_t *trusted_name, 
  +                                    apr_pool_t *pool);
  +
  +int apr_count_canonical_elements(const apr_canon_t *trusted_name);
  +
  +int apr_get_canonical_elements_length(const apr_canon_t *trusted_name,
  +                                      int firstelement, int lastelement);
  +
  +apr_status_t apr_get_canonical_elements(char **path_elements,
  +                                        const apr_canon_t *trusted_name,
  +                                        int firstelement, int lastelement,
  +                                        apr_pool_t *pool);
  +
  +/**
  + *  Returns APR_SUCCESS if canon_name is absolute.  Do not trust
  + *  !apr_is_absolute to determine if the path is relative.  Also,
  + *  test apr_is_virtualroot to avoid non-filesystem pseudo roots.
  + */
  +apr_status_t apr_is_absolute(apr_canon_t **path);
  +
  +/**
  + *  Returns APR_SUCCESS if canon_name is absolute.  Do not trust
  + *  !apr_is_relative to determine if the path is absolute.
  + */
  +apr_status_t apr_is_relative(apr_canon_t **path);
  +
  +/**
  + *  Returns APR_SUCCESS if the elements 0..elements resolves to a
  + *  platform's non-physical root, e.g. the //machine/ name that 
  + *  isn't an adaquately complete root for UNC paths.
  + */
  +apr_status_t apr_is_virtualroot(apr_canon_t **path, int elements);
  +
  +/**
    * Open the specified file.
    * @param new_file The opened file descriptor.
    * @param fname The full path to the file (using / on all systems)
  @@ -207,7 +318,7 @@
    *      Moving files or directories across devices may not be possible.
    */
   apr_status_t apr_rename_file(const char *from_path, const char *to_path,
  -                           apr_pool_t *pool);
  +                             apr_pool_t *pool);
   
   /**
    * Are we at the end of the file
  
  
  
  1.17      +2 -2      apache-2.0/src/lib/apr/misc/win32/names.c
  
  Index: names.c
  ===================================================================
  RCS file: /home/cvs/apache-2.0/src/lib/apr/misc/win32/names.c,v
  retrieving revision 1.16
  retrieving revision 1.17
  diff -u -r1.16 -r1.17
  --- names.c	2000/10/16 06:04:47	1.16
  +++ names.c	2000/10/23 17:21:14	1.17
  @@ -82,8 +82,8 @@
    * is present on the existing path.  This routine also
    * converts alias names to long names.
    */
  -APR_DECLARE(char *) apr_os_systemcase_filename(apr_pool_t *pCont, 
  -                                             const char *szFile)
  +static char * apr_os_systemcase_filename(apr_pool_t *pCont, 
  +                                         const char *szFile)
   {
       char buf[HUGE_STRING_LEN];
       char *pInputName;
  
  
  

Mime
View raw message