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 - 2004, 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.150 2005/09/02 11:14:23 mast Exp $"; + constant cvs_version= "$Id: filesystem.pike,v 1.151 2005/10/19 12:22:09 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:675:    if (rr[1] == -3) {    return(1);    }    } else {    return(0);    }    }    return(0);   }    + //! @[chmod()] that doesn't throw errors. + string safe_chmod(string path, int mask) + { +  return describe_error(catch { +  chmod(path, mask); +  return 0; +  }); + } +    mapping make_collection(string coll, RequestID id)   {    TRACE_ENTER(sprintf("make_collection(%O)", coll), this_object());       string norm_f = real_path(coll, id);       if (!norm_f) {    TRACE_LEAVE(sprintf("%s: Bad path", id->method));    return Roxen.http_status(405, "Bad path.");    }
Roxen.git/server/modules/filesystems/filesystem.pike:727:    errors++;    report_error(LOCALE(46,"Creation of %O failed. Permission denied.\n"),    coll);    TRACE_LEAVE(sprintf("%s: Contains symlinks. Permission denied",    id->method));    return Roxen.http_status(403, "Permission denied.");    }       int code = mkdir(norm_f);    int err_code = errno(); -  privs = 0; +        TRACE_ENTER(sprintf("%s: Accepted", id->method), 0);       if (code) { -  chmod(norm_f, 0777 & ~(id->misc->umask || 022)); +  string msg = safe_chmod(norm_f, 0777 & ~(id->misc->umask || 022)); +  privs = 0; +  if (msg) { +  TRACE_LEAVE(sprintf("%s: chmod %O failed: %s", id->method, norm_f, msg)); +  } else { +  TRACE_LEAVE(sprintf("%s: chmod ok", id->method, msg)); +  }    TRACE_LEAVE(sprintf("%s: Success", id->method)); -  TRACE_LEAVE(sprintf("%s: Success", id->method)); +     return Roxen.http_status(201, "Created");    } -  +  privs = 0;       TRACE_LEAVE(sprintf("%s: Failed", id->method));    return errno_to_status (err_code, 1, id);   }      class CacheCallback(string f, int orig_size)   {    int(0..1) `()(RequestID id, mixed key)    {    return _file_size(f, id) == orig_size;
Roxen.git/server/modules/filesystems/filesystem.pike:945:    errors++;    report_error(LOCALE(46,"Creation of %O failed. Permission denied.\n"),    oldf);    TRACE_LEAVE(sprintf("%s: Contains symlinks. Permission denied",    id->method));    return Roxen.http_status(403, "Permission denied.");    }       code = mkdir(f);    int err_code = errno(); -  privs = 0; +        TRACE_ENTER(sprintf("%s: Accepted", id->method), 0);       if (code) { -  chmod(f, 0777 & ~(id->misc->umask || 022)); +  string msg = safe_chmod(f, 0777 & ~(id->misc->umask || 022)); +  privs = 0; +  if (msg) { +  TRACE_LEAVE(sprintf("%s: chmod %O failed: %s", id->method, f, msg)); +  } else {    TRACE_LEAVE(sprintf("%s: Success", id->method)); -  +  }    TRACE_LEAVE("Success");    if (id->method == "MKCOL") {    return Roxen.http_status(201, "Created");    }    return Roxen.http_string_answer("Ok");    } else { -  +  privs = 0;    SIMPLE_TRACE_LEAVE("%s: Failed (errcode:%d)", id->method, errcode);    TRACE_LEAVE("Failure");    if (id->method == "MKCOL") {    if (err_code ==   #if constant(system.ENOENT)    system.ENOENT   #elif constant(System.ENOENT)    System.ENOENT   #else    2
Roxen.git/server/modules/filesystems/filesystem.pike:1048:    }       if(!to)    {    privs = 0;    TRACE_LEAVE("PUT: Open failed");    return errno_to_status (err, 1, id);    }       // FIXME: Race-condition. -  chmod(f, 0666 & ~(id->misc->umask || 022)); +  string msg = safe_chmod(f, 0666 & ~(id->misc->umask || 022));    privs = 0;       putting[id->my_fd] = id->misc->len;    if(id->data && strlen(id->data))    {    // FIXME: What if sizeof(id->data) > id->misc->len ?    if (id->misc->len > 0) {    putting[id->my_fd] -= strlen(id->data);    }    int bytes = to->write( id->data );
Roxen.git/server/modules/filesystems/filesystem.pike:1120:       SETUID_TRACE("CHMODing file", 0);       if (query("no_symlinks") && (contains_symlinks(path, oldf))) {    privs = 0;    errors++;    TRACE_LEAVE("CHMOD: Contains symlinks. Permission denied");    return Roxen.http_status(403, "Permission denied.");    }    -  array err = catch(chmod(f, id->misc->mode & 0777)); +  string msg = safe_chmod(f, id->misc->mode & 0777);    int err_code = errno();    privs = 0;       chmods++;       TRACE_ENTER("CHMOD: Accepted", 0);       if (stat_cache) {    cache_set("stat_cache", f, 0);    }    -  if(err) +  if(msg)    { -  TRACE_LEAVE("CHMOD: Failure"); +  TRACE_LEAVE(sprintf("CHMOD: Failure: %s", msg));    return errno_to_status (err_code, 0, id);    }    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.   
Roxen.git/server/modules/filesystems/filesystem.pike:1591:    }    }       if (source_st->isdir) {    mkdirs++;    object privs;    SETUID_TRACE("Creating directory/collection", 0);       int code = mkdir(dest_path);    int err_code = errno(); -  privs = 0; +        if (code) { -  chmod(dest_path, 0777 & ~(id->misc->umask || 022)); +  string msg = safe_chmod(dest_path, 0777 & ~(id->misc->umask || 022)); +  privs = 0; +  if (msg) { +  TRACE_LEAVE(sprintf("Chmod %O failed: %s", dest_path, msg)); +  } else {    TRACE_LEAVE("Success"); -  +  }    return Roxen.http_status(dest_st?204:201, "Created");    } else {    return errno_to_status (err_code, 1, id);    }    } else {    string source_path = path + source;    catch { source_path = decode_path(source_path); };    source_path = NORMALIZE_PATH (source_path);    if (query("no_symlinks") && (contains_symlinks(path, source_path))) {    errors++;