Description of problem: getcap utility should not follow symlinks to directories in recursive mode. This can cause output redudant information or drive getcap into endless loop if symlinks pointing to parent directories are present in a directory subtree being walked by getcap. Steps to Reproduce (example): # ln -s . link1 # ln -s link1 link2 # ls -l lrwxrwxrwx 1 ilja ilja 1 2008-07-11 11:50 link1 -> . lrwxrwxrwx 1 ilja ilja 5 2008-07-11 11:52 link2 -> link1 # getcap -r link1 Failed to get capabilities of file `link1/link2/link2/link2/link2/link2/link2/link2/link2/link2/link2/link2/link1/link2/link1/link2/link2/link2/link1/link1/link1/link1/link1/link1/link1/link1' (Too many levels of symbolic links) Failed to get attribute of file `link1/link2/link2/link2/link2/link2/link2/link2/link2/link2/link2/link2/link1/link2/link1/link2/link2/link2/link1/link1/link1/link1/link1/link1/link1/link1' (Too many levels of symbolic links) <getcap keeps printing these error messages in endless loop> Expected results: empty output
Heve a look at stat() function... there is version that does not follow symlinks named lstat(), but manpage says it is availible only for _BSD_SOURCE || _XOPEN_SOURCE >= 500
Created attachment 311829 [details] patch (fix candidate) This patch is an fix candidate for this bug. It replaces all the code for managing recursive walking through directory tree by nftw() system library call. With this patch, getcap does not follow symlinks at all (like find utility). Fixes also bug #449986.
*** Bug 449986 has been marked as a duplicate of this bug. ***
It looks like libcap-2.13.tar.gz is released here, http://www.kernel.org/pub/linux/libs/security/linux-privs/kernel-2.6/, so this should probably be repackaged at some point. I'm not sure if the new version fixes this problem because I couldn't find anything in the change log. However, I would recommend you submit your patch upstream as well.
Patch was sent to upstream and is already applied in git.
Thanks for the update and nice work!