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.30 1998/03/11 19:42:35 neotron Exp $"; + constant cvs_version= "$Id: filesystem.pike,v 1.31 1998/04/15 21:28:49 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   # 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;      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>"
Roxen.git/server/modules/filesystems/filesystem.pike:281:    }    } else {    return(0);    }    }    return(0);   }      mixed find_file( string f, object id )   { +  TRACE_ENTER("find_file(\""+f+"\")", 0); +     object o;    int size;    string tmp;    string oldf = f;   #ifdef FILESYSTEM_DEBUG    perror("FILESYSTEM: Request for "+f+"\n");   #endif    size = FILE_SIZE( f = path + f );       switch(id->method)    {    case "GET":    case "HEAD":    case "POST":       switch(-size)    {    case 1: -  +  case 3: +  case 4: +  TRACE_LEAVE("No file");    return 0; /* Is no-file */       case 2: -  +  TRACE_LEAVE("Is directory");    return -1; /* Is dir */       default:    if(f[ -1 ] == '/') /* Trying to access file with '/' appended */    {    /* Do not try redirect on top level directory */    if(sizeof(id->not_query) < 2)    return 0;    redirects++; -  +  TRACE_LEAVE("Redirecting to \"" + +  id->not_query[..sizeof(id->not_query)-2] + +  "\"");    return http_redirect(id->not_query[..sizeof(id->not_query)-2], id);    }       if(!id->misc->internal_get && QUERY(.files)    && (tmp = (id->not_query/"/")[-1]) -  && tmp[0] == '.') +  && tmp[0] == '.') { +  TRACE_LEAVE("Is .-file");    return 0; -  +  }   #ifndef THREADS    object privs;    if (((int)id->misc->uid) && ((int)id->misc->gid) &&    (QUERY(access_as_user))) {    // NB: Root-access is prevented.    privs=Privs("Getting file", (int)id->misc->uid, (int)id->misc->gid );    }   #endif    -  +  TRACE_ENTER("Opening file \"" + f + "\"", 0);    o = open( f, "r" );      #ifndef THREADS    privs = 0;   #endif       if(!o || (QUERY(no_symlinks) && (contains_symlinks(path, oldf))))    {    errors++;    report_error("Open of " + f + " failed. Permission denied.\n"); -  +  +  TRACE_LEAVE(""); +  TRACE_LEAVE("Permission denied.");    return http_low_answer(403, "<h2>File exists, but access forbidden "    "by user</h2>");    }       id->realfile = f; -  +  TRACE_LEAVE("");    accesses++;   #ifdef COMPAT -  if(QUERY(html)) /* Not very likely, really.. */ +  if(QUERY(html)) {/* Not very likely, really.. */ +  TRACE_LEAVE("Compat return");    return ([ "type":"text/html", "file":o, ]); -  +  }   #endif -  +  TRACE_LEAVE("Normal return");    return o;    }    break;       case "PUT":    if(!QUERY(put))    {    id->misc->error_code = 405; -  +  TRACE_LEAVE("PUT 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 http_auth_required("foo",    "<h1>Permission to 'PUT' files denied</h1>"); -  +  }    puts++;       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       if (QUERY(no_symlinks) && (contains_symlinks(path, oldf))) {    privs = 0;    errors++;    report_error("Creation of " + f + " failed. Permission denied.\n"); -  +  TRACE_LEAVE("PUT: Contains symlinks. Permission denied");    return http_low_answer(403, "<h2>Permission denied.</h2>");    }    -  +  TRACE_ENTER("PUT: Accepted", 0); +     rm( f );    mkdirhier( f ); -  +  +  /* Clear the stat-cache for this file */ +  if (stat_cache) { +  cache_set("stat_cache", f, 0); +  } +     object to = open(f, "wc");       privs = 0;       if(!to)    {    id->misc->error_code = 403; -  +  TRACE_LEAVE("PUT: Open failed"); +  TRACE_LEAVE("Failure");    return 0;    }       putting[id->my_fd]=id->misc->len;    if(id->data && strlen(id->data))    {    putting[id->my_fd] -= strlen(id->data);    to->write( id->data );    } -  if(!putting[id->my_fd]) +  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->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 "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])) +  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))) {    errors++;    report_error("Deletion of " + f + " failed. Permission denied.\n"); -  +  TRACE_LEAVE("DELETE: Contains symlinks");    return http_low_answer(403, "<h2>Permission denied.</h2>");    }       report_notice("DELETING the file "+f+"\n");    accesses++;       if (((int)id->misc->uid) && ((int)id->misc->gid)) {    // NB: Root-access is prevented.    privs=Privs("Deleting file", id->misc->uid, id->misc->gid );    }    -  +  /* Clear the stat-cache for this file */ +  if (stat_cache) { +  cache_set("stat_cache", f, 0); +  } +     if(!rm(f))    {    privs = 0;    id->misc->error_code = 405; -  +  TRACE_LEAVE("DELETE: Failed");    return 0;    }    privs = 0;    deletes++; -  +  TRACE_LEAVE("DELETE: Success");    return http_low_answer(200,(f+" DELETED from the server"));       default: -  +  TRACE_LEAVE("Not supported");    return 0;    }    report_error("Not reached..\n"); -  +  TRACE_LEAVE("Not reached");    return 0;   }      string query_name()   {    return sprintf("<i>%s</i> mounted on <i>%s</i>", query("searchpath"),    query("mountpoint"));   }