0247a3 | 1998-03-11 | David Hedbor | |
|
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 "roxenlib";
inherit "socket";
|
1358d5 | 1999-05-06 | Henrik Grubbström (Grubba) | | constant cvs_version= "$Id: filesystem.pike,v 1.54 1999/05/06 20:51:55 grubba Exp $";
|
190901 | 1998-02-24 | Henrik Grubbström (Grubba) | | constant thread_safe=1;
|
6682b9 | 1997-08-31 | Peter Bortas | |
|
f6d62d | 1997-03-26 | Per Hedbor | |
|
b1fca0 | 1996-11-12 | Per Hedbor | | #include <module.h>
|
48fa36 | 1997-04-05 | Per Hedbor | | #include <roxen.h>
|
14179b | 1997-01-29 | Per Hedbor | | #include <stat.h>
|
b1fca0 | 1996-11-12 | Per Hedbor | |
#if DEBUG_LEVEL > 20
# ifndef FILESYSTEM_DEBUG
# define FILESYSTEM_DEBUG
# endif
#endif
|
e5bad2 | 1998-02-10 | Per Hedbor | |
|
639611 | 1997-02-14 | Per Hedbor | |
|
8afb50 | 1998-04-15 | Henrik Grubbström (Grubba) | | #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)
|
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)
{
mapping res = ::http_low_answer(errno, data);
if (desc) {
res->rettext = desc;
}
return res;
}
|
b1fca0 | 1996-11-12 | Per Hedbor | | 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>":"")+
|
8764c0 | 1998-05-01 | Henrik Grubbström (Grubba) | | (QUERY(put)&&mkdirs?"<b>Mkdirs</b>: "+mkdirs+"<br>":"")+
|
6cec00 | 1998-05-14 | David Hedbor | | (QUERY(put)&&QUERY(delete)&&moves?
"<b>Moved files</b>: "+moves+"<br>":"")+
(QUERY(put)&&chmods?"<b>CHMODs</b>: "+chmods+"<br>":"")+
|
b1fca0 | 1996-11-12 | Per Hedbor | | (QUERY(delete)&&deletes?"<b>Deletes</b>: "+deletes+"<br>":"")+
(errors?"<b>Permission denied</b>: "+errors
+" (not counting .htaccess)<br>":"")+
(dirlists?"<b>Directories</b>:"+dirlists+"<br>":""));
}
void create()
{
defvar("mountpoint", "/", "Mount point", TYPE_LOCATION,
"This is where the module will be inserted in the "+
"namespace of your server.");
defvar("searchpath", "NONE", "Search path", TYPE_DIR,
"This is where the module will find the files in the real "+
"file system");
#ifdef COMPAT
defvar("html", 0, "All files are really HTML files", TYPE_FLAG|VAR_EXPERT,
"If you set this variable, the filesystem will _know_ that all files "
"are really HTML files. This might be useful now and then.");
#endif
|
9b9f70 | 1997-08-12 | Per Hedbor | | defvar(".files", 0, "Show hidden files", TYPE_FLAG|VAR_MORE,
|
b1fca0 | 1996-11-12 | Per Hedbor | | "If set, hidden files will be shown in dirlistings and you "
"will be able to retrieve them.");
|
9b9f70 | 1997-08-12 | Per Hedbor | | defvar("dir", 1, "Enable directory listings per default", TYPE_FLAG|VAR_MORE,
|
b1fca0 | 1996-11-12 | Per Hedbor | | "If set, you have to create a file named .www_not_browsable ("
"or .nodiraccess) in a directory to disable directory listings."
" If unset, a file named .www_browsable in a directory will "
"_enable_ directory listings.\n");
|
9b9f70 | 1997-08-12 | Per Hedbor | | defvar("tilde", 0, "Show backupfiles", TYPE_FLAG|VAR_MORE,
|
b1fca0 | 1996-11-12 | Per Hedbor | | "If set, files ending with '~' or '#' or '.bak' will "+
"be shown in directory listings");
|
01a57e | 1998-01-04 | Peter Bortas | | defvar("put", 0, "Handle the PUT method", TYPE_FLAG,
|
b1fca0 | 1996-11-12 | Per Hedbor | | "If set, PUT can be used to upload files to the server.");
|
f6d62d | 1997-03-26 | Per Hedbor | | defvar("delete", 0, "Handle the DELETE method", TYPE_FLAG,
|
b1fca0 | 1996-11-12 | Per Hedbor | | "If set, DELETE can be used to delete files from the "
"server.");
|
26d132 | 1997-01-29 | David KÃ¥gedal | | defvar("check_auth", 1, "Require authentication for modification",
|
b1fca0 | 1996-11-12 | Per Hedbor | | TYPE_FLAG,
"Only allow authenticated users to use methods other than "
"GET and POST. If unset, this filesystem will be a _very_ "
"public one (anyone can edit files located on it)");
|
14179b | 1997-01-29 | Per Hedbor | |
defvar("stat_cache", 1, "Cache the results of stat(2)",
|
9b9f70 | 1997-08-12 | Per Hedbor | | TYPE_FLAG|VAR_MORE,
|
14179b | 1997-01-29 | Per Hedbor | | "This can speed up the retrieval of files up to 60/70% if you"
" use NFS, but it does use some memory.");
|
2e7c23 | 1997-06-10 | Henrik Grubbström (Grubba) | |
defvar("access_as_user", 0, "Access file as the logged in user",
|
9b9f70 | 1997-08-12 | Per Hedbor | | TYPE_FLAG|VAR_MORE,
|
2e7c23 | 1997-06-10 | Henrik Grubbström (Grubba) | | "EXPERIMENTAL. Access file as the logged in user.<br>\n"
"This is useful for eg named-ftp.");
|
afb158 | 1997-07-06 | Henrik Grubbström (Grubba) | |
|
9b9f70 | 1997-08-12 | Per Hedbor | | defvar("no_symlinks", 0, "Forbid access to symlinks", TYPE_FLAG|VAR_MORE,
|
afb158 | 1997-07-06 | Henrik Grubbström (Grubba) | | "EXPERIMENTAL.\n"
"Forbid access to paths containing symbolic links.<br>\n"
"NOTE: This can cause *alot* of lstat system-calls to be performed "
"and can make the server much slower.");
|
b1fca0 | 1996-11-12 | Per Hedbor | | }
|
32ae66 | 1997-01-27 | Per Hedbor | |
|
b1fca0 | 1996-11-12 | Per Hedbor | | mixed *register_module()
{
return ({
MODULE_LOCATION,
"Filesystem",
("This is a virtual filesystem, use it to make files available to "+
|
fd0b6f | 1996-12-02 | Per Hedbor | | "the users of your WWW-server. If you want to serve any 'normal' "
"files from your server, you will have to have atleast one filesystem.")
|
b1fca0 | 1996-11-12 | Per Hedbor | | });
}
string path;
|
14179b | 1997-01-29 | Per Hedbor | | int stat_cache;
|
b1fca0 | 1996-11-12 | Per Hedbor | |
void start()
{
|
8afc81 | 1998-02-04 | Per Hedbor | | #ifdef THREADS
if(QUERY(access_as_user))
report_warning("It is not possible to use 'Access as user' when "
"running with threads. Remove -DENABLE_THREADS from "
"the start script if you really need this function\n");
#endif
|
b1fca0 | 1996-11-12 | Per Hedbor | | path = QUERY(searchpath);
|
14179b | 1997-01-29 | Per Hedbor | | stat_cache = QUERY(stat_cache);
|
b1fca0 | 1996-11-12 | Per Hedbor | | #ifdef FILESYSTEM_DEBUG
perror("FILESYSTEM: Online at "+QUERY(mountpoint)+" (path="+path+")\n");
#endif
}
string query_location()
{
return QUERY(mountpoint);
}
mixed stat_file( mixed f, mixed id )
{
|
64c51c | 1997-10-11 | Henrik Grubbström (Grubba) | | array fs;
if(stat_cache && !id->pragma["no-cache"] &&
(fs=cache_lookup("stat_cache",path+f)))
|
1b8f6b | 1998-02-24 | Per Hedbor | | return fs[0];
|
64c51c | 1997-10-11 | Henrik Grubbström (Grubba) | |
|
8afc81 | 1998-02-04 | Per Hedbor | | #ifndef THREADS
|
1b8f6b | 1998-02-24 | Per Hedbor | | object privs;
|
0216e2 | 1997-08-12 | Henrik Grubbström (Grubba) | | if (((int)id->misc->uid) && ((int)id->misc->gid) &&
(QUERY(access_as_user))) {
|
f7d981 | 1997-09-12 | Per Hedbor | | privs=Privs("Statting file", (int)id->misc->uid, (int)id->misc->gid );
|
0216e2 | 1997-08-12 | Henrik Grubbström (Grubba) | | }
|
8afc81 | 1998-02-04 | Per Hedbor | | #endif
|
64c51c | 1997-10-11 | Henrik Grubbström (Grubba) | | fs = file_stat(path + f);
|
1b8f6b | 1998-02-24 | Per Hedbor | | #ifndef THREADS
|
64c51c | 1997-10-11 | Henrik Grubbström (Grubba) | | privs = 0;
|
1b8f6b | 1998-02-24 | Per Hedbor | | #endif
|
14179b | 1997-01-29 | Per Hedbor | | if(!stat_cache)
return fs;
|
1b8f6b | 1998-02-24 | Per Hedbor | | cache_set("stat_cache", path+f, ({fs}));
|
14179b | 1997-01-29 | Per Hedbor | | return fs;
|
b1fca0 | 1996-11-12 | Per Hedbor | | }
string real_file( mixed f, mixed id )
{
if(this->stat_file( f, id ))
|
27b0e1 | 1996-11-26 | Per Hedbor | | 'this' */
|
b1fca0 | 1996-11-12 | Per Hedbor | | return path + f;
}
int dir_filter_function(string f)
{
if(f[0]=='.' && !QUERY(.files)) return 0;
if(!QUERY(tilde) && backup_extension(f)) return 0;
return 1;
}
array find_dir( string f, object id )
{
mixed ret;
array dir;
|
0216e2 | 1997-08-12 | Henrik Grubbström (Grubba) | | object privs;
|
8afc81 | 1998-02-04 | Per Hedbor | | #ifndef THREADS
|
0216e2 | 1997-08-12 | Henrik Grubbström (Grubba) | | if (((int)id->misc->uid) && ((int)id->misc->gid) &&
(QUERY(access_as_user))) {
|
f7d981 | 1997-09-12 | Per Hedbor | | privs=Privs("Getting dir", (int)id->misc->uid, (int)id->misc->gid );
|
0216e2 | 1997-08-12 | Henrik Grubbström (Grubba) | | }
|
8afc81 | 1998-02-04 | Per Hedbor | | #endif
|
0216e2 | 1997-08-12 | Henrik Grubbström (Grubba) | |
|
64c51c | 1997-10-11 | Henrik Grubbström (Grubba) | | if(!(dir = get_dir( path + f ))) {
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;
|
b1fca0 | 1996-11-12 | Per Hedbor | | if(!QUERY(dir))
if(search(dir, ".www_browsable") == -1)
{
errors++;
return 0;
}
if(sizeof(dir & ({".nodiraccess",".www_not_browsable",".nodir_access"})))
{
errors++;
return 0;
}
dirlists++;
if(QUERY(tilde) && QUERY(.files))
return dir;
|
e5bad2 | 1998-02-10 | Per Hedbor | | return Array.filter(dir, dir_filter_function);
|
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 | | {
|
2f8308 | 1999-05-05 | Henrik Grubbström (Grubba) | | object to;
object from;
object id;
string oldf;
[to, from, id, oldf] = id_arr;
|
1358d5 | 1999-05-06 | Henrik Grubbström (Grubba) | | #ifdef FILESYSTEM_DEBUG
werror(sprintf("done_with_put(%O)\n"
"from: %O\n",
id_arr, mkmapping(indices(from), values(from))));
#endif /* FILESYSTEM_DEBUG */
|
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) | |
|
2f8308 | 1999-05-05 | Henrik Grubbström (Grubba) | | id->send_result(http_low_answer(400,
"<h2>Bad Request - "
"Expected more data.</h2>"));
|
016316 | 1999-04-21 | Henrik Grubbström (Grubba) | | } else {
|
2f8308 | 1999-05-05 | Henrik Grubbström (Grubba) | | id->send_result(http_low_answer(200, "<h2>Transfer Complete.</h2>"));
|
016316 | 1999-04-21 | Henrik Grubbström (Grubba) | | }
|
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 | | {
|
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);
|
1358d5 | 1999-05-06 | Henrik Grubbström (Grubba) | | id->send_result(http_low_answer(413, "<h2>Out of disk quota.</h2>",
"413 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);
id->send_result(http_low_answer(413, "<h2>Disk full.</h2>"));
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);
|
1358d5 | 1999-05-06 | Henrik Grubbström (Grubba) | | id->send_result(http_low_answer(413, "<h2>Out of disk quota.</h2>",
"413 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 | | }
|
14179b | 1997-01-29 | Per Hedbor | | int _file_size(string X,object id)
{
array fs;
if(!id->pragma["no-cache"]&&(fs=cache_lookup("stat_cache",(X))))
{
|
1b8f6b | 1998-02-24 | Per Hedbor | | id->misc->stat = fs[0];
return fs[0]?fs[0][ST_SIZE]:-1;
|
14179b | 1997-01-29 | Per Hedbor | | }
if(fs = file_stat(X))
{
id->misc->stat = fs;
|
1b8f6b | 1998-02-24 | Per Hedbor | | cache_set("stat_cache",(X),({fs}));
|
14179b | 1997-01-29 | Per Hedbor | | return fs[ST_SIZE];
|
1b8f6b | 1998-02-24 | Per Hedbor | | } else
cache_set("stat_cache",(X),({0}));
|
14179b | 1997-01-29 | Per Hedbor | | return -1;
}
|
639611 | 1997-02-14 | Per Hedbor | | #define FILE_SIZE(X) (stat_cache?_file_size((X),id):Stdio.file_size(X))
|
14179b | 1997-01-29 | Per Hedbor | |
|
afb158 | 1997-07-06 | Henrik Grubbström (Grubba) | | int contains_symlinks(string root, string path)
{
array arr = path/"/";
foreach(arr - ({ "" }), path) {
root += "/" + path;
if (arr = file_stat(root, 1)) {
if (arr[1] == -3) {
return(1);
}
} else {
return(0);
}
}
return(0);
}
|
b1fca0 | 1996-11-12 | Per Hedbor | | mixed find_file( string f, object id )
{
|
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) | |
#ifdef FILESYSTEM_DEBUG
roxen_perror("FILESYSTEM: Request for \""+f+"\"\n");
#endif /* FILESYSTEM_DEBUG */
|
1358d5 | 1999-05-06 | Henrik Grubbström (Grubba) | | string mountpoint = QUERY(mountpoint);
string uri = combine_path(mountpoint + "/" + f, ".");
|
f2e1da | 1998-04-24 | Per Hedbor | | f = path + f;
|
da9e9f | 1998-04-24 | Per Hedbor | | #ifdef __NT__
if(f[-1]=='/') f = f[..strlen(f)-2];
|
b1fca0 | 1996-11-12 | Per Hedbor | | #endif
|
f2e1da | 1998-04-24 | Per Hedbor | | size = FILE_SIZE( f );
|
b1fca0 | 1996-11-12 | Per Hedbor | |
|
465eb6 | 1998-08-26 | Henrik Grubbström (Grubba) | |
|
b1fca0 | 1996-11-12 | Per Hedbor | | switch(id->method)
{
case "GET":
case "HEAD":
case "POST":
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:
if(f[ -1 ] == '/')
{
|
465eb6 | 1998-08-26 | Henrik Grubbström (Grubba) | |
|
dc58c1 | 1998-08-25 | David Hedbor | | return 0;
|
5e429c | 1997-05-25 | Wilhelm Köhler | |
if(sizeof(id->not_query) < 2)
return 0;
|
b1fca0 | 1996-11-12 | Per Hedbor | | redirects++;
|
a20b32 | 1999-01-14 | Henrik Grubbström (Grubba) | |
|
575f78 | 1999-01-14 | Henrik Grubbström (Grubba) | | string new_query =
http_encode_string(id->not_query[..sizeof(id->not_query)-2]) +
|
a20b32 | 1999-01-14 | Henrik Grubbström (Grubba) | | (id->query?("?" + id->query):"");
TRACE_LEAVE("Redirecting to \"" + new_query + "\"");
return http_redirect(new_query, id);
|
b1fca0 | 1996-11-12 | Per Hedbor | | }
if(!id->misc->internal_get && QUERY(.files)
&& (tmp = (id->not_query/"/")[-1])
|
8afb50 | 1998-04-15 | Henrik Grubbström (Grubba) | | && tmp[0] == '.') {
TRACE_LEAVE("Is .-file");
|
b1fca0 | 1996-11-12 | Per Hedbor | | return 0;
|
8afb50 | 1998-04-15 | Henrik Grubbström (Grubba) | | }
|
8afc81 | 1998-02-04 | Per Hedbor | | #ifndef THREADS
|
1b8f6b | 1998-02-24 | Per Hedbor | | object privs;
|
2e7c23 | 1997-06-10 | Henrik Grubbström (Grubba) | | if (((int)id->misc->uid) && ((int)id->misc->gid) &&
(QUERY(access_as_user))) {
|
0216e2 | 1997-08-12 | Henrik Grubbström (Grubba) | |
|
f7d981 | 1997-09-12 | Per Hedbor | | privs=Privs("Getting file", (int)id->misc->uid, (int)id->misc->gid );
|
2e7c23 | 1997-06-10 | Henrik Grubbström (Grubba) | | }
|
8afc81 | 1998-02-04 | Per Hedbor | | #endif
|
2e7c23 | 1997-06-10 | Henrik Grubbström (Grubba) | |
|
8afb50 | 1998-04-15 | Henrik Grubbström (Grubba) | | TRACE_ENTER("Opening file \"" + f + "\"", 0);
|
b1fca0 | 1996-11-12 | Per Hedbor | | o = open( f, "r" );
|
1b8f6b | 1998-02-24 | Per Hedbor | | #ifndef THREADS
|
2e7c23 | 1997-06-10 | Henrik Grubbström (Grubba) | | privs = 0;
|
1b8f6b | 1998-02-24 | Per Hedbor | | #endif
|
2e7c23 | 1997-06-10 | Henrik Grubbström (Grubba) | |
|
afb158 | 1997-07-06 | Henrik Grubbström (Grubba) | | if(!o || (QUERY(no_symlinks) && (contains_symlinks(path, oldf))))
|
b1fca0 | 1996-11-12 | Per Hedbor | | {
errors++;
report_error("Open of " + f + " failed. Permission denied.\n");
|
8afb50 | 1998-04-15 | Henrik Grubbström (Grubba) | |
TRACE_LEAVE("");
TRACE_LEAVE("Permission denied.");
|
b1fca0 | 1996-11-12 | Per Hedbor | | return http_low_answer(403, "<h2>File exists, but access forbidden "
"by user</h2>");
}
id->realfile = f;
|
8afb50 | 1998-04-15 | Henrik Grubbström (Grubba) | | TRACE_LEAVE("");
|
b1fca0 | 1996-11-12 | Per Hedbor | | accesses++;
#ifdef COMPAT
|
8afb50 | 1998-04-15 | Henrik Grubbström (Grubba) | | if(QUERY(html)) {
TRACE_LEAVE("Compat return");
|
b1fca0 | 1996-11-12 | Per Hedbor | | return ([ "type":"text/html", "file":o, ]);
|
8afb50 | 1998-04-15 | Henrik Grubbström (Grubba) | | }
|
b1fca0 | 1996-11-12 | Per Hedbor | | #endif
|
8afb50 | 1998-04-15 | Henrik Grubbström (Grubba) | | TRACE_LEAVE("Normal return");
|
b1fca0 | 1996-11-12 | Per Hedbor | | return o;
}
break;
|
8764c0 | 1998-05-01 | Henrik Grubbström (Grubba) | | case "MKDIR":
if(!QUERY(put))
{
id->misc->error_code = 405;
TRACE_LEAVE("MKDIR disallowed (since PUT is disallowed)");
return 0;
}
if(QUERY(check_auth) && (!id->auth || !id->auth[0])) {
TRACE_LEAVE("MKDIR: Permission denied");
return http_auth_required("foo",
"<h1>Permission to 'MKDIR' denied</h1>");
}
mkdirs++;
object privs;
if (((int)id->misc->uid) && ((int)id->misc->gid)) {
privs=Privs("Creating directory",
(int)id->misc->uid, (int)id->misc->gid );
}
if (QUERY(no_symlinks) && (contains_symlinks(path, oldf))) {
privs = 0;
errors++;
report_error("Creation of " + f + " failed. Permission denied.\n");
TRACE_LEAVE("MKDIR: Contains symlinks. Permission denied");
return http_low_answer(403, "<h2>Permission denied.</h2>");
}
TRACE_ENTER("MKDIR: Accepted", 0);
int code = mkdir( f );
privs = 0;
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");
return http_string_answer("Ok");
} else {
TRACE_LEAVE("MKDIR: Failed");
TRACE_LEAVE("Failure");
return 0;
}
break;
|
b1fca0 | 1996-11-12 | Per Hedbor | | case "PUT":
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;
|
f6d62d | 1997-03-26 | Per Hedbor | | }
|
8afb50 | 1998-04-15 | Henrik Grubbström (Grubba) | | if(QUERY(check_auth) && (!id->auth || !id->auth[0])) {
TRACE_LEAVE("PUT: Permission denied");
|
f6d62d | 1997-03-26 | Per Hedbor | | return http_auth_required("foo",
"<h1>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) | |
#ifdef QUOTA_DEBUG
report_debug("Checking quota.\n");
#endif /* QUOTA_DEBUG */
|
1358d5 | 1999-05-06 | Henrik Grubbström (Grubba) | | if (id->misc->quota_obj && (id->misc->len > 0) &&
!id->misc->quota_obj->check_quota(uri, id->misc->len)) {
|
2f8308 | 1999-05-05 | Henrik Grubbström (Grubba) | | errors++;
report_warning("Creation of " + f + " failed. Out of quota.\n");
TRACE_LEAVE("PUT: Out of quota.");
|
1358d5 | 1999-05-06 | Henrik Grubbström (Grubba) | | return http_low_answer(413, "<h2>Out of disk quota.</h2>",
"413 Out of disk quota");
|
2f8308 | 1999-05-05 | Henrik Grubbström (Grubba) | | }
|
b1fca0 | 1996-11-12 | Per Hedbor | |
|
f6d62d | 1997-03-26 | Per Hedbor | | object privs;
|
8afc81 | 1998-02-04 | Per Hedbor | |
|
2e7c23 | 1997-06-10 | Henrik Grubbström (Grubba) | | if (((int)id->misc->uid) && ((int)id->misc->gid)) {
|
0216e2 | 1997-08-12 | Henrik Grubbström (Grubba) | |
|
f7d981 | 1997-09-12 | Per Hedbor | | privs=Privs("Saving file", (int)id->misc->uid, (int)id->misc->gid );
|
2e7c23 | 1997-06-10 | Henrik Grubbström (Grubba) | | }
|
8afc81 | 1998-02-04 | Per Hedbor | |
|
f6d62d | 1997-03-26 | Per Hedbor | |
|
afb158 | 1997-07-06 | Henrik Grubbström (Grubba) | | 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++;
report_error("Creation of " + f + " failed. Permission denied.\n");
|
8afb50 | 1998-04-15 | Henrik Grubbström (Grubba) | | TRACE_LEAVE("PUT: Contains symlinks. Permission denied");
|
afb158 | 1997-07-06 | Henrik Grubbström (Grubba) | | return http_low_answer(403, "<h2>Permission denied.</h2>");
}
|
8afb50 | 1998-04-15 | Henrik Grubbström (Grubba) | | TRACE_ENTER("PUT: Accepted", 0);
|
b1fca0 | 1996-11-12 | Per Hedbor | | 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) {
#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 */
|
1358d5 | 1999-05-06 | Henrik Grubbström (Grubba) | | id->misc->quota_obj->deallocate(uri, size);
|
2f8308 | 1999-05-05 | Henrik Grubbström (Grubba) | | }
if (size) {
#ifdef QUOTA_DEBUG
report_debug("Deleting old file.\n");
#endif /* QUOTA_DEBUG */
rm(f);
}
}
|
8afb50 | 1998-04-15 | Henrik Grubbström (Grubba) | |
if (stat_cache) {
cache_set("stat_cache", f, 0);
}
|
c6f804 | 1998-06-04 | David Hedbor | | object to = open(f, "wct");
|
242240 | 1998-06-04 | David Hedbor | |
|
2e7c23 | 1997-06-10 | Henrik Grubbström (Grubba) | | privs = 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) | |
|
242240 | 1998-06-04 | David Hedbor | | 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) {
#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");
|
1358d5 | 1999-05-06 | Henrik Grubbström (Grubba) | | return http_low_answer(413, "<h2>Out of disk quota.</h2>",
"413 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");
|
b1fca0 | 1996-11-12 | Per Hedbor | | return http_string_answer("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) | | }
|
1358d5 | 1999-05-06 | Henrik Grubbström (Grubba) | | 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");
|
b1fca0 | 1996-11-12 | Per Hedbor | | return http_pipe_in_progress();
break;
|
6cec00 | 1998-05-14 | David Hedbor | | case "CHMOD":
|
1358d5 | 1999-05-06 | Henrik Grubbström (Grubba) | |
|
6cec00 | 1998-05-14 | David Hedbor | |
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");
return http_auth_required("foo",
"<h1>Permission to 'CHMOD' files denied</h1>");
}
object privs;
if (((int)id->misc->uid) && ((int)id->misc->gid)) {
privs=Privs("CHMODing file", (int)id->misc->uid, (int)id->misc->gid );
}
if (QUERY(no_symlinks) && (contains_symlinks(path, oldf))) {
privs = 0;
errors++;
TRACE_LEAVE("CHMOD: Contains symlinks. Permission denied");
return http_low_answer(403, "<h2>Permission denied.</h2>");
}
chmods++;
TRACE_ENTER("CHMOD: Accepted", 0);
if (stat_cache) {
cache_set("stat_cache", f, 0);
}
#ifdef DEBUG
report_notice(sprintf("CHMODing file "+f+" to 0%o\n", id->misc->mode));
#endif
|
def717 | 1998-05-15 | Henrik Grubbström (Grubba) | | array err = catch(chmod(f, id->misc->mode & 0777));
|
6cec00 | 1998-05-14 | David Hedbor | | privs = 0;
if(err)
{
id->misc->error_code = 403;
TRACE_LEAVE("CHMOD: Failure");
TRACE_LEAVE("Failure");
return 0;
}
TRACE_LEAVE("CHMOD: Success");
TRACE_LEAVE("Success");
return http_string_answer("Ok");
|
dba2b5 | 1998-05-14 | David Hedbor | | case "MV":
|
f37e47 | 1998-05-14 | Henrik Grubbström (Grubba) | |
|
dba2b5 | 1998-05-14 | David Hedbor | |
|
2f8308 | 1999-05-05 | Henrik Grubbström (Grubba) | |
|
dba2b5 | 1998-05-14 | David Hedbor | | if(!QUERY(put))
{
id->misc->error_code = 405;
TRACE_LEAVE("MV disallowed (since PUT is disallowed)");
return 0;
}
if(!QUERY(delete) && size != -1)
{
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;
}
if(QUERY(check_auth) && (!id->auth || !id->auth[0])) {
TRACE_LEAVE("MV: Permission denied");
return http_auth_required("foo",
"<h1>Permission to 'MV' files denied</h1>");
}
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;
}
moves++;
object privs;
if (((int)id->misc->uid) && ((int)id->misc->gid)) {
privs=Privs("Moving file", (int)id->misc->uid, (int)id->misc->gid );
}
|
f37e47 | 1998-05-14 | Henrik Grubbström (Grubba) | |
|
dba2b5 | 1998-05-14 | David Hedbor | |
|
f37e47 | 1998-05-14 | Henrik Grubbström (Grubba) | | if (QUERY(no_symlinks) &&
((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");
return http_low_answer(403, "<h2>Permission denied.</h2>");
}
TRACE_ENTER("MV: Accepted", 0);
#ifdef __NT__
|
f2a51c | 1998-05-26 | Per Hedbor | |
|
dba2b5 | 1998-05-14 | David Hedbor | | #endif
if (stat_cache) {
cache_set("stat_cache", movefrom, 0);
cache_set("stat_cache", f, 0);
}
|
f37e47 | 1998-05-14 | Henrik Grubbström (Grubba) | | #ifdef DEBUG
report_notice("Moving file "+movefrom+" to "+ f+"\n");
#endif /* DEBUG */
|
dba2b5 | 1998-05-14 | David Hedbor | | int code = mv(movefrom, f);
privs = 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");
|
dba2b5 | 1998-05-14 | David Hedbor | | return http_string_answer("Ok");
|
de14f2 | 1998-10-19 | Wim Bonis | |
case "MOVE":
|
2f8308 | 1999-05-05 | Henrik Grubbström (Grubba) | |
|
de14f2 | 1998-10-19 | Wim Bonis | |
if(!QUERY(put))
{
id->misc->error_code = 405;
TRACE_LEAVE("MOVE disallowed (since PUT is disallowed)");
return 0;
}
if(size != -1)
{
id->misc->error_code = 404;
TRACE_LEAVE("MOVE failed (no such file)");
return 0;
}
if(QUERY(check_auth) && (!id->auth || !id->auth[0])) {
TRACE_LEAVE("MOVE: Permission denied");
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;
}
|
1358d5 | 1999-05-06 | Henrik Grubbström (Grubba) | | string new_uri = combine_path(uri + "/../",
id->misc["new-uri"]);
|
de14f2 | 1998-10-19 | Wim Bonis | |
|
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 | |
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;
}
if(size < -1)
{
id->misc->error_code = 405;
TRACE_LEAVE("MOVE: Cannot overwrite directory");
return 0;
}
object privs;
if (((int)id->misc->uid) && ((int)id->misc->gid)) {
privs=Privs("Moving file", (int)id->misc->uid, (int)id->misc->gid );
}
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>");
}
TRACE_ENTER("MOVE: Accepted", 0);
moves++;
#ifdef __NT__
#endif
if (stat_cache) {
cache_set("stat_cache", moveto, 0);
cache_set("stat_cache", f, 0);
}
#ifdef DEBUG
report_notice("Moving file " + f + " to " + moveto + "\n");
#endif /* DEBUG */
int code = mv(f, moveto);
privs = 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");
return http_string_answer("Ok");
|
dba2b5 | 1998-05-14 | David Hedbor | |
|
b1fca0 | 1996-11-12 | Per Hedbor | | case "DELETE":
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 | | }
|
8afb50 | 1998-04-15 | Henrik Grubbström (Grubba) | | if(QUERY(check_auth) && (!id->auth || !id->auth[0])) {
TRACE_LEAVE("DELETE: Permission denied");
|
b1fca0 | 1996-11-12 | Per Hedbor | | return http_low_answer(403, "<h1>Permission to DELETE file denied</h1>");
|
8afb50 | 1998-04-15 | Henrik Grubbström (Grubba) | | }
|
b1fca0 | 1996-11-12 | Per Hedbor | |
|
afb158 | 1997-07-06 | Henrik Grubbström (Grubba) | | if (QUERY(no_symlinks) && (contains_symlinks(path, oldf))) {
errors++;
report_error("Deletion of " + f + " failed. Permission denied.\n");
|
8afb50 | 1998-04-15 | Henrik Grubbström (Grubba) | | TRACE_LEAVE("DELETE: Contains symlinks");
|
afb158 | 1997-07-06 | Henrik Grubbström (Grubba) | | return http_low_answer(403, "<h2>Permission denied.</h2>");
}
|
dbf74f | 1997-06-12 | Marcus Comstedt | | report_notice("DELETING the file "+f+"\n");
|
b1fca0 | 1996-11-12 | Per Hedbor | | accesses++;
|
f6d62d | 1997-03-26 | Per Hedbor | |
|
2e7c23 | 1997-06-10 | Henrik Grubbström (Grubba) | | if (((int)id->misc->uid) && ((int)id->misc->gid)) {
|
0216e2 | 1997-08-12 | Henrik Grubbström (Grubba) | |
|
f7d981 | 1997-09-12 | Per Hedbor | | privs=Privs("Deleting file", id->misc->uid, id->misc->gid );
|
2e7c23 | 1997-06-10 | Henrik Grubbström (Grubba) | | }
|
f6d62d | 1997-03-26 | Per Hedbor | |
|
8afb50 | 1998-04-15 | Henrik Grubbström (Grubba) | |
if (stat_cache) {
cache_set("stat_cache", f, 0);
}
|
f6d62d | 1997-03-26 | Per Hedbor | | if(!rm(f))
{
|
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");
|
b1fca0 | 1996-11-12 | Per Hedbor | | return http_low_answer(200,(f+" DELETED from the server"));
default:
|
8afb50 | 1998-04-15 | Henrik Grubbström (Grubba) | | TRACE_LEAVE("Not supported");
|
b1fca0 | 1996-11-12 | Per Hedbor | | return 0;
}
report_error("Not reached..\n");
|
8afb50 | 1998-04-15 | Henrik Grubbström (Grubba) | | TRACE_LEAVE("Not reached");
|
b1fca0 | 1996-11-12 | Per Hedbor | | return 0;
}
string query_name()
{
return sprintf("<i>%s</i> mounted on <i>%s</i>", query("searchpath"),
query("mountpoint"));
}
|