From 3961307b692a49f5463b909c1a7bc2a930e9fa8c Mon Sep 17 00:00:00 2001 From: Kaz Kylheku Date: Wed, 29 May 2019 06:34:37 -0700 Subject: path-private-to-me-p: bugfix: not including superuser. * share/txr/stdlib/path-test.tl (path-private-to-me, path-strictly-private-to-me): These functions were neglecting to trust the root user, as documented. If the file is owned by root, we treat it as if it were owned by the caller. Furthermore, if we have to process the group membership, we allow the group to contain the superuser's name. * txr.1: Documentation improved, and the treatment of groups documented. --- share/txr/stdlib/path-test.tl | 27 +++++++++++++++++++-------- 1 file changed, 19 insertions(+), 8 deletions(-) (limited to 'share') diff --git a/share/txr/stdlib/path-test.tl b/share/txr/stdlib/path-test.tl index 77384fa3..3a7146a8 100644 --- a/share/txr/stdlib/path-test.tl +++ b/share/txr/stdlib/path-test.tl @@ -114,25 +114,36 @@ (sys:path-test (s stat path) (let ((m s.mode) (euid (geteuid))) - (mlet ((g (getgrgid s.gid))) - (and (eql euid s.uid) + (mlet ((g (getgrgid s.gid)) + (name (let ((pw (getpwuid euid))) + (if pw pw.name))) + (suname (let ((pw (getpwuid 0))) + (if pw pw.name)))) + (and (or (zerop s.uid) + (eql euid s.uid)) (zerop (logand m s-iwoth)) (or (zerop (logand m s-iwgrp)) (null g.mem) - (and (not (rest g.mem)) - (equal (getpwuid euid).name (first g.mem))))))))) + (and (all g.mem (orf (op equal name) + (op equal suname)))))))))) (defun path-strictly-private-to-me-p (path) (sys:path-test (s stat path) (let ((m s.mode) (euid (geteuid))) - (mlet ((g (getgrgid s.gid))) - (and (eql euid s.uid) + (mlet ((g (getgrgid s.gid)) + (name (let ((pw (getpwuid euid))) + (if pw pw.name))) + (suname (let ((pw (getpwuid 0))) + (if pw pw.name)))) + (and (or (zerop s.uid) + (eql euid s.uid)) (zerop (logand m (logior s-iroth s-iwoth))) (or (zerop (logand m (logior s-iroth s-iwgrp))) (null g.mem) - (and (not (rest g.mem)) - (equal (getpwuid euid).name (first g.mem))))))))) + (and (all g.mem (orf (op equal name) + (op equal suname)))))))))) + (defmacro sys:path-examine ((sym statfun path) . body) ^[sys:do-path-test ,statfun ,path -- cgit v1.2.3