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.53 1999/05/05 20:20:31 grubba Exp $"; + constant cvs_version= "$Id: filesystem.pike,v 1.54 1999/05/06 20:51:55 grubba Exp $";   constant thread_safe=1;         #include <module.h>   #include <roxen.h>   #include <stat.h>      #if DEBUG_LEVEL > 20   # ifndef FILESYSTEM_DEBUG   # define FILESYSTEM_DEBUG
Roxen.git/server/modules/filesystems/filesystem.pike:24:      // 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, moves, chmods;    + static mapping http_low_answer(int errno, string data, string|void desc) + { +  mapping res = ::http_low_answer(errno, data); +  +  if (desc) { +  res->rettext = desc; +  } +  +  return res; + } +    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>":"")+
Roxen.git/server/modules/filesystems/filesystem.pike:239:   void done_with_put( array(object|string) id_arr )   {   // perror("Done with put.\n");    object to;    object from;    object id;    string oldf;       [to, from, id, oldf] = id_arr;    + #ifdef FILESYSTEM_DEBUG +  werror(sprintf("done_with_put(%O)\n" +  "from: %O\n", +  id_arr, mkmapping(indices(from), values(from)))); + #endif /* FILESYSTEM_DEBUG */ +     to->close();    from->set_blocking();    m_delete(putting, from);       if (putting[from] && (putting[from] != 0x7fffffff)) {    // Truncated!    id->send_result(http_low_answer(400,    "<h2>Bad Request - "    "Expected more data.</h2>"));    } else {
Roxen.git/server/modules/filesystems/filesystem.pike:272:    [to, from, id, oldf] = id_arr;       // Truncate at end.    data = data[..putting[from]];       if (id->misc->quota_obj &&    !id->misc->quota_obj->check_quota(oldf, sizeof(data))) {    to->close();    from->set_blocking();    m_delete(putting, from); -  id->send_result(http_low_answer(413, "<h2>Out of disk quota.</h2>")); +  id->send_result(http_low_answer(413, "<h2>Out of disk quota.</h2>", +  "413 Out of disk quota"));    return;    }       int bytes = to->write( data );    if (bytes < sizeof(data)) {    // Out of disk!    to->close();    from->set_blocking();    m_delete(putting, from);    id->send_result(http_low_answer(413, "<h2>Disk full.</h2>"));    return;    } else {    if (id->misc->quota_obj &&    !id->misc->quota_obj->allocate(oldf, bytes)) {    to->close();    from->set_blocking();    m_delete(putting, from); -  id->send_result(http_low_answer(413, "<h2>Out of disk quota.</h2>")); +  id->send_result(http_low_answer(413, "<h2>Out of disk quota.</h2>", +  "413 Out of disk quota"));    return;    }    if (putting[from] != 0x7fffffff) {    putting[from] -= bytes;    }    if(putting[from] <= 0) {    putting[from] = 0; // Paranoia    done_with_put( id_arr );    }    }
Roxen.git/server/modules/filesystems/filesystem.pike:353:       object o;    int size;    string tmp;    string oldf = f;      #ifdef FILESYSTEM_DEBUG    roxen_perror("FILESYSTEM: Request for \""+f+"\"\n");   #endif /* FILESYSTEM_DEBUG */    +  string mountpoint = QUERY(mountpoint); +  +  string uri = combine_path(mountpoint + "/" + f, "."); +     f = path + f;   #ifdef __NT__    if(f[-1]=='/') f = f[..strlen(f)-2];   #endif    size = FILE_SIZE( f );       /*    * FIXME: Should probably move path-info extraction here.    * /grubba 1998-08-26    */
Roxen.git/server/modules/filesystems/filesystem.pike:529:    TRACE_LEAVE("PUT: Permission denied");    return http_auth_required("foo",    "<h1>Permission to 'PUT' files denied</h1>");    }       puts++;      #ifdef QUOTA_DEBUG    report_debug("Checking quota.\n");   #endif /* QUOTA_DEBUG */ -  if (id->misc->quota_obj && -  !id->misc->quota_obj->check_quota(oldf, id->misc->len)) { +  if (id->misc->quota_obj && (id->misc->len > 0) && +  !id->misc->quota_obj->check_quota(uri, id->misc->len)) {    errors++;    report_warning("Creation of " + f + " failed. Out of quota.\n");    TRACE_LEAVE("PUT: Out of quota."); -  return http_low_answer(413, "<h2>Out of quota.</h2>"); +  return http_low_answer(413, "<h2>Out of disk quota.</h2>", +  "413 Out of disk quota");    }       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("Saving file", (int)id->misc->uid, (int)id->misc->gid );    }   // #endif
Roxen.git/server/modules/filesystems/filesystem.pike:567:    mkdirhier( f );       if (id->misc->quota_obj) {   #ifdef QUOTA_DEBUG    report_debug("Checking if the file already exists.\n");   #endif /* QUOTA_DEBUG */    if (size > 0) {   #ifdef QUOTA_DEBUG    report_debug("Deallocating " + size + "bytes.\n");   #endif /* QUOTA_DEBUG */ -  id->misc->quota_obj->deallocate(oldf, size); +  id->misc->quota_obj->deallocate(uri, size);    }    if (size) {   #ifdef QUOTA_DEBUG    report_debug("Deleting old file.\n");   #endif /* QUOTA_DEBUG */    rm(f);    }    }       /* Clear the stat-cache for this file */
Roxen.git/server/modules/filesystems/filesystem.pike:612:    putting[id->my_fd] -= strlen(id->data);    }    int bytes = to->write( id->data );    if (id->misc->quota_obj) {   #ifdef QUOTA_DEBUG    report_debug("Allocating " + bytes + "bytes.\n");   #endif /* QUOTA_DEBUG */    if (!id->misc->quota_obj->allocate(f, bytes)) {    TRACE_LEAVE("PUT: A string");    TRACE_LEAVE("PUT: Out of quota"); -  return http_low_answer(413, "<h2>Out of quota.</h2>"); +  return http_low_answer(413, "<h2>Out of disk quota.</h2>", +  "413 Out of disk quota");    }    }    }    if(!putting[id->my_fd]) {    TRACE_LEAVE("PUT: Just a string");    TRACE_LEAVE("Put: Success");    return http_string_answer("Ok");    }       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, oldf }) ); +  id->my_fd->set_id( ({ to, id->my_fd, id, uri }) );    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 "CHMOD":    // Change permission of a file. -  +  // FIXME: !!       if(!QUERY(put))    {    id->misc->error_code = 405;    TRACE_LEAVE("CHMOD disallowed (since PUT is disallowed)");    return 0;    }       if(QUERY(check_auth) && (!id->auth || !id->auth[0])) {    TRACE_LEAVE("CHMOD: Permission denied");
Roxen.git/server/modules/filesystems/filesystem.pike:805:    return 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;    } -  string mountpoint = QUERY(mountpoint); -  string moveto = combine_path(mountpoint + "/" + oldf + "/..", +  string new_uri = combine_path(uri + "/../",    id->misc["new-uri"]);    -  if (moveto[..sizeof(mountpoint)-1] != mountpoint) { +  if (new_uri[..sizeof(mountpoint)-1] != mountpoint) {    id->misc->error_code = 405;    TRACE_LEAVE("MOVE: Dest file on other filesystem.");    return(0);    } -  moveto = path + moveto[sizeof(mountpoint)..]; +  string moveto = path + "/" + new_uri[sizeof(mountpoint)..];       size = FILE_SIZE(moveto);       if(!QUERY(delete) && size != -1)    {    id->misc->error_code = 405;    TRACE_LEAVE("MOVE disallowed (DELE disabled, can't overwrite file)");    return 0;    }