summaryrefslogtreecommitdiffstats
path: root/usr.bin/find
diff options
context:
space:
mode:
authorbmilekic <bmilekic@FreeBSD.org>2004-04-03 17:10:04 +0000
committerbmilekic <bmilekic@FreeBSD.org>2004-04-03 17:10:04 +0000
commitfe706c8af3b169adf692cc68ea062d1644f6e22d (patch)
treefdb94cf9e8ca2a9605f8284a0491cc62e9a02a89 /usr.bin/find
parent7204d752f03abbfdd460f798e8a85fe0ca6bb7b3 (diff)
downloadFreeBSD-src-fe706c8af3b169adf692cc68ea062d1644f6e22d.zip
FreeBSD-src-fe706c8af3b169adf692cc68ea062d1644f6e22d.tar.gz
Give find(1) the option -acl to locate files with extended
ACLs. This is similar to what ls(1) can do. It is handy to have it so that it can be used in conjunction with "-exec setfacl {} \;" (to find(1)), among others. This is the submitter's patch, but slightly modified. PR: bin/65016 Submitted by: Christian S.J. Peron <maneo@bsdpro.com>
Diffstat (limited to 'usr.bin/find')
-rw-r--r--usr.bin/find/extern.h2
-rw-r--r--usr.bin/find/function.c51
-rw-r--r--usr.bin/find/option.c1
3 files changed, 54 insertions, 0 deletions
diff --git a/usr.bin/find/extern.h b/usr.bin/find/extern.h
index b259757..67a8e3b 100644
--- a/usr.bin/find/extern.h
+++ b/usr.bin/find/extern.h
@@ -52,6 +52,7 @@ OPTION *lookup_option(const char *);
creat_f c_Xmin;
creat_f c_Xtime;
+creat_f c_acl;
creat_f c_and;
creat_f c_delete;
creat_f c_depth;
@@ -82,6 +83,7 @@ creat_f c_xdev;
exec_f f_Xmin;
exec_f f_Xtime;
+exec_f f_acl;
exec_f f_always_true;
exec_f f_closeparen;
exec_f f_delete;
diff --git a/usr.bin/find/function.c b/usr.bin/find/function.c
index 3ba7555..72bf8aa 100644
--- a/usr.bin/find/function.c
+++ b/usr.bin/find/function.c
@@ -46,6 +46,8 @@ __FBSDID("$FreeBSD$");
#include <sys/param.h>
#include <sys/ucred.h>
#include <sys/stat.h>
+#include <sys/types.h>
+#include <sys/acl.h>
#include <sys/wait.h>
#include <sys/mount.h>
#include <sys/timeb.h>
@@ -352,6 +354,55 @@ c_mXXdepth(OPTION *option, char ***argvp)
}
/*
+ * -acl function --
+ *
+ * Show files with EXTENDED ACL attributes.
+ */
+int
+f_acl(PLAN *plan__unused, FTSENT *entry)
+{
+ int match, entries;
+ acl_entry_t ae;
+ acl_t facl;
+
+ if (S_ISLNK(entry->fts_statp->st_mode))
+ return 0;
+ if ((match = pathconf(entry->fts_accpath, _PC_ACL_EXTENDED)) <= 0) {
+ if (match < 0 && errno != EINVAL)
+ warn("%s", entry->fts_accpath);
+ else
+ return 0;
+ }
+ match = 0;
+ if ((facl = acl_get_file(entry->fts_accpath,ACL_TYPE_ACCESS)) != NULL) {
+ if (acl_get_entry(facl, ACL_FIRST_ENTRY, &ae) == 1) {
+ /*
+ * POSIX.1e requires that ACLs of type ACL_TYPE_ACCESS
+ * must have at least three entries (owner, group,
+ * other).
+ */
+ entries = 1;
+ while (acl_get_entry(facl, ACL_NEXT_ENTRY, &ae) == 1) {
+ if (++entries > 3) {
+ match = 1;
+ break;
+ }
+ }
+ }
+ acl_free(facl);
+ } else
+ warn("%s", entry->fts_accpath);
+ return match;
+}
+
+PLAN *
+c_acl(OPTION *option, char ***argvp__unused)
+{
+ ftsoptions &= ~FTS_NOSTAT;
+ return (palloc(option));
+}
+
+/*
* -delete functions --
*
* True always. Makes its best shot and continues on regardless.
diff --git a/usr.bin/find/option.c b/usr.bin/find/option.c
index 9e10e50..2f3ca3a 100644
--- a/usr.bin/find/option.c
+++ b/usr.bin/find/option.c
@@ -63,6 +63,7 @@ static OPTION const options[] = {
{ "(", c_simple, f_openparen, 0 },
{ ")", c_simple, f_closeparen, 0 },
{ "-a", c_and, NULL, 0 },
+ { "-acl", c_acl, f_acl, 0 },
{ "-amin", c_Xmin, f_Xmin, F_TIME_A },
{ "-and", c_and, NULL, 0 },
{ "-anewer", c_newer, f_newer, F_TIME_A },
OpenPOWER on IntegriCloud