From 2c053e75d44016dd6b07649a356c1ce55dbe1028 Mon Sep 17 00:00:00 2001 From: Kamil Dudka Date: Wed, 22 Dec 2010 15:03:48 +0100 Subject: walk_tree: do not follow symlink to directory with -h MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit reported by Jean-Pierre André at https://bugzilla.redhat.com/660613 --- libmisc/walk_tree.c | 3 ++- man/man1/getfattr.1 | 8 +++++--- test/attr.test | 8 ++++++++ test/root/getfattr.test | 8 +------- 4 files changed, 16 insertions(+), 11 deletions(-) diff --git a/libmisc/walk_tree.c b/libmisc/walk_tree.c index 30ff92a..2be9d47 100644 --- a/libmisc/walk_tree.c +++ b/libmisc/walk_tree.c @@ -60,7 +60,8 @@ static int walk_tree_rec(const char *path, int walk_flags, void *), void *arg, int depth) { int follow_symlinks = (walk_flags & WALK_TREE_LOGICAL) || - (!(walk_flags & WALK_TREE_PHYSICAL) && + ((walk_flags & WALK_TREE_DEREFERENCE) && + !(walk_flags & WALK_TREE_PHYSICAL) && depth == 0); int have_dir_stat = 0, flags = walk_flags, err; struct entry_handle dir; diff --git a/man/man1/getfattr.1 b/man/man1/getfattr.1 index 53beb84..5ad2177 100644 --- a/man/man1/getfattr.1 +++ b/man/man1/getfattr.1 @@ -79,7 +79,8 @@ while strings encoded as hexidecimal and base64 are prefixed with .TP .BR \-h ", " \-\-no-dereference Do not dereference symlinks. Instead of the file a symlink refers to, the -symlink itself is examined. +symlink itself is examined. Unless doing a logical (\-L) traversal, do not +traverse symlinks to directories. .TP .BR \-m " \f2pattern\f1, " \-\-match "=\f2pattern\f1" Only include attributes with names matching the regular expression @@ -104,8 +105,9 @@ List the attributes of all files and directories recursively. .TP .BR \-L ", " \-\-logical Logical walk, follow symbolic links to directories. -The default behaviour is to follow symbolic link arguments, and to -skip symbolic links encountered in subdirectories. +The default behaviour is to follow symbolic link arguments unless +\-\-no\-dereference is given, and to skip symbolic links encountered in +subdirectories. Only effective in combination with \-R. .TP .BR \-P ", " \-\-physical diff --git a/test/attr.test b/test/attr.test index d394562..4a14c2f 100644 --- a/test/attr.test +++ b/test/attr.test @@ -217,6 +217,14 @@ Attributes of symlinks vs. the files pointed to $ rm f +Attributes of symlinks vs. the files pointed to in a directory + + $ mkdir src + $ touch src/target + $ setfattr -n user.color -v blue src/target + $ ln -s src symlink + $ getfattr -n user.color -h symlink 2>/dev/null + Tests for file name that contain special characters $ touch "f " diff --git a/test/root/getfattr.test b/test/root/getfattr.test index 6fdb135..0c5d5dc 100644 --- a/test/root/getfattr.test +++ b/test/root/getfattr.test @@ -51,13 +51,7 @@ Make sure we follow symlinks on the command line only when we should: > user.test="test" > - $ getfattr -m- -Rhd here | ../sort-getfattr-output - > # file: here/f - > user.test="test" - > - > # file: here/l - > trusted.test="test" - > + $ getfattr -m- -Rhd here $ getfattr -m- -RLhd here | ../sort-getfattr-output > # file: here/f -- cgit v1.2.1