d69ba5 | 2001-09-03 | Martin Nilsson | |
|
57f45e | 1996-11-27 | Per Hedbor | |
|
b1fca0 | 1996-11-12 | Per Hedbor | |
|
57f45e | 1996-11-27 | Per Hedbor | |
|
f6d62d | 1997-03-26 | Per Hedbor | |
|
190901 | 1998-02-24 | Henrik Grubbström (Grubba) | | inherit "module";
inherit "socket";
|
219575 | 2002-06-14 | Martin Nilsson | | constant cvs_version = "$Id: filesystem.pike,v 1.118 2002/06/13 22:33:05 nilsson Exp $";
|
50ec73 | 2002-06-13 | Martin Nilsson | | constant thread_safe = 1;
|
6682b9 | 1997-08-31 | Peter Bortas | |
|
b1fca0 | 1996-11-12 | Per Hedbor | | #include <module.h>
|
14179b | 1997-01-29 | Per Hedbor | | #include <stat.h>
|
c5e096 | 1999-10-04 | Per Hedbor | | #include <request_trace.h>
|
219575 | 2002-06-14 | Martin Nilsson | | #include <roxen.h>
#define LOCALE(X,Y) _STR_LOCALE("mod_filesystem",X,Y)
|
b1fca0 | 1996-11-12 | Per Hedbor | |
|
ac69b5 | 1999-12-28 | Martin Nilsson | | #ifdef FILESYSTEM_DEBUG
# define FILESYSTEM_WERR(X) werror("Filesystem: "+X+"\n")
#else
# define FILESYSTEM_WERR(X)
#endif
#ifdef QUOTA_DEBUG
# define QUOTA_WERR(X) werror("QUOTA: "+X+"\n")
#else
# define QUOTA_WERR(X)
#endif
|
c7ec63 | 2001-08-15 | Henrik Grubbström (Grubba) | | #if constant(system.normalize_path)
#define NORMALIZE_PATH(X) system.normalize_path(X)
#else /* !constant(system.normalize_path) */
#define NORMALIZE_PATH(X) (X)
#endif /* constant(system.normalize_path) */
|
c5e096 | 1999-10-04 | Per Hedbor | | constant module_type = MODULE_LOCATION;
|
50ec73 | 2002-06-13 | Martin Nilsson | | constant module_name = "File systems: Normal File system";
constant module_doc =
("This is the basic file system module that makes it possible "
"to mount a directory structure in the virtual file system of "
"your site.");
|
c5e096 | 1999-10-04 | Per Hedbor | | constant module_unique = 0;
|
639611 | 1997-02-14 | Per Hedbor | |
|
b1fca0 | 1996-11-12 | Per Hedbor | | int redirects, accesses, errors, dirlists;
|
6cec00 | 1998-05-14 | David Hedbor | | int puts, deletes, mkdirs, moves, chmods;
|
b1fca0 | 1996-11-12 | Per Hedbor | |
|
1358d5 | 1999-05-06 | Henrik Grubbström (Grubba) | | static mapping http_low_answer(int errno, string data, string|void desc)
{
|
7f5966 | 2000-05-16 | Henrik Grubbström (Grubba) | | mapping res = Roxen.http_low_answer(errno, data);
|
1358d5 | 1999-05-06 | Henrik Grubbström (Grubba) | |
if (desc) {
res->rettext = desc;
}
return res;
}
|
b1fca0 | 1996-11-12 | Per Hedbor | | static int do_stat = 1;
string status()
{
|
50ec73 | 2002-06-13 | Martin Nilsson | | 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 />":"")+
|
ed540b | 2001-01-13 | Martin Nilsson | | (query("put")&&query("delete")&&moves?
|
50ec73 | 2002-06-13 | Martin Nilsson | | "<b>Moved files</b>: "+moves+"<br />":"")+
(query("put")&&chmods?"<b>CHMODs</b>: "+chmods+"<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 />":"");
|
b1fca0 | 1996-11-12 | Per Hedbor | | }
void create()
{
|
50ec73 | 2002-06-13 | Martin Nilsson | | defvar("mountpoint", "/", "Mount point",
|
b1e867 | 2001-08-01 | Per Hedbor | | TYPE_LOCATION|VAR_INITIAL|VAR_NO_DEFAULT,
|
50ec73 | 2002-06-13 | Martin Nilsson | | "Where the module will be mounted in the site's virtual file system.");
|
79ca87 | 2000-11-24 | Per Hedbor | |
|
50ec73 | 2002-06-13 | Martin Nilsson | | defvar("searchpath", "NONE", "Search path",
|
b1e867 | 2001-08-01 | Per Hedbor | | TYPE_DIR|VAR_INITIAL|VAR_NO_DEFAULT,
|
50ec73 | 2002-06-13 | Martin Nilsson | | "The directory that contains the files.");
|
79ca87 | 2000-11-24 | Per Hedbor | |
|
50ec73 | 2002-06-13 | Martin Nilsson | | defvar(".files", 0, "Show hidden files", TYPE_FLAG|VAR_MORE,
("If set, hidden files, ie files that begin with a '.', "
"will be shown in directory listings." ));
|
79ca87 | 2000-11-24 | Per Hedbor | |
|
50ec73 | 2002-06-13 | Martin Nilsson | | defvar("dir", 1, "Enable directory listings per default",
|
79ca87 | 2000-11-24 | Per Hedbor | | TYPE_FLAG|VAR_MORE,
|
50ec73 | 2002-06-13 | Martin Nilsson | | ("If set, it will be possible to get a directory listings "
"from directories in this file system. It is possible to "
"force a directory to never be browsable by putting a "
"<tt>.www_not_browsable</tt> or a <tt>.nodiraccess</tt> file "
"in it. Similarly it is possible to let a directory be "
"browsable, even if the file system is not, by putting a "
"<tt>.www_browsable</tt> file in it.\n"));
|
b1fca0 | 1996-11-12 | Per Hedbor | |
|
c4908f | 2000-05-06 | Martin Nilsson | | defvar("nobrowse", ({ ".www_not_browsable", ".nodiraccess" }),
|
50ec73 | 2002-06-13 | Martin Nilsson | | "List prevention files", TYPE_STRING_LIST|VAR_MORE,
"All directories containing any of these files will not be browsable.");
|
c4908f | 2000-05-06 | Martin Nilsson | |
|
50ec73 | 2002-06-13 | Martin Nilsson | | defvar("tilde", 0, "Show backup files", TYPE_FLAG|VAR_MORE,
("If set, files ending with '~', '#' or '.bak' will "
"be shown in directory listings"));
|
c4908f | 2000-05-06 | Martin Nilsson | |
|
50ec73 | 2002-06-13 | Martin Nilsson | | defvar("put", 0, "Handle the PUT method", TYPE_FLAG,
("If set, it will be possible to upload files with the HTTP "
"method PUT, or through FTP."));
|
b1fca0 | 1996-11-12 | Per Hedbor | |
|
50ec73 | 2002-06-13 | Martin Nilsson | | defvar("delete", 0, "Handle the DELETE method", TYPE_FLAG,
("If set, it will be possible to delete files with the HTTP "
"method DELETE, or through FTP."));
|
b1fca0 | 1996-11-12 | Per Hedbor | |
|
50ec73 | 2002-06-13 | Martin Nilsson | | defvar("check_auth", 1, "Require authentication for modification",
|
b1fca0 | 1996-11-12 | Per Hedbor | | TYPE_FLAG,
|
50ec73 | 2002-06-13 | Martin Nilsson | | ("Only allow users authenticated by a authentication module "
"to use methods that can modify the files, such as PUT or "
"DELETE. If this is not set the file system will be a "
"<b>very</b> public one since anyone will be able to edit "
"files."));
|
14179b | 1997-01-29 | Per Hedbor | |
|
50ec73 | 2002-06-13 | Martin Nilsson | | defvar("stat_cache", 0, "Cache the results of stat(2)",
|
79ca87 | 2000-11-24 | Per Hedbor | | TYPE_FLAG|VAR_MORE,
|
50ec73 | 2002-06-13 | Martin Nilsson | | ("A performace option that can speed up retrieval of files "
"from NFS with up to 50%. In turn it uses some memory and the "
"file system will not notice that files have changed unless "
"it gets a pragma no-cache request (produced e.g. by "
"Alt-Ctrl-Reload in Netscape). Therefore this option should "
"not be used on file systems that change a lot."));
defvar("access_as_user", 0, "Access files as the logged in user",
|
9b9f70 | 1997-08-12 | Per Hedbor | | TYPE_FLAG|VAR_MORE,
|
50ec73 | 2002-06-13 | Martin Nilsson | | ("If set, the module will access files as the authenticated "
"user. This assumes that a authentication module which imports"
" the users from the operating systems, such as the <i>User "
"database</i> module is used. This option is very useful for "
"named FTP sites, but it will have severe performance impacts "
"since all threads will be locked for each access."));
|
79ca87 | 2000-11-24 | Per Hedbor | |
|
527dc3 | 2001-09-21 | Per Hedbor | | defvar("access_as_user_db",
Variable.UserDBChoice( " all", VAR_MORE,
|
50ec73 | 2002-06-13 | Martin Nilsson | | "Authentication database to use",
("The User database module to use "
"when authenticating users for the "
"access file as the logged in user "
"feature."),
|
527dc3 | 2001-09-21 | Per Hedbor | | my_configuration()));
defvar( "access_as_user_throw", 0,
|
50ec73 | 2002-06-13 | Martin Nilsson | | "Access files as the logged in user forces login",
|
527dc3 | 2001-09-21 | Per Hedbor | | TYPE_FLAG|VAR_MORE,
|
50ec73 | 2002-06-13 | Martin Nilsson | | ("If true, a user will have to be logged in to access files in "
"this filesystem") );
|
527dc3 | 2001-09-21 | Per Hedbor | |
|
50ec73 | 2002-06-13 | Martin Nilsson | | defvar("no_symlinks", 0, "Forbid access to symlinks",
|
9b9f70 | 1997-08-12 | Per Hedbor | | TYPE_FLAG|VAR_MORE,
|
50ec73 | 2002-06-13 | Martin Nilsson | | ("It set, the file system will not follow symbolic links. "
"This option can lower performace by a lot." ));
|
79ca87 | 2000-11-24 | Per Hedbor | |
|
50ec73 | 2002-06-13 | Martin Nilsson | | defvar("charset", "iso-8859-1", "File contents charset",
|
79ca87 | 2000-11-24 | Per Hedbor | | TYPE_STRING,
|
50ec73 | 2002-06-13 | Martin Nilsson | | ("The charset of the contents of the files on this file "
"system. This variable makes it possible for Roxen to use "
"any text file, no matter what charset it is written in. If "
"necessary, Roxen will convert the file to Unicode before "
"processing the file."));
|
79ca87 | 2000-11-24 | Per Hedbor | |
|
50ec73 | 2002-06-13 | Martin Nilsson | | defvar("path_encoding", "iso-8859-1", "Filename charset",
|
79ca87 | 2000-11-24 | Per Hedbor | | TYPE_STRING,
|
50ec73 | 2002-06-13 | Martin Nilsson | | ("The charset of the file names of the files on this file "
"system. Unlike the <i>File contents charset</i> variable, "
"this might not work for all charsets simply because not "
"all browsers support anything except ISO-8859-1 "
"in URLs."));
defvar("internal_files", ({}), "Internal files", TYPE_STRING_LIST,
("A list of glob patterns that matches files which should be "
"considered internal. Internal files cannot be requested "
"directly from a browser, won't show up in directory listings "
"and can never be uploaded, moved or deleted by a browser."
"They can only be accessed internally, e.g. with the RXML tags "
"<tt><insert></tt> and <tt><use></tt>."));
|
54b480 | 2000-03-07 | Martin Stjernholm | | }
|
c7ec63 | 2001-08-15 | Henrik Grubbström (Grubba) | | string path, mountpoint, charset, path_encoding, normalized_path;
|
a2f3c7 | 2000-08-13 | Per Hedbor | | int stat_cache, dotfiles, access_as_user, no_symlinks, tilde;
array(string) internal_files;
|
527dc3 | 2001-09-21 | Per Hedbor | | UserDB access_as_user_db;
int access_as_user_throw;
|
b1fca0 | 1996-11-12 | Per Hedbor | | void start()
{
|
ed540b | 2001-01-13 | Martin Nilsson | | tilde = query("tilde");
charset = query("charset");
path_encoding = query("path_encoding");
no_symlinks = query("no_symlinks");
access_as_user = query("access_as_user");
|
527dc3 | 2001-09-21 | Per Hedbor | | access_as_user_throw = query("access_as_user_throw");
access_as_user_db =
my_configuration()->find_user_database( query("access_as_user_db") );
|
ed540b | 2001-01-13 | Martin Nilsson | | dotfiles = query(".files");
path = query("searchpath");
mountpoint = query("mountpoint");
stat_cache = query("stat_cache");
internal_files = query("internal_files");
|
527dc3 | 2001-09-21 | Per Hedbor | |
|
c7ec63 | 2001-08-15 | Henrik Grubbström (Grubba) | | #if constant(system.normalize_path)
if (catch {
if ((<'/','\\'>)[path[-1]]) {
normalized_path = system.normalize_path(path + ".");
} else {
normalized_path = system.normalize_path(path);
}
#ifdef __NT__
normalized_path += "\\";
#else /* !__NT__ */
normalized_path += "/";
#endif /* __NT__ */
}) {
|
50ec73 | 2002-06-13 | Martin Nilsson | | report_error("Path verification of %s failed.\n", mountpoint);
|
c7ec63 | 2001-08-15 | Henrik Grubbström (Grubba) | | normalized_path = path;
}
#else /* !constant(system.normalize_path) */
normalized_path = path;
#endif /* constant(system.normalize_path) */
|
ed540b | 2001-01-13 | Martin Nilsson | | FILESYSTEM_WERR("Online at "+query("mountpoint")+" (path="+path+")");
|
8d10df | 2000-01-06 | Martin Stjernholm | | cache_expire("stat_cache");
|
b1fca0 | 1996-11-12 | Per Hedbor | | }
string query_location()
{
|
a2f3c7 | 2000-08-13 | Per Hedbor | | return mountpoint;
|
b1fca0 | 1996-11-12 | Per Hedbor | | }
|
54b480 | 2000-03-07 | Martin Stjernholm | | #define FILTER_INTERNAL_FILE(f, id) \
|
a2f3c7 | 2000-08-13 | Per Hedbor | | (!id->misc->internal_get && sizeof (filter (internal_files, glob, (f/"/")[-1])))
|
54b480 | 2000-03-07 | Martin Stjernholm | |
|
4bc95b | 2001-09-11 | Per Hedbor | | #define SETUID(X) \
|
31eeb5 | 2001-12-21 | Henrik Grubbström (Grubba) | | if( access_as_user && !id->misc->internal_get) \
|
4bc95b | 2001-09-11 | Per Hedbor | | { \
|
527dc3 | 2001-09-21 | Per Hedbor | | User uid = id->conf->authenticate( id,access_as_user_db ); \
if( access_as_user_throw && !uid ) \
return id->conf->authenticate_throw( id, "User",access_as_user_db);\
if( uid && uid->uid() ) \
privs=Privs(X, uid->uid(), uid->gid() ); \
}
|
4dea32 | 2001-12-21 | Henrik Grubbström (Grubba) | | #define SETUID_TRACE(X,LEVELS) \
|
31eeb5 | 2001-12-21 | Henrik Grubbström (Grubba) | | if( access_as_user && !id->misc->internal_get) \
|
4dea32 | 2001-12-21 | Henrik Grubbström (Grubba) | | { \
User uid = id->conf->authenticate( id,access_as_user_db ); \
if( access_as_user_throw && !uid ) { \
int levels = (LEVELS); \
while(levels--) TRACE_LEAVE(""); \
TRACE_LEAVE(X ": Auth required."); \
return id->conf->authenticate_throw( id, "User",access_as_user_db);\
} \
if( uid && uid->uid() ) \
privs=Privs(X, uid->uid(), uid->gid() ); \
}
|
527dc3 | 2001-09-21 | Per Hedbor | | #define SETUID_NT(X) \
|
31eeb5 | 2001-12-21 | Henrik Grubbström (Grubba) | | if( access_as_user && !id->misc->internal_get ) \
|
527dc3 | 2001-09-21 | Per Hedbor | | { \
User uid = id->conf->authenticate( id,access_as_user_db ); \
|
4bc95b | 2001-09-11 | Per Hedbor | | if( uid && uid->uid() ) \
privs=Privs(X, uid->uid(), uid->gid() ); \
}
|
54b480 | 2000-03-07 | Martin Stjernholm | | mixed stat_file( string f, RequestID id )
|
b1fca0 | 1996-11-12 | Per Hedbor | | {
|
1f4a6c | 2000-08-28 | Per Hedbor | | Stat fs;
|
54b480 | 2000-03-07 | Martin Stjernholm | |
|
cdf053 | 2000-06-23 | Martin Stjernholm | | FILESYSTEM_WERR("stat_file for \""+f+"\"" +
(id->misc->internal_get ? " (internal)" : ""));
|
54b480 | 2000-03-07 | Martin Stjernholm | |
|
2c0a3e | 2001-08-13 | Per Hedbor | | f = path+f;
|
ae4620 | 2001-06-27 | Per Hedbor | | if (FILTER_INTERNAL_FILE (f, id))
return 0;
|
54b480 | 2000-03-07 | Martin Stjernholm | |
|
64c51c | 1997-10-11 | Henrik Grubbström (Grubba) | | if(stat_cache && !id->pragma["no-cache"] &&
|
2c0a3e | 2001-08-13 | Per Hedbor | | (fs=cache_lookup("stat_cache",f)))
|
1b8f6b | 1998-02-24 | Per Hedbor | | return fs[0];
object privs;
|
527dc3 | 2001-09-21 | Per Hedbor | | SETUID_NT("Statting file");
|
8afc81 | 1998-02-04 | Per Hedbor | |
|
ec0dab | 2000-04-03 | Per Hedbor | |
|
2c0a3e | 2001-08-13 | Per Hedbor | | fs = file_stat(decode_path(f));
|
64c51c | 1997-10-11 | Henrik Grubbström (Grubba) | | privs = 0;
|
a2f3c7 | 2000-08-13 | Per Hedbor | | if(!stat_cache) return fs;
|
2c0a3e | 2001-08-13 | Per Hedbor | | cache_set("stat_cache", f, ({fs}));
|
14179b | 1997-01-29 | Per Hedbor | | return fs;
|
b1fca0 | 1996-11-12 | Per Hedbor | | }
|
54b480 | 2000-03-07 | Martin Stjernholm | | string real_file( string f, RequestID id )
|
b1fca0 | 1996-11-12 | Per Hedbor | | {
|
c7ec63 | 2001-08-15 | Henrik Grubbström (Grubba) | | if(stat_file( f, id )) {
catch {
return NORMALIZE_PATH(decode_path(path + f));
};
}
|
b1fca0 | 1996-11-12 | Per Hedbor | | }
|
54b480 | 2000-03-07 | Martin Stjernholm | | int dir_filter_function(string f, RequestID id)
|
b1fca0 | 1996-11-12 | Per Hedbor | | {
|
a2f3c7 | 2000-08-13 | Per Hedbor | | if(f[0]=='.' && !dotfiles) return 0;
if(!tilde && Roxen.backup_extension(f)) return 0;
|
b1fca0 | 1996-11-12 | Per Hedbor | | return 1;
}
|
c4908f | 2000-05-06 | Martin Nilsson | | array(string) list_lock_files() {
|
ed540b | 2001-01-13 | Martin Nilsson | | return query("nobrowse");
|
c4908f | 2000-05-06 | Martin Nilsson | | }
|
54b480 | 2000-03-07 | Martin Stjernholm | | array find_dir( string f, RequestID id )
|
b1fca0 | 1996-11-12 | Per Hedbor | | {
array dir;
|
cdf053 | 2000-06-23 | Martin Stjernholm | | FILESYSTEM_WERR("find_dir for \""+f+"\"" +
(id->misc->internal_get ? " (internal)" : ""));
|
54b480 | 2000-03-07 | Martin Stjernholm | |
|
0216e2 | 1997-08-12 | Henrik Grubbström (Grubba) | | object privs;
|
527dc3 | 2001-09-21 | Per Hedbor | | SETUID_NT("Read dir");
|
0216e2 | 1997-08-12 | Henrik Grubbström (Grubba) | |
|
c7ec63 | 2001-08-15 | Henrik Grubbström (Grubba) | | if (catch {
f = NORMALIZE_PATH(decode_path(path + f));
} || !(dir = get_dir(f))) {
|
64c51c | 1997-10-11 | Henrik Grubbström (Grubba) | | privs = 0;
|
b1fca0 | 1996-11-12 | Per Hedbor | | return 0;
|
64c51c | 1997-10-11 | Henrik Grubbström (Grubba) | | }
|
0216e2 | 1997-08-12 | Henrik Grubbström (Grubba) | | privs = 0;
|
ed540b | 2001-01-13 | Martin Nilsson | | if(!query("dir"))
|
b1fca0 | 1996-11-12 | Per Hedbor | |
|
c4908f | 2000-05-06 | Martin Nilsson | | if(! has_value(dir, ".www_browsable"))
|
b1fca0 | 1996-11-12 | Per Hedbor | | {
errors++;
return 0;
}
|
ed540b | 2001-01-13 | Martin Nilsson | | if( sizeof(dir & query("nobrowse")) )
|
b1fca0 | 1996-11-12 | Per Hedbor | | {
errors++;
return 0;
}
dirlists++;
|
a2f3c7 | 2000-08-13 | Per Hedbor | | if(tilde && dotfiles &&
(!sizeof( internal_files ) || id->misc->internal_get))
|
b1fca0 | 1996-11-12 | Per Hedbor | | return dir;
|
3bf15e | 2000-03-08 | Martin Stjernholm | | dir = Array.filter(dir, dir_filter_function, id);
if (!id->misc->internal_get)
|
a2f3c7 | 2000-08-13 | Per Hedbor | | foreach (internal_files, string globstr)
|
3bf15e | 2000-03-08 | Martin Stjernholm | | dir -= glob (globstr, dir);
return dir;
|
b1fca0 | 1996-11-12 | Per Hedbor | | }
mapping putting = ([]);
|
2f8308 | 1999-05-05 | Henrik Grubbström (Grubba) | | void done_with_put( array(object|string) id_arr )
|
b1fca0 | 1996-11-12 | Per Hedbor | | {
|
b3ef2d | 1999-12-18 | Martin Nilsson | |
|
2f8308 | 1999-05-05 | Henrik Grubbström (Grubba) | | object to;
object from;
object id;
string oldf;
[to, from, id, oldf] = id_arr;
|
ac69b5 | 1999-12-28 | Martin Nilsson | | FILESYSTEM_WERR(sprintf("done_with_put(%O)\n"
"from: %O\n",
id_arr, mkmapping(indices(from), values(from))));
|
1358d5 | 1999-05-06 | Henrik Grubbström (Grubba) | |
|
2f8308 | 1999-05-05 | Henrik Grubbström (Grubba) | | to->close();
from->set_blocking();
m_delete(putting, from);
if (putting[from] && (putting[from] != 0x7fffffff)) {
|
016316 | 1999-04-21 | Henrik Grubbström (Grubba) | |
|
219575 | 2002-06-14 | Martin Nilsson | | id->send_result(http_low_answer
(400,
"<h2>" + LOCALE(63, "Bad Request - Expected more data.") +
"</h2>"));
} else
id->send_result(http_low_answer
(200, "<h2>" + LOCALE(64, "Transfer Complete.") + "</h2>"));
|
b1fca0 | 1996-11-12 | Per Hedbor | | }
|
2f8308 | 1999-05-05 | Henrik Grubbström (Grubba) | | void got_put_data( array (object|string) id_arr, string data )
|
b1fca0 | 1996-11-12 | Per Hedbor | | {
|
b3ef2d | 1999-12-18 | Martin Nilsson | |
|
2f8308 | 1999-05-05 | Henrik Grubbström (Grubba) | |
object to;
object from;
object id;
string oldf;
[to, from, id, oldf] = id_arr;
|
016316 | 1999-04-21 | Henrik Grubbström (Grubba) | |
|
2f8308 | 1999-05-05 | Henrik Grubbström (Grubba) | | 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);
|
219575 | 2002-06-14 | Martin Nilsson | | id->send_result(http_low_answer
(413, "<h2>" + LOCALE(65, "Out of disk quota.") + "</h2>",
"413 " + LOCALE(65, "Out of disk quota.") ));
|
2f8308 | 1999-05-05 | Henrik Grubbström (Grubba) | | return;
}
|
016316 | 1999-04-21 | Henrik Grubbström (Grubba) | |
|
2f8308 | 1999-05-05 | Henrik Grubbström (Grubba) | | int bytes = to->write( data );
|
016316 | 1999-04-21 | Henrik Grubbström (Grubba) | | if (bytes < sizeof(data)) {
|
2f8308 | 1999-05-05 | Henrik Grubbström (Grubba) | | to->close();
from->set_blocking();
m_delete(putting, from);
|
219575 | 2002-06-14 | Martin Nilsson | | id->send_result(http_low_answer(413, "<h2>" + LOCALE(66, "Disk full.") + "</h2>"));
|
2f8308 | 1999-05-05 | Henrik Grubbström (Grubba) | | return;
|
016316 | 1999-04-21 | Henrik Grubbström (Grubba) | | } else {
|
2f8308 | 1999-05-05 | Henrik Grubbström (Grubba) | | if (id->misc->quota_obj &&
!id->misc->quota_obj->allocate(oldf, bytes)) {
to->close();
from->set_blocking();
m_delete(putting, from);
|
219575 | 2002-06-14 | Martin Nilsson | | id->send_result(http_low_answer
(413, "<h2>" + LOCALE(65, "Out of disk quota.") + "</h2>",
"413 " + LOCALE(65, "Out of disk quota.") ));
|
2f8308 | 1999-05-05 | Henrik Grubbström (Grubba) | | return;
}
if (putting[from] != 0x7fffffff) {
putting[from] -= bytes;
|
32b4ba | 1999-04-21 | Henrik Grubbström (Grubba) | | }
|
2f8308 | 1999-05-05 | Henrik Grubbström (Grubba) | | if(putting[from] <= 0) {
putting[from] = 0;
done_with_put( id_arr );
|
016316 | 1999-04-21 | Henrik Grubbström (Grubba) | | }
}
|
b1fca0 | 1996-11-12 | Per Hedbor | | }
|
ec0dab | 2000-04-03 | Per Hedbor | | string decode_path( string p )
{
|
a2f3c7 | 2000-08-13 | Per Hedbor | | if( path_encoding != "iso-8859-1" )
p = Locale.Charset.encoder( path_encoding )->feed( p )->drain();
|
ec0dab | 2000-04-03 | Per Hedbor | | #ifndef __NT__
if( String.width( p ) != 8 )
p = string_to_utf8( p );
|
3f286a | 2000-08-23 | Per Hedbor | | #else
while( strlen(p) && p[-1] == '/' )
p = p[..strlen(p)-2];
|
ec0dab | 2000-04-03 | Per Hedbor | | #endif
return p;
}
|
c9e036 | 2000-08-28 | Johan Sundström | | int _file_size(string X, RequestID id)
|
14179b | 1997-01-29 | Per Hedbor | | {
|
1f4a6c | 2000-08-28 | Per Hedbor | | Stat fs;
|
a2f3c7 | 2000-08-13 | Per Hedbor | | if( stat_cache )
|
14179b | 1997-01-29 | Per Hedbor | | {
|
c9e036 | 2000-08-28 | Johan Sundström | | array(Stat) cached_fs;
if(!id->pragma["no-cache"] &&
(cached_fs = cache_lookup("stat_cache", X)))
|
a2f3c7 | 2000-08-13 | Per Hedbor | | {
|
c9e036 | 2000-08-28 | Johan Sundström | | id->misc->stat = cached_fs[0];
return cached_fs[0] ? cached_fs[0][ST_SIZE] : -1;
|
a2f3c7 | 2000-08-13 | Per Hedbor | | }
|
14179b | 1997-01-29 | Per Hedbor | | }
|
ec0dab | 2000-04-03 | Per Hedbor | | if(fs = file_stat(decode_path(X)))
|
14179b | 1997-01-29 | Per Hedbor | | {
id->misc->stat = fs;
|
a2f3c7 | 2000-08-13 | Per Hedbor | | if( stat_cache ) cache_set("stat_cache",(X),({fs}));
|
14179b | 1997-01-29 | Per Hedbor | | return fs[ST_SIZE];
|
a2f3c7 | 2000-08-13 | Per Hedbor | | } else if( stat_cache )
|
1b8f6b | 1998-02-24 | Per Hedbor | | cache_set("stat_cache",(X),({0}));
|
14179b | 1997-01-29 | Per Hedbor | | return -1;
}
|
afb158 | 1997-07-06 | Henrik Grubbström (Grubba) | | int contains_symlinks(string root, string path)
{
array arr = path/"/";
|
1f4a6c | 2000-08-28 | Per Hedbor | | Stat rr;
|
afb158 | 1997-07-06 | Henrik Grubbström (Grubba) | |
foreach(arr - ({ "" }), path) {
root += "/" + path;
|
1f4a6c | 2000-08-28 | Per Hedbor | | if (rr = file_stat(decode_path(root), 1)) {
if (rr[1] == -3) {
|
afb158 | 1997-07-06 | Henrik Grubbström (Grubba) | | return(1);
}
} else {
return(0);
}
}
return(0);
}
|
54b480 | 2000-03-07 | Martin Stjernholm | | mixed find_file( string f, RequestID id )
|
b1fca0 | 1996-11-12 | Per Hedbor | | {
|
8afb50 | 1998-04-15 | Henrik Grubbström (Grubba) | | TRACE_ENTER("find_file(\""+f+"\")", 0);
|
b1fca0 | 1996-11-12 | Per Hedbor | | object o;
int size;
string tmp;
|
afb158 | 1997-07-06 | Henrik Grubbström (Grubba) | | string oldf = f;
|
01128d | 1998-04-27 | Henrik Grubbström (Grubba) | |
|
cdf053 | 2000-06-23 | Martin Stjernholm | | FILESYSTEM_WERR("Request for \""+f+"\"" +
(id->misc->internal_get ? " (internal)" : ""));
|
01128d | 1998-04-27 | Henrik Grubbström (Grubba) | |
|
a2f3c7 | 2000-08-13 | Per Hedbor | |
|
c7ec63 | 2001-08-15 | Henrik Grubbström (Grubba) | | #define URI combine_path(mountpoint + "/" + oldf, ".")
|
1358d5 | 1999-05-06 | Henrik Grubbström (Grubba) | |
|
c7ec63 | 2001-08-15 | Henrik Grubbström (Grubba) | | string norm_f;
catch {
f = norm_f = NORMALIZE_PATH(f = decode_path(path + f));
#if constant(system.normalize_path)
|
bd2508 | 2001-08-16 | Henrik Grubbström (Grubba) | | if (!has_prefix(norm_f, normalized_path) &&
|
b0f68e | 2001-08-16 | Henrik Grubbström (Grubba) | | #ifdef __NT__
|
328277 | 2001-08-16 | Henrik Grubbström (Grubba) | | (norm_f+"\\" != normalized_path)
|
b0f68e | 2001-08-16 | Henrik Grubbström (Grubba) | | #else /* !__NT__ */
(norm_f+"/" != normalized_path)
#endif /* __NT__ */
) {
|
c7ec63 | 2001-08-15 | Henrik Grubbström (Grubba) | | errors++;
|
50ec73 | 2002-06-13 | Martin Nilsson | | report_error("Path verification of %O failed:\n"
"%O is not a prefix of %O\n",
oldf, normalized_path, norm_f);
|
c7ec63 | 2001-08-15 | Henrik Grubbström (Grubba) | | TRACE_LEAVE("");
TRACE_LEAVE("Permission denied.");
|
219575 | 2002-06-14 | Martin Nilsson | | return http_low_answer
(403, "<h2>" + LOCALE(67, "File exists, but access forbidden by user.") + "</h2>");
|
c7ec63 | 2001-08-15 | Henrik Grubbström (Grubba) | | }
|
b0f68e | 2001-08-16 | Henrik Grubbström (Grubba) | |
|
c7ec63 | 2001-08-15 | Henrik Grubbström (Grubba) | | id->not_query = mountpoint + replace(norm_f[sizeof(normalized_path)..],
"\\", "/");
|
bd2508 | 2001-08-16 | Henrik Grubbström (Grubba) | | if (sizeof(oldf) && (oldf[-1] == '/')) {
id->not_query += "/";
}
|
c7ec63 | 2001-08-15 | Henrik Grubbström (Grubba) | | #endif /* constant(system.normalize_path) */
};
|
a2f3c7 | 2000-08-13 | Per Hedbor | |
size = _file_size( f, id );
|
b1fca0 | 1996-11-12 | Per Hedbor | |
|
9e759c | 2001-09-11 | Henrik Grubbström (Grubba) | | FILESYSTEM_WERR(sprintf("_file_size(%O, %O) ==> %d\n", f, id, size));
|
465eb6 | 1998-08-26 | Henrik Grubbström (Grubba) | |
|
b04ec8 | 2000-01-31 | Per Hedbor | |
|
b1fca0 | 1996-11-12 | Per Hedbor | | switch(id->method)
{
case "GET":
case "HEAD":
case "POST":
|
b04ec8 | 2000-01-31 | Per Hedbor | |
|
b1fca0 | 1996-11-12 | Per Hedbor | | switch(-size)
{
case 1:
|
8afb50 | 1998-04-15 | Henrik Grubbström (Grubba) | | case 3:
case 4:
TRACE_LEAVE("No file");
|
b1fca0 | 1996-11-12 | Per Hedbor | | return 0;
case 2:
|
8afb50 | 1998-04-15 | Henrik Grubbström (Grubba) | | TRACE_LEAVE("Is directory");
|
b1fca0 | 1996-11-12 | Per Hedbor | | return -1;
default:
|
c7ec63 | 2001-08-15 | Henrik Grubbström (Grubba) | | if( oldf[ -1 ] == '/' ||
!norm_f) {
|
b04ec8 | 2000-01-31 | Per Hedbor | | return 0;
|
c7ec63 | 2001-08-15 | Henrik Grubbström (Grubba) | | }
|
b1fca0 | 1996-11-12 | Per Hedbor | |
|
a2f3c7 | 2000-08-13 | Per Hedbor | | if(!id->misc->internal_get)
{
if (!dotfiles
|
0fb1b1 | 2000-03-26 | Martin Stjernholm | | && sizeof (tmp = (id->not_query/"/")[-1])
|
a2f3c7 | 2000-08-13 | Per Hedbor | | && tmp[0] == '.')
{
|
54b480 | 2000-03-07 | Martin Stjernholm | | TRACE_LEAVE("Is .-file");
return 0;
}
|
a2f3c7 | 2000-08-13 | Per Hedbor | | if (FILTER_INTERNAL_FILE (f, id))
{
|
54b480 | 2000-03-07 | Martin Stjernholm | | TRACE_LEAVE ("Is internal file");
return 0;
}
|
8afb50 | 1998-04-15 | Henrik Grubbström (Grubba) | | }
|
5e5fd6 | 2000-03-07 | Martin Stjernholm | |
TRACE_ENTER("Opening file \"" + f + "\"", 0);
|
1b8f6b | 1998-02-24 | Per Hedbor | | object privs;
|
4dea32 | 2001-12-21 | Henrik Grubbström (Grubba) | | SETUID_TRACE("Open file", 1);
|
a2f3c7 | 2000-08-13 | Per Hedbor | |
o = Stdio.File( );
|
c7ec63 | 2001-08-15 | Henrik Grubbström (Grubba) | | if(!o->open(norm_f, "r" )) o = 0;
|
2e7c23 | 1997-06-10 | Henrik Grubbström (Grubba) | | privs = 0;
|
a2f3c7 | 2000-08-13 | Per Hedbor | | if(!o || (no_symlinks && (contains_symlinks(path, oldf))))
|
b1fca0 | 1996-11-12 | Per Hedbor | | {
errors++;
|
50ec73 | 2002-06-13 | Martin Nilsson | | report_error("Open of %s failed. Permission denied.\n",f);
|
b04ec8 | 2000-01-31 | Per Hedbor | |
|
8afb50 | 1998-04-15 | Henrik Grubbström (Grubba) | | TRACE_LEAVE("");
TRACE_LEAVE("Permission denied.");
|
219575 | 2002-06-14 | Martin Nilsson | | return http_low_answer
(403, "<h2>" + LOCALE(67, "File exists, but access forbidden by user.") +
"</h2>");
|
b1fca0 | 1996-11-12 | Per Hedbor | | }
|
c7ec63 | 2001-08-15 | Henrik Grubbström (Grubba) | | id->realfile = norm_f;
|
8afb50 | 1998-04-15 | Henrik Grubbström (Grubba) | | TRACE_LEAVE("");
|
b1fca0 | 1996-11-12 | Per Hedbor | | accesses++;
|
8afb50 | 1998-04-15 | Henrik Grubbström (Grubba) | | TRACE_LEAVE("Normal return");
|
a2f3c7 | 2000-08-13 | Per Hedbor | | if( charset != "iso-8859-1" )
{
if( id->misc->set_output_charset )
id->misc->set_output_charset( charset, 2 );
id->misc->input_charset = charset;
}
|
b1fca0 | 1996-11-12 | Per Hedbor | | return o;
}
break;
|
b04ec8 | 2000-01-31 | Per Hedbor | |
|
8764c0 | 1998-05-01 | Henrik Grubbström (Grubba) | | case "MKDIR":
|
ed540b | 2001-01-13 | Martin Nilsson | | if(!query("put"))
|
8764c0 | 1998-05-01 | Henrik Grubbström (Grubba) | | {
id->misc->error_code = 405;
TRACE_LEAVE("MKDIR disallowed (since PUT is disallowed)");
return 0;
|
b04ec8 | 2000-01-31 | Per Hedbor | | }
|
8764c0 | 1998-05-01 | Henrik Grubbström (Grubba) | |
|
54b480 | 2000-03-07 | Martin Stjernholm | | if (FILTER_INTERNAL_FILE (f, id)) {
id->misc->error_code = 405;
TRACE_LEAVE("MKDIR disallowed (since the dir name matches internal file glob)");
return 0;
}
|
9e759c | 2001-09-11 | Henrik Grubbström (Grubba) | | if (size != -1) {
|
c7ec63 | 2001-08-15 | Henrik Grubbström (Grubba) | | TRACE_LEAVE("MKDIR failed. Directory name already exists. ");
return 0;
}
|
076486 | 2001-03-16 | Per Hedbor | | if(query("check_auth") && (!id->conf->authenticate( id ) ) ) {
|
8764c0 | 1998-05-01 | Henrik Grubbström (Grubba) | | TRACE_LEAVE("MKDIR: Permission denied");
|
219575 | 2002-06-14 | Martin Nilsson | | return Roxen.http_auth_required
("foo", "<h1>" + LOCALE(68, "Permission to 'MKDIR' denied.") + "</h1>");
|
8764c0 | 1998-05-01 | Henrik Grubbström (Grubba) | | }
mkdirs++;
object privs;
|
4dea32 | 2001-12-21 | Henrik Grubbström (Grubba) | | SETUID_TRACE("Creating file", 0);
|
8764c0 | 1998-05-01 | Henrik Grubbström (Grubba) | |
|
ed540b | 2001-01-13 | Martin Nilsson | | if (query("no_symlinks") && (contains_symlinks(path, oldf))) {
|
8764c0 | 1998-05-01 | Henrik Grubbström (Grubba) | | privs = 0;
errors++;
|
50ec73 | 2002-06-13 | Martin Nilsson | | report_error("Creation of %s failed. Permission denied.\n",
|
c7ec63 | 2001-08-15 | Henrik Grubbström (Grubba) | | oldf);
|
8764c0 | 1998-05-01 | Henrik Grubbström (Grubba) | | TRACE_LEAVE("MKDIR: Contains symlinks. Permission denied");
|
219575 | 2002-06-14 | Martin Nilsson | | return http_low_answer(403, "<h2>" + LOCALE(69, "Permission denied.") + "</h2>");
|
8764c0 | 1998-05-01 | Henrik Grubbström (Grubba) | | }
|
c7ec63 | 2001-08-15 | Henrik Grubbström (Grubba) | | int code = mkdir(f);
|
8764c0 | 1998-05-01 | Henrik Grubbström (Grubba) | | privs = 0;
|
5e5fd6 | 2000-03-07 | Martin Stjernholm | |
TRACE_ENTER("MKDIR: Accepted", 0);
|
8764c0 | 1998-05-01 | Henrik Grubbström (Grubba) | | if (code) {
|
242240 | 1998-06-04 | David Hedbor | | chmod(f, 0777 & ~(id->misc->umask || 022));
|
8764c0 | 1998-05-01 | Henrik Grubbström (Grubba) | | TRACE_LEAVE("MKDIR: Success");
TRACE_LEAVE("Success");
|
219575 | 2002-06-14 | Martin Nilsson | | return Roxen.http_string_answer(LOCALE(70, "Ok"));
|
8764c0 | 1998-05-01 | Henrik Grubbström (Grubba) | | } else {
TRACE_LEAVE("MKDIR: Failed");
TRACE_LEAVE("Failure");
return 0;
}
break;
|
b1fca0 | 1996-11-12 | Per Hedbor | | case "PUT":
|
ed540b | 2001-01-13 | Martin Nilsson | | if(!query("put"))
|
f6d62d | 1997-03-26 | Per Hedbor | | {
id->misc->error_code = 405;
|
8afb50 | 1998-04-15 | Henrik Grubbström (Grubba) | | TRACE_LEAVE("PUT disallowed");
|
b1fca0 | 1996-11-12 | Per Hedbor | | return 0;
|
b04ec8 | 2000-01-31 | Per Hedbor | | }
|
f6d62d | 1997-03-26 | Per Hedbor | |
|
54b480 | 2000-03-07 | Martin Stjernholm | | if (FILTER_INTERNAL_FILE (f, id)) {
id->misc->error_code = 405;
TRACE_LEAVE("PUT of internal file is disallowed");
return 0;
}
|
076486 | 2001-03-16 | Per Hedbor | | if(query("check_auth") && (!id->conf->authenticate( id ) ) ) {
|
8afb50 | 1998-04-15 | Henrik Grubbström (Grubba) | | TRACE_LEAVE("PUT: Permission denied");
|
219575 | 2002-06-14 | Martin Nilsson | | return Roxen.http_auth_required
("foo", "<h1>" + LOCALE(71, "Permission to 'PUT' files denied.") + "</h1>");
|
8afb50 | 1998-04-15 | Henrik Grubbström (Grubba) | | }
|
2f8308 | 1999-05-05 | Henrik Grubbström (Grubba) | |
|
b1fca0 | 1996-11-12 | Per Hedbor | | puts++;
|
2f8308 | 1999-05-05 | Henrik Grubbström (Grubba) | |
|
ac69b5 | 1999-12-28 | Martin Nilsson | | QUOTA_WERR("Checking quota.\n");
|
1358d5 | 1999-05-06 | Henrik Grubbström (Grubba) | | if (id->misc->quota_obj && (id->misc->len > 0) &&
|
3f286a | 2000-08-23 | Per Hedbor | | !id->misc->quota_obj->check_quota(URI, id->misc->len)) {
|
2f8308 | 1999-05-05 | Henrik Grubbström (Grubba) | | errors++;
|
50ec73 | 2002-06-13 | Martin Nilsson | | report_warning("Creation of %s failed. Out of quota.\n",f);
|
2f8308 | 1999-05-05 | Henrik Grubbström (Grubba) | | TRACE_LEAVE("PUT: Out of quota.");
|
219575 | 2002-06-14 | Martin Nilsson | | return http_low_answer(413, "<h2>" + LOCALE(65, "Out of disk quota.") + "</h2>",
"413 " + LOCALE(65, "Out of disk quota.") );
|
2f8308 | 1999-05-05 | Henrik Grubbström (Grubba) | | }
|
b04ec8 | 2000-01-31 | Per Hedbor | |
|
f6d62d | 1997-03-26 | Per Hedbor | |
|
4dea32 | 2001-12-21 | Henrik Grubbström (Grubba) | | SETUID_TRACE("Saving file", 0);
|
f6d62d | 1997-03-26 | Per Hedbor | |
|
ed540b | 2001-01-13 | Martin Nilsson | | if (query("no_symlinks") && (contains_symlinks(path, oldf))) {
|
64c51c | 1997-10-11 | Henrik Grubbström (Grubba) | | privs = 0;
|
afb158 | 1997-07-06 | Henrik Grubbström (Grubba) | | errors++;
|
50ec73 | 2002-06-13 | Martin Nilsson | | report_error("Creation of %s failed. Permission denied.\n",f);
|
8afb50 | 1998-04-15 | Henrik Grubbström (Grubba) | | TRACE_LEAVE("PUT: Contains symlinks. Permission denied");
|
219575 | 2002-06-14 | Martin Nilsson | | return http_low_answer(403, "<h2>" + LOCALE(69, "Permission denied.") + "</h2>");
|
afb158 | 1997-07-06 | Henrik Grubbström (Grubba) | | }
|
c7ec63 | 2001-08-15 | Henrik Grubbström (Grubba) | | rm(f);
mkdirhier(f);
|
8afb50 | 1998-04-15 | Henrik Grubbström (Grubba) | |
|
2f8308 | 1999-05-05 | Henrik Grubbström (Grubba) | | if (id->misc->quota_obj) {
|
c7ec63 | 2001-08-15 | Henrik Grubbström (Grubba) | | QUOTA_WERR("Checking if the file already existed.");
|
2f8308 | 1999-05-05 | Henrik Grubbström (Grubba) | | if (size > 0) {
|
ac69b5 | 1999-12-28 | Martin Nilsson | | QUOTA_WERR("Deallocating " + size + "bytes.");
|
3f286a | 2000-08-23 | Per Hedbor | | id->misc->quota_obj->deallocate(URI, size);
|
2f8308 | 1999-05-05 | Henrik Grubbström (Grubba) | | }
}
|
c7ec63 | 2001-08-15 | Henrik Grubbström (Grubba) | | object to = open(f, "wct");
|
5e5fd6 | 2000-03-07 | Martin Stjernholm | | privs = 0;
TRACE_ENTER("PUT: Accepted", 0);
|
8afb50 | 1998-04-15 | Henrik Grubbström (Grubba) | |
if (stat_cache) {
cache_set("stat_cache", f, 0);
}
|
b1fca0 | 1996-11-12 | Per Hedbor | | if(!to)
|
f6d62d | 1997-03-26 | Per Hedbor | | {
id->misc->error_code = 403;
|
8afb50 | 1998-04-15 | Henrik Grubbström (Grubba) | | TRACE_LEAVE("PUT: Open failed");
TRACE_LEAVE("Failure");
|
f6d62d | 1997-03-26 | Per Hedbor | | return 0;
}
|
016316 | 1999-04-21 | Henrik Grubbström (Grubba) | |
|
c7ec63 | 2001-08-15 | Henrik Grubbström (Grubba) | | chmod(f, 0666 & ~(id->misc->umask || 022));
|
016316 | 1999-04-21 | Henrik Grubbström (Grubba) | |
|
2f8308 | 1999-05-05 | Henrik Grubbström (Grubba) | | putting[id->my_fd] = id->misc->len;
|
b1fca0 | 1996-11-12 | Per Hedbor | | if(id->data && strlen(id->data))
{
|
2f8308 | 1999-05-05 | Henrik Grubbström (Grubba) | |
if (id->misc->len > 0) {
putting[id->my_fd] -= strlen(id->data);
}
int bytes = to->write( id->data );
if (id->misc->quota_obj) {
|
ac69b5 | 1999-12-28 | Martin Nilsson | | QUOTA_WERR("Allocating " + bytes + "bytes.");
|
2f8308 | 1999-05-05 | Henrik Grubbström (Grubba) | | if (!id->misc->quota_obj->allocate(f, bytes)) {
TRACE_LEAVE("PUT: A string");
TRACE_LEAVE("PUT: Out of quota");
|
219575 | 2002-06-14 | Martin Nilsson | | return http_low_answer(413, "<h2>" + LOCALE(65, "Out of disk quota.") + "</h2>",
"413 " + LOCALE(65, "Out of disk quota.") );
|
2f8308 | 1999-05-05 | Henrik Grubbström (Grubba) | | }
}
|
b1fca0 | 1996-11-12 | Per Hedbor | | }
|
8afb50 | 1998-04-15 | Henrik Grubbström (Grubba) | | if(!putting[id->my_fd]) {
TRACE_LEAVE("PUT: Just a string");
TRACE_LEAVE("Put: Success");
|
219575 | 2002-06-14 | Martin Nilsson | | return Roxen.http_string_answer(LOCALE(70, "Ok"));
|
8afb50 | 1998-04-15 | Henrik Grubbström (Grubba) | | }
|
b1fca0 | 1996-11-12 | Per Hedbor | |
|
a2f346 | 1997-06-12 | Henrik Grubbström (Grubba) | | if(id->clientprot == "HTTP/1.1") {
|
b1fca0 | 1996-11-12 | Per Hedbor | | id->my_fd->write("HTTP/1.1 100 Continue\r\n");
|
a2f346 | 1997-06-12 | Henrik Grubbström (Grubba) | | }
|
3f286a | 2000-08-23 | Per Hedbor | | id->my_fd->set_id( ({ to, id->my_fd, id, URI }) );
|
b1fca0 | 1996-11-12 | Per Hedbor | | id->my_fd->set_nonblocking(got_put_data, 0, done_with_put);
|
8afb50 | 1998-04-15 | Henrik Grubbström (Grubba) | | TRACE_LEAVE("PUT: Pipe in progress");
TRACE_LEAVE("PUT: Success so far");
|
f4b8bc | 2000-05-01 | Martin Nilsson | | return Roxen.http_pipe_in_progress();
|
b1fca0 | 1996-11-12 | Per Hedbor | | break;
|
6cec00 | 1998-05-14 | David Hedbor | | case "CHMOD":
|
b04ec8 | 2000-01-31 | Per Hedbor | |
|
1358d5 | 1999-05-06 | Henrik Grubbström (Grubba) | |
|
b04ec8 | 2000-01-31 | Per Hedbor | |
|
ed540b | 2001-01-13 | Martin Nilsson | | if(!query("put"))
|
6cec00 | 1998-05-14 | David Hedbor | | {
id->misc->error_code = 405;
TRACE_LEAVE("CHMOD disallowed (since PUT is disallowed)");
return 0;
|
b04ec8 | 2000-01-31 | Per Hedbor | | }
|
6cec00 | 1998-05-14 | David Hedbor | |
|
54b480 | 2000-03-07 | Martin Stjernholm | | if (FILTER_INTERNAL_FILE (f, id)) {
id->misc->error_code = 405;
TRACE_LEAVE("CHMOD of internal file is disallowed");
return 0;
}
|
076486 | 2001-03-16 | Per Hedbor | | if(query("check_auth") && (!id->conf->authenticate( id ) ) ) {
|
6cec00 | 1998-05-14 | David Hedbor | | TRACE_LEAVE("CHMOD: Permission denied");
|
219575 | 2002-06-14 | Martin Nilsson | | return Roxen.http_auth_required("foo", "<h1>" + LOCALE(73, "Permission to 'CHMOD' files denied.") +
"</h1>");
|
6cec00 | 1998-05-14 | David Hedbor | | }
|
b04ec8 | 2000-01-31 | Per Hedbor | |
|
4dea32 | 2001-12-21 | Henrik Grubbström (Grubba) | | SETUID_TRACE("CHMODing file", 0);
|
b04ec8 | 2000-01-31 | Per Hedbor | |
|
ed540b | 2001-01-13 | Martin Nilsson | | if (query("no_symlinks") && (contains_symlinks(path, oldf))) {
|
6cec00 | 1998-05-14 | David Hedbor | | privs = 0;
errors++;
TRACE_LEAVE("CHMOD: Contains symlinks. Permission denied");
|
219575 | 2002-06-14 | Martin Nilsson | | return http_low_answer(403, "<h2>" + LOCALE(69, "Permission denied.") + "</h2>");
|
6cec00 | 1998-05-14 | David Hedbor | | }
|
c7ec63 | 2001-08-15 | Henrik Grubbström (Grubba) | | array err = catch(chmod(f, id->misc->mode & 0777));
|
5e5fd6 | 2000-03-07 | Martin Stjernholm | | privs = 0;
|
6cec00 | 1998-05-14 | David Hedbor | | chmods++;
TRACE_ENTER("CHMOD: Accepted", 0);
if (stat_cache) {
cache_set("stat_cache", f, 0);
}
|
b04ec8 | 2000-01-31 | Per Hedbor | |
|
6cec00 | 1998-05-14 | David Hedbor | | if(err)
{
id->misc->error_code = 403;
TRACE_LEAVE("CHMOD: Failure");
TRACE_LEAVE("Failure");
return 0;
}
TRACE_LEAVE("CHMOD: Success");
TRACE_LEAVE("Success");
|
219575 | 2002-06-14 | Martin Nilsson | | return Roxen.http_string_answer(LOCALE(70, "Ok"));
|
b04ec8 | 2000-01-31 | Per Hedbor | |
|
dba2b5 | 1998-05-14 | David Hedbor | | case "MV":
|
b04ec8 | 2000-01-31 | Per Hedbor | |
|
2f8308 | 1999-05-05 | Henrik Grubbström (Grubba) | |
|
ed540b | 2001-01-13 | Martin Nilsson | | if(!query("put"))
|
dba2b5 | 1998-05-14 | David Hedbor | | {
id->misc->error_code = 405;
TRACE_LEAVE("MV disallowed (since PUT is disallowed)");
return 0;
|
b04ec8 | 2000-01-31 | Per Hedbor | | }
|
ed540b | 2001-01-13 | Martin Nilsson | | if(!query("delete") && size != -1)
|
dba2b5 | 1998-05-14 | David Hedbor | | {
id->misc->error_code = 405;
TRACE_LEAVE("MV disallowed (DELE disabled, can't overwrite file)");
return 0;
}
|
f37e47 | 1998-05-14 | Henrik Grubbström (Grubba) | | if(size < -1)
|
dba2b5 | 1998-05-14 | David Hedbor | | {
id->misc->error_code = 405;
TRACE_LEAVE("MV: Cannot overwrite directory");
return 0;
}
|
076486 | 2001-03-16 | Per Hedbor | | if(query("check_auth") && (!id->conf->authenticate( id ) ) ) {
|
dba2b5 | 1998-05-14 | David Hedbor | | TRACE_LEAVE("MV: Permission denied");
|
219575 | 2002-06-14 | Martin Nilsson | | return Roxen.http_auth_required("foo", "<h1>" + LOCALE(74, "Permission to 'MV' files denied.") +
"</h1>");
|
dba2b5 | 1998-05-14 | David Hedbor | | }
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;
}
|
54b480 | 2000-03-07 | Martin Stjernholm | |
if (FILTER_INTERNAL_FILE (movefrom, id) ||
FILTER_INTERNAL_FILE (f, id)) {
id->misc->error_code = 405;
TRACE_LEAVE("MV to or from internal file is disallowed");
return 0;
}
|
4dea32 | 2001-12-21 | Henrik Grubbström (Grubba) | | SETUID_TRACE("Moving file", 0);
|
b04ec8 | 2000-01-31 | Per Hedbor | |
|
ed540b | 2001-01-13 | Martin Nilsson | | if (query("no_symlinks") &&
|
f37e47 | 1998-05-14 | Henrik Grubbström (Grubba) | | ((contains_symlinks(path, oldf)) ||
(contains_symlinks(path, id->misc->move_from)))) {
|
dba2b5 | 1998-05-14 | David Hedbor | | privs = 0;
errors++;
TRACE_LEAVE("MV: Contains symlinks. Permission denied");
|
219575 | 2002-06-14 | Martin Nilsson | | return http_low_answer(403, "<h2>" + LOCALE(69, "Permission denied.") + "</h2>");
|
dba2b5 | 1998-05-14 | David Hedbor | | }
|
c7ec63 | 2001-08-15 | Henrik Grubbström (Grubba) | | code = mv(movefrom, f);
|
5e5fd6 | 2000-03-07 | Martin Stjernholm | | privs = 0;
moves++;
|
dba2b5 | 1998-05-14 | David Hedbor | | TRACE_ENTER("MV: Accepted", 0);
if (stat_cache) {
cache_set("stat_cache", movefrom, 0);
cache_set("stat_cache", f, 0);
}
if(!code)
{
id->misc->error_code = 403;
TRACE_LEAVE("MV: Move failed");
TRACE_LEAVE("Failure");
return 0;
}
TRACE_LEAVE("MV: Success");
|
f37e47 | 1998-05-14 | Henrik Grubbström (Grubba) | | TRACE_LEAVE("Success");
|
219575 | 2002-06-14 | Martin Nilsson | | return Roxen.http_string_answer(LOCALE(70, "Ok"));
|
de14f2 | 1998-10-19 | Wim Bonis | |
case "MOVE":
|
2f8308 | 1999-05-05 | Henrik Grubbström (Grubba) | |
|
b04ec8 | 2000-01-31 | Per Hedbor | |
|
ed540b | 2001-01-13 | Martin Nilsson | | if(!query("put"))
|
de14f2 | 1998-10-19 | Wim Bonis | | {
id->misc->error_code = 405;
TRACE_LEAVE("MOVE disallowed (since PUT is disallowed)");
return 0;
|
b04ec8 | 2000-01-31 | Per Hedbor | | }
|
de14f2 | 1998-10-19 | Wim Bonis | | if(size != -1)
{
id->misc->error_code = 404;
TRACE_LEAVE("MOVE failed (no such file)");
return 0;
}
|
076486 | 2001-03-16 | Per Hedbor | | if(query("check_auth") && (!id->conf->authenticate( id ) ) ) {
|
de14f2 | 1998-10-19 | Wim Bonis | | TRACE_LEAVE("MOVE: Permission denied");
|
219575 | 2002-06-14 | Martin Nilsson | | return Roxen.http_auth_required("foo", "<h1>" + LOCALE(75, "Permission to 'MOVE' files denied.") +
"</h1>");
|
de14f2 | 1998-10-19 | Wim Bonis | | }
|
b04ec8 | 2000-01-31 | Per Hedbor | | if(!sizeof(id->misc["new-uri"] || "")) {
|
de14f2 | 1998-10-19 | Wim Bonis | | id->misc->error_code = 405;
errors++;
TRACE_LEAVE("MOVE: No dest file");
return 0;
}
|
3f286a | 2000-08-23 | Per Hedbor | | string new_uri = combine_path(URI + "/../",
|
1358d5 | 1999-05-06 | Henrik Grubbström (Grubba) | | id->misc["new-uri"]);
|
de14f2 | 1998-10-19 | Wim Bonis | |
|
3a26d1 | 2000-12-29 | Henrik Grubbström (Grubba) | |
|
1358d5 | 1999-05-06 | Henrik Grubbström (Grubba) | | if (new_uri[..sizeof(mountpoint)-1] != mountpoint) {
|
de14f2 | 1998-10-19 | Wim Bonis | | id->misc->error_code = 405;
TRACE_LEAVE("MOVE: Dest file on other filesystem.");
return(0);
}
|
1358d5 | 1999-05-06 | Henrik Grubbström (Grubba) | | string moveto = path + "/" + new_uri[sizeof(mountpoint)..];
|
de14f2 | 1998-10-19 | Wim Bonis | |
|
54b480 | 2000-03-07 | Martin Stjernholm | | 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;
}
|
a2f3c7 | 2000-08-13 | Per Hedbor | | size = _file_size(moveto,id);
|
de14f2 | 1998-10-19 | Wim Bonis | |
|
ed540b | 2001-01-13 | Martin Nilsson | | if(!query("delete") && size != -1)
|
de14f2 | 1998-10-19 | Wim Bonis | | {
id->misc->error_code = 405;
TRACE_LEAVE("MOVE disallowed (DELE disabled, can't overwrite file)");
return 0;
}
|
b04ec8 | 2000-01-31 | Per Hedbor | |
|
de14f2 | 1998-10-19 | Wim Bonis | | if(size < -1)
{
id->misc->error_code = 405;
TRACE_LEAVE("MOVE: Cannot overwrite directory");
return 0;
}
|
4dea32 | 2001-12-21 | Henrik Grubbström (Grubba) | | SETUID_TRACE("Moving file", 0);
|
de14f2 | 1998-10-19 | Wim Bonis | |
|
ed540b | 2001-01-13 | Martin Nilsson | | if (query("no_symlinks") &&
|
de14f2 | 1998-10-19 | Wim Bonis | | ((contains_symlinks(path, f)) ||
(contains_symlinks(path, moveto)))) {
privs = 0;
errors++;
TRACE_LEAVE("MOVE: Contains symlinks. Permission denied");
|
219575 | 2002-06-14 | Martin Nilsson | | return http_low_answer(403, "<h2>" + LOCALE(69, "Permission denied.") + "</h2>");
|
de14f2 | 1998-10-19 | Wim Bonis | | }
|
c7ec63 | 2001-08-15 | Henrik Grubbström (Grubba) | | code = mv(f, decode_path(moveto));
|
5e5fd6 | 2000-03-07 | Martin Stjernholm | | privs = 0;
|
de14f2 | 1998-10-19 | Wim Bonis | | TRACE_ENTER("MOVE: Accepted", 0);
moves++;
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");
TRACE_LEAVE("Failure");
return 0;
}
TRACE_LEAVE("MOVE: Success");
TRACE_LEAVE("Success");
|
219575 | 2002-06-14 | Martin Nilsson | | return Roxen.http_string_answer(LOCALE(70, "Ok"));
|
de14f2 | 1998-10-19 | Wim Bonis | |
|
b04ec8 | 2000-01-31 | Per Hedbor | |
|
b1fca0 | 1996-11-12 | Per Hedbor | | case "DELETE":
|
ed540b | 2001-01-13 | Martin Nilsson | | if(!query("delete") || size==-1)
|
f6d62d | 1997-03-26 | Per Hedbor | | {
id->misc->error_code = 405;
|
8afb50 | 1998-04-15 | Henrik Grubbström (Grubba) | | TRACE_LEAVE("DELETE: Disabled");
|
b1fca0 | 1996-11-12 | Per Hedbor | | return 0;
|
f6d62d | 1997-03-26 | Per Hedbor | | }
|
54b480 | 2000-03-07 | Martin Stjernholm | |
if (FILTER_INTERNAL_FILE (f, id)) {
id->misc->error_code = 405;
TRACE_LEAVE("DELETE of internal file is disallowed");
return 0;
}
|
076486 | 2001-03-16 | Per Hedbor | | if(query("check_auth") && (!id->conf->authenticate( id ) ) ) {
|
8afb50 | 1998-04-15 | Henrik Grubbström (Grubba) | | TRACE_LEAVE("DELETE: Permission denied");
|
219575 | 2002-06-14 | Martin Nilsson | | return http_low_answer(403, "<h1>" + LOCALE(76, "Permission to DELETE file denied.") + "</h1>");
|
8afb50 | 1998-04-15 | Henrik Grubbström (Grubba) | | }
|
b1fca0 | 1996-11-12 | Per Hedbor | |
|
ed540b | 2001-01-13 | Martin Nilsson | | if (query("no_symlinks") && (contains_symlinks(path, oldf))) {
|
afb158 | 1997-07-06 | Henrik Grubbström (Grubba) | | errors++;
|
50ec73 | 2002-06-13 | Martin Nilsson | | report_error("Deletion of %s failed. Permission denied.\n",f);
|
8afb50 | 1998-04-15 | Henrik Grubbström (Grubba) | | TRACE_LEAVE("DELETE: Contains symlinks");
|
219575 | 2002-06-14 | Martin Nilsson | | return http_low_answer(403, "<h2>" + LOCALE(69, "Permission denied.") + "</h2>");
|
afb158 | 1997-07-06 | Henrik Grubbström (Grubba) | | }
|
50ec73 | 2002-06-13 | Martin Nilsson | | report_notice("DELETING the file %s.\n",f);
|
b1fca0 | 1996-11-12 | Per Hedbor | | accesses++;
|
f6d62d | 1997-03-26 | Per Hedbor | |
|
4dea32 | 2001-12-21 | Henrik Grubbström (Grubba) | | SETUID_TRACE("Deleting file", 0);
|
f6d62d | 1997-03-26 | Per Hedbor | |
|
8afb50 | 1998-04-15 | Henrik Grubbström (Grubba) | |
if (stat_cache) {
cache_set("stat_cache", f, 0);
}
|
c7ec63 | 2001-08-15 | Henrik Grubbström (Grubba) | | if(!rm(f))
|
f6d62d | 1997-03-26 | Per Hedbor | | {
|
64c51c | 1997-10-11 | Henrik Grubbström (Grubba) | | privs = 0;
|
f6d62d | 1997-03-26 | Per Hedbor | | id->misc->error_code = 405;
|
8afb50 | 1998-04-15 | Henrik Grubbström (Grubba) | | TRACE_LEAVE("DELETE: Failed");
|
f6d62d | 1997-03-26 | Per Hedbor | | return 0;
}
|
64c51c | 1997-10-11 | Henrik Grubbström (Grubba) | | privs = 0;
|
f6d62d | 1997-03-26 | Per Hedbor | | deletes++;
|
2f8308 | 1999-05-05 | Henrik Grubbström (Grubba) | |
|
2ac400 | 1999-05-05 | Henrik Grubbström (Grubba) | | if (id->misc->quota_obj && (size > 0)) {
|
2f8308 | 1999-05-05 | Henrik Grubbström (Grubba) | | id->misc->quota_obj->deallocate(oldf, size);
}
|
8afb50 | 1998-04-15 | Henrik Grubbström (Grubba) | | TRACE_LEAVE("DELETE: Success");
|
219575 | 2002-06-14 | Martin Nilsson | | return http_low_answer(200, sprintf( LOCALE("%s DELETED from the server."), f));
|
b1fca0 | 1996-11-12 | Per Hedbor | |
default:
|
8afb50 | 1998-04-15 | Henrik Grubbström (Grubba) | | TRACE_LEAVE("Not supported");
|
b1fca0 | 1996-11-12 | Per Hedbor | | return 0;
}
|
8afb50 | 1998-04-15 | Henrik Grubbström (Grubba) | | TRACE_LEAVE("Not reached");
|
b1fca0 | 1996-11-12 | Per Hedbor | | return 0;
}
string query_name()
{
|
50ec73 | 2002-06-13 | Martin Nilsson | | if (sizeof(path) > 20)
return mountpoint + " from " + path[..7]...path[sizeof(path)-8..];
return mountpoint + " from " + path;
|
b1fca0 | 1996-11-12 | Per Hedbor | | }
|