xref: /netbsd-src/usr.sbin/mtree/mtree.8 (revision 5f7096188587a2c7c95fa3c69b78e1ec9c7923d0)
1.\" Copyright (c) 1989, 1990 The Regents of the University of California.
2.\" All rights reserved.
3.\"
4.\" Redistribution and use in source and binary forms, with or without
5.\" modification, are permitted provided that the following conditions
6.\" are met:
7.\" 1. Redistributions of source code must retain the above copyright
8.\"    notice, this list of conditions and the following disclaimer.
9.\" 2. Redistributions in binary form must reproduce the above copyright
10.\"    notice, this list of conditions and the following disclaimer in the
11.\"    documentation and/or other materials provided with the distribution.
12.\" 3. All advertising materials mentioning features or use of this software
13.\"    must display the following acknowledgement:
14.\"	This product includes software developed by the University of
15.\"	California, Berkeley and its contributors.
16.\" 4. Neither the name of the University nor the names of its contributors
17.\"    may be used to endorse or promote products derived from this software
18.\"    without specific prior written permission.
19.\"
20.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
21.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
24.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30.\" SUCH DAMAGE.
31.\"
32.\"     from: @(#)mtree.8	5.11 (Berkeley) 12/11/91
33.\"	$Id: mtree.8,v 1.1 1993/11/02 07:51:11 cgd Exp $
34.\"
35.Dd December 11, 1991
36.Dt MTREE 8
37.Os
38.Sh NAME
39.Nm mtree
40.Nd map a directory hierarchy
41.Sh SYNOPSIS
42.Nm mtree
43.Op Fl cderux
44.Op Fl f Ar spec
45.Op Fl K Ar keywords
46.Op Fl k Ar keywords
47.Op Fl p Ar path
48.Op Fl s Ar seed
49.Sh DESCRIPTION
50The utility
51.Nm mtree
52compares the file hierarchy rooted in the current directory against a
53specification read from the standard input.
54Messages are written to the standard output for any files whose
55characteristics do not match the specification's, or which are
56missing from either the file hierarchy or the specification.
57.Pp
58The options are as follows:
59.Bl -tag -width flag
60.It Fl c
61Print a specification for the file hierarchy to the standard output.
62.It Fl d
63Ignore everything except directory type files.
64.It Fl e
65Don't complain about files that are in the file hierarchy, but not in the
66specification.
67.It Fl f
68Read the specification from
69.Ar file  ,
70instead of from the standard input.
71.It Fl K
72Add the specified (whitespace or comma separated) keywords to the current
73set of keywords.
74.It Fl k
75Use the ``type'' keyword plus the specified (whitespace or comma separated)
76keywords instead of the current set of keywords.
77.It Fl p
78Use the file hierarchy rooted in
79.Ar path  ,
80instead of the current directory.
81.It Fl r
82Remove any files in the file hierarchy that are not described in the
83specification.
84.It Fl s
85Display a single checksum to the standard error output that represents all
86of the files for which the keyword
87.Cm cksum
88was specified.
89The checksum is seeded with the specified value.
90.It Fl u
91Modify the owner, group, and permissions of existing files to match
92the specification and create any missing directories.
93User, group, and permissions must all be specified for missing directories
94to be created.
95.It Fl x
96Don't descend below mount points in the file hierarchy.
97.El
98.Pp
99Specifications are mostly composed of ``keywords'', i.e. strings that
100that specify values relating to files.
101No keywords have default values, and if a keyword has no value set, no
102checks based on it are performed.
103.Pp
104Currently supported keywords are as follows:
105.Bl -tag -width Cm
106.It Cm cksum
107The checksum of the file using the default algorithm specified by
108the
109.Xr cksum 1
110utility.
111.It Cm ignore
112Ignore any file hierarchy below this file.
113.It Cm gid
114The file group as a numeric value.
115.It Cm gname
116The file group as a symbolic name.
117.It Cm mode
118The current file's permissions as a numeric (octal) or symbolic
119value.
120.It Cm nlink
121The number of hard links the file is expected to have.
122.It Cm uid
123The file owner as a numeric value.
124.It Cm uname
125The file group as a symbolic name.
126.It Cm size
127The size, in bytes, of the file.
128.It Cm link
129The file the symbolic link is expected to reference.
130.It Cm time
131The last modification time of the file.
132.It Cm type
133The type of the file; may be set to any one of the following:
134.sp
135.Bl -tag -width Cm -compact
136.It Cm block
137block special device
138.It Cm char
139character special device
140.It Cm dir
141directory
142.It Cm fifo
143fifo
144.It Cm file
145regular file
146.It Cm link
147symbolic link
148.It Cm socket
149socket
150.El
151.El
152.Pp
153The default set of keywords are
154.Cm gid ,
155.Cm mode ,
156.Cm nlink ,
157.Cm size ,
158.Cm slink ,
159.Cm time ,
160and
161.Cm uid .
162.Pp
163There are four types of lines in a specification.
164.Pp
165The first type of line sets a global value for a keyword, and consists of
166the string ``/set'' followed by whitespace, followed by sets of keyword/value
167pairs, separated by whitespace.
168Keyword/value pairs consist of a keyword, followed by an equals sign
169(``=''), followed by a value, without whitespace characters.
170Once a keyword has been set, its value remains unchanged until either
171reset or unset.
172.Pp
173The second type of line unsets keywords and consists of the string
174``/unset'', followed by whitespace, followed by one or more keywords,
175separated by whitespace.
176.Pp
177The third type of line is a file specification and consists of a file
178name, followed by whitespace, followed by zero or more whitespace
179separated keyword/value pairs.
180The file name may be preceded by whitespace characters.
181The file name may contain any of the standard file name matching
182characters (``['', ``]'', ``?'' or ``*''), in which case files
183in the hierarchy will be associated with the first pattern that
184they match.
185.Pp
186Each of the keyword/value pairs consist of a keyword, followed by an
187equals sign (``=''), followed by the keyword's value, without
188whitespace characters.
189These values override, without changing, the global value of the
190corresponding keyword.
191.Pp
192All paths are relative.
193Specifying a directory will cause subsequent files to be searched
194for in that directory hierarchy.
195Which brings us to the last type of line in a specification: a line
196containing only the string
197.Dq Nm \&..
198causes the current directory
199path to ascend one level.
200.Pp
201Empty lines and lines whose first non-whitespace character is a hash
202mark (``#'') are ignored.
203.Pp
204The
205.Nm mtree
206utility exits with a status of 0 on success, 1 if any error occurred,
207and 2 if the file hierarchy did not match the specification.
208.Sh EXAMPLES
209To detect system binaries that have been ``trojan horsed'', it is recommended
210that
211.Nm mtree
212be run on the file systems, and a copy of the results stored on a different
213machine, or, at least, in encrypted form.
214The seed for the
215.Fl s
216option should not be an obvious value and the final checksum should not be
217stored on-line under any circumstances!
218Then, periodically,
219.Nm mtree
220should be run against the on-line specifications and the final checksum
221compared with the previous value.
222While it is possible for the bad guys to change the on-line specifications
223to conform to their modified binaries, it shouldn't be possible for them
224to make it produce the same final checksum value.
225If the final checksum value changes, the off-line copies of the specification
226can be used to detect which of the binaries have actually been modified.
227.Pp
228The
229.Fl d
230and
231.Fl u
232options can be used in combination to create directory hierarchies
233for distributions and other such things.
234.Sh FILES
235.Bl -tag -width /etc/mtree -compact
236.It Pa /etc/mtree
237system specification directory
238.El
239.Sh SEE ALSO
240.Xr chmod 1 ,
241.Xr chown 1 ,
242.Xr chgrp 1 ,
243.Xr cksum 1 ,
244.Xr stat 2 ,
245.Xr fts 3 ,
246.Sh HISTORY
247The
248.Nm mtree
249utility appeared in
250.Bx 4.3 Reno .
251