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 - 2001, 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.133 2004/05/10 13:53:10 grubba Exp $"; + constant cvs_version= "$Id: filesystem.pike,v 1.134 2004/05/10 14:46:39 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:1205:    TRACE_LEAVE("MOVE failed (no such file)");    return 0;    }       if(query("check_auth") && (!id->conf->authenticate( id ) ) ) {    TRACE_LEAVE("MOVE: Permission denied");    return Roxen.http_auth_required("foo",    "<h1>Permission to 'MOVE' files denied</h1>");    }    -  // FIXME: Ought to be done in the protocol module. -  string new_uri = id->request_headers->destination || -  id->misc["new-uri"] || ""; -  +  string new_uri = id->misc["new-uri"] || "";    if (new_uri == "") {    id->misc->error_code = 405;    errors++;    TRACE_LEAVE("MOVE: No dest file");    return 0;    } -  int div = search(new_uri, "/"); -  if ((div > 0) && (new_uri[div-1] == ':')) { -  // Protocol specification present. -  new_uri = new_uri[div..]; -  } -  if (has_prefix(new_uri, "//")) { -  // Address specification present. -  div = search(new_uri, "/", 2); -  if (div > 0) { -  new_uri = new_uri[div..]; -  } else { -  new_uri = "/"; -  } -  } else { -  new_uri = combine_path(URI + "/../", new_uri); -  } +        // FIXME: The code below doesn't allow for this module being overloaded.    if (!has_prefix(new_uri, mountpoint)) {    id->misc->error_code = 405;    TRACE_LEAVE("MOVE: Dest file on other filesystem.");    return(0);    }    new_uri = new_uri[sizeof(mountpoint)..];    string moveto = path + "/" + new_uri;       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) -  { -  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 (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>");    }       if (mapping(string:mixed) ret =    write_access(new_uri, 0, id) ||    write_access(oldf, 0, id)) {    TRACE_LEAVE("MOVE: Locked");    return ret;    }    -  +  size = _file_size(moveto,id); +     SETUID_TRACE("Moving file", 0);    -  +  if (size != -1) { +  // Destination exists. +  +  Overwrite overwrite = +  id->request_headers->overwrite? +  (lower_case(id->request_headers->overwrite) == "t"? +  DO_OVERWRITE:NEVER_OVERWRITE):MAYBE_OVERWRITE; +  if (overwrite == NEVER_OVERWRITE) { +  privs = 0; +  TRACE_LEAVE("MOVE disallowed (overwrite header:F)."); +  return Roxen.http_status(412); +  } +  if(!query("delete")) +  { +  privs = 0; +  id->misc->error_code = 405; +  TRACE_LEAVE("MOVE disallowed (DELE disabled)"); +  return 0; +  } +  +  if ((overwrite == DO_OVERWRITE) || (size > -1)) { +  int code = recurse_delete_files(new_uri, +  id->get_multi_status()-> +  prefix(id->url_base() + +  mountpoint[1..]), id); +  if (code > 1) { +  privs = 0; +  TRACE_LEAVE("MOVE: Recursive delete failed."); +  return Roxen.http_status(412); +  } +  } else { +  privs = 0; +  TRACE_LEAVE("MOVE: Cannot overwrite directory"); +  return Roxen.http_status(412); +  } +  } +     code = mv(f, decode_path(moveto));    privs = 0;       TRACE_ENTER("MOVE: Accepted", 0);       moves++;       /* Clear the stat-cache for this file */    if (stat_cache) {    cache_set("stat_cache", moveto, 0);    cache_set("stat_cache", f, 0);    }       if(!code)    {    id->misc->error_code = 403; -  TRACE_LEAVE("MOVE: Move failed"); +  SIMPLE_TRACE_LEAVE("MOVE: Move failed (errno: %d)", errno());    TRACE_LEAVE("Failure");    return 0;    }    TRACE_LEAVE("MOVE: Success");    TRACE_LEAVE("Success"); -  return Roxen.http_string_answer("Ok"); +  if (size != -1) return Roxen.http_status(204); +  return Roxen.http_status(201);    -  +     case "DELETE":    if (size==-1) {    id->misc->error_code = 404;    TRACE_LEAVE("DELETE: Not found");    return 0;    }    if(!query("delete"))    {    id->misc->error_code = 405;    TRACE_LEAVE("DELETE: Disabled");