As I mentioned in
<http://docs.FreeBSD.org/cgi/mid.cgi?20120306000520.GS1519>, at work,
we're trying to use mtree(8) to do reality checks on server
configuration/provisioning.  (We are not proposing the use of mtree to
actually enforce a particular configuration -- we are only considering
using it to generate specification files, then check aa given system
against those specification files.)

I had thought it odd (after running "mtree -c") that most of the entries
in the resulting specification file failed to mention the mode of the
file; this was the catalyst for the above-cited message.

In the mean time, I started poking at the sources.

Caveat: I'm not really a C programmer; the  bulk of my background is in
sysadmin-type positions (though I've been doing other stuff for the last
4 years).

Anyway, I fairly quickly focused my attention on
src/usr.sbin/mtree/create.c, in particular, on the statf() function
therein.

Most of this part of the code is barely changed since 4.4 Lite; the most
recent change to the section in question (lines 207 - 208 from the
version in head as of r232599) was made by rgrimes@ back in 1994.

So I presume that there's something I'm overlooking or otherwise
missing, since the folks who have been here before were certainly more
clueful than I am.

But the code in question:

...
206         }
207         if (keys & F_MODE && (p->fts_statp->st_mode & MBITS) != mode)
208                 output(indent, &offset, "mode=%#o", p->fts_statp->st_mode & 
MBITS);
...

is what outputs the "mode" to standard output.

Here is (the bulk of) what I found:

* The "keys & F_MODE" term merely tests to see if we are interested
  in reporting the file mode.  (By default, we are.)

* "p->fts_statp->st_mode" refers to the "st_mode" returned from stat()
  for the file presently being examined.

* MBITS is a mask of "mode bits" about which we care; it is defined
  (in mtree.h) as "(S_ISUID|S_ISGID|S_ISTXT|S_IRWXU|S_IRWXG|S_IRWXO)".
  These are defined in sys/stat.h; MBITS, thus, works out to 0007777.

* mode is set to the (masked) mode of the (immediately) enclosing
  directory when it is visited in pre-order.  (This is done in statd().)

As a result, we only report the mode of a file if it differs from the
mode of its parent directory.

Huh??!?


Maybe I'm confused, but certainly for my present purposes, and likely in
general, I'd think it would make sense to just always report the file
mode.

A way to do that would be to change the above excerpt to read:

...
206         }
207         if (keys & F_MODE)
208                 output(indent, &offset, "mode=%#o", p->fts_statp->st_mode & 
MBITS);
...


Another alternative, in case there are use cases for the existing
behavior, would be to provide either another "key" or a command-line
flag that says "give me all the modes".

Am I the only one who would find such a change useful?

Thanks for any reality checks. :-}

Peace,
david
-- 
David H. Wolfskill                              da...@catwhisker.org
Depriving a girl or boy of an opportunity for education is evil.

See http://www.catwhisker.org/~david/publickey.gpg for my public key.

Attachment: pgpimJTsmaGQw.pgp
Description: PGP signature

Reply via email to