From nobody Mon Apr 08 20:25:42 2024 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4VD0w66yvmz5HhVY; Mon, 8 Apr 2024 20:25:42 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4VD0w65430z3xL3; Mon, 8 Apr 2024 20:25:42 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1712607942; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=55CDWSemFPGF0glIv+qW4HFmdmfvLZQQMbHSpQBd5N0=; b=uY1VbdRpfSb2OuegNSIhtoqz/ljDybBNRbIuYqo3do5hIJ7Ed7NA8zr8E98Y6JeFsJVoc5 NnVyK8O5qIwLBZXryPc37DJQ4OgSMpwRW2jK1ZuGcELygfvoHFwfHyYTE0KfSPBpEWQjtt cKfhpTAiqQBGT8/AfyEB4b1CSpXF0s8CJqvxKDLjGJBoyJuHmc6iFsOAyysWNFM461Xwc9 Fg3mZg9wOlljQNyYsm6VJOl7ttQrc71DMtoCHW13jRdVXRE1YvDAITR15JaOqCH8hOTPUg ltFAmpj1MtBUS9wjkz4YThFxSIQDWB2EngD3lGukUwzn+Q1vED6OV/zcek34Tw== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1712607942; a=rsa-sha256; cv=none; b=yHGAQqBXL2GuhgzpnNotRgu7hVSH8QWLU5vNXeSFszv7zECtkgfaQlCgt6H5ERN/Dx9fkN kj+mC/B+E1psSldyVV6gUI399HCB7MMuqkezNeRCsI++90+GchLWM18DXrC5haq3d+w5fk KcsRhAYP2NvfxOPFaa0aLN55JzykBMDyQUEcQD9H5UpX2K7XBc0NoOnQBHtFaVi69sygtP Y4wZC0f+6LAXexuz5z8c5OvxzrAlDBYE3LpGi1oC9qVo8T4eKPsaduxO4Hgt58WglHkw9l NQ35N5RYl+JmuQwQp1X5PO8wDICzOamVNhKHC8kMlxcvEcD16PH+W7Of1d+t2w== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1712607942; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=55CDWSemFPGF0glIv+qW4HFmdmfvLZQQMbHSpQBd5N0=; b=epr5co+VTuj24HS4xjf6EBU7sO705++azwN0vogDN6/VoGM1WJW2esIM39msrnEBbCD9jm pMKgepI+x5dDNndazyDgmmYkoIOnjjUCH4bqRYIXfv3QHwGds8O8yxSMhHN6Vi4djzzxSz 5l5RVe/xO91KnVH2vNq5FK0oMLXXRYYqN171fy/dxaivoR2P2KNx5QhapkQJ1vV+rLsJMP GfkG6IDoafAu0Bc9o8Dz4duPaL4AePMDhyOUvIo8qMrcqPfG4XCnxDkgjSoewZBntxL3AW qqDyGj17qmwKjQiBBXxAZauFiYY5F+YrohQZ0F8GymRaYxJ4DSAioNN5k1jQ+Q== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4VD0w64d62zQDP; Mon, 8 Apr 2024 20:25:42 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.17.1/8.17.1) with ESMTP id 438KPg9J039533; Mon, 8 Apr 2024 20:25:42 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 438KPg3Y039530; Mon, 8 Apr 2024 20:25:42 GMT (envelope-from git) Date: Mon, 8 Apr 2024 20:25:42 GMT Message-Id: <202404082025.438KPg3Y039530@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: John Baldwin Subject: git: aed5216e95e0 - stable/13 - find: Add -readable, -writable & -executable options List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: dev-commits-src-all@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: jhb X-Git-Repository: src X-Git-Refname: refs/heads/stable/13 X-Git-Reftype: branch X-Git-Commit: aed5216e95e0d028a46851f24cfef285452a7719 Auto-Submitted: auto-generated The branch stable/13 has been updated by jhb: URL: https://cgit.FreeBSD.org/src/commit/?id=aed5216e95e0d028a46851f24cfef285452a7719 commit aed5216e95e0d028a46851f24cfef285452a7719 Author: Ricardo Branco AuthorDate: 2024-01-21 19:53:05 +0000 Commit: John Baldwin CommitDate: 2024-04-08 17:34:21 +0000 find: Add -readable, -writable & -executable options Reviewed by: jhb, Mina Galić Pull Request: https://github.com/freebsd/freebsd-src/pull/1080 (cherry picked from commit e4b646ce16105efc943bc8ac2242a2220dfe18d8) --- usr.bin/find/extern.h | 3 +++ usr.bin/find/find.1 | 20 +++++++++++++++++++- usr.bin/find/function.c | 39 +++++++++++++++++++++++++++++++++++++++ usr.bin/find/option.c | 3 +++ 4 files changed, 64 insertions(+), 1 deletion(-) diff --git a/usr.bin/find/extern.h b/usr.bin/find/extern.h index 8c98a6d86bcd..3436f8cf07bf 100644 --- a/usr.bin/find/extern.h +++ b/usr.bin/find/extern.h @@ -88,6 +88,7 @@ exec_f f_delete; exec_f f_depth; exec_f f_empty; exec_f f_exec; +exec_f f_executable; exec_f f_expr; exec_f f_false; exec_f f_flags; @@ -109,11 +110,13 @@ exec_f f_print; exec_f f_print0; exec_f f_prune; exec_f f_quit; +exec_f f_readable; exec_f f_regex; exec_f f_size; exec_f f_sparse; exec_f f_type; exec_f f_user; +exec_f f_writable; extern int ftsoptions, ignore_readdir_race, isdepth, isoutput; extern int issort, isxargs; diff --git a/usr.bin/find/find.1 b/usr.bin/find/find.1 index a73196180e7c..def6a82d0a97 100644 --- a/usr.bin/find/find.1 +++ b/usr.bin/find/find.1 @@ -30,7 +30,7 @@ .\" .\" @(#)find.1 8.7 (Berkeley) 5/9/95 .\" -.Dd January 15, 2024 +.Dd January 21, 2024 .Dt FIND 1 .Os .Sh NAME @@ -467,6 +467,12 @@ if at least one invocation of returns a non-zero exit status, .Nm will return a non-zero exit status. +.It Ic -executable +Matches files which are executable by the current user. +This test makes use of the +.Xr access 2 +system call, and so can be fooled by NFS servers which do UID mapping (or root-squashing). +This is a GNU find extension. .It Ic -flags Oo Cm - Ns | Ns Cm + Oc Ns Ar flags , Ns Ar notflags The flags are specified using symbolic names (see .Xr chflags 1 ) . @@ -831,6 +837,12 @@ option was specified. Causes .Nm to terminate immediately. +.It Ic -readable +Matches files which are readable by the current user. +This test makes use of the +.Xr access 2 +system call, and so can be fooled by NFS servers which do UID mapping (or root-squashing). +This is a GNU find extension. .It Ic -regex Ar pattern True if the whole path of the file matches .Ar pattern @@ -927,6 +939,12 @@ is treated as a user ID. The same thing as .Ic -path , for GNU find compatibility. +.It Ic -writable +Matches files which are writable by the current user. +This test makes use of the +.Xr access 2 +system call, and so can be fooled by NFS servers which do UID mapping (or root-squashing). +This is a GNU find extension. .El .Sh OPERATORS The primaries may be combined using the following operators. diff --git a/usr.bin/find/function.c b/usr.bin/find/function.c index 9c1fd4df8731..d28c0edced9e 100644 --- a/usr.bin/find/function.c +++ b/usr.bin/find/function.c @@ -1813,3 +1813,42 @@ f_quit(PLAN *plan __unused, FTSENT *entry __unused) } /* c_quit == c_simple */ + +/* + * -readable + * + * File is readable + */ +int +f_readable(PLAN *plan __unused, FTSENT *entry) +{ + return (access(entry->fts_path, R_OK) == 0); +} + +/* c_readable == c_simple */ + +/* + * -writable + * + * File is writable + */ +int +f_writable(PLAN *plan __unused, FTSENT *entry) +{ + return (access(entry->fts_path, W_OK) == 0); +} + +/* c_writable == c_simple */ + +/* + * -executable + * + * File is executable + */ +int +f_executable(PLAN *plan __unused, FTSENT *entry) +{ + return (access(entry->fts_path, X_OK) == 0); +} + +/* c_executable == c_simple */ diff --git a/usr.bin/find/option.c b/usr.bin/find/option.c index c5b461f3389b..dc5e5003b3fb 100644 --- a/usr.bin/find/option.c +++ b/usr.bin/find/option.c @@ -80,6 +80,7 @@ static OPTION const options[] = { { "-empty", c_empty, f_empty, 0 }, { "-exec", c_exec, f_exec, 0 }, { "-execdir", c_exec, f_exec, F_EXECDIR }, + { "-executable", c_simple, f_executable, 0 }, { "-false", c_simple, f_false, 0 }, #if HAVE_STRUCT_STAT_ST_FLAGS { "-flags", c_flags, f_flags, 0 }, @@ -154,6 +155,7 @@ static OPTION const options[] = { // -printf { "-prune", c_simple, f_prune, 0 }, { "-quit", c_simple, f_quit, 0 }, + { "-readable", c_simple, f_readable, 0 }, { "-regex", c_regex, f_regex, 0 }, { "-samefile", c_samefile, f_inum, 0 }, { "-size", c_size, f_size, 0 }, @@ -163,6 +165,7 @@ static OPTION const options[] = { { "-uid", c_user, f_user, 0 }, { "-user", c_user, f_user, 0 }, { "-wholename", c_name, f_path, 0 }, + { "-writable", c_simple, f_writable, 0 }, { "-xdev", c_xdev, f_always_true, 0 }, // -xtype };