Subject: chflags wierdness
To: None <current-users@NetBSD.ORG>
From: Paul Boven <e.p.boven@student.utwente.nl>
List: current-users
Date: 04/13/1997 12:17:52
Hi everyone,

While playing with the "chflags" command I ran into a lot of strange
behaviour. Hardly any error-messages are generated, and the manpage
contains some errors.

First of all, the manpage chflags(1) lists the possible flags as:

           arch    set the archived flag
           opaque  set the opaque flag (owner or super-user only)
           nodump  set the nodump flag (owner or super-user only)
           sappnd  set the system append-only flag (super-user only)
           schg    set the system immutable flag (super-user only)
           uappnd  set the user append-only flag (owner or super-user only)
           uchg    set the user immutable flag (owner or super-user only)

This implies that to set the arch flag, you do not need to be owner or
superuser, while in fact superuser-privileges are needed to set this
flag. From <sys/stat.h>, note the SF_ARCHIVED entry:

 * Definitions of flags stored in file flags word.
 * Super-user and owner changeable flags.
 
#define UF_SETTABLE     0x0000ffff      /* mask of owner changeable flags */
#define UF_NODUMP       0x00000001      /* do not dump file */
#define UF_IMMUTABLE    0x00000002      /* file may not be changed */
#define UF_APPEND       0x00000004      /* writes to file may only append */
#define UF_OPAQUE       0x00000008      /* directory is opaque wrt. union */

#define SF_SETTABLE     0xffff0000      /* mask of superuser changeable flags */
#define SF_ARCHIVED     0x00010000      /* file is archived */
#define SF_IMMUTABLE    0x00020000      /* file may not be changed */
#define SF_APPEND       0x00040000      /* writes to file may only append */

Despite the chflags(2)-manpage, no ENOPERM is generated when trying
to set for instance this archived flag, which is quite confusing.
Moreover, when setting for instance UF_IMMUTABLE (uchg) on a file, this
happens:

bash$ touch foo
bash$ chflags uchg foo
bash$ rm foo
override rw-r--r--  paul/1024 for foo? y
rm: foo: Operation not permitted
 
A ls -l does not show what is wrong with this, and the question/error-message
is very misleading.

Also, the chflags(2)-manpage fails to mention the SF_ARCHIVED(arch) and
UF_OPAQUE(opaque)  

So there are some documentation-issues, and the lack of, or confusing, error-
messages are part of the namei/lookup part of the kernel.... Before I write
a send-pr about this, how important are these problems? Is this a known
problem, and should it be fixed? It seems the rote off this is the lookup/namei
part of the kernel, which alas is a tad beyond my league to hack around in...

Regards, Paul.
-- 
----------------------------------------------------------------------
Paul Boven, <e.p.boven@student.utwente.nl>  PE1NUT  QRV 145.575 JO32KF
          Lynx users have a "Right to follow a link", too!
----------------------------------------------------------------------