From 5c73305f0e4bb5e16aae798e177ec9213f853eec Mon Sep 17 00:00:00 2001 From: Rob Landley Date: Sun, 14 Feb 2021 10:06:01 -0600 Subject: Add find -executable Requested by aheirman on github: uses access(X_OK) which checks access control lists as well as permissions, and that _we_ can access them (u+x could be owned by a different user)... --- toys/posix/find.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/toys/posix/find.c b/toys/posix/find.c index 2d8ca0b1..3824f0c6 100644 --- a/toys/posix/find.c +++ b/toys/posix/find.c @@ -35,7 +35,7 @@ config FIND -inum N inode number N -empty empty files and dirs -type [bcdflps] type is (block, char, dir, file, symlink, pipe, socket) -true always true -false always false - -context PATTERN security context + -context PATTERN security context -executable access(X_OK) perm+ACL -newerXY FILE X=acm time > FILE's Y=acm time (Y=t: FILE is literal time) Numbers N may be prefixed by a - (less than) or + (greater than). Units for @@ -345,11 +345,13 @@ static int do_find(struct dirtree *new) } else test = 0; } } else if (!strcmp(s, "nouser")) { - if (check) if (bufgetpwuid(new->st.st_uid)) test = 0; + if (check && bufgetpwuid(new->st.st_uid)) test = 0; } else if (!strcmp(s, "nogroup")) { - if (check) if (bufgetgrgid(new->st.st_gid)) test = 0; + if (check && bufgetgrgid(new->st.st_gid)) test = 0; } else if (!strcmp(s, "prune")) { if (check && S_ISDIR(new->st.st_mode) && !TT.depth) recurse = 0; + } else if (!strcmp(s, "executable")) { + if (check && faccessat(dirtree_parentfd(new), new->name,X_OK,0)) test = 0; // Remaining filters take an argument } else { -- cgit v1.2.3