Author: Stefano Rivera <[email protected]>
Branch:
Changeset: r73642:1599b45fa4e1
Date: 2014-09-21 23:52 -0700
http://bitbucket.org/pypy/pypy/changeset/1599b45fa4e1/
Log: First step to fixing the sanbox: implement os.access
pypy now (since b97c7d6f7fd8) checks for executability, when
searching for its own executable on startup. This requires
os.access.
diff --git a/rpython/translator/sandbox/sandlib.py
b/rpython/translator/sandbox/sandlib.py
--- a/rpython/translator/sandbox/sandlib.py
+++ b/rpython/translator/sandbox/sandlib.py
@@ -459,6 +459,15 @@
do_ll_os__ll_os_lstat = do_ll_os__ll_os_stat
+ def do_ll_os__ll_os_access(self, vpathname, mode):
+ try:
+ node = self.get_node(vpathname)
+ except OSError, e:
+ if e.errno == errno.ENOENT:
+ return False
+ raise
+ return node.access(mode)
+
def do_ll_os__ll_os_isatty(self, fd):
return self.virtual_console_isatty and fd in (0, 1, 2)
diff --git a/rpython/translator/sandbox/test/test_vfs.py
b/rpython/translator/sandbox/test/test_vfs.py
--- a/rpython/translator/sandbox/test/test_vfs.py
+++ b/rpython/translator/sandbox/test/test_vfs.py
@@ -33,6 +33,8 @@
py.test.raises(OSError, d.join, 'bar')
st = d.stat()
assert stat.S_ISDIR(st.st_mode)
+ assert d.access(os.R_OK | os.X_OK)
+ assert not d.access(os.W_OK)
def test_file():
f = File('hello world')
@@ -46,6 +48,8 @@
st = f.stat()
assert stat.S_ISREG(st.st_mode)
assert st.st_size == 11
+ assert f.access(os.R_OK)
+ assert not f.access(os.W_OK)
def test_realdir_realfile():
for show_dotfiles in [False, True]:
@@ -78,6 +82,7 @@
f = v_test_vfs.join('symlink2')
assert stat.S_ISREG(f.stat().st_mode)
+ assert f.access(os.R_OK)
assert f.open().read() == 'secret'
else:
py.test.raises(OSError, v_test_vfs.join, 'symlink1')
diff --git a/rpython/translator/sandbox/vfs.py
b/rpython/translator/sandbox/vfs.py
--- a/rpython/translator/sandbox/vfs.py
+++ b/rpython/translator/sandbox/vfs.py
@@ -37,6 +37,15 @@
(st_mode, st_ino, st_dev, st_nlink, st_uid, st_gid,
st_size, st_atime, st_mtime, st_ctime))
+ def access(self, mode):
+ s = self.stat()
+ e_mode = s.st_mode & stat.S_IRWXO
+ if UID == s.st_uid:
+ e_mode |= (s.st_mode & stat.S_IRWXU) >> 6
+ if GID == s.st_gid:
+ e_mode |= (s.st_mode & stat.S_IRWXG) >> 3
+ return (e_mode & mode) == mode
+
def keys(self):
raise OSError(errno.ENOTDIR, self)
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit