# HG changeset patch # User ft # Date 1386067285 -3600 # Node ID 5c45c43de56e6778a7bb7a42a815eebbba34cd32 # Parent d27473cf6a01c1a80967c8e1b3882c122a0b2d4b mountpoint is now an console parameter readonly mode added diff -r d27473cf6a01 -r 5c45c43de56e config/OsecFS.cfg --- a/config/OsecFS.cfg Wed Nov 27 15:37:26 2013 +0100 +++ b/config/OsecFS.cfg Tue Dec 03 11:41:25 2013 +0100 @@ -2,9 +2,6 @@ # make sure this file is writeable Logfile: /var/log/fuse_test.log -# the place that the user will see (you can't access virusfiles here) -Mountpoint: /tmp/virtual_fuse - # where the files really are on the filesystem Rootpath: /tmp/root_fuse diff -r d27473cf6a01 -r 5c45c43de56e src/OsecFS.py --- a/src/OsecFS.py Wed Nov 27 15:37:26 2013 +0100 +++ b/src/OsecFS.py Tue Dec 03 11:41:25 2013 +0100 @@ -18,7 +18,7 @@ import requests -MINOPTS = { "Main" : ["Logfile", "Mountpoint", "Rootpath", "LocalScanserverURL", "RemoteScanserverURL"]} +MINOPTS = { "Main" : ["Logfile", "Mountpoint", "Rootpath", "LocalScanserverURL", "RemoteScanserverURL", "ReadOnly"]} CONFIG_NOT_READABLE = "Configfile is not readable" CONFIG_WRONG = "Something is wrong with the config" @@ -42,13 +42,13 @@ def printUsage (): print ("Usage:") - print ("%s configfile" % (sys.argv[0])) + print ("%s configfile mountpath ro/rw" % (sys.argv[0])) exit (128) def loadConfig (): print ("load config") - if (len (sys.argv) < 2): + if (len (sys.argv) < 4): printUsage () configfile = sys.argv[1] @@ -64,6 +64,13 @@ print (CONFIG_WRONG) print ("Error: %s" % (e)) + + config.set("Main", "Mountpoint", sys.argv[2]) + if (sys.argv[3] == "rw"): + config.set("Main", "ReadOnly", "false") + else: + config.set("Main", "ReadOnly", "true") + checkMinimumOptions (config) return config @@ -207,22 +214,32 @@ def chmod (self, path, mode): LOG.debug ("*** chmod %s %s" % (path, oct(mode))) + if (config.get("Main", "ReadOnly") == "true"): + return -errno.EACCES os.chmod (fixPath (path), mode) def chown (self, path, uid, gid): LOG.debug ("*** chown %s %s %s" % (path, uid, gid)) + if (config.get("Main", "ReadOnly") == "true"): + return -errno.EACCES os.chown (fixPath (path), uid, gid) def link (self, targetPath, linkPath): LOG.debug ("*** link %s %s" % (targetPath, linkPath)) + if (config.get("Main", "ReadOnly") == "true"): + return -errno.EACCES os.link (fixPath (targetPath), fixPath (linkPath)) def mkdir (self, path, mode): LOG.debug ("*** mkdir %s %s" % (path, oct(mode))) + if (config.get("Main", "ReadOnly") == "true"): + return -errno.EACCES os.mkdir (fixPath (path), mode) def mknod (self, path, mode, dev): LOG.debug ("*** mknod %s %s %s" % (path, oct (mode), dev)) + if (config.get("Main", "ReadOnly") == "true"): + return -errno.EACCES os.mknod (fixPath (path), mode, dev) # to implement virus scan @@ -256,11 +273,15 @@ self.file.close () def rename (self, oldPath, newPath): - LOG.debug ("*** rename %s %s" % (oldPath, newPath)) + LOG.debug ("*** rename %s %s %s" % (oldPath, newPath, config.get("Main", "ReadOnly"))) + if (config.get("Main", "ReadOnly") == "true"): + return -errno.EACCES os.rename (fixPath (oldPath), fixPath (newPath)) def rmdir (self, path): - LOG.debug ("*** rmdir %s" % (path)) + LOG.debug ("*** rmdir %s %s" % (path, config.get("Main", "ReadOnly"))) + if (config.get("Main", "ReadOnly") == "true"): + return -errno.EACCES os.rmdir (fixPath (path)) def statfs (self): @@ -268,17 +289,23 @@ return os.statvfs(".") def symlink (self, targetPath, linkPath): - LOG.debug ("*** symlink %s %s" % (targetPath, linkPath)) + LOG.debug ("*** symlink %s %s %s" % (targetPath, linkPath, config.get("Main", "ReadOnly"))) + if (config.get("Main", "ReadOnly") == "true"): + return -errno.EACCES os.symlink (fixPath (targetPath), fixPath (linkPath)) def truncate (self, path, length): - LOG.debug ("*** truncate %s %s" % (path, length)) + LOG.debug ("*** truncate %s %s %s" % (path, length, config.get("Main", "ReadOnly"))) + if (config.get("Main", "ReadOnly") == "true"): + return -errno.EACCES f = open (fixPath (path), "a") f.truncate (length) f.close () def unlink (self, path): - LOG.debug ("*** unlink %s" % (path)) + LOG.debug ("*** unlink %s %s" % (path, config.get("Main", "ReadOnly"))) + if (config.get("Main", "ReadOnly") == "true"): + return -errno.EACCES os.unlink (fixPath (path)) def utime (self, path, times): @@ -286,7 +313,10 @@ os.utime (fixPath (path), times) def write (self, path, buf, offset): - LOG.debug ("*** write %s %s %s" % (path, buf, offset)) + LOG.debug ("*** write %s %s %s %s" % (path, buf, offset, config.get("Main", "ReadOnly"))) + if (config.get("Main", "ReadOnly") == "true"): + self.file.close() + return -errno.EACCES self.file.seek (offset) self.file.write (buf) return len (buf) @@ -297,7 +327,9 @@ return -errno.EACCES def create (self, path, flags, mode): - LOG.debug ("*** create %s %s %s %s" % (fixPath (path), oct (flags), oct (mode), flag2mode (flags))) + LOG.debug ("*** create %s %s %s %s %s" % (fixPath (path), oct (flags), oct (mode), flag2mode (flags), config.get("Main", "ReadOnly"))) + if (config.get("Main", "ReadOnly") == "true"): + return -errno.EACCES self.file = os.fdopen (os.open (fixPath (path), flags, mode), flag2mode (flags)) self.fd = self.file.fileno ()