summaryrefslogtreecommitdiff
path: root/woof
diff options
context:
space:
mode:
authorWeisenhorn Geoffroy <geoffroy.weisenhorn@gmail.com>2008-10-29 22:10:00 +0100
committerHugues Hiegel <hugues@hiegel.fr>2011-10-21 16:24:08 +0200
commitbf0abc586c20a4d280d2d27baa6d6d0a8f8d53d5 (patch)
treebd51a8fa9ce1c888fe19b0eebd82a6ba57978e55 /woof
parentb603ca91d3f0746b4894e461a5b545330ae8e470 (diff)
FIX: check if file is readable
Diffstat (limited to 'woof')
-rwxr-xr-xwoof23
1 files changed, 23 insertions, 0 deletions
diff --git a/woof b/woof
index 5e2591f..383226f 100755
--- a/woof
+++ b/woof
@@ -27,6 +27,7 @@
""" woof -- an ad-hoc single file webserver"""
import sys, os, popen2, signal, select, socket, getopt, commands
+import stat
import urllib, BaseHTTPServer
import ConfigParser
@@ -98,6 +99,24 @@ def find_ip ():
return ip_addr
+def is_owner(stf):
+ """Return true if the file belongs to the current user"""
+ return stf.st_uid == os.getuid()
+
+def is_group(stf):
+ """Return true if the file belongs to the group of current user"""
+ return stf.st_gid == os.getgid()
+
+def is_read(filename):
+ """ Check whether a file is readable """
+ result_st = os.stat(filename)
+ if is_owner(result_st):
+ return (result_st.st_mode & stat.S_IRUSR)
+ elif is_group(result_st):
+ return (result_st.st_mode & stat.S_IRGRP)
+ else:
+ return (result_st.st_mode & stat.S_IROTH)
+
class FileServHTTPRequestHandler(BaseHTTPServer.BaseHTTPRequestHandler):
"""
Main class implementing an HTTP-Requesthandler, that serves just a single
@@ -335,6 +354,10 @@ def main ():
if not (os.path.isfile (filename) or os.path.isdir (filename)):
usage (defaultport, defaultmaxdown,
"%s: Neither file nor directory" % filenames[0])
+ if not is_read(filename):
+ usage (defaultport, defaultmaxdown,
+ "%s: Check read permission" % filenames[0])
+
serve_files (filename, maxdown, ip_addr, port)
# wait for child processes to terminate