If your main concern is securing a file, there is an easier way - set the sticky, setgid, and setuid bits on the directory. While this doesn't insure that the files have the exact same permissions, it does insure that (a) all files created in the directory will have the same group and owner as the directory (b) the files cannot be renamed or deleted except by the owner, i.e. the directory owner. This should go a long way to securing the files and avoiding race conditions while you clean up the permissions - especially if the user owning the directory is controlled by your script.

To setup the directory, add 7000 to the normal three digit permissions. (1000=sticky bit, 2000=setgid, 4000=setuid).

Another alternative you might want to consider is the *nix install command. This does a better job of letting you create a file with specific permissions whilst avoiding race conditions that might jeopardize security

For more information, see

Best of luck, beth

P.S. I'm assuming, of course, that you are working on a *nix system. These commands only work on the *nixes. (WinDos has its own funky logic for permissions and inheritance).


In reply to Re: mkdir with variable mask by ELISHEVA
in thread mkdir with variable mask by kreetrapper

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.