Capsicumize fts(3)
fts(3) is the file hierarchy traversal library used by nearly every recursive utility in FreeBSD like find, rm, ls, chflags, du, and others. It currently cannot operate inside Capsicum capability mode because it relies on path-based filesystem operations throughout traversal: opening the current directory by name, opening subdirectories by path, and resolving symlinks through constructed string paths. None of the utilities that depend on fts(3) can be Capsicumized until this is fixed. This project adds fts_openat(), a new entry point that accepts a pre-opened directory file descriptor as the traversal root, following the openat(2) convention. The existing fts_open() becomes a one-line wrapper over fts_openat(AT_FDCWD, ...), preserving full backward compatibility. The internal traversal engine is refactored to replace all path-based operations with fd-relative equivalents — openat() and fdopendir() for directory opens, dup() for CWD saves, and fstatfs() for filesystem type detection — while leaving the traversal state machine, path buffer, and cycle detection completely unchanged. The project is structured in two phases. The first and larger phase is a comprehensive ATF/Kyua regression test suite covering the complete documented behaviour of fts(3), built against the unmodified library as a safety baseline. The second phase is the internal refactoring, the new fts_openat() API, capability-mode tests using cap_enter() directly in ATF test cases, and a complete Capsicumization of chflags(1) as the end-to-end demonstration.
Project details
Technologies
Not listed in the archive