Protection of tied files

Discussion in 'Perl Misc' started by J Krugman, Jan 6, 2005.

  1. J Krugman

    J Krugman Guest

    Suppose that I have a Perl variable tied to some file. Does Perl
    provide any facilities for preventing some other program from
    modifying this file, and/or for detecting if such modification
    happens? (I'm only interested in the UNIX case).

    TIA!

    jill

    --
    To s&e^n]d me m~a}i]l r%e*m?o\v[e bit from my a|d)d:r{e:s]s.
     
    J Krugman, Jan 6, 2005
    #1
    1. Advertising

  2. J Krugman

    Anno Siegel Guest

    J Krugman <> wrote in comp.lang.perl.misc:
    >
    >
    >
    >
    > Suppose that I have a Perl variable tied to some file. Does Perl
    > provide any facilities for preventing some other program from
    > modifying this file, and/or for detecting if such modification
    > happens? (I'm only interested in the UNIX case).


    That is really a question about Unix then. Perl can only offer services
    that are supported by the OS.

    The answer is no. There is no way to stop a process with sufficient
    permissions to change a file. There may be implementations of mandatory
    locking, but that's not standard.

    Neither is there a reliable means of checking if the file was changed.
    The one-second resolution of file times is too coarse to be sure. The
    only way is to keep a copy and compare.

    All this is quite independent of the possibility that some Perl program
    could have decided to tie a variable (in what sense?) to the file.

    The usual solution is to set file permissions so that only collaborating
    users (normally just one) have access, and use (advisory) file locking
    for access control. That can be made watertight.

    Anno
     
    Anno Siegel, Jan 6, 2005
    #2
    1. Advertising

  3. J Krugman

    Guest

    J Krugman <> wrote:
    > Suppose that I have a Perl variable tied to some file. Does Perl
    > provide any facilities for preventing some other program from
    > modifying this file, and/or for detecting if such modification
    > happens? (I'm only interested in the UNIX case).
    >
    > TIA!


    You could unlink the filename which the variable is tied to, so that the
    only remaining link to the file inode is the one held by the perl program.
    That should stop all but the most dedicated superusers from messing with
    it. This still leaves a brief period in which someone could grab the file,
    so to be even safer, you should avoid ever creating the filename entry in
    the filesystem in the first place.

    perldoc -f open:

    As a special case the 3 arg form with a read/write mode and the
    third argument being "undef":
    open(TMP, "+>", undef) or die ...
    opens a filehandle to an anonymous temporary file.

    Of course doing this means that the filedata will be lost as soon as your
    program exits, so I hope that that is OK with you.

    Xho

    --
    -------------------- http://NewsReader.Com/ --------------------
    Usenet Newsgroup Service $9.95/Month 30GB
     
    , Jan 6, 2005
    #3
  4. J Krugman

    botfood Guest

    are you asking about flock() considerations to prevent other scripts
    from stepping on a tied file, or a permission issue with keeping
    network users from touching a file?
     
    botfood, Jan 7, 2005
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. g
    Replies:
    69
    Views:
    2,224
    Oliver Wong
    Apr 25, 2006
  2. New Bee

    Tied Up In Knots ASP.NET DataGrid

    New Bee, Sep 6, 2007, in forum: ASP .Net
    Replies:
    0
    Views:
    396
    New Bee
    Sep 6, 2007
  3. Aldorus
    Replies:
    5
    Views:
    5,377
    Aldorus
    Apr 24, 2009
  4. Nephi Immortal

    Two nested classes are tied together.

    Nephi Immortal, Aug 12, 2011, in forum: C++
    Replies:
    8
    Views:
    313
    TJorgenson
    Aug 16, 2011
  5. Larry Woods
    Replies:
    5
    Views:
    378
    Mark Schupp
    Jul 13, 2004
Loading...

Share This Page