File::Temp - provides functions for generating temporary files

This is release V0.22 of File::Temp. This module can be used to generate temporary files (providing a filename and filehandle) or directories. Possible race conditions are avoided and some security checks are performed (eg making sure the sticky bit is set on world writeable temp directories).

It could be considered to be in a late beta state since it has only been tested on six operating systems. The Windows implementation is not yet at release quality since currently files are only deleted when the program exits (via an END block), this differs from the Unix implementation where files can be deleted when the file is closed.

The object-oriented implementation can get around this problem by making use of the object destructor to delete the file or directory and is the recommended interface.

Please let me know if it fails on other operating systems.

INSTALLATION

% perl Makefile.PL
% make
% make test
% make install

TEST FAILURES

Test failures from lib/security saying "system possibly insecure"

Firstly, test failures from the ftmp-security are not necessarily serious or indicative of a real security threat. That being said, they bear investigating.

The tests may fail for the following reasons. Note that each of the tests is run both in the building directory and the temporary directory, as returned by File::Spec->tmpdir().

(1) If the directory the tests are being run is owned by somebody else than the user running the tests, or root (uid 0). This failure can happen if the Perl source code distribution is unpacked in a way that the user ids in the distribution package are used as-is. Some tar programs do this.

(2) If the directory the test are being run in is writable by group or by other (remember: with UNIX/POSIX semantics, write access to a directory means the right to add/remove files in that directory), and there is no sticky bit set in the directory. 'Sticky bit' is a feature used in some UNIXes to give extra protection to files: if the bit is on a directory, no one but the owner (or the root) can remove that file even if the permissions of the directory would allow file removal by others. This failure can happen if the permissions in the directory simply are a bit too liberal for the tests' liking. This may or may not be a real problem: it depends on the permissions policy used on this particular directory/project/system/site. This failure can also happen if the system either doesn't support the sticky bit (this is the case with many non-UNIX platforms: in principle the File::Temp should know about these platforms and skip the tests), or if the system supports the sticky bit but for some reason or reasons it is not being used. This is for example the case with HP-UX: as of HP-UX release 11.00, the sticky bit is very much supported, but HP-UX doesn't use it on its /tmp directory as shipped. Also as with the permissions, some local policy might dictate that the stickiness is not used.

(3) If the system supports the POSIX 'chown giveaway' feature and if any of the parent directories of the temporary file back to the root directory are 'unsafe', using the definitions given above in (1) and (2).

See the documentation for the File::Temp module for more information about the various security aspects.

REQUIREMENTS

Requires perl 5.6.0 or newer.
Perl 5.6.0 will give access to extra security checks.

Written completely in Perl. XS is not required.

File::Spec greater than or equal to 0.8 is required. Fcntl from perl5.5.670 or higher [but will work without it]. The above two modules are standard on Perl 5.6

PLATFORMS

Tested on the following platforms:

MacOSX 10.5.5, perl 5.10.0
Linux CentOS 5.2, perl 5.8.9

Earlier versions were tested on:

SUSe Linux 9.1, perl 5.8.3
Redhat Linux 9, perl 5.8.0
RedHat Linux 7, perl 5.6.0
Solaris 2.6, perl 5.6.0
Windows NT 4, perl 5.6.0
VMS, perl5.7.0
OS/2, perl5.7.0
DOS/DJGPP, perl5.7.0

RedHat Linux 6.1, perl 5.005_03
Digital Unix 4.0, perl 5.005_03

File::Temp is a standard Perl module as of perl 5.7.0 and 5.6.1.

Still may need work on non-Unix platforms to adjust test severity (for example stickyness test does not work on NT, and neither does unlink on an open file). MEDIUM and HIGH security checks have only been tested on Unix. Porting notes are provided at the start of Temp.pm.

FILE::PATH PROBLEM

In perl releases prior to perl 5.6.1 File::Temp will fail to remove directory paths if taint checking is enabled. The problem is a bug in the implementation of File::Path's rmtree function that is fixed in version 1.05 of File::Path. You may want to upgrade File::Path if you come across this problem (you should be able to simply copy in the new implementation of File::Path from a newer perl)..

AUTHOR

Tim Jenness <tjenness@cpan.org>

Copyright (C) 1999 - 2009 Tim Jenness and the UK Particle Physics and Astronomy Research Council. All Rights Reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.

CHANGES IN THIS RELEASE

V0.22

+ Portability fixes in t/fork.t provided by perl5-porters.

V0.21

      + Clean out $FILES_CREATED_BY_OBJECT when the destructor runs. Otherwise
        memory does not get returned. Really bad idea for daemons.
        (Thanks to Maxime Therreault RT #37621)

      + Remove the test on the parent directory to see if a file can
        be written. This will be found out anyway as soon as the file open
        is attempted. AFS systems may fail a -w test but still allow a file
              to be created. (thanks to Christopher Ellison)

      + Put an eval around rmtree. Some versions of rmtree croak if
        you attempt to remove a directory that you are inside. (debian bug
              479317 and RT #35779).

      + seekable test was failing on perl 5.6.0 so we now skip the specific
        test. (thanks to Zefram)

      + Integrate patches from bleadperl for cygwin. (thanks to Jari Aalto
        RT #36376)

V0.20

      + Fix lock.t test that was failing on some systems due to dodgy BEGIN
         block usage (Thanks to Steve Peters and JDHEDDEN - RT #31129)

V0.19

      + Add "newdir" constructor to create a temporary directory
        that will be deleted automatically when the object goes out
        of scope. (RT #15733)

      + tempdir now accepts a TEMPDIR flag for symmetry with tempfile
        (debian bug #351373)

      + Use of exclusive lock can now be disabled by using EXLOCK => 0
        in constructor or tempfile() call. (RT #22702 and #28397)

      + Hopefully really fixed problems with forked processes removing
        temp files and directories created by parent (V0.18 was still broken
        in OO interface) (RT #11067)

      + "_" should now be available as a character from the random character
        generator (RT #41345)

      + Now works again with perl 5.004 (RT#26841 RT#23524)

      + Error message clarified when parent directory does not exist (RT#41346)

      + Fix error message in uid check (RT #14218)

      + Add note concerning binmode to modify encoding of handle returned by tempfile
        (Wolfgang Husmann)

V0.18

      + overload extended to allow compare of object filename directly
        (Rafael Garcia-Suarez)

      + remove umask modification code (potentially thread unsage)
        (Peter Dintelmann, Gisle Aas)

V0.17

+ Now inherits from IO::Seekable (Ricky Myers and Toby Corkindale)

      + Pre-emptive load of Carp::Heavy so that File::Temp can report
        errors when it has run out of file handles (RT #14151)

      + Sebastien Aperghis-Tramoni reports that File::Temp works
        with perl 5.004. (RT #14149)

      + Use effective uid for security check rather than real uid
      (Alexey Tourbin) (RT #14218)

      + Fix Object contructor in SYNOPSIS (Peter Moerch)

      + Documentation updated to note that croak() is called on error
         and that srand should be called after a fork. "e.g." is no longer used.

V0.16

V0.14

V0.13:

V0.12:

V0.11:

V0.10:

V0.09:

V0.08:

V0.07:

V0.06:

V0.05: