mountpoint is now an console parameter
authorft
Tue, 03 Dec 2013 11:41:25 +0100
changeset 35c45c43de56e
parent 2 d27473cf6a01
child 4 114537186d9e
mountpoint is now an console parameter
readonly mode added
config/OsecFS.cfg
src/OsecFS.py
     1.1 --- a/config/OsecFS.cfg	Wed Nov 27 15:37:26 2013 +0100
     1.2 +++ b/config/OsecFS.cfg	Tue Dec 03 11:41:25 2013 +0100
     1.3 @@ -2,9 +2,6 @@
     1.4  # make sure this file is writeable
     1.5  Logfile: /var/log/fuse_test.log
     1.6  
     1.7 -# the place that the user will see (you can't access virusfiles here)
     1.8 -Mountpoint: /tmp/virtual_fuse
     1.9 -
    1.10  # where the files really are on the filesystem 
    1.11  Rootpath: /tmp/root_fuse
    1.12  
     2.1 --- a/src/OsecFS.py	Wed Nov 27 15:37:26 2013 +0100
     2.2 +++ b/src/OsecFS.py	Tue Dec 03 11:41:25 2013 +0100
     2.3 @@ -18,7 +18,7 @@
     2.4  import requests
     2.5  
     2.6  
     2.7 -MINOPTS = { "Main" : ["Logfile", "Mountpoint", "Rootpath", "LocalScanserverURL", "RemoteScanserverURL"]}
     2.8 +MINOPTS = { "Main" : ["Logfile", "Mountpoint", "Rootpath", "LocalScanserverURL", "RemoteScanserverURL", "ReadOnly"]}
     2.9  
    2.10  CONFIG_NOT_READABLE = "Configfile is not readable"
    2.11  CONFIG_WRONG = "Something is wrong with the config"
    2.12 @@ -42,13 +42,13 @@
    2.13  
    2.14  def printUsage ():
    2.15      print ("Usage:")
    2.16 -    print ("%s configfile" % (sys.argv[0]))
    2.17 +    print ("%s configfile mountpath ro/rw" % (sys.argv[0]))
    2.18      exit (128)
    2.19  
    2.20  def loadConfig ():
    2.21      print ("load config")
    2.22  
    2.23 -    if (len (sys.argv) < 2):
    2.24 +    if (len (sys.argv) < 4):
    2.25          printUsage ()
    2.26  
    2.27      configfile = sys.argv[1]
    2.28 @@ -64,6 +64,13 @@
    2.29          print (CONFIG_WRONG)
    2.30          print ("Error: %s" % (e))
    2.31  
    2.32 +
    2.33 +    config.set("Main", "Mountpoint", sys.argv[2])
    2.34 +    if (sys.argv[3] == "rw"):
    2.35 +        config.set("Main", "ReadOnly", "false")
    2.36 +    else:
    2.37 +        config.set("Main", "ReadOnly", "true")
    2.38 +
    2.39      checkMinimumOptions (config)
    2.40  
    2.41      return config
    2.42 @@ -207,22 +214,32 @@
    2.43  
    2.44      def chmod (self, path, mode):
    2.45          LOG.debug ("*** chmod %s %s" % (path, oct(mode)))
    2.46 +        if (config.get("Main", "ReadOnly") == "true"):
    2.47 +            return -errno.EACCES
    2.48          os.chmod (fixPath (path), mode)
    2.49  
    2.50      def chown (self, path, uid, gid):
    2.51          LOG.debug ("*** chown %s %s %s" % (path, uid, gid))
    2.52 +        if (config.get("Main", "ReadOnly") == "true"):
    2.53 +            return -errno.EACCES
    2.54          os.chown (fixPath (path), uid, gid)
    2.55  
    2.56      def link (self, targetPath, linkPath):
    2.57          LOG.debug ("*** link %s %s" % (targetPath, linkPath))
    2.58 +        if (config.get("Main", "ReadOnly") == "true"):
    2.59 +            return -errno.EACCES
    2.60          os.link (fixPath (targetPath), fixPath (linkPath))
    2.61  
    2.62      def mkdir (self, path, mode):
    2.63          LOG.debug ("*** mkdir %s %s" % (path, oct(mode)))
    2.64 +        if (config.get("Main", "ReadOnly") == "true"):
    2.65 +            return -errno.EACCES
    2.66          os.mkdir (fixPath (path), mode)
    2.67  
    2.68      def mknod (self, path, mode, dev):
    2.69          LOG.debug ("*** mknod %s %s %s" % (path, oct (mode), dev))
    2.70 +        if (config.get("Main", "ReadOnly") == "true"):
    2.71 +            return -errno.EACCES
    2.72          os.mknod (fixPath (path), mode, dev)
    2.73  
    2.74      # to implement virus scan
    2.75 @@ -256,11 +273,15 @@
    2.76          self.file.close ()
    2.77  
    2.78      def rename (self, oldPath, newPath):
    2.79 -        LOG.debug ("*** rename %s %s" % (oldPath, newPath))
    2.80 +        LOG.debug ("*** rename %s %s %s" % (oldPath, newPath, config.get("Main", "ReadOnly")))
    2.81 +        if (config.get("Main", "ReadOnly") == "true"):
    2.82 +            return -errno.EACCES
    2.83          os.rename (fixPath (oldPath), fixPath (newPath))
    2.84  
    2.85      def rmdir (self, path):
    2.86 -        LOG.debug ("*** rmdir %s" % (path))
    2.87 +        LOG.debug ("*** rmdir %s %s" % (path, config.get("Main", "ReadOnly")))
    2.88 +        if (config.get("Main", "ReadOnly") == "true"):
    2.89 +            return -errno.EACCES
    2.90          os.rmdir (fixPath (path))
    2.91  
    2.92      def statfs (self):
    2.93 @@ -268,17 +289,23 @@
    2.94          return os.statvfs(".")
    2.95  
    2.96      def symlink (self, targetPath, linkPath):
    2.97 -        LOG.debug ("*** symlink %s %s" % (targetPath, linkPath))
    2.98 +        LOG.debug ("*** symlink %s %s %s" % (targetPath, linkPath, config.get("Main", "ReadOnly")))
    2.99 +        if (config.get("Main", "ReadOnly") == "true"):
   2.100 +            return -errno.EACCES
   2.101          os.symlink (fixPath (targetPath), fixPath (linkPath))
   2.102  
   2.103      def truncate (self, path, length):
   2.104 -        LOG.debug ("*** truncate %s %s" % (path, length))
   2.105 +        LOG.debug ("*** truncate %s %s %s" % (path, length, config.get("Main", "ReadOnly")))
   2.106 +        if (config.get("Main", "ReadOnly") == "true"):
   2.107 +            return -errno.EACCES
   2.108          f = open (fixPath (path), "a")
   2.109          f.truncate (length)
   2.110          f.close ()
   2.111  
   2.112      def unlink (self, path):
   2.113 -        LOG.debug ("*** unlink %s" % (path))
   2.114 +        LOG.debug ("*** unlink %s %s" % (path, config.get("Main", "ReadOnly")))
   2.115 +        if (config.get("Main", "ReadOnly") == "true"):
   2.116 +            return -errno.EACCES
   2.117          os.unlink (fixPath (path))
   2.118  
   2.119      def utime (self, path, times):
   2.120 @@ -286,7 +313,10 @@
   2.121          os.utime (fixPath (path), times)
   2.122  
   2.123      def write (self, path, buf, offset):
   2.124 -        LOG.debug ("*** write %s %s %s" % (path, buf, offset))
   2.125 +        LOG.debug ("*** write %s %s %s %s" % (path, buf, offset, config.get("Main", "ReadOnly")))
   2.126 +        if (config.get("Main", "ReadOnly") == "true"):
   2.127 +            self.file.close()
   2.128 +            return -errno.EACCES
   2.129          self.file.seek (offset)
   2.130          self.file.write (buf)
   2.131          return len (buf)
   2.132 @@ -297,7 +327,9 @@
   2.133              return -errno.EACCES
   2.134  
   2.135      def create (self, path, flags, mode):
   2.136 -        LOG.debug ("*** create %s %s %s %s" % (fixPath (path), oct (flags), oct (mode), flag2mode (flags)))
   2.137 +        LOG.debug ("*** create %s %s %s %s %s" % (fixPath (path), oct (flags), oct (mode), flag2mode (flags), config.get("Main", "ReadOnly")))
   2.138 +        if (config.get("Main", "ReadOnly") == "true"):
   2.139 +            return -errno.EACCES
   2.140          self.file = os.fdopen (os.open (fixPath (path), flags, mode), flag2mode (flags))
   2.141          self.fd = self.file.fileno ()
   2.142