ruleset.py
changeset 32 4059dbe9f26a
parent 23 9fa62cfd2821
--- a/ruleset.py	Wed May 28 18:14:15 2008 +0100
+++ b/ruleset.py	Thu Jun 05 16:53:57 2008 +0100
@@ -5,6 +5,7 @@
 # This software may be used and distributed according to the terms
 # of the GNU General Public License, incorporated herein by reference.
 
+import sys
 import re
 
 allowedchars = "A-Za-z0-9_-"
@@ -49,7 +50,9 @@
     levels = ["init", "write", "read", "deny"]
 
     def __init__(self):
-        self.rules = []
+        # The user called "root" automatically has the highest
+        # privilege
+        self.rules = [(self.levels[0], rule([('user', 'root')]))]
         self.preset = {}
 
     def add(self, action, conditions):
@@ -74,14 +77,19 @@
     @classmethod
     def readfile(cls, fn):
         res = cls()
-        f = open(fn)
         try:
-            for l in f:
-                l = l.strip()
-                if len(l) == 0 or l.startswith("#"):
-                    continue
-                l = l.split()
-                res.add(l[0], rule([c.split("=", 1) for c in l[1:]]))
-        finally:
-            f.close()
+            f = open(fn)
+            try:
+                for l in f:
+                    l = l.strip()
+                    if len(l) == 0 or l.startswith("#"):
+                        continue
+                    l = l.split()
+                    res.add(l[0], rule([c.split("=", 1) for c in l[1:]]))
+            finally:
+                f.close()
+        except Exception, e:
+            print >> sys.stderr, "Failure reading rules file:", e
+            return cls()
         return res
+