|MTREE(8)||System Manager's Manual||MTREE(8)|
mtree — map a
mtree compares the file
hierarchy rooted in the current directory against a specification read from
the standard input. Messages are written to the standard output for any
files whose characteristics do not match the specification, or which are
missing from either the file hierarchy or the specification. For an
explanation of the directory hierarchy, see
The options are as follows:
-coption. This does not affect either the /set statements or the comment before each directory. It does however affect the comment before the close of each directory.
cksumwas specified. The checksum is seeded with the specified value.
-Uoption except a status of 2 is returned if the file hierarchy did not match the specification.
Specifications are mostly composed of “keywords” (i.e., strings that specify values relating to files). No keywords have default values, and if a keyword has no value set, no checks based on it are performed.
Currently supported keywords are as follows:
The default set of keywords are
There are four types of lines in a specification.
The first type of line sets a global value for a keyword, and consists of the string “/set” followed by whitespace, followed by sets of keyword/value pairs, separated by whitespace. Keyword/value pairs consist of a keyword, followed by an equals sign (‘=’), followed by a value, without whitespace characters. Once a keyword has been set, its value remains unchanged until either reset or unset.
The second type of line unsets keywords and consists of the string “/unset”, followed by whitespace, followed by one or more keywords, separated by whitespace.
The third type of line is a file specification and consists of a file name, followed by whitespace, followed by zero or more whitespace separated keyword/value pairs. The file name may be preceded by whitespace characters. The file name may contain any of the standard file name matching characters (“[”, “]”, “?”, or “*”), in which case files in the hierarchy will be associated with the first pattern that they match.
Each of the keyword/value pairs consist of a keyword, followed by an equals sign, followed by the keyword's value, without whitespace characters. These values override, without changing, the global value of the corresponding keyword.
All paths are relative. Specifying a directory will cause subsequent files to be searched for in that directory hierarchy. Which brings us to the last type of line in a specification: a line containing only the string “..” causes the current directory path to ascend one level.
Empty lines and lines whose first non-whitespace character is a hash mark (‘#’) are ignored.
mtree utility exits with a status of 0
on success, 1 if any error occurred, and 2 if the file hierarchy did not
match the specification. A status of 2 is converted to a status of 0 if the
-U option is used.
To detect system binaries that have been “trojan
horsed”, it is recommended that
sha256digest be run on
the file systems, and a copy of the results stored on a different machine
or, at least, in encrypted form. The output file itself should be digested
using the sha256(1) utility. Then,
sha256(1) should be run against the
on-line specifications. While it is possible for the bad guys to change the
on-line specifications to conform to their modified binaries, it is believed
to be impractical for them to create a modified specification which has the
same SHA-256 digest as the original.
options can be used in combination to create directory hierarchies for
distributions and other such things; the files in
/etc/mtree were used to create almost all
directories in a normal binary distribution.
mtree utility appeared in
|September 2, 2019||OpenBSD-current|