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 - 1998, Idonex AB.      // 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 "roxenlib";   inherit "socket";    - constant cvs_version= "$Id: filesystem.pike,v 1.35 1998/05/01 01:05:56 grubba Exp $"; + constant cvs_version= "$Id: filesystem.pike,v 1.36 1998/05/14 08:22:52 neotron Exp $";   constant thread_safe=1;         #include <module.h>   #include <roxen.h>   #include <stat.h>      #if DEBUG_LEVEL > 20   # ifndef FILESYSTEM_DEBUG   # define FILESYSTEM_DEBUG   # endif   #endif      // import Array;      #define TRACE_ENTER(A,B) do{if(id->misc->trace_enter)id->misc->trace_enter((A),(B));}while(0)   #define TRACE_LEAVE(A) do{if(id->misc->trace_leave)id->misc->trace_leave((A));}while(0)         int redirects, accesses, errors, dirlists; - int puts, deletes, mkdirs; + int puts, deletes, mkdirs, moves;      static int do_stat = 1;      string status()   {    return ("<h2>Accesses to this filesystem</h2>"+    (redirects?"<b>Redirects</b>: "+redirects+"<br>":"")+    (accesses?"<b>Normal files</b>: "+accesses+"<br>"    :"No file accesses<br>")+    (QUERY(put)&&puts?"<b>Puts</b>: "+puts+"<br>":"")+    (QUERY(put)&&mkdirs?"<b>Mkdirs</b>: "+mkdirs+"<br>":"")+ -  +  (QUERY(put)&&moves?"<b>Moved files</b>: "+moves+"<br>":"")+    (QUERY(delete)&&deletes?"<b>Deletes</b>: "+deletes+"<br>":"")+    (errors?"<b>Permission denied</b>: "+errors    +" (not counting .htaccess)<br>":"")+    (dirlists?"<b>Directories</b>:"+dirlists+"<br>":""));   }      void create()   {    defvar("mountpoint", "/", "Mount point", TYPE_LOCATION,    "This is where the module will be inserted in the "+
Roxen.git/server/modules/filesystems/filesystem.pike:506:    if(id->clientprot == "HTTP/1.1") {    id->my_fd->write("HTTP/1.1 100 Continue\r\n");    }    id->my_fd->set_id( ({ to, id->my_fd }) );    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 http_pipe_in_progress();    break;    +  case "MV": +  // This little kludge is used by ftp2 to move files. +  +  if(!QUERY(put)) +  { +  id->misc->error_code = 405; +  TRACE_LEAVE("MV disallowed (since PUT is disallowed)"); +  return 0; +  } +  if(!QUERY(delete) && size != -1) +  { +  id->misc->error_code = 405; +  TRACE_LEAVE("MV disallowed (DELE disabled, can't overwrite file)"); +  return 0; +  } +  +  if(size == -2) +  { +  id->misc->error_code = 405; +  TRACE_LEAVE("MV: Cannot overwrite directory"); +  return 0; +  } +  +  if(QUERY(check_auth) && (!id->auth || !id->auth[0])) { +  TRACE_LEAVE("MV: Permission denied"); +  return 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"); +  return 0; +  } +  moves++; +  +  object privs; +  + // #ifndef THREADS // Ouch. This is is _needed_. Well well... +  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 ); +  } +  // #endif +  +  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>"); +  } +  +  TRACE_ENTER("MV: Accepted", 0); +  +  +  /* Clear the stat-cache for this file */ + #ifdef __NT__ +  if(movefrom[-1] == '/') +  movefrom = move_from[..strlen(movefrom)-2]; + #endif +  if (stat_cache) { +  cache_set("stat_cache", movefrom, 0); +  cache_set("stat_cache", f, 0); +  } +  werror("Moving file "+movefrom+" to "+ f+"\n"); +  int code = mv(movefrom, f); +  privs = 0; +  +  if(!code) +  { +  id->misc->error_code = 403; +  TRACE_LEAVE("MV: Move failed"); +  TRACE_LEAVE("Failure"); +  return 0; +  } +  TRACE_LEAVE("MV: Success"); +  return http_string_answer("Ok"); +     case "DELETE":    if(!QUERY(delete) || size==-1)    {    id->misc->error_code = 405;    TRACE_LEAVE("DELETE: Disabled");    return 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>");