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.157 2008/08/15 12:33:54 mast Exp $"; + constant cvs_version= "$Id: filesystem.pike,v 1.158 2009/03/04 13:07:04 grubba Exp $";   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:27:   #endif      #ifdef QUOTA_DEBUG   # define QUOTA_WERR(X) werror("QUOTA: "+X+"\n")   #else   # define QUOTA_WERR(X)   #endif      #if constant(System.normalize_path)   #define NORMALIZE_PATH(X) System.normalize_path(X) - #else /* !constant(system.normalize_path) */ + #else /* !constant(System.normalize_path) */   #define NORMALIZE_PATH(X) (X) - #endif /* constant(system.normalize_path) */ + #endif /* constant(System.normalize_path) */      constant module_type = MODULE_LOCATION;   LocaleString module_name = LOCALE(51,"File systems: Normal File system");   LocaleString module_doc =   LOCALE(2,"This is the basic file system module that makes it possible "    "to mount a directory structure in the virtual file system of "    "your site.");   constant module_unique = 0;      int redirects, accesses, errors, dirlists;
Roxen.git/server/modules/filesystems/filesystem.pike:262:    access_as_user_db =    my_configuration()->find_user_database( query("access_as_user_db") );    dotfiles = query(".files");    path = query("searchpath");    mountpoint = query("mountpoint");    stat_cache = query("stat_cache");    internal_files = query("internal_files");          - #if constant(system.normalize_path) + #if constant(System.normalize_path)    if (catch {    if ((<'/','\\'>)[path[-1]]) { -  normalized_path = system.normalize_path(path + "."); +  normalized_path = System.normalize_path(path + ".");    } else { -  normalized_path = system.normalize_path(path); +  normalized_path = System.normalize_path(path);    } -  +  }) { +  report_error(LOCALE(1, "Path verification of %s failed.\n"), mountpoint); +  normalized_path = path; +  } + #else /* !constant(System.normalize_path) */ +  normalized_path = path; + #endif /* constant(System.normalize_path) */ +  if ((normalized_path == "") || !(<'/','\\'>)[normalized_path[-1]]) {   #ifdef __NT__    normalized_path += "\\";   #else /* !__NT__ */    normalized_path += "/";   #endif /* __NT__ */ -  }) { -  report_error(LOCALE(1, "Path verification of %s failed.\n"), mountpoint); -  normalized_path = path; +     } - #else /* !constant(system.normalize_path) */ -  normalized_path = path; - #endif /* constant(system.normalize_path) */ +     FILESYSTEM_WERR("Online at "+query("mountpoint")+" (path="+path+")");    cache_expire("stat_cache");   }      string query_location()   {    return mountpoint;   }    -  + ADT.Trie query_snmp_mib(array(int) base_oid, array(int) oid_suffix) + { +  return SNMP.SimpleMIB(base_oid, oid_suffix, +  ({ +  UNDEFINED, +  SNMP.String(query_location, "location", +  "Mount point in the virtual filesystem."), +  SNMP.String(query_name, "name"), +  SNMP.String(lambda() { +  return query("charset"); +  }, "charset"), +  SNMP.Counter(lambda() { +  return accesses; +  }, "accesses"), +  SNMP.Counter(lambda() { +  return errors; +  }, "errors"), +  SNMP.Counter(lambda() { +  return redirects; +  }, "redirects"), +  SNMP.Counter(lambda() { +  return dirlists; +  }, "dirlists"), +  SNMP.Counter(lambda() { +  return puts; +  }, "puts"), +  SNMP.Counter(lambda() { +  return mkdirs; +  }, "mkdirs"), +  SNMP.Counter(lambda() { +  return moves; +  }, "moves"), +  SNMP.Counter(lambda() { +  return chmods; +  }, "chmods"), +  SNMP.Counter(lambda() { +  return deletes; +  }, "deletes"), +  })); + }      #define FILTER_INTERNAL_FILE(f, id) \    (!id->misc->internal_get && sizeof (filter (internal_files, glob, (f/"/")[-1])))      #define SETUID(X) \    if( access_as_user && !id->misc->internal_get) \    { \    User uid = id->conf->authenticate( id,access_as_user_db ); \    if( access_as_user_throw && !uid ) \    return id->conf->authenticate_throw( id, "User",access_as_user_db);\
Roxen.git/server/modules/filesystems/filesystem.pike:368:    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 = path + f; +  f = normalized_path + f;    if (FILTER_INTERNAL_FILE(f, id)) return 0;    catch {    f = NORMALIZE_PATH(decode_path(f));    if (has_prefix(f, normalized_path) ||   #ifdef __NT__    (f+"\\" == normalized_path)   #else /* !__NT__ */    (f+"/" == normalized_path)   #endif /* __NT__ */    ) {
Roxen.git/server/modules/filesystems/filesystem.pike:793:    /* 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)); - #if constant(system.normalize_path) + #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"    "%O is not a prefix of %O\n"
Roxen.git/server/modules/filesystems/filesystem.pike:817:    return Roxen.http_status(403, "File exists, but access forbidden "    "by user");    }       /* Adjust not_query */    id->not_query = mountpoint + replace(norm_f[sizeof(normalized_path)..],    "\\", "/");    if (sizeof(oldf) && (oldf[-1] == '/')) {    id->not_query += "/";    } - #endif /* constant(system.normalize_path) */ + #endif /* constant(System.normalize_path) */    };       // NOTE: Sets id->misc->stat.    size = _file_size( f, id );       FILESYSTEM_WERR(sprintf("_file_size(%O, %O) ==> %d\n", f, id, size));       /*    * FIXME: Should probably move path-info extraction here.    * /grubba 1998-08-26
Roxen.git/server/modules/filesystems/filesystem.pike:995:    if (id->method == "MKCOL") {    return Roxen.http_status(201, "Created");    }    return Roxen.http_string_answer("Ok");    } else {    privs = 0;    SIMPLE_TRACE_LEAVE("%s: Failed (errcode:%d)", id->method, errcode);    TRACE_LEAVE("Failure");    if (id->method == "MKCOL") {    if (err_code == - #if constant(system.ENOENT) -  system.ENOENT + #if constant(System.ENOENT) +  System.ENOENT   #elif constant(System.ENOENT)    System.ENOENT   #else    2   #endif    ) {    return Roxen.http_status(409, "Missing intermediate.");    } else {    return Roxen.http_status(507, "Failed.");    }
Roxen.git/server/modules/filesystems/filesystem.pike:1713:    }    dest_file->close();    source_file->close();    return Roxen.http_status(dest_st?Protocols.HTTP.HTTP_NO_CONTENT:    Protocols.HTTP.HTTP_CREATED);    }   }      string query_name()   { +  if (path) {    if (sizeof(path) > 20) {    return sprintf((string)LOCALE(63,"%s from %s...%s"),    mountpoint, path[..7], path[sizeof(path)-8..]);    }    return sprintf((string)LOCALE(50,"%s from %s"), mountpoint, path);    } -  +  return "NOT MOUNTED"; + }