summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorJim Meyering <meyering@redhat.com>2009-11-07 08:09:12 +0100
committerJim Meyering <meyering@redhat.com>2009-11-07 08:43:00 +0100
commitd9dbbb9a455f6bfc4e09d9f5f6c6c633f1b03c52 (patch)
tree54ab2f41b2d2de1918d2b18913df819d0b6cfbba /lib
parent74cf4cb26dcecd36eb45dc00dbd4587d9dc24a2f (diff)
downloadcoreutils-d9dbbb9a455f6bfc4e09d9f5f6c6c633f1b03c52.tar.xz
chcon, chgrp, chmod and chown now diagnose a directory cycle
* lib/xfts.c (cycle_warning_required): New function. * lib/xfts.h: Declare it. * src/chown-core.c (change_file_owner): Diagnose a cycle. * src/chmod.c (process_file): Likewise. * src/chcon.c (process_file): Likewise. * NEWS (Bug fixes): Mention this.
Diffstat (limited to 'lib')
-rw-r--r--lib/xfts.c19
-rw-r--r--lib/xfts.h4
2 files changed, 23 insertions, 0 deletions
diff --git a/lib/xfts.c b/lib/xfts.c
index 5994a5fef..9c46f6af5 100644
--- a/lib/xfts.c
+++ b/lib/xfts.c
@@ -61,3 +61,22 @@ xfts_open (char * const *argv, int options,
return fts;
}
+
+/* When fts_read returns FTS_DC to indicate a directory cycle,
+ it may or may not indicate a real problem. When a program like
+ chgrp performs a recursive traversal that requires traversing
+ symbolic links, it is *not* a problem. However, when invoked
+ with "-P -R", it deserves a warning. The fts_options member
+ records the options that control this aspect of fts's behavior,
+ so test that. */
+bool
+cycle_warning_required (FTS const *fts, FTSENT const *ent)
+{
+#define ISSET(Fts,Opt) ((Fts)->fts_options & (Opt))
+ /* When dereferencing no symlinks, or when dereferencing only
+ those listed on the command line and we're not processing
+ a command-line argument, then a cycle is a serious problem. */
+ return ((ISSET (fts, FTS_PHYSICAL) && !ISSET (fts, FTS_COMFOLLOW))
+ || (ISSET (fts, FTS_PHYSICAL) && ISSET (fts, FTS_COMFOLLOW)
+ && ent->fts_level != FTS_ROOTLEVEL));
+}
diff --git a/lib/xfts.h b/lib/xfts.h
index 27ddb5d48..fc3ba9010 100644
--- a/lib/xfts.h
+++ b/lib/xfts.h
@@ -1,5 +1,9 @@
+#include <stdbool.h>
#include "fts_.h"
FTS *
xfts_open (char * const *, int options,
int (*) (const FTSENT **, const FTSENT **));
+
+bool
+cycle_warning_required (FTS const *fts, FTSENT const *ent);