1.1 --- a/src/OsecFS.py Wed Nov 27 15:37:26 2013 +0100
1.2 +++ b/src/OsecFS.py Tue Dec 03 11:41:25 2013 +0100
1.3 @@ -18,7 +18,7 @@
1.4 import requests
1.5
1.6
1.7 -MINOPTS = { "Main" : ["Logfile", "Mountpoint", "Rootpath", "LocalScanserverURL", "RemoteScanserverURL"]}
1.8 +MINOPTS = { "Main" : ["Logfile", "Mountpoint", "Rootpath", "LocalScanserverURL", "RemoteScanserverURL", "ReadOnly"]}
1.9
1.10 CONFIG_NOT_READABLE = "Configfile is not readable"
1.11 CONFIG_WRONG = "Something is wrong with the config"
1.12 @@ -42,13 +42,13 @@
1.13
1.14 def printUsage ():
1.15 print ("Usage:")
1.16 - print ("%s configfile" % (sys.argv[0]))
1.17 + print ("%s configfile mountpath ro/rw" % (sys.argv[0]))
1.18 exit (128)
1.19
1.20 def loadConfig ():
1.21 print ("load config")
1.22
1.23 - if (len (sys.argv) < 2):
1.24 + if (len (sys.argv) < 4):
1.25 printUsage ()
1.26
1.27 configfile = sys.argv[1]
1.28 @@ -64,6 +64,13 @@
1.29 print (CONFIG_WRONG)
1.30 print ("Error: %s" % (e))
1.31
1.32 +
1.33 + config.set("Main", "Mountpoint", sys.argv[2])
1.34 + if (sys.argv[3] == "rw"):
1.35 + config.set("Main", "ReadOnly", "false")
1.36 + else:
1.37 + config.set("Main", "ReadOnly", "true")
1.38 +
1.39 checkMinimumOptions (config)
1.40
1.41 return config
1.42 @@ -207,22 +214,32 @@
1.43
1.44 def chmod (self, path, mode):
1.45 LOG.debug ("*** chmod %s %s" % (path, oct(mode)))
1.46 + if (config.get("Main", "ReadOnly") == "true"):
1.47 + return -errno.EACCES
1.48 os.chmod (fixPath (path), mode)
1.49
1.50 def chown (self, path, uid, gid):
1.51 LOG.debug ("*** chown %s %s %s" % (path, uid, gid))
1.52 + if (config.get("Main", "ReadOnly") == "true"):
1.53 + return -errno.EACCES
1.54 os.chown (fixPath (path), uid, gid)
1.55
1.56 def link (self, targetPath, linkPath):
1.57 LOG.debug ("*** link %s %s" % (targetPath, linkPath))
1.58 + if (config.get("Main", "ReadOnly") == "true"):
1.59 + return -errno.EACCES
1.60 os.link (fixPath (targetPath), fixPath (linkPath))
1.61
1.62 def mkdir (self, path, mode):
1.63 LOG.debug ("*** mkdir %s %s" % (path, oct(mode)))
1.64 + if (config.get("Main", "ReadOnly") == "true"):
1.65 + return -errno.EACCES
1.66 os.mkdir (fixPath (path), mode)
1.67
1.68 def mknod (self, path, mode, dev):
1.69 LOG.debug ("*** mknod %s %s %s" % (path, oct (mode), dev))
1.70 + if (config.get("Main", "ReadOnly") == "true"):
1.71 + return -errno.EACCES
1.72 os.mknod (fixPath (path), mode, dev)
1.73
1.74 # to implement virus scan
1.75 @@ -256,11 +273,15 @@
1.76 self.file.close ()
1.77
1.78 def rename (self, oldPath, newPath):
1.79 - LOG.debug ("*** rename %s %s" % (oldPath, newPath))
1.80 + LOG.debug ("*** rename %s %s %s" % (oldPath, newPath, config.get("Main", "ReadOnly")))
1.81 + if (config.get("Main", "ReadOnly") == "true"):
1.82 + return -errno.EACCES
1.83 os.rename (fixPath (oldPath), fixPath (newPath))
1.84
1.85 def rmdir (self, path):
1.86 - LOG.debug ("*** rmdir %s" % (path))
1.87 + LOG.debug ("*** rmdir %s %s" % (path, config.get("Main", "ReadOnly")))
1.88 + if (config.get("Main", "ReadOnly") == "true"):
1.89 + return -errno.EACCES
1.90 os.rmdir (fixPath (path))
1.91
1.92 def statfs (self):
1.93 @@ -268,17 +289,23 @@
1.94 return os.statvfs(".")
1.95
1.96 def symlink (self, targetPath, linkPath):
1.97 - LOG.debug ("*** symlink %s %s" % (targetPath, linkPath))
1.98 + LOG.debug ("*** symlink %s %s %s" % (targetPath, linkPath, config.get("Main", "ReadOnly")))
1.99 + if (config.get("Main", "ReadOnly") == "true"):
1.100 + return -errno.EACCES
1.101 os.symlink (fixPath (targetPath), fixPath (linkPath))
1.102
1.103 def truncate (self, path, length):
1.104 - LOG.debug ("*** truncate %s %s" % (path, length))
1.105 + LOG.debug ("*** truncate %s %s %s" % (path, length, config.get("Main", "ReadOnly")))
1.106 + if (config.get("Main", "ReadOnly") == "true"):
1.107 + return -errno.EACCES
1.108 f = open (fixPath (path), "a")
1.109 f.truncate (length)
1.110 f.close ()
1.111
1.112 def unlink (self, path):
1.113 - LOG.debug ("*** unlink %s" % (path))
1.114 + LOG.debug ("*** unlink %s %s" % (path, config.get("Main", "ReadOnly")))
1.115 + if (config.get("Main", "ReadOnly") == "true"):
1.116 + return -errno.EACCES
1.117 os.unlink (fixPath (path))
1.118
1.119 def utime (self, path, times):
1.120 @@ -286,7 +313,10 @@
1.121 os.utime (fixPath (path), times)
1.122
1.123 def write (self, path, buf, offset):
1.124 - LOG.debug ("*** write %s %s %s" % (path, buf, offset))
1.125 + LOG.debug ("*** write %s %s %s %s" % (path, buf, offset, config.get("Main", "ReadOnly")))
1.126 + if (config.get("Main", "ReadOnly") == "true"):
1.127 + self.file.close()
1.128 + return -errno.EACCES
1.129 self.file.seek (offset)
1.130 self.file.write (buf)
1.131 return len (buf)
1.132 @@ -297,7 +327,9 @@
1.133 return -errno.EACCES
1.134
1.135 def create (self, path, flags, mode):
1.136 - LOG.debug ("*** create %s %s %s %s" % (fixPath (path), oct (flags), oct (mode), flag2mode (flags)))
1.137 + LOG.debug ("*** create %s %s %s %s %s" % (fixPath (path), oct (flags), oct (mode), flag2mode (flags), config.get("Main", "ReadOnly")))
1.138 + if (config.get("Main", "ReadOnly") == "true"):
1.139 + return -errno.EACCES
1.140 self.file = os.fdopen (os.open (fixPath (path), flags, mode), flag2mode (flags))
1.141 self.fd = self.file.fileno ()
1.142