[csw-devel] SF.net SVN: gar:[13206] csw/mgar/gar/v2/lib/python

wahwah at users.sourceforge.net wahwah at users.sourceforge.net
Sat Feb 5 20:40:14 CET 2011


Revision: 13206
          http://gar.svn.sourceforge.net/gar/?rev=13206&view=rev
Author:   wahwah
Date:     2011-02-05 19:40:13 +0000 (Sat, 05 Feb 2011)

Log Message:
-----------
checkpkg: New check, /etc/foo --> error

This new check catches paths such as /etc/puppet/auth.conf.

It uses a whitelist: /opt/csw, /etc/opt/csw, /var/opt/csw.

Modified Paths:
--------------
    csw/mgar/gar/v2/lib/python/package_checks.py
    csw/mgar/gar/v2/lib/python/package_checks_test.py

Modified: csw/mgar/gar/v2/lib/python/package_checks.py
===================================================================
--- csw/mgar/gar/v2/lib/python/package_checks.py	2011-02-05 19:39:43 UTC (rev 13205)
+++ csw/mgar/gar/v2/lib/python/package_checks.py	2011-02-05 19:40:13 UTC (rev 13206)
@@ -156,6 +156,14 @@
         },
 }
 
+
+ALLOWED_STARTING_PATHS = frozenset([
+  "/opt/csw",
+  "/etc/opt/csw",
+  "/var/opt/csw",
+])
+
+
 def RemovePackagesUnderInstallation(paths_and_pkgs_by_soname,
                                     pkgs_to_be_installed):
   """Emulates uninstallation of packages prior to installation
@@ -1193,6 +1201,28 @@
           % (pkgname, repr(pkgmap_entry["path"]), repr(pkgmap_entry["target"])))
 
 
+def CheckPrefixDirs(pkg_data, error_mgr, logger, messenger):
+  """Files are allowed to be in /opt/csw, /etc/opt/csw and /var/opt/csw."""
+  pkgname = pkg_data["basic_stats"]["pkgname"]
+  paths_with_slashes = [(x, x + "/") for x in ALLOWED_STARTING_PATHS]
+  for pkgmap_entry in pkg_data["pkgmap"]:
+    if "path" not in pkgmap_entry: continue
+    if not pkgmap_entry["path"]: continue
+    allowed_found = False
+    for p, pslash in paths_with_slashes:
+      # We need to handle /opt/csw as an allowed path
+      if pkgmap_entry["path"] == p:
+        allowed_found = True
+        break
+      if pkgmap_entry["path"].startswith(pslash):
+        allowed_found = True
+        break
+    if not allowed_found:
+      error_mgr.ReportError(
+          "bad-location-of-file",
+          "file=%s" % pkgmap_entry["path"])
+
+
 def CheckSonameMustNotBeEqualToFileNameIfFilenameEndsWithSo(
     pkg_data, error_mgr, logger, messenger):
   pass

Modified: csw/mgar/gar/v2/lib/python/package_checks_test.py
===================================================================
--- csw/mgar/gar/v2/lib/python/package_checks_test.py	2011-02-05 19:39:43 UTC (rev 13205)
+++ csw/mgar/gar/v2/lib/python/package_checks_test.py	2011-02-05 19:40:13 UTC (rev 13206)
@@ -1585,5 +1585,75 @@
     self.error_mgr_mock.NeedFile('/opt/csw/lib/libpq.so.5', mox.IsA(str))
 
 
+class TestCheckPrefixDirs(CheckpkgUnitTestHelper,
+                          unittest.TestCase):
+  FUNCTION_NAME = 'CheckPrefixDirs'
+
+  def CheckpkgTest(self):
+    self.pkg_data = copy.deepcopy(tree_stats[0])
+    self.pkg_data["pkgmap"].append(
+        {'class': 'none',
+         'group': None,
+         'line': None,
+         'mode': None,
+         'path': '/opt/csw/bin/foo',
+         'type': 'f',
+         'user': None,
+         'target': None})
+
+  def CheckpkgTest2(self):
+    self.pkg_data = copy.deepcopy(tree_stats[0])
+    self.pkg_data["pkgmap"].append(
+        {'class': 'none',
+         'group': None,
+         'line': None,
+         'mode': None,
+         'path': '/opt/cswbin/foo',
+         'type': 'f',
+         'user': None,
+         'target': None})
+    self.error_mgr_mock.ReportError(
+        'bad-location-of-file',
+        'file=/opt/cswbin/foo')
+
+  def CheckpkgTest3(self):
+    self.pkg_data = copy.deepcopy(tree_stats[0])
+    self.pkg_data["pkgmap"].append(
+        {'class': 'none',
+         'group': None,
+         'line': None,
+         'mode': None,
+         'path': '/var/opt/csw/foo',
+         'type': 'f',
+         'user': None,
+         'target': None})
+
+  def CheckpkgTest4(self):
+    self.pkg_data = copy.deepcopy(tree_stats[0])
+    self.pkg_data["pkgmap"].append(
+        {'class': 'none',
+         'group': None,
+         'line': None,
+         'mode': None,
+         'path': '/var/foo',
+         'type': 'f',
+         'user': None,
+         'target': None})
+    self.error_mgr_mock.ReportError(
+        'bad-location-of-file',
+        'file=/var/foo')
+
+	# These three utility functions allow to run 3 tests in a single
+	# class.
+  def testTwo(self):
+    self.RunCheckpkgTest(self.CheckpkgTest2)
+
+  def testThree(self):
+    self.RunCheckpkgTest(self.CheckpkgTest3)
+
+  def testFour(self):
+    self.RunCheckpkgTest(self.CheckpkgTest4)
+
+
 if __name__ == '__main__':
   unittest.main()


This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.


More information about the devel mailing list