[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Problem with ftw from (ice-9 ftw)

From: Ludovic Courtès
Subject: Re: Problem with ftw from (ice-9 ftw)
Date: Tue, 18 Feb 2014 10:11:09 +0100
User-agent: Gnus/5.130007 (Ma Gnus v0.7) Emacs/24.3 (gnu/linux)


Frank Terbeck <address@hidden> skribis:

> [snip]
> % ls -ladn .
> drwx------ 11 1000 1000 4096 Feb 18 00:53 .
> [snap]
> In that directory and as root, I'm doing the following at guile's REPL:
> [snip]
> scheme@(guile-user)> (use-modules (ice-9 ftw))
> scheme@(guile-user)> (format #t "UID: ~d, EUID: ~d~%" (getuid) (geteuid))
> UID: 0, EUID: 0
> $1 = #t
> scheme@(guile-user)> (ftw "." (lambda (name stat flag)
>                                 (format #t "~s: ~s~%" name flag)))
> ".": directory-not-readable
> $2 = #t
> [snap]
> The code treats root like a normal user, disregarding the fact that this
> particular users will be able to access any file or directory no matter
> the ownership or mode.

Indeed, that’s a bug.  I believe this is fixed with this patch:

diff --git a/module/ice-9/ftw.scm b/module/ice-9/ftw.scm
index 9c9694f..133e9c9 100644
--- a/module/ice-9/ftw.scm
+++ b/module/ice-9/ftw.scm
@@ -259,7 +259,8 @@
       (let* ((perms (stat:perms s))
              (perms-bit-set? (lambda (mask)
                                (not (= 0 (logand mask perms))))))
-        (or (and (= uid (stat:uid s))
+        (or (zero? uid)
+            (and (= uid (stat:uid s))
                  (perms-bit-set? #o400))
             (and (= gid (stat:gid s))
                  (perms-bit-set? #o040))
However, that ‘ftw’ tries to do permission checks by itself is really a
flaw in the first place, IMO.

> Indeed, the ‘scandir’ routine from the same module will read the
> contents of that directory just fine.

I would recommend using ‘scandir’ or ‘file-system-fold’ from (ice-9 ftw)
for new code.


reply via email to

[Prev in Thread] Current Thread [Next in Thread]