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 - 2000, 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.93 2001/01/04 06:02:50 nilsson Exp $"; + constant cvs_version= "$Id: filesystem.pike,v 1.94 2001/01/13 18:15:28 nilsson 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:55:   }      static int do_stat = 1;      string status()   {    return "<h2>"+LOCALE(3,"Accesses to this filesystem")+"</h2>"+    (redirects?"<b>"+LOCALE(4,"Redirects")+"</b>: "+redirects+"<br>":"")+    (accesses?"<b>"+LOCALE(5,"Normal files")+"</b>: "+accesses+"<br>"    :LOCALE(6,"No file accesses)")+"<br>")+ -  (QUERY(put)&&puts?"<b>"+LOCALE(7,"PUTs")+"</b>: "+puts+"<br>":"")+ -  (QUERY(put)&&mkdirs?"<b>"+LOCALE(8,"MKDIRs")+"</b>: "+mkdirs+"<br>":"")+ -  (QUERY(put)&&QUERY(delete)&&moves? +  (query("put")&&puts?"<b>"+LOCALE(7,"PUTs")+"</b>: "+puts+"<br>":"")+ +  (query("put")&&mkdirs?"<b>"+LOCALE(8,"MKDIRs")+"</b>: "+mkdirs+"<br>":"")+ +  (query("put")&&query("delete")&&moves?    "<b>"+LOCALE(9,"Moved files")+"</b>: "+moves+"<br>":"")+ -  (QUERY(put)&&chmods?"<b>"+LOCALE(10,"CHMODs")+"</b>: "+chmods+"<br>":"")+ -  (QUERY(delete)&&deletes?"<b>"+LOCALE(11,"Deletes")+"</b>: "+deletes+"<br>":"")+ +  (query("put")&&chmods?"<b>"+LOCALE(10,"CHMODs")+"</b>: "+chmods+"<br>":"")+ +  (query("delete")&&deletes?"<b>"+LOCALE(11,"Deletes")+"</b>: "+deletes+"<br>":"")+    (errors?"<b>"+LOCALE(12,"Permission denied")+"</b>: "+errors    +" ("+LOCALE(13,"not counting .htaccess")+")<br>":"")+    (dirlists?"<b>"+LOCALE(14,"Directories")+"</b>:"+dirlists+"<br>":"");   }      void create()   {    defvar("mountpoint", "/", LOCALE(15,"Mount point"), TYPE_LOCATION|VAR_INITIAL,    LOCALE(16,"Where the module will be mounted in the site's virtual "    "file system."));
Roxen.git/server/modules/filesystems/filesystem.pike:169:    "They can only be accessed internally, e.g. with the RXML tags"    " <tt>&lt;insert&gt;</tt> and <tt>&lt;use&gt;</tt>."));   }      string path, mountpoint, charset, path_encoding;   int stat_cache, dotfiles, access_as_user, no_symlinks, tilde;   array(string) internal_files;      void start()   { -  tilde = QUERY(tilde); -  charset = QUERY(charset); -  path_encoding = QUERY(path_encoding); -  no_symlinks = QUERY(no_symlinks); -  access_as_user = QUERY(access_as_user); -  dotfiles = QUERY(.files); -  path = QUERY(searchpath); -  mountpoint = QUERY(mountpoint); -  stat_cache = QUERY(stat_cache); -  internal_files = QUERY(internal_files); -  FILESYSTEM_WERR("Online at "+QUERY(mountpoint)+" (path="+path+")"); +  tilde = query("tilde"); +  charset = query("charset"); +  path_encoding = query("path_encoding"); +  no_symlinks = query("no_symlinks"); +  access_as_user = query("access_as_user"); +  dotfiles = query(".files"); +  path = query("searchpath"); +  mountpoint = query("mountpoint"); +  stat_cache = query("stat_cache"); +  internal_files = query("internal_files"); +  FILESYSTEM_WERR("Online at "+query("mountpoint")+" (path="+path+")");    cache_expire("stat_cache");   }      string query_location()   {    return mountpoint;   }         #define FILTER_INTERNAL_FILE(f, id) \
Roxen.git/server/modules/filesystems/filesystem.pike:232:   }      int dir_filter_function(string f, RequestID id)   {    if(f[0]=='.' && !dotfiles) return 0;    if(!tilde && Roxen.backup_extension(f)) return 0;    return 1;   }      array(string) list_lock_files() { -  return QUERY(nobrowse); +  return query("nobrowse");   }      array find_dir( string f, RequestID id )   {    array dir;       FILESYSTEM_WERR("find_dir for \""+f+"\"" +    (id->misc->internal_get ? " (internal)" : ""));       object privs;
Roxen.git/server/modules/filesystems/filesystem.pike:254:    if (((int)id->misc->uid) && ((int)id->misc->gid) && access_as_user )    // NB: Root-access is prevented.    privs=Privs("Getting dir", (int)id->misc->uid, (int)id->misc->gid );       if(!(dir = get_dir( decode_path(path + f) ))) {    privs = 0;    return 0;    }    privs = 0;    -  if(!QUERY(dir)) +  if(!query("dir"))    // Access to this dir is allowed.    if(! has_value(dir, ".www_browsable"))    {    errors++;    return 0;    }       // Access to this dir is not allowed. -  if( sizeof(dir & QUERY(nobrowse)) ) +  if( sizeof(dir & query("nobrowse")) )    {    errors++;    return 0;    }       dirlists++;       // Pass _all_ files, hide none.    if(tilde && dotfiles &&    (!sizeof( internal_files ) || id->misc->internal_get))
Roxen.git/server/modules/filesystems/filesystem.pike:529:    {    if( id->misc->set_output_charset )    id->misc->set_output_charset( charset, 2 );    id->misc->input_charset = charset;    }    return o;    }    break;       case "MKDIR": -  if(!QUERY(put)) +  if(!query("put"))    {    id->misc->error_code = 405;    TRACE_LEAVE("MKDIR disallowed (since PUT is disallowed)");    return 0;    }       if (FILTER_INTERNAL_FILE (f, id)) {    id->misc->error_code = 405;    TRACE_LEAVE("MKDIR disallowed (since the dir name matches internal file glob)");    return 0;    }    -  if(QUERY(check_auth) && (!id->auth || !id->auth[0])) { +  if(query("check_auth") && (!id->auth || !id->auth[0])) {    TRACE_LEAVE("MKDIR: Permission denied");    return Roxen.http_auth_required("foo",    "<h1>Permission to 'MKDIR' denied</h1>");    }    mkdirs++;    object privs;       if (((int)id->misc->uid) && ((int)id->misc->gid)) {    // NB: Root-access is prevented.    privs=Privs("Creating directory",    (int)id->misc->uid, (int)id->misc->gid );    }    -  if (QUERY(no_symlinks) && (contains_symlinks(path, oldf))) { +  if (query("no_symlinks") && (contains_symlinks(path, oldf))) {    privs = 0;    errors++;    report_error(LOCALE(46,"Creation of %s failed. Permission denied.\n"),f);    TRACE_LEAVE("MKDIR: Contains symlinks. Permission denied");    return http_low_answer(403, "<h2>Permission denied.</h2>");    }       int code = mkdir( decode_path(f) );    privs = 0;   
Roxen.git/server/modules/filesystems/filesystem.pike:583:    return Roxen.http_string_answer("Ok");    } else {    TRACE_LEAVE("MKDIR: Failed");    TRACE_LEAVE("Failure");    return 0;    }       break;       case "PUT": -  if(!QUERY(put)) +  if(!query("put"))    {    id->misc->error_code = 405;    TRACE_LEAVE("PUT disallowed");    return 0;    }       if (FILTER_INTERNAL_FILE (f, id)) {    id->misc->error_code = 405;    TRACE_LEAVE("PUT of internal file is disallowed");    return 0;    }    -  if(QUERY(check_auth) && (!id->auth || !id->auth[0])) { +  if(query("check_auth") && (!id->auth || !id->auth[0])) {    TRACE_LEAVE("PUT: Permission denied");    return Roxen.http_auth_required("foo",    "<h1>Permission to 'PUT' files denied</h1>");    }       puts++;       QUOTA_WERR("Checking quota.\n");    if (id->misc->quota_obj && (id->misc->len > 0) &&    !id->misc->quota_obj->check_quota(URI, id->misc->len)) {
Roxen.git/server/modules/filesystems/filesystem.pike:620:    return http_low_answer(413, "<h2>Out of disk quota.</h2>",    "413 Out of disk quota");    }          if (((int)id->misc->uid) && ((int)id->misc->gid)) {    // NB: Root-access is prevented.    privs=Privs("Saving file", (int)id->misc->uid, (int)id->misc->gid );    }    -  if (QUERY(no_symlinks) && (contains_symlinks(path, oldf))) { +  if (query("no_symlinks") && (contains_symlinks(path, oldf))) {    privs = 0;    errors++;    report_error(LOCALE(46,"Creation of %s failed. Permission denied.\n"),f);    TRACE_LEAVE("PUT: Contains symlinks. Permission denied");    return http_low_answer(403, "<h2>Permission denied.</h2>");    }       rm( decode_path(f) );    mkdirhier( decode_path(f) );   
Roxen.git/server/modules/filesystems/filesystem.pike:702:    id->my_fd->set_nonblocking(got_put_data, 0, done_with_put);    TRACE_LEAVE("PUT: Pipe in progress");    TRACE_LEAVE("PUT: Success so far");    return Roxen.http_pipe_in_progress();    break;       case "CHMOD":    // Change permission of a file.    // FIXME: !!    -  if(!QUERY(put)) +  if(!query("put"))    {    id->misc->error_code = 405;    TRACE_LEAVE("CHMOD disallowed (since PUT is disallowed)");    return 0;    }       if (FILTER_INTERNAL_FILE (f, id)) {    id->misc->error_code = 405;    TRACE_LEAVE("CHMOD of internal file is disallowed");    return 0;    }    -  if(QUERY(check_auth) && (!id->auth || !id->auth[0])) { +  if(query("check_auth") && (!id->auth || !id->auth[0])) {    TRACE_LEAVE("CHMOD: Permission denied");    return Roxen.http_auth_required("foo",    "<h1>Permission to 'CHMOD' files denied</h1>");    }          if (((int)id->misc->uid) && ((int)id->misc->gid)) {    // NB: Root-access is prevented.    privs=Privs("CHMODing file", (int)id->misc->uid, (int)id->misc->gid );    }    -  if (QUERY(no_symlinks) && (contains_symlinks(path, oldf))) { +  if (query("no_symlinks") && (contains_symlinks(path, oldf))) {    privs = 0;    errors++;    TRACE_LEAVE("CHMOD: Contains symlinks. Permission denied");    return http_low_answer(403, "<h2>Permission denied.</h2>");    }       array err = catch(chmod(decode_path(f), id->misc->mode & 0777));    privs = 0;       chmods++;
Roxen.git/server/modules/filesystems/filesystem.pike:761:    }    TRACE_LEAVE("CHMOD: Success");    TRACE_LEAVE("Success");    return Roxen.http_string_answer("Ok");       case "MV":    // This little kluge is used by ftp2 to move files.       // FIXME: Support for quota.    -  if(!QUERY(put)) +  if(!query("put"))    {    id->misc->error_code = 405;    TRACE_LEAVE("MV disallowed (since PUT is disallowed)");    return 0;    } -  if(!QUERY(delete) && size != -1) +  if(!query("delete") && size != -1)    {    id->misc->error_code = 405;    TRACE_LEAVE("MV disallowed (DELE disabled, can't overwrite file)");    return 0;    }       if(size < -1)    {    id->misc->error_code = 405;    TRACE_LEAVE("MV: Cannot overwrite directory");    return 0;    }    -  if(QUERY(check_auth) && (!id->auth || !id->auth[0])) { +  if(query("check_auth") && (!id->auth || !id->auth[0])) {    TRACE_LEAVE("MV: Permission denied");    return Roxen.http_auth_required("foo",    "<h1>Permission to 'MV' files denied</h1>");    }    string movefrom;    if(!id->misc->move_from ||    !(movefrom = id->conf->real_file(id->misc->move_from, id))) {    id->misc->error_code = 405;    errors++;    TRACE_LEAVE("MV: No source file");
Roxen.git/server/modules/filesystems/filesystem.pike:807:    id->misc->error_code = 405;    TRACE_LEAVE("MV to or from internal file is disallowed");    return 0;    }       if (((int)id->misc->uid) && ((int)id->misc->gid)) {    // NB: Root-access is prevented.    privs=Privs("Moving file", (int)id->misc->uid, (int)id->misc->gid );    }    -  if (QUERY(no_symlinks) && +  if (query("no_symlinks") &&    ((contains_symlinks(path, oldf)) ||    (contains_symlinks(path, id->misc->move_from)))) {    privs = 0;    errors++;    TRACE_LEAVE("MV: Contains symlinks. Permission denied");    return http_low_answer(403, "<h2>Permission denied.</h2>");    }       code = mv(decode_path(movefrom), decode_path(f));    privs = 0;
Roxen.git/server/modules/filesystems/filesystem.pike:845:    }    TRACE_LEAVE("MV: Success");    TRACE_LEAVE("Success");    return Roxen.http_string_answer("Ok");       case "MOVE":    // This little kluge is used by NETSCAPE 4.5       // FIXME: Support for quota.    -  if(!QUERY(put)) +  if(!query("put"))    {    id->misc->error_code = 405;    TRACE_LEAVE("MOVE disallowed (since PUT is disallowed)");    return 0;    }    if(size != -1)    {    id->misc->error_code = 404;    TRACE_LEAVE("MOVE failed (no such file)");    return 0;    }    -  if(QUERY(check_auth) && (!id->auth || !id->auth[0])) { +  if(query("check_auth") && (!id->auth || !id->auth[0])) {    TRACE_LEAVE("MOVE: Permission denied");    return Roxen.http_auth_required("foo",    "<h1>Permission to 'MOVE' files denied</h1>");    }       if(!sizeof(id->misc["new-uri"] || "")) {    id->misc->error_code = 405;    errors++;    TRACE_LEAVE("MOVE: No dest file");    return 0;
Roxen.git/server/modules/filesystems/filesystem.pike:890:       if (FILTER_INTERNAL_FILE (f, id) ||    FILTER_INTERNAL_FILE (moveto, id)) {    id->misc->error_code = 405;    TRACE_LEAVE("MOVE to or from internal file is disallowed");    return 0;    }       size = _file_size(moveto,id);    -  if(!QUERY(delete) && size != -1) +  if(!query("delete") && size != -1)    {    id->misc->error_code = 405;    TRACE_LEAVE("MOVE disallowed (DELE disabled, can't overwrite file)");    return 0;    }       if(size < -1)    {    id->misc->error_code = 405;    TRACE_LEAVE("MOVE: Cannot overwrite directory");    return 0;    }       if (((int)id->misc->uid) && ((int)id->misc->gid)) {    // NB: Root-access is prevented.    privs=Privs("Moving file", (int)id->misc->uid, (int)id->misc->gid );    }    -  if (QUERY(no_symlinks) && +  if (query("no_symlinks") &&    ((contains_symlinks(path, f)) ||    (contains_symlinks(path, moveto)))) {    privs = 0;    errors++;    TRACE_LEAVE("MOVE: Contains symlinks. Permission denied");    return http_low_answer(403, "<h2>Permission denied.</h2>");    }       code = mv(decode_path(f), decode_path(moveto));    privs = 0;
Roxen.git/server/modules/filesystems/filesystem.pike:944:    TRACE_LEAVE("MOVE: Move failed");    TRACE_LEAVE("Failure");    return 0;    }    TRACE_LEAVE("MOVE: Success");    TRACE_LEAVE("Success");    return Roxen.http_string_answer("Ok");          case "DELETE": -  if(!QUERY(delete) || size==-1) +  if(!query("delete") || size==-1)    {    id->misc->error_code = 405;    TRACE_LEAVE("DELETE: Disabled");    return 0;    }       if (FILTER_INTERNAL_FILE (f, id)) {    id->misc->error_code = 405;    TRACE_LEAVE("DELETE of internal file is disallowed");    return 0;    }    -  if(QUERY(check_auth) && (!id->auth || !id->auth[0])) { +  if(query("check_auth") && (!id->auth || !id->auth[0])) {    TRACE_LEAVE("DELETE: Permission denied");    return http_low_answer(403, "<h1>Permission to DELETE file denied</h1>");    }    -  if (QUERY(no_symlinks) && (contains_symlinks(path, oldf))) { +  if (query("no_symlinks") && (contains_symlinks(path, oldf))) {    errors++;    report_error(LOCALE(48,"Deletion of %s failed. Permission denied.\n"),f);    TRACE_LEAVE("DELETE: Contains symlinks");    return http_low_answer(403, "<h2>Permission denied.</h2>");    }       report_notice(LOCALE(49,"DELETING the file %s.\n"),f);    accesses++;       if (((int)id->misc->uid) && ((int)id->misc->gid)) {