[comp.unix.wizards] umask for ordinary files in CSH

jik@athena.mit.edu (Jonathan I. Kamens) (04/05/91)

In article <1991Apr4.180206.19976@terminator.cc.umich.edu>, bguthy@engin.umich.edu (bala s guthy ) writes:
|> I am reposting this here since I did not receive any replies for
|> this one on c.u.q   

  Well, I didn't see your original question, and I read c.u.q quite
thoroughly.  Perhaps you should have used a wider distribution?  I got this
message, even though it had a distribution of "sa", but perhaps that's just a
fluke.

|> --- Here is what the man page for csh says.
|> 
|>      umask [ value ]
|>                Display the file creation mask.   With  value  set
|>                the  file creation mask.  value is given in octal,
|>                and is XORed with the permissions of 666 for files
|>                and  777  for directories to arrive at the permis-
|>                sions for new files.  Common values  include  002,
|>                giving complete access to the group, and read (and
|>                directory search) access to others, or 022, giving
|>                read  (and directory search) but not write permis-
|>                sion to the group and others.

  The man page is wrong in two different ways.  First of all, it is not true
that 666 and 777 are the permissions that are always checked against.  The
permissions that are checked against are the permissions that the program that
creates the file or directory asked for.  For example, a compiler outputting
an executable might ask for 777 on a file, and a program that creates
directories that it knows should not be world-readable might ask for 700 or
770.

  Second, the permissions are not XORed.  The requested permissions are ANDed
with the negation of the umask, so that the bits that get set in the final
permissions are the bits that are set in the requested permissions and are not
set in the umask.

-- 
Jonathan Kamens			              USnail:
MIT Project Athena				11 Ashford Terrace
jik@Athena.MIT.EDU				Allston, MA  02134
Office: 617-253-8085			      Home: 617-782-0710

gwyn@smoke.brl.mil (Doug Gwyn) (04/05/91)

In article <1991Apr4.180206.19976@terminator.cc.umich.edu> bguthy@engin.umich.edu (bala s guthy ) writes:
>--- Here is what the man page for csh says.
>     umask [ value ]
>               the  file creation mask.  value is given in octal,
>               and is XORed with the permissions of 666 for files
>               and  777  for directories to arrive at the permis-
>               sions for new files.

Well, that manual is wrong.  It was a mistake for it to have said anything
more than "sets the process's umask to nnn (see umask(2))".  That is all
the shell does with the umask value specified.  If you look up umask(2) it
should say in effect that the low 12 bits of the umask value are NANDed
with the modes specified for O_CREATs etc.  In other words, 1 bits in the
umask indicate which mode bits are to be turned OFF from the set normally
specified when a file is created.

By the way, this was not a Wizardly question.

tr@SAMADAMS.PRINCETON.EDU (Tom Reingold) (04/09/91)

In article <15715@smoke.brl.mil> gwyn@smoke.brl.mil (Doug Gwyn)
writes:

$ Well, that manual is wrong.  It was a mistake for it to have said anything
$ more than "sets the process's umask to nnn (see umask(2))".  That is all
$ the shell does with the umask value specified.  If you look up umask(2) it
$ should say in effect that the low 12 bits of the umask value are NANDed
$ with the modes specified for O_CREATs etc.  In other words, 1 bits in the
$ umask indicate which mode bits are to be turned OFF from the set normally
$ specified when a file is created.
$ 
$ By the way, this was not a Wizardly question.

Sometimes, a wizard is defined as someone who knows what you want to
know.  I am not being facetious, because if you don't know something,
it may seem to need a wizard to know it.

I know that "what is a wizard?" has been discussed here many times
before.  I see it as a moving target.  Therefore "Does my question
belong in the wizards group?" is also.

I agree that I would prefer not to see the umask question here, but I
see no practical means to prevent it.  I find the very idea of a
"newsgroup" to be artificial.  We need something better, but I have
just opened a topic more fit for news.misc...
--
        Tom Reingold
        tr@samadams.princeton.edu  OR  ...!princeton!samadams!tr
        "Warning: Do not drive with Auto-Shade in place.  Remove
        from windshield before starting ignition."