Roxen.git / server / modules / filesystems / filesystem.pike

version» Context lines:

Roxen.git/server/modules/filesystems/filesystem.pike:1:   // This is a roxen module. Copyright © 1996 - 2004, Roxen IS.      // This is a virtual "file-system".   // It will be located somewhere in the name-space of the server.   // Also inherited by some of the other filesystems.      inherit "module";   inherit "socket";    - constant cvs_version= "$Id: filesystem.pike,v 1.158 2009/03/04 13:07:04 grubba Exp $"; + constant cvs_version= "$Id$";   constant thread_safe=1;      #include <module.h>   #include <roxen.h>   #include <stat.h>   #include <request_trace.h>         //<locale-token project="mod_filesystem">LOCALE</locale-token>   #define LOCALE(X,Y) _DEF_LOCALE("mod_filesystem",X,Y)
Roxen.git/server/modules/filesystems/filesystem.pike:387:    if (FILTER_INTERNAL_FILE (f, id))    return 0;       if(stat_cache && !id->pragma["no-cache"] &&    (fs=cache_lookup("stat_cache",f)))    return fs[0];    object privs;    SETUID_NT("Statting file");       /* No security currently in this function */ -  fs = file_stat(decode_path(f)); +  fs = file_stat(encode_path(f));    privs = 0;    if(!stat_cache) return fs;    cache_set("stat_cache", f, ({fs}));    return fs;   }    - string decode_path( string p ) + //! Convert to filesystem encoding. + //! + //! @note + //! Note that the @expr{"iso-8859-1"@} encoding will perform + //! conversion to utf-8 for wide strings OSes other than NT. + string encode_path( string p )   {    if( path_encoding != "iso-8859-1" )    p = Locale.Charset.encoder( path_encoding )->feed( p )->drain();   #ifndef __NT__    if( String.width( p ) != 8 )    p = string_to_utf8( p );   #else    while( strlen(p) && p[-1] == '/' )    p = p[..strlen(p)-2];   #endif    return p;   }      string real_path(string f, RequestID id)   {    f = normalized_path + f;    if (FILTER_INTERNAL_FILE(f, id)) return 0;    catch { -  f = NORMALIZE_PATH(decode_path(f)); +  f = NORMALIZE_PATH(encode_path(f));    if (has_prefix(f, normalized_path) ||   #ifdef __NT__    (f+"\\" == normalized_path)   #else /* !__NT__ */    (f+"/" == normalized_path)   #endif /* __NT__ */    ) {    return f;    }    };
Roxen.git/server/modules/filesystems/filesystem.pike:505:   {    array dir;       FILESYSTEM_WERR("find_dir for \""+f+"\"" +    (id->misc->internal_get ? " (internal)" : ""));       object privs;    SETUID_NT("Read dir");       if (catch { -  f = NORMALIZE_PATH(decode_path(path + f)); +  f = NORMALIZE_PATH(encode_path(path + f));    } || !(dir = get_dir(f))) {    privs = 0;    return 0;    }    privs = 0;       if(!query("dir"))    // Access to this dir is allowed.    if(! has_value(dir, ".www_browsable"))    {
Roxen.git/server/modules/filesystems/filesystem.pike:697:    if( stat_cache )    {    array(Stat) cached_fs;    if(!id->pragma["no-cache"] &&    (cached_fs = cache_lookup("stat_cache", X)))    {    id->misc->stat = cached_fs[0];    return cached_fs[0] ? cached_fs[0][ST_SIZE] : -1;    }    } -  if(fs = file_stat(decode_path(X))) +  if(fs = file_stat(encode_path(X)))    {    id->misc->stat = fs;    if( stat_cache ) cache_set("stat_cache",(X),({fs}));    return fs[ST_SIZE];    } else if( stat_cache )    cache_set("stat_cache",(X),({0}));    return -1;   }      int contains_symlinks(string root, string path)   {    foreach(path/"/" - ({ "" }), path) {    root += "/" + path;    Stat rr; -  if (rr = file_stat(decode_path(root), 1)) { +  if (rr = file_stat(encode_path(root), 1)) {    if (rr[1] == -3) {    return(1);    }    } else {    return(0);    }    }    return(0);   }   
Roxen.git/server/modules/filesystems/filesystem.pike:834:       /* only used for the quota system, thus rather unessesary to do for    each request....    */   #define URI combine_path(mountpoint + "/" + oldf, ".")       string norm_f;       catch {    /* NOTE: NORMALIZE_PATH() may throw errors. */ -  f = norm_f = NORMALIZE_PATH(f = decode_path(path + f)); +  f = norm_f = NORMALIZE_PATH(f = encode_path(path + f));   #if constant(System.normalize_path)    if (!has_prefix(norm_f, normalized_path) &&   #ifdef __NT__    (norm_f+"\\" != normalized_path)   #else /* !__NT__ */    (norm_f+"/" != normalized_path)   #endif /* __NT__ */    ) {    errors++;    report_error(LOCALE(52, "Path verification of %O failed:\n"
Roxen.git/server/modules/filesystems/filesystem.pike:1405:    set_status_for_path (new_uri, res->error, res->rettext);    return ([]);    }    } else {    privs = 0;    TRACE_LEAVE("MOVE: Cannot overwrite directory");    return Roxen.http_status(412);    }    }    -  code = mv(f, decode_path(moveto)); +  code = mv(f, encode_path(moveto));    int err_code = errno();    privs = 0;       TRACE_ENTER("MOVE: Accepted", 0);       moves++;       /* Clear the stat-cache for this file */    if (stat_cache) {    cache_set("stat_cache", moveto, 0);
Roxen.git/server/modules/filesystems/filesystem.pike:1568:    return Roxen.http_status(404, "File not found.");    }    if (!query("put")) {    TRACE_LEAVE("COPY: Put not allowed.");    return Roxen.http_status(405, "Not allowed.");    }    mapping|int(0..1) res = write_access(dest, 0, id) ||    write_access(combine_path(dest, "../"), 0, id);    if (mappingp(res)) return res;    string dest_path = path + dest; -  catch { dest_path = decode_path(dest_path); }; +  catch { dest_path = encode_path(dest_path); };    dest_path = NORMALIZE_PATH (dest_path);    if (query("no_symlinks") && (contains_symlinks(path, dest_path))) {    errors++;    report_error(LOCALE(57,"Copy to %O failed. Permission denied.\n"),    dest);    TRACE_LEAVE("COPY: Contains symlinks. Permission denied");    return Roxen.http_status(403, "Permission denied.");    }    Stat dest_st = stat_file(dest, id);    if (dest_st) {
Roxen.git/server/modules/filesystems/filesystem.pike:1681:    TRACE_LEAVE(sprintf("Chmod %O failed: %s", dest_path, msg));    } else {    TRACE_LEAVE("Success");    }    return Roxen.http_status(dest_st?204:201, "Created");    } else {    return errno_to_status (err_code, 1, id);    }    } else {    string source_path = path + source; -  catch { source_path = decode_path(source_path); }; +  catch { source_path = encode_path(source_path); };    source_path = NORMALIZE_PATH (source_path);    if (query("no_symlinks") && (contains_symlinks(path, source_path))) {    errors++;    report_error(LOCALE(57,"Copy to %O failed. Permission denied.\n"),    dest);    TRACE_LEAVE("COPY: Contains symlinks. Permission denied");    return Roxen.http_status(403, "Permission denied.");    }    puts++;