[Python-checkins] r52437 - sandbox/trunk/setuptools/setuptools/sandbox.py

phillip.eby python-checkins at python.org
Tue Oct 24 20:29:36 CEST 2006


Author: phillip.eby
Date: Tue Oct 24 20:29:35 2006
New Revision: 52437

Modified:
   sandbox/trunk/setuptools/setuptools/sandbox.py
Log:
Fixed not allowing os.open() of paths outside the sandbox, even if they
are opened read-only (e.g. /dev/urandom).


Modified: sandbox/trunk/setuptools/setuptools/sandbox.py
==============================================================================
--- sandbox/trunk/setuptools/setuptools/sandbox.py	(original)
+++ sandbox/trunk/setuptools/setuptools/sandbox.py	Tue Oct 24 20:29:35 2006
@@ -1,4 +1,4 @@
-import os, sys, __builtin__, tempfile
+import os, sys, __builtin__, tempfile, operator
 _os = sys.modules[os.name]
 _open = open
 from distutils.errors import DistutilsError
@@ -187,6 +187,21 @@
             self._violation(operation, src, dst, *args, **kw)
         return (src,dst)
 
+    def open(self, file, flags, mode=0777):
+        """Called for low-level os.open()"""
+        if flags & WRITE_FLAGS:
+            self._violation("open", file, flags, mode)
+        return _os.open(file,flags,mode)
+
+
+WRITE_FLAGS = reduce(
+    operator.or_,
+    [getattr(_os, a, 0) for a in
+        "O_WRONLY O_RDWR O_APPEND O_CREAT O_TRUNC O_TEMPORARY".split()]
+)
+
+
+
 
 class SandboxViolation(DistutilsError):
     """A setup script attempted to modify the filesystem outside the sandbox"""
@@ -201,3 +216,31 @@
 support alternate installation locations even if you run its setup
 script by hand.  Please inform the package's author and the EasyInstall
 maintainers to find out if a fix or workaround is available.""" % self.args
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#


More information about the Python-checkins mailing list