]> CyberLeo.Net >> Repos - FreeBSD/releng/8.0.git/blob - usr.sbin/mtree/mtree.8
Adjust to reflect 8.0-RELEASE.
[FreeBSD/releng/8.0.git] / usr.sbin / mtree / mtree.8
1 .\" Copyright (c) 1989, 1990, 1993
2 .\"     The Regents of the University of California.  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 .\" 4. Neither the name of the University nor the names of its contributors
13 .\"    may be used to endorse or promote products derived from this software
14 .\"    without specific prior written permission.
15 .\"
16 .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
17 .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 .\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
20 .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21 .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22 .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23 .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24 .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26 .\" SUCH DAMAGE.
27 .\"
28 .\"     From: @(#)mtree.8       8.2 (Berkeley) 12/11/93
29 .\" $FreeBSD$
30 .\"
31 .Dd June 16, 2007
32 .Dt MTREE 8
33 .Os
34 .Sh NAME
35 .Nm mtree
36 .Nd map a directory hierarchy
37 .Sh SYNOPSIS
38 .Nm
39 .Op Fl LPUcdeinqruxw
40 .Bk -words
41 .Op Fl f Ar spec
42 .Ek
43 .Bk -words
44 .Op Fl f Ar spec
45 .Ek
46 .Bk -words
47 .Op Fl K Ar keywords
48 .Ek
49 .Bk -words
50 .Op Fl k Ar keywords
51 .Ek
52 .Bk -words
53 .Op Fl p Ar path
54 .Ek
55 .Bk -words
56 .Op Fl s Ar seed
57 .Ek
58 .Bk -words
59 .Op Fl X Ar exclude-list
60 .Ek
61 .Sh DESCRIPTION
62 The
63 .Nm
64 utility compares the file hierarchy rooted in the current directory against a
65 specification read from the standard input.
66 Messages are written to the standard output for any files whose
67 characteristics do not match the specifications, or which are
68 missing from either the file hierarchy or the specification.
69 .Pp
70 The options are as follows:
71 .Bl -tag -width flag
72 .It Fl L
73 Follow all symbolic links in the file hierarchy.
74 .It Fl P
75 Do not follow symbolic links in the file hierarchy, instead consider
76 the symbolic link itself in any comparisons.
77 This is the default.
78 .It Fl U
79 Modify the owner, group, permissions, and modification time of existing
80 files to match the specification and create any missing directories or
81 symbolic links.
82 User, group and permissions must all be specified for missing directories
83 to be created.
84 Corrected mismatches are not considered errors.
85 .It Fl c
86 Print a specification for the file hierarchy to the standard output.
87 .It Fl d
88 Ignore everything except directory type files.
89 .It Fl e
90 Do not complain about files that are in the file hierarchy, but not in the
91 specification.
92 .It Fl i
93 Indent the output 4 spaces each time a directory level is descended when
94 create a specification with the
95 .Fl c
96 option.
97 This does not affect either the /set statements or the comment before each
98 directory.
99 It does however affect the comment before the close of each directory.
100 .It Fl n
101 Do not emit pathname comments when creating a specification.
102 Normally
103 a comment is emitted before each directory and before the close of that
104 directory when using the
105 .Fl c
106 option.
107 .It Fl q
108 Quiet mode.
109 Do not complain when a
110 .Dq missing
111 directory cannot be created because it already exists.
112 This occurs when the directory is a symbolic link.
113 .It Fl r
114 Remove any files in the file hierarchy that are not described in the
115 specification.
116 .It Fl u
117 Same as
118 .Fl U
119 except a status of 2 is returned if the file hierarchy did not match
120 the specification.
121 .It Fl w
122 Make some errorconditions non-fatal warnings.
123 .It Fl x
124 Do not descend below mount points in the file hierarchy.
125 .It Fl f Ar file
126 Read the specification from
127 .Ar file ,
128 instead of from the standard input.
129 .Pp
130 If this option is specified twice, the two specifications are compared
131 to each other rather than to the file hierarchy.
132 The specifications be sorted like output generated using
133 .Fl c .
134 The output format in this case is somewhat remniscent of
135 .Xr comm 1 ,
136 having "in first spec only", "in second spec only", and "different"
137 columns, prefixed by zero, one and two TAB characters respectively.
138 Each entry in the "different" column occupies two lines, one from each specification.
139 .It Fl K Ar keywords
140 Add the specified (whitespace or comma separated)
141 .Ar keywords
142 to the current set of keywords.
143 .It Fl k Ar keywords
144 Use the ``type'' keyword plus the specified (whitespace or comma separated)
145 .Ar keywords
146 instead of the current set of keywords.
147 .It Fl p Ar path
148 Use the file hierarchy rooted in
149 .Ar path ,
150 instead of the current directory.
151 .It Fl s Ar seed
152 Display a single checksum to the standard error output that represents all
153 of the files for which the keyword
154 .Cm cksum
155 was specified.
156 The checksum is seeded with the specified value.
157 .It Fl X Ar exclude-list
158 The specified file contains
159 .Xr fnmatch 3
160 patterns matching files to be excluded from
161 the specification, one to a line.
162 If the pattern contains a
163 .Ql \&/
164 character, it will be matched against entire pathnames (relative to
165 the starting directory); otherwise,
166 it will be matched against basenames only.
167 No comments are allowed in
168 the
169 .Ar exclude-list
170 file.
171 .El
172 .Pp
173 Specifications are mostly composed of ``keywords'', i.e., strings
174 that specify values relating to files.
175 No keywords have default values, and if a keyword has no value set, no
176 checks based on it are performed.
177 .Pp
178 Currently supported keywords are as follows:
179 .Bl -tag -width Cm
180 .It Cm cksum
181 The checksum of the file using the default algorithm specified by
182 the
183 .Xr cksum 1
184 utility.
185 .It Cm flags
186 The file flags as a symbolic name.
187 See
188 .Xr chflags 1
189 for information on these names.
190 If no flags are to be set the string
191 .Dq none
192 may be used to override the current default.
193 .It Cm ignore
194 Ignore any file hierarchy below this file.
195 .It Cm gid
196 The file group as a numeric value.
197 .It Cm gname
198 The file group as a symbolic name.
199 .It Cm md5digest
200 The MD5 message digest of the file.
201 .It Cm sha1digest
202 The
203 .Tn FIPS
204 160-1
205 .Pq Dq Tn SHA-1
206 message digest of the file.
207 .It Cm sha256digest
208 The
209 .Tn FIPS
210 180-2
211 .Pq Dq Tn SHA-256
212 message digest of the file.
213 .It Cm ripemd160digest
214 The
215 .Tn RIPEMD160
216 message digest of the file.
217 .It Cm mode
218 The current file's permissions as a numeric (octal) or symbolic
219 value.
220 .It Cm nlink
221 The number of hard links the file is expected to have.
222 .It Cm nochange
223 Make sure this file or directory exists but otherwise ignore all attributes.
224 .It Cm optional
225 The file is optional; do not complain about the file if it is
226 not in the file hierarchy.
227 .It Cm uid
228 The file owner as a numeric value.
229 .It Cm uname
230 The file owner as a symbolic name.
231 .It Cm size
232 The size, in bytes, of the file.
233 .It Cm link
234 The file the symbolic link is expected to reference.
235 .It Cm time
236 The last modification time of the file, in seconds and nanoseconds.
237 The value should include a period character and exactly nine digits
238 after the period.
239 .It Cm type
240 The type of the file; may be set to any one of the following:
241 .Pp
242 .Bl -tag -width Cm -compact
243 .It Cm block
244 block special device
245 .It Cm char
246 character special device
247 .It Cm dir
248 directory
249 .It Cm fifo
250 fifo
251 .It Cm file
252 regular file
253 .It Cm link
254 symbolic link
255 .It Cm socket
256 socket
257 .El
258 .El
259 .Pp
260 The default set of keywords are
261 .Cm flags ,
262 .Cm gid ,
263 .Cm mode ,
264 .Cm nlink ,
265 .Cm size ,
266 .Cm link ,
267 .Cm time ,
268 and
269 .Cm uid .
270 .Pp
271 There are four types of lines in a specification.
272 .Pp
273 The first type of line sets a global value for a keyword, and consists of
274 the string ``/set'' followed by whitespace, followed by sets of keyword/value
275 pairs, separated by whitespace.
276 Keyword/value pairs consist of a keyword, followed by an equals sign
277 (``=''), followed by a value, without whitespace characters.
278 Once a keyword has been set, its value remains unchanged until either
279 reset or unset.
280 .Pp
281 The second type of line unsets keywords and consists of the string
282 ``/unset'', followed by whitespace, followed by one or more keywords,
283 separated by whitespace.
284 .Pp
285 The third type of line is a file specification and consists of a file
286 name, followed by whitespace, followed by zero or more whitespace
287 separated keyword/value pairs.
288 The file name may be preceded by whitespace characters.
289 The file name may contain any of the standard file name matching
290 characters (``['', ``]'', ``?'' or ``*''), in which case files
291 in the hierarchy will be associated with the first pattern that
292 they match.
293 .Pp
294 Each of the keyword/value pairs consist of a keyword, followed by an
295 equals sign (``=''), followed by the keyword's value, without
296 whitespace characters.
297 These values override, without changing, the global value of the
298 corresponding keyword.
299 .Pp
300 All paths are relative.
301 Specifying a directory will cause subsequent files to be searched
302 for in that directory hierarchy.
303 Which brings us to the last type of line in a specification: a line
304 containing only the string
305 .Dq Pa ..\&
306 causes the current directory
307 path to ascend one level.
308 .Pp
309 Empty lines and lines whose first non-whitespace character is a hash
310 mark (``#'') are ignored.
311 .Pp
312 The
313 .Nm
314 utility exits with a status of 0 on success, 1 if any error occurred,
315 and 2 if the file hierarchy did not match the specification.
316 A status of 2 is converted to a status of 0 if the
317 .Fl U
318 option is used.
319 .Sh FILES
320 .Bl -tag -width /etc/mtree -compact
321 .It Pa /etc/mtree
322 system specification directory
323 .El
324 .Sh EXIT STATUS
325 .Ex -std
326 .Sh EXAMPLES
327 To detect system binaries that have been ``trojan horsed'', it is recommended
328 that
329 .Nm
330 .Fl K
331 .Cm sha256digest
332 be run on the file systems, and a copy of the results stored on a different
333 machine, or, at least, in encrypted form.
334 The output file itself should be digested using the
335 .Xr sha256 1
336 utility.
337 Then, periodically,
338 .Nm
339 and
340 .Xr sha256 1
341 should be run against the on-line specifications.
342 While it is possible for the bad guys to change the on-line specifications
343 to conform to their modified binaries, it is believed to be
344 impractical for them to create a modified specification which has
345 the same SHA-256 digest as the original.
346 .Pp
347 The
348 .Fl d
349 and
350 .Fl u
351 options can be used in combination to create directory hierarchies
352 for distributions and other such things; the files in
353 .Pa /etc/mtree
354 were used to create almost all directories in this
355 .Fx
356 distribution.
357 .Pp
358 To create an
359 .Pa /etc/mtree
360 style BSD.*.dist file, use
361 .Nm
362 .Fl c
363 .Fl d
364 .Fl i
365 .Fl n
366 .Fl k
367 .Cm uname,gname,mode,nochange.
368 .Sh SEE ALSO
369 .Xr chflags 1 ,
370 .Xr chgrp 1 ,
371 .Xr chmod 1 ,
372 .Xr cksum 1 ,
373 .Xr md5 1 ,
374 .Xr stat 2 ,
375 .Xr fts 3 ,
376 .Xr md5 3 ,
377 .Xr chown 8
378 .Sh HISTORY
379 The
380 .Nm
381 utility appeared in
382 .Bx 4.3 Reno .
383 The
384 .Tn MD5
385 digest capability was added in
386 .Fx 2.1 ,
387 in response to the widespread use of programs which can spoof
388 .Xr cksum 1 .
389 The
390 .Tn SHA-1
391 and
392 .Tn RIPEMD160
393 digests were added in
394 .Fx 4.0 ,
395 as new attacks have demonstrated weaknesses in
396 .Tn MD5 .
397 The
398 .Tn SHA-256
399 digest was added in
400 .Fx 6.0 .
401 Support for file flags was added in
402 .Fx 4.0 ,
403 and mostly comes from
404 .Nx .